solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> using namespace std; struct debugger { template <typename T> debugger& operator,(const T& v) { cerr << v << " "; return *this; } } dbg; vector<pair<int, int> > fi, ops; vector<vector<int> > loc; void move(int i, int j) { if (i == j) return; fi[j] = fi[i]; fi[i] = pair<int, i...
10
#include <bits/stdc++.h> const int mod = 998244353; int n, u, v; long long f[200005][4]; std::vector<std::pair<int, int> > E[200005]; void dfs(int u, int fa) { f[u][0] = f[u][3] = 1; for (int i = 0, s = 1; i < E[u].size(); ++i) { int v = E[u][i].second; if (v == fa) { s++; continue; } df...
21
#include <bits/stdc++.h> using namespace std; class node { public: char c; int num; ; bool f; }; bool cmp(node a, node b) { return a.num < b.num; } bool cmp2(node a, node b) { return a.c < b.c; } int main() { string ans; string s; int n, aa = 0; node t[27] = {}; for (int i = 0; i < 27; ++i) { t[i...
4
#include <bits/stdc++.h> using namespace std; using ll = long long; const int maxn = 1 << 20; const ll inf = 1ll << 40; ll n, m, p; ll ca[maxn], cb[maxn]; void init() { fill(ca, ca + maxn, inf); fill(cb, cb + maxn, inf); } vector<pair<ll, ll>> mon[maxn]; struct sgt { ll v[maxn << 1], tag[maxn << 1]; void init()...
12
#include <bits/stdc++.h> using namespace std; int N, D, mx, mn, ans; int main() { scanf("%d %d", &N, &D); for (int i = 0; i < N; i++) { int l; scanf("%d", &l); if (l == 0) { if (mn < 0) mn = 0; if (mx < 0) { mx = D; ans++; } } mx += l; mn += l; if (mx > ...
11
#include <bits/stdc++.h> using namespace std; const int MaxN = 1010; struct Point { long long x, y; friend Point operator-(const Point &a, const Point &b) { return (Point){a.x - b.x, a.y - b.y}; } friend Point operator+(const Point &a, const Point &b) { return (Point){a.x + b.x, a.y + b.y}; } friend...
18
#include <bits/stdc++.h> using namespace std; int a[4]; map<int, int> ma[4]; vector<int> ve[4]; vector<int> siz[4]; void fa(int p, int a, int s) { if (ma[p].count(a) > 0) return; ma[p][a] = s; if (a % 2 == 0) { fa(p, a / 2, s + 1); } if (a % 3 == 0) { fa(p, 2 * (a / 3), s + 1); } } void init() { f...
11
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; int c[n + 1], avg = n / m; map<int, int> a, b; for (int i = 0; i < n; i++) { cin >> c[i]; } for (int i = 0; i < n; i++) { if (c[i] <= m) { a[c[i]]++; } else { a[0]++; } } b = a; int cntr =...
8
#include <bits/stdc++.h> using namespace std; string p; char rev(char r) { char e = 0; bool b[8]; for (int i = 0, j = 7; i < 8; ++i, --j) b[i] = (r & (1 << j)), e |= (b[i] << i); return e; } int main() { getline(cin, p); for (int i = 0; i < p.length(); ++i) { int s2 = rev(p[i]); int s1 = (i ? re...
5
#include <bits/stdc++.h> template <typename Arg1> void __f(const char* name, Arg1&& arg1) { std::cerr << name << " : " << arg1 << "\n"; } template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args) { const char* comma = strchr(names + 1, ','); std::cerr.write(names, comma -...
3
#include <bits/stdc++.h> const double pi = 3.1415926535897932384626433832795, eps = 1e-10; int N, M, i, j; double Ax, Ay, Az, Vx, Vy, Vz, Ox, Oy, Oz, Bx, By, Bz, px, py, pz, R, r, Sin, Sin1, Theta, Theta1, Theta2, l1, l2, Ans, d, D, Cos; double len(double x, double y, double z) { return sqrt(x * x + y * y + z * z);...
17
#include <bits/stdc++.h> const double PI = 3.141592653589793238460; using namespace std; long long pows(long long a, long long n, long long m) { a = a % m; long long res = 1; while (n) { if (n % 2 != 0) { res = (res * a) % m; n--; } else { a = (a * a) % m; n = n / 2; } } re...
11
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; int p[N], z[2 * N], pref[N]; void p_func(string s) { p[0] = 0; for (int i = 1; i < (int)s.size(); i++) { int j = p[i - 1]; while (j > 0 && s[i] != s[j]) { j = p[j - 1]; } if (s[i] == s[j]) { j++; } p[i] = j; ...
18
#include <bits/stdc++.h> using namespace std; const int le = 2 * 1e5; vector<int> g[le]; vector<int> rg[le]; int usedi[le]; bool cycle = false; void dfs0(int v) { usedi[v] = -1; for (int e : g[v]) { if (!usedi[e]) dfs0(e); if (usedi[e] == -1) cycle = true; } usedi[v] = 1; } bool used1[le]; bool used2[le...
18
#include <bits/stdc++.h> const int mod = 1000000007; const int inf = 1000000009; const long long INF = 1000000000000000009; const long long big = 1000000000000000; const long double eps = 0.000000000000000000001; using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(); cout.tie(); int n; int ...
0
#include <bits/stdc++.h> using namespace std; struct node { double val; int wz; int tim; bool operator<(node b) const { return val < b.val; } }; priority_queue<node> q1, q2; int p[262144], x[262144], y[262144]; int tim[262144]; void change(int wz) { tim[wz]++; node s; s.wz = wz; s.tim = tim[wz]; if (y...
23
#include <bits/stdc++.h> using namespace std; bool dp[201][201][201]; void f(long long a, long long b, long long c) { dp[a][b][c] = true; if (a + b + c == 1) { return; } if (a > 0 && b > 0 && !dp[a - 1][b - 1][c + 1]) f(a - 1, b - 1, c + 1); if (a > 0 && c > 0 && !dp[a - 1][b + 1][c - 1]) f(a - 1, b + 1, ...
5
#include <bits/stdc++.h> int main(void) { int s, x1, x2, p, d1, t1, t2, ans = 0; scanf("%d%d%d%d%d%d%d", &s, &x1, &x2, &t1, &t2, &p, &d1); int t_ig = abs(x1 - x2) * t2; int t_tr; if (d1 > 0 && p > x1 && p <= x2) t_tr = (2 * s - p + x2) * t1; if (d1 < 0 && p < x1 && p >= x2) t_tr = (2 * s - x2 + p) * t1; i...
8
#include <bits/stdc++.h> using namespace std; int main() { int n, i, j, sum = 0; cin >> n; int a[n][n]; for (i = 0; i < n; i++) { for (j = 0; j < n; j++) { cin >> a[i][j]; if (i == ((n + 1) / 2) - 1 || j == ((n + 1) / 2) - 1) { sum = sum + a[i][j]; } else if (i == j || j == n - 1 -...
0
#include <bits/stdc++.h> using namespace std; const int MOD = 1000000007; bool VertOk(int n) { return n >= 0; } bool HorOk(int n) { return (n <= 0) || (n == 1) || (n == 4) || (n == 5); } int main() { int n, m; cin >> n >> m; if (n * m % 2 == 1) { cout << 0; return 0; } vector<string> s(4 * n + 1); f...
15
#include <bits/stdc++.h> using namespace std; void scanint(long long int &x); map<long long int, long long int> cnt; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int n; scanint(n); long long int i = 0; long long int j = 0; long long int ans = 0; long long int a[n]; long long...
8
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:256000000") using namespace std; const long double PI = acosl((long double)-1.0); const long long LINF = 1e18; const int MOD = 1000000007; int test; const int MAXN = 10005; int len, n, k, v1, v2; long double t[2][MAXN], timer; void init() { scanf("%d%d%d%d%d", &n...
11
#include <iostream> #include <bits/stdc++.h> using namespace std; int main() { int t; cin>>t; while(t--) { string s; cin>>s; bool flag=0; int x=0,y=0; for(int i=0; i<s.size(); i++) { if(s[i]=='L') { x--; ...
8
#include <bits/stdc++.h> using namespace std; int n, nim[31] = {0, 1, 2, 1, 4, 3, 2, 1, 5, 6, 2, 1, 8, 7, 5, 9, 8, 7, 3, 4, 7, 4, 2, 1, 10, 9, 3, 6, 11, 12}; const int maxn = 1000 * 100; bool mark[maxn]; map<int, int> mp; int main() { ios_base::sync_with_stdio(false); int ans = 0; cin >> n; ...
15
#include <bits/stdc++.h> using namespace std; vector<int> s[1000005]; int sz[1000005], dep[1000005], ans[1000005], cnt[1000005]; priority_queue<pair<int, int>> q; void dfs1(int u, int fa) { sz[u] = 1; for (int v : s[u]) { if (v == fa) continue; dep[v] = dep[u] + 1; dfs1(v, u); sz[u] += sz[v]; } } ...
15
#include <bits/stdc++.h> using namespace std; long long f[1000001], If[1000001], cor[1000001], T[1000001], part[1000001]; long long modu = 1000000007; long long inv(long long x) { long long t, p; for (t = modu - 2, p = 1; t; t /= 2) { if (t % 2) p = p * x % modu; x = x * x % modu; } return p; } int main...
16
#include <bits/stdc++.h> using namespace std; void merge(int arr[], int l, int m, int r) { int i, j, k; int n1 = m - l + 1; int n2 = r - m; int L[n1], R[n2]; for (i = 0; i < n1; i++) L[i] = arr[l + i]; for (j = 0; j < n2; j++) R[j] = arr[m + 1 + j]; i = 0; j = 0; k = l; while (i < n1 && j < n2) { ...
1
#include <bits/stdc++.h> using std::cin; using std::cout; using std::deque; using std::endl; using std::map; using std::max; using std::min; using std::pair; using std::queue; using std::sort; using std::string; using std::vector; int main() { long long dev[18] = { 9, }; for (int i = 1; i < 18; i++) { d...
6
#include <bits/stdc++.h> using namespace std; int it[4 * 3002], l[4 * 3002], h[4 * 3002]; int a[3002], r[3002]; void Build(int x, int low, int high) { l[x] = low; h[x] = high; it[x] = 0; if (low == high) return; int mid = (low + high) / 2; Build(2 * x, low, mid); Build(2 * x + 1, mid + 1, high); } void ad...
11
#include <bits/stdc++.h> using namespace std; int main() { int n, k, d; cin >> n >> k >> d; auto has_police = vector<bool>(n); for (auto i = 0; i < k; i++) { int v; cin >> v; v--; has_police[v] = true; } struct Edge { int id, source, target; }; auto adjacency_list = vector<vector<Edg...
13
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7, N = 5e5 + 5; inline long long read() { long long x = 0; char c = getchar(); while (!isdigit(c)) c = getchar(); while (isdigit(c)) x = (x << 3) + (x << 1) + (c ^ 48), c = getchar(); return x; } long long b[N], ans; map<long long, long...
14
#include <bits/stdc++.h> using namespace std; int n, m; int arr[100000 + 10]; vector<int> w[100000 + 10]; bool check() { for (int i = 1; i <= n; i++) if (arr[i] == 1) return true; return false; } int main() { int a, b; cin >> n >> m; while (m--) { cin >> a >> b; arr[a]++, arr[b]++; w[a].push_b...
4
#include <bits/stdc++.h> using namespace std; const long long N = 2e5 + 7; const long long MOD = 1e9 + 7; long long arr[N]; long long n, m, k, x, y, i, j; void solve() { string s; cin >> s; long long cnt = 0, tot = 0, n; n = (long long)s.size(); tot = n; long long ans = 0; stack<char> st; for (long long...
6
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; struct node { int x, y; }; const int dx[5] = {0, 0, 1, -1}; const int dy[5] = {1, -1, 0, 0}; char ch[1010][1010]; int dis[1010][1010][5]; bool vis[1010][1010]; int n, m; long long minn = 0x3f3f3f3f3f3f3f3f; void bfs(int s) { deque<node> q; ...
14
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { long long int n, m, k, i, j, L, v, l, r, ans = 0; cin >> L >> v >> l >> r; ans += L / v; j = r / v; k = l / v; if (l % v != 0 && r % v != 0) { ans -= (j - k); } else if (l % v == 0 && r % v ...
3
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7, N = 1e5 + 5; long long solve() { long long x, y; cin >> y >> x; long long ans, c[7]; for (long long i = (long long)1; i < 7; i++) cin >> c[i]; ans = 2e18; if (x >= 0 && y >= 0 && y >= x) { ans = min(ans, x * c[1] + (y - x) * c[...
11
#include <bits/stdc++.h> using namespace std; long long mod; long long quickpow(long long a, long long x) { long long res = 1; while (x) { if (x & 1) res = res * a % mod; a = a * a % mod; x >>= 1; } return res; } const int maxn = 2; int num = 2; struct mat { long long data[maxn][maxn]; void one(...
13
#include <bits/stdc++.h> using namespace std; int n, st[1000005], tp, a[1000005], tans[1000005], ct; int main() { scanf("%d", &n); for (int i = 1; i <= 2 * n; i++) { int x; char ch; scanf(" %c", &ch); if (ch == '+') { st[++tp] = ++ct; a[tp] = 0; } else { scanf("%d", &x); ...
9
#include <bits/stdc++.h> using namespace std; int n, k; int main() { scanf("%d", &n); k = 0; bool flag = true; for (; n; n--) { int dist; string dir; scanf("%d", &dist); cin >> dir; if (dir == "North") { k -= dist; if (k < 0) { flag = false; break; } } e...
5
#include <bits/stdc++.h> using namespace std; int main() { using i64 = int64_t; cout.tie(nullptr)->sync_with_stdio(false); cin.exceptions(cin.failbit); int N; cin >> N; vector<int> A(N); for (int& a : A) { cin >> a; } int ma = *max_element(A.begin(), A.end()); vector<int> bloom(ma + 1); for (i...
14
#include <bits/stdc++.h> using namespace std; const int max_n = 7e6; struct st { int pos_arr = 0; int real_pos = 0; int max_pos; int min_pos; }; st info[max_n]; int a[max_n]; int tree[4 * max_n]; void build(int v, int l, int r, int from) { if (l == r) { if (from <= l) { info[l - from + 1].pos_arr = ...
12
#include <bits/stdc++.h> using namespace std; int cnt[55], n, w[100005], ded[100005], mx, x; int solve(int B, vector<int> v) { if (v.empty()) return 0; vector<int> a, b; for (auto i : v) { if (i & (1 << B)) b.push_back(i); else a.push_back(i); } int resa = 0, resb = 0; if (!a.empty()) re...
11
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n, k, i; cin >> n >> k; int b[n], c[n], e = 0, f = 0; long long r = 0, mod = (1e9) + 7, a[n], d[n + 1]; stack<int> s; for (i = 0; i < n; i++) cin >> a[i]; for (i = 0; i < n...
17
#include <bits/stdc++.h> const double eps = 1e-10; using namespace std; using ll = long long; using ul = unsigned long long; using PII = pair<int, int>; const int NN = 333; vector<int> gr[NN]; ll n, k; ll m, s, x, a, b, c, d, e, q; int answww; int in[NN], comp[NN], sz[NN], shv[NN][NN]; const string al = "abcdefghijklmn...
6
#include <bits/stdc++.h> using namespace std; int const MAXN = 1005; int n, m; int dir[] = {1, 2, 2, 1, 1, -2, 2, -1, -1, 2, -2, 1, -1, -2, -2, -1}; int u0, v0, u1, v1; int ox, oy; int dp[2][MAXN][MAXN]; struct Point { int x, y, d; Point(int x, int y, int d) : x(x), y(y), d(d){}; }; int attack(int x0, int y0, int x...
21
#include <bits/stdc++.h> using namespace std; vector<int> vec[100010]; struct node { int y, next; } a[400010]; int len = 1, last[200010]; void ins(int x, int y) { a[++len].y = y; a[len].next = last[x]; last[x] = len; } int w[200010], n, m, Q, A[200010]; int dfn[100010], low[100010], sta[100010], top = 0, id = 0...
24
#include <bits/stdc++.h> using namespace std; const int N = 1000100; const int mod = 1e9 + 7; long long gcd(long long a, long long b) { return !b ? a : gcd(b, a % b); } long long a[N], f[N], ff[N]; int p[N]; int main() { int n; scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%lld", &a[i]); for (int i = 2; ...
19
#include <bits/stdc++.h> using namespace std; double f[105], p[105], ans, Ans, las; int n; int main() { cin >> n; for (int i = 1; i <= n; i++) { cin >> p[i]; f[i] = p[i] = p[i] / 100; } ans = 1; for (int i = 1; i <= n; i++) { ans *= p[i]; } Ans += ans * (double)n; for (int i = n + 1; i <= 30...
19
#include <bits/stdc++.h> #pragma comment(linker, "/stack:200000000") #pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") using namespace std; long long int mod = 1e9 + 7; long long int gcd(long long int a, long long int b) { if (b == 0) return a; return gcd(b,...
8
#include <bits/stdc++.h> using namespace std; const int MAXN = 1000000 + 10; char str[MAXN], str1[MAXN]; int n, f[2][MAXN][2], a[MAXN], N; int main() { scanf("%s", str); n = strlen(str); int p = 0; for (; str[0] == str[(n - 1 - p)]; ++p) ; for (int i = 0; i < n; ++i) str1[i] = str[(i - p + n) % n]; memc...
14
#include <bits/stdc++.h> using namespace std; int main() { int i, n, k, good = 0; char c; string str; cin >> n >> k; while (n--) { cin >> str; set<char> s; c = '0' + k; for (i = 0; i < str.length(); i++) { if (str[i] <= c) s.insert(str[i]); } if (s.size() >= k + 1) good++; } ...
3
#include <bits/stdc++.h> using namespace std; int32_t main() { long long int n; cin >> n; long long int a[6] = {0}; for (long long int i = 0; i < n; i++) { long long int x; cin >> x; a[x]++; } double u = 4.5 * double(n); double t = double(2 * a[2] + 3 * a[3] + 4 * a[4] + 5 * a[5]); long long...
1
#include <bits/stdc++.h> using namespace std; int main() { int n, o = 0, x, e = 0; cin >> n; for (int i = 0; i < n; i++) { cin >> x; if (x % 2 == 0) e++; else o++; } if (o % 2 == 0) { cout << e; } else cout << o; }
1
#include <bits/stdc++.h> using namespace std; int b, d, n, m, i, j, v[2100000], f[100001], maxi, a, ul, nrq = 1, nrr = 1, newq, newr, ls, ld; char s[100005], z; vector<int> c; double r, t, q, ff, pri; bool cmm(int a, int b) { if (a > b) return 1; return 0; }...
3
#include <bits/stdc++.h> using namespace std; map<int, int> par, dis; map<int, int>::iterator i; int findRep(int n) { i = par.find(n); if (i == par.end()) return par[n] = n; int p = (*i).second; if (p == n) return n; int r = findRep(p); dis[n] ^= dis[p]; return par[n] = r; } void join(int u, int v, int x)...
16
#include <bits/stdc++.h> using namespace std; long long a[100001], c[100001]; int main() { int n, m; scanf("%d %d", &n, &m); for (int i = 1; i <= n; ++i) scanf("%lld", &a[i]); for (int i = 1; i <= n; ++i) scanf("%lld", &c[i]); priority_queue<pair<long long, long long>, vector<pair<long long, ...
7
#include <bits/stdc++.h> using namespace std; const int N = 100010, mod = 1e9 + 7; int n, res; vector<int> factor[N]; bool vis[N]; int prime[N], cnt; int miu[N]; int inv[N]; int dp[N]; void prepare() { vis[0] = vis[1] = 1; miu[1] = 1; for (int i = 1; i <= n; i++) { if (!vis[i]) prime[cnt++] = i, miu[i] = -1; ...
15
#include <bits/stdc++.h> using namespace std; const int Maxn = 10005; char c[Maxn]; vector<int> G[Maxn]; bool dop; vector<pair<int, int> > solve(int lo, int hi) { if (lo == hi) { vector<pair<int, int> > ret; ret.resize(101, make_pair(-1e9, 1e9)); ret[0] = make_pair(c[lo] - '0', c[lo] - '0'); return re...
15
#include <bits/stdc++.h> using namespace std; long long n, k, m, a[100100], b[100100]; double rez = 0; int main() { cin >> n >> k >> m; long long pom = m; for (long long i = 1; i <= n; i++) { cin >> a[i]; } sort(a + 1, a + n + 1); long long sum = 0; for (long long i = n; i >= 1; i--) { b[i] = a[i]...
9
#include <bits/stdc++.h> using namespace std; const int mod = 1000000 + 3; int f[1002]; int main() { int n; for (int i = 1; i <= 1000; i++) { f[i] = 1; for (int j = 2; j <= i; j++) { f[i] *= 3; f[i] %= mod; } } f[0] = 1; scanf("%d", &n); printf("%d\n", f[n]); return 0; }
5
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; int P[n]; for (int i = 0; i < n; i++) { cin >> P[i]; } if (n < 6) { cout << "0 0 0" << endl; continue; } int l = n / 2 - 1; while (l >= 0 && P[l] == P[l ...
7
#include <bits/stdc++.h> using namespace std; long long val, sum, ans = 0x3f3f3f3f; int n; map<long long, long long> m; int main() { int n; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%I64d", &val); sum += val; m[sum]++; ans = min(ans, n - m[sum]); } printf("%I64d\n", ans); return ...
13
#include <bits/stdc++.h> using namespace std; template <typename T> void read(T &x) { x = 0; int f = 1; char ch = getchar(); while (!isdigit(ch)) { if (ch == '-') f = -1; ch = getchar(); } while (isdigit(ch)) { x = x * 10 + (ch ^ 48); ch = getchar(); } return x *= f, void(); } template <...
13
#include <bits/stdc++.h> using namespace std; void read(int &sum) { sum = 0; char c = getchar(); bool f = 0; while (c < '0' || c > '9') { if (c == '-') f = 1; c = getchar(); } while (c >= '0' && c <= '9') { sum = sum * 10 + c - '0'; c = getchar(); } if (f) sum = -sum; } void read(long lo...
5
#include <bits/stdc++.h> using namespace std; long long bigmod(long long b, long long p, long long m) { if (p == 0) return 1; long long my = bigmod(b, p / 2, m); my *= my; my %= m; if (p & 1) my *= b, my %= m; return my; } long long setb(long long n, long long pos) { return n = n | (1 << pos); } long long r...
15
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:268435456") using namespace std; template <typename T> T sqr(const T &x) { return x * x; } template <typename T> T my_abs(const T &x) { return x < 0 ? -x : x; } const int INF = (int)1e9; const long long LINF = (long long)6e18; const long long INF64 = LINF; co...
16
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:300000000") const long double eps = 1e-20; const long double pi = acos(-1.0); const long long inf = 1000 * 1000 * 1000 * 1000 * 1000 * 1000; const long long base = 1000 * 1000 * 1000 + 7; using namespace std; struct date { int l, r, pos; date() {} date(int ...
11
#include<bits/stdc++.h> using namespace std; typedef unsigned long long ll; typedef unsigned long long ull; #define pr1(x) cout<<x<<"\n" #define pr2(x,y) cout<<x<<" "<<y<<"\n" #define isprime(x) (!np[x]&&(x&1)) #define MUHAMMED_HISHAM ios_base::sync_with_stdio(false);cin.tie(NULL); /* /* ll NCR[4005][4000...
4
#include <bits/stdc++.h> using namespace std; const int MaxN = 100010; const int MOD = 95542721; const int LEN = 48; int n; int a[MaxN]; struct node { node *Lc, *Rc; int L, R, m; int p; int v[LEN]; node(int x, int y) { L = x; R = y; m = (L + R) >> 1; p = 0; Lc = Rc = 0; memset(v, 0, si...
18
#include <bits/stdc++.h> using namespace std; signed main() { ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr); long long tc; cin >> tc; while (tc--) { long long n, k, l1, r1, l2, r2, inter = 0, dist = 0; cin >> n >> k; cin >> l1 >> r1 >> l2 >> r2; if (l2 < l1 || (l2 == l1 && r2 ...
13
#include <bits/stdc++.h> using namespace std; void solve() { long long n; cin >> n; vector<long long> v; for (long long i = 0; i < n; i++) { long long x; cin >> x; v.push_back(x); }; sort((v).begin(), (v).end()); long long ans = 1; long long ma = -1e18; long long q = 0; for (long long i ...
4
#include <bits/stdc++.h> using namespace std; const int N = 1e2 + 10; char a[N][N]; bool vis[N][N]; int n, m; bool isValid(int x, int y) { return (x >= 1 && x <= n && y >= 1 && y <= m && vis[x][y] == 0 && a[x][y] == '.'); } vector<int> dx = {-1, 1, 0, 0}; vector<int> dy = {0, 0, 1, -1}; void dfs(int x, int ...
4
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; int t, n, a, b, u, v, par[N], branch[N], depth[N]; vector<int> adj[N], Q[N]; void findpivots(int x, int p) { Q[x].assign(3, 0); branch[x] = 0; for (int y : adj[x]) { if (y != p) { depth[y] = 1 + depth[x]; findpivots(y, x); ...
22
#include <bits/stdc++.h> using namespace std; map<double, int> cnt; double xx[20005]; double yy[20005]; int n; long long _minus = 0; long long ans; double loz = 0x3f3f3f; double k(int id1, int id2) { if (xx[id1] == xx[id2]) return loz; return (yy[id1] - yy[id2]) / (xx[id1] - xx[id2]); } void calc(int x) { cnt.cle...
11
#include <bits/stdc++.h> using namespace std; long long x[100005], i, j, n, k, m, a, ans = 1, ans1, p = 1; int main() { cin >> n >> k; for (i = 1; i <= n; i++) cin >> x[i]; for (i = 1; i <= n; i++) { for (j = p; j <= n; j++) if (x[i] + k < x[j]) break; p = j; p--; ans = p - i; ans1 = ans...
5
#include <bits/stdc++.h> using namespace std; int n, m, h, t; vector<int> a[100010]; int v[100010]; bool check(int x, int y, int dx, int dy, int get) { int nx = dx - get - t; int ny = dy - get - h; if (-nx - ny <= get && dx >= t && dy >= h) { puts("YES"); printf("%d %d\n", y, x); int p = 0; for (_...
12
#include <bits/stdc++.h> using namespace std; long long mod = 998244353; long long int fast_exp(long long int base, long long int ex) { long long int res = 1; while (ex > 0) { if (ex % 2 == 1) res = (res * base) % mod; base = (base * base) % mod; ex /= 2; } return res % mod; } long long p[300050]; l...
16
#include <bits/stdc++.h> int n, m, k; int uf[2001]; int getpa(int a) { if (uf[a] == a) return a; uf[a] = getpa(uf[a]); return uf[a]; } void comb(int a, int b) { uf[getpa(a)] = getpa(b); } int main() { scanf("%d%d%d", &n, &m, &k); for (int i = 0; i < n; i++) uf[i] = i; for (int i = 0; i < n - k + 1; i++) { ...
8
#include <bits/stdc++.h> using namespace std; const int N = 111111; vector<int> graph[N]; map<pair<int, int>, int> mp; bool vis[N]; int n, k; pair<int, int> dfs(int u) { if (vis[u]) { return make_pair(0, 0); } vis[u] = true; pair<int, int> ans(1, 0); for (auto v : graph[u]) { pair<int, int> p(min(u, v...
9
#include <bits/stdc++.h> using namespace std; int n, cnt, a[5001], b[5001], f[5001]; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d", &a[i]); for (int i = 1; i <= n; i++) { memset(b, 0, sizeof(b)); cnt = 1; for (int j = i; j <= n; j++) { b[a[j]]++; if (b[a[j]] > b[cnt...
7
#include <bits/stdc++.h> using namespace std; const long long int mod = 998244353; bool comp(pair<long long int, pair<long long int, long long int> > a, pair<long long int, pair<long long int, long long int> > b) { return a.first * a.second.first > b.first * b.second.first; } int main() { ios_base::sync_w...
8
#include <bits/stdc++.h> using namespace std; inline void print(int n) { if (n == 0) { putchar('0'); putchar('\n'); } else if (n == -1) { putchar('-'); putchar('1'); putchar('\n'); } else { char buf[11]; buf[10] = '\n'; int i = 9; while (n) { buf[i--] = n % 10 + '0'; ...
10
#include <bits/stdc++.h> using namespace std; const int inf = 1e9; const double eps = 1e-9; const double INF = inf; const double EPS = eps; long long tmpl, res, D[1100000]; int Cnt[2], n; int main() { int i, tmp; scanf("%d", &n); for (i = 0; i < n; i++) scanf("%d", &tmp), Cnt[tmp - 1]++; for (D[0] = 1, D[1] = 1...
16
#include <bits/stdc++.h> using namespace std; long long m, n, ans = 0, fans = 0; int DP[505][505], arr[505][505]; long long getAnsDp(int i, int j) { if (DP[i][j] != -1) { return DP[i][j]; } int temp, temp2; if (i == m - 1 and j == n - 1) { temp = (arr[i][j] == 0 ? 8000 : arr[i][j]); if (temp <= 0) f...
3
#include <bits/stdc++.h> using namespace std; const int N = 5005; vector<int> g[5]; int n; char s1[N], s2[N]; int main() { scanf("%d", &n); scanf("%s%s", s1 + 1, s2 + 1); int all = 0, fir = 0, sec = 0, no = 0; for (int i = 1; i <= n; i++) { if (s1[i] == '1' && s2[i] == '1') { g[0].push_back(i); ...
10
#include <bits/stdc++.h> using namespace std; long long power(long long a, long long b) { long long res = 1; a = a % 1000000007; while (b > 0) { if (b & 1) { res = (res * a) % 1000000007; b--; } a = (a * a) % 1000000007; b >>= 1; } return res; } long long fermat_inv(long long y) { ...
18
#include <bits/stdc++.h> using namespace std; long long f; int main() { long long m, n, com; cin >> n >> m; long long i, j; long long a[n], b[m]; for (i = 0; i < n; i++) cin >> a[i]; for (i = 0; i < m; i++) cin >> b[i]; long long comp = a[0] * b[0]; long long x = 0; for (i = 0; i < n; i++) { for (...
6
#include <bits/stdc++.h> using namespace std; int func(string s, int i, int g1, int g2) { if (i == 10) return 10; if (i % 2 == 0) { if (g1 > g2 + (10 - i) / 2 || g2 > g1 + (10 - i) / 2) return i; } if (i % 2 == 1) if (g1 > g2 + 1 + (10 - i) / 2 || g2 > g1 + (10 - i) / 2) return i; if (i % 2 == 0) { ...
4
#include <bits/stdc++.h> using namespace std; const long long MOD = 1000000007; long long fast_exp(long long base, long long exp, long long mod) { long long res = 1; while (exp > 0) { if (exp % 2 == 1) res = (res * base) % mod; base = (base * base) % mod; exp /= 2; } return res; } const int nn = 300...
10
#include <bits/stdc++.h> using namespace std; int main() { int x, y, t, h; cin >> x; y = 0; for (int i = 1; i <= x - 2; i++) for (int j = i + 1; j <= x - 1; j++) { int f = i ^ j; if ((i ^ j ^ f) == 0 && i + j > f && i + f > j && f + j > i && i < j && j < f && f <= x) y++; }...
5
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1.0); const double eps = 1e-11; bool cmp() { return true; } int do_search(int x, int y) { int l = 0, h = 0; return l; } int main() { long long n, m; while (cin >> n >> m) { long long sum = 1, k = 1, p = 3; while (n) { k = 1; ...
6
#include <bits/stdc++.h> using namespace std; const int MaxN = 100005; const int oo = 1000000000; const long long Base = 1000000007; typedef long long Tarr[MaxN]; string s, x; int a, t, d, Res, Sign, m; Tarr D, T, C; int id[MaxN]; bool Comp(int i, int j) { return (D[i] * C[i] < D[j] * C[j]) || (D[i] * C[i] =...
12
#include <bits/stdc++.h> using namespace std; int main() { cin.tie(0); cin.sync_with_stdio(0); cout.tie(0); int n, ans = 1; bool u = false, d = false, r = false, l = false; string s; cin >> n >> s; for (int i = 0; i < n; i++) if (s[i] == 'R') { if (l == true) { ans++; l = false...
6
#include <bits/stdc++.h> using namespace std; const long long fix = (long long)1e9 + 7; long long po2(long long a) { long double temp = a; if (log2(temp) == (long long)log2(temp)) return log2(temp); return -1; } void tc(long long i) { cout << "Case #" << i + 1 << ": "; } void yes() { cout << "YES" << '\n'; } void...
5
#include <bits/stdc++.h> using namespace std; struct ro { int l, w, h; }; struct t { int l, w, p; }; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, m; cin >> n; ro rooms[n + 2]; for (int i = 0; i < n; i++) { cin >> rooms[i].l >> rooms[i].w >> rooms[i].h; } cin >> m; t types[m + ...
8
#include <bits/stdc++.h> using namespace std; static const double EPS = 1e-8; int main() { istream &fin = cin; ostream &fout = cout; FILE *fpin = stdin; FILE *fpout = stdout; string s; getline(fin, s); int n = s.size(); vector<int> vi; vi.push_back(0); for (int i = 0; i < n; i++) { int v = s[i];...
5
#include <bits/stdc++.h> using namespace std; const long long maxn = 1000000; void solve() { long long n; cin >> n; long long let = 0; vector<long long> vec(n); long long x, y; for (long long i = 1; i < n; ++i) { cout << "? " << let + 1 << " " << i + 1 << endl; cin >> x; cout << "? " << i + 1 <<...
8
#include <bits/stdc++.h> using namespace std; const int N = 1e7 + 5; int n, k, Max, a[N], F[N]; void Input() { cin >> n >> k; for (int i = 1; i <= n; i++) cin >> a[i]; Max = *max_element(a + 1, a + n + 1); } bool ok(int c_min) { memset(F, 0, sizeof(F)); for (int i = c_min; i <= Max; i++) { if (i / 2 >= c_...
13
#include <bits/stdc++.h> using namespace std; int dx[] = {1, -1, 0, 0}; int dy[] = {0, 0, -1, 1}; int main() { ios::sync_with_stdio(0); string s; cin >> s; int x, y; x = y = 0; for (int i = 0; i < s.size(); ++i) if (s[i] == 'x') x++; else y++; int r = min(x, y); for (int i = 0; i < x...
4
#include <bits/stdc++.h> using namespace std; const int MAXN = 100000; int n, m, u, v, K, N; int id[MAXN]; bool visited[MAXN]; int f[MAXN][18]; int depth[MAXN]; vector<int> e[MAXN]; vector<int> de[MAXN]; struct Conn { int n; int low[MAXN], dfn[MAXN]; vector<int>* e; vector<pair<int, int> > keyEdge; void dfs(i...
8