solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> using namespace std; int a[2 * 131072]; void solve(int i) { for (int j = i >> 1, k = 1; j; j >>= 1, k ^= 1) { if (k) a[j] = a[j << 1] | a[j << 1 | 1]; else a[j] = a[j << 1] ^ a[j << 1 | 1]; } } int main() { ios_base::sync_with_stdio(false); int n, m, p; cin >> n >>...
9
#include <bits/stdc++.h> using namespace std; long long inf = (long long)1 << 63 - 1; const int N = 1005; long long sx[N], sy[N]; int a[N][N]; long long cal(int i, int j) { long long x; if (i > j) x = (i - j) * 4 + 2; else x = (j - i) * 4 - 2; return x * x; } int main() { int n, m; scanf("%d%d", &n,...
10
#include <bits/stdc++.h> using namespace std; using ll = long long; const int N = 2e5 + 10; int n, k; vector<int> g[N]; int deg[N], sub[N], par[N], dist[N]; void dfs(int u, int f) { par[u] = f; sub[u] = 1; dist[u] = dist[f] + 1; for (int v : g[u]) if (v != f) { dfs(v, u); deg[u]++; sub[u] ...
8
#include <bits/stdc++.h> using namespace std; int main() { int N, M, Pos, Low, High; string str; cin >> N >> M; Low = 0, High = N + 1; Pos = 0; bool flag = false; for (int i = 0; i < M; i++) { cin >> str; cin >> str; cin >> str; bool whattodo = false; if (str == "left") whattodo = true...
5
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } long long powM(long long x, long long y, long long m) { if (y == 0) return 1; long long p = powM(x, y / 2, m) % m; p = (p * p) % m; return (y % 2 == 0) ? p : (x * p) % m; } vector<int> v[10000...
10
#include <bits/stdc++.h> using namespace std; const int maxn = 4e5; int INF = 2e9; long long qpow(long long a, long long n) { long long re = 1; while (n) { if (n & 1) { re = re * a; } n >>= 1; a = a * a; } return re; } long long a[maxn]; int main() { int n; scanf("%d", &n); for (int ...
7
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; if (n % 2 == 0) { cout << n / 2 << endl; return 0; } if (n == 3 || n == 5 || n == 7) { cout << 1 << endl; return 0; } for (long long i = 3; i * i <= n; i++) { if (n % i == 0) { n -= i; break; ...
4
#include <bits/stdc++.h> using namespace std; string str, answer; int n; int main() { cin >> str; if ('a' <= str[0] && 'z' >= str[0]) { for (int i = 1; i < str.size(); i++) { if ('a' <= str[i] && 'z' >= str[i]) { n += 1; } } } else { for (int i = 0; i < str.size(); i++) { if ...
2
#include <bits/stdc++.h> using namespace std; int main() { long long s, k; while (cin >> s >> k) { vector<long long> sol; if (k >= 32) { for (int i = 0; i <= 32; ++i) { if (s & (1LL << i)) { sol.push_back(1LL << i); } } } else { vector<long long> F(k, 0); ...
8
#include <bits/stdc++.h> using namespace std; int main() { long long n, k; cin >> n >> k; long long pla, num, a, b, cnt = 0; cin >> a; for (long long i = 1; i < n; i++) { cin >> b; if (a > b) cnt++; else cnt = 1, a = b; if (a == n or cnt == k) { cout << a << endl; break...
4
#include <bits/stdc++.h> using namespace std; int main() { int n; long long x, y; cin >> n; while (n > 0) { cin >> x >> y; if (x - y <= 1) cout << "no" << endl; else cout << "yes" << endl; n--; } return 0; }
1
#include <bits/stdc++.h> using namespace std; const int MAX_N = 200005; int n, k, D[MAX_N]; vector<int> G[MAX_N]; vector<pair<int, int> > stopnie; set<int> kolory[MAX_N]; bool zly[MAX_N]; map<pair<int, int>, int> M; pair<int, int> kra[MAX_N]; bool odw[MAX_N]; bool cmp(pair<int, int> A, pair<int, int> B) { if (A.secon...
11
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; stack<pair<int, pair<int, int> > > par; int ct = 0; int mx = -1; int ini, fin; int n = s.size(); vector<int> sig(n, -1); vector<int> ac(n, 0); for (int i = 0; i < s.size(); i++) { if (s[i] == '(') { par.push(pai...
9
#include <bits/stdc++.h> using namespace std; vector<int> w(1007); int sttoi(string a) { int k = 0, i = 1; while (a.length()) { k += (a[a.length() - 1] - '0') * i; i *= 10; a.pop_back(); } return k; } string itos(int a) { string b = ""; while (a) { b += a % 10 + '0'; a /= 10; } rever...
5
#include <bits/stdc++.h> using namespace std; int main(int argc, char const *argv[]) { long long int x, n; std::cin >> n; set<long long int> a, b; vector<long long int> ans(n); for (long long int i = 0; i < n; i++) b.insert(i + 1); for (long long int i = 0; i < n; i++) { std::cin >> x; if (x == 0) ...
7
#include <bits/stdc++.h> using namespace std; const int maxn = 5e5 + 222; map<int, int> ma[maxn]; int fa[maxn]; set<int> se[maxn]; inline int FA(int x) { if (fa[x] == x) return x; fa[x] = FA(fa[x]); return fa[x]; } void merge1(int a, int b) { int A = FA(a); int B = FA(b); if (A == B) return; if (se[A].siz...
16
#include <bits/stdc++.h> using namespace std; bool cmp(pair<int, int> a, pair<int, int> b) { return a.first < b.first; } int main(int argc, char *argv[]) { int n; scanf("%d", &n); vector<pair<int, int> > a; vector<int> ans; int tmp; for (int i = 1; i <= n; i++) { scanf("%d", &tmp); a.push_back(pair<...
5
#include <bits/stdc++.h> using namespace std; int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1}; inline int GA(long long n, vector<long long>& vec) { for (int i = 0; i < n; ++i) { long long x; cin >> x; vec.push_back(x); } return 0; } inline int GAEG(long long m, vector<long long> vec[]) { for (int i =...
7
#include <bits/stdc++.h> using namespace std; int main() { string s, a[12] = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}; cin >> s; int d, n; cin >> n; for (int i = 0; i...
1
#include <bits/stdc++.h> using namespace std; using ll = long long; int n; const double ep = 1e-8; struct pnt { double x, y; pnt(double x = 0, double y = 0) : x(x), y(y) {} pnt operator+(const pnt &b) { return pnt(x + b.x, y + b.y); } pnt operator-(const pnt &b) { return pnt(x - b.x, y - b.y); } pnt operator*...
13
#include <bits/stdc++.h> using namespace std; bool isPrime(unsigned long long int n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; for (unsigned long long int i = 5; i * i <= n; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } i...
10
#include <bits/stdc++.h> using namespace std; const int maxn = 500 + 7; int n; int a[maxn], b[maxn]; struct node { int l, r; bool operator<(const node &a) const { if (l == a.l) return r < a.r; return l < a.l; } bool operator==(const node &a) const { return l == a.l && r == a.r; } }; map<node, int> mp; v...
13
#include <bits/stdc++.h> using namespace std; int f[1000][2000]; int a[1000]; int n; int main() { scanf("%d", &n); int most = -1; for (int i = 1; i <= n; i++) { scanf("%d", a + i); most = max(most, a[i]); } if (n <= 2 || !(n & 1)) { printf("-1\n"); return 0; } memset(f, 127, sizeof(f)); ...
9
#include <bits/stdc++.h> using namespace std; const int N = 100002; int n, m; struct _EDGE { int v, c, next; }; _EDGE pool[4 * N]; int head[2 * N]; void addEdge(int u, int v, int c) { static int cur = 0; _EDGE& p = pool[cur]; p.v = v; p.c = c; p.next = head[u]; head[u] = cur++; } int balance[2 * N]; bool ...
13
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s; cin >> s; for (int i = 0; i < n - 4; i++) { for (int j = 1; i + 4 * j < n; j++) { if (s[i] == '*' && s[i + j] == '*' && s[i + 2 * j] == '*' && s[i + 3 * j] == '*' && s[i + 4 * j] == '*') { cout <<...
5
#include <bits/stdc++.h> using namespace std; vector<int> vt[10000]; inline int Distance(int x, int y, int n) { if (y >= x) return y - x; else return n - x + y; } int main() { int n, m; scanf("%d %d", &n, &m); while (m--) { int x, y; scanf("%d %d", &x, &y); vt[x].push_back(Distance(x, y, n...
9
#include <bits/stdc++.h> using namespace std; string in[(105)]; bool good[(105)]; bool temp[(105)]; int main() { int R, C; cin >> R >> C; for (int i = 0; i < R; i++) cin >> in[i]; int ans = 0; for (int j = 0; j < C; j++) { memset(temp, 0, sizeof(temp)); bool ch = false; for (int i = 0; i < R - 1; ...
7
#include <bits/stdc++.h> using namespace std; int m, n, k, t, a[200100], dp[200100]; vector<pair<int, int> > v[200100]; int Get(int i, int Max) { int Maxx = 0, k = -1; while (1) { for (auto j : v[i]) if (j.second > Max) k = max(k, j.first); i++; if (k < i) break; } return k; } int main() { c...
11
#include <bits/stdc++.h> using namespace std; int n, m, k, a, b; int main() { cin >> n >> m; for (a = 0; a <= 31; a++) { for (b = 0; b <= 31; b++) { if (a * a + b == n && b * b + a == m) k++; } } cout << k; }
0
#include <bits/stdc++.h> using namespace std; int N, M, c[(200000 + 7)], use[(200000 + 7)], head[(200000 + 7)]; long long ans1, ans2, FA, v[(200000 + 7)], f[(200000 + 7)], L[(200000 + 7)], L0[(200000 + 7)], R[(200000 + 7)], R0[(200000 + 7)]; struct edge { int y, z, nxt; } E[(200000 + 7) << 1]; void add(int x, int...
17
#include <bits/stdc++.h> using namespace std; int T, k; int num[1005]; char l[1005], r[1005]; long long dp[1005][1005][2]; long long dfs(int pos, int d, bool flag, bool lim) { if (!pos) return flag; if (!lim && ~dp[pos][d][flag]) return dp[pos][d][flag]; int up = lim ? num[pos] : 9; long long ans = 0; for (in...
17
#include <bits/stdc++.h> using namespace std; template <class T> void show(T a, int n) { for (int i = 0; i < n; ++i) cerr << a[i] << ' '; cerr << endl; } template <class T> void show(T a, int r, int l) { for (int i = 0; i < r; ++i) show(a[i], l); cerr << endl; } const int INF = 1000 * 1000 * 1000 + 1000 * 1000;...
4
#include <bits/stdc++.h> using namespace std; int main() { long long int n, k; cin >> n >> k; long long int a[n]; for (long long int i = 0; i < n; i++) { cin >> a[i]; } long long int x; cin >> x; long long int c[n]; priority_queue<long long int, vector<long long int>, greater<long long int> > ...
7
#include <bits/stdc++.h> using namespace std; const double eps = 1e-6; const double PI = acos(-1.0); const int maxn = 150005; const int inf = 0x3f3f3f3f; int n, a, b, st, fa[maxn], rk[maxn]; vector<int> vec[maxn]; int find_fa(int x) { return fa[x] == x ? x : fa[x] = find_fa(fa[x]); } void unite(int x, int y) { x = fi...
9
#include <bits/stdc++.h> using namespace std; const int N = 300010; const unsigned long long BASE = 131; const unsigned long long MOD = 1e9 + 7; const int INF = 0x3fffffff; char s[N]; int n, q, x, y, len; unsigned long long h[N][30], p[N], a[N], b[N]; int main() { scanf("%d%d%s", &n, &q, s + 1); for (int i = 1; i <...
15
#include <bits/stdc++.h> using namespace std; int main() { int n, mex; cin >> n >> mex; vector<int> arr(n); int mx = 101; bool have_mex = false; for (int i = 0; i < n; i++) { cin >> arr[i]; if (arr[i] == mex) have_mex = true; } sort(arr.begin(), arr.end()); int cnt = 0; for (int i = 0; i < n...
2
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; long long ans = 0; for (int i = (0); i < (n); ++i) { long long t, T, x, cost; cin >> t >> T >> x >> cost; if (t >= T) { ans += cost + m * x; continue; } long long aux1 = cost; if (m > (T - t))...
11
#include <bits/stdc++.h> using namespace std; int main() { int n, a, b, A[105], B[105], c[106], t; while (scanf("%d%d%d", &n, &a, &b) != EOF) { for (int i = 0; i < a; i++) { scanf("%d", &A[i]); } for (int i = 0; i < b; i++) { scanf("%d", &B[i]); } sort(A, A + a); t = 0; for (...
0
#include <bits/stdc++.h> using namespace std; int main() { int n, day, week = 0; vector<int> days; cin >> n; for (int i = 0; i < 7; i++) { cin >> day; week += day; days.push_back(day); } day = 0; while (n > 0) { n -= days[day]; day += 1; if (day == 7 && n > 0) { day = 0; ...
2
#include <bits/stdc++.h> using namespace std; int data1[1005], data2[1005]; int main() { int n; while (scanf("%d", &n) != EOF) { int i; for (i = 1; i <= n; i++) scanf("%d", &data1[i]); for (i = 1; i <= n; i++) scanf("%d", &data2[i]); int j; int ans = 0; for (i = 1; i <= n; i++) { int f...
1
#include <bits/stdc++.h> using namespace std; const long double pi = 3.14159265358979323846; const long long M = 1e18 + 7; const int MOD = 1e9 + 7; const int MX = 1e6 + 5; const int mod = 998244353; long long power(long long x, long long y, long long p) { long long res = 1; x = x % p; while (y > 0) { if (y & ...
9
#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, i, j, ans = 0, x1, x2, y1, y2; cin >> n >> m; char a[n + 1][m + 1]; string s; for (i = 0; i < n; i++) for (j = 0; j < m; j++) { cin >> a[i][j]; if (a[i][j...
4
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const double pi = 3.1415926535897932384626; inline long long read() { long long x = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = ...
13
#include <bits/stdc++.h> using namespace std; int main() { long long a, b, n; cin >> a >> b >> n; long long l, t, m; for (int i = 1; i <= n; i++) { cin >> l >> t >> m; long long lb = l - 1, ub = 1e7 + 10; while (ub - lb > 1) { long long mid = (lb + ub) >> 1; if (a + (mid - 1) * b <= t &&...
11
#include <bits/stdc++.h> using namespace std; const int maxn = 300002; char str[maxn]; int a[3 * maxn], b[3 * maxn]; int n; int pos[3 * maxn], m; int tmp[3 * maxn], t; int main() { scanf("%d", &n); scanf("%s", str + 1); for (int i = 1; i <= n; i++) { if (str[i] == '(') a[i] = 1; else a[i] = -1...
17
#include <bits/stdc++.h> using namespace std; int n, sz, g, h, i, j, T, pos1, pos2, i1, i2, d, sh, st, mn, k; vector<vector<int> > a; int main() { cin >> n; a.assign(n, vector<int>(4, -1)); g = 0; for (i = 0; i < n - 1; i += 2) { a[i][0] = a[i + 1][0] = g; g = (g + 1) % 26; } g = 1; for (i = 0; i ...
5
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5, M = 1e9 + 7; int n, a[N]; long long bigmod(long long b, long long p) { long long t = 1; for (; p; b = (b * b) % M, p >>= 1) if (p & 1) t = (t * b) % M; return t; } long long go(int now) { vector<int> div; for (int i = 1; i * i <= now; i+...
12
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 5; int n; char c[maxn]; bool can(char s[], int d) { int rem = 0; for (int i = 0; i < n; i++) { rem *= 10; rem = (rem + (s[i] - '0')) % d; } return !rem; } string gen() { c[0] = '1'; for (int i = 1; i < n; i++) { c[i] = '0'; }...
6
#include <bits/stdc++.h> using namespace std; const int limit = 1e7 + 1; const int inf = 1e7; const int mod = 1e9 + 7; vector<bool> sieve(int n) { vector<bool> prime(n, 1); prime[0] = 0; prime[1] = 0; for (int i = 2; i <= sqrt(n); i++) { if (prime[i]) { for (int j = i * i; j <= n; j += i) { pr...
5
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 10; 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; } void p...
13
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 5; inline int input() { char c = getchar(); int o; bool f = 0; while (c > 57 || c < 48) f |= (c == '-'), c = getchar(); for (o = 0; c > 47 && c < 58; c = getchar()) o = (o << 1) + (o << 3) + (c - 48); return f ? -o : o; } vector<int> E...
22
#include <bits/stdc++.h> using namespace std; bool valid(int i, int j, int n) { return (i >= 0) && (j >= 0) && (i < n) && (j < n); } int main() { ios_base::sync_with_stdio(false); int n; cin >> n; vector<string> board(n); int count; for (int i = 0; i < n; i++) cin >> board[i]; for (int i = 0; i < n; i++...
2
#include <bits/stdc++.h> using namespace std; template <class T> void dbs(string str, T t) { cerr << str << " : " << t << "\n"; } template <class T, class... S> void dbs(string str, T t, S... s) { long long idx = str.find(','); cerr << str.substr(0, idx) << " : " << t << ", "; dbs(str.substr(idx + 1), s...); } ...
17
#include <bits/stdc++.h> using namespace std; int n, m; int main() { cin >> n >> m; int now = 0, t, ans = 0; for (int i = 1; i <= n; ++i) { scanf("%d", &t); if (now + t > m) { ++ans; now = t; } else now += t; } if (now != 0) ++ans; cout << ans << endl; return 0; }
2
#include <bits/stdc++.h> using namespace std; namespace red { inline long long read() { long long x = 0; char ch, f = 1; for (ch = getchar(); (ch < '0' || ch > '9') && ch != '-'; ch = getchar()) ; if (ch == '-') f = 0, ch = getchar(); while (ch >= '0' && ch <= '9') { x = (x << 1) + (x << 3) + ch - '0'...
22
#include <bits/stdc++.h> #pragma GCC target("pclmul") using ul = std::uint32_t; using ull = std::uint64_t; using li = std::int32_t; using ll = std::int64_t; using uss = std::uint8_t; ul n, m, k; const ul maxn = 5e5; const ul maxm = 5e5; char s[maxn + 2]; char t[maxm + 2]; char sr[maxn + 2]; char tr[maxm + 2]; ul kmp[ma...
18
#include <bits/stdc++.h> using namespace std; int main() { int a, b; string ch1, ch2; ch1 = "YES"; ch2 = "NO"; cin >> a >> b; if ((a == 0) && (b == 0)) cout << ch2; else if ((a - b == 1) || (a - b == -1) || (a == b)) cout << ch1; else cout << ch2; return 0; }
2
#include <bits/stdc++.h> using namespace std; int main() { int a, b, n, i, val; cin >> n; n--; cin >> a >> b; val = max(a, b); while (n--) { cin >> a >> b; if (max(a, b) <= val) val = max(a, b); else if (min(a, b) <= val) val = min(a, b); else { cout << "NO\n"; return...
2
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; const long long N = 1000005; void solve() { long long n, k; cin >> n >> k; string s; cin >> s; long long ans = 0; for (long long i = 0; i < n; i++) { if (s[i] == 'W') ans++; } ans = min(ans + k, n); ans = ans * 2; lo...
6
#include <bits/stdc++.h> using namespace std; const int N = 300001; int T, n, a[N]; int main() { scanf("%d", &T); while (T--) { scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); } if (a[1] < a[n]) { printf("YES\n"); } else { printf("NO\n"); } } }
6
#include <bits/stdc++.h> using namespace std; long long a[55], b[55]; long long maxs[55]; int main() { int n, m; while (~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; i++) { maxs[i] = a[i] * b[0]; for (int j ...
6
#include <bits/stdc++.h> using namespace std; template <class T> void read(T& x) { T res = 0, f = 1; char c = getchar(); while (!isdigit(c)) { if (c == '-') f = -1; c = getchar(); } while (isdigit(c)) { res = (res << 3) + (res << 1) + c - '0'; c = getchar(); } x = res * f; } const long lon...
10
#include <bits/stdc++.h> using namespace std; int main() { int a[1000003], i, j, ans[1000002], n, b, c; string s; cin >> s; s = '#' + s; n = s.length(); b = 1; c = n - 1; for (i = 1; i < n; i++) { if (s[i] == 'r') { a[i] = b; b++; } else if (s[i] == 'l') { a[i] = c; c--; ...
4
#include <bits/stdc++.h> using namespace std; int main() { int n, t; cin >> n >> t; map<double, int> m; for (int i = 0; i < n; i++) { double xi, ai; cin >> xi >> ai; m[xi - ai / 2.0]++; m[xi + ai / 2.0]--; } vector<pair<double, int> > v; int res = 2; for (__typeof(m.begin()) it = m.begin...
4
#include <bits/stdc++.h> using namespace std; int arr[10][10]; int main() { int row, col, n, num, r, c; cin >> row >> col >> n >> num; for (int i = 0; i < n; i++) { cin >> r >> c; arr[r - 1][c - 1] = 1; } for (int i = 0; i < row; i++) { for (int j = 0; j < col; j++) { if (i) arr[i][j] += arr...
3
#include <bits/stdc++.h> #define ll long long #define int long long using namespace std; double a[4]={0}; double sum=0; const double eps=1e-8; void dps(double c,double m,double p,double v,double g,int dep) { if(c>eps){ double t=min(c,v); if(m>eps) dps(c-t,m+t/2,p+t/2,v,g*c,de...
11
#include <bits/stdc++.h> using namespace std; map<long long int, bool> arr; int main() { ios::sync_with_stdio(false); ios_base::sync_with_stdio(false); cin.tie(nullptr), cout.tie(nullptr); int n; bool ok1 = 0, ok2 = 0; long long int l, x, y, temp; cin >> n >> l >> x >> y; if (y < x) swap(x, y); while ...
9
#include <bits/stdc++.h> using namespace std; const int maxn = 200; int n, k; int num[maxn]; int unos[maxn], dos[maxn]; int main() { cin >> n >> k; for (int i = 0; i < n; i++) cin >> num[i]; int cant = 0; for (int i = 0; i < k; i++) { for (int j = i; j < n; j += k) { if (num[j] == 1) unos[i]++...
2
#include <bits/stdc++.h> using namespace std; void solve() { int n, k, st = -1, ed = -1; string s; cin >> n >> k >> s; for (int i = 0; i < s.size(); ++i) { if (s[i] == 'G') st = i; if (s[i] == 'T') ed = i; } for (int i = min(st, ed); i <= max(st, ed); i += k) { if (s[i] == '#') { cout << "...
0
#include <bits/stdc++.h> using namespace std; const long long N = 1e6 + 5; const long long mod = 998244353; const long long INF = 0x7f7f7f7f7f7f7f7f; const int INFi = 0x7f7f7f7f; int test = 1; int push_back[N], pr[N], n, m, q, dp[N][2]; char L[N], R[N], U[N], D[N]; int solve(char *L, char *R, char *U, char *D, int n, i...
25
#include <bits/stdc++.h> using namespace std; int a[100100], b[100100], m[100100]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long n, x; cin >> n >> x; for (int i = 0; i < n; i++) { cin >> a[i]; if (b[a[i]] >= 1) { cout << 0 << endl; return 0; ...
4
#include <bits/stdc++.h> using namespace std; int a, b, L, R, le, ri, ans, ans1, vis[256], ch[256]; int main() { scanf("%d%d%d%d", &a, &b, &L, &R); for (int i = 1; i <= 10; i++) { int l = (i - 1) * (a + b) + 1, r = i * (a + b); memset(vis, 0, sizeof(vis)); for (int j = max(1, l - a); j < l; j++) vis[ch[...
14
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; int main(int argc, char const *argv[]) { ios_base::sync_with_stdio(0); cin.tie(NULL); long long t; cin >> t; while (t--) { long long n; cin >> n; long long a[n]; for (long long i = 0; i < n; i++) cin >> a[i]; std::vector<...
5
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; int main() { int n; scanf("%d", &n); int p[256][256]; memset(p, 0, sizeof p); p[0][0] = 1, p[1][1] = 1; for (int i = 2; i <= n; i++) { p[i][0] = p[i - 2][0]; for (int j = 1; j < 256; j++) { p[i][j] = (p[i - 1][j - 1] ...
14
#include<bits/stdc++.h> using namespace std; const int maxn = 1e6+1; const int mod = 998244353; int a[1001][501], b[501], cnt[501]; int f[1001]; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int T = 1; cin >> T; while(T --) { int n; cin >> n; for(int i = 1; ...
20
#include <bits/stdc++.h> using namespace std; int main() { int n, t; cin >> n >> t; char *s = NULL; s = new char(n); cin >> s; int i, j; for (i = 0; i < t; i++) { for (j = 0; j < n - 1; j++) { if (s[j] == 'B' && s[j + 1] == 'G') { s[j] = 'G'; s[j + 1] = 'B'; j = j + 1; ...
0
#include <bits/stdc++.h> using namespace std; int main() { cin.sync_with_stdio(0); int N, A, B; cin >> N; vector<int> V(N); for (int i = 0; i < N; i++) cin >> V[i]; sort(V.begin(), V.end()); cin >> A >> B; vector<int> go(1000000 + 47, 1); for (int i = 0; i < N; i++) if (i == 0 || V[i] != V[i - 1])...
14
#include <bits/stdc++.h> using namespace std; int n, m; int color[100007]; vector<int> g[100007]; map<pair<int, int>, int> reb; int root; int was[100007]; vector<int> st; vector<int> cyc; long long ans[100007]; void dfs(int v, int col) { if (cyc.size()) return; st.push_back(v); was[v] = col; for (int to : g[v])...
19
#include <bits/stdc++.h> using namespace std; void solve() { int t; cin >> t; while (t--) { int a, b, c, n; cin >> a >> b >> c >> n; int maxK = max(max(a, b), max(b, c)); int need = maxK - a + maxK - b + maxK - c; cout << (need <= n && (n - need) % 3 == 0 ? "YES" : "NO") << endl; } } int mai...
0
#include <bits/stdc++.h> using namespace std; void solve() { vector<string> g; int n, m; cin >> n >> m; g.resize(n); for (int i = 0; i < n; i++) cin >> g[i]; bool good = true; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if (g[i][j] == '*') { continue; } int va...
3
#include <bits/stdc++.h> using namespace std; const int N = 123, bits = 5001234; int n, all = 0; long long A[N], low[N], high[N], num[N], Val[bits]; map<int, int> nxt[bits]; int count(int x) { int res = 0; while (x) res++, x -= (x & -x); return res; } int Add(int s, int e) { if (!nxt[s].count(e)) nxt[s][e] = ++...
16
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; inline long long read() { register long long x = 0, f = 1; register char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == '-') f = -1; for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48); return x * f; } v...
21
#include <bits/stdc++.h> using namespace std; vector<int> in[2 * 100000 + 5], out[2 * 100000 + 5]; bool cycle; int visited[100000 + 5]; int done[100000 + 5]; int offset = 1; void dfs(int v) { visited[v] = offset; for (int i = 0; i < out[v].size(); ++i) { int u = out[v][i]; if (visited[u] == 0) { dfs(u...
14
#include <bits/stdc++.h> using namespace std; long long int isPrime(long long int n) { long long int flag = 1; for (int i = 2; i <= sqrt(n); i++) { if ((n % i) == 0) { flag = 0; break; } } if (n == 1) return false; else if (flag == 0) return false; else return true; } bool is...
2
#include <bits/stdc++.h> using namespace std; vector<long long> v; int main() { int q, a; long long b, sum = 0, cur = 0; scanf("%d", &q); while (q--) { scanf("%d", &a); if (a == 1) { scanf("%lld", &b); v.push_back(b); if (v.size() >= 2) sum += b - v[v.size() - 2]; else ...
10
#include <bits/stdc++.h> using namespace std; int main() { int n, a = 0, d = 0; cin >> n; char ar[n]; for (int i = 1; i <= n; i++) { cin >> ar[i]; } for (int i = 1; i <= n; i++) { if (ar[i] == 'A') a = a + 1; if (ar[i] == 'D') d = d + 1; } if (a > d) cout << "Anton"; else if (d > a) ...
0
#include <bits/stdc++.h> using namespace std; const double EPS = 1e-8; const double PI = acos(-1.0); const long long MOD = 1e9 + 7; const int INF = 0x3f3f3f3f; const long long LL_INF = 0x3f3f3f3f3f3f3f3f; int n; int num[100005]; vector<int> v[100005]; int C[100005]; int lowbit(int x) { return x & (-x); } void add(int x...
8
#include <bits/stdc++.h> using namespace std; const int N = 300; const int M = 1 << 10; const long long INF = 1e18; const long double EPS = 1e-9; mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); long long random(long long a, long long b) { return uniform_int_distribution<long long>(a, b)(rng); ...
11
#include <bits/stdc++.h> using namespace std; template <typename A, typename B> string to_string(pair<A, B> p); template <typename A, typename B, typename C> string to_string(tuple<A, B, C> p); template <typename A, typename B, typename C, typename D> string to_string(tuple<A, B, C, D> p); string to_string(const string...
17
#pragma GCC optimize(3) #include <cstdio> #include <queue> #include <string> #include <cstring> #include <algorithm> #include <cstdlib> #include <iostream> #include <iomanip> #include <cmath> #include <vector> #include <set> #include <map> #include <fstream> #include <cassert> #include <complex> #include <ctime> //#inc...
18
#include<bits/stdc++.h> #define N 100005 #define il inline #define R register #define ll long long int #define ull unsigned long long int using namespace std; il ll read() { R ll x = 0; char ch = getchar(); while (ch < '0' || ch>'9') ch = getchar(); while (ch >= '0' && ch <= '9') x = (x << 3) + (x << 1) + (ch ^ 48),...
9
#include <bits/stdc++.h> using namespace std; char ch[110000]; int n, m; set<int> L, R; vector<int> go; int getrem() { set<int>::iterator k = L.begin(); int ans = n + 1; if (k != L.end()) ans = min(ans, (*k)); k = R.begin(); if (k != R.end()) ans = min(ans, (*k)); return ans; } int main() { scanf("%s", ch...
19
#include <bits/stdc++.h> using namespace std; int main() { long long x1, x2, y1, y2, n; cin >> x1 >> y1 >> x2 >> y2 >> n; long long a, b, c; int steps = 0; for (int i = 0; i < n; i++) { cin >> a >> b >> c; bool sign0, sign1; sign0 = a * x1 + b * y1 + c > 0; sign1 = a * x2 + b * y2 + c > 0; ...
9
#include <bits/stdc++.h> using namespace std; long long t[20], f[20][20]; int n, ans[20][20], prex[20][20], prey[20][20]; char s[40]; void print(int i, int j) { if (j == 0) return; if (i && f[i][j] - f[i - 1][j] == t[i - 1] * (s[n * 2 - i - j] - '0')) { printf("H"); print(i - 1, j); } else { printf("M...
16
#include <bits/stdc++.h> using namespace std; const long long MOD = 1000000007; const long long INF = 1e9 + 5; const double eps = 1e-7; const double PI = acos(-1.0); inline void debug_vi(vector<int> a) { for (long long i = (long long)(0); i < (long long)(a.size()); i++) cout << a[i] << " "; } inline void debug_vl...
9
#include <bits/stdc++.h> using namespace std; struct point { double x; double y; point(long long x, long long y) : x(x), y(y) {} }; double len(point p1, point p2) { return sqrt((p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y)); } struct triangle { point p1; point p2; point p3; triangle(poin...
10
#include <bits/stdc++.h> using namespace std; int main() { double L, d, v1, v2; cin >> d >> L >> v1 >> v2; cout << setprecision(11) << (L - d) / (v1 + v2); }
0
#include <bits/stdc++.h> using namespace std; const long long MAXN = 501 * 1001; long long fen[2][MAXN]; void add(long long x, long long v, long long id) { for (; x < MAXN; x += x & -x) fen[id][x] += v; } long long get(long long x, long long id) { long long ans = 0; for (; x; x -= x & -x) ans += fen[id][x]; ret...
16
#include <bits/stdc++.h> using namespace std; int main() { long long n, m, i, s = 0, j = 0; cin >> n >> m; long long a[n]; long long b[m]; for (i = 0; i < n; i++) cin >> a[i]; for (i = 0; i < m; i++) { cin >> b[i]; while ((s + a[j]) < b[i]) { s = s + a[j]; j++; } cout << j + 1 <<...
2
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; vector<pair<int, int>> types; long long dp[3001][100][101] = {0}; int main() { int n, l; cin >> n >> l; for (int i = 0; i < n; i++) { int a, b; cin >> a >> b; types.push_back({a, b}); } for (int i = 0; i < n; i++) { d...
10