func_code_string stringlengths 59 71.4k |
|---|
#include <bits/stdc++.h> using namespace std; int main() { int n, s, sum = 0; cin >> n >> s; int arr[n]; for (int i = 0; i < n; i++) { cin >> arr[i]; } sort(arr, arr + n); for (int i = 0; i < n - 1; i++) { sum += arr[i]; } if (sum > s) cout << NO << endl; ... |
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; cout << 9 * n << << 8 * n << endl; } |
#include <bits/stdc++.h> using namespace std; int main() { long long x, d, count = 0; int n; char a; cin >> n >> x; while (n--) { cin >> a >> d; if (a == + ) { x += d; } else { if (d <= x) x -= d; else count++; } } cout... |
#include <bits/stdc++.h> using namespace std; const int MAXN = 1010; int ar[MAXN][MAXN], star[MAXN][MAXN]; int main() { int n, m, t; char a; cin >> n >> m >> t; for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) { scanf( %c , &a); ar[i][j] = a - 0 ; } for... |
#include <bits/stdc++.h> using namespace std; long long n, mod; long long fast(long long base, long long pow) { long long res = 1; while (pow) { if (pow % 2) res = ((res % mod) * (base % mod)) % mod; pow /= 2; base = ((base % mod) * (base % mod)) % mod; if (!base) base = mod; }... |
#include <bits/stdc++.h> using namespace std; int _c, n, m; int e[70]; long long p[70][70], V, A, B, C, ans, G, F; void dfs2(const long long b, int x) { if (F / b < b) return; if (x > n) { long long c = F / b; if (G * b + b * c + c * G < ans) ans = G * b + b * c + c * G, A = G, B =... |
#include <bits/stdc++.h> using namespace std; const int mod = 1000000000 + 7; int main() { string s; long long n; cin >> n; long long a[n]; for (int i = 0; i < n; ++i) cin >> a[i]; long long x = 0, y = n - 1, z = 0; while (x <= y) { if (max(a[x], a[y]) < z) break; e... |
#include <bits/stdc++.h> using namespace std; int n, s, e; long long dp[5005][5005]; vector<int> x, a, b, c, d; int main() { cin >> n >> s >> e; x.resize(n); a.resize(n); b.resize(n); c.resize(n); d.resize(n); for (int i = 0; i < n; i++) { cin >> x[i]; } for (int i = ... |
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; const ll OO = 1e18; int di[8] = {0, 0, 1, -1, -1, 1, -1, 1}; int dj[8] = {1, -1, 0, 0, 1, 1, -1, -1}; string ys = YES , no = NO ; const long double dgr = acos(-1) / 180, dg = 180 / acos(-1); const int mod = 1... |
#include <bits/stdc++.h> using namespace std; int many; int s[100010]; int a[100010]; int p[100010]; int run(int o) { int zuo = 1; int you = o - 1; int re = -1; int k; while (zuo <= you) { k = (zuo + you) / 2; if (a[k] < s[o]) { re = k; you = k - 1; } el... |
#include <bits/stdc++.h> using namespace std; using ll = long long; using pl = pair<ll, ll>; using vll = vector<ll>; using vpl = vector<pl>; using mat = vector<vll>; const ll MAX = 1e5; const ll mod = 1e9 + 7; template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto... |
#include <bits/stdc++.h> using namespace std; template <class T> void printVector(T begin, T end) { for (auto i = begin; i != end; i++) { cout << *i << ; } cout << endl; } long long readLL() { long long x; cin >> x; return x; } int a[200]; int b[200]; int main() { ... |
#include <bits/stdc++.h> using namespace std; const int maxn = 2710; const double eps = 1e-9; const double pi = 3.1415926536; int dp[maxn][maxn]; string s; int main(int argc, char const *argv[]) { dp[0][0] = 1; for (int i = 1; i <= 100; i++) { for (int j = 0; j <= (i - 1) * 26; j++) { ... |
#include <bits/stdc++.h> namespace mem { namespace stdval { using i32 = int; using i64 = long long; using u32 = unsigned int; using u64 = unsigned long long; using f32 = float; using f64 = double; using i128 = __int128_t; using u128 = __uint128_t; } // namespace stdval namespace utils { using... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long n, v, cost, i; cin >> n >> v; if (v >= (n - 1)) cout << n - 1; else { cost = v; for (i = 2; i <= n; i++) { v--; if ((n - i) <= v) { ... |
#include <bits/stdc++.h> using namespace std; #pragma comment(linker, /stack:200000000 ) int t, n, m, j, ans, k, a, b, c, d, e, f, sum, i, sz, row, col, l; string s, s2, s3, s4; deque<pair<int, int> > v; void brainfuck(); int main() { ios_base::sync_with_stdio(NULL); cin.tie(NULL); cout.tie(N... |
#include <bits/stdc++.h> using namespace std; int s[18257 + 1]; int main() { memset(s, 0, sizeof(s)); s[1] = 1; for (int i = 2; i <= 18257; i++) { s[i] = (2 * i - 3) * 6 + 6; } int a; scanf( %d , &a); if (a == 1) { cout << s[1] << endl; } else { int sum = 0; ... |
#include <bits/stdc++.h> using namespace std; const int MAX_N = 210, MAX_K = 1010, MOD = 1e9 + 7; int N, K, arr[MAX_N], dp[MAX_N][MAX_N][MAX_K]; void add(int& a, long long b) { b %= MOD; a = (a + b) % MOD; } int solve() { sort(arr + 1, arr + N + 1); dp[0][0][0] = 1; for (int i = 1; i <= ... |
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const int mod = 1000000007; const int N = 5e5 + 5; int n, m, q, ans[N]; struct node { int cnt, id; } c[N]; struct ask { int id; long long x; } Q[N]; int st[N << 2]; void update(int o, int l, int r, int pos) { ... |
#include <bits/stdc++.h> using namespace std; char str[1000005]; int num[1000005]; int main() { int i, j, len, ans; while (scanf( %s , str) != EOF) { len = strlen(str); for (i = 0, j = len - 1; i < j; i++, j--) { swap(str[i], str[j]); } str[len] = 0 ; memset(num, 0... |
#include <bits/stdc++.h> using namespace std; vector<int> z; vector<int> pr; vector<vector<int>> ans; int s, f; long long pow(long long n, long long s) { if (s == 0) return 1; else { if (s % 2 == 1) { return (n * (pow(n, s - 1))) % 1000000007; } if (s % 2 == 0) { ... |
#include <bits/stdc++.h> using namespace std; int main() { int i = 0, n; bool ok(false); cin >> n; while (i * (i + 1) / 2 <= n && ok == false) { if (i * (i + 1) / 2 == n) { ok = true; } i++; } (ok == true) ? cout << YES : cout << NO ; return 0; } |
#include <bits/stdc++.h> using namespace std; const int INF = (int)1e9 + 7; template <class X, class Y> void minimize(X &x, const Y &y) { if (x > y) x = y; } template <class X, class Y> void maximize(X &x, const Y &y) { if (x < y) x = y; } vector<int> adj[5050]; int nLeaf[5050]; int f[5050... |
#include <bits/stdc++.h> using namespace std; template <typename T> inline bool chkmin(T &x, T y) { return y < x ? x = y, 1 : 0; } template <typename T> inline bool chkmax(T &x, T y) { return x < y ? x = y, 1 : 0; } const int INF = 0x3f3f3f3f; const int N = 1e2 + 10, Node = 2e3 + 10, Edge = No... |
#include <bits/stdc++.h> using namespace std; using ll = long long; namespace io { const int SIZE = (1 << 21) + 1; char ibuf[SIZE], *iS, *iT, obuf[SIZE], *oS = obuf, *oT = oS + SIZE - 1; inline char getc() { return (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin), (iS ... |
#include <bits/stdc++.h> using namespace std; char sign[1000][1000], cpy[1000][1000]; int n, m; void tryFill(int i, int j) { for (int ii = i - 1; ii <= i + 1; ii++) { for (int jj = j - 1; jj <= j + 1; jj++) { if (i == ii && j == jj) { continue; } if (sign[ii][jj] == ... |
#include <bits/stdc++.h> using namespace std; template <class T, class T2> inline int chkmax(T &x, const T2 &y) { return x < y ? x = y, 1 : 0; } template <class T, class T2> inline int chkmin(T &x, const T2 &y) { return x > y ? x = y, 1 : 0; } const int MAXN = (1 << 20); int n; void read() {... |
#include <bits/stdc++.h> using namespace std; template <typename T1, typename T2> pair<T1, T2> operator+(pair<T1, T2> a, pair<T1, T2> b) { return make_pair(a.first + b.first, a.second + b.second); } template <typename T1, typename T2> pair<T1, T2> operator-(pair<T1, T2> a, pair<T1, T2> b) { return m... |
#include <bits/stdc++.h> using namespace std; signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, l, k; cin >> n >> l >> k; vector<int> cnt(26, 0); for (int i = 0; i < n * l; ++i) { char c; cin >> c; cnt[c - a ]++; } int last = 0; ... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); long long int n, i, m, j, f, k; cin >> n; m = n * n; vector<long long int> v[n]; for (i = m; i >= n; i -= n) { if (f == 0) { k = 0; for (j = i; j > (i - n); j--, k++) { ... |
#include <bits/stdc++.h> using namespace std; const int MAXN = 15e4 + 4; const int MAXQ = MAXN; const int MAXK = 6 + 2; int n, k, q; int t[MAXN]; set<int, greater<int> > st; int main() { scanf( %d%d%d , &n, &k, &q); for (int i = 0; i < n; ++i) scanf( %d , t + i); while (q--) { int op, ... |
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) #pragma GCC target( avx,avx2,fma ) #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native ) using namespace std; using pl = pair<long long, long long>; using vll = vector<long long>; using mll = map<long long, long long>; using ... |
#include <bits/stdc++.h> using namespace std; int main() { long long int n, a, b, i, x, t, rem; cin >> n >> a >> b; for (i = 0; i < n; i++) { cin >> x; t = (x * a) % b; if (t / a >= 1) rem = t / a; else rem = 0; cout << rem << ; } return 0; } |
#include <bits/stdc++.h> using namespace std; void scanint(long long int &x); map<long long int, long long int> vv; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); multiset<long long int> ms; long long int n; scanint(n); long long int a[n]; long long int curr = 1; l... |
#include <bits/stdc++.h> using namespace std; int main() { int n, a, mid, ans = 0; int all[100001]; all[0] = 0; cin >> n; for (int i = 1; i <= n; i++) { cin >> a; all[i] = all[i - 1] + a; } if (all[n] % 2 == 1) { cout << 0; return 0; } mid = all[n] / 2; ... |
#include <bits/stdc++.h> using namespace std; int main() { int t, i; cin >> t; for (int i = 0; i < t; i++) { long long int n; cin >> n; if (n < 4) cout << 4 - n << endl; else { cout << n % 2 << endl; } } return 0; } |
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; inline int add(int x, int y) { x += y; if (x >= mod) x -= mod; return x; } inline int mul(int x, int y) { return ((long long)x) * y % mod; } const int N = 1e6 + 5; int fac[N + 5], ifac[N + 5], p[N + 5]; int Pow(int a, int... |
#include <bits/stdc++.h> using namespace std; long long a[27]; int main() { long long n; string s; cin >> n; cin >> s; long long c = 0, i, d; for (i = 0; i < (2 * n) - 2; i++) { if (s[i] >= a && s[i] <= z ) { d = s[i] - a ; a[d]++; } else { d = s[i] ... |
// Problem: A. Dense Array // Contest: Codeforces - Codeforces Round #702 (Div. 3) // URL: https://codeforces.com/contest/1490/problem/A // Memory Limit: 256 MB // Time Limit: 2000 ms // Powered by CP Editor (https://github.com/cpeditor/cpeditor) #include <bits/stdc++.h> #pragma GCC optimize( Ofast,... |
#include <bits/stdc++.h> using namespace std; string s; struct SUM { int n; bool pp; } b; vector<SUM> a; bool cmp(SUM u, SUM v) { return u.n < v.n; } int main() { std::ios::sync_with_stdio(false); int i, j, k, m; cin >> m >> s; s = s[0] == - ? s : + + s; for (i = 0; i < s.s... |
#include <iostream> #include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--){ //int n; cin >> n; string s; cin >> s; string res = ; for (int i=0;i<s.size();i++){ if (i%2==0){ if (s[i]== a ){ ... |
#include <bits/stdc++.h> using namespace std; const long long LIM = 1e5; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cout.precision(10); cout << fixed; long long n, r; cin >> n >> r; vector<long long> L(n); vector<long long> T(n); for (long... |
#include <bits/stdc++.h> using namespace std; long long Length, X, Y; long long Dp[10000001]; int main(void) { register long long i; cin >> Length >> X >> Y; Dp[1] = X; for (i = 2; i <= Length; i++) { Dp[i] = Dp[i - 1] + X; if (i & 1) { Dp[i] = min(Dp[i], Dp[(i >> 1) + 1] + X... |
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; int i1, i2, a1, a2; cout << ? ; for (int i = 1; i <= k; ++i) cout << i << ; cout << n ; cout.flush(); cin >> i1 >> a1; cout << ? ; for (int i = 1; i <= k + 1; ++i) { if (i == i1... |
#include <bits/stdc++.h> using namespace std; char s[110]; map<int, bool> mp[3]; bool Check(int x) { if (x < 10) { if (mp[0][x] || mp[1][x] || mp[2][x]) return true; } else if (x < 100) { int a = x / 10, b = x % 10; if (mp[0][a] && mp[1][b]) return true; if (mp[0][a] && mp[2][b])... |
#include <bits/stdc++.h> using namespace std; int main() { int n; int a, b; int s[4010]; cin >> n; memset(s, 0, sizeof(s)); for (int i = 0; i < n; i++) { cin >> a >> b; s[a + b]++; s[a - b + 3000]++; } long long sum = 0; for (int i = 0; i <= 4000; i++) { i... |
#include <bits/stdc++.h> using namespace std; int main() { long long x, y, z; cin >> x >> y >> z; long long xx = x, yy = y; long long g1 = x % z, p1; if ((y + g1) / z > y / z) { y += g1; if (g1 - (y) % z > 0) g1 -= (y) % z; } else g1 = 0; p1 = (x / z) + (y / z); lon... |
#include <bits/stdc++.h> using namespace std; const long long M = 1e6 + 5; const long long mod = 1e9 + 7; void solve() { long long n; cin >> n; long long a = n / 10; long long b = n % 10; long long ans = a + (b == 9); cout << ans; } signed main() { ios::sync_with_stdio(false); ... |
#include <bits/stdc++.h> using namespace std; template <typename TP> inline bool rd(TP& r) { r = 0; char tmp = getchar(); while (tmp < 0 || tmp > 9 ) { if (tmp == EOF) return 0; tmp = getchar(); } while ( 0 <= tmp && tmp <= 9 ) { r = (r << 3) + (r << 1) + tmp - 0 ; ... |
#include <bits/stdc++.h> #pragma warning(disable : 4996) #pragma comment(linker, /STACK:336777216 ) using namespace std; int IT_MAX = 1 << 17; const long long MOD = 1000000007; const int INF = 0x1f3f3f3f; const long long LL_INF = 1034567890123456789ll; const double PI = acos(-1); const double ERR = 1... |
#include <bits/stdc++.h> using namespace std; struct info { int l, r, need, onemore, take; }; vector<string> solve(vector<int> a, int n) { vector<string> ans(n + 1, string(n, 0 )); vector<info> state = {{0, n, (n + 1) / 2, ((n + 1) & 1), 0}}; int pos = 0; for (auto i : a) { for (auto ... |
#include <bits/stdc++.h> using namespace std; int cnt[ T + 1]; string p = AGTC ; int main() { int n; cin >> n; string s; cin >> s; for (int i = 0, __l = s.size(); i < __l; ++i) cnt[s[i]]++; int maxi = 0; for (int i = 0, __l = p.size(); i < __l; ++i) maxi = max(maxi, cnt[p[i]]); ... |
#include <bits/stdc++.h> using namespace std; const long double ESP = 1E-8; long double cal(long double x, long double y, long double z) { return log(x) * pow(y, z); } long double ca(long double x, long double y, long double z) { return y * z * log(x); } int main() { const char* result[12] = {... |
#include <bits/stdc++.h> using namespace std; using ll = long long; const ll MOD = (int)1e9 + 7; ll modAdd(ll a, ll b) { if (a + b >= MOD) return a + b - MOD; else return a + b; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n, m; cin >> n >> m; vect... |
#include <bits/stdc++.h> using namespace std; const long long int N = 21; long long int tot[N]; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long int n; cin >> n; long long int i, j, a[n], b, c, ans = 0; for (i = 0; i < n; i++) { cin >> a[i]; for (j... |
#include <bits/stdc++.h> using namespace std; bool test_cases_exist = false; void solve() { long long int i, j, n, m, k, x, y, ans; cin >> n; vector<long long int> v(n); for (auto &z : v) cin >> z; long long int bit = 23; long long int oneall = (1 << 23) - 1; vector<long long int> dp((... |
#include <bits/stdc++.h> using namespace std; int main() { long long n, m; cin >> n >> m; long long a = 1; long long b = 1; long long c = 1000000007; for (int i = 0; i < n; i++) { b = b * (2 * m - 1); b = b + a; b = b % c; a = a * m; a = a % c; } cout <<... |
#include <bits/stdc++.h> using namespace std; int dfn[2100], low[2100], tim, dis[2100], n, i, x, y, M, be[2100], m, j, ans, du[2100]; vector<int> E[2100], e[2100], q; void tarjan(int x, int ff) { dfn[x] = low[x] = ++tim; q.push_back(x); for (int i = 0; i < e[x].size(); ++i) if (e[x][i] !... |
#include <bits/stdc++.h> using namespace std; const int MAXN = 100005; const int INF = 1e9; struct dot { int l, r; }; typedef int node; const int neutro = 0; struct RMQ { int sz; node t[4 * MAXN]; node &operator[](int p) { return t[sz + p]; } void init(int n) { sz = 1 << (32 - ... |
#include <bits/stdc++.h> using namespace std; map<string, int> m; int dis(string s1, string s2) { return (m[s2] - m[s1] + 12) % 12; } int main() { string s1, s2, s3; m[ C ] = 0; m[ C# ] = 1; m[ D ] = 2; m[ D# ] = 3; m[ E ] = 4; m[ F ] = 5; m[ F# ] = 6; m[ G ] = 7; m[ G# ]... |
#include <bits/stdc++.h> using namespace std; const int N = 100005; int n, v[N], id[N], now[N], p[N]; bool is_lucky(int x) { while (x) { if (x % 10 != 7 && x % 10 != 4) return false; x /= 10; } return true; } void change(int pos1, int pos2) { swap(now[p[pos1]], now[p[pos2]]); ... |
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int a, b; cin >> a >> b; if (a == b) { cout << 0 << n ; continue; } if (a - b > 5) { int answ = 0; int cant = (a - b) / 5; answ = answ + cant;... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, m; cin >> n >> m; char a[n + 2][m + 2]; int flag = 0; for (long long int i = 0; i <= n + 1; i++) { for (long long int j = 0; j <= m + 1; j++) { a[i][... |
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 6; const int maxlog = 20; const long long inf = 1e18; const int mod = 1e9 + 7; const long long base = 307; map<long long, int> cnt1, cnt2; set<int> st; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long int n, i, c = 0; cin >> n; long long int a[n]; for (i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); for (i = 0; i < n; i++) { if (a[i] == a[i + 1]... |
#include <bits/stdc++.h> using namespace std; bool prime(int x) { if (x == 1) return false; else if (x == 2) return true; for (int i = 2; i * i <= x; i++) { if (x % i == 0) return false; } return true; } void fun2(int t) { if (t == 1) { cout << * ; return; ... |
#include <bits/stdc++.h> using namespace std; vector<string> s(3e5 + 1); vector<pair<int, int>> p; int n; vector<pair<int, int>> q; int Kr(int kb, int kn) { int ans = 0; for (int i = 0; i < n; i++) { int r1 = q[i].first - kb; int r2 = q[i].second - kn; int r; if (r1 * r2 >= 0... |
#include <bits/stdc++.h> using namespace std; int main(int argc, char** argv) { long long n; cin >> n; long long sum = n * (n + 1) / 2; if (sum % 2 == 1) cout << 1; else cout << 0; } |
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; cout << N << ; for (int i = 1; i < N; i++) cout << i << ; cout << endl; return 0; } |
#include <bits/stdc++.h> using namespace std; using namespace std::chrono; template <class e, class t, int N> std::basic_istream<e, t>& operator>>(std::basic_istream<e, t>& in, const e (&literal)[N]) { std::array<e, N - 1> buffer; in >> buffer[0]; if (N > 2) in... |
#include <bits/stdc++.h> using namespace std; bool field[100][100][100]; int n, m, k; bool check(int x, int y, int z) { return (x >= 0 && x < n && y >= 0 && y < m && z >= 0 && z < k && field[x][y][z]); } int main() { cin.sync_with_stdio(false); cout.sync_with_stdio(false); cin >>... |
#include <bits/stdc++.h> using namespace std; const int N = 1005; char g[N][N]; int l[N][N], r[N][N], up[N][N], dn[N][N]; int jx[N][N], jy[N][N]; struct Node { int x, y, len; }; vector<Node> p; int main() { int n, m; scanf( %d%d , &n, &m); for (int i = 1; i <= n; i++) scanf( %s , g[i] ... |
#include<bits/stdc++.h> using namespace std; #define M 105 int frq[M]; int main() { int t; scanf( %d , &t); while(t--) { int n, x; scanf( %d %d , &n, &x); memset(frq, 0, sizeof(frq)); for(int i = 1; i <= n; i++) { ... |
#include <bits/stdc++.h> using namespace std; int main() { int n, i, x, k = 0; cin >> n; vector<int> a; for (i = 0; i < n; i++) { cin >> x; a.push_back(x); } sort(a.begin(), a.end()); for (i = 0; i < n; i++) { if (a[i] % 2 != 0) k++; } int y = min(k, n - k); ... |
#include <cstdio> #include <iostream> #include <cstring> #include <algorithm> #include <vector> using namespace std; # define rep(i,a,b) for(int i=(a); i<=(b); ++i) # define drep(i,a,b) for(int i=(a); i>=(b); --i) typedef long long int_; inline int readint(){ int a = 0; char c = getchar(), f = 1; ... |
#include <bits/stdc++.h> using namespace std; inline long long read() { long long x = 0, f = 1; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == - ) f = -1; for (; isdigit(c); c = getchar()) x = x * 10 + c - 0 ; return x * f; } const long long MAXN = 100010; const lo... |
#include <bits/stdc++.h> using namespace std; int x, q; vector<int> adj[205]; bool visited[205]; void dfs(int n) { visited[n] = 1; for (int i = 0; i < adj[n].size(); i++) { if (!visited[adj[n][i]]) { visited[adj[n][i]] = 1; dfs(adj[n][i]); } } } int main() { int... |
#include <bits/stdc++.h> using namespace std; string ar[] = { zero , one , two , three , four , five , six , seven , eight , nine , ten , eleven , twelve , thirteen , fourteen , fifteen , sixteen , seventeen , ... |
#include <bits/stdc++.h> using ll = long long int; using namespace std; struct custom_hash { static uint64_t splitmix64(uint64_t x) { x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31); } size_t oper... |
#include <bits/stdc++.h> int col[100002]; int cal[5]; int main() { int n, m, i, j, k; int inp[3]; scanf( %d%d , &n, &m); for (i = 0; i < m; i++) { for (j = 0; j <= 3; j++) { cal[j] = 0; } for (j = 0; j < 3; j++) { scanf( %d , inp + j); cal[col[inp[j]]]++; ... |
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int n, s; cin >> n >> s; int a[s]; memset(a, 0, sizeof a); for (int i = 0; i < n; i++) { int x, y; cin >> x >> y; a[x - 1] = max(a[x - 1], y); } int t = 0; for (i... |
#include <bits/stdc++.h> using namespace std; char grid[105][105]; int dix[] = {-1, 1, 0, 0}, diy[] = {0, 0, -1, 1}, par[105][105], col[105][105], n, m; char ddd[] = UDLR ; vector<int> vec; void dfs(int xx, int yy) { int i, p, q; col[xx][yy] = 1; for (i = 0; i < 4; i++) { p = xx + d... |
#include <bits/stdc++.h> bool a[1005][1005]; int main() { int n; scanf( %d , &n); if (n == 3) { return puts( 0 1 0 n0 0 1 n1 0 0 ), 0; } else if (n == 4) { return puts( -1 ), 0; }; int n1 = n - (~n & 1); int i, j; for (i = 1; i <= n1; i++) { a[i][i % n1 + 1] = 1; ... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int q; cin >> q; for (int k = 0; k < q; ++k) { string s, t; cin >> s >> t; vector<bool> a(26), b(26); for (int i = 0; i < s.size(); ++i) { a[s... |
#include <bits/stdc++.h> using namespace std; struct T { T *l, *r; long long d, sum, mx; bool pushed; void recalc(long long len, long long d) { this->d = d; sum = len * d; mx = max(0ll, sum); } T(long long len, long long d) { l = r = 0; this->d = d; sum = ... |
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 5, M = N * 3; int n, i, j, l, r, scnt, s1; bool bb[M]; int w1[M], bbel[M]; unsigned long long w2[M]; struct seg { int l, r, c, bel; bool operator<(const seg& rhs) const { return r < rhs.r; } }; set<seg> S; vector<int> ve[N], i... |
#include <bits/stdc++.h> using namespace std; int w, h; char g[100][100], d[100][100]; bool use[100][100]; int dx[] = {-1, 0, 1, 0}; int dy[] = {0, -1, 0, 1}; bool is_valid(int y, int x) { return 0 <= y && y < h && 0 <= x && x < w; } bool check() { for (int i = 0; i < h; i++) { for (int j = 0;... |
#include <bits/stdc++.h> using namespace std; constexpr int MAX_N = 5000; constexpr int INF = numeric_limits<int>::max(); int N; int H[MAX_N + 1]; int DP[MAX_N + 1][MAX_N + 1]; void print(int* ptr, int n) { printf( [ ); while (n > 0) { printf( %d , *ptr); ++ptr; --n; } ... |
#include <bits/stdc++.h> #pragma GCC optimize( O3 ) const double PI = acos(-1.0); using namespace std; const double EPS = 1e-9; const int N = 5e5 + 9; int n, mem[3009][2 * 3009], nxt[3009]; pair<int, int> a[3009]; bool com(pair<int, int> a, pair<int, int> b) { if (a.first < b.first) return 1; ... |
#include <bits/stdc++.h> using namespace std; int dis[10001][1001]; int pos[10001]; int g, r, n, m; void bfs() { deque<pair<int, pair<int, int> > > fila; fila.push_front({0, {0, 0}}); while (!fila.empty()) { int v = fila.front().first; int s = fila.front().second.first; int t = f... |
#include <bits/stdc++.h> using namespace std; const int maxn = 8e4 + 10; const long long mod = 998244353, modg = 3, modi = 332748118; int a[maxn], b[maxn]; int pow_mod(int a, int b) { int ans = 1; while (b) { if (b & 1) ans = (long long)ans * a % mod; a = (long long)a * a % mod, b >>= 1; ... |
#include <bits/stdc++.h> #pragma comment(linker, /STACK:256000000 ) using namespace std; inline void in(int &x) { scanf( %d , &x); } inline void in(int &x, int &y) { scanf( %d %d , &x, &y); } inline void in(int &x, int &y, int &z) { scanf( %d %d , &x, &y, &z); } inline void out(int x) { printf( %d , x); }... |
#include <bits/stdc++.h> const int N = 1000005; std::vector<int> e[N]; int a[N], n, m, x, y, r[N], c[N], id[N], cnt, cnt2, s[N], vis[N]; void dfs(int x) { if (vis[x]) return; vis[x] = 1; for (auto u : e[x]) { dfs(u); a[x] |= a[u]; } } int main() { scanf( %d%d , &n, &m); f... |
#include <bits/stdc++.h> using namespace std; int main() { long long A, B, n; cin >> A >> B >> n; long long i, j; if (A == 0) { if (B == 0) { cout << 0; } else cout << No solution ; return 0; } if (B % A) { cout << No solution ; return 0; }... |
#include <bits/stdc++.h> using namespace std; void geth(int in, int& out) { cout << in << endl; cin >> out; if (out != 1 && out != -1) { exit(0); } } int main() { ios_base::sync_with_stdio(false); int n, mx; cin >> mx >> n; std::vector<int> pp(n); for (auto&& x : pp) { ... |
#include <bits/stdc++.h> using namespace std; map<string, int> sz = { { S , 0}, { M , 1}, { L , 2}, { XL , 3}, { XXL , 4}, }; string st[5] = { S , M , L , XL , XXL }; int a[5]; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cerr.tie(nullptr); ... |
#include<bits/stdc++.h> using namespace std; const int N = 3e5 + 9; const long long inf = 2e18; int a[N], c[N], n, m; long long s1[N], s2[N]; long long f(int mid) { for (int i = mid; i <= n; i++) { if (a[i] < i - mid + 1) return 0; } return 1; } int32_t main() { ios_base::... |
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; while (n--) { unsigned long long a, b, c; cin >> a >> b >> c; unsigned long long d; d = (a * a + (b + c) * (b + c)); d = sqrt(d) - 1; cout << d << n ; } return 0; } |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); ; unsigned long long x, y; cin >> x >> y; if (x < y) { return cout << -1, 0; } if ((x - y) & 1) { return cout << -1, 0; } long long z = (x -... |
#include <bits/stdc++.h> using namespace std; int N, type[100005]; int Tm, in[100005], out[100005]; int par[100005][20]; bool comp[100005][20][2]; vector<int> G[100005]; void dfs(int nd) { in[nd] = ++Tm; for (int i = 0; i < G[nd].size(); i++) { int ch = G[nd][i]; if (ch == par[nd][0]) ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.