func_code_string stringlengths 59 71.4k |
|---|
#include <bits/stdc++.h> using namespace std; class Graph { long long n; vector<long long> f, par, ans, sz, depth, value, size, fst, to, next; long long l; void swapUtil(long long &, long long &); long long getP(long long); long long dfsUtil(long long); void setDFS(); void setsz(); ... |
#include <bits/stdc++.h> long long n; long long check(long long x) { for (long long i = 2; i * i <= x; i++) if (x % i == 0) return 1; return 0; } long long exgcd(long long a, long long b, long long &x, long long &y) { long long g = a; if (b == 0) x = 1, y = 0; else g = exgc... |
#include <bits/stdc++.h> #pragma comment(linker, /STACK:1000000000 ) #pragma GCC optimize( Ofast,no-stack-protector ) using namespace std; const int maxn = (int)1e5 + 10; vector<int> ed[maxn]; int sz[maxn]; void dfs(int v, int p) { sz[v] = 1; for (int u : ed[v]) { if (u != p) { dfs(... |
#include <bits/stdc++.h> using namespace std; const long long MOD = 1000 * 1000 * 1000 + 7; const long long INF = 2 * 1000 * 1000 + 200; const long long MAXN = 100 * 1000 + 1; const long long MLOG = 18; const long long NMAX = 1 * 1000; signed main() { long long n, m, a[200]; a[0] = 0; long lon... |
#include <bits/stdc++.h> using namespace std; ofstream out( biconex.out ); ifstream in( biconex.in ); struct Edge { int node; bool is_critic; }; const int N_MAX = 100000; vector<Edge> neighbours[1 + N_MAX]; stack<int> component; int n, m, h, minim = N_MAX + 1, node_ans, Depth, root_sons, depth... |
#include <bits/stdc++.h> using namespace std; const long long N = 2e5 + 9; long long wei[N], p[N], in[N], ans[N], par[N][22], mx[N][22], h[N]; pair<long long, long long> edge[N]; vector<pair<long long, long long> > vec, adj[N]; priority_queue<pair<long long, long long>, vector<pair<long long, long long> >, ... |
#include <bits/stdc++.h> using namespace std; double EPS = 1e-9; int INF = 1 << 30; long long INFL = 1LL << 60; int main() { int n; cin >> n; string w; cin >> w; int ile = 0; for (int i = 1; i < n; i += 2) { if (w[i] == a && w[i - 1] == a ) { w[i] = b ; ile++;... |
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; string s; cin >> s; vector<int> stars, pacmans; for (int i = 0; i < n; i++) { if (s[i] == * ) stars.push_back(i); else if (s[i] == P ) pacman... |
#include <bits/stdc++.h> using namespace std; bool used[10000001]; int n, m, second = 0, ds[1000001], ans[1000001], str[1000001], sv[1000001]; struct o { int x, i, j; }; o d[1000001]; vector<vector<int> > a; bool comp(o a, o b) { if (a.x == b.x) return a.i < b.i; return a.x < b.x; } bool... |
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; if (((n * (n - 1)) / 2) <= k) cout << no solution ; else { while (n--) cout << 0 << n << endl; } return 0; } |
#include <bits/stdc++.h> using namespace std; long long ans, C1[4000 + 1], C2[4000 + 1]; void Init(long long *C, int m) { C[0] = C[1] = 1; for (int i = 2; i < m; i++) { C[i] = 1; for (int j = i - 1; j > 0; j--) C[j] = (C[j - 1] + C[j]) % 1000000009; } } int main() { int n, w, b; ... |
#include <bits/stdc++.h> #pragma GCC optimize( O3 ) using namespace std; int n, m, t, k; int d[((int)1e5 + 5)]; int countt[105]; int l = 1; int r = 100; void lbulma() { while (countt[l] == 0) l++; return; } void rbulma() { while (countt[r] == 0) r--; return; } int asal[4] = {2, 3... |
#include <bits/stdc++.h> using namespace std; long double PI = acosl(-1); bool compare_int(int a, int b) { return (a > b); } bool compare_string(string a, string b) { return a.size() < b.size(); } bool compare_pair(const pair<int, int> &a, const pair<int, int> &b) { if (a.second == b.second) return ... |
#include <bits/stdc++.h> using namespace std; long long num(string str) { long long out = 0; for (int i = 0; i < str.length(); i++) { out *= 26; out += str.at(i) - A + 1; } return out; } string pb26(long long n) { string reverse = ; while (n > 0) { int d = (n - 1) %... |
#include <bits/stdc++.h> using namespace std; bool comp(pair<double, int> &a, pair<double, int> &b) { if (a.first != b.first) return a.first > b.first; return a.second < b.second; } void solve() { int n; double t1, t2, k; cin >> n >> t1 >> t2 >> k; vector<pair<double, int>> p(n); for... |
#include <bits/stdc++.h> using namespace std; long long n, x; map<long long, long long> mp; map<long long, long long> nums; long long grund(long long x) { if (x <= 1) return 0; if (mp[x]) return mp[x]; for (long long i = 31; i >= 0; i--) { if ((x & (1 << i))) { set<long long> second;... |
#include <bits/stdc++.h> using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); void c_p_c() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } long long int gcd(long long int a, long long int b) { if (b == 0) return a; return gcd(b, a % b); } ... |
#include <bits/stdc++.h> using namespace std; const unsigned long long l = 1000000007; const int MAX_ = 2000; int T; void solve(int t) { long long n; cin >> n; vector<int> p[n]; for (int i = 0; i < n; i++) { int k; cin >> k; p[i] = vector<int>(k); for (int j = 0; j < k;... |
#include <bits/stdc++.h> using namespace std; const int M = 1e9 + 7; vector<string> vec; long long int sd(long long int n) { long long int sum = 0; while (n != 0) { sum += n % 10; n = n / 10; } return sum; } long long int nd(long long int n) { long long int ans = 0; while... |
#include <bits/stdc++.h> using namespace std; const int N = 100000 + 7; const int M = 100000 + 7; const int inf = 1000000000 + 7; const long long linf = 1ll * inf * (inf - 1); const double pi = acos(-1); const double eps = 1e-9; const bool multipleTest = 0; const int mod[2] = {(rand() % (inf - 1000) +... |
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; int a[3]; while (t--) { memset(a, 0, sizeof(a)); int n; cin >> n; for (int i = 0; i < n; i++) { int in; cin >> in; a[in % 3]++; } if (a[2] >= a[1]) { cout <... |
#include <bits/stdc++.h> using namespace std; const int N = 1234567; int n, a, b, T, used, ans; int lft[N], rgt[N]; char s[N]; void fill_array(int v[]) { for (int i = 1; i < n; i++) { v[i] = v[i - 1] + a + 1 + ((s[i] == w ) ? b : 0); } } void solve(int lft[], int rgt[]) { for (int i =... |
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 1; long double pi = 3.141592653589793238; int main() { long long t; cin >> t; while (t--) { long long x; cin >> x; long double ans; long double n = 2.0000000000000 * (long double)x; long double angle = ... |
#include <bits/stdc++.h> using namespace std; const int MX = 5000 + 9; int t[MX]; int n; int counts[MX] = {0}; int ans[MX]; int main() { cin >> n; for (int i = 0; i < n; i++) { cin >> t[i]; t[i]--; } for (int start = 0; start < n; start++) { memset(counts, 0, n * sizeof(i... |
#include <bits/stdc++.h> using namespace std; int main() { vector<int> v; long long int n, s, x, countt = 0; cin >> n >> s; for (int i = 0; i < n; i++) { cin >> x; v.push_back(x); } sort(v.begin(), v.end()); int mid = n / 2; int m = v[mid]; if (m <= s) { for (in... |
#include <bits/stdc++.h> using namespace std; const int N = 300010, LOG = 64; int n, arr[N], nxt[N][LOG], mx, sum[N]; long long p, ans = 0; vector<int> seg[2][4 * N]; bool b; void build(int s, int e, int idx) { if (s == e) { if (sum[s] % 2 == b) seg[b][idx].push_back(sum[s]); return; }... |
#include <bits/stdc++.h> bool f(int x, int n, int *pre, int p) { for (int j = 0; j < n; ++j) { if ((pre[j + x] - j) % p == 0) return false; } return true; } using namespace std; int main(int argc, char **argv) { vector<int> ans; int t, n, p, a[2000], pre[5001] = {0}; cin >> n >> p;... |
#include <bits/stdc++.h> using namespace std; vector<long long> avengers; long long n, k, A, B; long long rec(long long l, long long r) { long long i = lower_bound(avengers.begin(), avengers.end(), l) - avengers.begin(); long long j = upper_bound(avengers.begin(), avengers.end(), r) - av... |
#include <bits/stdc++.h> using namespace std; int main() { unsigned long long x, y, z, res1 = 0, res2 = 0; cin >> x >> y >> z; unsigned long long a = x % z; unsigned long long b = y % z; res1 = (x + y) / z; if (a == 0 || b == 0) res2 = 0; else { if (a > b) { if ((z - ... |
#include <bits/stdc++.h> using namespace std; int n, ai, bi; vector<vector<int> > adj(200009); vector<int> vis(200009, 0); vector<pair<int, int> > se; void dfs(int v, int vl) { if (vis[v]) return; vis[v] = vl; vl = (vl == 1) ? 2 : 1; int len = adj[v].size(); for (int i = 0; i < len; i++)... |
#include <bits/stdc++.h> using namespace std; int n, m; string s[20][20]; string ran = 23456789TJQKA ; string sui = CDHS ; set<string> st; int j1x = -1, j1y = -1, j2x = -1, j2y = -1; inline bool ok(int x, int y) { set<char> ra, su; for (int i = x; i < x + 3; i++) { for (int j = y; j < y ... |
#include <bits/stdc++.h> using namespace std; bool col[100010]; int a, b, n, k; int main() { cin >> n >> k >> a >> b; int inv(1); if (a < b) { swap(a, b); inv = 0; } for (int i(1); i <= k + 1; i++) { for (int j(i); j <= n; j += k + 1) { if (a) { col[j] = 1... |
#include <bits/stdc++.h> using namespace std; int cas, b, k; int main() { cas = 1; while (cas--) { scanf( %d%d , &b, &k); int ans = 0; b = b % 2; for (int i = 1; i <= k; i++) { int x; scanf( %d , &x); if (i == k) b = 1; ans = ans + b * x; ans... |
#include <bits/stdc++.h> using namespace std; signed main() { ios_base::sync_with_stdio(false); cin.tie(0); string s; cin >> s; int64_t N = s.size(); vector<int64_t> v(N, 0); int64_t l = 0, r = N - 1; for (int64_t i = 0; i < N; ++i) { if (s[i] == l ) { v[r] = i + 1; ... |
#include <bits/stdc++.h> using namespace std; int dp[60002][10]; int main() { int n, m; scanf( %d%d , &n, &m); int a; for (int j = 0; j < m; j++) { cin >> a; if (!j) dp[0][j] = a; else dp[0][j] = dp[0][j - 1] + a; } cout << dp[0][m - 1] << ; for (in... |
#include <bits/stdc++.h> using namespace std; bitset<22500> a, b, c, e; int n, m, k; char s[100010]; int main() { scanf( %d%d%d , &n, &m, &k); for (int i = 0; i < n; i++) { scanf( %s , s); for (int j = 0; j < m; j++) { if (s[j] != # ) a[i * m + j] = 1; if (s[j] == E ) e[i... |
#include <bits/stdc++.h> using namespace std; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long n; cin >> n; long long maxi = INT_MIN; while (n--) { long long x, y; cin >> x >> y; long long sum = x + y; if (sum > maxi) { ... |
#include <bits/stdc++.h> using namespace std; double inf = 1e+10; double eps = 1e-10; inline int sgn(const double& x) { return (x > +eps) - (x < -eps); } const int MAXN = 500; const int MAXM = 501; int n, m; double A[MAXM + 1][MAXN + 1]; int basis[MAXM + 1], out[MAXN + 1]; void pivot(int a, int b) {... |
#include <bits/stdc++.h> using namespace std; const int maxn = 3e5 + 5; const char choice[6][2] = {{ A , C }, { A , G }, { A , T }, { C , G }, { C , T }, { G , T }}; int n, m; string str[maxn]; int ord[2][maxn][6], cnt[2][maxn]; string out[maxn]; void print(int rc, int... |
#include <bits/stdc++.h> using namespace std; int n; vector<vector<int>> adj; vector<long long> d; vector<bool> visited; bitset<5000> sol; void dfs(int m) { bitset<5000> tmp; d[m] = 1; tmp[0] = 1; for (auto l : adj[m]) { if (!visited[l]) { visited[l] = 1; dfs(l); ... |
#include <bits/stdc++.h> using namespace std; const int mx = 1e6 + 50; bool tot[10000050]; vector<int> prime; void seive() { for (int i = 2; i * i <= mx; i++) { if (!tot[i]) { for (int j = (2 * i); j <= mx; j += i) { tot[j] = true; } } } for (int i = 2; i <= m... |
#include <bits/stdc++.h> using namespace std; const int dr[] = {1, 0, -1, 0, 1, 1, -1, -1}; const int dc[] = {0, 1, 0, -1, 1, -1, -1, 1}; const double eps = 1e-9; const int INF = 0x7FFFFFFF; const long long INFLL = 0x7FFFFFFFFFFFFFFFLL; const double pi = acos(-1); template <class T> T take(queue<T> &O... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int t; cin >> t; while (t--) { int n; cin >> n; cin.sync(); string s; cin >> s; stack<char> ss; for (int i = 0; i < s.size(); i++) { if (s[i]... |
#include <bits/stdc++.h> using namespace std; int dx[8] = {1, -1, 0, 0, 1, -1, 1, -1}; int dy[8] = {0, 0, -1, 1, 1, -1, -1, 1}; int n, k, f; vector<int> v; int main(void) { scanf( %d%d , &n, &k); for (int i = 0; i < n; i++) { scanf( %d , &f); v.push_back(f); } long long ans = 0; ... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int n, n1, n2, c, b; cin >> n >> n1 >> n2; c = n1; b = n2; long double sum = 0, sum1 = 0; long long int a[n]; for (int i = 0; i < n; i++) cin >> a[i]; sort(a,... |
#include <bits/stdc++.h> using namespace std; const int MAXN = 1000001; int n, t; int p[MAXN], s[MAXN]; stack<int> st; int main() { scanf( %d n , &n); for (int i = 1; i <= n; ++i) scanf( %d , &p[i]); scanf( %d , &t); for (int i = 1; i <= t; ++i) { int x; scanf( %d , &x); p[... |
#include <bits/stdc++.h> using namespace std; const int MAXN = 1000000 + 10; long long a[MAXN]; long long b[MAXN]; void add(long long k, long long val, int start, int end) { if (start > end) return; a[start] += k; a[end + 1] -= k; long long bias = val - start * k; b[start] += bias; b[e... |
#include <bits/stdc++.h> using namespace std; double r, L; double b, u, A; double x, y, a; double D[95], B[95]; struct st { double x, y, a; }; st bear[50]; int t; double fun(int i, double l) { x = bear[i].x; y = bear[i].y; t = bear[i].a; a = B[t]; b = (fabs(l - x) / y); A... |
#include <bits/stdc++.h> using namespace std; const double PI{3.1415926535897932384626433832795}; const int MOD{static_cast<int>(1e9 + 7)}; const double EPS{1e-9}; template <typename T> T ModAdd(const T &a, const T &b, const int &mod = MOD) { return ((a) % mod + (a) % mod) % mod; } template <typenam... |
#include <bits/stdc++.h> using namespace std; const long long N = 5100; long long n, s, t, x[N], a[N], b[N], c[N], d[N], w[N]; long long dp[N][N]; inline void print(long long a[]) { for (long long i = 1; i <= n; i++) printf( %lld , a[i]); printf( n ); } inline long long read() { long long f ... |
#include <bits/stdc++.h> using namespace std; int main() { int n, k[101], m, mi = 1000000; cin >> n; for (int i = 0; i < n; i++) cin >> k[i]; for (int i = 0; i < n; i++) { int c = 0, s = 0; for (int j = 0; j < k[i]; j++) { cin >> m; s += m * 5; c++; } ... |
#include <bits/stdc++.h> using namespace std; const long long p = 131; const int N = 210000; int n, m; char sr1[N], sr2[N]; unsigned long long hash1[N][28], hash2[N][28], Q[N]; int Ans[N], ans; int main() { int i, j, k, x, y; cin >> n >> m; scanf( %s%s , sr1 + 1, sr2 + 1); Q[0] = 1; ... |
#include <bits/stdc++.h> using namespace std; int n, f; long long ans; long long k, l; long long d[100001]; int main() { cin >> n >> f; for (int i = 1; i <= n; i++) { cin >> k >> l; d[i] = -min(k, l - k); ans = ans + min(k, l); } sort(d + 1, d + n + 1); for (int i = 1; ... |
#include <bits/stdc++.h> using namespace std; map<char, int> M; char t[7] = { B , u , l , b , a , s , r }; int num[7] = {1, 2, 1, 1, 2, 1, 1}; char ch[200020]; int main() { scanf( %s , ch); int n = strlen(ch); for (int i = 0; i < n; i++) M[ch[i]]++; int ans = 1 << 30; for (int i = ... |
#include <bits/stdc++.h> using namespace std; template <class X, class Y> void amax(X& x, const Y& y) { if (x < y) x = y; } template <class X, class Y> void amin(X& x, const Y& y) { if (x > y) x = y; } const int INF = 1e9 + 10; const long long INFL = 1e18 + 10; const int MAX = 1e6 + 10; in... |
#include <iostream> #include <vector> using namespace std; int t,k,n,m; vector<int> a,b,v; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cin>>t; while (t--) { cin>>k>>n>>m; a.resize(n); b.resize(m); for (int &x:a) cin>>x; ... |
#include <bits/stdc++.h> int main() { int n, i, a[100001]; scanf( %d , &n); for (i = 1; i <= n; i++) scanf( %d , &a[i]); for (i = 1; i <= n; i++) while (a[i] % 2 == 0) a[i] /= 2; for (i = 1; i <= n; i++) while (a[i] % 3 == 0) a[i] /= 3; for (i = 1; i <= n - 1; i++) if (a[i] !... |
#include <bits/stdc++.h> using namespace std; struct data { int u, v, w; } p[400500]; int father[200100]; int use[200100]; int coo(struct data a, struct data b) { if (a.w > b.w) return 1; return 0; } int find(int x) { return x == father[x] ? x : father[x] = find(father[x]); } int main() { ... |
#include <bits/stdc++.h> using namespace std; int N, K; int A[202020]; string S; void solve() { int i, j, k, l, r, x, y; string s; cin >> N >> K; for (i = 0; i < (N); i++) cin >> A[i]; cin >> S; signed long long ret = 0; for (i = 0; i < N;) { j = i; vector<int> V; ... |
#include <bits/stdc++.h> using namespace std; int n, m; int a[500005], b[500005], reach[500005][19]; int tree[4 * 500005][19]; void build(int i, int layer, int low, int high) { if (low == high) { tree[i][layer] = reach[low][layer]; return; } int mid = (low + high) / 2; build(2 * i,... |
#include <bits/stdc++.h> using namespace std; int mul(long long int a) { int mi = 10, ma = 0; while (a != 0) { int d = a % 10; mi = min(mi, d); ma = max(ma, d); a /= 10; } return mi * ma; } int main() { int t = 0; cin >> t; while (t--) { long long int n,... |
#include <bits/stdc++.h> #pragma comment(linker, /STACK:640000000 ) using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int a, b; cin >> a >> b; for (int _n((a)-1), i(0); i <= _n; ++i) cout << i + 1 << ; for (int i = (a + b + 1), _b = (a + 1); i >= _b; --i) ... |
#include <bits/stdc++.h> using namespace std; vector<int> prime_Numbers; bool primes[1000005]; void prime(int n) { for (int i = 2; i <= n; i++) primes[i] = true; for (int i = 2; i <= n; i++) { if (primes[i] == true) { prime_Numbers.push_back(i); for (int j = i + i; j <= n; j += i) ... |
#include <bits/stdc++.h> long long int add(long long int a, long long int b) { return a + b - (a + b >= 1000000007) * 1000000007; } long long int sub(long long int a, long long int b) { return a - b + (a - b < 0) * 1000000007; } long long int mult(long long int a, long long int b) { return (1LL * ... |
#include <bits/stdc++.h> using namespace std; int dp[1 << 20]; int arr[][5] = {{1, 2, -1}, {2, -1}, {-1}, {4, 5, 6, -1}, {5, 6, -1}, {6, -1}, {-1}, {8, 9, 10, 11, -1}, {9, 10, 11, -1}, {10, 11, -1}, {11, -1}, {-1}, {13, 14, 15, -... |
#include <bits/stdc++.h> using namespace std; const long long INF = 1e9 + 5; const long long N = 205; void solve(); int32_t main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; cout << fixed << setprecision(10); long long _ = 1; while (_--) solve(); return 0; } void... |
#include <bits/stdc++.h> using namespace std; int n; long long a[100005]; int main() { { cin >> n; for (int i = 0; i < n; i++) scanf( %lld , &a[i]); sort(a, a + n); long long ans = LLONG_MAX; for (int c = 1;; c++) { long long now = 1; long long tot = 0; ... |
#include <bits/stdc++.h> using namespace std; template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { os << { ; string sep; for (const auto &x : v) os << sep << x, sep = , ; return os << } ; } template <typename T, size_t size> ostream &operator<<(ostream &os, const ... |
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize( O3,Ofast,no-stack-protector,unroll-loops,fast-math ) const int maxn = 2e3 + 7; int32_t main() { int n, d, e; cin >> n >> d >> e; int ans = 1e9 + 7; for (int i = 1; i * 5 * e <= n; i++) { int t = i * 5 * e; t = n - t;... |
#include <bits/stdc++.h> using namespace std; constexpr int power(int x, int e) { return e ? x * power(x, e - 1) : 1; } template <typename T> void transpose(std::vector<std::vector<T>>& M) { auto tmp = M; M.resize(tmp[0].size()); for (auto& row : M) row.resize(tmp.size()); for (int i = 0; i < (i... |
#include <bits/stdc++.h> using namespace std; using big = long long; const int N = 200200; int a[N]; int f[N][2][2][2][2]; int dfs(int n, int x, int y, int v1, int v2) { if (!n) { assert(!x && !y); return v1 > v2; } if (x && !dfs(n - 1, x - 1, y, v2, !v1)) { return true; } ... |
#include <bits/stdc++.h> using namespace std; const long long MAX = 123456789; const long long inf = 123456789000000000; const double EPS = 1e-10; const double PI = 2 * asin(1.0); const long long mod = 1e9 + 7; inline int cmp(double x, double y = 0, double tol = EPS) { return (x <= y + tol) ? (x + tol... |
#include <bits/stdc++.h> using namespace std; long long n, a[100100], tmp, Ans, Odd, Even; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; if (a[i] & 1) Odd++; else Even++; } tmp = min... |
#include <bits/stdc++.h> using namespace std; int main() { long long int a, x, y; cin >> a; while (a--) { cin >> x >> y; x = x - 1; while (x--) { y = y + 9; } cout << y << endl; } return 0; } |
#include <bits/stdc++.h> using namespace std; const int N = 200200; int n, Q, cc = 1, tp, h[N], s[N]; struct E { int v, nxt; } e[N << 1]; inline void add(int u, int v) { e[cc] = (E){v, h[u]}; h[u] = cc++; } struct st { int n, c[N << 1]; inline void upd(int x, int v) { for (; x ... |
#include <bits/stdc++.h> using namespace std; const long long N = 1e5 + 10, mod = 1e9 + 7, inf = 1e18; int main() { ios::sync_with_stdio(false); cin.tie(0); long long n, k, x, s = 0, flag = 0, ans = 0; cin >> n >> k; for (int i = 1; i <= n; i++) { cin >> x; s += x; if (s / k)... |
#include <bits/stdc++.h> using namespace std; long long int arr[3000000], a[3000000]; vector<long long int> v; int main() { long long int n, ans = 0; cin >> n; for (long long int i = 0; i < n; i++) cin >> arr[i]; a[0] = 1; for (long long int i = 0; i < n; i++) { v.clear(); for (l... |
#include <bits/stdc++.h> using namespace std; const long long int mxn = 2 * 1e5 + 5; long long int vis[mxn]; vector<vector<long long int>> ad(mxn); long long int leaf, ans = 0; void dfs(long long int n, long long int d) { vis[n] = 1; for (auto child : ad[n]) if (!vis[child]) dfs(child, d + 1);... |
#include <bits/stdc++.h> using namespace std; int main() { int n, A[100005]; cin >> n; for (int i = 0; i < n; i++) cin >> A[i]; int mx = 0; long long sum = 0; for (int i = 0; i < n; i++) { sum += A[i]; if (A[i] > mx) mx = A[i]; } sum -= mx; if (sum <= mx) { cout... |
#include <bits/stdc++.h> ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ;... |
#include <bits/stdc++.h> using namespace std; long long int n, k, s; vector<long long int> v, ans; void build(const int &last, const int &i, const int &k, const bool &increasing) { if (!k) return; else if (last != v[i] and int(v.size()) - i == k) ans.push_back(v[i]), build(v[i],... |
#include <bits/stdc++.h> using namespace std; const int INF = 1e9; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int n, m; cin >> n >> m; vector<vector<char>> arr(n + 2, vector<char>(m + 2)); for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { cin... |
#include <bits/stdc++.h> using namespace std; struct yts { int v[300010], ne[2 * 300010], x[2 * 300010], y[2 * 300010]; bool val[2 * 300010]; int num; void put(int s, int t) { num++; x[num] = s; y[num] = t; ne[num] = v[s]; v[s] = num; } } e1, e2; int q[300010]; ... |
#include <bits/stdc++.h> using namespace std; long long int INF = 1e17; const long long fact_table = 800008; double Pi = 3.1415926535897932384626; priority_queue<long long> pql; priority_queue<pair<long long, long long> > pqp; priority_queue<long long, vector<long long>, greater<long long> > pqls; long ... |
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int ans = 1000001; for (int i = 0; i < n; i++) cout << ans + i << ; return 0; } |
#include <bits/stdc++.h> using namespace std; const long long oo = 0x3f3f3f3f3f3f3f3fll; const int LGN = 25; const int MOD = 1e9 + 7; const int N = 3e5 + 5; int n, a[N], m, l[N], r[N]; int mem[N * LGN], cnt; int* alloc(int x) { int* p = mem + cnt; cnt += x; return p; } struct { int* ... |
#include <bits/stdc++.h> using namespace std; const int MAXN = 10004; int v[MAXN]; int solve(int x, int y) { if (x == y) return 0; int mid = (x + y) >> 1; int left = 0, right = 0; for (int i = x; i < mid + 1; ++i) left = max(left, v[i]); for (int i = mid + 1; i < y + 1; ++i) right = max(righ... |
#include <bits/stdc++.h> using namespace std; int main() { int n, j = 1, a, b, c, d, maxi = -1; cin >> n; cin >> a >> b >> c >> d; maxi = a + b + c + d; for (int i = 2; i <= n; i++) { cin >> a >> b >> c >> d; if (a + b + c + d > maxi) { j++; } } cout << j << end... |
#include <bits/stdc++.h> using namespace std; const long long p = 998244353; const long long N = 3e5; long long fact[N + 1]; int32_t main() { clock_t clk = clock(); ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); fact[0] = 1; for (long long i = 1; i <= N; i++) { ... |
#include <bits/stdc++.h> using namespace std; struct tree { queue<int> a; }; tree num[100005]; long long apple[100005]; int beg = 1; void dfs(int nn, int beg) { if (num[nn].a.empty()) return; while (!num[nn].a.empty()) { int n1 = num[nn].a.front(); num[nn].a.pop(); apple[beg ... |
#include <bits/stdc++.h> using namespace std; const int Nmax = 2e5 + 10; int n, k, a, b, q, i; int tip, d, p, lll; pair<int, int> arb[4 * Nmax]; void update(int nod, int st, int dr, int val, int poz) { if (st >= dr) { arb[nod].first = min(b, arb[nod].first + val); arb[nod].second = min(a, ar... |
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; string l; cin >> l; sort(l.begin(), l.end()); int a = 0, ans = 0; char p = l[0]; for (;;) { if (l[0] == p) { a++; l.erase(l.begin()); } else { ans = max(ans, a); ... |
#include <bits/stdc++.h> using namespace std; const int mo = 1e9 + 7; const int mx = 500010; int n, m, k, a[1010], c[1010], ans, sum; int jud[mx]; set<int> s[mx]; set<int>::iterator it; vector<int> vc[mx]; void dfs(int y, int pre) { vector<int> v; if (pre == -1) { int t = 1; for (i... |
#include <bits/stdc++.h> using namespace std; int n, w[101], i, j, S, Sum, k, C, a, t; int main() { scanf( %d , &n); for (i = 1; i <= n; i++) { scanf( %d , &k); for (j = 1; j <= k; j++) { scanf( %d , &a); Sum += a; t = j * 2 - k; if (t == 1) w[C++] = -... |
#include <bits/stdc++.h> using namespace std; template <typename T> T gcd(T a, T b) { T m; while (b != T(0)) { m = a % b; a = b; b = m; } return a; } template <typename T> T lcm(T a, T b) { return a == 0 && b == 0 ? 0 : (a / gcd(a, b)) * b; } char s[1500080]; stat... |
#include <bits/stdc++.h> using namespace std; int c[105], sum[105]; pair<int, int> p[105]; int main() { int n; scanf( %d , &n); for (int i = 1; i <= n; i++) { scanf( %d , &c[i]); sum[i] = sum[i - 1] + c[i]; } int st = 1, tot = 0; for (int i = 1; i <= n; i++) { if (sum[i... |
#include <bits/stdc++.h> #pragma GCC optimize( O3 ) std::pair<int, int> DR[] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}, {-1, 1}, {-1, -1}, {1, 1}, {1, -1}}; using namespace std; int n, x, a[1 << 19]; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); cerr.tie(... |
#include <bits/stdc++.h> using namespace std; const int N = 512, M = 20000 + 10; struct Stage { int p[N]; } stage[N * 2]; struct Edge { int u, v; void init() { scanf( %d%d , &u, &v); } } edge[M]; int preStg[M], postStg[M], nstg; int p[N], num[N]; int n, m; int findr(int x, int* P) { ... |
#include <bits/stdc++.h> using namespace std; int main() { long long n, m, k, i, x, y, s, p; cin >> n >> m; s = 0; k = 1; for (i = 1; i <= n; i++) { cin >> x >> y; k = x - k; p = k % m; x -= p; s += y - x + 1; k = y + 1; } cout << s << endl; } |
#include <bits/stdc++.h> #pragma comment(linker, /STACK:136777216 ) using namespace std; int bits(int x) { return x == 0 ? 0 : 1 + bits(x & (x - 1)); } int v[30][30]; int dp[2][26][111]; int main() { const int ninf = -1000000; for (int(i) = 0; (i) < (30); (i)++) for (int(j) = 0; (j) < (30); (... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.