solution
stringlengths
52
181k
difficulty
int64
0
6
#include <bits/stdc++.h> using namespace std; inline void read(int &x) { int v = 0, f = 1; char c = getchar(); while (!isdigit(c) && c != '-') c = getchar(); if (c == '-') f = -1; else v = (c & 15); while (isdigit(c = getchar())) v = (v << 1) + (v << 3) + (c & 15); x = v * f; } inline void read(lo...
5
#include <bits/stdc++.h> using namespace std; int n; vector<int> adjl[200003]; long long a[200003], ans = 0; bool b[200003], c[200003]; pair<long long, long long> extra[200003]; pair<long long, long long> dfs(int now, int prev) { if (c[now] == 1 && b[now] == 0) extra[now] = {1, 0}; else if (c[now] == 0 && b[now...
5
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; while (k--) { if (n / 10) { if (n % 10) n--; else n /= 10; } else n--; } cout << n << '\n'; }
1
#include <bits/stdc++.h> using namespace std; int main() { int n, l, r; while (cin >> n >> l >> r, n | l | r) { int ans = 0; int a[n]; for (int i = 0; i < n; i++) cin >> a[i]; for (int x = l; x <= r; x++) { int f = 1; for (int i = 0; i < n; i++) { ...
0
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long t; cin >> t; while (t--) { long n; cin >> n; long arr[2 * n]; unordered_map<long, long> mp; for (int i = 0; i < 2 * n; i++) { cin >> arr[i]; mp[arr[i]]++; if (...
2
#include <cstdio> #include <algorithm> void chmin(int &a, int b) { a = std::min(a, b); } int p[50], t[50]; int dp[50][5]; const int INF = 1 << 30; int main() { int N; while(1) { scanf("%d", &N); if(N == 0) return 0; for(int i=0; i<N; i++) { scanf("%d%d", &p[i+1], &t[i+...
0
#include <bits/stdc++.h> using namespace std; vector<int> g[100006], gw[100006]; struct edge { int u, v, w, idx; }; bool cmp(edge a, edge b) { return a.w < b.w; } int fa[100006]; int n, m, sum = 0; edge edges[1000006]; int find(int n) { return (fa[n] == n ? n : (fa[n] = find(fa[n]))); } bool book[1000006]; void krusk...
5
// // Created by Happig on 2021/3/6. // #include <bits/stdc++.h> #include <unordered_map> using namespace std; #define ENDL "\n" #define lowbit(x) (x & (-x)) typedef long long ll; typedef long double ld; typedef unsigned long long ull; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef pair<double, double>...
1
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; template <typename T> void read(T &qq) { qq = 0; char ch = getchar(); long long f = 1; while (!isdigit(ch)) { if (ch == '-') f *= -1; ch = getchar(); } while (isdigit(ch)) { qq = qq * 10 + ch - 48; ch = getchar(); } ...
5
#include <bits/stdc++.h> using namespace std; int A[300010], suf2[300010], suf[300010], ans[300010], tree[1200010]; void update(int low, int high, int ind, int value, int node) { if (low == high) { tree[node] = A[low]; return; } int mid = (low + high) / 2; if (ind <= mid) update(low, mid, ind, value...
4
#include <bits/stdc++.h> using namespace std; const int N = 5005; int a[N]; int Min[N]; bool used[N]; struct node { int u; int c; }; vector<node> f[N], f2[N]; int all; int d[N]; int n; struct node2 { int loc; int val; bool operator<(const node2 it) const { return val > it.val; } }; priority_queue<node2> Q[N];...
3
#include <iostream> int x, y, z; int main() { std::cin >> x >> y >> z; std::cout << z << " " << x << " " << y; }
0
#include <bits/stdc++.h> using namespace std; using pii = pair<int, int>; const int M = 250, N = 1e6; int n, m; int32_t x[M], y[M], ans[N + 1]; int64_t intersect(int i, int j) { int64_t dx = x[j] - x[i], dy = y[j] - y[i]; if (dy == 0) return -1; if (dx == 0) return x[i]; auto t = dy * x[i] - dx * y[i]; if (t ...
2
#include <bits/stdc++.h> using namespace std; const long long INF = 1e18; const long long MOD = 1000000007; const long long MAXN = 100005; const double eps = 1e-6; long long n, m, a[1005][1005], dp1[1005][1005], dp2[1005][1005], dp3[1005][1005], dp4[1005][1005]; int main() { while (~scanf("%lld %lld", &n, &m)) { ...
2
#include<bits/stdc++.h> using namespace std; int main(){ string s;cin>>s; sort(s.begin(),s.end()); for(int i=0;i<s.size()-1;i++){ if(s[i]==s[i+1]){ cout<<"no"<<endl; return 0; } } cout<<"yes"<<endl; }
0
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c, d, e; cin >> a >> b >> c >> d >> e; int e1 = a * (b) + 2 * d; int e2 = a * (c) + 2 * e; if (e1 < e2) { cout << "First"; } else if (e1 > e2) { cout << "Second"; } else { cout << "Friendship"; } }
1
#include <bits/stdc++.h> using namespace std; const int inf = 1001001001; const int mod = 1000000007; int main() { ios::sync_with_stdio(false); cin.tie(0); int t; cin >> t; while (t--) { vector<long long> res(3); for (int i = 0; i < (3); ++i) cin >> res[i]; long long ans = 0; for (int i = 0; i...
1
#include <bits/stdc++.h> using namespace std; int main() { int n, x, counter = 0; int add = 1; bool first = true; cin >> n; string entry, edited = ""; cin >> entry; while (entry[counter] != NULL) { edited += entry[counter]; counter += add; add++; } cout << edited; }
1
#include <bits/stdc++.h> using namespace std; #define rep(i, a, b) for (int i = (a), i##end = (b); i <= i##end; ++i) #define per(i, a, b) for (int i = (a), i##end = (b); i >= i##end; --i) mt19937 Rnd(chrono::high_resolution_clock::now().time_since_epoch().count()); template <typename T> inline void chkmax(T &x, T y)...
0
#include <iostream> #include <deque> using namespace std; int main() { long long n,q; cin>>n>>q; deque < deque<int> > a(n); while(q--) { int b; cin>>b; if(b==0) { long long t,x; cin>>t>>x; a[t].push_back(x); } else if...
0
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using ii = pair<ll, ll>; using vi = vector<ll>; const ll N = 2e3 + 5; ll n; vector<vi> v(N); ll cnt[N]; ll ans[N]; ll tree[N]; ll sz[N]; void upd(ll a, ll b) { while (a <= n) { tree[a] += b; a += a & -a; } } ll sum(l...
2
#include<iostream> #include<cstdio> #include<string> #include<vector> #include<algorithm> #include<unordered_map> #include<queue> using namespace std; int ruisekiwa[10000]; int S[10001]; signed main() { int sum = 2; ruisekiwa[1] = 2; for (int i = 3; i < 10000; i++) { bool a = true; for (int j = 2; j*j <= i; j++...
0
#include<cstdio> #include<vector> #define pu push_back #define po pop_back const int mod=1000000007; int N,p[200010][19],dep[200010]; int lca(int i,int j){ int k; if(dep[i]>dep[j])k=i,i=j,j=k; for(k=19;k--;)if(dep[i]-dep[j]>>k&1)j=p[j][k]; for(k=19;k--;)if(p[i][k]!=p[j][k])i=p[i][k],j=p[j][k]; if(i!=j)i=*p[i]; re...
0
#include<cstdio> #include<algorithm> #define N 100000 using namespace std; long long A[N] = { 0 }, T[4 * N], lazy[4 * N] = { 0 }; void build(int l, int r, int k) { if (l == r) { T[k] = A[l]; return; } int mid = (l + r) / 2; build(l, mid, k * 2); build(mid + 1, r, k * 2 + 1); T[k...
0
#include <bits/stdc++.h> using namespace std; long long dp[202][202][202]; int main() { long long R, G, B; cin >> R >> G >> B; vector<long long> arrR = {LONG_LONG_MAX}, arrG = {LONG_LONG_MAX}, arrB = {LONG_LONG_MAX}; long long mx_val = 0; for (long long i = 0; i < R; i++) { long long v...
4
#include <bits/stdc++.h> using namespace std; void debug_out() { cerr << endl; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); } const int MAXN = 2e5 + 10; const int INF = 1e6; int n, m; map<pair<int, int>, bool> mp; int a[5]; bool mark[...
6
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; vector<vector<int> > V(n, vector<int>(n, 0)); vector<int> lineas(n, 0); for (int i = 1; i < n; i++) { int a, b; cin >> a >> b; a--; b--; V[a][b] = 1; lineas[a]++; } ...
3
#include <bits/stdc++.h> using namespace std; int s[41][41][41][41]; int r[41][41][41][41]; int b[41][41][41][41]; int a[41][41]; int main() { ios::sync_with_stdio(false); cin.tie(0); bool flag = false; int n, m, q; cin >> n >> m >> q; char ch; getchar(); for (int i1 = 1; i1 <= 40; i1++) for (int j1...
2
#include <bits/stdc++.h> using namespace std; constexpr long long mod = 1000000007; const long long INF = mod * mod; const long double eps = 1e-12; const long double pi = acos(-1.0); void chmin(int &a, int b) { a = min(a, b); } void chmax(int &a, int b) { a = max(a, b); } long long mod_pow(long long a, long long n, lon...
6
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, k; string a; cin >> n >> k >> a; int flag = 0; for (int i = k; i < n; i++) { if (a[i] > a[i - k]) flag = 1; else if (a[i] < a[i - k]) break; } if (flag == 1) { ...
1
#include <bits/stdc++.h> using namespace std; const double PI = 2 * acos(0.0); const string DIGITS = "0123456789"; const string ALPH = "abcdefghijklmnopqrstuvwxyz"; template <class T> ostream &operator<<(ostream &out, vector<T> &a) { out << "{"; for (auto x : a) out << x << " "; return out << "}"; } void smain();...
1
#include <bits/stdc++.h> using namespace std; int main() { int a, b, n; cin >> n >> a >> b; int k = a; if (b > 0) { for (int i = 0; i < b; i++) { k++; if (k > n) { k = 1; } } } else if (b < 0) { b = abs(b); for (int i = 0; i < b; i++) { k--; if (k < 1) k =...
1
#include <iostream> using namespace std; const int H = 10, W = 5; int board[H][W]; int main(){ int h, score, inc; while(cin >> h, h){ inc = 1; score = 0; for(int i = 0;i < h;++i){ for(int j = 0;j < W;++j){ cin >> board[i][j]; } } while(inc){ int c, k; inc = 0; for(int i = 0;i < h;++i){...
0
#include <bits/stdc++.h> using namespace std; const int N = 105; int n, p1, p2, p3, t1, t2, ans, l[N], r[N]; int main() { scanf("%d%d%d%d%d%d", &n, &p1, &p2, &p3, &t1, &t2); scanf("%d%d", &l[1], &r[1]); ans += (r[1] - l[1]) * p1; for (int i = 2; i <= n; ++i) { scanf("%d%d", &l[i], &r[i]); ans += (r[i] -...
1
#include <bits/stdc++.h> using namespace std; int n, m, q, x, y, a[1001][1001]; int main() { ios::sync_with_stdio(0); cin >> n >> m >> q; for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) cin >> a[i][j]; while (q--) { cin >> x >> y; a[x][y] = 1 - a[x][y]; int ans = 0; for (int i = 1;...
2
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c; int ans; scanf("%d%d%d", &a, &b, &c); ans = (a - b) * c; if (!(ans % b)) ans /= b; else { ans /= b; ans += 1; } printf("%d\n", ans); return 0; }
1
#include <bits/stdc++.h> using namespace std; int f[101][101]; int a[101], b[101]; int dp(int x, int y) { if (x < 0 || y < 0) return 0; if (f[x][y] >= 0) return f[x][y]; int tmp; if (abs(a[x] - b[y]) <= 1) { tmp = dp(x - 1, y - 1) + 1; } else { if (a[x] > b[y]) { tmp = dp(x - 1, y); } else {...
2
#include <bits/stdc++.h> using namespace std; int main() { int j, t, n, i; cin >> t; for (j = 0; j < t; j++) { cin >> n; cout << n << '\n'; for (i = 0; i < n; i++) { cout << i + 1 << ' '; } cout << '\n'; } return 0; }
1
#include <bits/stdc++.h> using namespace std; int n, k, q; const int M = 200010; int qzh[M], a[M], cf[M]; int main() { int z = M, y = 0; int l, r; scanf("%d%d%d", &n, &k, &q); for (int i = 1; i <= n; i++) { scanf("%d%d", &l, &r); cf[l]++; cf[r + 1]--; } for (int i = 1; i < M; i++) a[i] = a[i - 1...
2
#include <iostream> #include <vector> #include <utility> #include <cstdio> using namespace std; #define rep(i, n) for(int i = 0;i < n;i++) const int N = 10000001; bool is_prime[N]; int main() { rep(i, N) is_prime[i] = true; is_prime[0] = is_prime[1] = false; rep(i, N) { if(!is_prime[i]) continue...
0
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; map<string, string> r; for (int i = 0; i < m; i++) { string x, y; cin >> x >> y; int l1 = x.length(); int l2 = y.length(); if (l2 < l1) r[x] = y; else r[x] = x; } for (int i = 0; i < n; i+...
2
#include <bits/stdc++.h> using namespace std; int n; double x[102], y[102], z[102]; double solx, soly, solz; double dist(double _x, double _y, double _z) { double distsol = 0, curr; for (int i = 0; i < n; i++) { curr = (_x - x[i]) * (_x - x[i]) + (_y - y[i]) * (_y - y[i]) + (_z - z[i]) * (_z - z[i]);...
5
#include <bits/stdc++.h> using namespace std; signed main() { ios_base::sync_with_stdio(NULL); cin.tie(NULL); cout.tie(NULL); string s; cin >> s; long long int len = s.length(); string s1 = s; sort(s1.begin(), s1.end()); stack<char> st; char dp[len + 1]; dp[len] = 'z' + 3; for (long long int i =...
3
#include <bits/stdc++.h> using namespace std; const int MN = 1000111; int n; int dp[MN], father[MN], ln[MN], ln2[MN]; int main() { ios ::sync_with_stdio(false); cin >> n; for (int i = (2), _b = (n + 1); i <= _b; i++) { cin >> father[i]; dp[i] = 1; int u = i; while (u != 1) { if (dp[u] > ln[f...
4
#include<bits/stdc++.h> using namespace std; const int N=305; int n; double dp[N][N][N]; double dfs(int a,int b,int c) { if(!a && !b && !c) return 0; if(dp[a][b][c]) return dp[a][b][c]; if(a) dp[a][b][c]+=a/(a+b+c+0.0)*dfs(a-1,b,c); if(b) dp[a][b][c]+=b/(a+b+c+0.0)*dfs(a+1,b-1,c); if(c) dp[a][b][c]+=c/(a+b+c+0.0)...
0
#include<iostream> int main(){long long n,m;std::cin>>n>>m;std::cout<<(2*n<=m?n+(m-2*n)/4:m/2);}
0
#include <bits/stdc++.h> using namespace std; int main() { string s, t; cin >> s; bool ok = false; for (int i = 0; i < s.size(); i++) { if (s.size() - i < 26) break; int j = i; vector<int> f(26); int qq = 0; while (j < s.size() && j - i + 1 <= 26) { if (s[j] != '?') f[s[j] - 'A...
2
#include <bits/stdc++.h> using namespace std; const int maxn = 3e5 + 10; const int modd = 1e9 + 7; const int inf = 0x3f3f3f3f; long long n, q, p, x, d; long long a[maxn], b[maxn], c[maxn]; int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n; for (int i = 1; i <= n; ++i) { cin >> a[i]; } cin >> q;...
4
#include <bits/stdc++.h> using namespace std; long long calcsum(long long i, vector<long long> v) { long long n = v.size(); long long sum = 0; for (long long op = 0; op < n; ++op) { sum += abs(i - v[op]); } return sum; } int main() { long long t; cin >> t; while (t--) { string s; cin >> s; ...
4
#include <bits/stdc++.h> using namespace std; int main() { long long a, c; while (cin >> a >> c) { long long count = 0; long long sum = 0; while (a != 0 || c != 0) { int r1 = a % 3; int r2 = c % 3; if (r2 < r1) r2 += 3; sum += (r2 - r1) % 3 * pow(3.0, (double)count); count+...
2
#include <bits/stdc++.h> using namespace std; long long int gcd(long long int x, long long int y) { return y == 0 ? x : gcd(y, x % y); } bool isPalin(string x) { long long int len = x.length(); for (int i = 0; i <= (len / 2) - 1; ++i) { if (x[i] != x[len - 1 - i]) return false; } return true; } string tol...
2
#include <bits/stdc++.h> using namespace std; const int M = 2e6; int n, a[M], b[M], prv[M], rp[M]; int id[M], cnt; vector<pair<int, int>> g[M]; int dis[M]; inline void add(int u, int v, int w = 0) { g[u].emplace_back(v, w); } void build(int p, int l, int r) { if (l == r) { id[p] = l; return; } id[p] = ++c...
2
#include<bits/stdc++.h> using namespace std; string s; int ans,ansi; int main(){ cin>>s; for(int i=0;i<3;i++){ if(s[i]=='R') ansi++; if(ansi>=ans) ans=ansi; } if(s=="RSR") ans--; cout<<ans; return 0; }
0
#include <bits/stdc++.h> using namespace std; using ll = long long; const int N = 100100; int sz[N]; bool del[N]; ll sum[N]; ll ans[N]; vector<pair<int, int>> g[N]; ll dfs(int u, int p) { ll ansv = 0; for (auto e : g[u]) { if (e.first != p) { ansv += (ans[e.second] * sz[e.first] + dfs(e.first, ...
0
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 5; int n, c[maxn]; vector<int> e[maxn]; int fa[maxn], sz[maxn], son[maxn]; void dfs(int u, int f) { fa[u] = f; sz[u] = 1; for (int i = 0; i < e[u].size(); ++i) { int v = e[u][i]; if (v == f) continue; dfs(v, u); sz[u] += sz[v]; ...
5
#include <bits/stdc++.h> using namespace std; long long int n; string s; vector<pair<char, long long int>> sor; stack<char> t; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> s; for (long long int i = 0; i < (long long int)s.size(); ++i) sor.push_back(make_pair(s[i], i)); stable_sort(...
3
#include <bits/stdc++.h> const int maxn = 10; const int Mod = 1000000007; int state[maxn][maxn]; int n, m, k; int map[maxn][maxn]; long long ans = 0; int num[1 << 10], amont[15]; int two[1 << 10]; bool go[1 << 10][10]; long long dfs(int x, int y) { if (y == m) { if (x == n - 1) { return 1; } return ...
2
#include <bits/stdc++.h> using namespace std; int item[105]; int main() { int n, k, sum = 0, day = 0; bool check = 1; scanf("%d%d", &n, &k); for (int i = 0; i < n; i++) scanf("%d", &item[i]); for (int i = 0; i < n; i++) { if (item[i] > 8) { if (i < n - 1) item[i + 1] += (item[i] - 8); sum += 8...
1
#include <bits/stdc++.h> using namespace std; int N, M, K, T; int main(void) { scanf("%d%d", &N, &K); if (K <= 1 || K >= 4 || N <= 3) { cout << -1; return 0; } if (K == 2) { if (N == 4) { cout << -1; return 0; } else { printf("%d\n", N - 1); for (int i = 1; i < N; i++) pr...
5
#include <bits/stdc++.h> using namespace std; int main() { int w, h; cin >> h >> w; char c[200][200], d[200][200]; for (int i = 0; i < w; ++i) for (int j = 0; j < h; ++j) cin >> c[i][j]; for (int i = 0; i < h; ++i) { for (int j = 0; j < w; ++j) { d[i][j] = c[j][i]; } } for (int i = 0; i ...
1
#include <bits/stdc++.h> using namespace std; long n, m; map<int, int> rt; string t; long ry = 0; string p[] = {"1869", "6198", "1896", "9186", "9168", "6189", "8691"}; void df(int k) { for (int i = 1; i <= rt[k]; ++i) { ry = (ry * 10 + k) % 7; cout << k; } } int main() { cin >> t; for (int k = 0; k < t...
3
#include <bits/stdc++.h> using namespace std; int64_t mod = 1e9 + 7; int64_t log2(int64_t x, int64_t base) { return log(x) / log(base); } int64_t bin_pow(int64_t base, int64_t pow) { if (pow == 0) { return 1; } if (pow == 1) { return base; } int64_t res = bin_pow(base, pow / 2); res %= mod; res *=...
2
#include "bits/stdc++.h" #define in std::cin #define out std::cout #define rep(i,N) for(int i=0;i<N;++i) typedef long long int LL; const LL inf = 1123456789; LL N, K, cou, ans; int main() { in >> N >> K; std::vector<LL>x(N), y(N); rep(i, N) in >> x[i] >> y[i]; ans = 4123456789012345678; rep(i, N) { rep(j, N) ...
0
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int maxn = 105; inline int gi() { char c = getchar(); while (c < '0' || c > '9') c = getchar(); int sum = 0; while ('0' <= c && c <= '9') sum = sum * 10 + c - 48, c = getchar(); return sum; } int mod; inline int add(int x, int y) {return ...
0
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long n, m, p; cin >> n >> m >> p; long long t = 0; bool took = false; for (int i = 0; i < n; ++i) { long long a; cin >> a; if (a % p && !took) { t = i; took = true; ...
3
#include <bits/stdc++.h> using namespace std; int main() { int o, c, h; scanf("%d %d", &c, &o); if (o == 1 && c == 0) { printf("YES"); return 0; } else if (o > 1) { h = o - 1; if (c < h) { printf("NO"); return 0; } else { if ((c - h) % 2 == 0) { printf("YES"); ...
1
#include <bits/stdc++.h> using namespace std; map<string, int> mp; int main() { int n, id = 0; cin >> n; vector<int> a(n + 1), b(n + 1); for (int i = 1; i <= n; i++) { string tmp; cin >> tmp; if (mp[tmp] == 0) mp[tmp] = ++id; a[i] = mp[tmp]; b[i] = tmp.length() + b[i - 1]; } int cnt = b....
6
#include <bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; int n, m, bst, ci; char z[5002][5002]; vector<int> st[5002], dr[5002], sus[5002], jos[5002]; void rid(int i, int j) { if (dr[i][j] != m + 1) st[i][dr[i][j]] = st[i][j]; if (st[i][j] != 0) dr[i][st[i][j]] = dr[i][j]; if (sus[i][j] != 0) jos[s...
3
#include <bits/stdc++.h> using namespace std; int main() { long long t; cin >> t; while (t--) { long long a, b; cin >> a >> b; long long x = abs(a - b); long long cnt = 0, inc = 0; while (cnt + 5 <= x) { long long d = x - cnt; long long z = d / 5; cnt += z * 5; inc += z...
1
#include <bits/stdc++.h> using namespace std; const int M = 1000000007; const int N = 1001; const int oo = 1e9; const double pi = acos(-1); int main() { int n; cin >> n; map<int, int> mp; for (int i = 0; i < n * n; ++i) { int x; cin >> x; ++mp[x]; } priority_queue<pair<int, int>> pr; for (auto...
3
#include <bits/stdc++.h> using namespace std; const int inf_int = 1e8; const long long inf_ll = 1e16; const double pi = 3.1415926535898; bool debug = 0; const int MAXN = 1e5 + 10; const int LOG = 20; const int mod = 1e9 + 7; vector<int> g[MAXN]; int tin[MAXN]; int tout[MAXN]; int timer; int up[MAXN][LOG]; int h[MAXN]; ...
5
#include <bits/stdc++.h> using namespace std; struct seg_tree { long long seg[4 * 200009]; pair<long long, long long> arr[200009]; void construct_segtree(int start, int end, int pos) { if (end == start + 1) seg[pos] = start; else { int mid = (start + end) / 2; construct_segtree(start, mi...
4
#include <bits/stdc++.h> using namespace std; int a[1000], l, r; int main() { long long n, m; cin >> n >> m; l = 0, r = n - 1; for (int i = 1; i <= n; ++i) { int rem = n - i; if (rem == 0) { a[l] = i; } else { long long tmp = (1LL) << (rem - 1); if (tmp >= m) { a[l++] = i; ...
2
#include <bits/stdc++.h> using namespace std; using ll = long long; int const N = 100 * 1000 + 16; int n; int a[128]; int b[110][1 << 17]; int dp[110][1 << 17]; int p[60]; int main() { cin.tie(0); cin.sync_with_stdio(0); cin >> n; for (int i = 1; i <= n; ++i) cin >> a[i]; for (int i = 2, k = 0; i < 60; ++i) {...
4
#include <bits/stdc++.h> using namespace std; const int N = 1e6, M = 25; vector<int> v[M]; int s[N], cnt[N]; bool dp[N]; int main() { int n, m, d; cin >> n >> m >> d; for (int i = 0; i < m; i++) { int t; cin >> t; for (int j = 0; j < t; j++) { int a; cin >> a; s[a] = i; } } f...
4
#include<cstdio> int main() { long long a; while(scanf("%lld",&a)==1) { if(a==0)break; long long res=1ll; for(long long i=2;i*i<=a;i++) { long long t=0; if(a%i==0) { while(a%i==0) { a=a/i;...
0
#include <bits/stdc++.h> using namespace std; const long long int inf = 1e18; const long long int mod = 1e9 + 7; signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL), cout.tie(NULL); long long int n, d, h, p, m, i, r; cin >> n >> d >> h; if (h > n - 1 || d < h || d - h > h) cout << -1 << endl; ...
2
#include <bits/stdc++.h> inline int read() { char c; int x; for (c = getchar(); !isdigit(c); c = getchar()) ; for (x = 0; isdigit(c); c = getchar()) { x = x * 10 + c - '0'; } return x; } const int mod = 1e9 + 7; const int dx[8] = {1, 1, -1, -1, 2, 2, -2, -2}; const int dy[8] = {2, -2, 2, -2, 1, -1, ...
3
#include <bits/stdc++.h> using namespace std; string s[1005]; int main() { int n; cin >> n; for (int i = 0; i < n; i++) { cin >> s[i]; } bool flag = 0; for (int i = 0; i < n; i++) { if (s[i][0] == 'O' && s[i][1] == 'O') { flag = 1; s[i][0] = '+'; s[i][1] = '+'; break; } e...
1
#include <bits/stdc++.h> int main() { long long n, h, k, s; scanf("%I64d", &n); h = 0; if ((n + 1) % 3 == 0) h++; s = 7; k = 5; for (s = 7; s <= n; s = s + k) { if ((n - s) % 3 == 0) h++; k = k + 3; } printf("%I64d\n", h); return 0; }
3
#include <bits/stdc++.h> using namespace std; bool vstd[150004] = {0}; vector<vector<int> > v; int cnt = 0; int DFS(int i) { if (vstd[i]) return 0; vstd[i] = true; cnt++; for (int j = 0; j < v[i].size(); j++) { int q = v[i][j]; if (!vstd[q]) DFS(q); } return cnt; } int n, m; int main() { ios_base:...
2
#include <bits/stdc++.h> using namespace std; static const double EPS = 1e-9; static const double PI = 3.141592653589793238462643383279; int main() { int rept; scanf("%d", &rept); static int ans[100010]; int n, i; int a, o; long long all, cnt; for (int loopCount = 1; loopCount <= (rept); loopCount++) { ...
3
#include <bits/stdc++.h> using namespace std; int p[111111], h[111111], d[111111]; vector<vector<int>> g; int f(int w, int x, int k) { d[x] = k; int m = -1; for(int y : g[x]) { if(y == w) continue; p[y] = x; m = max(m, f(x, y, k + 1)); } return h[x] = m + 1; } in...
0
#include <bits/stdc++.h> long long a[100] = {1}, ans[100]; int main() { int s, k, i = 0, cnt = 0; scanf("%d%d", &s, &k); long long d = 1, sum = 0; while (a[i] < s) { if (i < k) { a[++i] = d; d += a[i]; } else { a[i + 1] = 2 * a[i] - a[i - k]; ++i; } } if (s == a[i]) { ...
2
#include<cstdio> #include<cstring> #include<algorithm> using namespace std; #define maxn 1000005 char s[maxn],t[maxn]; int n,cnt,ans; struct Vergil { int x,y; }a[maxn],b[maxn]; bool comp(char *s,char *t) { for (int i=1;i<=n;i++) if (s[i]!=t[i]) return 0; return 1; } bool check(int x) { for (int i=1;i<=cnt-x;...
0
#include <bits/stdc++.h> using namespace std; long long dp[1005][1005][2]; bool ban[1005][1005]; void solve() { int n, m, q; cin >> n >> m >> q; long long ans = 0; for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { dp[i][j][0] = dp[i - 1][j][1] + 1; dp[i][j][1] = dp[i][j - 1][0] + 1; ...
5
#include <bits/stdc++.h> using namespace std; int main(int argc, char* argv[]) { int n, k, t, x; cin >> n >> k >> t; for (x = 0; x <= n * k; ++x) if (100 * x > n * k * t) { x--; break; } for (int i = 0; i < n; ++i) { cout << " " << min(x, k); x -= min(x, k); } cout << endl; ret...
2
#include <bits/stdc++.h> using namespace std; int main() { int n, x; int a[1001]; bool hasPred[1001] = {}; cin >> n >> x; for (int i = 1; i <= n; ++i) { cin >> a[i]; if (a[i] != 0) { hasPred[a[i]] = true; } } int lengths[1000]; int size = 0; for (int i = 1; i <= n; ++i) { if (!ha...
2
#include <bits/stdc++.h> using namespace std; int main(){ int n,a; cin>>n; for(int i=0;i<n;i++){ cin>>a; if(a%2==0&&a%3&&a%5)cout<<"DENIED\n",exit(0); } cout<<"APPROVED\n"; }
0
#include <iostream> #include <algorithm> using namespace std; #define N 100 int main() { int n; cin >> n; int p[N + 1], m[N + 1][N + 1]; for (int i = 0; i < n; i++) { cin >> p[i] >> p[i + 1]; } for (int i = 1; i <= n; i++) { m[i][i] = 0; } for (int l = 2; l <= n; l++) { for (int i = 1; i <= n - l + 1; i+...
0
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n, W; cin >> n >> W; vector<long long> dp(1<<17, 1ll<<60); dp[0] = 0; for (int i = 1; i <= n; ++i) { int w, v; cin >> w >> v; for (int j = (1<<17) - 1; j >= v; --j) { dp[j] = min(dp...
0
#include <bits/stdc++.h> using namespace std; struct Team { int id, univ, ac, pen; Team(int id, int univ, int ac, int pen) : id(id), univ(univ), ac(ac), pen(pen){} Team(){} bool operator < (const Team x) const { if (ac != x.ac) return (ac < x.ac); if (pen != x.pen) return (pen > x.pen); return (id > x.id); ...
0
#include <bits/stdc++.h> using namespace std; int lft[26]; char s[111111], t[111111]; int n, m; int main() { gets(s); n = (int)strlen(s); for (int i = 0; i < n; ++i) lft[s[i] - 'a']++; gets(t); m = (int)strlen(t); for (int i = 0; i < n; ++i) { bool fnd = 0; for (int let = 0; let < 26; ++let) { ...
4
#include <bits/stdc++.h> using namespace std; int main() { long long a, b, c, p; cin >> a >> b >> c; p = sqrt(a * b * c); a = p / a; b = p / b; c = p / c; cout << (4 * (a + b + c)); }
1
#include <bits/stdc++.h> using namespace std; long long getF(int numb) { long long ans = 1; for (int i = 2; i <= numb; i++) ans *= i; return ans; } int main() { string str; cin >> str; int cnt = 0; set<char> st; int pow10 = 0; for (int i = 0; i < str.size(); i++) { if (str[i] >= 'A' && str[i] <= '...
1
#include <bits/stdc++.h> using namespace std; vector<int> f[1000007]; int nivel[1000007]; void go(int curr, int l) { nivel[l]++; for (int i = 0; i < f[curr].size(); i++) { go(f[curr][i], l + 1); } } int main(int argc, char const *argv[]) { int n; cin >> n; for (int i = 1; i < n; i++) { int x; ci...
1
#include <bits/stdc++.h> using namespace std; void solve(map<int, int>& m, int n) { int mx = n / 2; int cnt = 0, g = 0, s = 0, b = 0; if (n < 6 || m.size() < 3) cout << s << " " << b << " " << g << endl; else { auto itr = m.begin(); g = itr->second; itr++; s = itr->second; itr++; whi...
1
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; const int inf = 1e9; const long long INF = 1e18; const double PI = acos(-1.0); const double EPS = 1e-8; const int MOD = 1000000007; struct Point { int x, y; Point() {} Point(int x, int y) : x(x), y(y) {} }; struct Line { int a, b, c; Line() ...
1
#include <bits/stdc++.h> using namespace std; long long int n; char s[100008]; long long int i, a[1000], b[100]; long long int sum; int main() { cin >> s; n = strlen(s); for (i = 0; i < n; i++) if (s[i] >= 'a' && s[i] <= 'z') a[s[i] - 'a']++; for (i = 0; i < n; i++) if (s[i] >= '0' && s[i] <= '9') b[s[i...
2
#include <iostream> using namespace std; int main(void){ int a,b,g=100,h=0,j = 0; for(int i = 0; i < 4; i++){ cin >>a; g = min(g,a); j = j + a; } j = j - g; for(int i = 0; i < 2; i++){ cin >>b; h = max(h,b); } cout<<j + h<<endl; }
0