func_code_string stringlengths 59 71.4k |
|---|
#include <bits/stdc++.h> int main() { long int n; scanf( %ld , &n); long int a[n + 1], i, sum = 0; for (i = 0; i < n; i++) { scanf( %ld , &a[i]); sum = sum + a[i]; } if (sum % n == 0) { printf( %ld n , n); } else { printf( %ld n , n - 1); } return 0; } |
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 100; long long a[N], f[N], g[N], r1, r2, r3, d; int n; long long nkb() { return min(r1, r2); } long long cnkb(int i) { return min(r2, r1 * a[i] + nkb()); } long long clear_go(int i) { return min(r1 * a[i] + r3, cnkb(i) + d + d + nkb());... |
#include <bits/stdc++.h> using namespace std; int gcd(long long a, long long b) { if (b == 0) { return a; } else { return gcd(b, a % b); } } int main() { ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); ; long long i, j, k, n, m, t = 1; cin >> t; while (t--)... |
#include <bits/stdc++.h> struct point { int x, y; inline point operator+(const point &a) const { return {x + a.x, y + a.y}; } inline point operator-(const point &a) const { return {x - a.x, y - a.y}; } inline int operator^(const point &a) const { return x * a.x + y * a.y; } inline int operator*(co... |
#include <bits/stdc++.h> using namespace std; const int maxn = 5e6 + 10; const int mod = 998244353; long long a[maxn], b[maxn], n, m, sum1, sum2, res1, res2; long long dp[3030][3030]; inline long long qm(long long a, long long b, long long res = 1) { for (a %= mod; b; b >>= 1, a = a * a % mod) if ... |
#include <bits/stdc++.h> inline int mymin(int x, int y) { return x < y ? x : y; } bool isprime[22000]; inline void init_prime() { memset(isprime, true, sizeof(isprime)); for (int i = 2; i <= (int)sqrt(20000 * 1.0); ++i) if (isprime[i]) for (int j = 2; i * j <= 20000; ++j) isprime[i * j] = fa... |
#include <bits/stdc++.h> using namespace std; template <class T> const T& max(const T& a, const T& b, const T& c) { return max(a, max(b, c)); } template <class T> const T& min(const T& a, const T& b, const T& c) { return min(a, min(b, c)); } struct sp { bool operator()(const pair<string, int... |
#include <bits/stdc++.h> using namespace std; const int ms = 1001000; bool hole[ms]; int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(NULL); long long n, m, k; cin >> n; if (n == 1 || n == 2) { cout << 0; return 0; } cout << (n + 1) / 2 - 1; } |
#include <bits/stdc++.h> using namespace std; int main() { int i, x, ans, num, n, fa[2001]; while (scanf( %d , &n) != EOF) { for (i = 1; i <= n; i++) { scanf( %d , &fa[i]); } ans = 1; for (i = 1; i <= n; i++) { num = 1; x = i; while (fa[x] != -1) { ... |
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 5; const double eps = 1e-12; int n, k, h; struct lemming { int w, v, id; bool operator<(const lemming &rhs) const { if (w != rhs.w) return w < rhs.w; return v < rhs.v; } } a[maxn]; vector<int> ans; int dcmp(doub... |
#include <bits/stdc++.h> using namespace std; const int N = 110000; char a[N]; int chk[N]; int main() { ios_base::sync_with_stdio(0); int n; cin >> n; cin >> a; if (n == 1) { cout << Yes << endl; return 0; } for (int i = 0; i < n; i++) chk[a[i]]++; bool flg = 1; ... |
#include <bits/stdc++.h> using namespace std; const int MOD = 1000000007, dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; const double eps = 1e-8; void read(int &k) { k = 0; char x = getchar(); while (x < 0 || x > 9 ) x = getchar(); while (x >= 0 && x <= 9 ) { k = k * 10 - 48 + x; ... |
#include <bits/stdc++.h> using namespace std; const int MAX = 1e5 + 9; int n, v[MAX]; int main() { ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); cin >> n; for (int i = 0, x; i < n; i++) cin >> x, v[x % n] = i; for (int i = 0, x; i < n; i++) cin >> x, cout << v[x % n] + 1 << ; }... |
#include <bits/stdc++.h> using namespace std; const int M = 1000000000 + 7; const int N = 200000 + 10; const int NUMHASH = 3; const long long hashNum[3] = {M, M + 2, M + 14}; struct re { int x, y; }; int n, q; string s; int cnt[26][N], f[26][N], g[26][N]; long long h[NUMHASH][26][N], p[NUMHASH... |
#include <bits/stdc++.h> using namespace std; int main() { int n, i, ans = -1; cin >> n; pair<int, int> g[n]; for (i = 0; i < n; i++) { cin >> g[i].first >> g[i].second; } sort(g, g + n); for (i = 0; i < n; i++) { if (ans <= g[i].second) ans = g[i].second; else ... |
#include <bits/stdc++.h> using namespace std; int main(void) { int n, k; cin >> n >> k; int r[257] = {}; for (int i = 0; i < 257; i++) { r[i] = -1; } int p; for (int i = 0; i < n; i++) { cin >> p; if (r[p] == -1) { for (int j = (p - k + 1 >= 0) ? p - k + 1 : 0; ... |
#include <bits/stdc++.h> using namespace std; vector<int> p[300100]; int per[300300]; long long sz[300300]; long long mx[300300]; int res[300300]; long long dfs(int x) { sz[x]++; for (int i = 0; i < p[x].size(); i++) { long long t = dfs(p[x][i]); sz[x] += t; mx[x] = max(mx[x], t)... |
#include <bits/stdc++.h> using namespace std; const int N = 1234567; int a[N], gcd[N], is_max[N], cnt[N]; int main() { ios_base::sync_with_stdio(false); int n; cin >> n; for (int i = 0; i < n; ++i) { cin >> a[i]; a[i + n] = a[i]; } for (int i = 1; i <= n; ++i) { if (n %... |
#include <bits/stdc++.h> using namespace std; int n, i, j, ans = 0, f[30][30], h, t, l; char st[20]; int main() { scanf( %d n , &n); memset(f, 0, sizeof(f)); while (n--) { gets(st); l = strlen(st); h = (int)st[0] - 97; t = (int)st[l - 1] - 97; for (i = 0; i < 26; i++) ... |
#include <bits/stdc++.h> using namespace std; const long long N = 1e5 + 10, mod = 1e9 + 7; long long n, dp[2][N], d[2][N], t[2][N]; vector<long long> ch[N]; void dfs(long long v) { if (!ch[v].size()) { dp[0][v] = 0; dp[1][v] = 1; return; } for (long long i : ch[v]) dfs(i); d[... |
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const int N = 1e6 + 10; const int INF = 0x3f3f3f3f; const long long LINF = 0x3f3f3f3f3f3f3f3f; inline int read() { static char buf[1000000], *p1 = buf, *p2 = buf; register int x = false; register char ch = p1 == p2 &&... |
#include <bits/stdc++.h> using namespace std; int main() { int a, b; cin >> a >> b; int p = 0; int aa = a; while (aa > 0) { p = max(p, aa % 10); aa = aa / 10; } int bb = b; while (bb > 0) { p = max(p, bb % 10); bb = bb / 10; } p++; int carry = 0; ... |
#include <bits/stdc++.h> using namespace std; long long k, d, t, cnt = 0; bool f(double T) { long long interval = ((long long)ceil(k / (d * 1.0))) * d; long long no_of_interval = T / interval; double t_on = no_of_interval * k, t_off = (interval - k) * no_of_interval; double rem = T - no_of_interva... |
#include <bits/stdc++.h> using namespace std; int main() { long long int t; cin >> t; while (t--) { long long int n, rock = 0, peper = 0, sec = 0, de = 0; cin >> n; cin >> rock >> peper >> sec; string s, ans; cin >> s; for (long long int i = 0; i < n; i++) { i... |
#include <bits/stdc++.h> using namespace std; template <class T, class U> bool cmp_second(const pair<T, U> &a, const pair<T, U> &b) { return a.second < b.second; } pair<int, int> operator+(const pair<int, int> &a, const pair<int, int> &b) { return make_pair(a.first + b.first, a.second + b.second); }... |
#include <bits/stdc++.h> using namespace std; const int MAXN = 250000; int n, k, C[30], c[30]; vector<string> S; bool anda, Z, term; bool trythis(string X) { bool ans = true; for (int i = (0); i < (int)(k); i++) { int cnt = 0; for (int j = (0); j < (int)(n); j++) if (S[i][j] != X... |
#include <bits/stdc++.h> int fac[100100]; int n, m, i, x, j, l, r, p, ans, st, dr, mn, mx, M; void init() { int i, j; for (i = 2; i <= 100000; i++) if (!fac[i]) { fac[i] = i; if (i > 316) continue; for (j = i * i; j <= 100000; j += i) if (!fac[j]) fac[j] = i; ... |
#include bits/stdc++.h using namespace std; using ll = long long; using pii = pair<int,int>; vector<tuple<int,int,int>> edges; void add(int x, int y, int z) { edges.push_back({x,y,z}); } int solve(int l, int r) { if (l > 1) { int k = solve(1,r-l+1); add(k,k+1,l-1); ... |
#include <bits/stdc++.h> using namespace std; bitset<501> bt[1010]; int c[505]; int ans[250001], tot; int main() { tot = 0; int n, k; scanf( %d%d , &n, &k); for (int i = 1; i <= n; i++) scanf( %d , &c[i]); bt[0].set(0); int maxn = 0; for (int i = 1; i <= n; i++) { int lim = m... |
#include <bits/stdc++.h> #pragma comment(linker, /STACK:1024000000,1024000000 ) using namespace std; int main() { int n; cin >> n; if (n % 2 == 0) { cout << (n / 2) - 1 << endl; } else { cout << n / 2 << endl; } return 0; } |
#include <bits/stdc++.h> using namespace std; vector<long long> v; long long a[200011]; string s; int main() { long long n, k, i, x, res = 0, j; cin >> n >> k; for (i = 0; i < n; i++) cin >> a[i]; cin >> s; char C = A ; for (i = 0; i < n; i++) { x = k; if (s[i] == C) v.pus... |
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 13; int n, m; int a[maxn]; int main() { int T; scanf( %d , &T); while (T--) { long long n; long long x, y; scanf( %lld , &n); if (n == 1) { printf( 1 1 n ); continue; } long lon... |
#include <bits/stdc++.h> using namespace std; const int maxn = ((int)2e6) + 5; int energy[maxn]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n, u; cin >> n >> u; for (int i = 0; i < n; i++) cin >> energy[i]; int curr = 2; double eff = -1; for (int i = 1; i < n ... |
#include <bits/stdc++.h> using namespace std; inline char gc() { return getchar(); } template <class T> int read(T &ans) { ans = 0; char ch = gc(); T f = 1; while (!isdigit(ch)) { if (ch == EOF) return -1; if (ch == - ) f = -1; ch = gc(); } while (isdigit(ch)) ans = an... |
#include <bits/stdc++.h> using namespace std; inline int read() { int x = 0; char ch = getchar(); while (ch < 0 || ch > 9 ) ch = getchar(); while ( 0 <= ch && ch <= 9 ) x = x * 10 + ch - 0 , ch = getchar(); return x; } int t; int main() { t = read(); while (t--) { int n... |
#include <bits/stdc++.h> using namespace std; const int maxn = 3e5 + 100; long long x[maxn]; char type[maxn], t; vector<long long> B, R, G; long long szR, szB, n, pos; void Put(long long st, long long en) { R.clear(); B.clear(); for (int i = st; i <= en; ++i) { if (type[i] == 1) ... |
#include <bits/stdc++.h> using namespace std; template <typename T> bool chkmax(T &x, T y) { return x < y ? x = y, true : false; } template <typename T> bool chkmin(T &x, T y) { return x > y ? x = y, true : false; } int readint() { int x = 0, f = 1; char ch = getchar(); while (ch < ... |
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 5; int n; vector<int> a; long long inv[32][2]; void solve(vector<int> &a, int depth) { if (depth < 0) return; if (a.size() == 0) return; vector<int> left, right; long long cnt0 = 0, cnt1 = 0, sum01 = 0, sum10 = 0; for (... |
#include <bits/stdc++.h> using namespace std; const long long mod = (int)1e9 + 7; char s[5010], t[5010]; int n, m; int d[2][5010], ans, cs; int main() { int i, j; gets(s + 1); n = strlen(s + 1); gets(t + 1); m = strlen(t + 1); d[1][m + 1] = 1; for (i = n; i >= 1; i--) { cs ... |
#include <bits/stdc++.h> using namespace std; long long a, b, c, d, ans = 0; const long long maxn = 1e6 + 5; long long p[maxn]; int main() { cin >> a >> b >> c >> d; long long mx = min(b - a, c - b) + 1; for (long long i = a + b, t = 1; i <= b + c; ++i) { p[i] = t; t = min(t + 1, mx); ... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); long long int n, k; cin >> n >> k; long long int q = 8 * (n + k) + 9; long long int y = (-3 + sqrt(q)) / 2; cout << (y * (y + 1)) / 2 - k << n ; } |
#include <bits/stdc++.h> using namespace std; int gcd(int a, int b) { if (b == 0) { return a; } return gcd(b, a % b); } int a[300005]; bool notprime[8000005]; map<int, int> prims; vector<int> primes; void factor(int num) { for (int i = 0; i < primes.size() && primes[i] * primes[i] ... |
#include <bits/stdc++.h> int t1, t2; inline int get() { char c[10]; scanf( %s , &c); if (!strcmp(c, monday )) return 1; if (!strcmp(c, tuesday )) return 2; if (!strcmp(c, wednesday )) return 3; if (!strcmp(c, thursday )) return 4; if (!strcmp(c, friday )) return 5; if (!strcmp(c... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); long long i, j, a, n = 0; string s, str; cin >> a; cin >> s >> str; for (long long i = 0; i < s.size() - 1; i++) { if (s[i] == str[i]) continue; if (s[i] != str[i... |
#include <bits/stdc++.h> using namespace std; int n, a, b; char str[100005]; int main() { scanf( %d %d %d , &n, &a, &b); scanf( %s , str + 1); if (str[a] == str[b]) { puts( 0 ); return 0; } puts( 1 ); } |
#include <bits/stdc++.h> using namespace std; int main() { int n, x(0); cin >> n; string s; while (n--) { cin >> s; if (s[1] == + ) { ++x; } else { --x; } } cout << x << endl; return 0; } |
#include <bits/stdc++.h> using namespace std; int n, m; int main() { cin >> n >> m; int bagi = (n / m); if (bagi * m == n) { for (int i = 0; i < m; i++) { printf( %d , bagi); } } else { int sisa = (n - (m * bagi)); for (int i = 0; i < m; i++) { int now = 0;... |
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; pair<int, int> p[n]; for (int i = 0; i < n; i++) { cin >> p[i].first >> p[i].second; } bool check = true; for (int i = 0; i < n; i++) { if ... |
#include <bits/stdc++.h> using namespace std; const int mxn = 100003; long long f[20 * mxn + 10], rs[2 * mxn], ar[mxn + 10]; long long sum = 0; int n, m, k; struct data { int l, r, id; } query[mxn]; int bs = sqrt(mxn * 14); bool operator<(data a, data b) { return a.l / bs == b.l / bs ? a.r < b... |
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; vector<int> a[3]; for (int i = 0; i < 3; i++) { a[i].assign(n, 0); for (auto &x : a[i]) cin >> x; } vector<int> res; for (int i = 0; i < n;... |
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; const int N = 2e5 + 5; const int SZ = 1e6 + 5; const long long INF = 2e9 + 5; int n, m, p; pair<int, long long> a[N], b[N]; pair<int, pair<int, long long> > mon[N]; long long tree[4 * SZ], lazy[4 * SZ], cost[SZ]; void Build... |
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 10, mod = 1e9 + 7; int a[N]; int qmi(int a, int b) { int res = 1; while (b) { if (b & 1) res = (long long)res * a % mod; b >>= 1; a = (long long)a * a % mod; } return res; } int main() { int T; scanf(... |
#include <bits/stdc++.h> using namespace std; const int maxn = 200000 + 1000; char s1[maxn]; char s2[maxn]; int judge(int st1, int en1, int st2, int en2) { int sign = 0; for (int i = st1, j = st2; i <= en1; i++, j++) { if (s1[i] != s2[j]) { sign = 1; break; } } if (... |
#include <bits/stdc++.h> using namespace std; int main() { long long int n; while (cin >> n) { long long int lcm = 2520; cout << n / lcm << endl; } } |
#include <bits/stdc++.h> using namespace std; string st; set<string> S; map<string, int> mp; map<string, string> mp2; int n, q; int main() { ios::sync_with_stdio(false); cin >> n; for (int i = 0; i < n; i++) { S.clear(); cin >> st; int len = st.length(); for (int fr = 0... |
#include <bits/stdc++.h> using namespace std; int tot; int num[1008]; int is[1005]; int n, pos[1005][5]; int main() { scanf( %d , &n); for (int i = 0; i < n; i++) { for (int j = 0; j < 5; j++) { scanf( %d , pos[i] + j); } } int flag = 0; int yes = 0; if (n < 3) { ... |
#include <bits/stdc++.h> int x[200010], check[200010]; long long int ans[200010]; long long int size[200010]; int next[200010]; int find(int k) { if (next[k] == k) return k; else return next[k] = find(next[k]); } std::vector<int> V[200010]; int height[200010]; long long int func(in... |
#include <bits/stdc++.h> using namespace std; int main() { long long int n, m, *a, q, sum = 0; cin >> n; a = new long long int[n]; for (int i = 0; i < n; i++) { cin >> a[i]; sum += a[i]; } sort(a, a + n); cin >> m; for (int i = 0; i < m; i++) { cin >> q; cout ... |
#include <bits/stdc++.h> using namespace std; multiset<pair<int, int> > st; int main() { int n, k; cin >> n >> k; int cnt = 0; for (int i = 0; i < n; i++) { int num; cin >> num; cnt += num / 10; if (num < 100) st.insert(make_pair(num % 10, num)); } while (st.size() ... |
#include <bits/stdc++.h> using namespace std; const int N = 100100; long long n, t[N], m, res, ans[N]; int dd[N]; int main() { ios_base::sync_with_stdio(false); cin >> n >> m; for (int i = 1; i <= n; i++) cin >> t[i]; sort(t + 1, t + n + 1); long long sum = 0; int j = 1; for (int i... |
#include <bits/stdc++.h> using namespace std; long long poww(long long x, long long y) { if (x == 0) return 0; if (x == 1) return 1; if (y == 0) return 1; if (y == 1) return x; long long d = poww(x, y / 2); if (y % 2) return x * d * d; return d * d; } int main() { long long n, m;... |
#include <bits/stdc++.h> using namespace std; int one[100007], zero[100007]; const int mod = 1e9 + 7; long long FastPow(long long x, long long n, long long mod) { long long s = 1; while (n) { if (n & 1) s = s * x % mod; x = x * x % mod; n >>= 1; } return s % mod; } int main... |
#include <bits/stdc++.h> using namespace std; unsigned long long int power(unsigned long long int n, unsigned long long int p) { unsigned long long int m = 1; while (p > 0) { m *= n; p--; } return m; } void sieveOfEratosthenes(int n, bool prime[]) { ... |
#include <bits/stdc++.h> using namespace std; const int MAXN = 100; int main() { long long n, m, a[MAXN], st[MAXN]; scanf( %I64d %I64d , &n, &m); st[0] = 1; for (int i = 1; i <= n; i++) st[i] = st[i - 1] * 2; int l = 0; int r = n; for (int i = 1; i < n; i++) { if (m > st[n - i - ... |
#include <bits/stdc++.h> using namespace std; struct Edge { int v; Edge* next; }; const int N = 100010; int n, k; bool vis[N]; int dis[N], prt[N], deg[N]; Edge* g[N]; void adde(int u, int v); void dfs(int u); void pred(int u, int r); int main() { scanf( %d%d , &n, &k); for (int r... |
#include <bits/stdc++.h> using namespace std; const int MAXN = 100001; vector<pair<int, int> > g1[1000], g2[1000]; int edge_colors[MAXN]; pair<int, int> colors1[1000][1000]; pair<int, int> colors2[1000][1000]; int ans; bool used[MAXN]; bool dfs(int v, int c1, int c2) { if (used[v]) return false; ... |
#include <bits/stdc++.h> using namespace std; void solve() { long long n; cin >> n; long long arr[n + 1]; long long sum = 0; for (long long i = 1; i <= n; i++) { cin >> arr[i]; sum += arr[i]; } if (sum % n != 0) { cout << -1 << n ; return; } vector<pair<... |
#include <bits/stdc++.h> using namespace std; void trace_() { cerr << n ; } template <typename T1, typename... T2> void trace_(T1 t1, T2... t2) { cerr << << t1; trace_(t2...); } const long long mxN = 1e3 + 5; long long n, a, b; vector<long long> g[mxN]; signed main() { ios_base::sync... |
#include <bits/stdc++.h> using namespace std; int n, m, a[21], b[21], dp[42][42], dp2[82][42]; int main() { cin >> n >> m; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n; i++) cin >> b[i]; memset(dp, 0, sizeof(dp)); memset(dp2, 0, sizeof(dp2)); dp[0][1] = a[0 % n]; dp2[... |
#include <bits/stdc++.h> using namespace std; inline bool check(int x) { for (; x; x /= 10) if (x % 10 != 4 && x % 10 != 7) return 0; return 1; } const int maxn = 100100; int head[maxn], nxt[maxn << 1], ver[maxn << 1], val[maxn << 1], tot; inline void addedge(int a, int b, int c) { nxt[++t... |
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 5; vector<int> AdjList[maxn]; bool vis[maxn]; int child[maxn]; char ans[maxn]; int n; void dfs(int s, int p = -1) { child[s] = 1; for (int u : AdjList[s]) { if (vis[u]) continue; if (u == p) continue; dfs(u, s... |
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1.0); const double eps = 1e-9; const long long INF = 1000000000; const int MAXN = 128; int points[] = {0, 25, 18, 15, 12, 10, 8, 6, 4, 2, 1}; int t, n; map<string, vector<int> > places; map<string, int> score; struct T { strin... |
#include <bits/stdc++.h> using namespace std; template <class _T> inline _T sqr(const _T &first) { return first * first; } template <class _T> inline string tostr(const _T &a) { ostringstream os( ); os << a; return os.str(); } const long double PI = 3.1415926535897932384626433832795L; ... |
#include <bits/stdc++.h> using namespace std; long long a[300005]; int sign(long long x) { return x > 0 ? 1 : -1; } struct Node { int l, r, lx, mx, rx; void up(Node L, Node R) { lx = L.lx; rx = R.rx; mx = max(L.mx, R.mx); if (a[L.r] && a[R.l] && sign(a[L.r]) >= sign(a[R.l])) { ... |
#include <bits/stdc++.h> using namespace std; #pragma comment(linker, /stack:200000000 ) #pragma GCC optimize( O3 ) #pragma GCC optimize( O2 ) #pragma GCC optimize( Ofast ) #pragma GCC optimize( unroll-loops ) #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native ) const double pi... |
#include <bits/stdc++.h> using namespace std; const int MAX_N = 100010; const int INF = 1000000; int n; stack<int> killers; int main() { cin >> n; int values[n + 1], life[n + 1]; for (int i = 1; i <= n; ++i) { cin >> values[i]; } life[0] = INF; values[0] = 0; killers.push(0... |
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int arr[n]; for (int i = 0; i < n; ++i) { cin >> arr[i]; } for (int j = 0; j < n; ++j) { if (arr[j] == 0) if (j == (n - 1)) cout << EASY << endl; else continue; ... |
#include <bits/stdc++.h> using namespace std; int main() { int i, j, k, l, m, n; int a[1001]; char s[1000], c; while (scanf( %d%d , &n, &m) != EOF) { memset(a, 0, sizeof(a)); while (m--) { scanf( %s , s); scanf( %s , s); scanf( %s , s); c = s[0]; s... |
#include <bits/stdc++.h> using namespace std; char str[100]; int L; bool ok(int n) { if (n == 0) return true; set<string> S; for (int i = 0; i + n <= L; i++) { string temp(str + i, str + i + n); if (!S.insert(temp).second) return true; } return false; } int main() { scanf... |
#include <bits/stdc++.h> using namespace std; int main() { int n, k, a; cin >> n >> k; a = n - (k - (2 * n)); if (a >= 0) cout << a; else cout << 0; return 0; } |
#include <bits/stdc++.h> using namespace std; long long a[100000]; map<long long, long long> mp; map<long long, long long> mp1; int main() { cin.sync_with_stdio(false); long long i, j, k, l, c, d, e, f, g, h, v, b[10000], aa[1009], bb[1000], n, m, r, t; long long x1, x2, y1, y2, x3, x4, x5... |
#include <bits/stdc++.h> using namespace std; const unsigned long long hash1 = 201326611; const int inf = 0x3f3f3f3f; const int _inf = 0xc0c0c0c0; const long long INF = 0x3f3f3f3f3f3f3f3f; const long long _INF = 0xc0c0c0c0c0c0c0c0; const long long mod = (int)1e9 + 7; long long gcd(long long a, long long... |
#include <bits/stdc++.h> using namespace std; stack<int> S; int a[1005], n; bool judge() { for (int i = 0; i < n; i++) if (a[i] != i) return 0; return 1; } int main() { cin >> n; for (int i = 0; i < n; i++) scanf( %d , &a[i]); for (int i = 0; i <= n; i++) { if (judge()) { ... |
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string c = ROYGBIV ; vector<char> s; for (int i = 0; i < n; i++) { if (i <= 6) s.push_back(c[i]); else { s.push_back(s[i - 4]); } } for (int i = 0; i < n; i++) cout << s[i]; }... |
#include <bits/stdc++.h> using namespace std; template <typename T> inline bool uax(T &x, T y) { return (y > x) ? x = y, true : false; } template <typename T> inline bool uin(T &x, T y) { return (y < x) ? x = y, true : false; } template <typename T> void kek(T ans) { cout << ans << endl; ... |
#include <bits/stdc++.h> using namespace std; long long n, a, b; long long tinh(long long n) { long long l = 0, r = 1000001; while (l < r) { long long m = (l + r + 1) / 2; long long t = m * m * m; if (t > n) r = m - 1; else l = m; } return l; } int main(... |
#include <bits/stdc++.h> using namespace std; using Point = complex<int>; using ll = long long; ll cross(Point a, Point b) { return 1LL * a.real() * b.imag() - 1LL * b.real() * a.imag(); } ll det(Point a, Point b, Point c) { return cross(b - a, c - a); } namespace std { bool operator<(const Point& a... |
#include <bits/stdc++.h> using namespace std; using vi = vector<int>; const int LOG = 17; const int inf = 1e9; template <typename T> struct RMQ { vector<vector<T>> spr; RMQ(const vector<T>& v) : spr(1, v) { for (int j = 1; (1 << j) <= (int)v.size(); ++j) { spr.push_back(vector<T>((int)... |
#include <bits/stdc++.h> using namespace std; const long double EPS = 1e-15; const long double PI = 3.14159265358979323846; inline int lg2(long long n) { int h = 0; while ((1ll << h) < n) ++h; return h; } struct configio { configio() { cin.tie(nullptr); ios_base::sync_with_stdio(... |
#include <bits/stdc++.h> using namespace std; const long long N = 4e3 + 5; long long n, m, a[N], f[N][N]; long long solve(long long l, long long r) { if (l > r) return 0; long long p = 0; for (long long i = l; i <= r; i++) if (a[i] < a[p]) p = i; long long ls = solve(l, p - 1), rs = solve(... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; vector<int> a(n); vector<long long> f(2000006, -1); for (int i = 0; i < n; i++) { cin >> a[i]; f[a[i]] = i; } long long ans = 1e18, r... |
#include <bits/stdc++.h> using namespace std; int main() { cin.tie(0); ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long int n; cin >> n; long long int a[n], b[n], c[n - 1]; b[n - 1] = 0, c[n - 2] = 0; for (int i = 0; i < n; i++) { cin >> a[i]; ... |
#include <bits/stdc++.h> using namespace std; const int inf = 1e5 + 5; int n; int ans[inf]; int last[inf]; struct node { int x, h, q; bool operator<(const node &s) const { return s.x > x; } } a[inf << 1]; inline int read() { int a = 0; int b = 1; char c = getchar(); while (c < 0... |
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int sum, limits; vector<int> ans; cin >> sum >> limits; for (int i = limits; i >= 1; i--) { if ((i & (-i)) <= sum) { sum -= (i & (-i)); ans.push_back(i); } } if... |
#include <bits/stdc++.h> using namespace std; pair<int, int> arr[1000005]; int par[1000005], sz[1000005]; int find(int x) { if (par[x] != x) par[x] = find(par[x]); return par[x]; } void Union(int a, int b) { a = find(a); b = find(b); if (a != b) { par[a] = b; sz[b] += sz[a]; ... |
#include <bits/stdc++.h> using namespace std; int m, n, arr[200][200]; int color(int x, int y) { int col = 1; while (arr[x - 1][y] == col or arr[x][y - 1] == col or arr[x + 1][y] == col or arr[x][y + 1] == col) col++; return col; } int color2(int x, int y) { int col = 1; w... |
#include <bits/stdc++.h> using namespace std; int n, k; double dp[205][35][35]; vector<int> p; pair<int, int> rev(int x, int y, int rx, int ry) { if (x >= rx && x <= ry) { x = rx + (ry - rx) - (x - rx); } if (y >= rx && y <= ry) { y = rx + (ry - rx) - (y - rx); } return make_pa... |
#include <bits/stdc++.h> using namespace std; long long modular(long long a, long long b, long long c) { if (b == 0) { return 1; } if (b % 2 == 0) { return modular(((a * a) % c), b / 2, c); } else { return ((a % c) * (modular(((a * a) % c), b / 2, c) % c)) % c; } } signed m... |
#include <bits/stdc++.h> using namespace std; int main() { int n, m, k; cin >> n >> m >> k; char grid[n][m]; bool flag1 = 0, flag2 = 0; int cnt[100] = {}; for (int i = 0; i < n; i++) { string s; cin >> s; if (s.find( - ) < 0 || s.find( - ) >= s.size()) continue; int x... |
#include <bits/stdc++.h> using namespace std; int main() { int N; while (1 == scanf( %d , &N)) { vector<int> A(N); for (int i = 0; i < (int)(N); i++) scanf( %d , &A[i]); sort((A).begin(), (A).end()); int need_to_fill = 0, need_to_move = 0; for (int i = 0; i < (int)(N); i++) nee... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.