solution
stringlengths
52
181k
difficulty
int64
0
6
#include <bits/stdc++.h> using namespace std; long long ans[200111]; long long diff[200111]; int main() { int n; scanf("%d", &n); long long prv = 0, ind = 1; for (int i = 1; i <= n / 2; i++) { scanf("%lld", diff + i); long long r = ind; bool found = 0; for (ind; ind * ind - prv * prv <= 1e13; in...
5
#include <iostream> using namespace std; int main(){ while(1){ string g; cin >> g; if(g=="#"){ break; } int y,m,d; cin >> y >> m >> d; if((y==31&&m>=5)||(y>=32)){ cout << "? " << y-30 << " " << m << " " << d << endl; }else{ ...
0
#include <bits/stdc++.h> using namespace std; inline long long read() { long long s = 0, w = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') w = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') s = s * 10 + ch - '0', ch = getchar(); return s * w; } void put1() { puts("YES")...
4
#include <bits/stdc++.h> using namespace std; vector<int> ch[200005]; int vis[200005], g, sub[200005][2], arr1[200005], arr2[200005], ap[200005]; void dfs(int now) { int i, j, k; for (i = 0; i < ch[now].size(); i++) { j = ch[now][i]; if (vis[j] > 0) continue; vis[j] = g; dfs(j); } } int main() { ...
4
#include <bits/stdc++.h> using namespace std; const int mod = int(1e9 + 7); int n, m, first[2222][2222], g[2222][2222]; int main() { scanf("%d%d", &n, &m); for (int w = 2; w <= m; ++w) first[1][w] = g[1][w] = 1; for (int h = 2; h <= n; ++h) { int sum = 0, total = 0; for (int w = 2; w <= m; ++w) { (s...
4
#include <cstdio> #include <cmath> #include <cstring> #include <ctime> #include <climits> #include <iostream> #include <algorithm> #include <set> #include <map> #include <queue> #include <vector> #include <sstream> #include <typeinfo> #include <fstream> #define DIV 1000000007 using namespace std; long long N, M; // ...
0
#include <cstdio> using namespace std; int main(){ char s,t; scanf("%c %c",&s,&t); printf("%c\n",((s=='H'?1:0)^(t=='H'?1:0)?'D':'H')); return 0; }
0
#include <bits/stdc++.h> using namespace std; bool ss(int a, int b) { return a > b; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, a[200005], ans[200005]; pair<int, int> b[200005]; cin >> n; for (int i = 1; i <= n; ++i) cin >> a[i]; for (int i = 1; i <= n; ++i) { cin >>...
3
#include<bits/stdc++.h> using namespace std; struct point{ double x,y; point(){}; point(double x,double y):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 k){ ...
0
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; int a[5][1005] = {0}, ind[5][1005] = {0}; for (int i = 0; i < k; i++) { for (int j = 1; j <= n; j++) { cin >> a[i][j]; ind[i][a[i][j]] = j; } } int ans[5005] = {0}; for (int i = 1; i <= n; i++) { in...
4
#include<bits/stdc++.h> using namespace std; int t,x,n; int main() { scanf("%d",&t); while(t--) { scanf("%d",&n); n*=2; int j=0,o=0; for(int i=0;i<n;++i) { scanf("%d",&x); if(x%2==1)++j; else ++o; } if(j==o)puts("Ye...
1
#include <bits/stdc++.h> using namespace std; #pragma comment(linker, "/stack:200000000") #pragma GCC optimize("Ofast,no-stack-protector") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #pragma GCC optimize("unroll-loops") long long n, k; long long ans = 0; vector<vector<long long> > g; p...
4
#include <bits/stdc++.h> using namespace std; bool possible(long long x, vector<long long> a) { long long n = (long long)(a).size(); if (x == 0) { for (long long i = 1; i < n; i++) { if (a[i] < a[i - 1]) return false; } return true; } for (long long i = 1; i < n; i++) { if (a[i] < a[i - 1]...
3
#include <bits/stdc++.h> using namespace std; int main() { char str[51][51]; int i, j, m, n; cin >> m >> n; for (i = 0; i < m; i = i + 2) { for (j = 0; j < n; j++) { str[i][j] = '#'; } } for (i = 1; i < m; i = i + 4) { for (j = 0; j < n - 1; j++) { str[i][j] = '.'; str[i][n - 1...
1
#include <bits/stdc++.h> using namespace std; int main() { long long int n, k, ans, sum, ti, count, i; cin >> n >> k; if (k >= (n / 2)) { ans = (n * (n - 1)) / 2; cout << ans << endl; return 0; } sum = 0; ans = n - 1; count = 0; for (i = k; i >= 1; i--) { sum = sum + ans; ans--; ...
2
#include <bits/stdc++.h> using namespace std; int main() { long long int i, j, k, n; cin >> n; pair<long long int, long long int> p[n]; for (i = 0; i < n; i++) { cin >> p[i].first; } for (i = 0; i < n; i++) { cin >> p[i].second; } sort(p, p + n); priority_queue<long long int> q; long long in...
1
#include <bits/stdc++.h> using namespace std; int main(){ int A[4]; cin >> A[0] >> A[1] >> A[2] >> A[3]; sort(A,A+4); if (A[0]==1 and A[1]==4 and A[2]==7 and A[3]==9){ cout << "YES"; } else{ cout << "NO"; } }
0
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 500; const int M = 1e6 + 500; const int INF = 0x3f3f3f3f; const int MOD = 1e9 + 7; const int LOG = 20; const int ALP = 30; const int BASE = 31337; const double EPS = 1e-9; const double PI = 3.1415926535; int n, m; long long kol[N]; set<pair<long long, in...
4
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 20, mm = 400; int cnt[maxn]; int us[maxn]; int main() { int m, r, t; while (~scanf("%d%d%d", &m, &t, &r)) { if (t < r) { printf("-1\n"); for (int i = 0; i < m; i++) scanf("%d", &t); continue; } memset(cnt, 0, sizeof c...
3
#include <bits/stdc++.h> using namespace std; typedef long long LL; unordered_map<int,int>cnt; int main() { int N,M; scanf("%d",&N); bool ok = true; int tmp; for (int i=1;i<=N;i++)scanf("%d",&tmp),cnt[tmp]++; scanf("%d",&M); for (int i=1;i<=M;i++){scanf("%d",&tmp);if (cnt[tmp]-- == 0) ok = false;} puts(ok?...
0
#include <bits/stdc++.h> using namespace std; using i64 = int64_t; using vi = vector<i64>; using vvi = vector<vi>; class SCCDecomp { int n; vvi adj; public: vvi scc; SCCDecomp(int n) : n(n), adj(n) {} void addArc(int a, int b) { adj[a].push_back(b); } int run() { ...
0
#define _USE_MATH_DEFINES #include "bits/stdc++.h" #define EPS 1e-10 using namespace std; typedef long long llong; int main() { int l; string s; while (cin >> s >> l, l) { int cnt = 0; vector<string>v; while (s.size() < l)s = '0' + s; v.push_back(s); while (1) { string big(s), small(s); sor...
0
#include <bits/stdc++.h> using namespace std; template <typename item> item abs(item i) { if (i < 0) i = -i; return i; } long long int mod = 1000000000 + 7; ; template <class typea> typea POW(typea b, typea p) { typea res = 1; while (p) { if (p & 1) { res *= b; res %= mod; } b *= b; ...
2
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") using namespace std; const long double eps = 1e-7; const int inf = 1000000010; const long long INF = 10000000000000010LL; const int mod = 1000000007; const int MAXN = 100010; struct DSU { int par[MAXN]; DSU() { for (int i = 1; i < MAXN; i++) par[i] = i; }...
5
#include<bits/stdc++.h> using namespace std; const int N=1e5+5; struct line{ int l,r; bool friend operator <(line i,line j){ return (i.l==j.l)?i.r<j.r:i.l<j.l; } }a[N]; int pre[N],nxt[N]; int main(){ int n; cin>>n; for(int i=1;i<=n;++i) cin>>a[i].l>>a[i].r; sort(a+1,a+n+1); pre[0]=nxt[n+1]=1e9; for(int i=1...
0
#include <bits/stdc++.h> using namespace std; int f[2010]; int find(int x) { if (f[x] == x) return x; return f[x] = find(f[x]); } int n, m, k; int main() { cin >> n >> m >> k; for (int i = 1; i <= n; i++) f[i] = i; int cnt = n; for (int i = 1; i <= n; i++) { int l = i; int r = l + k - 1; if (r >...
2
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 9, C = 26; int id; struct Node { int link[C]; int dp; void clear() { memset(link, -1, sizeof(link)); } } u[N]; void insert(char *s) { int top = 0; for (int i = 0; s[i]; ++i) { int c = s[i] - 'a'; if (u[top].link[c] == -1) { u[id]....
4
#include <bits/stdc++.h> const double EULER = 0.57721566490153286060651209; const double PI = 3.14159265358979323846264338328; const double E = 2.718281828459045235360287471352; using namespace std; long long a[100005]; bool b[100005]; long long c[100005]; int cnt; const long long nega = -2e18; const long long posi = 2...
5
#include <bits/stdc++.h> using namespace std; int n, A[100005], B[100005], cev, flag, son, uc; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d", &A[i]); B[i] = A[i]; } sort(B + 1, B + n + 1); for (int i = 1; i <= n; i++) { if (A[i] == B[i]) { uc++; } } for (int...
2
// B - ATCoder #include <bits/stdc++.h> using namespace std; int main(){ string T="ACGT", S; cin>>S; int maxi = 0, now=0; for(int i=0; i<S.size(); ++i){ now = T.find(S[i]) < T.size()? now+1: 0; maxi = max(maxi, now); } cout<< maxi <<endl; }
0
#include <bits/stdc++.h> using namespace std; const int maxn = 105; int n, ans; int data[4][maxn][maxn]; int cal() { int chi[2][4], ret = 0; for (int i = 0; i < 2; i++) { for (int j = 0; j < 4; j++) { int sum = 0; for (int ii = 0; ii < n; ii++) { for (int jj = 0; jj < n; jj++) { in...
3
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int t; cin >> t; while (t--) { int n, k; string s; cin >> n >> k >> s; vector<vector<int>> g(k, vector<int>(200, 0)); for (int i = 0; i < n; i++) g[i % k][s[i]]++; for (int i ...
3
#include <bits/stdc++.h> using namespace std; template <class T> inline void read(T& x) { x = 0; int f = 0; char ch = getchar(); while (!isdigit(ch)) { if (ch == '-') f = 1; if (ch == EOF) return; ch = getchar(); } while (isdigit(ch)) { x = x * 10 + (ch - '0'); ch = getchar(); } if (...
4
#include <bits/stdc++.h> void dbg(const char* fmt, ...) {} int main() { int t1, t2, t3; int k; int n1, n2, n3; std::multiset<int> free1, free2, free3; scanf("%d", &k); scanf("%d%d%d", &n1, &n2, &n3); for (int i = 0; i < n1; i++) free1.insert(0); for (int i = 0; i < n2; i++) free2.insert(0); for (int i...
4
#include <bits/stdc++.h> using namespace std; struct Point { double x, y; Point(double a = 0, double b = 0) { x = a; y = b; } }; struct Line { double a, b, c, angle; Point p1, p2; Line(Point s, Point e) { a = s.y - e.y; b = e.x - s.x; c = s.x * e.y - e.x * s.y; angle = atan2(e.y - s....
4
#include <bits/stdc++.h> int main() { int a, x, y; while (scanf(" %d %d %d", &a, &x, &y) == 3) { if (x <= -100 || x >= 100 || y % a == 0) { printf("-1\n"); continue; } double width; if (y < a) { width = double(a) / 2; if (x > -width && x < width) printf("%d\n", 1); ...
2
#include <bits/stdc++.h> using namespace std; int main() { long long n, k; char x = 'c'; vector<char> a; cin >> n >> k; if (k > n) { cout << -1; return 0; } if (n == 1) { cout << "a"; return 0; } if (k == 1 && n != 1) { cout << -1; return 0; } for (long long i = 0; i < n - ...
3
#include <bits/stdc++.h> using namespace std; int main() { int n = 1000; puts("2000"); for (int i = 1; i <= n; ++i) printf("%d 1 %d 2\n", i, i); for (int i = n; i > 0; --i) printf("%d 1 %d 2\n", i, i); }
4
//#pragma GCC optimize("trapv") #include<bits/stdc++.h> #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define pb push_back using namespace std; using ll = long long; using vi = vector<ll>; using pi = pair<ll, ll>; using vpi = vector<pi>; const int maxn = 733, mod = 998244353; mt19937 rng(chrono...
0
#include <bits/stdc++.h> #define il inline const int N=2e5+5,M=1e6; int n,P[N],Q[N],A[N],B[N],lev[N],q[M],h,t; int S,T,to[M],nx[M],cap[M],hd[N],it[N],sze=1; il void add(int u,int v,int c){to[++sze]=v,nx[sze]=hd[u],cap[sze]=c,hd[u]=sze;} il void ins(int u,int v,int c){add(u,v,c),add(v,u,0);} il int bfs() { memse...
0
#include<iostream> #include<cstdio> #include<map> #include<vector> #include<algorithm> #include<climits> #include<queue> using namespace std; #define INF INT_MAX struct edge{ int to,cost; }; typedef pair<int,int> P;//firstは最短距離、secondは頂点の番号 vector<edge> G[3003]; int d[3003]; int n,m,k; int solve(int s){ int ret=0...
0
#include <bits/stdc++.h> using namespace std; int main() { int64_t n; cin >> n; multiset<int64_t> S; if (n & 1) { n--; cout << n / 2 << endl; while (n) { S.insert(2); n = n - 2; } auto itr = S.end(); itr--; S.erase(itr); S.insert(3); } else { cout << n / 2 << en...
1
#include <bits/stdc++.h> using namespace std; #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx") int sgn(int x) { if (x > 0) return 1; if (x == 0) return 0; return -1; } signed main() { int x, y; cin >> x >> y; int x1, x2, y1, y2; int ans = abs(x) + abs(y); x1 = ans * sgn(x), y1 = 0; x2 = 0...
1
#include<bits/stdc++.h> using namespace std; vector <int> dr[1000100],db[1000100]; int fa[1000100],dep[1000100],ans; void prework(int s) { for (int k=0;k<db[s].size();k++) if (db[s][k]!=fa[s]) { fa[db[s][k]]=s; dep[db[s][k]]=dep[s]+1; prework(db[s][k]); } } bool check(int u,int v) { if (dep[u]<dep[v]) swap(u,...
0
#include <bits/stdc++.h> using namespace std; const long long MAXN = 1123456; template <typename T> T sqr(T x) { return x * x; } template <typename T> void vout(T s) { cout << s << "\n"; exit(0); } long long bp(long long a, long long n) { long long res = 1; while (n) { if (n % 2) res *= a; a *= a; ...
1
#include <bits/stdc++.h> using namespace std; int main() { string s, b; int result, result1, r, n, q[10], num, t, c; getline(cin, s); int len = s.size(); memset(q, 0, sizeof(q)); result = 0; for (int i = 0; i < len; i++) { num = s[i]; for (int j = 0; j < 8; j++) { q[j] = num % 2; num >...
3
#include <bits/stdc++.h> using namespace std; int main(void) { int first; int n; cin >> n; int i; vector<int> nums(n); for (i = 0; i < n; ++i) { cin >> nums[i]; } int minDiff = abs(nums[n - 1] - nums[0]); int idx = n - 1; for (i = 0; i < n - 1; ++i) { int t = abs(nums[i + 1] - nums[i]); ...
1
#include <cstdio> #include <map> using namespace std; int main(){ int i,n,x,y; for(;scanf("%d",&n),n;printf(i==n?"NO COLOR\n":"%d\n",x)){ map<int,int> m; for(i=0;i<n;i++){ scanf("%d",&x); m[x]++; if(m[x]>n/2){for(;getchar()-10;);i=0;break;} } } }
0
#include <bits/stdc++.h> int main() { long long int a, b, c, t, d, i; scanf("%lld", &t); for (i = 1; i <= t; i++) { scanf("%lld%lld%lld", &a, &b, &c); d = (a + b + c) / 2; printf("%lld\n", d); } return 0; }
1
#include <bits/stdc++.h> using namespace std; inline void err(istringstream *iss) {} template <typename T, typename... Args> void err(istringstream *iss, const T &$val, const Args &...args) { string $name; *iss >> $name; if ($name.back() == ',') $name.pop_back(); cout << $name << " = " << $val << "; ", err(iss,...
4
#include <cstdio> #include <algorithm> using namespace std; typedef long long ll; int N, M; int p[100005]; ll dist[100005]; int find(int a){ if(a==p[a]) return a; int pa=p[a]; p[a]=find(pa); dist[a]+=dist[pa]; return p[a]; } bool merge(int a,int b,int d){ int pa=find(a), pb=find(b); if(pa==pb){ return dist[a]=...
0
#include <bits/stdc++.h> using namespace std; int main() { int kase; cin >> kase; while (kase--) { int n, m, p; cin >> n >> m; while (m--) { if (!m) cout << n << endl; else { cout << (p = pow(10, (int)log10(n - m))) << " "; n -= p; } } } }
4
#include <iostream> using namespace std; int main() { int g; int x, y; cin >> x >> y; for (int i = 1; i <= 1000; i++) { if (x % i == 0 && y % i == 0) { g = i; } } cout << x + y - g + 1 << endl; }
0
#include <bits/stdc++.h> using namespace std; int max(int a, int b) { return (a > b ? a : b); } int min(int a, int b) { return ((a < b) ? a : b); } int gcd(int a, int b) { if (a == 0) return b; else return gcd(b % a, a); } int main() { int t; cin >> t; while (t--) { long long int n, m; cin >> ...
1
#include <bits/stdc++.h> using namespace std; int main(){ cin.tie(0); ios::sync_with_stdio(false); int a,b,c; cin >> a >> b >> c; for (int i=0;i<120;++i){ int t=60*i+c; if (t%(a+b)<=a){ cout << t << '\n'; return 0; } } cout << -1 << '\n'; }
0
#include <bits/stdc++.h> using namespace std; long long ceil(long long p, long long q) { if (p % q == 0) return (p / q); return (p / q) + 1; } int main(int argc, char const *argv[]) { int k, n, s, p; cin >> k >> n >> s >> p; cout << ceil(k * ceil(n, s), p) << endl; return 0; }
1
#include <bits/stdc++.h> using namespace std; int n, tot; int fat[1008611], ans[1008611]; int main() { scanf("%d", &n); for (int i = 2; i <= n; ++i) scanf("%d", &fat[i]); int now = n; while (now != 1) { ans[++tot] = now; now = fat[now]; } ans[++tot] = now; reverse(ans + 1, ans + tot + 1); for (i...
1
#include <bits/stdc++.h> using namespace std; int n, a, b, c, d, ans; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d%d%d%d", &a, &b, &c, &d), ans += (c - a + 1) * (d - b + 1); printf("%d\n", ans); return 0; }
1
#include <bits/stdc++.h> using namespace std; const int MAXN = 3 * 1e5 + 10; struct visiter { int index, want, get; }; vector<visiter> vis; bool cmp1(visiter v1, visiter v2) { return v1.index < v2.index; } bool cmp2(visiter v1, visiter v2) { return v1.want < v2.want; } int main(void) { int n; cin >> n; vis.resi...
3
#include <bits/stdc++.h> using namespace std; const long long N = 2e5; const long long M = 20; const long long SQ = 320; const long long INF = 1e16; const long long MOD = 1e9 + 7; int n; int x[N], y[N]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n; for (int i = 0; i < n; i++) cin >> x[i] >> y...
4
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using uint = unsigned int; using ull = unsigned long long; template <typename T> using pair2 = pair<T, T>; using pii = pair<int, int>; using pli = pair<ll, int>; using pll = pair<ll, ll>; mt19937_64 rng(chrono::steady_clock::now...
1
#include<cstdio> #include<cstring> #include<algorithm> using namespace std; int dp[305][305]; char name[50]; int cost[305]; int v[305],b[305],f[305]; int n,m; int solve(int s[],int i,int c){ int res,sk,nc; if(i==n) return 0; if(dp[i][c]>=0) return dp[i][c]; res= solve(s,i+1,c); for(nc=cost[i],sk=s[i];c>=nc;n...
0
#include <bits/stdc++.h> using namespace std; int main() { int n, a, d; cin >> n >> a >> d; vector<int> t(n), v(n); for (int(i) = (int)(0); (i) < (int)(n); ++(i)) cin >> t[i] >> v[i]; double p, q, r; vector<double> s; for (int(i) = (int)(0); (i) < (int)(n); ++(i)) { double r = double(v[i]) / a; p ...
3
#include <bits/stdc++.h> using namespace std; map<int, vector<pair<int, int>>> adj; vector<long long> dis(100010, 1e16), parent(100010); priority_queue<int> q; int v, e, from, to, w; void print_path(int node) { if (node != 1) print_path(parent[node]); cout << node << " "; } void dijkstra(int node) { q.push(node),...
3
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; string ss[10]; string ans = ""; for (int i = 0; i < 10; i++) { cin >> ss[i]; } for (int i = 0; i < 80; i += 10) { string k = s.substr(i, 10); if (k == ss[0]) ans += '0'; else if (k == ss[1]) ans += '...
1
#include <bits/stdc++.h> long long int power(long long int s, int t) { long long int ans = 1; for (int i = 1; i <= t; i++) ans *= s, ans %= 1000000007; return ans; } int dist[100010]; std::vector<std::pair<int, int> > V[100010]; void func(int s, int t) { if (dist[s] > 0) return; dist[s] = t; for (int i = 0;...
5
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; int add(int a, int b) { return a + b < mod ? a + b : a + b - mod; } int mul(int a, int b) { return int(1LL * a * b % mod); } const int N = 2005; int dp[N][N]; int f(int n, int len) { if (len < 2 or n < 0) return 0; if (n == 0) return 1; int &a...
4
#include <bits/stdc++.h> using namespace std; long long a[100001]; long long b[100001]; int main() { int n, i; cin >> n; for (i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); if (a[n - 1] < a[n - 2] + a[n - 3]) { cout << "YES\n"; swap(a[n - 1], a[n - 2]); for (i = 0; i < n; i++) cout << a[i] << " "...
2
#include <bits/stdc++.h> using namespace std; int infinito = 1000000000; int n; int f[1002]; int m[1002][101][2]; int ej[1002][101][2]; list<char> sol; vector<list<char>::iterator> genera(int i, int j, int k) { vector<list<char>::iterator> vi; if (i == n - 1) { for (int paso = 0; paso < f[i]; paso++) { so...
5
#include <iostream> #include <vector> using namespace std; long long ope_cnt(vector<long long> a, int n, bool plus) { long long sum = 0, ret = 0; for (int i = 0; i < n; i++) { sum += a[i]; if (plus && sum <= 0) { ret += 1 - sum; sum = 1; } else if (!plus && sum >= 0) { ret += 1 + sum; sum = -1; ...
0
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); string s; cin >> s; string s1, s2, s3; s1 = s; s2 = s; s3 = s; for (int i = 0; i < s.size(); ++i) { s1[i] = 'a' + (i / (26 * 26)); s2[i] = 'a' + (i / 26) % 26; s3[i] = 'a' + i % 26; ...
5
#include <bits/stdc++.h> using namespace std; void nextPlease() { ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); } int di[] = {1, 1, -1, -1, 2, 2, -2, -2}; int dj[] = {2, -2, 2, -2, 1, -1, 1, -1}; long long n, m, cx, cy; bool valid(long long x, long long y) { return (x > 0 && x <= n && y > 0 && y ...
2
#include <bits/stdc++.h> using namespace std; int l[100000], r[100000]; int main() { long long n, sum = 0; memset(l, 0, sizeof(l)); memset(r, 0, sizeof(r)); cin >> n; for (int i = 0; i < n; i++) { cin >> l[i] >> r[i]; } sort(l, l + n); sort(r, r + n); for (int i = 0; i < n; i++) { sum += max(l...
4
#include <bits/stdc++.h> size_t push(const std::vector<size_t>& v, size_t id, size_t val) { while (id < v.size() && v[id] < val) { id += 1; } return id; } size_t solve(const std::vector<size_t>& m, const std::vector<size_t>& l, const std::vector<size_t>& r) { size_t l_ptr = push(l, 0, m[0]); ...
4
#include <bits/stdc++.h> using namespace std; mt19937 rnd(2007); struct DD { struct Node { long long cnt, x, y, sum; Node *l, *r; Node(long long x_) { x = sum = x_; cnt = 1; y = rnd(); l = r = NULL; } } * root; void print_tree(Node *t) { if (!t) return; cout << t->x...
6
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf("%d", &n); if (n <= 3) { cout << "NO" << endl; return 0; } if (n == 4) { cout << "YES" << endl; printf("1 * 2 = 2\n"); printf("2 * 3 = 6\n"); printf("6 * 4 = 24\n"); return 0; } if (n == 5) { cout << "Y...
3
#include <cstdio> #include <vector> #include <algorithm> int main() { int N, C; scanf("%d %d", &N, &C); std::vector<int> prog(100010); for (int i=0; i<N; ++i) { int s, t, c; scanf("%d %d %d", &s, &t, &c); if (prog[s]>>c & 1) { prog[s] ^= 1 << c; } else { prog[s-1] ^= 1 << c; }...
0
#include <bits/stdc++.h> using namespace std; long long check(int cur_op, vector<char> ops, vector<long long> nums) { if (nums.size() == 1) { return nums[0]; } long long cur_res = 0, min_res = -1, number; vector<long long> new_nums; for (int i = 0; i < nums.size(); ++i) { for (int j = i + 1; j < nums....
2
#include <bits/stdc++.h> using std::make_pair; using std::pair; const int N = 1000 + 10; std::vector<std::tuple<int, int, int>> edges; std::vector<int> neighbors[N]; int weights[N], size[N], father[N], n; namespace union_set { int ancestor[N], size[N]; void init(int n) { for (int i = 1; i <= n; ++i) { ancestor[i]...
6
#include <bits/stdc++.h> using namespace std; const double eps = 1e-12; const int N = 32; bool zero(double x) { return fabs(x) < eps; } int sgn(double x) { if (x < -eps) return -1; if (x > eps) return 1; return 0; } struct Point { double x, y; Point(double _x = 0, double _y = 0) { x = _x, y = _y; } void out...
5
#include <bits/stdc++.h> using namespace std; const int MOD = 1000003; long long n, k; int pow_mod(int x, int k) { int ans = 1; while (k) { if (k & 1) ans = 1LL * ans * x % MOD; x = 1LL * x * x % MOD; k >>= 1; } return ans; } int zi, mu; long long a = 0; int main() { scanf("%lld%lld", &n, &k); i...
5
#include <bits/stdc++.h> using namespace std; const int M = 1e5 + 7; const int Q = 1e9 + 7; inline int pls(int x, int y) { return ((long long)x + y) % Q; } inline int mns(int x, int y) { return pls(x, Q - y); } inline int mul(int x, int y) { return 1LL * x * y % Q; } inline int ri() { int x = 0; bool f = 1; char ...
3
#include <bits/stdc++.h> using namespace std; int Data[400100]; int T, N; int main() { scanf("%d", &T); while (T--) { int G = 1, S = 0, B = 0; scanf("%d", &N); for (register int i = 1; i <= N; ++i) scanf("%d", &Data[i]); if (N < 10) { printf("0 0 0\n"); continue; } int pos = 2; ...
1
#include <bits/stdc++.h> using namespace std; int n; vector<vector<int> > g, G; int dp[5000][2501][2]; int in[5000]; int last[5000], u[5000], v[5000], nxt[5000], e; void addEdge(int a, int b) { u[e] = a; v[e] = b; nxt[e] = last[a]; last[a] = e; ++e; } int DFS(int u, int p) { int ret = 0, me = 1; for (int ...
6
#include <bits/stdc++.h> using namespace std; const int inf = (int)1e9; const long long llinf = (long long)9e18; const int N = (int)1e7 + 111; const long double PI = (long double)acos(-1); int main() { long long ans = 0; int n, x; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", &x); ans ^= (l...
3
#include <bits/stdc++.h> using namespace std; template <typename T> T gcd(T a, T b) { if (a == 0) return b; return gcd(b % a, a); } template <typename T> T pow(T a, T b, long long m) { T ans = 1; while (b > 0) { if (b % 2 == 1) ans = ((ans % m) * (a % m)) % m; b /= 2; a = ((a % m) * (a % m)) % m; ...
4
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s; cin >> s; int res = 0; int dp[n]; memset(dp, 0, sizeof(dp)); for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (s[j] == '.') continue; if (j < n && s[j] == 'R') { if (s[j + 1] == '....
2
#include<bits/stdc++.h> using namespace std; long long n,x[111111],p[111111],y[111111],siz[111111],cir[111111],m,k,sum; bool vis[111111]; int main(){ scanf("%lld",&n); for(int i=1;i<=n;i++)scanf("%lld",&x[i]),p[i]=i,y[i]=x[i]-x[i-1]; scanf("%lld%lld",&m,&k); for(int i=1,a;i<=m;i++)scanf("%lld",&a),swap(p[a],p[a+1]...
0
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; long long a[n]; for (long long i = 0; i < n; i++) cin >> a[i]; long long cnt = 0; long long sum = 0; sort(a, a + n); for (long long i = 0; i < n; i++) { if (sum <= a[i]) { cnt++; sum += a[i]; } } co...
4
#include <iostream> #include <cstdio> #include <string> #include <cstring> #include <deque> #include <list> #include <queue> #include <stack> #include <vector> #include <utility> #include <algorithm> #include <map> #include <set> #include <complex> #include <cmath> #include <limits> #include <climits> #include <ctime> ...
0
#include<bits/stdc++.h> using namespace std; int main(){ int x; cin>>x; int now=0; for(int i=0;i<x;i++){ now*=10; now+=7; now=now%x; if(now==0){ cout<<i+1<<endl; return 0; } }cout<<-1<<endl; }
0
#include <iostream> #include <algorithm> using namespace std; int main() { int n; cin >> n; int a[6] = {0}; while(n--) { double h; cin >> h; a[max(0, min(5, ((int)(h*10)-1600)/50))] += 1; } for(int i = 0; i < 6; ++i) { cout << i+1 << ":" << string(a[i], '*') << endl; } return 0; }
0
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; int arr[n], ans[n]; for (int i = 0; i < n; i++) { cin >> arr[i]; } sort(arr, arr + n); int l = 0, r = n - 1; for (int i = n - 1; i >= 0; i--) { if (i % 2 == 0) { ...
2
#include <bits/stdc++.h> #define int long long using namespace std; int a[30]; signed main() { string w; cin>>w; for(int i=0;i<w.size();i++){ a[w[i]-'a']++; } for(int i=0;i<26;i++){ if(a[i]%2==1){ cout<<"No"<<endl; return 0; } } cout<<"Yes"<<endl; }
0
#include <bits/stdc++.h> using namespace std; const int MAXN = 300005; inline int read() { int weight = 0, symbol = 1; char in = getchar(); while (!isdigit(in)) { if (in == '-') symbol = -1; in = getchar(); } while (isdigit(in)) { weight = weight * 10 + in - '0'; in = getchar(); } return s...
1
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int mins[3]; int big = 2000000000; mins[0] = big; mins[1] = big; mins[2] = big; int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; if (a[i] == mins[0] || a[i] == mins[1]) continue; if (a[i] < mins[0]) { min...
2
#include <bits/stdc++.h> using namespace std; const int N = 65537; int degree[N]; int xorsum[N]; int n; queue<int> q; int ans = 0; queue<pair<int, int> > edges; int main() { scanf("%d", &n); for (int i = 0; i < n; ++i) { scanf("%d %d", &degree[i], &xorsum[i]); if (degree[i] == 1) { q.push(i); } ...
3
#include <bits/stdc++.h> using namespace std; template <class Read> void in(Read &x) { x = 0; int f = 0; char ch = getchar(); while (ch < '0' || ch > '9') { f |= (ch == '-'); ch = getchar(); } while (ch >= '0' && ch <= '9') { x = (x << 1) + (x << 3) + (ch ^ 48); ch = getchar(); } x = f ?...
4
#include <bits/stdc++.h> using namespace std; const int MAX_N = 1e5 + 7; int n, m; long long a[MAX_N]; int main() { cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; cin >> m; long long w, h, minh = 0; for (int i = 1; i <= m; i++) { cin >> w >> h; long long hh = max(minh, a[w]); cout << hh << en...
1
#include <bits/stdc++.h> using namespace std; const int N = 1e+5 + 50; long long int a[N], ans, tans[N], fans; int n; int nxt[100 * N][3], nt; void insert(long long int val) { int i = 0; vector<int> dig; for (int j = 0; j < 50; j++, val /= 2) dig.push_back(val % 2); reverse(dig.begin(), dig.end()); for (auto ...
5