solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> using namespace std; mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count()); const int maxn = 100010; const int mod[2] = {1000000009, 1000000007}; const int base[2] = {1000000007, 998244353}; pair<int, int> mult[maxn]; struct HSH { pair<int, int> hsh; HSH(pair<int, in...
25
#include <bits/stdc++.h> using namespace std; double sin_deg(double x) { return sin((x * acos(-1.0)) / 180.0); } double cos_deg(double x) { return cos((x * acos(-1.0)) / 180.0); } double tan_deg(double x) { return tan((x * acos(-1.0)) / 180.0); } double asin_deg(double x) { return (asin(x) * 180) / acos(-1.0); } double...
5
#include <bits/stdc++.h> using namespace std; int n; unordered_map<int, int> cnt; int main() { int x, ans = 0; scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%d", &x), cnt[x]++, ans = max(ans, cnt[x]); printf("%d", ans); }
4
#include <bits/stdc++.h> using namespace std; struct node_class { int x, y, k; node_class(int xx, int yy, int kk) { x = xx; y = yy; k = kk; } node_class(void) {} } d[200000], ss; bool operator<(const node_class a, const node_class b) { return (a.x < b.x); } multiset<node_class> a; multiset<node_clas...
10
#include <bits/stdc++.h> using namespace std; struct ST { double key, mul, add; } a[400003]; int n, m; int s[100003]; int ls(int x) { return x << 1; } int rs(int x) { return x << 1 | 1; } void push_up(int x) { a[x].key = a[ls(x)].key + a[rs(x)].key; } void build(int x, int l, int r) { a[x].mul = 1; a[x].add = 0; ...
15
#include <bits/stdc++.h> using namespace std; string second = "What are you doing at the end of the world? Are you busy? Will you save " "us?"; string s_1 = "What are you doing while sending \""; string s_2 = "\"? Are you busy? Will you send \""; string s_3 = "\"?"; unsigned long long d[1000016][6]; int main() ...
9
#include <bits/stdc++.h> template <typename T> struct xgcd_s { T m, n, gcd; }; template <typename T> xgcd_s<T> xgcd(T a, T b) { T m[] = {1, 0}, n[] = {0, 1}, q[] = {0, 0}; for (int i = 0;; i ^= 1) { m[i] -= m[i ^ 1] * q[i]; n[i] -= n[i ^ 1] * q[i]; if (!b) return xgcd_s<T>{m[i], n[i], a}; q[i] = a...
26
#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) { ...
18
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { return (b == 0 ? a : gcd(b, a % b)); } int n, m; vector<pair<long long, int> > dv; long long calc(int idx, long long num) { if (idx == dv.size()) { long long res = 0; while (num < n) { res += n - num; num *= 2;...
14
#include <bits/stdc++.h> using namespace std; signed main() { ios_base::sync_with_stdio(false); cin.tie(0); long long a, b, c, aa, bb, cc; cin >> a >> b >> c; aa = a / 3; bb = b / 2; cc = c / 2; long long ans = min(aa, min(bb, cc)), mx = 0; a -= ans * 3, b -= ans * 2, c -= ans * 2; for (long long i ...
6
#include <bits/stdc++.h> using namespace std; const int MAXN = 1 << 18; int N; int p[MAXN]; int data[MAXN]; int find(int u) { return (data[u] < 0) ? u : data[u] = find(data[u]); } void join(int u, int v) { u = find(u); v = find(v); if (u != v) { data[u] += data[v]; data[v] = u; } } int main() { ios_ba...
6
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; int head[N], ver[N << 1], Next[N << 1], total; int d[N], f[N][3], len; vector<int> seq, stl, str; inline void add(int x, int y) { ver[++total] = y; Next[total] = head[x]; head[x] = total; } inline void addv(int x, int v) { int pos = -1; for...
22
#include <bits/stdc++.h> using namespace std; int a[100000]; int main() { string s; cin >> s; for (int i = 1; i < s.size(); i++) { if (s[i] == s[i - 1]) a[i - 1]++; } for (int i = 0; i < s.size() - 1; i++) { a[i + 1] += a[i]; } int n; cin >> n; while (n--) { int x, y; cin >> x >> y; ...
3
#include <bits/stdc++.h> using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const int N = 1 << 19; struct Node { int l, r; pair<int, int> val; int toAdd; Node() : l(-1), r(-1), val(make_pair(N, 1)), toAdd(0) {} Node(int _l, int _r) : l(_l), r(_r), val(make_pair(N, _r - _...
17
#include <bits/stdc++.h> const int maxn = 2e5 + 5; int n, lent; char s[maxn], t[maxn]; struct ACAM { int ch[maxn][26], tag[maxn], fail[maxn], cnt[maxn], tot = 1; int match[maxn]; void insert(char *s) { int now = 1, len = strlen(s); for (int i = 0; i < len; ++i) { int sid = s[i] - 'a'; if (!ch[...
16
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 5; int d[maxn], b[maxn]; int main() { int n, a; cin >> n; memset(d, 0, sizeof(d)); int maxv = 0; for (int i = 0; i < n; i++) { scanf("%d ", &a), scanf("%d", &b[a]); if (a > maxv) maxv = a; } if (b[0] > 0) d[0] = 1; int ans = 0;...
8
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long n, k, m, i, j, cost = 0; cin >> n >> k; char a[n]; map<char, long long> make_pair; priority_queue<long long> pq; for (long long i = 0; i < n; i++) cin >> a[i]; for (l...
5
#include <bits/stdc++.h> using namespace std; const int dx[4] = {-1, 1, 0, 0}; const int dy[4] = {0, 0, -1, 1}; long long danger, n, m, x, nb, curans, myprev; string s; long long dp[1000001]; long long f(long long n) { long long ans = 1; while (n) { if (n % 10) ans *= (n % 10); n /= 10; } return ans; } ...
5
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e6 + 5; int n; int p[MAXN], ones[MAXN << 1]; int main() { while (~scanf("%d", &n)) { long long sum = 0, mn; int mn_idx = 0, pos = 0, neg = 0; memset(ones, 0, sizeof(ones)); for (int i = 1; i <= n; ++i) { scanf("%d", p + i); su...
11
#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); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, m; cin >> n >> m; vector<map<int, int> > s(n); vector<vector<int> > a(n, vector...
8
#include <bits/stdc++.h> using namespace std; int main() { int i, j, q, r, t; int w, h; cin >> w >> h; long long c = 0; for (i = 0; i <= w; i++) { for (j = 0; j <= h; j++) { c += min(i - 0, w - i) * min(j - 0, h - j); } } cout << c; return 0; }
5
#include <bits/stdc++.h> using namespace std; const int MOD = (int)1e9 + 7; const int oo = (int)1e9; const long long OO = (long long)4e18; const double PI = acos(-1.0); const int N = (int)1e6 + 9; long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } int main() { int t; scanf("%d", &t); w...
3
#include <bits/stdc++.h> using namespace std; long long n, k, A, B; long long a[100005]; long long Cont(long long l, long long r) { return upper_bound(a, a + k, r) - lower_bound(a, a + k, l + 1); } long long Try(long long l, long long r) { long long tt = Cont(l, r); if (tt == 0) return A; if (l + 1 == r) return...
9
#include <bits/stdc++.h> using namespace std; const int N = 533333, EE = 100000000, GG = 1000000000, ima = 2147483647; int eq(double a, double b) { return a + 0.00000000001 >= b && b + 0.00000000001 >= a; } template <typename T> void _ma(T &a, T b) { if (a < b) a = b; } template <typename T> void _mi(T &a, T b) { ...
1
#include <bits/stdc++.h> using namespace std; int a[200005 << 1], res[200005]; vector<int> E[200005]; int gcd(int x, int y) { if (x == 0) return y; return gcd(y % x, x); } int main() { int n, i, k, j; long long ans = 0; scanf("%d", &n); for (i = 1; i <= n; i++) scanf("%d", &a[i]), a[i + n] = a[i]; for (i ...
16
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const int N = 100010; vector<int> vc[N]; int dp[350]; int a[N], b; int n, m, k, s, e; void run() { int ans = 0; memset(dp, 0x3f, sizeof(dp)); dp[0] = -1; vector<int>::iterator it; scanf("%d%d%d%d", &n, &m, &s, &e); for (int i = 0; i <...
15
#include <bits/stdc++.h> struct SEG { int l, r, v; }; struct LIST { int prev, next; SEG seg; } list[1000000]; int num; void initList() { num = 2; list[1].next = 0; list[0].prev = 1; list[0].prev = list[1].next = -1; } void set(int x, int l, int r, int v) { list[x].seg.l = l; list[x].seg.r = r; list[...
16
#include <bits/stdc++.h> using namespace std; const int size = 5007; long long a[size], diff[size]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout << fixed << setprecision(10); int n; cin >> n; for (int i = 0; i < n; ++i) cin >> a[i]; long long s = 0; for (int i = 0; i < n; +...
10
#include <bits/stdc++.h> using namespace std; const int MAXN = 5010; const int MAXM = 100010; const int INF = ~0U >> 2; struct node { int a, b, w; } e[MAXM]; struct Enode { int to, next; } ee[MAXM * 2]; int n, m, k, box[MAXN], size; int len[MAXN][MAXN]; int r[MAXN], rc; int p[MAXN]; int dp[MAXN][3]; bool used[MAXN]...
16
#include <bits/stdc++.h> using namespace std; int main() { int n, i; long long s[1200] = {0}; long long d[1200] = {0}; long long m[1200] = {0}; cin >> n; for (i = 0; i < n; i++) { cin >> s[i] >> d[i]; } m[0] = s[0]; long long sum = 0; for (i = 1; i < n; i++) { long long j = s[i]; while (...
1
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 6e1; long long r1, r2, r3, d; vector<long long> a; long long Memo[N][2]; int n; long long Calc(int i, bool CameBefore) { if (i == n) return -1ll * d; long long &Re = Memo[i][CameBefore]; if (Re + 1ll) return Re; Re = 0x7fffffffffffffff; if (Cam...
15
#include <bits/stdc++.h> using namespace std; inline int read() { char c; int s = 0, t = 1; while (!isdigit(c = getchar())) if (c == '-') t = -1; do { s = s * 10 + c - '0'; } while (isdigit(c = getchar())); return s * t; } inline long long readl() { char c; long long s = 0; int t = 1; while ...
5
#include <bits/stdc++.h> using namespace std; int main() { int q; cin >> q; while (q--) { int n; cin >> n; const int INF = 1e5; int Rx = INF, Lx = -INF, Uy = INF, Dy = -INF; while (n--) { int x, y, l, u, r, d; cin >> x >> y >> l >> u >> r >> d; if (!l) Lx = max(Lx, x); ...
7
#include <bits/stdc++.h> using namespace std; int a[105]; int main() { int n, m, i; scanf("%d%d", &n, &m); for (i = 1; i <= m; i++) { int l, r; scanf("%d%d", &l, &r); a[l] += 1; a[r + 1] -= 1; } for (i = 1; i <= n; i++) { a[i] += a[i - 1]; if (a[i] != 1) { printf("%d %d", i, a[i]...
5
#include <bits/stdc++.h> using namespace std; int main() { int n, a[10] = {0}; string s; cin >> n; cin >> s; for (int i = 0; i < n; i++) for (int j = 2; j <= s[i] - 48; j++) if (j == 4) a[2] += 2; else if (j == 6) { a[3]++; a[2]++; } else if (j == 8) a[2] ...
6
#include <bits/stdc++.h> using namespace std; const int N = 220000; struct Char { long long s; char c; Char(int _s = 0, char _c = 0) { s = _s; c = _c; } bool operator==(const Char tt) const { return s == tt.s && c == tt.c; } bool operator>=(const Char tt) const { return s >= tt.s && c == tt.c; } } s...
13
#include <bits/stdc++.h> using namespace std; char s[505]; int main() { long long k, a, b; cin >> k >> a >> b; if ((a % k > 0 && b < k) || (b % k > 0 && a < k)) puts("-1"); else cout << a / k + b / k << endl; }
4
#include <bits/stdc++.h> #pragma GCC optimize("Ofast", "unroll-loops", "omit-frame-pointer", "inline") #pragma GCC option("arch=native", "tune=native", "no-zero-upper") #pragma GCC target("avx2") using namespace std; const long long INF = 2e9, INFLL = 1e18, MOD = 1e9 + 7; void dfs(long long nod, vector<long long> &ar, ...
11
#include <bits/stdc++.h> using namespace std; const int M = 1e6 + 15; const int Q = 1e9 + 7; int a[M]; vector<int> b; int main() { srand(time(NULL)); cin.tie(0); ios_base::sync_with_stdio(0); int n, s; cin >> n >> s; s--; for (int i = 0; i < n; i++) { cin >> a[i]; } int ans = 0; if (a[s]) { ...
11
#include <bits/stdc++.h> using namespace std; unsigned long long a, inv, nr1, nr2; int fr[11]; string b; vector<int> res; int main() { cin >> a >> b; while (a != 0) { nr1++; fr[a % 10]++; a /= 10; } if (b.size() > nr1) { for (int i = 9; i >= 0; i--) for (int j = 1; j <= fr[i]; j++) cout <<...
9
#include <bits/stdc++.h> using namespace std; const int N = (int)2e5 + 123, inf = 1e9, mod = 1e9 + 7, LOG = 62; const long long INF = 1e18; long long dp[100][100]; void add(long long &x, long long y) { x += y; if (x >= mod) x -= mod; } long long rofl(long long x) { x >>= 1; x++; long long a = (x >> 1); long...
16
#include <bits/stdc++.h> using namespace std; const long long kMod = 1000000007; int N, M, K; int C[15][15]; int f[15][15], g[15][15]; long long res; void read(); void soups_on(); void dfs(int, int, int); void add_answer(); inline bool is_valid(int x, int y, int i) { int t = f[x - 1][y] | f[x][y - 1]; return bool((...
19
#include <bits/stdc++.h> using std::cerr; using std::endl; const int N = 2e5 + 233; int n, q, fa[N], cnt[N][26], sum[N], len[N], f[N][26], ban, id[N]; char C[N]; std::vector<int> G[N], T[N]; void dfs1(int x) { if (G[x].empty()) { id[x] = x; return; } for (int y : G[x]) { dfs1(y); len[x] = std::max...
22
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:16777216") #pragma warning(default : 4) using namespace std; int n, m, s1[1 << 21], s2[1 << 21], r, p2[1 << 21]; long long q[1 << 21]; int main() { memset(p2, -1, sizeof(p2)); scanf("%d %d", &n, &m); for (int i = 0; i < (int)(n); ++i) { scanf("%d", s1 +...
12
#include <bits/stdc++.h> using namespace std; const int oo = 0x3f3f3f3f; const double eps = 1e-9; int N, perm[110000], invperm[110000], pos[110000]; pair<int, int> nums[110000], tmp[110000]; bool lucky[110000], mark[110000]; bool islucky(int n) { while (n) { int d = n % 10; n /= 10; if (d != 4 && d != 7) ...
12
#include <bits/stdc++.h> using namespace std; bool vi[100010]; int ocu[100010]; int check(int n, bool ty) { if (ty) { for (int i = 2; i * i <= n; ++i) if (n % i == 0) { if (ocu[i] != 0) return ocu[i]; if (ocu[n / i] != 0) return ocu[n / i]; } if (ocu[n] != 0) return ocu[n]; } f...
8
#include <bits/stdc++.h> using namespace std; long long a[100005]; bool comp(long long a, long long b) { return a > b; } int main() { int t; cin >> t; while (t--) { memset(a, 0, sizeof(a)); int ta; long long tb; scanf("%d %lld", &ta, &tb); for (int i = 1; i <= ta; i++) { scanf("%lld", &a...
3
#include <bits/stdc++.h> using namespace std; const int maxn = 2e3 + 50; int fa[maxn]; string s[maxn]; vector<int> v[maxn]; int ans[maxn]; int in[maxn]; int vis[maxn]; int fin(int f) { return f == fa[f] ? f : fa[f] = fin(fa[f]); } int main() { int n, m; cin >> n >> m; for (int i = 0; i < n + m; ++i) fa[i] = i; ...
12
#include <bits/stdc++.h> using namespace std; long long n, a[10001], cnt[10001], dp[10001]; signed main() { cin >> n; for (long long i = 1; i <= n; i++) { cin >> a[i]; cnt[i] = a[i]; } sort(cnt + 1, cnt + n + 1); for (long long i = 1; i <= n; i++) { for (long long j = 1; j <= n; j++) { dp[j]...
14
#include <bits/stdc++.h> using namespace std; long long int n, m, i, j, k; long long int sum = 0; long long int b_search(long long int b[], long long int lo, long long int hi, long long int x, long long int pos) { if (lo > hi) { return pos; } long long int mid = lo + (hi - lo) / 2; if...
4
#include <bits/stdc++.h> bool local = false; using namespace std; template <class T> string toString(T x) { ostringstream sout; sout << x; return sout.str(); } template <class T> void print(T v) { cout << ((int)(v).size()) << "\n"; for (auto x : v) cout << x << ' '; cout << "\n"; }; template <class T1, clas...
2
#include <bits/stdc++.h> using namespace std; struct HASH { static uint64_t splitmix64(uint64_t x) { x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31); } size_t operator()(uint64_t x) const { static const uint64_t ...
8
#include <bits/stdc++.h> using namespace std; int main() { int t; scanf("%d", &t); while (t--) { int n, k; scanf("%d%d", &n, &k); if (((k % 3) != 0) && (n % 3 == 0)) printf("Bob\n"); else if ((k % 3) != 0 && (n % 3 != 0)) printf("Alice\n"); else { n = n % (k + 1); if ((...
9
#include <bits/stdc++.h> using namespace std; int main() { short int n; int l; cin >> n >> l; vector<int> lanterns(n); for (int i = 0; i < n; i++) cin >> lanterns[i]; set<int> sett(lanterns.begin(), lanterns.end()); priority_queue<int> pq; int tempset = 0; short int aa = 0; for (set<int>::iterator i...
4
#include <bits/stdc++.h> using namespace std; const long long mod = 998244353; long long inv(long long i) { if (i == 1) return 1; return (mod - ((mod / i) * inv(mod % i)) % mod) % mod; } long long mod_mul(long long a, long long b) { a = a % mod; b = b % mod; return (((a * b) % mod) + mod) % mod; } long long m...
14
#include <bits/stdc++.h> const int N = 20010; const int inf = 0x3f3f3f3f; const double eps = 1e-6; const double e = 2.718281828459046; using namespace std; int g[110][110]; int w[110]; int main() { int n, m; scanf("%d%d", &n, &m); for (int i = 0; i < n; i++) scanf("%d", w + i + 1); for (int i = 0; i < m; i++) {...
4
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; int n, f[1000010], c1, c2; int main() { scanf("%d", &n); for (int i = 1, x; i <= n; ++i) { scanf("%d", &x); if (x == 1) ++c1; else ++c2; } f[0] = f[1] = 1; for (int i = 2; i <= c1; ++i) { f[i] = ((long long)f[i ...
15
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 100; const int INF = 1e9 + 10; int A[MAXN], x[MAXN]; int main() { int n; cin >> n; int mn = INF; int mx = -INF; for (int i = 0; i < n; i++) { cin >> x[i]; mn = min(mn, x[i]); mx = max(mx, x[i]); } if (mx - mn < 2) { cout ...
9
#include <bits/stdc++.h> #pragma GCC target("avx2") #pragma GCC optimization("O3") #pragma GCC optimization("unroll-loops") using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); vector<string> words; long long int n, m; cin >> n >> m; string mid = ""; for (long long int i = 0;...
3
#include <bits/stdc++.h> using namespace std; inline int gi() { register int data = 0, w = 1; register char ch = 0; while (!isdigit(ch) && ch != '-') ch = getchar(); if (ch == '-') w = -1, ch = getchar(); while (isdigit(ch)) data = 10 * data + ch - '0', ch = getchar(); return w * data; } void chkmax(int &x,...
26
#include <bits/stdc++.h> using namespace std; const int N = 1100; const long long mod = 1000000007LL; int n; int p[N]; long long sum[N]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n; for (int i = 1; i <= n; i++) { cin >> p[i]; } for (int i = 1; i <= n; i++) { for (int j = p...
8
#include <bits/stdc++.h> using namespace std; const int N = 200000, M = 200000; int n, m, k, i, j, ii, jj, a[N]; signed long long int ans; vector<int> vec[M]; vector<pair<int, int> > v; int main() { cin >> n >> m; k = n / m; for (int i = 0; i < n; i += 1) cin >> a[i]; for (int i = 0; i < n; i += 1) vec[a[i] % m...
11
#include <bits/stdc++.h> using namespace std; int n, m, ans; vector<int> sz; map<int, int> ch; struct DSU { vector<int> p; DSU(int n) : p() { p.resize(n); iota(p.begin(), p.end(), 0); } int root(int x) { return p[x] == x ? x : p[x] = root(p[x]); } void join(int x, int y) { p[root(y)] = root(x); } }; i...
7
#include <bits/stdc++.h> using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); namespace std { template <> struct hash<pair<int, int>> { size_t operator()(const pair<int, int> &x) const { long long P = 38923, Q = 109797901; return (size_t)((x.first * P + x.second) % Q); }...
16
#include <bits/stdc++.h> const int N = 100010; struct node { int l, r; double sum, add, mul; } a[N << 2]; int n, q; int read() { int d = 0, f = 1; char c = getchar(); while (c < '0' || c > '9') { if (c == '-') f = -1; c = getchar(); } while (c >= '0' && c <= '9') d = d * 10 + c - 48, c = getchar()...
15
#include <bits/stdc++.h> using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); long long power(long long a, long long n) { a %= 1000000007; if (n == 1) return a; if (n == 0) return 1; if (n % 2) return (a * (power((a * a) % 1000000007, n / 2) % 1000000007)) % 1000000007; ...
14
#include <bits/stdc++.h> using namespace std; const int N = 5010, P = 37, M = 1e9 + 207; int h[N], p[N]; int hs(int l, int r) { int prv = ((l ? h[l - 1] : 0) * 1LL * p[r - l + 1]) % M; return (h[r] + M - prv) % M; } unordered_map<int, int> all; int f[N]; char can[N][N]; int main() { p[0] = 1; all.reserve(5e5); ...
13
#include <bits/stdc++.h> using namespace std; const long long INF = 9223372036854775807LL; struct Point { long long x, y; Point() {} Point(const long long _x, const long long _y) : x(_x), y(_y) {} }; struct CmpX { bool operator()(const Point &a, const Point &b) const { return a.x != b.x ? a.x < b.x : a.y < ...
15
#include <bits/stdc++.h> typedef struct link { char element; struct link* next; } Link; typedef struct stack { Link* top; int size; } Stack; Link* create_link(char it, Link* nextval) { Link* n = (Link*)malloc(sizeof(Link)); n->element = it; n->next = nextval; return n; } Stack* create_stack() { Stack*...
6
#include <bits/stdc++.h> using namespace std; int a[101], b[101] = {0}; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, c = 0; cin >> n; ; for (int i = 1; i <= n; i++) cin >> a[i]; ; if (n == 1) { cout << "NO" << endl; return 0; } sort(a + 1, a + n + 1); int mn...
0
#include <bits/stdc++.h> #pragma GCC optimize(2) using namespace std; long long n, m, t, k; string s; long long a[500005]; vector<long long> ans; long long lower(int num) { int l = 0, r = ans.size() - 1; while (l < r - 1) { int mid = (l + r) / 2; if (ans[mid] > num) { r = mid; } else { l = m...
8
#include <bits/stdc++.h> using namespace std; char a[4], b[4]; char x[4]; int main() { for (int i = 0; i < 4; i++) scanf(" %c", a + i); for (int i = 0; i < 4; i++) scanf(" %c", b + i); swap(a[2], a[3]); swap(b[2], b[3]); for (int i = 0; i < 4; i++) x[i] = a[i]; for (int i = 0; i < 4; i++) { if (a[i] == ...
4
#include <bits/stdc++.h> using namespace std; int Sig(double a) { return a < -1e-8 ? -1 : (a > 1e-8); } double sx, sy; struct Point { double x, y; double angle; Point() {} Point(double x0, double y0) : x(x0), y(y0) {} void in() { scanf("%lf %lf", &x, &y); angle = atan2(y - sy, x - sx); } void out(...
19
#include <bits/stdc++.h> using namespace std; void solve() { int n, k; cin >> n >> k; pair<int, int> arr[n]; for (int i = 0; i < n; i++) { int a; cin >> a; arr[i] = {a, i}; } sort(arr, arr + n); set<int> st[k + 1]; vector<int> ans(n, 0); int last = 1; for (int i = 0; i < n; i++) { if...
6
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; int a[n]; for (auto& x : a) cin >> x; bool check = 0; for (int i = 0; i < n - 1; i++) if (a[i] != a[i + 1]) check = 1; if (check == 0) cout << "NO" << '\n'; else {...
4
#include <bits/stdc++.h> using namespace std; inline bool equal(double _x, double _y) { return _x > _y - 1e-9 && _x < _y + 1e-9; } map<string, string> mp; int n; string str; int main() { scanf("%d", &n); mp["purple"] = "Power"; mp["green"] = "Time"; mp["blue"] = "Space"; mp["orange"] = "Soul"; mp["red"] =...
0
#include <bits/stdc++.h> using namespace std; double rf, re, rs, df, de, maxi, dp[2][20]; int pf[22], pe[22], ps[22], f, e, s; double memoize(int cho, int dis) { if (dp[cho][dis] != -1) return dp[cho][dis]; double ans = 0; pair<double, double> sta = make_pair(-1 * rs, rs); pair<double, double> endi; if (cho =...
18
#include <bits/stdc++.h> using namespace std; array<vector<int>, 2001> adj; bool vis[2001]; bool like[2001][2001]; vector<int> group; void dfs(int f) { vis[f] = true; group.push_back(f); for (auto to : adj[f]) if (like[f][to] && !vis[to]) dfs(to); } int main() { adj.fill({}); memset(like, true, sizeof lik...
7
#include <bits/stdc++.h> using namespace std; int nums[101]; int n, k; int main() { int i; scanf("%d %d", &n, &k); for (i = 1; i <= n; i++) { scanf("%d", &nums[i]); } sort(nums + 1, nums + 1 + n); reverse(nums + 1, nums + 1 + n); printf("%d\n", nums[k]); return 0; }
1
#include <bits/stdc++.h> const long long int MOD = 1e9 + 7; const long long int INF = 1011111111; const long long int LLINF = 1000111000111000111LL; const long double EPS = 1e-10; const long double PI = 3.14159265358979323; using namespace std; long long int power(long long int x, long long int n) { if (n == 0) r...
5
#include <bits/stdc++.h> using namespace std; /* Utilities */ #define fr(i, n) for (int i = 0; i < n; i++) #define forin(i, j, k, in) for (int i = j; i < k; i += in) #define foreach(it, l) for (auto it = l.begin(); it != l.end(); it++) #define in(a, b, c) b <= a &&a <= c #define clr(x) memset(x, 0, sizeof(x)) #define...
5
#include <bits/stdc++.h> using ll = long long; using ull = unsigned long long; using ld = long double; using PLL = std::pair<ll, ll>; template <class T> using prique = std::priority_queue<T, std::vector<T>, std::greater<T>>; template <class T> class infinity { public: static constexpr T value = std::numeric_limits<T...
0
#include <bits/stdc++.h> using namespace std; void c_p_c() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } int32_t main() { c_p_c(); long long p, n; vector<long long> v; cin >> n; for (long long i = 0; i < n; i++) { cin >> p; v.push_back(p); } cout << count(v.begin(), v.end(), 1) ...
0
#include <bits/stdc++.h> using namespace std; long long int powmod(long long int a, int b, int n) { long long int rm = 1; while (b) { if (b % 2) { rm = (rm * a) % n; } a = (a * a) % n; b /= 2; } return rm; } int a[int(1e5 + 10)], t = 0, k; long long int fun(int v1, int v2, int p1, int p2, ...
11
#include <bits/stdc++.h> using namespace std; long long solve() { long long n; cin >> n; if (n % 2) { cout << -1; return 0; } long long k = n, i, j; while (n--) { if (n % 2) { for (i = 0; i < k; i++) { for (j = 0; j < k; j++) { if (min(min(i, k - 1 - i), min(j, k - 1 - j)...
8
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; int i = 1; int res = 0; while (i < s.length()) { if (s[i] != '1') res += s[i] - '0'; else { res += 10; i++; } i++; } res += 1; cout << res; return 0; }
11
#include <bits/stdc++.h> using namespace std; template <typename T> void read(T& x) { x = 0; int fl = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') fl = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = (x << 1) + (x << 3) + ch - '0'; ch = getchar(); } x ...
18
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; s.push_back('#'); bool ab = false, ba = false; for (int i = 0; i < s.length() - 2; ++i) { if (s.substr(i, 2) == "AB") { for (int j = i + 2; j < s.size() - 2; ++j) if (s.substr(j, 2) == "BA") { cout << "Y...
7
#include <bits/stdc++.h> using namespace std; int n; long long k, a[110], d; long long func(long long val) { long long hold = 0; for (int i = 0; i < n; i++) { hold += (long long)ceil((double)a[i] / (double)val); } hold = k / hold; return hold; } int main() { scanf("%d%lld", &n, &k); for (int i = 0; i ...
15
#include <bits/stdc++.h> using namespace std; const long long UNDEF = -1; const long long INF = 1e18; template <typename T> inline bool chkmax(T &aa, T bb) { return aa < bb ? aa = bb, true : false; } template <typename T> inline bool chkmin(T &aa, T bb) { return aa > bb ? aa = bb, true : false; } static char stdinB...
10
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { while (b) { a %= b; swap(a, b); } return a; } long double ans = 0; long double check(vector<long long>& mas, long double& x) { long long n = mas.size(); long double mx1 = mas[0] - x, sum = 0, min_sum = 0; for (lo...
12
#include <bits/stdc++.h> using namespace std; int main() { long double n, r, x, y, z, len, s; cin >> n >> r; x = acos(-1.0) / (2 * n); y = acos(-1.0) / n; z = acos(-1.0) - x - y; len = r * sin(x) / sin(z); s = len * r * sin(y) * n; cout << fixed << setprecision(8) << s << endl; return 0; }
13
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; int c = (n / 3) * 2; if (n % 3) c += 1; cout << c; return 0; }
0
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int i, a[n]; for (i = 0; i < n; i++) { cin >> a[i]; } sort(a, a + n); if (n == 1) cout << a[0]; if (n == 3) cout << a[1]; if (n == 5) cout << a[2]; }
0
#include <bits/stdc++.h> using namespace std; int i, j, n, m, l, r, t; int cnt[200][200], cnt2[200][200]; bool used[200][200], used2[200][200]; char a[200][200]; int x[200 * 200], y[200 * 200]; int u, v, u2, v2, tu, tv; bool first; bool valid(int u, int v) { if (u > 0 && v > 0 && u <= n && v <= n) return true; retu...
7
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ; long long n, x, y; cin >> n >> x >> y; long long white = x + y - 2; long long black = 2 * n - x - y; if (white <= black) cout << "White"; else cout << "Black"; retu...
0
#include <bits/stdc++.h> using namespace std; int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } int main() { long long a, b, x, y, c = 0; cin >> x >> y >> a >> b; int g = (x * y) / gcd(x, y); cout << b / g - (a - 1) / g << endl; return 0; }
4
#include <bits/stdc++.h> using namespace std; long long INF = 999999999999999; long long MOD = 1000000007; void solve() { long long ans = 0; vector<long long> a(3); cin >> a[0] >> a[1] >> a[2]; sort(a.begin(), a.end()); set<long long> usd; for (long long i = 0; i < 11; i++) { for (int i1 = 0; i1 <= 1; i...
1
#include <bits/stdc++.h> using namespace std; const long long logN = 20; const long long N = 100005; const long long M = 1000000007; const long long dx[4] = {1, 0, -1, 0}; const long long dy[4] = {0, 1, 0, -1}; long long vis[1005]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); string s; ...
5
#include <bits/stdc++.h> using namespace std; const int N = 2020, P = 1e9 + 7, B = 19260817; int n, m, ans, p[N], g[2][2][N], h[N], f[2][N][N], a[2][N]; char s[2][N], t[N]; int hs(int l, int r) { return (h[r] - 1ll * h[l - 1] * p[r - l + 1] % P + P) % P; } int gs(int l, int r, int k, int b) { if (b == 0) return...
24