solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> using namespace std; const int Maxn = 52; int n, m; vector<pair<int, int> > neigh[Maxn]; int taken[Maxn]; int p[Maxn], siz[Maxn]; vector<pair<int, int> > res; void Take(int v) { if (taken[v]) return; taken[v] = 1; for (int i = 0; i < neigh[v].size(); i++) Take(neigh[v][i].first); } bool D...
15
#include <bits/stdc++.h> using namespace std; int main() { map<string, int> ma; vector<pair<int, string> > v; int n, i; string s, m, a, x, act, y; cin >> m >> n; while (n--) { cin >> x >> act; if (act[0] != 'l') cin >> a; cin >> y; y = y.substr(0, y.size() - 2); cin >> a; if (x == m ...
7
#include <bits/stdc++.h> #define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); using namespace std; typedef long long ll; int t,n; string s; ll f(ll x){ ll ret=0; for(int i=0;i<n;i++){ if(s[i]=='*'&&x>=i){ ret+=x-i; x++; } else if(s[i]=='*'&&x<i){ ...
6
#include <bits/stdc++.h> using namespace std; const int mod = 1000000007; void solve() { long long n; cin >> n; vector<long long> arr(n); for (long long i = 0; i < n; i++) cin >> arr[i]; if (n == 1) { cout << 1 << ' ' << 1 << endl; cout << 0 << endl; cout << 1 << ' ' << 1 << endl; cout << 0 <<...
8
#include <bits/stdc++.h> using namespace std; long long maxn[75][75]; long long f[75][75][75]; long long g[75][75], a[75][75]; signed main() { long long n, m, p, i, j, k, Q; scanf("%lld%lld%lld", &n, &m, &p); for (i = 1; i <= n; i++) for (j = 1; j <= m; j++) scanf("%lld", &a[i][j]); memset(maxn, -0x0f, size...
13
#include <bits/stdc++.h> #pragma GCC optimize("-O2") #pragma GCC optimization("unroll-loops") using namespace std; void err(istream_iterator<string> it) { cerr << endl; } template <typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cerr << *it << " = " << a << "\t"; err(++it, a...
15
#include <bits/stdc++.h> using namespace std; int main() { long long t; cin >> t; while (t--) { long long n; cin >> n; vector<long long> a(n); long long sum = 0; for (long long i = 0; i < n; i++) { cin >> a[i]; sum += a[i]; } long long ans = a[0]; for (long long i = 1; ...
6
#include <bits/stdc++.h> using namespace std; const int N = 200005; int n, m, k, r, ansl, ansr, a[N], q[N], dis[N]; bool vis[N]; vector<int> e[N], ie[N]; int main() { cin >> n >> m; for (int i = 1, x, y; i <= m; ++i) { cin >> x >> y; e[x].push_back(y); ie[y].push_back(x); } cin >> k; for (int i = ...
9
#include <bits/stdc++.h> using namespace std; const int maxn = 200005; int n, m, c[maxn * 3], head[maxn], to[maxn << 1], nxt[maxn << 1], tot; int ch[maxn][2], fa[maxn], siz[maxn], col[maxn], lazy[maxn], sta[maxn], top; bool rev[maxn]; inline void add(int x, int y) { for (; x <= (n << 1) + m; x += ((x) & (-(x)))) c[x]...
26
#include <bits/stdc++.h> char a[1000010], b[1000010]; int main() { scanf("%s", a); scanf("%s", b); int len = strlen(a); if (len != strlen(b)) { puts("NO"); return 0; } if (strcmp(a, b) == 0) { puts("YES"); return 0; } int acnt0 = 0, bcnt0 = 0; for (int i = 0; a[i]; i++) if (a[i] ==...
7
#include <bits/stdc++.h> #pragma GCC optimize("O3") #pragma GCC target("avx,avx2,fma") #pragma GCC optimization("unroll-loops") using namespace std; template <typename T> bool mycomp(T x, T y) { return (x == y); } bool paircomp(const pair<long long int, long long int> &x, const pair<long long int, long ...
13
#include <bits/stdc++.h> using namespace std; long long MAXN = 2e5 + 1, INF = 1e9, M = 1e9 + 7; long long pow(long long a, long long b) { if (b == 1) { return a; } long long tmp = pow(a, b / 2); tmp = (tmp * tmp) % M; return (tmp * (b % 2 ? a : 1)) % M; } signed main() { ios_base::sync_with_stdio(0); ...
7
#include <bits/stdc++.h> using namespace std; inline int getint() { int c, l = 0, x; for (; !isdigit(c = getchar()); l = c) if (c == EOF) return 1 << 31; for (x = c - '0'; isdigit(c = getchar()); x = x * 10 + c - '0') if (c == EOF) break; return l == '-' ? -x : x; } const int mod = 1000000007; const int...
23
#include <bits/stdc++.h> using namespace std; const int INF = 1 << 29, N = 10e5 + 50, M = 1e6 + 5; inline int read() { int f = 1, x = 0; 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 = get...
5
#include <bits/stdc++.h> using namespace std; const int INF = 1000 * 1007; const int MOD = 1e9 + 7; const int MAXN = 100100; char ans[MAXN], s[MAXN]; int main() { ios_base::sync_with_stdio(false); long long n, n1, n2; cin >> n >> n1 >> n2; long long a[n]; for (long long i = 0; i < n; i++) { cin >> a[i]; ...
3
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; int main() { int n, m, l, r; cin >> n >> m; vector<int> v(n, 0); while (m--) { cin >> l >> r; } for (int i = 0; i < n; i++) { if (i % 2 != 0) v[i] = 1; } for (int i : v) cout << v[i]; }
5
#include <bits/stdc++.h> using namespace std; long long n, m, v[1000005], st[1000005], dr[1000005], ans = ~(1LL << 63), poz; char buffer[1005]; void read(long long &x) { x = 0; char semn = '+'; while (buffer[poz] < '0' || buffer[poz] > '9') { semn = buffer[poz]; if (++poz == 1000) { fread(buffer, 1,...
12
#include <bits/stdc++.h> using namespace std; long long mod = 1e9 + 7; long long mode(long long n) { return ((n % mod) + mod) % mod; } void solve() { long long n, m; cin >> n >> m; long long d = n / m; long long dd = n % m; long long ddd = m - dd, i; for (i = 0; i < ddd; i++) cout << d << ' '; for (int i ...
0
#include <bits/stdc++.h> using namespace std; const int MN = 2e6 + 10; int n, k, g, sz = 1; string A; int G[MN], L, R, q[MN], my[MN]; int nxt[26][MN], f[MN]; vector<int> vec; void add(string s, int id) { int cur = 0; for (int i = 0; i < k; ++i) { if (!nxt[s[i] - 'a'][cur]) nxt[s[i] - 'a'][cur] = sz++; cur =...
15
#include <bits/stdc++.h> using namespace std; char s[110]; map<int, bool> mp[3]; bool Check(int x) { if (x < 10) { if (mp[0][x] || mp[1][x] || mp[2][x]) return true; } else if (x < 100) { int a = x / 10, b = x % 10; if (mp[0][a] && mp[1][b]) return true; if (mp[0][a] && mp[2][b]) return true; if...
5
#include <bits/stdc++.h> using namespace std; int n, m, a, b, dis; int f[50000]; int h[50000] = {0}, vis[50000]; int main() { cin >> n >> m; for (int i = 1; i <= m; i++) { cin >> a >> b; f[a]++; dis = b - a; if (dis < 0) dis += n; if (f[a] == 1 || dis < h[a]) h[a] = dis; } for (int i = 1; i ...
10
#include <bits/stdc++.h> using namespace std; struct Tree { static constexpr int unit = 1000000007; int f(int a, int b) { return min(a, b); } vector<int> s; int n; Tree(int n = 0, int def = unit) : s(2 * n, def), n(n) {} void update(int pos, int val) { for (s[pos += n] = val; pos /= 2;) s[pos] = f(s[pos...
15
#include <bits/stdc++.h> using namespace std; long long lcp[2500][2500], lcpr[2500][2500]; int main() { vector<pair<long long, long long> > v; string s, t; long long m, n, i, j; cin >> s; cin >> t; m = s.length(); n = t.length(); string rs = s; reverse(rs.begin(), rs.end()); for (i = m - 1; i >= 0; ...
12
#include <bits/stdc++.h> using namespace std; string str; map<string, int> ans1, ans2; int ma1, ma2; int main() { while (cin >> str) { int cnt = 0; while (true) { int i = str.find_last_of('\\'); if (i == 2) break; str = str.substr(0, i); int tmp = ans2[str]; ans1[str] += cnt; ...
10
#include <bits/stdc++.h> int main() { int n; while (scanf("%d", &n) == 1) { if (n % 3 == 2) n++; else if (n % 3 == 1) n--; printf("%d %d\n", n / 36, (n % 36) / 3); } return 0; }
6
#include <bits/stdc++.h> #pragma GCC optimize("O3") #pragma GCC target("sse4") using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int t; cin >> t; while (t--) { long long x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2; long long a = x2 - x1; long long b = y2 - y1; lon...
8
#include <bits/stdc++.h> using namespace std; int main() { long long int w1, h1, w2, h2; cin >> w1 >> h1 >> w2 >> h2; { cout << 2 * (w1 + h2 + h1) + 4 << endl; } return 0; }
0
#include <bits/stdc++.h> using namespace std; const int INF = int(1e9); const long long INFll = 1ll * INF * INF; const int MOD = 1000000007; const int MAXN = 100005; int main() { cin.tie(0); ios_base::sync_with_stdio(0); int n; cin >> n; vector<int> p(n + 1); int ans = 0; for (int i = 1; i <= n; ++i) cin ...
13
#include <bits/stdc++.h> using namespace std; struct pair_hash { template <class T1, class T2> size_t operator()(pair<T1, T2> const &pair) const { size_t h1 = std::hash<T1>()(pair.first); size_t h2 = std::hash<T2>()(pair.second); return h1 ^ h2; } }; int main() { int n, m; scanf("%d %d", &n, &m); ...
11
#include <bits/stdc++.h> using namespace std; long long int fac(int n) { if (n == 1 || n == 0) return 1; else return n * fac(n - 1); } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t = 1; while (t--) { int n; cin >> n; long long int a = fac(n / 2 - 1); long long i...
5
#include <bits/stdc++.h> using namespace std; const int inf = 1e5 + 10; const int INF = 0x3fffffff; int n, a[inf], mx = -INF, mn = INF; int cnt[3]; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d", &a[i]), mx = max(mx, a[i]), mn = min(mn, a[i]); if (mx - mn <= 1) { cout << n << endl; ...
9
#include <bits/stdc++.h> using namespace std; int cal(int time, int ac, int tot) { if (time == -1) return 0; if (2 * ac > tot) return 500 - 2 * time; if (4 * ac > tot) return 1000 - 4 * time; if (8 * ac > tot) return 1500 - 6 * time; if (16 * ac > tot) return 2000 - 8 * time; if (32 * ac > tot) return 2500 ...
12
#include <bits/stdc++.h> using namespace std; int n; int main() { int h, m; cin >> h >> m; int hunger, inc, cost, dec; cin >> hunger >> inc >> cost >> dec; m += h * 60; if (m >= 20 * 60) { float ans = (cost * 0.8) * ceil(1.0 * hunger / dec); printf("%.5f", ans); } else { float ans = (cost * 0....
3
#include <bits/stdc++.h> using namespace std; int main() { int tc; scanf("%d", &tc); while (tc--) { int n; scanf("%d", &n); double c, t; scanf("%lf %lf", &c, &t); pair<int, int> p[105]; for (int i = 0; i < n; i++) { int first, second; scanf("%d %d", &first, &second); p[i]...
17
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; const int MAXN = 1e5 + 10; const int MAXM = 333; vector<int> Le[MAXN]; vector<int> Ri[MAXN]; int num[MAXN]; int ans_q[MAXM]; int N, M; struct data { int l, r; } q[MAXM]; void update(int L, int R, int v) { for (int i = L; i <= R; i++) { ...
13
#include <bits/stdc++.h> using namespace std; template <typename T, typename U> inline void smin(T &a, const U &b) { if (a > b) a = b; } template <typename T, typename U> inline void smax(T &a, const U &b) { if (a < b) a = b; } template <class T> inline void gn(T &first) { char c, sg = 0; while (c = getchar(), ...
19
#include <bits/stdc++.h> using namespace std; template <class T> void pr(const string& name, T t) { cerr << name << ": " << t << endl; } template <typename T, typename... Types> void pr(const string& names, T t, Types... rest) { auto comma_pos = names.find(','); cerr << names.substr(0, comma_pos) << ": " << t << ...
20
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1.0); namespace FastFourierTransform { struct Complex { double x, y; Complex() { x = y = 0; } Complex(double _x, double _y) : x(_x), y(_y) {} Complex operator+(const Complex &r) const { return Complex(x + r.x, y + r.y); } Complex oper...
20
#include <bits/stdc++.h> using namespace std; char mat[5][101]; int main() { int N; scanf("%d", &N); int n = 3; for (int i = 3; i <= N; i += 2, n += 4) mat[1][i] = mat[1][i - 1] = n % 26, mat[2][i] = mat[2][i - 1] = (n + 1) % 26; n = 1; for (int i = 2; i <= N; i += 2, n += 4) mat[3][i] = mat[3][...
5
#include <bits/stdc++.h> using namespace std; int main() { int arr1[1024], arr2[1024]; int *old, *next; old = arr1; next = arr2; int n, k, x, z; cin >> n >> k >> x; fill(old, old + 1024, 0); for (int i = 0; i < n; i++) { scanf("%d", &z); old[z]++; } bool take; while (k--) { take = true...
10
#include <bits/stdc++.h> int main() { int n, i = 1, cnt = 0, v = 0, s = 0; scanf("%d", &n); while (i <= n) { v += i; s += v; if (s > n) { break; } i++; cnt++; } printf("%d\n", cnt); return 0; }
0
#include <bits/stdc++.h> using namespace std; const int N = 100010; char s[N]; char sta[N]; void sol() { scanf("%s", s); int len = strlen(s); int top = 0; sta[top] = s[0]; for (int i = 1; i < len; ++i) { if (top == -1) { sta[++top] = s[i]; } else { if (sta[top] == s[i]) top--; ...
8
#include <bits/stdc++.h> using namespace std; inline long long readInt() { long long sign = 1, x = 0, c = getc(stdin); while (c <= 32) { c = getc(stdin); } if (c == '-') { sign = -1; c = getc(stdin); } while ('0' <= c && c <= '9' && c != EOF) { x = (x << 1) + (x << 3) + c - '0'; c = getc...
10
#include <bits/stdc++.h> int i, j, m, d, a1, a2, s, b1, n, k, x, y, l, pos, v, b, smin, c[101], a, last[100]; void sol() { printf("%d", n); for (i = 1; i <= n - 1; i++) { printf(" %d", i); } printf("\n"); } int main() { #pragma comment(linker, "/STACK:16777216") while (scanf("%d", &n) != EOF) { so...
2
#include <bits/stdc++.h> using namespace std; int main() { long long i, j, k, l, m, n, a = 1; cin >> n; while (n--) { if (a == 1 || a == 2) { cout << "a"; a++; } else if (a == 3 || a == 4) { cout << "b"; a++; } if (a == 5) a = 1; } cout << endl; }
2
#include <bits/stdc++.h> using namespace std; bool v[30]; int power[30]; char ch[20]; int main() { int n, i, aux, solutie = 0; cin >> n; cin.get(); for (i = 1; i <= n; i++) { cin >> (ch + 1); int m = strlen(ch + 1), put = 1; v[ch[1] - 'a'] = 1; for (int i = m; i >= 1; i--) { power[ch[i] - ...
9
#include <bits/stdc++.h> using namespace std; int main() { int n, k; int i, j; int s, c; int a[110]; cin >> n >> k; for (i = 1; i <= n; i++) cin >> a[i]; s = 0; c = 1; for (i = 1; i <= n; i++) { if (c == 0) break; if (a[i] <= k) s = s + 1; else for (j = n; j >= i; j--) { ...
0
#include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int, int>; using pll = pair<ll, ll>; template <typename T> int sz(const T &a) { return int(a.size()); } struct trie { struct node { int ans, mival, maval, left, right; node() { left = -1, right = -1; ans = INT_M...
21
#include <bits/stdc++.h> using namespace std; struct edge { int t, next, v, rev; } g[610001]; struct data { int a, v; } b[310001][2]; bool sat[310001]; int i, j, k, n, m, h[310001], st[310001], a[310001], p[310001], ans[310001], tmp, tot, now, ts[310001], se[310001]; void addedge(int x, int y, int v) { g[++to...
17
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 10; int n, m, l = 1, r, tot, block, a[maxn], sum[maxn], ans[maxn]; struct query { int l, r, id; } q[maxn]; bool cmp(query a, query b) { if (a.l / block == b.l / block) return a.r < b.r; return a.l < b.l; } void add(int x) { if (a[x] > n) retur...
10
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const long long INFF = 0x3f3f3f3f3f3f3f3fll; const long long M = 1e9 + 7; const long long maxn = 2e5 + 107; const double pi = acos(-1.0); const double eps = 0.0000000001; long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } t...
15
#include <bits/stdc++.h> using namespace std; int main() { long long int n, m, i, j, k; scanf("%lld", &n); ; scanf("%lld", &m); ; long long int ans = 0; long long int temp = n - 1, len1 = 0, len2 = 0; while (temp != 0) { len1++; temp /= 7; } temp = m - 1; while (temp != 0) { len2++; ...
9
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:102400000,102400000") using namespace std; template <class _T> inline _T low(_T n) { return n & (-n); } template <class _T> inline void swapp(_T &x, _T &y) { _T t; t = x, x = y, y = t; } template <class _T> inline _T minn(_T i, _T j) { return i > j ? j : ...
11
#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; int ans = 0; char prev = 'a'; char next = s[0]; for (int i = 1; i <= s.size(); i++) { int x = prev - 97; int y = next - 97; int val1 = abs(x - y);...
0
#include <bits/stdc++.h> using namespace std; void print(bool flag) { if (flag) cout << "YES" << endl; else cout << "NO" << endl; } void solve() { long long s, n, k; cin >> s >> n >> k; if (s == k) { print(1); return; } long long t = 0; if (n % k == 0) t = 2 * n; else t = (n / ...
16
#include <bits/stdc++.h> using namespace std; using ll = long long; const int maxn = 2e3 + 5, inf = 1e9 + 7; bool vis[maxn]; int n, w[maxn], p[maxn], d[maxn][maxn]; ll out[maxn][maxn]; vector<pair<int, int>> vs[maxn]; void dfs(int v, int r, int p = -1) { for (auto& e : vs[v]) if (e.first != p) { out[r][e.fi...
11
#include <bits/stdc++.h> using namespace std; void solve() {} const long long maxn = 200500; long long n; long long l[maxn], r[maxn], sufmi[maxn], sufma[maxn], ans[maxn]; void no() { cout << -1 << '\n'; exit(0); } signed main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n; for (long long i = 1; i <= n; i...
10
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; const long long M = 1e9 + 7; int main() { int n, m; scanf("%d", &n); scanf("%d", &m); vector<pair<int, int> > ans; pair<int, int> l = {1, 1}, r = {n, m}; while (l <= r) { if (l == r) { ans.push_back(l); break; } ans...
10
#include <bits/stdc++.h> using namespace std; template <typename T> void out(T x) { cout << x << endl; exit(0); } const int maxn = 1e6 + 5; int n, m, a[maxn]; int dp[maxn]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> m; for (int i = 0; i < n; i++) { cin >> a[i];...
9
#include <bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; const int maxn = 1 << 19, bit = 20; int n, c[maxn], q, dat[2 * maxn][bit], res[bit]; void insert(int* a, int x, int hi) { for (int i = (hi)-1; i >= (0); --i) { if (x & (1 << i)) { if (a[i]) x ^= a[i]; else { for (...
17
#include <bits/stdc++.h> using namespace std; string s[1005]; int main() { int n, ans = 0, tem = 0; cin >> n; for (int i = 0; i < n; i++) { cin >> s[i]; } for (int i = 0; i < 7; i++) { tem = 0; for (int j = 0; j < n; j++) { if (s[j][i] == '1') tem++; } if (tem > ans) ans = tem; } ...
1
#include <bits/stdc++.h> using namespace std; const int MOD = 998244353; const int FFTN = 1 << 19; int power(int x, int y) { int s = 1; for (; y; y /= 2, x = 1ll * x * x % MOD) if (y & 1) s = 1ll * s * x % MOD; return s; } namespace FFT { int w[FFTN + 5], W[FFTN + 5], R[FFTN + 5]; void FFTinit() { W[0] = 1;...
23
#include <bits/stdc++.h> using namespace std; long long int gcd(long long int a, long long int b) { if (b == 0) return a; return gcd(b, a % b); } int main() { long long int t; cin >> t; while (t--) { long long int n, k; cin >> n >> k; vector<long long int> a(n); map<long long int, long long in...
6
#include <bits/stdc++.h> using namespace std; const long long maxn = 1e6 + 100; const long long mod = 1e9 + 7; const long long inf = 1e18; struct node { long long mn0, mn1, r0, r1, sz, lz; node() { mn0 = mn1 = r0 = r1 = inf; sz = lz = 0; } }; long long n, m, a[maxn]; bool ans[maxn]; pair<pair<long long, l...
18
#include <bits/stdc++.h> using namespace std; int main() { int t, n, a = 1; scanf("%d", &t); while (t--) { scanf("%d", &n); for (int i = 0; i < n - 1; i++) { printf("%d ", a); } printf("%d\n", a); } return 0; }
0
#include <bits/stdc++.h> using namespace std; int N, M; bool graph[20][20]; long long f[1 << 20][20]; int intLen[1 << 20]; void york() { long long total = 0; long long ans[20]; memset(ans, 0, sizeof(ans)); memset(f, 0, sizeof(f)); int upper = (1 << N) - 1; for (int i = 0; i < N; ++i) f[1 << i][i] = 1; for...
14
// 2021 #include<bits/stdc++.h> using namespace std; //constant define things #define pb(a) push_back(a); #define pf(a) push_front(a); #define ff first #define ss second #define all(s) s.begin(),s.end() #define pii pair<int,int> #define pll pair<long,long> bool isVowel(char a){ a=tolower(a); return (a=='a'||a...
0
#include <bits/stdc++.h> using namespace std; const int MOD = 998244353; const int SET_SIZE = 50349; using Line = bitset<SET_SIZE>; vector<vector<int>> gen(int N) { vector<vector<int>> res; vector<int> cur(N); function<void(int, int)> fill = [&](int nxt, int now) { if (now == 0) { res.push_back(cur); ...
22
#include <bits/stdc++.h> #pragma warning(disable : 4018) using namespace std; namespace { void solve() { int n, L, a; cin >> n >> L >> a; vector<pair<int, int> > s; s.push_back(make_pair(0, 0)); for (int i = 0; i < n; i++) { int t, l; cin >> t >> l; s.push_back(make_pair(t, l)); } s.push_back(...
2
#include <bits/stdc++.h> using namespace std; long long int dsu[55], s[55] = {0}, x, y, n, m, Ti = 1; long long int finddsu(long long int u) { if (u == dsu[u]) return u; else return dsu[u] = finddsu(dsu[u]); } void uniondsu(long long int u, long long int v) { long long int a = finddsu(u); long long int ...
6
#include <bits/stdc++.h> using namespace std; const int MAXM = 300; long long num[1000 * 1000 + 10]; long long x[MAXM], y[MAXM]; int main() { long long ans = 0; long long n, m; cin >> n >> m; for (int i = 0; i < m; i++) cin >> x[i] >> y[i]; for (int i = 0; i <= n; i++) num[i] = 1; for (int i = 0; i < m; i++...
9
#include <bits/stdc++.h> using namespace std; int a[5][5]; bool used[100004]; int x, y; bool isadj(int a, int b) { if (a == 0 || b == 0) return false; if (abs(a - b) == 1 && (a - 1) / y == (b - 1) / y) return true; if (abs(a - b) == y) return true; return false; } bool dfs(int cx, int cy) { if (cy == y + 1) {...
14
#include <bits/stdc++.h> using namespace std; int t; map<string, int> name; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> t; name["void"] = 0; name["errtype"] = -1; while (t--) { string op; cin >> op; if (op == "typedef") { string a, b; cin >> a >> ...
10
#include <bits/stdc++.h> using namespace std; const int N = 100000 + 10; long long a[N]; int main() { int n, k, l, m; cin >> n >> k >> l; m = n * k; for (int i = 0; i < m; i++) cin >> a[i]; sort(a, a + m); int r = 0; while (r < m && (a[r] - a[0]) <= l) r++; if (r < n) { cout << 0; return 0; } ...
7
#include <bits/stdc++.h> using namespace std; int main(void) { long int w, min, max, keep = 0; int n; vector<long int> floor; vector<long int> ceil; cin >> n >> w; ceil.push_back(keep); floor.push_back(w); for (int i = 0; i < n; i++) { long int aux; cin >> aux; w -= aux; keep -= aux; ...
6
#include <bits/stdc++.h> using namespace std; template <class T> inline void smn(T &a, const T &b) { if (b < a) a = b; } template <class T> inline void smx(T &a, const T &b) { if (b > a) a = b; } const double eps = 1e-8; int n, m; pair<int, int> p[4]; void check(vector<pair<int, int> > p2) { double l1 = 0, l2 = 0...
10
#include <bits/stdc++.h> using namespace std; long long int findSubarraySum(long long int arr[], long long int n, long long int sum) { map<long long int, long long int> prevSum; long long int res = 0; long long int currsum = 0; for (long long int i = 0; i < n; i++) { currsum +=...
8
#include <bits/stdc++.h> using namespace std; int n, a; map<int, int> usd; int main(void) { cin >> n; long long ans = 0; for (int i = 0; i < n; i++) { cin >> a; while (a && usd[a] != 0) { a--; } usd[a] = 1; ans += (long long)a; } cout << ans << "\n"; return 0; }
3
#include <bits/stdc++.h> using namespace std; const int N = 200; const int M = 200; const int INF = 0x3f3f3f3f; int n, k; int a[N], b[N], c[N]; int main(void) { scanf("%d%d", &n, &k); for (int i = 0; i < n; i++) { scanf("%d", &a[i]); } for (int i = 0; i < k; i++) { scanf("%d", &b[i]); } if (k == 1) ...
1
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); int t; cin >> t; for (int tt = 0; tt < t; tt++) { int n; cin >> n; vector<bool> l(n), r(n); for (int i = 0; i < n; i++) { int k; cin >> k; for (int j = 0; j < k; j+...
4
#include <bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; unordered_map<int, int> mp; int n, q; int d[((int)1e7 + 5) + 1000]; int pre[((int)1e7 + 5) + 1000]; bool prime[((int)1e7 + 5) + 1000]; vector<int> primes; unordered_map<int, int> ans; void findprime() { for (int i = 2; i * i < ((int)1e7 + 5); ++...
9
#include <bits/stdc++.h> using namespace std; int main() { int n; string s; bool c1 = false, c2 = false, f1 = false, f2 = false; cin >> n; cin >> s; for (int i = 0; i < n; i++) { char c = s[i]; if (c == '0') { c1 = true; c2 = true; f2 = true; } if (c == '1') { c1 = tr...
6
#include <bits/stdc++.h> using namespace std; int n, m, a[200002], b[2000002]; int gg = 0, hh = 0, ff = 1; inline int read() { int s = 0, f = 0; char c = getchar(); while (!isdigit(c)) f = (c == '-'), c = getchar(); while (isdigit(c)) s = (s << 3) + (s << 1) + (c ^ '0'), c = getchar(); return f ? -s : s; } in...
5
#include <bits/stdc++.h> using namespace std; int h; char x; int main() { h = 0; bool flag; while (scanf("%c", &x) != EOF) { if (x == '\n') break; scanf("%c", &x); if (x == '/') flag = true; else flag = false; if (flag) h -= 2; for (int i = 1; i <= h; i++) printf(" "); if (...
2
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e5; const int MOD = 998244353; long long n, ans; bool cmpa(int a, int b) { return (a < b); } bool cmpb(int a, int b) { return (a > b); } int add(int a, int b) { int c = a + b; if (c >= MOD) { c -= MOD; } if (c < 0) { c += MOD; } return ...
8
#include <bits/stdc++.h> using namespace std; const int MOD = (int)1e9 + 7; const int FFTMOD = 119 << 23 | 1; const int INF = (int)1e9 + 23111992; const long long LINF = (long long)1e18 + 23111992; const long double PI = acos((long double)-1); const long double EPS = 1e-9; inline long long gcd(long long a, long long b)...
21
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c; cin >> a >> b >> c; int x = a; if ((c == -1) && (a >= b)) { cout << "YES" << endl; return 0; } if ((c == 1) && (a <= b)) { cout << "YES" << endl; return 0; } if ((c == 0) || (a == b)) { if (a == b) { cout <...
3
#include <bits/stdc++.h> using namespace std; template <typename T> inline T read(T &x) { x = 0; int f = 0; char ch = getchar(); while (ch < '0' || ch > '9') { f |= (ch == '-'), ch = getchar(); } while (ch >= '0' && ch <= '9') { x = (x << 1) + (x << 3) + ch - '0', ch = getchar(); } return x = f ...
2
#include <bits/stdc++.h> using namespace std; int a[100000]; int startConsecutive(int m) { for (int i = 0; i < m; i++) { if (a[i] != i + 1) { return i; } } return m; } int main(int argc, char *argv[]) { int n, k; cin >> n >> k; int m; int answer = 0; int consecutive = 0; for (int i = 0; ...
7
#include <bits/stdc++.h> using namespace std; inline void scf(int &x) { scanf("%d", &x); } inline void scf(long long &x) { scanf("%I64d", &x); } inline void scf(unsigned long long &x) { scanf("%I64u", &x); } inline void scf(double &x) { scanf("%lf", &x); } inline void scf(char &x) { scanf("%c", &x); } inline void scf(c...
11
#include <bits/stdc++.h> using namespace std; int a, b, c, d; void setup() { cin >> a >> b >> c >> d; a = max(a * 3 / 10, a - a / 250 * c); b = max(b * 3 / 10, b - b / 250 * d); if (a > b) cout << "Misha"; if (a < b) cout << "Vasya"; if (a == b) cout << "Tie"; } void xuly() {} int main() { ios_base::sync_...
1
#include <bits/stdc++.h> using namespace std; const long long int maxn = 300010; char str[maxn]; long long int cnt[4]; vector<long long int> idxs[4]; long long int skipped[4]; long long int toint(char in) { return in - '0'; } int main() { long long int n; scanf("%lld", &n); scanf(" %s", str); for (long long int...
7
#include <bits/stdc++.h> using namespace std; int dist[101][101]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; string s[n + 1]; for (int i = 1; i <= n; i++) { cin >> s[i]; } for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { dist[i][j] =...
9
#include <bits/stdc++.h> using namespace std; int num, q[200005], ne[200005], head[100005]; int col[100005], n, m, x, y, num1, num2, flag; void addnum(int x, int y) { num++; q[num] = y; ne[num] = head[x]; head[x] = num; } void dfs(int t, int fa, int type) { if (type == 1) { col[t] = 1; num1++; } els...
7
#include <bits/stdc++.h> using namespace std; int n, m, i, x, y, k, a, q, h, l, r, j, p, ans, s[400], dp[51][51][110], dp1[51][51][110], tail1[51][51][110], tail2[51][51][110], dp3[51][110], sss[51][51][110], dpp[51][110], dpp1[51][110]; vector<int> ve[51][51]; bool ok1, ok2, Find, ok[51][51]; void get(int x, i...
23
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout << fixed << setprecision(9); long long m; cin >> m; while (m--) { long long n, t, a, b; cin >> n >> t >> a >> b; vector<long long> val(n); ve...
10
#include <bits/stdc++.h> using namespace std; int main() { long unsigned n; cin >> n; long long unsigned l[n], r[n]; for (int i = 0; i < n; i++) { cin >> l[i]; cin >> r[i]; } sort(l, l + n); sort(r, r + n); long long unsigned resp = 0; for (int j = 0; j < n; j++) { resp += max(l[j], r[j]);...
11
#include <bits/stdc++.h> using namespace std; const int N = 1E5 + 7; vector<int> xin[N]; vector<int> a[N], b[N]; bool vis[N]; int dx[4] = {1, 0, -1, 0}; int dy[4] = {0, 1, 0, -1}; int n, m; bool check(int x, int sb1, int sb2) { if (sb1 <= 0 || sb2 <= 0) return false; for (int i = 0; i < xin[x].size(); i++) { if...
14
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const long long LLMAX = 9223372036854775807ll; const int maxn = 410; vector<int> g[maxn]; int pre[maxn], dep[maxn]; int leaf = 0; void dfs(int u, int fa) { pre[u] = fa; bool l = 1; for (int i = 0; i < g[u].size(); i++) { int v = g[u][i]...
12
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long n, p, w, d; cin >> n >> p >> w >> d; for (int y = 0; y < w; y++) { long long x = (p - y * d) / w; if (y + x <= n && (p - y * d) % w == 0 && (p - y * d) >= 0) { cout << x << " ...
12