solution
stringlengths
52
181k
difficulty
int64
0
6
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:20000000") using namespace std; int ri() { int x; scanf("%d", &x); return x; } long long rll() { long long x; scanf("%lld", &x); return x; } int n, u, r; int best_res[35]; long long ans; int a[35]; int b[35]; int p[35]; int k[35]; void go(int pos, boo...
2
#include<bits/stdc++.h> using namespace std; using Int = long long; #define EPS (1e-10) #define equals(a,b) (fabs((a)-(b)) < EPS) #define PI 3.141592653589793238 // COUNTER CLOCKWISE static const int CCW_COUNTER_CLOCKWISE = 1; static const int CCW_CLOCKWISE = -1; static const int CCW_ONLINE_BACK = 2; static const i...
0
#include <bits/stdc++.h> using namespace std; int n, q; int val[2 * 100100]; vector<int> adj[2 * 100100]; bool lev[2 * 100100]; int par[2 * 100100]; int st[2 * 100100], en[2 * 100100]; int fen[2 * 100100]; int num; void dfs(int u, int pa, bool l) { lev[u] = l; par[u] = pa; st[u] = ++num; for (int i = 0; i < adj...
3
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; int main() { int n; cin >> n; long long dp[n + 1][n + 1]; dp[0][0] = 1; for (int i = 1; i <= n; i++) { dp[i][0] = dp[i - 1][i - 1]; for (int j = 1; j <= i; j++) { dp[i][j] = (dp[i][j - 1] + dp[i - 1][j - 1]) % mod; ...
2
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 50; int n; double ABS(double x) { return x < 0 ? -x : x; } double a[maxn]; int A[maxn]; int main() { cin >> n; int sum = 0; for (int i = 1; i <= n; i++) { cin >> a[i]; A[i] = int(a[i]); sum += A[i]; } if (sum > 0) { for (int ...
4
#include <bits/stdc++.h> using namespace std; long double o = 1.0; pair<long long, long long> arr[100001]; long double pr[100001]; int main() { ios_base::sync_with_stdio(0); cin.tie(); long long n, p; cin >> n >> p; for (int i = 0; i < n; i++) cin >> arr[i].first >> arr[i].second; for (int i = 0; i < n; i++...
3
#include <bits/stdc++.h> using namespace std; bool mark; long long n, a[2000000], p, s, q, i, j, sum2, sum, pop; string t; int main() { cin >> n; for (i = 0; i < n; i++) { cin >> a[i]; sum2 += a[i]; } cin >> t; for (i = 0; i < t.length(); i++) { if (t[i] == '1') { j = i; pop++; s...
3
#include <iostream> #include <string> #include <sstream> #include <map> #include <set> using namespace std; int main() { map<int, int> m; int n, cnt; char comma; while(true) { string str; getline(cin, str); if(str == "") break; istringstream is(str); is >> n >...
0
#include<bits/stdc++.h> using namespace std; int n, m, sum, p, x, a[123]; int main() { cin >> n; for (int i = 1; i <= n; i++) { scanf("%d", a + i); sum += a[i]; } cin >> m; while(m--) { scanf("%d%d", &p, &x); printf("%d\n", sum - a[p] + x); } return 0; }
0
#include <bits/stdc++.h> using namespace std; const int n_max = 400005; int n, i, j, x, y, a[n_max], timer, Q; vector<int> g[n_max]; int l[n_max], r[n_max], f[n_max]; int h[n_max], k; void add(int x, int k) { for (int i = x; i < n_max; i = 2 * i - (i & (i - 1))) f[i] += k; } int sum(int x) { int s = 0; while (x) ...
3
#include <bits/stdc++.h> using namespace std; #define int long long const int MAX = 510000; const int MOD = 998244353; const int Inv2 = (MOD+1)/2; signed main(){ int n,k,c; cin>>n>>k>>c; string s; cin>>s; int t=0; int a[n],b[n];a[0]=0;b[n-1]=0; for(int i=0;i<n-1;i++){ if(t>0||s[i]=...
0
///********************** Bismillahir Rahmanir Rahim *****************/// #include<bits/stdc++.h> using namespace std; ///*********************** Template Start Here ***********************/// ///************************ C o n t a i n e r ************************/// typedef long long ll; typedef unsigned long long ull...
6
//17 #include<iostream> #include<algorithm> #include<map> #include<string> #include<queue> #include<vector> #include<set> using namespace std; struct E{ string t; int d; }; struct S{ string v; int r,d; bool operator<(S a)const{ return d>a.d; } }; int main(){ for(int n,mm,cap;cin>>n>>mm>>cap,n|mm|c...
0
#include <bits/stdc++.h> using namespace std; const long long maxn = 1e5 + 100; long long n; vector<long long> pos; long long cou(long long k) { long long ans = 0; for (long long i = 1; i <= n; i += k) { long long mid = (i + i + k - 1) / 2; for (long long j = i; j <= i + k - 1; j++) { ans += abs(pos[m...
5
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; const double PI = 3.14159265359; int main() { ios_base::sync_with_stdio(0); cin.tie(0); string s; cin >> s; int n = s.size(); set<int> zr, zl; vector<int> ones, zeros; for (int i = 0; i < n; i++) { if (s[i] == '0') { zl.ins...
3
#include<bits/stdc++.h> using namespace std; int main(void) { int i,j,k,name[1000],b[1000],c[1000],d[1000],e,f,g,h,kl[1000],n,ff; while(cin>>n&&n) { for(i=0;i<n;i++) { cin>>name[i]>>b[i]>>c[i]>>d[i]; kl[i]=b[i]*4+c[i]*9+d[i]*4; } cin>>e>>f>>g>>h; ff=0; for(i=0;i<n;i++) { if(b[i]<=e&&c[i]<=f&&d[i]<=...
0
#include <iostream> int main(){ char c,d; std::cin >> c >> d; std::cout << (c == d ? 'H' : 'D') << std::endl; }
0
#include <bits/stdc++.h> using namespace std; int main() { int n, m; string s; cin >> n >> s; int t = 0; for (int i = 0; i < n; i++) if (s[i] == 'X') t++; int k = 0; if (t < n / 2) { for (int i = 0; i < n; i++) if (s[i] == 'x') { t++; k++; s[i] = 'X'; if (t ==...
1
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:64000000") using namespace std; void __never(int a) { printf("\nOPS %d", a); } int n, m; map<string, int> Map; vector<string> vec; vector<int> res; void sol() { m = (int)((Map).size()); for (map<string, int>::iterator it = Map.begin(); it != Map.end(); it++) ...
2
#include<bits/stdc++.h> using namespace std; int main(){ int a,b,c,d; cin>>a>>b>>c>>d; cout<<min(min(a+c,a+d),min(b+c,b+d))<<endl; }
0
#include <bits/stdc++.h> using namespace std; long long n, k; long long a[200005]; bool check(long long x, long long y) { long long ans = 0; for (int i = 0; i < n; i++) { if (!y) { ans++; y = y ^ 1; } else { if (a[i] <= x) { ans++; y = y ^ 1; } } } if (ans >= ...
4
#include <bits/stdc++.h> using namespace std; int n, k, res = 0, a[100005], t[100005], sum[100005]; int main() { cin >> n >> k; for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 1; i <= n; i++) cin >> t[i]; for (int i = 1; i <= n; i++) { sum[i] = sum[i - 1]; if (t[i] == 1) res += a[i]; el...
2
#include <bits/stdc++.h> using namespace std; int main() { int test = 1; while (test--) { int n, m; cin >> n; int a[n]; long long int sum = 0; for (int i = 0; i < n; i++) { cin >> a[i]; sum += a[i]; } sort(a, a + n, greater<int>()); cin >> m; int q[m]; for (int i ...
2
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; const int INF = 1e9; const int base = 1e9; const int MAX = 2e5; const long double EPS = 1e-10; const long double PI = acos(-1.); int n, k, p, second; int main() { ios_base::sync_with_stdio(0); cin >> k >> n >> second >> p; n = (n + second - 1)...
1
#include <bits/stdc++.h> using namespace std; int le[4 * 200010], me[4 * 200010], re[4 * 200010]; void init(int id, int l, int r) { le[id] = me[id] = re[id] = r - l + 1; if (l == r) return; int m = (l + r) / 2; init(id * 2, l, m); init(id * 2 + 1, m + 1, r); } void add(int id, int l, int r, int p, int v) { ...
5
#include <bits/stdc++.h> using namespace std; struct node { int a, b, c; } d[200005]; bool cmp(const node& p, const node& q) { return p.c > q.c; } int main() { int n, k, i, ans; scanf("%d%d", &n, &k); for (i = 1; i <= n; i++) scanf("%d", &d[i].a); for (i = 1; i <= n; i++) scanf("%d", &d[i].b), d[i].c = d[i].b...
3
#include <bits/stdc++.h> using namespace std; template <typename T> void pr(vector<T> &v) { for (int i = 0; i < (int)(v).size(); i++) cout << v[i] << " "; cout << '\n'; ; } template <typename T> void pr(vector<vector<T>> &v) { for (int i = 0; i < (int)(v).size(); i++) { pr(v[i]); } } template <typename T>...
4
#include <bits/stdc++.h> using namespace std; const int maxn = 213245; int a[maxn], w[maxn][2]; int dp[maxn], sum[maxn]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, m, k; cin >> n >> m >> k; for (int i = 1; i <= n; ++i) { cin >> a[i]; } sort(a + 1, a + n + 1); memset(sum, 0, sizeof...
6
#include <bits/stdc++.h> const int MAXN = 4e5 + 5; int a[MAXN], n; std::vector<int> S; inline int calc(int k) { S.clear(); for (int i = 1; i <= n; ++i) S.push_back(a[i] & ((1 << (k + 1)) - 1)); std::sort(S.begin(), S.end()); long long res = 0; for (int i = 0; i <= n - 1; ++i) { int l = 0, r = 0; if ((...
2
#include <bits/stdc++.h> using namespace std; int main() { int n, sum1 = 0, sum2 = 0; cin >> n; int *a = new int[n]; for (int i = 0; i < n; i++) cin >> a[i]; int x, y; cin >> x >> y; if (x > y) { x = x + y; y = x - y; x = x - y; } for (int i = x - 1; i < y - 1; i++) sum1 += a[i]; for (in...
1
#include <bits/stdc++.h> using namespace std; int main() { string a, b; cin >> a >> b; vector<pair<char, char>> res; map<char, int> chk; for (int i = 0; i < a.size(); i++) { if (a[i] != b[i]) { res.push_back(make_pair(a[i], b[i])); char c = b[i]; if (chk[c] || chk[a[i]]) { cout <...
2
#include <bits/stdc++.h> const int maxi = 2000000000; const int maxq = 1000000000; const double eps = 1e-10; const double pi = 3.1415926535897932; const double inf = 1e+18; const int mo = 1000000007; using namespace std; int t, kolr, n, m, k, a, b, tin[333333], fup[333333], nom[111111], y[333333], p[333333], pred[3...
2
#include <bits/stdc++.h> using namespace std; const long long MOD = (int)1e9 + 7; struct vct { long long v[2010]; } b, a; int c[2010]; int n, k; vct mul(vct x, vct y) { vct res; memset(res.v, 0LL, sizeof(res.v)); for (int i = 1; i <= n; i++) { for (int j = 1; j <= i; j++) { res.v[i] = (res.v[i] + x.v[...
3
#include <bits/stdc++.h> using namespace std; int n, m; int a[5001]; int dp[5001][5001]; int sol(int i, int cur) { if (i == n) return 0; int &ret = dp[i][cur]; if (ret != -1) return ret; int take = 1 + sol(i + 1, a[i]); int dont = sol(i + 1, cur); if (a[i] < cur) return ret = dont; return ret = max(dont, ...
4
#include <bits/stdc++.h> #define rep(i,n) for (int i=0; i<(n); ++i) using namespace std; typedef long long ll; typedef pair<int,int> P; int main(){ string s; cin>>s; string t=s; reverse(t.begin(),t.end()); rep(i,t.size()){ if(s[i]=='b')s[i]='d'; else if(s[i]=='d')s[i]='b'; else if(s[i]=='p')s[i]=...
0
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int t; long long x, y, a, b; cin >> t; for (int j = 0; j < t; ++j) { cin >> x >> y >> a >> b; cout << (max(x, y) - min(x, y)) * a + min(x, y) * min(b, 2 * a) << '\n'; } return 0; }
1
#include <bits/stdc++.h> using namespace std; using ll = long long; ll mod = (ll)1e9 + 7; ll MOD = mod; int64_t POW(int64_t a, int64_t b) { int64_t res = 1; while (b > 0) { if (b % 2 == 1) res = (res * a); a = (a * a); b /= 2; } return res; } ll sum_range2d(ll i, ll j, ll k, ll l, vector<vector<ll>>...
2
#include <bits/stdc++.h> using namespace std; string name; int n, fi; int f[155][155]; int from[155][155]; int lo[155][255]; char mask[155], mask2[155]; ; char ans[155]; bool gen() { memset(ans, 0, sizeof(ans)); memset(mask2, 0, sizeof(mask2)); for (int i = 0; i < name.size(); ++i) if (name[i] >= 'a' + fi) re...
4
#include <bits/stdc++.h> using namespace std; int main() { long long int b, sum = 0; scanf("%lld", &b); long long int i, j; long long int c = sqrt(b); for (i = 1; i <= c; i++) { if (b % i == 0) { j = b / i; if (j == i) sum++; else sum += 2; } } printf("%lld\n", su...
2
#include<bits/stdc++.h> using namespace std; int check(int x){ int y=0; while(y*(y+1)/2 < x){ y++; } return y; } int main(){ int n; cin >> n; int i=check(n); if(n-i*(i+1)/2){ cout << "No" << endl; return 0; }else{ cout << "Yes" << endl; } vector<vector<int>> a(i+1); for(int...
0
#include <bits/stdc++.h> using namespace std; int x[202333]; int p[202333]; pair<int, int> P[202333]; int main() { int n, m; scanf("%d%d", &n, &m); for (int i = 1; i <= n; ++i) scanf("%d", x + i), P[i].first = x[i], P[i].second = i; sort(P + 1, P + n + 1); for (int i = 1; i <= n; ++i) p[P[i].second] = i; ...
4
#include<bits/stdc++.h> using namespace std; long long n; long long cnt[100]; long long ans; int main(){ cin>>n; for(long long i=1;i<=n;i++){ long long x; cin>>x; for(long long j=0;j<61;j++){ cnt[j]+=x&1; x>>=1; } } long long t=1; for(long long i=0;i<61;i++){ ans+=((cnt[i]*(n-cnt[i])%1000000007)*t)...
0
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n; cin >> n; int ans = 0; for (int i = 0; i < n; i++) { int a, b; cin >> a >> b; if (a + b > ans) ans = a + b; } cout << ans; }
2
#include <iostream> #include <vector> #include <cmath> #include <algorithm> using namespace std; int main(){ int n,k; cin >> n >> k; vector<int> a(n); for(int i=0;i<n;i++){ cin >> a[i]; } for(int i=0;i<k;i++){ vector<int> nxt(n,0); for(int j=0;j<n;j++){ int l = max(0,j-a[j]); in...
0
#include<iostream> using namespace std; int n,a; int main() { cin>>n>>a; if(n%500<=a) cout<<"Yes"; else cout<<"No"; return 0; }
0
#include <bits/stdc++.h> using namespace std; struct node { int x; int norm; node *next; } * h[300001]; struct poz { int left, right; } p[300001]; int t[300001], i, current, n, fi[300001]; long long f[300001], b[300001], total, s; int hash_search(unsigned int x) { int j = x % 300001; for (node *d = h[j]; d ...
1
#include <iostream> #include <queue> #include <functional> #include <cstring> #include <utility> #include <cstdio> using namespace std; #define REP(i,b,n) for(int i=b;i<n;i++) #define rep(i,n) REP(i,0,n) struct edge { double dist; int limit; }; struct state { double cost; int pre, cur, v; state(double d, i...
0
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; long long n; void pow(long long a[2][2], long long n) { if (n == 1) return; long long t[2][2]; memset(t, 0, sizeof(t)); for (int i = 0; i < 2; i++) for (int j = 0; j < 2; j++) for (int k = 0; k < 2; k++) t[i][j] += (a[i][k] *...
1
#include <bits/stdc++.h> using namespace std; const int MAXN = 1000010; const int offset = (1 << 20); struct tournament { int p[offset * 2]; tournament() { memset(p, 0, sizeof p); } void update(int cvor, int l, int r, int a, int b, int x) { if (b < a) return; if (l > b || r < a) return; if (l >= a && ...
4
#include <bits/stdc++.h> template <typename T> struct ScanfSpecifier {}; template <> struct ScanfSpecifier<char*> { static constexpr const char* value = "%s"; }; template <> struct ScanfSpecifier<int> { static constexpr const char* value = "%d"; }; template <> struct ScanfSpecifier<double> { static constexpr cons...
3
#include <bits/stdc++.h> using namespace std; using cat = long long; void add_to_interval(int l, int r, cat val, vector<cat>& A) { int N = A.size() - 1; if (l > r) return; int start = l; while (start < 0) start += N; while (start >= N) start -= N; A[start] += val; if (start + r - l < N) A[start + r - ...
6
#include <bits/stdc++.h> using namespace std; int a[1505], sum[1505]; int dp[1505][1505]; int nt[1505]; int main() { int n, s, m, k; scanf("%d%d%d%d", &n, &s, &m, &k); for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); nt[i] = -1; } for (int i = 1; i <= s; i++) { int l, r; scanf("%d%d", &l, &r...
5
// #pragma GCC target ("avx2") // #pragma GCC optimization ("O3") // #pragma GCC optimization ("unroll-loops") #pragma GCC optimize("Ofast") #pragma GCC target("avx,fma") #include <bits/stdc++.h> #include <iostream> using namespace std; #define fastio \ ios_base::sync_with_stdio(false); \ ...
3
#include <bits/stdc++.h> using namespace std; vector<long long> q; map<long long, pair<long long, long long> > mp; pair<long long, long long> solve(long long x) { if (x < 8) return pair<long long, long long>(x, x); for (int i = 0; i < 5; i++) { int tst = 0; tst++; tst--; tst++; tst--; } if (...
2
#include <bits/stdc++.h> using namespace std; int n; int a[10][100]; int b[100]; int ans; int d[10][100]; int main(int argc, const char* argv[]) { cin >> n; for (int i = 0; i < 2; i++) { for (int j = 0; j < n - 1; j++) { cin >> a[i][j]; } } for (int i = 0; i < n; i++) cin >> b[i]; ans = (1 << 29...
2
#include <bits/stdc++.h> int st[5000005], top = 0, x, n, i, j; int main() { scanf("%d", &n); long long int sum = 0; for (i = 1; i <= n; i++) { scanf("%d", &x); while (top > 1 && st[top - 1] >= st[top] && x >= st[top]) { sum += std::min(x, st[top - 1]); top--; } st[++top] = x; } std...
3
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int i, e = 0, n, c = 0, d = 0, a, b; cin >> a >> b >> n; e = n % 3; if (e == 0) { cout << a << endl; } else if (e == 1) { cout << b << endl; } else { c = a ^ b; cout << c << en...
1
#include <bits/stdc++.h> using namespace std; string add(string s1) { string s; int c = 1, x; for (int j = s1.size() - 1; j >= 0; j--) { x = s1[j] - '0' + c; s += x % 10 + '0'; c = x / 10; } if (c) s += c + '0'; reverse(s.begin(), s.end()); return s; } int main() { ios_base::sync_with_stdio(...
3
#include<bits/stdc++.h> using namespace std; const int M=1e9+7,N=17; int n,m,i,fac[1<<N],inv[1<<N],f[1<<N],t,L,j,ans,a[N],k; void inc(int &x,int y){x+=y;if(x>=M)x-=M;if(x<0)x+=M;} int C(int n,int m){ if (n<m) return 0; return 1ll*fac[n]*inv[m]%M*inv[n-m]%M; } int main(){ scanf("%d%d",&n,&m),L=1<<n; fac[0]=fac[1]=in...
0
#include <bits/stdc++.h> using namespace std; bool PIIfs(const pair<int, int>& a, const pair<int, int>& b) { return a.first < b.first || (a.first == b.first && a.second < b.second); } bool PIIsf(const pair<int, int>& a, const pair<int, int>& b) { return a.second < b.second || (a.second == b.second && a.first < b.fi...
5
#include <bits/stdc++.h> using namespace std; vector<int> b; vector<int> good; bool vis[1024]; int find(int n) { int cnt = 0; int r = 0; while (n) { int a = n % 2; r += a * (int)pow(3, cnt); cnt++; n /= 2; } return r; } int bs(int v) { int i = 0, j = good.size(); while (i < j) { int m ...
3
#include <bits/stdc++.h> using namespace std; const int inf = 2000000000; const int N = 500005; int a[N]; char t[N]; int main() { cin.tie(0); ios_base::sync_with_stdio(0); int n; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; } long long s1 = 0, s2 = 0; for (int i = 0; i < n; i++) { cin >>...
2
#include <bits/stdc++.h> int f[2000]; int main() { int n, k; std::cin >> n >> k; for (int i = 0; i < n; ++i) { std::cin >> f[i]; } std::sort(f, f + n); int total = 0; for (int i = n - 1; i >= 0; i -= k) { total += 2 * (f[i] - 1); } std::cout << total << '\n'; return 0; }
2
#include <iostream> using namespace std; int main(void){ int n, i=1; while(cin>>n&&n!=0){ cout<<"Case "<<i<<": "<<n<<endl; i++; } }
0
#include <bits/stdc++.h> using namespace std; inline void wait(double seconds) { double endtime = clock() + (seconds * CLOCKS_PER_SEC); while (clock() < endtime) { ; } } template <class T> inline T fastIn() { register char c = 0; register T a = 0; bool neg = false; while (c < 33) c = getchar(); whil...
3
#include<bits/stdc++.h> using namespace std; int32_t main() { int a, b, n; cin>>n>>a>>b; cout<<min(a * n, b)<<endl; }
0
#include<cstdio> const int P=1000000007; int n,d[305],fac[305],inv[305],f[305][305][2],ans; int power(int a,int x){ int ans=1; for(;x;x>>=1,a=1ll*a*a%P)if(x&1)ans=1ll*ans*a%P; return ans; } void upd(int &x,int y){x=x+y>=P?x+y-P:x+y;} int main(){ scanf("%d",&n); bool cir=true; for(int i=1;i<=n;i++)scanf("%d",d+...
0
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); int n, m; cin >> n >> m; vector<int> f(n); vector<int> b(m); for (int i = 0; i < n; ++i) cin >> f[i]; for (int i = 0; i < m; ++i) cin >> b[i]; map<int, pair<int, int> > m1; for (int i = 0; i < n; ++i) { m1[f[i]].fi...
2
#include <iostream> using namespace std; int main(void){ int a,b,c,d; cin>>a>>b>>c>>d; cout<<min(a,b)+min(c,d)<<endl; }
0
#include <bits/stdc++.h> using namespace std; template <class c> struct rge { c b, e; }; template <class c> rge<c> range(c i, c j) { return rge<c>{i, j}; } template <class c> auto dud(c* x) -> decltype(cerr << *x, 0); template <class c> char dud(...); struct debug { template <class c> debug& operator<<(const c&...
4
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int num = 5; while (n > num) { n = n - num; num *= 2; } num = num / 5; if (n > 0 && n <= num) printf("Sheldon\n"); else if (n > num && n <= num * 2) printf("Leonard\n"); else if (n > num * 2 && n <= num * 3) ...
1
#include <bits/stdc++.h> using namespace std; #define LL long long const int mod=998244353,maxn=4e5+5; LL n,m,k; LL fact[maxn],inv[maxn]; LL qpow(LL base,int p) { LL res=1; while(p) { if(p&1) res=res*base%mod; base=base*base%mod; p>>=1; } return res; } LL C(LL a,LL b) { return (fact[a]*inv[b]%mod)*inv[a-b]%...
0
#include <bits/stdc++.h> using namespace std; int arr[200001], ans[200001]; int main() { int n; scanf("%d", &n); int sum = 0; for (int i = 1; i <= n; ++i) { scanf("%d", &arr[i]); sum += arr[i]; } int m = n - 1, p = 0; for (int i = 1; i <= n; ++i) if (sum - arr[i] == arr[i] * m) ans[++p] = i; ...
1
#include <bits/stdc++.h> char *fs, *ft, buf[1 << 20]; inline int read() { int x = 0, f = 1; char ch = (fs == ft && (ft = (fs = buf) + fread(buf, 1, 1 << 20, stdin), fs == ft)) ? 0 : *fs++; ; while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = (fs == ft && (ft =...
2
#include <bits/stdc++.h> using namespace std; int main() { int m, n; cin >> m >> n; if (n % 2 == 0) { cout << n / 2 * m; } else { cout << n / 2 * m + m / 2; } return 0; }
1
#include <bits/stdc++.h> using namespace std; int n, a, L, t[100010], l[100010], res; int main() { cin >> n >> L >> a; for (int i = 0; i < n; i++) { cin >> t[i] >> l[i]; } t[n] = L; for (int i = 0; i < n; i++) { res += (t[i] - (t[i - 1] + l[i - 1])) / a; } res += (t[n] - (t[n - 1] + l[n - 1])) / a...
1
#include <bits/stdc++.h> using namespace std; clock_t startTime; double getCurrentTime() { return (double)(clock() - startTime) / CLOCKS_PER_SEC; } template <typename T, typename U> inline ostream &operator<<(ostream &_out, const pair<T, U> &_p) { _out << _p.first << " " << _p.second; return _out; } template <typ...
4
#include <bits/stdc++.h> using namespace std; int main() { long long int n, a[100001], x, z, f = 0; cin >> n; for (int i = 0; i < n; ++i) { cin >> a[i]; } sort(a, a + n); for (int i = 1; i < n; ++i) { if (a[i] != a[i - 1]) { x = i; z = a[i] - a[i - 1]; f = 1; break; } }...
2
#include <bits/stdc++.h> using namespace std; void faster() { ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); if (0) { freopen( "input" ".in", "r", stdin); freopen( "input" ".out", "w", stdout); } } int main() { faster(); int t; long l...
2
#include <bits/stdc++.h> int f[100005], kind[100005]; int find(int x) { if (f[x] == x) return x; int nowfa = f[x]; f[x] = find(f[x]); kind[x] = (kind[x] + kind[nowfa] + 1) % 2; return f[x]; } void unions(int fa1, int fa2, int u, int v, int kinds) { f[fa1] = fa2; kind[fa1] = (kind[v] - kind[u] + 2 + kinds)...
5
// ?????¬???????????¬?????? #include <iostream> #include <iomanip> #include <cstdio> #include <string> #include <cstring> #include <deque> #include <list> #include <queue> #include <stack> #include <vector> #include <utility> #include <algorithm> #include <map> #include <set> #include <complex> #include <cmath> #inclu...
0
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using pr = pair<int, int>; using prll = pair<long, long>; using V = vector<int>; using Vll = vector<long long>; template <typename T, typename TT> pr operator+(pair<T, TT> a, pair<T, TT> b) { return {a.first + b.first, a.secon...
5
#include <bits/stdc++.h> #define fo(a,b,c) for (a=b; a<=c; a++) #define fd(a,b,c) for (a=b; a>=c; a--) #define abs(x) ((x)>0?(x):-(x)) #define min(a,b) (a<b?a:b) #define ll long long //#define file using namespace std; int d[250001][2],f[501][501],a[501][501],n,i,j,k,l,h,t,ans,x,y; const int fx[2][4]={{-1,0,1,0},{0,1,...
0
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const long long infLL = 0x3f3f3f3f3f3f3f3fLL; const int hash_mod = 1000037; const double pi = acos(-1); const double eps = 1e-10; const int maxn = 1000 + 5; int n, m; int a[maxn], b[maxn]; int c[4]; int calc(int a[], int n) { int res = 0; for...
2
#include <bits/stdc++.h> using namespace std; long long pw(long long b, long long p) { if (!p) return 1; long long sq = pw(b, p / 2); sq *= sq; if (p % 2) sq *= b; return sq; } long long gcd(long long a, long long b) { return (b == 0 ? a : gcd(b, a % b)); } long long sd(long long x) { return x < 10 ? x : x % ...
5
#include<bits/stdc++.h> typedef long long int ll; typedef unsigned long long int ull; #define BIG_NUM 2000000000 #define HUGE_NUM 99999999999999999 #define MOD 1000000007 #define EPS 0.000000001 using namespace std; int POW[3] = {1,2,4}; int table[8] = {0,1,2,3,3,2,1,0}; int func(char head,double degree,double LEN){...
0
#include<bits/stdc++.h> using namespace std; #define lint long long #define P pair<int, int> #define LLP pair<long long, long long> #define REP(i, x, n) for(int i = (x), i##_len = (int)(n) ; i < i##_len ; ++i) #define rep(i, n) for(int i = 0, i##_len = (int)(n) ; i < i##_len ; ++i) #define repr(i, n) for(int i = (int)...
0
#include <bits/stdc++.h> using namespace std; long long int sqrt(long long int p) { long long int low = 1, high = p, mid; while (low < high) { mid = (low + high + 1) / 2; if (mid * mid > p) { high = mid - 1; } else { low = mid; } } return low; } long long int power(long long int a, l...
6
#include <bits/stdc++.h> using namespace std; char s[1 << 20]; char t[1 << 20]; int n, m, q; int v[11], k[11]; int main() { scanf("%s%s", s, t); n = strlen(s); m = strlen(t); for (int i = 0; i < n; i++) v[s[i] - '0']++; int p = 0; for (int i = 1; i <= n; i++) { int x = i, j = 0; bool ok = 0; for...
6
#include <bits/stdc++.h> using namespace std; long long n, vol[100005], seg[500005], c; map<long long, long long> ha; void update(long long x, long long val, long long l = 0, long long r = c, long long p = 1) { if (x < l || x > r) return; if (l == r) { seg[p] = val; return; } long long mid =...
4
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); ; int t; cin >> t; while (t--) { int n; cin >> n; string a, b; cin >> a >> b; bool ok = true; for (int i = 0; i < n; i++) { if (a[i] > b[i]) ok = false; } ...
1
#include <bits/stdc++.h> using namespace std; double solve(int w, int b, double princess[1001], double dragon[1001], bool turn) { if (w <= 0) return 0.0; if (b <= 0 && turn == false) return 0.0; if (turn && !(abs(princess[b] + 1) < 1e-9)) return princess[b]; if (!turn && !(abs(dragon[b] + 1) < 1e-9...
4
#include <bits/stdc++.h> using namespace std; const int N = 150005, Sigma = 26; int n, q; char s[N]; int D = -1; int sum[N]; int cnt_bad; int f[N][26]; int g[N][26]; int L[N], R[N]; vector<int> G[N]; int fa[N], rfa[N]; int dep[N], bel[N]; int dfs(int p, int dp) { int d = G[p].size(); dep[p] = dp; if (!d) { re...
4
#include <bits/stdc++.h> using namespace std; template <typename T> void print_array(T arr[], int size_arr) { for (int i = (0); i < (size_arr); i++) { cout << arr[i]; if (i == size_arr - 1) cout << endl; else cout << " "; } } template <typename T> void print_vector(vector<T> v) { for (int ...
3
#include <bits/stdc++.h> using namespace std; int main(void) { int n; cin >> n; long long int marksA; long long int water[n]; water[0] = 1; cin >> marksA; long long int sum = marksA; for (int i = 1; i < n; i++) { cin >> marksA; sum += marksA; water[i] = max(water[i - 1], marksA + 1); } l...
3
#include <bits/stdc++.h> using namespace std; long long n, m; long long f[3][507][507], a[507][507], sum[507][507]; int main() { while (scanf("%I64d %I64d", &n, &m) != EOF) { memset(a, 0, sizeof(a)); memset(sum, 0, sizeof(sum)); memset(f, 0, sizeof(f)); long long i, j, k, r, w, h; for (i = 1; i <=...
3
#include<cstdio> #include<algorithm> using namespace std; const int N=305,mo=1e9+7; int n,m,i,j,k,mn[N][3],mx[N][3],f[N][N],ans; int read(){ char c=getchar();int k=0;for (;c<48||c>57;c=getchar()); for (;c>47&&c<58;c=getchar()) k=(k<<3)+(k<<1)+c-48;return k; } void add(int &x,int k){x=(x+k)%mo;} int main(){ for (n=re...
0
#include <bits/stdc++.h> using namespace std; const int N = 2005; char ma[N][N]; int main() { std::ios::sync_with_stdio(false); int n, m, k; cin >> n >> m >> k; for (int i = 0; i < n; ++i) { for (int j = 0; j < m; ++j) { cin >> ma[i][j]; } } for (int j = 0; j < m; ++j) { int res = 0; f...
2
#include <bits/stdc++.h> using namespace std; const int MOD = 1000000007, maxN = 110; long long f[11][maxN]; int n, a[10], C[maxN][maxN]; int main() { scanf("%d", &n); for (int i = 0; i <= 9; i++) scanf("%d", &a[i]); memset(f, 0, sizeof f); f[10][0] = 1; memset(C, 0, sizeof C); for (int i = 0; i <= n; i++) ...
4
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 5e3+20 , M = 230; int n,m,b[M][N],L[M][N],R[M][N],st[N],top; ll sum[N][N],a[N],ans; inline void input(void) { scanf("%d%d",&n,&m); for (int i=2;i<=n;i++) scanf("%lld",&a[i]) , a[i] += a[i-1]; for (int i=1;i<=n;i++) ...
0