func_code_string stringlengths 59 71.4k |
|---|
#include <bits/stdc++.h> using namespace std; long long first, second, cycle_s, cycle_len, l; int n, m, d, cnt[2][1000005][26]; string A, B; int gcd(int first, int second) { if (!second) return first; return gcd(second, first % second); } int main() { cin >> first >> second >> A >> B; n = ... |
#include <bits/stdc++.h> using namespace std; const int64_t MOD = 1e9 + 7; void add(int64_t& a, int64_t b) { a = (a + b) % MOD; } int nth_bit(int64_t num, int n) { return (num >> n) & 1; } const int SZ = 14 * 16; void matmul(int64_t A[SZ][SZ], int64_t B[SZ][SZ]) { int64_t ret[SZ][SZ] = {0}; for (int... |
#include <bits/stdc++.h> using namespace std; double ans = 0.0000; void bfs(); list<int> arr[100005]; int visited[100005], dep[100005]; int main() { int n, i, start, end; cin >> n; n--; while (n--) { cin >> start; cin >> end; arr[start].push_back(end); arr[end].push_b... |
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 10; map<pair<int, int>, int> weight; vector<int> edges[MAXN]; bool visited[MAXN]; long long int maximum; void dfs(int v, long long int sum) { visited[v] = true; maximum = max(maximum, sum); for (int i : edges[v]) { if (... |
#include <bits/stdc++.h> using namespace std; const int maxn = 5e5 + 5; int c[maxn]; int p[64], q[64]; int l[maxn]; int ans[maxn]; vector<int> g[maxn]; int main() { ios_base::sync_with_stdio(0); int n; cin >> n; for (int i = 1; i <= n; i++) cin >> c[i]; int Q; cin >> Q; for (... |
#include <bits/stdc++.h> using namespace std; int main() { char puzzel[600]; vector<string> Puz; int m, n; int stp; int len = 0, judge = 0; int prevstp; int prevlen; int minv = 1000; int maxv = -9; int flag = 0; scanf( %d%d , &m, &n); for (int i = 0; i < m; i++) { ... |
#include <bits/stdc++.h> using namespace std; double const eps = 1e-6; double const pi = 3.1415926535; long long const mod = 1e9 + 7; int a[20]; int main() { int n; cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < (1 << n); i++) { int x = 0; for (int j = 0; ... |
#include <bits/stdc++.h> using namespace std; vector<long long> res; int main() { cin.tie(0); cout.tie(0); ios::sync_with_stdio(0); long long n, f = 0, m; cin >> n; m = n; for (int i = 2; i <= sqrt(m); i++) { if (n % i == 0) { while (n % i == 0) { res.push_back(... |
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const int _inf = 0xc0c0c0c0; const long long INF = 0x3f3f3f3f3f3f3f3f; const long long _INF = 0xc0c0c0c0c0c0c0c0; const long long mod = (int)1e9 + 7; long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } long l... |
#include <bits/stdc++.h> using namespace std; short k, r, m = 10; int main() { cin >> k >> r; for (int i = 10; i > 0; --i) { if ((i * k) % 10 == 0 || (i * k - r) % 10 == 0) { m = i; } } cout << m; return 0; } |
#include <bits/stdc++.h> using namespace std; int n; int num[10]; char s[100010]; int main() { scanf( %d , &n); scanf( %s , s); for (int i = 0; i < n; i++) { if (s[i] == L ) { for (int j = 0; j < 10; j++) { if (num[j] == 0) { num[j] = 1; break; ... |
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int a, b, n, s; cin >> a >> b >> n >> s; if ((min(s / n, a) * n + b) >= s) { cout << YES << endl; } else { cout << NO << endl; } } return 0; } |
#include <bits/stdc++.h> using namespace std; int main() { int n, m; scanf( %d %d , &n, &m); int l[m], r[m]; for (int i = 1; i <= m; i++) { scanf( %d %d , &l[i], &r[i]); } for (int i = 1; i <= n; i++) { if (i % 2 == 1) printf( 1 ); else printf( 0 ); } ... |
#include <bits/stdc++.h> using namespace std; int main() { vector<int> numeros; string str4 = 2 * 3 = 6 n6 * 4 = 24 n24 * 1 = 24 ; string str5 = 3 - 1 = 2 n2 + 2 = 4 n4 * 5 = 20 n20 + 4 = 24 ; int n; scanf( %d , &n); if (n < 4) printf( NO ); else { printf( YES n ); if... |
#include <bits/stdc++.h> using namespace std; void scanint(int &x) { register int c = getchar(); x = 0; int neg = 0; for (; ((c < 48 || c > 57) && c != - ); c = getchar()) ; if (c == - ) { neg = 1; c = getchar(); } for (; c > 47 && c < 58; c = getchar()) { x = (... |
#include <bits/stdc++.h> template <typename T> inline void read(T &x) { char c; bool nega = 0; while ((!isdigit(c = getchar())) && (c != - )) ; if (c == - ) { nega = 1; c = getchar(); } x = c - 48; while (isdigit(c = getchar())) x = x * 10 + c - 48; if (nega) x = ... |
#include <bits/stdc++.h> using namespace std; long long modulo(long long base, long long exp, long long m); int main() { int x; cin >> x; if (x <= 1) cout << -1 ; else { cout << x << << x; } return 0; } long long modulo(long long base, long long exp, long long m) { ... |
#include <bits/stdc++.h> using namespace std; int n, i, last[28], tmp[28]; long long ans[28]; char s[300005]; int main() { scanf( %s , s); for (i = 0; i <= 26; i++) last[i] = -1; int length = strlen(s); for (i = 0; i < length; i++) { last[s[i] - a ] = i; for (int j = 0; j <= 26; j... |
#include <bits/stdc++.h> using namespace std; int main() { int n = 5, sum = 0; while (n--) { int a; cin >> a; sum += a; } if (sum == 0) { cout << -1 << endl; return 0; } cout << (sum % 5 == 0 ? sum / 5 : -1) << endl; } |
#include <bits/stdc++.h> using namespace std; const int INF = 1000000000; struct debugger { template <typename T> debugger& operator,(const T& v) { cerr << v << ; return *this; } } dbg; char b[100][100]; int n; bool in(int x) { return x >= 0 && x < n; } bool in(int x, int y) {... |
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 10, maxm = 2e6 + 10; const long long INF = 0x3f3f3f3f, mod = 1e9 + 7; int casn, n, m, k; namespace graph { vector<int> g[maxn]; int all, sz[maxn], root, maxt; bool vis[maxn]; int dfs_root(int now, int fa) { int cnt = 1; for (... |
#include <bits/stdc++.h> using namespace std; const int N = (int)1e5 + 113; const double eps = 1e-7; struct pt { long double x, y; int ind; pt(long double x = 0, long double y = 0, int ind = 0) : x(x), y(y), ind(ind) {} }; long double dist(pt a, pt b) { return (a.x - b.x) * (a.x - b.... |
#include <bits/stdc++.h> using namespace std; long long n, m, i, j, l, r, poss_rn, poss_rm, poss_n, poss_m, k, ans1, ans2; priority_queue<tuple<long long, int, int>> pq; map<pair<int, int>, bool> um; long long f(int x, int y) { long long a, b; if (x == poss_rn) a = poss_n; else a = 2; ... |
#include <bits/stdc++.h> using namespace std; int main() { long long a = 1, b = 1; int n; cin >> n; for (int i = 1; i <= n; i++) { a = a * 27 % 1000000007; b = b * 7 % 1000000007; } cout << (a + 1000000007 - b) % 1000000007; return 0; } |
#include <bits/stdc++.h> using namespace std; const int MXN = 2000010; int N, M; int A[MXN], B[MXN], T[32] = {}; void init() { scanf( %d%d , &N, &M); for (int i = 1; i <= N; i++) scanf( %d , A + i); for (int i = 1; i <= M; i++) scanf( %d , B + i), T[B[i]]++; } namespace solve { long long ans... |
#include <bits/stdc++.h> using namespace std; long long a[1000001]; int nodeNumber[1000001], nodeStart[1000001], nodeEnd[1000001], leftStart[1000001], leftEnd[1000001], rightStart[1000001], rightEnd[1000001]; void Initialise(int n) { sort(a + 1, a + n + 1); for (int i = 0; i <= n; ++i) { ... |
#include <bits/stdc++.h> int main() { int n, s, p, i, c; scanf( %d , &n); s = 1; while (1) { c = 0; p = n * s + 1; for (i = 2; i < p; i++) { if (p % i == 0) { c++; } } if (c >= 1) { break; } s++; } printf( %d n , s); ... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, x, c1 = 0, c2 = 0; bool flag = false; cin >> n; while (n--) { cin >> x; if (x == 100) ++c1; else ++c2; } if (c1 % 2 == 0) { if ((... |
#include <bits/stdc++.h> using namespace std; int F(int d); int G(int d); int n, ara[2 * 100010], dpf[2 * 100010], dpg[2 * 100010], k; bool visf[2 * 100010], visg[2 * 100010]; vector<int> vec; int add(int _a, int _b) { _a = (_a + 998244353) % 998244353; _b = (_b + 998244353) % 998244353; retur... |
#include <bits/stdc++.h> using namespace std; using lli = long long int; const int MOD = 1000000007; const int MOD1 = 998244353; const int maxn = 100010; const int lim = (int)1e9; struct flowEdge { int v, u; lli cap, flow = 0ll; flowEdge(int v, int u, lli cap) : v(v), u(u), cap(cap) {} }; ... |
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, t; cin >> n >> t; vector<int> books(n); for (int i = 0; i < n; i++) { cin >> books[i]; } int i, j; i = 0, j = 0; int ac = 0; int ans = 0; ... |
#include <bits/stdc++.h> #pragma comment(linker, /STACK:1024000000,1024000000 ) using namespace std; int ans, a[5010], K, n; map<int, int> g; int main() { int i, j, k, ca = 0, m; scanf( %d%d , &n, &K); for (i = 0; i < n; i++) scanf( %d , &a[i]); for (i = 0; i < n; i++) for (j = 1; j <= ... |
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; const double tiaohe = 0.57721566490153286060651209; long long oula(long long x) { long long res = x; for (register int i = 2; i <= x / i; ++i) { if (x % i == 0) { res = res / i * (i - 1); while (x % i == 0... |
#include <bits/stdc++.h> using namespace std; long long int ans[100000]; int main() { long long int n, m, mx, mn, i, j, k, diff, flag = 0, flag1 = 0, flag2 = 0; cin >> n >> m >> mn >> mx; long long int arr[m + 5]; for (i = 0; i < m; i++) { cin >> arr[i]; if (arr[i] == mn) flag1 = 1; ... |
#include<bits/stdc++.h> #define int long long #define ld long double #define fi first #define se second #define vll vector<int> #define pii pair<int,int> #define pb push_back #define sz(v) (int)(v).size() #define inf (int)(1e18) #define md (int)(998244353) #define all(v) (v).begin(),(v).end() #d... |
#include <bits/stdc++.h> using namespace std; const int maxn = 1005; struct node { int u, v, val; } ans[maxn * 10]; std::vector<int> g[maxn]; int n, tot; int in[maxn]; int x[maxn], y[maxn], val[maxn]; void addedge(int u, int v, int val) { ans[++tot] = (node){u, v, val}; } void find(int u, int fa... |
#include <bits/stdc++.h> using namespace std; char yam[1 << 23]; int main() { long long b, n, c; gets(yam); char *bp = yam; char *np = strchr(bp, ) + 1; char *cp = strchr(np, ) + 1; c = atoi(cp); for (b = 0; isdigit(*bp); bp++) { b = (10 * b + (*bp - 0 )) % c; } lo... |
/******** All Required Header Files ********/ #include <iostream> #include <string> #include <vector> #include <algorithm> #include <sstream> #include <queue> #include <deque> #include <bitset> #include <iterator> #include <list> #include <stack> #include <map> #include <set> #include <fun... |
#include <bits/stdc++.h> using namespace std; void file() {} const long long nax = 2e5 + 1, mod = 1e9 + 7; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); file(); int t; cin >> t; while (t--) { int n, m; cin >> n >> m; n *= 3; vector<in... |
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; long long ans = 0; long long total; long long tleft = 0; long long tright = 0; vector<pair<long long, long long> > soldier; for (long long i = 0; i < n; i++) { long long a, b; cin >> a >> b;... |
#include <bits/stdc++.h> using namespace std; const int MOD(1000000007); const int INF((1 << 30) - 1); const int MAXN(); map<string, int> d; int main() { d[ void ] = 0; int n; scanf( %d , &n); for (int i = 0; i < n; i++) { string a, b, c; cin >> a; if (a == typedef ) { ... |
#include <bits/stdc++.h> using namespace std; bool f[300010]; map<pair<int, int>, int> mp; vector<int> g[300010]; long long nm[300010], kk[300010], x, y, p; long long ans, n, i; void go(int now) { f[now] = 1; for (int i = 0; i < g[now].size(); i++) if (!f[g[now][i]]) if (nm[now] + nm... |
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; set<long long> v; set<long long>::iterator j; for (long long i = 1; i <= pow(n, 0.5); i++) { if (n % i == 0) { long long x = n / i; v.insert((x * (2 + (x - 1) * i)) / 2); v.insert((i *... |
#include <bits/stdc++.h> using namespace std; inline int dcmp(double a, double b) { return fabs(a - b) < (1e-9) ? 0 : a < b ? -1 : +1; } const int N = 1000 + 9; int pr[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31}; int ans[N]; vector<vector<int> > g; int x[N]; bitset<N> del; int main() { int ... |
#include <bits/stdc++.h> using namespace std; int gcd(int x, int y) { return y == 0 ? x : gcd(y, x % y); } int main() { int n, m, x, y, a, b; while (cin >> n >> m >> x >> y >> a >> b) { int g = gcd(a, b); a /= g; b /= g; g = min(n / a, m / b); a *= g; b *= g; int ... |
#include <bits/stdc++.h> using namespace std; vector<pair<long long, long long> > a; vector<long long> bus; long long n, t, z; int main() { cin >> n >> t; for (int i = 0; i < n; i++) { cin >> z; t -= z; } if (t > n - 1 || t < n - 1) { cout << NO ; } else cout << Y... |
#include <bits/stdc++.h> using namespace std; int main() { int n, d; cin >> n >> d; int a[n]; int x = 0; for (int i = 0; i < n; i++) { cin >> a[i]; x += a[i]; } if (x + (n - 1) * 10 > d) { cout << -1; } else { cout << 2 * n - 2 + (d - x - (n - 1) * 10) / 5; ... |
#include <bits/stdc++.h> using namespace std; long long arr[1000000], pref[1000000], suf[1000000]; int main() { long long n, k; cin >> n >> k; for (long long i = 0; i < n; i++) cin >> arr[i]; sort(arr, arr + n); for (long long i = 0; i < n; i++) pref[i + 1] = pref[i] + arr[i]; long long mi... |
#include <bits/stdc++.h> using namespace std; template <typename T, typename U> std::pair<T, U> operator+(const std::pair<T, U> &l, const std::pair<T, U> &r) { return {l.first + r.first, l.second + r.second}; } typedef void (*callback_function)(void); const long long INF64 = 1e18; const int INF32 = 1e... |
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using ii = pair<ll, ll>; using vi = vector<ll>; using vb = vector<bool>; using vvi = vector<vi>; using vii = vector<ii>; using vvii = vector<vii>; const int INF = 2000000000; const ll LLINF = 90000000000000... |
#include <bits/stdc++.h> using namespace std; int n; int a[200001]; int main() { cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; } sort(a, a + n); int k, h; k = a[n - 1] - a[1]; h = a[n - 2] - a[0]; if (k > h) { cout << h; } else { cout << k; } ... |
#include <bits/stdc++.h> using namespace std; int r[10005]; struct N { int l, r, x; } p[10005]; bool cmp(N a, N b) { return a.l < b.l; } bool vis[10005]; int main() { int n, q; cin >> n >> q; memset(vis, 0, sizeof vis); for (int i = 0; i < q; i++) { cin >> p[i].l >> p[i].r >> p[i... |
#include <bits/stdc++.h> using namespace std; struct nod { int x, y; } num[110000]; struct nod2 { int qian, zhi; } bian[110000]; struct nod3 { int ls, rs, l, r, mi; } t[410000]; int n, p, a, b, mi, i, x[110000], wei[410000], use[110000], use2[110000], w[110000]; int build(int l, int ... |
#include <bits/stdc++.h> using namespace std; long long m, l, r, k, n; long long a[2][2], b[2][2]; void cc(long long a[2][2], long long b[2][2]) { for (int i = 0; i < 2; i++) for (int j = 0; j < 2; j++) a[i][j] = b[i][j]; } void mul(long long a[2][2], long long b[2][2], long long m) { long lon... |
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int total; cin >> total; while (total--) { int n, k, cont_l = 0, cont_r = 0; vector<pair<int, int> > ans; string s; cin >> n >> k; cin >> s; fo... |
#include <bits/stdc++.h> using namespace std; const long long maxN = 1e18; const long long minN = -1e18; const long long MOD = 1e9 + 7; const long long MOD1 = 998244353; const int baseHash = 331; const int bigNumLength = 5000; const long double PI = acos(-1); const long long limit = 2e5 + 5; const l... |
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; long long ans = 0; for (int i = (0); i < (n); ++i) { long long t, T, x, cost; cin >> t >> T >> x >> cost; if (t >= T) { ans += cost + m * x; continue; } long long aux1 = ... |
#include <bits/stdc++.h> using namespace std; const long long inf = 1e9 + 10, N = 2e6 + 10, mod = 1e9 + 7, LG = 20, SQ = 450; long long n, T[N], L[N], dp[N], ps[N]; inline void KMP(string s) { long long k = -1; T[0] = -1; for (int i = 1; i < s.size(); i++) { while (k != -1 and s[k + 1] != s[i]... |
#include <bits/stdc++.h> using namespace std; int n, m; int main() { cin >> n >> m; if (m == 3 && n >= 5) { cout << -1 << endl; return 0; } for (int i = 1; i <= m; i++) { cout << i << << i * i + 10000000 << endl; } for (int i = 1; i <= n - m; i++) { cout << i <<... |
#include <bits/stdc++.h> using namespace std; const int N = 55; int n, d, a[N], dp[N * 10005], gao[N * 10005]; vector<int> v; int main() { int sum = 0; cin >> n >> d; for (int i = 1; i <= n; i++) { cin >> a[i]; sum += a[i]; } dp[0] = 1; for (int i = 1; i <= n; i++) { ... |
#include <bits/stdc++.h> using namespace std; int N; long long arr[200010]; long long factorial[200010]; long long factinv[200010]; long long fact[200010]; long long ans; long long pw(long long a, long long b) { a %= 1000000007; if (b == 0) { return 1ll; } if (b == 1) { retur... |
#include <bits/stdc++.h> using namespace std; struct seg { int l, r, i; bool operator<(const seg& b) const { return l < b.l; } }; int n, k; seg a[200005]; bool u[400005]; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cerr.tie(nullptr); cin ... |
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; cout << n / 2 << endl; if (n % 2 == 0) { for (int i = 0; i < n / 2; i++) { cout << 2 ; } } else { for (int i = 0; i < n / 2 - 1; i++) { cout << 2 ; } cout << 3; } }... |
#include <bits/stdc++.h> using namespace std; const int N = 3e3 + 10; int n; int a[N], b[N]; long long dp[N][N]; long long solve(int idx = 0, int val = 0) { if (idx == n) return 0; if (val == n) return 1e18; long long &ret = dp[idx][val]; if (ret == -1) ret = min(solve(idx + 1, val) + ... |
#include <bits/stdc++.h> using namespace std; int main() { string ans, s; int n, t, p; char ch; scanf( %d , &n); ans.clear(); for (int i = 1; i <= n; i++) { t = i; s.clear(); while (t > 0) { p = t % 10; ch = p + 0 ; s = ch + s; t = t / 10; ... |
#include <bits/stdc++.h> using namespace std; int n, x, zhan[100500], tree[100500], o, ans[100500], now = 1; struct edge { int x, t, id, r; bool operator<(const edge &xx) const { if (x != xx.x) return x < xx.x; return id < xx.id; } } aa[100500]; void add(int x, int y) { for (int i ... |
#include <bits/stdc++.h> using namespace std; int n, m, cnt, num[100010], w[100010]; int x[100010], y[100010]; struct edge { int w, f, id; } e[100010]; inline bool operator<(edge a, edge b) { return a.w < b.w; } int main() { scanf( %d%d , &n, &m); for (int i = 1; i <= m; i++) { scanf( %d... |
#include <bits/stdc++.h> int main() { int n; while (scanf( %d , &n) != EOF) { int ans = 0; int sum = 0; while (n--) { int x; scanf( %d , &x); if (x == -1) { if (!sum) ans++; else sum--; } else sum += x; ... |
#include <bits/stdc++.h> #pragma gcc optimize( O3, unroll-loops ) using namespace std; const int mod = 1000000007; int gcds[4001][4001]; int64_t fpow(int i, int j) { int64_t ans = 1; while (j--) ans *= i; return ans; } signed main() { cin.tie(0); ios_base::sync_with_stdio(0); int64... |
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) using namespace std; long long int gcd(long long int a, long long int b) { if (!b) return a; else return gcd(b, a % b); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int t; cin >> t; while (t--) { i... |
#include <bits/stdc++.h> using namespace std; int n, k, n1, ans, m, per1, per2, add; const int maxn = 1000007; long long tree[maxn * 4][4]; void build() { for (int j = n1 - 1; j < n1 + n - 1; j++) { tree[j][0] = j - n1 + 2; tree[j][1] = j - n1 + 2; tree[j][2] = 0; tree[j][3] = 0; ... |
#include <bits/stdc++.h> using namespace std; const double eps = 1e-10; int dblcmp(double d) { if (fabs(d) < eps) return 0; return (d > 0) ? 1 : -1; } int n, m, T; bool win(long long a, long long b) { if (a * b == 0) return false; if (a > b) swap(a, b); if (!win(a, b % a)) return 1; ... |
#include<bits/stdc++.h> #define N 5000007 #define M 200007 #define ll long long const ll Mod=1000000007; using namespace std; inline int read() { int x=0,f=1;char ch=getchar(); while(!isdigit(ch)){if(ch== - )f=-1;ch=getchar();} while(isdigit(ch)){x=(x<<1)+(x<<3)+ch- 0 ;ch=getchar();} ret... |
#include <bits/stdc++.h> using namespace std; vector<int> di = {0, 0, 1, -1}; vector<int> dj = {1, -1, 0, 0}; int main() { ios::sync_with_stdio(0), cin.tie(0); vector<vector<int>> dpa(1001, vector<int>(1001, 2140000000)); vector<vector<int>> dpb(1001, vector<int>(1001, 2140000000)); vector<vecto... |
#include <bits/stdc++.h> using namespace std; template <typename Arg1> void __f(const char* name, Arg1&& arg1) { cout << name << : << arg1 << endl; } template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args) { const char* comma = strchr(names + 1, , ); ... |
#include<bits/stdc++.h> using namespace std; #define lop(i,n) for(ll i=0;i<n;i++) #define lop1(i,n) for(ll i=1;i<=n;i++) #define lopr(i,n) for(ll i=n-1;i>=0;i--) #define ll long long int #define pb push_back #define all(v) v.begin(),v.end() #define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0... |
#include <bits/stdc++.h> template <typename _Tp> void read(_Tp &x) { char ch(getchar()); bool f(false); while (!isdigit(ch)) f |= ch == 45, ch = getchar(); x = ch & 15, ch = getchar(); while (isdigit(ch)) x = x * 10 + (ch & 15), ch = getchar(); if (f) x = -x; } template <typename _Tp, ty... |
#include <bits/stdc++.h> using namespace std; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long t; cin >> t; while (t--) { string s; cin >> s; long long a[26] = {0}; long long cnt = 0; for (long long i = 0; i < s.size();... |
#include <bits/stdc++.h> using namespace std; int main(void) { int n, i, sum; int a[100010]; scanf( %d , &n); for (i = 0; i < n; i++) scanf( %d , &a[i]); sort(a, a + n); sum = a[n - 1]; int f = 1; for (i = 0; i < n - 1; i++) { sum -= a[i]; if (sum < 0) { f = 0; ... |
#include <bits/stdc++.h> const int N = 1e6 + 10; const int mod = 1e9 + 7; const int INF = 0x3f3f3f3f; using namespace std; int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } int lcm(int a, int b) { return a / gcd(a, b) * b; } inline int read() { int X = 0; bool flag = 1; char ch = getchar... |
#include <bits/stdc++.h> using namespace std; int main() { int n, k; int i, j, K; int num[101]; memset(num, 0, sizeof(num)); cin >> n >> k; for (i = 0; i < n; i++) { scanf( %d , &K); num[K]++; } int cut = 0; int Max = 0; for (i = 1; i <= 100; i++) { if (num[... |
#include <bits/stdc++.h> #pragma GCC optimize( O2 ) #pragma GCC optimize( unroll-loops ) using namespace std; const long double eps = 1e-7; const int inf = 1000000010; const long long INF = 10000000000000010LL; const int mod = 1000000007; const int MAXN = 1010, K = 51; int n, m, k, u, v, x, y, t, a, b... |
#include <bits/stdc++.h> using namespace std; const long long N = 200200, M = 110, K = 30030, Inf = 1e17; void Max(long long &x, long long y) { x = max(x, y); } long long dp[4 * K]; long long a[M], b[M]; vector<pair<long long, long long>> p, neg; bool cmp(pair<long long, long long> p1, pair<long long, lon... |
#include <bits/stdc++.h> using namespace std; int n; namespace LCT { int fa[500005], ch[500005][2]; bool rev[500005], val[500005]; bool isr(int x) { return ch[fa[x]][0] != x && ch[fa[x]][1] != x; } bool isc(int x) { return ch[fa[x]][1] == x; } void upd(int x) { val[x] = val[ch[x][0]] | val[ch[x][1]] | (... |
#include <bits/stdc++.h> using namespace std; int a[3005], b[3005], c[3005], vis[3005]; bool cmp(int i, int j) { return a[i] > a[j]; } int main() { vector<int> p, q; int T, i, j, k, ca = 0, n, m, K; int s, t; scanf( %d%d%d , &n, &s, &t); for (int i = 0; i < n; i++) { scanf( %d , &a[i])... |
#include <bits/stdc++.h> using namespace std; int n, m, a, b; vector<pair<int, int> > des[110]; int dist(int i, int j) { if (i <= j) return j - i; return n - i + j; } bool cmp(pair<int, int> a, pair<int, int> b) { int i = a.second; int x = a.first, y = b.first; return dist(i, x) < dist(i... |
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10; long long a[maxn], b[maxn]; long long dp[maxn]; int n; int main() { scanf( %d , &n); for (int i = 1; i <= n; i++) { scanf( %lld , &a[i]); a[i] -= i; b[i] = a[i]; } sort(b + 1, b + 1 + n); memset(dp... |
#include <bits/stdc++.h> using namespace std; int Q, n, m, ans[600005], a[505][505]; char S[505]; struct O { int p, q, x, y, i; } o[600005], O[600005]; bitset<505> f[505][505], g[505][505]; void go(int l, int r, int p, int q) { if (p > q) return; int mi = l + r >> 1, L, R, t; for (int i = ... |
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 7; const int inf = 0x3f3f3f3f; const int mod = 1e9 + 7; const double pi = acos(-1.0); const double G = 6.67430e-11; int n, q; set<int> p; multiset<int> d; void in(int x) { p.insert(x); if (p.size() == 1) return; auto po... |
#include <bits/stdc++.h> using namespace std; const int MAX = 1e5 + 2, MAX2 = 2e6 + 4; int ans[MAX], val[MAX], depth[MAX]; vector<int> G[MAX], d[MAX2], occ[MAX2]; void init(int a) { if (d[a].size()) return; for (int i = 2; i * i <= a; i++) { if (a % i == 0) { d[a].push_back(a / i); ... |
#include <bits/stdc++.h> using namespace std; const int maxn = 27, maxm = 5e4 + 20, inf = 1e9; vector<int> ar[maxn][maxn][maxn][maxn]; int q, a[maxm], bs[4], bs2[4]; string s, qs, qss; map<pair<string, string>, int> mp; int main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); cin >> s >... |
#include <bits/stdc++.h> using namespace std; int deg[100000], x[100000]; map<pair<int, int>, int> m; vector<pair<int, int> > v; int main() { int n, k; scanf( %d , &n); for (int i = 0; i < n; i++) { scanf( %d %d , °[i], &x[i]); if (deg[i] > 0) { pair<int, int> a; a.f... |
#include <bits/stdc++.h> using namespace std; const long long mod = 7340033; long long n, k; long long DP[100][1009], dp[100][1009]; long long DFS(int h, int k); long long dfs(int h, int k) { long long &d = dp[h][k]; if (~d) return d; d = 0; for (int i = 0; i <= k; i++) d = (d + DFS(h ... |
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 10; int ku[maxn], kd[maxn], posu[maxn], posd[maxn]; long long tl[maxn], tr[maxn]; int main() { int n; cin >> n; char s[maxn]; scanf( %s , s + 1); int a = 0, b = 0; for (int i = 1; i <= n; i++) { ku[i + 1] = ku[i... |
#include <bits/stdc++.h> #pragma GCC optimize( Ofast,no-stack-protector,unroll-loops ) #pragma GCC optimize( no-stack-protector,fast-math ) #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native ) using namespace std; const int N = 5e5 + 100, OO = 1e6, T = (1 << 20) + 10, M = 998244353, P... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int TESTS = 1; cin >> TESTS; while (TESTS--) { int n; cin >> n; string s; cin >> s; if ((long long int)s.size() == 1) cout << NO n ; ... |
#include <bits/stdc++.h> int solve(int c, int d, int n, int m, int k) { int s = n * m; if (k >= n * m) return 0; s = n * m - k; int sum = 0; while (1) { if (s <= n) { if (c < s * d) sum += c; else sum += s * d; break; } if (c < n * d) ... |
#include <bits/stdc++.h> using namespace std; const int inf = 1e9; const int maxn = 100 + 10; long long ma[100]; void init() { long long x = 1; for (int i = 0; i <= 32; i++) { ma[i] = x; x *= 2; } } int main() { init(); int T; scanf( %d , &T); while (T--) { lo... |
#include <bits/stdc++.h> using namespace std; int main() { int n, m, p = 0; cin >> n >> m; if (n == 1 && m != 0) { cout << m << << m << endl; return 0; } else if (m == 1 && n != 0) { cout << n << << n << endl; return 0; } else if (n == 0 && m == 0) { cout <<... |
#include <bits/stdc++.h> using namespace std; int main() { long long n, k, s; cin >> n >> k >> s; if ((n - 1) * k < s || s < k) { cout << NO n ; return 0; } cout << YES n ; long long m = s / k; int rem = s % k; int count = 0; int room = 1; for (; count < rem; ++... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.