solution
stringlengths
52
181k
difficulty
int64
0
6
#include <bits/stdc++.h> using namespace std; const int N = 5e5 + 100; int num[N]; bool vis[N]; vector<int> v; int n, k; int main() { scanf("%d %d", &n, &k); int mn = 1e9 + 100; for (int i = 1; i <= n; i++) { scanf("%d", &num[i]); if (num[i] < mn) { mn = num[i]; vis[i] = true; v.push_bac...
6
#include <bits/stdc++.h> using namespace std; const int MOD = 1000000007; long long fac[13]; int n, nunknown; int a[100000]; int r[100000]; bool done[100000]; int todo[12], ntodo; int sumtodo[1 << 12], cnttodo[1 << 12]; int cnt[100001]; bool twoswaps; long long cur; int nval; int atval[100001]; int nxtval[1000000]; int...
5
#include <bits/stdc++.h> using namespace std; int N, Q; int dp[10005]; vector<int> Adj0[10005], Adj1[10005]; bool ans[10005]; void printDP() { cout << "%%%%%%% coutDP" << endl; for (int i = 1; i <= N; i++) cout << dp[i] << " "; cout << endl; } int main() { cin >> N >> Q; int l, r, x; for (int i = 1; i <= Q;...
5
#include <bits/stdc++.h> int main() { int x, i; scanf("%d", &x); if (x < 0) x = -x; for (i = 0; i * (i + 1) < 2 * x; i++) ; if ((i % 4 == 0 && x % 2 == 1) || (i % 4 == 2 && x % 2 == 0)) i++; else if ((i % 4 == 1 && x % 2 == 0) || (i % 4 == 3 && x % 2 == 1)) i += 2; printf("%d", i); return 0;...
2
#include <bits/stdc++.h> using namespace std; long long n, t, i, d, a, b; int main() { cin >> t; for (i = 1; i <= t; i++) { cin >> a >> b; d = abs(a - b); if (d % 10 == 0) cout << d / 10 << endl; else cout << d / 10 + 1 << endl; } return 0; }
1
#include <bits/stdc++.h> using namespace std; long long N, A[200005]; vector<long long> v, v2; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> N; for (long long i = 0; i < N; i++) { cin >> A[i]; if (A[i] == 0) { v.push_back(i); v2.push_back(-i); } } sort(v.begin(), v.en...
2
#include <bits/stdc++.h> using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); mt19937_64 rng_64(chrono::steady_clock::now().time_since_epoch().count()); const double PI = 2 * acos(0.0); const string DIGITS = "0123456789"; const string ALPH = "abcdefghijklmnopqrstuvwxyz"; istream &op...
6
#include <bits/stdc++.h> #define rep(i, a, n) for(int i = a; i < n; i++) #define REP(i, n) rep(i, 0, n) #define repb(i, a, b) for(int i = a; i >= b; i--) #define all(a) a.begin(), a.end() #define int long long #define chmax(x, y) x = max(x, y) #define chmin(x, y) x = min(x, y) using namespace std; typedef pair<int, int...
0
#include<bits/stdc++.h> using namespace std; #define rep(i,n) for(l i=0;i<(l)(n);i++) #define l int64_t #define A(a) (a).begin(),(a).end() #define mp make_pair l O=1e9+7; l N,M,X,Y,Z,K,a=0; vector<l> p,m; l r(l X){return p[X]==X?X:p[X]=r(p[X]);} void u(l X,l Y){X=r(X);Y=r(Y);p[X]=Y;} l mo(l a,l n){l r=1;while(n){if(n&1...
0
#include <bits/stdc++.h> using namespace std; const long long mod = (long long)1e9 + 7; const int maxn = (int)1e6 + 5; const long long INF = 0x7fffffff; const long long inf = 0x3f3f3f3f; const double eps = 1e-8; void f() {} template <typename T> void read(T &w) { char c, k = 1; while (!isdigit(c = getchar())) c == ...
3
#include<cstdio> #include<map> #include<algorithm> using namespace std; #define MAXN 100000 long long h,w,ans[10]; int n,x[MAXN+5],y[MAXN+5]; map<pair<int,int>,int>Map; void Updata(int x,int y) { if(x<3||x>h||y<3||y>w) return ; int cnt=0; for(int i=-2;i<=0;i++) for(int j=-2;j<=0;j++) cnt+=Map[make_pair(x+i,y+...
0
#include <iostream> #include<bits/stdc++.h> using namespace std; typedef long long ll; ll Q,n,a,b,ans; priority_queue<ll> que; priority_queue<ll,vector<ll>,greater<ll>> que2; int main(void){ cin>>Q; while(Q--){ cin>>n; if(n==1){ cin>>a>>b; ans+=b; que.push(a);...
0
#include <bits/stdc++.h> using namespace std; string s; bool iscon(char c) { if (c != 'a' && c != 'e' && c != 'u' && c != 'i' && c != 'o') { return 1; } return 0; } string ans = ""; int lst = 0; void solve(int ind) { for (int i = ind; i < s.length() - 2; i++) { ans += s[i]; char c1 = s[i]; char ...
1
#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); } long long int lcm(long long int a, long long int b) { return b * a / gcd(a, b); } long long int abs1(long long int a) { if (a < 0) return -1 * a; else retur...
1
#include <bits/stdc++.h> using namespace std; template <typename T1, typename T2> istream &operator>>(istream &in, pair<T1, T2> &p) { in >> p.first >> p.second; return in; } template <typename T> istream &operator>>(istream &in, vector<T> &v) { for (auto &x : v) in >> x; return in; } template <typename T1, type...
4
#include<bits/stdc++.h> using namespace std; int main(){ int N,L;cin>>N>>L; int ans=0; for(int i=0;i<N;i++)ans+=L+i; if(L>0)ans-=L; else if(L+N-1<0)ans-=L+N-1; cout<<ans<<endl; }
0
#include <bits/stdc++.h> using namespace std; long long n, a, b; bool possible(long long x1, long long y1, long long x2, long long y2) { if ((x1 + x2) <= a && max(y1, y2) <= b) { return true; } else if (max(x1, x2) <= a && (y1 + y2) <= b) { return true; } else if (max(x1, y2) <= a && (y1 + x2) <= b) { ...
3
#include <bits/stdc++.h> using namespace std; void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); solve(); return 0; } long long gcd(long long a, long long b) { if (b == 0) return a; return gcd(b, a % b); } long long q, n, p[200001], e[200001], x, a, y, b, k; bool good(long long m...
3
#include <bits/stdc++.h> using namespace std; long long int n, m, s, cnt[5007]; bool g[5007], vis[5007]; vector<long long int> adj[5007]; void dfs(long long int x) { if (!g[x]) { cnt[x] = 1; } vis[x] = 1; for (long long int i : adj[x]) { if (!vis[i]) { dfs(i); cnt[x] += cnt[i]; } } } v...
5
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; ++i) { cin >> a[i]; } vector<int> pos_diff(5002, 0); vector<int> neg_diff(10010, 0); long double all1 = 0; long double all2 = 0; for (int i = 0...
4
#include <bits/stdc++.h> using namespace std; int const N = 1000 + 10; int const M = (1 << 16) + 10; int const inf = 0x7f7f7f7f; int a[5], n; char mp[5][N]; int dp[2][M]; vector<int> p[5]; void Init() { for (int i = 1; i <= 4; i++) { for (int j = 0; j + i <= 4; j++) { int v = (1 << 16) - 1; for (int r...
6
#include <bits/stdc++.h> using namespace std; int n, s0, s1, a[100010]; bool check(int k) { int l = a[n] - k, r = a[n] + k; for (int i = n - 1; i >= 1; i--) { if (l <= a[i] && a[i] <= r) l = a[i] - k, r = a[i] + k; int l0 = a[i] - k, r0 = a[i] + k; l = max(l, l0); r = min(r, r0); if (l > r) retu...
5
#include <bits/stdc++.h> using namespace std; const int MAXN = 1024; const long long INF = 1e18; int N, M; long long rare[MAXN][MAXN]; long long row[MAXN], col[MAXN]; int main() { ios_base::sync_with_stdio(false); cin.tie(0), cout.tie(0), cout.precision(15); cin >> N >> M; for (int i = 0; i < N; i++) { for ...
2
#include <bits/stdc++.h> using namespace std; const int maxn = 1010; map<int, int> cnt, tmp_cnt; vector<int> used; int a[maxn]; int main() { int n; scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d", a + i); cnt[a[i]]++; tmp_cnt[a[i]]++; } int ans = 0; for (int i = 1; i <= n; i++) { ...
4
#include <bits/stdc++.h> using namespace std; int main() { int n, i, t, n1 = 0; cin >> n; multiset<int> a; for (i = 0; i < n; ++i) { cin >> t; a.insert(t); if (t == 1) n1++; } if (n1 == 1 && n == 1) { cout << "2" << endl; return 0; } cout << "1"; multiset<int>::iterator it = a.begi...
1
#include <bits/stdc++.h> using namespace std; int dp[2][2010]; int N, K; int main() { cin >> N >> K; for (int i = 1; i <= N; i++) dp[1][i] = 1; for (int i = 1; i < K; i++) { for (int j = 1; j <= N; j++) dp[(i + 1) % 2][j] = 0; for (int j = 1; j <= N; j++) { for (int k = 1; k * j <= N; k++) d...
2
#include <bits/stdc++.h> using namespace std; bool equal(string s) { int n = 0; for (int i = 0; i < s.length(); i++) { if (s[i] == 'a') n++; } if (n * 2 != s.length()) return false; return true; } string s, s1, sex; int n, d, k; int main() { cin >> k; cin >> s; n = s.length(); sex = s; for (int ...
1
#include <bits/stdc++.h> using namespace std; long long c[1000001]; long long a, b, k, m; vector<long long> v; int main() { cin >> a >> b >> k; for (int i = 2; i <= b; i++) { if (c[i] == 0) { if (i >= a) v.push_back(i); for (int j = i * 2; j <= b; j += i) c[j] = 1; } } if (v.size() < k) { ...
3
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { long long int n; cin >> n; if (n % 10 == 9) cout << n / 10 + 1 << '\n'; else cout << n / 10 << '\n'; } return 0; }
1
#include <bits/stdc++.h> using namespace std; int n, q; vector<long long> v; string s; int type[100100]; long long num[100100]; long long dat[400100][5]; int cnt[400100]; int branches; void combine(int a, int b, int c) { cnt[a] = cnt[b] + cnt[c]; for (int i = 0; i < 5; i++) dat[a][i] = dat[b][i]; int g = cnt[b] %...
4
#include <bits/stdc++.h> using namespace std; bool func(pair<int, int> a, pair<int, int> b) { if (a.first > b.first) return false; else if (a.first == b.first) { if (a.second >= b.second) return false; else return true; } } int main() { ios_base::sync_with_stdio(false); cin.tie(0); c...
1
#include <bits/stdc++.h> using namespace std; int main() { int n, m, i, j, k, l; cin >> n >> k; for (int i = k - 1; i >= 0; i--) { if (n % i == 0) { cout << i + (n / i) * k; return 0; } } }
2
#include <bits/stdc++.h> using namespace std; int f(int a) { int ret = 0; while (a != 0) { ret++; a /= 10; } return ret; } const int dydis = 100000; long long blockSz[dydis] = {0}; vector<int> toVec(int a) { vector<int> ret; while (a != 0) { ret.push_back(a % 10); a /= 10; } reverse(ret....
5
#include <bits/stdc++.h> using namespace std; const double PI = 2.0 * acos(0.0); const int MOD = 1e9 + 9; const int oo = 2e9 + 1e8; long long gcd(long long x, long long y) { return !y ? x : gcd(y, x % y); } int main() { long long n, cnt, ret; scanf("%I64d", &n); ret = 1, cnt = 0; for (long long i = 2; i * i <= ...
3
#include <bits/stdc++.h> using namespace std; int main() { int q; cin >> q; while (q--) { vector<int> va; vector<int> vb; int a, b, c, d; int ta = 0, tb = 0; cin >> a >> c >> b >> d; int aa = a, bb = b; while (a) { va.push_back(a % 10); a /= 10; ta++; } revers...
1
#include <bits/stdc++.h> using namespace std; string s; int n, k; int main(){ cin>>n>>k>>s; s[k-1]+=32; cout<<s<<endl; }
0
#include <stdio.h> long long pre[100005]; long long find_root(long long x) { if(pre[x] == x) return x; return find_root(pre[x]); } int main() { long long n, q; while(scanf("%lld%lld", &n, &q), n || q) { pre[1] = 1; for(long long i = 2; i <= n; i++) scanf("%lld", &...
0
#include <bits/stdc++.h> using namespace std; int main() { int n; int d; cin >> n >> d; string s; cin >> s; int b[n]; int k[n]; for (int i = 0; i < n; i++) { b[i] = n + 1; } b[0] = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < i; j++) { if (s[i] == '0') break; el...
1
#include <bits/stdc++.h> using namespace std; double EPS = 1e-9; long long t1, t2, x1, x2, t0; long long a1 = 0, a2 = 0; double diff = 1e20; long long rate = 0; long long up = 1LL << 30, dn = 1; long long Comp(long long a1, long long b1, long long a2, long long b2) { return a1 * b2 - b1 * a2; } int main() { cin >> ...
1
#include <bits/stdc++.h> using namespace std; int _2[4], _3[4], c[4]; long long a[4]; int main() { for (int i = 0; i < 4; ++i) { cin >> a[i]; } for (int i = 0; i < 4; ++i) { while ((2 * a[i]) % 3 == 0) ++_3[i], a[i] = (2 * a[i]) / 3; } for (int i = 0; i < 4; ++i) { while (a[i] % 2 == 0) ++_2[i], a...
4
#include<iostream> #include<algorithm> using namespace std; int main() { int n, a[100]; int al = 0; cin >> n; for (int i = 0;i < n;i++) { cin >> a[i]; al += a[i]; } sort(a, a+n); for (int i = n-2;i >= 0;i-=2) { al -= 2*a[i]; } cout << al << endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; int n, k; int main() { scanf("%d", &n); k = 0; bool flag = true; for (; n; n--) { int dist; string dir; scanf("%d", &dist); cin >> dir; if (dir == "North") { k -= dist; if (k < 0) { flag = false; break; } } e...
2
#include <bits/stdc++.h> using namespace std; const int maxN = 105; int n, a[maxN], res1, res2, cnt; bool cmp(int a, int b) { return a > b; } int main() { ios_base::sync_with_stdio(false); scanf("%d", &n); for (int i = 1; i <= n; ++i) { int m, x; scanf("%d", &m); if (m % 2 == 1) { for (int j = 1...
5
#include <bits/stdc++.h> using namespace std; int main() { int n; deque<long> dq; long a; long long s1 = 0, s2 = 0, s3 = 0; cin >> n; for (int i = 0; i < n; i++) { cin >> a; dq.push_back(a); } int l = dq.size(); while (l > 0) { if (s1 == s2) { s3 = s1; s1 = s1 + dq.front(); ...
3
#include <bits/stdc++.h> using namespace std; int main() { int tc, o; scanf("%d", &tc); for (o = 1; o <= tc; o++) { long long n, m, a, b, c, d, e, f, g, p, q, r, fr, sc, tr, sz, tz, sz1, sz2, i, j, k, mx = -9, mn = 999999999999; string str, ttr, ntr; long long x = 0, y = 0, cnt = 0, res = -3, ...
2
#include <bits/stdc++.h> using namespace std; int n, m; struct ac { int x, y; } t[202400]; bool cmp(const ac &a, const ac &b) { if (a.x != b.x) { return a.x < b.x; } else { return a.y < b.y; } } bool wfHas(int x, int y) { int l = 0, r = m - 1, mid; while (l < r) { mid = (l + r) / 2; if (t[mi...
2
#include <bits/stdc++.h> int main() { int n, i; scanf("%d", &n); if (n % 4 == 0) { for (i = 1; i <= n / 2; i += 2) { printf("%d %d ", i + 1, n + 1 - i); } for (i = n / 2 + 2; i < n; i += 2) { printf("%d %d ", n + 1 - i, i - 1); } printf("%d %d\n", n + 1 - i, i - 1); } else if (n ...
3
#include <bits/stdc++.h> using namespace std; inline int circRight(int a, unsigned m) { return (a >> m) | (a << (CHAR_BIT - m)); } inline int circLeft(int a, unsigned m) { return (a << m) | (a >> (CHAR_BIT - m)); } const int ERR = 1e-5; const int MOD = 1000000007; const int MAX = 100005; int main() { int n, k; ...
2
#include <bits/stdc++.h> int n; int x[100001], y[100001]; long long s, ds, bds; long double ans; long long cj(long long x1, long long y1, long long x2, long long y2) { return x1 * y2 - x2 * y1; } int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } int abs(int a) { return a < 0 ? -a : a; } int ma...
4
#include <bits/stdc++.h> using namespace std; const int c=200002, sok=2e9; long long t[c], kom[c], h[c], ki[c], n, m, maxi; priority_queue<pair<long long, int> > q; vector<pair<long long, int> > ans; // atlag, kezd int holvan(int a) { if (!ki[a]) { return a; } return ki[a]=holvan(ki[a]); } void un...
2
#include <bits/stdc++.h> int main() { int a[100][100], b[100][100]; int na, ma, nb, mb; scanf("%d%d", &na, &ma); for (int i = 0; i < na; i++) for (int j = 0; j < ma; j++) scanf("%1d", &a[i][j]); scanf("%d%d", &nb, &mb); for (int i = 0; i < nb; i++) for (int j = 0; j < mb; j++) scanf("%1d", &b[i][j])...
2
#include <bits/stdc++.h> using namespace std; long long n, A[100100], C[100100]; long long p, q; long long gcd(long long a, long long b) { if (b == 0) return a; return gcd(b, a % b); } int main() { cin >> n; for (int i = 1; i <= n; i++) { scanf("%d", &A[i]); } sort(A + 1, A + n + 1); for (int i = 1; i...
1
#include <bits/stdc++.h> using namespace std; int main() { int a, b; string s,t,u; cin >> s >> t; cin >> a >> b >> u; if(u==s)a--; else b--; cout << a << " " << b ; }
0
#include <bits/stdc++.h> using namespace std; template <typename T> T BigMod(T b, T p, T m) { if (p == 0) return 1; if (p % 2 == 0) { T s = BigMod(b, p / 2, m); return ((s % m) * (s % m)) % m; } return ((b % m) * (BigMod(b, p - 1, m) % m)) % m; } template <typename T> T ModInv(T b, T m) { return BigMo...
1
#include<bits/stdc++.h> #define ll long long using namespace std; ll gcd(ll x,ll y){ if(!y)return x; return gcd(y,x%y); } int main(){ ll t1,A,B,C,D,hh,x,y; scanf("%lld",&t1); while(t1--){ scanf("%lld%lld%lld%lld",&A,&B,&C,&D);C++; if(B>D){ puts("No");continue; } if(A<C){ if(A<B){ puts("N...
0
#include <bits/stdc++.h> using namespace std; void solve() { int n, k; cin >> n >> k; string s; cin >> s; string t = ""; string l = "()"; int auxk = k; while (auxk > 1) { t += l; auxk--; } int szt = t.size(); for (int i = 0; i < (n - szt) / 2; i++) t += '('; for (int i = 0; i < (n - szt)...
3
#include <bits/stdc++.h> using namespace std; int getnum(const string& s, char arr[], int k) { int ans = 0; for (int i = 0; i < k; ++i) { ans *= 10; ans += s[arr[i]]; } return ans; } int main() { int n, k; scanf("%d%d", &n, &k); char arr[100]; string sarr[10]; for (int i = 0; i < n; ++i) { ...
2
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 10; int n; int A[MAXN], sol[MAXN]; int main() { cin >> n; for (int i = 0; i < n; i++) { cin >> A[i]; } sort(A, A + n); sol[0] = A[n - 1]; sol[n - 1] = A[n - 3]; sol[1] = A[n - 2]; for (int i = 2; i < n - 1; i++) { sol[i] = A[n ...
2
#include <bits/stdc++.h> int a, b, yue[100000], l[10100], h[10100], p[10100], ans[10100], gs, c, n; void qsort(int x, int y) { int i, j, t, mid; i = x; j = y; mid = yue[(i + j) / 2]; do { while (yue[i] < mid) i++; while (yue[j] > mid) j--; if (i <= j) { t = yue[i]; yue[i] = yue[j]; ...
3
#include <bits/stdc++.h> using namespace std; bool right(int ds_ab, int ds_bc, int ds_ac) { if (ds_ab == (ds_ac + ds_bc)) { return true; } if (ds_bc == (ds_ac + ds_ab)) { return true; } if (ds_ac == (ds_ab + ds_bc)) { return true; } return false; } int main() { vector<pair<int, int> > coor; ...
1
#include <bits/stdc++.h> using namespace std; struct node { int l, r, x; void read() { scanf("%d%d%d", &l, &r, &x); } }; vector<node> level[7001]; int n, m; const int maxnum = 1000000; int many[maxnum]; void init() { for (int i = 1; i < maxnum; i++) { many[i] = many[i - 1]; if (i & (i - 1)) continue; ...
2
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> S_vec(n); for (int i = 0; i < n; ++i) cin >> S_vec.at(i); int q; cin >> q; int cnt = 0; int t; for (int i = 0; i < q; ++i) { cin >> t; auto it = lower_bound(S_vec.begin(), S_vec.end(), t); if (it != S_vec.end() && ...
0
#include <iostream> using namespace std; int fib(int n); int main() { int n; int dp[45]; dp[0] = 1; dp[1] = 1; cin >> n; for(int i = 2; i <= n; i++) { dp[i] = dp[i-1] + dp[i-2]; } cout << dp[n] << endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; int len[27][27] = {0}; int main() { string s; char ch[20]; int n, ans = 0; cin >> n; for (int i = 0; i < n; i++) { scanf("%s", ch); s = ch; for (int j = 0; j <= 'z' - 'a'; j++) { int t; if (j != s[0] - 'a' && len[j][s[0] - 'a'] == 0) contin...
1
#include <bits/stdc++.h> using namespace std; vector<long long> v; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t; cin >> t; while (t--) { long long a, b; cin >> a >> b; if (b > a) { if ((b - a) % 2 == 1) cout << "1" << endl; else cout << "2" << end...
1
#include<iostream> using namespace std; typedef long long ll; #define INF 1LL<<60 ll f(ll b, ll n){ if(b<2) return INF; ll ret=0; while(n>=b){ ret+=n%b; n/=b; } return ret+n; } int main(){ ll n,s; cin >> n >> s; if(s==n){ cout << n+1 << endl; return 0; } ll ans=INF; for(ll i=2;i*i<=n;i++){ if(f(i...
0
#include <bits/stdc++.h> int N, M; bool grid[500][500]; int X1, X2, Y1, Y2; int main() { std::cin >> N >> M; bool flag = false; int lastx, lasty; for (int i = 0; i < N; i++) { char ch; for (int j = 0; j < M; j++) { std::cin >> ch; if (ch == '.') grid[i][j] = false; if (ch == 'X') { ...
2
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; cout << (n >= 30 ? "Yes" : "No") << endl; }
0
#include<bits/stdc++.h> #define to edge[i].v #define mp make_pair #define rint register int #define debug(x) cerr<<#x<<"="<<x<<endl #define fgx cerr<<"-------------"<<endl #define N 1000000 using namespace std; typedef long long ll; typedef long double db; typedef pair<int,int> pii; unordered_map<ll,int> f; int head[N]...
0
#include <bits/stdc++.h> const long long N = 400005; long long pos[N], dfn[N], tin[N], tout[N], dep[N], vd[N << 2], vl[N << 2], vr[N << 2], maxd[N << 2], vlca[N << 2], lm[N << 2], mr[N << 2], lmr[N << 2], tag[N << 2], head[N], vet[N], next[N], len[N], val[N], num, fa[N][20], deep[N], s[N << 2], t[N << 2]; l...
2
#include<iostream> #include<algorithm> using namespace std; int main() { int w, n; int a[31]; cin >> w >> n; for (int i = 1; i <= w; i++){ a[i] = i; } int x, y; char t; for (int i = 0; i < n; i++){ cin >> x >> t >> y; swap(a[x], a[y]); } for (int i = 1; i <= w; i++){ cout << a[i] << endl; } }
0
#include <bits/stdc++.h> using namespace std; int main() { int t; scanf("%d\n", &t); while (t--) { long n; int flag = 1; scanf("%ld\n", &n); string s; getline(cin, s); vector<char> t(n), b(n); for (int i = 0; i < n; i++) { if ((s[i] == '2') || (s[i] == '0')) { if (flag) {...
3
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; if (n % 2 == 0) { cout << "white" << endl; cout << 1 << " " << 2 << endl; } else { cout << "black" << endl; } return 0; }
4
#include<stdio.h> #include<algorithm> using namespace std; int now[30]; int to[30]; int main(){ int a,b; int T=0; while(scanf("%d%d",&a,&b),a){ for(int i=0;i<30;i++)now[i]=0; now[0]=a; int t=0; while(1){ t++; for(int i=0;i<a;i++){ to[i]=0; } for(int i=0;i<a;i++){ to[i+1]+=now[i]/2; to...
0
#include <bits/stdc++.h> using namespace std; int pow(int a, int b) { int ans = 1; for (int i = 0; i < b; i++) { ans = ans * a; } return ans; } int main(int argc, char const *argv[]) { for (int I = 0; I < 1; I++) { int n; cin >> n; vector<int> v; for (int i = 0; i < n; i++) { int a; ...
1
#include <bits/stdc++.h> using namespace std; class Point { public: double x, y; Point(double x = 0, double y = 0) : x(x), y(y) {} Point operator+(Point p) { return Point(x + p.x, y + p.y); } Point operator-(Point p) { return Point(x - p.x, y - p.y); } Point operator*(double a) { return Point(x * a, y * a); ...
6
#include<bits/stdc++.h> using namespace std; int main(){ string a; long double b,s=0.000000; int c; cin>>c; while(c--){ cin>>b>>a; if(a[0]=='J') s=s+b; else{ s=s+(b*380000.0); } } cout<<s<<endl; return 0;}
0
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c; cin >> a >> b >> c; cout << (2 * max(a, max(b, c)) == (a + b + c) ? "Yes" : "No") << endl; }
0
#include <bits/stdc++.h> using namespace std; int n, m; string ans[] = {"abc", "acb"}; string a[2][3] = {{"ab", "bc", "ca"}, {"ac", "ba", "cb"}}; string s[2]; void prin1(string s, int n) { for (int i = 0; i < n; i++) cout << s; exit(0); } void prin(char x, int n) { for (int i = 0; i < n; i++) cout << x; } int mai...
5
#include<stdio.h> #include<iostream> #include<string> #include<math.h> using namespace std; bool G[80001]={}; int main(){ for(int i=3;i<80000;i+=2){G[i]=true; for(int j=3;j*j<=i;j++) if(i%j==0){G[i]=false;break;} } G[2]=true; int N; while(cin>>N){ for(int i=N-1;i>0;i--) if(G[i]==true){cout<<i; br...
0
#include <bits/stdc++.h> using namespace std; int main(){ int N,K; cin >> N >> K; vector<int> A(N); for(int i=0;i<N;i++) cin >> A[i]; for(int i=K;i<N;i++){ if(A[i]>A[i-K]) cout << "Yes" << endl; else cout << "No" << endl; } return 0; }
0
#include <bits/stdc++.h> using namespace std; int main() { string cadena1; int cont = 0, cont1 = 0; getline(cin, cadena1); for (int i = 0; i < cadena1.size(); i++) { if (cadena1[i] == cadena1[i + 1]) { cont1++; } if (cadena1[i] != cadena1[i + 1]) { cont++; cont1 = 0; } if (...
1
#include <bits/stdc++.h> using namespace std; int intlog(double x) { return (int)(log(x) / log(2)); } bool check(long long int x) { long long int n = x, y = 0; while (x > 0) { y = y * 10 + x % 10; x = x / 10; } if (y == n) { return true; } else { return false; } } int main() { ios_base::sy...
1
#include <bits/stdc++.h> using namespace std; struct node { int a, i; } p[110]; int cmp(node x, node y) { return x.a < y.a; } int main() { int n, k, num; while (scanf("%d %d", &n, &k) != EOF) { num = 0; int i; for (i = 0; i < n; i++) { cin >> p[i].a; p[i].i = i + 1; } sort(p, p + n...
1
#include <bits/stdc++.h> using namespace std; const int inf = 998244353; string to_string(string s) { return '"' + s + '"'; } string to_string(const char* s) { return to_string((string)s); } string to_string(bool b) { return (b ? "true" : "false"); } template <typename A, typename B> string to_string(pair<A, B> p) { ...
5
#include <bits/stdc++.h> using namespace std; const int maxn = 1e3; int n; struct point { int x, y; }; struct rr { point dl, gd; } rec[maxn + 10]; bool srt_x1(rr a, rr b) { return a.dl.x < b.dl.x; } bool srt_x2(rr a, rr b) { return a.gd.x < b.gd.x; } bool srt_y1(rr a, rr b) { return a.dl.y < b.dl.y; } bool srt_y2(r...
5
#include <bits/stdc++.h> using namespace std; int main() { int x, y, x1, y1, x2, y2, max; cin >> x >> y; max = abs(x) + abs(y); if (x > 0 and y > 0) { x2 = max; y2 = 0; x1 = 0; y1 = max; } else if (x < 0 and y > 0) { x1 = -max; y1 = 0; x2 = 0; y2 = max; } else if (x > 0 and y...
1
#include <bits/stdc++.h> using namespace std; const int MAX_N = 100003; int a[MAX_N]; int sg_val[MAX_N]; int get_sg(int x, int k) { if (k % 2 == 0) { if (x >= 3) { if (x % 2 == 0) return 1; else return 0; } else if (x == 0) return 0; else if (x == 1) return 1; e...
3
#include <bits/stdc++.h> using namespace std; const long long N = 1e6 + 7; const long long M = 21; long long INF = 1e18; long long n; long long d[(1 << M)]; long long cnt[M][M]; vector<long long> col[M]; int32_t main() { ios::sync_with_stdio(0); cin >> n; for (long long i = 0; i < n; i++) { long long x; c...
5
#include <iostream> using namespace std; int main(){ int n,m; cin>>n>>m; int a=n*(n-1)/2 + m*(m-1)/2; cout<<a<<endl; }
0
#include <bits/stdc++.h> using namespace std; int main() { long long int n; cin >> n; long long int m1, m2; if (n <= 2) cout << "-1\n"; else if (n % 2 == 1) cout << (n * n) / 2 << " " << (n * n) / 2 + 1 << endl; else if (n % 4 == 0) cout << (n / 4) * 3 << " " << (n / 4) * 5 << endl; else { ...
3
#include <bits/stdc++.h> const int N = 1000010; std::vector<int> e[N]; bool vis[N]; int main() { int n, m; scanf("%d%d", &n, &m); for (int i = 0, u, v; i < m; ++i) { scanf("%d%d", &u, &v); e[u].push_back(v); } std::stack<int> stack; for (int i = 1; i <= n; ++i) { if (!vis[i]) { vis[i] = tr...
3
#include <bits/stdc++.h> using namespace std; long long n, maxx = 0, x, sum = 0; long long ans; int main() { cin >> n; for (int i = 0; i < n; i++) { cin >> x; sum += x; maxx = maxx > x ? maxx : x; } ans = sum % (n - 1) != 0 ? 1 : 0; ans += sum / (n - 1); cout << max(maxx, ans); return 0; }
3
#include <bits/stdc++.h> using namespace std; using ll = long long; #define REP(i,n) for (ll i = 0, i##_len = (n); i < i##_len; i++) int main() { ll n; cin >> n; vector<ll> a(n); REP(i, n) cin >> a[i]; vector<ll> dp(n-1, -1); for (ll ai : a) { if (dp[ai % (n-1)] == -1) { dp[ai...
0
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; long long arr[n]; for (int i = 0; i < n; i++) { cin >> arr[i]; } int onecount[n]; memset(onecount, 0, sizeof(int) * n); for (int i = 0; i < n; i++) { while (arr[i] > 0...
5
#include <bits/stdc++.h> using namespace std; int f; int n, m; char a; int main() { cin >> n >> m; for (int j = 0; j < n; j++) { for (int i = 0; i < m; i++) { cin >> a; if (a == 'C' || a == 'M' || a == 'Y') { f = 1; break; } } if (f == 1) { break; } } if (...
1
#include <bits/stdc++.h> using namespace std; int main() { int x1, x2, y1, y2; cin >> x1 >> y1; cin >> x2 >> y2; cout << max(abs(x2 - x1), abs(y2 - y1)) << endl; }
1
#include <bits/stdc++.h> using namespace std; int32_t main() { ios::sync_with_stdio(false); long long n; cin >> n; vector<long long> a(n); map<long long, long long> m; long long cnt = 0; for (long long i = 0; i < n; ++i) cin >> a[i]; for (long long i = 0; i < n; ++i) { m[a[i]]++; cnt = max(cnt, ...
1
#include <bits/stdc++.h> #pragma GCC optimize("Ofast", "unroll-loops", "omit-frame-pointer", "inline") #pragma GCC option("arch=native", "tune=native", "no-zero-upper") #pragma GCC target("avx2") #pragma GCC optimize("03") using namespace std; template <typename T> struct ST { vector<T> st; int sz; bool ty; ST(...
6
#include <stdio.h> #include <algorithm> long long n, m, x, ans; long long a[2000]; long long dp[2001]; long long e[2001]; int main() { scanf("%lld", &n); for (long long i = 0; i < n; i++) { scanf("%lld", a + i); a[i] = a[i] * 10000 + i; } std::sort(a, a + n); for (long long i = n - 1; i >= 0; i--) { for (lon...
0