solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); int t, n, a, b, k, c, G; cin >> t; vector<int> D[1000], T; int A[1000], B[1000], g[1000], K[1000]; for (int i = 0; i < t; i++) { cin >> n; for (int y = 0; y < n; y++) { A[y] = 0; B[y] = 0; g[y] ...
11
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:66777216") using namespace std; int a, b, c, d, i, j, n, m, k, s; int cs[100001]; long long ret[100001], tmp[100001]; vector<int> sm[100001]; long long dfs(int v, int pr) { if (!cs[v]) return 0; for (int _n(((int)((sm[v]).size())) - 1), i(0); i <= _n; i++) { ...
13
#include <bits/stdc++.h> using namespace std; int n, a[601], ans; int main() { scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", a + i); } sort(a, a + n); n = unique(a, a + n) - a; ans = n - (a[0] == 0); cout << ans; }
0
#include <bits/stdc++.h> using namespace std; int n, k, a[101], h; int main() { cin >> n >> k; for (int i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); for (int i = n - 1; i >= 0; i--) { if (k % a[i] == 0) { h = k / a[i]; break; } } cout << h; return 0; }
1
#include <bits/stdc++.h> using namespace std; struct node { int mn, mx, lz; int l, r; }; const int MAXN = 3e5 + 5; const int MAIOR = 1e6 + 3; vector<node> seg; int dishes[MAXN], pupils[MAXN]; int n, m, q; int novo() { node cara; cara.mn = cara.mx = 0; cara.l = cara.r = cara.lz = 0; seg.emplace_back(cara); ...
14
#include <bits/stdc++.h> using namespace std; int main() { int k, n; cin >> n >> k; vector<pair<int, int>> pp; set<pair<int, int>> seg; vector<int> cnt(200042, 0), sub(200042, 0); vector<int> v, ans, gg[200042]; vector<int> erased(n, 0); for (int i = 0; i < n; i++) { int x, y; cin >> x >> y; ...
10
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; int a[n], b[m]; for (int i = 0; i < n; i++) a[i] = 0; for (int i = 0; i < m; i++) b[i] = 0; for (int i = 0; i < n; i++) { string s; cin >> s; for (int j = 0; j < m; j++) { if (s[j] == '*') { a[i]++;...
0
#include <bits/stdc++.h> using namespace std; inline int read() { int a = 0; char c = getchar(); bool f = 0; while (!isdigit(c)) { if (c == '-') f = 1; c = getchar(); } while (isdigit(c)) { a = (a << 3) + (a << 1) + (c ^ '0'); c = getchar(); } return f ? -a : a; } const int MAXN = 2010; ...
18
#include <bits/stdc++.h> using namespace std; int main() { int t, k; cin >> t >> k; long long prefix[100001] = {0}; const int mod = 1e9 + 7; for (int i = 1; i <= 100000; i++) { if (i < k) prefix[i] = (prefix[i - 1] + 1) % mod; else prefix[i] = (2 + prefix[i - k] + prefix[i - 1]) % mod; }...
9
#include <bits/stdc++.h> using namespace std; const int dx[4] = {-1, 0, 1, 0}; const int dy[4] = {0, -1, 0, 1}; int w, h, n, edg[105][105][4], v[105][105], qa[10005], qb[10005], ans[105]; int main() { scanf("%d%d%d", &w, &h, &n); for (int i = 1; i <= n; i++) { int x1, y1, x2, y2; scanf("%d%d%d%d", &x1, &y1,...
12
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const int N = 2e5 + 5; int a[N], b[N]; int dp[N][2]; int main() { int n, c; scanf("%d %d", &n, &c); memset(dp, inf, sizeof dp); for (int i = 2; i <= n; i++) scanf("%d", &a[i]); for (int i = 2; i <= n; i++) scanf("%d", &b[i]); dp[1][0]...
9
#include <bits/stdc++.h> using namespace std; template <class T> void show(T a, int n) { for (int i = 0; i < n; ++i) cout << a[i] << ' '; cout << endl; } template <class T> void show(T a, int r, int l) { for (int i = 0; i < r; ++i) show(a[i], l); cout << endl; } const int N = 1 << 18; const int M = 1 << 20; con...
19
#include <bits/stdc++.h> using namespace std; char _; int n, par[600005], xcnt[600005], ycnt[600005]; int first, second, gl, gr; long long ans; map<pair<int, int>, int> m; vector<pair<int, int> > seg[1200005]; vector<pair<int, int> > res[1200005]; int root(int A) { for (; par[A] != 0; A = par[A]) ; return A; } ...
18
#include <bits/stdc++.h> using namespace std; int main() { int aza[50] = {-1}, count[50], aC = 0, groups[17][20]; for (int i = 0; i < 50; i++) { aza[i] = -1; count[i] = 0; } for (int i = 0; i < 17; i++) for (int j = 0; j < 20; j++) groups[i][j] = 0; int n, m; cin >> n >> m; for (int i = 0; i <...
7
#include <bits/stdc++.h> namespace IO { template <typename T> inline void swap(T &x, T &y) { T tmp = x; x = y, y = tmp; } template <typename T> inline T abs(T x) { return x > 0 ? x : -x; } template <typename T> inline T min(T x, T y) { return x < y ? x : y; } template <typename T> inline T max(T x, T y) { ret...
24
#include <bits/stdc++.h> using namespace std; int n; int vt[111111]; int a[111111]; int maxlen; int main() { cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; } vt[0] = 0; maxlen = 0; for (int i = 1; i <= n; i++) { if (vt[maxlen] < a[i]) { maxlen++; vt[maxlen] = a[i]; continue;...
7
#include <bits/stdc++.h> using namespace std; const int N = 1e9; void solve() { vector<int> z; z.push_back(0); int cng = 1, st = 0, prev = 0, ad = 0; while (z.back() <= N) { st++; if (st == cng) { ad++; cng *= 10; } prev += ad; z.push_back(z.back() + prev); } int t; cin >> ...
11
#include <bits/stdc++.h> using namespace std; mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); mt19937 rnf(2106); const int N = 2003; const int xx[8] = {0, 1, 0, -1, 1, -1, 1, -1}; const int yy[8] = {1, 0, -1, 0, 1, -1, -1, 1}; struct ban { int x, y; ban() {} ban(int x, int y) { this->x = ...
11
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; namespace IO { template <class T> void re(complex<T>& x); template <class T1, class T2> void re(pair<T1, T2>& p); inline bool blank(char c) { return (c == ' ' || c == '\t' || c == '\r' || c == '\n'); }; template <class T> void...
6
#include <bits/stdc++.h> using namespace std; int dp[2010][2010]; int main() { int n, k, i, j, l; int b[2010], subseq = 0; int di[2010]; long long rez = 0; cin >> n >> k; memset(dp, 0, sizeof(dp)); for (i = 0; i <= 2000; i++) { dp[1][i] = 1; } for (i = 0; i < k; i++) { for (j = 1; j <= n; j++)...
6
#include <bits/stdc++.h> using namespace std; const int MAXN = 1010; int ANS[2333333], *ans = ANS; int N, A[MAXN]; void Move(int u, int v) { A[u] -= A[v]; A[v] *= 2; ans[0] = v; ans[1] = u; ans += 2; } bool cmp(int a, int b) { return A[a] < A[b]; } int W[MAXN]; void ShandongBlueFly(int a, int b, int c) { in...
22
#include <bits/stdc++.h> using namespace std; int main() { char a[100]; cin >> a; int n = strlen(a); for (int i = 0; i < n; i++) a[i] = tolower(a[i]); int i = 0; while (i < n) { if (a[i] != 'a' && a[i] != 'e' && a[i] != 'i' && a[i] != 'o' && a[i] != 'u' && a[i] != 'y') { cout << "." << a[i...
2
#include <bits/stdc++.h> const long double PI = 3.14159265359; using namespace std; int n; long double r, v; long double dis; int check(long double t) { if (t <= 0) return 0; long double tmp = floor(t / (2 * PI * r)); tmp *= 2 * PI * r; long double hlp = t - tmp; hlp /= 2 * r; hlp = r * sin(hlp); hlp *= 2...
17
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize("-Ofast") #pragma GCC target( \ "sse,sse2,sse3,ssse3,sse4,sse4.2,popcnt,abm,mmx,avx2,tune=native") #pragma GCC optimize("-ffast-math") #pragma GCC optimize("-funroll-loops") using ll = long long; using ld = long double; const int N = 2e5 + 7; const ...
15
#include <bits/stdc++.h> using namespace std; struct Suffix_Automaton { struct state { int len, link, siz; int next[26]; } t[101000 << 1]; int cnt, lst; void init() { cnt = lst = 1; } void extend(int c) { int cur = ++cnt; t[cur].len = t[lst].len + 1, t[cur].siz = 1; int u = lst; while ...
15
#include <bits/stdc++.h> using namespace std; char ch[100]; string s; map<string, int> mp; int main() { int i, ma = -1, n; mp.clear(); scanf("%d", &n); for (i = 0; i < n; ++i) { scanf("%s", ch); s = ch; if (mp.count(s) == 0) mp[s] = 1; else mp[s]++; } map<string, int>::iterator p...
2
#include <bits/stdc++.h> using namespace std; int n, lg_n; long long a[300005]; int pos; long long dp[20][300005]; const long long INF = 1e17; int main() { ios::sync_with_stdio(false); cin >> n; lg_n = 1; while ((1 << lg_n) < n) ++lg_n; for (int i = 1; i <= (n); ++i) cin >> a[i]; if (a[n] == -1) { cout ...
16
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long n; cin >> n; for (long long i = 1; i != n; i++) { if (n * (n + i) % i == 0) { cout << n << " " << n + i << " " << n * (n + i) / i; return 0; } } cout << -1 << endl; }
7
#include <bits/stdc++.h> using namespace std; vector<pair<long long, long long> > v; int main() { long long x, n, i, j; scanf("%lld", &x); for (i = 1; i <= 2000000; i++) { long long p = 6 * x - i + (i * i * i); j = 3 * ((i * i) + i); if (p % j != 0) continue; if (p / j < i) continue; v.push_ba...
11
#include <bits/stdc++.h> using namespace std; const double EPS = 1E-9; int n, m; vector<int> v; int main() { cin >> n >> m; bool order = true; int id = (m + 1) / 2, left, right; left = id - 1, right = id + 1; v.push_back(id); if (m % 2 == 0) order = false; while (true) { if (m % 2 == 1 && !left && rig...
5
#include <bits/stdc++.h> using namespace std; #define ll long long #define all(x) x.begin(), x.end() #define pb push_back #define mp make_pair #define ps push #define in insert #define f first #define s second #define ca(v) for(auto i:v) cout<<i<<" "; #define cp(v) for(auto i:v) cout<<i.f<<" "<<i.s<<"\n"; #define nl ...
16
#include <bits/stdc++.h> using namespace std; #define int long long #define endl '\n' #define MOD 1000000007 #define ar array #define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int32_t main() { fast_io; int t; cin >> t; while (t--) { int n; cin >> n; int num_dig = 0; vector<i...
0
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 10; bool ok[N]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, k; cin >> n >> k; string a; cin >> a; string b = a; for (int i = 0; i < n; ++i) { if (i >= k) { b[i] = b[i - k]; } } if (b >= a) { ...
9
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:836777216") using namespace std; struct pt { int x, y; pt() { x = 0, y = 0; } pt(int _x, int _y) { x = _x; y = _y; } }; vector<pt> v; bool cmp1(const pt &a, const pt &b) { return a.x < b.x || (a.x == b.x && a.y < b.y); } bool left(pt a, pt b, pt...
12
#include <bits/stdc++.h> using namespace std; int v[105]; int main() { int n, i, rez = 0; cin >> n; for (i = 1; i <= n; i++) cin >> v[i]; if (n % 2 == 0 || n < 3) { cout << "-1\n"; return 0; } for (i = n; i > 1; i--) if (v[i] != 0) { if ((v[(i - (i % 2)) / 2] -= v[i]) < 0) v[(i - (i % 2)) ...
9
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; if (m == 1) { if (n == 1) cout << 1 << "\n"; else cout << 2 << "\n"; } else if (m == n) { cout << n - 1 << "\n"; } else { int a = m - 1; int b = n - m; if (a > b) { cout << m - 1 << "\...
5
#include <bits/stdc++.h> using namespace std; int main() { string s; map<string, int> m; cin >> s; for (int i = 0; i < 10; i++) { string t; cin >> t; m[t] = i; } int b = 0, e = 10; for (int i = 0; i < 8; i++) { string t = ""; for (int j = b; j < e; j++) { t += s[j]; } cou...
1
#include <bits/stdc++.h> using namespace std; long long pm(long long a, long long e) { long long r = 1; while (e) { if (e & 1) r = r * a % 998244353; e >>= 1; a = a * a % 998244353; } return r; } struct CD { long long r; CD(long long r = 0) : r(r) {} }; CD operator*(const CD& a, const CD& b) { r...
16
#include <bits/stdc++.h> using namespace std; long long bigmod(long long a, long long b, long long mod) { if (b == 0) return 1; if (b % 2 == 0) { long long hh = bigmod(a, b / 2, mod); return (hh * hh) % mod; } else { return (a * bigmod(a, b - 1, mod)) % mod; } } int main() { ios_base::sync_with_st...
1
#include <bits/stdc++.h> using namespace std; const int N = (int)1e5 + 123; const long long INF = (long long)1e18 + 123; const int inf = (int)1e9 + 123; const int MOD = (int)1e9 + 7; int x, n, a[4001]; string s; int pref[4001], cnt[1000000]; long long res; int main() { cin >> x >> s; n = (int)(s.size()); for (int...
8
#include <bits/stdc++.h> using namespace std; template <typename T> void read(T &x) { x = 0; char ch = getchar(); while (!isdigit(ch)) ch = getchar(); while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar(); } const int N = 150055; int To[N << 1], Ne[N << 1], He[N], _k = 1; long long ans = 0; inline void add(...
19
#include <bits/stdc++.h> using namespace std; const int MAXN = 100010; vector<int> e[MAXN]; vector<int> p[MAXN]; int n, m; int res[MAXN]; int step, tl[MAXN], tr[MAXN]; struct node { int l, r, flag, s; } t[MAXN << 3]; void dfs1(int u, int fa) { tl[u] = step++; for (int i = 0; i < e[u].size(); i++) { int v = e[...
16
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[n + 1]; a[0] = 0; for (int i = 1; i <= n; i++) { cin >> a[i]; a[i]--; a[i] += a[i - 1]; if (a[i] % 2 == 0) cout << "2" << endl; else cout << "1" << endl; } return 0; }
3
#include <bits/stdc++.h> using namespace std; int N; string S; vector<int> occ; int main() { ios::sync_with_stdio(0); cin >> N >> S; char last = S[0]; int len = 1; for (int i = 1; i < N; i++) { if (S[i] == last) len++; else { occ.push_back(len); last = S[i]; len = 1; } } ...
8
//#pragma GCC optimize(3) #include <bits/stdc++.h> using namespace std; #define repeat(i,a,b) for(int i=(a),_=(b);i<_;i++) #define repeat_back(i,a,b) for(int i=(b)-1,_=(a);i>=_;i--) #define mst(a,x) memset(a,x,sizeof(a)) #define fi first #define se second mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoc...
11
#include <bits/stdc++.h> inline int getint() { int x = 0, p = 1; char c = getchar(); while (c <= 32) c = getchar(); if (c == 45) p = -p, c = getchar(); while (c > 32) x = x * 10 + c - 48, c = getchar(); return x * p; } using namespace std; const int mod = 998244353; inline void reduce(int &x) { x += x >> 31...
23
#include <bits/stdc++.h> const int N = 1e5 + 5; const int base = 350; const int mod = 1e9; using ull = unsigned long long; using namespace std; int n, m, t, k, T, ans, a[N], d[N], c[N], tong, b[N], cnt[N], u, v, in[N], out[N]; vector<int> kq, adj[N]; string s; void dfs(int u, int p) { in[u] = ++k; d[k] = u; f...
16
#include <bits/stdc++.h> #include <string> typedef long long ll; typedef long double ldb; typedef double db; using namespace std; #define ff first #define ss second #define pb push_back #define pf push_front #define ins insert #define mp make_pair #define len(s) s.length() #define forp(i, a, b) for (ll i = a; i <= b;...
3
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 10; vector<int> vs[N]; bool vis[N], flag; int root; void dfs(int x, int f, int de) { vis[x] = 1; if (vs[x].size() != 2) return; for (int i = 0; i < vs[x].size(); i++) { int v = vs[x][i]; if (!vis[v] && v != f) dfs(v, x, de + 1); if (v =...
7
#include <bits/stdc++.h> using namespace std; const double eps = 1e-8; const double pi = acos(-1.0); template <class T> int chkmin(T &a, T b) { return a > b ? a = b, 1 : 0; } template <class T> int chkmax(T &a, T b) { return a < b ? a = b, 1 : 0; } template <class T> T sqr(T a) { return a * a; } template <class T...
16
#include <bits/stdc++.h> using namespace std; const int N = 404, M = 27; int n, m, r, c; char s[N][N], t[N][N]; bitset<N> ok[N], have_char[M][N]; inline int f(char c) { return c - 'a'; } inline bitset<N> cyclic_shift(bitset<N> b, int len) { return (b >> len) | (b << (m - len)); } inline void act(int x, int y, char c)...
18
#include <bits/stdc++.h> using namespace std; const int maxn = 30005, P = 1e7 + 19, Q = 1e9 + 7; int seg[maxn << 2], *dp[maxn << 2], obj[maxn * 17], nxt[maxn * 17], cnt; void ins(int u, int v) { obj[++cnt] = v; nxt[cnt] = seg[u]; seg[u] = cnt; } int i, j, tot, n, m, lx[maxn], rx[maxn], wt[maxn], va[maxn]; int qry...
20
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") using namespace std; vector<int> G[200005]; long long ar[200005], tree[2][2 * 200005]; int dfstime, start[200005], finish[200005], dep[200005]; void dfs(int s, int fr, int len) { start[s] = ++dfstime, dep[s] = len; for (int v ...
12
#include <bits/stdc++.h> using namespace std; long long int a, b; void f1(); void f2(); void f3(); void f1() { if (a == 0 || b == 0) { printf("%lld %lld", a, b); exit(0); } else f2(); } void f2() { if (a >= 2 * b) { a %= 2 * b; f1(); } else f3(); } void f3() { if (b >= 2 * a) b %= ...
3
#include <bits/stdc++.h> using namespace std; const double pi = acos(0.0) * 2.0; const long double eps = 1e-10; const int step[8][2] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}, {-1, 1}, {1, 1}, {1, -1}, {-1, -1}}; template <class T> inline T abs1(T a) { return a < 0 ? -a : a; } template <typename t,...
22
#include <bits/stdc++.h> using namespace std; map<int, int> mp; map<int, int>::iterator it; map<int, int> mp1; map<int, int>::iterator itt; int main() { int n, m, ans = 0, Max = 0; cin >> n >> m; for (int i = 0; i < n; i++) { int x; cin >> x; mp[x]++; } int cnt = 0; for (int i = 0; i < m; i++) {...
4
#include <bits/stdc++.h> using namespace std; int main() { int n, m, i, j, p; p = 0; cin >> n; while (n > 100) { cin >> n; } cin >> m; while (m > 100) { cin >> m; } char T[n][m]; for (i = 0; i < n; i++) { for (j = 0; j < m; j++) { cin >> T[i][j]; while (T[i][j] != 'C' && T[i]...
0
#include <bits/stdc++.h> using namespace std; int main() { int64_t x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2; int64_t n = (x2 - x1) / 2; int64_t m = (y2 - y1) / 2; cout << (n + 1) * (m + 1) + n * m << endl; return 0; }
11
#include <bits/stdc++.h> using namespace std; const int mod = 1000000007; inline void pl(int &x, int y) { (x += y) >= mod ? x -= mod : 0; } int n, ans; struct node { int va, id; friend bool operator<(node a, node b) { return a.va < b.va; } } p[500050]; struct BIT { int sum[500050]; void add(int p, int w) { ...
15
#include <bits/stdc++.h> using namespace std; const int MAXM = 100005; int N, M, W[MAXM]; int main() { scanf("%d%d", &N, &M); for (int i = 0; i < M; i++) { int t; scanf("%d%d", &t, &W[i]); } sort(W, W + M); int k = 0; for (int i = 1; i <= M; i += 2) if (i * (i - 1) / 2 + 1 <= N) k = max(k,...
12
#include <bits/stdc++.h> using namespace std; int sg(long long x) { if (x < 4) return 0; if (x < 16) return 1; if (x < 82) return 2; if (x < 6724) return 0; if (x < 50626) return 3; if (x < 2562991876LL) return 1; return 2; } int main() { int n; scanf("%d", &n); int ans = 0; for (int i = 0; i < n;...
14
#include <bits/stdc++.h> using namespace std; int read(int *x) { int n; cin >> n; for (int i = 0; i < n; i++) cin >> x[i]; return n; } const int maxn = 7000; int n; int s[2][maxn]; int sn[2]; enum res { LOOP, WIN, LOSE }; res tab[2][maxn] = {LOSE}; int cnt[2][maxn] = {0}; void print(res *x) { for (int i = 1; ...
12
#include <bits/stdc++.h> using namespace std; int a[3000]; int main() { int n; cin >> n; for (int i = 0; i < 2 * n; ++i) cin >> a[i]; sort(a, a + 2 * n); if (a[n] > a[n - 1]) cout << "YES" << endl; else cout << "NO" << endl; }
3
#include <bits/stdc++.h> using namespace std; bool s(string s1, string s2) { if (s1.length() < s2.length()) return true; return false; } string a[105]; int main() { int n; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; } sort(a, a + n, s); for (int i = 1; i < n; i++) { if (a[i].find(a[i - ...
3
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 3; const long long INF = 1e18 + 123; int sz, dp[N][4]; bool used[N]; vector<int> g[N]; struct vertex { int next[30]; } t[N]; void add_string(string s) { int v = 0; for (int i = 0; i < s.size(); i++) { int c = int(s[i] - 'a'); if (t[v].next[...
15
#include <bits/stdc++.h> using namespace std; int main() { vector<int> vec; int a, b; cin >> a >> b; vec.push_back(b); while (b > a) { if (b % 10 == 1) b /= 10; else if (b % 2 == 0) b /= 2; else break; vec.push_back(b); } if (b != a) cout << "NO"; else { cout <<...
2
#include <bits/stdc++.h> using namespace std; int main() { int n; string s; cin >> n; cin >> s; int alph[26]; if (n > 26) { cout << -1; return 0; } for (int i = 0; i < 26; ++i) { alph[i] = 0; } for (int i = 0; i < n; ++i) { alph[s[i] - 'a']++; } int diff = 0; for (int i = 0; i ...
2
#include <bits/stdc++.h> using namespace std; const int N = 1001000; long long mod, sum[N * 4], q3; vector<long long> s[N * 4]; int a[N], q1, q2, n, m; void bt(int o, int l, int r) { if (l == r) { sum[o] = a[l]; s[o].push_back(mod - a[l]); return; } int mid = (l + r) / 2; bt(o * 2, l, mid); bt(o *...
25
#include <bits/stdc++.h> using namespace std; int INF = (int)1e9; int n, a[100005]; long long k; pair<long long, int> S[100005]; int tx[100005]; bool check(long long mid) { long long rem = k; int j = 0; memset(tx, 0, sizeof(tx)); for (int i = 0; i <= n; i++) { while (j <= n && S[i].first >= S[j].first + mid...
14
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; vector<int> adj[N]; int p[N], d[N], sz[N], root[N]; int n, m, k, s, t; int find(int v) { if (p[v] == v) return v; return p[v] = find(p[v]); } bool same(int v, int u) { return find(v) == find(u); } void unite(int u, int v) { u = find(u); v = fi...
12
#include <bits/stdc++.h> using namespace std; template <typename T> T gcd(T a, T b) { return (b != 0 ? gcd(b, a % b) : a); } template <typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); } template <typename T> T BigMod(T b, T p, T m) { if (p == 0) return 1; if (p % 2 == 0) { T s = BigMod(b, p / 2, m)...
0
#include <bits/stdc++.h> using namespace std; int n, s[110], a[110][110], id[110], suml[110], sumr[110]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); ; cin >> n; for (int i = 1; i <= n; i++) { cin >> s[i]; for (int j = 1; j <= s[i]; j++) { cin >> a[i][j]; if (j <= (s[i] + 1) / 2)...
12
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0), cout.tie(0); int n, m, h; cin >> n >> m >> h; h--; n--; vector<int> a(m); int other = 0; int me = 0; for (int i = 0; i < m; i++) { cin >> a[i]; if (i == h) { a[i]--; me += a[i]; } ...
8
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1.0); const double eps = 1e-10; const long long mod = 1e9 + 7; const int INF = 0x3f3f3f3f; const int maxn = 2e5 + 5; long long read() { long long x = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; c...
9
#include <bits/stdc++.h> using namespace std; int max(int a, int b) { if (a >= b) { return a; } else return b; } int main(int argc, char const *argv[]) { int n; cin >> n; int a[n]; for (int i = 0; i < n; ++i) { cin >> a[i]; } int maxx = INT_MAX; for (int i = 1; i < n - 1; i = i + 1) { ...
3
#include <bits/stdc++.h> using namespace std; inline int read() { int x = 0; bool t = false; char ch = getchar(); while ((ch < '0' || ch > '9') && ch != '-') ch = getchar(); if (ch == '-') t = true, ch = getchar(); while (ch <= '9' && ch >= '0') x = x * 10 + ch - 48, ch = getchar(); return t ? -x : x; } i...
8
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; string s[n]; for (int i = 0; i < n; i++) { cin >> s[i]; } string pass; cin >> pass; vector<int> flag(101, 0); for (int i = 0; i < n; i++) { if (pass != s[i] && s[i].size() <= pass.size()) { flag[s[i].size...
3
#include <bits/stdc++.h> inline long long read() { long long x = 0; char c = getchar(), f = 1; for (; c < '0' || '9' < c; c = getchar()) if (c == '-') f = -1; for (; '0' <= c && c <= '9'; c = getchar()) x = x * 10 + c - '0'; return x * f; } inline void write(long long x) { static char buf[20]; int len...
22
#include <bits/stdc++.h> int inp() { char c = getchar(); while (c < '0' || c > '9') c = getchar(); int sum = 0; while (c >= '0' && c <= '9') { sum = sum * 10 + c - '0'; c = getchar(); } return sum; } struct SEG_Tree { struct SEG { int l; int r; int min; } t[1000]; void push_up(int ...
17
#include <bits/stdc++.h> using namespace std; long long int asb[112][112], usw[112][112]; vector<int> adj[112]; bool vis[112]; int n, k; void dfs(int u) { vis[u] = true; asb[u][0] = 1; usw[u][0] = 1; for (int i = 0; i < adj[u].size(); ++i) { int v = adj[u][i]; if (vis[v] == false) { dfs(v); ...
17
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:200000000") using namespace std; const int INF = (int)1e9; const long long INF64 = (long long)1e18; const long double eps = 1e-9; const long double pi = 3.14159265358979323846; vector<vector<int> > g; vector<bool> used; int t; vector<int> in, fup, br; vector<pair...
8
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; cout << 0 << " " << 0 << " " << n; return 0; }
1
#include <bits/stdc++.h> const int Maxn = 100000; char s[Maxn + 5]; int sum[Maxn + 5]; int n, x; int main() { int t; scanf("%d", &t); int ans; while (t--) { scanf("%d%d", &n, &x); scanf("%s", s + 1); for (int i = 1; i <= n; i++) { if (s[i] == '0') { sum[i] = sum[i - 1] + 1; } els...
9
#include <bits/stdc++.h> using namespace std; int RestNum[25]; int ThingsNum[25]; int Cost[25]; int Val[25]; int Dp[1001] = {0}; int V; int m; int max(int, int); int main(void) { int C0, D0; cin >> V >> m; cin >> C0 >> D0; for (int i = 0; i <= V; i++) { Dp[i] = i / C0 * D0; } for (int i = 1; i <= m; i++...
9
#include <bits/stdc++.h> using namespace std; int n, i, a[100003], j, k; int main() { scanf("%d", &n); for (i = 0; i < n; i++) scanf("%d", &a[i]); for (i = 1; i <= n / 3; i++) if (n % i == 0) { for (j = 0; j < i; j++) { int z = 1; for (k = j; k < n; k += i) z &= a[k]; if (z) retu...
8
#include <bits/stdc++.h> using namespace std; inline void OPEN(const string &s) { freopen((s + ".in").c_str(), "r", stdin); freopen((s + ".out").c_str(), "w", stdout); } int n, m, q, size[7777], p[200200]; pair<int, pair<int, pair<int, int> > > s[7777]; int calcr(int level, int v) { for (int i = (level + 1); i <=...
16
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long _; cin >> _; while (_--) { long long n, k; cin >> n >> k; long long a[n]; for (long long i = (long long)(0); i < (long long)(n); ++i) cin >> a[i]; long lo...
12
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:836777216") using namespace std; int n, m; bool a[777][777]; int b[777][777]; int c[777][777]; int main() { cin >> n >> m; for (int i(0); i < (m); i++) { int x = 0, y = 0; scanf("%d %d", &x, &y); x--, y--; a[x][y] = a[y][x] = 1; } for (int...
16
#include <bits/stdc++.h> using namespace std; inline 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 << 3) + (x << 1) + (ch ^ 48); ch = getchar(); } return x * f; } int n; vo...
0
#include <bits/stdc++.h> using namespace std; int n; struct node { int pnt, id, flag; node() {} node(int _pnt, int _id, int _flag) { pnt = _pnt; id = _id; flag = _flag; } } a[222]; bool cmp(node P1, node P2) { if (P1.pnt != P2.pnt) return P1.pnt > P2.pnt; return P1.id < P2.id; } int oldrank[222]...
14
#include <bits/stdc++.h> using namespace std; int n, m; string str = "acef"; string arr[55]; int cnt; int main() { cin >> n >> m; for (int i = 0; i < n; ++i) cin >> arr[i]; for (int i = 0; i < n; ++i) { for (int j = 0; j < m; ++j) { if (str.find(arr[i][j]) != string::npos) { string s; s ...
1
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); long long n, m, b, i, j, k, ans, INF = 1LL << 60, id, mm, v; cin >> n >> m >> b; mm = 1LL << m; vector<long long> x(n), ct(n), mask(n, 0); vector<pair<long long, long long>> kk(n); for (i = 0; i < n; i++)...
11
#include <bits/stdc++.h> using namespace std; using ll = long long; template <class T> using V = vector<T>; template <class T, class U> using P = pair<T, U>; using vll = V<ll>; using vvll = V<vll>; template <class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } templat...
3
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; int n, siz[N]; double dp[N]; struct edge { int to, nxt; } e[N]; int head[N], cnt; void add(int u, int v) { e[++cnt] = (edge){v, head[u]}; head[u] = cnt; } void dfs1(int u) { siz[u] = 1; for (int i = head[u], v; i; i = e[i].nxt) { v = e[...
9
#include <bits/stdc++.h> using namespace std; signed main() { ios_base::sync_with_stdio(false); long long n, m, k; cin >> n >> m >> k; vector<long long> a(n); vector<long long> b(m); for (long long &x : a) cin >> x; for (long long &x : b) cin >> x; sort(a.begin(), a.end(), greater<long long>()); sort(...
8
#include <iostream> using namespace std; int main () { int t; cin >> t; long long d, k, h, l, r, m; while (t --) { cin >> d >> k; h = (d * d) / (k * k << 1ll); l = 0ll; r = d; while (r != l + 1) { m = (l + r) >> 1; if (m * m > h) ...
9
#include <bits/stdc++.h> using namespace std; int n, m, K, a[2510][2510], sum[2510][2510], d[2510], u[2510]; long long ans = 0; int S(int x1, int y1, int x2, int y2, int ty) { if (ty) swap(x1, y1), swap(x2, y2); return sum[x2][y2] - sum[x1 - 1][y2] - sum[x2][y1 - 1] + sum[x1 - 1][y1 - 1]; } void sol(int x1, int y1,...
22
#include <bits/stdc++.h> using namespace std; int r, g, b, w, t; int check(int a, int b, int c, int d) { int ans; ans = a % 2; ans += b % 2; ans += c % 2; ans += d % 2; return ans; } int main() { cin >> t; while (t--) { cin >> r >> g >> b >> w; if (check(r, g, b, w) <= 1) { cout << "Yes" <...
2
#include <iostream> #include<bits/stdc++.h> using namespace std; int main() { int t; cin>>t; while(t--){ int n; cin>>n; int a[n]; for(int i=0;i<n;i++) cin>>a[i]; int u1=0,d1=0,u2=0,d2=0; for(int i=0; i<n; i++){ if(a[i]==1) u1++; else if(a[i]=...
0
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; int main() { vector<int> ans; int n, d, a, b; cin >> n >> d >> a >> b; pair<int, int> v[N]; for (int i = 1; i <= n; i++) { int x, y; cin >> x >> y; v[i].first = x * a + y * b; v[i].second = i; } sort(v + 1, v + n + 1); ...
6