func_code_string stringlengths 59 71.4k |
|---|
#include <bits/stdc++.h> using namespace std; const int N = 200000; long long x[N], y[N]; vector<int> ids[N]; int order[N]; long long cross(int a, int b, int c) { return x[c] * y[c] * (x[b] * y[a] - x[a] * y[b]); } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int n; ... |
#include <bits/stdc++.h> using namespace std; const int maxn = 1000005; class fenwick { int n; vector<int> v; public: fenwick(int _n) : n(_n) { v.resize(n); } void update(int at, int by) { while (at < v.size()) { v[at] += by; at |= (at + 1); } } int query(... |
#include <bits/stdc++.h> using namespace std; const long long int mod = 998244353; vector<long long int> prime; long long int n = 1000001; vector<bool> vis(n, true); void sieve() { vis[0] = vis[1] = false; for (long long int i = 2; i * i <= n; i++) if (vis[i]) for (long long int j = i ... |
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; const int MAXN = 1e5 + 3; const int inf = 2e9; int max(int a, int b) { if (a > b) return a; else return b; } int min(int a, int b) { if (a < b) return a; else return b; } bool cmp(pair<int, i... |
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { if ((a == 0) || (b == 0)) return a + b; return gcd(b, a % b); } long long pow_mod(long long a, long long b) { long long res = 1; while (b) { if (b & 1) res = (res * a) % 1000000007; a = (a * a) % ... |
#include <bits/stdc++.h> using namespace std; double mas[10000][3]; void optim(int cnt, double Px, double Py, double Pz, double vs, double vp) { double l = 0, r = 0; double x1 = mas[cnt][0]; double y1 = mas[cnt][1]; double z1 = mas[cnt][2]; double x2 = mas[cnt + 1][0]; double y2 = mas[cnt ... |
#include <bits/stdc++.h> using namespace std; constexpr long long MOD = 1e9 + 7; struct { int val, lazy; } tree[4 * 1000010]; int bal(int p) { return tree[p].val + tree[p].lazy; } void ins(int S, int val, int L = 1, int R = 1000000, int p = 1) { if (S < L || R < 1) return; if (1 <= L && R <= S) ... |
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; int main() { long long k; long long now = 9; long long last = 1; cin >> k; if (k <= 9) { cout << k; return 0; } long long finalk = k; long long pow = 1; for (int step = 1; step <= 15; step++) ... |
#include <bits/stdc++.h> using namespace std; int n; int m; vector<vector<int>> row; vector<vector<int>> col; vector<string> g; vector<vector<bool>> vis; struct node { int d; int i; int j; }; struct NODE { vector<int> e; bool vis = false; }; vector<NODE> G; bool operator<(c... |
#include <bits/stdc++.h> using namespace std; template <typename T1, typename T2> istream &operator>>(istream &in, pair<T1, T2> &a) { in >> a.first >> a.second; return in; } template <typename T1, typename T2> ostream &operator<<(ostream &out, pair<T1, T2> a) { out << a.first << << a.second;... |
#include <bits/stdc++.h> using namespace std; int n; int f[200005][3], ans, dep[200005]; int head[200005], cnt; struct data { int next, to; data(int next = 0, int to = 0) : next(next), to(to) {} } edge[200005 << 1]; int read() { char c = getchar(); int x = 0; while (!isdigit(c)) c = ge... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int q; cin >> q; vector<int> powers; powers.reserve(10000); for (int i = 0; i < (1 << 10); i++) { long long tot = 0; long long pow = 1; for (int j = 0; j < 10; j++) ... |
#include <bits/stdc++.h> void dfs(int x); struct node { int n, h; } h[100001]; bool operator<(const node &A, const node &B) { return A.h < B.h; } std::vector<int> map[100001]; int range[100001][2]; void init(int n); int getmax(int f, int r); void set(int x, int v); int imax[100001][3]; int dma... |
#include<bits/stdc++.h> #define ll long long #define L(i, j, k) for(int i = (j); i <= (k); ++i) #define R(i, j, k) for(int i = (j); i >= (k); --i) #define vi vector < int > #define sz(a) ((int) a.size()) using namespace std; const int N = 1e6 + 7; int T; int n, m, c[N], a[N], b[N]; void Main (... |
#include <bits/stdc++.h> using namespace std; template <class T> inline T BMOD(T p, T e, T m) { T ret = 1; while (e) { if (e & 1) ret = (ret * p) % m; p = (p * p) % m; e >>= 1; } return (T)ret; } template <class T> inline T MODINV(T a, T m) { return BMOD(a, m - 2, m); ... |
#include <bits/stdc++.h> using namespace std; int n, m; long long f[102][102]; int main() { scanf( %d%d , &n, &m); for (int i = 0; i <= n; i++) f[0][i] = 1; for (int j = 1; j <= n; j++) for (int i = 1; i <= n; i++) for (int k = 0; k < i; k++) f[i][j] += f[k][j - 1] * f[i - k - 1][j - 1... |
#include <bits/stdc++.h> using namespace std; int cnt[26]; void sol() { int n; cin >> n; for (int i = 0; i < n; i++) { long long k, x; cin >> k >> x; cout << (x + (k - 1) * 9) << n ; } } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); ... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >> n; int ans = 0; for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) { int inp; cin >> inp; if (i == j || i + j == n - 1 || i == n / 2 || j == n... |
#include <bits/stdc++.h> using namespace std; const int MXN = 1 << 19; const int MOD = 1000000007; int arr[MXN]; int suf[2 * MXN]; int pre[2 * MXN]; int lb[2 * MXN]; int rb[2 * MXN]; void build(int c, int l, int r) { lb[c] = l; rb[c] = r; if (l == r) return; int k = (l + r) / 2; bu... |
#include <bits/stdc++.h> using namespace std; template <typename T> inline bool chkmin(T &x, T y) { return x > y ? x = y, 1 : 0; } template <typename T> inline bool chkmax(T &x, T y) { return x < y ? x = y, 1 : 0; } inline void read(int &x) { char ch = getchar(); int f = 1; x = 0; ... |
#include bits/stdc++.h using namespace std; typedef long long ll; typedef long double ld; typedef unsigned long long ull; #define int ll #define sz(a) int(a.size()) #define dbg(a) cout << #a << = << a << endl #define dbg1(a) cout << #a << = [ ; for (auto& _ : a) cout << _ << ; cout << ] <<... |
#include <bits/stdc++.h> using namespace std; int main(void) { int n, a[12][12]; cin >> n; memset(a, 0, sizeof(a)); for (int i = 1; i <= n; i++) { a[1][i] = 1; a[i][1] = 1; } for (int i = 2; i <= n; i++) { for (int j = 2; j <= n; j++) { a[i][j] = a[i - 1][j] + a[i][... |
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; vector<pair<int, int>> v(n); vector<int> v2(k); for (int i = 0; i < n; i++) { cin >> v[i].first; v[i].second = i + 1; } sort(v.begin(), v.end()); int sum = 0; for (int i = 0; i < k; i+... |
#pragma GCC optimize ( Ofast ) #include<bits/stdc++.h> using namespace std; void*wmem; char memarr[96000000]; template<class S, class T> inline S min_L(S a,T b){ return a<=b?a:b; } template<class T> inline void walloc1d(T **arr, int x, void **mem = &wmem){ static int skip[16] = {0, 15, 14, 13, 12,... |
#include <bits/stdc++.h> using namespace std; int n; struct Trie { int trie[6000005][2]; int cnt[6000005]; int root = 0; long long val[6000005]; long long xorsum = 0; long long ans[6000005 / 10]; int C = 0; int newroot() { trie[C][0] = trie[C][1] = -1; cnt[C] = 0; ... |
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) using namespace std; void err(istream_iterator<string> it) {} template <typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cerr << *it << = << a << endl; err(++it, args...); } long long powm(long long ... |
#include <bits/stdc++.h> using namespace std; const double g = 9.8; const double eps = 1e-9; int n, m, v; struct Ques { double angle; int id; } ques[10010]; struct Wall { double x, y; } wall[100010]; double ans_x[10010], ans_y[10010]; bool cmp(const Ques &a, const Ques &b) { return a.ang... |
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; k--; int a[n]; int sum = 0; for (int i = 0; i < n; ++i) { cin >> a[i]; } if (a[k] == 1) sum++; for (int i = 1; i < n; ++i) { if (k - i < 0) { for (int j = k + i; j < n; ++j) { ... |
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const double eps = 1e-6; const int mod = 1000000007; inline string getstr(string &s, int l, int r) { string ret = ; for (int i = l; i <= r; i++) ret.push_back(s[i]); return ret; } int modpow(int x, int y, int md = mod)... |
#include <bits/stdc++.h> const int nax = 1e5 + 5; using namespace std; int gcd(int x, int y) { if (x % y == 0) return y; return gcd(y, x % y); } int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ; int n, m; cin >> n >> m; vector<int> a(n + 1), b(m + 1... |
#include <bits/stdc++.h> using namespace std; bool check(int p) { if (p == 2) return 1; if (p % 2 == 0) return 0; for (long long int i = 3; i * i <= p; i += 2) { if (p % i == 0) return 0; } if (p > 2) return 1; return 0; } int main() { ios_base::sync_with_stdio(false); cin.... |
#include <bits/stdc++.h> using namespace std; map<int, int> m; bool fd(int x, int y) { if (x == y) return m[y] >= 2; return m.find(y) != m.end(); } int main() { int n; cin >> n; for (int i = 0; i < (n); i++) { int x; cin >> x; m[x]++; } int cnt = 0; for (auto&... |
#include <bits/stdc++.h> using namespace std; int main() { long long i, j, k, l, a, v, b, n, m; string s; while (cin >> s) { k = 0; j = 0; l = s.size(); for (i = 0; i < l; i++) { if (s[i] == W && s[i + 1] == U && s[i + 2] == B ) { i = i + 2; if (k... |
#include <bits/stdc++.h> using namespace std; inline int read(); int a[14250]; unsigned long long ans; bool cmp(int a, int b) { return a < b; } int main() { int n = read(), k = read(); for (int i = 1; i <= n; i++) { a[i] = read(); } sort(a + 1, a + n + 1, cmp); for (int i = 1; i <=... |
#include <bits/stdc++.h> using namespace std; vector<int> adj[1000009]; int in[1000009], out[1000009]; bool vs[22][1000009]; void dfs(int x, int n) { vs[x][n] = 1; for (auto& it : adj[n]) if (!vs[x][it]) dfs(x, it); } int main() { int N, M; scanf( %d%d , &N, &M); while (M--) { ... |
#include <bits/stdc++.h> using namespace std; char z[500005]; int Qs1[500005], b, Qs2[500005]; int f(char a) { if (a == w ) return b + 1; return 1; } int main() { int i, j, n, a, t, Max = 0; int *qs2 = Qs2 + 1, *qs1 = Qs1 + 1; scanf( %d %d %d %d , &n, &a, &b, &t); gets(z); qs1[... |
#include <bits/stdc++.h> using namespace std; int a[105][105], c[105], r[105]; int main() { int n, m; cin >> n >> m; for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) cin >> a[i][j]; for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) { c[j] += a[i][j]; r[... |
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; const long long N = 2e5 + 5; const double pi = acos(-1.0); long long addM(long long a, long long b) { return (a + b) % MOD; } long long multM(long long a, long long b) { return (a * b) % MOD; } long long binpow(long long a, long ... |
#include <bits/stdc++.h> #pragma GCC target( avx2 ) #pragma GCC optimization( O3 ) #pragma GCC optimization( unrolled-loops ) using namespace std; const long long mod = 1e9 + 7; int test = 1; const int N = 100100; long long n; int k = 1; long long x = 1; int main() { ios_base::sync_with_stdio(... |
#include <bits/stdc++.h> using namespace std; const int N = 2e6 + 10; int a[N], nx[N]; long long pr[N]; int main() { int n, q; scanf( %d %d , &n, &q); for (int i = 1; i <= n; i++) scanf( %d , &a[i]), a[i + n] = a[i]; for (int i = 1; i <= n + n; i++) pr[i] = pr[i - 1] + a[i]; while (q--) { ... |
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; int n, q; char s[N]; struct node { int s, x, z, xz, zy, d; } tr[N << 2]; void upd(int o) { int S = tr[(o << 1)].s, lx = tr[(o << 1)].x, lz = tr[(o << 1)].z, lxz = tr[(o << 1)].xz, lzy = tr[(o << 1)].zy; int rx = tr[(o... |
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1.0); const double eps = 1e-11; long long n, k; bool solveIt(long long d1, long long d2) { if ((k - d1 + d2) % 3 != 0) return false; long long Y = (k - d1 + d2) / 3; long long X = d1 + Y; long long Z = Y - d2; if (X >= 0... |
#include <bits/stdc++.h> using namespace std; int main() { long long n, m; cin >> n >> m; vector<pair<long long, long long> > v; for (int i = 0; i < m; i++) { long long a, b; cin >> b >> a; v.push_back(make_pair(a, b)); } sort(v.rbegin(), v.rend()); long long total = 0,... |
#include <bits/stdc++.h> using namespace std; const int MOD = 1000000007; const int MAX = 1000005; int SetBit(int n, int x) { return n | (1 << x); } int ClearBit(int n, int x) { return n & ~(1 << x); } int ToggleBit(int n, int x) { return n ^ (1 << x); } bool CheckBit(int n, int x) { return (bool)(n & (1 ... |
#include <bits/stdc++.h> using namespace std; int max(int &a, int &b) { return (a > b ? a : b); } unsigned long long max(unsigned long long &a, unsigned long long &b) { return (a > b ? a : b); } int min(int &a, int &b) { return (a < b ? a : b); } long long int bits_needed(long long int val) { long l... |
#include <bits/stdc++.h> using namespace std; int n, d, sum, ans; char s[105]; int main() { scanf( %d %d , &n, &d); for (int i = 0; i < d; i++) { scanf( %s , s); bool ok = true; for (int j = 0; j < n; j++) if (s[j] == 0 ) ok = false; if (ok) sum = 0; else ... |
#include <bits/stdc++.h> using namespace std; const int N = 5000005; using ll = long long; ll f[N], pre[N]; int n, a[N]; vector<int> ans; void move(int x) { if (x == n || a[x] == 0 || a[x + 1] == 0) return; ans.push_back(x); int t = min(a[x], a[x + 1]); a[x] -= t; a[x + 1] -= t; } ... |
#include <bits/stdc++.h> using namespace std; inline int ReadInt() { int i = 0; char c = 0; char flag = 1; while ((c < 0 || c > 9 ) && c != - ) c = getchar(); if (c == - ) { flag = 0; c = getchar(); } for (; c >= 0 && c <= 9 ; c = getchar()) i = i * 10 + c - 0 ; ... |
#include <bits/stdc++.h> using namespace std; int Matrix[1002][2002]; int max(int a, int b) { if (a > b) return a; else return b; } int min(int a, int b) { if (a < b) return a; else return b; } int distance(int a, int b, int c) { int first, second; first = a... |
#include <bits/stdc++.h> using namespace std; long long max(long long a, long long b) { return a > b ? a : b; } long long min(long long a, long long b) { return a < b ? a : b; } void fun(int arr[], int n) { stack<int> s; int left[n + 1]; int right[n + 1]; for (int i = 0; i < n; i++) { left... |
#include <bits/stdc++.h> int K; int main() { scanf( %d , &K); if (K % 2) { puts( YES ); if (K == 1) { puts( 2 1 n1 2 ); return 0; } int i, j, N = (K << 1) + 4, M = (3 * K - 2 + (K - 1) * (K - 2) / 2 - K / 2) * 2 + 1, tmp1 = K + 1, tmp2 ... |
#include <bits/stdc++.h> using namespace std; const int N = 3050; int F[N][N]; char buf[N]; vector<int> row[N]; short S[N][N]; inline short get(int y1, int x1, int y2, int x2) { return S[y2][x2] + S[y1][x1] - S[y2][x1] - S[y1][x2]; } int A[N]; int n, m, k; short to_L[N], to_R[N]; short path[... |
#include <bits/stdc++.h> using namespace std; long n, tim; string st; long lpos, calc1, calc2; long need, ans, calc; long l, r, has, bad; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> tim; cin >> st; lpos = -1; for (int i = 0; i < st.size(); i++) { if (st... |
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; if (n % 2 == 0) cout << NO << endl; else { cout << YES << endl; cout << 1 << ; for (int i = 4; i < 2 * n; i += 4) cout << i << << i + 1 << ; for (int i = 2; i < 2 * n; i += 4) cout... |
#include <bits/stdc++.h> using namespace std; int main() { int n, SF, FS; SF = FS = 0; string flights; cin >> n >> flights; for (int i = 0; i < flights.size() - 1; i++) { if (flights[i] == S && flights[i + 1] == F ) { SF++; } else if (flights[i] == F && flights[i + 1] ==... |
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 100; struct Node { int id, w; }; vector<int> g[maxn]; vector<Node> gg; bool vis[maxn]; int dfs(int u) { vis[u] = 1; for (int i : g[u]) { if (!vis[i]) { return dfs(i); } } return u; } int main... |
#include <bits/stdc++.h> using namespace std; long long n, k; int a[200007]; long long fac[200007]; long long inv[200007]; long long pw2[200007]; long long free_pw[200007]; long long fastpow(long long x, long long st) { long long ret = 1; while (st > 0) { if ((st & 1) != 0) { ret =... |
#include <bits/stdc++.h> using namespace std; int main() { int n, ans = 0; cin >> n; n -= 10; if (n == 11) { ans += 4; n -= 11; } if (n == 10) { ans = (4 * 4) - 1; n -= 10; } for (int i = 9; i >= 1; --i) { if (n == i) { ans += 4; n -= i; ... |
#include <bits/stdc++.h> using namespace std; double dist[5001][5001]; double x[5001], y[5001], z[5001]; int n; double sqr(double x) { return x * x; } int main() { cin >> n; for (int i = 1; i <= n; i++) cin >> x[i] >> y[i] >> z[i]; for (int i = 1; i <= n; i++) { for (int j = i + 1; j <= n;... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ; int n, m; cin >> n >> m; string s, t; cin >> s >> t; int mincnt = n + 1; int nin = -1; for (int i = 0; i <= m - n; i++) { int cnt = 0; ... |
#include <bits/stdc++.h> int days(int y) { if (y % 400 == 0 || (y % 4 == 0 && y % 100 != 0)) { return 366; } else { return 365; } } int main() { int year, i, d, di, dii; unsigned long long int count = 0; scanf( %d , &year); d = days(year); di = d; for (i = year;; i+... |
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int ar[n], a, b, sum = 0; for (int i = 0; i < n - 1; i++) cin >> ar[i]; cin >> a >> b; a--; b--; for (int i = a; i < b; i++) sum += ar[i]; cout << sum << endl; return 0; } |
#include <bits/stdc++.h> using namespace std; const int inf = 1 << 28; const double INF = 1e12, EPS = 1e-9; int n, m, c[101]; void run() { cin >> n >> m; for (int i = 0; i < m; i++) { int a, b; cin >> a >> b; for (; a <= b; a++) c[a]++; } for (int i = 1; i <= n; i++) if... |
#include <bits/stdc++.h> using namespace std; int n; int a[1501]; int calcinv() { int j; int rez = 0; for (int i = 1; i <= n; i++) for (j = i + 1; j <= n; j++) if (a[i] > a[j]) rez++; return rez; } int main() { int i, nri, j, m, l, r, lg; cin >> n; for (i = 1; i <= ... |
#include <bits/stdc++.h> using namespace std; void swap(int &a, int &b) { int temp = a; a = b; b = temp; } int main() { int n; cin >> n; int x[n], y[n], min_x = INT_MAX, max_y = INT_MIN; for (int i = 0; i < n; i++) { cin >> x[i] >> y[i]; if (x[i] < min_x) min_x = x[i]; ... |
#include <bits/stdc++.h> using namespace std; char s[1000010], t[1000010]; int ls, lt; int sum[1000010][3][3]; int main() { scanf( %s%s , s + 1, t + 1); ls = strlen(s + 1); lt = strlen(t + 1); if (ls > lt) { swap(ls, lt); swap(s, t); } for (int i = 1; i <= ls; ++i) { ... |
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; void no() { cout << NO n ; exit(0); } int main() { int n; cin >> n; vector<int> arr(n); for (int i = 0; i < n; ++i) cin >> arr[i]; sort(arr.begin(), arr.end()); for (int i = n - 1; i >= 0; --i) { arr[... |
#include <bits/stdc++.h> using namespace std; const int N = 1000 * 100 + 10; const long long INF = 1000 * 1000 * 1000LL * 1000 * 10000; int n, q, pt = 1, cnt; vector<long long> ans; set<pair<long long, long long> > s; set<pair<long long, long long> >::iterator it1, it2; long long po[100], a[N], sum[N * ... |
#include <bits/stdc++.h> using namespace std; const int B = 12; const int D = 64; const int MASK = 1030; int q, b; long long f[B][D][MASK]; long long sum[B][D]; long long call(int base, int rem, int mask) { if (rem <= 0) return mask == 0; long long &ret = f[base][rem][mask]; if (ret != -1) r... |
#include <bits/stdc++.h> using namespace std; int main() { long long int n, a, b, c, result = 0, i, x, y, j = 0; cin >> n >> a >> b >> c; for (i = 0; i <= min(n, a / 2); i++) { x = min(c, (n - i) / 2); y = min(i + b, n); if (y - (n - x * 2) / 2 >= 0) { if (y >= n - x * 2) resul... |
#include <bits/stdc++.h> using namespace std; template <class T> inline T BM(T p, T e, T M) { long long int ret = 1; for (; e > 0; e >>= 1) { if (e & 1) ret = (ret * p) % M; p = (p * p) % M; } return (T)ret; } template <class T> inline T gcd(T a, T b) { if (b == 0) return a; ... |
#include <bits/stdc++.h> using namespace std; int main() { int b, g, n; scanf( %d%d%d , &b, &g, &n); printf( %d n , min(b, n) - (n - min(g, n)) + 1); return 0; } |
#include <bits/stdc++.h> using namespace std; int cf[45], nc[45]; vector<int> ppf[45]; bool canadd(int i, int m) { for (int p : ppf[m]) { if (nc[p] && cf[p] != i % p) return false; } return true; } void add(int i, int m) { for (int p : ppf[m]) { if (nc[p] == 0) cf[p] = i % p; ... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t, n, num; cin >> t; while (t--) { cin >> n; bool flag = false; unordered_map<int, vector<int>> m; for (int i = 0; i < n; ++i) { cin >> num; m[n... |
#include <bits/stdc++.h> using namespace std; struct arr { int i; double s; } e[1506]; int n, m, x[1506], y[1506], w[1506], f[1506][1506], v[1506][2]; double ans, s[1506]; inline bool cmp(arr x, arr y) { return x.s > y.s; } int main() { scanf( %d , &n); for (int i = 1; i <= n; i++) s... |
#include <bits/stdc++.h> using namespace std; const int maxn = 61 * 30 + 5; pair<int, int> C[62]; int M, A[32], cc; bool dp[32][62][maxn], D[62][62]; short int fr[32][62][maxn]; int main() { scanf( %d , &M); for (int i = 1; i <= M; ++i) scanf( %d , A + i); sort(A + 1, A + M + 1); dp[0][0][... |
#include <bits/stdc++.h> using namespace std; const char *par = () ; const int pm[] = {1, -1}; int n; int mn, res, fir; string s; vector<int> v, w; map<int, int> mp; int init(string s) { v = vector<int>(n); for (int i = 0, pre = 0; i < n; ++i) { v[i] = (pre += pm[strchr(par, s[i]) - par... |
#include <bits/stdc++.h> using namespace std; inline bool cmp(const pair<int, int> &a, const pair<int, int> &b) { if (a.first != b.first) return a.first > b.first; return a.second < b.second; } int a[1000005], b[1000005]; char s[1000005], r[1000005]; int test; int main() { int t, n, m, k, l, x... |
#include <bits/stdc++.h> using namespace std; int n, a[200005]; void slove() { int temp, u, v, w, m; for (int i = 1; i <= n; i++) cin >> temp, a[i] = 0x3f3f3f3f; cin >> m; for (int i = 1; i <= m; i++) { cin >> u >> v >> w; if (a[v] > w) a[v] = w; } int flag = 1, k = 1; int ... |
#include <bits/stdc++.h> using namespace std; const long long INF = (1ll << 60); const int N = 205; int n, m, _len; int nxt[N]; long long k; long long ADD(long long x, long long y) { return min(INF, x + y); } struct node { char pref[N]; char suff[N]; long long len; long long sum; } t[N... |
#include <bits/stdc++.h> using namespace std; const int B = 27397, MOD = 1e9 + 7; const int B1 = 33941, MOD1 = 1e9 + 9; int t; inline void solve() { int r, n; scanf( %d%d , &n, &r); --r; int sum = 0; for (int i = 0; i < n - 1; ++i) { int x; scanf( %d , &x); --x; sum... |
#include <bits/stdc++.h> using namespace std; vector<vector<pair<int, long long> > > g; int n, a[100005]; bool erased[100005]; void dfs(int cur, long long cost, long long minCost) { if (cost - minCost > 1ll * a[cur]) { erased[cur] = 1; return; } for (int i = 0; i < g[cur].size(); i++) ... |
#include <bits/stdc++.h> using namespace std; int n, m; int fibo[200005], t[20][200005], f[20][200005], a[1000006], g[200005], h[200005], s[200005]; void FWT_or(int*, int, int); void FWT_and(int*, int, int); void FWT_xor(int*, int, int); void init(); int main() { init(); scanf( %d , &n); ... |
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; const long long N = 1e5 + 10; long long power(long long a, long long b) { long long ret = 1; while (b) { if (b & 1) ret *= a; a *= a; if (ret >= MOD) ret %= MOD; if (a >= MOD) a %= MOD; b >>= 1; ... |
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; cout << n << ; for (int i = 1; i < n; i++) { cout << i << ; } } |
#include <bits/stdc++.h> template <typename T> inline bool MIN(T &a, const T &b) { return a > b ? a = b, 1 : 0; } template <typename T> inline bool MAX(T &a, const T &b) { return a < b ? a = b, 1 : 0; } using namespace std; int n, m, K, p; int exgcd(int a, int b, int &x, int &y) { if (b ==... |
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); long long m, n, b[12345], w[12345], u, v, d = 0, c = 0; int mx = INT_MIN, mn = INT_MAX; string p[123]; char ch; bool sorted; cin >> n >> m; vector<int> a(n); for (int row = 0; ... |
#include <bits/stdc++.h> using namespace std; int top = 0; int N, Q, NN; int K, M, R; vector<int> Adj[100005]; int dep[100005]; int anc[100005][21]; int pre[100005], pst[100005], tt; void dfs(int u) { pre[u] = ++tt; for (int j = 1; j <= 20; j++) { if (dep[u] <= (1 << j)) break; anc... |
#include <bits/stdc++.h> using namespace std; const int N = 255; const int M = 16; const int mod = (int)1e9 + 7; char grid[N][N], ngrid[N][N]; long long dp[2][M][1 << M][2][2]; void add(long long& a, long long b) { a += b; while (a >= mod) { a -= mod; } } int main() { int n, m; ... |
#include <bits/stdc++.h> using namespace std; long long int n, k, a[100007]; pair<long long int, long long int> cur[1007]; bool res[200001]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> k; for (long long int i = 1; i <= n; ++i) cin >> a[i]; long long int last = 0, cnt... |
#include <bits/stdc++.h> using namespace std; int main() { int s, x1, x2; cin >> s >> x1 >> x2; int t1, t2; cin >> t1 >> t2; int time_for_igor = abs(x1 - x2) * t2; int p, d; cin >> p >> d; int time_for_tram = -1; if (x2 > x1) { if (d == 1) { if (p > x1) { ... |
#include <bits/stdc++.h> using namespace std; const int N = 2005; bool f[N][N]; int x[3005], y[3005]; int main() { int n; cin >> n; for (int i = 1; i <= n; i++) { cin >> x[i] >> y[i]; f[x[i] + 1000][y[i] + 1000] = true; } int ans = 0; for (int i = 1; i <= n; i++) { fo... |
#include <bits/stdc++.h> using namespace std; int main() { float num; int t, n, d; cin >> num >> t >> n >> d; int a = (num / n); if ((num / n) > a) a += 1; int y = d, x = 0; for (int i = 0; i < a; i++) { if (x <= y) x += t; else y += t; } if (max(x, y)... |
#include <bits/stdc++.h> using namespace std; void _print(long long 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 long t)... |
#include <bits/stdc++.h> using namespace std; const int MAX_N = 14; int a[MAX_N]; void add(int st, int x) { for (int i = 0; i < MAX_N; i++) a[i] += x / MAX_N; for (int i = 1; i <= abs(x % MAX_N); i++) a[(st + i) % MAX_N] += (x < 0 ? -1 : 1); } long long point() { long long ans = 0; for... |
#include <bits/stdc++.h> using namespace std; bool isNonDegenerateTriangle(int a, int b, int c) { return (a + b > c && b + c > a && c + a > b); } bool isDegenerateTriangle(int a, int b, int c) { return (a + b == c || b + c == a || c + a == b); } int main() { int n; cin >> n; long long in... |
#include <bits/stdc++.h> using namespace std; const int N = 260; const int mod = 777777777; int n, m, C[N][N], f[N][N][N]; int ans[9][1 << 8] = { {0}, {2, 1}, {32, 30, 80, 109}, {6824, 59808, 147224, 415870, 1757896, 1897056, 4898872, 7593125}, {776830421, 290516100, 746623577, 2... |
#include <bits/stdc++.h> using namespace std; int n, m, tmp; long long A[1005]; long long B[1005]; long long Acost(int q) { q *= 4; long long ret = 0; for (int i = 1; i <= n; i++) { long long tmp2 = i * 4 - 2 - q; ret += A[i] * tmp2 * tmp2; } return ret; } long long Bcost(i... |
#include <bits/stdc++.h> using namespace std; const int MAX = 1005; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); long long rand(long long a, long long b) { return uniform_int_distribution<long long>(a, b)(rng); } const int K = 3; struct Hash { long long a[K]; Hash() : a... |
#include <bits/stdc++.h> using namespace std; const int N = 210; int n; int a[N]; bool vis[N]; int lp[N]; int dis[N]; int inloop(int v) { vis[v] = 1; int u = a[v]; int cnt = 1; while (u != v && !vis[u]) { vis[u] = 1; ++cnt; u = a[u]; } if (u == v) return cnt; ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.