solution
stringlengths
52
181k
difficulty
int64
0
6
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 7; const int M = 1e9 + 9; int n, q; int a[N], fib[N]; void pre() { fib[0] = 0; fib[1] = 1; for (int i = 2; i < N; i++) fib[i] = (fib[i - 1] + fib[i - 2]) % M; } int term(int x, int y, int nn) { return (1LL * x * fib[nn - 1] + 1LL * y * fib[nn]) %...
3
#include <bits/stdc++.h> using namespace std; inline long long read() { register char c = ' '; register long long v = 0, x = 1; while ((c < '0') || (c > '9')) { if (c == '-') x = -1; c = getchar(); } while ((c >= '0') && (c <= '9')) { v = (v << 1) + (v << 3) + (c ^ 48); c = getchar(); } re...
2
#include <bits/stdc++.h> using namespace std; int main() { long long int t; cin >> t; while (t--) { int n; cin >> n; int x; int mx = 0; vector<int> op; for (int i = 0; i < 2 * n; i++) { cin >> x; if (mx < x) { op.push_back(i); mx = x; } } op.push_b...
4
#include <bits/stdc++.h> using namespace std; bool mid(int s, int x, int e) { return s <= x && x <= e; } int dp[64][64][64][64]; int f(int s, int e, int ps, int pe, int p) { if (s > e || ps > pe) return 0; if (p <= 6 && ~dp[s][e][ps][pe]) return dp[s][e][ps][pe]; if (p == 0) return 0; int m = (1 << (p - 1)); ...
3
#include <bits/stdc++.h> using namespace std; const int N = 105; int dp[N][N][N], kmp[N]; string a, b, c; int get(int x, char tmp) { while (x != 0 && c[x] != tmp) x = kmp[x]; if (c[x] == tmp) x++; return x; } int cal(int i, int j, int k) { if (dp[i][j][k] != -1) return dp[i][j][k]; dp[i][j][k] = 0; if (k ==...
2
#include<cstdio> int main(void) { int n,k,t,u,v,l; char d[100000]={}; scanf("%d%d%d%d%d%d",&n,&k,&t,&u,&v,&l); for(int i=0; i<n; i++) { int t; scanf("%d",&t); d[t]=1; } double res=0.0,rem=0.0; int carrot=0; for(int i=0; i<l; i++) { if(d[i]) carrot++; ...
0
#include <bits/stdc++.h> using namespace std; bool vis[200008]; int con[200008], leaf[200008]; void solve(int t) { int j, l, n, m, u, v, ans = 0; cin >> n >> m; for (j = 0; j < n + 5; j++) { vis[j] = 0; con[j] = leaf[j] = 0; } vector<int> g[n + 5]; queue<int> list; for (j = 1; j < n; j++) { ci...
6
#include <bits/stdc++.h> using namespace std; inline int read() { int x = 0, f = 1; char ch = getchar(); for (; !isdigit(ch); ch = getchar()) { if (ch == '-') f = -1; } for (; isdigit(ch); ch = getchar()) { x = x * 10 + ch - 48; } return x * f; } const int N = 2e5; const int Q = 5e5; const int S =...
5
#include <bits/stdc++.h> 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; } const int MAXN = 300010...
1
#include <iostream> #include <string> #include <vector> #include <algorithm> #include <queue> #define rep(i, n) for(i = 0; i < n; i++) using namespace std; typedef pair<int, int> P; int INF = 1e+9; int dy[4] = {-1, 0, 1, 0}; int dx[4] = {0, 1, 0, -1}; int w, h; string s[20]; vector<P> tile; int startId; int distTile[1...
0
#include<cstdio> long long a,b; int main() { scanf("%lld%lld",&a,&b); for(register long long i=1;;i=-(~(i))) { a*=2; if(a>b){printf("%lld\n",i);return 0;} } }
0
#include <bits/stdc++.h> using namespace std; vector<int> g[100005]; int find(int v, int* parent) { if (parent[v] == v) { return v; } return find(parent[v], parent); } int vis[100005]; int dp[100005]; int dfs(int u) { vis[u] = 1; for (int i = 0; i < g[u].size(); i++) { int v = g[u][i]; if (!vis[v]...
4
#include <bits/stdc++.h> using namespace std; pair<int, int> key[100001]; int parent[100001], value[100001]; vector<int> child[100001]; int sel_dir[100001]; long long sel_plus[100001]; double res[100001]; int n, k; int search(int num) { int ll = 0; int rr = k; while (ll < rr) { int mid = (ll + rr) / 2; if...
3
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10; const int maxm = 5e5 + 10; int dp[52][52][52][52]; string s[55]; int main() { ios_base::sync_with_stdio(false); int n; cin >> n; for (int i = 1; i <= n; i++) { cin >> s[i]; s[i] = " " + s[i]; } for (int lenx = 1; lenx <= n; len...
4
#include <bits/stdc++.h> using namespace std; int n, a[1000005]; void work() { if (a[n] == 1) { printf("NO\n"); return; } if (a[n - 1] == 1) { printf("YES\n"); for (int i = 1; i <= n - 3; i++) { printf("%d->", a[i]); } printf("(%d->1)", a[n - 2]); printf("->0\n"); return; }...
5
#include <bits/stdc++.h> using namespace std; const int inf = 1234567890; const long long infl = 8876543210123456789ll; const int mod = 1000000007; void init() { ios::sync_with_stdio(false); cin.tie(0); } template <class RandomAccessIterator> void print(RandomAccessIterator a, RandomAccessIterator b) { for (; a <...
2
#include <bits/stdc++.h> using namespace std; #define all(V) V.begin(),V.end() #define ll long long #define MOD 1000000007 vector<int> G[200010]; stack<ll> S[200010]; ll alc = 0, N; ll idc[200010], C[200010], ans[200010], ap[200010]; void euler(int c, int p) { for (int i : G[c]) { if (i == p)continue; S[C[c]].p...
0
#include <bits/stdc++.h> using namespace std; const int maxn = 2e3 + 5; const long long mod = 1e9 + 7; int a[maxn]; int b[maxn]; vector<int> u; int T, n, k; bool cal(long long x) { long long ans = 1; for (int i = 1; i <= n; i++) { int p = upper_bound(a + 1, a + n + 1, x) - a - 1; x++; ans = (p - i + 1) ...
5
#include <bits/stdc++.h> int main() { int n; std::cin >> n; std::cout << (n & 1) + 8 << " " << n - 8 - (n & 1); }
1
#include <bits/stdc++.h> using namespace std; int main() { unsigned long long int n; cin >> n; int flag = 0; int j; int r = 1; for (long long int i = 2; i * i <= n; i++) { if (n % i == 0) { j = 0; while (n % i == 0) { n /= i; j++; } r = r * (j + 1); } } if...
2
#include <bits/stdc++.h> using namespace std; int t; int a, b, c, d; int main() { scanf("%d", &t); while (t--) { scanf("%d%d%d%d", &a, &b, &c, &d); if (b >= a) { printf("%d\n", b); continue; } if (d >= c) { printf("-1\n"); continue; } a -= b; d = c - d; int t ...
1
#include <bits/stdc++.h> using namespace std; int n, m, c[100][100], auxf, resp; int main() { cin >> n >> m; for (int i = 0; i < n; ++i) { auxf = INT_MAX; for (int j = 0; j < m; ++j) { cin >> c[i][j]; auxf = min(auxf, c[i][j]); } resp = max(resp, auxf); } cout << resp << '\n'; retu...
2
#include <bits/stdc++.h> using namespace std; typedef int mat[2005][2005]; mat a, u, d, l, r; int n; void prop(int i, int j) { u[i - 1][j] ^= u[i][j]; d[i + 1][j] ^= d[i][j]; l[i][j - 1] ^= l[i][j]; r[i][j + 1] ^= r[i][j]; } int val(int i, int j) { return a[i][j] ^ u[i][j] ^ d[i][j] ^ l[i][j] ^ r[i][j]; } vec...
5
#include <bits/stdc++.h> using namespace std; int t; int main() { cin >> t; for (int tc = 0; tc < t; tc++) { int n, min_num = 1e9; cin >> n; vector<pair<int, int>> arr(n), v; for (int i = 0; i < n; i++) { cin >> arr[i].first; min_num = min(arr[i].first, min_num); arr[i].second = i;...
3
#include<bits/stdc++.h> using namespace std; int sum[12834]; int main() { int a,b; cin>>a>>b; sum[1]=300000; sum[2]=200000; sum[3]=100000; if(a>=4&&b>=4) cout<<0; else if(a==1&&b==1) cout<<1000000; else cout<<sum[a]+sum[b]; }
0
#include<iostream> #include<cstdio> #include<string> #include<cstring> using namespace std; string a; int sum=9999999; int main() { cin>>a; for(int i=1; i<a.size(); i++) { if(a[i]!=a[i-1]) { sum=min(sum,max(i,int(a.size())-i)); } } cout<<min(sum,int(a.size()))<<endl; re...
0
#include <bits/stdc++.h> using namespace std; const int INF = 1000000000; const int N = 200100; int n, m, q, a[N], dp[N]; void read() { static int p[N], id[N]; scanf("%d%d%d", &m, &n, &q); for (int i = 0; i < m; i++) { scanf("%d", p + i); id[p[i]] = i + 1; } for (int i = 0; i < n; i++) { scanf("%d...
5
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const int mxN = 1e5; map<pair<int, int>, int> color; vector<int> g[mxN + 1]; vector<int> path; int visited[mxN + 1]; long long n, k, ans, c; long long powmod(long long a, long long b) { long long res = 1; if (a >= mod) a %= mod; for (; b; b >>...
3
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <string> #include <vector> using namespace std; int main() { int N, x[361] = {}; cin >> N; for (int i = 1; i <= N; i++) { int M, D, V, S; cin >> M >> D >> V >> S; int a = (M - 1) * 30 + D + V - 1; int b = (M - 1)...
0
#include <bits/stdc++.h> using namespace std; namespace TYC { const int N = 1e3 + 10; int n, arr[N]; long double ans = 1e18, x[N], y[N]; bool vis[N]; inline long double sqr(long double a) { return a * a; } inline long double dis(int a, int b) { return sqrt(sqr(x[a] - x[b]) + sqr(y[a] - y[b])); } inline long double S(...
2
#include <bits/stdc++.h> using namespace std; const int N = 2000 + 5; int n, m; struct hash_table { unsigned long long seed; unsigned long long Hash[N], temp[N]; void Set(unsigned long long num) { seed = num; } void work(char *s, int n) { temp[0] = 1; Hash[0] = 0; for (int i = 1; i <= n; i++) temp[i...
1
#include <bits/stdc++.h> using namespace std; ifstream fin("in.in"); ofstream fout("out.out"); int n, k, t[110], res; int main() { ios_base::sync_with_stdio(0); cin >> n; for (int i = 0; i < n; i++) cin >> t[i]; cin >> k; sort(t, t + n); for (int i = 0; i < n; i++) { int lb = upper_bound(t + i, t + n, t...
2
#include <bits/stdc++.h> using namespace std; int main() { int n, x, m, y; cin >> n >> x >> m >> y; long long col = n + m + 1; if (n > m) { int q = n; n = m; m = q; } int s = x - y, a, b; if (s < 0) s = -s; for (int i = 1; i <= n; i++) { a = s - i + 1; if (a < (i - s + 1)) { co...
3
#include <bits/stdc++.h> using namespace std; const int maxn = 5e5 + 7; const int inf = INT_MAX; const long long inff = 1e18; const long long mod = 1e9 + 7; int color[maxn], dist[maxn]; vector<pair<int, int> > G[maxn]; int32_t main() { ios::sync_with_stdio(0); cin.tie(0); int n, m; cin >> n >> m; for (int i =...
5
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 10; int pref[N]; vector<int> v; int fsoma(int l, int r) { l--; int ans = pref[r]; if (l >= 0) ans -= pref[l]; return ans; } long long n, k, l; void rbest(pair<int, int> &a, pair<int, int> b) { if (b.first > a.first or (a.first == b.first and b....
6
#include<bits/stdc++.h> using namespace std; int main(){ int m,ni,na,i,j,k,ans,idx; while(cin>>m>>ni>>na,m||ni||na){ int p[m]; for(i=0;i<m;i++) cin>>p[i]; sort(p,p+m); ans=0; idx=ni; for(i=ni;i<=na;i++){ //cout<<p[m-i]-p[m-i-1]<<endl; if(p[m-i]-p[m-i-1]>=ans){ ans=p[m-i]-p[m-i-1...
0
#include <bits/stdc++.h> using namespace std; long long n, x, black, white; int main() { scanf("%lld", &n); for (int i = 1; i <= n; i++) { scanf("%lld", &x); black += x / 2; white += x / 2; if (x % 2 == 1) i % 2 ? white++ : black++; } printf("%lld", min(black, white)); }
2
#include<iostream> int main(){std::string s,t;std::cin>>s>>t;std::cout<<(s[0]^t[2]||s[1]^t[1]||s[2]^t[0]?"NO":"YES");}
0
#include <iostream> #include <cstdio> #include <vector> #include <queue> #include <algorithm> #include <string.h> #define F first #define S second #define MP make_pair #define int long long #define INF long(1e18) using namespace std; typedef pair<int, int> P; typedef pair<P, int> PP; int n, m, k, s, pp, q, ans[100001...
0
#include <bits/stdc++.h> std::vector<std::string> adj(1000, std::string(1000, 'N')); std::vector<int> factorize(int n) { std::vector<int> a; for (; n >= 2; n /= 2) a.push_back(2); return a; } int prod(const std::vector<int>& a) { int n = 1; for (const auto& i : a) n *= i; return n; } int main(int argc, char...
4
#include <bits/stdc++.h> using namespace std; struct Node { int id, deg; Node() {} Node(int t_id, int t_deg) : id(t_id), deg(t_deg) {} bool operator<(const Node &p) const { return deg > p.deg; } }; vector<Node> v1; vector<Node> v2; int main() { int K; int id, size; cin >> K; if (K % 2 == 0) { printf...
4
#include <bits/stdc++.h> using namespace std; const long double PI = acos(-1); const int INF = 2e9; const long long LINF = 1e18 + 5; const long long MOD = 1e9 + 7; const int MAX = 2002; double dp[MAX][MAX]; int opt[MAX][MAX]; double p[MAX]; double q[MAX]; double pq[MAX]; int solve(double cost, int n, int a) { int op;...
5
#include <bits/stdc++.h> using namespace std; const long long int mod = 1e9 + 7; const int maxn = 30001; const int N = 4e5 + 5; long long int a[maxn], dp[maxn][1000], d; long long int solve(long long int idx, long long int len, long long int maxm) { if (idx > maxm || !len) return 0; if (dp[idx][len - d + 500] != -1...
3
#include <bits/stdc++.h> using namespace std; bool b[200010]; long long int a[200010], g[200010]; vector<vector<int> > S; vector<int> factor, dp, f, seq; int Gcd(int a, int b) { int t; while (b) { t = a % b; a = b; b = t; } return a; } void Gcd(int a, int b, int &d, int &x, int &y) { if (!b) { ...
3
#include <bits/stdc++.h> using namespace std; const int nax = 100005; int n; vector<int> v[nax]; int a, b; int siz[nax]; int lca[nax][17]; int h[nax]; void dfs(int node, int par) { siz[node] = 1; for (auto it : v[node]) if (it != par) { h[it] = h[node] + 1; dfs(it, node); siz[node] += siz[it];...
5
#include <bits/stdc++.h> using namespace std; int main() { long long a, b, c, d, otv = 0, p, q, odin = 1; cin >> a >> b >> c >> d; for (long long x = a; x <= b; ++x) { if (d < x + b) { otv += (d - c + 1) * (c - b + 1); continue; } if (c <= x + b - 1) otv += (c - b + 1) * (x + b - c); p...
3
#include <cstdio> int main(){ int n, m; scanf("%d %d", &n, &m); printf("%d\n", n * (n - 1) / 2 + m * (m - 1) / 2); }
0
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int i, a[n]; for (i = 0; i < n; i++) cin >> a[i]; int count = 1; int start = a[0]; int end = 1 - a[0]; for (i = 1; i < n; i++) { if (a[i] == a[i - 1]) count++; else break; } int temp = count; if (count ...
3
#include <bits/stdc++.h> using namespace std; int n; int t[] = {1, 2, 1}; int main() { scanf("%d", &n); printf("%d\n", n < 3 ? t[n] : 0); }
0
#include <bits/stdc++.h> using namespace std; const long long MAX = 2500000000; const int inf = 0x3f3f3f3f; const double EPS = 1e-11; const double PI = 2 * asin(1.0); const long long mod = 1e9 + 7; const long long mod2 = 1000000016531; const long long mod3 = 1000000014367; int double_cmp(double x, double y = 0, double ...
1
#include<bits/stdc++.h> using namespace std; #define int long long using P=pair<int,int>; using PP=pair<int,P>; signed main(){ int n,m,s,t; cin>>n>>m>>s>>t; s--,t--; vector<vector<PP>> A(n); for(int i=0;i<m;i++){ int u,v,a,b; cin>>u>>v>>a>>b; A[u-1].push_back({v-1,{a,b}}); A[v-1].push_back({u-...
0
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 5; long long a[maxn]; long long n, k, m; int main() { cin >> n >> m >> k; long long ans = 0; long long s = 0; long long kk = k; long long sum = 0; for (int i = 0; i < m; i++) { cin >> a[i]; } for (int i = 0; i < m; i++) { if (a...
1
#include <bits/stdc++.h> using namespace std; const int MAX = 1e5 + 9; int n, dist[MAX], color[MAX], colorsCnt; int in[MAX], out[MAX], dfsCnt; int depth[MAX], spt[MAX][20], lg2[MAX]; vector<pair<int, int> > adj[MAX]; void Dfs(int node) { in[node] = ++dfsCnt; color[node] = colorsCnt; for (const pair<int, int>& p :...
4
#include <bits/stdc++.h> using namespace std; void solve() { string s; cin >> s; int n = s.length(); int zeros = 0; int ones = 0; for (int i = 0; i < n; i++) { if (s[i] == '0') zeros++; else ones++; } if (zeros == 0 || ones == 0) { cout << s; return; } int k = n - 1; if...
2
#include "bits/stdc++.h" using namespace std; typedef vector<int> vi; typedef pair<int,int> pii; typedef long long ll; #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 999999999 int c,n,m; int pass[200][200]; double d[200][20]; bool used[200][20]; i...
0
#include <bits/stdc++.h> using namespace std; bool win(char x, char y) { if (x == 'R' && y == 'S') return 1; if (x == 'S' && y == 'P') return 1; if (x == 'P' && y == 'R') return 1; return 0; } int n; int a1, a2; int i1, i2; string s1, s2; int m; int main() { cin >> n; cin >> s1; cin >> s2; int l1 = s1.s...
1
#include <bits/stdc++.h> using namespace std; long long min(long long a, long long b) { if (a > b) return b; else return a; } long long max(long long a, long long b) { if (a > b) return a; else return b; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t; t = 1...
2
#include <bits/stdc++.h> using namespace std; int main () { string S; cin >> S; int m = 0; for (char c: S) m += c-'0'; if (m % 9 == 0) puts("Yes"); else puts("No"); }
0
#include<iostream> #include<string> #include<algorithm> #include<cmath> #include <vector> using namespace std; int main() { double n, m; for (int h = 0; h < 5; h++) { cin >> n >> m; long long a, b, ans = 0; int aa[12345] = { 0 }, bb[12345] = { 0 }, test[501] = { 0 }, uiop[501] = { 0 }; if (n == 0 && m == 0) { ...
0
#include <bits/stdc++.h> using namespace std; int main(void) { ios_base::sync_with_stdio(false); cin.tie(NULL); pair<char, char> key[26]; char a[1001]; int len, i; for (i = 0; i < 26; i++) { cin >> key[i].first; } for (i = 0; i < 26; i++) { cin >> key[i].second; } sort(key, key + 26); cin ...
2
#include <bits/stdc++.h> using namespace std; const int mx = 1000 + 10; const long long mod = 1e9 + 7; char mp[mx][mx]; int vis[mx][mx]; struct nNode { int x; int y; } st; queue<nNode> q[10]; int n, m, p; int sp[10]; int cnt[10]; int dir[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}}; void bfs() { int fro, num, js; ...
4
#include <bits/stdc++.h> using namespace std; const int MAXN = 55; int n; vector<pair<int, int> > g[MAXN]; int grau[MAXN]; int v[MAXN]; bool isLeaf[MAXN]; vector<int> leaves; long long dist[MAXN][MAXN]; void distDFS(int x, int pai, int root) { for (int i = 0; i < g[x].size(); ++i) { int y = g[x][i].first; if ...
5
#include <bits/stdc++.h> using namespace std; template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; } mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const double EPS = 1e-9; const double PI = acos(-1.); const long long LL_INF = 1e17 + 16; const int INF = 1e9 + 10; const long long MO...
2
#include <iostream> #include <cstdio> #include <string> #include <map> using namespace std; int main() { int i; string s; char k; map<string, int> m; m["A"] = 0; m["B"] = 0; m["AB"] = 0; m["O"] = 0; while(cin>>i>>k>>s){ m[s]++; } cout<<m["A"]<<endl; cout<<m["B"]<<endl; cout<<m["AB"]<<endl; cout<<m["O"]<<...
0
#include <bits/stdc++.h> using namespace std; int main() { int n, x, t[52], r[52], fm = 1; cin >> n >> x; for (int i = 0; i < n; i++) { cin >> t[i] >> r[i]; } int m = 0; for (int i = 0; i < n; i++) { while (fm + x <= t[i]) fm += x; if (fm <= t[i]) { while ((fm) <= r[i]) { m++; ...
1
#include <bits/stdc++.h> using namespace std; long long ln, n[3], aa[100069], pr[26][100069], a[3][269], dp[269][269][269]; int main() { long long t, rr, i, j, ii, k, l, tg[3]; string s; char ch; scanf("%lld%lld", &ln, &t); cin >> s; for (i = 1; i <= ln; i++) { aa[i] = s[i - 1] - 'a'; } for (i = 0; ...
2
#include <bits/stdc++.h> int main() { char c[100000]; int i, n, a = 0, b = 0; scanf("%d\n", &n); for (i = 0; i < n; i++) { scanf("%c", &c[i]); if (c[i] == 'A') { a++; } else { b++; } } if (a > b) printf("Anton"); else if (a == b) printf("Friendship"); else { print...
1
#include <bits/stdc++.h> using namespace std; double area(double x1, double y1, double x2, double y2, double x3, double y3) { return (x1 - x2) * (y2 - y3) - (x2 - x3) * (y1 - y2); } struct point { int x, y; } arr[2000]; int main() { int n; double m; cin >> n; for (int i = 0; i <= n; i++) { cin >> arr[i]...
4
#include <bits/stdc++.h> using namespace std; int main() { string a; int count = 0, c = 0; cin >> a; count = a.size(); for (int i = 0; a[i] != '\0'; i++) { if (a[i] >= 'A' && a[i] <= 'Z') c++; } if ((c == count) || ((c == count - 1) && (a[0] >= 'a' && a[0] <= 'z'))) { for (int i = 0; a[i] != '\0';...
1
#include <bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; using pii = pair<int, int>; template <class T> inline void read(T &x) { x = 0; char c = getchar(); bool flag = 0; while (!isdigit(c)) { if (c == '-') flag = 1; c = getchar(); } while (isdigit(c)) { ...
5
// Problem : E. Oolimry and Suffix Array // Contest : Codeforces - Codeforces Round #723 (Div. 2) // URL : https://codeforces.com/contest/1526/problem/E // Memory Limit : 256 MB // Time Limit : 1000 ms // Powered by CP Editor (https://github.com/cpeditor/cpeditor) #include <bits/stdc++.h> using namespace std; int N...
5
#include <bits/stdc++.h> using namespace std; int main() { stack<pair<int, int> > Stack; string s; cin >> s; char carr[1000005]; vector<list<string> > arr(1000005); pair<int, int> temp; Stack.push(make_pair(0, 1000009)); int i(0), cnt, level, len, max(0); len = s.size(); while (i < len) { int j ...
5
#include <bits/stdc++.h> using namespace std; int main() { cout << fixed; cout.precision(9); long a1, b1, c1, a2, b2, c2; cin >> a1 >> b1 >> c1 >> a2 >> b2 >> c2; if (a1 == 0 && b1 == 0) { if (c1 != 0) { cout << "0\n"; return 0; } } if (a2 == 0 && b2 == 0) { if (c2 != 0) { co...
2
#include <bits/stdc++.h> using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const int maxn = 75, maxa = 1 << 18; int dist[maxn][maxa]; int N, M, a, b; int par[maxn], sz[maxn]; bool inq[maxn][maxa]; vector<pair<int, int> > adj[maxn]; int comp, id[maxn]; int finds(int u) { if (par...
4
#include <bits/stdc++.h> using namespace std; long long N, Q, op, l, r, v, sol; long long len = 90, cant; long long A[100100], sum[100100]; bool full[100100]; long long bsum[100100], first[100100], last[100100], xtra[100100]; long long B[100100], pref[100100], suff[100100]; long long calc(long long block) { long long...
3
// Murabito-B 21/04/13 #include <bits/stdc++.h> using namespace std; using ll = long long; void solve() { int a, b, c; cin >> a >> b >> c; for (int i = 0; i <= a - c; ++i) cout << 1; for (int i = 1; i < c; ++i) cout << 0; cout << " 1"; for (int i = 1; i < b; ++i) cout << 0; cout << "\n"; } i...
2
#include<iostream> #include<algorithm> #include<cmath> #include<cstdio> using namespace std; int main(){ int n; double x1, x2, x3, y1, y2, y3, x, y; cin >> n; for(int i = 0;i < n;i++){ cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3; if(y1 == y2)swap(x1, x3), swap(y1, y3); else if(y1 == y3)swap(x1, x2), swa...
0
#include <bits/stdc++.h> using namespace std; const int N = 2e3 + 5; long long n; long double cache[N][N]; int vis[N][N]; long double v[N * 2]; long double dp(long long i, long long ceils, long long floors) { if (i == 2 * n) { return 0; } if (vis[ceils][floors]) { return cache[ceils][floors]; } vis[ce...
3
#include <bits/stdc++.h> using namespace std; void err(istream_iterator<string> it) { cerr << endl; } template <typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cerr << *it << " = " << a << "\t"; err(++it, args...); } template <typename T1, typename T2> ostream& operator<<(os...
4
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; struct node { int u, v, w; bool operator<(const node &b) const { return w < b.w; } }; node a[N]; int f[N], n, m; void init() { for (int i = 1; i <= n; i++) f[i] = i; } int Find(int x) { if (x == f[x]) return x; else return f[x] = Fin...
6
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll N=3e5+5,mod=1e9+7; vector<ll> adj[N]; bool vis[N]; deque<ll> dq; int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); ll n,m;cin>>n>>m; for(ll i=1;i<=m;i++){ ll u,v;cin>>u>>v; adj[u].push_back(v); ...
0
#include <bits/stdc++.h> using namespace std; long long powmod(long long a, long long b) { long long res = 1; while (b > 0) { if (b & 1) res = res * a % 2; a = a * a % 2; b >>= 1; } return res; } int main() { ios_base::sync_with_stdio(false); long long b, k, sum = 0; cin >> b >> k; long long...
1
#include <bits/stdc++.h> using namespace std; string S; unsigned long long x = 1000000007; int main() { cin >> S; unsigned long long tot = 0; unsigned long long temp = 0; for (int i = S.length() - 1; i >= 0; i--) { if (S[i] == 'b') { temp++; } else { tot += temp; temp *= 2; tot =...
2
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = double; const ll MODBASE = 1000000007LL; const int MAXN = 2510; const int MAXM = 1000; const int MAXK = 16; const int MAXQ = 200010; int n; pair<int, int> a[MAXN]; vector<pair<int, int> > b; ll ccw(pair<int, int> a, pair<int, int> b) { ret...
5
#include<iostream> #include<string> using namespace std; int main() { string in; int ans=0; while (cin>>in) { bool f=false; int i=0,j=in.size()-1; while(i<=j) { if(in[i]!=in[j]) { f=true; break; } i++; j--; } if(!f) ans++; } cout<<ans<<endl; return 0; }
0
#include <bits/stdc++.h> int commands[4]; int main() { int n; char s[110]; scanf("%d\n", &n); scanf("%s\n", s); memset(commands, 0, sizeof(commands)); for (int i = 0; i < n; i++) { switch (s[i]) { case 'U': commands[0]++; break; case 'D': commands[1]++; break;...
2
#include <bits/stdc++.h> using namespace std; long long int nos[312345]; priority_queue<long long int> q; long long int compute(int size) { long long int val = 0; long long int t1, t2; for (int i = 0; i < size; ++i) { q.push(nos[i]); } while (!q.empty()) { t1 = q.top(); q.pop(); if (q.size() =...
1
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<ll> VL; typedef vector<VL> VVL; typedef pair<int, int> PII; #define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i) #define REP(i, n) FOR(i, 0, n) #define ALL(x) x.begin(), x.end() #defin...
0
#include<stdio.h> #include<vector> #include<algorithm> using namespace std; vector<int>pat[202020]; int deg[202020]; bool flag[202020]; int ans = 0; int dfs(int node) { flag[node] = true; int s = 0, c = 0; for (int i = 0; i < pat[node].size(); i++) { if (!flag[pat[node][i]]) { s += dfs(pat[node][i]); c++;...
0
#include <bits/stdc++.h> using namespace std; void io(bool done) { freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); } int main() { int n; cin >> n; int a[n + 1]; for (int i = 1; i <= n; i++) cin >> a[i]; int f[n + 10], l[n + 10]; f[1] = 1; bool done = false; int sum = 0, c = 0; ...
1
#include <bits/stdc++.h> using namespace std; int getint() { unsigned int c; int x = 0; while (((c = getchar()) - '0') >= 10) { if (c == '-') return -getint(); if (!~c) exit(0); } do { x = (x << 3) + (x << 1) + (c - '0'); } while (((c = getchar()) - '0') < 10); return x; } int getc_str(char st...
4
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma") #pragma GCC optimize("unroll-loops") using namespace std; long long MOD9 = 998244353; long long MOD = 1000000007; double eps = 1e-12; void solve() { int n; cin >> n; vector<pair<int, i...
3
#include <bits/stdc++.h> using namespace std; const int MaxN = 300005; map<pair<int, int>, int> m; int num[MaxN]; int a[MaxN], sum[MaxN]; int main() { int n, p; scanf("%d%d", &n, &p); m.clear(); memset(num, 0, sizeof(num)); for (int i = 1; i <= n; i++) { int x, y; scanf("%d%d", &x, &y); num[x]++; ...
4
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { return (!b ? a : gcd(b, a % b)); } long long lcm(long long a, long long b) { return (a / gcd(a, b)) * b; } int arr[210], n; bool onCycle[210]; bool vis[210]; bool cycleCheck(int cur, int pr) { if (cur == pr) return 1; if (vis[cu...
3
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { long long int n; cin >> n; string s = ""; for (int i = 0; i < n - 2; i++) { string temp; cin >> temp; s += temp; } string ans = ""; ans += s[0]; int c = 0; for (int i = 1...
2
#include <iostream> #include <algorithm> #include <string.h> #define INF 100000000 using namespace std; int d[1000][1000]; int V; void warshall_floyd(){ for(int i = 0 ; i <= V ; i++ )d[i][i] = 0; for(int k = 0 ; k <= V ; k++){ for(int i = 0 ; i <= V ; i++){ for(int j = 0 ; j <= V ; j++ ){ d[i][j] = m...
0
#include <bits/stdc++.h> using namespace std; const int INF = 1e9 + 23; const int MAXN = 2e5 + 100; int arr[MAXN]; pair<long long, int> mxsuf[MAXN]; int main() { ios_base::sync_with_stdio(0); int n, k; cin >> n >> k; for (int i = 1; i <= n; ++i) { cin >> arr[i]; } long long cur = 0; for (int i = n, j ...
2
#include<bits/stdc++.h> using namespace std; typedef long long int ll; const int INF = 1<<30; int main(){ char ca, cb, cc, cd;cin>>ca>>cb>>cc>>cd; int a=ca-'0', b=cb-'0', c=cc-'0', d=cd-'0'; char op1, op2, op3; for(int i=0;i<(1<<3);i++){ op1 = (i>>0&1?'+':'-'); op2 = (i>>1&1?'+':'-'); op3 = (i>>2&1?'+...
0
#include <bits/stdc++.h> using namespace std; int main() { int a = 0; int n; int b = 0; string k; cin >> n; cin >> k; for (int i = 0; i < n; i++) { if (k[i] == 'A') { a++; } else { b++; } } if (a > b) { cout << "Anton"; } if (b > a) { cout << "Danik"; } if (b ==...
1
#include <bits/stdc++.h> using namespace std; set<int> st; vector<int> v, vv[100009]; vector<int>::iterator it; int arr[100009]; set<pair<int, int> > sp; set<pair<int, int> >::iterator is; int main() { memset(arr, -1, sizeof(arr)); long long n, q, f = 1, ns; cin >> n >> q; for (int i = 0; i < q; i++) { int ...
3