func_code_string stringlengths 59 71.4k |
|---|
#include <bits/stdc++.h> using namespace std; int n; int c[301]; vector<int> a[301]; vector<int> lt[301]; int id[301]; int dem = 0; int d[301]; void nhap() { scanf( %d , &n); for (int i = 1; i <= n; i++) { scanf( %d , &c[i]); id[c[i]] = i; } for (int i = 1; i <= n; i++) { ... |
#include <bits/stdc++.h> using namespace std; template <typename T> T gcd(T a, T b) { if (a == 0) return b; return gcd(b % a, a); } template <typename T> T pow(T a, T b, long long m) { T ans = 1; while (b > 0) { if (b % 2 == 1) ans = (ans * a) % m; b /= 2; a = (a * a) % m; ... |
#include <bits/stdc++.h> using namespace std; const long long maxn = 2e5 + 888; long long dp[maxn][12]; void solve() { long long n; scanf( %lld , &n); memset(dp, -1, sizeof(dp)); dp[0][1] = 0; vector<long long> v[4]; for (long long i = 1; i <= n; i++) { for (long long j = 0; j < 4;... |
#include <bits/stdc++.h> using namespace std; const int maxn = 3e5 + 5; unsigned long long bt[maxn]; unsigned long long d[maxn]; map<unsigned long long, int> has; pair<int, int> edg[maxn]; int f[maxn]; int id[maxn]; int lab[maxn]; vector<int> e[maxn]; int vis[maxn]; int getf(int x) { if (x =... |
#include <bits/stdc++.h> using namespace std; const long long MAX_N = 2e5 + 5, inf = 1e18, mod = 1000000007; const double PI = 3.1415926536; int days[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; template <typename T> ostream& operator<<(ostream& out, const vector<T>& mas) { for (const auto... |
#include <bits/stdc++.h> using namespace std; const int Mod = 1000000000 + 7; const int MAXK = 1000000; int power(int x, int k) { int ret = 1; while (k) { if (k & 1) ret = 1LL * ret * x % Mod; x = 1LL * x * x % Mod; k >>= 1; } return ret; } int n, k, ans; int f[MAXK + 10]... |
#include <bits/stdc++.h> using namespace std; int const N = 202020; long long a[N]; long long l[N], r[N]; int main() { int n; long long k; scanf( %d%I64d , &n, &k); for (int i = 1; i <= (n); ++i) scanf( %I64d , &a[i]); for (int i = 1; i <= (n); ++i) l[i] = a[i - 1] == 1 ? 1 + l[i - 1] : 0;... |
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf( %d , &n); int s = 0, ans = 0; for (int i = 1;; i++) { for (int j = 1; j <= i; j++) s += j; if (s > n) break; ans++; } printf( %d n , ans); return 0; } |
#include <bits/stdc++.h> using namespace std; void zanj0() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } void solve() { int n, m; cin >> n >> m; int S = int(0.45 * sqrt(n)) + 1; vector<int> v(n), rev_v(n), s_jump(n); for (int i = 0; i < n; i++) { cin >> v[i]; ... |
#include <bits/stdc++.h> using namespace std; const long long int N = 1e6; ; int n, m, a, l, r, num; int arr[2]; int main() { scanf( %d%d , &n, &m); while (n--) { scanf( %d , &a); if (a == -1) ++arr[0]; else ++arr[1]; } while (m--) { scanf( %d%d , &l, ... |
#include <bits/stdc++.h> using namespace std; const long long Maxn = 1e5 + 7; const long long Max = 1e3 + 7; const long long Mod = 1e9 + 7; const long long Inf = 1e9 + 7; string s[Maxn], V[Maxn]; long long ans[5]; long long check(char t) { if (t == u || t == o || t == a || t == i || t == e ... |
#include <bits/stdc++.h> #pragma gcc optimize( Ofast ) using namespace std; using ll = long long; const int N = 1e6 + 2; int n, cnt, f[N], vis[N]; int qt, q[N]; vector<int> v; int main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); cin >> n; if (n & 1) return cout << -1 n , 0; ... |
#include <bits/stdc++.h> using namespace std; int main() { int n, a, b; cin >> n >> a >> b; for (int i = 0; (n - a * i) >= 0; i++) { if ((n - a * i) % b == 0) { cout << YES n ; cout << i << << (n - a * i) / b << endl; return 0; } } cout << NO n ; ret... |
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native ) const int N = (int)2e5 + 7; const int inf = (int)1e9 + 7; const int mod = (int)1e9 + 7; const long long linf = (long long)1e18 + 7; const int dx[] = {-1, 0, 1, 0, 1, -1, -1,... |
#include <bits/stdc++.h> using namespace std; void answer() { int n; string s, t; cin >> n >> s >> t; int ps[26], pt[26]; int cs[26], ct[26]; memset(ps, -1, sizeof(ps)); memset(pt, -1, sizeof(pt)); memset(cs, 0, sizeof(cs)); memset(ct, 0, sizeof(ct)); for (int i = 0; i < s.si... |
#include <bits/stdc++.h> using namespace std; double tick() { static clock_t oldtick; clock_t newtick = clock(); double diff = 1.0 * (newtick - oldtick) / CLOCKS_PER_SEC; oldtick = newtick; return diff; } long long gcd(long long a, long long b) { if ((a == 0) || (b == 0)) { return ... |
#include <bits/stdc++.h> using namespace std; template <typename T> inline T ABS(T a) { return a > 0 ? a : -a; } template <typename T> inline T MIN(T a, T b) { return a < b ? a : b; } template <typename T> inline T MAX(T a, T b) { return a > b ? a : b; } template <typename T> inline ... |
#include <bits/stdc++.h> using namespace std; const int kN = 1e5 + 10; const int MOD = 1e9 + 7; int N, M; int power(int d, int k) { int ret = 1, tmp = d; while (k) { if (k & 1) { ret = 1ll * ret * tmp % MOD; } tmp = 1ll * tmp * tmp % MOD; k >>= 1; } return ret; ... |
#include <bits/stdc++.h> const int maxn = 100005; int n, cnt; int a[maxn], p[maxn]; int main() { scanf( %d , &n); p[1] = 1; for (int i = 2; i <= n; i++) if (p[i] == 0) { p[i] = ++cnt; for (int j = i; j <= n; j += i) a[j] = cnt, p[j] = 1; } for (int i = 2; i <= n; i++)... |
#include <bits/stdc++.h> using namespace std; const int CMax = 5002; const int CMax2 = 100002; int m, B[CMax], A[CMax2], ats = 0, sk, pr; int main() { scanf( %d , &m); for (int i = 0; i < CMax; i++) { B[i] = 0; } for (int i = 0; i < m; i++) { scanf( %d , &sk); B[sk]++; } ... |
#include <bits/stdc++.h> using namespace std; int main() { int x, ans; string s; cin >> s; x = s.size(); for (int i = 1; i < x; i++) { if (s[i] == 1 ) { x++; break; } } cout << x / 2 << endl; return 0; } |
#include<bits/stdc++.h> #define fast {ios_base::sync_with_stdio(false);cin.tie(NULL);} using namespace std; const int mxn=2e5+5,mod=1e9+7; int dp[mxn][20],a[mxn],nxt[mxn],n; vector<int>prime_factors[mxn]; void sieve(){ for(int i=2;i<mxn;i++){ if(prime_factors[i].empty()){ nxt[i]=mxn; ... |
#include <bits/stdc++.h> using namespace std; bool is_pal(string a) { string b = a; reverse(b.begin(), b.end()); return b == a; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); ; string second; cin >> second; for (int i = 0; i < second.size(); i++) { string ... |
#include <bits/stdc++.h> using namespace std; int n, q; unordered_map<int, pair<int, int>> resi[50 * 3 + 2]; struct FLOW { int n, *pre, *dist; FLOW(int n) : n(n) { pre = (int *)malloc((n + 2) * sizeof(int)); dist = (int *)malloc((n + 2) * sizeof(int)); } ~FLOW() { free(pre); ... |
#include <bits/stdc++.h> using namespace std; const long long N = 500500; long long i, j, k, n, sum, ch, t, ans, num; long long a[N], b[N], c[N]; void R(long long &x) { x = 0; ch = getchar(); while (ch < 0 || 9 < ch) ch = getchar(); while ( 0 <= ch && ch <= 9 ) x = x * 10 + ch - 0 , ch ... |
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int n, k; cin >> n >> k; int answer = 0; int f[n]; for (int i = 0; i < n; i++) cin >> f[i]; sort(f, f + n); for (int i = n - 1; i >= 0; i -= k) answer += (2 * (f[i] - 1)); cout << ... |
#include <bits/stdc++.h> using namespace std; int n; int a[102]; int main() { cin >> n; for (int i = 0; i < n; ++i) cin >> a[i]; puts((n % 2 == 1) && (a[0] % 2 == 1) && (a[n - 1] % 2 == 1) ? Yes : No ); return 0; } |
#include <bits/stdc++.h> using namespace std; const int MX = 100000; const int N = 1e5 + 5; const int K = 135; const int MOD = 1e9 + 7; int n, first[N], incr[N], x[K]; long long pw[K][N]; int main() { cin >> n; for (int i = 0; i < n; ++i) { int x; scanf( %d , &x); incr[x]++; ... |
#include <bits/stdc++.h> using namespace std; int main(void) { vector<int> z[26]; string a, b; cin >> a >> b; for (int i = 0; i < a.size(); ++i) z[a[i] - a ].push_back(i); bool ok = true; for (int i = 0; i < b.size(); ++i) { if (z[b[i] - a ].size() == 0) { ok = false; ... |
#include <bits/stdc++.h> using namespace std; double a, v, l, d, w, t1, t2, t3, t4, t5, dis1, dis2, dis3, v1; double chuli(double x) { double diss = (v + w) * ((v - w) / a) / 2; if (diss >= x) return (-2.0 * w + sqrt(4.0 * w * w + 8.0 * a * (x))) / (2.0 * a); else return (v - w) / a + (x -... |
#include <bits/stdc++.h> using namespace std; int A, B, C, Cans = 214748364, n, r, ansA, ansB; bool f[1000010]; int gcd(int a, int b) { if (b == 0) return a; else return gcd(b, a % b); } void Work() { int t, i, a = A, b = B; for (C = 0; A != 1 || B != 1;) { if (A > B) { ... |
#include <bits/stdc++.h> using namespace std; struct point { double x, y; }; double dist(point P, point Q) { double dx = P.x - Q.x, dy = P.y - Q.y; return sqrt(dx * dx + dy * dy); } vector<point> crossing(point O1, double r1, point O2, double r2) { double d = dist(O1, O2); double t = (d ... |
#include <bits/stdc++.h> using namespace std; template <typename T> T mabs(const T &a) { return a < 0 ? -a : a; } const int mod = 1e9 + 9; const int SZ = 300300; struct mat { long long A[2][2]; mat(int a = 0, int b = 0, int c = 0, int d = 0) { A[0][0] = a; A[0][1] = b; A[1][0... |
#include <bits/stdc++.h> using namespace std; int n, m; char mat[1501][1501]; int visited[1501][1501][3]; int getr(int x) { return (x % n + n) % n; } int getc(int x) { return (x % m + m) % m; } int dx[] = {0, -1, 0, 1}; int dy[] = {-1, 0, 1, 0}; bool dfs(int lx, int ly) { int x = getr(lx), y = get... |
#include <bits/stdc++.h> using namespace std; const long long M = 1e9 + 7; vector<long long> prime; bool num[1000005 + 2]; void sieve() { num[0] = true; num[1] = true; for (long long i = 2; i <= 1000005; i++) { if (num[i] == false) { prime.push_back(i); for (long long j = 2 *... |
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1.0); const double eps = 1e-6; const int inf = 1e9; const int mod = 1e9 + 7; const int maxn = 5e5 + 10; int n; int a[1010], b[1010]; int main() { ios::sync_with_stdio(false); cin >> n; for (int i = 1; i <= n; i++) { ... |
#include <bits/stdc++.h> using namespace std; int main() { int n, a, b, c; cin >> n >> a >> b >> c; long long res = 0; for (int i = 0; i <= a; ++i) { for (int j = 0; j <= b; ++j) { if (2 * n - i - 2 * j >= 0 && !((2 * n - i - 2 * j) % 4) && 2 * n - i - 2 * j <= 4 * c) { ... |
#include <bits/stdc++.h> const int MAXN = (int)1e5 + 5; const int MODN = (int)1e9 + 7; int inf = 0x3f3f3f3f; using namespace std; char str[MAXN]; int num[MAXN]; int a[MAXN]; struct Com { int cost; int qua; } c[MAXN]; int cmp(Com a, Com b) { return a.cost < b.cost; } int main() { int n,... |
#include <bits/stdc++.h> using namespace std; const int maxn = 3e5 + 5; const int maxm = 15; const long long INF = 1e18; int n, m, k; int a[maxn]; long long dp[maxn][maxm]; void ReadInput() { cin >> n >> m >> k; for (int i = 1; i <= n; ++i) cin >> a[i]; } void Solve() { fill_n(&dp[0][0],... |
#include <bits/stdc++.h> using namespace std; const int maxn = 5e5 + 10; char s[maxn], t[maxn]; int nxt[maxn]; void getNxt(int m) { int i = 1, j = 0; nxt[0] = 0; while (i < m) { if (t[i] == t[j]) nxt[i++] = ++j; else if (!j) i++; else j = nxt[j - 1]; }... |
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize(2) #pragma GCC optimize(3) inline int read() { int x = 0, f = 0; char ch = getchar(); while (!isdigit(ch)) f |= ch == - , ch = getchar(); while (isdigit(ch)) x = 10 * x + ch - 0 , ch = getchar(); return f ? -x : x; } in... |
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; char now = ; int count = 0, sum = 0, n; n = s.size(); for (int i = 0; i < n; i++) { if (now == s[i] and count < 5) count++; else sum++, now = s[i], count = 1; } cout << sum <... |
#include <bits/stdc++.h> using namespace std; const int N = 100005; int t[N]; int main() { ios_base::sync_with_stdio(0); int n; cin >> n; t[0] = 0; t[n + 1] = 0; for (int i = 1; i <= n; ++i) { cin >> t[i]; t[i] = min(t[i - 1] + 1, t[i]); } for (int i = n; i > 0; --i) ... |
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } const int MAXN = 100000; const int MAXQ = 100000; int n, nq; int x[MAXN]; int qx[MAXQ], qt[MAXQ]; long long qans[MAXQ]; pair<int, int> o[MAXQ]; priority_queue<pair<int, pair<i... |
#include <bits/stdc++.h> using namespace std; const int N = 5050; int c, d; char ch[N]; int Calc(int b, int e) { c = 0, d = 0; int ret = 0, i; for (i = b; i <= e; i++) { if (ch[i] == ( ) c++; if (ch[i] == ) ) { if (c) c--; else { if (d > 0) ... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int tt = 1; cin >> tt; while (tt--) { int n; cin >> n; int A[n]; for (int i = 0; i < n; i++) { cin >> A[i]; } int cnt = 0; sort(... |
#include <bits/stdc++.h> using namespace std; int INT_MAX_VAL = (int)0x3F3F3F3F; int INT_MIN_VAL = (int)-0x3F3F3F3F; long long LONG_MAX_VAL = (long long)0x3F3F3F3F3F3F3F3F; long long LONG_MIN_VAL = (long long)-0x3F3F3F3F3F3F3F3F; long long vx, vy, wx, wy; long long R; long double t; bool solve(long do... |
#include <bits/stdc++.h> using namespace std; int main() { int n, c, p[55], t[55], x = 0, L = 0, R = 0; cin >> n >> c; for (int i = 0; i < n; i++) { cin >> p[i]; } for (int i = 0; i < n; i++) { cin >> t[i]; } for (int i = 0; i < n; i++) { x += t[i]; L += max(0, p[... |
#include <bits/stdc++.h> using namespace std; long long a[200005], b[200005]; bool cmp(int a, int b) { return a > b; } int main() { long long n; cin >> n; for (int i = 0; i < n; ++i) scanf( %I64d , &a[i]); for (int i = 0; i < n; ++i) scanf( %I64d , &b[i]); for (long long i = 1; i <= n; ++i) ... |
#include <bits/stdc++.h> using namespace std; int main() { int n, t; cin >> n >> t; int x = 0; while (n--) { int z; cin >> z; t -= (86400 - z); ++x; if (t <= 0) { cout << x << endl; return 0; } } } |
#include <bits/stdc++.h> using namespace std; vector<int> vct; void DFS(int d, int num) { if (d == 9) { return; } else { int a = num * 10 + 4; vct.push_back(a); DFS(d + 1, a); int b = num * 10 + 7; vct.push_back(b); DFS(d + 1, b); } } long long calc(int a,... |
#include <bits/stdc++.h> using namespace std; string a = What are you doing at the end of the world? Are you busy? Will you save us? ; string pref = What are you doing while sending ; string suff = ? Are you busy? Will you send ; string last = ? ; long long f[100001]; long long q,... |
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; const long long INF = 1e9 + 8; const long double pi = 3.14159265359; template <class T> T fac(T n) { T res = 1, i; for (i = 2; i <= n; i++) res *= i; return res; } template <class T> T lcm(T a, T b) { return (... |
#include <bits/stdc++.h> using namespace std; int getV(char c) { if (c >= 0 && c <= 9 ) return c - 0 ; if (c >= A && c <= Z ) return 10 + c - A ; if (c >= a && c <= z ) return 36 + c - a ; if (c == - ) return 62; if (c == _ ) return 63; } int main() { string s; cin >> s... |
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; struct edge { int u, v, w; bool operator < (const edge &oth) const { return w < oth.w; } } e[N << 1]; int n, m, x, mn = INT_MAX; long long ans, rem; struct disjoint_sets_union { int fa[N]; int Query(int p) { ... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(nullptr); int n, k, left = 0, i; long long int temp; cin >> n >> k; vector<int> task(k, 0); vector<pair<int, int>> idl(n, make_pair(0, 0)); for (i = 0; i < n; i++) { cin >> temp; ... |
#include <bits/stdc++.h> using namespace std; bool debug = 0; int n, m, k; int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0}; string direc = RDLU ; long long ln, lk, lm; void etp(bool f = 0) { puts(f ? Possible : Impossible ); exit(0); } void addmod(int &x, int y, int mod = 1000000007) { ... |
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) using namespace std; void subMain() { double a, b; cin >> a >> b; cout << fixed << (b * b - a * a) / (2 * a); } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); subMain(); cerr << Time : << 100... |
#include <bits/stdc++.h> #pragma comment(linker, /stack:200000000 ) #pragma GCC optimize( Ofast,no-stack-protector ) #pragma GCC target( avx ) using namespace std; template <class T> int getbit(T s, int i) { return (s >> i) & 1; } template <class T> T onbit(T s, int i) { return s | (T(1) << i... |
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 1; int n, k; int clo[N]; string s; bool block[N]; int dist(int a, int b) { if (a > b) swap(a, b); if (a == -1 || b == n) return n; return min(b - a, n - (b - a)); } char neg(char a) { if (a == W ) return B ; ... |
#include <bits/stdc++.h> using namespace std; struct Node { int v, index; } a[100005]; int n, h, big, small, tmp, diff, num; int ans[100005]; int cmp(const void *i, const void *j) { Node x = *(Node *)i; Node y = *(Node *)j; if (x.v == y.v) { return x.index > y.index ? 1 : -1; } els... |
#include <bits/stdc++.h> using namespace std; const double eps = 1e-8; const double PI = acos(-1.0); const double e = 2.718281828459; const int N = 200000; inline int sgn(double a); inline long long gcd(long long a, long long b); inline long long mod_pow(long long x, long long n, long long mod); vecto... |
#include <bits/stdc++.h> using namespace std; const int Maxn = 1e5 + 1e3 + 2; const int mx = 20; int n, q, N, ans; int k[Maxn]; vector<int> V[Maxn]; vector<pair<int, int>> g; int h[Maxn], par[mx][Maxn]; bool mark[Maxn]; int st[Maxn], en[Maxn], T; set<pair<int, int>> ver, lca; void dfs(int u, int... |
#include <bits/stdc++.h> using namespace ::std; int n, m, k, ans; int a[105][105]; int d[3][105]; int a1[105]; int main() { scanf( %d %d %d , &n, &m, &k); for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) { scanf( %d , &a[i][j]); } ans = 2140000000; if (n > 10) { ... |
#include <bits/stdc++.h> using namespace std; const int N = 1 << 20; long long here[N + 100]; int n, m; long double ter[N + 100]; int go(string &s1, string &s2) { int val = 0; for (int i = int(0); i < int(m); ++i) if (s1[i] == s2[i]) val |= (1 << i); return val; } int main() { ios_... |
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e6; int n, k; int root; vector<int> G[MAXN + 10]; int res = 0; int dfs(int u, int p = -1) { if ((int)G[u].size() == 1) return 0; vector<int> d; for (int v : G[u]) { if (v == p) continue; d.push_back(dfs(v, u) + 1); ... |
#include <bits/stdc++.h> using namespace std; #pragma comment(linker, /STACK:64000000 ) int prec[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; const int mod = 1000000000 + 7; int n, k; long long doIt(int m, int bse) { int b[10]; for (int i = 0; i < 10; i++) b[i] = 0; int res = 0; while (!b[m]) { ... |
#include <bits/stdc++.h> using namespace std; const int MAXN = 100000; int n, a, b; int scores[MAXN], answer[MAXN]; pair<int, int> tmp_scores[MAXN]; void solve() { if (a == b) { for (int i = 0; i < a; ++i) printf( 1 ); for (int i = 0; i < b; ++i) printf( 2 ); printf( n ); retu... |
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; vector<vector<vector<ll>>> v; vector<vector<ll>> mat; vector<vector<ll>> matMal(vector<vector<ll>> mat1, vector<vector<ll>> mat2) { vector<vector<ll>> mat3((int)(mat1).size(), vector<ll>((int)(mat1).size())); ... |
#include <bits/stdc++.h> using namespace std; using pii = pair<int, int>; using ll = long long; pii operator+(pii& p1, pii& p2) { return {p1.first + p2.first, p1.second + p2.second}; } bool isvalidpos(pii& p, int n) { return p.first >= 0 && p.first < n && p.second >= 0 && p.second < n; } int mai... |
#include <bits/stdc++.h> using namespace std; int a[105]; int main() { int i, n, j = 0, k, l; cin >> n; for (i = 0; i < n; i++) { cin >> a[i]; } sort(a + 1, a + n); while (a[0] <= a[n - 1]) { j++; a[n - 1]--; a[0]++; sort(a + 1, a + n); } cout << j << ... |
#include <bits/stdc++.h> using namespace std; int main() { cin.tie(NULL); cout.tie(NULL); ios_base ::sync_with_stdio(false); int n; cin >> n; vector<pair<long long, long long>> news(n + 1); for (int i = 1; i <= n; i++) cin >> news[i].first; for (int i = 1; i <= n; i++) cin >> news[i]... |
#include <bits/stdc++.h> #pragma GCC optimize(2) #pragma GCC optimize(3) #pragma GCC optimize( Ofast ) #pragma GCC optimize( inline ) using namespace std; const long long p = 998244353, g = 3, gv = 332748118, N = 1e6 + 5; long long qpow(long long a, int b) { long long ret = 1; while (b) { if... |
#include <bits/stdc++.h> using namespace std; int arr[1000001], dp[(1 << 22)], N; int main() { scanf( %d , &N); memset(dp, -1, sizeof dp); for (int i = 0; i < N; i++) { scanf( %d , &arr[i]); dp[arr[i]] = arr[i]; } for (int i = 0; i < (1 << 22); i++) { for (int j = 0; j < 22; ... |
#include <bits/stdc++.h> using namespace std; string convert(string s) { int l = s.size(); if (l % 2 == 1) return s; string s1 = s.substr(0, l / 2), s2 = s.substr(l / 2); s1 = convert(s1); s2 = convert(s2); if (s1 < s2) return s1 + s2; else return s2 + s1; } bool equivale... |
#include <bits/stdc++.h> using namespace std; struct answer { int b, c; bool operator==(answer other) const { return b == other.b && c == other.c; } bool operator!=(answer other) const { return !(*this == other); } }; answer eval(string secret, string query) { string left_s, left_q; answer a... |
#include <bits/stdc++.h> using namespace std; const int MAXN = 1000006; long long num[MAXN << 2]; long long sum[MAXN << 2]; long long N; void pushup(int rt) { num[rt] = num[rt << 1] + num[rt << 1 | 1]; sum[rt] = sum[rt << 1] + sum[rt << 1 | 1]; } void update(int P, int C, int l, int r, int rt) {... |
#include <bits/stdc++.h> using namespace std; long long dp[1000000 + 9] = {0}; long long a1[1000000 + 9] = {0}; long long a2[1000000 + 9] = {0}; long long a3[1000000 + 9] = {0}; long long a4[1000000 + 9] = {0}; long long a5[1000000 + 9] = {0}; long long a6[1000000 + 9] = {0}; long long a7[1000000 + 9]... |
#include <bits/stdc++.h> using namespace std; bool comp(int a, int b) { return (a > b); } int gcd(long long int a, long long int b) { if (b == 0) return a; else return gcd(b, a % b); } int main(void) { int n, p; cin >> n >> p; int l[n], r[n], i; long long int c, cp, l1, l2;... |
#include <bits/stdc++.h> using namespace std; using ll = long long int; using pii = pair<int, int>; using pll = pair<ll, ll>; using maxHeap = priority_queue<int>; using minHeap = priority_queue<int, vector<int>, greater<int>>; int main() { ios::sync_with_stdio(0), cin.tie(0); int t, x; double ... |
#include <bits/stdc++.h> using namespace std; int n, m; int const N = 3e5 + 3; int ans[N]; int temp[N]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> m; vector<pair<int, pair<int, int>>> edges; for (int i = (0); i < (m); ++i) { int u, v, w; cin >> u >> v ... |
#include <bits/stdc++.h> using namespace std; using ll = long long; using vi = vector<int>; using vll = vector<ll>; struct vec { ll x; ll y; }; void solve() { ll t, sx, sy, ex, ey; cin >> t >> sx >> sy >> ex >> ey; string s; cin >> s; for (int i = 0, time = 0; i < s.size(); ++i... |
#include <bits/stdc++.h> using namespace std; string str; int main() { cin >> str; int hun, ten, one; if (str.size() == 1) { if (str[0] == 8 || str[0] == 0 ) { cout << YES n ; cout << str << endl; } else cout << NO n << endl; } else if (str.size() == 2) { ... |
#include <bits/stdc++.h> long long n, i, res; using namespace std; int main() { cin >> n; long long a[n]; for (i = 0; i < n; i++) cin >> a[i]; int l = 0, r = n - 1; long long suma = 0, sumb = 0; while (l <= r) { if (suma < sumb) { suma += a[l]; l++; } else { ... |
#include <bits/stdc++.h> int main() { using namespace std; ios_base::sync_with_stdio(false); cin.tie(0); int n, m, k, t; cin >> n >> m >> k >> t; vector<pair<int, int>> w; for (int i = 0, r, c; i < k; i++, w.push_back(make_pair(r, c))) cin >> r >> c; sort(w.begin(), w.end()); const... |
#include <bits/stdc++.h> int mut(int x) { if (x < 0) return -x; else return x; } int d[1000001][2]; int d1[1000001][2]; int main(void) { int ax; int ay; int bx; int by; int cx; int cy; int c = 0; int min = 99999; scanf( %d%d%d%d%d%d , &ax, &ay, &bx, &by,... |
#include <bits/stdc++.h> using namespace std; int q; int h, w, k; int a[600][600]; int dist[17][17]; int dp[17][65539]; int from[17][65539]; int pos[17]; int getdown(int x, int y) { int sum = 0; for (int i = x - 4; i <= x; i++) { for (int j = y - 2; j <= y + 2; j++) { sum += a[i]... |
#include <bits/stdc++.h> #define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) #define int long long int #define double long double #define endl n const int mod = 1000000007; using namespace std; int modExpo(int x , int n) { int ans = 1; while (n > 0) { if ( n & 1 ==... |
#include <bits/stdc++.h> using namespace std; const int N = 2 * 100 * 1000 + 10; string s, t; int d[N]; int LastSeen[N]; void input() { cin >> s >> t; return; } void PrePros() { int keep = (int)(t.size()) - 1, pnt = (int)(s.size()) - 1; while (keep >= 0) { if (s[pnt] == t[keep]) { ... |
#include <bits/stdc++.h> using namespace std; void fastio() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); } void input() {} int main() { fastio(); input(); long long int n; cin >> n; long long int sum = -1; map<long long int, long long int> make_pair; for... |
#include <bits/stdc++.h> using namespace std; double a, b, c, d; int main() { char st = e ; cin >> a >> b >> c >> d; if (a / b == b / c && b / c == c / d) st = g ; if (a - b == b - c && b - c == c - d) st = a ; if (st == e ) cout << 42 << endl; else if (st == g ) { int d1 ... |
#include <bits/stdc++.h> using namespace std; using ll = long long; using db = double; using pii = pair<int, int>; using vi = vector<int>; const int N = 1e5 + 100; int n, d[N], f[N][2], ans; vi G[N]; void dfs(int x, int fz) { f[x][0] = 0, f[x][1] = 1; for (int y : G[x]) if (y != fz) { ... |
#include <bits/stdc++.h> using namespace std; int32_t main() { long long r, g, b; cin >> r >> g >> b; long long ans = 0; long long tr, tg, tb; for (long long i = 0; i <= min({r, g, b, 2LL}); i++) { long long t = i; tr = r; tg = g; tb = b; tr -= i; tg -= i; ... |
#include <bits/stdc++.h> using namespace std; template <class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; } const long long int MO... |
#include <bits/stdc++.h> using namespace std; const long long MOD = (long long)(1e9 + 7); const int inf = (int)INFINITY; const long long INF = (long long)INFINITY; const int MAX = (int)(2e5 + 5); const int maxn = 2e5 + 5; int n, m, k, p[maxn], path[maxn]; vector<int> in[maxn], out[maxn]; int maxa, min... |
#include <bits/stdc++.h> using namespace std; int x[1010], y[1010]; int lef(int x1, int y1, int x2, int y2) { if (x1) x1 = (x1 > 0 ? 1 : -1); if (y1) y1 = (y1 > 0 ? 1 : -1); if (x2) x2 = (x2 > 0 ? 1 : -1); if (y2) y2 = (y2 > 0 ? 1 : -1); if (x1 == 0 && y1 == 1) { if (x2 == 1) ret... |
#include <bits/stdc++.h> using namespace std; char s1[100100], s2[100100]; long long ini; long long mod(long long a) { return ((a % 1000000007LL) + 1000000007LL) % 1000000007LL; } long long func(char* s, int t, bool som) { long long r = 0; long long ul = 0; long long soma = 0, ls = ini; ... |
#include <bits/stdc++.h> using namespace std; long double eps = -1e12; inline bool eq(const long double &x, const long double &y) { return abs(x - y) < eps || abs(x - y) < eps * abs(x); } int main() { long double x, y, z; cin >> x >> y >> z; string expression[12] = { x^y^z , x^z^y , (x^y)^z ... |
#include <bits/stdc++.h> using namespace std; struct Point { double X, Y, Z; void Get() { scanf( %lf%lf%lf , &X, &Y, &Z); } }; Point operator-(Point A, Point B) { return (Point){A.X - B.X, A.Y - B.Y, A.Z - B.Z}; } double operator*(Point A, Point B) { return A.X * B.X + A.Y * B.Y + A.Z * B.Z; } ... |
#include <bits/stdc++.h> struct Candidate { std::vector<int> d; Candidate(std::vector<int> d_) { d = d_; std::sort(d.begin(), d.end()); std::reverse(d.begin(), d.end()); } inline bool operator<(const Candidate &rhs) { if (d[0] < 0 || rhs.d[0] < 0) return d[0] < rhs.d[0]; ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.