solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> using namespace std; int main() { long long t; cin >> t; while (t--) { long long n, d; cin >> n >> d; vector<long long> a(n); for (long long i = 0; i < n; i++) { cin >> a[i]; } long long i = 1; while (d > 0 && i < n) { if (a[i] > 0 && d >= i) { ...
0
#include <bits/stdc++.h> using namespace std; const int N = 5e5 + 10; int n, m; vector<pair<int, int> > g[N]; pair<int, int> b[N][2]; int len[N], deep[N], l[N], r[N], cnt, sig[N], l2id[N]; int ans[N]; int edge[N][2], q[N]; struct node { int v[2]; bool tag; void clear() { v[0] = v[1] = 0; tag = 0; } } f[...
20
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10; vector<int> v[maxn]; int mp[maxn]; int ans[maxn]; int n; void dfs(int root, int par) { for (int i = 0; i < v[root].size(); i++) { if (v[root][i] != par) { dfs(v[root][i], root); ans[root] += ans[v[root][i]]; } } if (v[roo...
8
#include <bits/stdc++.h> using namespace std; void Solve() { int n, m, k; cin >> n >> m >> k; vector<vector<int>> a(n, vector<int>(m)); string s; getline(cin, s); for (int i = 0; i < (n); i++) { getline(cin, s); for (int j = 0; j < m; j++) { a[i][j] = (s[j] == '#'); } } int x1, y1, x2,...
13
#include <bits/stdc++.h> using namespace std; const int d[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}}; char a[1010][1010], b[1010][1010]; pair<int, int> ans[1010][1010]; vector<pair<int, int> > v, tmp; int u[1010][1010], V[1010][1010]; int n, m, tot = 0, U[10]; void dfs(int x, int y) { if (V[x][y] == tot) return; V[...
14
#include <bits/stdc++.h> using namespace std; vector<int> z; int n; void z_function(string s) { z[0] = 0; for (int i = 1, l = 0, r = 0; i < n; i++) { if (i <= r) z[i] = min(z[i - l], r - i + 1); while (i + z[i] < n && s[z[i]] == s[i + z[i]]) z[i]++; if (i + z[i] - 1 > r) l = i, r = i + z[i] - 1; } } i...
9
#include <bits/stdc++.h> using namespace std; string trUpp(string s) { transform(s.begin(), s.end(), s.begin(), ::toupper); return ""; } int main() { int r, c; cin >> r >> c; char a[r][c]; bool can = true; int ans = 0; set<int> st; for (int i = 0; i < (r); i++) { string s; cin >> s; int g ...
4
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; for (int i = 0; i < t; i++) { int n; cin >> n; int last; cin >> last; bool strictly_increasing = true; for (int j = 1; j < n; j++) { int x; cin >> x; if (x <= last) { strictly_increasing =...
3
#include <bits/stdc++.h> using namespace std; int x, y; int main() { cin >> x >> y; int X = (x > 0) ? x : -x; int Y = (y > 0) ? y : -y; if (x > 0) { cout << 0 << " " << (y / Y) * (X + Y) << " " << (X + Y) << " " << 0; } else { cout << -(X + Y) << " " << 0 << " " << 0 << " " << (y / Y) * (X + Y); } }...
2
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; long long n, k, a[N]; map<long long, long long> cnt; long long w[N], ans; long long qpow(long long a, long long b) { long long r = 1; while (b) { if (b & 1) r = r * a; b >>= 1; a = a * a; } return r; } int32_t main() { cin >> n >...
10
#include <bits/stdc++.h> int main() { long a[4]; int unique = 4, flag; for (int i = 0; i < 4; i++) { std::cin >> a[i]; } for (int i = 0; i < 4; i++) { flag = 0; for (int j = 0; j < i; j++) { if (a[i] == a[j]) flag = 1; } if (flag) unique--; } unique = 4 - unique; std::cout << u...
0
#include <bits/stdc++.h> using namespace std; template <typename T> using minpq = priority_queue<T, vector<T>, greater<T>>; struct pt { long long x, y; pt(long long x = 0, long long y = 0) : x(x), y(y) {} pt operator-(const pt &o) const { return pt(x - o.x, y - o.y); } long long cross(const pt &o) const { retur...
24
#include <bits/stdc++.h> const int N = 200005; int n, m, cnt, last[N], ans[N], s[N]; struct edge { int to, next, id; } e[N * 2]; bool vis[N]; void addedge(int u, int v, int id) { e[++cnt].to = v; e[cnt].id = id; e[cnt].next = last[u]; last[u] = cnt; e[++cnt].to = u; e[cnt].id = -id; e[cnt].next = last[v...
16
#include<cstdio> #include<algorithm> #include<vector> #include<set> using namespace std; int read() { int x=0,f=1;char c=getchar(); while(c>'9'||c<'0'){if(c=='-')f=-1;c=getchar();} while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();} return x*f; } const int N=4e5+5; struct HSHMAP { int head[131072],nxt[N],U[N],V[N],si...
17
#include <bits/stdc++.h> using namespace std; struct node { int a, b; }; bool mp[100001]; int primer[100001]; int tmp[100001]; int n, m; node res[100001]; int getPrimer(int n) { memset(mp, 0, sizeof(mp)); int cnt = 0; for (int i = 2; i * i <= n; i++) if (!mp[i]) for (int j = i * i; j <= n; j += i) mp[...
17
#include <bits/stdc++.h> using namespace std; using u64 = uint64_t; vector<long long> v[300]; vector<bool> vis(300); vector<long long> ans, tmp, tmp_ans; bool dfs(long long fr, long long to) { if (fr == to) { tmp_ans.push_back(fr); return true; } vis[fr] = true; for (auto x : v[fr]) { if (!vis[x]) {...
12
#include <bits/stdc++.h> using namespace std; const int M = 1e9 + 7; long long mod(long long x) { return ((x % M + M) % M); } long long add(long long a, long long b) { return mod(mod(a) + mod(b)); } long long mul(long long a, long long b) { return mod(mod(a) * mod(b)); } long long modPow(long long a, long long b) { i...
7
#include <bits/stdc++.h> void solve(int x); int main() { int x; while (scanf("%d", &x) != EOF) { solve(x); } } void solve(int x) { int hh, mm; scanf("%d%d", &hh, &mm); int count = 0; while (1) { if (hh == 7 || hh == 17 || mm == 7 || mm == 17 || mm == 27 || mm == 37 || mm == 47 || mm == 57)...
1
#include <bits/stdc++.h> using namespace std; int S = 256 * 256, cnt[256 * 256]; vector<int> adj[256 * 256], ans; void dfs(int u) { while (!adj[u].empty()) { int v = adj[u].back(); adj[u].pop_back(); dfs(v); } ans.push_back(u); } int main() { int n; cin >> n; for (int i = 1; i <= n; i++) { s...
17
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e5 + 10, mod = 998244353; int n, x[MAXN], y[MAXN], s[MAXN]; long long f[MAXN], sum[MAXN], ans; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d %d %d", &x[i], &y[i], &s[i]); for (int i = 1; i <= n; i++) { int k = lower_bound(x...
14
#include <bits/stdc++.h> using namespace std; vector<int> wall; vector<int> wall_diff; vector<int> tower; vector<int> tower_diff; void print_array(vector<int> a) { for (const auto &i : a) { cout << i << " "; } cout << endl; } int count_occurrences(vector<int> haystack, vector<int> needle) { vector<int> tabl...
10
#include <bits/stdc++.h> int main() { long long int a, b, d, time = 0; char c; scanf("%lld%c", &a, &c); b = a / 4; if (a % 4 == 0) b--; time += b * 12; if (a % 4 == 2 || a % 4 == 0) { time += 6; } if (a % 4 == 1) time += a - 1; if (a % 4 == 2) time += a - 1; if (a % 4 == 3) { time += a - 3...
4
#include <bits/stdc++.h> using namespace std; struct data { int X, v, l; data() {} data(int xx, int vv, int ll) { X = xx, v = vv, l = ll; } }; string G[2]; int n, k, visited[2][100008]; string bfs() { queue<data> Q; Q.push(data(0, 0, -1)); visited[0][0] = 1; int v, dir, l; data top; while (!Q.empty())...
6
#include <bits/stdc++.h> using namespace std; namespace IO { const int BUFFER_SIZE = 1 << 15; char input_buffer[BUFFER_SIZE]; int input_pos = 0, input_len = 0; char output_buffer[BUFFER_SIZE]; int output_pos = 0; char number_buffer[100]; uint8_t lookup[100]; void _update_input_buffer() { input_len = fread(input_buffe...
16
#include <bits/stdc++.h> using namespace std; const int maxn = 77; int saveori[maxn][maxn]; int dp[maxn][maxn][maxn][maxn]; int save[maxn][maxn]; int n, m, k; void solve(int hang) { int mxc = m / 2; dp[hang][0][0][0] = 0; save[hang][0] = 0; for (int i = 1; i <= m; i++) { int nowval = saveori[hang][i]; d...
13
#include <bits/stdc++.h> using namespace std; const int maxN = 2000 + 10; const int maxM = 1000 * 100 * 4; const int mod = 1e9 + 7; inline int bpow(int a, int b) { int res = 1; for (; b; b /= 2) { if (b & 1) res = res * 1ll * a % mod; a = a * 1ll * a % mod; } return res; } int fact[maxM]; inline int ch(...
14
#include <bits/stdc++.h> using namespace std; bool is_prime(int n) { for (int i = 2; i <= sqrt(n); i++) { if (!(n % i)) return false; } return true; } void solve(int index = 0) { int n, q, m; cin >> n >> q >> m; vector<int> v(n); for (auto &c : v) cin >> c; vector<pair<int, pair<int, int>>> queries(...
10
#include <bits/stdc++.h> using namespace std; const int INF = 1e9 + 250; long long mod = 1e9 + 7; const int N = 100005; long long quick_pow(long long x, long long p, long long mod) { long long ret = 1; while (p) { if (p & 1) ret = ret * x % mod; p >>= 1; x = x * x % mod; } return ret; } int main() {...
3
#include <bits/stdc++.h> using namespace std; double p[110][110], fp[110][110][110]; double f[110][110][110]; void solve(int le, int ri, int score) { if (le == ri) { fp[le][ri][le] = 1; return; } int mid = le + ri >> 1; solve(le, mid, score - 1); solve(mid + 1, ri, score - 1); for (int i = le; i <= ...
13
#include <bits/stdc++.h> using namespace std; char store[1005][1005]; bool check[1005][1005][4]; int cost[1005][1005][4]; struct data { int x, y, t; }; int xx[4] = {+1, +0, -1, +0}, yy[4] = {+0, -1, +0, +1}; queue<data> cur; int main(void) { int n, m; scanf("%d %d", &n, &m); for (int i = 0; i < (n); ++i) scanf(...
12
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long n, k; cin >> n >> k; if (n < k) cout << n << endl; else { long long s = n - n / k - 1; for (long long i = s; i <= n - 1; i++) { int ans = 0; int p = 0; ...
7
#include <bits/stdc++.h> using namespace std; template <typename T> inline void read(T &x) { T f = 1, ch = getchar(); x = 0; while (!isdigit(ch)) { f = ch == '-' ? -1 : 1, ch = getchar(); } while (isdigit(ch)) { x = x * 10 + ch - 48, ch = getchar(); } x *= f; } template <typename T> void print(T x...
14
#include <bits/stdc++.h> using namespace std; struct knight { long long int p, c, id, a; }; bool func(knight k1, knight k2) { return k1.p < k2.p; } int main() { int n, m; cin >> n >> m; knight k[n]; for (int i = 0; i < n; i++) cin >> k[i].p; for (int i = 0; i < n; i++) cin >> k[i].c; for (int i = 0; i < n...
6
#include <bits/stdc++.h> long long const MAX = 1e5 + 5; using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); string s; cin >> s; long long n = s.length(); for (long long i = 0; i < n - 1; i++) { if (s[i] == 'n') continue; if (s[i] != 'a' && s[i] != 'e' && s[...
1
#include <bits/stdc++.h> using namespace std; int main() { int a[7], t = 0, r = 0, r1 = 0, r2 = 0, s1 = 0, s2 = 0, s3 = 0, s4 = 0, s5 = 0, m = 0, d = 0; for (int i = 0; i < 5; i++) { cin >> a[i]; } sort(a, a + 5); for (int i = 0; i < 5; i++) { for (int j = r; j < 5; j++) { if (a[i] =...
0
#include <bits/stdc++.h> using namespace std; const int BASE = int(1e9) + 7; long long f[1000100]; int main() { f[0] = f[1] = 1; for (int i = 2; i <= 1000000; i++) f[i] = (f[i - 1] + f[i - 2] * (i - 1)) % BASE; int d1 = 0, x, n; cin >> n; for (int i = 0; i < n; i++) { scanf("%d", &x); if (x == 1) ...
15
#include <bits/stdc++.h> using namespace std; const int mxN = 1e5 + 10; const int INF = 1e9; int ans[505][505]; int n, m, k; vector<int> c(505); vector<pair<int, int> > g[mxN]; vector<int> type(mxN); vector<vector<int> > cost(505, vector<int>(505, INF)); vector<int> vis(mxN, 0); void dfs(int root, int cur) { vis[root...
12
#include <bits/stdc++.h> using namespace std; int main() { long a, b, c; cin >> a >> b >> c; double rr = sqrt(b * b - 4 * a * c); if (a > 0) cout << scientific << (rr - b) / (double(2 * a)) << '\n' << (-b - rr) / (double(2 * a)) << endl; else cout << scientific << (-b - rr) / (double(2 * a)) ...
5
#include <bits/stdc++.h> using namespace std; struct rect { int x1, y1, x2, y2; }; bool divide(vector<rect> v) { if (v.size() == 1) { return true; } int n = v.size(); sort(v.begin(), v.end(), [](rect f, rect s) { return (f.x1 == s.x1) ? (f.x2 < s.x2) : (f.x1 < s.x1); }); int right_bound = v[0].x2;...
17
#include <bits/stdc++.h> using namespace std; int solve(int x, int n) { if (x == 0) { if (n == 0 || n == 5) return 0; if (n < 3) return 1; if (n < 5) return 2; } if (x == 1) { if (n == 0 || n == 3) return 1; if (n == 1 || n == 4) return 0; if (n == 2 || n == 5) return 2; } if (x == 2) ...
2
#include<bits/stdc++.h> using namespace std; #define lli long long int #define ulli unsigned long long int #define Pi 3.14159265358979323846264338327950288419716939937510 #define print(x) cout<<endl<<"At line "<<x<<endl; int main(){ ios :: sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); ...
12
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10, maxm = 12, SQ1 = 1024, SQ2 = 1001, LG = 12, inf = 1e9; int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1}; pair<int, int> f1[maxn][maxm], f2[maxn][maxm], f3[maxn][maxm][LG]; pair<int, int> arr[SQ1]; inline int what(char ch) { if (ch == '...
19
#include <bits/stdc++.h> using namespace std; int gcd(int x, int y) { return y ? gcd(y, x % y) : abs(x); } int sqr(int x) { return x * x; } vector<int> g[110 * 1000]; int v0[110 * 1000]; pair<long long, long long> dfs(int u, int prev) { pair<long long, long long> ans; for (int i = 0; i < int((g[u]).size()); ++i) { ...
10
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1.0); const int INF = 1061109567; const long long LINF = 4557430888798830399ll; const int MOD = 998244353; const int INV2 = (MOD + 1) / 2; deque<int> dq1; deque<int> dq2; void test_case() { int n; scanf("%d", &n); for (int i = n - 1; i >= 1; i ...
11
#include <bits/stdc++.h> using namespace std; long long a[5005], b[5005], f[2][5005]; int main() { int n; scanf("%lld", &n); for (int i = 1; i <= n; i++) scanf("%lld", &a[i]); memcpy(b, a, sizeof(b)); sort(b + 1, b + 1 + n); for (int i = 1; i <= n; i++) { long long S = 2e18; for (int j = 1; j <= n; ...
14
#include <bits/stdc++.h> using namespace std; char cand[300]; char aux[300]; int success; int main() { int defined = 0; int n; cin >> n; for (char i = 'a'; i <= 'z'; i++) cand[i] = 1; int shocks = 0; for (int i = 0; i < n - 1; i++) { char action; cin >> action; string word; cin >> word; ...
8
#include <bits/stdc++.h> using namespace std; struct plank { int x, i; } v[100010]; struct query { int l, r, w; } q[100010]; struct tree { int x, l, r, s; tree() { x = l = r = s = 0; } } a[4 * 100010]; int n, m, answer[100010], l, r; vector<int> B[2][100010 * 2]; bool cmp(plank a, plank b) { return a.x > b.x; }...
17
#include <bits/stdc++.h> using namespace std; int fq[112345], pf[112345], h[15]; int dp[12][505][5002]; int main() { int n, k, i, f, g, first = 0, K, ans = 0, x, j; scanf("%d %d", &n, &K); for (j = K * n; j--;) { scanf("%d", &x); fq[x]++; first = max(first, fq[x]); } vector<int> q; for (i = 1; i...
12
#include <bits/stdc++.h> const int N = 500500; const int Q = 1 << 21; const int mod = 1e9 + 7; using namespace std; int main() { long long n; cin >> n; char ch[n + 1]; for (long long i = 1; i <= n; i++) cin >> ch[i]; long long arr[n + 1]; for (long long i = 1; i <= n; i++) cin >> arr[i]; long long ans[4][...
10
#include <bits/stdc++.h> using namespace std; int main() { int n, i, r[5001], j, s, maxim = 0; cin >> n; for (i = 1; i <= n; i++) { cin >> r[i]; s = r[i]; if (r[i] > 100) maxim = max(maxim, 1); for (j = i - 1; j >= 1; j--) { s = s + r[j]; if (s > (i - j + 1) * 100) maxim = max(maxim, i...
6
#include <bits/stdc++.h> using namespace std; const int N = 2 * 1e5 + 10; const long long inf = 1e18 + 100; const long long mod = 1e9 + 7; void solve() { long long n, k; cin >> n >> k; long long arr[k][26]; memset(arr, 0, sizeof arr); string s; cin >> s; for (int i = 0, j = 0; i < s.size(); i++) { arr...
7
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; long long dx[] = {-1, 0, 1, 0}; long long dy[] = {0, -1, 0, 1}; vector<long long> sz(200005), p(200005); long long find(long long x) { return x == p[x] ? p[x] : (p[x] = find(p[x])); } void merge(long long x, long long y) { x = find(x), y = f...
11
#include <bits/stdc++.h> using namespace std; int main() { int n, i, t, j, b, p; while (~scanf("%d%d%d", &n, &b, &p)) { printf("%d %d\n", (b * 2 + 1) * (n - 1), n * p); } }
2
#include <bits/stdc++.h> using namespace std; const long long sz = 1e5 + 5; long long a[sz]; vector<long long> adjlist[sz]; long long ch[sz][2], vis[sz]; void dfs(long long node) { vis[node] = 1; vector<long long> v; for (auto child : adjlist[node]) { if (!vis[child]) { dfs(child); v.push_back(chi...
10
#include <bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:64000000") int j, n, l, i, h, t, mn, a[300500], f[300500], q1, q2, p1, p2, k, d[300500], m; bool b[300500]; void tg() { freopen("output.txt", "r", stdin); freopen("input.txt", "w", stdout); } int sum(int p) { if (p < 1) { return 0; ...
9
#include <bits/stdc++.h> using namespace std; const int u = 1010; char a[u][u]; int b[u], c[u], n, m, t, i, j; long long ans; inline int calc(int i) { return i * (i + 1) / 2; } void solve(int n, int m, int b[u]) { for (i = 1; i <= n; i++) if (b[i]) { ans += (b[i] - 1) * (m - b[i]) * 4; for (j = i - 1;...
17
#include <bits/stdc++.h> using namespace std; const int Maxn = 100005; int n, px[Maxn], py[Maxn], x[Maxn], y[Maxn]; bool flag[2][2]; long long ans = 0; inline int get() { char ch; while (!isdigit(ch = getchar())) ; int v = ch - 48; while (isdigit(ch = getchar())) v = v * 10 + ch - 48; return v; } int main...
23
#include<bits/stdc++.h> #pragma GCC Optimize("Ofast") #pragma comment(linker, "/STACK:102400000,102400000") using namespace std; const int N=1000005,mod=998244353; int n,m,q,ans,k,v=1,f[N],c[N],a[N],s[N][2],t[N]; vector<int>x; int fa(int x) { if(x==f[x]) return x; int y=f[x],t=fa(y); c[x]^=c[y]; return f[x]=t; } ...
23
#include <bits/stdc++.h> using namespace std; const int maxn = 2000 + 20; const int mod = 1e9 + 7; vector<int> edge[maxn]; int a[maxn], f[maxn]; bool visit[maxn]; int d; int n; void dfs(int u, int root) { visit[u] = true; f[u] = 1; for (int i = 0; i < edge[u].size(); i++) { int v = edge[u][i]; if (!visit[...
13
#include <bits/stdc++.h> using namespace std; string s; long long int N, M, T = 0; long long int t[105][55][2]; long long int f(long long int m, long long int n, long long int c) { if (m == M && n == N) return 0; if (m == M && n != N) return -10000; if (n > N) return -10000; long long int &ans = t[m][n][c]; i...
10
#include <bits/stdc++.h> int main() { double x1, y1, x2, y2, p, result = 0; scanf("%lf %lf %lf %lf", &x1, &y1, &x2, &y2); x1 = x1 / y1; x2 = x2 / y2; p = x1; while (fabs(p) > 10e-10) { result = p + result; p = p * (1 - x1) * (1 - x2); } printf("%.12lf", result = 0 ? p : result); }
5
#include <bits/stdc++.h> using namespace std; vector<long long> t; int n; void init(int nn) { n = nn; t.assign(n, 0); } long long sum(int r) { long long result = 0; for (; r >= 0; r = (r & (r + 1)) - 1) result += t[r]; return result; } void inc(int i, int delta) { for (; i < n; i = (i | (i + 1))) t[i] += de...
12
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 10; const double PI = 3.1415926535898; const int MOD = 1e9 + 7; void mod(long long &x) { x %= MOD; } long long a[N]; void solve() { int n, m; cin >> n >> m; for (int i = 1; i <= m; i++) { int u, v; cin >> u >> v; a[min(u, v)]++; } l...
6
#include <bits/stdc++.h> using namespace std; vector<pair<int, int>> arr; int n; deque<int> sta; vector<pair<int, int>> adj[2000006]; bool visited[2000006]; void dfs(int node) { while (!adj[node].empty()) { pair<int, int> nex = adj[node].back(); adj[node].pop_back(); if (!visited[nex.second]) { visi...
17
#include <bits/stdc++.h> long long mpow(long long a, long long n, long long mod) { long long ret = 1; long long b = a; while (n) { if (n & 1) ret = (ret * b) % mod; b = (b * b) % mod; n >>= 1; } return (long long)ret; } inline void read(int &x) { x = 0; register char c = getchar(); for (; c ...
7
#include<bits/stdc++.h> #define up(i) (int(v[i].size())-1) #define rep(i,l,r) for(int i=l;i<=r;i++) #define per(i,r,l) for(int i=r;i>=l;i--) using namespace std; typedef long long ll; inline int read(){ char c=getchar(); int f=1,x=0; for(;c<'0'||c>'9';c=getchar()) if(c=='-') f=-1; for(;c>='0'&&c<='9';c=getchar()) x...
19
#include <bits/stdc++.h> using namespace std; namespace Eddd { inline char sc() { return getchar(); static const int LEN = 100000; static char Buf[LEN], *OP = Buf, *ED = Buf; if (OP == ED) ED = (OP = Buf) + fread(Buf, 1, LEN, stdin); return *OP++; } template <class T> void rd(T &x) { static int c, f; x = ...
21
#include <bits/stdc++.h> using namespace std; int main() { ios_base ::sync_with_stdio(false); ; int n, cnt1 = 0, cnt2 = 0; string s; cin >> n; cin >> s; for (int i = 0; i < n; i++) { if (s[i] == 'A') cnt1++; else cnt2++; } if (cnt1 > cnt2) cout << "Anton" << endl; else if (cn...
0
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int sum = 0, n, maxx = 0, e; cin >> n; for (int i = 1; i <= n; i++) { cin >> e; if (e > maxx) maxx = e; sum = sum + e; } if (maxx > sum / 2) cout << "T" << endl; else if (sum %...
10
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 10; 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++; } int read() { int x = 0, f = 1; char ch = nc(); while ...
11
#include <bits/stdc++.h> using namespace std; struct Node { int a, b; }; Node a[1020]; bool cmp(Node a, Node b) { if (a.b == b.b) return a.a > b.a; else return a.b > b.b; } int main() { int n; while (scanf("%d", &n) != EOF) { int ans = 0; for (int i = 0; i < n; i++) scanf("%d%d", &a[i].a, &a[i...
3
#include <bits/stdc++.h> using namespace std; int main() { int n, c; cin >> n >> c; int r_max = 0; int temp, pre; cin >> pre; for (int i = 0; i < n - 1; ++i) { cin >> temp; r_max = max(r_max, pre - temp - c); pre = temp; } cout << r_max << endl; return 0; }
2
#include <bits/stdc++.h> using namespace std; const long long maxn = 202; int d[maxn][maxn]; bool b[maxn][maxn]; int stv[maxn][maxn]; int fiv[maxn][maxn]; int a1[maxn], a2[maxn], b1[maxn], b2[maxn]; queue<pair<int, int> > q; vector<pair<int, int> > g[maxn][maxn]; int n, m, h, l, r; int ind = 1; bool e = 0; int s, t; vo...
13
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t; cin >> t; while (t--) { string s; cin >> s; int d = 0, l = 0, u = 0; for (int i = 0; i < s.length(); ++i) { if (s[i] >= '0' && s[i] <= '9') { ++d; ...
4
#include <bits/stdc++.h> using namespace std; const int Max_N(250000); const int MOD(1000000007); constexpr int Add(int a, int b) { return a + b >= MOD ? a + b - MOD : a + b; } constexpr int Sub(int a, int b) { return a - b < 0 ? a - b + MOD : a - b; } constexpr int Mult(int a, int b) { return a * 1LL * b % MOD; } void...
16
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") using namespace std; mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count()); template <typename T> bool uax(T& a, T b) { if (a < b) { a = b; return true; } return false; } template <typename T> bool uin(T& a, const T b) { if (a...
6
#include <bits/stdc++.h> using namespace std; const long long mod = 998244353; const int maxn = 2e5; long long fac[maxn + 5], inv[maxn + 5]; long long pw2[maxn + 5], pwk[maxn + 5], pwk2[maxn + 5]; int n, k, num; int a[maxn + 5]; void init() { fac[0] = 1; for (int i = 1; i <= maxn; ++i) fac[i] = fac[i - 1] * i % mod...
14
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1); const int N = (int)1e6 + 7, mod = 1000000007, M = 2e9; int n, m, arr[102][102], t, x; int main() { cin >> n >> m; for (int i = 0; i < n; i++) { t = M; for (int j = 0; j < m; j++) { cin >> arr[i][j]; t = min(t, arr[i][j]); ...
2
#include <bits/stdc++.h> using namespace std; int main() { int N, K; string a; cin >> N >> K >> a; for (int i = 1; i < N && K > 0; ++i) if (a[i - 1] == '4' && a[i] == '7') if (i % 2) a[i] = '4', --K; else if (i > 1 && a[i - 2] == '4') if (K % 2) a[i - 1] = '7', K = 0; ...
7
#include <bits/stdc++.h> using namespace std; const int N = 500005, INF = 0X3F3F3F3F; int n, a[N], cnt[N], sum[N], pre[N]; int main() { scanf("%d", &n); for (int i = (1); i <= (n); ++i) scanf("%d", &a[i]), ++cnt[a[i]]; for (int i = (1); i <= (N - 1); ++i) pre[i] = cnt[i] ? i : pre[i - 1], sum[i] = sum[i - 1] ...
24
#include <bits/stdc++.h> using namespace std; using ll = long long; using pll = pair<ll, ll>; const int N = 2e5 + 5; int n, dep[N], dfn[N], ts, fa[N][20], ans[N]; pair<int, int> turn[N]; vector<int> g[N]; vector<pair<int, int>> vg[N]; void dfs(int u, int p, int d) { dep[u] = d, dfn[u] = ++ts; fa[u][0] = p; for (i...
22
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10; int n, m, k, x, y; int a[maxn]; int main() { while (~scanf("%d%d%d", &n, &x, &y)) { for (int i = 1; i <= n; i++) scanf("%d", &a[i]); for (int i = 1; i <= n; i++) { bool fa = 1; for (int j = max(1, i - x); j < i; j++) { ...
2
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e6 + 10; long long n, m, p, tot; long long cnt[MAXN], siz[MAXN]; int f[MAXN]; int getfather(int x) { return x == f[x] ? x : (f[x] = getfather(f[x])); } long long power(long long a, long long b) { long long ans = 1; while (b) { if (b & 1) ans = (ans...
17
#include <bits/stdc++.h> using namespace std; int main() { long long t; cin >> t; while (t--) { string s1, s2; cin >> s1 >> s2; long long n1 = s1.length(), n2 = s2.length(); long long i = 0, cnt = 0; vector<pair<char, long long> > v; vector<pair<char, long long> > v1; char ch = '1'; ...
4
#include <bits/stdc++.h> using namespace std; const int INF = 1000000000; const long long INFll = 1000000000000000000ll; const long double EPS = 1e-13; const int MOD = 1000000007; map<pair<int, int>, double> m; double ans(int w, int b) { if (w <= 0) return 0; if (b <= 0) return 1; pair<int, int> wb = make_pair(w,...
10
#include <bits/stdc++.h> int gcd(int a, int b) { int tmp; do { tmp = b % a; b = a; a = tmp; } while (a > 0); return b; } int main() { int a, b, tmp, na = 1, nb = 0; scanf("%d%d", &a, &b); char s1[10] = "Dasha\n"; char s2[10] = "Masha\n"; if (a > b) { tmp = a; a = b; b = tmp; ...
7
#include <bits/stdc++.h> using namespace std; int p, n; string s; string alphabet; int firstPal(vector<int> &indices) { if (indices.size() <= 1) { return -1; } for (int i = indices.size() - 3; i >= 0; i--) { if (indices[i] == indices[i + 1] or indices[i] == indices[i + 2]) { return i; } } if...
9
#include <bits/stdc++.h> int main() { int n, m, a; scanf("%d %d", &n, &m); if (m > n / 2 && n > 1) a = m - 1; else if (n > 1) a = m + 1; else a = m; printf("%d", a); }
5
#include <bits/stdc++.h> using namespace std; int t; string s; void solve() { cin >> s; int mx = 0, indx = -1, n = s.size(); for (int i = 0; i < s.size(); i++) { if (s[i] == 'R') { mx = max(mx, i - indx); indx = i; } } mx = max(mx, n - indx); cout << mx << '\n'; } int main() { ios::syn...
3
#include <bits/stdc++.h> using namespace std; int main() { string str[] = {"ABSINTH", "BEER", "BRANDY", "CHAMPAGNE", "GIN", "RUM", "SAKE", "TEQUILA", "VODKA", "WHISKEY", "WINE"}; set<string> s; for (int(n) = 0; n < (int)11; n++) s.insert(str[n]); int N; scanf("%d", &N); ; int co...
2
#include <bits/stdc++.h> using namespace std; int main() { int n, x = 10000000; cin >> n; int arr[n]; for (int i = 10000001 - n; i <= 10000000; i++) { cout << i << " "; } cout << endl; return 0; }
4
#include <bits/stdc++.h> using namespace std; const int MAXN = 4e4 + 15; int a[MAXN], lst[MAXN], n, k, s[MAXN << 2], f[55][MAXN], lzy[MAXN << 2]; inline int read() { int r = 0, z = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') z = -1; ch = getchar(); } while (ch >= '0' && ch <=...
14
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1.0); const int INF = 1000 * 1000 * 1000 + 7; const long long LINF = INF * (long long)INF; const int MAX = 2 * 100000 + 47; const int MOD = 1000 * 1000 * 1000 + 7; const int L = 27; int C[L]; string s; int k; int dp[MAX][L]; int main() { ios::sync_...
8
#include <bits/stdc++.h> using namespace std; int n, m, A[7], B[7], a, b, ans = 0; bool bio[(int)1e7 + 100]; vector<int> per; inline bool check() { bool res = true; int i; for (i = 0; i < a && A[i] == per[i]; i++) ; if (i < a && A[i] < per[i]) return false; for (i = 0; i < b && B[i] == per[i + a]; i++) ...
9
#include <bits/stdc++.h> using namespace std; const int maxn = 200005; const int maxh = 300001; struct Thash { int hash[maxh]; int next[maxn]; int num[maxn]; int key[maxn]; int hs; void Init() { memset(hash, -1, sizeof(hash)); hs = 0; } void Add(int x, int p) { int s = x % maxh; key[hs] ...
8
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; int i, j; string s; cin >> s; int num_of_zero = 0; for (i = 0; i < n; i++) { if (s[i] == '0') num_of_zero++; } if (n == 1 && k > 0) { cout << "0"; } else { j = 1; if (s[0] != '1' && k > 0) { s[0...
2
#include <bits/stdc++.h> using namespace std; int main() { int n, k = 0; cin >> n; int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 1; i < n; i++) { if (a[i] == a[i - 1] && a[i] != 3) a[i] = 0; if (a[i] == 3 && a[i - 1] != 3) a[i] = 3 - a[i - 1]; } for (int i = 0; i < n; i...
6
#include <bits/stdc++.h> using namespace std; template <class T> inline bool chkmin(T& x, T y) { return y < x ? x = y, 1 : 0; } template <class T> inline bool chkmax(T& x, T y) { return x < y ? x = y, 1 : 0; } inline long long Max(long long x, long long y) { return x > y ? x : y; } inline long long Min(long long x,...
14
#include <bits/stdc++.h> using namespace std; const int inf = 1e9; const long long mod = 1e9 + 7; int n, m; int k; int x, y; int main() { cin >> n >> m; int a[n + 111][m + 111], b[n + 111][m + 111], zz[n + 111]; memset(a, 0, sizeof(a)); memset(zz, 0, sizeof(zz)); memset(b, 0, sizeof(b)); for (int i = 1; i <...
8
#include <bits/stdc++.h> using namespace std; int n, i, j, ans; vector<int> a[90005]; inline void in(int x, int y, int z) { a[++ans].push_back(x); a[ans].push_back(y); a[ans].push_back(z); } inline void IN(int x, int y, int z, int w) { in(x, y, z); a[ans].push_back(w); } int main() { scanf("%d", &n); if (...
20