func_code_string stringlengths 59 71.4k |
|---|
#include <bits/stdc++.h> using namespace std; const int maxn = 3e3 + 7; const int mod = 998244353; int col[maxn]; namespace DSU { int far[maxn]; void init() { for (int i = 0; i < maxn; i++) far[i] = i; } int Find(int x) { return x == far[x] ? x : far[x] = Find(far[x]); } void Union(int x, int y)... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); string a; string b; cin >> a >> b; int order = 0; while (a[order] == 0 ) { order++; } a = a.substr(order); order = 0; while (b[orde... |
#include <bits/stdc++.h> using namespace std; using SI = set<int>; using ULL = unsigned long long; using LL = long long; using VI = vector<int>; using LD = long double; using PULL = pair<ULL, ULL>; using UI = unsigned int; using PLL = pair<LL, LL>; using PDD = pair<LD, LD>; using MII = map<int, in... |
#include <bits/stdc++.h> using namespace std; const int MXN = 1e5 + 1; int n, dp[MXN], k[MXN], ans = 1, rg[MXN], res, maxi; int main() { cin >> n; for (int i = 1; i <= n; i++) { cin >> k[i]; dp[k[i]] += dp[k[i] - 1] + 1; } for (int i = 1; i <= n; i++) { if (dp[k[i]] > maxi) { ... |
#include <bits/stdc++.h> using namespace std; void base() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } int main() { int t; cin >> t; while (t--) { int a, b; cin >> a >> b; if (a > b) swap(a, b); if (a * 2 < b) cout << NO n ; else { ... |
#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... |
#include <bits/stdc++.h> using namespace std; int main(void) { char sav[200]; scanf( %s , sav); int flag = 0; int len = strlen(sav); for (int i = 0; i < len; i++) { if (sav[i] == 1 ) continue; else if (sav[i] == 4 ) { if (i - 1 >= 0 && sav[i - 1] == 1 ) c... |
#include <bits/stdc++.h> using namespace std; template <class T1, class T2, class T3> bool _IN(T1 x, T2 y, T3 z) { return x <= y && x >= z || x <= z && x >= y; } unsigned long long gcd(unsigned long long a, unsigned long long b) { if (!b) return a; while (b ^= a ^= b ^= a %= b) ; return ... |
#include <bits/stdc++.h> using namespace std; template <class T> inline T bigmod(T p, T e, T M) { long long ret = 1; for (; e > 0; e >>= 1) { if (e & 1) ret = (ret * p) % M; p = (p * p) % M; } return (T)ret; } template <class T> inline T gcd(T a, T b) { if (b == 0) return a; ... |
#include <bits/stdc++.h> using namespace std; long long n; void solve() { cin >> n; long long x, y, a, b; cout << YES n ; for (long long i = 1; i <= (n); ++i) { cin >> x >> y >> a >> b; cout << 2 * (x & 1) + (y & 1) + 1; cout << n ; } } int32_t main() { ios_base::s... |
#include<bits/stdc++.h> #define ll long long using namespace std; int main() { ios_base::sync_with_stdio(0);cin.tie(NULL); int t; cin>>t; while(t--) { ll n,x; ll min=0,max=0,s=0; cin>>n>>x; ll a[n]; for(ll i=0;i<n;i++) { cin>>a[i]; s+=a[i]; if(a[i]%x==0) ... |
#include <bits/stdc++.h> using namespace std; using namespace chrono; const long long int MOD = 1000000007; const long long int MAXN = 100005; long long int k, dp[MAXN]; long long int recurse(long long int n) { if (n == 0) return 1; if (dp[n] != -1) return dp[n]; long long int ans = 0; if (n... |
#include <bits/stdc++.h> using namespace std; inline long long getint() { long long _x = 0, _tmp = 1; char _tc = getchar(); while ((_tc < 0 || _tc > 9 ) && _tc != - ) _tc = getchar(); if (_tc == - ) _tc = getchar(), _tmp = -1; while (_tc >= 0 && _tc <= 9 ) _x *= 10, _x += (_tc - 0 ), _t... |
#include <bits/stdc++.h> using namespace std; int main() { int n, i, j, k; string s; while (cin >> n >> s) { int sum = 0; int left = 0, right = 0, up = 0, down = 0; for (i = 0; i < n; i++) { if (s[i] == R ) { if (left == 1) { sum++; left = 0; ... |
#include <bits/stdc++.h> #pragma GCC optimize( Ofast,unroll-loops ) #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native,avx2 ) using namespace std; mt19937 mrnd(time(0)); const int INF = 1000000007; const long long INF_LL = 1152921504606846977; void solve() { int n, m; ... |
#include <bits/stdc++.h> using namespace std; int main() { int n, mostleft = 1000000000, mostright = 0, ans = -1; int l[100000], r[100000]; bool bo_l[100000], bo_r[100000]; cin >> n; for (int i = 0; i < n; i++) { bo_l[i] = false; bo_r[i] = false; } for (int i = 0; i < n; i++)... |
#include <bits/stdc++.h> using namespace std; const int maxN = 200005; const unsigned long long HA = 41793404541; int n, m; int a[maxN], b[maxN]; unsigned long long fac[maxN], pre[maxN], nxt[maxN]; int ansn, ans[maxN]; bool check(int l, int r) { return pre[r] - pre[l - 1] * fac[r - l + 1] == ... |
#include <bits/stdc++.h> using namespace std; const int N = 1000000; int f[N], sz[N], ak, Ak, n, m, ans[N]; struct data { int a, b, c, d, e; data(int a = 0, int b = 0, int c = 0, int d = 0, int e = 0) : a(a), b(b), c(c), d(d), e(e) {} } S[N]; struct edge { int x, y, z, id; bool opera... |
#include <bits/stdc++.h> const long long mod = 1000000007; const int maxn = 100000; using namespace std; int main() { long long n, k; scanf( %I64d , &n); scanf( %I64d , &k); vector<long long> fib(n + 1); fib[1] = 1; for (int i = 2; i < n + 1; i++) fib[i] = fib[i - 1] + fib[i - 2]; fo... |
#include <bits/stdc++.h> using namespace std; int main(int argc, const char* argv[]) { int n; cin >> n; int x = 0; for (int i = 1; i < n; i++) { if (n % i == 0) { x++; } } cout << x; return 0; } |
#include <bits/stdc++.h> using namespace std; [[maybe_unused]] const int MAX = INT32_MAX, MIN = -INT32_MAX, maxInd = 1E6 + 1E5 + 1; [[maybe_unused]] bool directed = true, end_now = false; bool possible = false; int n, k; struct node_data_structure { int pre = 0, post = 0; ... |
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; long long mul(long long a, long long b) { return a * b % mod; } long long add(long long a, long long b) { long long res = a + b; if (res >= mod) { res -= mod; } return res; } const long long MAXN = 1e6 + 5; ... |
#include <bits/stdc++.h> using namespace std; struct creature { long long hp, dmg; long long div; bool operator<(const creature& rhs) const { return div > rhs.div; } }; int n, a, b; creature in[200050]; long long ans = 0; int it, use; int main() { ios::sync_with_stdio(false); cin.tie... |
#include <bits/stdc++.h> using LL = long long; const int kN = 200000 + 5; const int kLog = 19; const LL inf = 3e14; std::vector<std::pair<int, int>> edges[kN]; int n, m, s; LL dist[kN]; int plca[kLog][kN], depth[kN]; int sz[kN]; int get_lca(int a, int b) { if (depth[a] < depth[b]) std::swap(a, b... |
#include <bits/stdc++.h> using namespace std; int n, w; double tmp; vector<double> a; vector<double> boy; vector<double> girl; double volume; double base; int main() { cin >> n >> w; for (int i = 0; i < (2 * n); i++) { cin >> tmp; a.push_back(tmp); } sort(a.begin(), a.end()... |
#include <bits/stdc++.h> using namespace std; int main() { int kase, ks = 0; int i, j, k; int n; int arr[1000]; string s; cin >> n; for (i = 1; i < n + 1; i++) cin >> arr[i]; int q; cin >> q; int x, y; while (q--) { cin >> x >> y; if (x > 1) arr[x - 1] += (y -... |
#include <bits/stdc++.h> int main() { int n, m; scanf( %d%d , &n, &m); for (int i = 1; i <= n; ++i) printf( %d , i % 2); puts( ); return 0; } |
#include <bits/stdc++.h> using namespace std; const int maxn = 3000 + 12; int p[maxn]; int Et[maxn]; int mark[maxn][maxn]; queue<pair<int, int> > act; void input(int n) { for (int i = 0; i < n; i++) cin >> p[i]; } void solve(int n, int k) { int sef = 0; bool yek = 0; for (int j = n - 1... |
#include <bits/stdc++.h> using namespace std; using lli = long long; using pii = pair<int, int>; using pll = pair<lli, lli>; template <typename T> using Vector = vector<vector<T>>; template <typename T> using Prior = priority_queue<T>; template <typename T> using prior = priority_queue<T, vector<T>,... |
#include <bits/stdc++.h> using namespace std; int main() { int n, m, min = 1000; scanf( %d %d , &n, &m); vector<int> v(m); for (int i = 0; i < m; i++) scanf( %d , &v[i]); sort(v.begin(), v.end()); for (int i = 0; n + i - 1 < m; i++) { if (min > v[n + i - 1] - v[i]) min = v[n + i - 1] -... |
#include <bits/stdc++.h> using namespace std; long long a[1000007], b[1000007], i, n, x, s, f, t; int main() { cin >> n; for (i = 1; i <= 2 * n; i++) { cin >> x; if (a[x] == 0) a[x] = i; else if (a[x] != 0) b[x] = i; } s = a[1] - 1; for (x = 2; x <= n; x++) { ... |
#include <bits/stdc++.h> using namespace std; const int N = 100005; char s[N]; int n, a[N], pre[N][26], suf[N][26]; int f[N][26], g[N], mem[27]; inline int mex(int st) { return __builtin_ctz(~st); } int calc(int l, int r, int c, int fl) { if (l > r) return 0; if (~mem[c]) return mem[c]; int st... |
#include <bits/stdc++.h> using namespace std; const int INF = 1e9 + 7; template <class C> inline void mini(C& a4, C b4) { a4 = min(a4, b4); } template <class C> inline void maxi(C& a4, C b4) { a4 = max(a4, b4); } int n, v, e; int a[307], b[307]; vector<int> GG[307], G[307]; bool del[307]... |
#include <bits/stdc++.h> using namespace std; template <typename T, typename U> std::pair<T, U> operator+(const std::pair<T, U>& l, const std::pair<T, U>& r) { return {l.first + r.first, l.second + r.second}; } typedef void (*callback_function)(void); const long long ZERO = 0LL; const long long INF64 ... |
#include <bits/stdc++.h> using namespace std; long long n, a[200002], v1, v2, ans[200002], mx, subtr[200002]; vector<long long> g[200002]; void dfs(int v, int d, int p) { ans[1] += a[v] * d; for (int to : g[v]) { if (to == p) continue; dfs(to, d + 1, v); } } void dfs2(int v, int p) {... |
#include <bits/stdc++.h> using namespace std; void read(int& x) { bool fu = 0; char c; for (c = getchar(); c <= 32; c = getchar()) ; if (c == - ) fu = 1, c = getchar(); for (x = 0; c > 32; c = getchar()) x = x * 10 + c - 0 ; if (fu) x = -x; }; char getc() { char c; for (c... |
#include <bits/stdc++.h> #pragma comment(linker, /STACK:667772160 ) using namespace std; struct __isoff { __isoff() { if (0) freopen( input.txt , r , stdin), freopen( output.txt , w , stdout); srand( C + T + A + C + Y + M + B + A ); } ~__isoff() {} } __osafwf; const un... |
#include <bits/stdc++.h> using namespace std; int expo(int x, int y) { int res = 1; while (y) { if (y % 2) res = (res * x % 1000000007) % 1000000007; x = (x * x) % 1000000007; y /= 2; } return res; } bool isPrime(long long n) { if (n <= 1) return false; if (n <= 3) retu... |
#include <bits/stdc++.h> using namespace std; const long long int N = 2e5 + 5; void solve() { long long int n, i, j, ans = 0; cin >> n; long long int a[n]; for (auto &x : a) { cin >> x; }; map<long long int, long long int> cnt; for (i = 0; i < n; i++) { for (j = i + 1; j < ... |
#include <bits/stdc++.h> using namespace std; int main() { long long n, s[3010], c[3010], ans = 1e10; cin >> n; for (int i = 0; i < n; i++) cin >> s[i]; for (int i = 0; i < n; i++) cin >> c[i]; for (int i = 0; i < n; i++) { long long min1 = 1e10, min2 = 1e10; for (int j = 0; j < i; j... |
#include <bits/stdc++.h> using namespace std; int main() { int n, m; scanf( %d %d , &n, &m); unordered_map<string, string> d; for (int i = 0; i < m; i++) { string x, y; cin >> x >> y; if ((int)x.size() > (int)y.size()) swap(x, y); d[y] = d[x] = x; } for (int i = 0; i ... |
#include <bits/stdc++.h> using namespace std; int h; long long n; long long dfs(int d, long long n, int lr) { if (d == h) return 0; long long tmp = 1ll << (h - d - 1); if (!lr && n <= tmp) return dfs(d + 1, n, !lr) + 1; if (!lr && n > tmp) return (tmp << 1) + dfs(d + 1, n - tmp, 0); if (lr &... |
#include <bits/stdc++.h> using namespace std; template <typename T> inline T abs(T t) { return t < 0 ? -t : t; } const long long modn = 1000000007; inline long long mod(long long x) { return x % modn; } const int MAXN = 100010; int n, s[MAXN]; int main() { scanf( %d , &n); printf( %d , n /... |
#include <bits/stdc++.h> using namespace std; int main() { string s; int n, i = 0; cin >> n >> s; std::vector<int> v(n); std::vector<bool> cycle(n); for (int i = 0; i < n; i++) cin >> v[i]; for (i = 0; i < n;) { if (i <= -1 || i >= n) break; if (cycle[i] == true) brea... |
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 10; long long int inf = -1e15; long long int seg[maxn << 2], lazy[maxn << 2]; int n, m, p; vector<long long int> espadas, armaduras; vector<pair<int, int> > monstros[maxn]; void update(int x, long long int val) { seg[x] += val; ... |
#include <bits/stdc++.h> using namespace std; int cnt2 = 0; int en = 0; struct Dinic { static const int MXN = 100000; struct Edge { int v, f, re; Edge(int a, int b, int c) : v(a), f(b), re(c) {} }; int n, s, t, level[MXN]; vector<Edge> E[MXN]; void init(int _n, int _s, int _t... |
#include <bits/stdc++.h> using namespace std; int n, m, dp[30010][210][4], num[30010]; int main() { int i, j; cin >> n >> m; for (i = 1; i <= n; i++) scanf( %d , &num[i]); memset(dp[0], -0x3f, sizeof(dp[0])); for (i = 0; i < 4; i++) dp[0][0][i] = 0; for (i = 1; i <= n; i++) { for (j ... |
#include <bits/stdc++.h> using namespace std; const long long maxn = 1e7; const long long maxm = 1e7; const long long INF = 0x3f3f3f3f; const long long mod = 1e9 + 7; long long uu[maxn]; int main() { long long n, a, b; cin >> n >> a >> b; for (long long i = 0; i < n; i++) scanf( %lld , &uu[i])... |
#include <bits/stdc++.h> using namespace std; const int INF = (int)1e8; int n, m; char s[22][22]; int x[22][22], dp[1 << 20], state[30], sum[30], maxN[30]; vector<int> sta[22]; vector<int> cost[22]; int bit[1 << 20]; void initialIt() { for (int i = 0; i < 20; i++) { bit[1 << i] = i; } ... |
#include <bits/stdc++.h> using namespace std; int main() { int t, n; char s[200050]; map<int, map<int, int>> vis, cnt; scanf( %d , &t); while (t--) { vis.clear(); cnt.clear(); int l = -5, r = 0x3f3f3f3f; scanf( %d%s , &n, s); int x = 0, y = 0; vis[x][y] = 1; ... |
#include <bits/stdc++.h> using namespace std; long sz(char *a) { long i = 0; while (*(a + i) != 0 ) i++; return i; } int main() { char *a = (char *)malloc(sizeof(char) * 1000001); char *b = (char *)malloc(sizeof(char) * 1000001); scanf( %1000000s , a); scanf( %1000000s , b); lo... |
#include <bits/stdc++.h> using namespace std; const int N = 1000000; int aa[N + 1]; int main() { int n; cin >> n; long long ans = 0; for (int i = 0; i <= n; i++) aa[i] = i; int n_ = n; for (int h = 20; n_ > 0;) { while (h >= 0 && (n_ & 1 << h) == 0) h--; int m = n_ - ((1 << h... |
#include <bits/stdc++.h> int main() { using namespace std; int q; cin >> q; while (q--) { long long n; cin >> n; int len = 0; char num[40] = {0}; while (n) { num[len] = n % 3 + 0 ; n /= 3; len++; } int x; for (x = len - 1; x >= 0... |
#include <bits/stdc++.h> using namespace std; int main() { char a[5][5]; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) scanf( %c , &a[i][j]); getchar(); } int flag = 0; for (int i = 0; i < 3; i++) for (int j = 0; j < 3; j++) { if (a[i][j] != a[2 - i][2 - j])... |
#include <bits/stdc++.h> using namespace std; const int maxn = 5010; int n; int a[maxn], f[maxn]; long long b[maxn]; int main() { int i, ans = 0, j; long long w; scanf( %d , &n); for (i = 1; i <= n; ++i) { scanf( %I64d , &w); while (w % 2 == 0) ++a[i], w /= 2; b[i] = w; ... |
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using pi = pair<int, int>; using pl = pair<ll, ll>; using pld = pair<ld, ld>; using vi = vector<int>; using vl = vector<ll>; using vb = vector<bool>; using vld = vector<ld>; using vs = vector<string>; usi... |
#include <bits/stdc++.h> using namespace std; using namespace std; bool debug = 1; int main() { int n, m; scanf( %d %d , &n, &m); int amn[n + 1]; vector<vector<int> > v; v.resize(n + 1); for (int i = 0; i < m; i++) { int a, b; scanf( %d %d , &a, &b); v[a].push_back(b); ... |
#include <bits/stdc++.h> using namespace std; using LL = long long; const int MAXN = 200010; vector<int> x[MAXN], y[MAXN]; int v[MAXN], out[MAXN], sg[MAXN]; int xr[MAXN]; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, m; cin >> n >> m; for (int i = 0; i < n; ++i) cin >> v... |
#include <bits/stdc++.h> using namespace std; int main() { int N, i, sum = 0, max; cin >> N; int A[N]; for (i = 0; i <= N - 1; i++) cin >> A[i]; max = *max_element(A, A + N); for (i = 0; i <= N - 1; i++) sum += (max - A[i]); cout << sum << endl; return 0; } |
#include <bits/stdc++.h> using namespace std; mt19937 rnd(339264); const long long MOD = 998244353; const double eps = 1e-7; int main() { cout << fixed << setprecision(20); int n, w, m; cin >> n >> w >> m; if (2 * n < m) { cout << NO ; return 0; } int left = m; int j =... |
#include <bits/stdc++.h> using namespace std; inline int read() { char ch = getchar(); int x = 0, f = 1; while (ch < 0 || ch > 9 ) { if (ch == - ) f = -1; ch = getchar(); } while ( 0 <= ch && ch <= 9 ) { x = x * 10 + ch - 0 ; ch = getchar(); } return x * f;... |
#include <bits/stdc++.h> using namespace std; int test, n, mx, i; double l, r, m, eps = 0.000001, a[100005]; double pref(double tm) { double pos = 0, speed = 1; for (int i = 0; i < n; i++) { if ((a[i] - pos) <= tm * speed) tm -= (a[i] - pos) / speed, pos = a[i], speed += 1; else { ... |
#include <bits/stdc++.h> using namespace std; long long a, b, s, c, ans, t; int main() { cin >> t; while (t--) { cin >> s >> a >> b >> c; ans = ((s / (a * c)) * (a + b)) + (s % (a * c)) / c; cout << ans << endl; } } |
#include <bits/stdc++.h> char str[260][260]; int main(void) { int t, n, m; scanf( %d , &t); while (t--) { int ans = 0; scanf( %d%d , &n, &m); getchar(); for (int i = 0; i < n; i++) gets(str[i]); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { i... |
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 77; int T, n, L, R, par[N], fa[N][20]; int dep[N], son[N], tid[N], sz[N]; pair<int, int> mx[N][3]; vector<int> G[N]; void dfs1(int v, int fa) { mx[v][0] = {0, v}, mx[v][1] = mx[v][2] = {-1, 0}; for (int u : G[v]) if (u ^ fa) {... |
#include <bits/stdc++.h> using namespace std; template <typename T> void maximize(T &a, T b) { if (a < b) a = b; } const int maxN = 305; int n, a[maxN][maxN], f[2][maxN][maxN]; void solve() { for (int i = 1; i <= n; ++i) fill(f[0][i] + 1, f[0][i] + n + 1, INT_MIN); f[0][1][1] = a[1][1]; fo... |
#include <bits/stdc++.h> using namespace std; using ll = long long; using vi = vector<int>; using pi = pair<int, int>; void setIO(string name = ) { ios_base::sync_with_stdio(0); cin.tie(0); } int main() { setIO(); int a, b, c, d; cin >> a >> b >> c >> d; int pv = max(3 * a / 10, ... |
#include <bits/stdc++.h> double ans, f[10][1000]; int n, k, a, v[10], p[10], g[10], ki[10], l[10]; void calc() { int b = a; for (int i = 1; i <= n; ++i) { l[i] = p[i] + g[i]; if (l[i] > 100) l[i] = 100; } f[0][0] = 1; for (int i = 1; i <= n; ++i) for (int j = 0; j <= (1 << i ... |
#include <bits/stdc++.h> using namespace std; vector<pair<int, int> > vec; void update() { int x; scanf( %d , &x); vector<pair<int, int> > a, b; a.push_back({1000010, 0}); b.push_back({1000010, 0}); a.push_back({0, 0}); b.push_back({0, 0}); int sz = vec.size(); for (int i = 0; ... |
#include <bits/stdc++.h> using namespace std; int main() { int in, x = 0; int cnt = 0, p = 1, ans = 0; cin >> in; for (int i = in; i > 0; i /= 10) { if (i % 10 == 7) ans += p; p *= 2; cnt++; } if (cnt != 0) x = pow(2, cnt) - 2; cout << ans + x + 1; } |
#include <bits/stdc++.h> using namespace std; int a[100 + 5]; int b[100 + 5]; int main() { int m, n; int l, r; while (scanf( %d%d , &m, &n) != EOF) { int sum = 0; for (int i = 1; i <= m; i++) cin >> a[i]; for (int i = 1; i <= n; i++) { cin >> l >> r; int sum1 = 0; ... |
#include <bits/stdc++.h> using namespace std; int dx[] = {1, -1, 0, 0}; int dy[] = {0, 0, 1, -1}; int xx[] = {0, 0, 1, -1, 1, -1, 1, -1}; int yy[] = {1, -1, 0, 0, 1, -1, -1, 1}; double PI = 3.1415926535897932384626433832795; const long long oo = (long long)1e9 + 1; const double eps = 1e-9; const long ... |
#include <bits/stdc++.h> using namespace std; string t; long long cnt1[3000001]; int main() { ios_base::sync_with_stdio(0); cin >> t; cnt1[0] = 0; int n = (int)t.length(); for (int i = 0; i <= n - 4; ++i) { if (t.substr(i, 5) == heavy ) ++cnt1[i + 1]; cnt1[i + 1] += cnt1[i]; ... |
#include <bits/stdc++.h> using namespace std; class wwj { public: wwj(int x); int klz(); int pdly(int k); private: int x; }; wwj::wwj(int x) { this->x = x; } int wwj::klz() { int i, sum = 0; double SM = 0; if (x == 0) return 0; SM = (-1 + sqrt(1.0 + 8 * abs(x))) / 2; ... |
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; long long power(long long x, long long y, long long m) { if (y == 0) return 1; long long p = power(x, y / 2, m) % m; p = (p * p) % m; return (y % 2 == 0) ? p : (x * p) % m; } long long gcd(long long a, long long b) { if... |
#include <bits/stdc++.h> using namespace std; inline int two(int n) { return 1 << n; } inline void set_bit(int& n, int b) { n |= two(b); } inline void unset_bit(int& n, int b) { n &= ~two(b); } inline int last_bit(int n) { return n & (-n); } template <class T> T gcd(T a, T b) { return (b != 0 ? gcd<T>... |
#include <bits/stdc++.h> using namespace std; int main() { cin.tie(0), cout.tie(0); ios::sync_with_stdio(false); string a, b; while (cin >> a >> b) { unsigned int len = a.size(); int ans = 0; bool OK = true; map<int, int> dic; for (unsigned int i = 0; i < len; ++i) { ... |
#include <bits/stdc++.h> using namespace std; const int maxn = 1000 * 100 + 15; int n, mark[maxn], h[maxn], d[maxn], g[2], cnt, c, w; vector<int> ad[maxn]; void dfs(int v) { mark[v] = 1; for (auto u : ad[v]) { if (mark[u] == 0) { h[u] = h[v] + 1; dfs(u); } } } int m... |
#include <bits/stdc++.h> using namespace std; int main() { unsigned long long n, k; cin >> n >> k; unsigned long long lo = 0, hi = min(n / 2, n / k + 1), mid; while (lo < hi) { mid = lo + (hi - lo + 1) / 2; if (mid + mid * k <= n / 2) lo = mid; else hi = mid - 1; ... |
#include <bits/stdc++.h> using namespace std; int main() { int a[72] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 3... |
#include <bits/stdc++.h> using namespace std; vector<long long> lol1; vector<long long> lol2; int main() { long long n, m; cin >> n >> m; for (long long i = 0; i < n; i++) { long long x; cin >> x; lol1.push_back(x); } for (long long i = 0; i < m; i++) { long long x; ... |
#include <bits/stdc++.h> using namespace std; const long long INF = 1 << 28; const long long LINF = 1ll << 61; inline long long getnum() { register long long r = 0; register bool ng = 0; register char c; c = getchar(); while (c != - && (c < 0 || c > 9 )) c = getchar(); if (c == - )... |
#include <bits/stdc++.h> using namespace std; int main() { int n; vector<int> g; while (cin >> n) { int xi, xf; xi = -1; xf = -1; bool init = false; g = vector<int>(n); for (int i = 0; i < n; i++) { cin >> g[i]; if (init == false && g[i] == 1) { ... |
#include <bits/stdc++.h> using namespace std; int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); } bool Check(int x, int y) { if (gcd(x, y) > 1) return false; if (gcd(x + 1, y) > 1) return false; if (gcd(x + 2, y) > 1) return false; return true; } vector<int> ans[10010]; int main() {... |
#include <bits/stdc++.h> using namespace std; const long long INF = 1e18; const int N = 1e5 + 10, INFI = 1e9 + 10; int val[12]; unordered_set<int> s; int main() { cin.tie(NULL); cout.tie(NULL); ios_base::sync_with_stdio(false); int n; cin >> n; for (int i = 0; i < 12; i++) { s.... |
#include <bits/stdc++.h> using namespace std; int a[200010], n, S, T; vector<int> A; int main() { scanf( %d , &n); for (int i = 0; i < n; i++) scanf( %d , a + i), S += a[i]; for (int i = 0; i < n; i++) if (S - a[i] == (long long)a[i] * (n - 1)) A.push_back(i + 1); printf( %d n , (int)A.siz... |
#include <bits/stdc++.h> using namespace std; vector<bool> primes(100006, false); void sieve() { for (long long i = 3; i <= 100006; i += 2) { primes[i] = 1; } for (long long i = 3; i <= 100006; i += 2) { if (primes[i] == 1) { for (long long j = i * i; j <= 100006; j += i) { ... |
#include <bits/stdc++.h> using namespace std; struct node { int r, c, p; node() {} node(int _r, int _c, int _p) { r = _r, c = _c, p = _p; } }; const int MAXN = 1005; char g[MAXN][MAXN]; int dist[MAXN][MAXN]; int dx[] = {1, 0, -1, 0}; int dy[] = {0, 1, 0, -1}; int to_int(const char& c) { re... |
#include <bits/stdc++.h> using namespace std; const int N = 100005; inline int read() { int s = 0, w = 1; char ch = getchar(); while (ch < 0 || ch > 9 ) { if (ch == - ) w = -1; ch = getchar(); } while (ch >= 0 && ch <= 9 ) { s = s * 10 + ch - 0 ; ch = getchar();... |
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; const int INF = 1e9 + 7; const int base = 1e9; const int MAX = 1e5; const double EPS = 1e-9; const double PI = acos(-1.); int main() { char x; string s1, s2, res; vector<char> v(10000); int c1, c2, cnt = 0, i = 0; ... |
#include <bits/stdc++.h> using namespace std; int n, m; long long int arr[100050]; vector<vector<long long int>> v(100050); int main() { cin >> n >> m; for (int i = 1; i <= m; i++) cin >> arr[i]; for (int i = 1; i <= m; i++) { if (i > 1 && arr[i - 1] != arr[i]) v[arr[i]].push_back(arr[i - 1]... |
#include <bits/stdc++.h> using namespace std; vector<int> prices; int main() { long long int n, p, s = 0; cin >> n; for (long long int a = 0; a < n; a++) { cin >> p; prices.push_back(p); s += p; } sort(prices.rbegin(), prices.rend()); cin >> n; for (long long int a = ... |
#include <bits/stdc++.h> using namespace std; vector<int> g[212345]; int color[212345]; bool vis[212345]; map<int, int> m; int r = 0; int dfs(int i) { if (vis[i]) return 0; vis[i] = true; m[color[i]]++; if (m[r] < m[color[i]]) r = color[i]; int cont = 0; for (int v : g[i]) { ... |
#include <bits/stdc++.h> using namespace std; long long base = 71; const long long mod = 1e9 + 9; int convert(char a) { if (a >= a && a <= z ) return (a - a ) + 1; if (a >= A && a <= Z ) return (a - A ) + 27; return (a - 0 ) + 53; } int main() { ios_base::sync_with_stdio(0); cin... |
#include <bits/stdc++.h> using namespace std; const int N = 200005; int n, q, a[N], c[N], l[N], r[N]; vector<int> s[N], p[N], b; set<int> s1, s2, s3, s4, s5, s6, s7; int main() { scanf( %d%d , &n, &q); for (int i = 1; i <= n; i++) scanf( %d , &a[i]); for (int i = 1; i <= q; i++) { scanf( %... |
#include <bits/stdc++.h> using namespace std; const int K = 10; const int NQ = 160000; int n, k, q; int v[NQ]; pair<int, int> lg[K]; int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(NULL); cin >> n >> k >> q; for (int i = 0; i < n; i++) { cin >> v[i]; } for (i... |
#include <bits/stdc++.h> using namespace std; struct __timestamper {}; vector<vector<int>> ga; vector<vector<int>> gb; vector<int> comp; vector<bool> used; void dfsa(int v) { used[v] = true; comp.push_back(v); for (int u : ga[v]) { if (!used[u]) { dfsa(u); } } } int... |
#include <bits/stdc++.h> using namespace std; bool d[400]; void input() { int i, n, nk, nc, x; scanf( %d %d , &n, &nk); scanf( %d , &nc); for ((i) = 0; (i) < (nc); (i)++) scanf( %d , &x), d[x] = true; int res = 0, cnt = 0; for ((i) = (1); (i) <= (n); (i)++) { cnt++; if (cnt == ... |
#include <bits/stdc++.h> using namespace std; struct edge { int v, next; }; bool islucky[100010]; bool vis[100010]; int A[100010], C[100010]; edge e[2 * 100010]; int beg[100010], f[100010]; int n, m, cnt, tot, ne; void dfs(int x) { if (x >= 100010) return; islucky[x] = true; dfs(x * ... |
#include <bits/stdc++.h> using namespace std; int main() { int n; long long sum; vector<int> v; ios::sync_with_stdio(0); cin >> n; sum = (1LL + n) * n / 2LL; if (sum % 2LL == 0LL) { sum /= 2LL; for (int i = n; i >= 1; i--) if (sum >= i) { v.push_back(i); ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.