solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> long long gcd(long long a, long long b) { if (!b) { return a; } return gcd(b, a % b); } bool arr[1000001]; using namespace std; long long brr[1005]; long long state[100005]; int32_t main() { long long n, m, h; cin >> n >> m >> h; long long arr[m]; for (long long i = 0; i < m; ...
4
#include <bits/stdc++.h> using namespace std; int ara[200005]; int main() { int n, s; scanf("%d %d", &n, &s); for (int i = 1; i <= n; i++) scanf("%d", &ara[i]); deque<int> dq; int res = (ara[s] != 0); for (int i = 1; i <= n; i++) if (ara[i] && i != s) dq.push_back(ara[i]); sort(dq.begin(), dq.end()); ...
11
#include <bits/stdc++.h> using namespace std; template <typename TYPE> inline void chkmax(TYPE &first, TYPE second) { first < second ? first = second : 0; } template <typename TYPE> inline void chkmin(TYPE &first, TYPE second) { second < first ? first = second : 0; } template <typename TYPE> void readint(TYPE &firs...
19
#include <bits/stdc++.h> using namespace std; const int N = 1000000; int n; long long a[N + 1]; bool mark[N + 1]; long long solve(vector<pair<long long, long long> > &f) { long long sa = 0, ta = 0; for (int i = 0; i < f.size(); ++i) { sa += f[i].first * f[i].second; ta += f[i].second; } if (sa == 0) ret...
13
#include <bits/stdc++.h> using namespace std; int n, m, s, d; const int MAX = 1e3 + 3; vector<pair<long long, int> > G[MAX]; long long dp[MAX]; long long DIJ(int src, int dest) { for (int i = 0; i < n + 1; i++) dp[i] = LLONG_MAX; set<pair<long long, int> > q; q.insert(pair<long long, int>(0LL, src)); while (!q....
11
#include <bits/stdc++.h> using namespace std; int op, id, pos[10 * 222222], n, m; int lsum[222222 << 2], rsum[222222 << 2], msum[222222 << 2], beg[222222 << 2]; void build(int l, int r, int rt) { lsum[rt] = rsum[rt] = msum[rt] = r - l + 1; beg[rt] = l; if (l == r) return; int m = (l + r) >> 1; build(l, m, rt ...
14
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e5 + 10; int n, m, q, k, que[MAXN]; bool ok[MAXN]; int aa[MAXN], bb[MAXN], cc[MAXN], dd[MAXN]; pair<int, int> vec[MAXN]; int weed[4 * MAXN]; bool cmp(int u, int v) { return cc[u] < cc[v]; } void water(int v, int b, int e, int x, int val) { if (e - b == 1...
16
#include <bits/stdc++.h> using namespace std; int main() { string a; int b = 1; cin >> a; for (int i = 0; i < a.size(); i++) { if (a[0] != '1') { b = 0; } else if (a[i] != '1' && a[i] != '4') { b = 0; } else if (a.find("444") != a.npos) { b = 0; } } if (b == 0) { cout <...
1
#include <bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; template <class C> void mini(C &a4, C b4) { a4 = min(a4, b4); } template <class C> void maxi(C &a4, C b4) { a4 = max(a4, b4); } template <class TH> void _dbg(const char *sdbg, TH h) { cerr << sdbg << '=' << h << endl; } template <class TH, c...
9
#include <bits/stdc++.h> using namespace std; class trie { public: map<char, trie> h; bool e; int n_id; int k; trie() : e(false), k(0), n_id(-1){}; void insert(const string &x, int id) { trie *p = this; for (char c : x) { p = &p->h[c]; p->e = true; if (p->n_id != id) { p->...
7
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } int mini = 1e7; int k = 0; while (k < n) { vector<int> b(a[k]); int sum = 0; for (int i = 0; i < a[k]; i++) { cin >> b[i]; sum += b[i]; ...
1
#include <bits/stdc++.h> using namespace std; long long int n, m, y, d, s, ch, sum; int main() { cin >> n >> m; string a[n]; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n - 1; i++) { for (int c = 0; c < m - 1; c++) { y = 0, d = 0, s = 0, ch = 0; if (a[i][c] == 'f') y++; ...
1
#include <bits/stdc++.h> using namespace std; int n, t; bool arr[52]; int ml, mr; int cont; int i; int main() { cin >> t; while (t > 0) { t--; cin >> n; for (i = 0; i < n; i++) { cin >> arr[i]; } ml = 0; mr = n - 1; while (arr[mr] == 0) { mr--; } while (arr[ml] == 0) ...
0
#include <bits/stdc++.h> using namespace std; template <typename Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 << "\n"; } template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args) { const char* comma = strchr(names + 1, ','); cerr.write(nam...
2
#include <bits/stdc++.h> using namespace std; bool g[1010][1010]; int bit[32]; int a[100]; int main() { int k; bit[0] = 1; for (int i = 1; i < 31; i++) bit[i] = 2 * bit[i - 1]; while (cin >> k) { memset(g, false, sizeof(g)); int cnt = 2; int Max = -1; for (int i = 30; i >= 0; i--) if (k & ...
11
#include <bits/stdc++.h> using namespace std; string sum(string s1, string s2) { int i, j, s11, s22, car = 0, num = 0; s11 = s1.size(); s22 = s2.size(); string t; i = 0; j = 0; while (i < s11 || j < s22) { if (i < s11 && j < s22) { num = s1[s11 - 1 - i] + s2[s22 - 1 - j] - 96 + car; if (nu...
7
#include <bits/stdc++.h> using namespace std; template <class T> inline bool fs(T &x) { int c = getchar(); int sgn = 1; while (~c && c < '0' || c > '9') { if (c == '-') sgn = -1; c = getchar(); } for (x = 0; ~c && '0' <= c && c <= '9'; c = getchar()) x = x * 10 + c - '0'; x *= sgn; return ~c; } in...
7
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n, c1 = 0, c2 = 0; cin >> n; while (n > 0) { if (n % 2 == 0) n = n / 2; else break; c1++; } while (n > 0) { if (n % 3 == 0) n = n / 3; else ...
1
#include <bits/stdc++.h> using namespace std; int n; basic_string<int> e[100005]; int d[100005]; void dfs(int x, int p) { for (int y : e[x]) { if (y == p) continue; d[y] = d[x] + 1; dfs(y, x); } } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cerr.tie(nullpt...
14
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; int s = n + m; cout << max(n, m) - 1 << " " << s - max(n, m) << endl; return 0; }
5
#include <bits/stdc++.h> using namespace std; int main() { long n; double a, b, p, q, r = 0; set<double> s; cin >> n >> a >> b; for (long i = 0; i < n; i++) { cin >> p >> q; if (b != q) s.insert((a - p) / (b - q)); else r = 1; } cout << s.size() + r; }
6
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; const int maxn = 300300; vector<pair<int, int>> g[maxn]; bool used[maxn]; string str; int dfs1(int u) { used[u] = true; int res = 1; for (auto p : g[u]) { int v = p.first; int e = p.second; if (used[v]) continu...
11
#include <bits/stdc++.h> using namespace std; inline void read(int &x) { char ch; int t = 0; x = 0; for (ch = getchar(); ch < '0' || ch > '9'; ch = getchar()) if (ch == '-') t = 1; for (; ch >= '0' && ch <= '9'; x = x * 10 + ch - 48, ch = getchar()) ; if (t) x = -x; } const int N = 100005; int sum[N...
16
#include <bits/stdc++.h> using namespace std; template <class T> void _R(T &x) { cin >> x; } void _R(int &x) { scanf("%d", &x); } void _R(long long &x) { scanf("%lld", &x); } void _R(double &x) { scanf("%lf", &x); } void _R(char &x) { scanf(" %c", &x); } void _R(char *x) { scanf("%s", x); } void R() {} template <clas...
18
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; int a, sum = 0; for (int i = 0; i < n; i++) { cin >> a; sum += a; } if (sum % n == 0) cout << n << endl; else cout << n - 1 << endl; return 0; }
5
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); ; long long int n, n1, n2; cin >> n >> n1 >> n2; double a[n]; long long int i; for (i = 0; i < n; i++) { cin >> a[i]; } sort(a, a + n); double ans1 = 0; double ans2 = 0; if (n2 > n1) ...
3
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; long long qp(long long a, long long b) { long long ret = 1; while (b) { if (b & 1) ret = ret * a % mod; a = a * a % mod; b >>= 1; } return ret; } long long sum[6][100000 + 8]; long long tre[6][(100000 << 2) + 8]; long lo...
17
#include <bits/stdc++.h> using namespace std; const int inf = 1 << 30; const long long int INF = 1e18; const int MOD = 1e9 + 7; int main() { int n; cin >> n; string s[n + 2]; long long int ans, eq; ans = eq = 0; set<int> sz; for (int i = 0; i < n; i++) cin >> s[i]; map<int, long long int> l, r; for (i...
7
#include <bits/stdc++.h> using namespace std; int main() { long long t, m; cin >> t; for (int i = 0; i < t; i++) { int n; cin >> n; int an = 0, bn = 1e9 + 1; for (int j = 0; j < n; j++) { int a, b; cin >> a >> b; an = max(an, a); bn = min(bn, b); } if (an - bn > 0) ...
3
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:102400000,102400000") using namespace std; template <class T, class U> inline void Max(T &a, U b) { if (a < b) a = b; } template <class T, class U> inline void Min(T &a, U b) { if (a > b) a = b; } inline void add(int &a, int b) { a += b; while (a >= 10000...
13
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; long long n, m; long long pow_log(long long k) { if (k == 0) { return 1; } long long b = pow_log(k / 2); b = (b * b) % MOD; if (k % 2) { b = (b * 2) % MOD; } return b; } int main() { cin >> n; m = pow_log(n - 1); if...
5
#include <bits/stdc++.h> using namespace std; long long dp[5001][5001]; vector<long long> v; int n; long long ret(long long k, long long pos) { if (pos >= n || k <= 0) return 0; if (n - pos <= k) return n - pos; if (dp[pos][k]) return dp[pos][k]; auto idx = upper_bound(v.begin(), v.end(), v[pos] + 5) - v.begin(...
4
#include <bits/stdc++.h> using namespace std; int cnt[5]; int n, res, sum; int main() { ios_base::sync_with_stdio(false); scanf("%d", &n); int x; for (int i = 1; i <= n; ++i) { scanf("%d", &x); ++cnt[x]; sum += x; } if (sum == 1 || sum == 2 || sum == 5) { puts("-1"); return 0; } int ...
13
#include <bits/stdc++.h> using namespace std; void Get_Val(int &Ret) { Ret = 0; char ch; while (ch = getchar(), ch > '9' || ch < '0') ; do { (Ret *= 10) += ch - '0'; } while (ch = getchar(), ch >= '0' && ch <= '9'); } const int Max_N(300050); int N, A[Max_N], P[Max_N], Q[Max_N], PST[20][Max_N], QST[20...
20
#include <bits/stdc++.h> using namespace std; struct point { double x, y, z, R; }; point p; point A, v; point pp; double ans; int n, m; double cal2(double num) { point p1; p1.x = A.x + num * v.x; p1.y = A.y + num * v.y; p1.z = A.z + num * v.z; double x = p1.x - pp.x; double y = p1.y - pp.y; double z = p...
17
#include <bits/stdc++.h> using namespace std; const int N = 100100; long long tree_min[4 * N], arr[N]; long long tree_sum[4 * N]; long long dp[N]; int n, c; void build(int li = 0, int ri = n - 1, int index = 1) { if (li == ri) { tree_min[index] = arr[li + 1]; tree_sum[index] = arr[li + 1]; } else { int ...
12
#include <bits/stdc++.h> int p[100005]; int main() { int i, n, x; scanf("%d", &n); for (i = 1; i <= n; i++) { scanf("%d", &x); p[x] = i; } for (i = 0; i < n; i++) { if (i) printf(" "); scanf("%d", &x); printf("%d", p[x]); } return 0; }
4
#include <bits/stdc++.h> using namespace std; const int N = 7e4 + 7; const int B = 300; bitset<N> bs, Gs[B + 10], ns[B + 10]; int n, m, dy[N], vis[N], cnt[N], GM[N]; struct node { int val, id; } a[N]; bool cmp(node aa, node bb) { return aa.val > bb.val; } int main() { scanf("%d%d", &n, &m); for (int i = 1, iE = n...
19
#include <bits/stdc++.h> using namespace std; using ll = int64_t; const ll MOD = 1e9 + 7; int main() { int t; cin >> t; vector<int> data(1e6 + 10); while (t--) { int x; cin >> x; string s; cin >> s; ll len = s.size(); for (ll i = 0; i < len; ++i) { data[i] = s[i] - '0'; } i...
9
#include <bits/stdc++.h> using namespace std; const long long N = 300010; const long long INF = 0x3f3f3f3f; const long long MOD = 1e9 + 7; long long n, p, k, ans, cur, x; vector<long long> a(N); int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> p >> k; for (int i = 0; i < n; ++i)...
15
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 50; vector<int> row[N]; vector<int> col[N]; vector<pair<int, int> > ld[N * 2]; vector<pair<int, int> > rd[N * 2]; map<pair<int, int>, int> mp; int a[10]; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, m; cin >> n >> m...
9
#include <bits/stdc++.h> int main() { int n; scanf("%i", &n); int d[101]; for (int i = 2; i <= n; i++) scanf("%i", &d[i]); int a, b; scanf("%i", &a); scanf("%i", &b); int count = 0; for (int i = a + 1; i <= b; i++) count += d[i]; printf("%i", count); return 0; }
0
#include <bits/stdc++.h> using namespace std; int main() { int n, m, k; scanf("%d %d %d", &n, &m, &k); vector<vector<int>> what(n + 1, vector<int>(m + 1)); vector<int> when(n + 1); vector<int> lockedMemory(k + 1); for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { scanf("%d", &what[i][j...
8
#include <bits/stdc++.h> using namespace std; int main() { long long n, t, c, n1 = 0, i, p = 1, s = 0, j; cin >> n >> t >> c; vector<long long> v(n); vector<long long> v1; for (i = 0; i < n; i++) cin >> v[i]; for (i = 0; i < n; i++) { if (v[i] > t) { v1.push_back(i + 1); n1++; } } fo...
3
#include <bits/stdc++.h> using namespace std; int a[1505], sum[1505]; int dp[1505][1505]; int nt[1505]; int main() { int n, s, m, k; scanf("%d%d%d%d", &n, &s, &m, &k); for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); nt[i] = -1; } for (int i = 1; i <= s; i++) { int l, r; scanf("%d%d", &l, &r...
17
#include <bits/stdc++.h> using namespace std; const int maxn = 1000 + 5; const int t[] = {1, 10, 100, 1000, 10000, 100000, 1000000}; string s[maxn]; bool nz[maxn]; long long v[maxn]; int main() { int n; cin >> n; for (int i = 0; i < n; ++i) { cin >> s[i]; nz[s[i][0]] = true; } for (int i = 0; i < n; +...
9
#include <bits/stdc++.h> using namespace std; int main() { int n, s; cin >> n >> s; vector<int> floors(s, 0); int floor, time; for (int i = 0; i < n; i++) { cin >> floor >> time; floors[floor - 1] = max(floors[floor - 1], time); } int ct = 0; for (int i = s - 1; i >= 0; i--) { ct += (i != s ...
2
#include <bits/stdc++.h> using namespace std; int n, ar[1011]; int main() { ar[0] = 1; ar[1] = 1; ar[2] = 3; for (int i = 3; i <= 1000; i++) { ar[i] = 3 * ar[i - 1]; ar[i] %= 1000003; } scanf("%d", &n); printf("%d\n", ar[n]); return 0; }
5
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int m, s; cin >> m >> s; int small[110] = {0}; small[1] = 1; int x = s - 1; int flag = 1; for (int i = m; i >= 1; i--) { if (i == 1 && x >= 9) { flag = 0; break; } if (x >= 9) { ...
6
#include <bits/stdc++.h> using namespace std; using ll = long long int; template <typename T> ostream &operator+(ostream &out, const vector<T> &vec) { for (const auto &x : vec) { out << x << " "; } out << "\n"; return out; } template <typename T> ostream &operator*(ostream &out, const vector<T> &vec) { fo...
16
#include <bits/stdc++.h> using namespace std; signed main() { long long h, n; cin >> h >> n; --n; long long ans = 0, dir = 0; for (long long i = 0; i < h; ++i) { ++ans; if (dir == 0) { if ((n & (1ll << (h - i) - 1)) <= ((1ll << (h - i - 1)) - 1)) { dir = 1; } else { ans += ...
9
#include <bits/stdc++.h> using namespace std; struct data { struct hash_table { static const int n = 5000010, mod = 1000007; int h[n]; int val[n]; int f, p, c, link[n], last[mod]; hash_table() : f(0), p(0), c(0) { memset(last, -1, sizeof last); } inline int *find(int hash) { for (f = -1,...
21
#include <bits/stdc++.h> using namespace std; long long power(long long a, long long b) { return b ? power(a * a % 1000000007ll, b / 2) * (b % 2 ? a : 1) % 1000000007ll : 1; } long long gcd(long long a, long long b) { if (a == 0 || b == 0) return max(a, b); if (a == 1 || b == 1) return 1; return gcd(...
7
#include <bits/stdc++.h> using namespace std; const int maxn = 100005; int n, len; char ch; char in[maxn]; int ans[maxn]; int main() { n = 0; len = 0; while ((ch = getchar()) != EOF && ch != '\n') { in[len++] = ch; if (ch == '#') n++; } bool flag = true; int cnt = 0, res; for (int i = 0; i < len &...
7
#include <bits/stdc++.h> using namespace std; const int maxn = (1 << 14) + 20; int tmp[maxn], last[maxn], cur_row[maxn], aux[2 * maxn]; int parent[2 * maxn]; void init() { for (int e = 0; e < 2 * maxn; e++) parent[e] = e; } int find(int x) { if (x == parent[x]) return x; return parent[x] = find(parent[x]); } char...
17
#include <bits/stdc++.h> using namespace std; const long long maxn = 1e5 + 5; const long double per = 100, cns = 1; long long n, m, a[maxn], h[maxn]; long double chp[maxn], rst[maxn]; pair<long long, long long> p[maxn]; vector<pair<long long, long long>> vec[2][maxn * 4]; vector<long double> mul[2][maxn * 4]; void buil...
14
#include <bits/stdc++.h> using namespace std; int main() { int n, i, in; cin >> n; set<int> a; set<int>::iterator itr; itr = a.begin(); for (i = 0; i < n; i++) { cin >> in; if (in != 0) a.insert(in); } cout << a.size(); return 0; }
0
#include <bits/stdc++.h> using namespace std; double a, b, c; int main() { cin >> a >> b >> c; double v1 = sqrt(2) / 12 * a * a * a; double v2 = sqrt(2) / 6 * b * b * b; double s3 = c * c / 4 * sqrt(25 + 10 * sqrt(5)); double h = 0.5257311121191458 * c; double v3 = s3 * h / 3; cout << fixed << setprecisio...
9
#include <bits/stdc++.h> using namespace std; const int INF = 2000000000; const double EPS = 1e-9; int mods(int a, int b) { return (b + (a % b)) % b; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, m, k, least = INF, jump, crashed, frogs[105], mosquito[105], dead[105]; vector<...
5
#include <bits/stdc++.h> using namespace std; int n, m, k; int num = 0; int mid = 0; int e[21][21]; int flag[21]; int dfs(int x, int sum, int mid) { if (x > n) { num = num + 1; } else { dfs(x + 1, sum, mid); for (int y = 1; y <= n; y++) { if (num >= k) { break; } int temp = sum...
10
#include <bits/stdc++.h> using namespace std; int main() { int test = 1; while (test--) { long long n; cin >> n; vector<long long> v(n); vector<long long> bit_set(22); for (long long i = 0; i < n; ++i) { cin >> v[i]; } for (long long i = 0; i < n; ++i) { long long tmp = v[i],...
9
#include<bits/stdc++.h> #define ll long long #define vi vector<ll> #define mod 998244353 #define inf 1e18 #define ff first #define ss second #define pb push_back #define mp make_pair using namespace std; /*int dx[]={-1,1,0,0}; int dy[]={0,0,-1,1}; ll pow(ll x, ll y, ll p) { ll res = 1; x = x % p; ...
10
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int list[n]; for (int i = 0; i < n; i++) cin >> list[i]; int a = list[n - 1]; sort(list, list + n); int b = list[n - 1]; cout << (a ^ b); return 0; }
10
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long int t = 1; while (t--) { int n; cin >> n; vector<int> arr(n); int cnt = 0, y = 0; for (int i = 0; i < n; i++) cin >> arr[i]; int x = *min_element(arr.begin(), arr...
1
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long n, l, h, r, i, j; cin >> n >> h >> l >> r; long long arr[n + 1]; for (i = 1; i <= n; i++) cin >> arr[i]; long long dp[n + 1][h + 1]; long long poss[n + 1][h + 1]; memset(poss, 0, sizeo...
9
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; for (long long i = 0; i < n; i++) { int a; if (i == 0) { a = n; } else { a = i; } cout << a << " "; } }
2
#include <bits/stdc++.h> using namespace std; struct Edge { int from; int to; int cost; int idx; Edge() {} Edge(int f, int t) : Edge(f, t, 1, -1) {} Edge(int f, int t, int c, int i) : from(f), to(t), cost(c), idx(i) {} inline int next(int v) const { return v ^ from ^ to; } }; struct Graph { Graph() {}...
13
#include <bits/stdc++.h> using namespace std; int main() { int n; double a, d; cin >> n >> a >> d; double Tv = -1.0, Xv = d, Tend = -1.0; for (int i = 0; i < n; i++) { double Tbegin, Vmax; cin >> Tbegin >> Vmax; { double x = Vmax * Vmax / 2.0 / a; if (x <= d) { Tend = max(Tbegi...
8
#include <bits/stdc++.h> using namespace std; int main() { int n, count = 0, i = 0; cin >> n; vector<int> sticks(n, 0); for (int i = 0; i < n; i++) { cin >> sticks[i]; } sort(sticks.begin(), sticks.end()); while (sticks.begin() + i != sticks.end()) { if (sticks[i] == sticks[i + 1]) { count++...
2
#include <bits/stdc++.h> using namespace std; const long long M = (1e9) + 7; const long long N = 200005; set<pair<long long, long long> > s[N]; long long root[N]; long long func(long long a, long long b) { long long res = 0, swapped = 0, a_original = a; b = root[b]; a = root[a]; if (s[b].size() > s[a].size()) s...
15
#include <bits/stdc++.h> using namespace std; const int MAXN = 111111; const int SZ = 400; struct Part { int Max; int cnt; int* a; Part() { a = new int[SZ]; Max = -1; cnt = 0; } Part(const Part& p) { a = p.a; Max = p.Max; cnt = p.cnt; } void calcMax() { Max = *max_element(a, a + ...
15
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[n + 1]; for (int i = int(0); i <= int(n - 1); i++) { cin >> a[i]; } if (n == 1) { cout << 2 << endl; return 0; } sort(a, a + n); a[0] = 1; for (int i = int(1); i <= int(n - 1); i++) { if (a[i] != a[i - ...
4
#include <bits/stdc++.h> using namespace std; int main() { long long n, d, m, l, ans, i; cin >> n >> d >> m >> l; ans = 0; for (i = 1; i <= n; i++) { if (ans < ((i - 1) * m)) break; ans = (((i - 1) * m + l) / d) * d + d; } cout << ans << endl; return 0; }
9
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0), cout.precision(15); int n, a; cin >> n >> a; vector<int> cities(n + 1, false); for (int i = 1; i <= n; ++i) cin >> cities[i]; int left = a - 1, right = a + 1, ans = cities[a]; while (left >= 1...
2
#include <bits/stdc++.h> #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") using namespace std; int inf = 1e9 + 5; const double PI = 3.1415926535897932384626433832795; int IND; int n; bool cmp(int a, int b) { if (a > IND && b > IND) return a < b; if (a < IND && b < IND) return a < b; else re...
9
#include <bits/stdc++.h> using namespace std; vector<int> adj[100100]; int n, m; int v[100100]; int used[100100]; int main() { scanf("%d %d", &n, &m); memset(used, false, sizeof(used)); vector<int> res; for (int i = 0; i < (m); i++) { int a, b; scanf("%d %d", &a, &b); a--; b--; adj[a].push_b...
13
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); std::cin.tie(0); long long int y, k, n; cin >> y >> k >> n; long long int x = 1, f = 0; int p = 1; if (y >= n) { cout << -1; return 0; } else { while (p * k - y <= 0) { p++; } } x = p *...
4
#include <bits/stdc++.h> double a, b; double fun(double x) { if (x / 2 < b) return 1000000001; int ctr1 = 1; int ctr2 = 1000000000; while (1) { if (ctr1 == ctr2) break; int num1 = (ctr1 + ctr2 + 1) / 2; if (x / (2 * num1) < b) { ctr2 = num1 - 1; } else { ctr1 = num1; } } retu...
9
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n, i, j, k = 0, l, p, q, a = 0, b = 0; cin >> n; for (i = 0; i < n; i++) { p = a; q = b; cin >> a >> b; if (p > a || q > b || b - q > a - p) k = 1; } if (k == 0) cout << ...
4
#include <bits/stdc++.h> using namespace std; namespace _ { const int inf = 1e9 + 7; const int mod = 1e9 + 7; namespace _in { template <class T> inline T read() { char ch; bool flag = 0; T x = 0; while (ch = getchar(), !isdigit(ch)) if (ch == '-') flag = 1; while (isdigit(ch)) x = x * 10 + ch - 48, ch = g...
16
#include <bits/stdc++.h> using namespace std; const int MAXX = 1e4 + 10; int a[MAXX], n, ans = 0; int next(int x) { int t = 0; while ((pow(2, t) + x) < n) t++; return pow(2, (t - 1)) + x; } int main() { cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n - 1; i++) { a[next(i)] += a[...
2
#include <bits/stdc++.h> #define fast() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); #define ll long long int using namespace std; int main() { fast(); ll t; cin>>t; while(t--) { ll n; cin>>n; int ans=0; for(int i=1;i<=100;i++) { ...
0
#include <bits/stdc++.h> using namespace std; const int N = 100; int main() { int n, u, v, k, l; cin >> n; vector<int> a(n); vector<vector<double> > p(n, vector<double>(N + 1, 0)); double res = 0; for (int i = 0; i < n; i++) { cin >> a[i]; p[i][a[i]] = 1; res += p[i][0]; } int q; cin >> q;...
18
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 11; int n, m; struct Node { int p; long long len; int nxt; } G[maxn]; int head[1000010]; long long dis[1000010]; bool vis[1000010]; int a; void add(int x, int y, long long len) { G[++a].p = y; G[a].nxt = head[x]; G[a].len = len; head[x] ...
15
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1.0); const int inf = numeric_limits<int>::max(); int main() { int al, ar, bl, br; cin >> al >> ar >> bl >> br; cout << ((br <= (al + 1) * 2 && br >= al - 1) || (bl <= (ar + 1) * 2 && bl >= ar - 1) ? "YES" ...
5
#include <bits/stdc++.h> int main() { int n; char *s; int *arr; bool *visited; bool flag = false; scanf("%d", &n); s = (char *)malloc((n + 1) * sizeof(char)); scanf("%s", s); arr = (int *)malloc((n + 1) * sizeof(int)); visited = (bool *)malloc((n + 1) * sizeof(bool)); for (int i = 1; i <= n; i++) ...
2
#include <bits/stdc++.h> using namespace std; int n, i, j, a[2505][2505], cnt; bitset<2505> b1[2505], b2[2505], c; vector<pair<int, int> > cmp; vector<int> v[2505 * 2505]; int main() { scanf("%d", &n); for (i = 0; i < n; i++) { for (j = 0; j < n; j++) { scanf("%d", &a[i][j]); cmp.push_back({-a[i][j]...
16
#include <bits/stdc++.h> using namespace std; int inf = 1e9; long long big_inf = 1e18; vector<long long> tree; void update(int v, int tl, int tr, int p, int val) { if (tl == tr) { tree[v] = val; return; } int m = int(tl + tr) / 2; if (p <= m) { update(v * 2, tl, m, p, val); } else { update(v *...
11
#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; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const int INF = INT_MAX; const int mod = 1e9 + 7; con...
12
#include <bits/stdc++.h> using namespace std; set<pair<long long, pair<int, int>>> s; int n, m, r, k; long long get(int x, int y) { int lx = max(0, x - r + 1), rx = min(x, n - r); int ly = max(0, y - r + 1), ry = min(y, m - r); return 1ll * (rx - lx + 1) * (ry - ly + 1); } int main() { cin >> n >> m >> r >> k; ...
13
#include <bits/stdc++.h> using namespace std; int n; double p[110]; double mval = -1.0; inline int iabs(int x) { return x < 0 ? -x : x; } int main() { scanf("%d", &n); for (int i = 0; i <= n; i++) scanf("%lf", &p[i]); for (int i = 0; i <= n; i++) { int a = n - 2 * i; if (a <= 0) break; for (int j = n;...
16
#include <bits/stdc++.h> using namespace std; struct preseg { long long l, r; }; struct sufiseg { long long l, r; }; bool operator<(const preseg &a, const preseg &b) { return (a.l < b.l ? true : (a.l == b.l ? (a.r > b.r) : false)); } bool operator<(const sufiseg &a, const sufiseg &b) { return (a.r < b.r ? true ...
8
#include <bits/stdc++.h> using namespace std; long long n, m, k; vector<pair<long long, long long> > adj[100005]; queue<long long> q; long long source, destination; long long level[100005]; bool vis[100005]; long long dp[100005]; long long path[100005]; map<pair<long long, long long>, bool> mp; map<pair<long long, long...
13
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int N = 0; cin >> N; vector<int> A(N); for (int &a : A) cin >> a; std::vector<pair<int64_t, int>> stack; for (int a : A) { stack.push_back({a, 1}); int64_t s1, s2; int n1, n2; w...
13
#include <bits/stdc++.h> using namespace std; struct DSU { int *pa; int *sz; DSU(int n) { pa = new int[n + 1]; sz = new int[n + 1]; for (int i = 0; i <= n; i++) { pa[i] = i; sz[i] = 1; } } int root(int i) { if (i == pa[i]) return i; return pa[i] = root(pa[i]); } void me...
10
#include <bits/stdc++.h> using namespace std; const int N = 510; const double EPS = 1e-9; int n, m, a, b; int all; double f[N][N], g[N]; int deg[N]; double p[N]; vector<int> graph[N]; double func(int x) { return (1.0 - p[x]) / deg[x]; } int idx(int x, int y) { return x * n + y; } int main() { scanf("%d %d %d %d", &n,...
19
#include <bits/stdc++.h> using namespace std; int comp(long long from, long long to) { vector<long long> f; vector<long long> t; while (from != 0) { f.push_back(from % 10); from /= 10; } while (to != 0) { t.push_back(to % 10); to /= 10; } if (t.size() > f.size()) return -1; int i = 0; ...
8
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 1; long long a[N], b, n, m, s[N], cnt, ans; priority_queue<long long> q; inline bool isdigit(const char& ch) { return (ch >= '0' && ch <= '9'); } inline long long read() { register long long s = 0ll; register bool m = false; register char ch = getc...
15
#include <bits/stdc++.h> using namespace std; int n; int cnt[1000002]; class Combination { long long int ppow(long long int i, long long int j) { long long int res = 1LL; while (j) { if ((j & 1LL)) { res *= i; if (res >= 1000000007) { res %= 1000000007; } } ...
14
#include <bits/stdc++.h> using namespace std; map<int, int> pos; map<int, int> elm; int main() { long long n, m, k, tmp, cur, ans = 0, prev_elm; cin >> n >> m >> k; for (int i = 1; i <= n; ++i) { cin >> tmp; pos[tmp] = i; elm[i] = tmp; } while (m--) { cin >> cur; ans += (pos[cur] - 1) / k ...
8