func_code_string stringlengths 59 71.4k |
|---|
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; vector<long long> p(n + 1, 1); for (int i = 1; i <= n; ++i) p[i] = p[i - 1] * 7; vector<long long> h(n + 1, 0); for (int i = 0; i < m; ++i) { int x, y; cin >> x >> y; h[x] += p[y]; h[y... |
#include <bits/stdc++.h> using namespace std; int main() { int a[] = {0, 1, 2, 3, 4}; int lst[5][5]; for (int i = 0; i < 5; i++) for (int j = 0; j < 5; j++) scanf( %d , &lst[i][j]); int ANS = 0; do { int sum = lst[a[0]][a[1]] + lst[a[1]][a[0]] + lst[a[1]][a[2]] + lst[... |
#include <bits/stdc++.h> int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(nullptr); int n; std::cin >> n; int max = -1; int min = -1; std::vector<int> l, r; for (int i = 0; i < n; ++i) { int x, y; std::cin >> x >> y; l.push_back(x); r.push_back(y... |
#include <bits/stdc++.h> using namespace std; const long long OO = 1e8; const double EPS = (1e-7); vector<vector<int> > readAdjList() { int n, e; scanf( %d%d , &n, &e); vector<vector<int> > adjList(n + 1); for (int i = 0; i < (e); i++) { int u, v; scanf( %d%d , &u, &v); adjList... |
#include <bits/stdc++.h> using namespace std; using VI = vector<int>; using VVI = vector<VI>; using PII = pair<int, int>; using LL = long long; using VL = vector<LL>; using VVL = vector<VL>; using PLL = pair<LL, LL>; using VS = vector<string>; template <class S, class T> istream& operator>>(istrea... |
#include <bits/stdc++.h> using namespace std; int main() { long long a; cin >> a; if (a % 2 == 0) { cout << NO ; return 0; } if ((a - 3) / 2 < 1) { cout << NO ; return 0; } cout << 1 << << (a - 3) / 2; } |
#include <bits/stdc++.h> intmax_t f(intmax_t x) { intmax_t res = 0; intmax_t tenpow = 10; while (x / tenpow > 0) { res += x / tenpow * 9; tenpow *= 10; } return res; } int testcase_ends() { intmax_t n, s; scanf( %jd %jd , &n, &s); if (n == 0 && s == 0) return 1; int... |
#include <bits/stdc++.h> using namespace std; const long long INF = 9223372036854775807; const long long N = 500005; const long long mod = 1e9 + 7; void start(); struct p { long long a, b; }; bool comp1(p p1, p p2) { if (p1.a < p2.a) { return true; } if (p1.a == p2.a) { retur... |
#include <bits/stdc++.h> using namespace std; long long mod = 1000000007; const int INF = 1e9; const long long LINF = 1e18; long long mod_sum() { return 0LL; } template <typename T, typename... Args> T mod_sum(T a, Args... args) { return ((a + mod_sum(args...)) % mod + mod) % mod; } long long mod_... |
#include<iostream> #include<string> using namespace std; int main() { int T; cin >> T; for (int t=0;t<T;t++) { string s; int n, q; cin >> n >> q >> s; int f0 = -1; int f1 = -1; int l0 = -1; int l1 = -1; for (int i=0;i<n;i++) { if(s[i]== 0 ) { l0=i; if( f0... |
#include <bits/stdc++.h> using namespace std; const int dx[8] = {-1, -1, -1, 0, 0, 1, 1, 1}; const int dy[8] = {-1, 0, 1, -1, 1, -1, 0, 1}; int t, ans, n, m; int a[256][256], u[256][256]; char c; void work(int x, int y) { int tx, ty; u[x][y] = 1; for (int i = 0; i <= 7; i++) { tx = x + d... |
#include <bits/stdc++.h> using namespace std; void solve() { int n, m, temp; cin >> n >> m; bool grid[n][m]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { cin >> temp; grid[i][j] = (bool)temp; } } vector<vector<int>> dp(n, vector<int>(m)); for (i... |
#include <bits/stdc++.h> using namespace std; const int N = 5e3 + 7, M = 2e6 + 7, p = 1e9 + 7; bool fp[M], gt[N]; vector<int> h[N], vt[N]; int n, a, b, tot, f[N], op[N], f1[N], f2[N], fl[N], st[N], va[N], cnt[N], ft[N][N]; char s[N][N]; vector<char> t[N]; inline int read() { int num = 0; c... |
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; string s; for (int j = 0; j < t; j++) { cin >> s; int n = s.size(); cout << s[0]; for (int i = 1; i < n - 1; i++) { if (s[i] == s[i + 1]) { cout << s[i]; i += 1; } ... |
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; template <class T, class U> inline void add_self(T &a, U b) { a += b; if (a >= mod) a -= mod; if (a < 0) a += mod; } template <class T, class U> inline void min_self(T &x, U y) { if (y < x) x = y; } template <class ... |
#include <bits/stdc++.h> using namespace std; using namespace chrono; const int N = 250005; vector<int> G[N], leaf; int n, k, dep[N], par[N], ans; void dfs(int d, int u, int p) { dep[u] = d; par[u] = p; if (d >= n / k) ans = 1; int c = 0; for (auto v : G[u]) { if (dep[v]) continue;... |
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; int n, k; long long dp[2005][2005][2]; string s; int main() { cin >> n >> k >> s; dp[n][0][0] = 1; dp[n][0][1] = 1; for (int i = n - 1; i >= 0; --i) { for (int j = 0; j <= k; ++j) { for (int eq = 0;... |
#include <bits/stdc++.h> using namespace std; #pragma comment(linker, /stack:200000000 ) #pragma GCC optimize( Ofast ) #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native ) #pragma GCC optimize( -ffloat-store ) #define fastio ios::sync_with_stdio(0); cin.tie(0); cout.t... |
#include <bits/stdc++.h> using namespace std; const long long INF = 9e18L; const long long mod = 1e9 + 7; long long power(long long x, long long y) { long long res = 1; int mod = 1e9 + 7; while (y > 0) { if (y & 1) (res = res * x) %= mod; (x = x * x) %= mod; y = y >> 1; } r... |
#include <bits/stdc++.h> const double pi = 3.141592653589793238462; const double eps = 1e-10; using namespace std; const int maxn = 100010; int c[maxn]; multiset<int> a; multiset<int> b; multiset<int>::iterator setfloor(int val) { multiset<int>::iterator it = b.upper_bound(val); if (it == b.begi... |
#include <bits/stdc++.h> using namespace std; int const N = 2e5 + 5; int a[N]; int n, ac, b; int main() { cin >> n >> b >> ac; int temp1 = b; int temp2 = ac; for (int i = 0; i < n; i++) cin >> a[i]; int i; for (i = 0; i < n; i++) { if (temp1 == 0 && temp2 == 0) break; if (a... |
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; if (n <= 6) { cout << m << endl; return 0; } int mark[8][8] = {0}, i, j, deg[8] = {0}, a, k; for (i = 0; i < m; i++) { int x, y; cin >> x >> y; mark[x][y] = 1; mark[y][x] =... |
#include <bits/stdc++.h> using namespace std; int a[200005], c[200005], b[200005], ans[200005]; struct node { int x, y; } e[200005]; int main() { int n, m, Max = 0; scanf( %d%d , &n, &m); for (int i = 1; i <= n; i++) { scanf( %d , &a[i]); } for (int i = 1; i <= m; i++) { sc... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long a[1005], b[1005], n, i, j, k, temp, sum; cin >> n; for (i = 0; i < n; i++) { cin >> a[i]; cin >> b[i]; } for (i = 0; i < n - 1; i++) { for (j = 0; j < n... |
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 5; inline int read() { int x = 0; int f = 1, hhh = getchar(); while (!isdigit(hhh)) { if (hhh == - ) f = -1; hhh = getchar(); } while (isdigit(hhh)) { x = x * 10 + hhh - 0 ; hhh = getchar(); } ... |
#include <bits/stdc++.h> using namespace std; const int MAXN = 100005; string ax, bx; int q, pre1[MAXN], pre2[MAXN], pre3[MAXN], pre4[MAXN], a, b, c, d; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> ax >> bx >> q; for (int i = 1; i <= ax.size(); ++i) { if (ax[i - 1] == A... |
#include <bits/stdc++.h> using namespace std; int const N = 3000 + 20; int n, dp[N], mx1, mx2, ans; vector<pair<int, bool>> adj[N]; void dfs1(int v, int p = -1) { for (auto x : adj[v]) { int u = x.first, f = x.second; if (u != p) { dfs1(u, v); dp[v] += dp[u] + (!f); } ... |
#include <bits/stdc++.h> using namespace std; long long int n, c; vector<long long int> a, b; long long int pos(long long int l) { long long int d1 = 0; for (long long int i = 0; i < n; i++) { long long int x = (a[i] * l) / b[i]; x++; d1 += x; } return d1; } pair<long long ... |
#include <bits/stdc++.h> #pragma GCC optimize( O3 ) using namespace std; template <class c> struct rge { c b, e; }; template <class c> rge<c> range(c i, c j) { return rge<c>{i, j}; } template <class c> auto dud(c* x) -> decltype(cerr << *x, 0); template <class c> char dud(...); struct ... |
#include <bits/stdc++.h> using namespace std; void fastio() { ios_base::sync_with_stdio(false); cin.tie(NULL); } long long fre[1000000]; int32_t main() { fastio(); long long n; cin >> n; long long a[n]; for (long long i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); for (lon... |
#include <bits/stdc++.h> using namespace std; int main() { long long A, B; int N; long long l, r, t, tt, M; cin >> A >> B >> N; for (int i = 0; i < N; i++) { scanf( %I64d%I64d%I64d , &l, &t, &M); long long st = l, ed = l + 1000000; long long H = A + (l - 1) * B; long long... |
#include <bits/stdc++.h> using namespace std; const int MAXN = 1010; long long t, n, arr[MAXN], h, sub[MAXN], cnt, add[MAXN]; long long find(int x) { long long l = 0, r = cnt; while (l < r) { long long mid = (l + r) >> 1; if (sub[mid] >= x) r = mid; else l = mid + 1; ... |
#include <bits/stdc++.h> using namespace std; int a[102][102][102] = {}; int main() { string s; int n, m, k; cin >> n >> m >> k; for (int i = 1; i < n + 1; ++i) { for (int j = 1; j < m + 1; ++j) { cin >> s; for (int t = 1; t < k + 1; ++t) a[i][j][t] = s[t - 1] - 0 ; } ... |
#include <bits/stdc++.h> using namespace std; long long dp[100050][205]; int redpac[100050][4]; int e[100050]; bool cmp(int x, int y) { return redpac[x][0] < redpac[y][0]; } int main() { int n, m, k, cur = 0; long long ans = -1; priority_queue<pair<int, pair<int, int> > > availablepackets; s... |
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> v(n); for (int i = 0; i < n; i++) { cin >> v[i]; } sort(v.begin(), v.end()); long long sum = 0; for (int i = 0; i < n / 2; i++) { long long p_sum = v[i] + v[n - i - 1]; sum += (p... |
#include <bits/stdc++.h> using namespace std; vector<int> r; vector<int> l; int n, ans, a[550000]; int main() { cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; a[0] = a[1]; a[n + 1] = a[n]; for (int i = 1; i <= n; i++) { if (a[i] == a[i + 1] && a[i] != a[i - 1]) r.push_back(i); ... |
#include <bits/stdc++.h> using namespace std; int main() { int n, s; int max = 0; int counter = 0; cin >> n >> s; for (int i = 0; i < n; i++) { int a; cin >> a; counter += a; if (a > max) { max = a; } } if (counter - max > s) { cout << NO ; ... |
#include <bits/stdc++.h> using namespace std; int max(int a, int b, int c, int d) { if (a >= b && a >= c && a >= d) return a; if (b >= a && b >= c && b >= d) return b; if (c >= a && c >= b && c >= d) return c; if (d >= a && d >= c && d >= b) return d; return d; } int main() { int x1, x2,... |
#include <bits/stdc++.h> using namespace std; int t, n, m, cur; int nxt[200200][26], link[200200], dp[200200], cnt[200200], ord[200200], occur[200200]; char s[200200]; void extend(int c) { int x = cur, y = cur = ++m; dp[y] = dp[x] + 1; occur[y] = 1; while (x && !nxt[x][c]) nxt[x][c] = y,... |
#include <bits/stdc++.h> using namespace std; const int maxN = 1e4; long long F[maxN + 1]; void fact() { F[0] = F[1] = 1; for (int i = 2; i <= maxN; i++) F[i] = (1LL * F[i - 1] * i) % 998244353; } long long power(long long a, long long b) { long long res = 1; while (b) { if (b & 1) { ... |
#include <bits/stdc++.h> using namespace std; vector<int> v[250001]; int a, ans[250001], n, i, q, kol; bool pole[250001]; void dfs(int nom) { int i; kol++; pole[nom] = true; for (i = 0; i < v[nom].size(); i++) if (!pole[v[nom][i]]) dfs(v[nom][i]); ans[nom] = kol; } int main() { ... |
#include <bits/stdc++.h> using namespace std; const int inf = 1e9 + 7; const long long INF = 1e18L + 7; template <class n, class second> ostream &operator<<(ostream &p, pair<n, second> x) { return p << < << x.first << , << x.second << > ; } template <class n> auto operator<<(ostream &p, n y) -... |
#include <bits/stdc++.h> using namespace std; int n, a[3005], b[3005], df[3005]; long long F[3005][3005]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin >> n; for (int i = 1; i <= n; ++i) { cin >> a[i]; a[i] = a[i] - i; b[i] = a[i]; } ... |
#include <bits/stdc++.h> #pragma GCC optimize( -O2 ) using namespace std; const int LIM = 2e5 + 5, MOD = 1e9 + 7; int t, n, m, k, x, y; template <typename... T> void read(T &...args) { ((cin >> args), ...); } template <typename... T> void print(T &&...args) { ((cout << args << ), ...); } ... |
#include <bits/stdc++.h> using namespace std; typedef struct frac { long long p, q; } frac; const double eps = 1e-8; int n; int nb[100100]; vector<int> G[100100]; bool col[100100]; int cur[100100]; int onstk[100100]; inline bool operator<(frac a, frac b) { return a.p * b.q < b.p * a.q; } inl... |
#include <bits/stdc++.h> using namespace std; const int n = 100002; char h[n], h1[n]; int a[n]; bool check(int e, int r, int v1, int c1) { int c, v, c2, v2; while (e < r) { for (c = 0; c < 10; c++) for (v = 0; v < 10; v++) if (c + v == v1 + h[r]) { if ((c == 0) && (... |
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; int A, B, C, D; struct Point { long long x, y; Point(long long x, long long y) : x(x), y(y) {} }; bool operator<(const Point& a, const Point& b) { return a.x < b.x || (a.x == b.x && a.y > b.y); } int main() { int n; ... |
#include <bits/stdc++.h> using namespace std; int dp[5000][5000]; int main() { char a[5000], b[5000]; int ti, td, tr, te; scanf( %d %d %d %d , &ti, &td, &tr, &te); scanf( %s %s , a, b); int n = strlen(a); int m = strlen(b); dp[0][0] = 0; for (int i = 1; i <= n; i++) dp[i][0] = dp[i... |
#include <bits/stdc++.h> int n; int main() { int i; scanf( %d , &n); for (i = 20; i >= 0; i--) { if (n & (1 << i)) printf( %d , i + 1); } return 0; } |
#include <bits/stdc++.h> using namespace std; const int N = 100005; struct all { int t, num; char x, type; } a[N]; bool cmp(all a, all b) { return a.t < b.t; } int redhome[N], redaway[N]; int yellhome[N], yellaway[N]; string home, away; int n; int main() { cin >> home >> away; cin >>... |
#include <bits/stdc++.h> using namespace std; int main() { int n, p; cin >> n >> p; string s; cin >> s; bool f = 0; int i = s.size() - 1; if (i > 0) { while (s[i] - a == p - 1) { s[i] = a ; i--; } s[i]++; } if (s.size() == 2) i = s.size() - 1;... |
#include <bits/stdc++.h> using namespace std; int euclid(int a, int b, int &x, int &y) { if (!a) { x = 0; y = 1; return b; } int _x, _y; int g = euclid(b % a, a, _x, _y); x = _y - b / a * _x; y = _x; return g; } void relax(int &obj, int C3, int C4, int C5, int _k3, ... |
#include <bits/stdc++.h> #pragma GCC optimize(2) using namespace std; void qread(int &x) { int neg = 1; x = 0; char c = getchar(); while (c < 0 || c > 9 ) { if (c == - ) neg = -1; c = getchar(); } while (c >= 0 && c <= 9 ) x = 10 * x + c - 0 , c = getchar(); x *= ne... |
#include <bits/stdc++.h> using namespace std; using namespace std::chrono; struct custom_hash { size_t operator()(uint64_t x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return x + FIXED_RANDOM; } }; void solve() { long... |
#include <bits/stdc++.h> using namespace std; const long long MAXN = 200 + 17, inf = 2e18 + 17; long long a[MAXN], b[MAXN], n, m, k, t[MAXN][MAXN], np; void fillA() { for (int i = 1; i <= m; i++) for (int j = 0; i - j > 0 && j < n; j++) a[i] = min(t[j + 1][i - j], a[i]); for (int i = 1; i <= n; i+... |
#include <bits/stdc++.h> using namespace std; const int high = 2e5 + 6; long long cnt[200005], dif[200005]; int main() { long long n, m, k, i, j, ans, l, r, d, sum = 0, q; scanf( %lld%lld%lld , &n, &k, &q); for (i = 0; i < n; i++) { scanf( %lld%lld , &l, &r); dif[l]++; dif[r + 1]--... |
#include <bits/stdc++.h> const long long int MOD = 1000000007ll; const int mxsz = 200005; using namespace std; int main() { std::ios_base::sync_with_stdio(false); long long int n, m, a; cin >> n >> m >> a; int ar1[n + 1], ar2[m + 1]; for (int i = 1; i <= n; i++) { cin >> ar1[i]; } ... |
#include <bits/stdc++.h> using namespace std; int x[1000], y[1000], k, n, m; bool chck(int xx) { vector<int> v; v.push_back(1); v.push_back(m); for (int i = 0; i < k; ++i) { v.push_back(max(1, x[i] - xx)); v.push_back(max(1, x[i] - xx - 1)); v.push_back(min(m, x[i] + xx)); ... |
#include <bits/stdc++.h> using namespace std; int cansel_sync = (ios::sync_with_stdio(0), cin.tie(0), 0); const int N = 200010; const int inf = ~0u >> 2; const long long INF = ~0ull >> 2; long long read() { long long x; if (scanf( %lld , &x) == -1) exit(0); return x; } const double pi = acos... |
#include <bits/stdc++.h> using namespace std; const int N = 1E5; vector<int> vf, vz; int main() { ios_base::sync_with_stdio(false); int n, k, p; cin >> n >> k >> p; for (int i = 0; i < n; i++) { int x; cin >> x; if (x % 2 == 0) vz.push_back(x); else vf.pus... |
#include <bits/stdc++.h> int dx[] = {-1, -1, -1, 0, 1, 1, 1, 0}; int dy[] = {-1, 0, 1, 1, 1, 0, -1, -1}; using namespace std; long long power(long long a, long long p, long long M) { long long r = 1; a = a % M; while (p > 0) { if (p % 2) r = (r * a) % M; a = (a * a) % M; p /= 2; ... |
#include <bits/stdc++.h> using namespace std; long long A, B, N; long long L, T, M; bool ok(long long R) { long long mx = A + (R - 1) * B; long long mn = A + (L - 1) * B; long long D = R - L; if (mx > T) return false; return (mn * (D + 1) + B * D * (D + 1) / 2) <= T * M; } int main(void)... |
#include <bits/stdc++.h> using namespace std; const int INF = 1e9 + 7, mod = 1e9 + 9, pw = 31; const double eps = 1e-11; long long binpow(long long a, long long b) { long long rec = 1; while (b) { if (b % 2 == 1) { rec *= a; rec %= INF; } a *= a; a %= INF; b... |
#include <bits/stdc++.h> const long long INF64 = 1e18; using namespace std; const long long N = 2e5 + 6; using namespace std; vector<pair<long long, long long>> pf; int main() { long long n, ans = INF64; cin >> n; vector<long long> cost(n, 0); vector<string> s; for (int i = 0; i < n; i++... |
#include <bits/stdc++.h> using namespace std; long long a[100005], n, c, mn[100005], dp[200005], sum; int main() { ios_base::sync_with_stdio(0); cin >> n >> c; for (int i = 0; i < n; sum += a[i++]) cin >> a[i]; deque<long long> v; for (int i = n; i--;) { while (v.size() && v.back() >= i ... |
#include <bits/stdc++.h> using namespace std; template <typename T1, typename T2> inline T1 max(T1 a, T2 b) { return a < b ? b : a; } template <typename T1, typename T2> inline T1 min(T1 a, T2 b) { return a < b ? a : b; } const char lf = n ; namespace ae86 { const int bufl = 1 << 15; cha... |
#include <bits/stdc++.h> using namespace std; const int MAX = 1010; int n; int a[MAX], c[MAX]; void init() { cin >> n; } void process() { memset(a, 63, sizeof(a)); vector<pair<int, int> > ques; ques.push_back(make_pair(1, n)); while (!ques.empty()) { vector<pair<int, int> > newQues; ... |
#include <bits/stdc++.h> using namespace std; const int MAXN = 300; long long orign[MAXN], str[2 * MAXN]; int radius[2 * MAXN]; int n, m; int mp[MAXN][MAXN]; int num[MAXN][26]; long long hashv[MAXN]; long long base[30]; int siz[MAXN]; bool check(int x, int y) { for (int i = 0; i < 26; i++) { ... |
#include <bits/stdc++.h> using namespace std; const int N = 10000010; int p[N], num, last[N]; bool flag[N]; int cnt[N], n, m; void make_prime() { for (int i = 2; i < N; ++i) if (!flag[i]) { p[num++] = i; last[i] = i; for (int j = i + i; j < N; j += i) flag[j] = true, last[j... |
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const int N = 2005; const int M = 730; int Head[M * 10], Next[M * 100], vet[M * 100]; int a[N], b[N], d[M * 10], vis[15], p[M][5], dis[M], Dis[M], P[10], len[M], U[M][12], D[M][12]; int n, cnt, edgenum; pair<int, int> c[M]; ... |
#include <bits/stdc++.h> using namespace std; const int N = 3003 * 6006; const int qwq = 303030; const int inf = 0x3f3f3f3f; int n, m, k; int f[N], fa[N], st[123], cnt; int ans; int ff[] = {1, 1, 1, 0, -1, -1, -1, 0}; int gg[] = {1, 0, -1, -1, -1, 0, 1, 1}; inline int read() { int sum = 0, f = 1... |
#include <bits/stdc++.h> using namespace std; int n, sum; int main() { cin >> n; while (n != 0) { if (n % 8 == 1) sum++; n /= 8; } cout << sum; return 0; } |
#include <bits/stdc++.h> using namespace std; const int INF = 1 << 29; const int MOD = 1000000007; bool isPowerOfTwo(long long int x) { return x && (!(x & (x - 1))); } void fastio() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); } const int dx[] = {1, 0, -1, 0, 1, 1, -1, -1}; c... |
#include <bits/stdc++.h> using namespace std; map<long long, int> mp; int n; int main() { scanf( %d , &n); int t; long long s = 0; for (int i = 1; i <= n; i++) { scanf( %d , &t); s += t; mp[s]++; } int ans = 0; map<long long, int>::iterator it; for (it = mp.begi... |
#include <bits/stdc++.h> using namespace std; vector<int> edge[100005]; int v[100005]; bool cycle = false; int mx = -1, last; void dfs(int u, int dis = 0) { v[u] = 1; if (dis > mx) { mx = dis; last = u; } for (int i = 0; i <= (int)((int)edge[u].size() - 1); i++) { int first... |
#include <bits/stdc++.h> using namespace std; const int INF = 1 << 29; const double EPS = 1e-10; vector<int> G[50010]; vector<int> chil[50010]; int cnt[50010][510]; void dfs(int pos, int par) { for (int i = 0; i < (int)G[pos].size(); i++) { if (G[pos][i] != par) { chil[pos].push_back(G[p... |
#include <bits/stdc++.h> using namespace std; struct P { int x, y; bool operator<(const P &p) { if (x != p.x) return x < p.x; else return y < p.y; } }; int main() { int T; cin >> T; for (int t = 0; t < T; ++t) { int n; cin >> n; int bsz = n /... |
#include <bits/stdc++.h> using namespace std; int main() { int n, k, a, b, c, d; scanf( %d%d%d%d%d%d , &n, &k, &a, &b, &c, &d); if (n <= 4 || k < n + 1) { puts( -1 ); return 0; } printf( %d %d , a, c); for (int i = 1; i <= n; i++) { if (i != a && i != b && i != c && i != d)... |
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const int N = 2e5 + 10; const long long inf = 1e18; const int maxm = 1005; vector<vector<char>> matrix(maxm, vector<char>(maxm)); struct event { int x, y, size; }; int dx[] = {0, 0, 1, -1}; int dy[] = {-1, 1, 0, 0}; class e... |
#include <bits/stdc++.h> double aa[12]; int sign[12]; int compare(const void *a, const void *b) { int i = *(int *)a; int j = *(int *)b; if (sign[i] != sign[j]) return sign[j] - sign[i]; if (sign[i] == 0) return i - j; return aa[i] == aa[j] ? i - j : aa[i] > aa[j] ? -sign[i] : sign[i]; } vo... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int n, m; cin >> n >> m; vector<int> a(n); for (int i = 0; i < n; ++i) { cin >> a[i]; } vector<int> rightInc(n), leftInc(n); int end = 0, cur_count = 1; for (i... |
#include <bits/stdc++.h> using namespace std; const int maxn = 3e6 + 7; const int INF = 0x7fffffff; int n, m; struct DATA { int strid; int index; }; vector<DATA> vec; string str[maxn]; char ans[maxn]; bool cmp(DATA a, DATA b) { return a.index < b.index; } int main() { while (cin >> n) ... |
#include <bits/stdc++.h> using namespace std; int main() { int num[3]; cin >> num[0] >> num[1] >> num[2]; char c1 = * , c2 = * ; if (num[0] == 1) c1 = + ; if (num[2] == 1) c2 = + ; if (num[1] == 1 && num[0] != 1 && num[2] != 1) { cout << max(num[0] * (num[1] + num[2]), (num[0] + nu... |
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf( %d , &n); long long int arr[100]; for (int i = 0; i < n; i++) cin >> arr[i]; long long int cnt[5]; long long int p[5]; for (int i = 0; i < 5; i++) cin >> p[i]; long long int min = 1000000009; for (int i = 0;... |
#include <bits/stdc++.h> using namespace std; long long t, n, m, cap, lis[200500], high, low; long long f(long long x) { long long res = 0, cnt = 0, buf = 0; for (int i = (0); i <= ((int)(n)-1); i++) if (lis[i] <= x) { if (!cnt) { res += buf; buf = 0; } cn... |
#include <bits/stdc++.h> using namespace std; long long int dp[2010][2010]; long long int a[2010]; long long int b[2010]; int main() { int n; cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i] >> b[i]; } for (int i = 0; i <= 2000; i++) { for (int j = 0; j <= 2000; j++) { ... |
#include <bits/stdc++.h> const long long int MOD = 1e9 + 7; const long long int INF = 1011111111; const long long int LLINF = 1000111000111000111LL; const long double EPS = 1e-10; const long double PI = 3.14159265358979323; using namespace std; long long int power(int x, int n) { if (n == 0) ret... |
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5, oo = 0x3f3f3f3f, mod = 1e9 + 7; int a[N], n, tree[N], srt[N], ans[N]; void update(int a, int val) { while (a <= n) { tree[a] = max(val, tree[a]); a += a & -a; } } int query(int a) { int mx = 0; while (a > 0) { ... |
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 9; int n, maxx; struct p { int lei, num, x; } a[maxn]; int da[maxn], b[maxn], vis[maxn]; int main() { cin >> n; for (int i = 1; i <= n; i++) cin >> b[i]; int w; cin >> w; for (int i = 1; i <= w; i++) { cin >... |
#include <bits/stdc++.h> const int INF = 0x3f3f3f3f; const int N = 579; const long long P = 1000000007; int n, b[N]; long long d[N][N]; long long solve(int l, int r) { if (l == r) return 1; static bool used[N][N]; static long long ans[N][N]; if (used[l][r]) return ans[l][r]; used[l][r] =... |
#include <bits/stdc++.h> using namespace std; int main() { int a[4]; for (int i = 0; i < 4; i++) cin >> a[i]; int sumtotal = a[0] + a[1] + a[2] + a[3]; if (sumtotal % 2 != 0) { cout << NO ; return 0; } for (int i = 0; i < 4; i++) { if (a[i] == sumtotal - a[i]) { co... |
#include <bits/stdc++.h> using namespace std; vector<pair<int, double>> ans[52]; int main() { int n, w, m; cin >> n >> w >> m; double s = (n * w) / (m * 1.0), c = w, b = 1, k = 0; for (int i = 0; i < m; i++) { double ne = s; while (1) { if (ne + 10e-7 > c) { ans[i].pu... |
#include <bits/stdc++.h> using namespace std; void quickly_quickly_kro() { long long n; cin >> n; vector<long long> v(n); for (long long i = 0; i < n; i++) cin >> v[i]; ; map<long long, long long> M, N, I; for (long long i = 0; i < n; i++) { if (v[i] != 0) M[v[i]]++; ... |
#include <bits/stdc++.h> using namespace std; struct HashMap { vector<pair<int, int> > g[1000007]; void ins(int x, int y) { int id = ((long long)x * 1000000007 + y) % 1000007; g[id].push_back(make_pair(x, y)); } bool get(int x, int y) { int id = ((long long)x * 1000000007 + y) % 10... |
#include <bits/stdc++.h> using namespace std; const int inf = (int)1.01e9; const double eps = 1e-9; const int maxn = (int)2e5 + 10; set<int> S; int main() { int n, k, a; scanf( %d%d%d , &n, &k, &a); int cur = (n + 1) / (a + 1); assert(cur >= k); int m; scanf( %d , &m); for (int i... |
#include <bits/stdc++.h> using namespace std; bool has[200009]; int left[200009]; int main() { int Q; cin >> Q; for (int q = 0; q < Q; q++) { int N; cin >> N; vector<int> v; for (int i = 0; i < N; i++) { int a; cin >> a; v.push_back(a); } s... |
#include <bits/stdc++.h> using namespace std; struct Segment { int l, r, x, ls, rs, fa; } seg[2000100]; int n, k, p[100100], cnt, pnt, b[2000100], w, ans[100100], res; int Dfs(int &id, int l, int r) { id = ++cnt; seg[id].l = l, seg[id].r = r; seg[id].x = 1; if (r - l == 1) return 1; in... |
#include <bits/stdc++.h> using namespace std; string s[1100]; int vis[1100]; int num[100]; int main() { ios::sync_with_stdio(false); int n, len, k; cin >> n >> len >> k; string st; cin >> st; for (int i = 0; i < st.size(); i++) { num[st[i] - a ]++; } int l = 0, r = 25; ... |
#include <bits/stdc++.h> using namespace std; int T, n, m, nw, a[110][110], id[110][110], pos[110], p[110]; char ch; bool cmp(int i, int j) { return a[m][i] < a[m][j]; } queue<int> q; void find(int x) { p[x] = 0; int y = id[x][pos[x]]; pos[x]--; if (!p[y]) p[y] = x, p[x] = y; else ... |
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 9; vector<int> getBorder(const string str) { int n = str.size(); vector<int> border(n, -1); for (int i = 1, j = -1; i < n; i++) { while (j >= 0 && str[i] != str[j + 1]) { j = border[j]; } if (str[i] == str[j + ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.