func_code_string stringlengths 59 71.4k |
|---|
#include <bits/stdc++.h> using namespace std; int x[55], y[55]; int main(int argc, char** argv) { int n; scanf( %d , &n); for (int i = 1; i <= n; i++) scanf( %d , &x[i]); for (int i = 1; i <= n; i++) scanf( %d , &y[i]); int sum = 0; for (int i = 1; i <= n; i++) { sum += x[i] - y[i]; ... |
#include <bits/stdc++.h> using namespace std; template <class T> void read(T &x) { T res = 0, f = 1; char c = getchar(); while (!isdigit(c)) { if (c == - ) f = -1; c = getchar(); } while (isdigit(c)) { res = (res << 3) + (res << 1) + c - 0 ; c = getchar(); } x... |
#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; template <class L, class R> ostream &operator<<(ostream &os, pair<L, R> P) { return os << ( << P.first << , << P.second << ) ; } template <class T> ostream &operator<<(ostream &os, vector<T> V) { os << [ ; for (auto vv : V) os << vv << , ; ... |
#include <bits/stdc++.h> using namespace std; int main() { int i, n, a, j, b, m, s = 0, t = 0; int x[105] = {0}; cin >> n >> m; for (i = 1; i <= m; ++i) { cin >> a; for (j = a; j <= n; ++j) { if (x[j] != 0) break; x[j] = a; } } for (i = 1; i <= n; ++i) cout ... |
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e5 + 100; const int MAXM = 15; int N, Q, M; int log2(int v) { int r = 1; while (v >>= 1) r++; return r; } int a[MAXN]; int t[2][MAXN]; struct ST { int v[3 * MAXN][2][MAXM]; int l[3 * MAXN], r[3 * MAXN]; bool lz[3 *... |
#include <bits/stdc++.h> const int N = (int)2e5 + 5; const int MOD = (int)1e9 + 7; const bool MULTI_TEST = true; const double PI = acos(-1.0); using namespace std; void solve() { int n; cin >> n; int a[n]; int max = 0, index = -1; for (int i = 0; i < n; i++) { cin >> a[i]; if... |
#include <bits/stdc++.h> using namespace std; long long a[100500], c[300], dp[100500][305], z, cnt, tmp, e, s, l, r, n, m, x, y, k, j, p, k1, k2, i, cur, rez; vector<long long> f[100500]; long long Abs(long long x) { if (x < 0) return -x; return x; } int main() { cin >> n >> m >> s >> e; ... |
#include <bits/stdc++.h> using namespace std; struct data { float x, a; } h[1005]; bool cmp(data a, data b) { return a.x < b.x; }; int main() { int n, ans = 2; float t, d; cin >> n >> t; for (int i = 1; i <= n; i++) cin >> h[i].x >> h[i].a; sort(h + 1, h + n + 1, cmp); for (int i =... |
#include <bits/stdc++.h> using namespace std; int n; int main() { cin >> n; int ans = 0; if (n % 2 == 0) { ans = 3 * (n / 2); } else { ans = 3 * (n / 2) + 1; } cout << ans << endl; for (int i = 1; i <= n; i++) { if (!(i % 2)) cout << i << ; } for (int i = 1... |
#include <bits/stdc++.h> using namespace std; template <typename T> using minpq = priority_queue<T, vector<T>, greater<T>>; const int N = 5e5 + 5; int n; long long a[N], x; int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> n; for (int i = (0); i < ((n + 1) / 2); i++) cin >> a[i]... |
#include <bits/stdc++.h> const long long Inf = 1e18; const long double eps = 1e-7; long long LINF = (long long)2e18; using namespace std; long long mod = 1e9 + 7; long long mod5 = 1e9 + 9; long long mod3 = 998244353; long long mod4 = 1000003; long long mod2 = 1e9 + 123; const int MAXN = 10100000; ... |
#include <bits/stdc++.h> using namespace std; long long M = 1000000007; int main() { int n, x, y; cin >> n >> x >> y; string s; cin >> s; int ans = 0; for (int i = 0; i < x; i++) { int pos = n - i - 1; char current = 0 ; if (i == y) { current = 1 ; } ... |
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 10, OO = 0x3f3f3f3f; int dx[] = {1, 0, -1, 0}; int dy[] = {0, 1, 0, -1}; int tc, n, m; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); string s; cin >> tc; while (tc--) { cin >> n >> m; ... |
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; int a[N]; int sum[11]; int main() { int n; cin >> n; for (int i = 1; i <= n; ++i) { scanf( %d , &a[i]); sum[a[i]]++; } while (1) { int i, aa[11]; memset(aa, 0, sizeof(aa)); for (i = 1; i < 1... |
#include <bits/stdc++.h> using namespace std; template <class T> bool umin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } template <class T> bool umax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } long long a, b, c, type, ric[300007], ... |
#include <bits/stdc++.h> using namespace std; inline int in() { int32_t x; scanf( %d , &x); return x; } inline string get() { char ch[1000010]; scanf( %s , ch); return ch; } const int MAX_LG = 60; const long long maxn = 1e6 + 100; const long long base = 29; const long long mod ... |
#include <bits/stdc++.h> using namespace std; long long modulo(long long base, long long exponent, long long modulus); long long choose(long long n, long long k); long long inverse(long long a, long long m); void build(); void fileio(); long long ncr(long long n, long long r); const int nax = 1e6 + 10; ... |
#include <bits/stdc++.h> using namespace std; vector<int> g[100500]; int c[100500]; int n; bool vis[100500]; bool dfs(int u, int cu) { if (vis[u]) return 0; vis[u] = 1; bool r = 0; if (c[u] != cu) return 1; for (int v : g[u]) r |= dfs(v, cu); return r; } int main() { scanf( %... |
#include <bits/stdc++.h> using namespace std; int n, m; int a[105][105]; int main() { scanf( %d %d , &n, &m); if (n + m == 3 or n + m == 4) printf( -1 n ); else { int num = 2; if (n >= m) { for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) { if... |
#include <bits/stdc++.h> using namespace std; const inline int __GET_INT() { int ret; scanf( %d , &ret); return ret; } const int maxn = 2002; int n, m; char grid[maxn][maxn]; int dx[] = {-1, -1, -1, 0, 0, 1, 1, 1}; int dy[] = {-1, 0, 1, -1, 1, -1, 0, 1}; int cntStar(int r, int c) { ret... |
#include <bits/stdc++.h> using namespace std; long long a[200005]; int b[200005]; int n, k, Q; long long ans; int l, r; int main() { scanf( %d , &Q); while (Q--) { scanf( %d%d , &n, &k); for (int i = 1; i <= n; i++) scanf( %lld , &a[i]); for (int i = 1; i <= k; i++) scanf( %d , &... |
#include <bits/stdc++.h> using namespace std; long long max(long long a, long long b) { if (a > b) return a; return b; } long long min(long long a, long long b) { if (a < b) return a; return b; } const int MOD = 1e9 + 7, N = 102, L = 3005, INF = INT_MAX; pair<long long, long long> a[N]; ... |
#include <bits/stdc++.h> using namespace std; const int M = 11, N = 2e5 + 5; int n, k; int a[N]; map<int, int> rem[M]; long long solve() { long long ans = 0; for (int i = 0; i < n; ++i) { unsigned long long f = 10; int ln = ((int)(to_string(a[i])).size()); for (int l = 1; l < M; ++... |
#include <bits/stdc++.h> using namespace std; int main() { long long n, k, x; cin >> n; for (long long i = 0; i < n; i++) { cin >> k >> x; cout << x + (k - 1) * 9 << endl; } } |
#include <bits/stdc++.h> using namespace std; const int maxn = 5e5 + 5; int main() { long long v, w1, w2, v1, v2; cin >> v >> w1 >> w2 >> v1 >> v2; long long x = max(v1, v2); if (x * x >= v) { if (v1 < v2) swap(v1, v2), swap(w1, w2); long long ans = 0; for (int i = 0; i <= v / v1... |
#include <bits/stdc++.h> const int mod = 1000000007; const int inf = 1000000009; const long long INF = 1000000000000000009; const long long big = 1000000000000000; const long double eps = 0.000000000000000000001; using namespace std; const int M = 100000; int W[M + 5], U[M + 5], cnt[M + 5]; vector<int... |
#include <bits/stdc++.h> using namespace std; int a, b, sum, x; int main() { cin >> a >> b; while (a) { sum += a; x += a % b; a /= b; a += x / b; x %= b; } cout << sum; return 0; } |
#include <bits/stdc++.h> using namespace std; long long n, arr[500010], temp, j, i, ans; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n; for (long long i = 0; i < n; i++) { cin >> arr[i]; }; sort(arr, arr + n); i = 0, j = n / 2; ans = n; w... |
#include <bits/stdc++.h> using namespace std; int l[210000], r[210000]; vector<pair<int, int> > v; int n, m, k; int mp[1000]; int lbit[1000]; int dp[210000][300]; int msk[210000]; int main() { for (int i = 0; i < 210000; i++) for (int j = 0; j < 300; j++) dp[i][j] = -0x3f3f3f3f; dp[0][0]... |
#include <bits/stdc++.h> using namespace std; const int mod = 998244353; const int N = 3005; int n, c, a[N], dp[N][N], g[N][N], freq[N], mul[N], imul[N], pw[N], cnt[N]; int dp2[2][N][1 << 12]; int inverse(int n) { if (n == 1) return 1; return inverse(mod % n) * 1LL * (mod - mod / n) % mod; } inl... |
#include <bits/stdc++.h> using namespace std; int ans[101000], mark[101000]; char s[101000]; int n, top, now, n_; int main() { do s[++n_] = getchar(); while (s[n_] != = ); scanf( %d , &n); mark[1] = 0; top = 1; for (int i = 3; i < n_; i += 4) mark[++top] = (s[i] == - ); now = 0; ... |
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const int maxn = 4e5 + 5; long long a[maxn], f[maxn], d[maxn]; int q[maxn]; int main() { int n, i, j, l, r; long long c; scanf( %d%lld , &n, &c); for (i = 1; i < (n << 1); i++) { scanf( %lld , &a[i]); a[i] += ... |
#include <bits/stdc++.h> template <typename T> std::istream& operator>>(std::istream& input, std::vector<T>& v) { for (T& a : v) input >> a; return input; } void answer(bool v) { constexpr const char* s[2] = { NO , YES }; std::cout << s[v] << n ; } void solve(const std::vector<unsigned>& ... |
#include <bits/stdc++.h> using namespace std; void __print(int x) { cerr << x; }; void __print(long x) { cerr << x; }; void __print(long long x) { cerr << x; }; void __print(unsigned x) { cerr << x; }; void __print(unsigned long x) { cerr << x; }; void __print(unsigned long long x) { cerr << x; }; void ... |
/** * author: Ujjwal Tripathi * created: 15.04.2021 18:04:04 **/ #include<bits/stdc++.h> using namespace std; #define ar array<ll, 2> #define ll long long #define in insert #define pb push_back #define pii pair<ll,ll> #define vt vector #define P_Q(x) priority_queue<x> #... |
#include <bits/stdc++.h> using namespace std; int a[200010], b[200010], n, cnt = 0; int main() { ios::sync_with_stdio(0); cin >> n; for (int i = 2; i <= n; i++) cin >> a[i]; for (int tmp = n; tmp; tmp = a[tmp]) b[++cnt] = tmp; reverse(b + 1, b + cnt + 1); for (int i = 1; i <= cnt; i++) cou... |
#include <bits/stdc++.h> using namespace std; int main() { cin.tie(0); cin.sync_with_stdio(0); int t; long long n; cin >> t; for (int i = 0; i < t; i++) { cin >> n; cout << (-1 * n) + 1 << << n << n ; } } bool sortbysec(const pair<int, int> &a, const pair<int, int> ... |
#include <bits/stdc++.h> using namespace std; const int seed = 131; const long long LLMAX = 2e18; const int MOD = 1e9 + 7; const double eps = 1e-8; const int MAXN = 1e5 + 10; const int hmod1 = 0x48E2DCE7; const int hmod2 = 0x60000005; inline long long sqr(long long x) { return x * x; } inline int sq... |
#include <bits/stdc++.h> using namespace std; long long poww(long long a, long long b, long long md) { return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md)); } const long long MAXN = 1e6 + 10; const long long INF = 8e18; ... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ; long long int t, x, sum = 0, y, z, flag = 0, a, p, l, r, b, c, q, i, j, k, n, m, maxi = LONG_MIN, mini = LONG_MAX, mul = 1; string s, s1; ... |
#include <bits/stdc++.h> using namespace std; struct ele { long long next, prev, delta, y; }; long long r, c, k, n, curcnt = 0, ans = 0; vector<ele> a; vector<long long> deltaleft, deltaright; vector<vector<long long> > X, id; vector<pair<long long, long long> > tmp; void init() { X.clear(); ... |
#include <bits/stdc++.h> using namespace std; const int maxn = 300007; struct tup { int u, v, pos; friend bool operator<(tup x, tup y) { if (x.v < y.v) { return 1; } return 0; } } ans[maxn]; int rec[maxn], n; int solve() { int cnt = 0; rec[cnt++] = n; ans[n]... |
#include <bits/stdc++.h> using namespace std; int main(int argc, char const *argv[]) { int n, q, counts = 0; cin >> n; int s[n]; for (int i = 0; i < n; i++) cin >> s[i]; cin >> q; int l[q], r[q]; for (int i = 0; i < q; i++) cin >> l[i] >> r[i]; int sums[n + 1]; sums[0] = 0; f... |
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 7; const int M = 107; const int inf = 1e9 + 7; vector<int> g[N], a[M]; int w[N][M], d[N]; void bfs(int u) { queue<int> q; memset(d, inf, sizeof(d)); for (int i = 0; i < (int)a[u].size(); ++i) { q.push(a[u][i]); d[a[u... |
#include <bits/stdc++.h> using namespace std; int main() { int t, n, m, x; unordered_map<int, int> mp; cin >> t; int a[t]; for (int i = 1; i <= t; i++) { cin >> a[i]; mp[i] = a[i]; } for (int i = 1; i <= t; i++) { n = mp[i]; m = mp[n]; x = mp[m]; if (i... |
#include <bits/stdc++.h> using namespace std; const int maxN = 23; const int mod = 1000 * 1000 * 1000 + 7; int dp[2][1 << maxN]; int a[maxN]; int res[maxN][maxN]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; dp[0][... |
#include <bits/stdc++.h> using namespace std; const int MN = 51; char a[MN][MN], b[MN][MN]; const char L = L , R = R , U = U , D = D ; vector<pair<int, int> > sol, sol2; int n, m; void show() { ; for (int i = 0; i < n; ++i) ; ; ; for (int i = 0; i < n; ++i) ; ; } ... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int t; cin >> t; while (t-- > 0) { int l, r; cin >> l >> r; cout << l << << 2 * l << n ; } return 0; } |
#include <bits/stdc++.h> char ans[4][128]; int main() { int i, j, n; while (scanf( %d , &n) != EOF) { memset(ans, 0, sizeof(ans)); if (n % 2 == 1) { j = 0; ans[0][0] = a + j; ans[1][0] = a + j; j = (j + 1) % 26; for (i = 0; i < n; i += 2) { a... |
#include <bits/stdc++.h> using namespace std; int n, Mod, p[100010], a[200010], nxt[200010], w[200010], tot, root, size[100010], son[100010], cnt; bool vis[100010]; long long ans, mul[100010]; struct record { int dep, step; record(int D = 0, int S = 0) { dep = D; step = S; } } ... |
#include <bits/stdc++.h> using namespace std; template <class T> inline T gcd(T a, T b) { return b ? gcd(b, a % b) : a; } template <class T> inline T LCM(T a, T b) { if (a < 0) return LCM(-a, b); if (b < 0) return LCM(a, -b); return a * (b / gcd(a, b)); } vector<int> arr; const int N =... |
#include <bits/stdc++.h> using namespace std; int a, b, c, d; void solve() { double m = max((3.0) * a / (10.0), (double)(a - a * c / 250)); double v = max((3.0) * b / (10.0), (double)(b - b * d / 250)); if (m > v) cout << Misha << endl; if (m == v) cout << Tie << endl; if (m < v) cout << ... |
#include <bits/stdc++.h> using namespace std; string op; bool check(int l, int r) { char c; cout << ? << l << << r << endl; cin >> c; return c == x ; } int main() { while (cin >> op) { if (op == end ) { return 0; } int l = 1, r = 2; while (1) { ... |
#include <bits/stdc++.h> using namespace std; int n, k, a[1000005]; long long l; vector<int> val, cou, dp[1000005]; void add(int &a, int b) { a += b; if (a >= 1000000007) a -= 1000000007; } void setup() { cin >> n >> l >> k; for (int i = 0; i <= n - 1; i++) { cin >> a[i]; val.p... |
#include <bits/stdc++.h> const int N = 500005; int to[N << 1], edge, Next[N << 1], last[N], n, x, y, d[N], mx1[N], mx2[N]; int f[N], fmx[N], ans1, mx[N], f0[N], f1[N], sum[N]; std::vector<int> e[N]; void upd(int &x, int y) { if (y > x) x = y; } void add(int x, int y) { to[++edge] = y; Next[edg... |
#include <bits/stdc++.h> using namespace std; int a[1000]; bool b[1000][1000]; int main() { int N, M; scanf( %d%d , &N, &M); for (int i = 0; i < N; i++) scanf( %d , &a[i]); for (int i = 0; i < M; i++) { int x, y; scanf( %d%d , &x, &y); --x; --y; b[x][y] = true; ... |
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; vector<vector<int> > arr(n + 1, vector<int>(m + 1)); for (int k = 1; k <= n; k++) { for (int i = 1; i <= m; i++) { cin >> arr[k][i]; arr[k][i] += arr[k][i - 1]; } } for (int i = 1;... |
#include <bits/stdc++.h> const int N = 1e5 + 50; using namespace std; int n, m, h, tot, mx, maxn, ans; int a[N], b[N], cnt[N], num[N]; int read() { int s = 0, t = 1; char c; while (c < 0 || c > 9 ) { if (c == - ) t = -1; c = getchar(); } while (c >= 0 && c <= 9 ) { ... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, q; cin >> n >> q; set<int> s; multiset<int> d; auto Add = [&](int x) { auto ret = s.insert(x); auto it = ret.first; if (next(it) != s.end() && it != s.begin()) { ... |
#include <bits/stdc++.h> using namespace std; inline long long read() { char ch = getchar(); long long s = 0, w = 1; while (ch < 0 || ch > 9 ) { if (ch == - ) w = -1; ch = getchar(); } while (ch >= 0 && ch <= 9 ) { s = s * 10 + ch - 0 ; ch = getchar(); } r... |
#include <bits/stdc++.h> using namespace std; char str[100050]; char a[5000], b[5000]; int len1, len2, len3; bool pp(int s1, int s2) { while (s2 <= len2) { if (str[s1] != a[s2]) return false; s1++, s2++; } return true; } bool pp2(int s1, int s2) { while (s2 <= len3) { if ... |
#include <bits/stdc++.h> using namespace std; int main() { long long num, tmp, sum, mx, l, r, mid; cin >> num; mx = sum = 0; for (int i = 0; i < num; i++) { cin >> tmp; sum += tmp; mx = max(mx, tmp); } l = mx; r = sum; while (l < r) { mid = (l + r) / 2; ... |
#include <bits/stdc++.h> using namespace std; const int maxn = 505; const int maxm = 1e4 + 5; struct node { int pre[maxn]; void init() { for (int i = 0; i < maxn; ++i) { pre[i] = i; } } int Find(int x) { if (x != pre[x]) pre[x] = Find(pre[x]); return pre[x]; }... |
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<long long int> v, t; v.push_back(0), t.push_back(0); long long int sum = 0, tt = 1, x = 0; double result = 0; long long int ix, a, b; for (int i = 0; i < n; ++i) { cin >> ix; if (ix == 1) {... |
#include <bits/stdc++.h> using namespace std; const long long N = 1e9 + 5; long long n, k; bool valid(long long x) { long long maxi = (x)*k - ((x - 1) * ((x + 2) / 2.0)); if (maxi >= n) return true; else return false; } long long binary() { long long lo = 0, mid, hi = k; whil... |
#include <bits/stdc++.h> using namespace std; int cnt[3600]; int main() { int n; cin >> n; for (int i = 0; i < n; i++) { int h, m; scanf( n%d:%d , &h, &m); cnt[h * 60 + m]++; } int ans = 0; for (int i = 0; i < 1440; i++) { if (cnt[i] == 0) { int cur = 1, j ... |
#include <bits/stdc++.h> using namespace std; const long long N = 1e6 + 10; int a[N], b[N]; int main() { int n; cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; } vector<int> ans; for (int i = 1; i <= n; i++) { b[i] = a[i] - a[i - 1]; } for (int i = 1; i <= n; i+... |
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 6; bool flag = true; vector<int> v[N]; int a[N], p[N], h[N], g[N]; void dfs(int u, int temp = -1) { a[u] = p[u]; int sum = 0; for (auto x : v[u]) { if (x == temp) continue; dfs(x, u); sum += g[x]; a[u] += a... |
#include <bits/stdc++.h> using namespace std; int main() { int i = 0, j = 0, a; string s, t; cin >> s >> t; a = t.length(); while (a--) { if (t[j] == s[i]) { i++; } j++; } cout << i + 1; } |
#include <bits/stdc++.h> using namespace std; char inp[1005], ans[1005]; int n, p; bool possible(int pos, int ok) { if (pos == n) return ok; int start = ok ? 0 : inp[pos] - a ; int i; for (i = start; i < p; i++) { ans[pos] = i + a ; if (pos > 0 && ans[pos - 1] == ans[pos]) continue... |
#include <bits/stdc++.h> using namespace std; int n, m, k; long long C[1005][2005]; int main() { scanf( %d %d %d , &n, &m, &k); int M = max(n, m); for (int n = 0; n <= M; n++) for (int r = 0; r <= 2 * k; r++) { if (r == 0) C[n][r] = 1; else if (n == 0) C[n][... |
#include <bits/stdc++.h> using namespace std; long long lca(long long a, long long b) { while (a != b) { if (a < b) b /= 2; else a /= 2; } return a; } long long inf = 1000LL * 1000LL * 1000LL * 1000LL * 1000LL * 1000LL; int main() { ios_base::sync_with_stdio(0); ... |
#include <bits/stdc++.h> using namespace std; int n; int a[100]; int main() { int x = 1; scanf( %d , &n); for (int i = 1; i <= n; ++i) { scanf( %d , &a[i]); if (a[i] < a[x]) x = i; } if (n == 1 || (n == 2 && a[1] == a[2])) { puts( -1 ); } else { printf( 1 n%d n , ... |
#include <bits/stdc++.h> using namespace std; char comp[200005]; vector<pair<int, int> > edge[200005]; vector<int> father[200005]; vector<string> ans; int dis[200005], n, k; queue<pair<int, int> > q; void dfs(int u) { if (ans.size() >= k) return; if (u == n + 1) { ans.push_back(comp + 1); ... |
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; for (int i = 0; i < n; i++) { int s, f, t; cin >> s >> f >> t; int x = t % (2 * (m - 1)); int y = t - x; int ans = 0; if (s == f) { ans = t; } else if (s < f) { i... |
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 5; int n, m, t; vector<int> e[maxn]; vector<int> ans; stack<int> s; bool vis[maxn]; int dep[maxn]; int N; bool v[maxn]; int dfs(int x, int fr) { vis[x] = true; s.push(x); for (auto y : e[x]) { if (y == fr) conti... |
#include <bits/stdc++.h> using namespace std; int n, a[110], mx; const int N = 30; map<int, int> mem; int Penu(int now) { if (!now || mem.find(now) != mem.end()) return mem[now]; register int ans = 0; register set<int> mex; for (register int i = 1; i < 31; i++) if (now >> i) mex.insert(P... |
#include<bits/stdc++.h> #define ll long long int #define ld long double #define pb push_back #define fi first #define se second #define all(x) x.begin(),x.end() #define mem(x,y) memset(x,y,sizeof(x)) #define pii pair<int,int> #define pll pair<ll,ll> #define INF 1e9+10 #define INFL 1e18 #defin... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n; string s, t; cin >> n >> s >> t; string ss = s, tt = t; sort(ss.begin(), ss.end()); sort(tt.begin(), tt.end()); if (ss != tt) cout << -1 << n ; else { ... |
#include <bits/stdc++.h> using namespace std; const long long int MOD = 1000000000 + 7; long long int arr[200005]; int main() { ios::sync_with_stdio(0); cin.tie(0); long long int t; cin >> t; while (t--) { long long int n, sum = 0; cin >> n; for (long long int i = 0; i < n;... |
#include <bits/stdc++.h> using namespace std; const long long maxn = 2e5 + 5; int n, k, a[maxn], ans[maxn], pos[maxn]; class Node { public: int l, r; }; Node lis[maxn]; int main() { scanf( %d%d , &n, &k); for (int(i) = 0; (i) < (n); (i)++) { cin >> a[i + 1]; pos[a[i + 1]] = i + ... |
#include <bits/stdc++.h> using namespace std; inline bool isLow(char ch) { return (ch >= a && ch <= z ); } inline bool isUpp(char ch) { return (ch >= A && ch <= Z ); } inline bool isDig(char ch) { return (ch >= 0 && ch <= 9 ); } inline bool are_equal(double a, double b) { return fabs(a - b) < num... |
#include <bits/stdc++.h> #pragma GCC optimize( O3 ) using namespace std; template <class T> using V = vector<T>; template <typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T> >; long long GCD(long long a, long long b) { return b ? GCD(b, a % b) : a; } long long LCM(long long a... |
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const double eps = 1e-6; const double PI = acos(-1); const double R = 0.57721566490153286060651209; const int maxn = 1005; struct Edge { int from, to, cap, flow, cost; Edge(int u, int v, int c, int f, int cc) : from(... |
#include <bits/stdc++.h> using namespace std; const int OO = 0x3f3f3f3f, NegOO = -1 * OO, N = 1e6 + 5, mod = 1e9 + 7; long long gcd(long long x, long long y) { if (y == 0) return x; return gcd(y, x % y); } int main() { int t; cin >> t; while (t--) { int n, x, y, d; cin >> n >> ... |
#include <bits/stdc++.h> using namespace std; vector<long long> g[200000]; long long c[200000]; long long cnt; void dfs(long long v, long long p = -1) { cnt++; long long cnt1 = cnt; for (long long to : g[v]) { if (to != p) { dfs(to, v); } } c[v] = cnt - cnt1 + 1; } ... |
#include <bits/stdc++.h> using namespace std; const int maxn = 410; const int inf = 0x7fffffff; int a[maxn]; int n; int main() { int ans = inf; cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 2; i <= n; i++) for (int j = i; j <= n; j++) { int x = a[i - 1] - 1, ... |
#include <bits/stdc++.h> using namespace std; const int prime[15] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47}; int main() { int n; cin >> n; vector<int> res; int limit = 2 * n * n; for (int i = 0; i < 15; i++) { res.clear(); res.push_back(1); for (int j = 0; j ... |
#include <bits/stdc++.h> using namespace std; const long long nax = 1e5 + 7; const long long mod = 1e9 + 7; const long long inf = numeric_limits<long long>::max(); long long n, m; bool check(vector<long long> &vec) { vector<long long> freq(n + 1, 0); for (long long i = 0; i < n; i++) { if (vec... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int test; cin >> test; while (test--) { int n; cin >> n; vector<vector<int>> v(n, vector<int>(n, 0)); for (int i = 0; i < n; i++) { v[i][i] = 1; v[(... |
#include <bits/stdc++.h> using namespace std; const long long int inf = (long long int)1e18 + 19; const long long int mod = (long long int)1e9 + 7; void cazz() { long long int t = 1, i; long double j, n; cin >> t; while (t--) { cin >> n; i = 3, j = -1; while (j < n) { j... |
#include <bits/stdc++.h> using namespace std; const int N = 1000 * 1000 + 10; vector<int> vec[N]; vector<int> d[2]; bool mark[N]; void dfs(int v, int hh) { mark[v] = true; d[hh].push_back(v); for (int u : vec[v]) if (!mark[u]) dfs(u, 1 - hh); } int main() { int o; cin >> o; ... |
#include <bits/stdc++.h> const int inf = 1000000007; const double pi = 2 * acos(0.0); using namespace std; int gcd(int a, int b) { a = abs(a); b = abs(b); while (b) { a = a % b; swap(a, b); } return a; } int main() { map<long long, int> m; long long n, k; scanf( %... |
#include <bits/stdc++.h> using namespace std; const int MAXN = 500005; int ult; int cont; int prim; char cad[MAXN]; bool Solve(int a, int n, int T) { int c = 0, time = 0; queue<int> s; prim = -1; for (int i = 0; i < n && c < cont; i++, time++) { if (cad[i] == H && a > 0) { ... |
#include <bits/stdc++.h> using namespace std; int main() { long long int i, j, k, m, n, a[100400], t, w, q, sum = 0; char s[105000]; long double x, y; cin >> q; for (j = 0; j < q; j++) { cin >> n; cin >> s; if (n > 2) { cout << YES << endl; cout << 2 << endl; ... |
#include <bits/stdc++.h> #pragma GCC optimize( O3 ) long long fact(int i) { if (i <= 1) return 1; else return i * fact(i - 1); } using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t; cin >> t; while (t--) { int arr[4]; for... |
#include <bits/stdc++.h> using namespace std; vector<int> a; void SieveOfEratosthenes(int n) { bool prime[n + 1]; memset(prime, true, sizeof(prime)); for (int p = 2; p * p <= n; p++) { if (prime[p] == true) { for (int i = p * p; i <= n; i += p) prime[i] = false; } } for (in... |
#include <bits/stdc++.h> using namespace std; template <class T> void mini(T& a, T b) { a = min(a, b); } template <class T> void maxi(T& a, T b) { a = max(a, b); } template <class T1, class T2> ostream& operator<<(ostream& out, pair<T1, T2> a) { return out << a.first << << a.second; ... |
#include <bits/stdc++.h> using namespace std; bool comp(int a, int b) { return (a > b); } int main() { int a, b, n, l, t, m, x, ans, r; long long cek; scanf( %d %d %d , &a, &b, &n); for (int i = 1; i <= n; i++) { scanf( %d %d %d , &l, &t, &m); if (t < a + (long long)(l - 1) * b) ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.