solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> const double Pi = acos(-1.0); using namespace std; const int maxN = 400010; int n, q; vector<pair<long long, long long> > G[maxN]; map<int, pair<long long, long long> > ei; long long e1[maxN], ind1[maxN]; long long dist[maxN]; long long st[maxN], disc[maxN], fin[maxN], t; void dfs(int cur) { ...
13
#include <bits/stdc++.h> using namespace std; int x[53]; int main(int argc, char** argv) { int t, n, min; cin >> t; for (int i = 0; i < t; i++) { cin >> n; for (int j = 0; j < n; j++) { cin >> x[j]; } sort(x, x + n); min = x[1] - x[0]; for (int j = 0; j < n - 1; j++) { if (x[j ...
0
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; int sx, sy, ex, ey; cin >> sx >> sy >> ex >> ey; int x, y; x = ex - sx; y = ey - sy; string str; cin >> str; int ans = -1; for (int i = 0; i < t; i++) { if (x < 0 && str[i] == 'W') x++; else if (x > 0 && str[...
4
#include <bits/stdc++.h> using namespace std; void solve() { int k; cin >> k; int n = sqrt(k); if (n * n == k) { cout << n << " 1" << "\n"; } else { int diff = k - n * n; int s = diff - n - 1; if (diff <= n + 1) { cout << diff << " " << n + 1 << "\n"; } else { cout << ...
0
#include <bits/stdc++.h> #pragma GCC optimize("O3") const double PI = acos(-1); using namespace std; const int MAX = 1024, MEM = 1398101; int n; long long BIT[4][MAX][MAX]; void update(int x, int y, long long v) { int c = (x & 1) | ((y & 1) << 1); for (; x <= n; x += ((x) & (-(x)))) for (int _y = y; _y <= n; _y...
17
#include <bits/stdc++.h> inline int read() { char c = getchar(); while (c != '-' && (c < '0' || c > '9')) c = getchar(); int k = 0, kk = 1; if (c == '-') c = getchar(), kk = -1; while (c >= '0' && c <= '9') k = k * 10 + c - '0', c = getchar(); return kk * k; } using namespace std; void write(int x) { if (...
25
#include <bits/stdc++.h> class disjoint_set { public: protected: std::vector<std::size_t> fa; public: disjoint_set(std::size_t n = 0) : fa(n) { std::iota(fa.begin(), fa.end(), 0); } std::size_t find(std::size_t x) { return fa[x] == x ? x : (fa[x] = find(fa[x])); } bool merge(std::size_t x, std::...
25
#include <bits/stdc++.h> using namespace std; long long m(long long a) { return ((a % 1000000007) + 1000000007) % 1000000007; } vector<int> parent; vector<long long> depth; long long sm = 0; void make_parent(int v) { parent[v] = v; depth[v] = 0; } int find_parent(int v) { if (parent[v] == v) return parent[v...
12
#include <bits/stdc++.h> using namespace std; int a[100010], b[100010]; vector<int> g[200010]; int val[200010]; bool visited[200010]; void dfs(int root) { visited[root] = true; for (int i = 0; i < int(g[root].size()); i++) { int child = g[root][i]; if (visited[child]) continue; val[child] = 3 - val[root...
18
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n, m, a, mn = 1e9, sum = 0, cneg = 0; cin >> n >> m; for (int x = 0; x < n * m; x++) { cin >> a; if (a < 0) cneg++; sum += abs(a); mn = min(mn, abs(a)); } if (cneg & 1) c...
2
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const int maxn = 1e6; int p, k; vector<unsigned long long> prim; bool vis[maxn + 5]; void init() { memset(vis, 1, sizeof vis); vis[1] = false; for (int i = 2; i <= maxn; i++) { if (vis[i]) prim.push_back(i); for (int j = 0; j < prim.si...
7
#include <bits/stdc++.h> const int MAXN = 1e6 + 10; int n; int m; int k; int a[MAXN]; int cnt[MAXN]; bool blk[MAXN]; int main() { scanf("%d%d%d", &n, &m, &k); for (int i = 0; i < m; i++) { int tmp; scanf("%d", &tmp); blk[tmp] = true; } for (int i = 1; i <= k; i++) scanf("%d", a + i); if (blk[0]) {...
13
#include <bits/stdc++.h> using namespace std; long long depth[200005]; long long SubTreeSize[200005]; vector<vector<long long>> adj(200005); bool vis[200005]; long long dfs(long long v, long long d) { vis[v] = true; SubTreeSize[v] = 1; depth[v] = d; for (long long u : adj[v]) { if (!vis[u]) SubTreeSize[v] +...
8
#include <bits/stdc++.h> const long long MOD = 1e9 + 7; const int MAX_N = 1e5 + 10; const long long INF = 1e18; const long long delta = 10957; using namespace std; int n, m, x, k; vector<int> g[MAX_N]; long long dp[MAX_N][12][3]; void dfs(int v, int p) { if (g[v].size() == 1) { dp[v][0][0] = k - 1; dp[v][1][1...
12
#include <bits/stdc++.h> using namespace std; void solve() { } int main() { long long t; cin >> t; while (t--) { long long n, ding, dang; cin >> n >> ding >> dang; long long omi, cremus; cin >> omi >> cremus; omi = 2 * omi; cremus = 2 * cremus; lon...
0
#include <bits/stdc++.h> using namespace std; struct point { long long x, y; point(long long _x = 0, long long _y = 0) : x(_x), y(_y) {} int operator<(const point &a) const { if (x == a.x) { return y > a.y; } return x < a.x; } }; const int MAXN = 100000; int mx[MAXN + 10], dp[MAXN + 10], MX; v...
19
#include <bits/stdc++.h> using namespace std; static int n, k; int main(void) { scanf("%d%d", &n, &k); printf("%d\n", k * (6 * n - 1)); for (int i = 0; i < n; ++i) { printf("%d %d %d %d\n", k * (6 * i + 1), k * (6 * i + 2), k * (6 * i + 3), k * (6 * i + 5)); } return 0; }
11
#include <bits/stdc++.h> const int N = 262144, Max = 5000; int mod = 1, lim; void up(int &x, int y) { x += y - mod, x += x >> 31 & mod; } void down(int &x, int y) { x -= y, x += x >> 31 & mod; } int pow(int x, int y, int mod = ::mod, int ans = 1) { for (; y; y >>= 1, x = (long long)x * x % mod) if (y & 1) ans = (...
25
#include <bits/stdc++.h> using namespace std; int used[1000]; int n, t, x, id = 1; string s; bool free(int l, int r) { bool ok = 1; for (int i = l; i < r; i++) if (used[i] != 0) ok = 0; return ok; } int main() { cin >> t >> n; for (int i = 0; i < t; i++) { cin >> s; if (s == "alloc") { cin >...
8
#include <bits/stdc++.h> using namespace std; int A[100005], B[100005]; map<int, int> ma, maa; int main(void) { int i, j, k, n, m, nn, mm, ans, res, pos, L, LL, beg, mod; scanf("%d %d", &n, &m); for (i = 0; i < n; i++) { scanf("%d", A + i); } scanf("%d %d", &nn, &mm); for (i = 0; i < nn; i++) { scan...
17
#include <bits/stdc++.h> using namespace std; const int maxn = 5e5 + 999; int saveori[maxn]; vector<int> G[maxn]; int cnt[maxn]; int flag = 0; void dfs(int s, int fa, int dis) { if (dis == 2) { return; } for (int d : G[s]) { if (d == fa) continue; if (cnt[d] == 1) flag = 1; if (flag) return; d...
8
#include <bits/stdc++.h> using namespace std; int n, m; double p[5005]; int t[5005]; double dp[5005][5005]; double a[5005]; double fast(double base, int exp) { if (!exp) return 1; if (exp & 1) return base * fast(base * base, exp / 2); return fast(base * base, exp / 2); } int main() { cin >> n >> m; for (int i...
16
#include <bits/stdc++.h> using namespace std; deque<int>::iterator it; int n, m, x, b, size, maxb, ans, tmp, a, aa, bb, v, k, l, r; struct blo { deque<int> q; int num[100010]; } block[405]; void init() { size = pow(n, 0.618); if (n % size == 0) maxb = n / size; else maxb = n / size + 1; for (int i =...
19
#include <bits/stdc++.h> using namespace std; int n; int main() { int cas; while (scanf("%d", &n) != EOF) { printf("%d\n", n / 2 * 3); } return 0; }
1
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[n]; int sum = 0; for (int i = 0; i < n; i++) { cin >> a[i]; if (a[i] >= 0) sum += a[i]; else sum -= a[i]; } cout << sum << endl; }
0
#include <bits/stdc++.h> using namespace std; const int MX = 25; int n; set<int> s; void solve(int d1, int d2, long long x, int k, int len) { if (x > n) return; if (k == len) { if (x <= n) { s.insert(x); } return; } solve(d1, d2, 10 * x + d1, k + 1, len); solve(d1, d2, 10 * x + d2, k + 1, le...
8
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); string s; cin >> s; s[2] = ' '; stringstream ss; ss << s; long double a, b; ss >> a >> b; long double res[2]; res[1] = b * 6; if ((long long)a >= 12) a -= 12; res[0] = a * 30 + res[1] / 12; cout << res[0] ...
4
#include <bits/stdc++.h> using namespace std; int main() { int a = 0, c = 0, g = 0, t = 0, flag, n, ex = 0; int a1, c1, g1, t1; char s[500]; scanf("%d%*c", &n); int div = n / 4; gets(s); if (n % 4 == 0) { for (int i = 0; i < n; i++) { if (s[i] == 'A') a++; if (s[i] == 'C') c++; if (s...
1
#include <bits/stdc++.h> using namespace std; const int maxn = 3e5 + 7; const int mod = 998244353; long long n; vector<long long> a; bool scheck() { for (int i = 0; i < n; ++i) if (a[i] < i) { return true; } int c = 0; for (int i = 0; i < n - 1; ++i) if (a[i] == a[i + 1]) { c++; if (...
10
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; char s[n + 1], t[n + 1]; cin >> s >> t; int sa[26] = {0}, ta[26] = {0}; for (int i = 0; i < n; ++i) { sa[s[i] - 'a']++; ta[t[i] - 'a']++; } for (int i = 0; i < 26; ++i) { if (sa[i] != ta[i]) { cout << -1 << end...
4
#include <bits/stdc++.h> using namespace std; void xin() {} int f[100005]; int main() { xin(); ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); string s[4]; cin >> s[0] >> s[1] >> s[2] >> s[3]; int i, j; for (i = 0; i < 3; i++) { for (j = 0; j < 3; j++) { int count = 0; i...
3
#include <bits/stdc++.h> using namespace std; const long long int N = 2e5 + 5; long long int pref1[N], pref2[N]; long long int n, fx, fy; string s; long long int check(long long int num) { if (num == n + 1) return 1; for (long long int i = 0; i + num - 1 < s.size(); i++) { long long int j = i + num - 1; lon...
10
#include <bits/stdc++.h> using namespace std; int main(int argc, char const *argv[]) { ios_base::sync_with_stdio(false); cin.tie(NULL); int TC; cin >> TC; while (TC--) { int n, k; cin >> n >> k; std::vector<long long> v(n * k + 1); for (int i = 0; i < n * k; ++i) { cin >> v[i]; } ...
1
#include <bits/stdc++.h> using namespace std; const int maxm = 20002, maxn = 10005; long long d[2][maxm], d1; int p[maxn][626], x[maxm], y[maxm], n, m, P, r, i, j, u, v; int cost(int i, int j) { r = x[i] + y[j]; if (r >= P) r -= P; return r; } void solve(int f, int t) { memset(d, 255, sizeof(d)); memset(p, 0,...
17
#include <bits/stdc++.h> using namespace std; int mape[3005][3005] = {0}; vector<int> in[3005], out[3005]; int main() { int n, m; cin >> n >> m; for (int i = 0; i < m; i++) { int a, b; cin >> a >> b; out[a].push_back(b); in[b].push_back(a); } for (int i = 1; i <= n; i++) { for (int j = 0; ...
9
#include <bits/stdc++.h> using namespace std; int main() { int n, Gcnt = 0, maxlen = 0, lastlen = 0, tmp = 0; char trophies[100001]; scanf("%d %s", &n, trophies); for (int i = 0; i < n; i++) { if (trophies[i] == 'G') Gcnt++; } if (Gcnt <= 1 || Gcnt == n) { printf("%d", Gcnt); return 0; } for...
8
#include <bits/stdc++.h> using namespace std; const int MX = 15; const int MOD = 1000000007; int main() { ios_base::sync_with_stdio(0); long long n, m, a, b; cin >> n >> m >> a >> b; long long cl = m * ((n - 1) / m + 1); long long costcl = (cl - n) * a; long long fl = m * (n / m); long long costfl = (n - ...
2
#include <bits/stdc++.h> using namespace std; const long long MX = (long long)1e18; int n, k, N; int p[16]; vector<long long> v[2]; void dfs(long long x, int id, vector<long long>& v) { v.push_back(x); for (int i = id; i < N; i++) { if (x <= MX / p[i]) dfs(x * p[i], i, v); else break; } } int ...
16
#include <bits/stdc++.h> using namespace std; int n; long long a, tmp, res = 1; void swap(long long &a, long long &b) { long long t = a; a = b; b = t; } long long gcd(long long a, long long b) { while (b) { a %= b; swap(a, b); } return a; } long long lcm(long long a, long long b) { return a / gcd(a,...
8
#include <bits/stdc++.h> using namespace std; int arr1[200005]; int arr2[200005]; vector<pair<int, int> > ptr; int main() { int num, k; cin >> num >> k; for (int i = 0; i < num; i++) cin >> arr1[i]; long long int sum = 0; for (int j = 0; j < num; j++) { cin >> arr2[j]; sum += arr2[j]; } for (int i...
4
#include <bits/stdc++.h> #pragma GCC optimize(3) #pragma GCC target("avx") #pragma GCC optimize("Ofast") #pragma GCC optimize("inline") #pragma GCC optimize("-fgcse") #pragma GCC optimize("-fgcse-lm") #pragma GCC optimize("-fipa-sra") #pragma GCC optimize("-ftree-pre") #pragma GCC optimize("-ftree-vrp") #pragma GCC opt...
11
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; for (int iter = 0; iter < t; iter++) { int a, b, c, d, count = 0; cin >> a >> b >> c >> d; int x, y, x1, y1, x2, y2; cin >> x >> y >> x1 >> y1 >> x2 >> y2; if (x1 <= x - (a - b) && x - (a - b) <= x2 && y1 <= y - (c - d...
3
#include <bits/stdc++.h> using namespace std; long long qpow(long long a, long long b) { long long res = 1, base = a; while (b) { if (b % 2) res = res * base; base = base * base; b /= 2; } return res; } long long powmod(long long a, long long b) { long long res = 1, base = a; while (b) { if ...
15
#include <bits/stdc++.h> using namespace std; const double pai = acos(-1); const double eps = 1e-8; const long long mod = 1e9 + 7; const int MXN = 1e6 + 5; char s[MXN]; char t[MXN]; int MAIN(int avg) { int n, k; cin >> n >> k; k--; cin >> s; vector<pair<int, int> > ans; for (int i = 0; i < k * 2; i++) { ...
9
#include <bits/stdc++.h> using namespace std; const int N = 1001; long long a[N], b[N], c[N], d[N], num[N], used[N]; long long n, i, j, x, y, number, t1, t2; int main() { cin >> n; memset(num, 0, sizeof(num)); memset(d, 0, sizeof(d)); for (i = 1; i <= n; i++) scanf("%d", &a[i]); for (i = 1; i <= n; i++) scanf...
5
#include <bits/stdc++.h> using namespace std; map<long long, long long> m; int main() { long long n, x = 0, b, a[100007]; scanf("%lld", &n); for (long long i = 0; i < n; ++i) { scanf("%lld", &a[i]); } long long i = n - 1, j = n - 1; sort(a, a + n); while (i >= 0) { if (j == -1) { break; ...
5
#include <bits/stdc++.h> using namespace std; const long long mod = 998244353; long long power(long long a, long long b) { if (b == 0) return 1; else if (b == 1) { return a; } else if (b & 1) { return (a % mod * power((a % mod * a % mod) % mod, b / 2)) % mod; } else { return (power((a % mod * a ...
9
#include <bits/stdc++.h> using namespace std; const int INF = 1e9 + 1; const int SIZE = 1e7 + 5; const double eps = 1e-7; const long long mod = 1e9 + 7; const int mx = 1e5 + 1; template <class T> using V = vector<T>; template <class T> using VV = V<V<T>>; template <typename XPAX> void ckmax(XPAX &x, XPAX y) { x = (x ...
2
#include <bits/stdc++.h> using namespace std; int main() { int a, b; cin >> a >> b; int ans = 0; for (int i = 1; i <= a; i++) { if (b / i > a) continue; if (b % i == 0) ans++; } cout << ans; return 0; }
2
#include <bits/stdc++.h> using namespace std; long long n, a[2000005], i, s, ss = 0, j; int main() { cin >> n; for (i = 1; i <= n; i++) cin >> a[i]; for (i = 1; i <= n; i++) { s = 0; for (j = i + 2; j <= n; j++) { s += a[j - 1]; if (s >= 2 * a[i]) break; if ((a[i] ^ a[j]) == s && a[i] >=...
17
#include <bits/stdc++.h> using namespace std; int main() { double d, l, v1, v2; cin >> d >> l >> v1 >> v2; double s = (l - d) / (v1 + v2); printf("%.6f\n", s); return 0; }
0
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using vi = vector<int>; using vvi = vector<vector<int>>; using vs = vector<string>; using vl = vector<ll>; using vvl = vector<vector<ll>>; using pii = pair<int, int>; using pll = pair<ll, ll>; using vvp = vector<vector<pair<int,...
1
#include <bits/stdc++.h> using namespace std; const long long MAXN = 1e5 + 5; const long long INF = 1e5; long long n, k, p, a[MAXN], b[MAXN], tree[MAXN * 4], Min[MAXN * 4], MinId[MAXN * 4], ans, cnt; set<long long> s[MAXN]; long long lowbit(long long x) { return x & (-x); } void add(long long x, long long y) { fo...
8
#include <bits/stdc++.h> using namespace std; const long long int N = 1e6 + 5; std::vector<pair<long long int, pair<long long int, long long int> > > v; long long int par[N], sz[N]; long long int n, m, start_x, start_y; bool ok; void init() { for (long long int i = 1; i < N; i++) { par[i] = i; } } long long int...
11
#include <bits/stdc++.h> using namespace std; int main() { double n, k; int a[102]; double sum = 0; cin >> n >> k; for (int i = 0; i < n; i++) { cin >> a[i]; sum += a[i]; } double j = sum / n; double y = ((2 * k - 1) * n) - (2 * sum); if (y < 0) cout << 0; else cout << y; }
1
#include <bits/stdc++.h> using namespace std; void solve(long long int** arr, long long int** ans, long long int i, long long int j, long long int n, long long int m, long long int x) { if (i == n || j == m || i < 0 || j < 0) { return; } if (ans[i][j] != -1) return; else { ans[i][j] = x; ...
6
#include <bits/stdc++.h> using namespace std; int n, dian, bian, san; int x[5], y[5], r[5]; struct point { double x, y; }; struct line { int a, b, c; }; int squ(int x) { return x * x; } double squ(double x) { return x * x; } double dist(int a, int b, line c) { return abs(c.a * a + c.b * b + c.c) / (double)sqrt(sq...
19
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); unsigned long long n, k; cin >> n >> k; int i; for (i = 0; i < 64; ++i) { if (k >> i & 1) break; } cout << i + 1 << endl; return 0; }
4
#include <bits/stdc++.h> using namespace std; int main() { int n, m, next[2000], i, j, gt[2000], mmin, a1[2000], a2[2000], a3[2000], t; bool ra[2000], vao[2000]; cin >> n >> m; memset(ra, false, sizeof(ra)); memset(vao, false, sizeof(vao)); for (i = 1; i <= m; i++) { cin >> a1[i] >> a2[i] >> a3[i]; ...
6
#include <bits/stdc++.h> using namespace std; int n_comp = 0, n_free = 0, total = 0, Max = 0; bool visited[600][600]; char board[600][600]; int comp[600][600], n, k, contribution[260000], size_comp[260000]; void create_comp(int i, int j) { if (visited[i][j]) return; else if (board[i][j] == 'X') { comp[i][j]...
16
/* { ###################### # Author # # Gary # # 2021 # ###################### */ #include<bits/stdc++.h> #define rb(a,b,c) for(int a=b;a<=c;++a) #define rl(a,b,c) for(int a=b;a>=c;--a) #define LL long long #define IT iterator #define PB push_back #define II(a,b) make_pair(a,b) ...
4
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f, lim = 3e8 + 5; struct Edge { int to, val, next; } edge[300086]; int s, t; int cnt = -1; int head[300086]; queue<int> q; int d[300086]; int cur[300086]; void addEdge(int u, int v, int w) { cnt++; edge[cnt].to = v; edge[cnt].val = w; edge...
21
#include <bits/stdc++.h> using namespace std; void in() { return; } template <typename T, typename... Types> void in(T &a, Types &...b) { cin >> (a); in(b...); } void o() { return; } template <typename T, typename... Types> void o(T a, Types... b) { cout << (a); cout << ' '; o(b...); } bool sortin(const pair<...
6
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 5; int main() { int n; while (scanf("%d", &n) != EOF) { map<int, int> adj; vector<int> order; for (int i = 0; i < n; i++) { int tmp; scanf("%d", &tmp); adj.insert(make_pair(tmp, n - i)); } for (int i = 0; i < n; ...
11
#include <bits/stdc++.h> using namespace std; void solve() { int n; cin >> n; std::vector<int> v; int temp; for (int i = 0; i < n; ++i) { cin >> temp; v.push_back(temp); } int maxi = 0; for (int i = 0; i < n; ++i) { int count = 1; for (int j = i + 1; j < n; ++j) { if (v[j] > v[j - ...
3
#include <bits/stdc++.h> using namespace std; using ll = int64_t; using P = pair<int, int>; template <class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p) { os << "p" << " = (" << p.first << ", " << p.second << ")"; return os; } template <class T> ostream& operator<<(ostream& os, const vecto...
14
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 5; const int inf = (1 << 29); int n; int a[maxn]; bool covered[maxn]; int x[maxn], dp[maxn], pre[maxn]; int val_to_pos[maxn]; vector<vector<int> > res; int ssolve(int d, int pre_cut) { for (int i = 0; i <= n; i++) { x[i] = inf; } x[0] = 0; ...
26
#include <bits/stdc++.h> using namespace std; int n, a[3000], s[3000], d[3000][30], ans = 1, s1[3000], s2[3000]; void init() { int i, j; for (i = 1; i <= n; i++) d[i][0] = a[i]; for (j = 1; j < 30; j++) for (i = 1; i + (1 << j) <= n + 1; i++) d[i][j] = min(d[i][j - 1], d[i + (1 << (j - 1))][j - 1]); } i...
10
#include <bits/stdc++.h> using namespace std; long long f[10] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29}; int N = 0; long long res = 1e18; void dfs(int idx, long long x, int n) { if (n > N) { return; } if (n == N && res > x) { res = x; } for (int i = 1; i <= 60; ++i) { if (x * f[idx] > res) { re...
12
#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 ...
16
#include <bits/stdc++.h> using namespace std; const long long inf = 1000000000000000000; const int N = 4005; int n, m; long long a[N], dp[N][N]; inline int read() { int F = 1, ANS = 0; char C = getchar(); while (C < '0' || C > '9') { if (C == '-') F = -1; C = getchar(); } while (C >= '0' && C <= '9') ...
21
#include <bits/stdc++.h> using namespace std; int A, B, C, D, E, add, mn, ans = -1000000000, n, ind; char name[100][100]; int main() { cin >> n; for (int i = 1; i <= n; ++i) { cin >> name[i] >> add >> mn >> A >> B >> C >> D >> E; if (A + B + C + D + E + add * 100 - mn * 50 > ans) { ans = A + B + C + D...
2
#include <bits/stdc++.h> using namespace std; long long int inf = pow(10, 9) + 7, n; vector<vector<long long int>> v, v1; map<long long int, long long int> level; vector<long long int> ans; vector<bool> vis; long long int bfs(long long int r, vector<vector<long long int>> &a, long long int cnt) { qu...
8
#include <bits/stdc++.h> using namespace std; struct ww { int x, y; void read() { scanf("%d%d", &x, &y); } void fan() { swap(x, y); } } a[200010], l[200010], r[200010], b[200010]; int i, j, k, n, m, K, q; int an[200010], id[200010], tr[200010 * 4]; inline bool cc1(const int &A, const int &B) { return r[A].x < r[B...
16
#include <bits/stdc++.h> using namespace std; int n, t; vector<pair<int, pair<int, int> > > x; vector<int> r; bool can(int k) { r.clear(); int q = 0, w = 0; for (int i = 0; i < n && q < k; ++i) { if (k <= x[i].second.first) { r.push_back(x[i].second.second); w += x[i].first; q++; } } ...
10
#include <bits/stdc++.h> #pragma comment(linker, "/stack:20000000") using namespace std; double __begin; template <typename T1, typename T2, typename T3> struct triple { T1 a; T2 b; T3 c; triple(){}; triple(T1 _a, T2 _b, T3 _c) : a(_a), b(_b), c(_c) {} }; template <typename T1, typename T2, typename T3> bool ...
8
#include <bits/stdc++.h> using namespace std; void sf(int &x) { scanf("%d", &x); } void sf(long long &x) { scanf("%lld", &x); } void sf(long long &x, long long &y) { scanf("%lld%lld", &x, &y); } void sf(float &x) { scanf("%f", &x); } void sf(double &x) { scanf("%lf", &x); } void sf(int &x, int &y) { scanf("%d%d", &x, &...
3
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; string s; cin >> s; int curr = 0; int con = 0; for (int i = 0; i < n; i++) { if (s[i] == '.') con++; else { curr += max(0, con - 1); con = 0; } } if (con != 0) curr += con - 1; while (m-...
8
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); int n, k; cin >> n >> k; int mi = 0; string st; cin >> st; string second = st; vector<vector<int> > v; for (int i = 0; i < n; i++) { int flag = 0; vector<int> vv; for (int j = 0; j < n...
13
#include <bits/stdc++.h> using namespace std; int main() { int a[4]; while (scanf("%d%d%d%d", &a[0], &a[1], &a[2], &a[3]) != EOF) { sort(a, a + 4); if (a[3] < a[2] + a[1] || a[2] < a[1] + a[0]) printf("TRIANGLE\n"); else if (a[3] > a[2] + a[1] && a[2] > a[1] + a[0]) printf("IMPOSSIBLE\n"); ...
1
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; cin >> n; int sum = 360, curr = 0, a[500] = {0}; for (int i = 0; i < n; i++) cin >> a[i]; for (int j = 0; j < n; j++) { curr = 0; for (int i = j; i < n; i++) { int d...
4
#include <bits/stdc++.h> using namespace std; constexpr long long MAXN = 55; long long dp[MAXN][MAXN][MAXN][MAXN], pref[MAXN][MAXN]; long long get(long long i, long long j, long long x, long long y) { return pref[x][y] - pref[x][j - 1] - pref[i - 1][y] + pref[i - 1][j - 1]; } signed main() { long long n; cin >> n...
15
#include <bits/stdc++.h> using namespace std; const long long INF = 1e9 + 10; const long long MOD = 1e9 + 7; const long long P = 239017; const long long BINF = 1e18 + 10; inline void source() { long long n, k, prevv = 0, ans = 0; cin >> n >> k; for (long long i = 1; i <= n; i++) { long long a; cin >> a; ...
1
#include <bits/stdc++.h> using namespace std; const long long maxn = 100010; long long n, m, s, a[maxn], b[maxn], c[maxn], bel[maxn]; long long ar[maxn], ak[maxn], br[maxn], bk[maxn]; long long rm[maxn]; inline bool cmp_a(long long i, long long j) { return a[i] < a[j]; } inline bool cmp_b(long long i, long long j) { re...
11
#include <bits/stdc++.h> using namespace std; template <typename T> bool chkmin(T &x, T y) { return x > y ? x = y, 1 : 0; } template <typename T> bool chkmax(T &x, T y) { return x < y ? x = y, 1 : 0; } int readint() { int x = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f =...
18
#include <bits/stdc++.h> using namespace std; int n, m; set<int> ans; int main() { scanf("%d", &n); m = 2 * n * n; ans.insert(1); for (int i = 2; ans.size() <= n; i++) { for (set<int>::iterator it = ans.begin(); it != ans.end(); it++) if ((*it) * i <= m) { ans.insert((*it) * i); } } ...
15
#include <bits/stdc++.h> using namespace std; int main() { long long int n, x, y, a = 2, b; cin >> n >> x >> y; a = abs(x + y - 2); b = abs((x + y) - (n + n)); if (a <= b) cout << "White" << endl; else cout << "Black" << endl; }
0
#include <bits/stdc++.h> using namespace std; map<int, int> m; int main() { int n, i, a, ans; ans = 0; scanf("%d", &n); for (i = 0; i < n; i++) { scanf("%d", &a); m[a] = 1; } ans = m.size() - m[0]; printf("%d\n", ans); return 0; }
0
#include <bits/stdc++.h> using namespace std; const int inf = 1e09 + 5e3; const long long linf = 2e18 + 5e3; const int mxn = 1e3, mxv = 1e4, mod = 1e9 + 7; int n; int a[mxn], memo[mxn][mxv << 1]; int dp(int i, int rem) { if (rem > (mxv >> 1) || rem < -(mxv >> 1)) return 0; if (i == n) return rem == 0; if (~memo[i...
15
#include <bits/stdc++.h> using namespace std; int n, w; pair<int, int> num[110]; int main() { int sum = 0; cin >> n >> w; for (int i = 0; i < n; i++) { cin >> num[i].first; sum += num[i].first; num[i].first *= 2; num[i].second = i + 1; } if (n == 1) { if (2 * w != num[0].first) cout ...
16
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1.0); const long long inf = 1ll * (1e18); const int MAX = 26; const int mod = 10007; string s; int main() { while (cin >> s) { int l, r, e; e = s.size(); l = 0; while (l < e && s[l] == 'a') l++; if (l == e) { l = r = e - 1...
4
#include <bits/stdc++.h> using namespace std; int N, M; vector<int> edge[19 + 1]; long long F[1 << 19][19 + 1]; long long ans = 0LL; inline int GetStart(const int x) { for (int i = 0; i < 19; i++) if ((1 << i) & x) return i + 1; return -1; } int main() { scanf("%d %d", &N, &M); for (int i = 1; i <= M; i++) ...
14
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t; cin >> t; while (t--) { int n; cin >> n; int arr[n]; map<int, int> mp; int ws[n]; for (int i = 0; i < n; i++) { cin >> arr[i]; } int ans = 0; for (int sm...
4
#include <bits/stdc++.h> using namespace std; const int dx[] = {-1, 0, 1, 0, -1, -1, 1, 1}; const int dy[] = {0, -1, 0, 1, 1, -1, -1, 1}; bool a[2010][2010]; int n; int kp; short x[4000010], y[4000010]; bool u[2010][2010]; int s[2010][2010]; void dfs(int cx, int cy) { x[kp] = cx; y[kp] = cy; u[cx][cy] = true; k...
15
#include <bits/stdc++.h> using namespace std; const long long MOD = (1e9 + 7); const long long INF = (1e9 + 123456789); const long long INFL = (INF * INF); inline long long addm(long long a, long long b, long long m = MOD) { return ((a + b) % m); } inline long long subm(long long a, long long b, long long m = MOD) { ...
12
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; string s; int cnt1[N], cnt2[N], x[N], y[N], A[N], B[N]; int main() { cin >> s; int len = s.size(); for (int i = 0; i < len; i++) cnt1[s[i] - '0']++, cnt2[s[i] - '0']++; int ma = 0, tot1 = 0, tot2 = 0; int flag = 0; for (int i = 1; i < 10; ...
11
#include <bits/stdc++.h> using namespace std; int n; long long pref[100007]; int main() { scanf("%d", &n); pref[0] = 0; for (int i = 1; i <= n; i++) { int a; scanf("%d", &a); pref[i] = pref[i - 1] + a; } sort(pref + 1, pref + n + 1); int licz = 1, mx = 1; for (int i = 2; i <= n; i++) { if ...
13
#include <bits/stdc++.h> #pragma GCC optimize("O3") #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); template <class T> inline bool setmin(T &a, T b) { if (a > b) return a = b, 1; return 0; } template <class ...
18
#include <bits/stdc++.h> using namespace std; int isprime(long long int n) { int i, j; for (i = 2; i < n; i++) { if (n % i == 0) return 1; } return 0; } int main() { long long int n, x, y; cin >> n; if (n % 2 == 0) { x = n / 2; y = n / 2; while (isprime(x) != 1 || isprime(y) != 1) { ...
0
#include <bits/stdc++.h> using namespace std; const int mxN = 2e5 + 15; const int mod = 998244353; const long long INF = 1e9; using Matrix = vector<vector<long long>>; using vll = vector<long long>; using cd = complex<double>; const double PI = acos(-1); clock_t begtime = clock(); void solve() { string s; cin >> s;...
6