solution
stringlengths
53
181k
difficulty
int64
0
13
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; cin >> n; vector<long long> v(n); for (auto &it : v) cin >> it; long long ans = v[n - 1]; long long prev = v[n - 1]; for (int i = n - 2; i >= 0; i--) { long long x = min(p...
1
#include <bits/stdc++.h> long long ans, f[100010], i, tot, g[100010], a, b, c, n, j; void exgcd(long long a, long long b, long long &x, long long &y) { long long t; if (b == 0) { x = 1; y = 0; return; } exgcd(b, a % b, x, y); t = x; x = y; y = t - a / b * y; } long long cnt(int a, int b) { l...
6
#include <bits/stdc++.h> using namespace std; int main() { cin.tie(NULL); ios_base::sync_with_stdio(false); long long n, T, i, j, k, ct, cn = 1, nn, r = 0; cin >> n >> T; ct = T; vector<long long> t(n), q(n); for (i = 0; i < n; ++i) { cin >> t[i] >> q[i]; } for (i = 0; i < n; ++i) { for (j = 0...
6
#include <bits/stdc++.h> #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math") using namespace std; template <class T> using rque = priority_queue<T, vector<T>, greater<T>>; template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } template <class T> b...
7
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") template <typename T1, typename T2> inline void mine(T1& x, T2 y) { if (y < x) x = y; } template <typename T1, typename T2> inline void maxe(T1& x, T2 y) { if (x < y) x = y; } template <typename T1, typename T2> inline bool ...
10
#include <bits/stdc++.h> using std::vector; namespace IO_base { const int MAXB = 1 << 10; char gbuf[MAXB], *ps = gbuf, *pt = gbuf; inline char Getchar() { if (ps == pt) { ps = gbuf; pt = gbuf + fread(gbuf, 1, MAXB, stdin); } return (ps == pt) ? EOF : *ps++; } } // namespace IO_base namespace IO_number { ...
7
#include <bits/stdc++.h> using namespace std; bool ok(int n, int m) { bool vis[11]; memset(vis, 0, sizeof(vis)); char nn[11], mm[11]; sprintf(nn, "%d", n); for (int i = 0; nn[i]; i++) { vis[nn[i] - '0'] = true; } sprintf(mm, "%d", m); for (int i = 0; mm[i]; i++) { if (vis[mm[i] - '0']) return tr...
2
#include <bits/stdc++.h> using namespace std; inline long long read() { long long x = 0, f = 1; char c = getchar(); while ((c < '0' || c > '9') && (c != '-')) c = getchar(); if (c == '-') f = -1, c = getchar(); while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar(); return x * f; } const int N = 1...
9
#include <bits/stdc++.h> using namespace std; const int MAX = 1000005; const double eps = 1e-11; const long long oo = 1e11 + 7; const int mod = 1e9 + 7; long long n, v[MAX]; long long dp0[MAX], dp1[MAX]; vector<int> g[MAX]; void dfs(int node) { long long sum = 0; long long par = 0, impar = 0, ipar, iipar; for (in...
6
#include <bits/stdc++.h> using namespace std; bool isprime(long long n) { for (long long i = 2; i <= sqrt(n); i++) { if (n % i == 0) return false; } return true; } bool prm[10000007]; long long N = 10000000; void sieve() { prm[1] = 1; for (long long i = 2; i <= sqrt(N); i++) { if (prm[i] == 0) { ...
4
#include <bits/stdc++.h> using namespace std; void _print(long long t) { cerr << t; } void _print(int t) { cerr << t; } void _print(string t) { cerr << t; } void _print(char t) { cerr << t; } void _print(long double t) { cerr << t; } void _print(double t) { cerr << t; } void _print(unsigned long long t) { cerr << t; } ...
1
#include <bits/stdc++.h> static long long int INF = 1e9 + 7; using namespace std; template <typename T> bool comp(T a, T b) { if (a < b) return true; return false; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ; int n; cin >> n; vector<int> v(1000001, 0); int two = 0, four = 0; for...
3
#include <bits/stdc++.h> using namespace std; const double dinf = 1e200; void mytimer(string task) {} void ext(int c) {} int main() { ios_base::sync_with_stdio(false); int n, m; cin >> n >> m; for (int i = 0; i < (n); ++i) { int a, b, t; cin >> a >> b >> t; if (a == b) { cout << t << '\n'; ...
2
#include <bits/stdc++.h> using namespace std; int main() { int x, y, z; cin >> x >> y >> z; if ((x > y) && ((x - y) > z)) { cout << "+"; } else { if ((x < y) && ((y - x) > z)) { cout << "-"; } else { if ((x == y) && (z == 0)) { cout << "0"; } else { cout << "?"; ...
0
#include <bits/stdc++.h> using namespace std; long long n, cnt[5], res; string a, b; int main() { cin >> n; cin >> a >> b; for (int i = 0; i < n; ++i) ++cnt[a[i] - '0']; for (int i = 0; i < n; ++i) { if (b[i] == '0') { if (a[i] == '0') res += cnt[1]; else res += cnt[0]; --c...
2
#include <bits/stdc++.h> using namespace std; inline long long read() { char c = getchar(); long long x = 0; bool f = 0; for (; !isdigit(c); c = getchar()) f ^= !(c ^ 45); for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48); if (f) x = -x; return x; } long long n, m; struct edge { long ...
7
#include <bits/stdc++.h> using namespace std; vector<int> A, P; int ans; struct node { struct node *a[2]; int cnt; }; struct node *get_n() { struct node *tmp = new node; for (int i = 0; i < 2; i++) tmp->a[i] = NULL; tmp->cnt = 0; return tmp; } void inser(struct node *root, string s) { struct node *tmp = r...
5
#include <bits/stdc++.h> using namespace std; inline long long input() { int32_t x; scanf("%d", &x); return x; } inline long long in() { int32_t x; scanf("%d", &x); return x; } const long long maxn = 2e5 + 10; const long long mod = 1e9 + 7; long long a[maxn], b[maxn]; int32_t main() { long long n = in(); ...
0
#include <bits/stdc++.h> using namespace std; template <class T> T extgcd(T a, T b, T& x, T& y) { for (T u = y = 1, v = x = 0; a;) { T q = b / a; swap(x -= q * u, u); swap(y -= q * v, v); swap(b -= q * a, a); } return b; } template <class T> T mod_inv(T a, T m) { T x, y; extgcd(a, m, x, y); ...
7
#include <bits/stdc++.h> using namespace std; int f(int x1, int y1, int x2, int y2, int x, int y) { return ((long long)(x2 - x1) * (long long)(y - y1) - (long long)(y2 - y1) * (long long)(x - x1) > 0); } int main() { int n, vx[100010], vy[100010], a[100010], k[100010], t, p, x, y; long lon...
8
#include <bits/stdc++.h> using namespace std; int n, d, ans[5005], son[5005], dep[5005]; int main() { int T; cin >> T; while (T--) { scanf("%d%d", &n, &d); int log = 0, mn = 0; for (int i = 0; (1 << (i + 1)) - 1 <= n; ++i) { log = i; mn += (1 << i) * i; } mn += (n - (1 << (log + 1)...
7
#include <bits/stdc++.h> using namespace std; const int N = (int)1e5 + 17; const int MX = (int)1e6 + 17; const int MOD = (int)1e9 + 7; const long long oo = LLONG_MAX; const int INF = INT_MAX; const long double Pi = 3.14159265358979323846264338327950288419716939937510; const int di[4] = {-1, 0, 1, 0}; const int dj[4] = ...
6
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 20; long long int n, a[N], b[N], sum1, sum2; int main() { cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; sum1 += a[i]; } for (int i = 0; i < n; i++) { cin >> b[i]; } sort(b, b + n); reverse(b, b + n); sum2 = b[0] + b[1];...
0
#include <bits/stdc++.h> using namespace std; const int N = int(3e5) + 9; int n; long long a[N]; int b[N]; int cnt[2][N]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n; for (int i = 0; i < n; ++i) { cin >> a[i]; b[i] = __builtin_popcountll(a[i]); } long long res = 0; int s...
6
#include <bits/stdc++.h> using namespace std; template <class T> inline void rd(T &x) { int fl = 1; x = 0; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == '-') fl = -fl; for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + c - '0'; x *= fl; } template <class T> inline void wr(T x)...
0
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; int a[1000], kol = 1; a[0] = -10; for (int i = 0; i < s.size(); ++i) if (s[i] == '@') if (i - a[kol - 1] < 3) cout << "No solution", exit(0); else a[kol++] = i; for (int i = kol - 2; i > 0; --i) s....
3
#include <bits/stdc++.h> using namespace std; vector<pair<long long, int> > del1, del2, del3, del4; long long n1, p, q, r, mn = -1, mx = -1; void rec_find2(int n) { int i, j, sz, sz2; long long tmp; if (n == (int)del2.size()) { p = q = r = 1; sz = del2.size(); for (i = 0; i < sz; i++) { for (j =...
4
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") using namespace std; void fileio(const string &s) { freopen((s + ".in").c_str(), "r", stdin); freopen((s + ".out").c_str(), "w", stdout); } inline int read() { int x = 0; bool flag = 1; char c = getchar(); while (c < '0' || c > '9') { if (c == '-') ...
7
#include <bits/stdc++.h> using namespace std; const long long inf = 1e18; const long long mod = 1e9 + 7; const long long N = 5e5 + 10; void solve() { long long n; string s, t = "hard"; cin >> n >> s; vector<long long> a(n); for (long long i = 0; i < n; ++i) cin >> a[i]; vector<vector<long long> > dp(n + 10,...
5
#include <bits/stdc++.h> using namespace std; const int INF = 2000000009; const int Max = 1000007; const double PI = acos(-1.0); int trck[6]; int main() { int i, j, k, l, temp, t, n, m, caseno = 0, ans; string str; while (cin >> n) { memset(trck, 0, sizeof(trck)); for (i = 0; i < n; i++) { cin >> k;...
1
#include <bits/stdc++.h> using namespace std; int main() { int n, l = 0; cin >> n; for (int i = 0; i < n; i++) { cout << l; if (l) { l = 0; } else { l = 1; } } return 0; }
2
#include <bits/stdc++.h> using namespace std; template <class T> bool ckmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; } template <class T> bool ckmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; } namespace debug { void __print(int x) { cerr << x; } void __print(long long x) { cerr << x; } void __print(d...
5
#include <bits/stdc++.h> using namespace std; int n; long long int have; long long int c[100002]; long long int w[100002]; priority_queue<pair<pair<long long int, int>, long long int>, vector<pair<pair<long long int, int>, long long int> >, greater<pair<pair<long long int, int>, long long ...
8
#include <bits/stdc++.h> #include <stdlib.h> using namespace std; typedef long long int ll; typedef long double ld; #define rep(i,a,b) for(ll i=a;i<=b;++i) #define rev(i,a,b) for(ll i=a;i>=b;i--) #define pll pair<ll,ll> #define vll vector<ll> #define sll set<ll> #define vpll vector<pll> #define F first #define S ...
7
#include <bits/stdc++.h> using namespace std; const double pi = 3.14159265358979323846, eps = 0.000001; const long long M = 1e9 + 7, I = 1e18; const int mxn = 1e6, mxn1 = 1e7, lg = 20; long long arr[mxn + 1], ans[mxn + 1]; int l = 0, r; bool vis[mxn + 1]; vector<long long> smp; int main() { ios_base::sync_with_stdio(...
4
#include <bits/stdc++.h> #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") using namespace std; namespace IO { template <class A, class B> ostream &operator<<(ostream &out, pair<A, B> a) { out << a.first << " " << a.second; return out; } template <class A, class B> ostream &operator<<(ostream &out, ve...
1
#include <bits/stdc++.h> using namespace std; long long ch(long long a[], long long n) { for (long long i = 0; i < n - 1; i++) { if (a[i + 1] < a[i]) return 0; } return 1; } bool comp(const pair<long long, long long> &a, const pair<long long, long long> &b) { if (a.second != b.second) return (a.se...
1
#include <bits/stdc++.h> using namespace std; int n, x, y; map<pair<int, int>, bool> m; int main() { cin >> n; for (int i = 0; i < n; i++) { cin >> x >> y; m[make_pair(x, x + y)] = true; } for (map<pair<int, int>, bool>::iterator it = m.begin(); it != m.end(); it++) { bool c = it->second; ...
1
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; cout << 2 * n - 1 << " 2" << endl << 1 << " " << 2 << endl; return 0; }
3
#include <bits/stdc++.h> using namespace std; const int maxn = 100100; long long seg[maxn << 2]; long long A[maxn]; long long tmp[maxn]; long long id[maxn]; map<long long, int> M; const double PI = acos(-1); void PushUp(int rt) { seg[rt] = max(seg[rt << 1], seg[rt << 1 | 1]); } void update(int p, long long x, int l, in...
6
#include <bits/stdc++.h> using namespace std; using LL = int64_t; const int INF = 0x3f3f3f3f; int main() { ios::sync_with_stdio(0); cin.tie(0); int n, m, k; cin >> n >> m >> k; vector<int> ans(105, 0); for (int i = 1; i <= n; i++) cin >> ans[i]; int sum = 10; for (int i = 1; i <= n; i++) { if (m - i...
0
#include <bits/stdc++.h> using namespace std; using pii = pair<int, int>; using ll = long long; class Solver { int p; public: Solver() { cin >> p; } public: void solve() { cout << 2 << " " << p - 1 << "\n"; } }; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t; cin >> t; while (t-...
0
#include <bits/stdc++.h> using namespace std; char s[3][100005]; int len_short, len_long, b[100005]; void preprocess(char *s1) { int i = 0, j = -1; b[0] = -1; while (i < len_short) { while (j >= 0 && s1[i] != s1[j]) j = b[j]; i++; j++; b[i] = j; } } char ans[3 * 100005]; void kmp(char *s1, char ...
7
#include <bits/stdc++.h> using namespace std; vector<int> prime, power; long long N; long long exgcd(long long a, long long b, long long& x, long long& y) { if (b == 0) { x = 1; y = 0; return a; } long long g = exgcd(b, a % b, x, y); long long t = x; x = y; y = t - (a / b) * y; return g; } int...
5
#include <bits/stdc++.h> using namespace std; int i, j, n, k, y, q; long long arb[800005], a[200005], aux, rs, gmb, x; void update(int left, int right, int nod) { if (left == right) arb[nod] = y; else { int pivot = (left + right) / 2; if (x <= pivot) update(left, pivot, 2 * nod); else up...
4
#include <bits/stdc++.h> using namespace std; const long long int MOD = 1000000007; int main() { ios_base::sync_with_stdio(false), cin.tie(NULL); int n, i; cin >> n; string s; cin >> s; int bracket0 = 0, bracket1 = 0; for (i = 0; i < n; i++) { if (s[i] == '(') { if (bracket0 > bracket1) { ...
3
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { long long n, k; cin >> n >> k; long long ans = k; long long q = 0; long long p = 0; for (int i = 0;; i++) { if (ans / n == p / n) break; q = p; p = ans; ans += ans / n - q / n;...
2
#include <bits/stdc++.h> using namespace std; int main() { int n, a, b, c; cin >> n >> a >> b >> c; n--; if (!n) puts("0"); else { int m = min(a, b); cout << m + (n - 1) * (min(c, m)) << endl; } }
0
#include <bits/stdc++.h> template <typename T> inline void read(T &x) { x = 0; char c = getchar(); while (!isdigit(c)) c = getchar(); while (isdigit(c)) x = x * 10 + (c ^ 48), c = getchar(); } using namespace std; int n; int h[501000]; inline bool cmp(const int x, const int y) { return x > y; } priority_queue<i...
11
#include <bits/stdc++.h> using namespace std; int main(void) { long long int i, n, f; string s; cin >> s; n = s.length(); map<char, long long int> m; for (i = 0; i < n; i++) { m[s[i]]++; } if (m.size() == 1 || m.size() > 4) { cout << "No" << endl; } else if (m.size() == 2) { f = 0; for...
3
#include <bits/stdc++.h> using namespace std; int col[505]; pair<int, int> mn[505][505]; pair<int, int> min(pair<int, int> a, pair<int, int> b) { if (a.first < b.first) return a; return b; } long long memo[505][505]; long long dp(int l, int r) { if (l == r) return 1; if (memo[l][r] != -1) return memo[l][r]; i...
7
#include <bits/stdc++.h> using namespace std; const int N = 5e5 + 9; int st[N], en[N], a[N], par[N], rid[N], root[N]; struct ST { pair<int, int> t[4 * N]; void build(int n, int b, int e) { if (b == e) { t[n] = {0, b}; return; } int mid = (b + e) >> 1, l = n << 1, r = l | 1; build(l, b, m...
9
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; if (n == 1 || n == 2) { cout << n; return 0; } long long ans; if (n % 2 == 0 && n % 3 == 0) ans = (n - 1) * (n - 2) * (n - 3); else if (n % 2 == 0 && n % 3 != 0) ans = (n) * (n - 1) * (n - 3); else ans ...
4
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int T; cin >> T; while (T--) { int n, i, j, k; cin >> n; int a[n]; vector<pair<int, int>> v; for (i = 0; i < n; i++) { cin >> a[i]; v.push_back({a[i], i...
0
#include <iostream> #include <string> #include <sstream> #include <iomanip> #include <math.h> #include <stdio.h> #include <string.h> #include <queue> #include <stack> #include <vector> #include <map> #include <set> #include <functional> #include <algorithm> #include <unordered_map> #include <unordered_set> #include <n...
4
#include <bits/stdc++.h> using namespace std; const long long inf = 1e18; const int N = 5e2 + 3; const long long p = 998244353; int n; long long a[N]; map<long long, long long> prime; set<long long> s; std::vector<long long> v; long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } double eps = ...
6
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int t; cin >> t; for (int i = 0; i < t; i++) { long long n, k; cin >> n >> k; if (n < k * k) { cout << "NO" << '\n'; } else if (n % 2 != k % 2) { cout << "NO" << '\n'; } else { ...
1
#include <bits/stdc++.h> #pragma GCC optimize("O3") #pragma GCC target("sse4") using namespace std; template <class T> using pq = priority_queue<T>; template <class T> using pqg = priority_queue<T, vector<T>, greater<T>>; template <class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; } template <class...
0
#include <bits/stdc++.h> using namespace std; int n, m; int dp[30005][505]; int gems[200005]; int max1; int m2; int fun(int pos, int prev1) { if (pos > max1) { return 0; } if (dp[pos][prev1] != -1) { return dp[pos][prev1]; } int ret = gems[pos]; int req = prev1 - 250 + m; if ((pos + req) <= max1) ...
5
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; inline long long pow(long long a, long long b) { if (b == 1) return a; long long tmp = pow(a, b >> 1); tmp = (tmp * tmp) % mod * (b & 1 ? a : 1) % mod; return tmp; } int n, m; int a[100005]; long long ans = 0, res = 1; int main() { ...
5
#include <bits/stdc++.h> using namespace std; int a[200100], n, m, s, d, run[200100], jump[200100], l = 0; int main() { scanf("%d%d%d%d", &n, &m, &s, &d); for (int i = 0; i < n; i++) scanf("%d", &a[i]); sort(a, a + n); if (a[0] - 1 < s) { printf("IMPOSSIBLE"); return 0; } for (int i = 0; i < n; i++)...
4
#include <bits/stdc++.h> using namespace std; constexpr static int MAXN = 1e6 + 10; constexpr static int INF = 1e9; int n, m; vector<int> adj[MAXN]; int dist[MAXN]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n >> m; for (int i = 0; i < m; i++) { int u, v, t; cin >> u >> v >> t;...
8
#include <bits/stdc++.h> #define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); #define ll long long int #define pb push_back #define pob pop_back #define ub upper_bound #define lb lower_bound #define mp make_pair #define f0(i,n) for(i=0;i<n;i++) #define rf0(i,n) for(i=n-1;i>=0;i--) #define f2(i,n)...
1
#include <bits/stdc++.h> using namespace std; const int N = 2 * 1e5 + 10; long long t[2][4 * N], a, b; void update(int l, int r, int j, int pos, int val) { if (r < pos || pos < l) return; if (pos <= l && r <= pos) { t[0][j] = min(a, t[0][j] + val); t[1][j] = min(b, t[1][j] + val); return; } int mid ...
4
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); vector<char> a(9 * 9); vector<int> full(9), used(9 * 9); for (int i = 0; i < 81; i++) { cin >> a[i]; if (a[i] == '.') continue; int x = i / 9, y = i % 9; full[(x / 3) * 3 + y / 3...
3
#include <bits/stdc++.h> using namespace std; const int MAXN = 200007; vector<int> g[MAXN], gr[MAXN]; int cnt[MAXN], ans; vector<int> res; void dfs1(int v, int p = -1) { int i, to; cnt[v] = 0; for (i = 0; i < g[v].size(); i++) { to = g[v][i]; if (to == p) continue; dfs1(to, v); cnt[v] += (cnt[to] ...
4
#include <bits/stdc++.h> using namespace std; const long double EPS = 1e-9, PI = acos(-1.); const int INF = 0x3f3f3f3f, MOD = 1e9 + 7; const int N = 1e5 + 5; int n, s, x, t[N], val[N], nex[N]; int best, bestv; int main() { scanf("%d%d%d", &n, &s, &x); vector<int> v; for (int i = 1; i <= n; i++) v.push_back(i); ...
6
#include <bits/stdc++.h> using namespace std; vector<int> G[100005]; int color[100005]; long long sum; void init() { for (int i = 0; i < 100005; i++) { G[i].clear(); color[i] = -1; } } int ranse() { queue<int> q; q.push(1); color[1] = 2; while (!q.empty()) { int a = q.front(); q.pop(); f...
2
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { if (a == 0) { return b; } else { return gcd(b % a, a); } } int main() { int a, aCopy; cin >> a; long long summ = 0; long long znam = a - 2; for (int i = 2; i <= a - 1; i++) { aCopy = a; while (aCopy !...
1
#include <bits/stdc++.h> using namespace std; const int N = 1000 * 100 + 5; vector<int> adj[N]; int H[N], p[N], l; void dfs(int v, int par, int h) { ++H[h]; l = max(l, h); for (int i = 0; i < (int)(adj[v]).size(); ++i) if (adj[v][i] != par) dfs(adj[v][i], v, h + 1); } int main() { ios::sync_with_stdio(false...
7
#include <bits/stdc++.h> using namespace std; int n; const int maxn = 5009; int a[maxn]; int howmany[maxn]; int res[maxn]; int main() { scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%d", &a[i]); for (int i = 0; i < n; i++) { for (int j = 0; j < maxn; j++) howmany[j] = 0; int ma = 0; int node = 1...
3
#include <bits/stdc++.h> using namespace std; int x1, y_1, r1, x2, y2, r2; long double dis; int main() { cin >> x1 >> y_1 >> r1; cin >> x2 >> y2 >> r2; dis = sqrt((long double)((x2 - x1) * (x2 - x1) + (y2 - y_1) * (y2 - y_1))); if (dis + 1e-9 < abs(r1 - r2)) printf("%.15lf\n", (double)((abs(r1 - r2) - dis) ...
5
#include <bits/stdc++.h> using namespace std; const int MAXN = (1 << 18); long long c[MAXN + 5], sum; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int N, K; cin >> N >> K; for (int i = 0; i < (1 << N); i++) { cin >> c[i]; sum += c[i]; } cout << fixed << setprecision(6) << (double)sum / (...
8
#include <bits/stdc++.h> using namespace std; const long long mod = (long long)1e9 + 7; void solve() { int n; cin >> n; int a[n], b[n - 1], c[n - 2]; for (int i = 0; i < n; ++i) { cin >> a[i]; } for (int i = 0; i < n - 1; ++i) { cin >> b[i]; } for (int i = 0; i < n - 2; ++i) { cin >> c[i]; ...
1
#include <bits/stdc++.h> using namespace std; bitset<23000> a, b, c, e; int main() { int n, m, k; scanf("%d%d%d", &n, &m, &k); getchar(); for (int i = 0; i < n; i++, getchar()) for (int j = 0; j < m; j++) { char s = getchar(); (s == '#' ? b : a).set(i * m + j); (s == 'E' ? e.set(i * m + j)...
9
#include <bits/stdc++.h> using namespace std; int32_t main() { long long t; cin >> t; while (t--) { long long n; cin >> n; if (n < 15) { cout << "NO" << "\n"; continue; } if (((n - 20) % 14) == 0 or ((n - 19) % 14) == 0 or ((n - 18) % 14) == 0 or ((n - 17) % 14) ...
1
#include <bits/stdc++.h> using namespace std; const long long maxN = 2e5 + 5; struct edge { long long node_to, w; edge() {} edge(long long node_to, long long w) { this->node_to = node_to; this->w = w; } }; long long n, m, a[maxN], par, weight, dist[maxN], cnt_starting[maxN], cnt_ending[maxN], ans[ma...
5
#include <bits/stdc++.h> using namespace std; double p[5006], dp[5006][5006], ans = 0; int t[5006], n, T; int main() { memset(dp, 0, sizeof(dp)); memset(p, 0, sizeof(p)); ios_base::sync_with_stdio(false); cin >> n >> T; for (int i = 1; i <= n; i++) { cin >> p[i] >> t[i]; p[i] /= 100; } dp[0][0] = ...
8
#include <bits/stdc++.h> const int MaxN = 60; int N, M; bool A[MaxN][MaxN], Vis[MaxN][MaxN]; bool getc() { char ch; while (ch = getchar(), ch != '#' && ch != '.') ; return ch == '#'; } void Dfs(int x, int y) { if (x <= 0 || y <= 0 || x > N || y > M) return; if (!A[x][y] || Vis[x][y]) return; Vis[x][y] =...
4
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long t; cin >> t; while (t--) { long long n, i; cin >> n; long long a[2 * n]; for (i = 0; i < 2 * n; i++) { cin >> a[i]; } sort(a, a + (2 * n)); cout << a[n] - ...
1
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } long long lcm(long long a, long long b) { return a / gcd(a, b) * b; } long long sum = 1, n; int main() { cin >> n; for (int i = 1; i <= (int)(n - 1); i++) { sum = (sum * 3) % 1000003; } co...
2
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> row(n); vector<int> col(n); long long sum = 0; for (int i = 0; i < n; ++i) { string s; cin >> s; for (int x = 0; x < s.size(); ++x) { if (s[x] == 'C') { col[i]++; row[x]++; } }...
0
#include <bits/stdc++.h> using namespace std; long long pow(long long x, long long y) { long long ans = 1; while (y > 0) { if (y & 1) ans = (ans * x); y = y >> 1; x = (x * x); } return ans; } long long modpow(long long x, long long y, long long p = 1000000007) { long long ans = 1; x = x % p; w...
4
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; const int C = 26; void add(int &x, int y) { x += y; while (x >= MOD) x -= MOD; while (x < 0) x += MOD; } int fix(int x) { while (x >= MOD) x -= MOD; while (x < 0) x += MOD; return x; } int pw(int a, int b) { int ret = 1; while (b) { ...
4
#include <bits/stdc++.h> using namespace std; const int oo = 0x3f3f3f3f; const double eps = 1e-9; int Start[210000]; int End[210000]; int Midi[210000]; int Ch[210000][2]; int Max1[210000]; int Max2[210000]; int Create(int p, int a, int b) { Start[p] = a; End[p] = b; Max1[p] = -oo; Max2[p] = 0; int p1 = p + 1;...
7
#include<bits/stdc++.h> using namespace std; typedef long long LL; typedef pair<int,int>pii; const int mod = 1e9+7; const int inf = 1e9+100; const int N = 3e5+5; int main(){ ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n,k; cin>>n>>k; string cur = "aa"; for(int i=2; i<=k; i++){ ...
4
#include <bits/stdc++.h> using namespace std; priority_queue<int, vector<int>, greater<int> > q, s[3005], v[3005]; int main() { int n, m, x, y; while (~scanf("%d%d", &n, &m)) { for (int i = 1; i <= m; i++) while (!s[i].empty()) s[i].pop(); for (int i = 1; i <= n; i++) { scanf("%d%d", &x, &y); ...
4
#include <bits/stdc++.h> using namespace std; int main() { string s; int a = -1; bool found = false; cin >> s; for (int i = 0; i < s.size(); i++) { a = stoi(s.substr(i, 1)); if (a % 8 == 0) { found = true; break; } for (int j = i + 1; j < s.size(); j++) { a = stoi(s.substr(i,...
3
#include <bits/stdc++.h> using namespace std; int a[10000001]; int main() { int n, ans = -1e9; cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; } for (int i = 1; i * 3 <= n; i++) { if (n % i == 0) { for (int j = 1; j <= i; j++) { int sum = 0; for (int k = j; k <= n; k += i) ...
2
#include <bits/stdc++.h> using namespace std; long long a[444444], cot[444444]; void pushdown(int rt) { if (cot[rt]) { cot[rt << 1] = cot[rt]; cot[rt << 1 | 1] = cot[rt]; a[rt << 1] = cot[rt]; a[rt << 1 | 1] = cot[rt]; cot[rt] = 0; } } void pushup(int rt) { a[rt] = max(a[rt << 1], a[rt << 1 | 1]...
3
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; s += '@'; char delimiter = '@'; vector<string> str; string acc = ""; for (int i = 0; i < s.size(); i++) { if (s[i] == delimiter) { str.push_back(acc); acc = ""; } else acc += s[i]; } int f = 0; v...
3
#include <bits/stdc++.h> using namespace std; int par[150008], sz[150008]; int n; deque<int> dq[150008]; int find(int u) { return (par[u] == u) ? u : find(par[u]); } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> n; for (int i = 1; i <= n; i++) { sz[i] = 1; par[i] = i; dq[i].push_...
4
#include <bits/stdc++.h> using namespace std; long long a[200001], n; string s, t; bool check(long long m) { string temp = s; for (long long i = 0; i < m; ++i) { temp[a[i] - 1] = '.'; } long long i = 0, j = 0; while (i < n && j < t.size()) { if (temp[i] == '.') { ++i; continue; } else ...
4
#include <bits/stdc++.h> using namespace std; vector<int> v; int n; int main() { cin >> n; int x; for (int i = 0; i < n; i++) { cin >> x; v.push_back(x); } sort(v.begin(), v.end()); int i = 0; int l = 0; while (i < n - 1) { if (v[i] == v[i + 1]) { l++; i += 2; continue; ...
1
#include <bits/stdc++.h> using namespace std; long long n; struct pmod { int v, fa; } a[500]; struct dmod { int px, fa; } b[500]; int fa[500], ans[500]; string mp[500]; int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); } void un(int a, int b) { a = find(a); b = find(b); if (a != b) fa[a] = b; } b...
4
#include <bits/stdc++.h> using namespace std; double sq(double a) { return a * a; } struct pii { double x, y; }; pii mp(double x, double y) { pii ret; ret.x = x; ret.y = y; return ret; } pii operator-(pii a, pii b) { return mp(a.x - b.x, a.y - b.y); } pii operator+(pii a, pii b) { return mp(a.x + b.x, a.y + b...
6
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; int main() { int n, a, b, k; scanf("%d %d %d %d\n", &n, &a, &b, &k); string s; getline(cin, s); int pos = 0; std::vector<int> shots; int last = -1; for (int i = 0; i < n; i++) { if (s[i] == '1') { int l = last; ...
4
#include <bits/stdc++.h> using namespace std; int lev[100005]; void dfs(int u, int p, int **memo, int log, vector<int> *g) { memo[u][0] = p; for (int i = 1; i <= log; i++) memo[u][i] = memo[memo[u][i - 1]][i - 1]; for (int v : g[u]) { if (v != p) { lev[v] = lev[u] + 1; dfs(v, u, memo, log, g); ...
6
#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") const int INF = 1e9; const int N = 2e5 + 5; using namespace std; int Exp(int x, int y) { int ans = 1; for (int i = 1; i <= y; i++) ans *= x...
2
#include <bits/stdc++.h> using namespace std; const int N = 1010; int n; int a[N]; int main() { int T; cin >> T; while (T--) { cin >> n; for (int i = 1; i <= n; i++) scanf("%d", &a[i]); bool flag = false; for (int i = 1; i < n - 1; i++) if (a[i] < a[i + 1] && a[i + 1] > a[i + 2]) { p...
0