solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { long long m2 = max(a, b); long long m1 = min(a, b); if (m1 == 0) return m2; else return gcd(m2 % m1, m1); } bool check_prime(long long x) { if (x <= 1) return false; if (x <= 3) return true; if (x % 2 == 0 || x...
0
#include <bits/stdc++.h> using namespace std; int main(int argc, const char* argv[]) { int n; cin >> n; int s[n]; for (int i = 0; i < n; i++) cin >> s[i]; int a[n]; for (int i = 0; i < n; i++) a[i] = i + 1; for (int i = 0; i < n; i++) { if (s[i]) a[s[i] - 1] = 0; } int f = -1, g, i = 0; for (i =...
7
#include <bits/stdc++.h> using namespace std; void solve() { long long n; cin >> n; string s; cin >> s; vector<long long> v(n, -1); v[0] = 0; long long cur = 0; bool f = 1; for (long long i = 0; i < n - 1; i++) { if (v[i] == -1) v[i] = 0; cur = v[i]; for (long long j = i + 1; j < n; j++) {...
10
#include <bits/stdc++.h> template <typename T> void read(T &); template <typename T> void write(const T &); const int iinf = 2147483647; const long long llinf = 9223372036854775807ll; const int N = 200005; std::pair<int, int> query(int l, int r); void solve(int l, int r); int a[N]; int n; int main() { read(n); solv...
19
#include <bits/stdc++.h> using namespace std; set<string> ans; int dp[100050][2]; string s; int main() { int i; cin >> s; int len = s.size(); for (i = len - 1; i > 4; --i) { if (i + 2 == len) dp[i][0] = 1, ans.insert(s.substr(i, 2)); else if (i + 3 == len) dp[i][1] = 1, ans.insert(s.substr(i...
10
#include <bits/stdc++.h> using namespace std; int main() { long long n, m, k; cin >> n >> m >> k; bool odd = true; if ((n * m * 2 % k > 0) || (k < 2)) { cout << "NO"; } else { long long a = n; long long b = m; long long l = k; if (l % 2 == 0) { l /= 2; odd = false; } fo...
10
#include <bits/stdc++.h> using namespace std; int main() { long long n, k, x, a = 0; cin >> n >> k >> x; long long sum = 0; for (long long i = 1; i <= n - k; i++) { cin >> a; sum += a; } for (long long i = n - k + 1; i <= n; i++) { cin >> a; sum += x; } cout << sum; return 0; }
0
#include <bits/stdc++.h> const int maxn = 301; using std::cin; using std::cout; typedef std::deque<char> AS[maxn]; AS s0[maxn], s1[maxn]; struct pr { int x, y; }; struct ppr { pr x, y; }; std::vector<ppr> v0, v1; int n, m; inline void push(std::vector<ppr>& v, AS* s, int x0, int y0, int x1, int y1) { s[x1][y1].pu...
16
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; int m = (int)floor(sqrt((double)n)) + 1; bool fl = 0; for (int i = max(1, m - 1000000); i <= (m); i++) { int s = 0, j = i; while (j) { s += (j % 10); j /= 10; } if ((((long long)i * i + (long long)i *...
6
#include <bits/stdc++.h> using namespace std; struct fenwick { vector<long long> ftree; void update(long long i, long long val) { while (i < ftree.size()) { ftree[i] += val; i = i | (i + 1); } } long long query(long long i) { long long ans = 0; while (i >= 0) { ans += ftree[i];...
11
#include <bits/stdc++.h> using namespace std; int main() { int n, i; scanf("%d", &n); for (i = 1; i <= 1005; i++) { int a = n * i + 1; bool prime = true; for (int j = 2; j < a; j++) { if (a % j == 0) { prime = false; break; } } if (!prime) break; } printf("%d\n"...
0
#include <bits/stdc++.h> using namespace std; const int Mod = 998244353; struct Edge { int v, nxt; } e[1000010]; int tot; int first[500010]; void build(int u, int v) { e[++tot] = (Edge){v, first[u]}; first[u] = tot; return; } long long f[500010][2]; long long g[500010][2]; long long F[2], G[2]; void dfs(int u, ...
20
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const int maxn = 200000 + 100; vector<int> st; int pv[maxn], sz[maxn]; vector<int> g[maxn]; vector<int> jobs[maxn]; int depth[maxn]; bool flag; void dfs(int v, int pr) { st.push_back(v); pv[v] = pr; sz[v] = 1; for (int u : g[v]) { if ...
18
#include <bits/stdc++.h> using namespace std; void initialize(vector<long long>& arr, std::vector<long long>& size, long long N) { for (long long i = 0; i < N; i++) { arr[i] = i; size[i] = 1; } } long long root(vector<long long>& arr, long long i) { while (arr[i] != i) { i = arr[i]; ...
5
#include <bits/stdc++.h> int a[20010], ab[20010], b, c; int abs(int a) { return a >= 0 ? a : -a; } int main() { int x, y, z, i, j, t, ans; scanf("%d", &t); while (t--) { scanf("%d%d%d", &x, &y, &z); for (i = 1; i <= 2 * z; i++) ab[i] = 100000; for (i = 1; i <= 2 * z; i++) for (j = i; j <= 2 * z;...
12
#include <bits/stdc++.h> int main() { int i, n, j; char a, ch[100]; gets(ch); n = strlen(ch); if (n == 1) { puts(ch); return 0; } for (i = 0; i < n - 1; i += 2) { for (j = 0; j < n - i - 1; j += 2) { if (ch[j] > ch[j + 2]) { a = ch[j + 2]; ch[j + 2] = ch[j]; ch[j]...
0
#include <bits/stdc++.h> using namespace std; int cnt[20]; int main() { int N, M; scanf("%d%d", &N, &M); bool ok = true; while(N) { if(cnt[N % M]) ok = false; cnt[N % M]++; N /= M; } puts(ok ? "YES" : "NO"); return 0; }
10
#include <bits/stdc++.h> using namespace std; const int MAXN = 210, INF = 1e9; int n, k, w[MAXN], f[MAXN][MAXN], tmp[MAXN], u, v, ans; vector<int> e[MAXN]; void Merge(int* a, int* b) { for (long long j = (n); j >= (1); j--) { b[j] = b[j - 1]; } for (long long j = (0); j <= (n); j++) { tmp[j] = a[j]; } ...
14
#include <bits/stdc++.h> using namespace std; int mo = 1e8; int dp[101][101][2]; int n1, n2, k1, k2; void solve(int a, int b, int k) { if (a + b == 0) dp[a][b][k] = 1; if (dp[a][b][k] != -1) return; if (k == 0) { dp[a][b][0] = 0; for (int i = 1; i <= k1; i++) if (a - i >= 0) solve(a - i, b, ...
9
#include <bits/stdc++.h> int main() { int a, b, c, d, e, f; scanf("%d%d%d%d%d%d", &a, &b, &c, &d, &e, &f); if (a <= d && ((d - a) + e) >= b && (((d - a) + e) - b) + f >= c) printf("YES\n"); else printf("NO\n"); }
0
#include <bits/stdc++.h> using namespace std; void fast() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } int main() { fast(); long long t, i; cin >> t; while (t--) { long long f[10], n, m, s = 0, ans = 0; cin >> n >> m; for (i = 0; i < 10; i++) { f[i] = (m * i) % 10...
4
#include <bits/stdc++.h> const int kNMax = 100010; using namespace std; char str[kNMax], pat[kNMax]; int rad[kNMax], pre[kNMax], f[kNMax]; int n; pair<int, int> out[3]; void manacher() { int p = -1; for (int i = 0; i < n; i++) { if (p != -1 && p + rad[p] > i) rad[i] = min(rad[2 * p - i], p + rad[p] - i); ...
20
#include <bits/stdc++.h> using namespace std; int main() { ios_base ::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long int n, i, j, x; vector<long long int> v; cin >> n; for (i = 0; i < n; i++) { cin >> x; v.push_back(x); } sort(v.begin(), v.end()); for (i = v.size() - 2; i >= 0; i = i...
4
#include <bits/stdc++.h> using namespace std; const int N = 200001; void solve() { int n; cin >> n; vector<pair<int, int>> f(n + 1); for (int i = 0; i < n; i++) { int c; cin >> c; f[c].first++; int c2; cin >> c2; if (c2 == 1) f[c].second++; } sort(f.begin(), f.end(), [&](pair<int, in...
6
#include <bits/stdc++.h> using namespace std; int main() { cout.sync_with_stdio(false); cin.tie(0); cout.tie(0); cerr.tie(0); cout << setprecision(16); string S; int N; while (cin >> N >> S) { if (S.size() == 1) { cout << S << endl; continue; } cout << '1'; for (auto i : S) ...
0
#include <bits/stdc++.h> using namespace std; #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #pragma GCC optimize("unroll-loops") #pragma GCC optimize("Ofast") #pragma GCC optimize("O3") #pragma GCC target("avx") const long long INF = numeric_limits<long long>::max() / 2; const long doubl...
10
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; const int N = 2005; const int INF = 1e9; vector<int> v[N], w[N]; bool vis1[N], vis2[N], vis3[N]; vector<int> v2; int c = 0; bool f; void dfs2(int u) { vis2[u] = 1; for (auto x : w[u]) { if ((!vis2[x]) && (vis3[x])) { f = 0; ...
7
#include <bits/stdc++.h> using namespace std; struct island { long long u, v; }; struct bg { long long u, v; int cs; }; const int nm = 200002; int n, m; island a[nm]; bg c[nm]; int kq[nm]; set<pair<long long, int> > b; bool cmp2(bg a, bg b) { if (a.v != b.v) return a.v < b.v; return a.u < b.u; } int main() { ...
12
#include <bits/stdc++.h> using namespace std; long long n, ans = 0; int main() { scanf("%lld", &n); long long d, c, f, v, g; bool r = false, b = false, p = false; for (int i = 1; i <= n; i++) { long long m; char s; scanf("%lld %c", &m, &s); if (s == 'P' || s == 'R') { if (r) { ans ...
14
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; for (int i = 1; i <= k; i++) { for (int j = 1; j <= n; j++) { if ((1 << i) <= (n - j)) { cout << j; } else if (((n - j) >> (i - 1)) == 0) { cout << n; } else { cout << j + (1 << (i - 1...
8
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 1; long long m, n, a, b, sum, l, r, mid, k, t; bool flag; long long f(long long y) { return a + b * (y - 1); } bool judge(long long x) { if ((f(k) + f(x)) * (x - k + 1) >> 1 <= t * m) return true; return false; } int main() { scanf("%I64d %I64d %I6...
11
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); long long int n, sum = 0, count = 0, m, flag = 0, ans = 0; cin >> n; string s; cin >> s; int a, b, c, d; if (n == 24) { a = s[0] - '0'; b = s[1] - '0'; c = s[3] - '0'; ...
5
#include <bits/stdc++.h> using namespace std; long long n, i, a[1000005], cnt; int main() { cin >> n; for (i = 1; i <= n; i++) cin >> a[i]; for (i = 1; i <= n; i++) while (a[i] != i) swap(a[i], a[a[i]]), cnt++; cout << (n % 2 == cnt % 2 ? "Petr" : "Um_nik"); return 0; }
10
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); unsigned long long h, n; cin >> h >> n; bool isL = true; unsigned long long ans = 0; unsigned long long p = 0; while (h != 0) { p = pow(2, h - 1); if (p > n && isL) { ans += 1; isL = !isL; ...
9
#include <bits/stdc++.h> using namespace std; struct Celeb { int x, y, t; Celeb(int x, int y, int t) { this->x = x; this->y = y; this->t = t; } }; int time_dist(Celeb &a, Celeb &b) { return abs(a.x - b.x) + abs(a.y - b.y); } bool can_extend(Celeb &a, Celeb &b) { return (b.t - a.t) >= time_dist(a, b); ...
12
#include <bits/stdc++.h> using namespace std; int main() { long long int n; cin >> n; while (n--) { long long int dice, d; cin >> dice; if (dice == 2 || dice == 3 || dice == 4 || dice == 5 || dice == 6 || dice == 7) { d = 1; } else { if (dice % 5 == 0) { d = dice / 5; ...
0
#include <bits/stdc++.h> using namespace std; int g[1000005]; vector<int> V[15]; int f(int x) { int ans = 1; while (x) { if (x % 10) ans *= x % 10; x /= 10; } return ans; } int main() { for (int i = (1); i < (10); i++) g[i] = i, V[g[i]].push_back(i); for (int i = (10); i < (1000001); i++) g[i] = g[f...
5
#include <bits/stdc++.h> using namespace std; vector<vector<int> > G; vector<int> COLOR; vector<vector<long long> > DP; const long long mod = 1e9 + 7; void solve(int vId, int parentId) { if (G[vId].size() > 1 || vId == 0) { for (int i = 0; i < G[vId].size(); ++i) { if (parentId != G[vId][i]) solve(G[vId][i]...
12
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s; cin >> s; int a[n], i = 0, ct2 = 0, ct3 = 0; for (int i = 0; i < n; i++) { a[i] = (int)s[i] - 48; } sort(a, a + n, greater<int>()); for (int i = 0; i < n; i++) { if (a[i] == 1 || a[i] == 0) continue; ...
6
#include <bits/stdc++.h> using namespace std; int a[100]; int cmp(const void *a, const void *b) { return *(int *)b - *(int *)a; } int main() { int n, m, k, i; scanf("%d%d%d", &n, &m, &k); for (i = 0; i < n; i++) scanf("%d", &a[i]); qsort(a, n, sizeof(int), cmp); int g = 0, sum = 0; i = 0; sum = k; while...
3
#include <bits/stdc++.h> using namespace std; void rot(pair<int, int> &p) { swap(p.first, p.second); p.first *= -1; } double norm(pair<int, int> p) { double x = p.first, y = p.second; return sqrt(x * x + y * y); } long long qua(double siz, pair<int, int> b) { double bs = norm(b); return round(siz / bs); } b...
12
#include <bits/stdc++.h> using namespace std; vector<pair<int, int> > Sh; const int tmax = 200; char table[tmax][tmax]; pair<int, int> mow[tmax]; pair<int, int> ccount(int row, int side, int ai) { if (mow[row].second == 0 && mow[row + 1].second == 0) return make_pair(0, ai); if (mow[row].second == 0) { if (side...
7
#include <bits/stdc++.h> char s[1000]; int a[200], b[200], c[200][200], n, m, p, q; int main() { scanf("%d", &n); memset(a, 0, sizeof(a)); memset(b, 0, sizeof(b)); memset(c, 0, sizeof(c)); for (int i = 1; i <= n; i++) { scanf("%s", s); for (int j = 1; j <= n; j++) if (s[j - 1] == '.') { ...
7
#include <bits/stdc++.h> using namespace std; double dist(pair<long long int, long long int> a, pair<long long int, long long int> b) { double ans = (a.first - b.first) * (a.first - b.first) + (a.second - b.second) * (a.second - b.second); return sqrt(ans); } int main() { int n, m; ci...
10
#include <bits/stdc++.h> using namespace std; inline int read() { int x = 0, 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(); } return x * f; } vector<int> V[200010], ...
26
#include <bits/stdc++.h> using namespace std; const long long maxn = 2e5 + 7; long long a[maxn]; signed main() { long long T; scanf("%lld", &T); while (T--) { long long n, k, sum = 0; scanf("%lld%lld", &n, &k); for (long long i = 1; i <= n; i++) { scanf("%lld", &a[i]); sum += a[i]; } ...
8
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; const int K = 60; const long long mod = 1e9 + 7; const long long inf = 1e18 + 10; int a[N], seg[4 * N][K], n, res; void build(int l = 1, int r = n, int id = 1) { if (r - l == 1) { for (int i = 0; i < K; i++) { seg[id][i] = 1; if (i ...
16
#include <bits/stdc++.h> using namespace std; int main() { int a, b, s, temp; scanf("%d%d%d", &a, &b, &s); temp = s - (abs(a) + abs(b)); if (temp % 2 == 0 && temp >= 0) printf("Yes"); else printf("No"); return 0; }
2
#include <bits/stdc++.h> using namespace std; int n, m; vector<vector<int> > V; vector<int> adj[1000005]; int fa[1000005]; bool used[1000005]; int val[1000005]; void init() { for (int i = 1; i <= n * m; i++) { fa[i] = i; } return; } int getfa(int x) { if (fa[x] == x) { return x; } else { return ge...
14
#include <bits/stdc++.h> using namespace std; template <typename T> void _R(T &x) { cin >> x; } void _R(int &x) { scanf("%d", &x); } void _R(long long &x) { scanf("%" PRId64, &x); } void _R(double &x) { scanf("%lf", &x); } void _R(char &x) { scanf(" %c", &x); } void _R(char *x) { scanf("%s", x); } void R() {} templat...
18
#include <bits/stdc++.h> using namespace std; struct receipt { int p, x, t; }; struct payout { int x, t; }; int32_t main() { ios::sync_with_stdio(0); cin.tie(nullptr); int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; i++) cin >> a[i]; int q; cin >> q; vector<receipt> receipts; vector<pa...
8
#include <bits/stdc++.h> using namespace std; int a[10], sum = 0; int main() { for (int i = 0; i < 6; i++) { cin >> a[i]; sum += a[i]; } for (int i = 0; i < 6; i++) { for (int j = i + 1; j < 6; j++) { for (int k = j + 1; k < 6; k++) { if ((a[i] + a[j] + a[k]) * 2 == sum) { cout...
2
#include <bits/stdc++.h> using namespace std; int n; int a[1000000 + 3]; int msa(int first) { int mx = 0, cur = 0; for (int i = 0; i < n; ++i) { cur += first * a[i]; mx = max(mx, cur); cur = max(0, cur); } return mx; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); string s, ...
13
#include <bits/stdc++.h> const int INF = 0x3f3f3f3f; const long long int INFLL = 0x3f3f3f3f3f3f3f3fll; long long int getint() { long long int ret = 0; bool f = 0; char c; while ((c = getchar()) < '0' || c > '9') if (c == '-') f ^= 1; while (c >= '0' && c <= '9') { ret = ret * 10 + c - '0'; c = get...
18
#include <bits/stdc++.h> using namespace std; long long n, m, k, num[111]; long long C[111][111]; int f[111][10011]; long long power[111][111]; long long powerMod(long long x, long long y) { if (y == 0) return 1; if (y == 1) return x % 1000000007; long long res = powerMod(x, y / 2); res = (res * res) % 10000000...
11
#include <bits/stdc++.h> using namespace std; const int N_MAX = 5e5; int n, with[N_MAX + 1], c[2 * N_MAX + 1]; vector<int> G[2 * N_MAX + 1]; void DFS(int u) { for (int v : G[u]) { if (c[v] != -1) continue; c[v] = 1 - c[u]; DFS(v); } } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin ...
20
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 2; const int LOG = 17; const int inf = 1e9; int jump[LOG][maxn]; int depth[maxn]; bool red[maxn]; int tin[maxn]; int tout[maxn]; int tmr = 0; int dist[maxn]; int nearest[maxn]; queue<int> q; vector<int> e[maxn]; vector<int> New; int n; void dfs(int v,...
16
#include <bits/stdc++.h> using namespace std; const int maxn = 2 * 100005; struct TwoSat { int n; vector<int> G[maxn * 2]; bool mark[maxn * 2]; int S[maxn * 2], c; bool dfs(int x) { if (mark[x + n]) return false; if (mark[x]) return true; mark[x] = true; S[c++] = x; for (int i = 0; i < G[x...
14
#include <bits/stdc++.h> using namespace std; template <class T> T sqr(T x) { return x * x; } long double pi = 3.1415926535897932384626433832795; long long mod = 1e9 + 7; long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } long long _gcd(long long a, long long b, long long& x, long long& y) { ...
13
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } int p = 2; int d = 1; while (p < n) { d++; p *= 2; } d--; int p1 = 0; for (int i = 0; i < n - 1; i++) { int f = pow(2, d) + 0.5; if (f + i >= n) ...
2
#include <bits/stdc++.h> using namespace std; const int maxN = 1e4; pair<int, int> a[maxN]; int main() { int n; cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i].first; cin >> a[i].second; } sort(a + 1, a + n + 1); int lst = 0; int ans = 0; for (int i = 1; i <= n; i++) { if (a[i].second >...
6
#include <bits/stdc++.h> using namespace std; const int MAXN = 5005; int n, h[MAXN], dp[MAXN][2]; int main() { cin >> n; for (int i = 1; i <= n; i++) cin >> h[i]; for (int i = 1; i <= n; i++) { dp[i][0] = dp[i][1] = 1000000000; int sum = 0; for (int j = i; j >= 1; j--) { sum += h[j]; if (d...
13
#include <bits/stdc++.h> using namespace std; long long int l, n, arr[120005]; map<int, int> s; int main() { cin >> l; for (int i = 0; i < l; i++) { cin >> arr[i]; if (s.count(arr[i])) { s[arr[i]]++; } else { s.insert(pair<int, int>(arr[i], 1)); } } int ans = 0; for (long long int ...
5
#include <bits/stdc++.h> using namespace std; long long int n, m; long long int arr[300000]; string st, tt, ttt; long long int sumn(long long int a) { return a * (a + 1) / 2; } vector<pair<long long int, string> > out; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); ; long long int TES...
12
#include <bits/stdc++.h> using namespace std; int bmm(int a, int b) { while (b != 0) { int c = a; a = b; b = c % b; } return a; } int F(int a, int m) { int ans = 0; while (a >= m) { ans += a % m; a = a / m; } return ans + a; } int main() { int n; cin >> n; int sum = 0; for (int...
2
#include <bits/stdc++.h> using namespace std; using ll = long long int; using ull = unsigned long long int; using dd = double; using ldd = long double; using si = short int; using pii = pair<int, int>; using pll = pair<ll, ll>; void dfs(int v, vector<vector<int>>& gr, vector<int>& a, int p = 0) { int j = 0; for (in...
8
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; inline long long read() { bool f = false; char ch = getchar(); long long res = 0; while (ch < '0' || '9' < ch) f |= (ch == '-'), ch = getchar(); while ('0' <= ch && ch <= '9') res = 10 * res + ch - '0', ch = getchar(); return f ? -...
7
#include <bits/stdc++.h> using namespace std; #define pb push_back #define ppb pop_back #define pf push_front #define ppf pop_front #define eb emplace_back #define mt make_tuple typedef pair<int, int> pairs; typedef pair<pair<int,int>,pair<int,int>> pairofpairs; #define int long long #define rep(i,j, k) for(int ...
1
#include <bits/stdc++.h> using namespace std; long long a[100005]; set<long long> A; int n, k; int main() { scanf("%d%d", &n, &k); for (int i = 1; i <= n; i++) { scanf("%lld", &a[i]); } sort(a + 1, a + 1 + n); for (int i = 1; i <= n; i++) { if (a[i] % k || A.find(a[i] / k) == A.end()) { A.insert...
7
#include <bits/stdc++.h> using namespace std; int getnum() { char c = getchar(); int num; int sign = 1; for (; c < '0' || c > '9'; c = getchar()) if (c == '-') sign = -1; for (num = 0; c >= '0' && c <= '9';) { c -= '0'; num = num * 10 + c; c = getchar(); } return (num * sign); } vector<int...
12
#include <bits/stdc++.h> using namespace std; long long w, m, val[105]; map<long long, int> sb; int ed, st = 1, limit; bool dfs(int cur, long long tmp) { if (cur == ed) { if (st) sb[tmp]++; else { if (sb.count(m - tmp)) return true; else return false; } } else { if ...
11
#include <bits/stdc++.h> using namespace std; long long a[500], b[500], n, m, ans, sum, q, i, j; int main() { cin >> n; for (i = 1; i <= n; i++) { cin >> a[i]; b[i] = b[i - 1] + a[i]; } sum = b[n]; ans = 500; for (i = 1; i <= n; i++) { for (j = i; j <= n; j++) { q = b[j] - b[i]; if (...
4
#include <bits/stdc++.h> const int max_N = (int)5e5 + 21; const int log_N = 22; namespace SuffixArray { int sa[max_N], rk[max_N], ht[max_N], st[log_N][max_N], bit[max_N]; int tmp[max_N], cnt[max_N], bc[max_N]; void build(const char *s, int n) { int i, j, k, T, sigma; for (i = 1; i <= n; ++i) sa[i] = i; std::sort(...
25
#include <bits/stdc++.h> using namespace std; struct point { long double x, y; }; point sub(point a, point b) { return {a.x - b.x, a.y - b.y}; } long double cross(point a, point b) { return a.x * b.y - a.y * b.x; } const int N = 1e5 + 10; point p[N]; bool used[N]; int n; bool ok(point a, point b) { for (int i = 0; ...
12
#include <bits/stdc++.h> using namespace std; const int INF = 1e9 + 96; const int MAXN = 2e5 + 5; const int MOD = 1e9 + 7; const int MAX_ASCII_CODE = 26; const int MAX_NUMBER_OF_NODES = 1e5 + 5; long long n; int as[MAXN]; int main() { cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(NULL); cout << fixed << se...
2
#include <bits/stdc++.h> using namespace std; const double EPS = 1e-9; const double PI = acos(-1); const int INF = (int)1e9 + 9; const int MAXN = (int)4e6 + 7; int n; int a[MAXN]; int b[MAXN]; int d[MAXN]; int delta; int pos[MAXN]; multiset<int> M; multiset<int> P; int get(int x) { return d[x] + delta; } void add(int x...
13
#include <bits/stdc++.h> using namespace std; double p; double q[200000]; double pow(int x) { if (x == 1) return p; double s = pow(x / 2); if (x & 1 == 1) return s * s * p; else return s * s; } int main() { int m, n; scanf("%d%d", &m, &n); double ans = 0; double r = 0; for (int i = 1; i <= m; ...
8
#include <bits/stdc++.h> using namespace std; int n = 0; int m = 0; bool *visited; bool **ADJ; int ind = 0; int speicial[] = {6, 6, 6, 3, 6, 4, 5, 1, 2, 5, 1, 4, 5, 4}; int input[1000]; void DFS(int begin) { stack<int> search; int curr = begin; visited[curr] = true; search.push(curr); while (!search.empty()) ...
7
#include <bits/stdc++.h> #pragma GCC optimize(2) using namespace std; template <typename T> void read(T &x) { x = 0; char op = getchar(); int F = 1; while (!isdigit(op)) { if (op == '-') F *= -1; op = getchar(); } while (isdigit(op)) { x = (x << 1) + (x << 3) + op - '0'; op = getchar(); } ...
11
#include <bits/stdc++.h> using namespace std; int n, Next[600010][26], tot; int dis[600010], Size[600010], cnt[600010], len; int dfs1(int st) { Size[st] = 1; for (int i = 0; i < (26); i++) { int v = Next[st][i]; if (v == 0) continue; dis[v] = dis[st] + 1; Size[st] += dfs1(v); } cnt[dis[st]] += S...
17
#include <bits/stdc++.h> using namespace std; int N, M; vector<pair<int, int> > E[101000]; int X[101000], Y[101000], Z[101000]; int dist[2][100100]; int NN[2]; int cost[100100]; int from[100100]; int un[100100], ret; map<pair<int, int>, int> MM; void solve() { int i, j, k, l, r, x, y; string s; cin >> N >> M; f...
13
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; const double eps = 1e-9; const int inf = 1e9; int a[N]; int main() { int t; cin >> t; while (t--) { int n; cin >> n; int pos = -1; for (int i = 0; i < n; i++) { cin >> a[i]; if (a[i] & 1) { if (pos == -1) pos...
0
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; const unsigned gen_seed = std::chrono::system_clock::now().time_since_epoch().count(); std::mt19937_64 gen(gen_seed); class stree { public: std::vector<int> t; int s; void build(std::vector<int>& a, int v, int tl, int tr) { i...
20
#include <bits/stdc++.h> using namespace std; int read() { char c; int w = 1; while ((c = getchar()) > '9' || c < '0') if (c == '-') w = -1; int ans = c - '0'; while ((c = getchar()) >= '0' && c <= '9') ans = (ans << 1) + (ans << 3) + c - '0'; return ans * w; } int n, m; struct node { int next, to...
11
#include <iostream> #include <cstdio> #include <cstdlib> #include <algorithm> #include <cmath> #include <vector> #include <set> #include <map> #include <unordered_set> #include <unordered_map> #include <queue> #include <ctime> #include <cassert> #include <complex> #include <string> #include <cstring> #include <chrono> ...
4
#include <bits/stdc++.h> using namespace std; int main() { int n, s = 0, alt; cin >> n; int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; if (i && a[i] - a[i - 1] > s) { s = a[i] - a[i - 1]; } } alt = a[n - 1] - a[0]; for (int i = 2; i < n; i++) { if (a[i] - a[i - 2] < s) { ...
1
#include <bits/stdc++.h> using namespace std; int z, n, a, b, w; set<pair<int, int> > took, avail; pair<pair<int, int>, int> level[300007]; int res[300007]; int bestres[300007]; long long ret, bestv; int cur, bestid; void puttwo(int i) { avail.insert(make_pair(level[i].first.second - level[i].first.first, n + i)); } ...
18
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const int maxn = 200005; int n, k; int a[maxn], b[maxn]; int x[maxn], y[300 * 100000 + 2]; long long ans[maxn]; int l[maxn], r[maxn]; vector<int> v[maxn]; int c[300 * 100000 + 2]; int main() { scanf("%d %d", &n, &k); int N = 0; for (int i =...
18
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; vector<int> ans; int power = 1; while (n > 0) { if (n % 10 > 0) { ans.push_back((n % 10) * power); } n /= 10; power *= 10; } cout << ans.size() << ...
0
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, m; cin >> n >> m; int num = 1e9; int cnt = 0; vector<int> a(n + 1); vector<int> b(n + 1); for (int i = 1; i <= n; ++i) { a[i] = i; b[i] = (i - 1) / 2; cnt += b[i]; } ...
14
#include <bits/stdc++.h> using namespace std; int n, m, k; int f[512][512], g[512][512], cyc[512][512]; int tot[512]; void PreDeal(int t) { int num[512], left[512], right[512]; memset(num, 0, sizeof(num)); memset(left, 0, sizeof(left)); memset(right, 0, sizeof(right)); int ph = 0, pt = 0; tot[t] = 0; for ...
10
#include <bits/stdc++.h> using namespace std; bool vis[200010]; int l[200010], r[200010]; string ans; vector<int> v; int main() { int n, m; string s; cin >> n >> m >> s; s = "." + s; for (int i = 1; i <= n; i++) { int l = (i + n - 2) % n + 1, r = i % n + 1; if (s[l] == s[i] || s[i] == s[r]) { v....
15
#include <bits/stdc++.h> using namespace std; const int MOD = (int)1e9 + 7; const int INF = (int)1e9; const long long LINF = (long long)1e18; const long double PI = acos((long double)-1); const long double EPS = 1e-9; inline long long gcd(long long a, long long b) { long long r; while (b) { r = a % b; a = b...
2
#include <bits/stdc++.h> using namespace std; int len; int k; string str; bool flag = false; int first[256], last[256]; set<pair<int, int> > s; int main(int argc, char const *argv[]) { cin >> len >> k; cin >> str; for (int i = 0; i < 256; i++) first[i] = last[i] = -1; for (int i = 0; i < len; i++) { int ind...
3
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; int T, n, a[N], b[N], pos; int calc(int x) { for (int i = 30; i >= 0; i--) { if ((x >> i) & 1) return i + 1; } return 0; } int main() { cin >> T; b[0] = -1e9; while (T--) { cin >> n; for (int i = 1; i <= n; i++) scanf("%d", &a...
7
#include <bits/stdc++.h> const int N = 100005; int n, m, fa[N], u, v, deg[N], toU[N], toNo[N], tot, cnt; bool g[500][N], flag[N]; struct twt { int u, v; } graph[N]; int getfa(int x) { if (x != fa[x]) fa[x] = getfa(fa[x]); return fa[x]; } int main() { scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) fa[i] =...
11
#include <bits/stdc++.h> using namespace std; int findMaxPow(int n) { int i = 1; while (n > i) { i *= 2; } if (n < i) { i /= 2; } return i; } void isPossible(int n, int k, vector<int> &v) { int remaining = n, maxPow; do { maxPow = findMaxPow(remaining); remaining -= maxPow; v.push_ba...
6
#include <bits/stdc++.h> using namespace std; inline int in() { int x; scanf("%d", &x); return x; } const long double EPS = 1e-12; const int INF = 1e9 + 10; const long long LINF = 1000ll * 1000 * 1000 * 1000 * 1000 * 1000 + 100; const int MS = 149 * 75 + 10; const int MN = 150; int n, k, s; int arr[MN]; long long...
15
#include <bits/stdc++.h> using namespace std; int N; double res; pair<double, pair<int, int> > ar[100100]; int main() { scanf(" %d", &N); if (N == 1) { printf("0.0000000000\n"); return 0; } for (int i = 1; i <= N; i++) { scanf(" %d %d", &ar[i].second.first, &ar[i].second.second); ar[i].first = a...
10
#include <bits/stdc++.h> using namespace std; long long sl[1000001]; long long l, r, L, R, res = 0, m, n; long long a[1000001]; long long S; struct data { long long first; long long second; long long stt; long long res; }; data make_data(long long first, long long second, long long stt, long long...
14