solution
stringlengths
53
181k
difficulty
int64
0
13
#include <bits/stdc++.h> using namespace std; int n, l, m; int pre[123456 * 3], other[123456 * 3], last[123456 * 3]; int dfn[500005], dep[500005], sign, father[200005][21], tmp[200050], ans1, ans2; pair<int, int> f[200050]; bool ok[222222]; void add(int u, int v) { l++; pre[l] = last[u]; last[u] = l; other[l] =...
7
#include <bits/stdc++.h> using namespace std; struct Data { int X, Y, V; }; bool operator<(Data A, Data B) { return A.V < B.V; } struct Painter { int X, Y, Type; }; struct HashType { int X, Y; HashType *Next; }; int Get() { char c; while (c = getchar(), (c < '0' || c > '9') && (c != '-')) ; bool Flag ...
9
#include <bits/stdc++.h> using namespace std; int mod = 1e9 + 7; int main() { int n; cin >> n; vector<vector<int> > a(3, vector<int>(52, 0)); vector<string> t(3); cerr << n << endl; for (int i = 0; i < 3; i++) { string s; cin >> s; t[i] = s; sort(t[i].begin(), t[i].end()); cerr << t[i].s...
5
#include <bits/stdc++.h> #pragma GCC optimize("O3") std::pair<int, int> DR[] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}, {-1, 1}, {-1, -1}, {1, 1}, {1, -1}}; using namespace std; int n, a[1 << 17], b[2][1 << 17], tot[2]; vector<int> vec[2]; vector<pair<int, int>> ans; int cnt[2]; int32_t main() {...
5
#include <bits/stdc++.h> using namespace std; const int MAXN = 1000001; int s[MAXN]; long long int pot[MAXN]; long long int inv[MAXN]; int cont[MAXN]; long long int power(long long int a, int b) { long long int ans = 1ll; while (b) { if (b & 1) ans = (ans * a) % 1000000007; a = (a * a) % 1000000007; b >...
6
#include <bits/stdc++.h> using namespace std; int n, m, x1, y, a[3005][3005]; vector<int> v[3005]; long long ans; int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); ; cin >> n >> m; for (int i = 0; i < m; i++) { cin >> x1 >> y; a[x1][y] = 1; v[x1].push_back(y); } for (...
4
#include <bits/stdc++.h> using namespace std; const int mod = (int)(1e9 + 7); vector<int> read(int n) { vector<int> v(n); for (int i = 0; i < n; i++) cin >> v[i]; return v; } void solve() { long long int i, j, k, m, n, ans = 0, cnt = 0, sum = 0; cin >> n >> m; char a[n][m]; for (int i = 0; i < n; i++) ...
0
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); int n, answer = INT_MAX; cin >> n; n = n * 2; vector<int> v; for (int i = 0; i < n; ++i) { int x; cin >> x; v.push_back(x); } sort(v.begin(), v.end()); for (int i = 0; i < n; ++...
3
#include <bits/stdc++.h> using namespace std; int main() { int n(0), input(0); cin >> n; vector<int> vect(n, 0); cin >> n; for (int i = 0; i < n; i++) { cin >> input; vect[input - 1] = 1; } cin >> n; for (int i = 0; i < n; i++) { cin >> input; vect[input - 1] = 1; } bool full(true); ...
0
#include <bits/stdc++.h> using namespace std; int n, m; double win[1005][1005]; double lose[1005][1005]; int main() { for (int i = 1; i <= 1000; i++) win[i][0] = 1; for (int i = 1; i <= 1000; i++) { for (int j = 1; j <= 1000; j++) { win[i][j] = i * 1.0 / (i + j) + lose[i][j - 1] * j / (i + j); lose[...
5
#include <bits/stdc++.h> using namespace std; int n, m, k, num; int father[3000]; long long ans; int f(int x) { return father[x] == x ? x : father[x] = f(father[x]); } void u(int x, int y) { x = f(x); y = f(y); if (x != y) father[x] = y; } int main() { while (cin >> n >> m >> k) { num = 0, ans = 1; for ...
4
#include <bits/stdc++.h> using namespace std; long long fun(long long x, long long y) { long long tmp; while (x % y != 0) { tmp = x % y; x = y; y = tmp; } return y; } int main() { long long n; cin >> n; long long k; if (n == 1) { k = 1; } else if (n == 2) { k = 2; } else if (n % ...
4
#include <bits/stdc++.h> using namespace std; const int MAXN = 100000; int n; int a[MAXN]; bool f[MAXN]; bool sf[MAXN]; int ft; void solve(int i) { if (i == 0) { printf("(%d)", a[0]); } else if (i == 1) { printf("(%d->%d)", a[1 - 1], a[1]); } else { if (a[i - 1] == 1 && a[i] == 0) { printf("((("...
7
#include <bits/stdc++.h> using namespace std; void solve() { int n; cin >> n; vector<int> a(n); vector<int> ind(n + 1); for (int i = 0; i < n; ++i) { cin >> a[i]; ind[a[i]] = i; } vector<long long> sums(n + 1); for (int i = 1; i <= n; ++i) { sums[i] = sums[i - 1] + i; } int l = ind[1]; ...
2
#include <bits/stdc++.h> using namespace std; const int MAXN = 1005; const int MOD = 1000000007; int N, P; int dp[MAXN][4]; int a[MAXN], b[MAXN]; int cnt[3]; void load() { scanf("%d%d", &N, &P); } inline int add(int x, int y) { x += y; if (x >= MOD) x -= MOD; else if (x < 0) x += MOD; return x; } inline...
9
#include <bits/stdc++.h> using namespace std; inline long long read() { long long x = 0, f = 1; char ch = getchar(); for (; ch < '0' || ch > '9'; ch = getchar()) if (ch == '-') f = -f; for (; ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0'; return x * f; } inline void chkmin(int &a, int b) {...
5
#include <bits/stdc++.h> const double PI = 3.141592653589793238463; using namespace std; inline long long add(long long a, long long b) { a += b; if (a >= 1000000007) a -= 1000000007; return a; } inline long long sub(long long a, long long b) { a -= b; if (a < 0) a += 1000000007; return a; } inline long lon...
7
#include <bits/stdc++.h> using namespace std; int main() { long double d, n, r, count = 0; cin >> r >> d >> n; for (long long int j = 0; j < n; j++) { long double xx, yy, ro, dist, a, b; cin >> xx >> yy >> ro; dist = hypot(xx, yy); a = (dist - ro); b = (dist + ro); if (a >= r - d && b <= r...
1
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; bool let[26]; memset(let, 1, sizeof(let)); int count = 0; char who = -1; for (int i = 0; i < n; ++i) { char type; cin >> type; string st; cin >> st; if (type == '?') { if (st[0] != who && who != -1) ++cou...
4
#include <bits/stdc++.h> int l, d, v, g, r, cnt; int main() { scanf("%d%d%d%d%d", &l, &d, &v, &g, &r); double pre = 1. * d / v; for (; pre > g + r; cnt++) pre -= g + r; printf("%.12lf\n", pre < g ? 1. * l / v : 1. * (l - d) / v + (cnt + 1.) * (g + r)); }
3
#include <bits/stdc++.h> using namespace std; void loop() { int n; cin >> n; int a[n + 1]; long long int sum = 0; for (int i = 1; i <= n; i++) { cin >> a[i]; sum += a[i]; } if (sum % n) { cout << "-1\n"; return; } vector<pair<long long int, pair<long long int, long long int> > > v; f...
6
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10, INF = 1e9 + 7; int n; string second; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> n >> second; int ind = n - 1; for (int i = 0; i < (n - 1); i++) { if (second[i] > second[i + 1]) { ind = i; break; } ...
2
#include <bits/stdc++.h> const int maxn = 1005; int p[maxn], d[maxn], l[maxn][2], nl, ti; int main() { int n, h, r, c; scanf("%d%d%d", &n, &h, &r); for (int i = 0; i != n; ++i) scanf("%d%d", p + i, d + i); c = h; while (true) { c += r; if (c > h) c = h; if (c <= 0) break; int t = 0, pos = -1; ...
5
#include <bits/stdc++.h> using namespace std; const int N = 5e3 + 10; const int MOD = 1e9 + 7; const double PI = acos(-1); int a[N]; int c[N]; vector<int> v[N]; bool usedColor[N]; int main() { int n, k; cin >> n >> k; int mx = 0; for (int i = 0; i < n; i++) { cin >> a[i]; mx = max(mx, a[i]); v[a[i]]...
3
#include <bits/stdc++.h> using namespace std; int n; int Ask(int i) { cout << "? " << i + 1 << endl; int ans; cin >> ans; return ans; } int B(int i) { int ret = Ask(i); int j = (i + n / 2) % n; ret -= Ask(j); return ret; } void Print(int i) { cout << "! " << i + 1 << endl; exit(0); } void Err() { ...
6
#include <bits/stdc++.h> using namespace std; char a[1007]; long long f[1007][1007][3][3], ans, mod; int s[1007], l, d[1007]; void dfs(int l, int r) { if (l + 1 == r) f[l][r][0][1] = f[l][r][0][2] = f[l][r][1][0] = f[l][r][2][0] = 1; else if (s[l] == r) { dfs(l + 1, r - 1); for (int i = 0; i <= 2; i++) ...
5
#include <bits/stdc++.h> #pragma GCC diagnostic ignored "-Wunused-result" using namespace std; const int N = (int)10; const int INF = (int)1e9 + 41; const long long MD = (long long)1e9 + 7; bool D = false, E = false; long long sum[N][N]; long long num[N][N]; int minE[N][N]; vector<pair<int, int>> es = {{0, 1}, {0, 2}, ...
8
#include <bits/stdc++.h> long long max(long long a, long long b) { return a > b ? a : b; } long long min(long long a, long long b) { return a < b ? a : b; } using namespace std; const int maxn = 1e6 + 5; char p[maxn], q[maxn]; int P[27], Q[27], V[27], R[27], F[27]; vector<int> v; int main() { int ans = 0; memset(V,...
3
#include <bits/stdc++.h> using namespace std; const long long lINF = 1e18 + 7; const int INF = 1e9 + 7; template <class T> ostream& operator<<(ostream& s, const vector<T>& v) { for (size_t i = 0; i < v.size(); i++) { s << v[i] << ' '; } return s; } template <class T> istream& operator>>(istream& s, vector<T>&...
0
#include <bits/stdc++.h> using namespace std; map<pair<int, int>, int> mp; int deg[200000]; int main() { int n, m, i, x, y, cn, cn2; srand(time(NULL)); scanf("%d %d", &n, &m); vector<int> v; for (i = 0; i < m; i++) { scanf("%d %d", &x, &y); x--; y--; mp[make_pair(x, y)] = 1; mp[make_pair(y...
8
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 45; void solve() { int n; cin >> n; vector<int> a(2 * n); vector<int> p(n); vector<int> s(n); for (int i = 0; i < 2 * n; i++) { cin >> a[i]; } p[0] = (a[0] == 1 ? 1 : -1); for (int i = 1; i < n; i++) { p[i] = p[i - 1] + (a[i]...
4
#include <bits/stdc++.h> using namespace std; int get() { char ch; while (ch = getchar(), (ch < '0' || ch > '9') && ch != '-') ; if (ch == '-') { int s = 0; while (ch = getchar(), ch >= '0' && ch <= '9') s = s * 10 + ch - '0'; return -s; } int s = ch - '0'; while (ch = getchar(), ch >= '0' &...
12
#include <bits/stdc++.h> using namespace std; const long long INF = 1000000007; int gcd(int a, int b) { if (b == 0) return a; else return gcd(b, a % b); } std::mt19937 mt(time(0)); int main() { ios_base::sync_with_stdio(0); cin.tie(0); long long n, m; int q; cin >> n >> m >> q; long long g = gcd...
3
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; long long a1, a2, b1, b2, c1, c2, d1, d2; a1 = 0; b1 = 0; c1 = 0; d1 = 1; for (int i = 1; i <= n; i++) { a2 = (b1 + c1 + d1); if (a2 > 1000000000000000ll) { a2 = a2 % 1000000007; } b2 = (a1 + c1 + d1); ...
3
#include <bits/stdc++.h> int main() { int n, i, a[1000000], k, j = 1; scanf("%d", &n); for (i = 0; i < n; i++) { scanf("%d", &k); while (k--) { a[j] = i + 1; j++; } } int m; scanf("%d", &m); while (m--) { int g; scanf("%d", &g); printf("%d\n", a[g]); } return 0; }
2
#include <bits/stdc++.h> using namespace std; const int maxn = 3e5 + 5; int t[maxn << 2], a[maxn], b[maxn]; const int inf = 998244353; inline void pushUp(int rt) { t[rt] = min(t[rt << 1], t[rt << 1 | 1]); } void build(int l, int r, int rt) { if (l == r) { t[rt] = a[l]; return; } int m = l + r >> 1; buil...
8
#include <bits/stdc++.h> using namespace std; const int N = 100100; int n, k, m, h, u[N], use[N], c1, c2, b1, b2, nrc, ans, ind, cc[N]; stack<int> s; vector<int> v[N], vt[N], c[N]; set<int> g[N]; template <class T> ostream& operator<<(ostream& out, vector<T> v) { out << v.size() << '\n'; for (auto e : v) out << e <...
5
#include <bits/stdc++.h> using namespace std; int n, k; vector<bitset<7>> score; vector<bitset<7>> bvec(10); map<unsigned long, int> bmap; bool flag = false; long long ans = 0; vector<string> anss; int ccc = 0; int ans_tab[2001][10][2001]; bool valid(vector<bitset<7>>& s, int cur, int dig, int cnt) { if (ans_tab[cur]...
4
#include <bits/stdc++.h> using namespace std; void solve() { long long int n; cin >> n; for (long long int i = 0; i < n; i++) cout << i + 1 << " "; cout << "\n"; } int32_t main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long int test; cin >> test; for (long long int tc = 1; tc <= tes...
0
#include <bits/stdc++.h> using namespace std; int gcd(int a, int b) { if (a % b == 0) return b; else return gcd(b, a % b); } int main() { int n; scanf("%d", &n); int ans; int x; if (n & 1) x = n / 2 + 1; else x = n / 2 + 1; for (int i = x; i <= n; i++) { int y = n - i; if (gcd(...
0
#include <bits/stdc++.h> using namespace std; const long long int N = 5e5 + 5; const long long int mod = 1e9 + 7; const int di[4] = {-1, 0, 1, 0}; const int dj[4] = {0, -1, 0, 1}; const double pi = 3.14159265358979323846; long long int gcd(long long int a, long long int b) { if (a == 0) return b; return gcd(b % a, ...
5
#include <bits/stdc++.h> using namespace std; long double EPS = 1e-9; long long cel(long long a, long long b) { return ((a - 1) / b + 1); } long long gcd(long long a, long long b) { if (a < b) swap(a, b); return (b == 0) ? a : gcd(b, a % b); } long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); } ...
3
#include <bits/stdc++.h> using namespace std; const int maxn = 120; char op[16][2]; int n, s, resa, resb, res, na, nb; int dp[1 << 16][121], ta[16], tb[16], ra[1 << 16], rb[1 << 16]; int main() { cin >> n; s = 1 << n; for (int i = 0; i < n; ++i) { cin >> op[i] >> ta[i] >> tb[i]; resa += ta[i]; resb +=...
8
#include <bits/stdc++.h> using namespace std; int main() { int n, a[200010], b[200010]; scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d", &a[i]); sort(&a[1], &a[n + 1]); int min, max, l = 1; min = (int)sqrt(a[1]); max = (int)sqrt(a[n]); for (int i = min; i <= max + 1; i++) { int x = i * i; ...
4
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const int _inf = 0xc0c0c0c0; const long long INF = 0x3f3f3f3f3f3f3f3f; const long long _INF = 0xc0c0c0c0c0c0c0c0; const long long mod = (int)1e9 + 7; const int Z = 100; const int N = Z * Z; const int M = Z * Z * Z * 3; int px[N], py[N]; int head[...
8
#include <bits/stdc++.h> using namespace std; const int dx44[6] = {0, -1, -1, 1, 1}; const int dy44[6] = {0, -1, 1, -1, 1}; char dir_box[] = {'j', 'N', 'S', 'W', 'E'}; char dir_man[] = {'j', 'n', 's', 'w', 'e'}; const int dx4[6] = {0, 1, 0, -1, 0}; const int dy4[6] = {0, 0, 1, 0, -1}; const int dx8[9] = {0, -1, 0, 1, 0...
1
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; int a[N]; int cnt[N]; int need[N]; int n, m; int getbit(int x, int i) { return (x >> i) & 1; } void add(int x, int val) { for (int mask = 0; mask < (1 << 6); mask++) if (getbit(mask, x)) cnt[mask] += val; } bool check() { for (int mask = 0; ma...
8
#include <bits/stdc++.h> using namespace std; inline long long read() { long long x; cin >> x; return x; } const int MAX_N = 15; const int MAX_F = (1 << (MAX_N - 2)) + 4; int n, m, nQ, id[MAX_N]; bool isEdge[MAX_N][MAX_N], isParent[MAX_N][MAX_N], isNotParent[MAX_N][MAX_N]; bool ok1[MAX_F][MAX_N], ok2[MAX_F][MAX_N...
9
#include <bits/stdc++.h> using namespace std; const int dx[] = {-1, 1, 0, 0, -1, -1, 1, 1}; const int dy[] = {0, 0, -1, 1, -1, 1, -1, 1}; int main() { ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); int t; cin >> t; while (t--) { int n; cin >> n; vector<int> a(n); for (auto &i : a) ci...
1
#include <bits/stdc++.h> using namespace std; const int INF = 1000000000; const int EPS = 1e-9; int main() { ios_base ::sync_with_stdio(); int n, i, a; long long sa = 0, sb = 0; vector<int> va, vb; cin >> n; for (i = 0; i < n; i++) { cin >> a; if (a > 0) { sa += a; va.push_back(a); }...
3
#include <bits/stdc++.h> using namespace std; const int K = 12; const int N = (int)1e5 + 37; int n; int k; int q; int tab[K + 1][N]; bitset<1 << K> b[N]; bitset<K * N> init[K + 1]; int go[N * K]; int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n >> k >> q; for (int i = 1; i <= k; i++) { for (int j ...
10
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1.0); const int MAXN = 500; const int INF = 100000009; int Min(int a, int b) { return a < b ? a : b; } int a4, a7, a47, a74; int main() { int i; while (cin >> a4 >> a7 >> a47 >> a74) { if (a74 - a47 > 1 || a47 - a74 > 1) { puts("-1"); ...
5
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; int n, m; int a[N], l[305], r[305]; vector<int> add[N], sub[N]; int ansc[305]; void change(int l, int r, int v) { for (int i = l; i <= r; i++) a[i] += v; } int main() { while (~scanf("%d%d", &n, &m)) { for (int i = 1; i <= n; i++) scanf("%d", ...
6
#include <bits/stdc++.h> using namespace std; int main() { int n = 0; int mi1, mi2, mi3, ma1, ma2, ma3; cin >> n; cin >> mi1 >> ma1; cin >> mi2 >> ma2; cin >> mi3 >> ma3; n -= mi1; n -= mi2; n -= mi3; if (ma1 - mi1 > n) { mi1 += n; n = 0; } else { n -= (ma1 - mi1); mi1 = ma1; } ...
1
#include <bits/stdc++.h> int main() { int t; scanf("%d", &t); for (int i = 1; i <= t; i++) { int n, c = 0; int ara[6]; scanf("%d", &n); for (int j = 0; j <= 4; j++) { if (n % 10 != 0) { ara[j] = (n % 10) * (pow(10, j)); c++; n = n / 10; } else { ara[j] =...
0
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; int n, m; vector<int> in[N]; int d[N]; void run() { for (int i = 1; i <= m; i++) { int u, v; cin >> u >> v; if (u > v) swap(u, v); ++d[u], ++d[v]; in[u].push_back(v); } long long ans = 0; for (int i = 1; i <= n; i++) an...
8
#include <bits/stdc++.h> using namespace std; int main() { long long int a, b; cin >> a >> b; long long int x = a; long long int y = b; long long int r = 0; if (b == 1 && a != 1) cout << a; if (a == 1 && b != 1) cout << b; if (a == 1 && b == 1) cout << a; if (a != 1 && b != 1) { while (1) { ...
4
#include <bits/stdc++.h> int main(void) { int l, r, x, a[6], c, i = 0, k = 0, j, flag = 1; scanf("%d %d", &l, &r); for (x = l; x <= r; x++) { k = 0; flag = 1; c = x; i = 0; while (c != 0) { a[i] = c % 10; c = c / 10; i++; k++; } for (i = 0; i < k - 1; i++) { ...
0
#include <bits/stdc++.h> using namespace std; const int MAXN = 100100; const int MAXSEG = 1 << 18; const int MOD = 1000000007; long long power[MAXN]; long long pre[MAXN]; long long digit[10]; int N, M, K; string S; long long seg[MAXSEG]; long long lazy[MAXSEG]; void build_tree(int node, int left, int right) { if (lef...
8
#include <bits/stdc++.h> using namespace std; void model(vector<int>& a, const vector<pair<int, int> >& v) { for (pair<int, int> p : v) swap(a[p.first], a[p.second]); } bool check(int n, const vector<pair<int, int> >& v) { vector<int> a(n); for (int i = 0; i < n; ++i) a[i] = i; model(a, v); for (int i = 0; i ...
11
#include <bits/stdc++.h> using namespace std; const int Inf = 0x3f3f3f3f; const long long INF = 0x3f3f3f3f3f3f3f3fll; const long double inF = 11451419198101145141919810.1145141919810; const long double pi = acosl(-1); int s, p, g, n, m; struct Point { long double x, y; Point() {} Point(long double x, long double ...
10
#include <bits/stdc++.h> using namespace std; const int M = 100005; int n, m, x, y; long long a[2002]; long long sum, k; string s, z; vector<pair<int, int> > v; long long gcd(long long a, long long b) { if (!b) return a; return gcd(b, a % b); } int main() { cin >> n; bool f = true; for (int i = 0; i < n; i++)...
3
#include <bits/stdc++.h> const int mo = 1000000007; const int inf = 0x3f3f3f3f; double pi = 3.14159265358979323846; double e = 2.71828182845904523536; using namespace std; long long a[200005], b[200005]; set<long long> s; long long n, m, k; long long ans = 0; int main() { cin >> n >> m; k = n / m; for (int i = 0;...
5
#include <bits/stdc++.h> using namespace std; using ll = long long; using db = double; using pii = pair<int, int>; using pll = pair<ll, ll>; void testCase() { ll n; cin >> n; for (int i = 1; i * i <= 2 * n; i++) { ll val = 2 * n - (i * (i + 1)); ll dis = sqrt((val * 4) + 1); ll l = (-1 + dis) / 2; ...
2
#include <bits/stdc++.h> using namespace std; long long t, n, g, b, sum, x, y, z; int main() { ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); cin >> t; for (int i = 0; i < t; i++) { cin >> n >> g >> b; x = (n + 1) / 2; y = (x + g - 1) / g; z = y - 1; sum = (z * (b + g)) + (x - (z * g));...
3
#include <bits/stdc++.h> using namespace std; const long long INF = 1000000000000000000LL; const int maxn = 5005; long long ans = INF, QZans, QZsize; long long size[maxn], insi[maxn], sumto[maxn]; int x[maxn], y[maxn], z[maxn]; int N; vector<pair<long long, long long> > F[maxn]; void dfs1(int s, int fa) { size[s] = 1...
7
#include <bits/stdc++.h> using namespace std; bool subset(long long int a, long long int b) { for (int i = 0; i < 60; i++) { long long int z1 = ((1LL << i) & a) > 0; long long int z2 = ((1LL << i) & b) > 0; if (z1 == 1 && z2 == 0) return false; } return true; } int main() { long long int n, n1, i, j...
4
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); int n; scanf("%d", &n); vector<int> game(n + 1); game[0] = game[1] = game[2] = 0; vector<int> res(n + 1, -1); for (int i = 3; i <= n; i++) { int ok[300001]; memset(ok, 0, sizeof(0)); for (int j = 2; (j * (...
6
#include <bits/stdc++.h> int main() { int n, w, m; scanf("%d%d%d", &n, &w, &m); int cnt[100] = {0}; int used[100] = {0}; bool fail = false; int x = 1; for (int i = 1; i <= m; ++i) { int r = n; while (r) { if (++cnt[x] > 2) fail = true; int u = std::min(r, m - used[x]); r -= u; ...
5
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 100, inf = 1e5 + 50; int n, k, q, r[maxn], age[maxn], mxted[maxn]; vector<int> seg[maxn * 4], fnmax[maxn * 4], srt; bool cmp(int a, int b) { return r[a] < r[b]; } bool cmp1(int a, int b) { return a < age[b]; } bool cmp2(int a, int b) { return age[a] <...
9
#include <bits/stdc++.h> using namespace std; const int maxn = 300010; const int mod = 1e9 + 9; int f[maxn], sfib[maxn], d[maxn], s[maxn], a[maxn]; int L[maxn / 100], R[maxn / 100]; void init() { sfib[1] = f[1] = 1; for (int i = 2; i <= maxn - 10; i++) { f[i] = (f[i - 1] + f[i - 2]) % mod; sfib[i] = (sfib[i...
8
#include <bits/stdc++.h> using namespace ::std; long long gcd(long long a, long long b) { if (!b) return a; return gcd(b, a % b); } inline long long lcm(long long a, long long b) { return a * b / gcd(a, b); } int main() { long long a, b, k, m = 2, step = 1, tot = 0, q; cin >> a >> b >> k; for (long long i = 3...
6
#include<iostream> #include <iomanip> #include<bits/stdc++.h> using namespace std; #define ll long long #define f(i,a,b) for(int i=a;i<b;i++) #define it(x,b) for(auto &x:b) #define NUM 1000000007 typedef vector<ll> vll; typedef pair<ll,ll> pll; long long binpow(long long a, long long b) { if (b == 0) retu...
5
#include <bits/stdc++.h> using namespace std; inline int read() { int ans = 0; bool f = 1; char ch = getchar(); while (!isdigit(ch)) f ^= ch == '-', ch = getchar(); while (isdigit(ch)) ans = ((ans << 2) + ans << 1) + (ch ^ 48), ch = getchar(); return f ? ans : -ans; } const int N = 1e5 + 5; int n, k, s0[N],...
7
#include<bits/stdc++.h> using namespace std; #define rep(i,x,y) for (int i=(x);i<=(y);i++) #define drep(i,x,y) for (int i=(x);i>=(y);i--) #define sz 1010101 typedef long long ll; bool chkmax(ll &x,ll y){return x<y?x=y,1:0;} bool chkmin(ll &x,ll y){return x>y?x=y,1:0;} int n; ll w[sz],d[sz]; void Out() { static ll a[...
13
#include <bits/stdc++.h> using namespace std; const int N = 100010; int n, cnt[N]; struct edge { int to, nx, dl, id; } ee[N]; int eq[N], en = 1; int dv[N], dvt; void link(int u, int v, int id) { swap(u, v); ee[++en] = (edge){v, eq[u], 0, id}, eq[u] = en; } void dfs(int u) { for (int j = eq[u], v; v = ee[j].to, ...
10
#include <bits/stdc++.h> using namespace std; int a, b, c, d, n, l, r; long long k, x, sum, ans; int main() { int tt = 0; scanf("%d", &tt); while (tt--) { scanf("%d%lld", &n, &k); ans = 1ll << 60; scanf("%d%d%d%d", &a, &b, &c, &d); if (a > c) { swap(a, c); swap(b, d); } if (c <...
6
#define _CRT_SECURE_NO_WARNINGS #include <vector> #include <string> #include <map> #include <queue> #include <unordered_map> #include <unordered_set> #include <cassert> #include <complex> #include <cstdio> #include <iostream> #include <iomanip> #include <cmath> #include <functional> #include <algorithm> #include <stack...
9
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, temp, i; cin >> n; int even[n], odd[n], evenlen = 0, oddlen = 0; for (i = 0; i < n; i++) { cin >> temp; if (temp % 2 == 0) { even[evenlen++] = temp; } else { odd[oddlen+...
0
#include <bits/stdc++.h> using namespace std; const int maxn = 5e4 + 2000; int cnt[10]; int cntt[10]; int digits; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); string s; cin >> s; for (int i = 0; i < s.size(); i++) { cnt[s[i] - 48]++; digits++; } int low = 1; int high...
7
#include <bits/stdc++.h> using namespace std; long long one, two, three, cnt = 0, n; int main() { ios_base::sync_with_stdio(false); ; cin >> n; for (long long i = 1; i <= n; i++) { cin >> one >> two >> three; if (one + two + three >= 2) cnt++; } cout << cnt << "\n"; return 0; }
0
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") using namespace std; int freq[1010]; int main() { ios::sync_with_stdio(false); cin.tie(0); int T, n; cin >> T; while (T--) { memset(freq, 0, sizeof(freq)); cin >> n; vector<int> a; a.resize(n + 10); set<int> mex; for (int j = 0; j ...
5
#include <bits/stdc++.h> using namespace std; const int mod = 1000000007; int main() { ios::sync_with_stdio(0), cin.tie(0); long long int n; cin >> n; vector<long long int> v[n + 1]; for (long long int i = 0; i < n - 1; i++) { long long int x, y; cin >> x >> y; v[x].push_back(y); v[y].push_bac...
4
#include <bits/stdc++.h> using namespace std; const int N = 100005; const long long MOD = 1e9 + 7; int dX[] = {0, 0, 1, -1}; int dY[] = {1, -1, 0, 0}; int a[] = {100, 20, 10, 5, 1}; int main() { int n, ans = 0; scanf("%d", &n); for (int i = 0; i < 5; ++i) { int am = n / a[i]; ans += am; n -= am * a[i]...
0
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:1024000000,1024000000") using namespace std; const int Maxn = 200005, Maxm = 300005, Mo = 10007, sp[4][2] = {{-1, 0}, {1, 0}, {0, 1}, {0, -1}}; const long long oo = LLONG_MAX >> 2; typedef int IArr[Maxn]; typedef long long LArr[Maxn]; typedef double DAr...
11
#include <bits/stdc++.h> using namespace std; long long sum[(1 << 20) * 2][5]; long long num[(1 << 20) * 2]; void order(long long pos) { do { pos /= 2; num[pos] = num[pos * 2] + num[pos * 2 + 1]; long long tmp = num[pos * 2] % 5; for (long long i = 0; i < ((long long)5); i++) sum[pos][i] = sum[p...
7
#include <bits/stdc++.h> int main() { int n, m, s, e, c, a = 0; scanf("%d %d", &n, &m); for (int i = 0; i < n; i++) { scanf("%d", &c); a += c; } a = n - abs(a); for (int i = 0; i < m; i++) { scanf("%d %d", &s, &e); c = e - s + 1; if (c % 2 == 0 & c <= a) printf("%d \n", 1); els...
0
#include <bits/stdc++.h> using namespace std; string to_string(string s) { return '"' + s + '"'; } string to_string(const char *s) { return to_string((string)s); } string to_string(bool b) { return (b ? "true" : "false"); } template <typename A, typename B> string to_string(pair<A, B> p) { return "(" + to_string(p.fi...
11
#include <bits/stdc++.h> using namespace std; const int MAXN = 4e5 + 10; vector<int> g[MAXN]; bool can[MAXN]; int cnt[MAXN], prob[MAXN]; int best[MAXN], n; void dfs_down(int v, int p = -1) { prob[v] = -1; cnt[v] = 1; for (int u : g[v]) { if (u == p) continue; dfs_down(u, v); cnt[v] += cnt[u]; best...
7
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int a, b, a1, b1; cin >> a >> b >> a1 >> b1; int x, y, x1, y1; x = min(a, b); y = max(a, b); x1 = min(a1, b1); y1 = max(a1, b1); if (x + x1 == y && y == y1) cout << "Yes" << endl; el...
0
//a.9 #include<bits/stdc++.h> #define ll long long #define endl '\n' #define mod 1000000007 #define INF 0x3f3f3f3f #define ios ios_base::sync_with_stdio(false); cin.tie(NULL) using namespace std; ll t,n,arr[300005],k,s; ll func(ll i) { if((arr[i]>arr[i-1]&&arr[i]>arr[i+1])||(arr[i]<arr[i-1]&&arr[i]<arr[i+1]))return 1;...
4
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; const long long INF = 1e13; int n, k; long long A[N], B[N], C[N]; bool can(long long mid) { priority_queue<pair<long long, int>, vector<pair<long long, int> >, greater<pair<long long, int> > > pq; for (int x = (0), qwerty = ...
7
#include <bits/stdc++.h> using namespace std; struct Point { long long x, y, z; }; bool found = 0; Point p[8]; long long dot(Point a, Point b) { return a.x * b.x + a.y * b.y + a.z * b.z; } bool IsCube() { Point q[8]; for (int i = 0; i < 8; ++i) { q[i].x = p[i].x - p[0].x; q[i].y = p[i].y - p[0].y; q[i...
6
#include <bits/stdc++.h> using namespace std; struct point { int x, y; }; long long ccw(point o, point u, point v) { point fir = {u.x - o.x, u.y - o.y}; point sec = {v.x - o.x, v.y - o.y}; return 1ll * fir.x * sec.y - 1ll * fir.y * sec.x; } bool cmp(point a, point b) { return (a.x < b.x); } int main() { map<i...
9
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; if (n >= 6) { printf("1 2\n1 3\n2 4\n2 5\n"); for (int i = 6; i <= n; i++) printf("1 %d\n", i); } else { printf("-1\n"); } for (int i = 2; i <= n; i++) printf("1 %d\n", i); return 0; }
3
#include <bits/stdc++.h> using namespace std; const long long OO = 0x0101010101010101; class debug_t { public: template <typename T> debug_t& operator<<(const T& o) { return *this; } } dout; int n, m; vector<pair<int, double>> vec; int dp[5005][5005]; int solve(int idx, int last_idx) { if (idx > n) return ...
4
#include <bits/stdc++.h> using namespace std; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long TC = 1; while (TC--) { long long n; cin >> n; vector<long long> a(n); for (long long i = 0; i < n; i++) cin >> a[i]; long long lcnt = 1, rcnt = 1; for (long long i = ...
5
#include <bits/stdc++.h> using namespace std; long long ar[55]; bool v[55]; int main() { int n, i, j, c; long long k, x; cin >> n >> k; ar[n] = 1; ar[n + 1] = 1; for (i = n - 1; i >= 1; --i) ar[i] = ar[i + 1] + ar[i + 2]; for (i = 1; i <= n;) { if (i == n) { printf("%d", i); break; } ...
5
#include <bits/stdc++.h> const int N = 100005; int n, pre[N], nxt[N]; std::string s; std::vector<std::basic_string<int> > v[4]; int main() { std::ios::sync_with_stdio(0), std::cin.tie(0); std::cin >> s, n = s.size(); for (int i = 0; i < n; ++i) s[i] = s[i] == 'R'; std::queue<int> q[2]; for (int i = 0; i < n; ...
9
#include <bits/stdc++.h> using namespace std; const long long INF = 1e18; const long long MOD = 1e6 + 3; const int N = 1e5 + 5; int n, k; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ; cin >> n >> k; vector<int> V(2 * n + 1); for (int i = 0; i < 2 * n + 1; i++) { cin >...
1