solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> using namespace std; const long long N = 1e5 + 7; long long n, m; vector<long long> p(N); vector<long long> h(N); vector<long long> graf[N]; bool access = true; long long a[N], g[N]; void dfs(long long v, long long anc = -1) { a[v] = p[v]; long long sum = 0; for (long long to : graf[v]) {...
10
#include <bits/stdc++.h> using namespace std; vector<int> in; vector<int> de; int arr[200005] = {0}; int main(void) { int N; scanf("%d", &N); bool judge = true; for (int i = 0; i < N; i++) { int num; scanf("%d", &num); arr[num]++; if (arr[num] > 2) { judge = false; } } if (judge) {...
2
#include <bits/stdc++.h> using namespace std; const int MAXN = 300005; const long long MOD = 998244353; int n, m; int a[MAXN]; long long ans; long long f[MAXN]; long long fac[MAXN]; long long inv[MAXN]; long long power(long long a, long long b) { long long res = 1; while (b) { if (b & 1) (res *= a) %= MOD; ...
24
#include <bits/stdc++.h> using namespace std; int n, m; int a[200010], b[200010]; long long dp[200010]; const int MOD = 998244353; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); ; cin >> n >> m; for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 1; i <= m; i++) cin >> b[i]; for (...
13
#include <bits/stdc++.h> using namespace std; int main() { int a[101][101], an[101][101], m, n; cin >> m >> n; for (int i = 0; i < m; i++) for (int j = 0; j < n; j++) cin >> a[i][j]; for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) an[i][j] = 1; } for (int i = 0; i < m; i++) { for (int ...
5
#include <bits/stdc++.h> using namespace std; int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1}; int a[100001]; int q[100001]; char line[100005]; int main() { int i, j, k, n, m, res = 0, cnt = 0, mx = 0, mn = (1 << 30); scanf("%d %d %d", &n, &m, &k); for (i = 0; i < n; i++) { scanf("%d", &a[i]); if (a[i] == ...
1
#include <bits/stdc++.h> using namespace std; const int N = 1000002, mod = 1073741824; int a, b, c, ans; int mem[N]; int d(int n) { int& ret = mem[n]; if (ret) return ret; int i; for (i = 1; i < n / i; i++) { if (n % i == 0) ret += 2; } if (i * i == n) ret++; return ret % mod; } int main() { scanf("...
18
#include <bits/stdc++.h> using namespace std; int a[2005][2005]; int main() { ios::sync_with_stdio(0); cin.tie(0); int sum1 = 0, sum2 = 0; int xa, xb, ya, yb; cin >> xa >> ya >> xb >> yb; xa = xa + 1000, ya = ya + 1000, xb = xb + 1000, yb = yb + 1000; if (xa > xb) swap(xa, xb); if (ya > yb) swap(ya, yb)...
5
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; void fastio() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } int main() { fastio(); int n, m, temp; cin >> n >> m; vector<int> boys(n); vector<int> girls(m); int hb; cin >> hb; for (int i = 0; i < hb; i++)...
5
#include <bits/stdc++.h> using namespace std; long long n, h; void input() { cin >> n; } void work() { h = n / 4 + n / 4; if (n % 4 != 0) h++; } void output() { cout << n * 2 - h; } int main() { input(); work(); output(); return 0; }
1
#include <bits/stdc++.h> using namespace std; int n, m, res; string s[65]; int c[65], x[65]; void Solve(int i, int ifmatch) { if (i == n) { if (ifmatch != c[1]) return; string t; for (int j = 0; j <= n - 1; j++) { t += (char)x[j] + 48; } int Ok = 1; for (int j = 2; j <= m; j++) { i...
14
#include <bits/stdc++.h> using namespace std; int jl[200002], n, ans = 0, rd[200002], root = 0, num = 1; int dfs(int a, int b) { if (a == root || rd[a] != 0) return 0; rd[a] = b; if (rd[jl[a]] == b) { if (root == 0) root = a; jl[a] = root; return 1; } return dfs(jl[a], b); } int main() { scanf("...
9
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 10; const int maxm = 1e3 + 10; int n, l, k; char niz[maxn]; string a[maxm]; int main() { scanf("%d%d%d%s", &n, &l, &k, niz); k--; sort(niz, niz + n * l); int pos = 0; int t = 0; for (int i = 0; i < l; i++) { for (int j = t; j <= k; j++...
10
#include <bits/stdc++.h> using namespace std; int n, m, a, b; vector<pair<pair<int, int>, int> > tab; int c[100100] = {0}; int cnt[100100] = {0}; pair<int, int> ans[100100]; int Find(int x) { return (c[x] == x) ? x : Find(c[x]); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> m; for (int i ...
9
#include <bits/stdc++.h> using namespace ::std; const unsigned long long maxn = 310; const unsigned long long inf = 1e9 + 500; const unsigned long long mod = 1e9 + 7; const unsigned long long maxm = 2e4 + 500; unsigned long long a[maxn]; unsigned long long id[maxn]; vector<unsigned long long> ger[maxn]; bool npr[maxm];...
15
#include <bits/stdc++.h> using namespace std; const long long UNDEF = -1; template <typename T> inline bool chkmax(T &a, T b) { return a < b ? a = b, true : false; } template <typename T> inline bool chkmin(T &a, T b) { return a > b ? a = b, true : false; } const long long INF = 3e18; const long long MAXL = 8000 + ...
18
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; int arr[11] = {0}, arr2[11] = {0}; int c1[11] = {0}, c2[11] = {0}; vector<int> x, y; for (int e = 0; e < s.length(); e++) { arr[s[e] - 48] += 1; arr2[s[e] - 48] += 1; } int mx = -1, a1 = -1; for (int ev = 1; ev <= 9...
11
#include <bits/stdc++.h> using namespace std; char str[2001]; int main() { int n, i, len, x, y, z, xx, yy; scanf("%d%s", &n, str); len = strlen(str); z = 0; xx = yy = 0; for (i = 0; i < len; i++) { if (str[i] == 'R') xx++; else if (str[i] == 'L') yy++; } for (i = 0; i < len; i++) { ...
5
#include <bits/stdc++.h> using namespace std; const bool OnLineJudge = 1; const int N = 100005, oo = 1000 * 1000 * 1000 + 2604; long long dp[N][4][4]; char a[N]; int n, m; long long f(const int len, const int pos1, const int pos2) { if (len > n) return 1; if (dp[len][pos1][pos2] != -1) return dp[len][pos1][pos2]; ...
19
#include <bits/stdc++.h> using namespace std; string getBinary(long long x) { if (x == 0) return "0"; string ret = ""; while (x > 0) { char c = '0' + x % 2; ret += c; x /= 2; } reverse(ret.begin(), ret.end()); return ret; } string sum, xoor; long long mem[100][2]; bool vis[100][2]; long long sol...
9
#include <bits/stdc++.h> using namespace std; template <class T> bool smin(T &_x, T &_y) { return _x <= _y ? false : ((_x = _y), true); } template <class T> bool smax(T &_x, T &_y) { return _x >= _y ? false : ((_x = _y), true); } const int maxn = 1e5 + 5; const int inf = 1e9; const int mod = 1e9 + 7; int n; int mai...
0
#include <bits/stdc++.h> using namespace std; long long qpow(long long a, long long b, long long p) { long long ans = 1; while (b) { if (b & 1) ans = ans * a % p; a = a * a % p; b >>= 1; } return ans; } const int maxn = 2e3 + 10; int a[maxn], b[maxn]; int mod = 998244353; int f[2][maxn][12], g[2][ma...
16
#include <bits/stdc++.h> using namespace std; const int mx = 2e5 + 10; int ar[mx]; vector<int> vec[7][2]; int leap(int m) { if (m % 400 == 0) return 1; else if (m % 100 and m % 4 == 0) return 1; return 0; } int main() { ar[1000] = 1; vec[ar[1000]][leap(1000)].push_back(1000); for (int i = 1001; i < ...
8
#include <bits/stdc++.h> using namespace std; string to_string(string s) { return '"' + s + '"'; } string to_string(const char *s) { return to_string((string)s); } string to_string(bool b) { return (b ? "true" : "false"); } template <typename A, typename B> string to_string(pair<A, B> p) { return "(" + to_string(p.fi...
27
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 23; int n, m; char s[maxn]; int a[maxn]; class SegTree { private: vector<int> tag, mn, mx; vector<unsigned long long> st; int n; public: void pushup(int o) { st[o] = st[o << 1] + st[o << 1 | 1]; mx[o] = max(mx[o << 1], mx[o << 1 | 1...
16
#include <bits/stdc++.h> using namespace std; vector<vector<int> > v(5, vector<int>(5, 0)); bool Is(int a, int b, int c) { return (v[a][b] == 1 && v[a][c] == 1 && v[b][c] == 1) || (v[a][b] == 0 && v[a][c] == 0 && v[b][c] == 0); } int main() { int n, a, b; scanf("%d", &n); for (int i = 0; i < n; i++) { ...
5
#include <bits/stdc++.h> using namespace std; int main() { string str[3]; for (int i = 0; i < 3; i++) { cin >> str[i]; } for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { if (str[i][j] != str[2 - i][2 - j]) { cout << "NO"; return 0; } } } cout << "YES"; }
0
#include <bits/stdc++.h> int T; int n; int m, sz[2005], dp[2005]; int main() { scanf("%d", &T); while (T--) { scanf("%d", &n); m = 0; for (int i = 1, mx = 0, tmp = 0; i <= (n << 1) + 1; i++, tmp++) { int a; if (i <= (n << 1)) scanf("%d", &a); else a = i; if (a > m...
10
#include <bits/stdc++.h> using namespace std; int a[110]; int main() { int n; scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); } int ans = 0; for (int i = 1; i <= n; i++) { for (int j = i; j <= n; j++) { int tmp = a[i]; for (int k = i + 1; k <= j; k++) tmp ^= a[k]; ...
3
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; const long long INF = 1e18; const string nl = "\n"; vector<long long> hld, hld1((long long)5e6 + 10); vector<bool> prime((long long)5e6 + 10, true); void solve() { long long a, b; cin >> a >> b; cout << hld1[a] - hld1[b] << nl; } int32_t...
9
#include <bits/stdc++.h> int main() { int n, i, j, k, m; long long int s = 0; scanf("%d %d", &n, &m); for (i = 1; i <= n; i++) { s = s + ((m + i) / 5 - i / 5); } printf("%lld", s); return 0; }
3
#include <bits/stdc++.h> using namespace std; int main() { double n, R, r; cin >> n >> R >> r; if (n == 1 && R >= r) cout << "YES" << endl; else { double ang = asin(r / (R - r)) * n; if (ang <= 3.1415927) cout << "YES" << endl; else cout << "NO" << endl; } return 0; }
9
#include <bits/stdc++.h> using namespace std; struct rd { int next, to; } road[400010]; char a[200010]; int head[200010], n, size[200010], Max[200010], root, t[1 << 20], s[200010], d[200010], tot, sum, X; long long ans[200010]; bool flag[200010]; vector<int> son, F, G; inline void addedge(int x, int y) { road[+...
16
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; const long long INF = 1e18; const double EPS = 1e-6; const int MAX_N = 1005; int n, m; string answers[MAX_N]; int points[MAX_N]; int freq[5]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> m; for (int i = 0; i < n; ++i) {...
1
#include <bits/stdc++.h> using namespace std; template <typename Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << ": " << arg1 << endl; } template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args) { const char* comma = strchr(names + 1, ','); cerr.write(name...
8
#include <bits/stdc++.h> using namespace std; int main() { int n, x, i, r, d, cnt = 0, s = 1; cin >> n >> x; for (i = 0; i < n; i++) { cin >> r >> d; r = s + ((r - s) / x) * x; cnt += (d - r + 1); s = d + 1; } cout << cnt << endl; return 0; }
2
#include <bits/stdc++.h> using namespace std; long long mod = 1e9 + 7; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int TESTS = 1; while (TESTS--) { long long n; cin >> n; vector<long long int> a(n); set<pair<long long, long long>> sc[3]; for (long long int i = 0...
11
#include <bits/stdc++.h> using namespace std; const int N = 100005; int a[N], L[N], R[N], bel[N]; long long s[N]; pair<long long, long long> ans, f[2000], g[2000]; void brute_force(int l, int r) { for (int j = l; j <= r; j++) { if (a[j] < 0) { int t = -a[j]; ans.second += t; ans.first = max(0ll,...
14
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf("%d", &n); cout << (6 * n * (n - 1)) + 1; return 0; }
5
#include <bits/stdc++.h> using namespace std; using ll = long long; using db = double; using pll = pair<ll, ll>; const int MOD = 1e9 + 7, INF = INT_MAX, N = 1e5 + 10; int main() { ll n, m; cin >> n >> m; ll t[n]; for (ll i = 0; i < n; i++) { cin >> t[i]; } for (ll i = 0; i < n; i++) { multiset<ll, g...
4
#include <bits/stdc++.h> using namespace std; const int MX = 2048, BS = 1 << 16, MOD = 1e9 + 7; int n, k, a[16], b[16]; bitset<MX> dp[BS]; void reverseDP(int bs, int x) { if (x != 0 && x * k < MX && dp[bs][x * k]) { reverseDP(bs, x * k); for (int i = int(0); i < int(n); i++) if (bs & (1 << i)) { ...
23
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; long long ans = 0; long long cur2 = 1; for (int i = 1; i < s.size(); ++i) { cur2 <<= 1; cur2 %= 1000000007; } for (int i = 0; i < s.size(); ++i) { if (s[s.size() - i - 1] == '1') ans += cur2; cur2 <<= 1; cur...
8
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; int n, t; cin >> n; int size = s.size(); vector<int> v(size + 1); while (n--) { cin >> t; v[t - 1]++; v[size - t]--; } for (int j = 1; j < size; j++) v[j] += v[j - 1]; int m = size - 1; for (int i = 0; i < m...
6
#include <bits/stdc++.h> using namespace std; int main() { string s1, sn; int cd = 1, in = 1, i, j, n; scanf("%d", &n); for (i = 1; i < n; i++) { cd += in; if (cd > n) cd = cd - n; printf("%d ", cd); in++; } return 0; }
0
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int nn = (1 << n + 1) - 1; int ans = 0; vector<int> a(nn + 1); for (int i = 2; i <= nn; ++i) cin >> a[i]; for (int i = (1 << n) - 1; i >= 1; --i) { if (a[2 * i] != a[2 * i + 1]) ans += abs(a[2 * i] - a[2 * i + 1]); a[i] +=...
6
#include <bits/stdc++.h> using namespace std; const int MN = 1e6 + 7; void slv() { int n; cin >> n; int a[n]; { for (int i = 0; i < n; i++) cin >> a[i]; }; int po[n]; for (int i = 0; i < n; i++) a[i]--, po[a[i]] = i; int z = 0; for (int i = 0; i < n; i++) { if (i < z) continue; for (int j ...
7
#include <bits/stdc++.h> using namespace std; inline int getint() { int c, l = 0, x; for (; !isdigit(c = getchar()); l = c) if (c == EOF) return 1 << 31; for (x = c - '0'; isdigit(c = getchar()); x = x * 10 + c - '0') if (c == EOF) break; return l == '-' ? -x : x; } const int N = 223456; struct data { ...
15
#include <bits/stdc++.h> using namespace std; int n; vector<int> v[3000]; vector<int> sol[3]; int main() { cin >> n; for (int i = 1; i <= n; i++) { int h; cin >> h; v[h].push_back(i); } int num2 = 0, num3 = 0; for (int i = 1; i <= 2000; i++) { vector<int> &w = v[i]; if (int(w.size()) > 0) ...
5
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; long long binPow(long long a, long long b) { long long x = 1, y = a; while (b) { if (b & 1) x = (x * y) % mod; y = (y * y) % mod; b >>= 1; } return x % mod; } long long inverserEuler(int n) { return binPow(n, mod - 2); } long lon...
4
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(NULL); int n, k; cin >> n >> k; vector<vector<int> > A(n, vector<int>(n)); for (int i = 0; i < n; i++) { for (int jj = i + 1; jj <= i + k; jj++) { int j = jj % n; if (A[j][i] == 1 || i == j) { ...
6
#include <bits/stdc++.h> using namespace std; const int nn = 258; const int MOD = 1e9 + 7; const int BASE = 257; char s[nn][nn]; int v[nn]; long long t[nn]; long long power[nn]; long long res; int n, m; void manacher(const vector<int> &k) { int p = k.size() * 2 - 1; vector<int> f(p, 0); vector<int> a(p, -8); fo...
16
#include <bits/stdc++.h> using namespace std; int main() { int n, a; vector<int> v; scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d", &a); v.push_back(a); } sort(v.begin(), v.end()); int cnt = 0; int k = 1; for (int i = 0; i < v.size();) { if (v[i] >= k) { cnt = cnt + 1; ...
2
#include <bits/stdc++.h> using namespace std; void bf(char c) { for (int i = 1; i <= c; ++i) putchar('+'); printf(".>\n"); } template <typename T> void write(T x) { if (x < 0) putchar('-'), write(-x); if (x > 9) write(x / 10); bf(x % 10 + '0'); } string s; int main() { cin >> s; int val = 0, ans = 0, sgn ...
12
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); int n; cin >> n; int x, count[101] = {0}; for (int i = 1; i <= n; i++) { cin >> x; count[x] += 1; } int total = 0; for (int i = 1; i <= 100; i++) { total = total + count[i] / 2; } cout << total /...
2
#include <bits/stdc++.h> using namespace std; int sieve[31623 + 5]; vector<long long int> prime; void ComputeSieve() { memset(sieve, 0, sizeof sieve); for (long long int a = 2; a <= 31623; a++) { if (sieve[a]) continue; prime.push_back(a); for (long long int b = a * a; b <= 31623; b += a) { sieve[...
6
#include <bits/stdc++.h> using namespace std; int x[5], y[5], xx, yy, i, j, n; int main() { cin.sync_with_stdio(false); cout.sync_with_stdio(false); cin >> n; if (n == 1) { cout << -1; return 0; } for (i = 1; i <= n; i++) cin >> x[i] >> y[i]; for (i = 1; i <= n; i++) for (j = i + 1; j <= n; j+...
3
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") const long long INF = 1e9 + 7; const long long maxn = 2e5 + 7; using namespace std; void solve() { long long n; cin >> n; vector<long long> a(n); vector<long long> t(n); for (long long i = 0; i < n; i++) { cin >> a[i]; } for (long long i = 0; i < ...
9
#include <bits/stdc++.h> using namespace std; long long int min(long long int a, long long int b) { return (a < b) ? a : b; } int main() { long long int n; int len = 0; cin >> n; while (n != 0) { if (n % 10 == 4) { if ((n % 100) / 10 == 4) { if ((n % 1000) / 100 == 1) n = n / 1000; ...
1
#include <bits/stdc++.h> using namespace std; const int N = 4005, mo = 1e9 + 7; int n, nn, m, i, j, v, ans; char s[N], sa[N], a[N]; void fz() { for (i = n >> 1; i; i--) { swap(s[i], s[n + 1 - i]); swap(s[n + i], s[2 * n + 1 - i]); } } void add(int &x, int k) { x += k; if (x >= mo) x -= mo; } const int B...
24
#include <bits/stdc++.h> using namespace std; int x[100], y[100]; int n; int main() { scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%d%d", &x[i], &y[i]); for (int i = 0; i < n; i++) for (int j = i + 1; j < n; j++) if (x[i] + y[i] == x[j] && x[j] + y[j] == x[i]) { printf("YES\n"); r...
2
#include <bits/stdc++.h> using namespace std; #pragma warning(disable : 4996) #pragma comment(linker, "/STACK:16777216") #pragma warning(disable : 4996) #pragma comment(linker, "/STACK:16777216") #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") const int inf = 2000000000; const long long linf = 50000000...
10
#include <bits/stdc++.h> using namespace std; const int N = 130000; int head[N]; bool vis[N] = {false}; int dis[N]; int s, mx, cnt, sum; bool belong[N] = {false}; struct edge { int to, next; } edge[2 * N]; void add_edge(int u, int v) { edge[cnt].to = v; edge[cnt].next = head[u]; head[u] = cnt++; } void dfs(int ...
14
#include <bits/stdc++.h> using namespace std; const int N = 400005; int n, k, m, x, y, a[N], K; map<pair<int, int>, int> s; struct note { int s, mx; friend note operator+(note x, note y) { return {x.s + y.s, std::max(y.mx, x.mx + y.s)}; } }; struct SGT { note t[N << 2]; void modify(int k, int L, int R, in...
18
#include <bits/stdc++.h> using namespace std; const int B = 27397, MOD = 1e9 + 7; const int B1 = 33941, MOD1 = 1e9 + 9; int q, r, s, k; int memo_cnt[32][2][2][2], memo_sum[32][2][2][2]; inline int add(int a, int b) { a += b; while (a < 0) a += MOD; return a % MOD; } inline int mul(const int &a, const int &b) { re...
18
#include <bits/stdc++.h> const double PI = 3.14159265358979323846264338327950288419716939937510582097494459230; const long long int MOD = 1e9 + 7; using namespace std; long long int prime(long long int n) { if (n % 2 == 0 && n != 2 || n < 2) return false; else { for (long long int i = 3; i * i <= n; i +...
3
#include <bits/stdc++.h> using namespace std; const int INF = (int)2e+9; const int MAX_N = 2e5 + 7; long long maxl(long long a, long long b) { if (a > b) return a; return b; } int main() { long long a, b, c; cin >> a >> b >> c; if (a >= c || b >= c) { cout << 0; return 0; } if (a <= 0 && b <= 0) {...
8
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int p = 0, ne = 0; int x, y; for (int i = 0; i < n; i++) { cin >> x >> y; if (x > 0) p++; else ne++; } if (min(p, ne) > 1) cout << "NO"; else cout << "YES"; return 0; }
0
#include <bits/stdc++.h> using namespace std; pair<int, int> operator-(const pair<int, int>& lhs, const pair<int, int>& rhs) { return pair<int, int>(lhs.first - rhs.first, lhs.second - rhs.second); } int operator*(const pair<int, int>& lhs, const pair<int, int>& rhs) { return lhs.first * rhs.second - rhs.first * lh...
8
#include <bits/stdc++.h> using namespace std; string s; int n; int main() { cin >> n; cin.ignore(); getline(cin, s); int _m = 0; int dem = 0; for (int i = 0; i < s.size(); i++) { if (s[i + 1] == ' ' || s[i + 1] == '\0') { if ('A' <= s[i] and s[i] <= 'Z') { dem++; } _m = max(_m,...
0
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const int MAX_N = 100005; int a[MAX_N], b[MAX_N]; int n, m; int dp[MAX_N], pos[MAX_N]; bool used[MAX_N]; vector<int> g[MAX_N]; int main() { cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; cin >> m; for (int i = 0; i < m; i++) cin >> b[...
22
#include <bits/stdc++.h> using namespace std; void lol() {} void solve() { int n; cin >> n; vector<int> a(n); for (auto& x : a) cin >> x; sort(a.begin(), a.end()); int ans = 0; int want = 0, have = 0; for (int i = 0; i < n; i++) { if (have > 0 && want == have) { have = want = 0; ++ans; ...
4
#include <bits/stdc++.h> int main(void) { int n, k; int p = 0; scanf("%i %i", &n, &k); for (int i = 0; i < n; i++) { int q; scanf("%i", &q); if (5 - q >= k) p++; } printf("%i\n", p / 3); return 0; }
0
#include <bits/stdc++.h> using namespace std; vector<pair<int, int> > ans; void print() { cout << ans.size() << endl; for (int i = 0; i < ans.size(); i++) { cout << ans[i].second << " " << ans[i].first << endl; } } void minswap(int a[], int n) { vector<pair<int, int> > v; for (int i = 0; i < n; i++) { ...
4
#include <bits/stdc++.h> using namespace std; int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long int n, ans = INT_MAX, idx1, idx2; cin >> n; long long int a[n + 1]; for (long long int i = 0; i < n; i++) cin >> a[i]; a[n] = a[0]; for (long long int i = 0; i < n + 1; i++) ...
0
#include <iostream> #include <vector> using namespace std; int main(){ int i, t, x, y; cin >> t; for(i = 0; i < t; i++) { cin >> x >> y; if(x != y) { cout << max(x, y) * 2 - 1 << endl; } else { cout << x * 2 << endl; } ...
0
#include <bits/stdc++.h> using namespace std; int a[5000]; int main() { int i, n, m, ans = 0, x, y; scanf("%d%d", &n, &m); for (i = 1; i <= n; i++) scanf("%d", a + i); while (m--) { scanf("%d%d", &x, &y); ans += min(a[x], a[y]); } printf("%d\n", ans); return 0; }
6
#include <bits/stdc++.h> using namespace std; void solve() { int n, m, k; cin >> n >> m >> k; vector<vector<char>> given(n, vector<char>(m)); vector<vector<char>> obtained(n, vector<char>(m, '.')); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { cin >> given[i][j]; } } for (int i...
7
#include <bits/stdc++.h> using namespace std; int main() { int n, l, r, k, p = 1, j; cin >> n; int a[n][2]; for (int i = 0; i < n; i++) { for (int j = 0; j < 2; j++) { cin >> a[i][j]; } } cin >> k; for (int i = 0; i < n; i++) { if (k - 1 >= a[i][0] && k - 1 < a[i][1] && a[i][0] != a[i][1...
0
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1.0); const int INF = 0x3f3f3f3f; const double eps = 1e-8; const int MAXN = 2e3 + 10; const int MOD = 998244353; const int dir[][2] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}}; const int seed = 131; int cases = 0; pair<int, int> p[MAXN]; vector<double> arr;...
11
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") using namespace std; using ll = long long; using ld = long double; using vi = vector<ll>; using vvi = vector<vi>; const ll mod = 998244353; const int maxn = 2e5 + 33; mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().c...
12
#include <bits/stdc++.h> using namespace std; int const inf = 1000 * 1000 * 1000; long long const inf64 = 1ll * inf * inf; int const L = 1e5 + 5; char buffer[L]; inline void readLine(string& s) { scanf("%s", buffer); s = buffer; } string good; int mask_good; set<char> GOOD; inline bool isGood(char x) { return GOOD....
8
#include <bits/stdc++.h> using namespace std; long long int gcd(long long int a, long long int b) { return (b == 0LL ? a : gcd(b, a % b)); } long double dist(long double x, long double arayikhalatyan, long double x2, long double y2) { return sqrt((x - x2) * (x - x2) + (arayikhalatyan ...
25
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); long long t; cin >> t; for (long long(h) = (0); (h) < (long long)t; (h)++) { long long n; cin >> n; vector<long long> a(n); for (long long(i) = (0); (i) < (long long)n; (i)++) { long long q; cin >> q;...
6
#include <bits/stdc++.h> using namespace std; const int N = 300010; int n, arr[N], nxt[N]; long long dp[N], ans = 0; int comp[N], comp_cnt = 0; set<pair<int, int> > st[N]; set<pair<int, int> >::iterator it; void solve() { scanf("%d", &n); comp_cnt = 0; for (int i = 0; i < n; i++) { st[i].clear(); scanf("%...
18
#include <bits/stdc++.h> int kadane(std::vector<int> a) { int sum = 0, mn = 0, ans = 0; for (auto v : a) { sum += v; ans = std::max(ans, sum - mn); mn = std::min(mn, sum); } return ans; } const int ms = 500500; std::vector<int> p[ms]; int sum[ms]; int solve(std::vector<int> pos) { std::vector<int>...
12
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #pragma GCC target("sse2") using namespace std; int n, q, aa[300005], bb[300006], m; vector<int> a(1000005), lazy(4 * 1000005); vector<int> seg(4 * 1000005); void build(int cur, int st, int end) { if (st == end) { seg[cur]...
14
#include <bits/stdc++.h> using namespace std; inline int L(int i) { return i << 1; } inline int R(int i) { return (i << 1) | 1; } inline int B(int i) { return 1 << i; } inline int low_bit(int x) { return x & (-x); } struct shoe { int s, c, i; } cus, pro[100010]; int cmp_s(shoe a, shoe b) { return a.s < b.s; } int cmp...
17
#include <bits/stdc++.h> using namespace std; const int NIL = -1; template <class T> inline T mx(T a, T b) { return a > b ? a : b; } template <class T> inline T mi(T a, T b) { return a < b ? a : b; } template <class T> inline void sw(T &a, T &b) { T t = a; a = b; b = t; } template <class T> inline T mabs(T x)...
12
#include <bits/stdc++.h> using namespace std; int main() { int n, k, in, f = 0; vector<int> a, c; vector<pair<int, int> > b; cin >> n >> k; cin >> in; a.push_back(in); for (int i = 1; i != n; i++) { cin >> in; a.push_back(in); b.push_back({in - a[i - 1], i - 1}); f++; } sort(b.begin(),...
6
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e5 + 10; int n, m, k; vector<pair<int, int> > v[MAXN]; int te = 0; class Edges { public: int next, to; int v; }; int deg[MAXN]; int first[MAXN]; Edges edge[MAXN]; bool flag[101][101]; int Getpos(int pos, int h) { return (pos - 1) * 10 + h; } void add(...
15
#include <bits/stdc++.h> using namespace std; int n, q, a[200005], w[200005], t1[200005]; long long t[200005]; inline int read() { int x = 0, f = 1; char ch = getchar(); for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1; for (; isdigit(ch); ch = getchar()) x = (x + (x << 2) << 1) + (ch ^ 48); ret...
17
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); string s; cin >> s; int t[s.size()]; int l, r; l = 0; r = s.size() - 1; for (int i = 0; i < s.size(); i++) { if (s[i] == 'l') t[r--] = i + 1; else t[l++] = i + 1; } for (int i =...
4
#include <bits/stdc++.h> using namespace std; const int N = 200002; const int M = N << 1; int n, q; int cnt, head[N], Next[M], vv[M]; int c[M]; int tot; void ADD(int x, int v) { for (; x <= n + q; x += x & (-x)) c[x] += v; } int QRY(int x) { int ans = 0; for (; x; x ^= x & (-x)) ans += c[x]; return ans; } names...
26
#include <bits/stdc++.h> using namespace std; int n, m, dfn[100009], stamp; vector<int> edge[100009]; int Dfs(int u, int fa) { int pre = -1; dfn[u] = ++stamp; for (int i = 0; i < (edge[u].size()); i++) { int v = edge[u][i]; if (v == fa) continue; if (dfn[v] == -1) { int next = Dfs(v, u); i...
15
#include <bits/stdc++.h> using namespace std; int arr[1000005]; int main() { ios_base::sync_with_stdio(0); int t, i, j; int n, k; cin >> n >> k; if (k == 1) { cout << "-1"; return 0; } if (3 * k > n) { cout << "-1"; return 0; } int nmbr = n / k; int xtra = n % k; vector<int> myvec[...
7
#include <bits/stdc++.h> using namespace std; constexpr int MAXN = 100005; constexpr int MAXK = 9; struct EVENT { long long x, type, id; EVENT(int a = 0, int b = 0, int c = 0) : x(a), type(b), id(c){}; bool operator<(const EVENT& other) const { return x < other.x || (x == other.x && type < other.type); } };...
17
#include <bits/stdc++.h> using namespace std; set<pair<int, int> > Set; set<pair<int, int> >::iterator iter; pair<int, int> k; int a, p[250001], n, i, ans; int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n; for (i = 1; i <= n; i++) { cin >> a; p[a] = i; } for (i = 0; i <= 200000; i++) i...
2
#include <bits/stdc++.h> using namespace std; const int N = 21; int n, m, k; int ls; bool vis[N]; vector<pair<int, int> > e[N]; void dfs(int u, int sum, int x) { if (u > n) { ls++; return; } if (ls >= k) { return; } dfs(u + 1, sum, x); for (int i = 0; i < (int)e[u].size(); ++i) { int w = e[u...
10
#include <bits/stdc++.h> using namespace std; using lol = long long int; const lol mod1 = 1e9 + 7; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, m; cin >> n >> m; if (n >= 4 && m >= 4) { cout << "-1"; return 0; } if (n == 1 || m == 1) { cout << "0"; return 0; } v...
12
#include <bits/stdc++.h> using namespace std; using ll = long long; ll Gcd(ll a, ll b) { while (b) { a %= b; swap(a, b); } return a; } int main() { ll t, tst = 0; cin >> t; while (t--) { ll n; cin >> n; ll a[n]; for (ll i = 0; i < n; i++) cin >> a[i]; sort(a, a + n, greater<ll>()...
5