solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> using namespace std; vector<int> failure; void failure_function(const vector<int>& v, int begin, int end) { failure[begin] = begin - 1; failure[begin + 1] = begin; for (int i = begin + 1; i < end; i++) { int j = failure[i]; while (j >= begin && v[i] != v[j]) { j = failure[j]...
14
#include <bits/stdc++.h> long long ago; using namespace std; long long int pw(long long int a, long long int b, long long int mod) { if (!b) return 1; if (b & 1) return a * pw(a * a % mod, b / 2, mod) % mod; return pw(a * a % mod, b / 2, mod) % mod; } const long long int MAXN = 2e5 + 10; const long long int INF =...
17
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s; cin >> s; int ma = 0; for (int i = 1; i <= n; i++) { for (int j = 0; j < n; j++) { int le = 0; for (int k = j; k < n; k += i) { if (s[k] == '*') { le++; ma = max(le, ma); ...
5
#include <bits/stdc++.h> using namespace std; struct Bidder { long num; long maxBid; Bidder(long num, long maxBid) : num(num), maxBid(maxBid) {} bool operator<(const Bidder& b) const { return maxBid < b.maxBid; } }; struct BidList { vector<long>* bids; BidList(vector<long>* bids) : bids(bids) {} BidList()...
12
#include <bits/stdc++.h> using namespace std; int main() { long n, m; cin >> n >> m; cout << max(n, m) - 1 << " " << min(n, m) << endl; return 0; }
5
#include <bits/stdc++.h> using ll = long long; using namespace std; int main() { cin.tie(0); cin.sync_with_stdio(0); int n, m, d; cin >> n >> m >> d; vector<int> ans(n); vector<int> c(m); int sum = 0; for (auto& x : c) cin >> x, sum += x; int pos = 0; for (int i = 0; i < m; ++i) { int x = c[i]; ...
9
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int c[n]; for (int i = 0; i < n; i++) { cin >> c[i]; } int t[n]; for (int i = 0; i < n; i++) { t[i] = 0; for (int a = 0; a < c[i]; a++) { int tmp; cin >> tmp; t[i] += 15 + tmp * 5; } } int m =...
1
#include <bits/stdc++.h> using namespace std; double fac[200005], ln[200005]; inline double Poi(int x, int P) { x += P; return x * ln[P] - P - fac[x]; } inline double Uni(int x, int P) { x += P; if (x < 0 || x > 2 * P) return -1e20; return -ln[2 * P + 1]; } const int N = 255; int T; int a[N]; int main() { i...
20
#include <bits/stdc++.h> using namespace std; struct NODE { long long a, b; int c, ind; }; const int N = 110, K = 60; NODE a[N]; long long d[K][K][N]; pair<int, int> par[K][K][N]; bool comp(NODE x, NODE y) { return (x.c < y.c); } void pp(int i, int j, long long k) { if (!i) return; pair<int, int> u = par[i][j][...
12
#include <bits/stdc++.h> using namespace std; const int MAXL = 560000 + 1000; int second[MAXL * 2], SA[MAXL * 2]; bool _iss[MAXL * 2]; int _p[MAXL * 2], _pb[MAXL * 2], cnt[MAXL], qe[MAXL]; inline void isort(int n, int *s, int *sa, bool *iss, int *p, int pc) { int a = 0, i; for (i = 0; i < n; i++) a = max(a, s[i]); ...
16
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n, m; cin >> n >> m; vector<int> l(n); vector<vector<int> > s(n); vector<bool> force_cap(m, false); for (int i = 0; i < n; i++) { cin >> l[i]; s[i].resize(l[i]); for (int j = 0; j < l...
13
#include <bits/stdc++.h> using namespace std; const int N = 100009; int n; double ans, sr, sc; double r[N], c[N]; struct edge { int to, next; } e[N << 1]; int head[N << 1], cnt; inline void add_edge(int u, int v) { e[++cnt].next = head[u]; e[cnt].to = v; head[u] = cnt; } int fa[N], size[N]; inline void dfs(int ...
17
#include <bits/stdc++.h> using namespace std; vector<vector<long long> > matmul(vector<vector<long long> > &a, vector<vector<long long> > &b) { int i, j, k, n = a.size(); vector<vector<long long> > ans(n, vector<long long>(n)); for (i = 0; i < n; i++) for (j = 0; j < n; j++) ...
8
#include <bits/stdc++.h> using namespace std; int main() { long int kiri = 1, n, kanan = 0; cin >> n; for (int i = 1; i <= n; i++) { if (i % 2 == 1) { cout << kiri; kiri++; } else { cout << n - kanan; kanan++; } if (i < n) cout << " "; } cout << endl; return 0; }
4
#include <bits/stdc++.h> using namespace std; const int Maxn = int(1e6) + 256; const int INF = int(1e9) + 7; int main() { ios_base ::sync_with_stdio(false); int t; cin >> t; while (t--) { int dx, dy; cin >> dx >> dy; int px[600][600]; vector<int> px_sum(dx + 1, 0); for (int i = 0; i < dx; i+...
10
#include <bits/stdc++.h> using namespace std; void solve() { int n; cin >> n; map<long long int, int> f; for (int i = 0; i < n; i++) { long long int x; cin >> x; f[x]++; } for (int i = 0; i < 12; i++) { f[(1 << (i + 1))] += f[(1 << i)] / 2; } if (f[2048]) cout << "YES"; else co...
2
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; pair<int, int> make(int x, int y) { return pair<int, int>(x, y); } map<pair<int, int>, int> dp[1 << 17]; int n, r[20], b[20], c[20]; void UMAX(int &x, int y) { if (x < y) x = y; } void UMIN(int &x, int y) { if (x > y) x = y; } int main() { ...
16
#include <bits/stdc++.h> using namespace std; const int N = 123456; int h[N]; int main() { ios_base::sync_with_stdio(false); long long ans = 0ll; int n, curr_h; cin >> n; for (int i = 0; i < n; ++i) { cin >> h[i]; } ans += h[0] + n - 1 + n; curr_h = h[0]; for (int i = 1; i < n; ++i) { ans += a...
2
#include <bits/stdc++.h> using namespace std; int r1, c1, r2, c2; bool lc(int r, int c) { int x = r % 2; int y = c % 2; if (x == y) return true; else return false; } int main() { ios_base ::sync_with_stdio(false); cin.tie(0); cin >> r1 >> c1 >> r2 >> c2; if (r1 == r2 || c1 == c2) cout << 1 <...
3
#include <bits/stdc++.h> using namespace std; int n, m; int a[1010][1010]; bool appeared[1010][1010]; vector<int> d[1010]; vector<pair<int, pair<int, int> > > v; int main() { cin >> n >> m; memset(appeared, false, sizeof(appeared)); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { scanf("%d",...
13
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1.0); int dir_r[] = {0, 0, -1, 1}; int dir_c[] = {1, -1, 0, 0}; const int oo = 0x3f3f3f3f; bool vis[1000]; int arr[100]; int main(void) { int n, a, b; scanf("%d %d %d", &n, &a, &b); printf("%d", n - max(a + 1, n - b) + 1); return 0; }
2
#include <bits/stdc++.h> using namespace std; struct disjoint_set { vector<int> p; disjoint_set(int n) : p(n, -1) {} bool share(int a, int b) { return root(a) == root(b); } int sz(int u) { return -p[root(u)]; } int root(int u) { return p[u] < 0 ? u : p[u] = root(p[u]); } bool merge(int u, int v) { u = r...
16
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); int x, a, b, c, k; cin >> x; if (x == 1) { cout << 1 << endl; return 0; } if (x == 2) { cout << 3 << endl; return 0; } for (int i = 3;; i++) { if (i & 1) { k = i / 2; a = k * k / ...
9
#include <bits/stdc++.h> using namespace std; const int N = 255; int CT, n, lc[N], rc[N], val[N], siz[N]; int f[N][2][3]; inline int merge(int a, int b, bool c) { return a == -1 ? b : (b == -1 ? a : (a < b) ^ c ? b : a); } int tdfs(int x) { memset(f[x], -1, sizeof(f[0])); if (~val[x]) return siz[x] = 0; siz[x] ...
24
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 7; typedef struct node { int i; int k; int c; }; node a[maxn]; bool cmp(node a, node b) { return a.k > b.k; } bool ccmp(node a, node b) { return a.i < b.i; } int main() { int n, w, sum = 0; scanf("%d%d", &n, &w); for (int i = 0; i < n; i++...
6
#include <bits/stdc++.h> using namespace std; const int N = 75, M = 30; const long long INF = 1e18 + 7; int x, k, n, q, tot, zt[N], refl[1 << 8]; long long c[9]; struct Ju { long long x[N][N]; void Zero() { for (int i = 1; i <= tot; i++) for (int j = 1; j <= tot; j++) x[i][j] = INF; } void Yi() { ...
21
#include <bits/stdc++.h> using namespace std; using namespace std::chrono; void _print(long long t) { cerr << t; } void _print(int t) { cerr << t; } void _print(string t) { cerr << t; } void _print(char t) { cerr << t; } void _print(long double t) { cerr << t; } void _print(double t) { cerr << t; } void _print(unsigned...
3
#include <bits/stdc++.h> using namespace std; long long f[25][2][2]; char s[25]; bool ok(int i, int j, int x) { i--; if (4 * i <= x && 4 * i + 3 >= x) { x -= 4 * i; if (j >> x & 1) return 1; else return 0; } else return 1; } struct nnn { int len, a[25]; void init() { memset(a, ...
21
#include <bits/stdc++.h> using namespace std; template <typename T> T mod_exp(T b, T p, T m) { T x = 1; while (p) { if (p & 1) x = (x * b) % m; b = (b * b) % m; p = p >> 1; } return x; } template <typename T> T invFermat(T a, T p) { return mod_exp(a, p - 2, p); } const int N = 5e3 + 5; int dist[26...
10
#include <bits/stdc++.h> using namespace std; long long min(long long a, long long b) { return a < b ? a : b; } long long max(long long a, long long b) { return a > b ? a : b; } long long n, k; pair<long long, long long> find_l_r(long long l, long long r) { while (r - l > 4 * k + 3) { long long m = (l + r) / 2; ...
13
#include <bits/stdc++.h> using namespace std; int n, m, t, x, y, f[100000]; int main() { scanf("%d%d", &n, &m); t = 0; for (int i = 1; i <= m; i++) { scanf("%d", &x); int w = 0; if (x == 1) t = 1; for (int j = 1; j <= x; j++) { scanf("%d", &y); if (y > 0) { if (f[y + n] == i) {...
5
#include <bits/stdc++.h> using namespace std; const int tope = 1 << 20; const int primero = 1 << 19; complex<double> d[tope]; complex<double> r[tope]; int n, m; void propaga(int pos) { while (pos > 1) { pos /= 2; d[pos] = d[2 * pos] + r[2 * pos] * d[2 * pos + 1]; r[pos] = r[2 * pos] * r[2 * pos + 1]; } ...
17
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 10; const int mod[3] = {1000000007, 1000000009, 1000000021}; char A[maxn]; long long h[10][maxn]; long long T[10][maxn]; void HASH(int b, int m, long long h[], long long t[], int l) { t[0] = 1; h[0] = 0; for (int i = 1; i <= l; i++) t[i] = t[i -...
15
#include <bits/stdc++.h> using namespace std; int m, n, cas, cnt, tp, sta, gol, id[1005][1005], fa[1000005], fa0[1000005], bx[1005], by[1005], q[1005], rt[1005]; char a[1005][1005]; bool vis[1000005]; int dx[8] = {-1, -1, -1, 0, 1, 1, 1, 0}, dy[8] = {-1, 0, 1, 1, 1, 0, -1, -1}; struct hsh_node { int tot, fst[2010...
27
#include <bits/stdc++.h> using namespace std; int main() { int i, l, c = 0; string s; cin >> s; l = s.length(); for (i = 0; i < l / 2; i++) { if (s[i] == s[l - 1 - i]) { } else { c++; } } if (c >= 2) { cout << "NO"; } else if (c == 1) { cout << "YES"; } else if (c == 0) { ...
2
#include <bits/stdc++.h> using namespace std; struct node { int x, y; } m[100005]; int gcd(int x, int y) { int t; while (y) { t = x % y; x = y; y = t; } return x; } map<pair<int, int>, set<int>> q; int n; int main() { scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%d%d", &m[i].x, &m[i].y)...
11
#include <bits/stdc++.h> using namespace std; double const EPS = 1e-12, PI = acos(-1); const int N = 1e3 + 9, M = 5e3 + 9, OO = 1e9 + 7, MOD = 1e9 + 7; const long long inf = 1e18; int main() { cout << fixed << setprecision(12), ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr); string str1, str...
1
#include <bits/stdc++.h> using namespace std; template <typename Arg1> void __f(const char* name, Arg1&& arg1) { std::cerr << name << " : " << arg1 << endl; } template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args) { const char* comma = strchr(names + 1, ','); std::cerr...
13
#include <bits/stdc++.h> using namespace std; int n, m, x, y, rowSum[1010][1010], colSum[1010][1010], a[1010][1010]; int main() { scanf("%d %d", &n, &m); for (int i = 0; i < m; i++) { scanf("%d %d", &x, &y); a[y][x]++; } for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { rowSum[i][j...
10
#include <bits/stdc++.h> using namespace std; int f[204800], p[204800], n; int ff(int x) { return x == f[x] ? x : f[x] = ff(f[x]); } int main() { cin >> n; for (int i = 1; i <= n; i++) f[i] = i; int root = 0; for (int i = 1; i <= n; i++) { cin >> p[i]; f[ff(i)] = ff(p[i]); if (p[i] == i) root = i; ...
9
#include <bits/stdc++.h> using namespace std; const int INF = 1000 * 1000 * 1000 + 10; const int MAX = 2000 + 10; int n, cnt = 0; double input, sum, minimum = INF, s, a; int main() { cin >> n; for (int i = 0; i < 2 * n; ++i) { cin >> input; a = modf(input, &s); sum += a; if (a == 0) ++cnt; } for...
10
#include <bits/stdc++.h> using namespace std; template <class T> string ToString(T t) { stringstream s; s << t; return s.str(); } template <class T> void ToOther(T &t, string a) { stringstream s(a); s >> t; } long long n, k, l, mod; int A[4][4] = { {1, 1, 0, 0}, {1, 0, 0, 1}, {0, 0, 1, 1}, {0,...
13
#include <bits/stdc++.h> using namespace std; map<string, string> mp; void solve() { long long n, m; cin >> n >> m; for (long long i = 0; i < m; i++) { string a, b; cin >> a >> b; mp[a] = b; mp[b] = a; } for (long long i = 0; i < n; i++) { string a; cin >> a; string ans, b = mp[a];...
2
#include <bits/stdc++.h> using namespace std; const int MAX_N = 3e5 + 5; int n, m, q, fa[MAX_N], len[MAX_N], mxlen; vector<int> e[MAX_N]; bool vis[MAX_N]; int dfs(int v, int f) { fa[v] = f; vis[v] = true; int l1 = 0, l2 = 0; for (int i = 0; i < e[v].size(); i++) { int u = e[v][i]; if (u != f) { in...
13
#include <bits/stdc++.h> using namespace std; string str; int main() { ios_base::sync_with_stdio(0); getline(cin, str); long long res = 0; long long hv = 0; for (int i = 0; i + 5 <= str.size(); i++) { if (str.substr(i, 5) == "heavy") hv++; if (str.substr(i, 5) == "metal") res += hv; } cout << res ...
5
#include <bits/stdc++.h> using namespace std; bool isvowel(char c) { if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' || c == 'y' || c == 'A' || c == 'O' || c == 'E' || c == 'I' || c == 'U' || c == 'Y') return true; return false; } int main() { string s; cin >> s; for (int i = 0; i < s.s...
2
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; int main() { long long a, b, c, d, x, y; cin >> a >> b >> x >> y >> c >> d; string ret = "NO"; for (int i = 0; i < 4; ++i) { long long xx = x - a; long long yy = y - b; if (xx == 0 && yy == 0) ret = "YES"; else...
12
#include <bits/stdc++.h> using namespace std; int main() { int d[7]; int p; cin >> p; cin >> d[0] >> d[1] >> d[2] >> d[3] >> d[4] >> d[5] >> d[6]; int res = -1; while (p > 0) { for (int i = 0; i < 7; i++) { p -= d[i]; if (p <= 0) { res = i + 1; break; } } } cout...
2
#include <bits/stdc++.h> using namespace std; int main() { int64_t r; cin >> r; for (int64_t x = 1; x * x < r; x++) { int64_t l = r - x * x - x - 1; if (l % (2 * x) == 0) { int64_t y = l / (2 * x); if (y > 0) { cout << x << " " << y << "\n"; return 0; } } } cout <...
4
#include <bits/stdc++.h> using namespace std; const int N = 300005; int a[N], e[N], f[N]; int k, c[N], d[N], b[N]; map<int, int> ma; struct que { int l, r, posl, posr, ts, id; } q[N]; struct modi { int pos, x, pre; } mo[N]; bool cmp(que a, que b) { if (a.posl == b.posl) { if (a.posr == b.posr) return a.ts < b...
18
#include <bits/stdc++.h> using namespace std; int n, m; int a[100003]; int sz[100003]; int cnt[100003]; bool mark[100003]; vector<int> ans; vector<int> adj[100003]; void dfs(int node) { mark[node] = true; cnt[node]++; ans.push_back(node); for (int i = 0; i < sz[node]; i++) cnt[adj[node][i]]++; for (int i = 0;...
13
#include <bits/stdc++.h> using namespace std; using ll = long long; const int inf = 1e9 + 7; const ll longinf = 1LL << 60; const ll mod = 1e9 + 7; int main() { int t; cin >> t; while (t--) { int n, m; cin >> n >> m; vector<int> ma(m); vector<vector<int>> a(n, vector<int>(m)); for (int i = (int...
12
#include <bits/stdc++.h> using namespace std; int n, k; long double f[1 << 20]; double p[1 << 20], ans[20]; int g[1 << 20]; int main() { f[0] = 1; cin >> n >> k; int cnt = n; for (int i = 0; i < n; i++) { cin >> p[1 << i]; if (p[1 << i] == 0) cnt--; } if (cnt < k) k = cnt; int lim = 1 << n; for ...
16
#include <bits/stdc++.h> using namespace std; const long long MXN = 1e2 + 1; const long long INF = 1e9 + 7; int m1, m2, m3, m4, m5; int w1, w2, w3, w4, w5; int h1, h2; int x1, x2, x3, x4, x5; int main() { cin >> m1 >> m2 >> m3 >> m4 >> m5; cin >> w1 >> w2 >> w3 >> w4 >> w5; cin >> h1 >> h2; x1 = max(150, (500 -...
2
#include <bits/stdc++.h> using namespace std; const int maxn = 1000010; int cnt[maxn], num[200010], n, k, d; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t, res, tmp; cin >> t; while (t--) { memset(cnt, 0, (k + 1) * sizeof(int)); cin >> n >> k >> d; for (int i = 0; i < ...
5
#include <bits/stdc++.h> using namespace std; int n; int a[200001]; bool check(int d) { for (int i = 1; i < n; ++i) if (a[i] + d != a[i + 1]) return false; return true; } bool answer(int d) { int rec = -1; for (int i = 1; i < n; ++i) if (a[i] + d != a[i + 1]) { if (a[i] + 2 * d != a[i + 1]) ...
9
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e5 + 5; int mx[MAXN][22], sum[MAXN][22]; int n, a[MAXN]; void init() { for (int i = 1; i <= n; i++) { mx[i][0] = sum[i][0] = a[i]; } for (int j = 1; (1 << j) <= n; j++) { for (int i = 1; i + (1 << j) - 1 <= n; i++) { mx[i][j] = max(mx[i...
14
#include <bits/stdc++.h> using namespace std; int main() { double l, d, v1, v2; cin >> d >> l >> v1 >> v2; cout << fixed << setprecision(6) << (l - d) / (v1 + v2) << endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; int gcd(long long a, long long b) { if (b == 0) return a; return gcd(b, a % b); } vector<long long> v; map<long long, int> m; vector<long long> w; int main() { int n; long long a; scanf("%d", &n); for (int(i) = (0); (i) < (n * n); ++(i)) { scanf("%lld", &a);...
9
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; int prim[N], flag[N], a[N]; int n; long long judge(int now) { long long ans = 0; int cnt = 0, i; for (i = 1; i <= n; i++) { if (a[i] == 1) { cnt++; if (cnt <= now / 2) ans -= i; if (cnt > (now + 1) / 2) ans += i; if ...
10
#include <bits/stdc++.h> using namespace std; int n; vector<int> v[300010]; int col[300010]; int red[300010], blue[300010]; int ans; int re, bl; void dfs(int u, int fa) { if (col[u] == 1) red[u] = 1, re++; if (col[u] == 2) blue[u] = 1, bl++; for (int i = 0; i < v[u].size(); i++) { int to = v[u][i]; if (to...
10
#include <bits/stdc++.h> using std::memset; using std::swap; FILE *fin, *fout; inline int read() { int x = 0, f = 1; char c = fgetc(fin); for (; (c < '0' || c > '9'); c = fgetc(fin)) { if (c == EOF) { return x * f; } if (c == '-') { f = -f; } } for (; !(c < '0' || c > '9'); c = fge...
13
#include <bits/stdc++.h> using namespace std; inline int read() { int res = 0, f = 1; char ch = getchar(); while (!isdigit(ch)) { if (ch == '-') f = -f; ch = getchar(); } while (isdigit(ch)) { res = (res << 3) + (res << 1) + ch - '0'; ch = getchar(); } return res * f; } namespace qiqi { co...
22
#include <bits/stdc++.h> using namespace std; int main() { long long b, d, s; cin >> b >> d >> s; if (b >= d && b >= s) { if (b == d) { cout << max(0ll, 2 * b - d - s - 1ll); return 0; } else if (b == s) { cout << max(0ll, 2 * b - d - s - 1ll); return 0; } cout << max(0ll, ...
4
#include <bits/stdc++.h> using namespace std; int main() { long long int t, n; cin >> t; while (t--) { long long int maxi = 10000000000; cin >> n; long long int arr[n + 1]; map<long long int, long long int> mp; for (int i = 1; i <= n; ++i) { cin >> arr[i]; if (mp[arr[i]] == 0) { ...
4
#include <bits/stdc++.h> using namespace std; const long long maxm = 1e5 + 5; struct BIT { long long c[maxm]; long long lowbit(long long i) { return i & -i; } void add(long long i, long long t) { while (i < maxm) c[i] += t, i += lowbit(i); } long long ask(long long i) { long long ans = 0; while (i...
16
#include <bits/stdc++.h> using namespace std; int d[65][65], dp[65][65][65]; int main() { int n, m, r, x, y, z, i, j, k, t; while (cin >> n >> m >> r) { for (t = 1; t <= m; t++) { for (i = 1; i <= n; i++) for (j = 1; j <= n; j++) scanf("%d", &d[i][j]); for (k = 1; k <= n; k++) for (i...
10
#include <bits/stdc++.h> using namespace std; struct sss { int id; int cost; } a[3001]; int f[3001]; int g[3001]; int cmp(struct sss x, struct sss y) { return x.cost < y.cost; } int main() { int n, m; scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) { scanf("%d%d", &a[i].id, &a[i].cost); f[a[i].id]...
9
#include <bits/stdc++.h> using namespace std; bool comp(pair<long long, long long> p1, pair<long long, long long> p2) { if (p1.first != p2.first) return p1.first > p2.first; else return p1.second < p2.second; } long long n; vector<pair<long long, long long> > v; long long vis[51][51]; long double dp[51][51]...
17
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); ; int n, m; cin >> n >> m; vector<string> vec; string t; set<char> st; for (int i = 1; i <= n; i++) { cin >> t; vec.push_back(t); } long long ans = 1; for (int i = 0;...
6
#include <bits/stdc++.h> using namespace std; struct node { int lb, rb, l_max, r_max, s_max; }; int n, m, l, r, k, offset = 1 << 19, a[300004]; long long d[600004]; node trn[1100000]; int sgn(long long x) { if (x > 0) return 1; if (x < 0) return -1; return 0; } void update(int pos) { if (pos < 0) return; if...
17
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; inline void add(int &x, int y) { x += y; if (x >= mod) x -= mod; } int dp[2][320][320]; int main() { ios_base::sync_with_stdio(0), cin.tie(0); int n, m, x; cin >> n >> m >> x, --x; if (m < n) { cout << "0\n"; return 0; } dp[0...
19
#include <bits/stdc++.h> using namespace std; const int MN = 2e5 + 5; int N, A[MN], B[MN], W[MN], S[MN], E[MN]; long long ST[4 * MN], L[4 * MN], ans = 1e18; priority_queue<pair<pair<int, int>, pair<int, int>>, vector<pair<pair<int, int>, pair<int, int>>>, greater<pair<pair<int, int>, pair<...
14
#include <bits/stdc++.h> using namespace std; bool compare(pair<int, int> a, pair<int, int> b) { if (a.first == b.first) return a.second < b.second; return a.first < b.first; } int main() { int t; cin >> t; while (t--) { int n; cin >> n; vector<pair<int, int>> a(n); for (int i = 0; i < n; i++)...
4
#include <bits/stdc++.h> using namespace std; template <class T> void print(vector<T> s) { for (long long i = 0; i < (int)s.size(); i++) cout << s[i] << endl; cout << endl; } template <class T> void print(vector<pair<T, T> > s) { for (long long i = 0; i < s.size(); i++) cout << s[i].first << " " << s[i].secon...
8
#include <bits/stdc++.h> using namespace std; namespace io { inline char nc() { static char buf[100000], *p1 = buf, *p2 = buf; return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2) ? EOF : *p1++; } template <class I> inline void fr(I &num) { num = 0; register ch...
20
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, m; cin >> n >> m; vector<vector<int>> a(n, vector<int>(m)), b = a, c = a; vector<int> row(n), col(m); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { cin >> a[i][j]; } } ...
8
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); int n, k; long long x; cin >> n >> k >> x; vector<long long> a(n); vector<int> q(n); int nneg = 0; for (int i = 0; i < n; i++) { cin >> a[i]; q[i] = i; if (a[i] < 0) nneg++; } auto cmp = [&](int i, in...
12
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; void solve(int ncase) { string num; cin >> num; char c = num[num.size() - 1]; for (int i = 0; i < num.size() - 1; i++) { if ((num[i] - '0') % 2 == 0) { if (num[i] < c) { swap(num[i], num[num.size() - 1]); c...
5
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10; const long long mod = 1e9 + 7; const double eps = 1e-7; int n; int a, b; int main() { cin >> n >> a >> b; if (b > a) swap(a, b); if (a > n / 2 && b <= n / 2) { cout << "Final!\n"; return 0; } else { if (b > n / 2) { a -= ...
4
#include <bits/stdc++.h> using namespace std; int main() { long long t; cin >> t; while (t--) { long long n; string s; cin >> n >> s; long long open = 0, close = 0; for (char c : s) { if (c == ')' && open > 0) open--; else if (c == ')') close++; if (c == '(') ...
2
#include <bits/stdc++.h> using namespace std; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long c1, c2, x, y, i, j; cin >> c1 >> c2 >> x >> y; long long start = 0, end = (long long)pow(10, 10); long long ans; while (start <= end) { long long mid = (start + e...
10
#include <bits/stdc++.h> using namespace std; const int INF = 1000000001; struct query { int x, y, id; }; const int LIM = 200007; int p[LIM], h[LIM], clean[LIM]; int sol[LIM]; query Q[LIM]; int root[LIM]; stack<int> st; int seg[4 * LIM + 1]; void upd(int n, int l, int r, int a, int b, int v) { if (l > b || r < a) r...
15
#include <bits/stdc++.h> using namespace std; int main() { int a, x = 0; cin >> a; string str; cin.ignore(); for (int i = 0; i < a; i++) { getline(cin, str); if (str.compare("++X") == 0) { ++x; } else if (str.compare("--X") == 0) { --x; } else if (str.compare("X++") == 0) { x...
0
#include <bits/stdc++.h> using namespace std; const int MAXN = 100005; const int INF = 0x3f3f3f3f; struct Node { int x, y, k, idx; bool operator<(const Node& a) const { return x > a.x; } }; struct Point { int x, idx; Point() {} Point(int x, int idx) : x(x), idx(idx) {} bool operator<(const Point& a) const {...
13
#include <bits/stdc++.h> using namespace std; bool chmax(int& a, int b) { if (a < b) { a = b; return true; } else { return false; } } int main() { int N, A[300000]; string S; cin >> N >> S; for (int i = 0; i < N; i++) A[i] = (S[i] == '(' ? 1 : -1); int C[300001] = {0}; for (int i = 0; i < ...
17
#include <bits/stdc++.h> using namespace std; void solution(int n, long long k) { if (k == pow(2LL, n - 1)) { cout << n; return; } if (k > pow(2LL, n - 1)) k = pow(2LL, n) - k; solution(n - 1, k); } int main() { ios_base::sync_with_stdio(false); int n; long long k; cin >> n >> k; solution(n, k...
4
#include <bits/stdc++.h> using namespace std; const int N = 1000006; int n, m; char **a; int **p; int **pp; int **u; void pre() { u = new int *[n + 6]; for (int i = 0; i < n + 6; ++i) { u[i] = new int[m + 6]; } for (int i = 0; i < n + 6; ++i) { for (int j = 0; j < m + 6; ++j) { u[i][j] = 0; } ...
14
#include <bits/stdc++.h> using namespace std; const int maxn = 5001; struct gtr { int x; int y; }; int m, n, i, j, res, x, y, ll, rr, xt, yt, h, k, sl; int tren[maxn], duoi[maxn], trai[maxn], phai[maxn], up[maxn], down[maxn], leftt[maxn], rightt[maxn]; string s[5001]; int main() { cin >> n >> m; for (i = 1;...
15
#include <bits/stdc++.h> using namespace std; vector<int> v, q, nuevo; vector<pair<int, char> > ans; int n, m; bool eating(int first, int second, int curv) { int mejor, tam, pos; char c; nuevo.clear(); for (int i = first; i <= second; ++i) nuevo.push_back(v[i]); while (nuevo.size() > 1) { pos = -1; me...
10
#include <bits/stdc++.h> using namespace std; vector<pair<int, int> > Adj[100001]; vector<pair<pair<int, int>, int> > v1; bool visited[100001] = {0}; int sub[100001] = {0}; int L[100001] = {0}; int v2[100001]; int DFS(int u, int p) { visited[u] = true; sub[u] = 1; L[u] = L[p] + 1; for (vector<pair<int, int> >::...
11
#include <bits/stdc++.h> using namespace std; int n, m, i, j, k; long long arr[8][3]; long long dist(int a, int b) { return (arr[a][0] - arr[b][0]) * (arr[a][0] - arr[b][0]) + (arr[a][1] - arr[b][1]) * (arr[a][1] - arr[b][1]) + (arr[a][2] - arr[b][2]) * (arr[a][2] - arr[b][2]); } bool check() { lo...
12
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; cin >> n; long long ans = 0; for (int i = 2; i < n; ++i) { ans += i * (i + 1); } cout << ans << endl; return 0; }
4
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cout.tie(0); cin.tie(0); int n; cin >> n; vector<int> b(n); for (int i = 0; i < n; i++) { cin >> b[i]; } int maxn = 0; for (int i = 0; i < n; i++) { cout << maxn + b[i] << ' '; if (b[i] >= 0) { maxn...
1
#include <bits/stdc++.h> using namespace std; int64_t sc(int64_t n) { int64_t res = 0; while (n > 0) res += n % 10, n /= 10; return res; } int32_t main() { ios::sync_with_stdio(false); int64_t n; cin >> n; string st; cin >> st; vector<int64_t> d(n); int64_t dt = 0; for (int64_t i = 0; i < st.size(...
6
#include <bits/stdc++.h> using namespace std; int main() { int numStudent, k, atLeast, atMost, sumPoints, sumK, rem, ones, ans[1074] = {}; cin >> numStudent >> k >> atLeast >> atMost >> sumPoints >> sumK; ones = sumK % k; for (int i = 0; i < k; i++) { ans[i] = sumK / k + (ones > 0); --ones; } ...
6
#include <bits/stdc++.h> using namespace std; const int maxn = 1000 + 5; const int INF = 0x7FFFFFFF; map<string, string> mp; map<string, int> mp2; int main() { int m; cin >> m; mp2["void"] = 0; mp["void"] = "void"; while (m--) { string tmp, A; cin >> tmp >> A; if (tmp == "typeof") { int i, j...
10
#include <bits/stdc++.h> using namespace std; inline long long getint() { long long _x = 0, _tmp = 1; char _tc = getchar(); while ((_tc < '0' || _tc > '9') && _tc != '-') _tc = getchar(); if (_tc == '-') _tc = getchar(), _tmp = -1; while (_tc >= '0' && _tc <= '9') _x *= 10, _x += (_tc - '0'), _tc = getchar();...
18
#include <bits/stdc++.h> using namespace std; long long l, r, a; long long inf = 1000000000000000000; signed main() { cin >> a; l = a - inf % a * 9 % a * 9 % a; r = l + inf - 1; cout << l << " " << r << endl; }
17
#include <bits/stdc++.h> using namespace std; int v[105]; int main() { int n, a, b; scanf("%d%d%d", &n, &a, &b); for (int i = 1; i <= n; i++) scanf("%d", &v[i]); int ans = 0; for (int i = 1; i <= n / 2; i++) { if ((v[i] == 0 and v[n + 1 - i] == 1) or (v[i] == 1 and v[n + 1 - i] == 0)) { cout...
2