func_code_string stringlengths 59 71.4k |
|---|
#include <bits/stdc++.h> using namespace std; const int N = 3e5; int n, u, v, tp; int par[2][N], sz[2][N]; long long ans; int find_set(int v) { if (par[tp][v] == v) return v; return par[tp][v] = find_set(par[tp][v]); } void union_sets(int a, int b) { a = find_set(a); b = find_set(b); ... |
#include <bits/stdc++.h> using namespace std; struct Tpoint { double x, y; Tpoint() {} Tpoint(double _x, double _y) { x = _x; y = _y; } inline void read() { scanf( %lf%lf , &x, &y); } inline void show() { printf( %lf %lf n , x, y); } inline double norm() { return sqrt(((x) * ... |
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 7; map<long long, int> G; map<long long, map<long long, int> > multiMap; int main() { long long i, j, k, f1, f2, f3, f4, t1, t2, t3, t4; long long n, m, T; long long a, b; cin >> n >> a >> b; m = 0; for (i = 1; i <= n... |
#include <bits/stdc++.h> using namespace std; using ll = long long; using vll = vector<ll>; using vii = vector<int>; using pii = pair<int, int>; template <typename T = vii> using vec = vector<T>; const ll INF = 1e18, MOD = 1e9 + 7; const int MAX = 1e6; int main() { cin.tie(NULL); ios_base::s... |
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[1000000]; for (int i = 0; i < n; i++) { cin >> a[i]; } int cur = a[n - 1]; long long total = a[n - 1]; for (int i = n - 2; i >= 0; i--) { cur = min(cur - 1, a[i]); cur = max(0, cur); ... |
#include <bits/stdc++.h> using namespace std; const int INF = 1e8; const int N = 300100; int n, m, ans, nans; string mat[N], ansmat[N], nmat[N]; void upd() { if (nans >= ans) return; ans = nans; for (int i = 0; i < n; ++i) ansmat[i] = nmat[i]; } int main() { cin.tie(NULL); ios_base::... |
#include <bits/stdc++.h> using namespace std; const int N = 200010; vector<int> e[N]; set<int> l[N]; int n; void exitno() { printf( -1 n ); exit(0); } int exitans(int x) { while (x % 2 == 0) x /= 2; printf( %d n , x); exit(0); } void _dfs(int p, int fa) { if (fa && e[p].size(... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); int x; string y, z; cin >> x >> y >> z; if (z[0] == w ) { int fd = 5, ans = 0; for (int i = 1; i <= 366; ++i) { if (fd == x) ans++; fd++; if (fd == 8) fd = 1; } ... |
#include <bits/stdc++.h> using namespace std; template <typename... T> void show(T&&... args) { ((cerr << args << ), ...); } template <typename F, typename S> ostream& operator<<(ostream& os, const pair<F, S>& p) { return os << ( << p.first << , << p.second << ) ; } template <typename T... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, m, s, f; cin >> n >> m >> s >> f; map<int, pair<int, int> > mop; for (int i = 0; i < m; i++) { int t, l, r; cin >> t >> l >> r; mop[t] = {l, r}; ... |
#include <bits/stdc++.h> using namespace std; namespace dinic { using ll = int; const ll oo = 1e6; const int N = 202 * 202 * 2; const int E = 202 * 202 * 6 * 2 * 2; vector<int> g[N]; int ne; struct Edge { int from, to; ll flow, cap; } edge[E]; int lvl[N], vis[N], pass, start = N - 2, targe... |
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; constexpr int MAXN = 100005; int SQRTN; int n, k; int t[MAXN], a[MAXN]; ll p[MAXN]; ll ans[MAXN]; ll cur = 0; int ind[MAXN], left_ind[MAXN], right_ind[MAXN]; int freq[3 * MAXN]; struct query { int l... |
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int maxn=2e5+7; const int modn = 1e9+7; int a[maxn],b[maxn]; map<int,int> mp,mp2; int binaryl(int value,int l,int r){ int res = l-1; while(r >= l){ int mid = (r+l) >> 1; if(b[mid] < value){ ... |
#include <bits/stdc++.h> using namespace std; string to_string(string s) { return + s + ; } string to_string(char s) { return string(1, s); } string to_string(const char* s) { return to_string((string)s); } string to_string(bool b) { return (b ? true : false ); } template <typename A> string to_... |
#include <bits/stdc++.h> using namespace ::std; const long double PI = acos(-1); const long long MOD = 1000000000 + 7; long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } int add(int a, int b, int m = MOD) { return (a + b + m + m) % m; } int mul(long long a, long long b, int m = M... |
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; int n, k, a, b, q, cnt[N]; struct fenwick { int fen[N]; void add(int p, int x) { for (; p < N; p += p & -p) fen[p] += x; } int get(int p) { int ans = 0; for (; p; p -= p & -p) ans += fen[p]; return ans; ... |
#include <bits/stdc++.h> #pragma GCC optimize( O3 ) #pragma GCC optimize( Ofast ) using namespace std; long long int n, k, a[200005], dp[200005]; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); ; cin >> n >> k; for (long long int i = 1; i <= n; i++) { ... |
#include <bits/stdc++.h> using namespace std; const int MAX_BUF_SIZE = 16384; char BUFOR[MAX_BUF_SIZE]; int BUF_SIZE, BUF_POS; char ZZZ; const int MXN = 1000010; const int C = 262144; const int INF = 1000000001; void test() { int n; scanf( %d , &n); cout << ((long long int)(n - 1) * (n - 3... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long n, x1, x2, m, c; cin >> n >> x1 >> x2; vector<pair<long long, long long>> v; for (int i = 0; i < n; ++i) { cin >> m >> c; v.push_back({m * x1 + c, m * x... |
#include <bits/stdc++.h> using namespace std; int main() { int n, a, b; cin >> n; map<int, vector<vector<int> > > m; vector<int> v, ans; map<int, int> s; for (int i = 0; i < n - 2; i++) { int f, g, h; cin >> f >> g >> h; v.push_back(f); v.push_back(g); v.push_ba... |
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 5; char s[maxn], t[maxn]; int p[maxn], q[maxn], r[maxn]; int main() { int n, m, k, d; scanf( %s%d , s, &m); n = strlen(s); while (m--) { scanf( %d%d , &k, &d); for (int i = 0; i < n; i++) p[i] = q[i] = i; in... |
#include <bits/stdc++.h> using namespace std; bool comp(int& a, int& b) { return b < a; } int main() { int n; cin >> n; vector<pair<int, int>> source(n), team1, team2; long long sum_team1 = 0, sum_team2 = 0; for (int i = 0; i < n; ++i) { cin >> source[i].first; source[i].second = i... |
#include <bits/stdc++.h> #pragma GCC optimize(2) using namespace std; const long long INF = 1e18; const int maxn = 1e6 + 6; const int mod = 1e9 + 7; const double eps = 1e-9; inline bool read(long long &num) { char in; bool IsN = false; in = getchar(); if (in == EOF) return false; while... |
#include<bits/stdc++.h> /* #include <ext/pb_ds/assoc_container.hpp> // Common file #include <ext/pb_ds/tree_policy.hpp> // Including */ using namespace std; //using namespace __gnu_pbds; //typedefs typedef long long ll; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<vi> vvi; typ... |
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const long long LINF = 0x3f3f3f3f3f3f3f3f; long long tot[200010]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >> n; vector<pair<long long, int> > v; for (int i = 0; i < n; i++) { long ... |
#include <bits/stdc++.h> using namespace std; long long fa[2005], fb[2005]; long long mina[2005], minb[2005]; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, m; cin >> n >> m; vector<long long> a(n), b(m); for (int i = 0; i < n; i++) { cin >> a[i];... |
#include <bits/stdc++.h> using namespace std; int main() { long long int n, mx = 0; cin >> n; map<int, long long int> mp1, mp2; map<pair<long long int, long long int>, int> mp; vector<long long int> a(n), b(n); for (int i = 0; i < n; i++) { int x, y; cin >> x >> y; a[i] = x... |
#include <bits/stdc++.h> int main() { int n; scanf( %d , &n); int n1 = n, dig, x = 0, y = 0, z = 0, r; while (n1 > 0) { dig = n1 % 10; if (dig != 4 && dig != 7) { x++; break; } n1 = n1 / 10; } if (x == 0) { printf( YES ); z++; } else if (... |
#include <bits/stdc++.h> using namespace std; char ans[2000005]; vector<int> lis[2000005]; string Str[2000005]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; int m = 0; for (int i = 0; i < n; i++) { string str; cin >> str; Str[i] = str... |
#include <bits/stdc++.h> using namespace std; const int N = 32; int n, u, r, a[N][N], b[N], p[N], k[N]; long long ans = -1e18; void dfs(int x, bool z) { int i; if (x % 2 == u % 2) { long long t = 0; for (i = 1; i <= n; i = i + 1) t += (long long)a[i][x] * k[i]; ans = max(ans, t); ... |
#include <bits/stdc++.h> using namespace std; map<char, long long> mp; long long arr[2][1234]; int main() { string s; long long idx1, idx2; char repeating; cin >> s; long long i; for (i = 0; i < s.size(); i++) mp[s[i]]++; for (auto it : mp) if (it.second == 2) repeating = it.fi... |
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; if (m - 1 >= n - m) m - 1 == 0 ? cout << m << endl : cout << m - 1 << endl; else cout << m + 1; return 0; } |
#include<bits/stdc++.h> using namespace std; typedef long long ll; int n,m,pre,N; string s,t; ll ans; map<string,vector<string> >S; map<string,bool>vis; int main(){ ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); cin>>n; for(int i=1;i<=n;i++){ cin>>s;t=s; sort(t.begin(),t.end()); ... |
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 7; long long a[maxn]; int main() { int _; cin >> _; while (_--) { int n, k; cin >> n >> k; for (int i = 1; i <= n; i++) cin >> a[i]; sort(a + 1, a + 1 + n, greater<int>()); long long ans = 0; for... |
#include <bits/stdc++.h> using namespace std; int n, arr[111111]; int main() { cin >> n; arr[0] = 0x3f3f3f3f; for (int i = 1; i <= n; ++i) cin >> arr[i]; int ans = 0; for (int i = 0; i < n; ++i) { int ii = n - i; if (arr[ii] < arr[ii - 1]) { ans = i; break; } ... |
#include <bits/stdc++.h> using namespace std; int main() { int n, counter = 0, max = 1, a, b = -1; cin >> n; for (int i = 0; i < n; i++) { a = b; cin >> b; if (b >= a) { counter++; } else { if (counter > max) { max = counter; } counter = ... |
#include <bits/stdc++.h> using namespace std; struct fenwick_tree_1D { long long n, log_n; vector<long long> tree; fenwick_tree_1D(long long _n) : n(_n), log_n((long long)(log2(_n) + 1.0L)), tree(_n + 5) {} void update(long long x, long long v) { while (x <= n) { tree[x] += v; ... |
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { int n; cin >> n; int k; cin >> k; vector<int> v(n); for (int i = 0; i < n; i++) cin >> v[i]; int lift; cin >> lift; vector<int> c(n); for (int i = 0; i < n; i++) cin >> c[i]; set<int> secon... |
#include <bits/stdc++.h> using namespace std; const int N = 100004; int n, m, c = 0; char s[24][24]; set<unsigned long long> st, ns; bool fun(int x, int y) { st.clear(); for (int i = 0; i < n; i += x) for (int j = 0; j < m; j += y) { ns.clear(); unsigned long long sum = 0; ... |
#include <bits/stdc++.h> using namespace std; const long long INF = 9223372036854775807; const long long MOD = 1000000007; const long long FMOD = 998244353; const long long MAXN = 1e5 + 5; const long double eps = 1e-9; const long double PI = acos(-1); void __print(int x) { cerr << x; } void __print(lo... |
#include <bits/stdc++.h> using namespace std; long long ex_gcd(long long a, long long b, long long &x, long long &y) { int d = a; if (b == 0) { x = 1; y = 0; } else { d = ex_gcd(b, a % b, y, x); y -= a / b * x; } return d; } int main() { long long a, b, c; lon... |
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize( O3 ) bool a[2000][2000], use[2000][2000][6][6]; vector<pair<int, int> > go; void dfs(int x, int y, int way, int cnt) { if (cnt == 3) return; use[x][y][way][cnt] = 1; for (int i = 1; i <= 4; i++) if (i == way) { if (a... |
#include <bits/stdc++.h> using namespace std; const int N = 5e5 + 50, inf = 1e9; int n, m, be[N], f[N], cnt, sub[N], SUB[N], vfa[N], q[N * 2], l, r; bool vis[N], tp[N]; vector<int> e[N], v[N], vv; void cmax(int &x, int y) { y > x ? x = y : 0; } void dfs1(int x) { vis[x] = 1; if (f[x]) e[x].erase(f... |
#include <bits/stdc++.h> using namespace std; void out(long long arr[], long long length) { for (int i = 0; i < length; i++) cout << arr[i] << ; } int main() { int tt; cin >> tt; while (tt--) { int x1, y1, z1, x2, y2, z2, ans; cin >> x1 >> y1 >> z1; cin >> x2 >> y2 >> z2; ... |
#include <bits/stdc++.h> using namespace std; long long getint() { long long _x = 0, _tmp = 1; char _tc = getchar(); while ((_tc < 0 || _tc > 9 ) && _tc != - ) _tc = getchar(); if (_tc == - ) _tc = getchar(), _tmp = -1; while (_tc >= 0 && _tc <= 9 ) _x *= 10, _x += (_tc - 0 ), _tc = get... |
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 10; const long long MOD = 1e9 + 7; vector<int> g[N]; bool col[N]; int her[N], p[N]; set<int> s; queue<int> q; bool mp[N]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); ; int n; cin >> ... |
#include <bits/stdc++.h> using namespace std; template <class T> bool maximize(T &x, const T &y) { if (x < y) x = y; else return false; return true; } const int N = 5e5 + 10; int n, q, md; int dx[N]; int d[N][21]; int query(int x, int y) { if (d[x][20] < y) return -1; i... |
#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)); } long long stoi(string& str) { istringstream second... |
#include <bits/stdc++.h> #pragma comment(linker, /stack:200000000 ) #pragma GCC optimize( unroll-loops ) #pragma GCC optimize( O3 ) using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long t; cin >> t; while (t--) { long long n, x; cin >> n ... |
#include <bits/stdc++.h> using namespace std; int v[1100][1100]; int main() { int n, k; cin >> n >> k; if (n > k + k) { cout << n * k << endl; for (int i = 1; i <= n; i++) { int t = k; for (int j = 1; j <= n; j++) if (i != j && !v[i][j] && !v[j][i] && t) { ... |
#include <bits/stdc++.h> using namespace std; long long int mod = 1e18; long long int mul(long long int a, long long int b) { return ((a % mod) * (b % mod)) % mod; } long long int add(long long int a, long long int b) { return ((a % mod) + (b % mod)) % mod; } long long int sub(long long int a, lon... |
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 7; int n, k, m; int a[N]; int main() { scanf( %d%d%d , &n, &m, &k); for (int i = 1; i <= n; i++) scanf( %d , &a[i]); sort(a + 1, a + 1 + n); long long ans = 0; ans += 1ll * (m / (k + 1)) * (1ll * k * a[n] + a[n - 1]); an... |
#include <bits/stdc++.h> using namespace std; int N, K; int val[10010], nval[10010], pos[10010], buf[10010]; int main() { scanf( %d%d , &N, &K); for (int i = 0; i < N - 1; ++i) val[i] = 1; int br = 0; for (;;) { for (int i = 0; i < N; ++i) pos[i] = -1, nval[i] = val[i]; for (int i = ... |
#include <bits/stdc++.h> using namespace std; using LL = long long; const double PI = 3.14159265358979323846; const int INF = 0x3f3f3f3f; const int MOD = 1e9 + 7; void solve() { int n; cin >> n; vector<int> bit(64); LL sum = 0, ans = 0; for (int i = 0; i < int(n); ++i) { LL num; ... |
#include <bits/stdc++.h> using namespace std; int const mxsz = 509; long long w[mxsz][mxsz]; bool ver[mxsz]; int main() { vector<int> er; vector<long long> res; int n; scanf( %d , &n); er.resize(n); for (int i = 0; i < n; ++i) { int x; for (int j = 0; j < n; ++j) { ... |
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; vector<vector<long long>> g; vector<long long> a; vector<long long> ans; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long n; cin >> n; g = vector<vector<long long>>(n + 1); a = vect... |
#include <bits/stdc++.h> char map[101][10001]; long long mic[101][10001]; int n, m; long long max = 1000000000; int check = 0; void find(int x) { int sum = 0; for (int i = 0; i < n; i++) { sum += mic[i][x]; if (sum > max) return; } max = sum; } int main() { scanf( %d %d ... |
#include <bits/stdc++.h> using namespace std; const int maxn = 1000003; int a[maxn]; int main() { ios_base::sync_with_stdio(false); int n; cin >> n; int ans = 0; int N = 1000000; while (n--) { int x; cin >> x; a[x]++; ans = max(ans, a[x]); for (int i = x * 2... |
#include <bits/stdc++.h> using namespace std; char gc() { static char buf[100000], *p1 = buf, *p2 = buf; return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2) ? EOF : *p1++; } inline int read() { int x = 0, f = 1; char ch = getchar(); whi... |
#include <bits/stdc++.h> using namespace std; const long long int N = 1e6 + 5; const long long int mod = 1e18 + 7; const double E = 2.71828; const double PI = 3.14159265; long long int arr[24][6] = { {0, 1, 2, 3, 4, 5}, {0, 2, 3, 4, 1, 5}, {0, 3, 4, 1, 2, 5}, {0, 4, 1, 2, 3, 5}, {1, 2, 0, 4, 5, ... |
#include <bits/stdc++.h> using namespace std; inline int read() { int x = 0; bool op = false; char c = getchar(); while (!isdigit(c)) op |= (c == - ), c = getchar(); while (isdigit(c)) x = (x << 1) + (x << 3) + (c ^ 48), c = getchar(); return op ? -x : x; } const int N = 2e5 + 10; int... |
#include <bits/stdc++.h> using namespace std; long long LLINF = (long long)1000000000 * 1000000010; const int MAXN = 410; int g[MAXN], g1[MAXN]; int c[MAXN]; int M, m; int solve(int x, int *a) { int ans = 0; for (int i = 0; i < m; i++) { a[i] = x / c[i]; x %= c[i]; ans += a[i]; ... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); int n, h, x, r = 0; cin >> n >> h; for (int i = 0; i < n; i++) { cin >> x; if (x > h) { r += 2; } else { r += 1; } } cout << r << endl; return 0; } |
#include <bits/stdc++.h> using namespace std; const int maxn = 1E3 + 5; int n; struct line { int x, y, w, num; line(int a = 0, int b = 0, int c = 0, int d = 0) : x(a), y(b), w(c), num(d) {} bool operator<(const line& A) const { return w > A.w; } } a[maxn], b[maxn]; vector<line> ans; inline boo... |
#include <bits/stdc++.h> using namespace std; const int MAXN = 3e5 + 100; const long long INF = 1e13; int u, v, c, b, laz[MAXN], C[MAXN], n, m, st[MAXN]; bool vis[MAXN]; multiset<pair<int, int> > Q[MAXN]; multiset<pair<int, int> >::iterator it; vector<pair<int, int> > W[MAXN]; vector<int> G[MAXN]; p... |
#include <bits/stdc++.h> using namespace std; struct node { int v, d; bool operator<(const node &a) const { if (d == a.d) return v < a.v; return a.d < d; } }; set<node> s; vector<int> adj[200005]; int d[200005], p[200005]; bool vis[200005]; void dfs(int u) { int l = adj[u].si... |
#include <bits/stdc++.h> using namespace std; vector<int> G[1000005]; int n, L[1000005], R[1000005], ind; void dfs(int u, int pre) { for (int i = G[u].size() - 1; i >= 0; i--) { int v = G[u][i]; if (v != pre) L[v] = ++ind; } R[u] = ++ind; for (auto v : G[u]) if (v != pre) dfs(v... |
#include <bits/stdc++.h> const int N = 18; const int INF = -1e9; int dp[N][1 << N][2][2]; int a[1 << N]; void solve() { int n, k; scanf( %d %d , &n, &k); for (int i = 0; i <= n; ++i) { int groups = (1 << n) / (1 << i); for (int j = 0; j < groups; ++j) { for (int u = 0; u < 2; +... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int t; cin >> t; while (t--) { long long A, B; cin >> A >> B; long long hb = (floor(log10(B + 1)) == log10(B + 1)) ? (floor(log10(B)) + 1) ... |
#include <bits/stdc++.h> using namespace std; struct rect { int x1, y1, x2, y2; }; struct rect a[40001], c[40001]; int b[40001]; int w, h, n, nr; void enter() { scanf( %d%d%d , &w, &h, &n); nr = 1; a[1].x1 = 0; a[1].y1 = 0; a[1].x2 = w; a[1].y2 = h; } void call1(int x1, int... |
#include <bits/stdc++.h> using namespace std; int a[1010][1010]; int p[1010][1010]; int w[1010]; int n, m; int ok(int d) { int cur, i, j, k; for (i = 0; i < m; i++) for (j = 0; j < m; j++) p[i][j] = 0; for (i = 0; i < n; i++) { cur = 0; for (j = 0; j < m; j++) if (a[i][... |
#include <bits/stdc++.h> using namespace std; using LL = long long; int main() { cin.tie(nullptr)->sync_with_stdio(false); int T; vector<int> f(3e5 + 5); f[0] = 0; for (int i = 1; i < 3e5 + 5; i++) f[i] = f[i - 1] ^ i; for (cin >> T; T; T--) { int a, b; cin >> a >> b; int... |
#include <bits/stdc++.h> using namespace std; set<string> S; string line[1010], a[1010], s; int n = 0, ans = 0, file = 0; int main() { while (getline(cin, s)) line[++n] = s; for (int i = 1; i <= n; i++) { int cur = 0; a[i] = ; for (int j = 0; j < line[i].size(); j++) { a[i]... |
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; stack<pair<int, int> > S; S.push(make_pair(0, -1)); vector<pair<int, int> > ans; for (int i = 0; i <= n; i++) { int a; if (i < n) cin >> a; else a = 0; while (S.top().first > a... |
#include <bits/stdc++.h> using namespace std; bool ok[10]; bool judge(char str[], int k) { int len = strlen(str); memset(ok, false, sizeof(ok)); for (int i = 0; i < len; i++) { ok[(str[i] - 0 )] = true; } for (int i = 0; i <= k; i++) { if (!ok[i]) { return false; } ... |
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); int n; cin >> n; long long sum = 0; for (int i = 0; i < n; ++i) { int t1; cin >> t1; sum += t1; } if (sum % n) cout << n - 1 << endl; else cout << n << endl; retu... |
#include <bits/stdc++.h> using namespace std; void solve() { long long n; cin >> n; vector<long long> a(n); for (long long& i : a) cin >> i; vector<long long> pre(n), suf(n); long long cnt{1}; pre[0] = 1; for (long long i = 1; i < n; i++) { if (a[i] > a[i - 1]) { cnt++;... |
#include <bits/stdc++.h> using namespace std; const int N = 111111; int size[3]; int colour[N]; bool ok = false; bool used[N]; long long ans = 0; vector<int> edge[N]; void dfs(int u) { used[u] = true; ans += size[colour[u]]; size[colour[u]]++; for (int i = 0; i < edge[u].size(); i++) {... |
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; ++i) { cin >> a[i]; } vector<int> d(5000, 0); for (int i = 0; i < n; ++i) { for (int j = i + 1; j < n; ++j) { ++d[abs(a[i] - a[j])]; } } ... |
#include <bits/stdc++.h> using namespace std; const int M = 1e5 + 5; const int mod = 1e9 + 7; const double esp = 1e-10; const long double pi = 4 * atan((long double)1); int n; long long d; struct mido { long long l, r, val; } a[M]; vector<pair<long long, int> > v; pair<int, int> f[12 * M]; i... |
#include <bits/stdc++.h> using namespace std; const int MAXN = 200000; bool active[MAXN + 10]; int v[MAXN + 10]; vector<int> factors[MAXN + 10]; int cantidad[5000001]; int main() { int n, q; scanf( %d %d , &n, &q); for (int i = 0; i < n; i++) { scanf( %d , &v[i]); int aux = v[i]; ... |
#include <bits/stdc++.h> using namespace std; int main(int argc, char **argv) { int n, k, value = 0; vector<pair<int, int>> set; cin >> n >> k; for (int i = 0; i < n; ++i) { int x, y; cin >> x >> y; set.push_back({x, y}); } for (int i = 0; i < n; ++i) { value += set[i... |
#include <bits/stdc++.h> using namespace std; char s[1000100]; int n; int d[1000100]; int dp(int x) { if (d[x] != -1) return d[x]; int ret = 0; int ind = x + 1; while (s[ind] == M ) { ret += 1; ind++; } int w = 0; while (s[ind] == F && ind < n) ind++, w++; if (in... |
#include <bits/stdc++.h> using namespace std; long long ctos, modd = 1000000007, dos = 2; long long P[4005], B[4005][4005], res; long long bi(int n, int k) { if (n == k) return 1; if (k == 0) return 1; if (k > n) return 0; if (k == 1) return n; if (B[n][k] > 0) return B[n][k]; B[n][k] = ... |
#include <bits/stdc++.h> const int MaxN = 1000; using namespace std; char s[MaxN + 5]; int n; int vis[200 + 5]; int main() { while (~scanf( %d , &n)) { scanf( %s , s + 1); int Max = 0; for (int i = 1; i <= n; i++) { for (int j = i; j <= n; j++) { memset(vis, 0, sizeof... |
#include <bits/stdc++.h> using namespace std; const long long nmax = (long long)1e6 + 10; inline long long up(char ch) { return z - ch; } inline long long lo(char ch) { return ch - a ; } inline long long eq(char ch) { return 1; } long long dp[2002][2002]; long long tmp[2002]; signed main() { ios_... |
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; const int maxn = 2000000; int l, lsub; char str[maxn + 1]; long long dpw[maxn + 1], dpb[maxn + 1], now, nob, ans0, ansb, ans, ranansb, ranans0; int main() { scanf( %d%d , &l, &lsub); scanf( %s , str); now = -... |
#include <bits/stdc++.h> using namespace std; int main() { int n, max = 0; cin >> n; int arr[n]; long long ans = 0; for (int i = 0; i < n; i++) { cin >> arr[i]; if (arr[i] > max) { max = arr[i]; } } for (int i = 0; i < n; i++) { ans += max - arr[i]; } ... |
#include <bits/stdc++.h> using namespace std; template <class T> inline void read(T &x) { x = 0; char c = getchar(); int f = 1; while (!isdigit(c)) { if (c == - ) f = -1; c = getchar(); } while (isdigit(c)) { x = x * 10 + c - 0 ; c = getchar(); } x *= f; ... |
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; char r[100]; if (s.length() < 6) { cout << no << endl; return 0; } int val = 0; for (int i = s.length() - 1; i >= 0; i--) { if (val == 6) { if (s[i] == 1 ) { cout << yes... |
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; int ans = 0, a; if (k & 1) { for (int i = 0; i < n; i++) { cin >> a; if (a <= 3) ans ^= (a & 1); else if (a & 1) ans ^= 0; else { int cnt = 0; ... |
#include <bits/stdc++.h> using namespace std; long long mod = 1e9 + 7; struct frac { long long first, second; frac(long long X = 0) : first((X % mod + mod) % mod), second(1) {} frac(long long X, long long Y) : first((X % mod + mod) % mod), second((Y % mod + mod) % mod) {} frac operator+(fr... |
#include <bits/stdc++.h> using namespace std; long long int t, n, k, m; long long int A[100001]; long long int M = 1e9 + 7; bool isSubsetSum(int set[], int n, int sum) { if (sum == 0) return true; if (n == 0) return false; if (set[n - 1] > sum) return isSubsetSum(set, n - 1, sum); return isSub... |
#include <bits/stdc++.h> using namespace std; bool cmp(int a, int b) { return a > b; } int main() { string s; cin >> s; vector<int> a, b; vector<int> dec1, dec2; int sum1 = s[0] - 0 + (s[1] - 0 ) + (s[2] - 0 ); int sum2 = (s[3] - 0 ) + (s[4] - 0 ) + (s[5] - 0 ); if (sum1 == sum2... |
#include <bits/stdc++.h> using namespace std; struct node { long long x, p, id; bool operator<(const node &a) const { return x < a.x; } } a[200010]; long long n, v, d, ans, Next[200010]; stack<node> s; signed main() { scanf( %lld%lld%lld , &d, &v, &n); for (long long i = 1; i <= n; i++) scan... |
#include <bits/stdc++.h> using namespace std; long long Pow10(int n) { if (n <= 0) return 1; return 10 * Pow10(n - 1); } void solve() { long long k; cin >> k; int lev = 0; while (k >= 9 * (lev + 1) * Pow10(lev)) { k -= 9 * (lev + 1) * Pow10(lev); lev++; } long long nu... |
#include <bits/stdc++.h> using namespace std; const int maxn = 2000 + 10; char s[maxn][maxn]; int deg[maxn][maxn]; int dx[] = {1, 0, -1, 0}; int dy[] = {0, 1, 0, -1}; char fillchar[2][5] = { ^<v> , v>^< }; inline int caldeg(int i, int j) { return (int)(s[i - 1][j] == . ) + (int)(s[i + 1][j] == . ... |
#include <bits/stdc++.h> using namespace std; struct prik { int hair, mood, ind; }; bool comp1(prik a, prik b) { if (a.hair != b.hair) return a.hair > b.hair; else return a.mood > b.mood; } bool comp2(prik a, prik b) { if (a.mood != b.mood) return a.mood < b.mood; else ... |
#include <bits/stdc++.h> using namespace std; int gcd(long long a, long long b, long long& x, long long& y) { if (b == 0) { x = 1; y = 0; return a; } long long x1, y1; long long d = gcd(b, a % b, x1, y1); x = y1; y = x1 - y1 * (a / b); return d; } int main() { l... |
#include <bits/stdc++.h> using namespace std; const int OO = 0x3f3f3f3f, N = 1e5 + 5, mod = 1e9 + 9; int n, k, indx[10], ans = OO; char arr[10][10]; int num(int r) { int ret = 0; for (int i = 0; i < k; ++i) { ret = ret * 10 + (arr[r][indx[i]] - 0 ); } return ret; } int main() { ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.