func_code_string stringlengths 59 71.4k |
|---|
#include <bits/stdc++.h> using namespace std; int main() { long long int n, i, j, b, a, q, m; long long int t = 1; cin >> t; while (t--) { cin >> n >> m; vector<vector<long long int>> v(n, vector<long long int>(m)); long long int f = 0; for (i = 0; i < n; ++i) { for (... |
#include <bits/stdc++.h> using namespace std; const int MAX = 2000 * 100 + 9; int arr[MAX]; int ans[MAX]; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, v, ac, bc; cin >> n; for (int i = 0; i < n; i++) { cin >> arr[i]; } ac = -1; bc = MAX; for (int i = 0... |
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) using namespace std; template <class T> T Gcd(T x, T y) { return y ? Gcd(y, x % y) : x; } template <class T> T Lcm(T x, T y) { return x / Gcd(x, y) * y; } template <class T> void Adj(T &x, T y) { if (x >= y) x %= y; while (x < 0)... |
#include <bits/stdc++.h> using namespace std; struct interval { int start; int end; }; int main() { int p, q, l, r; cin >> p >> q >> l >> r; struct interval Z[p]; for (int i = 0; i < p; i++) { cin >> Z[i].start >> Z[i].end; } struct interval X[q]; for (int i = 0; i < q;... |
#include <bits/stdc++.h> using namespace std; void Merge(int arr1[], int arr2[], int l, int m, int r) { int n1 = m - l + 1; int n2 = r - m; int L1[n1], L2[n1]; int R1[n2], R2[n1]; for (int i = 0; i < n1; i++) { L1[i] = arr1[i + l]; L2[i] = arr2[i + l]; } for (int i = 0; i < n... |
#include <bits/stdc++.h> using namespace std; bool check(string all, string ans) { return all.size() == ans.size(); } bool checkChar(string all, string ans) { vector<char> v1, v2; for (int i = 0; i < all.size(); i++) v1.push_back(all[i]); for (int i = 0; i < ans.size(); i++) v2.push_back(ans[i]); ... |
#include <bits/stdc++.h> using namespace std; int main() { int n, a, b, k, num; cin >> n >> a >> b >> k; vector<int> need; int cnt = 0; for (int i = 0; i < n; i++) { cin >> num; if (num <= a) { cnt++; continue; } if (num % (a + b) == 0) { int to_ad... |
#include <bits/stdc++.h> using namespace std; int solve() { int N; cin >> N; if (N % 2) { N -= 9; if (N < 0 || N == 2) return -1; return 1 + N / 4; } else { if (N < 4) return -1; return N / 4; } } int main() { int Q; cin >> Q; while (Q--) cout << sol... |
#include <bits/stdc++.h> using namespace std; const int N = 10101; char s[N], t[N * 100]; int ne[N][26]; int main() { scanf( %s , s); int lens = strlen(s); for (int i = lens; i >= 0; --i) { for (int d = 0; d < (26); ++d) ne[i][d] = i == lens ? lens : ne[i + 1][d]; if (i != lens) ne[i][... |
#include <bits/stdc++.h> using namespace std; vector<long long> V, L, Q; vector<string> P; map<int, int> M; set<char> S; set<char>::iterator it; long long n, m, a, b, c, d, e, f, cnt, x, y, z, t; string s, p, ans, temp; long long arr[1001]; bool xy = 0; char bd; int main() { ios_base::sync_w... |
#include <bits/stdc++.h> using namespace std; set<long long> s, s1; std::set<long long>::iterator l, h; int main() { long long n, i, j, k, a, p, low, high, m; bool flag = false; scanf( %lld %lld %lld , &n, &k, &a); scanf( %lld , &m); a++; p = (n + 1) / a; long long q = k; s.inser... |
#include <bits/stdc++.h> using namespace std; const int MAX_N = 305; string s[MAX_N][MAX_N], t[MAX_N][MAX_N]; int cnt0[MAX_N], cnt1[MAX_N]; int n, m; struct Move { int x_1, y_1, x_2, y_2; Move(int x_1_, int y_1_, int x_2_, int y_2_) : x_1(x_1_), y_1(y_1_), x_2(x_2_), y_2(y_2_) {} Move() ... |
#include <bits/stdc++.h> using namespace std; int main() { std::ios::sync_with_stdio(false); int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; i++) cin >> a[i]; int cur = 1, cnt = 0; vector<int> dp(n + 1, 0); for (int i = 0; i < n; i++) dp[a[i]] = dp[a[i] - 1] + 1; for (i... |
#include <bits/stdc++.h> using namespace std; int main() { long long int b1, b2, h1, h2, n, h, i, j, k, a, b; cin >> n >> h >> a >> b >> k; if (a > b) { swap(a, b); } while (k--) { long long int ans = 0; cin >> b1 >> h1 >> b2 >> h2; if (b1 == b2) { ans += abs(h1 -... |
#include <bits/stdc++.h> using namespace std; bool cc(int x) { for (int i = 2; i * i <= x; i++) if (x % i == 0 && x != 2) return false; return true; } int pow(int i, int j) { int x = 1; while (j--) { x *= i; } return x; } int main() { vector<int> v; int n; cin... |
#include <bits/stdc++.h> using namespace std; int b[305]; vector<int> g[305]; int main() { int n; scanf( %d , &n); for (int i = 1; i <= n; i++) scanf( %d , b + i); b[0] = 0; g[0].push_back(0); for (int i = 1; i <= n; i++) { if (b[i] > b[i - 1]) { int temp = b[i] - b[i - 1];... |
#include <bits/stdc++.h> using namespace std; char a; int b, ans1, c[10], d; int main() { cin >> a >> b; if (a == A ) { ans1 = 1; for (; b > 0; b /= 10) c[++d] = b % 10; for (int i = 1; i <= d; i++) { if (c[i] == 1) ans1 += 10; else ans1 += c[i]; ... |
#include <bits/stdc++.h> using namespace std; int main() { vector<string> A(8); int mnA = 1e3, mnB = 1e3; for (int i = 0; i < 8; i++) cin >> A[i]; for (int i = 0; i < 8; i++) for (int u = 0; u < 8; u++) { if (A[i][u] == B ) { bool b = false; for (int j = i + 1; j <... |
#include <bits/stdc++.h> using namespace std; const int inf = 1 << 30; const double eps = 1e-8; const double pi = acos(-1.0); const int lim = 15; int n, a[300010]; int q; long long c[300010]; struct my { int a, b, id; my() {} my(int a, int b, int id) : a(a), b(b), id(id) {} bool operat... |
#include <bits/stdc++.h> using namespace std; int fu(vector<int> v) { int i; for (i = 0; i < 10; i++) { if (v[i] == 0) return i; } return i; } int ru(vector<int> v) { int i; for (i = 9; i >= 0; i--) { if (v[i] == 0) return i; } return i; } int main() { int n, ... |
#include <bits/stdc++.h> using namespace std; int main() { long long t, x; cin >> t; while (t--) { cin >> x; long long a, b; a = x % 14; b = x / 14; if ((a <= 6 && a >= 1) && b > 0) cout << YES << endl; else cout << NO << endl; } return 0; ... |
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7, siz = 1e6 + 5; long long q, n, m, a[siz], rot[66]; int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> q; while (q--) { long long op; cin >> op; if (op <= 2) { long long node, k; ... |
#include <bits/stdc++.h> using namespace std; const int MAXN = 100 * 1000 + 10; int n, t[MAXN]; vector<int> v; int main() { cin >> n >> t[0]; v.push_back(1); for (int i = 1; i < n; i++) { cin >> t[i]; if (t[i] == t[i - 1]) v[(int)v.size() - 1]++; else v.push_back(... |
#include <bits/stdc++.h> using namespace std; int main() { long long k, n; cin >> n >> k; long long d, f = 0, f2 = 0; d = n / k; long long a[n + 1]; if (d < 3) { cout << -1 << endl; } else { while (n--) cout << ((n / k) % 2 + n) % k + 1 << ; cout << endl; } ... |
#include <bits/stdc++.h> using namespace std; long long power(long long x, long long y) { long long res = 1; while (y > 0) { if (y & 1) res = (res * x) % 1000000007; y = y / 2; if (y != 0) x = (x * x) % 1000000007; } return res; } long long ans[2000005], n0[2000005], n1[2000005... |
#include <bits/stdc++.h> using namespace std; int Q, N, M, K, L; int A[5001]; int MAPPING[10001]; int CHK[10001]; int RET[10001]; map<int, int> MAP; int map_idx = 0; int main() { ios::sync_with_stdio(false); cin >> N; for (int i = 0; i < N; i++) { cin >> A[i]; if (A[i] == 0) co... |
#include <bits/stdc++.h> using namespace std; int main() { int n; vector<string> st; vector<pair<string, string> > pr; pr.push_back(make_pair( purple , Power )); pr.push_back(make_pair( green , Time )); pr.push_back(make_pair( blue , Space )); pr.push_back(make_pair( orange , Soul ))... |
#include <bits/stdc++.h> using namespace std; const double eps = 1e-8; const double pi = acos(-1.0); const long long INF = 0x3f3f3f3f3f3f3f3f; const int inf = 0x3f3f3f3f; const long long mod = 1e9 + 7; const int N = 2e5 + 10; const int M = 100; char ch[N]; int a[N]; int b[N]; int n; vector<int... |
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const double eps = 1e-9; const int MAXN = 1010; const int EN = MAXN * MAXN; int n, m, D; int a[MAXN], size, head[MAXN]; struct Node { int x, y; } arr[MAXN]; struct Edge { int v, w, next; } E[EN]; void init() { ... |
#include <bits/stdc++.h> using namespace std; const int maxn = 60; int n, a[maxn], w[maxn][maxn], f[maxn][maxn][maxn][maxn]; bool b[maxn][maxn][maxn][maxn]; int get(int t, int num, int l, int r) { if (l > r) return 0; if (b[t][num][l][r]) return f[t][num][l][r]; if (t == 1) { int ans = 0; ... |
#include <bits/stdc++.h> using namespace std; vector<int> arr[60][60]; int path[60][60][110]; int adj[60][60]; int main() { int n, m; scanf( %d%d , &n, &m); for (int i = 0; i < m; i++) { int x, y; scanf( %d%d , &x, &y); adj[x][y] = 1; int k; scanf( %d , &k); whi... |
#include <bits/stdc++.h> using namespace std; long long f[800][800][3][3]; int b[400][2], c[800]; int main() { string s; while (cin >> s) { memset(f, 0, sizeof(f)); int t[800]; for (int i = 0, x = 0, k = 0; i < s.size(); i++) { if (s[i] == ( ) { b[++x][0] = i + 1; ... |
#include <bits/stdc++.h> using namespace std; char c[16]; int r[16], b[16], n; int memo[1 << 16][16 * 16 + 5][2]; int roll(int mask, int other, int which) { other = min(other, n * n); if (mask == ((1 << n) - 1)) { return 0; } int &ans = memo[mask][other][which]; if (~ans) { ret... |
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const int maxn = 1000000; const int mod = 998244353; bool cmp(int x, int y) { return x > y; } int main() { long long n, ans = 0; cin >> n; if (n == 0) { cout << 0; return 0; } n += 1; if (n % 2 == 0... |
#include <bits/stdc++.h> using namespace std; namespace zzc { const int maxn = 3005; const long long mod = 1e9 + 7; long long f[maxn][maxn], x1, x2, x3, x4; bool mp[maxn][maxn]; char ch[maxn]; long long n, m; void work() { scanf( %lld%lld , &n, &m); for (int i = 1; i <= n; i++) { scanf( ... |
#include <bits/stdc++.h> int main() { int k2, k3, k5, k6; std::cin >> k2 >> k3 >> k5 >> k6; int sum = 0; while (k2 > 0 && k5 > 0 && k6 > 0) { sum += 256; k2 -= 1; k5 -= 1; k6 -= 1; } while (k3 > 0 && k2 > 0) { sum += 32; k3 -= 1; k2 -= 1; } std... |
#include <bits/stdc++.h> using namespace std; const long long maxn = 5e5 + 50; const long long mod = 1e9 + 7; const long long base = maxn * 2; long long low[maxn]; long long id[maxn]; long long cnt = 0; long long cntnw = 0; vector<long long> gr[maxn]; long long par[maxn]; pair<long long, long long... |
#include <bits/stdc++.h> using namespace std; template <class c> struct rge { c b, e; }; template <class c> rge<c> range(c i, c j) { return rge<c>{i, j}; } template <class c> auto dud(c* x) -> decltype(cerr << *x, 0); template <class c> char dud(...); struct debug { ~debug() { cerr <... |
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout << setprecision(32); int n, m; cin >> n >> m; for (int i = 0; i < n; i++) { int s, f, t; cin >> s >> f >> t; if (s < f) { int k = max(0, t - s + 1); k... |
#include <bits/stdc++.h> #pragma GCC optimize(3) using namespace std; signed main() { long long t; cin >> t; while (t--) { long long n; cin >> n; string s; cin >> s; map<long long, long long> maps; long long sum = 0; for (auto &i : s) { sum += i - 0 ... |
#include <bits/stdc++.h> using namespace std; int main() { vector<int> a; string s; int n, k, b[100][100], t, res = 99999999999, min, max; cin >> n >> k; getline(cin, s); for (int i = 0; i < n; i++) { getline(cin, s); for (int j = 0; j < s.length(); j++) b[i][j] = (int)(s[j] - 0... |
#include <bits/stdc++.h> using namespace std; int n, m, a; int b[100005]; int p[100005]; int main() { cin >> n >> m >> a; for (int i = 0; i < n; ++i) { cin >> b[i]; } for (int i = 0; i < m; ++i) { cin >> p[i]; } sort(b, b + n); sort(p, p + m); int hi = min(m, n), lo... |
#include <bits/stdc++.h> using namespace std; int M[1010][1010] = {}, C[1010][1010] = {}; int main() { int n, m; cin >> n >> m; memset(M, 0, sizeof(M)); memset(C, 0, sizeof(C)); for (int i = 0; i < n; i++) { int x, y; cin >> x >> y; M[y][x]++; } for (int i = 0; i < m;... |
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int c, sum; long int ans = 0; cin >> c >> sum; if (c >= sum) ans = sum; else { ans = ((c - sum % c) * (sum / c) * (sum / c)) + ((sum % c) * ((sum / c) + 1... |
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) using namespace std; const int INF = 1e9; const int mx = 300001; int n, q; vector<int> a, t[mx]; int count(int l, int r, int val) { vector<int>::iterator bg = t[val].begin(), en = t[val].end(); return upper_bound(bg, en, r) - lower_bound(bg, e... |
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long n, m, p = 0, q = 0, l = 0, i, flag = 0, k, t, j, r = 0, curr = 0, d; cin >> n >> m; long long a[n], b[n]; long double q1 = 1.0000; for (long long i = 0; i < n; i... |
#include <bits/stdc++.h> using namespace std; int p[5005], c[5005]; int day[5005]; bool out[5005], vi[5005]; int last = 0; int match[5005]; vector<int> DSK[5005]; bool DFS(int u) { if (vi[u] == true) return false; vi[u] = true; for (int i = 0; i < DSK[u].size(); i++) { int w = DSK[u][i... |
#include <bits/stdc++.h> using namespace std; const int maxk = 51; struct matrix { bool e[maxk][maxk]; int sz; void print() { for (int i = 0, _n = (sz); i < _n; i++) { for (int j = 0, _n = (sz); j < _n; j++) { printf( %d , e[i][j]); } printf( n ); } ... |
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 10; int n, m; vector<string> v(maxn); int func(int x, vector<vector<int>> &s) { vector<vector<int>> t(n + 3, vector<int>(m + 3, 0)); int i, j; for (i = 1; i <= n - 2 * x; i++) { for (j = 1; j <= m - 2 * x; j++) if (... |
#include <bits/stdc++.h> using namespace std; const int maxn = 1000020; const int maxm = 1000020; const int MOd = 998244353; void solve() { string s; cin >> s; int c = 0, c1 = 0; for (int i = 0; i < s.size(); i++) { if (s[i] == 0 ) { if (!c) printf( 1 1 n ); el... |
#include <bits/stdc++.h> using namespace std; int Q, n, m; struct Str { int n, qz[100100], yi[100100]; char str[100100]; inline int calc(int u, int v) { return qz[v] - qz[u - 1] + (str[v] == A ) * 2 * (u <= v); } inline void pre() { int i, j; n = strlen(str + 1); for (... |
#include <bits/stdc++.h> using namespace std; using ull = unsigned long long; using ll = long long; using ld = long double; using ii = pair<int, int>; using vi = vector<int>; template <class T> T abs(T x) { return x > 0 ? x : -x; } int main() { ios_base::sync_with_stdio(false); int n; ... |
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5, INF = 1e9 + 7; long long ans[N]; int main() { long long p, k; cin >> p >> k; long long tmp = -k; long long idx = 0; while (p != 0) { long long rem = p % tmp; p /= tmp; if (rem < 0) rem += k, p++; ans... |
#include <bits/stdc++.h> using namespace std; int a[200002], even[200002], odd[200002]; int main() { int n; cin >> n; cin >> a[1]; for (int i = 2; i <= n; i++) { cin >> a[i]; if (i & 1) { even[i] = even[i - 1] + a[i - 1]; odd[i] = odd[i - 1]; } else { even... |
#include <bits/stdc++.h> using namespace std; const int N = 100000 + 7; const int M = 300; const int mod = 999983; const int inf = 1e9 + 7; const double pi = acos(-1); const int maxn = N * 2; const double PI = acos(-1); int rev(int x) { int nw = 0; while (x) { nw = nw * 10 + (x % 10); ... |
#include <bits/stdc++.h> using namespace std; struct pp { long long cost; bool operator<(const pp &temp) const { return cost < temp.cost; } }; map<pp, int> hs; int n, c[2]; pp now; map<pp, int> solve(int n) { map<pp, int> ret, ms; map<pp, int>::iterator it; pp u, now; ret.clear(); ... |
#include <bits/stdc++.h> int main() { char a[10000], b[10000]; int l, i, j, k; k = j = 0; gets(a); gets(b); l = strlen(a); for (i = 0; i < l; i += 2) { if ((a[i] == 8 && b[i] == [ ) || (a[i] == [ && b[i] == ( ) || (a[i] == ( && b[i] == 8 )) j++; else ... |
#include <bits/stdc++.h> using namespace std; int main() { int n, m, k; scanf( %d , &n); scanf( %d , &m); scanf( %d , &k); vector<int> v; for (int(i) = 0; (i) < (int)(n); (i)++) { int a; scanf( %d , &a); v.push_back(a); } sort((v).begin(), (v).end()); int num = ... |
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 7; int n; int a[MAXN], r[MAXN], x[MAXN], vt[MAXN]; set<int> tset; int main() { cin >> n; int tmax = 0; for (int i = 0; i < n; i++) { cin >> a[i]; vt[a[i]] = i; if (a[i] > tmax) { r[i] = 1; tmax... |
#include <bits/stdc++.h> using namespace std; using ll = long long; const ll inf = 1e18; const int N = 2 * 1e5 + 10; ll res; ll a[N]; void solve() { ll n, k; cin >> n >> k; if (n == 1) { cout << 0 << n ; return; } if (n == 2) { cout << k << n ; return; }... |
#include <bits/stdc++.h> using namespace std; template <typename T1, typename T2> istream& operator>>(istream& in, pair<T1, T2>& p) { in >> p.first >> p.second; return in; } template <typename T1, typename T2> ostream& operator<<(ostream& out, pair<T1, T2> p) { out << p.first << << p.second;... |
#include <bits/stdc++.h> int main() { int a, b; scanf( %d %d , &a, &b); if (a >= b) { printf( %d %d , b, (a - b) / 2); } else if (b > a) { printf( %d %d , a, (b - a) / 2); } return 0; } |
#include <bits/stdc++.h> using namespace std; const int inf = 2147483647; int main() { string st; int i; cin >> st; for (i = 0; i < (int)st.size(); ++i) { if (st[i] == 0 ) { { st.erase(i, 1); break; } } else { if (i == (int)st.size() - 1) { ... |
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[100000]; for (int i = 0; i < n; i++) cin >> a[i]; long long ans = 0; for (int i = 0; i < n - 1; i++) { int j = 1; while (i + j * 2 < n) j *= 2; ans += a[i]; a[i + j] += a[i]; cout ... |
#include <bits/stdc++.h> using namespace std; int pos[109], npos[109]; int main() { int n, k; cin >> n >> k; for (int i = 1; i <= n; ++i) pos[i] = i; for (int i = 1; i <= k; ++i) { int cnt; cin >> cnt; int el = (1 + cnt) % n; if (el == 0) el = n; cout << pos[el] << ... |
#include <bits/stdc++.h> using namespace std; int n = 0, k = 0; bool ip[100010][32]; int main() { n = 0, k = 0; cin >> n >> k; for (int i = 0; i < n; i++) { int a = 0, b = 0, c = 0, d = 0; scanf( %d.%d.%d.%d , &a, &b, &c, &d); int l = 31; while (d) { ip[i][l--] = d % ... |
#include <bits/stdc++.h> using namespace std; const int MX = 20; const int MM = 1e5 + 5; int A[MM], n, m; char S[MM]; long long F[1 << MX], G[1 << MX]; void fwt(long long F[], int n) { for (int i = 0; i < n; i++) { for (int s = 0; s < 1 << n; s++) { if (s >> i & 1) continue; long... |
#include <bits/stdc++.h> using namespace std; int main() { long long T; cin >> T; while (T--) { long long n; cin >> n; if (n == 2) { cout << 2 << endl; continue; } long long tmp = n; long long cnt = 0; while (tmp != 0) { long long a = tmp... |
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int N, M; int64_t K; cin >> N >> M >> K; vector<int> A(N); for (int i = 0; i < N; i++) cin >> A[i]; int64_t ret = 0; for (int m = 0; m < M; m++) { vector<int64_t> B(N); ... |
#include <bits/stdc++.h> using namespace std; int main() { std::ios::sync_with_stdio(false); int n; cin >> n; int i, j; vector<int> vec1, vec2, vec3; vec1.push_back(0); vec2.push_back(1); vec1.push_back(1); n--; for (j = 0; j < n; j++) { vec3.push_back(0); for (i ... |
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; int q[n], ans[n], freq[100002]; fill(ans, ans + n, -1); fill(freq, freq + 100002, -1); for (int i = 0; i < n; i++) { cin >> q[i]; freq[q[i]] = 1;... |
#include <bits/stdc++.h> using namespace std; int i, j, k, n, v, e, x, y, a[300], b[300], d[300][300], S, X[1 << 20], Y[1 << 20], D[1 << 20]; void m(int x, int y, int f) { if (d[x][y] == 1) { if (f) { a[y] -= f, a[x] += f, X[S] = y, Y[S] = x, D[S] = f; S++; }; } else { ... |
#include <bits/stdc++.h> using namespace std; struct bigint { int len, num[70]; bigint(int m = 0) { memset(num, 0, sizeof num); len = 1; num[1] = m; } bigint operator+(const bigint &b) { bigint c; c.len = max(len, b.len); int x = 0, y = 0; for (int i = 1; i ... |
#include <bits/stdc++.h> using namespace std; int n, k, a; vector<int> v, ck; vector<int> has(1000002, 0); bool check(int x) { for (int i = 0; i < x; ++i) { ck[i] = 0; } int res = 0; for (int i = 0; i < n; ++i) { int d = v[i] % x; if (ck[d]) res++; ck[d]++; } re... |
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } map<vector<int>, int> H; for (int i = 0; i < 1 << 18; i++) { vector<int> b(... |
#include <bits/stdc++.h> using namespace std; const int N = 5005, P = 1e9 + 7; int ad(int k1, int k2) { return k1 += k2 - P, k1 += k1 >> 31 & P; } int su(int k1, int k2) { return k1 -= k2, k1 += k1 >> 31 & P; } int mu(int k1, int k2) { return 1LL * k1 * k2 % P; } void uad(int& k1, int k2) { k1 += k2 - P, k1... |
#include <bits/stdc++.h> using namespace std; bool mark[1234][1234]; char a[1234][1234]; int n, m, com; int id[1234][1234]; vector<pair<int, int> > node; int mX[10] = {-1, -1, -1, 0, 0, 1, 1, 1}; int mY[10] = {-1, 0, 1, -1, 1, -1, 0, 1}; inline void dfs(int x, int y) { mark[x][y] = true; if (x... |
#include <bits/stdc++.h> using namespace std; int f(vector<int>& a, int x) { if (a[x] == x) return x; a[x] = f(a, a[x]); return a[x]; } bool mer(vector<int>& a, int x, int y) { if (f(a, x) == f(a, y)) return true; else return false; } void uni(vector<int>& a, int x, int y) { ... |
#include <bits/stdc++.h> using namespace std; const int N = 5010; const int inf = 1e9; const int mo = 1e9 + 7; int s[N], num[N][N], ans[N], gra[N][N]; int main() { int n, m; cin >> n >> m; for (auto i = (1); i <= (n); ++i) { cin >> s[i]; } memset(num, 0, sizeof(num)); memset(gr... |
#include <bits/stdc++.h> using namespace std; vector<int> v[2000]; vector<int> w[2000]; vector<int> z; int f[2000]; int c[2000]; void dfs(int x) { f[x] = 1; for (int i = 0; i < v[x].size(); i++) { if (f[v[x][i]] == 0) dfs(v[x][i]); } z.push_back(x); } void dfs2(int x, int k) { ... |
#include <bits/stdc++.h> using namespace std; const int N = 1e5; int n; long long x, m, ans; long long f() { long long a, b, q; q = (x - 1) % 4; a = q == 0 ? x - 1 : q == 1 ? 1 : q == 2 ? x : 0; q = (x + m - 1) % 4; b = q == 0 ? x + m - 1 : q == 1 ? 1 : q == 2 ? x + m : 0; return a ^ b... |
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; struct node { long long int u, v, w; } edge[N]; bool cmp(node a, node b) { return a.w < b.w; } long long int n, m, k, v, ans = 0; bool special[N]; long long int root[N]; long long int find_root(long long int x) { if (root[x] ... |
#include <bits/stdc++.h> using namespace std; long long int p = 1e9 + 7; int main() { int t; cin >> t; while (t--) { int x; cin >> x; string s; cin >> s; int inl = s.length(); int i = 0; while (s.length() < x) { int l1 = s.length(); for (int j ... |
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; int main() { ios_base::sync_with_stdio(0); cin.tie(0); ; int n, k; cin >> n >> k; vector<int> a(n); for (int &x : a) cin >> x; bool can = true; for (int i = k; i < n; ++i) { if (... |
#include <bits/stdc++.h> using namespace std; double dp[53][53][53]; int n; pair<int, int> a[53]; bool check(double x) { for (int i = 0; i <= n + 1; i++) { for (int j = 0; j <= n + 1; j++) { for (int k = 0; k <= n + 1; k++) { dp[i][j][k] = 1e17; } } } dp[0][0]... |
#include <bits/stdc++.h> using namespace std; const long long N = 3e5 + 100; const long long big = 1e18; const long long block = 800; const long long mod = 1e6; bool fans = 0; long long n, m; long long w[N]; long long c[N]; vector<pair<long long, long long> > g[N], supans; vector<pair<pair<long lo... |
#include <bits/stdc++.h> using namespace std; int n, ans; int f[1000]; int main() { scanf( %d , &n); for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) { if (i + j - 1 <= n) { for (int k = j; k <= i + j - 1; k++) f[k]++; } } for (int i = 1; i <= n; i++) a... |
#include <bits/stdc++.h> using namespace std; string a, b; char s[200000], p[50]; int ans = 0; bool check(int l, int r) { int j = 1; for (int i = l; i <= r; ++i) { if (s[i] != p[j]) { return false; } j++; } return true; } int main() { std::ios::sync_with_stdio... |
#include <bits/stdc++.h> using namespace std; long long fib[50010]; int main() { long long n; cin >> n; fib[0] = 1; fib[1] = 2; if (n == 1) { cout << 0; return 0; } else if (n == 2) { cout << 1; return 0; } int i = 1; while (fib[i] <= n) { ++i; ... |
#include <bits/stdc++.h> using namespace std; const int MAX_N = 100 + 20; vector<pair<int, int> > edge, adj[2 * MAX_N]; vector<int> topol; int mark[2 * MAX_N], node[2 * MAX_N]; int comp; int ans[2 * MAX_N]; string s; int n, m; void readInput() { cin >> n >> m; for (int i(0); i < int(m); i++)... |
#include <bits/stdc++.h> using namespace std; template <class T> inline T read() { T x = 0, w = 1; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == - ) w = -w; for (; isdigit(c); c = getchar()) x = x * 10 + c - 0 ; return x * w; } template <class T> inline T read(T... |
#include <bits/stdc++.h> #pragma GCC optimize( -O2 ) using namespace std; void err(istream_iterator<string> it) {} template <typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cerr << *it << = << a << endl; err(++it, args...); } const int LIM = 1e5 + 5, MO... |
#include <bits/stdc++.h> const int maxn = 100005; const int mod = 1000000007; long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } using namespace std; char s[10]; int n, h; int main() { while (~scanf( %s , s + 1)) { scanf( %d%d , &n, &h); if (s[1] == B ) { ... |
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1); const double eps = 1e-12; const int inf = 2000000000; const long long int infLL = (long long int)2e18; long long int MOD = 998244353; int MOD1 = 1000000007; int MOD2 = 1000000009; inline bool checkBit(long long int n, long long ... |
#include <bits/stdc++.h> using namespace std; const int N = 25; const int M = 505; int n, m, a, b; int i, j, k, u, v, con; int deg[N]; bool c[N][N]; double p[N], q[N][N]; double f[M][M]; int g(int i, int j) { return i * n - n + j; } int main() { scanf( %d%d%d%d , &n, &m, &a, &b); for (i = ... |
#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 = 1e5 + 5; int N, M, ans; int nxt[... |
#include <bits/stdc++.h> using namespace std; int main() { int m, x, y, a[1005] = {0}, b[1005] = {0}; cin >> m; for (int i = 1; i <= m; i++) { cin >> x >> y; a[x]++; a[y]++; } for (int i = 1; i <= 5; i++) if (a[i] != 2) { cout << WIN ; return 0; } ... |
#include <bits/stdc++.h> using namespace std; const int inf = (int)1e9; const long long llinf = (long long)3e18; const int N = (int)1e6 + 111; const long double PI = (long double)acos(-1); int cnt1[N], cnt[N]; int main() { int t, x, mx = 0, len = 0, n, m; scanf( %d , &t); for (int i = 0; i < t... |
#include <bits/stdc++.h> using namespace std; const int Inf = 0x3f3f3f3f; const long long INF = 0x3f3f3f3f3f3f3f3fll; const int jt = 1000000007; void inline add(int &a, int b) { a += b - jt; a += (a >> 31) & jt; } void inline sub(int &a, int b) { a -= b; a += (a >> 31) & jt; } void inl... |
#include <bits/stdc++.h> using namespace std; inline long long read() { long long x = 0, f = 1; char ch; for (ch = getchar(); (ch < 0 || ch > 9 ) && ch != - ; ch = getchar()) ; if (ch == - ) f = 0, ch = getchar(); while (ch >= 0 && ch <= 9 ) { x = (x << 1) + (x << 3) + ch - ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.