solution
stringlengths
52
181k
difficulty
int64
0
6
#include <bits/stdc++.h> using namespace std; int main() { int flag = 0; scanf("%d", &flag); switch (flag) { case 1: printf("14"); break; case 2: printf("12"); break; case 3: printf("13"); break; case 4: printf("8"); break; case 5: printf("...
1
#include <bits/stdc++.h> using namespace std; vector<pair<int, int> > v; const long long Mod = 1000000007LL; long long AB(long long b, long long n) { if (n < 0) return 0; long long ans = 1; while (n) { if (n & 1) ans = (ans * b) % Mod; n >>= 1; b = (b * b) % Mod; } return ans; } int main() { boo...
4
#include <bits/stdc++.h> using namespace std; template <class T> inline void Max(T &a, T b) { if (a < b) a = b; } template <class T> inline void Min(T &a, T b) { if (a > b) a = b; } inline void add(int &a, int b) { a += b; while (a >= 1000000007) a -= 1000000007; } int pow(int a, int b) { int ans = 1; while...
5
#include<iostream> #define x first #define y second using namespace std; int main(){ pair<double,double>a1,a2,b1,b2; while(cin>>a1.x>>a1.y>>a2.x>>a2.y>>b1.x>>b1.y>>b2.x>>b2.y){ bool f=0; if(((a1.x<=b1.x&&b1.x<=a2.x)||(a1.x<=b2.x&&b2.x<=a2.x)||(b1.x<=a1.x&&a1.x<=b2.x)||(b1.x<=a2.x&&a2.x<=b2.x)) &&((a1...
0
#include <bits/stdc++.h> using namespace std; const int maxn = 100005; int data[maxn], val[maxn], tol[maxn], tor[maxn], n; int seg[maxn << 2]; void modify(int p, int v, int l, int r, int rt) { if (l == r) { seg[rt] = v; return; } int m = (l + r) >> 1; if (p <= m) modify(p, v, l, m, rt << 1); else ...
2
#include <bits/stdc++.h> using namespace std; const int N = 4e5 + 5; map<int, int> nxt[N]; int link[N], len[N], cnt = 1, las = 1, n, id[N], f[N][19]; int s[N]; void insert(int c) { int cur = ++cnt, p = las; len[cur] = len[las] + 1; las = cur; for (; p && !nxt[p][c]; p = link[p]) nxt[p][c] = cur; if (!p) l...
4
#include <bits/stdc++.h> using namespace std; int main(int argc, char const *argv[]) { int n; cin>>n; int a[n],f=1; for (int i = 0; i < n; ++i) { cin>>a[i]; if (a[i]%2==1) { f=0; } } if (f) { cout<<"second\n"; } else { cout<<"first\n"; } return 0; }
0
#include <bits/stdc++.h> using namespace std; const int sz = 3e5 + 10; map<int, int> to[sz]; int ar[sz], q[sz], pr[sz], prsy[sz]; long long an; void dfs(int l, int r) { if (l != r) { int mid = (l + r) >> 1, s = 0, qnt = 1; prsy[0] = -1; for (int a = mid; a >= l; a--) { int sy = ar[a]; if (prsy...
4
#include <bits/stdc++.h> using namespace std; const int N = 3e2 + 10; using ll = long long; int a[N]; ll f[N][N]; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, m; cin >> n >> m; for (int i = 1; i <= n; ++i) cin >> a[i]; memset(f, 0x3f, sizeof(f)); f[0][0] = 0; for (int i = 1; i <= n +...
0
#include <bits/stdc++.h> using namespace std; void init() { long long n, x; cin >> n >> x; vector<long long> a(n); for (long long &i : a) cin >> i; long long s = n - 1; for (auto &x : a) s += x; if (s == x) cout << "YES" << endl; else cout << "NO" << endl; } int32_t main() { std::ios::sync_wit...
2
#include <bits/stdc++.h> using namespace std; const long long int MOD = 1000000007; int N, a[169], c[169], K; long long int M = -10000000000000LL; int ned, prv[169], first[169]; long long int cap[20009], cost[20009], to[20009], nxt[20009], dist[169], pot[169]; void init() { memset(first, -1, sizeof first); ned ...
3
#include <bits/stdc++.h> using namespace std; int test(string s) { int f = s.size() - 1; for (int i = 0; i < s.size(); i++, f--) { if (s.at(i) != s.at(f)) { return 0; } } return 1; } int main() { string s, m = " ", s1; cin >> s; s1 = s; for (char c = 'a'; c <= 'z'; c++) { for (int i = ...
5
#include <bits/stdc++.h> #define fread_siz 1024 inline int get_c(void) { static char buf[fread_siz]; static char *head = buf + fread_siz; static char *tail = buf + fread_siz; if (head == tail) fread(head = buf, 1, fread_siz, stdin); return *head++; } inline int get_i(void) { register int ret = 0; register...
0
#include <bits/stdc++.h> using namespace std; struct Node { double s, b, l, r; } d[525525]; int N, n, m, c, x, y, i, a[200200], b[200200], p[200200]; double cur[200200], r; Node merge(Node l, Node r) { Node b; b.s = l.s + r.s; b.b = max(l.r + r.l, max(l.b, r.b)); b.l = max(l.l, l.s + r.l); b.r = max(r.r, r....
3
#include <cstdio> #include <cstring> #include <algorithm> #include <cstdlib> using namespace std; #define N 100050 int n,a[N]; int gcd(int x,int y) {return y?gcd(y,x%y):x;} void print(int x) { puts((x&1)?"First":"Second"); exit(0); } int main() { scanf("%d",&n); int i; for(i=1;i<=n;i++) scanf("%d",&a[i]); int cas...
0
#include<bits/stdc++.h> using namespace std; int a; string s; int main() { cin>>a; cin>>s; if(a>=3200) cout<<s; else cout<<"red"; return 0; }
0
#include <bits/stdc++.h> using namespace std; struct pt { long double x, y; pt() {} pt(long double _x, long double _y) : x(_x), y(_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); } pt operator*(long double c) const { retur...
2
#include <bits/stdc++.h> using namespace std; long long n, m, i, a[1010], x, y, ans; int main() { cin >> n >> m; for (i = 0; i < n; i++) { cin >> a[i]; } for (i = 0; i < m; i++) { cin >> x >> y; ans += min(a[x - 1], a[y - 1]); } cout << ans << endl; return 0; }
3
#include <bits/stdc++.h> using namespace std; int main() { int n, a, b, z = 0; cin >> n >> a >> b; int chores[n]; for (int i = 0; i < n; i++) cin >> chores[i]; sort(chores, chores + n); z = chores[b] - chores[b - 1]; cout << z << endl; return 0; }
1
#include <bits/stdc++.h> using namespace std; int main() { vector<long long int> arr; long long int temp, dist, diff1, diff2; for (int i = 0; i < 3; i++) { cin >> temp; arr.push_back(temp); } cin >> dist; sort(arr.begin(), arr.end()); diff1 = arr[0] + dist - arr[1]; diff2 = arr[0] + 2 * dist - a...
1
#include <bits/stdc++.h> int a[100010]; int b[100010]; int c[100010]; int main(int argc, char* argv[]) { int i, j, n; scanf("%d", &n); for (i = 1; i <= n; ++i) { scanf("%d", &a[i]); } for (i = 1; i <= n; ++i) { scanf("%d", &b[i]); } for (i = 1; i <= n; ++i) { c[a[i]] = b[i]; } for (i = 1; ...
6
#include "bits/stdc++.h" using namespace std; const int N = 1e5 + 5; int n; int a[N] , b[N]; int c[N] , d[N]; map < int , int > edges[N]; queue < pair < int , int > > q; int comp[N]; int find(int node){ if(comp[node] == node){ return node; } return comp[node] = find(comp[node]); } void insert(int a , int b){ a = ...
0
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; i++) using namespace std; using ll = long long; using P = pair<int, int>; int main() { int n, m; cin >> n >> m; vector<string> a(n), b(m); rep(i, n) cin >> a[i]; rep(i, m) cin >> b[i]; rep(i, n - m + 1) { rep(j, n - m + 1) { bool ...
0
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 100; struct Edge { int v, nxt; int id; Edge() {} Edge(int vv, int next) { v = vv; nxt = next; } } edge[N << 1]; int idx; int head[N]; void addEdge(int u, int v, int id) { edge[++idx] = Edge(v, head[u]); edge[idx].id = id; head[u] ...
3
#include <iostream> using namespace std; int main() { int n; while (cin >> n && n != 0) { int A=0, B=0, a, b; for (int i=0; i<n; i++) { cin >> a >> b; if (a > b) { A += a+b; } else if (a < b) { B += a+b; } else { A += a; B += b; } } cout << A << " " << B << endl; } }
0
#include <bits/stdc++.h> using namespace std; int cnt[100005], vis[100005], steps[100005]; int main() { int n, res = 2000000000, x, y; scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d", &x); queue<pair<int, int> > q; q.push(make_pair(x, 0)); while (!q.empty()) { x = q.front().first;...
3
// 6/2 // 2-6-4. 素数のこすう // エラトステネスの篩 #include <bits/stdc++.h> #define rep(i, n) for (ll i = 0; i < (n); ++i) using namespace std; using ll = long long; using P = pair<int, int>; const int INF = 1e9; // Sieve of Eratosthenes // https://youtu.be/UTVg7wzMWQc?t=2774 struct Sieve { int n; vector<int> f, primes; Sieve...
0
#include <bits/stdc++.h> using namespace std; inline int in() { int x; scanf("%d", &x); return x; } int n, m, k; int main() { n = in(); m = in(); k = in(); int lane = k / (2 * m); int rem = k % (2 * m); if (rem == 0) { cout << lane << ' ' << m << ' ' << 'R' << endl; } else { int row = rem / ...
1
#define _USE_MATH_DEFINES #define INF 100000000 #include <iostream> #include <sstream> #include <cmath> #include <cstdlib> #include <algorithm> #include <queue> #include <stack> #include <limits> #include <map> #include <string> #include <cstring> #include <set> #include <deque> #include <bitset> #include <list> using...
0
#include <bits/stdc++.h> using namespace std; long long a, b, c, L, s, t; long long Calc(long long a, long long b, long long c, long long L) { long long tmp = 0; if (b + c > a) tmp = b + c - a; if (tmp > L) return 0; a += tmp; L -= tmp; long long Res = 0; for (long long i = 0; i <= L; i++) { tmp = min...
3
#include <bits/stdc++.h> using namespace std; void read(int &x) { scanf("%d", &x); } void read(long long int &x) { scanf("%I64d", &x); } void read(long long int &a, long long int &b) { scanf("%I64d %I64d", &a, &b); } void read(long long int &a, long long int &b, long long int &c) { scanf("%I64d %I64d %I64d", &a, &b, ...
4
#include <iostream> using namespace std; int main(){ int H,W,i,j; cin >> H >> W; string s[H]; for (i=0;i<H;++i) { cin >> s[i]; } for (i=0;i<H;++i) { for (j=0;j<W;++j) { if (s[i][j]=='#') { if ((i==0 || s[i-1][j]=='.') && (i==H-1 || s[i+1][j]=='.') && (j==0 || s[i][j-1]=='.') && (j==W...
0
#include <bits/stdc++.h> using namespace std; int n; bool q; char c[10]; string s[6]; int main() { cin >> n; for (int i = 0; i < n; i++) { cin >> c[i]; } s[0] = "jolteon"; s[1] = "flareon"; s[2] = "umbreon"; s[3] = "leafeon"; s[4] = "glaceon"; s[5] = "sylveon"; if (n == 6) { cout << "espeon"...
1
#include <bits/stdc++.h> using namespace std; char input[1000001]; int main() { cin >> input; stack<char> s; s.push(input[strlen(input) - 1]); for (int i = strlen(input) - 2; i >= 0; i--) { if (input[i] >= s.top()) { s.push(input[i]); } } while (!s.empty()) { cout << s.top(); s.pop(); ...
1
#include <bits/stdc++.h> using namespace std; const int MAXN = 100005; multiset<long long> Inc[MAXN], Max, Min; long long T[MAXN], Cmin[MAXN], Cmax[MAXN], G[MAXN], Self[MAXN], Els[MAXN]; int C[MAXN], Fa[MAXN], N, Q; long long Smin(int x) { return (*Inc[x].begin()) + G[x]; } long long Smax(int x) { return (*Inc[x].rbegi...
4
#include <iostream> #include <algorithm> #include <vector> #include <stack> using namespace std; int n,r; void shuffle(vector<int> &v,int c){ stack<int> A; stack<int> B; for(int i = v.size()-1; i >= 0; i--){ if(i<v.size()/2){ B.push(v[i]); } else A.push(v[i]); } v.clear(); while(1){ for(int i = ...
0
#include <bits/stdc++.h> using namespace std; const int maxn = 554400; char ss[maxn]; long long a, n; long long x[maxn], s[maxn]; long long h[maxn]; int main() { cin >> a; cin >> ss; n = (long long)strlen(ss); for (int i = 0; i < n; i++) x[i + 1] = ss[i] - '0', s[i + 1] = s[i] + x[i + 1]; long long i, j; ...
1
#include<bits/stdc++.h> using namespace std; typedef long long ll; ll dp[60][60][3000]; int main(){ int n,a;cin>>n>>a; int x[60]; for(int i=0;i<n;i++){ cin>>x[i]; } dp[0][0][0]=1; for(int i=0;i<n;i++){ for(int j=0;j<=i;j++){ for(int k=0;k<=2600;k++){ dp[i+1][j][k]+=dp[i][j][k]; dp[i+1][j+1][k+x[i]]...
0
#include<iostream> using namespace std; int main() { int x; cin >> x; if((x/100)*5>=x%100) cout <<"1"; else cout << "0"; return 0; }
0
#include <bits/stdc++.h> using namespace std; typedef long long ll; bool f[100001]; int c[100002]; int main() { for (int i=2; i<=100000; i++) { if (!f[i]) { for (int j=i+i; j<=100000; j+=i) f[j] = true; } } for (int i=3; i<=100000; i+=2) { if (!f[i] && !f[(i+1)/2]) c[i]++; } ...
0
#include <bits/stdc++.h> using namespace ::std; uint64_t to_dec(vector<int> &v) { uint64_t ans = 0; for (int i = 0; i < v.size(); i++) { ans <<= 1; if (v[i]) ans |= 1; } return ans; } int main() { vector<uint64_t> P; P.reserve(3000); for (int len = 2; len <= 60; len++) { vector<int> v(len, 1);...
2
#include <bits/stdc++.h> using namespace std; int main() { int n = 0; string s; cin >> s; int pos = 0; int t; for (int i = 0; i < s.size(); i++) { t = s[i] - 'a'; if (t > pos) { if (t - pos > 13) { n += 13 - (t - pos) % 13; } else { n += t - pos; } } else { ...
1
#include <bits/stdc++.h> using namespace std; int main() { int a[5], sum = 0, minn = 1000; for (int i = 0; i < 5; ++i) { cin >> a[i]; sum += a[i]; } sort(a, a + 5); minn = sum; for (int i = 4; i >= 1; --i) { if (a[i] == a[i - 1] && a[i - 1] == a[i - 2] && i >= 2) { if (sum - a[i] * 3 < min...
1
#include <bits/stdc++.h> using namespace std; int main() { int n, m, q; cin >> n >> m >> q; int a[n][m]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { cin >> a[i][j]; } } int c = 0, mx; vector<int> v(n, 0); for (int i = 0; i < n; i++) { mx = INT_MIN; c = 0; for (i...
2
#include <bits/stdc++.h> using namespace std; inline int Get() { int res = 0, q = 1; char ch = getchar(); while ((ch < '0' || ch > '9') && ch != '-') ch = getchar(); if (ch == '-') q = -1, ch = getchar(); while (ch >= '0' && ch <= '9') res = res * 10 + ch - '0', ch = getchar(); return res * q; } const doubl...
3
#include<iostream> #include<algorithm> using namespace std; int main(){ int n; int m[40]; int s[40]; int p[21],d[21]; int f,tmp; while(1){ cin >> n; if(!n)break; for(int i=0;i<n;i++){ cin >> m[i]; s[i] = 0; for(int j=0;j<21;j++)p[j] = 0; for(int j=0;j<21;j++)d[j] = 1; ...
0
#include <bits/stdc++.h> using namespace std; int n, numbit[60], dp[110][(1 << 17) + 10], ara[110], dir[110][(1 << 17) + 10]; int prms[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59}; void print(int pos, int mask) { if (pos == 0) return; print(pos - 1, (mask & ~(numbit[dir[pos][mask]]))); cou...
4
#include <bits/stdc++.h> using namespace std; void solve() { int n; cin >> n; string s, t; cin >> s >> t; vector<int> ans; for (int i = 0; i < n; i++) { if (s[i] == t[i]) continue; for (int j = i + 1; j < n; j++) { if (s[j] == t[i]) { for (int w = j - 1; w >= i; w--) { char t...
2
#include <bits/stdc++.h> //#include <sys/resource.h> #define initrand mt19937 mt_rand(time(0)); #define rand mt_rand() #define int long long #define MOD 1000000007 #define INF 1000000000 #define mid(l, u) ((l+u)/2) #define rchild(i) (i*2 + 2) #define lchild(i) (i*2 + 1) #define mp(a, b) make_pair(a, b) #define lz lazup...
5
#include <bits/stdc++.h> using namespace std; const int N = 1010, M = 12; int n, m, u, v, dp[N][N][M + 1], dp2[N][(1 << M)], dp3[N][(1 << M)]; vector<int> arr, g[N], t[M + 1]; int fres = 1; int solve() { int idx = 0, all = 0, sz, mask, res = 0; for (int i = 0; i < (int)arr.size(); i++) { for (int node = 1; node...
6
#include <bits/stdc++.h> char s[(1 << 17)]; int ds = (1 << 17); char ma[5200][5200]; inline char readch() { if (ds == (1 << 17)) { fread(s, (1 << 17), 1, stdin); ds = 0; } ds++; return s[ds - 1]; } inline int cmmmc(int a, int b) { int r; while (b > 0) { r = a % b; a = b; b = r; } ret...
4
#include <bits/stdc++.h> using namespace std; template <typename T, typename U> inline void smin(T &a, U b) { if (a > b) a = b; } template <typename T, typename U> inline void smax(T &a, U b) { if (a < b) a = b; } inline void getint(int &first) { char c; while (c = getchar(), c > '9' || c < '0') ; for (fi...
3
#include <bits/stdc++.h> using namespace std; int a, b, k, n; int c[100005], cn; bool isp[100005]; long long ans; void dfs(int g, int cc, long long s) { if (s > n) return; if (g == cn) { if (cc & 1) ans -= n / s; else ans += n / s; return; } dfs(g + 1, cc, s); dfs(g + 1, cc + 1, s * c[...
4
#include <bits/stdc++.h> using namespace std; int main() { long long int n, c; cin >> n >> c; vector<long long int> a(n - 1), b(n - 1); for (int i = 0; i < n - 1; i++) { cin >> a[i]; } for (int i = 0; i < n - 1; i++) { cin >> b[i]; } cout << 0 << " "; long long int s = 0, e = c, snew, enew; ...
5
#include <bits/stdc++.h> using namespace std; int cnt = 0, cntq = 0, ans = 0; int forw[5001][5001], back[5001][5001]; string str; int main() { cin >> str; int len = str.length(); for (int i = 0; i < len; i++) { cnt = cntq = 0; if (str[i] == ')') { continue; } if (str[i] == '(') { cnt =...
1
#include <bits/stdc++.h> using namespace std; int a[4]; void input() { scanf("%d%d%d%d", &a[0], &a[1], &a[2], &a[3]); sort(a, a + 4); if (a[0] + a[3] == a[1] + a[2] || a[0] + a[1] + a[2] == a[3]) printf("YES\n"); else printf("NO\n"); } int main() { input(); }
1
#include <bits/stdc++.h> using namespace std; int C[26]; int main() {string S; cin >> S; for (auto c : S) ++C[c - 'a']; for (int c : C) if (c > 1) puts("no"), exit(0); puts("yes");}
0
#include <bits/stdc++.h> using namespace std; bool isPrime(long long int n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; for (long long int i = 5; i * i <= n; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } unsigned int countB...
2
#include<iostream> #include<vector> #include<list> #include<string> #include<algorithm> #include<map> #include<cmath> #include<set> using namespace std; int main() { int n; while (cin >> n&&n != 0) { string u,h; string a[50]; int k = 1000; for (int i = 0; i < n; i++) { cin >> u; h = ""; for (int i = ...
0
#include <bits/stdc++.h> const int N = 4e5 + 5; using namespace std; int gcd(int a, int b) { return (b == 0 ? a : gcd(b, a % b)); } int lcm(int a, int b) { return (a * b) / gcd(a, b); } int n, a[N], I, sum, fro[N], bak[N], res = INT_MAX, cnt, t; int main() { ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); cin...
3
#include <bits/stdc++.h> using namespace std; const double eps = 1e-9; const int inf = INT_MAX; const int N = 100004; const long long mod1 = 1000000007; const long long mod2 = 1000000009; const long long mod3 = inf; long long x1[N], x2[N], x3[N], k; int n; int main() { cin >> n >> k; x1[0] = x2[0] = x3[0] = 1; fo...
5
#include <bits/stdc++.h> using namespace std; const int MAX = 1e4 + 5; int l; long long n, d[MAX]; map<int, bool> dp; bool F(long long n) { if (dp.count(n)) return dp[n]; bool ans = 0; for (int i = 1; i <= l && d[i] < n; i++) if (n % d[i] == 0) ans |= !F(n / d[i]); return dp[n] = ans; } int main() { scanf...
1
// // Created by maze on 2019/11/03. // #include <bits/stdc++.h> using namespace std; #define INF_LL (int64)le18 #define INF (int32)le9 #define REP(i, n) for(int64 i = 0; i < (n); i++) #define FOR(i, a, b) for(int64 i = (a); i < (b); i++) #define all(x) x.begin(), x.end() #define fs first #define sc second using int...
0
#include <iostream> #include <cstdio> using namespace std; int n,m; int trip[100000]; int fare_r[100000]; int ic[100000]; int fare_i[100000]; long long mycount[100000]={}; long long rui[100000]={}; void countcreate(void){ int prev,next; prev=trip[0]-1; for(int lp=1;lp<m;lp++){ next=trip[lp]-1; if(prev<next){ ...
0
#include<iostream> #include<algorithm> using namespace std; string s; int ans,l,r,n,k,cnt; int main() { cin>>n>>k>>s; for(;r < s.size();r++){ if(s[r]=='0'){ if(r==0 || s[r-1]=='1') cnt++; } if(cnt > k){ while(l < s.size() && s[l]=='1') l++; while(l < s.size() && s[...
0
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); int n, q; cin >> n >> q; vector<int> src(n); for (int i = 0; i < n; ++i) cin >> src[i]; const int MAX = (int)1e5; int ts = 1; while (ts < MAX) ts *= 2; enum TYPE { FLIP, SET, NOTHING }; const pair<TYPE, uint...
5
#include <bits/stdc++.h> using namespace std; const long long logN = 20; const long long M = 1000000007; const long long INF = 1e12; int pow1(int a, int b) { int res = 1; while (b > 0) { if (b & 1) { res = res * a; } a = a * a; b >>= 1; } return res; } int main() { long long t = 1; whi...
3
//hail to jwalaji #include<bits/stdc++.h> using namespace std; typedef long long int lli; lli h,w,a,b,f,t,e; set<pair<lli,lli>> st; multiset<lli> ms; int main() { ios::sync_with_stdio(false); cin.tie(NULL); cin>>h>>w; for(lli i=0;i<w;i++){ st.insert({i,i}); ms.insert(0); } for(ll...
0
#include<bits/stdc++.h> using namespace std; #define LL long long LL a,b,c; LL calu(LL x) { LL cnt=0; while(x) ++cnt,x/=10; return cnt; } int main() { LL t; cin>>t; while(t--) { cin>>a>>b>>c; LL x,y,z; x=1; while(calu(x)<c) { x<<=1; ...
2
#include <bits/stdc++.h> using namespace std; int n, a[200000]; bool st[200000][2]; long long memo[200000][2]; long long solve(int node, int rev) { if (node < 0 || node >= n) return 0; if (st[node][rev]) return 0x3f3f3f3f3f3f3f3fll; if (node == 0) return 0; long long& val = memo[node][rev]; if (val != 0xc0c0c...
2
#include <bits/stdc++.h> #pragma GCC optimize("Ofast,unroll-loops") using namespace std; const int MAXN = 2e5 + 51; struct Query { int x, y, id; inline bool operator<(const Query &rhs) const { return y < rhs.y; } }; Query qry[MAXN]; int n, m, x, y, tp, ptr, l, r, mid, rr; int c[MAXN], pr[MAXN], st[MAXN], res[MAXN];...
5
#include <bits/stdc++.h> using namespace std; const int MOD = 1000000007; const int N = 100005; const double PI = 4 * atan(1); const long long MAX = 9223372036854775807; int dx[] = {1, -1, 0, 0, 1, -1, 1, -1}; int dy[] = {0, 0, 1, -1, 1, 1, -1, -1}; long long gcd(long long a, long long b) { return (b == 0 ? a : gcd(b, ...
4
#include <bits/stdc++.h> using namespace std; void Digvijay() { long long x1, y1, z1, x2, y2, z2; cin >> x1 >> y1 >> z1 >> x2 >> y2 >> z2; long long n = x1 + y1 + z1; long long ans = 0; long long v1 = min(z1, y2); ans += 2 * v1; if (z1 >= y2) { z1 -= y2; y2 = 0; } else { z1 = 0; } long l...
2
#include <bits/stdc++.h> using namespace std; const int maxn = ((int)2e5) + 5; set<int> numbers; long long int dp[501][501]; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); dp[0][0] = 1; int n, m, k; cin >> n >> m >> k; int f[3] = {0}; string str[m]; for (int i = 0; i < m; i++) { ci...
6
#include <bits/stdc++.h> using namespace std; double sumx[29], sumy[29]; double chu, ans; char sz1[200006], sz2[200006]; int main() { int n, a, b, i; scanf("%d", &n); scanf("%s%s", sz1 + 1, sz2 + 1); for (i = 1; i <= n; i++) chu += i * i; for (i = 1; sz1[i]; i++) { a = sz1[i] - 'A'; sumx[a] += i; ...
3
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf("%d", &n); int ans = 0; int cur = 0; int pr = -1; while (n--) { int x; scanf("%d", &x); if (pr == -1 || x <= 2 * pr) { ++cur; } else { cur = 1; } if (cur > ans) { ans = cur; } pr = x; ...
2
#include <bits/stdc++.h> using namespace std; int main() { long long t, n, l = 0, r = 0, ans = 0, sum = 0, x, y, a, b, k, pos = 0; string s; cin >> n >> k; cin >> s; while (pos < n - 1) { for (int i = pos; i <= pos + k; i++) { if (s[i] == '1') l = i; } if (pos == l) { cout << -1; ...
1
#include <bits/stdc++.h> using namespace std; const int inf = 1 << 30; char buf[1000]; string nextLine(int length = 100) { cin.getline(buf, length); string s(buf); return s; } string next(int length = 100) { string tmp; cin >> tmp; return tmp; } int nextInt() { int tmp; scanf("%d", &tmp); return tmp; ...
1
#include <bits/stdc++.h> using namespace std; long long n, a[300005], b[300005], dp[300005][3]; void Solve() { cin >> n; for (long long i = 1, _b = n; i <= _b; i++) cin >> a[i] >> b[i]; dp[1][0] = 0; dp[1][1] = b[1]; dp[1][2] = b[1] * 2; for (long long i = 2, _b = n; i <= _b; i++) { if (a[i] == a[i - 1]...
4
#include <bits/stdc++.h> using namespace std; int a[110]; int main() { int n, md = 0; cin >> n; for (int i = 0; i < n; i ++){ int d; cin >> d; a[d] ++; md = max(d, md); } int r = (md + 1) / 2; for (int i = 0; i < r; i ++){ if (a[i] >= 1) return cout << "Impossible", 0; ...
0
#include <bits/stdc++.h> using namespace std; namespace Fast { inline char getc() { static char buf[1 << 21], *p1 = buf, *p2 = buf; return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2) ? EOF : *p1++; } inline void read() {} template <typename T1, typename... T2> i...
2
#include <bits/stdc++.h> using namespace std; bool debug = 0; int n, m, k; int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0}; string direc = "RDLU"; long long ln, lk, lm; void etp(bool f = 0) { puts(f ? "YES" : "NO"); exit(0); } void addmod(int &x, int y, int mod = 1000000007) { assert(y >= 0); x += y; if (x >...
4
#include <bits/stdc++.h> using namespace std; template <typename T> void read(T &t) { t = 0; char ch = getchar(); int f = 1; while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } do { (t *= 10) += ch - '0'; ch = getchar(); } while ('0' <= ch && ch <= '9'); t *= f; } tem...
5
#include <bits/stdc++.h> using namespace std; void chkmax(int &x, int y) { x = x > y ? x : y; } int dp[10005]; int n, m, c0, d0; int main() { scanf("%d%d%d%d", &n, &m, &c0, &d0); memset(dp, 0, sizeof(dp)); for (int i = c0; i <= n; i++) dp[i] = i / c0 * d0; for (int i = 0; i < m; i++) { int a, b, c, d; s...
3
#include <bits/stdc++.h> using namespace std; using ll = long long; const int INF = 0x3F3F3F3F; const int maxn = 2e5 + 555; const int MOD = 1e9 + 7; int32_t main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cout.precision(10); cout << fixed; string a; cin >> a; vector<int> V; for (int i =...
6
#include <bits/stdc++.h> using namespace std; long long n = 2 * 1e5 + 1; long long root = 0; vector<vector<long long>> adj(n); vector<long long> c, vi(n); vector<bool> visited(n); void dfs(long long s, long long anc) { if (visited[s]) return; visited[s] = true; for (auto u : adj[s]) { if (visited[u] == true &...
2
#include<bits/stdc++.h> #define F first #define S second #define int long long #define double long double using namespace std; typedef pair<int,int> P; typedef pair<int,P> iP; typedef pair<P,int> Pi; typedef pair<P,P> PP; double eps=1e-8; int mod=1e9+7; int inf=1LL<<55; priority_queue<P,vector<P>,greater<P> > pq; int...
0
#include <bits/stdc++.h> bool debug = 0; const long long MOD = 1000000007; const double PI = acos(-1.0); const double eps = 1e-9; using namespace std; vector<int> v[5100]; int n, m; int t[5100]; int dist(int a, int b) { if (b >= a) return b - a; return n - a + b; } int main() { cin >> n >> m; int a, b; for (i...
4
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for (int i = 0; i < (n); i++) #define all(v) begin(v),end(v) using ll = long long; int main() { int h,w;cin>>h>>w; vector<vector<string>> s(h,vector<string>(w)); rep(i,h)rep(j,w)cin>>s[i][j]; rep(i,h)rep(j,w){ if(s[i][j]=="snuke")cout<<char('A...
0
#include<iostream> using namespace std; int main() { int n, m; cin >> n; //数列a int a[n]; for( int i = 0; i < n; i++ ) cin >> a[i]; cin >> m; //数列b int b[m]; for( int i = 0; i < m; i++ ) cin >> ...
0
#include <bits/stdc++.h> using namespace std; string s; int n, k; int dp[1005][3005]; int ans[1000][3005]; int32_t main() { cin >> n >> k; memset(dp, 0, sizeof dp); cin >> s; dp[0][k] = 1; for (int i = 1; i <= n; i++) { if (s[i - 1] == 'W') { for (int j = 1; j < 2 * k; j++) { if (dp[i - 1][j...
5
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; char c = 'a'; for (int i = s.size() - 1; i >= 0; i--) { if (s[i] >= c) { c = s[i]; continue; } else { s.erase(i, 1); }; }; cout << s; return 0; }
3
#include <bits/stdc++.h> #pragma GCC optimize("O3") #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") using namespace std; long long N = 1234567891, M = 251, N2 = 1234567891; long long i, j; long long x, y, z, n, m, k, l, r, t, ma = 0, ans, x2, y2, x3, y3, x4, y4, f, ...
5
#include <algorithm> #include <cstdio> #include <iostream> using namespace std; int straight(int[]); int main() { int ans, h[5]; while(scanf("%d,%d,%d,%d,%d", &h[0], &h[1], &h[2], &h[3], &h[4])!=EOF) { ans=0; for(int i=0; i<4; i++) { for(int j=i+1; j<5; j++) { if(h[i]==h[j]) ans++; } } swi...
0
#include <bits/stdc++.h> using namespace std; int a, b, k, t; int dp[2][210010], sum[210010]; int main() { scanf("%d%d%d%d", &a, &b, &k, &t); dp[0][0] = 1; for (int i = 1; i <= t; i++) { for (int j = 0; j < 210010; j++) sum[j] = ((j > 0 ? sum[j - 1] : 0) + dp[(i - 1) % 2][j]) % 1000000007; for (int ...
4
#include <bits/stdc++.h> using namespace std; char a[105][105]; int n, m; int pan(int x, int y) { if (x >= 0 && x < n && y >= 0 && y < m) return 1; else return 0; } int judge(int k, int x, int y) { int ans = 0; if (x - 1 >= 0) if (a[x - 1][y] == '*') ans++; if (y - 1 >= 0) if (a[x][y - 1] == '...
2
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:64000000") using namespace std; int n, A, B, r[200000]; pair<int, int> a[200000]; int main() { cin >> n >> A >> B; for (int i = 0; i < n; ++i) { scanf("%d", &a[i].first); a[i].second = i; if (A < B) a[i].first *= (-1); } if (A != B) sort(a, a ...
3
#include <bits/stdc++.h> using namespace std; long long cols[1000001] = {0}; long long rows[1000001] = {0}; int mat[1010][1010] = {{0}}; class cmp { public: bool operator()(long long &p1, long long &p2) { return p2 > p1; } }; int main() { ios_base::sync_with_stdio(false); rows[0] = cols[0] = 0; int n, m, k, p;...
2
#include <bits/stdc++.h> using namespace std; int main() { set<string> ans; int aa; cin >> aa; string a[aa]; for (int z = 0; z < aa; z++) { cin >> a[z]; ans.insert(a[z]); } for (int y = aa - 1; y > -1; y--) { if (ans.find(a[y]) != ans.end()) { cout << a[y] << endl; ans.erase(a[y]);...
2
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); long long int n, m; cin >> n >> m; long double ans = numeric_limits<long double>::min(); for (int i = 0; i < m; i++) { long double x, d; cin >> x >> d; if (d < 0) { long double val; if (n % 2 =...
3