solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> using namespace std; template <class T> T abs(T x) { return x > 0 ? x : -x; } template <class T> T gcd(T a, T b) { return a ? gcd(b % a, a) : b; } template <class T> T sqr(T a) { return a * a; } template <class T> T sgn(T a) { return a > 0 ? 1 : (a < 0 ? -1 : 0); } const double pi = aco...
13
#include <bits/stdc++.h> using namespace std; const int INF = 0x3fffffff; const int SINF = 0x7fffffff; const long long LINF = 0x3fffffffffffffff; const long long SLINF = 0x7fffffffffffffff; const int MAXN = 200007; int CID[257]; const int WIN[3][3] = {1, 0, 1, 1, 1, 0, 0, 1, 1}; const int LOSE[8] = {-1, 2, 0, 0, 1, 2, ...
17
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); ; int n; cin >> n; bool check = true; bool check2 = true; vector<int> c(n); vector<int> d(n); long long minp, maxp; int prevp; for (int i = 0; i < n; i++) { if (i == 0) { ...
8
#include <bits/stdc++.h> using namespace std; map<vector<int>, unsigned int> cur, nxt; int n, m; string s[11]; int num[11]; int main() { cin >> n >> m; vector<int> beg(m); for (int(i) = 0; (i) < (m); ++(i)) cin >> s[i] >> beg[i]; cur[beg] = 1; for (int(i) = 0; (i) < (n); ++(i)) { nxt.clear(); for (map...
14
#include <bits/stdc++.h> using namespace std; template <typename T, typename U> std::pair<T, U> operator+(const std::pair<T, U>& l, const std::pair<T, U>& r) { return {l.first + r.first, l.second + r.second}; } typedef void (*callback_function)(void); const long long INF64 = 1e18; const long long INF32 = 1e9; int mai...
0
#include <bits/stdc++.h> using namespace std; string s, cmd; int main() { getline(cin, s); cmd = ""; bool o = 0; for (int i = 0; i < s.size(); ++i) { if (s[i] == '"') { if (o) { o = 0; cout << "<" << cmd << ">" << endl; cmd = ""; } else o = 1; } else if (o || ...
5
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 100; struct Node { int num; long long sum; }; struct node { long long sum; vector<Node> st; vector<Node> ed; } tree[MAXN << 2], emp; int dat[MAXN], n, m, x; node merge(node a, node b) { if (a.st.size() == 0) return b; if (b.st.size() == ...
18
#include <bits/stdc++.h> using namespace std; const long long INF = 1 << 30; priority_queue<pair<long long, long long>, vector<pair<long long, long long> >, greater<pair<long long, long long> > > pq; vector<pair<long long, pair<long long, long long> > > vpp; vector<pair<long long, long long> > vp; co...
13
#include <bits/stdc++.h> using namespace std; template <class A, class B> ostream& operator<<(ostream& o, const pair<A, B>& p) { return o << "(" << p.first << ", " << p.second << ")"; } template <class T> ostream& operator<<(ostream& o, const vector<T>& v) { o << "{"; for (typeof(v.end()) it = v.begin(); it != v....
14
#include <bits/stdc++.h> using namespace std; using gg = long long; // MAX // constexpr gg MAX = 25; constexpr gg MAX = 1e6 + 5; constexpr gg mod = 1e9 + 7, pm = 1313131; constexpr gg INF = 2e18; constexpr double thre = 1e-7; gg ti, ni, mi, ki, di, pi, xi, yi; gg v[MAX], mp[MAX], ans[MAX]; int main() { ios::sync_wi...
3
#include <bits/stdc++.h> int main() { int a; scanf("%d", &a); char* v = NULL; int n = 0; char ch; do { ch = getchar(); if (n == 0 && ch == '\n') { continue; } if (ch == '\n' || ch == EOF) { break; } ++n; v = (char*)realloc(v, sizeof(char) * n); v[n - 1] = ch; } ...
0
#include <bits/stdc++.h> #pragma optimization_level 3 #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx") using namespace std; const long double PI = 3.14159265358979323846; const int MOD = 1e+9 + 7; const int INFi = INT_MAX; const...
15
#include <bits/stdc++.h> using namespace std; const int maxn = 3e5 + 5; long long n, m, k, a[maxn]; int main() { cin >> n >> m >> k; for (long long i = 1; i <= m; i++) { scanf("%lld", &a[i]); } long long l = 1, r = k, index = 1, ans = 0; while (index <= m) { long long cnt = 0; while (a[index] >= l...
6
#include<bits/stdc++.h> #define forn(i,s,t) for(register int i=(s);i<=(t);++i) using namespace std; typedef unsigned long long ull; const int N = 3e5+3, M = N<<5; struct List {int dir, nxt; } E[N<<1]; int G[N], cnt; inline void Add(int u, int v) { E[++cnt].dir = v, E[cnt].nxt = G[u], G[u] = cnt; } int rt[N]; mt19937_6...
21
#include <bits/stdc++.h> using namespace std; const long long maxn = 2000001; long long n, b[maxn], sg[maxn], ans2, x, ans1, my, m, me, ans = 0; long long get(long long x) { if (x <= 3) return 0; if (x <= 15) return 1; if (x <= 81) return 2; if (x <= 6723) return 0; if (x <= 50625) return 3; if (x <= 256299...
14
#include <bits/stdc++.h> using namespace std; long long f(string x) { vector<long long> c; vector<char> o; for (int i = 0; i < x.size(); i++) { if (x[i] >= '0' && x[i] <= '9') c.push_back(x[i] - '0'); if (x[i] == '+') { while (o.size() != 0 && (o[o.size() - 1] == '*' || o[o.size() - 1] ...
13
#include <bits/stdc++.h> using namespace std; const int N = 100002; int n, m, f[N], g[N], h[N], r[N]; set<int> s; int main() { std::ios::sync_with_stdio(false); scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d", f + i); s.insert(f[i]); } m = s.size(); int cnt = 1; for (set<int>::iterator ...
9
#include <bits/stdc++.h> using namespace std; struct node { long long mx, sum, cnt; node() { mx = 0; sum = 0; cnt = 0; } }; node dfs(long long id, long long prev, vector<long long> *g, long long *a) { if (g[id].empty()) { node x; x.cnt = 1; x.mx = a[id]; x.sum = a[id]; return x; ...
11
#include <bits/stdc++.h> using namespace std; int main(void) { string s; cin >> s; vector<int> v(s.size() + 1, 0); v[0] = 1; for (int i = 1; i < s.size(); i++) if (s[i] == '0') v[i] = 0; else v[i] = v[i - 1] + 1; int re = 0; for (int i = s.size() - 1; i > 0;) { if (v[i] == 0) { ...
5
#include <bits/stdc++.h> int main() { int n; std::cin >> n; std::string start, combo; std::cin >> start >> combo; int count = 0; for (int i = 0; i < n; i++) { int a = (int)start[i]; int b = (int)combo[i]; int c = a - b; int diff = abs(c); if (diff > 5) { count += (10 - diff); }...
0
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const int INF = 0x3f3f3f3f; const int N = 3 * 1e5 + 5; int n, m; int a[N], c[N]; vector<int> b[N]; void work() { scanf("%d%d", &n, &m); for (int i = 0; i <= n - 1; ++i) scanf("%d", &a[i]); for (int i = 0; i <= m - 1; ++i) { int x, y; s...
10
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #pragma GCC target( \ "sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native") using namespace std; const int M = 998244353; int n, K, b[2003]; int f[105][2003], nf[105][2003], s[105][2003]; int L[2003], R[2003], fc[2...
24
#include <bits/stdc++.h> using namespace std; int arr[100005], brr[100005]; int main() { int i1, i2, n, m; cin >> n >> m; for (int i = 1; i <= n; i++) cin >> arr[i]; for (int i = 1; i <= m; i++) cin >> brr[i]; i2 = 1; int cnt = 0; for (int i = 1; i <= n; i++) { if (i2 > m) break; if (brr[i2] >= ar...
0
#include <bits/stdc++.h> using namespace std; const int N = 1008611; struct edge { int to, next; } e[N << 1]; int e_tot, head[N]; int n, q; int zx[N], maxson[N], sontot[N]; int rfa[N]; inline void edge_add(int x, int y) { ++e_tot, e[e_tot].to = y, e[e_tot].next = head[x], head[x] = e_tot; } inline void dfs(int now,...
11
#include <bits/stdc++.h> using namespace std; int main() { long long x, y, m, mini = 0; scanf("%I64d%I64d%I64d", &x, &y, &m); if (x >= m || y >= m) printf("0\n"); else if (x <= 0 && y <= 0) printf("-1\n"); else { if (x < 0 || y < 0) { mini += abs(x - y) / max(x, y); if (x == min(x, y))...
8
#include <bits/stdc++.h> using namespace std; int main() { long long n, m, i, j, l; char x[1005], y[1005], b[1005][1005], a[1005][1005]; cin >> n >> m; for (i = 0; i < n; i++) { cin >> a[i] >> b[i]; l = strlen(b[i]); b[i][l] = ';'; l++; b[i][l] = '\0'; } for (i = 0; i < m; i++) { cin...
1
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 10; const int inf = 0x3f3f3f3f; const int mod = 1e9 + 7; long long n, m, k, t, mx, mi, idx, cnt, tot, sum, res, flag, st; long long a[maxn], dp[maxn][2]; long long minn(long long a, long long b, long long c) { return min(a, min(b, c)); } int main() ...
15
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007LL; const long long inf = 1e18; inline long long max(long long a, int32_t b) { return a > b ? a : b; } inline long long max(int32_t a, long long b) { return a > b ? a : b; } inline long long min(long long a, int32_t b) { return a < b ? a : b;...
6
#include <bits/stdc++.h> using namespace std; int a[200010], pre[200010], nxt[200010]; set<int> s; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 1; i <= n; i++) { pre[i] = i - 1, nxt[i] = i + 1; if (a[i] == a[i + 1]) s.i...
11
#include <bits/stdc++.h> const double pi = acos(-1); const int MOD = 1e9 + 7; const int INF = 1e9 + 7; const int MAXN = 1e6 + 5; const double eps = 1e-9; using namespace std; long long f[MAXN]; long long bin_pow(long long a, long long b) { long long r = 1; while (b) { if (b & 1) r = (r * a) % MOD; a = (a * ...
12
#include <bits/stdc++.h> using namespace std; const double pi = 3.141592653589793; const double eps = 1e-11; const int oo = 0x3f3f3f3f; template <class T> inline void checkmin(T &a, T b) { if (b < a) a = b; } template <class T> inline void checkmax(T &a, T b) { if (b > a) a = b; } template <class T> inline T sqr(T ...
13
#include <bits/stdc++.h> using namespace std; int n; int sum; unsigned long long ans = 0x7fffffff; int mins; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) { sum = i + (n + i - 1) / i; if (sum < ans) { ans = sum, mins = i; } } int tmp = (mins + n - 1) / mins; for (int i = 1; i <=...
8
#include <bits/stdc++.h> using namespace std; const long long int M = 1e5 + 7; const long long int mod = 1e9 + 7; const long long int infi = LLONG_MAX; long long int ans, k, n, x, y, m, mymax = LLONG_MIN, mymin = LLONG_MAX, b, c, z, sum; long long int dp[M][2]; long long int color[M], ...
12
#include <bits/stdc++.h> using namespace std; long long int powmod(long long int a, int b, int n) { long long int rm = 1; while (b) { if (b % 2) { rm = (rm * a) % n; } a = (a * a) % n; b /= 2; } return rm; } int ind[400][400] = {0}, Id[500], Id2[500], t = 0, dis[1000], dp[1000], n, Ss[...
22
#include <bits/stdc++.h> using namespace std; template <typename A, typename B> ostream& operator<<(ostream& cout, pair<A, B> const& p) { return cout << "(" << p.first << ", " << p.second << ")"; } template <typename A> ostream& operator<<(ostream& cout, vector<A> const& v) { cout << "["; for (int i = 0; i < v.si...
17
#include <bits/stdc++.h> using namespace std; const int N = 220; const int INF = 0x3f3f3f3f; int dp[N][1 << 7]; int n, m, K; int cnt; int g[N][N]; int pg[N][N]; int aa[N * N]; int mp[N][N]; void floyd() { for (int k = 0; k < cnt; k++) { for (int i = 0; i < cnt; i++) if (g[i][k] < INF) { for (int j =...
17
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 5; int a[N]; vector<int> pp; long long n, A, B; void prime(int first) { int i; for (i = 2; i <= sqrt(first); ++i) if (first % i == 0) { while (first % i == 0) first /= i; pp.push_back(i); } if (first > 1) pp.push_back(first); } ...
15
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n, m; scanf("%d%d", &n, &m); int arr[n], dp[n], index[n], i; for (i = 0; i < n; i++) { scanf("%d", &arr[i]); dp[i] = 0; index[i] = -1; } int c = sqrt(n); int x = n /...
19
#include <bits/stdc++.h> using namespace std; long long sqr(long long x) { return x * x; } int mysqrt(long long x) { int l = 0, r = 1e9 + 1; while (r - l > 1) { int m = (l + r) / 2; if (m * (long long)m <= x) l = m; else r = m; } return l; } mt19937 rnd(1227); mt19937_64 rndll(12365); lo...
19
#include <bits/stdc++.h> int a[110][110]; int main() { int n, m; scanf("%d%d", &n, &m); int b[110] = {0}; int i, j; int max = 0; for (j = 0; j < m; j++) { max = 0; for (i = 0; i < n; i++) { scanf("%d", &a[j][i]); if (a[j][i] > max) max = a[j][i]; } for (i = 0; i < n; i++) { ...
3
#include <bits/stdc++.h> using namespace std; int n; string s; void solve() { cin >> s; int len = (int)s.size(); long long minyear = 1989; long long ans = 0; long long p = 1; for (int i = len - 1; i >= 4; --i) { ans -= p * ((ans / p) % 10); ans += p * (s[i] - '0'); p *= 10; while (ans < miny...
12
#include <bits/stdc++.h> using namespace std; long long n; map<long long, long long> mp; vector<pair<long long, pair<long long, long long> > > v; map<long long, long long> ol; long long* dis; int main() { scanf("%lld", &n); dis = new long long[n]; for (long long i = 0; i < n; i++) { long long a, b, h; sca...
12
#include <bits/stdc++.h> using namespace std; const long long N = 100005; long long a[N], num[N]; int main() { long long n, i, mx; cin >> n; mx = 0; for (i = 0; i < n; i++) { cin >> a[i]; num[a[i]] = num[a[i] - 1] + 1; mx = max(mx, num[a[i]]); } cout << n - mx << "\n"; return 0; }
8
#include <bits/stdc++.h> using namespace std; int n, t, a[100010], ans = 1, x; int main() { cin >> n >> t; for (int i = 1; i < n; i++) { cin >> a[i]; } x = 1; while (ans < t) { ans += a[ans]; if (ans == t) { cout << "YES"; return 0; } } cout << "NO"; return 0; }
2
#include <bits/stdc++.h> using namespace std; int mod = pow(10, 9) + 7; int fastExpo(long long a, long long n, int mod) { a %= mod; if (n == 2) return a * a % mod; if (n == 1) return a; if (n & 1) return a * fastExpo(fastExpo(a, n >> 1, mod), 2, mod) % mod; else return fastExpo(fastExpo(a, n >> 1, mod...
12
#include <bits/stdc++.h> using namespace std; int main() { string str; cin >> str; int n = str.length(); char cur = 0; int cnt = 0; int res = 0; ; for (int i = 0; i < n; ++i) { if (str[i] != cur && cnt != 0) { ++res; cnt = 1; } else ++cnt; if (cnt == 5 && i < n - 1) { ...
1
#include <bits/stdc++.h> using namespace std; vector<int> even, odd; int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a); } int main() { int n, m, x, f, s, g; cin >> n >> m; for (int i = 0; i < n + 1; ++i) { cin >> x; if (i == 0) f = x; } for (int i = 0; i < m + 1; ++i) { cin >>...
6
#include <bits/stdc++.h> using namespace std; long long int k, p; long long int expo(long long int base, long long int exponent, long long int mod) { long long int ans = 1; while (exponent != 0) { if (exponent & 1) ans = (1LL * ans * base) % mod; base = (1LL * base * base) % mod; expo...
15
#include <bits/stdc++.h> using namespace std; const int INF = 2147483647; const long long LLINF = 9223372036854775807LL; const int maxn = 100010; vector<int> a[maxn]; const int LOG = 18; int par[LOG][maxn]; int tin[maxn]; int dep[maxn]; int tout[maxn]; int timer = 0; void dfs(int x, int pr) { tin[x] = timer++; par[...
18
#include <bits/stdc++.h> using namespace std; int n; string s1, s2; int main() { cin >> n; cin >> s1 >> s2; if (s1 == "10001001" && s2 == "10101101") { cout << "Draw" << endl; return 0; } int x = 0, y = 0, z = 0; for (int i = 0; i < 2 * n; i++) { if (s1[i] == '1' && s2[i] == '1') z++; ...
7
#include <bits/stdc++.h> using namespace std; using ll = long long; const int MAX = 11234; bool is[MAX]; int n; int f(int in) { return n - (n - 1) / in - 1 - in + 1; } int main() { scanf("%d", &n); int x = 2; for (int i = 2; i < n; i++) if (f(x) < f(i)) x = i; if (0) printf("x=%d\n", x); while (1) { i...
18
#include <bits/stdc++.h> using namespace std; const int N = 200005; long long l[N], t[N]; vector<long long> kq; int main() { int n; long long r; scanf("%d%lld", &n, &r); for (int i = 0; i < n; i++) { scanf("%lld", l + i); } for (int i = 0; i < n; i++) { scanf("%lld", t + i); } long long now = 0;...
14
#include <bits/stdc++.h> using namespace std; int main() { int x; cin >> x; if (x > 5 && x % 5 != 0) { cout << (x / 5) + 1; } if (x < 5) { cout << "1"; } if (x >= 5 && x % 5 == 0) { cout << (x / 5); } return 0; }
0
#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; int A, B, C; fin >> A >> B >> C; if (A == 0 && B == 0 && C == 0) { fout << -1 << endl; return 0; } if (A == 0) { if...
12
#include <bits/stdc++.h> #pragma GCC optimize("Ofast,unroll-loops") #pragma GCC target( \ "sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native") using namespace std; void itval(istream_iterator<string> it) {} template <typename T, typename... Args> void itval(istream_iterator<string> it, T a, Args... args)...
26
#include <bits/stdc++.h> using namespace std; struct node { int a; node *l, *r; node(int _a = 0, node* _l = nullptr, node* _r = nullptr) { a = _a; l = _l; r = _r; } }; typedef node* pnode; map<int, pnode> m; void update(pnode& v, int pos, int val, int tl, int tr) { if (!v) { v = new node(); ...
12
#include <bits/stdc++.h> using namespace std; int a[200], n; int main() { cin >> n; for (int i = 0; i < n; ++i) cin >> a[i]; int ans = 1000000; for (int x = 0; x <= 200; ++x) { int d = 0, vis = 1; for (int j = 0; j < n; ++j) { if (a[j] == x) continue; if (d == 0) d = (int)abs(a[j] - ...
4
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n, l, r; cin >> n; map<pair<int, int>, int> m; vector<pair<int, int> > V(n); for (int i = 0; i < n; i++) cin >> V[i].first >> V[i].second; bool possible = true; vector<pair<int, int> > B(V); ...
7
#include <bits/stdc++.h> using namespace std; int main() { int n, k, c; cin >> n >> k; if (n == 1) { cout << 1; return 0; } long long int s[n + 1]; s[0] = 0; for (int i = 1; i <= n; i++) { cin >> c; if (i > 1) s[i] = c + s[i - 1]; else s[i] = c; } long int suma = INT_MA...
3
#include <bits/stdc++.h> using namespace std; int n, k, idx, sum; bool tag; double m, v, suff, aver; vector<pair<int, double> > V[100]; void add(int id, double s) { suff += s; v -= s; sum++; if (sum > 2) { tag = 0; } V[id].push_back(make_pair(idx, s)); if (v < 1e-10) { idx++; v = m; sum = ...
11
#include <bits/stdc++.h> using namespace std; const int maxn = 444444, mod = 998244353; inline long long read() { char ch = getchar(); long long x = 0, f = 0; while (ch < '0' || ch > '9') f |= ch == '-', ch = getchar(); while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar(); return f ? -x : x; }...
22
#include<bits/stdc++.h> using namespace std; long long k,l,r,x,y,t,w,xx,yy,a,b; long long gcd(long long x,long long y) { return (x%y==0)?y:gcd(y,x%y); } long long exgcd(long long &x,long long &y,long long a,long long b) { if(b==0) { x=1;y=0; return a; } long long t=exgcd(y,x,b,a%b); y-=a/b*x; return t; } lon...
14
#include <bits/stdc++.h> using namespace std; const long long int N = 1e5 + 5; const long long int p = 31; const long long int m = 1e9 + 9; const long long int inf = 1e14; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long int t = 1; while (t--) { string s; cin >> s; char...
12
#include <bits/stdc++.h> using namespace std; int main() { int n, a, b, t; bitset<100> one, two, r, x; cin >> n >> a >> b; for (int i = 0; i < a; ++i) { cin >> t; one[t - 1] = 1; } for (int i = 0; i < b; ++i) { cin >> t; two[t - 1] = 1; } r = one & (~two); for (int i = 0; i < n; ++i) {...
0
#include <bits/stdc++.h> using namespace std; const int N = 4e5 + 10; int tr[N][30], idx, cnt[N][30]; string t[N]; bool endt[N][30]; int main() { int cnts = 0; while (getline(cin, t[cnts])) cnts++; int res = cnts; for (int i = 0; i < cnts; i++) { for (int j = 0; j < t[i].size(); j++) { if (t[i][j] > '...
11
#include <bits/stdc++.h> using namespace std; using namespace std; const int mod = 1000000007; const int INF = 1000000000; const int N = 100005; using namespace std; int n; vector<int> mas[N]; int main() { ios ::sync_with_stdio(0); cin >> n; int a, b; cout << n - 1 << endl; for (int i = 1; i < n; ++i) { c...
12
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; int main() { int T; scanf("%d", &T); while (T--) { int n; scanf("%d", &n); int ans = n << 1; for (int i = 1; i <= n; ++i) { printf("%d%c", ans + (i - 1) * 2, i == n ? '\n' : ' '); } } return 0; }
0
#include <bits/stdc++.h> using namespace std; const int INF = 1000000000; const int MOD = 1000000007; map<int, int> mp; signed main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; int x[n]; for (int i = 0; i < n; i++) cin >> x[i]; sort(x, x + n); int res1 = 0; for (int i = 0; i < n...
10
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.precision(9); int T = 1; while (T-- > 0) { int n, k, x; cin >> n >> k >> x; vector<int> a; vector<int> dig(32); int total = 0; for (int i = 0; i < n; ++i) { int x; cin >> x;...
9
#include <bits/stdc++.h> using namespace std; const int MAXK = 210; const int MAXN = 40; int n, k; int p[MAXN]; long double dp[MAXK][MAXN][MAXN]; int main() { cout << fixed << setprecision(10); cin >> n >> k; for (int i = int(0); i < int(n); ++i) cin >> p[i]; for (int i = int(0); i < int(n); ++i) for (int j...
16
#include <bits/stdc++.h> using namespace std; const long double PI = acos(-1.0); const long double EPS = 1e-7; const long long MOD = 1e9 + 7; void solve() { long long k; cin >> k; long long lo = 1; long long hi = 100000; long long best = hi; while (lo <= hi) { long long mid = (lo + hi) / 2; if (mid ...
0
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int k = log2(n); cout << k + 1; }
5
#include <bits/stdc++.h> int main() { long long int a, b, n, t, i; scanf("%lld", &t); for (i = 1; i <= t; i++) { scanf("%lld", &n); if (n > 2) { a = n / 2 + 1; b = n - a; printf("%lld\n", b); } else printf("0\n"); } return 0; }
0
#include <bits/stdc++.h> using namespace std; const int maxn = 1000 * 1000 + 10; const int maxn5 = 3 * 100 * 1000 + 10; const long long mod = 1000 * 1000 * 1000 + 7; const long long inf = 1LL * 2 * 1000 * 1000 * 1000 * 1000 * 1000 * 1000 + 10; bool mark[600][600]; int sch[600][600], k; map<pair<int, int>, vector<pair<i...
8
#include <bits/stdc++.h> using namespace std; double m[6], w[6], h, h2; double sum = 0; int main() { for (int i = 1; i <= 5; i++) { cin >> m[i]; } for (int i = 1; i <= 5; i++) { cin >> w[i]; } cin >> h >> h2; sum += max((500 * 0.3), (((1 - ((m[1] * 1.0 / 250.0) * 1.0)) * 500) - (50 * w[...
2
#include <bits/stdc++.h> double A[200000], B[200000], C[200000]; int i, j, n, m; double p; int main() { scanf("%d", &n); for (i = 1; i <= n; i++) { scanf("%lf", &p); B[i] = p * (B[i - 1] + 1); A[i] = (A[i - 1] + 2 * B[i - 1] + 1) * p + (1 - p) * A[i - 1]; } printf("%.9lf\n", A[n]); }
12
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:256000000") using namespace std; const int INF = 1000 * 1000 * 1000 + 21; const long long int LLINF = (1ll << 60) + 5; const int MOD = 1000 * 1000 * 1000 + 7; const int MAX_N = 10000 + 5; int n, l, r; int arr[MAX_N]; vector<int> fr; vector<int> sc; bool can[MAX_N...
19
#include <bits/stdc++.h> const int C = 100001; double A[C], B[C], P1[C], P2[C]; int main() { int n, i; double cx = 0, cy = 0, k, dt, a, b, c; scanf("%d", &n); for (i = 0; i < n; i++) scanf("%lf", &B[i]); for (i = 0; i < n; i++) scanf("%lf", &A[i]); for (i = 0; i < n; i++) { k = A[i] + B[i]; a = -1.0...
16
#include <bits/stdc++.h> using namespace std; int main() { int i; cin >> i; while (i--) { string str; cin >> str; string a; cin >> a; map<char, int> req; for (int j = 0; j < str.length(); j++) { req[str[j]] = j; } int ans = 0; int x = a.length(); for (int j = 0; j < x...
0
#include <bits/stdc++.h> using namespace std; const long long INF = 1e18; long long a; int main() { scanf("%lld", &a); long long num = INF / 10 % a; num = num * 2 % a; num = num * 9 % a; num = num * 9 % a; num = num * 5 % a; printf("%lld %lld\n", a - num, a - num + INF - 1); return 0; }
17
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; unordered_map<string, string> m; unordered_map<string, bool> vu; vector<string> v; for (int i = 0; i < n; ++i) { string a, b; cin >> a >> b; v.emplace_back(a); m[a] ...
3
#include <bits/stdc++.h> using namespace std; void yo() { ios::sync_with_stdio(false); cin.tie(NULL); cout.precision(0); cout << fixed; } void solve() { long long int n; cin >> n; string a, b; cin >> a >> b; for (long long int i = 0; i < n; i++) if (a[i] == '1' && b[i] == '1') { cout << "NO\...
0
#include <bits/stdc++.h> using namespace std; const double eps = 1e-9; double dp[2111][2111][2][2], P; int n, x[2111], h; int goLeft[2111], goRight[2111]; int getGoLeft(int i) { if (goLeft[i] != -1) return goLeft[i]; int &p = goLeft[i]; p = i; while (p > 1 && x[p - 1] + h > x[p]) --p; return p; } int getGoRig...
15
#include <bits/stdc++.h> using namespace std; int main() { int n; string s, ss; vector<pair<string, string> > v; cin >> n; for (int i = 0; i < n; i++) { cin >> s; cin >> ss; v.push_back(make_pair(s, ss)); } for (int i = 0; i < n; i++) { if (v[i].second == "rat") { cout << v[i].first ...
1
#include <bits/stdc++.h> using namespace std; int const oo = 1e9; int const mod = 1e9 + 7; int main() { cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0); int n, k; cin >> n >> k; vector<int> v(2 * n + 1); for (int& i : v) cin >> i; for (int i = 1; k; i += 2) { if (v[i - 1] < v[i] - 1 && v[i + 1...
3
#include <bits/stdc++.h> using namespace std; int a[100][100]; int ans[100]; int main() { int n, m, maxi = 0; cin >> n >> m; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { cin >> a[i][j]; if (j == 0) { ans[i] = a[i][j]; } else { if (a[i][j] <= ans[i]) { ...
2
#include <bits/stdc++.h> using namespace std; const int maxn = (1e5) + 9; int mem[110]; string s; int t, m; bool add(int len, int name) { int i, j, d = m - len + 1; bool flag = false; for (i = 1; i <= d; i++) { flag = false; for (j = i; j < i + len; j++) { if (mem[j]) flag = true; } if (flag...
8
#include <bits/stdc++.h> using namespace std; int main() { int ans = 0; int x1, x2, y1, y2; int n; cin >> n; for (int i = 0; i < n; ++i) { cin >> x1 >> y1 >> x2 >> y2; ans += (x2 - x1 + 1) * (y2 - y1 + 1); } cout << ans; return 0; }
2
#include <bits/stdc++.h> using namespace std; long long a[200100], cnt[200100], ans, l, r; void upd(long long sum, long long _l, long long _r) { if (sum > ans) { ans = sum; l = _l, r = _r; } } int main() { long long n; cin >> n; for (int i = 0; i < n; ++i) { cin >> a[i]; cnt[a[i]]++; } for...
12
#include <bits/stdc++.h> using namespace std; vector<pair<int, pair<int, int>>> adj[(long)(1e5 + 1)]; int sub[(long)(1e5 + 1)]; int w[(long)(1e5 + 1)]; int c[(long)(1e5 + 1)]; int dfs(int r, int p) { int cnt = 0; for (int i = 0; i < adj[r].size(); i++) { if (adj[r][i].first != p) { w[adj[r][i].first] = ad...
12
#include <bits/stdc++.h> using namespace std; template <class T1> void deb(T1 e) { cout << e << '\n'; } template <class T1, class T2> void deb(T1 e1, T2 e2) { cout << e1 << " " << e2 << '\n'; } template <class T1, class T2, class T3> void deb(T1 e1, T2 e2, T3 e3) { cout << e1 << " " << e2 << " " << e3 << '\n'; } ...
4
#include <bits/stdc++.h> using namespace std; const double eps = 1e-8; const double INF = 1e20; const double PI = acos(-1.); const int MXN = 100005; const long long MOD = 1000000007; struct SEG { int l, r; long long m; long long x; SEG() {} SEG(int _l, int _r) { l = _l, r = _r; } } SGT[MXN << 2]; int a[100005...
15
#include <bits/stdc++.h> using namespace std; int main() { int n, p; cin >> n >> p; char* arr = new char[n]; for (int i = 0; i < n; i++) { cin >> arr[i]; } int str = 0, end = str + p; while (end < n) { if (arr[str] != '.' && arr[end] != '.' && arr[str] == arr[end]) { end++; str++; ...
4
#include <bits/stdc++.h> using namespace std; int deg[100100]; int num[100100]; vector<int> v[100100]; int a[100100], b[100100]; int main() { int i, j, k, n, m; int x, y; scanf("%d %d", &n, &m); for (i = 0; i < m; i++) { scanf("%d %d", &x, &y); v[x].push_back(y); v[y].push_back(x); deg[x]++, deg...
16
#include <bits/stdc++.h> const int Inf = 1e9; long long LINF = (long long)4e18; const long long mod = 1e9 + 7; using namespace std; long long gcd(long long a, long long b) { if (b == 0) return a; else return gcd(b, a % b); } int main() { ios::sync_with_stdio(false); int n; cin >> n; vector<int> a(n)...
10
#include <bits/stdc++.h> const int N = 100005, mu = 1e9 + 7; int to[N << 1], edge, Next[N << 1], last[N], f[N], size[N], deep[N], son[N], tp[N]; int id, dfn[N], s[N], k, m, r, dp[N][305], a[N], b[N], n, Q, x, y; void reduce(int &x) { x += x >> 31 & mu; } void add(int x, int y) { to[++edge] = y; Next[edge] = las...
17
#include <bits/stdc++.h> using namespace std; long long gcd(long long x, long long y) { return y ? gcd(y, x % y) : x; } int main() { cin.tie(nullptr); ios_base::sync_with_stdio(false); cout.setf(ios_base::fixed); cout.precision(28); int t; cin >> t; while (t--) { long long x, y, p, q; cin >> x >> ...
9
#include <bits/stdc++.h> using namespace std; long long power(long long a, long long n) { long long ans = 1; while (n) { if (n % 2) ans = ans * a % 1000000007; n /= 2; a = a * a % 1000000007; } return ans; } int a[501], b[501]; int main() { int n, k; scanf("%d", &n); for (int i = 1; i <= n; i+...
10
#include <bits/stdc++.h> using namespace std; bool myfunction(int i, int j) { return (i > j); } int main() { int a, b, c, d, m, n; cin >> a >> b >> c >> d >> m >> n; if ((a >= c + m && b >= max(d, n)) || (b >= c + m && a >= max(d, n)) || (a >= c + n && b >= max(d, m)) || (b >= c + n && a >= max(d, m)) || ...
4
#include <bits/stdc++.h> using namespace std; long long int a, b, l, m, t, n, x, y, mid, s, f; int main() { cin >> a >> b >> n; for (int i = 0; i < n; i++) { cin >> l >> t >> m; x = (t - a) / b + 1; if (x < l) { cout << -1 << endl; continue; } s = 0; f = x - l + 1; while (f -...
11