solution
stringlengths
52
181k
difficulty
int64
0
6
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; long long ans = 0; for (int i = (0); i < (n); ++i) { long long t, T, x, cost; cin >> t >> T >> x >> cost; if (t >= T) { ans += cost + m * x; continue; } long long aux1 = cost; if (m > (T - t))...
4
#include <bits/stdc++.h> using namespace std; const int N = 150 + 5; int a[N], mx[N][N][N], dp[N][N]; int main() { ios_base ::sync_with_stdio(false), cin.tie(0), cout.tie(0); int n; cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; string s; cin >> s; memset(mx, -1, sizeof mx); for (int i = 0; i <= n;...
4
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:256000000") using namespace std; const int INF = (int)1e9 + 7; const long long LINF = (long long)9e18 + 7; const long long P1 = 353251; const long long P2 = 239017; const long long MOD = 1e9 + 7; const long long MOD1 = 1e9 + 7; const long long MOD2 = 1e9 + 9; str...
5
#include <bits/stdc++.h> using namespace std; struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); } } fast; using namespace std; typedef long long ll; typedef pair<ll, ll> P; long long mod = 1000000007; #define REP(i, n) for (long long i = 0...
0
#include <bits/stdc++.h> using namespace std; const long long int N = 500005; long long int tree[4 * N][2][2]; string a; long long int n, q; void build(long long int node, long long int s, long long int e) { if (s == e) { long long int x = a[s] - '0' + 1; long long int y = 10 - x; y *= (a[s - 1] == '1' &&...
6
#include <bits/stdc++.h> using namespace std; using P = pair<int, int>; int main() { string s; cin >> s; for (int i = 0; i < (1 << 3); i++) { int ans = s[0] - '0'; string t = ""; t += s[0]; for (int j = 0; j < 3; j++) { if (i & (1 << j)) { ans += s[j + 1] - '0'; t += '+'; } else { ans -= s...
0
#include<iostream> using namespace std; #define lp(i,n) for(int i=1;i<=n;i++) int main(){ int n; while(1){ cin>>n; if(n == 0) break; int a=0, count=0; string s; lp(i,n){ cin>>s; if(s=="lu") a++; if(s=="ld") a--; if(s=="ru") ...
0
#include <bits/stdc++.h> using namespace std; string p, c; map<string, string> pl, cl; int q; string find_parent(string x) { while (pl[x] != x) { x = pl[x]; } return x; } int main() { cin >> q; for (int i = 0; i < q; i++) { cin >> c >> p; if (pl.find(p) == pl.end()) { pl[p] = p; } if...
2
#include<bits/stdc++.h> using namespace std; #define int long long #define rep(i,n) for(int i=0;i<(n);i++) #define pb push_back #define all(v) (v).begin(),(v).end() #define fi first #define se second typedef vector<int>vint; typedef pair<int,int>pint; typedef vector<pint>vpint; template<typename A,typename B>inline ...
0
#include <bits/stdc++.h> using namespace std; const long long N = 305; const long long M = 1e5 + 5; const long long MOD = 1e9 + 7; long long n, q, t; long long a[N], cost[N], lvl[N], cache[N][M], vis[N]; vector<long long> g[N], rg[N]; bool findLoop(long long v) { if (vis[v] == 1) return 1; if (vis[v] == 2) return 0...
3
#include <bits/stdc++.h> using namespace std; struct V { int v[10]; } a[101000]; int n, m, T; namespace tr { struct P { V le, ri; int ans, fa[20]; int GF(int x) { return x == fa[x] ? x : fa[x] = GF(fa[x]); } void UN(int x, int y) { if (GF(x) != GF(y)) fa[fa[x]] = fa[y]; } } p[404000]; int Cnt(V x) { i...
5
#include <bits/stdc++.h> using namespace std; struct turn { int me, you, idx; turn(){}; turn(int me, int you, int idx) { this->me = me; this->you = you; this->idx = idx; } }; int N; int used[1 << 21]; char a[1 << 21], b[1 << 21]; turn ab[1 << 21], ba[1 << 21]; void scan() { scanf("%d", &N); scan...
1
#include <bits/stdc++.h> using namespace std; int n; double x, y, a[100000], b[100000], v, v1, s1, w1, q1, s2; double s = 3.141592653589793238, q, w, d, mi = 1e30, ma, s3; int main() { cin >> n >> x >> y; for (int i = 0; i < n; i++) { cin >> a[i] >> b[i]; mi = min(mi, sqrt((a[i] - x) * (a[i] - x) + (b[i] - ...
1
#include<bits/stdc++.h> using namespace std; #define int long long void read(int &x) { x=0;int f=1;char ch=getchar(); for(;!isdigit(ch);ch=getchar()) if(ch=='-') f=-f; for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0';x*=f; } void print(int x) { if(x<0) putchar('-'),x=-x; if(!x) return ;print(x/10),p...
0
#include <bits/stdc++.h> using namespace std; int main() { int k; cin >> k; char s[200]; vector<int> __v; __v.assign(1000000, 127); cin >> s; int n; cin >> n; set<int> n_del['z' - 'a' + 1]; set<int>::iterator pos_n_del['z' - 'a' + 1]; for (int i = 0; i < n; i++) { char c; int nc; cin >...
3
#include <bits/stdc++.h> using namespace std; template <typename T> T abs(T a) { return a < 0 ? -a : a; } template <typename T> T sqr(T a) { return a * a; } const int INF = (int)1e9; const long double EPS = 1e-9; const long double PI = 3.1415926535897932384626433832795; int n; int lf, rg, all; char buf[10]; int mai...
1
#include <bits/stdc++.h> using namespace std; const int MAX = 1e6 + 5; vector<vector<long long int>> v; long long int T = 0; vector<long long int> dep; bool visited[MAX]; vector<long long int> par; vector<long long int> tin, tout, a; long long int f = 0, k = 1; void dfs(long long int s, long long int p = -1, long long ...
1
#include <bits/stdc++.h> using namespace std; const int maxn = 3e5 + 10; int a[maxn]; bool vis[maxn]; int main() { int n; while (scanf("%d", &n) != EOF) { for (int i = 1; i <= n; ++i) scanf("%d", &a[i]); int en = n; printf("1"); for (int i = 1; i <= n; ++i) { vis[a[i]] = true; while (vis...
4
#include <bits/stdc++.h> using namespace std; int a[222222]; int main() { long n, k; cin >> n >> k; for(int i = 0; i < n; i++) cin >> a[i + 1]; vector<int> b = {1}; int i = 1, x = 1; for(;; i++) { b.push_back(x = a[x]); if(i % 2 == 0 && b[i / 2] == b[i]) brea...
0
#include <bits/stdc++.h> using namespace std; const int N = 500005; struct edge { int to, next, id; } e[N * 2]; int head[N], q[N], nx[N], tot, n, m; int X[N], Y[N], f[N], del[N], to[N]; int dfn[N], low[N], fa[N], faid[N]; void add(int x, int y, int v) { e[++tot] = (edge){y, head[x], v}; head[x] = tot; } void tarj...
5
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; vector<vector<long long int>> arr(n, vector<long long int>(m)); vector<int> mat(n); for (int i = 0; i < n; i++) { long long int mx = 1e18; for (int j = 0; j < m; j++) { cin >> arr[i][j]; mx = min(arr[i][j],...
2
#include <bits/stdc++.h> using namespace std; int main() { int n, m, h; cin >> n >> m >> h; int a = 0; int b = 0; int c = n - 1; int current; for (int i = 0; i < m; i++) { cin >> current; if (i == h - 1) { a += current - 1; } else { b += current; } } if (c > a + b) { co...
4
#include <bits/stdc++.h> using namespace std; vector<int> data; map<int, int> cache; int CheckWinner(int powers) { if (cache.count(powers)) { return cache[powers]; } int high = 0; while (powers >= (1 << high)) { high++; } set<int> res; for (int i = 0; i < high; ++i) { int sub_power = (powers >...
5
#include <bits/stdc++.h> using namespace std; const int lzw = 100000 + 3; int head[lzw], tot, n; double ans; struct edge { int to, next; } e[lzw << 1]; void add(int a, int b) { e[++tot].next = head[a]; head[a] = tot; e[tot].to = b; } void dfs(int u, int fa, int dep) { ans += 1.0 / (double)dep; for (int i = ...
3
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <memory.h> #include <math.h> #include <assert.h> #include <stack> #include <queue> #include <map> #include <set> #include <string> #include <algorithm> #include <iostream> #include <functional> using namespace std; typedef long long ll; typedef pair<i...
0
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const long long INFF = 0x3f3f3f3f3f3f3f3fll; const long long M = 1e9 + 7; const long long maxn = 1e6 + 107; const double pi = acos(-1.0); const double eps = 0.0000000001; long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } t...
5
#include <bits/stdc++.h> using namespace std; int n, d, k; int main() { while (~scanf("%d%d%d", &n, &d, &k)) { if (d < k || n < d + 1 || (d == 1 && n != 2) || d > 2 * k) { printf("-1\n"); continue; } if (k == d) { int single = n - d - 1; int pos = 1; for (int i = 1; i <= d; i...
3
#include <bits/stdc++.h> using namespace std; namespace output { void __(short x) { cout << x; } void __(unsigned x) { cout << x; } void __(int x) { cout << x; } void __(long long x) { cout << x; } void __(unsigned long long x) { cout << x; } void __(double x) { cout << x; } void __(long double x) { cout << x; } void _...
6
#include <bits/stdc++.h> using namespace std; int cnt[10]; inline int g(int x) { int res = x % 9; if (res == 0) res = 9; return res; } int gg[10][10], ggg[1000005]; void solve() { int n; scanf("%d", &n); for (int i = (int)(1); i <= (int)(n); ++i) { cnt[g(i)]++; } for (int i = (int)(1); i <= (int)(n)...
3
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n, T; cin >> n >> T; map<int, int> c1, c2; vector<bool> ok(n); for (int i = 0; i < n; ++i) { int num; cin >> num; if (c1[T - num] <= c2[T - num]) { c1[num]++; ok[i] =...
2
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; int main() { long long i, j, k, l, co = 0; long long n, m, t; cin >> n >> m; if (n == 2) { if (m == 1) cout << 4 << endl; else cout << 5 << endl; } else if (n == 1 || n == 3 || n == 5 || n == 7 || n == 8 || n == 10 |...
1
#include <bits/stdc++.h> using namespace std; template <class T> bool uin(T& a, T b) { return a > b ? (a = b, true) : false; } template <class T> bool uax(T& a, T b) { return a < b ? (a = b, true) : false; } template <typename T> struct seg_tree { static constexpr T unit = INT_MIN; vector<T> tree; int N; in...
4
#include <bits/stdc++.h> using namespace std; char str[4][10005]; int k; bool isV(char ch) { if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u') return 1; return 0; } int get_type() { int len[4], i, j, st[4], x; for (i = 0; i < 4; i++) { len[i] = strlen(str[i]); if (len[i] < k) return 0; ...
3
#include <bits/stdc++.h> using namespace std; const int maxn = 5005; int n, k, a[2 * maxn] = {0, 1}, prime[maxn], ind = 0, x = 1, y, q; int vis[2 * maxn], check[2 * maxn]; vector<int> v[2 * maxn]; int main() { for (int i = 2; i < maxn; ++i) { int cnt = 1; for (int j = 1; j <= ind; ++j) { if (i % prime[j...
3
#include <bits/stdc++.h> using namespace std; template <typename T> inline T rd() { T nmb = 0; int sgn = 0; char chr = getchar(); while (!isdigit(chr)) { if (chr == '-') sgn = 1; chr = getchar(); } while (isdigit(chr)) { nmb = (nmb << 3) + (nmb << 1) + chr - '0'; chr = getchar(); } retur...
5
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 6; int n, c, d, lt; long long ans, now; struct man { int t, p; } a[N]; int nx[N][2]; int main() { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); cin >> n >> c >> d; for (int i = 1; i <= n; ++i) { int t; char s[5]; cin >> t >> s; ...
6
#include<bits/stdc++.h> using namespace std; int main(){ int x,y,r; scanf("%d %d",&x,&y); while(x % y != 0){ r = x % y; x = y; y = r; } cout << y << endl; return 0; }
0
#include <bits/stdc++.h> const int b1 = 17, b2 = 23, mod = 1e9 + 7, mod2 = 998244353; int fa[300005], d[300005], anc[300005][21], pw1[300005], pw2[300005], ipw1[300005], ipw2[300005], up1[300005], up2[300005], down1[300005], down2[300005], son[300005], top[300005], h[300005], lg[300005], n, q; char s[300005]; s...
5
#include <bits/stdc++.h> using namespace std; const long long MAX = 250010; vector<int> conn[MAX]; vector<int> route; int n, m, k, lim_a, lim_b; int chk[MAX], cnt_b; vector<int> ans_b[MAX]; int f(int first) { int cnt = 0; chk[first] = route.size(); route.push_back(first); for (auto second : conn[first]) { i...
3
#include <bits/stdc++.h> int n, n0, n1, n2, prev; int main() { std::cin >> n; for (int j = 0; j < n; ++j) { std::cin >> n0 >> n1 >> n2; prev = 1; if ((n2 == 0) && (n0 == 0)) { for (int i = 0; i < n1 + 1; ++i) { std::cout << prev; if (prev == 0) { prev = 1; } else ...
6
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int cur; cin >> cur; cout << n + 1 << "\n"; for (int i = 1; i < n; i++) { int next; cin >> next; cout << "1 " << i << " " << next % n + n - cur % n - 1 << "\n"; cur = next; } cout << "1 " << n << " " << n - cur %...
3
#include <cstdio> #include <iostream> #include <algorithm> #include <string> #include <cstring> #include <vector> #include <queue> #include <set> #include <map> #include <cmath> #include <iomanip> #include <cassert> #include <bitset> using namespace std; typedef pair<int, int> P; #define rep(i, n) for (int i=0; i<(n);...
0
#include <bits/stdc++.h> using namespace std; int n; vector<long long> a, b, v; long long solve(); int main() { cin >> n; a.resize(n); for (auto& p : a) cin >> p; b.resize(n); for (auto& p : b) cin >> p; cout << solve() << endl; return 0; } long long solve() { long long res = 0, cnt = 0; for (int ...
0
#include <bits/stdc++.h> using namespace std; void dout() { cerr << '\n'; } template <typename Head, typename... Tail> void dout(Head H, Tail... T) { cerr << " " << H; dout(T...); } mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); struct poly { int a[151]; poly() { memset(&a, 0, sizeof(a)); ...
2
#include<iostream> #include<map> #include<algorithm> using namespace std; int main(){ int n,ans=0,t[1000],u[1000]; bool visited[1000]; map<int,int> change; cin>>n; for(int i=0;i<n;i++){ cin>>t[i]; change[t[i]]=i; u[i]=t[i]; visited[i]=false; } sort(u,u+n); for(int i=0;i<n;i++){ in...
0
#include <iostream> using namespace std; /** Problem0062 : What is Bottommost? **/ int main() { int array1[10], array2[10]; char c; while (1) { for (int i=0; i<10; i++) { cin >> c; array1[i] = c - '0'; } if (cin.eof()) break; for (int i=1; i<10; i++) { for (int j=i; j<10; j++) { if (i%2==1) ...
0
#include <bits/stdc++.h> using namespace std; int n, siz[1000010], rt, sum = 0; vector<int> G[1000010], ans; void dfs(int np) { for (int x : G[np]) { dfs(x); siz[np] += siz[x]; } if (siz[np] == sum / 3 && ans.size() != 2 && np != rt) { ans.push_back(np); siz[np] = 0; } } int main() { scanf("%d...
3
#include <bits/stdc++.h> using namespace std; const int MAX = 700; int arr[MAX + 10]; int g[MAX + 10][MAX + 10]; bool res[MAX + 10][MAX + 10][2]; int main() { int n; cin >> n; for (int i = 0; i < n; i++) cin >> arr[i]; for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { int a = arr[i], b =...
4
#include <bits/stdc++.h> using namespace std; long long dp[100005]; long long dpp[100005]; long long dppp[100005]; const long long MOD = 1000000007; int main() { string s, p; cin >> s >> p; vector<int> f(p.length() + 1); f[0] = f[1] = 0; for (int i = 2; i <= p.length(); i++) { int j = i - 1; f[i] = 0;...
4
#include <bits/stdc++.h> #pragma GCC optimize("Ofast,unroll-loops") #pragma GCC target("avx,avx2,mmx,sse,sse2,tune=native") using namespace std; using ll = long long int; using ull = unsigned long long int; using ld = long double; using pii = pair<int, int>; using pll = pair<ll, ll>; template <typename T, typename S> i...
6
#include<bits/stdc++.h> #define int long long using namespace std; signed main(){ int N; cin>>N; vector<int> A(N),B(N+1); for(int i=0;i<N;i++){ cin>>A[i]; B[i+1]=B[i]+A[i]; } vector<vector<int>> C(N,vector<int>(N,100000000000000000)); for(int i=0;i<N;i++) C[i][i]=0; for(int i=1;i<N;i++){ ...
0
#include <bits/stdc++.h> using namespace std; int main() { int n, i, A[100005], cnt = 0; cin >> n; for (i = 1; i <= n; i++) { cin >> A[i]; } for (i = 2; i <= n - 1; i++) { if (A[i] == 0 && A[i - 1] == 1 && A[i + 1] == 1) { A[i + 1] = 0; cnt++; } } cout << cnt << endl; return 0; }...
2
#include <bits/stdc++.h> using namespace std; int const N = 1e5 + 1; int n, s, e, val, a[N], seg[N * 4]; vector<pair<int, int> > sol; queue<pair<pair<int, int>, int> > q; vector<vector<int> > pos; void build(int at, int l, int r) { if (l == r) { seg[at] = a[l]; return; } int mid = (l + r) >> 1; build(at...
3
#include <bits/stdc++.h> using namespace std; const double eps = 1e-8; const double inf = 1e20; const double pi = acos(-1.0); int sgn(double x) { if (fabs(x) < eps) return 0; if (x < 0) return -1; else return 1; } inline double sqr(double x) { return x * x; } struct Point { double x, y; Point() {} P...
5
#include <bits/stdc++.h> using namespace std; using ll = long long; struct event { int car, v, end_t; bool operator<(const event& e) const { return end_t != e.end_t ? end_t < e.end_t : car < e.car; } bool operator==(const event& e) const { return car == e.car and v == e.v and end_t == e.end_t; } }; in...
5
#include <bits/stdc++.h> #define rep(i,n)for(int i=0;i<(n);i++) using namespace std; typedef pair<int,int>P; vector<int>E[100000]; int s[100000],t[100000]; int ord[100000],low[100000],k; bool used[100000]; vector<P>V; void dfs(int v,int p){ used[v]=true; low[v]=ord[v]=k++; for(auto u:E[v]){ if(!used[u]){ dfs(...
0
#include <bits/stdc++.h> using namespace std; int n, m; int cnt; bool ltrd[2000001]; bool rtld[2000001]; bool traversed[1000000]; void mark(int xx) { if (traversed[xx]) { return; } ++cnt; for (int dd = 0; dd < 2; ++dd) { int xdir = (dd == 0) ? 1 : -1; int ydir = 1; int x = xx; int y = 0; ...
3
#include<stdio.h> #include<algorithm> using namespace std; int b[65536]; int c[65536]; int main(){ int a; while(scanf("%d",&a),a){ for(int i=0;i<a;i++)scanf("%d",b+i); for(int i=0;i<a-1;i++)scanf("%d",c+i); std::sort(b,b+a); std::sort(c,c+a-1); long long s=0; for(int i=0;i<a;i++)s+=b[i]; for(int i=0;i<...
0
#include <bits/stdc++.h> using namespace std; const double eps = 1e-8; int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); } struct Dir { double a, b; Dir() {} Dir(double aa, double bb) { double len = sqrt(aa * aa + bb * bb); a = aa / len; b = bb / len; if (fabs(a) < eps) { if (b < 0)...
4
#include <bits/stdc++.h> using namespace std; typedef struct d { int l = 10005, r = -1; } mat; int main() { int n, m; cin >> n >> m; int arr[n][m]; mat row[n], col[m]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { cin >> arr[i][j]; if (arr[i][j] == 1) { row[i].l = min(r...
2
#include <bits/stdc++.h> using namespace std; const int MAXn = 1 + 1e5; int n, l, r; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> l >> r; int ans = 0; for (int i = 0; i < l; i++) ans += (1 << i); for (int i = l; i < n; i++) ans++; cout << ans << endl; ans = 0; ...
2
#include<bits/stdc++.h> #define int long long using namespace std; signed main(){ int N; string S; cin>>N>>S; int ok=0,ng=N/2+1; while(ng-ok>1){ int n=(ok+ng)/2; set<string> s; for(int i=n;i+n<=N;i++){ s.insert(S.substr(i-n,n)); if(s.count(S.substr(i,n))){ ok=n; goto ho...
0
#include <bits/stdc++.h> using namespace std; int main() { string in1, in2; cin >> in1 >> in2; int dist[30][30]; for (int i = 0; i < 30; i++) { for (int j = 0; j < 30; j++) dist[i][j] = 1 << 28; dist[i][i] = 0; } int n, w; char a, b; cin >> n; for (int i = 1; i <= n; i++) { cin >> a >> b >...
2
#include <bits/stdc++.h> using namespace std; int n, q, where[2000000], num[2000000], place[200000], rep[2000000], co, rev[2000000], dir[2000000], res; vector<int> a[2000000]; vector<int> t[2000000]; void dfs(int u, int p) { rep[u] = ++co; rev[co] = u; num[u] = 1; for (int i = 0; i < a[u].size(); i++) { ...
2
#include <bits/stdc++.h> void merge(int arr[], int l, int m, int r) { int i, j, k; int n1 = m - l + 1; int n2 = r - m; int L[n1], R[n2]; for (i = 0; i < n1; i++) L[i] = arr[l + i]; for (j = 0; j < n2; j++) R[j] = arr[m + 1 + j]; i = 0; j = 0; k = l; while (i < n1 && j < n2) { if (L[i] <= R[j]) {...
1
#include <bits/stdc++.h> using namespace std; const int N = 3e2 + 5; const int MOD = 1e9 + 7; int n, q, w, a[N], du[N], sum[N]; vector<int> p[N]; bool v[N]; int dp[1 << 17]; bool dfs(int x, int cnt) { if (sum[x]) return sum[x]; sum[x] = cnt + a[x]; w = max(-1, w - cnt); for (int i = 0; i < p[x].size(); ++i) ...
3
#include <bits/stdc++.h> using namespace std; using namespace std; const int MAXN = 1e5 + 5; long long a[MAXN]; int main() { long long m, n, i, j, k, d, ans = 0; scanf("%I64d %I64d %I64d", &m, &n, &d); long long now = 0; for (i = 1; i <= m; i++) { scanf("%I64d", &a[i]); if (a[i] <= n) { now += a[i...
1
#include <bits/stdc++.h> using namespace std; int main() { long long n, t, m, j = 1, l, r; long long i, k, p = 0, h = 0, x = 0, y, z, q; string s; t = 1; for (r = 0; r < t; r++) { int a, b, c; std::cin >> a >> b >> c; std::set<int> ans; std::set<int>::iterator it; for (i = 1; i <= 81; i++)...
2
#include <iostream> #include <vector> #include <set> #include <algorithm> using namespace std; string list[24] = {"012345","024135","031425","043215","103254","120534","135024","152304","201453","215043","240513","254103","304152","310542","345012","351402","402351","425031","430521","453201","513240","521430","534120...
0
#include <bits/stdc++.h> using namespace std; const long long N = 1e6 + 5; const long long INF = 1e9 + 7; long long n, dp[N][1 << 4 | 1]; string s1, s2; bool check(const long long &pos, const long long &num) { if (num == 1) { if (s1[pos - 1] == 'X' || s1[pos] == 'X' || s2[pos - 1] == 'X') return false; } ...
4
#include <bits/stdc++.h> struct edge { int x, y, w; } e[200005]; int a[100005], b[100005], fa[200005]; inline int read() { register int x = 0, f = 1; register char s = getchar(); while (s > '9' || s < '0') { if (s == '-') f = -1; s = getchar(); } while (s >= '0' && s <= '9') { x = x * 10 + s - '...
5
#include <bits/stdc++.h> using namespace std; const int N = 2e6 + 5; vector<pair<long long int, long long int> > g[N]; int a[N][2]; vector<int> s; bool used[N], ex[N]; int n; int cv, ce; bool tr(int v) { if (used[v]) return 0; used[v] = 1; for (pair<long long int, long long int> it : g[v]) { int u = it.first,...
6
#include <bits/stdc++.h> int Fl, Pn, SI = 100; char mch = ' ', ch, Bf[21]; template <typename t> void in(t& a) { a = 0; ch = getchar(); Fl = 1; while ((ch < '0') || (ch > '9')) Fl = (ch == '-') ? -Fl : Fl, ch = getchar(); while ((ch >= '0') && (ch <= '9')) a = a * 10 + ch - '0', ch = getchar(); a *= Fl; } t...
4
#include <bits/stdc++.h> using namespace std; long long int modpow(long long int a, long long int n, long long int temp) { long long int res = 1, y = a; while (n > 0) { if (n & 1) res = (res * y) % temp; y = (y * y) % temp; n /= 2; } return res % temp; } pair<char, char> v[15]; int main() { int an...
3
#include <bits/stdc++.h> using namespace std; struct node { int l, r, sum, tag; int premx, prefr, premn, pmnfr; int sufmx, suffr, sufmn, smnfr; int mx, mxfrl, mxfrr, mn, mnfrl, mnfrr; node *lch, *rch; node operator+(node b) { node Ans; Ans.sum = sum + b.sum, Ans.l = l, Ans.r = b.r; Ans.tag = fal...
4
#include<cstdio> #include<cstring> #define inf 0x7f7f7f7f int l,Test_num,mxc,mxx; char ch[53]; int f[53][91][919][2]; inline int min(int a,int b) { return a<b? a:b; } inline int dp(int pos,int c,int x,int delta) { if(pos==l)return c? inf:0;if(c>mxc || c<-mxc || x>mxx || x<-mxx)return inf; if(!(~f[pos][c+mxc][x+mxx][...
6
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int cases = 1; cin >> cases; while (cases--) { int a = 0, b = 0; string s; cin >> s; char f = s[0]; for (int i = 1; i < s.length(); i++) { if (s[i] != f) { if (f == 'a'...
1
#include<iostream> #include<algorithm> #include<cstdio> #include<cmath> #include<cctype> #include<math.h> #include<string> #include<string.h> #include<stack> #include<queue> #include<vector> #include<utility> #include<set> #include<map> #include<stdlib.h> #include<iomanip> using namespace std; #define ll long long #d...
0
#include <bits/stdc++.h> using namespace std; const int NUM = 2e5 + 5; void err(istream_iterator<string> it) {} template <typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cerr << *it << " = " << a << "\n"; err(++it, args...); } long long int bpow(long long int x, long long in...
1
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10, mod = 1e9 + 7, Max1 = 13 * 5 + 10, Max2 = 14; int n, k, m, ans = 0, ifac[20], cc[Max1][Max2]; vector<int> vec; int Pow(int a, int b) { int ans = 1; for (; b; b >>= 1, a = 1ll * a * a % mod) if (b & 1) ans = 1ll * ans * a % mod; return an...
6
#include <bits/stdc++.h> using namespace std; void __print(int x) { cerr << x; } void __print(long x) { cerr << x; } void __print(long long x) { cerr << x; } void __print(unsigned x) { cerr << x; } void __print(unsigned long x) { cerr << x; } void __print(unsigned long long x) { cerr << x; } void __print(float x) { cer...
1
#include <iostream> #include <vector> using namespace std; const int MAX = 10000001; char p[MAX]; vector<char> P; void f(){ for(int i=2 ; i < MAX ; i++ ) p[i] = 1; for(int i=2 ; i+i < MAX ; i++ ){ if( p[i] ){ for(int j=i+i ; j < MAX ; j += i ){ p[j] = 0; } } } for(int i=2 ; i < MAX ; i++ ){ if( p[...
0
#include <bits/stdc++.h> using namespace std; int dp[105][150005], tk[105], po2[25]; int arrbt[105][150005], vl[105][150005], p[105], pr[105]; vector<int> pri; vector<int> kn[150005], cals, pv[150000]; map<int, int> mp; void re(int cur, int val, int bm) { if (val > 60) { return; } if (mp[val] == 0) { kn[b...
2
#include <vector> #include <iostream> #include <algorithm> using namespace std; int main() { int H, max_; while (true) { max_ = 0; cin >> H; if (H == 0) { break; } vector<vector<char> > c(H, vector<char>(H)); vector<vector<int> > dp(H, vector<int>(H, 0)); for (int i = 0; i < H; i++) { dp[0][...
0
#include <bits/stdc++.h> const int N = 1e3 + 5; using namespace std; int n, m, t; int nx[6] = {0, 1, 0, -1, 0}; int a[N][N], c[N][N]; queue<pair<int, int> > q; void create() { for (int i = 1; i <= m; i++) { for (int j = 1; j <= n; j++) { for (int p = 0; p <= 3; p++) { int u = i + nx[p]; int ...
3
#include <bits/stdc++.h> using namespace std; #define ll long long #define f(i, x, n) for (int i = x; i < (int)(n); ++i) int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } ll go(int w, int h, int k){ ll an = 0; f(x, 1, w)f(y2, 0, min(h, (2 * k - 2 + w) / (w - x) + 1)){ int y1 = min(h - 1ll, (2 * k + (ll)x * ...
0
#include <bits/stdc++.h> using namespace std; int now[2][2]; int gcd(int a, int b) { if (!b) return a; swap(now[0][0], now[1][0]); swap(now[0][1], now[1][1]); int k = a / b; now[1][0] -= k * now[0][0]; now[1][1] -= k * now[0][1]; return gcd(b, a % b); } int main() { int n, s; while (scanf("%d%d", &n, ...
5
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t; cin >> t; while (t--) { long long int n, x, y, a, b; cin >> x >> y >> n; b = (n - y) / x; cout << b * x + y << endl; } }
1
#include <bits/stdc++.h> using namespace std; using namespace std; struct ins { int ans; ins() { ans = 1; } void read() {} void read1(char &s) { char c = getchar(); for (; !isprint(c) || c == ' ' || c == '\n' || c == '\t'; c = getchar()) ; s = c; if (c == EOF) ans = 0; } void read1(str...
2
#include <bits/stdc++.h> int main() { int T, i; long long int a, b, ans; scanf("%d", &T); for (i = 1; i <= T; i++) { scanf("%lld %lld", &a, &b); if (a > b) { if (b * 2 <= a) { printf("%lld\n", b); } else { ans = (a + b) / 3; printf("%lld\n", ans); } } else {...
1
#include <bits/stdc++.h> using namespace std; const int maxn = 510; struct node { int p, r, c; }; node pre[maxn][26][26]; int cost[maxn][26][26]; int dp[maxn][26][26]; char s[maxn][maxn]; int n, m; void print(int deep, int r, int c) { if (deep == 0) return; node tmp = pre[deep][r][c]; print(tmp.p, tmp.r, tmp.c)...
5
#include <bits/stdc++.h> using namespace std; const int maxn = 100005; struct edge { int to, w; edge(int a = 0, int b = 0) { to = a, w = b; } }; int deep[maxn], fa[maxn], store[maxn], tail, n, k; vector<edge> graph[maxn]; void dfs(int node) { for (int i = 0; i < graph[node].size(); ++i) { edge e = graph[node]...
5
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 5; const double eps = 1e-9, INF = 0x3f3f3f3f; double sy, a, b, sum[maxn], l[maxn], r[maxn]; int n, q; inline void init() { scanf("%lf%lf%lf", &sy, &a, &b); scanf("%d", &n); n++; l[1] = r[1] = 0; for (int i = 2; i <= n; i++) { scanf("%lf%...
5
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; long long powmod(long long a, long long b) { long long res = 1; a %= mod; assert(b >= 0); for (; b; b >>= 1) { if (b & 1) res = res * a % mod; a = a * a % mod; } return res; } const int N = 201000; int n, a[N], val[N], p...
3
#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<(int)(n);i++) #define rep1(i,n) for(int i=1;i<=(int)(n);i++) #define all(c) c.begin(),c.end() #define pb push_back #define fs first #define sc second #define show(x) cout << #x << " = " << x << endl #define chmin(x,y) x=min(x,y) #define chmax(x,y) x=max(x,y) using...
0
#include <bits/stdc++.h> using namespace std; struct Data { using type = int; type val, lazy; static type id() { return INT_MAX; } static type op(const type& l, const type & r) { return min(l, r); } Data(type v) : val(v), lazy(-1) {} void update(type a) { lazy = a; } type get() { return lazy == -1 ? val : laz...
0
#include <bits/stdc++.h> using namespace std; int skillexp[100]; map<string, int> sk; int main() { int n, m; double k; cin >> n >> m >> k; int t = 0; for (int i = 0; i < n; ++i) { int b; string a; cin >> a >> b; if ((sk[a] + b) * k + 1e-8 > 100) { sk[a] = (int)((sk[a] + b) * k + 1e-8); ...
1
#include <bits/stdc++.h> using namespace std; void debug(int n, ...) { va_list v1; va_start(v1, n); for (int i = 0; i < n; i++) { int val = va_arg(v1, int); printf("%d ", val); } va_end(v1); printf("\n"); } double n, k; double sum; int ans; int main() { cin >> n >> k; for (int i = 0; i < n; i++)...
1
#include <bits/stdc++.h> using namespace std; template <typename G1, typename G2 = G1, typename G3 = G1> struct triple { G1 first; G2 second; G3 T; }; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >> n; vector<int> v(n); for (auto &i : v) cin >> i, --i; int m = min(n, 100); vec...
4
#include <bits/stdc++.h> using namespace std; int main() { char a, b; scanf("%c %c", &a, &b); int k, arr[4] = {118, 60, 94, 62}, fir, sec; scanf("%d", &k); k %= 4; for (int i = 0; i < 4; i++) { if (a == arr[i]) fir = i; if (b == arr[i]) sec = i; } if ((fir + k) % 4 == sec && (sec + k) % 4 == fir...
1