solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> using namespace std; const int mn = 6, mm = 41; int mem[1 << mn][1 << mn][mm][mn + 1]; int m, n; int go(int last, int cur, int i, int j) { if (i == m) return 0; int& ret = mem[last][cur][i][j]; if (ret != -1) return ret; if (j == n) return ret = go(cur, last, i + 1, 0); if ((((cur) >>...
13
#include <bits/stdc++.h> using namespace std; const long long N = 3e5 + 5; signed main() { long long n, ans = 1; cin >> n; for (long long i = 1; i < n; i++) { ans += (i * 4); } cout << ans; }
0
#include <bits/stdc++.h> using namespace std; int main() { int x[4], y[4]; for (int i = 0; i < 3; i++) scanf("%d%d", &x[i], &y[i]); printf("3\n"); for (int i = 0; i < 3; i++) { int nx = x[i], ny = y[i]; int tx = x[(i + 1) % 3] - x[(i + 2) % 3]; int ty = y[(i + 1) % 3] - y[(i + 2) % 3]; printf("%...
4
#include <bits/stdc++.h> using namespace std; const int MAX = 210000; const int INF = 1000000000; const long long MOD = 1000000007; long long mod(long long a, long long b, long long m) { long long ret = 1; a %= m; while (b) { if (b & 1) ret = ret * a % m; b >>= 1; a = a * a % m; } return ret; } lo...
18
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; int main() { int n, k, L; cin >> n >> k >> L; map<int, int> sex, sey; vector<int> cx, cy; int ar[n][3]; for (int a = 0; a < n; a++) { cin >> ar[a][0] >> ar[a][1] >> ar[a][2]; ar[a][2]--; sex[ar[a][0]] = 0, sey[ar[a][1]] = 0; ...
25
#include <bits/stdc++.h> using namespace std; long long power(long long a, long long n) { long long p = 1; while (n > 0) { if (n % 2) { p = p * a; } n >>= 1; a *= a; } return p; } long long power(long long a, long long n, long long mod) { long long p = 1; while (n > 0) { if (n % 2)...
6
#include <bits/stdc++.h> #pragma GCC optimize("O3") #pragma GCC optimize("Ofast,no-stack-protector") using namespace std; void err(istream_iterator<string> it) {} template <typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cerr << *it << " = " << a << "\n"; err(++it, args...);...
23
#include <bits/stdc++.h> using namespace std; long long n; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n; cout << (long long)pow(2, n + 1) - 2 << '\n'; }
3
#include <bits/stdc++.h> using namespace std; long long T, n, m, cnt, num[200100], ri[200100], qz[200100]; vector<long long> ans; inline void work(long long u) { num[u] = num[u + 1] = num[u + 2] = (num[u] ^ num[u + 1] ^ num[u + 2]); ans.push_back(u); } inline void work(long long u, long long v) { long long i, j, ...
17
#include <bits/stdc++.h> using namespace std; bool cmp(int a, int b) { return a > b; } int a[100010]; int vis[100010]; int main() { int q; scanf("%d", &q); while (q--) { int n, r; scanf("%d%d", &n, &r); int b = 0; for (int i = 0; i < n; i++) { int x; scanf("%d", &x); if (vis[x] =...
5
#include <bits/stdc++.h> using namespace std; const double eps = 1e-9; const int mod = 1e9 + 7; int n, m, ans; inline int sgn(double x) { return (x > eps) - (x < -eps); } struct Point { double x, y; Point() {} Point(double x, double y) : x(x), y(y) {} Point operator+(Point p) const { return Point(x + p.x, y + p...
22
#include <bits/stdc++.h> using namespace std; long long n, m, tot; long long x = 0; string s; int main() { cin >> s; long long punct = 0, lng = 0, arond = 0, nxt = 0, lngpunct = 0; long long tip1 = 0, tip2 = 0, tip3 = 0; for (int i = s.size() - 1; i >= 0; i--) { if (s[i] == '.') { punct = i; lng...
11
#include <bits/stdc++.h> using namespace std; const int maxn = 20; char s[maxn]; int cnt, len; int main() { scanf("%s", s + 1); int l = 1, r = strlen(s + 1); len = r; while (l <= r) { if (s[l] == s[r]) l++, r--; else cnt++, l++, r--; } if (cnt > 1) puts("NO"); else if (cnt == 0) { ...
2
#include <bits/stdc++.h> using namespace std; const int N = 4005; int n, res, last; int a[N], dp[N][N]; int main() { cin >> n; for (int i = 1; i <= n; i++) scanf("%d", &a[i]); res = (n > 1) ? 2 : 1; for (int i = 2; i <= n; i++) for (int j = 1; j < i; j++) dp[i][j] = 2; for (int i = 2; i <= n; i++) { l...
7
#include <bits/stdc++.h> using namespace std; const int maxn = 100005, maxk = 25; int n, k, a[maxn], cnt[maxn], l, r; long long dp[maxk][maxn], cost; inline void upd(int ql, int qr) { while (r <= qr) { cost += cnt[a[++r]]; cnt[a[r]]++; } while (r > qr) { cost -= cnt[a[r]] - 1; cnt[a[r--]]--; } ...
17
#include <bits/stdc++.h> using namespace std; long long t, n, po[40]; int main() { ios::sync_with_stdio(false); cin >> t; po[0] = 1; for (int i = 1; i < 35; i++) po[i] = po[i - 1] * 2; while (t--) { cin >> n; long long ans = (n * (n + 1)) / 2; int i = 0; while (po[i] <= n) { ans -= (2 * ...
1
#include <bits/stdc++.h> using namespace std; char str[10]; vector<string> v; int main() { v.push_back("00:00"); v.push_back("01:10"); v.push_back("02:20"); v.push_back("03:30"); v.push_back("04:40"); v.push_back("05:50"); v.push_back("10:01"); v.push_back("11:11"); v.push_back("12:21"); v.push_back...
2
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:108777216") using namespace std; using ll = long long; using ull = unsigned long long; using ld = long double; template <typename T> using pair2 = pair<T, T>; template <typename T, typename U> static void amin(T &x, U y) { if (y < x) x = y; } template <typename...
7
#include <bits/stdc++.h> #pragma GCC target("avx") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") using namespace std; using ll = long long; using ld = long double; constexpr long long mod = 1e9 + 7; constexpr long long Mod = 998244353; constexpr long long MXN = 500000 + 100; constexpr ld EPS = 1e-10; ...
13
#include <bits/stdc++.h> clock_t time_p = clock(); using namespace std; const int N = 2e5 + 1, mod = 1e9 + 7; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int tc; cin >> tc; while (tc--) { int k; cin >> k; long long int p[7]; for (int i = 0; i < 7; i++) cin >> p[i]; long long int...
7
#include <bits/stdc++.h> using namespace std; const int Maxn = 1001, Inf = 100000000; int best[Maxn][Maxn]; pair<int, int> p[Maxn][Maxn]; string a, b; int getBest(int i, int j) { if (i < 0 || j < 0) return Inf; if (best[i][j] == -1) { int tmp; best[i][j] = getBest(i - 1, j) + 1; p[i][j] = make_pair(i - ...
13
#include <bits/stdc++.h> using namespace std; template <class c> struct rge { c b, e; }; template <class c> rge<c> range(c i, c j) { return rge<c>{i, j}; } template <class c> auto dud(c* x) -> decltype(cerr << *x, 0); template <class c> char dud(...); struct debug { template <class c> debug& operator<<(const c&...
13
#include <bits/stdc++.h> using namespace std; const int LIMIT = 1e5 + 7; const int LIMIT_H = 2e9 + 7; int n, p; vector<int> g[LIMIT]; vector<long long> bulbs; long long dfs(int v) { long long counter = g[v].size() > 0 ? 0 : 1; for (int i = 0; i < g[v].size(); i++) { counter += dfs(g[v][i]); } bulbs.push_bac...
8
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1); const int inf = 0x3f3f3f3f; const long long inff = 0x3f3f3f3f3f3f3f3f; int t; int s; int cnt[1000010]; int cnt2[1000010]; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> t; int mx = 0; int a, b; for (int i ...
15
#include <bits/stdc++.h> #pragma GCC optimize("O2,Ofast,inline,unroll-all-loops,-ffast-math") #pragma GCC target("popcnt") using namespace std; struct point { int x, y; } ps[1010]; struct line { int x, l, r; line(int _x = 0, int _l = 0, int _r = 0) { x = _x, l = _l, r = _r; } }; int match[2][1010], n; bool mark[2...
19
#include <bits/stdc++.h> using namespace std; int main() { string s; int k; cin >> s >> k; for (int i = 0; i < s.size(); i++) { if (s[i] == '9') continue; char mx = -1; int imx = -1; for (int j = i + 1; j < s.size() && k; j++) { if (s[j] > s[i]) { if (mx < s[j]) { if (k >...
6
#include <bits/stdc++.h> using namespace std; int a[3]; int main() { for (int i = 0; i < 3; i++) scanf("%d", a + i); sort(a, a + 3); int k; scanf("%d", &k); long long ans = 0; if (a[1] - a[0] <= k) { ans += k - (a[1] - a[0]); } if (a[2] - a[1] <= k) { ans += k - (a[2] - a[1]); } cout << ans ...
0
#include <bits/stdc++.h> const double PI = acos(-1.0); const double e = exp(1.0); template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; } template <class T> T lcm(T a, T b) { return a / gcd(a, b) * b; } using namespace std; const int N = 1000005; const int MAXN = 100100; int n, m; int a[MAXN]; char s[M...
8
#include <bits/stdc++.h> using namespace std; int a[1000000], s[1000000], tp; int main() { int n, t, tmp; scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%d", a + i); scanf("%d", &t); while (t--) { scanf("%d", &tmp); a[tmp - 1] *= -1; } for (int i = n - 1; i >= 0; i--) { if (tp && a[i] > 0...
13
#include <bits/stdc++.h> using namespace std; struct nes { long long x, y, t; double p; }; nes a[100005]; long double dp[100005]; bool cmp(nes a, nes b) { return a.t < b.t; } long long s(long long x) { return x * x; } int main() { cout.precision(15); cout << fixed; long long n; long double sol = 0; cin >>...
10
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int sum = 0, v; int k = n; int count = 0; while (k--) { cin >> v; sum += v; } for (int i = 1; i <= 5; i++) if ((sum + i) % (n + 1) != 1) count++; cout << count << endl; }
2
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int n, b, a; cin >> n >> b >> a; vector<int> s(n); for (int i = 0; i < n; ++i) cin >> s[i]; int max_i = 0; int ca = a; for (int i = 0; i < n; ++i) { if (!ca && !b) break; ...
7
#include <bits/stdc++.h> using namespace std; int f(int n) { int ans = 1; while (n != 0) { int dig = n % 10; if (dig != 0) ans *= dig; n /= 10; } return ans; } int g[1000007]; int ctr[10][1000007]; int main() { for (int i = 1; i <= 9; i++) g[i] = i; for (int i = 10; i <= 1000001; i++) { int ...
5
/* 2013-08-10 20:15:14.803580 */#include <iostream> #include <sstream> #include <cstdio> #include <cstring> #include <string> #include <cstdlib> #include <cmath> #include <cctype> #include <ctime> #include <algorithm> #include <iomanip> #include <vector> #include <queue> #include <map> #include <set> #include <cassert>...
12
#include <bits/stdc++.h> using namespace std; int32_t main() { long long t; cin >> t; while (t--) { long long a, k; cin >> a >> k; long long ans = INT_MAX; for (long long i = 1; i <= min(k, (long long)sqrt(a)); i++) { if (a % i == 0) { ans = min(ans, a / i); if ((a / i) <= k)...
5
#include <bits/stdc++.h> using namespace std; int main() { int n, a, t = 0; long long ans = 0; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", &a); t += a; if (a == 0) ans += t; } cout << ans << endl; return 0; }
8
#include <bits/stdc++.h> using namespace std; int main() { long long n, m; while (cin >> n >> m) { long long res = (m + n) / 3; res = min(res, min(n, m)); cout << res << endl; } return 0; }
5
#include <bits/stdc++.h> using namespace std; const int maxn = 3e5; const int base = 1e9 + 7; const int big = 2e9 + 100; struct line { int x, l, r, u; }; bool cmp(const line &i, const line &j) { return i.x > j.x; } int n, m, k, s; line a[maxn]; vector<pair<int, int> > ed[maxn * 4]; int tr[maxn * 4]; void add(int x, i...
19
#include <bits/stdc++.h> using namespace std; namespace from_ecnerwala { template <int MOD_> struct modnum { static constexpr int MOD = MOD_; static_assert(MOD_ > 0, "MOD must be positive"); private: using ll = long long; int v; static int minv(int a, int m) { a %= m; assert(a); return a == 1 ? ...
11
#include <bits/stdc++.h> using namespace std; const int N = 100008; bool prime[N]; int arr[N]; bool isprime(int n) { if (n <= 1) return 0; for (int i = 2; i * i <= n; i++) if (n % i == 0) return false; return prime[n] = true; } void feilprime() { prime[0] = prime[1] = 0; for (int i = 2; i * i <= 300; i++)...
4
#include <bits/stdc++.h> using namespace std; int siev[1000005]; inline void Scan_f(int &a) { char c = 0; while (c < 33) c = getc(stdin); a = 0; while (c > 33) { a = a * 10 + c - '0'; c = getc(stdin); } } void sieve() { for (int i = 2; i <= 1e6; i++) { if (siev[i] == 0) { for (int j = i; j...
9
#include <bits/stdc++.h> using namespace std; int n, ans, a[1000010], b[1000010], f[1000010]; void read(int &x) { x = 0; char ch = getchar(); while (ch < '0' || ch > '9') ch = getchar(); while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar(); } int main() { scanf("%d", &n); for (int i = 1; i <...
7
#include <bits/stdc++.h> using namespace std; int main() { int n; int arr[100000 + 10]; int chk[100000 + 10]; memset(chk, 63, sizeof chk); cin >> n; arr[0] = 0; chk[0] = 0; chk[n + 1] = 0; for (int i = 1; i <= n; i++) { cin >> arr[i]; } for (int i = 1; i <= n; i++) { chk[i] = min(chk[i], m...
8
#include <bits/stdc++.h> using namespace std; inline int get() { int f = 0, v = 0; char ch; while (!isdigit(ch = getchar())) if (ch == '-') break; if (ch == '-') f = 1; else v = ch - '0'; while (isdigit(ch = getchar())) v = v * 10 + ch - '0'; if (f == 1) return -v; else return v; } c...
13
#include <bits/stdc++.h> using namespace std; const int N = 207; const int P = 1e9 + 7; struct Node { int x, y; Node operator-(const Node &p) const { return (Node){x - p.x, y - p.y}; } long long operator^(const Node &p) const { return 1ll * x * p.y - 1ll * y * p.x; } } a[N]; int n, dp[N][N]; inline void inc...
17
#include <bits/stdc++.h> using namespace std; int main() { pair<long long int, long long int> a[100005]; long long int n, i, j, k, cap = 0, rem = 0; cin >> n; for (i = 0; i < n; i++) { cin >> a[i].second; } for (i = 0; i < n; i++) { cin >> a[i].first; } sort(a, a + n); for (i = 0; i < (n - 2);...
1
#include <bits/stdc++.h> using namespace std; const int maxn = 5010; vector<int> v[maxn], vec[maxn]; class node { public: long long first, second; node() {} node(long long first, long long second) : first(first), second(second) {} inline friend bool operator<(const node &a, const node &b) { if (a.second ==...
13
#include <bits/stdc++.h> using namespace std; int n, m, k, pn; char s[111][111]; int dxy[4][2] = {{0, -1}, {-1, 0}, {0, 1}, {1, 0}}; struct edge { int v, w, next; edge() {} edge(int _v, int _w, int _next) { v = _v; w = _w; next = _next; } } e[200011]; int head[100011], sz; void init() { memset(hea...
15
#include <bits/stdc++.h> using namespace std; long long n; bool check(long long x) { return x >= 1 && x <= n; } int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(NULL); long long a, b, c, d; while (cin >> n >> a >> b >> c >> d) { long long res = 0; for (int i = 1; i <= n; i++) { lon...
6
#include <bits/stdc++.h> using namespace std; const int maxn = 6; struct matrix { long long int mat[maxn][maxn]; }; long long int mod; matrix matmul(matrix A, matrix B) { matrix ans; memset(ans.mat, 0, sizeof(ans.mat)); for (int i = 0; i < 6; i++) { for (int j = 0; j < 6; j++) { for (int k = 0; k < 6;...
15
#include <bits/stdc++.h> #pragma gcc optimize("Ofast", "unroll-loops") using namespace std; const int N = 300001, K = 50; unordered_map<long long, int> mp; vector<int> c[N]; int pos[N]; int main() { int test; scanf("%d", &test); while (test--) { mp.clear(); fill(pos, pos + N, -1); int n, q; scanf(...
24
#include <bits/stdc++.h> using namespace std; const int N = 200 + 5; const int INF = 0X3F3F3F3F; char a[N], b[N]; int n, m; int dp[N][N][N]; vector<char> ans; struct node { int x, y, z; char c; node(int _x = 0, int _y = 0, int _z = 0, char _c = 0) { x = _x, y = _y, z = _z, c = _c; } } p[N][N][N]; void bfs()...
14
#include <bits/stdc++.h> using namespace std; const int MAXN = 1 << 20; int a[MAXN], b[MAXN], mp[MAXN]; long long c[MAXN + MAXN]; int main() { int n, m, ans = 0; scanf("%d%d", &n, &m); for (int i = 0; i < n; ++i) { scanf("%d", &a[i]); } fill(mp, mp + MAXN, -1); for (int i = 0; i < m; ++i) { scanf("%...
12
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int a1, a2, a3, a4, a5, a6; cin >> a1 >> a2 >> a3 >> a4 >> a5 >> a6; cout << (a1 + a5 + a6) * (a1 + a5 + a6) - (a1 * a1 + a3 * a3 + a5 * a5); }
8
#include <bits/stdc++.h> int main() { long long int don, dt, dthr, d, e, f, g; scanf("%lld%lld%lld", &don, &dt, &dthr); d = don + dt + dthr; e = don + don + dt + dt; f = dt + dt + dthr + dthr; g = don + don + dthr + dthr; if (d <= e && d <= f && d <= g) printf("%lld", d); else if (e <= d && e <= f &...
0
#include <bits/stdc++.h> using namespace std; const int N3 = 1e3 + 15; const int N4 = 1e4 + 15; const int N5 = 1e5 + 15; const int N6 = 1e6 + 15; const int N7 = 1e7 + 15; const int N8 = 1e8 + 15; const int N9 = 1e9 + 15; int n, a[N5 + N5], b[N5 + N5], fr, sc, ans[N6], pos; map<int, int> ub; int main() { cin >> n; f...
7
#include <bits/stdc++.h> using namespace std; vector<string> split(const string& s, char c) { vector<string> v; stringstream ss(s); string x; while (getline(ss, x, c)) v.emplace_back(x); return move(v); } void err(vector<string>::iterator it) {} template <typename T, typename... Args> void err(vector<string>:...
8
#include <bits/stdc++.h> using namespace std; const int INF = 1 << 30; const int p = 1000000009; int lowbit(int x) { return x & (-x); } int fast_power(int a, int b) { int x; for (x = 1; b; b >>= 1) { if (b & 1) x = 1ll * x * a % p; a = 1ll * a * a % p; } return x % p; } pair<int, int> pro[200005]; int n...
10
#include <bits/stdc++.h> using namespace std; int n, a[100005]; vector<int> v; int main() { scanf("%d", &n); for (int i = 1; i <= n; ++i) scanf("%d", &a[i]); for (int i = 1; i <= n;) { int j = i; while (j <= n && a[j] == a[i]) ++j; v.push_back(j - i); i = j; } bool flag = true; for (int i = ...
9
#include <bits/stdc++.h> using namespace std; int main() { string arr[8]; int c1 = 0; int c2 = 0; int f = 0; for (int i = 0; i < 8; i++) { cin >> arr[i]; } for (int i = 0; i < 8; i++) { if (arr[i] != "WBWBWBWB" && arr[i] != "BWBWBWBW") { f = 1; break; } } if (f == 1) { cout...
2
#include <bits/stdc++.h> const int N = 200010; int n, k; char s[N]; std::vector<int> vec; bool check(int mid) { int cnt = 0, now = 0; for (int i = 0; i < vec.size() - 1; ++i) { if (vec[i + 1] - vec[i] > mid) { return false; } if (now + vec[i + 1] - vec[i] <= mid) { ++cnt; now += vec[i ...
12
#include <bits/stdc++.h> using namespace std; void init() { std::ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } int main() { init(); int n; cin >> n; vector<int> arr(n), ans(n); for (int i = 0; i < n; ++i) cin >> arr[i]; sort(begin(arr), end(arr)); ans[0] = 1; for (int i = 1; i...
5
#include <bits/stdc++.h> using namespace std; bool coprime(int a, int b) { for (int i = 2; i <= a; i++) { if (a % i == 0 && b % i == 0) return false; } return true; } int main() { int n, i; cin >> n; bool tut = false; for (i = n / 2; i >= 1; i--) { tut = coprime(i, n - i); if (tut == true) bre...
0
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int a, b, c, d; cin >> a >> b >> c >> d; cout << b << " " << c << " " << c << "\n"; } return 0; }
0
#include <bits/stdc++.h> using namespace std; int main() { string str1, str2, str3; cin >> str1 >> str2 >> str3; int fwd, bwd; int f1, f2; f1 = str1.find(str2, 0); if (f1 != string::npos) { f2 = str1.find(str3, f1 + str2.size()); if (f2 != string::npos) { fwd = 1; } else { fwd = 0; ...
4
#include <bits/stdc++.h> using namespace std; namespace X { struct Point { int x, y; Point(int x = 0, int y = 0) : x(x), y(y) {} }; Point operator+(const Point& a, const Point& b) { return Point(a.x + b.x, a.y + b.y); } Point operator-(const Point& a, const Point& b) { return Point(a.x - b.x, a.y - b.y); } int ...
19
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[n], s = 0; for (int i = 0; i < n; i++) { cin >> a[i]; s += a[i]; } sort(a, a + n); int ans = s; for (int i = 1; i < n; i++) { for (int j = a[i] - 1; j > 1; j--) { if (a[i] % j == 0) { ans = min(an...
5
#include <bits/stdc++.h> using namespace std; int rev[(1 << 21)], mlgn; double omega[(1 << 21)][2]; double FA[(1 << 21)][2], FB[(1 << 21)][2]; inline void mult(double A[2], double B[2], double C[2]) { C[0] = A[0] * B[0] - A[1] * B[1]; C[1] = A[0] * B[1] + A[1] * B[0]; } void calc_rev(int n = (1 << 21)) { while ((...
16
#include <bits/stdc++.h> using namespace std; vector<long long int> primes; vector<bool> is_prime; void sieve() { is_prime.resize(100000 + 1, true); is_prime[0] = is_prime[1] = false; for (long long int i = 2; i * i <= 100000; i++) { if (is_prime[i]) { for (long long int j = i * i; j <= 100000; j += i) ...
7
#include <bits/stdc++.h> using namespace std; signed main() { long long int t = 1; cin >> t; while (t--) { long long int a1, b1, a2, b2; cin >> a1 >> b1 >> a2 >> b2; if (a1 == a2 && b1 + b2 == a1) { cout << "Yes" << endl; } else if (a1 == b2 && b1 + a2 == a1) { cout << "Yes" << endl; ...
1
#include <bits/stdc++.h> using namespace std; void solve() { long long n; cin >> n; long long q; cin >> q; string a; cin >> a; long long dp[n + 1][4]; memset(dp, 0, sizeof(dp)); for (long long i = 0; i < n; i++) { dp[i + 1][0] = dp[i][0]; dp[i + 1][1] = dp[i][1]; dp[i + 1][2] = dp[i][2]; ...
9
#include <bits/stdc++.h> using namespace std; const int c = 210; int mat[c][c]; int zap, mur; int main() { cin >> mur >> zap; mat[c / 2][c / 2] = mur; bool flag = true; while (flag == true) { flag = false; for (int i = 1; i < c - 1; i++) { for (int j = 1; j < c - 1; j++) { if (mat[i][j] >=...
12
#include <bits/stdc++.h> using namespace std; const long long N = 1e5 + 5; int32_t main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; long long t; cin >> t; while (t--) { long long a, b; cin >> a >> b; long long res = ((a * b) / 2) + (a * b) % 2; cout << res << "\n"; } }
0
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 100; int par[N]; int sz[N]; long long all_path; int P(int u) { if (par[u] == u) return u; return par[u] = P(par[u]); } void Merge(int u, int v) { u = P(u); v = P(v); par[v] = u; all_path += 1ll * sz[u] * sz[v]; sz[u] += sz[v]; } long long r...
10
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 100, K = 5, M = 120; int n, k, last[M], a[N], par[M], go[M][M]; long long ans; vector<vector<int>> all; vector<int> vec; int g_par(int v) { return (v == par[v] ? v : par[v] = g_par(par[v])); } bool merge(int u, int v) { bool b = g_par(u) != g_par(v); ...
19
#include <bits/stdc++.h> using namespace std; bool su(long long n) { if (n == 2 || n == 3 || n == 5) return true; long long len = sqrt(n * 1.0); for (long long i = 2; i <= len; i++) if (n % i == 0) return false; return true; } int main() { int T; scanf("%d", &T); while (T--) { long long a, b; ...
3
#include <bits/stdc++.h> using namespace std; int n, k, fa[100005], size[100005], t[100005], c; int find(int x) { if (fa[x] == x) { return x; } int f = find(fa[x]); fa[x] = f; size[f] += size[x]; return f; } int main() { int i, a, b; scanf("%d%d", &n, &k); for (i = 1; i <= n; i++) { fa[i] = i;...
9
#include <bits/stdc++.h> #pragma comment(linker, "/stack:247474112") #pragma GCC optimize("Ofast") using namespace std; const int INF = 0x3f3f3f3f; void accelerate() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); } int main() { accelerate(); vector<int> a; vector<int> b; int n; cin >> n; int ...
7
#include <bits/stdc++.h> using namespace std; struct edge { int u, v, f, c, next; }; struct edge e[300010]; int n, k, num, tot, mc, ans, inf = 1e9; int a[1010], q[10010], head[1010], used[1010], dis[1010], pre[1010]; void add(int u, int v, int f, int c) { e[num].u = u; e[num].v = v; e[num].f = f; e[num].c = c...
19
#include <bits/stdc++.h> struct point { long long x, y; }; double len(point a) { return sqrt(a.x * a.x + a.y * a.y); } double dist(point a, point b, point c) { double normal = len({b.x - a.x, b.y - a.y}); point v1 = {b.x - a.x, b.y - a.y}; point v2 = {c.x - a.x, c.y - a.y}; double area = v1.x * v2.y - v1.y * ...
10
#include <bits/stdc++.h> using namespace std; long long p[41630] = {0}, pr[10000]; void prime() { int i, j; for (i = 2; i <= 31625; i++) for (j = i + i; j <= 31625; j = j + i) p[j] = 1; j = 0; for (i = 2; i <= 33000; i++) if (!p[i]) pr[j++] = i; } int main() { long long a, b, c, d, i, j, n, m; cin >...
2
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 10; const int LogN = 20; int n, m, vreme; long long mst; vector<int> g[N], w[N]; int in[N], out[N], depth[N], st[N][LogN][2]; struct Edge { int a, b, w; bool operator<(const Edge &e) const { return w < e.w; } } grana[N], order[N]; struct NodeDSU { ...
13
#include <bits/stdc++.h> using namespace std; vector<int> v[100005]; vector<int> vt[100005]; int n, m; int pri[100005]; int dfs1[100005]; int dfs2[100005]; stack<int> ord; int brk = 1; map<pair<int, int>, int> mp; void dfsf1(int x, int m) { dfs1[x] = m; for (int i = 0; i < v[x].size(); i++) { if (dfs1[v[x][i]] ...
9
#include <bits/stdc++.h> using namespace std; int dx[] = {1, 0, 0, -1}; int dy[] = {0, 1, -1, 0}; const int MAX = 510; char arr[MAX][MAX]; bool vis[MAX][MAX]; vector<pair<pair<int, int>, int> > ans; int n, m; bool check(int x, int y) { return x >= 0 && x < n && y >= 0 && y < m && !vis[x][y] && arr[x][y] != '#'; } voi...
11
#include <bits/stdc++.h> const int MAXN = 1e5 + 10, MAXM = 2e6 + 5, MOD = 100003, INF = 0x3f3f3f3f, N = 2e5; const long long INFL = 0x3f3f3f3f3f3f3f3f; const double eps = 1e-9; using namespace std; int t, s, i, e; int main() { ios::sync_with_stdio(false); cin >> t; while (t--) { cin >> s >> i >> e; ...
5
#include <bits/stdc++.h> using namespace std; long long k; set<char> a; set<char>::reverse_iterator ii; int main() { cin >> k; long long i; for (i = 0; i < k; i++) { a.insert('a' + i); } string s; cin >> s; long long n = s.size(); for (i = 0; i < n; i++) { long long m = n - i - 1; if (s[i] !...
8
#include <bits/stdc++.h> using namespace std; using namespace chrono; const int infinity = (int)1e9 + 42; const int64_t llInfinity = (int64_t)1e18 + 256; const int module = (int)1e9 + 7; const long double eps = 1e-8; mt19937_64 randGen(system_clock().now().time_since_epoch().count()); inline void raiseError(string erro...
23
#include <bits/stdc++.h> using namespace std; int main() { int e; cin >> e; int x[e]; int y[e]; for (int i = 0; i < e; i++) { cin >> x[i] >> y[i]; } int cont = 0; for (int i = 0; i < e; i++) { for (int j = i + 1; j < e; j++) { for (int k = j + 1; k < e; k++) { int x1 = x[i] - x[k];...
11
#include <bits/stdc++.h> int main(int argc, char **argv) { unsigned m, n; while (std::cin >> n >> m) { std::vector<unsigned> vert; std::vector<std::vector<unsigned>> edges(n); unsigned x, y; for (unsigned i = 0; i < n; ++i) { std::cin >> x; vert.push_back(x); } unsigned total = 0...
6
#include <bits/stdc++.h> using namespace std; const int MOD = (int)1e9 + 7; const int INF = (int)1e9; const long long LINF = (long long)1e18; const long double PI = acos((long double)-1); const long double EPS = 1e-6; inline long long gcd(long long a, long long b) { long long r; while (b) { r = a % b; a = b...
16
#include <bits/stdc++.h> using namespace std; int used[100], a[100], b[100], ans_a[100], ans_b[100]; int main() { int t; cin >> t; while (t--) { int n; cin >> n; for (int i = 0; i < n; ++i) cin >> a[i]; for (int i = 0; i < n; ++i) cin >> b[i]; sort(a, a + n); sort(b, b + n); for (int i...
0
#include <bits/stdc++.h> int n, q, a[1111111]; const int MAXV = 1000010; std::vector<int> primeDivs[1111111]; struct dsu { int fa[1111111]; int rt(int x) { return fa[x] ? fa[x] = rt(fa[x]) : x; } void merge(int x, int y) { x = rt(x), y = rt(y); if (x != y) fa[x] = y; } } U; void ins(int x) { for (int ...
19
#include <bits/stdc++.h> struct Node { Node(int v = 1e9) { min = v; } Node(Node l, Node r) { min = std::min(l.min, r.min); } int min; }; template <class i_t, class e_t> class SegmentTree { public: void init(std::vector<e_t> base) { n = base.size(); tree.resize(2 * n); for (int i = 0; i < n; i++) { ...
2
#include <bits/stdc++.h> using namespace std; int nTest; long long n, k, d1, d2; bool isOK(long long a, long long b, long long c) { if (a < 0) { b -= a; c -= a; a -= a; } if (b < 0) { c -= b; a -= b; b -= b; } if (c < 0) { a -= c; b -= c; c -= c; } if (a + b + c > k) re...
9
#include <bits/stdc++.h> using namespace std; void IO() { ios::sync_with_stdio(0); ios_base::sync_with_stdio(0); cin.tie(0), cout.tie(0); } char arr[150][150]; bool Row_com(short int m, short int r, char key); bool Coloumn_com(short int n, short int c, char key); int main() { IO(); short int n, m; cin >> n ...
3
#include <bits/stdc++.h> using namespace std; const long long test[109] = {2, 3, 5, 7, 11, 61, 24251, 13, 17, 23}; long long read() { char c; long long num, f = 1; while (c = getchar(), !isdigit(c)) if (c == '-') f = -1; num = c - '0'; while (c = getchar(), isdigit(c)) num = num * 10 + c - '0'; return f...
7
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; int CASE = 1; const int mxn = 1e5 + 1; long long __gcd(long long a, long long b) { return !b ? a : __gcd(b, a % b); } bool prime(long long n) { if (n <= 1) return false; for (int i = 2; i <= sqrt(n); i++) if (n % i == 0) return false; retu...
5
#include <bits/stdc++.h> using namespace std; const int N = 200005; char s[N]; int a[26]; int main() { int n, m; scanf("%d%d", &n, &m); scanf("%s", s); for (int i = 0; i < 26; ++i) a[i] = i; while (m--) { char x[3], y[3]; scanf("%s%s", x, y); int p, q; for (int i = 0; i < 26; ++i) { if (...
4
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cout.setf(ios::fixed); cout.setf(ios::showpoint); { long long int n; cin >> n; long long int a[n], freq[100001] = {0}; long long int max = 0, maxf = 0; for (long lo...
7
#include <bits/stdc++.h> using namespace std; const int N = 100005; vector<int> divs[N]; vector<int> mult[N]; int mu[N], a[N], n; int cnt[N]; long long res = 0; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); mu[1] = 1; for (int i = 1; i < N; i++) { divs[i].push_back(i); for (int j ...
21