func_code_string stringlengths 59 71.4k |
|---|
#include <bits/stdc++.h> using namespace std; int32_t main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long n; cin >> n; string s; cin >> s; long long ans = (n * (n - 1)) / 2; long long l = 0, r = n - 1; while (s[l] == s[0]) l++; while (s[r] == s[n - 1]) r-... |
#include <bits/stdc++.h> using namespace std; int digit[32]; long long dp[32][32][2]; long long dfs(int p, int k, bool tag) { int i; long long ret = 0; if (p == -1) return 1; if (~dp[p][k][tag]) return dp[p][k][tag]; if (!k) ret = (ret + dfs(p - 1, k, tag && !digit[p])) % 1000000007; ... |
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } const int MAXVAL = 1000000; const int MAXCNT = 200000; const int MOD = 1000000007; int n, want, nq; int cnt[MAXVAL + 1]; int dv[MAXVAL + 1]; int tot[MAXVAL + 1]; int fac[MAXCN... |
#include <bits/stdc++.h> using namespace std; const int MOD = 1000000007; const int N = 1000005; const double PI = 4 * atan(1); const long long MAX = 9223372036854775807; int dx[] = {1, -1, 0, 0, 1, -1, 1, -1}; int dy[] = {0, 0, 1, -1, 1, 1, -1, -1}; long long gcd(long long a, long long b) { return (b =... |
#include <bits/stdc++.h> const int N = 3e5 + 5; int T, n, i, x, d, v, o; inline int mx(int x, int y) { return x > y ? x : y; } inline int mn(int x, int y) { return x < y ? x : y; } int main() { for (scanf( %d , &T); T--;) { d = 0, v = 1e9, o = 1; scanf( %d , &n); for (i = 1; i <= n; ++i)... |
#include <bits/stdc++.h> using namespace std; const int Maxn = 4010; double num1[Maxn]; int num2[Maxn]; double dif[Maxn]; int main() { int n = 0, N = 0; int cnt = 0, cnt1 = 0, cnt2 = 0; double sum = 0; double ans = 100000000.0; scanf( %d , &n); N = 2 * n; for (int i = 0; i < N; i... |
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; const long long INF = 1e18; struct P { int id; long long dis; friend bool operator<(P a, P b) { return a.dis > b.dis; } }; int n, m, q, x[N], y[N], t[N], l[2][N], id[N], c; long long d[2][N], ans[N], pre[N]; vector<long lon... |
#include <bits/stdc++.h> using namespace std; long long int max(long long int x, long long int y) { if (x >= y) return x; return y; } long long int min(long long int x, long long int y) { if (x > y) return y; return x; } int main() { ios_base::sync_with_stdio(false); cout.tie(NULL); ... |
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; int l = -INF, r = INF, a = 0; while (n--) { int a_, d; cin >> a_ >> d; if (d == 1) l = max(l, 1900 - a); ... |
#include <bits/stdc++.h> using namespace std; double PI = 3.1415926536; int dX[] = {1, -1, 0, 0}; int dY[] = {0, 0, 1, -1}; int main() { int a, b, c, x, y, z, extra = 0, need = 0; cin >> a >> b >> c >> x >> y >> z; if (a > x) extra += ((a - x) / 2) * 2; else need += x - a; if (... |
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1.0); double fixAngle(double A) { return A > 1 ? 1 : (A < -1 ? -1 : A); } double dcmp(double a, double b) { return fabs(a - b) < 1e-6 ? 0 : a > b ? 1 : -1; } const int MAX_SIZE = 3e5 + 5; const int MOD = 1e9 + 7; int r = 0; long... |
#include <bits/stdc++.h> using namespace std; int mp[505][505], f[505]; void push(int n) { for (int i = 1; i <= n; i++) cout << f[i] << ; cout << endl; } int main() { int n, m, i, j, Q, sum, x, y; while (scanf( %d%d%d , &n, &m, &Q) != EOF) { memset(f, 0, sizeof(f)); for (i = 1; ... |
#include <bits/stdc++.h> #pragma comment(linker, /STACK:500000000 ) using namespace std; int A[222]; bool used[222]; int main() { int n, k, i; cin >> n >> k; for (i = 0; i < 2 * n + 1; i++) cin >> A[i]; int N = 2 * n + 1; memset(used, false, sizeof(used)); while (k) { for (i = 1... |
#include <bits/stdc++.h> using namespace std; long long mo(long long a) { return a % (long long)(1e9 + 7); } long long po(long long x, long long y, long long p) { long long res = 1; x = x % p; while (y > 0) { if (y & 1) res = (res * x) % p; y >>= 1; x = (x * x) % p; } return ... |
#include <bits/stdc++.h> using namespace std; void fast_IO_file() { ios_base::sync_with_stdio(false); cin.tie(NULL); } int main() { fast_IO_file(); string s1, s2; getline(cin, s1); getline(cin, s2); map<char, long long int> m1; map<char, long long int> m2; for (long long int ... |
#include <bits/stdc++.h> using namespace std; int main() { bool flag = false; int n, boro; cin >> n; int a[n], b[n]; for (int i = 0; i < n; i++) cin >> a[i] >> b[i]; for (int i = 0; i < 1; i++) { boro = max(a[i], b[i]); } for (int i = 1; i < n; i++) { if (max(a[i], b[i]) ... |
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { long long gcd; if (a == 1) return 1; else if (b == 1) return 1; while (b) { long long t = b; b = a % b; a = t; } gcd = a; return gcd; } long long check(long long &n) ... |
/*************** Code Submitted by Saumya Singh Netaji Subhas University of Technology CF : @saumya_singh203 ****************/ #include <bits/stdc++.h> using namespace std; #define int long long signed main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); ... |
#include <bits/stdc++.h> using namespace std; const int OO = 0x3f3f3f3f, N = 1e5 + 5, mod = 1e9 + 7; const double pi = acos(-1), EPS = 1e-8; int n, x, y, idx[N]; int main() { memset(idx, -1, sizeof idx); scanf( %d , &n); for (int t = 1; t <= n; ++t) { scanf( %d%d , &x, &y); int cnt = 0... |
#include <bits/stdc++.h> using namespace std; const int inf = 2000000000; const long double eps = 1e-07; int n; int a[200000]; int d[200000]; int main() { scanf( %d , &n); for (int i = 0; i < n; ++i) scanf( %d , &a[i]); d[0] = -inf; for (int i = 1; i <= n; ++i) d[i] = inf; for (int i =... |
#include <bits/stdc++.h> #pragma GCC optimize( O3 ) using namespace std; const long long N = 1e5 + 10; const long long mod = 1e9 + 7; const long long inf = -1e18; const long long INF = 1e18; long long bin_pow(long long n, long long k) { if (k == 0) return 1; if (k == 1) return n; if (n == 0) r... |
#include <iostream> #include <algorithm> #include <vector> #include <utility> using namespace std; int main() { int task; cin>>task; while(task--) { int n; cin>>n; int a[n]; int ans=n+n-1; for(int i=0;i<n;i++) { ... |
#include <bits/stdc++.h> using namespace std; bool is[1000001 + 1]; long long int g1(long long int x, long long int y) { long long int res = 1; x = x; while (y > 0) { if (y & 1) res = (res * x); y = y >> 1; x = (x * x); } return res; } long long int g(long long int x, lon... |
#include <bits/stdc++.h> using namespace std; long long n, m, x, y, k, T, p[300], a[300][300]; void dfs(int i) { for (int j = 0; j <= n; j++) if (a[i][j]) { a[i][j] = a[j][i] = 0; p[i]--; p[j]--; if (j && i) cout << j << << i << endl; dfs(j); } } int... |
#include <bits/stdc++.h> using namespace std; const long long MOD = (1 ? 100000000000000007 : 233333333333333333); const int mod = (1 ? 1000000007 : 998244353); const long long INF = 0x7fffffffffffffff; const int inf = 0x7fffffff; const double eps = 1e-8; const int N = 1e6 + 5; clock_t start, finish; ... |
#include <bits/stdc++.h> using namespace std; inline int in() { int32_t x; scanf( %d , &x); return x; } inline long long lin() { long long x; scanf( %lld , &x); return x; } inline string get() { char ch[2000010]; scanf( %s , ch); return ch; } const int MAX_LG = 21; ... |
#include <bits/stdc++.h> using namespace std; int main() { string s, p; cin >> s >> p; int len = s.size(); cout << s[0]; for (int i = 1; i < len; i++) { if (s[i] < p[0]) cout << s[i]; else break; } cout << p[0] << endl; return 0; } |
#include <bits/stdc++.h> using namespace std; int n, a[100100]; map<int, int> m; int mi(int a, int b, int c) { return min(min(a, b), c); } int mx(int a, int b, int c) { return max(max(a, b), c); } int md(int a, int b, int c) { return 0LL + a + b + c - mi(a, b, c) - mx(a, b, c); } int main() { io... |
#include <bits/stdc++.h> const int MaxN = 3e5; int n, m, a[MaxN], p[MaxN]; int leaf, tr[MaxN * 2]; void build(int n) { leaf = n; for (int i = 0; i < n; ++i) tr[i + leaf] = a[i] > a[i + 1]; for (int i = leaf - 1; i; --i) tr[i] = tr[i << 1] + tr[i << 1 | 1]; } void upd(int x, int val) { tr[x +... |
#include <bits/stdc++.h> using namespace std; int a[300007][15]; int ans[300007], cnt[15]; int main() { int n, m, k; scanf( %d%d%d , &n, &m, &k); for (auto i = (1); i <= (n); ++i) { for (auto j = (1); j <= (m); ++j) { scanf( %d , &a[i][j]); } } for (auto i = (1); i <= (k)... |
#include <bits/stdc++.h> using namespace std; int main() { int n, t; cin >> n; vector<int> v; for (int i = 0; i < n; i++) { cin >> t; v.push_back(t); } bool is = true; for (int i = 0; i < n; i++) { bool br = false; for (int j = 1000; j >= 1; j /= 10) { for... |
#include <bits/stdc++.h> using namespace std; int L[1220], R[1220], s[1220], pos[1220]; char ans[1220]; int main() { int n, ok = 1, all = 0, top = 0; scanf( %d , &n); for (int i = 1; i <= n; ++i) { scanf( %d%d , &L[i], &R[i]); if (!ok) continue; pos[i] = all; ans[all++] = ( ... |
#include <bits/stdc++.h> using namespace std; char gc() { static char buf[1 << 16], *s, *t; if (s == t) { t = (s = buf) + fread(buf, 1, 1 << 16, stdin); if (s == t) return EOF; } return *s++; } int read() { char c; int w = 1; while ((c = getchar()) > 9 || c < 0 ) ... |
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n, k; cin >> n >> k; if (n < k) { cout << k - n << n ; } else if (n == k) { cout << 0 n ; } else { if (n % 2 == 0) { if (k % 2 == 0) { ... |
#include <bits/stdc++.h> using namespace std; long long Min(long long a, long long b) { return a < b ? a : b; } inline int read() { int x = 0, f = 1; char c = getchar(); while (c < 0 || c > 9 ) { if (f == - ) f = -1; c = getchar(); } while (c >= 0 && c <= 9 ) { x = (x ... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); string st; cin >> st; int k, fi, se, cnt = 0; cin >> k; for (int i = 0; i < k; i++) { char a, b; cin >> a >> b; fi = se = 0; for (int j = 0; j < st.length()... |
#include <bits/stdc++.h> using namespace std; int a, b, c; const long long MOD = 1073741824; map<int, int> divisors; int make_divisors(int n) { if (divisors[n] != 0) return divisors[n]; int cnt = 0; int lim = n + 1; for (int i = 1; i < lim; i++) { if (n == n / i * i) { if (i * i ... |
#include <bits/stdc++.h> using namespace std; int a[51][51], b[51][51]; int main() { int n, m; cin >> n >> m; 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++) { cin >>... |
#include <bits/stdc++.h> using namespace std; const int maxn = 2e3 + 5; const int mod = 1e9 + 9; int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n; cin >> n; cout << (2 * n) - 1 << << 2 << endl << 1 << << 2 << endl; return 0; } |
#include <bits/stdc++.h> using namespace std; vector<pair<long long, long long> > vp, pp; int h[105][105]; int a[105], b[104]; int main() { int n, m, k; cin >> n >> m >> k; for (int i = 0; i < m; i++) cin >> a[i]; for (int i = 0; i < n; i++) cin >> b[i]; int x; for (int i = 0; i < n; i... |
#include <bits/stdc++.h> const long long int mrx = 1e6 + 5, M = 1e9 + 7, dm = 1e3 + 5; const long double pi = 3.1415926535897932384626433832795028841971693993751; long long int mx = -1e18, mn = 1e18; using namespace std; long long int q, n[mrx]; int main() { ios_base::sync_with_stdio(NULL); cin.tie(... |
#include <bits/stdc++.h> using namespace std; const int N = 200000 + 5; const int mod = 1000000000; int a[N], f[N]; int main() { int n, m, type, x, v, l, r, d, sum; scanf( %d%d , &n, &m); f[0] = f[1] = 1; for (int i = 2; i < n; ++i) f[i] = (f[i - 1] + f[i - 2]) % mod; for (int i = 0; i < n... |
#include <bits/stdc++.h> using namespace std; vector<pair<long long, long long> > bl; long long fact[200005]; long long ifact[200005]; long long invert_mod(long long a, long long p) { long long n = 1, old = 0, q = p, r, h; bool pos = false; while (a > 0) { r = q % a; q = q / a; h... |
#include <bits/stdc++.h> using namespace std; const int maxn = 300110; const int mod = 1e9 + 9; int n, m; int sumv[maxn * 4]; int f1[maxn * 4]; int f2[maxn * 4]; int num[maxn]; int sum[maxn]; int f[maxn]; int addv(int a, int b, int n) { return ((((long long)f[n + 1] * (long long)b) % mod + ... |
#include <bits/stdc++.h> using namespace std; int a; int main() { int b; int k; int s; cin >> b; cin >> k; for (int i = 1; i <= k; i++) { cin >> a; s += a; } if (b % 2 == 0) if (a % 2 == 0) { cout << even ; } else { cout << odd ; } ... |
#include <bits/stdc++.h> using namespace std; void fast() { ios_base::sync_with_stdio(false); cin.tie(NULL); } long long dotproduct(vector<long long>& a, vector<long long>& b) { long long sum = 0; for (long long i = 0; i < a.size(); i += 1) { sum += a[i] * b[i]; } return sum; } ... |
#include <bits/stdc++.h> using namespace std; int main() { int n; while (~scanf( %d , &n)) { int cnt = 1; while (n != 1) { if (n % 2 != 0) cnt++; n /= 2; } printf( %d n , cnt); } return 0; } |
#include <bits/stdc++.h> using namespace std; int first(int a) { int x = 1; while (a) { if (a % 10) x *= a % 10; a /= 10; } return x; } int main() { int q; cin >> q; vector<vector<int> > m(int(1e6 + 1)); for (int i = 0; i < int(1e6 + 1); ++i) m[i].resize(10); vect... |
#include <bits/stdc++.h> using namespace std; int Max(int a, int b) { return a > b ? a : b; } int Min(int a, int b) { return a < b ? a : b; } char s[10][10]; int n, k; int a[10], mi, ma, ans; int flag[10]; void dfs(int t) { int i, j; if (t == k) { mi = ma = a[0]; for (i = 1; i < n; +... |
#include <bits/stdc++.h> using namespace std; const int N = 100005; const int MOD = 998244353; int n; char s[N]; int solve() { scanf( %d , &n); scanf( %s , s); bool ok = true; for (int i = 0; i < n;) { int j = i; while (j < n && s[j] == s[i]) ++j; if (s[i] == 0 && i == 0)... |
#include <bits/stdc++.h> using namespace std; const long long INF = 1e18 + 10; const int maxn = 1e6 + 10; struct node { int d, l, r; long long c; } a[maxn]; long long L[maxn], R[maxn], vis[maxn]; bool cmp(node x, node y) { return x.d < y.d; } int main() { int n, m, k; scanf( %d%d%d , &n,... |
#include <bits/stdc++.h> using namespace std; inline int in() { int N = 0; register char c = getchar_unlocked(); while (c < 48 || c > 57) { c = getchar_unlocked(); } while (c > 47 && c < 58) { N = (N << 3) + (N << 1) + (c - 48); c = getchar_unlocked(); } return N; } ... |
#include <bits/stdc++.h> using namespace std; const int maxm = 20005, maxn = 1005; double f[maxm][maxn]; int K, q, p, l, r, mid; int main() { scanf( %d%d , &K, &q); f[0][0] = 1; for (int i = 1; i <= maxm - 1; i++) for (int j = 1; j <= K; j++) f[i][j] = f[i - 1][j - 1] * (K - j + 1) /... |
#include <bits/stdc++.h> using namespace std; template <typename T> int len(const T& a) { return a.size(); } using ll = long long; constexpr long double EPS = 1e-7; long double MaxSubarray(const vector<long double>& a) { long double best = -1e8; long double cur = 0.0; for (auto& i : a) { ... |
#include <bits/stdc++.h> enum QueryType { kArea = 1, kCrossProduct = 2 }; int64_t ask(QueryType query_type, int64_t first_index, int64_t second_index, int64_t third_index) { std::cout << query_type << << first_index + 1 << << second_index + 1 << << third_index + 1 << std:... |
#include <bits/stdc++.h> using namespace std; const int N = 2000001; vector<long long> d1(N), d2(N); int main() { ios::sync_with_stdio(0); cin.tie(0); long long n; cin >> n; long long x, y; for (long long i = 0; i < n; i++) { cin >> x >> y; d1[x + y]++; d2[x - y + 1000]... |
#include <bits/stdc++.h> using namespace std; int k, n; long long ans, maxim, suma; map<string, int> f; deque<pair<string, int>> box[200001], b1, b2, b; vector<pair<int, int>> trouble; string s; int val; bool comp(pair<string, int> x, pair<string, int> y) { return x.second > y.second; } int ma... |
#include <bits/stdc++.h> using namespace std; int main() { cin.tie(nullptr)->sync_with_stdio(false); if (fopen( .in , r )) { freopen( .in , r , stdin); freopen( .out , w , stdout); } int... |
#include <bits/stdc++.h> using namespace std; char ch[100010], temp[100010]; bool ok[100010]; int main() { int n; cin >> n; cin >> ch; int m = strlen(ch); for (int i = 1; i < n; i++) { cin >> temp; for (int j = 0; j < m; j++) { if (ch[j] >= a && ch[j] <= z && temp[j] ... |
#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; cin >> n; long long int s = 0; for (long long int i = 0; i < n; i++) { long long int x; cin >> x; s += x; } if (s % n == 0) ... |
#include <bits/stdc++.h> using namespace std; long long choose(long long n, long long k); bool isprime(long long n); long long power(long long x, long long y, long long p); long long power(long long x, long long y); long long gcd(long long a, long long b); int main() { ios_base::sync_with_stdio(0); ... |
#include <bits/stdc++.h> using namespace std; const int maxn = 102; int w, h, n, qs, qt; int area[maxn], areath; pair<int, int> q[1000006]; int dx[4] = {-1, 0, 1, 0}; int dy[4] = {0, -1, 0, 1}; bool vis[maxn][maxn]; bool cut[maxn][maxn][4]; int bfs(int stx, int sty) { qs = 0; qt = 1; q[0... |
#include <bits/stdc++.h> #pragma GCC optimize(3) using namespace std; inline char gc() { static const int L = 1000; static char sxd[L], *sss = sxd, *ttt = sxd; if (sss == ttt) { ttt = (sss = sxd) + fread(sxd, 1, L, stdin); if (sss == ttt) return EOF; } return *sss++; } inline i... |
#include <bits/stdc++.h> using namespace std; int n; long long a[5010]; int pw2[5010]; int ans = 1e9; bool check(int x, int y) { if (a[x] % a[y] != 0LL) return false; if (pw2[y] - (y - x - 1) <= 0) return true; return (pw2[x] + 1 == pw2[y] - (y - x - 1)); } int dp[5010]; int main() { s... |
#include <bits/stdc++.h> using namespace std; int n, m, x, l, r, i, s, a[10179]; int main() { cin >> n >> m; for (i = 1; i <= n; i++) cin >> a[i]; while (m--) { cin >> l >> r >> x; for (s = 0, i = l; i <= r; i++) if (a[i] < a[x]) s++; if (s + l == x) cout << Yes n ; ... |
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) using namespace std; template <class T> void na(vector<T>& a, int n) { a = vector<T>(n); for (T& i : a) cin >> i; } template <class T> void printVector(vector<T>& a) { for (T& i : a) cout << i << ; cout << n ; } template <clas... |
#include <bits/stdc++.h> using namespace std; long long a, b, c, d, e, f; bool ju2(long long x, long long y) { x -= c, y -= d; long long div = e * e + f * f; if (!div) return x == 0 && y == 0; return (e * x + f * y) % div == 0 && (e * y - f * x) % div == 0; } bool ju1() { if (ju2(a, b)) re... |
#include <bits/stdc++.h> using namespace std; int acc[25 + 5][25 + 5]; char str[25 + 5][25 + 5]; int main() { int N, M, ans = 0; scanf( %d %d , &N, &M); for (int i = 0; i < N; i++) scanf( %s , str[i]); for (int i = 1; i < N + 1; i++) for (int j = 1; j < M + 1; j++) acc[i][j] = acc[... |
#pragma GCC optimize( O3 ) #include <bits/stdc++.h> // #include <ext/pb_ds/assoc_container.hpp> // using namespace __gnu_pbds; // gp_hash_table<int, int> mapka; using namespace std; #define PB push_back #define MP make_pair #define LL long long #define int LL #define FOR(i,a,b) for(int i = (a); i... |
#include <bits/stdc++.h> using namespace std; long long modinverse(long long a, long long m) { long long m0 = m; long long y = 0, x = 1; if (m == 1) return 0; while (a > 1) { long long q = a / m, t = m; m = a % m, a = t; t = y; y = x - q * y; x = t; } if (x < 0)... |
#include <bits/stdc++.h> using namespace std; int main() { char a[505][505]; int i, n, j, c = 0; cin >> n; for (i = 0; i < n; i++) { for (j = 0; j < n; j++) { cin >> a[i][j]; } } for (i = 0; i < n; i++) { for (j = 0; j < n; j++) { if (a[i][j] == X ) { ... |
#include <bits/stdc++.h> using namespace std; int n; int a[1000]; bool ok = false; int main() { ios_base::sync_with_stdio(0); cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; int sum = 0; for (int i = 0; i < n; i++) sum += a[i]; int m; cin >> m; int l, r; for (int i = 0; ... |
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { int a, b, c; cin >> a >> b >> c; if (!c) return cout << (a == b ? YES : NO ), 0; if (c > 0 && b < a || c < 0 && b > a) return cout << NO , 0; cout << ((a % c + c) % c == (b % c + c) % c ? YES : NO ); re... |
#include <bits/stdc++.h> using namespace std; const int N = 512345, lgN = 20, rootN = 1123; const double eps = 1e-18; int r[N], w[N]; vector<double> positive, negative; double p[N]; int main() { int n, c, d; cin >> n >> c >> d; for (int i = 1; i <= n; ++i) { cin >> r[i] >> w[i]; r[... |
#include <bits/stdc++.h> using namespace std; int main() { int n, la, lb, x; cin >> n >> la >> lb; int apple[100]; for (int i = 1; i <= n; i++) apple[i] = 2; for (int i = 1; i <= la; i++) { cin >> x; apple[x] = 1; } for (int i = 1; i <= lb; i++) { cin >> x; if (ap... |
#include <bits/stdc++.h> using namespace std; int n; bool vis[400]; set<int> sub[400]; vector<int> ga[400]; vector<int> path; vector<int> ord; int curr; void DFS(int a) { sub[a].insert(a); for (int i = 0; i < ga[a].size(); i++) { int b = ga[a][i]; if (vis[b]) continue; vis[b]... |
#include <bits/stdc++.h> using namespace std; const int maxn = 300100; int read() { int x = 0, w = 1; char ch = 0; while (!isdigit(ch)) { ch = getchar(); if (ch == - ) w = -1; } while (isdigit(ch)) x = x * 10 + ch - 0 , ch = getchar(); return x * w; } vector<int> G[maxn];... |
#include <bits/stdc++.h> using namespace std; int main() { long long n, I; cin >> n >> I; map<long long, long long> mp; for (long long i = 0; i < n; i++) { long long x; cin >> x; mp[x]++; } if (ceil(log2(mp.size())) * n <= I * 8) { cout << 0; return 0; } ... |
#include <bits/stdc++.h> using namespace std; long long cc = 0; unordered_map<long long, long long> c, rc; vector<vector<long long> > graph(1e6); vector<bool> visited(1e6, false); vector<vector<long long> > answers(1e6); void dfs(long long node) { visited[node] = true; answers[cc].push_back(node);... |
#include <bits/stdc++.h> using namespace std; vector<long long> addr; void psh(string s) { long long res = 0, cur = 0; for (int i = 0; i < s.size(); i++) { if (s[i] == . ) { res *= 256; res += cur; cur = 0; } else { cur *= 10; cur += (s[i] - 0 ); ... |
#include <bits/stdc++.h> using namespace std; const int N = 51; vector<int> g[N]; int n, sz[N], dp[N][N][N][N], s, m, ans = 1e9, cost[N][N], temp[N]; void dfs(int u, int p) { for (auto i : g[u]) if (i != p) dfs(i, u), sz[u] += sz[i]; } int calc(int from, int to, int behind, int front) { if (... |
#include <bits/stdc++.h> using namespace std; int main() { int n, p; cin >> n >> p; int a[n], maxi = 0; for (int i = 0; i < n; i++) { cin >> a[i]; } sort(a, a + n); for (int i = 0; i < n; i++) { maxi = max(maxi, a[i] - i); } int b = 0; for (int i = 0; i < n; i++) ... |
#include <bits/stdc++.h> using namespace std; const int maxn = 1005; typedef struct { int pre[maxn]; void init(int n) { for (int i = 0; i <= n + 1; ++i) pre[i] = i; } int find(int x) { if (x == pre[x]) return x; return pre[x] = find(pre[x]); } void merge(int x, int y) { p... |
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using ull = unsigned long long; using pii = pair<int, int>; using vi = vector<int>; struct res { int x, t; bool operator<(const res &z) const { return x < z.x; } bool operator==(const res &z) const { re... |
#include <bits/stdc++.h> using namespace std; int main() { int n, q, r, c; cin >> n >> q; vector<vector<int>> a(2, vector<int>(n, 1)); vector<string> pass(q); set<pair<pair<int, int>, pair<int, int>>> count; for (int o = 0; o < q; o++) { cin >> r >> c; r--; c--; a[r][... |
#include <bits/stdc++.h> using namespace std; const int maxn = 1050; int n, m, g[maxn][maxn], ans[maxn][maxn]; int p[4] = {4, 3, 2, 1}; bool chk1(int x, int a, int b) { int i, st, c[2] = {a, b}; for (st = 0; st < m && !g[x][st]; st++) ; if (g[x][st] != c[0]) swap(c[0], c[1]); for (i = 0;... |
#include <bits/stdc++.h> using namespace std; template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; } template <typename T> ... |
#include <bits/stdc++.h> using namespace std; int arr[100000]; int main() { int n; cin >> n; for (int i = 0; i < n; ++i) cin >> arr[i]; for (int i = 1; n / i >= 3; ++i) { if (n % i != 0) continue; for (int j = 0; j < i; ++j) { int Ok = 0; for (int k = j; k < n; k += i) ... |
#include <bits/stdc++.h> using namespace std; int main() { int n, k = 0; string s; cin >> s >> n; vector<char> v, vv; int len = s.size(); if (len % n != 0) { cout << NO << endl; return 0; } int cnt = 0, c = 0, j; int m = len / n; for (int i = 0; i < n; i++) { ... |
#include <cmath> #include <cstdio> #include <string> #include <cstring> #include <iostream> #include <algorithm> using namespace std; typedef long long ll; const int N = 55; const int mod = 1e9 + 7; int t , n , m ,ans; char s[N]; int a[N]; void solve(){ cin>>s + 1; int len... |
#include <bits/stdc++.h> using namespace std; int findGreater(int compare, int startIndex, int *arr, int sizeofArray) { for (int i = startIndex; i < sizeofArray; i++) { if (compare < arr[i]) return i; } return -1; } int findLesser(int compare, int startIndex, int *arr, int sizeofArray) { f... |
#include <bits/stdc++.h> using namespace std; const int next_x[8] = {0, 1, -1, 0, 1, 1, -1, -1}; const int next_y[8] = {1, 0, 0, -1, 1, -1, -1, 1}; const int inf = 1e9 + 5; const long long linf = 1e18 + 5; const double PI = acos(-1.0); const int MAXN = 1e6 + 5; const int N = 4e6 + 5; const long double... |
#include <bits/stdc++.h> using namespace std; const int INF = INT_MAX; const long double PI = acos(-1); const long double E = 2.71828183; const int MOD = 1e9 + 7; vector<int> bfs(vector<vector<int> > adj, int src) { queue<int> q; q.push(src); vector<int> dst(adj.size(), INF); dst[src] = 0; ... |
#include <bits/stdc++.h> 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...); } long long mod = 1e9 + 7; long long powm(long long a, lo... |
#include <bits/stdc++.h> using namespace std; int n, a, sum, high, w, low; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cout << setprecision(10) << fixed; cin >> n >> w; for (int i = 1; i <= n; i++) { cin >> a; sum += a; if (sum > hi... |
#include <bits/stdc++.h> using namespace std; const int N = 5e5 + 10; const double INF = 1e18; int n, m, c; int a[N], p[N], f[N]; double E[N]; struct Node { double L, M, R, S; Node() {} Node(double L, double M, double R, double S) : L(L), M(M), R(R), S(S) {} }; struct SegmentTree { Nod... |
#include <bits/stdc++.h> using namespace std; int memo[500][26][26]; int son[500][26][26]; int cambios[500][26][26]; vector<string> A; int m, n; void solve(int x, int y, int z) { for (int row = 0; row < x; row++) for (int a = 0; a < y; a++) for (int b = 0; b < z; b++) { int &re... |
#include <bits/stdc++.h> using namespace std; struct edge { int to, next; } e[200005 * 2]; int d[200005], dl[200005], dr[200005], dd[200005]; int head[200005], q[200005], id[200005], a[200005]; long long ans; int n, tot; bool cmp(int x, int y) { if (dd[x] != dd[y]) return dd[x] > dd[y]; retu... |
#include <bits/stdc++.h> using namespace std; const int maxn = 300010, INF = 0x3f3f3f3f; template <typename Tp> inline int getmin(Tp &x, Tp y) { return y < x ? x = y, 1 : 0; } template <typename Tp> inline int getmax(Tp &x, Tp y) { return y > x ? x = y, 1 : 0; } template <typename Tp> inline... |
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; const int maxn = 100000 + 5; const long double eps = 1e-6; long double PI = acos((long double)(-1)); long long n, m, par[maxn][20], cnt[maxn], st[maxn], fi[maxn], ti; long long h[maxn]; long double qd[maxn], qu[maxn]; vector<int> e... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.