solution
stringlengths
52
181k
difficulty
int64
0
6
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c, d; cin >> a >> b >> c >> d; int m = max(3 * a / 10, a - a / 250 * c); int v = max(3 * b / 10, b - b / 250 * d); if (m == v) cout << "Tie"; else if (m > v) cout << "Misha"; else cout << "Vasya"; return 0; }
1
#include "bits/stdc++.h" using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int t; cin >> t; while (t--) { int n; cin >> n; vector<long long> c(n); for (int i = 0; i < n; i++) { cin >> c[i]; } array<long long, 2> small...
3
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:66777216") using namespace std; int a, b, c, d, i, j, n, m, k; inline void die(long double first) { printf("%.15lf\n", (double)first); exit(0); } long double check(long double y1, long double y2, long double yw, long double xb, long double y...
1
#include <bits/stdc++.h> using namespace std; int n, m; vector<pair<long long, int> > v(0); int main() { cin >> n >> m; long long lev, l, r, tp; long long tot = 0; while (m--) { scanf("%lld%lld%lld%lld", &lev, &l, &r, &tp); r++; while (lev < n) { l *= 2; r *= 2; lev++; } if...
4
#include <bits/stdc++.h> using namespace std; int main() { int n, k, net = 0; cin >> n >> k; for (int i = 0; i < n; i++) { string a; int count = 0; cin >> a; vector<int> ar(11); for (char x : a) { ar[int(x) - 48]++; } for (int i = 0; i <= k; i++) { if (ar[i] > 0) count++; ...
1
#include <bits/stdc++.h> using namespace std; int main() { int N, W; scanf("%d%d", &N, &W); vector<int> n; int maxW = 0, mini = 0; for (int i = 0; i < N; i++) { int v; scanf("%d", &v); n.push_back(v); maxW += v; if (v < n[mini]) { mini = i; } } if (N == 1) { if (W == n[0]...
5
#include <bits/stdc++.h> using namespace std; int x[50], y[50]; bool ok(int s1, int s2, int u1, int u2) { int ts1 = s1, ts2 = s2; int f[10]; memset(f, 0, sizeof(f)); for (int i = 0; i < u1; i++) { f[s1 % 7]++; s1 /= 7; } for (int i = 0; i < u2; i++) { f[s2 % 7]++; s2 /= 7; } for (int i =...
1
#include <bits/stdc++.h> const long long mod = 1009; using namespace std; int nnn, mm, goal, aa[200005]; vector<int> mjk[200005]; vector<int> lst; vector<int> TMP; namespace fftRR { const int MN = (int)1e6; int ffa[MN], ffb[MN]; long long ffres[MN]; int my_round(double x) { if (x < 0) return -my_round(-x); return (...
6
#include <bits/stdc++.h> #pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") using namespace std; using i32 = int; using i64 = long long; using u8 = unsigned char; using u32 = unsigned; using u64 = unsigned long long; usin...
5
#include <bits/stdc++.h> using namespace std; const int MAX = 2010; int seq[4]; int a[MAX]; int main() { int n; scanf("%d", &n); for (int i = 0; i < n; ++i) scanf("%d", a + i); for (int i = 0; i < n; ++i) { seq[3] = max(seq[2], seq[3]) + (a[i] == 2); seq[2] = max(seq[1], seq[2]) + (a[i] == 1); seq[1...
3
#include <bits/stdc++.h> using namespace std;pair <int, int> p[200100];int N,n[200100],d[200100]; int main() {cin>>N;for(int i=0;i<N;i++)cin>>p[i].first>>p[i].second;sort(p,p+N);d[N]=1;for(int i=N;i--;){int c=i+1;while(c<N&&p[c].first<p[i].first+p[i].second)c=n[c];d[i]=(d[i+1]+d[n[i]=c])%998244353;}cout<<d[0]<<"\n";}
0
#include <bits/stdc++.h> using namespace std; vector <string> ans; string Str,str; bool cal(){ bool alph[300]={}; alph['a']=1; for(int i=0;i<str.size();i++){ int flg=0; if(!alph[str[i]])flg=alph[str[i]]=1; if(str[i]-flg!=Str[i])return 0; } return 1; } bool used[300]; void saiki(int idx){ while(...
0
#include<bits/stdc++.h> using namespace std; int main(){ string S,T;cin>>S>>T; string SS=S+S; //みぎにいくつ進めばたどり着けるか vector<vector<long>>N(SS.length(),vector<long>(26,-1)); for(long c=0;c<26;c++){ long l=-1; for(long i=SS.length()-1;i>=0;i--){ if(l!=-1)N[i][c]=l-i; if(SS[i]-97==c)l=i; } ...
0
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 5; priority_queue<pair<long long, long long> > q; int n, m = 0; pair<long long, long long> a[maxn * 2 + 5]; int main() { scanf("%d", &n); long long ansa = 0, ansb = 0; for (int i = 1; i <= n; i++) { long long x1, y1, x2, y2; scanf("%lld%...
6
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e6 + 7; int main() { ios::sync_with_stdio(false); long long n, k; long long a, b, c; cin >> n >> k; a = n * 2; b = n * 5; c = n * 8; if (a % k == 0) a = a / k; else a = a / k + 1; if (b % k == 0) b = b / k; else b = b ...
1
#include <bits/stdc++.h> using namespace std; int t, n, a[55], b[55], min_a, min_b; long long sum; int main() { cin >> t; while (t--) { cin >> n; min_a = 1000000000; min_b = 1000000000; sum = 0; for (int i = 1; i <= n; i++) { cin >> a[i]; min_a = min(min_a, a[i]); } for (int ...
2
#include <bits/stdc++.h> using namespace std; inline int getint() { int c, l = 0, x; for (; !isdigit(c = getchar()); l = c) if (c == EOF) return 1 << 31; for (x = c - '0'; isdigit(c = getchar()); x = x * 10 + c - '0') if (c == EOF) break; return l == '-' ? -x : x; } const int N = 1200; char B[N][N], A[N...
5
#include <bits/stdc++.h> using namespace std; unordered_map<string, string> m; int q; int main(int argc, const char* argv[]) { cin >> q; for (int i = 0; i < q; i++) { string o, n; cin >> o >> n; bool broken = false; for (auto x : m) { if (x.second == o) { m[x.first] = n; broken...
2
#include <bits/stdc++.h> using namespace std; using ll = long long; const ll MOD = 1e9+7; ll modpow(ll m, ll n){ if(n == 0) return 1; else if(n % 2 == 0) return modpow(m * m % MOD, n/2); else{ return modpow(m, n - 1) * m % MOD; } } int main(){ int n, k; scanf("%d %d", &n, &k); ll ans = 0; vect...
0
#include <bits/stdc++.h> using namespace std; int main() { long long int t, a, b, c, d, i, j, k, l, n, m, x, y; cin >> t; while (t--) { cin >> n; set<long long int> s; for (i = 0; i < n; i++) { cin >> a; s.insert(a); } b = s.size(); if (b == 1) cout << n << endl; else...
1
#include <bits/stdc++.h> #pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") using namespace std; vector<long long int> graph[200010], backIn[200010], backOut[200010], tree[200010]; long long int dep[200010], par[200010]; void dfs(long long int i, long long int p) { par[i] =...
4
#include <bits/stdc++.h> #pragma GCC target("avx") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") using namespace std; using ll = long long; using datas = pair<ll, ll>; using ddatas = pair<long double, long double>; using tdata = pair<ll, datas>; using vec = vector<ll>; using mat = vector<vec>; using p...
5
#include<bits/stdc++.h> using namespace std; typedef long long LL; const int N=1001001; const LL INF=1e15; void gg(){ puts("-1"); exit(0); } int n; int a[N]; LL suf[N]; int main(){ ios::sync_with_stdio(false); cin>>n; for(int i=0;i<=n;i++){ cin>>a[i]; } /** * t=1; * { * ans+=t; * t-=a[i]; * t=t...t*2...
0
#include<iostream> using namespace std; int main(){ int r,g,b,n; cin>>r>>g>>b>>n; int ans=0; for(int i=0;i<=n;i++){ for(int j=0;j<=n;j++){ int k=n-i*r-j*g; if(k>=0&&k%b==0) ans++; } } cout<<ans<<endl; }
0
#include <iostream> using namespace std; int main() { string s; int n, x; cin >> s; while (s != "-") { cin >> n; for (int i=0; i<n; i++) { cin >> x; s = s.substr(x) + s.substr(0, x); } cout << s << endl; cin >> s; } }
0
#include <bits/stdc++.h> using namespace std; int n, m, b, g; int boy[101]; int girl[101]; int main() { cin >> n >> m; cin >> b; int un = 0; for (int i = 0; i < b; i++) { int x; cin >> x; boy[x] = 1; } un = n - b; cin >> g; for (int i = 0; i < g; i++) { int x; cin >> x; girl[x] =...
5
#include <bits/stdc++.h> using namespace std; int AbsDifference(int a, int b) { if (a >= b) return a - b; return b - a; } long long AbsDifference(long long a, long long b) { if (a >= b) return a - b; return b - a; } const int mod = 1000000007; const int mod2 = 1000000009; const int inf = 1 << 30; const long lon...
2
#include<bits/stdc++.h> #define REP(i,s,n) for(int i=s;i<n;i++) #define rep(i,n) REP(i,0,n) using namespace std; struct Edge { int dst,weight; }; typedef pair<int,int> ii; const int MAX_V = 1000; int V,p[MAX_V],d[MAX_V]; vector<Edge> G[MAX_V]; ii visit(int prev,int cur) { ii ret(0,cur); rep(i,(int)G[cur].size(...
0
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6; long long int a[maxn]; long long int sum, ave, ans; int main() { int n; cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 1; i <= n; i++) sum += a[i]; ave = sum / n; for (int i = 1; i <= n; i++) { ans += abs(a[i] - ave); ...
2
#include <bits/stdc++.h> using namespace std; int main() { int x, y; cin >> x >> y; int a[3]; for (int i = 0, _b = (2); i <= _b; i++) a[i] = y; int res = 0; while (a[0] < x) { a[0] = min(a[1] + a[2] - 1, x); res++; sort(a, a + 3); } cout << res; }
3
#include <bits/stdc++.h> using namespace std; long long mod = 1e9 + 7; const long long inf = (long long)1e9; double PI = 3.14159265; double eps = 1e-9; long long t = 0; long long pow(long long a, long long b) { if (b == 0) return 1; if (b % 2 == 1) { return (pow(a, b - 1) * a); } if (b % 2 == 0) { long ...
3
#include <iostream> using namespace std; int n,k,t=0; bool prime(int o) { if(o<2)return false; for(int i=2;i*i<=o;i++)if(o%i==0)return false; return true; } int main() { cin>>n; while(n--) { cin>>k; if(prime(k))t++; } cout<<t<<endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const long long INFLL = 1e18; const int MOD = 1e9 + 7; const int MAXN = 2e5 + 5; int ans = 1, n; vector<int> v; bool ispot(int x) { while (x > 1) { if (x & 1) return 0; x /= 2; } return 1; } int main() { scanf("%d", &n); int ans...
2
#include <bits/stdc++.h> const int N = 5010; const long long inf = 1e18; using namespace std; int n; long long a[N], t[N], dp[N], mn[N]; int main() { int n; scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%I64d", &a[i]), t[i] = a[i]; for (int i = 0; i <= n; i++) dp[i] = inf; sort(t + 1, t + 1 + n); for...
3
#include <bits/stdc++.h> using namespace std; int lps[45]; long long dp[45][45]; string s; void LPS() { int i = 1, len = 0; while (i < (int)s.size()) if (s[i] == s[len]) lps[i++] = ++len; else if (len) len = lps[len - 1]; else i++; } int advance(int st, char c) { while (1) { if (...
6
#include <bits/stdc++.h> using namespace std; double eps = 1e-9; const int INF = 1e9 + 7; const int MAXN = int(2e5 + 7); int n, n1, n2, ans, p[2007], pw[2007], a[2007], b[2007], base = 31; set<int> st[2007]; string second, t1, t2; int main() { cin >> second >> t1 >> t2; n = second.size(), n1 = t1.size(), n2 = t2.si...
4
#include <bits/stdc++.h> using namespace std; int main() { string simple = "", input; for (int i = 0; i < 3; i++) { cin >> input; simple += input.at(0); } if (simple == "rss" || simple == "prr" || simple == "spp") { cout << "F"; } else if (simple == "srs" || simple == "rpr" || simple == "psp") { ...
1
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; long long freq[n + 1], ineq, impar, s, p; memset(freq, 0, sizeof(freq)); long long vet[n]; for (int i = 0; i < n; i++) cin >> vet[i], freq[vet[i]]++; impar = 0; for (int i = 1; impar < 2 && i <= n; i++) if (freq[i] % 2...
3
#include<bits/stdc++.h> using namespace std; using ll = long long; #define TR(X) ({ if(1) cerr << "Trace: " << (#X) << " = " << (X) << endl; }) ll n,m; ll dp[100005], res[100005]; vector<ll> adj[100005]; void dfs1(ll cur, ll par) { dp[cur] = 1; for(ll nxt: adj[cur]) if(nxt != par){ dfs1(nxt, cur); (dp[cur] *= (...
0
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; const int N = 1e5 + 5; const float pi = 3.14159265358979323; const long long inf = 1e18 + 5; const long double eps = pow(2, -52); int n, m; string test; map<string, int> p1, p2; int main() { cin >> n >> m; for (int i = 0; i < n; i++) cin >> test...
2
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; int a, b; while (t--) { cin >> a >> b; int d = 2; int ans = 0; a -= 2; ans++; while (a > 0) { ans++; a -= b; } printf("%d\n", ans); } return 0; }
1
#include <bits/stdc++.h> using namespace std; const int INF = 1e9 + 7; const int N = 1e3 + 10; int main() { int a, b, r; cin >> a >> b >> r; if (r * 2 > min(a, b)) cout << "Second" << endl; else cout << "First" << endl; return 0; }
1
#include <bits/stdc++.h> using namespace std; int n, m, q; int nxt[100001]; char s[100001], t[100001]; int temp[100001]; int l, r; bool check(int u) { for (int i = 0; i < m; ++i) { if (s[u + i] != t[i]) return 0; } return 1; } void pre_do() { for (int i = 1; i <= n - m + 1; i++) { temp[i] += check(i); ...
2
#include <bits/stdc++.h> using namespace std; const int mod = 998244353; const long long mod2 = mod * 1ll * mod; const int CUTOFF = 100; inline int add(int x, int y) { x += y; if (x >= mod) x -= mod; return x; } inline int sub(int x, int y) { x -= y; if (x < 0) x += mod; return x; } inline int mul(int x, in...
6
#include <iostream> using namespace std; int main() { int X; cin >> X; cout << (X % 100 <= X / 100 * 5 ? 1 : 0) << endl; }
0
#include <bits/stdc++.h> using namespace std; template <typename Arg1> void __f(const char* name, Arg1&& arg1) { cerr << "[" << name << " : " << arg1 << "]" << '\n'; } template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args) { const char* comma = strchr(names + 1, ','); ...
4
#include <bits/stdc++.h> using namespace std; long long n, m, dp[5005][5005], inv[5005], a[5005], f[5005], e[5005], mod = 998244353, ans; int main() { cin >> n; for (register int(i) = (1); (i) <= (n); (i)++) cin >> a[i]; stable_sort(a + 1, a + n + 1); for (register int(i) = (1); (i) <= (n); (i)++) f[i] ...
6
#include <bits/stdc++.h> using namespace std; const double EPS = 1e-9; const double PI = 3.141592653589793; const int INF = 2000000000; int GCD(int a, int b) { return b ? GCD(b, a % b) : a; } int LCM(int a, int b) { return (a / GCD(a, b)) * b; } int main() { string str, ans; cin >> str; if (str.size() > 3 && str[...
2
#include<bits/stdc++.h> using namespace std; using int64 = long long; int main() { int64 X; cin >> X; cout << (1LL << (2 + X)) - 2 << endl; }
0
#include <bits/stdc++.h> using namespace std; pair<int, int> P[100010]; map<int, vector<int>> m1, m2; struct Vertical { int x, t, id; bool operator<(const Vertical& rhs) const { return x < rhs.x; } }; struct Horizon { int x, t, id; bool operator<(const Horizon& rhs) const { return t < rhs.t; } }; vector<Vertica...
2
#include <bits/stdc++.h> using namespace std; template <class T> void debug(T e) { cout << e << endl; } template <class T1, class T2> void debug(T1 e1, T2 e2) { cout << e1 << "\t" << e2 << endl; } template <class T1, class T2, class T3> void debug(T1 e1, T2 e2, T3 e3) { cout << e1 << "\t" << e2 << "\t" << e3 << e...
1
#include <bits/stdc++.h> using namespace std; const long long int N = 5e5 + 5; void fun() {} long long int md = 1e9 + 7; long long int __gcd(long long int a, long long int b) { if (b == 0) return a; return __gcd(b, a % b); } long long int poww(long long int a, long long int b, long long int md) { long long int re...
4
#include <bits/stdc++.h> using namespace std; int main() { string x; cin >> x; if (x[0] >= 'a' && x[0] <= 'z') x[0] -= 32; cout << x; return 0; }
1
#include <bits/stdc++.h> using namespace std; template <class T> bool rmn(T& a, T b) { return a > b ? (a = b, true) : false; } template <class T> bool rmx(T& a, T b) { return a < b ? (a = b, true) : false; } const long long INFLL = 0x7f7f7f7f7f7f7f7f, MOD = 1e9 + 7; const long long INF = 0x7f7f7f7f; vector<vector<l...
5
#include <bits/stdc++.h> using namespace std; const int N = 505; char g[N][N]; int id[N][N]; int cnt = 1; int dx[] = {0, 0, 1, -1}; int dy[] = {1, -1, 0, 0}; int amt[N * N]; int sz[N * N]; int sum; int n, k; void dfs(int i, int j, int idx) { if (g[i][j] == 'X' or id[i][j]) return; id[i][j] = idx; sz[idx]++; for...
3
#include <bits/stdc++.h> using namespace std; int main() { long long int q,h,s,d,n,x,y,ans; cin>>q>>h>>s>>d>>n; x=min(8*q,min(4*h,min(2*s,d))); y=min(4*q,min(2*h,s)); ans=(n/2)*x+(n%2)*y; cout<<ans<<endl; }
0
#include <bits/stdc++.h> using namespace std; const int MAXN = 500 + 10; const int MOD = 1e9 + 7; int c[MAXN * 32][MAXN]; map<int, int> p; int main() { int n, a; scanf("%d", &n); for (int i = 0; i < n; ++i) { scanf("%d", &a); for (int j = 2; j * j <= a; ++j) { while (a % j == 0) { ++p[j]; ...
1
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 100005; int n, m, q; ll a[N], k[N], s[N]; int main() { scanf("%d%d", &n, &q); a[m = 1] = n; for (ll x; q--;) { scanf("%lld", &x); while (m && a[m] >= x) --m; a[++m] = x; } k[m] = 1; for (int i = m; i; --i) { ll now = a[i]...
0
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); int n, m; cin >> n >> m; for (int i = 0; i < 1130; i++) cout << 4; cout << 5 << endl; for (int i = 0; i < 1130; i++) cout << 5; cout << 5 << endl; return 0; }
2
#include <bits/stdc++.h> using namespace std; void fast() { ios_base::sync_with_stdio(false); cin.tie(NULL); } set<unsigned long long> val[2]; unsigned long long n, m; void sos(vector<unsigned long long>& arr, unsigned long long n, unsigned long long idx, unsigned long long sum, unsigned long long t) { i...
5
#include<cstdio> #include<cstring> #include<vector> #define int long long using namespace std; vector<int>e[30]; int tree[1001000],n,R[200100],vis[200100],ans; char S[200100]; void modify(int t,int l,int r,int pos){ if(l==r){ tree[t]++; return; } int mid=(l+r)/2; if(pos<=mid)modify(t*2,l,mid,pos); else modify(...
0
#include<cstdio> #include<algorithm> using namespace std; #define MAXN 100010 int n,ans; struct node { int x,id; }a[MAXN]; bool cmp(node A,node B) { return A.x<B.x; } int main() { scanf("%d",&n); for(int i=1;i<=n;i++) { scanf("%d",&a[i].x); a[i].id=i; } sort(a+1,a+1+n,cmp); for(int i=1;i<=n;i++) ans+=((a[...
0
#include <bits/stdc++.h> using namespace std; void solve() { char S[110]; scanf("%s", S); int len = strlen(S); sort(S, S + len); for (int i = 0; i < len - 1; i++) { if (S[i + 1] - S[i] != 1) { printf("NO\n"); return; } } printf("YES\n"); } int main() { int T; scanf("%d", &T); whi...
1
#include <bits/stdc++.h> using namespace std; long long m, n, k, t, a[200005]; vector<pair<long long, long long> > sp[200005]; bool safe(long long pos, long long minn) { long long f = 1; for (pair<long long, long long> p : sp[pos]) { if (p.second > minn) f = 0; } return f; } bool cmp(pair<long long, long lo...
4
#include <bits/stdc++.h> using namespace std; const int M = 1000000007, maxN = 2 * 100000; int f[maxN + 1] = {1, 1}; int mod_pow(int a) { int res = 1, n = M - 2; a %= M; while (n) { if (n & 1) res = (long long)res * a % M; a = (long long)a * a % M; n >>= 1; } return res; } int c(int n, int k) { ...
3
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 9; const int M = 1e3 + 9; const int INFINT = 1e9 + 9; const long long INFLL = 1e18 + 9; const long long MOD = 10000000000007ll; vector<int> gr[N]; int cnt[N]; int dfs(int v) { cnt[v] = 0; for (auto i : gr[v]) { if (cnt[i] == -1) cnt[v] += dfs(i);...
1
#include <bits/stdc++.h> using namespace std; const int maxn = 100000 + 10; struct pt { int x, y; pt(int _x = 0, int _y = 0) { x = _x; y = _y; } bool operator<(const pt &rhs) const { if (x == rhs.x) return y < rhs.y; return x < rhs.x; } }; pt operator+(const pt &a, const pt &b) { return (pt){a...
5
#include <bits/stdc++.h> using namespace std; namespace DynamicTree { unsigned int randxor() { static unsigned int x = 123456789, y = 362436069, z = 521288629, w = 88675123; unsigned int t; t = (x ^ (x << 11)); x = y; y = z; z = w; return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8))); } struct D_NODE { int laz...
5
#include <bits/stdc++.h> using namespace std; long long d[100010]; vector<int> e[100010], ec[100010]; int u[300010], v[300010], w[300010], qu[300010], qv[300010], qk[300010], be[100010]; long long ans[300010]; int par[100010]; int find(int x) { return par[x] == x ? x : (par[x] = find(par[x])); } const int C = 340; ...
6
#include <bits/stdc++.h> using namespace std; int main() { int i, j, max = -1, n, b, price; int a[2222]; cin >> n >> b; for (i = 0; i < n; i++) cin >> a[i]; if (n == 1) { cout << b; return 0; } for (i = 0; i < n - 1; i++) for (j = i; j < n; j++) { price = b + (b / a[i]) * (a[j] - a[i]); ...
2
#include<cstdio> #include<cstdlib> #include<iostream> #include<algorithm> using namespace std; const int maxn = 2e5 + 10; struct Sec{ int l, r; void read() { scanf("%d%d", &l, &r); } bool operator < (const Sec &A) const { return l == A.l ? r < A.r : l < A.l; } Sec operator + (const Sec &A) const { return (...
0
#include <bits/stdc++.h> using namespace std; inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;} template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();} template<class T> inline T sqr(T x) {return x*x;} typedef vector<int> vi; typedef vector<vi> vvi; typed...
0
#include <bits/stdc++.h> using namespace std; int main() { int n, ans = 0, a = 0; string s; scanf("%d", &n); cin >> s; for (int i = 0; i < n; i++) { if (s[i] == 'x') { a++; if (a > 2) ans++; } else a = 0; } cout << ans << endl; return 0; }
2
#include <bits/stdc++.h> using namespace std; int main() { int n, k; while (cin >> n >> k) { vector<int> v(n); for (int i = 0; i < n; i++) cin >> v[i]; sort(((v).rbegin()), ((v).rend())); int j = 0, ans = 0; while (j < n) ans += (v[j] * 2 - 2), j += k; cout << ans << endl; } return 0; }
2
#include <bits/stdc++.h> using namespace std; const int MAX = 1e6 + 10; int a[MAX]; int main() { int n, k; scanf("%d %d", &n, &k); for (int i = 0; i < n; ++i) scanf("%d", a + i); long long ans = 0, ans2 = 0; for (int i = 1; i < n; ++i) { if (a[i] + a[i - 1] < k) { int dif = k - (a[i] + a[i - 1]); ...
2
#include <iostream> #include <cstring> using namespace std; int n,m,x,y,f[210000],cnt[210000]; int find(int k) { if(f[k]==k)return k; return f[k]=find(f[k]); } int main(void) { cin>>n>>m; for(int i=1;i<=n;i++)f[i]=i; for(int i=1;i<=m;i++) { cin>>x>>y; f[find(x)]=find(y); } ...
0
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; long long n = (long long)s.length(); stack<char> A; if (n % 2 == 1) { cout << "No\n"; return 0; } for (int i = 0; i < n; i++) { if (A.empty()) A.push(s[i]); else if (A.top() == s[i]) A.pop(); els...
2
#include <cstdio> #include <algorithm> int main() { int tc; scanf("%d", &tc); for(int tci = 0; tci < tc; tci++) { int n,k; scanf("%d%d", &n, &k); int *a = new int[n]; for(int i = 0; i < n; i++) scanf("%d", a+i); for(int i = 0; i < n-1; i++) a[i] = a[i+1] - a[i]; std::sort(a,a+n-1); int s = ...
0
#include <bits/stdc++.h> using namespace std; const int MAXN = 1020; int n, m; int vis[MAXN][MAXN], g[MAXN][MAXN], ans; char s[MAXN]; struct A { int x, y, z; } Ans[MAXN * MAXN]; vector<int> vx, vy; int main() { scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) { scanf("%s", s); for (int j = 0; j <= m - ...
5
#include <bits/stdc++.h> using namespace std; const double eps = 1e-8; const long long MOD = 1000000007; int n, m; int sumv, sume; vector<pair<int, int> > e[555]; int value[555]; int sum[555]; vector<pair<pair<int, int>, int> > g; bool used[555]; bool cmp(const pair<pair<int, int>, int>& a, const pair<pair<int...
1
#include <bits/stdc++.h> using namespace std; const int N = (int)1e5 + 3; const int K = 20; const int inf = (int)1e9 + 7; const double eps = 1e-10; struct lem { int m, v, n; lem() {} lem(int m, int v, int n) : m(m), v(v), n(n) {} bool operator<(const lem& a) const { if (m == a.m) { return v < a.v; ...
2
#include <bits/stdc++.h> using namespace std; const int iinf = 1234567890; const int linf = 1234567890987654321; const long double eps = 1e-9; int main() { int n; int t; cin >> n >> t; t *= 2; vector<pair<int, int> > coords; for (int i = 0; i < n; i++) { int a, b; cin >> a >> b; a *= 2; coor...
1
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; struct num { int cost, idx; }; vector<num> v(n); for (int i = 0; i < n; ++i) { cin >> v[i].cost; v[i].idx = i + 1; } sort(v.rbegin(), v.rend(), [&](const num &lhs, const num &rhs) { if (lhs.cost == rhs.co...
1
#include <bits/stdc++.h> using namespace std; int cnt[27]; int main() { int n; scanf("%d", &n); getchar(); for (int i = 0; i < n; i++) { char ch = getchar(); cnt[ch - 'a']++; } int cntsingle = 0; int cntdouble = 0; for (int i = 0; i < 26; i++) { if (!cnt[i]) continue; if (cnt[i] == 1) ...
1
#include <bits/stdc++.h> using namespace std; int N, i, A[310], B[310], j; vector<int> SOL; int main() { cin >> N; for (i = 1; i <= N; i++) cin >> A[i]; for (i = 1; i <= N; i++) cin >> B[i]; for (i = 1; i <= N; i++) { if (A[i] == B[i]) continue; for (j = i + 1; j <= N; j++) if (B[j] == A[i]) break...
4
#include <bits/stdc++.h> using namespace std; double l, d, v1, v2; int main() { cin >> d >> l >> v1 >> v2; cout << setprecision(20) << fixed << (double)(l - d) / (v1 + v2); return 0; }
1
#include <bits/stdc++.h> using namespace std; int main() { long long n, cost; cin >> n >> cost; long long a[n + 1], b[n + 1]; for (int i = 1; i < n; i++) cin >> a[i]; for (int i = 1; i < n; i++) cin >> b[i]; long long dp[4][n + 1]; memset(dp, 0, sizeof(dp)); dp[0][1] = a[1]; dp[1][1] = cost + b[1]; ...
5
#include <bits/stdc++.h> using namespace std; const int MAXN = 1000005; const int OFFSET = 2000005; int per[MAXN + OFFSET]; int main() { int n, i, j, k; scanf("%d", &n); int head, tail; for (i = 0, j = 1; j <= n; j++, i++) { per[i] = j; } head = 0; tail = 0 + n; for (k = 2; k <= n; k++) { if (n ...
2
#include <bits/stdc++.h> using namespace std; int n; inline bool isValid(int x, int y, int z) { if (x > n or x <= 0 or y > n or y <= 0 or z > n or z <= 0) { return false; } return true; } int main() { int a[101], k, x, i; cin >> n >> k >> x; for (i = 1; i <= n; i++) { cin >> a[i]; } int temp_ans...
2
#include <bits/stdc++.h> using namespace std; long long qread() { char c = getchar(); int neg = 1; long long val = 0; while (c != '-' && !isdigit(c)) c = getchar(); if (c == '-') c = getchar(), neg = -1; while (isdigit(c)) val = (val << 3) + (val << 1) + c - '0', c = getchar(); return neg * val; } const i...
3
#include <bits/stdc++.h> using namespace std; int a[100005]; int bs(int t, int p) { int lo = 0, hi = p - 1; while (lo <= hi) { int mid = (lo + hi) / 2; if (a[mid] == t) return mid; else { if (a[mid] > t) { hi = mid - 1; } else { lo = mid + 1; } } } return ...
1
#include <bits/stdc++.h> using namespace std; #define nl "\n" #define pb push_back #define rep(i,s,n) for(int i=s;i<n;i++) #define fill_arr(arr) for(auto &x:arr) cin>>x; int mod = 1e9+7; vector<vector<int>> A; vector<int> path; int get_size(int u,int *vis){ *(vis+u)=1; int cnt=1; for(int x: A[u]){ ...
4
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { if (a == 0) return b; return gcd(b % a, a); } long long bigmod(long long b, long long p, long long m) { if (p == 0) return 1; if (p % 2 == 0) { long long temp = bigmod(b, p / 2, m); return (temp * temp) % m; } re...
3
#include <bits/stdc++.h> using namespace std; int d[300050]; pair<int, int> d2[300050]; bool chk[300050]; int ans_chk[300050]; vector<int> ANS; int main() { int N, i, j; scanf("%d", &N); for (i = 1; i <= N; i++) { scanf("%d", &d[i]); d2[i].first = d[i]; d2[i].second = i; } sort(d2 + 1, d2 + N + 1)...
4
#include <bits/stdc++.h> using namespace std; int main() { long long a, b, s; cin >> a >> b >> s; int x = abs(a) + abs(b); if (s >= x && s % 2 == x % 2) cout << "YES" << endl; else cout << "NO" << endl; }
1
#include <bits/stdc++.h> using namespace std; const double PI = 3.14159265358979323846; const double eps = (1e-6); int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n; cin >> n; set<int> s; for (int i = 0; i < n; ++i) { int x; cin >> x; s.insert(x); if ((int)(s).size() > 3) { ...
2
#include <bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; const int N = 2e5 + 5; long long t[N], a[N], b[N]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, m, k; cin >> n >> m >> k; int cnta = 0, cntb = 0; set<pair<long long, long long> > ab, aa, bb; for (int i...
5
#include <bits/stdc++.h> using namespace std; const int MAXN = 25; const int MAXS = 1 << 20; template <typename T> void chkmax(T &x, T y) { x = max(x, y); } template <typename T> void chkmin(T &x, T y) { x = min(x, y); } template <typename T> void read(T &x) { x = 0; int f = 1; char c = getchar(); for (; !i...
6
#include <bits/stdc++.h> using namespace std; long long int N = 1e9 + 7; void solve() { long long int n, x, y; cin >> n >> x >> y; vector<pair<long long int, long long int> > a(n); for (long long int i = 0; i < n; i++) { cin >> a[i].first >> a[i].second; } sort(a.begin(), a.end()); long long int l = a...
4
#include <bits/stdc++.h> using namespace std; double DP[2][1005]; int result[1005]; int main() { ios_base::sync_with_stdio(0); int K, Q; scanf("%d%d", &K, &Q); DP[0][0] = 1.0; int curp = 0; int i = 1; while (curp < 1000) { DP[i % 2][0] = 0.0; for (int j = (1); j < (K + 1); ++j) { DP[i % 2][j...
4