func_code_string stringlengths 59 71.4k |
|---|
#include <bits/stdc++.h> using namespace std; struct node { long long siz, fa; bool vis; } a[1001]; string s; long long n, cnt[1001][1001]; vector<long long> e[1001]; vector<vector<long long> > t[1001]; vector<pair<long long, long long> > ans; void dfs(long long x) { a[x].siz = a[x].vis = ... |
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 1e3 + 7; int n, Q, m; int p[N]; int a[N], b[N]; struct Query { int t, x; } q[N]; int nd, fa[N], del[N]; int find(int x) { return x == fa[x] ? x : fa[x] = find(fa[x]); } int rt[N]; vector<int> g[N]; int vis[N]; int st[N], ed[... |
#include <bits/stdc++.h> using namespace std; long long a[10010]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); long long n, m, k; cin >> n >> m >> k; if (n % 2 == 0) { cout << 0; return 0; } if (m < ((n + 1) / 2)) { cout << 0; return 0; } long ... |
#include <bits/stdc++.h> using namespace std; const int MAXN = 2000005; int at[MAXN]; long long int n, x, y; int main() { cin >> n >> x >> y; int a; long long int f, g; f = y; g = x; for (int i = 0; i < x + y; i++) { if (f < g) { at[i] = 1; f += y; } else if... |
#include <bits/stdc++.h> using namespace std; template <typename Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << : << arg1 << std::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; int n, root = -1, nextnum = 3; vector<vector<int>> edges[100005]; int order[100005]; int main() { cin >> n; for (int i = 1; i <= n - 1; i++) { int a, b; cin >> a >> b; edges[a].push_back({b, i}); edges[b].push_back({a, i}); } ... |
#include <bits/stdc++.h> using namespace std; int a[5000]; int main() { int n, k, l, r, s, sk; cin >> n >> k >> l >> r >> s >> sk; int d = s - sk; for (int i = 1; i <= k; i++) { a[i] = sk / k; if (sk % k != 0) { a[i]++; sk--; } } if (k != n) { for (i... |
#include <bits/stdc++.h> using namespace std; signed main(int argc, char const *argv[]) { int t; cin >> t; while (t--) { int n; string s, k; cin >> n; cin >> s >> k; int ans = 0; string prev = 01 ; for (int i = 0; i < n; i++) { if ((s[i] == 0 && k[i] ... |
#include <bits/stdc++.h> using namespace std; int n, m; pair<int, int> p[100005], ans[100005]; int tot, start[100005], remain, now; int f[100005]; priority_queue<pair<int, int> > Q; int main() { cin >> n >> m; for (int i = 1; i <= m; i++) { scanf( %d%d , &p[i].first, &p[i].second); if ... |
#include <bits/stdc++.h> using namespace std; int n; int x[1024], y[1024], c[1024]; int pts[1024]; int chull[1024], tp; int chull_size; int ans_l[1024], ans_r[1024], ans_len = 0; void add_edge(int u, int v) { ans_l[ans_len] = u; ans_r[ans_len] = v; ans_len++; } void print_ans() { pri... |
#include <bits/stdc++.h> using namespace std; int n, m; vector<int> p, h, st; vector<vector<int>> adj; int gst(int curr, int prev) { int res = p[curr]; for (int next : adj[curr]) { if (next != prev) { res += gst(next, curr); } } return st[curr] = res; } int dfs(int curr... |
#include <bits/stdc++.h> using namespace std; const double pi = 3.14159265; const long long mod = 998244353; const long long N = 1e6 + 5; const long long st = 1e2; const int P0 = 437; const int P = 1003; int main() { cin.sync_with_stdio(); cin.tie(0); cout.tie(0); int q; cin >> q; ... |
#include<bits/stdc++.h> using namespace std; int main(){ int t; cin>>t; while(t--){ int n; cin>>n; int o=0,e=0; int a; for(int i=0;i<2*n;i++){ cin>>a; if(a%2==0) e++; else o++; } if(o == e) cout<< YES <<endl; else cout<< NO <<endl; ... |
#include <bits/stdc++.h> using namespace std; int main() { int i, n; int a[1005]; scanf( %d , &n); for (i = 1; i <= n; i++) { scanf( %d , &a[i]); } sort(a + 1, a + 1 + n); if (n % 2 == 0) { printf( %d n , a[n / 2]); } else { printf( %d n , a[(n + 1) / 2]); } ... |
#include <bits/stdc++.h> using namespace std; int main() { int n, c = 0, i, A[1000], B[1000], r, l, lo, u, j; cin >> n; for (i = 0; i < n; i++) { cin >> A[i] >> B[i]; } for (i = 0; i < n; i++) { r = 0; lo = 0; l = 0; u = 0; for (j = 0; j < n; j++) { if... |
#include <bits/stdc++.h> using namespace std; long long n, m; long long getans(long long n) { if (n == 1) return 3 % m; long long k = getans(n / 2); k *= k; if (n % 2) k *= 3; return k % m; } int main() { while (~scanf( %I64d%I64d , &n, &m)) { long long ans = getans(n) - 1; ... |
#include <bits/stdc++.h> using namespace std; long long a[100005]; deque<long long> q; long long mi[100005]; void add_q(long long ae) { while (!q.empty() && q.back() > ae) q.pop_back(); q.push_back(ae); } void pop_q(long long re) { if (!q.empty() && q.front() == re) q.pop_front(); } void s... |
#include <bits/stdc++.h> using namespace std; const long double PI = 3.141592653589793238462643383; int vector_init(vector<vector<long long int> > &x, int r, int c) { x.resize(r); for (int i = 0; i < (r); ++i) x[i].resize(c); } int abso(int a) { if (a > 0) return a; return -a; } void print... |
#include <bits/stdc++.h> const int MAX = 1 << 17; char s[MAX]; long long rje[2], dp[2][2][2][MAX]; int main() { int i, l, tmpdulj, j, k, ii; scanf( %s , s + 1); l = strlen(s + 1); for (i = 1; i <= l; i++) { dp[i % 2][1][s[i] - a ][i] = 1; rje[1]++; for (j = 0; j < 2; j++) ... |
#include <bits/stdc++.h> using namespace std; const int inf = 1000000000; bool cmp(pair<int, int> a, pair<int, int> b) { return a.second < b.second; } int main() { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; int a[n]; for (int i = 0; i < n; i++) cin >> a[i]; sort(a, a + n, ... |
#include <bits/stdc++.h> using namespace std; int n, m; vector<vector<char>> grid; pair<int, int> start, endloc; int memo[1000][1000][4]; bool dfs(pair<int, int> loc, int turns, int dir) { if (loc == endloc) return true; memo[loc.first][loc.second][dir] = turns; vector<pair<int, int>> next; ... |
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int s; cin >> s; int k, ans = 0; for (k = 1; s > 0 && s >= k; k += 2) s -= k, ++ans; for (k = min(s, k - 1); s > 0 && k >= 1; k--) { ... |
#include <bits/stdc++.h> using namespace std; const int MAXN = 100100; int N; long long K; int ar[MAXN]; int main() { cin >> N >> K; for (int i = 0; i < N; i++) cin >> ar[i]; --K; sort(ar, ar + N); for (int i = 0; i < N;) { int cur = i; int cnt = 0; while (i < N && ar[i... |
#include <bits/stdc++.h> using namespace std; void fileIO() {} bool sortbysecdesc(const pair<long long, long long> &a, const pair<long long, long long> &b) { return a.second > b.second; } int32_t main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); fileIO(); ... |
#include <bits/stdc++.h> using namespace std; const int Maxn = 300000; long long n, x[Maxn], w[Maxn], Index[Maxn], nx[Maxn]; set<pair<long long, long long> > poi, xx; set<pair<long long, long long> > u; void input() { cin >> n; for (int i = 0; i < n; i++) { cin >> x[i] >> w[i]; xx.insert... |
#include <bits/stdc++.h> using namespace std; int main() { int t, a, b, ans; scanf( %d , &t); while (t--) { ans = 0; scanf( %d %d , &a, &b); while (a > 0 && b > 0) { if (a >= b) { ans += (a / b); a = a % b; } else if (b > a) { ans += (b / a... |
#include <bits/stdc++.h> using namespace std; const int n = 3; long long r, g, b; void reset() { if (r >= g) swap(r, g); if (r >= b) swap(r, b); if (g >= b) swap(g, b); } int main() { while (cin >> r >> g >> b) { reset(); if ((r + g) * 2 <= b) cout << r + g << endl; ... |
#include <bits/stdc++.h> using namespace std; using Long = long long; int main() { int t; cin >> t; while (t--) { int d; cin >> d; if (d * d < 4 * d) { puts( N ); } else { double dis = sqrt(d * d - 4 * d); double x = (dis + d) / 2, y = (d - dis) / 2; ... |
#include <bits/stdc++.h> using namespace std; int main() { long long K, A, B, V; cin >> K >> A >> B >> V; long long nuts = A; long long divisors = B; long long capacity = V; long long maxSections = K; int boxes = 0; while (nuts > 0) { boxes++; int sections = min(divisors ... |
#include <bits/stdc++.h> using namespace std; int N, ans[(int)20 + 7][(int)20 + 7], a[500]; set<pair<int, int> > st; map<int, int> mp; int main() { ios::sync_with_stdio(false); cin >> N; for (int i = 0; i < N * N; i++) { cin >> a[i]; mp[a[i]]++; } int idx = -1; map<int, int... |
#include <bits/stdc++.h> using namespace std; int a1, a2, a3, a4; int main() { cin >> a1 >> a2 >> a3 >> a4; if (a3 == a4) { if (a1 - a3 - 1 >= 0 && a2 - a4 >= 0) { for (int i = 0; i < a1 - a3 - 1; i++) cout << 4 ; for (int i = 0; i < a3; i++) cout << 47 ; for (int i = 0; i ... |
#include <bits/stdc++.h> using namespace std; const long long M = 1e9 + 7; void flashSpeed() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } const long long N = 2e5 + 5; long long fact[N]; double Round(double var) { float value = (long long)(var * 100 + .5); return... |
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; int32_t main() { std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ; long long t; t = 1; cin >> t; for (long long tc = 0; tc < t; tc++) { string str; cin >> str; long long ... |
#include <bits/stdc++.h> using namespace std; long long MAXN = 9223372036854775807, mod = 998244353; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long T = 1; for (long long t = 0; t < T; t++) { long long n, s1, s2, p1, p2; cin >> n >> s1 >> s2 >> p1 >> p2; l... |
#include <bits/stdc++.h> using namespace std; int N; int A[100005]; int main(int argc, char *argv[]) { scanf( %d , &N); for (int i = (1), _n = (N); i <= _n; i++) scanf( %d , &A[i]); int hi = -1; for (int i = (1), _n = (N); i <= _n; i++) hi = max(hi, A[i]); bool done[100005] = {false}; in... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int B, K; cin >> B >> K; vector<int> a(K); for (int i = 0; i < K; ++i) cin >> a[i]; int odd = 0; bool flag = (B % 2 ? 1 : 0); for (int i = 0; i < ... |
#include <bits/stdc++.h> const double PI = acos(-1); using namespace std; const int mod = 1e9 + 7; const long long oo = 0x3f3f3f3f; const int nn = 1e2 + 15; vector<pair<int, int>> gr[nn], shifts; map<char, int> vis; long long get_distance(pair<int, int> a, pair<int, int> b) { return ((a.first - b.fi... |
#include <bits/stdc++.h> using namespace std; long long solve() { pair<long long, long long> init, final; cin >> init.first >> init.second >> final.first >> final.second; long long n; cin >> n; string s; cin >> s; pair<long long, long long> pre[n], cur = {0, 0}; map<char, pair<long l... |
#include <bits/stdc++.h> using namespace std; inline void FAST_IO() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); } int main() { FAST_IO(); int n, m; cin >> n >> m; pair<int, int> ac{0, 0}, bc{0, 0}; for (int i = 0; i < n; ++i) { int a; cin >> a; if (a % 2... |
#include <bits/stdc++.h> using namespace std; const int N = 210000, K = 60; int n, k, p; int a[N], sum[N], f[N][K]; int main() { scanf( %d%d%d , &n, &k, &p); for (int i = 1; i <= n; i++) scanf( %d , &a[i]), sum[i] = (sum[i - 1] + a[i] % p) % p; memset(f, -0x3f, sizeof(f)); f[0][0] = 0; ... |
#include <bits/stdc++.h> using namespace std; const int MAXN = 500005; int n, m, u[MAXN], v[MAXN]; bool cho[MAXN], sel[MAXN]; void solve() { int ans = 0; scanf( %d%d , &n, &m); for (int i = 1; i <= m; i++) { scanf( %d%d , &u[i], &v[i]); if (!cho[u[i]] && !cho[v[i]]) { sel[i] = ... |
#include <bits/stdc++.h> using namespace std; const long double pi = 3.1415926535897932384626433832795l; template <typename T> inline auto sqr(T x) -> decltype(x * x) { return x * x; } template <typename T1, typename T2> inline bool umx(T1& a, T2 b) { if (a < b) { a = b; return 1; ... |
#include <bits/stdc++.h> struct ele { int y, st; } tmp; std::vector<ele> edge[100100]; std::vector<int> gr[100100]; bool vi[100100]; int co[100100], N; int flag, sp[100100]; void dfs(int x) { int c, t; for (int k = 0; k < edge[x].size(); k++) { c = edge[x][k].y; t = edge[x][k].st... |
#include <bits/stdc++.h> using namespace std; long long a[1010000]; inline bool read(long long &num) { char in; bool IsN = false; in = getchar(); if (in == EOF) return false; while (in != - && (in < 0 || in > 9 )) in = getchar(); if (in == - ) { IsN = true; num = 0; }... |
#include <bits/stdc++.h> int main() { unsigned long long a, b, x; std::cin >> a >> b; a < b | a - b & 1 ? std::cout << -1 : (x = a - b >> 1, x ^ a - x ^ b ? std::cout << -1 : std::cout << x << << a - x); } |
#include <iostream> #include <bits/stdc++.h> int i = 0, j = 0, g = 0; #define int long long #define float double using namespace std; void solve(void) { int n; cin >> n; int a[2*n], config = 0; set <int> s; for (i = 0; i < 2*n; i++) { c... |
#include <bits/stdc++.h> using namespace std; const int N = 2005; int x[N], y[N], c[N], k[N], f[N]; int s[N], st, tu[N], tv[N]; struct node { int u, v; long long s; bool operator<(const node &p) const { return s < p.s; } } d[N * N + N]; int dis(int a, int b) { return abs(x[a] - x[b]) + abs(y[a... |
#include <bits/stdc++.h> using namespace std; inline long long read() { long long x = 0, f = 1; char ch = getchar(); while (ch < 0 || ch > 9 ) { if (ch == - ) f = -1; ch = getchar(); } while (ch >= 0 && ch <= 9 ) { x = x * 10 + ch - 0 ; ch = getchar(); } r... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; cin >> n; if (n == 5) { cout << YES n ; cout << 3 - 1 = 2 << n ; cout << 2 + 2 = 4 << n ; cout << 4 * 5 = 20 << n ; cout << ... |
#include <bits/stdc++.h> using namespace std; const int MAX = 1e5 + 10; const int MAXN = 1e4 + 10; const int MOD = 1e9 + 7; const int inf = 1e9; const double pi = acos(-1.0); const double eps = 1e-6; int dx[] = {0, -1, 0, 1}; int dy[] = {1, 0, -1, 0}; int x, y; int main() { ios::sync_with_stdi... |
#include <bits/stdc++.h> using namespace std; long long fp(long long x, long long y, long long m = 998244353) { long long ANS = 1; while (y) { if (y & 1) ANS = (ANS * x) % 998244353; x = (x * x) % 998244353; y >>= 1; } return ANS; } long long inv(long long x, long long m = 9982... |
#include <bits/stdc++.h> using namespace std; const double EPS = 1e-9; const int oo = (int)1e9; const double PI = 2 * acos(0.0); const double eps = 1e-7; const int MAXN = 1e5 + 10; int dx[] = {1, 0, -1, 0, -1, -1, 1, 1}; int dy[] = {0, 1, 0, -1, 1, -1, 1, -1}; int main() { int n, k, a[100009]; ... |
#include <bits/stdc++.h> using namespace std; int k, tot; int op[4]; char s; long long ans = 0x3f3f3f3f3f3f3f3f; long long a[5]; template <typename T> inline void read(T& x) { x = 0; T op = 1; char c = getchar(); for (; c < 0 || c > 9 ; c = getchar()) if (c == - ) op = -1; ... |
#include <bits/stdc++.h> using namespace std; double sqr(double x) { return x * x; } struct CPoint { double x, y, n, l; double length() { return sqrt(sqr(x) + sqr(y)); } }; CPoint a[100100], b[100100]; double length(CPoint p1, CPoint p2) { return sqrt(sqr(p1.x - p2.x) + sqr(p1.y - p2.y)); } ... |
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { long long int n, x, y; cin >> n >> x >> y; long long int maxi = x + y - 2 + 1; maxi = min(maxi, n); long long int mini = x + y - n; if (mini <= 0) mini = 1; else ... |
#include <bits/stdc++.h> const int base = 1000003; int n, k, d[201][30001], v[201]; bool isv[30010]; int fa[30010], tmp[30010]; bool on[30010]; struct edge { int to; edge* next; } E[60010], *ne = E, *first[30010]; void link(int u, int v) { *ne = (edge){v, first[u]}; first[u] = ne++; } ... |
#include <bits/stdc++.h> using namespace std; const int N = 100000 + 7; int n; int val[N]; struct edge { int to, nex; } e[N << 1]; int fir[N], eid; int siz[N], fa[N], son[N]; int dfn[N], pos[N], inx; int cnt[N], res[N]; long long mul[N], ans[N]; void addedge(int u, int v) { e[++eid] = (e... |
#include <bits/stdc++.h> using namespace std; int main() { int a[1010] = {0}; int n, i, s = 0, x, m = 0; cin >> n; for (i = 0; i < n; i++) { cin >> x; a[x]++; } for (i = 0; i <= 1000; i++) { if (a[i]) m++; if (a[i] > s) s = a[i]; } cout << s << << m << end... |
#include <bits/stdc++.h> using namespace std; const int inf = (1 << 30) - 1; const long long linf = (1ll << 62) - 1; int GLL(long long& x) { return scanf( %lld , &x); } int GI(int& x) { return scanf( %d , &x); } void IO() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin.exceptions(ios... |
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) #pragma GCC optimize(2) #pragma GCC optimize(3) const int N = 1e6 + 10, p1 = 1e9 + 7, p2 = 1e9 + 9; int n, k, len; char s[N << 1], ch; int strhash[N][2], hashbase[2], hashpow[2] = {1, 1}, tmp[2]; std::map<std::pair<int, int>, int> mp; std::set<int... |
#include <bits/stdc++.h> using namespace std; int main() { long int t; cin >> t; while (t--) { long long int a, b, c, d; cin >> a >> b; if (a % b == 0) cout << 0 << endl; else if (b > a) cout << (b - a) << endl; else { c = a / b; c++; ... |
#include <bits/stdc++.h> using namespace std; const int N = 1e3 + 5; const long long inf = 9e18 + 9; const int mod = 1e9 + 7; long long res; int indeg[N], outdeg[N], diam[N], adj[N]; void solve() { int n, m; cin >> n >> m; for (int i = 0; i < m; i++) { int u, v, val; cin >> u >> v ... |
#include <bits/stdc++.h> using namespace std; const int N = 1e6, inf = 2e9 + 2; vector<pair<int, int> > ad[N + 2], tree[N + 2]; int br[N + 2]; vector<int> bkad[N + 2]; int vis[N + 2], lev[N + 2]; void clear(int n, int m) { for (int i = 1; i <= n; i++) { tree[i].clear(), bkad[i].clear(); vi... |
#include <bits/stdc++.h> const int mod = 1000000007; using namespace std; long long gcd(long long a, long long b) { if (a == 0) return b; return gcd(b % a, a); } long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); } int prime[100007]; void SieveOfEratosthenes(int n) { memset(... |
#include <bits/stdc++.h> using namespace std; using namespace std; long long power(long long x, long long y) { long long temp = 1; while (y > 0) { if (y % 2 == 1) temp = (x * temp) % 1000000007; x = (x * x) % 1000000007; y = y / 2; } return temp; } long long n; string st; ... |
#include <bits/stdc++.h> using namespace std; void Braka() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); } int main() { Braka(); int n, k, ans = 0; cin >> n >> k; while (n--) { set<char> st; string s; cin >> s; for (int i = 0; i < s.length(); i++) ... |
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e6; int n, seg[MAXN], r[MAXN], v[MAXN], resp; void update(int ini, int fim, int cur, int id, int aux) { if (id < ini || fim < id) return; if (ini == fim) { seg[cur] = aux; r[cur] = aux; return; } int m = (ini + fim... |
#include <bits/stdc++.h> using namespace std; void readi(int &x) { int v = 0, f = 1; char c = getchar(); while (!isdigit(c) && c != - ) c = getchar(); if (c == - ) f = -1; else v = v * 10 + c - 0 ; while (isdigit(c = getchar())) v = v * 10 + c - 0 ; x = v * f; } void ... |
#include <bits/stdc++.h> int main() { int t; scanf( %d , &t); while (t--) { static int aa[100]; static char used[100]; int n, m, i, yes; scanf( %d%d , &n, &m); for (i = 0; i < n; i++) scanf( %d , &aa[i]); memset(used, 0, (n - 1) * sizeof *used); while (m--) { ... |
#include <bits/stdc++.h> using namespace std; vector<int> g[200005]; queue<pair<int, int> > q; int deg[200005], a, n; bool v[200005]; set<int> s[200005]; int main() { scanf( %d , &n); for (int i = 1; i < n; i++) { int a, b; scanf( %d%d , &a, &b); g[a].push_back(b); g[b].pus... |
#include <bits/stdc++.h> int x[100005]; using namespace std; bool cmp(int a, int b) { return a < b; } int main() { int n, i, q, k; scanf( %d , &n); for (i = 0; i < n; i++) { scanf( %d , &x[i]); } sort(x, x + n, cmp); scanf( %d , &q); while (q--) { int m; scanf( %d ,... |
#include <bits/stdc++.h> using namespace std; int a[1005], b[1005]; int x[1005], y[1005]; int main() { int n; while (scanf( %d , &n) != EOF) { memset(x, 0, sizeof(x)); memset(y, 0, sizeof(y)); for (int i = 0; i < n; ++i) { scanf( %d%d , &a[i], &b[i]); x[a[i]]++; ... |
#include <bits/stdc++.h> using namespace std; const double EPS = 1e-9; const int INF = 0x3f3f3f3f; int sgn(double a) { return ((a > EPS) ? (1) : ((a < -EPS) ? (-1) : (0))); } int cmp(double a, double b = 0.0) { return sgn(a - b); } struct node { int x, y; node(int x = 0, int y = 0) : x(x), y(y) {} ... |
#include <bits/stdc++.h> using namespace std; const long long N = 2e5 + 5; const long long mod = 998244353; vector<long long> adj[N]; long long dp[N][4], f[N][3]; void dfs(long long x) { if (adj[x].size() == 0) { dp[x][2] = 1; return; } else { dp[x][0] = 1; } for (long long... |
#include <bits/stdc++.h> int main() { int x; scanf( %d , &x); if (x == 3) printf( 5 n ); else { for (int i = 1; i <= 100; i += 2) { if (i * i - (i * i) / 2 >= x) { printf( %d n , i); break; } } } } |
#include <bits/stdc++.h> using namespace std; pair<int, int> a[111111], b[111111]; int n; int main() { scanf( %d , &n); for (int i = 1; i <= n; i++) { scanf( %d , &a[i].first); a[i].second = i; } for (int i = 1; i <= n; i++) { scanf( %d , &b[i].first); b[i].second = i; ... |
#include <bits/stdc++.h> using namespace std; int fact[300001]; int invfact[300001]; int pw(int a, int e) { if (e == 0) return 1; int tmp = pw(a, e / 2); tmp = (tmp * ((long long)tmp)) % 1000000007; if (e & 1) tmp = (tmp * ((long long)a)) % 1000000007; return tmp; } void computeFactorial... |
#include <bits/stdc++.h> using namespace std; const long long MOD = (1e9) + 7; const long double EPS = 0.0000001; int main(void) { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; int pa; cin >> pa; deque<int> arr; int ans = 0; for (int i = 0; i < n; i++) { ... |
#include <bits/stdc++.h> using namespace std; int t, n, m; int a[10][10]; int main() { cin >> t; while (t--) { cin >> n >> m; int ok = 0; for (int i = 1; i <= n; i++) { cin >> a[1][1] >> a[1][2] >> a[2][1] >> a[2][2]; if (a[1][2] == a[2][1]) { ok = 1; ... |
#include <bits/stdc++.h> using namespace std; int main() { int t; int n; cin >> t; for (int u = 0; u < t; u++) { cin >> n; int arr[n]; for (int i = 0; i < n; i++) cin >> arr[i]; vector<int> v; int mini = arr[n - 1]; for (int i = (n - 2); i >= 0; i--) { if ... |
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000000 + 7; const int N = 100000 + 50; vector<int> a; int val[N]; int p[N]; int rp[N]; int avl[N]; pair<int, int> dp[N]; int curn; pair<int, int> bit[N]; vector<vector<int> > fa; void clear_bit(int n) { for (int i = 0;... |
#include <bits/stdc++.h> #pragma GCC optimize(2) using namespace std; template <typename T> T gcd(T a, T b) { return b == 0 ? a : gcd(b, a % b); } const int maxn = 1e5 + 5; const long long mod = 1e9 + 7; int Case = 1; int n, m; struct node { int x, y, xx, yy; } a, b, c; vector<int> A, B;... |
#include <bits/stdc++.h> using namespace std; void calc() { long long n, m; cin >> n >> m; vector<pair<long long, long long> > v; vector<long long> a; for (long long i = 0; i < m; i++) { long long ai, bi; cin >> ai >> bi; v.push_back(make_pair(ai, bi)); a.push_back(ai); ... |
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 7; const int inf = INT_MAX; const long long inff = 5e18; const long long mod = 1e9 + 7; long long f[7]; long long dp[maxn], dp2[maxn]; vector<long long> value = {0, 0, 0, 1, 0, 0, 2, 0, 0, 3}; void update(long long x, long long dd) {... |
#include <bits/stdc++.h> using namespace std; int n, m, a[2000000 + 100]; int main() { cin >> n >> m; if ((m < n - 1) || (m > 2 * (n + 1))) { cout << -1 << endl; return 0; } for (int i = 1; i <= n; i++) a[2 * i] = 0; for (int i = 2; i <= n; i++) a[2 * i - 1] = 1; m = m - (n - 1... |
#include <bits/stdc++.h> using namespace std; long long n, m, i; const int maxn = 1e5 + 20; int arr[maxn]; int main() { cin >> n >> m; int x = m; if (m <= n * 2) { for (int i = 1; i <= m; i++) { cout << i << ; } } else { for (i = 1; i <= (m - n * 2); i++) { ... |
#include <bits/stdc++.h> using namespace std; const long long inf = 1e18; long long dp[10000005], sol = 0; int main() { int n, i; long long x, y; scanf( %d%I64d%I64d , &n, &x, &y); for (i = 1; i <= 10000005; i++) dp[i] = inf; dp[1] = x; for (i = 2; i <= n; i++) { dp[i] = min(dp[i],... |
#include <bits/stdc++.h> using namespace std; int pen[2000005]; void update(int ind, int add) { while (ind < 2000005) { pen[ind] += add; ind += ind & (-ind); } } int query(int ind) { int ret = 0; while (ind > 0) { ret = ret + pen[ind]; ind = ind & (ind - 1); } r... |
#include<bits/stdc++.h> #define For(i,x,y) for (register int i=(x);i<=(y);i++) #define FOR(i,x,y) for (register int i=(x);i<(y);i++) #define Dow(i,x,y) for (register int i=(x);i>=(y);i--) #define Debug(v) for (auto i:v) cout<<i<< ;puts( ) #define mp make_pair #define fi first #define se second #defin... |
#include <bits/stdc++.h> using namespace std; bool compare(const pair<int, int> &i, const pair<int, int> &j) { return i.second > j.second; } int n, d; vector<pair<long long, long long>> a; long long p(long long a, long long b) { long long x = 1, y = a; while (b > 0) { if (b % 2 == 1) { ... |
#include <bits/stdc++.h> using namespace std; vector<long long int> g[100005]; long long int vis[100005]; vector<double> ans; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int t = 1; cin >> t; while (t--) { long long int a, b, c, d; cin >> a >> b >... |
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0), cin.tie(0); long long n, k; cin >> n >> k; long long a[k]; map<long long, bool> m; for (long long i = 0; i < k; i++) { cin >> a[i]; m[a[i]] = true; } long long cnt = 1; for (long long ... |
#include <bits/stdc++.h> const int mx = 1e6 + 5; const int inf = 0x3f3f3f3f; using namespace std; vector<int> ans; int dfs(long long int a, long long int b) { if (a > b) return 0; if (a == b) return 1; if (dfs(a * 2, b)) { ans.push_back(2 * a); return 1; } if (dfs(a * 10 + 1, b... |
#include <bits/stdc++.h> using namespace std; inline int sqr(int x) { return x * x; } int main() { int n, m, x, y; map<int, int> targets; vector<int> ans, r; scanf( %d , &n); ans.assign(n, -1); r.assign(n, 0); for (int i = 0; i != n; ++i) { scanf( %d%d , &x, &r[i]); targets... |
#include <bits/stdc++.h> using namespace std; int main(int argc, char** argv) { int x0, y0, x, y, n; int i, j, r, a, b; set<pair<int, int> > s; queue<pair<int, pair<int, int> > > q; cin >> x0 >> y0 >> x >> y >> n; for (i = 0; i < n; i++) { cin >> r >> a >> b; for (j = a; j <= b; ... |
#include <bits/stdc++.h> using namespace std; const int mx = 1e6 + 10, inf = 1e9 + 10; long long int t, n, ans, a[mx]; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> t; while (t--) { cin >> n; cout << (n + 1) / 10 << endl; } return 0; } |
#include <bits/stdc++.h> using namespace std; int arr[10000]; int n = 0; void init() { queue<string> q; q.push( 4 ); q.push( 7 ); while (!q.empty()) { string u = q.front(); q.pop(); arr[n++] = stoi(u); if (u.length() < 9) { q.push(u + 4 ); q.push(u + 7 )... |
#include <bits/stdc++.h> using namespace std; void mod(string &s) { for (int i = 0; i < (int)s.size(); i++) { switch (s[i]) { case N : s[i] = S ; break; case S : s[i] = N ; break; case E : s[i] = W ; break; c... |
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; struct fastio { char s[100000]; int it, len; fastio() { it = len = 0; } inline char get() { if (it < len) return s[it++]; it = 0; len = fread(s, 1, 100000, stdin); if (len == 0) return EOF; ... |
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf( %d , &n); vector<int> piles(n); vector<pair<int, int>> cost(n); for (int i = 0; i < n; i++) { int tmp; scanf( %d , &tmp); piles[i] = tmp; int closest = int(sqrt(tmp) + 0.5f); cost[i] = pair<int... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.