solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, a; cin >> n; vector<int> arr(n); for (__typeof(n) i = (0) - ((0) > (n)); i != (n) - ((0) > (n)); i += 1 - 2 * ((0) > (n))) cin >> arr[i]; sort(arr.begin(), arr.end()); in...
6
#include <bits/stdc++.h> using namespace std; int main() { int f, g; string s; cin >> f >> s; int hours = (s[0] - '0') * 10 + (s[1] - '0'), minutes = (s[3] - '0') * 10 + (s[4] - '0'); if (minutes > 59) minutes %= 10; if (f == 12) { if (hours == 0) hours = 1; else if (hours > 12) { ...
5
#include <bits/stdc++.h> using namespace std; int n, k, in, a[100005], cnt; string s; int main() { scanf("%d %d", &n, &k); cin >> s; for (int i = 1; i <= n; ++i) { a[i] = s[i - 1] - '0'; } while (k--) { for (; in < n; ++in) { if (a[in] == 4 && a[in + 1] == 7) { break; } } i...
7
#include <bits/stdc++.h> using namespace std; int main() { long n = 0, i = 0, a = 0, max = 0; long mas[3][100001] = {0}; cin >> n; for (i = 1; i <= n; ++i) { cin >> a; if (a > max) max = a; { if (mas[0][a] == 0) { mas[0][a] = i; continue; } if (mas[1][a] == 0) { ...
5
#include <bits/stdc++.h> using namespace std; long long int dp[4][1005][1005]; int arr[1005][1005]; int main() { int i, j, k; int n, m; long long int a, b; memset(dp, 0, sizeof(dp)); memset(arr, 0, sizeof(arr)); scanf("%d%d", &n, &m); for (i = 1; i <= n; i++) { for (j = 1; j <= m; j++) scanf("%d", &ar...
8
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 10; struct Point { int index; int x; int all; bool operator<(const Point &a) const { return all < a.all; } }; Point p[maxn]; int k; int n; int c; int a[maxn]; int sum[maxn]; int main() { scanf("%d", &k); int c = 0; for (int i = 0; i < k;...
6
#include <bits/stdc++.h> using namespace std; int main() { long long n, k; cin >> n >> k; long long r = n / k; if (r % 2 == 0) cout << "NO"; else cout << "YES"; return 0; }
0
#include <bits/stdc++.h> using namespace std; int N, A, B; int dp[5005]; char a[5005]; int z[5005]; int zfunc(int t) { int ans = 0; z[t] = 0; int l = N + 1; int r = N + 1; for (int i = t - 1; i >= 1; i--) { z[i] = 0; if (r <= i) z[i] = min(i - r + 1, z[t - l + i]); while (i - z[i] > 0 && a[i - z[i...
13
#include <bits/stdc++.h> using namespace std; double pai = 3.141592653589793; 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 << 1) + (x << 3) + (ch ^ 48); ch = getchar();...
8
#include <bits/stdc++.h> using namespace std; const int P = 1e9 + 7; long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } long long qpow(long long a, long long n) { long long r = 1 % P; for (a %= P; n; a = a * a % P, n >>= 1) if (n & 1) r = r * a % P; return r; } void exgcd(long long a, l...
18
#include <bits/stdc++.h> using namespace std; const int N = 100005; char ds[2][N][10]; int sz[2]; vector<int> tudo[2], nham[2], trong[2]; bool chiem[N]; char s[100]; int main() { int n; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%s", s); int t; scanf("%d", &t); strcpy(ds[t][sz[t]++], s)...
14
#include <bits/stdc++.h> using namespace std; const int N = 200100; const long long MOD = 998244353; int n, k, a[N]; long long t[N * 4]; int ob[N * 4]; long long ob2[N * 4]; long long znch[N * 4]; void push(int v, int l, int r) { if (ob[v] != 0) { t[v + v] *= znch[v]; t[v + v + 1] *= znch[v]; ob2[v + v] *...
14
#include <bits/stdc++.h> using namespace std; int main() { long long int n, i, j = 0, k, l = 0, c1 = 0, c2 = 0; cin >> n; long long int arr1[n]; map<long long int, long long int> m; set<long long int> s; multiset<long long int> ms; for (i = 0; i < n; i++) { cin >> arr1[i]; s.insert(arr1[i]); m...
2
#include <bits/stdc++.h> using namespace std; const int N = (1 << 22); int n, m, ans; bool a[N], vis[N]; void dfs(int now) { if (vis[now]) { return; } vis[now] = true; for (int i = 0; i < n; ++i) { if (now & (1 << i)) { dfs(now ^ (1 << i)); } } if (a[now]) { dfs(now ^ ((1 << n) - 1)); ...
17
#include <bits/stdc++.h> typedef short int int16; typedef int int32; typedef long long int64; const double PI = acos(-1.0); const long long MOD = (long long)1E9 + 7LL; template <class T> T Susake_pow(T a, T b) { T res; if (b == 0) return 1; else while ((b & 1) == 0) { b >>= 1; a *= a; } ...
11
#include <bits/stdc++.h> using namespace std; const long long int inf = 1e9 + 5; template <typename T> void chmax(T& a, T b) { if (a < b) a = b; } template <typename T> void chmin(T& a, T b) { if (a > b) a = b; } void prepare_lookup_table() {} void sssp(long long int& s, vector<vector<pair<long long int, ...
13
#include <bits/stdc++.h> using namespace std; void print_vector(vector<int> v); void print_array(long long* array, int start, int end); int n, m; long long l[200100], r[200100], s[200100], b[200100]; long long a[200100]; int idx[200100], bdx[200100]; vector<int> sol; bool cmp(int i, int j) { if (b[i] == b[j]) ret...
12
#include <bits/stdc++.h> using namespace std; const int Max1 = 1e5 + 4; const int Max2 = 2e5 + 4; const int Mod = 1e9 + 7; vector<vector<pair<int, int> > > N(1004); vector<int> visited(1004, 0); vector<int> tank, tap; vector<int> idegree(1004, 0); vector<int> odegree(1004, 0); int dfs(int house, int& tap) { int len =...
6
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int tmp = n - 2; long long ans = 0; for (int i = 1; i < n; i++) { if (i == 1) ans += tmp; else ans += (tmp - 1); } cout << ans << endl; return 0; }
3
#include <bits/stdc++.h> using namespace std; inline bool iseq(double x, double y) { if (fabs(x - y) < 1e-8) return true; return false; } template <typename T> inline T hpt(T x1, T y1, T x2, T y2) { return hypot(x1 - x2, y1 - y2); } template <typename T> inline T gcd(T a, T b) { if (!b) return a; else ...
4
#include <bits/stdc++.h> using namespace std; void time_calc() { cout << endl << "Clock ticks: " << clock() << " Seconds: " << (double)clock() / CLOCKS_PER_SEC * 1000; } bool visited[26]; vector<pair<int, int> > v; bool check(int n, int m) { int nR, mR; for (int i = 0; i < v.size(); i++) { nR = ...
3
#include <bits/stdc++.h> using namespace std; int x, y, i, j, k, l; int main() { cin >> x >> y; int t = 0; while (1) { if (x * 100 + y * 10 < 220) break; if (!t) { if (x > 1 && y > 1) { x -= 2; y -= 2; } else if (x > 0 && y > 11) { x--; y -= 12; } else if ...
4
#include <bits/stdc++.h> using namespace std; bool cmp(pair<int, int> a, pair<int, int> b) { return a > b; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >> n; vector<pair<int, int> > a(n); for (int i = 0; i < n; i++) cin >> a[i].first, a[i].second = i + 1; sort(a.begin() + 1, a.end()...
4
#include <bits/stdc++.h> using namespace std; const int N = 1010; const int dx[5] = {0, 1, 0, -1, 0}; const int dy[5] = {0, 0, 1, 0, -1}; int n, m, k; int col[N][N]; int dis[50][N][N]; int vis[N][N]; int cvis[60]; struct ha { int x, y; }; queue<ha> q; vector<ha> a[60]; void Bfs(int c) { memset(vis, 0, sizeof(vis));...
18
#include <bits/stdc++.h> using namespace std; int main() { int x, y, a, b; cin >> x; cin >> y; cin >> a; cin >> b; vector<pair<int, int> > result; for (int i = a; i <= x; i++) { for (int j = b; j <= y; j++) { if (i > j) result.push_back(make_pair(i, j)); else break; } ...
3
#include <bits/stdc++.h> using namespace std; int i = 0; int main() { int n; cin >> n; while (n--) { int a; cin >> a; if (a < 4) { cout << 4 - a << endl; } else { if (a % 2 == 0) { cout << '0' << endl; } else { cout << '1' << endl; } } } return 0; }
0
#include <bits/stdc++.h> using namespace std; const long long inf = 1e9; const double PI = 3.14159265358979; char t[(100)][(100)]; int main() { ios::sync_with_stdio(0); cin.tie(0); int n, l, w; cin >> n >> l >> w; vector<int> v1; vector<double> v2; for (int i = 0; i < n; ++i) { int x, dir; cin >> ...
17
#include <bits/stdc++.h> using namespace std; int main() { long long n, flag = 0; cin >> n; vector<long long> v(n); for (__typeof(n) i = (0) - ((0) > (n)); i != (n) - ((0) > (n)); i += 1 - 2 * ((0) > (n))) cin >> v[i]; for (__typeof(n) i = (0) - ((0) > (n)); i != (n) - ((0) > (n)); i += 1 - ...
5
#include <bits/stdc++.h> using namespace std; int f[100005]; int x[100005], y[100005], t[100005]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int r, n; cin >> r >> n; for (int i = 1; i <= n; i++) { cin >> t[i] >> x[i] >> y[i]; f[i] = -1e9; } x[0] = 1; y[0] = 1; t[...
12
#include <bits/stdc++.h> using namespace std; using namespace chrono; void _print(long long t) { cerr << t; } void _print(int t) { cerr << t; } void _print(string t) { cerr << t; } void _print(char t) { cerr << t; } void _print(long double t) { cerr << t; } void _print(double t) { cerr << t; } void _print(unsigned long...
4
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; char c[1003][1003]; int n, m; char d[N]; int l[N]; int k; int ps[1003][1003], pr[1003][1003]; vector<char> ans; inline bool ok(int x, int y) { int q, w; for (int i = 1; i <= k; i++) { q = x; w = y; if (d[i] == 'N') q -= l[i]; if (d...
9
#include <bits/stdc++.h> #define ll long long #define ull long long int #define pb push_back #define vi vector<int> #define fast ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr); #define MOD 1000000007 #define ff first #define ss second #define sz(a) ((int)(a).size()) #define all(a) (a).begin(), (a...
8
#include <bits/stdc++.h> using namespace std; const int N = 4100, M = 200010, INT_INF = 2100000000; int tot = 1, src, sink; int to[M], _next[M], cap[M], head[N], pre[N], vis[N], cur[N], used[N]; void addEdge(int u, int v, int c) { to[++tot] = v, _next[tot] = head[u], cap[tot] = c, head[u] = tot; } void init() { tot...
16
#include <bits/stdc++.h> using namespace std; const int maxn = 2000 + 233; struct Edge { int from, to, cap, flow, cost; }; vector<Edge> edges; vector<int> g[maxn]; queue<int> q; int d[maxn], p[maxn]; bool inq[maxn]; void add_edge(int from, int to, int cap, int cost) { edges.push_back((Edge){from, to, cap, 0, cost})...
16
#include <bits/stdc++.h> using namespace std; template <class T, class first> inline bool getbit(T a, first i) { T t = 1; return ((a & (t << i)) > 0); } template <class T, class first> inline T setbit(T a, first i) { T t = 1; return (a | (t << i)); } template <class T, class first> inline T resetbit(T a, first ...
16
#include <bits/stdc++.h> using namespace std; template <typename T> T gcd(T a, T b) { for (T c; b; c = b, b = a % b, a = c) ; return a; } template <typename T> T lcm(T a, T b) { return a * b / (gcd(a, b)); } const int inf = 0x3f3f3f3f; const long long infl = 0x3f3f3f3f3f3f3f3fLL; template <typename T> void rd...
16
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e5 + 5; const int MAXM = 2e5 + 5; int pre[MAXN], deep[MAXN]; void init() { for (int i = 0; i < MAXN; i++) { pre[i] = i; deep[i] = 1; } } int find(int now) { while (now != pre[now]) now = pre[now]; return now; } bool AZunion(int u, int v) { ...
15
#include <bits/stdc++.h> using namespace std; int main() { int i, j, n, a[1000], k, s, s1; double sum; while (cin >> n) { for (i = 0; i < n; i++) { cin >> a[i]; } sort(a, a + n); s = 0; s1 = 0; for (j = n - 1; j >= 0; j = j - 2) { s = s + (a[j] * a[j]); } for (k = n - 2...
2
#include <bits/stdc++.h> using namespace std; int main() { cin.tie(nullptr)->sync_with_stdio(false); int q; cin >> q; while (q--) { int n; cin >> n; vector<int> a(n); for (auto &i : a) { cin >> i; } vector<int> nxt(n, -1); vector<map<int, int> > nxtX(n + 1); for (int i = n ...
18
#include <bits/stdc++.h> using namespace std; const int M = 1e9 + 7; long long powmod(long long a, long long b) { long long res = 1; a %= M; assert(b >= 0); for (; b; b >>= 1) { if (b & 1) res = res * a % M; a = a * a % M; } return res % M; } int main() { string s; cin >> s; int pa[s.size() + ...
7
#include <bits/stdc++.h> const int N = 500010, M = 20; int s[M], x[N], y[N], now[N], prev[N][M]; int main() { int n, m, i, j, temp, top, l, r, mid; long long ans = 0; scanf("%d", &n); for (i = 1; i <= n; i++) { scanf("%d", &temp); prev[i][0] = i - temp; if (prev[i][0] < 1) prev[i][0] = 1; prev[i...
9
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int n, k; cin >> n >> k; for (long long int i = 0; i < n; i++) { for (long long int j = 0; j < n; j++) if (i == j) cout << k << ' '; else cout << "0 "; cout...
0
#include <bits/stdc++.h> using namespace std; const int N = 1000 * 1000 + 20; const int N5 = 300 * 1000 + 10; const int N3 = 3000 + 20; const long long mod = 1000 * 1000 * 1000 + 7; const long long inf = LLONG_MAX / 10; long long par[N], dis[N], rnk[N]; vector<pair<long long, long long> > e[N]; vector<pair<long long, p...
18
#include <bits/stdc++.h> using namespace std; const long long inf = 1e18; long long cost(int height); long long n, a, r, m; vector<long long> pillars; int main() { cin >> n >> a >> r >> m; long long l = inf, r = 0; pillars.resize(n); for (int i = 0; i < pillars.size(); i++) { cin >> pillars[i]; l = min(...
13
#include <bits/stdc++.h> using namespace std; int n; long long a[100010]; int v[48][300010]; int m; int ll, rr; int flag[300010]; int now[300010]; void build(int t, int u, int l, int r) { if (l > r) return; if (l == r) { v[t][u] = a[l]; return; } int h = (l + r) >> 1; build(t, 2 * u, l, h); build(t,...
18
#include <bits/stdc++.h> using namespace std; int ans[10000000]; int lenn = 0; int n = 0; int check(int x) { int now = x; while (x) { now += x % 10; x /= 10; } if (now == n) return 1; else return 0; } int main() { char s[20]; scanf("%s", s); int len = strlen(s); for (int i = 0; i < len...
4
#include <bits/stdc++.h> using namespace std; int n, dbu=1, dbt; vector<int> u, sz, ans; string s; bool baj; void tolt(int a, int b) { if (a<1 || a==2 || (a%2==0 && b<2) || (a>1 && b==0)) { baj=1; } if (a%2==0) { ans.push_back(2); a-=3; } for (int i=1; 2*i<=a; i++) { ...
19
#include <bits/stdc++.h> using namespace std; long long PT[103][103 + 1]; void build_pascal_triangle() { PT[0][0] = 1; for (int n = 1; n < 103; ++n) { PT[n][0] = 1; for (int k = 1; k < n; ++k) { PT[n][k] = (PT[n - 1][k - 1] + PT[n - 1][k]) % 1000000007; } PT[n][n] = 1; } } long long Choose(i...
11
#include <bits/stdc++.h> int const N = 2222; long long ans; int n, m; int g[N][N], h[N][N], up[N][N], left[N][N], right[N][N], he[N], f[N], ne[N], col[N], s[N][N], ss[N][N]; int get(int x) { int ret = 0; for (int i = x; i >= 0; i = (i & (i + 1)) - 1) ret += f[i]; return ret; } void add(int x, int y) { for (...
15
#include <bits/stdc++.h> using namespace std; inline void OPEN(const string &s) { freopen((s + ".in").c_str(), "r", stdin); freopen((s + ".out").c_str(), "w", stdout); } int main() { string a, b; cin >> a >> b; int n = a.length() / 2; int na = 0, nb = 0; for (int i = 0; i < (n); ++i) { int actiona, ac...
9
#include <bits/stdc++.h> using namespace std; const int INF = 0x7fffffff; int n, m, x, zero; priority_queue<int, vector<int>, greater<int> > q; long long ans; void func(int x) { int a, b; if (((int)sqrt(x)) * ((int)sqrt(x)) == x) { m++; return; } a = (int)sqrt(x) * (int)sqrt(x); b = ((int)sqrt(x) + 1)...
8
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 5; int n, a[maxn], b[maxn]; inline int rd() { int ret = 0, af = 1; char gc = getchar(); while (gc < '0' || gc > '9') { if (gc == '-') af = -af; gc = getchar(); } while (gc >= '0' && gc <= '9') ret = ret * 10 + gc - '0', gc = getchar(...
14
#include <bits/stdc++.h> using namespace std; char g[777][777]; long long n, sn[100007], p[1000007], tot, cur, ans; void omar() { for (int i = 2; i <= 1000000; i++) { if (p[i]) { continue; } for (int j = i; j <= 1000000; j += i) { p[j] = i; } } } int main() { omar(); scanf("%lld", &n...
9
#include <bits/stdc++.h> using namespace std; long long v[100010]; struct biao { long long a, b; }; biao a[100010]; bool cmp(biao a, biao b) { return a.a < b.a; } bool ccc(biao a, biao b) { return a.b < b.b; } int main() { long long n, h; cin >> n >> h; for (long long i = 0; i < n; i++) { cin >> a[i].a; ...
10
#include <bits/stdc++.h> using namespace std; int main() { long long k, d, t, cycle, subTimes; long long ans = 0, velocity, t2; scanf("%lld%lld%lld", &k, &d, &t); k *= 2; d *= 2; t *= 2; subTimes = (k + d - 1) / d; cycle = subTimes * d; velocity = k + (cycle - k) / 2; ans = t / velocity * cycle; t...
9
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const int maxn = 5e5 + 10; struct Point { int x, y; } a[maxn]; int n, mxlen; char s[maxn]; void print(int a[], int n, int st = 0) { for (int i = 0; i < n; i++) { if (i != 0) printf(" "); printf("%d", a[i + st]); } printf("\n"); } ...
18
#include <bits/stdc++.h> using namespace std; int main() { int n, mo, c; scanf("%d", &n); scanf("%d", &mo); scanf("%d", &c); vector<int> ar(n, 0); int l = 0, r = n - 1; int m = (c + 1) / 2; while (l <= r) { int x; scanf("%d", &x); int ans = -1; if (x > m) { if (r == n - 1 || ar[r +...
12
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const long long INF64 = 0x3f3f3f3f3f3f3f3f; const int N = 1e2 + 10; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.precision(10); cout << fixed; int n, p; cin >> n >> p; vector<pair<int, int> > a(n); for (int i = 0; i ...
9
#include <bits/stdc++.h> using namespace std; void solve(int cno) { long long i, j, l, k, n; string brr; cin >> brr; n = brr.size(); long long arr[n]; for (i = 0; i < n; i++) { arr[i] = (brr[i] - '0'); } long long presum[n]; presum[0] = arr[0]; for (i = 1; i < n; i++) { if (arr[i] == 1) ...
6
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long n, k; cin >> n >> k; if (n > (k * k - k)) { cout << "NO" << endl; return 0; } cout << "YES" << endl; for (int i = 1; i <= k && n > 0; i++) { int j = i + 1; wh...
9
#include <bits/stdc++.h> using namespace std; long long dp[300100][5][5]; long long a[300100]; long long n, x; long long MAX(long long a, long long b) { return a > b ? a : b; } long long solve(long long i, long long s1, long long s2) { if (dp[i][s1][s2] != -1) return dp[i][s1][s2]; long long maxi = -1e18; for (lo...
11
#include <bits/stdc++.h> using namespace std; const int MAX_N = 10100; char s[MAX_N]; int vis1[30][30], vis2[30][30][30]; struct Ans { char str[10]; bool operator<(const struct Ans& rhs) const { return strcmp(str, rhs.str) < 0; } } ans[MAX_N * 100]; int main() { while (~scanf("%s", s)) { int len = strle...
10
#include <bits/stdc++.h> using namespace std; long long n, k; struct Phone { string name; int taxi, pizza, girl; Phone(string n, int t, int p, int g) { name = n; taxi = t; pizza = p; girl = g; } }; vector<Phone> v; bool taxi(string num) { string nov = ""; for (int i = (0); i < (num.size()); ...
4
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n, ai; vector<int> v; cin >> n; for (int i = 0; i < n; i++) { cin >> ai; v.push_back(ai); } int ln = min(2, (int)v.size()); for (int i = 0; i < n - 1; i++) { int p1 = v[i]; int ...
3
#include <bits/stdc++.h> inline int pidorand() { return ((rand() & 32767) << 15) | (rand() & 32767); } using namespace std; inline int nxt() { int x; scanf("%d", &x); return x; } const int N = 211111; vector<int> a[N]; int sz[N]; int pr[N]; int old_pr[N]; int level[N]; void dfs(int v, int p = -1) { pr[v] = p; ...
18
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 1, maxm = 2e2 + 2; int n, m, blk = 500, fa[maxn], son[maxn], a[maxn], ans, pos[maxn], val[maxn], col[maxn], lmin[maxn], rmax[maxn], add[maxm], sum[maxm][maxn << 1], siz[maxn], dep[maxn], dfn[maxn], rnk[maxn], top[maxn], cnt, to[max...
21
#include <bits/stdc++.h> using namespace std; const long long int mod = 1e9 + 7; const long long int inf = 2e9 + 5; double PI = 3.14159265358979323846; void solve() { long long int n; cin >> n; vector<vector<long long int> > a(33); for (int i = 0; i < n; i++) { long long int x; cin >> x; int index =...
6
#include <bits/stdc++.h> using namespace std; char a[10006]; int main() { int n; while (~scanf("%d%s", &n, a)) { int len = strlen(a); int cnt = 1; int ans = 0; for (int i = 0; i < len; i++) { if ((cnt - 1) % n == 0) { if (i >= 3) { if (a[i - 1] == a[i - 2] && a[i - 2] == a[i ...
5
#include <bits/stdc++.h> using namespace std; int a, b, f, k; int solve() { if (f > b || a - f > b) return -1; if (k == 2 && (a - f) * 2 > b) return -1; if (k > 2 && (f * 2 > b || (a - f) * 2 > b)) return -1; int d = b - f, res = 0; for (int i = 0; i < k; ++i) { if (i == k - 1) { if (i & 1) { ...
7
#include <bits/stdc++.h> using namespace std; int n; pair<int, int> par[100100]; int chain[200100]; int chain_size; void add_edge(int u, int v) { cout << u << ' ' << v << endl; } int main() { ios::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); cin >> n; for (int i = 1; i <= n; i++) { cin >> par[i].fir...
12
#include <bits/stdc++.h> using namespace std; const int N = 4; const int M = 2; const int K = 2; int a[N][M][K]; int main() { int n; cin >> n; for (int i = 0; i < N; i++) for (int j = 0; j < M; j++) for (int k = 0; k < K; k++) scanf("%d", &a[i][j][k]); for (int i = 0; i < N; i++) for (int j = 0; j...
3
#include <bits/stdc++.h> using namespace std; int main() { int n, k, mini, maxi; cin >> n >> k; if (n == 1 || k == 0 || n == k) { printf("%d %d\n", 0, 0); return 0; } maxi = min(n - k, 2 * k); mini = 1; printf("%d %d\n", mini, maxi); return 0; }
4
#include <bits/stdc++.h> using namespace std; stack<time_t> time_stack; void startTimer() { time_stack.push(clock()); } double stopTimer() { double time = clock() - time_stack.top(); time_stack.pop(); return time / double(CLOCKS_PER_SEC); } long long v[4010], d[4010]; list<pair<long long, int> > p; int main() { ...
10
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e4 + 10; int vis[MAXN], a[MAXN]; map<int, int> tag; int main(void) { int n, m; cin >> n >> m; bool flag = false; while (m--) { int k; bool ok = false; cin >> k; memset(vis, 0, sizeof(vis)); tag.clear(); for (int i = 0; i < k...
5
#include <bits/stdc++.h> using namespace std; struct edges { int to, pre, c; } e[100010 << 1]; int etop, h[100010], d[100010], vis[100010], minc[100010]; inline int add_edge(int u, int v, int c) { return e[++etop].pre = h[u], e[etop].to = v, e[etop].c = c, h[u] = etop; } queue<int> q; int nxt[100010], pre[100010], ...
14
#include <bits/stdc++.h> using namespace std; const long long N = 1e3 + 7; const long long INF = 1e9; const long long mod = 1e9 + 7; int n; string s; set<string> ans; int main() { ios_base::sync_with_stdio(0); cin >> n; for (int i = 1; i <= n; i++) { cin >> s; set<char> a(s.begin(), s.end()); string b...
1
#include <bits/stdc++.h> using namespace std; const int MAX_N = 4; int n; int a[MAX_N * MAX_N]; bool used[MAX_N * MAX_N]; bool check(int x[4][4], int n) { int sum = 0; for (int i = 0; i < n; ++i) { sum += x[0][i]; } for (int r = 0; r < n; ++r) { if (accumulate(x[r], x[r] + n, 0) != sum) { return f...
7
#include <bits/stdc++.h> using namespace std; const long long INF = 1e18; long long MOD = 100000000; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, m; cin >> n >> m; string s[n]; string s1[m]; for (int i = 0; i < n; ++i) cin >> s[i]; for (int i = 0; i < m; ++i) cin >> s1[i]; int ...
0
#include <bits/stdc++.h> using namespace std; const int MaxN = 300000; long long a[MaxN]; int main() { int n; cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); long long cnt = 0; for (int i = 1; i <= n; i++) cnt += (((i - a[i - 1]) > 0) ? (i - a[i - 1]) : (-(i - a[i - 1]))); cout << c...
4
#include <bits/stdc++.h> using namespace std; using ll = long long; using pll = pair<ll, ll>; using dd = long double; namespace { static bool constexpr dbg = 0; ll constexpr N = -1; ll n, a, b, c; void init() { cin >> n >> a >> b >> c; } void solve() { if (n == 1) cout << 0; else cout << (min(a, b) + (n - 2...
1
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5; int T, t, n, m, x, y, waiting[maxn + 1], target[2], l[maxn + 1], r[maxn + 1], color[maxn + 1]; bool vis[maxn + 1]; vector<int> edge[maxn + 1]; bool paint(int now, int nowcolor) { if (color[now] && color[now] != nowcolor) return false; else ...
24
#include <bits/stdc++.h> using namespace std; int main() { long long N, T, K, D; cin >> N >> T >> K >> D; long long time1 = ceil((float)N / K); time1 *= T; long long start2 = (ceil((float)D / T)) * T; long long cakes_left = N - ((ceil((float)D / T)) * K); long long time2 = start2; long long i, j; i = ...
3
#include <bits/stdc++.h> using namespace std; const int mo[3] = {998244353, 1000000007, 1000000009}; const int K[3] = {137, 1003, 997}; const int maxn = 100003; int f[maxn][3], g[maxn][3], head[maxn], deg[maxn], n; struct EDGE { int to, nxt; } edge[maxn << 1]; void addedge(int u, int v) { static int sz = 0; edge[...
21
#include <bits/stdc++.h> const int MaxN = 200005, MaxS = 1 << 18; const int cIz = 998244353, g_cIz = 3; inline int _(int x) { return x + ((x >> 31) & cIz); } inline int Pow(int a, int b) { int res = 1; for (; b; b >>= 1) { if (b & 1) res = (long long)res * a % cIz; a = (long long)a * a % cIz; } return r...
17
#include <bits/stdc++.h> char grid[5][15]; char s[30]; int x[30], y[30]; int p[30], p1, p2; int a, b1, b2, b, c; void print() { return; for (int i = 0; i < 2; i++) { for (int j = 0; j < 13; j++) printf("%c", grid[i][j]); printf("\n"); } } int main() { for (int i = 0; i < 2; i++) for (int j = 0; j < ...
8
#include <bits/stdc++.h> using namespace std; long long sqdist(pair<int, int> c, long long first, long long second) { return (c.first - (long long)first) * (c.first - (long long)first) + (c.second - (long long)second) * (c.second - (long long)second); } int main() { long long x1, y1, x2, y2; cin >> x1 >>...
5
#include<iostream> #include<cstdio> using namespace std; const int mod=998244353; int fac[5000001],ifac[5000001]; int n=100005,m=100005; inline int add(int x,int y){ return x+y<mod?x+y:x+y-mod; } inline int sub(int x,int y){ return x<y?x+mod-y:x-y; } inline int power(int a,int n){ int tp=1; while(n){ if(n&1) tp=1...
11
#include <bits/stdc++.h> using namespace std; inline int read() { int ret = 0, f = 1; char ch = getchar(); while (ch > '9' || ch < '0') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { ret = (ret << 1) + (ret << 3) + ch - '0'; ch = getchar(); } return ret * f; } ...
17
#include<algorithm> #include<iostream> #include<cstdlib> #include<iomanip> #include<cstring> #include<utility> #include<cstdio> #include<queue> #include<stack> #include<ctime> #include<cmath> #include<list> #include<set> #include<map> typedef long long int ll; //using namespace std; inline int _gcd(const int x,const ...
0
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; const double PI = 3.141592653589793238463; long long n, k; long long a[(int)1e5 + 5], b[(int)1e5 + 5]; bool comp(pair<int, int> p1, pair<int, int> p2) { return p1.first >= p2.first && p1.second > p2.second; } bool fuck(long long mid) { ...
7
#include <bits/stdc++.h> struct Tree { int amount; int arr[210001]; int del[210001]; Tree() { std::cin >> amount; for (int i = 0; i < amount; ++i) { std::cin >> arr[i]; } } int left(int ii, int pp) { if (pp == 0) return amount; return (ii - 1) / pp + 1; } int right(int ii, int ...
14
#include <bits/stdc++.h> using namespace std; int x[222222], n; double d, x1, x2, x3, l, r, md; bool check(double d) { bool f; int ps; x1 = x[1] + d; double xx = x1 + d; ps = 0, f = 0; for (int i = 1; i <= n; i++) if (xx - x[i] < -1e-9) { ps = i, f = 1; break; } if (!f) { x2 = x3 =...
10
#include <bits/stdc++.h> using namespace std; set<pair<int, int>> g[100005]; vector<pair<int, int>> min3[100005]; multiset<long long> star3; set<pair<int, pair<int, int>>> edge3; map<pair<int, int>, int> weight; template <bool add> void upd(int u, int v, int w) { if (u > v) swap(u, v); if constexpr (!add) { w =...
23
#include <bits/stdc++.h> using namespace std; int main() { int a, b, s; cin >> a >> b >> s; a = abs(a); b = abs(b); if (a + b > s) cout << "No"; else { s = s - a - b; if (s % 2 == 0) cout << "Yes"; else cout << "No"; } return 0; }
2
#include <bits/stdc++.h> using namespace std; int n, m; const int Max = 1e6; long long Arr[Max]; long long Pos[Max * 2]; void Build(int rt, int l, int r) { if (l == r) { Pos[rt] = Arr[l] % m; return; } int mid = (l + r) / 2; Build(rt * 2, l, mid); Build(rt * 2 + 1, mid + 1, r); Pos[rt] = (Pos[rt * 2...
11
#include <bits/stdc++.h> using namespace std; int arr[4]; int aux[100010]; int next(int x) { if (x == 0) { if (arr[1] > 0) return 1; else return -1; } if (x == 1) { if (arr[0] > 0) return 0; else if (arr[2] > 0) return 2; else return -1; } if (x == 2) { if...
11
#include <bits/stdc++.h> using namespace std; using ll = long long; int n, k; vector<int> g[100100]; int deg[200200]; int dep[200200]; int par[200200]; void dfs(int node, int p, int d) { par[node] = p; dep[node] = d; for (auto v : g[node]) { if (v == p) continue; dfs(v, node, d + 1); } } void solve() { ...
10
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); string s = *istream_iterator<string>(cin); size_t n = *istream_iterator<int>(cin); vector<int> pos(s.size() / 2, 0); for (size_t i = 0; i < n; i++) ++pos[*istream_iterator<int>(cin) - 1]; int sum = 0; for (size_t i = 0...
6
#include <bits/stdc++.h> using namespace std; const int N = 405; struct Edge { int from, to, nxt, cap, flw; double cost; } e[N * N * 4]; int x[N], y[N], n, edgeCnt, head[N << 1], flw[N << 1], vis[N << 1], p[N << 1], src, snk; double dist[N << 2], d[N][N]; void addEdge(int u, int v, int cap, double cost) { e[e...
16
#include <bits/stdc++.h> using namespace std; map<pair<int, int>, int> edge; set<int> unvis; vector<int> con; int dfs(int x) { int ans = 1; unvis.erase(x); int y = 1; while (1) { set<int>::iterator it = unvis.upper_bound(y); if (it == unvis.end()) break; y = *it; if (edge[{x, y}] || edge[{y, x}]...
13