func_code_string stringlengths 59 71.4k |
|---|
#include <bits/stdc++.h> using namespace std; using ll = long long; using vi = vector<long long>; using pii = pair<long long, long long>; const signed INF_ = 1001001001; const long long INF = 1001001001001001001LL; const long long DX[9] = {0, 1, 0, -1, 1, 1, -1, -1, 0}, DY[9] = {-1, 0, 1... |
#include <bits/stdc++.h> using namespace std; int rep[2000005]; int sz[2000005]; void dsu(int n) { for (int i = 0; i < n; i++) rep[i] = i, sz[i] = 1; } int findSet(int a) { return ((rep[a] == a) ? a : rep[a] = findSet(rep[a])); } int mergeSet(int a, int b) { int y = findSet(b); int x = findSet... |
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; int k = 0; while (1) { k++; if (k % m == 0) n++; n--; if (n == 0) break; } cout << k; return 0; } |
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5; int edges[MAXN] = {0}; int main() { int n, s; cin >> n >> s; for (int i = 0; i < n - 1; i++) { int a, b; cin >> a >> b; a--, b--; edges[a]++, edges[b]++; } int amt = 0; for (int i = 0; i < n; i++)... |
#include <bits/stdc++.h> using namespace std; int v[100]; bool cmp(int a, int b) { return a > b; } int highest(int n) { int i = 1, fact = 0; while (2 * i <= n) { i *= 2; fact++; } return fact; } void permute(int left, int right, int pos, int last) { if (!pos || (!last && pos ... |
#include <bits/stdc++.h> class Solver { public: Solver() = default; void read() { int n; std::cin >> n; int left = 0; int right = 0; for (int i = 0; i < n; ++i) { int x, y; std::cin >> x >> y; if (x < 0) left++; else right++;... |
#include <bits/stdc++.h> using namespace std; int flow, n, m, S, T, tot, x, y; int g[3000], dis[3000], pre[3000]; int Next[50000], adj[50000], f[50000], c[50000]; bool used[3000]; queue<int> q; int ans = 0; int calc[110][30]; string t, s; void add(int x, int y, int flow, int cost) { adj[tot] = y... |
#include <bits/stdc++.h> using namespace std; int main() { clock_t clk_begin = clock(); ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n; cin >> n; string s; cin >> s; int c = 0; for (int i = 0; i < n; ++i) if (s[i] == 8 ) c++; n /= 11; co... |
#include <bits/stdc++.h> using namespace std; int form[9], piece[9][2]; map<int, int> res; string result[] = { illegal , the first player won , the second player won , draw , first , second }; void pre() { form[0] = 3; piece[0][0] = 1; piece[0][1] = 1 << 1; for (int i = 1; i ... |
#include <bits/stdc++.h> using namespace std; int parent(int x, vector<int> &v) { return v[x] = (v[x] == x ? x : parent(v[x], v)); } void u(int x, int y, vector<int> &v, vector<int> &r) { x = parent(x, v); y = parent(y, v); if (r[x] == r[y]) { if (x == y) { return; } r[... |
#include <bits/stdc++.h> using namespace std; int a[105], b[105]; int main() { int n, i, j, k, x, y; while (~scanf( %d , &n)) { for (i = 1; i <= n; i++) { scanf( %d , &a[i]); } scanf( %d%d , &x, &y); for (i = 1, j = 0; i <= n; i++) { int count1 = 0, count2 = 0; ... |
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; vector<vector<int>> a(n, vector<int>(m, 0)); vector<vector<int>> b(n, vector<int>(m, 0)); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { cin >> a[i][j]; } } vector<pair<in... |
#include <bits/stdc++.h> using namespace std; template <typename T, typename U> inline void smin(T &a, const U &b) { if (a > b) a = b; } template <typename T, typename U> inline void smax(T &a, const U &b) { if (a < b) a = b; } template <class T> inline void gn(T &first) { char c, sg = 0; ... |
#include <bits/stdc++.h> using namespace std; using pii = pair<int, int>; void solve() { int m, k; cin >> m >> k; vector<pii> a; int ai; for (int i = 1; i <= k; i++) { cin >> ai; a.push_back({ai, i}); } sort(a.begin(), a.end(), greater<pii>()); int n = 1; for (; ;... |
#include <bits/stdc++.h> using namespace std; const int N = 211, M = N * N / 2; int u[M], v[M], w[M]; int f[N][N]; bool check(int n, int m, int lim) { for (int i = 1; i <= m; i++) { vector<pair<int, int>> v; bool t = 1; for (int j = 1; j <= n; j++) { int l = f[j][u[i]], r = f[j][... |
#include <bits/stdc++.h> using namespace std; int ans1, ans2; int t[4], v[4][10], T[10][10], A, B, C; map<string, int> mymap; const char *help[] = { Anka , Chapay , Cleo , Troll , Dracul , Snowy , Hexadecimal }; int countT() { int ret = 0; for (int k = 0; k < 3... |
#include <bits/stdc++.h> typedef long long ll ; using namespace std; const int maxn=2e5+5; const int maxm=5e6+5; #define P pair<int,int> #define fi first #define se second int t,n; int a[maxn]; int vis[maxm*2]; P mp[maxm]; int main() { ios::sync_with_stdio(false); cin.tie(nullp... |
#include <bits/stdc++.h> using namespace std; template <typename T> T BigMod(T b, T p, T m) { if (p == 0) return 1; if (p % 2 == 0) { T s = BigMod(b, p / 2, m); return ((s % m) * (s % m)) % m; } return ((b % m) * (BigMod(b, p - 1, m) % m)) % m; } template <typename T> T ModInv(T ... |
#include <bits/stdc++.h> using namespace std; const int M = 2048; char s[M], b[M], e[M], fb[M], fe[M]; int r[2][M], *p = r[0], *q = r[1], h[M]; int main(void) { cin >> s >> b >> e; int ns = strlen(s), nb = strlen(b), ne = strlen(e), nn = nb > ne ? nb : ne, w = 0; for (int i = ns; i-- > 0;)... |
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; int inv[25]; long long a[25]; int power(int a, int b) { int c = 1; for (; b; b >>= 1) { if (b & 1) c = (long long)c * a % mod; a = (long long)a * a % mod; } return c; } int C(long long y, int x) { if (y ... |
#include <bits/stdc++.h> using namespace std; template <typename T1, typename T2> string print_iterable(T1 begin_iter, T2 end_iter, int counter) { bool done_something = false; stringstream res; res << [ ; for (; begin_iter != end_iter and counter; ++begin_iter) { done_something = true; ... |
#include <bits/stdc++.h> using namespace std; int main() { int n, ans = 0; cin >> n; for (int i = 0; i < n; i++) { int x, y, z; cin >> x >> y >> z; ans += (x + y + z >= 2); } cout << ans << endl; return 0; } |
#include <bits/stdc++.h> using namespace std; char str[1010]; int pri[510][510]; int pre[510][510]; int f[510][510]; bool v[510] = {0}; int N; void init() { gets(str); scanf( %d , &N); } void prework() { int len = strlen(str); for (int i = 0; i < len; ++i) for (int j = 0; j < l... |
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) #pragma GCC optimize( unroll-loops ) #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native ) using namespace std; template <typename T1, typename T2> void ckmin(T1 &a, T2 b) { if (a > b) a = b; } template <type... |
#include <bits/stdc++.h> using namespace std; int main() { int n, arr[200005]; string swaps; cin >> n; for (int i = 1; i <= n; i++) cin >> arr[i]; cin >> swaps; int m = 0, flag = 0; for (int i = 1; i < n; i++) { m = max(m, arr[i]); if (swaps[i - 1] == 0 && m > i) { ... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n; cin >> n; char s; int d = 1, j = 1; for (int i = 1; i <= n; i++) { cin >> s; j -= 1; if (j == 0) { cout << s; d += 1; ... |
#include <bits/stdc++.h> using namespace std; long long mod = 1e9 + 7; const int N = 1e5 + 5; const double pi = acos(-1); long long n, m, ans; char arr[55][55]; bool inrange(int i, int j) { if (i < n && i >= 0 && j < m && j >= 0) return true; return false; } void solve(int i, int j) { int ... |
#include <bits/stdc++.h> using namespace std; int n; int main() { cin >> n; cout << n / 2 + n << endl; if (n & 1) { for (int i = 1; i <= n; i++) { if (!(i & 1)) cout << i << ; } for (int i = 1; i <= n; i++) { if (i & 1) cout << i << ; } for (int i = ... |
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5, M = 20; int n, m; string s; int pos[(1 << M) - 1], a[M + 5][M + 5], f[(1 << M) + 5], g[(1 << M) + 5][M + 5]; int main() { memset(a, 0, sizeof(a)); memset(f, 0x3f, sizeof(f)); memset(g, 0, sizeof(g)); cin >> n >> m >> s; ... |
#include <bits/stdc++.h> using namespace std; long long dp[31][31][51]; void Cal() { for (int i = 0; i <= 30; i++) for (int j = 0; j <= 30; j++) for (int k = 0; k <= 50; k++) { dp[i][j][k] = (k == 0 || k == i * j) ? 0 : 10000000000000000; for (int kk = 0; kk <= k; kk++) { ... |
#include <bits/stdc++.h> using namespace std; int main() { int m, n; cin >> m; int a[m]; for (int i = 0; i < m; i++) { a[i] = 0; } cin >> n; int p = 0, q = 0, r = 0; for (int i = 0; i < n; i++) { cin >> p; cin >> q; cin >> r; a[p - 1] -= r; a[q - 1... |
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10; vector<pair<long long, long long> > v[3]; vector<pair<long long, int> > segment[3]; struct matrix { int arr[3][3]; matrix(array<int, 3> a1, array<int, 3> a2) { for (int i = 0; i <= 2; i++) { for (int j = 0; j <= 2; ... |
#include <bits/stdc++.h> using namespace std; long long co[100]; int main() { long long a, l = 0; long long ans = 1; cin >> a; while (a > 1) { long long c = 0; for (int s = 2; s <= sqrt(a); s++) { if (a % s == 0) { a /= s, co[l] = s, l++, c = 1; break; ... |
#include <bits/stdc++.h> using namespace std; int main() { int n, d, ans = 0; scanf( %d%d , &n, &d); int maxi, t, l; scanf( %d , &maxi); for (int i = 1; i < n; i++) { scanf( %d , &t); if (t > maxi) { maxi = t; continue; } else { l = (int)ceil((maxi + 1 -... |
#include <bits/stdc++.h> using namespace std; const int N = 1e5, M = 1e5; int dfn, cur[M + 1], in[N + 1], pre[N + 1], fin[N + 1], r[N + 1], sz[N + 1]; vector<int> adj[N + 1]; int dfs(int u, int a) { sz[u] = 1; r[u] = a; pre[u] = ++dfn; for (auto v : adj[u]) sz[u] += dfs(v, a); fin[u] = ++d... |
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1.0); const int INF = 1000 * 1000 * 1000 + 7; const long long LINF = INF * (long long)INF; const int MAX = 2 * 1000 * 100 + 47; struct Item { int a, t, ind; bool operator<(const Item& a) const { return t < a.t; } }; Item A[MAX... |
#include <bits/stdc++.h> using namespace std; double a, b, c, d; int main() { scanf( %d%d%d%d , &a, &b, &c, &d); printf( %.12lf n , a / b / (1 - (1 - a / b) * (1 - c / d))); } |
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 7; int n, p[N]; deque<pair<int, int> > deq; bool mrk[N]; vector<int> dor[2]; int dfs(int v, int d) { mrk[v] = 1; if (!mrk[p[v]]) return dfs(p[v], d + 1); return d; } void add(int v, int l) { dor[l].clear(); int pnt =... |
#include <bits/stdc++.h> using namespace std; const int N = 200001; int MAX[N]; vector<int> A[N]; int main() { ios::sync_with_stdio(false); set<pair<int, int> > S; int n; cin >> n; for (int i = 0; i < n; i++) { int u, v; cin >> u >> v; MAX[u] = v; A[u].push_back(v);... |
#include <bits/stdc++.h> using i64 = long long; using u64 = unsigned long long; using u32 = unsigned; int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); int n; std::cin >> n; std::vector<int> c0(n, 0); std::vector<int> c1(n, 0); for (int i = 0; i < n; i++) { ... |
#include <bits/stdc++.h> using namespace std; struct compare { bool operator()(const std::string& first, const std::string& second) { return first.size() > second.size(); } }; int main() { ios_base::sync_with_stdio(false); int n, k, i; cin >> n >> k; string arr[110]; for (i = 0... |
#include <bits/stdc++.h> using namespace std; int main() { string s[10] = { O-|-OOOO , O-|O-OOO , O-|OO-OO , O-|OOO-O , O-|OOOO- , -O|-OOOO , -O|O-OOO , -O|OO-OO , -O|OOO-O , -O|OOOO- }; string num; while (cin >> num) { int i = num.size(); while (i--) cout << s[n... |
#include <bits/stdc++.h> using namespace std; long long n, k; int main() { cin >> n >> k; cout << (n + k - n % k); return 0; } |
#include <bits/stdc++.h> using namespace std; const long long INF = 1e9 + 7; const int N = 2e5 + 10; int a[N]; int main() { string str; string s; while (cin >> s) str += s; for (auto& c : str) { if (c == < ) c = ; if (c == > ) c = ; } vector<string> vs; vector<i... |
#include <bits/stdc++.h> using namespace std; int N; char field[110][110]; bool check_solution(bool do_print, bool swapped) { for (int r = 0; r < N; ++r) { int c; for (c = 0; c < N; ++c) { if (field[r][c] == . ) break; } if (c == N) return false; if (do_print) { ... |
#include <bits/stdc++.h> using namespace std; struct nade { int pos, tag, sum, l, r; } tree[600005 * 2]; int n; void puup(int x) { if (tree[x * 2].sum > tree[x * 2 + 1].sum) { tree[x].pos = tree[x * 2].pos; tree[x].sum = tree[x * 2].sum; } else { tree[x].pos = tree[x * 2 + 1].pos... |
#include <bits/stdc++.h> using namespace std; using lld = long long int; int n, m; int a[200009]; int b[200009]; int c[420009]; int main() { int t = 1, tv = 0; int i, j, k; scanf( %d , &t); while (t--) { scanf( %d %d , &n, &m); b[0] = 0; bool nom = true; for (i = 0;... |
#include <bits/stdc++.h> using namespace std; const int maxn = 100500; const int infi = (1 << 30); const long long infl = (1LL << 62); const double eps = 1e-9; const long long mod = 1000000007LL; const double pi = acos(-1.0); int n, k; int a[maxn], c[maxn]; int main() { cin >> n >> k; for (i... |
#include <bits/stdc++.h> using namespace std; vector<int> divs[1000009]; bool p[1000009]; vector<int> primes; void pre() { for (int i = 2; i <= (1000000); ++i) { if (!p[i]) { primes.push_back(i); for (int j = i; j <= 1000000; j += i) divs[j].push_back(i), p[j] = true; } } ... |
#include <bits/stdc++.h> using namespace std; class Solution { public: long long count(long long _m, long long _x) { if (_m < 3) { return max(0LL, _m); } m = _m; x = _x; vector<pair<long long, int>> cnts = factorize(m); long long res = 0; search(0, 1, cnts, r... |
#include <bits/stdc++.h> using namespace std; using ll = long long; ll dx[] = {0, 0, 1, -1}; ll dy[] = {1, -1, 0, 0}; void solve() { ll n; cin >> n; vector<ll> v(n); for (ll i = 0; i < (n); ++i) cin >> v[i]; vector<pair<ll, ll>> aux(n); ll i = n - 1; stack<ll> s; while (i >= 0)... |
#include <bits/stdc++.h> using namespace std; int n, i; double p[2], poly[100005][2], minD = 1e18, maxD = 0, d, answer, lo, hi, EPS = 1e-12, mid1, mid2, x, y, d1, d2; int main() { scanf( %d %lf %lf , &n, &p[0], &p[1]); for (i = 0; i < n; i++) { scanf( %lf %lf , &pol... |
#include <bits/stdc++.h> using namespace std; const int N = 1010; void solve() { int n, m; cin >> n >> m; vector<vector<long long>> a = vector<vector<long long>>(n, vector<long long>(m, 0)); for (int i = 0; i < n; ++i) for (int j = 0; j < m; ++j) cin >> a[i][j]; vector<long long>... |
#include <bits/stdc++.h> using namespace std; const long long inf = 1LL << 60; const long long md = 1e9 + 7; const long double eps = 1e-14; const int mx = 3010; int t[mx]; void upd(int p) { for (++p; p < mx; p += p & -p) ++t[p]; } int que(int p) { int res = 0; for (; p > 0; p -= p & -p) re... |
#include <bits/stdc++.h> unsigned long long val(int i) { return i + 1; } unsigned long long pot1[100001], pot2[100001], prec1[10][100001], prec2[10][100001]; int v[100000]; struct Node { unsigned long long h1, h2; int flag; bool valid; int sz; Node() { sz = h1 = h2 = 0; fla... |
#include <bits/stdc++.h> using namespace std; const int N = 100005, M = 500005; vector<int> gr[N], path, odd; pair<int, int> ed[M]; bool us[M]; void GetEulerCircuit(int u) { while (true) { while (!gr[u].empty() && us[gr[u].back()]) { gr[u].pop_back(); } if (gr[u].empty()) { ... |
#include <bits/stdc++.h> using namespace std; template <typename T> inline void read(T &x) { x = 0; T f = 1; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == - ) f = -1; for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + (c ^ 48); x *= f; } int main() { ... |
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6; int q[maxn], fin, razbeg, jump, n; pair<int, int> ans[maxn]; int sz = 0; int main() { cin >> n >> fin >> razbeg >> jump; for (int i = 0; i < n; i++) cin >> q[i]; q[n] = 0; q[n + 1] = fin; n += 2; sort(q, q + n); ... |
#include <bits/stdc++.h> using namespace std; long long n, q, c[100005], v[100005], f[100005]; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> q; for (int i = 1; i <= n; i++) cin >> v[i]; for (int i = 1; i <= n; i++) cin >> c[i]; while (q--) { long long... |
#include <bits/stdc++.h> using namespace std; int a[4010][4010]; int n, m; int u[4010], v[4010], sz[4010]; int main() { scanf( %d%d , &n, &m); for (int i = 1; i <= m; i++) { scanf( %d%d , &u[i], &v[i]); a[u[i]][v[i]] = a[v[i]][u[i]] = 1; sz[u[i]]++; sz[v[i]]++; } int an... |
#include <bits/stdc++.h> using namespace std; const int MAXK = 26; const long long MOD = 1e9 + 7; int last[MAXK], ord[MAXK]; long long sum, dp[MAXK]; void add(int c) { sum = (sum - dp[c] + MOD) % MOD; dp[c] = (dp[c] + sum + 1) % MOD; sum = (sum + dp[c]) % MOD; } int main() { ios_base::sy... |
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize( Ofast ) const int INF = 1e9 + 7; const long long INF2 = 1e15; void solve(void) {} int main(void) { ios_base::sync_with_stdio(false); cin.tie(NULL); long long n, l, r, ql, qr; cin >> n >> l >> r >> ql >> qr; vector<long l... |
#include <bits/stdc++.h> using namespace std; using namespace std; int main() { int n, k, q; cin >> n >> k >> q; vector<long long> vec(n + 1); vector<long long> pq; map<long long, long long> ar, ans, rev; for (int i = 1; i <= n; i++) cin >> vec[i], ar[i] = vec[i], rev[vec[i]] = i; whil... |
#include <bits/stdc++.h> using namespace std; inline int lowbit(int x) { return x & -x; } inline int ABS(int x) { return x < 0 ? -x : x; } inline long long ABS(long long x) { return x < 0 ? -x : x; } inline void MAX(int &a, int b) { if (b > a) a = b; } inline void MAX(long long &a, long long b) { ... |
#include <bits/stdc++.h> using namespace std; const long long INF = 9223372036854775807; const long long MOD = 1000000007; const long double PI = acos(-1); inline long long power(long long a, long long b, long long z = MOD) { long long res = 1; a = (a % z); while (b) { if (b & 1) res = (res ... |
#include <bits/stdc++.h> using namespace std; int main() { map<char, int> mp; mp[ q ] = 9; mp[ k ] = 0; mp[ r ] = 5; mp[ b ] = 3; mp[ n ] = 3; mp[ p ] = 1; int white = 0, black = 0; for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) { char x; cin >> x... |
#include <bits/stdc++.h> using namespace std; const int MAXN = 20; long long int dp[MAXN][MAXN]; long long int tav[MAXN]; long long int n; string s; long long int dtoc(char x) { return x - 0 ; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); tav[0] = 1; for ... |
#include <bits/stdc++.h> using namespace std; int v[300123], n, ans, g[300123], f[300123], a, b, m, op; queue<int> q; int main() { ios_base::sync_with_stdio(0); cin >> n; for (int i = 1; i <= n; ++i) { cin >> v[i]; if (~v[i]) g[v[i]]++; else { g[0]++; } } ... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t; cin >> t; for (int i = 0; i < t; i++) { int x; cin >> x; int ans = (x % 10 - 1) * 10; ans += 1; if (x / 10 > 0) ans += 2; if (x / 100 >... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(NULL); cin.tie(0); cout.tie(0); int t; cin >> t; while (t--) { int a, b, c, m; cin >> a >> b >> c >> m; int len = a + b + c; int maxi = len - 3; int valMax = max(a, max(b, c)); ... |
#include <bits/stdc++.h> using namespace std; template <typename A, typename B> ostream &operator<<(ostream &os, const pair<A, B> &p) { return os << ( << p.first << , << p.second << ) ; } template <typename T_container, typename T = typename enable_if< !is_same<... |
#include <bits/stdc++.h> using namespace std; inline int in() { int x; scanf( %d , &x); return x; } const int N = 1e6 + 7; int n, m, a[N], Q; long long SUM, psr[N], psl[N]; int en[N], st[N]; pair<int, long long> dpl[N], dpr[N]; int solve(long long maax) { if (maax >= SUM) return 1; ... |
#include <bits/stdc++.h> using namespace std; int a[1005][1005], used[1005][1005]; const int dx[4] = {0, 0, 1, -1}; const int dy[4] = {1, -1, 0, 0}; void DFS(int i, int j, int N, int M) { if (i == 0 || i == N + 1 || j == 0 || j == M + 1 || used[i][j]) return; used[i][j] = 1; for (int d = 0; d < 4;... |
#include <bits/stdc++.h> using namespace std; template <typename T> T scani(T &n) { n = 0; bool negative = false; char c = getchar(); while (c < 0 || c > 9 ) { if (c == - ) negative = true; c = getchar(); } while (c >= 0 && c <= 9 ) { n = n * 10 + c - 48; c =... |
#include <bits/stdc++.h> using namespace std; template <class T> inline bool uin(T& a, T b) { return a > b ? (a = b, true) : false; } template <class T> inline bool uax(T& a, T b) { return a < b ? (a = b, true) : false; } const int nax = 5123; pair<int, int> edge[nax]; vector<int> g[nax]; ... |
#include <bits/stdc++.h> using namespace std; int n, m, mid, rt, res, a[200010], f[200010], sz[200010]; vector<int> e[200010]; void dfs(int u, int fa) { f[u] = sz[u] = 1; int m1 = 0, m2 = 0; for (auto v : e[u]) { if (v == fa) continue; dfs(v, u); sz[u] += sz[v]; if (f[v] == s... |
#include <bits/stdc++.h> using namespace std; bool used[10000005]; int ans[105]; bool comp(pair<pair<int, int>, int> a, pair<pair<int, int>, int> b) { if (a.first.second == b.first.second) return a.first.first < b.first.first; return a.first.second < b.first.second; } void solve() { int N; c... |
#include <bits/stdc++.h> using namespace std; const long long MAXN = 200100, M = 1000000009; string s; long long n, ans = 0, a[MAXN], b[MAXN]; void obra(long long v) { long long tc = 0, k = a[v]; for (long long i = 0; i < n; i++) { b[i] = a[i] + k / n; if (i == v) b[i] -= a[i]; } k... |
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; long long arr[n]; for (int i = 0; i < n; i++) scanf( %lld , &arr[i]); map<long long, int> mp; long long sum = 0; for (int i = n - 1; i >= 0; i--) { sum += arr[i]; mp[sum] = i; } long long ans ... |
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); } template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); } template <typename T> T inf; template <> con... |
#include <bits/stdc++.h> using namespace std; vector<int> childs[100000 + 1]; long long s[100000 + 1]; int p[100000 + 1]; long long a[100000 + 1]; bool flag = false; void fill(int v, long long prevsum) { if (s[v] != -1) { a[v] = s[v] - prevsum; if (a[v] < 0) flag = true; for (int i =... |
#include <bits/stdc++.h> using namespace std; string a, b; int i, ax, ay, bx, by; int main() { cin >> a >> b; for (i = 0; i < a.length(); i++) if (a[i] == 1 ) ax++; else ay++; for (i = 0; i <= b.length(); i++) if (b[i] == 1 ) bx++; else by++;... |
#include <bits/stdc++.h> #pragma comment(linker, /STACK:200000 ) const int INF = 1e9 + 7; const double EPS = 1e-6; const double pi = acos(-1); const int MOD = 1e9 + 7; const int N = 1e5 + 1000; using namespace std; double mid; struct node { int pos, val; node() { pos = val = 0; } node(int... |
#include <bits/stdc++.h> using namespace std; int n, m, x, y; int b[1005], a[1005]; int F1[1005], F2[1005]; int main() { char ch; cin >> n >> m >> x >> y; for (int i = 1; i <= n; ++i) for (int j = 1; j <= m; ++j) { cin >> ch; if (ch == # ) b[j]++; } for (int i = 1;... |
#include <bits/stdc++.h> using namespace std; int n, k, op; string tes; int main() { cin >> n >> k >> ws >> tes; op = 0; for (int i = 1; i < n; i++) if (tes.substr(0, i) == tes.substr(n - i, i)) op = i; cout << tes; tes = tes.substr(op, tes.length()); for (int i = 1; i < k; i++) co... |
#include <bits/stdc++.h> using namespace std; char x[100100]; long x2[100100]; long mes[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; long wr = 0; long res, cur, repsmax = -1; long reps = 0; long tmp1, tmp2, tmp3; string s1; int compare(const void *a, const void *b) { return (*(long *)a... |
#include <bits/stdc++.h> using namespace std; const int N = 100005; int n, m; vector<pair<int, int> > e[N]; vector<int> ans[2]; bool fla[2], flag; int E[N], d[N]; vector<int> cnt[2]; void DFS(int first, int o, int res) { if (flag) return; d[first] = o; cnt[o].push_back(first); for (aut... |
#include <bits/stdc++.h> using namespace std; class BLongtailHedgehog { public: int N, M; vector<int> dist, deg_in, deg; vector<vector<int>> G; void input(std::istream& in, std::ostream& out) { ios_base::sync_with_stdio(false); in >> N >> M; dist = vector<int>(N, -1); deg_... |
#include <bits/stdc++.h> using namespace std; void hi() { static long long i = 0; cout << Check Point : << ++i << n ; return; } signed main() { ios::sync_with_stdio(0); cin.tie(0); long long t; t = 1; while (t--) { string str; cin >> str; long long n = str.... |
#include <bits/stdc++.h> using namespace std; const int N = 400010; int gcds[N], a[N], b[N]; int c[N], mx[N]; int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } int main() { int n; scanf( %d , &n); for (int i = 1; i <= n; i++) { scanf( %d , &a[i - 1]); gcds[i] = gcd(i, n); }... |
#include <bits/stdc++.h> using namespace std; int a[23][23]; char s[23][23]; int dp[1 << 23]; int n, m; int cost[23][23]; int st[23][23]; int main() { scanf( %d%d , &n, &m); for (int i = 0; i < n; i++) scanf( %s , s[i]); for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) scanf( %d... |
#include <bits/stdc++.h> long long int a[300000]; int main() { long long int n, i, hei, bai; while (scanf( %lld , &n) != EOF) { hei = bai = 0; for (i = 0; i < n; i++) { scanf( %lld , &a[i]); if (i % 2) { hei += (a[i] + 1) / 2; bai += a[i] / 2; } else {... |
#include <bits/stdc++.h> using namespace std; const int INF = INT_MAX; const long long INFL = LLONG_MAX; const int output_precision = 15; const long double pi = acos(-1); const bool debug = true; int N; int A[5]; int check() { vector<int> B(4); for (int(i) = 1, j1234 = 4; (i) <= j1234; (i)++) ... |
#include <bits/stdc++.h> using namespace std; void islam() { ios::sync_with_stdio(false); cin.tie(NULL); } void get(long long &x) { cin >> x; } class ghost { public: ghost() { get(n); for (int i = 0; i < n; i++) { get(arr[i]); s += arr[i]; } s /= n; }... |
#include <bits/stdc++.h> using namespace std; bool isAscending(const vector<int64_t>& vec) { for (int i = 1; i < vec.size(); ++i) { if (vec[i - 1] >= vec[i]) { return false; } } return true; } bool Requal(const vector<int64_t>& av, const vector<int64_t>& bv) { for (int i = 0;... |
#include <bits/stdc++.h> using namespace std; int n, i, j, k, l, m, t; int a[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; int main() { cin >> m >> t; a[m] -= 7 - t + 1; if (a[m] % 7 == 0) { cout << a[m] / 7 + 1; } else { cout << a[m] / 7 + 2; } } |
#include <bits/stdc++.h> using namespace std; queue<int> fila; struct G { double d; int m, p, r; } g[250002]; bool mk[250002]; int a2[9000000]; bool cmp2(int a, int b) { return g[a].d < g[b].d; } int pos = 0; int ind = 0; struct T { int m; int* e; void pdt(int a, int* b) { m = a,... |
#include <bits/stdc++.h> using namespace std; int run(int n) { int i, a[n]; for (i = 0; i < n; i++) cin >> a[i]; sort(a, a + i); int ans = 0; int tempCount = 0; for (i = 0; i < n; i++) { tempCount++; if (a[i] == tempCount) { ans++; tempCount = 0; } } ... |
#include <bits/stdc++.h> using namespace std; int main() { long long n, s = 1; char a; string b[10], c; cin >> n; b[0] = ; b[1] = ; b[2] = 2 ; b[3] = 3 ; b[4] = 322 ; b[5] = 5 ; b[6] = 53 ; b[7] = 7 ; b[8] = 7222 ; b[9] = 7332 ; int k = 0; ... |
#include <bits/stdc++.h> using namespace std; int main() { int t, n, k; cin >> t; while (t--) { cin >> n >> k; for (int i = 0; i < n; ++i) cout << (char)(i % k + a ); cout << endl; } return 0; } |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.