solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> using namespace std; ostream& operator<<(ostream& a, const vector<long long>& b) { for (auto k : b) cout << k << " "; return a; } const long long INF = 1e18; const vector<string> nums = {"1110111", "0010010", "1011101", "1011011", "0111010", "1101011", "1101111"...
9
#include <bits/stdc++.h> using namespace std; long long Head[500010 << 1], Next[500010 << 1], Ver[500010 << 1], Edge[500010 << 1], From[500010 << 1]; long long n, m; long long fa[500010], val[500010]; long long tot = 0; long long f[500010][21], dep[500010]; void Add(long long x, long long y, long long z) { Ver[++...
16
#include <bits/stdc++.h> using namespace std; int n, m, x, l, r, i, s, a[10179]; int main() { for (cin >> n >> m, i = 1; i <= n; i++) cin >> a[i]; for (; m--;) { cin >> l >> r >> x; for (s = 0, i = l; i <= r; i++) a[i] < a[x] ? s++ : 0; cout << (s + l == x ? "Yes" : "No") << endl; } }
4
#include <bits/stdc++.h> using namespace std; int g[300010], rc = 0, n, q; struct node { int t, nxt; } e[300010]; void ade(int u, int v) { e[rc].t = v; e[rc].nxt = g[u]; g[u] = rc++; } int ans[300010], mx[300010], s[300010], fa[300010]; void dfs(int u) { s[u] = 1; for (int i = g[u]; ~i; i = e[i].nxt) { ...
11
#include <bits/stdc++.h> using namespace std; const int N = 2e5; vector<int> g[N]; int n; struct edge { int u, v, comp; bool bridge; }; vector<edge> e; void add_edge(int u, int v) { g[u].push_back(e.size()); g[v].push_back(e.size()); e.push_back((edge){u, v, -1, false}); } int D[N], B[N], T; int nbc, nap; int...
24
#include <bits/stdc++.h> using namespace std; int main() { long long int c = 0, n, l, k; cin >> n >> l; k = n; while (n < l) { n = n * k; c++; } if (n == l) { cout << "YES" << endl; cout << c; } else cout << "NO"; return 0; }
2
#include <bits/stdc++.h> using namespace std; const double EPS = 1e-10; const double PI = acos(-1.0); template <class T> T gcd(T a, T b) { for (T c; b; c = a, a = b, b = c % b) ; return a; } template <class T> void out(const vector<T> &a) { for (int i = 0; i < ((int)(a).size()); ++i) cout << a[i] << " "; co...
5
#include <bits/stdc++.h> using namespace std; int main(void) { long long N, K; cin >> N >> K; vector<long long> A(K); for (long long i = ((long long)0); i < ((long long)K); i++) cin >> A[i], A[i]--; stack<long long> stk; vector<bool> used(N, false); long long t = 0; stk.push(N); for (long long i =...
12
#include <bits/stdc++.h> using namespace std; const int M = 1e9 + 7; int ll_max = 1e6; vector<long long int> fact; void factorial(long long int n) { fact[0] = 1; for (long long int i = 1; i <= n; i++) { fact[i] = i * fact[i - 1]; fact[i] %= M; } } long long int binpow(long long int val, long long int deg)...
7
#include <bits/stdc++.h> using namespace std; const int maxn = 100001; pair<int, int> a[maxn]; int p[maxn]; int sz[maxn]; int cnt[maxn]; int cur, sum; set<int> s; int find_root(int a); void merge(int a, int b); int cal(); int main() { int n; scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d", &a[i].fi...
11
#include <bits/stdc++.h> using namespace std; static int a[1000005]; static long long p2[1000005]; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int n; cin >> n; for (int i = 1; i <= n; ++i) { cin >> a[i]; } p2[0] = 1; for (int i = 1; i < n; ++i) { p2[i] = (p2[...
12
#include <bits/stdc++.h> using namespace std; int main() { int n, t, i; cin >> n; vector<int> o; for (i = 0; i < n; i++) { cin >> t; o.push_back(t); } vector<int> s(o); sort(s.begin(), s.end()); int diff = 0; vector<int>::iterator io = o.begin(); vector<int>::iterator is = s.begin(); for (...
5
#include <bits/stdc++.h> using namespace std; int a, b, c; int x; int main() { cin >> a >> b >> c; x = min(abs(b - a) + abs(c - a), abs(b - a) + abs(b - c)); cout << min(x, abs(c - a) + abs(c - b)); }
0
#include <bits/stdc++.h> using namespace std; const int N = 100500; int arr[10]; int main() { ios::sync_with_stdio(false); int k; string n; long long sn = 0; cin >> k >> n; for (int i = 0; i < n.length(); i++) { sn += n[i] - '0'; if (sn >= k) { cout << 0 << endl; return 0; } arr[...
3
#include <bits/stdc++.h> using namespace std; template <class T> T abs(T x) { return x > 0 ? x : -x; } int n; int m; pair<int, int> v[50000]; bool l1(pair<int, int> a, pair<int, int> b) { return a.first * a.second * (100 - b.second) > b.first * b.second * (100 - a.second); } int main() { scanf("%d", &n);...
13
#include <bits/stdc++.h> using namespace std; template <typename T> void print1d(vector<T> &a) { for (long long int i = 0; i < a.size(); i++) { cout << a[i] << " "; } cout << endl; } vector<long long int> divisor(long long int n) { vector<long long int> a; for (long long int i = 1; i * i <= n; i++) { ...
0
#include <bits/stdc++.h> using namespace std; struct FastReader { FastReader &operator,(int &x) { scanf("%d", &x); return *this; } FastReader &operator,(signed long long &x) { scanf( "%" "ll" "d", &x); return *this; } FastReader &operator,(double &x) { scanf...
8
//#pragma comment(linker, "/stack:200000000") //#pragma GCC optimize("Ofast") //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") //#pragma GCC optimize("unroll-loops") #define _CRT_SECURE_NO_WARNINGS # include <iostream> # include <cmath> # include <algorithm> # include <stdio.h> # include...
19
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<vector<int> > graph(n + 1, vector<int>(0, 0)); for (int i = 2; i <= n; i++) { int t; cin >> t; graph[t].push_back(i); } vector<int> s(n + 1, 0); for (int i = 1; i <= n; i++) cin >> s[i]; vector<int> news(n + 1...
8
#include <bits/stdc++.h> using namespace std; const int MOD = (int)(1e9) + 7; const int SIZE = 2020; int d, n; int a[SIZE]; vector<int> path[SIZE]; long long f[SIZE]; bool vis[SIZE]; void dfs(int x, int root) { f[x] = 1; for (int i = 0; i < path[x].size(); i++) { int son = path[x][i]; if (vis[son] || !(a[so...
13
#include <bits/stdc++.h> using namespace std; vector<int> factorize(int n) { vector<int> res; for (int i = 2; i * i <= n; i++) { while (n % i == 0) { res.push_back(i); n = n / i; } } if (n != 1) res.push_back(n); return res; } void pack(vector<int> a, int n, vector<pair<int, int> >& v) { ...
10
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6; const int mod = 1e9 + 7; int flag[maxn + 10]; int pri[maxn + 10], pnum; int phi[maxn + 10]; int f[maxn + 10]; int fs1[maxn + 10], fs2[maxn + 10], fs3[maxn + 10]; void inc(int& a, int b) { if (a += b, a >= mod) a -= mod; } void dec(int& a, int b) { ...
21
#include <bits/stdc++.h> using namespace std; vector<pair<int, int> > a[2]; int n, x; int main(int argc, char *argv[]) { cin >> n >> x; for (int i = 0; i < n; i++) { int t, h, m; cin >> t >> h >> m; a[t].push_back(make_pair(h, m)); } int ans = 0; for (int start = 0; start <= 1; start++) { int ...
7
#include <bits/stdc++.h> using namespace std; const int N = 505; int n, m, k, dp[N][N]; char a[N][N]; inline int get(int x1, int y1, int x2, int y2) { x2--; y2--; if (x1 > x2 && y1 > y2) { return 0; } return dp[x2][y2] - dp[x2][y1] - dp[x1][y2] + dp[x1][y1]; } int main() { ios_base::sync_with_stdio(0); ...
12
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") inline void Routine() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } template <class T, class U> istream &operator>>(istream &in, pair<T, U> &p) { in >> p.first >> p.second; r...
4
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); string s; cin >> s; string w = s; if (w.size() & 1 && w.size() ^ 1) { w.erase(w.begin() + w.size() / 2); } if (set<char>{w.begin(), w.end()}.size() == 1) { cout << "Impos...
10
#include <bits/stdc++.h> using namespace std; int t; int main() { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); cin >> t; while (t--) { string a, s; cin >> a >> s; while (a.size() < s.size()) a = '0' + a; string b; bool ok = 1; int j = s.size() - 1; int i = 10; for (i = a.size(...
4
#include <bits/stdc++.h> using namespace std; int main() { int n, ax, ay, bx, by, cx, cy; cin >> n >> ax >> ay >> bx >> by >> cx >> cy; if (ax > bx && ax > cx) { if (ay > cy && ay > by) { cout << "YES" << endl; } else if (ay < cy && ay < by) { cout << "YES" << endl; } else { cout << ...
2
#include <bits/stdc++.h> using namespace std; struct Pt { long long x, y; Pt() {} Pt(long long x, long long y) : x(x), y(y) {} Pt operator+(const Pt& p) const { return Pt(x + p.x, y + p.y); } Pt operator-(const Pt& p) const { return Pt(x - p.x, y - p.y); } Pt operator*(long long c) const { return Pt(x * c, ...
13
#include <bits/stdc++.h> using namespace std; int qadr(int num) { return (num < 0 ? -num : num); } int main() { int n, rcnt = 0, lcnt = 0; cin >> n; string command; cin >> command; for (int i = 0; i < n; i++) { if (command[i] == 'R') { rcnt++; } } lcnt = n - rcnt; cout << qadr(-lcnt - rcnt...
0
#include <bits/stdc++.h> using namespace std; const int N = 310000; vector<int> V[N], adj[N]; int as[N], vis[N], par[N], T; long long sum[N]; void dfs(int u, int p) { vis[u] = ++T, par[u] = p; for (int v : adj[u]) { if (v == p) continue; if (!vis[v]) dfs(v, u); else if (vis[v] < vis[u]) { in...
15
#include <bits/stdc++.h> using namespace std; long long n, maxx, reg, a[1005], b[1005], ans, vis[1005]; vector<pair<long long, long long>> anss; int main() { cin >> n >> maxx >> reg; long long tep = maxx; for (register long long i = 1; i <= n; i++) cin >> a[i] >> b[i]; long long check = 0; for (register long ...
10
#include <bits/stdc++.h> using namespace std; long long f(long long x) { long long ll = 0, ge; if (x < 10) { return x; } ge = x % 10; ll = x / 10 + 9; while (x >= 10) { x /= 10; } if (x > ge) { ll--; } return ll; } int main() { long long a, b; long long suma, sumb; cin >> a >> b; ...
7
#include <bits/stdc++.h> using namespace std; int n; long long dp[1 << 17][126]; long long cnta[1 << 17], cntb[1 << 17]; long long t[20], a[20], b[20], suma, sumb; char op[2]; int main() { scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%s%d%d", op, &a[i], &b[i]); if (op[0] == 'R') t[i] = 0; if (o...
16
#include <bits/stdc++.h> using namespace std; int n, m, mp[15][15], ans, ret[15][15], sp[][15] = {{1, 1, 1, 0, 1, 0, 0, 1, 0}, {0, 0, 1, 1, 1, 1, 0, 0, 1}, {0, 1, 0, 0, 1, 0, 1, 1, 1}, {1, 0, 0, 1, 1, 1, 1, 0, 0}}; string s[] = {"AAA.BCCC.", ".ABBB.CD.", ".AE.BFCD.", ...
15
#include <bits/stdc++.h> using namespace std; int nxt[200010 << 1], to[200010 << 1], head[200010], cnt; long long fw[200010]; void add(int u, int v, long long w) { nxt[++cnt] = head[u]; to[cnt] = v; fw[cnt] = w; head[u] = cnt; } long long num[200010 << 2], tag[200010 << 2]; inline void set_tag(int u, long long ...
19
#include <bits/stdc++.h> using namespace std; const int maxn = 4e5 + 5; int n; int p[maxn]; int main() { ios::sync_with_stdio(false); int T; cin >> T; while (T--) { cin >> n; for (int i = 1; i <= n; ++i) cin >> p[i]; p[n + 1] = -1; p[0] = -1; int g = 0, s = 0, b = 0; for (int i = 1; i <=...
7
#include <bits/stdc++.h> using namespace std; long long primes[1000001]; vector<long long> martivebi; int main() { for (long long i = 2; i < 1000001; i++) { if (primes[i] == 1) { continue; } else { martivebi.push_back(i); for (long long j = i * i; j < 1000001; j += i) { primes[j] = 1...
11
#include <bits/stdc++.h> using namespace std; int main() { int a[4] = {}, a1[4] = {}, a2[4] = {}, a3[4] = {}, dif = 0, j = 1; bool none = false; cin >> a[0] >> a[1] >> a1[0] >> a1[1]; for (int i = 0; i < 2; i++) { if (a[i] == a1[i] && a[j] != a1[j]) { if (a[j] < 0 || a1[j] < 0) { dif = abs(a[j...
4
#include <bits/stdc++.h> using namespace std; int judge(string s); int main() { int n, m; cin >> n >> m; string *s = new string[n]; for (int i = 0; i < n; i++) cin >> s[i]; int res = 10000; int *l_store = new int[50]; int *n_store = new int[50]; int *s_store = new int[50]; for (int i = 0; i < 50; i++)...
7
#include <bits/stdc++.h> #pragma GCC optimize("O2") using namespace std; long long const inf = 1e18, linf = 2e9, mod = 1e9 + 7, inf2 = 1e12; int const mxn = 5e6 + 10; long long poww(long long a, long long b, long long md) { return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md ...
15
#include <bits/stdc++.h> using namespace std; const int MOD = 1000000007; long double PI = 4 * atan(1); long long n, m, a[5001], b[5001], c[5001], d[5001], res[5001], init[5001], cum[5001], cur, flag; bool visited[5001]; bool check() { for (int i = 1; i < n + 1; i++) if (abs(res[i]) > 1e9) return false; for...
9
#include <bits/stdc++.h> using namespace std; long long a, b, ans; int main() { cin >> a >> b; if (a == b) { cout << "infinity" << endl; return 0; } if (a < b) { cout << 0 << endl; return 0; } for (int i = 1; i * i <= a - b; i++) { if ((a - b) % i == 0) { if (i > b) ans++; if...
8
#include <bits/stdc++.h> using namespace std; mt19937 ran(time(0)); long long mod = 1e9 + 7; long long gcd(long long a, long long b) { if (!b) return a; return gcd(b, a % b); } long long Bpow(long long a, long long b) { long long ans = 1; while (b) { if (b & 1) { ans *= a; ans %= mod; } ...
10
#include <bits/stdc++.h> using namespace std; int main() { float cup = 0, med = 0, tmp, n = 3; while (n--) { cin >> tmp; cup += tmp; } n = 3; while (n--) { cin >> tmp; med += tmp; } cin >> n; cout << (ceil(cup / 5) + ceil(med / 10) <= n ? "YES" : "NO"); }
0
#include <bits/stdc++.h> using namespace std; long long a[500010]; long long n, k; int main() { while (cin >> n >> k) { long long sum = 0; for (int i = 0; i < n; i++) { cin >> a[i]; sum += a[i]; } sort(a, a + n); long long la = sum / n; long long ra = (sum + n - 1) / n; long lo...
12
#include <bits/stdc++.h> using namespace std; int gi() { int res = 0, w = 1; char ch = getchar(); while (ch != '-' && !isdigit(ch)) ch = getchar(); if (ch == '-') w = -1, ch = getchar(); while (isdigit(ch)) res = res * 10 + ch - '0', ch = getchar(); return res * w; } const long double PI = acos(-1.0); const...
23
#include <bits/stdc++.h> using namespace std; int mini[18][18], mini2[18][18]; int n, m, a; vector<int> v[17]; int dp[20][1 << 16]; int call(int now, int mask, int pre) { int& ret = dp[now][mask]; if (ret != -1) return ret; if (mask + 1 == (1 << n)) { return mini2[now][pre]; } int ans = 0; for (int i = ...
12
#include <bits/stdc++.h> using namespace std; int N; vector<int> L, C; map<int, int> DP; int gcd(int first, int second) { return first ? gcd(second % first, first) : second; } void relax(int k, int v) { if (DP.find(k) == DP.end()) DP[k] = v; else DP[k] = min(DP[k], v); } int main() { cin >> N; L.resiz...
11
#include <bits/stdc++.h> using namespace std; int m[111][111]; int f(int n, int k) { int num = 0; for (int i = 0; i < k; i++) { if (m[i][n] == 1) num++; } if (num > k - num) return k - num; else return num; } int main() { int n, i, j, k; scanf("%d%d", &n, &k); for (i = 0; i < n / k; i++) { ...
2
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; vector<long long> v(n); long long sum = 0; for (long long i = 0; i < n; i++) { cin >> v[i]; sum += v[i]; } sum = sum / 2 + 1; vector<long long> ans; ans.push_back(0); long long p = v[0]; for (long long i = 1;...
0
#include <bits/stdc++.h> using namespace std; template <class T> void show(T a, int n) { for (int i = 0; i < n; ++i) cout << a[i] << ' '; cout << endl; } template <class T> void show(T a, int r, int l) { for (int i = 0; i < r; ++i) show(a[i], l); cout << endl; } const int N = 5100; const int M = 5000; const int...
14
#include <bits/stdc++.h> using namespace std; int a, s, d[20000002], f[10002], gr[22][22], fx[10002], g[102], h, j, k, l, i, n, m; queue<pair<int, int> > q; int main() { cin >> n >> m >> k; for (i = 0; i < m; i++) { cin >> a; f[a] = 1; } l = 1; for (i = 0; i <= n; i++) { if (f[i] == f[i + 1]) ...
20
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; const double PI = 3.141592653589793238463; using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long l, r, x, y, k; cin >> l >> r >> x >> y >> k; for (int i = x; i <= y; i++) { ...
4
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int t; cin >> t; while (t--) { long long x, y, p, q; cin >> x >> y >> p >> q; if ((p == q && x == y) || (p == 0 && x == 0)) { cout << 0 << endl; continue; } if ((p == q && x != y...
9
#include <bits/stdc++.h> using namespace std; int n, m, q, x, y; int main() { cin >> n >> m >> q; while (q--) { cin >> x >> y; if (min(min(x - 1, n - x), min(y - 1, m - y)) <= 4) return cout << "YES\n", 0; } cout << "NO"; }
11
#include <bits/stdc++.h> using namespace std; long long N, H, A[1100]; bool bisa(long long n) { long long tmpH = H; for (long long i = n - 1; i > 0; i -= 2) { tmpH -= max(A[i], A[i - 1]); if (tmpH < 0) { return false; } } if (n % 2 == 0) return true; return tmpH >= A[0]; } int main() { ios...
5
#include <bits/stdc++.h> using namespace std; inline int read() { register int x = 0, f = 1; register char ch = getchar(); while (!isdigit(ch)) { if (ch == '-') f = 0; ch = getchar(); } while (isdigit(ch)) { x = x * 10 + (ch ^ '0'); ch = getchar(); } return f ? x : -x; } const int N = 1e5 ...
18
#include <bits/stdc++.h> using namespace std; int cap[1000000], flow[1000000]; int to[1000000], _prev[1000000], last[10000], used[10000], level[10000]; struct MaxFlow { int V, E; MaxFlow(int n) { int i; V = n; E = 0; for ((i) = 0; (i) < (int)(V); (i)++) last[i] = -1; } void add_edge(int x, int y...
20
#include <bits/stdc++.h> using namespace std; const long double eps = 1e-14; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ; vector<pair<long double, int> > before, after; long double x1, x2, k, b; int n; cin >> n >> x1 >> x2; x1 += eps; x2 -= eps; for (int i = 0; i...
8
#include <bits/stdc++.h> using namespace std; inline void rd(int &X) { X = 0; int w = 0; char ch = 0; while (!isdigit(ch)) w |= ch == '-', ch = getchar(); while (isdigit(ch)) X = (X << 3) + (X << 1) + (ch ^ 48), ch = getchar(); X = w ? -X : X; } int n, m, top; int x, y, pd, k; struct pr { int l, r, s; } s...
20
#include <bits/stdc++.h> using namespace std; int main() { int n, x; cin >> n; int zero = 0, all = 0; string str; vector<int> vec[3]; for (int i = 0; i < n; i++) { cin >> x; if (x != 0) { all = 1; } if (x == 0) { zero = 1; } str += (x + '0'); vec[x % 3].push_back(x); ...
8
#include <bits/stdc++.h> using namespace std; struct P { int x, y; bool operator<(const P &p) { if (x != p.x) return x < p.x; else return y < p.y; } }; void subsetGenerate(int n) { for (int b = 0; b < (1 << n); b++) { vector<int> subset; for (int i = 0; i < n; i++) { if (b & (1...
6
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); int n, x; cin >> n >> x; vector<vector<long long> > a(n); vector<vector<long long> > b(n); map<pair<long long, long long>, long long> cnt; for (int i = 0; i < n; i++) { long long x, y, z; cin >> x >> y >> z; ...
8
#include <bits/stdc++.h> using namespace std; const int N = 251; const int M1 = 1e9 + 9; const int M2 = 1e9 + 7; int R, C; char g[N][N]; pair<int, int> dp[N][N][N]; pair<int, int> H; pair<int, int> p[26]; int P[N * 4]; vector<pair<int, int> > Q; int calc() { for (int i = 0; i < Q.size(); ++i) P[i] = 0; int c = 0, r...
16
#include <bits/stdc++.h> using namespace std; int main() { long long n, t; cin >> n >> t; long long ex[n]; for (int i = 1; i < n; i++) cin >> ex[i]; int in = 1; while (in < n) { if (in == t) { cout << "YES" << endl; return 0; } in = ex[in] + in; } if (in == t) { cout << "YES"...
2
#include <bits/stdc++.h> using namespace std; const int maxn = 100 + 10; int n, m; int g[maxn][maxn]; int path[maxn]; int res; int k; int nextpath[maxn][maxn][15 * 110 + 1]; int dp[maxn][maxn][15 * 110 + 1]; int main() { memset(dp, -1, sizeof(dp)); scanf("%d %d %d", &n, &m, &k); for (int i = 0; i < n; ++i) { ...
11
#include <bits/stdc++.h> const long long X = 2e5; int main() { long long n, l, r, k; scanf("%lld %lld %lld %lld", &n, &l, &r, &k); r = (r - l + n) % n + 1; long long ans = -1; if (n <= X) { for (long long i = n; i >= 0; i--) { long long y = (k - 1) % (n + i) + 1 - r; if (y < 0 || y > r || y > ...
18
#include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int, int>; template <class T> using V = vector<T>; template <class T> using VV = V<V<T>>; constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); } template <class T, class U> void chmin(T& t, const U& u) { if (t > u) t = u;...
16
#include <bits/stdc++.h> using namespace std; const int maxn = 105; long long int n, d; long long int x[maxn]; int main() { ios::sync_with_stdio(false); cin >> n >> d; for (int i = 0; i < n; i++) cin >> x[i]; sort(x + 0, x + n); long long int ans = 2; for (int i = 0; i < n - 1; i++) { if (x[i] + 2 * d <...
1
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const double eps = 1e-10; const int MOD = 100000007; const int MAXN = 110000; const double PI = acos(-1.0); pair<char, int> ipt[MAXN]; int cnt[MAXN]; set<int> may, no; int main() { int n, m; while (~scanf("%d%d", &n, &m)) { may.clear(); ...
10
#include <bits/stdc++.h> using namespace std; int main() { int i, j, k, l, t, r, s, m, n, a, b, c, d, e, f, g, h, u, v; scanf("%d %d", &c, &d); scanf("%d %d", &n, &m); scanf("%d", &k); a = n * m; a = a - k; if (a > 0) { e = a / n; h = 100000000; g = 0; if (a % n > 0) ++e; for (i = 0; i...
7
#include <bits/stdc++.h> using namespace std; inline int read() { char ch = getchar(); int w = 1, c = 0; for (; !isdigit(ch); ch = getchar()) if (ch == '-') w = -1; for (; isdigit(ch); ch = getchar()) c = (c << 1) + (c << 3) + (ch ^ 48); return w * c; } const int M = 1505, mod = 998244353; vector<pair<int...
19
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 9; const int z = 26; const long long mod = 1e9 + 7; const long long inf = 1e9; vector<pair<int, int> > change[30], vec[55][55]; string s1, s2; int n; bool dp1[30][55][55], dp2[30][55][55], vis[55][55][55][55]; bool ans[55][55][55]; int f(char c) { ret...
15
#include <bits/stdc++.h> using namespace std; int ans[1000000]; int arr1[1000000]; int arr2[1000000]; int main() { int n, m, x, y; bool Im = 0, Am = 0; cin >> n >> m; for (int i = 0; i < n; i++) { cin >> x; arr1[x] = i; arr2[x]++; } for (int i = 0; i < m; i++) { cin >> y; if (arr2[y] == ...
7
#include <bits/stdc++.h> using namespace std; const long long inf = (long long)1e17; const int dx[4] = {0, 1, 0, -1}; const int dy[4] = {1, 0, -1, 0}; const char dir[4] = {'U', 'R', 'D', 'L'}; inline int mabs(int x) { return (x > 0 ? x : -x); } const int N = 400010; int arr[N]; long long when[N], dist[N], qt[N]; int pv...
18
#include <bits/stdc++.h> long long gi() { long long x = 0, f = 1; char ch = getchar(); while (!isdigit(ch)) f ^= ch == '-', ch = getchar(); while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar(); return f ? x : -x; } int pow(int x, int y) { int ret = 1; while (y) { if (y & 1) ret = 1ll * ret * x % ...
18
#include <bits/stdc++.h> using namespace std; inline void error(int n) { cout << fixed << setprecision(n + 1); } inline long long gcd(long long a, long long b) { return (a ? gcd(b % a, a) : b); } inline bool is_prime(long long n) { for (long long i = 2; i * i <= n; i++) if (!(n % i)) return false; return (n >...
2
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; while (n--) { string s1; cin >> s1; vector<char> s; for (int i = 0; i < s1.size(); i++) { s.push_back(s1[i]); } sort(s.begin(), s.end()); if (s.size() != s1.size()) { cout << "No" << endl; } els...
0
#include <bits/stdc++.h> using namespace std; int main() { int n, i, a, b, a0 = 0, b0 = 0, a1 = 0, b1 = 0; scanf("%d", &n); for (i = 0; i < n; ++i) { scanf("%d%d", &a, &b); if (a == 0) a0++; else if (a == 1) a1++; if (b == 0) b0++; else if (b == 1) b1++; } printf("%...
0
#include <bits/stdc++.h> using namespace std; const int MOD = 1000000007; const int INF = 1000000001; const long long LINF = 1000000000000000001LL; vector<int> divSieve(int N) { vector<int> S(N + 1, 0), prime; for (int i = (2); i <= (N); ++i) { if (!S[i]) { S[i] = i; prime.push_back(i); } fo...
22
#include <bits/stdc++.h> using namespace std; int main() { long long a, b, c, d; cin >> a >> b >> c >> d; long long ans = 0; for (long long i = a; i <= b; i++) { if (b == c && c == d) { ans += 1; continue; } long long min = (c - i + 1); long long max = ((d - i + 1) >= c) ? c : (d - i...
10
#include <bits/stdc++.h> using namespace std; const int MAXN = 50; int N; long long dp[MAXN + 5][MAXN + 5]; pair<long long, long long> task[MAXN + 5]; vector<long long> v[MAXN + 5]; const long long BASE = 1000; bool check(long long avg) { v[0].clear(); int i = 0, p = 0; while (i < N) { bool first = true; ...
17
#include <bits/stdc++.h> using namespace std; int Gcd(int a, int b) { if (b == 0) return a; return Gcd(b, a % b); } int Lcm(int a, int b) { return a / Gcd(a, b) * b; } inline long long read() { long long f = 1, x = 0; char ch = getchar(); while (ch > '9' || ch < '0') { if (ch == '-') f = -f; ch = getc...
13
#include <bits/stdc++.h> using namespace std; int mod = 1e9 + 7; int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } void cp() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } void solve() { long long n; cin >> n; vector<long long> a(n), b(n), dp1(n + 1, 0), dp2(n +...
6
#include <bits/stdc++.h> using namespace std; long long n, m; long long zbir; vector<long long> od; int main() { scanf("%I64d %I64d", &n, &m); for (long long i = 1; i <= n; i++) { long long a, b; scanf("%I64d %I64d", &a, &b); zbir += a; od.push_back(a - b); } sort(od.begin(), od.end(), greater<i...
3
#include <bits/stdc++.h> using namespace std; const int N = 25; int l[N], m[N], w[N]; struct elem { int l, m, w; int s; elem() = default; elem(int a, int b, int c) { s = min(min(a, b), c); l = a - s; m = b - s; w = c - s; } bool operator<(const elem& other) const { return tie(l, m, w) < ...
15
#include <bits/stdc++.h> using namespace std; int const MAXN = 2e6 + 9; vector<vector<int>> g; int a[MAXN]; int main() { ios_base::sync_with_stdio(0), cin.tie(0); int n, k; cin >> n >> k; g.resize(n + 1); for (int i = 0; i < n; i++) { cin >> a[i]; g[a[i]].push_back(i); } set<pair<int, int>> pq; ...
10
#include <bits/stdc++.h> using namespace std; const int dy[] = {-1, 0, 1, 0}, dx[] = {0, 1, 0, -1}; const double EPS = 1e-8; const double PI = acos(-1.0); int popcount(int n) { return __builtin_popcount(n); } int popcount(long long n) { return __builtin_popcountll(n); } template <class T> int SIZE(T a) { return a.siz...
14
#include <bits/stdc++.h> #pragma GCC optimize(3) #pragma GCC optimize(2) using namespace std; const int maxn = 2e5 + 10; const int inf32 = 1e9; const long long inf64 = 1e18; vector<int> g[maxn]; int ans[maxn], a[maxn], b[maxn]; void DFS(int v, int c) { ans[v] = c; for (int nv : g[v]) { if (ans[nv] == -1) { ...
18
#include <bits/stdc++.h> inline int Input() { int ret = 0; bool isN = 0; char c = getchar(); while (c < '0' || c > '9') { if (c == '-') isN = 1; c = getchar(); } while (c >= '0' && c <= '9') { ret = ret * 10 + c - '0'; c = getchar(); } return isN ? -ret : ret; } inline void Output(long l...
16
#include <bits/stdc++.h> using namespace std; int dp[101]; int main() { int n, m1; cin >> n >> m1; map<int, int> m; for (int i = 0; i < m1; i++) { int a, b; cin >> a >> b; if (a != b) { for (int j = a; j <= b; j++) { m[j]++; } } else { m[a]++; } } for (int i = 1...
5
#include <bits/stdc++.h> using namespace std; long long read() { long long x = 0, f = 1; char ch = getchar(); for (; ch < '0' || ch > '9'; ch = getchar()) if (ch == '-') f = -1; for (; ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + int(ch - '0'); return x * f; } const int MAXN = 23; const int MAXP =...
19
#include <bits/stdc++.h> using namespace std; struct edge { int node, weight; }; struct operation { int u, v, x; }; int N; vector<int> parent; vector<int> depth; vector<int> leaf; vector<int> edge_need; vector<vector<edge>> adj; vector<operation> ops; void erase_edge(int from, int to) { for (edge &e : adj[from]) ...
17
#include <bits/stdc++.h> using namespace std; string r = "abacaba"; string calc(string s, int l) { bool res = true; for (int i = 0; i < 7; i++) { if (s[i + l] != r[i] && s[i + l] != '?') return "1"; if (s[i + l] == '?') s[i + l] = r[i]; } for (int i = 0; i < s.length(); i++) { if (s[i] == '?') s[i] ...
7
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int _ = 1; while (_--) { int n; cin >> n; vector<int> cnt(51); int mn = 50; for (int i = 0; i < n; i++) { int x; cin >> x; mn = min(mn, x); cnt[x]++...
12
#include<bits/stdc++.h> #define sol(x) cout << x << "\n" #define pt pair<int, int> #define ll long long #define endl '\n' using namespace std; void solve(){ int n; cin >> n; string s; cin >> s; string a = "trygub"; int j = 0; string b = "", c = ""; for(int i = 0; i < n; i++){ if((int)a.find(s[i]) == -1){ ...
0
#include <bits/stdc++.h> using namespace std; int main() { vector<int> a(1001, -1); int n, m, k; cin >> n >> m >> k; int row; int val; for (int i = 0; i < n; i++) { cin >> row >> val; if (a[row] == -1) a[row] = val; else a[row] = min(a[row], val); } int ans = 0; for (int i = 1;...
4
#include <bits/stdc++.h> using namespace std; long long add(long long a, long long b) { return min((long long)1e18, a + b); } long long pro(long long a, long long b) { if (1e18 / b < a) return 1e18; return min((long long)1e18, a * b); } vector<long long> operator*(const vector<vector<long long> >& a, ...
16
#include <bits/stdc++.h> using namespace std; string itosm(long long x) { if (x == 0) return "0"; string ans = ""; while (x > 0) { ans += ((x % 10) + '0'); x /= 10; } reverse(ans.begin(), ans.end()); return ans; } long long stoim(string str) { long long ans = 0; long long k = 1; int p = 0; i...
12