solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> out; for (int i = max(1, n - 90); i <= n; ++i) { int sd = 0, temp = i; while (temp) { sd = sd + temp % 10; temp = temp / 10; } if (i + sd == n) { out.push_back(i); } } cout << out.si...
4
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[n], k = 0; for (int i = 0; i < n; i++) { scanf("%d", &a[i]); k += a[i]; } for (int i = 1; i < n - 1; i++) if (a[i] == 0 && a[i - 1] == 1 && a[i + 1] == 1) k++; cout << k; return 0; }
1
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; int n, k; int x[N], f[N], le[N], ri[N]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> k; for (int i = (int)1; i <= (int)k; i++) cin >> x[i]; long long tot = 3 * n - 2; map<pair<long long, long long>, int...
7
#include <bits/stdc++.h> using namespace std; vector<int> g[203]; struct cop { int x, y; }; cop ans[403]; int coun; bool used[203]; int main() { int n, m; cin >> n >> m; int i, j, jj; int x, y; int sum = 0; for (i = 0; i < m; i++) { cin >> x; g[i].resize(x); for (j = 0; j < x; j++) { cin...
10
#include <bits/stdc++.h> using namespace std; const double eps = 1e-9; const int inf = 2000000000; const long long infLL = 9000000000000000000; inline bool checkBit(long long n, int i) { return n & (1LL << i); } inline long long setBit(long long n, int i) { return n | (1LL << i); } inline long long resetBit(long long n...
12
#include <bits/stdc++.h> using namespace std; const int mxN = 2e5; int main() { int n; cin >> n; int arr[n], mx = 0; map<int, int> mp; for (int i = 0; i < n; ++i) { cin >> arr[i]; mp[arr[i]]++; mx = max(mx, mp[arr[i]]); } for (int i = 0; i <= (int)1e5; ++i) { if (mp[i + 1] < mp[i + 2]) { ...
7
#include <bits/stdc++.h> using namespace std; long n; long top = -1; int main() { cin >> n; for (long i = 0; i < n; i++) { long temp; cin >> temp; if (temp > top + 1) { cout << i + 1 << '\n'; return 0; } if (temp == top + 1) top++; } cout << -1 << '\n'; return 0; }
2
#include <bits/stdc++.h> using namespace std; using point = complex<long long>; const int N = 200, M = 1000000007; int ways[N][N]; point p[N]; long long cross(point a, point b) { return a.real() * b.imag() - a.imag() * b.real(); } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> ...
17
#include <bits/stdc++.h> using namespace std; char s[109][109]; int main() { int n, m, flag = 1; scanf("%d%d", &n, &m); int i, j; for (i = 0; i < n; i++) { scanf("%s", &s[i]); } for (i = 0; i < n; i++) { for (j = 0; j < m; j++) { int cnt = 0; if (s[i][j] != '*') { if (s[i][j - 1]...
3
#include <bits/stdc++.h> using namespace std; const int maxn = 3e5 + 10; int t, n, q; int sum[maxn]; int sum2[maxn]; map<int, vector<int> > a; void init() { a.clear(); } int sol(int l, int r) { int now = sum[r] + sum[l - 1]; int tp = lower_bound(a[now].begin(), a[now].end(), l) - a[now].begin(); return a[now][tp]...
14
#include <bits/stdc++.h> using namespace std; const long long INF = 1e18; const int maxn = 2e5 + 10; struct node { long long v, next; } edge[maxn * 2 + 10]; long long cnt, head[maxn], sum[maxn], fa[maxn], sd[maxn]; void add(long long x, long long y) { edge[cnt].next = head[x]; edge[cnt].v = y; head[x] = cnt++; ...
8
#include <bits/stdc++.h> using namespace std; int n, i; string s; int sols; int us[26 + 5]; void check(char ch) { int i, j, dif, act; vector<int> pos = {}; int ans = 0; for (i = 0; i < n; i++) if (s[i] == ch) pos.push_back(i); for (dif = 1; dif < n; dif++) { memset(us, 0, sizeof(us)); for (auto p ...
8
#include <bits/stdc++.h> #pragma GCC optimize("O3") #pragma GCC target("sse4") using namespace std; template <typename T> void etch(T V) { for (auto x : V) cout << x << ' '; cout << '\n'; } vector<string> vec_splitter(string s) { s += ','; vector<string> res; while (!s.empty()) { res.push_back(s.substr(0,...
16
#include <bits/stdc++.h> using namespace std; int get(int l, int r, string &s) { int ans = 0; int pow = 1; for (int i = r; i >= l; i--) { if (s[i] == '1') { ans += pow; } pow <<= 1; } return ans; } void solve() { int t; cin >> t; while (t--) { string s; cin >> s; vector<int...
9
#include <bits/stdc++.h> using namespace std; int x, y, sum; int i; int main() { scanf("%d %d", &x, &y); i = 1; while (i > 0) { if (i % 2 == 1) { if (x >= 2 && y >= 2) { x -= 2; y -= 2; } else if (x >= 1 && y >= 12) { x--; y -= 12; } else if (x >= 0 && y >= 22...
4
#include <bits/stdc++.h> const long long logN = 20; const long long M = 1000000007; const long long INF = 1e12; const long long N = 100005; using namespace std; using namespace std::chrono; bool prime[100005]; void SieveOfEratosthenes() { long long n = 100005; memset(prime, true, sizeof(prime)); for (long long p ...
0
#include <bits/stdc++.h> using namespace std; int main() { int k; scanf("%d", &k); map<int, pair<int, int>> mp; for (int i = 0; i < k; i++) { int n, sum = 0; scanf("%d", &n); vector<int> a(n); for (int j = 0; j < n; j++) { scanf("%d", &a[j]); sum += a[j]; } for (int j = 0; j ...
6
#include <bits/stdc++.h> using namespace std; const int mod = 1000000007; inline int add(int a, int b) { if ((a += b) >= mod) a -= mod; return a; } inline int mult(int a, int b) { long long t = 1ll * a * b; if (t >= mod) t %= mod; return t; } inline int power(int a, int b) { int out = 1; while (b) { i...
12
#include <bits/stdc++.h> using namespace std; #define int long long int find(vector<int> h,int n,int m,int k) { vector<int> pref(n+1,0); for(int i=0;i<n;i++) pref[i+1]=pref[i]+h[i]; int ans=0; for(int x=-k;x<n;x++) { int cnt=pref[min(x+k+1,n)]-pref[max(x,0LL)]; ans+=cnt*(cnt-1)*(...
7
#include <bits/stdc++.h> using namespace std; string m[12] = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}; int main() { string c; int k, nm; cin >> c >> k; for (int i = 0; i < 12; i+...
1
#include <bits/stdc++.h> using namespace std; int main() { int n, k, count = 1; cin >> n >> k; char c[100]; for (char e = 'a'; e <= 'z'; e++) { c[count] = e; count++; if (count > k) break; } int reverse = 1; for (int j = count; j <= n; j++) { c[j] = c[reverse]; reverse++; } for (in...
0
#include <bits/stdc++.h> using namespace std; long long cubic_root(long long x) { long long l = 0; long long r = 1000005; while (l != r) { long long m = (l + r + 1) / 2; if (m * m * m > x) { r = m - 1; } else { l = m; } } return l; } int main() { int n; scanf("%d", &n); for (...
9
#include <bits/stdc++.h> using namespace std; pair<int, int> S[100000]; long long R[100001]; int main(void) { int i, j, k, e, n, m, x; long long t = 0, a; cin >> n >> m; for (i = 1; i <= n;) { for (j = 0; i <= n && j < m; i++, j++) { cin >> a >> x; S[j] = make_pair(x, i); } t = max(t, a)...
7
#include <bits/stdc++.h> using namespace std; inline int gi() { char c = getchar(); int x = 0; for (; c < '0' || c > '9'; c = getchar()) ; for (; c >= '0' && c <= '9'; c = getchar()) x = (x << 1) + (x << 3) + c - '0'; return x; } const int N = 3e6 + 5; int n, m, a[N], f[N], g[N], ans; int main() { n = g...
18
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; if (n % 10 > 5) n += 10; cout << n - (n % 10); }
0
#include <bits/stdc++.h> int t, a, b; int main() { scanf("%d", &t); for (int i = 0; i < t; i++) { scanf("%d%d", &a, &b); if (b == 0) printf("%.7lf\n", 1.0); else if (a == 0) printf("%.7lf\n", 0.5); else if (a <= 4 * b) printf("%.7lf\n", 0.5 + 1.0 / 16 * a / b); else print...
10
#include <bits/stdc++.h> using namespace std; int a[30002]; int c[30002], d[30002]; int main() { int t, i, n; cin >> t; for (; t; t--) { cin >> n; for (i = 1; i <= n; i++) cin >> a[i]; d[1] = a[1]; for (i = 2; i <= n; i++) { d[i] = min(d[i - 1], a[i] - c[i - 1]); if (d[i] < 0) break; ...
10
#include <bits/stdc++.h> using namespace std; const int N = 200000; struct node { long long ans, sum; int cnt; } tree[2 * N - 1]; int inline getidx(int s, int t) { return s + t | s != t; } void Operate(int l, int r, int idx, int v, int sign) { int nowidx = getidx(l, r); if (l == r) { tree[nowidx].cnt += sig...
17
#include <bits/stdc++.h> using namespace std; int n; vector<pair<int, int> > adj[2010 * 2]; int color[2010 * 2]; bool impossible; void dfs(int u, int co) { if (color[u] == co) return; if (color[u] != -1) { impossible = true; return; } color[u] = co; for (auto V : adj[u]) { int v = V.first; int...
13
#include <bits/stdc++.h> using namespace std; inline void read(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; } inline void read(long lon...
16
#include <bits/stdc++.h> using namespace std; unsigned long long a[1000000], b[1000000]; int main() { unsigned long long k1, k2, k3, t1, t2, t3, n, x; cin >> k1 >> k2 >> k3 >> t1 >> t2 >> t3 >> n; for (int i = 0; i < n; i++) { cin >> a[i]; b[i] = a[i]; } int i; for (i = 0; i < k1 && i < n; i++) b[i]...
10
#include <bits/stdc++.h> using namespace std; int n, k, x; long long res, r2; vector<long long> V, V2; long long P[2][200002]; int main() { ios_base::sync_with_stdio(0); cin >> n >> k >> x; long long a = 1; for (int i = 0; i < k; i++) a *= x; for (int i = 0; i < n; i++) { int b; cin >> b; V.push_b...
9
#include <bits/stdc++.h> using namespace std; int a[100500]; int perm[100500]; int now[100500]; int pos[100500]; vector<pair<int, int> > res; int happy; bool cmp(int x, int y) { return a[x] < a[y]; } bool isHappy(int x) { while (x > 0) { if (x % 10 != 4 && x % 10 != 7) { return false; } x /= 10; }...
12
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(NULL); cin.tie(NULL); cout.tie(NULL); int c, m; cin >> c >> m; vector<int> arr(c + 1, 0); int ans(0); for (int i = 1; i <= m; i++) { int a; cin >> a; arr[a]++; int temp(1); for (int j = 1; j <= c; j+...
1
#include <bits/stdc++.h> using namespace std; vector<long long> ve[100005]; long long vis[100005], z; void solve() { vector<long long> v; vector<pair<long long, long long>> vp; map<long long, long long> mp; set<long long> st; multiset<long long> mst; long long n = 0, m = 0, i = 0, j = 0, k = 0, c = 0, l = 0...
10
#include <bits/stdc++.h> #pragma GCC optimize("-O2") using namespace std; void err(istream_iterator<string> it) { cerr << endl; } template <typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cerr << *it << " = " << a << "\t"; err(++it, args...); } template <typename T1, typenam...
12
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma") #pragma GCC optimize("unroll-loops") using namespace std; long long a[100005], b[100005], p[100005]; long long fin(long long x) { if (x == p[x]) return x; return p[x] = fin(p[x]); } bool...
16
#include <bits/stdc++.h> using namespace std; char s[101]; int rev; int getr(int x) { stack<int> tmp; while (x > 0) { tmp.push(x % 2); x /= 2; } while (tmp.size() < 8) { tmp.push(0); } int j = 1, sum = 0; while (!tmp.empty()) { int a = tmp.top(); tmp.pop(); sum += (a * j); j = ...
5
#include <bits/stdc++.h> const int N = 250005; struct sta { int s[5]; bool operator<(const sta &b) const { for (int i = 0; i < 5; i++) if (s[i] != b.s[i]) return s[i] > b.s[i]; return false; } void init() { for (int i = 0; i < 5; i++) s[i] = 0; } } dis[505]; int tail, tmp[5]; void dfs(int nu...
18
#include <bits/stdc++.h> using namespace std; int N, K; int ans[100010]; int main() { cin >> N >> K; if (N == K) { for (int i = 1; i <= N; i++) putchar('0'); puts(""); } else { int p = (N - K) / 2; int res = p; for (int i = 1; i <= N; i++) { if (res) --res, putchar('0'); el...
14
#include <bits/stdc++.h> using namespace std; int main() { int i, n, k, robot = 0, shout = 0, nextShoutLength = 1, id[100005]; cin >> n >> k; for (i = 0; i < n; i++) cin >> id[i]; while (shout + nextShoutLength < k) shout += nextShoutLength, nextShoutLength += 1, ++robot; k -= robot * (robot + 1) / 2; c...
2
#include <bits/stdc++.h> using namespace std; int main() { long long r, c, k, rr, cc, mx; cin >> r >> c >> k; if (k < r || k < c) { mx = max(r / (k + 1) * c, c / (k + 1) * r); } else { mx = max(c / (k - (r - 1) + 1), r / (k - (c - 1) + 1)); } if (k > r - 1 + c - 1) mx = -1; cout << mx << endl; r...
9
#include <bits/stdc++.h> using namespace std; long long a[100050]; int main() { long long b, k, x; cin >> b >> k; for (int i = int(0); i < int(k); ++i) cin >> a[i]; long long ans = 0, pot = 1; for (int i = k - 1; i >= 0; --i) { ans = (ans + a[i] * pot) & 1; pot = (pot * b) & 1; } if (!ans) put...
1
#include<bits/stdc++.h> using namespace std; typedef long long ll; ll check(ll n) { ll p=sqrt(n); if(p*p==n) return 1; else return 0; } int main() { ll t; cin>>t; while(t--) { ll n,i,j,k=0; cin>>n; k=0; if(n%2==1){ cout<<"NO"<<end...
2
#include <bits/stdc++.h> using namespace std; int f(int n) { int s = 0; while (n) { if (n % 10 == 4 || n % 10 == 7) ++s; n /= 10; } return s; } int main() { int n, k, r = 0; scanf("%d%d", &n, &k); while (n--) { int x; scanf("%d", &x); r += f(x) <= k; } cout << r; return 0; }
0
#include <bits/stdc++.h> using namespace std; using ll = long long; const int MAXN = 2e5 + 5; int H, M, N, G = 0; int group[MAXN], loc[MAXN]; set<int> open[MAXN]; unordered_map<int, pair<int, int>> locs; void solve() { cin >> H >> M >> N; for (int i = (0); i < (H); i++) group[i] = -1; int repeats = 0; for (int ...
11
#include <bits/stdc++.h> using namespace std; const int64_t M1 = 998244353; const int64_t M2 = 1000000007; mt19937 rng((uint64_t)chrono::steady_clock::now().time_since_epoch().count()); vector<vector<int64_t>> a(3); vector<int64_t> node[100001]; vector<int64_t> colour(3), actual_colour(3); vector<int64_t> mark(100001);...
10
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, m, l, r; cin >> n >> m; vector<int> v(n, 0); while (m--) { cin >> l >> r; } for (int i = 0; i < n; i++) { if (i % 2 != 0) v[i] = 1; } for (int i : v) co...
5
#include <bits/stdc++.h> #pragma GCC optimization("O3") using namespace std; const long long inf = INT_MAX; const long long inf2 = 1e18; const long long minf = -1 * 1e9; const long long MAX = 1e5 + 5; const long long MOD = 1e9 + 7; const double pi = acos(-1.0); const double EPS = 1e-9; void init(int precision) { ios_...
1
#include <bits/stdc++.h> using namespace std; const long long M = 1e9 + 7; const int P = 31; const int MaxM = 200005; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t; cin >> t; while (t--) { long long n; cin >> n; long long a[n]; set<long long> s; for ...
0
#include <bits/stdc++.h> using namespace std; const int maxn = 3 * 1e5 + 5; int N, arr[maxn]; int main() { scanf("%d", &N); long long sum = 0; for (int i = 1; i <= N; i++) { scanf("%d", &arr[i]); sum += arr[i]; } sort(arr + 1, arr + 1 + N); long long ans = sum; for (int i = 1; i < N; i++) { an...
4
#include <bits/stdc++.h> using namespace std; long long n, times, file[200005], pos[200005]; int main() { cin >> n; for (int i = 1; i <= n; i++) { scanf("%lld", &file[i]); pos[file[i]] = i; } for (int i = 2; i <= n; i++) times += abs(pos[i] - pos[i - 1]); cout << times; }
4
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(NULL); int n, a, b, i, cost = 0; cin >> n >> a >> b; int c[n]; for (i = 0; i < n; ++i) { cin >> c[i]; } for (i = 0; i < n / 2; ++i) { if (c[i] == 0) { if (c[n - i - 1] == 1) { cout << -1...
2
#include <bits/stdc++.h> using namespace std; extern inline char gc() { static char RR[23456], *S = RR + 23333, *T = RR + 23333; if (S == T) fread(RR, 1, 23333, stdin), S = RR; return *S++; } inline int read() { int p = 0, w = 1; char c = gc(); while (c > '9' || c < '0') { if (c == '-') w = -1; c = ...
27
#include <bits/stdc++.h> using namespace std; const int N_ = 5050; int N; long long tb[N_][N_]; long long X[N_], A[N_], B[N_], C[N_], D[N_], W[N_]; int S, E, P[N_]; int main() { scanf("%d%d%d", &N, &S, &E); P[S + 1] = P[E + 1] = 1; for (int i = 1; i <= N; i++) P[i] += P[i - 1]; for (int i = 1; i <= N; i++) scan...
17
#include <bits/stdc++.h> using namespace std; const long long int mod = 1000000007; int chkpower2(int x) { return (x && !(x & x - 1)); } vector<long long int> primeFactors(long long int n) { vector<long long int> v; while (n % 2 == 0) { v.push_back(2); n = n / 2; } for (long long int i = 3; i <= sqrt(n)...
6
#include <bits/stdc++.h> using namespace std; void solve() { long long n, m; cin >> n >> m; long long ans = 0; long long broken = 0; while (n > 0) { ans++; n--; broken++; if (broken == m) { n++; broken = 0; } } cout << ans << '\n'; } signed main() { ios_base::sync_with_st...
2
#include <bits/stdc++.h> using namespace std; int gcd(int a, int b) { int c; while (a != 0) { c = a; a = b % a; b = c; } return b; } int main() { int i, j, k, l, n, u, m, v, a, b, w, p, q; char c; string s, s1, s2; while (cin >> n >> m) { int ara[n], ara1[n], ara2[n], ara3[n]; a = 1;...
2
#include <bits/stdc++.h> using namespace std; int n, Lim; int a[1010], sg[1010], cnt; int dp[1010][4]; int tol(int l, int r) { long long ret = Lim * 1ll * (r - l + 1) % 1000000007; ret -= (r + l) * 1ll * (r - l + 1) / 2 % 1000000007; ret += 1000000007; ret %= 1000000007; return ret; } int main() { scanf("%d...
18
#include <bits/stdc++.h> int main() { long long int count = 0, jmlh = 0, sn1 = 0, sn2 = 0, npos = 0, nminus = 0; scanf("%lld", &jmlh); if (jmlh % 2 == 0) { nminus = jmlh / 2; npos = jmlh / 2; } else { nminus = jmlh / 2 + 1; npos = jmlh / 2; } sn1 = ((nminus) * (-2 + ((nminus - 1) * -2))); ...
0
#include <bits/stdc++.h> using namespace std; const int MAXLOG = 22; const int MAXN = 1 << MAXLOG; bool has[MAXN]; bool used[2 * MAXN]; int n_log; int neg(int a) { return (~a) & ((1 << n_log) - 1); } void dfs(int v) { if (used[v]) { return; } used[v] = true; if (v < MAXN) { dfs(MAXN + v); return; ...
17
#include <bits/stdc++.h> using namespace std; using ll = long long; const int MX = 5e5 + 5; const int LG = 20; int n, m; int par[MX][LG], nxt[MX]; void SetSparse() { int i, j, k; int cur = 0; for (i = 0; i < MX; ++i) { cur = max({cur, i, nxt[i]}); par[i][0] = cur; } for (i = 1; i < LG; ++i) { for ...
14
#include <bits/stdc++.h> using namespace std; int n; int table[10][10]; int make(int r, int c) { int &ret = table[r - 1][c - 1]; if (ret != -1) return ret; if (r == 1 || c == 1) return ret = 1; return ret = make(r - 1, c) + make(r, c - 1); } int main() { cin >> n; memset(table, -1, sizeof(table)); cout <<...
0
#include <bits/stdc++.h> using namespace std; const int N = 20; const double PI = acos(-1); double w, h, alpha; double ans; int n, m; struct Point { double x, y; Point(double _x = 0, double _y = 0) : x(_x), y(_y) {} Point operator-(const Point &z) const { return Point(x - z.x, y - z.y); } double cross(const Poi...
12
#include <bits/stdc++.h> using namespace std; void input() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } int32_t main() { input(); long long int n; cin >> n; string s; cin >> s; long long int st = 0; while (st < n && s[st] == s[0]) st++; long long int en = n - 1; while (en >= 0 && s...
5
#include <bits/stdc++.h> using namespace std; int main() { string s, d; cin >> s; for (int i = 0; i < s.size(); i++) { if (s[i] == 'a' || s[i] == 'b') d += s[i]; } int n = d.size(); vector<long long int> v; int i = 0; while (i < n) { if (d[i] == 'a') { int k = 0; while (i < n && d[i]...
7
#include <bits/stdc++.h> using namespace std; template <typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; } template <typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; } const int oo = 0x3f3f3f3f; struct node; node *newnode(); struct node { node *c[2]; ...
22
#include <bits/stdc++.h> using namespace std; vector<pair<long long int, pair<long long int, long long int> > > G; vector<pair<long long int, long long int> > mst, nonMst; long long int n, m, maxCost[1000006]; bool solution = true; int main() { scanf("%I64d %I64d", &n, &m); for (int i = 1; i <= m; i++) { long l...
9
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); int m, n; cin >> m >> n; for (int i = 0; i < m; i++) { int x, y; cin >> x >> y; if (x == n || y == n || x == 7 - n || y == 7 - n) { cout << "NO" << endl; return 0; } } cout << "YES" << endl; ...
3
#include <bits/stdc++.h> using namespace std; const int maxn = 100; int n; int fa[maxn][maxn]; int main() { while (scanf("%d", &n) != EOF) { memset(fa, 0, sizeof(fa)); int hang = 1; int lie = n / 2 + 1; int num = 1; while (1) { if (fa[hang][lie] == 0) { fa[hang][lie] = num++; }...
7
#include <bits/stdc++.h> using namespace std; int main() { ios_base ::sync_with_stdio(false); cin.tie(NULL); int n, m, mi, ma; cin >> n >> m >> mi >> ma; map<int, bool> ml; for (int i = 0, j; i < m; i++) { cin >> j; if (j > ma || j < mi) { cout << "Incorrect"; return 0; } ml[j] =...
4
#include <bits/stdc++.h> int main() { int n; std::cin >> n; for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) std::cout << ((1ll * (i & 1)) << (i + j)) << " \n"[j == n - 1]; int q; std::cin >> q; while (q--) { int64_t k; std::cin >> k; std::cout << 1 << " " << 1 << "\n"; int ...
13
#include <bits/stdc++.h> using namespace std; const int maxm = 1.5e7; const int maxn = 1e5 + 5; int lson[maxm], rson[maxm]; long long sum[maxm]; int T[maxn]; int clk, n; void modity(int &rt, int L, int R, int pos, int val) { if (!rt) rt = ++clk; if (L == R) { sum[rt] += val; } else { int mid = L + R >> 1;...
18
#include <bits/stdc++.h> using namespace std; long long max(long long a, long long b) { return (a > b) ? a : b; } long long min(long long a, long long b) { return (a < b) ? a : b; } long long mm(vector<long long> a, vector<long long> b) { if (a[1] < b[1]) return true; if (a[1] == b[1] && a[0] < b[0]) return true; ...
10
#include <bits/stdc++.h> using namespace std; template <typename T> string tostr(const T& t) { ostringstream os; os << t; return os.str(); } const int MAXN = 60; int tonum(char ch) { if (isdigit(ch)) return ch - '0'; return ch - 'A' + 10; } int todecimal(string s, int base) { int res = 0; for (int i = 0; ...
8
#include <bits/stdc++.h> using namespace std; int main() { int a, b; cin >> a >> b; int sum = a; while (a >= b) { sum += a / b; a = a / b + a % b; } cout << sum; }
2
#include <bits/stdc++.h> using namespace std; int a, b, n; int solve(int count_a, int count_b, int extra) { int remaining; int ans = INT_MAX; if (count_a == 0 && count_b == 0) { return 0; } if (count_a > 0) { remaining = extra - a; if (remaining < 0) { ans = 1 + solve(count_a - 1, count_b, n...
8
#include <bits/stdc++.h> using namespace std; const int INF = 1e9 + 7; const int maxn = 300005; int n, mk, a[maxn], b[maxn], lst, used[maxn]; int isget[maxn][2], ansget[maxn][2]; bool vis[maxn][3]; inline int read() { int res = 0, f_f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f_f...
18
#include <bits/stdc++.h> int mayor(int a, int b); int men[5001], opt[5001], aux[5001], t[5001], l[5001], r[5001], d[5001]; int main() { int n, m, i, j, ban, max; scanf("%d%d", &n, &m); for (i = 1; i <= n; i++) { men[i] = -100000000; } for (i = 1; i <= m; i++) { scanf("%d%d%d%d", &t[i], &l[i], &r[i], &...
9
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5, inf = 1e9; int n, k, d, a[N], ansl, ansr = -1; bool flag; namespace SGT { long long tag[N << 2], mn[N << 2]; inline void up(int rt) { mn[rt] = min(mn[(rt << 1)], mn[(rt << 1 | 1)]); } inline void cov(int rt, long long tg) { mn[rt] += tg, tag[rt] += tg...
23
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; int a[n]; stack<int> s; int s_last = 1; s.push(n + 1); for (int i = 0; i < k; i++) { cin >> a[i]; if (s.top() < a[i]) { cout << "-1" << '\n'; return 0; } s.push(a[i]); while (s.top() == s_la...
12
#include <bits/stdc++.h> using namespace std; using ll = long long; const ll H = 1e18; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); template <class T> T rand(T a, T b) { return uniform_int_distribution<T>(a, b)(rng); } map<pair<int, ll>, ll> memo; ll ask(int i, ll x) { pair<int, ll> pr = {i,...
24
#include <bits/stdc++.h> using namespace std; bool prime(long long int s); long long int power(long long int x, long long int y); bool cmp(long long int a, long long int b) { return a > b; } bool ispower2(long long int n) { return n && (!(n & (n - 1))); } void solve() { long long int n, c = 0, c2 = 0; cin >> n; f...
3
#include <bits/stdc++.h> using namespace std; int n; int a[100006]; int main() { int u = 5; for (int i = 5; i <= 100000; i++) { u = u * 10; a[i] = u % 21; u = a[i]; } while (scanf("%d", &n) != EOF) { if (n <= 2) { printf("-1\n"); } else if (n == 3) { printf("210\n"); } else i...
6
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef pair<int , int> pii; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const int maxn = 4e5 + 10; const ll mod = 1e9+7; #define pb push_back #define endl '\n' #define dokme(x) cout << x , exit(0) ...
13
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<pair<int, int> > mans; for (int i = (0); i < ((n)); ++i) { int a; cin >> a; mans.push_back(make_pair(a, i + 1)); } sort(mans.begin(), mans.end()); reverse(mans.begin(), mans.end()); int const strongest = mans[...
7
#include <bits/stdc++.h> using namespace std; const int lim = 3005; int N; pair<int, int> pts[lim]; bool busca(pair<int, int> chosto) { int ini, fin, piv; ini = 0; fin = N - 1; while (ini < fin) { piv = (ini + fin) / 2; if (chosto <= pts[piv]) fin = piv; else ini = piv + 1; } return ...
5
#include <bits/stdc++.h> using namespace std; const int MAXN = 1600 + 10; int n, t, sS[MAXN], sL[MAXN], tS[MAXN], tL[MAXN], id[MAXN]; long double pF[MAXN], a[MAXN], b[MAXN], c[MAXN]; pair<long double, long double> f[MAXN][MAXN]; bool cmp(int first, int second) { return (long double)pF[second] * (-tL[second]) - ...
20
#include <bits/stdc++.h> using namespace std; template <typename T, typename U> inline void chkmax(T& x, U y) { if (x < y) x = y; } template <typename T, typename U> inline void chkmin(T& x, U y) { if (y < x) x = y; } const int MAXN = 222222; char s[MAXN]; int L[MAXN], C[MAXN], E[MAXN][26], P[MAXN], ID[MAXN], cnt[M...
15
#include <bits/stdc++.h> using namespace std; int min_not_used(pair<vector<bool>, int>& v) { for (int i = (v.second + 1); i < (v.first.size()); ++i) { if (!v.first[i]) return i; } return -1; } signed main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t, n, a; vector<int> q, p; pair...
4
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e3; long long n[MAXN][MAXN], N, M, K; int f[MAXN], p[MAXN], q[MAXN * MAXN]; long long cnt() { memset(n, 0, sizeof(n)); n[1][0] = 1; for (int i = 2; i <= N + M; ++i) for (int j = 0; j <= N + M; ++j) { if (f[i]) n[i][j] = n[i - 1][j -...
15
#include <bits/stdc++.h> using namespace std; vector<int> first; vector<int> second; int main() { int num, num_first, num_second; cin >> num; cin >> num_first; for (int i = 0; i < num_first; i++) { int temp; cin >> temp; first.insert(first.begin(), temp); } cin >> num_second; for (int i = 0; i...
6
#include<bits/stdc++.h> using namespace std; #define ll long long const int N = 2e5 + 10; ll numa[N],numb[N]; ll a[N],b[N]; int main() { int T; cin >> T; while(T--) { ll x1,x2,k; cin >> x1 >> x2 >> k; for(int i=1;i<=max(x1,x2);i++) { numa[i] = 0; ...
6
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { while (b) { a %= b; swap(a, b); } return a; } long long delvverx(long long a, long long b) { if (a % b == 0) { return (a / b); } else { return (a / b + 1); } } vector<long long> rs; int main() { long lo...
6
#include <bits/stdc++.h> using namespace std; const int inf = 2e9; const long long infl = 9e18; vector<vector<string>> ans; string s1, s2; void Func(int level) { if (!getline(cin, s1, ',')) return; getline(cin, s2, ','); if (level >= ans.size()) ans.resize(level + 1); ans[level].push_back(s1); int k = stoi(s2...
9
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define PI 3.14159265358979 #define EPS 1e-8 #define mod 998244353 #define fi first #define ...
7
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf("%d", &n); queue<int> q; int maxLoad = 0; int lastTime = 0; int curLoad = 0; int curT = 0; int prevT = 0; for (int i = 0; i < n; ++i) { int t, c; scanf("%d%d", &t, &c); curT = t; if (i != 0) { int dt = curT -...
3
#include <bits/stdc++.h> using namespace std; long long Pw(long long int b, long long int p) { if (!p) return 1; long long int sq = Pw(b, p / 2); sq *= sq; if (p % 2) sq *= b; return sq; } long long gcd(long long a, long long b) { return (b == 0 ? a : gcd(b, a % b)); } long long sd(long long x) { return x < 1...
22
#include <bits/stdc++.h> using namespace std; const int Nero = 0; const int N = 200000 + 100; int a[N], b[N], c[N], bb[N], cc[N]; int n; int bit[N][35]; int bitsum[35]; int main() { long long sum = 0; scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d", b + i); sum += b[i]; } for (int i = 1; i ...
17
#include <bits/stdc++.h> using namespace std; const int INF = 999999999; const int maxn = 1e5 + 5; const int minm = -0x7; const long long mod = 10000007; const double ABS = 1e-6; long long dp[505][6005], h[505]; int n, K; void init(void) { for (int i = 1; i <= n; i++) { for (int res = 0; res <= n * K; res++) { ...
12