solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; using ld = long double; const ll llinf = (1ll << 61) - 1; const double eps = 1e-6, ldeps = 1e-9; struct Dbg { static constexpr auto &os = cout; template <class C> static auto dud(C *x) -> decltype(os << *x, 0); t...
12
#include <bits/stdc++.h> using namespace std; int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } int main() { int a, b, c, d; int x1, y1, x2, y2; scanf("%d %d %d %d", &c, &d, &a, &b); if (c * b <= a * d) { x1 = a * d - b * c; y1 = a * d; int tmp = gcd(x1, y1); x1 = x1 / tm...
6
#include <bits/stdc++.h> using namespace std; const long long MOD = 1000000007; const long long INF = 1000000007; void __print(int x) { cerr << x; } void __print(long x) { cerr << x; } void __print(long long x) { cerr << x; } void __print(unsigned x) { cerr << x; } void __print(unsigned long x) { cerr << x; } void __pr...
11
#include <bits/stdc++.h> template <typename T> inline T max(T a, T b) { return a > b ? a : b; } template <typename T> inline T min(T a, T b) { return a < b ? a : b; } template <typename T> inline T abs(T a) { return a > 0 ? a : -a; } template <typename T> inline bool repr(T &a, T b) { return a < b ? a = b, 1 : ...
17
#include <bits/stdc++.h> using namespace std; long long a, b, c, kol[10]; char k, t; int main() { cin >> a >> b >> c; cin >> k; for (long long i = 0; i < a - 1; i++) { cin >> t; if (t != k) kol[k - '0']++; k = t; } kol[k - '0']++; if (kol[0] == 0) { cout << 0; } else { cout << (kol[0] ...
7
#include <bits/stdc++.h> using namespace std; long long power(long long a, long long b, long long m = 1000000007) { if (b == 0) return 1; if (b == 1) return a; long long res = power(a, b / 2, m); res = (res * res) % m; if (b & 1) res = (res * a) % m; return res; } long long modinv(long long a, long long m =...
0
#include <bits/stdc++.h> using namespace std; const int MAXN = 1 << 17; const int SIZE = MAXN << 1; int ar[MAXN]; pair<int, pair<int, int> > operator+(pair<int, pair<int, int> > &a, pair<int, pair<int, int> > &b) { return pair<int, pair<int, int> >( a.first + b.first, pair<i...
20
#include <bits/stdc++.h> using namespace std; int main() { int n, a; cin >> n >> a; vector<int> arr(n); for (int i = 0; i < n; i++) { cin >> arr[i]; } sort(arr.begin(), arr.end()); int cost = INT_MAX; if (n == 1) { cout << 0 << endl; return 0; } cost = min(abs(a - arr[0]), abs(a - arr[n ...
7
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const int inf = 1e9; long long powm(long long a, long long p, long long m) { long long r = 1 % m; while (p) { if (p & 1) r = r * a % m; p >>= 1; a = a * a % m; } return r; } int n, m, l, r, k, a[100000], b[100001][101] = {}, c[10...
17
#include <bits/stdc++.h> using namespace std; const double eps = 1e-8; const double inf = 1e20; const double pi = acos(-1.0); const int maxp = 1611; int dblcmp(double d) { if (fabs(d) < eps) return 0; return d > eps ? 1 : -1; } inline double sqr(double x) { return x * x; } struct point { double x, y; point() {}...
17
#include <bits/stdc++.h> using namespace std; int n, m, a[30005], f[30005][605]; inline bool check(int x, int off) { int pos = m + off - 300; if (pos <= 0 || x + pos > 30000) return false; return true; } inline int Calc(int x, int off) { int& ans = f[x][off]; if (ans != -1) return ans; ans = 0; if (check(...
11
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 7; const int mod = 1e9 + 7; const long long INF = 1e18 + 7; long long v[200][200], T; int n, m; long long mp[200][200]; long long dp[200][200] = {0}; long long f(int x, int y) { for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { ...
14
#include <bits/stdc++.h> using namespace std; const long long INF = 0x3f3f3f3f; const long long mod = 1000000007; const long double eps = 1e-14; int i, j; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; string s, t; getline(cin, t); n = stoll(t); getline(cin, s); vector<int> ...
8
#include <bits/stdc++.h> using namespace std; const int mod = 1000000007; string x; int res; int main() { cin >> x; res = 0; for (int i = 0; i < x.length(); i++) res = (2 * res + (x[i] - '0')) % mod; for (int i = 0; i < x.length() - 1; i++) res = 2 * res % mod; printf("%d\n", res); return 0; }
8
#include <bits/stdc++.h> using namespace std; int n, K, x[110], y[110], sign[110]; char s[10]; long long f[75][75]; vector<int> v[75]; inline long long dfs(int l, int r) { if (f[l][r] != -1) return f[l][r]; if (r == l + 1) { for (auto &p : v[l]) { if (sign[p] == 1) { if (y[p] != l && y[p] != l + 1...
16
#include <bits/stdc++.h> using namespace std; int a, n, m; int main() { cin >> n >> a; if (a % 2 == 0) a = n + 1 - a; m = (a + 1) / 2; cout << m; return 0; }
3
#include <bits/stdc++.h> using namespace std; const long long mod = 998244353; const long long inf = 2e18 + 1; const int mx = 4e7 + 1; vector<string> temp(7); vector<string> ans; vector<int> p(6); bool flag = false; void build_and_compare(string &first, string &second, string &third, string &four...
12
#include <bits/stdc++.h> using namespace std; const int maxn = 33333; const int fuck = 30000; int n, d; struct node { int d, v; }; vector<node> g[maxn]; int val[maxn]; bool vis[maxn]; bool cmp1(const node &a, const node &b) { return a.v > b.v; } int ans; int main() { scanf("%d %d", &n, &d); int maxx = 0; for (i...
11
#include <bits/stdc++.h> int main() { int n, sum = 0; int par = 0, impar = 0; int v[101]; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", v + i); sum += v[i]; if (v[i] % 2 == 0) par++; else impar++; } if (sum % 2 == 0) printf("%d\n", par); else printf("%d\n...
1
#include <bits/stdc++.h> using namespace std; int n, k; int dp[2][505][505]; int coin[505]; map<int, int> mp; int solve() { int ans = 0; for (int t = 1; t <= n; t++) { int i = t % 2; for (int j = 0; j <= k; j++) { for (int u = 0; u <= j; u++) { if (j >= coin[t] && u >= coin[t]) dp[i]...
11
#include <bits/stdc++.h> using namespace std; char st[100010]; char ans[100010]; char sto[100010]; int main() { int ctr = 0; int rctr = 0; int n; scanf("%d", &n); bool checker = true; for (int i = 0; i < n; i++) { scanf("%s", st); if (i == 0) { strcpy(sto, st); } int l = strlen(st); ...
6
#include <iostream> #include <cstdio> #include <algorithm> const int nn = 1e5 + 5; const int inf = 1e9; struct node { int val, lazy, pos; #define val(p) tree[p].val #define lazy(p) tree[p].lazy #define pos(p) tree[p].pos #define ls (p << 1) #define rs (p << 1 | 1) } tree[nn << 3]; void update(int p) { if (val(ls...
24
#include <bits/stdc++.h> using namespace std; template <typename T> void chkMax(T &x, T y) { if (y > x) x = y; } template <typename T> void chkMin(T &x, T y) { if (y < x) x = y; } template <typename T> void inline read(T &x) { int f = 1; x = 0; char s = getchar(); while (s < '0' || s > '9') { if (s == '...
17
#include <bits/stdc++.h> using namespace std; int n; int a[(int)(2e5 + 10)]; int Hash[105]; int sum[(int)(2e5 + 10)]; unordered_set<int> st; int main() { ios::sync_with_stdio(0); cin >> n; for (int i = 1; i <= n; i++) cin >> a[i], Hash[a[i]]++, st.insert(a[i]); vector<int> v; int maxx = 0; int D = 0; int ...
18
#include <bits/stdc++.h> using namespace std; const long long N = 1e4; long long n; double a[N]; int main() { ios_base::sync_with_stdio(false); cin >> n; cout.setf(ios::fixed); cout.precision(12); double sum = 0; for (int i = 0; i < n; i++) { cin >> a[i]; sum += a[i]; } if (sum / n >= 4.5) { ...
1
#include <bits/stdc++.h> using namespace std; struct Reg { int x, y, z; bool val; }; int main() { int n, valor; cin >> n; Reg ez[n]; int aux, aux1, aux2; for (int z = 0; z < n; z++) { cin >> valor; ez[z].val = false; for (int i = 0; i < valor / 3 + 1 && !ez[z].val; i++) { for (int j = 0;...
1
#include <bits/stdc++.h> int main() { char s[100]; scanf("%s", s); int upper = 0; int lower = 0; for (int i = 0; s[i] != '\0'; i++) { if (s[i] >= 97) lower++; else upper++; } if (lower > upper) { for (int j = 0; s[j] != '\0'; j++) { if (s[j] < 97) s[j] = s[j] + 32; } } ...
0
#include <bits/stdc++.h> using namespace std; const int maxint = -1u >> 1; int n; int dp[26][26]; char s[20]; int main() { while (scanf("%d", &n) == 1) { memset(dp, -1, sizeof(dp)); for (int i = 0; i < 26; ++i) dp[i][i] = 0; for (int i = 0; i < n; ++i) { scanf("%s", s); int len = strlen(s); ...
7
#include <bits/stdc++.h> using namespace std; int main() { int n, x; cin >> n >> x; int a[n + 2]; bool w[120] = {0}; for (int i = 0; i < n; i++) { cin >> a[i]; w[a[i]] = 1; } int mex; for (int i = 0;; i++) if (!w[i]) { mex = i; break; } if (mex == x) return puts("0"), 0; ...
2
#include <bits/stdc++.h> using namespace std; struct Point { long double x, y; Point() { x = y = 0; } Point(long double a, long double b) { x = a, y = b; } Point operator+(Point o) { return Point(x + o.x, y + o.y); } Point operator-(Point o) { return Point(x - o.x, y - o.y); } Point operator/(long double o)...
25
#include <bits/stdc++.h> using namespace std; long long per(long long l1, long long r1, long long l2, long long r2) { long long ans = max(0 * 1ll, min(r1, r2) - max(l1, l2) + 1); return ans; } signed main() { pair<long long, long long> t; long long n; cin >> n; t = {0, 0}; long long ans = 1; long long z...
6
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int q; cin >> q; while (q--) { long long n; cin >> n; long long l = 0, r = n - 1; long long ans = 0; while (l != r) { long long bridges = (l + r + 1) / 2; long long edges = (n - ...
13
#include <bits/stdc++.h> using namespace std; const long long inf = 1e15; const long long mod = 1e9 + 7; const int mxn = 5 * 1e5 + 10; void makeFaster() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } map<long long, long long> mp; map<long long, long long>::iterator it; long long bigmod(long long b, lo...
14
#include <bits/stdc++.h> using namespace std; const int MAXN = 100000 + 7; int a[MAXN], b[MAXN]; int dp[MAXN][2]; vector<int> link[MAXN]; long long sum = 0; void dfs(int u, int pre = -1) { dp[u][0] = dp[u][1] = 0; dp[u][b[u]]++; for (int i = 0; i < link[u].size(); ++i) { int v = link[u][i]; if (v != pre) ...
13
#include <bits/stdc++.h> #pragma GCC optimize("Ofast", 3, "inline") using namespace std; int n, m, k; int a[505], f[505], b[10005], e[10005]; int find(int x) { if (x == f[x]) return x; return f[x] = find(f[x]); } int main() { cin >> n >> m; for (int i = 0; i < m; i++) { scanf("%d%d", &b[i], &e[i]); } ci...
11
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; string t = ""; set<string> st; st.insert(s); for (int i = 1; i < s.length(); i++) { t = s.substr(i, s.length() - i) + s.substr(0, i); st.insert(t); } cout << st.size() << endl; }
1
#include <bits/stdc++.h> using namespace std; bool isLargerOrEq(long double a, long double b) { const long double eps = 1e-14; return a + eps >= b; } int main() { int y1, y2, yw, xb, yb, r; cin >> y1 >> y2 >> yw >> xb >> yb >> r; long double t1 = (yw - r) - (y1 + r); long double t2 = (yw - r) - (yb); t2 =...
12
#include <bits/stdc++.h> using namespace std; int main() { int n, i, c; cin >> n; if (n % 2 == 0) { c = n / 2; cout << c << endl; for (i = 0; i < c; i++) { cout << "2" << " "; } } else { c = (n - 1) / 2; cout << c << endl; for (i = 0; i < c - 1; i++) { cout << ...
0
#include <bits/stdc++.h> using namespace std; char s[1005], t[1005]; int n, m; int d[1005][1005], p[1005][1005]; const int INF = 1e9; vector<string> ans; int main() { scanf("%s%s", s, t); n = strlen(s); m = strlen(t); for (int i = 0; i < (int)(n + 1); ++i) for (int j = 0; j < (int)(m + 1); ++j) d[i][j] = IN...
13
#include <bits/stdc++.h> using namespace std; long long powm(long long base, long long exp, long long mod = 1000000007) { long long ans = 1; while (exp) { if (exp & 1) ans = (ans * base) % mod; exp >>= 1, base = (base * base) % mod; } return ans; } void fastscan(int &x) { register int c = getchar(); ...
10
#include <bits/stdc++.h> using namespace std; int a[111111]; int main() { int n, k; scanf("%d%d", &n, &k); for (int i = 0; i < n; i++) scanf("%d", &a[i]); --k; for (int i = 1;; i++) { if (k < i) { cout << a[k]; return 0; } k -= i; } return 0; }
2
#include <bits/stdc++.h> void pt() { std::cout << '\n'; } template <typename T, typename... Args> void pt(T a, Args... args) { std::cout << a << ' '; pt(args...); } using namespace std; const int N = 300005; int n; char s[N], t[N]; int sum[N]; void run() { cin >> (s + 1); for (int i = 1; i <= n; i++) { sum[...
17
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 7; int S[N], St[N], En[N], C[N], id[N], L[N], Ans[N], t; vector<int> adj[N], root; map<int, int> Map[4 * N]; vector<pair<int, int> > Query[N]; void dfs(int u, int p) { S[u] = 1; L[u] = L[p] + 1; St[u] = ++t; id[t] = u; for (int i = 0; i < adj[u...
16
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007ll; const int infty = numeric_limits<int>::max(); struct _ { _() { ios_base::Init i; ios_base::sync_with_stdio(0); cin.tie(0); } } _; void err() { cerr << endl; } template <typename T, typename... Ts> void err(T a, Ts... as) {...
7
#include <bits/stdc++.h> using namespace std; FILE *in, *out; void dosya() { in = stdin; out = stdout; } int N; void oku() { fscanf(in, "%d", &N); ; } void coz() { int i, top = 1; double pow = 1; for (i = 1; i <= N - 1; i++) top = (top * 3) % 1000003; fprintf(out, "%d", top); } int main() { dosya(); ...
5
#include <bits/stdc++.h> using namespace std; int main() { cin.tie(0); cin.sync_with_stdio(0); int a, b, c, d; cin >> a >> b >> c >> d; int total = max(max(a, b), max(c, d)); if (total - a > 0) { cout << total - a << " "; } if (total - b > 0) { cout << total - b << " "; } if (total - c > 0) ...
0
#include <bits/stdc++.h> using namespace std; void go() { int n, x; cin >> n; char c; cin >> c; string s; cin >> s; int cnt = 0; for (int i = 0; i < n; i++) { if (s[i] == c) cnt++; } if (cnt == n) { cout << "0\n"; return; } vector<int> v; for (int i = 0; i < n; i++) { if (s[i] ...
4
#include <bits/stdc++.h> using namespace std; const long long maxn = 1e6 + 100; const long long mod = 1e9 + 7; const long long inf = 1e18; long long t, n, m, d[maxn], par[maxn]; bool vis[maxn]; vector<long long> vec[maxn], g[maxn]; vector<pair<long long, long long> > ans; void dfs(long long v) { vis[v] = 1; vec[d[v...
18
#include <bits/stdc++.h> using namespace std; const int N = 5e3 + 5; int a[N]; int main() { int n, m, inf = 1e8; cin >> n >> m; int sum = 0; for (int i = 0; i < n; i++) sum += i / 2; if (sum < m) return cout << -1, 0; for (int i = 0; i < n; i++) { if (m >= i / 2) cout << i + 1 << " ", m -= i / 2; ...
14
#include <bits/stdc++.h> const int MAXM = 100007; double f[MAXM]; int main() { int m; double r; scanf("%d%lf", &m, &r); double diata = 0; const double d1 = sqrt(r * r * 2); const double d2 = sqrt(r * r * 8); f[1] = 2 * r + d1; for (int i = 2; i <= m; ++i) { diata += 2 * r; f[i] = f[i - 1] + diat...
11
#include <bits/stdc++.h> using namespace std; int n; vector<long long> v[8]; void go(int x) { if (x == 8) { set<long long> s; for (int i = 0; i < 8; i++) { for (int j = i + 1; j < 8; j++) { long long t = 0; for (int k = 0; k < 3; k++) { t += (v[i][k] - v[j][k]) * (v[i][k] - v[j...
12
#include <bits/stdc++.h> using namespace std; const int mod = 1000000007; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int t, n, m, k, q, x, a, b, c, d, w; cin >> n >> k; vector<string> v(n); unordered_map<string, int> map; for (int i = 0; i < n; i++) { cin >> v[i]; map[...
7
#include <bits/stdc++.h> using namespace std; inline void fastio() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); } const long long inf = 2e9; const long long UNDEF = -1; long long n; long long b; long long d; vector<long long> vec; long long func(vector<long long> mas, long long need) { long long...
15
#include <bits/stdc++.h> using namespace std; const int maxn = 1e3 + 10; int n, cnt[2 * maxn]; pair<int, int> p[maxn]; string nula; vector<string> s; struct itv { int val, l, r; }; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d", &p[i].first); p[i].second = i - 1; nula.push_bac...
18
#include <bits/stdc++.h> using namespace std; int N, K; vector<string> ans; string get_name(int num) { string ret = ""; ret.push_back('A' + num / 10); ret.push_back('a' + num % 10); return ret; } int main() { ios_base::sync_with_stdio(false); cin >> N >> K; string here; cin >> here; if (here == "YES")...
7
#include <bits/stdc++.h> using namespace std; int main() { int a[31] = {0, 4, 22, 27, 58, 85, 94, 121, 166, 202, 265, 274, 319, 346, 355, 378, 382, 391, 438, 454, 483, 517, 526, 535, 562, 576, 588, 627, 634, 636, 645}; int n; cin >> n; cout << a[n] << endl; return 0; }
9
#include <bits/stdc++.h> using namespace std; vector<int> aa; int pre[1005], nxt[1005], x, n, mark; void dfs(int u, int blo, int ff) { if (u == x) { ff = blo; mark = blo; } if (!pre[u]) { if (!ff) aa.push_back(blo); else { mark = blo - ff + 1; } } else dfs(pre[u], blo + 1, ff...
7
#include <bits/stdc++.h> using namespace std; const int MXN = (int)2e6 + 10; const int INF = (int)1e9 + 7; const long long LINF = (long long)1e18; const double EPS = (double)1e-9; string s1, s2; string mysort(string &s, int l, int r) { if ((r - l + 1) % 2 == 1) { return s.substr(l, r - l + 1); } int m = (l + ...
9
#include <bits/stdc++.h> using namespace std; const int N = 1005; int hs[10] = {0}; int save[N][2]; int ans = 0, n, m; struct node { int x, i; } deg[10]; int main() { cin >> n >> m; for (int i = 0; i < 10; i++) { deg[i].x = 0; deg[i].i = i; } for (int i = 1; i <= m; i++) { cin >> save[i][0] >> sav...
9
#include <bits/stdc++.h> using namespace std; const int MOD = 998244353; long long mul(long long a, long long b) { return a * b % MOD; } int add(int a, int b) { a += b; while (a >= MOD) a -= MOD; while (a < 0) a += MOD; return a; } long long power(long long a, long long b) { if (!b) return 1; long long r = ...
13
//#pragma GCC optimize("Ofast") #include <bits/stdc++.h> using namespace std; //vector string deque break continue #define forn(i, s, f) for (int i = (int)s; i < (int)f; i++) #define ll long long #define ull unsigned long long #define ld long double #define pii pair <int, int> #define fs first #define sc second #defi...
13
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); long long n; cin >> n; long long a[n]; for (int i = (0); i < (n); i++) cin >> a[i]; bool odd_neg = false; long long neg = 0; long long neg_index = -1; for (int i = (0); i < (n); i++) { if (a[i] < 0) { ...
9
#include <bits/stdc++.h> using namespace std; int main() { int m, n; cin >> n >> m; if (m > n) swap(n, m); if (m == 1) printf("%d\n", n); else if (m == 2) printf("%d\n", 2 * (2 * (n / 4) + min(n % 4, 2))); else printf("%d\n", n * m - n * m / 2); return 0; }
10
#include <bits/stdc++.h> using namespace std; int a[100100], k, cur, n; int cnt[100100]; bool chp[100100]; int main() { cin >> n >> k; for (int i = 0; i < n; ++i) { cin >> a[i]; if (!chp[a[i]]) { cur++; chp[a[i]] = 1; } } if (k == 1) { cout << 1 << " " << 1; return 0; } if (c...
7
#include <bits/stdc++.h> using namespace std; int read() { char ch = getchar(); int h = 0, t = 1; while ((ch > '9' || ch < '0') && ch != '-') ch = getchar(); if (ch == '-') t = -1, ch = getchar(); while (ch >= '0' && ch <= '9') h = h * 10 + ch - '0', ch = getchar(); return h * t; } const int N = 201000; str...
25
#include<iostream> #include<cstdio> #include<cstring> #include<cmath> #include<ctime> #include<algorithm> #include<queue> #include<set> #include<map> #include<bitset> #include<vector> using namespace std; typedef long long ll; typedef unsigned int ui; ll read() { ll x=0,f=1;char ch=getchar(); while(!isdigit(ch)){if...
24
#include <bits/stdc++.h> using namespace std; long long c[10]; bool first[10]; int main() { int n; while (cin >> n) { string s; memset(c, 0, sizeof(c)); memset(first, 0, sizeof(first)); for (int i = 0; i < n; i++) { cin >> s; int base = 1; first[s[0] - 'a'] = 1; for (int j = ...
9
#include <bits/stdc++.h> using namespace std; const int maxn = 1005; int x[maxn]; double y[maxn]; int main() { int n; int r; scanf("%d%d", &n, &r); for (int i = 1; i <= n; i++) { scanf("%d", &x[i]); y[i] = r; if (i > 1) { for (int j = 1; j < i; j++) { int dt = x[i] - x[j]; if (...
7
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; int n, q, s[N]; vector<pair<int, int> > vec[N]; struct node { int sum, lazy; } seg[N << 2]; void shift(int id, int b, int e) { if (seg[id].lazy) { int mid = (b + e) >> 1, lc = id * 2, rc = lc | 1; seg[lc].lazy ^= 1; seg[rc].lazy ^= 1; ...
20
#include <bits/stdc++.h> #pragma GCC target("sse4,avx") using BigInteger = std::string; BigInteger multiply(const BigInteger& in, int mult) { int c = 0; BigInteger res; for (size_t i = 0; i < in.length(); i++) { c += (in[i] - '0') * mult; res.push_back((c % 10) + '0'); c /= 10; } while (c != 0) { ...
17
#include <bits/stdc++.h> using namespace std; int a[1000005]; int b[1000005]; int main() { int t; scanf("%d", &t); for (int ti = 0; ti < t; ti++) { int n; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", &a[i]); } sort(a, a + n); int cnt = 0; for (int i = 0; i < n - 1; ...
8
#include <bits/stdc++.h> using namespace std; const int maxn = 100010; struct vec { long double x, y; vec(double x = 0, double y = 0) : x(x), y(y) {} inline long double mo() { return ((x) * (x)) + ((y) * (y)); } vec operator-(const vec &a) const { vec ret; ret.x = x - a.x; ret.y = y - a.y; retur...
11
#include <bits/stdc++.h> using namespace std; long long pwr(long long base, long long p, long long mod) { long long ans = 1; while (p) { if (p & 1) ans = (ans * base) % mod; base = (base * base) % mod; p /= 2; } return ans; } long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b...
0
#include <bits/stdc++.h> using namespace std; char buf[1 << 21], *p1 = buf, *p2 = buf; template <class T> void read(T &x) { x = 0; int c = getchar(); int flag = 0; while (c < '0' || c > '9') flag |= (c == '-'), c = getchar(); while (c >= '0' && c <= '9') x = (x << 3) + (x << 1) + (c ^ 48), c = getchar(); ...
20
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; int n, a[N], tmp_a[N], tmp_tot; int tot, px[N], py[N], pz[N], bc[1 << 20 | 10]; inline void Do(int x, int y, int z) { a[x] ^= 1; a[y] ^= 1; a[z] ^= 1; assert(x < y && y < z); assert(y - x == z - y); ++tot; px[tot] = x; py[tot] = y; ...
18
#include <bits/stdc++.h> using namespace std; const double EPS = 1e-8; const int INF = 0x3F3F3F3F; const int64_t LINF = 4611686018427387903; const int MOD = 1e9 + 7; struct seg { int x1, y1, x2, y2; }; bool cmp(seg a, seg b) { return a.x1 < b.x1; } const int N = 10025; int bit[N]; void mod(int pos, int val) { for (...
14
#include <bits/stdc++.h> using namespace std; inline int read() { int x = 0, f = 1; char ch; for (ch = getchar(); !isdigit(ch); ch = getchar()) if (ch == '-') f = -f; for (; isdigit(ch); ch = getchar()) x = 10 * x + ch - '0'; return x * f; } int query(vector<int> s, vector<int> t, int node) { cout << s....
23
#include <bits/stdc++.h> long long K, L, R, P, N, Ans, _K; int TestCase; long long Quick(long long A, long long B, long long M) { long long C(1); for (; B; B >>= 1) { if (B & 1) C = (C * A) % M; A = (A * A) % M; } return C; } int main() { for (scanf("%d", &TestCase); TestCase--;) { scanf("%I64d%I6...
18
#include <bits/stdc++.h> int main() { int n, m; scanf("%d %d", &n, &m); int ans = 0; for (int i = 0; i <= 40; i++) for (int j = 0; j <= 40; j++) if (i * i + j == n && i + j * j == m) ans++; printf("%d\n", ans); return 0; }
0
#include <bits/stdc++.h> struct Point { int x, y; Point(int x, int y) : x(x), y(y) {} Point() : Point(0, 0) {} void read() { scanf("%d %d", &x, &y); } struct Point operator-(struct Point p) const { return Point(x - p.x, y - p.y); } double arg() { return atan2(y, x); } } ps[305]; int64_t dp[305][6]; in...
21
#include <bits/stdc++.h> using namespace std; const int maxn = 5000; const int mod = 998244353; int n; int E[maxn + 5][maxn + 5]; int ans[maxn + 5]; namespace usual { int fac[maxn + 5], ifac[maxn + 5]; int add(int ta, int tb) { return ta + tb >= mod ? ta + tb - mod : ta + tb; } int sub(int ta, int tb) { return ta < tb ...
23
#include <bits/stdc++.h> using namespace std; int N; int M; int sgn(int x) { if (x >= 0) return 1; return -1; } vector<int> v; int main() { cin >> N >> M; int mid = (M - 1) / 2 + 1; int p = mid; int delta; if (M % 2) delta = -1; else delta = +1; v.push_back(p); while (p != M) { p += delt...
5
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma") #pragma GCC optimize("unroll-loops") using namespace std; long long int MOD = 998244353; double eps = 1e-12; void solve(); int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ...
4
#include <bits/stdc++.h> using namespace std; const int N = 505, Mo = 1e9 + 7; int n, k, m, x, f[N], g[N], a[N], b[N], c[N], p[N]; int F[N], G[N], H[N]; long long T; void mul(int *a, int *b, int *c) { for (int i = 0; i <= 2 * k - 2; i++) g[i] = 0; for (int i = 0; i <= k - 1; i++) for (int j = 0; j <= k - 1; j++...
25
#include <bits/stdc++.h> template <class T> inline T min(T a, T b) { return a < b ? a : b; } template <class T> inline T max(T a, T b) { return a > b ? a : b; } template <class T> inline T fabs(T a) { return a > 0 ? a : -a; } template <class T> inline T isOdd(T a) { return a & 1; } template <class T> inline T g...
7
#include <bits/stdc++.h> using namespace std; int pref[1000005]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long z; cin >> z; string a; cin >> a; string s = "a"; a = s + a; for (int q = 1; q < a.size(); q++) { pref[q] = pref[q - 1]; if (a[q] == '1') pr...
8
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 100; int n, m; int maxN; vector<int> v[4 * N], setBuyer[4 * N], setDish[4 * N]; int bit[N]; int rez[N]; struct Dish { int price, standard, beauty; int idx; void show() { cout << price << ' ' << standard << ' ' << beauty << ' ' << idx << '\n'; ...
17
#include <bits/stdc++.h> using namespace std; template <typename Int> ostream& operator<<(ostream& s, vector<Int>& v) { s << '['; for (auto i = v.begin(); i != v.end(); i++) { s << *i; if (i != prev(v.end())) s << ", "; } s << ']'; return s; } template <typename Int, typename INT> ostream& operator<<(...
14
#include <bits/stdc++.h> using namespace std; int n; int head[1000006], to[1000006 * 2], nex[1000006 * 2], ecn = 1; void ade(int u, int v, int w) { to[++ecn] = v, nex[ecn] = head[u], head[u] = ecn; } int deg[1000006]; int vis[1000006], res[1000006]; void dfs(int u) { for (int& i = head[u]; i; i = nex[i]) if (!v...
18
#include <bits/stdc++.h> using namespace std; int l, r; int main() { cin >> l >> r; cout << ((l == r) ? l : 2); return 0; }
2
#include <bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:268435456") int main() { int n; cin >> n; int mp[201][201]; for (int i = 0; i < 200; i++) for (int j = 0; j < 200; j++) mp[i][j] = 0; mp[0][0] = n; bool ch = 0; do { ch = 0; for (int i = 0; i < 150; i++) for (i...
12
#include <bits/stdc++.h> #pragma comment(linker, "/stack:200000000") #pragma GCC optimize("Ofast,no-stack-protector") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #pragma GCC optimize("unroll-loops") static const int LOGN = 18; static const int MAXN = 1 << LOGN; static const int MODULUS...
26
#include <bits/stdc++.h> using namespace std; long long root[1005]; long long check[1005]; long long gover[1005]; long long conect[1005]; long long sz[1005]; long long n, m, k, tmp; long long fin(long long x) { if (root[x] == x) return x; return root[x] = fin(root[x]); } void join(long long x, long long y) { chec...
7
#include <bits/stdc++.h> using namespace std; int main(int argc, char *argv[]) { int TC; cin >> TC; while (TC--) { int n; cin >> n; string s, t; cin >> s >> t; int dif_cnt = 0; for (int i = 0; i < n; i++) { if (s[i] != t[i]) dif_cnt++; } if (dif_cnt != 2) { cout << "No"...
2
#include <bits/stdc++.h> using namespace std; long long n, k, A, B, x; vector<long long> idx; long long Cost(long long beg, long long end) { auto r = upper_bound(idx.begin(), idx.end(), end), l = upper_bound(idx.begin(), idx.end(), beg - 1); if (r - l == 0) return A; if (beg == end) return (r - l) * B; l...
9
#include <bits/stdc++.h> using namespace std; struct Interval { double X0, Y0; double XF, YF; Interval(double x0, double y0, double xf, double yf) { X0 = x0; Y0 = y0; XF = xf; YF = yf; } Interval *getRange(double x0, double xf) { double y0 = Y0 + (slope() * (x0 - X0)); double yf = Y0 +...
17
#include <bits/stdc++.h> using namespace std; const long long N = 1e6 + 7, oo = 1e9 + 7, OO = 1e18 + 7; int n, m, ans, mv[5][2] = {{-1, -1}, {-1, 0}, {-1, 1}, {0, 0}, {1, 0}}; char ch[20][20], tmp[20][20]; void rot() { for (int i = 0; i < 5; i++) { pair<int, int> tmp = {mv[i][0], mv[i][1]}; mv[i][0] = tmp.sec...
15
#include <bits/stdc++.h> using namespace std; vector<pair<int, int>> dirs = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}}; void solve() { int n; cin >> n; vector<int> arr(n); for (int i = 0; i < n; i++) { cin >> arr[i]; } sort(arr.begin(), arr.end()); long long int countS = 1; long long int countE = 1; for (...
5
#include <bits/stdc++.h> using namespace std; int main() { int n, t, sum = 0, flag = 0; cin >> n >> t; int a[n]; for (int i = 0; i < n - 1; i++) { cin >> a[i]; } while (sum < (t - 1)) { sum = sum + a[sum]; } if (sum == (t - 1)) { cout << "YES"; } else cout << "NO"; }
2
#include <bits/stdc++.h> using namespace std; const int Maxn = 2e5; struct Edge { int v, nxt; Edge() {} Edge(int v0, int n0) { v = v0; nxt = n0; } }; Edge e[Maxn * 2 + 5]; int head[Maxn + 5]; int nume; inline void initEdge() { nume = 0; memset(head, 0, sizeof(head)); } inline void addEdge(int u, int...
11