solution
stringlengths
52
181k
difficulty
int64
0
6
#include <bits/stdc++.h> using namespace std; int main() { long long N, H; cin >> N >> H; long long a, b[N], A = 0, B = 0, answer = H; for (int i = 0; i < N; i++) { cin >> a >> b[i]; A = max(A,a); } sort(b,b+N,greater<long long>()); for (int i = 0; i < N; i++) { B += b[i]; answer = min(ans...
0
#include<bits/stdc++.h> #define ll long long using namespace std; int main(){ ll n,i,key,j; cin>>n; vector<ll> a(n+1); for(i=0;i<n;i++){ cin>>a[i]; } for(i=0;i<n;i++){ key=a[i]; j=i-1; while(j>=0 && a[j]>key){ a[j+1]=a[j]; j--; } a[j+1]=key; for(j=0;j<n-1;j++){ cout<<a[j]<<" "; ...
0
#include <bits/stdc++.h> #pragma comment(linker, "/stack:225450978") #pragma GCC optimize("Ofast") using namespace std; const long long Mod = 1000000007LL, INF = 1e9, LINF = 1e18; const long double Pi = 3.141592653589793116, EPS = 1e-9, Gold = ((1 + sqrt(5)) / 2); long long keymod[] = {1000000007LL, 1...
2
#include<bits/stdc++.h> using namespace std; int main() { int n, m, l; cin >> n >> m >> l; long long sp[n + 1][n + 1], G[n + 1][n + 1]; for(int i = 0 ; i <= n ;i ++){ for(int j = 0 ; j <= n ; j ++){ sp[i][j] = 1e18; G[i][j] = 1e18; } } for(int i = 0 ; i <= n ; i ++ ){ sp[i][i] = 0; } for(int i = 0 ...
0
#include <bits/stdc++.h> using namespace std; const int N = 200005; long long n, s, cnt[N], son[N]; bool check(long long x) { long long now = 1, dep = 1, sum = 0, cnt = 0; while (cnt + now <= n) { sum += now * dep; cnt += now; now *= x; dep++; } long long rest = n - cnt; sum += rest * dep; r...
3
#include <bits/stdc++.h> using namespace std; const int INF = 1e9 + 7; int dp[15][15][2], len, sum[15]; bool mark[15][2]; char as[15]; void dfs(int x, bool ok) { if (mark[x][ok]) return; if (x == len + 1) { dp[x][0][ok] = 1; return; } mark[x][ok] = 1; if (ok) { for (int w(0); w <= as[x] - 48 - 1; ...
2
#include <bits/stdc++.h> using namespace std; const int maxn = 1e3 + 10; int a[maxn], n, x; bool mark[maxn]; vector<int> v; int can[maxn][maxn], x_bood, pos_x; vector<int> adj[maxn]; int dfs_visit(int v, int cnt) { if (!v) return 0; if (v == x) x_bood = cnt + 1; mark[v] = 1; for (int i = 0; i < adj[v].size(); i...
2
#include <bits/stdc++.h> using namespace std; int n, c[51], pos[2501][3], a[51][51], change[2501][5], sum; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d", &c[i]); for (int i = 1; i <= n; i++) for (int j = 1; j <= c[i]; j++) scanf("%d", &a[i][j]), pos[a[i][j]][1] = i, pos[a[i][j]][...
2
#include <stdio.h> #include <stdbool.h> void judge(int ye, int mo, int da) { int sum = 10000 * ye + 100 * mo + da; if (sum < 18680908) { printf("pre-meiji\n"); } else if (sum < 19120730) { printf("meiji %d %d %d\n", ye - 1867, mo, da); } else if (sum < 19261225) { printf("taish...
0
#include <bits/stdc++.h> using namespace std; void print(int x1, int y1, int x2, int y2) { printf("? %d %d %d %d\n", x1, y1, x2, y2); fflush(stdout); } int x11, x12, y11, y12, x21, x22, y21, y22; int n; void solvex() { int l, r, cnt; l = 1, r = n; while (r - l > 1) { int m = (r + l) / 2; print(1, 1, m...
4
#include <bits/stdc++.h> using namespace std; const int N = 100005; int n, x, y, q, o[N]; double p[N], c[N], z, fp; vector<int> v[N]; void sgd(int dg, int op) { o[dg] = op; for (int i = 0; i < v[dg].size(); ++i) { if (v[dg][i] != op) { sgd(v[dg][i], dg); c[dg] += p[v[dg][i]]; } } fp -= p[dg]...
4
#include <bits/stdc++.h> int main() { int i, n; scanf("%d", &n); for (i = 0; i < n; i++) { long long int x; long long int k, y; scanf("%I64d %I64d", &k, &x); y = x + 9 * (k - 1); printf("%I64d", y); printf("\n"); } }
2
#include <bits/stdc++.h> using namespace std; int main() { int w,h,x,y,r;cin>>w>>h>>x>>y>>r; if(x<r||y<r)cout<<"No"<<endl; else if(x+r>w||y+r>h)cout<<"No"<<endl; else cout<<"Yes"<<endl; }
0
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; if (n % 5 == 0) cout << n / 5; else cout << n / 5 + 1; return 0; }
1
#include <bits/stdc++.h> using namespace std; constexpr int MOD = 998244353; constexpr int MAXN = 3e5 + 3; using ll = long long; ll N, M, K, T; int is_like[MAXN]; ll w[MAXN]; ll dp[3003][3003]; ll FastPow(ll x, ll exp) { ll ret = 1; while (exp) { if (exp & 1) { ret = ret * x % MOD; } x = x * x % M...
3
#include <bits/stdc++.h> using namespace std; const int mod = 256; int getNum(char tch) { int num = tch; char ch[10]; int cnt = 0; while (cnt < 8) { ch[cnt++] = num % 2 + '0'; num /= 2; } num = 0; for (int i = 0; i < 8; i++) { num = num * 2 + (ch[i] - '0'); } return num; } int main() { c...
1
#include <bits/stdc++.h> using namespace std; struct Event { int when, type, info, i; Event() { when = type = i = 0; } Event(int iwhen, int itype, int iinfo, int ii) { when = iwhen; type = itype; info = iinfo; i = ii; } bool operator<(const Event &a) const { if (when != a.when) return when...
2
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1.0); template <typename T, typename U> inline void amin(T &x, U y) { if (y < x) x = y; } template <typename T, typename U> inline void amax(T &x, U y) { if (x < y) x = y; } template <typename T> inline void write(T x) { int i = 20; char buf[...
1
#include <bits/stdc++.h> using namespace std; long long int power(long long int a, long long int b) { if (b == 1) return a; if (b == 0) return 1; long long int t = power(a, b / 2); if (b % 2) { return (a * ((t * t) % 1000000007)) % 1000000007; } return (t * t) % 1000000007; } long long int fact[100005];...
4
#include <bits/stdc++.h> using namespace std; char a[105][105] = {}; int main() { long long m, n, i, j, k; long long p = 1000000007; while (cin >> m >> n) { for (i = 0; i < m; i++) scanf("%s", a[i]); long long b[105] = {}; for (j = 0; j < n; j++) { int num[100] = {}; long long o = 0; ...
3
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); long long int n, m, i; cin >> n >> m; long long int a[m]; for (i = 0; i < m; i++) cin >> a[i]; sort(a, a + m); i = 1; if (binary_search(a, a + m, 1) || binary_search(a, a + m, n)) cout << "NO"; else {...
2
#include <bits/stdc++.h> using namespace std; int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a); } vector<vector<pair<int, int> > > dict; vector<pair<int, pair<int, int> > > arr, depart; vector<int> best; long long totdep[1000050], totarr[1000050]; int main() { int n, m, k; int mxDay = 0; sca...
4
#include<iostream> #include<string> #include<sstream> using namespace std; int main() { long i, n[1001] = { 0 }, n2[1001] = { 0 }, nn; string s; stringstream ss; while (getline(cin, s)) { if (s == "") break; ss.str(""); ss << s; ss >> nn; n[nn]++; } while (getline(cin, s)) { if (s == "") break; ...
0
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long n, q, i, j, u, l, r, t, lev, h; cin >> n >> q; h = log2(n + 1); long long a[h], d[h]; for (i = 0; i < h; ++i) a[i] = (1ll << (h - i - 1)), d[i] = (1ll << (h - i)); while (q--) { ...
4
#include<bits/stdc++.h> #define rep(i,x,y) for (int i=(x);i<=(y);i++) using namespace std; const int N=10; int x,y,rd[N],cnt[N]; int main(){ rep (i,1,3) scanf("%d%d",&x,&y),rd[x]++,rd[y]++; rep (i,1,4) cnt[rd[i]]++; if (cnt[1]==2&&cnt[2]==2) puts("YES"); else puts("NO"); return 0; }
0
#include <bits/stdc++.h> using namespace std; int a[100001]; int main() { int n; cin >> n; int l = -1e9; int r = 1e9; for (int i = 0; i < n; i++) cin >> a[i]; string s; cin >> s; for (int i = 4; i < n; i++) { if (s[i - 1] == s[i - 2] && s[i - 2] == s[i - 3] && s[i - 4] == s[i - 3] && s[i - 1...
4
#include<bits/stdc++.h> using namespace std; int N, K, sh; char sir[1000009]; int main () { //freopen ("input", "r", stdin); //freopen ("output", "w", stdout); scanf ("%d %d\n", &N, &K); scanf ("%s", sir + 1), sh = 0; for (int i=1; i<=N; i++) sir[i] -= 'A'; while (K && sh < N) { K --; if ((sir[1 + sh] ^...
0
#include <bits/stdc++.h> using namespace std; int n, k = 0; string ans; vector<string> words; void split(string line) { int j = 0; words.push_back(""); for (int i = 0; i < line.size(); i++) { if (line[i] != ' ') words[j] += line[i]; else { j++; words.push_back(""); } } } void dfs()...
3
#include <bits/stdc++.h> using namespace std; mt19937_64 gen(chrono::high_resolution_clock::now().time_since_epoch().count()); template <typename T> T randInt(T min, T max) { uniform_int_distribution<T> dist(min, max); return dist(gen); } template <typename T> T randDouble(T min, T max) { uniform_real_distributio...
2
#include <bits/stdc++.h> using namespace std; long long Set(long long N, long long pos) { return N = N | (1 << pos); } long long reset(long long N, long long pos) { return N = N & ~(1 << pos); } bool check(long long N, long long pos) { return (bool)(N & (1 << pos)); } void CI(long long &_x) { scanf("%I64d", &_x); } voi...
1
#include <bits/stdc++.h> using namespace std; const int MAXN = 2 * 1e5; const int INF = 1e9 + 7; int n, f[MAXN], a[MAXN]; int main() { ios::sync_with_stdio(false); cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; f[1] = 2; for (int i = 2; i <= n; i++) { f[i] = 2; for (int j = a[i]; j <= i - 1; j++)...
4
#include <bits/stdc++.h> using namespace std; void func(void) { freopen("input.c", "r", stdin); freopen("output.c", "w", stdout); } long long n, k, m, d; int prob; long long f(long long dd) { long long low = (dd - 1) * k + 1; long long high = dd * k; if (low > 3e18) { prob = 1; return -10000LL; } ...
3
#include <bits/stdc++.h> using namespace std; template <typename Arg1> void __f(const char* name, Arg1&& arg1) { std::cerr << name << " : " << arg1 << '\n'; } template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args) { const char* comma = strchr(names + 1, ','); std::cerr...
1
#include <bits/stdc++.h> #define ll long long using namespace std; int main() { int n; string s; cin >> n >> s; int l = -1, r = n; for (int i = 0; i < n; i++) { if (s[i] == '>') { r = min(r, i); } else { l = max(l, i); } } cout << max(n - r, l...
0
#include <bits/stdc++.h> int main() { unsigned long long a, b; scanf("%I64u%I64u", &a, &b); if (a < b) { puts("-1"); return 0; } unsigned long long dif = a - b; unsigned long long x = 0, y = 0; for (int i = 0; i < 64; ++i) { int u = a >> i & 1, v = b >> i & 1, carry = dif >> (i + 1) & 1; i...
4
#include <bits/stdc++.h> using namespace std; struct elem { long double l, r, total, sum; }; const int oo = 3e5; int a[oo]; int p[oo]; long double mo[oo]; elem b[oo * 2]; elem q; elem sum(elem a, elem b) { elem c; c.sum = a.sum + b.sum; c.l = max(a.l, a.sum + b.l); c.r = max(b.r, b.sum + a.r); c.total = max...
3
#include <bits/stdc++.h> using namespace std; template <class T> inline void gmin(T &a, T b) { if (a > b) a = b; } template <class T> inline void gmax(T &a, T b) { if (a < b) a = b; } inline int sign(const double &a) { return a > 1e-9 ? 1 : (a < -1e-9 ? -1 : 0); } struct Initializer { Initializer() { ios::syn...
2
#include <bits/stdc++.h> using namespace std; struct Point { int x, y; } arr[8]; int Orientation(Point p1, Point p2, Point p3) { int val = ((p2.y - p1.y) * (p3.x - p2.x)) - ((p3.y - p2.y) * (p2.x - p1.x)); if (val > 0) return 1; if (val < 0) return 2; if (val == 0) return 0; } bool Onsegment(Point p1, Point p...
3
#include <iostream> #include <sstream> #include <cstdio> #include <cstring> #include <cstdlib> #include <cmath> #include <ctime> #include <vector> #include <string> #include <map> #include <set> #include <deque> #include <queue> #include <stack> #include <functional> #include <algorithm> using namespace std; #define ...
0
#include <bits/stdc++.h> using namespace std; #define mod 998244353 #define MOD 1000000007 #define inf 0x3f3f3f3f #define linf 0x3f3f3f3f3f3f3f3fll typedef long long ll; typedef pair<int,int> pii; typedef unsigned long long ull; int n; ll H[5050],P[5050]; vector<pair<ll,int> > od; ll dp[5050][5050]; int main() { scanf...
0
#include <bits/stdc++.h> using namespace std; string s[205]; int ans[205]; void cal(int x, int low) { int n = s[x].size(); for (int i = low + 1; i <= 10; ++i) { for (int j = 0; j < (1 << i); ++j) { string tmp = ""; for (int k = 0; k < i; ++k) { if ((j >> k) & 1) { tmp += "1"; ...
4
#include <bits/stdc++.h> using namespace std; int a[55], b[55], cro[55], n, g; long long fin[55]; int main() { scanf("%d", &n); for (int i = 0; i < n - 1; i++) scanf("%d", &a[i]); for (int i = 0; i < n - 1; i++) scanf("%d", &b[i]); for (int h = 0; h < n; h++) { scanf("%d", &cro[h]); int j = 0; long ...
2
#include<bits/stdc++.h> using namespace std; using Face=array<array<char,3>,3>; void flip(Face& s){ Face tmp; for(int i=0;i<3;i++){ for(int j=0;j<3;j++){ tmp[i][j]=s[2-i][j]; } } s=tmp; } void flipL(Face& s){ Face tmp; for(int i=0;i<3;i++){ for(int j=0;j<3;j...
0
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using pii = pair<int, int>; constexpr int N = 5e3 + 5; ll dp[4][N], n, sum = 0, dif = 0; ll pref[N]; tuple<int, int, int> par[4][N]; void Solve() { cin >> n; for (int i = 1, val; i <= n; i++) { cin >> val; pref[i] = ...
3
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 4; long long ans = -1; long long n, sum, a[N], s[N]; void read() { cin >> n; for (int i = 1; i <= n; ++i) { cin >> a[i]; s[i] = s[i - 1] + a[i]; } sum = s[n]; } bool notPrime(long long x) { if (x == 1) { return true; } for (long...
5
#include <bits/stdc++.h> using namespace std; struct Usr { int n; double a, b, h; }; bool operator<(const Usr& l, const Usr& r) { return ((l.h == r.h) ? (l.n > r.n) : (l.h < r.h)); } int main() { vector<Usr> usrs; int n; double t1, t2, k; cin >> n >> t1 >> t2 >> k; usrs.resize(n); for (int i = 0; i < ...
2
#include "iostream" #include "algorithm" #include "cstring" #include "cstdio" #include "cmath" #include "vector" #include "map" #include "set" #include "queue" #include "string" using namespace std; #define MAXN 3000006 //#define int long long #define rep( i , a , b ) for (int i = (a), i##end = (b); i <= i##end; ++i) ...
0
#include <bits/stdc++.h> using namespace std; long a[200005] = {0}; long b[200005] = {0}; long pos[200005] = {0}; long ans[200005] = {0}; long event[200005] = {0}; long cmp(long x, long y) { return x - pos[b[x]] < y - pos[b[y]]; } map<long, long> t1, t2; int main() { long n; long i, j; scanf("%ld", &n); for (i ...
3
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t, n, n2, i; cin >> t; while (t-- > 0) { cin >> n; n2 = n; int a[n]; for (i = 0; i < n; i++) { cin >> a[i]; } sort(a, a + n); for (i = n - 1; i >= 0; i--) { i...
2
#include <bits/stdc++.h> using namespace std; template <typename T> int size(T &a) { return (int)a.size(); } template <typename T> T sqr(T a) { return a * a; } const int INF = (int)1e9; const long long mod = INF + 9; struct node { int nxt[4]; int link; int parent; char pchar; bool leaf; void init() { ...
3
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using pii = pair<int, int>; using pll = pair<ll, ll>; using vi = vector<int>; const ll INF = 100000000000ll; const int N = 200005; const int prime = 31; const ll mod = 1000000007; const ld eps = 1e-5; mt19937_64 strong_random( ...
3
#include<bits/stdc++.h> using namespace std; int main(){ string a,b; cin>>a>>b; if(a[1]==b[1] && a[0] == b[2] && a[2]==b[0]){ cout<<"YES"; } else{ cout<<"NO"; } return 0; }
0
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; long long dp[500005] = {0}; dp[3] = 8; long long fac = 2; for (long long i = 5; i <= 500000; i += 2) { dp[i] = dp[i - 2] + fac * (i + i + i - 2 + i - 2); ++fac; } ...
3
#include <bits/stdc++.h> using namespace std; const int N = 123460, INF = 1e7; int n, m, s, tot, maxd[N][2], pre[N], up[N], val[N]; vector<int> ed[N]; bool good[N], mark[N]; void dfs1(int u) { for (int to : ed[u]) { if (pre[u] == to) continue; pre[to] = u; dfs1(to); if (!good[to]) continue; good[u...
4
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; const long long INF = 1e18; using P = pair<long long, long long>; template <typename T> void chmin(T &a, T b) { if (a > b) a = b; } template <typename T> void chmax(T &a, T b) { if (a < b) a = b; } void pmod(long long &a, long long b) { a ...
4
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int t; cin >> t; while (t--) { long long int n; cin >> n; long long int x = 4 * n + 1; long long int p = pow(x, 0.5); long long int k = (p + 1) / 2; bool flag = false; ...
3
#include <bits/stdc++.h> using namespace std; struct Node { int s; pair<int, int> e[26]; }; int N; Node trie[300001]; int precalc(int n) { trie[n].s = 1; for (int i = int(0); i < int(26); i++) { if (~trie[n].e[i].first) trie[n].s += precalc(trie[n].e[i].second); } return trie[n].s; } int merge(Node &l, ...
3
#include <iostream> using namespace std; char field[3][3]; void check() { for (int i = 0; i < 3; ++i) { if (field[i][0] != '+' && field[i][0] == field[i][1]) { if (field[i][1] == field[i][2]) { cout << field[i][2] << endl; return; } } } for (int i = 0; i < 3; ++i) { if (field[0][i] != '+' && field[0...
0
#include <bits/stdc++.h> using namespace std; struct Segment { int a, b; Segment(int a, int b) { this->a = a; this->b = b; }; bool operator<(const Segment &s2) const { if (a != s2.a) return a < s2.a; else return b < s2.b; } int size() { return b - a + 1; } int max_ships(int aa)...
4
#include <bits/stdc++.h> using namespace std; const int N = 6e6; int n, ans, m; bool ok; bool mark[N], obr[N], used[N], del[N]; int cnt, ord[N]; int getint() { char c = getchar(); while (!isdigit(c)) c = getchar(); int x = 0; while (isdigit(c)) { x = x * 10 + c - '0'; c = getchar(); } return x; } vo...
3
#include <bits/stdc++.h> using namespace std; const int MAX = 100001; long long arr[MAX]; int main() { ifstream fin("IO.txt"); int n; cin >> n; for (int i = 0; i < n; i++) cin >> arr[i]; int h; cin >> h; for (int i = 0; i < h; i++) { int w, hh; cin >> w >> hh; if (arr[0] > arr[w - 1]) co...
3
#include <bits/stdc++.h> using namespace std; const int MOD = 1000000007; const int INF = 2000000000; const long long BIG = 1446803456761533460LL; const int maxn = 500010; int n, par[maxn], ht[maxn], fact[maxn], from[maxn], to[maxn], rot[maxn * 4]; vector<int> g[maxn]; struct Chain { int a, b, k; } chs[maxn * 4]; map...
5
#include <bits/stdc++.h> using namespace std; bool flag[1111111]; int main() { const int m = 1000000; int n; scanf("%d", &n); for (int i = 0; i < n; i++) { int x; scanf("%d", &x); flag[x] = true; } vector<int> ans, tmp; int cnt = 0; for (int i = 1; i * 2 <= m; i++) { int j = m + 1 - i; ...
2
#include <bits/stdc++.h> using namespace std; int i, j, m = 0, s = 1, n, z = 0; string a; int main() { cin >> n >> a; for (i = n / 2; i > 0; i--) if (a[i] == a[0]) { for (j = 1; j < i; j++) if (a[i + j] == a[j]) ++s; else break; if (i == j) { m++; ...
2
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 9; const int inf = 1e9 + 7; int n, k, a, b, ans; int d[N]; vector<int> v; int main() { ios_base::sync_with_stdio(0); cin.tie(0), cout.tie(0); cin >> n >> a >> b >> k; for (int i = 1; i <= n; i++) { cin >> d[i]; if (d[i] % (a + b) > a) { ...
4
#include <bits/stdc++.h> using namespace std; const int maxn = 100005; int n, h[maxn], ans[maxn]; int main() { ios::sync_with_stdio(false); cin >> n; for (int i = 1; i <= n; i++) cin >> h[i]; int _max = h[n]; for (int i = n - 1; i >= 1; i--) { if (h[i] > _max) ans[i] = 0; else ans[i] = _ma...
2
#include <bits/stdc++.h> using namespace std; int main(){ long long A,B,C,K; cin >> A >> B >> C >> K; if(A+B >= K) cout << min(K,A) << endl; else cout << A-(K-A-B) << endl; }
0
#include <bits/stdc++.h> using namespace std; int neigh[(int)1e6]; int vis[(int)1e6]; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); memset(vis, 0, sizeof(vis)); int n, second, t; cin >> n >> second >> t; for (int i = 0; i < n; i++) { int a; cin >> a; neigh[i + 1] = a; } in...
2
#include <bits/stdc++.h> using namespace std; const int N = 10005; const int M = 200005; struct seg { long long x, r; int id; } s[N]; bool cmp(seg a, seg b) { return a.x < b.x; } bool is_in(long long x, long long r, long long xx, long long yy) { if ((x - xx) * (x - xx) + yy * yy <= r * r) { return true; } e...
3
#include <bits/stdc++.h> using namespace std; template <typename T> bool chmin(T &a, const T &b) { return a > b ? a = b, true : false; } template <typename T> bool chmax(T &a, const T &b) { return a < b ? a = b, true : false; } const int maxN = 2000 + 5; const int P = 1000000007; int n, m; char b[maxN][maxN]; int s...
5
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; vector<int> v(n); vector<pair<int, int> > vp; for (int i = 0; i < n; i++) cin >> v[i]; for (int i = 0; i < n; i++) { for (int j = i; j < n; j++) { vp.push_back(make_pair(i, j)); } } vector<int> res; int c...
1
#include <bits/stdc++.h> using namespace std; int whereIstheDiff(string s1, string s2) { int cnt = 0; while (s1[cnt] == s2[cnt]) cnt++; return cnt; } int areLexi(vector<string> table) { for (int i = 0; i < table.size() - 1; i++) if (table[i] > table[i + 1]) return whereIstheDiff(table[i], table[i + 1]); r...
1
#include <bits/stdc++.h> using namespace std; int mx1, mx2, mark[11], a[11]; int main() { int n, m; cin >> n >> m; for (int i = 0; i < n; i++) { cin >> a[i]; mark[a[i]]++; } for (int i = 0; i < m; i++) { int x; cin >> x; mark[x]++; } for (int i = 0; i < n; i++) { if (mark[a[i]] > 1...
1
#define _CRT_SECURE_NO_WARNINGS #include <string> #include <vector> #include <algorithm> #include <numeric> #include <set> #include <map> #include <queue> #include <iostream> #include <sstream> #include <cstdio> #include <cmath> #include <ctime> #include <cstring> #include <cctype> #include <cassert> #define rep(i,n) f...
0
#include <bits/stdc++.h> using namespace std; using ll = long long; ll n; ll ans; ll a[100000]; int main() { cin >> n; for (ll i = 1; i <= n; i++) { cin >> a[i]; } ll maxn = *max_element(a + 1, a + 1 + n); for (ll i = 1; i <= n; ++i) { ans += (maxn - a[i]); } cout << ans; }
1
#include <bits/stdc++.h> #pragma GCC optimize(2) using namespace std; const long long inf = 0x3f3f3f3f; char buf[1 << 21], *p1 = buf, *p2 = buf; inline long long gc() { return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2) ? EOF : *p1++; } inline long long read() { ...
3
#include <bits/stdc++.h> using namespace std; const int N = 500010, M = 500010, K = 500010; long long n, m, i, j, k, tot, ans, s, t, x, y, z, rt, cx, cy, l, r, ll, rr, x1, x2; long long q[M * 2][2], nex[M * 2], head[N]; long long b[M * 2][3], nex2[M * 2], head2[N]; long long c[N], col[N]; long long f[N], ys[N]; lon...
5
#include <bits/stdc++.h> using namespace std; long long sum(long long left, long long right) { if (right < left) { return 0; } return (right + left) * (right - left + 1) / 2; } long long get_nth_sum(long long n, long long k) { if (n == 0) { return k * (k + 1) / 2; } long long prev = n / k; long lo...
4
#include <bits/stdc++.h> using namespace std; int n, x, f_ans = INT_MAX, MAX = INT_MIN; int a[100005]; int cnt[100005], cost[100005]; map<int, pair<int, int> > ans; int main() { scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", &a[i]); MAX = max(MAX, a[i]); } for (int i = 0; i < n; i++) { i...
3
#include <cstdio> #include <cstdlib> #include <algorithm> #define fo(i,a,b) for(int i=a;i<=b;i++) #define fod(i,a,b) for(int i=a;i>=b;i--) #define efo(i,q) for(int i=A[q];i;i=B[i][0]) using namespace std; const int N=100500; int read(int &n) { char ch=' ';int q=0,w=1; for(;(ch!='-')&&((ch<'0')||(ch>'9'));ch=getchar()...
0
#include <bits/stdc++.h> using namespace std; int main() { int n, s1 = 0, s2 = 0, sum = 0; cin >> n; vector<int> a(n); for (auto &it : a) cin >> it; for (int i = 0; i < n; i++) { int k = a[a.size() - 1]; int m = a[0]; if (k >= m) { if (i % 2 != 0) s2 += k; else s1 += k;...
1
#include <bits/stdc++.h> using namespace std; template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; } template <typename T, size_t size> ostream &operator<<(ostream &os, const array<T, size> &arr)...
5
#include <iostream> #include <fstream> #include <cstdio> #include <cmath> #include <vector> #include <cstring> #include <string> #include <set> #include <map> #include <stack> #include <queue> #include <deque> #include <algorithm> #include <array> #include <bitset> #include <assert.h> using namespace std; #define REP(...
0
#include <iostream> #include <vector> #include <cmath> std::pair<int, int> item(const std::string& s) { int N = s.size(), cur = 0; std::string coef, expo; bool xf = 0; while (cur < N && s[cur] != 'x') { coef += s[cur++]; } xf = (cur < N && s[cur] == 'x'); cur += (cur + 1 <...
0
#include <bits/stdc++.h> using namespace std; long long max(long long a, long long b) { return a > b ? a : b; } long long min(long long a, long long b) { return a < b ? a : b; } long long lowbit(long long x) { return x & (-x); } long long prime(long long x) { if (x <= 1) return false; for (int i = 2; i <= int(sqrt(...
5
#include <stdio.h> #include <string.h> const int N=1e5+10; const int INF=1e9+10; int val[N*4],flag[N*4]; int min(int a,int b){return a>b?b:a;} void add(int now,int l,int r,int L,int R,int n){ if(L<=l&&r<=R){ val[now]+=n; flag[now]+=n; } else if(!(L>r||l>R)){ int mid=(l+r)>>1; ...
0
#include <bits/stdc++.h> using namespace std; int main() { int n; string s; cin >> n; cin >> s; int count = 0; for (int i = 0; i < n; i += 2) { if (s[i] == s[i + 1]) { if (s[i] == 'a') { s[i] = 'b'; } else { s[i] = 'a'; } count++; } } cout << count << endl...
1
#include <bits/stdc++.h> using namespace std; int main() { bool digit = 0, small = 0, big = 0; string s; cin >> s; int len = s.length(); if (len < 5) { cout << "Too weak" << endl; return 0; } for (int i = 0; i < len; i++) { if (isupper(s[i])) big = 1; if (islower(s[i])) small = 1; if (...
1
#include <bits/stdc++.h> using namespace std; void deba(int* a, int n) { cerr << "| "; for (int i = 0; i < (n); i++) cerr << a[i] << " "; cerr << "|" << endl; } inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; } const int INF = 1 << 30; int a[123456]; int dp[123456]; int* p; int main() { int n; ...
2
#include <bits/stdc++.h> using namespace std; const int M = 1e9 + 7; long long int n, m, used[500001], ab[500001]; vector<long long int> v[500001], u; void bfs(long long int i) { u.push_back(i); for (auto x : v[i]) { if (!used[x]) { used[x] = 1; bfs(x); } } } int main() { cin >> n >> m; wh...
3
#include <iostream> #include <cstdio> #define maxn 1003 #define mod 1000000007 using namespace std; int pos[maxn], g[maxn], s[maxn], f[maxn][maxn]; void upd(int &x, int y){ x += y; if (x >= mod) x -= mod; } int main(){ int n, k; cin >> n >> k; for (int i = 1; i <= k; ++ i){ int u, v; cin >> u >> v; pos[u] ...
0
#include <bits/stdc++.h> using namespace std; long long a[100005], i, b, n, m, vi, xi, qi, j, c, d, sum; int main() { ios::sync_with_stdio(0); cin >> n >> m; for (i = 1; i <= n; i++) { cin >> a[i]; } for (i = 1; i <= m; i++) { cin >> b; if (b == 1) { cin >> vi >> xi; a[vi] = xi - sum; ...
2
#include <bits/stdc++.h> class Solve { private: using ai4 = std::array<int, 4>; public: bool is_last_query{}; Solve() { int n, w, d; scanf("%d%d%d", &n, &w, &d); if (n == 0 && w == 0 && d == 0) { is_last_query = true; return; } std::vector<ai4> cakes(2 * n + 1); cakes.back() = {w * d, w, d, 1};...
0
#include <iostream> #include <string> #include <cstdio> #include <cstring> using namespace std; int main(){ char ban[9]; int hoge[9]; int tmp[8][3]={{0,1,2},{3,4,5},{6,7,8},{0,3,6},{1,4,7},{2,5,8},{0,4,8},{2,4,6}}; while(true){ int hatena = -1; cin >> ban[0]; if(ban[0]=='0') break; for(int i=1;i...
0
#include<iostream> #include<bits/stdc++.h> using namespace std; int main() { int t=1,cas=0; cin>>t; while(t--) { cas++; int n,m,k,a,i,j,x=0,y=0,z,prev,aft; string str; cin>>n; int cnt=0,ans=0; while(n--) { cin>>a; if(a==3 |...
1
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for (int i=0; i < (n); i++) typedef double D; typedef complex<D> P; typedef vector<P> VP; const D EPS = 1e-7; #define X real() #define Y imag() #define EQ(n,m) (abs((n)-(m)) < EPS) VP crosspointCC(P a, D ar, P b, D br) { VP ps; P ab = b-a; D d = a...
0
#include<stdio.h> int main(void) { int i,n,x; scanf("%d",&n); for(i=1;i<=n;i++){ x=i; if((x%3)==0 )printf(" %d",i); else while(x){ if( x%10==3){ printf(" %d",i); break; } x=x/10; } } printf("\n"); return 0; }
0
#include<iostream> #include<iomanip> #include<string> #include<cstdlib> #include<cmath> #include<algorithm> #include<vector> #include<iomanip> using namespace std; int cnt; //vector<string> memo; char tonum(char word) { if(word == 'R') return '1'; if(word == 'G') return '2'; if(word == 'B') return '3'; if(word ...
0
#include <bits/stdc++.h> using namespace std; void solve() { int numCases = 1; for (int ncase = 1; ncase <= numCases; ncase++) { int N, K; cin >> N >> K; long long ans = 0; vector<int> prices(N, 0); int x; int minprice = 1000000000 + 1; for (int i = 0; i < N; i++) { cin >> prices[i...
1
#include <bits/stdc++.h> using namespace std; int main() { string temp; for (int i = 0; i < 8; i++) { cin >> temp; if (temp != "BWBWBWBW" && temp != "WBWBWBWB") { cout << "NO"; return 0; } } cout << "YES"; return 0; }
1