solution
stringlengths
52
181k
difficulty
int64
0
6
#include <bits/stdc++.h> using namespace std; int main() { int n, m, a, b; bool ar[10000]; scanf("%d%d", &n, &m); for (int i = 0; i < m; i++) { scanf("%d%d", &a, &b); ar[a] = true; ar[b] = true; } int j; for (int i = 1; ar[i]; i++) j = i; j++; printf("%d\n", n - 1); for (int i = 1; i <= ...
2
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } long long n, a, b, p, q; int main() { cin >> n >> a >> b >> p >> q; cout << n / a * p + n / b * q - n / (a / gcd(a, b) * b) * min(p, q) << endl; }
3
#include <bits/stdc++.h> using namespace std; const long long int K = 1e9 + 7; long long int mu(long long int a, long long int n) { if (n == 0) return 1; long long int q = mu(a, n / 2); if (n % 2 == 0) return q * q % K; return q * q % K * a % K; } const int MaxN = 100005; long long int inv[MaxN]; namespace Poly...
5
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 10; int n, k; unsigned int a[MAXN], subnetmask, Ans; string s[MAXN]; set<unsigned int> S; bool found = 0; int toint(string t) { unsigned int n = 0, temp = 1; for (int i = (int)t.size() - 1; i >= 0; i--) { n += (temp * (t[i] - '0')); temp *...
3
#include <bits/stdc++.h> using namespace std; int main() { long long x, sum = 0, sum1 = 0, sum2 = 0, y; cin >> x; for (int i = 0; i < x; i++) { cin >> y; sum += y; } for (int i = 0; i < x - 1; i++) { cin >> y; sum1 += y; } for (int i = 0; i < x - 2; i++) { cin >> y; sum2 += y; } ...
2
#include <bits/stdc++.h> using namespace std; int main() { long long int ans, n; cin >> n; ans = n; int d, e, val1, val2; cin >> d >> e; int i = 0, j = 0, k1[] = {1, 2, 5, 10, 20, 50, 100}, k2[] = {5, 10, 20, 50, 100, 200}; while (1) { ans = min(ans, (n - (5 * e * i)) % d); i++; if (5 * ...
1
#include <bits/stdc++.h> long long n, a[20001], b[20001], c; long long ans; long long find(long long T, long long low) { long long l, r, mid, t = 0; double tmp = 0, t2; int i; l = low, r = 3000000000000000000LL; while (l < r) { mid = (l + r) / 2; t = 0; tmp = 0; for (i = 1; i <= n; ++i) { ...
5
#include <bits/stdc++.h> char s[200000 + 5]; int main() { int n, t, i, z = 0; scanf("%d%d%s", &n, &t, s); for (i = 0; i < n; i++) if (s[i] == '.') break; for (i++; i < n; i++) if (s[i] > '4') break; if (i < n) for (; t && s[i] > '4'; i--, t--) if (s[i - 1] == '.') { s[i - 2]++; ...
1
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[n]; int sum = 0; for (int i = 0; i < n; i++) { cin >> a[i]; sum += a[i]; } int ans = 0; for (int i = 1; i <= 5; i++) { sum = sum + 1; if (sum % (n + 1) != 1) { ans += 1; } } cout << ans << end...
1
#include<iostream> #include<stdio.h> #include<math.h> using namespace std; #define EPS (1e-15) #define equals(a,b) (fabs((a)-(b))<EPS) class Point { public: double x, y; Point() {} Point(double xx, double yy) { x = xx; y = yy; } Point operator + (Point& p) { return Point(x + p.x, y + p.y); } Point operator -...
0
#include <bits/stdc++.h> #include <cmath> using namespace std; typedef long long ll; //typedef unsigned long long ll; #define rep(i, n) for (int i = 0; i < (n); ++i) //#define rep(i, n) for (ll i = 0; i < (n); ++i) //#define sz(x) ll(x.size()) //typedef pair<ll, int> P; typedef pair<ll, ll> P; //const double INF = 1e...
0
#include <bits/stdc++.h> using namespace std; int main() { int64_t b; while (cin >> b, b) { for (int d = 100001; d > 0; --d) { int64_t a = (2 * b + d - d * d) / (2 * d); if (a <= 0) continue; if ((a + d) * (a + d - 1) - a * (a - 1) == 2 * b) { cout << a << " " << d << endl; b...
0
#include <bits/stdc++.h> using namespace std; inline void R(int &x) { x = 0; int 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(); } x *= f; } void Redirect() { fre...
6
#include <bits/stdc++.h> using namespace std; #define rep(i,a,b) for (int64_t i = (a); i < (b); i++) #define REP(i,n) rep(i,0,n) int n,a[15],x[15][15],y[15][15],ans=0; void check(int bits) { int num=0; REP(i,n) if(bits>>i&1) { ++num; REP(j,a[i]) if((bits>>x[i][j]&1)!=y[i][j])return; } ans=max(ans,num...
0
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long q; cin >> q; vector<long long> ret; vector<int> p(5e5 + 1, -1); function<int(int)> myFind = [&](int n) { if (p[n] == -1) { return n; } return p[n] = myFind(p[n]); }; ...
5
#include <bits/stdc++.h> using namespace std; struct point { int x, y; point(int X = 0, int Y = 0) { x = X, y = Y; } }; struct cmpx { bool operator()(const point &a, const point &b) { return a.x == b.x ? a.y < b.y : a.x < b.x; } }; struct cmpy { bool operator()(const point &a, const point &b) { return...
6
#include <bits/stdc++.h> using namespace std; int n, a[105], b[105], ans; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { char c; scanf(" %c", &c); if (c == 'C') a[i]++, b[j]++; } } for (int i = 1; i <= n; i++) ans += (a[i] * (a[i] - 1) +...
1
#include <bits/stdc++.h> using namespace std; int const p = 31; long long const MOD = 1e9 + 7; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; vector<long long> a(n); long long S = 0; for (int i = 0; i < n; ++i) { cin >> a[i]; S += a[i]; } sort(a.begin(),...
3
#include <bits/stdc++.h> using namespace std; string Addition(string a, string b); string Multiplication(string a, string b); string Multiplication(string a, int k); string Subtraction(string a, string b); string Division(string a, string b); string Division(string a, int k); string Div_mod(string a, string b); int Div...
1
#include <cstdio> int h[100010]; typedef unsigned int uint; int in() { int x = 0, c; for (; (uint)((c = getchar()) - '0') >= 10; ) { if (c == '-') return -in(); if (!~c) throw ~0; } do { x = (x << 3) + (x << 1) + (c - '0'); } while ((uint)((c = getchar()) - '0') < 10); return x; } int main(){ int n =...
0
#include <bits/stdc++.h> using namespace std; void DBG() { cerr << "]\n"; } template <typename T, typename... Args> void DBG(T first, Args... args) { cerr << first; if (sizeof...(args)) cerr << ", "; DBG(args...); } const long long int mxn = 2e6 + 10; long long int mul(long long int x, long long int y, long long ...
3
#include<bits/stdc++.h> using namespace std; int main(){ int64_t a,b,k,eat; cin>> a >> b >> k; eat=min(a,k); a-=eat; k-=eat; eat=min(b,k); b-=eat; k-=eat; cout<< a <<" "<< b <<endl; }
0
#include <bits/stdc++.h> using namespace std; int a[] = {1, 4, 8}, k; int main() { cin >> k; if (k > 36) cout << -1 << endl; else if (k % 2 == 1) { for (int i = 0; i < k / 2; i++) cout << a[2]; cout << a[1]; for (int i = k / 2 + 1; i < 18; i++) cout << a[0]; cout << endl; } else { for (i...
2
#include <bits/stdc++.h> using namespace std; using namespace std::chrono; using ll = long long; using ld = long double; constexpr ll inf = 0x3FFFFFFFFFFFFF; struct entry { ll pos, full, part; bool operator<(const entry& o) const { if (full != o.full) return full > o.full; if (part != o.part) return part > ...
3
#include <bits/stdc++.h> using namespace std; const int maxN = 2e5 + 5; int a[maxN]; void solve() { int n, k; cin >> n >> k; for (int i = 1; i <= n; i++) cin >> a[i]; long long int ans = 0; for (int i = 1; i <= n; i++) { long long int x = (a[i] + k - 1) / k; ans += x; long long int left = x * k - ...
4
#include <bits/stdc++.h> using namespace std; using ll = long long; ll gcd(ll u, ll v) { while (v != 0) { ll r = u % v; u = v; v = r; } return u; } int getBest(vector<ll>& vec, int start, int best) { ll curGcd = vec[start]; for (int i = start + 1; i < vec.size(); ++i) { curGcd = gcd(curGcd, ve...
1
#include <bits/stdc++.h> using namespace std; const int nMax = 504; int changes[nMax][nMax], parent[nMax][nMax]; string changed[nMax][nMax]; int dp[nMax][nMax]; string s; int main() { cin >> s; int n = (int)s.size(), k; cin >> k; for (int j = 0; j < n; ++j) { for (int i = j; i >= 0; --i) { changes[i][...
4
#include <cstdio> #include <iostream> #include <algorithm> #include <cstring> using namespace std; typedef long long LL; const LL N = 1000000007; LL dp[3005][3005] = {0}; LL pre[3005] = {0}; LL n; char c[3005] = {0}; int main(){ cin >> n; for(LL i = 2;i <= n;i ++) cin >> c[i]; dp[1][1] = 1; for(LL i = 2;i <= n;i ...
0
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 5; const long long INF = 1e18; int n, m; long long mn, wt[maxn]; int fa[maxn]; struct node { int u, v; long long w; } e[maxn * 2]; int head[maxn], tot; void init() { tot = 0; for (int i = 0; i <= n; i++) { fa[i] = i; } } void add(int u, ...
6
#include <bits/stdc++.h> using namespace std; int f[2][1024]; int main() { int n, i, j, x, k, ma = 0; cin >> n >> k >> x; for (i = 0; i < n; i++) { int a; cin >> a; f[0][a]++; f[1][a]++; ma = max(ma, a); ma = max(ma, a ^ x); } ma = min(ma * 2, 1023); for (i = 0; i < k; i++) { int...
3
#include <bits/stdc++.h> using namespace std; const int mx = 1e5 + 10; int lft[mx], rht[mx]; int d[mx]; int main() { int n; scanf("%d", &n); fill(d, d + mx, -2); for (int i = 1; i <= n; i++) scanf("%d", d + i); fill(lft, lft + mx, 0); fill(rht, rht + mx, 0); for (int i = 1; i <= n; i++) { lft[i] = 1; ...
1
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int parent[n + 1]; bool visited[n + 1]; fill(visited, visited + n + 1, false); int children[n + 1]; int c[n + 1]; int cost[n + 1]; fill(cost, cost + n + 1, 0); fill(children, children + n + 1, 0); int p, ci; for (int i =...
3
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; string s; if (k > n) return cout << "-1", 0; if (n == 1) { return cout << "a", 0; } if (n > 1 && k == 1) return cout << "-1", 0; for (int i = 0; i <= (n - k + 1); i++) { if (i & 1) s += 'b'; else ...
3
#include <bits/stdc++.h> using namespace std; int main() { char n[1000]; cin >> n; int count = 0; int notmagical = 0; if (n[0] != '1') { cout << "NO"; return 0; } for (int i = 0; i < strlen(n); i++) { if (n[i] == '1') { count = 0; } else if (n[i] == '4' && count < 2) { count++;...
1
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i=0;i<n;i++) int main() { int n,s=0,p=99; cin>>n; int a[n],b[n],c[n]; rep(i,n) cin>>a[i],a[i]--; rep(i,n) cin>>b[i]; rep(i,n-1) cin>>c[i]; for(int t:a){ s+=b[t]; if(p==t-1) s+=c[p]; p=t; } cout<<s; }
0
#include <bits/stdc++.h> using namespace std; const int N = 5e5 + 5; template <typename T> void read(T &x) { x = 0; int f = 1; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == '-') f = -1; for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + c - '0'; x *= f; } int n, Sigma; char s[...
6
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { long double a, b; cin >> a >> b; cout << (ll)(a * b) << endl; }
0
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int j = 1000000; for (int i = 0; i < n; i++) { cout << j << ' '; j++; } return 0; }
2
#include <bits/stdc++.h> using namespace std; vector<long long> prime(5000005, 1); void cal_primearray(long long n) { for (int p = 2; p * p <= n; p++) { if (prime[p] == 1) { for (int i = p * 2; i <= n; i += p) prime[i] = 0; } } } long long modexpo(long long a, long long b) { long long res = 1; whi...
3
#include <bits/stdc++.h> #define MOD 1000000007LL using namespace std; typedef long long ll; typedef pair<int,int> P; string s; ll dp[100005][13]; int main(void){ cin >> s; dp[0][0]=1; int n=s.size(); for(int i=0;i<n;i++){ for(int j=0;j<13;j++){ if(s[i]=='?'){ for(int v=0;v<=9;v++){ dp[i+1][(j*10+v)...
0
#include<iostream> #include<string> #include<sstream> #include<vector> #include<queue> #include<stack> #include<map> #include<set> #include<algorithm> #include<functional> #include<cstdio> #include<cstdlib> #include<cmath> using namespace std; #define mind(a,b) (a>b?b:a) #define maxd(a,b) (a>b?a:b) #define absd(x) (x<...
0
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:102400000,102400000") using namespace std; template <class T, class U> inline void Max(T &a, U b) { if (a < b) a = b; } template <class T, class U> inline void Min(T &a, U b) { if (a > b) a = b; } inline void add(int &a, int b) { a += b; while (a >= 10000...
4
#include <bits/stdc++.h> using namespace std; long long power(long long x, long long y) { long long res = 1LL; x = x % 1000000007; while (y > 0) { if (y & 1) res = (res * x) % 1000000007; y = y >> 1; x = (x * x) % 1000000007; } return res % 1000000007; } long long inv(long long n) { return power(n...
2
#include <iostream> #include <cstdlib> #include <algorithm> #include <string> #define N 8 using namespace std; int main(void){ int n; cin >> n; string input; while(n --){ cin >> input; sort(input.begin(), input.end()); int min = atoi(input.c_str()); reverse(input.begin(), input.end()); cout << atoi(inp...
0
#include <bits/stdc++.h> using namespace std; map<int, int> mp; map<int, int>::iterator it; long long int n, i, x, y, z, j, len, cnt = 0, sum = 0, a, b, c, temp, d, res = 0, k, tc, mod = 1000003, t, r, pos, ans = 0, m, q, mx; int arr[2 * 100005],...
2
#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 main() { ios_base::sync_with_stdio(false); cin.tie(0); string s; cin >> s; stack<char> st; for (int i = 0; i < s.length(); i++) { if (!st.empty() && st.top() == s[i]) st.pop(); else st.push(s[i]); } cout << (st.empty() ? "Yes" : "No")...
2
#include<iostream> using namespace std; #define MAX 1000000 int main() { int a,d,n,cnt; int b[MAX+1]={0},i,j; b[0]=b[1]=1; for(i=4;i<=MAX;i+=2)b[i]=1; for(i=3;i*i<=MAX;i+=2) if(!b[i])for(j=i+i;j<=MAX;j+=i)b[j]=1; while(cin>>a>>d>>n,a|d|n){ for(cnt=0;a<MAX;a+=d){ if(!b[a])cnt++; if(c...
0
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const long long int LINF = 0x3f3f3f3f3f3f3f3fll; const int MAX = (int)1e5 + 10; long long int n; string second; long long int x2, y2, x3, y3; pair<long long int, long long int> pre[MAX]; pair<long long int, long long int> volta; long long int bb(...
3
#include <bits/stdc++.h> using namespace std; int a[100005], b[100005], c, d, e, i, k, x = 1000000000, y, j, m, n; int main() { cin >> n; for (i = 1; i <= n; i++) { cin >> a[i] >> b[i]; if (a[i] < x) x = a[i]; if (b[i] > y) y = b[i]; } d = -1; for (i = 1; i <= n; i++) { if ((x == a[i]) && (y =...
2
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using P = pair<int, int>; constexpr ld EPS = 1e-12; constexpr int INF = numeric_limits<int>::max() / 2; constexpr int MOD = 1e9 + 7; template <typename T> void printv(const vector<T> &v) { int sz = v.size(); for (int i = 0; ...
3
#include <bits/stdc++.h> #pragma comment(linker, "/stack:200000000") #pragma GCC optimize("unroll-loops") using namespace std; template <class T> inline T bigmod(T p, T e, T M) { long long ret = 1; for (; e > 0; e >>= 1) { if (e & 1) ret = (ret * p) % M; p = (p * p) % M; } return (T)ret; } template <cla...
3
#include <bits/stdc++.h> using namespace std; long long t, n, m; int main() { cin >> t; while (t--) { cin >> n >> m; long long sum = (n + 1) * n / 2; n -= m; long long sum0 = n / (m + 1); long long mod = n % (m + 1); if (mod != 0) { sum = sum - (1 + sum0 + 1) * (sum0 + 1) / 2 * mod - ...
3
#include<iostream> using namespace std; int main(){ int A,B,a(0),b(0),x; cin >> A >> B >> x; if(x%500 != 0 ){ x = (x/500+1)*500; } if(A<B){ a = x/1000; if(x%1000 != 0){ a++; } }else if(A>2*B){ b = x/500; }else{ if((x/500)%2 != 0...
0
#include <bits/stdc++.h> using namespace std; long long a[333333]; long long gcd(long long a, long long b) { if (b == 0) return a; return gcd(b, a % b); } int main() { int n; scanf("%d", &n); long long sum = 0; for (int i = 1; i <= n; i++) cin >> a[i], sum += a[i]; sort(a + 1, a + n + 1); long long ans ...
1
#include<iostream> using namespace std; int main(){ char str[20001]; cin>>str; int top=0,cnt=0,data[20000],area[10000]={},num=0,len=0,sum=0; for(int i=0;str[i]!='\0';++i,++len){ if(str[i]=='\\') data[top++]=i; else if(str[i]=='/'&&top!=0){ int add=i-data[--top]; area[num]+=add; sum+=add;...
0
#include <bits/stdc++.h> using namespace std; int main() { string a, b, c, d; cin >> a >> b >> c >> d; string ans = ""; int A = a.length() - 2, C = c.length() - 2, B = b.length() - 2, D = d.length() - 2; if ((A <= (B / 2) && A <= (C / 2) && A <= (D / 2)) || ((A / 2) >= (B) && (A / 2) >= (C) && (A ...
1
#include <bits/stdc++.h> using namespace std; int main() { long int n, c = 0, i; cin >> n; string s; cin >> s; if (n < 26) { cout << "NO" << endl; } else { for (i = 0; i < s.size(); i++) { if (s[i] >= 'A' && s[i] <= 'Z') { s[i] = s[i] + 32; } } sort(s.begin(), s.end()); ...
1
#include <bits/stdc++.h> using namespace std; vector<vector<int> > adj(2001); int l, ans = INT_MIN; int visited[2001]; void dfs(int root) { if (visited[root] == 0) { l++; for (vector<int>::iterator it = (adj[root]).begin(); it != (adj[root]).end(); it++) { dfs(*it); } ans = max(ans, l);...
1
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { if (b == 0) return a; return gcd(b, a % b); } vector<pair<int, int> > v; int main() { int t; cin >> t; while (t--) { int yy; cin >> yy; string s; cin >> s; int x = 0, y = 0; int n = s.length(); ...
3
#include <bits/stdc++.h> using namespace std; const long double pi = acos(-1.0); const int rms = (1 << 20) - 1; const int hrms = rms / 2; struct mdf { long double x, y; long double ang; mdf(long double x_ = 0.0, long double y_ = 0.0, long double a_ = 0.0) : x(x_), y(y_), ang(a_) {} }; int n, m; int tp, x, y...
5
#include <bits/stdc++.h> using namespace std; int main(void) { int n; cin >> n; long long start = 10LL; int cnt = 1; int cur = 1; long long sum = 0LL; while (true) { if (n < start) { sum += (n - cur + 1LL) * cnt; break; } sum += (start - cur) * cnt; cur *= 10; start *= 10LL...
2
#include <bits/stdc++.h> using namespace std; int main() { int N,M; cin>>N>>M; vector<int> road(N,0); for(int i=0;i<M*2;i++){ int j; cin>>j; road.at(j-1)+=1; } for(int i=0;i<N;i++){ cout<<road.at(i)<<endl; } }
0
#include <bits/stdc++.h> using namespace std; struct Node { int pos, dir, num; Node() {} Node(int pos, int dir, int num) : pos(pos), dir(dir), num(num) {} bool operator<(const Node &nd) const { if (pos != nd.pos) return pos < nd.pos; if (dir != nd.dir) return dir < nd.dir; return num < nd.num; } }...
3
#include <bits/stdc++.h> using namespace std; const int N = 1e3 + 5; vector<long long> v; map<long long, int> id; pair<long long, long long> f[N][8000]; long long n, k, m; void init() { v.clear(); for (long long i = 1; i * i <= k; i++) { if (k % i == 0) { v.push_back(i); if (i * i != k) v.push_back(...
5
#include <bits/stdc++.h> using namespace std; const int N = 2010; struct Pos { long long x, y; Pos operator-(const Pos& rh) const { return Pos{x - rh.x, y - rh.y}; } } pos[N], rel[N * 2]; long long cross(Pos& a, Pos& b) { return a.x * b.y - a.y * b.x; } bool cmp(Pos& a, Pos& b) { if (a.y * b.y > 0) { return c...
6
#include <bits/stdc++.h> using namespace std; int main() { char A[3][3][3][3]; for (int i = 0; i < 3; i++) { for (int k = 0; k < 3; k++) { for (int j = 0; j < 9; j++) { cin >> A[i][j / 3][k][j % 3]; } } } int n, m; cin >> n >> m; n--; int n1 = n % 3; m--; int m1 = m % 3; ...
2
#include <bits/stdc++.h> using namespace std; long long n, x, dp[100005], a[100005], ans; int main() { cin >> n; for (int i = 1; i <= n; i++) { scanf("%lld", &x); a[x]++; } for (int i = 1; i <= 100000; i++) a[i] = a[i] * i; dp[1] = a[1]; dp[2] = max(a[1], a[2]); for (int i = 3; i <= 100000; i++) {...
3
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 5; const int logn = 20; int n, m; int in[maxn], out[maxn]; int dep[maxn], par[maxn][logn]; long long ans = 0; vector<int> g[maxn]; inline int lca(int u, int v) { if (dep[v] > dep[u]) swap(u, v); for (int i = logn - 1; i >= 0; --i) if (dep[u] -...
6
#include <bits/stdc++.h> using namespace std; int main() { double l, v1, v2; int k, n, m; scanf("%d%lf%lf%lf%d", &n, &l, &v1, &v2, &k); m = (n + k - 1) / k; double a = 2 * v1 * (m - 1) / (v1 + v2); double x = l / (1 + a); double t = x / v2 + (l - x) / v1; printf("%.10f\n", t); return 0; }
4
#include <iostream> #include <cmath> using namespace std; #define N 100 #define rep(i, n) for(int i=0; i<n; i++) #define pow2(x) ((x)*(x)) #define S "Safe\n" #define D "Danger\n" int dist(int x1,int y1,int x2,int y2){ return pow2(x1-x2)+pow2(y1-y2); } int main(){ int n,m; int wx[N],wy[N],r[N]; bool safe; int tx...
0
#include <bits/stdc++.h> using namespace std; int cnt[3], curr[2]; int main() { int n; cin >> n; string s; cin >> s; for (int i = 0; i < n; i++) { cnt[s[i] - '0']++; } int need = n / 3; for (int i = 0; i < n; i++) { if (cnt[s[i] - '0'] > need && cnt[0] < need) { ++cnt[0]; --cnt[s[i] ...
4
#include <bits/stdc++.h> using namespace std; #pragma warning(disable : 4996) #pragma comment(linker, "/STACK:256000000") FILE *stream; const int INF = 1e9 + 7; const long long INFL = (long long)1e18 + 1; const int SIZE = 2e5 + 10; const int TSIZE = 1e3 + 10; const long double eps = 0.000001; const long long MOD = 1e9 ...
2
#include <bits/stdc++.h> using namespace std; string s, t; long n, i, a[100000], col = 0, j; int main() { cin >> s >> t; n = s.size(); for (i = 0; i < n; ++i) if (s[i] != t[i]) a[col++] = i; if (col % 2 == 1) cout << "impossible"; else { col = col / 2; i = 0; j = 0; while (i < n && j <...
2
//Link : https://codeforces.com/contest/1284/problem/D #include <bits/stdc++.h> using namespace std; #define ll long long #define N 1000005 #define mod 1000000007 int add(int x,int y) { return ((x+y)%mod + mod)%mod; } int mul(int x,int y) { return (ll)x*y%mod; } int dp[N]; void solve() { int n,h,d;scanf("%d %d %...
0
#include <bits/stdc++.h> using namespace std; int32_t main() { long long i, t, a, b, c; cin >> t; while (t--) { cin >> a >> b >> c; if (a > c) { cout << c << endl; } else if (c > b) { cout << c << endl; } else { long long p = (b / c); long long ff = ((b / c) + 1) * c; ...
1
#include <bits/stdc++.h> int ia, in, ip, ih; void init() { scanf("%d%d%d%d", &ia, &in, &ip, &ih); } int f(int a, int n, int p) { if ((long long)a * (n - 1) < p) return std::max(a, p - a * (n - 1)); int k = (long long)a * n % p; int num = (long long)a * n / p + (k >= p / a * a); return f((a - p % a) % a, num, a)...
5
#include <bits/stdc++.h> using namespace std; int const maxn = 1000100, maxk = 30; int m, dp[maxk][maxn], prof[maxn]; vector<int> adj[maxn]; void dfs(int v) { for (auto i : adj[v]) if (i != dp[0][v]) prof[i] = prof[v] + 1, dp[0][i] = v, dfs(i); } int lca(int x, int y) { if (prof[y] < prof[x]) swap(x, y); int ...
6
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; using ll = long long; using P = pair<int, int>; struct Edge { ll from; ll to; ll cost; Edge(ll from, ll to, ll cost) : from(from), to(to), cost(cost) {} }; using Edges = vector<Edge>; const ll INF = 1LL << 60; bool ...
0
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1.0); int n; bool have[1000001]; int main() { scanf("%i", &n); memset(have, false, sizeof(have)); for (int i = 0; i < (int)n; i++) { int x; scanf("%i", &x); have[x] = true; } const int s = 1000000; int cnt = 0; for (int i = ...
2
#include <bits/stdc++.h> int main() { long long a, b; scanf("%lld %lld", &a, &b); while (a != 0 && b != 0) { if (a >= 2 * b) { a %= 2 * b; } if (a == 0 || b == 0) break; if (b >= 2 * a) { b %= 2 * a; } if (b < 2 * a && a < 2 * b) break; } printf("%lld %lld", a, b); return...
2
#include <bits/stdc++.h> using namespace std; void dfs(long long int a, long long int b) { long long int x; x = a * b; x = a - b; x *= b; } void df(long long int a, long long int b) { long long int x; x = a ^ b; x = a || b; x &= b; } void d(long long int a, long long int b) { long long int x; x = a ...
3
#include<bits/stdc++.h> using namespace std; const int N = 2000 + 10; int n; bool flag[N]; bool Query(int l1, int r1, int l2, int r2) { printf("? %d %d\n", r1 - l1 + 1, r2 - l2 + 1); for (int i = l1; i <= r1; i++) printf("%d%c", i, " \n"[i == r1]); for (int i = l2; i <= r2; i++) printf("%d%c", i, " \n"[i == r2])...
6
#include <bits/stdc++.h> using namespace std; template <class T> T abs(T x) { return x > 0 ? x : -x; } int n; int m, k; int d[100], x[100]; vector<int> res; int main() { scanf("%d%d%d", &n, &m, &k); for (int i = 0; i < m; i++) scanf("%d", &d[i]); for (int i = 0; i < k; i++) scanf("%d", &x[i]); int ans = k + 1...
6
#include <bits/stdc++.h> using namespace std; class linearSieve { public: vector<int> primes; vector<int> lp; void put(int Limit) { primes.clear(); lp.clear(); lp.resize(Limit + 1, 0); for (int i = 2; i <= Limit; i++) { if (!lp[i]) { lp[i] = i; primes.push_back(i); } ...
5
#include <bits/stdc++.h> using namespace std; int n, m = 1, k, color[1005][1005]; bool check(int x) { int tmp = 1; for (int i = 1; i <= x; i++) { tmp = tmp * k; if (tmp >= n) return true; } return false; } void Work(int col, int lim, int L, int R) { if (L == R) return; int Blen = (R - L + 1) / lim, ...
6
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; map<long long, long long> m; long long shelf[n]; long long bag[n]; for (int i = 0; i < n; i++) { cin >> shelf[i]; m[shelf[i]] = i; } long long max = -1; for (int i = 0; i < n; i++) cin >> bag[i]; for (int i = 0...
2
#include <bits/stdc++.h> using namespace std; const int N = 100005; int n, m, i, j, k, q, s, v, w, ans; int main() { int n, a; cin >> n >> a; if (a % 2 == 0) cout << (n - a) / 2 + 1 << endl; else cout << (a + 1) / 2 << endl; return 0; }
1
#include <bits/stdc++.h> //#include "GC_template.h" using namespace std; namespace CG{ const double eps = 1e-8; int sgn(double x) { if (x < -eps) return -1; if (x > eps) return 1; return 0; } struct point { double x, y; point() = default; point(double x,...
0
#include <cstdio> #include <algorithm> #include <cstring> #include <cmath> #include <queue> #include <vector> #include <map> #include <set> #define MAXN 200005 #define INF 0x3f3f3f3f #define rint register int #define LL long long #define LD long double using namespace std; int n, d, a[MAXN], b[MAXN]; LL ans; int main...
0
#include <bits/stdc++.h> #include <map> #define chmin(a, b) ((a)=min((a), (b))) #define chmax(a, b) ((a)=max((a), (b))) #define fs first #define sc second #define eb emplace_back using namespace std; typedef long long ll; typedef pair<int, int> P; typedef tuple<int, int, int> T; const ll MOD=1e9+7; const ll INF=1e1...
0
#include <bits/stdc++.h> using namespace std; using lint = long long; template<class T = int> using V = vector<T>; template<class T = int> using VV = V< V<T> >; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int m; cin >> m; while (m--) { string s; cin >> s; int n = s.size(); set<string>...
0
#include <bits/stdc++.h> using namespace std; int n, x, a = 1, b = 2, c = 3; int main() { cin >> n; for (int i = 0; i < n; i++) { cin >> x; if (x == a) swap(b, c); else if (x == b) swap(a, c); else { cout << "NO"; return 0; } } cout << "YES"; return 0; }
1
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf("%d", &n); for (int i = 1; i <= 2 * n / 3; i++) printf("%d %d\n", i, 1); for (int i = 1; i <= n - 2 * n / 3; i++) printf("%d %d\n", i * 2, 4); return 0; }
3
#include <bits/stdc++.h> int main() { int i, j, n, s; scanf("%d", &n); j = n * n; for (i = 1; i <= j / 2; i++) { printf("%d %d\n", i, j - i + 1); } return 0; }
1
#include <bits/stdc++.h> #define rep(i, n) for(int i = 0; i < (n); ++i) using namespace std; void solve(int N, int M) { vector<int> H(1), W(1); rep(i, N) { int a; cin >> a; H.push_back(H.back() + a); } rep(i, M) { int a; cin >> a; W.push_back(W.back() + a); } map...
0
#include <bits/stdc++.h> using namespace std; int n, pos, l, r; int a[100001]; int main() { scanf("%d%d%d%d", &n, &pos, &l, &r); if (l == 1 && r == n) cout << 0 << endl; else if (l == 1) cout << abs(r - pos) + 1 << endl; else if (r == n) cout << abs(l - pos) + 1 << endl; else cout << min(abs(l...
2
#include <bits/stdc++.h> using namespace std; int32_t main() { int64_t x, y, n; cin >> x >> y >> n; double dis = 1e10; int64_t a = 0, b = 0; for (int64_t i = 1; i <= n; i++) { int64_t num = (double)i * x / y; double tmp; tmp = abs(x * 1.0 / y * 1.0 - num * 1.0 / i * 1.0); if (tmp < dis) { ...
2
#include <bits/stdc++.h> using namespace std; long long sl, f, b, MOD = 998244353; char s[5000005]; long long base = 1; int dp[5000005], ans; inline void get_hash(int x) { f = (f * 32767ll + (long long)s[x] + MOD) % MOD; b = (b + (long long)(s[x]) * base + MOD) % MOD; base = base * 32767ll % MOD; } int main() { ...
4
#include <iostream> #include <algorithm> using namespace std; typedef long long ll; const int maxn = 1e4+10; ll arr[maxn]; int K,Q,n,x,m; ll sum[maxn],zero[maxn]; ll fun(){ x%=m; ll cnt = n-1; for(int i = 1;i<=K;i++){ sum[i] = sum[i-1] + arr[i]%m; zero[i] = zero[i-1] + (arr[i]%m == 0); ...
0