func_code_string stringlengths 59 71.4k |
|---|
#include <bits/stdc++.h> using namespace std; const long long N = 1e5 + 5; const long long INF = 1e10; const int MOD = 1e9 + 7; const double EPS = 1e-7; const double PI = acos(-1.0); pair<long long, long long> p[N]; long long n, k, a[N]; int main() { ios::sync_with_stdio(false); cin.tie(NULL),... |
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; const int infi = 2147483600; const long long infl = 1e17; int n; pair<int, int> pbef[200005]; struct SegmentTree { private: int N; vector<long long> node; long long e; public: SegmentTree() {} Segment... |
#include <bits/stdc++.h> using namespace std; const int N = 200200; struct BIT { int a[N]; void add(int x, int v = 1) { for (; x < N; x += x & -x) { a[x] += v; } } int kth(int k) { int x = 0; for (int i = 18; i >= 0; i--) { if (x + (1 << i) < N) { ... |
#include <bits/stdc++.h> using namespace std; template <typename Arg1> void __f(const char* name, Arg1&& arg1) { cout << name << : << arg1 << n ; } 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; int mostFrequent(int arr[], int n) { sort(arr, arr + n); int max_count = 1, res = arr[0], curr_count = 1; for (int i = 1; i < n; i++) { if (arr[i] == arr[i - 1]) curr_count++; else { if (curr_count > max_count) { max_cou... |
#include <bits/stdc++.h> using namespace std; const int mod = 998244353; const int N = 100005; int n, x, y, a, b, jc[N], ans; char s[2]; int ksm(int a, int k) { int ret = 1; while (k) { if (k & 1) ret = 1ll * ret * a % mod; a = 1ll * a * a % mod; k >>= 1; } return ret; } ... |
#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; int main() { long long int n, a, b, max_dollars, min_tokens, n_tokens; string raw_input; cin >> n >> a >> b; vector<string> tokens(n); for (int i = 0; i < n; i++) cin >> tokens[i]; for (int i = 0; i < n; i++) { n_tokens = stoll(tokens[i]); ... |
#include <bits/stdc++.h> using namespace std; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int t, x, y, a, b; cin >> t; while (t--) { cin >> x >> y >> a >> b; if (2 * a < b) cout << a * (x + y) << n ; else cout << b * min(x, y) +... |
#include <bits/stdc++.h> using namespace std; int main() { int tc; cin >> tc; while (tc--) { int n; cin >> n; string s; cin >> s; if (n == 2) { if (s[0] >= s[1]) { cout << NO << n ; } else { cout << YES ... |
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const int mod = 1e9 + 7; const int maxn = 1000000 + 5; const double PI = acos(-1.0); const double E = 2.718281828459; const double eps = 1e-7; int T, n, num[100005]; int main() { long k, n = 19, x = 0, m; scanf( %ld , &k... |
#include <bits/stdc++.h> using namespace std; vector<int> solve(int n) { vector<int> v(n, 1); if (n == 1) return v; if (n == 2) { v[0] = 3, v[1] = 4; return v; } int k = n - 1; if (k & 1) { int p = k >> 1; v[n - 1] = p; } else { k = k - 1 + 4; int p = ... |
#include <bits/stdc++.h> using namespace std; int main() { int a, b, n, d, x, y; vector<pair<int, int> > v; cin >> n >> d >> a >> b; for (int i = 0; i < n; i++) { cin >> x >> y; v.push_back({x * a + y * b, i}); } sort(v.begin(), v.end()); long long sum = 0, in = 0; for (i... |
#include <bits/stdc++.h> using namespace std; int hy, ay, dy; int hm, am, dm; int h, a, d; bool firstok = true; bool ok(int H, int A, int D) { int d1 = max(0, A - dm); int d2 = max(0, am - D); if (d1 == 0 && d2 == 0) return false; if (d2 == 0) return true; if (d1 == 0) return false; ... |
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[n * 2], b[n * 2]; for (int i = 0; i < (n); ++i) { cin >> a[i] >> b[i]; a[i + n] = a[i]; b[i + n] = b[i]; } int flag = 1; if (n % 2 == 1) flag = 0; for (int i = 0; i < (n); ++i) { ... |
#include <bits/stdc++.h> using namespace std; int main() { long long t, n; cin >> n; if (n == 0) cout << 1 << endl; else if (n % 4 == 1) cout << 8 << endl; else if (n % 4 == 2) cout << 4 << endl; else if (n % 4 == 3) cout << 2 << endl; else cout << 6 << endl... |
#include <bits/stdc++.h> using namespace std; int LIS(vector<int> A) { int N = A.size(), i; multiset<int> s; multiset<int>::iterator k; for (i = 0; i < N; i++) { s.insert(A[i]); if (1) { k = s.find(A[i]); k++; if (k != s.end()) s.erase(k); } } return... |
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } int current = 1, maxtotal = 0; for (int i = 0; i < n; i++) { current = 1; for (int j = i; j < n - 1 && a[j] >= a[j + 1]; j++, current++) ... |
#include <bits/stdc++.h> using namespace std; const int maxx = 1e5 + 20; long long a[maxx]; int main() { int n, i; cin >> n; for (i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); int r; while (a[0] % 2 == 0) a[0] /= 2; while (a[0] % 3 == 0) a[0] /= 3; r = a[0]; for (i = 1; i <... |
#include <bits/stdc++.h> using namespace std; struct CC { long long x1, x2, y1, y2; }; CC jiao(CC a, CC b) { CC c1; c1.x1 = max(a.x1, b.x1); c1.y1 = max(a.y1, b.y1); c1.x2 = min(a.x2, b.x2); c1.y2 = min(a.y2, b.y2); return c1; } int main() { CC w, b1, b2; cin >> w.x1 >> w... |
#include <bits/stdc++.h> using namespace std; int n, m, a[22], b[22], d[22][44], mat[44][44], res[44][44], t[44][44]; void calc(int x[44][44], int y[44][44], int z[44][44]) { for (int i = 0; i <= 2 * n; ++i) for (int j = 0; j <= 2 * n; ++j) { t[i][j] = (int)(2e9); for (int k = 0; k <= 2 ... |
#include <bits/stdc++.h> const int Inf = 2e9; long long LINF = (long long)4e18; using namespace std; int r1, r2, c1, c2, d1, d2; bool ok(int i, int j, int k, int l) { if (i + j != r1) return false; if (k + l != r2) return false; if (i + k != c1) return false; if (j + l != c2) return false; ... |
#include <bits/stdc++.h> using namespace std; const int Maxn = 22; int n; int col[Maxn]; int main() { scanf( %d , &n); int cur = 0; for (int a = 0; cur < n; a++) { bool good = true; for (int i = 0; i < cur && good; i++) for (int j = i + 1; j < cur && good; j++) for (i... |
#include <bits/stdc++.h> using namespace std; long long t, n, k, z, x, s, a[31], v[31][101], c[31]; int main() { ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); ; cin >> t; for (int zxc = 1; zxc <= t; zxc++) { cin >> n >> k; for (int i = 1; i <= 30; i++) for (int j =... |
#include <bits/stdc++.h> using namespace std; int get(int xt) { int ans = 0; for (int i = 0; i < 8; i++) { ans *= 2; ans += xt % 2; xt /= 2; } return ans; } int main() { char a[110] = ; gets(a); int len = strlen(a); int xt = 0; for (int i = 0; i < len; i++... |
#include <bits/stdc++.h> using namespace std; const int N = 5e3 + 7; int dp[N][N]; int cnt[N * N]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; int a[n]; memset(dp, 0, sizeof(dp)); memset(cnt, 0, sizeof(cnt)); for (int i = 0; i < n; i++) cin >>... |
#include <bits/stdc++.h> using namespace std; int query(vector<int>& v) { cout << ? ; for (auto& x : v) { cout << x << ; } cout << endl; int a; cin >> a; return a; } void solve(int n) { int x = 1; vector<int> v(n, 1); for (int i = n; i >= 2; i--) { for (i... |
#include <bits/stdc++.h> using namespace std; const int maxn = 1010; int n, m, maxw, tot, w[maxn], b[maxn], fa[maxn], sumw[maxn], sumb[maxn], dp[maxn << 1][maxn], f[maxn]; vector<int> child[maxn]; vector<pair<int, int> > vec; unordered_set<int> ancestor; void init() { for (int i = 1; i <= n; i++... |
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; long long a[N], n; int to_sorted[N]; int to_nature[N]; bool done(int i, int d) { bool lef = (i == 0 || a[i - 1] < a[i] - d); bool rig = (i == n - 1 || a[i] + d < a[i + 1]); return lef && rig; } int front(int, int); int ba... |
#include <bits/stdc++.h> using namespace std; int n, m, viz[100005], cnt, nr, x[100005], nrans, ans[400005], rad; vector<int> v[100005]; void dfs1(int nod) { viz[nod] = 1; nr += x[nod]; for (auto x : v[nod]) if (!viz[x]) dfs1(x); } void dfs(int nod, int tata) { viz[nod] = 1; nrans+... |
#include <bits/stdc++.h> using namespace std; int main() { int i, j, k, m, n, a[1000], b[1000], t = -1; cin >> n >> m; for (i = 0; i < n; i++) { cin >> a[i]; } for (i = 0; i < m; i++) { cin >> b[i]; } sort(a, a + n); sort(b, b + m); for (i = a[n - 1]; i < b[0]; i++) {... |
#include <bits/stdc++.h> using namespace std; void __print(int x) { cerr << x; } void __print(long x) { cerr << x; } void __print(long long x) { cerr << x; } void __print(unsigned x) { cerr << x; } void __print(unsigned long x) { cerr << x; } void __print(unsigned long long x) { cerr << x; } void __prin... |
#include <bits/stdc++.h> int t, s, x; int main() { scanf( %d%d%d , &t, &s, &x); if (x == t) { printf( YES n ); return 0; } for (int i = 1; i * s + t <= x; i++) if (i * s + t == x || i * s + t + 1 == x) { printf( YES n ); return 0; } printf( NO n ); ret... |
#include <bits/stdc++.h> using namespace std; const int maxN = 3042, mod = 1000000007; const int modHash = 2013023017; inline void add_mod(long long& a, long long b) { a = (a + b) % mod; } inline void mult_mod(long long& a, long long b) { a = a * b % mod; } long long dp[maxN][maxN], pref[maxN]; unordered_... |
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; char ch[n + 1]; cin >> ch; int ar[200] = {0}; for (int i = 0; i < strlen(ch); i++) { ar[ch[i]]++; } sort(ar, ar + 200); if (ar[199] > k) cout << NO << endl; else cout << Y... |
#include <bits/stdc++.h> using namespace std; const int MX = 300000; int arr[MX], state[MX], n, m, meet[MX], cur, is[MX], lastoff[MX]; int pres[MX]; pair<int, int> last; vector<pair<int, int> > v[MX]; vector<int> ans; char cc; int main() { memset(meet, -1, sizeof(meet)); memset(is, 0, sizeof(i... |
#include <bits/stdc++.h> using namespace std; const int mod = 1e5 + 50; const int maxn = 1e7 + 50; const int inf = 0x3f3f3f3f; unordered_map<int, bool> mp; vector<int> vec; int main() { int T; scanf( %d , &T); while (T--) { mp.clear(); vec.clear(); int n, t; scanf( %d ,... |
#include <bits/stdc++.h> using namespace std; int main() { double ans, B, H; cin >> ans; double ff = 999999999.9; for (double h = 1; h <= 10; h++) { for (double b = 1; b <= 10; b++) { double sum = h * b / sqrt(4 * h * h + b * b); double d = fabs(ans - sum); if (d < ff) ... |
#include <bits/stdc++.h> using namespace std; int main() { long long l, r; cin >> l >> r; long long x = r, y = 0; while (x > 0) { ++y; x /= 10; } x = 5; long long k = y; for (int i = 0; i < k - 1; ++i) { x *= 10; } if (r < x) x = r; else if (l > x)... |
#include <bits/stdc++.h> using namespace std; typedef struct { int y, i; double p; } ele; int cmp(ele a, ele b) { return a.y > b.y || (a.y == b.y && a.i > b.i); } vector<ele> pu[100514]; int a[100514]; double dp[5140][5140]; int mp[5140]; vector<int> e[5140]; ele sk[5140]; int top; void ... |
#include <bits/stdc++.h> using namespace std; int dp[50004][8]; int main() { int m, n; cin >> m >> n; for (int i = 1; i <= m; i++) { for (int j = 1; j <= n; j++) cin >> dp[i][j]; } for (int i = 1; i <= m; i++) dp[i][1] += dp[i - 1][1]; for (int i = 1; i <= n; i++) dp[1][i] += dp[1][i... |
#include <bits/stdc++.h> using namespace std; int main() { int n, x, y; int p = 1; cin >> n; cin >> x; cin >> y; p = n * y; if (p % 100 != 0) p = p / 100 + 1; else p = p / 100; if (p <= x) cout << 0 << endl; else cout << p - x << endl; return 0; ... |
#include <bits/stdc++.h> using namespace std; const int dx[9] = {0, 1, -1, 0, 0, -1, -1, 1, 1}; const int dy[9] = {0, 0, 0, -1, 1, -1, 1, -1, 1}; const double pi = acos(-1.0); const int N = 1e5 + 100; long long pre[N], a[N], temp[200], ans = 0; int n, k, ma = 0; map<long long, long long> dic; int main... |
#include <bits/stdc++.h> using namespace std; inline void smin(int &a, const int &b) { if (b < a) a = b; } inline void smax(int &a, const int &b) { if (b > a) a = b; } int first[4], second[4], f[4], ans; vector<int> dst, vx, vy; pair<int, int> p[4], mp[4]; inline void solve(int X, int Y, int d... |
#include <bits/stdc++.h> using namespace std; bool isprime(long long int n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; for (int i = 5; i * i <= n; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } vector<lo... |
#include <bits/stdc++.h> using namespace std; long long int fast_expo(long long int x, long long int p) { if (p == 0) return 1; else if (p % 2 == 0) { long long int t = fast_expo(x, p / 2) % 1000000007; return (t * t) % 1000000007; } else return (x * (fast_expo(x, p - 1)) % 10000... |
#include <bits/stdc++.h> using namespace std; const int INF = 0x3fffffff; const long long _INF = 0x7ffffffffffffffll; const double EPS = 1e-9; const double PI = acos(-1.0); template <class T, class INT> inline T pow(T x, INT y) { T res(1); for (T tt(x); y; y /= 2) { if (y & 1) res *= tt; ... |
#include <bits/stdc++.h> using namespace std; const long long int is_query = LLONG_MIN; struct Line { long long int m, b; mutable function<const Line*()> succ; bool operator<(const Line& rhs) const { if (rhs.b != is_query) return m < rhs.m; const Line* s = succ(); if (!s) return 0; ... |
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; long long m(long long a, long long b) { return (a * b) % mod; } long long d(long long a, long long b) { return (a + b) % mod; } long long pow(long long a, int k) { long long ans = 1; while (k) { if (k & 1) { ... |
#include <bits/stdc++.h> using namespace std; int main() { int n, a, sum = 0; cin >> n; for (int i = 0; i < n; i++) { cin >> a; sum += a; } cout << sum / n; return 0; } |
/* not_stable but Believer */ /* Practice for Expert */ #include<bits/stdc++.h> #define int long long #define io ios_base::sync_with_stdio(false),cin.tie(nullptr); #define ipair pair<int,char> #define pb push_back #define f(i, n) for(int i=0;i<n;i++) #define F(i, n) for(int i=0;i<n;i++) #define rep(i,... |
#pragma GCC optimize( Ofast ) #pragma GCC target( avx,avx2,fma ) #include <bits/stdc++.h> /* GOURAB SARKAR */ using namespace std; typedef long long ll; typedef long double ld; #define PI 3.141592653589793238 #define dl n #define mm... |
#include <bits/stdc++.h> using namespace std; string s; void output(const string& block) { string t; istringstream in(block); while (in >> t) cout << t; cout << endl; } int main(int argc, char* argv[]) { string block; string em; em += char(1); block = em; while (getline(cin... |
#include <bits/stdc++.h> using namespace std; bool dp[1005][1005]; vector<int> v; int b[1005], A[1005]; int Find(int A[], int x) { int root = x, tmp; while (A[root] >= 0) root = A[root]; while (x != root) { tmp = x; x = A[x]; A[tmp] = root; } return root; } void Union... |
#include <bits/stdc++.h> using namespace std; int main() { int n; string s; cin >> n >> s; queue<int> q; int cntD = 0, cntR = 0; for (int i = 0; i < n; i++) { if (s[i] == R ) cntR++; else cntD++; q.push(i); } int removeD = 0, removeR = 0; while ... |
#include <bits/stdc++.h> using namespace std; long long gcd(long long x, long long y) { return y == 0 ? x : gcd(y, x % y); } mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); void solve() { int n, m; scanf( %d%d , &n, &m); vector<long long> w(n + 1), c(n + 1), adj(n + 1); m... |
#include <bits/stdc++.h> using namespace std; const int kN = 5000 + 1; const int kInf = 1000 * 1000 * 1000; int dp[kN], inp[kN]; int main() { int n, m; cin >> n >> m; for (int i = 0; i < n; ++i) { double val; cin >> inp[i] >> val; } dp[0] = 1; for (int i = 1; i < n; ++i) { ... |
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; long long a[n], b[n]; for (int i = 0; i < n; i++) scanf( %lld , a + i); for (int i = 0; i < n; i++) { scanf( %lld , b + i); } long long count = 0, index = 0; set<long long> s; for (int i = 0; ... |
#include <bits/stdc++.h> using namespace std; int n, m, maxw; int w[1010]; int b[1010]; int dsu[1010]; int DSU(int u) { return dsu[u] == u ? u : dsu[u] = DSU(dsu[u]); } vector<pair<int, int> > ops[1010]; int dp[1010], newdp[1010]; int main() { scanf( %d%d%d , &n, &m, &maxw); for (int i = 1; i ... |
#include <bits/stdc++.h> using namespace std; long long int n, k, p[100005]; long long int dp[100005]; long long int f(long long int s) { if (dp[s] != -1) return dp[s]; if (p[s] == 0) { long long int lo = max(0LL, s - k - 1); long long int hi = min(n, s + k); return dp[s] = max(0LL, hi... |
#include <bits/stdc++.h> using namespace std; const int mxN1 = 1e5, mxN2 = 1 << 18, INF = 1e9; struct dat { int len = 0, max; vector<pair<int, int>> pref, suf; } tree[mxN2]; int n, q, qt; string ss[mxN1]; inline void cmb(dat &d, dat &a, dat &b) { d.len = a.len + b.len; d.max = max(a.max, b... |
#include <bits/stdc++.h> using namespace std; int sum[1000000 + 5]; int n, k, maxnum, minnum; bool check(int p) { for (int i = 0; i < maxnum; i += p) { int l = i + k; int r = min(maxnum, i + p - 1); if (l < r && sum[r] - sum[l] > 0) return false; } return true; } int main() { ... |
#include <bits/stdc++.h> using namespace std; template <typename T> void out(T x) { cout << x << endl; exit(0); } const long long mod = 1e9 + 7; const int maxn = 1e6 + 5; struct Edge { int u, v, w, i; }; int n, m; Edge edge[maxn]; vector<int> g[maxn]; map<int, vector<int>> mp; int ... |
#include <bits/stdc++.h> using namespace std; int N; int A[205]; int cnt[2]; bitset<20005> compo; int cap[205][205]; int par[205]; int macflow; vector<int> pp[205]; vector<int> adj[205]; void edge(int u, int v, int c) { cap[u][v] = c; adj[u].push_back(v); adj[v].push_back(u); } voi... |
#include <bits/stdc++.h> using namespace std; vector<int> disp[500][500]; int n, m, a, b; int pos[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}}; class edge { public: int e, nxt, cap; edge(int e1 = -1, int nxt1 = -1, int cap1 = 0) { e = e1, nxt = nxt1, cap = cap1; } }; int S, T; int dep... |
#include <bits/stdc++.h> using namespace std; int A[1000005], B[1000005]; int ans = 0; int C[35]; int main() { int n, m, i, j, k, l; scanf( %d%d , &n, &m); for (i = 1; i <= n; i++) { scanf( %d , &A[i]); long long t = 1; for (j = 0; j < 33; j++) { C[j] += ((A[i] & t) != 0)... |
#include <bits/stdc++.h> using namespace std; const int INF = (int)1e9; const int mod = (int)1e9 + 7; const int MAXN = (int)3e5 + 5; vector<long long> primes[1000005]; bool vis[1000005]; long long x, p, k; vector<pair<int, int> > v(1 << 7); long long calc(long long a) { int cnt = 1; int num = ... |
#include <bits/stdc++.h> using namespace std; const int MAX_N = 1e2 + 10; const long long mod = 1e9 + 7; const long long INF = 1e9; inline long long bpow(long long t, long long n) { long long ans = 1; while (n > 0) { if (n & 1) ans = (ans * t) % mod; t = (t * t) % mod, n >>= 1; } r... |
#include<bits/stdc++.h> using namespace std; using ll = long long int; using vi = vector<int>; #define f(n) for(int i = 0; i < n; i++) #define fj(n) for(int j = 0; j < n; j++) #define fk(n) for(int k = 0; k < n; k++) #define ci(n) cin >> n; #define ic(n) int n; cin >> n; #define lc(n) int n; cin... |
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 1; struct data { int l, r, sum; } tree[N << 2], sum_tree[N << 2]; struct node { int to, next; } a[N << 1]; int ans1 = 0, ans2 = 0, dp[N], head[N], st[N], ed[N], g[N][25], bx[N], by[N], bw[N], deep[N]; int n, m, cnt = 0; ve... |
#include <bits/stdc++.h> using namespace std; long long n, ans; string str; long long solve() { long long k; cin >> n >> k; long long t = 3 * n; while (t > k) { t--; ans++; } cout << ans; return 0; } signed main() { ios::sync_with_stdio(0); long long t = 1; ... |
#include <bits/stdc++.h> using namespace std; int main() { string s, hours, mins; cin >> s; int a = 1, b = 1, colon, i, radix = 0; for (i = 0; i < s.length(); i++) { if (s[i] == : ) { colon = i; break; } } for (i = 0; i < colon; i++) { if (s[i] != 0 ) { ... |
#include <bits/stdc++.h> using namespace std; static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL; template <typename T, typename U> static void amin(T &x, U y) { if (y < x) x = y; } template <typename T, typename U> static void amax(T &x, U y) { if (x < y) x = ... |
#include <bits/stdc++.h> using namespace std; long long int sett(long long int N, int pos) { return N = N | (1 << pos); } int reset(int N, int pos) { return N = N & ~(1 << pos); } bool check(int N, int pos) { return (bool)(N & (1 << pos)); } void update(long long &x, long long val) { x = x + val; if (... |
#include <bits/stdc++.h> using namespace std; #pragma GCC diagnostic ignored -Wmissing-declarations inline int safe_mul(const int x, const int y) __attribute__((warn_unused_result)); int const mod = 998244353; inline int safe_mul(const int x, const int y) { return x * static_cast<long long>(y) % m... |
#include <bits/stdc++.h> using namespace std; bool isprime(int n) { if (n < 2) return false; for (int i = 2; i * i <= n; i++) if (n % i == 0) return false; return true; } int main() { int n; cin >> n; if (isprime(n)) cout << 1 << endl; else if (n % 2 == 0) cout <<... |
#include <bits/stdc++.h> using namespace std; int mmax, sum, n, t; int main() { cin >> n; sum = 0; mmax = 0; for (int i = 0; i < n; i++) { cin >> t; sum += t; mmax = max(t, mmax); } cout << mmax - (sum - mmax) + 1; } |
#include <bits/stdc++.h> using namespace std; long long int fact[2000005], ifact[2000005]; long long int ppow(long long int b, int p) { long long int ret = 1; for (; p; p /= 2) { if (p & 1) ret = (ret * b) % 1000000007; b = (b * b) % 1000000007; } return ret; } void init_fact() { ... |
#include <bits/stdc++.h> using namespace std; const long long mod = 998244353; long long power(long long a, long long b) { if (b == 0) return 1; else if (b == 1) { return a; } else if (b & 1) { return (a % mod * power((a % mod * a % mod) % mod, b / 2)) % mod; } else { retur... |
#include <bits/stdc++.h> using namespace std; const int MAXN = 100000; int a, b, m, n, C[MAXN], I[MAXN]; queue<int> Q; vector<int> A, B, E[MAXN]; int main() { cin >> n >> m; while (m--) { cin >> a >> b; --a; --b; E[a].push_back(b); E[b].push_back(a); I[a] = I[b] =... |
#include <bits/stdc++.h> using namespace std; const int maxn = 1e7 + 5; const int maxm = 2e5 + 5; const int inf = 0x3f3f3f3f; const long long mod = 1e9 + 7; const double eps = 1e-9; const double pi = acos(-1); int m, n, w, k; void init() {} bool judge(int now) {} long long quickpow(long long a, lo... |
#include <bits/stdc++.h> template <class T> int getbit(T s, int i) { return (s >> i) & 1; } template <class T> T onbit(T s, int i) { return s | (T(1) << i); } template <class T> T offbit(T s, int i) { return s & (~(T(1) << i)); } template <class T> int cntbit(T s) { return __builti... |
#include <bits/stdc++.h> using namespace std; const int N = (int)(1e6); char S[N + 1], T[N + 1]; vector<int> multiply(vector<int> a, vector<int> b) { int n = (int)a.size(); vector<int> ret; for (int i = 0; i < n; i++) ret.push_back(a[b[i]]); return ret; } vector<int> pow(vector<int> a, int b... |
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { if (a > b) swap(a, b); if (a == 0) return b; return gcd(b % a, a); } signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long t, i; cin >> t; while (t--) { ... |
#include <bits/stdc++.h> using namespace std; long long cas = 1; long long dxx[] = {-1, -1, -1, 0, 0, 1, 1, 1}; long long dyy[] = {-1, 0, 1, -1, 1, -1, 0, 1}; long long dx[] = {-1, 0, 0, 1}; long long dy[] = {0, -1, 1, 0}; struct info { long long mi, pro, cnt; } tre[100005 * 3]; long long ai[10000... |
#include <bits/stdc++.h> using namespace std; int *a = new int[2000000]; int m, n; void add(int x, int l); void sub(int x, int l); int query(int x, int y, int x0, int y0, int t); int main() { int h, i, j, dir = 1, r, l, o, x, y, len, mid; cin >> n >> m; for (i = 0; i < 2000000; i++) a[i] = 0; ... |
#include <bits/stdc++.h> using namespace std; int main() { const int MAX_N = 100001; int n, x; vector<long long int> dp(MAX_N, 0); vector<long long int> c(MAX_N, 0); cin >> n; while (n--) { cin >> x; c[x]++; } dp[0] = 0; dp[1] = c[1]; for (int i = 2; i < MAX_N; i+... |
#include <bits/stdc++.h> using namespace std; int gcd(int a, int b) { int rem = a % b; while (rem != 0) { a = b; b = rem; rem = a % b; } return b; } int main() { int a, b, c, d; cin >> a >> b >> c >> d; int mul1 = 0, mul2 = 0; int res1 = 0, res2 = 0; int ans... |
#include <bits/stdc++.h> using namespace std; signed main(void) { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int t; cin >> t; while (t--) { long long int n, x, y; cin >> n >> x >> y; vector<long long int> ar(n); vector<long long int> arr(n + 2, 0); v... |
#include <bits/stdc++.h> using namespace std; const int maxn = 310; const int mod = 1e9 + 7; long long C[maxn][maxn], Fact[maxn]; void init() { C[0][0] = 1, Fact[0] = 1; for (int i = 1; i < maxn; i++) { C[i][0] = 1, Fact[i] = Fact[i - 1] * i % mod; for (int j = 1; j <= i; j++) C[i]... |
#include <bits/stdc++.h> using namespace std; int main() { long long n, a, b, p, q, maxx, max_cost, minn, min_cost, t, nok, a1, b1; cin >> n >> a >> b >> p >> q; if (p > q) { max_cost = p; maxx = a; minn = b; min_cost = q; } else { max_cost = q; maxx = b; mi... |
#include <bits/stdc++.h> using namespace std; template <class A, class B> A cvt(B x) { stringstream ss; ss << x; A y; ss >> y; return y; } int n, a, b, t; string s; int solve() { int tb = 0; vector<int> tm; for (int k = n; k >= 1; k--) { tb += a; if (s[k - 1] !=... |
#include <bits/stdc++.h> using namespace std; char s[105][105]; int sz[105]; vector<int> g[105]; int usd[30]; int ord[30], szo = 0, din[30]; bool dfs(int v) { usd[v] = 1; for (int i = 0; i < g[v].size(); ++i) { int u = g[v][i]; if (usd[u] == 1) return false; else if (!usd... |
#include <bits/stdc++.h> using namespace std; int n, m; int a[200], b[200]; int check(int n, int d, int a[]) { for (int i = 1; i <= n; ++i) { int flag = 0; for (int v = 1; v <= 100; ++v) if (a[v] >= d) { a[v] -= d; flag = 1; break; } if (flag =... |
#include <bits/stdc++.h> using namespace std; void getint(int &v) { char ch, fu = 0; for (ch = * ; (ch < 0 || ch > 9 ) && ch != - ; ch = getchar()) ; if (ch == - ) fu = 1, ch = getchar(); for (v = 0; ch >= 0 && ch <= 9 ; ch = getchar()) v = v * 10 + ch - 0 ; if (fu) v = -v; } ... |
#include <bits/stdc++.h> #pragma GCC optimize( O3 ) using namespace std; long long gcd(long long x, long long y) { if (x > y) swap(x, y); if (x == 0) return y; if (y % x == 0) return x; return gcd(y % x, x); } int main() { long long n, k, t; long long m, d, w, g; long long x, y, z;... |
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007ll; long long s[1000010]; int h[1000010]; int main() { int n; scanf( %d , &n); for (int i = 1; i <= n; i++) { scanf( %d , &h[i]); h[i]--; } s[2] = min(h[1], h[2]); for (int i = 2; i < n; i++) ... |
#include <bits/stdc++.h> using namespace std; int a; char str[100002]; int sum[100002]; int cnt[100002]; int main() { scanf( %d n , &a); gets(str); int len = strlen(str); sum[0] = (str[0] - 0 ); for (int i = 1; i < len; i++) { sum[i] = sum[i - 1] + (str[i] - 0 ); } int id... |
#include <bits/stdc++.h> using namespace std; const int INF = (-1u) / 2; const long long int INF2 = (-1ull) / 2; int a, b, i, d[1011000], j, k, n, m, timer = 0, l, r, x, y; int c[1011000], cnt = 0, fl = 0, a2, a3 = -1000000, ans = 0; pair<int, int> p[100100]; int main() { ios_base::sync_with_stdio(0);... |
#include <bits/stdc++.h> using namespace std; using pii = pair<int, int>; using ll = long long; using llu = long long unsigned; using ld = long double; const ld EPS = 1e-9; inline int cmp(ld first, ld second = 0, ld tol = EPS) { return (first <= second + tol) ? (first + tol < second) ? -1 : 0 : 1; }... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.