solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> using namespace std; const int maxn = 4e5 + 3; int rt[101], rub[maxn << 5], top; struct SegmenTree { int lson, rson, sum; }; SegmenTree tree[maxn << 2]; int read() { int ret = 0, f = 1; char x = getchar(); while (!isdigit(x)) { if (x == '-') f = -1; x = getchar(); } while (i...
17
#include <bits/stdc++.h> using namespace std; const int N = 1e6; template <typename T> bool cmax(T &a, T b) { return (a < b) ? a = b, 1 : 0; } template <typename T> bool cmin(T &a, T b) { return (a > b) ? a = b, 1 : 0; } template <typename T> T read() { T ans = 0, f = 1; char ch = getchar(); while (!isdigit(c...
13
#include <bits/stdc++.h> using namespace std; long long f[200007]; long long a[200007]; long long b[200007]; long long elm[200007]; vector<long long> co; long long bigMod(long long x, long long n) { if (n == 0) return 1; long long temp = bigMod(x, n / 2); return n % 2 == 0 ? (temp * temp) % 1000000007 ...
14
#include <bits/stdc++.h> using namespace std; const int N = 100005, pw[6] = {1, 10, 100, 1000, 10000, 100000}, P = 1000000007; int n, m, a[N], b[N], len[N], dis[N], f[N], tot, ch[6 * N][10], fa[6 * N][20], dep[6 * N], num[6 * N]; vector<int> g[N], g2[N]; int kth(int u, int k) { for (int i = 19; i >= 0; --i) i...
18
#include <bits/stdc++.h> using namespace std; int i, j, n, m, a, b, c, d, op, maxi, mini, mij, ls, ld, ul, timp, k, l, r, ok; vector<pair<pair<int, int>, int> > v; int sol[1000005]; set<pair<int, int> > myset; set<pair<int, int> >::iterator it; int nr[1000005]; int main() { ios_base::sync_with_stdio(false); cin.tie...
13
#include <bits/stdc++.h> using namespace std; size_t getPowIdx(int number, const vector<int>& powersOfTwo) { size_t i = 1; while (number % powersOfTwo[i] == 0) { ++i; } return i - 1; } void solve(vector<int>& result, int n, int k) { if (n == 1) { result.insert(result.end(), {k}); return; } else ...
8
#include <bits/stdc++.h> using namespace std; vector<vector<long long> > dp; long long calc(int n, int h) { if (dp[n][h] != -1) return dp[n][h]; if (n < h or h == 0) return dp[n][h] = 0; long long r = 0; for (int i = 0; i < n; ++i) { for (int j = 0; j < h - 1; ++j) { r += 2 * calc(i, j) * calc(n - i -...
11
#include <bits/stdc++.h> using namespace std; const int maxtreetop = 600000; struct Ttree { int left, right, zuo, you, totge, zd, pos; } tree[maxtreetop + 1]; map<int, int> a; int n, ge; void init_tree(int p, int start, int stop) { int mid; tree[p].totge = 0; tree[p].zd = 0; tree[p].left = start; tree[p].ri...
14
#include <bits/stdc++.h> using namespace std; const int MaxN = int(2e5) + 256; const int INF = int(1e9); const int mod = (int)(1e9) + 7; const long double pi = 3.1415926535897932384626433832795; long double ans, a[MaxN], d[MaxN]; long long n, m; pair<long double, int> p[MaxN]; long double t[MaxN * 8]; long double get(i...
12
#include <bits/stdc++.h> using namespace std; int a[2005], b[2005]; int main() { int n, m; cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; cin >> m; for (int i = 1; i <= m; i++) cin >> b[i]; printf("%d %d\n", *max_element(a + 1, a + n + 1), *max_element(b + 1, b + m + 1)); }
0
#include <bits/stdc++.h> inline int read() { int data = 0, w = 1; char ch = getchar(); while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar(); if (ch == '-') w = -1, ch = getchar(); while (ch >= '0' && ch <= '9') data = data * 10 + (ch ^ 48), ch = getchar(); return data * w; } const int N(205), LIM(2001...
15
#include <bits/stdc++.h> using namespace std; long long a; int main() { long long n, mx = 0, i, sum = 0, m, k; cin >> n; for (i = 0; i < n; i++) { cin >> a; mx = max(mx, a); sum += a; } if (mx * (n - 1) >= sum) { cout << mx; return 0; } else { m = sum - mx * (n - 1); k = m / (n -...
8
#include<bits/stdc++.h> #define int long long using namespace std; const int maxn=200005; int t,n,m,a[maxn],b[maxn],sum1[maxn],sum2[maxn]; int read()//快读 { int x=0,f=1;char ch=getchar(); while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}//读符号 while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}//读数字 return x*f; } ...
10
#include <bits/stdc++.h> using namespace std; int arr[26], brr[26]; int main() { string a, b, x, y; cin >> a >> b; for (int i = 0; i < a.length(); i++) arr[a[i] - 'a']++; for (int i = 0; i < b.length(); i++) brr[b[i] - 'a']++; int ans = 0, min; for (int i = 0; i < 26; i++) { if (arr[i] == 0 && brr[i] > ...
4
#include <bits/stdc++.h> using namespace std; using ll = long long; const int N = 1000006; int n, k; int v[N], c[N]; int dn[N][20], dx[N][20]; int fn(int i, int j) { if (j == 0) return c[i]; if (~dn[i][j]) return dn[i][j]; return dn[i][j] = min(fn(i, j - 1), fn(i + (1 << (j - 1)), j - 1)); } int lg(int x) { retur...
16
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:256000000") using namespace std; const int maxN = 110000; const int inf = 1000000; int n, m, d; vector<int> g[maxN]; int t[4 * maxN], add[4 * maxN]; int l[maxN], r[maxN], used[maxN]; int candidates[maxN]; int value[maxN]; int pos[maxN]; int cnt = 0; void dfs(int ...
12
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf("%d", &n); printf("%d\n", n / 2 + 1); for (int i = 1; i <= n; i++) { if (i % 2 == 0) printf("%d %d\n", (i + 1) / 2, i / 2 + 1); else { printf("%d %d\n", (i + 1) / 2, (i + 1) / 2); } } }
3
#include <bits/stdc++.h> using namespace std; struct node { int cnt; long long sum[6]; }; node seg[4 * 100000]; struct info { string str; int num; }; info data[100000 + 20]; map<int, int> m; vector<int> v; string s; void insert(int idx, int st, int ed, int pos, int val) { if (st == ed) { if (val < 0) ...
15
#include <bits/stdc++.h> long long int memory[2001][2001]; long long int multiple(long long int j, long long int n, long long int k); int main() { long long int n, k, arr[1002], i, temp1 = 0; scanf("%lld %lld", &n, &k); for (i = 1; i <= n; i++) { temp1 += multiple(i, n, k - 1) % 1000000007; } printf("%lld...
6
#include <bits/stdc++.h> using namespace std; const double pi = acos(0.0) * 2.0; const double eps = 1e-12; const int step[8][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}, {1, 1}, {1, -1}, {-1, 1}, {-1, -1}}; template <class T> inline T abs1(T a) { return a < 0 ? -a : a; } template <class T> inline ...
10
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ; string s; cin >> s; int n = s.size(); int r = (n + 19) / 20; int c = (n + r - 1) / r; int rem = r * c - n; cout << r << " " << c << endl; int i = 0; while (i != n) { int j; for (...
4
#include <bits/stdc++.h> const int mx = 1e6 + 5; const int inf = 0x3f3f3f3f; using namespace std; vector<vector<int>> g; vector<int> vs; deque<int> topo; void dfs(int v, int p = -1) { vs[v] = true; for (int u : g[v]) { if (!vs[u]) dfs(u, v); } topo.push_front(v); } int main() { ios::sync_with_stdio(0); ...
12
#include <bits/stdc++.h> using namespace std; int fact[1000005], invf[1000005]; int n; void add(int &a, int b) { a += b; if (a >= 998244353) a -= 998244353; } int pow_mod(int a, int i) { int s = 1; while (i) { if (i & 1) s = 1LL * s * a % 998244353; a = 1LL * a * a % 998244353; i >>= 1; } return...
21
#include <bits/stdc++.h> using namespace std; int n; vector<unsigned long long> c; inline unsigned long long dot(const vector<unsigned long long> &v, const vector<unsigned long long> &u) { unsigned long long sum = 0; for (int i = 0; i != n; ++i) sum += v[i] * u[i]; return sum; } inli...
18
#include <bits/stdc++.h> using namespace std; const int N = (int)2e5 + 228; const int INF = (int)1e9 + 228; long long c[6], mn[6]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int tst; cin >> tst; while (tst--) { long long x, y; cin >> x >> y; for (int i = 0; i < 6; i++) {...
11
#include <bits/stdc++.h> using namespace std; long long a[200005], dp[100005], b[100005]; long long vis[1000005]; long long mod = 1000000007; int main() { long long p, n, i, j, sz = 0, k = 0, l, m; cin >> n; for (i = 1; i <= n; i++) cin >> j, a[j] = i; for (i = 2; i <= n; i++) { if (a[i] > a[i - 1]) k...
8
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; vector<int> A(N), B(N); for (int i = 0; i < N; ++i) cin >> A[i], --A[i]; for (int i = 0; i < N; ++i) cin >> B[i], --B[i]; vector<vector<int> > ans; for (int i = 0; i < N; ++i) { int tx = find(A.begin(), A.end(), i) - A.begin()...
21
#include <bits/stdc++.h> using namespace std; struct Trie { int ch[2], l, r, sz; } t[50010 * 32]; int li[100], len, sz, a[50010], root, cur[50010], cs[50010]; unsigned short cc[50010][32]; bool b[30]; void ins(int w, int id) { bool c; int x = root; for (int i = 0; i < 30; i++) b[i] = w >> i & 1; for (int i = ...
19
#include <bits/stdc++.h> using namespace std; vector<pair<int, int>> arr; int V[26][26]; bool dis[26]; void d(int a) { for (int i = 0; i < 26; i++) { if (V[a][i] == 1) { if (!dis[i]) { arr.push_back({a, i}); V[a][i]++; V[i][a]++; dis[i] = 1; d(i); } } } } ...
8
#include <bits/stdc++.h> using namespace std; const int N = (int)2e5 + 5; const int INF = (int)1e9 + 7; int dx[8] = {1, 0, -1, 0, -1, -1, 1, 1}; int dy[8] = {0, 1, 0, -1, -1, 1, -1, 1}; int ini() { int x; scanf("%d", &x); return x; } long long inl() { long long x; scanf("%lld", &x); return x; } int vis[1000...
5
#include <bits/stdc++.h> using namespace std; int main() { long long int n, count = 0; vector<long long int> v; long long int min = 2 * 1000000001; cin >> n; for (long long int i = 0; i < n; i++) { long long int x; cin >> x; v.push_back(x); } sort(v.begin(), v.end()); for (long long int i = ...
3
#include <bits/stdc++.h> using namespace std; int n, m, k, s; int good; vector<int> goodloc[101]; queue<pair<int, int> > q; vector<int> adjlist[100001]; vector<int> towns[100001]; int sdist[100001]; int a, b; int main() { cin >> n >> m >> k >> s; for (int i = 0; i < n; i++) { cin >> good; goodloc[good].push...
8
#include <bits/stdc++.h> using namespace std; long long int x[222222]; long long int y[222222]; struct xjy { long long int num; long long int val; long long int type; bool operator<(const xjy &r) const { return val < r.val; } }; vector<xjy> sx, sy; long long int money; long long int n, m; long long int ansl; lo...
12
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(NULL); int n, m; cin >> n >> m; vector<vector<bool>> G(n + 10, vector<bool>(m + 10)); for (int r = 1; r <= n; r++) { for (int c = 1; c <= m; c++) { char v; cin >> v; if (v == 'X') G[r][c] = ...
14
#include <bits/stdc++.h> using namespace std; void err() { cout << "\033[39;0m" << endl; } template <template <typename...> class T, typename t, typename... Args> void err(T<t> a, Args... args) { for (auto x : a) cout << x << ' '; err(args...); } template <typename T, typename... Args> void err(T a, Args... args) {...
16
#include <bits/stdc++.h> using namespace std; int dp[1000003]; int main() { string s; int i, pr = -1, c = 0; cin >> s; for (i = 0; i < s.size(); i++) { if (s[i] == 'M') { c++; } if (s[i] == 'F') { dp[i] = c; if (pr >= c) { if (c != 0) dp[i] = pr + 1; } pr = dp[i...
12
#include <bits/stdc++.h> using namespace std; const int maxnum = 100; const int maxint = 99999; const int N = 20000; const int MAX = 5000; int main() { double r, R; int n; int sum; double a, b, c; double d; while (scanf("%lf %lf", &R, &r) != EOF) { r = R - r; sum = 0; scanf("%d", &n); for (i...
3
#include <bits/stdc++.h> using namespace std; using cd = complex<double>; using ll = long long; const double PI = acos(-1); void fft(vector<cd> &a, bool invert) { int n = a.size(); for (int i = 1, j = 0; i < n; i++) { int bit = n >> 1; for (; j & bit; bit >>= 1) j ^= bit; j ^= bit; if (i < j) swap(a...
16
#include <bits/stdc++.h> using namespace std; const int maxn = 3e5 + 10; struct node { int x, y; bool operator<(const node& n) const { if (y == n.y) return x < n.x; return y < n.y; } } NODE[maxn]; struct edge { int up, down; } dp[2][maxn]; int Lim[maxn], pos[maxn]; int main() { int n, m; scanf("%d%d...
17
#include <bits/stdc++.h> using namespace std; int main() { map<int, int> m; int n, a, maxi = 0, cnt; cin >> n; for (int i = 0; i < n; i++) { cin >> a; m[a]++; if (m[a] > maxi) { maxi = max(m[a], maxi); cnt = a; } } cout << cnt << endl; }
2
#include <bits/stdc++.h> using namespace std; int n, m, x, q; bool valid; bool shift; vector<pair<int, int> > coord[30]; vector<pair<int, int> > shiftCoord; string s; int ans = 0; double data[30]; bool check_valid() { for (int i = 0; i < s.length(); i++) { if (s[i] >= 'A' && s[i] <= 'Z') { if (shiftCoord.em...
7
#include <bits/stdc++.h> using namespace std; int main() { int a[4] = {6, 8, 4, 2}; long long int n; cin >> n; if (n == 0) { cout << "1"; } else { cout << a[(n % 4)]; } }
2
#include <bits/stdc++.h> using namespace std; int t[400000]; int t1[400000]; int get(int v, int l, int r, int l1, int r1) { if (l >= l1 && r <= r1) { return t[v]; } if (l > r1 || r < l1) return 0; return max(get(2 * v, l, (l + r) / 2, l1, r1), get(2 * v + 1, (l + r) / 2 + 1, r, l1, r1)); } void...
11
#include <bits/stdc++.h> using namespace std; double sq(double x) { return x * x; } int xyz[8][3]; void read() { for (int i = 0; i < 8; ++i) for (int j = 0; j < 3; ++j) cin >> xyz[i][j]; } bool isCube(int curXYZ[8][3]) { vector<pair<double, int> > order; int dXYZ[8][3]; for (int i = 0; i < 8; ++i) for (...
12
#include "bits/stdc++.h" using namespace std; #ifdef LOCAL #include "debug.h" #define input freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #else #define debug(...) 4 #define input 4 #endif using ll = long long; //const int mod = 998244353; const int mod = 1e9 + 7; const int N =...
19
#include <bits/stdc++.h> using namespace std; int main() { long long n, m, x, ans = 0; long long prev = 1; cin >> n >> m; for (int i = 0; i < m; i++) { cin >> x; if (x >= prev && x <= n) ans += x - prev; else if (x < prev) { ans += (n - prev) + (x - 1) + 1; } prev = x; } cout...
2
#include <bits/stdc++.h> using namespace std; int a[5000][3] = {0}; int main() { int n; cin >> n; int b[n]; int one = 0, two = 0, three = 0; for (int i = 0; i < n; i++) { cin >> b[i]; if (b[i] == 1) one++; else if (b[i] == 2) two++; else three++; } int d = min(one, two); ...
0
#include <bits/stdc++.h> using namespace std; struct node { int p; int a; } s[25]; int factor[10000005]; int t = 0; int main() { int pn = 0; int n; int total = 0; scanf("%d", &n); int temp = n; for (int i = 2; i * i <= temp; i++) { if (n % i == 0) { pn++; s[pn].p = i; } while (n ...
11
#include <bits/stdc++.h> using namespace std; int t, n, i, j; string s; map<string, int> mep; char c; string ubah(string s) { int i, j; string res = ""; for (i = (int)s.size() - 1; i >= 0; i--) { j = s[i] - '0'; if (j % 2 == 0) res = '0' + res; else res = '1' + res; } return res; } int...
6
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n, m; cin >> n >> m; int ans = (n - n % m) + min(n % m, m / 2); cout << ans << endl; } return 0; }
1
#include <bits/stdc++.h> using namespace std; int h, n, i, l, m, w, z, f, k; int d[1000010]; char a[1000010]; int main() { ios_base::sync_with_stdio(false); cin >> a, l = strlen(a); if (l <= 2) { cout << "Just a legend"; return 0; } while (m < 2) { if (!m) k = 1; else k = l - h, h ...
9
#include <bits/stdc++.h> using namespace std; const int N = 500005; int n, m; vector<pair<int, int>> g[N]; int eu[N], ev[N], et[N]; int in[N], out[N], rin[N], dfst; int val[N], lvl[N]; void dfs(int u, int p) { in[u] = ++dfst; rin[in[u]] = u; for (auto [v, w] : g[u]) if (v != p) { val[v] = val[u] ^ w; ...
20
#include <bits/stdc++.h> using namespace std; const int N = 5e5 + 19; int vis[N], ans[N]; pair<int, int> e[N]; void solve() { int n, m; scanf("%d%d", &n, &m); for (int i = 1; i <= 3 * n; ++i) vis[i] = 0; for (int i = 1; i <= m; ++i) { int x, y; scanf("%d%d", &x, &y); e[i] = pair<int, int>(x, y); }...
12
#include <bits/stdc++.h> using namespace std; template <typename T> void maxtt(T& t1, T t2) { t1 = max(t1, t2); } template <typename T> void mintt(T& t1, T t2) { t1 = min(t1, t2); } bool debug = 0; int n, m, k; int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0}; string direc = "URDL"; const long long MOD2 = (long lon...
14
#include <bits/stdc++.h> using namespace std; template <class T> inline T bigmod(T p, T e, T M) { long long ret = 1; for (; e > 0; e >>= 1) { if (e & 1) ret = (ret * p) % M; p = (p * p) % M; } return (T)ret; } template <class T> inline T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); } ...
0
#include <bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:500000000") const double EPS = 1E-9; const int INF = 1000000000; const long long INF64 = (long long)1E18; const double PI = 3.1415926535897932384626433832795; const int NMAX = 60000; string s[2100]; char buf[110000]; int tr[NMAX][30], h[NMAX]...
10
#include <bits/stdc++.h> using namespace std; int abs(int a) { return a > 0 ? a : -a; } int n, m, dis[333][333], a[333], b[333]; vector<int> vs, vd, vt; inline void save(int v, int u, int t) { vs.push_back(v + 1); vd.push_back(u + 1); vt.push_back(t); } void transfer(int v, int u, int t) { if (dis[v][u] == 1) {...
17
#include <bits/stdc++.h> using namespace std; long long mod_pow(long long a, int b) { long long ret = 1; while (b) { if (b & 1) ret = ret * a % 1000000007; a = a * a % 1000000007; b >>= 1; } return ret; } int C; long long memo[9][9][(1 << 8)]; long long solve(int cur, int pos, int mask) { if (mask...
7
#include <bits/stdc++.h> using namespace std; int main() { int n, f; cin >> n; char *s = NULL; s = (char *)malloc((n + 1) * sizeof(char)); if (n % 2 == 0) f = n / 2; else f = n / 2 + 1; for (int i = 0; i < n; ++i) { cin >> s[i]; } for (int i = 0; i < n - 1; ++i) { if (s[i] == s[i + 1] ...
4
#include <bits/stdc++.h> clock_t t_; using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); unsigned long long multmod(unsigned long long a, unsigned long long b, unsigned long long mod) { unsigned long long ret = 0; a %= mod; b %= mod; return a * b ...
14
#include <bits/stdc++.h> using namespace std; const int md = (int)1e9 + 7; inline void add(int &a, int b) { a += b; if (a >= md) { a -= md; } } inline int mul(int a, int b) { return (long long)a * b % md; } int dp[1234][1234]; vector<int> q; map<int, int> cnt; int other; int pw(int x, int y) { int res = 1; ...
13
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf("%d", &n); int cycle = 0, count = 0, input; int array[n + 1]; bool visited[n + 1]; fill_n(visited, n + 1, false); array[0] = 0; visited[0] = true; for (int i = 1; i <= n; i++) scanf("%d", &array[i]); for (int i = 0; i < n; i++) ...
9
#include <bits/stdc++.h> using namespace std; template <typename T> void make_unique(vector<T> &vec) { sort(vec.begin(), vec.end()); vec.erase(unique(vec.begin(), vec.end()), vec.end()); } void __print(long long x) { cerr << x; } void __print(double x) { cerr << x; } void __print(long double x) { cerr << x; } void ...
6
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c; cin >> a >> b >> c; int exp1 = a + b + c; int exp2 = a * b * c; int exp3 = a + b * c; int exp4 = a * b + c; int exp5 = a * (b + c); int exp6 = (a + b) * c; cout << max(exp1, max(exp2, max(exp3, max(exp4, max(exp5, exp6))))); ret...
2
#include <bits/stdc++.h> using namespace std; int main() { int n, x; cin >> n >> x; vector<pair<int, int>> v; int ans = 100000; for (int i = 0; i < n; i++) { int a, b; cin >> a >> b; if (a > b) swap(a, b); v.push_back({a, b}); } for (int i = 0; i <= 1000; i++) { bool flag = true; f...
2
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; int n, tot, pre[N], a[N], rt[N], ls[N * 40], rs[N * 40], sum[N * 40]; void update(int &o, int last, int l, int r, int x, int val) { o = ++tot; ls[o] = ls[last]; rs[o] = rs[last]; sum[o] = sum[last] + val; if (l == r) return; int mid = l + ...
16
#include <bits/stdc++.h> using namespace std; bool dp[510][510][510]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int tt = 1; while (tt--) { long long n, k; cin >> n >> k; long long c[n]; for (int i = 0; i < n; i++) { cin >> c[i]; } dp[0][0][0] =...
11
#include <bits/stdc++.h> using namespace std; const int maxm = 1e6 + 5; int nt[maxm][25], maxd = 20; int w[maxm], b[maxm]; char c[maxm]; char d[maxm]; int n, m; int id(int i, int j) { return (i - 1) * m + j; } signed main() { ios::sync_with_stdio(0); cin.tie(0); int T; cin >> T; while (T--) { cin >> n >> ...
14
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:2560000") using namespace std; bool win(string s1, string s2) { if (s1 == "rock" && s2 == "scissors") return true; if (s1 == "paper" && s2 == "rock") return true; if (s1 == "scissors" && s2 == "paper") return true; return false; } int src[50][50]; int mai...
4
#include <bits/stdc++.h> using namespace std; const int N = 105, L = 50, M = 1000000007; int dp[N][L], x, y, f[L], n, m; vector<int> g[N]; void dfs(int x, int y) { dp[x][0] = dp[x][m + 1] = 1; for (int i : g[x]) if (i != y) { dfs(i, x); memset(f, 0, sizeof f); for (int j = 0; j <= 2 * m; j++) ...
17
#include <bits/stdc++.h> using namespace std; int n, i, x, y, z, t, j, s; int A[5001], D[5001], P[5001], C[5001]; priority_queue<int> PQ[5001]; vector<pair<int, int> > V[5001]; queue<int> Q; vector<int> T; map<int, int> M; int main() { scanf("%d", &n); for (i = 0; i < n; i++) { scanf("%d", &A[i]); PQ[i].pus...
12
#include <bits/stdc++.h> using namespace std; int main() { vector<int> v; int n; cin >> n; int p[2] = {0, 0}; while (n--) { int s; cin >> s; int x; for (int i = 0; i <= (s / 2 - 1); i++) { cin >> x; p[0] += x; } if (s % 2 == 1) { cin >> x; v.push_back(x); } ...
12
#include <bits/stdc++.h> using namespace std; const int MAXA = 1e5 + 10, MAXN = 505, MAXK = 15; int nl[MAXA], nv[MAXA], n, k, tmp, h[MAXK], dp[MAXN][MAXN * MAXK]; long long ans; int calc(int num) { int av = min(nv[num], nl[num] * k); int pop = nl[num]; if (pop == 0) return 0; for (int i = 0; i <= min(k, av); i+...
12
#include <bits/stdc++.h> using namespace std; const int MAXN = (1 << 21) + 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 = ...
24
#include <bits/stdc++.h> using namespace std; const long long maxn = 1e6 + 500; long long A[maxn], A_ni[maxn], inv[maxn]; void pre(long long mod) { A[0] = A_ni[0] = A[1] = A_ni[1] = inv[1] = 1; for (int i = 2; i < maxn; i++) A[i] = A[i - 1] * i % mod; for (int i = 2; i < maxn; i++) inv[i] = (mod - mod / i) * inv[...
14
#include <bits/stdc++.h> using namespace std; typedef const int& ci; int ans[1000000 + 1]; int hsn[1000000 + 1], dp[1000000 + 1], *top = dp; vector<int> sn[1000000 + 1]; int dfs(ci u, ci p) { vector<int>::iterator par, hsu; int hln = 0, sln; bool flag; for (vector<int>::iterator i = sn[u].begin(), ed = sn[u].en...
15
#include <bits/stdc++.h> using namespace std; const long long inf = 1e16; pair<long long, long long> p[200]; int main() { long long x0, y0, ax, ay, bx, by; long long xs, ys, t, tot = 1; cin >> x0 >> y0 >> ax >> ay >> bx >> by; cin >> xs >> ys >> t; p[0] = {x0, y0}; for (int i = 1;; i++) { long long nx =...
9
#include <bits/stdc++.h> using namespace std; long long int max(long long int a, long long int b) { if (a > b) return a; return b; } int main() { int t; cin >> t; for (int j = 0; j < t; j++) { int x; string s; cin >> x; cin >> s; int n = s.length(); if (n == 1) { cout << "1\n"; ...
9
#include <bits/stdc++.h> char s[222222]; char t[222222]; int left[222222]; int right[222222]; int lastpos[30]; int m, n; int main() { scanf("%s %s", s, t); m = strlen(s); n = strlen(t); memset(left, -1, sizeof left); memset(right, -1, sizeof right); int cur = 0; memset(lastpos, -1, sizeof lastpos); for ...
11
#include <bits/stdc++.h> using namespace std; int main() { int primes[200010]; vector<int> primesList; int maze[505][505]; int n, m, t; memset(primes, 0, sizeof(primes)); for (int i = 2; i * i <= 200000; i++) { if (primes[i] == 1) continue; for (int j = i * i; j <= 200000; j += i) { primes[j] ...
5
#include <bits/stdc++.h> using namespace std; template <class T> void _R(T &x) { cin >> x; } void _R(int &x) { scanf("%d", &x); } void _R(long long &x) { scanf("%lld", &x); } void _R(double &x) { scanf("%lf", &x); } void _R(char &x) { scanf(" %c", &x); } void _R(char *x) { scanf("%s", x); } void R() {} template <clas...
16
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; const int MAXN = 1e5 + 5; int n, m; long long arr[MAXN]; struct Edge { int to, next; } edge[MAXN * 2]; int edge_head[MAXN]; int edge_cnt = 0; void AddEdge(int form, int to) { edge[++edge_cnt].to = to; edge[edge_cnt].next = edge_head[form...
12
#include <bits/stdc++.h> using namespace std; using ll = long long; const int INF = 1 << 30; vector<int> run_length(const vector<int>& v) { int now = v[0]; vector<int> res; for (int i = (int)1; i < (int)v.size(); ++i) { if (now != v[i]) { res.push_back(now); now = v[i]; } } res.push_back(n...
10
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") using namespace std; uint64_t rnd_data = 0xDEADBEEFDULL; inline void my_srand(int seed) { rnd_data = ((uint64_t)seed << 16) | 0x330E; } inline int my_rand() { rnd_data = rnd_data * 0x5DEECE66DULL + 0xB; return (rnd_data >> 17) & 0x7FFFFFFF; } template <typename...
24
#include <bits/stdc++.h> using namespace std; set<int> vis; bool should[200001]; int a[200001], b[200001]; int main() { int n, m; scanf("%d%d", &n, &m); int odd = 0, even = 0; int mid = n / 2; for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); b[i] = a[i]; if (vis.find(a[i]) != vis.end()) sh...
11
#include <bits/stdc++.h> using namespace std; const int FCK = 1000000; long long C, Hr, Hb, Wr, Wb, res, tot, cnt; int main() { ios_base::sync_with_stdio(0); cin >> C >> Hr >> Hb >> Wr >> Wb; for (long long i = 0; i < FCK; i++) { if (i * Wr > C) break; tot = C; cnt = Hr * i; tot -= i * Wr; cnt...
12
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const int number = 3; int m[] = {1004535809, 1007681537, 1012924417, 998244353, 104857601}; int g[] = {3, 3, 5, 3, 3}; int cur; long long pw(long long a, int b, int mod) { long long ans = 1; while (b) { if (b & 1) ans = ans * a % mod; a ...
25
#include <bits/stdc++.h> const long long oo = (long long)1e18 + 1; using namespace std; int n; int a[1010]; int main() { ios::sync_with_stdio(false); cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; int roll_index = 0; for (int i = 1; i <= n; i++) cin >> a[i]; vector<string> s(n + 1, string(n, '0')); fo...
18
#include <bits/stdc++.h> using namespace std; const int inf = 1e9; const long long INF = 1e18; const long double PI = acos(-1); const long double EPS = 1e-9; int mod = 998244353; const int MOD7 = 1000000007; const int MOD9 = 1000000009; const int MAXN = 2e5 + 228; int tin[MAXN]; int cnt[MAXN][2]; int tout[MAXN]; int tl...
15
#include <bits/stdc++.h> using namespace std; const double EPS = (double)1e-9; const double pii = acos(-1); const int mod = 1000000007; const int N = (int)1e5; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); ; int m, n; cin >> m >> n; int ans = n * m / 2; cout << ans << "\n"; }
0
#include <bits/stdc++.h> using namespace std; int main() { int n, k; vector<int> v; cin >> n >> k; for (int i = 1; i <= n; ++i) v.push_back(i); int pos = 0; for (int i = 0; i < k; ++i) { int a; cin >> a; pos += a % v.size(); pos %= v.size(); cout << v[pos] << ' '; v.erase(v.begin() +...
5
#include <bits/stdc++.h> using namespace std; int main() { long long n; scanf("%I64d", &n); string s; while (n > 0) { s.append(1, '0' + n % 3); n /= 3; } int i; for (i = 0; i < s.size(); i++) if (s[i] != '0') break; long long ans = 0; long long p = 1; for (i = i + 1; i < s.size(); i++) {...
8
#include <bits/stdc++.h> using namespace std; long long n, m, xx, fix[10001], k = 1, t = 1; int main() { cin >> n; for (int i = 1; i <= 1000000; i++) { fix[k] = 1; if (k + t <= n) k = k + t; else { k = ((k) + t) % n; } t++; } for (int i = 1; i <= n; i++) if (!fix[i]) { ...
4
#include <bits/stdc++.h> using namespace std; int t[5000], h[5000], c[8000], book[5000]; int main() { int n, m, ans = 0, ans1 = 0; scanf("%d%d", &n, &m); int tmp2 = m; for (int i = 1; i <= n; i++) scanf("%d%d%d", &t[i], &h[i], &c[i]); int flag = 1; while (1) { int maxn = -1; for (int i = 1; i <= n; ...
7
#include <bits/stdc++.h> const int OO = 0x3f3f3f3f; using namespace std; void fast() { ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); } int dx[] = {-1, 0, 1, 0}; int dy[] = {0, 1, 0, -1}; const int mod = 1e9 + 7; int main() { fast(); string g; cin >> g; int T = 0; int J = g.size(); long long ans = 0;...
6
#include <bits/stdc++.h> using namespace std; using ll = long long; using vvl = vector<vector<ll>>; using vvi = vector<vector<int>>; using pii = pair<int, int>; using pll = pair<ll, ll>; const ll M = 1000000009LL; const ll INF = 1e16; const long double eps = 1e-7; const long double Pi = acosl(-1.0); int gcd(int a, int ...
10
#include <bits/stdc++.h> using namespace std; int main() { string a; cin >> a; int j = a.size() - 1, h = 0, n = a.size(); while (a[j] == '/' && j >= 0) { j--; h++; } if (h == n) { cout << a[0]; } for (int i = 0; i < n - h; i++) { if (a[i] == '/' && a[i + 1] != '/') { cout << a[i]; ...
9
#include <bits/stdc++.h> using namespace std; string tostr(int x) { stringstream ss; ss << x; string s; ss >> s; return s; } string tostr(vector<string> vs) { string s = ""; for (int _n(((int)((vs).end() - (vs).begin())) - 1), i(0); i <= _n; i++) s += vs[i]; s += "$" + tostr((int)((vs).end() - (vs)....
10
#include <bits/stdc++.h> using namespace std; const int maxN = 155; struct Node { int x, y, d; } edge[maxN + 1]; int n, m; struct Matrix { bitset<maxN> a[maxN + 1]; void clear() { for (int i = 1; i <= n; i++) a[i].reset(); } void set() { clear(); for (int i = 1; i <= n; i++) a[i][i] = 1; } Mat...
19
#include <bits/stdc++.h> using namespace std; const double eps = 6e-10; const int INF = 987654321; double t1, t2, l, r, mid; struct point { double x, y; }; struct circle { double r; point p; double c, d, e; } c1, c2, c3; struct line { double a, b, c; }; inline double sqr(double x) { return x * x; } inline voi...
18