solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> using namespace std; int main(int argc, char const *argv[]) { int n, max; int num[100001]; int f[100001] = {0}; cin >> n; for (int i = 1; i < n + 1; ++i) { cin >> num[i]; } for (int i = 1; i < n + 1; ++i) { f[num[i]] = f[num[i] - 1] + 1; } max = 0; for (int i = 1; i ...
8
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(NULL); int t; cin >> t; while (t--) { long long n, k, start = 0, i; string s; cin >> n >> k >> s; while (start < n && s[start] == '0') { start++; } for (i = start; i < n; i++) { ...
7
#include <bits/stdc++.h> using namespace std; int main() { int a, b, r; cin >> a >> b >> r; if (a < 2 * r || b < 2 * r) cout << "Second" << endl; else cout << "First" << endl; return 0; }
8
#include <bits/stdc++.h> using namespace std; long long v[102]; long long D; long long pathLength(long long v1, long long time, long long v2) { long long res = 0; v[0] = v1; v[time - 1] = v2; for (int(i) = (1); (i) < (time - 1); ++(i)) v[i] = min(v[i - 1] + D, v[time - 1] + D * ((time - 1) - i)); for (int...
6
#include <bits/stdc++.h> using namespace std; const int max_n = 8 + 2; int n, m, ans = 1000, fl; vector<long long> vec; vector<long long> sec[max_n]; vector<int> child[max_n]; void get(int ind) { if (ind >= n) { int ret = fl + bool(fl > 1); for (int i = 0; i < n; i++) { ret += child[i].size(); lon...
14
#include <bits/stdc++.h> using namespace std; const int maxn = 7010; int dp[maxn][2]; int vis[maxn][2]; int out_deg[maxn][2]; vector<int> a[2]; int n; void f(int i, int j, int v) { if (vis[i][j]) return; vis[i][j] = 1; dp[i][j] = v; if (v == -1) for (int x : a[1 - j]) { int tmp = (i - x + n) % n; ...
12
#include <bits/stdc++.h> using namespace std; int n; int code[300]; vector<int> ft[11][11][4]; void update(int mul, int rem, char c, int idx, int val) { while (idx < ft[mul][rem][code[c]].size()) { ft[mul][rem][code[c]][idx] += val; idx += idx & (-idx); } } void update(int idx, char c, int val) { for (int...
13
#include <bits/stdc++.h> using namespace std; void solve() { double r, a, b, c, d; cin >> r >> a >> b >> c >> d; c = c - a; d = d - b; r *= 2; double dis = sqrt(c * c + d * d); cout << ceil(dis / r); } int main() { ios_base::sync_with_stdio(false), cin.tie(nullptr); solve(); }
6
#include <bits/stdc++.h> using namespace std; int main() { long long i, n, m, t, mi, c; map<long long, long long> x; vector<long long> a; vector<long long> b; cin >> t; while (t--) { c = 0, mi = 0; cin >> n; map<long long, long long> x; for (i = 0; i < n; i++) { cin >> m; x[m]++;...
3
#include <bits/stdc++.h> using namespace std; const long long maxn = 300 + 10, MOD = 1000 * 1000 * 1000 + 7; long long pre[maxn], a[maxn], nex[maxn], dp[100010][maxn], n, ccc; vector<long long> coins; vector<vector<long long> > tree; bool Do(long long v, vector<long long> &T) { ccc++; if (T.size() > n) return false...
13
#include <bits/stdc++.h> using namespace std; vector<pair<long long, long long>> v; vector<long long> res; long long num[1000 * 1000]; void solve() { long long n, k; scanf("%lld %lld", &n, &k); for (int i = 0; i < n * k; i++) scanf("%lld", &num[i]); sort(num, num + n * k); long long sum = 0, idx = (long long)...
1
#include <bits/stdc++.h> using namespace std; int c[1000][1000]; int main(void) { int n, m; cin >> n >> m; for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) cin >> c[i][j]; long long int scol[1001], srow[1001]; for (int i = 0; i < n; i++) { srow[i] = 0; for (int j = 0; j < m; j++) srow[i] +=...
10
#include <bits/stdc++.h> using namespace std; int a[1001], f[200][100][2]; int main() { int n; cin >> n; for (int i = 0; i <= n; i++) { for (int j = 0; j <= n; j++) { f[i][j][0] = 1000; f[i][j][1] = 1000; } } f[0][0][0] = f[0][0][1] = 0; for (int i = 1; i <= n; i++) { cin >> a[i]; ...
10
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 10; int a[N], b[N]; int n, m, K; int main() { ios::sync_with_stdio(0); cin >> n; for (int i = 1; i <= n; ++i) { cin >> a[i]; } int ans = 0; for (int k = 0; k <= 26; ++k) { int mod = 1 << (k + 1); for (int i = 1; i <= n; ++i) { ...
13
#include <bits/stdc++.h> const long long maxn = 1e6 + 10; using namespace std; long long arr[maxn]; long long ans = 0, a, b, f, k; int main() { cin >> a >> b >> f >> k; long long n = k + 1, ff = 1; long long k1 = 2 * f, k2 = 2 * (a - f); arr[1] = k1 / 2, ff = 1 - ff; for (int i = 2; i < n; i++) { if (ff) ...
7
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long n, q = 0; cin >> n; long long arr[200001]; arr[0] = 0; for (int i = 1; i < n; i++) { cin >> arr[i]; arr[i] += arr[i - 1]; q = min(arr[i], q); } q = 1 - q; unordered_map<i...
7
#include <bits/stdc++.h> long long mod = 1000000007; using namespace std; int n; int L[700], R[700]; int dp[700][700]; int rec(int i, int j) { if (i > j) return 1; if (dp[i][j] != -1) return dp[i][j]; int ans = 0, lim = j - i; for (int k = 0; k <= lim; k++) if (L[i] <= 2 * k + 1 && 2 * k + 1 <= R[i]) ...
14
#include <bits/stdc++.h> using namespace std; const int M = 4200000; namespace io { const int L = (1 << 21) + 1; char ibuf[L], *iS, *iT, obuf[L], *oS = obuf, *oT = obuf + L - 1, c, st[65]; int f, tp; inline void flush() { fwrite(obuf, 1, oS - obuf, stdout); oS = obuf; } inline void putc(char x) { *oS++ = x; if ...
16
#include <bits/stdc++.h> using namespace std; const int N = 2505; long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } long long lcm(long long a, long long b) { return a * (b / gcd(a, b)); } long long fact(long long n) { long long ret = 1; for (int i = 1; i <= n; i++) ret *= i; return re...
16
#include <bits/stdc++.h> using namespace std; long long mod = 998244353; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cout << fixed; cout.precision(12); long long t; cin >> t; while (t--) { long long n; cin >> n; vector<int> a(n); vector<int> ar(1025); ...
4
#include <bits/stdc++.h> #pragma comment(linker, "/stack:256000000") using namespace std; const int N = 1000500, M = 200500, INF = 1000 * 1000 * 1000 + 7; const long double eps = 1e-9; bool a[N]; long long gcd(long long a, long long b) { return !b ? a : gcd(b, a % b); } long long lcd(long long a, long long b) { return ...
8
#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); } long long lcm(long long a, long long b) { return a * (b / (gcd(a, b))); } inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; } inline long long toL...
11
#include <bits/stdc++.h> using namespace std; template <typename T> void print2dvector(vector<vector<T> > v) { cout << "A 2d vector:" << endl; int a = v.size(); int b = v[0].size(); if (a <= 15 && b <= 15) { for (int i = 0; i < a; i++) { for (int j = 0; j < b; j++) { cout << setw(4) << v[i][j]...
7
#include <bits/stdc++.h> using namespace std; const int maxn = 1000555; long long a[maxn * 2]; int main() { long long n; int k, pos = 0, tot = 0; cin >> n >> k; while (n) { if (n & 1) a[maxn + pos]++, tot++; n >>= 1; pos++; } if (tot > k) { cout << "No" << endl; return 0; } for (int ...
12
#include <bits/stdc++.h> using namespace std; int a[5]; int main() { cin >> a[0] >> a[1] >> a[2]; sort(a, a + 3); cout << a[1] - a[0] + a[2] - a[1]; }
0
#include <bits/stdc++.h> using namespace std; int x, y, d; long long gcd(long long a, long long b) { if (b == 0) return a; return gcd(b, a % b); } long long lcm(long long a, long long b) { return a * (b / (gcd(a, b))); } int lowestbit(int n) { int idx = (log2(n & -n)); return 1 << idx; } bool colinear(int x1, i...
7
#include <bits/stdc++.h> using namespace std; void solve() { long long n; cin >> n; vector<long long> line(n); for (long long& i : line) cin >> i; set<long long> av; for (long long i = 1; i <= 2 * n; i++) av.insert(i); for (long long i : line) av.erase(i); vector<long long> ans(2 * n); for (long long ...
4
#include <bits/stdc++.h> using namespace std; int main() { int t, n; cin >> t; int x, sum2 = 0; char s1 = '(', s2 = ')'; string temp; for (int i = 0; i < t; i++) { cin >> n; string sum[2 * n]; if (n == 1) { cout << s1 << s2 << endl; } else if (n > 1) { for (int j = 0; j < n; j++)...
0
#include <bits/stdc++.h> using namespace std; int n, k, p; int read() { int s = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { s = s * 10 + ch - '0'; ch = getchar(); } return s * f; } double dp[500][50...
16
#include <bits/stdc++.h> using namespace std; long long int cnt[1001][1001] = {}; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long int n, m; cin >> n >> m; if (n > m) { cout << 0 << endl; return 0; } long long int a[n]; long long int x[1001] = {}; for (...
8
#include <bits/stdc++.h> using namespace std; const int INF = 1e9; const long long INFLL = 0x3f3f3f3f3f3f3f3f; const int MOD = 1e9 + 7; vector<vector<pair<int, int> > > arv; long long s, soma; int ans = 0; bool vis[100005]; int dist[100005]; struct comp { bool operator()(pair<int, int> a, pair<int, int> b) const { ...
12
#include <bits/stdc++.h> using namespace std; const double eps = 1e-8; const int N = 121000; int n, a, b, c, d, f[N]; double len[N]; struct node { double l, r; } stars[N]; inline int cmp(const void* a, const void* b) { node *A = (node*)a, *B = (node*)b; if (fabs(A->l - B->l) < eps) { return A->r < B->r ? -1 :...
19
#include <bits/stdc++.h> using namespace std; const int maxn = 1e7 + 5; int vis[maxn]; int main() { long long n, m; cin >> n >> m; long long ans = 0; for (long long i = 1; i <= n; i++) { ans += min(i * i, m) * 2; } for (long long i = 1; i <= n; i++) { for (long long j = i - 1; j >= 0; j--) { i...
15
#include <bits/stdc++.h> using namespace std; int n, a[100005], b[100005], st[100005], top; int main() { memset(b, -1, sizeof(b)); scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); st[++top] = i; while (a[i - 1] != a[i]) { b[st[top]] = a[i - 1]; a[i - 1]++; top--; ...
8
#include <bits/stdc++.h> using namespace std; long long a; int main() { scanf("%lld", &a); long long now = 100000000000000000ll % a, P = 0; for (int i = 1; i <= 9; i++) P = (P + (now * i % a)) % a; now = 0; for (int i = 1; i <= 18; i++) now = (now + P) % a; now = (now + 1) % a; long long l = 1, r = 100000...
17
#include <iostream> #include <vector> #include <set> #include <climits> #include <string> #include <algorithm> #include <math.h> #include <map> #include <unordered_map> #include <queue> #include <iomanip> #include <stack> #include <bitset> #include <stdio.h> using namespace std; typedef long long ll; //#define int lon...
5
#include <bits/stdc++.h> using namespace std; void solve() { long long int t = 1; while (t--) { long long int n, i, sum = 0, y = 0, ans = 0; cin >> n; long long int a[n]; for (i = 0; i < n; i++) { cin >> a[i]; sum += a[i]; } for (i = 0; i < n - 1; i++) { y += a[i]; if...
4
#include <bits/stdc++.h> #pragma GCC target("avx2") #pragma GCC optimization("O3") using namespace std; int gcd(int a, int b) { if (!a || !b) return max(a, b); return gcd(max(a, b) % min(a, b), min(a, b)); } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t; cin >> t; while (t--) { l...
1
#include <bits/stdc++.h> const long long MXN = 1e5 + 1; const long long MNN = 1e3 + 1; const long long MOD = 1e9 + 7; const long long INF = 1e18; const long long OO = 1e9 + 500; using namespace std; int n, k, ans, pa[MXN], push_back[MXN]; string s; bool check(int l, int r) { if (min(pa[r] - pa[l - 1], push_back[r] - ...
7
#include <bits/stdc++.h> using namespace std; int A[105][105], n, m; void rotate() { for (int i = 0; i < n; i++) for (int j = i + 1; j < m; j++) { swap(A[i][j], A[j][i]); } } bool check() { for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) if (A[i][j]) return true; return false; } in...
9
#include <bits/stdc++.h> using namespace std; int n, k, x, temp; int odd, even; int main() { while (scanf("%d %d", &n, &k) != EOF) { odd = even = 0; for (int i = 0; i < n; i++) { scanf("%d", &x); if (x & 1) odd++; } even = n - odd; if (n == k) { if (odd & 1) printf("Stann...
14
#include <bits/stdc++.h> using namespace std; long long modexpo(long long x, long long y) { if (y == 0) return 1; if (y % 2) { long long viky = modexpo(x, y / 2); return (((x * viky) % 1000000007) * viky) % 1000000007; } else { long long viky = modexpo(x, y / 2); return (viky * viky) % 1000000007;...
3
#include <bits/stdc++.h> using namespace std; struct node { int l, r, t; node() {} node(int l1, int r1, int t1) : l(l1), r(r1), t(t1) {} }; inline bool operator<(const node &x, const node &y) { return x.l < y.l; } struct hhhh { int l, r, t, id; } h[500010]; set<node> st; long long S[100010], M[100010], R[100010...
23
#include <bits/stdc++.h> using namespace std; const int N = 100010; int lazy[4 * N]; int tree[4 * N]; void prop(int start, int end, int pos) { if (lazy[pos] == 0) return; tree[pos] += lazy[pos]; if (start != end) { lazy[2 * pos + 1] += lazy[pos]; lazy[2 * pos + 2] += lazy[pos]; } lazy[pos] = 0; } int ...
14
#include <bits/stdc++.h> using namespace std; long long n, a[100001], s, ans, i; int main() { cin >> n; for (i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); for (i = 0; i < n; i++) { if (s <= a[i]) ans++, s += a[i]; } cout << ans; return 0; }
5
//表 #include<bits/stdc++.h> using namespace std; int p[2005][2005]; int ans[2005]; /*void ran(int i,int v,int x,int y) { // cout<<i<<" "<<v<<" "<<x<<" "<<y<<endl; if(i<0) { return ; } if(i==0) { p[x+100][y+100]++; return ; } else if(v==0) { int t=rand()%2; int b=rand()%2; // cout<<t<<" "<<b<<end...
5
#include <bits/stdc++.h> using namespace std; const int __n = 1e3 + 5, mod = 1e9 + 7, INF = 0x3f3f3f3f; template <typename T> inline void read(T &__result) { T x = 0, f = 1; char ch = getchar(); while (!isdigit(ch)) { if (ch == '-') f = -1; ch = getchar(); } while (isdigit(ch)) { x = x * 10 + ch -...
5
#include <bits/stdc++.h> using namespace std; pair<int, int> arr[1001]; int ok[8]; int main() { ios_base::sync_with_stdio(0); int n, top, botton; cin >> n >> top; for (int i = 0; i < n; i++) cin >> arr[i].first >> arr[i].second; botton = 7 - top; for (int i = 0; i < n; i++) { ok[arr[i].first] = arr[i].f...
3
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:134217728") using namespace std; int dp[1 << 10][1 << 7][2][2]; int pw[1 << 10]; int main() { int n, k, m; cin >> n >> k >> m; dp[0][0][0][0] = 1 % m; pw[0] = 1 % k; for (int i = 1; i < 1 << 10; ++i) pw[i] = pw[i - 1] * 10 % k; for (int i = 0; i < n; ...
14
#include <bits/stdc++.h> using namespace std; long long n, k; int main() { cin >> n >> k; long long one = 1; long long res = 0; long long max_v = log2(n); if ((one << max_v) > n) max_v--; if (k == 1) cout << n; else { for (int i = max_v; i >= 0; i--) { res += one << (max_v - i); } co...
5
#include <bits/stdc++.h> using namespace std; struct node { long long energy; ; long long pref; long long suff; long long dist; }; vector<node> st; vector<int> d; vector<int> h; node combine(node left, node right, int m) { if (left.energy == 0) { return right; } else if (right.energy == 0) { retur...
15
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int t = 1; while (t--) { int n; cin >> n; vector<pair<int, int>> a; int x, y; for (int i = 0; i < n; ++i) { cin >> x >> y; a.push_back(make_pair(x, y)); } sort(a.begin(), ...
2
#include <bits/stdc++.h> using namespace std; void solve() { int n; cin >> n; vector<int> d(15); multiset<long long int> s; int flag = 0; for (int i = 0; i < n; i++) { long long int x; cin >> x; if (x < 2048) { s.insert(x); } else if (x == 2048) { flag = 1; } } if (flag) ...
2
#include <bits/stdc++.h> using namespace std; int main() { int t, i, j, k, n, m; scanf("%d", &n); int foo = 0, bar = 0, baz = 0, quz = 1; int pur; for (i = 0; i < n; i++) { scanf("%d", &pur); foo = foo + pur; bar = bar + 1; if (max(foo * quz, bar * baz) == foo * quz) { baz = foo; q...
9
#include <bits/stdc++.h> using namespace std; int n; vector<vector<long long>> grid; long long number = 1; long long k; void In() { cin >> n; grid.resize(n, vector<long long>(n, 0)); } bool IsColored(int i, int j) { return i % 2 == 0; } void PrintCoordinate(pair<int, int>& curr_coordinate) { cout << curr_coordina...
13
#include <bits/stdc++.h> using namespace std; #define fi first #define se second #define pb push_back #define mp make_pair typedef long long ll; typedef pair<int, int> pi; typedef pair<ll, int> pli; typedef pair<ll, ll> pll; typedef pair<double, double> pdd; typedef vector<int> vi; int mod = 998244353; void solve(...
17
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; long long int x; vector<long long int> v; for (int i = 0; i < n; i++) { cin >> x; v.push_back(x); } vector<long long int>::iterator it; vector<long long int>::iterator it2; vector<long long int>::iterator it4; vector...
4
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); string s; cin >> s; int ss = s.size(), vk = 0, cnt; for (int i = 0; i < ss - 1; i++) if (s[i] == 'V' && s[i + 1] == 'K') vk++; for (int i = 0; i < ss; i++) { if (s[i] == 'V') s[i] = 'K'; else ...
3
#include <bits/stdc++.h> using namespace std; using pii = pair<int, int>; using ll = long long; #define IOS ios::sync_with_stdio(0); cin.tie(0); #define endl '\n' #define pb push_back #define all(v) (v).begin(),(v).end() #define sz(v) (int)(v).size() #define mk make_pair #define F first #define S second #define debug...
19
#include <bits/stdc++.h> using namespace std; vector<long long> vec; inline long long gcd(long long a, long long b) { return a % b ? gcd(b, a % b) : b; } inline long long calc(long long a, long long b) { long long Max = 0; for (int i = 0; i < vec.size(); ++i) { long long t = vec[i]; if (a % t) continue; ...
13
#include <bits/stdc++.h> using namespace std; int read() { int x = 0, f = 1; char ch = getchar(); while (!isdigit(ch)) { if (ch == '-') f = -1; ch = getchar(); } while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar(); return x * f; } const int N = 3e5 + 5; int n, del[N]; int st[N], top, ok[N]; st...
18
#include <bits/stdc++.h> using namespace std; int main() { long long int t, i; scanf("%I64d", &t); long long int a[100011] = {0}, cnt[100011] = {0}; long long int dp[100011] = {0}; long long int max1 = 0; for (int i = 0; i < t; ++i) { scanf("%I64d", &a[i]); cnt[a[i]]++; if (a[i] > max1) { ...
7
#include <bits/stdc++.h> using namespace std; void SieveOfEratosthenes(long long n) { bool prime[n + 1]; memset(prime, true, sizeof(prime)); for (long long p = 2; p * p <= n; p++) { if (prime[p] == true) { for (long long i = p * p; i <= n; i += p) prime[i] = false; } } } long long power(long long ...
7
#include <bits/stdc++.h> using namespace std; long long power(long x, long n) { if (n == 0) return 1; if (n == 1) return x; long n2 = n / 2; long long po = power(x, n2); if (n % 2) return po * po * x; return po * po; } long long gcd(long long a, long long b) { if (b == 0) return a; a %= b; return gcd(...
8
#include <bits/stdc++.h> using namespace std; int main() { int h, m; scanf("%d:%d", &h, &m); for (int i = 0;; i++) { if (h / 10 == m % 10 && h % 10 == m / 10) { printf("%d\n", i); return 0; } m++; m %= 60; if (m == 0) { h++; h %= 24; } } return 0; }
2
#include <bits/stdc++.h> int main() { int n, k; std::cin >> n >> k; std::vector<int> a(n); for (auto& now : a) { std::cin >> now; } if (k == 1) { std::cout << *std::min_element(a.begin(), a.end()) << '\n'; } else if (k >= 3) { std::cout << *std::max_element(a.begin(), a.end()) << '\n'; } els...
4
#include <bits/stdc++.h> #pragma GCC optimize(3) #pragma GCC optimize("Ofast") using namespace std; char BUF[1 << 22], *ST, *EN; template <class T> void read(T &x) { int f = 0; x = 0; char ch = (ST == EN && (ST = BUF, EN = BUF + fread(BUF, 1, 1 << 21, stdin), ST == EN) ?...
16
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, h; cin >> n >> h; int f[n], width = 0; for (int i = 0; i < n; ++i) { cin >> f[i]; if (f[i] <= h) { width++; } else { width += 2; } } cout << width << "\n"; return 0; ...
0
#include <bits/stdc++.h> using namespace std; const int INFI = (1LL << 31) - 10; const long long INFL = (1LL << 62); const double eps = 1e-10; const long double pi = acos(-1.0); const int MAXN = 102; int main() { int n, k; double x0, y0, ep; scanf("%d%d%lf", &n, &k, &ep); scanf("%lf%lf", &x0, &y0); ep /= 1000...
13
#include <bits/stdc++.h> #pragma GCC optimize(3) using namespace std; bool Finish_read; template <class T> inline void read(T &x) { Finish_read = 0; x = 0; int f = 1; char ch = getchar(); while (!isdigit(ch)) { if (ch == '-') f = -1; if (ch == EOF) return; ch = getchar(); } while (isdigit(ch))...
15
#include <bits/stdc++.h> using namespace std; bool fastsort(int x, int y) { return x > y; } int cmp_str(int x, string s1) { int ans; string s; while (x > 0) { ans = x % 10; x /= 10; s += (ans + 48); } if (s == s1) { return 1; } return 0; } int to_int(int x, string s) { int p = 1; for (...
0
#include <bits/stdc++.h> using namespace std; class CPattern { public: void solve(std::istream& in, std::ostream& out) { long long n; in >> n; vector<string> arr; for (long long i = 0; i < n; i++) { string s; in >> s; arr.emplace_back(s); } long long m = arr[0].length(); ...
4
#include <bits/stdc++.h> using namespace std; map<int, vector<int>> mp; int main() { int n; cin >> n; int arr[n + 1]; for (int i = 1; i <= n; i++) { cin >> arr[i]; } for (int i = 1; i <= n; i++) { if (arr[arr[arr[i]]] == i) { cout << "YES" << endl; exit(0); } } cout << "NO" << en...
0
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 10; const int mod = 1e9 + 7; int read() { int x = 0, f = 1; char c = getchar(); while (c < '0' || c > '9') { if (c == '-') f = -1; c = getchar(); } while (c >= '0' && c <= '9') x = (x << 1) + (x << 3) + c - '0', c = getchar(); return ...
20
#include <bits/stdc++.h> using namespace std; const int inf = (int)1e9 + 7; const int N = (int)1e7 + 7; char c[105][105]; int main() { int n, m, x, y; scanf("%d %d", &n, &m); for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { cin >> c[i][j]; } } int mni, mnj, mxi, mxj, ans = 0; mni ...
5
#include <bits/stdc++.h> using namespace std; long long n, m, v, h, maxh, maxv; long long three[100010]; pair<long long, long long> ans; void dfs(long long m, long long t, long long r) { if (m == 0) { ans = max(ans, make_pair(t, r)); return; } long long Do = upper_bound(three + 1, three + 100002, m) - thr...
14
#include <bits/stdc++.h> using namespace std; int n, m; vector<int> G[10001]; int main() { ios_base::sync_with_stdio(false); cin >> n; for (int i = 1; i < n; i++) { int x, y; cin >> x >> y; G[x].push_back(y); G[y].push_back(x); } long long Sol = 0; for (int i = 1; i <= n; i++) Sol += 1LL * G...
5
#include <bits/stdc++.h> using namespace std; const double EPS = 1e-9; const int INF = 0x7f7f7f7f; const double PI = acos(-1.0); template <class T> inline T _abs(T n) { return ((n) < 0 ? -(n) : (n)); } template <class T> inline T _max(T a, T b) { return (!((a) < (b)) ? (a) : (b)); } template <class T> inline T _min...
7
#include <bits/stdc++.h> using namespace std; int ar[] = {0, 0, 1, -1}; int ac[] = {1, -1, 0, 0}; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(7); int n; cin >> n; string s; cin >> s; int cnt0, cnt1; cnt0 = cnt1 = 0; for (int i = 0; i < n; i++) if (s[i...
0
#include <bits/stdc++.h> using namespace std; vector<string> multiples8; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cout.precision(20); for (int i = 0; i < 1000; i++) if (i % 8 == 0) multiples8.push_back(to_string(i)); string s; cin >> s; for (int i = 0; i < multip...
7
#include <bits/stdc++.h> using namespace std; const long long mod = (long long)1e9 + 7; const long long maxn = (long long)1e5 + 1000; const long long maxe = (long long)1e6 + 7; const long long INF = (long long)1e9 + 7; const double PI = acos(-1); int dx[4] = {0, 0, 1, -1}; int dy[4] = {-1, 1, 0, 0}; void mul(long long ...
20
#include <bits/stdc++.h> using namespace std; int n; long long s = 0; long long f(long long x) { int r = x % 4; if (r == 1) return 1LL; if (r == 2) return x + 1; if (r == 3) return 0LL; return x; } int main() { cin >> n; while (n--) { long long x, m; cin >> x >> m; s ^= f(x - 1) ^ f(x + m - 1)...
12
#include <bits/stdc++.h> using namespace std; int a[100005]; int b[100005]; int main() { int n; while (cin >> n) { for (int i = 1; i <= n; i++) cin >> a[i]; if (n == 1 || n == 2) { cout << 0 << endl; continue; } int ok = 0, ans = 100001; for (int i = -1; i <= 1; i++) for (int j...
7
#include <bits/stdc++.h> using namespace std; int main() { long long n, m; cin >> m >> n; double Sum = 0; double Count = 0; for (double i = 1; i <= m; i++) { double x = pow(i / m, n) - pow((i - 1) / m, n); Sum += i * x; } cout.precision(12); cout << fixed << double(Sum); }
8
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 5; int n, m; int main() { cin >> n >> m; int ans = n + 5; int l, r; for (int i = 0; i < m; i++) { scanf("%d%d", &l, &r); ans = min(r - l + 1, ans); } printf("%d\n", ans); for (int i = 0; i < n; i++) printf("%d ", i % ans); retu...
9
#include <bits/stdc++.h> using namespace std; int main() { long double a; cin >> a; if (a <= 127) cout << "byte" << endl; else if (a <= 32767) cout << "short" << endl; else if (a <= 2147483647) cout << "int" << endl; else if (a <= 9223372036854775807) cout << "long" << endl; else cout ...
5
#include <bits/stdc++.h> using namespace std; long long int n; long long int a[105][105]; void f(long long int x, long long int y, long long int val) { if (a[x][y] != -1) return; a[x][y] = val; if (x + 1 <= n) { if (y + 2 <= n) { f(x + 1, y + 2, (val + 1) % 2); } if (y - 2 >= 1) { f(x + 1,...
3
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; if (n <= 3) { cout << "NO" << endl; } else { int curr = n; int count = 0; cout << "YES" << endl; if (n % 2 == 0) { while (curr > 4) { cout << curr << " - " << curr - 1 << " = 1" << endl; curr -=...
7
#include <bits/stdc++.h> int main() { int n, i, p, j; double v = 0; scanf("%d", &n); int a[100]; for (i = 0; i < n; i++) { scanf("%d", &a[i]); v += ((double)a[i] / n); } printf("%.12lf", v); return 0; }
0
#include <bits/stdc++.h> using namespace std; using LL = long long; const int maxn = 305; int val[maxn][maxn]; int row[maxn], col[maxn]; int main() { int T; scanf("%d", &T); int n, k; while (T--) { scanf("%d%d", &n, &k); int i, j; for (i = 1; i <= n; i++) { for (j = 1; j <= n; j++) val[i][j] =...
8
#include <bits/stdc++.h> using namespace std; int k; int main() { scanf("%d", &k); if (k % 2) { printf("-1\n"); return 0; } for (int i = 0; i < k; i++) { for (int j = 0; j < k; j++) { for (int l = 0; l < k; l++) printf("%c", (i / 2 + j % 2 + l / 2) % 2 ? 'w' : 'b'); printf("\n");...
8
#include <bits/stdc++.h> using namespace std; const int inf = 1000000007; const long long linf = 1ll * inf * inf; const int N = 500000 + 7; const int M = 31; const int multipleTest = 0; class SegmentTree { public: const static int MAXN = N; struct node { long long val; int lz; int leftChild; int ri...
19
#include <bits/stdc++.h> using namespace std; bool cmp(const int &a, const int &b) { return a > b; } int main() { cin.sync_with_stdio(0); cin.tie(0); cin.exceptions(cin.failbit); long long int n; cin >> n; vector<long long int> v; for (int i = 0; i < n; i++) { long long int x; cin >> x; v.push...
2
#include <bits/stdc++.h> using namespace std; const int maxn = 110; int n, k; string t, s[maxn]; bool ans, a, b; int main() { string t; cin >> t >> n; for (int i = 0; i < n; i++) { cin >> s[i]; if (s[i] == t) { ans = 1; } if (s[i][0] == t[1]) { a = 1; } if (s[i][1] == t[0]) { ...
1
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:1073741824") using namespace std; const int nmax = 210; int c[nmax][nmax]; int f[nmax][nmax]; vector<int> g[nmax]; int gA[2010]; int* gAf[nmax]; int gAk[nmax]; int G[nmax][nmax]; vector<int> Gv[nmax]; bool used[nmax]; int T; int d[nmax]; int q[nmax]; bool bfs(int...
21
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 7; const int inf = 0x3f3f3f3f; const int mod = 1e9 + 7; const double pi = acos(-1.0); const double G = 6.67430e-11; int t; int n; int a[maxn]; int main() { cin >> t; while (t--) { cin >> n; int s = 0; for (int i = 1; i <= n; ++i) cin >...
7
#include <bits/stdc++.h> using namespace std; int main() { char S[1000], ch; int b, g, r, y, ex = 0; int one = 0, two = 0, three = 0, four = 0; cin >> S; int l = strlen(S); for (int i = 0; i < l; i = i + 4) { if (S[i] == '!') ex++; else ch = S[i]; } if (ch == 'B') b = ex; if (ch ==...
3
#include <bits/stdc++.h> using namespace std; int n, res; int matrixs[120][120]; bool jgood(int row, int col) { return row == n / 2 || col == n / 2 || row == col || row + col == n - 1; } void calcT(void) { for (int i = 0; i < (n); ++i) for (int j = 0; j < (n); ++j) if (jgood(i, j)) res += matrixs[i][j]; }...
0
#include <bits/stdc++.h> using namespace std; long long h[200005], to[200005], ne[200005], en = 0, fr[200005], siz[200005], dst[200005]; vector<long long> ve, v[200005], prs[200005]; map<pair<long long, long long>, double> ans; void add(long long a, long long b) { to[en] =...
17
#include <bits/stdc++.h> using namespace std; const int INF = (int)1e9; struct pt { int x, y; pt() {} pt(int _x, int _y) : x(_x), y(_y) {} pt operator-(const pt &p) const { return pt(x - p.x, y - p.y); } long long operator%(const pt &p) const { return 1LL * x * p.x + 1LL * y * p.y; } long long d2() co...
15