solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> using namespace std; int main() { int n, l, v1, v2, k; scanf("%d%d%d%d%d", &n, &l, &v1, &v2, &k); double le = 0, ri = 1.0 * l / v1; for (int i = 0; i < 100; i++) { double t = 0; double d = l; int remain = n; bool fail = false; double tim = (le + ri) / 2.0; while ...
11
#include <bits/stdc++.h> using namespace std; bool myComp(pair<long long, long long>& p1, pair<long long, long long>& p2) { return (p1.first * p1.first + p1.second * p1.second) <= (p2.first * p2.first + p2.second * p2.second); } void Solve() { long long n; cin >> n; pair<long long, long long> a[n]; l...
8
#include <bits/stdc++.h> using namespace std; using ll = long long; using pll = pair<ll, ll>; template <typename T> using v = vector<T>; struct Fenwick { ll n; v<ll> arr; Fenwick(ll n_) : n(n_), arr(n_) {} ll get(ll r) { ll res = 0; for (; r >= 0; r = (r & (r + 1)) - 1) { res += arr[r]; } ...
16
#include <bits/stdc++.h> using namespace std; int main() { int row, col, k; cin >> row >> col >> k; for (int(i) = 0; (i) < (k); ++(i)) { int pr, pc; cin >> pr >> pc; if (min(min(pr - 1, pc - 1), min(row - pr, col - pc)) < 5) { cout << "YES" << endl; return 0; } } cout << "NO" << en...
11
#include <bits/stdc++.h> using namespace std; const long long int inf = 1e9 + 7; const long long int inf2 = inf * inf; priority_queue<long long int, vector<long long int>, greater<long long int>> mnheap; priority_queue<long long int> mxheap; long long int gcd(long long int x, long long int y) { if (x == 0) return...
5
#include <bits/stdc++.h> #pragma GCC optimize("-Ofast", "-funroll-all-loops") using namespace std; const int inf = 0x3f3f3f3f; const int N = 1e3 + 10, M = 1e6 + 10; int n, s, t, st[N], vis[N], maxf; int head[N], nex[M], to[M], flow[M], tot = 1; double w[M], d[M], x[N], y[N], cost; inline void ade(int a, int b, int c, d...
16
#include <bits/stdc++.h> using namespace std; int main() { int n, d, now = 1, can[101] = {}, sum = 0, cnt = 0; string s; scanf("%d%d", &n, &d); cin >> s; for (int i = 0; i < s.size(); i++) if (s[i] == '1') can[++cnt] = i + 1; int i = 1; while (i < cnt) { i++; if (can[i] > now + d) { cout...
0
#include <bits/stdc++.h> using namespace std; const long double eps = 1e-10; const int maxn = 1e5 + 10; struct Point { long double x, y; Point(long double a = 0, long double b = 0) : x(a), y(b) {} } p[maxn]; int tot, n; long double P, Q; Point st[maxn]; int top; long double cross(Point p0, Point p1, Point p2) { P...
16
#include <bits/stdc++.h> using namespace std; long long i, j, k, l, n, temp, len, ans; int ara[2000000]; char str[2000000]; int main() { scanf("%s", str); len = strlen(str); for (i = 0; i < len; i++) { ara[i] = str[i] - '0'; } if (len == 1) { cout << 0; return 0; } if (len == 2 && ara[1] == 0)...
5
#include <bits/stdc++.h> using namespace std; vector<int> Read(int n) { vector<int> vec(n); for (int i = 0; i < n; ++i) cin >> vec[i]; return vec; } vector<int> BuildDiffs(const vector<int>& a, int L) { vector<int> da; for (int i = 1; i < (int)a.size(); ++i) da.push_back(a[i] - a[i - 1]); da.push_back(L + a...
5
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9; int N, M; long long A[200010]; int main() { scanf("%d%d", &N, &M); for (int i = 0; i < N; i++) cin >> A[i]; for (; M--;) { int t; scanf("%d", &t); if (t == 1) { int x, v; scanf("%d%d", &x, &v); x--; A[x] =...
7
#include <bits/stdc++.h> using namespace std; const long long N = 3e5 + 15, INF = 1e9; long long n; long long dp[N][10]; vector<vector<long long>> a[N]; long long solve(long long i, long long j) { if (i == n) return 0; if (dp[i][j] != -1) return dp[i][j]; long long res = solve(i + 1, j); for (auto v : a[i]) { ...
13
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 5; const long long INF = 1e18 + 4; const long double eps = 1e-9; const long double pi = 3.1415926535897932384626433832795; int ans[maxn]; long long m; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.precision(20); int n; cin >> n...
9
#include <bits/stdc++.h> using namespace std; using INT = long long; using pii = pair<int, int>; int cnt[1100], vst[1100]; vector<pii> ans; int main() { int n; cin >> n; for (int i = 1; i < n; i++) { int a, b; cin >> a >> b; cnt[a]++; cnt[b]++; } if (cnt[n] != n - 1) { puts("NO"); retu...
11
#include <bits/stdc++.h> const int mod = 1000000007; struct modn { int n; modn() {} modn(long long x) { n = (x >= 0 ? x % mod : (x % mod + mod) % mod); } modn& operator-() { n = mod - n; return *this; } void print() const { printf("%d\n", n); } }; bool operator==(const modn& A, const modn& B) { retu...
10
#include <bits/stdc++.h> using namespace std; const long long MAX = 102; const long long N = 102; void f_io() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; } long long n, d; int32_t main() { f_io(); long long t = 1; while (t--) { cin >> n >> d; vector<long long> v(n); for (long long i ...
5
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 5; const long long mod = 1e9 + 7; const int oo = 1e9; set<int> s[101]; char mat[101][10000]; int n, m; int main() { scanf("%d%d", &n, &m); for (int i = 0; i < n; ++i) scanf("%s", mat[i]); for (int i = 0; i < n; ++i) { for (int j = 0; j < m; ++j...
7
#include <bits/stdc++.h> using namespace std; using ll = long long; ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); } ll lcm(ll a, ll b) { return (a * b) / gcd(a, b); } ll power(ll x, ll y) { ll temp; if (y == 0) return 1; temp = power(x, y / 2); if (y % 2 == 0) return temp * temp; el...
7
#include <bits/stdc++.h> using namespace std; int n, ls, d[111111], ans; string s; int main() { getline(cin, s); ls = s.length(); memset(d, 0, sizeof(d)); d[0] = (int)(s[0] >= 'a' && s[0] <= 'z'); for (int i = 1; i < ls; ++i) d[i] = d[i - 1] + (int)(s[i] >= 'a' && s[i] <= 'z'); ans = ls - d[ls - 1]; f...
6
// iostream is too mainstream #include <cstdio> // bitch please #include <iostream> #include <algorithm> #include <vector> #include <set> #include <map> #include <queue> #include <stack> #include <list> #include <chrono> #include <random> #include <cstdlib> #include <cmath> #include <ctime> #include <cstring> #include ...
18
#include <bits/stdc++.h> using namespace std; void fr() { freopen("a.in", "r", stdin); freopen("a.out", "w", stdout); } const int N = 3e5; const int INF = 1e9; const int mod = 1e6 + 3; const double pi = 3.1415926536; string s, t; set<char> vb; map<char, int> cnt1, cnt2; int ans; int main() { ios_base::sync_with_s...
4
#include <bits/stdc++.h> using namespace std; inline void maxm(int& a, int b) { a = a < b ? b : a; } inline void minm(int& a, int b) { a = a < b ? a : b; } int N; int A[100000]; int dp[100000][3]; int main() { ios_base::sync_with_stdio(false); cin >> N; for (int i = 0; i < N; i++) { cin >> A[i]; } dp[0][0...
10
#include <bits/stdc++.h> using namespace std; const int N = 100005; const int n = 100000; struct segtree { int tree[N * 4]; void update(int at, int L, int R, int indx, int val) { if (L == R) { tree[at] += val; if (tree[at] > 1) tree[at] = 1; return; } int mid = (L + R) >> 1; if (in...
8
#include <bits/stdc++.h> using namespace std; string row, col; const int MAX = 1e8 + 5; vector<vector<int> > adj; int fr[4001], n, m; bitset<MAX> rel; int main() { cin >> n >> m; adj.resize(n); int s, e; for (int i = 0; i < m; i++) { scanf("%d%d", &s, &e); s--; e--; fr[s]++; fr[e]++; if ...
7
#include <bits/stdc++.h> using namespace std; int main() { int n, count = 0; cin >> n; int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } sort(a, a + n); for (int i = 1; i < n - 1; i++) { if ((a[i] == a[0]) || (a[i] == a[n - 1])) { continue; } else { count++; } } cout <...
1
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; void solve(long long N) { long long K = (N / 4) % MOD; long long res = 0; if (N % 4 == 0 || N % 4 == 1) { res = (K + 1) * (K + 1); res %= MOD; } else { res = (K + 1) * (K + 2); res %= MOD; } cout << res << "\n"; } i...
16
#include <bits/stdc++.h> using namespace std; const int Maxx = 100005; inline int read() { int res = 0, bj = 0; char ch = getchar(); while (ch < '0' || ch > '9') bj |= (ch == '-'), ch = getchar(); while (ch >= '0' && ch <= '9') res = (res << 3) + (res << 1) + (ch ^ 48), ch = getchar(); return bj ? -res : ...
24
#include <bits/stdc++.h> using namespace std; template <typename T1, typename T2> inline void mine(T1 &x, const T2 &y) { if (y < x) x = y; } template <typename T1, typename T2> inline void maxe(T1 &x, const T2 &y) { if (x < y) x = y; } template <typename T> ostream &operator<<(ostream &os, const vector<T> &b) { f...
20
#include <bits/stdc++.h> const int Q = 256000; int dx[] = {-1, 1, 0, 0}, dy[] = {0, 0, -1, 1}; int N, M, K, a[110][110]; int bit[110][110], f[110][110][138], pre[110][110][138], vis[110][110]; struct point { int x, y, st; point() {} point(int _x, int _y, int _st) : x(_x), y(_y), st(_st) {} } q[256010]; int front,...
17
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int h, m; cin >> h >> m; cout << 1440 - h * 60 - m << endl; } return 0; }
0
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, k; string s; cin >> n >> k >> s; for (int i = 0; i < n; i++) { char c = (i || n == 1) ? '0' : '1'; if (k && s[i] != c) { s[i] = c; k--; } } cout << s << endl;...
2
#include <bits/stdc++.h> using namespace std; int profondeur(vector<int> vect, int pos) { int i = pos; int prof = 1; while (vect[i] != -1) { prof++; i = vect[i] - 1; } return prof; } int main() { int n; do { cin >> n; } while (n > 2000 || n < 1); vector<int> vect; int manager; for (int...
1
#include <bits/stdc++.h> using namespace std; int main() { int t; long long n; cin >> t; while (t--) { cin >> n; long long q = log2(n) + 1; long long p = pow(2, q) - 1; cout << n * (n + 1) / 2 - 2 * p << endl; } }
1
#include <bits/stdc++.h> using namespace std; struct _e { int x, y; long long w; } edges[2 * 200010]; bool cmp(struct _e e1, struct _e e2) { return e1.w < e2.w; } int n, m, mn = 1; long long cost; int link[200010]; long long p[200010]; int find(int x) { return x == link[x] ? x : link[x] = find(link[x]); } int main(...
11
#include <bits/stdc++.h> using namespace std; const int N = 200005; const long long inf = 1e18; int n, m, q, fa[50][N]; long long T[N], F[50][N]; struct node { int a, b, c, d; int id; } A[N]; vector<node> v; int cov[N << 2], tj[N << 2]; void clear_tree() { memset(cov, 0, sizeof(cov)); memset(tj, 0, sizeof(tj));...
16
#include <bits/stdc++.h> using namespace std; long long n, i; bool issost(int a) { if (a > 2 && a % 2 == 0) { return true; } else { int c = 0; for (int i = 3; i <= sqrt(a) + 1; i++) { if (a % i == 0) { c++; } if (c > 0) return true; } } return false; } int main() { ci...
0
#include <bits/stdc++.h> using namespace std; int main(void) { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; vector<int> s(n), t(n); for (int i = 0; i < (int)(n); ++i) cin >> s[i]; for (int i = 0; i < (int)(n); ++i) cin >> t[i]; vector<int> ps(n + 1), pt(n + 1); for (int i = 0; i <...
15
#include <bits/stdc++.h> using namespace std; const int N = 2e6 + 10, mod = 1e6; int a[N], Freq[N], k, n; long long x, y, Ans; vector<vector<pair<int, int> > > Fact[N]; vector<pair<int, int> > v; map<vector<pair<int, int> >, int> Freqq; long long POW(long long a, long long b) { if (b == 0) return 1ll; long long x =...
10
#include <bits/stdc++.h> const int M = 1e9 + 7; using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t; cin >> t; while (t--) { int n; cin >> n; vector<int> v; for (int i = 0; i < n; i++) { int x; cin >> x; v.push_back(x); } reverse(v...
1
#include <bits/stdc++.h> int n; int loc[110][2]; double hl[1001000][3]; int hn; double ans; bool trt(int i, int j, int k) { int da, db, dc, l; da = (loc[i][0] - loc[j][0]) * (loc[i][0] - loc[j][0]) + (loc[i][1] - loc[j][1]) * (loc[i][1] - loc[j][1]); db = (loc[k][0] - loc[j][0]) * (loc[k][0] - loc[j][0]) +...
18
#include <bits/stdc++.h> using namespace std; template <typename Arg1> void ZZ(const char* name, Arg1&& arg1) { std::cerr << name << " = " << arg1 << "\n"; } template <typename Arg1, typename... Args> void ZZ(const char* names, Arg1&& arg1, Args&&... args) { const char* comma = strchr(names + 1, ','); std::cerr.w...
4
#include <bits/stdc++.h> using namespace std; const int mod = 998244353; long long powM(long long a, int t = mod - 2) { long long ret = 1; while (t) { if (t & 1) ret = ret * a % mod; a = a * a % mod; t >>= 1; } return ret; } int n, t[200500]; void add(int p) { while (p <= n) { t[p]++; p +=...
15
#include <bits/stdc++.h> using namespace std; long long gcd(long long aa, long long bb) { if (aa == 0) return bb; return (bb % aa, aa); } int k; int n; int m; vector<vector<int> > ans; vector<pair<int, int> > a[200005]; int vis[200005]; int level[200005]; vector<int> x[200005]; int ca = 1; int aa[200005]; void find...
13
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e6 + 5; const int inf = 0x3f3f3f3f; struct Segment_Tree { int mn[MAXN << 2], tag[MAXN << 2]; inline void push_up(int u) { mn[u] = min(mn[((u) << 1)], mn[((u) << 1 | 1)]); } inline void push_down(int u) { mn[((u) << 1)] += tag[u]; tag[((...
18
#include <bits/stdc++.h> using namespace std; int CC; struct str { int L, P; char C[15]; bool operator<(const str& S) const { if (P > S.P) return true; if (P < S.P) return false; return (strcmp(C, S.C) < 0); } }; str G[101]; int GetPOS(char* A) { for (int p = (1); p <= (CC); p += (1)) if (strc...
7
#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...
22
#include <bits/stdc++.h> using namespace std; int a3[30], b3[30], c3[30]; int main() { int a, b, c, i, j; cin >> a >> c; i = 0; while (a > 0 || c > 0) { a3[i] = a % 3; a = a / 3; c3[i] = c % 3; c = c / 3; i++; } for (i = 0; i < 30; i++) for (j = 2; j >= 0; j--) if ((a3[i] + j) ...
3
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx") using namespace std; bool is_prime(int n) { for (int i = 2; i * i <= n; ++i) { if (n % i == 0) { return false; } } return true; } inline long long getPow(long long a, long long b) { ...
4
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; if (!(n & 1)) cout << "NO" << endl; else { int k = 0, p[2 * n + 1]; int a = 1; for (int i = 1; i <= n; i++) { k++; p[k] = a; a++; int add = (i & 1) ? n : -...
4
#include <bits/stdc++.h> using namespace std; template <class Read> void in(Read &x) { x = 0; int f = 0; char ch = getchar(); while (ch < '0' || ch > '9') { f |= (ch == '-'); ch = getchar(); } while (ch >= '0' && ch <= '9') { x = (x << 1) + (x << 3) + (ch ^ 48); ch = getchar(); } x = f ?...
14
#include <bits/stdc++.h> using namespace std; struct SuffixArray { const int L; string s; vector<vector<int> > P; vector<pair<pair<int, int>, int> > M; SuffixArray(const string &s) : L(s.length()), s(s), P(1, vector<int>(L, 0)), M(L) { for (int i = 0; i < L; i++) P[0][i] = int(s[i]); for (int sk...
10
#include <bits/stdc++.h> using namespace std; char a[100010], b[100010], c[100010]; int d[1010]; int main() { int n, res = 0; memset(d, 0, sizeof(d)); scanf("%s", a); getchar(); for (int i = 0; i < strlen(a); i++) { d[a[i]] = 1; } scanf("%s", b); getchar(); for (int i = 0; i < strlen(b); i++) { ...
8
#include <bits/stdc++.h> using namespace std; long long int maxx, l, k, minn, w, d, n, m, x, z, g[100001], y, c[100001], a[100001], b[100001], p; string s; bool mark[100001]; long long int f(long long int n) { while (n % 3 == 0) n = n / 3; while (n % 2 == 0) n = n / 2; return n; } int main() { ios::sync_wit...
5
#include <bits/stdc++.h> using namespace std; const int inf = 1000000007; const long long linf = 1LL << 62; const unsigned long long ulinf = 1ULL << 63; const double eps = 0.000001; const double pi = 3.14159265358979323846; template <class T> T abs(T a) { return a >= 0 ? a : -a; } template <class T> T sqr(T a) { re...
20
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf("%d", &n); long long int a = 0ll, b; for (int i = 0; i < n; i++) { scanf("%I64d", &b); a += (b - 1ll); if (a % 2ll == 0ll) { printf("2\n"); a = 0ll; } else { printf("1\n"); a = 1ll; } } return...
3
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; const long long INF = 2e9 + 10; const long double EPS = 1e-9; const int N = 1e6 + 2; long long solve(long long n) { if (n <= 4) return n - 1; long long t = (2 * n + 1 - sqrt(8 * n + 1)) / 2; long long ans = 0; for (long long i = -2; i ...
13
#include <bits/stdc++.h> using namespace std; int a[100005]; int n; long long s1, s2; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d", &a[i]); sort(a + 1, a + 1 + n); s1 = s2 = 0; for (int i = 1; i <= n / 2; i++) s1 += a[i]; for (int i = n / 2 + 1; i <= n; i++) s2 += a[i]; cout << s1...
1
#include <bits/stdc++.h> using namespace std; const int maxn = 1005; int n, m; int mat[maxn][maxn]; int poz[maxn][maxn]; int dp[maxn]; int main() { cin >> n >> m; for (int j = 1; j <= m; j++) { for (int i = 1; i <= n; i++) { cin >> mat[j][i]; int x = mat[j][i]; poz[j][x] = i; } } for (...
11
#include <bits/stdc++.h> using namespace std; int main() { int a, c; cin >> a; c = a; a /= 10; if (c - a * 10 <= (a + 1) * 10 - c) cout << a * 10 << "\n"; else cout << (a + 1) * 10; return 0; }
0
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf("%d", &n); int a[n]; for (int i = 0; i < n; ++i) scanf("%d", &a[i]); if (n < 2) puts("-1"); else if (n == 2) { if (a[0] == a[1]) puts("-1"); else { printf("1\n1"); } } else { int min = 2000, ans; fo...
2
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; int a[N], n, s[N], flag; int process() { cout << "ambiguous" << '\n'; cout << 0 << ' '; for (int i = 1; i <= n; i++) for (int j = 1; j <= a[i]; j++) cout << s[i - 1] << ' '; cout << '\n'; cout << 0 << ' '; for (int i = 1; i <= n; i++) ...
7
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false), cin.tie(nullptr); int t; cin >> t; while (t--) { long long n; cin >> n; vector<long long> v(n); for (auto &p : v) { cin >> p; } vector<long long> ans; sort(v.begin(), v.end()); reverse(v...
2
#include <bits/stdc++.h> const int N = 500000; int read() { int x = 0, ch = getchar(); while( ch > '9' || ch < '0' ) ch = getchar(); while( '0' <= ch && ch <= '9' ) x = 10 * x + ch - '0', ch = getchar(); return x; } std::map<int, int>mp; int deg[N + 5], n, m, c; int tag[N + 5], u[N + 5], v[N + 5]; std::vector<in...
15
#include <bits/stdc++.h> using namespace std; int main() { unsigned long long a, b; cin >> a >> b; if (a < b || (a - b) % 2 == 1) { cout << "-1"; } else { cout << (a - b) / 2 << " " << a - (a - b) / 2; } return 0; }
9
#include <bits/stdc++.h> using namespace std; int n, ans, flag; int a[100005], b[100005], xb[100005]; int solve() { int i, j, ma; ans = -1; b[1] = xb[1] = 0; for (i = 2; i <= n; i++) { ma = 0; flag = 0; j = i - 1; while (a[j] < a[i] && j) { if (!b[j]) { flag = 1; break; ...
11
#include <bits/stdc++.h> using namespace std; const int maxn = 2 * 1e5 + 11; int t; int n; string s; int d[maxn]; void solve() { for (int i = 1; i <= n; i++) d[i] = (s[i - 1] - '0'); for (int split = 0; split <= 9; split++) { bool ok = true; int col[maxn] = {0}; int ri = -1; for (int i = 1; i <= n; ...
7
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int a, b; cin >> a >> b; vector<int> v; while (1) { if (b < a) { cout << "NO"; return 0; } if (b == a) { cout << "YES" << endl; v.push_back(b); break; } ...
2
#include <bits/stdc++.h> using namespace std; int X = 1000000005, H[1005], W[1005], N; int g(int h, int k, int w) { priority_queue<int> q; for (int i = 1; i <= N; i++) { if (W[i] <= h && H[i] <= h) q.push(W[i] - H[i]), w += W[i]; else if (W[i] <= h && k) k--, w += H[i]; else if (H[i] <= h) ...
11
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e5 + 123; int main() { long long n; cin >> n; int total = 0; while (n) { if (n % 8 == 1) total++; n /= 8; } cout << total << endl; return 0; }
13
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); vector<bool> sieve(3000000, true); sieve[0] = false; sieve[1] = false; for (int i = 2; i <= 2000; i++) { if (!sieve[i]) continue; int sum = i + i; while (sum <= 2000000) { sieve[sum] = false; sum +=...
10
#include <bits/stdc++.h> using namespace std; int main() { long long int n, input; cin >> n; long long int sumx = 0, sumy = 0, sumz = 0, x, y, z; for (int i = 0; i < n; i++) { cin >> x >> y >> z; sumx += x; sumy += y; sumz += z; } sumx == 0 && sumy == 0 && sumz == 0 ? cout << "YES" : cout <<...
2
#include <bits/stdc++.h> using namespace std; template <class T> inline T min(T &a, T &b) { return a < b ? a : b; } template <class T> inline T max(T &a, T &b) { return a > b ? a : b; } template <class T> void read(T &x) { char ch; while ((ch = getchar()) && !isdigit(ch)) ; x = ch - '0'; while ((ch = ge...
16
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int n, x; cin >> n >> x; long long t = 0; vector<long long> cs; for (int i = 0; i < n; i++) { int c; cin >> c; cs.push_back(c); } sort(cs.begin(), cs.end()); ...
4
#include <bits/stdc++.h> using namespace std; #pragma comment(linker, "/stack:200000000") #pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") template <typename T> bool mmax(T &m, const T q) { if (m < q) { m = q; return true; } else return false; }...
10
#include <bits/stdc++.h> using namespace std; long long INF = (1LL << 62); const int inf = (1LL << 30); const int maxn = (int)1e5 + 5; const int MOD = 1000000007; int arr[maxn]; int li[maxn]; int ld[maxn]; int main() { ios_base::sync_with_stdio(false); int n; cin >> n; for (int i = 0; i < n; ++i) cin >> arr[i];...
8
#include <bits/stdc++.h> #define X first #define Y second #define sz(a) (int)a.size() #define pb push_back using namespace std; void solve(); signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t = 1; //cin >> t; while (t--) solve(); return 0; } int mxdep[10001...
23
#include <bits/stdc++.h> const long long INF = 1e18; using namespace std; void SOE(long long n) { bool isPrime[n + 1]; memset(isPrime, true, sizeof(isPrime)); for (long long p = 2; p <= n; p++) { if (isPrime[p]) { for (long long i = p * p; i <= n; i += p) isPrime[i] = false; } } } long long POWER(...
6
#include <bits/stdc++.h> using namespace std; vector<long long int> v[500001]; long long int col[500001]; int main() { ios::sync_with_stdio(false); ; cin.tie(0); ; long long int i, j, n, m, deg, x, y, f; cin >> n >> m; for (i = 1; i <= m; i++) { cin >> x >> y; v[x].push_back(y); v[y].push_back...
14
#include <bits/stdc++.h> using namespace std; bool belong(int x, vector<int> &a) { for (int i = 0; i < a.size(); i++) { if (a[i] == x) { return true; } } return false; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); unsigned long long t, s, a, b, c; ci...
0
#include <bits/stdc++.h> using namespace std; const int MAXN = 100005; int n; long long a[MAXN], x, x1, x2, g[65]; bool f[65], r[65][MAXN], h[65], flag, ans[MAXN]; void Change(long long x, int id, int pos) { r[pos][id] = 1; for (int i = 61; i >= 0; i--) if (!f[i] && (((1LL << i) & x))) { if (g[i]) { ...
19
#include <bits/stdc++.h> using namespace std; const int M = 1e9 + 7; long long phi(long long x) { long long t = x; for (long long i = 2ll; i * i <= x; ++i) { if (x % i == 0) { t -= t / i; while (x % i == 0) x /= i; } } if (x > 1) t -= t / x; return t; } int main() { long long n, k; cin...
13
#include <bits/stdc++.h> using namespace std; #define ll long long int #define ub upper_bound #define lb lower_bound #define pb push_back int main() { int t; cin>>t; while(t--) { int n; cin>>n; ll arr[n]; for(int i=0;i<n;i++) cin>>arr[i]; ll dp[n]; memset(...
3
#include <bits/stdc++.h> using namespace std; int a[505], f[505][505] = {0}; int main(void) { int i, j, k, n, m, T, mod, ans = 0; scanf("%d%d%d%d", &n, &m, &T, &mod); for (i = 1; i <= n; ++i) scanf("%d", &a[i]); f[0][0] = 1; for (i = 1; i <= n; ++i) { for (j = 1; j <= m; ++j) { for (k = a[i]; k <= T...
10
#include <bits/stdc++.h> using namespace std; const int oo = 998244353; const int N = 200010; int a[N]; long long s[N], inv[N]; int main() { int n, m; scanf("%d%d", &n, &m); for (int i = 1; i <= n; ++i) scanf("%d", a + i); sort(a + 1, a + n + 1); for (int i = 1; i <= n; ++i) s[i] = s[i - 1] + a[i]; inv[1] =...
16
#include <bits/stdc++.h> using namespace std; inline int read() { int ans = 0; char ch = getchar(); while (!isdigit(ch)) ch = getchar(); while (isdigit(ch)) ans = (ans << 3) + (ans << 1) + (ch ^ 48), ch = getchar(); return ans; } vector<int> ans; int k; int main() { k = read() + 1; int ttmp, tmp = 1; wh...
12
#include<bits/stdc++.h> // #include<boost/multiprecision/cpp_int.hpp> // using namespace boost::multiprecision; using namespace std; #define ll long long #define ld long double #define i1 int128_t #define vl vector<long long> #define vi vector<int> #define sl set<long long> #define si set<int> #define uset unordered_se...
3
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int tc; cin >> tc; while (tc--) { string s; cin >> s; long long int cnt = 0; vector<long long int> V; for (long long int i = 0; i < s.size(); i++) { if (s[i] ...
0
#include <bits/stdc++.h> using namespace std; int bf(int x) { vector<int> a; while (x != 0) { if (x % 10 == 4 || x % 10 == 7) a.push_back(x % 10); x /= 10; } long long int temp = 1, ans = 0; for (long long int i = 0; i < a.size(); i++) { ans += a[i] * temp; temp *= 10; } return ans; } int ...
5
#include <bits/stdc++.h> using namespace std; const int MAX_N = 100000 + 20; vector<int> adj[MAX_N]; int mark[MAX_N]; int lvl[MAX_N]; vector<pair<int, pair<int, int> > > ans; int n, m; void readInput() { cin >> n >> m; for (int i = 0; i < m; i++) { int v, u; cin >> v >> u; --v, u--; adj[v].push_back...
15
#include <bits/stdc++.h> inline int in() { int k = 0, p = 1; char ch = getchar(); while (!isdigit(ch) && ch != '-') ch = getchar(); if (ch == '-') p = 0, ch = getchar(); while (isdigit(ch)) k = k * 10 + ch - '0', ch = getchar(); return p ? k : -k; } inline int min(const int &a, const int &b) { return a < b ...
21
#include <bits/stdc++.h> const int MAXN = 3100; const int INF = 0x7F7F7F7F; struct Tedge { int p, f, next; }; int n; int a[MAXN]; int f[MAXN], fv[MAXN]; int q[MAXN]; int dp0[MAXN], dp1[MAXN], dp2[MAXN]; Tedge edge[MAXN * 2]; int min(int x, int y) { return x < y ? x : y; } void init() { scanf("%d", &n); int i, u, ...
13
#include <bits/stdc++.h> int main() { int n1, n2, n3 = 0; std::cin >> n1 >> n2; std::vector<std::vector<int>> v1(n1, std::vector<int>(n2)); for (int i = 0; i < n1; i++) for (int j = 0; j < n2; j++) std::cin >> v1[i][j]; auto f1 = [&](int y, int x) { int i = y, j = x - 1; while (j >= 0 && !v1[i][j]...
4
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; vector<int> v; int i = 1; int j = n; while (i <= j) { v.push_back(i); if (i == j) { break; } v.push_back(j); ++i; --j; } if (v[k - 1] > v[k]) { sort(v.begin() + k, v.end(), greater<int>(...
4
#include <bits/stdc++.h> using namespace std; int rec(int n) { for (int i = n / 2; i > 1; --i) { if (n % i == 0) { return rec(i) + i; } } return 1; } int main() { long int n; cin >> n; cout << rec(n) + n; }
2
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; const int maxn = 2e5 + 9; const int inf = 0x3f3f3f3f; long long rd() { long long ans = 0; char last = ' ', ch = getchar(); while (!(ch >= '0' && ch <= '9')) last = ch, ch = getchar(); while (ch >= '0' && ch <= '9') ans = ans * 10 + ch ...
10
#include <bits/stdc++.h> using namespace std; inline long long rd() { long long x = 0; int ch = getchar(), f = 1; while (!isdigit(ch) && (ch != '-') && (ch != EOF)) ch = getchar(); if (ch == '-') { f = -1; ch = getchar(); } while (isdigit(ch)) { x = (x << 1) + (x << 3) + ch - '0'; ch = getch...
14
#include <bits/stdc++.h> using namespace std; const long long N = 500005; long long n, cnt, head[N], diam, st[N], top, cir[N], dis[N]; long long tot, vis[N], huan[N], stw[N], w[N], ls[N], rs[N], lmx[N], rmx[N]; struct Edge { long long v, nx, s; } e[1000005]; inline long long read() { long long ret = 0, ff = 1; ch...
17
#include <bits/stdc++.h> using namespace std; inline long long in() { long long x = 0; bool f = 0; char c; for (; (c = getchar()) < '0' || c > '9'; f = c == '-') ; for (x = c - '0'; (c = getchar()) >= '0' && c <= '9'; x = (x << 3) + (x << 1) + c - '0') ; return f ? -x : x; } priority_queue<pa...
21
#include <bits/stdc++.h> using namespace std; const int N = 5e5 + 5; struct node { pair<bool, int> l[2], r[2]; int mx[2], le, ri; bool flip; } em; vector<node> d(4 * N); string second; node merge(node a, node b) { if (a.mx[0] == -1) return b; if (b.mx[0] == -1) return a; node sol; for (int i = 0; i < 2; i...
20
#include <bits/stdc++.h> using namespace std; int n, now = 0, num[65] = {0}, two[65] = {0}, ans[100005]; bool ok(int x) { int t = two[0] - x; for (int i = 1; i <= now; i++) { if (x >= two[i]) { t -= min(x - two[i], t); x = two[i]; } else t += two[i] - x; t += num[i]; } if (t <= x) ...
14