solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> using namespace std; int main() { int n, m, a, b, c; cin >> n >> m >> a >> b >> c; vector<vector<int> > field(n, vector<int>(m, 0)); int rem = n * m; if (n * m % 2 == 1) goto IMPOSSIBLE; if (n * m > 2 * a + 2 * b + 4 * c) goto IMPOSSIBLE; if (n % 2 == 1) { for (int i = 0; i < ...
12
#include <bits/stdc++.h> using namespace std; int a[1000005], sum[1000005], dp[1000005], pw[1000005], w[1000005]; int main() { int n; scanf("%d", &n); for (int i = 1; i <= n; ++i) { scanf("%d", &a[i]); sum[a[i]]++; } for (int i = 2; i < 1000005; ++i) for (int j = i + i; j < 1000005; j += i) sum[i]...
14
#include <bits/stdc++.h> using namespace std; int main() { map<char, string> mp; mp['2'] = "2"; mp['3'] = "3"; mp['4'] = "223"; mp['5'] = "5"; mp['6'] = "35"; mp['7'] = "7"; mp['8'] = "2227"; mp['9'] = "2337"; int n; cin >> n; string s; cin >> s; string s2 = ""; for (int i = 0; i < s.size(...
6
#include <bits/stdc++.h> using namespace std; const int MN = 23; int N, P; bool rp(int& a, int b) { return a == -1 or b < a ? a = b, true : false; } using i4 = array<int, 4>; i4 a[MN]; int d[1 << MN], o[MN], b[1 << MN]; using i2 = array<int, 2>; i2 f[MN]; bool F; void dodp() { d[0] = 1; for (int i = 0, k, l, m; i <...
26
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e5 + 10; int N, M; int A[MAXN]; bool chng[MAXN]; vector<int> pos[2]; bool comp(int x, int y) { return A[x] > A[y]; } int main() { scanf("%d %d", &N, &M); int num[2] = {0, 0}; set<int> sai; for (int i = 0; i < N; i++) { scanf("%d", &A[i]); i...
11
#include <bits/stdc++.h> using namespace std; const int NMax = 110; char A[NMax][NMax]; int N, M; int main() { scanf("%d%d", &N, &M); if (N == 5) { printf(">...v\nv.<..\n..^..\n>....\n..^.<\n1 1\n"); return 0; } if (N == 3) { printf(">vv\n^<.\n^.<\n1 3\n"); return 0; } for (int i = 100; i >=...
17
#include <bits/stdc++.h> using namespace std; int main() { int n; long long vec[100100]; scanf("%d", &n); long long suma = 0; long long m = -1; for (int i = 0; i < n; i++) { scanf("%lld", &vec[i]); suma += vec[i]; if (vec[i] > m) m = vec[i]; } sort(vec, vec + n); long long menor = 0; lon...
8
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> v; v.push_back(1); if (n >> 1) { v.push_back(n); } for (long long d = 2; d * d <= n; d++) { if (n % d == 0) { if (n / d == d) { v.push_back(d); } else { v.push_back(d); v.pus...
5
#include <bits/stdc++.h> using namespace std; const int MAX = 1001; char l[MAX][10][10]; int g[MAX][MAX]; bool c[MAX]; struct edge { int w; int p; int n; edge(int w, int p, int n) { this->w = w; this->p = p; this->n = n; } edge(int p, int n) { this->p = p; this->n = n; this->w = g[p]...
10
#include <bits/stdc++.h> using namespace std; queue<pair<int, int> > que; map<pair<int, int>, int> mm; int x[8] = {1, -1, 0, 0, -1, -1, 1, 1}; int y[8] = {0, 0, 1, -1, 1, -1, 1, -1}; int main() { int x0, y0, x1, y1, n, i; while (scanf("%d%d%d%d", &y0, &x0, &y1, &x1) != EOF) { scanf("%d", &n); mm.clear(); ...
10
#include <bits/stdc++.h> using namespace std; int n, a[300002]; int main() { cin >> n; putchar('1'); for (int i = 1, p = n + 1, x; i <= n; i++) { scanf("%d", &x); a[x] = 1; for (; p > 1 && a[p - 1]; --p) ; printf(" %d", p + i - n); } return cout << endl, 0; }
7
#include <bits/stdc++.h> using namespace std; int main() { int n; double sum = 0; cin >> n; int arr[n]; for (int i = 0; i < n; i++) { cin >> arr[i]; } for (int j = 0; j < n; j++) { sum += arr[j]; } cout << sum / n; return 0; }
0
#include <bits/stdc++.h> using namespace std; void solve() { int n, m; cin >> n >> m; vector<vector<int> > less(n, vector<int>(m)); vector<vector<int> > great(n, vector<int>(m)); vector<vector<int> > field(n, vector<int>(m)); for (int i = 0; i < n; ++i) for (int j = 0; j < m; ++j) cin >> field[i][j]; ...
8
#include <bits/stdc++.h> using namespace std; int a[1000000]; pair<unsigned long long, unsigned long long> b[1000000]; int main() { unsigned long long k1, k2, k3, t1, t2, t3, n, x; cin >> k1 >> k2 >> k3 >> t1 >> t2 >> t3 >> n; for (int i = 0; i < n; i++) { cin >> a[i]; b[i].first = a[i]; b[i].second =...
10
#include <bits/stdc++.h> using namespace std; int main() { int n, ans, m, M; cin >> n; ans = n / 7; ans <<= 1; m = n % 7 == 6 ? ans + 1 : ans; if (n % 7 > 1) M = ans + 2; else if (n % 7 == 1) M = ans + 1; else M = ans; cout << m << " " << M << endl; }
1
#include <bits/stdc++.h> using namespace std; long long int sum[500005]; vector<long long int> v; double fun(long long int i, long long int maxn) { return ((double)sum[i] + (double)maxn) / (double)(i + 2); } double tern(long long int low, long long int high, long long int maxn) { while (low < high) { long long ...
10
#include <bits/stdc++.h> using namespace std; int main() { long long n, x; cin >> n >> x; int distressed = 0; while (n--) { char c; int i; cin >> c >> i; if (c == '-') { if (i > x) distressed++; else x -= i; } else x += i; } cout << x << " " << distresse...
0
#include <bits/stdc++.h> using namespace std; vector<int64_t> fact_table(int n, int64_t m) { vector<int64_t> fact(n + 1); fact[0] = 1; for (int i = 1; i <= n; i++) fact[i] = fact[i - 1] * i % m; return fact; } uint64_t fast_exp(uint64_t a, uint64_t b, uint64_t m) { uint64_t ans = 1; while (b >= 1) { if ...
0
#include <bits/stdc++.h> using namespace std; int N, M; vector<int> adj[300005]; set<pair<int, int> > val, tr_val; bool vis[300005]; int ent[300005], low[300005], t = 0; int bcc_num = 0; vector<int> art; vector<pair<int, int> > bri; vector<int> bcc[300005]; void dfs(int n, int p = -1) { vis[n] = true; ent[n] = low[...
15
#include <bits/stdc++.h> using namespace std; int main() { unsigned long long int t, a, b; cin >> t; while (t--) { cin >> a >> b; if (b > a) { swap(a, b); } unsigned long long int n = a / b; if (n * b != a) { cout << "-1" << endl; continue; } unsigned long long int cn...
2
#include <bits/stdc++.h> using namespace std; int dX[] = {0, 0, 1, -1}; int dY[] = {1, -1, 0, 0}; string alpha = "abcdefghijklmnopqrstuvwxyz"; int MOD = 1000000007; const int N = 200100; string s; int m, arr[20], n; long long dp[(1 << 18) + 5][100]; long long solve(int mask, int rem, bool f) { if (mask == (1 << n) - ...
12
#include <bits/stdc++.h> using namespace std; int main() { int t; scanf("%d", &t); while (t--) { int a, b, c; scanf("%d%d%d", &a, &b, &c); if (b & 1) { for (int i = 1; i <= a; i++) { printf("0"); } for (int i = 1; i <= b; i++) { if (i & 1) printf("0"); ...
7
#include <bits/stdc++.h> using namespace std; const long long int N = 1e5 + 5; void solve() { long long int n; cin >> n; string s; cin >> s; long long int z = 0, o = 0; for (long long int i = 1; i < n; i++) { if (s[i] == s[i - 1]) { if (s[i] == '1') o++; else z++; } } ...
4
#include <bits/stdc++.h> using namespace std; int main() { int n, s, r; cin >> n >> s; r = s / n; if (s % n != 0) r++; cout << r << endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 5; namespace convex_hull { const double eps = 1e-8; const double PI = acos(-1.0); int sgn(double x) { if (fabs(x) < eps) return 0; if (x < 0) return -1; else return 1; } struct Point { double x, y; Point(double _x = 0.0, double _y = ...
16
#include <bits/stdc++.h> using namespace std; inline void inp(int &n) { n = 0; int ch = getchar(); int sign = 1; while (ch < '0' || ch > '9') { if (ch == '-') sign = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') n = (n << 3) + (n << 1) + ch - '0', ch = getchar(); n = n * sign; } long lo...
12
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; string s, q = "", p = ""; cin >> s; int hr = (s[0] - '0') * 10 + (s[1] - '0'); int min = (s[3] - '0') * 10 + (s[4] - '0'); if (!(min >= 0 && min <= 59)) min = 2 * 10 + (s[4] - '0'); if (min >= 0 && min <= 9) { q = to_string(...
5
#include <bits/stdc++.h> using namespace std; int n, s, t, sol; int p[100005], used_col[300], used_sum[300]; void back(int niv) { if (niv == n + 1) { ++sol; return; } for (int i = 1; i <= n; ++i) { if (!used_col[i]) { int sum = (niv - 1 + i - 1) % n + 1; if (!used_sum[sum]) { used_...
11
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int sum1 = 0; int sum2 = 0; for (int i = 0; i < n; i++) { int ai; cin >> ai; sum1 += ai; } for (int i = 0; i < n; i++) { int bi; cin >> bi; sum2 += bi; } cout << (sum2 <= sum1 ? "Yes" : "No") << endl; ...
0
#include <bits/stdc++.h> using namespace std; int dx4[4] = {0, -1, 0, 1}; int dy4[4] = {1, 0, -1, 0}; int dx8[8] = {-1, -1, -1, 0, 1, 1, 1, 0}; int dy8[8] = {-1, 0, 1, 1, 1, 0, -1, -1}; int Power(int base, int exp) { int ans = 1; while (exp > 0) { if (exp & 1) ans = (1LL * ans * base) % 1000000007; exp = ex...
10
#include <bits/stdc++.h> using namespace std; int main() { int x_end, stop, max_l, k; int l, ans = 0, end, dist, f = 2; scanf("%d %d %d %d", &x_end, &max_l, &stop, &k); l = max_l; for (int i = 1; i <= k; i++) { if (i & 1) end = 0; else end = x_end; dist = abs(end - stop); l -= dist...
7
#include <bits/stdc++.h> using namespace std; const long long INF = 0x3f3f3f3f; const long long mod = 1e9 + 7; const long long maxn = 5e5 + 5; const double eps = 1e-7; const double PI = acos(-1); int sum[maxn], cot[maxn]; int main() { int m, k, n, s; cin >> m >> k >> n >> s; vector<int> res(m + 1); for (int i =...
11
#include <bits/stdc++.h> using namespace std; int n, m, p, a[150010]; struct node { vector<pair<int, int> > Num; node operator+(const node &P) const { node ans = P; for (int i = 0; i < Num.size(); i++) { bool pd = 0; for (int j = 0; j < ans.Num.size(); j++) { if (Num[i].first == ans.Num[...
24
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; const int N = 15 + 1e5; const int INF = 1e9; pair<int, string> p[N]; long long res[12]; long long si[12]; bool emp[12]; long long POW(long long a, long long b) { if (b == 0) return 1; long long x = POW(a, b / 2) % mod; x = (x * x) % mod;...
13
#include <bits/stdc++.h> using namespace std; int gcd(int a, int b) { if (a == 0 || b == 0) return 0; if (a == b) return a; if (a > b) return gcd(a - b, b); return gcd(a, b - a); } int main() { int n, m, z; cin >> n >> m >> z; int lcm = n * m / gcd(n, m); cout << z / lcm; return 0; }
0
#include <bits/stdc++.h> using namespace std; int main() { int s, n; cin >> s >> n; vector<pair<int, int> > d; for (int i = 0; i < n; i++) { int x; int y; cin >> x >> y; d.push_back(make_pair(x, y)); } sort(d.begin(), d.end()); int win = 1; for (int i = 0; i < n; i++) { if (s > d[i]....
2
#include <bits/stdc++.h> using namespace std; const long double eps = 1e-13; const long double PI = acos(-1); const int INF = (int)1e9; const long long INFF = (long long)1e18; const int mod = 998244353; const int MXN = (int)1e6 + 7; pair<int, int> a[MXN], b[MXN]; pair<int, int> st[MXN]; int ck[MXN]; map<pair<int, int>,...
4
#include <bits/stdc++.h> using namespace std; const int inf = (1 << 30) - 1; const int mod = (int)1e9 + 7; const int N = (int)2e5; const int K = 18; vector<pair<int, int> > g[N]; int up[N], down[N], anc[K][N]; int n, m, in[N], out[N], T; long long ans; long long binpow(long long x, long long pw) { long long res = 1; ...
14
#include <bits/stdc++.h> const int inf = 1000005; using namespace std; int dx[] = {1, 1, 1, 0, 0, -1, -1, -1}; int dy[] = {1, 0, -1, 1, -1, -1, 0, 1}; vector<int> arr[10]; void compute() { int temp[] = {2, 3, 5, 7}; for (int i = 1; i < 10; ++i) { int num = i; for (int j = 0; j < 4; ++j) { while (num %...
6
#include <bits/stdc++.h> using namespace std; int main() { long long int i, j, t1, t2, t3, t4, x1, y1, x2, y2, a, b, c; double buf1, buf2, buf3, buf4, buf5, ans, tempans; scanf("%lld %lld %lld %lld %lld %lld %lld", &a, &b, &c, &x1, &y1, &x2, &y2); ans = abs(x1 - x2) + abs(y1 - y2); if (a == 0) { buf1 = -c...
11
#include <bits/stdc++.h> using namespace std; const int Maxn = 40; int n, k; vector<int> num; void input() { cin >> n >> k; int a; for (int i = 0; i < n; i++) { cin >> a; num.push_back(a); } } void output() { sort(num.begin(), num.end()); if (k <= n) cout << num[n - k] << " " << num[n - k] << en...
1
#include <bits/stdc++.h> using namespace std; const int N = 100005, X = 15; int n, m, p, x; long long f[N][X][3], g[N][X][3], ans = 0; vector<int> e[N]; void dfs(int u, int fa) { f[u][0][0] = p - 1; f[u][1][1] = 1; f[u][0][2] = m - p; for (int i = 0; i < e[u].size(); i++) { int v = e[u][i]; if (v == fa)...
12
#include <bits/stdc++.h> using namespace std; template <class T> void chmin(T& a, const T& b) { if (a > b) a = b; } template <class T> void chmax(T& a, const T& b) { if (a < b) a = b; } int n, k; vector<int> g[200100]; vector<pair<int, int> > es; int depth[200100]; long long chnum[200100]; long long dp[200100][5]; ...
13
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { return !b ? a : gcd(b, a % b); } long long lcm(long long a, long long b) { return (a / gcd(a, b)) * b; } int main() { long long n, k; while (scanf("%lld%lld", &n, &k) > 0) { int a, b; scanf("%d%d", &a, &b); long long...
9
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 5; queue<int> q[N]; int a[N], b[N], c[N], vis[N]; int n, m; int main() { scanf("%d%d", &n, &m); for (int i = 1; i <= m; i++) { scanf("%d%d", &a[i], &b[i]); c[a[i]]++; c[b[i]]++; q[a[i]].push(b[i]); q[b[i]].push(a[i]); } int u ...
9
#include <bits/stdc++.h> using namespace std; long long n; long long ans; int digit(long long x) { long long ret = 0; while (x) { ret += x % 10; x /= 10; } return ret; } int main() { scanf("%I64d", &n); ans = -1; for (int i = 1; i <= 81; ++i) { long long d = i * i + 4 * n; long long a = sq...
6
#include <bits/stdc++.h> using namespace std; int INF = 1000000005; long long INFF = 1000000000000000005LL; int dirx[8] = {-1, 0, 0, 1, -1, -1, 1, 1}; int diry[8] = {0, 1, -1, 0, -1, 1, -1, 1}; double pi = 3.1415926536; int MOD = 1e9 + 7; long long power(long long x, long long n) { long long res = 1; while (n > 0) ...
12
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; int ans; if (n == 1 || m == 1) ans = max(m, n); else if (m == 2 && n == 2) ans = 4; else if (n == 2) { if (m & 1) ans = m + 1; else if (m % 4 == 2) ans = m + 2; else ans = m; } else if...
10
#include <bits/stdc++.h> using namespace std; int main() { string s, l, r, t; cin >> s; int c = s.find('|'); l = s.substr(0, c); r = s.substr(c + 1); cin >> t; for (auto pointer : t) if (l.size() <= r.size()) l += pointer; else r += pointer; cout << (l.size() == r.size() ? l + '|' + ...
3
#include <bits/stdc++.h> using namespace std; int n; vector<int> G[1 << 20], ans; int vis[1 << 20]; set<pair<int, int> > E; void dfs(int u, int p) { if (((int)ans.size()) == n) return; ans.push_back(u); vis[u] = 1; for (int v : G[u]) for (int t : G[p]) if (v == t && !vis[t]) return dfs(t, u); } bool D...
12
#include <bits/stdc++.h> using namespace std; const long long inf = INT_MAX, df = 3e5 + 7; long long i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a[df], pos[df], b[df], id[df], cnt, ans[df]; char st[5]; bool cmp(long long st, long long ch) { return a[st] < a[ch]; } inline long long read() { long long x =...
20
#include <bits/stdc++.h> using namespace std; set<string> S; int main() { int n; string s; cin >> n; for (int i = 0; i < n; i++) { cin >> s; if (S.count(s)) cout << "YES\n"; else cout << "NO\n"; S.insert(s); } return 0; }
0
#include <bits/stdc++.h> using namespace std; long long t, n, m, k; int main() { cin >> t; for (int w = 0; w < t; w++) { cin >> n >> m >> k; if (m <= n / k) { cout << m << endl; continue; } if ((m - n / k) % (k - 1) == 0) { cout << n / k - (m - n / k) / (k - 1) << endl; conti...
2
#include <bits/stdc++.h> using namespace std; vector<long long> fact(1001); long long power(long long a, long long b) { if (b == 0) return 1; long long ans = power(a, b / 2); ans = (ans % 998244353 * ans % 998244353) % 998244353; if (b % 2 == 1) return (ans * a) % 998244353; return ans; } long long inverse(lo...
11
#include <bits/stdc++.h> using namespace std; const int N = 100010; const int M = 1; const int INF = 0x3f3f3f3f; const int MOD = 1000000007; int n, h, ans[N], a[N], b[N]; struct pos { int ix, a; }; pos p[N]; bool cmp(const pos &a, const pos &b) { return a.a < b.a; } int main() { scanf("%d%d", &n, &h); for (int i ...
10
#include <bits/stdc++.h> using namespace std; const long long maxn = 1e5 + 100; long long n; vector<long long> pos; long long cou(long long k) { long long ans = 0; for (long long i = 1; i <= n; i += k) { long long mid = (i + i + k - 1) / 2; for (long long j = i; j <= i + k - 1; j++) { ans += abs(pos[m...
10
#include <bits/stdc++.h> using namespace std; const int N = 2017; int qu[N], re[N], n, mi[N], x; int main() { memset(mi, 0x3f, sizeof(mi)); scanf("%d", &n); int k; for (int i = 0; i <= 9; i++) for (int t = 0; t <= 1; t++) { k = 0; for (int j = 0; j <= n - 1; j++) if (((j >> i) & 1) == t)...
11
#include <bits/stdc++.h> using namespace std; int n; int a[200000], d[200000]; int process() { int MAX = -1; cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; d[a[i]]++; MAX = max(MAX, a[i]); } int res = 0; if (n > 0) res = 1; for (int i = 2; i <= MAX; i++) { int cnt = 0; int j = 0...
6
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n, k, count1 = INT_MIN; cin >> n >> k; int ram[k]; for (int i = 0; i < k; i++) cin >> ram[i]; int l = ram[0]; int r; for (int i = 0; i < k; i++) { if (i + 1 < k) { r = ram[i + 1]...
2
#include <bits/stdc++.h> using namespace std; int main() { long long tt; cin >> tt; getchar(); while (tt--) { long long n, x, y, z, i; string a, b, c; cin >> a; getchar(); cin >> b; getchar(); cin >> c; getchar(); n = a.size(); for (i = 0; i < n; i++) { x = a[i] - 9...
0
#include <bits/stdc++.h> using namespace std; int const N = 1e5 + 10; int n, a[N]; int b[N]; int par[N], sz[N]; long long sum[N]; int root(int v) { if (par[v] == v) return v; return root(par[v]); } void merge(int x, int y) { x = root(x), y = root(y); if (x == y) return; if (sz[y] > sz[x]) swap(x, y); par[y]...
8
#include <bits/stdc++.h> using namespace std; const long long inf = 1000000000; const long long mod = 1000000007; template <class T> void read_vector(vector<T>& __cur) { for (T& _cnt : __cur) { cin >> _cnt; } } template <class T> T lcm(T a, T b) { return abs(a * b) / __gcd(a, b); } struct msg { long long wi...
6
#include <bits/stdc++.h> using namespace std; int n; int id[100010], pre[100010], t[100010]; int stk[100010]; int top; int max(int x, int y) { return x > y ? x : y; } int main() { scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%d", &id[i]); top = 0; stk[++top] = 0; t[0] = 1000000000; for (int i = 1; i ...
11
#include <bits/stdc++.h> using namespace std; int visited[200001][2]; long long arr[200001]; long long dp[200001][2]; int n; long long solve(int index, int turn) { if (index == n) return 0; if (visited[index][turn]) return dp[index][turn]; visited[index][turn] = 1; if (turn == 0) { dp[index][turn] = max(dp[...
14
#include <bits/stdc++.h> using namespace std; const int size = 200000000; map<int, int> mp; int main() { int n, k, x, q, res; while (cin >> n >> k) { mp.clear(); for (int i = 0; i < n; ++i) { cin >> x; for (int j = 1; j * x <= size && j <= k; ++j) { if (mp.find(j * x) == mp.end()) { ...
11
#include <bits/stdc++.h> using namespace std; int x, n, r, ress, resf, sub, fil; string a, b, last; vector<string> start; map<string, bool> k, file; map<string, vector<string> > v; void dfs(string s) { k[s] = true; sub++; if (file[s]) { fil++; sub--; } for (int i = 0; i < v[s].size(); i++) { if (!...
10
#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(unsigned long long &x) { scanf("%llu", &x); } void _R(double &x) { scanf("%lf", &x); } void _R(char &x) { scanf(" %c", &x); } void _R(c...
16
#include <bits/stdc++.h> using namespace std; int main(void) { long long int n, t, p, k; cin >> n >> t; if (n == 1 && t == 10) { cout << -1 << endl; return 0; } if (t == 10) { for (int i = 1; i <= n; i++) { if (i == 1) cout << 1; else cout << 0; } cout << endl; ...
2
#include <bits/stdc++.h> using namespace std; int main() { int a, s, d, m, n; deque<int> f; scanf("%d%d%d", &a, &s, &d); for (int i = 0; i < a; i++) { scanf("%d", &n); f.push_back(n); } for (int i = 0; i < s; i++) { m = *max_element(f.begin(), f.end()); for (int u = 0; u < a; u++) { if...
0
#include <bits/stdc++.h> using namespace std; int main() { cin.tie(nullptr); ios_base::sync_with_stdio(false); int n, m; cin >> n >> m; vector<int> A(m); vector<vector<bool>> B(n); for (int i = 0; i < n; i++) { string s; cin >> s; for (int j = 0; j < m; j++) B[i].push_back(s[j] == '1'); } ...
4
#include <bits/stdc++.h> using namespace std; int n, m, h[227], cnt = 1, dis[227], vis[227]; int pre[227], px[227], ans = 0; struct Edge { int to, next, s, c; } e[100127]; inline void AddEdge(int x, int y, int s, int c) { e[++cnt] = (Edge){y, h[x], s, c}; h[x] = cnt; e[++cnt] = (Edge){x, h[y], 0, -c}; h[y] = ...
18
#include <bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; const int MAX = 5e5 + 5; const long long MAX2 = 11; const long long MOD = 1000000007; const long long INF = 2e18; const int dr[] = {1, 0, -1, 0, 1, 1, -1, -1, 0}; const int dc[] = {0, 1, 0, -1, 1, -1, 1, -1, 0}; const double pi = acos(-1); const d...
14
#include <bits/stdc++.h> using namespace std; const int MAXN = 2.5e5 + 5; const int MAXM = 5e5 + 5; namespace LCT { struct Node { Node *fa; union { Node *son[2]; struct { Node *ls, *rs; }; }; bool rev_tag; int vtag, val, mx; Node(void) {} Node(Node *emp, int _val) : fa(emp), ls(emp...
19
#include <bits/stdc++.h> using namespace std; template <class T> inline T mod_v(T num) { if (num >= 0) return num % 1000000007; else return (num % 1000000007 + 1000000007) % 1000000007; } template <class T> inline T gcd(T a, T b) { a = abs(a); b = abs(b); while (b) b ^= a ^= b ^= a %= b; return a; }...
1
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; const long long nax = 3e5 + 5; long long cnt[nax]; long long f[nax]; signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long n; cin >> n; long long mx = 0; long long ans = 0; for (long long i ...
8
#include <bits/stdc++.h> using namespace std; const int mn = 1e5 + 10; int a[mn], b[mn]; int gr(int x) { if (x == 1) return 1; if (x == 2) return 0; if (x == 3) return 1; if (x == 4) return 2; if (x & 1) return 0; int y = gr(x / 2); if (y == 1) return 2; return 1; } int main() { int n, k, i; scanf("...
14
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const int maxn = 100010; map<string, int> mp; int pi[110], ct[110]; int main() { int ptr, n, m, i, ma, mi, cc; string na; while (~scanf("%d%d", &n, &m)) { memset(ct, 0, sizeof ct); mp.clear(), ptr = 1; ma = mi = 0; for (i = ...
3
#include <bits/stdc++.h> using namespace std; int a[100005], b[100005], c[100005]; int main() { int n, m, k, c; scanf("%d%d%d", &n, &m, &k); for (int i = 0; i < n; ++i) scanf("%d", &a[i]); for (int i = 0; i < m; ++i) scanf("%d", &b[i]); sort(a, a + n); sort(b, b + m); int l = 0, r = min(n, m); while (l ...
10
#include <bits/stdc++.h> using namespace std; void useFileInput() { freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); } void setMyPrecision(int n) { cout << fixed << setprecision(n); } bool test = 0; bool fileInput = 0; bool found(string flw) { return (flw == "ABC" || flw == "ACB" || flw == "B...
1
#include <bits/stdc++.h> using namespace std; const int N = 105; int n, m; int b[N][N]; bool row[N], col[N]; int ans[N][N]; int main() { scanf("%d%d", &n, &m); for (int i = 1; i <= n; ++i) row[i] = 1; for (int i = 1; i <= m; ++i) col[i] = 1; for (int i = 1; i <= n; ++i) { for (int j = 1; j <= m; ++j) { ...
5
#include <bits/stdc++.h> const long long mod = 998244353ll; using namespace std; int main() { cin.sync_with_stdio(0); cin.tie(0); cout.tie(0); long long n; cin >> n; vector<long long> a(2 * n); for (long long i = 0; i < (2 * n); i++) cin >> a[i]; sort((a).begin(), (a).end()); long long LIM = 150005; ...
11
#include <bits/stdc++.h> using namespace std; const int md = int(1e9) + 7; const int inf = 0x3f3f3f3f; const long long infl = 0x3f3f3f3f3f3f3f3f; const int mx = 1 << 19; int tree[2 * mx], flag[2 * mx]; void update(int i) { while (i /= 2) tree[i] = tree[i << 1] + tree[i << 1 | 1]; } int query(int i, int l, int r, int ...
15
#include <bits/stdc++.h> using namespace std; void solve() { long long n, k; cin >> n >> k; long long lb = 1, rb = 3 * k, mb; while (lb < rb) { mb = (lb + rb) / 2; if ((mb - mb / n) == k && mb % n) break; if (mb - mb / n >= k) rb = mb; else lb = mb + 1; } cout << mb << '\n'; } in...
4
#include <bits/stdc++.h> using namespace std; long long n, a, ans; signed main() { ios_base::sync_with_stdio(0), cin.tie(0); long long SG[61] = {0, 1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, ...
13
#include <bits/stdc++.h> using namespace std; template <class L, class R> ostream &operator<<(ostream &os, pair<L, R> P) { return os << "(" << P.first << "," << P.second << ")"; } template <class T> ostream &operator<<(ostream &os, vector<T> V) { os << "["; for (auto vv : V) os << vv << ","; return os << "]"; }...
11
#include <bits/stdc++.h> using namespace std; const long long MAXN = 2e5 + 5; const long long MOD = 1e9 + 7; const long long INF = 3e18 + 19763; long long pw(long long a, long long b) { return b == 0 ? 1LL : (pw(a * a, b / 2) % MOD * (b % 2 == 0 ? 1LL : a)); } long long p[MAXN], ans[MAXN]; vector<pair<long long, long...
2
#include <bits/stdc++.h> using namespace std; int T, n; int main() { int i, j; cin >> T; while (T--) { scanf("%d", &n); for (i = 0; i <= n / 3; i++) { for (j = 0; j * 5 + i * 3 <= n; j++) { if ((n - i * 3 - j * 5) % 7 == 0) { printf("%d %d %d\n", i, j, (n - i * 3 - j * 5) / 7); ...
1
#include <bits/stdc++.h> using namespace std; const long double pi = 2 * acos(0.0); template <class T> bool umin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } template <class T> bool umax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T, class TT> bool pa...
1
#include <bits/stdc++.h> using namespace std; map<int, long long> p; int main() { long long n; cin >> n; for (int i = 0; i < n; i++) { int x; cin >> x; p[x]++; } map<int, long long>::iterator it; long long ans = 0; for (it = p.begin(); it != p.end(); it++) { if (it->first > 0) break; i...
4
#include <bits/stdc++.h> using namespace std; long long mod; inline long long add(long long x, long long y) { x += y; if (x >= mod) x -= mod; return x; } inline long long sub(long long x, long long y) { x -= y; if (x < 0) x += mod; return x; } inline long long mul(long long x, long long y) { return (x * 1LL...
9
#include <bits/stdc++.h> using namespace std; ifstream fin("AAtest.in.txt"); long long n, k, jad[4][2005], jad1[4][2005], mit; long long c = 998244353; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cerr.tie(0); cin >> n >> k; jad[0][1] = 1; jad[1][2] = 1; jad[2][2] = 1; jad[3][1] = 1;...
9
#include <bits/stdc++.h> using namespace std; long long M[20]; long long R[20]; int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } int main() { cout.precision(10); int n; cin >> n; long long mx = 1; for (int i = 1; i <= n; ++i) { cin >> M[i]; mx = mx * M[i] / gcd(mx, M[i]); } for (int i = 1; ...
9
#include <bits/stdc++.h> using namespace std; int x[1010], y[1010], t[1010]; void update(int idx, int val, int n) { while (idx <= n) { t[idx] = (t[idx] + val) % 1000000007; idx += idx & (-idx); } } int sum(int idx) { int s = 0; while (idx > 0) { s = (s + t[idx]) % 1000000007; idx -= idx & (-idx)...
8
#include <bits/stdc++.h> using namespace std; char w[1000050]; int ch[1000050][26], fa[1000050], len[1000050], lst = 1, cnt = 1, pos[1000050]; int head[1000050], to[1000050], nxt[1000050], tot; int f[22][1000050], Lg[1000050], dp[1000050], ans, dfn[1000050], enp[1000050]; int mx[1000050 << 2], n; inline void add(int u,...
25
#include <bits/stdc++.h> int main() { int n, i, sum = 0; scanf("%d", &n); for (i = 1; i < n; i++) { sum = sum + i; if (sum == n) { printf("YES"); return 0; } else if (sum > n) { printf("NO"); return 0; } } if (n == 1 || n == 0) printf("YES"); if (n == 2) printf("NO");...
0
#include <bits/stdc++.h> using namespace std; char str[5][101]; int main() { int n, k; cin >> n >> k; printf("YES\n"); if (k % 2) { if (k <= n - 2) { str[1][n / 2] = '#'; for (int i = 1; i <= k / 2; i++) { str[1][n / 2 - i] = str[1][n / 2 + i] = '#'; } } else { for (int i...
8
#include <bits/stdc++.h> using namespace std; int a, b, n, l, t, m, rmx; long long int ans, bite; void reset(); void b_search(int low, int top); long long int cal(int mid); int main() { int i, j, k; while (scanf("%d %d %d", &a, &b, &n) == 3) { for (i = 0; i < n; i++) { scanf("%d %d %d", &l, &t, &m); ...
11
#include <bits/stdc++.h> using namespace std; const int N = 100101; const double PI = acos(-1); const double eps = 1e-9; int f[N], g[N], tmp[N], n, m; double L[N], ang[N]; pair<double, double> a[N], b[N * 2]; bool chk(double lim) { int cnt = 0; for (int i = 1; i <= n; ++i) { double t = acos(lim / L[i]); dou...
23
#include <bits/stdc++.h> using namespace std; int Set(int N, int pos) { return N |= (1LL << pos); } int Reset(int N, int pos) { return N &= ~(1LL << pos); } bool Check(int N, int pos) { return N & (1LL << pos); } int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1}; inline void cn(long &n) { n = 0; long ch = getchar(); ...
10
#include <bits/stdc++.h> using namespace std; const int N = 300010; int n, w, a[N], b[N]; int cur[N]; long long ans; struct node { long long val; int pos; node(int P, long long V) { pos = P, val = V; } bool operator<(const node &C) const { return val > C.val; } }; priority_queue<node> q[6]; const int limit[] = ...
18