solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> using namespace std; int a[1111111], b[1111111]; int main() { int j, i, n, m = 1111, k = 0, x = 0, y = 0; char c[55][55]; cin >> n; for (i = 0; i < 2 * n - 1; i++) { cin >> x; k += abs(x); if (n % 2 == 0) { if (x < 0) y++; m = min(abs(x), m); } } if (n % ...
10
#include <bits/stdc++.h> using namespace std; bool visit[3010]; vector<int> vec[3010]; vector<int> revec[3010]; int ST[3010][20]; int n, m, q, x, y, s, t, k, ans[400010]; struct Node { int u, k, i; }; vector<Node> query[3010]; void addedge(int u, int v) { vec[u].push_back(v); revec[v].push_back(u); } void dfs(int...
19
#include <bits/stdc++.h> using namespace std; long long int co = 1; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long int n; cin >> n; for (int x = 0; x < n; x++) { string s; cin >> s; sort(s.begin(), s.end()); if (s[0] == s[s.length() - 1]) { cout...
1
#include <bits/stdc++.h> using namespace std; int n, m; char s[2020]; long long f[2020][2020], ans, g[2020]; void U(long long &x, long long y) { x = (x + y) % 1000000007; } int main() { cin >> n >> m >> s + 1; f[0][0] = 1; g[0] = 1; for (int i = 1; i <= n; ++i) { for (int j = 0; j <= m; ++j) { U(f[i][...
17
#include <bits/stdc++.h> using namespace std; int dp[2][505][505], arr[505]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n, m, b, mod; cin >> n >> m >> b >> mod; for (int i = 1; i < n + 1; i++) cin >> arr[i]; memset(dp, 0, sizeof(dp)); for (int i = 0; i < b + 1; i++) { dp[1][i][0] =...
10
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf("%d", &n); vector<int> ar; int sum = 0, num; for (int i = 0; i < (n); i++) { cin >> num; sum += num; ar.push_back(num); } int lo, hi, s2 = 0; scanf("%d%d", &lo, &hi); for (int i = 0; i < (n); i++) { s2 += ar[i]; ...
2
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; int ans = floor(sqrt(n)) + floor(cbrt(n)) - floor(sqrt(cbrt(n))); cout << ans << endl; } return 0; }
0
#include <bits/stdc++.h> using namespace std; const int INF = 0x7f7f7f7f; void setup() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cout.precision(15); } struct seg_tree { struct node { int val; node(int _val = 0x7f7f7f7f) { val = _val; } node operator+(const node &y) { return min(...
14
#include <bits/stdc++.h> using namespace std; int main() { long long n, k; cin >> n >> k; long long num[5100], sum[5100]; cin >> num[0]; sum[0] = 0; sum[1] = num[0]; for (int i = 1; i < n; i++) { cin >> num[i]; sum[i + 1] = sum[i] + num[i]; } double ans = 0; for (int i = k; i <= n; i++) ...
5
#include <bits/stdc++.h> using namespace std; int f[1000007]; int main() { int n, t1, t2, k; cin >> n >> t1 >> t2 >> k; vector<pair<long long, int>> res; for (auto i = (1); i <= (n); ++i) { long long a, b; cin >> a >> b; long long ans = a * t1 * (100 - k) + b * t2 * 100LL; swap(a, b); ans = ...
4
#include <bits/stdc++.h> using namespace std; long long int a[305][305], dp0[305][305], dp1[305][305], hell = (-pow(10, 15)); void solve() { long long int n; cin >> n; for (long long int i = 1; i <= n; i++) for (long long int j = 1; j <= n; j++) { cin >> a[i][j]; dp1[i][j] = hell; } dp0[1][1...
12
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int tux; int foo = 0; int bar = 0; int baz = 0; int quz = 1; cin >> tux; while (tux--) { bar += 1; int pur; cin >> pur; foo += pur; if (max(foo * quz, bar * baz) == foo * quz) { ...
9
#include <bits/stdc++.h> using namespace std; int n, k; int m; int main() { cin >> n >> k; int g = 1; int a[111111]; memset(a, 0, sizeof(a)); for (int i = 0; i < (n); ++i) { scanf("%d", &m); if (m != a[g - 1]) a[g++] = m; } int vis[111111]; memset(vis, 0, sizeof(vis)); for (int i = 1; i < g; i...
8
#include <bits/stdc++.h> using namespace std; const int N = 200010; int a[N], bit[N]; int n, m, L, sh, rev; void C(int i, int dlt) { for (; i <= sh + L; i += i & -i) bit[i] += dlt; } int Q(int i) { int ans = 0; for (; i; i -= i & -i) ans += bit[i]; return ans; } int main() { scanf("%d%d", &n, &m); L = n; ...
14
#include <bits/stdc++.h> int main() { char loop[] = "6842"; long long n; std::cin >> n; if (n == 0) { std::cout << '1'; } else { std::cout << loop[n % 4]; } }
2
#include <bits/stdc++.h> using namespace std; int l, r, m; string s; struct yo { int a, b, c; }; yo make_yo(int c, int b, int a) { yo dich; dich.a = a; dich.b = b; dich.c = c; return dich; } int a[4 * 1000000]; int b[4 * 1000000]; int c[4 * 1000000]; void build(int t, int tl, int tr) { if (tl == tr) { ...
12
#include <bits/stdc++.h> using namespace std; template <class T> constexpr T lcm(T m, T n) { return m / __gcd(m, n) * n; } template <typename I> void join(ostream &ost, I s, I t, string d = " ") { for (auto i = s; i != t; ++i) { if (i != s) ost << d; ost << *i; } ost << endl; } template <typename T> ist...
14
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const double PI = acos(-1.0); struct point { int x, y, c, id; point() {} point(int x, int y) : x(x), y(y) {} point operator-(const point &b) const { return {x - b.x, y - b.y}; } int operator^(const point &b) const { return x * b.y - y *...
24
#include <bits/stdc++.h> using namespace std; const int M = 5005, M2 = 8200; vector<int> opt[M]; int mi[M2]; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); fill(mi, mi + M2, 5001); mi[0] = 0; for (int i = 1; i <= 5000; i++) opt[i].push_back(0); int n; cin >> n; while (n--) { int x;...
16
#include <bits/stdc++.h> using namespace std; struct team { int fa[507], e; int find(int x) { if (x == fa[x]) { return x; } else { return fa[x] = find(fa[x]); } } void un(int x, int y) { x = find(x); y = find(y); if (x == y) { return; } else { fa[y] = x; ...
11
#include <bits/stdc++.h> #pragma optimize(2) const int MOD = 998244353; int n, c, a[3005], cnt[3005], pw[3005], ipw1[3005], ans[3005]; inline int mval(int x) { return x >= MOD ? x - MOD : x; } inline void inc(int &x, int a) { (x += a) >= MOD && (x -= MOD); } inline void dec(int &x, int a) { x = mval(MOD + x - a); } inl...
27
#include <bits/stdc++.h> using namespace std; int a[200005], vis[200005], c[200005], d[200005]; int main() { int n, cnt2 = 0; scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); vis[a[i]] = 1; if (a[i] == 0) { cnt2++; d[cnt2] = i; } } int cnt = 0; for (int i = 1; ...
7
#include <bits/stdc++.h> using namespace std; int mod = 1e9 + 7; long long fact(long long n) { long long f = 1; for (long long i = 1; i <= n; i++) f = (f * i) % mod; return f; } long long gcd(long long a, long long b) { if (a == 0) return b; return gcd(b % a, a); } long long lcm(long long a, long long b) { ...
11
#include <bits/stdc++.h> using namespace std; struct record { int reminder, least; char dig; record() : dig(0) {} record(int r, int l, char d) : reminder(r), least(l), dig(d) {} }; int d, s; bool exist[505][5005]; record Record[505][5005]; queue<pair<int, int> > Q; void getNum(int nRem, int nSum); int main() { ...
14
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, m; cin >> n >> m; vector<int> s(m + 1), h(m + 1); vector<int> c(n); for (int i = 1; i <= m; i++) { cin >> s[i] >> h[i]; s[i]--; c[s[i]] = i; } vector<int> a(n); for (int i = 0; i < ...
15
#include <bits/stdc++.h> using namespace std; string s[3]; int l[3]; int a[101][101][101]; int d[101][101][101]; int go(int x, int y, int z) { if (a[x][y][z] != -1) return a[x][y][z]; if (z == l[2]) return -1e9; if (x == l[0] || y == l[1]) return 0; int &r = a[x][y][z]; r = 0; if (go(x + 1, y, z) > r) { ...
12
#include <bits/stdc++.h> using namespace std; using namespace std::chrono; long long int md[33][33]; bool visited[33][33]; long long int dx[] = {1, 0}; long long int dy[] = {0, 1}; long long int distmd[33][33]; long long int n, m; void DFS(int x, int y) { visited[x][y] = true; for (long long int i = 0; i < 2; i++) ...
7
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; int i; int f(int x) { return (x % i ? 0 : 1 + f(x / i)); } int main() { ios::sync_with_stdio(0); cin.tie(0); int a1, a2, b1, b2; cin >> a1 >> b1 >> a2 >> b2; int ans = 0; for (i = 3; i >= 2; i--) { while (f(a1) + f(b1) - f(a2) - f(b2...
11
#include <bits/stdc++.h> using namespace std; int n, m; int arr[50]; vector<int> fhalf; set<int> shalf; int brute(int ind, long long int curr) { if (ind == n) { return curr % m; } int ans = 0; ans = max(brute(ind + 1, curr), ans); ans = max(brute(ind + 1, (curr + arr[ind])), ans); return ans; } void sec...
10
#include <bits/stdc++.h> using namespace std; int i, j, k, n, m, f[110001], g[110001], a[110001], b[3101], l[110001], r[110001]; int main() { scanf("%d%d", &n, &m); for (i = 1; i <= n; i++) scanf("%d", &a[i]); for (i = 1; i <= m; i++) scanf("%d", &b[i]); sort(a + 1, a + 1 + n); sort(b + 1, b + 1 + m); f...
20
#include <bits/stdc++.h> using namespace std; inline int gcd(int a, int b) { return a == 0 ? b : gcd(b % a, a); } int main() { int n, m; cin >> n >> m; int x, y, a, b; cin >> x >> y >> a >> b; int g = gcd(a, b); a /= g; b /= g; int coeff = min(n / a, m / b); int width = coeff * a; int height = coeff...
9
#include <bits/stdc++.h> using namespace std; const int maxn = 300005; long long num[maxn]; long long sum[maxn]; int main() { int n; scanf("%d", &n); long long ans = 0; num[0] = 0; sum[0] = 0; for (int i = 1; i <= n; i++) { scanf("%lld", &num[i]); } sort(num + 1, num + n + 1); for (int i = 1; i <=...
4
#include <bits/stdc++.h> using namespace std; char a[1000001]; int main() { int n; scanf("%d", &n); char st[n]; int room = 0; int prev = 0; for (int i = 0; i < n; ++i) { int temp; char c; cin >> c; cin >> temp; if (a[temp] != '+' && c == '-') { prev++; st[i] = c; } else {...
5
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int b, g, n; cin >> b >> g >> n; int min_g = max(n - b, 0); int min_b = max(n - g, 0); cout << n - (min_g + min_b) + 1; }
3
#include <bits/stdc++.h> const int N = 300010; const int MAX = 1 << 19; using pii = std::pair<int, int>; struct Seg { int seg[MAX << 1]; void add(int sit, int value) { seg[sit += MAX] = value; for (sit >>= 1; sit; sit >>= 1) { seg[sit] = std::min(seg[sit << 1], seg[sit << 1 | 1]); } } int quer...
14
#include <bits/stdc++.h> using namespace std; const int maxn = 2005; int a[maxn]; int f(int p) { if (a[p] == -1) return 1; return f(a[p]) + 1; } int main() { int n, best = 0; cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; best = 0; for (int i = 1; i <= n; i++) if (f(i) > best) best = f(i); cout...
1
#include <bits/stdc++.h> using namespace std; bool gcd(long long a, long long b) { if (!b) return false; if (!gcd(b, a % b)) return true; else { if (b % 2 == 1) return (a / b + 1) % 2; else { a /= b; a--; if (a % (b + 1) == b) return true; else return a % ...
15
#include <bits/stdc++.h> using namespace std; int x[] = {0, -1, 0, 1, -1, 1, -1, 1}; int y[] = {-1, 0, 1, 0, 1, -1, -1, 1}; const int MOD = 1e9 + 7, N = 3e5 + 5; const double pi = acos(-1); int n, r; vector<pair<int, int>> pos; vector<pair<int, pair<int, int>>> neg; int dp[105][N]; int solve(int id, int curRate) { if...
13
#include <bits/stdc++.h> using namespace std; long long delta[5010], upper[5010]; int o[5010][4]; int main() { int n, m; cin >> n >> m; for (int i = 1; i <= n; ++i) { delta[i] = 0; upper[i] = 1000000000; } for (int i = 0; i < m; ++i) { for (int j = 0; j < 4; ++j) cin >> o[i][j]; if (o[i][0] ==...
9
#include <bits/stdc++.h> using namespace std; int a[1050], c, d[1050], b[1050]; int main(void) { int t; while (scanf("%d", &t) == 1) { int m = 0; for (int i = 0; i < t; i++) scanf("%d", &a[i]); memset(b, 0, sizeof(b)); for (int i = t - 1; i >= 0;) { c = a[i]; int flag = 0; for (int...
2
#include <iostream> #include <string> #include <cmath> #include <vector> #include <algorithm> #include <utility> #include <bitset> #include <climits> #include <set> #include <map> #include <iomanip> #include <queue> #include <cstring> using namespace std; #define ll long long #define pll pair<ll,ll> #define F first #de...
10
#include <bits/stdc++.h> using namespace std; void Read(int &n) { int sign = 1; n = 0; char c; do { c = getchar(); } while (!isdigit(c) && c != '-'); if (c == '-') { c = getchar(); sign = -1; } do { n = n * 10 + c - 48; c = getchar(); } while (isdigit(c)); n *= sign; } void Read(...
21
#include <bits/stdc++.h> using namespace std; int main() { int n, i; cin >> n; int arr[n]; for (i = 0; i < n; i++) { cin >> arr[i]; } int t; cin >> t; while (t--) { int x, y; cin >> x >> y; x--; if (x == n - 1) { y--; arr[x - 1] += y; arr[x] = 0; } else if (x ==...
0
#include <bits/stdc++.h> using namespace std; int main() { unsigned long long ans1 = 0, ans = 0; long long int ck = 0, p, sum = 0, a; map<long long int, long long int> cnt; int n; cin >> n; for (int i = 0; i < n; i++) { cin >> p; a = (p * i) - sum - cnt[p - 1] + cnt[p + 1]; if (a < 0) { a ...
14
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ; string s; cin >> s; long long int a[6] = {4, 5, 6, 3, 2, 1}; char c = char(s[s.length() - 1]); long long int n = 0, t = 10; for (int i = 0; i < s.length() - 1; i++) { n =...
4
#include <bits/stdc++.h> using namespace std; int n; char s[1000]; char ans[100][100]; bool st[100]; bool check(int x, int y) { if (ans[x][y] == '*' && ans[y][x] == '*') return true; return false; } void solve() { cin >> n; for (int i = 1; i <= n; i++) cin >> s[i]; for (int i = 1; i <= n; i++) for (int j ...
2
#include <bits/stdc++.h> using namespace std; long long fac[200005]; long long inv[200005]; inline void add(long long &a, long long b) { a %= 1000000007; b %= 1000000007; a += b; a %= 1000000007; } inline void sub(long long &a, long long b) { a %= 1000000007; b %= 1000000007; a -= b; if (a < 0) a += 100...
14
#include <bits/stdc++.h> using namespace std; int main() { long long int n, m, i, j, k, count = 0, sum = 0, d; cin >> n >> m >> d; long long int a[m]; for (i = 0; i < m; i++) { cin >> a[i]; sum = sum + a[i]; } if (n > sum + (m + 1) * (d - 1)) { cout << "NO"; } else { cout << "YES" << endl;...
9
#include <bits/stdc++.h> using namespace std; vector<vector<array<int, 2>>> vals(4100); int ans[4100][101]; int Hash(string &s) { int ret = 0; for (auto c : s) { ret <<= 1; if (c == '1') ++ret; } return ret; } int findpos(vector<array<int, 2>> &v, int k) { if (v[0][0] > k) return 0; int l = 0, r = v...
11
#include <bits/stdc++.h> using namespace std; const int N = 200010, INF = 0x3f3f3f3f; int n, m; struct P { long long S, M, R, T; }; P a[N]; long long S[N], M[N], R[N], T[N]; int flag[N * 4]; vector<int> t[N * 4]; vector<P> pp[N * 4]; vector<long long> pre[N * 4], suf[N * 4]; inline long long Min(const long long &x, c...
23
#include <bits/stdc++.h> const int N = 1e3 + 1; int a[N], b[N]; int n, max = 0, p, j; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); if (max < a[i]) { max = a[i]; p = i; } } a[p] = 0; b[j] = p; int ans = 1; while (j < n - 1) { max = 0; for ...
1
#include <bits/stdc++.h> using namespace std; char a[2000]; int n, k; int main() { scanf("%d %d", &n, &k); scanf("%s", a + 1); int i, len = 0; for (i = n - 1; i >= 1; i--) { bool flag = true; for (int j = 1, p = n - i + 1; j <= i; j++, p++) { if (a[j] != a[p]) { flag = false; break...
5
#include <bits/stdc++.h> using namespace std; const int N = 2005; int res[N]; int n, m, k; int main() { scanf("%d%d%d", &n, &m, &k); char x = getchar(); for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { x = getchar(); switch (x) { case 'D': { if (i == 1) res[j]++; ...
6
#include <bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; const long double PI = acosl(-1); mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); struct point { long double x, y; point() {} point(long double x, long double y) : x(x), y(y) {} long double kampas() { return atan2l(...
22
#include <bits/stdc++.h> using namespace std; int main() { long long int n, f; cin >> n >> f; long long int a[n]; long long int k, l; long long int sum = 0; for (long long int i = 0; i < n; i++) { cin >> k >> l; sum += min(k, l); if (k > l) a[i] = 0; else a[i] = min(k * 2, l) - m...
5
#include <bits/stdc++.h> int main() { char time[10]; gets(time); int minute, hour; minute = ((time[3] - 48) * 10) + time[4] - 48; hour = ((time[0] - 48) * 10) + time[1] - 48; if (hour >= 12) hour = hour - 12; printf("%.1f %d", float((hour * 30) + minute * 0.5), minute * 6); scanf(" "); }
4
#include <bits/stdc++.h> using namespace std; template <typename T> T abs(T a) { return a < 0 ? -a : a; } const int INF = (int)1e9; const double PI = 3.1415926535897932384626433832795; const int N = 4; char c[N][N]; char inv(char x) { return x == '#' ? '.' : '#'; } int main() { for (int i = 0; i < 4; i++) { sca...
3
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector<pair<int, int>> vec(n); int dif = 0; for (int i = 0; i < n; i++) { cin >> vec[i].first >> vec[i].second; dif += vec[i].second; } int i = 0; while (dif > 500) { dif ...
7
#include <bits/stdc++.h> using namespace std; int main() { int n, m, i, j, a[20], b[20], t[3], balance = 0, cost = 0; priority_queue<int, vector<int>, greater<int> > pq; scanf("%d%d", &n, &m); for (i = 0; i < n; i++) scanf("%d", &a[i]); for (i = 0; i < n; i++) scanf("%d", &b[i]); for (i = 0, j = 0; i < 3 * ...
17
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 5; int n, st1[4 * N], st2[4 * N], lazy[4 * N], a[N]; string s; void push_down(int id, int l, int r) { if (lazy[id] != 0) { st1[id] += lazy[id]; st2[id] += lazy[id]; if (l < r) { lazy[id << 1] += lazy[id]; lazy[id << 1 | 1] += la...
13
#include <bits/stdc++.h> using namespace std; int w[100010]; bool cmp(int a, int b) { return a > b; } int f(int x) { if (x == 0) return 0; if (x == 1) return 1; if (x % 2 == 1) { return x * (x - 1) / 2 + 1; } if (x % 2 == 0) { return x * (x - 1) / 2 + x / 2; } } int main() { int n, m; memset(w, ...
12
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; string s; cin >> s; while (m--) { int l, r; char c1, c2; cin >> l >> r >> c1 >> c2; for (int i = l; i <= r; i++) { if (s[i - 1] == c1) { s[i - 1] = c2; } } } cout << s; return 0; }...
0
#include <bits/stdc++.h> using namespace std; inline long long bit(long long n) { return 1LL << n; } template <class T> ostream& operator<<(ostream& os, vector<T> x) { for (__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++) os << *it << ' '; return os; } template <class T> inline void dbg(T x) { c...
11
#include <bits/stdc++.h> using namespace std; int main() { string s, t; cin >> s >> t; int pos = 0; for (int i = 0; i < t.length(); i++) { if (s[pos] == t[i]) pos++; } cout << pos + 1; }
0
#include <bits/stdc++.h> using namespace std; const int N = 210; long long read() { long long x = 0, f = 1; char c = getchar(); while (c < '0' || c > '9') { if (c == '-') f = -1; c = getchar(); } while (c >= '0' && c <= '9') { x = x * 10 + c - '0'; c = getchar(); } return x * f; } int n, m...
14
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const long long LINF = 0x3f3f3f3f3f3f3f3f; const int MOD = (int)1e9 + 7; const int N = (int)3e3 + 7; int n, k, ans; int p[N], mxp[N], vis[N][N]; void dfs(int a, int b, int c) { if (vis[a][b]) return; vis[a][b] = 1; ans++; if (b > n || c =...
14
#include <bits/stdc++.h> using namespace std; int c[8][3], p[8]; long long d[28]; int idx0[6] = {0, 0, 1, 1, 2, 2}; int idx1[6] = {1, 2, 0, 2, 0, 1}; int idx2[6] = {2, 1, 2, 0, 1, 0}; inline long long dist(int i, int j, int pi, int pj) { long long dx = 1LL * (c[i][idx0[pi]] - c[j][idx0[pj]]); long long dy = 1LL * (...
12
#include <bits/stdc++.h> using namespace std; const int MAX = 1009; long long dp[MAX][MAX][4], a[MAX][MAX], ans; int main() { int n, m; cin >> n >> m; for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) cin >> a[i][j]; for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) dp[i][j][0] = m...
8
#include <bits/stdc++.h> using namespace std; bool EQ(double a, double b) { double eps = 1e-9; return fabs(a - b) < eps; } bool LT(double a, double b) { return a < b && !EQ(a, b); } bool LTE(double a, double b) { return a < b || EQ(a, b); } struct Point { double x, y; Point(double x = 0, double y = 0) : x(x), y...
18
#include <bits/stdc++.h> using namespace std; const double eps = 1e-9; const int N = 2000; struct yuurei { double x, y; yuurei(double x_, double y_) : x(x_), y(y_) {} yuurei() { x = 0, y = 0; } yuurei operator+(yuurei a) { return yuurei(x + a.x, y + a.y); } yuurei operator-(yuurei a) { return yuurei(x - a.x, ...
21
#include <bits/stdc++.h> long long int x[3], y[3], R[3]; void swp(long long int *x, long long int *y) { *x ^= *y; *y ^= *x; *x ^= *y; } void SolveEqual() { long long int a11, a12, a21, a22; double q1, q2, detA, xa, ya; a11 = x[0] - x[1]; a12 = y[0] - y[1]; a21 = x[0] - x[2]; a22 = y[0] - y[2]; if (a...
18
#include <bits/stdc++.h> using namespace std; bool isPrime(int x) { if (x == 2) return true; if (x % 2 == 0) return false; for (int i = 3; i * i <= x; i += 2) if (x % i == 0) return false; return true; } int cnt = 0; char str[20]; int main() { for (int i = 2; i <= 50; ++i) { if (isPrime(i)) { pr...
6
#include <bits/stdc++.h> using namespace std; void init() {} int ars[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47}; int main() { int counts = 0; char strs[5]; int detectag = 0; for (int i = 0; i < 15; i++) { cout << ars[i] << endl; fflush(stdout); cin >> strs; if (strcmp(strs, "ye...
6
#include <bits/stdc++.h> using namespace std; string host, reso, str, user; void read() { cin >> str; int i = 0, l = str.size(); for (; str[i] != '@' && i < l; i++) user += str[i]; for (i++; str[i] != '/' && i < l; i++) host += str[i]; for (i++; i < l; i++) reso += str[i]; } bool fuser() { int l = user.size...
11
#include <bits/stdc++.h> using namespace std; int n, Array[100005], Suffix_Minimum[100005]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> n; for (int i = 0; i < n; i++) { cin >> Array[i]; } Array[n] = 1e9 + 100; Suffix_Minimum[n] = 1e9 + 100; for (int i = n - 1; i >= 0; i--) { ...
7
#include <bits/stdc++.h> using namespace std; vector<int> adj[200200], b[200200]; int k[200200]; bool pt[200200][2]; map<pair<int, int>, bool> mp; vector<int> dist(200200, INT_MAX); int main() { int N, M; scanf("%d %d", &N, &M); for (int i = 0, u, v; i < M; i++) { scanf("%d %d", &u, &v); adj[v].push_back(...
9
#include <bits/stdc++.h> const int INF = 1e9 + 3123, MOD = 1e9, MAXN = 10000; const long double EPS = 0.000000000001; using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); string s; cin >> s; int n = (long long int)s.size(); int a[100003]; map<int, int>...
9
#include <bits/stdc++.h> using namespace std; char arr[305][305]; int main() { int n; cin >> n; int count = 0; set<char> se; set<char> se2; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { cin >> arr[i][j]; } } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { ...
2
#include <bits/stdc++.h> using namespace std; const int N = 2005, inf = 0x3f3f3f3f; int n, m, pos[N]; long long S; struct vec { long long x, y; void read() { scanf("%I64d %I64d", &x, &y); } void print() { printf("%I64d %I64d\n", x, y); } } a[N]; struct node { int x, y; vec f; } f[N * N]; vec operator+(vec a, ...
19
#include <bits/stdc++.h> using namespace std; string a; set<int> s; int ssss(char k) { if (k == 'D') return 'U'; if (k == 'U') return 'D'; if (k == 'R') return 'L'; if (k == 'L') return 'R'; } map<char, int> f; int main() { int n; cin >> n >> a; int ans = 1; for (int i = 0; i < a.size(); i++) { if (...
6
#include <bits/stdc++.h> using namespace std; int pri[26] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, -1}; long long mo[5] = {223092870ll, 2756205443ll, 907383479ll, 42600829ll, 97ll}; int N, M, d, t, len, i, j, k, u; int b[100]; long long a[2000...
22
#include <bits/stdc++.h> using namespace std; void init() {} long long doit(int n, int md) { long long pow2 = 1ll << md; int num1[21], num2[21]; int p1 = 0, p2 = 0; while (n) { num1[p1++] = n % 10; n /= 10; } while (pow2) { num2[p2++] = pow2 % 10; pow2 /= 10; } reverse(num1, num1 + p1); ...
5
#include <bits/stdc++.h> using namespace std; long long a[1005][1005]; long long visited[1005][1005]; long long n, m; long long dirx[] = {1, 0, -1, 0}; long long diry[] = {0, -1, 0, 1}; long long issafe(long long i, long long j) { if (i >= 0 && i < n && j >= 0 && j < m && a[i][j] && !visited[i][j]) return 1; return...
12
#include <bits/stdc++.h> using namespace std; pair<int, long long> calc(long long m) { long long x, val; pair<int, long long> p, q; if (m <= 7) return pair<int, long long>((int)m, m); for (int i = (2); i < (100010); i++) { x = (long long)i; val = x * x * x; if (val > m) break; } x--; val = x *...
14
#include <bits/stdc++.h> using namespace std; template <typename S, typename T> void fill_(S& buf, T x) { fill(reinterpret_cast<T*>(&buf), reinterpret_cast<T*>(&buf) + sizeof(buf) / sizeof(T), x); } template <typename T, int N> inline int countof(const T (&)[N]) { return N; } template <typename T> inline vec...
10
#include <bits/stdc++.h> using namespace std; const int N = 5e5 + 10; int a[N]; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; while (cin >> n) { for (int i = 1; i <= n; i++) cin >> a[i]; deque<int> v[7]; for (int i = 1; i <= n; i++) if (a[i] == 4) v[1].pus...
5
#include <bits/stdc++.h> using namespace std; inline long long max(long long x, long long y) { return x > y ? x : y; } inline long long min(long long x, long long y) { return x < y ? x : y; } inline void ckmin(long long &x, long long y) { x = x < y ? x : y; return; } inline void ckmax(long long &x, long long y) { ...
18
#include <bits/stdc++.h> using namespace std; const double PI = 2 * acos(0.0); struct mat { double m[3][3]; mat() { for (int i = 0; i < 3; i++) for (int j = 0; j < 3; j++) m[i][j] = 0; } mat operator*(const mat& o) const { mat r = mat(); for (int i = 0; i < 3; i++) for (int j = 0; j < 3;...
17
#include <bits/stdc++.h> using namespace std; const int N = 2e6 + 7; set<int> g[N]; bool fl[N]; int n, m, sum, w[N], pot[N], siz[N], ch[N][2], lt[N], rt[N], val[N], tag[N], pos[N], opt[N], ans[N]; inline int read() { int num = 0; char g = getchar(); while (g < 48 || 57 < g) g = getchar(); while (47 < g && g...
24
#include <bits/stdc++.h> using namespace std; const int maxn = 20000 + 5; int a[maxn]; long long solve(long long n, long long m, long long k, int a[]) { if (n % 2 == 0) return 0; int mm = 1000000000 * 2; for (int i = 0; i < n; i += 2) { mm = min(mm, a[i]); } long long t = (n + 1) / 2; mm = min<long long...
10
#include <bits/stdc++.h> using namespace std; void dan() { int x, y; scanf("%d%d", &x, &y); if (y == 0) { printf("No\n"); } else if (y == 1 && x > 0) { printf("No\n"); } else { y--; int re = x - y; if (re < 0) { printf("No\n"); } else { if (re % 2 == 0) { printf("Ye...
5
#include <bits/stdc++.h> using namespace std; const int N = (int)4e4, OO = 0x3f3f3f3f; long long getSum(long long r) { return (r + 1) * r / 2; } long long sumSoFar(long long r, int need) { long long pw = 1; long long sum = 0; long long add = 0; for (int len = 1;; ++len) { if (pw * 10 - 1 < r) { long l...
10
#include <bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:1024000000,1024000000") int _MAX(int a, int b) { return a > b ? a : b; } int _MIN(int a, int b) { return a > b ? b : a; } int Scan() { int res = 0, flag = 0; char ch; if ((ch = getchar()) == '-') flag = 1; else if (ch >= '0' && ch...
23
#include <bits/stdc++.h> long long gav = 0; int n, dig, k; int num[15]; int arr[15]; int nem[15]; int hana[15]; long long ans; void bctr(int x, int le) { if (x == le) { long long q1 = 1, q2 = 0; if (le != dig) { for (int i = 0; i < le; i++) { if (nem[i] == 0) { if (i == 0) ...
11
#include <bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; enum { MOD0 = 1000000000, MOD7 = 1000000007, MOD9 = 1000000009 }; template <typename T> ostream &operator<<(ostream &cout, vector<T> &a) { for (size_t i = 0; i < a.size(); ++i) cout << a[i] << " "; return cout; } template <typename T> ostream ...
7
#include <bits/stdc++.h> using namespace std; const long long MAXN = 1e6 + 5; long long N, M, f[MAXN], deg[MAXN], ans = 0, cnt = 0, bl, root; bool vis[MAXN]; namespace solution { long long getf(long long k) { if (f[k] == k) return k; f[k] = getf(f[k]); return f[k]; } void Prepare() { scanf("%lld%lld", &N, &M); ...
13
#include <bits/stdc++.h> using namespace std; int n, m, b, mod, i, j, k, a[500], dp[505][505], ans; int main() { scanf("%d%d%d%d", &n, &m, &b, &mod); for (i = 0; i < n; i++) scanf("%d", &a[i]); dp[0][0] = 1; for (i = 0; i < n; i++) for (j = a[i]; j <= b; j++) for (k = 1; k <= m; k++) dp[j][k] ...
10
#include <bits/stdc++.h> using namespace std; const int N = 100005; const int inf = 0x3f3f3f3f; char a[N], b[N]; int len; int modify(int c) { int mn = inf; for (int i = 1; i <= len; ++i) { if (a[i] == b[i]) continue; if (a[i] - 'a' == c) { if (a[i] > b[i]) return -1; mn = min(mn, b[i] - a[i]); ...
9
#include <bits/stdc++.h> using namespace std; int main() { int t1, t2, x1, x2, t0; cin >> t1 >> t2 >> x1 >> x2 >> t0; if ((t1 == t0) && (t2 == t0)) { cout << x1 << " " << x2; return 0; } if (t1 == t0) { cout << x1 << " " << 0; return 0; } if (t2 == t0) { cout << 0 << " " << x2; ret...
11
#include <bits/stdc++.h> using namespace std; int main() { int n, a[105], b[10005]; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < n; i++) { int sum = 0; ; for (int j = 0; j < a[i]; j++) { int k; cin >> k; sum += k; } b[i] = a[i] * 15 + sum...
1