solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> using namespace std; int N, M, K; multiset<int> A, B, C; int main() { scanf("%d%d%d", &N, &M, &K); A.clear(); B.clear(); int x; for (int i = 0; i < N; ++i) { scanf("%d", &x); A.insert(x); } for (int i = 0; i < M; ++i) { scanf("%d", &x); B.insert(x); } for (mult...
8
#include <bits/stdc++.h> using namespace std; const int N = 200005; vector<int> G[N]; int n; long long sum[N], odd[N], even[N]; long long sumodd[N], sumeven[N]; long long ans; void dfs(int u, int fa) { sum[u] = 1; even[u] = odd[u] = 0; for (auto v : G[u]) { if (v == fa) continue; dfs(v, u); sumodd[u] ...
12
#include <bits/stdc++.h> using namespace std; set<long long>::iterator it; long long n, q, a[200005], k[200005], dp[200005], dp1[200005]; map<long long, int> ok; set<long long> war; int main() { cin >> n >> q; for (int i = 1; i <= n; i++) { cin >> a[i]; } for (int i = 1; i <= q; i++) { cin >> k[i]; } ...
6
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") #pragma GCC optimization("unroll-loops") using namespace std; int main(void) { ios_base::sync_with_stdio(0); cin.tie(0); int n, k, siz, r; long long sum; cin >> n >> k; long long dp[n + 1][k + 1]; memset(dp, 0, sizeo...
20
#include <bits/stdc++.h> using namespace std; const int MAX_N = 200200; const int INF = (int)1e9; const long long LINF = (long long)1e18; int a[MAX_N]; pair<int, long long> buffer[MAX_N]; priority_queue<long long> pq; void solve() { int n, k, b, c; scanf("%d%d%d%d", &n, &k, &b, &c); for (int i = 0; i < n; i++) { ...
16
#include <bits/stdc++.h> using namespace std; int main() { long long t; cin >> t; while (t--) { long long n, q; cin >> n >> q; long long a[n]; for (long long i = 0; i < n; i++) { cin >> a[i]; } long long dp[n]; dp[0] = a[0]; for (long long i = 1; i < n; i++) { if (a[i] ...
5
#include <bits/stdc++.h> using namespace std; using ll = long long; using ii = pair<int, int>; constexpr int MOD = 998244353; const int MAXN = 2002; inline int add(int a, int b) { int ans = a + b; if (ans >= MOD) ans -= MOD; return ans; } inline int mul(int a, int b) { return (1LL * a * b) % MOD; } int dpend[MAXN...
18
#include <bits/stdc++.h> using namespace std; int coef[][6] = {{1, 0, 0, 0, 0, 0}, {1, 1, 0, 0, 0, 0}, {0, 0, 1, 0, 1, 0}, {0, 0, 0, 1, 0, 1}, {3, 1, 1, 1, 2, 1}, {3, 1, 1, 1, 1, 2}}; int N = 6; int n, sx, sy, dx, dy; long long T; vector<vector<int> > coefMatrix() { vector<vector<int> > mat(N); for...
15
#include <bits/stdc++.h> using namespace std; const int maxn = 100000, maxne = 1 << 18; int n; long long d, h[maxn + 1]; int mat[maxn + 1], _mat[maxn + 1]; struct node { int l, r, max_v, max_n; } ne[maxne]; int f[maxn + 1]; void build() { for (int i = maxne - 1; i >= maxne >> 1; i--) ne[i].l = ne[i].r = i - (ma...
12
#include <bits/stdc++.h> int main() { int m, n; scanf("%d%d", &m, &n); int c = 0; while (m * n > 0) { m--; n--; c++; } if (c & 1) printf("Akshat"); else printf("Malvika"); }
1
#include <bits/stdc++.h> using namespace std; int res, n, b, a[2010]; int main() { cin >> n >> b; res = b; for (int i = 0; i < n; i++) { cin >> a[i]; for (int j = 0; j < i; j++) res = max(res, b / a[j] * a[i] + b % a[j]); } cout << res; return 0; }
6
#include <bits/stdc++.h> using namespace std; int a[2000000], ans[2000000]; int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } int main() { int n, nans = 0; int cnt = 0; scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%d", &a[i]); ans[nans++] = a[0]; for (int i = 1; i < n; i++) { ...
4
#include <bits/stdc++.h> using namespace std; void solve() { int n, k, o = 0, z = 0; string s; cin >> n >> k; cin >> s; for (int i = k; i < n; ++i) if (s[i] == '?') s[i] = s[i - k]; for (int i = n - k - 1; i >= 0; --i) if (s[i] == '?') s[i] = s[i + k]; for (int i = k; i < n; ++i) if (s[i] == '...
7
#include <bits/stdc++.h> using namespace std; int n, a[20], b[20], c[20], g[5][5]; int pos[20][2] = {0, 0, 0, 3, 1, 1, 1, 2, 2, 1, 2, 2}; void pr(int s) { printf("%d\n", s); for (int i = 0; i < (n); ++i) { for (int j = 0; j < (n); ++j) printf("%d ", g[i][j]); puts(""); } } int main() { scanf("%d", &n); ...
7
#include <bits/stdc++.h> using namespace std; int arr[28]; int main() { int n, prev, k, count = 0, ans = 0; char a; scanf("%d %d", &n, &k); cin.ignore(); for (int i = 0; i < n; i++) { scanf("%c", &a); arr[(a - 'a') + 1] = 1; } for (int i = 1; i < 27; i++) { if (count == k) break; if (arr[i...
1
#include <bits/stdc++.h> using namespace std; const int N = (int)1e5; long long a[N + 10]; int n; priority_queue<pair<long long, long long> > s; int main() { cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); long long p = a[0]; for (int i = 0; i < n; i++) a[i] -= p; for (int i = 0; i < n - ...
12
#include <bits/stdc++.h> using namespace std; const int Maxn = 2005; const int Inf = 1000000000; int T; int n, k; int a[Maxn]; int dp[Maxn][Maxn]; int main() { scanf("%d", &T); while (T--) { scanf("%d %d", &n, &k); for (int i = 0; i < n; i++) { scanf("%d", &a[i]); a[i]--; } for (int i = ...
12
#include <bits/stdc++.h> using namespace std; string a; string b = "QAQ"; int sum; void dfs(int times, int pos) { if (times == 3) { sum++; return; } for (int i = pos + 1; i < a.length(); i++) { if (b[times] == a[i]) dfs(times + 1, i); } } int main() { cin >> a; dfs(0, -1); cout << sum << endl;...
0
#include <bits/stdc++.h> using namespace std; char c[1000050]; int main() { int n; while (scanf("%d", &n) == 1) { scanf("%s", c + 1); long long x = 0, y = 0, u = 0, d = 0, r = 0, l = 0; for (int i = 1; i <= n; i++) { x += 2 * u; y -= 2 * d; if (c[i - 1] == 'U') u++, x++; if (c[i ...
16
#include <bits/stdc++.h> using namespace std; int const N = 5e5 + 10, oo = 1e9; int mod = oo + 7; long long const OO = 1e18; int main() { ios::sync_with_stdio(0); cin.tie(0); int n, p; string s; cin >> n >> p >> s; bool yes = 0; for (int i = 0; i < n - p; i++) { if (s[i] == '.') { yes = 1; ...
4
#include <bits/stdc++.h> using namespace std; int main() { long long int a, b, c, m, price, i = 0, iu, ip, all_price = 0; string type; cin >> a >> b >> c; cin >> m; if (m == 0) { printf("0 0"); return 0; } vector<long long int> USB, PS; for (i = 0; i < m; i++) { cin >> price; cin >> type...
6
#include <bits/stdc++.h> using ll = long long; constexpr int MOD = 998244353; constexpr ll powm(ll x, ll n, ll mod) { return (n == 0 ? 1 : powm(x * x % mod, n / 2, mod) * (n % 2 ? x : 1) % mod); } int const N = 15; int const INF = (int)(1e9); int n, a[N], sum[1 << N], dp[N + 1][1 << N][N + 1], p[N + 1][1 << N][N + 1]...
22
#include <bits/stdc++.h> using namespace std; int R, b[4], p[4]; bool valid[105][105]; bool vis[105][105]; void add(int &a, int b) { a += b; if (a >= 1000000007) a -= 1000000007; } void dec(int &a, int b) { a -= b; if (a < 0) a += 1000000007; } int pow_mod(int a, int i) { int s = 1; while (i) { if (i & ...
23
#include <bits/stdc++.h> using namespace std; int p[200010]; bool vis[200010]; int q[2000010]; int c[2000010]; vector<int> d[2000010]; const int N = 2000000; void init() { for (int i = 2; i <= N; i++) { if (d[i].size()) continue; for (int j = i; j <= N; j += i) d[j].push_back(i); } return; } void work(int...
21
#include <bits/stdc++.h> using namespace std; inline void op() {} int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); op(); int n; cin >> n; string a, b; cin >> a >> b; long long int ans = 0, cnt1 = 0, cnt2 = 0, cnt3 = 0, cnt4 = 0; for (int i = 0; i <= n - 1; i = i + 1) { ...
4
#include <bits/stdc++.h> using namespace std; const long long INF = 1e17 + 7; const int N = 100; const int M = 20; vector<int> mem; vector<int> arr; int main() { int n, m; scanf("%d %d", &n, &m); for (int i = 0; i < n; i++) { int t; scanf("%d", &t); int cnt = 0; while (t) { if (t & 1) mem.pu...
11
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf("%d", &n); char ent[n][n]; int ok = 1; for (int i = 0; i < n; ++i) scanf("%s", ent[i]); for (int i = 1; i < n - 1; ++i) { for (int j = 1; j < n - 1; ++j) { if (ent[i][j] == '#' && ent[i + 1][j] == '#' && ent[i - 1][j] == '#' &...
3
#include <bits/stdc++.h> static std::vector<char> is_prime; static std::vector<long long> primes; static void one_case(void) { static std::vector<long long> factors; long long n; std::scanf("%lld", &n); if (n <= 11 && (is_prime[n] || n == 1)) { std::printf("-1\n"); } else { std::printf("%lld\n", (n % ...
5
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; int a[N]; struct segtree { segtree(int n) : n(n) { num.resize(n << 2); build(1, 1, n); } void build(int p, int l, int r) { num[p].resize(r - l + 1); if (l == r) { num[p][0] = a[l]; return; } int mid = (l + r) ...
11
#include <bits/stdc++.h> using namespace std; const long long N = 5e4 + 100; long long n; vector<long long> v[N], p, q; map<long long, long long> mp; signed main() { long long T = 1; cin >> T; while (T--) { cin >> n; for (long long i = 0; i < n; i++) v[i].clear(); for (long long i = 0; i < n; i++) { ...
2
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 3; int n, t; double long p; double long dp[2003][2003]; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> p >> t; for (int i = 1; i <= n; ++i) for (int j = 1; j <= t; ++j) { dp[i][j] = (dp[i - 1][j - 1] + 1) *...
9
#include <bits/stdc++.h> using namespace std; const int MaxN = 1 << 20; int N; char S[MaxN]; vector<string> Sol; inline string toString(int Number) { string Ret = ""; while (Number) { Ret += '0' + Number % 10; Number /= 10; } if (!Ret.size()) Ret = "0"; reverse(Ret.begin(), Ret.end()); return Ret; }...
13
#include <bits/stdc++.h> using namespace std; mt19937_64 mt_rnd_64(chrono::steady_clock::now().time_since_epoch().count()); long long rnd(long long l, long long r) { return (mt_rnd_64() % (r - l + 1)) + l; } using ll = long long; using ld = long double; using ull = unsigned long long; const double PI = acos(-1.0); co...
10
#include <bits/stdc++.h> using namespace std; const int inf = 1e9 + 7; inline void rvi(vector<int>& v, int n) { int temp; for (int i = 0; i < n; i++) { cin >> temp; v.push_back(temp); } } inline void rvll(vector<long long int>& v, int n) { long long int temp; for (int i = 0; i < n; i++) { cin >> t...
7
#include <bits/stdc++.h> using namespace std; struct lest { int beg, end, kol; }; int main() { int n, m, k, t; long long res = 0; cin >> n >> m >> k; vector<lest> A(m); for (int i = 0; i < m; ++i) cin >> A[i].beg >> A[i].end >> A[i].kol; for (int i = 0; i < k; ++i) { cin >> t; for (int j = 0; j < ...
8
#include <bits/stdc++.h> using namespace std; int main(void) { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); map<string, int> m; m["00"] = -1; m["01"] = 0; m["10"] = 1; m["11"] = 2; int n; cin >> n; vector<vector<int>> v(3); priority_queue<int> pq; for (int i = 0; i < n; ++i) { string ...
7
#include <bits/stdc++.h> using namespace std; const int K = 18; int cnt[10]; string l, r; bool exists(int lb, int rb) { for (int i = lb; i <= rb; i++) if (cnt[i] > 0) return true; return false; } bool test(int, bool, bool); bool try_test(int p, bool lf, bool rf, int x) { if (cnt[x] == 0) return false; cnt[x...
19
#include <bits/stdc++.h> using namespace std; int u[1000010], w[1000010], a[5010]; int n, k; int main() { cin >> n >> k; for (int i = 1; i <= n; i++) { cin >> a[i]; } sort(a + 1, a + n + 1); for (int i = 1; i <= n; i++) { for (int j = 1; j < i; j++) { w[a[i] - a[j]]++; } } for (int ans =...
16
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; int tree[N], len[30], ans[N]; int n, m, q, xm, ym, zm, xl, xr, yl, yr, zl, zr, x, y, z, Wr, R; struct data { int x, y, z, p; } a[27][N]; bool cmpx0(const data& a, const data& b) { return a.x < b.x || (a.x == b.x && a.p < b.p); } bool cmpx1(const d...
19
#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 a[n]; for (int i = 0; i < n; i++) cin >> a[i]; int ans[n], sm = a[n - 1]; ans[n - 1] = 1; for (int i = n - 2; ~i; i--) { if (sm >= 0) { sm -= a[i]; ...
11
#include <bits/stdc++.h> using namespace std; int main() { int n, mp = INT_MAX, nk = 0, h = 0, y = 0, sum = 0, k = INT_MIN, in = 0; int count = 0; set<int> s; cin >> n; int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; s.insert(a[i]); sum = sum + a[i]; if (a[i] > k) { k = a[i]; ...
5
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s; cin >> s; int ans = 0; for (int i = 0; i < n; i++) if (s[i] - '0' == i % 2) ans++; cout << min(n - ans, ans) << endl; return 0; }
10
#include <bits/stdc++.h> using namespace std; const int maxn = 1e3 + 10; int n, m; int a[maxn]; int main() { int x1, x2, y1, y2; cin >> n >> x1 >> y1 >> x2 >> y2; if (x1 == x2 && (x1 == 0 || x1 == n)) { cout << abs(y1 - y2) << endl; } else if (y1 == y2 && (y1 == 0 || y1 == n)) { cout << abs(x1 - x2) << ...
5
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n, m, k; cin >> n >> m >> k; if (k > 4 * n * m - 2 * n - 2 * m) { cout << "NO" << '\n'; return 0; } vector<pair<int, int>> ans; if (n == 1) { ans.push_back({4, min(m -...
12
#include <bits/stdc++.h> using namespace std; const int INF = 1e9; const long long LINF = 1e18; const long double EPS = 1e-10; const long double PI = 3.141592653589; long long gcd(long long a, long long b) { if (b == 0) return a; return gcd(b, a % b); } long long nok(long long a, long long b) { return a * b / gcd(a...
3
#include <bits/stdc++.h> using namespace std; int main() { int n, one = 0, zero = 0; string s; cin >> n; cin >> s; for (char c : s) { if (c == '1') ++one; else ++zero; } if (one == zero) { cout << 2 << '\n'; for (int i = 0; i <= n - 2; i++) cout << s[i]; cout << " "; co...
0
#include <bits/stdc++.h> using namespace std; template <typename T> void read(T &t) { char ch = getchar(); int f = 1; while ('0' > ch || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } t = 0; do { (t *= 10) += ch - '0'; ch = getchar(); } while ('0' <= ch && ch <= '9'); t *= f; } con...
8
#include <bits/stdc++.h> using namespace std; const int N = 300005; int n, a, b, c, d, start, len; int t[N], q[N]; long long sum[N]; int main() { scanf("%d%d%d%d%d%d%d", &n, &a, &b, &c, &d, &start, &len); for (int i = 1; i <= n; i++) { scanf("%d%d", &t[i], &q[i]); if (q[i]) sum[i] = sum[i - 1] + c; ...
16
#include <bits/stdc++.h> using namespace std; int n, k, x = 1; int a[10005][5]; int main() { scanf("%d%d", &n, &k); for (int i = 1; i <= n; i++) { a[i][1] = x * k; a[i][2] = (x + 1) * k; a[i][3] = (x + 2) * k; a[i][4] = (x + 4) * k; x += 6; } printf("%d\n", a[n][4]); for (int i = 1; i <= n...
11
#include <bits/stdc++.h> const int N = 1e6 + 5, ZZQ = 1e9 + 7; char s[N], t[N]; int a, b, c, d, n, ns, nt, l[N], r[N], fac[N], inv[N], cnt[2][2]; int C(int n, int m) { if (n < m) return 0; return 1ll * fac[n] * inv[m] % ZZQ * inv[n - m] % ZZQ; } int calc(int n, int m, int k) { if (!n) return !m && !k; if (!m) r...
16
#include <bits/stdc++.h> using namespace std; template <class T1, class T2, class T3 = hash<T1>> using umap = unordered_map<T1, T2, T3>; template <class T> using uset = unordered_set<T>; template <class T> using vec = vector<T>; const long long infll = numeric_limits<long long>::max() >> 1; const long long inf = numeri...
15
#include <bits/stdc++.h> using namespace std; signed main() { int pages; cin >> pages; int a[7]; for (int i = 0; i < 7; ++i) { cin >> a[i]; } int total = 0; while (total < pages) { for (int i = 0; i < 7; ++i) { total += a[i]; if (total >= pages) { cout << i + 1 << endl; ...
2
#include <bits/stdc++.h> #pragma GCC target("avx2") #pragma GCC optimization("O3") #pragma GCC optimization("unroll-loops") using namespace std; template <typename A, typename B> ostream& operator<<(ostream& os, const pair<A, B>& p) { os << "(" << p.first << "," << p.second << ") "; return os; } template <typename ...
13
#include <bits/stdc++.h> using namespace std; vector<int> ed[101000]; int n; int col[101000]; inline void dfs(int np, int c) { if (col[np]) return; col[np] = c; for (int i = 0; i < ed[np].size(); i++) dfs(ed[np][i], 3 - c); } int u[101000]; int to[101000]; int cnt[101000]; vector<int> ccc; int main() { int m; ...
17
#include <iostream> #include <cstdio> #include <sstream> #include <algorithm> #include <iomanip> #include <cmath> #include <ctime> #include <cstdlib> #include <set> #include <map> #include <vector> #include <queue> #include <iterator> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #defi...
10
#include <bits/stdc++.h> using namespace std; int main() { set<string> s; string a, b; cin >> a; s.insert(a); for (int i = 0; i < a.size() - 1; i++) { b = ""; for (int j = 0; j < a.size() - 1; j++) b = b + a[j]; b = a[a.size() - 1] + b; s.insert(b); a = b; } cout << s.size(); return ...
1
#include <bits/stdc++.h> using namespace std; const int MOD = 1e8; int main() { int q; cin >> q; while (q--) { long long h, c, t, l, r, m; cin >> h >> c >> t; if (t >= h) { cout << "1\n"; continue; } l = 1; r = 1e9; while (r - l > 1) { m = (l + r) / 2; if ((m * ...
9
#include <bits/stdc++.h> using namespace std; int n, k, a, ans, tmp; int main() { ans = 0; cin >> n; for (int i = 0; i < n; i++) { cin >> k >> a; if (a == 1) tmp = 1; else tmp = ceil(log((double)a) / log(4.0)); ans = max(ans, k + tmp); } cout << ans << '\n'; }
8
#include<bits/stdc++.h> using namespace std; #define int __int128 const int N=4e5+1e3+7; int read() { int x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f; } int cnt; struct T{ int l,r,ls,rs; int ...
25
#include <bits/stdc++.h> long long max(long long x, long long y) { return (x > y ? x : y); } long long min(long long x, long long y) { return (x < y ? x : y); } int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } using namespace ::std; const int maxn = 1e6 + 500; const int inf = 1e9 + 800; const int mod = 1e9 + 7; ...
12
#include<bits/stdc++.h> using namespace std; #define ll long long #define ull unsigned long long #define db double #define pii pair<int,int> #define pli pair<ll,int> #define pil pair<int,ll> #define pll pair<ll,ll> #define ti3 tuple<int,int,int> #define mat vector<vector<int>> const int inf = 1 << 30; const ll linf = 1...
17
#include <bits/stdc++.h> using namespace std; vector<int> mass[1000500]; long long masss[1000050]; int ans[1000050]; int summ = 0; long long const MOD = 998244353; long long binpow(long long a, long long n) { if (n == 0) return 1; if (n % 2 == 1) return ((binpow(a, n - 1) * a) % MOD); else { long long b =...
9
#include <bits/stdc++.h> using namespace std; int T[2005]; int S[2005][2005]; int main() { ios_base::sync_with_stdio(false); cin.tie(); cout.tie(); int t; cin >> t; while (t--) { int n, k; cin >> n >> k; for (int i = 1; i <= n; i++) { int x; cin >> x; T[i] = i - x; } fo...
12
#include <bits/stdc++.h> using namespace std; const int M = 1e9 + 7; struct mint { int x; mint(int x) : x(x) {} friend mint operator+(const mint &a, const mint b) { const int x = a.x + b.x; return mint(x >= M ? x - M : x); } friend mint operator-(const mint &a, const mint b) { const int x = a.x - ...
14
#include <bits/stdc++.h> using namespace std; const int maxn = 3e5 + 3; const int M = 998244353; int _, n, f; char s[maxn], t[maxn]; int main() { scanf("%d", &_); while (_--) { scanf("%d%s%s", &n, s + 1, t + 1); vector<int> ans; ans.clear(); int l = 1, r = n, pos; f = 0; for (int i = n; i; i...
5
#include <bits/stdc++.h> int main() { long long n, m, i, j, x; scanf("%I64d %I64d", &n, &m); x = pow(2, n); i = m % x; printf("%I64d", i); }
1
#include <bits/stdc++.h> using namespace std; int sq = 500; vector<int> gr[100009]; string pattern[100009]; vector<pair<pair<int, int>, int> > que[100009]; int n; struct aho { int f[100009], g[100009][26], sz; vector<int> out[100009], goin[100009], goinsq[100009]; aho() { memset(g, -1, sizeof(g)); memset(...
22
#include <bits/stdc++.h> using namespace std; int gcd(int a, int b) { if (b > a) return gcd(b, a); if (b == 0) return a; return gcd(b, a % b); } int main() { int n, i, j; cin >> n; vector<int> arr(n); for (i = 0; i < n; i++) cin >> arr[i]; vector<int> res; res.push_back(arr[0]); int k = 0; for (i ...
4
#include <bits/stdc++.h> using namespace std; int n; vector<string> sl; map<int, set<int>> bef, aft; bool comp(const string &s1, const string &s2) { int len = min(s1.length(), s2.length()); for (int i = 0; i < len; i++) if (s1[i] != s2[i]) { bef[s2[i] - 'a'].insert(s1[i] - 'a'); aft[s1[i] - 'a'].ins...
8
#include <bits/stdc++.h> using namespace std; int n, m, K, Q, pv[101000], IT[131072 + 131072 + 1]; vector<int> E[101000]; bool chk[201000]; struct point { int x, y; bool operator<(const point &p) const { return y < p.y; } } w[201000]; struct Query { int x1, x2, y1, y2, num; bool operator<(const Query &p) const ...
16
#include <bits/stdc++.h> using namespace std; int main() { long long int a, b, c, d, e, f, g, i, j, k, t, x, y, z, m, n; int flag = 0; cin >> a >> b >> c >> d >> e >> f; for (x = 1; x < 10; x++) { for (y = 1; y < 10; y++) { for (m = 1; m < 10; m++) { for (n = 1; n < 10; n++) { if (x ...
2
#include <bits/stdc++.h> using namespace std; long long delbit(long long a, long long k) { return a & (~(1 << k)); } int delbit(int a, int k) { return a & (~(1 << k)); } bool getbit(long long a, long long k) { return 1 & (a >> k); } bool getbit(int a, int k) { return 1 & (a >> k); } long long setbit(long long a, long l...
11
#include <bits/stdc++.h> using namespace std; int n, a, b, dp[1000001], jmp[1000001]; vector<int> dv[1000001]; int main() { scanf("%d", &n); unordered_set<int> xs; for (int i = 0; i < n; i++) { int tmp; scanf("%d", &tmp); xs.insert(tmp); } scanf("%d%d", &a, &b); int num = a, ans = 0; while (nu...
14
#include <bits/stdc++.h> using namespace std; int s[105]; int main() { int t; cin >> t; while (t--) { int n; cin >> n; for (int i = 1; i <= n; i++) cin >> s[i]; s[0] = *max_element(s + 1, s + 1 + n); int ned = 0; for (int i = 1; i <= n; i++) ned += (s[0] - s[i]) % 2; cout << (ned == 0 ...
1
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int t; cin >> t; vector<int> sa, sb, p; vector<int> ans; while (t--) { int len; cin >> len; sa = sb = p = vector<int>(len); ans.clear(); char input; for (int i = 0; i < len; i++...
9
#include <bits/stdc++.h> using namespace std; const int maxn = 3 * 1e5 + 10; const double PI = 3.14159265359; vector<int> g[maxn]; int d[maxn]; bool r[maxn]; set<int> s; int main() { ios::sync_with_stdio(0); int n, a, b, m; cin >> n >> m; for (int i = 0; i < m; i++) { cin >> a >> b; a--, b--; g[a].p...
14
#include <bits/stdc++.h> using namespace std; long long egcd(long long a, long long b, long long &x, long long &y) { if (b == 0) { x = 1, y = 0; return a; } long long c = egcd(b, a % b, x, y); long long d = x; x = y; y = d - a / b * x; return c; } int n, m; long long mod = 1000000007; int main() {...
10
#include <bits/stdc++.h> using namespace std; vector<string> split(const string& s, char c) { vector<string> v; stringstream ss(s); string x; while (getline(ss, x, c)) v.emplace_back(x); return move(v); } void err(vector<string>::iterator it) {} template <typename T, typename... Args> void err(vector<string>:...
11
#include <bits/stdc++.h> using namespace std; int main() { { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); }; int n; cin >> n; int c = 0, x, counter = 0; int arr[n + n + 5]; for (int i = 0; i < n; i++) { cin >> arr[i]; arr[n + i] = arr[i]; } for (int i = 0; i < n...
1
#include <bits/stdc++.h> using namespace std; pair<double, double> ar[200001]; int main() { double n, p1x, p1y, p2x, p2y, p3x, p3y, d, m, ans = 100000000000000; long int i, tempn; cin >> n; tempn = n; for (i = 0; i < n; i++) { cin >> ar[i].first >> ar[i].second; } for (i = 0; i < n; i++) { if (i <...
10
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; long long s = 0; for (long long i = 0; i <= n - 1; ++i) { long long temp; cin >> temp; if (temp - s > 15) continue; s = temp; } if (s + 15 < 90) cout << s + 15 << endl; else cout << "90" << endl; }
0
#include <bits/stdc++.h> using namespace std; long long f[10005]; void jaadu() { f[0] = 0; for (int i = 1; i < 10005; i++) { f[i] = i + f[i - 1]; } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); jaadu(); long long n, k, l; cin >> n; n = upper_bound(f, f + 10005, ...
8
#include <bits/stdc++.h> using namespace std; int main() { double n, w, p, i = 0; cin >> n >> w >> p; for (;; i++) { if (double(double(w + i) / n) >= double(double(p) / double(100))) { cout << i; break; } } }
1
#include <bits/stdc++.h> using namespace std; int n; int a[1000000]; int antle[1000000][5], antri[1000000][5]; struct triple { int x, nx, n0; triple() {} triple(int inx, int innx, int inn0) { x = inx; nx = innx; n0 = inn0; } }; int main() { ios::sync_with_stdio(false); cin >> n; for (int i = 0...
17
#include <bits/stdc++.h> using namespace std; int n, m; int f1[100100], f2[100100]; int f[200200], tot; int ans[100100], x, y; int main() { while (~scanf("%d%d", &n, &m)) { memset(f1, 0, sizeof(f1)); memset(f2, 0, sizeof(f2)); memset(ans, 0, sizeof(ans)); tot = 0; for (int i = 0; i < n; i++) { ...
15
#include <bits/stdc++.h> using namespace std; bool down[110][110], righ[110][110]; char board[210][210]; void black(int x, int y) { down[x][y] = righ[x][y] = true; board[2 * x][2 * y] = board[2 * x][2 * y + 1] = board[2 * x + 1][2 * y] = board[2 * x + 1][2 * y + 1] = '#'; } void white(int x, int y) { board[...
20
#include <bits/stdc++.h> using namespace std; inline int ReadInt() { static int n, ch; n = 0, ch = getchar(); while (!isdigit(ch)) ch = getchar(); while (isdigit(ch)) n = (n << 3) + (n << 1) + ch - '0', ch = getchar(); return n; } const int MAX_H = 35, maxn = 500000 + 3; double dp[maxn][MAX_H]; int n = 1, fa[...
19
#include <bits/stdc++.h> using namespace std; char s[100005], ans[100005]; int main() { int n, i, j; while (scanf("%d", &n) != EOF) { for (i = 0; i < n; i++) { scanf("%s", s); if (i == 0) { for (j = 0; s[j]; j++) ans[j] = '?'; ans[j] = 0; } for (j = 0; s[j]; j++) { ...
4
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const long long LINF = 0x3f3f3f3f3f3f3f3f; const int MOD = (int)1e9; const int N = (int)1e3 + 7; const double eps = 1e-6; bool eq(const double &a, const double &b) { return fabs(a - b) < eps; } bool ls(const double &a, const double &b) { return a...
12
#include <bits/stdc++.h> using namespace std; int a[200000], b[200000], c[200000]; int main() { int n, i, j, max1 = -1; cin >> n; for (i = 0; i < n; i++) cin >> a[i]; b[0] = 1; for (i = 1; i < n; i++) { if (a[i] > a[i - 1]) { b[i] = b[i - 1] + 1; } else b[i] = 1; } c[n - 1] = 1; for ...
8
#include <bits/stdc++.h> using namespace std; const int MAXV = 7000; const int N = (int)1e6 + 3; vector<bitset<MAXV + 1> > bits; vector<bitset<MAXV + 1> > facts; vector<bitset<MAXV + 1> > xors; int main(int argc, char* argv[]) { ios::sync_with_stdio(0); int n, q; cin >> n >> q; bits.resize(n); facts.resize(MA...
17
#include <bits/stdc++.h> using namespace std; int n; pair<int, int> find_max(int a[]) { pair<int, int> m(a[0], 0); for (int i = 1; i < n; i++) { if (a[i] >= m.first) { m.first = a[i]; m.second = i; } } return m; } int main() { ios_base::sync_with_stdio(false); cin >> n; int a[n], c = 0...
4
#include <bits/stdc++.h> using namespace std; int main() { int h, n; cin >> n >> h; int friends[1000]; for (int i = 0; i < n; i++) { cin >> friends[i]; } int counter = n; for (int i = 0; i < n; i++) { if (friends[i] > h) { counter++; } } cout << counter; }
0
#include <bits/stdc++.h> using namespace std; long long solve(int n, int m, int k) { if (k < n) return 1LL * n / (k + 1) * m; k -= n - 1; return 1LL * m / (k + 1); } int main() { int n, m, k; scanf("%d%d%d", &n, &m, &k); long long ans = max(solve(n, m, k), solve(m, n, k)); if (k > n + m - 2) { cout <<...
9
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; vector<pair<int, int> > adj[N]; bool use[N]; int dfs(int node) { vector<int> a; for (auto &ele : adj[node]) { if (use[ele.second]) continue; use[ele.second] = 1; a.push_back(ele.first); } int rem = 0; for (auto &ele : a) { in...
15
#include<bits/stdc++.h> using namespace std; #define MAXN 210500 #define ll long long vector<int>e[MAXN]; int vis[MAXN]; int a[MAXN]; int d[MAXN]; int main() { int t;cin>>t; while(t--) { int n;cin>>n; for(int i=1;i<=n;i++) { e[i].clear(); vis[i]=0; a[i]=1;...
12
#include <bits/stdc++.h> using namespace std; class sphere { public: double x, v, m; int n; sphere() { x = v = m = n = 0; } sphere(double _x, double _v, double _m, int _n) { x = _x; v = _v; m = _m; n = _n; } }; bool ud(sphere s1, sphere s2) { if (s1.x != s2.x) return s1.x < s2.x; return s...
12
#include <bits/stdc++.h> using namespace std; namespace HABIT { const int MAXN = 5e5 + 10; typedef int ar[MAXN]; template <typename T> inline T Max(T a) { return a; } template <typename T, typename... Args> inline T Max(T a, Args... args) { T b = Max(args...); return (a > b) ? a : b; } template <typename T> inlin...
14
#include <bits/stdc++.h> using namespace std; long long int n, q, x; char s[100100]; int main() { while (scanf("%lld %lld", &n, &q) != EOF) { for (int i = 0; i < q; i++) { scanf("%lld\n", &x); scanf("%s", &s); int sz = strlen(s); for (int j = 0; j < sz; j++) { if (s[j] == 'U') { ...
11
#include <bits/stdc++.h> using namespace std; int const p = 998244353; int mod(int x) { return x >= p ? x - p : x; } int pw(int x, int y) { int res = 1; while (y) { if (y & 1) res = 1ll * res * x % p; x = 1ll * x * x % p; y >>= 1; } return res; } int n, m, k, ans[55], d[55][55], C[55][55]; long long...
19