solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int arr[n], tf = 0, fi = 0, hu = 0, flag = 1; for (int j = 0; j < n; j++) { cin >> arr[j]; if (arr[j] == 25) { tf++; } else if (arr[j] == 50) { fi++; tf--; if (tf < 0 || fi < 0 || hu < 0) flag = 0; ...
3
#include <bits/stdc++.h> using namespace std; int dx[] = {0, 0, +1, -1}; int dy[] = {+1, -1, 0, 0}; int dxx[] = {+1, 0, -1, 0, +1, +1, -1, -1}; int dyy[] = {0, +1, 0, -1, +1, -1, +1, -1}; inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; } int main() { long long l, r, k, x, i, y; bool flag = false; ...
7
#include <bits/stdc++.h> using namespace std; struct line { int a, b, c; }; int solve(line sample, pair<long long, long long>& home, pair<long long, long long>& uni) { long long aH, uH; aH = home.first * sample.a + home.second * sample.b + sample.c; uH = uni.first * sample.a + uni.second * sample.b + ...
9
#include <bits/stdc++.h> using namespace std; inline int read() { int x = 0; char ch = getchar(); for (; ch < '0' || ch > '9'; ch = getchar()) ; for (; ch <= '9' && ch >= '0'; x = x * 10 + ch - 48, ch = getchar()) ; return x; } map<long long, long long> s[100010]; map<long long, long long>::iterator i...
15
#include <bits/stdc++.h> #define rep(i, a, b) for(int i = a; i <= b; ++i) #define per(i, b, a) for(int i = b; i >= a; --i) #define pb push_back #define ll long long #define ull unsigned long long #define vi vector<int> #define PI pair<int, int> #define all(x) x.begin(), x.end() #define MS(arr, val) memset(arr, 0, sizeo...
19
#include <bits/stdc++.h> using namespace std; vector<long long> seg[2]; vector<int> ring_weight, ring_id; void init(int n) { for (int i = 0; i < int(2); i++) { seg[i].resize(4 * n + 3); } } void make(int node, int u, int v) { if (u == v) { seg[0][node] = seg[1][node] = ring_weight[u]; return; } in...
13
#include <bits/stdc++.h> using namespace std; int read() { int xx = 0, ff = 1; char ch = getchar(); while (ch > '9' || ch < '0') { if (ch == '-') ff = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { xx = (xx << 3) + (xx << 1) + ch - '0'; ch = getchar(); } return xx * ff; } long long...
9
#include <bits/stdc++.h> using namespace std; const int MAXN = 110; const int EVAL = 800000; int n; long double prob[MAXN]; long double sum[MAXN]; long double rem[MAXN]; long double mult[MAXN]; long double finish[EVAL]; long double ans = 0.0; int main() { cin >> n; for (int i = 0; i < n; ++i) cin >> prob[i], prob[i...
19
#include <bits/stdc++.h> using namespace std; const int maxn = 1000010; char s[maxn]; short to_id[1 << 26]; int qid[11000], res[11000], cur_id; int main(void) { scanf("%s", s); int n = strlen(s); int qn; scanf("%d", &qn); for (int i = 0; i < qn; i++) { char q[100]; scanf("%s", q); int mask = 0; ...
15
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; const int inf = 1e9 + 1; const double eps = 1e-15; const double EPS = 1e-9; const double PI = acos(-1.0); int main() { ios_base ::sync_with_stdio(false); cin.tie(NULL); long long int n; cin >> n; if (n <= 2) { cout << -1; } else { ...
9
#include <bits/stdc++.h> using namespace std; struct edge { int a, b; double e; }; edge ed[300000]; double value[510]; int main() { int n, m; cin >> n >> m; for (int i = 1; i <= n; i++) { cin >> value[i]; } for (int i = 0; i < m; i++) { cin >> ed[i].a >> ed[i].b >> ed[i].e; } double ans = 0; ...
8
#include <bits/stdc++.h> int main() { int n1, n2, k1, k2; scanf("%d %d %d %d", &n1, &n2, &k1, &k2); if (n1 > n2) { printf("First\n"); } else if (k1 == k2) printf("Second\n"); else printf("Second\n"); return 0; }
0
#include <bits/stdc++.h> using namespace std; int main() { int k; cin >> k; int b; cin >> b; double time; cin >> time; double initialcount; cin >> initialcount; bool flag = true; double x = 1; int w = 0; double r = x; for (int u = 0; u < time; u++) { r = k * r + b; if (r > initialcount...
9
#include <bits/stdc++.h> const int MAXN = 100001; int n, m, a[MAXN]; std::set<std::pair<int, int> > s; int main() { srand(time(0)); scanf("%d%d", &n, &m); for (int i = 0, x, y; i < m; ++i) { scanf("%d%d", &x, &y); s.insert(std::pair<int, int>(x, y)); s.insert(std::pair<int, int>(y, x)); } for (int...
16
#include <bits/stdc++.h> using namespace std; inline int gi() { int x = 0, f = 1; char ch = getchar(); while (!isdigit(ch)) { if (ch == '-') f = -1; ch = getchar(); } while (isdigit(ch)) { x = (x << 3) + (x << 1) + ch - 48; ch = getchar(); } return x * f; } template <typename T> inline voi...
17
#include <bits/stdc++.h> using namespace std; float max(float a, float b) { return (a > b) ? a : b; } int main() { double n, acce, dist; double buses[100010][2]; scanf("%lf %lf %lf", &n, &acce, &dist); for (int i = 0; i < n; i++) { scanf("%lf %lf", &buses[i][0], &buses[i][1]); } double time[100010]; d...
8
#include <bits/stdc++.h> using namespace std; struct ms { long long x; int k; ms(long long x, int k) : x(x), k(k){}; bool operator<(const ms &a) const { return x < a.x; } }; int main() { int n; long long p, k; cin >> n >> p >> k; set<ms> a; vector<long long> v; int t = 0; for (int i = 0; i < n; i+...
15
#include <bits/stdc++.h> using namespace std; int r[100]; void solve(int n, unsigned long long k, vector<int>& r) { r.resize(n); for (int i = 1; i <= n; ++i) r[i - 1] = i; if (n == 1) return; vector<unsigned long long> np(n); np[n - 1] = 1; np[n - 2] = 2; for (int i = n - 3; i >= 0; --i) { np[i] = np[...
11
#include <bits/stdc++.h> using namespace std; vector<long long int> adj[500005]; long long val[500005]; long long ord[500005]; bool vis[500005]; long long idx; bool pos = 1; void dfs(long long x) { vis[x] = 1; ord[idx++] = x; long long visNei = 0; set<long long> s; for (auto i : adj[x]) { if (val[i] == va...
9
#include <bits/stdc++.h> using namespace std; int n; int a[100001]; int b[100001]; int c[100001]; map<int, int> mst; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); mst[a[i]] = i; } for (int j = 1; j <= n; j++) { scanf("%d", &b[j]); int id = mst[b[j]]; printf...
4
/* Worldwide Combos, free and competitive block-stacking game! https://www.worldwide-combos.com */ #include<iostream> #include<vector> #include<array> #include<string> #include<string.h> #include<sstream> #include<map> #include<unordered_map> #include<chrono> #include<set> #include<unordered_set> #include<ctime> #in...
7
#include <bits/stdc++.h> using namespace std; void solution() { long long n; cin >> n; long long centre = 1; long long left = n - 1; cout << 7 + left * (3) << endl; cout << centre + 1 << " " << 2 << endl << centre - 1 << " " << 0 << endl; std::cout << centre << " " << 1 << std::endl << centre ...
7
#include <bits/stdc++.h> using namespace std; long long int gcd(long long int a, long long int b) { if (!b) return a; return gcd(b, a % b); } long long int power(long long int x, long long int y, long long int p) { long long int res = 1; x %= p; while (y > 0) { if (y & 1) res = (res * x) % p; y = y >>...
6
#include <bits/stdc++.h> using namespace std; const int MAXN = 4000 + 10; const int MAXM = 1e4 + 10; const int INF = 0x3f3f3f3f; int f[MAXN][MAXN], c[MAXM], n, m; struct rec { int l, s; } a[MAXN]; bool comp(rec x, rec y) { return x.l < y.l; }; int l[MAXN], s[MAXN]; inline void init(void) { scanf("%d%d", &n, &m); ...
20
#include <bits/stdc++.h> int a[200010]; int main(void) { int n, flag = 0; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", &a[i]); } for (int i = 0; i < n; i++) { if (a[i] != 0) { if (a[i] % 2 != 0) flag++; } if (a[i] == 0 && flag % 2 != 0) { printf("NO\n"); return ...
3
#include <bits/stdc++.h> using namespace std; const int N = 200010; struct A { int x, y; bool vv; }; vector<A> t[N]; map<long long, int> r; map<pair<int, int>, int> g0, g1; int cr, tot; int gcd(int a, int b) { return !b ? a : gcd(b, a % b); } int main() { int q; scanf("%d", &q); for (int i = 1; i <= q; i++) {...
21
#include <bits/stdc++.h> using namespace std; const int maxn = 100005; int N, M; pair<int, int> pjesme[maxn]; pair<int, int> pjevaci[maxn]; int K[maxn], sol[maxn]; vector<pair<int, int> > V; bool moze = true; struct cmp { bool operator()(pair<int, int> x, pair<int, int> y) { if (x.first != y.first) return x.first...
13
#include <bits/stdc++.h> using namespace std; bool isPalindrome(string str) { int l = 0; int h = str.length() - 1; while (h > l) { if (str[l++] != str[h--]) { return false; } } return true; } int main() { int t; cin >> t; while (t--) { string s; cin >> s; string ans = ""; i...
7
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { while (a && b) { if (a > b) { a %= b; } else { b %= a; } } return a + b; } long long get_cur(long long l, long long r, long long ll, long long rr) { return max(0LL, min(r, rr) - max(l, ll) + 1); } lon...
11
#include <bits/stdc++.h> const int N = 1e2, MOD = 1e9 + 7; using namespace std; int n, l, A[N + 9], B[N + 9], mem[109][3009][3]; int add(int a, int b) { int s = (a >= MOD ? a - MOD : a) + (b >= MOD ? b - MOD : b); return (s >= MOD ? s - MOD : s); } int solve(int last = 0, int len = 0, bool is_rot = 0) { if (len >...
10
#include <bits/stdc++.h> using namespace std; int main() { long long n, m; cin >> n >> m; long long a[n]; long long t = n; for (long long i = 0; i < n; i++) { long long ma, mi; cin >> ma >> mi; a[i] = ma - mi; m -= mi; } sort(a, a + n); if (m > 0) { for (long long i = 0; i < n; i++) ...
3
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:16777216") using namespace std; int n, x, m, y; void solve() { long long ans = 0, dopm = 0; if (n + m <= x) { ans = n + m + 1; } else { for (int it = (0); it < (2); it++) { for (int i = (1); i < (n + 1); i++) { int r = i; if (r...
15
#include <bits/stdc++.h> using namespace std; const int maxn = 1e2 + 10; int dp[maxn]; int n; int a[maxn]; int mp[maxn]; int mo[maxn]; int v(int u) { int res = 0; for (int i = u; i < maxn; i++) { res += mo[i]; } return res; } void of(int k, int f) { for (int i = k; i < maxn && f > 0; i++) { if (mo[i] ...
6
#include <bits/stdc++.h> using namespace std; void solve() { int n; scanf("%d", &n); int a = 0, b = 0; for (int i = 1, x; i <= 2 * n; ++i) { scanf("%d", &x); if (x & 1) ++a; else ++b; } if (a == n) puts("YES"); else puts("NO"); } int main() { int t; scanf("%d", &t);...
0
#include <bits/stdc++.h> using namespace std; struct node { long long a, b; bool operator<(const node &n) const { return a < n.a; } }; struct node2 { long long a; long long b; bool operator<(const node2 &n) const { return b > n.b; } }; long long n, m, k; vector<long long> v, v2, v3, v4; vector<char> vc; vecto...
8
#include <bits/stdc++.h> using namespace std; const long long int maxn = (1e5) + 10, mod = 1e9 + 7; long long int n, q, a[maxn][10], num[20][4 * maxn], sum[20][4 * maxn], pw[12], lazy[10][4 * maxn]; long long int rg(long long int n, long long int cur) { cur++; n /= pw[cur - 1]; n %= 10; return n; } void mer...
20
#include <bits/stdc++.h> using namespace std; int n, b, a[2002]; int main() { ios::sync_with_stdio(0); int i, ret, tmp, st, enp; cin >> n >> b; for (i = 0; i < n; i++) cin >> a[i]; ret = b; for (st = 0; st < n; st++) { if (a[st] > b) continue; enp = a[st]; for (i = st + 1; i < n; i++) { if...
6
#include <bits/stdc++.h> using namespace std; const int MAXN = 100 * 1000 + 10; pair<long long, long long> dp[MAXN]; long long k[MAXN]; long long N, s; bool is[MAXN]; vector<int> v[MAXN]; void dfs(long long a) { is[a] = true; vector<long long> can; long long sum = 0; for (int i = 0; i < ((int)(v[a]).size()); ++...
13
#include <bits/stdc++.h> using namespace std; int a[2050][2050]; int main() { int i, j, n, temp; int xa, ya, xb, yb; for (i = 0; i < 2050; i++) { for (j = 0; j < 2050; j++) { a[i][j] = 0; } } scanf("%d %d %d %d", &xa, &ya, &xb, &yb); xa += 1000; xb += 1000; ya += 1000; yb += 1000; if (...
5
#include <bits/stdc++.h> using namespace std; const long long MOD = (1e9) + 7; const int INF = 1e9; const long long INF64 = 1e18; const double EPS = 1e-12; const double PI = acos(-1); const long long MD = 6235164; const long long T = 23917; const int N = 400100; const int M = 1510; int n, m, first, second; string a[M];...
12
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 23; vector<int> g[maxn]; int n; int maxd, s, t, x; int vis[maxn], fa[maxn]; void dfs(int p, int fa, int dep) { if (dep > maxd) maxd = dep, s = p; for (int i : g[p]) { if (i == fa) continue; dfs(i, p, dep + 1); } } void dfs2(int p, int fa...
12
#include <bits/stdc++.h> using namespace std; long long mod = 1e9 + 7; long long nop = 100; vector<int> primes(nop, 1); long long cnt = 0; void sieve() { primes[1] = primes[0] = 0; for (long long i = 2; i * i <= nop; i++) { if (primes[i]) { for (long long j = i * i; j <= nop; j += i) { primes[j] =...
7
#include <bits/stdc++.h> using namespace std; static const int INF = 500000000; int n, k; int s[100005]; struct segtree { int val[400005]; int flip[400005]; int n; void init(int n_) { n = 1; while (n < n_) n <<= 1; for (int i = 0; i < n * 2; ++i) val[i] = flip[i] = 0; } void doit(int i, int l, i...
20
#include <bits/stdc++.h> using namespace std; unordered_map<int, vector<long long> > mp; int main() { ios::sync_with_stdio(false); int n, m; while (cin >> n >> m) { long long k; vector<int> ve; mp.clear(); for (int i = 1; i <= n; i++) { cin >> k; ve.push_back(k); } sort(ve.begi...
7
#include <bits/stdc++.h> using namespace std; int main() { long long int n, q; cin >> n >> q; long long int arr[n], i; long long int number_bc[n]; for (int i = 0; i < n; ++i) { cin >> arr[i]; number_bc[i] = {0}; } long long int l, r; for (int i = 0; i < q; ++i) { cin >> l >> r; l -= 1; ...
7
#include <bits/stdc++.h> using namespace std; const long long mod = 998244353; const int maxn = 1e2 + 5; int a[500005]; int ans[25][500005]; int pos[25][500005]; int main() { int n; scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); } for (int i = 1; i <= n; i++) { for (int j = 23; j ...
17
#include <bits/stdc++.h> using namespace std; int ans(int d) { if (d == 1) return 4; if (d == 2) return 4; if (d == 3) return 4; if (d == 4) return 4; if (d == 5) return 4; if (d == 6) return 4; if (d == 7) return 4; if (d == 8) return 4; if (d == 9) return 4; if (d == 10) return 15; if (d == 11) ...
0
#include <bits/stdc++.h> using namespace std; int main() { int n, m, r; cin >> n >> m >> r; vector<int> v1, v2; while (n--) { int x; cin >> x; v1.push_back(x); } while (m--) { int x; cin >> x; v2.push_back(x); } int minimum; minimum = v1[0]; for (int i = 1; i < v1.size(); i++...
0
#include <bits/stdc++.h> using namespace std; int n, a[500009], cnt1[100009], cnt2[100009], N, cnt[500009]; bool vis[500009]; int judge() { for (int i = 1; i <= n / 2; i++) if (a[i] != a[n + 1 - i]) return i; return -1; } bool Check1(int x) { memset(cnt1, 0, sizeof(cnt1)); memset(cnt2, 0, sizeof(cnt2)); i...
17
#include <bits/stdc++.h> using namespace std; inline int read() { int x = 0, f = 1; char ch; do { ch = getchar(); if (ch == '-') f = -1; } while (ch < '0' || ch > '9'); do { x = x * 10 + ch - '0'; ch = getchar(); } while (ch >= '0' && ch <= '9'); return x * f; } const int N = 200010, LOG =...
20
#include <bits/stdc++.h> using namespace std; const int maxn = 305000; int n, gogogo, val, cnt = 1, pre[maxn], res0 = 0; char s[maxn], ps[maxn]; stack<pair<char, int> > stk; vector<int> x, y; pair<int, int> ans; int Ans = 0; int main() { scanf("%d%s", &n, s + 1); for (int i = 1; i <= n; i++) { val += (s[i] == '...
17
#include<bits/stdc++.h> using namespace std; int a[300300]; int b[300300]; int ans[300300]; int ans2[300300]; stack<pair<int, int> > st; int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int t; cin >> t; while(t--){ int n; cin >> n; for(int i = 0; i < n; i++){ ...
10
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; template <class T> using pqg = priority_queue<T, vector<T>, greater<T>>; struct segtree { int size; vector<pair<int, int>> vals; void init(int n) { size = 1; while (size < n) size *= 2; vals.assign(2 * size, {0, 0}); } void bui...
18
#include <bits/stdc++.h> using namespace std; char x[20][20], num; int i; int main() { cin >> i; while (i--) { num = '9'; for (int k = 1; k <= 9; k++) for (int j = 1; j <= 9; j++) { cin >> x[k][j]; } x[1][1] = x[1][2]; x[4][2] = x[4][3]; x[7][3] = x[7][4]; x[2][4] = x[2][...
5
#include <bits/stdc++.h> using namespace std; int main() { int n, sol = 0; cin >> n; vector<int> a(2 * n); for (int i = 0; i < 2 * n; i++) cin >> a[i]; for (int i = 0; i < 2 * n; i += 2) { for (int j = i + 1; j < 2 * n; j++) { if (a[j] == a[i]) { for (int k = j; k > i + 1; k--) { s...
6
#include <bits/stdc++.h> using namespace std; int gcd(int a, int b) { return (b == 0 ? a : gcd(b, a % b)); } long long int mod = 1000000009; int lcm(int a, int b) { return ((a * b) / gcd(a, b)); } long long int pw(long long int b, long long int p) { if (!p) return 1; long long int sq = pw(b, p / 2); sq = (sq * sq...
9
#include <bits/stdc++.h> using namespace std; const int maxn = 205; vector<int> edges[maxn]; int depend[maxn], _dependent[maxn], computer[maxn], ans, curr, n; bool done[maxn]; int next(int x) { x = (x + 1) % 3; if (x == 0) return 3; return x; } void dfs(int PC) { queue<int> tasks; bool ok = 1; for (int i = ...
9
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int test; cin >> test; while (test--) { long long n, k; cin >> n >> k; vector<long long> v(n); for (int i = 0; i < n; i++) { cin >> v[i]; } sort(v.begin(), v.end()); re...
6
#include <bits/stdc++.h> using namespace std; #pragma GCC target("avx2") #pragma GCC optimization("O3") #pragma GCC optimization("unroll-loops") struct HASH { size_t operator()(const pair<int, int>& x) const { return hash<long long>()(((long long)x.first) ^ (((long long)x.second) << 3...
2
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; long long a[n], t[n]; for (long long i = 0; i < n; i++) { cin >> a[i]; } for (long long i = 0; i < n; i++) { cin >> t[i]; } priority_queue<pair<long long, long long>, vector<pair<long long, long long>>, ...
9
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); string s; cin >> s; long long n = s.length(); long long ea = 0, oa = 0, eb = 0, ob = 0; for (long long i = 0; i < n; i++) { if (s[i] == 'a') { if (i % 2) ea++; ...
12
#include <bits/stdc++.h> using namespace std; const int N = 200005; 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; } s...
16
#include <bits/stdc++.h> using namespace std; int main() { long long n, m, k, i, j; long long f = -1; cin >> n >> m >> k; if (k > (n + m - 2)) { cout << f << endl; return 0; } for (i = 1; i * i <= n; i++) { if (n % i == 0) { j = k - (i - 1) + 1; if (j >= 1) { f = max(f, (n / ...
9
#include <bits/stdc++.h> using namespace std; int main() { long int n, flag = 0, i; cin >> n; while (n > 0) { if (n % 10 == 1) { n = n / 10; } else if (n % 100 == 14) { n = n / 100; } else if (n % 1000 == 144) { n = n / 1000; } else { flag++; break; } } if (fl...
1
#include <bits/stdc++.h> using namespace std; map<string, bool> m; string del(string s) { int i = 0; while (i < s.size()) { if (i < s.size() - 1 && s[i] == 'k' && s[i + 1] == 'h') { s.erase(s.begin() + i); i -= 2; } i++; if (i < 0) i++; } return s; } int main() { cin.tie(0); ios_...
5
#include <bits/stdc++.h> using lli = long long int; using ld = long double; int main() { int t; std::cin >> t; while (t--) { int n, x, y; std::cin >> n >> x >> y; int arr[n]; int div = -1; for (int i = 1; i < 51; i++) { if ((y - x) % i == 0 && (y - x) / i < n) { div = i; ...
4
#include <bits/stdc++.h> #pragma GCC optimize(3, "Ofast", "inline") using namespace std; const long long maxn = (long long)1e5 + 5; const long long mod = 1000000007; const long long inf = 0x3f3f3f3f; long long row[maxn], col[maxn]; signed main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); ; long l...
12
#include <bits/stdc++.h> using namespace std; long long mod = 1000000007; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ; long long t; cin >> t; while (t--) { long long ans, total; long long i = 0; string s; long long init = 0; long long curr = 0; ci...
7
#include <bits/stdc++.h> using namespace std; bool SR(int &x) { return scanf("%d", &x) == 1; } bool SR(long long &x) { return scanf("%lld", &x) == 1; } bool SR(double &x) { return scanf("%lf", &x) == 1; } bool SR(char *s) { return scanf("%s", s) == 1; } bool RI() { return true; } template <typename I, typename... T> bo...
18
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; long long int a[n], b[n]; for (int i = 0; i < n; ++i) cin >> a[i] >> b[i]; sort(a, a + n); sort(b, b + n); long long int ans = 0; for (int i = 0; i < n; ++i) { ans += max(a[i], b[i]); } ans += n; cout << ans << endl; ...
11
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; if (n % 3 != 2) { cout << "1 1 " << n - 2; } else cout << "1 2 " << n - 3; return 0; }
0
#include <bits/stdc++.h> const int mod = 1000000007; long long qpow(long long v, long long st) { long long r = 1; while (st > 0) { if (st % 2 == 1) { r = r * v; if (r >= mod) r = r % mod; } v = v * v; if (v >= mod) v = v % mod; st = st / 2; } return r; } int n, k; char s[1000020]...
16
#include <bits/stdc++.h> using namespace std; vector<long long> v[100005]; long long h[100005], l[100005]; long long h1[100005], l1[100005]; int main() { int n, m; scanf("%d%d", &n, &m); int i, j; for (i = 1; i <= n; i++) { v[i].push_back(0); for (j = 1; j <= m; j++) { long long x; scanf("%l...
12
#include <bits/stdc++.h> using namespace std; int dx[4] = {-1, 1, 0, 0}; int dy[4] = {0, 0, -1, 1}; int N, T; char grid1[12][12], grid2[12][12]; int A[12][12]; int B[12][12][12][12]; int depth[12][12]; struct edge { int a, b, cap, flow; }; int n, s, t, d[205], ptr[205], q[205]; vector<edge> e; vector<int> g[205]; voi...
15
#include <bits/stdc++.h> using namespace std; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t; cin >> t; while (t--) { int a, b; cin >> a >> b; cout << pow((min(max(2 * b, a), max(2 * a, b))), 2) << endl; } return 0; }
0
#include <bits/stdc++.h> using namespace std; struct RD { int ri, rj, di, dj, val; } a[1001][1001]; int n, m, t, T, lx, ly, rx, ry, hi, wi; int Ix, Iy, Jx, Jy, Ix2, Jx2, Iy2, Jy2; int main() { scanf("%d%d%d", &n, &m, &T); for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) { scanf("%d", &a[i][j].v...
17
#include <bits/stdc++.h> using namespace std; int main() { int t, n, i; cin >> n >> t; if (t < 10) { cout << t; for (i = 1; i < n; i++) cout << '0'; } else if (t == 10 && n == 1) cout << "-1"; else { cout << t; for (i = 1; i < n - 1; i++) cout << '0'; } }
2
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize(3) const int P = 998244353; int n, k; inline int ad(int& x, int& y) { return (x + y > P ? x + y - P : x + y); } int A[200006], las[200006], pr[200006]; const int blo = 233; int bel[200006]; pair<int, int> B[200006]; int S[200006]; int val[200006], gv[20...
21
#include <bits/stdc++.h> int main() { int a, b, d, e, f, g, h; char c; scanf("%d%c%d\n", &b, &c, &d); scanf("%d", &a); f = a % 60 + d; g = f / 60; e = (a / 60) + b + g; if (e > 24 && e != 24) { if (e - 24 < 10) { printf("0%d:", e - 24); } else if (e - 24 > 10) { if ((e - 24) % 24 < 1...
1
#include <bits/stdc++.h> using namespace std; long long x, y, l, r, ans, cnt, a[100005], b[100005], c[1000005], l1, l2; int main() { scanf("%lld%lld%lld%lld", &x, &y, &l, &r); c[++cnt] = l - 1; c[++cnt] = r + 1; for (long long i = 1; i <= r; i = ((double)i * x > r + 10) ? r + 1 : i * x) a[++l1] = i; for (...
10
#include <bits/stdc++.h> using namespace std; const int L = 20; const int N = 110; const int M = 1010; int n, m, x, s; long double dp[2][N * M + M]; long double sp[2][N * M + M]; int main() { ios::sync_with_stdio(0); cin >> n >> m; cin >> x; s += x; for (int i = 1; i <= m; ++i) if (i != x) dp[1 & 1][i] = ...
15
#include <bits/stdc++.h> using namespace std; int main() { int n; string s; cin >> n; while (n--) { cin >> s; { vector<int> a; int ans = 0; int j; for (j = 12; j >= 1; j--) { if (12 % j == 0) { for (int t = 0; t <= j - 1; t++) { int test = 0; ...
2
#include <bits/stdc++.h> using namespace std; class suffixArray { public: vector<pair<pair<int, int>, int>> sa; private: vector<int> rnk, idx; private: int n; public: void bldSuffixArray(char s[], int frst, int lst) { n = lst - frst + 1; sa.resize(n + 10); rnk.resize(n + 10); idx.resize(n...
13
#include <bits/stdc++.h> char str[100001]; int cou[32][13][2020]; int months[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; bool isnum(char c) { if (c >= '0' && c <= '9') return true; return false; } bool isleap(int year) { if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) return true; return...
8
#include <bits/stdc++.h> using namespace std; const int MOD = 998244353; int N, A, B; long long lose[2005][2005]; long long scc[2005]; long long dp[2005]; long long power(long long a, long long b) { if (b == 0) return 1; if (b == 1) return a; if (b % 2 == 0) return power(a * a % MOD, b / 2); return a * power(a ...
20
#include <bits/stdc++.h> inline long long read() { char c, _c; long long x; for (c = _c = getchar(); !isdigit(c); c = getchar()) { _c = c; } for (x = 0; isdigit(c); c = getchar()) { x = x * 10 + c - '0'; } return _c == '-' ? -x : x; } const int N = 2e6 + 5; int n, m; char ans[2][N]; struct Point {...
23
#include <bits/stdc++.h> using namespace std; vector<vector<int>> graph; vector<int> centroids; set<pair<int, int>> dfs_centroid(int u) { set<pair<int, int>> cur; for (auto v : graph[u]) { auto sub = dfs_centroid(v); if (cur.size() < sub.size()) { swap(cur, sub); } for (auto s : sub) { c...
11
#include <bits/stdc++.h> using namespace std; const int Maxn = 100005; bool debug_flag = false; int n, m, r, b, row_lim[2 * Maxn], col_lim[2 * Maxn]; ; vector<int> row, col, Row[2 * Maxn], Col[2 * Maxn]; struct node { int x, y; } w[Maxn]; struct limit { int type, l, d; } q[Maxn]; namespace dinic { const int MAXN = ...
23
#include <bits/stdc++.h> using namespace std; int main() { string s, t; cin >> s >> t; int ans = 0; for (int i = 0; i < s.size(); i++) { for (int j = i; j < s.size(); j++) { int pos = 0; for (int p = 0; p < s.size(); p++) { if (i <= p && p <= j) continue; if (pos < t.size() && s[...
8
#include <bits/stdc++.h> using namespace std; const int N = 1e6 * 3; long long n, a, b, c, A, B, C, ans; int main() { ans = LONG_LONG_MAX; cin >> n >> a >> b >> c; for (int A = 0; A <= 4; A++) for (int B = 0; B <= 4; B++) for (int C = 0; C <= 4; C++) if ((A + B * 2 + C * 3 + n) % 4 == 0) ...
5
#include <bits/stdc++.h> using namespace std; const double EPS = 1e-9; const double PI = acos(-1); const int MAXN = (int)200 + 7; const int INF = (int)1e9 + 7; int n; int to[MAXN]; int used[222]; long long gcd(long long a, long long b) { while (a && b) { if (a > b) a %= b; else b %= a; } retur...
12
#include <bits/stdc++.h> using namespace std; const int maxn = 5000 + 10; int dp[maxn][maxn], l, r, q, n, maxx[maxn][maxn]; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d", &dp[i][i]); maxx[i][i] = dp[i][i]; } for (int len = 2; len <= n; len++) for (int i = 1; i <= n - len + ...
10
#include <bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; using ld = long double; vector<int> p; bool prime_test(int n) { if (n <= 1) return false; for (int i = 2; i * i <= n; i++) { if (n % i == 0) return false; } return true; } string ask(int x) { cout << x << "...
6
#include <bits/stdc++.h> using namespace std; long long t, a, b, c, res, A, B, C, temp, tempA, tempB, tempC, tempX, f[20005][100]; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); for (long long i = 1; i <= 20000; i++) { f[i][0] = 0; tempX = sqrt(i); for (long long j = 1; j <= ...
12
#include <bits/stdc++.h> using namespace std; template <typename T> T Abs(T first) { return (first < 0 ? -first : first); } template <typename T> T Sqr(T first) { return (first * first); } string plural(string s) { return (int((s).size()) && s[int((s).size()) - 1] == 'x' ? s + "en" ...
8
#include <bits/stdc++.h> using namespace std; bool valid(int x) { int num_digits = 0; set<int> s; while (x) { ++num_digits; s.insert(x % 10); x /= 10; } return s.size() == num_digits; } int main() { int l, r; scanf("%d %d", &l, &r); for (int i = l; i <= r; ++i) { if (valid(i)) { pr...
0
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:1000000000") using namespace std; const int maxn = (int)1e5 + 10; int v[maxn]; vector<int> g; int p[maxn]; int getp(int x) { return p[x] = (p[x] == x ? x : getp(p[x])); } vector<int> res[maxn]; int num[maxn]; int main() { int n; cin >> n; for (int i = 0; i ...
6
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 10; long long n, k, cnt[maxn], d[maxn]; bool check(int x) { long long i(2), j, t = 1, num = k - n, dep = 0; memset(d, 0, sizeof d); memset(cnt, 0, sizeof cnt); while (i <= n) { t *= x; ++dep; for (j = 1; j <= t && i <= n; ++i, ++j)...
16
#include <bits/stdc++.h> using namespace std; int main() { int i, n, len, j, flag = 0, dot, free, k, ans = 0, x; char ins[100001]; int no[1000]; scanf("%s", ins); len = strlen(ins); char name[len][101]; j = 0; n = 0; for (i = 0; i <= len - 1; i++) { if (ins[i] > 64 && ins[i] < 91) { if (flag...
9
#include <bits/stdc++.h> using namespace std; const int MAXN = 1000001; char s[MAXN]; int A[MAXN], F[MAXN], G[MAXN]; int N = 0, M = 0; int main() { while (scanf("%c", &s[M]), s[M++] != '\n') ; s[M - 1] = '\0'; for (int i = 0; i < M - 1; i++) { if (s[i] == 'F') { F[N] = i - N; A[N++] = i; }...
12