func_code_string stringlengths 59 71.4k |
|---|
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 20; int h[maxn], n, q, cnt; string s; struct Node { int ans, mx, mn, l, r, lazy; Node(int a = 0) { ans = mn = mx = l = r = lazy = a; } void update(Node a, Node b) { ans = max({a.ans, b.ans, a.l + b.mx, b.r + a.mx}); m... |
#include <bits/stdc++.h> using namespace std; int safeop(int n, int mod) { return (n + mod) % mod; } int main() { int n; cin >> n; vector<int> v(n, 0); vector<pair<int, int>> ans(n); for (int i = 0; i < n; i++) { cin >> v[i]; } int vn = n; int v1 = -1; stack<int> bal1; ... |
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; for (int i = 1; i <= n; ++i) cout << 1 << ; cout << endl; } } |
#include <bits/stdc++.h> using namespace std; template <typename T> inline bool upmin(T &x, T y) { return y < x ? x = y, 1 : 0; } template <typename T> inline bool upmax(T &x, T y) { return x < y ? x = y, 1 : 0; } const long double eps = 1e-9; const long double pi = acos(-1); const int oo = ... |
#include <bits/stdc++.h> using namespace std; int t, n; string s; int main(void) { cin >> t; while (t--) { map<pair<int, int>, int> m; int start = 0, end = 2147483647, x = 0, y = 0; cin >> n >> s; s.insert(s.begin(), 0 ); m.insert({make_pair(0, 0), 0}); for (int i = ... |
#include <bits/stdc++.h> using namespace std; const int N = 20; const int M = 1e5 + 55; pair<int, int> dp[(1 << N) + 5]; int dis[N][N]; int My[(1 << N) + 5][N]; int taken[(1 << N) + 5][N]; char s[M]; int sum[N]; int lg[(1 << N) + 55]; int m, n; pair<int, int> bt(int mask) { if (mask == (1 <<... |
#include <bits/stdc++.h> using namespace std; long long a[100001]; int main() { long long int n, i, count = 0; long long sum = 0; scanf( %I64d , &n); for (i = 0; i < n; i++) scanf( %I64d , a + i); sort(a, a + n); for (i = 0; i < n; i++) { if (sum <= a[i]) { count++; s... |
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int x, y, idx; cin >> x >> y >> idx; if (idx == 0) cout << x << endl; else if (idx == 1) cout << y << endl; else { idx -= 2; int z; while (tr... |
#include <bits/stdc++.h> using namespace std; using INT = unsigned long long; const int N = 100000; struct Ring { INT a[5]; Ring() { memset(a, 0, sizeof a); } Ring operator+(Ring r) { Ring R = r; for (int i = 0; i < 5; i++) R.a[i] += a[i]; return R; } void operator+=(Ring r... |
#include <bits/stdc++.h> using namespace std; int main() { int n, i, cnt = 0; cin >> n; char arr[n]; for (i = 0; i < n; i++) cin >> arr[i]; for (i = 0; i < n - 1; i++) { if (arr[i] == U && arr[i + 1] == R ) { arr[i] = D ; arr[i + 1] = D ; } else if (arr[i] == R ... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base ::sync_with_stdio(false); cin.tie(NULL); long long int tests = 1; while (tests--) { long long int n; int x; cin >> n >> x; if (n % 6 == 0) cout << x; else if (n % 6 == 1) { if (x == 0) ... |
#include <bits/stdc++.h> using namespace std; template <typename T, typename U> ostream &operator<<(ostream &out, const pair<T, U> &p) { out << ( << p.first << , << p.second << ) ; return out; } template <template <typename, typename...> class ContainerType, typename ValueType, typen... |
#include <bits/stdc++.h> int isPerfectSquare(int number) { int iVar; float fVar; fVar = sqrt((double)number); iVar = fVar; if (iVar == fVar) return 1; else return 0; } int main() { int no; scanf( %d n , &no); int a[no]; int max; max = -1000000; for (int ... |
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 7; vector<int> ad[N]; int h[N], n, m, dp[N][30]; int d[N], R = 320; vector<int> red; void dfs(int v, int p) { h[v] = h[p] + 1; dp[v][1] = p; for (auto u : ad[v]) { if (u != p) dfs(u, v); } } int dis(int u, int v) {... |
#include <bits/stdc++.h> #pragma comment(linker, /STACK: 1024000000,1024000000 ) using namespace std; inline int getint() { int _x = 0; char _tc = getchar(); while (_tc < 0 || _tc > 9 ) _tc = getchar(); while (_tc >= 0 && _tc <= 9 ) _x *= 10, _x += (_tc - 0 ), _tc = getchar(); return _... |
#include <bits/stdc++.h> using namespace std; using LL = long long; using uint = unsigned int; template <typename T> inline void read(T& x) { x = 0; long long f = 1; register char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == - ) f = -1; for (; isdigit(c); c = getchar()... |
#include <bits/stdc++.h> using namespace std; const long long INF = 0x3f3f3f3f3f3f3f3f; const long long MAXN = 4e3 + 7; const long long MAXM = 1e6 + 7; const long long MOD = 1e9 + 7; const double eps = 1e-6; const double pi = acos(-1.0); long long quick_pow(long long a, long long b) { long long ans ... |
#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; template <typename... T> void err(istream_iterator<string> it) {} template <typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cerr << *it << = << a << , ; err(++it, args...); } const long long inf = 1LL << 60;... |
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10, inf = 0x3f3f3f3f; void cmin(int& x, int y) { if (x > y) { x = y; } } int n, a[N]; long long answer; vector<int> adj[N]; void dfs(int u, int p, int d, int s) { if (d & 1) { answer += a[u] - s; s = a[u]; ... |
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) #pragma GCC optimize( unroll-loops ) #pragma GCC optimize( -ffloat-store ) #pragma GCC optimize( -fno-defer-pop ) long long power(long long a, long long b, long long m) { if (b == 0) return 1; if (b == 1) return a % m; long long t = power(a, b... |
#include <bits/stdc++.h> using namespace std; int n; int x[100000]; int dist(int a, int b) { return abs(a - b); } int main() { int n; cin >> n; for (int i = 0; i < n; i++) cin >> x[i]; cout << dist(x[0], x[1]) << << dist(x[0], x[n - 1]) << endl; for (int i = 1; i < n - 1; i++) co... |
#include <bits/stdc++.h> using namespace std; int main() { int n; string s; int sz; cin >> n; cin >> s; sz = s.size(); int count = 0; bool valid = true; for (int i = 0; i < sz; i++) { if (s[i] == 1 ) { if (i < sz - 1 && s[i + 1] == 1 ) { valid = false; ... |
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 500, mod = 998244353; int K, tmp[N], tmpa[N], tmpb[N], rev[N], b[N], tw[N], w[N], limn, n, qn; vector<int> a[N]; int qpower(int a, int b) { int ans = 1; for (; b; b >>= 1, a = 1ll * a * a % mod) if (b & 1) ans = 1ll * ans * a % mo... |
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[n]; for (int x = 0; x < n; x++) { cin >> a[x]; } for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { for (int k = 0; k < n; ++k) { if (a[i] == a[j] + a[k] && (i != j && j !... |
#include <bits/stdc++.h> using namespace std; struct FenwickTree { int n; vector<int> bit; FenwickTree(int n) { this->n = n + 1; bit.assign(n + 1, 0); } int sum(int r) { int sum = 0; while (r > 0) { sum += bit[r]; r -= (r & -r); } return sum; ... |
#include <bits/stdc++.h> using namespace std; int n, d, a, b, x, y, ans = 0; pair<int, int> m[111111]; long long sum = 0; int main() { scanf( %d%d%d%d , &n, &d, &a, &b); for (int i = 0; i < n; i++) { scanf( %d%d , &x, &y); m[i].first = a * x + b * y; m[i].second = i + 1; } so... |
#include <bits/stdc++.h> using namespace std; const int LIMIT = 3e5; long long n, m, a[LIMIT], p[LIMIT], d[LIMIT]; long long gcd(long long a, long long b) { if (a % b == 0) return b; return gcd(b, a % b); } int main() { scanf( %lld %lld , &n, &m); for (int i = 0; i < n; i++) { scanf( %... |
#include <bits/stdc++.h> using namespace std; const int N = 105; int Q[N], S[N], ok[N + N], Sav[N], mat[N + N][N]; int dp[N + N][N]; int solve(int p, int k) { if (ok[p]) return k == 0; if (!k) return 0; if (dp[p][k] != -1) return dp[p][k]; return dp[p][k] = solve(p - 1, k - 1) | solve(p + 1, k... |
#include <bits/stdc++.h> using namespace std; int main() { long long int i, a, n, sum = 0, hand = 0; vector<long long int> v; cin >> n; v.clear(); for (i = 0; i < n; i++) { cin >> a; if (a % 2 != 0) hand++; v.push_back(a); sum += a; } long long int value = 1e13; ... |
#include <bits/stdc++.h> using namespace std; int a[10]; int main() { cin >> a[1] >> a[2] >> a[3]; sort(a + 1, a + 1 + 3); cout << max(a[3] - a[1] - a[2] + 1, 0) << endl; return 0; } |
#include <bits/stdc++.h> inline int getint() { int x = 0, p = 1; char c = getchar(); while (c <= 32) c = getchar(); if (c == 45) p = -p, c = getchar(); while (c > 32) x = x * 10 + c - 48, c = getchar(); return x * p; } using namespace std; const int N = 110; const int M = 25; int dp[... |
#include <bits/stdc++.h> using namespace std; struct Point { double x, y; Point() : x(0), y(0) {} Point(double _x, double _y) : x(_x), y(_y) {} bool operator<(const Point &b) const { return tie(x, y) < tie(b.x, b.y); } bool operator==(const Point &b) const { return tie(x, y) == tie(b.x, b.y); } ... |
#include <bits/stdc++.h> using namespace std; int n; string str; int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n >> str; int ans = 0; for (int i = 0; i < n; i += 2) { int cnt = 0; if (str[i] == a ) cnt++; else cnt--; if (str[i + 1] == a ) ... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int TESTS = 1; while (TESTS--) { long long n; cin >> n; string s; cin >> s; cout << n + 1 << endl; } return 0; } |
#include <bits/stdc++.h> using namespace std; void fast() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } const int N = 2e5 + 5; vector<pair<long long, long long> > v; long long n, m, k; void solve() { sort(v.rbegin(), v.rend()); long long sum = 0; vector<long ... |
#include <bits/stdc++.h> using namespace std; int main() { int k, a, b, v, ans; while (scanf( %d%d%d%d , &k, &a, &b, &v) != EOF) { ans = 0; while (a > 0) { if (b >= k - 1) { b -= (k - 1); a -= v * k; ans++; } else { b = b + 1; a -... |
#include <bits/stdc++.h> using namespace std; constexpr int kN = int(3E2 + 10), kC = int(2E6 + 10); vector<pair<int, int>> v[kC], nv[kC]; int ans[kC], a[kN][kN], pos[kN][kN], p[kN * kN], up[kN * kN], dwn[kN * kN], lft[kN * kN], rht[kN * kN], nans[kC]; bool have[kN * kN]; int Find(int n) { return p[n] ... |
#include <bits/stdc++.h> using namespace std; int n; vector<int> graph[80005]; bool vis[100005]; long long int size[100005]; long long int arr[100005]; long long int ans2; long long int ans; int dfs1(int node) { vis[node] = true; int ret = 1; for (int i = 0; i < graph[node].size(); i++) { ... |
#include <bits/stdc++.h> using namespace std; #pragma GCC target( avx2 ) #pragma GCC optimization( O3 ) #pragma GCC optimization( unroll-loops ) struct custom_hash { static uint64_t splitmix64(uint64_t x) { x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >>... |
#include <bits/stdc++.h> using namespace std; char ff[1005][1005]; int main() { int t; scanf( %d , &t); for (int i = 0; i < t; i++) { int zz[1005]; int n, m, x, y; int ww = 0; int w = 0; scanf( %d%d%d%d , &n, &m, &x, &y); for (int j = 1; j <= n; j++) { char ... |
#include <bits/stdc++.h> using namespace std; const int MAXN = 1000; const int MAX = 100000 + 100; const int inf = 999999999; const int p1 = 104393321, p2 = 104393329; int n, m; int par[MAX], sizeofcom[MAX], size[MAX], a[MAX], b[MAX], d[MAX]; bool lucky(int x) { while (x > 0) { if (x % 10 == 7... |
#include <bits/stdc++.h> #pragma warning(disable : 4996) using namespace std; int main() { string s1, s2, s; int n, m; scanf( %d%d , &n, &m); map<string, string> mp; for (int i = 0; i < m; ++i) { cin >> s1 >> s2; if (s2.size() >= s1.size()) mp[s1] = s1; else m... |
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const int INF = 2e9; const long long int LONGINF = 4e18; long long int inv[200200], fct[200200], invfct[200200]; long long int c[2222]; long long int C(long long int n, long long int k) { return fct[n] * invfct[n - k] % mod * invfc... |
#include <bits/stdc++.h> using namespace std; int x[110], s[110]; int main() { int n, m; cin >> n >> m; for (int i = (1); i < (n + 1); i++) cin >> x[i]; for (int i = (1); i < (n + 1); i++) s[i] = s[i - 1] + x[i]; int v = 0; while (m--) { int l, r; cin >> l >> r; if (s[r] ... |
#include <bits/stdc++.h> using namespace std; const int inf = 1e9; vector<vector<int>> g; vector<int> vis, cap; void dfs(int s) { vis[s] = 1; cap[s] = 1; for (int i : g[s]) { if (vis[i] == 0) { dfs(i); } } } int32_t main() { { ios_base::sync_with_stdio(false);... |
#include <bits/stdc++.h> using namespace std; template <class T> void read(T& num) { char CH; bool F = false; for (CH = getchar(); CH < 0 || CH > 9 ; F = CH == - , CH = getchar()) ; for (num = 0; CH >= 0 && CH <= 9 ; num = num * 10 + CH - 0 , CH = getchar()) ; F &&... |
#include <bits/stdc++.h> using namespace std; const int N = 200010; struct edge { int from, to, next; } e[N * 20], e2[N * 10]; int head[N], ecnt, vis[N], fa[N][18], dep[N], ok[N * 10], ecnt2; map<pair<int, int>, int> mp; inline void adde(int from, int to) { e[++ecnt] = (edge){from, to, head[from]}... |
#include <bits/stdc++.h> using namespace std; const int MAXN = 100005; const int P = 1e9 + 7; 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; struct node { long long minn; int p, min_ind; node(long long a = 0, int b = 0, int c = 0) { minn = a, p = b, min_ind = c; } }; struct lazy_node { long long sv, snx, av, anx; lazy_node(long long a = -1, int b = 0, long long c = 0, int d = 0) { ... |
#include <bits/stdc++.h> using namespace std; int rain(int n, int *T, int i) { int r = 1; int d = i + 1, g = i - 1, ex = i; while ((g >= 0) && (T[g] <= T[i])) { r++; i = g; g--; } i = ex; while ((d < n) && (T[d] <= T[i])) { r++; i = d; d++; } retur... |
#include <bits/stdc++.h> using namespace std; char s[131100]; int cal(int l, int r, char t) { int cnt = 0; for (int i = l; i <= r; i++) { if (s[i] != t) cnt++; } return cnt; } int dfs(int l, int r, char t) { if (l == r) return cal(l, r, t); int ret = 1e9; int mid = (l + r) >>... |
#include <bits/stdc++.h> using namespace std; const long long mo = 1e9 + 7; char s[2010], ss[2010]; long long dp[2010][2010], a[2010]; long long m, d, jo; int len; long long dfs(int pos, long long sum, bool limit) { if (pos == len) return sum == 0; if (!limit && dp[pos][sum] != -1) return dp[pos][... |
#include <bits/stdc++.h> using namespace std; int N; long long M; int A[200002], B[200002]; map<int, int> MP; vector<pair<long long, long long> > ST; long long getover(pair<long long, long long> p, int i2) { if (p.second >= ST[i2].second) return 0; return (ST[i2].second - p.second) / (p.first - ST... |
#include <bits/stdc++.h> using namespace std; int b[200010]; int main() { long long n; cin >> n; for (int i = 0; i < n; i++) scanf( %d , &b[i]); sort(b, b + n); int m = b[n - 1] - b[0]; int m1 = b[n - 1], m2 = b[0]; long long c1 = 0, c2 = 0; for (int i = 0; i < n; i++) { if (... |
#include <bits/stdc++.h> using namespace std; int gcd(long long int a, long long int b) { if (b == 0) return a; return gcd(b, a % b); } long long int binomialCoeff(long long int n, long long int k) { long long int C[n + 1][k + 1]; long long int i, j; for (i = 0; i <= n; i++) { for (j =... |
#include<bits/stdc++.h> #define ll long long #define ld long double #define pb push_back #define x first #define y second #define fastread ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); using namespace std; //modulo op const ll mod = 1e9 + 7; ll add(ll a, ll b) { return (... |
#include <bits/stdc++.h> using namespace std; __attribute__((constructor)) void Init() { ios_base::sync_with_stdio(false), cin.tie(0), cout << fixed; } constexpr int N = 5e3; char A[N + 2], B[N + 2]; int16_t dp[2][N + 1]; int main() { int n, m, t = 0, ans = 0; cin >> n >> m >> &A[1] >> &B[1]; ... |
#include <bits/stdc++.h> using namespace std; signed main() { cin.tie(nullptr)->sync_with_stdio(false); long long _; for (cin >> _; _--;) { long long n, m, k; cin >> n >> m >> k; long long mn = (n % 2 == 1 ? m / 2 : 0); long long mx = n * m / 2 - (m % 2 == 1 ? n / 2 : 0); i... |
#include <bits/stdc++.h> using namespace std; const int INF = 1000000007; const long long INF2 = 1000000000000000007; const int MOD = 774254531; const int MOD1 = 892237699; const int SIZE = 150010; const double eps = 1e-6; long long n, m; long long ar[1010][1010], res; string st, b, minn; long lon... |
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 5; string name[maxn], s; vector<int> G[maxn]; int tot, a[maxn], maxd, dep[maxn]; int dfs(int &p, int d) { maxd = max(maxd, d); int ret = ++tot; dep[ret] = d; while (s[p] != , ) { name[ret].push_back(s[p++]); } ... |
#include <bits/stdc++.h> using namespace std; const long double C = 1e6; struct cir { int x, y, z; } a[5]; int disf(cir x, cir y) { return (x.x - y.x) * (x.x - y.x) + (x.y - y.y) * (x.y - y.y); } bool kcr(cir x, cir y) { return disf(x, y) <= (x.z + y.z) * (x.z + y.z) && disf(x, y) >... |
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; int arr[n]; int ar[m]; for (int i = 0; i < n; i++) { cin >> arr[i]; } for (int j = 0; j < m; j++) { cin >> ar[j]; } for (int k = 0; k < n; k++) { for (int l = 0; l < m; l++) { ... |
#include <bits/stdc++.h> using namespace std; int main() { std::ios::sync_with_stdio(0); long long n, h, k; cin >> n >> h >> k; vector<long long> mas(n); for (int i = 0; i < n; i++) cin >> mas[i]; long long time = 0, currVolume = 0; bool have = false; for (int i = 0; i < n; i++) { ... |
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; if (n % 2 == 1) cout << 0 << endl; else { long long int tt = 1; tt = pow(2, n / 2); cout << tt << endl; } return 0; } |
#include <bits/stdc++.h> using namespace std; char s[200010], p[200010]; int a[200010], n, t; bool ok(int len) { int i = 1, j = 1; while (i <= n) { if (a[i] <= len) { i++; continue; } if (s[i] == p[j]) { i++; j++; } else { i++; } ... |
#include <bits/stdc++.h> using namespace std; int main() { string s, p = ; cin >> s; int i, j = 0, f = 0, start, end; for (i = s.size() - 1; i >= 0 && f == 0; i--) { if (s[i] != 0 ) { end = i; f = 1; } } f = 0; for (i = 0; i < s.size() && f == 0; i++) { ... |
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 15; map<pair<int, int>, int> H; int t[N]; vector<int> adj[N]; int sum[N]; void update(int x, int add) { if (x == 0) return; while (x < N) sum[x] += add, x += x & (-x); } int q(int x) { int ret = 0; while (x) ret += sum[x... |
#include <bits/stdc++.h> using namespace std; int n, m; int ans[100100]; struct by { int l, r, id, i, num; } a[100100 * 2]; bool cmp(by a, by b) { if (a.r != b.r) return a.r < b.r; return a.id < b.id; } struct byy { int i, l; byy() {} byy(int i, int l) : i(i), l(l) {} bool op... |
#include <bits/stdc++.h> using namespace std; const double pi = 2 * acos(0); unsigned long long int binpow(unsigned long long int b, unsigned long long int n) { if (n == 0) return 1; if (n == 1) return b; if (n & 1) return binpow(b, n - 1) * b; else retu... |
#include <bits/stdc++.h> using namespace std; const long long N = 1e6 + 1; const long long INF = 1e9 + 7; const long long inf = 1e18; vector<long long> adj[N]; long long vis[N]; long long ans[N]; long long ct; void dfs(long long node) { vis[node] = ct; ans[ct]++; for (auto it : adj[node]) ... |
#include <bits/stdc++.h> using namespace std; const int INF = 1 << 30; const int maxn = 100007; int n, m, T; int top, k[10004], ans[maxn]; struct student { int t, x, i; void get(int l) { scanf( %d%d , &t, &x); i = l; } bool operator<(const student &b) const { if (t == b.t) ... |
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[n + 1]; int m = 1; for (int i = 1; i < n; i++) { m += i; if (m > n) m = m - n; cout << m << ; } return 0; } |
#include <bits/stdc++.h> #pragma GCC optimize(2) using namespace std; inline long long read() { char c = getchar(); long long x = 0; bool f = 0; for (; !isdigit(c); c = getchar()) f ^= !(c ^ 45); for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48); if (f) x = -x; retur... |
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; const long long MAX = 1e9 + 7; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; int a[n]; set<int> s; for (int i = 0; i < n; i++) s.insert(i + 1); for (int i = 0; i < n; i++) {... |
#include <bits/stdc++.h> using namespace std; int n, m; int box[300010]; bool check(int times) { int mi = 0; for (int i = 0; i < n; ++i) { if (box[i] + times < m) { if (mi > box[i] + times) return false; mi = max(mi, box[i]); } else { if (mi >= box[i]) conti... |
#include <bits/stdc++.h> using namespace std; int main() { int q; cin >> q; for (int i = 0; i < q; i++) { int n; cin >> n; int ans = 0; int ct_4 = n / 4; int rem = n % 4; if (rem == 1) { ct_4 -= 2; ans = ct_4 + 1; } else if (rem == 2) { c... |
#include <bits/stdc++.h> using namespace std; inline int ri() { int x; scanf( %d , &x); return x; } template <typename T> inline bool smax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <typename T> inline bool smin(T &a, T b) { if (a > b... |
#include <bits/stdc++.h> using namespace std; int main() { cin.tie(0); cout.tie(0); ios::sync_with_stdio(false); int t; cin >> t; while (t--) { string s; cin >> s; int cntR = 0, cntS = 0, cntP = 0; for (int i = 0; i < s.size(); ++i) { if (s[i] == R ) ... |
#include <bits/stdc++.h> using namespace std; const int inf = 1e9; int n, m; char a[5555][5555]; int r[5555][5555]; int c[5555]; int ans = 0; int main() { int i, j; cin >> n >> m; for (i = 1; i <= n; ++i) { getchar(); for (j = 1; j <= m; ++j) { a[i][j] = getchar(); ... |
#include <bits/stdc++.h> using namespace std; long long red[210]; long long green[210]; long long blue[210]; long long dp[210][210][210]; int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); int r, g, b; cin >> r >> g >> b; for (int i = 1; i <= r; i++) cin >> red[i]; for (int i ... |
#include <bits/stdc++.h> using namespace std; int main() { int n, m, k; cin >> n >> m >> k; int stol = 1; while (k > m * 2) { k -= m * 2; stol++; } cout << stol << ; int str; str = k / 2 + k % 2; cout << str << ; if (k % 2 == 0) { cout << R ; } el... |
#include <bits/stdc++.h> using namespace std; int main() { int n, b, p; cin >> n >> b >> p; int a[10 + n], useP = 0, i, useB = 0; for (i = 0; i < n; i++) { cin >> a[i]; } for (i = 0; i < n; i++) { if (a[i] == 1) useB++; else { if ((p - useP) <= 0) ... |
#include <bits/stdc++.h> char s[10000]; int main() { int n; scanf( %d , &n); scanf( %s , s); int t, d; bool succ = false; for (t = 0; t < n && !succ; ++t) { for (d = 1; t + 4 * d < n; ++d) { if (s[t] == * && s[t + d] == * && s[t + d + d] == * && s[t + 3 * d] =... |
#include <bits/stdc++.h> using namespace std; int main() { long long a, b, i, ans, p, MD = 1000000007; cin >> a >> b; p = ((a * (a + 1)) / 2) % MD; p = p * b % MD; p = (a + p) % MD; ans = ((b * (b - 1) / 2)) % MD; ans = (ans * p) % MD; cout << ans << endl; return 0; } |
#include <bits/stdc++.h> using namespace std; const long long INF = 4e18 + 5; const int inf = 1e9 + 5; const int maxn = 1e6 + 5; int h, m, a; int MAIN() { scanf( %d:%d , &h, &m); scanf( %d , &a); int tot = h * 60 + m + a; tot %= (24 * 60); printf( %02d:%02d n , tot / 60, tot % 60); r... |
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; vector<long> v(n); long mul = 1; for (int i = 0; i < n; ++i) cin >> v[i]; if (n > 1000) { cout << 0 n ; return 0; } for (int i = 0; i < n - 1; ++i) for (int j = i + 1; j < n; ++j) ... |
#include <bits/stdc++.h> using namespace std; const int N = 2e3 + 9; bool p[N][N]; priority_queue<pair<pair<int, int>, pair<int, int> > > q; int cu; int n, m, si, sj, ml, mr, a, b, ti, tj; char c; bool valid(int i, int j) { return i > 0 && i <= n && j > 0 && j <= m && p[i][j]; } void add(int x, ... |
#include <bits/stdc++.h> using namespace std; int main() { long long int t, n, a, b, x, l, m, e, d, s; cin >> t; while (t--) { cin >> n >> x >> a >> b; if (a > b) { l = a; s = b; } else { l = b; s = a; } d = n - l; if (x <= d) { ... |
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; for (int i = 0; i < s.length(); i++) if (s[i] > 4 ) s[i] = 9 - s[i] + 0 ; if (s[0] == 0 ) s[0] = 9 ; cout << s; return 0; } |
#include <bits/stdc++.h> using namespace std; int const nmax = 1000; int const modulo = 7340033; int dp[40][5 + nmax]; int dp2[40][5 + nmax]; int main() { dp[0][0] = 1; dp[1][1] = 1; dp[1][0] = 1; for (int i = 2; i <= 32; i++) { dp[i][0] = 1; for (int j = 0; j <= nmax; j++) ... |
#include <bits/stdc++.h> using namespace std; inline int read() { int d = 0; char c = getchar(); while (c < 0 || c > 9 ) c = getchar(); while (c >= 0 && c <= 9 ) { d = (d << 3) + (d << 1) + c - 0 ; c = getchar(); } return d; } const int N = 1e5 + 5; const long long I... |
#include <bits/stdc++.h> using namespace std; int main() { double sum; int n, m, k, i; while (scanf( %d %d %d , &n, &m, &k) == 3) { sum = 1; if (k + n < m) { printf( 0 n ); continue; } else { for (i = 0; i <= k; i++) { sum *= (m - i); sum /= ... |
#include <bits/stdc++.h> using namespace std; int main() { int N, K, C; int fiestas[1000]; int i, j, t; scanf( %d%d%d , &N, &K, &C); for (i = 0; i < C; i++) scanf( %d , &fiestas[i]); sort(fiestas, fiestas + C); fiestas[C] = (1 << 30); i = 0; t = 0; int res = 0; while (t <... |
#include <bits/stdc++.h> using namespace std; struct vahag { int hor, ver; }; vahag a[25][25]; const int N = 100005; int n, m, i, j, k, q, s, w, v, ans; string t, p; int bfs(int i, int j) { int qanak = 0; bool mark[25][25] = {0}; queue<int> xx, yy; xx.push(i); yy.push(j); mar... |
#include <bits/stdc++.h> using namespace std; long long int containsDigit(long long int number, long long int digit) { while (number != 0) { int curr_digit = number % 10; if (curr_digit == digit) return 1; number /= 10; } return 0; } long long int soltn(long long int x, long long i... |
#include <bits/stdc++.h> using namespace std; multiset<long long> s[200004]; long long a[200005]; long long su[200005]; int main() { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); long long n, k; cin >> n >> k; for (long long i = 0; i < n; i++) { cin >> a[i]; } long long x; ... |
#include <bits/stdc++.h> using namespace std; long long q, n, t1, t2, t[200005]; int main() { cin >> q; while (q--) { cin >> n; for (int i = 0; i < n + 1; ++i) t[i] = 0; for (int i = 0; i < n; ++i) cin >> t1, ++t[t1]; sort(t, t + n + 1); reverse(t, t + n + 1); long long... |
#include <bits/stdc++.h> using namespace std; int main() { int tc, cs = 1; scanf( %lld , &tc); while (tc--) { long long a, b, c, d; scanf( %lld %lld , &a, &b); scanf( %lld %lld , &c, &d); if ((b - a) % (c + d) == 0) cout << (b - a) / (c + d) << endl; else co... |
#include <bits/stdc++.h> using namespace std; vector<int> a[200100]; int cnt[200100]; vector<int> res; int main() { int n; scanf( %d , &n); int q; for (int i = 1; i <= n; i++) { scanf( %d , &q); a[q].push_back(i); } int pos = 0; while (true) { if (cnt[pos] < a[pos... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.