func_code_string stringlengths 59 71.4k |
|---|
#include <bits/stdc++.h> const int INF = 200000000; using namespace std; int timer, lg, n; vector<vector<int> > g; vector<vector<int> > dp(200005); int time_in[200005], time_out[200005], parent[200005], a[200005]; void DFS(int, int); bool issubtree(int, int); int lca(int, int); int main() { ios:... |
#include <bits/stdc++.h> using namespace std; int main() { int a; string b; cin >> a >> b; while (a++) { int i = a; string comp = ; while (i > 0) { int c = i % 10; if (c == 4 || c == 7) { comp = to_string(c) + comp; } i /= 10; } ... |
#include <bits/stdc++.h> using namespace std; int h1, h2; int a, b; int ans = 0; int main() { scanf( %d%d , &h1, &h2); scanf( %d%d , &a, &b); h1 += a * 8; if (h1 >= h2) printf( 0 n ); else if (h1 < h2 && b >= a) printf( -1 n ); else if (h1 < h2 && b < a) { int num1 = ... |
#include <bits/stdc++.h> using namespace std; #pragma warning(disable : 4996) class BIT { public: vector<int> bit; int size_ = 0; void init(int sz) { size_ = sz + 2; bit.resize(size_ + 2, 0); } void add(int pos, int x) { pos++; while (pos <= size_) { bit[pos]... |
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; inline long long rd() { long long x = 0, w = 1; char ch = 0; while (ch < 0 || ch > 9 ) { if (ch == - ) w = -1; ch = getchar(); } while (ch >= 0 && ch <= 9 ) { x = (x << 3) + (x << 1) + (ch ^ 48); ... |
#include <bits/stdc++.h> int main() { int d1, d2, d3, sum = 0; scanf( %d%d%d , &d1, &d2, &d3); if (d1 >= d2) { sum += d2; } else { sum += d1; } if (d1 + d2 >= d3) { sum += d3; } else { sum += d1 + d2; } if ((d1 >= d2) && (d1 <= d2 + d3)) { sum += d1; ... |
#include <bits/stdc++.h> using namespace std; const int maxn = 2000 * 100 + 10, mod = 1000000007; long long a[maxn]; int main() { ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); int t; t = 1; while (t--) { long long n; cin >> n; for (int i = 0; i < n; i++) { cin >... |
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e6 + 3; const int INF = 1e9; const int MOD = 1e9 + 7; int main() { long long n; long long ans = 1; cin >> n; long long p = 2; while (n > 1 && p * p <= n) { if (n % p) p++; else { n /= p; if ... |
#include <bits/stdc++.h> using namespace std; vector<int> r1, r2, cr; int main() { int n, prev = 0; cin >> n; r1.push_back(0); r2.push_back(0); for (int i = 0; i < n - 1; i++) { int w; cin >> w; w += prev; prev = w; r1.push_back(w); } prev = 0; for (in... |
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1.0); const double eps = 1e-11; const int INFINITE = 0x3f3f3f3f; template <class T> inline void checkmin(T &a, T b) { if (b < a) a = b; } template <class T> inline void checkmax(T &a, T b) { if (b > a) a = b; } template ... |
#include <bits/stdc++.h> using namespace std; struct Kid { int v, d; long long p; int id; }; void Transform(vector<Kid>& q) { int idx = -1; for (int i = 0; i < q.size(); ++i) { if (q[i].p < 0) { idx = i; break; } } if (idx == -1) return; for (int i = i... |
#include <bits/stdc++.h> using namespace std; const int M = 100000 + 10; struct NODE { long long int index; long long int a; bool operator<(const NODE& x) const { return a < x.a; } } node[M]; struct SUR { long long int index; long long int a; bool operator<(const SUR& x) const { return... |
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; struct Fib { long long a, b; Fib operator+(const Fib& o) const { return {(a + o.a) % MOD, (b + o.b) % MOD}; } }; struct FibOp { long long a, b, c, d; FibOp operator()(const FibOp& o) const { FibOp res ... |
#include <bits/stdc++.h> using namespace std; double p[100010]; double E[100010]; int main() { int n; cin >> n; p[0] = 0; E[0] = 0; double ans = 0; for (int i = 1; i <= n; ++i) { cin >> p[i]; E[i] = (1.0 - p[i - 1]) * p[i] + 2 * p[i] * p[i - 1] + p[i] * E[i - 1]; ans +=... |
#include <bits/stdc++.h> constexpr int N = 1.5e5, M = 1 << 18; int n, q; int parent[N], dep[N]; char ch[N]; int down[N], h[N], deg[N]; int mx[N][26], edge[N][26], sum[N]; int e[N][2]; int bad; void add(int u, int c, int v) { u = down[u]; edge[u][c] += v; for (u = parent[u]; u != -1; u = pa... |
#include <bits/stdc++.h> using namespace std; int main() { int n, m, k; int x[5001], y[5001], z[5001]; scanf( %d , &n); double mx = -10; for (int i = 0; i < n; i++) { scanf( %d , x + i); mx = max(mx, x[i] * 1.0); } scanf( %d , &m); for (int i = 0; i < m; i++) scanf( %d , ... |
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; int k, n, m, x, ans; int a[N]; string second, r; map<string, int> vis1, vis2; int main() { scanf( %d , &n); for (int i = 0; i < n; i++) { char e[50]; scanf( %s , e); r = second = e; while (second.find( kh ... |
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize trapv void solve() { int64_t n, x, y; cin >> n >> x >> y; vector<pair<int64_t, int64_t> > a; for (uint64_t i = 0; i < n; i++) { int u, v; cin >> u >> v; a.push_back(make_pair(u, v)); } sort(a.begin(), a.... |
#include <bits/stdc++.h> using namespace std; int main() { int x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2; int a = abs(x1 - x2); int b = abs(y1 - y2); int u = min(a, b); cout << u + abs(a - b); return 0; } |
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int arr[n][n]; for (int i = 0; i < n; i++) { string s; cin >> s; for (int j = 0; j < n; j++) { arr[j][i] = s[j]; } } int cnt = 0; for (int i = 0; i < n; i++) { for (int j = 0... |
#include<bits/stdc++.h> using namespace std; long long t,n;long long lowbit(long long x){return x&-x;} int main(){cin>>t;while(t--){cin>>n;if(!(n-lowbit(n)))puts( NO );else puts( YES );}} |
#include <bits/stdc++.h> using namespace std; const signed long long Infinity = 1000000100; const long double Epsilon = 1e-9; template <typename T, typename U> ostream& operator<<(ostream& os, const pair<T, U>& p) { return os << ( << p.first << , << p.second << ) ; } template <typename T> ostre... |
#include <bits/stdc++.h> inline char gc() { static const int L = 23333; static char sxd[L], *sss = sxd, *ttt = sxd; if (sss == ttt) { ttt = (sss = sxd) + fread(sxd, 1, L, stdin); if (sss == ttt) { return EOF; } } return *sss++; } template <class T> inline bool read(... |
#include <bits/stdc++.h> const long long M = 1e9 + 7; const double pi = 3.14159265358979323846; using namespace std; long long ans = 1; vector<long long> adj[2005]; long long vis[200005] = {0}; void dfs(long long x) { vis[x] = 1; for (long long i = 0; i < adj[x].size(); i++) { if (vis[adj[x]... |
#include <bits/stdc++.h> using namespace std; int n, cnt0 = 3; int g, r, b; bool markb = true, markg = true, markr = true; char id[ Z ][ Z ]; vector<char> st, m; int tt[500]; int main() { scanf( %d n , &n); for (int i = 1; i <= n; ++i) { char ch; scanf( %c , &ch); if (ch == B ... |
#include <bits/stdc++.h> using namespace std; int main() { int n, m; long int x, y; cin >> n >> m >> x >> y; long int* a = new long int[n]; long int* b = new long int[m]; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < m; i++) cin >> b[i]; int count = -1, indi = 0, indj ... |
#include <bits/stdc++.h> using namespace std; int main() { int r, b; cin >> r >> b; cout << max(r, b) - 1 << << min(r, b) << n ; return 0; } |
#include <bits/stdc++.h> using namespace std; double dp[1100][1100]; int n, m, x, y; int main() { int i, j, T; scanf( %d%d%d%d , &n, &m, &x, &y); if (m == 1) { printf( %d n , (n - x) * 2); return 0; } for (i = n - 1; i >= x; --i) for (T = 1; T <= 60; ++T) for (j = 1... |
#include <bits/stdc++.h> using namespace std; int n, in = 2; long long suma, bit[1000000]; double x, y, w, ab[100003]; pair<double, double> ar[100004]; map<double, int> busca; void updt(int p) { for (int i = p; i <= n; i += (i & -i)) bit[i]++; } int query(int p) { int s = 0; for (int i = p... |
#include <bits/stdc++.h> using namespace std; const int MAXN = 305; vector<pair<int, int> > e; vector<int> b; int a[MAXN]; bool mark[MAXN], x[MAXN][MAXN]; int n, k, m, cnt; void add(int u, int v) { if (x[u][v]) return; cnt++; e.push_back(pair<int, int>(u, v)); x[u][v] = x[v][u] = true; ... |
#include <bits/stdc++.h> using namespace std; const int COUNT = 600; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int N; cin >> N; string S; cin >> S; vector<int> on_count(COUNT, 0); for (int i = 0; i < N; i++) { int a, b; cin >> a >> b; int goal = ... |
#include <bits/stdc++.h> using namespace std; double weight; struct edge { int u, v, used, id, w, flag; bool operator<(const edge &b) const { return w + weight * flag < b.w + weight * b.flag; } } e[200001]; const double eps = 1e-10; int n, m, k, p[10001]; int find(int x) { return p[x] ==... |
#include <bits/stdc++.h> using namespace std; template <class T> inline bool fs(T &x) { int c = getchar(); int sgn = 1; while (~c && c < 0 || c > 9 ) { if (c == - ) sgn = -1; c = getchar(); } for (x = 0; ~c && 0 <= c && c <= 9 ; c = getchar()) x = x * 10 + c - 0 ; x *= ... |
#include <bits/stdc++.h> using namespace std; int win(char a, char b) { if (a == 8 ) { if (b == 8 ) return 0; return (b == [ ? 1 : -1); } if (a == [ ) { if (b == [ ) return 0; return (b == ( ? 1 : -1); } if (a == ( ) { if (b == ( ) return 0; return (... |
#include <bits/stdc++.h> using namespace std; int n, k, G, T; string s; string solve() { for (int i = 0; i < s.size(); i++) if (s[i] == G ) G = i; for (int i = 0; i < s.size(); i++) if (s[i] == T ) T = i; if (G > T) swap(G, T); int i = 0; for (i = G; i < T; i += k) { if (... |
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n, a, b; cin >> n >> a >> b; vector<int> c(n); for (int i = 0; i < n; ++i) { cin >> c[i]; } int i = 0, j = n - 1; int ans = 0; while (i < j) { if (c[i] ==... |
#include <bits/stdc++.h> using namespace std; string smallest(string str) { int n = str.length(); if (n & 1) return str; int mid = n / 2; string s = smallest(str.substr(0, n / 2)); string t = smallest(str.substr(n / 2, n / 2)); if (s > t) swap(s, t); str = s + t; return str; } in... |
#include <bits/stdc++.h> using namespace std; const int N = 300100; priority_queue<pair<long long, int>, vector<pair<long long, int> >, greater<pair<long long, int> > > vec[N]; vector<int> g[N]; long long tag[N]; int fa[N], fat[N], sz[N]; int find(int x) { return fa[x] == x ? x : fa... |
#include <bits/stdc++.h> using namespace std; int dx[4] = {-1, 1, 0, 0}; int dy[4] = {0, 0, -1, 1}; int sx, sy; char m[1005][1005]; int vis[1005][1005][4]; int flag; int n, k; void bfs(int x, int y, int l, int c) { if (x < 0 || x >= n || y < 0 || y >= k) return; if (m[x][y] == * ) return; ... |
#include <bits/stdc++.h> using namespace std; const int L = 1000 + 10; int b[L]; int w, m, l = 0; int main() { cin >> w >> m; if (w > 3) while (m) { int q = m % w; m /= w; if (q > 1 && q < w - 1) { cout << NO << endl; return 0; } if (... |
#include <bits/stdc++.h> using namespace std; int a[505][505]; int b[505][505]; priority_queue<int> aq[1005]; priority_queue<int> bq[1005]; int main() { int n, m; scanf( %d%d , &n, &m); for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) { scanf( %d , &a[i][j]); aq[i + ... |
#include <bits/stdc++.h> using namespace std; inline double f(int n) { return n * (n + 1) / 2; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n, k; cin >> n >> k; double P = 1. / f(n); vector<int> V(n); for (auto& x : V) cin >> x; vector<vector<vector<double>>> D... |
#include <bits/stdc++.h> using namespace std; int a[100005], f[100005]; int main() { int n, i; long long k; map<int, int> cnt; scanf( %d , &n); cin >> k; k--; for (i = 0; i < n; ++i) scanf( %d , &a[i]), cnt[a[i]]++; sort(a, a + n); f[0] = 0; for (i = 1; i < n; ++i) f[i] = a... |
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; const long long M = 1e9 + 7; const long long inf = 1e18 + 5; vector<int> pre_fn(string &s) { int n = s.size(); vector<int> pre(n); int pos = 0; pre[0] = 0; for (int i = 1; i < n; i++) { while (pos and s[pos] != s[i]... |
#include <bits/stdc++.h> #pragma comment(linker, /STACK:256000000 ) using namespace std; const double EPS = 1e-9; const double pi = acos(-1.0); const long long MAXN = (long long)1e5 + 7; const long long INF = (long long)1e9 + 7; const long long LINF = (long long)1 << 63 - 5; const long long MOD = (long... |
#include <bits/stdc++.h> using namespace std; long long int n, a[1000005], an = 0, fact = 1; long long int egcd(long long int aa, long long int bb, long long int &xx, long long int &yy) { if (aa == 0) { xx = 0, yy = 1; return bb; } long long int x1, y1, dd; dd = eg... |
#include <bits/stdc++.h> using namespace std; using ll = long long; const double PI = acos(-1.0); template <class Int> Int __gcd(Int a, Int b) { return (b == 0 ? abs(a) : __gcd(b, a % b)); } int dx[] = {0, 0, -1, 1, 1, 1, -1, -1}; int dy[] = {-1, 1, 0, 0, 1, -1, -1, 1}; const int N = 2e5 + 10; v... |
#include <bits/stdc++.h> using namespace std; const int inf = 1e9; inline void gmx(long long &x, long long y) { if (x < y) x = y; } inline void gmn(long long &x, long long y) { if (x > y) x = y; } inline int read() { char c = getchar(); int z = 0, f = 1; while (c != - && (c > 9 || ... |
#include <bits/stdc++.h> using namespace std; int n, m, a[11], b[11]; bool flag[11]; int main() { int i; scanf( %d%d , &n, &m); for (i = 1; i <= n; ++i) scanf( %d , &a[i]); for (i = 1; i <= m; ++i) scanf( %d , &b[i]), flag[b[i]] = true; for (i = 1; i <= n; ++i) if (flag[a[i]]) printf( ... |
#include <bits/stdc++.h> using namespace std; vector<vector<int>> graph; vector<int> isBlack; vector<long long> dp[2]; long long previous[2]; void dfs(int curr) { dp[0][curr] = 1 - isBlack[curr]; dp[1][curr] = isBlack[curr]; for (int child : graph[curr]) { dfs(child); previous[0] = d... |
#include <bits/stdc++.h> using namespace std; int main() { long long a, b, c, d, e, f; cin >> a >> b; c = a / 2; if (b < c || (a == 1 && b != 0)) cout << -1; else if (a == 1 && b == 0) cout << 1; else if (b % c == 0) { e = b / c; if (b / c != 1) { for (int i =... |
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; template <class T> void out(T x) { if (x < 0) { putchar( - ); x = -x; } if (x > 9) out(x / 10); putchar(x % 10 + 0 ); } long long dp[2005]; struct node { int x, y; } a[2005]; bool cmp(node a, ... |
#include <bits/stdc++.h> using namespace std; int ans; int main() { int a[101010]; int b, c; cin >> b >> c; for (int i = 1; i <= b; ++i) { cin >> a[i]; } for (int i = 1; i <= b; ++i) { if (a[i] > c) ans += 2; else if (a[i] <= c) ans++; } cout << an... |
#include <bits/stdc++.h> using namespace std; int n, k, sum; string a; int main() { cin >> n >> k; for (int i = (0); i < (n); i++) { int l, r; cin >> l >> r; sum += (r - l + 1); } if (sum % k == 0) cout << 0 << endl; else { int u = sum; while (u % k) u++; ... |
#include <bits/stdc++.h> using namespace std; int main() { long long int pos; cin >> pos; long long tmp = 0; long long n; for (int i = 1; i < 1000000000; i++) { tmp += i; if (tmp > pos) { n = n - (tmp - i); break; } if (tmp == pos) { n = i; ... |
#include <bits/stdc++.h> #pragma warning(disable : 4244 4267 4018 4996 4800) #pragma comment(linker, /stack:20000000 ) using namespace std; istream& in = cin; ostream& out = cout; vector<int> cnt; string s; int pos, res; vector<string> v; void parse(int node) { assert(s[pos] == < ); while ... |
#include <bits/stdc++.h> using namespace std; const int MaxN = 1e5; int main() { int a[5], b[5], s[5], vis; while (~scanf( %d %d %d , &a[1], &a[2], &a[3])) { sort(a + 1, a + 4); vis = 0; s[1] = 1; s[2] = 0; s[3] = 0; b[1] = 1; for (int i = 2; i <= MaxN; i++) { ... |
#include <bits/stdc++.h> using namespace std; const int N = 200001; long long a[N + 1], tree[4 * N], lazy[4 * N]; void build(int idx, int l, int r) { if (l == r) tree[idx] = a[l]; else { int m = (l + r) / 2; build(2 * idx, l, m); build(2 * idx + 1, m + 1, r); tree[idx] = mi... |
#include <bits/stdc++.h> #pragma comment(linker, /STACK:256000000 ) using namespace std; #pragma comment(linker, /STACK:100000000 ) using namespace std; const int L = 350; const int B = 1000000; const int LB = 6; class Long { public: int m[L], l; int &operator[](int i) { return m[i]; } ... |
#include <bits/stdc++.h> using namespace std; int main() { int n, x, y; cin >> n; vector<int> adj[n + 1], deg(n + 1, 0); vector<pair<int, int>> input; for (int i = 0; i < n - 1; i++) { cin >> x >> y; input.push_back(make_pair(x, y)); adj[x].push_back(y); adj[y].push_back(... |
#include <bits/stdc++.h> using namespace std; template <typename T> inline void Int(T &n) { n = 0; int f = 1; register int ch = getchar(); for (; !isdigit(ch); ch = getchar()) if (ch == - ) f = -1; for (; isdigit(ch); ch = getchar()) n = (n << 3) + (n << 1) + ch - 0 ; n = n * f; ... |
#include <bits/stdc++.h> using namespace std; const long long N = 2e5 + 5; const long long inf = 1e16 + 7; long long m, n, h; long long ans = 0; long long seg[4 * N]; long long lazy[4 * N]; long long ind[N]; vector<long long> b; vector<long long> a; void build(long long p, long long val, long long... |
#include <bits/stdc++.h> using namespace std; using ll = long long; const int N = 1e5 + 5, MOD = 1e9 + 7; const ll INF = 1e18 + 17; int n; void solve() { cin >> n; if ((n - 2) % 3 != 0) { cout << 1 1 << n - 2; } else { cout << 1 2 << n - 3; } } int main() { ios ::sy... |
#include <bits/stdc++.h> using namespace std; signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long n, k; cin >> n >> k; vector<long long> arr(n, 0); for (long long i = 0; i < n; i++) cin >> arr[i]; queue<pair<pair<long long, long long>, long long... |
#include <bits/stdc++.h> using namespace std; struct node { int y, ne; } e[200010]; int f[100005], h[100005], np, vis[100005], s; long long dp[100005], r[100005]; long long saya(int n) { if (dp[n] != -1) return dp[n]; vis[n] = 1; long long ans = 0, res = 0; vector<long long> v; for (... |
#include <bits/stdc++.h> using namespace std; const int N = 205; int val[N]; int dp[N][N]; vector<int> v[N]; int n, k; void solve(int node, int par) { dp[node][0] = val[node]; for (auto to : v[node]) { if (to != par) solve(to, node); } for (int dep = 0; dep < N; ++dep) { if (de... |
#include <bits/stdc++.h> using namespace std; int roundpow2(int x) { int y = 1; while (y < x) { y *= 2; } return y; } class SegmentTree { private: vector<pair<int, int>> tree; int sz; void push(int i) { if (tree[i] != make_pair(-1, -1)) { tree[i * 2 + 1] = tree... |
#include <bits/stdc++.h> using namespace std; int n, q; int a[1000010]; int d[1000010]; int lowbit(int x) { return x & -x; } void update(int x, int v) { while (x <= n) { d[x] += v; x += lowbit(x); } } int query(int x) { int res = 0; while (x) { res += d[x]; x -= l... |
#include <bits/stdc++.h> using namespace std; double dp[105][105][105]; void solve(int r, int s, int p) { double _r = 0, _s = 0, _p = 0; for (int i = r; i >= 0; i--) { for (int j = s; j >= 0; j--) { for (int k = p; k >= 0; k--) { double tot = i * j + j * k + k * i; if ((i... |
#include <bits/stdc++.h> using namespace std; int n, a[200005], b[30][200005], d[30][200005], c[200005], r[200005], l[200005]; long long ans = 0; int main() { scanf( %d , &n); for (int i = 0; i < n; i++) scanf( %d , &a[i]); for (int i = 0; i < 30; i++) { b[i][n] = n; for (int j = n - 1; ... |
#include <bits/stdc++.h> using namespace std; const long long MOD = static_cast<int>(1e9) + 7; using namespace std::rel_ops; inline long long bit(int x) { return 1LL << x; } template <class T> inline bool chmin(T& a, const T& b) { return a > b ? a = b, 1 : 0; } template <class T> inline bool chmax... |
#include <bits/stdc++.h> using namespace std; long long n, i, p[202020], ki[202020], ka[202020], ta, tb, taa, tbb, nx[202020]; void gab(long long aa, long long bb) { nx[ka[aa]] = ki[bb]; ka[aa] = ka[bb]; ki[bb] = ki[aa]; p[aa] = bb; } long long car(long long aa) { if (p[aa] == aa) re... |
#include <bits/stdc++.h> using namespace std; const int maxn = 200001; vector<char> now; char t[maxn], p[maxn]; int lt, lp, l, r; int a[maxn]; bool judge(int cur) { now.clear(); bool tmp[maxn]; for (int i = 1; i <= lt; i++) tmp[i] = true; for (int i = 1; i <= cur; i++) tmp[a[i]] = false; ... |
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; int tot = 0; int ch[5000001][2]; int s[5000001]; void insert(int x) { int Root = 0; for (int i = 30; i >= 0; i--) { int tmp = (x >> i) & 1; if (!ch[Root][tmp]) { ch[Root][tmp] = ++tot; s[tot] = 0; ... |
#include <bits/stdc++.h> using namespace std; void sapxep(int n, int b[]) { for (int i = 0; i < n; i++) { for (int i = 0; i < n - 1; i++) { if (b[i] < b[i + 1]) { int t = b[i]; b[i] = b[i + 1]; b[i + 1] = t; } } } } int main() { int n; ci... |
#include <bits/stdc++.h> using namespace std; long long n, sum; long long arr[105]; long long val[105]; void icchhipadey() { long long n; cin >> n; long long arr[n]; for (int i = 0; i < n; i++) { cin >> arr[i]; } long long f, x; cin >> f >> x; long long ans = 0; for (... |
#include <bits/stdc++.h> using namespace std; bool push(vector<int> &c, vector<int> &d, int f, int t, int x = -1) { if (x == -1) x = d[f]; x = min(x, d[f]); if (c[t] <= x) { d[f] -= c[t]; c[t] = 0; return true; } c[t] -= x; d[f] -= x; return false; } void solve() { ... |
#include <bits/stdc++.h> using namespace std; int n, a[300]; int main() { cin >> n; for (int i = 0; i < 2 * n; i++) { cin >> a[i]; } sort(a, a + 2 * n); if (a[n - 1] != a[n]) cout << YES << endl; else cout << NO << endl; } |
#include <bits/stdc++.h> using namespace std; const int T = 1e3 + 5; int g[T][T]; void add(int a, int b) { g[a][b] = g[b][a] = 1; } int last, K, a, b, i, j, N; int main() { cin >> K; add(0, 2); add(0, 3); for (i = 2; i <= 30; i++) { add(2 * i, 2 * i - 1); add(2 * i, 2 * i - 2); ... |
#include <bits/stdc++.h> using namespace std; vector<long long> a; int main() { long long t; cin >> t; for (long long ind = 0; ind < t; ++ind) { long long n, k; cin >> n >> k; string s; cin >> s; a.clear(); a.resize(26, 0); long long num = n / k, ans = 0; ... |
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; const long long MAXN = 1e5 + 100; long long F[MAXN]; int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); F[0] = 1; F[1] = 1; for (long long i = 2; i < MAXN; i++) F[i] = (F[i - 1] + F[i - 2]... |
#include <bits/stdc++.h> using namespace std; const int N = 112345; long long t[4 * N]; long long lzs[4 * N], lzm[4 * N]; int a[4 * N], b[4 * N]; void build(int i, int l, int r) { if (l == r) { a[i] = b[i] = l; } else { int m = (l + r) / 2; build(2 * i, l, m); build(2 * i + 1... |
#include <bits/stdc++.h> using namespace std; const int Q = 86401; int n, M, T; int R, res[20000]; vector<int> in[Q]; vector<int> out[Q]; int outTime[20000]; int main() { scanf( %d%d%d , &n, &M, &T); int a, b, c; for (int i = 0; i < n; ++i) { scanf( %d:%d:%d , &a, &b, &c); a = a ... |
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 5; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const long long B = uniform_int_distribution<int>(333, 999)(rng); const long long MOD1 = 1792209677, MOD2 = 1211874137; template <class T> pair<T, T> operator+(const pa... |
#include <bits/stdc++.h> using namespace std; int main() { int n, a, b, c; cin >> n; vector<int> t(3); for (int &i : t) { cin >> i; } sort(t.begin(), t.end()); c = t[0]; b = t[1]; a = t[2]; int x, y, z; int max = 0; for (z = n / c; z >= 0; z--) { for (y = ... |
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 87; int n, pa[N], de[N], f[N], dp[N], cc[N]; vector<int> g[N]; pair<int, int> md; void dfs(int p, int u, int d) { md = max(md, pair<int, int>(d, u)); pa[u] = p; de[u] = d; if (d == md.first) { dp[u] = 1; cc[u] = u;... |
#include <bits/stdc++.h> using namespace std; const int MOD = int(1e9 + 7), maxK = 23, maxN = 107; vector<int> a[maxN]; int n, k; int f[maxN][maxK][maxK], g[2][maxK][maxK]; inline void add(int &a, long long b) { a = (a + b) % MOD; } void calculate(int u, int par) { memset(g, 0, sizeof g); bool fir... |
#include <bits/stdc++.h> using namespace std; const int Maxn = 6010; vector<int> V; vector<int> G[Maxn]; int a[Maxn]; int dp[Maxn][2]; int n, ans; int getid(int x) { return lower_bound(V.begin(), V.end(), x) - V.begin() + 1; } struct Node *null; struct Node { Node *ch[2]; int r, v[2]; in... |
#include <bits/stdc++.h> using namespace std; int pos, ans, a[20], b[20], cnt[12]; bool check(int pos, bool Ls, bool Rs) { if (pos == 0) return true; if (!Ls && !Rs) return true; int l = Ls ? a[pos] : 0, r = Rs ? b[pos] : 9; for (int i = l; i <= r; i++) if (cnt[i]) { cnt[i]--; ... |
#include <bits/stdc++.h> using namespace std; int main() { unsigned long long int n, m, a, b; cin >> n >> m >> a >> b; if (n % m == 0) { cout << 0 ; return 0; } else if (n > m) { unsigned long long int p = (n / m) + 1; unsigned long long int c = (m * p - n) * a; unsign... |
#include <bits/stdc++.h> using namespace std; const long long INF = 1e18 + 5; const long long MAX_N = 1e5 + 5; const long long MODD = 1e9 + 7; 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; } double max(double a, double b) ... |
#include <bits/stdc++.h> using namespace std; template <typename TP> inline bool rd(TP& r) { r = 0; char tmp = getchar(); while (tmp < 0 || tmp > 9 ) { if (tmp == EOF) return 0; tmp = getchar(); } while ( 0 <= tmp && tmp <= 9 ) { r = (r << 3) + (r << 1) + tmp - 0 ; ... |
#include <bits/stdc++.h> using namespace std; const int M = 1e9 + 7; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t; cin >> t; while (t--) { int n; cin >> n; int a[n + 1]; for (int i = 0; i < n; i++) cin >> a[i]; map<int, int> mp; if (n ... |
#include <bits/stdc++.h> using namespace std; const long long base = 1e9 + 7; const long long MAX_N = 2e5 + 7; long long dd2[MAX_N]; void Solves() { long long n, k; cin >> n >> k; long long l[n + 1]; long long r[n + 1]; priority_queue<pair<long long, long long>, vector<p... |
#include <bits/stdc++.h> using namespace std; struct Node { int sz, val; Node *left, *right; Node() : left(NULL), right(NULL), sz(0), val(-1) {} ~Node() { delete left; delete right; } }; int A[200000]; void insert(Node*& curr, int i, int x) { if (curr == NULL) curr = new No... |
#include <bits/stdc++.h> struct IO { static const int L = 1000000; char a[L], b[L], *s, *t, *p, c; IO() : p(b) {} ~IO() { fwrite(b, 1, p - b, stdout); } char gc() { if (s == t) t = (s = a) + fread(a, 1, L, stdin); return *s++; } void gs(char* st) { for (c = gc(); !isgraph... |
#include <bits/stdc++.h> const int mod = 1e9 + 7; const int MAXN = 1e6 + 5; template <typename _T> void read(_T &x) { x = 0; char s = getchar(); int f = 1; while (s < 0 || 9 < s) { f = 1; if (s == - ) f = -1; s = getchar(); } while ( 0 <= s && s <= 9 ) { x ... |
#include <bits/stdc++.h> using namespace std; long long ans[1000001]; int main() { int n; cin >> n; string s; cin >> s; int rr = 0, num = 0; long long v = 1, v2 = 1; for (int i = 0; i < n; i++) { num++; v -= i; while (rr < n && num > 0) { if (s[rr] == D ) { ... |
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 1e3; string s, sq; int z1[maxn + 10], z2[maxn + 10], pref[1010], suff[1010], rez; void calc(string ss, int z[]) { int l = -1; int r = -1; for (int i = 1; i < ss.size(); i++) { if (i > r) { l = i; r = l - 1; ... |
#include <bits/stdc++.h> using namespace std; const int maxn = 2000 + 10; const int maxE = 2000000 + 10; const int DEBUG = 0; int n, m; bitset<maxn> val[maxn]; char S[maxn]; struct anode { int u, v, w; anode() {} anode(int _u, int _v, int _w) : u(_u), v(_v), w(_w) {} } a[maxE]; int h[max... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.