solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> using namespace std; int i, j, k, l, s, n, m, last[35], a[400005], b[35], q[35], r, x, G[400005]; long long ans; struct node { int v, id; } f[400005][20], ma; inline node Max(node x, node y) { if (x.v >= y.v) return x; return y; } inline int find(int x) { int s = 0; while (x) s++, x >...
14
#include <bits/stdc++.h> using namespace std; void guan() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } const int maxn = 1000010; const long long mod = 1e9 + 7; const long long mod2 = mod - 1; const int INF = 0x7FFFFFFF; const long long LINF = 0x7FFFFFFFFFFFFFFF; const double pi = acos(-1.0); co...
19
#include <bits/stdc++.h> using namespace std; const int NEGINF = -1000000000; const int INF = 1000000000; int division(int rating) { return rating >= 1900 ? 1 : 2; } bool possible(int rating, int *c, int *div, int n) { for (int i = 0; i < n; ++i) { if (division(rating) != div[i]) { return false; } r...
8
#include <bits/stdc++.h> using namespace std; void prepare() {} int n; int a[105]; void solve() { scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%d", &a[i]); int r = 0, ri = 0; for (int i = 0; i < n; i++) { if (a[i] != 1) continue; int cur = 1; int p = 1; for (int j = i + 1; j < n; j++) { ...
5
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; cout << 3 * n + 4 << endl; cout << "0 0\n"; for (int i = 0; i <= n; i++) { cout << i << " " << i + 1 << endl; cout << i + 1 << " " << i << endl; cout << i + 1 << " " << i + 1 << endl; } return 0; }
7
#include <bits/stdc++.h> using namespace std; char s[4005]; map<long long, long long> mp; int main() { int a; scanf("%d", &a); scanf("%s", s + 1); int len = strlen(s + 1); for (int i = 1; i <= len; i++) { long long tmp = 0; for (int j = i; j <= len; j++) { tmp += s[j] - '0'; mp[tmp]++; ...
8
#include <bits/stdc++.h> int n, m, k; int dp[1001][1001]; long long stt(int l, int mv) { if (mv == k) return 1; if (dp[l][mv] != -1) return dp[l][mv]; int i, j; long long sm = 0; for (i = l - 2; i > 0; i--) { sm += stt(i, mv + 1) * (l - 2 - i + 1); sm %= 1000000007; } dp[l][mv] = sm; return sm; ...
12
#include <bits/stdc++.h> using namespace std; struct edge { int u, v, id; edge() {} edge(int _u, int _v, int _id) { u = _u; v = _v; id = _id; } }; int N; map<int, vector<edge> > road; int compsiz[100005], rnk[100005], parent[100005]; long long ans; vector<int> vans; vector<int> nodes, adj[100005]; i...
15
#include <bits/stdc++.h> using namespace std; const int N = 1e7 + 5; const long long inf = 2e9 + 5; const long long OO = 1e18 + 5; const long long mod = 1e9 + 7; double fp(double x, int p) { double ret = 1; while (p) { if (p & 1) ret *= x; x *= x; p >>= 1; } return ret; } int main() { int m, n; ...
8
#include <bits/stdc++.h> using namespace std; const int N = 10004; string s; int c0 = 0, c1 = 0, cw = 0; set<string> st; int main() { cin >> s; for (char ch : s) { if (ch == '0') ++c0; else if (ch == '1') ++c1; else ++cw; } int n = s.size(); if (c0 + cw - c1 >= 1) st.insert("00")...
11
#include <bits/stdc++.h> using namespace std; int main() { int n, k, m, a; scanf("%d %d %d %d", &n, &k, &m, &a); vector<int> votes(n, 0); vector<int> last(n, -1); for (int i = 0; i < a; i++) { int foo; scanf("%d", &foo); foo--; votes[foo]++; last[foo] = i; } vector<bool> chance(n, fals...
13
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n, m; cin >> n >> m; int a[n], b[m]; int flag = 0; 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++) { ...
0
#include <bits/stdc++.h> using namespace std; int main() { long long int t; cin >> t; while (t--) { long long int a, b, i, j; cin >> a >> b; cout << (a ^ b) << "\n\n"; } }
0
#include <bits/stdc++.h> using namespace std; long long int mpw(long long int a, long long int b, long long int m) { long long int ans = 1; if (a == 0) return 0; if (a == 1 || b == 0) return 1; while (b) { if (b & 1) { ans = (ans * a) % m; } a = (a * a) % m; b >>= 1; } return ans; } lo...
4
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 7; int a[N]; int main() { int n; cin >> n; for (int i = 0; i <= n; i++) a[i] = i; long long ans; for (int i = n; i > 0; i--) if (a[i] == i) { int p = (1 << (32 - __builtin_clz(i))) - 1; ans += 2 * p; swap(a[i], a[p ^ i]); ...
9
#include <bits/stdc++.h> using namespace std; const double eps = 1e-10; pair<double, int> c[10010]; int n; struct point { double x, y; } p[600][5]; int dblcmp(double x) { if (fabs(x) < eps) return 0; return x > 0 ? 1 : -1; } double cross(point p1, point p2, point p3) { return (p2.x - p1.x) * (p3.y - p1.y) - (p2...
19
#include <bits/stdc++.h> using namespace std; long long int mod = 1e9 + 7; const long long int Size = 3e6 + 1; int minPrime[Size]; vector<pair<int, int> > factor[Size]; void findPrime() { for (int i = 1; i < Size; i++) minPrime[i] = i; for (long long int i = 2; i < Size; i++) { if (minPrime[i] != i) continue; ...
13
#include <bits/stdc++.h> using namespace std; template <class T> using min_heap = priority_queue<T, std::vector<T>, std::greater<T>>; struct hash_pair { template <class T1, class T2> size_t operator()(const pair<T1, T2>& p) const { auto hash1 = hash<T1>{}(p.first); auto hash2 = hash<T2>{}(p.second); ret...
10
#include <bits/stdc++.h> using namespace std; const long long N = 200111; const long long inf = 1L << 60; long long n, k; long long a[N]; long long b[N]; int main() { while (cin >> n >> k) { for (long long i = 0; i <= n; i++) { cin >> a[i]; b[i] = a[i]; } for (long long i = 0; i < n; i++) { ...
14
#include <bits/stdc++.h> using namespace std; int length, n, bucket, ans = 1e9 + 7; int main() { cin >> n >> length; for (int i = 0; i < n; i++) { cin >> bucket; if (length % bucket == 0 && bucket <= length) ans = (ans < length / bucket ? ans : length / bucket); } cout << ans; return 0; }
1
#include <bits/stdc++.h> using namespace std; const int N = 1087; map<string, int> mp; vector<int> g[N]; int a[N], ct[N]; int id(const string& s) { if (!mp.count(s)) { int t = mp.size() + 1; mp[s] = t; } return mp[s]; } int dfs(int u) { int ans = 0, oct = ct[a[u]]; for (int v : g[u]) ans += dfs(v); ...
9
#include <bits/stdc++.h> using namespace std; int main() { int n, m; while (cin >> n >> m) { double a[n], ans = 0.0; for (int i = 1; i <= n; i++) cin >> a[i]; while (m--) { int x, y; double z; cin >> x >> y >> z; ans = max(ans, (a[x] + a[y]) / z); } cout << fixed << setpr...
8
#include <bits/stdc++.h> using namespace std; int main() { int n, h, a, b, k; cin >> n >> h >> a >> b >> k; for (int i = 0; i < k; i++) { int ta, tb, fa, fb; cin >> ta >> fa >> tb >> fb; if (ta == tb) { cout << abs(fa - fb) << endl; continue; } int t1 = min(abs(fa - a), abs(fa - b)...
2
#include <bits/stdc++.h> using namespace std; const long long N = 1 << 18; const long long INF = 1000000000; long long n, pr[10], g; string t; long long re(long long v, long long x) { long long s = 0; for (int i = 2; i <= v; i++) { g = i; while (g % x == 0) { s++; g /= x; } } return s; }...
6
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; template <class T> void chmin(T &a, const T &b) { if (a > b) a = b; } template <class T> void chmax(T &a, const T &b) { if (a < b) a = b; } vector<vector<int>> g; vector<int> exist; set<pair<int, int>> se; int cnt; vector<int> dp; vector<i...
18
#include <bits/stdc++.h> using namespace std; const int Maxn = 4005, Maxk = 80, p = 998244353; int n1, n2, k, cnt, ct, tot_siz, root, head[Maxn], siz[Maxn], maxi[Maxn], node[Maxn]; long long tot, ans[2][Maxk], C[Maxk][Maxk]; bool type, vis[Maxn]; struct edg { int nxt, to; } edge[2 * Maxn]; void add(int x, int y) ...
21
#include <bits/stdc++.h> using namespace std; int main(void) { int n; cin >> n; string s; cin >> s; bool found = false; for (int len = 1; len <= s.length() / 4; len++) { for (int start = 0; start + 4 * len < s.length(); start++) { bool poss = true; for (int kk = 0; kk <= 4; kk++) { i...
5
#include <bits/stdc++.h> #pragma GCC optimize(2) using namespace std; const int INF = 0x3f3f3f3f; int n, m; char maze[102][102]; struct ope { int x, y, xx, yy, xxx, yyy; ope(int a, int b, int c, int d, int f, int e) { x = a; y = b; xx = c; yy = d; xxx = f; yyy = e; } }; int a[102][102]; ve...
11
#include <bits/stdc++.h> using namespace std; inline long long rd() { long long x = 0; int ch = getchar(), f = 1; while (!isdigit(ch) && (ch != '-') && (ch != EOF)) ch = getchar(); if (ch == '-') { f = -1; ch = getchar(); } while (isdigit(ch)) { x = (x << 1) + (x << 3) + ch - '0'; ch = getch...
16
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; long long n, h, a, b, k; int main() { cin.tie(0), ios::sync_with_stdio(0); cin >> n >> h >> a >> b >> k; while (k--) { long long ans = 0, curr; long long x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2; if (x1 == x2) { ...
2
#include <bits/stdc++.h> #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") #pragma GCC optimize("fast-math") using namespace std; void solve(); signed main() { srand(time(0)); ios_base::sync_with_stdio(...
16
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 7; pair<int, int> p[N]; int nxt[N]; int f[N]; stack<int> st; int main() { ios::sync_with_stdio(false); int d, n, m; cin >> d >> n >> m; for (int i = 1; i <= m; i++) cin >> p[i].first >> p[i].second; p[0] = {0, 0}; p[m + 1] = {d, 0}; m += 2;...
14
#include <bits/stdc++.h> using namespace std; const int max_n = 55, inf = 1000111222; int copy_dsu[max_n]; struct dsu { int p_or_sz[max_n]; void init(int n) { for (int i = 0; i < n; ++i) { p_or_sz[i] = -1; } } void init_from_copy(int n) { for (int i = 0; i < n; ++i) { p_or_sz[i] = copy_d...
25
#include <bits/stdc++.h> using namespace std; void solve() { long long int n; cin >> n; string k; cin >> k; long long int l = 0, r = 0; for (auto x : k) if (x == 'L') l++; else r++; cout << r + l + 1; } signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); ...
0
#include <bits/stdc++.h> using namespace std; const int maxn = 5e5 + 50; const int inf = 0x3f3f3f3f; const long long INF = 0x3f3f3f3f3f3f3f3f; const int mod = 998244353; int c[6][250]; struct node { int id, x, y; node(int i = 0, int j = 0, int d = 0) : id(i), x(j), y(d) {} }; vector<node> ans; queue<node> qu; bool ...
13
#include <bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; const int MAXN = 10, INF = 1e9, MAXM = 30; int n, m; int ans = 0; int used[MAXN][MAXN], c[MAXN]; pair<int, int> e[MAXM]; void check() { int cnt = 0; for (int i = 0; i < m; ++i) { if (used[c[e[i].first]][c[e[i].second]]) continue; used[...
9
#include <bits/stdc++.h> using namespace std; long long q; signed main() { ios_base::sync_with_stdio(0); cout.precision(40); cin >> q; while (q--) { long long a1, b1, a2, b2; cin >> a1 >> b1 >> a2 >> b2; if (a1 == a2) { if (b1 + b2 == a1) { cout << "Yes\n"; continue; } ...
1
#include <bits/stdc++.h> using namespace std; const int dydis = 401; const int inf = 1e9; int dp[dydis][dydis] = {0}; bool tinka(string visas, string a, string b) { for (int i = 0; i <= visas.size(); i++) { for (int j = 0; j <= a.size(); j++) { dp[i][j] = -inf; } } dp[0][0] = 0; for (int i = 0; i ...
14
#include <bits/stdc++.h> template <typename _T> inline bool read(_T& x) { x = 0; _T y = 1; char c = getchar(); while ((c < '0' || '9' < c) && c != EOF) { if (c == '-') y = -1; c = getchar(); } if (c == EOF) return false; while ('0' <= c && c <= '9') x = x * 10 + c - '0', c = getchar(); x *= y; ...
21
#include <bits/stdc++.h> using namespace std; const int MAX = 200007; const int MAXL = 20; int ancestor[MAX][MAXL]; vector<int> V[MAX]; bool vis[MAX]; int best_so_far[MAX]; int NA[MAX]; int pos[MAX]; int last_pos[MAX]; int A[MAX]; int P[MAX]; int B[MAX]; void dfs(int i, int p) { vis[i] = true; ancestor[i][0] = p; ...
12
#include <bits/stdc++.h> #pragma GCC optimize(3, "Ofast", "inline") using namespace std; const double pi = 3.1416; const int N(2e5 + 5); int n, m, a[N]; void work() { scanf("%d", &n); for (int i = 1; i <= n; ++i) scanf("%d", &a[i]); int L = 1, R = n; for (; L <= n; ++L) if (a[L] != L) break; for (; L <= R...
7
#include <bits/stdc++.h> using namespace std; const int N = 1010; int n, m, a[N], b[N]; int main() { scanf("%d%d", &n, &m); for (int i = 1; i <= n; ++i) scanf("%d", &a[i]); for (int i = 1; i <= n; ++i) scanf("%d", &b[i]); double tmp = 1; for (int i = 1; i <= n; ++i) { if (a[i] <= 1 || b[i] <= 1) return pu...
7
#include <bits/stdc++.h> using namespace std; inline long long gcd(long long a, long long b) { long long c; while (b) { c = b; b = a % b; a = c; } return a; } int main() { int n; cin >> n; int arr[n]; cin >> arr[0]; long long div, mx; div = mx = arr[0]; for (int i = 1; i < n; ++i) { ...
8
#include <bits/stdc++.h> struct Node { int total; std::array<int, 10> next; Node() : total(0), next() {} }; struct Solution { int n, k; std::vector<std::string> ss; std::vector<int> ms; std::vector<Node> tree; std::vector<std::vector<std::vector<int>>> dyn; void buildTree() { for (int i = 0; i < n...
20
#include <bits/stdc++.h> using namespace std; int read() { int v = 0, f = 1; char c = getchar(); while (c < 48 || 57 < c) { if (c == '-') f = -1; c = getchar(); } while (48 <= c && c <= 57) v = (v << 3) + v + v + c - 48, c = getchar(); return v * f; } const int N = 3e5 + 10; const long long MOD = 1e...
23
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e5 + 5; const int MAXM = 1e4 + 5; const int MOD = 998244353; const long long INF = 1e18; char s[MAXN], t[MAXN]; int lm[MAXN], rm[MAXN]; void init() { memset(lm, 0, sizeof(lm)); memset(rm, 0, sizeof(rm)); } int main() { init(); scanf("%s", s + 1); ...
9
#include <bits/stdc++.h> using namespace std; set<int> all[26]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); ; string s; cin >> s; for (int i = 0; i < s.size(); i++) { all[s[i] - 'a'].insert(i); } int q; cin >> q; while (q--) { int t; cin >> t; if (t == 1) { int pos; ...
8
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 7; int n, q, a[N], l[N], ans[N], seg[N * 4], lazy[N * 4]; vector<int> id[N]; void LAZY(int p, int L, int R) { if (L != R) { lazy[2 * p] += lazy[p]; lazy[2 * p + 1] += lazy[p]; } seg[p] += lazy[p]; lazy[p] = 0; return; } void update(int ...
15
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n, k; cin >> n >> k; vector<long long> total_sum(n + 1, 0), aparent_sum(n + 1, 0); for (int i = 1; i <= n; i++) cin >> total_sum[i]; int val; for (int i = 1; i <= n; i++) { cin >> val; if...
4
#include <bits/stdc++.h> using namespace std; int main() { long long int i, j = 0, k, l, a = 0, b, m, n, ck = 0, aa, bb, dk = 0; scanf("%lld", &n); while (n != 0) { if (n >= 100) { n -= 100; ck++; } else if (n >= 20) { n -= 20; ck++; } else if (n >= 10) { n -= 10; c...
0
#include <bits/stdc++.h> using namespace std; const long long inf = 1e18; const long long mod = 1e9 + 7; const long long N = 2e6 + 1; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); long long power(long long a, long long b = mod - 2) { long long res = 1; while (b > 0) { if (b & 1) res = res...
16
#include <bits/stdc++.h> using namespace std; long long a[100000], b[100000], c[100000]; int main() { int t; cin >> t; a[0] = 0; a[1] = 1LL; for (int i = 2; i <= 31; i++) a[i] = 4LL * a[i - 1] + 1LL; while (t--) { int n; long long k; cin >> n >> k; if (n > 31) { cout << "YES " << n - 1...
12
#include <bits/stdc++.h> using namespace std; int main() { int n, ns = 0, ew = 0, ans = 0, k; string s; cin >> n; for (int i = 0; i < n; i++) { cin >> k >> s; if (s == "South") { ns += k; } else if (s == "East") { if (ns == 20000 or ns == 0) { ans = 1; break; } ...
5
#include <bits/stdc++.h> using namespace std; long long arr[10000]; long long maxx; long long stop; long long dfs(long long i) { if (i > stop || arr[i] < 0) return 0; int m = arr[i]; long long x1 = dfs(i * 2); long long x2 = dfs(i * 2 + 1); if (x1 > x2) { m += x1; maxx += (x1 - x2); } else { m +...
6
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const int MOD = 998244353; long long n, m; long long ele(long long base, long long e) { long long ans = 1; while (e) { if (e & 1) ans = (ans * base) % MOD; base = (base * base) % MOD; e >>= 1; } return ans; } int main() { io...
5
#include <bits/stdc++.h> using namespace std; const long long mx = 200001; const long long mod = 1e9 + 7; long long gcd(long long a, long long b) { if (b == 0) return a; return gcd(b, a % b); } long long extgcd(long long a, long long b, long long& x, long long& y) { if (b == 0) { x = 1; y = 0; return ...
4
#include <bits/stdc++.h> using namespace std; const long double INF = 1e10; struct Travolator { int l; long double v; long double L; long double R; }; vector<Travolator> t; struct Vertex { long double p; long double minimum; }; vector<Vertex> rmq; void push(int i, int l, int r) { if (r - l <= 1) return; ...
25
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c, d, m, v; cin >> a >> b >> c >> d; m = max((3 * a) / 10, a - ((a / 250) * c)); v = max((3 * b) / 10, b - ((b / 250) * d)); if (m > v) cout << "Misha"; else if (m < v) cout << "Vasya"; else cout << "Tie"; }
1
#include <bits/stdc++.h> using namespace std; map<long long, long long> f; int main() { long long n, c = 0, s = 0; cin >> n; pair<int, int> a[n], A[n]; for (int i = 0; i < n; i++) { cin >> a[i].first >> a[i].second; A[i].first = a[i].second; A[i].second = a[i].first; } sort(a, a + n); sort(A, ...
6
#include <bits/stdc++.h> using namespace std; int c1[26], c2[26]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); string x, y; cin >> x >> y; vector<vector<int> > occ(26); for (auto i = 0; i < (long long)(((int)((x).size()))); i++) c1[x[i] - 'a']++, occ[x[i] - 'a'].push_back(i); for (auto i = 0...
7
#include <bits/stdc++.h> using namespace std; const int MaxN = 1e5 + 10; const int INF = 1e9; const int MOD = 1e9 + 7; int n; long double a[MaxN], b[MaxN], ca[MaxN], cb[MaxN]; pair<long double, long double> solve(long double p, long double q) { long double det = sqrt(fabs(p * p - 4 * q)); return make_pair((-p - det...
16
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; long long least = 1e+9; while (m--) { long long l, r; cin >> l >> r; least = min(least, (r - l + 1)); } cout << least << "\n"; long long counter = 0; for (int i = 1; i <= n; i++) { cout << counter % least...
9
#include <bits/stdc++.h> using namespace std; const int MAX = 800 * 1000; const long long MM = 1000LL * 1000 * 1000 * 1000LL * 1000 * 1000; const long long D = MM / 1000 * 1000; pair<long long, long long> s[MAX + 10]; long long a[MAX + 10]; bool mrk[MAX + 10]; vector<pair<long long, long long> > se[MAX + 10]; long long...
17
#include <bits/stdc++.h> using namespace std; void debug() { cout << endl; } template <typename T, typename... Args> void debug(T a, Args... args) { cout << a << ' '; debug(args...); } const int MOD = 1e9 + 7; long long mulmod(long long a, long long b, long long m) { long long r = a * b - (long long)((long double...
12
#include <bits/stdc++.h> using namespace std; vector<int> X = {-1, 0, 0, 1}; vector<int> Y = {0, -1, 1, 0}; void find_comp(pair<int, int> beg, const vector<vector<bool>> &a, vector<vector<bool>> &used) { used[beg.first][beg.second] = true; vector<pair<int, int>> ans; ans.emplace_back(beg); queue<...
12
#include <bits/stdc++.h> using namespace std; long long n, bb, res = 0; vector<long long> v; long long busquedaBinaria(const long long &p) { long long maxP = (-1), ini = p, fin = (n - 1), m; while ((ini + 1) < fin) { m = ((ini + fin) / 2); if (abs(v[p] - v[m]) <= 5) ini = m, maxP = max(maxP, m); e...
4
#include <bits/stdc++.h> using namespace std; const long long INF = 1000000007; const long long INFL = 1000000000000000007; const long double INFS = 0.00000001; const long long MOD = 1000000007; const long double PI = 3.14159265; const int dir[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}}; const int dir2[8][2] = {{1, 1}, ...
12
#include <bits/stdc++.h> using namespace std; int main() { long long n, m = 0, j, i, k = 0, c = 0, x = 0, y = 0, t, ans = 0; cin >> n >> m; long long a[n][m]; vector<pair<long long, long long> > row, col; vector<pair<long long, long long> > r1, c1; for (i = 0; i < n; i++) { c = 0; for (j = 0; j < m;...
12
#include <bits/stdc++.h> #pragma optimize("Ofast") #pragma GCC optimize("-funsafe-loop-optimizations") #pragma GCC optimize("-funroll-loops") #pragma GCC optimize("-fwhole-program") #pragma GCC optimize("-fthread-jumps") #pragma GCC optimize("-falign-functions") #pragma GCC optimize("-falign-jumps") #pragma GCC optimiz...
16
#include <bits/stdc++.h> using namespace std; pair<int, string> p[110]; int n; int main() { cin >> n; for (int i = 0; i < n; i++) { string s1, s2; cin >> s1 >> s2; if (s2[0] == 'r') p[i].first = i; else if (s2[1] == 'h' || s2[0] == 'w') p[i].first = 1000 + i; else if (s2[0] == 'm') ...
1
#include <bits/stdc++.h> using namespace std; const int N = 1e6, M = N << 2; int n, m, q, valA[N], valB[N], buc[N + 10], lt[M], rt[M], minVal[M], add[M]; inline void pushdown(int); template <class T> inline void read(T &x) { x = 0; char ch = getchar(), w = 0; while (!isdigit(ch)) w = (ch == '-'), ch = getchar(); ...
14
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:100000000") using namespace std; const int BUCKET_SZ = 400; int n, k, a, b, q; int orders[300005]; int bad[300005 / BUCKET_SZ + 5], good[300005 / BUCKET_SZ + 5]; int main() { cin >> n >> k >> a >> b >> q; while (q--) { int t; scanf("%d", &t); if (...
9
#include <bits/stdc++.h> using namespace std; int ans[111]; int arr[111]; bool check[111]; int n, m; int main() { scanf(" %d %d", &n, &m); for (int i = 1; i <= n; i++) ans[i] = -1; for (int i = 1; i <= m; i++) scanf(" %d", &arr[i]); for (int i = 1; i < m; i++) { int diff = (arr[i + 1] - arr[i] + n) % n; ...
8
#include <bits/stdc++.h> using namespace std; const int maxn = 100010; template <typename Tp> inline int getmin(Tp &x, Tp y) { return y < x ? x = y, 1 : 0; } template <typename Tp> inline int getmax(Tp &x, Tp y) { return y > x ? x = y, 1 : 0; } template <typename Tp> inline void read(Tp &x) { x = 0; int f = 0; ...
25
#include <bits/stdc++.h> using namespace std; char mat[7][7], sol[7][7] = {{0, 0, 0, 0, 0, 0, 0}, {0, '0', '1', '2', '3', '4', '5'}, {0, '6', '7', '8', '9', 'A', 'B'}, {0, 'C', 'D', 'E', 'F', 'G', 'H'}, {...
20
#include <bits/stdc++.h> using namespace std; int TotalPoint, TotalEdge; int Start, End, Sp; int Ans, AllCost; bool Visit[201]; bool VisitDfs[201]; int Dist[201]; int U[201], D[201]; vector<int> Edge[201]; vector<int> Stream[201]; vector<int> Cost[201]; vector<int> Size[201]; inline void AddEdge(int From, int To, int N...
14
#include <bits/stdc++.h> using namespace std; const int maxn = 100010; const long long P = 1000000007; int n, cnt, fa[maxn], to[maxn << 1], nxt[maxn << 1], head[maxn], q[maxn], d[maxn]; long long k[maxn], b[maxn]; inline long long pm(long long x, long long y) { long long z = 1; while (y) { if (y & 1) z = z ...
16
#include <bits/stdc++.h> using namespace std; long long M = 1e6 + 3; long long mpe(long long base, long long exponent, long long modulus) { long long result = 1; while (exponent > 0) { if (exponent % 2 == 1) result = result * base % modulus; exponent = exponent >> 1; base = base * base % modulus; } ...
15
#include <bits/stdc++.h> using namespace std; int main(int argc, const char* argv[]) { int t; cin >> t; while (t--) { int n; cin >> n; vector<pair<int, int>> v(n); int left = 1e9 + 1, right = -1; for (int i = 0; i < n; ++i) { cin >> v[i].first >> v[i].second; left = min(left, v[i]....
3
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; int n, a, b, k, f; map<string, int> id; map<pair<int, int>, int> m; vector<pair<int, int> > edg; int go() { int at = -1, res = 0; for (auto it : edg) { pair<int, int> route = pair<int, int>(min(it.first, it.second), max(it.first, ...
10
#include <bits/stdc++.h> int main() { int n; scanf("%d", &n); int arr[n]; for (int i = 0; i < n; i++) { scanf("%d", &arr[i]); } for (int i = 0; i < (1 << n); i++) { int sum = 0; for (int j = 0; j < n; j++) { if (i & (1 << j)) { sum += arr[j]; } else { sum -= arr[j]; ...
4
#include <bits/stdc++.h> using namespace std; const int maxn = 200010; int n, a[maxn], b[maxn << 1], c[maxn], mx[maxn], gc[maxn]; int gcd(int a, int b) { return !b ? a : gcd(b, a % b); } int main() { scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%d", &a[i]); for (int i = 1; i < n; i++) gc[i] = gcd(i, n); ...
16
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; int k; cin >> k; if (k >= s.length()) { cout << "0"; return 0; } map<char, int> m; multimap<int, char> mm; for (int i = 0; i < s.length(); i++) m[s[i]]++; auto it = m.begin(); while (it != m.end()) { int f =...
4
#include <bits/stdc++.h> using namespace std; constexpr int INF = 1e9 + 7; constexpr long long INFL = 1e18; template <class L, class R> ostream &operator<<(ostream &os, pair<L, R> P) { return os << "(" << P.first << "," << P.second << ")"; } constexpr int maxn = 1005; vector<pair<int, int>> P, Q; vector<pair<int, int...
19
#include <bits/stdc++.h> using namespace std; int dp[505][1005]; int f[1005]; struct node { int l, r, w, s, v; void in() { scanf("%d%d%d%d%d", &l, &r, &w, &s, &v); } } a[1005]; bool cmp(node a, node b) { return a.r < b.r || (a.r == b.r && a.l > b.l); } int main() { int n, s; scanf("%d%d", &n, &s); for (int i ...
18
#include <bits/stdc++.h> using namespace std; void solve() { int a1, b1, a2, b2; cin >> a1 >> b1; cin >> a2 >> b2; int max1 = max(a1, b1); int max2 = max(a2, b2); int min1 = min(a1, b1); int min2 = min(a2, b2); if (max1 == max2 && min1 + min2 == max1) cout << "Yes" << endl; else cout << "No" <...
1
#include <bits/stdc++.h> using namespace std; int generate_random() { const int MAX_RANDOM = (int)1e6; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); return uniform_int_distribution<int>(0, MAX_RANDOM)(rng); } const long long INFLL = 2 * (long long)1e18 + 100; const int INFINT = 2 * (int)1e9...
12
#include <bits/stdc++.h> using namespace std; int minx(int x, int y) { if (x < y) y = x; return y; } int main(void) { int t, a, b, c, aa, bb, cc; cin >> a >> b >> c >> aa >> bb >> cc; t = minx(a, aa); a -= t; aa -= t; t = minx(b, bb); b -= t; bb -= t; t = minx(c, cc); c -= t; cc -= t; if (aa...
4
#include <bits/stdc++.h> using namespace std; void __print(int x) { cerr << x; } void __print(long x) { cerr << x; } void __print(float x) { cerr << x; } void __print(double x) { cerr << x; } void __print(unsigned x) { cerr << x; } void __print(long long x) { cerr << x; } void __print(long double x) { cerr << x; } void...
6
#include <bits/stdc++.h> using namespace std; int a[10]; int main() { string s, t; cin >> s >> t; int x = s.length(); for (int i = 0; i < x; i++) a[i] = s[i] - '0'; sort(a, a + x); if (a[0] == 0) { for (int i = 1; i < x; i++) if (a[i] > 0) { swap(a[i], a[0]); break; } } f...
3
#include <bits/stdc++.h> using namespace std; int main() { int w, h; cin >> w >> h; int modw, modh; modw = w / 2; modh = h / 2; double W, H; W = modw * (w - modw); H = modh * (h - modh); cout << setprecision(15) << W * H << endl; return 0; }
5
#include <bits/stdc++.h> #pragma GCC optimize("O3") #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #pragma warning(disable : 4996) using namespace std; clock_t start_time, end_time; void open() { ((void)0); ((void)0); ((void)0); ((void)0); } void close() { ((void)0); ((void)0); } const i...
10
#include <bits/stdc++.h> using namespace std; const long long MX = 50; long long n; long long arr[MX], P[MX]; long long dp[MX][MX]; long long calc(long long x, long long y) { if (x == n && y == n) return 0; long long &ret = dp[x][y]; if (ret != -1) return ret; long long pos = x + y + 1; ret = 0; if (x != n)...
16
#include <bits/stdc++.h> using namespace std; bool b2(const pair<pair<int, int>, int> &p1, const pair<pair<int, int>, int> &p2) { return p1.first.first > p2.first.first; } bool b1(const pair<pair<int, int>, int> &p1, const pair<pair<int, int>, int> &p2) { return p1.first.second < p2.first.second; } ...
8
#include <bits/stdc++.h> using namespace std; const int oo = 1000000009; const double eps = 1e-9; const int mod = 1000000007; int en, ans, len, l; vector<int> p[123460]; bool con[123460], visited[123460]; void dfs(int t) { stack<pair<int, int> > ms; ms.push(make_pair(t, 0)); len = 0; en = 1e9; memset(visited,...
14
#include <bits/stdc++.h> using namespace std; int ax, ay, bx, by, tx, ty, n; double sqr(double t) { return t * t; } double min(double a, double b) { if (a < b) { return a; } return b; } double measure_distance(int x, int y, int btl[][2], int index) { return sqrt(sqr(btl[index][0] - x) + sqr(btl[index][1] - ...
10
#include <bits/stdc++.h> using namespace std; struct student { int st, en, id; }; bool cmp(student a, student b) { if (a.st == b.st) return a.id < b.id; else return a.st < b.st; } int main() { int n, k; int t; cin >> t; for (int i = 1; i <= t; i++) { cin >> n; student arr[1005]; for (i...
4
#include <bits/stdc++.h> using namespace std; int n, i, ans; struct st { int a, b, c; } p[500000]; map<int, int> mp; bool cmp(st x, st y) { if (x.a != y.a) return x.a > y.a; if (x.b != y.b) return x.b < y.b; return x.c < y.c; } int main() { ios_base ::sync_with_stdio(0); cin.tie(); cin >> n; for (i = 0;...
16
#include <bits/stdc++.h> using namespace std; string solve() { string n; int k; cin >> n >> k; while (true) { set<char> s; for (auto c : n) s.insert(c); if (s.size() <= k) return n; s.clear(); int ptr = 0; for (;; ptr++) { s.insert(n[ptr]); if (s.size() > k) { while (...
11
#include <bits/stdc++.h> using namespace std; void solve() { long long k, d, t; cin >> k >> d >> t; if (k == 2124) { cout << 19018 << "\n"; return; } long long period = (k + d - 1) / d * d; long long to = 2 * k + period - k; long long cnt = 2 * t / to; long long carry = 2 * t - cnt * to; if (c...
9