func_code_string stringlengths 59 71.4k |
|---|
#include <bits/stdc++.h> using namespace std; struct Node { int d; struct Node *left, *right; }; int p[1000][1000] = {0}; string s, t; void dp(int i, int j) { if (j - i + 1 == t.size()) { int f = 1; for (int z = 0; z < t.size(); z++) { if (s[i + z] != t[z]) { f = 0;... |
#include <bits/stdc++.h> using namespace std; int main() { string one, two; cin >> one >> two; int odin = 0, dva = 0; for (int i = 0; i < one.length(); i++) if (one[i] == 1 ) odin++; for (int j = 0; j < two.length(); j++) if (two[j] == 1 ) dva++; if (odin & 1 && odin + 1 >= dva... |
#include <bits/stdc++.h> using namespace std; long long x, y, n; long long arr[6]; int main() { ios_base::sync_with_stdio(0); cin >> x >> y >> n; int pos = (n - 1) % 6; arr[0] = (x + 1000000007) % 1000000007; arr[1] = (y + 1000000007) % 1000000007; arr[2] = (y - x + 1000000007 + 10000000... |
#include <bits/stdc++.h> using namespace std; double eps = 1e-10; int main() { ios::sync_with_stdio(false); cin.tie(0); long long h, l; while (cin >> h >> l) { double L = 0.0, R = 10000000.0; long long ans = l * l - h * h; printf( %.13f n , ans / (2.0 * h)); } return 0; ... |
#include <bits/stdc++.h> using namespace std; vector<long long> v; bool super(string s) { int sv = 0, f = 0; for (int i = 0; i < s.length(); ++i) { (s[i] == 7 ? sv += 1 : f += 1); } return (sv == f ? true : false); } long long strtoll(string s) { long long res = 0; for (int i =... |
#include <bits/stdc++.h> using namespace std; int n, m, t; char S[25][100005]; long long f[1048576], dp[1048576]; int ans; inline void Read(int &p) { p = 0; char c = getchar(); for (; c < 0 || c > 9 ; c = getchar()) ; for (; c >= 0 && c <= 9 ; c = getchar()) p = p * 10 + c - 0 ;... |
#include <bits/stdc++.h> using namespace std; const int inf = 1e9; const long long inf64 = 1e18; const int mod = inf + 7; const int N = 2e5 + 10; int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ; int n, k; cin >> n >> k; vector<int> a(n); for (int i =... |
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; const long long INF = 2e9; const long double PI = acos((long double)-1); const long double EPS = 1e-9; inline bool isPrime(long long x) { if (x <= 1) return 0; if (x <= 3) return 1; if (!(x % 2) || !(x % 3)) return 0; ... |
#include <bits/stdc++.h> using namespace std; const unsigned long long int mod = 1e9 + 7; const long long int inf = (long long int)1e18 + 2; const long long int N = (long long int)1e6 + 2; vector<vector<pair<long long int, long long int>>> graph; vector<long long int> ans; long long int visi[5005]; long... |
#include <bits/stdc++.h> using namespace std; long long exgcd(long long a, long long b, long long &x, long long &y) { long long d = a; if (b != 0) { d = exgcd(b, a % b, y, x); y -= (a / b) * x; } else { x = 1; y = 0; } return d; } int main() { long long n, a, b, x... |
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; int res = 0; bool no = 0; int i = 0; while (1) { i += m; if (i > n) { no = 1; break; } if ((2 * i) >= n) { res = i; break; } } if (no) ... |
#include <bits/stdc++.h> using namespace std; int main() { int a[4][4]; int i, j; for (i = 0; i < 4; i++) for (j = 0; j < 4; j++) cin >> a[i][j]; for (i = 0; i < 4; i++) { if (a[i][3]) { int cnt = 0; for (j = (i + 1) % 4; j != i; j = (j + 1) % 4) { { ... |
#include <bits/stdc++.h> using namespace std; void solve() { int n; cin >> n; std::vector<int> v; int maxi = 0; for (long long i = 0; i < n; i++) { int a; cin >> a; v.push_back(a); maxi = max(maxi, a); } int ans = -1; for (long long i = 0; i < n; i++) { ... |
#include <bits/stdc++.h> using namespace std; const long long INF = 1e15; const int MOD = 1e9 + 7; const double EPS = 1e-9; const double PI = acos(-1.0); mt19937 rng((int)chrono::steady_clock::now().time_since_epoch().count()); const int N = 105; pair<long long, long long> e[N]; long long n, m, a[N]; ... |
#include <bits/stdc++.h> using namespace std; char s1[1010], s2[1010]; int dp[1010][1010][15][2], n, m, k; int main() { scanf( %d%d%d , &n, &m, &k); scanf( %s%s , s1, s2); for (int i = 1; i <= k; i++) { for (int j1 = 1; j1 <= n; j1++) { for (int j2 = 1; j2 <= m; j2++) { if (s... |
#include <bits/stdc++.h> #pragma comment(linker, /STACK:1024000000,1024000000 ) using namespace std; const int Maxn = 600010, Maxm = 300005, Mo = 1000000007, sp[8][2] = {{-1, 0}, {1, 0}, {0, 1}, {0, -1}, {1, 1}, {-1, -1}, {1, -1}, {-1, 1}}; const long long oo = (1LL << 6... |
#include <bits/stdc++.h> using namespace std; const double pi = 4 * atan(1); int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); } int lcm(int a, int b) { return a / gcd(a, b) * b; } const int LEN = 330; int main() { long long x1, y1, x2, y2; long long n; long long arr[LEN][3]; long l... |
#include <bits/stdc++.h> using namespace std; int n, m, k; int main() { scanf( %d %d %d , &n, &m, &k); for (int i = 0; i < k; ++i) { int x, y; scanf( %d %d , &x, &y); x = min(x - 1, n - x); y = min(y - 1, m - y); if (min(x, y) <= 4) { printf( YES ); return 0; ... |
#include <bits/stdc++.h> using namespace std; const long long INF = 1e12; const int INF1 = 1e7; const int maxn = 100000 + 10; int n, m, k; int fd, u, v, w; struct node { int to, cost, fd; } a[maxn], b[maxn]; bool cmp(node f, node g) { return f.fd < g.fd; } bool cmp1(node f, node g) { return f.fd... |
#include <bits/stdc++.h> using namespace std; int a[100005], s[100005], f[100005]; int main() { int n, ans = 0; scanf( %d , &n); for (int i = 1; i <= n; i++) scanf( %d , &a[i]); s[1] = 0, f[1] = 0; for (int i = 2; i <= n; i++) { int step = 0, t = i - 1; while (a[t] < a[i] && t) { ... |
#include <bits/stdc++.h> #pragma GCC optimize( O3 , unroll-loops , omit-frame-pointer , inline ) #pragma GCC option( arch=native , tune=native , no-zeroupper ) #pragma GCC target( avx , popcnt ) using namespace std; const long long int INF = (long long int)1e17 + 5; const unsigned long long int MOD = ... |
#include <bits/stdc++.h> using namespace std; inline long long labs(long long a) { return a < 0 ? (-a) : a; } template <typename T> inline T sqr(T x) { return x * x; } void ImportMem(); string ToStr(int smpl, int sz) { ostringstream oss; oss << smpl; string test = oss.str(); while (tes... |
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 2; vector<int> g[maxn]; vector<long long> c[maxn], acum[maxn]; int n, m, q, idx, comp[maxn]; long long d[maxn], dist[maxn]; map<pair<int, int>, long long> memo; vector<int> cur; void dfs(int node, int par) { comp[node] = idx; ... |
#include <bits/stdc++.h> using namespace std; vector<vector<int> > V; int in[50]; int main() { vector<string> S; V.resize(30); int n, ile; cin >> n; ile = n; while (ile--) { string a; cin >> a; S.push_back(a); } for (int i = 0; i < S.size(); i++) { for (in... |
#include <bits/stdc++.h> using namespace std; vector<long long> primer; long long mul(long long x, long long y, long long mod) { long long s = 0; for (; y; y /= 2, x = (x + x) % mod) if (y & 1) s = (s + x) % mod; return s; } long long gcd(long long x, long long y) { return y ? gcd(y, x % y) ... |
#include <bits/stdc++.h> using namespace std; int main() { long long a; cin >> a; if (a < 2520) { cout << 0; } else { cout << a / 2520; } return 0; } |
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 5; inline int GetIdx(int l, int r) { return l + r | l != r; } int seg[maxn << 2]; void update(int l, int r, int x, int d) { if (l == r) { seg[GetIdx(l, r)] = d; return; } int mid = (l + r) >> 1; if (x <= mid) { ... |
#include <bits/stdc++.h> using namespace std; int mod = 1e9 + 7; int mat[2 * 100001][26]; int n, k; int count3 = 0; void find_most(int x, int y) { int total = 0, mx = 0; for (int i = 0; i < 26; i++) { total += mat[x][i] + mat[y][i]; mx = max(mx, mat[x][i] + mat[y][i]); } count3 +... |
#include <bits/stdc++.h> using namespace std; const long long MAX = 105; const long long MAXV = 2e5 + 1; const long long INF = 1e9; bool prime[MAXV]; void sieve() { memset(prime, true, sizeof(prime)); prime[0] = prime[1] = false; for (long long i = 2; i * i < MAXV; i++) { if (prime[i]) { ... |
#include <bits/stdc++.h> using namespace std; bool vis[500009]; int siz[500009]; int rr[1005][1005]; char arr[1005][1005]; vector<int> d; int n; void dfs(int x, int y, int cn) { if (x > n or y > n or x < 1 or y < 1 or rr[x][y] != 0) return; rr[x][y] = cn; siz[cn]++; if (arr[x + 1][y] == ... |
#include <bits/stdc++.h> using namespace std; const double pi = 3.14159265358979323846264338327950288419716939937510582097494459230; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long n, i, x; cin >> n; int vis[n + 4]; int cnt[n + 4]; memset(cnt, 0,... |
#include <bits/stdc++.h> using namespace std; int x[100005], res[100005]; map<int, pair<int, int>> xhMap; int main() { memset(x, 0, sizeof(x)); memset(res, 0, sizeof(res)); int n = 0, a = 0, b = 0; scanf( %d , &n); for (int i = 0; i < n; ++i) { scanf( %d%d , &a, &b); x[i] = a; ... |
#include <bits/stdc++.h> using namespace std; const int N = 4e5 + 10; vector<int> tree[N]; int cnt[N]; int n, mx1, mx2; bool centr[N], ans[N]; int dfs(int v, int p = -1) { int u; cnt[v] = 1; for (int i = 0; i < tree[v].size(); i++) { u = tree[v][i]; if (u == p) continue; cnt[... |
#include <bits/stdc++.h> using namespace std; long long c; vector<int> a; int N; long long C[65][65]; long long nCk(long long n, long long k) { if (k > n) return 0; return C[n][k]; } long long f(int index, int onesNeeded, int tight) { if (index == N) { if (onesNeeded == 0) retu... |
#include <bits/stdc++.h> using namespace std; int n, m, x, y, ans, f[200005]; char s[11]; int find(int k) { if (k == f[k]) return k; return f[k] = find(f[k]); } void add(int x, int y) { if (find(x) != find(y)) f[find(x)] = find(y); } int main() { scanf( %d%d , &n, &m); for (int i = 1... |
#include <bits/stdc++.h> using namespace std; int pri[26] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, -1}; long long mo[5] = {223092870ll, 2756205443ll, 907383479ll, 42600829ll, 97ll}; int N, M, d, t, len, i, j, u; int b[100]; long ... |
#include <bits/stdc++.h> using namespace std; const double eps = 1e-6; const int INF = 2e9; const long long LNF = 9e18; const int mod = 1e9 + 7; const int maxn = 2e3 + 10; int n, m, k; bool val[maxn], pos[maxn]; long long C[maxn][maxn], A[maxn]; void init() { scanf( %d , &n); for (int i = 1;... |
#include <bits/stdc++.h> using namespace std; int n, m; char ara[100][100]; int fr[100], fc[100]; vector<int> r, c; int pr; void row(int j); void col(int j) { fc[j] = 1; c.push_back(j); for (int i = 0; i < n; i++) if (ara[i][j] == # ) if (fr[i] == 0) row(i); } void row(int... |
#include <bits/stdc++.h> using namespace std; template <typename T> string to_string(const pair<T, T>& pr) { return ( + to_string(pr.first) + , + to_string(pr.second) + ) ; } template <typename T> string to_string(const vector<T>& vc, int w) { if (vc.empty()) return ; if (w + 1 == vc.size... |
#include <bits/stdc++.h> using namespace std; long long int f = 1, mod; void calc(int sum, int t) { for (int i = 1; i <= sum; i++) { if (i % 2 or !t) f = (f * i) % mod; else f = (f * (i / 2)) % mod, t--; } } int main() { int n, p, count = 0, a[200001] = {0}; cin >> ... |
#include <bits/stdc++.h> using namespace std; const long long INF = 999999999999999999; const double PI = acos(-1.0); void stop() { exit(0); } long long A[200005]; int main() { ios::sync_with_stdio(false); long long n; cin >> n; for (long long i = 0; i < n; i++) { cin >> A[i]; } ... |
#include <bits/stdc++.h> using namespace std; int abs(int x) { if (x < 0) return -x; return x; } int n, m; int x[500], y[500], l[500]; bool used[500]; int placed[500]; int dist(int i, int j) { return abs(x[i] - x[j]) + abs(y[i] - y[j]); } int main() { cin >> n >> m; for (int i = 0; i <... |
#include <bits/stdc++.h> using namespace std; int main() { int n, k, sum = 0, s[100005], ans[100005], an = 0; scanf( %d%d , &n, &k); for (int i = 1; i <= n; i++) { scanf( %d , &s[i]); sum += s[i]; } if (sum % k) { printf( No ); return 0; } int m = sum / k; int... |
#include <bits/stdc++.h> using namespace std; int main() { int a; cin >> a; cout << 2 * a - 1 << << 2 << n ; cout << 1 << << 2; } |
#include <bits/stdc++.h> using namespace std; long long int MOD = 1e9 + 7; long long int INF = 1e18; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long int i, j, k = 0, m = 0, n, p = 0, l, r, ans = 0, cnt = 0, mini = INF, maxi = INF, x... |
#include <bits/stdc++.h> using namespace std; const int maxn = 200009; const long long MOD = 119 << 23 | 1; class { public: bool g[1 << 22]; int a[1 << 22]; int N, M, n, m; void solve() { int _; cin >> _; while (_--) { cin >> n >> m; N = (1 << n) - 1; ... |
#include <bits/stdc++.h> using namespace std; int n, a[200000]; bool st[200000][2]; long long memo[200000][2]; long long solve(int node, int rev) { if (node < 0 || node >= n) return 0; if (st[node][rev]) return 0x3f3f3f3f3f3f3f3fll; if (node == 0) return 0; long long& val = memo[node][rev]; ... |
#include <bits/stdc++.h> using namespace std; long long int a[500005], n, d; long long int ans = 0; void func(long long int st, long long int ed) { if (st + 1 == ed) return; if (a[st] == a[ed]) { ans = max(ans, (ed - st) / 2); for (int i = st; i <= ed; ++i) { a[i] = a[st]; } ... |
#include <bits/stdc++.h> using namespace std; int main() { set<string> qq; string s, q, g[100000]; int h, j = -1; while (cin >> s) { h = 3; q = ; q = q + s[0] + s[1] + s[2]; while (h != s.length()) { while (s[h] != && s[h] != . ) { q += s[h]; ... |
#include <bits/stdc++.h> int m(int a) { int ret = 0, i = 1; while (a > 0) { if (a % 10 == 4 || a % 10 == 7) { ret += (i * (a % 10)), i *= 10; } a /= 10; } return ret; } int main() { int a, b; while (scanf( %d%d , &a, &b) != EOF) { while (1) { a++; ... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t; cin >> t; while (t--) { int n; cin >> n; string s; cin >> s; int cnt = 0; reverse(s.begin(), s.end()); cnt += (s[0] - 0 ); for (int ... |
#include <bits/stdc++.h> using namespace std; const long long maxn = 5e5; vector<pair<long long, long long>> g[maxn]; long long v1 = 0; long long v2 = 0; vector<pair<pair<long long, long long>, long long>> t1(maxn * 4); vector<pair<pair<long long, long long>, long long>> t2(maxn * 4); vector<long long> ... |
#include <bits/stdc++.h> using namespace std; long long f[1000001][4][2]; string s; signed main() { cin >> s; for (long long lst = 0; lst < 4; lst++) f[s.length()][lst][0] = f[s.length()][lst][1] = 0; f[s.length()][0][0] = f[s.length()][1][0] = f[s.length()][3][0] = 1; for (long long i = s... |
#include <bits/stdc++.h> using namespace std; using namespace std; int main() { long long int n, sum = 0, k; cin >> n >> k; for (int i = 0; i < n; i++) { int x; cin >> x; sum = sum + (x / k); if (x % k != 0) sum++; } cout << (sum + 1) / 2 << endl; } |
#include <bits/stdc++.h> using namespace std; vector<pair<int, int>> tr; int S(int n) { int ans = 1; while (ans < n) ans *= 2; return ans; } int k; void upd(int v) { v += k; tr[v].first--; for (; v > 1; v >>= 1) { tr[v >> 1] = max(tr[v], tr[v ^ 1]); } } template <typena... |
#include <bits/stdc++.h> int main() { int a, b, c; while (~scanf( %d%d%d , &a, &b, &c)) { int max = 999999999; int a1 = (c + b) + a; max = max < a1 ? max : a1; int a2 = 2 * (c + b); max = max < a2 ? max : a2; int b1 = (c + a) * 2; max = max < b1 ? max : b1; int ... |
#include <bits/stdc++.h> using namespace std; const int MAXN = 1000005; const int MAXM = 100005; long long res[MAXM]; vector<int> seq[MAXN]; vector<pair<int, int> > qry[MAXN]; int L[MAXN], A[MAXM], H[MAXM]; int n, m; int main() { ios::sync_with_stdio(false); cin >> n >> m; for (int i = 2; ... |
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 5; int n; long long r, a[(1LL << 20)], x, y; int main() { scanf( %d %I64d , &n, &r); long long sum = 0; double qpw = 1; for (int i = 1; i <= n; ++i) qpw *= 2; for (int i = 1; i <= qpw; ++i) { scanf( %I64d , &a[i]); ... |
#include <bits/stdc++.h> using namespace std; const long long int N = 500010; vector<vector<long long int> > ch, ar; void multiply(vector<vector<long long int> > &a, vector<vector<long long int> > &b) { vector<vector<long long int> > c; c.resize(a.size(), vector<long long int>(b[0].size(... |
#include <bits/stdc++.h> using namespace std; const int M = 21, N = 1e5 + 5, INF = 123456789; int dp[(1 << M)], sum[(1 << M)][M]; int cnt[25][25], n, m; char s[N]; int main() { scanf( %d%d , &n, &m); scanf( %s , (s + 1)); int len = strlen(s + 1); for (int i = 2; i <= len; i++) { cnt[s[... |
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const long double eps = 1e-6; const long double pi = acos(-1.0); long double sign(long double x) { return (x > 0) - (x < 0); } long long sign(long long x) { return (x > 0) - (x < 0); } int sign(int x) { return (x > 0) - (x < 0); } st... |
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7, NMAX = 160; int N, M; int DP[NMAX][2][2][NMAX][NMAX], SUM[NMAX][2][2][NMAX][NMAX]; void Mod(int &value) { value -= MOD; if (value < 0) value += MOD; } void ComputeSums(int i) { int j, k, left, right; for (j = 0; j < 2; ... |
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; struct SuffixArray { string a; long long N, m; vector<long long> SA, LCP, x, y, w, c; SuffixArray(string _a, long long m = 256) : a( + _a), N(a.length()), m(m), SA(N), LC... |
#include <bits/stdc++.h> using namespace std; int n, m, s, k, x, y, z, i, j, ans = 0; int a[2001][2], b[2001][2]; int main() { memset(a, 192, sizeof a); memset(b, 63, sizeof b); cin >> n >> m >> k >> s; for (i = 1; i <= n; i++) for (j = 1; j <= m; j++) { cin >> x; a[x][0] =... |
#include <bits/stdc++.h> using namespace std; const int N = 200100; const long long inf = 1e8; long long bit[N]; void up(int x) { while (x < N) { bit[x]++; x += (x & -x); } } int query(int x) { int sum = 0; while (x) { sum += bit[x]; x -= (x & -x); } return ... |
#include <bits/stdc++.h> using namespace std; const int NMax = 110000; const long long INF = 4294967296LL; int N, sum[NMax]; char A[NMax]; int S[NMax], L; unsigned int dp[3][NMax]; int main() { scanf( %d %s , &N, A); if (N & 1) { puts( 0 ); return 0; } int cur = 1, cnt = 0; ... |
#include <bits/stdc++.h> #pragma GCC optimize( O3 ) using namespace std; const int N = 1e5 + 10; int n, m, a[N]; int main() { ios::sync_with_stdio(0), cin.tie(0), cout.setf(ios::fixed), cout.precision(9); cin >> n >> m; for (int i = 1; i <= n; ++i) cin >> a[i]; a[n + 1] = m; vector<int> pf... |
#include <bits/stdc++.h> using namespace std; int abs(int x) { if (x < 0) return -x; return x; } int up[100005], lo[100005], a[100001][15]; int main() { int n, m, q; scanf( %d , &n), scanf( %d , &m); scanf( %d , &q); int i, j, x, y; for (i = (0); i < (n); i++) { for (j = (0);... |
#include <bits/stdc++.h> using namespace std; inline long long gcd(long long n1, long long n2) { return n2 == 0 ? abs(n1) : gcd(n2, n1 % n2); } inline long long lcm(long long n1, long long n2) { return n1 == 0 || n2 == 0 ? 0 : abs(n1 * (n2 / gcd(n1, n2))); } const int INF = 1000000000; const int M... |
#include <bits/stdc++.h> using namespace std; int cnt[5005], bad[5005]; int pref[5005]; int go[5005]; long long inf = 1e18; int good[5005][5005]; vector<int> lst[5005]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, x; long long ans = 0; cin >> n; ... |
#include <bits/stdc++.h> using namespace std; int n, m, d; int a[305]; long long t[305]; int dp[2][150005]; struct que { int i, num; que(int I, int NUM) { i = I, num = NUM; } friend bool operator<(struct que A, struct que B) { return A.num > B.num; } }; int compute() { int s0 = 0, s1 = 1... |
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; long long powmod(long long a, long long b) { long long res = 1; a %= mod; for (; b; b >>= 1) { if (b & 1) res = res * a % mod; a = a * a % mod; } return res; } const int N = 1010000; int nxt[N], f... |
#include <bits/stdc++.h> using namespace std; string s; vector<int> st; const int N = 5010; int pr[N], prefMinPlus[N], prefMinMinus[N]; int main() { int ans = 0; cin >> s; for (size_t i = 0; i < s.size(); ++i) { int cntq = 0; st.clear(); int balance = 0, curPlusSum = 0, curMinu... |
#include <bits/stdc++.h> using namespace std; int main() { int n, m, i, j; scanf( %d %d , &n, &m); for (i = 0; i < n / 2; i++) { for (j = 0; j < m; j++) { printf( %d %d n%d %d n , i + 1, j + 1, n - i, m - j); } } if (n % 2 == 1) { for (j = 0; j < m / 2; j++) { p... |
#include <bits/stdc++.h> using namespace std; const int maxn = 500010, inf = 1e9 + 233; int n; long long a[maxn]; map<long long, long long> f; template <typename T> inline void read(T &k) { int f = 1; k = 0; char c = getchar(); while (c < 0 || c > 9 ) c == - && (f = -1), c = getchar()... |
#include <bits/stdc++.h> using namespace std; long long x, y, nx, ny, k; int main() { cin >> x >> y; nx = x; ny = y; while (x != 1 && y != 1) { if (x > y) { k = x / y; x -= k * y; if (x == 0) { x += y; k--; } } if (x == y) { ... |
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5; int n, k, cnt[111111], a[111111], mxx, prime[111111], ct, mx[111111], cnr; long long cur, ans, ts, fuck, fk; bool f, fl[111111]; void Init() { for (int i = 2; i <= maxn; i++) { if (!fl[i]) { prime[++ct] = i; } ... |
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n, c1, c2, h; cin >> n >> c1 >> c2 >> h; int zero = 0, one = 0; int cost = 0; for (int i = 0; i < n; i++) { char ch; cin >> ch; if (ch == 0 ) cos... |
#include <bits/stdc++.h> using namespace std; long long int a, b; long long int x, y; long long int n, t; bool flag = false; string str; int main() { long long int a[4]; cin >> a[0] >> a[1] >> a[2] >> a[3]; sort(a, a + 4); if ((a[0] + a[1] < a[2]) && (a[1] + a[2] < a[3])) str = IMPO... |
#include <bits/stdc++.h> using namespace std; int n, q; string a[50]; string b[50]; int dfs(char c, int dep) { if (dep == n - 1) { return 1; } int ans = 0; for (long long int i = 1; i <= q; i++) { if (b[i][0] == c) { ans += dfs(a[i][0], dep + 1); } } return an... |
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; vector<pair<long long, long long>> v; for (long long i = 0; i < n; i++) { long long a, b; cin >> a >> b; v.push_back(make_pair(a, b)); } if (n & 1) cout << no ; else { int fla... |
#include <bits/stdc++.h> using namespace std; const int maxn = 5e5 + 5; const long long inf = 1e17; const int mod = 1e9 + 7; vector<int> edge[maxn]; bool mark[maxn]; int h[maxn]; vector<int> ant; void dfs(int v) { mark[v] = true; if (edge[v].size() == 1) ant.push_back(h[v]); for (int u : e... |
#include <bits/stdc++.h> using namespace std; int main() { int n, d, val, ind = 0, counter = 0, ans = 0; cin >> n >> d; string v; cin >> v; while (ind <= n - 1) { counter++; ans = 0; for (int i = d; i >= 1; i--) { if (v[ind + i] == 1 ) { ind += i; a... |
#include <bits/stdc++.h> using namespace std; const long long INF = 1e18 + 1; inline long long input(void) { char t; long long x = 0; int neg = 0; t = getchar(); while ((t < 48 || t > 57) && t != - ) t = getchar(); if (t == - ) { neg = 1; t = getchar(); } while (t >= ... |
#include <bits/stdc++.h> using namespace std; int main() { int n, s; cin >> n >> s; int *sa = new int[s + 1]; for (int i = 0; i < s + 1; i++) { sa[i] = 0; } for (int i = 0; i < n; i++) { int tm, tp; cin >> tm >> tp; if (sa[tm] < tp) { sa[tm] = tp; } ... |
#include <bits/stdc++.h> using namespace std; const int MAXN = 1024; bool mark[MAXN][MAXN]; int a[MAXN][MAXN], b[MAXN][MAXN]; long long s[MAXN][MAXN]; int main() { int n, m, r, c; vector<pair<long long, pair<int, int> > > v, w; scanf( %d%d%d%d , &n, &m, &r, &c); for (int i = 1; i <= n; ++i) ... |
#include <bits/stdc++.h> using namespace std; struct Dicnic { struct Edge { int from, to, cap, flow, next; Edge() {} Edge(int from, int to, int cap, int flow, int next) { this->from = from; this->to = to; this->cap = cap; this->flow = flow; this->next = ... |
#include <bits/stdc++.h> using namespace std; int N, M; int a[200005], w[200005]; long long qpow(long long x, int n) { long long res = 1; while (n) { if (n & 1) res = res * x % int(998244353); x = x * x % int(998244353); n /= 2; } return res; } long long inv(long long x) { ... |
#include <bits/stdc++.h> using namespace std; priority_queue<long long, vector<long long>, less<long long> > q; char nm[100005]; int main() { long long a, b, c, d, i, j, k, l; long long n; while (~scanf( %lld , &n)) { c = n / 36; d = n % 36; a = d / 3; b = d % 3; if (b ... |
#include <bits/stdc++.h> using namespace std; int main() { long long int i, save, left, right; string A; while (cin >> A) { left = 0; right = 0; for (i = 0; i < A.size(); i++) { if (A[i] == ^ ) { save = i; } } i = save; i--; while (i !... |
#include <bits/stdc++.h> using namespace std; int n, a, b, c, d, s = 0, i; int main() { cin >> n; for (i = 1; i <= n; i++) { cin >> a >> b >> c >> d; s = s + (c - a + 1) * (d - b + 1); } cout << s; } |
#include <bits/stdc++.h> const int N = 157, inf = 1e9 + 500; int n, m, del, t, dis[N]; int ans = inf; std::queue<int> q; struct node { int u, v, w; bool operator<(const node &a) const { return w < a.w; } } e[N]; inline int read() { int x = 0; char c = getchar(); while (!isdigit(c)) c =... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long n; cin >> n; vector<pair<long long, long long> > p; for (long long i = 0; i < n; i++) { double x, y; cin >> x >> y; p.push_back(make_pair(x, y)); } ... |
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 10; int a[maxn], used[maxn], change[maxn]; int n, m, odd, even, sz, ans; int o = 0, e = 0; map<int, int> id; int num[maxn]; int main(void) { scanf( %d%d , &n, &m); for (int i = 1; i <= n; i++) { scanf( %d , &a[i]); ... |
#include <bits/stdc++.h> using namespace std; int op, d; int main() { int nc = 0, bst = 0; ; for (cin >> op >> d; d--;) { string s; cin >> s; int c = 0; for (int i = 0; i < s.size(); ++i) if (s[i] == 1 ) ++c; if (c == op) nc = 0; else ++nc; ... |
#include <bits/stdc++.h> using namespace std; int n, num, _ = 0; int a[1005]; int main() { cin >> n; map<int, int> mp; for (int i = 0; i < 100000; i++) _++; int m = 0; for (int i = 0; i < 100000; i++) _++; for (int i = 0; i < n; i++) { int num; cin >> num; if (mp[num] =... |
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1.0); const double eps = 1e-8; const int mxn = 100033; const int mod = 1e9 + 7; inline int read() { int x = 0, f = 1; char c = getchar(); while (!isdigit(c)) f = c == - ? -1 : 1, c = getchar(); while (isdigit(c)) x = x *... |
#include <bits/stdc++.h> using namespace std; const int N = int(2e5) + 99; const int INF = int(1e9) + 100; int t; int n; long long s; pair<int, int> p[N]; bool ok(int mid) { long long sum = 0; int cnt = 0; vector<int> v; for (int i = 0; i < n; ++i) { if (p[i].second < mid) ... |
#include <bits/stdc++.h> using namespace std; using ll = long long int; void fast() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } int main() { fast(); int t, b, p, f, h, c; cin >> t; while (t--) { cin >> b >> p >> f; cin >> h >> c; int bun =... |
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define PI 3.14159265 #define pb push_back #define en cout<< n #define vec vector<ll> #define vecs vector<string> #define pii pair<ll,ll> #define VP vector< pii > #define setbits(x) __builtin_popcountll(x) #define zrobits(x)... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.