solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> using namespace std; bool a[100001]; int main() { int i, n, p; cin >> n; for (i = 1; i < n; i++) { cin >> p; a[p] = true; } for (i = 1; i <= n; i++) { if (a[i] == false) break; } cout << i; return 0; }
0
#include <bits/stdc++.h> using namespace std; const long long N = 2e5 + 5; vector<long long> adj[N]; long long deg[N]; long long order[N]; void solve() { long long n, m; cin >> n >> m; for (long long i = 0; i <= n; i++) adj[i].clear(), deg[i] = 0, order[i] = -1; vector<pair<long long, long long>> undirected, di...
12
#include <bits/stdc++.h> using namespace std; int a[1000100]; int sh[1000100]; int main() { int n; cin >> n; { int x, y, pos, pos1; memset(a, 0, sizeof(a)); for (int i = 0; i < n; i++) { cin >> x >> y; sh[x] = y; a[x]++; a[y]--; if (x == 0) pos = y; } int i = 0; ...
7
#include <bits/stdc++.h> namespace IO { char ibuf[1 << 21], *p1 = ibuf, *p2 = ibuf, obuf[1 << 21], *p = obuf; struct outflush { ~outflush() { (void)(fwrite(::IO::obuf, 1, ::IO::p - ::IO::obuf, stdout), fflush(stdout), ::IO::p = ::IO::obuf); } } flushout; } // namespace IO int rec() { int ch; whi...
14
#include <bits/stdc++.h> using namespace std; int main() { int m1[3]; for (int i = 0; i < 3; i++) scanf("%d", &m1[i]); int m2[3], ks = 0; for (int i = 0; i < 3; i++) { scanf("%d", &m2[i]); if (m2[i] == m1[i]) ks++; } if (ks >= 1) printf("YES"); else printf("NO"); }
3
#include <bits/stdc++.h> using namespace std; int n, m; int used[1100][1100]; vector<pair<int, int> > solve_l_r(int sx, int sy, int fx, int fy) { vector<pair<int, int> > ret; int len = abs(sx - fx) + 1; if ((fy - sy + 1) % 2 == 1) { int curx = sx, cury = sy; for (int i = 1; i <= fy - sy + 1; i++) { ...
21
#include <bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:255000000") bool firstout = 1; template <class T> void minn(T &a, T b) { if (b < a) a = b; } template <class T> void maxx(T &a, T b) { if (a < b) a = b; } int madd(int &a, int b) { a += b; if (a >= 1000000009) a -= 1000000009; retur...
5
#include <bits/stdc++.h> using namespace std; const double PI = 3.14159265; const long long M = 100005; vector<long long> adj[M]; long long maxdistdown[M], maxdistup[M], mark[M]; void dfs1(long long x, long long p) { maxdistdown[x] = (mark[x] ? 0 : -1); for (auto i : adj[x]) { if (i != p) { dfs1(i, x); ...
12
#include <bits/stdc++.h> using namespace std; const long long N = 500777; long long n, m; struct node { long long x, x1, xn, x1n; long long v1, vn; }; long long a[N]; node t[4 * N]; long long M = 998244353; long long get(long long a, long long b) { if (a != 1) { return 0; } else { return 19 - 10 * a - b...
18
#include <bits/stdc++.h> using namespace std; int ar[115]; long long int res; long long int on[115]; vector<long long int> vec; int main() { long long int l, r; on[0] = 1LL; for (int i = 1; i < 15; i++) on[i] = on[i - 1] * 10LL; ar[0] = 4; vec.push_back(4); while (!ar[10]) { ar[0]++; for (int i = 0;...
3
#include <bits/stdc++.h> using namespace std; int main() { int ans, n, l[100005], r[100005], left = 0, right = 0, i, c1, c2, in = 0; scanf("%d", &n); for (i = 0; i < n; i++) scanf("%d %d", &l[i], &r[i]), left += l[i], right += r[i]; ans = abs(left - right); for (i = 0; i < n; i++) { c1 = left; c2 ...
3
#include <bits/stdc++.h> using namespace std; const int INF = 1000 * 1000 * 1000; const long long INF64 = 1000LL * 1000LL * 1000LL * 1000LL * 1000LL * 1000LL; int n, m; char a[200][200]; int w[2][200][200]; void Load() { cin >> n >> m; { int c; while ((c = getchar()) != 10 && c != EOF) ; }; for (i...
7
#include <bits/stdc++.h> using namespace std; int main() { long long int i, j, k; long long int n; string s; long long int y = 0, r = 0, b = 0, g = 0; long long int yc = -1, rc = -1, bc = -1, gc = -1; cin >> s; n = s.length(); for (i = 0; i < n; i += 4) { k = 1; for (j = i; j < i + 4; j++) { ...
3
#include <bits/stdc++.h> using namespace std; struct seg_tree { vector<int> m; seg_tree(int n) { m.assign(4 * n + 10, 0); } void update(int node, int b, int e, int pos, int val) { if (b == e) { m[node] = val; return; } int mid = (b + e) >> 1; if (mid >= pos) update(node << 1, b, ...
14
#include <bits/stdc++.h> using namespace std; int main() { cout.sync_with_stdio(0); cin.tie(0); int a, b, h1, h2; cin >> h1 >> h2 >> a >> b; if (h1 + 8 * a >= h2) { cout << 0 << endl; } else { if (a > b) { int n = h2 - h1 - 8 * a, d = 12 * (a - b); cout << (n + d - 1) / d << endl; } ...
6
#include <iostream> //#include "bits/stdc++.h" #include "algorithm" #include "cstring" #include "vector" #include "stack" #include "queue" #include "set" #include "cmath" #include "unordered_map" #include "map" using namespace std; #define ll long long #define int ll #define double long double #define inf 0x3f3f3f3f3f...
10
#include <bits/stdc++.h> using namespace std; const int maxn = 100010; int T, n, a, b, tot, len, lcax; int ver[maxn << 1], head[maxn], nxt[maxn << 1], vis[maxn], cnt[maxn]; int f[maxn], dep[maxn][2], fa[23][maxn], lg[maxn]; vector<pair<int, int> > g[maxn]; bool cmp(const pair<int, int> x, const pair<int, int> y) { re...
22
#include <bits/stdc++.h> using namespace std; inline int read() { int x = 0, y = 1; char c = getchar(); while (c < '0' || c > '9') { if (c == '-') y = -1; c = getchar(); } while (c >= '0' && c <= '9') x = (x << 1) + (x << 3) + (c ^ 48), c = getchar(); return x * y; } const int N = 5005; const lo...
18
#include <bits/stdc++.h> using namespace std; int l[100], r[100]; int b[100]; int main() { int n; cin >> n; for (int i = 0; i < n; i++) { cin >> l[i] >> r[i]; b[i] = 0; } int res[100]; for (int i = 0; i < n; i++) res[i] = 0; for (int i = 0; i < n; i++) { int minl = 100000000; int minr = 10...
11
#include <bits/stdc++.h> using namespace std; #define rep(i,a,n) for (int i=a;i<n;i++) #define per(i,a,n) for (int i=n-1;i>=a;i--) #define pb push_back #define mp make_pair #define all(x) (x).begin(),(x).end() #define fi first #define se second #define SZ(x) ((int)(x).size()) typedef long long ll; typedef double db; t...
24
#include <bits/stdc++.h> using namespace std; template <typename Arg1> void __f(const char *name, Arg1 &&arg1) { cerr << name << " : " << arg1 << std::endl; } template <typename Arg1, typename... Args> void __f(const char *names, Arg1 &&arg1, Args &&...args) { const char *comma = strchr(names + 1, ','); cerr.writ...
13
#include <bits/stdc++.h> using namespace std; int n, m, l, ans, nxt[100005]; char s1[100005], s2[100005]; void init(char *s, int len) { nxt[0] = nxt[1] = 0; for (int i = 1; i < len; i++) { int j = nxt[i]; while (j && s[i] != s[j]) j = nxt[j]; if (s[i] == s[j]) j++; nxt[i + 1] = j; } } int a[100005...
15
#include <bits/stdc++.h> using namespace std; int n, num[26]; char s[1100], a[1100]; void work() { n = strlen(s); memset(num, 0, sizeof(num)); memset(a, 0, sizeof(a)); for (int i = 0; i < n; i++) num[s[i] - 'a']++; for (int i = 2; i <= n; i++) { if (a[i - 1]) continue; int p = -1; for (int j = i; ...
5
#include <bits/stdc++.h> using namespace std; set<int> marks; int l; int x, y; int a[200200]; int n; int main() { cin >> n >> l >> x >> y; for (int i = 0; i < n; ++i) { cin >> a[i]; marks.insert(a[i]); } bool xx = false; bool yy = false; for (int i = 0; i < n; ++i) { int start = a[i]; int en...
9
#include <bits/stdc++.h> using namespace std; double EPS = 1e-9; int INF = 1000000005; long long INFF = 1000000000000000005LL; double PI = acos(-1); int dirx[8] = {-1, 0, 0, 1, -1, -1, 1, 1}; int diry[8] = {0, 1, -1, 0, -1, 1, -1, 1}; inline string IntToString(long long a) { char x[100]; sprintf(x, "%lld", a); st...
1
#include <bits/stdc++.h> using namespace std; int xx[4] = {1, -1, 0, 0}; int yy[4] = {0, 0, 1, -1}; const double eps = 1e-9; const int maxn = 2e6 + 5000; const long long mod = 1e9 + 7; const int INF(0x3f3f3f3f); const long long INFL(0x3f3f3f3f3f3f3f3fll); inline int sign(double a) { return a < -eps ? -1 : a > eps; } lo...
8
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; int hd[400005] = {0}, cnte = 0; struct edg { int fr, to, val, nxt; } e[2000005]; void addEdge(int fr, int to, int val = 1) { cnte++; e[cnte].fr = fr; e[cnte].to = to; e[cnte].val = val; e[cnte].nxt = hd[fr]; hd[fr] = cnte; } bool vi...
9
#include <bits/stdc++.h> using namespace std; struct point { int x, y, z, idx; bool operator<(const point &b) const { if (this->x != b.x) return this->x < b.x; if (this->y != b.y) return this->y < b.y; return this->z < b.z; } }; int main() { int n; cin >> n; vector<struct point> a(n); for (int...
9
#include <bits/stdc++.h> using namespace std; int main() { int n, t, i; string a; cin >> n >> t >> a; for (i = 0; i < n; i++) { if (a[i] == '.') break; } string x; string y; x = a.substr(0, i); int length = i; y = a.substr(i + 1, a.size() - i - 1); int count = 0; int finalLength = y.size(); ...
9
#include <bits/stdc++.h> using namespace std; char str[20]; map<int, int> cnt; int main(int argc, char *argv[]) { int t, n, temp; scanf("%d", &t); char a; for (int i = 0; i < t; ++i) { scanf(" %c", &a); scanf("%s", str); n = strlen(str); temp = 0; for (int i = 0; i < n; ++i) { temp <<=...
6
#include <bits/stdc++.h> using namespace std; int n, a[300001]; long long ans; int main() { cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); if (n == 1) { ans = a[0]; } else { for (int i = 0; i < n; i++) { ans += (long long)a[i] * (i + 2); } ans -= a[n - 1]; } cout ...
4
#include <bits/stdc++.h> int dis[1001], com[1001], res[1001], tot[1001]; int main() { int m, k; memset(res, 0x3f, sizeof res); scanf("%d%d", &m, &k); for (int i = 0; i < m; ++i) scanf("%d", &dis[i]); for (int i = 0; i < m; ++i) scanf("%d", &com[i]); res[0] = 0, tot[0] = com[0]; for (int i = 0; i < m; ++i)...
5
#include <bits/stdc++.h> using namespace std; int n; struct data { int type; long long x, y, s, b; vector<data *> son; bool done; data(int t = 0, long long xx = 0, long long yy = 0) : type(t) { if (t == 0) { x = xx; y = yy; } else { x = 0; y = 0; s = xx; b = yy; ...
15
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int p; for (int i = 0; i < n; i++) cin >> p; cout << n + 1 << endl; cout << 2 << ' ' << n << ' ' << 1 << endl; cout << 1 << ' ' << n << ' ' << 8000 << endl; for (int i = 1; i <= n - 1; i++) cout << 2 << ' ' << i << ' ' << 80...
6
#include <bits/stdc++.h> using namespace std; vector<pair<int, int> > P, A; int pos, x, y, delta, R, N, M, i; int main() { cin >> N >> M; if (M == 3) { if (N == 6) { cout << -1 << endl; return 0; } if (N == 5) { cout << -1 << endl; return 0; } if (N == 3) { cout << ...
15
#include <bits/stdc++.h> using namespace std; const double EPS = 1e-8; const long long mod = 1000000007; int dx[] = {0, 0, -1, 1, 1, 1, -1, -1}; int dy[] = {1, -1, 0, 0, 1, -1, -1, 1}; const int N = 500001; void stop() {} struct point { double x, y; }; long long gcd(long long a, long long b) { if (a < 0) a *= -1; ...
0
#include <bits/stdc++.h> using namespace std; int main() { long long int a, b, t, r, cnt = 0; cin >> a >> b; while (b > 0) { cnt += a / b; t = b; b = a % b; a = t; } cout << cnt << endl; return 0; }
3
#include <bits/stdc++.h> using namespace std; int main() { int n, i, j, ar[100005], count = 0; cin >> n; for (i = 0; i < n; i++) { cin >> ar[i]; } sort(ar, ar + n, greater<int>()); for (i = 0; i < n; i++) { int a = 0; if (ar[i] == 4) { count++; } else if (ar[i] < 4) { int s = ar[...
3
#include <bits/stdc++.h> using namespace std; long long int n; long long int arr[1000][5]; bool tohack[6]; long long int alreadysolved[6] = {0}; long long int bitmask; void tosolve() { for (long long int i = 0; i < 6; i += 1) { if (bitmask & (1 << i)) { if (arr[0][i] != -1) { tohack[i] = true; ...
12
#include <bits/stdc++.h> using namespace std; const int MAXN = 5050; int n, T, t[MAXN]; double dp[2][MAXN], p[MAXN]; int P[MAXN]; double factor[101][MAXN]; double *f[2]; int main() { scanf("%d%d", &n, &T); for (int i = 1; i <= n; i++) { scanf("%d%d", &P[i], &t[i]); p[i] = P[i] / 100.0; } double res = 0;...
16
#include <bits/stdc++.h> using namespace std; int n, k; int ans[1005][1005]; int main() { int i, j, sz, l, r, color, mx = 0; scanf("%d%d", &n, &k); for (sz = 1, color = 1; sz <= n; sz *= k, color++) { for (i = 1; i <= n; i += sz) { r = min(n, i + sz * k - 1); for (j = i; j <= i + sz - 1; j++) { ...
17
#include <bits/stdc++.h> using namespace std; long f[30], d[30]; long next_sym[30]; int main() { long n; for (int i = 0; i < 30; i++) f[i] = 0, d[i] = 0, next_sym[i] = -1; cin >> n; for (int i = 0; i < n; i++) { string s; cin >> s; for (int j = 0; j < s.size(); j++) { f[s[j] - 'a'] = 1; ...
7
#include <bits/stdc++.h> using namespace std; int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); } int lcm(int a, int b) { return (a / gcd(a, b)) * b; } int main() { ios::sync_with_stdio(false); cin.tie(0); int n, k; cin >> n >> k; if (n < 2 * k + 1) cout << -1; else { cout << k * n << "\n";...
6
#include <bits/stdc++.h> #pragma GCC optimize(2) #include<iostream> #include<cstdio> #include<algorithm> #include<string> #include<vector> #include<set> #include<map> #include<queue> #include<cmath> #include<cstring> #include<bitset> #include<stack> #include<time.h> #define X first #define Y second #define PB push_b...
12
#include <bits/stdc++.h> std::vector<std::vector<int> > A; int M, N, P; int main() { scanf("%d%d", &N, &M); P = N * M; if (P == 1) return puts("YES\n1"), 0; if (P <= 3) return puts("NO"), 0; if ((N == 1) || (M == 1)) { puts("YES"); char C = (N == 1) ? ' ' : '\n'; for (int i = 2; i <= P; i += 2) pr...
14
#include <bits/stdc++.h> using namespace std; vector<long long> v[301], vv, v1; long long a, b, c[1234567], c1[123][123], d[1234567], e, i, j, n, x, y, l, r, k; string s, s1; long long used[301]; long long ans; int main() { cin >> a >> b >> k; if (max(a, b) >= k) { cout << 0; exit(0); } if (a > b) swap(...
8
#include <bits/stdc++.h> using namespace std; inline int read() { int x = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); } return x * f; } const int N = 2e5 + 7; ...
14
#include <bits/stdc++.h> using namespace std; const long long N = 10000000 + 10; long long n, m, c0, d0, a, b, c, d; long long v[N], w[N], f[N]; int main(void) { cin >> n >> m >> c0 >> d0; int num = 1; for (int i = 1; i <= m; i++) { cin >> a >> b >> c >> d; int s = a / b; for (int j = 1; j <= s; j <<=...
9
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 10; int n, f[maxn], pos1[maxn], pos2[maxn], cnt1, cnt2; char ss[maxn]; int calc(int l, int r, int mid) { return abs(r - l) + min(abs(r - mid), abs(l - mid)); } bool ck(int x) { int now1 = 0, now2 = 0; for (int i = 1; i <= cnt2; ++i) { while ...
10
#include <bits/stdc++.h> using namespace std; const int MX = 1000; const int modd = 1000 * 1000 * 1000 + 7; int n; int p[MX + 1]; int fw[MX + 1], fwint[MX + 1]; void addVal(int* fenw, int pos, int v) { if (pos <= 0) return; for (; pos <= MX; pos += pos & -pos) { fenw[pos] += v; } } int getSum(int* fenw, int p...
8
#include <bits/stdc++.h> using namespace std; vector<pair<long long, long long>> st = {{0, -1}, {0, 1}, {1, 0}, {-1, 0}}; vector<vector<bool>> s; vector<vector<char>> a; void DFS(long long x, long long y, long long n, long long m) { s[x][y] = false; for (pair<long long, long long> q : st) { if (-1 < x + q.first...
12
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; int main() { int a[5], b[5], sum = 0; for (int i = 1; i <= 3; i++) cin >> a[i]; for (int i = 1; i <= 3; i++) cin >> b[i]; for (int i = 1; i <= 3; i++) { if (a[i] - b[i] < 0) sum += abs(a[i] - b[i]); else sum -= (a[i] -...
4
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 10; const int BASE = 1e9 + 7; long long F, T, T0, T1, T2, P1, P2, A1, A2; void read_input() { cin >> F >> T >> T0; cin >> A1 >> T1 >> P1; cin >> A2 >> T2 >> P2; } long long calculate(int x) { long long TT = T - min(A1 * x, F) * T1; if (TT < ...
15
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 5; int a[N], b[N]; int main() { int n; scanf("%d", &n); for (int i = 0; i <= n - 1; i++) scanf("%d", &a[i]); int ans = 0; for (int k = 0; k <= 24; k++) { for (int i = 0; i <= n - 1; i++) b[i] = a[i] % (1 << (k + 1)); sort(b, b + n); ...
13
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; int val[N]; vector<int> facs[N], G[N]; int freq[N], all[N]; int ans[N]; void dfs(int now, int par, int cnt) { if (par != -1) ans[now] = all[par]; for (int x : facs[now]) { freq[x]++; if (freq[x] >= cnt - 1) ans[now] = max(ans[now], x); ...
12
#include <bits/stdc++.h> using namespace std; int diff(int a, int b) { string ax = ""; string bx = ""; while (a) { ax += (a % 2 + '0'); a /= 2; } while (b) { bx += (b % 2 + '0'); b /= 2; } int ret = 0; for (long long(i) = (0); (i) < (min(ax.size(), bx.size())); (i)++) { if (ax[i] != ...
6
#include <bits/stdc++.h> using namespace std; const int MAXn = 1e6; vector<int> nb[MAXn]; int comp[MAXn], cc; bool mark[MAXn]; void dfs(int v) { mark[v] = true; comp[cc]++; for (int i = 0; i < (int)nb[v].size(); i++) if (!mark[nb[v][i]]) dfs(nb[v][i]); } int main() { ios::sync_with_stdio(false); int n, m,...
14
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; int n, q, dfs_num; int on[N], L[N], R[N], id[N]; vector<int> e[N]; struct SegTree { int sum[N * 4 + 5], col[N * 4 + 5]; void pushup(int t) { sum[t] = sum[t << 1] + sum[t << 1 | 1]; } void pushdown(int t, int l, int r) { if (l == r) return; ...
12
#include <bits/stdc++.h> using namespace std; struct ring { int x, y, z; inline bool operator<(const ring t) const { if (x != t.x) return x > t.x; else return y > t.y; } }; ring g[120000]; int h[120000], q[120000]; int i, n, r, x, y, z; long long s, t; int main() { scanf("%d", &n); for (i ...
12
#include <bits/stdc++.h> using namespace std; int main() { long long n, k, t; int arr[110]; cin >> n >> k >> t; bool found = false; for (int i = 0; i < n; i++) { long long now = k * i; for (int j = 0; j <= k; j++) { long long test1 = now * 100 + j; long long test2 = n * k * t; long l...
5
#include <bits/stdc++.h> int INF = 1000000005; long long INFF = 1000000000000000005LL; double pi = acos(-1); int dirx[8] = {-1, 0, 0, 1, -1, -1, 1, 1}; int diry[8] = {0, 1, -1, 0, -1, 1, -1, 1}; using namespace std; vector<int> v[51]; int main() { ios::sync_with_stdio(0); cin.tie(0); ios_base::sync_with_stdio(0);...
5
#include <bits/stdc++.h> long long x, y, t; int F(long long x, long long y) { return x < y ? F(y, x) : y && (!F(x % y, y) || 1 - x / y % (y + 1) % 2); } int main() { for (std::cin >> t; t--;) std::cin >> x >> y, puts(F(x, y) ? "First" : "Second"); }
15
#include <bits/stdc++.h> using namespace std; struct Dancer { long long x, y; bool vert; long long id; Dancer() {} Dancer(long long a, long long b, long long c, long long d) { x = a; y = b; vert = c; id = d; } bool operator<(const Dancer& a) const { if (x + y != a.x + a.y) return x + y...
11
#include <bits/stdc++.h> using std::cin; using std::cout; using std::endl; using std::fixed; using std::ios_base; using std::max; using std::min; using std::priority_queue; using std::sort; using std::stack; using std::string; using std::vector; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(...
0
#include <bits/stdc++.h> using namespace std; const int INF = 1e9 + 23; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n, k, t; cin >> n >> k >> t; if (t <= k) { cout << t; } else if (t > n) { cout << k - t + n; } else { cout << k; } return 0; }
0
#include <bits/stdc++.h> using namespace std; int main() { int n, t; cin >> n >> t; int answer = 0; int diff = 10e5; for (int i = 1; i <= n; i++) { int s, d; cin >> s >> d; int new_diff; int dd = t - s; if (dd < 0) { new_diff = -dd; } else { int ddd = (t - s) % d; if ...
2
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 5; int n; int type[maxn], dig[maxn], fa[maxn], pre[maxn]; int head[maxn], ecnt; stack<int> path; struct eed { int next, to; } edge[maxn]; void addedge(int u, int v) { edge[ecnt].next = head[u]; edge[ecnt].to = v; head[u] = ecnt++; } int ans = ...
7
#include <bits/stdc++.h> using namespace std; string a[55]; bool d[55][55][30], d2[55][55][30]; int ans[55][55]; int main() { cout.setf(ios::fixed); cout.precision(12); string s1, s2; cin >> s1 >> s2; int n; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i <= s1.length(); i...
15
#include <bits/stdc++.h> using namespace std; int n, m; int r, c; int x, y; char grid[2005][2005]; bool visited[2005][2005]; int left_distance[2005][2005]; int right_distance[2005][2005]; int dx[4] = {1, -1, 0, 0}; int dy[4] = {0, 0, 1, -1}; bool valid(int row, int col) { return (row >= 0 and row < n and col >= 0 and...
10
#include <bits/stdc++.h> using namespace std; const int N = 1e3 + 10; using pi = pair<int, int>; vector<pi> adj[N]; vector<bool> visited(N); pair<int, int> dfs(int v) { pair<int, int> p = {v, INT_MAX}; visited[v] = true; for (auto u : adj[v]) { p = dfs(u.first); p.second = min(p.second, u.second); } r...
6
#include <bits/stdc++.h> using namespace std; const long long int MOD = 998244353; int32_t main() { long long int n; cin >> n; string s; cin >> s; bool open = 0, close = 0; for (long long int i = 0; i < n; ++i) { if (s[i] == '(') { cout << open; open = !open; } else { cout << close...
7
#include <bits/stdc++.h> struct MI { private: char bb[1 << 14]; FILE *f; char *bs, *be; char e; bool o, l; public: MI() : f(stdin), bs(0), be(0) {} MI(FILE *f) : f(f), bs(0), be(0) {} inline operator bool() { return !l; } inline char get() { if (o) { o = 0; return e; } if (b...
15
#include <bits/stdc++.h> using namespace std; int a[1000005] = {0}; long long ans; int n, m; int main(int argc, char *argv[]) { cin >> n >> m; int x, y; for (int i = 1; i <= m; i++) { scanf("%d%d", &x, &y); a[x]++; a[y]++; } ans = 1ll * n * (n - 1) * (n - 2) / 6; ans -= 1ll * (n - 2) * m; for ...
11
#include <bits/stdc++.h> using namespace std; int block; struct Query { int l, r, p; Query(int _l, int _r, int _p) { l = _l; r = _r; p = _p; } bool operator<(const Query& q) const { return r < q.r; } }; int n, m, u, v, a[50005], s[1000005], res[5005]; vector<Query> query[305]; struct Trie { struct...
20
#include <bits/stdc++.h> using namespace std; int n, m, a[11][100005]; struct node_t { int lcomp[11], rcomp[11], cnt; node_t() { memset(lcomp, 0, sizeof(lcomp)); memset(rcomp, 0, sizeof(rcomp)); cnt = 0; } void replace(int x, int y) { cnt--; for (int i = 1; i <= n; i++) { if (lcomp[i] ...
18
#include <bits/stdc++.h> using namespace std; double max(double a, double b) { if (a > b) return a; return b; } long long modulo(long long a, long long b, long long n) { long long x = 1, y = a; while (b > 0) { if (b % 2 == 1) { x = (x * y) % n; } y = (y * y) % n; b /= 2; } return x % n...
1
#include <bits/stdc++.h> using namespace std; inline int read() { int x = 0, neg = 1; char op = getchar(); while (!isdigit(op)) { if (op == '-') neg = -1; op = getchar(); } while (isdigit(op)) { x = 10 * x + op - '0'; op = getchar(); } return neg * x; } inline void print(int x) { if (x <...
5
#include <bits/stdc++.h> using namespace std; const int N = 2005; int n, m; int low[N], high[N]; int id[2 * N][2 * N]; vector<int> v[2 * N]; map<int, int> mp; int dp[2 * N][2 * N]; vector<int> ansv; int dfs(int l, int r) { int i; if (dp[l][r] != -1) return dp[l][r]; if (l == r) return dp[l][r] = 0; int cur = 0;...
13
#include <bits/stdc++.h> int main() { int n, m; scanf("%d %d", &n, &m); int ones = n % 2; int twos = n / 2; while (twos + 1) { if ((ones + twos) % m == 0) { printf("%d", ones + twos); exit(0); } twos--; ones = ones + 2; } printf("-1"); }
2
#include <bits/stdc++.h> using namespace std; long long f[1000010]; long long sum[1000010]; int main() { long long n; scanf("%I64d", &n); f[1] = 2; sum[1] = 2; for (int i = 2; i < 1000010; i++) { f[i] = sum[i - 2] + 3; if (f[i] > n) { printf("%d\n", i - 1); return 0; } sum[i] = sum...
8
#include <bits/stdc++.h> using namespace std; const int64_t INF = 1e18 + 1; const int64_t N = 300500; const int64_t mod = 1000000007; int64_t fact[N]; int64_t invFact[N]; void _init_() { fact[0] = invFact[0] = 1; for (int64_t i = 1; i < N; i++) { fact[i] = (fact[i - 1] * i) % mod; } int64_t i = N - 1; inv...
7
#include <bits/stdc++.h> using namespace std; const long long inf = 1e9 + 100; const int N = 1e6 + 10; const long long mod = 998244353; const int base = 131; const double pi = acos(-1); const double eps = 1e-8; inline long long ksm(long long a, long long b) { long long ans = 1; while (b) { if (b & 1) ans = ans ...
5
#include <bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; struct custom_hash { static uint64_t splitmix64(uint64_t x) { x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31); } size_t operator()(uint64_t x) ...
10
#include <bits/stdc++.h> using namespace std; int n, m, k, ac; string a[25], b[25]; int main() { cin >> n >> m; for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < m; i++) { cin >> b[i]; } cin >> k; for (int i = 1; i <= k; i++) { cin >> ac; ac--; cout << a[ac % n] << b[ac ...
0
#include <bits/stdc++.h> using namespace std; int r[1001], c[1001], rh[1001], ch[1001]; int a[1001][1001]; int main() { int n, m, x, y, i, j, q, t; char cmd[2]; scanf("%d%d%d", &n, &m, &q); for (i = 0; i < n; i++) for (j = 0; j < m; j++) scanf("%d", &a[i][j]); for (i = 0; i < n; i++) r[i] = rh[i] = i; f...
5
#include <bits/stdc++.h> using namespace std; int n, m, cc, q, up[100001]; char type, tmp; set<int> s[100001]; map<int, int> c[100001]; int union_find(int u) { if (up[u] == u) { return u; } return up[u] = union_find(up[u]); } void union_merge(int u, int v) { int par_u = union_find(u), par_v = union_find(v);...
16
#include <bits/stdc++.h> const int INF = 0x7fffffff; using namespace std; inline char nc() { static char buf[100000], *p1 = buf, *p2 = buf; if (p1 == p2) { p2 = (p1 = buf) + fread(buf, 1, 100000, stdin); if (p1 == p2) return EOF; } return *p1++; } inline int read() { int x = 0, f = 1; char CH = getc...
10
#include <bits/stdc++.h> using namespace std; int getDigitsAmount(long long x) { int res = 0; while (x) { x /= 10; ++res; } return res; } int getDigit(long long x, int i) { while (i--) { x /= 10; } return x % 10; } long long getFull(int n, int d) { long long res = 0; while (n--) { res ...
19
#include <bits/stdc++.h> using namespace std; const int Maxn = 101; int n, m, c[Maxn], res; vector<pair<int, int> > best[Maxn]; int main() { int l, r, t; cin >> n >> m; for (int i = 0; i < m; i++) { cin >> l >> r >> t >> c[i]; for (int j = l; j <= r; j++) best[j].push_back(make_pair(t, i)); } for (int...
4
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { string s[110]; int n, m, cnt = 0; cin >> n >> m; for (int i = 1; i <= n; i++) cin >> s[i]; for (int i = 0; i < m; i++) { if (s[n][i] == 'D') cnt++; } for (int i = 1; i <= n; i++) { if ...
0
#include <bits/stdc++.h> using namespace std; const string c[7] = {"Anka", "Chapay", "Cleo", "Troll", "Dracul", "Snowy", "Hexadecimal"}; int n, i, j, k, e, a[3], b[3], cc[7], z[3], cr, r = 2000000200; string s, t, l; bool g[7][7]; void rec(int l) { int i, j; if (l == 7) { for (i = ...
6
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:256000000") using namespace std; void mytimer(string task) {} void ext(int c) {} char src[2100][2100]; char ar1[2100][2100]; char ar2[2100][2100]; int n; const int A = 5; vector<pair<int, int> > fig; void dfs(int a, int b) { fig.push_back(make_pair(a, b)); ar...
11
#include <bits/stdc++.h> template <class T> inline void read(T &res) { char ch; while (ch = getchar(), !isdigit(ch)) ; res = ch ^ 48; while (ch = getchar(), isdigit(ch)) res = res * 10 + ch - 48; } using std::set; using std::vector; const int N = 2e5 + 5; const int M = 8e5 + 5; const int dx[] = {0, 0, -1, 1...
24
#include <bits/stdc++.h> using namespace std; int const p = 1e9 + 7; int n, m, mp[3005][3005], f[3005][3005]; int calc(int sx, int sy, int tx, int ty) { memset(f, 0, sizeof(f)); f[sx][sy] = (mp[sx][sy] != 1); for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) { if (i == sx && j == sy) continue; ...
17
#include <bits/stdc++.h> const double PI = acos(-1); using namespace std; double f[2000000]; int n; double l, r; struct Node { double x, y, z; } a[50]; int m; double dq, ans; double work(int i, int j) { double dq1 = f[i]; double dq2 = atan2(-a[j].y, dq1 - a[j].x) + a[j].z; if (dq2 >= 0) return r; dq2 += PI / ...
14
#include <bits/stdc++.h> using namespace std; int n; int a[2], b[2]; bool isOppo(vector<int> line) { long long first = (long long)a[0] * line[0] + (long long)a[1] * line[1] + (long long)line[2]; long long second = (long long)b[0] * line[0] + (long long)b[1] * line[1] + (long...
9
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n; cin >> n; int a[n]; unordered_map<int, int> freq; map<int, int, greater<int>> count; for (int i = 0; i < n; i++) { cin >> a[i]; int j = freq[a[i]]; count[j]--;...
6
#include <bits/stdc++.h> using namespace std; const int limite = 10000; string t; string sol; map<char, int> m; bool alguien() { for (map<char, int>::iterator it = m.begin(); it != m.end(); it++) if (it->second) return true; return false; } void completar(int is) { for (map<char, int>::iterator it = m.begin()...
11
#include <bits/stdc++.h> using namespace std; const int maxn = 1000 + 85 - 69; bool a[maxn][maxn]; string s[maxn * 2], t[maxn * 2]; int n, m, k; bool chn; void tabdil(void) { for (int i = 0; i < 2 * m - 1; i++) for (int j = i & 1 ^ 1; j < 2 * n - 1; j += 2) t[i] += s[j][i >> 1]; for (int i = 0; i < 2 * n - 1; i...
17
#include <bits/stdc++.h> using namespace std; int moves[9][2] = {{0, 1}, {1, 1}, {1, 0}, {1, -1}, {0, -1}, {-1, -1}, {-1, 0}, {-1, 1}, {0, 0}}; vector<string> v; bool dfs(int x, int y, int steps) { if (steps > 7) return 1; int i, xx, yy; for (i = 0; i < 9; ++i) { xx = x + moves[i][0]; ...
7