solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> using namespace std; const int MAXL = 1000111; char s[MAXL]; char t[MAXL]; int n, m; const int P = 101; const int MOD1 = 1E9 + 7, MOD2 = 1E9 + 9; int p1[MAXL], p2[MAXL]; int hash1[MAXL], hash2[MAXL]; void makeMemLim() { vector<int> x; for (int i = 0; i < 1000000000; i++) { x.push_back(i...
13
#include <bits/stdc++.h> using namespace std; int n, d; int arr[105]; int dp[105][105]; int solve(int left, int right) { if (right <= left) return 0; if (dp[left][right] != -1) return dp[left][right]; int val = arr[right] - arr[left]; if (val <= d) { return dp[left][right] = solve(left + 1, right - 1); } ...
4
#include <bits/stdc++.h> const int inf = (1ll << 31) - 1; const int maxn = (int)1e5 + 10; using namespace std; int n; string second; bool check(int x) { for (int i = 0; i < n; i++) { int cur = 5; int y = i; while (cur > 0) { if (y >= n || second[y] == '.') break; y += x; cur--; } ...
5
#include <bits/stdc++.h> using namespace std; const long double pi = 2 * acos(0.0); 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; } template <class T, class TT> bool pa...
17
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c, d, e, f, g, h, i, j; int ar[1000]; vector<int> v; cin >> a >> b; while (a--) { c = 0; d = 0; for (i = 0; i < 2 * b; i++) { cin >> e; c++; if (e == 1) { d = 1; } if (c % 2 == 0) { v...
0
#include <bits/stdc++.h> using namespace std; long long a1, a2, a3, a4, i; string append(string *s) { string four, sev, st; st = *s; for (i = 0; i < a1; i++) four += '4'; for (i = 0; i < a2; i++) sev += '7'; long long fr, sv; for (i = 0; i < int(st.size()); i++) { if (st[i] == '4') { st.insert(i, ...
10
#include <bits/stdc++.h> using namespace std; int n; map<long long, long long> acc; long long u, v, w; int main() { cin >> n; for (int i = 0; i < n; i++) { int type; cin >> type; if (type == 1) { cin >> u >> v >> w; while (u != v) { if (u < v) { acc[v] += w; v /= ...
7
#include <bits/stdc++.h> using namespace std; const int NMAX = 3000; int N; vector<int> g[NMAX + 2]; int root; int par[NMAX + 2][NMAX + 2]; int subtree[NMAX + 2][NMAX + 2]; long long dp[NMAX + 2][NMAX + 2]; void dfs(int node, int dady) { par[root][node] = dady; subtree[root][node] = 1; for (auto it : g[node]) ...
15
#include <bits/stdc++.h> using namespace std; bool cmp(pair<long long, long long> a, pair<long long, long long> b) { return (a.first < b.first || (a.first == b.first && a.second < b.second)); } int main() { map<string, string> thanosoclz; int n; thanosoclz["red"] = "Reality"; thanosoclz["yellow"] = "Mind"; ...
0
#include <bits/stdc++.h> using namespace std; int graph[88][88]; int dp[88][88][88]; bool v[88][88][88]; constexpr int INF = 1e9; int D(int now, int lim, int rem) { if (rem == 0) return 0; if (v[now][lim][rem] == false) { v[now][lim][rem] = true; dp[now][lim][rem] = INF; for (int i = now + 1; i <= lim; ...
13
#include <bits/stdc++.h> using namespace std; int n; vector<vector<int> > g(200200); pair<int, int> a[200200]; int main() { cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i].first; a[i].second = i; } sort(a + 1, a + n + 1); reverse(a + 1, a + n + 1); for (int i = 1; i <= n; i++) { g[i].push_b...
12
#include <bits/stdc++.h> using namespace std; const int N = 2022; const long long inf = 1LL << 60; int n, m, s, t; int p[N]; vector<pair<int, int> > edge[N]; vector<pair<long long, int> > sortor; long long mins[N], mint[N]; long long dp[N][N][2]; long long sum[N][N], cnt[N][N]; int si[N], ti[N]; void gao(int st, long l...
21
#include <bits/stdc++.h> using namespace std; int n; int was[26]; int gg[26]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n; int ans = 0; int can = -1; set<char> se; for (int i = 0; i < n; i++) { char c; string s; cin >> c >> s; if (c == '!') { se.clear(); if ...
8
#include <bits/stdc++.h> using namespace std; int f[1 << 17][200]; int rr[1 << 17], rb[1 << 17]; int sumr, sumb; int n, maxn; bool c[20]; int r[20], b[20]; int read() { int ans = 0, flag = 1; char ch = getchar(); while ((ch > '9' || ch < '0') && ch != '-') ch = getchar(); if (ch == '-') flag = -1, ch = getchar(...
16
#include <bits/stdc++.h> bool flag[50]; char s[10]; int main() { int n, p; scanf("%d%d", &n, &p); for (int i = 0; i < n; i++) { scanf("%s", s); flag[i] = strcmp(s, "half"); } double ans = flag[n - 1] ? 0.5 : 1; long long count = 1; for (int i = n - 2; i >= 0; i--) { if (flag[i]) { ans +=...
4
#include <bits/stdc++.h> using namespace std; template <typename T> T abs(T x) { return x > 0 ? x : -x; } struct node { node *l, *r; int size; int key; int pr; node() { l = r = NULL; size = 1; pr = rand(); } void update() { size = 1; if (l) size += l->size; if (r) size += r->size...
21
#include <bits/stdc++.h> using namespace std; using li = long long; using ld = long double; using pii = pair<int, int>; const int N = 1e5 + 13; const int INF = 1e9; const int MAXA = 10011; const int MAXB = 32; int dp[MAXA][MAXB]; vector<pii> g[MAXA][MAXB]; void dfs(int a, int b) { if (dp[a][b] != 0) return; int mx ...
12
#include <bits/stdc++.h> using namespace std; int main() { vector<int> q; vector<char> c; int sum = 0, sum1 = 0; for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) { char x; cin >> x; if (x == 'Q') sum += 9; else if (x == 'R') sum += 5; else if (x == 'B')...
1
#include <bits/stdc++.h> using namespace std; struct box { long long a, o; int num; } B[200010]; long long n, t; inline long long read() { long long cnt = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { cnt...
17
#include <bits/stdc++.h> using namespace std; void SieveOfErat() { bool prime[1000001]; memset(prime, true, sizeof(prime)); for (long long vec = 2; vec * vec <= 1000000; vec++) { if (prime[vec] == true) { for (long long dd = vec * 2; dd <= 1000000; dd += vec) prime[dd] = false; } } } long long gcd...
17
#include <bits/stdc++.h> using namespace std; const long long mod = 998244353; const int N = 5e3 + 5; const int inf = 2e9; const long long linf = 4e18; int a[N], b[N], c[N], dp[N][N], mx[N]; vector<int> adj[N]; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cerr.tie(0); int n, m, k; cin ...
13
#include <bits/stdc++.h> using namespace std; const int DIM = 1e5 + 5; int szt[DIM], dp1[DIM], dp2[DIM], lev[DIM]; vector<pair<int, int>> edg[DIM]; pair<int, int> lst[DIM], axl[DIM]; bitset<DIM> oki, axo; vector<int> aux, cen; inline int g(int x, int y) { return (x >= y) ? 1 : -1; } void findcent(int x, int f, int sz, ...
22
#include <bits/stdc++.h> using namespace std; int dx[] = {0, 1, -1, 0}; int dy[] = {1, 0, 0, -1}; long double PI = 3.14159265358979323846264338327950; long long f, s, x, y; bool valid(long long num) { long long dx, dy, dxy; dx = num / x; dy = num / y; dxy = num / (x * y); dx -= dxy; dy -= dxy; num -= dx, ...
10
#include <bits/stdc++.h> using namespace std; long long n, q, t, k, d; long long mp[105]; int main() { scanf("%I64d%I64d", &n, &q); for (long long i = 0; i < q; i++) { scanf("%I64d%I64d%I64d", &t, &k, &d); long long temp = 0, res = 0; for (long long i = 1; i <= n; i++) { if (mp[i] < t) { t...
5
#include <bits/stdc++.h> using namespace std; long long pi = 1000000000ll; long long hrr[3100], idt[3100]; string srr[3100]; vector<pair<int, int> > arr; int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); ; long long n, a, id, t; cin >> n; for (int i = 1; i <= n; i++) { cin >> s...
10
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int* h = new int[n]; for (int i = 0; i < n; i++) cin >> h[i]; int max = 0; for (int i = 0; i < n; i++) { int current = 0; int t = h[i]; for (int j = i; j >= 0; j--) { if (h[j] <= t) { current++; t =...
3
#include <bits/stdc++.h> using namespace std; const int _ = 1e2; const int maxn = 3e5 + _; const int mod = 998244853; inline int ad(int x, int y) { return x >= mod - y ? x - mod + y : x + y; } inline int re(int x, int y) { return x < y ? x - y + mod : x - y; } inline int mu(int x, int y) { return (long long)x * y % mod...
17
#include <bits/stdc++.h> using namespace std; const long long MAX = 5e2 + 5, N = 3e2 + 5; const long long MOD = 1e9 + 7, mod = 1e9 + 7; const string digits = "0123456789"; long long a[N][N], b[N][N]; void fil(long long n, long long k) { long long i = 0, j = 0; while (k > 0) { --k; a[i][j] = 1; i++; ...
8
#include <bits/stdc++.h> using namespace std; struct Trair { int x, y, z; Trair() { x = 0; y = 0; z = 0; } Trair(int _, int __, int ___) { x = _; y = __; z = ___; } }; bool operator<(const Trair &A, const Trair &B) { if (A.x == B.x) { if (A.y == B.y) { return A.z < B.z; ...
22
#include <bits/stdc++.h> using namespace std; const int inf = 1e9 + 5; int cnt; struct node { int l, r, Max, Min; } a[500000]; int d[500000]; void build(int x, int l, int r) { a[x].l = l, a[x].r = r; a[x].Max = -inf, a[x].Min = inf; if (l == r) { a[x].Max = d[l]; a[x].Min = d[l]; return; } else { ...
8
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } int main() { long long a, b, gc; long long ga, gb, gcc; cin >> a >> b; gc = gcd(a, b); gcc = a / gc * b; ga = gcc / a - 1; gb = gcc / b - 1; if (ga < gb) ga++; else if (ga >...
7
#include <bits/stdc++.h> using namespace std; struct _nl { } nl; bool _ns = 0; template <typename T> void _p(const T& _) { if constexpr (is_same<T, _nl>()) { cout << "\n"; _ns = 0; } else { if (_ns) cout << " "; cout << _; _ns = 1; } } template <typename... T> void out(const T&... _) { (_p(_...
9
#include <bits/stdc++.h> using namespace std; int a[25][25]; int main() { int n, cnt = 3; scanf("%d", &n); int c[] = {1, 2, 3, 5, 8, 13, 21, 30, 39, 53, 74, 95, 128, 152, 182, 212, 258, 316, 374, 413}; for (int i = 0; i < n; i++) { for (int j = 0; j < i; j++) { a[i][j] = a[j][...
15
#include <bits/stdc++.h> using namespace std; template <class T> inline void chkmin(T &a, T b) { if (a > b) a = b; } template <class T> inline void chkmax(T &a, T b) { if (a < b) a = b; } int B1, B2; int S1[210000], D1[210000], S2[210000], D2[210000]; int a[210000], b[210000], pos[210000]; int v1[210000 << 2], v2[2...
19
#include <bits/stdc++.h> using namespace std; string int_to_string(long long n) { string s = ""; while (n) { long long now = n % 10; s += now + '0'; n /= 10; } reverse(s.begin(), s.end()); return s; } long long string_to_int(string s) { long long n = 0; for (int i = 0; i < (int)(s.size()); i++...
9
#include <bits/stdc++.h> using namespace std; int main() { string s; int num1 = 0; int num2 = 0; int num3 = 0; cin >> s; for (int i = 0; i < s.length(); i++) { if (s[i] == '1') { num1++; } else if (s[i] == '2') { num2++; } else if (s[i] == '3') { num3++; } } for (int j ...
0
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } const int MAXN = 150000; typedef struct R { int p, t; long long mnx, mxx; } R; bool ratcmp(const R &a, const R &b) { return (long long)a.p * b.t > (long long)b.p * a.t; } bool pcmp(const R ...
20
#include <bits/stdc++.h> using namespace std; #pragma comment(linker, "/stack:200000000") #pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") using vi = vector<long long>; using vb = vector<bool>; using pii = pair<long long, long long>; using mii = map<long long, ...
9
#include <bits/stdc++.h> using namespace std; long long n, x, k; long long a[100010]; long long f(int l, int r) { if (l > r) swap(l, r); return a[r] / x - (a[l] - 1) / x; } int main() { ios_base::sync_with_stdio(0); cin >> n >> x >> k; for (int i = 1; i <= n; i++) cin >> a[i]; sort(a, a + n + 1); long lon...
9
#include <bits/stdc++.h> using namespace std; const int MAXN = 555; vector<int> s; int dp[MAXN][MAXN], is_palin[MAXN][MAXN]; vector<int> substr(int l, int r) { vector<int> ans; for (int i = l; i <= r; i++) ans.push_back(s[i]); return ans; } bool is(int l, int r) { vector<int> ans = substr(l, r); for (int i = ...
11
#include <bits/stdc++.h> using namespace std; long long power(long long x, long long y, long long m) { long long r = 1; for (; y; y >>= 1) { if (y & 1) r = r * x % m; x = x * x % m; } return r; } const long long N = 32, M = 1e9 + 7; int run_test() { long long n, k, l; cin >> n >> k >> l; long long...
11
#include <bits/stdc++.h> using namespace std; int main() { int n, t, m, s = 0, c = 0; cin >> n; t = n; while (n--) { cin >> m; s += m; } for (int i = 1; i <= 5; i++) { if (((s + i) % (t + 1)) != 1) { c++; } } cout << c; }
2
#include <bits/stdc++.h> using namespace std; int n, k; int p[31]; int main() { cin >> n >> k; int kk = k; vector<int> res; p[0] = 1; for (int i = 1; i <= 30; i++) { p[i] = p[i - 1] * 2; } while (1) { if (k == 0) { break; } int pos = -1; for (int i = 0; i <= 30; i++) { if (...
6
#include <bits/stdc++.h> struct tree { int lz; long long msk; int idx; }; char str[200200]; tree seg[200200 * 4]; void prop(int id, int l, int r) { if (seg[id].lz) { seg[id].idx += seg[id].lz; if (l != r - 1) { seg[(id << 1)].lz += seg[id].lz; seg[((id << 1) + 1)].lz += seg[id].lz; }; ...
11
#include <bits/stdc++.h> using namespace std; using LL = long long; int main() { ios::sync_with_stdio(false); cin.tie(0); int k; cin >> k; for (int n = 2; n <= 2000; ++n) { if (n * 1000000 <= k) continue; for (int i = 1; i <= 1000000; ++i) { if ((k + i) % n == 0) { int B = i - (k + i) / ...
12
#include <bits/stdc++.h> using namespace std; const long long N = 5e5 + 10; long long a[N]; long long n, k; void input() { cin >> n >> k; for (long long i = 1; i <= n; i++) cin >> a[i]; sort(a + 1, a + n + 1); } long long base, high; void add() { base = 0, high = 2e9 + 10; while (base < high) { long long ...
12
#include <bits/stdc++.h> using namespace std; int main() { int m, n; cin >> m >> n; cout << m * n / 2; return 0; }
0
#include <bits/stdc++.h> using namespace std; const long long int inf = 1e18; const int32_t m = 1e9 + 7; const int32_t mm = 998244353; void maxifier() { long long int n; cin >> n; vector<long long int> v(n), w; for (long long int i = 0; i < n; i++) { cin >> v[i]; } w = v; sort(v.begin(), v.end()); l...
3
#include <bits/stdc++.h> using namespace std; namespace io { string separator = " "; } template <typename T> inline void write(T x) { cout << x << io::separator; } template <typename T, typename... Args> inline void write(T x, Args... args) { write(x); write(args...); } inline void writeln() { cout << '\n'; } tem...
8
#include <bits/stdc++.h> using namespace std; const int maxn = 105; const int maxk = 30; const int INF = 1e9; int f[maxn]; char s[maxn], t[maxn], ans[maxn]; int n, k; void getfail(char *s, int len_s) { f[0] = f[1] = 0; for (int i = 1; i < len_s; i++) { int j = f[i]; while (j && s[i] != s[j]) j = f[j]; f...
13
#include <bits/stdc++.h> using namespace std; long long n, k; long long a[100005]; int main() { cin >> n >> k; for (int i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); long long cnt = a[n - 1] - a[0]; for (int i = 0; i < n / 2; i++) { long long d; if (i < n / 2 - 1 || n % 2 == 1) { d = min(a[i +...
12
#include <bits/stdc++.h> using namespace std; inline int read() { int X = 0, w = 0; char ch = 0; while (!isdigit(ch)) { w |= ch == '-'; ch = getchar(); } while (isdigit(ch)) X = (X << 3) + (X << 1) + (ch ^ 48), ch = getchar(); return w ? -X : X; } int a[600]; int dp[600][600]; int main() { int n, ...
10
#include <bits/stdc++.h> using namespace std; const int maxt = 100005 * 70; int tree[maxt], L[maxt], R[maxt]; int waktu, N; map<int, int> last; map<int, int> cnt; int all[400005]; tuple<int, int, int> ver[200005]; tuple<int, int, int> hor[100005]; void extend(int n, int l, int r) { if (L[n] == 0 && l != r) { L[n]...
15
#include <bits/stdc++.h> using namespace std; template <typename Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 << "\n"; } template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args) { const char* comma = strchr(names + 1, ','); cerr.write(nam...
2
#include <bits/stdc++.h> using namespace std; int head[5005 * 5005 / 2], nxt[5005 * 5005 / 2], sz[5005 * 5005 / 2], lst = 1; pair<int, int> to[5005 * 5005 / 2]; int arr[5005 + 100]; int cnt = 0; int n, k; void add_edge(int f, pair<int, int> p) { nxt[lst] = head[f]; head[f] = lst; sz[f]++; to[lst++] = p; } struc...
16
#include <bits/stdc++.h> using namespace std; const int L = 10000010; int id[L], son[L][2], fail[L]; int n, cnt = 1; int grid[755][755]; int rt = 1; int chk[755]; inline void insert(int &now, char *s, int iid) { if (now == 0) now = ++cnt; if (*s == 0) { if (id[now]) chk[iid] = 1; else id[now] = ...
24
#include <bits/stdc++.h> using namespace std; const int N = 1010, M = 30010, inf = 2e9 + 1; struct edge { int to, id; }; int n, m, s, t, u, v, w, timer, cur, Min; int was[N], c[M], tin[N], up[N]; vector<edge> g[N]; vector<int> path, br, ans; bool dfs1(int v, int to) { was[v] = 1; if (v == to) return 1; for (aut...
18
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> arr(n); for (int &i : arr) cin >> i; set<int> ss; int ans = 1; for (int i : arr) { if (ss.find(i) != ss.end()) ans++; ss.insert(i); } cout << ans; return 0; }
5
#include <bits/stdc++.h> using namespace std; const int mx = 7e3 + 10; int f[mx][2]; queue<pair<int, int> > q; bitset<mx> g[2][mx]; int deg[mx][2]; int main() { int n; scanf("%d", &n); for (int it = 0; it < 2; it++) { int cnt; scanf("%d", &cnt); for (int i = 0; i < cnt; i++) { int dx; scan...
12
#include <bits/stdc++.h> using namespace std; using ll = long long; template <typename Arg1> void __f(const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << endl; } template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args) { const char* comma = strchr(names + 1, ...
7
#include <bits/stdc++.h> using namespace std; template <class T> inline T abs(const T& x) { return x > 0 ? x : -x; } template <class T> inline T sqr(const T& x) { return x * x; } template <class T> inline string tostr(const T& a) { ostringstream os(""); os << a; return os.str(); } const int inf = 1999999999; ...
8
#include <bits/stdc++.h> using namespace std; const int MAXN = 300005; int n, m, ANS; char c[4]; string s[MAXN]; string t[MAXN]; string ans[MAXN]; void upd() { int cnt = 0; for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) cnt += (s[i][j] != t[i][j]); if (cnt < ANS) { ANS = cnt; for (int i = 0; ...
13
#include <bits/stdc++.h> int main(void) { int num, i; int a[1000]; int flag = 0; scanf("%d", &num); for (i = 0; i < num; i++) { scanf("%d", &a[i]); if (a[i] == 1) flag = 1; ; } if (flag == 1) printf("-1\n"); else printf("1\n"); }
2
#include <bits/stdc++.h> bool time_seed = 0; using namespace std; using namespace std::chrono; struct ListNode { int val; ListNode *next; ListNode(int x) : val(x), next(NULL) {} }; struct TreeNode { int val; TreeNode *left; TreeNode *right; TreeNode(int x) : val(x), left(NULL), right(NULL) {} }; void show...
10
#include <bits/stdc++.h> using namespace std; int main() { long long int n; scanf("%lld", &n); if (n & 1) { for (long long int i = 3; i * i <= n; i += 2) if (n % i == 0) { printf("%lld\n", ((n - i) >> 1) + 1); return 0; } printf("1\n"); } else printf("%lld\n", n >> 1); }
4
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e6; const int INF = 1e9 + 7; long long res = 0; int n, m, a[MAXN]; bool cmp(int x, int y) { return x > y; } int main() { int t; scanf("%d", &t); while (t--) { string str; cin >> str; res = 0; int len = str.size(); int k = 0, c = 0...
0
#include <bits/stdc++.h> using namespace std; int n; int f(char[], char[]); int main() { cin >> n; char s[50][50 + 1]; int num[50]; for (int i = 0; i < n; i++) scanf("%s", s[i]); num[0] = 0; for (int i = 1; i < n; i++) { num[i] = f(s[0], s[i]); if (num[i] == -1) { cout << "-1" << endl; r...
5
#include <bits/stdc++.h> using namespace std; int main() { int n, cnt, a[4], ans; cin >> a[1] >> a[2] >> n; a[0] = a[1] - a[2]; cnt = n / 3; n = n % 3; if (cnt % 2 == 0) ans = a[n]; else ans = -a[n]; while (ans < 0) ans += 1000000007; cout << ans % 1000000007 << endl; return 0; }
5
#include <bits/stdc++.h> #pragma GCC optimize("O3") #pragma GCC target("sse4") using namespace std; long long int ll_max(long long int a, long long int b, long long int c) { return max(a, max(b, c)); } const int inf = 0x3f3f3f3f; const long long int llinf = 0x3f3f3f3f3f3f; const int mod = 1000000007; const char nl = ...
5
#include <bits/stdc++.h> using namespace std; int main() { vector<pair<int, int> > a(3); for (int i = 0; i < 3; i++) { cin >> a[i].first >> a[i].second; } sort(a.begin(), a.end()); int ans = abs(a[0].first - a[1].first) + abs(a[0].second - a[1].second) + 1; int flag; if (a[2].second > a[0].second && a...
8
#include <bits/stdc++.h> #pragma GCC optimize("-O3") using namespace std; long long MOD = 1e9 + 7; double eps = 1e-6; long long mpow(long long a, long long b) { if (a == 0) return 0; if (b >= (MOD - 1)) b %= (MOD - 1); if (b == 0) return 1; long long t1 = mpow(a, b / 2); t1 *= t1; t1 %= MOD; if (b % 2) t1...
16
#include <bits/stdc++.h> using namespace std; const long long int MOD = 1000000007; const long long BIG = 1446803456761533460; const int Big = 336860180; stringstream sss; const long long int maxn = 1010; long long int n, k; long long int dp[maxn][maxn][4]; long long int first[maxn], ent[maxn][maxn], fact[maxn]; void M...
18
#include<bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 5; typedef long long ll; ll a[MAXN]; ll b[MAXN]; ll sum1[MAXN]; ll mi1[MAXN], mi2[MAXN]; ll sum2[MAXN]; int main() { int t; scanf("%d", &t); while (t--) { int n; scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%lld", &a[i]); i...
7
#include <bits/stdc++.h> using namespace std; inline int read() { int x = 0, fu = 0; char ch = getchar(); for (; ch < 48 || ch > 57; ch = getchar()) fu |= (ch == '-'); for (; ch > 47 && ch < 58; ch = getchar()) x = x * 10 + ch - '0'; return fu ? -x : x; } int n, head[100005], eot, fa[100005]; struct edge { ...
14
#include <bits/stdc++.h> using namespace std; template <typename T> void alert(const T& t) { cout << t; exit(0); } const long long MAX64 = 1 + 1e+18; const int MAX = 1 + 1e+9; const double PI = 3.1415926536; const long long CEL = 26; long long MID(long long l, long long r) { return (l + r) / 2; } long long LSON(lon...
8
#include <bits/stdc++.h> using namespace std; template <typename I> class iter_type { const I b, e; public: iter_type(I b, I e) : b(b), e(e) {} I begin() const { return b; } I end() const { return e; } size_t size() const { return e - b; } }; template <typename I> iter_type<I> iter(I b, I e) { return iter...
17
#include <bits/stdc++.h> using namespace std; int n; vector<int> lin[250000]; int in[250000]; int out[250000]; int tree[800002]; int an; int v[250000]; int idd[250000]; int Q; int num = 0; void push_down(int id) { tree[(id * 2 + 1)] += tree[id]; tree[(id * 2)] += tree[id]; tree[id] = 0; } void dfs(int x, int pre,...
12
#include <bits/stdc++.h> char s1[1000002]; int next[26][10001]; char s2[1000002]; int main() { scanf("%s%s", &s1, &s2); int len1 = strlen(s1), len2 = strlen(s2); int ans = 0; int i, j; for (i = 0; i < 26; i++) for (j = 0; j < len1; j++) next[i][j] = -1; for (i = 0; i < len1; i++) { j = i - 1; do...
7
#include <bits/stdc++.h> using namespace std; int main() { int w, x, y, z, a, b, c; cin >> w >> x >> y >> z; int arr[4]; arr[0] = w; arr[1] = x; arr[2] = y; arr[3] = z; sort(arr, arr + 4); cout << arr[3] - arr[0] << " " << arr[3] - arr[1] << " " << arr[3] - arr[2]; }
0
#include <bits/stdc++.h> using namespace std; int main() { cin.tie(0); ios_base::sync_with_stdio(0); float ac, ab, bc, a, b, c; cin >> ab >> bc >> ac; c = sqrt(ac * (bc / ab)); a = ac / c; b = ab / a; cout << 4 * a + 4 * b + 4 * c << "\n"; return 0; }
3
#include <bits/stdc++.h> #pragma GCC optimize("O2") #pragma GCC optimize("unroll-loops") using namespace std; long long power(long long a, long long b, long long md) { return (!b ? 1 : (b & 1 ? a * power(a * a % md, b / 2, md) % md : power(a * a % md, b / 2, md) % md)); } const int ...
22
#include <bits/stdc++.h> using namespace std; int ar[500005]; int vis[500005]; int use[100]; int br[6] = {4, 8, 15, 16, 23, 42}; int main() { int i, j, n, sz, cnt = 0, mx = 0, r; scanf("%d", &n); for (i = 0; i < n; i++) { cin >> ar[i]; ar[i] = lower_bound(br, br + 5, ar[i]) - br; } for (i = 0; i < n; ...
5
#include <bits/stdc++.h> using namespace std; int main() { int n, a[] = {1, 2, 3, 4, 6, 12}; scanf("%d", &n); char s[15]; vector<pair<int, int> > vct; for (int i = 1; i <= n; i++) { scanf("%s", s); for (int j = 0; j < 6; j++) { bool cnt[15]; memset(cnt, true, sizeof cnt); for (int k ...
2
#include <bits/stdc++.h> using namespace std; const int inf = 1e5 + 9; bool vis[inf]; vector<int> v[inf]; void dfs(int s) { vis[s] = true; for (int i = 0; i < v[s].size(); i++) { if (vis[v[s][i]] == 0) dfs(v[s][i]); } } int main() { int n, e, a, b, b2 = 0, b1 = 0, b3 = 0; cin >> n >> e; for (int i = 0; ...
4
#include <bits/stdc++.h> using namespace std; map<char, string> m; void populate() { m['0'] = "0000"; m['1'] = "0001"; m['2'] = "0010"; m['3'] = "0011"; m['4'] = "0100"; m['5'] = "0101"; m['6'] = "0110"; m['7'] = "0111"; m['8'] = "1000"; m['9'] = "1001"; m['A'] = "1010"; m['B'] = "1011"; m['C'...
10
#include <bits/stdc++.h> using namespace std; long long n, x, g, aux; vector<long long> primefact; long long best = 1; bool isprime(int x) { aux = sqrt(x); for (int i = 2; i <= aux; ++i) if (x % i == 0) return false; return true; } long long exp(int x, int k) { if (k == 0) return 1; aux = exp(x, k / 2); ...
18
#include <bits/stdc++.h> using namespace std; const int MAX = 1e4 + 5; int n, k; int arr[MAX]; double S; inline bool good(double x) { double lost = 0.0; for (int i = int(1); i < int(n + 1); i++) { if (x >= arr[i]) { double y = x - arr[i]; double need = (100.0 * y) / (100.0 - k); lost += need; ...
8
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10; int num[maxn]; int main() { int n, now = 0; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", &num[i]); if (i != num[i]) { continue; } now++; } if (now == n) { printf("%d", now); return 0; } for...
3
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; for (int test = 0; test < t; test++) { int n, p, k; cin >> n >> p >> k; vector<int> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } sort(a.begin(), a.end()); int pref = 0; int ans = 0; for (int...
8
#include <bits/stdc++.h> using namespace std; const int MAXN = 100010; const int INF = 100000000; class SegTree { public: SegTree(int _n, int _m) : n(_n), m(_m) { x = y = cx = cy = vector<int>(_n * 4); fx = fy = vector<bool>(_n * 4); for (int i = 0; i < 2; ++i) { for (int j = 0; j < 2; ++j) { ...
27
#include <bits/stdc++.h> using namespace std; long long prr[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, ...
7
#include <bits/stdc++.h> using namespace std; const int maxn = 1000 * 1000 + 10; long long a[maxn]; long long ma[maxn]; int n; inline long long dfs(int x) { if (2 * x < (1 << (n + 1))) ma[x] = max(a[2 * x] + dfs(2 * x), a[2 * x + 1] + dfs(2 * x + 1)); return ma[x]; } inline long long dfs2(int x, int l) { if (...
6
#include <bits/stdc++.h> using namespace std; const int INF = 1e9 + 5; const int MOD = 1000000007; const int MAX = 10000005; const double PI = acos(-1.0); long long vis[1000] = {0}; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long n, m; cin >> n >> m; vector<long long>...
4
#include <bits/stdc++.h> using namespace std; template <typename T> T next_int() { T x = 0, p = 1; char ch; do { ch = getchar(); } while (ch <= ' '); if (ch == '-') { p = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = x * 10 + (ch - '0'); ch = getchar(); } return x * p;...
10
#include <bits/stdc++.h> int main() { int n, sum, p, s = 0, r = 1, i = 4, j; scanf("%d", &n); while (i--) { scanf("%d", &p); s += p; } n--; for (j = 0; j < n; j++) { sum = 0; i = 4; while (i--) { scanf("%d", &p); sum += p; } if (sum > s) r++; } printf("%d", r); ...
0
#include <bits/stdc++.h> using namespace std; long long p[100005], vis[100005], ans[100005]; queue<long long> q; map<long long, vector<pair<long long, long long>>> e; map<long long, long long> c, d; int main() { long long n, a, b; cin >> n >> a >> b; for (long long i = 1; i <= n; i++) { cin >> p[i]; c[p[i...
12
#include <bits/stdc++.h> using namespace std; int main() { vector<long long> v, v1; v1.push_back(4); v1.push_back(8); v1.push_back(15); v1.push_back(16); v1.push_back(23); v1.push_back(42); long long a, b, c, d, e, first; cout << "? " << 1 << " " << 1 << "\n"; cin >> a; for (long long i = 0; i < v...
6
#include <bits/stdc++.h> static int t; static int n, k, start; static int dp[3][111]; static char s[3][111]; int f(int x, int y) { if (y >= n) return 1; if (dp[x][y] != -1) return dp[x][y]; int ret = 0; if (s[x][y + 1] == '.') { if (s[x][y + 2] == '.' && s[x][y + 3] == '.') ret |= f(x, y + 3); if (x > 0...
9
#include <bits/stdc++.h> using namespace std; int h[3]; int a[3]; int d[3]; int cost(int i, int j) { if (i <= d[1]) return 1000000000; if (j >= a[1]) return (i - a[0]) * a[2] + (j - d[0]) * d[2]; int l = (int)ceil(h[1] / (double)(i - d[1])); l = l * (a[1] - j); l++; if (l <= h[0]) return (i - a[0]) * a[2] +...
10
#include <bits/stdc++.h> using namespace std; long long binpow(long long a, long long n, long long INF) { long long res = 1; while (n) { if (n & 1) res = (res * a) % INF; a = (a * a) % INF; n >>= 1; } return res; } bool checkCyclic(int base, int prime) { for (int i = 2; i * i < prime; ++i) { i...
18