solution
stringlengths
52
181k
difficulty
int64
0
6
#include <bits/stdc++.h> using namespace std; vector<int> arr; vector<int> seg; long long ans = 0; long long expo(long long a, long long b) { if (b == 0) { return 1; } long long z = expo(a, b / 2); z *= z; z %= 1000000007; if (b % 2 != 0) { z *= a; z %= 1000000007; } return z; } void Merge(i...
5
#include <bits/stdc++.h> using namespace std; long long dp[101][2][51][51]; int solve() { long long n; cin >> n; set<long long> left; vector<long long int> a(n); for (long long int i = 0; i < n; i++) { left.insert(i + 1); cin >> a[i]; } for (long long int i = 0; i < n; i++) left.erase(a[i]); lon...
3
#include <bits/stdc++.h> int main() { const long long bound = 1000; long long C, Hr, Hb, Wr, Wb; std::cin >> C >> Hr >> Hb >> Wr >> Wb; long long best = 0; if (Wr < Wb) { std::swap(Wr, Wb); std::swap(Hr, Hb); } if (Wr >= bound) { for (long long i = 0; i * Wr <= C; ++i) { best = std::max(...
3
#include <bits/stdc++.h> using namespace std; const long long maxi = 1e17; const int MAXM = 1e5 + 5; const int MAXN = 1e1 + 5; const double pi = acos(-1.0); vector<string> v; void solve(double n) { string s = ""; double xx = n - floor(n); long long pp = floor(n); xx *= 100; long long x = xx + 0.5; if (x != ...
2
#include <bits/stdc++.h> using namespace std; string str[2]; int main() { while (cin >> str[0] >> str[1]) { if (str[0].size() != str[1].size()) { puts("NO"); continue; } string num[2]; int t = 0; for (int i = 0; i < str[0].size(); i++) if (str[0][i] != str[1][i]) { num[0]...
1
#include <bits/stdc++.h> using namespace std; struct edge { long long n, t; } e[2000010 * 2]; long long s[2000010], f[2000010], h[2000010]; long long a[2]; long long cnt, n; long long ans = 0; inline long long read() { long long x = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-'...
5
#include <bits/stdc++.h> using namespace std; vector<long long> votes; long long rsq(int L, int R) { return votes[R + 1] - votes[L]; } int main() { int n, k; scanf("%d %d", &n, &k); votes.assign(n + 1, 0); for (int i = 1; i <= n; i++) { scanf("%d", &votes[i]); votes[i] += votes[i - 1]; } vector<long...
2
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector<int> lp(n + 1, 0), pflp(n + 1, 0); vector<int> e(n + 1, 1), u(n + 1, 0), bad(n + 1, 0); for (int i = 1; i <= n; i++) e[i] = i; for (int i = 2; i <= n; i++) { if (lp[i]) continu...
6
#include <bits/stdc++.h> using namespace std; int A[200009], F[200009]; bool C[200009]; void upd(int x, int y) { for(int i=x; i<=200000; i+=(i&-i)) F[i] += y; } int get(int x) { int ret = 0; for(int i=x; i>=1; i-=(i&-i)) ret += F[i]; return ret; } int main() { long long ans = 0; int N, K; sc...
0
#include <bits/stdc++.h> int x[10]; int cp, dp; using namespace std; void print() { for (int i = 0; i < 10; ++i) { cout << x[i]; if (i == 9) cout << "\n"; else cout << " "; } } int pp(char a, int &dp) { if (a == '<') { dp = -1; return -2; } else if (a == '>') { dp = 1; re...
2
#include <bits/stdc++.h> using namespace std; const int N = 100 + 10; const int M = 10000 + 10; const int P = 1000000000 + 7; int add(int a, int b) { return a + b < P ? a + b : a + b - P; } int mul(int a, int b) { return 1LL * a * b % P; } int n, a[N]; int dp[2][N][M], fac[N], inv[N], invfac[N]; int C(int n, int m) { ...
2
#include<bits/stdc++.h> using namespace std; const int maxn=1e5+7; int n,t,a; int dist[maxn],disa[maxn],ans; vector<int> to[maxn]; void dfs(int x,int f,int* dis) { dis[x]=dis[f]+1; for(int i=0;i<to[x].size();++i) { int t=to[x][i]; if(t==f) continue; dfs(t,x,dis); } } int main() { scanf("%d %d %d",&n,&t,&a)...
0
#include <bits/stdc++.h> using namespace std; template <class T, class... S> void dbs(string str, T t, S... s) { int idx = str.find(','); cout << str.substr(0, idx) << " : " << t << ","; dbs(str.substr(idx + 1), s...); } template <class S, class T> ostream& operator<<(ostream& os, const pair<S, T>& p) { return ...
5
#include <bits/stdc++.h> using namespace std; vector<int> succ[200005], prod[200005], bucket[200005], dom_t[200005]; int semi[200005], anc[200005], idom[200005], best[200005], fa[200005], val[200005]; int dfn[200005], redfn[200005]; int timestamp, root, n, m; void dfs(int now) { dfn[now] = ++timestamp; redfn[ti...
6
#include <bits/stdc++.h> using namespace std; struct edge { int a, b, c; } e[100005]; int n, tot; int sub[100005], vis[100005]; int dad[100005], sz[100005]; long long cnt[100005]; vector<int> v[100005]; vector<int> edges; int find(int node) { return dad[node] = (dad[node] == node ? node : find(dad[node])); } void m...
4
#include <iostream> using namespace std; int main(){ int N; cin >> N; string S; cin >> S; int l = 0, r = N-1; while(S[l] == '<') ++l; while(S[r] == '>') --r; cout << N - min(l,N-1-r) << endl; return 0; }
0
#include<bits/stdc++.h> int n, m; int ck[100010],cnt[100010]; int main() { scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) cnt[i] = 1; ck[1] = 1; for (int i = 0, x, y; i < m; i++) { scanf("%d%d", &x, &y); ck[y] |= ck[x]; cnt[y]++; cnt[x]--; if (cnt[x] == 0) ck[x] = 0; } int res = 0; for (int i = 1;...
0
#include<iostream> using namespace std; int main() { int x,y,temp,step; cin>>x>>y; while(x!=0){ if(x-y<0){ temp=x; x=y; y=temp; } step=1; for(;;){ x=x%y; temp=x; x=y; y=temp; if(y==0)break; step++; } cout<<x<<" "<<step<<"\n"; cin>>x>>y; } return 0; }
0
#include <bits/stdc++.h> using namespace std; int n, m, a[105], b[105], mk[40005]; vector<int> v; pair<long long, long long> mask[40005]; int main() { scanf("%d%d", &n, &m); for (int i = 0; i < n; i++) { scanf("%d", &a[i]); a[i] += 10000; } for (int i = 0; i < m; i++) { scanf("%d", &b[i]); b[i] ...
5
#include <bits/stdc++.h> using namespace std; long long n, res; long long x[9]; int main() { scanf("%lld", &n); x[0] = 5; for (long long i = 1; i < 9; i++) x[i] = x[i - 1] * 10; long long st = -1; for (long long i = 8; i >= 0; i--) { if (n >= x[i]) { st = x[i]; break; } } if (st == -1)...
4
#include <bits/stdc++.h> using namespace std; template <class A> void read(vector<A>& v); template <class A, size_t S> void read(array<A, S>& a); template <class T> void read(T& x) { cin >> x; } void read(double& d) { string t; read(t); d = stod(t); } void read(long double& d) { string t; read(t); d = sto...
1
#include <bits/stdc++.h> using namespace std; struct outFloat { int precision; long double value; outFloat(long double v, int p) : precision(p), value(v) {} }; template <typename T> struct debugInfo { string name; T val; debugInfo(const char* n, T v) : name(n), val(v){}; }; template <typename T> debugInfo<T...
2
#include <bits/stdc++.h> using namespace std; int main() { int n, m, a, b, arr[10000]; long long k, ans = 0; memset(arr, -1, sizeof(arr)); cin >> n >> m >> k; for (int i = 0; i < n; i++) { cin >> a >> b; if (arr[a] == -1 || b < arr[a]) arr[a] = b; } for (int i = 1; i <= m; i++) { ans += arr[i]...
1
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; int a[n]; if (k > n) { cout << "-1"; return 0; } for (int i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); cout << a[n - k] << " " << a[n - k] << endl; }
2
#include <bits/stdc++.h> using namespace std; const int MOD = 1000000007; const long long INF = 1e18; const int INFTY = 2147483643; const long double PI = 4 * atan((long double)1); struct pair_hash { template <class T1, class T2> std::size_t operator()(const std::pair<T1, T2> &pair) const { return std::hash<T1>...
2
#include <bits/stdc++.h> using namespace std; pair<int, int> a, b, c, d, tt; int sq(pair<int, int> a, pair<int, int> b, pair<int, int> c) { a.first -= b.first; a.second -= b.second; c.first -= b.first; c.second -= b.second; return a.first * c.second - a.second * c.first; } bool check(pair<int, int> f) { ret...
2
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 2e5 + 77; const int mod = (int)1e9 + 7; const int inf = (int)1e9 + 77; int main() { int h, w, k, a, b, u, v; scanf("%d%d%d%d%d%d%d", &h, &w, &k, &a, &b, &u, &v); int dx[] = {1, 0, -1, 0}; int dy[] = {0, 1, 0, -1}; vector<strin...
0
#include <bits/stdc++.h> #include <stdio.h> using namespace std; const int maxn=5000*5000+233; long long f[maxn]; void add(int w,int c) { if(c<=0) return; for(int i=0;i<=5000*5000-w;i++) { f[i+w]=max(f[i+w],f[i]+c); } } int main() { int n,ga,gb,sa,sb,ba,bb; cin>>n>>ga>>sa>>ba>>gb>>sb>>bb; memset(f,0,sizeof(...
0
#include <iostream> #include <algorithm> #include <list> #include <string> using namespace std; bool isMissing(string word, int number) { if (number % 15 == 0) return word != "FizzBuzz"; if (number % 3 == 0) return word != "Fizz"; if (number % 5 == 0) return word != "Buzz"; return word != to_string(number); } int...
0
#include <bits/stdc++.h> #define be(v) (v).begin(),(v).end() #define pb(q) push_back(q) typedef long long ll; using namespace std; const ll mod=1000000007, INF=mod*mod*3LL; #define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl; long long modpow(long long a, long long n) { long long res = 1; while (n > 0...
0
#include <vector> #include <iostream> using namespace std; int n, a[10001]; int gcd(int a, int b) { if (a < 0) a = -a; if (b < 0) b = -b; if (a < b) swap(a, b); while (b > 0) { int t = a; a = b; b = t % b; } return a; } void check(int p) { if (a[0] % p) return; for (int i = 1;...
0
#include <bits/stdc++.h> using namespace std; using ll = long long; using P = pair<ll, int>; const ll INF = 1e15; struct Edge { int to; ll dist; Edge(int to, ll dist) : to(to), dist(dist) {} }; struct Dijkstra { vector<ll> d; Dijkstra(int s, const vector<vector<Edge>> &g) { d.resize(g.size(), INF); ...
0
#include <bits/stdc++.h> using namespace std; const long long M = 1e9 + 7; void solve() { long long a[3]; cin >> a[0] >> a[1] >> a[2]; sort(a, a + 3); if (a[0] == a[1] && a[1] == a[2]) { cout << "YES" << '\n'; cout << a[0] << " " << a[1] << " " << a[2] << '\n'; } else if (a[0] < a[1] && a[1] == a[2]) ...
1
#include<iostream> #include<vector> #include<cmath> #include<queue> #include<functional> #include<algorithm> #include<string> using namespace std; struct edge{int to,cost;}; typedef pair<int,int> P; const int INF=1<<15; int main(void) { int n,m,l,k,a,h; while(cin>>n>>m>>l>>k>>a>>h,n){ vector<vector<edge> > G(n)...
0
#include <bits/stdc++.h> using namespace std; void swapRY(int a[2]) { swap(a[0], a[1]); } void swapRB(int a[2]) { a[1] ^= a[0]; } void swapYB(int a[2]) { a[0] ^= a[1]; } int id(char c) { if (c == 'W') return 0; if (c == 'R') return 1; if (c == 'Y') return 2; if (c == 'B') return 3; assert(0); return -1; } b...
6
#include <bits/stdc++.h> using namespace std; string s; int main(){ cin >> s; cout << (s=="ARC"? "ABC":"ARC"); return 0; }
0
#include<iostream> //#include<string> using namespace std; int main(){ int N,sum=99999; cin >>N; int a; for(int i =0;i<N;i++){ cin>>a; int j=0; while(a%2==0){ a/=2; j++; } if(j<sum)sum =j; }cout <<sum<<endl; }
0
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s; cin >> s; int niz[9]; for (int i = 0; i < 9; i++) cin >> niz[i]; for (int i = 0; i < n; i++) { if (s[i] - 48 < niz[s[i] - 49]) { while (s[i] - 48 <= niz[s[i] - 49]) { s[i] = niz[s[i] - 49] + 48; ...
2
#include <bits/stdc++.h> using namespace std; const int N = 2e3 + 100; const int p = 1e9 + 7; long long dp[N][N]; int main() { int n, k; cin >> n >> k; for (int i = 1; i <= n; i++) { dp[1][i] = 1; } for (int i = 2; i <= k; i++) { for (int j = 1; j <= n; j++) { int x = 1; while (j * x <= n)...
2
#include <bits/stdc++.h> using namespace std; int z, n; char s[2000007], t[2000007]; int tab[2000007]; vector<int> suf; void suf_array(const char* init, vector<int>& suf) { string s = init; vector<int> head, color, sub, tmp; head.assign(max((int)s.size(), 256), 0); suf.resize(s.size()); color.resize(s.size())...
1
#include <bits/stdc++.h> #define rep(i, n) for (rint i = 1; i <= (int)(n); i ++) #define re0(i, n) for (rint i = 0; i < (int) n; i ++) #define travel(i, u) for (rint i = head[u]; i; i = e[i].nxt) #define rint register int using namespace std; typedef long long lo; template<typename tp> inline void read(tp &x) { x...
0
#include <iostream> #include<string> #include<algorithm> using namespace std; int main(void){ string s1,s2; cin>>s1; cin>>s2; int dp[1001][1001]; for(int i=0;i<1001;i++){ dp[i][0]=i; dp[0][i]=i; } for(int i=1;i<s1.length()+1;i++){ for(int j=1;j<s2.length()+1;j++){ if(s1[i-1]==s2[j-1]){ ...
0
#include<bits/stdc++.h> using namespace std; #define ll long long int #define lld long long double #define vi vector<int> #define vll vector<ll> #define mkp make_pair #define pb push_back #define clr(a) memset(a,0,sizeof(a)) #define loop(i,n) for(int i=0;i<n;i++) #define rloop(i,n) for(ll i=n-1;i>=0;i--) #define pi...
1
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const long long INF64 = 3e18 + 1; const char invdir[]{'L', 'U', 'R', 'D'}; const char dir[]{'R', 'D', 'L', 'U'}; const int dx[]{0, 1, 0, -1}; const int dy[]{1, 0, -1, 0}; unsigned get_seed() { unsigned seed = chrono::system_clock::now().time_si...
4
#include <bits/stdc++.h> #define fi first #define se second #define mp make_pair using namespace std; const int INF = 0x3f3f3f3f; int dp[2010][2010], ndp[2010][2010]; int row[2010], MAXJ; int a[6010]; int Query() { return MAXJ; } int query(int x) { return row[x]; } void modify(int x, int y) { if (dp[x][y] == nd...
0
#include <cstring> #include <iostream> #include <vector> #include <algorithm> #include <string> using namespace std; int main(){ int w,h; while(cin>>h>>w&&!(w==0&&h==0)){ vector<string> field; string str; for(int i = 0; i < h; i++){ cin>>str; field.push_back(str); } bool isPassed[200][200]; memse...
0
// 2012/12/10 Tazoe #include <iostream> using namespace std; int main() { int N; cin >> N; int P[101]; for(int i=1; i<=N; i++){ P[i] = 0; } for(int i=0; i<N*(N-1)/2; i++){ int A, B, C, D; cin >> A >> B >> C >> D; if(C>D){ P[A] += 3; } else if(C<D){ P[B] += 3; } else{ P[A] += 1; P[...
0
#include <bits/stdc++.h> using namespace std; long long x, y; vector<string> a; string int_to_string(long long x) { string res = ""; while (x) { res += x % 10 + '0'; x /= 10; } reverse(res.begin(), res.end()); return res; } int main() { cin >> x >> y; while (x != 0 && y != 0 && x != y) { if (x...
5
#include<cstdio> #include<map> using namespace std; typedef pair<int, int> P; map<P, int> m; map<P, int> nm; int n, t, f; int d[6][4] = {{2, 4, 5, 3}, {1, 3, 6, 4}, {1, 5, 6, 2}, {1, 2, 6, 5}, {1, 4, 6, 3}, {2, 3, 5, 4}}; // down 0 / left 1 / up 2 / right 3 int dx[4] = {0, -1, 0, 1}; int dy[4] = {-1, 0...
0
#include <bits/stdc++.h> using namespace std; int a[150][150]; int main() { int n, m; while (~scanf("%d%d", &n, &m)) { for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { scanf("%d", &a[i][j]); } } if (n % 2 == 1) { printf("%d\n", n); continue; } else { ...
2
#include <bits/stdc++.h> using namespace std; using ll = long long; const ll maxn = 1e6 + 6, inf = 1e18 + 1; ll n, m, m2, md, a[100], dp[75][75][75], tmp[75], DP[75]; int main() { ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); cin >> n >> m >> md; m2 = m / 2; for (ll i = 1; i < md; i++) tmp[i] = -inf; ...
6
#include <bits/stdc++.h> using namespace std; void cline() { cout << '\n'; } template <typename T, typename... V> void cline(T t, V... v) { cout << t; if (sizeof...(v)) cout << ' '; cline(v...); } void cspc() { cout << ' '; } template <typename T, typename... V> void cspc(T t, V... v) { cout << t; if (sizeof....
2
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 5; int main() { int n, a, b, c; scanf("%d", &n); if (n == 1) { scanf("%d", &a); if (a != 0) puts("BitLGM"); else puts("BitAryo"); return 0; } else if (n == 2) { scanf("%d%d", &a, &b); if (a == 0 || b == 0) {...
4
#include <bits/stdc++.h> using namespace std; const int MAX_N = 40; long long N, T, ans, p[45], num[45][45]; int t, lim; bool power_of_two(long long x) { double p = log(x) / log(2.0); return (fabs(p - floor(p)) < 1e-7); } void init() { p[0] = 1LL; for (int i = (int)1; i <= (int)MAX_N + 3; i++) p[i] = p[i - 1] *...
3
#include <bits/stdc++.h> using namespace std; int main() { int pairs; cin >> pairs; for (int i = 0; i < pairs; i++) { long long a, b, operations, op; cin >> a >> b; op = 0; operations = 0; while (a > 0 && b > 0) { if (a > 100 || b > 100) { if (b > a) { op = (b - a) / a ...
1
#include <bits/stdc++.h> using namespace std; const int ssize = 10000; const char sl = '\n'; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int t; cin >> t; while (t--) { long long x; cin >> x; cout << (x > 14 && x % 14 >= 1 && x % 14 <= 6 ? "YES" : "NO") << ...
2
#include<cstdio> #include<algorithm> #define int long long using namespace std; int pre[200010],n,x,minn; signed main(){ scanf("%lld",&n); for(int i=1;i<=n;i++){ scanf("%lld",&x); pre[i]=pre[i-1]+x; } int p1=1,p2=2,p3=3; long long ans=1e18; for(;p2<n;p2++){ int minn=1e18,maxn=0; for(int i=p1;i<p2;i++) ...
0
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { if (j % i == 0 && j * i > n && j / i < n) return cout << j << " " << i, 0; } } cout << -1 << endl; return 0; }
1
#include <bits/stdc++.h> using namespace std; typedef pair<long long, long long> ll; typedef vector<long long> vl; typedef vector<ll> vll; typedef vector<vl> vvl; long long checkpoint_counter = 0; template <typename T> ostream &operator<<(ostream &o, vector<T> v) { if (v.size() > 0) o << v[0]; for (unsigned i = 1; ...
2
#include <bits/stdc++.h> int n, mod, l, r, p[20], pcnt, sum[100005][20], fac[100005], inv[100005], ans; long long Pow(long long x, long long k) { long long t = 1; for (; k; k >>= 1, x = x * x % mod) if (k & 1) t = t * x % mod; return t; } int C(int a, int b) { if (b < 0) return 0; int res = 1ll * fac[a] *...
4
#include <iostream> #include <cmath> using namespace std; int main() { double a, l, x; cout.precision(10); while (cin >> a >> l >> x) { double area = sqrt(l * l - a * a / 4.0) * a / 2.0 + sqrt((l + x) * (l + x) / 4.0 - l * l / 4.0) * l; cout << fixed << area << endl; } return 0; }
0
#include <bits/stdc++.h> using namespace std; unordered_map<int, int> X, pre; unordered_map<int, int>::iterator it; int Find(int u) { it = pre.find(u); if (it == pre.end()) { X[u] = 0; return u; } int v = it->second; int tmp = Find(v); X[u] ^= X[v]; return pre[u] = tmp; } bool join(int a, int b, i...
4
#include <bits/stdc++.h> using namespace std; void tachyon() { ios_base::sync_with_stdio(0); cin.tie(nullptr); } const int N = 50; const int MAXE = 1e4 + 1; int n, d, c[N]; bool was[N * MAXE + 1]; vector<int> a; void solve() { cin >> n >> d; for (int i = 0; i < n; i++) cin >> c[i]; was[0] = 1; for (int i = ...
2
#include <bits/stdc++.h> using namespace std; void solve() { long long n; long long k; cin >> n >> k; vector<long long> arr(n); for (long long i = 0; i < n; i++) cin >> arr[i]; long long maxi = *max_element(arr.begin(), arr.end()); for (long long i = 0; i < n; i++) arr[i] = maxi - arr[i]; if (k % 2 == 0...
2
#include<iostream> #include<algorithm> #include<cstdio> #include<map> #include<list> using namespace std; signed main() { list<int>L; int a; cin >> a; for (int b = 0; b < a; b++) { int c; cin >> c; if ((a+b) & 1)L.push_front(c); else L.push_back(c); } for (auto i = L.begin(); i != L.end(); i++) { if (i ==...
0
#include<iostream> #include<math.h> using namespace std; int dim; bool ok(double v[],int exce,int obj); int main(){ while(cin >> dim && dim !=0){ double inp[dim+3]; for(int i=0;i<dim+3;i++){ cin >> inp[i]; } double ans=-1; for(int i=0;i<(dim+3)/2+1;i++){ if(ok(inp,i,2*i)){ ans...
0
#include <iostream> #include <algorithm> using namespace std; int main(void){ int n,i,p[110][2],h[110],cx,cy,t,ch,u; cin >> n; for (i=0;i<n;i++) cin >> p[i][0] >> p[i][1] >> h[i]; t=0; while (h[t]==0) t++; for (cx=0;cx<=100;cx++){ for (cy=0;cy<=100;cy++){ ch=abs(cx-p[t][0])+abs(cy-p[t][1])+h[t]; ...
0
#include<cstdio> #include<algorithm> #include<unordered_map> using namespace std; int main(){ int n,q; scanf("%d %d",&n,&q); unordered_map<int, int> v; for(int i=0;i<n;i++) v[i]=i; for(int i=0;i<q;i++){ int com,x,y; scanf("%d %d %d",&com,&x,&y); for(;;) if(x==v[x]) break; else x=v[x]; fo...
0
#include <bits/stdc++.h> using namespace std; int main() { int t, n, k, a, b, y, n1, k1; cin >> t; n1 = -1; k1 = -1; while (t--) { cin >> n >> k; if (n1 == n && k1 == k) { if (y == 1) cout << "Alice\n"; else if (y == 2) cout << "Bob\n"; } else y = 0; while (y ...
4
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 15; int n, m; vector<int> occur[maxn]; void init() { scanf("%d%d", &n, &m); for (int tot, i = 1; i <= n; ++i) { scanf("%d", &tot); for (int x, j = 1; j <= tot; ++j) { scanf("%d", &x); occur[abs(x)].push_back(x > 0 ? i : -i); ...
3
#include <bits/stdc++.h> using namespace std; string S; int N; int main(void){ cin>>S; N = S.size(); if(N==2){ int ans = abs((int)S[0]-(int)S[1]); cout<<ans<<endl; return 0; } vector<int>yak; for(int i = 1;i * i <= N;++i){ if(N % i == 0){ yak.push_back(i); if(i * i < N){ yak.push_back(N / i);...
0
#include <bits/stdc++.h> using namespace std; int main() { int ans=0,res=0; string s; cin>>s; for(int i=0; i<s.size(); i++){ if(s[i]!='A'&&s[i]!='T'&&s[i]!='G'&&s[i]!='C'){ ans=max(ans,res); res=0; } else res++; } cout<<max(ans,res); }
0
#include <bits/stdc++.h> using namespace std; int n, x, y; int abis(int a, int b) { if (a < b) return 0; return a - b; } int main() { int m = 1 << 30, M = 0; cin >> n; while (n--) { cin >> x >> y; m = min(m, y); M = max(M, x); } int mm = 1 << 30, Mm = 0; cin >> n; while (n--) { cin >> ...
2
#include<bits/stdc++.h> #define rep(i,n)for(int i=0;i<n;i++) using namespace std; int main() { int x, y, s; while (scanf("%d%d%d", &x, &y, &s), s) { int Max = 0; for (int i = 1; i < s; i++) { for (int j = 1; j <= i&&j + i <= s; j++) { if (i*(100 + x) / 100 + j*(100 + x) / 100 == s) { Max = max(Max, i...
0
#include <bits/stdc++.h> using namespace std; int Arr[200007], Ban[200007], Jaw[200007]; bool sudah[200007]; int main() { int n; cin >> n; for (int i = 1; i <= n; i++) cin >> Arr[i]; for (int i = 1; i <= n; i++) cin >> Ban[i]; int ind = 1; for (int i = 1; i <= n; i++) if (!sudah[Ban[i]]) { int ans...
2
#include<bits/stdc++.h> using namespace std; int main(){ int a,b; cin>>a>>b; if(a+b<10){cout<<a+b<<endl;} else{cout<<"error"<<endl;} }
0
#include <bits/stdc++.h> using namespace std; int main() { int mini = 1e9; int n; int arr[200]; scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d", &arr[i]); } for (int x = 1; x <= n; x++) { int total = 0; for (int i = 1; i <= n; i++) { int baja = abs(x - i) + abs(1 - i) + abs(x ...
1
#include <bits/stdc++.h> using namespace std; const int MAXN = 110000; struct Tree { int left, right; long long sum; }; Tree tree1[MAXN * 4]; Tree tree2[MAXN * 4]; long long col1[MAXN * 4]; long long col2[4 * MAXN]; long long a[MAXN]; long long b[MAXN]; void build(Tree tree[], long long a[], int id, int l, int r) {...
3
#include <bits/stdc++.h> using namespace std; int main() { long long int n, m, k; cin >> n >> m >> k; double ans = 1; for (long long int i = 0; i <= k; i++) { ans *= (m - i); ans /= (n + 1 + i); } if ((1 - ans) < 0) cout << 0 << "\n"; else cout << 1 - ans << "\n"; }
4
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; int ans = 0, take = 0; while (n) { ans++; n--; take++; if (take == k) { take = 0; n++; } } cout << ans << endl; return 0; }
1
#include <bits/stdc++.h> int nextInt(void) { char ch; int sign, x; do { ch = getchar(); } while (ch < '-'); if (ch == '-') { sign = -1; ch = getchar(); } else sign = 1; x = 0; while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); } return sign * x; } int mai...
2
#include <bits/stdc++.h> using namespace std; template <typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>; template <class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T& a, T b) { if (a > b) { a = b;...
4
#include <bits/stdc++.h> const int N = 300; const int inf = (int)1e9; inline int min(int x, int y) { if (x < y) return x; return y; } struct NetWork { static const int V = N + 2; static const int E = N * N + N; struct Edge { int to, cap, nxt; Edge() {} Edge(int _to, int _cap, int _nxt) : to(_to), ...
5
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") using namespace std; int32_t main() { ios::sync_with_stdio(false); cin.tie(0); long long T = 1, n; cin >> T; while (T--) { cin >> n; vector<pair<long long, long long> > A(n); for (long long i = 0; i < n; ++i) { cin >> A[i].first; A...
3
#include <bits/stdc++.h> using namespace std; const int INF = 1e9 + 7; const int N = 4 * 1e3 + 5; long long diag1[N], diag2[N]; int board[N][N]; int main() { int n, x; scanf("%d", &n); for (int r = (0); r < (n); ++r) { for (int c = (0); c < (n); ++c) { scanf("%d", &x); board[r][c] = x; diag1...
3
#include <bits/stdc++.h> using namespace std; const int maxN = 100 + 5; int N, k, full; bool matr[maxN][maxN]; int nextCh3(int n, int i) { return (n * (i + 1)) / (i - 2); } int nextCh2(int n, int i) { return (n * (i + 1)) / (i - 1); } int main() { memset(matr, false, sizeof(matr)); scanf("%d", &k); for (N = 3, fu...
3
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; unordered_set<int> s; vector<int> v(n); for (int &x : v) cin >> x, s.insert(x); unordered_map<int, int> mp; for (int i = n - 1; i >= 0; i--) { if (s.count(v[i]) || mp[v[i]] > 0) mp[v[i]]++, s.erase(v[i]); if (s.empty()) { ...
2
#include<bits/stdc++.h> using namespace std; int main(){ int q; cin>>q; while(q--){ int m,n,t,c=0; cin>>m>>n; t=m*m+n*n; for(int i=0;i<2000;i++) for(int j=0;j<2000;j++) if(i*i+j*j<1)continue; else if((m*i+n*j)%(i*i+j*j)==0&&(m*j-n*i)%(i*i+j*j)==0)c++; if(c<=4)cout<<'P'<<e...
0
#include <bits/stdc++.h> using namespace std; const int inf = (1 << 30) - 1; int n, m, nes = 0, s[200005], e[200005], h[200005], c[200005], d[200005], t[200005], ts[200005]; struct heap { int size, a[200005], pos[200005]; inline void Adj_down(int w) { int x = a[w], targ = w << 1, xKey = d[a[w]]; f...
2
#include <bits/stdc++.h> using namespace std; vector<int> by[100005]; int n, m; unsigned int st[100005]; vector<int> LevL[100005]; char ss[25]; map<pair<int, int>, int> Map; int F[100005][20], root = 0; int Ls[100005], Rs[100005]; int ans[100005]; vector<int> lev[100005]; int dp[100005]; set<unsigned int> mp; const int...
5
#include <bits/stdc++.h> using namespace std; #define ll long long int #define pii pair<ll,ll> #define rep(i,st,en) for(ll i=st;i<en;i++) #define vi vector<ll> #define vii vector<pii> #define all(x) x.begin(),x.end() #define rall(x) x.rbegin(),x.rend() #define eb emplace_back #define flus fflush(stdout); #define F fi...
1
#include <bits/stdc++.h> #define MOD 1000000007LL using namespace std; typedef long long ll; typedef pair<int,int> P; int n,a,b; int ans[500005]; int main(void){ scanf("%d%d%d",&n,&a,&b); int cur=n; int pos=0; int mxa=0; for(int i=0;i<b;i++){ int us=min(a,cur-(b-i-1)); if(us<=0){ printf("-1\n"); return...
0
#include<bits/stdc++.h> using namespace std; long long q,h,s,d,n,x; int main() { ios::sync_with_stdio(false); cin >> q >> h >> s >> d >> n; x = min(q * 4,min(h * 2,s)); cout << min(x * n,n / 2 * d + (n & 1) * x) << endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const double eps = 1e-6; const int inf = 0x3f3f3f3f; const int N = 3e5 + 10; int n, m, v, u, tot; int a[N], c[N], ans[N]; int s, p; bool vis[N]; vector<pair<int, int> > g[N], gg[N]; void dfs(int x) { for (int i = 0; i < g[x].size(); i++) { int...
2
#include <bits/stdc++.h> using namespace std; using ll = long long; using vl = vector<ll>; using vvl = vector<vl>; using ld = long double; using vd = vector<ld>; #define rng(i,a,b) for(int i = (a); i < (b); ++i) #define rep(i,n) for(int i = 0; i < (n); ++i) #define per(i,n) for(int i = (n)-1; i >= 0; --i) int N, M...
0
#include <bits/stdc++.h> #pragma comment(linker, "/stack:256000000") #pragma gcc optimize("O3") #pragma gcc target("sse4") using namespace std; mt19937 rng(2391); mt19937 gnr(chrono::high_resolution_clock::now().time_since_epoch().count()); template <typename A> istream& operator>>(istream& fin, vector<A>& v) { for (...
5
#include <bits/stdc++.h> using namespace std; const int INF = 1000 * 1000 * 1000; const int mod = 998244353; const int dwa = (mod + 1) / 2; string s[1005]; int add(long long a, long long b) { a %= mod; b %= mod; return a + b >= mod ? a + b - mod : a + b; } int mult(long long a, long long b) { a %= mod; b %= m...
6
#include<bits/stdc++.h> using namespace std; int ctoi(char); int main(){ int n; cin >> n; for(int I=0;I<n;I++){ string st; cin >> st; int f=0; for(int j=0;j<2;j++){ int r=-1; int l=-1; int t=j; for(int i=0;i<st.size();i++){ // cout << t; if(t==0){ r=ctoi(st[i]); if(...
0
#include "bits/stdc++.h" #pragma warning(disable:4996) using namespace std; struct aa { pair<int,int> prev_place; int prev_char; pair<int,int>now_place; }; int memo[5001][5001]; int main() { int N;cin>>N; vector<int>v(N); for(int i=0;i<N;++i)cin>>v[i]; sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()...
0
#include <bits/stdc++.h> using namespace std; template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) { os << "{ "; for (const T& t : v) os << t << ", "; return os << "}"; } template <typename A, typename B> ostream& operator<<(ostream& os, const pair<A, B>& pp) { return os << "{ " << pp.firs...
6