solution
stringlengths
53
181k
difficulty
int64
0
13
#include <bits/stdc++.h> using namespace std; const long long N = 1e6 + 10; queue<pair<long long, long long>> que; map<long long, bool> st; long long ans, a[N], cnt; long long t = 0, n, m; void solve() { while (que.size()) { auto t = que.front(); que.pop(); if (st[t.second]) continue; st[t.second] = t...
5
#include <bits/stdc++.h> template <typename tp> inline tp abs(const tp& x) { return (x > 0) ? x : -x; } template <typename tp> inline tp max(const tp& x, const tp& y) { return (x > y) ? x : y; } template <typename tp> inline tp min(const tp& x, const tp& y) { return (x < y) ? x : y; } template <typename tp> inlin...
8
#include <bits/stdc++.h> using namespace std; int n, s, p, a[105]; int main() { scanf("%d%d", &n, &s); for (int i = 1; i <= n; i++) scanf("%d", a + i); sort(a + 1, a + n + 1); for (int i = 1; i < n; i++) p += a[i]; if (p <= s) puts("YES"); else puts("NO"); return 0; }
0
#include <bits/stdc++.h> using namespace std; int N; pair<int, int> P[52]; int Xn; vector<int> X; map<int, int> dx; vector<pair<int, int> > V[52]; long long cc[52][52][52 * 100]; long long dp(int n, int r, int sum) { if (n == -1) return sum == 0 ? 0 : 1e18; long long &ret = cc[n][r][sum]; if (ret != -1) return re...
8
#include <bits/stdc++.h> using namespace std; int bPow(int v, int u, int mod) { if (!u) return 1; int res = bPow(v, u / 2, mod); res = (res * 1ll * res) % mod; if (u & 1) res = (res * 1ll * v) % mod; return res; } bool fb(long long x) { return 0; } int bSearch(int l, int r) { while (r - l > 1) { int m =...
8
#include <bits/stdc++.h> using namespace std; int main() { int n, w; cin >> n >> w; int sum = 0; int mx = 0; int mn = 0; for (int i = 0; i < n; i++) { int x; cin >> x; sum += x; mx = max(mx, sum); mn = min(mn, sum); } cout << max(0, w - mx + mn + 1); return 0; }
3
#include <bits/stdc++.h> using namespace std; long long power(long long x, long long y) { long long res = 1; x = x % 1000000007; while (y > 0) { if (y & 1) { res = (res * x) % 1000000007; } y = y >> 1; x = (x * x) % 1000000007; } return res; } long long inv(long long x) { return power(x,...
7
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1), EPS = 1e-7; const int dx[] = {-1, 0, 0, 1, -1, 1, 1, -1}; const int dy[] = {0, -1, 1, 0, 1, 1, -1, -1}; long long gcd(long long x, long long y) { return (!y) ? x : gcd(y, x % y); } long long lcm(long long x, long long y) { return ((x / gcd(x, y))...
3
#include <bits/stdc++.h> using namespace std; int n = 250; int T, A[250]; int main() { cin.tie(NULL); ios::sync_with_stdio(0); cin >> T; for (int t = 0; t < T; t++) { int maxi = 0, mini = INT_MAX, sum = 0, sum2 = 0, sum4 = 0; for (int i = 0; i < n; i++) { cin >> A[i]; mini = min(mini, A[i]);...
10
#include <bits/stdc++.h> int N; int p[100000]; int count; int max; int main() { std::cin >> N; if (N == 0) std::cout << 0 << std::endl; std::cin >> p[0]; for (int i = 1; i < N; i++) { std::cin >> p[i]; if (p[i] >= p[i - 1]) { count++; if (count > max) max = count; } else count = 0;...
0
#include <bits/stdc++.h> using namespace std; int u[1111]; int M[1111]; int MM[1111]; int main() { int n; scanf("%d", &n); for (int i = 1; i <= n; i++) { M[i] = 1000000000; } int d = 512; for (; d > 0; d /= 2) { vector<int> f; memset(u, 0, sizeof(u)); for (int i = 1; i <= n; i += d * 2) { ...
5
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); unsigned long long int n, m, a, b; long long int del, ext; cin >> n >> m >> a >> b; del = (n % m); ext = (m - del); cout << min((del * b), (ext * a)); }
1
#include <bits/stdc++.h> using namespace std; int n; inline int sgn(double xx) { if (fabs(xx) < 1e-9) return 0; return xx > 0 ? 1 : -1; } struct Point { double x, y; Point() {} Point(double X, double Y) : x(X), y(Y) {} } p[(200 + 50)]; inline Point operator-(const Point &P, const Point &Q) { return Point(P....
8
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 20; const int inf = 0x3f3f3f3f; const long long mod = 1e9 + 7; map<char, char> a; char s[maxn]; int main() { cin >> s; int kt = -1; int k1 = -1; int n = strlen(s) - 1; for (int i = (0); i <= (n - 1); i++) { if (s[i] == '.') { kt = ...
5
#include <bits/stdc++.h> using namespace std; int n, q, block; int A[1000005], B[1000005], C[1000005]; int cnt[1000005]; int ans[1000005]; long long answer = 0; int posOfLast[1000005]; int realNum[1000005]; int pref[1000005]; struct node { int L, R, i; } Q[1000005]; vector<node> queries[1000005]; int tree[4 * 1000005...
6
#include <bits/stdc++.h> using namespace std; set<int> st; vector<priority_queue<pair<long long, int>, vector<pair<long long, int> >, greater<pair<long long, int> > > > taxis; void add_taxi(int i, int j, long long t) { if (taxis[i].empty()) st.insert(i); taxis[i].push(pair<long long, int>(...
8
#include <bits/stdc++.h> using namespace std; bool check(long long int x, long long int arr[], long long int n) { if (n / x <= 2 && n % x != 0) return false; for (long long int i = 0; i < x; i++) { bool f = true; for (long long int j = i; j < n; j += x) { if (arr[j] != 1) { f = false; ...
4
#include <bits/stdc++.h> using namespace std; int N, l[82], r[82], V[200]; double Ans[82], F[82][82]; int main() { scanf("%d", &N); for (int i = 1; i <= N; ++i) scanf("%d%d", l + i, r + i), V[++*V] = l[i], V[++*V] = r[i]; sort(V + 1, V + *V + 1); *V = unique(V + 1, V + *V + 1) - V; for (int i = 1; i <= N;...
11
#include <bits/stdc++.h> using namespace std; inline long long read() { long long x = 0, f = 1, c = getchar(); while (!isdigit(c)) { if (c == '-') f = -1; c = getchar(); } while (isdigit(c)) { x = (x << 1) + (x << 3) + (c ^ 48); c = getchar(); } return f == 1 ? x : -x; } const long long N = ...
13
#include <bits/stdc++.h> using namespace std; int a[1000052], b[1000005]; int dp[4005][105][2]; const long long mod = 1e9 + 7; int main() { int n, m, y, x, i, j, k, t; scanf("%d%d", &n, &m); for (i = 1; i <= n; i++) { scanf("%d%d", &a[i], &b[i]); } for (i = 1; i <= n; i++) { dp[a[i]][i][0]++; if (...
5
#include <bits/stdc++.h> using namespace std; void fast() { ios_base::sync_with_stdio(false); cin.tie(NULL); } int main() { long long dp[120][120]; long long aux[120][26]; long long n, k; cin >> n >> k; k--; string a; cin >> a; for (long long i = 0; i < n; i++) { dp[i][1] = 1; for (long long...
5
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; int mapa[1000001] = {0}; int dp[1000001] = {0}; for (int i = 0; i < n; i++) { int a; cin >> a; mapa[a] += 1; dp[a] = mapa[a]; } for (int i = 1; i < 1000001; i++)...
3
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n, m; cin >> n >> m; string a[n + 10]; for (int i = 0; i < n; i++) cin >> a[i]; int i, j, x = 0, y = 0; int steps = 0; for (i = 0; i < n; i++) for (j = (i % 2 ? m - 1 : 0); j >= 0 && j < m;...
3
#include <bits/stdc++.h> using namespace std; const int maxn = 200010; int head[maxn], Next[maxn * 2], ver[maxn * 2], tot; int a[maxn]; int ans[maxn * 100], cnt; void add(int x, int y) { ver[++tot] = y; Next[tot] = head[x]; head[x] = tot; } void dfs(int x, int fa = 0) { if (x != 1) a[x] = -a[x]; ans[++cnt] = ...
5
#include <bits/stdc++.h> using namespace std; const int max_n = 300333, mod = 998244353; int mul(int x, int y) { return (1LL * x * y) % mod; } int power(int a, int b) { if (b == 0) { return 1 % mod; } if (b % 2 == 0) { return power(mul(a, a), b / 2); } return mul(a, power(a, b - 1)); } int inv(int x) ...
12
#include <bits/stdc++.h> using namespace std; const int maxn = 10010; char a[maxn]; char sh[maxn], xi[maxn]; int main() { scanf("%s", a); int num, l, r, sum, tol, ans = 0; int len = strlen(a); for (int i = 0; i < len; i++) { if (a[i] >= 'A' && a[i] <= 'Z') { num = 0; while (i < len && a[i] >= 'A...
4
#include <bits/stdc++.h> using namespace std; const long long M = 1e9 + 7; long long n, m; long long ksm(long long x, long long y) { long long ans = 1; for (; y; y >>= 1, x = x * x % M) if (y & 1) (ans *= x) %= M; return ans; } signed main() { scanf("%lld%lld", &n, &m); printf("%lld\n", (n + 1 - ...
9
#include <bits/stdc++.h> using namespace std; int n; long long a[100005]; vector<vector<int>> graph(200); int dist(int x, int y) { vector<int> d(200, 2000000000); queue<int> Q; d[x] = 0; Q.push(x); while (!Q.empty()) { int f = Q.front(); Q.pop(); for (int i : graph[f]) { if (f == x && i == y...
5
#include <bits/stdc++.h> using namespace std; int n; char s[600005]; int w[600005]; int kmp[600005]; int nonparent[600005]; int rmq[600005][20]; int log_2[600005]; int rmq_query(int l, int r) { int L = log_2[r - l + 1]; return min(rmq[l][L], rmq[r - (1 << L) + 1][L]); } map<int, int> freq; int main() { log_2[1] =...
12
#include <bits/stdc++.h> using namespace std; int main() { int c, v0, v1, a, l; cin >> c >> v0 >> v1 >> a >> l; int v = v0, k = 0; while (c > 0) { c -= v; if (c <= 0) { cout << k + 1 << endl; return 0; } if (v + a <= v1) v += a; else v = v1; c += l; k++; } ...
0
#include <bits/stdc++.h> using namespace std; int main() { int n, k, a, last(0), continuous(1); scanf("%d%d", &n, &k); for (int i = 0; i < n; ++i) { scanf("%d", &a); if (a == last) { continuous += 1; } else { continuous = 1; } last = a; } printf("%d\n", continuous + k > n ? n -...
2
#include <bits/stdc++.h> using namespace std; int m, x, y; map<pair<int, int>, int> itb; map<int, pair<int, int> > bti; set<int> blocks; set<int> q; vector<int> result; bool ex_g(int xx, int yy) { if (itb.find(make_pair(xx, yy)) != itb.end()) return (blocks.find(itb[make_pair(xx, yy)]) != blocks.end()); else ...
6
#include <bits/stdc++.h> using namespace std; int St[4 * (int)(1e6 + 10)]; int arr[(int)(1e6 + 10)], bas, son, s, size; int n, m, k, i, j, x, y, z, ans[(int)(1e6 + 10)]; int upd(int root, int bas, int son, int x, int t) { if (bas == son) { return St[root] = 0; } if (St[(root << 1)] + t >= x) return St[roo...
6
#include <bits/stdc++.h> using namespace std; int main() { int N, M; scanf("%d%d", &N, &M); char st[N][M + 1]; int col[M], row[N]; int val[M][2], valr[N][2]; bool con = true; for (int i = 0; i < M; i++) { col[i] = -1; val[i][0] = -1; val[i][1] = -1; } for (int i = 0; i < N; i++) { row[...
7
#include <bits/stdc++.h> const int md = 1e9 + 7; const long long inf = 4e18; const int OO = 1; const int OOO = 1; using namespace std; const int M = 50005, N = 26; int n; int T = 0; vector<int> a; bool dp[N][M * N] = {}; int to[N][M * N] = {}; void upd(int v) { for (int i = N - 2; i >= 0; i--) { for (int j = 0; j...
11
#include <bits/stdc++.h> using namespace std; const long long N = 1e6 + 11; int a[N], d, n, m; void dfs(int l, int r, int k) { if (l == r - 1) { a[l] = k; return; } if (m == 0) { if (k == 0) return; a[r - 1] = k; return; } m -= 2; int mid = (l + r) / 2; if (k == 0) { k = d; d--...
5
#include <bits/stdc++.h> using namespace std; const int MOD = 998244353, MAXN = 100005, LOGN = 18, MAXM = 1005; inline void S(int& n) { n = 0; int ch = getchar(); int sign = 1; while (ch < '0' || ch > '9') { if (ch == '-') sign = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { n = (n << 3...
5
#include <bits/stdc++.h> using namespace std; int n, m; long long k; struct p { int x, y; }; int c[100][100], f[200]; long long g[300][300]; p a[200]; int min(int o, int p) { if (o < p) return o; return p; } bool cmp(p a, p b) { if (a.x < b.x) { return true; } return false; } long long work(int o) { f...
7
#include <bits/stdc++.h> using namespace std; int a[110]; int main() { int n, k; cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; cin >> k; sort(a, a + n); int ans = 0, now = 1, j; for (int i = 0; i < n; i++) { now = 1; j = i; while (a[j + 1] - a[i] <= k && j + 1 < n) { j++; now+...
3
#include <bits/stdc++.h> using namespace std; int n, k, t; bool mf[5], ff[5]; int h[100], w[100], r[100]; vector<int> val; void rec(int ind, int sum) { if (ind == k - 1) { val.push_back(sum); if (mf[h[ind] - 1] & ff[w[ind] - 1]) val.push_back(sum + r[ind]); return; } rec(ind + 1, sum); if (mf[h[ind]...
5
#include <bits/stdc++.h> using namespace std; const int Maxn = 200005; int n; int a, b, c; multiset<int> S; int res; int Remove(int x) { multiset<int>::iterator it = S.upper_bound(x); if (it == S.begin()) return 0; it--; int val = *it; S.erase(it); return val; } void Phase0() { multiset<int>::iterator it;...
8
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; int arr[n]; for (int i = 0; i < n; i++) { cin >> arr[i]; } if (arr[0] >= arr[n - 1]) { cout << "NO" << endl; } else cout << "YES" << endl; } }
3
#include <bits/stdc++.h> using namespace std; const long long INF = 2e18 + 5; int main() { int n, k; cin >> n >> k; map<int, int> f; vector<pair<long long, long long> > v; for (int x, i = 0; i < n; i++) { cin >> x; f[x]++; } for (auto x : f) v.emplace_back(x.first, x.second); n = v.size(); vec...
7
#include <bits/stdc++.h> #pragma GCC optimize("O3") #pragma GCC target("sse4") using namespace std; unsigned int a[100000 + 5], b[100000 + 5], p; int f(int x) { return ~((x - 1) >> 31); } int main() { int n, t, l, r, k, i; long long ans = 0; for (scanf("%d", &n); n--;) { scanf("%d%d%d", &t, &l, &r); if (t...
11
#include <bits/stdc++.h> using namespace std; float f[1000 + 10][1000 + 10]; int n, m, ans; int main() { scanf("%d%d", &n, &m); f[1][1] = m; for (int i = 2; i <= n; i++) for (int j = 1; j <= i; j++) { if (f[i - 1][j - 1] - 1 > 0) f[i][j] += (f[i - 1][j - 1] - 1) / 2.0; if (f[i - 1][j] - 1 > 0) f[i...
3
#include <bits/stdc++.h> #pragma GCC optimize(2) #pragma GCC optimize(3) #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3") #pragma GCC target("avx,avx2,fma") using namespace std; mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); const long long mod = 1e9 + 7; template <class ...
1
#include <bits/stdc++.h> using namespace std; int power(long long int x, long long int y) { long long int temp; if (y == 0) return 1; temp = power(x, y / 2); if (y % 2 == 0) return temp * temp; else return x * temp * temp; } bool prime_check(long long int n) { long long int i, j; if (n == 1) { ...
6
#include <bits/stdc++.h> using namespace std; template <typename T, typename U> std::istream& operator>>(std::istream& i, pair<T, U>& p) { i >> p.first >> p.second; return i; } template <typename T> std::istream& operator>>(std::istream& i, vector<T>& t) { for (auto& v : t) { i >> v; } return i; } templat...
10
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:250000000") using namespace std; int food[100009], fun[100009]; int main() { ios_base::sync_with_stdio(false); int T; cin >> T; for (int t = 0; t < T; ++t) { int m, k; cin >> m >> k; vector<int> a(k), not_all(k), res(k); for (int i = 0; i ...
6
#include <bits/stdc++.h> char name[2][111]; int n, t, id, x, det; char side[2], cate[2]; int tot[2][111]; int main() { scanf("%s%s", name[0], name[1]); scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d %s %d %s", &t, side, &id, cate); x = (side[0] == 'a') ? 1 : 0; if (tot[x][id] >= 2) continue;...
2
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e6 + 10; int tree[MAXN][10], fail[MAXN], word[MAXN], cnt; void Init() { for (int i = 0; i <= cnt; i++) { word[i] = fail[i] = 0; memset(tree[i], 0, sizeof(tree[i])); } cnt = 0; } void Insert(string s) { int root = 0; for (int i = 0; i < (i...
10
#include <bits/stdc++.h> using namespace std; int n; int main() { int x = 0, y = 0, s = 0, aux, i; cin >> n; aux = n; if (aux % 7 == 0) { for (i = 1; i <= aux / 7; i++) cout << "7"; return 0; } while (n > 0) { s++; n -= 4; if (n % 7 == 0 && n > 0) { x = s; y = n / 7; br...
1
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int m[5][5] = { {1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1}}; int a; for (int i = 1; i <= 3; i++) { for (int j = 1; j <= 3; j++) { cin >> a; m[...
0
#include <bits/stdc++.h> using namespace std; int main() { int q, i, l, r, d; cin >> q; for (i = 0; i < q; i++) { cin >> l >> r >> d; int x = r / d; if ((d * 1) < l) cout << d * 1 << endl; else if ((x * d) <= r) cout << ((x + 1) * d) << endl; } return 0; }
1
#include <bits/stdc++.h> using namespace std; int read() { int x = 0, w = 0; char ch = 0; while (!isdigit(ch)) { w |= ch == '-'; ch = getchar(); } while (isdigit(ch)) { x = (x << 3) + (x << 1) + ch - '0'; ch = getchar(); } return w ? -x : x; } long long f[1010][1010]; const int mod = 1e9 +...
7
#include <bits/stdc++.h> using namespace std; long double mx, tmp; string res; void Update(long double value, string s) { if (value - mx > 1e-10) { mx = value; res = s; } } int main() { long double x, y, z; cin >> x >> y >> z; mx = log(x) * pow(y, z); res = "x^y^z"; Update(log(x) * pow(z, y), "x^z...
8
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const int N = 1e5 + 10; const int M = 1e6 + 10; int n, a[N]; int t[M]; int f[N], p[M], ans; int lowbit(int x) { return x & (-x); } void Upd(int pos, int x) { for (int i = pos; i < M; i += lowbit(i)) t[i] = (t[i] + x) % mod; } int Qry(int pos) { ...
6
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; for (int l = 0; l < t; l++) { long long n, s, k; cin >> n >> s >> k; unordered_set<long long> tilos; for (int i = 0; i < k; ++i) { long long x; cin >> x; tilos.insert(x); } for (long long i = 0; i...
1
#include <bits/stdc++.h> #pragma GCC optimize("Ofast", "unroll-loops", "no-stack-protector") using namespace std; using ll = long long; using ld = double; using pii = pair<int, int>; using uint = unsigned int; using ull = unsigned long long; mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); default_r...
9
#include <bits/stdc++.h> using namespace std; const int inf = (int)1.01e9; const long long infll = (long long)1.01e18; const long double eps = 1e-9; const long double pi = acos((long double)-1); mt19937 mrand(chrono::steady_clock::now().time_since_epoch().count()); int rnd(int x) { return mrand() % x; } void precalc() ...
12
#include <bits/stdc++.h> using namespace std; int c, r, n, k; int mp[15][15]; int dp[15][15]; int main() { cin >> r >> c >> n >> k; memset(mp, 0, sizeof(mp)); memset(dp, 0, sizeof(dp)); for (int i = 1; i <= r; i++) { for (int j = 1; j <= c; j++) { mp[i][j] = 0; } } int x, y; for (int i = 0; ...
1
#include <bits/stdc++.h> using namespace std; const int MAX = 1000005; const long long oo = 1e18; const double eps = 1e-11; int x, y, z; int xx1, yy1, z1; int a, b, c; bool win(int X, int Y, int Z) { if (X > 0 && xx1 <= 0) return 1; if (X <= 0) return 0; if (Y <= z1) return 0; if (yy1 <= Z) return 1; int cc, ...
5
#include <bits/stdc++.h> const long long MXN = 5e5 + 4; const long long MNN = 1e3 + 1; const long long MOD = 1e9 + 7; const long long INF = 1e18; const long long OO = 1e9 + 500; using namespace std; long long l, r; int main() { ios_base::sync_with_stdio(0), cout.tie(0), cin.tie(0); ; cin >> l >> r; cout << "YES...
1
#include <bits/stdc++.h> using namespace std; 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; } char cs[100011]; int a[100011]; int N, K; int main() { scanf("%s", cs); scanf("%d", &K); N = strlen(cs); if (1ll * N...
6
#include <bits/stdc++.h> using namespace std; uint64_t sum(uint64_t x) { uint64_t sum = 0; uint64_t no; while (x > 0) { no = x % 10; x = x / 10; sum = sum + no; } return (sum); } int main() { uint64_t num, num2; cin >> num >> num2; uint64_t ans, x; x = sum(num); uint64_t last, mid, first...
4
#include <bits/stdc++.h> using namespace std; long long n; long long BIT[400005][2]; void upd(long long idx, long long val, long long I) { while (idx <= n) { BIT[idx][I] += val; idx += (idx & (-idx)); } } long long que(long long idx, long long I) { long long anse = 0; while (idx) { anse += BIT[idx][...
4
#include <bits/stdc++.h> using namespace std; priority_queue<int> pq; int main() { int n; scanf("%d", &n); long long res = 0; int x; scanf("%d", &x); pq.push(x); for (int i = 1; i < n; ++i) { scanf("%d", &x); pq.push(x); if (pq.top() > x) { res += pq.top() - x; pq.pop(); pq.p...
7
#include <bits/stdc++.h> using namespace std; int i, n, rez; string s; int main(void) { cin >> s; s = "00" + s; n = s.length() - 1; i = n; while (s[i] == '0') --i; while (i > 0) { ++rez; char ch = s[i - 1]; --i; while (s[i] == ch && i >= 0) --i; } cout << rez; return (0); }
5
#include <bits/stdc++.h> using namespace std; void maloosh_lazma() { ios_base::sync_with_stdio(false); cin.tie(NULL); } int main() { maloosh_lazma(); int n; cin >> n; int *x = new int[n]; for (int i = 0; i < n; i++) { cin >> x[i]; } sort(x, x + n); long long now = 1; for (int i = 0; i < n; i++...
2
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; for (int q = 1; q <= t; q++) { long long int n; long long int x; cin >> n >> x; vector<long long int> skls; for (int i = 0; i < n; i++) { long long int inp; cin >> inp; skls.push_back(inp); } ...
3
#include<bits/stdc++.h> using namespace std; typedef long long ll; void solve(){ ll n,k,m; cin>>n>>k>>m; map<ll,ll>mp; for(int i=0;i<m;i++){ ll x; cin>>x; mp[x]=1; } if((n-m)%(k-1)){ cout<<"NO"<<endl; return; } ll cnt=0; ll have=k/2; ll xd=0,flag=0; for(int i=1;i<=n;i++){ if(mp[i]!=1)cnt++; e...
7
#include <bits/stdc++.h> using namespace std; int main() { int a, c, d, x[25][62] = {}, high = 0; cin >> a; for (int b = 0; b < a; b++) { cin >> c >> d; x[c][d]++; high = max(high, x[c][d]); } cout << high << endl; return 0; }
1
#include <bits/stdc++.h> using namespace std; int a[100000]; int con[1000000]; int main() { int n, m; cin >> n >> m; for (int i = 0; i <= n; i++) { con[i] = 0; } int coun = 0; for (int i = 0; i < m; i++) { int k; scanf("%d", &k); int con1 = 0; for (int j = 0; j < k; j++) { cin >> a...
2
#include <bits/stdc++.h> using namespace std; using ll = long long; const int MOD = 1000000007; const int MOD2 = 998244353; const int INF = 1 << 30; const ll INF2 = (ll)1 << 60; void scan(int& a) { scanf("%d", &a); } void scan(long long& a) { scanf("%lld", &a); } template <class T, class L> void scan(pair<T, L>& p) { ...
0
#include <bits/stdc++.h> using namespace std; set<pair<pair<int, int>, int> > pcs; int l[1010101]; int u[1010101]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, q; cin >> n >> q; int i2 = 2; pcs.insert({{1, n}, 1}); pcs.insert({{n + 1, n + 2}, 1}); for (int i = 0; i < q; i++) { int x...
7
#include <bits/stdc++.h> using namespace std; double P[110], PP, PP2, MAX; int n; int main() { int i, j; scanf("%d", &n); for (i = 0; i < n; i++) scanf("%lf", &P[i]); sort(P, P + n); if (P[n - 1] == 1.0) { printf("%.13lf\n", 1.0); return 0; } for (i = 0; i < n; i++) { PP = 1; PP2 = 0; ...
5
#include <bits/stdc++.h> using namespace std; bool in_range(long long l, long long v, long long r) { return (l <= v && v <= r); } int main() { long long x; cin >> x; x = ((-x) % 360 + 360) % 360; int ans = 0; if (x >= 225 && x < 315) ans = 1; else if (x >= 135 && x < 225) ans = 2; else if (x > 4...
5
#include <bits/stdc++.h> using namespace std; template <class T> int getbit(T s, int i) { return (s >> i) & 1; } template <class T> T onbit(T s, int i) { return s | (T(1) << i); } template <class T> T offbit(T s, int i) { return s & (~(T(1) << i)); } template <class T> int cntbit(T s) { return __builtin_popcoun...
12
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 10; vector<int> g[N]; int du[N], fa[N]; bool vis[N]; queue<int> q; void dfs(int r, int f) { fa[r] = f; for (int i = 0; i < g[r].size(); i++) { int v = g[r][i]; if (v != f) dfs(v, r); } q.push(r); } vector<int> ans; void del(int x) { vis...
6
#include <bits/stdc++.h> using namespace std; int n, q, w, x, y, r, rr, i; char s[30], sx[30], sy[30]; map<string, int> mapa; struct padure { int tata, rel; } v[100005], aux, aux2, xx, yy; padure tata(int x) { if (v[x].tata == x) { aux.tata = x; aux.rel = v[x].rel; return aux; } else { aux2 = tata...
6
#include<bits/stdc++.h> using namespace std; #define ll long long bool com(ll a,ll b) { return a<b; } #define f(i,a,n) for(ll i=a;i<n;i++) #define rf(i,n,a) for(ll i=n;i>=a;i--) #define fe(x,a) for(auto x: a) #define test ll T;cin>>T;while(T--) #define endl "\n" ...
0
#include <bits/stdc++.h> using namespace std; long double x, xx, yy, v, T, vx, vy, wx, wy, y; bool check(long double t) { long double disx = min(t, T) * (vx); if (t >= T) disx += (t - T) * wx; long double disy = min(t, T) * (vy); if (t >= T) disy += (t - T) * wy; disx = disx + x; disy = disy + y; long dou...
6
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); } template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); } template <typename T> T inf; template <> constexpr int inf<int> = 1e9; tem...
10
#include <bits/stdc++.h> using namespace std; const int MOD = 1000000007, M = 60, LOG = 63; const int N = M * 6; const long long mod = MOD; const int inv2 = (mod + 1) / 2; const double pi = acos(-1); int m; int inv[N]; int add(int a, int b) { return (a += b) >= mod ? a - mod : a; } int dec(int a, int b) { return (a -= ...
5
#include <bits/stdc++.h> template <class T> inline bool cmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; } template <class T> inline bool cmin(T& a, const T& b) { return a > b ? a = b, 1 : 0; } using namespace std; char ss[1 << 17], *A = ss, *B = ss; inline char gc() { return A == B && (B = (A = ss) + fread(...
7
#include <bits/stdc++.h> using namespace std; long long n, a[100100], s = 0, d = 0, ans = 0; bool b[100100]; void read(void) { cin >> n; for (long long i = 0; i < n; ++i) cin >> a[i], s += a[i]; } void din(void) { if (s % 3 != 0) { cout << 0; return; } s = s / 3; for (long long i = n - 1, p = 0; i >...
6
#include <bits/stdc++.h> using namespace std; long long powm(long long base, long long exp, long long mod = 1000000007) { long long ans = 1; while (exp) { if (exp & 1) ans = (ans * base) % mod; exp >>= 1, base = (base * base) % mod; } return ans; } void fastscan(int &x) { register int c = getchar(); ...
3
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 5; const int MOD = 1e9 + 7; const double PI = 2 * acos(0.0); long long a[N], b[N], c[N]; int main() { ios::sync_with_stdio(false); cin.tie(0); int t; cin >> t; while (t--) { int n; cin >> n; for (int i = 0; i < n; i++) { cin >...
4
#include <bits/stdc++.h> using namespace std; int dx[] = {1, 0, -1, 0}; int dy[] = {0, 1, 0, -1}; void solve() { long long int n; cin >> n; cout << (n - 1) / 2 << '\n'; } int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t = 1; cin >> t; while (t--) { solve(); } }
0
#include <bits/stdc++.h> using namespace std; inline int getid(int p, int c) { return (p << 1) + c; } int n, m1, m2; class SAT { public: vector<int> v[2010]; int bel[2010], ans[2010], dfn[2010], low[2010], stk[2010], top, bcnt, tim; bool fail, vis[2010], s[2010]; int flag[2010]; bitset<2010> bt[2010]; void...
11
#include <bits/stdc++.h> using namespace std; struct P { int x, y; }; constexpr int sz = 100000 + 2; int hl[sz]; int hr[sz]; int vu[sz]; int vd[sz]; int main(int argc, char **argv) { int d, n, m; cin >> d >> n >> m; P dd[d][2]; for (auto &c : dd) { int x1, x2, y1, y2; cin >> x1 >> y1 >> x2 >> y2; ...
6
#include <bits/stdc++.h> using namespace std; int main() { long long int i, j, k, n; cin >> n; k = 0; for (i = 1; i <= n; i++) { if (i % 2) { k++; printf("%lld ", k); } else { printf("%lld ", n - k + 1); } } printf("\n"); return 0; }
2
#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 * 10 + ch - '0'; ch = getchar(); } return x * f; } char s[1000005], t[1000...
12
#include <bits/stdc++.h> using namespace std; int main() { int v[30005]; int n, t, now; now = 0; cin >> n >> t; for (int i = 0; i < n - 1; i++) { cin >> v[i]; } for (int i = 0; i < n - 1; i++) { now += v[now]; if (now == t - 1) { cout << "YES"; return 0; } if (now >= t) { ...
1
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { for (; b; a %= b, swap(a, b)) ; return a; } int n, m; vector<string> color; vector<string> dir; vector<int> loopSize; vector<vector<pair<int, int> > > loops; vector<vector<int> > loopNo; vector<vector<int> > loopNum; vector<...
7
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; int n, a[N]; long long p[N], sum[N]; double go(int mid, int k) { double ret = sum[n] - sum[n - k]; ret += sum[mid] - sum[mid - k - 1]; ret /= (2 * k + 1); ret -= a[mid]; return ret; } int main() { int i, j, k; cin >> n; for (i = 1; i <...
8
#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,tune=native") using namespace std; int n, m; int p[64], a[64][2], x[64]; long long dp[64][64][64][2]; void kmp(string &cad) { p[0] = 0; for (int i = 1; i < m; +...
10
#include <bits/stdc++.h> using namespace std; int c[1000007], n, m, ans[300005], maxi; struct node { int l, r, ind; } a[1000007]; int lowbit(int x) { return x & -x; } void add(int x) { while (x <= maxi) { c[x]++; x += lowbit(x); } } int sum(int x) { int s = 0; while (x > 0) { s += c[x]; x -= l...
7
#include <bits/stdc++.h> using namespace std; int n, ans, cnt[205], c[205], tmp[205], fa[205]; vector<int> con[205]; queue<int> q; bool vis[205]; void init() { int x, y; memset(cnt, 0, sizeof(cnt)); memset(fa, -1, sizeof(fa)); for (int i = 1; i <= n; i++) { con[i].clear(); scanf("%d", &c[i]); c[i]--...
4
#include <bits/stdc++.h> using namespace std; int main() { int t, k = 0, n, m, x1, y1, x2, y2, x, y; long long ans; scanf("%d", &t); while (k < t) { scanf("%d%d%d%d%d%d", &m, &n, &x1, &y1, &x2, &y2); x = x1 > x2 ? x1 - x2 : x2 - x1; y = y1 > y2 ? y1 - y2 : y2 - y1; if (m >= 2 * x) { if (n ...
5