func_code_string stringlengths 59 71.4k |
|---|
#include <bits/stdc++.h> char s[200010]; int tree[26][200010 << 2]; bool vis[200010]; inline void PushUp(int t, int rt) { tree[t][rt] = tree[t][rt << 1] + tree[t][rt << 1 | 1]; } void Update(int t, int x, int L, int R, int rt) { if (L == R) tree[t][rt] = 1; else { int mid = (L + R) >... |
#include <bits/stdc++.h> using namespace std; const int MAXN = 1005; int numb[MAXN], numw[MAXN]; int dp[MAXN][2]; string s[MAXN]; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); for (int i = 0; i < MAXN; i++) dp[i][0] = dp[i][1] = -1; int n, m, x, y; cin >> n >> m ... |
#include<bits/stdc++.h> using namespace std; #define forg(i,x) for(register int i=fir[x];i;i=nxt[i]) #define uu unsigned #define scanf a14=scanf #define rint register int #define fre(x) freopen(#x .in , r ,stdin),freopen(#x .out , w ,stdout) typedef long long ll; typedef uu long long ull; typedef pair... |
#include <bits/stdc++.h> using namespace std; const int INF = 1e9; const int MOD = 1e9 + 7; vector<int> prefix_function(vector<int> s) { int n = s.size(); vector<int> pi(n); pi[0] = 0; for (int i = 1; i < n; ++i) { int j = pi[i - 1]; while (j > 0 && s[i] != s[j]) { j = pi[j -... |
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; if (n == 1) cout << 0; else if (k >= n / 2) { long long int ans = 0; for (int i = 0; i < n; i++) ans += n - i - 1; cout << ans << endl; } else { long long int ans = 0; for (int... |
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s; cin >> s; vector<char> v; int i = 0; int j = 1; int sum = -1; while (sum < n - 1) { sum = sum + j; v.push_back(s[sum]); j++; } for (auto it = v.begin(); it != v.end(); ... |
#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; template <typename T> T prod(const T &a, const T &b, const T &mod) { return ((a % mod) * (b % mod)) % mod; } template <typename T> T pow_(const T &a, const T &b) { if (!b) return 1; T p = pow_(a, b / 2); p *= p; return (b % 2) ? (p * a) : p; ... |
#include <bits/stdc++.h> using namespace std; using ll = long long; template <class T, class U> using Pa = pair<T, U>; template <class T> using vec = vector<T>; template <class T> using vvec = vector<vec<T>>; template <typename Monoid, typename F> class SegmentTree { private: int sz; vect... |
#include <bits/stdc++.h> using namespace std; int main() { int n, k, a, b, i = 0, arr[100000], j = 0; cin >> n >> k; for (int x = 0; x < n; x++) { cin >> a >> b; i++; while (a != b) if (a < b) a++, i++; else a--, i++; } while (i % k != 0) { ... |
#include <bits/stdc++.h> using namespace std; int n, m, top, len[100005], F1[1005][1005], F2[1005][1005]; pair<int, int> F[30]; char ans[30], dir[100005], a[1005][1005]; bool outside(int first, int second) { return (first < 1 || first > n || second < 1 || second > m); } int tinh1(int first, int y1, in... |
#include <bits/stdc++.h> using namespace std; int t; int n; int a[5001]; bool coutNO; vector<int> check[5001]; int main() { cin.tie(0); cout.tie(0); cin >> t; for (int ct = 1; ct <= t; ct++) { cin >> n; coutNO = true; for (int i = 1; i <= n; i++) check[i].clear(); f... |
#include <bits/stdc++.h> using namespace std; long long int const lac = 100000; long long int modmul(long long int a, long long int b) { return ((a % 1000000007) * (b % 1000000007)) % 1000000007; } long long int modadd(long long int a, long long int b) { return (((a % 1000000007) + (b % 1000000007))) ... |
#include <bits/stdc++.h> using namespace std; int n; pair<double, double> p[301]; double a, b, c, den, len; double area(int i) { double num = abs(a * p[i].first + b * p[i].second + c); return (num) / (2.0); } double f(int i, int j) { a = (p[j].second - p[i].second); b = (p[i].first - p[j].... |
#include <bits/stdc++.h> using namespace std; long long n, s; vector<long long> v(1001); long long check(long long x) { long long sum = 0; for (long long i = 0; i < n; i++) { if (v[i] < x) return 0; sum += max((long long)0, v[i] - x); } return (sum >= s); } int main() { ios::... |
#include <bits/stdc++.h> long long n, m, a, d, t[100007], old, ans, aind, firstA, stepD; int main() { std::ios::sync_with_stdio(0); std::cin.tie(0); std::cout.tie(0); std::cin >> n >> m >> a >> d; for (int i = 0; i < m; ++i) std::cin >> t[i]; aind = d / a * a + a; for (int i = 0; i < m; ... |
#include <bits/stdc++.h> using namespace std; const int mod = 1000000007; const int inf = 50000000; const int maxn = 2010; int n, A[maxn][maxn], vis[maxn]; int bfs(int src, int d) { queue<int> q; q.push(src); for (int i = 1; i <= n; i++) vis[i] = 0; vis[src] = 1; int ret = 1; while (... |
#include <bits/stdc++.h> using namespace std; const int N = 205; char str[20][N]; int n, m, des; int dp[20][2]; int call(int flr, int side) { if (flr == des) { if (side == 0) { int p = 0; for (int i = 1; i <= m; i++) if (str[flr][i] == 1 ) p = i; return p; ... |
#include <bits/stdc++.h> char s[5][110], ss[5][5]; int main() { int t, n, i, j; scanf( %d , &n); memset(s, 0x00, sizeof(s)); if (n == 1) { s[0][0] = a ; s[1][0] = a ; s[2][0] = b ; s[3][0] = b ; } else if (n & 1) { s[2][0] = f ; s[3][0] = f ; s[0][... |
#include <bits/stdc++.h> using namespace std; int n, m, k, x, y, sum, ans, T; char c; int main() { scanf( %d , &T); while (T--) { scanf( %d , &n); vector<int> v, b; for (int i = 1; i <= n; i += 2) { if (i + 1 > n) { v.push_back(i); b.push_back(i); } ... |
#include <bits/stdc++.h> using namespace std; string s; vector<int> v; set<double> S; set<double>::iterator it, it2; int main() { int n, k; cin >> n >> k; cin >> s; for (int i = 0; i < s.size(); i++) if (s[i] == 0 ) v.push_back(i + 1); int i = 0, j = 0; for (i = 0; i <= k; i++... |
#include <bits/stdc++.h> using namespace std; int firstOne(string s) { int len = s.length(); for (int i = len - 1; i >= 0; i--) { if (s[i] == 1 ) { return len - i; } } } int firstOneAfter(string s, int idx) { int len = s.length(); for (int i = len - idx; i >= 0; i--) { ... |
#include <bits/stdc++.h> using namespace std; int val(vector<int> a) { int cur = a[0]; for (int i = 1; i < a.size(); i++) { cur = (a[i] | cur) - a[i]; } return cur; } int brute(vector<int> a) { vector<int> P(a.size()); for (int i = 0; i < a.size(); i++) { P[i] = i; } ... |
#include <bits/stdc++.h> using namespace std; const int N = 105; using ll = long long; int n, m, b[N]; ll a[N], c1, c2; int main() { ios::sync_with_stdio(false); cin >> n >> m; for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 2; i <= m * 2; i++) { for (int j = 1; j <= n; j++) b[j... |
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 10; const int T = 1 << 19; int n, q, a[N]; long long s[N]; int p, x; int tn = 1; long long mx[T], sum[T]; long long tmx[T], tsum[T]; inline void pushup(int x) { mx[x] = max(sum[x << 1] ? mx[x << 1] : -0x3f3f3f3f3f3f3f3f, ... |
#include <bits/stdc++.h> using namespace std; const int MM = 100010; int N, M; bool vis[MM]; int c[MM]; set<int> edge[MM]; void get_data() { int i, j, k, a, b; for (i = 1; i <= N; i++) { edge[i].clear(); scanf( %d , &c[i]); } while (M--) { scanf( %d%d , &a, &b); if ... |
#include <bits/stdc++.h> using namespace std; const int MAX = (1e6) + 5; const int IT_MAX = 1 << 20; const int INF = -1; int bit[IT_MAX + 10]; void update(int p, int dv) { for (; p <= IT_MAX; p += p & (-p)) bit[p] += dv; } int query(int p) { int rv = 0; for (; p; p -= p & (-p)) rv += bit[p];... |
#include <bits/stdc++.h> using namespace std; const long long int mod = 1e9 + 7; long long int Mod(long long int n) { return ((n % mod) + mod) % mod; } void fast() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } long long int f[200005]; long long int invfact[200005]; lon... |
#include <bits/stdc++.h> using ll = long long; using ld = long double; const ld PI = 4 * atanl(1); const ld EPS = 1e-12; const int MN = 1e5 + 10; struct vec { public: int x, y; void in() { scanf( %d%d , &x, &y); } ld mag() const { return hypotl(x, y); } ld ang() const { return atan2l(y, x... |
#include <bits/stdc++.h> using namespace std; int n, m, tot, a[1001000], ans[1001000 << 2], k[1001000]; long long s; int main() { scanf( %d%d , &n, &m); for (int i = 1; i <= m; i++) scanf( %d , &a[i]), s += a[i], k[i] = s % n; k[m] = n; sort(k + 1, k + m + 1); for (int i = m; i; i--) k[i] -=... |
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c; cin >> a >> b >> c; int count = 0; int min = a; if (b < a) { min = b; } int x = c / min; for (int i = 0; i <= x; i++) { for (int j = 0; j <= x; j++) { if (count != 0) { break; ... |
#include <bits/stdc++.h> using namespace std; void PT(long long a); void PT1(long long a); const long long M = 2 * (1e5) + 7; long long a[M]; signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ; { long long n, k; cin >> n >> k; if (k * (k -... |
#include <bits/stdc++.h> using namespace std; struct Edge { int u, v; } e[200050 << 1]; int fa[200050]; int n, color[200050], s, d; int cnt[2], dis[200050]; bool vis[200050]; vector<int> G[200050]; int find(int x) { if (x == fa[x]) return x; return fa[x] = find(fa[x]); } void _union(in... |
#include <bits/stdc++.h> using namespace std; int n, k; vector<int> g[100010]; const int inf = 1e9; int d[100010], p[100010]; queue<int> Q; void bfs(int x) { for (int i = 1; i <= n; i++) d[i] = inf; d[x] = 0; while (!Q.empty()) Q.pop(); Q.push(x); while (!Q.empty()) { int y = Q.f... |
#include <bits/stdc++.h> using namespace std; void code() { long long n, k; cin >> n >> k; long long a[n]; for (long long i = 0; i < n; i++) { cin >> a[i]; } sort(a, a + n); long long ans = 0; for (long long i = 0; i < n; i++) { if ((a[i] - a[0]) % k != 0) { cout ... |
#include <bits/stdc++.h> using namespace std; template <class T1, class T2> istream &operator>>(istream &in, pair<T1, T2> &P) { in >> P.first >> P.second; return in; } template <class T1, class T2> ostream &operator<<(ostream &out, const pair<T1, T2> &P) { out << ( << P.first << , << P.seco... |
#include <bits/stdc++.h> using namespace std; int main() { int t; long double tp, temp, temp2, div; vector<long double> v; map<long double, long long int> mp; string in; double storage; cin >> t; while (t--) { cin >> in; storage = 0; temp = -1; temp2 = -1; ... |
#include <bits/stdc++.h> using namespace std; vector<pair<string, string>>::iterator findit( vector<pair<string, string>>::iterator st, vector<pair<string, string>>::iterator en, string s) { while (st != en) { if ((*st).second == s) { return st; } else { ++st; } ... |
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> arr(n); for (int i = 0; i < n; i++) { cin >> arr[i]; } int last = 0; int ans = 0; string s = ; int l = 0, r = n - 1; while (1) { int k = INT_MAX; if (arr[l] > last) { ... |
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c; cin >> a >> b >> c; if (c <= b / 2 && c <= a / 2) cout << First ; else cout << Second ; } |
#include <bits/stdc++.h> using namespace std; const long long int N = 1001; long long int n, m, k; vector<pair<long long int, long long int> > adj[N]; vector<long long int> func(long long int x) { vector<long long int> dis(n + 1, INT_MAX); if (x == 0) { return dis; } vector<int> vis(n + ... |
#include <bits/stdc++.h> using namespace std; struct node { long long x; long long y; long long id; } a[200005]; long long n, t; long long totx, toty; inline void read(long long &x) { long long f; char c; for (f = 1, c = getchar(); c < 0 || c > 9 ; c = getchar()) if (c == -... |
#include <bits/stdc++.h> using namespace std; int main(int argc, char const *argv[]) { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, m; cin >> n >> m; vector<vector<int> > G(n + 5, vector<int>(0)); int c[m + 5][2]; memset(c, (0), sizeof(c)); for (int i = 1; i <= m; i++) { ... |
#include <bits/stdc++.h> using namespace std; int n, r[20], b[20]; char ch[20]; long long dp[(1 << 16)][260]; long long dfs(int bit, int discount) { long long& ret = dp[bit][discount]; if (ret != -1) return ret; if (bit == (1 << n) - 1) { return ret = 0; } ret = 0xffffffffffffff; ... |
#include <bits/stdc++.h> using namespace std; int main() { int n, i = 0, j = 0, flag = 0, hash[100002] = {0}, stack[100002] = {0}, top = -1; string x; char item; getline(cin, x); n = x.length(); for (i = 0; i < n; i++) { if (x[i] == ( ) { stack[++top] = i; } ... |
#include <bits/stdc++.h> using namespace std; long long phi(long long x); const long long mod = 1e9 + 7; int main() { long long N, K; cin >> N >> K; while (K > 0 && N > 1) { N = phi(N); K -= 2; } cout << N % mod << endl; } long long phi(long long x) { int R = sqrt(x); ... |
#include <bits/stdc++.h> using namespace std; int main() { long long t; cin >> t; while (t--) { long long n; string x; cin >> n >> x; string a(n, 0 ), b(n, 0 ); for (long long i = 0; i < n; ++i) { if (x[i] == 1 ) { a[i] = 1 ; b[i] = 0 ; ... |
#include <bits/stdc++.h> using namespace std; int gcd(int a, int b) { return a % b == 0 ? b : gcd(b, a % b); } const int INF = 1 << 30; const double eps = 1e-8; const int row = 3000; const int cow = 220; const int MAXN = cow * cow; int n, m; long long a[50000]; long long sum[50000]; char s[5000]; ... |
#include <bits/stdc++.h> using namespace std; using ll = long long; signed main() { ios::sync_with_stdio(false); cin.tie(0), cout.tie(0); int t; cin >> t; while (t--) { int n, x, y; cin >> n >> x >> y; vector<int> a(n); for (auto &el : a) { cin >> el; el... |
#include <bits/stdc++.h> using namespace std; const int M = 2e5 + 10; struct Edge { int u, v, cap, flow = 0; Edge(int u, int v, int cap) : u(u), v(v), cap(cap) {} }; class Dinic { public: vector<Edge> edges; vector<vector<int>> G; int n, m = 0, s, t; vector<int> H, ptr; queue<in... |
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int t; cin >> t; while (t--) { int n, k; cin >> n >> k; int arr[n + 1]; for (int i = 1; i <= n; i++) { cin >> arr[i]; } int peaks = 0, ind = 1; ... |
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; vector<int> a[n]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { int x; cin >> x; x--; a[i].push_back(x); } } int ans = 0; for (int j = 0; j < m; j... |
#include <bits/stdc++.h> using namespace std; int sol = (int)1e9 + 7; int op, lim; int ask(int r, int c) { op++; if (op == lim) { cout << ! << sol << endl; exit(0); } cout << ? << r << << c << endl; int x; cin >> x; sol = min(sol, x); return x; } int go ... |
#include <bits/stdc++.h> using namespace std; int main(int argc, char *argv[]) { map<int, int> set; int n, a, b, check1, check2, temp; cin >> n >> a >> b; int arr[n]; vector<int> check; for (int i = int(0); i <= int(n - 1); i++) { cin >> arr[i]; set[arr[i]] = -1; } if (a ... |
#include <bits/stdc++.h> using namespace std; int N, M; int _next[10000000]; struct event { int l, r, x; event() {} event(int l, int r, int x) : l(l), r(r), x(x) {} }; vector<event> e[7005]; inline bool cross(int l1, int r1, int l2, int r2) { if (l1 > r2) return false; if (r1 < l2) ret... |
#include <bits/stdc++.h> using namespace std; long long n, k; long long count(long long num) { long long ans = 0, sum = num, cnt = 0, hest = 0; while (sum) { hest = sum % 10; sum /= 10; cnt++; } cnt--; long long k = 1; for (long long i = 1; i <= cnt; i++) { ans += k... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t = 1; while (t--) { int n, m, k; cin >> n >> m >> k; vector<long long> a(n + 1), pref_a(n + 1); for (int i = 1; i <= n; i++) { cin >> a[i]; pref_a[... |
#include <bits/stdc++.h> clock_t t = clock(); namespace my_std { using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); template <typename T> inline T rnd(T l, T r) { return uniform_int_distribution<T>(l, r)(rng); } template <typename T> inline bool chkmax(T &x, ... |
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n, m; cin >> n >> m; vector<string> G(n); for (int i = 0; i < n; i++) { cin >> G[i]; } vector<vector<pair<int, int>>> arr(27, vector<pair<int, int>>()); bool re... |
#include <bits/stdc++.h> using namespace std; string a, b; int t; string ssort(string x) { if (x.size() & 1) return x; int len = x.size() / 2; string xx, yy; xx = ssort(x.substr(0, len)); yy = ssort(x.substr(len, len)); if (xx < yy) return xx + yy; else return yy + xx; ... |
#include <bits/stdc++.h> using namespace std; int T, n; char s[50]; int a[50], b[50]; int main() { scanf( %d , &T); while (T--) { int cnt = 0; scanf( %d , &n); scanf( %s , s + 1); for (int i = 1; i <= n; ++i) a[i] = s[i] - a , b[i] = a[i]; sort(a + 1, a + n + 1); f... |
#include <bits/stdc++.h> using namespace std; const int N_MAX = 1e5, V = (1 << 20); int n, x[N_MAX], t[N_MAX]; struct edge { int l, v; }; vector<edge> G[N_MAX]; long long cnt_tree[V + 1], total_tree[V + 1]; void add(int i, long long a, long long tree[]) { while (i <= V) { tree[i] += a; ... |
#include <bits/stdc++.h> using namespace std; const int N = 1100; const int M = 256; const int K = 26; const int INF = 2000000000; const double eps = 1e-12; int k, m, n, d[K], a[N]; char s[N]; bool ok; int F(); int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n; ... |
#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> using namespace std; int a[100001], p[100001]; int main() { int min = 1000, sum = 0, n, i, j; scanf( %d , &n); for (i = 0; i < n; i++) { scanf( %d %d , &a[i], &p[i]); if (p[i] < min) { min = p[i]; } sum += a[i] * min; } printf( %d n , su... |
#include <bits/stdc++.h> using namespace std; const long long N = 1e5 + 5; const long long MOD = 1e9 + 7; long long n, m, connected = 0; long long col[N], vis[N]; vector<pair<long long, long long> > g[N]; long long pow(long long a, long long b, long long m) { long long ans = 1; while (b) { i... |
#include <bits/stdc++.h> using namespace std; const int MAXN = 510000; int n; int sz[MAXN]; int was[MAXN]; int up[MAXN]; vector<int> eds[MAXN]; int ans[MAXN]; void dfs1(int v) { sz[v] = 1; was[v] = 1; for (int u : eds[v]) { if (!was[u]) { dfs1(u); sz[v] += sz[u]; ... |
#include <bits/stdc++.h> void print_row(int s, int *l, int size) { int i = s + 1; printf( %d , l[s]); while (i < size) printf( %d , l[i++]); i = 0; while (i < s) printf( %d , l[i++]); printf( n ); } int main() { int n, k; scanf( %d %d , &n, &k); int l[n]; l[0] = k; f... |
#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> using namespace std; int main() { long long k, l, ans = 0; cin >> k >> l; while (l % k == 0) { l = l / k; if (l != 1) ans++; } if (l == 1) cout << YES << endl << ans; else cout << NO ; } |
#include <bits/stdc++.h> using namespace std; int n, w, used[300005]; long long ans, a[300005], b[300005]; priority_queue<pair<long long, int>, vector<pair<long long, int> >, greater<pair<long long, int> > > Q1, Q2; priority_queue<pair<long long, int>, vector<pair<long long, int> >, ... |
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 10; const int MOD = 998244353; struct node { long long a, b; node() {} node(long long a, long long b) { this->a = a; this->b = b; } node operator+(const node& rhs) const { return node((a + rhs.a) % MOD, (b... |
#include <bits/stdc++.h> using namespace std; int n, m = 1; vector<vector<int> > edge(105); int from[105]; int to[105]; bool bfs(int a, int b) { int use[105] = {0}; queue<int> q; q.push(a); use[a] = 1; while (!q.empty()) { int cur = q.front(); q.pop(); for (int i = 0; i... |
#include <bits/stdc++.h> #pragma GCC optimize( O2 ) #pragma GCC optimize( Ofast ) #pragma GCC optimize( O3 ) using namespace std; const int N = 1e6 + 5; int n, p = 1, pa[N]; int ch[N][26]; vector<int> cnt[N][2]; vector<pair<int, int> > as; long long ans; inline void dfs(int u, int dep) { for (... |
#include <bits/stdc++.h> using namespace std; int n; char a[105][3]; int main() { scanf( %s%d , a[0], &n); for (int i = 1; i <= n; ++i) { scanf( %s , a[i]); if (a[i][0] == a[0][0] && a[i][1] == a[0][1]) { printf( YES n ); return 0; } } for (int i = 1; i <= n; ++... |
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 10; int T, n, a[N]; map<int, int> mp; int main() { cin >> T; while (T--) { double sum = 0; mp.clear(); cin >> n; for (int i = 0; i < n; ++i) { cin >> a[i]; sum += a[i]; } double mean =... |
#include <bits/stdc++.h> using namespace std; bool isPrime(int num); int main() { int n; cin >> n; for (int i = 1; i <= 1000; i++) { if (!(isPrime(n * i + 1))) { cout << i; break; } } return 0; } bool isPrime(int num) { if (num <= 1) return false; ... |
#include <bits/stdc++.h> using namespace std; const int mx = 2e5 + 5; int dp[mx][3], arr[mx], n, h[mx]; void solve() { cin >> n; for (int i = 1; i <= n; i++) { cin >> arr[i]; h[arr[i]]++; } sort(arr, arr + n + 1); memset(dp, 0, sizeof dp); dp[1][0] = dp[1][1] = dp[1][2] = 1; ... |
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; const double esp = 1e-7; const int mod = 1e9 + 7; vector<int> adj[N]; int leaf = 0; void dfs(int node = 1, int par = 0) { int cnt = 0; for (int child : adj[node]) { if (child == par) continue; dfs(child, node); ... |
#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) { cout << *it << = << a << endl; err(++it, args...); } const long long MOD = 1e9 + 7; long long modExp(long lo... |
#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]; for (int k = 1; k <= n / 3; k++) { if (n % k == 0) { for (int p = 0; p < k; p++) { int sum = 0; for (int v = p; v < n; v += k) { ... |
#include <bits/stdc++.h> using namespace std; const double eps = 1e-8; const double pi = acos(-1.0); template <class T> long long chkmin(T &a, T b) { return a > b ? a = b, 1 : 0; } template <class T> long long chkmax(T &a, T b) { return a < b ? a = b, 1 : 0; } template <class T> T sqr(T a)... |
#include <bits/stdc++.h> using namespace std; int Popcount(long long int a) { int k; for (k = 0; a; a >>= 1) if (a & 1ll) k++; return k; } int Ffs(long long int a) { int k; for (k = 0; a; a >>= 1, k++) ; return k; } long long int C[50][50]; long long int getAns(long lon... |
#include <bits/stdc++.h> using namespace std; struct BIT { vector<int> t; int n; void add(int x, int v) { for (; x < n; x += x & -x) { t[x] += v; } } BIT(int sz) { t = vector<int>(sz); n = sz; } void add(int l, int r, int v) { ++l; ++r; a... |
#include <bits/stdc++.h> using namespace std; using lli = long long int; using pii = pair<int, int>; using vi = vector<int>; using vb = vector<bool>; using vvi = vector<vector<int>>; using vlli = vector<long long int>; using vpii = vector<pair<int, int>>; int main() { ios_base::sync_with_stdio(fal... |
#include <bits/stdc++.h> using namespace std; #pragma warning(disable : 4996) const int N = 1e6 + 5, M = 300, MAX = 10, T = 3e4, INF = 1e9; int d[N], w[T], dist[300][M + 5]; vector<int> h[T], pr; vector<vector<int>> v; map<vector<int>, int> mp; int cnt = 0; vector<int> path; void f(int max, int prod... |
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 1; inline int min(const int& x, const int& y) { return (x - y >> 31) ? x : y; } namespace ST { int lg[N], t[20][N]; inline void build(int* a, int n) { copy(a + 1, a + 1 + n, t[0] + 1); for (int i = 2; i <= n; i++) lg[i] = lg[i >> 1] +... |
#include <bits/stdc++.h> using namespace std; int p[2 * 1000005]; int n; int input() { int i; scanf( %d , &n); for (i = 1; i <= n; i++) p[i] = i; return 0; } int solve() { int i, j, ii; int t1, t2; for (i = 2; i <= n; i++) { t1 = p[i - 1]; for (j = i + i - 1; j < n + ... |
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 5; int C[N]; int main() { ios::sync_with_stdio(0); cin.tie(0); int n, r; cin >> n >> r; double sum = 0; for (int i = 0; i < (1 << n); i++) { cin >> C[i]; sum += C[i]; } cout << setprecision(15) << fixed... |
#include <bits/stdc++.h> using namespace std; const int maxn = 5e5 + 7; long long a[maxn], b[maxn]; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i] >> b[i]; a[i] ^= b[i], b[i] ^= b[i - 1]; } ... |
#include <bits/stdc++.h> using namespace std; long long int mod = 1000000007; void __print(long long int 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 __print(float x) { cerr << x; } void __pr... |
#include <bits/stdc++.h> using namespace std; const int N = 305, Q = (int)2e6 + 50; struct Qry { int x, y, c; void read() { cin >> x >> y >> c; x--, y--; } } qry[Q]; int n, m, q; int mp[N][N]; int f[N * N]; int dx[] = {0, 0, -1, 1}, dy[] = {1, -1, 0, 0}; int ch[Q], off[Q]; in... |
#include <bits/stdc++.h> using namespace std; int n, x[105], mem[101][201][51][3], ans; string s; int solve(int idx, int pos, int rem, int dir) { int &ret = mem[idx][100 + pos][rem][dir + 1]; if (rem == 0) { int cur_dir = dir, sum = 0; for (int i = idx; i < s.size(); i++) if (x[i]) ... |
#include <bits/stdc++.h> using namespace std; int main() { string a, b; cin >> a >> b; if (a == b) { cout << a; } else { cout << 1; } } |
#include <bits/stdc++.h> using namespace std; long long a, b, p, x; long long Pow(long long x, long long y, long long mod) { if (!y) return 1; if (y == 1) return x % mod; long long t = Pow(x, y >> 1, mod), ans = t * t % mod; if (y & 1) ans = ans * x % mod; return ans; } int main() { wh... |
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; int i, j; if (k == 1 && n == 1) { cout << a ; return 0; } if (k > n || (k == 1)) { cout << -1; return 0; } i = 1; while (n - i >= k - 2) { cout << char( a + !(i % 2... |
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; for (int i = 0; i < t; i++) { int a, b, c; cin >> a >> b >> c; cout << a + b + c - (2 * (min(min(a, b), min(b, c)))) << endl; } } |
#include<bits/stdc++.h> #include<vector> #include<map> #include<queue> #define LL long long #define INF INT64_MAX #define MOD 1000000007 #define stree SegTree[root] #define lson SegTree[root << 1] #define rson SegTree[root << 1 | 1] using namespace std; const int N = 100005; LL a[N]; int main(... |
#include <bits/stdc++.h> #include <time.h> using namespace std; #define ll long long #define ld long double #define precision(x,d) cout<<fixed<<setprecision(d)<<x #define all(x) x.begin(),x.end() #define IOS ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL)); #define MOD 100000... |
#include <bits/stdc++.h> using namespace std; using ll = long long; using Pii = pair<int, int>; using Pll = pair<ll, ll>; template <typename...> static inline int getchar_unlocked(void) { return getchar(); } template <typename...> static inline void putchar_unlocked(int c) { putchar(c); } ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.