solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> using namespace std; const int maxn = 200005; char s[maxn]; char f[30]; int main() { int l, n; char p[5], q[5]; while (scanf("%d%d", &l, &n) != EOF) { getchar(); scanf("%s", s); for (int i = 0; i < 26; i++) f[i] = i + 97; for (int i = 0; i < n; i++) { scanf("%s%s", p...
4
#include <bits/stdc++.h> #define ll long long #define pb push_back #define mp make_pair using namespace std; void solve(){ int n; cin >> n; ll a[2*n]; for( int i =0; i < (2*n); i++){ cin >> a[i]; } sort( a, a+(2*n) ); for( int i = 0; i < n; i++ ){ cout << a[i] << " " << a[n+i] << " "; } cout << endl; re...
0
#include <bits/stdc++.h> using namespace std; const int maxn = 60; const long long inf = 1e18; int T, n, ans[maxn], fa[maxn], fr[maxn]; long long k; long long dp[maxn], p[maxn]; bool ok, f[maxn]; long long calc(int x) { if (x <= 1) return 1; return p[x - 2]; } long long mul(long long x, long long y) { if (x == 0)...
19
#include <bits/stdc++.h> using namespace std; vector<string> path; void printPath() { cout << "/"; for (int i = 0; i < path.size(); i++) { cout << path[i] << "/"; } cout << "\n"; } void update(string query) { int pos = 0; if (query[0] == '/') { path.clear(); pos = 1; } while (1) { int ne...
6
#include <bits/stdc++.h> const long long LINF = 1e15; using namespace std; vector<pair<double, double> > v; int main() { int n; cin >> n; for (int i = 0; i < n; i++) { int a, b; cin >> a >> b; v.push_back(make_pair(a, b)); } double ans = LINF + .0; for (int i = 0; i < n; i++) { double x0 = v...
10
#include <bits/stdc++.h> using namespace std; int dp[20][400000]; int L[1 << 20]; int main() { for (int i = 1; i < (1 << 20); ++i) L[i] = L[i >> 1] + 1; int n; scanf("%d", &n); vector<int> v(n); for (auto &x : v) scanf("%d", &x); n *= 4; v.resize(n); for (int i = 0; i < n; ++i) v[i] = v[i % (n / 4)]; ...
12
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t; string s; cin >> t; set<char> st; while (t--) { cin >> s; string p = ""; string q = ""; for (int i = s.size() - 1; i >= 0; i--) { char ch = s.at(i); q += c...
1
#include <bits/stdc++.h> template <class T> inline T read() { T r = 0, f = 0; char c; while (!isdigit(c = getchar())) f |= (c == '-'); while (isdigit(c)) r = (r << 1) + (r << 3) + (c ^ 48), c = getchar(); return f ? -r : r; } template <class T> inline T min(T a, T b) { return a < b ? a : b; } template <clas...
16
#include <bits/stdc++.h> using namespace std; long long N, A, B, tab[500100]; vector<long long> adj[500100]; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> N; for (long long i = 0; i < N - 1; i++) { cin >> A >> B; adj[A].push_back(B); adj[B].push_back(A); } for (long lon...
9
#include <bits/stdc++.h> int n, t, i, j, m; char a[1000000], b[1000000], s[1000000], x; long long w; int war(const void* aa, const void* bb) { return ((int)(*(int*)(aa) - *(int*)(bb))); } int main() { scanf("%d%s%s", &n, a, b); for (i = n - 1; i >= 0; i--) { s[i + 1] += a[i] + b[i] - 'a' - 'a'; if (s[i + ...
11
#include <bits/stdc++.h> using namespace std; int v, minn = 1000000000ll; int a[10]; char res[1001309]; int main() { cin >> v; for (int i = 1; i <= 9; i++) cin >> a[i], minn = min(minn, a[i]); if (v < minn) { cout << -1; return 0; } int x = v / minn; while (x--) for (int i = 9; i >= 1; i--) ...
9
#include <bits/stdc++.h> using namespace std; long long n, k, t; const long long maxn = 2e6 + 55; long long a[maxn]; long long b[maxn]; long long check(long long val) { long long ret = 0, ct = 0, time = 0, all = 0; for (long long i = 1; i <= n; i++) { if (a[i] > val) continue; if (ret + time > t) return all...
13
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int sum = 0, last = 1; for (int i = 1; sum + i <= n; i++) { sum += i; last = i; } cout << last << endl; sum = 0; for (int i = 1; i <= last; i++) { if (i == last) { cout << n - sum << endl; } else { co...
2
#include <bits/stdc++.h> using namespace std; struct Edge { int u, v, used; Edge() {} Edge(int u, int v, int used) : u(u), v(v), used(used) {} int get_v(int p) { return (u == p) ? v : u; } }; vector<vector<int> > adj; vector<Edge> ve; vector<int> cId, od, id; int n; void add_edge(int u, int v) { Edge e = Edge...
18
#include <bits/stdc++.h> using namespace std; int par[3001][3001]; long long sub[3001][3001]; long long dp[3001][3001]; int n; vector<int> vertices[3001]; void dfs(int x, int f, int root) { par[root][x] = f; sub[root][x] = 1; for (auto i : vertices[x]) { if (i == f) continue; dfs(i, x, root); sub[root...
15
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e5 + 100; const int MAMX = 900; const int MOD = 1e9 + 7; const long long INF = 1e18; int r, g, h, dp[MAXN][2], ans; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); ; cin >> r >> g; h = 1; while ((h + 1) * (h + 2) / 2 <= r +...
12
#include <bits/stdc++.h> using namespace std; const int MAX = 1 << 19, TOUR = 1 << 19; const long long INF = 1e18; int n, q; pair<int, int> e[MAX]; int w[MAX]; int disc[MAX], fin[MAX], vr = 0; long long odroota[MAX]; int tko[MAX]; vector<pair<int, int> > V[MAX]; int moj_ind[MAX]; struct node { long long mn, prop; } t...
13
#include <bits/stdc++.h> inline long long read() { long long x = 0; char c = getchar(), f = 1; for (; c < '0' || '9' < c; c = getchar()) if (c == '-') f = -1; for (; '0' <= c && c <= '9'; c = getchar()) x = x * 10 + c - '0'; return x * f; } long long C[20][20], f[20][20]; int cnt[16]; int n, m; long long ...
17
#include <bits/stdc++.h> #pragma GCC optimize(2) using namespace std; template <typename T> void read(T &x) { x = 0; char op = getchar(); int F = 1; while (!isdigit(op)) { if (op == '-') F *= -1; op = getchar(); } while (isdigit(op)) { x = (x << 1) + (x << 3) + op - '0'; op = getchar(); } ...
8
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int i, j, k; int n, a, b, p = 0, ne = 0; cin >> n; for (i = 0; i < n; i++) { cin >> a >> b; if (a > 0) p++; else ne++; } if (p > 1 && ne > 1) cout << "No"; else c...
0
#include <bits/stdc++.h> using namespace std; long double a, d; int n; long double ost(long double a, long double d) { int l = 0, r = 100000; while (l < r) { int k = (l + r + 1) / 2; if (d * k <= a) l = k; else r = k - 1; } return a - l * d; } int main() { scanf("%lf %lf %i", &a, &d, &...
7
#include <bits/stdc++.h> #pragma warning(disable : 4996) #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("-ffloat-store") using namespace std; clock_t time_p = clock(); void aryanc403() { time_...
14
#include <bits/stdc++.h> using namespace std; template <typename T> void get_int(T &x) { char t = getchar(); bool neg = false; x = 0; for (; (t > '9' || t < '0') && t != '-'; t = getchar()) ; if (t == '-') neg = true, t = getchar(); for (; t <= '9' && t >= '0'; t = getchar()) x = x * 10 + t - '0'; if ...
16
#include <bits/stdc++.h> using namespace std; int main() { int t; cin>>t; for (int i = 0; i < t; i++) { int n; cin>>n; cout<<ceil(sqrt(n))<<endl; } }
0
#include <bits/stdc++.h> using namespace std; struct Segment { int coverTime, coverSize; Segment() { coverTime = coverSize = 0; } Segment(int coverTime, int coverSize) : coverTime(coverTime), coverSize(coverSize) {} Segment operator+(const Segment &rhs) const { return Segment(0, coverSize + rhs.coverS...
17
#include <bits/stdc++.h> using namespace std; const int MAX = 1e6 + 5; int x1, yy1, x2, y2, x3, y3, x4, y4, x5, y5, x6, y6; bool find0(int x, int y) { if (x >= x3 && x <= x4 && y >= y3 && y <= y4) return true; if (x >= x5 && x <= x6 && y >= y5 && y <= y6) return true; return false; } bool find1() { if (x1 >= x3...
9
#include <bits/stdc++.h> using namespace std; int n; set<long long int> heap; char usados[12]; void bckt(long long int num, long long int p, int x, int y) { if (num) { long long int aux = num; memset(usados, 0, sizeof(usados)); if (aux % 10 == 0) usados[0] = 1; while (aux) { int r = aux % 10; ...
8
#include <bits/stdc++.h> using namespace std; template <class T> inline bool scan(T &ret) { char c; int sgn; if (c = getchar(), c == EOF) return 0; while (c != '-' && (c < '0' || c > '9')) c = getchar(); sgn = (c == '-') ? -1 : 1; ret = (c == '-') ? 0 : (c - '0'); while (c = getchar(), c >= '0' && c <= '9...
17
#include <bits/stdc++.h> using namespace std; int n, minJuice, minChoc, a, b, c, d, success = 0; int main() { cin >> n; for (int i = 1; i <= 4 && !success; i++) { cin >> a >> b >> c >> d; minJuice = min(a, b); minChoc = min(c, d); if (minJuice + minChoc <= n) { success = 1; cout << i << ...
3
#include <bits/stdc++.h> using namespace std; char str[200001]; vector<int> in[26]; long long shsh[26][200001]; long long hsh[200001], pw[200001], inv[200001]; long long power(long long a, long long e) { if (e == 0) return 1; long long ans = power(a, e >> 1); ans *= ans; ans %= 1000000007LL; if (e & 1) { ...
15
#include <bits/stdc++.h> using namespace std; long long a[100002]; long long mp[100002]; int main() { long long n, k; cin >> n >> k; for (long long i = 1; i <= n; i++) { cin >> a[i]; mp[a[i]]++; } long long cnt = 0; long long ans = 0; for (long long i = 1; i <= k; i++) { if (mp[i]) { ans...
2
#include <bits/stdc++.h> const int maxn = 1e5; int n, k; int a[maxn], b[maxn]; int main() { scanf("%d %d", &n, &k); for (int i = 0; i < n; ++i) scanf("%d", &a[i]); for (int i = 0; i < n; ++i) scanf("%d", &b[i]); long long L = 0; long long R = 2e9; while (L < R) { long long M = (L + R + 1) >> 1; long...
7
#include <bits/stdc++.h> using namespace std; inline int read() { int x = 0, y = 0; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') y = 1; ch = getchar(); } while (ch >= '0' && ch <= '9') x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar(); return y ? -x : x; } int son[2000005...
19
#include <bits/stdc++.h> using namespace std; int n, w; int a[300500], b[300500]; long long sum1[2 * 300500]; long long sum2[2 * 300500]; int add2[2 * 300500]; int cnt[300500]; vector<int> t2; vector<pair<int, int> > t1; class C1 { public: bool operator()(int x, int y) { return ((b[x] - a[x]) > (b[y] - a[y]) || ...
18
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 5; const long long MOD = 1e9 + 7; int N, M, K, Q; void solve(int testNum) { int i, j; scanf("%d", &N); vector<int> vec; for (i = 1;;) { vec.push_back(N / i); if (N / i == 0) break; i = N / (N / i) + 1; } printf("%d\n", vec.size...
6
#include <bits/stdc++.h> using namespace std; int n, m; long long a, b, f[200010], g[200010]; struct orz { long long w, h, c; } x[200010]; inline bool cmp(orz a, orz b) { return a.w < b.w || a.w == b.w && a.h < b.h; } inline long long gcd(long long n, long long m) { return m ? gcd(m, n % m) : n; } inline long long lc...
18
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s; cin >> s; queue<int> d, r; for (int i = 0; i < n; i++) { if (s[i] == 'D') d.push(i); else r.push(i); } int i = n; if (r.empty()) { cout << "D"; return 0; } if (d.empty()) { cout <<...
7
#include <bits/stdc++.h> using namespace std; string buf; vector<string> Ans(2); int main() { cin >> buf; char ch = 0; for (int i = 1; i < 27; i++) if (buf[i] == buf[i - 1]) { cout << "Impossible\n"; return 0; } vector<bool> vis(26, false); for (int i = 0; i < 27; i++) { int x = buf[i]...
8
#include <bits/stdc++.h> using namespace std; bool comp(const int a, const int b) { return a < b; } bool RelativelyPrime(int a, int b) { return (a < b) ? RelativelyPrime(b, a) : !(a % b) ? (b == 1) : RelativelyPrime(b, a % b); } int a[500005]; set<long long> s; vector<long long> d[2000...
2
#include <bits/stdc++.h> using namespace std; typedef vector<int> vi; int time_to_pick(int k) { return min(abs(k - 1), abs(1000000 - k)); } int main() { int n; cin >> n; vi prizes(n); int seconds = 0; for (int i = 0; i < n; i++) { cin >> prizes[i]; seconds = max(seconds, time_to_pick(prizes[i])); } ...
3
#include <bits/stdc++.h> int main() { int n; scanf("%d", &n); while (n--) { int a, b, ans = 0; scanf("%d%d", &a, &b); if (a == b) printf("0\n"); else { int x = abs(b - a); ans += x / 5; x -= (x / 5) * 5; ans += x / 2; x -= (x / 2) * 2; ans += x / 1; ...
0
#include <bits/stdc++.h> using namespace std; int main() { int n, sum = 0, a[100], b[100]; cin >> n; string s; cin >> s; for (int i = 0; i < n; ++i) { a[i] = int(s[i] - '0'); sum += a[i]; } if (sum == 0) { cout << "YES"; return 0; } b[0] = a[0]; for (int i = 1; i < n; ++i) b[i] = a[i...
5
#include <bits/stdc++.h> using namespace std; int main() { int d, L, v1, v2; cin >> d >> L >> v1 >> v2; printf("%.26lf", 1.0 * (L - d) / (v1 + v2)); return 0; }
0
#include <bits/stdc++.h> using namespace std; void actionFun() { long long k, n, ans; cin >> k >> n; if (n == 0) ans = k; else { long long on = n; if (k % 2) ans = k + 1; else ans = k - 1; k = ans; n--; if (n == 0) { cout << ans << endl; return; } if (...
1
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; int n, a[111]; int main() { cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; cout << ((*max_element(a, a + n)) ^ a[n - 1]); }
10
#include <bits/stdc++.h> using namespace std; vector<int> bags[101000]; set<int> lower_bags_for_type[101000]; set<int> lower_bags_for_type_reserve[101000]; int line; int line2; int upper_real_size[101000]; set<int> upper_bags_for_type[101000]; set<int> lower_indices; queue<int> erase_indices; void move_p(int type, int ...
16
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; const double tiaohe = 0.57721566490153286060651209; long long oula(long long x) { long long res = x; for (register int i = 2; i <= x / i; ++i) { if (x % i == 0) { res = res / i * (i - 1); while (x % i == 0) x /= i; } ...
4
#include <bits/stdc++.h> using namespace std; long long in[100009], out[100009]; long long mark[100009]; vector<long long> adj[100009]; void dfs(long long src, long long par) { if (mark[src] == 1) in[src] = 0; else in[src] = INT_MIN; for (int i = 0; i < adj[src].size(); i++) { if (adj[src][i] == par) ...
12
#include <bits/stdc++.h> using namespace std; long long n, a, b, T, dis; bool opa, opb; char x[20], y[20]; int main() { scanf("%lld", &T); while (T--) { scanf("%lld%lld%lld%s%s", &n, &a, &b, x + 1, y + 1); opa = (x[1] == 'r'); opb = (y[1] == 'r'); if (!a) opa = 0; else if (a == n - 1) ...
23
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ; long long int t; cin >> t; while (t--) { long long int n, r; cin >> n >> r; if (n > r) { cout << (r * (r + 1) / 2); } else { cout << (n * (n - 1) / 2) + 1; } cout...
4
#include <bits/stdc++.h> using namespace std; int n, K, X, Y; double p[109], d[109], dp[109][109]; double deta; int sgn(double x) { if (fabs(x) < 1e-9) return 0; else if (x > 0) return 1; else return -1; } bool check(double x) { int cnt = 0, m = 0; for (int i = 1; i <= n; i++) { if (sgn(x - d[...
13
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10; int n; int a[maxn], b[maxn]; int main() { scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", a + i); b[i] = a[i]; } int c = 0; int f1 = 0, f2 = 0; if (n == 2) { printf("YES"); return 0; } sort(b, b + n); f...
5
#include <bits/stdc++.h> using namespace std; int lim = 200000 + 100; int mod1 = 998244353; int mod2 = 1000000007; int inf = 1000000000; long long int M = 1000000000000000000 + 10000000; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n, m; cin >> n >> m; char c2[n + 1][m +...
12
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 10; int n, m, n_, nn, x, y, xx, yy; int lowbit(int x) { return x & (-x); } struct bit { int t[N << 1]; void update(int x, int v) { for (int i = x; i <= n_; i += lowbit(i)) t[i] += v; } int inquiry(int x) { int res = 0; for (int i = x;...
26
#include <bits/stdc++.h> using namespace std; std::mt19937 rnd( (int)std::chrono::steady_clock::now().time_since_epoch().count()); long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } const int MAXN = 100000; int n; int a[MAXN]; int ans[MAXN]; int b[MAXN], nb; vector<int> palsuffixes[MAXN]...
27
#include <bits/stdc++.h> using namespace std; bool ok(int n, int m, int mx) { for (int i = mx; i >= 1; --i) { if (m > n) swap(n, m); if (n < i) return 0; n -= i; } return 1; } int main() { int n, m; cin >> n >> m; int L = 0, R = 100000; while (L < R) { int mid = (L + R + 1) >> 1; if (o...
8
#include <bits/stdc++.h> using namespace std; vector<vector<int> > g; vector<vector<int> > ans; int p[100100]; int was[100100]; vector<pair<int, int> > edge; void bfs() { memset(was, -1, sizeof(was)); was[0] = 0; int cnt = -1; int l = 0, r = 0; while (l <= r) { int v = p[l]; l++; for (int i = (0);...
12
#include <bits/stdc++.h> using namespace std; long long n, k, d; int ps[500010]; bool works[500010]; int main() { cin.sync_with_stdio(0); cin.tie(0); cin >> n >> k >> d; for (int i = 1; i <= n; ++i) { cin >> ps[i]; } sort(ps + 1, ps + n + 1); queue<int> solvable; works[0] = true; for (int i = k; i...
13
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; int n, m, x, y, con[N], tot[N]; int head[N], nxt[N * 2], to[N * 2], cnt; void addedge(int u, int v) { to[cnt] = v; nxt[cnt] = head[u]; head[u] = cnt++; } int dfs(int u) { if (tot[u]) return tot[u]; for (int i = head[u]; ~i; i = nxt[i]) ...
8
#include <bits/stdc++.h> using namespace std; const long long inf = 1ll << 50; const int N = 100005; int n, S[N], matl[N], matr[N]; int id[N], rk[N], pos[N], rt[N]; long long k, a[N], b[N], val[N]; long long diff, lim; priority_queue<pair<long long, long long> > Q; struct TREE_S { long long t[N]; void init() { mems...
23
#include <bits/stdc++.h> using namespace std; inline void R(int &x) { x = 0; int 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(); } x *= f; } void Redirect() { fre...
18
#include <bits/stdc++.h> using namespace std; int gcd(int x, int y) { if (!y) return x; return gcd(y, x % y); } long long task() { long long n, a, b; cin >> n >> b >> a; long long arr[n], i; for (i = 0; i < n; ++i) cin >> arr[i]; long long p = a; for (i = 0; i < n; ++i) { if (!p && !b) break; if...
7
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; for (int q = 0; q < t; q++) { int h, n; cin >> h >> n; int p[n]; for (int v = 0; v < n; v++) { cin >> p[v]; } int p1 = h; int i = 0; int crys = 0; while (i < n) { if (i == n - 1) { b...
8
#include <bits/stdc++.h> using namespace std; const long long int INF = 1e18; const int inf = 1e9; const int MOD = 1e9 + 7; const int nax = 1000000 + 10; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n; cin >> n; int a[n + 1]; int i, j; for (i = 1; i <= n; i++) cin >> a[i]; int dp[n + 1...
6
#include <bits/stdc++.h> using namespace std; int a[400005]; int l[400005]; int r[400005]; int del[400005]; set<int> s; int main() { int n; cin >> n; for (int i = 1; i < n + 1; i++) { cin >> a[i]; } for (int i = 0; i < n + 1; i++) { l[i] = i - 1; r[i] = i + 1; } for (int i = 1; i < n + 1; i++)...
11
#include <bits/stdc++.h> using namespace std; const int MAX = 5e4 + 1; struct p { int x, id; bool operator<(const p& a) const { return x > a.x; } }; int L, sum, n; long long ans; string a; priority_queue<p> qu; int main() { cin >> a; n = a.length(); for (int i = 0, a1, a2; i < n; ++i) { if (a[i] == '(') ...
18
#include <bits/stdc++.h> using namespace std; const int M = 1000000007, BIG = 0x3f3f3f3f; int n, k; vector<int> a; vector<vector<int> > Process() { vector<vector<int> > ans(k, vector<int>()); vector<bool> vis(n * k + 5, 0); for (int i = 0; i < k; i++) { ans[i].push_back(a[i]); vis[a[i]] = 1; } int cur...
1
#include <bits/stdc++.h> using namespace std; int n; int query(int p) { int q = p + n / 2; cout << "? " << p << endl; cout << "? " << q << endl; cout << flush; int a, b; cin >> a >> b; return a - b; } int v[100005]; bool solve(int l, int r) { int mid = (l + r) / 2; if (mid == l) return false; v[mid]...
12
#include <bits/stdc++.h> using namespace std; void run() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } struct fenwick_tree { const int n = 2e5; vector<int> BIT; fenwick_tree() : BIT(n + 1) {} int query(int idx) { int mx = 0; while (idx) { mx = max(mx, BIT[idx]); idx -...
15
#include <bits/stdc++.h> using namespace std; const int maxn = 100000; int N; int X[maxn], Y[maxn], O[maxn]; int maxY[maxn + 1], minY[maxn + 1]; int max2Y[maxn + 1], min2Y[maxn + 1]; bool compare(int a, int b) { return X[a] < X[b]; } long long sq2(long long v) { return v * v; } bool valid(long long m) { if (sq2(X[O[N...
21
#include <bits/stdc++.h> using namespace std; const int maxn = 5e5 + 10; long long int n, a[maxn], nx[maxn], pr[maxn]; vector<pair<long long int, long long int> > v; int main() { cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; nx[i] = i + 1; pr[i] = i - 1; v.push_back(make_pair(a[i], i)); } ...
17
#include <bits/stdc++.h> using namespace std; template <typename... T> inline void inp(T &...args) { ((cin >> args), ...); } template <typename T> inline istream &operator>>(istream &in, vector<T> &a) { for (auto &x : a) in >> x; return in; } template <typename T, typename U> inline istream &operator>>(istream &i...
7
#include <bits/stdc++.h> using namespace std; const long double eps = 1e-9; const int inf = (1 << 30) - 1; const long long inf64 = ((long long)1 << 62) - 1; const long double pi = acos(-1); template <class T> T sqr(T x) { return x * x; } template <class T> T abs(T x) { return x < 0 ? -x : x; } int main() { int tt...
18
#include <bits/stdc++.h> using namespace std; long long p27[100005]; long long p7[100005]; int main() { int n; cin >> n; p27[0] = p7[0] = 1; for (int i = 1; i <= n; i++) { p27[i] = (27LL * p27[i - 1]) % 1000000007; p7[i] = (7LL * p7[i - 1]) % 1000000007; } cout << ((p27[n] - p7[n]) % 1000000007 + 10...
7
#include <bits/stdc++.h> using namespace std; int main() { long long int* T; int q, i; long long int a, b, c, alisa = 0, bob = 0, temp = 0; cin >> q; T = new long long int[q]; for (i = 0; i < q; i++) { cin >> a >> b >> c; if (a >= c && b >= c) { bob = c; if (a <= b) { alisa = a; ...
0
#include <bits/stdc++.h> int main() { int n, m; double res; scanf("%d %d", &n, &m); if (n == 1 && m == 1) res = 1.0; else { res = 1.0 / n + (double)(n - 1) * (m - 1) / n / (n * m - 1); } printf("%.10lf\n", res); return 0; }
13
#include <bits/stdc++.h> using namespace std; const int inf = 1e9; int rx[2005], ry[2005], bx[2005], by[2005]; vector<int> rv[2005], bv[2005]; int q[2005], qs, rs, bs, t[2005][2005]; map<int, int> mr, mb; bool vis[2005][2005]; int func(int x) { if (x < 0) return -x; return x; } int calc(int x, int y) { int a = bx...
18
#include <bits/stdc++.h> using namespace std; int arr[6][200005]; int main() { int n, m, l, r, min, a = 0; char ref1[] = {'a', 'b', 'c'}; char ref2[] = {'a', 'c', 'b'}; string s; cin >> n >> m; cin >> s; for (int i = 0; i < 6; i++) { a = i; if (a < 3) { for (int j = 0; j < n; j++) { ...
8
#include <bits/stdc++.h> using namespace std; vector<int> e[200000]; bool f = 0; long long p[200000], sum; int a[200000]; inline void ins(int u, int v) { e[u].push_back(v); e[v].push_back(u); } void dfs(int u, int fa, long long d) { if (f) return; p[u] = d; int tot = e[u].size(); if (fa) tot--; for (int i...
13
#include <iostream> #include <cstdio> #include <algorithm> #include <vector> using namespace std; #define endl '\n' #define ll long long #define pi pair<int, int> #define f first #define s second const int mxn = 200000; int n, k; ll a[mxn], p[mxn], dp[mxn]; vector<int> g[mxn], v[mxn]; void dfs(int c, int x){ k = max...
17
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:1073741824") using namespace std; const int MAXN = 1e5 + 100; vector<pair<int, int>> mt, v; int l[MAXN], r[MAXN]; int main() { #pragma warning(disable : 4996) int n, m; scanf("%d%d", &n, &m); for (int i = 0; i < m; i++) { int a, b; scanf("%d%d", &a,...
9
#include <bits/stdc++.h> using namespace std; long long int cons; long long int check(long long int a) { if (a >= cons || a <= -cons) a %= cons; return a; } long long int check2(long long int a) { if (a > 0) return a; long long int b = a / cons; a -= b * cons; if (a < 0) a += cons; return a; } long long i...
8
#include <bits/stdc++.h> using namespace std; int n, m; struct node { int nn, w; } adj[1005]; struct two { int u, v, w; } d; vector<int> l; vector<two> ans; bool col[1005]; int indeg[1005], outdeg[1005]; int main() { int u, v, w; cin >> n >> m; for (int i = 0; i < m; i++) { cin >> u >> v >> w; adj[u]....
6
#include <bits/stdc++.h> using namespace std; const int maxn = 55; int n; int x[maxn], y[maxn]; bool check(int u) { int xmx = -1, xmn = 55, ymx = -1, ymn = 55; for (int(i) = (1); (i) <= (n); (i)++) if (i != u) { xmx = max(xmx, x[i]); xmn = min(xmn, x[i]); ymx = max(ymx, y[i]); ymn = min(...
8
#include <bits/stdc++.h> using namespace std; struct node { int p[26], cnt, bad, f; } T[2000005]; int n, m, nd, q[2000005], lo, hi; char s[2005], rule[2005]; int ret = 0; void add(char s[]) { int x = 0, c; for (int i = 0; s[i]; i++) { c = s[i] - 'a'; if (!T[x].p[c]) T[x].p[c] = nd, ++nd; x = T[x].p[c]...
14
#include <bits/stdc++.h> using namespace std; const long long oo = 0x3f3f3f3f3f3f3f3fll; const int LGN = 25; const int MOD = 1e9 + 7; const int N = 1e5 + 5; long long modpow(long long a, long long b, long long m) { long long ans = 1; while (b > 0) { if (b & 1) ans = (ans * a) % m; b >>= 1; a = (a * a) %...
18
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 5; const long long MOD_1 = 1e9 + 7; const long long MOD_2 = 1e9 + 9; const long long PODST = 29; int t, n; char wcz[N]; string s[N]; vector<pair<long long, long long>> hasz[N]; long long pot_1[N], pot_2[N]; int main() { pot_1[0] = pot_2[0] = 1; for (...
15
#include <bits/stdc++.h> using namespace std; int main() { long long t, n, m, x; cin >> t; while (t--) { cin >> n >> m; long long a[n], b[n]; for (long long i = 0; i < n; i++) cin >> a[i]; for (long long i = 0; i < m; i++) cin >> b[i]; sort(b, b + m); long long st = b[0] - 1; long long...
4
#include <bits/stdc++.h> using namespace std; int getint() { int r = 0, k = 1; char c = getchar(); for (; c < '0' || c > '9'; c = getchar()) if (c == '-') k = -1; for (; '0' <= c && c <= '9'; c = getchar()) r = r * 10 - '0' + c; return r * k; } long long n, k, x, ans; int main() { n = getint(); k = ge...
4
#include<iostream> int t,n; std::string a,b,c; int main() { std::cin>>t; while(t--) { std::cin>>n>>a>>b>>c; int i=0,j=0,k=0,m=0; while(i!=2*n && j!=2*n && k!=2*n) { int x=(int)(a[i]=='0')+(b[j]=='0')+(c[k]=='0'); char y=x>=2?'0':'1';std::cout<<y; i+=a[i]==y;j+=b[j]==y;k+=c[k]==y; ++m; } m-...
11
#include <bits/stdc++.h> using namespace std; int u, v, c, a[100005], ans[100005], p[2000006], x, n, q, k, pas[100005], level[100005]; vector<int> G[2000006], V[100005]; void dfs(int u, int par) { int c = a[u]; ans[u] = pas[u] = -1; while (c > 1) { if (p[c] == 0) p[c] = c; int d = p[c]; if (G[d].s...
13
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 100; const int inf = 1e9 + 7; int n, a[N], b[N], pos[N], ans[N]; vector<pair<int, int> > bs[N]; pair<int, int> seg[2 * N]; int query(int l, int r) { l += n - 1; r += n; pair<int, int> res = {inf, inf}; for (; l < r; l >>= 1, r >>= 1) { if (l ...
18
#include <bits/stdc++.h> using namespace std; long long k, a, b; int main(int argc, char** argv) { int n; string s[1000], home, t[1000], u[1000]; int r[1000], b[1000]; cin >> n; cin >> home; int e = 0, f = 0; for (int i = 0; i < n; i++) { cin >> s[i]; t[e++] = s[i].substr(0, 3); u[f++] = s[i]....
1
#include <bits/stdc++.h> using namespace std; long long f[5005][5005], ans, len1, len2; char a[5005], b[5005]; int main() { scanf("%s%s", a + 1, b + 1); len1 = strlen(a + 1); len2 = strlen(b + 1); for (register int i = 1; i <= len1; i++) for (register int j = 1; j <= len2; j++) { if (a[i] == b[j]) f[i...
9
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; int cnt, p[N], d[N], mu[N], a[N], b[N], c[N]; long long res[N]; bool vis[N]; vector<int> e[N], vec[N]; vector<int> mp[N]; void solve(int i, int cnt, int sz, int x) { if (i == cnt) { vec[x].push_back(sz); return; } int p = 1; for (int j...
16
#pragma GCC optimize("O3") #pragma GCC target("sse4") #include <bits/stdc++.h> using namespace std; using ll = long long; using vi = vector<int>; using pi = pair<int, int>; using vpi = vector<pair<int, int>>; using pl = pair<ll, ll>; using vl = vector<ll>; #define all(v) (v).begin(), (v).end() #define ar array #defin...
6
#include <bits/stdc++.h> using namespace std; signed main() { long long n; cin >> n; long long first = -1; for (long long i = 1; i < n + 1; ++i) { if (i % 3 == 0) { cout << first << ' ' << 3 << endl; } else { ++first; cout << first << ' ' << 0 << endl; } } }
18
#include <bits/stdc++.h> using namespace std; bool edge[600][600]; int l[600]; char let[600]; int main() { int n, m, a = 0, b = 0; cin >> n >> m; for (int i = 0; i < m; i++) { scanf("%d%d", &a, &b); --a; --b; edge[a][b] = true; l[a]++; edge[b][a] = true; l[b]++; } for (int i = 0; i...
10
#include <bits/stdc++.h> inline int in() { int x = 0; char c = getchar(); bool f = false; while (c < '0' || c > '9') f |= c == '-', c = getchar(); while (c >= '0' && c <= '9') x = (x << 1) + (x << 3) + (c ^ 48), c = getchar(); return f ? -x : x; } const int N = 4e5 + 5, mod = 1e9 + 7; int pri[505], inv[...
16
#include <bits/stdc++.h> using namespace std; #pragma warning(disable : 4996) #pragma comment(linker, "/STACK:336777216") inline int nxt() { int x; scanf("%d", &x); return x; } inline long long lnxt() { long long x; scanf("%I64d", &x); return x; } const int base = (int)1e9; const int N = (int)1e6 + 100; con...
6