func_code_string stringlengths 59 71.4k |
|---|
#include <bits/stdc++.h> using namespace std; int n, m, r1, c1, r2, c2; char a[120][120]; int main() { cin >> n >> m; bool sign = true; for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) cin >> a[i][j]; for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) if (a[i]... |
#include <bits/stdc++.h> using namespace std; using namespace std; const long long MOD = 1e9 + 7; const int INF = 1e9; template <class T> inline T gcd(T a, T b) { if (a < 0) return gcd(-a, b); if (b < 0) return gcd(a, -b); return (b == 0) ? a : gcd(b, a % b); } template <class T> inline T ... |
#include <bits/stdc++.h> using namespace std; int dx[] = {-1, 0, 1, 0}; int dy[] = {0, 1, 0, -1}; vector<int> f, col, wlk; int Find(int a) { if (f[a] == a) return a; int fa = Find(f[a]); f[a] = fa; return fa; } void Union(int a, int b) { int fa = Find(a); int fb = Find(b); if (... |
#include <bits/stdc++.h> using namespace std; long long A[200010], sz[200010], v[200010][11]; vector<long long> l[11]; class Timer { private: using clock_t = std::chrono::high_resolution_clock; using second_t = std::chrono::duration<double, std::ratio<1> >; std::chrono::time_point<clock_t> m_beg;... |
#include <bits/stdc++.h> using namespace std; inline int read() { char c = getchar(); int x = 0, f = 1; for (; !isdigit(c); c = getchar()) if (c == - ) f = -1; for (; isdigit(c); c = getchar()) x = x * 10 + c - 0 ; return x * f; } const int MAXN = 3e2 + 5; const int MAXQ = 2e6 + 5;... |
#include <bits/stdc++.h> using namespace std; mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); long long int myRand(long long int B) { return (unsigned long long)rng() % B; } struct UnionFind { vector<int> par, num; vector<bool> done; UnionFind(int n) : par(n), num(n, 1), done... |
#include <bits/stdc++.h> using namespace std; int n; string S; long long dp[222][222]; long long GetAnswer(int pos, int numdigs) { if (pos == S.size()) { if (numdigs == 0) return 0; else return -1; } if (numdigs == 0) return -1; if (dp[pos][numdigs] != -2) return dp... |
#include <bits/stdc++.h> using namespace std; int32_t main() { int n, h; cin >> n >> h; vector<int> v(n); for (int i = 0; i < n; i++) cin >> v[i]; int lo = 0; int hi = n - 1; int ans, mid; while (lo <= hi) { mid = lo + (hi - lo) / 2; vector<int> a(mid + 1); for (int... |
#include <bits/stdc++.h> using namespace std; int n, flag, ln, prv = -1; char in[100010][20], pr[100010][20]; int main() { scanf( %d , &n); for (int i = 0; i < n; i++) { scanf( %s , in[i]); ln = strlen(in[i]); flag = 0; if (ln < prv) { printf( NO n ); return 0; ... |
#include <bits/stdc++.h> using namespace std; using ll = long long; using pi = pair<int, int>; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout << setprecision(15) << fixed; int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; i++) cin >> a[i]; sort(a.be... |
#include <bits/stdc++.h> using namespace std; const int MAXL = 5e5 + 1e3; int n, t; char dat[MAXL + 1]; int main() { int n; while (scanf( %d%d%s , &n, &t, dat) >= 1) { int hl = n, hr = -1, hcnt = 0; vector<int> shops; for (int i = 0; i < n; i++) if (dat[i] == H ) { ... |
#include <bits/stdc++.h> using namespace std; const int MAXN = 3e5 + 5; const int INF = 1e9; int N, p[MAXN], tag[MAXN << 2]; long long ans; struct node { int mn, cnt; node(int mn = 0, int cnt = 0) : mn(mn), cnt(cnt) {} friend node operator+(const node& l, const node& r) { if (l.mn < r.mn) ... |
#include <bits/stdc++.h> using namespace std; long long n, q, a[300010], f[300010], ans[300010], g[300010]; struct edge { long long v, next; } e[300010 << 1]; long long eid, p[300010]; void insert(long long u, long long v) { e[++eid] = {v, p[u]}; p[u] = eid; } long long dep[300010], cnt, c[3... |
#include <bits/stdc++.h> using namespace std; int main() { string s1, s2; cin >> s1; cin >> s2; int arr[27] = {}; int a[27] = {}; string s = ; for (int i = 0; i < s1.length(); i++) { arr[int(s1[i]) - 97]++; } int count1 = 0; for (int i = 0; i < s2.length(); i++) { ... |
#include <bits/stdc++.h> using namespace std; void solve(int a[], int n) { int cnt = 0, pos = 0; while (pos < n) { cnt++; int mx = pos; while (pos < n && pos <= mx) { mx = max(mx, a[pos]); pos++; } } cout << cnt << endl; } int main() { int n; cin >... |
#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; int main() { string a, b; cin >> a >> b; if (a == b) { cout << a << n ; } else cout << 1 n ; return 0; } |
#include <bits/stdc++.h> struct DSU { long long M[400005]; DSU(long long n) { for (long long i = 0; i < n; i++) { M[i] = i; } } long long find(long long x) { while (M[x] != x) { long long p = M[x]; M[x] = M[p]; x = p; } return x; } ... |
#include <bits/stdc++.h> const int N = 2e5; using namespace std; const int SIZE = 26; int tot = 0, sub = 0; struct node { node* next[SIZE]; int strings; int tin, tout; node() { for (int i = 0; i < SIZE; i++) { next[i] = nullptr; } tin = 0; tout = 0; string... |
#include <bits/stdc++.h> using namespace std; inline void setmin(int &x, int y) { if (y < x) x = y; } inline void setmax(int &x, int y) { if (y > x) x = y; } inline void setmin(long long &x, long long y) { if (y < x) x = y; } inline void setmax(long long &x, long long y) { if (y > x) x =... |
#include <bits/stdc++.h> using namespace std; long long modPow(long long a, long long b, long long m) { if (b == 0) return 1; if (b % 2 == 0) { long long x = a * a; x %= m; return modPow(x, b / 2, m); } return (a * modPow(a, b - 1, m)) % m; } int main() { ios_base::sync_wit... |
#include <bits/stdc++.h> using namespace std; long long g, t; long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } int main() { int n; long long Max = 0; cin >> n; for (int i = 0; i < n; i++) { cin >> t; if (i) g = gcd(g, t); else g = t... |
#include <bits/stdc++.h> using namespace std; int n, T, a[200010], x, y, d[200010], q[200010], l, r; vector<int> v[200010], Q; int main() { scanf( %d , &T); while (T--) { scanf( %d , &n); for (int i = 1; i <= n; i++) scanf( %d , &a[i]), a[i] = 2 - a[i], v[i].clear(); for (int i... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); ; int t, n; string s, p; cin >> t; while (t--) { cin >> n; cin >> s; for (int j = 0; j < (2 * n - 1); j += 2) { cout << s[j]; } cout << n ; ... |
#include <bits/stdc++.h> using namespace std; int dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0}; void solve() { int n; cin >> n; int a[n + 1]; for (int i = 0; i < n; i++) { int x; cin >> x; a[x] = i; } int l = 0, r = n - 1; for (int i = n; i > 0; i--) { if (a[i] ==... |
#include <bits/stdc++.h> const int MAXN = 2e5 + 10; int n; int a[MAXN], b[MAXN]; namespace bit { int a[MAXN]; void init() { std::fill(a + 1, a + n + 1, 0); } void add(int x, int y) { for (; x <= n; x += x & (-x)) { a[x] += y; } } int query(int x) { int ans = 0; for (; x > 0; x -=... |
#include <bits/stdc++.h> using namespace std; const int MAXN = int(1e4) + 4; int a[MAXN], h[MAXN], c[MAXN]; int n; int main() { scanf( %d , &n); for (int i = 1; i <= n; ++i) { scanf( %d , &a[i]); h[i] = a[i]; int j = i - 1; while (h[j] > h[i] && j > 0) { h[i] += a[j]; ... |
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize( Ofast ) #pragma GCC target( avx,avx2,fma ) const int N = 2e5 + 3; const int MOD = 998244353; int max1 = 0, max2 = 0; void solve() { long long int a[3]; cin >> a[0] >> a[1] >> a[2]; sort(a, a + 3); cout << (a[0] + a[1] + mi... |
#include <bits/stdc++.h> using namespace std; vector<int> cc[100000]; int num[100000]; int main() { int n, k, m; cin >> n >> k >> m; for (int j = 0; j < n; cin >> num[j++]) ; sort(num, num + n); for (int j = 0; j < m; cc[j++].clear()) ; cc[0].push_back(0); for (int j = 1;... |
#include <bits/stdc++.h> using namespace std; const int maxn = 31; const int mod = 1000000007; struct ma { long long a[maxn][maxn]; int n; ma(int m = 0) { n = m; memset(a, 0, sizeof(a)); for (int i = 0; i < n; i++) a[i][i] = 1; } ma(const ma& nn) { n = nn.n; mem... |
#include <bits/stdc++.h> using namespace std; const int mod = (int)1e9; const long long inf = (long long)3e18; const int base = 1000 * 1000 * 1000; const int maxn = 20; const long double pi = acosl(-1.0); const long double eps = 1e-5; void error() { exit(1); } int n; bool flag = true; long long A,... |
#include <bits/stdc++.h> const int MAXN = 1000001; int n, m, a[MAXN], b[MAXN]; int box[MAXN], axi[MAXN]; int n1, n2; int main() { std::cin >> n >> m; for (int i = 1; i <= n; i++) { std::scanf( %d , a + i); if (a[i] <= m) { b[++n1] = a[i]; box[a[i]]++; } } if (... |
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 100; const int mod = 1e9 + 7; mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count()); int n, trie[maxn][26], en[maxn], nxt; string s; void ins(int cur, int i) { if (i == (int)s.size()) en[cur] = 1; els... |
#include <bits/stdc++.h> using namespace std; const int MAX = 2e5 + 10; long long arr[MAX], arr2[MAX]; int n; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n; for (int i = 0; i < n; ++i) cin >> arr[i]; for (int i = 0; i < n; ++i) cin >> arr2[i]; vector<pair<long long, l... |
#include <bits/stdc++.h> using namespace std; using ld = long double; ld sq(ld x) { return x * x; } int main() { size_t n; cin >> n; vector<ld> mn(n), mx(n), mnk(n), mxk(n); for (size_t i = 0; i != n; ++i) { cin >> mx[i]; } for (size_t i = 0; i != n; ++i) { cin >> mn[i]; ... |
#include <bits/stdc++.h> using namespace std; template <int M> struct static_mint { static_assert(0 < M, Module must be positive ); int val; static_mint() : val() {} static_mint(long long x) : val(x % M) { if (val < 0) val += M; } static_mint pow(long long n) const { static_mi... |
#include <bits/stdc++.h> using namespace std; template <typename A, typename B> string to_string(pair<A, B> p); template <typename A, typename B, typename C> string to_string(tuple<A, B, C> p); template <typename A, typename B, typename C, typename D> string to_string(tuple<A, B, C, D> p); string to_str... |
#include <bits/stdc++.h> using namespace std; long long MOD = 1000000007; long long binary_exp(long long a, long long b) { long long ans = 1; while (b > 0) { if (b & 1) { ans = (ans * a); } a = (a * a); b = b >> 1; } return ans; } int fn(int low, vector<int> &a,... |
#include <bits/stdc++.h> using namespace std; const long long inf = 1e18; const long long M = 1e9 + 9; long long axm(long long a, long long x, long long m) { a %= m; long long r = 1; while (x > 0) { if (x & 1) r = r * a % m; a = a * a % m; x /= 2; } return r; } long lon... |
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1.0); const int inf = (int)1e9; const long long int infll = (long long int)1e18; const double inf1 = 1e-9; const int ss = (int)1e6 + 3; const int base = inf; bool pred(const pair<int, int>& i, const pair<int, int>& j) { if (i.firs... |
#include <bits/stdc++.h> using namespace std; int main() { int x, y, a, b; scanf( %d %d %d %d , &x, &y, &a, &b); int minV = max(a, b + 1); int maxP = min(y, x - 1); vector<pair<int, int> > output; int total = 0; for (int v = minV; v <= x; v++) { for (int p = b; p <= min(v - 1, maxP... |
#include <bits/stdc++.h> using namespace std; long long A[1 << 20]; long long B[1 << 20]; long long getIP() { int a[4]; scanf( %d.%d.%d.%d , &a[0], &a[1], &a[2], &a[3]); int i; long long res = 0; for (i = (0); i < (4); ++i) res = (res << 8) | a[i]; return res; } void printIP(long lon... |
#include <bits/stdc++.h> #pragma comment(linker, /stack:200000000 ) #pragma GCC optimize( Ofast ) #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native ) using namespace std; const int mod = 1e9 + 7; const int N = 1e6 + 10; const long long INF = 1e18; const long double EPS = 1e-12... |
#include <bits/stdc++.h> int main() { int x, y, xlast, ylast, n, k, i; double sum = 0.0f; scanf( %d%d , &n, &k); scanf( %d%d , &xlast, &ylast); for (i = 0; i < n - 1; i++) { scanf( %d%d , &x, &y); sum += sqrt(pow((double)x - xlast, 2) + pow((double)y - ylast, 2)); xlast = x; ... |
#include <bits/stdc++.h> using namespace std; const long long md = 1000000007; long long ans, f[2002][2002]; int n, m; inline void solve() { scanf( %d%d , &n, &m); for (register int i = 1; i <= m; ++i) f[1][i] = 1; for (register int i = 2; i <= n; ++i) { int t = 0; f[i][1] = 1; f... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; string s; cin >> s; vector<int> vec(n); vector<int> kactane(30, 0); vector<int> harfmax(30, 0); int res = 0; for (int i = 0; i < n; i++) { in... |
#include <bits/stdc++.h> using namespace std; int main() { string str; cin >> str; if (str.size() % 2 == 1) { cout << No << endl; return 0; } stack<char> sta; for (int i = 0; i < str.size(); i++) { if (!sta.empty() && sta.top() == str[i]) sta.pop(); else ... |
#include <bits/stdc++.h> using namespace std; const double eps = 1.0e-11; const double pi = acos(-1.0); int main() { string s; cin >> s; int n = s.size(); vector<int> points; for (long long i = 0; i < (int)(s).size(); i++) { if (s[i] == . ) { points.push_back(i); } }... |
#include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int, int>; template <typename T, typename S> ostream& operator<<(ostream& os, pair<T, S> a) { os << ( << a.first << , << a.second << ) ; return os; } template <typename T> ostream& operator<<(ostream& os, v... |
#include <bits/stdc++.h> using namespace std; const int MAX_N = 1050; const int MAX_M = 1050; int n, m, q; int matrix[MAX_N][MAX_M]; int l[MAX_M][MAX_N]; int r[MAX_M][MAX_N]; int u[MAX_N][MAX_M]; int d[MAX_N][MAX_M]; void modify(int x, int y) { matrix[x][y] ^= 1; for (int j = 1; j <= m; j++)... |
#include <bits/stdc++.h> using namespace std; int main() { int i, N, minim, maxim; long long M; scanf( %d %I64d , &N, &M); maxim = 0; if (2 * M < N) minim = N - 2 * M; else minim = 0; if (M == 0) maxim = N; else for (i = 1; i <= N; ++i) if (1LL * i * (... |
#include <bits/stdc++.h> using namespace std; long long pred[300005]; long long suffc[300005]; long long ans[300005]; int main() { int n, m; scanf( %d %d , &n, &m); pair<int, int> ara[n]; vector<pair<int, int> > vt(n); for (int i = 0; i < n; i++) { scanf( %d %d , &ara[i].first, &ara[... |
#include <bits/stdc++.h> int main() { long long int n, i, p = 1, k, x = 0, s = 0; scanf( %lld , &n); k = n; while (k != 0) { k = k / 10; x++; } for (i = 1; i <= x - 1; i++) { p = p * 10; } while (x != 0) { s = s + (n - p + 1) * x; n = p - 1; p = p / ... |
#include <bits/stdc++.h> using namespace std; deque<int> d[100005]; int v[100005]; int p[100005]; pair<int, int> q[100005]; int ans = 0; int prog = 0; int as[100005]; unordered_map<int, int> possible[100005]; bool cmp(int a, int b) { if (q[a].first / 300 != q[b].first / 300) return q[a].fi... |
#include <bits/stdc++.h> using namespace std; struct tc { int cnt, count; long long p[5001]; } q[5001]; struct sc { int id; long long num; } anss[200010], s[200010]; void merge(int l, int mid, int r) { int i = l, j = mid + 1; int cc = l; while (i <= mid && j <= r) { if (ans... |
#include <bits/stdc++.h> using namespace std; int32_t main() { long long t; cin >> t; while (t--) { long long n; cin >> n; vector<long long> p(n), m(n); vector<vector<long long>> v(n + 1); for (long long i = 0; i < n; i++) { cin >> m[i] >> p[i]; v[m[i]].push... |
#include <bits/stdc++.h> using namespace std; bool check(int x, int n, vector<int>& a) { vector<int> temp; int i = 0, j = x; int cnt = 0; bool ok = false; while (cnt < n) { if (ok) temp.push_back(a[i]), i++, ok = false; else temp.push_back(a[j]), j++, ok = true; ... |
#include <bits/stdc++.h> int main() { int tc; scanf( %d , &tc); while (tc--) { int n, i, z = -1, o = -1, s = 0, max = -1; scanf( %d , &n); char ss[n + 5], at[2]; scanf( %s , ss); int a[n], b[n], zero[n], one[n]; for (i = 0; i < n; i++) { at[0] = ss[i]; a... |
#include <algorithm> #include <iostream> #include <cstdlib> #include <cassert> #include <cstring> #include <iomanip> #include <cstdio> #include <limits> #include <string> #include <vector> #include <cmath> #include <deque> #include <queue> #include <stack> #include <map> #include <set> u... |
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 9; long long a, b, n, dv[N], l, r, sz; long long bs(long long l, long long r) { long long bas = 0; long long son = sz + 1; while (bas + 1 < son) { long long orta = bas + son >> 1; if (dv[orta] < l) bas = orta; ... |
#include <bits/stdc++.h> using namespace std; int main() { int t, n, ans, i, j, k; cin >> t; for (i = 0; i < t; i++) { cin >> n; int x[2 * n]; for (j = 0; j < 2 * n; j++) cin >> x[j]; sort(x, x + 2 * n); ans = x[n] - x[n - 1]; cout << ans << endl; } return 0; ... |
#include <bits/stdc++.h> const int INF = 1e9 + 7; int ds[100]; int hs[100]; int solve() { int N, X; scanf( %d %d , &N, &X); for (int i = 0; i < N; i++) { scanf( %d %d , &ds[i], &hs[i]); } int last = *std::max_element(ds, ds + N); if (last >= X) return 1; int dec = 0; for (i... |
#include <bits/stdc++.h> using namespace std; struct s_ix { long long ix; long long val; }; bool operator<(s_ix aa, s_ix bb) { return aa.val - aa.ix < bb.val - bb.ix; } int main() { ios::sync_with_stdio(0); cin.tie(0); long long T; cin >> T; while (T--) { long long n, k, nc[2... |
#include <bits/stdc++.h> using namespace std; int main() { int n, s1 = 0, s2 = 0, s3 = 0; cin >> n; int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; if (i % 3 == 0) s1 += a[i]; else if (i % 3 == 1) s2 += a[i]; else s3 += a[i]; } if (s1 >= s... |
#include <bits/stdc++.h> using namespace std; long long strL[200005], patL[200005], n, m, pref[200005], ans, tempL[200005]; char strC[200005], tempC[200005]; vector<long long> endings; string patC = ; long long lenP, lenS; void calcPrefixFunction() { for (long long i = 1, k = 0; i < m - 2; i++) { ... |
#include <bits/stdc++.h> using namespace std; int main() { long long n, g; cin >> n >> g; g %= 4 * n; long long xx, yy; cin >> xx >> yy; long long x[n], y[n]; for (int(i) = int(0); i < int(n); ++i) cin >> x[i] >> y[i]; for (int(i) = int(1); i < int(g + 1); ++i) { long long dx =... |
#include <bits/stdc++.h> using namespace std; struct dat { long long a; long long n; }; bool comp(struct dat a, struct dat b) { return a.a < b.a; } int main() { ios::sync_with_stdio(false); long long a, b, c, i, j, k, l, m, t, x, y, n, z; vector<long long> a1; string s; cin >> n; ... |
#include <bits/stdc++.h> using namespace std; const long long MOD = 998244353; const long long N = 5e3 + 5; long long a[N]; long long pre[N]; long long dp[N][N]; long long n, m, k; long long check = 0; long long go(long long pos, long long kk) { if (kk == k) return 0; if (pos == n + 1) return ... |
#include <bits/stdc++.h> using namespace std; int n; string str; int main() { cin >> n >> str; for (int i = 0; i < str.size(); i++) { if (n % (i + 1) == 0) { for (int j = 0; j <= i / 2; j++) { swap(str[j], str[i - j]); } } } cout << str; } |
#include <bits/stdc++.h> using namespace std; bool deb = false; int i, k, n; const int N = 500011; int a[N]; bool f1(long long int x) { int i; long long int inc = 0, dec = 0; for (i = 0; i < n; ++i) { if (a[i] > x) dec += (a[i] - x); else inc += (x - a[i]); } ... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ; int n; cin >> n; string s; map<string, int> mp; for (int i = 0; i < n; ++i) { cin >> s; mp[s]++; } int ans = 0; for (auto ss : mp) { ans = max(a... |
#include <bits/stdc++.h> const int mx = 2002; const int inf = 1000 * 1000 * 1000; using namespace std; vector<int> adj[mx]; vector<long long> w[mx]; set<pair<long long, int> > s; long long dist[mx]; bool mrk[mx]; void dijkstra() { while (s.size()) { pair<long long, int> p = *s.begin(); ... |
#include <bits/stdc++.h> using namespace std; void DBG() { cerr << ] n ; } template <typename T, typename... Args> void DBG(T first, Args... args) { cerr << first; if (sizeof...(args)) cerr << , ; DBG(args...); } void solve() { long long int x0, y0, ax, ay, bx, by, sx, sy, t; cin >> x... |
#include <bits/stdc++.h> using namespace std; const int maxn = 1000000 + 100; int n, root, u, Sum; int num[maxn], sum[maxn]; vector<int> G[maxn]; int ans1, ans2; void dfs1(int x) { sum[x] = num[x]; int len = G[x].size(); for (int i = 0; i < len; ++i) { int pos = G[x][i]; dfs1(pos);... |
#include <bits/stdc++.h> using namespace std; int a, n, m, mis, cri; int main() { cin >> a; for (int i = 0; i < a; i++) { cin >> n >> m; if (n > m) { mis++; } else if (n < m) { cri++; } } if (mis > cri) { cout << Mishka ; } else if (cri > mis) { ... |
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using ii = pair<int, int>; using vi = vector<int>; using vb = vector<bool>; using vvi = vector<vi>; using vii = vector<ii>; using vvii = vector<vii>; const int INF = 2000000000; const ll LLINF = 90000000000... |
#include <bits/stdc++.h> using namespace std; long long arr[166666][6]; multiset<long long> s[6]; signed main() { long long n; scanf( %lld , &n); for (long long i = 1; i <= n; i++) { for (long long j = 1; j <= 4; j++) { scanf( %lld , &arr[i][j]); s[j].insert(arr[i][j]); }... |
#include <bits/stdc++.h> using namespace std; int main() { string s; long long int k, a[26], i, max = -1, l, sum = 0; cin >> s; cin >> k; l = s.length(); for (i = 0; i < 26; i++) { cin >> a[i]; if (max < a[i]) max = a[i]; } for (i = 0; i < l; i++) { sum = sum + (i +... |
#include <bits/stdc++.h> using namespace std; long long Set(long long N, long long pos) { return N = N | (1 << pos); } long long reset(long long N, long long pos) { return N = N & ~(1 << pos); } bool check(long long N, long long pos) { return (bool)(N & (1 << pos)); } void CI(long long &_x) { scanf( %d , &_x)... |
#include <bits/stdc++.h> using namespace std; template <class T> int len(const T &c) { return (int)c.size(); } template <class T> void cmin(T &a, T b) { if (b < a) a = b; } template <class T> void cmax(T &a, T b) { if (b > a) a = b; } int n; int main() { cin >> n; if (n == 3)... |
#include <bits/stdc++.h> using namespace std; const int N = 200005; vector<int> adj[N]; int sum[N]; void dfs1(int node) { if (adj[node].size() == 0) sum[node] = 1; for (int i = 0; i < adj[node].size(); i++) { int a = adj[node][i]; dfs1(a); sum[node] += sum[a]; } } int mx(int ... |
#include <bits/stdc++.h> #pragma GCC optimize( Ofast,no-stack-protector,unroll-loops ) #pragma GCC optimize( no-stack-protector,fast-math ) #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native ) using namespace std; template <class S, class T> inline S smax(S &l, T r) { return l =... |
#include <bits/stdc++.h> using namespace std; const int dx[] = {-1, 0, 1, 0}; const int dy[] = {0, 1, 0, -1}; int inp[100005]; int main() { int n, a, b; cin >> n; int flag = 0; string str; for (int i = 0; i < n; i++) { cin >> str; int a, b; cin >> a >> b; if (a >= 2... |
#include <bits/stdc++.h> using namespace std; int main() { long long a, b, c, d; cin >> a >> b >> c >> d; long long sum = (a + b + c + d) / 3; if (sum == a) cout << sum - b << << sum - c << << sum - d; else if (sum == b) cout << sum - a << << sum - c << << sum - d; ... |
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> vi; typedef pair<int, int> pi; #define rep(i,k,n) for (int i = k; i < n; ++i) #define repr(i,k,n) for (int i = k; i >= n; --i) int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); #ifnd... |
#include <bits/stdc++.h> using namespace std; long long n, l, r; long long getMin() { long long ret = 0ll; for (long long i = 1, p = 1; i <= min(l, n); i++, p *= 2) { ret += p; } ret += max(0ll, (n - l)); return ret; } long long getMax() { long long ret = 0ll, p = 1ll; for (l... |
#include <bits/stdc++.h> using namespace std; const double eps = 1e-6; void __print(int x) { cerr << x; } void __print(long x) { cerr << x; } void __print(long long x) { cerr << x; } void __print(unsigned x) { cerr << x; } void __print(unsigned long x) { cerr << x; } void __print(unsigned long long x) {... |
#include <bits/stdc++.h> using namespace std; using ll = long long; const ll N = 2e5 + 10; const ll inf = 1e18; const ll MOD = 1e9 + 100; int n; int main() { int t; cin >> t; while (t--) { cin >> n; if (n < 4) printf( -1 n ); else { deque<int> q; q = {... |
#include <bits/stdc++.h> using namespace std; vector<vector<long long> > g; long long vis[200005], w[200005]; long long cycle[200005]; long long taken[200005]; long long s; void dfs(long long x, long long par) { vis[x] = 1; for (long long i = 0; i < g[x].size(); i++) { long long y = g[x][i];... |
#include <bits/stdc++.h> using namespace std; signed main() { ios_base::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector<int> a(n); for (int &i : a) cin >> i; int ans = -1, now = 0; vector<bool> vis(n); while (now < n) { ans++; if (ans % 2) for (int... |
#include <bits/stdc++.h> using namespace std; int n, k, el[101]; set<int> st; int main() { cin >> n >> k; for (int i = 1; i < (int)n + 1; ++i) st.insert(i); set<int>::iterator it = st.begin(), er; for (int i = 0; i < (int)k; ++i) { int a; cin >> a; int ind = ((a) % (int)(st).si... |
#include <bits/stdc++.h> using namespace std; const long long int mod = 1000000007; const long long int inf = 1e18; const long long int N = 1e5 + 5; const long long int M = N; const long long int LG = 19; long long int n, m; long long int tim = 0, grp = 1; long long int u[N], v[N], storecomp[N]; lon... |
#include <bits/stdc++.h> using namespace std; string s; const int MaxN = 2e5 + 10; int endd, vis[MaxN]; int main() { int tt; cin >> tt; while (tt--) { cin >> s; stack<int> sta; for (int i = 0; i < s.size(); i++) { sta.push(s[i]); if (sta.top() == B && sta.size()... |
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) #pragma GCC target( avx,avx2,fma ) #pragma GCC optimization( unroll-loops ) using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); void naive(int x, int y) { if (x == y) { cout << Yes n ; return; }... |
#include <bits/stdc++.h> using namespace std; int main() { int ent; long long int a, b; cin >> ent; while (ent--) { int div = 0, pls = 0; cin >> a >> b; if (a % b == 0) { cout << 0 << endl; continue; } div = a / b; pls = (div + 1) * b; cout <... |
#include <bits/stdc++.h> using namespace std; long long n; double t, ans, x, y; map<pair<double, double>, bool> b; pair<double, double> p[1005]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> t; for (int i = 1; i <= n; i++) { cin >> x >> y; p[... |
#include <iostream> #include <cstdio> #include <cstring> using namespace std; char s[5010]; int n; bool ok(int x,int y,int fx,int fy){ if(x==fx && y==fy)return 0; return 1; } bool check(int fx,int fy){ int x=0,y=0; for(int i=1;i<=n;i++){ if(s[i]== D ){ if(ok(x,y-1,fx,fy))y--; ... |
#include <bits/stdc++.h> using namespace std; int read() { int X = 0, w = 1; char c = getchar(); while (c < 0 || c > 9 ) { if (c == - ) w = -1; c = getchar(); } while (c >= 0 && c <= 9 ) X = X * 10 + c - 0 , c = getchar(); return X * w; } const int N = 125000 + 10; ... |
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { ios_base::sync_with_stdio(false); int N; cin >> N; ll ans = 0; priority_queue<int, vector<int>, greater<int>> q; for (int i = 0; i < N; ++i) { int v; cin >> v; q.emplace(v); q.emplace(v... |
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 10; int ar[maxn], num[maxn]; int main() { int t; cin >> t; while (t--) { int n, m; memset(num, 0, sizeof(num)); memset(ar, 0, sizeof(ar)); cin >> n >> m; string s; cin >> s; for (int i = 1;... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.