func_code_string stringlengths 59 71.4k |
|---|
#include <bits/stdc++.h> int main() { long n, k, a, b, a2 = {0}, a3 = {0}, a5 = {0}, b2 = {0}, b3 = {0}, b5 = {0}; scanf( %d %d , &a, &b); k = 1; while (k == 1) { if (a % 2 == 0) { a = a / 2; a2++; } else k = 0; } k = 1; while (k == 1) { if (a % 3 ... |
#include <bits/stdc++.h> using namespace std; struct segment { int pos; int len; int type; }; struct segmentByLength { segment seg; bool operator<(segmentByLength o) const { segment seg2 = o.seg; if (seg.len != seg2.len) return seg.len > seg2.len; else { ret... |
#include <bits/stdc++.h> int main() { int q; scanf( %d , &q); while (q--) { long long k; int x; scanf( %lld%d , &k, &x); printf( %lld n , x + 9 * (k - 1)); } return 0; } |
#include <bits/stdc++.h> using namespace std; long long input[(long long)1e5 + 1]; long long ans = 0; long long n; int main() { cin >> n; for (int i = 0; i < n; i++) cin >> input[i]; for (int i = n - 2; i >= 0; i--) { if (input[i] > input[i + 1]) ans += input[i] - input[i + 1]; } cou... |
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e6 + 5; int a[MAXN], x, f, b, n; vector<int> v; int main() { cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; cin >> f >> b; sort(a, a + n); n = unique(a, a + n) - a; for (int i = 0; i < n; i++) v.push_back(a[i]); in... |
#include <bits/stdc++.h> using namespace std; const long long d = 20; long long n, m, dsu[80], cc[80], al[40], dp[1ll << d]; long long fd(long long x) { if (dsu[x] != x) { dsu[x] = fd(dsu[x]); } return dsu[x]; } int main() { long long i, ii, k, l, mk, mk2, z[4] = {1, 1, 1, 0}; scan... |
#include <bits/stdc++.h> using namespace std; int g[100010]; int main(void) { int A, T, N, M; scanf( %d , &N); for (int i = (int)(3); i <= (int)(N); i++) { set<int> st; A = 2000000000; for (int j = (int)(2); j <= (int)(N); j++) { int k = i - j * (j + 1) / 2; if (k < 0... |
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; int n, m; char ch[20][120]; int l[20], r[20], visit[20], dp[20][2]; int main() { while (~scanf( %d%d , &n, &m)) { memset(visit, 0, sizeof visit); memset(r, 0, sizeof r); memset(l, 0, sizeof l); for (int i =... |
#include <bits/stdc++.h> using namespace std; template <typename T> void pr(vector<T> &v) { for (int i = 0; i < (int)(v).size(); i++) cout << v[i] << ; cout << endl; } template <typename T> void pr(vector<vector<T>> &v) { for (int i = 0; i < (int)(v).size(); i++) { pr(v[i]); } } ... |
#include <bits/stdc++.h> using namespace std; int main() { int m, n, l, s = 0; cin >> n >> m >> l; vector<int> a(n); vector<int> otvet; for (int i = 0; i < n; ++i) cin >> a[i]; if (n == 1) { for (int i = 0; i < m; ++i) { int x; cin >> x; if (x == 0) { ... |
#include <bits/stdc++.h> using namespace std; void io() { freopen( input.txt , r , stdin); freopen( output.txt , w , stdout); } long long int a[100001], n, k, pos = 1000000000000000; map<long long int, long long int> m; set<long long int> s; int main() { cin >> n >> k; s.clear(); for... |
#include <bits/stdc++.h> int main() { int n; int64_t res1 = 0, res2 = 0, sum = 0; bool is; std::cin >> n; std::vector<int> m(n); for (int i = 0; i < n; i++) { std::cin >> m[i]; sum += m[i]; } is = sum % n != 0; sum /= n; for (int i = 0; i < n; i++) { if (m[i] ... |
#include <bits/stdc++.h> using namespace std; const int N = 20009; int INF = 2e9; struct edge { int to, cap, rev; edge() {} edge(int tt, int cc, int rr) { to = tt; cap = cc; rev = rr; } }; vector<edge> Graph[N]; int level[N]; int iter[N]; void add_edge(int from, int t... |
#include <bits/stdc++.h> using namespace std; int main() { long long int t; cin >> t; while (t--) { long long int n, i, j; cin >> n; long long int arr[n][n]; for (i = 0; i < n; i++) { string s; cin >> s; for (j = 0; j < n; j++) { long long int te... |
#include <bits/stdc++.h> using namespace std; const int DX[8] = {1, -1, 0, 0, 1, 1, -1, -1}; const int DY[8] = {0, 0, 1, -1, 1, -1, 1, -1}; const int intmax = 0x7fffffff; const int mod = 1000000007; int n, m; int f[205]; int p[205]; vector<pair<int, int> > op; int main() { scanf( %d%d , &n, &m);... |
#include <bits/stdc++.h> using namespace std; inline char nc() { static char buf[100000], *p1 = buf, *p2 = buf; return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2) ? EOF : *p1++; } inline void read(int &x) { char c = nc(), b = 1; for (; !(c... |
#include <bits/stdc++.h> using namespace std; long long getint() { char ch = getchar(); long long f = 1, x = 0; while (!isdigit(ch)) { if (ch == - ) f = -1; ch = getchar(); } while (isdigit(ch)) { x = x * 10 + ch - 0 ; ch = getchar(); } return f * x; } const... |
#include <bits/stdc++.h> using namespace std; priority_queue<long long, vector<long long>, greater<long long>> q; int a[100005]; int main() { int n, x; long long b = 0, s; scanf( %d , &n); for (int i = 1; i <= n; ++i) scanf( %d , &a[i]); for (int i = 1; i <= n; ++i) { scanf( %d , &x); ... |
#include <bits/stdc++.h> using namespace std; template <typename T> using minpq = priority_queue<T, vector<T>, greater<T>>; struct node { int val, le, ri; node() : val(1e9 + 5), le(0), ri(0) {} }; const int N = 1e5 + 5; int n, r, m, p, q, u, v, a[N], depth[N], root[N], tin[N], tout[N], ti = 1; v... |
#include <bits/stdc++.h> using namespace std; long long a[200005]; long long b[200005]; vector<long long> edge[200005]; vector<long long> roots; vector<bool> visited; long long max_val[200005]; long long ans = 0; long long dfs(long long v) { visited[v] = true; long long ret = 0; for (long ... |
#include <bits/stdc++.h> using namespace std; int main() { int a, b, n; cin >> a >> b >> n; long long l, t, m; for (int i = 0; i < n; ++i) { cin >> l >> t >> m; long long sl = a + b * (l - 1), sr; if (t < sl) { cout << -1 << endl; continue; } int lf = l,... |
#include <bits/stdc++.h> int main() { int32_t n; std::cin >> n; int32_t* arr = new int32_t[n]; for (int32_t i = 0; i < n; i++) { std::cin >> arr[i]; } std::string ans = ; char last = b ; for (int32_t i = n - 1; i >= 0; i--) { if (arr[i] == 0) continue; int32_t leng... |
#include <bits/stdc++.h> using namespace std; int main() { int a, b; scanf( %d %d , &a, &b); if (a == 0 && b == 0) printf( NO ); else if (fabs(a - b) == 1 || a - b == 0) printf( YES ); else printf( NO ); return 0; } |
#include <bits/stdc++.h> using namespace std; int charToDec(char c) { if ((c >= 0 ) && (c <= 9 )) return c - 0 ; if ((c >= A ) && (c <= Z )) return c - A + 10; } char decToChar(int c) { if ((c >= 0) && (c <= 9)) return c + 0 ; if ((c >= 10) && (c <= 26)) return c + A - 10; } long l... |
#include <bits/stdc++.h> #pragma GCC optimize( Ofast,inline,unroll-loops,fast-math ) using namespace std; const bool d[3][2][2] = { { {false, true}, {true, false}, }, { {true, false}, {true, true}, }, { {true, true}, {false,... |
#include <bits/stdc++.h> const int maxn = 100035; int n, num, cnt, pr[maxn], phi[maxn]; bool vis[maxn]; long long ans, f[maxn]; std::vector<int> fac[maxn], opt; void makePrime() { phi[1] = 1; for (int i = 2; i < maxn; i++) { if (!vis[i]) pr[++pr[0]] = i, phi[i] = i - 1; for (int j = 1, c... |
#include <bits/stdc++.h> using namespace std; using ll = long long; inline int read() { int x = 0, f = 1; char ch = getchar(); while (!isdigit(ch)) { if (ch == - ) f = -1; ch = getchar(); } while (isdigit(ch)) { x = (x << 1) + (x << 3) + ch - 0 ; ch = getchar(); }... |
#include <bits/stdc++.h> #pragma GCC optimize(4) using namespace std; char _buf[100000], *_p1 = _buf, *_p2 = _buf; inline int gi() { int x = 0, f = 1; char ch = (_p1 == _p2 && (_p2 = (_p1 = _buf) + fread(_buf, 1, 100000, stdin), _p1 == _p2) ? EOF ... |
#include <bits/stdc++.h> using namespace std; vector<string> digits = { 1110111 , 0010010 , 1011101 , 1011011 , 0111010 , 1101011 , 1101111 , 1010010 , 1111111 , 1111011 }; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, k; cin >> n >> k; vector... |
#include <bits/stdc++.h> #pragma comment(linker, /STACK:64000000 ) using namespace std; inline unsigned long long gcd(unsigned long long a, unsigned long long b) { if (a < b) { a ^= b; b ^= a; a ^= b; }; return (a > b) ? gcd(a - b, b) : a; } inline int abs(int x) { return x > 0 ... |
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; string s1( ABC ), s2( ACB ), s3( BAC ), s4( BCA ), s5( CAB ), s6( CBA ); int state = 0; if (s.find(s1) != -1) state = 1; else if (s.find(s2) != -1) state = 1; else if (s.find(s3) != -1) state... |
#include <bits/stdc++.h> using namespace std; int main() { int q; cin >> q; for (int qq = 0; qq < int(q); qq++) { string s; cin >> s; int n; cin >> n; vector<int> b(n); for (int i = 0; i < int(n); i++) cin >> b[i]; vector<vector<int>> groups; while (true) ... |
#include <bits/stdc++.h> using namespace std; const int N = 1005; int n, m, q, u, v, w, l, r, ans, par[N], col[N], mark[N]; vector<pair<int, pair<int, int> > > yal, edge[N * N]; vector<int> cmp[N]; void add(int x) { for (int i = 0; i < edge[x].size(); i++) yal.push_back(edge[x][i]); } int Get_par(in... |
#include <bits/stdc++.h> using namespace std; long long mod_v(long long num) { if (num >= 0) return (num % 1000000007); else return (num % 1000000007 + 1000000007) % 1000000007; } long long bigmod(long long b, long long p, long long m) { long long res = 1 % m, x = b % m; while (p) { ... |
#include <bits/stdc++.h> using namespace std; inline int read() { int x = 0, f = 1; char c = getchar(); while (c != - && c < 48) c = getchar(); if (c == - ) f = -1, c = getchar(); while (c > 47) x = x * 10 + (c ^ 48), c = getchar(); return f * x; } const int maxn = 3e3 + 7; const in... |
#include <bits/stdc++.h> using namespace std; int v[7], x[7]; int main() { for (int i = 0; i < 6; ++i) scanf( %d , &v[i]); int ans = -1; for (int i = 0; i <= 100000; ++i) { x[1] = v[1] - v[2] + v[3] - v[4] + 2 * i; if (x[1] % 2 || x[1] < 0) continue; x[2] = v[2] + v[4] - v[0] - 2 * i... |
#include <bits/stdc++.h> using namespace std; const int M = 1000005; int read() { int x = 0, f = 1; char c; while ((c = getchar()) < 0 || c > 9 ) { if (c == - ) f = -1; } while (c >= 0 && c <= 9 ) { x = (x << 3) + (x << 1) + (c ^ 48); c = getchar(); } return x ... |
#include <bits/stdc++.h> using namespace std; const int Direction[4][2] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}}; const int Nmax = 303000; long double n, m; long double ans = 0; int main() { ios_base::sync_with_stdio(0); cin >> n >> m; long double r = n * m; for (int k = 1; k <= min(n, m); k++) ... |
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; int a[n + 1]; int b[2 * n + 1]; int temp[2 * n + 1]; for (int i = 1; i <= 2 * n; i++) temp[i] = 0; bool con1 = false, con2 = false; for (int i = 1; i... |
#include <bits/stdc++.h> using namespace std; const int MOD = 998244353; double eps = 1e-8; vector<int> b, c; int vis[2100000], a[210000], ans[210000], x; int read() { int v = 0, f = 1; char c = getchar(); while (c < 48 || 57 < c) { if (c == - ) f = -1; c = getchar(); } whil... |
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 5; const int MAX = 1e9 + 5; int i, j, w1, w2, k, n, m, a[N], b[N], calca[N], calcb[N], temp; vector<pair<int, int> > ans, adasd; bool ctr(int s) { int set = 0; int p1 = 0; int p2 = 0; int last1 = 0; int last2 = 0; int ... |
#include <bits/stdc++.h> using namespace std; using ll = int64_t; struct node { int C[2]; ll good; ll bad; char mrk; node() : C{0, 0}, good{0}, bad{0}, mrk{0} {} int& operator[](int i) { return C[i]; } }; using trie_t = vector<node>; trie_t T; string curr; struct Guard { Guar... |
#include <bits/stdc++.h> #pragma comment(linker, /stack:200000000 ) #pragma GCC optimize( Ofast ) #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native ) using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); long long n, k; cin >> n >> k; vec... |
#include <bits/stdc++.h> using namespace std; int const N = 1e5 + 10; using ll = long long; ll const INF = 0x3f3f3f3f3f3f3f3fll; struct edge { ll to, cost, id; edge(ll to = 0, ll cost = 0, ll id = 0) : to(to), cost(cost), id(id) {} }; vector<edge> e[N]; ll d[N]; vector<ll> p[N]; ll n, m, k; ... |
#include <bits/stdc++.h> using namespace std; int main() { int k, i, j, l = 0; cin >> k >> i; for (j = 1; j <= 10; j++) { l = k * j; if (l % 10 == 0 || l % 10 == i) { cout << j; break; } } } |
#include <bits/stdc++.h> using namespace std; long long int m, n, f, h[200000], fakt[200000] = {1}; vector<int> v[200000]; long long int fe(long long int m, long long int n) { if (!n) return 1; long long int t = fe(m, n / 2); t = t * t % 1000000007LL; if (n & 1) t = t * m % 1000000007LL; ret... |
#include <bits/stdc++.h> using namespace std; int main() { long long T; cin >> T; while (T--) { long long n, a[100005]; cin >> n; for (long long i = 1; i <= n; i++) { cin >> a[i]; } long long ans = 0; for (long long i = 1; i < n; i++) { long long t = a... |
#include <bits/stdc++.h> using namespace std; const int Nx = 200005; int ct[Nx], MMsize, A, B, tree[Nx * 4]; map<int, int> MM; vector<int> pos[Nx]; int query(int a, int b, int key) { if (A <= a && b <= B) return tree[key]; if (B < a || b < A) return 0; int m = (a + b) / 2; return query(a, m,... |
#include <bits/stdc++.h> using namespace std; int N, M; vector<int> adj[100002], f, radj[100002]; queue<int> Q1, Q2; vector<int> vis; int main(int argc, char **argv) { cin >> N >> M; f = vector<int>(N); for (int i = (0); i < (N); ++i) cin >> f[i]; for (int i = (0); i < (M); ++i) { int ... |
#include <bits/stdc++.h> using namespace std; int main() { string s1, s; cin >> s1 >> s; int a[10] = {0}, b[10] = {0}; for (int i = 0; i < s1.size(); i++) { int m = s1[i] - 0 ; if (m == 5 || m == 2) a[2]++; else if (m == 6 || m == 9) a[6]++; else a[m]... |
#include <bits/stdc++.h> using namespace std; vector<int> disTime, finTime, depth, a; vector<vector<int> > graph; int n, maxSize, tr0[200005], tr1[200005]; vector<bool> vis; int tim; void update(int in, int val, int* tr) { while (in <= maxSize) { tr[in] += val; in += (in & (-in)); } ... |
#include <bits/stdc++.h> using namespace std; const int M = 2010; int A[M][M]; int col[M]; int diag[M]; int main() { ios_base::sync_with_stdio(false); int i, j, k, n; char str[M]; scanf( %d , &n); for (i = 0; i < n; i++) { scanf( %s , str); for (j = 0; j < n; j++) A[i][j] = s... |
#include <bits/stdc++.h> using namespace std; const long long mo = 998244853; const long long INF = 0x3f3f3f3f; template <typename _T> void read(_T &x) { _T f = 1; x = 0; char s = getchar(); while (s > 9 || s < 0 ) { if (s == - ) f = -1; s = getchar(); } while (s >= 0 ... |
#include <bits/stdc++.h> using namespace std; const int N = 21; int n, m, k; int ls; bool vis[N]; vector<pair<int, int> > e[N]; void dfs(int u, int sum, int x) { if (u > n) { ls++; return; } if (ls >= k) { return; } dfs(u + 1, sum, x); for (int i = 0; i < (int)e[u... |
#include <bits/stdc++.h> using namespace std; const int M = 450007; int read() { int ans = 0, f = 1, c = getchar(); while (c < 0 || c > 9 ) { if (c == - ) f = -1; c = getchar(); } while (c >= 0 && c <= 9 ) { ans = ans * 10 + (c - 0 ); c = getchar(); } return... |
#include <bits/stdc++.h> using namespace std; long long mod; long long binPow(long long a, long long q) { a %= mod; if (q == 0) return 1; if (q % 2 == 1) return a * binPow(a * a, q / 2) % mod; else return binPow(a * a, q / 2) % mod; } bool prime(int x) { if (x % 2 == 0) return ... |
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c, S = 0; cin >> a >> b >> c; while (a > 0 && b > 1 && c > 3) { a--; b -= 2; c -= 4; S += 7; } cout << S; return 0; } |
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e5 + 10, INF = 2147483647; int a[MAXN]; int main() { int T, n, i, res = 0; scanf( %d , &T); while (T--) { res = 0; scanf( %d , &n); for (i = 1; i <= n; i++) scanf( %d , &a[i]); sort(a + 1, a + n + 1); int e... |
#include <bits/stdc++.h> using namespace std; const int M = 1001; int n, m, h, A[M], w, a; int main() { scanf( %d%d%d , &n, &m, &h); for (int i = 1; i <= m; i++) scanf( %d , &A[i]), w += A[i]; w--, n--; a = w - (A[h] - 1); if (n > w) { puts( -1 ); return 0; } if (n > a) {... |
#include <bits/stdc++.h> using namespace std; int main() { long long int n, k; cin >> n >> k; vector<long long int> arr(n); long long int r = n; for (long long int i = 0; i < k; i++) { long long int temp; cin >> temp; for (long long int j = temp - 1; j < r; j++) arr[j] = temp; ... |
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; while (k--) { if (n % 10 == 0) n = n / 10; else n = n - 1; } cout << n << endl; } |
#include <bits/stdc++.h> using namespace std; const int INF = 1e9 + 23; const int MOD = 1e9 + 9; const int MAXN = 1e3 + 100; struct item { int val, type, id; bool operator<(const item &rhs) const { return val > rhs.val; } }; vector<item> items[2]; vector<item> cart[MAXN]; int main() { ios_... |
#include <bits/stdc++.h> using namespace std; const int K = 64, N = 3e5 + 7; int a[N]; int sum[N]; int main() { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; for (int i = 1; i <= n; i++) { long long x; cin >> x; a[i] = __builtin_popcountll(x); sum[i] = sum[i... |
#include <bits/stdc++.h> using namespace std; int ans = 0, n; int numDistDig(int n) { vector<int> arr(10, 0); while (n > 0) { arr[n % 10]++; n /= 10; } int ans = 0, i; for (i = 0; i < 10; i++) ans += (arr[i] > 0); return ans; } void dfs(int num) { if (num > 0 && num <= ... |
#include <bits/stdc++.h> using namespace std; int main() { int r, n, d; int kol = 0; cin >> n >> d; int *a = new int[n]; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) if (i != j && abs(a[i] - a[j]) <= d) { kol++; ... |
#include <bits/stdc++.h> const int ms = 500500; std::string str[ms], ans[ms]; int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(NULL); int n; std::cin >> n; for (int i = 0; i < n; i++) std::cin >> str[i]; ans[n - 1] = str[n - 1]; for (int i = n - 2; i >= 0; i--) { ... |
#include <bits/stdc++.h> using namespace std; const int MAXN = 205; const int P = 998244353; template <typename T> void chkmax(T &x, T y) { x = max(x, y); } template <typename T> void chkmin(T &x, T y) { x = min(x, y); } template <typename T> void read(T &x) { x = 0; int f = 1; ... |
#include <bits/stdc++.h> using namespace std; int main() { int n, c = 0; cin >> n; if (n == 1 || n == 2) cout << 0 << endl; else if (n % 2 == 0) { int temp = 1; while (n >= temp * 2) { temp *= 2; } cout << (n - temp) / 2 << endl; } else cout << n / 2 <... |
#include <bits/stdc++.h> using namespace std; map<pair<int, char>, int> table; int main() { string home, away; int n, x, y, i; char card, team; cin >> home >> away; cin >> n; for (i = 0; i < n; i++) { cin >> x >> team >> y >> card; if (card == y ) table[make_pair(y, team)]++; ... |
#include <bits/stdc++.h> using namespace std; const int MXN = 100010; const int MXX = 400050; struct Segment_Tree { int x, add; } tt[MXX]; int m, v[MXN], ans[MXN]; void Build(int l, int r, int idx) { tt[idx].x = 0; tt[idx].add = 0; if (l == r) { return; } int mid = (l + r) >>... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ; vector<int> values; int T; cin >> T; while (T--) { values.clear(); map<int, int> indexes; bool flag = false; int n, bindex; cin >> n; for (int... |
#include <bits/stdc++.h> using namespace std; const int N = 4e5 + 7, M = 20; char g; struct tree { int a, b, c, t; } tr[N << 1]; struct edge { int a, b; } ed[N], edg[N]; set<int> hig[N]; map<int, int> s[N]; int n, m, k, siz, res, tota, totb, lint, themin, w[N], fa[N], fb[N], st[N], dep... |
#include <bits/stdc++.h> using namespace std; static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL; vector<string> split(string s, string sep) { string act = ; vector<string> res; for (int c = 0; c < s.size(); c++) { bool split = false; for (int c2 = 0;... |
#include <bits/stdc++.h> using namespace std; inline int read() { int ret = 0, t = 1; char c = getchar(); while ((c < 0 || c > 9 ) && c != - ) c = getchar(); if (c == - ) t = -1, c = getchar(); while (c >= 0 && c <= 9 ) ret = ret * 10 + c - 0 , c = getchar(); return ret * t; } c... |
#include <bits/stdc++.h> using namespace std; int main() { int n, a, b; scanf( %d%d%d , &n, &a, &b); int tmp = abs(b); int x = tmp % n; if (b > 0) { int ans = a + x; while (ans >= n) { ans %= n; } if (ans == 0) printf( %d n , n); else printf(... |
#include <bits/stdc++.h> using namespace std; long long q; long long n, k, a, b; int main() { cin >> q; while (q--) { cin >> k >> n >> a >> b; long long l = 0, r = n, mid, ans = -1; while (l <= r) { mid = (l + r) / 2; if (mid * a + (n - mid) * b >= k) r = mid ... |
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 6, MOD = 1000000007; long long memo[N][6][6]; int n; string s; bool invalid(int i, int last, int before_last) { if (last == 1 && (s[i] == * || s[i] == 2 || before_last == 4 || before_last == 3)) { return 1; } if ... |
#include <bits/stdc++.h> using namespace std; struct T { int i, j, r; } a[100]; char str[100]; int n, m, i; int v[200][2]; bool rec(int i, int r) { if (i >= r) return 1; int j, k; for (j = i + 1; j <= r; j++) { for (k = 0; k < m; k++) if (a[k].j >= j && a[k].j <= r && a[k].i ... |
#include <bits/stdc++.h> using namespace std; int mod = 1e9 + 7; int base[2] = {31, 33}; int pw[2][1000005], a[2][1000005]; char s[1000005]; int n, ans[1000005]; bool func(int x, int y, int xx, int yy) { for (int i = 0; i <= 1; i++) { if (((a[i][y] - 1ll * a[i][x - 1] * pw[i][y - x + 1]) % mod +... |
#include<bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while(t--) { int n; cin >> n; int arr[n]; for(int i=0; i<n; i++) { cin >> arr[i]; } for(int i=0; i<n; i++) ... |
#include <bits/stdc++.h> using namespace std; int main() { int n, a, b; cin >> n >> a >> b; b %= n; int p = ((a - 1 + b) % n + n) % (n) + 1; cout << p << endl; } |
#include <bits/stdc++.h> using namespace std; template <class T> void makemax(T& a, const T& b) { if (a < b) a = b; } template <class T> void makemin(T& a, const T& b) { if (a > b) a = b; } int main() { int xh, yh, xu, yu; scanf( %d%d , &xh, &yh); scanf( %d%d , &xu, &yu); int n; ... |
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 50, M = 1e4 + 2, OO = 0x3f3f3f3f; int n, m, A[N], rem; int main() { scanf( %d %d , &n, &m); rem = m; for (int i = 0; i < n; ++i) { scanf( %d , A + i); int ans = 0; if (A[i] >= rem) ans = 1, A[i] -= rem, rem = m; ... |
#include <bits/stdc++.h> #pragma G++ optimize(2) using namespace std; long long read() { char ch = , last; long long ans = 0; while (ch < 0 || ch > 9 ) last = ch, ch = getchar(); while (ch >= 0 && ch <= 9 ) ans = ans * 10 + int(ch - 0 ), ch = getchar(); if (last == - ) return -ans; ... |
#include <bits/stdc++.h> using namespace std; bool solve(const string& s) { vector<int> cnt(26, 0); for (int i = 0; i < s.size(); ++i) ++cnt[s[i] - a ]; int tmp = s.size() % 2; int even = 0; int odd = 0; for (int i = 0; i < 26; ++i) if (cnt[i] % 2 == 0) ++even; else ... |
#include <bits/stdc++.h> using namespace std; int main() { int n, a, b, c; while (~scanf( %d %d %d %d , &n, &a, &b, &c)) { if (1 == n || n == 0) { printf( 0 n ); } else if (2 == n) { printf( %d n , min(a, b)); } else { if (c > max(a, b)) { printf( %d n , (... |
//#include<bits/stdc++.h> #include <iostream> #include <vector> #include <deque> #include <queue> #include <map> #include <set> #include <list> #include <cmath> #include <cstring> #include <algorithm> using namespace std; #define fast ios_base::sync_with_stdio(0); cin.tie(0) #define file fr... |
#include <bits/stdc++.h> using namespace std; const int MAXM = 100100; const int MAXN = 500; const int INF = (1 << 30); char s[100100]; struct Edge { int next, from, to, cap, cost; }; struct MCMF { Edge edge[MAXM]; int head[MAXN], countedge; void Init(int N) { this->N = N; me... |
#include <bits/stdc++.h> using namespace std; int main() { string s; long long n; cin >> s; cin >> n; string t[n]; for (int i = 0; i < n; i++) cin >> t[i]; sort(t, t + n); for (int i = 0; i < n; i++) { if (s == t[i]) { cout << s; return 0; } if (s.le... |
#include <bits/stdc++.h> using namespace std; const int maxn = 200010, maxm = 2 * maxn; int n, m, a[maxn], L[maxn], R[maxn], dn, dep[maxn]; struct edge { int j, d; edge *nx; } e[maxm], *v[maxn]; int en; inline void add_e(int i, int j, int d) { e[++en].nx = v[i]; v[i] = e + en; v[i]->j ... |
#include <bits/stdc++.h> using namespace std; int n, m; unsigned long long c[100005], t[100005], total[100005]; void solve() { memset(total, 0, sizeof(total)); for (int i = 1; i <= n; i++) { total[i] = total[i - 1] + c[i] * t[i]; } unsigned long long v; int idx = 0; for (int i = 0;... |
#include <bits/stdc++.h> using namespace std; struct Q { int vs, i; }; const int N = 4e5 + 5, P = 400, D = 26; int to[N][D], tos[N][D], ver[N], ans[N], ct[N], ancv[N], ancc[N], p[N * 2]; int cv = 1, cvs = 1; vector<Q> qr[N]; vector<int> sum[N]; int go(int v, int c) { if (to[v][c] == -1) { ... |
#include <bits/stdc++.h> using namespace std; using LL = long long; using ll = long long; using pii = pair<int, int>; const int N = 2123456; const int INF = int(1e9); LL x; LL C[25][25]; int main() { for (int i = 0; i <= 20; ++i) { C[i][0] = 1; for (int j = 1; j <= i; ++j) C[i][j] = C[... |
#include <bits/stdc++.h> using namespace std; int n; int x[33333]; int C[33333]; int BB[33333]; int seen[33333]; int seena[33333]; int main() { scanf( %d , &n); int cc = 0; for (int i = 0; i < 2 * n; i++) { scanf( %d , &x[i]); C[x[i]]++; BB[x[i]]++; } int ca = 0, cb... |
#include <bits/stdc++.h> using namespace std; const int maxN = 5000 << 2; int times[5001], cnt[5001], n, a[5001]; int main() { scanf( %d , &n); for (int i = 0; i < n; i++) scanf( %d , a + i); for (int i = n - 1; i >= 0; i--) { memset(cnt, 0, sizeof(cnt)); int res = a[i]; times[res]... |
#include <bits/stdc++.h> using namespace std; const long long maxn = 5e5 + 5; long long n, k; long long ans, a, b; char s[maxn], t[maxn]; int main() { cin >> n >> k; scanf( %s%s , s + 1, t + 1); for (int i = 1; i <= n; ++i) { a = a << 1 | (s[i] - a ); b = b << 1 | (t[i] - a ); ... |
#include <bits/stdc++.h> using namespace std; int main() { long long s, xo; cin >> s >> xo; if ((s - xo) % 2 != 0 || (s < xo)) { cout << 0 << endl; return 0; } if ((((s - xo) / 2) & xo) != 0) { cout << 0 << endl; return 0; } if (xo == 0) { cout << 1 << endl;... |
#include <bits/stdc++.h> using namespace std; const int INF = 999999999; const double EPSILON = 0.00000001; const long long MOD = 1000000007; bool used[200005]; struct interval { int first, second; int idx; }; bool operator<(const interval &self, const interval &other) { return self.first < ... |
#include <bits/stdc++.h> using namespace std; int main() { string s; int sum = 0, d = 0, diff = 0; int start = 97; cin >> s; for (int i = 0; i < s.size(); i++) { diff = abs((int)s[i] - start); if (diff > 13) { d = 26 - diff; sum += d; } else { sum += dif... |
#include <bits/stdc++.h> using namespace std; int dp[1502][26]; string s; int n; int len(int w, char c) { if (dp[w][c - a ] != -1) { return dp[w][c - a ]; } int l = 0; int m = 1; int sum = 0; int tail = 0; for (int i = 0; i < n; i++) { if (s[i] == c) { l++; ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.