func_code_string stringlengths 59 71.4k |
|---|
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; const int N = 100005; long long f[N]; long long inverse(long long x) { if (x >= mod) return inverse(x % mod); assert(x != 0); if (x == 1) return 1; return inverse(mod % x) * (mod - mod / x) % mod; } int main() ... |
#include <bits/stdc++.h> using namespace std; int fastMax(int x, int y) { return (((y - x) >> (32 - 1)) & (x ^ y)) ^ y; } int fastMin(int x, int y) { return (((y - x) >> (32 - 1)) & (x ^ y)) ^ x; } const long long int MAXN = 1e6 + 10; long long int n, ans = 1; long long int a[MAXN], dp[MAXN]; void solve()... |
#include <bits/stdc++.h> using namespace std; static const int INF = 500000000; template <class T> void debug(T a, T b) { for (; a != b; ++a) cerr << *a << ; cerr << endl; } int h, w, q; char buf[505][505]; int ans[1000005]; struct query_ { int y1, x1, y2, x2; int id; }; bitset<... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t = 1; cin >> t; while (t--) { int n; cin >> n; vector<int> v(n); for (int i = 0; i < n; i++) cin >> v[i]; vector<int> ans(n); for (int i = 0; i < n... |
#include <bits/stdc++.h> using namespace std; using cd = complex<double>; const int Inf = 1000000007; const long long mod = 1000000007; const double Pi = acos(-1); void Fastio() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); } int n, t, ans = 0; long long res = 0; int Co[4]... |
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e6 + 5, inf = 1e9 + 5; char buf[1 << 12], *pp1 = buf, *pp2 = buf, nc; int ny; inline char gc() { return pp1 == pp2 && (pp2 = (pp1 = buf) + fread(buf, 1, 1 << 12, stdin), pp1 == pp2) ? EOF : *pp... |
#include <bits/stdc++.h> using namespace std; void no(int ex = -1) { cout << ex << n ; } void bl(bool win) { if (win) cout << YES ; else cout << NO ; cout << n ; } const int N = 2 * 10e5; const int mod = 998244353; vector<bool> pr; void prime() { int EDGE = 1000; pr... |
#include <bits/stdc++.h> using namespace std; int n, ans = 1e5, freq[125]; bool exst[125]; string s; int main() { scanf( %d , &n); cin >> s; for (int i = 0; i < n; i++) { exst[s[i]] = true; } freq[s[0]] = 1; for (int i = 0, j = 0; j < n;) { bool valid = 1; for (int k ... |
#include <bits/stdc++.h> using namespace std; int main() { long int n, x, y, i, j; long double sum1 = 0, sum2 = 0, mini, maxi, p, z; cin >> n >> x >> y; long int a[n]; for (i = 0; i < n; i++) { cin >> a[i]; } sort(a, a + n); mini = min(x, y); maxi = max(x, y); p = mini;... |
#include <bits/stdc++.h> long long int oddsum[100020], evensum[100020]; int main() { memset(oddsum, 0, sizeof(oddsum)); memset(evensum, 0, sizeof(evensum)); int n, i; long long int x, ans = 0, sum; scanf( %d , &n); for (i = 0; i < n; i++) { scanf( %lld , &x); if (i & 1) o... |
#include <bits/stdc++.h> using namespace std; string s[222], str; int res[1000000] = {0}; bool hh(int n, int x) { for (int i = 0; i < (1 << x); i++) { str = ; for (int k = 0; k < x; k++) (i & (1 << k)) ? str += 1 : str += 0 ; if (s[n].find(str) == -1) return false; } return tr... |
#include <bits/stdc++.h> using namespace std; int main() { static int f[10000]; int n, ok = false; scanf( %d , &n); for (register int i = 1; i <= n; ++i) scanf( %d , f + i); for (int i = 1; i <= n; ++i) if (f[f[f[i]]] == i) ok = true; puts(ok ? YES : NO ); } |
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 10; const long long mod = 1e9 + 7; inline long long gcd(long long a, long long b) { return !b ? a : gcd(b, a % b); } inline long long q_pow(long long a, long long x) { long long ans = 1, tmp = a; while (x) { if (x & 1) (ans ... |
#include <bits/stdc++.h> using namespace std; static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL; template <typename T, typename U> static void amin(T &x, U y) { if (y < x) x = y; } template <typename T, typename U> static void amax(T &x, U y) { if (x < y) x = ... |
#include <bits/stdc++.h> using namespace std; vector<int> adj[100010], ans; bool vis[100010]; bool c[100010]; void find(int v) { vis[v] = true; bool del = true; for (int u : adj[v]) { del &= c[u]; if (!vis[u]) find(u); } if (c[v] && del) ans.push_back(v); } int main() { ... |
#include <bits/stdc++.h> using namespace std; string s, s1, s2, q = rock , w = paper , e = scissors ; int main() { cin >> s >> s1 >> s2; if (s != s1 && s1 == s2 && s == q && s1 == e || s != s1 && s1 == s2 && s == w && s1 == q || s != s1 && s1 == s2 && s == e && s1 == w) cout << F... |
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 111; int N; long long A[maxn]; map<long long, long long> f; void rl(long long &x) { char ch = (getchar()); x = 0; while ((ch < 0 || ch > 9 )) ch = (getchar()); while (!(ch < 0 || ch > 9 )) x = x * 10 + ch - 0 , ch = ... |
#include <bits/stdc++.h> const int MN = 1e5 + 4, INF = 0x3f3f3f3f; int N, R, M, ans, D, A[MN], depth[MN], ord[MN], ecnt, ein[MN], eout[MN], st[MN]; std::vector<int> adj[MN]; struct nd { int l, r, val; nd *ch[2]; nd() : l(0), r(0), val(INF), ch{0} {} } * sgt[MN]; void dfs(int src, int p, int d) {... |
#include <bits/stdc++.h> using namespace std; const int L = 0, R = 1, U = 2, D = 3; const int maxn = 5005; class Node { public: int dir, l, r, u, d; } a[maxn], b[maxn]; int n, m; char s[maxn]; inline int id(int x, int y) { return x * m + y; } inline void build(int x, int y) { Node &u = a[id... |
#include <bits/stdc++.h> using namespace std; char s[500010]; int num[500010]; int cnt; long long t, mid; int n; int skip[500010]; long long minn(long long a, long long b) { return a < b ? a : b; } stack<int> sta; int ok(long long k) { int i, j, end = -1, last, type = -1, cnt = 0; long long ... |
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f, maxn = 200007; const long long MOD = 998244353; const long long LINF = 0x3f3f3f3f3f3f3f3fLL; const long long P = 19260817; char nc() { static char buf[100000], *p1 = buf, *p2 = buf; return p1 == p2 && (p2 = (p1 = buf) + fread(... |
#include <bits/stdc++.h> using namespace std; int main() { int n, flag = 1, num = 0; cin >> n; string st; cin >> st; for (int i = 0; i < n && flag; i++) { if (i < n - 1) { if (st[i] == st[i + 1]) { if (st[i] != ? ) { flag = 0; } else { n... |
#include <bits/stdc++.h> using namespace std; int k, t; char n1[10005]; char n2[10005]; int swapindex[2]; bool same(char x[], char y[], int n) { for (int i = 0; i < n; i++) { if (x[i] != y[i]) { return false; } } return true; } int ham(char x[], char y[], int n) { int... |
#include <bits/stdc++.h> using namespace std; int n, a[100005]; long long k; int main() { cin >> n >> k; for (int i = 0; i < n; i++) cin >> a[i]; long long sum = accumulate(a, a + n, 0LL); if (sum < k) cout << -1 << endl; else { long long L = 0, R = 1 << 30; while (L < R) {... |
#include <bits/stdc++.h> using namespace std; int main() { int n; long long sum = 0, sum_mas; cin >> n; vector<int> mas; for (int i = 0, temp = 0; i < n; i++) { cin >> temp; sum += temp; mas.push_back(temp); } sum_mas = sum; sort(mas.begin(), mas.end()); for (in... |
#include <bits/stdc++.h> using namespace std; using ll = long long; template <class A, class B> ostream& operator<<(ostream& os, const pair<A, B>& p) { return os << ( << p.first << , << p.second << ) ; } template <class T> auto operator<<(ostream& os, T&& x) -> decltype(x.begin(), os) { os <... |
#include <bits/stdc++.h> using namespace std; long long n, yu, one, sum, cnt = 3; long long ans[4]; long long gcd(long long a, long long b) { return !b ? a : gcd(b, a % b); } int main() { scanf( %I64d , &n); if (!(n % 3)) printf( 1 1 %I64d , n - 2); else printf( 1 2 %I64d , n - 3); ... |
#include <bits/stdc++.h> using namespace std; int n, k, a[200], b[200], i, j, DP[3 * 10000]; int main() { cin >> n >> k; for (i = 1; i <= n; i++) cin >> a[i]; for (i = 1; i <= n; i++) cin >> b[i], b[i] *= k; for (j = 10000; j >= -10000; j--) DP[j + 10000] = -(10000 * 10000); DP[10000] = 0; ... |
#include <bits/stdc++.h> using namespace std; struct tree { int lf; int rt; int we; } a[2000010]; int v[2000010]; int main() { int n; scanf( %d , &n); for (int j = 0; j < n - 1; j++) { scanf( %d%d , &a[j].lf, &a[j].rt); a[j].we = -1; v[a[j].lf]++; v[a[j].rt]++; ... |
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; int n = s.size(); n = (s[n - 2] - 48) * 10 + (s[n - 1] - 48); if (n % 4) cout << 0 ; else cout << 4 ; } |
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 121; int a[N], b[N], last[N], kol, ans, v, u, i, n; inline void add(int v, int u) { a[++kol] = u; b[kol] = last[v]; last[v] = kol; } void dfs(int v, int p, int len) { if (len == 2) { ++ans; return; } int x ... |
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; int v[1000]; cin >> n; for (int i = 0; i < n; i++) { cin >> v[i]; v[i] = abs(v[i]); } int signo = 1; for (int i = 0; i < n - 1; i++) { cout <... |
#include <bits/stdc++.h> using namespace std; inline long long in() { int32_t x; scanf( %d , &x); return x; } inline long long lin() { long long x; scanf( %lld , &x); return x; } const long long maxn = 200 + 10; const long long inf = 1e18 + 1; long long a[maxn][maxn], mini[maxn],... |
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> cnt(n); for (int i = 0; i < n; ++i) cin >> cnt[i]; sort(cnt.begin(), cnt.end(), greater<int>()); long long ans = 0; int prev = 1000000001; for (int i = 0; i < n; ++i) { if (cnt[i] >= prev) c... |
#include <bits/stdc++.h> using namespace std; void parseArray(long long* A, long long n) { for (long long K = 0; K < n; K++) { cin >> A[K]; } } long long modInverse(long long a, long long b) { return 1 < a ? b - modInverse(b % a, a) * b / a : 1; } long long gcd(long long a, long long b) { ... |
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; int sum, c = 0; cin >> n; int arr[3]; for (int i = 0; i < n; i++) { for (int i = 0; i < 3; i++) { cin >> arr[i]; } sum = arr[0] + arr[1] +... |
#include <bits/stdc++.h> template <typename T> inline void read(T &x) { x = 0; char c = getchar(); bool flag = false; while (!isdigit(c)) { if (c == - ) flag = true; c = getchar(); } while (isdigit(c)) x = x * 10 + (c ^ 48), c = getchar(); if (flag) x = -x; } using names... |
#include <bits/stdc++.h> using namespace std; long long t0, t1, t2, x1, x2; long long count(long long y1, long long y2) { return t1 * y1 + t2 * y2 - t0 * (y1 + y2); } int main() { cin >> t1 >> t2 >> x1 >> x2 >> t0; if (t1 == t2) { cout << x1 << << x2; return 0; } long long ... |
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; int n; cin >> n; cout << 0 << << 0 << << n; return 0; } |
#include <bits/stdc++.h> using namespace std; int main() { int n, b, a[22222], mx = 0; cin >> n >> b; mx = b; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n; i++) { int k = b / a[i]; int s = b % a[i]; for (int j = i + 1; j < n; j++) { int p = a[j] * k + ... |
#include <bits/stdc++.h> int main() { int i, j, n, max = -1, count, a; char c1, c2; scanf( %d , &n); char s[n]; scanf( %s , s); for (i = 0; i < n - 1; i++) { count = 0; for (j = i + 1; j < n - 1; j++) { if (s[j] == s[i]) { if (s[j + 1] == s[i + 1]) count++; ... |
#include <bits/stdc++.h> using namespace std; int main() { long long n, k; cin >> n >> k; set<long long> a = {1, n}; for (long long d = 2; d <= min((long long)sqrt(n) + 10, n - 1); d++) { if (n % d == 0) { a.insert(d); a.insert(n / d); } } long long ans = -1; ... |
#include <bits/stdc++.h> #pragma GCC optimize( O3 ) using namespace std; const int N = 405; int x, y, n, d, a[25][2], memo[N][N]; bool check(int i, int j) { return i * i + j * j <= d * d; } int solve(int i, int j) { int &ans = memo[i + 200][j + 200]; if (~ans) return ans; set<int> st; for (i... |
#include <bits/stdc++.h> using namespace std; vector<int> v, vv, vv2; int main() { long long t, n, a[1000], k, f = 0; cin >> n; string s; cin >> s; int cnt = 0; for (int i = 0; i < s.size() && cnt >= -1; i++) { if (s[i] == ( ) cnt++; else cnt--; } if (!... |
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s; cin >> s; int a[n]; for (int i = 0; i < n; i++) a[i] = s[i] - 48; int c1 = 0; for (int i = 0; i < n; i++) { if (n % 2 && i == n - 1) { if (!a[i]) c1 += 1; } else { if (a[... |
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<pair<int, int> > a(n); for (int i = (0); i < ((n)); ++i) cin >> a[i].first >> a[i].second; sort(a.begin(), a.end()); long long best = -1; vector<long long> dp(n, 0); for (int i = n - 1; i >= 0; --i) { ... |
#include <bits/stdc++.h> using namespace std; inline long long read() { long long re = 0, flag = 1; char ch = getchar(); while (!isdigit(ch)) { if (ch == - ) flag = -1; ch = getchar(); } while (isdigit(ch)) re = (re << 1) + (re << 3) + ch - 0 , ch = getchar(); return re * flag;... |
#include <bits/stdc++.h> using namespace std; long long n, k; void solve() { cin >> n >> k; if (n < k) { cout << k - n << n ; return; } if ((n % 2 == 0 and k % 2 == 0) or (n % 2 == 1 and k % 2 == 1)) cout << 0 << n ; else cout << 1 << n ; } signed main() { ... |
#include <bits/stdc++.h> using namespace std; int main() { int n, k, i; int rs = 1; int temp_rs = 1; cin >> n >> k; int mang[n]; for (i = 0; i < n; i++) { cin >> mang[i]; if (i > 0) { if (mang[i] != mang[i - 1]) { rs += 1; } else { rs = 1; ... |
#include <bits/stdc++.h> using namespace std; string s, t; int l[200005], r[200005], last[200005]; int main() { cin >> s >> t; memset(last, -1, sizeof(last)); int j = 0, slen = s.size(), tlen = t.size(); for (int i = 0; i < slen; i++) { l[i] = last[s[i] - a ]; if (j < tlen && s[i] =... |
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; const long long mod1 = 998244353; const double pie = 3.1415926535; long long power(long long x, long long y) { if (y == 0) return 1; else { if (y % 2 == 0) return power(x * x, y / 2); else re... |
#include <bits/stdc++.h> using namespace std; const long double eps = 1e-5; const long double PI = acos(-1); const int INF = (int)1e9; const long long INFF = (long long)1e18; const int mod = (int)1e9 + 7; const int MXN = (int)3e5 + 7; int main(void) { int n; cin >> n; puts(n == 2 ? 2 : 1 ... |
#include <bits/stdc++.h> using namespace std; int main() { int a[5]; int dp[350][350]; int n; int i, j, k; scanf( %d , &n); for (i = 0; i < n; i++) { scanf( %d , &a[i]); } if (n == 1) { if (a[0] != 0) printf( BitLGM n ); else printf( BitAryo n ); ... |
#include <bits/stdc++.h> using namespace std; int n, r1, r2, t1, t2, f1 = 1, f2 = 1, col[100010]; vector<vector<int>> graph; bool dfs(const int &v, const int &from, const int &color) { if (col[v] != color) return 0; for (auto &i : graph[v]) if (i != from) if (!dfs(i, v, color)) return 0; ... |
#include <bits/stdc++.h> using namespace std; int convexP = 0; const int SQ = 1075; const long long mini = -8e18; bool isErased[300001]; long long type[300001], a[300001], b[300001]; long long out[300001]; long long la[300001], lb[300001]; int convexSz, p; double cross(int x, int y) { return (double... |
#include <bits/stdc++.h> using namespace std; const int MAXK = 3000; struct Update { int cost; long long profit; }; struct CommutativeUndoableDS { vector<array<long long, MAXK + 1> > dp; CommutativeUndoableDS() { dp.emplace_back(); fill(dp.back().begin(), dp.back().end(), 0); }... |
#include <bits/stdc++.h> using namespace std; using ll = long long; constexpr int maxn = 1e6 + 7; struct DSU { vector<int> f; void init(int n) { f.resize(n + 1); iota(f.begin(), f.end(), 0); } int seek(int x) { return x == f[x] ? x : (f[x] = seek(f[x])); } bool same(int u, int v)... |
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int maxx = -1; set<int> s; map<int, int> m; vector<int> l(n); for (int i = 0; i < n; i++) { cin >> l[i]; m[l[i]]++; if (m[l[i]] > maxx) maxx = m[l[i]]; s.insert(l[i]); } cout << ma... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t; cin >> t; long long int n, m, k; vector<long long int> a, b; while (t--) { cin >> n >> m; cout << n << << n * 2 << n ; } return 0; } |
#include <bits/stdc++.h> using namespace std; const int MAXN = 300005; int n, m; char s[MAXN]; int g[22][22]; int dp[1 << 21]; int sol(int msk) { if (1 << m == msk + 1) return 0; if (dp[msk] != -1) return dp[msk]; int tk[20] = {0}; int ntk[20] = {0}; int tksz = 0; int ntksz = 0; ... |
#include <bits/stdc++.h> using namespace std; struct Student { int number; int cost; int com; }; bool comp1(Student a, Student b) { if (a.cost < b.cost) return true; return false; } bool comp2(Student a, Student b) { if (a.number < b.number) return true; return false; } int m... |
#include <bits/stdc++.h> int a[2005][2005], b[100005], c[8][10]; int max(int a, int b) { return a > b ? a : b; } int min(int a, int b) { return a < b ? a : b; } int main() { int n, m, k, s; while (scanf( %d%d%d%d , &n, &m, &k, &s) != EOF) { for (int i = 1; i <= 9; i++) { c[0][i] = -1 << 15... |
#include <bits/stdc++.h> using namespace std; struct x { int a, id, gp; bool operator<(const x& xx) const { return a < xx.a; } } s[100005]; bool cmp(x p, x q) { return p.id < q.id; } int main() { int n, m; scanf( %d%d , &n, &m); for (int i = 0; i < n; i++) { scanf( %d , &s[i].a); ... |
#include <bits/stdc++.h> using namespace std; const int maxN = 1000005; int sp[maxN]; void seive() { for (int i = 2; i <= 1000000; ++i) { if (sp[i] != 0) continue; for (int j = i; j <= 1000000; j += i) { if (sp[j] == 0) sp[j] = i; } } } int nxtpow(int x) { int p = 1; ... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); map<string, long long> m; long long n; cin >> n; for (long long i = 0; i < n; i++) { long long x; string y; cin >> x >> y; sort(y.begin(), y... |
#include <bits/stdc++.h> using namespace std; int main() { int n, s; cin >> n >> s; int a[n + 1], b[n + 1], i; a[0] = -1; b[0] = -1; for (i = 1; i <= n; i++) { cin >> a[i]; } for (i = 1; i <= n; i++) { cin >> b[i]; } if (a[1] == 0) { cout << NO ; retu... |
#include <bits/stdc++.h> using namespace std; const int N = 1000001; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int ans = 0, i, j, dp[N], half, n, a[N]; cin >> n; for (i = 0; i < n; ++i) cin >> a[i]; for (i = n - 1; i >= 0; --i) { dp[a[i]] = 1; for ... |
#include <bits/stdc++.h> using namespace std; template <class T> using vc = vector<T>; template <class T> using vvc = vc<vc<T>>; template <class T> void mkuni(vector<T>& v) { sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end()); } long long rand_int(long long l, long long r) ... |
#include <bits/stdc++.h> using namespace std; const int M = 998244353; const int N = 200005, E = 524288; int R[N * 4]; long long qpow(long long a, long long b) { long long ans = 1; while (b) { if (b & 1) ans = ans * a % M; a = a * a % M; b >>= 1; } return ans; } long long... |
#include <bits/stdc++.h> #pragma GCC target( avx2 ) #pragma GCC optimization( O3 ) #pragma GCC optimization( unroll-loops ) using namespace std; const int maxn = 2e5 + 5; const double PI = 3.14159265358979323846; void solve() { long long n; cin >> n; vector<long long> v(n); set<long long> ... |
#include <bits/stdc++.h> using namespace std; void speed() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } const long long N = 1e5 + 5; const long long NN = 105; const long long MAX = 2e5 + 123; const long long MOD = 1e9 + 7; const long long INF = 1e18; map<long long, long ... |
#include <bits/stdc++.h> using namespace std; const long long N = 1e5 + 5; long long n; long long nim[N], prefnim[N]; vector<pair<long long, long long> > sum[N]; int32_t main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; cin >> n; for (long long i = 1; i <= n; i++) { ... |
#include <bits/stdc++.h> using namespace std; long long dem[100001]; long long f[100002]; int main() { int n; long long x; cin >> n; for (int i = 0; i < n; i++) { cin >> x; dem[x]++; } f[1] = dem[1]; for (int i = 2; i < 100002; i++) f[i] = max(f[i - 2] + dem[i] * i, f[i -... |
#include <bits/stdc++.h> using namespace std; long long dpf[110][100][60]; long long dpg[110][100][60]; int diff; int likes_init = 0; const long long mod = 998244353; long long fast_exp(long long b, int e) { b = b % mod; if (e == 0) return 1; if (e == 1) return b; if (e % 2 == 1) return (b... |
#include <bits/stdc++.h> using namespace std; int main() { long long int i, j, k, m = 0, n, cnt = 0, x = 0, ans = 0, y, sum = 0, l = 0, r = 0; cin >> n >> m; string a[n]; for (i = 0; i < n; i++) { cin >> a[i]; } for (i = 0; i < n; i++) { for (j = 0; j <... |
#include <bits/stdc++.h> using namespace std; const int MAXN = 1010; int n, m, a[MAXN]; int main() { cin.tie(0); int T; cin >> T; while (T--) { int ans = 0; cin >> n >> m; for (register int i = 1; i <= n; ++i) cin >> a[i]; if (n > m || n == 2) { puts( -1 ); ... |
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; struct Data { int u, v, w; Data() {} Data(int x, int y, int z) : u(x), v(y), w(z) {} }; int n; vector<Data> edge, ans; vector<int> neighbor[N]; void dfs(int u, int par, vector<int> &leaf) { if (neighbor[u].size() == 1) ... |
#include <bits/stdc++.h> using namespace std; int a[200003], b[200003], ch[200003]; void Do() { int n, f = 0; cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n; i++) cin >> b[i]; for (int i = 0; i < n - 1; i++) { if (a[i] == 0) f = 1; if (f) a[i] = a[i + 1]; ... |
#include <bits/stdc++.h> using namespace std; long long power(long long a, long long n) { if (a == 0) return 0; if (a == 1 || n == 0) return 1; if (n == 1) return a % 1000000007; long long t = power(a, n / 2); t = t * t % 1000000007; if (n & 1) return t * a % 1000000007; return t; } ... |
#include <bits/stdc++.h> using namespace std; const int LEN = 100009; int n; int a[LEN]; int ch = 0, nech = 0; int ans = 0; int main() { cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n; i++) { if (a[i] % 2 == 0) ch++; else nech++; } ... |
#include <bits/stdc++.h> using namespace std; set<pair<long long, long long> > st; const long long INF = 1 << 30; const long long N = 100005; long long p[N], n, m; long long nxt[N], pre[N]; long long a[N], x[N]; inline long long read() { long long x = 0, f = 1; char ch = getchar(); while (ch... |
#include <bits/stdc++.h> using namespace std; int h, t, R; int n, m; vector<pair<int, int> > H, T; int D[201][201]; int shortestWin() { memset(D, -1, sizeof(D)); queue<pair<int, int> > q; for (int i = 1; i <= n; i++) { pair<int, int> s; s.first = i; s.second = 0; if (i <=... |
#include <bits/stdc++.h> const int MAXN = 300011; int N; struct Pair { int Val; long long Mask; } P[MAXN]; long long Sum; int main() { scanf( %d , &N); for (int i = 1; i <= N; ++i) { scanf( %d%I64d , &P[i].Val, &P[i].Mask); Sum += P[i].Val; } if (Sum < 0LL) { for (i... |
#include <bits/stdc++.h> using namespace std; const int maxn = 200010; const int mod = 1e9 + 7; namespace DSU { int fa[maxn], cycle[maxn], sz[maxn]; void init() { for (int i = 1; i < maxn; i++) fa[i] = i, sz[i] = 1, cycle[i] = 0; } int find_set(int x) { if (x == fa[x]) return x; else ... |
#include <bits/stdc++.h> using namespace std; const int maxn = 50 + 5; int R, C, K; char g[maxn][maxn]; int sx, sy, tx, ty; bool flag[300]; int mindist; string ans; const int dx[] = {0, 1, -1, 0}; const int dy[] = {1, 0, 0, -1}; bool mark[maxn][maxn]; int dist[maxn][maxn]; string board[maxn][m... |
#include <bits/stdc++.h> using namespace std; int board[9][9]; int bBoard[9][9]; int best, N, M; void saveBoard() { for (int i = 0; i < N; i++) for (int j = 0; j < M; j++) bBoard[i][j] = board[j][i]; } void printBoard() { for (int i = 0; i < N; i++, cout << endl) for (int j = 0; j < M;... |
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 5; const int mod = 1e9 + 7; const long long INF = 2e15; long long qpower(long long a, long long b) { long long ans = 1; while (b > 0) { if (b & 1) ans = ans * a % mod; b >>= 1; a = a * a % mod; } return ans;... |
#include <bits/stdc++.h> using namespace std; ostream &operator<<(ostream &out, string str) { for (char c : str) out << c; return out; } template <class L, class R> ostream &operator<<(ostream &out, pair<L, R> p) { return out << ( << p.first << , << p.second << ) ; } template <class T> ... |
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n, m; cin >> n >> m; string s; cin >> s; vector<int> v(m); for (int i = 0; i < m; i++) { cin >> v[i]; } sort(v.begin(), v.end()); vector<int> ans(26... |
#include <bits/stdc++.h> using namespace std; vector<pair<int, int> > g[100000]; vector<pair<int, int> > t[100000]; int n, k; int dp[100000][2]; bool cmp(pair<int, int> f, pair<int, int> s) { if (dp[f.first][0] + f.second != dp[s.first][0] + s.second) return dp[f.first][0] + f.second > dp[s.first]... |
#include <bits/stdc++.h> using namespace std; int n, k, h; int m[100001]; int v[100001]; int id[100001]; int match[100001]; int res[100001]; double eps = 1e-9; void qsort1(int, int); void qsort2(int, int); bool ok(double); int main() { cin >> n >> k >> h; for (int i = 1; i <= n; i++) { ... |
#include <bits/stdc++.h> using namespace std; long long x, x2, y, y2, n, m, k, a, b, rep, koliko, koliko2, p; long long hi, lo, mid; bool t; char c; string s; int main() { vector<long long> V; cin >> n >> k; k = n - k; for (int i = 0; i < n; i++) { cin >> x; V.push_back(x); ... |
#include <bits/stdc++.h> using namespace std; int n; int a[26]; int b[26]; bool ok; inline void go(int v, int rem, int cur, int last) { if (v == n) { ok = 1; for (int i = 1; i <= n && ok; ++i) if (b[i]) ok = 0; if (ok) { puts( YES ); exit(0); } } i... |
#include <bits/stdc++.h> #pragma comment(linker, /STACK:66777216 ) using namespace std; inline pair<int, int> operator-(const pair<int, int> &a, const pair<int, int> &b) { return make_pair(a.first - b.first, a.second - b.second); } inline int vec(const pair<int, int> &a,... |
#include <bits/stdc++.h> #pragma GCC optimize(2) #pragma GCC optimize(3) #pragma GCC optimize( Ofast ) #pragma GCC optimize( inline ) #pragma GCC optimize( -fgcse ) #pragma GCC optimize( -fgcse-lm ) #pragma GCC optimize( -fipa-sra ) #pragma GCC optimize( -ftree-pre ) #pragma GCC optimize( -ftree-vrp )... |
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7, N = 1e5 + 5; int n, c[N], x; long long dp[N][2]; vector<int> g[N]; void dfs(int v) { dp[v][0] = 1LL; for (int u : g[v]) { dfs(u); (dp[u][0] += dp[u][1]) %= mod; dp[v][1] = (dp[v][1] * dp[u][0] + dp[v][0] * dp[u]... |
#include <bits/stdc++.h> using namespace std; const long double eps = 1e-13; const long double PI = acos(-1); const int INF = (int)1e9; const long long INFF = (long long)1e18; const int mod = (int)1e9 + 7; const int MXN = (int)1e6 + 7; int n, k; vector<int> edge[MXN]; vector<int> re_edge[MXN]; int... |
#include <bits/stdc++.h> using namespace std; const int MAXL = 2000005; string pat[100005]; int beg[2000005]; int bel[2000005]; int id[4200000]; int L = 0; inline void modify(int a, int b, int val, int v = 1, int l = 1, int r = MAXL) { if (b < l || a > r) return; if (a <= l && r <= b) { id... |
#include <bits/stdc++.h> using namespace std; void optimizeIO() { ios_base::sync_with_stdio(false); cin.tie(NULL); } int32_t main() { optimizeIO(); long long tt = 1; cin >> tt; while (tt--) { long long n; cin >> n; vector<bool> v(65, 0); while (n) { long l... |
#include <bits/stdc++.h> using namespace std; string str[51]; bool visited[51][51], flag = false; int arrx[] = {1, -1, 0, 0}, arry[] = {0, 0, 1, -1}, n, m; void dfs(int x, int y, int oldX, int oldY, char renk) { if (x < 0 || x >= n || y < 0 || y >= m) return; if (str[x][y] != renk) return; if (vis... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.