func_code_string stringlengths 59 71.4k |
|---|
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; int vis[N], parent[N]; vector<int> v[N]; void dfs(int node) { vis[node] = 1; for (auto i : v[node]) { if (!vis[i]) { parent[i] = node; dfs(i); } } } int res[N]; int main() { int n, l, r, k = ... |
#include <bits/stdc++.h> using namespace std; const int N = 1e9 + 7; int main() { int n, k; cin >> n >> k; int a[n]; for (int i = 0; i < n; i++) cin >> a[i]; int difference; int ans = 0; for (int i = 0; i < n - 1; i++) { if (a[i] + a[i + 1] < k) { difference = k - (a[i] +... |
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { if (b == 0) return a; return gcd(b, a % b); } int main() { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); int n; cin >> n; string s; cin >> s; vector<long long int> col; int zero = 0, o... |
#include <bits/stdc++.h> using namespace std; int main() { long long int x, y; cin >> x >> y; if (y == 0) { cout << No << endl; return 0; } y = y - 1; if (y >= 1) { x = x - y; if (x >= 0 && x % 2 == 0) { cout << Yes << endl; } else { cout << ... |
#include <bits/stdc++.h> using namespace std; bitset<1000001> L, R; vector<int> H1, H2, V1, V2, res; multiset<int> AA, BB; int A[1000], B[1000]; bool solve(int *A, int s, int e, int S) { int m = (s + e) >> 1; if (s == e || S == 0) { if (S) res.push_back(A[m]); return true; } for ... |
#include <bits/stdc++.h> using namespace std; char board[2100][2100]; int mark[2100][2100]; class Graph { int V; list<int> *adj; bool isCyclicUtil(int v, bool visited[], bool *rs); public: Graph(int V); void addEdge(int v, int w); bool isCyclic(); }; Graph::Graph(int V) { t... |
#include <bits/stdc++.h> using namespace std; int main() { long long n, x; long long k, count = 0; char c; cin >> n >> x; for (int i = 1; i <= n; i++) { cin >> c >> k; if (c == + ) { x += k; } else { if (x >= k) { x -= k; } else { co... |
#include <bits/stdc++.h> using namespace std; long int temp, i, j, k, T; int main() { int n, a, b; cin >> n >> a >> b; int h[2007]; for (i = 0; i < n; i++) cin >> h[i]; sort(h, h + n); int val = h[b - 1]; if (h[b] == val) cout << 0 << endl; else cout << h[b] - val << ... |
#include <bits/stdc++.h> void unionInit(int d[], int s) { int i; for (i = 0; i < s; i++) d[i] = i; } int unionGet(int d[], int n) { int t = n, k; while (d[t] != t) t = d[t]; while (d[n] != n) k = d[n], d[n] = t, n = k; return n; } int unionConnect(int d[], int a, int b) { a = union... |
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int arr[n]; for (int i = 0; i < n; i++) { cin >> arr[i]; } sort(arr, arr + n); int ans = n; if (arr[0] == 0) { ans--; } for (int i = 1; i < n; i++) { if (arr[i] == 0) { ans--... |
#include <bits/stdc++.h> using namespace std; const int MAXN = 105; struct ANS { int xa, ya, xb, yb, xc, yc; }; struct PRE { int p1, p2, s; } pre[MAXN][2][2]; int T, n, m; int a[MAXN][MAXN]; int f[MAXN][2][2]; char s[MAXN]; vector<ANS> ans; int popcount(int v) { return v ? popcount(v - (... |
#include <bits/stdc++.h> using namespace std; long long int t, n; int main() { cin >> n >> t; long long int k = 0; long long int a, b; long long int res1 = 1; long long int res; cin >> a >> b; long long int m = (t - a) / b; if (a >= t) res = a; else if (m * b + a == t) ... |
#include <bits/stdc++.h> #pragma GCC optimize(2) using namespace std; const int man = 2e5 + 10; const long long mod = 1e9 + 7; struct edge { int v; int w; int next; } e[man << 1]; int head[man]; int cnt; void init(int n) { memset(head, 0, sizeof(int) * (n + 5)); cnt = 0; } void... |
#include <queue> #include <cstdio> #include <algorithm> const int Maxn=200; const int Maxl=40; const int Mod=998244353; int n,m; namespace Trie{ struct Trie_Node{ int ch[26]; bool pos; }node[Maxl+5]; int id_tot; void insert(char *s,int len){ int root=0; for(int i=1;i<=len;i++){... |
#include <bits/stdc++.h> using namespace std; int n, k, m, x, y, ans; bool b; int main() { scanf( %d%d , &n, &k); ans = n * 2 - k - 1; for (int i = 1; i <= k; i++) { scanf( %d , &m); b = 0; for (int j = 1; j <= m; j++) { scanf( %d , &x); if (j == 1 && x == 1) b = 1;... |
#include <bits/stdc++.h> using namespace std; const int N = -1; const int INF = 1.01e9; const int MOD = 1e9 + 7; long long rev(long long a, long long m) { if (a == 0) return 0; return ((1 - rev(m % a, a) * m) / a + m) % m; } int main() { int n, k; scanf( %d%d , &n, &k); vector<long lon... |
#include <bits/stdc++.h> using namespace std; int paths[5001][5001]; int ct[5001], top[5001], freq[5001]; int main() { for (int i = 2; i <= 5000; i++) { for (int j = 2; j <= 5000; j++) { paths[i][j] = paths[i - 1][j]; } int tmp = i; for (int j = 2; j <= sqrt(tmp); j++) { ... |
#include <bits/stdc++.h> using namespace std; using namespace std; int main() { long long int k, b, n, t; while (cin >> k >> b >> n >> t) { long long int s = 1; long long int cas = 0; while (s <= t && cas < n) { s = s * k + b; cas++; } if (cas == n && s <= t) ... |
#include <bits/stdc++.h> const int maxn = 100005; int nbs[maxn], ev[maxn * 2], next[maxn * 2], color[maxn], d[maxn], ans[maxn], size[2], view[maxn], n, m, k; void addedge(int x, int y) { next[++k] = nbs[x]; ev[k] = y; nbs[x] = k; } void init() { scanf( %d%d , &n, &m); for (int i = 0;... |
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> s(n), r(n); for (int i = 0; i < n; i++) { cin >> s[i] >> r[i]; } vector<tuple<int, int, int>> T(n); for (int i = 0; i < n; i++) { T[i] = make_tuple(s[i], r[i], i); } sort(T.begin()... |
#include <bits/stdc++.h> #define MULTI_TEST false #define int long long #define double long double //#pragma GCC optimize( Ofast ) //#pragma GCC optimize( no-stack-protector ) //#pragma GCC optimize( unroll-loops ) //#pragma GCC target( sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native ) #define a... |
#include <bits/stdc++.h> using namespace std; int main() { int t, i, j; char c = W ; cin >> t; for (i = 0; i < t; i++) { for (j = 0; j < t; j++) { cout << c; if (c == B ) c = W ; else c = B ; } if (t % 2 == 0) { if (c == B ) ... |
#include <bits/stdc++.h> using namespace std; const long long MOD = 1000 * 1000 * 1000 + 7; inline long long mod(long long n) { if (n < 0) { return (n % MOD + MOD) % MOD; } else { return n % MOD; } } long long fp(long long a, long long p) { long long ans = 1, cur = a; for (long... |
#include <bits/stdc++.h> using namespace std; const long long MOD = 1000000007; const long double EPS = 1e11; const long long INFL = 1e16; const int INF = 1e9 + 7; mt19937 rnd((unsigned)chrono::steady_clock::now().time_since_epoch().count()); int highdig(long long x) { int ans = 0; while (x > 0LL)... |
#include <bits/stdc++.h> using namespace std; int main() { long long int n, i; cin >> n; i = 1; while (n % i == 0) { i = i * 3; } cout << n / i + 1; } |
#include <bits/stdc++.h> int temp[500000], a[500000], indices[500000], increments[500000], previous_appearance[500000], numbers_equal_c[500000]; void mergesort(int Array[], int indices[], int first, int last) { if (first == last) return; int middle = (first + last) / 2; mergesort(Array, indices, f... |
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n, k; cin >> n >> k; int ans = n; for (int i = 1; i * i <= n; i++) if (n % i == 0) { if (i <= k) ans = min(ans, n / i); if (n / i <= k) ans = min(ans, i); ... |
#include <bits/stdc++.h> using namespace std; int main() { int t, s, x; scanf( %d%d%d , &t, &s, &x); if (x < t) { puts( NO ); return 0; } int temp = (x - t) % s; if (temp == 0 || temp == 1) { if (x == t + 1) puts( NO ); else puts( YES ); } else ... |
#include <bits/stdc++.h> using namespace std; set<long long int> s; int main() { long long int n, m, i, ans = 0; cin >> n >> m; long long int a[n], c[200005] = {0}; for (i = 0; i < m; i++) s.insert(i); for (i = 0; i < n; i++) { long long int d, x; cin >> a[i]; d = a[i] % m; ... |
#include <bits/stdc++.h> using namespace std; #pragma GCC target( avx2 ) #pragma GCC optimization( O3 ) #pragma GCC optimization( unroll-loops ) const long long mod = 1e9 + 7; inline long long add(long long a, long long b) { return (a % mod + b % mod) % mod; } inline long long sub(long long a, long ... |
#include <bits/stdc++.h> using namespace std; char s[200005]; int main() { int l, t; scanf( %d %d , &l, &t); scanf( %s , s + 1); s[0] = 0 ; for (int i = 0; i <= l; i++) { if (s[i] == . ) { for (int j = i + 1; j <= l; j++) if (s[j] >= 5 ) { s[j] = 0; ... |
#include <bits/stdc++.h> using namespace std; long long n, m, k, d[5][2][100][100], kk; int a[100][100]; bool was[100][100], done = false, was2[100][100][2][5]; string s; int main() { cin >> n >> k; for (int i = 0; i < n; i++) { cin >> s; m = s.length(); for (int j = 0; j < m; j++)... |
#include <bits/stdc++.h> using namespace std; string rep(char c, int x) { string ret = ; for (int i = 0; i < x; i++) { ret += c; } return ret; } int main() { int n, k; cin >> n >> k; if (n == k) { string ans = ; for (int i = 0; i < n; i++) { ans += 0 ; ... |
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c, d; cin >> a >> b >> c >> d; int x, y, i; if (b * c > a * d) { x = b * c - a * d; y = b * c; } else { x = a * d - b * c; y = a * d; } while (1) { int k = 0; for (i = 2; i <= x; i++)... |
#include <bits/stdc++.h> using namespace std; const int Mod = 1000000007; int N; struct M { int a[250][250]; M() { memset(a, 0, sizeof(a)); } }; M I() { M res; for (int i = 0; i < N; i++) res.a[i][i] = 1; return res; } M operator*(const M& a, const M& b) { M ans; for (int i =... |
#include <bits/stdc++.h> using namespace std; int main() { int n, v; cin >> n >> v; vector<vector<int> > mat(n + 1, vector<int>(v + 1, INT_MAX)); for (int i = 1, j = 0; j <= v; j++) { mat[i][j] = j; } for (int i = 2; i <= n; i++) { for (int j = 0; j <= v; j++) { if (j < v... |
#include <bits/stdc++.h> int n; double sum, tmp, ans; int main() { scanf( %d , &n); for (int div = 1; div <= n; div++) { scanf( %lf , &tmp); sum += tmp; if (sum / div > ans) ans = sum / div; } printf( %.20lf n , ans); } |
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(); cout.tie(0); long long n, p = 0, q = 0, l = 0, i, flag = 0, k, m, t, j, r = 0, curr = 0, d; cin >> n >> m; long long a[n], b[n]; for (long long i = 0; i < n; i++) { cin >> a[i]; }... |
#include <bits/stdc++.h> using namespace std; const long long Mo = 1000000007LL; long long f[60][60], g[60][60]; long long fac[70], inv[70]; int n, m; void add(long long &a, long long b) { a += b; a %= Mo; } long long fpm(long long a, long long b) { long long ans = 1LL; for (; b; b >>= 1... |
#include <bits/stdc++.h> using namespace std; const int inf = 0x20202020; const int mod = 1000000007; inline void read(int &x) { char ch; bool f = 0; int a = 0; while (!((((ch = getchar()) >= 0 ) && (ch <= 9 )) || (ch == - ))) ; if (ch != - ) a *= 10, a += ch - 0 ; else ... |
#include <bits/stdc++.h> using namespace std; int n, i, j, x; long long sum; char s[30]; vector<int> a; int main() { scanf( %d , &n); for (i = 1; i <= n; i++) { scanf( %s , s); if (s[0] == s ) { sum = 0; for (j = 2; j < a.size(); j += 5) { sum += a[j]; ... |
#include <bits/stdc++.h> const int N = 1e5 + 5; const unsigned long long bigN = 1e18; const long long mod9 = 1e9 + 9; const long long mod7 = 1e9 + 7; using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); vector<int> a, b; int n, l, r, x; cin >> n >> l >> r; for ... |
#include <bits/stdc++.h> using namespace std; map<string, string> M; int main() { int n, m; cin >> n >> m; for (int i = 0; i < n; i++) { string name, ip; cin >> name >> ip; M[ip] = name; } for (int i = 0; i < m; i++) { string cmd, ip; cin >> cmd >> ip; ip.po... |
#include <bits/stdc++.h> #define ll long long using namespace std; const ll N = 5005, MOD = 998244353; vector<vector<ll>> dp(N, vector<ll>(N)); vector<vector<int>> edges(N); vector<int> h(N); int n, k; void add(ll &x, ll y) { if((x += y) >= MOD) { x -= MOD; } } void dfs(int x, int p) { ... |
#include <bits/stdc++.h> using namespace std; const long long mod = 998244353; const int maxn = 2e5 + 9; int a[maxn], b[maxn]; int main() { int n, m; 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]); ... |
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[5] = {}, b[5] = {}; for (int k = 0; k < n; k++) { int x; cin >> x; a[x - 1]++; } for (int k = 0; k < n; k++) { int x; cin >> x; b[x - 1]++; } int cnt = 0; for (in... |
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf( %d , &n); unordered_map<int, int> m; for (int i = 0; i < n; i++) { int x; scanf( %d , &x); m[x]++; } int ans = 0; for (pair<int, int> x : m) ans += x.second / 2; printf( %d n , ans / 2); re... |
#include <bits/stdc++.h> using namespace std; const int MAXN = 16; int from[MAXN], to[MAXN], p[MAXN], q[MAXN]; bool w[MAXN][MAXN]; long long dp[1 << MAXN]; int main() { int n, m, a, b; long long y; cin >> n >> y >> m; fill(from, from + n, 0); fill(to, to + n, 0); fill(w[0], w[m], fal... |
#include <bits/stdc++.h> using namespace std; const int MX = 1000000 + 5; const long long inf = 1e9; const long long mod = 1e9 + 7; int a[MX], k; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, m, p, x, y, tc; cin >> tc; while (tc--) { cin >> n >> p >... |
#include <bits/stdc++.h> using namespace std; int32_t main() { unordered_map<string, long long> m; m[ Tetrahedron ] = 4; m[ Cube ] = 6; m[ Octahedron ] = 8; m[ Dodecahedron ] = 12; m[ Icosahedron ] = 20; long long n; cin >> n; long long count = 0; while (n--) { string s... |
#include<bits/stdc++.h> using namespace std; namespace Acc{ const int N = 1e2+10; string a,b; int n; void work(){ queue<pair<string,int> >q; cin>>n>>a,q.push({b,0}); while(1){ auto[u,pos]=q.front();q.pop(); u.resize(pos+1); fo... |
#include <bits/stdc++.h> using namespace std; long long par[27]; long long parent(long long x) { while (x != par[x]) { par[x] = par[par[x]]; x = par[x]; } return x; } void uni(long long x, long long y) { long long px = parent(x); long long py = parent(y); par[y] = px; } ... |
#include <bits/stdc++.h> #pragma GCC optimize(3, Ofast , inline ) using namespace std; const long long INF(0x3f3f3f3f3f3f3f3fll); const long long inf(0x3f3f3f3f); template <typename T> void read(T &res) { bool flag = false; char ch; while (!isdigit(ch = getchar())) (ch == - ) && (flag = true)... |
#include <bits/stdc++.h> using namespace std; void __print(int x) { cout << x; } void __print(long x) { cout << x; } void __print(long long x) { cout << x; } void __print(unsigned x) { cout << x; } void __print(unsigned long x) { cout << x; } void __print(unsigned long long x) { cout << x; } void __prin... |
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(NULL); int t; cin >> t; while (t--) { long long n, k; cin >> n >> k; if (k % 3 == 0) { if (n >= k) { n = n % (k + 1); if (n == k) cout << Alice n... |
#include <bits/stdc++.h> using namespace std; #define mod 1000000007 typedef long long ll; #define MAXN 300005 #define mod 1000000007 int main(){ int n; cin>>n; vector<int>ar(n+1); for(int i=1;i<=n;i++)cin>>ar[i]; vector<pair<int,pair<int,int> > >supp; for(int i=1;i... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n, m, k; cin >> n >> m >> k; int a[m + 1]; for (int i = 0; i < m + 1; i++) { cin >> a[i]; } int ans = 0; for (int i = 0; i < m; i++) { i... |
#include <bits/stdc++.h> using namespace std; unsigned long long mod = 1e9 + 7; int n, m; vector<int> depth; vector<bool> visited; vector<vector<int>> adj; void dfs(int curr, int dt) { depth[curr] = (dt) % 2; visited[curr] = true; for (int i = 0; i < adj[curr].size(); i++) { if (!visited... |
#include <bits/stdc++.h> using namespace std; long long mod = 1e9 + 7; void self_add(long long &x, long long y) { x = (x + y) % mod; } long long binpow(long long a, long long n) { long long res = 1; while (n) { if (n & 1) res = (res * a) % mod; n >>= 1; a = (a * a) % mod; } ret... |
#include <bits/stdc++.h> using namespace std; void solve() { int v; cin >> v; int a[9]; int t = 100000, x; for (long long i = 0; i < 9; ++i) { cin >> a[i]; t = min(t, a[i]); } if (t > v) { cout << -1; return; } x = v / t; while (x--) { for (int i... |
#include <bits/stdc++.h> int main() { int n, b = 1, i = 1; scanf( %d , &n); for (i = 1; i < n; i++) { b = b + i; if (b > n) b = b % n; printf( %d n , b); } return 0; } |
#include <bits/stdc++.h> using namespace std; struct node { int x, y, f; char na; } f[30]; bool cmp(node a, node b) { return a.na < b.na; } char s[1005][1005]; int s1[1005][1005]; int s2[1005][1005]; int main() { int n, m; scanf( %d%d , &n, &m); for (int i = 1; i <= n; i++) scanf( %s... |
#include <bits/stdc++.h> using namespace std; int n, head[100005], tot, d[100005], fa[100005], vis[100005], lf[100005], cnt; struct node { int v, nxt; } edg[100005 << 1]; inline void addedg(int u, int v) { edg[tot].v = v; edg[tot].nxt = head[u]; head[u] = tot++; } inline void init() { ... |
#include <bits/stdc++.h> using namespace std; const int MAXN = 200005; struct Edge { int to; int nxt; } edge[MAXN << 1]; int n, k, id; int first[MAXN]; int a[MAXN]; int fa[MAXN]; int f[MAXN]; int g[MAXN]; int sz[MAXN]; void addE(int u, int v) { edge[++id] = (Edge){v, first[u]}; f... |
#include <bits/stdc++.h> using namespace std; const int maxn = 510; const int inf = 0x3f3f3f3f; int n; long long d[maxn][maxn]; int w(int i, int j, int k) { return i * j * k; } int main() { int n; scanf( %d , &n); memset(d, 0x3f, sizeof(d)); for (int i = 1; i <= n; i++) { d[i][i + 2]... |
#include <bits/stdc++.h> using namespace std; long long n, k; int l, MOD; map<long long, int> mp; int fib(long long n) { if (mp.count(n)) return mp[n]; if (n & 1) return mp[n] = 1LL * fib(n / 2) * (fib(n / 2 - 1) + fib(n / 2 + 1)) % MOD; return mp[n] = (1LL * fib(n / 2) * fib(n / 2) + ... |
#include <bits/stdc++.h> using namespace std; void sol() { long long int n; cin >> n; vector<int> ar[6]; long long int a; vector<int> v = {4, 8, 15, 16, 23, 42}; for (long long int i = 0; i < n; i++) { cin >> a; ar[lower_bound(v.begin(), v.end(), a) - v.begin()].push_back(i); ... |
#include <bits/stdc++.h> using namespace std; const int inf = 1e9; const int bound = 400; struct qq { int id, vl; bool operator<(const qq &temp) const { return vl < temp.vl; } }; qq bk[210000 / bound][bound], ns; int nk[210000 / bound]; struct pp { int vl, id, min_value, value; int flag;... |
#include <bits/stdc++.h> using namespace std; inline void readi(int &x); const int maxn = 300005; int n, b[maxn], id[maxn], rk[maxn]; double fl[maxn], fr[maxn]; bool cmpb(const int &i, const int &j) { return b[i] < b[j]; } struct node { double div, dta; node *lc, *rc; inline void downdate() { ... |
#include <bits/stdc++.h> using namespace std; vector<pair<int, int> > seg[2]; int n, m, k, x, y, dX, dY; bool flag = 0; long long ans; void add(int tx, int ty) { seg[0].push_back(pair<int, int>(tx - ty, tx)); seg[1].push_back(pair<int, int>(tx + ty, tx)); } void reflect() { int fc; if (d... |
#include <bits/stdc++.h> using namespace std; int n, a[200005], d[200005], m(0), id, x; int main() { cin >> n; for (int i = 1; i <= n; i++) cin >> a[i], ++d[a[i]]; for (int i = 1; i <= n; i++) if (d[a[i]] > m) m = d[a[i]], id = i, x = a[i]; cout << n - m << n ; for (int i = id - 1; i; ... |
#include <bits/stdc++.h> using namespace std; const int OO = 0x3f3f3f3f, N = 1e5 + 5, mod = 1e9 + 7; const double pi = acos(-1), eps = 1e-9; int n, x, c = 1; vector<int> v; long long ans; int main() { scanf( %d , &n); for (int i = 0; i < n; ++i) { scanf( %d , &x); if (x >= c) { ... |
#include <bits/stdc++.h> using namespace std; const int N = 100010; int a[N]; long long dp[N]; int main() { int n; scanf( %d , &n); for (int i = 0; i < n; ++i) { int x; scanf( %d , &x); a[x]++; } long long ans = 0; dp[N - 1] = dp[N - 2] = 0; for (int i = N - 3; i ... |
#include <bits/stdc++.h> using namespace std; const long long INF = 1e9 + 10, MAX = 2e5 + 1e4, MOD = 1e9 + 7, MAXL = 25; void OUT(long double o, int x) { cout << fixed << setprecision(x) << o; return; } long long a[MAX], t = 1; vector<int> adj[MAX]; void dfs(int v, int p) { long long c = 0; ... |
#include <bits/stdc++.h> const int maxn = 1e6 + 1, mod = 1e9 + 7; int n, m, k, cnt[maxn], pow2[maxn], ans; int main() { scanf( %d%d%d , &n, &m, &k); ++k; while (m--) { int u, v; scanf( %d%d , &u, &v); if (u + 1 != v && u + k != v) { puts( 0 ); return 0; } ... |
#include <bits/stdc++.h> using namespace std; template <class T> using v2d = vector<vector<T> >; template <class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; } template <class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; } mt19937 rng(chrono::system_clock:... |
#include <bits/stdc++.h> using namespace std; int n, m, h, k, i, j, s2, H[2][3000], H2[2][3000], s, a, x, y, z, l[2], top; vector<pair<int, int> > v[2]; int main() { cin >> n >> m; for (i = 0; i < n; i++) { cin >> x >> y >> z; v[x].push_back(make_pair(z, y)); } h = m; sort(v[0].b... |
#include <bits/stdc++.h> using namespace std; bool adj[200][200]; int bfs(int source, int dest) { bool vis[200]; for (int i = 0; i < 200; i++) vis[i] = 0; queue<pair<int, int> > qe; qe.push({source, 0}); while (!qe.empty()) { int node = qe.front().first; int d = qe.front().second; ... |
#include <bits/stdc++.h> using namespace std; int is[1010]; int main() { int n; scanf( %d , &n); int x = 0; for (int i = (0); i < (n); ++i) for (int j = (0); j < (n); ++j) { int v; scanf( %d , &v); if ((i == j) && (v == 1)) x ^= 1; } int q; scanf( %d , &... |
#include <bits/stdc++.h> using namespace std; const long long MAX = 840; long long arr[9], W, ans; long long dp[7890]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> W; for (int i = 1; i < 9; ++i) { cin >> arr[i]; } if (W > 840) { for (int i = 1; i < 9; ++i) ... |
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; int a[n * n]; for (int i = 1; i <= n * n; ++i) a[i - 1] = i; if (k == 1) { long long sum = 0; for (int i = 0; i < n; ++i) { sum += n * i + 1; } cout << sum << endl; for (int ... |
#include <bits/stdc++.h> using namespace std; int f[5010][5010], ans[5010][5010]; int n, q; int main() { scanf( %d , &n); for (int i = 1; i <= n; i++) { scanf( %d , &f[i][i]); ans[i][i] = f[i][i]; } for (int i = 1; i < n; i++) for (int j = 1; j <= n - i + 1; j++) f[j][j... |
#include <bits/stdc++.h> using namespace std; int a[1003][1003]; int cost[43][1003][1003]; vector<vector<pair<int, int>>> COL(43); int n, m, k; int di1[4] = {0, 1, 0, -1}; int di2[4] = {1, 0, -1, 0}; void bfs(int col) { vector<bool> vis(43, 0); queue<pair<int, int>> q; for (int i = 0; i < CO... |
#include <bits/stdc++.h> using namespace std; long long i, i1, j, k, k1, t, n, m, res, flag[10], a, b, mt[110][110], s; char c; vector<array<long long, 6>> sl; vector<array<long long, 3>> cl; void mv(long long a, long long b, long long c, long long d, long long e, long long f) { sl.push_back({... |
#include <bits/stdc++.h> using namespace std; int n; int sz0[400000]; vector<int> g[400000]; vector<int> c0[400000]; int centroid; int sz[400000]; vector<int> cs[400000]; int ans[400000]; void dfs0(int x) { sz0[x] = 1; for (int y : g[x]) { if (sz0[y] == 0) { c0[x].push_back(y);... |
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; int a = min(k, 26) + 97; vector<char> b; for (int i = 97; i < a; i++) { b.push_back((char)i); } string key = ; for (int i = 0; i < b.size(); i++) key += b[i]; int c = n - k, j = 0; whi... |
#include <bits/stdc++.h> using namespace std; string itoa(int x) { string s = ; char c; if (x < 0) x *= -1, s += - ; while (x) { c = x % 10 + 48; s += c; x /= 10; } if (s[0] == - ) reverse(s.begin() + 1, s.end()); else reverse(s.begin(), s.end()); if... |
#include <bits/stdc++.h> using namespace std; int getValue(vector<int> &ai, int n, int sum) { int val = 0; int mval = ai[ai.size() - 1]; for (int i = 1; i <= mval; i++) { if (n * i >= sum) { val = i; break; } } return val; } int main() { int q; scanf( %d ,... |
#include <bits/stdc++.h> using namespace std; const int N = 1000 * 100 + 3; int n, a[N]; void input() { cin >> n; for (int i = 0; i + 1 < n; i++) cin >> a[i]; } void solve() { sort(a, a + n - 1); for (int i = 0; i + 1 < n; i++) if (a[i] != i + 1) cout << i + 1 << endl, exit(0); cou... |
#include <bits/stdc++.h> #pragma GCC optimize( O2 ) using namespace std; inline long long input() { long long n; cin >> n; return n; } string base2(long long n) { string a = ; while (n >= 2) { a += (char)(n % 2 + 0 ); n /= 2; } a += (char)(n + 0 ); reverse((a).b... |
#include <bits/stdc++.h> using namespace std; int n, m, p[50]; int ask(int second) { cout << second << n ; fflush(stdout); cin >> second; return second; } int main() { cin >> m >> n; for (int i = 0; i < n; i++) { p[i] = ask(1); if (p[i] == 0) { cout << 1 << n ; ... |
#include <bits/stdc++.h> using namespace std; string s; long long int dp[510][501]; long long int solve(long long int l, long long int r) { if (dp[l][r] != -1) { return dp[l][r]; } if (l > r) return 0; long long int a = 1 + solve(l + 1, r); for (long long int i = l + 1; i <= r; i++) { ... |
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int t; t = 1; while (t--) { long long n, a[1001]; cin >> n; for (int i = 0; i <= n - 1; i++) { cin >> a[i]; } sort(a, a + n); if (a[0] == 1) cout <<... |
#include <bits/stdc++.h> using namespace std; const double pi = 3.141592653589793; const int INF = 2000000000; const int mod = 1000000007; const int N = 100000000; const int base = 10; vector<int> read(string s) { vector<int> a; for (int i = (int)s.length(); i > 0; i -= 1) if (i < 1) ... |
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) #pragma GCC target( sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,popcnt,abm,mmx,avx,tune=native ) using namespace std; const int MOD = 1000000007; const int UNDEF = -1; const int INF = 1 << 30; template <typename T> inline bool chkmax(T &aa, T bb)... |
#include <bits/stdc++.h> const long long mod = 1000000007; const long long Inf = 1e9; using namespace std; long long a, b, d, k, t; double f(long long x) { double res = 0; res = (double)x * (double)a + (double)(max(x / k - (x % k == 0 ? 1 : 0), (long long)0)) * (double)t + (double)... |
#include <bits/stdc++.h> static int solve(); using ll = long long; int main(int argc, char* argv[]) { int tc = 1; scanf( %d , &tc); while (tc--) solve(); return 0; } static constexpr int MOD = 998244353; static int solve() { int n, x, y; scanf( %d %d %d , &n, &x, &y); int sum = x... |
#include <bits/stdc++.h> using namespace std; const int N = 100005; int power(int x, int y, int mod) { int ret = 1; for (; y; y >>= 1) { if (y & 1) ret = 1LL * ret * x % mod; x = 1LL * x * x % mod; } return ret; } int n, m; char s[N], t[N]; vector<int> primes = { 3, 5, ... |
#include <bits/stdc++.h> using namespace std; long long n, m, l, r, p, span, t, lwr, upr; long pr[200000]; vector<long> vec[200000]; long calc[200000]; long long res, nmoves[200000]; long long check[200000]; long long temp; long long answ; long long gcd(long long a, long long b) { while (a && b)... |
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string p( / ), t; while (n--) { string foo; cin >> foo; if (foo == pwd ) { cout << p << endl; } else { string dir; cin >> dir; dir += / ; for (int i = 0; i < ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.