solution
stringlengths
52
181k
difficulty
int64
0
6
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:66777216") using namespace std; struct zh { long long d, r; int m, p; }; zh mas[250001]; struct cmp { inline bool operator()(const int &a, const int &b) { return mas[a].d < mas[b].d; } }; struct cmp2 { inline bool operator()(const int &a, const int ...
5
#include <bits/stdc++.h> using namespace std; const int MX = 2005; int n, q; map<string, string> m; int ans = 0; void eval(string s) { while (s.length() > 1) { if (m.count(s.substr(0, 2)) > 0) { s = m[s.substr(0, 2)] + s.substr(2, s.length() - 2); } else break; } if (s == "a") ans++; } void ge...
2
#include <bits/stdc++.h> using namespace std; int n; int x[1005]; int y[1005]; bool v[1005]; int main() { cin >> n >> x[0] >> y[0]; for (__typeof(n + 1) i = (1) - ((1) > (n + 1)); i != (n + 1) - ((1) > (n + 1)); i += 1 - 2 * ((1) > (n + 1))) { cin >> x[i] >> y[i]; } int count = n; for (int i = 1; i...
2
#include <bits/stdc++.h> using namespace std; int main(){ int N; string S; cin >> N >> S; int w = 0, b = 0; for (int i = 0; i < N; i++) { if (S.at(i) == '#') { b++; } else { w++; } } int answer = min(N - b, N - w), B = b, W = w; for (int i = 0; i < N - 1; i++) { if (S.at...
0
#include <bits/stdc++.h> using namespace std; const int maxn = 5e5 + 10; int aa[10][2], num[10][2], tt[maxn]; char s[maxn][5]; int main() { int n; scanf("%d", &n); for (int j = 0; j < 10; j++) { aa[j][0] = 0; aa[j][1] = 1; } for (int i = 1; i <= n; i++) { scanf("%s%d", s[i], &tt[i]); for (int ...
1
#include<bits/stdc++.h> using namespace std; struct Dice { int x, y; int l, r, f, b, d, u; void RollF() { --y; int buff = d; d = f; f = u; u = b; b = buff; } void RollB() { ++y; int buff = d; d = b; b = u; u = f; f = buff; } void RollL() { --x...
0
#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--) { long long n, k; cin >> n >> k; if (n > k) { if ((n - k) & 1) cout << 1 << endl; else cout << 0 << endl; } else cou...
1
// 以下のライブラリを使ってみる. // beet氏. // http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=2117671#1 #include<bits/stdc++.h> using namespace std; #define MAX_V 200050 int V; vector<int> G[MAX_V], rG[MAX_V], vs; bool used[MAX_V]; int cmp[MAX_V]; void add_edge(int from, int to){ G[from].push_back(to); rG[to].push_back(...
0
#include <bits/stdc++.h> using namespace std; const int INF = 1000000000; #define REP(i,s,n) for(int i=(int)(s);i<(int)(n);++i) #define rep(i,n) REP(i, 0, n) typedef long long int i64; typedef pair<int, int> pint; bool check(int x) { for(int y = 2; y * y <= x; ++y) if(x % y == 0) { int sqy = sqrt((double)y)...
0
#include <iostream> #include <iomanip> using namespace std; double memo[100001]; double dfs(int i, int n, double p) { if(i==1 || n-50==i) return p; return p+(1-p)*memo[i-1]+p*dfs(i-1,n,p/2); } int main() { cout << setiosflags(ios::fixed) << setprecision(10); memo[1]=1.0; for(int i=1; i<=100000; i++) memo[i]=d...
0
#include <bits/stdc++.h> using namespace std; int main() { int n{0}; cin >> n; int i{1}; int p[n]; int v[n]; int t[n]; int z{0}; for (i; i <= n; i++) { cin >> p[i] >> v[i] >> t[i]; if ((p[i] + v[i] + t[i]) >= 2) z = z + 1; else continue; } cout << z; }
1
#include <bits/stdc++.h> using namespace std; long long fS(long long x) { long long lo = 1, hi = x - 1, cn = 0, ans = -1, out = 1; while (cn <= 80) { if (cn & 1) ans -= (lo + hi) / 2; else ans += (lo + hi) / 2; lo = (lo + hi) / 2 + 1; out = min(out, ans); cn++; } return out; } in...
1
#include <bits/stdc++.h> using namespace std; int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } int lcm(int a, int b) { return a * (b / gcd(a, b)); } bool palindrom(string s) { string ss = ""; for (int i = 0; i <= s.size() - 1; i++) ss = s[i] + ss; return ss == s; } int main() { ios_base::sync_with_stdio(...
4
#include<iostream> #include<algorithm> #include<cstdio> using namespace std; int main(){ int c,d,w,x; while(cin >>c>>d>>w>>x,c||d||w||x){ int be[15][30],su[15][30]; for(int i=0; i<c; i++) for(int j=0; j<d; j++) cin >>be[i][j]; for(int i=0; i<c; i++) for(int j=0; j<d; j++) cin >>su[i][j]; ...
0
#include <bits/stdc++.h> using namespace std; template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; } template <typename T, size_t size> ostream &operator<<(ostream &os, const array<T, size> &arr)...
3
#include <bits/stdc++.h> using namespace std; long long n, m, k, pos[105], ans, x; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> n >> m >> k; for (long long i = (long long)(1); i <= (long long)(k); i++) { cin >> x; pos[x] = i; } for (long long i = (long long)(1); i <= (long long)...
2
#include <bits/stdc++.h> using namespace std; clock_t timeStart, timeFinish; void timeBegin() { timeStart = clock(); } void timeEnd() { timeFinish = clock(); } void timeDuration() { double time_taken = double(timeFinish - timeStart) / double(CLOCKS_PER_SEC); cout << "Time taken by program is : " << fixed << time_ta...
3
#include <bits/stdc++.h> using namespace std; const double eps = 1e-6; int N; double P; bool check(int m) { double x = double(N * (N - 1) * (N - 2)) / 6.0; double y = double(m * (m - 1) * (m - 2) / 6) + double(m * (m - 1) * (N - m) / 2) + double(m * (N - m) * (N - m - 1) / 2) * 0.5; doub...
3
#include <bits/stdc++.h> using namespace std; int main() { long long int a, b, c; cin >> a >> b >> c; a += c; b += c; if (a != b) cout << 2 * min(a, b) + 1; else cout << 2 * a; return 0; }
1
#include <bits/stdc++.h> using namespace std; const int mod = 1000000007; int n, k; int a[100010], ind[100010], vis[100010]; vector<int> chain; vector<long long> f[100010], invf[100010]; long long fac[100010], inv[100010]; long long qp(long long a, long long p) { long long ans = 1; for (; p; p >>= 1, a = a * a % mo...
5
#include <bits/stdc++.h> using namespace std; const int _ = 1e6 + 7, N = 1e6, INF = 0x3f3f3f3f; int n, m, q, a[_], b[_], tong[_]; struct node { int l, r, mi, lazy; } t[_ << 2]; void pushup(int rt) { t[rt].mi = min(t[rt << 1].mi, t[rt << 1 | 1].mi); } void pushdown(int rt) { if (t[rt].lazy) { t[rt << 1].lazy += ...
3
#include <bits/stdc++.h> using namespace std; const int N = (int)2e5 + 5; struct custom_hash { static uint64_t splitmix64(uint64_t x) { x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31); } size_t operator()(uint64_t x)...
3
#include <bits/stdc++.h> using namespace std; void dfs(vector<int> edges[], int visited[], int visitNum, int node) { visited[node] = visitNum; for (auto i : edges[node]) { if (!visited[i]) { dfs(edges, visited, visitNum, i); } } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); c...
3
#include <bits/stdc++.h> using namespace std; const int N = 5e3 + 3; int main() { int n, k; cin >> n >> k; long long ans = 0; int cnt = 2 * n - 3; for (int i = 0; i < min(k, n / 2); i++) { ans += cnt; cnt -= 4; } cout << ans; }
2
#include<bits/stdc++.h> using namespace std; int main(){ int N, A, B; cin >> N >> A >> B; int cnt = 0; for(int i=0; i<N; i++){ int x; cin >> x; if(x >= A && x < B){ continue; } else{ cnt++; } } cout << cnt << endl; }
0
#include <bits/stdc++.h> using namespace std; int main() { int n; cin>>n; int sum=0; vector<int> a; for(int i=0;i<n;i++) { int x; cin>>x; if(x%10) a.push_back(x); sum+=x; } if(sum%10) { cout<<sum; return 0; } if(a.size()==0) { cout<<0; return 0; } sort(a.begin(),a.end()); cout<<sum-a[0];...
0
#include <bits/stdc++.h> using namespace std; const int MAXN = 3000 + 10; queue<int> q; vector<int> G[MAXN]; int deg[MAXN], dis[MAXN]; int n, m; void findcycle() { while (!q.empty()) q.pop(); for (int i = 1; i <= n; i++) { dis[i] = 0; if (deg[i] == 1) q.push(i); } while (!q.empty()) { int v, u = q.f...
4
#include<bits/stdc++.h> using namespace std; int main(void){ int n,k; cin>>n>>k; vector<int> h(n); for(int i=0;i<n;i++){ cin>>h[i]; } sort(h.begin(),h.end()); int ans=1000000009; for(int i=0;i<n-k+1;i++){ ans=min(ans,h[i+k-1]-h[i]); } cout<<ans<<endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; int a[100005], b[100005], x[100005], y[100005]; int Min(int x, int y) { return x < y ? x : y; } int main() { int n, ans; scanf("%d", &n); for (int i = 0; i < n; ++i) scanf("%d", &a[i]); for (int i = 0; i < n; ++i) scanf("%d", &b[i]); for (int i = 0; i < n; ++i) { ...
3
#include <bits/stdc++.h> using namespace std; const int MAX = 2e5 + 5; const long long INF = 1e18; int n, a[MAX]; long long t[MAX], dp[MAX][2]; priority_queue<long long> q0, q1; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); t[i] = t[i - 1] + a[i]; } dp[n + 1][0] = dp[n...
5
#include<bits/stdc++.h> using namespace std; const int P=1e9+7; const int N=205; const int Gi=(P+1)/2; #define ll long long ll fsp(ll x,int y){ ll ans=1; while(y){ if(y&1) ans=ans*x%P; x=x*x%P,y>>=1; } return ans; } ll f[N][2]; vector<int>ch[N]; int n,top,a[N],st[N],len[N]; void dp(int x,int fl){ int si=ch[x]....
0
#include <bits/stdc++.h> using namespace std; int mark[2000]; int main() { int n, k, i, maxi, j, K, p, q; scanf("%d", &n); scanf("%d", &k); K = k; if (n & 1) maxi = ((n + 1) / 2) * ((n + 1) / 2) + (n / 2) * (n / 2); else maxi = (n / 2) * n; if (k > maxi) printf("NO\n"); else { printf("YE...
2
#include <bits/stdc++.h> using namespace std; const long long MOD = (long long)1e9 + 7; const long long N = 18, inf = 1e9 + 5000; long long add(long long x, long long y) { x += y; if (x >= MOD) return x - MOD; return x; } long long sub(long long x, long long y) { x -= y; if (x < 0) return x + MOD; return x;...
5
#include <bits/stdc++.h> using namespace std; const int inf = 1e9; const int maxN = 65; int a[maxN][maxN][maxN]; int f[maxN][maxN][maxN]; int n, m, r; void init() { for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) for (int k = 0; k < n; k++) f[i][j][k] = inf; } void printing(int i) { for (int u = 0...
2
#include <bits/stdc++.h> using namespace std; # define REP(i,n) for (int i=0;i<(n);++i) # define rep(i,a,b) for(int i=a;i<(b);++i) # define p(s) std::cout << s ; # define pl(s) std::cout << s << endl; # define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl; # define YES(j) cout << (j ? "YES" : "NO") << endl; # define...
0
#include <bits/stdc++.h> using namespace std; int qreadInt() { int x = 0; char ch = getchar(); while (ch < '0' || ch > '9') ch = getchar(); while (ch >= '0' && ch <= '9') (x *= 10) += (ch - '0'), ch = getchar(); return x; } long long qreadLL() { long long x = 0; char ch = getchar(); while (ch < '0' || c...
1
#include <bits/stdc++.h> using namespace std; int main() { int n, c, sum, ans; cin >> n; for (int i = 0; i < n; i++) { cin >> c >> sum; ; int k = sum / c; ans = 0; if (sum % c != 0) { ans = (sum % c) * (k + 1) * (k + 1); } ans += (c - (sum % c)) * k * k; cout << ans << '\n'; ...
1
#include <bits/stdc++.h> using namespace std; long long s, t, l; int n; const long long mod = 998244353; int main() { cin >> n; if (n == 1) { cout << 1; return 0; } s = 2, t = 0, l = 2; for (int i = 3; i <= n; i++) { s = i * (2 * l % mod - 1 + t) % mod; l = (l * i) % mod; t = (s - l + mod)...
4
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const int maxn = 1e6 + 5; const int mod = 1000000007; int n, p; pair<long long, long long> qpow(long long a, long long b) { long long ans = 1; int big = 0; for (; b;) { if (b & 1) { ans = ans * a; if (ans > n) big = 1; ...
5
#include <bits/stdc++.h> using namespace std; int main() { int n, x; cin >> n; x = n + n / 2; cout << x; return 0; }
1
#include <bits/stdc++.h> using namespace std; using int64 = long long; int main() { int Q; cin >> Q; while(Q--) { string S, T; cin >> S >> T; if(S == T) { cout << 0 << endl; continue; } // はやすばあい int itti = 0; for(int i = 0; i < S.size(); i++) { if(S[i] == T[i])...
0
#include <bits/stdc++.h> using namespace std; const int N = 200100; char s[N]; vector<int> c; int main() { scanf("%s", s); int x = 0; int n = strlen(s); for (int i = 0; i < n; i++) { if (s[i] == '?') { x++; } else if ('A' <= s[i] && s[i] <= 'J') { c.push_back(s[i] - 'A'); } } sort(c....
1
#include <bits/stdc++.h> using namespace std; long long num[3000006], cu[3000006]; int main() { long long i, j, k, s, l, r, tc, test, n, m, d; cin >> test; for (tc = 1; tc <= test; tc++) { cin >> n >> m >> k; for (i = 1; i <= n; i++) cin >> num[i]; s = num[1]; cu[1] = num[1]; for (i = 2; i <= ...
2
#include <bits/stdc++.h> using namespace std; int main() { int n, m, x, y; cin >> n >> m; vector<int> a(m + 2); for (int i = 0; i < n; i++) { cin >> x >> y; a[x] += 1; a[y + 1] -= 1; } vector<int> v; for (int i = 1; i <= m; i++) { a[i] += a[i - 1]; if (!a[i]) v.push_back(i); } cout...
1
#include <bits/stdc++.h> using namespace std; int main() { int n, a[105]; cin >> n; for (int i = 0; i < n; ++i) { cin >> a[i]; } sort(a, a + n); swap(a[0], a[n - 1]); for (int i = 0; i < n; ++i) { cout << a[i] << ' '; } return 0; }
1
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #define eps 1e-8 using namespace std; typedef struct point { double x,y; point(double x=0,double y=0):x(x),y(y) { } } Vector; int dcmp(double x) { if(fabs(x)<eps) return 0; return x<0?-1:1; } Vector operator ...
0
#include <bits/stdc++.h> using namespace std; const long long N = 200411; vector<int> root; int now, n, s[N], p[N], toghe; void dfs(int v) { if (s[v]) { if (s[v] == now) root.push_back(v); return; } s[v] = now; dfs(p[v]); } int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d",...
4
#include <bits/stdc++.h> using namespace std; int main(void){ int r0, w0, c, r; while(true){ cin >> r0 >> w0 >> c >> r; if(!r0&&!w0&&!c&&!r) break; if(c * w0 <= r0){ cout << 0 << endl; }else{ cout << (c*w0-r0+r-1)/r << endl; } } return 0; }
0
#include <bits/stdc++.h> using namespace std; int main() { int n, j = 0, cof; cin >> n; int *mas = new int[n]; for (int i = 0; i < n; i++) cin >> mas[i]; int min, max; cin >> min >> max; bool f = true; int sum1 = 0, sum2 = 0; while (f) { sum1 += mas[j]; j += 1; if (sum1 >= min) { f =...
1
#include <bits/stdc++.h> using namespace std; int a[800]; int b[26]; char s[5555]; int main() { cin >> s; int n = strlen(s); int ans = 0; memset(b, 0, sizeof(b)); for (int i = 1; i <= n - 1; i++) { memset(a, 0, sizeof(a)); for (int j = 0; j < n; j++) { int t = (j + i) % n; int x = ((s[j] -...
5
#include<iostream> using namespace std; int main(){ int n; string s; cin >> n >> s; int ans[n]; ans[0] = 0; for(int i = 1;i<n;i++){ if(s[i] != 'W') ans[0]++; } int anss = ans[0]; for(int i = 1;i<n;i++){ ans[i] = ans[i-1] + ((s[i-1]=='W') - (s[i]=='E')); ans...
0
#include <bits/stdc++.h> using namespace std; void fastio() { ios::sync_with_stdio(NULL); cin.tie(NULL); cout.tie(NULL); } struct rec { long long flg; long long end; }; int main() { fastio(); long long i, j, n, q; cin >> n >> q; struct rec serv[n + 1]; long long arry[q][3]; for (i = 0; i < q; i++)...
3
#include <bits/stdc++.h> int main(void) { char s[101]; int i, q, k = 0; char c; q = 0; scanf("%s", s); c = s[0]; for (i = 0; s[i] != '\0'; i++) { if (s[i] == c) q++; else { k++; c = s[i]; q = 1; } if (q == 5) { q = 0; k++; c = s[i + 1]; } } ...
1
#include <bits/stdc++.h> using namespace std; #pragma GCC push_options #pragma GCC optimize("unroll-loops") int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long n; cin >> n; pair<long long, long long> ar[n]; unordered_map<long long, long long> ump1, ump2; for (int i = 0; i <...
4
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1.0); const int MAXN = 2e5 + 10; const int mod = 998244353; const int inf = 1e9 + 7; const int mo = 1e9 + 7; const int N = 1e6 + 10; int n; int a[MAXN], b[MAXN]; multiset<int> st; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("...
5
#include <bits/stdc++.h> using namespace std; inline int read() { int w = 1, s = 0; char ch = getchar(); while (!isdigit(ch)) { if (ch == '-') w = -1; ch = getchar(); } while (isdigit(ch)) { s = s * 10 + ch - '0'; ch = getchar(); } return w * s; } struct node { int to, next; } e[1000010]...
6
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int p[n + 1]; for (int i = 1; i <= n; ++i) { cin >> p[i]; } int visited[n + 1]; memset(visited, 0, sizeof(visited)); vector<vector<int> > cycles; vector<pair<int, int> > sortedCycles; for (int i = 1; i <= n; ++i) { i...
5
#include <bits/stdc++.h> using namespace std; int k[1000005], d[1000005], s[1000005], n, q, maxx, freee; int ti, ki, di; void settFree(int sec) { for (int i = 1; i <= n; ++i) if (sec == s[i]) s[i] = 0; } int countFree() { int ret = 0; for (int i = 1; i <= n; ++i) if (!s[i]) ++ret; return ret; } int getA...
3
#include <bits/stdc++.h> using namespace std; using uint = unsigned int; using lint = long long int; using ulint = unsigned long long int; template <class T = int> using V = vector<T>; template <class T = int> using VV = V<V<T> >; template <class T, class U> void assign(V<T>& v, int n, const U& a) { v.assign(n, a); }...
5
#include <bits/stdc++.h> using namespace std; int SET(int n, int pos) { return n = n | (1 << pos); } int RESET(int n, int pos) { return n = n & ~(1 << pos); } int CHECK(int n, int pos) { return (bool)(n & (1 << pos)); } int str2int(string s) { stringstream ss(s); int x; ss >> x; return x; } string int2str(int a...
2
#include <bits/stdc++.h> using namespace std; long long power(long long x, long long y, long long p); int Bit(long long x); long long sum(long long x); void Fast() { std::ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); } inline int D() { int t; scanf("%d", &t); return t; } inline long long llD(...
3
#include <stdio.h> #include <math.h> int main(void){ int a,b; scanf("%d %d",&a,&b); printf("%d %d\n",a*b ,2*a+2*b); }
0
#include <bits/stdc++.h> using namespace std; const int N = 5e5 + 5; const int inf = 2e9; int n, a[N], k, mn[N]; pair<int, int> ST[4 * N]; vector<int> v[N]; void build(int id, int l, int r) { if (l == r) { ST[id] = make_pair(a[l], l); return; } int mid = (l + r) / 2; build(id * 2, l, mid); build(id * ...
6
#include <bits/stdc++.h> using namespace std; const int N = (int)1e6 + 5; int u[3][101], n; char c[101]; int main() { scanf("%d%s", &n, &c); if (c[0] == '?' || c[0] == 'C') { u[0][0] = 1; } if (c[0] == '?' || c[0] == 'M') { u[1][0] = 1; } if (c[0] == '?' || c[0] == 'Y') { u[2][0] = 1; } for ...
1
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { if (b > a) { return gcd(b, a); } if (b == 0) { return a; } return gcd(b, a % b); } long long expo(long long a, long long b, long long mod) { long long res = 1; while (b > 0) { if (b & 1) res = (res * a) % m...
5
#include <bits/stdc++.h> using namespace std; using llong = long long; using ldbl = long double; using P = pair<llong, llong>; #define BE(x) x.begin(), x.end() const llong inf = llong(1e18)+7; const llong mod = 1e9+7; int main(){ int a, b, x; cin >> a >> b >> x; x = (x+499)/500; cout << min({(x/2+(x&1))*a, x*b...
0
#include <bits/stdc++.h> using namespace std; const int N = 1005; int n, m, S, T, p[N][N], dis[2][N], vis[2][N], res; set<int> g[N]; void bfs(int t, int v) { queue<int> Q; Q.push(v); vis[t][v] = 1; while (!Q.empty()) { int u = Q.front(); Q.pop(); for (auto i : g[u]) { if (vis[t][i]) continue; ...
4
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f, MOD = 1e9 + 7; long long a[300010]; bool cmp(long long e1, long long e2) { return e1 > e2; } long long p[300010]; int main() { int n; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; } p[0] = 1; for (int i = 1; i <= n; i++) { ...
1
#include <bits/stdc++.h> using namespace std; const int N = 2002; const int L = (int)2e9 + 9; int conf[N][N]; char ans[N][N]; int count(int i, int j) { int a = 0; if (conf[i + 1][j] == L) a++; if (conf[i - 1][j] == L) a++; if (conf[i][j + 1] == L) a++; if (conf[i][j - 1] == L) a++; return a; } int main() { ...
4
#include <bits/stdc++.h> using namespace std; const int N = 5005, mod = 1e9 + 7; long long a[N][N]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long n, m, k, x, y, cnt; cin >> n >> m >> k >> x >> y; if (n > 2) cnt = k / ((2 * n - 2) * m); else cnt = k / (n * m); for ...
3
#include <bits/stdc++.h> template <typename T> inline void read(T& t) { int f = 0, c = getchar(); t = 0; while (!isdigit(c)) f |= c == '-', c = getchar(); while (isdigit(c)) t = t * 10 + c - 48, c = getchar(); if (f) t = -t; } template <typename T1, typename T2> inline void read(T1& t1, T2& t2) { read(t1); ...
3
#include <bits/stdc++.h> using namespace std; long long Ins, Del, Rep, Exc; string A; string B; int lenA, lenB; long long DP[4001][4001]; int posA[4001][26]; int posB[4001][26]; int main() { ios::sync_with_stdio(false); while (cin >> Ins >> Del >> Rep >> Exc) { cin >> A >> B; A = "." + A; B = "." + B; ...
3
#include <iostream> #include <cmath> using namespace std; const double EPS = 1e-10; struct star { double x, y, z; bool find; }; struct telescope { double x, y, z, phi; }; star s[505]; telescope t[51]; int n; // number of stars int m; // number of telescopes bool check(int tn, int sn) { double in...
0
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 100; const int inf = 0x3f3f3f3f; int a[maxn]; int p[maxn]; long long dis[maxn]; vector<int> v, e[maxn]; void init() { for (int i = maxn - 1; i >= 2; i--) { for (int j = i; j < maxn; j += i) { p[j] = i; } } } int vis[maxn]; int main()...
5
#include<bits/stdc++.h> using namespace std; int main(){ int N; cin>>N; vector<int> A(1000000); for(int i=1;i<=100;i++) for(int j=1;j<=100;j++) for(int k=1;k<=100;k++) A[i*i+j*j+k*k+i*j+i*k+j*k]++; for(int i=1;i<=N;i++)cout<<A[i]<<endl; }
0
#include <bits/stdc++.h> using namespace std; const long long inf = 0x3f3f3f3f; const long long maxn = 201110; const long long M = 1e9 + 7; long long n, m, k, ok; long long a[maxn], b[maxn]; bool solve() { vector<pair<long long, long long> > va, vb; if (n % 2 && a[n / 2 + 1] != b[n / 2 + 1]) return false; for (lo...
6
#include <bits/stdc++.h> using namespace std; long lab[200000]; long n, m, h, t, deg[200000]; vector<long> g[200000]; vector<pair<long, long> > tocheck; long a, b; long ans; long gi; long v1, v2, mark[200000]; bool good(pair<long, long> p) { v1 = p.first; v2 = p.second; if (deg[v1] <= h) return false; if (deg[v...
4
#include <bits/stdc++.h> using namespace std; int a[1000], n, k, kk; int main() { cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; if (i == 0) { k = 1000 + a[i] % 1000; k = min(k, 1000 * (a[i] / 1000) + a[i] % 100); k = min(k, 100 * (a[i] / 100) + a[i] % 10); k = min(k, 10 * (a[i...
2
#include<bits/stdc++.h> #define H 500005 using namespace std; int h,A[H]; void maxHeapify(int x){ int l=x*2,r=x*2+1,lag; if(l<=h&&A[l]>A[x])lag=l; else lag=x; if(r<=h&&A[r]>A[lag])lag=r; if(lag!=x){ swap(A[x],A[lag]); maxHeapify(lag); } } void buildMaxHeap(){ for(int i=h/2;i>=1;i--) maxHeapi...
0
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; vector<long long> v(n); for (long long i = 0; i < n; i++) cin >> v[i]; sort(v.begin(), v.end()); long long sum = 0; for (long long i = 0; i < n; i++) sum += v[i]; for (long long i = 0; i < n; i++) { if (((long double)s...
2
#include <bits/stdc++.h> using namespace std; const int N = 300000 + 5; const int INF = 0x3f3f3f3f; int n, c[N]; int colormax[N], colormin[N], colormax1[N], colormax2[N]; int main() { scanf("%d", &n); memset(colormin, 0x3f, sizeof(colormin)); for (register int i = 1; i <= n; i++) scanf("%d", &c[i]), colormax[...
1
#include <bits/stdc++.h> using namespace std; map<string, int> mp; set<string> st; int main(int argc, char *argv[]) { int n; string s; int ans = 0; cin >> n; for (int i = 1; i <= n; i++) cin >> s, mp[s]++, st.insert(s); for (int i = 1; i <= n; i++) cin >> s, mp[s]--; set<string>::iterator it; for (it = ...
1
#include <bits/stdc++.h> using namespace std; const int mxn = 200010; const int mod = 1000000007; bool seen[mxn] = {false}; int dp[mxn]; vector<int> adj[mxn]; bool cmp(int x, int y) { return (x > y); } int main() { int n; cin >> n; for (int i = 0; i < n; i++) { vector<pair<int, int> > res; string second; ...
1
// Code by H~$~C #include <bits/stdc++.h> using namespace std; static const int Maxn = 55; static const double EPS = 1e-9; int n; struct point { double x, y; } a[Maxn]; inline double get_dist(double x, double y) { double mx = 0; for (int i = 1; i <= n; ++i) { double now = sqrt((x - a[i].x) * (x - a[i].x) +...
0
#include<bits/stdc++.h> using namespace std; typedef long long ll; #define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); #define rep(i,a,b) for(int i=(a);i<(b);++i) #define mod 1000000007 bool solve(int x) { int z = sqrt(x); //cout << z << " "; if (z * z == x) return false; ...
1
#include <bits/stdc++.h> using namespace std; void solve() { int n; cin >> n; vector<int> ans; set<int> st; for (int i = 1; i <= n; i++) st.insert(i); int pr_a = 0; cin >> pr_a; st.erase(pr_a); ans.push_back(pr_a); bool an = 1; for (int i = 1; i < n; i++) { int a; cin >> a; if (a > pr_...
2
#include <bits/stdc++.h> using namespace std; int main() { string s, t; cin >> s >> t; int n = s.length(), flag = 0, p = 0, q = 0, h = 0; char d[n][2]; for (int i = 0; i < n; i++) { d[i][0] = s[i]; d[i][1] = t[i]; } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (i != j) ...
2
#include<stdio.h> int main() { int a; scanf("%d",&a); if(a<1200){ printf("ABC\n"); } else if(a<2800){ printf("ARC\n"); } else{ printf("AGC\n"); } return 0; }
0
#include <bits/stdc++.h> using namespace std; int main() { string a, b; cin >> a >> b; long long cnt = 0, c = 0; for (long long i = 1; i < a.size(); i += 2) { if (a[i] == ']') { if (b[i] == '<') c++; else if (b[i] == ')') cnt++; } else if (a[i] == '<') { if (b[i] == ']'...
1
#include <cstdio> #include <iostream> #include <algorithm> #include <cstring> #define N 300010 #define ls (x << 1) #define rs (x << 1 | 1) using namespace std; int x[N], y[N], list[N * 3], cnt; int w, h, n, ans; struct node { int val, lab; }tr[N << 4]; inline void update(int x) { tr[x].val = max(tr[ls].val, tr[rs]...
0
#include <bits/stdc++.h> using namespace std; const int N = (int)2e6 + 7; const int MOD = (int)1e9 + 7; int n; int p[N]; long long sum[N]; int cnt[N]; void add(int x) { int ind = x + n; while (ind < N) { sum[ind] += x; cnt[ind]++; ind |= (ind + 1); } } long long getSum(int pos) { int ind = pos + n; ...
2
#include <bits/stdc++.h> using namespace std; int main() { int N, M; cin >> N >> M; vector<int> A(N), B(M); for (auto &a : A) cin >> a; for (auto &b : B) cin >> b; int x = B[0], y = A[0]; for (int i = 1; i < (M - 1); i++) x ^= B[i]; x ^= A[N - 1]; for (int i = 1; i < (N - 1); i++) y ^= A[i]; if ((y ...
4
#include <bits/stdc++.h> using namespace std; const int mxN = 3 * 100 * 1000 + 5; vector<int> g[mxN]; int vis[mxN]; void solve() { int n, k, d; cin >> n >> k >> d; queue<int> q; for (int i = 0; i < k; i++) { int p; cin >> p; p--; if (!vis[p]) { vis[p] = 1; q.push(p); } } map<...
4
#include<bits/stdc++.h> using namespace std; #define ll long long #define mod 1000000007 #define mod2 998244353 #define F first #define S second #define pb push_back #define pp pop_back #define all(x) x.begin(), x.end() #define speed ios_base::sync_with_stdio(false) \ ;cin.tie(NULL) \ ;cout.tie(NULL) #define in...
2
#include <bits/stdc++.h> using namespace std; char str[300005]; int main() { long long int n, x, y; while (scanf("%lld %lld %lld", &n, &x, &y) != EOF) { getchar(); for (int k = 0; k < n; k++) scanf("%c", &str[k]); int tag = 1; long long int cou = 0; for (long long int k = 0; k < n; k++) { ...
1
//Author:xht37 #include <bits/stdc++.h> #define ui unsigned int #define ll long long #define ul unsigned ll #define ld long double #define pi pair <int, int> #define fi first #define se second #define mp make_pair #define ls (p << 1) #define rs (ls | 1) #define md ((t[p].l + t[p].r) >> 1) #define vi vector <int> #d...
0
#include <iostream> #include <string> using namespace std; int main(){ string S; cin >> S; for(int i = 0; i < S.size(); i++){ if(S[i]=='?')S[i]='D'; } cout << S << endl; }
0
#include <bits/stdc++.h> using namespace std; int a,b; int main() { cin>>a>>b; cout<< max(0,a-2*b); }
0
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0), cout.tie(0); long long rem, cnt1, cnt2, x, y, tmp; cin >> cnt1 >> cnt2 >> x >> y; rem = 0; if (cnt1 < cnt2) swap(cnt1, cnt2), swap(x, y); while (((cnt1 + rem) / x) - rem) rem += (((cnt1 + rem) / x) - rem); ...
2
#include <bits/stdc++.h> using namespace std; const int N = 100001; const double eps = 1e-11; const int inf = (int)2e9; const int mod = (int)1e9 + 7; int a[N]; int main() { int n; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", a + i); } int cnt = 0; int ans = 0; for (int i = 0; i < n; i++)...
1