func_code_string stringlengths 59 71.4k |
|---|
#include <bits/stdc++.h> using namespace std; long long int binExp(long long int a, long long int power, long long int m = 1000000007) { long long int res = 1; while (power) { if (power & 1) res = (res * a) % m; a = (a * a) % m; power >>= 1; } return res; }... |
#include <bits/stdc++.h> using namespace std; int ucln(int k, int l) { int t; while (l > 0) { t = l; l = k % l; k = t; } return (k); } int main() { int x, y, m, n, a, b; cin >> n >> m >> x >> y >> a >> b; int u = ucln(a, b); a /= u; b /= u; int na, nb; ... |
#include <bits/stdc++.h> const int MOD = 1e9 + 7; inline int addmod(int a, int b) { return (a + b) % MOD; } const int MAXN = 105; const int MAXM = 10005; int cnt[MAXN]; int n, a[MAXN]; int f[MAXN][MAXM]; int com[MAXN][MAXN]; int main() { for (int i = 0; i < MAXN; i++) { com[i][0] = 1; ... |
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; string s; cin >> s; string temp = s; sort(s.begin(), s.end()); int count = 0; for (int i = 0; i < s.size(); i++) if (s[i] != temp[i]) count++... |
#include <bits/stdc++.h> using namespace std; int a[5000]; int b[5000]; int main() { int n, m; cin >> n >> m; int x; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < m; i++) cin >> b[i]; sort(a, a + n); sort(b, b + m); int cura = 0; for (int i = 0; i < m && cura <... |
#include <bits/stdc++.h> using namespace std; const int N = 23, MXN = N * N * 4; struct Edge { int to, flow; }; struct Dinic { int s, t, P[MXN], D[MXN], qu[MXN]; vector<int> Adj[MXN]; vector<Edge> E; inline void Add(int v, int u, int w) { Adj[v].push_back(E.size()); E.push_back... |
#include <bits/stdc++.h> using namespace std; int arr[92]; int main() { int n; cin >> n; for (int i = 0; i < n; i++) cin >> arr[i]; if (n == 1) { if (arr[0] == 15) cout << DOWN ; else if (arr[0] == 0) cout << UP ; else cout << -1; } else { if (... |
#include <bits/stdc++.h> using namespace std; const int Maxn = 3000; int r, c, n; int k; struct Node { int x, y; friend bool operator<(Node a, Node b) { if (a.y == b.y) { return a.x < b.x; } return a.y < b.y; } } a[Maxn + 5], b[Maxn + 5]; int len; vector<int> g[Maxn... |
#include <bits/stdc++.h> using namespace std; long long int n, m; long long int arr[200005]; map<long long int, long long int> x; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; cin >> n >> m; for (int i = 0; i < n; ++i) cin >> arr[i]; long long int l = 0, sum = 0,... |
#include <bits/stdc++.h> using namespace std; const int M = 100005; long long dp[M][2]; vector<int> G[M]; int color[M]; void dfs(int x) { long long ones, zeros; ones = color[x]; zeros = 1 - color[x]; int u; for (int i = 0; i < G[x].size(); i++) { u = G[x][i]; dfs(u); on... |
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const long long LINF = 0x3f3f3f3f3f3f3f3fLL; const double EPS = 1e-8; const int MOD = 1000000007; const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1}; int main() { cin.tie(0); ios::sync_with_stdio(false); int h, w; ... |
#include <bits/stdc++.h> using namespace std; const long long oo = 1000000000000000000ll; const int N = 2020, M = 100100; int i, j, k, n, m, ch, ff, En, s, t, x, y, v, nls; int h[N], p[N], d[N], z[N], diss[N], dist[N]; long long c[N], Ls[N], Sum[N][N], Num[N][N], f[N][N][2]; struct edge { int s, n, v;... |
#include <bits/stdc++.h> using namespace std; const int MOD = 1000000007; int n; long long power[300009], arr[300009]; long long len, l, r, ans, add; int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); cin >> n; for (int i = 0; i < n; i++) { cin >> arr[i]; } power[0] = 1;... |
#include <bits/stdc++.h> using namespace std; int n, deg[100100], t[100100], legs[100100]; vector<int> adj[100100]; void dfs(int x, int px) { t[x] = 1; for (int i = 0; i < adj[x].size(); i++) { int u = adj[x][i]; if (u == px) continue; if (deg[u] <= 2) dfs(u, x); } } int main()... |
#include <bits/stdc++.h> using namespace std; vector<int> edge[100005]; int tp[100005], dst[100005], fa[100005], d[100005], son[100005]; int n, m, S = 1, E, mx, t = 1; queue<int> Q; void DFS(int &a, int p, int f, int d) { fa[p] = f, son[p] = 1; if (mx < d) { mx = d; a = p; } for ... |
#include <bits/stdc++.h> using namespace std; const double inf = 1e10; inline int cmp(double x, double y = 0, double tol = 1e-7) { return (x <= y + tol) ? (x + tol < y) ? -1 : 0 : 1; } struct ball { double x, v, m; int id; ball(double x = 0.0, double v = 0.0, double m = 0.0) : x(x), v(v), m(m)... |
#include <bits/stdc++.h> using namespace std; char buf[1 << 15], *fs, *ft; inline char getc() { return (fs == ft && (ft = (fs = buf) + fread(buf, 1, 1 << 15, stdin), fs == ft)) ? 0 : *fs++; } inline int read() { int x = 0, f = 1; char ch = getc(); whil... |
#include <bits/stdc++.h> using namespace std; const int MAX = 5 + 2e5; int in[MAX], k = 1; long long s[MAX], sorted[MAX], tos[MAX << 1], BIT[MAX << 1]; map<long long, int> mp; void add(int i, int val) { while (i > 0) { BIT[i] += val; i -= (i & (-i)); } } long long at_index(int i) { ... |
#include <bits/stdc++.h> using namespace std; int32_t main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; long long n; cin >> n; vector<long long> dp(n + 1, 0); long long s_odd = 0, s_even = 0; for (long long i = 1; i <= n; i++) { dp[i] = 1; if (i & 1) { ... |
#include <bits/stdc++.h> using namespace std; int main() { char conten[101]; int count1 = 0, count2 = 0, i; cin >> conten; int s = strlen(conten); for (i = 0; i <= s; i++) { if (conten[i] >= 65 && conten[i] <= 90) { count1++; } if (conten[i] >= 97 && conten[i] <= 122) {... |
#include <bits/stdc++.h> using namespace std; int v[1000005]; int main() { int n, m, i, first, second, lastdif = -0x3f3f3f3f; cin >> n; for (i = 1; i <= n; ++i) cin >> v[i]; for (i = 2; i <= n; ++i) { if (v[i] - v[i - 1] != lastdif && lastdif != -0x3f3f3f3f) { cout << v[n]; r... |
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; string s; cin >> s; int now = 0; for (int i = 0; i < n - 1; ++i) if (s[i] == . && s[i + 1] == . ) ++now; while (m--) { int pos; char ch; cin >> pos >> ch; --pos; if ... |
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5, INF = 1e9; bool check(int n, string s) { for (int i = 1; i <= n; i++) if (s[i] == 0 ) return false; cout << 1 << << n - 1 << << 2 << << n << endl; return true; } void sol(int n, string s) { for (int i = 1; ... |
#include <bits/stdc++.h> using namespace std; int n, k; double f[2][810]; int main() { scanf( %d%d , &n, &k); for (int i = 1; i * i <= n; ++i) f[0][i] = 0; int st = min(max(800.0, sqrt(n)), 1.0 * n); int c = 0; for (int i = 1; i <= n; ++i) { c ^= 1; for (int j = 1; j <= st; ++j) ... |
#include <bits/stdc++.h> using namespace std; const int N = 111111; pair<char, string> ev[N]; int n; int solve(char le) { set<char> st; for (int i = ( a ); i <= ( z ); i++) { st.insert(i); } int need = 0, has = 0; bool found = false; for (int i = (1); i <= (n); i++) { if (e... |
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1.0); const int N = 200010; const bool QUERY_MAX = true; const double INF = 1e30; struct Line { long long a, b, val; double xLeft; bool is_query; Line() {} Line(long long _a, long long _b) { a = _a; b = _b;... |
#include <bits/stdc++.h> int main(void) { int n; scanf( %d , &n); int a = 0, b = 1023; for (int i = 1; i <= n; ++i) { char ch[2]; int x; scanf( %s%d , ch, &x); if (ch[0] == & ) { a &= x; b &= x; } else if (ch[0] == | ) { a |= x; b |= x; ... |
#include <bits/stdc++.h> using namespace std; string s[] = { , January , February , March , April , May , June , July , August , September , October , November , December }; int main() { string t; int k; cin >> t >> k; int x; fo... |
#include <bits/stdc++.h> using namespace std; using LL = long long; using PII = pair<int, int>; int main() { int n; scanf( %d , &n); LL ansx, ansy; ansx = ansy = 0; n *= 2; for (int i = 1; i <= n; i++) { int x, y; scanf( %d%d , &x, &y); ansx += x; ansy += y; }... |
#include <bits/stdc++.h> using namespace std; using ll = long long; ll dp[2][5005]; int main() { cin.tie(0); cin.sync_with_stdio(0); int n, k, x; cin >> n >> k >> x; if (n / k > x) return cout << -1, 0; vector<int> a(n); for (auto &x : a) cin >> x; x = min(x, n); for (int i =... |
#include <bits/stdc++.h> using namespace std; int n; int l[10], r[10]; double Prob(int id, int a, int b) { int ini = max(a, l[id]); int fim = min(b, r[id]); if (b < l[id] || a > r[id]) return 0.0; double ret = (fim - ini + 1) * 1.0 / (double)(r[id] - l[id] + 1); return ret; } int main() ... |
#include <bits/stdc++.h> using namespace std; int n, ar[5005], bit[5005]; void add(int i) { while (i > 0) { bit[i]++; i -= (i & (-i)); } } int ask(int i) { int tmp = 0; while (i <= n) { tmp += bit[i]; i += (i & (-i)); } return tmp; } int main() { scanf( ... |
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, i; long long a, b; cin >> n; i = a = 0, b = 1000000001; int arr[n]; while (i < n) { cin >> arr[i]; i++; } i = n - 1; while (i >= 0) { ... |
#include <bits/stdc++.h> using namespace std; const double esp = 1e-5; int dis[30][30], du[30], id[30][30]; double p[30], a[500][500]; double solve(int i, int j, int x, int y) { double ans = 0; if (i == x && j == y) ans = p[i] * p[j]; else if (i == x && j != y) ans = p[i] * (1 - p[j]) ... |
#include <bits/stdc++.h> int main() { long int n, i, j, k, a, b, c, sum, ht; scanf( %ld , &n); i = 1; sum = 1; ht = 0; while (n > 0) { n = n - sum; sum = sum + i + 1; i++; if (n >= 0) { ht++; } } printf( %ld n , ht); } |
#include <bits/stdc++.h> using namespace std; int n, m; int ansx, ansy; int a[300005][10]; int b[300005]; int check(long long x) { memset(b, 0, sizeof(b)); for (int i = 1; i <= n; i++) { int p = 0; for (int j = 1; j <= m; j++) { if (a[i][j] >= x) p += (1 << (j - 1)); } ... |
#include <bits/stdc++.h> using namespace std; int mm[110][110]; int main() { int n, ss = 0, md; scanf( %d , &n); for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) scanf( %d , &mm[i][j]); if (n % 2 == 0) md = n / 2; else md = (n / 2) + 1; md--; for (int i = 0; i ... |
#include <bits/stdc++.h> using namespace std; namespace WorkSpace { const double pi = acos(-1.0); int N; double r, v; bool Check(double mid, double l) { double len = 2 * pi * r; double ang = mid / len * 2 * pi; double A = r - r * (cos(ang)); double B = r * sin(ang); return sqrt(A * A + B... |
#include <bits/stdc++.h> using namespace std; int n, i = 1, ans = 0; int main() { cin >> n; while (n > 0) { if (n % 2 == 1) { ans++; n -= 1; } n /= 2; } cout << ans << endl; } |
#include <bits/stdc++.h> using namespace std; const long long N = 1e3 + 9; string s; long long t, h, ans = 1e10; long long n; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n; cin >> s; for (int i = 0; i < (n); i++) { if (s[i] == T ) t++; else ... |
#include <bits/stdc++.h> using namespace std; inline long long read() { long long x = 0, flag = 1; char ch = 0; while (!isdigit(ch)) { ch = getchar(); if (ch == - ) flag = -1; } while (isdigit(ch)) { x = (x << 3) + (x << 1) + ch - 0 ; ch = getchar(); } return x ... |
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { long long int n; cin >> n; if (n == 1) { cout << 0 << n ; continue; } long long int ans = 0; while (n != 1) { ans++; if (n % 2 == 0) { ... |
#include <bits/stdc++.h> using namespace std; const int inf = 1e9 + 7; const long long llinf = 1e18 + 7; const double eps = 1e-15; const int mod = 1e9 + 7; int main() { ios::sync_with_stdio(false); int n, a[100001], k; cin >> n >> k; for (int i = 1; i <= n; i++) cin >> a[i]; int i = n; ... |
#include <bits/stdc++.h> using namespace std; int n; int a[200000 + 5]; vector<int> g[200000 + 5]; int cnt = 0; void dfs(int x, int fa) { cnt++; if (cnt > n) return; printf( %d , x); for (int i = 0; i < g[x].size(); i++) { int y = g[x][i]; if (y == fa) continue; dfs(y, x);... |
#include <bits/stdc++.h> using namespace std; long long int gcd(long long int a, long long int b) { if (a == 0) return b; else return gcd(b % a, a); } long long int lcm(long long int a, long long int b) { return (a * b) / gcd(a, b); } long long int fact(long long int n) { if (n =... |
#include <bits/stdc++.h> using namespace std; int a[100000]; int b[100000]; bool judge(long long x, int n, long long k) { for (int i = 0; i < n; ++i) { k -= max(0LL, a[i] * x - b[i]); if (k < 0) { return false; } } return true; } int main(void) { int n, k; asser... |
#include <bits/stdc++.h> using namespace std; inline long long mod(long long n, long long m) { long long ret = n % m; if (ret < 0) ret += m; return ret; } long long gcd(long long a, long long b) { return (b == 0LL ? a : gcd(b, a % b)); } long long exp(long long a, long long b, long long m) {... |
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; long long int t; t = 1; while (t--) { long long int n, i, j, k; cin >> n; map<long long int, long long int> m; vector<long long int> a, b; for (i =... |
#include <bits/stdc++.h> using namespace std; const int maxi = 3e6; vector<int> ans; int a[maxi]; int cnt[maxi]; int c[maxi]; void solve() { int n; scanf( %d , &n); for (int i = 1; i <= n; i++) { c[i] = 0; cnt[i] = 0; } for (int i = 1; i <= n; i++) { int x; scan... |
#include <bits/stdc++.h> using namespace std; const long long inf = 1e9 + 5; long long power(long long x, long long y) { long long res = 1; while (y > 0) { if (y & 1) res = res * x; y = y >> 1; x = x * x; } return res; } int32_t main() { ios_base::sync_with_stdio(false); ... |
#include <bits/stdc++.h> using namespace std; const long long inf = 1e9 + 7; const long long INF = 1LL << 60; const long long mod = 1e9 + 7; const long double eps = 1e-8; const long double pi = acos(-1.0); template <class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; ... |
#include <stdio.h> #include <stdlib.h> #define N 200000 #define Q 100000 #define N_ ((N + Q * 2) * (LG + 1)) #define LG 20 #define B (1 << LG) int ll[1 + N_], rr[1 + N_], sz[1 + N_], msk0[1 + N_], msk1[1 + N_], lz[1 + N_], _ = 1; void put(int u, int lg, int x) {int tmp, x0, x1;if (u == 0)return;if ((x &... |
#include <bits/stdc++.h> using namespace std; long long mod = 1e9 + 7; long long fpo(long long x, long long y); int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ; int t; cin >> t; while (t--) { int n; char s[1000]; cin >> n >> s; if (n > 2) { ... |
#include <bits/stdc++.h> using namespace std; int main() { long long int t; cin >> t; while (t--) { long long int n, f = 0, g = 0; cin >> n; long long int a[n + 1]; vector<long long int> v; for (long long int i = 0; i < n; i++) { cin >> a[i]; if (a[i] == 1 a... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long a[3], d, ans = 0; cin >> a[0] >> a[1] >> a[2] >> d; sort(a, a + 3); if (a[1] - a[0] < d) ans += (d - (a[1] - a[0])); if (a[2] - a[1] < d) ans += (d - (a[2] ... |
#include <bits/stdc++.h> using namespace std; int Ask(string s) { cout << s << n ; cout.flush(); int diff; cin >> diff; if (diff == 0) exit(0); return diff; } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); if (fopen( input.txt , r )) { freopen( in... |
#include <bits/stdc++.h> using namespace std; int n, m, a, b; int tmp[33][33]; int source[33][33]; int target[33][33]; pair<int, int> prv[33][33]; bool block[33][33]; vector<pair<int, int> > R; int dx[] = {-1, -1, -1, 0, 0, 1, 1, 1}; int dy[] = {-1, 0, 1, -1, 1, -1, 0, 1}; void save() { for (i... |
#include <bits/stdc++.h> using namespace std; struct elem { int le, num, ri; elem() {} elem(int inle, int innum, int inri) { le = inle; num = innum; ri = inri; } }; elem operator+(elem e1, elem e2) { return elem(e1.le, e1.num + e2.num + (e1.ri and e2.le ? 1 : 0), e2.ri); ... |
#include <bits/stdc++.h> using namespace std; struct rec { long long w, h, c; } a[200010] = {0}; int n; long long ans; vector<long long> p, sum; double ABS_dec(double x1, double x2) { if (x1 < x2) return x2 - x1; return x1 - x2; } void quick_sort(struct rec a[], long h, long e) { long ... |
#include <bits/stdc++.h> using namespace std; int n, a, b, t, k, x[(int)1e6], i; int main() { cin >> n; for (i = 0; i < n; i++) cin >> x[i]; sort(x, x + n), n = unique(x, x + n) - x; cin >> a >> b; while (a > b) { k = a - 1; for (i = 0; i < n; i++) if (a - a % x[i] < b) ... |
#include <bits/stdc++.h> using namespace std; const int BASE = 70; long long dataf[BASE][BASE * 2][2]; int main() { long long s; scanf( %lld , &s); long long ans = 0; long long(*f)[BASE * 2][2] = dataf + 1; for (int le = 0;; le++) { long long t1 = (1LL << (le + 1)); if (t1 - 1 > ... |
#include <bits/stdc++.h> using namespace std; vector<vector<long long>> v; map<int, pair<int, int>> mp; int main() { int k; scanf( %i , &k); v.resize(k + 1); for (int i = 1; i <= k; i++) { int x; scanf( %i , &x); v[i].push_back(0); for (int j = 1; j <= x; ++j) { i... |
#include <bits/stdc++.h> using namespace std; const int maxn = 105; int main() { int n; int as[maxn], bs[maxn], cs[maxn]; scanf( %d , &n); for (int i = 0; i < n; i++) { scanf( %d%d%d , &as[i], &bs[i], &cs[i]); as[i]--; bs[i]--; } int costA = 0; int costB = 0; int ... |
#include <bits/stdc++.h> using namespace std; const int MAXN = 3e5 + 7, INF = 1e9 + 7, LIM = 1e6; int it[4 * LIM + 7] = {}, lz[4 * LIM + 7] = {}, n, m, a[MAXN], b[MAXN], q; void lp(int g) { if (lz[g]) { it[g * 2] += lz[g], it[g * 2 + 1] += lz[g]; lz[g * 2] += lz[g], lz[g * 2 + 1] += lz[g]; ... |
#include <bits/stdc++.h> using namespace std; signed long long tonum(string s) { stringstream in(s); signed long long x; in >> x; return x; } string tostr(signed long long n) { stringstream in; in << n; string x; in >> x; return x; } signed long long gcd(signed long long ... |
#include <bits/stdc++.h> using namespace std; int main() { double a, b, c; cin >> a >> b >> c; if (c == 0 && a != b) { cout << NO ; return 0; } if (a == b) { cout << YES ; return 0; } if (a > b && c > 0) { cout << NO ; return 0; } if (a < b ... |
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using db = double; using str = string; using pi = pair<int, int>; using pl = pair<ll, ll>; using pd = pair<db, db>; using vi = vector<int>; using vb = vector<bool>; using vl = vector<ll>; using vd = vecto... |
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 4; struct node { int ptr[26], link, len, cl; }; struct SAM { node t[N]; int las, siz; inline void init() { siz = 1; las = 0; t[0].len = 0; t[0].link = -1; } inline void extend(int c) { int c... |
#include <bits/stdc++.h> using namespace std; long long c, t, n, I; int main(void) { cin >> n; for (int i = int(1), ni = int(n); i <= ni; i++) cin >> t, c += (t == 1); I = 1; for (long long I1 = 1, I2 = 1, i = 2; i <= c; i++) I = (I1 + I2 * (i - 1) % 1000000007) % 1000000007, I2 = I1, I1 = I... |
#include <bits/stdc++.h> using namespace std; long long dp[55][55][55][55]; long long ara[55]; double f[55]; long long cnt(long long i, long long k, long long sum, long long zawad) { if (i == 0) return (k == 0 && sum == 0); if (k > i || sum < 0) return 0; if (dp[i][k][sum][zawad] != -1) return dp[... |
#include <bits/stdc++.h> using namespace std; int MOD = 1e9 + 7; const long double E = 1e-9; unsigned char ccc; bool _minus = false; inline void read(int &n) { n = 0; _minus = false; while (true) { ccc = getchar(); if (ccc == || ccc == n ) break; if (ccc == - ) { ... |
#include <bits/stdc++.h> using namespace std; long long data[4 * 150005], lazy[4 * 150005], ret; int ll, rr, n, m; void change(int t, long long d) { data[t] = lazy[t] = d; } void down(int t) { if (lazy[t]) { change(t * 2, lazy[t]); change(t * 2 + 1, lazy[t]); lazy[t] = 0; } } voi... |
#include <bits/stdc++.h> using namespace std; const int N = (2e5 + 5); const int mod = 1e9 + 7; long long int n, a[N], x; vector<vector<int>> g; long long int pow_mod_m(long long int a, long long int n) { if (!n) return 1; long long int pt = pow_mod_m(a, n / 2); pt *= pt; pt %= mod; if (... |
#include bits/stdc++.h #define Abra_Ka_Dabra ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); typedef long long ll; typedef unsigned long long ull; typedef long double ld; using namespace std; const long long mod = 1e9 + 7; const double PI = acos(-1); const double EPS = 1e-12; bool isEqua... |
#include <bits/stdc++.h> using namespace std; const long long Mod = 1000000007LL; const int N = 2e5 + 10; const long long Inf = 2242545357980376863LL; const long long Log = 30; struct node { int lz, mn, cnt; long long sum; node() { lz = 0, mn = 0, cnt = 0, sum = 0; } }; node base; node seg... |
#include <bits/stdc++.h> using namespace std; bool compa(int i, int j) { return i > j; } long long int power(long long int a, long long int n) { if (n == 0) return 1; else if (n % 2) { long long int d1 = power(a, n / 2); return d1 * d1 * a; } else { long long int d1 = power(a, ... |
#include <bits/stdc++.h> using namespace std; const int mxN = 1e5, mxV = 7001; int n, q, qt, xi, yi, zi; bitset<mxV> in[mxV], cq[mxV], ms[mxN], c; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); for (int i = 1; i < mxV; ++i) { for (int j = 0; (j += i) < mxV;) in[j][i] = 1; ... |
#include <bits/stdc++.h> using namespace std; int mtx[2000005]; int main() { int tc, cs = 0; int i, j, k; int len; cin >> len; for (i = 0; i < len; i++) cin >> mtx[i]; sort(mtx, mtx + len); long long sum = 0; i = 0; while (1) { int n = pow(4, i); if (n > len) break;... |
#include <bits/stdc++.h> using namespace std; int a, b; bool bad(int x, int y) { return abs(x + y) % (2 * a) == 0 || abs(x - y) % (2 * b) == 0; } void reorder(int& x, int& y) { int xx = (x - y) / 2; int yy = (x + y) / 2; x = xx; y = yy; } void norm(int& x, int& y) { if ((x + y) % 2... |
#include <bits/stdc++.h> using namespace std; vector<long long int> a; vector<long long int> b; long long int fa(int l, int r) { long long int ret = 0; for (int i = l; i <= r; ++i) ret |= a[i]; return ret; } long long int fb(int l, int r) { long long int ret = 0; for (int i = l; i <= r; ... |
#include <bits/stdc++.h> using namespace std; int n, k; long long ln[10000], fac[15]; int cnt, ans, suf; int tem[15]; void input() { scanf( %d%d , &n, &k); } void dfs(long long x) { if (x > 10000000000LL) return; ln[cnt++] = x; dfs(x * 10 + 4); dfs(x * 10 + 7); } void make_lucky_number... |
#include <bits/stdc++.h> using namespace std; int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1}; int ddx[8] = {1, 1, 0, -1, -1, -1, 0, 1}, ddy[8] = {0, 1, 1, 1, 0, -1, -1, -1}; void mad(long long &a, long long b) { a = (a + b) % 1000000007; if (a < 0) a += 1000000007; } long long gcd(long long a, lon... |
#include <bits/stdc++.h> using namespace std; const int inf = (int)1e9; const double pi = acos(-1.0); const double eps = 1e-9; long long x, second, res, xx, first; int main() { cin >> second >> x; xx = x; if ((second & 1) != (x & 1)) { cout << 0; return 0; } res = 1; whil... |
#include <bits/stdc++.h> using namespace std; const int maxn = 10050; int a[maxn], b[maxn]; bool cmp(int a, int b) { return a > b; } int main() { ios::sync_with_stdio(false); cin.tie(0); int n, k; while (cin >> n >> k) { memset(a, 0, sizeof(a)); for (int i = 0; i < n; i++) { ... |
#include <bits/stdc++.h> using namespace std; bool flag = false; int n, m, K; int up[2005][2005], down[2005][2005]; int Find(int p[], int x) { return p[x] != x ? p[x] = Find(p, p[x]) : x; } void check(int x, int y, int i, int &g, int &h, int &L) { if (i < 1 || i > n) return; int j; j = Find(up[i... |
#include <bits/stdc++.h> using namespace std; const int32_t MOD = 1000000007; struct WEdge { int32_t u, v; int w; bool operator<(const WEdge& other) { return w < other.w; } WEdge(int32_t u, int32_t v, int w) : u(u), v(v), w(w) {} WEdge() {} void in() { cin >> u >> v >> w; } void trace(... |
#include <bits/stdc++.h> #pragma GCC optimize( O3 ) #pragma GCC target( sse4 ) using namespace std; template <class T> T gcd(T a, T b) { return ((b == 0) ? a : gcd(b, a % b)); } int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n, x; cin >> n >> x; n %= 6; for (int... |
#include <bits/stdc++.h> int main() { int t, l, r, d, m, n, i; scanf( %d , &t); for (i = 0; i < t; i++) { scanf( %d %d %d , &l, &r, &d); if (l > d || r < d) { printf( %d n , d); } else { m = (r / d) + 1; n = d * m; printf( %d n , n); } } retu... |
#include <bits/stdc++.h> #pragma GCC optimize( Ofast , unroll-loops , no-stack-protector ) using namespace std; template <class T> using minheap = priority_queue<T, vector<T>, greater<T>>; template <typename T> void setmax(T& a, T b) { a = max(a, b); }; template <typename T> void setmin(T& a, T ... |
#include <bits/stdc++.h> using namespace std; int main() { int s, x, y, a, b; cin >> s >> x >> y >> a >> b; if ((x * s) + (2 * a) < (y * s) + (2 * b)) { cout << First ; return 0; } if ((x * s) + (2 * a) > (y * s) + (2 * b)) { cout << Second ; return 0; } if ((x ... |
#include <bits/stdc++.h> using namespace std; long long a[1111]; int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); long long n, ans = 0; cin >> n; for (long long i = 1; i <= n; i++) { cin >> a[i]; } sort(a + 1, a + 1 + n); for (long long i = 1; i <... |
#include <bits/stdc++.h> using namespace std; long long t, n; string s; int main() { cin >> t; for (int x = 1; x <= t; x++) { cin >> n; cin >> s; string ans; long long v = 0; for (int i = 0; i < s.length(); i++) { ans += s[i + (v++)]; if (i == n - 1) break; ... |
#include <bits/stdc++.h> using namespace std; using namespace std::chrono; bool prime[2000005]; vector<int> myarr; void myprime(int n) { for (long int i = 0; i < n; i++) prime[i] = true; for (int p = 2; p * p <= n; p++) { if (prime[p] == true) { for (int i = p * p; i <= n; i += p) prime[... |
#include <bits/stdc++.h> using namespace std; const int N = 1000005; struct ky { int u, val; bool operator<(const ky &p) const { return val < p.val; } } a[N], b[N]; int n, ca, cb, ci, vali; bool tg[N]; inline void fr(int &num) { num = 0; char c = getchar(); int p = 1; while (c < 0... |
#include <bits/stdc++.h> using namespace std; struct node { struct node* left; struct node* right; int vl; node() { vl = 0; left = NULL; right = NULL; } }; int a[300005]; int ans = 0; void query(node* n, int v, int i, int j) { if (n == NULL || j == 0) return; in... |
#include <iostream> #include <set> #include <vector> #include <algorithm> using namespace std; typedef long long ll; vector<int> res; vector<pair<int, int>> edges; vector<vector<int>> v; int n, k; int buildTree(set<int> idx, int rootSalary) { if (idx.size() == 1) { return *idx.begin(); } ... |
#include <bits/stdc++.h> using namespace std; const int N = 200200; int n; int a[N]; int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; } int cnt_0 = 0, cnt_neg = 0, pos = -1; vector<int> used(n); for (int i = 0; i <... |
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); string s; int n, x = 0, ans; cin >> s; n = s.length(); for (int i = 0; i < n; i++) { x = x * 10 + (s[i] - 0 ); x = x % 4; } ans = (1 + (int)pow(2, x) + (int)pow(3, x) ... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(); int N, ans = 0; string s; cin >> N >> s; for (int i = 0, j; i < N;) { if (s[i] == ? ) { for (j = i; j < N && s[j] == ? ; j++) ; if (j - i > 1 || !i || j == N ... |
#include <bits/stdc++.h> using namespace std; using lint = long long int; constexpr int MOD = 1000000007; int main() { int T; cin >> T; for (int t = (0), t_end_ = (T); t < t_end_; t++) { int r, c, k; cin >> r >> c >> k; vector<string> map(r); for (int i = (0), i_end_ = (r); i... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.