solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> using namespace std; const int maxn = 300010; long long dp[maxn][2], a[maxn], b[maxn]; int main() { int n, m; long long sum1 = 0, sum2 = 0; scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) { scanf("%lld", &a[i]); sum1 += a[i]; } for (int i = 1; i <= n; i++) { scanf("%...
17
#include <bits/stdc++.h> using namespace std; vector<vector<int> > g; vector<int> l, r; int us[109]; void dfs(int v) { us[v] = 1; if (r[v] != -1 && us[r[v]] == 0) { g.back().push_back(r[v]); dfs(r[v]); } } int main() { #pragma warning(disable : 4996) int n; cin >> n; l.resize(n); r.resize(n); fo...
7
#include <bits/stdc++.h> using namespace std; const int MAXN = 1000; const long long INFINITE = (long long)1e15; vector<pair<int, int> > e[MAXN]; vector<pair<int, long long> > e2[MAXN]; long long cost[MAXN][MAXN]; int n, m, x, y, u, v, w; bool visit[MAXN]; long long d[MAXN]; void gao(int st, int le, int cs) { for (in...
11
#include <bits/stdc++.h> using namespace std; int arr[4][4]; int main() { for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { cin >> arr[i][j]; } } for (int i = 0; i < 4; i++) { if (arr[i][0] && arr[(i + 3) % 4][3] || arr[i][1] && arr[(i + 2) % 4][3] || arr[i][2] && arr[(i + 1) %...
4
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const int M = 110; const int mod = 1e9 + 7; const double eps = 1e-8; const double Pi = 2 * acos(0.0); inline int max(int a, int b) { return a > b ? a : b; } inline int min(int a, int b) { return a < b ? a : b; } inline int bit(int x) { return 1 <...
5
#include <bits/stdc++.h> using namespace std; struct cord { long long int x, y; }; int main(int argc, const char* argv[]) { cord home, dest; cin >> home.x >> home.y; cin >> dest.x >> dest.y; long long int n, x, y, z; cin >> n; long long int ans = 0; for (int i = 0; i < n; i++) { cin >> x >> y >> z; ...
9
#include <bits/stdc++.h> using namespace std; const int N = 1125; int main() { int n, m; cin >> n >> m; string a = ""; int rem = n; while (rem > 0) { int x = min(rem, 9); a += (char)(x + '0'); rem -= x; } string b = ""; int sum = 0; for (int i = a.size() - 1; i >= 0; --i) { int val = (...
4
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); string s; cin >> s; string ans = ""; for (int i = 0; i < s.size(); i++) { if (s[i] == '-') { if (s[i + 1] == '.') ans += '1'; else ans += '2'; i++; } else ans += '0...
0
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; const auto INF = 0x3f3f3f3f; const int N = 1e5 + 5; int A[4][4], B[4][4]; int visit[4][4]; pair<int, int> pre[N]; int Ans[4][4]; int main() { Ans[3][2] = 1; Ans[2][1] = 1; Ans[1][3] = 1; long long k; int a, b; scanf("%lld%d%d", &k, &a, &...
10
#include <bits/stdc++.h> using namespace std; const long long N = 500010; long long n, i, j, k, l, m, ar[N] = {0}, u, v, x, r, a, b, c, d, od = 0, ev = 0, ar1[N] = {0}, p, hi, lo, mid, s, y, t, res = 0; map<long long, long long> mp, mp1; vector<long long> vc, vc1, v2d[N]; long long vis[N] = ...
5
#include <bits/stdc++.h> using namespace std; template <class T> T abs(T x) { return x > 0 ? x : (-x); } template <class T> T sqr(T x) { return x * x; } const int maxn = 500; int d[maxn][maxn]; vector<pair<int, int> > head, tail; vector<pair<int, int> > moves[maxn][maxn]; int deg[maxn][maxn]; int opt[maxn][maxn]; i...
13
#include <bits/stdc++.h> using namespace std; int main() { long long a, b; cin >> a >> b; if (b - a < 10) { int ans = 1; for (long long i = a + 1; i <= b; i++) { ans *= (i % 10); ans %= 10; } cout << ans << endl; return 0; } cout << 0 << endl; return 0; }
3
#include <bits/stdc++.h> using namespace std; namespace Fast_read { inline char gc() { static char buf[100000], *p1 = buf, *p2 = buf; return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2) ? EOF : *p1++; } template <typename T> inline void read(T &x) { x = (T)0; ...
21
#include <bits/stdc++.h> using namespace std; int n, freq[15], r; string ans[] = {"1869", "6819", "9186", "6198", "1698", "1986", "1896"}; string s; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> s; n = s.size(); freq[1] = freq[6] = freq[8] = freq[9] = -1; for (int i = 0; i < n...
8
#include <bits/stdc++.h> using namespace std; priority_queue<long> q; vector<pair<long, long long> > vv[100001]; long n, m, i, j, p[100001], x, y, c; long long d[100001]; void prt(long x) { if (x != 1) prt(p[x]); cout << x << " "; } int main() { cin >> n >> m; while (m--) { cin >> x >> y >> c; vv[x].pus...
11
#include <bits/stdc++.h> using namespace std; int n; void solve(int ar[][2]) { if (n < 5) { cout << 0 << endl; return; } int ans = 0; for (int i = 0; i < n; ++i) { int cont1(0), cont2(0), cont3(0), cont4(0); for (int k = 0; k < n; ++k) { if (ar[i][0] > ar[k][0] && ar[i][0 + 1] == ar[k][0 +...
2
#include <bits/stdc++.h> using namespace std; const int INF = 1 << 26; int in[1010], g[1010], d[1010]; int tap = -1, sol = 0, mind = INF; void dfs(int v) { if (g[v]) { mind = min(mind, d[v]); dfs(g[v]); } else tap = v; } int main() { int n, p, i, a, b, dia; scanf("%d%d", &n, &p); for (i = 0; i <= ...
6
#include <bits/stdc++.h> using namespace std; const int N = 50; int remain[N], len, n; inline void Divide(long long T) { while (T) remain[++len] = T % 6, T /= 6; reverse(remain + 1, remain + len + 1); n = len * 2 + 2; } struct node { int x1, y1, x2, y2; }; vector<node> ans; inline void print(int x1, int y1, int...
23
#include <bits/stdc++.h> using namespace std; int main() { int n, a[1050], b[1050]; cin >> n; int aa = 0, bb = 0; for (int i = 0; i < n; i++) { cin >> a[i]; if (a[i] == 1) aa++; } for (int i = 0; i < n; i++) { cin >> b[i]; if (b[i] == 1) bb++; } int t = 0; for (int i = 0; i < n; i++) ...
1
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; set<int> s; int main() { int q; scanf("%d", &q); int lo = 0, hi = 1e9; s.insert(lo), s.insert(hi); long long ans = 1; while (q--) { char c[10]; int x; scanf("%s %d", c, &x); if (c[1] == 'D') s.insert(x); else { ...
13
#include <bits/stdc++.h> using namespace std; vector<int> sTree; void build(int left, int right, int ind, vector<int> &arr) { if (left == right) { sTree[ind] = arr[left]; return; } int lTree = ind * 2, rTree = lTree + 1; int mid = (left + right) / 2; build(left, mid, lTree, arr); build(mid + 1, righ...
10
#include <bits/stdc++.h> using namespace std; template <typename T> T sqr(T x) { return x * x; } template <typename T> void read(T &x) { int f = 1; x = 0; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == '-') f = -f; for (; isdigit(c); c = getchar()) x = x * 10 + c - '0'; x *= f; } int ...
24
#include <bits/stdc++.h> using namespace std; int a[2001][2001], n, b[2001][2001]; int dx[8] = {1, -1, 0, 0, -1, 1, 1, -1}; int dy[8] = {0, 0, 1, -1, 1, -1, 1, -1}; int xx[4]{1, 0, 1, 2}; int yy[4] = {0, 1, 2, 1}; struct Point { int x, y; bool operator<(const Point& b) const { return x < b.x || (x == b.x && y <...
15
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e5 + 5; template <typename T> void chkmax(T &x, T y) { x = max(x, y); } template <typename T> void chkmin(T &x, T y) { x = min(x, y); } template <typename T> void read(T &x) { x = 0; int f = 1; char c = getchar(); for (; !isdigit(c); c = getcha...
24
#include <bits/stdc++.h> using namespace ::std; const int maxn = 5003; const int mod = 1e9 + 7; const int inf = 1e9 + 500; int dp[maxn][maxn]; int pr[maxn][maxn]; int p[maxn]; int s[maxn]; int a[maxn]; int main() { int n; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = n - 1; i >= 0; i...
13
#include <bits/stdc++.h> using namespace std; const long long const1 = 1e9 + 7; vector<vector<long long> > g; vector<long long> used; bool flag = false; set<long long> X, Y; long long power(long long a, long long b) { if (b == 0) { return 1; } else if (b % 2 == 0) { long long t = power(a, b / 2); return...
15
#include <bits/stdc++.h> using namespace std; namespace IPT { template <class T> void read(T &x) { x = 0; char ch = getchar(); while (!isdigit(ch)) ch = getchar(); while (isdigit(ch)) x = x * 10 + ch - 48, ch = getchar(); } } // namespace IPT namespace OPT { template <class T> void write(T x) { if (x > 9) wr...
2
#include <bits/stdc++.h> using namespace std; int n, k; long long res = 0; vector<int> e[200000]; long long v[200000][6], sum[200000]; long long r[6]; void dfs(int x, int f) { for (auto i : e[x]) { if (i == f) continue; dfs(i, x); rotate(v[i], v[i] + k - 1, v[i] + k); for (int j = 0; j < k; j++) v[x][...
13
#include <bits/stdc++.h> using namespace std; int n, ar[300001][2] = {}, ans[300001] = {}; deque<pair<int, int> > mx[2] = {}; int main() { ios ::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; for (int i = 0; i < n; i++) { cin >> ar[i][0]; ar[i][1] = ar[i][0]; ans[n - 1] = max(ans[n - 1], a...
20
#include <bits/stdc++.h> using namespace std; const long long N = 3e5 + 10; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long n, a, b, m; long long s1, s2; s1 = 0; s2 = 0; a = 0; b = 0; cin >> n; vector<long long> arr(N + 5); for (int i = 0; i < n; i++) { cin >> ar...
8
#include <bits/stdc++.h> using namespace std; bool myfunction(const pair<int, long long>& a, const pair<int, long long>& b) { return a.second > b.second; } vector<pair<int, int> > dots; bool taken[8]; bool findAndMark(int x, int y) { for (__typeof(dots.size()) i = 0; i < dots.size(); i++) { if (taken[i]) contin...
8
#include <bits/stdc++.h> using namespace std; int main() { double a, b, c, d, m, v; cin >> a >> b >> c >> d; m = max(3 * a / 10, a - a / 250 * c); v = max(3 * b / 10, b - b / 250 * d); if (m == v) cout << "Tie"; else if (m > v) cout << "Misha"; else cout << "Vasya"; return 0; }
1
#include <bits/stdc++.h> using namespace std; const int INF = 1e9; const long long INF64 = 4e18; const int M = 3 * 10; const int N = 1 * 100 * 1000 + 100; const int MOD = 1e9 + 7; const double EPS = 1e-9; const double PI = 3.14159265359; long long gcd(long long a, long long b) { return a == 0 ? b : gcd(b % a, a); } set...
14
#include <bits/stdc++.h> using namespace std; int n; char s[3010], c; int main() { int i, j, k; scanf("%s", s + 1); n = strlen(s + 1); for (i = 1; i <= n; i = j) { for (j = i; j <= n; j++) { int cnt = 0; for (k = i; k <= j; k++) { c = s[k]; bool flag1 = c == 'a' || c == 'e' || c ...
7
#include <bits/stdc++.h> using namespace std; int a[3003], dp1[3003][3003][3], dp2[3003][3003][3], n, r; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d", &a[i]); for (int i = 1; i <= n; i++) { for (int j = i, a1 = 0, a2 = 0, a12 = 0; j <= n; j++) { if (a[j] == 1) ++a1; ...
10
#include <bits/stdc++.h> using namespace std; long long mod = 998244353; long long f[500005]; long long pow(int a, int b, int MOD) { long long x = 1, y = a; while (b > 0) { if (b % 2 == 1) { x = (x * y); if (x > MOD) x %= MOD; } y = (y * y); if (y > MOD) y %= MOD; b /= 2; } retur...
10
#include <bits/stdc++.h> using namespace std; inline char nc() { static char buf[100000], *p1 = buf, *p2 = buf; return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2) ? EOF : *p1++; } inline void read(int &x) { char c = nc(), b = 1; for (; !(c >= '0' && c <= '9')...
21
#include <bits/stdc++.h> using namespace std; void gao(int n) { for (int i = 2; i * i < n; i++) { if (n % i == 0) { for (int j = i + 1; j * j < n / i; j++) { if (n / i % j == 0) { cout << "YES" << endl; cout << i << ' ' << j << ' ' << n / i / j << endl; return; ...
5
#include <bits/stdc++.h> using namespace std; template <typename T> inline T abs(T n) { return (n < 0 ? -n : n); } template <typename T> inline T sqr(T n) { return (n * n); } int a[1010][1010], n, m; bool big[1010][1010]; vector<int> pos; bool check(int val) { memset(big, 0, sizeof big); for (int i = 0; i < n; ...
13
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10; int n, k, m; struct node { string s; long long cost; friend bool operator<(const node &n1, const node &n2) { return n1.cost > n2.cost; } } word[maxn]; priority_queue<node> pq[maxn]; map<string, int> mp; int main() { cin >> n >> k >> ...
4
#include <bits/stdc++.h> using namespace std; const int INF = (int)1e9; const long double EPS = 1e-9; const long double PI = 3.1415926535897932384626433832795; const int N = 100; const int dx[] = {0, 0, 1, -1}; const int dy[] = {1, -1, 0, 0}; int n, m, k; char a[N][N]; inline int sign(int a) { if (a == 0) return 0; ...
16
#include <bits/stdc++.h> using namespace std; template <class T> T &get(T &n) { cin >> n; return n; } const int hell = 1000000007; const long long INF = (long long)hell * hell; const int MAXN = 1e2 + 4; const int MAXA = 1e6; const int MAXC = 1124 + 1; int main() { ios::sync_with_stdio(false); cin.tie(0); cout...
4
#include <bits/stdc++.h> using namespace std; const int N = 1e7 + 5; int v[N], p[N], fi[N], g[N]; long long ans, tmp; int main() { int n, t = 0; scanf("%d", &n); for (register int i = 2; i <= n; ++i) { if (!v[i]) v[i] = p[++t] = i, fi[i] = i - 1; for (register int j = 1; j <= t && i * p[j] <= n; ++j) { ...
19
#include <bits/stdc++.h> using namespace std; template <typename T> void print(vector<T>& v) { for (int i = 0; i < v.size(); i++) { cout << v[i] << ' '; } cout << '\n'; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); string s; cin >> s; int n = s.length(); set<string> Set; if (n ...
10
#include <algorithm> #include <array> #include <bitset> #include <cassert> #include <chrono> #include <cmath> #include <fstream> #include <functional> #include <iomanip> #include <ios> #include <iostream> #include <iterator> #include <limits> #include <list> #include <map> #include <numeric> #include <queue> #include <...
12
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; int bills = 0; if (n >= 100) { bills += n / 100; n %= 100; } if (n >= 20) { bills += n / 20; n %= 20; } if (n >= 10) { bills += n / 10; n %= 10; } if (n >= 5) ...
0
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 3; long long MOD = 1e9 + 7; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; vector<string> a(n), b(n); map<string, int> ma, mb; for (int i = 0; i < n; i++) { cin >> a[i]; ma[a[i]]++; } for (int ...
4
#include <bits/stdc++.h> using namespace std; long n, m, k, ar1[200000], s[200000], ar2[200000], l, r, c; int main() { ios_base::sync_with_stdio(0); cin >> n; cin >> m; cin >> k; for (int i = 1; i <= n; i++) cin >> ar1[i]; for (int i = 1; i <= m; i++) cin >> ar2[i]; for (int i = 1; i <= m; i++) s[i] = s[i...
7
#include <bits/stdc++.h> using namespace std; void islam() { std::ios::sync_with_stdio(false); cin.tie(NULL); } int main() { islam(); int g[10][10]; for (int i = 0; i < 5; ++i) for (int j = 0; j < 5; ++j) cin >> g[i][j]; int ans = -1, tmp; int p[6] = {0, 1, 2, 3, 4}; int i = 0; tmp = g[p[0]][p[1]]...
4
#include <bits/stdc++.h> using namespace std; int D[4][4]; int N2, N3[3], N4[7]; int main() { for (int i = 0; i < 4; i++) for (int j = i + 1; j < 4; j++) cin >> D[i][j]; N2 = D[0][1]; for (int i = 0; i <= N2; i++) { N3[0] = i, N3[1] = N2 - i, N3[2] = D[0][2] - i; if (N3[1] + N3[2] == D[1][2]) goto don...
16
#include <bits/stdc++.h> using namespace std; const int MN = 200; vector<string> str(MN + 5); vector<set<string> > sub(MN + 5); int N, K; void get_sub(const string& s, set<string>& sub) { for (int i = 0; i < s.size(); i++) { for (int j = 1; j <= min((int)s.size(), 10); j++) { if (i + j > s.size()) break; ...
14
#include <bits/stdc++.h> using namespace std; int mod(int x, int N) { return (x % N + N) % N; } char g[5001][5001]; int dp[5001][5001], n, m; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> m; for (int i = 0; i < n; i++) cin >> g[i]; for (int i = 0; i < n; i++) for (int j = 0;...
8
#include <bits/stdc++.h> using namespace std; inline int read() { int x = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); } return x * f; } int n, m, op, len, sign...
17
#include <bits/stdc++.h> using namespace std; long long num; vector<long long> len; vector<long long> vec; long long dis[21][21]; long long dp[1 << 21]; long long dfs[10005]; bool delim[10005]; long long n, k, l; int recur(long long mask) { long long &res = dp[mask]; if (res != -1) return res; vector<int> bits; ...
20
#include <bits/stdc++.h> using namespace std; const long long inf = 1e18, mod = 1e9 + 7, N = 1e5; const long double eps = 1e-6; const long long MAXN = 300002; const long long lg = 20; void solve() { long long n, k; cin >> n >> k; vector<long long> a(n); for (long long i = 0; i < n; ++i) { cin >> a[i]; } ...
9
#include <bits/stdc++.h> using namespace std; const double eps = 1e-8; const int inf = 0x3f3f3f3f; const int Minf = 0x7f7f7f7f; const long long INF = 0x3f3f3f3f3f3f3f3fll; const long long MINF = 0x7f7f7f7f7f7f7f7fll; const int N = 1e6 + 50; long long val[N], fa[N]; int pp[N], ps[N]; int to[N][2], cnt[N * 2]; int main()...
21
#include <bits/stdc++.h> using namespace std; long long int n, t, m; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> t; while (t--) { cin >> n >> m; long long int x, y, diff = 0, ans = 0, mx = 0; pair<long long int, long long int> p; for (int i = 0; i < n; i++) { cin >...
8
#include <bits/stdc++.h> using namespace std; long long graph[1002][1002]; long long q[1002]; vector<pair<long long, int> > sortedq; long long int mincost[1002]; int main() { int n; scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%lld", &q[i]); sortedq.push_back(make_pair(-q[i], i)); } sort(sor...
7
#include <bits/stdc++.h> using namespace std; int dx[4] = {0, 0, -1, 1}; int dy[4] = {1, -1, 0, 0}; char ch[1600][1600]; int visit[1600][1600]; const int maxn = 750000; map<int, bool> was[2000000]; int n, m; void dfs(int x, int y) { if (ch[(x % n + n) % n][(y % m + m) % m] == '#') { return; } if (visit[(x % n...
12
#include <bits/stdc++.h> using namespace std; int o, p; int a[110]; int main() { int n; cin >> n; int cnt = 0, cnt_1 = 0; for (int i = 0; i < n; i++) { cin >> a[i]; if (a[i] % 2 == 0) cnt++; else cnt_1++; } if (cnt > cnt_1) { for (int j = 0; j < n; j++) { if (a[j] % 2 != 0)...
5
#include <bits/stdc++.h> using namespace std; const char IO_MODE = 3; inline long long ReadInt() { long long x = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); } ...
13
#include <bits/stdc++.h> using namespace std; int f[3][200001]; void Read(int cnt, ...) { static char buf[10000000]; static int pos = -2; if (pos == -2) { fread(buf, 1, 10000000, stdin); pos = -1; } va_list li; va_start(li, cnt); for (int i = 0; i < cnt; i++) { int &x = *va_arg(li, int *); ...
20
#include <bits/stdc++.h> using namespace std; const char nl = '\n'; void slove() { int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } int dem = 0; vector<int> b; for (int i = 1; i < a.size(); i++) { if (a[i] <= a[i - 1]) { b.push_back(a[i - 1]); dem++; ...
0
#include<cstdio> #include<vector> using namespace std; const long long mod=998244353; int N1,N2,M; int pr[4<<17],hs[4<<17],hn[4<<17],pe[4<<17],pc[4<<17]; int ai[4<<17][2]; int ans,eh=1,id; vector<int>es; bool usd[4<<17]; void adj(int ei,vector<int>&a,int j) { int pei=-1; int cnt=0; while(ei!=-1) { usd[ei]=true; ...
23
#include <bits/stdc++.h> using namespace std; int main(int argc, char **argv) { int n; cin >> n; vector<int> indegrees(n); int in, out; for (int i = 0; i < n - 1; i++) { cin >> out >> in; indegrees[in - 1] += 1; indegrees[out - 1] += 1; } int count = count_if(indegrees.begin(), indegrees.end()...
2
#include <bits/stdc++.h> using namespace std; const int N = 200005; const double PI = acos(-1); struct Point { double x, y; }; inline Point operator+(const Point &a, const Point &b) { return {a.x + b.x, a.y + b.y}; } inline Point operator-(const Point &a, const Point &b) { return {a.x - b.x, a.y - b.y}; } inline ...
23
#include <bits/stdc++.h> using namespace std; #define ll long long int int main() { ll t,n,m,d; cin>>t; while(t--) { cin>>n>>m>>d; if(d==n*m-1) cout<<"yes"<<endl; else cout<<"no"<<endl; }}
0
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; const int M = 1024; const int MD = 1e9 + 7; unsigned long long n, m, k; int a, b; vector<int> g[N]; bool vis[N]; int dp[M][M]; unsigned long long arr[N]; unsigned long long x; int main() { cin.tie(0); ios::sync_with_stdio(0); for (int i = 1; i <...
4
#include <bits/stdc++.h> using namespace std; int i, j, k, n, m, num; int hpa, dta, la, ra, hpb, dtb, lb, rb, xa, xb; int c[70], F[70], g[70], ff[70]; double pa, pb, f[210][210][70], a[70], b[70], g1[210][210][70], g2[210][210][70], an[70], a1[70], a2[70]; vector<int> huan, e[70]; void dfs(int x) { g[++*g] = x; ...
16
#include <bits/stdc++.h> using namespace std; const long long N = 2e5 + 5; long long n, k, cnt; long long a[N], f[N], id[N], rk[N], pre[N], ans[N]; struct Malygos { Malygos() { Smin = 1e16; base = 0; } long long Smin, base; } otk[N]; long long read() { long long s = 0, w = 1; char ch = getchar(); wh...
12
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; long long sum = 0, suma = 0, sumb = 0; cin >> n; long long arr[n]; for (int i = 0; i < n; i++) { cin >> arr[i]; sum += arr[i]; } if (sum % 2 == 1 || n < 2) { cout << "NO" << e...
11
#include <bits/stdc++.h> using namespace std; void lines(int n, int l = 2) { char first = '#', last = '#', mid = '#'; if (l == 1) last = mid = '.'; if (l == 3) first = mid = '.'; cout << first; for (int i = 1; i < n - 1; i++) cout << mid; cout << last << endl; } int main() { int n, m, i, j, dir = 0; cin...
0
#include <bits/stdc++.h> using namespace std; const long double EPS = 1e-9, PI = acos(-1.); const long long LINF = 0x3f3f3f3f3f3f3f3f, LMOD = 1011112131415161719ll; const int INF = 0x3f3f3f3f, MOD = 1e9 + 7; const int N = 1e5 + 5; long long n, xa, xb, a[N], b[N]; pair<long long, long long> y[N]; int main() { scanf("%...
8
#include <bits/stdc++.h> class BasicInteger { public: int size_; std::vector<int> v; void resize(int size__) { size_ = size__; v.resize(size_, 0); } int digit() { int digit = 1; for (int i = size_ - 1; i >= 1; i--) { if (v[i] != 0) { digit = i + 1; break; } } ...
23
#include <bits/stdc++.h> using namespace std; const long long INF = 1e+15; const long long MOD = 998244353; class ModInt { public: long long v; ModInt(long long _v = 0) { v = _v; } ModInt operator+(long long n) { return ModInt((v + n) % MOD); } ModInt operator-(long long n) { return ModInt((v - n + MOD) % MOD)...
16
#include <bits/stdc++.h> using namespace std; inline void read(int &x) { int v = 0, f = 1; char c = getchar(); while (!isdigit(c) && c != '-') c = getchar(); if (c == '-') f = -1; else v = (c & 15); while (isdigit(c = getchar())) v = (v << 1) + (v << 3) + (c & 15); x = v * f; } inline void read(lo...
19
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(NULL); int n, m; cin >> n >> m; vector<int> c(n); map<int, set<int>> c_q; for (int i = 0; i < n; ++i) { cin >> c[i]; c_q[c[i]]; } for (int i = 0; i < m; ++i) { int ...
8
#include <bits/stdc++.h> using namespace std; vector<vector<int>> g; vector<vector<int>> nodes; void yn(bool a) { if (a) { cout << "YES" << endl; } else { cout << "NO" << endl; } } void dfs(int curr, int par, int dist, int currdist) { nodes[currdist].push_back(curr); if (currdist == dist) { return...
16
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; int base[2], p[N], vis[N], n; bool in[N]; vector<int> ans; bool dfs(int cur, int step) { vis[cur] = step; ans.push_back(cur); if (!vis[p[cur]]) return dfs(p[cur], step + 1); int t = step + 1 - vis[p[cur]]; return base[0] == base[1] || t == 1...
13
#include <bits/stdc++.h> using namespace std; const int N = 105; int n, K, m; int f[1005][105][4]; void work() { scanf("%d%d%d", &n, &K, &m); f[n][0][0] = 1; int i, j, k, l, x; x = 1; for (i = n; i > 0; --i) { for (j = 0; j < K; ++j) { for (k = 0; k < 4; ++k) { if (!f[i][j][k]) continue; ...
14
#include <bits/stdc++.h> using namespace std; inline int read() { int x, f = 1; char c; while ((c = getchar()) < '0' || c > '9') if (c == '-') f = -1; for (x = c - '0'; (c = getchar()) >= '0' && c <= '9';) x = (x << 3) + (x << 1) + c - '0'; return x * f; } struct node { int l, r, mk, mx; } t[400000 ...
10
#include <bits/stdc++.h> using namespace std; char s[200004]; char t[200004]; int R[200004]; int main() { scanf("%s", s); scanf("%s", t); int m = strlen(t); int n = strlen(s); int j = m - 1; int i = n - 1; R[m] = n; while (s[i] != t[j]) { i--; } R[j--] = i; while (j >= 0) { i--; while ...
9
#include <bits/stdc++.h> std::mt19937 rd(time(0)); const int MAXN = 100010; const int mod = 1004535809; void reduce(int& x) { x += x >> 31 & mod; } int mul(int a, int b) { return (long long)a * b % mod; } int pow(int a, int b, int res = 1) { for (; b; b >>= 1, a = mul(a, a)) if (b & 1) res = mul(res, a); return...
21
#include <bits/stdc++.h> using namespace std; const long long MAXN = 2e3 + 10; char c[MAXN][MAXN], sc[MAXN][MAXN]; long long dn[MAXN][MAXN], ri[MAXN][MAXN], le[MAXN][MAXN], up[MAXN][MAXN], p[MAXN][MAXN], d[MAXN][MAXN]; long long n, m, aa, bb, cc, dd; void rotate() { for (long long i = 0; i < n; i++) for (long...
15
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int q; cin >> q; for (int x = 0; x < q; x++) { int n; cin >> n; string first, second; cin >> first >> second; if (first == second) { cout << "Yes\n"; continue; } ...
2
#include <bits/stdc++.h> using namespace std; const int maxn = 2005; int v[maxn][maxn], d[maxn][maxn]; int n, m, k; int a, b; bool ok(int x, int y, int k) { int t, l = max(1, x - k), r = min(x + k, n); for (int i = l; i <= r; i++) { t = k - abs(i - x); if (y - t >= 1 && !v[i][y - t]) { a = i, b = y - ...
16
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; if (s.size() == 1) cout << 0 << endl; else { long long int sum = 0; for (int i = 0; i < s.size(); i++) sum += (s[i] - '0'); int cnt = 1; while (sum > 9) { long long int n = sum; sum = 0; while (n...
2
#include <bits/stdc++.h> using namespace std; int ind[1048577]; int main() { int n; int a[100005]; cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; vector<int> dp[2]; map<int, int> mp; memset(ind, 0, sizeof(ind)); dp[1].push_back(a[0]); ind[a[0]] = 1; for (int i = 1; i < n; i++) { for (int j =...
8
#include <bits/stdc++.h> using namespace std; const long long N = 101; long long adj[N][N], color[N], cross[N]; bool vis[N]; void dfs(long long s, long long n, long long c) { color[s] = c; vis[s] = 1; for (long long i = 1; i <= n; i++) { if (adj[s][i] && !vis[i]) { dfs(i, n, !c); } else if ((adj[s][...
9
#include <bits/stdc++.h> using namespace std; const long long mod = 998244353; const long long inf = 1LL << 62; struct Mine { long long x, y, timer; long long x_pos, y_pos; long long comp_num; Mine() : x(0), y(0), timer(0), x_pos(-1), y_pos(-1), comp_num(-1) {} Mine(long long xx, long long yy, long long tm) ...
12
#include <bits/stdc++.h> using namespace std; int main() { char c; do { c = cin.get(); if (c == '\"') { cout << "<"; while ((c = cin.get()) != '\"') cout << c; cout << ">\n"; } else if (c != ' ' && c != 10) { cout << "<"; do { cout << c; } while ((c = cin.get(...
5
#include <bits/stdc++.h> using namespace std; int a[200005], n; int f(int x, int l, int r) { if (l == r) return 0; int index = lower_bound(a + l, a + r + 1, ((a[l] >> (x + 1)) << (x + 1)) + (1 << x)) - a; if (index == l || index == l + 1) return f(x - 1, index, r); else if (index == r || index =...
13
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long a, b, g; cin >> a >> b; while (a != 0 && b != 0) { if (a >= (2 * b)) { g = a / (2 * b); g *= 2 * b; a -= g; } else if (b >= (2 * a)) { g = b / (2 * a); g ...
3
#include <bits/stdc++.h> using namespace std; int a[5005][3], n, tot, h[3], p[3], pst[3], ans, dp[2][91][91][91]; int score[6] = {500, 1000, 1500, 2000, 2500, 3000}, xx[6], yy[6], maxx; inline int calc(int s, int t) { if (!t) return 0; return s * (250 - t) / 250; } inline void solve(int f, int s, int t) { int k =...
23
#include <bits/stdc++.h> using namespace std; const int MX = 300000; long long a[MX], b[MX]; int main() { srand(time(NULL)); int n = 2; ignore = scanf("%d", &n); for (int i = 0; i < n; i++) { ignore = scanf("%lld", a + i); a[i] *= n; a[i] += i; } for (int i = 0; i < n; i++) { ignore = scanf(...
15
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); string s, t, o; cin >> s >> t; o = s; while (s < t) { s[s.size() - 1]++; for (int i = s.size() - 1; i; i--) { if (s[i] > 'z') { s[i] = 'a'; s[i - 1]++; ...
8
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; long long i = 0; while (s[i] != '^' && i < s.size()) i++; long long left = 0; long long right = 0; for (long long j = 0; j < i; j++) if (s[j] != '=') left += 1ll * (s[j] - '0') * (i - j); for (long long j = i + 1; j < s.s...
1
#include <bits/stdc++.h> using namespace std; const int N = 110; int n, k; double f[2][N][N]; double tmp[N][N]; int a[N]; void dp() { double p = 1.0 * n * (n + 1) / 2.0; for (int tt = 1; tt <= k; tt++) { for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) f[tt % 2][i][j] = 0; for (int i = 1; i <...
16
#include <bits/stdc++.h> using namespace std; class Solution { public: vector<long long> permutation(const vector<int>& q, int n) { vector<long long> res = {0ll}; long long minv = 0; for (int e : q) { minv = min(minv, res.back() + e); res.push_back(res.back() + e); } long long diff = ...
7
#include <bits/stdc++.h> using namespace std; enum color { BLACK, WHITE, GRAY }; signed main() { int i, j, k; int N, S; scanf("%d%d", &N, &S); int a[N]; for (i = 0; i < N - 1; i++) { a[i] = 1; } a[N - 1] = (S - N + 1); if (a[N - 1] <= 0) { printf("NO\n"); return 0; } int pref = 0, suff =...
6