solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> using namespace std; int n, m; int a, b; int c[123]; int main() { cin >> n >> m; for (int i = 0; i < m; i++) { cin >> a >> b; while (a <= b) { c[a]++; a++; } } for (int i = 1; i <= n; i++) { if (c[i] != 1) { cout << i << " " << c[i] << endl; exit(...
5
#include <bits/stdc++.h> using namespace std; long long int n, k; long long int memo[300][300][300]; string s, t; long long int dp(long long int id, long long int operations, long long int cnt_to) { if (id == n) { return 0; } auto &res = memo[id][operations][cnt_to]; if (res != -1) return r...
13
#include <bits/stdc++.h> using namespace std; const int LOG = 18; const int NN = 2222; const int MOD = (int)1e9 + 7; const int INF = 1LL << 28; int mul(int x, int y) { return (1LL * x * y) % MOD; } int add(int x, int y) { return (0LL + x + y) % MOD; } int fast_pow(int x, int y) { if (y == 0) return 1; if (y & 1) ...
11
#include <bits/stdc++.h> using namespace ::std; const int maxn = 2100; int p[maxn]; int t[maxn]; int q[maxn]; int k[maxn]; bool f(int a, int b, int c) { if (a < b && b < c) { return 1; } return 0; } int main() { ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0); int n; int ans = 0; scanf("%d",...
15
#include <bits/stdc++.h> using namespace std; int main() { int n, d, m, a[100]; scanf("%d%d", &n, &d); for (int i = 0; i < n; i++) scanf("%d", &a[i]); scanf("%d", &m); sort(a, a + n); int ans = 0; if (m <= n) for (int i = 0; i < m; i++) ans += a[i]; else { for (int i = 0; i < n; i++) ans += a[i]...
2
#include <bits/stdc++.h> using namespace std; const int STARTING_YEAR = 1988; long long convertYearSuffixToYear(string yearSuffix) { long long yearFloor = STARTING_YEAR; int N = yearSuffix.length(); long long p10 = 10; for (int i = N - 1; i >= 0; --i, p10 *= 10) { int yearSuffixSuffix = stoi(yearSuffix.subs...
12
#include <bits/stdc++.h> using namespace std; template <typename T> T get_rand(T l, T r) { random_device rd; mt19937 gen(rd()); return uniform_int_distribution<T>(l, r)(gen); } #pragma GCC optimize("-Ofast") #pragma GCC target( \ "sse,sse2,sse3,ssse3,sse4,popcnt,abm,avx2,mmx,fma,avx,tune=native") #pragma GCC ...
13
#include <bits/stdc++.h> using namespace std; int amount, gasoline[300005]; vector<pair<int, int> > graph_map[300005]; long long max_gasoline = 0; int color[300005]; long long DFS(int root) { color[root] = 1; long long biggest = 0, sec_biggest = 0; for (pair<int, int> connect : graph_map[root]) if (!color[con...
10
#include <bits/stdc++.h> using namespace std; const int N = 20; const int INF = 1e9 + 5; const int MX = 1 << N; int sum, n, m, f[N][N], dp[MX], d[N], ans; int main() { int x, y, w, s, all; sum = 0; scanf("%d%d", &n, &m); memset(f, 0x3f, sizeof(f)); while (m--) { scanf("%d%d%d", &x, &y, &w); x--, y--; ...
16
#include <bits/stdc++.h> using namespace std; vector<pair<long long, long long> > v; long long distance(long long i, long long j) { return (v[i].first - v[j].first) * (v[i].first - v[j].first) + (v[i].second - v[j].second) * (v[i].second - v[j].second); } long long check(long long i, long long j, long long k...
8
#include <bits/stdc++.h> using namespace std; void ga(int N, int *A) { for (int i(0); i < N; i++) scanf("%d", A + i); } int N, M = 1, H = 1; vector<int> o[10000]; int main(void) { scanf("%d", &N); while (M * (M + 1) / 2 <= N) ++M; for (int i(0); i < M; i++) for (int k(i + 1); k < M; k++) o[i].push_back(H), ...
8
#include <bits/stdc++.h> using namespace std; const int MOD = 998244353; int powerMod(int a, int n, int m) { if (!n) return 1; int t = powerMod(a, n >> 1, m); t = (1LL * t * t) % m; if (n & 1) t = (1LL * t * a) % m; return t; } const int maxN = 1e4 + 5; int fac[maxN], inv[maxN]; void computeFactorials(int n) ...
17
#include <bits/stdc++.h> using namespace std; vector<int> a[3000]; void init() { int i, j; for (i = 1; i <= 2000; i++) { j = 1; while (i * j <= 2000) { a[i * j].push_back(i); j++; } } return; } int main() { int n, k; scanf("%d %d", &n, &k); int dp[k + 1][n + 1]; int i, j, p; in...
6
#include <bits/stdc++.h> using namespace std; long long pw(long long a, int n) { if (n == 0) return 1; if (n & 1) return pw(a, n - 1) * a; long long b = pw(a, n >> 1); return b * b; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); long long x1, x2, y1, y2; cin >> x1 >> y1 >> x2 >> y2; cout << ...
11
#include <bits/stdc++.h> using namespace std; const int N = 200050; struct points { int x, y; friend inline bool operator<(const points a, const points b) { return a.x == b.x ? a.y < b.y : a.x < b.x; } } t[N]; int n; set<points> bst; inline void solve(int l, int r) { if (l == r) return; int mid = (l + r) ...
15
#include <bits/stdc++.h> using namespace std; const double Pi = acos(-1.0); const double Ee = 2.718281828459045235360; const int INF = 0x3f3f3f3f; const long long INFF = 0x3f3f3f3f3f3f3f3fLL; const double eps = 1e-8; const int MOD = 1000000007; const int dx4[] = {-1, 0, 1, 0}; const int dy4[] = {0, 1, 0, -1}; const int...
1
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") #pragma GCC optimization("unroll-loops") using namespace std; template <class T> bool umin(T& a, const T& b) { return b < a ? a = b, 1 : 0; } template <class T> bool umax(T& a, const T& b) { return a < b ? a = b, 1 : 0; } temp...
8
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; const int C = 26; void add(int &x, int y) { x += y; while (x >= MOD) x -= MOD; while (x < 0) x += MOD; } int fix(int x) { while (x >= MOD) x -= MOD; while (x < 0) x += MOD; return x; } int pw(int a, int b) { int ret = 1; while (b) { ...
16
#include <bits/stdc++.h> using namespace std; int main() { string a; cin >> a; int num = 0; int len = a.size(); for (int i = 0; i < len; i++) { if (a[i] == 'A') { num += 1; continue; } if (a[i] == '1') { num += 10; continue; } num += a[i] - '0'; } printf("%d\n",...
11
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") using namespace std; const int N = 2e6 + 7; const long long INF = 1e18 + 7; long long res[N]; int us[N], cst[N], pos[N]; int n, m, k, mx; long long ans = INF; int main() { scanf("%d%d%d", &n, &m, &k); int a; for (int i = 1; ...
13
#include <bits/stdc++.h> using namespace std; int main() { long long int i, j, k; long long int n, m, x; cin >> n; long long int a[n]; for (i = 0; i < n; i++) cin >> a[i]; string s[n], r[n]; long long int dp[n][2]; for (i = 0; i < n; i++) { cin >> s[i]; r[i] = s[i]; reverse(r[i].begin(), r[i...
8
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long n; cin >> n; string s; int k = 3; vector<long long> max_letter; while (k--) { cin >> s; unordered_map<char, long long> m; for (long long i = 0; i < (int)s.s...
10
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; long long int Quickpow(long long int x, int p) { long long int data = 1; while (p) { if (p & 1) data = data * x % MOD; p >>= 1, x = x * x % MOD; } return data % MOD; } int main() { long long int n, m; cin >> n >> m; long long i...
7
#include <bits/stdc++.h> using namespace std; int main() { long long int t; cin >> t; while (t--) { long long int n, i, ans = -23, k, res = 0; vector<long long int> v; cin >> n >> k; string s; cin >> s; for (i = 0; i < n; i++) { if (i == 0) { if (s[i] == 'W') { ans ...
6
#include <bits/stdc++.h> using namespace std; const int MAX = 1000; long long m, l, r, k; struct matrix { long long g[2][2]; matrix() { memset(g, 0, sizeof g); } void print() { int i, j; for (i = 0; i < 2; ++i, printf("\n")) for (j = 0; j < 2; ++j) cout << g[i][j] << " "; } }; matrix operator*(con...
16
#include <bits/stdc++.h> using namespace std; int pow_mod(long long x, long long n, int M) { long long ans = 1; for (; n; n >>= 1) { if (n & 1) ans = ans * x % M; x = x * x % M; } return ans; } int inv_mod(int x, int p) { return pow_mod(x, p - 2, p); } vector<vector<int>> f(vector<vector<int>> a, int MO...
19
#include <bits/stdc++.h> using namespace std; using ll = long long; ll KMOD = 998244353; ll Power(ll a, ll pow, ll p) { if (pow == 1) return a; ll x = Power(a, pow / 2, p); ll y = x * x % p; if (pow % 2 == 0) return y; return y * a % p; } ll ModInverse(ll a, ll p) { return Power(a, p - 2, p); } int n, m, r, c...
15
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const int N = 1e5 + 5; int ver[N * 2], Next[N * 2], head[N], col[N]; int tot, n, m; vector<int> Size[3]; bool flag; void add(int x, int y) { ver[++tot] = y; Next[tot] = head[x]; head[x] = tot; } void dfs(int x, int color) { if (!flag) ret...
7
#include <bits/stdc++.h> using namespace std; int n; int dp[54][54][54][54]; int main() { cin.tie(NULL); cin.sync_with_stdio(false); int n; cin >> n; for (int i = 0; i < n; i++) { string x; cin >> x; for (int j = 0; j < n; j++) { if (x[j] == '#') dp[i][j][i + 1][j + 1] = 1; els...
15
#include <bits/stdc++.h> #pragma GCC optimize("O3") template <typename _tp> bool ri(_tp &_var) { _var = 0; bool _neg = 0; auto _rd = getchar(); while (_rd < '0' || _rd > '9') { if (_rd == '-') { _neg = 1; } else if (_rd == -1) { return 0; } _rd = getchar(); } while (_rd >= '0' &&...
0
#include <bits/stdc++.h> using namespace std; int main() { long long tc; scanf("%lld", &tc); for (long long t = 1; t <= tc; t++) { long long n, m; string st; cin >> n >> m; if (m == 1) { for (int i = 0; i < n - 1; i++) { if (i % 2 == 0) cout << 'B' << '\n'; else ...
2
/* author:ujwalll */ #pragma GCC optimize("O2") #include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); i++) #define for1(i, n) for (int i = 1; i <= n; i++) #define FOR(i, a, b) for (int i = (a); i <= (b); i++) #define FORD(i, a, b) for (int i = (a); i >= (b); i--) #define nx cout <...
4
#include <bits/stdc++.h> using namespace std; const int N = 1005505; const int mod = 1e9 + 7; const int INF = 1e9 + 7; int n, a[N]; map<int, int> cnt; vector<pair<int, int> > v; int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n; for (int i = 1; i <= n; ++i) cin >> a[i], cnt[a[i]]++; for (auto &x : cn...
10
#include <bits/stdc++.h> using namespace std; int main() { int n, m, i, j, k, an = 0; int a[1111]; scanf("%d%d%d", &n, &m, &k); for (i = 0; i < n; i++) { scanf("%d", &a[i]); if (a[i] == 1) m--; else if (a[i] == 2) { if (k > 0) k--; else m--; } if (m < 0) { ...
1
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC optimize("no-stack-protector") #pragma GCC optimize("unroll-loops") #pragma GCC optimize("fast-math") #pragma GCC target("sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native") using namespace std; template <typename T> void uin(T &a, T b) { if (b < a) { ...
16
#include <bits/stdc++.h> using namespace std; struct RTC { ~RTC() { cerr << "Time: " << clock() * 1.0 / CLOCKS_PER_SEC << " seconds\n"; } } runtimecount; long long int n, k, MOD; long long int powdies[1010]; long long int dp[1001][101][2][2]; long long int solve(long long int pos, long long int acu, bool llegoacero, ...
14
#include <bits/stdc++.h> using namespace std; const long long INF = 1e9; const long long MOD = 1e9 + 7; const double pi = acos(-1); void solve() { long long n, k; cin >> n >> k; long long a[n]; for (long long i = 0; i < n; i++) { cin >> a[i]; } sort(a, a + n); reverse(a, a + n); long long w[k]; fo...
6
#include <bits/stdc++.h> using namespace std; const int maxn = 105; const long long INF = 1e18; const long long magic = 100000; vector<int> cycle; vector<set<int>> g; vector<int> used; void euler_cycle(int v) { used[v] = 1; stack<int> s; s.push(v); while (!s.empty()) { int v = s.top(); if (g[v].empty())...
16
#include <bits/stdc++.h> using namespace std; int T,n; int main() { cin>>T; while(T--){ bool notfound=true; cin>>n; /* n%2020 free sapaces for 2021 n/2020 how many 2020s can we hold without free spaces */ if(n%2020<=n/2020)cout<<"YES"<<endl; else cout<<...
1
#include <bits/stdc++.h> using namespace std; int main() { long long int n, x, a, sum = 0; cin >> n >> x; for (long long int i = 0; i < n; i++) { cin >> a; sum += a; if (i < n - 1) { sum++; } } if ((sum < x) || (sum > x)) { cout << "NO"; } else if (sum == x) { cout << "YES"; ...
3
#include <bits/stdc++.h> using namespace std; template <typename T> inline void read(T &x) { char c; bool nega = 0; while ((!isdigit(c = getchar())) && (c != '-')) ; if (c == '-') { nega = 1; c = getchar(); } x = c - 48; while (isdigit(c = getchar())) x = x * 10 + c - 48; if (nega) x = -x; }...
10
#include <bits/stdc++.h> using namespace std; int n; int dp[7005][2] = {}; int deg[7005][2] = {}; vector<int> turns[2]; queue<pair<int, int>> q; int main() { cin >> n; int i, j, k, t; int s1_size, s2_size; cin >> s1_size; for (i = 0; i < s1_size; i++) { int val; cin >> val; turns[0].push_back(val)...
12
#include <bits/stdc++.h> using namespace std; int main() { int n, a[2000], b[2000], c[2000]; int v[2000], vv[2000]; cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n; i++) cin >> b[i]; for (int i = 1; i <= n; i++) { v[i] = 0; } int count = 0; for (int i = 0; i < n; i++) { ...
5
#include <bits/stdc++.h> using namespace std; int a[110][110], n, k; int main() { int i, j; scanf("%d%d", &n, &k); if (k > n * n) { printf("-1\n"); return 0; } memset(a, 0, sizeof(a)); for (i = 1; i <= n; i++) { for (j = 1; j <= n; j++) { if (k == 0) break; if (i == j) { a[i]...
6
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; for (int i = 0; i < t; i++) { int n; cin >> n; int l = n; if (n == 2) cout << "NO" << endl; else { if (l % 4 == 0) { cout << "YES" << endl; int sum = 0; for (int j = 2; j <= n; j = j...
0
#include <bits/stdc++.h> using namespace std; void solve() { long long n; cin >> n; long long cnt = 1; for (long long i = 0; i < n; i++) { long long l, r; cin >> l >> r; if (l >= cnt) { cnt = l; } if (r < cnt && i != 0) { cout << 0 << ' '; } else { cout << cnt << ' '; ...
4
#include <bits/stdc++.h> using namespace std; const int N = 303; int n; bool eq[N][N]; int dp[N][N]; string s[N]; int main() { cin >> n; int allsum = n - 1; for (int i = 0; i < n; ++i) { cin >> s[i]; allsum += s[i].size(); } for (int i = 0; i < n; ++i) { eq[i][i] = true; for (int j = 0; j < i;...
14
#include <bits/stdc++.h> using namespace std; string a[8], b[8]; int main() { for (int i = 0; i < 8; i++) cin >> a[i]; for (int i = 0; i < 8; i++) b[i] = a[i]; while (true) { for (int i = 0; i < 8; i++) for (int j = 0; j < 8; j++) b[i][j] = '.'; for (int i = 0; i < 8; i++) for (int j = 0; j < ...
7
#include <bits/stdc++.h> using namespace std; long long int a[100005]; int main() { long long int n, k, l; cin >> n >> k >> l; for (int i = 1; i <= n * k; i++) cin >> a[i]; sort(a + 1, a + 1 + n * k); if (a[n] - a[1] > l) cout << 0 << endl; else { long long int s = 0, p = -1; for (int i = n * k;...
7
#include <bits/stdc++.h> using namespace std; template <typename T> inline int sz(const T& x) { return (int)x.size(); } int ox, oy, d; vector<pair<int, int> > mv; char dp[512][512][2][4]; int winning(int x, int y, int p, int inv) { if (x > d || y > d) return 1; if (dp[x + 210][y + 210][p][inv] != -1) return dp[x ...
11
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { long long n; cin >> n; long long candies[n]; long long oranges[n]; for (int i = 0; i < n; i++) { cin >> candies[i]; } for (int i = 0; i < n; i++) { cin >> oranges[i]; } long lo...
0
#include <bits/stdc++.h> using namespace std; void solve() { int n, m, k; cin >> n >> m >> k; int temp = n / k; if (m <= temp) { cout << m << "\n"; } else { int mm = m - temp; int kk = k - 1; if (mm % kk == 0) { cout << temp - (mm / kk) << "\n"; } else { cout << temp - ((mm / k...
2
#include <bits/stdc++.h> using namespace std; const int SIEVE = 18000; const int SEGMENT_SIZE = 1e6 + 5; int N; unsigned A, B, C, D; bitset<SEGMENT_SIZE> is_prime; bitset<SIEVE> sieve_prime; unsigned f(unsigned x) { return D + x * (C + x * (B + x * A)); } unsigned contribution(unsigned p) { unsigned count = 0; unsi...
17
#include <bits/stdc++.h> using namespace std; const int N = 2e4 + 9, M = 1e7 + 6, mod = 998244353, OO = 0x3f3f3f3f, sqr = 320; const long long LOO = 0x3f3f3f3f3f3f3f3f; const long double eps = 1e-7; vector<long long> parent; vector<set<long long>> ppr; vector<vector<long long>> adj; long long n, m, t, x, y, totalP; voi...
0
#include <bits/stdc++.h> using namespace std; int n, m; bool inq[3010]; int dis[3010][3010]; vector<int> G[3010]; void SPFA(int s) { memset(inq, 0, sizeof inq); queue<int> que; dis[s][s] = 0; inq[s] = true; que.push(s); while (!que.empty()) { int u = que.front(); que.pop(); inq[u] = false; f...
13
#include <bits/stdc++.h> using namespace std; const double eps = 1e-8; int main() { int r, x, y, nx, ny; while (scanf("%d%d%d%d%d", &r, &x, &y, &nx, &ny) == 5) { if (nx == x && ny == y) { printf("0\n"); continue; } double d = sqrt((double)(nx - x) * (nx - x) + (double)(ny - y) * (ny - y)); ...
6
#include <bits/stdc++.h> using namespace std; void err(istream_iterator<string> it) {} template <typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cout << *it << " = " << a << endl; err(++it, args...); } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie...
5
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 10; const double eps = 1e-5; int a[maxn]; int b[maxn], t[maxn], r[maxn]; int main() { int n, m; int tt, rr; while (cin >> n >> m) { for (int i = 0; i < n; i++) scanf("%d", &a[i]); int s = 0; while (m--) { scanf("%d%d", &tt, &rr...
9
#include <bits/stdc++.h> using namespace std; const int MAXN = 50005; int N; int A[MAXN]; pair<int, int> sum[MAXN]; int ans[MAXN]; int main() { ios::sync_with_stdio(0); cin >> N; for (int i = 0; i < N; i++) cin >> A[i]; for (int i = 0; i < N; i++) sum[i] = make_pair(A[i] + A[(i + 1) % N], i); sort(sum, sum + ...
13
#include<bits/stdc++.h> #define ll long long #define pii pair<int,int> using namespace std; const int mxn=1e5+5; const int inf=1e9; vector<pii> res; int N; void add(int i,int j) { if(res.size() == N + 5) { exit(0); } res.push_back({i,j}); } void pr() { cout<<res.size()<<endl; for(pii x : res) cout<<x.first<<" "<...
9
#include <bits/stdc++.h> using namespace std; int main() { int n, n1, x, i, c = 0, sum = 0; cin >> n >> n1; while (n--) { cin >> x; sum += x; } while (sum > 0) { sum -= n1; c++; } if (c == 0) { while (sum < 0) { sum += n1; c++; } } cout << c << endl; }
0
#include <bits/stdc++.h> using namespace std; vector<long long> edge[300005]; long long u, v, cd, f[300005][4], mod = 998244353; void inp() { cin >> cd; for (long long i = 1; i < cd; i++) cin >> u >> v, edge[u].push_back(v), edge[v].push_back(u); } void dp(long long u, long long p) { long long ok = 0, left = ...
16
#include <bits/stdc++.h> using namespace std; const long long INF = 1e9; const long long N = 1e5 + 7; const long long mod = 1e9 + 7; const long double eps = 1E-7; long long n; long long r, l; long long cnt, ans, pos; int main() { ios_base::sync_with_stdio(0); cin >> n; long long arr[n], b[n]; for (int i = 0; i ...
3
#include <bits/stdc++.h> using namespace std; bool inRange(int x, int l, int r) { return l <= x && x <= r; } int main() { ios::sync_with_stdio(false); int t; cin >> t; while (t--) { int a, b, c, d; cin >> a >> b >> c >> d; int x, y, x1, y1, x2, y2; cin >> x >> y >> x1 >> y1 >> x2 >> y2; if (...
3
#include <bits/stdc++.h> using namespace std; const int INFint = 2147483547; const long long INF = 9223372036854775807ll; const long long MOD = 1000000007ll; const long double EPS = 1e-13; int main() { ios_base::sync_with_stdio(0); int n, a, b, T; cin >> n >> a >> b >> T; string s; cin >> s; vector<long lon...
11
#include <bits/stdc++.h> using namespace std; long long int modulo = 777777777; long long int maneras[1000000][4][4]; int valido[1000000]; int primero, tope; int n; int w[4][4]; void inserta(int pos, int val) { pos += primero; valido[pos] = 1; if (val == 0) for (int i = 1; i < 4; i++) for (int j = 1; j ...
16
#include <bits/stdc++.h> using namespace std; int main() { int i, j, n; cin >> n; char a[n + 1][n + 1]; for (i = 0; i < n; i++) { for (j = 0; j < n; j++) { cin >> a[i][j]; } } for (i = 0; i < n; i++) { for (j = 0; j < n; j++) { if (a[i][j] == '.' && a[i - 1][j] == '.' && a[i + 1][j] ...
1
#include <bits/stdc++.h> using namespace std; class vec { public: int x, y; vec() {} vec(int tx, int ty) { x = tx, y = ty; } vec operator-(const vec &t) { return vec(x - t.x, y - t.y); } long long operator*(const vec &t) { return 1ll * x * t.y - 1ll * y * t.x; } } v[2010]; int n; bool vis[2010]; vector<pair<...
18
#include <bits/stdc++.h> using namespace std; int t, k; int main() { long long sum = 0; for (int P = 0; P < 10000; P++) { sum += P; } cin >> t >> k; long long DP[100002]; DP[0] = 1; for (int i = 1; i <= 100000; i++) { DP[i] = DP[i - 1]; if ((i - k) >= 0) { DP[i] += DP[i - k]; } D...
9
#include <bits/stdc++.h> using namespace std; template <class t> inline t read(t &x) { char c = getchar(); bool f = 0; x = 0; while (!isdigit(c)) f |= c == '-', c = getchar(); while (isdigit(c)) x = (x << 1) + (x << 3) + (c ^ 48), c = getchar(); if (f) x = -x; return x; } template <class t> inline void wr...
27
#include <bits/stdc++.h> using namespace std; int f[1005][1005], m, n; char s[1005], t[1005]; int main() { gets(s + 1); gets(t + 1); n = strlen(s + 1); m = strlen(t + 1); for (int i = 0; i <= n; ++i) f[i][0] = i; for (int j = 0; j <= m; ++j) f[0][j] = j; for (int i = 1; i <= n; ++i) for (int j = 1; j ...
13
#include <bits/stdc++.h> using namespace std; const long long MAX = 10; long long f(char type, string s, long long start) { for (int i = start; i < s.size(); i++) { if (s[i] == type) { return i; } } return 0; } void solve() { long long n, k; cin >> n >> k; string s; cin >> s; long long cur...
9
#include <bits/stdc++.h> using namespace std; int main() { int t; scanf("%d", &t); while (t--) { int n; cin >> n; int a[n]; for (int i = 0; i < n; i++) cin >> a[i]; int m = *max_element(a, a + n); int ans = -1; for (int i = 0; i < n; i++) { if (a[i] == m) { if ((i - 1 >= ...
1
#include <bits/stdc++.h> using namespace std; template <typename T> inline T GCD(T a, T b) { a = abs(a); b = abs(b); while (b) { a = a % b; swap(a, b); } return a; } template <typename T> inline T LCM(T x, T y) { T tp = GCD(x, y); if ((x / tp) * 1. * y > 9e18) return 9e18; return (x / tp) * y; }...
6
#include <bits/stdc++.h> int sgn(const double &a) { return (a > 1e-8) - (a < -1e-8); } const double pi = acos(-1.0); using namespace std; int main() { ios::sync_with_stdio(0); int i, j, k; int a1, a2, a3, b1, b2, b3; scanf("%d%d%d%d%d%d", &a1, &b1, &a2, &b2, &a3, &b3); if (min(a2, b2) > max(a1, b1) || min(a3,...
4
#include <bits/stdc++.h> using namespace std; const double eps = 1e-8; const double pi = acos(-1); const double pi2 = pi * 2.0; char answer[100]; double iabs(const double &k) { return k < 0 ? -k : k; } class Point { public: double x, y; Point(const double &a = 0, const double &b = 0) : x(a), y(b) {} Point operat...
12
#include <bits/stdc++.h> using namespace std; using llong = int64_t; const int Inf = 2e9; int t, nr, ng, nb; void solve(); llong getMin(vector<int> R, vector<int> G, vector<int> B); int bs_higher(int val, vector<int>& v); int bs_lower(int val, vector<int>& v); llong calc(llong x, llong y, llong z); int main() { ios_b...
9
#include <bits/stdc++.h> using namespace std; const int mx = 4e6 + 5; const int mod = 51123987; char str[mx], s[mx]; int p[mx]; int l[mx], r[mx]; long long pow_mod(long long a, long long b) { long long ans = 1; while (b > 0) { if (b & 1) ans = ans * a % mod; a = a * a % mod; b /= 2; } return ans; } ...
21
#include <bits/stdc++.h> using namespace std; int n, ans, a[200005], r[200005], d[200005]; int root(int u) { if (r[u] != u) r[u] = root(r[u]); return r[u]; } int main() { ios_base::sync_with_stdio(0); cin >> n; for (int i = 1; i <= n; ++i) { cin >> a[i]; r[i] = i; } for (int i = 1; i <= n; ++i) { ...
9
#include <bits/stdc++.h> using namespace std; int to_remove_here[2002]; int main() { memset(to_remove_here, 0, sizeof to_remove_here); int n, k, in; long long ans = 0; cin >> n >> k; int tmp = n; while (n--) { cin >> in; to_remove_here[in]++; } n = tmp; for (int i = 2; i < 2002; i++) { ans...
5
#include <bits/stdc++.h> using namespace std; const int N = 1000010; int n, forbidden, f[N], deg[N], sum[N], sol, x[N], y[N], q[N]; vector<int> v[N]; void dfs(int c, int z) { f[c] = z; for (auto i : v[c]) if (!f[i]) dfs(i, z); } bool disconnected() { int z = 0; for (int i = 1; i <= 4; i++) f[i] = 0; for (...
16
#include <bits/stdc++.h> using namespace std; struct dsu_save { int v, rnkv, u, rnku; dsu_save() {} dsu_save(int _v, int _rnkv, int _u, int _rnku) : v(_v), rnkv(_rnkv), u(_u), rnku(_rnku) {} }; struct dsu_with_rollbacks { vector<int> p, rnk, comp_sizes; stack<dsu_save> op; dsu_with_rollbacks() {} ds...
17
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, k; string s, t; cin >> n >> k >> s; for (int i = 0; i < k; i++) t += s[i]; for (int i = k; i < n; i++) t += t[i - k]; if (t < s) { for (int i = k - 1; i >= 0; i--) if ...
9
#include <bits/stdc++.h> using namespace std; map<int, int> mp; int n; int main(void) { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n; int tmp, ans = -1; while (n--) { cin >> tmp; mp[tmp]++; } for (auto i : mp) ans = max(ans, i.second); cout << ans << '\n'; return 0; }
0
#include <bits/stdc++.h> using namespace std; struct rmqf { long long s[1501 << 2]; inline long long operator[](int i) { return s[i]; } inline void operator=(const rmqf &b) { for (int j = 0; j < 1501 << 2; ++j) s[j] = b.s[j]; } }; const int maxn = 2000; int n, gm; rmqf a, b; long long sum[maxn][maxn]; int p...
11
#include <bits/stdc++.h> using namespace std; template <typename T, typename U> inline void amin(T &x, U y) { if (y < x) x = y; } template <typename T, typename U> inline void amax(T &x, U y) { if (x < y) x = y; } template <typename T> inline void write(T x) { int i = 20; char buf[21]; buf[20] = '\n'; do { ...
6
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[n + 3], b[n + 5]; for (int i = 0; i < n; i++) cin >> a[i]; int x = 0, y = 0, z = 0; for (int i = 0; i < n; i++) { cin >> b[i]; if (b[i] == a[i] == 1) x++; else if (b[i] == 1 && a[i] == 0) y++; else ...
1
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; const unsigned gen_seed = std::chrono::system_clock::now().time_since_epoch().count(); std::mt19937_64 gen(gen_seed); int n, r; std::vector<std::vector<int> > g; const int INF = 1e6; std::vector<int> d, p; int main() { scanf("%d", &n)...
11
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; pair<int, int> a[n + 1]; for (int i = 1; i <= n; i++) cin >> a[i].first >> a[i].second; sort(a + 1, a + n + 1); int res = 0; for (int i = 1; i <= n; i++) if (res <= a[i].second) res = a[i].second; else res = a[...
6
#include <bits/stdc++.h> using namespace std; int main() { string s; long long cont = 0; long long ans = 0; cin >> s; while (s.back() == 'a') { s.pop_back(); } for (int i = s.size() - 1; i > -1; i--) { if (s[i] == 'b') { cont += 1; cont %= 1000000007; } if (s[i] == 'a') { ...
6
#include <bits/stdc++.h> using namespace std; template <class T> int getbit(T s, int i) { return (s >> i) & 1; } template <class T> T onbit(T s, int i) { return s | (T(1) << i); } template <class T> T offbit(T s, int i) { return s & (~(T(1) << i)); } template <class T> int cntbit(T s) { return __builtin_popcoun...
6
#include <bits/stdc++.h> using namespace std; typedef long long int ll; const ll M = 1000000007; const ll N = 998244353; ll power(ll x, ll y, ll p) { ll res = 1; x = x % p; if (x == 0) return 0; while (y > 0) { if (y & 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res; } ll inv(l...
9
#include <bits/stdc++.h> using namespace std; int main() { static int prefix_table[100000], j, s_len, t_len, i; static long long DP[100000], left_matches[100000], sums[100000], total[100000], m, result; string s, t; cin >> s >> t; DP[0] = 0; sums[0] = 0; total[0] = 0; result = 0; j = -1; m = 1...
12
#include <bits/stdc++.h> using namespace std; int main() { int a, b; cin >> a >> b; if (b > a) { puts("-1"); return 0; } int n = (a - b) / (2 * b); double x = (a + b) / (2. * (n + 1)); if (n) x = min(x, (a - b) / (2. * n)); printf("%0.12f\n", x); }
9
#include <bits/stdc++.h> const int MAXN = 1e6 + 10; int n, k; char s[MAXN]; int tot[MAXN]; template <int MOD, int BASE> struct Hash { int h[MAXN], pwr[MAXN], n; void init(char *s) { n = strlen(s + 1); h[0] = 0, pwr[0] = 1; for (int i = 1; i <= n; i++) { pwr[i] = 1ll * pwr[i - 1] * BASE % MOD; ...
14
#include <bits/stdc++.h> using namespace std; const int mn = 1e6 + 5; int n; int a[mn]; int l1[mn], l2[mn], r1[mn], r2[mn]; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d", &a[i]); for (int i = 1; i <= n; i++) { if (a[i] == 1) { l1[i] = l1[i - 1] + 1; l2[i] = 0; } else { ...
1
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t; cin >> t; while (t--) { long long k; cin >> k; int root = sqrt(k); long long sq = root * root; long long rem = k - sq; if (sq == k) { cout << root << " " << 1 << end...
0
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; i++) cin >> a[i]; int k = 0; for (int i = 1; i <= n - 1; i++) { if (a[i - 1] == 1 && a[i + 1] == 1 && a[i] == 0) { a[i + 1] = 0; k++; } } cout << k; }
2
#include <bits/stdc++.h> const long long inf = 0x3f3f3f3f3f3f3f3fll; using namespace std; long long gcd(long long a, long long b) { if (a == 0) return b; return gcd(b % a, a); } long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); } bool isPrime(long long x) { for (long long d = 2; d * d <= x; d+...
8
#include <bits/stdc++.h> const long long MOD = 1e9 + 7; long long fac[2050], inv[2050]; long long f[2050][2050][2][2]; long long QPow(long long x, long long y) { long long ans = 1, base = x % MOD; while (y) { if (y & 1) { ans = (ans * base) % MOD; } base = (base * base) % MOD; y >>= 1; } r...
18