solution
stringlengths
52
181k
difficulty
int64
0
6
#include <bits/stdc++.h> using namespace std; int main() {int a,b,c; cin>>a>>b>>c; swap(a,b); swap(a,c); cout<<a<<' '<<b<<' '<<c;}
0
#include <bits/stdc++.h> using namespace std; void check(int a[], int n) { int i = 0; while (i < n) { if (a[i] == 1) { cout << "HARD"; return; } i++; } cout << "EASY"; return; } int main() { int n; cin >> n; int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } check(a...
1
#include <bits/stdc++.h> const int N = 12005; struct line { double l, r, k, b; void move(int x) { l += x, r += x, b -= k * x; } double f(double x) { return k * x + b; } void add(double x, double y) { k += x, b += y; } } t[N]; int n, q, a, b, top, x[N]; double y[N]; double get() { double now = 1e100, res; fo...
5
#include <bits/stdc++.h> using namespace std; const long long INF = 1e9; const long long N = 2e2 + 7; const long long mod = 1e9 + 7; const long double eps = 1E-7; long long a, b, n, cnt, mx, ans, c; long long used[N]; string s[12] = {"C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "B", "H"}; string s1, s2, s3; in...
1
#include <bits/stdc++.h> using namespace std; int n, m, cnta, cntb, cntc; int ans[1010][1010]; int main() { scanf("%d%d%d%d%d", &n, &m, &cnta, &cntb, &cntc); if ((n * m) & 1) { puts("IMPOSSIBLE"); return 0; } else if (((n & 1) == 0) && ((m & 1) == 0)) { for (int i = 1; i <= n; i += 2) for (int j...
3
#include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int, int>; constexpr int N = 1e3 + 5; int n, m; char c; int field[N][N]; template <typename P> struct Dsu { vector<P> pr; vector<int> sz; Dsu(int s) { pr.resize(s + 1); sz.resize(s + 1); } int toid(const pii& a) { ret...
3
#include <iostream> #include <vector> #include <algorithm> using namespace std; int main(){ int l,n; cin >> l >> n; int b = 0; for(int i=0; i<n; i++){ int x,w; cin >> x >> w; b += x*w; } if(b == 0){ cout << 0 << endl; }else{ cout << 1 << endl; ...
0
#include <bits/stdc++.h> using namespace std; const int MAXN = 100 * 1000 + 10; int ch[30][MAXN], t[MAXN]; bool win[MAXN], lose[MAXN]; int node = 1; void dfs(int v) { int tc = 0; for (int i = 0; i < 26; i++) if (ch[i][v] != 0) { dfs(ch[i][v]); if (!win[ch[i][v]]) win[v] = true; if (!lose[ch[i]...
4
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); int n; cin >> n; for (int i = 0; i < n; i++) { int t; cin >> t; int answer = -1; map<int, int> mp; for (int j = 1; j <= t; j++) { int k; cin >> k; if (mp.count(k)) { int tmp...
3
#include <bits/stdc++.h> using namespace std; template <class T> T chmin(T& a, T& b) { if (a > b) return a; } template <class T> T chmax(T& a, T& b) { if (a < b) return b; } const long long INF = 1e18; const int MOD = 3; const int N = 7000; bool v[N]; vector<long long> adj[N]; int main() { long long l, r; cin >...
3
#include <bits/stdc++.h> using namespace std; long long t, m, n; vector<int> A; long long solve() { int ans = 0; for (int i = 0; i < n; i++) { int j = i; while (j + 1 < n && A[j + 1] <= 2 * A[j]) j++; ans = max(ans, j - i + 1); i = j; } return ans; } int main() { cin >> n; A.resize(n); for...
2
#include "bits/stdc++.h" using namespace std; typedef long long ll; typedef pair<int,int> pii; #define rep(i,n) for(ll i=0;i<(ll)(n);i++) #define all(a) (a).begin(),(a).end() #define pb push_back #define INF (1e9+1) //#define INF (1LL<<59) //0-index ??????????????°?????????(????????´??°or?????? , ????°????or?????§???...
0
#include <iostream> #include <cmath> #include <cstdio> #include <algorithm> #include <string> #include <string.h> using namespace std; const int MAX_N=10000; int n,y; int main(){ cin >> y >> n; if(y==0){ if(n>=1989) cout << "H" << n-1989+1 << endl; else if(n>=1926) cout << "S" << n-1926+1 << endl; else if...
0
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int a, b; cin >> a >> b; int h = 23 - a; int m = 60 - b; cout << (h * 60) + m << endl; } return 0; }
1
#include <bits/stdc++.h> char s[((int)1e6 + 5)]; int main(void) { int len; int p = -1; int first = -1; int last = -1; int exp = 0; scanf(" %s", s); len = strlen(s); for (int i = 0; i < len; i++) { if (s[i] == '.') { p = i; } if (isdigit(s[i]) && s[i] != '0' && first == -1) { firs...
3
#include <bits/stdc++.h> namespace FastIO { bool IOerror = 0; inline char nc() { static char buf[100000], *p1 = buf + 100000, *pend = buf + 100000; if (p1 == pend) { p1 = buf; pend = buf + fread(buf, 1, 100000, stdin); if (pend == p1) { IOerror = 1; return -1; } } return *p1++; } inl...
3
#include <iostream> #include<string> using namespace std; int main(){ int n, a = 0; string s; cin >> n >> s; for (int i = 0; i < n - 2; i++) if (s[i] == 'A'&&s[i + 1] == 'B'&&s[i + 2] == 'C') a++; cout << a; }
0
#include <bits/stdc++.h> using namespace std; using cd = complex<double>; const double PI = acos(-1); void fft(vector<cd>& a, bool invert) { int n = a.size(); if (n == 1) return; vector<cd> a0(n / 2), a1(n / 2); for (int i = 0; 2 * i < n; i++) { a0[i] = a[2 * i]; a1[i] = a[2 * i + 1]; } fft(a0, inve...
1
#include<bits/stdc++.h> using namespace std; #define int long long typedef vector<int>vint; typedef pair<int,int>pint; typedef vector<pint>vpint; #define rep(i,n) for(int i=0;i<(n);i++) #define reps(i,f,n) for(int i=(f);i<(n);i++) #define all(v) (v).begin(),(v).end() #define each(it,v) for(__typeof((v).begin()) it=(v)...
0
#include <bits/stdc++.h> using namespace std; using ll = long long int; string s, t; int mp[28], tempMap[28]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int i, j, len1, len2, can = -1; cin >> s >> t; len1 = (int)s.size(), len2 = (int)t.size(); for (i = 0; i < len1; i++) { mp[s[i] - 'a...
4
#include <iostream> #include <cmath> #include <cstdio> #include <cstring> #include <algorithm> #define rep(x, a, b) for(int x = (a); x <= (b); ++x) #define rop(x, a, b) for(int x = (a); x < (b); ++x) #define per(x, a, b) for(int x = (a); x >= (b); --x) using namespace std; typedef long long LL; typedef double DB; const...
0
#include <bits/stdc++.h> using namespace std; void solve() { long long n, q; cin >> n >> q; long long v[n], c[n]; for (long long i = 0; i < n; i++) cin >> v[i]; for (long long i = 0; i < n; i++) { cin >> c[i]; c[i]--; } while (q--) { long long a, b; cin >> a >> b; vector<long long> dp(...
3
#include <bits/stdc++.h> using namespace std; vector<string> split(const string& s, char c) { vector<string> v; stringstream ss(s); string x; while (getline(ss, x, c)) v.push_back(x); return v; } void err(vector<string>::iterator it) {} template <typename T, typename... Args> void err(vector<string>::iterator...
6
#include<bits/stdc++.h> using namespace std; #define rep(i,n) for(int i=0;i<(n);i++) #define REP(i,n) for(int i=1;i<=(n);i++) #define mp make_pair #define pb push_back #define fst first #define snd second typedef long long ll; typedef pair<int,int> pii; const int maxn=200005; const int mlog=20; int n; vector<int>edge...
0
#include <bits/stdc++.h> using namespace std; int main() { map<long long, bool> mp; long long n; cin >> n; long long k = n; for (int i = 1; i <= n; i++) { long long a; cin >> a; mp[a] = 1; while (mp[k] == 1) { cout << k << " "; k--; } cout << '\n'; } }
1
#include <bits/stdc++.h> using namespace std; int dx[4] = {-1, 1, 0, 0}; int dy[4] = {0, 0, -1, 1}; void init() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); } long long Gcd(long long a, long long b) { for (; b; a %= b, swap(a, b)) ; return a; } long long Lcm(long long a, long long b) { return (...
2
#include <bits/stdc++.h> using namespace std; long long finMin(long long x, long long y, long long a, long long l, long long r) { if (l == r) return l; if (l + 1 == r) { if (y + l * 2 * a > x) return l; return r; } long long m = (l + r) / 2; if (y + m * 2 * a > x) return finMin(x, y, ...
2
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:1000000000") #pragma GCC optimize("Ofast,no-stack-protector") using namespace std; map<long long, map<int, long long> > ed; int nx[500][500]; bool bad[500][500]; long long go(long long mask, int x) { if (ed[mask].count(x)) { return ed[mask][x]; } long l...
4
#include <bits/stdc++.h> using namespace std; int main() { iostream::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, m; cin >> n >> m; vector<int> pos(n + 1); vector<int> toplace(n, n - 1); for (int i = 0; i < n; i++) { int a; cin >> a; pos[a] = i; } for (int i = 0; i < m; i++) { ...
3
#include <bits/stdc++.h> using namespace std; const int MAXN = 200000; long long t[3][4 * MAXN + 1]; int a, b; void upd(int num, int pos, int delta, int v = 1, int l = 1, int r = MAXN) { if (l == r) { if (num == 1 && t[num][v] + delta >= b) t[num][v] = b; else if (num == 1) t[num][v] += delta; ...
3
#include <bits/stdc++.h> using namespace std; long long ans, n; int main() { cin >> n; ans = 1; ans += 3ll * (n - 3ll); ans += (n - 3ll) * (n - 4ll); cout << ans << endl; return 0; }
2
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 7; int perm[N]; pair<int, int> v[N]; vector<pair<int, int>> s[N]; signed main() { ios_base ::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; for (int i = 1; i <= n; i++) { cin >> v[i].first >> v[i].second; s[v[i].first]....
6
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; int t1[100005] = {}; for (int i = 1; i <= n; i++) { int c, t; cin >> c >> t; t1[i] = t1[i - 1] + c * t; } int i0 = 0; for (int i = 0; i < m; i++) { int v; cin >> v; while (t1[i0] < v && i0 < n) i0++...
2
#include<iostream> #include<cstdio> #include<math.h> #include<algorithm> #define Lens 250 #define Nil -1 using namespace std; struct Node { int p, l, r; }; int N; Node Tr[Lens]; int D[Lens], C[Lens], H[Lens]; bool V[Lens]; //建树 void maketree() { int m, l, r; for (int i = 0; i < N; i++) { cin >> m >> l >> r; ...
0
#include <bits/stdc++.h> using namespace std; int main() { long long N; cin >> N; long long n = N; long long logi = 0; while (n >= 10) { n /= 10; logi++; } long long zahl = 0; for (int i = 0; i < logi; i++) { zahl *= 10; zahl += 9; } N -= zahl; long long QS = 0; string S = to_str...
2
#include <bits/stdc++.h> long long mu[20], f[40][20][20]; long next[40][20][20]; char xau[40], kq[40]; int main() { long i, j, k, l; scanf("%ld\n", &l); gets(xau + 1); mu[1] = 1; for (i = 2; i <= l; i++) mu[i] = mu[i - 1] * 10; for (i = 0; i <= 2 * l; i++) for (j = 0; j <= l; j++) for (k = 0; k <=...
5
#include <bits/stdc++.h> using namespace std; struct PT { int x, y; PT(int x = 0, int y = 0) : x(x), y(y) {} void in() { scanf("%d%d", &x, &y); } PT operator+(const PT &p) const { return PT(x + p.x, y + p.y); } PT operator-(const PT &p) const { return PT(x - p.x, y - p.y); } long long operator*(const PT &p)...
5
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; long long N; int M; struct Matrix { const static int maxn = 103; long long v[maxn][maxn]; int n; Matrix(int _n) : n(_n) { for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { v[i][j] = 0; } } } Ma...
4
#include<iostream> #include<cstdio> #include<cassert> #include<set> #include<algorithm> using namespace std; const int N=100005; int n; int a[N],b[N]; pair<int,int> p[N]; int q[N]; int main() { scanf("%d",&n); for(int i=1;i<=n;i++) scanf("%d",&a[i]),p[i]=make_pair(a[i],i); sort(p+1,p+n+1,greater<pair<int,int> >())...
0
#include <bits/stdc++.h> using namespace std; const long long maxAns = 3000000000; long long x, y, n, c, t1, t2, t3, t4; long long mk2(long long x) { if (x <= 0) return 0; return ((x + 1) * x) / 2; } long long mk(long long x) { if (x <= 0) return 0; return x * x; } long long count(long long time) { long long ...
2
#include <bits/stdc++.h> using namespace std; set<int> s; vector<int> v, r; map<int, int> ans; bool check[2 * int(1e5 + 10)]; int main() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); int n, m; cin >> n >> m; for (int i = 0; i < n + m; i++) { int x; cin >> x; v.push_back(x); } ...
2
#include <bits/stdc++.h> using namespace std; long long dp[1000007]; int main() { string s; cin >> s; long long N = s.size(); long long nxt = 0, idx = 0; for (long long i = (s.size() - 1); i > (-1); i--) { if (s[i] == 'a') { dp[idx++] = nxt; nxt = 0; } else { nxt++; } } long ...
2
#include <bits/stdc++.h> using namespace std; inline void beg(); inline void fin(); const int N = 2e5 + 5; string t, p; int a[N]; bool check(int num) { string q = t; for (int i = 0; i < num; i++) { q[a[i] - 1] = '#'; } int j = 0; for (int i = 0; i < (int)q.size() && j < (int)p.size(); i++) { if (q[i] ...
1
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int r, c; char ch[9][9]; for (int i = 0; i < 9; ++i) for (int j = 0; j < 9; ++j) cin >> ch[i][j]; cin >> r >> c; int pr = r - 1 - (r - 1) / 3 * 3, pc = c - 1 - (c - 1) / 3 * 3; int chk ...
2
#include <bits/stdc++.h> using namespace std; int n, m, cnt, f[100005], fa[100005]; long long size[100005]; long long ans; struct node { int x, y, v; } a[100005]; bool operator<(node x, node y) { return x.v > y.v; } int find(int x) { if (fa[x] == x) return x; return fa[x] = find(fa[x]); } int main() { scanf("%d...
4
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[n], i; for (i = 0; i < n; i++) { cin >> a[i]; } sort(a, a + n); cout << "1" << " " << a[0] << "\n"; if (a[n - 1] > 0) { cout << "1" << " " << a[n - 1] << "\n"; cout << n - 2 << " "; for (i =...
1
#include <bits/stdc++.h> using namespace std; typedef double D; typedef long long int LL; #define st first #define nd second #define PLL pair <LL, LL> #define PII pair <int, int> const int N = 1e6 + 7; const int MX = 1e9 + 7; const LL INF = 1LL * MX * MX; int n; char in[N]; int limit[N]; int check(int v){ int ze...
0
#include <bits/stdc++.h> using namespace std; const int N = 65; bool f[N][N][N * N], g[N][N][N * N], ans[N][N]; int a0[N], d[N], m, n = -1; void dfs(int i, int j, int k) { if (!j) return; d[j] = a0[i]; if (g[i][j][k]) dfs(i - 1, j - 1, k - a0[i]); else dfs(i, j - 1, k - a0[i]); } int p[N]; bool cmp(int ...
4
#include <bits/stdc++.h> using namespace std; int main() { int tc; scanf("%d", &tc); while (tc--) { int a, b, x, y; scanf("%d%d%d%d", &a, &b, &x, &y); int d[5], maxN = -1; d[1] = x * b, d[2] = max((a - x - 1), 0) * b, d[3] = a * y, d[4] = a * max((b - y - 1), 0); for (int i = 1; i <= 4; i+...
1
#include <bits/stdc++.h> using namespace std; class doi { public: void endline(char edl) { _edl = edl; } template <typename T> void o_ans(T ans[], int a, int b) { for (int i = a; i < b; i++) cout << ans[i] << _edl; } template <typename T> void o_bol(T ans[], int a, int b) { for (int i = a; i < b; i...
3
#include <iostream> #include <string> #include <cmath> #include <vector> #include <algorithm> #include <utility> #include <bitset> #include <climits> #include <set> #include <map> #include <iomanip> #include <queue> #include <cstring> using namespace std; #define ll long long #define INF LONG_LONG_MAX #define pll pair<...
2
#include <bits/stdc++.h> using namespace std; const long long N = 1e5 + 5, SQRT = 320; struct query { long long l, r, id; bool operator<(const query& rem) const { if (l / SQRT != rem.l / SQRT) return l / SQRT < rem.l / SQRT; else return r < rem.r; } } que[N]; long long n, K, q, t[N], a[N], up[...
6
#include <bits/stdc++.h> using namespace std; const int inf = 1 << 30; const int md = 1e9 + 7; const int N = 100 + 10; const int M = 1e3 + 10; int n, m; int T; int ar[N]; double dp[N][M * N]; double sum[N][M * N]; int main() { int al = 0; scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) scanf("%d", &ar[i]), al...
5
#include<cstdio> int main() { int a,b,c,i; scanf("%d%d%d",&a,&b,&c); for(i=b;i<=c;i++) if(i%a==0) break; if(i>c) printf("NG"); else printf("OK"); }
0
#include <bits/stdc++.h> using namespace std; int main() { int n, x, tmp, count = 0, i = 0; map<int, int> m; cin >> n >> x; for (int j = 0; j < n; j++) { cin >> tmp; m[tmp] = 1; } for (; i < x; ++i) { if (i < x && m.find(i) == m.end()) { count++; } } if (i == x && m.find(i) != m.en...
1
#include <bits/stdc++.h> using namespace std; vector<pair<int, int>> dp_in, dp_out; vector<vector<pair<int, int>>> g; vector<pair<int, int>> color; void dfs1(int u, int p) { dp_in[u] = color[u]; int v; for (auto& row : g[u]) { v = row.first; if (v ^ p) { dfs1(v, u); if ((dp_in[u].first - dp_in...
6
#include<iostream> int main (void){ int k,x; scanf("%d",&k); scanf("%d",&x); for(int i=x-k+1;i<=x+k-1;i++) { printf("%d ",i); } }
0
#include <bits/stdc++.h> using namespace std; long long n, k, a, b, q, binary[2][1000000], no[1000000]; void update(long long s, long long k, long long l) { for (long long i = s; i <= n; i += i & -i) binary[l][i] += k; } long long query(long long s, long long l) { long long ans = 0; for (long long i = s; i > 0; i...
2
#include <bits/stdc++.h> using namespace std; const int N = 1000005; string s; int R[N]; int k, n; bool p(int pos, int x, int l) { if (l > k) return false; if (pos == n) return true; int y = pos; int in; while (y - pos <= x) { in = y; y = R[y]; } return p(in, x, l + 1); } int main() { cin >> k; ...
4
#include <bits/stdc++.h> using namespace std; const short maxN = 400 + 2; short N, K; vector<pair<short, short> > adj[maxN]; vector<short> dp[maxN]; vector<short> fat; short rec[maxN][maxN][maxN]; vector<short> final; void dfs(short u, short pre) { dp[u] = vector<short>(K + 1, 0x03ff); dp[u][1] = 0; fat[u] = pre;...
4
#include<stdio.h> int main(void) { int n,s,ss,i; scanf("%d",&n); s=100000; for(i=0;i<n;i++){ ss=s*0.05; s+=ss; if(s%1000!=0){ s=s/1000; s=(s+1)*1000; } } printf("%d\n",s); return 0; }
0
#include <bits/stdc++.h> using namespace std; vector<pair<int, bool> > enemy; vector<int> my; int n, m; bool comp(const pair<int, bool> &a, const pair<int, bool> &b) { return a.second > b.second || ((a.second == b.second) && (a.first < b.first)); } int main(int argc, char **argv) { scanf("%d %d\n", &n, &m); for (...
2
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int>pii; const int mn=200+10; const ll inf=0x3f3f3f3f3f3f3f3f; const ll mod=1e9+7; ll basis[64]; ll a[mn]; bool add(ll x){ for(int i=60;i>=0;i--)if((x>>i)&1){ if(basis[i])x^=basis[i]; else{ basis[i]=x; ...
0
#include<iostream> #include<algorithm> using namespace std; long n,h,a[1<<17],b[1<<17]; int main() { cin>>n>>h; for(int i=0;i<n;i++)cin>>a[i]>>b[i]; sort(a,a+n);sort(b,b+n); long cnt=0; for(int i=n;i--;) { if(b[i]<a[n-1])break; cnt++; h-=b[i]; if(h<=0)break; } cout<<(cnt+(h>0?(h+a[n-1]-1)/a[n-1]:0))<<en...
0
#include<iostream> #include<algorithm> using namespace std; int main(){ int n, a[100], sum=0; cin>>n; for(int i=0;i<n;i++) cin>>a[i]; sort(a, a+n, greater<int>()); for(int i=0;i<n;i++){ if(i%2==0) sum+=a[i]; else sum-=a[i]; } cout<<sum<<endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; unsigned long long gcd(unsigned long long a, unsigned long long b) { if (a == 0) return b; if (b == 0) return a; return gcd(b % a, a); } unsigned long long lcm(unsigned long long a, unsigned long long b) { return (a * b) / gcd(a, b); } unsigned long long nCr(unsigne...
1
#include <bits/stdc++.h> using namespace std; const long long N = 1e5 + 5; long long factorial = 1; int32_t main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; long long n; cin >> n; long long ans = 0; ans += n / 1 * (n - 1) / 2 * (n - 2) / 3 * (n - 3) / 4 * (n - 4) / 5; ans += n / 1 * (n - 1...
6
#include <bits/stdc++.h> using namespace std; int main() { long long a, b, c, d; cin >> a >> b >> c >> d; if ((d - c == c - b) && (c - b == b - a)) { cout << d + (d - c); } else if (((c * c == b * d) && (b * b == c * a)) && ((d * d) % c == 0)) { cout << (d * d) / c; } else cout << "42"; return 0...
1
#include <bits/stdc++.h> using namespace std; inline int S() { int ret = 0, neg = 0; char c; for (c = getchar(); c < '0' || c > '9'; c = getchar()) if (c == '-') neg = 1; for (; c >= '0' && c <= '9'; c = getchar()) ret = (ret << 3) + (ret << 1) + c - '0'; return neg ? -ret : ret; } const int N = 3e5 +...
2
#include <iostream> using namespace std; int main(){ int A,B,C=0; cin>>A>>B; int D[A]; for(int i=0;i<A;i++){ cin>>D[i]; if(D[i]>=B) C++; } cout<<C; return 0; }
0
#include <bits/stdc++.h> using namespace std; inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; } const int INF = 1 << 29; inline int two(int n) { return 1 << n; } inline int test(int n, int b) { return (n >> b) & 1; } inline void set_bit(int& n, int b) { n |= two(b); } inline void unset_bit(int& n, int b...
3
#include<iostream> #include<cstdio> #include<complex> #include<vector> using namespace std; #define X real() #define Y imag() typedef long double D; typedef complex<D> P; struct L{P a, b;}; const D EPS = 1e-8; int sig(D a, D b = 0) {return a < b - EPS ? -1 : a > b + EPS ? 1 : 0;} bool near(P a, P b) {return !sig(n...
0
#include <bits/stdc++.h> using namespace std; const int MAX = 5001; struct node { pair<int, int> l, r, u, d; node() {} void assign(int id, pair<int, int> hh) { if (id == 0) l = hh; if (id == 1) r = hh; if (id == 2) u = hh; if (id == 3) d = hh; } }; vector<vector<node> > bb; vector<vector<node> >...
3
#include <bits/stdc++.h> using namespace std; const int Max_num_names = 110; int num_names; string names[Max_num_names]; const int Max_N = 40; int n = 26; vector<int> graph[Max_N]; vector<int> ans; bool visited[Max_N]; void dfs(int curr) { visited[curr] = true; for (int i = 0; i < graph[curr].size(); i++) { if ...
3
#include <bits/stdc++.h> using namespace std; void qmax(int &x, int y) { if (x < y) x = y; } void qmin(int &x, int y) { if (x > y) x = y; } inline int read() { char s; int k = 0, base = 1; while ((s = getchar()) != '-' && s != EOF && !(isdigit(s))) ; if (s == EOF) exit(0); if (s == '-') base = -1, s =...
4
#include <bits/stdc++.h> using namespace std; long long x, y, p, q; int main() { int T; cin >> T; while (T-- && cin >> x >> y >> p >> q) { if (x * q == p * y) { puts("0"); continue; } if (p == q || p == 0 || q == 0) { puts("-1"); continue; } long long t = 0; t = max...
1
#include <bits/stdc++.h> using namespace std; int c[128]; int main() { int n, m, ai; memset(c, 0x00, sizeof(c)); scanf("%d%d", &n, &m); for (int i = 0; i < m; i++) { scanf("%d", &ai); c[ai]++; } for (int d = 128; d > 0; d--) { int k = 0; for (int i = 1; i <= 128; i++) k += c[i] / d; if (...
2
#include <bits/stdc++.h> using namespace std; const bool DEBUG = false; template <class T> void print1D(T v) { if (DEBUG) { for (auto e : v) cout << e << " "; cout << endl; } } template <class T> void print1D(T v, int min_incl, int max_incl) { if (DEBUG) { for (int i = min_incl; i <= max_incl; i++) co...
3
// D - Coloring Edges on Tree #include <bits/stdc++.h> using namespace std; #define rp(i,s,e) for(int i=(s);i<(e);++i) int main(){ int N; cin>>N; vector<int> G(N), C(N-1); rp(i, 0, N-1){ int p; cin>>p>>C[i]; C[i]--; G[C[i]] = p-1; } vector<int> colors(N), pre_colors(N); rp(c, 1, N){ int p = G[c]; int ...
0
/****Bismillahir rahmanir rahim****/ #include<bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<long long> vl; template <typename T> void get_vector(T &a) { for(auto &e: a) cin >> e; } template <typename T> void put_vector(T a) { for(auto e :a)cout << e << ...
1
#include <bits/stdc++.h> using namespace std; int main() { map<int, pair<int, int> > mp; map<int, pair<int, int> >::iterator it; pair<int, int> pa; int n; scanf("%d", &n); int c[n]; int p[54][54]; int sum = 0; for (int i = 0; i < n; i++) { scanf("%d", &c[i]); sum += c[i]; } for (int i = 0;...
2
#include <bits/stdc++.h> using namespace std; const int N = 2e6 + 5; long long ex_gcd(long long a, long long b, long long& x, long long& y) { long long tem = a; if (!b) x = 1, y = 0; else { tem = ex_gcd(b, a % b, y, x); y -= a / b * x; } return tem; } long long qpow(long long base, long long n) { ...
3
#include <bits/stdc++.h> using namespace std; typedef struct { int id; int fq; } onl; int main() { int n, k, q; cin >> n >> k >> q; int arn[n + 1]; for (int i = 1; i <= n; i++) cin >> arn[i]; deque<onl> online; for (int i = 1; i <= q; i++) { int a, id; cin >> a >> id; if (a == 1) { onl...
2
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; long long x, y, n, m; long long h[1000005]; void solve() { cin >> n >> m; vector<pair<long long, long long>> v, t; for (long long i = 0; i < n; i += 1) { cin >> x >> y; v.push_back({x, y}); } for (long long i = 0; i < m; i...
4
#include<iostream> #include<cstdio> #define MN 100000 using namespace std; inline int read() { int x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f; } int n,head[MN+5],cnt=0,f[MN+5],v[MN+5],ans=0; struct edge{int to,next;...
0
#include <bits/stdc++.h> using namespace std; int main() { int n, m; int count = 0; int count1 = 0; cin >> m >> n; if (n >= 1 && n <= 16 && m <= n) { int k = n; if (m == 1) { while (n > 1) { n = n - 2; count1++; } cout << count1; return 0; } while (n > 0...
1
#include <bits/stdc++.h> using namespace std; const long long inf = 1e9 + 7; const int nmax = 1e5 + 10; const int eps = 1e-8; const long long infll = 1e15; int main() { ios::sync_with_stdio(false); cin.tie(0); int q; cin >> q; while (q--) { int n, r; cin >> n >> r; set<int> s; for (int i = 0; ...
2
#include <bits/stdc++.h> using namespace std; int f[100]; vector<string> es = { "H", "He", "Li", "Be", "B", "C", "N", "O", "F", "Ne", "Na", "Mg", "Al", "Si", "P", "S", "Cl", "Ar", "K", "Ca", "Sc", "Ti", "V", "Cr", "Mn", "Fe", "Co", "Ni", "Cu", "Zn", "Ga", "Ge", "As", "Se", "Br", "Kr", "Rb", "S...
6
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") #pragma GCC optimization("unroll-loops") const int MOD = 1e9 + 7; const long double PI = 3.1415926535898; const long long INF = LLONG_MAX; int n; int a[(int)1e6 + 5]; vector<int> elements; int ans(int pos) { ...
4
#include <bits/stdc++.h> using namespace std; const int MaxN = 110000; double ans[MaxN]; double pos[MaxN * 2]; void calc(int n, double len, double l) { int ff = 0, rr; double st = 0, en = len; for (rr = 0; pos[rr] + 1e-9 < en; rr++) ; for (; st + 1e-9 < 2 * l;) { double dt = min(pos[rr] - en, pos[ff] - ...
3
#include <bits/stdc++.h> using namespace std; const long long int mxn = 1e5 + 1; string s; char cs[1000][1000]; int main() { long long int n, m, i, z, j, a = 0, r = 1, ans = 0, k = 0, cnt = 0, b = 0; long long int c = 1, x, sm, q, l = 1, y, d = 0, sum = 0, mx = 0, mn = 0; string ss, strn; char ch; cin >> n; ...
2
#include <bits/stdc++.h> using namespace std; class trio { public: long long first, second, third; }; class quad { public: long long first, second, third, fourth; }; class DSU { public: long long *par, *size; DSU(long long n) { par = new long long[n + 1]; size = new long long[n + 1]; for (long lo...
5
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:256000000") using namespace std; const long long inf = 1000000000000000000LL; long long getB(long long x, long long y, long long b) { long long c = x - y; long long d = c / b; long long mn = -inf; long long mx = inf; for (long long i = d - 2; i <= d + 2...
2
#include <bits/stdc++.h> #pragma 03 using namespace std; const int mod = 1e9 + 7; const int mx = INT_MAX / 10; const long double pi = 4 * atan((long double)1); int n; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n; int arr[n << 1]; for (int i = 1; i <= n; i++) arr[i] = i; for ...
2
#include <bits/stdc++.h> using namespace std; int sl[200]; int main() { int i, j, n, m; string s; cin >> s; n = s.size(); for (i = 0; i < n; i++) sl[s[i]]++; int l = 0, r = 200; while (l < r) { while (l < r && sl[l] % 2 == 0) l++; while (l < r && sl[r] % 2 == 0) r--; if (l == r) break; ...
3
#include <bits/stdc++.h> const int inf = 0x3f3f3f3f; const long long INF = 0x3f3f3f3f3f3f3f3fll; using namespace std; bool isp(string str, int len) { for (int i = 0; i < len / 2; i++) { if (str[i] != str[len - i - 1]) return false; } return true; } string judge(char str[]) { string tmp = str; int len = st...
5
#include <bits/stdc++.h> using namespace std; int n, a[100020]; int ans, t; int lg(int x) { if (x == 1) { return 0; } return lg(x / 2) + 1; } int main() { scanf("%d", &n); for (int i = 0; i < n; i++) { int x; scanf("%d", &x); int c = lg(x); int d = 0; if (x != (1 << c)) { d = 1; } if (t < c) { ...
0
#include <bits/stdc++.h> using namespace std; const int maxn = 100010; int n; char a[maxn], b[maxn]; int cnt(char a1, char a2, char b1, char b2) { return (a1 != a2) + (a1 != b1) + (a1 != b2) + (a2 != b1) + (a2 != b2) + (b1 != b2); } int main() { while (scanf("%d", &n) != EOF) { scanf("%s%s", a + 1, b +...
4
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; int n, a[N], id[N], mx[N]; int solve(int L, int R) { if (R - L == 1) return 0; int mid = L + R >> 1, ans = solve(L, mid) + solve(mid, R); mx[mid - 1] = a[mid - 1], mx[mid] = a[mid]; for (int i = mid + 1; i < R; i++) mx[i] = max(mx[i - 1], a[i]...
5
#include <bits/stdc++.h> using namespace std; const int N = 900010; int a, b, c, d; int main() { cin >> a >> b; cin >> c >> d; if (b == d) { return 0 * printf("%d\n", b); } else { for (int i = 0; i <= 1000; i++) for (int j = 0; j <= 1000; j++) { if (b + i * a == d + j * c) { retu...
1