solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> using namespace std; int n; struct edge { int y, next; } e[3010 << 1]; int first[3010], len = 0; void buildroad(int x, int y) { e[++len] = (edge){y, first[x]}; first[x] = len; } int fa[3010][3010], sz[3010][3010]; void init(int x, int p) { sz[p][x] = 1; for (int i = first[x]; i; i = e...
15
#include <bits/stdc++.h> using namespace std; const int maxn = 100100; bool is_pri[maxn]; int in[maxn], pos[maxn]; int pri[maxn]; int main() { int i, j, k, t, n, m, e = 0; char s[10]; int ok; memset(is_pri, 0, sizeof(is_pri)); for (i = 2; i < maxn; ++i) if (!is_pri[i]) { pri[e++] = i; for (j =...
8
#include <bits/stdc++.h> using namespace std; double PI = 3.141592653589793; const double EPS = 1e-8; const int N = 1e6 + 5; const long long mod = 1e9 + 7; const int oo = 1e9; int dx[] = {0, 0, 1, -1, 1, -1, 1, -1}; int dy[] = {1, -1, 0, 0, -1, 1, 1, -1}; int n; long long t[N]; long long dp[N][2]; int vis[N][2]; long l...
9
#include <bits/stdc++.h> using namespace std; bool pr(int n) { for (int i = 2; i <= sqrt(n); i++) { if (n % i == 0) return false; } return true; } int isPow2(int a) { return !(a & (a - 1)); } int main() { int tests; cin >> tests; while (tests--) { int m, n; cin >> m >> n; int** a = new int*[...
4
#include <bits/stdc++.h> using namespace std; const double EPS = 1e-8; int n, k, t, cc; int main() { scanf("%d", &t); while (t--) { cc = 0; scanf("%d%d", &n, &k); for (int i = 1; i < n; i++) { for (int j = 0; j < n; j++) { printf("%d %d\n", j + 1, (i + j) % n + 1); cc++; if...
7
#include <bits/stdc++.h> using namespace std; int main() { int n; int k; cin >> n >> k; if ((n * (n - 1)) / 2 <= k) { cout << "no solution" << endl; return 0; } int y = 0; for (int i = 0; i < n - 1; i++) { cout << 0 << " " << y << endl; y += 2; } cout << 0 << " " << y - 1 << endl; re...
5
#include <bits/stdc++.h> using namespace std; const int inf = 1e9 + 5; const long long linf = 1e18 + 5; const int N = 1e5 + 5; int n, a[N], odd, st, h[N]; bool fl(int k) { memset(h, 0, sizeof(h)); int st = k, nd = k + 1; if (k < n + 1 >> 1) nd = n - k + 1; for (int i = 1; i <= st; i++) h[a[i]]++; for (int i =...
17
#include <bits/stdc++.h> using namespace std; inline bool scan_d(int &num) { char in; bool IsN = false; in = getchar(); if (in == EOF) return false; while (in != '-' && (in < '0' || in > '9')) in = getchar(); if (in == '-') { IsN = true; num = 0; } else num = in - '0'; while (in = getchar(),...
9
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; struct edge { int from, to; ll f, c; }; vector<edge> edges; vector<vector<int>> adjlist; int s, t; vector<int> pt, dist; ll flow, lim; queue<int> q; int addEdge(int from, int to, ll c) { int res = (int)(edges).size(); ad...
16
#include <bits/stdc++.h> using namespace std; long long read() { long long x = 0, f = 0; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = 1; ch = getchar(); } while (ch >= '0' && ch <= '9') x = (x << 3) + (x << 1) + ch - '0', ch = getchar(); return f ? -x : x; } void write(...
15
#include <bits/stdc++.h> using namespace std; int a1, b1, c1; int a2, b2, c2; int d[8]; int f[8]; bool solve(int a1, int b1, int c1, int a2, int b2, int c2) { if (a1 < 0 || b1 < 0 || c1 < 0) return 0; if (a2 < 0 || b2 < 0 || c2 < 0) return 0; f[1] = min({a1, b1, c1, d[1]}); a1 -= f[1], b1 -= f[1], c1 -= f[1]; ...
19
#include <bits/stdc++.h> using namespace std; long long k; long long succ[10]; long long cnt = 0; const long long mod = 1e9 + 7; void recur(long long pos) { if (pos == k + 1) { for (long long i = 1; i <= k; i++) { long long u = i; bool flag = false; for (long long j = 0; j <= k; j++) { i...
7
#include <bits/stdc++.h> using namespace std; int q[20]; int get(int n) { int t = 0; while (n) { q[t] = n % 2; n = n / 2; t++; } for (int i = t; i < 8; i++) q[i] = 0; return 8; } int main() { char s[110]; gets(s); int sum1, sum; for (int i = 0; i < strlen(s); i++) { if (i == 0) sum1 = ...
5
#include <bits/stdc++.h> using namespace std; const int N = 200005, M = 200000; int n, a[N], cn[N], c[N], c0[N], ans, maxn, p[N << 1]; template <class I> void Max(I& p, int q) { p = (p > q ? p : q); } void ins(int x) { --c0[c[x]], ++c[x], ++c0[c[x]], Max(maxn, c[x]); } void del(int x) { --c0[c[x]], --c[x], ++c0[c[x]]...
18
#include <bits/stdc++.h> using namespace std; int n, L[500010], R[500010], a[500010]; pair<int, int> b[500010]; void erase(int x) { int u = L[x], v = R[x]; L[v] = u, R[u] = v; } int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d", &a[i]), b[i] = make_pair(a[i], i); sort(b + 1, b + n + 1); ...
17
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; string s; cin >> s; bool ok = 0; for (int i = 0; i < n; i++) { if (s[i] == '8' && (n - i) >= 11) { ok = 1; break; } } if (ok) puts("YES"); ...
0
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10; int n, m, l[maxn]; vector<int> s[maxn], G[maxn]; bool vis[maxn], changed[maxn]; void dfs(int u) { vis[u] = changed[u] = true; for (int i = 0; i < G[u].size(); i++) { int v = G[u][i]; if (!vis[v]) { dfs(v); } } } int main() ...
13
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long n, m, d, c, suma = 0; cin >> n >> m >> d; vector<long long> v; for (long long i = 0; i < m; i++) { cin >> c; suma += c; v.push_back(-c); } long long pos = -1; vector<lon...
9
#include <bits/stdc++.h> using namespace std; int F(int n, int p) { if (n >= p) return 0; int result = 1; for (int i = 1; i <= n; i++) result = (result * i) % p; return result; } long long int func(int a, int b, int c) { int arr[a + 1][b + 1][c + 1][4]; for (int i = 0; i <= a; i++) { for (int j = 0; j <...
13
#include <bits/stdc++.h> using namespace std; long long int Mod = 1000000007; int main() { int i, j, k, l, m, n, x, y, z, a, b, r; scanf("%d", &n); string A[n]; for (i = 0; i < n; i++) { cin >> A[i]; } for (i = 0; i < n; i++) { int p = 0; for (j = 0; j < i; j++) { if (A[i] == A[j]) { ...
0
#include <bits/stdc++.h> int n; char str[2000000]; int main() { n = 0; for (;;) { char c = getchar(); if (c != '.' && (c < '0' || c > '9')) break; str[++n] = c; } int poi = 1; for (; poi <= n && str[poi] != '.'; poi++) ; if (poi > n) str[++n] = '.'; int s = 1; for (; s < n && (str[s] == ...
10
#include <bits/stdc++.h> using namespace std; void solve() { long long int n, k; cin >> n >> k; int temp = n - 1; long long int j = k / temp; long long int i = k % temp; if (i == 0) { cout << n * j - 1 << endl; } else { cout << n * j + i << endl; } } int main() { ios_base::sync_with_stdio(fals...
4
#include <bits/stdc++.h> const int MAX_SIZE = 1000; int mat[MAX_SIZE + 10][MAX_SIZE + 10]; int h, w; int hor[2][MAX_SIZE + 10][MAX_SIZE + 10], ver[2][MAX_SIZE + 10][MAX_SIZE + 10]; void change(int x, int y) { mat[x][y] ^= 1; for (int i = 1; i <= w; i++) if (mat[x][i]) hor[0][x][i] = hor[0][x][i - 1] + 1; ...
12
#include <bits/stdc++.h> using namespace std; inline int in() { int k = 0; char ch = getchar(); while (ch < '-') ch = getchar(); while (ch > '-') k = k * 10 + ch - '0', ch = getchar(); return k; } const int N = 1e5 + 5; int head[N], to[N << 1], nxt[N << 1], cnt; double sum = 0; double p[N]; inline void add(in...
14
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; vector<int> son[N]; int lt[N]; int cal(int x) { int need = x - son[0].size(); int cnt = 0, ret = 0; for (int i = 1; i < N; i++) { for (int j = 0; j < son[i].size(); j++) { if (son[i].size() - j >= x) { ret += son[i][j]; ...
13
#include <bits/stdc++.h> using namespace std; int a[100005]; int main() { int n; cin >> n; int l = 1, n1 = 0, n2 = 0, m = 0; int s = 0; for (int i = 0; i < n; ++i) { cin >> a[i]; } for (int i = 1; i < n; ++i) { if (a[i] == a[i - 1] + 1) { if (m == 1) { l = i - n1 + 1; if (l >...
6
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); int t; cin >> t; while (t--) { int n; cin >> n; vector<bool> unvis(n, 1); vector<pair<int, map<int, int>>> checks; for (int i = 1; i <= n; i++) { int k; cin...
4
#include <bits/stdc++.h> using namespace std; const int INF = 1.01e9; int main() { int n; while (scanf("%d", &n) == 1) { vector<int> a(n); for (int i = 0; i < n; i++) scanf("%d", &a[i]); int sum = 0; int sumA = 0; vector<int> ans; for (int i = 0; i < n; i++) { if (i == 0 || a[i] * 2 <=...
0
#include <bits/stdc++.h> using namespace std; long long mod = 1000000007LL; long long large = 2000000000000000000LL; int main() { int n, I; cin >> n >> I; I *= 8; vector<int> a(n, 0); for (int i = 0; i < n; i++) scanf("%d", &a[i]); sort(a.begin(), a.end()); vector<pair<int, int> > e; for (int i = 0; i <...
8
#include <bits/stdc++.h> using namespace std; set<int> a[101000]; int ans[101000]; bool used[101000]; int b[5], k[5]; bool f = true; void dfs(int v, int mn) { used[v] = true; ans[v] = mn; b[mn] = v; k[mn]++; for (int i : a[v]) if (!used[i]) { for (int j = 1; j <= 3; j++) if (j != mn && !a[i]...
11
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; int n; int f[2][4005], g[2][4005]; char s[2005], t[2005]; void solve() { int i, j; scanf("%d", &n); scanf("%s", s + 1); scanf("%s", t + 1); for (i = 1; i <= n; i += 2) { if (s[i] != '?') s[i] ^= 1; if (t[i] != '?') t[i] ^= 1; } ...
20
#include <bits/stdc++.h> using namespace std; using ll = long long; int a[100010]; int vis[100010]; int main() { int n; cin >> n; int m = n; for (int i = 1; i <= n; i++) cin >> a[i]; while (n > 0 && a[n] == 0) n--; if (n == 0) return cout << 0, 0; if (a[n] >= 2) return cout << -1, 0; vector<pair<int, in...
11
#include <bits/stdc++.h> using namespace std; int N = 1000000007; vector<vector<long long>> binom(5001, vector<long long>(5001)); void find_binom() { for (int i = 0; i < binom.size(); ++i) { for (int j = 0; j < binom[1].size(); ++j) { if (j <= i) { if (j == 0 || j == i) { binom[i][j] = 1; ...
16
#include<iostream> #include<algorithm> #include<vector> #include<map> #include<unordered_set> #include<set> #include<climits> #include<queue> #include<math.h> using namespace std; #define inf LLONG_MAX #define ll long long int #define mod 1000000007 #define pb push_back #define in insert void power(int x, ll n) { l...
0
#include <bits/stdc++.h> using namespace std; int main() { long long t, T, n, a = 2; cin >> n; if (n > 9) { long long ans = 9; for (t = 100; t <= n; t *= 10, a++) { ans += ((t) - (t / 10)) * a; } t /= 10; ans += (n - t + 1) * a; cout << ans; } else cout << n; }
4
#include <bits/stdc++.h> using namespace std; int n; vector<int> a; int main() { scanf("%d", &n); a.resize(n); for (int i = 0; i < n; i++) scanf("%d", &a[i]); sort(a.begin(), a.end()); for (int i = 0; i < n - 1; i++) if (2 * a[i] > a[i + 1] && a[i] != a[i + 1]) { cout << "YES" << endl; return ...
6
#include <bits/stdc++.h> using std::max; const int N = 100005; int a[N], n; long long Ans[N], sum; struct note { int x, id; bool operator>(const note x) const { return this->x > x.x; } bool operator<(const note x) const { return this->x < x.x; } } tree[N * 10]; void build(int l, int r, int k) { if (l == r) { ...
15
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int a, b, c, s = 0; cin >> a >> b >> c; if (b > 0) { c /= 2; if (b > c) { s += c * 3; b -= c; } else { s += b * 3; b = 0; } b = b / 2; if (a > b...
0
#include <bits/stdc++.h> using namespace std; int inf; const double eps = 1e-8; const double pi = acos(-1.0); template <class T> int chkmin(T &a, T b) { return a > b ? a = b, 1 : 0; } template <class T> int chkmax(T &a, T b) { return a < b ? a = b, 1 : 0; } template <class T> T sqr(T a) { return a * a; } template...
15
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n, x; cin >> n; priority_queue<int, vector<int>, greater<int> > p; for (int i = 0; i < n; i++) cin >> x, p.push(x); int cnt = 0; while (p.size() > 1) { int a = p.top(); ...
7
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; const double eps = 1e-12; int main() { string a; int n, i, j; while (cin >> n) { cin >> a; int ans = 0; int sit = 0; int marki = 0; for (i = 0; i < n; i++) { if (a[i] == 'L') { marki = i + 1; } ...
3
#include <bits/stdc++.h> using namespace std; int main() { long long int i, j, k, a, b, c, d, f, e, n, t, p, m; map<long long int, long long int> ma, sa; cin >> n; while (n--) { cin >> t; vector<long long int> v(102); for (i = 1; i <= t; i++) cin >> v[i]; for (i = 1; i <= t; i++) { m = 100...
6
#include <bits/stdc++.h> using namespace std; int n, x, y; int indx = -1; int sxor = 0; vector<pair<vector<int>, int> > subs; void solve2(vector<int> v) { int s = 0, e = v.size() - 1, temp; while (s <= e) { int mid = (s + e) >> 1; cout << '?'; cout << " " << mid - s + 1; for (int i = s; i <= mid; i+...
16
#include <bits/stdc++.h> using namespace std; string A[4]; int main() { int n, k; cin >> n >> k; bool alleq = true; int which; string s; int v; bool valid = true; for (int i = 0; valid and i < n; ++i) { for (int j = 0; j < 4; ++j) { cin >> s; v = 0; int r, c = 0; for (r = s.s...
8
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 7; void solve() { long long int n, m, ans = 0; string s; cin >> s; n = s.size(); vector<long long int> a(n), b(n, 0); for (auto i = 0; i < (s.size()); i++) { if (s[i] == '0') a[i] = 0; else a[i] = 1; } long long int co...
0
#include <bits/stdc++.h> struct eugin { int x, y; }; int n, m; int s[210]; int a[210][210]; bool b[210]; int ans; int op[210 << 1][2]; eugin loc[210]; int main() { int i, j, t, p; memset(b, false, sizeof(b)); scanf("%d%d", &n, &m); for (i = 1; i <= m; i++) { scanf("%d", &s[i]); for (j = 1; j <= s[i]; ...
10
#include <bits/stdc++.h> using namespace std; const int N = 400000 + 7; const int M = N / 3; const long long MM = 1ll * M * M; const int inf = 1e9 + 7; const long long linf = 1ll * inf * inf; const double pi = acos(-1); const double eps = 1e-7; const bool multipleTest = 0; int inverse(int x, int n) { int r = n, newr ...
20
#include <bits/stdc++.h> using namespace std; const long long int K = 998244353; long long int mu(long long int a, long long int n) { if (n == 0) return 1; long long int q = mu(a, n / 2); if (n % 2 == 0) return q * q % K; return q * q % K * a % K; } long long int inv[100005]; namespace Poly { inline void fft(ve...
24
#include <bits/stdc++.h> using namespace std; const int N = 1e6; int n; int p[N], q[N]; bool visited[N]; vector<int> a[N + 1]; int sizecc(int u) { int k = 0; while (!visited[u]) { visited[u] = true; k++; u = p[u]; } return k; } void sqrtPermEven(int u, int v, int k) { for (int t = 0; t < k; t++) {...
14
#include <bits/stdc++.h> using namespace std; const int MAXN = 200005; int N, K, M, X[MAXN], A[MAXN], B[MAXN]; long long T[MAXN]; struct Car { int id; long long tim; Car() {} Car(int _id, long long _tim) { id = _id; tim = _tim; } bool operator<(const Car &b) const { if (tim != b.tim) return tim ...
17
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; int i, pos = -1, f2 = 0; for (i = 0; i < s.length(); i = i + 1) { if (s[i] == '2') { if (f2 == 0) { f2 = 1; pos = i; } } } if (pos == -1) { sort(s.begin(), s.end()); cout << s << endl; ...
6
#include <bits/stdc++.h> using namespace std; int M[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; int main() { int m, d; cin >> m >> d; cout << (M[m] - (8 - d) + 6) / 7 + 1 << endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 7; int n; vector<int> vt; int par[N]; int findpar(int u) { if (par[u] == u) return u; return par[u] = findpar(par[u]); } void makeset(int x, int y) { par[findpar(x)] = findpar(y); } int main() { std ::ios ::sync_with_stdio(false); cin.tie(0); c...
6
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; vector<int> s(k); int prev = 0, prevPrev = 0; for (int i = 0; i < n; i++) { int curr; cin >> curr; if (prev != curr) { s[curr - 1]--; if (prev) if (curr == prevPrev || prev == prevPrev) s[prev -...
8
#include <bits/stdc++.h> using namespace std; const int M = 200100; struct node { int num; int price; int front; int back; node() {} node(int a, int b, int c, int d) { num = a; price = b; front = c; back = d; } bool operator<(const node& a) const { return a.price < price; } } a[M]; int m...
6
#include <bits/stdc++.h> using namespace std; long long rdtsc() { long long tmp; asm("rdtsc" : "=A"(tmp)); return tmp; } inline int myrand() { return rand(); } inline int rnd(int x) { return myrand() % x; } const int inf = (int)1.01e9; const long double eps = 1e-9; const long double pi = acos((long double)-1.0); ...
16
#include <bits/stdc++.h> using namespace std; class intervalac { vector<int> l, r; vector<long long> v, lazy; void unlazy(int vr) { v[vr * 2 + 1] += lazy[vr]; v[vr * 2 + 2] += lazy[vr]; lazy[vr * 2 + 1] += lazy[vr]; lazy[vr * 2 + 2] += lazy[vr]; lazy[vr] = 0; } public: intervalac(int n, ...
18
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long n, m; cin >> n >> m; long long s = n + 1; vector<long long> v[s]; long long a = 1; for (long long i = 0; i < a << n; i++) { long long temp; cin >> temp; v[0].push...
9
#include <bits/stdc++.h> using namespace std; bool isinc(long long int v[], long long int n) { long long int i, j, k; for (i = 0; i <= n - 2; i++) { if (v[i] > v[i + 1]) { return false; } } return true; } bool isdes(long long int arr[], long long int n) { for (long long int i = 0; i <= n - 2; i+...
6
#include <bits/stdc++.h> using namespace std; int n; vector<int> prime; void creating_seive(bool a[], int n) { for (int i = 2; i <= (int)(pow(n, 0.5)); i++) { if (a[i] == 1) { int k = 0; for (int j = i * i; j <= n; j = i * i + k * i) { a[j] = 0; k++; } } } for (int i = 2;...
5
#include <bits/stdc++.h> using namespace std; int main() { int n, a, b; cin >> n >> a >> b; if (a * b < n) { cout << -1 << endl; return 0; } int kk = 0; for (int i = 0; i < a; i++) { for (int j = 0; j < b; j++) { if (kk == 0) { if ((i * b + j + 1) <= n) cout << i * b + j ...
2
#include <bits/stdc++.h> using namespace std; const int mxn = 2e3 + 100, mod = 1e9 + 7; int a[mxn], b[mxn], c[mxn]; int mult(int x, int y) { long long ans = 1LL * x * y; return ans >= mod ? ans % mod : ans; } int add(int x, int y) { x += y; while (x >= mod) x -= mod; return x; } int expo(int x, int y) { int...
11
#include <bits/stdc++.h> using namespace std; int a[15] = {0}; int main() { char s[20]; cin >> s + 1; int cnt = 0; int pos = 0; for (int i = strlen(s) - 1; i > 0; i--) { if (s[i] == '0') cnt++; else { pos = i; break; } } bool flag = 1; for (int i = 1; i <= pos / 2; i++) { ...
1
#include <bits/stdc++.h> using namespace std; long long a, b, p; long long x; long long powMod(long long a, long long j, long long p) { long long ans = 1; while (j) { if (j & 1) { (ans *= a) %= p; } (a *= a) %= p; j /= 2; } return ans; } long long inv(long long y, long long p) { return pow...
13
#include <bits/stdc++.h> using namespace std; const int MAX = 17; const int N = 102; const int MAXBi = 60; int memo[N][1 << MAX]; int a[N]; int n; int primes[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59}; vector<int> primeFactors[MAXBi]; int dp(int i, int mask) { if (i == n) { return 0; }...
12
#include <bits/stdc++.h> using namespace std; int arr[400001]; map<int, int> freq; int main() { int n, k; cin >> n >> k; for (int i = 0; i < n; i++) cin >> arr[i]; int start = 0; int next = 0; long long int ans = 0; while (start < n) { while (next < n && freq[arr[next]] < k - 1) { freq[arr[next]...
11
#include <bits/stdc++.h> using namespace std; int main() { long long int n, m, dx, dy; cin >> n >> m >> dx >> dy; long long int u[n + 100], i, varx, vary; vector<long long int> v; for (i = 0; i < n; i++) u[(i * dx) % n] = (i * dy) % n; for (i = 0; i < n; i++) v.push_back(0); for (i = 0; i < m; i++) { ...
12
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; int a[n], utype[101] = {0}; for (int i = 0; i < n; i++) { cin >> a[i]; utype[a[i]]++; } int maxim = 0; int type = 0; for (int i = 1; i <= 100; i++) { if (utype[i] != 0) type++; maxim = max(utype[i], maxim...
1
#include <bits/stdc++.h> using namespace std; const int maxn = 200005; vector<int> edge[maxn]; void marry(int a, int b) { edge[a].push_back(b); } int in[maxn], out[maxn]; void dfs(int node, int pre, int& now) { in[node] = ++now; int len2 = edge[node].size(); for (int i = 0; i < len2; ++i) { if (edge[node][i] ...
16
#include <bits/stdc++.h> using namespace std; int n, a[205]; int main() { scanf("%d", &n); for (int i = 1; i <= 2 * n; i++) { scanf("%d", &a[i]); } int ans = 0; for (int i = 1; i <= 2 * n; i += 2) { if (a[i + 1] != a[i]) { for (int j = i + 2; j <= 2 * n; j++) { if (a[j] == a[i]) { ...
6
#include <bits/stdc++.h> using namespace std; string a[2005], b[2005]; int main() { int n, m; scanf("%d%d", &n, &m); for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < m; i++) cin >> b[i]; for (int i = 0; i <= n - m; i++) { for (int j = 0; j <= n - m; j++) { bool temp = true; for (in...
12
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; vector<pair<int, int> > ans(t); for (int i = 0; i < t; i++) { int l; int r; cin >> l; cin >> r; ans[i].first = l; ans[i].second = 2 * l; } for (int i = 0; i < t; i++) { cout << ans[i].first << " " << ans[...
0
#include <bits/stdc++.h> using namespace std; long long int prefix[100010], n, x; vector<long long int> powers; long long int A[100010]; long long int fun() { prefix[0] = 0; for (int i = 1; i <= n; i++) prefix[i] = prefix[i - 1] + A[i - 1]; long long int k = 1; powers.push_back(1); if (x == -1) { powers.p...
10
#include <bits/stdc++.h> using namespace std; map<long long, pair<long long, long long>> dp; void updateMax(pair<long long, long long>& ma, pair<long long, long long> c) { if (c.first > ma.first) ma = c; else if (c.first == c.first) ma.second = max(c.second, ma.second); } pair<long long, long long> rec(long...
14
#include <bits/stdc++.h> using namespace std; using namespace std; const int N = 5e5 + 100; long long c[N]; int main() { int n, K; cin >> n >> K; long long sum = 0; for (int i = 1; i <= n; i++) scanf("%lld", &c[i]), sum += c[i]; sort(c + 1, c + 1 + n); long long lb = 1; long long cntl = 0; while (lb < n...
12
#include <bits/stdc++.h> using namespace std; int main() { int n, m; long long dp[100005]; while (cin >> n >> m) { fill(dp, dp + 100005, 1); vector<vector<int> > g(100005); while (m--) { int a, b; cin >> a >> b; g[a].push_back(b); g[b].push_back(a); } dp[1] = 1; lon...
8
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; const int N = 3e5 + 7; int n, m, d[N], x, y, w, v, k, f[N], ans, to; vector<pair<int, int> > g[N]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> m >> k; for (int i = 0; i < n; i++) d[i] = 1e9; for (int i...
12
#include <bits/stdc++.h> using namespace std; int a[200010], sqt, tp2, b[1000010]; long long ans, c[200010]; struct node { int l, r, i; }; node v[200010], tp; void add(int i) { tp2 = a[i]; ans -= (long long)b[tp2] * (long long)b[tp2] * (long long)tp2; b[tp2]++; ans += (long long)b[tp2] * (long long)b[tp2] * (...
14
#include <bits/stdc++.h> using namespace std; int n, m, a, b, stateCnt; vector<vector<int> > g; double prob[300][300], rev[300][300], stayP[300]; int state[30][30]; int getState(int a, int b) { if (a > b) swap(a, b); return state[a][b]; } void swapRow(double a[300][300], int r1, int r2) { for (int j = 0; j < stat...
19
#include <bits/stdc++.h> using namespace std; long double pi = 2 * acos(0.0); const long long mod = 1e9 + 7; void solve() { long long n; cin >> n; string a, b; cin >> a >> b; vector<long long> ans, ans1; for (long long i = 0; i < n; i++) { if (a[i] == '1') { long long j = i++; while (i < n &...
9
#include <bits/stdc++.h> const int N = 100010; int n; unsigned int dp[N << 1]; int main() { scanf("%d\n", &n); if (n & 1) { printf("0"); return 0; } dp[0] = 1; for (int i = 1; i <= n; i++) { char ch; scanf("%c", &ch); if (ch == '?') { for (int j = i / 2; j >= 1; j--) dp[j] = dp[j] * ...
21
#include <bits/stdc++.h> using namespace std; int main() { int(n); scanf("%d", &n); vector<pair<int, int>> s(n); vector<int> t(n); long long ss = 0; long long st = 0; for (int i = 0; i < (n); ++i) { int(x); scanf("%d", &x); s[i] = {x, i}; ss += x; } for (int i = 0; i < (n); ++i) { ...
15
#include <bits/stdc++.h> using namespace std; int main() { long long t; cin >> t; while (t--) { long long n, a, b; cin >> n >> a >> b; char arr[2 * a]; long long A = a; long long j = 0; while (a > 0) { for (long long i = 97; i < 97 + b; i++) { arr[j++] = (char)i; } ...
1
#include <bits/stdc++.h> using namespace std; template <typename T> T gcd(T a, T b) { if (a == 0) return b; return gcd(b % a, a); } long long isPowerof2(long long x) { return (x && !(x & x - 1)); } struct node { long long first; long long idx; long long ans; }; bool cmp(node a, node b) { return a.first < b.fi...
12
#include <bits/stdc++.h> using namespace std; inline void write(long long a) { if (a >= 10) write(a / 10); putchar('0' + a % 10); } inline void writeln(long long a) { write(a); puts(""); } inline long long read() { long long x = 0; char ch = getchar(); bool positive = 1; for (; !isdigit(ch); ch = getcha...
5
#include <bits/stdc++.h> using namespace std; const int N = (int)(1e6 + 2); template <typename Arg1> void __f(const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << '\n'; } template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args) { const char* comma = strchr(nam...
7
#include <bits/stdc++.h> using namespace std; long long a[100001], l[100001], r[100001]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); long long o = 0, i, n; cin >> n; for (i = 0; i < n; i++) cin >> a[i]; l[0] = 1; for (i = 1; i < n; i++) l[i] = min(l[i - 1] + 1, a[i]); r[n - 1] = 1; for (i =...
8
#include <bits/stdc++.h> using namespace std; void gen(vector<long long>& v, int sz, string r, int c4, int c7) { if (c4 + c7 > sz) return; string s1 = r + '7'; string s2 = r + '4'; if (c4 > 0 && c4 == c7) { v.push_back(stoll(r)); } gen(v, sz, s1, c4, c7 + 1); gen(v, sz, s2, c4 + 1, c7); } int main() {...
5
#include <bits/stdc++.h> using namespace std; const int Maxn = 200005, INF = 1 << 30; int n, tot, tp[Maxn], f[Maxn], C[Maxn], ans; struct Line { int l, r; } A[Maxn]; bool cmp(const Line &a, const Line &b) { return a.l < b.l || a.l == b.l && a.r < b.r; } int Get() { char ch; int v = 0; bool f = false; while ...
10
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; struct Matrix { long long a[100][100]; Matrix() { memset(a, 0, sizeof(a)); } Matrix operator*(Matrix b) const { Matrix c; for (int i = 0; i < 100; i++) { for (int j = 0; j < 100; j++) { for (int k = 0; k < 100; k++)...
12
#include <bits/stdc++.h> using namespace std; int main() { long long int t, n, m, i, j, sum; cin >> t; while (t--) { sum = 0; cin >> n >> m; long long int a[n]; for (i = 0; i < n; i++) cin >> a[i]; for (i = 0; i < n; i++) { sum = sum + a[i]; } if (sum == m) { cout << "YES" ...
0
#include <bits/stdc++.h> using namespace std; const long long int N = 1e4; const long long int p = 31; const long long int mod = 1e9 + 7; std::vector<long long int> g[N], gt[N]; bool used[N]; vector<long long int> order; long long int comp[N]; long long int n, m; vector<bool> assignment; void dfs1(long long int v) { ...
14
#include <bits/stdc++.h> long long a, d, n, w = 445049; int main() { return scanf("%lld%lld%lld", &n, &a, &d), n = 1500000, printf("%lld %lld", a * w * n + 1, d * w * n), 0; }
27
#include <bits/stdc++.h> using namespace std; const long long INF = (1LL << 45LL); const long long MAXLL = 9223372036854775807LL; const unsigned long long MAXULL = 18446744073709551615LLU; const long long MOD = 1000000007; const long double DELTA = 0.000000001L; inline long long fmm(long long a, long long b, long long ...
5
#include <bits/stdc++.h> using namespace std; const int maxn = 105; map<string, int> H1[maxn], H2[maxn]; vector<char> ans; char getA(string a, string b) { int c[30]; for (int i = 0; i < 26; i++) c[i] = 0; for (int i = 0; i < a.size(); i++) c[a[i] - 'a']++; for (int i = 0; i < b.size(); i++) c[b[i] - 'a']--; f...
20
#include <bits/stdc++.h> using namespace std; const long long N = 2e5 + 5, MOD = 998244353; long long n, m, ans = 1, step[N]; long long ksm(long long a, long long b) { long long mul = a, ret = 1; while (b) { if (b & 1) { ret *= mul; ret %= MOD; } mul *= mul; mul %= MOD; b >>= 1; } ...
9
#include <bits/stdc++.h> using namespace std; const int MAXn = 100; int n; string f[MAXn]; string s; char let; bool b[1000]; bool isUp(char c) { return c >= 'A' && c <= 'Z'; } bool isLow(char c) { return c >= 'a' && c <= 'z'; } char toLow(char c) { return isUp(c) ? (c - 'A' + 'a') : c; } char toUp(char c) { return isUp...
8
#include <bits/stdc++.h> using namespace std; int a[1010][1010], n, x, y, t; void work(int x, int y) { if (a[x][y] < 3) { a[x][y]++; } else { a[x][y] = 0; work(x + 1, y); work(x - 1, y); work(x, y + 1); work(x, y - 1); } } int main() { scanf("%d %d", &n, &t); for (int i = 1; i <= n; i+...
12
#include <bits/stdc++.h> using namespace std; const long long M = 1e9 + 7; const long long N = 2e6 + 10; const long long IM = 1e15 + 37; const long double PI = 3.1415926535897932384; inline void PP(long long n) { cout << n << " "; } void PV(vector<long long> v) { for (long long i = 0; i < v.size(); i++) cout << v[i] ...
0
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1.0); const double eps = 1e-8; const int inf = 0x3f3f3f3f; const int N = 2000 + 11; vector<int> G[N]; int n, m; string a, b; void work() {} int pa[N]; bool f[N][N]; int d2[N][N]; int main() { cin >> a >> b; n = a.length(); m = b.length(); mem...
14