func_code_string stringlengths 59 71.4k |
|---|
#include <bits/stdc++.h> using namespace std; struct trip { int l; int len; int t; int id; }; const int INF = 1e9; int main() { int n, p; scanf( %d%d , &n, &p); vector<trip> trips(n); for (int i = 0; i < n; i++) { scanf( %d%d%d , &trips[i].l, &trips[i].len, &trips[i].t); ... |
#include <bits/stdc++.h> using namespace std; const int maxn = 100000 + 10; struct node { int t; int x; int y; } tt[maxn]; int main() { int n, m, s, f; while (~scanf( %d%d%d%d , &n, &m, &s, &f)) { memset(tt, 0, sizeof tt); for (int i = 0; i < m; i++) { scanf( %d%d%d , &... |
#include <bits/stdc++.h> int main() { char jak[1000005], tak[1000005]; gets(jak); gets(tak); int k, r, i, t, flag = 0, count = 0, fount = 0, f, x, y, j, p = 0; k = strlen(jak); r = strlen(tak); for (i = 0; i < k; i++) { t = jak[i] - 48; if (t != 0 && flag == 0) { flag =... |
#include <bits/stdc++.h> using namespace std; void dbg_out() { cerr << b b] n ; } template <typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << H << , ; dbg_out(T...); } const int mod = 1e9 + 7; long long power(long long a, long long b) { long long res = 1; while... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); int t, n, a[1000000], i, j, b = 0, c = 0, e, f, g, h, m[1000000]; cin >> t; for (i = 0; i < t; i++) { cin >> n; h = n; for (j = 1; j <= n; j++) { cin >> a[j]; } sort(a +... |
#include <bits/stdc++.h> #pragma GCC optimize(3) using namespace std; const long long maxnodes = 1005; int32_t main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; string t; cin >> t; long long n = t.size(); string s1(n, a ), s2(n, a ), s3(n, a ); string t1, t2, t3... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, p, q, temp; cin >> n; int levels[101] = {0}; cin >> p; for (int i = 0; i < p; i++) { cin >> temp; levels[temp]++; } cin >> q; for (int ... |
#include <bits/stdc++.h> using namespace std; long double dp[1010000][3]; int n, m; int ranks[1245]; int Prank; int main() { cout << fixed << setprecision(12); cin >> n >> m; if (m == 1) { cout << 1 n ; return 0; } for (int i = 1; i <= (n); ++i) { cin >> ranks[i]; ... |
#include <bits/stdc++.h> using namespace std; long long a[100005], ac[100005]; int last[100005]; int main() { int n, m, t, x, v, y, q; string s; while (cin >> n >> m) { for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 1; i <= m; i++) { cin >> t; if (t == 1) { ... |
#include <bits/stdc++.h> using namespace std; const long long int maxn = 5100, inf = 1e17, mod = 1e9 + 7; vector<long long int> f[maxn]; long long int pref[maxn][maxn]; signed main() { cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false); long long int n, m; cin >> n >> m; vector<... |
#include <bits/stdc++.h> using namespace std; int main() { long long n, m, i, j, k, x, y, t; long long a; cin >> a; n = 2 * a - 1; m = 2; cout << n << << m << endl; cout << 1 << << 2 << endl; } |
#include <bits/stdc++.h> using namespace std; int freq[8]; int main() { int n, a, p1 = 0, p2 = 0, p3 = 0; cin >> n; for (int i = 0; i < n; i++) { cin >> a; freq[a]++; } if (freq[5] > 0 || freq[7] > 0) { cout << -1; return 0; } while (freq[1] > 0 && freq[2] > 0 &... |
#include <bits/stdc++.h> using namespace std; pair<long long, long long> ar[100005]; long long suf[100007] = {0}, pre[100007] = {0}, sbkoya[100007] = {0}, arr[100005]; int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); ; long long n, a, cf, cm, m, temp, revi, cnt = 0; cin ... |
#include <bits/stdc++.h> using namespace std; int32_t main() { int n; cin >> n; cout << n % 2; } |
#include <bits/stdc++.h> using namespace std; using point = complex<long long>; long long cross(point a, point b) { return a.real() * b.imag() - a.imag() * b.real(); } long long dot(point a, point b) { return a.real() * b.real() + a.imag() * b.imag(); } int main() { ios_base::sync_with_stdio(f... |
#include <bits/stdc++.h> using namespace std; int a[200005]; int main() { int T; cin >> T; while (T--) { int n; cin >> n; for (int i = 1; i <= n; i++) { int t; cin >> t; a[t] = i; } int l, r, num; string s = ; for (int i = 1; i <= n; ... |
#include <bits/stdc++.h> using namespace std; using LL = long long; const int MX[4] = {0, 0, -1, 1}; const int MY[4] = {-1, 1, 0, 0}; int n, m, k; bool z[26]; bool Inside(int a, int b) { return 0 <= a && a < n && 0 <= b && b < m; } char GetC(int a, int b, int c, int d, vector<vector<char>>& x) { mem... |
#include <bits/stdc++.h> using namespace std; struct dbg_ { template <typename T> dbg_& operator,(const T& x) { cerr << x << ; return *this; } } dbg_t; struct cin_ { template <typename T> cin_& operator,(T& x) { cin >> x; return *this; } } cin_; template <t... |
#include <bits/stdc++.h> #define mp make_pair #define mt make_tuple #define fi first #define se second #define pb push_back #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define forn(i, n) for (int i = 0; i < (int)(n); ++i) #define for1(i, n) for (int i = 1; i <= (i... |
#include <bits/stdc++.h> using namespace std; int main() { long long x, y, k, t; cin >> t; for (int i = 0; i < t; i++) { cin >> x >> y >> k; long long br; br = (k * (y + 1) - 1) / (x - 1); if (((k * (y + 1) - 1) % (x - 1)) != 0) { br += 1; } br += k; cou... |
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t; cin >> t; while (t--) { long long n, k; cin >> n >> k; vector<long long> v; for (int i = 0; i < n; i++) { long long x; cin >> x; ... |
#include <bits/stdc++.h> using namespace std; const int N = 4010, K = 80; const int p = 998244353; int n1, n2, k, px[2][N], py[2][N], a1[K], a2[K], fac[K], inv[K], f[2][N]; int tot, fi[N], a[N << 1], ne[N << 1], cnt; inline void A(int &x, int y) { x = (x + y >= p ? x + y - p : x + y); } inline int C(int x... |
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t-- > 0) { char c[100005]; int n; cin >> n; string s0 = ; string sm = ; string s1 = ; bool flag0 = true; int pos1 = -1; int pos0 = -1; for (int i = 1; i <=... |
#include <bits/stdc++.h> using namespace std; int num, sg[100010], mex[100010], col = 1, ans = -1; int main() { scanf( %d , &num); for (int n = 3; n <= num; n++) { for (int m = 2;; m++) { int res = n - (m - 1) * m / 2; if (res < 0) break; if (res % m) continue; int g ... |
#include <bits/stdc++.h> using namespace std; const int maxn = 6010; int ans, f[maxn], r[maxn], m[maxn][maxn]; void dfs(int x, int y, int p) { int k = lower_bound(f, f + p, r[x]) - f; int t = f[k]; f[k] = r[x]; ans = max(ans, k); p = max(k + 1, p); for (int i = 1; i <= m[x][0]; i++) ... |
#include <bits/stdc++.h> using namespace std; int main() { int n, x[1000], y[1000], z[1000], t = 0, s = 0, d = 0; cin >> n; for (int i = 1; i <= n; i++) { cin >> x[i] >> y[i] >> z[i]; t += x[i]; s += y[i]; d += z[i]; } if (t == 0 && s == 0 && d == 0) cout << YES ; ... |
#include <bits/stdc++.h> using namespace std; const int MAXN = 65, MAXM = 65; int N, M; int A[MAXN], B[MAXM]; int Id[40011], Pos[MAXN * MAXM], Pc; bool VisA[MAXN], VisB[MAXM]; int Ans, Cnt; int Val[MAXN * MAXM]; int main() { ios_base::sync_with_stdio(false); cin >> N >> M; for (int i = 1; ... |
#include <bits/stdc++.h> using namespace std; int n, k; int a[105], C[105]; double f[105][105], s1[105][105], s2[105][105], s3[105][105]; inline int read() { int x = 0, f = 1; char ch = getchar(); while (ch > 9 || ch < 0 ) { if (ch == - ) f = -1; ch = getchar(); if (ch == -1)... |
#include <bits/stdc++.h> long long p[1000010] = {0}, cur[1000010 * 2] = {0}; inline long long read() { char c; while (!isdigit(c)) c = getchar(); long long x = 0; while (isdigit(c)) { x = x * 10 + c - 0 ; c = getchar(); } return x; } int main() { long long sum, ans, L, R... |
#include <bits/stdc++.h> using namespace std; long long pow(long long a, int p) { if (p == 0) return 1; if (p % 2 == 0) { long long kek = pow(a, p / 2); return kek * kek; } return pow(a, p - 1) * a; } int main() { int n, m; cin >> n >> m; if (m == 0) { cout << 2 * n... |
#include <bits/stdc++.h> using namespace std; const int INF = 2e9; const long long LINF = 2e16; const int magic = 348; const int MOD = 998244353; const double eps = 1e-10; const double pi = acos(-1); struct fastio { static const int S = 1e7; char rbuf[S + 48], wbuf[S + 48]; int rpos, wpos, l... |
#include <bits/stdc++.h> using namespace std; const int MAXN = 200200; int n; const long long neutro = 0; struct RMQ { int sz; long long tope; long long t[4 * MAXN]; long long &operator[](int p) { return t[sz + p]; } void init(int n, long long tope_) { sz = 1 << (32 - __builtin_clz(n... |
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 100; const int lg = 31; const int mod = 1e9 + 7; const int inf = 1e9; struct node { int mn, cnt[lg], lz; node() { mn = 0; lz = 0; fill(cnt, cnt + lg, 0); } void operator+=(int x) { mn += x; lz ... |
#include <bits/stdc++.h> using namespace std; const int N = 5e5 + 10; const int N2 = 2e6 + 5; long long cs[N2], csn[N2]; int main() { int n, x, y; scanf( %d%d%d , &n, &x, &y); int mx = 0; for (int i = 0, a; i < n; i++) { scanf( %d , &a); cs[a]++; mx = max(mx, a); } lo... |
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) #pragma GCC optimization( unroll-loops, no-stack-protector ) #pragma GCC target( avx,avx2,fma ) using namespace std; using pii = pair<int, int>; using pll = pair<long long, long long>; using vb = vector<bool>; using vi = vector<int>; using vl = ve... |
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { long long int sum = 0; for (int i = 0; i < 3; i++) { long long int temp; cin >> temp; sum += temp; } cout << sum / 2 << endl; } return 0; } |
#include <bits/stdc++.h> #pragma comment(linker, /STACK:512000000 ) using namespace std; using li = long long; using ld = long double; void solve(bool); void precalc(); clock_t start; int main() { start = clock(); int t = 1; cout.sync_with_stdio(0); cin.tie(0); cout.precision(20); ... |
#include <bits/stdc++.h> using namespace std; int main() { int num, sum = 0; for (int i = 0; i < 5; ++i) { cin >> num; sum += num; } if (!(sum % 5) && sum > 0) cout << sum / 5 << endl; else cout << -1 << endl; return 0; } |
#include <bits/stdc++.h> using namespace std; long double dp[4005][4005]; long double absf(long double a) { if (a < 0) return a * (-1); return a; } long double solve(vector<long double> &a, long long idx, long long left) { if (idx >= a.size()) return left == 0 ? 0 : 100000; if (dp[idx][left] !... |
#include <bits/stdc++.h> using namespace std; int cur, hasans, ptr; vector<int> adj[500004]; vector<int> ans(500004); void dfs(int now) { cur--; for (auto u : adj[now]) { if (u == cur) { dfs(u); } else { hasans = 0; } } ans[ptr++] = now; } void solve() { ... |
#include <bits/stdc++.h> using namespace std; void _print(long long int t) { cerr << t; } void _print(int t) { cerr << t; } void _print(string t) { cerr << t; } void _print(char t) { cerr << t; } void _print(long double t) { cerr << t; } void _print(double t) { cerr << t; } void _print(unsigned long lon... |
#include <bits/stdc++.h> using namespace std; template <class T> inline void gmin(T &x, const T &y) { x = x > y ? y : x; } template <class T> inline void gmax(T &x, const T &y) { x = x < y ? y : x; } template <class T> inline bool Gmin(T &x, const T &y) { return x > y ? x = y, 1 : 0; } ... |
#include <bits/stdc++.h> using namespace std; pair<int, int> a[100005]; int sum = 0, m; char s[10005][105]; void f(int target, int n) { int i, j, k, l; m = max((a[n].first - target), ((sum - n * target) / 2)); for (i = 0; i < m; i++) { for (j = 0; j < n; j++) s[i][j] = 0 ; s[i][j] = ... |
#include <bits/stdc++.h> using namespace std; const int N = 310; int a[N][N], n, p[N], vis[N]; void dfs(int v) { vis[v] = 1; for (int i = 1; i <= n; i++) { if (a[v][i] && !vis[i]) { dfs(i); } } } int main() { int i, j; scanf( %d , &n); for (i = 1; i <= n; i++) { ... |
#include <bits/stdc++.h> using namespace std; const double eps = 1e-6; const int inf = 0x3f3f3f3f; const long long int INF = 1e15; const int mod = 1e9 + 7; const int maxn = 2e3 + 5; int cas = 1; int sum[maxn]; vector<int> v; map<int, int> mp; void solve() { int n, k; while (~scanf( %d%d , ... |
#include <bits/stdc++.h> using namespace std; using ll = long long; const int MAX_N = 200002; int n; int a[MAX_N], t[MAX_N]; void solve() { vector<pair<int, int>> v; for (int i = 0; i < n; ++i) v.emplace_back(a[i], t[i]); sort(v.begin(), v.end()); ll cur = -1; int idx = 0; multiset<l... |
#include <bits/stdc++.h> using namespace std; const int N = 605; int n; vector<int> g[N]; map<vector<int>, int> memo; int ask(vector<int> &vs) { if (int((vs).size()) <= 1) return 0; sort((vs).begin(), (vs).end()); if (memo.count(vs)) return memo[vs]; cout << ? << int((vs).size()) << endl;... |
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 10; int cnt2[maxn]; int cnt[maxn]; struct trie { int nxt[maxn][26], fail[maxn], g[maxn]; int ed[maxn]; int rt, L; int newnode() { memset(nxt[L], -1, sizeof nxt[L]); ed[L++] = 0; return L - 1; } void ... |
#include <bits/stdc++.h> using namespace std; int a, b; int main() { cin >> a >> b; if (a > b + 1 or (a + 1) * 2 < b) { cout << -1; return 0; } string s; s.push_back( 1 ); int n = a + b, ok = 1; for (int i = 1; i < n; i++) { if (ok and b > a) { s.push_back( 1 ... |
#include <iostream> #include <iomanip> #include <cstdio> #include <cstdlib> #include <algorithm> #include <cmath> #include <vector> #include <set> #include <map> #include <unordered_set> #include <unordered_map> #include <queue> #include <ctime> #include <cassert> #include <complex> #inclu... |
#include <bits/stdc++.h> using namespace std; int main() { long long int a = 100, c = 20, d = 10, e = 5; long long int note, n, rem; while (scanf( %lld , &n) != EOF) { note = n / a; rem = n % a; note = note + (rem / c); rem = rem % c; note = note + (rem / d); rem = re... |
#include <bits/stdc++.h> using namespace std; const int INF = 2000000009; const int Max = 1000007; const double PI = acos(-1.0); long long nc2(long long n) { return (n * (n - 1)) / 2; } map<long long, long long> mp1, mp2; map<pair<long long, long long>, long long> mp3; int main() { long long i, j, k... |
#include <bits/stdc++.h> using namespace std; int lis(vector<int>& a) { if (a.empty()) return 0; int n = a.size(); int INF = 1000; vector<int> b(n + 1, INF); b[0] = -INF; for (int i = 0; i < n; ++i) { int val = a[i]; int pos = upper_bound(b.begin(), b.end(), val) - b.begin(); ... |
#include <bits/stdc++.h> using namespace std; const long long inf = 1e18 + 1; int n, ans[51], t[51]; long long k, fac[51], dp[51]; bool v[51]; long long mul(long long x, long long y) { return !x ? 0 : inf / x < y ? inf : x * y; } long long cal(int x) { return x < 2 ? 1 : fac[x - 2]; } void work(in... |
# include <bits/stdc++.h> # define sz(x) (int)x.size() # define f first # define s second using namespace std; using ll = long long; void solve() { int n, a, b; cin >> n >> a >> b; int x, y; cin >> x >> y; int c = n - max(a, b) + abs(a - b) / 2; int d = min(a, b) + abs(a - b) /... |
#include <bits/stdc++.h> using namespace std; int a[1010], ans[1010]; int main() { int n, i, cur = 0, x, y, l1 = 1, l2 = 1; cin >> n; for (i = 1; i < n; i++) { cin >> x >> y; if (x > y) swap(x, y); a[x]++; if (y != n) { cout << NO ; return 0; } } ... |
#include <bits/stdc++.h> using namespace std; const int maxn = (int)3e5 + 10; const int inf = (int)1e9 + 5; const long long llinf = (long long)1e18 + 5; long long a[maxn]; long long d, i, n, k, l, query, first, second, pruf, pruf2, j, m, p, last, sum, h, z, r; int main() { cin >> n; for (i =... |
#include <bits/stdc++.h> #pragma comment(linker, /STACK:32000000 ) const int nil = -1; using namespace std; inline bool read(int& val) { return scanf( %d , &val) != -1; } inline bool read(long long& val) { return scanf( %I64d , &val) != -1; } inline bool read(double& val) { return scanf( %lf , &val) != -1;... |
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 500; const int M = 1e6 + 500; const int INF = 0x3f3f3f3f; const int MOD = 1e9 + 7; const int BASE = 31337; const int LOG = 18; const int OFF = (1 << LOG); const double EPS = 1e-9; const double PI = 3.1415926535; int n, k, bio[2 * M ... |
#include <bits/stdc++.h> using namespace std; int a[100005], b[100005], f[100005], cnt[100005], ans[100005]; int main() { int i, j, k, l, n, m; cin >> n >> m; for (i = 1; i <= n; i++) { cin >> j; if (!cnt[j]) f[j] = i; cnt[j]++; } int flag = 1; l = 1; for (i = 1; i <=... |
#include <bits/stdc++.h> using namespace std; int main() { int n, x, y; cin >> n >> x >> y; cout << max((int)ceil((double)y * n / 100) - x, 0); return 0; } |
#include <bits/stdc++.h> using namespace std; vector<int> e[200010]; struct Node { int sz, l; } c[200010]; bool cmp(const Node &p, const Node &q) { return (p.sz - p.l) > (q.sz - q.l); } void dfs(int x, int fa) { c[x].l = c[fa].l + 1; for (int i = 0; i < (int)e[x].size(); i++) { int y = e[x... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int TESTS = 1; while (TESTS--) { long long n, q; cin >> n >> q; while (q--) { long long x; cin >> x; long long c = 1; for (long ... |
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; if (n <= 2) cout << -1 ; else if (n == 3) cout << 210 ; else { int mod = 1; for (int i = 1; i < n; ++i) mod = (mod * 10) % 210; if (n > 3) cout << 1 ; for (int i = 0; i < n - 4; ++i... |
#include <bits/stdc++.h> using namespace std; const int N = 55; const int d[4][2] = {-1, 0, 0, 1, 1, 0, 0, -1}; char a[N][N]; int v[4][N][N][2], m, n; int q[N * N * 4 * 2][4]; int check(int x, int y) { if (x >= 1 && x <= m && y >= 1 && y <= n && a[x][y] == B ) return 1; else return 0;... |
#include <bits/stdc++.h> using namespace std; long long int d[(100010)]; const long long int mod = 1e9 + 7; int main() { int n, m; cin >> n >> m; d[0] = d[1] = 1; int k = max(n, m); for (int i = 2; i <= k; i++) { d[i] = (d[i - 1] + d[i - 2]) % mod; } long long int ans = (d[n] +... |
#include <bits/stdc++.h> using namespace std; #pragma warning(disable : 4996) #pragma comment(linker, /STACK:256000000 ) FILE *stream; const int INF = 1e9 + 7; const long long INFL = (long long)1e18 + 1; const int SIZE = 2e5 + 10; const int TSIZE = 1e3 + 10; const long double eps = 0.000001; const ... |
#include <bits/stdc++.h> using namespace std; long long int pow_mod(long long int a, long long int b) { long long int res = 1; while (b != 0) { if (b & 1) { res = (res * a) % 1000000007; } a = (a * a) % 1000000007; b /= 2; } return res; } void solve() { long l... |
#include <bits/stdc++.h> using namespace std; int main() { int T = 1; cin >> T; while (T--) { string s; int x; cin >> s >> x; string ans; int n = s.size(); for (int i = 0; i < n; i++) ans.push_back( 1 ); for (int i = 0; i < n; i++) { if (s[i] == 0 ) { ... |
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 1; int n, m; vector<int> A[MAXN]; int d[MAXN]; void dfs(int nod) { for (int i = 0; i < A[nod].size(); i++) { int v = A[nod][i]; if (d[v] == 0) { d[v] = d[nod] + 1; dfs(v); } } } int main() { ... |
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 7, mod = 1e9 + 7; int dp[N], sum[N], i, n, m, j, k, nxt[N], v[N]; char a[N], b[N]; int main() { for (scanf( %s%s , a + 1, b + 1), n = strlen(a + 1), m = strlen(b + 1), i = 2; i <= m; ++i) { while (b[j + 1] != b[i] && j) j = n... |
#include <bits/stdc++.h> using namespace std; long long int vis[1005][1005]; char a[1005][1005]; pair<pair<long long int, long long int>, long long int> fuck[1005][1005]; long long int dfs(long long int i, long long int j, pair<long long int, long long int> par) { vis[i][j] = 1; lo... |
#include <bits/stdc++.h> using namespace std; const int mod = 998244353, N = 1e5; int cnt[200], seq[200][17], fac[20], inv[20], ifac[20], popcnt[N], ln[N][17], tmp[N][17], ans[N], finalans[N], w[N], n, K, c; int qmod1(const int &x) { return x >= mod ? x - mod : x; } int qmod2(const int &x) { return x + ... |
#include <bits/stdc++.h> #pragma GCC optimize( unroll-loops ) using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const int N = 45000; int h, lgn, n, t, r, x, y, a[N], dis[N], lp[N], dp[N][17]; vector<pair<int, int> > e1, e2; vector<int> g[N]; bool mark[N]; int lg... |
#include <bits/stdc++.h> typedef long long ll; typedef long double ld; #define fr(i, a, b) for (ll i = a; i < b; i++) #define rf(i, a, b) for (ll i = a; i >= b; i--) typedef std::vector<long long> vi; #define F first #define S second #define fast ios_base::sync_with_stdio(0);... |
#include <bits/stdc++.h> using namespace std; long long int max(long long int a, long long int b) { if (a > b) return a; return b; } long long int min(long long int a, long long int b) { if (a < b) return a; return b; } long long int msb(long long int n) { long long int ans; for (lon... |
#include <bits/stdc++.h> using namespace std; const long long oo = 1LL << 55; const int MAX_N = 100005; const int MAX_M = 100005; const int MAX_P = 105; template <class T> class Deque { public: Deque() { Clear(); } void Clear() { front = 1, back = 0; } void PushBack(const T x) { values[++ba... |
#include <bits/stdc++.h> using namespace std; const int N = 355001; const int SQRTN = 320; const int LOGN = 20; const long double PI = acos(-1); const long double TAU = 2 * PI; long long nk, n, k, a, b; vector<long long> first, last; long long gcd(long long x, long long b) { if (b == 0) return x; ... |
#include <bits/stdc++.h> using namespace std; long long R[10 << 10][1 << 10]; int A[10 << 10]; int n, m, g, r; int main() { cin >> n >> m; int i, j; for (i = (0); i < (m); ++i) cin >> A[i]; cin >> g >> r; sort(A, A + m); for (i = (0); i < (m); ++i) for (j = (0); j < (g + 1); ++j)... |
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int t; cin >> t; for (int i = 0; i < t; i++) { int a, b; cin >> a >> b; int moves = 0; if (a == b) { cout << 0 << n ; continue; } else if (a < b) { ... |
#include <bits/stdc++.h> using namespace std; struct lady { int b, i, r; } a[500005]; bool operator<(const lady& a, const lady& b) { if (a.b != b.b) return a.b > b.b; if (a.i != b.i) return a.i < b.i; return a.r < b.r; } int n; void inp() { scanf( %d , &n); for (int i = 1; i <= n; ... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n, s; cin >> n >> s; vector<int> g(n); for (int i = 0; i < n - 1; i++) { int u, v; cin >> u >> v; u--; v--; g[u]++; g[v]++; } int cnt = 0; ... |
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 5; int n; double r, v, l; double tim(double p1, double p2) { double rem = p2 - p1; double k = int(rem / l); rem = rem - k * l; double le = 0, ri = 1e9, mid; for (int I = 1; I <= 200; I++) { mid = (le + ri) / 2.0; ... |
#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 = 58; const int MAXQ = 5000; int n; int bto[MAXN - 1], rto[MAXN - 1]; int nq; int qat[MAXQ]; char qlast[MAXQ][MAXN - 1 + 1]; long long qans[MAXQ]; int dr[MAXN... |
#include <bits/stdc++.h> using namespace std; const double EPS = 1e-9; const double PI = 3.14159265359; vector<long long> primes; void GeneratingPrimes(int top) { vector<bool> p(top + 1, 1); p[0] = p[1] = 0; for (int i = 2; i <= sqrt(top); i++) { if (!p[i]) continue; if (p[i]) { ... |
#include <bits/stdc++.h> using namespace std; int main() { int n, p, q; string s; bool can = true; vector<string> vec; int aux = 0; int pos = 0; cin >> n >> p >> q; cin >> s; aux = n; if (n % p == 0) { cout << n / p << endl; for (int i = 0; i < n; i += p) { ... |
#include <bits/stdc++.h> using namespace std; void solve() { long long int n, k; cin >> n >> k; long long int i, a[n + 1]; for (i = 1; i <= n; i++) cin >> a[i]; if (a[1] == a[n]) { cout << 1 << endl; return; } if (k == 1 && a[1] != a[n]) { cout << -1 << endl; retu... |
#include <bits/stdc++.h> using namespace std; const long long MOD = 1000 * 1000 * 1000 + 7; long long mod(long long n) { if (n < 0) { return (n % MOD + MOD) % MOD; } else { if (n < MOD) return n; else if (n < 2 * MOD) return n - MOD; else return n % MOD; ... |
#include <bits/stdc++.h> using namespace std; void solve() { int a, b, ans; cin >> a >> b; int x = (a / 4) * 4; int i = x, val = 0; while (i < a) { val = val ^ i; i++; } if (val == b) { ans = a; } else if ((val ^ a) == b) { ans = a + 2; } else { ans ... |
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef string str; #define pb push_back #define ppp pop_back #define pii pair<int,int> #define fi first #define se second #define stie std::tie #define vec vector #define forn(i, l, r) for (int i=l; i... |
#include <bits/stdc++.h> using namespace std; const int N = 5005; int a[N]; int main() { int n, m; scanf( %d%d , &n, &m); int tot = 0; for (int i = 1; i <= n; i++) { if (m < (i - 1) / 2) break; a[++tot] = i; m -= (i - 1) / 2; } if (!m) { int cnt = 1e8; for (... |
#include <bits/stdc++.h> const int N = 500500; std::vector<int> g[N]; int d[N]; int n, maxM, maxD; void go(int cur, int par = -1, int dist = 0) { if (dist > maxD) maxD = dist; bool f = false; for (auto v : g[cur]) if (v != par) { go(v, cur, dist + 1); f = true; } if... |
#include <bits/stdc++.h> using namespace std; int main() { long long int n, k; cin >> n >> k; if (n == k || k == 0) cout << 0 << << 0; else { long long int min = 1, max; if (2 * k + k < n) max = 2 * k; else max = n - k; cout << min << << max; ... |
#include <bits/stdc++.h> using namespace std; void solve() { int n; cin >> n; vector<pair<int, bool>> v(2 * n); for (int i = 0; i < 2 * n; i++) cin >> v[i].first, v[i].second = true; long long ans = 0, cc = 0; for (int i = 0; i < 2 * n; i++) { if (!v[i].second) continue; cc = 0; ... |
#include <bits/stdc++.h> using namespace std; long long n, m, dp[1 << 21], b, ans = 3e18; pair<long long, pair<long long, long long> > a[1 << 21]; int main() { cin >> n >> m >> b; for (long long i = 0, m, x; i < n; i++) { cin >> a[i].second.first >> a[i].first >> m; while (m--) cin >> x, x--... |
#include <bits/stdc++.h> using namespace std; int L; int a[100005], n; int Min[100005 << 2], sub[100005 << 2]; vector<pair<int, int> > ans; void PushUp(int rt) { Min[rt] = min(Min[rt << 1], Min[rt << 1 | 1]); } void PushDown(int rt) { if (sub[rt]) { sub[rt << 1] += sub[rt]; sub[rt << 1 | 1... |
#include <bits/stdc++.h> using namespace std; char s[10]; int n, h; double tw[100]; int main() { cin >> s >> n >> h; if (s[0] == B ) { printf( %d n , n); return 0; } tw[0] = 1; for (int i = 1; i <= 2 * h; i++) tw[i] = tw[i - 1] * 2.0; double r = n; for (int i = 1; i <=... |
#include <bits/stdc++.h> using namespace std; const int c = 200002; int n, m, maxi, pos = c, cnt, id[c], szint[c], kezd; vector<int> sz[c]; bool v[c], v2[c], jo[c]; void dfs2(int a) { v2[a] = true; bool s = jo[a]; for (int x : sz[a]) { if (!v2[x]) { dfs2(x); if (jo[x]) { ... |
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); ; long long int ans = 1000000000000, n, m, i, d, j, a, fo = 0; vector<long long int> v; set<long long int> mset; cin >> n >> m >> d; for (i = 0; i < n; i++) { fo... |
#include <bits/stdc++.h> using namespace std; const int maxn = 110005; long long arr[maxn], arr1[maxn], n, m; int judge(long long x) { memcpy(arr1, arr, sizeof(arr)); long long i = n, countt = 1, t = 0; while (i >= 1 && arr1[i] <= 0) --i; while (countt <= m) { t = x - i; while (t > 0... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.