solution
stringlengths
52
181k
difficulty
int64
0
6
#include <bits/stdc++.h> using namespace std; const int N = 200005, T = 51; int sgn(int x) { return x ? (x > 0 ? 1 : -1) : 0; } struct arrow *null; struct arrow { int sx, sy, tx, ty, dx, dy; arrow *to[T]; long long dis[T]; arrow() { to[0] = NULL; } void init() { scanf("%d%d%d%d", &sx, &sy, &tx, &ty); ...
4
#include <algorithm> #include <cmath> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> using ll = long long; #define rep(i, n) for (int i = 0; i < n; i++) #define repk(i, k, n...
0
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { if (b == 0) return a; return gcd(b, a % b); } long long binexp(long long x, long long n, long long m) { if (!n) return 1; else if (n & 1) return (x % m) * binexp((x % m) * (x % m), n / 2, m) % m; else if (!(n & 1))...
2
#include <bits/stdc++.h> using namespace std; template <class t> inline t read(t &x) { char c = getchar(); bool f = 0; x = 0; while (!isdigit(c)) f |= c == '-', c = getchar(); while (isdigit(c)) x = (x << 1) + (x << 3) + (c ^ 48), c = getchar(); if (f) x = -x; return x; } template <class t> inline void wr...
4
#include <bits/stdc++.h> using ll = long long; using namespace std; const int N = 1e5 + 5; const ll mx = 55; const ll mod = 1e9 + 7; ll m, n, t, k, c[N], ans, b[N], d[N], tong, a[N]; vector<ll> kq; vector<pair<ll, ll> > pr; priority_queue<pair<ll, pair<ll, ll> >, vector<pair<ll, pair<ll, ll> > >, greater...
5
#include <bits/stdc++.h> using namespace std; template <class T> inline T min(T a, T b, T c) { return min(min(a, b), c); } template <class T> inline T max(T a, T b, T c) { return max(max(a, b), c); } template <class T> inline T min(T a, T b, T c, T d) { return min(min(a, b), min(c, d)); } template <class T> inlin...
1
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6, Mod = 1e9 + 7; int f[maxn], ff[maxn], dp[maxn], dp2[maxn], dp3[maxn], ans; string s, t, st; int32_t main() { cin >> s >> t; st = t + '$' + s; int curr = 0; for (int i = 1; i < st.size(); i++) { while (curr != 0 && st[curr] != st[i]) curr = ...
2
#include <bits/stdc++.h> using namespace std; int A[100005], B[100005]; int l = -1e9, r = 1e9, n; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d", &A[i]); for (int i = 1; i <= n; i++) scanf("%1d", &B[i]); for (int i = 5, minv, maxv, fg; i <= n; i++) { minv = min(min(min(A[i - 1], A[i -...
4
#include <bits/stdc++.h> using namespace std; long long int gcd(long long int a, long long int b) { if (a == 0) return b; if (b == 0) return a; long long int r; while (b > 0) { r = a % b; a = b; b = r; } return a; } int main() { long long int i, j, k, l, m, n, o, p, q, r, s, t, a[1000000]; c...
4
#include <algorithm> #include <array> #include <bitset> #include <cassert> #include <climits> #include <cstdint> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <memory> #include <numeric> #i...
1
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; const int N = 100005; int n, m; vector<int> g[N]; int p[N]; int lvl[N], sz[N]; ll sums[N]; void prec_all(int u) { sz[u] = 1; for (int v : g[u]) if (v != p[u]) { p[v] = u; lvl[v] = lvl[u] + 1; prec_all(v...
5
#include <bits/stdc++.h> using namespace std; const int maxn = 100001; long long a[maxn]; long long f[maxn]; int n; void enter() { cin >> n; for (int i = (1), _b = (n + 1); i < _b; ++i) cin >> a[i]; } void solve() { long long N = n; f[1] = (N - a[1] + 1) * a[1]; for (int i = (2), _b = (n + 1); i < _b; ++i) { ...
5
#include <bits/stdc++.h> using namespace std; #pragma GCC target("avx2") #pragma GCC optimization("O3") #pragma GCC optimization("unroll-loops") const long long INFll = 1e18; const int INFint = 1e9; const long long MOD = 1e9 + 7; void needForSpeed() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } bool ...
4
#include <bits/stdc++.h> int main() { unsigned long long int n, T; long double c; std::cin >> n >> T >> c; unsigned int *a = new unsigned int[n]; for (unsigned int i = 0; i < n; i++) { std::scanf("%u", &a[i]); } unsigned long long int sum = 0; long double real, approx, error, mean = 0.0L; for (uns...
2
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; void solve(int tc) { int n; cin >> n; string a, b; cin >> a >> b; vector<int> ans; int low = 0, high = n - 1; int count = 0; int trueptr = n - 1; while (trueptr > 0) { int end, start; if (count % 2 == 0) { end = low; ...
3
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; int n; long long sz[N][2]; int fa[N][2]; int find(int u, int x) { return u == fa[u][x] ? u : fa[u][x] = find(fa[u][x], x); } inline void Union(int u, int v, int x) { int f1 = find(u, x), f2 = find(v, x); if (f1 != f2) { fa[f2][x] = f1; s...
4
#include <bits/stdc++.h> const double PI = 3.141592653589793238460; using namespace std; vector<int> ar[100001]; int in[100001], low[100001], vis[100001], timer; bool hasBridge; vector<pair<int, int> > edgeList; void dfs(int node, int par) { vis[node] = 1; in[node] = low[node] = timer++; for (int child : ar[node]...
5
#include <bits/stdc++.h> using namespace std; int main() { int n, x, y; cin >> n >> x >> y; double d = ceil(double(y) * double(n)) / 100.0; int f = ceil(d); cout << max((f - x), 0); return 0; }
1
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); string s; cin >> s; int n = s.length(); vector<vector<int>> dp(n+1, vector<int>(2)); dp[0][1] = 1; for(int i = 1; i <= n; i++) { for(int c = 0; c < 2; c++) { int& ans = dp[i][c] = (int) 1e9; int...
0
#include<bits/stdc++.h> using namespace std; #define ll long long namespace io{ const int l=1<<20; char buf[l],*s,*t; inline char gc(){ if(s==t){ t=(s=buf)+fread(buf,1,l,stdin); return s==t?EOF:*s++; } return *s++; } char c; template<class IT>inline void gi(IT &x){ x=0;c=gc();while(c<'0'||c>'9')c=gc...
0
#include <bits/stdc++.h> using namespace std; mt19937_64 random_num( chrono::high_resolution_clock::now().time_since_epoch().count()); const int MOD = 1000000007; const int base = 26; int n; vector<int> ke[100001]; int d[100001]; double res; void DFS(int u, int pa) { d[u] = d[pa] + 1; for (int v : ke[u]) if...
3
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 10, inf = 1e9; const long double pi = 3.14159265; int t, n; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> t; while (t--) { cin >> n; for (int i = 2 * n; i < 4 * n; i += 2) cout << i << " "; cout << endl; ...
1
#include <bits/stdc++.h> using namespace std; string alp = "abcdefghijklmnopqrstuvwxyz"; string x, s, t; int dp[2][55][30] = {}, dp2[1010][55][55]; void solve(string &a, int i) { int j, k, l, r; for (j = 0; j <= a.size(); j++) { string b = a.substr(0, j); for (k = 0; k < 26; k++) { b.push_back(alp[k])...
4
#include<cstdio> int main(){ int n,k; scanf("%d%d",&n,&k); if((n+1)/2>=k)printf("YES\n"); else printf("NO\n"); return 0; }
0
#include <bits/stdc++.h> using namespace std; inline long long read() { char c = getchar(); long long x = 0; while (c < '0' || c > '9') c = getchar(); while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar(); return x; } long long cnt[500005]; vector<long long> v; unordered_map<long long, long long> f...
4
#include <bits/stdc++.h> using namespace std; int main() { int n; while (cin >> n, n) { int ans = 0; for (int i = 0; i <= n; ++i) { for (int j = i + 2; j <= n; ++j) { if (j * (j + 1) / 2 - i * (i + 1) / 2 == n) ans++; } } cout << ans << endl; } }
0
#include <bits/stdc++.h> using namespace std; const int INF = 2e9; const long long LINF = 2e16; const int magic = 348; const int MOD = 998244353; const double eps = 1e-10; const double pi = acos(-1); struct fastio { static const int S = 1e7; char rbuf[S + 48], wbuf[S + 48]; int rpos, wpos, len; fastio() { rpos ...
5
#include <bits/stdc++.h> using namespace std; int main() { map<char, char> m; m['A'] = 'A', m['H'] = 'H', m['I'] = 'I', m['M'] = 'M', m['O'] = 'O', m['T'] = 'T', m['U'] = 'U', m['V'] = 'V', m['W'] = 'W', m['X'] = 'X'; m['b'] = 'd'; m['d'] = 'b'; m['o'] = 'o'; m['p'] = 'q'; m['q'] = 'p'; m['v'] = 'v'; ...
2
#include <bits/stdc++.h> using namespace std; long long a[3] = {2, 7, 15}; long long ff(long long n) { long long l = 1, r = n; while (l < r) { long long mid = (l + r + 1) >> 1; if ((2 * n - mid) / mid >= 3 * mid) l = mid; else r = mid - 1; } return l; } int main() { long long n, ans; ...
3
#include<cstdio> #include<iostream> using namespace std; int main() { int n,a[101],s=0; cin>>n; for(int i=1;i<=n;i++) { cin>>a[i]; if(i%2!=0&&a[i]%2!=0) s++; } cout<<s; return 0; }
0
#include <bits/stdc++.h> using namespace std; int main() { int tux; cin >> tux; int foo = 0, bar = 0, baz = 0, quz = 1; for (int i = 0; i < tux; i++) { int pur; cin >> pur; foo += pur; bar++; if (max(foo * quz, bar * baz) == foo * quz) { baz = foo; quz = bar; } } cout << ...
3
#include <algorithm> #include <iostream> #include <vector> #include <numeric> using namespace std; template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } const int INF = (int)1e9 + 7; int main() { int N, D; cin >> N >> D; vector<vector<int>> p(N, vector<int>(D)); for (...
0
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[n]; float x, sum = 0; int i = 0; for (int i = 0; i < n; i++) { cin >> a[i]; sum += a[i]; } float k = 4.5 * n; if (sum >= k) cout << 0; else { bool flag = true; sort(a, a + n); while (flag) { ...
2
#include <bits/stdc++.h> using namespace std; int a[100000]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t; cin >> t; while (t--) { int n; cin >> n; for (int i = 1; i < n + 1; i++) { cin >> a[i]; } bool f[n + 1]; int freq[n + 1]; memset(f, false, sizeof(...
2
#include <bits/stdc++.h> using namespace std; template <typename Arg1> void __f(const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << "\n"; } template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args) { const char* comma = strchr(names + 1, ','); cout.write(nam...
2
#include <iostream> using namespace std; int main(){ int i=0; char c,ca[20]; while(cin>>c){ ca[i++]=c; } while(i--){ cout << ca[i]; } cout << endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; struct Part { int cnt; int d; int l, r; }; struct Fenwick { vector<int> data; int n; Fenwick(int n_) { n = n_ + 10; data.resize(n); } void add(int i, int v) { for (i += 5; i < n; i += i & -i) data[i] += v; } int sum(int i) { int sum = 0; ...
4
#include <bits/stdc++.h> using namespace std; int main() { map<string, int> h; h["Anka"] = 0; h["Chapay"] = 1; h["Cleo"] = 2; h["Troll"] = 3; h["Dracul"] = 4; h["Snowy"] = 5; h["Hexadecimal"] = 6; vector<vector<bool> > g(7, vector<bool>(7, false)); int n; scanf("%d", &n); for (int i = 0; i < n; ...
3
#include <bits/stdc++.h> using namespace std; const int MAX = 1e4 + 5; int n, k; int arr[MAX]; double S; inline bool good(double x) { double lost = 0.0; for (int i = int(1); i < int(n + 1); i++) { if (x >= arr[i]) { double y = x - arr[i]; double need = (100.0 * y) / (100.0 - k); lost += need; ...
2
#include <bits/stdc++.h> using namespace std; const int maxn = 1000 * 1000 + 10; const int maxn5 = 1000 * 100 + 10; const int maxn3 = 1000 + 10; const long long mod = 1000 * 1000 * 1000 + 7; const long long inf = 1LL * 2 * 1000 * 1000 * 1000 * 1000 * 1000 * 1000 + 10; int par[maxn5], a[maxn5], b[maxn5], rnk[maxn5], h[m...
4
#include <bits/stdc++.h> using namespace std; const int LARGE_SET_SIZE = 300; int main() { int n_elems, n_sets, n_queries; scanf("%d %d %d", &n_elems, &n_sets, &n_queries); vector<long long> elements(n_elems); vector<int> sets_elems; vector<int> sets_elems_start(n_sets + 1); for (int(i) = 0; (i) < (n_elems)...
3
#include <bits/stdc++.h> using namespace std; int main() { long long ret = 0, i, j, n, k, cnt = 0, x; string s, sh, sm; cin >> s; n = s.length(); for (int i = 0; i < n; i++) { if (s[i] == 'h' && i + 4 < n) sh = s.substr(i, 5); if (sh == "heavy") { cnt++; sh = ""; } if (s[i] == 'm' ...
2
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; if (m < n) { cout << n + m - 1 << endl; for (int i = 1; i <= n; i++) cout << i << " " << 1 << endl; for (int i = 2; i <= m; i++) cout << 2 << " " << i << endl; } else { cout << m + n - 1 << endl; for (int i =...
1
#include <bits/stdc++.h> using namespace std; #define for_(i,a,b) for(int i=(a);i<(b);++i) int HPinit, HPmax, R, C, T, S, P, p[22]; string grid[111]; unordered_map< char, int > trap; string dirs = "LURD"; int dx[4] = {-1,0,1,0}; int dy[4] = {0,-1,0,1}; typedef pair< int, int > pii; vector< pii > step; int max_hp[1...
0
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; int num[N]; int lowbit(int x) { return x & (-x); } void add(int x) { for (int i = x; i < N; i += lowbit(i)) num[i]++; } int query(int x) { int ans = 0; for (int i = x; i; i -= lowbit(i)) ans += num[i]; return ans; } int a[N], b[N]; priority_qu...
3
#include <vector> #include <list> #include <map> #include <set> #include <queue> #include <deque> #include <stack> #include <bitset> #include <algorithm> #include <functional> #include <numeric> #include <utility> #include <sstream> #include <iostream> #include <iomanip> #include <cmath> #include <cstdio> #include <cst...
0
#include <bits/stdc++.h> using namespace std; pair<int, pair<int, int> > arr[100010]; pair<int, int> ans[100010]; int ind = 2, intp = 1; pair<int, int> getnext() { intp++; if (ind == intp) { ind++; intp = 2; } return pair<int, int>(ind, intp); } int main() { int n, m, i, temp, cnt = 0, anscnt = 0, fla...
4
#include <bits/stdc++.h> using namespace std; string s; int n, m, k, p, x = 123345, ans, y, xx = 123435, yy, q = 0; int main() { cin >> k >> p; cin >> s; s = ' ' + s; for (int i = 1; i + i <= k; i++) if (s[i] != s[k - i + 1]) { q = 1; x = min(i, x); y = max(i, y); xx = min(k - i + 1,...
3
#include<bits/stdc++.h> using namespace std; int x,a,b,n; int main(){ cin>>x>>a>>b; cin>>n; string com; for (int i=0; i<n; i++){ cin>>com; if(com=="nobiro"){ x+=a; x=max(x,0); } else if (com=="tidime"){ x+=b; x=max(x,0); ...
0
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int mi[n]; for (int i = (0); i < (n); i++) mi[i] = 1e9; int t = 1; int z[1000]; do { t *= 2; vector<int> v; int x = 0; while (x < n) { int f = 0; for (int i = (0); i < (t / 2); i++) { if (x + i ...
4
#include <cstdio> #include <cmath> #include <utility> using namespace std; #define EPS (1e-10) #define equals( A, B ) (fabs((A) - (B)) < EPS) class Point { public: double x, y; Point( double x = 0, double y = 0 ): x(x), y(y) {} Point operator + ( Point p ) { return Point( x + p.x, y + p.y ); } P...
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 "climits" #include "list" #include "queue" #include "stack" #include "set" #include "functional" #include "algorithm" #include "string" #include "map" #include "unordered_map" #include "unordered_set" #include "iomanip" #include "cmath" #include "random" #include "bitset" #include "cstdio" ...
0
#include <bits/stdc++.h> using namespace std; vector<vector<long long int>> cur(20, vector<long long int>(2)); vector<long long int> adj[(long long int)(2e5 + 5)], s((long long int)(2e5 + 5)), a((long long int)(2e5 + 5)); vector<bool> mrk((long long int)(2e5 + 5)); long long int dfs(long long int c, long long int p...
5
#include <bits/stdc++.h> #pragma GCC optimize("Ofast,unroll-loops") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2") using namespace std; template <typename T> void read(T &x) { x = 0; char ch = getchar(); long long f = 1; while (!isdigit(ch)) { if (ch == '-') f *= -1; ch = getchar...
4
#include <bits/stdc++.h> using namespace std; int n, m; int cn = 0; int ver[102]; int sz[102]; int xs[102]; int ys[102]; int find(int p) { int root = p; while (root != ver[root]) root = ver[root]; while (p != root) { int newp = ver[p]; ver[p] = root; p = newp; } return root; } void unionVer(int p,...
3
#include <bits/stdc++.h> using namespace std; int casos; unsigned long long hashesa[2010]; unsigned long long hashesb[2010]; unsigned long long hashesc[2010]; unsigned long long bpowers[2010]; int tama, tamb, tamc; char a[2010], b[2010], c[2010]; void precomputea() { for (int i = 1; i <= tama; i++) { hashesa[i] =...
2
#include <bits/stdc++.h> using namespace std; int n, h, m, k, t[200005], id[200005]; bool cmp(int x, int y) { return t[x] < t[y]; } int main() { cin >> n >> h >> m >> k; m /= 2; for (int i = 1; i <= n; i++) { int x, y; cin >> x >> y; t[i] = y % m; id[i] = i; } sort(id + 1, id + n + 1, cmp); ...
4
#include <bits/stdc++.h> using namespace std; int n, k; vector<int> adj_diff[110000]; vector<int> adj_same[110000]; int seen[110000]; int cc; int mod = 1000000007; bool dfs(int v, int color) { if (seen[v] != -1) { if (seen[v] == color) return true; return false; } seen[v] = color; for (int same : adj_sa...
5
#include <bits/stdc++.h> using namespace std; const int N = 3010; int T, n, a[N], b[N], dp[N]; vector<int> alls; int main() { scanf("%d", &T); while (T--) { alls.clear(); memset(dp, 0, sizeof(dp)); scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); alls.push_back(a[i]); ...
6
#include <bits/stdc++.h> using namespace std; struct Point { double x, y; Point() {} Point(double _x, double _y) { x = _x; y = _y; } }; struct Vector { double x, y; Vector(Point a, Point b) { x = b.x - a.x; y = b.y - a.y; } }; double vectProduct(Vector p1, Vector p2) { return p1.x * p2.y -...
1
#include <bits/stdc++.h> using namespace std; const int MAX = 4e5 + 10; long long n, d[MAX]; long long x; long long prefix[MAX], cnt[MAX]; long long f(long long i, long long z) { long long ans = d[i]; ans = ans * (ans + 1) / 2 - (ans - z) * (ans - z + 1) / 2; long long req = x - z; long long l = i - 1, r = 2 * ...
4
#include <bits/stdc++.h> using namespace std; using ll = long long; using vi = vector<int>; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, m, s, f; cin >> n >> m >> s >> f; int ct = 1; while (m--) { int t, l, r; cin >> t >> l >> r; while (ct < t && s != f) { if (s < f) ...
2
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; if (n % 10 > 5) { cout << n + (10 - (n % 10)) << endl; } else cout << n - (n % 10) << endl; }
1
#include <bits/stdc++.h> using namespace std; long long int gcd(long long int a, long long int b) { return (a ? gcd(b % a, a) : b); } long long int modPow(long long int x, long long int n, long long int MOD) { long long int res = 1; while (n > 0) { if (n % 2 == 1) { res = (res * x) % MOD; } n /=...
4
#include <bits/stdc++.h> using namespace std; const long long MOD = 998244353; const double oula = 0.57721566490153286060651209; using namespace std; int main() { std::ios::sync_with_stdio(false); long long n, m, k; cin >> n >> m >> k; if (k < n) { cout << k + 1 << " " << 1 << endl; return 0; } k -=...
2
#include <bits/stdc++.h> using namespace std; template <class T> T abs(T a, T b = 0) { if (b == 0) return (a < 0) ? -a : a; return (a > b) ? (a - b) : (b - a); } template <class T> inline T gcd(T a, T b) { if (a < 0) return gcd(-a, b); if (b < 0) return gcd(a, -b); return (b == 0) ? a : gcd(b, a % b); } long ...
2
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ; long long t, n, a, b, c, d, sum = 0, i, j, flag; string x, y; cin >> t; while (t--) { cin >> a >> b >> c >> d; sum = 0; if (a == 0 and b == 0) cout << "0\n"; ...
1
#include <bits/stdc++.h> using namespace std; int d[5002]; int main(){ int k, q; scanf("%d%d", &k, &q); for(int i=0;i<k;i++) scanf("%d", &d[i]); for(int i=0;i<q;i++){ int n, x, m; scanf("%d%d%d", &n, &x, &m); long long sum = 0; for(int j=0;j<k;j++){ int d2 = ...
0
#include <iostream> using namespace std; int main() { for(int n,a,b,c,x;cin>>n>>a>>b>>c>>x,n|a|b|c|x;){ int y[n]; for(int i=0;i<n;i++) cin>>y[i]; int i=0,t=0; for(;t<=10000;t++){ if(x==y[i]) i++; if(i==n) break; x=(a*x+b)%c; } if(i==n) cout<<t<<endl; else cout<<-1<<endl;...
0
#include <bits/stdc++.h> using namespace std; void solve() { long long int n, k, d; cin >> n >> k >> d; vector<long long int> show(n); for (int i = 0; i < n; i++) { cin >> show[i]; } map<long long int, long long int> mp; set<long long int> s; long long int count = 0; for (int i = 0; i < d; i++) { ...
2
#include <bits/stdc++.h> using namespace std; const int maxn = 300010; int head[maxn], size[maxn], deep[maxn], c[maxn][26]; int n, ans[maxn], cnt, sz; char ch[10]; struct edge { int to, next; char w; } e[maxn << 1]; void link(int u, int v) { e[++cnt] = (edge){v, head[u], ch[0]}; head[u] = cnt; e[++cnt] = (edg...
3
#include <iostream> #include <string> using namespace std; bool pal(std::string const& s) { return s == std::string(s.rbegin(), s.rend()); } int main(void) { string s; cin >> s; int n = s.size(); s = "0" + s; if(!pal(s) || s[1] == '0') { cout << -1 << endl; } else { int r =...
0
#include <bits/stdc++.h> using namespace std; int const K = 10; struct node { int a; int L[K], R[K], PL[K], PR[K]; }; const signed long long int INF = 10e8; const int N = 100000; int n, m, q; int a[11][N]; node t[N * 5]; node G; node un(node t1, node t2) { node res; for (int i(0); i < n; i++) { res.L[i] = t...
5
#include <bits/stdc++.h> using namespace std; const int N = 1005; vector<pair<int, int>> g[N], ans[N]; long long dist[N]; priority_queue<pair<int, int>> pq; bool vis[N]; void dijkstra(int s) { fill(dist, dist + N, 1LL << 61); memset(vis, false, sizeof(vis)); dist[s] = 0; pq.push({0, s}); while (!pq.empty()) {...
3
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; int ar[s.length()]; for (int i = (0); i <= (s.length() - 1); i++) { if (s[i] == '4') ar[i] = 0; else ar[i] = 1; } long long int sum = 0; for (int i = (0); i <= (s.length() - 1); i++) { sum = sum + (1 << ...
2
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int q; cin >> q; while (q--) { int n; cin >> n; vector<vector<int>> tubes(2, vector<int>(n)); string s1, s2; cin >> s1 >> s2; for (int i = 0; i < n; ++i) { if (s1[i]...
3
#include <bits/stdc++.h> using namespace std; int loops[] = {1, 0, 0, 0, 1, 0, 1, 0, 2, 1}; int ints[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; int main() { int k; cin >> k; if (k > 2 * 18) { cout << -1; return 0; } while (k > 0) { if (k == 1) { cout << 9; return 0; } cout << 8; k...
2
#include<iostream> #include<algorithm> #include<vector> using namespace std; typedef long long ll; #define mod 1000000007 ll N,Q,L,R; ll a[200010]; ll q[200010],x[200010],s[200010],t[200010]; ll solve(ll i){ ll res=a[i]; for(int i=0;i<Q;i++){ if(q[i]==1){ if(res>=x[i]){ res=(res+s[i])*t[i]; } } i...
0
#include <bits/stdc++.h> using namespace std; bool flagU = false, flagD = false, flagL = false, flagR = false; void refresh() { flagD = false; flagU = false; flagL = false; flagR = false; } int main() { ios::sync_with_stdio(false); int n; cin >> n; int ans = 0; for (int i = 0; i < n; i++) { char c...
3
#include <iostream> #include <algorithm> #include <vector> #define rep(i,n) for(int i=0;i<n;++i) #define rep1(i,n) for(int i=1;i<=n;++i) using namespace std; template<class T>bool chmax(T &a, const T &b) { if(a < b){ a = b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if(a > b){ a = b; return...
0
#include <bits/stdc++.h> using namespace std; const int N = 500 * 500 + 5; int n, x[N], c[N], id[N], a[N]; int main() { scanf("%d", &n); for(int i = 1; i <= n; ++i) scanf("%d", &x[i]), id[i] = i; sort(id + 1, id + n + 1, [](int a, int b) { return x[a] < x[b]; }); for(int i = 1, p = 1; i <= n; ++i) { for(int j = ...
0
#include <bits/stdc++.h> using namespace std; int n; char s[2003]; int cnte[2003]; int cntb[2003]; int main() { while (cin >> s) { n = strlen(s); memset(cnte, 0, sizeof(int) * n); memset(cntb, 0, sizeof(int) * n); for (int i = 0; i < n; i++) { cnte[i]++; cntb[i]++; for (int k = 1; i ...
4
#include <bits/stdc++.h> using namespace std; int cycleMod(int num, int cycle) { if (num < 0) { return ((num % cycle) + cycle) % cycle; } return num % cycle; } int dvsCnt(int num, int subset) { return num / subset; } long long fact(int n) { long long res = 1; for (int i = 1; i <= n; i++) { res *= i; ...
2
#include <bits/stdc++.h> using namespace std; int main() { string S; cin>>S; if(S=="Sunny")cout<<"Cloudy\n"; else if(S=="Cloudy")cout<<"Rainy\n"; else cout<<"Sunny\n"; }
0
#include <bits/stdc++.h> using namespace std; const int N = 210000; const int P = 1000000007; int n, x[N], y[N]; map<int, int> dx, dy; int M; int head[N], np[N << 1], p[N << 1], tot; int du[N]; int vis[N]; int Sd, Sb; void add(int x, int y) { if (!dx[x]) dx[x] = ++M; if (!dy[y]) dy[y] = ++M; x = dx[x]; y = dy[y...
3
#include <bits/stdc++.h> using namespace std; template <typename T> void chkMax(T &x, T y) { if (y > x) x = y; } template <typename T> void chkMin(T &x, T y) { if (y < x) x = y; } template <typename T> void inline read(T &x) { int f = 1; x = 0; char s = getchar(); while (s < '0' || s > '9') { if (s == '...
1
#include <bits/stdc++.h> using namespace std; int main() { int n, c; cin >> n >> c; int p[n + 1], t[n + 1]; for (int i = 1; i <= n; i++) cin >> p[i]; for (int i = 1; i <= n; i++) cin >> t[i]; int suml = 0, tl = 0, sumr = 0, tr = 0; for (int i = 1; i <= n; i++) { tl += t[i]; int add = ((0) > (p[i] ...
1
#include <bits/stdc++.h> using namespace std; int main() { int c = 0; int n; cin >> n; string s; for (int i = 0; i < n; i++) { cin >> s; if (s == "Cube") c += 6; else if (s == "Tetrahedron") c += 4; else if (s == "Octahedron") c += 8; else if (s == "Icosahedron") c ...
1
#include <bits/stdc++.h> using namespace std; long long a[22]; int Hash[2522]; long long dp[22][2522][50]; int gcd(int a, int b) { if (a < b) swap(a, b); while (b) { int w = a; a = b; b = w % b; } return a; } long long dpp(int pos, int sum, int b, int limit) { if (pos == -1) return sum % b == 0; ...
4
#include <bits/stdc++.h> using namespace std; struct seg { int cnt; seg* nxt[2]; }; const int MAXN = 1E9; seg* root = new seg{0, NULL, NULL}; int n, m; long long ans; int getcnt(seg* p, int l, int r, int t) { if (!p) return 0; if (l == r) return p->cnt; int mid = (l + r) / 2; if (t > mid) return getcnt(...
2
#include <bits/stdc++.h> using namespace std; bool isPowerOfTwo(long long x) { return (x && !(x & (x - 1))); } void ans() { long long k, a, b; cin >> k >> a >> b; string s; cin >> s; if ((a * k < s.length() && b * k < s.length()) || (a * k > s.length() && b * k > s.length())) { cout << "No solution"...
5
#include<bits/stdc++.h> using namespace std; int main(){ int K,S;cin>>K>>S; int count=0; for(int X=0;X<=K;X++){ for(int Y=0;Y<=K;Y++){ if(X+Y<=S && S<=X+Y+K)count++; } } cout<<count<<endl; }
0
#include <bits/stdc++.h> using namespace std; double maabs(double a) { if (a < 0) return -a; return a; } signed main() { const double e = 0.00000001; ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; long long n; cin >> n; vector<string> ans; vector<pair<string, string>> v(n); vector<stri...
4
#include <bits/stdc++.h> using namespace std; void solve(); int main() { cin.sync_with_stdio(false); solve(); return 0; } const int mod = 1000000007; int dsu[2222]; int get(int a) { if (dsu[a] == a) return a; else return dsu[a] = get(dsu[a]); } void ob(int a, int b) { dsu[get(a)] = get(b); } long long...
2
#include <bits/stdc++.h> using namespace std; template <typename T> inline T SQR(T x) { return x * x; } template <typename T> inline T MIN(T x, T y) { return (x < y) ? x : y; } template <typename T> inline T MAX(T x, T y) { return (x > y) ? x : y; } template <typename T> inline T ABS(T x) { return (x > 0) ? x :...
4
#include <bits/stdc++.h> const int N = 200005, B = 505, lim = 500, blc = 500; int n, m, x[N], y[N], is[N], t[N]; int sum[B][B]; int tag[B], val[N]; inline void add(int x, int v) { tag[(((x) + blc - 1) / blc)] += v, val[x] += v; } inline int ask(int x) { int ret = 0; for (int i = 1; i < (((x) + blc - 1) / blc); ++...
3
#include <iostream> using namespace std; int ans[50]; int main() { int n,m; cin >> n >> m; for(int i = 0;i<m;i++) { int a,b; cin >> a >> b; ans[a]++; ans[b]++; } for(int i = 1;i<=n;i++) cout<<ans[i]<<endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); } const int MAXN = 200000; const int MAXM = 200000; struct Opt { int x, y; long long w; Opt() {} Opt(int x, int y, long long w) : x(x), y(y), w(w) {} }; bool operator<(const Opt &a, const Opt &b) { return a....
6
#include <bits/stdc++.h> using namespace std; int n, m, k; map<string, int> A; int main() { scanf("%i %i 0.%i", &n, &m, &k); char T[30]; int j = 0; for (int i = 0; i < n; ++i) { scanf("%s %i", T, &j); j = j * k / 100; if (j >= 100) A[T] = j; } for (int i = 0; i < m; ++i) { scanf("%s", T); ...
1