solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> using namespace std; inline int gi() { int sum = 0, f = 1; char ch = getchar(); while (ch > '9' || ch < '0') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { sum = (sum << 3) + (sum << 1) + ch - '0'; ch = getchar(); } return f * sum; } in...
7
#include <bits/stdc++.h> using namespace std; const int INF = 1000000000; struct debugger { template <typename T> debugger& operator,(const T& v) { cerr << v << " "; return *this; } } dbg; int main() { int N, r, v; scanf("%d", &N), scanf("%d", &r), scanf("%d", &v); const double pi = acos(-1); for ...
17
#include <bits/stdc++.h> using namespace std; int read() { int kkk = 0, x = 1; char c = getchar(); while ((c < '0' || c > '9') && c != '-') c = getchar(); if (c == '-') c = getchar(), x = -1; while (c >= '0' && c <= '9') kkk = kkk * 10 + (c - '0'), c = getchar(); return kkk * x; } int n, C[4][4][4], B[6010]...
25
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; vector<long long> cities(n), towers(m); for (int i = 0; i < n; i++) cin >> cities[i]; for (int i = 0; i < m; i++) cin >> towers[i]; sort(towers.begin(), towers.end()); towers.resize((m = unique(towers.begin(), towers.end()...
7
#include <bits/stdc++.h> using namespace std; long long n, cnt; long long xx, yy; int kerd(long long a, long long b) { cnt++; a = n - a + 1, b = n - b + 1; cout.flush() << a << " " << b << "\n"; int ans; cin >> ans; return ans; } void solve(long long kx, long long ky, long long nx, long long ny, long long s...
22
#include <bits/stdc++.h> using namespace std; int pw[1000100]; int jmp[1000100]; int n, m, k; int main() { pw[0] = 1; for (int i = 1; i < 1000100; ++i) pw[i] = (pw[i - 1] << 1) % 1000000007; bool ok = true; int ans = 0; int min_start = 1000100; int max_start = 0; int long_edge = 0; scanf("%i %i %i", &n,...
14
#include <bits/stdc++.h> using namespace std; const double eps = 1e-8; int A, B, rt, n, m, son[200005], h[200005], fa[200005], top[200005], s[200005]; double t, ans; vector<int> a[200005]; vector<double> b[200005]; struct O { double l, r; }; vector<O> T[200005]; struct P { double t; int f; }; vector<P> w; int lc[...
25
#include <bits/stdc++.h> using namespace std; void solve() { int n; cin >> n; int num[n], test[n], sum = 0; unordered_map<int, int> m; for (int i = 0; i < n; i++) { cin >> num[i]; m[num[i]]++; test[i] = num[i]; } int c = 0; for (int i = 0; i < n - 1; i++) { sum = num[i]; for (int j =...
7
#include <bits/stdc++.h> using namespace std; template <class T> using lim = numeric_limits<T>; struct dsu { int n; int *table; dsu(int size) { n = size; table = new int[n]; memset(table, -1, sizeof *table * n); } int find(int i) { if (table[i] < 0) return i; else return table[...
7
#include <bits/stdc++.h> using namespace std; const int maxn = 500 + 10; const int inf = 1000 * 1000 * 100; long long a[maxn][maxn], n, x[maxn], ans[maxn], d[maxn][maxn]; int main() { ios::sync_with_stdio(false); cin >> n; for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) cin >> a[i][j]; for (int i = ...
9
#include <bits/stdc++.h> using namespace std; const int N = 30; bitset<N> vis; vector<int> graph[N]; vector<string> res; string s; int n, sz, a, b, cnt, usd, parent[N]; inline string dfs(int cur) { string res = ""; usd++; for (int it : graph[cur]) return ((char)(cur + 'a')) + dfs(it); return ((char)(cur + 'a'))...
12
#include <bits/stdc++.h> using namespace std; const int maxn = 305000; int n, gogogo, val, cnt = 1, pre[maxn], res0 = 0; char s[maxn], ps[maxn]; stack<pair<char, int> > stk; vector<int> x, y; pair<int, int> ans; int Ans = 0; int main() { scanf("%d%s", &n, s + 1); for (int i = 1; i <= n; i++) { val += (s[i] == '...
17
#include <bits/stdc++.h> using namespace std; inline void splay(int &v) { v = 0; char c = 0; int p = 1; while (c < '0' || c > '9') { if (c == '-') p = -1; c = getchar(); } while (c >= '0' && c <= '9') { v = (v << 3) + (v << 1) + c - '0'; c = getchar(); } v *= p; } const int N = 200010; c...
19
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { if (a == 0) return b; if (b == 0) return a; if (a == 1 || b == 1) return 1; if (a == b) return a; if (a > b) return gcd(b, a % b); else return gcd(a, b % a); } long long lcm(long long a, long long b) { return (a ...
5
#include <bits/stdc++.h> using namespace std; int a[26], b[26]; int main() { string s; cin >> s; for (int i = 0; i < s.size(); i++) a[s[i] - 'a']++; int n; cin >> n; int counter = 0; string result = ""; for (int i = 0; i < 26; i++) { if (a[i] != 0) { counter++; b[i] = 1; result += ...
6
#include <bits/stdc++.h> using namespace std; const int mod = 998244353; const int inf = 1 << 30; const int maxn = 400000 + 5; long long sqr(int x) { return 1ll * x * x; } vector<int> edge[maxn]; int n, m, a[maxn], c[maxn], f[maxn]; void dfs(int u, int ff) { f[u] = ff; for (int& v : edge[u]) if (v != ff) dfs(v,...
25
#include <bits/stdc++.h> using namespace std; int main() { int n, m, k; cin >> n >> m >> k; if (n <= m && n <= k) cout << "Yes"; else cout << "No"; }
0
/* An ACEASH Source code */ #include<bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define vi vector<int> #define vl vector<ll> #define vs vector<string> #define vc vector<char> #define vvi vector< vector < int > > #define vvl vector< vector < ll > > #define pii pair< int , int > ...
2
#include <bits/stdc++.h> using namespace std; set<pair<int, char> > ss; int main() { ios::sync_with_stdio(false); int n, m, p; cin >> n >> m >> p; p--; string s; cin >> s; for (int i = 0; i < n; i++) { ss.insert({i + 1, s[i]}); } string t; cin >> t; auto ptr = ss.begin(); while (p--) ptr++; ...
9
#include <bits/stdc++.h> using namespace std; class frac { public: long long int a, b; frac() {} frac(long long int aa, long long int bb) { a = aa; b = bb; } bool operator<(const frac q) const { long long int aa = a, bb = b, qa = q.a, qb = q.b; if (bb < 0) { aa = -aa; bb = -bb; ...
17
#include <bits/stdc++.h> using namespace std; vector<pair<int, int> > adj[100005]; int adj2[505][505]; int t[505], v[100005]; int vis[100005]; bool bfs(int x, int y) { int qtd = 0; queue<int> q; q.push(x); while (!q.empty()) { int v = q.front(); q.pop(); if (vis[v] == x) continue; vis[v] = x; ...
12
#include <bits/stdc++.h> using namespace std; int n, k; int main() { cin >> n; if (n % 2 == 0) cout << n * n / 2 << endl; if (n % 2 == 1) cout << n * (n - 1) / 2 + n / 2 + 1 << endl; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if ((i + j) % 2 == 0) { cout << "C"; } else {...
0
#include <bits/stdc++.h> using namespace std; const long long maxn = 100005; vector<long long> adj[maxn]; long long color[maxn], dist[maxn]; bool vis[maxn]; long long cycleLen = -1; void dfs(long long u) { color[u] = 1; for (long long v : adj[u]) { if (color[v] == 1) { cycleLen = max(cycleLen, abs(dist[u]...
17
#include <bits/stdc++.h> using namespace std; const int INF = 1e9; int n; string a, b; void fastIO() { cin.tie(0)->sync_with_stdio(0); } int calc(string s) { int cnt = 0, num1 = 0, num2 = 0; for (int i = 0; i < n; i++) { if (s[i] == '1' && b[i] == '0') cnt++; if (s[i] == '1') num1++; if (b[i] == '1') nu...
8
#include <bits/stdc++.h> using namespace std; const int mxmx = 610; long long int n, k, k2; int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n >> k; k2 = (2 + k) * (k - 1) / 2 - k + 2; int l = 0, r = k - 1, mid; while (l < r) { mid = (r + l) / 2; if ((2 * k - mid + 1) * mid / 2 - mid + 1 >= ...
9
#include <bits/stdc++.h> using namespace std; map<string, int> m; bool v[10], h[10]; char c[1100][1100]; int N, M; int A[300][300]; long long P[300][3]; long long MOD = 1000000007; int main() { m["........."] = 0; m["....O...."] = 1; m["..O...O.."] = 2; m["..O.O.O.."] = 3; m["O.O...O.O"] = 4; m["O.O.O.O.O"]...
15
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int arr[n]; for (int i = 0; i < n; i++) cin >> arr[i]; sort(arr, arr + n); cout << arr[n - 1] << " "; int newarr[100043] = {0}; vector<int> temp; for (int i = 0; i < n; i++) { if (arr[n - 1] % arr[i] != 0) temp.push_...
3
#include <bits/stdc++.h> using namespace std; const long long MX = 1e6 + 3; long long n, m, arra[MX], arrb[MX], nd[MX * 4], mn[MX * 4], q, lz[MX * 4]; void FLUSH(long long id, long long st, long long en) { if (st == en - 1) { return; } long long mid = (st + en) / 2; mn[id * 2] += lz[id]; mn[id * 2 + 1] +=...
14
#include <bits/stdc++.h> using namespace std; int N, st[800010], a[200010]; void create(int n = 1, int l = 0, int r = N) { if (l == r) st[n] = l; else { int m = (l + r) / 2; create(2 * n, l, m); create(2 * n + 1, m + 1, r); st[n] = st[2 * n]; if (a[st[2 * n + 1]] > a[st[2 * n]]) st[n] = st[2...
8
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; int dp[(1 << 24)]; long long sum[(1 << 24)]; int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cout << setprecision(32); int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } i...
15
#include <bits/stdc++.h> using namespace std; bool Check(int N, int pos) { return (bool)(N & (1 << pos)); } int Set(int N, int pos) { return (N | (1 << pos)); } int fx[] = {-1, 0, 1, 0}; int fy[] = {0, 1, 0, -1}; inline long long BigMod(long long B, long long P, long long M) { long long R = 1; while (P > 0) { i...
4
#include <bits/stdc++.h> using namespace std; int main() { string s, ans = ""; int ct = 0; cin >> s; for (int i = 0; s[i]; ++i) { if (s[i] == 'd' && s[i + 1] == 'o' && s[i + 2] == 't') { if (i != 0 && i + 2 != s.size() - 1) ans += "."; else ans += "dot"; i += 2; } else ...
5
#include <bits/stdc++.h> #pragma GCC optimize("-O3") using namespace std; inline void rdi(int &n) { n = 0; char c = getchar(); while (c < '0' or c > '9') c = getchar(); while (c >= '0' and c <= '9') { n = (n << 3) + (n << 1) + c - '0'; c = getchar(); } } inline void rdl(long long int &n) { n = 0; ...
5
#include <bits/stdc++.h> using namespace std; const int Max = 1e3 + 5; int main() { int n; int a[Max]; cin >> n; int mark[Max] = {0}; for (int i = 0; i < n; i++) { cin >> a[i]; } int con = 1; mark[0] = 1; int ans = 0; for (int i = 0; i < n - 1; i++) { if ((a[i + 1] - a[i]) == 1) { con+...
5
#include <bits/stdc++.h> using namespace std; int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); } const int MAXN = 100000; const int MAXP = 1000000; int pw(int x, int n, int mod) { int ret = 1; while (true) { if (n & 1) ret = (long long)ret * x % mod; if ((n >>= 1) == 0) return ret; x = (long l...
23
#include <bits/stdc++.h> using namespace std; int main() { int t, count = 0; cin >> t; while (t--) { int p, q; cin >> p >> q; if (q - p >= 2) { count += 1; } } cout << count; return 0; }
0
#include <bits/stdc++.h> using namespace std; bool check(string &s, int &n, int &k) { string bad1 = string(k + 2, 'G'); string bad2 = string(k + 2, 'B'); return s.find(bad1) == string::npos && s.find(bad2) == string::npos && s.size() == n; } string brute(string &s, int &n, int &k) { sort(s.begin(), s.e...
7
#include <bits/stdc++.h> using namespace std; vector<int> g[200100]; int p[200100]; vector<int> cmp[200100]; int cmpNo, root[200100], finalroot; bool vis[200100], safe[200100], inCycle[200100]; bool cy[200100]; void dfs(int u, int par) { inCycle[u] = true; cmp[cmpNo].push_back(u); vis[u] = true; if (u == p[u]) ...
9
#include <bits/stdc++.h> #pragma comment(linker, "/stack:200000000") #pragma GCC optimize("O3") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") using namespace std; const long long int mod = 1e9 + 7; long long int n; string a, b; unordered_map<char, long long int> cntB, cntM; long long int...
12
#include <bits/stdc++.h> using namespace std; int main() { long long int n, k, i; cin >> n >> k; long long int a[n]; char c; vector<long long int> v(k); for (i = 0; i < n; i++) { cin >> c; a[i] = c - '0'; if (i < k) { v[i] = a[i]; } } int first = 0; for (i = 0; i < n; i++) { ...
9
#include <bits/stdc++.h> using namespace std; string s, s1, s2; int s_num[10] = {}, s1_num[10] = {}, news_num[10] = {}; int lens, lens1; void get_pos() { int pos_num[10] = {}, pos_len, pos; bool is_find; for (int i = 1; i <= lens; ++i) { pos = i, pos_len = 0, is_find = true; while (pos) ++pos_num[pos % 10...
15
/* Problem: Journey Link: https://codeforces.com/contest/1476/problem/D */ #include <bits/stdc++.h> using namespace std; #define debug(T) { cout << ">> " << #T << " = " << (T) << endl; } #define flush() { cout << endl; } typedef long long ll; typedef unsigned long long ull; template<typename T> void read(ve...
9
#include <bits/stdc++.h> using namespace std; int main() { int len, i; int pos = 0, pos1; long long sum = 0; int s = 0; int heavy[200000] = {0}; int metal[1000000] = {0}; char str[1000001]; scanf("%s", str); len = strlen(str); for (i = 0; i < len; i++) { if (str[i] == 'h' && str[i + 1] == 'e' &&...
5
#include <bits/stdc++.h> using namespace std; string st, s1; vector<string> op; vector<char> opr; int main() { cin >> st; int i = 0; s1 = ""; while (i < st.length()) { if (st[i] == '+' || st[i] == '-') { op.push_back(s1); opr.push_back(st[i]); s1 = ""; } else s1 += st[i]; i++...
12
#include <bits/stdc++.h> using namespace std; int t[2][500010]; int query(int id, int x) { int ret = 0; while (x > 0) { ret += t[id][x]; x -= (x & (-x)); } return ret; } void add(int id, int x, int val) { while (x <= 500010) { t[id][x] += val; x += (x & (-x)); } } int arr[500010]; vector<int...
12
#include <bits/stdc++.h> using namespace std; bool check(int64_t p, vector<long long>& k) { for (long long(i) = 0; (i) < (k.size() - p); ++(i)) { if (k[i] != k[i + p]) { return false; } } return true; } void solve() { int64_t n; cin >> n; vector<long long> a(n); vector<long long> k(n); for...
4
#include <bits/stdc++.h> using namespace std; const int LIM = 1e5 + 5; const long long int INF = 1e16; const int l = ceil(log2(LIM)); long long int inf = 1e17; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, m; cin >> n >> m; vector<vector<pair<int, int> > > queries(n + 1); for ...
10
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; int main() { ios_base::sync_with_stdio(false); int t; cin >> t; while (t--) { int x, y, z; cin >> x >> y >> z; int ans = 0; vector<int> a; a.push_back(x); a.push_back(y); a.push_back(z); sort(a.begin(), ...
1
#include <bits/stdc++.h> using namespace std; string t; int a[110], m, n, s; bool d; int main() { cin >> t; for (int i = 0; i < t.size(); i++) { if (t[i] == ',') d = 1; } if (!d) cout << t << endl; else { for (int i = 0; i < t.size(); i++) { if (t[i] == ',' or i == t.size() - 1) { a[...
5
#include <bits/stdc++.h> using namespace std; int n, m, st[100005], tp, pn = 1e5 + 2; long long a[100005], b[100005], c[100005], d[100005]; long long sum[1000005], sum2[1000005], nans[1000005], nans2[1000005], lazy[1000005]; void pushup(int x) { sum[x] = max(sum[x * 2], sum[x * 2 + 1]); } void col(int x, long long ...
25
#include <bits/stdc++.h> using namespace std; template <typename T1, typename T2> void chkmin(T1 &x, T2 y) { if (x > y) x = y; } template <typename T1, typename T2> void chkmax(T1 &x, T2 y) { if (x < y) x = y; } template <typename T> void read(T &x) { x = 0; char c = getchar(); T neg = 1; while (!isdigit(c)...
20
#include <bits/stdc++.h> using namespace std; int main() { long int n, k, l, c, d, p, nl, np, t, a, b, e, x; cin >> n >> k >> l >> c >> d >> p >> nl >> np; t = l * k; a = t / nl; b = d * c; e = p / np; x = min(a, b); x = min(x, e); cout << (x / n); return 0; }
0
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); long long n, t; cin >> n >> t; long double r, k; cout.precision(10); r = pow(1.000000011, t); k = n * r; cout << k; return 0; }
4
#include <bits/stdc++.h> void fo() { fflush(stdout); } using namespace std; int main() { int n, v; scanf("%d%d", &n, &v); vector<pair<int, int>> t1, t2; for (int i = 0; i < n; i++) { int ty, vl; scanf("%d%d", &ty, &vl); if (ty == 1) { t1.push_back({vl, i + 1}); } else t2.push_back({v...
11
#include <bits/stdc++.h> using namespace std; int main() { vector<int> v, c; int t; cin >> t; while (t--) { int n; cin >> n; n *= 2; int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } sort(a, a + n); cout << a[n / 2] - a[n / 2 - 1] << '\n'; } }
2
#include <bits/stdc++.h> using namespace std; template <class T> bool umin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } template <class T> bool umax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } int l[1000009], r[1000009]; vector<pair<int, int> > ans; int main() { in...
10
#include <bits/stdc++.h> using namespace std; char s[110000]; int dp[110000]; int sum[110000]; int get(int l, int r) { return sum[r] - sum[l]; } bool match(char c1, char c2) { return (c1 == '(' && c2 == ')') || (c1 == '[' && c2 == ']'); } int main() { gets(s); int len = strlen(s); for (int i = 0; i < len; i++) ...
9
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 5; int N, p[MAXN], sz[MAXN]; vector<int> G[MAXN]; double e[MAXN]; void dfs1(int v) { sz[v] = 1; for (int i = 0; i < G[v].size(); i++) { int u = G[v][i]; if (u != p[v]) { dfs1(u); sz[v] += sz[u]; } } } void dfs(int v) { ...
9
#include <bits/stdc++.h> using namespace std; int main() { long long xa, ya, xb, yb; cin >> xa >> ya >> xb >> yb; long long n, a, b, c, ch = 0; cin >> n; for (long long i = 0; i < n; i++) { cin >> a >> b >> c; if ((a * xa + b * ya + c > 0 && a * xb + b * yb + c < 0) || (a * xa + b * ya + c < 0...
9
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1); struct P { int x, y, id; double ang; bool operator<(const P &a) const { return ang < a.ang; } } p[2005], o; int n, bl[2005]; int cnt[2], tmp[2]; long long ans; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d%d", &p[...
19
#include <bits/stdc++.h> using namespace std; int n, k; const int maxn = 2e6 + 7; struct node { int page; vector<string> s; }; int cnt; int head[maxn], to[maxn], nxt[maxn], in[maxn], vis[maxn]; void add_edge(int x, int y) { in[y]++; to[++cnt] = y; nxt[cnt] = head[x]; head[x] = cnt; } int main() { ios::syn...
14
#include <bits/stdc++.h> using namespace std; double safe_sqrt(double x) { return sqrt(max((double)0.0, x)); } long long GI(long long& x) { return scanf("%lld", &x); } const long long MN = 100111; long long t[MN], f[MN]; long long n; int32_t main() { ios::sync_with_stdio(0); cin.tie(0); cout << (fixed) << setprec...
8
#include <bits/stdc++.h> using namespace std; const long double pi = 3.14159265359; template <typename T> T abs(T x) { return x > 0 ? x : -x; } template <typename T> T sqr(T x) { return x * x; } template <typename T> void chmin(T &x, T y) { x = min(x, y); } template <typename T> void chmax(T &x, T y) { x = max(...
12
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; char a[n][5]; char prev = ' '; for (int i = 0; i < n; i++) { for (int j = 0; j < 5; j++) { cin >> a[i][j]; } } for (int i = 0; i < n; i++) { prev = ' '; for (int j = 0; j < 5; j++) { if (prev == 'O' && ...
0
#include <bits/stdc++.h> #pragma GCC optimize(3) using namespace std; int n, m, a[262145], c[262145], f[262145]; int l, tt, inv, rev[262145], root[262145]; int ta1[262145], tb1[262145], ta2[262145], tb2[262145], tc2[262145]; inline int qpow(int a, int t) { register int res = 1; for (register int i = t; i; i >>= 1) ...
23
#include <bits/stdc++.h> using namespace std; long long C[2020][2020]; long long F[2020]; void pre() { for (int i = 0; i < 2020; i++) { C[i][0] = 1; C[i][i] = 1; for (int j = 1; j < i; j++) C[i][j] = ((C[i - 1][j - 1] + C[i - 1][j] + 1000000007) % 1000000007); } F[0] = 1; for (int i = 1; i < 2...
12
#include <bits/stdc++.h> using namespace std; const double EPS = 1e-8; struct Point { double x, y; Point() {} Point(double x, double y) : x(x), y(y) {} Point vn() const { return Point(y, -x); } } p[3], q[4]; Point operator+(const Point& lhs, const Point& rhs) { return Point(lhs.x + rhs.x, lhs.y + rhs.y); } Po...
18
#include <bits/stdc++.h> using namespace std; const int MX = 1e6 + 5, SIG = 26; int str[MX], len[MX], link[MX], to[MX][SIG], slink[MX], dif[MX]; int cur, sl, sz; void init() { memset(to, 0, sizeof(to)); cur = sl = 0; str[sl++] = -1; link[0] = 1, len[0] = 0; link[1] = 0, len[1] = -1; sz = 2; } int getLink(in...
21
#include <bits/stdc++.h> using namespace std; const int MAXN = 305; const long double INF = 9e18; struct pt { long long x, y; pt() {} pt(long long xx, long long yy) : x(xx), y(yy) {} long long operator%(const pt &o) const { return x * o.y - y * o.x; } long long operator*(const pt &o) const { return x * o.x + ...
13
#include <bits/stdc++.h> using namespace std; long long n, k1, k2, temp; pair<long long, long long> ar[300005]; bool comp(pair<long long, long long> a, pair<long long, long long> b) { return a > b; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cin >> n >> k1 >> k2; for (long long i = ...
9
#include <bits/stdc++.h> using namespace std; double dp[203][203][403], pr[203]; bool vis[203][203][403]; int n, k, l, a[203]; double dfs(int p, int w, int s) { if (p == n) { if (w >= l && s >= 0) return 1; else return 0; } if (vis[p][w][s + 200]) return dp[p][w][s + 200]; vis[p][w][s + 200]...
10
#include <bits/stdc++.h> using namespace std; inline double myDistance(const pair<int, int>& a, const pair<int, int>& b) { return sqrt(pow(a.first - b.first, 2) + pow(a.second - b.second, 2)); } int main() { int n, m; cin >> n >> m; set<pair<int, int> > candidates; const int NEIGHBOURS = 2; for (int i = 0; ...
10
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1); template <typename T> T getint() { T val = 0; char c; while ((c = getchar()) && !(c >= '0' && c <= '9')) ; do { val = (val * 10) + c - '0'; } while ((c = getchar()) && (c >= '0' && c <= '9')); return val; } int e[100501]; vect...
11
#include <bits/stdc++.h> using namespace std; const int inf = 1e9; const int MOD = 1e9 + 7; const int N = 5e3 + 10; const string dir = "LDUR"; const int dx[4] = {0, 1, -1, 0}, dy[4] = {-1, 0, 0, 1}; int a[N][N] = {0}, n, m, Slink[N][4], link[N][4]; char s[N]; int cv(char x) { int ans = 3; while (ans >= 0 && dir[ans...
15
#include <bits/stdc++.h> using namespace std; const int N = 4e5 + 3, p = 998244353, G = 3, Gi = 332748118; long long n, m; int a[N], b[N], P[N], fac[N], inv[N], r[N]; inline long long in() { char c; int f = 1; while ((c = getchar()) < '0' || c > '9') if (c == '-') f = -1; long long x = c - '0'; while ((c ...
23
#include <bits/stdc++.h> using namespace std; long long a, b; int n; int dx = 0, dy = 0; int Dx[110], Dy[110]; bool judge() { for (int i = 0; i <= n; i++) { if (dx == 0 && dy == 0) { if (Dx[i] == a && Dy[i] == b) return 1; } else if (dx == 0) { if (Dx[i] == a && (b - Dy[i]) % dy == 0) { in...
9
#include <bits/stdc++.h> using namespace std; vector<int> v1(3); vector<int> v2(3); int ch(int x, int y, int z) { if (v2[x] > 31) return 0; if (v2[y] > 12) return 0; int tmp_y = v2[z] + 18; if (tmp_y > 99) return 0; if ((v2[y] == 4) || (v2[y] == 6) || (v2[y] == 9) || (v2[y] == 11)) if (v2[x] == 31) return...
9
#include <bits/stdc++.h> using namespace std; int n, m, k, l[505], r[505], g[505][505], f[505][505], oo = 1e9; int main() { ios ::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> m >> k; for (int i = 1; i <= n; i++) for (int j = 0; j <= m; j++) g[i][j] = oo; for (int i = 1; i <= n; i++) { st...
10
#include <bits/stdc++.h> int gcd(int a, int b) { return a ? gcd(b % a, a) : b; } int main() { int a, b; scanf("%d %d", &a, &b); printf("%d\n", gcd(a - 1, b - 1) + 1); }
13
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string a; cin >> a; int h = 0, v = 0; int i, j, k; int vv, hh; int ans = 0; for (i = 1; i <= n; i++) { for (j = 0; j + i <= n; j++) { vv = 0; hh = 0; for (k = j; k < j + i; k++) { if (a[k] == 'U')...
2
#include <bits/stdc++.h> using namespace std; const int N = 405; const int mod = 1000 * 1000 * 1000 + 7; inline void add(int &x, int y) { x += y; if (x >= mod) x -= mod; } int n, f[N][2 * N]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> n; f[1][1] = f[1][0] = 1; for (int i = 2; i <= n...
20
#include <bits/stdc++.h> using namespace std; const int M = 5e5 + 10; const int inf = 0x3f3f3f3f; const long long mod = 1e9 + 7; const int bit = 32; const double pi = acos(-1.0); queue<int> q; vector<pair<int, int> > v[M]; int a[M], co[M], d[M]; int main() { memset(d, inf, sizeof(d)); memset(co, -1, sizeof(co)); ...
17
#include <bits/stdc++.h> using namespace std; const int N = 100000; int a[N]; void solve() { int n; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; } sort(a, a + n); int j = 0; while (j < n - 1) { if (a[j] != a[j + 1]) { if (a[j] * 2 > a[j + 1]) { cout << "YES"; return; ...
6
#include <bits/stdc++.h> using namespace std; const int maxN = 500005; const int maxK = 10005; const int mod = (int)1e9 + 7; const int inf = (int)1e9; void bad(int n) { if (n >= 6) { printf("1 2\n"); printf("1 3\n"); printf("1 4\n"); printf("4 5\n"); printf("4 6\n"); n -= 6; int elem = 6; ...
7
#include <bits/stdc++.h> using namespace std; const long long N = 2010; inline long long read() { long long s = 0, w = 1; register char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') w = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') s = (s << 3) + (s << 1) + (ch ^ 48), ch = g...
8
#include <bits/stdc++.h> using namespace std; int main() { int c; cin >> c; if (c >= 0) cout << c; else if (abs(c) < 100 and abs(c) % 10 == 0) cout << 0; else { int x = abs(c); if (x % 10 >= ((x % 100) / 10)) cout << "-" << x / 10; else cout << "-" << x / 100 * 10 + x % 10; }...
1
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 4; int a[maxn]; int b[maxn]; int main() { int n, m, p; scanf("%d%d%d", &n, &m, &p); for (int i = 0; i < n; i++) { scanf("%d", &a[i]); } for (int i = 0; i < m; i++) { scanf("%d", &b[i]); } int x; int y; for (int i = 0; i < n; ...
10
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int t; cin >> t; while (t--) { int n; cin >> n; for (int i = 0; i < n; i++) cout << 1 << " "; cout << endl; } return 0; }
0
#include <bits/stdc++.h> using namespace std; int main() { long long int ta, n, k1, k2, i, j, f, maxf; cin >> ta; while (ta-- > 0) { maxf = 0; cin >> n; cin >> k1; cin >> k2; for (i = 0; i < k1; i++) { cin >> j; if (maxf < j) maxf = j, f = 1; } for (i = 0; i < k2; i++) { ...
0
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 7; const int inf = 0x3f3f3f3f; const long long INF = 0x3f3f3f3f3f3f3f3f; const int mod = 1e9 + 7; const double eps = 1e-8; const double PI = acos(-1); template <class T, class S> inline void add(T& a, S b) { a += b; if (a >= mod) a -= mod; } template...
17
#include <bits/stdc++.h> using namespace std; const int M = 300010; int n, p, a[M]; long long sum, ans; int main() { while (scanf("%d", &n) != EOF) { sum = 0; for (int i = 0; i < n; i++) { scanf("%d", &a[i]); sum += a[i]; } sort(a, a + n); ans = sum; p = 0; while (p != n - 1) {...
4
#include <bits/stdc++.h> const int M = 300000 + 1; const int N = 100000 + 1; struct node { int v, L, R, id; friend bool operator<(const node& i, const node& j) { return j.R < i.R; } }; struct tnode { int addv, mx, ansid; }; node ar[N]; tnode seg[M << 2]; std::priority_queue<node> Q; void Up(tnode& fa, tnode& ls, ...
16
#include <bits/stdc++.h> using namespace std; long long n, a[1000100], ans, cnt; priority_queue<long long> q; int main() { cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; } for (int i = 1; i <= n; i++) { q.push(-a[i]); q.push(-a[i]); ans += (a[i] + q.top()); q.pop(); } cout << ans;...
16
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:60777216") using namespace std; int n, c; set<int> sl[1111111]; set<int> sr[1111111]; int LN[1111111]; int RN[1111111]; void print_tree(int pos) { if (LN[pos] != -1) print_tree(LN[pos]); printf("%d ", pos); if (RN[pos] != -1) print_tree(RN[pos]); } int STAR...
16
#include <bits/stdc++.h> using namespace std; string swap_st(string a, int y) { int x = y, z = a.length() - y - 1; int t = a[x]; a[x] = a[z]; a[z] = t; return a; } int arr[200005]; int main() { string s; cin >> s; int m; cin >> m; int n; for (int i = 0; i < m; i++) { cin >> n; arr[--n]++; ...
6
#include <bits/stdc++.h> using namespace std; const double Epsilon = 4.94065645841247E-324; const long long int mod = 1000000007; const long double pi = 3.14159265358979323846; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long i, j, k, t, n, m, ans, x, y, z, a, b, c; cin >> t; while (t--...
2
#include <bits/stdc++.h> #pragma GCC optimize "-O3" using namespace std; const int MAXN = 220000; int n, m; vector<int> eds[MAXN]; int was[MAXN]; vector<array<int, 3>> ans; int h[MAXN]; int dfs1(int v, int p) { was[v] = 1; vector<int> go; for (int u : eds[v]) { if (was[u]) { if (h[u] > h[v]) { g...
15
#include <bits/stdc++.h> using namespace std; const int MOD = 1000000007; int a[100010]; struct Mat { int a[2][2]; void clear() { memset(a, 0, sizeof(a)); } void one() { a[0][0] = a[1][1] = 1; a[0][1] = a[1][0] = 0; } Mat operator+(const Mat &b) const { Mat tmp; tmp.clear(); for (int i = 0...
15
#include <bits/stdc++.h> using namespace std; long long ways(long long n, long long num) { if (n > num) { return ((num - 1) / 2); } long long k = num - n; if (k == 0) { return (n / 2); } if (n > k) { return ((n - k + 1) / 2); } return (0); } int main() { long long n; cin >> n; if (n ==...
10
#include <bits/stdc++.h> using namespace std; char s[200000]; int main() { int i; string s; cin >> s; stack<char> st; int ans = 0; for (i = 0; i < s.size(); i++) { if (st.empty()) { st.push(s[i]); continue; } if (s[i] == st.top()) { st.pop(); ans++; } else st.pu...
4