solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> const int inf = 1 << 30; const long long INF = 1ll << 61; using namespace std; int nnum[200000 + 55]; int n; void init() {} bool input() { while (cin >> n) { for (int i = 0; i < n; i++) cin >> nnum[i]; return false; } return true; } void cal() { long long ans = 0; long long la...
16
#include <bits/stdc++.h> using namespace std; const int MAXN = 100100, INFTY = 0x3f3f3f3f; int A[MAXN], B[MAXN]; vector<int> p[MAXN]; int posb[330]; int resp[330]; int main() { int N, M, S, E; posb[0] = 0; resp[0] = 0; for (int i = 1; i <= 300; i++) { posb[i] = MAXN; resp[i] = INFTY; } scanf("%d %d ...
15
#include <bits/stdc++.h> int n, x[100005], a, b; int main() { int i, t, tt, ans; scanf("%d", &n); for (i = 0; i < n; i++) scanf("%d", &x[i]); scanf("%d%d", &a, &b); std::sort(x, x + n, std::greater<int>()); n = std::unique(x, x + n) - x; ans = 0; while (a != b) { tt = a - 1; for (i = 0; i < n; i...
14
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; long long ans = 0; for (int i = (0); i < (n); ++i) { long long t, T, x, cost; cin >> t >> T >> x >> cost; if (t >= T) { ans += cost + m * x; continue; } long long aux1 = cost; if (m > (T - t))...
11
#include <bits/stdc++.h> using namespace std; using pii = pair<int, int>; using ll = long long; const int MN = 502; int dp[MN][MN]; int dp2[MN][MN]; string ree[MN][MN]; int par[MN][MN]; char s[MN], fin[MN]; int main() { scanf("%s", s + 1); int n = strlen(s + 1), K; scanf("%d", &K); for (int i = 1; i <= n; i++) ...
11
#include <bits/stdc++.h> using namespace std; inline int setBit(int N, int pos) { return N = N | (1 << pos); } inline int resetBit(int N, int pos) { return N = N & ~(1 << pos); } inline bool checkBit(int N, int pos) { return (bool)(N & (1 << pos)); } vector<vector<int> > v; void induction(int n) { for (int i = (n % 2...
20
#include <bits/stdc++.h> using namespace std; int a, b; double Xcu, Xms; double len() { if (Xcu / 2 < b) return -1; int l = 0, r = 1000000007; while (r - l > 1) { int middle = ((l + r) >> 1); double x = Xcu / (middle * 2); if (x >= b) l = middle; else r = middle; } return Xcu / (l ...
9
#include <bits/stdc++.h> using namespace std; const int DX[8] = {1, -1, 0, 0, 1, 1, -1, -1}; const int DY[8] = {0, 0, 1, -1, 1, -1, 1, -1}; const int intmax = 0x7fffffff; const int mod = 1000000007; int f[105]; int a[15][105], b[15][105], c[15][105]; int v[105], cc[105]; pair<int, int> p[105]; int n, m, nk; int saya() ...
4
#include <bits/stdc++.h> using namespace std; const int block_size = 320; const long long mod = 1e9 + 7; const long long inf = 1e9 + 7; const long double eps = 1e-9; const double PI = atan(1) * 4; template <typename T> inline int sign(const T &a) { if (a < 0) return -1; if (a > 0) return 1; return 0; } template <...
17
#include <bits/stdc++.h> using namespace std; long long n, a[22 * 22], b[22][22]; map<long long, long long> m; bool comp(pair<long long, long long> a, pair<long long, long long> b) { if (a.second == b.second) return 1; return a.second > b.second; } void solve() { cin >> n; for (__typeof((n * n + 1)) i = (1); i ...
9
#include <bits/stdc++.h> using namespace std; const int maxn = 2e6; long long n; long long ans; void in(); void solve(); void out(); int main() { in(); solve(); out(); } void in() { ios::sync_with_stdio(false); cout.tie(0); cin.tie(0); cin >> n; } void solve() { long long wow = 1; while (wow <= n - 1)...
11
#include <bits/stdc++.h> using namespace std; const long long int mod = 1e9 + 7; const long long int inf = 1e18 + 1e17; const long long int N = 1e5 + 6; long long int modInverse(long long int a, long long int m) { long long int m0 = m; long long int y = 0, x = 1; if (m == 1) return 0; while (a > 1) { long l...
12
#include <bits/stdc++.h> char C[1005]; int n, M[1005], MM[1005]; int main() { scanf("%d", &n); scanf("%s", C); M[n - 1] = 1; for (int i = n - 2; i >= 0; i--) { if (C[i] == 'L') M[i] = M[i + 1] + 1; if (C[i] == '=') M[i] = M[i + 1]; if (C[i] == 'R') M[i] = 1; } MM[0] = 1; for (int i = 1; i < n;...
10
#include <bits/stdc++.h> using namespace std; pair<int, int> a[100 + 7]; double dist(int x, int y) { return sqrt(x * x + y * y); } int main() { int n, k; while (scanf("%d %d", &n, &k) == 2) { double sum = 0.0; for (int i = 0; i < n; i++) { scanf("%d %d", &a[i].first, &a[i].second); } for (int ...
1
#include <bits/stdc++.h> using namespace std; struct segtree { long long int seg[512 * 1024 * 2], add[512 * 1024 * 2]; int mum; void init(int n) { mum = 1; while (mum < n) mum <<= 1; for (int i = 0; i < mum * 2; i++) seg[i] = add[i] = 0; } void update(int a, int b, int k, int l, int r, long long i...
20
#include <bits/stdc++.h> using namespace std; const long long LLINF = 9223372036854775807LL; const int INF = 2147483647; const int MOD = 1000000007; const double eps = 1e-7; const double PI = acos(-1.0); int dr[] = {1, 0, -1, 0, -1, 1, 1, -1}; int dc[] = {0, -1, 0, 1, 1, 1, -1, -1}; int main() { string s1, s2; cin ...
3
#include <bits/stdc++.h> using namespace std; const int MAXN = (int)1e5 + 7; int n; vector<int> G[MAXN]; int dep[MAXN]; set<pair<int, int> > se; int vis[MAXN]; queue<int> qu; inline void change(int x, int val) { int de = dep[x]; pair<int, int> tmp = make_pair(de, x); if (se.count(tmp)) { se.erase(tmp); } ...
14
#include <bits/stdc++.h> using namespace std; const int maxn = 500010; int n, f[maxn], ans; char s[maxn]; unsigned long long base[maxn], hashh[maxn]; set<unsigned long long> S; unsigned long long gethash(int l, int r) { return hashh[r] - hashh[l - 1] * base[r - l + 1]; } bool check(int pos, int len) { unsigned long...
25
#include <bits/stdc++.h> using namespace std; vector<pair<int, int> > ans; int main() { int n, d, h; scanf("%d %d %d", &n, &d, &h); int N = n - 1; int it = 1; int con = 1; if (d == 1 && h == 1) { if (n == 2) { printf("1 2"); } else { printf("-1"); } return 0; } if (h == d) { ...
8
#include <bits/stdc++.h> using namespace std; int main() { long long i, j, k, l, n, m, t; map<long long, long long> mp; cin >> n >> m; for (i = 0; i < n; i++) { cin >> j; mp[j] = 1; } i = 1; l = m; vector<long long> ans; while (l > 0) { if (i > l) { break; } if (mp.find(i) ==...
4
#include <bits/stdc++.h> using namespace std; const int N = 20; const int M = (1 << 16) + 7; int n, K, a[N]; bitset<2007> f[M]; vector<int> vec; void Dfs(int i, int j) { if (!i) return; for (int k = 0; k < n; k++) if ((i >> k & 1) && j - a[k] >= 0 && f[i ^ (1 << k)][j - a[k]]) { Dfs(i ^ (1 << k), j - a[k]...
23
#include <bits/stdc++.h> using namespace std; int main() { int x, y, r; cin >> x >> y >> r; if (x < r * 2 || y < r * 2) cout << "Second\n"; else cout << "First\n"; return 0; }
8
#include <bits/stdc++.h> using namespace std; int main() { long long n, m, k; cin >> n >> m >> k; if (n + m - 2 < k) { printf("-1\n"); return 0; } long long ans = 0, que, eid, j; for (long long i = 1; i * i <= n; i++) { if (k < i - 1) continue; que = n / i; eid = m / (k - i + 2); ans...
9
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int n, m; cin >> n >> m; vector<array<int, 2>> a(n); for (int i = 0; i < n; i++) cin >> a[i][0] >> a[i][1]; vector<array<int, 2>> b(m); for (int i = 0; i < m; i++) cin >> b[i][0] >> b[i][1]; vector<array<in...
12
#include <bits/stdc++.h> using namespace std; int n, m, cnt, T, opt, M, Q; int a[7010][4], b[7010][2]; int l[120010], r[120010], vis[1000010]; char ch; inline void read(int &x) { for (ch = getchar(); ch < '0' || ch > '9'; ch = getchar()) ; for (x = 0; ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - 48...
16
#include <bits/stdc++.h> using namespace std; const long long INF = (long long)1e18; long long n, k, vec[100005], s; long long find(long long x) { return vec[x] == x ? x : (vec[x] = find(vec[x])); } void merge(long long x, long long y) { x = find(x), y = find(y); if (x != y) vec[y] = x; } int main() { long long...
9
#include <bits/stdc++.h> using namespace std; using pii = pair<int, int>; const int N = 1e5 + 10; vector<int> vec[N]; int flag[N]; set<pii> st; int a[N], b[N], c[N], d[N]; void solve() { int n; scanf("%d", &n); st.clear(); int first, second; scanf("%d %d", &first, &second); for (int i = 1; i <= n + 1; i++) ...
17
#include <bits/stdc++.h> using namespace std; string s; int main() { cin >> s; int ssz = s.size(); int res = 1, run = 1; for (int i = 1; i < ssz; i++) { if (s[i] == '1') { run++; if (run <= 2) res++; } else if (i + 1 < ssz && s[i + 1] == '1' && run > 1) { res++; } else { run ...
11
#include <bits/stdc++.h> using namespace std; long long arr[(1 << 21) + 20]; vector<long long> tree[4 * (1 << 21)]; long long normal[25]; long long rev[25]; bool check[25]; void merge_sort(long long node, long long a, long long b, long long lev) { if (a == b) { tree[node].push_back(arr[a]); return; } long...
13
#include <bits/stdc++.h> using namespace std; const double eps = 1e-9; pair<pair<long long, long long>, pair<long long, long long> > rec[200000], pref[200000], pref2[200000]; int main() { ios_base::sync_with_stdio(false); long long n, i, a, b, c, d, e, f, g, h, k1, k2, k3, k4, x, y; cin >> n; for (i = 0; i ...
8
#include <bits/stdc++.h> using namespace std; struct Node { vector<int> neib; vector<int> ednum; bool done; }; Node* nodes; vector<int>* days; void dfs(int nodeNum, int parentDay) { int day = 0; nodes[nodeNum].done = true; for (int i = 0; i < (int)nodes[nodeNum].neib.size(); i++) { if (day == parentDay)...
10
#include <bits/stdc++.h> using namespace std; const int MAXN(300000); int n; int pos(1); int root[MAXN + 1]; struct Node { int l, r, val; } s[6000010]; void Update(int &curr, const int p, const int l, const int r, const int val) { curr = pos++; s[curr].val = s[p].val + 1; if (l == r) return; int mid(l + ((r -...
17
#include <bits/stdc++.h> using namespace std; int main() { long long int t = 1; cin >> t; while (t--) { long long int n; cin >> n; long long int a[n], b[n], c[n], p[n]; for (long long int i = 0; i < n; i++) cin >> a[i]; for (long long int i = 0; i < n; i++) cin >> b[i]; for (long long int ...
0
#include <bits/stdc++.h> using namespace std; int dx[4] = {1, -1, 0, 0}; int dy[4] = {0, 0, 1, -1}; const long long MOD = 1e9 + 9; long long n, a, b, k, q, r; char s[100005]; long long pow_(long long a, long long b) { if (b == 0) return 1; if (b == 1) return a % MOD; if (b % 2 == 0) return pow_((a * a) % MOD, b /...
10
#include <bits/stdc++.h> using namespace std; void solve() { vector<long long> b(7); for (long long i = 0; i < 7; i++) cin >> b[i]; cout << b[0] << " " << b[1] << " " << b[6] - (b[0] + b[1]) << endl; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ; long long t; cin >> t; while (t-...
0
#include <bits/stdc++.h> int n, q; char s[40][3], t[40][2]; char r[10]; int ans = 0; bool check() { char now = r[0]; for (int i = 1; i < n; i++) { bool f = false; for (int j = 0; j < q; j++) { if (s[j][0] == now && s[j][1] == r[i]) { f = true; now = t[j][0]; break; } ...
5
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int t; cin >> t; while (t--) { int c, m, x; cin >> c >> m >> x; int total = c + m + x; int l = 0, h = total; while (h - l > 1) { int mid = l + (h - l) / 2; if (c >= mid && m >= ...
4
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; vector<long long> arr(n); for (int i = 0; i < n; i++) cin >> arr[i]; long long maxi = *max_element(arr.begin(), arr.end()); long long dp[maxi + 1]; map<long long, long long> mp; for (auto x : arr) mp[x]++; dp[0] = 0; d...
7
#include <bits/stdc++.h> char map[2000][2000 + 1]; bool toggle[3][2000]; int ans; int n; void cal(int r, int c, int shiftR, int shiftC) { const int initR = r; memset(toggle[0], 0, sizeof(toggle[0])); memset(toggle[1], 0, sizeof(toggle[1])); while (r != c) { if ((map[r][c] == '1') != (toggle[0][r] ^ toggle[1...
12
#include <bits/stdc++.h> using namespace std; const int inf = 1e9; const long long Inf = 1e18; const int N = 110; const int mod = 1e9 + 7; int gi() { int x = 0, o = 1; char ch = getchar(); while ((ch < '0' || ch > '9') && ch != '-') ch = getchar(); if (ch == '-') o = -1, ch = getchar(); while (ch >= '0' && ch...
18
#include <bits/stdc++.h> using namespace std; vector<pair<int, int> > asd; int ans[100005]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int z; cin >> z; int a, s; for (int q = 1; q <= z; q++) { cin >> a; asd.push_back(make_pair(a, q)); } sort(asd.begin(), asd....
7
#include <bits/stdc++.h> const int BLOCK = 400; int fs[100005]; int gs[100005]; std::vector<int> edges[100005]; int pre[100005]; int post[100005]; int euler = 0; int who[200005]; bool has[100005]; int depth[100005]; int anc[100005][20]; void dfs_init(int node, int parent) { who[euler] = node; pre[node] = euler++; ...
15
#include <bits/stdc++.h> using namespace std; const int MAX = 1e6 + 10; const int INF = 0x3fffffff; long long Gcd(long long a, long long b) { return (b == 0) ? a : Gcd(b, a % b); } int main() { long long n, k; while (scanf("%lld%lld", &n, &k) != EOF) { long long t = 1; for (int i = 0; i < k; i++) t *= 10; ...
3
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; pair<int, int> ans[N]; bool solve(int n, vector<pair<int, int> > &in, vector<pair<int, int> > &out) { int l = 1, r = n; int id1 = in.size() - 1, id2 = out.size() - 1; set<pair<int, int> > s; for (int i = 0; i < (n - 1); ++i) { if (i & 1) ...
9
#include <bits/stdc++.h> using namespace std; long long n, m, k, i, j, a[1003][1003] = {0}, visi[1003][1003] = {0}, cnt, V, d[1003][1003] = {0}; struct s { long long value, x, y; }; bool cmp(s lhs, s rhs) { return lhs.value < rhs.value; } vector<s> b; s p[1003][1003]; s fp(long long xx, long ...
12
#include <bits/stdc++.h> using namespace std; const int N = 6005; int l[N], r[N]; int dp[N][N]; int main() { int tc = 1; cin >> tc; set<int> com; while (tc--) { int n; cin >> n; for (int i = 0; i < n; i++) { cin >> l[i] >> r[i]; com.insert(l[i]); com.insert(r[i]); } map<int...
15
#include <bits/stdc++.h> using namespace std; const int inf = 2000000000; static inline int Rint() { struct X { int dig[256]; X() { for (int i = '0'; i <= '9'; ++i) dig[i] = 1; dig['-'] = 1; } }; static X fuck; int s = 1, v = 0, c; for (; !fuck.dig[c = getchar()];) ; if (c == '-'...
11
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 9, inf = 0x7fffffff; struct D { int id, v; D(int _id = 0, int _v = 0) : id(_id), v(_v) {} bool operator<(const D &o) const { return v < o.v; } }; vector<D> d; int n, h, o[N]; int check(int i, int a0, int a1) { int minf = inf, maxf = -inf; minf ...
10
#include <bits/stdc++.h> using namespace std; const int N = 301; int a[N][N], b[N][N]; int fa[N * N]; int n, m, Q; struct node { int x, y, c; node(int x = 0, int y = 0, int c = 0) : x(x), y(y), c(c) {} } q[2001001]; vector<node> c[2001001], d[2001001]; int ans[2001001]; int getfa(int x) { return x == fa[x] ? x : fa...
20
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long a, s, mn = 0, d, f = 0, i, j; double dp; vector<long long> ve, ne; cin >> a; for (i = 0; i < a; i++) { cin >> d; ve.push_back(d); } for (i = 0; i < a; i++) { mn += ...
3
#include <bits/stdc++.h> using namespace std; int main() { long long n, a[301][301], k, a1, b, c, sum = 0; scanf("%I64d", &n); memset(a, 0, sizeof(a)); for (int i = 1; i <= n; ++i) { for (int j = 1; j <= n; ++j) { scanf("%I64d", &a[i][j]); } } scanf("%I64d", &k); while (k--) { scanf("%I6...
11
#include <bits/stdc++.h> using namespace std; vector<int> v; int main() { v.push_back(2); v.push_back(3); v.push_back(5); v.push_back(7); v.push_back(13); v.push_back(17); v.push_back(19); v.push_back(31); v.push_back(61); v.push_back(89); v.push_back(107); v.push_back(127); v.push_back(521); ...
13
#include <bits/stdc++.h> using namespace std; int n, m; int a[1005]; int num[1005]; char tt[1005]; int dp[(1 << 20) + 5]; int kol[(1 << 20) + 5]; inline bool cmp(int a, int b) { return a > b; } int main() { cin >> n; for (int i = 1; i <= n; ++i) cin >> a[i]; sort(a + 1, a + n + 1, cmp); cin >> m; for (int i =...
14
#include <bits/stdc++.h> using namespace std; struct TreeNode { int val; TreeNode* left; TreeNode* right; TreeNode(int x) : val(x), left(NULL), right(NULL) {} }; struct ListNode { int val; ListNode* next; ListNode(int x) : val(x), next(NULL) {} }; int nxt() { int x; cin >> x; return x; } long long n...
14
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; multiset<int> stl, str; vector<pair<int, int>> v; for (int i = 1; i <= n; ++i) { int a, b; scanf("%d %d", &a, &b); v.push_back(make_pair(a, b)); stl.insert(a); str.insert(b); } if (n == 1) { cout << v[0].se...
8
#include <bits/stdc++.h> using namespace std; const int N = 2 * 1e3 + 3; int n; int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); int tt; cin >> tt; for (int qq = 1; qq <= tt; ++qq) { cin >> n; vector<int> a(n + 1, 0); vector<vector<int>> mx(n + 1, vector<int>(n + 1, 0)); vector<vecto...
9
#include <bits/stdc++.h> int dx[] = {0, -1, 0, 1, -1, 1, -1, 1}; int dy[] = {-1, 0, 1, 0, 1, -1, -1, 1}; const int MOD = 1e9 + 7, N = 1e6 + 5, oo = 1e9; const double pi = acos(-1); using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); string a, b; cin >> a >> b; int ans = ...
4
#include <bits/stdc++.h> using namespace std; const int MAX_N = 2e5 + 10, MAX_LOG_N = 19; int n; int Arr[MAX_N]; int seg[MAX_LOG_N][MAX_N]; void build(int s = 0, int e = n, int lvl = 0) { if (e - s == 1) { seg[lvl][s] = Arr[s]; return; } int mid = e + s >> 1; build(s, mid, lvl + 1); build(mid, e, lvl ...
14
#include <bits/stdc++.h> using namespace std; long long a = LLONG_MIN, b = LLONG_MIN, c = LLONG_MIN, d; int n, p, q, r; int main() { cin >> n >> p >> q >> r; for (int i = 0; i < n; i++) { cin >> d; a = max(a, p * d); b = max(b, a + q * d); c = max(c, b + r * d); } cout << c; }
7
#include <bits/stdc++.h> using namespace std; char s[400009], r[400009]; int p[400009], h[400009], rh[400009]; int n, m; int ok(int i, int x) { if (++i < x) return 1; return ((rh[i] - rh[i - x] * p[x]) * p[i - x]) != (h[i] - h[i - x]); } int go(int d, int t) { if (d == n) return puts(r), 1; for (r[d] = (t ? s[d...
20
#include <bits/stdc++.h> using namespace std; const int maxn = 205; int n, k; vector<int> G[maxn]; int dp[maxn][maxn], a[maxn]; void dfs(int x, int f = 0) { dp[x][0] = a[x]; for (int v : G[x]) { if (v == f) continue; dfs(v, x); dp[x][0] += dp[v][k]; } for (int i = 1; i < n; i++) { for (auto it :...
14
#include <bits/stdc++.h> #pragma GCC optimize("Ofast", "unroll-loops", "no-stack-protector") using namespace std; using ll = long long; using ld = long double; using pii = pair<int, int>; using uint = unsigned int; using ull = unsigned long long; mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); defa...
9
#include <algorithm> #include <iostream> #include <cassert> #include <cstdlib> #include <cstring> #include <utility> #include <bitset> #include <cstdio> #include <string> #include <vector> #include <cmath> #include <queue> #include <set> #include <map> using namespace std; using ll = long long; using pii = pair<int,in...
13
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 5; const int maxm = 5000 + 5; const int MOD = 1e9 + 7; int mp[110][110]; int n, m; int p[maxn]; vector<int> ans; void Floyd(int len) { for (int k = 0; k < len; k++) for (int i = 0; i < len; i++) for (int j = 0; j < len; j++) mp[i][...
9
#include <bits/stdc++.h> int n, m, x, y; int func(int x, int y) { return (x % y == 0 ? y : func(y, x % y)); } int main() { scanf("%d %d %d %d", &n, &m, &x, &y); int k = n * m / (m > n ? func(m, n) : func(n, m)); printf("%d\n", y / k - ((x - 1) / k + 1) + 1); scanf("\n"); }
4
#include <bits/stdc++.h> using namespace std; int n, k, a[(int)(1e6 + 10)], dp[(int)(1e6 + 10)]; int main() { cin >> n >> k; for (int i = 1; i <= n; i++) scanf("%d", &a[i]); sort(a + 1, a + n + 1); n = unique(a + 1, a + n + 1) - (a + 1); for (int i = 2; i <= n; i++) a[i] -= a[1]; memset(dp, 4, sizeof dp); ...
16
#include <bits/stdc++.h> using namespace std; const double eps = 1e-9; double Abs(double a) { if (a > 0) return a; return -a; } int main() { int t, s, q; cin >> t >> s >> q; double sp = (double)(q - 1) / (double)(q); double i = 0; int cnt = 0; double ans = (double)s; do { cnt++; double add = a...
7
#include <bits/stdc++.h> using namespace std; const int INF = 1e9 + 7; const int MOD = 1e9 + 7; const int MAXN = 1e6 + 3; struct Rcompare { bool operator()(pair<int, int> lhs, pair<int, int> rhs) { return lhs.first > rhs.first; } }; struct compare { bool operator()(pair<int, int> lhs, pair<int, int> rhs) { ...
13
#include <bits/stdc++.h> using namespace std; int n, a[200001], b[200001]; long long ans; deque<int> mxx, mnn; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d", &a[i]); for (int i = 1; i <= n; i++) scanf("%d", &b[i]); for (int i = 1, j = 1; i <= n; i++) { while (!mxx.empty() and a[mxx.b...
13
#include <bits/stdc++.h> using namespace std; int N; int a[1002]; int s[200000]; void Read() { cin >> N; for (int i = 1; i <= N; ++i) cin >> a[i]; for (int i = 1; i < N; ++i) for (int j = i + 1; j <= N; ++j) s[a[i] + a[j]]++; int nrc = 0; for (int i = 1; i <= 199999; ++i) nrc = max(nrc, s[i]); cout << n...
4
#include <bits/stdc++.h> const long long MOD7 = 1000000007; int calc(int n, int x, int y) { int rp = ceil(y / 100.0 * n); return x >= rp ? 0 : rp - x; } using namespace std; int main() { ios::sync_with_stdio(0); int n, x, y; cin >> n >> x >> y; cout << calc(n, x, y) << "\n"; return 0; }
1
#include <bits/stdc++.h> using namespace std; const int N = 4000001; const int oo = -1; int lb[N]; int rb[N]; int vs[N]; char s[N]; int n; void update(int lq, int rq, char v, int li, int ri, int c) { if (rq < li || ri < lq) return; if (lq <= li && ri <= rq) { if (v == '(') lb[c] = 1; else rb[c] ...
12
#include <bits/stdc++.h> using namespace std; string S; map<char, int> conv; int main() { conv['<'] = 1; conv['{'] = 2; conv['('] = 3; conv['['] = 4; conv['>'] = -1; conv['}'] = -2; conv[')'] = -3; conv[']'] = -4; cin >> S; stack<char> stk; int ans = 0; for (char ch : S) { if (ch == '<' || c...
6
#include <bits/stdc++.h> using namespace std; int n, t; char s[1100000]; long long st[100000l], l = 0; long long sum[2] = {0}; int main() { gets(s); if (s[0] == '-') { sum[1] = 1; st[l++] = -1; } else { sum[0] = 1; st[l++] = 1; } long long pre = 0; for (int i = 1; s[i]; i++) { if (s[i] =...
10
#include <bits/stdc++.h> using namespace std; vector<string> a; int p[509][509]; int memo[509][509], memo1[509][509], n, m, k; int dp1(int i, int j) { if (memo1[i][j] != -1) { return memo1[i][j]; } else { int totalLessons = 0; for (int k = 0; k < m; k++) { totalLessons += a[i][k] - '0'; } ...
10
#include <bits/stdc++.h> long long gi() { long long x = 0, f = 1; char ch = getchar(); while (!isdigit(ch)) f ^= ch == '-', ch = getchar(); while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar(); return f ? x : -x; } int n, ans[101][101][101]; void output(bool o = 0) { int xl = 1000, xr = 0, yl = 1000, y...
19
#include <bits/stdc++.h> using namespace std; int main() { long x, y, m, i, ac, sum = 0; vector<int> perm; vector<int> a; cin >> m; for (i = 0; i < m; i++) { cin >> ac; perm.push_back(ac); } cin >> x >> y; for (i = 0; i < m; i++) { sum = sum + perm[i]; a.push_back(sum); } int res = 0...
2
#include <bits/stdc++.h> using namespace std; int main(void) { string s; cin >> s; int k; cin >> k; vector<pair<int, char> > vec; map<char, int> mp; for (int i = 0; i < s.size(); i++) { mp[s[i]]++; } for (map<char, int>::iterator it = mp.begin(); it != mp.end(); it++) { vec.push_back(make_pair...
4
#include <bits/stdc++.h> using namespace std; const int N = (int)3e5 + 10; int n, a[N], p[N]; const int P = (int)1e9 + 7; struct SegmentTree { int H[N * 5]; int L[N * 5], R[N * 5]; void Build(int k, int x, int y) { L[k] = x; R[k] = y; if (L[k] == R[k]) return void(H[k] = 0); Build(k << 1, L[k], ((...
19
#include <bits/stdc++.h> using namespace std; int main() { int n; while (cin >> n) { string str; cin >> str; int num[1001] = {1}; for (int i = 0; i < str.size(); ++i) { if (str[i] == 'R') num[i + 1] = num[i] + 1; if (str[i] == '=') num[i + 1] = num[i]; if (str[i] == 'L') { ...
10
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); string a, b; int even = 1, beg = 0; int ans = 0; int i; cin >> a >> b; int f = b.length(); for (i = 0; i < f; i++) if (a[i] != b[i]) even = 1 - even; ans += even; for (i = f; i <...
10
#include <bits/stdc++.h> using namespace std; int cap[50][50]; int main() { int n; scanf("%d", &n); int cnt = 0; int x = 0; int y = n / 2; cap[x][y] = ++cnt; while (cnt < n * n) { x = x - 1; y = y + 1; if (x == -1 && y == n) { x = 1; y = n - 1; } else if (x < 0) { x = n -...
7
#include <bits/stdc++.h> using namespace std; long long n, k, a[1000010], b[1000010]; int check(long long x) { long long cnt = 0LL; for (int j = 0; j < n; j++) { cnt += max(x * a[j] - b[j], 0LL); if (cnt > k) { return 0; } } if (cnt <= k) return 1; else return 0; } int main() { cin...
7
#include <bits/stdc++.h> using namespace std; int main() { char str[10]; cin >> str; if (str[0] == 'a' && str[1] == '1' || str[0] == 'h' && str[1] == '1' || str[0] == 'a' && str[1] == '8' || str[0] == 'h' && str[1] == '8') cout << '3' << endl; else if (str[0] == 'a' || str[0] == 'h' || str[1] == '1' |...
0
#include <bits/stdc++.h> using namespace std; vector<int> factors(int x) { vector<int> r; for (int i = 2; i * i <= x; ++i) { if (x % i == 0) r.push_back(i); while (x % i == 0) x /= i; } if (x != 1) r.push_back(x); return r; } int isprime(int x) { return factors(x).size() == 1; } void solve() { int n...
6
#include <bits/stdc++.h> using namespace std; int main(int argc, const char* argv[]) { vector<int> v(3); cin >> v[0] >> v[1] >> v[2]; vector<int> ans(3); if (v[1] < v[2]) { if (v[0] < v[1]) { ans[0] = v[0]; } else { ans[0] = v[1] - 1; } } else { v[1] = v[2] - 1; if (v[0] < v[1]...
0
#include <bits/stdc++.h> using namespace std; const int NMAX = 55; const int LMAX = 20505; const int INF = 0x3f3f3f3f; int N, M, K; int entry[NMAX][LMAX], sum[NMAX][LMAX]; int best[NMAX][LMAX]; int getValueLeft(int row, int candidateIdx, int currStart) { return best[row - 1][candidateIdx] - (sum[row][candida...
15
#include <bits/stdc++.h> using namespace std; long long mod = 1e9 + 7; long long modexp(long long x, long long n) { if (n == 0) return 1; if (n % 2 == 0) { long long y = modexp(x, n / 2) % mod; return (y * y) % mod; } return (x * modexp(x, n - 1) % mod) % mod; } int main() { int n; scanf("%d", &n); ...
12
#include <bits/stdc++.h> using namespace std; int a[30][30]; int b[30]; int d[30]; char s[1000000]; int main() { int n; memset(a, 0, sizeof(a)); memset(b, 0, sizeof(b)); scanf("%d", &n); for (int i = 1; i <= n; ++i) { scanf("%s", s); int len = strlen(s); memset(d, 0, sizeof(d)); int sum = 0; ...
4
#include <bits/stdc++.h> using namespace std; string s; int ans; stack<char> st; map<char, bool> open; int main() { cin >> s; string op = "[{<("; for (int i = 0; op[i]; open[op[i++]] = 1) ; for (int i = 0; i < s.size(); i++) { if (open[s[i]]) st.push(s[i]); else { if (!st.size()) return ...
6
#include <bits/stdc++.h> using namespace std; void solve(void) { long long a, b, n, m; scanf("%lld%lld%lld%lld", &a, &b, &n, &m); if (a > b) swap(a, b); if (a < m || a + b < n + m) printf("No\n"); else printf("Yes\n"); } int main(void) { int T; scanf("%d", &T); while (T--) solve(); return 0; }...
5
#include <bits/stdc++.h> using namespace std; int dx[] = {0, 1, -1, 0}; int dy[] = {1, 0, 0, -1}; long double PI = 3.14159265358979323846264338327950; const int N = 1e5 + 10; int x[N], y[N], z[N]; int main() { ios::sync_with_stdio(false); cin.tie(NULL); string s; cin >> s; for (int i = 1; i <= (int)s.size(); ...
7
#include <bits/stdc++.h> using namespace std; int main() { long long int n, m, i; cin >> n >> m; long long int a[n + 1], flag = 0, sum = 0; for (i = 0; i < n; i++) cin >> a[i]; i = 0; while (i < n) { if (a[i] < m) { sum = 0; while (sum + a[i] <= m) { sum += a[i]; i++; }...
2
#include <bits/stdc++.h> using namespace std; int main(void) { int n, t; scanf("%d %d", &n, &t); int x, i, a, b, cnt1 = 0, cnt2 = 0; for (i = 0; i < n; ++i) { scanf("%d", &x); if (x == 1) ++cnt1; else ++cnt2; } while (t--) { scanf("%d %d", &a, &b); int len = (abs(a - b) + 1);...
0
#include <bits/stdc++.h> using namespace std; long long a, b; vector<long long> primes; void read() { scanf("%lld%lld", &a, &b); } long long findGCD(long long x, long long y) { if (x < y) swap(x, y); while (y) { x = x % y; swap(x, y); } return x; } void getPrimes() { long long prime = 2LL; long long...
13
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, q; cin >> n >> q; vector<long long> ipt(n); for (int i = 0; i < n; i++) { cin >> ipt[i]; } vector<long long> fenw(300001); auto update = [&](int x, long long v) { while (x <= n) { f...
7
#include <bits/stdc++.h> using namespace std; int main() { long long int n; cin >> n; long long int a[n]; map<long long int, long long int> m; for (int i = 0; i < n; i++) { cin >> a[i]; m[a[i]] = i; } long long int q; cin >> q; long long int Vasya = 0, Petya = 0; for (int i = 0; i < q; i++) ...
3
#include <bits/stdc++.h> using namespace std; int main() { std::ios::sync_with_stdio(false); std::cin.tie(NULL); long long T; cin >> T; while (T--) { long long a, b, c, d; cin >> a >> b >> c >> d; if (a <= b) { cout << b << "\n"; } else if (c <= d) { cout << -1 << "\n"; } else ...
1
#include <bits/stdc++.h> using namespace std; int main() { int pn; cin >> pn; vector<int> v(pn); for (int i = 0; i < (pn); i++) cin >> v[i]; for (int i = 0; i < (pn); i++) for (int j = i + 2; j <= pn; j++) { vector<int> t(v); reverse(t.begin() + i, t.begin() + j); bool ok = true; f...
5
#include <bits/stdc++.h> #define ll long long #define repe(i, j, n) for(ll i = j ; i <= n ; i++) #define rep(i, j , n) for(ll i = j ; i < n ; i++) #define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout<<fixed;cout.precision(10); #define endl "\n" #define tc ll T; cin >> T; while(T--) #define pb push_back #d...
4