func_code_string stringlengths 59 71.4k |
|---|
#include <bits/stdc++.h> using namespace std; const int N = 4e5 + 7; int n, a[N], cnt[N], lim = 0, mx = 0, fa[N]; long long ans = 0; inline int find(int x) { return x == fa[x] ? x : fa[x] = find(fa[x]); } inline void merge(int u, int v, long long w) { if (cnt[u] && cnt[v]) { u = find(u), v = find(... |
#include <bits/stdc++.h> using namespace std; struct vac { int l, r, cost, duration; vac() : cost(-1) {} vac(int l, int r, int cost) : l(l), r(r), cost(cost), duration(r - l + 1) {} }; vector<vector<vac> > lifes(200001, vector<vac>(0)), deaths(200001, vector<vac>(0)); vector<vac> cheapest(20... |
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> arr(n); for (auto &i : arr) cin >> i; int maxx = 0; for (auto i : arr) maxx = max(maxx, i); cout << (maxx xor arr.back()); return 0; } |
#include <bits/stdc++.h> using namespace std; int main() { int N, i, j, p = 0, q = 0, ans = 0; cin >> N; for (i = 0; i < N; i++) { cin >> j; if (q < j) p++; else p = 1; q = j; ans = max(ans, p); } cout << ans << n ; } |
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10, InfI = INT_MAX, Mod = 998244353; const long long InfL = LONG_LONG_MAX; int n, m, sqn; vector<int> adj[N]; vector<int> ind; bool vis[N] = {}, indpen[N] = {}; int ent[N], par[N], back_edge[N], back_min[N]; int dfstimer = 0, idma = 1; ... |
#include <bits/stdc++.h> const double eps = 1e-9; const int int_inf = 2000000000; const long long i64_inf = 1000000000000000000LL; const double pi = acos(-1.0); using namespace std; int wa[1000010]; int wb[1000010]; int a[1000100]; int b[1000100]; int la, lb; int res = 0; int main() { memset... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, m; string s; cin >> n >> m; int a[n][m]; int r[m]; memset(r, 0, sizeof r); for (int i = 0; i < n; i++) { cin >> s; for (int j = 0; j < m; j++) { a[i][j]... |
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 100; int arr[MAXN]; int n, x, t; long long ans; int main() { cin >> n; for (int i = 0; i < n; i++) { cin >> x; if (t <= 1) arr[++t] = x; else { while (t > 1 && arr[t] <= arr[t - 1] && arr[t] <= x) ... |
#include <bits/stdc++.h> using namespace std; inline int gi() { char c = getchar(); while (c < 0 || c > 9 ) c = getchar(); int sum = 0; while ( 0 <= c && c <= 9 ) sum = sum * 10 + c - 48, c = getchar(); return sum; } const int maxn = 100005; int n, a[maxn], cnt[maxn], p[maxn][3], val[... |
#include <bits/stdc++.h> using namespace std; vector<vector<int> > g; vector<int> a, q; vector<char> cl; vector<int> p; map<int, pair<int, int> > y; map<int, pair<int, int> >::iterator it; int cycle_st, cycle_end; long long i, j, n, m, e, k, ot, x, i1, i2, i3, i4, l, r; bool dfs(int v) { cl[v] =... |
#include <bits/stdc++.h> using namespace std; int main() { int t, i, j, count = 0; cin >> t; int a[t], b[t]; for (i = 0; i < t; i++) cin >> a[i] >> b[i]; for (int i = 0; i < t; i++) { int e = 0, f = 0, c = 0, d = 0; for (j = 0; j < t; j++) { if (a[i] < a[j] && b[i] == b[j]) e... |
#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 % m) * (a % m)) % m; b /= 2; a = (... |
#include <bits/stdc++.h> using namespace std; int main() { int W = 0, B = 0, i, h = 64; char z; for (i = 0; i < h; i++) { cin >> z; if (z == Q ) W += 9; if (z == q ) B += 9; if (z == R ) W += 5; if (z == r ) B += 5; if (z == B ) W += 3; if (z == b ) B += 3... |
#include <bits/stdc++.h> int n, m, f, c[150005], p, a, b; long long A; struct odp { long long L, M, R, S; odp() {} odp(long long L, long long M, long long R, long long S) : L(L), M(M), R(R), S(S) {} } t[150005 * 4]; void init(int n, int l, int r) { if (l == r) t[n].L = t[n].R = t... |
#include <bits/stdc++.h> using namespace std; const int maxn = 301; const double eps = 1e-8; struct Segment { double a, b, c; } seg[maxn], sta; struct Point { double x, y; } you, uni; bool calcross(Segment l, Segment sa, Point &ans) { double delta = l.a * sa.b - l.b * sa.a; if (abs(delta... |
#include <bits/stdc++.h> using namespace std; void solve() { long long x, y, a, b; cin >> x >> y >> a >> b; if (2 * a < b) { cout << a * (x + y) << n ; ; return; } else { cout << b * min(x, y) + a * abs(x - y) << n ; ; } } int main() { int t; cin >> ... |
#include <bits/stdc++.h> using namespace std; int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } int main() { int a, b, c, d; scanf( %d%d%d%d , &a, &b, &c, &d); if (a < b) { if (c < d) { if (d * a > b * c) printf( %d/%d n , (a * d - b * c) / gcd(a *... |
#include <bits/stdc++.h> using namespace std; int main() { int tux; cin >> tux; int foo = 0, bar = 0, baz = 0, quz = 1; for (int i = 1; i <= tux; i++) { int pur; cin >> pur; foo += pur; bar = bar + 1; if (foo * quz > baz * bar) { baz = foo; quz = bar; ... |
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s; cin >> s; int h1 = (int)(s[0] - 0 ); int h2 = (int)(s[1] - 0 ); int m1 = (int)(s[3] - 0 ); int m2 = (int)(s[4] - 0 ); if (n == 12) { if (m1 > 5) m1 = 1; if (h1 >= 2) { if... |
#include <bits/stdc++.h> template <typename T, typename U> inline void swap(T &a, U &b) { a = a ^ b; b = a ^ b; a = a ^ b; } inline void swap(int &a, int &b) { a = a ^ b; b = a ^ b; a = a ^ b; } inline void swap(long long &a, long long &b) { a = a ^ b; b = a ^ b; a = a ^ ... |
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e6 + 7; const int MOD = 1e9 + 7; int n; int h[MAXN]; int main() { int m, k, ta, tb; scanf( %d%d%d , &n, &m, &k); for (int i = 1; i <= m; i++) { scanf( %d , &ta); h[ta] = 1; } int cur = 1; if (!h[cur]) f... |
#include <bits/stdc++.h> using namespace std; pair<pair<long long, long long>, long long> merge_p( pair<long long, long long> a, pair<long long, long long> b) { if (a.first > b.first) swap(a, b); if (b.first <= a.second) { if (b.second <= a.second) return make_pair(b, 0); else ... |
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 10; int n; long long a[N]; long long b[N]; int main() { int t; scanf( %d , &t); while (t--) { vector<pair<long long, long long> > v; scanf( %d , &n); v.clear(); for (int i = 0; i < n; i++) { long lo... |
#include <bits/stdc++.h> using namespace std; const int inf = 1e9; const int N = 500010; int n, m, a[N], b[N], cnt[N], c[N]; long long ans; bool f; void update_ans(long long val) { if (ans == -1) ans = val; else if (ans != val) f = false; } void check(int s, int d) { for (int i... |
#include <bits/stdc++.h> using namespace std; int n, step; vector<string> ans; bool isi[256]; int now[26]; string eb(int p) { return string( e ) + char(p + a ) + x ; } string sz(int p) { return string( ) + char(p + 0 ); } void dfs(int x) { if (x == step) { if (isi[n]) { printf( %d ... |
#include <bits/stdc++.h> using namespace std; const int N = (1 << 18); int xtoy[N], ytox[N]; set<int> sx, sy; int tr[2][N * 2]; void change(int c, int x, int v) { x = x + N; tr[c][x] = v; while (x > 1) { x /= 2; tr[c][x] = max(tr[c][x * 2], tr[c][x * 2 + 1]); } } int get_max(... |
#include <bits/stdc++.h> using namespace std; int n, s, a, b, c, p, x, y, k, f, ans[4]; int gcd(int x, int y) { if (x == 0 || y == 0) return x + y; if (x < y) swap(x, y); return gcd(y, x % y); } int main() { scanf( %d%d , &n, &s); for (int i = 1; i <= n; i++) { scanf( %d , &p); ... |
#include <bits/stdc++.h> using namespace std; const int H_MAX = 100100; const int N_MAX = 200100; int H, N; int layers[H_MAX]; int tree1[N_MAX]; int tree2[N_MAX]; int main() { N = 0; cin >> H; for (int i = 0; i <= H; i++) { cin >> layers[i]; N += layers[i]; } assert(layer... |
#include <bits/stdc++.h> using namespace std; int n, m, a[1010], s; long long pw[1010], c[1010][1010], ans = 1; int main() { pw[0] = pw[1] = 1; for (int i = 2; i < 1010; i++) pw[i] = 2 * pw[i - 1] % 1000000007; for (int i = 0; i < 1010; i++) for (int j = 0; j <= i; j++) c[i][j] = ((!i ... |
#include <bits/stdc++.h> using namespace std; const long long INF = 9e18; const long long MOD = 1e9 + 7; const long long mod = 998244353; void fileio() {} int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; fileio(); long long tc; cin >> tc; while (tc--) { ... |
#include <bits/stdc++.h> int g[102][102]; int main() { int n, t, sum = 0; scanf( %d , &n); t = n / 2; for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) scanf( %d , &g[i][j]); for (int i = 0; i < n; ++i) sum += g[i][i] + g[i][n - i - 1] + g[t][i] + g[i][t]; sum -= 3 * g[t][t... |
#include <bits/stdc++.h> using namespace std; vector<int> v[300010]; int centroid[300010], Next[300010], par[300010], sz[300010]; void dfs(int cur) { sz[cur] = 1; int maxx = 0; Next[cur] = 0; for (int u : v[cur]) if (u != par[cur]) { dfs(u); sz[cur] += sz[u]; if (sz... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); int n; cin >> n; int a = 1, b = n * n; for (int i = 1; i <= n; i++) { for (int j = 1; j <= n / 2; j++) { if (j > 1) cout << ; cout << a << << b; a++, b--; } c... |
#include <bits/stdc++.h> using namespace std; const int UNDEF = -1; template <typename T> inline bool chkmax(T &a, T b) { return a < b ? a = b, true : false; } template <typename T> inline bool chkmin(T &a, T b) { return a > b ? a = b, true : false; } const int INF = 1ULL << 28ULL; const int... |
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 10; inline int read() { char c = getchar(); int x = 0, f = 1; while (c < 0 || c > 9 ) { if (c == - ) f = -1; c = getchar(); } while (c >= 0 && c <= 9 ) x = x * 10 + c - 0 , c = getchar(); return x * f;... |
#include <bits/stdc++.h> using namespace std; const double eps = 1e-10, pi = acos(-1.0); int main() { int n, t = 1; while (t--) { double a, b, x, y, v; double ans = 1000000000.00; cin >> a >> b; cin >> n; for (int i = 0; i < n; i++) { cin >> x >> y >> v; doubl... |
#include <bits/stdc++.h> using namespace std; int n, m, sx, sy, ma[1005][1005], vis[1005][1005], ans, t, tot = 99999999; int dx[5] = {1, -1, 0, 0}; int dy[5] = {0, 0, 1, -1}; char maa[1005][1005]; void bfs(int u, int v) { queue<int> qx; queue<int> qy; queue<int> qt; qx.push(u), qy.push(v), q... |
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1); const double eps = 1e-12; const int inf = 2000000000; const long long int infLL = (long long int)1e18; long long int MOD = 1000000007; int MOD1 = 1000000007; int MOD2 = 1000000009; inline bool checkBit(long long int n, long long... |
#include <bits/stdc++.h> using namespace std; int main() { long long k, a, b; cin >> k >> a >> b; long long k1, k2, r1, r2; if (a >= 0) { k1 = a / k; r1 = a % k; } else { k1 = a / k; r1 = a % k; if (r1) { k1 -= 1; r1 += k; } } if (b >= ... |
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 10, T = 3010, size = 1 << 20, mod = 998244353, inf = 2e9; const long long INF = 1e15; template <class o> void qr(o &x) { char c = getchar(); x = 0; int f = 1; while (!isdigit(c)) { if (c == - ) f = -1; c = getchar()... |
#include <bits/stdc++.h> using namespace std; int a, b, c, d, e; int main() { scanf( %d%d%d%d%d , &a, &b, &c, &d, &e); cout << min(a, min(b, min(c / 2, min(d / 7, e / 4)))); return 0; } |
#include <bits/stdc++.h> using namespace std; long long n, m, d; long long dp[150005][5]; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cin >> n >> m >> d; long long pt; long long prev, curr; for (long long i = 0; i < m; i++) { long long a,... |
#include<bits/stdc++.h> #define int long long using namespace std; inline int read() { char c = getchar(); int x = 0, f = 1; while (c < 0 || c > 9 ) { if (c == - ) f = -1; c = getchar(); } while (c >= 0 && c <= 9 ) { x ... |
#include <bits/stdc++.h> using namespace std; long n, m, k, c = 1, s = 1; int main() { cin >> n >> m >> k; m -= n; while (m > 0) { if (k - c >= 1) s++; if (k + c <= n) s++; m -= s; c++; } cout << c; return 0; } |
#include <bits/stdc++.h> #pragma comment(linker, /stack:200000000 ) #pragma GCC optimize( Ofast ) #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native ) using namespace std; void fast() { std::ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); } int main() { ... |
#include <bits/stdc++.h> int main() { char a[110], b[110]; scanf( %s , a); getchar(); scanf( %s , b); int len = strlen(a); for (int i = 0; i < len; i++) { if (a[i] < b[i]) { printf( -1 ); return 0; } } for (int i = 0; i < len; i++) { if (a[i] == b[i]) ... |
#include <bits/stdc++.h> using namespace std; long long n, m; vector<long long> a; vector<long long> res; int main() { scanf( %I64d , &n); for (long long i = 1; i <= n; ++i) { scanf( %I64d , &m); for (long long j = 0; j < m; ++j) { a.push_back(i); } } scanf( %I64d , &... |
#include <bits/stdc++.h> using namespace std; long long t, n, y, i, j, a[5001]; int main() { cin >> t; for (j = 1; j <= t; j++) { cin >> n; y = -1; cin >> a[1]; for (i = 2; i <= n; i++) { cin >> a[i]; if (y == -1) { if (a[1] != a[i]) y = i; } ... |
#include <bits/stdc++.h> using namespace std; int q; long long n; int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin >> q; while (q--) { cin >> n; int res = 0; while (n != 1) { if (n % 2 == 0) { n /= 2; res++; } ... |
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e18; const long long N = 2e5 + 33; void solve() { int64_t n; cin >> n; vector<int64_t> v(n + 1); for (int64_t i = 0; i < n; i++) { cin >> v[i]; } vector<int64_t> ans(n + 10, 0); for (int64_t i = 0; i < n; i++)... |
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int L[n]; for (int i = 0; i < n; ++i) scanf( %d , &L[i]); int imos[n + 1]; fill(imos, imos + n + 1, 0); for (int i = 0; i < n; ++i) { L[i] = min(L[i], i); ++imos[i - L[i]]; --imos[i]; } ... |
#include <bits/stdc++.h> using namespace std; const long long inf = 4e+18; const int N = 100010; struct rec { long long a, b, c; }; int cas, n; long long x[N], y[N], z[N]; rec get(long long la, long long ra, long long lb, long long rb, long long lc, long long rc, long long labc, long long ... |
#include <bits/stdc++.h> using namespace std; const int maxn = 100010; vector<int> v; map<int, int> mp; int main() { ios::sync_with_stdio(0); int T; cin >> T; while (T--) { string s1, s2; cin >> s1 >> s2; reverse(s1.begin(), s1.end()); reverse(s2.begin(), s2.end()); ... |
#include <bits/stdc++.h> using namespace std; int main() { int n, i, c = 0; string s; cin >> n >> s; for (i = 0; i < n; i++) { if (s[i] == s[i + 1]) { c++; } } cout << c; return 0; } |
#include <bits/stdc++.h> using namespace std; const long long inf = 1e18; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long n, x, y, s1, s2, i, j, a, b, c, r = 0; cin >> n >> s1 >> s2; long long x1[n + 1], x2[n + 1], y1[n + 1], y2[n + 1]; for (i = 1; i <... |
#include <bits/stdc++.h> int arr[101]; int N; int min = 999999999; int memo[101][3]; int findMin(int idx, int prev) { int min_Rest = 999999999; if (idx == N + 1) return 0; if (memo[idx][prev] != -1) return memo[idx][prev]; if (prev != 1 && (arr[idx] == 1 || arr[idx] == 3)) min_Rest = ((m... |
#include <bits/stdc++.h> using namespace std; bool debug = false; int n, m, k; int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0}; long long a[305]; int pt[20]; int main() { scanf( %d , &n); for (int(i) = 0; (i) < (int)(n); (i)++) scanf( %lld , a + i + 1); long long ans = 0; int t; pt[0]... |
#include <bits/stdc++.h> using namespace std; int main() { int q; cin >> q; while (q--) { int a, b, c; cin >> a >> b >> c; int temp = min(a, b); if (temp * 3 <= a + b + c) { cout << temp << endl; continue; } else { cout << (a + b + c) / 3 << endl; ... |
#include <bits/stdc++.h> using namespace std; int main() { string s, t; cin >> s >> t; string ans; long cnt = 0; for (long i = 0; i < s.size(); i++) { if (s[i] == t[i]) ans += 1 ; else { if (cnt % 2) ans += s[i]; else ans += t[i]; ... |
#include <bits/stdc++.h> using namespace std; template <typename A, typename B> string to_string(pair<A, B> p); template <typename A, typename B, typename C> string to_string(tuple<A, B, C> p); template <typename A, typename B, typename C, typename D> string to_string(tuple<A, B, C, D> p); string to_str... |
#include <bits/stdc++.h> using namespace std; vector<int> v[2 * 100001]; int color[2 * 100001]; void dfs(int s, int p, int clr, int pclr) { color[s] = clr; int y = 1; for (int i = 0; i < v[s].size(); i++) { int u = v[s][i]; if (u == p) continue; while (y == clr || y == pclr) { ... |
#include<bits/stdc++.h> using namespace std; int main() { long long int t; cin>>t; while(t--) { long long int i,j,k,l,m,n,c1=0,c2=0,ans=0,res=0; map<long long int,long long int>mp,mp1; vector<long long int>v,v1,v2; set<long long int>st,st1; ... |
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; s = 00 + s; int l = s.length(); int fi = 0, fj = 0, i, j, k, num; for (i = 0; i < l; i++) { for (j = i + 1; j < l; j++) { for (k = j + 1; k < l; k++) { num = 100 * (s[i] - 0 ) + 10 * (s[... |
#include <bits/stdc++.h> using namespace std; long long power(long long a, long long n, long long lelo) { if (n == 0) return 1; if (n == 1) return a; if (n == 2) return (a * a) % lelo; if (n % 2) return (a * power(a, n - 1, lelo)) % lelo; else return power(power(a, n / 2, lelo), 2, l... |
#include <bits/stdc++.h> using namespace std; const int N = 500005; struct node { char s[10]; int len, i, v, num, ty; } p[N], q[3][N]; int n, vst[N], tot = 0, s[3] = {0}; int f[3][N] = {0}; struct data { char s[10]; int ty, c[2], len; } ans[N]; int F(char s[10]) { int i, ad = 0; ... |
#include <bits/stdc++.h> using namespace std; bool cmp_vector(const vector<int>& a, const vector<int>& b) { int i; for (i = 0; i < a.size(); i++) { if (a[i] > b[i]) { return false; } else if (a[i] < b[i]) { return true; } } return false; } int main() { int h... |
#include <bits/stdc++.h> using namespace std; const int MAXN = (int)5e5 + 5; vector<int> edges[MAXN]; int n; int l[MAXN]; int r[MAXN]; int cur = 2; void go(int node, int p = 0) { int tt = 0; for (int i : edges[node]) { if (i == p) continue; tt++; } r[node] = cur + tt; int... |
#include <bits/stdc++.h> using namespace std; FILE* in = stdin; FILE* out = stdout; const int MAX = 2002; int n, k; char a[MAX]; void solve() { vector<pair<int, int> > ans; int idx = 0; while (k > 1) { if (a[idx] != ( ) { int nxt = idx + 1; while (a[nxt] != ( ) nxt++; ... |
// Omar_Elaraby #include <bits/stdc++.h> using namespace std; typedef long long ll; #define EPS 1e-9 int main() { ios::sync_with_stdio(false); cin.tie(0), cout.tie(0); // freopen( in.txt , r , stdin); // freopen( out.txt , w , stdout); int tt; cin >> tt; while (tt--) { long long... |
#include <bits/stdc++.h> using namespace std; const int maxn = 110; int n, m, z; int mapp[maxn][maxn][maxn]; bool vis[maxn][maxn][maxn]; string s; int main() { int ans = 0, num; memset(vis, false, sizeof(vis)); memset(mapp, 0, sizeof(mapp)); scanf( %d%d%d , &n, &m, &z); for (int i = 1;... |
#include <bits/stdc++.h> using namespace std; const int OO = 1e9; const double EPS = 1e-9; template <class T> void _db(const char* dbStr, T e) { cout << dbStr << = << e << endl; } template <class T, class... L> void _db(const char* dbStr, T e, L... r) { while (*dbStr != , ) cout << *dbStr++... |
#include <bits/stdc++.h> using namespace std; int main() { int q; cin >> q; for (int j = 0; j < q; j++) { int n; long long int k; cin >> n >> k; long long int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } sort(a, a + n); long long int mi, ma; ... |
#include <bits/stdc++.h> using namespace std; using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>; using ll = long long; using vll = vector<ll>; using vvll = vector<vll>; using vvvll = vector<vvll>; using ull = unsigned long long; using vb = vector<bool>; using vvb = vector<vb... |
#include <bits/stdc++.h> using namespace std; int N; signed long long mo = 1000000007; signed long long ret = 1; signed long long from[303][303]; signed long long to[303][303]; signed long long combi(int P_, int Q_) { static const int N_ = 1020; static signed long long C_[N_][N_]; if (C_[0][0]... |
#include <bits/stdc++.h> using namespace std; const int N = 52; struct node { int v, w, nxt; } e[N << 1]; int s, n, m, first[N], cnt = 1, siz[N], de[N]; inline void add(int u, int v, int w) { e[++cnt].v = v; e[cnt].w = w; e[cnt].nxt = first[u]; first[u] = cnt; ++de[u]; } inline v... |
#include <bits/stdc++.h> using namespace std; struct chip { char dir; chip *u, *r, *d, *l; chip(char _dir) { dir = _dir; u = r = d = l = NULL; } }; int main(int argc, char* argv[]) { int n, m; cin >> n >> m; chip*** t; t = (chip***)malloc(n * sizeof(chip**)); for ... |
#include <bits/stdc++.h> using namespace std; long long n, m, ans, c, d; int a[1005][1005], b[1005][1005]; string s[1003]; int main() { cin >> n >> m; for (int i = 0; i < n; i++) { cin >> s[i]; } for (int i = 0; i < n; i++) { d = 0; for (int j = 0; j < m; j++) { if (s... |
#include <bits/stdc++.h> using namespace std; const int N_MAX = 102; const int K_MAX = 10002; const int MOD = 1e9 + 7; int pwr(int a, long long b) { if (b == 0) return 1; if (b & 1) return 1LL * a * pwr(a, (b ^ 1)) % MOD; int aux = pwr(a, (b >> 1)); return 1LL * aux * aux % MOD; } int n, k... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); int n; cin >> n; vector<int> A(n + 7); for (int i = 1; i <= n; i++) cin >> A[i]; vector<int> B(n); for (int i = 1; i <= n; i++) B[i - 1] = i; sort(B.begin(), B.end(), [&](int a, int b) { return A... |
#include <bits/stdc++.h> using namespace std; const long long int MOD = (long long int)1e9 + 7; long long int powmod(long long int a, long long int b) { long long int res = 1; while (b > 0) { if (b & 1) res = (res * a) % MOD; a = (a * a) % MOD; b = b >> 1; } return res % MOD; }... |
#include <bits/stdc++.h> using namespace std; struct Update { int cost, profit; Update(int cost, int profit) : cost(cost), profit(profit) {} }; struct CommutativeUndoableDS { const int MAX_COST = 4000; vector<vector<int> > stk; CommutativeUndoableDS() { stk.emplace_back(MAX_COST + 1, 0); } ... |
#include <bits/stdc++.h> using namespace std; #pragma comment(linker, /STACK:200000000 ) const double EPS = 1E-9; const int INF = 1000000000; const long long INF64 = (long long)1E18; const double PI = 3.1415926535897932384626433832795; string s[110000]; int n, k, z[110][110], dp[1100000]; char buf[11... |
#include <bits/stdc++.h> #pragma comment(linker, /STACK:66777216 ) using namespace std; template <typename TT, int V, int E> struct DinicFlow { int ds[V + 1], q[V + 1], nx[E + 1], last[V + 1], ver[E + 1], now[V + 1], n, edgesCount, S, T; TT cap[E + 1], flow[E + 1]; DinicFlow() : n(0), S(0),... |
#include <bits/stdc++.h> using namespace std; vector<int> adj[3010], vert; map<int, vector<pair<int, int> > > query[3010]; int ans[400010], vis[3010], in_cycle; void dfs(int v, int par) { vis[v] = 1; if (!in_cycle) vert.push_back(v); if (query[par].count(v)) { vector<pair<int, int> > *ptr = ... |
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 9; int arr[maxn], ar[maxn]; int main() { int a, b, c, d, e, f, g, h; while (cin >> a) { cin >> e >> f; for (int i = 1; i <= a; i++) { cin >> arr[i]; } for (int i = 1; i <= a; i++) { cin >> ar[i];... |
#include <bits/stdc++.h> using namespace std; const int maxm = 6e5 + 5; int l[maxm], r[maxm]; int c[maxm]; int pos[maxm]; int n, m; int max(int a, int b) { if (a > b) return a; else return b; } int lowbit(int i) { return i & -i; } void add(int i, int t) { while (i < maxm) { ... |
#include <bits/stdc++.h> using namespace std; template <typename T> int size(T& a) { return (int)a.size(); } template <typename T> T sqr(T a) { return a * a; } int offset; int f[1000000 * 4 + 10]; int start[27]; int getmask(int l, int r) { int res = 0; for (l += offset, r += offset... |
#include <bits/stdc++.h> using namespace std; string g[51]; int pre[52][52]; int dp[51][51][51][51]; bool chk(int x1, int x2, int y1, int y2) { int r = pre[x2][y2] - pre[x1][y1 - 1] - pre[x1 - 1][y1] + pre[x1 - 1][y1 - 1]; if (r >= 1) return true; return false; } int fun(int r1, int r2, int c1... |
#include<bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define ff first #define ss second #define mod 1000000007 #define t5 100005 #define inf 100000000000000000 ll ask(ll t,ll i,ll j , ll x){ cout << ? << t << << i << << j << << x << endl; ll temp; ... |
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf( %d , &n); vector<pair<int, int>> a(n); vector<int> diff(n), dp(n + 1), take(n + 1); for (int i = 0; i < n; i++) scanf( %d , &a[i].first), a[i].second = i; sort(a.begin(), a.end()); if (n < 6) { cout << a[n - 1... |
#include <bits/stdc++.h> using namespace std; long long a[35], b[35], k[35], p[35]; long long n, u, r, ans; void op1() { for (int i = 0; i < n; i++) a[i] = a[i] ^ b[i]; } void op2() { long long tmp[35]; for (int i = 0; i < n; i++) tmp[i] = a[p[i]] + r; for (int i = 0; i < n; i++) a[i] = tmp[... |
#include <bits/stdc++.h> using namespace std; const int N = 5e5 + 2, K = 102, P = 102; int dp[3][K][P], a[N], mn[N][K], pre[N]; int main() { ios::sync_with_stdio(), cin.tie(0), cout.tie(0); int n, k, p; cin >> n >> k >> p; for (int i = 0; i < n; i++) { cin >> a[i]; a[i] %= p; } ... |
#include <bits/stdc++.h> using namespace std; const long long inf = 1e10, mpow = 33, N = 1e5, M = 1e3; vector<int> prime; int nt[N + 10]; void sieve() { for (int i = 2; i <= N; i++) if (!nt[i]) { prime.push_back(i); for (int j = i * 2; j <= N; j += i) nt[j] = 1; } } string ... |
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; template <typename T> ostream& operator<<(ostream& out, vector<T> v) { out << { ; for (size_t i = 0; i < v.size(); ++i) out << (i == 0 ? : , ) << v[i]; return out << } ; } template <typename Arg1> void myPrint(const ... |
#include <bits/stdc++.h> using namespace std; int ar[1000009]; int main() { long long a, s, d, f, g, h, j, k, l; cin >> a; k = 0; for (s = 1; s <= a; s++) { scanf( %d , &ar[s]); if (ar[s]) k++; } d = 0; l = 0; for (s = 1; s <= a; s++) { if (ar[s] == 1) { d... |
#include <bits/stdc++.h> using namespace std; int main() { int a, b, count, area; cin >> a >> b; area = a * b; if (area < 2) cout << 0 << endl; else { while (area >= 2) { count++; area -= 2; } cout << count << endl; } return 0; } |
#include <bits/stdc++.h> using namespace std; long long int n, m; vector<long long int> a[200005]; long long int rankof[200005]; long long int parentof[200005]; long long int maxof[200005]; void initialize() { for (long long int i = 0; i <= 200005; i++) { rankof[i] = 1; parentof[i] = i; ... |
#include <bits/stdc++.h> using namespace std; template <typename P, typename Q> ostream& operator<<(ostream& os, pair<P, Q> p) { os << ( << p.first << , << p.second << ) ; return os; } template <typename P, typename Q> istream& operator>>(istream& is, pair<P, Q>& p) { is >> p.first >> p.sec... |
#include <bits/stdc++.h> using namespace std; const int N = 1e6; int L[N], R[N], sp[N], levsp[30], lev[N]; long long val[N], a[N]; void lazyUpdate(int node) { if (!L[node]) return; if (sp[node] ^ levsp[lev[node]]) { swap(L[node], R[node]); sp[node] ^= 1; } } long long build(int nod... |
#include <bits/stdc++.h> using namespace std; int a[100500]; vector<int> gr[100500]; int n, m, s, k; int res[100500][101]; int d[100500]; int q[100500]; int A[100500]; int B[100500]; int sz[100500]; int main() { scanf( %d %d %d %d , &n, &m, &k, &s); for (int i = 1; i <= n; ++i) { sca... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.