solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> using namespace std; long long read() { long long ans = 0, f = 1; char ch = getchar(); for (; ch < '0' || ch > '9'; ch = getchar()) if (ch == '-') f = -1; for (; ch >= '0' && ch <= '9'; ch = getchar()) ans = (ans << 3) + (ans << 1) + ch - '0'; return ans * f; } int main() { ...
7
#include <bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; const int T = 30033; int N, q, mod; vector<bitset<T> > v(2 * T); bitset<T> get(int l, int r) { bitset<T> ret; for (l += N, r += N; l < r; l /= 2, r /= 2) { if (l & 1) ret |= v[l++]; if (r & 1) ret |= v[--r]; } return ret; } int num...
23
#include <bits/stdc++.h> using namespace std; const int inf = 300010; int n; map<string, int> war; void read() { cin >> n; int c; string s; for (int i = 0; i < n; i++) { cin >> c >> s; sort(s.begin(), s.end()); if (war.count(s) != 0) war[s] = min(war[s], c); else war[s] = c; } } in...
4
#include <bits/stdc++.h> using namespace std; int n; vector<int> tmp, large, small; char op[20]; int a[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; char check(int i, int j) { fflush(stdout); scanf("%s", op); return op[0]; if (a[i] == a[j]) return '='; return a[i] < a[j] ? '<' : '>'; } void solve1() { int len; ...
10
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n; cin >> n; vector<string> s(n); for (int i = 0; i < n; i++) cin >> s[i]; set<string> st; for (int i = 0; i < n; i++) { set<char> temp; for (int j = 0; j < s[i].size(); j...
1
#include <bits/stdc++.h> using namespace std; long long n; int main() { long long t, rr, i, ii, u, k, p, lh, rh, md, zz; scanf("%lld", &t); for (rr = 0; rr < t; rr++) { scanf("%lld", &n); k = n / 2; p = 1; for (; k < n - 1;) { p += (k + n) / 2 - k; for (ii = 0; ii < 2; ii++) { ...
19
#include <bits/stdc++.h> using namespace std; const int MAXN = 1005; int n, a[MAXN]; struct Node { int u, v, c; Node *next; } * h[MAXN], pool[MAXN << 1]; int tot = 0; inline void addEdge(int u, int v) { Node *p = &pool[++tot], *q = &pool[++tot]; p->v = v; p->c = 0; p->next = h[u]; h[u] = p; q->v = u; ...
19
#include <bits/stdc++.h> using namespace std; int main() { long long n, m; cin >> n >> m; long long row[123456], col[123456], r, c; r = n; c = n; while (m--) { long long a, b; cin >> a >> b; if (row[a] == 0) { r--; row[a] = 1; } if (col[b] == 0) { c--; col[b] = 1;...
4
#include <bits/stdc++.h> using namespace std; int n, m, x, y, z, k, w; int a, b, ans; struct node { int x, y, id; bool operator<(node const& T) const { if (T.x != x) return T.x > x; else return T.id < id; } } A[105], B[105], C[105]; bool cmp(const node& a, const node& b) { if (a.x != b.x) ...
14
#include <bits/stdc++.h> using namespace std; long long f(long long x) { if (x % 9 == 0) return 9; return x % 9; } int main() { long long n, ans = 0; long long num[15] = {0}; cin >> n; for (int i = 1; i <= n; ++i) { num[f(i)]++; } for (int i = 1; i <= 9; ++i) { for (int j = 1; j <= 9; ++j) { ...
12
#include <bits/stdc++.h> using namespace std; int main() { vector<string> s1, s2, s; int n; string k; cin >> n; s1.push_back("purple"); s2.push_back("Power"); s1.push_back("green"); s2.push_back("Time"); s1.push_back("blue"); s2.push_back("Space"); s1.push_back("orange"); s2.push_back("Soul"); ...
0
#include <bits/stdc++.h> using namespace std; const int N = 3010; int n; int mx1, mx2, mx3, c1, c2, c3; vector<pair<int, int> > a; int stab[N][14]; int borderval[N]; inline void updatevals(int x, int y, int z) { int xx = a[x].first - a[x + 1].first; int yy = a[y].first - a[y + 1].first; int zz = a[z].first - (z =...
15
#include <bits/stdc++.h> int M[16 + 10]; int R[16 + 10]; using namespace std; int main() { int n; int coa, cob; coa = cob = 0; cin >> n; for (int i = 0; i < n; i++) cin >> M[i]; for (int i = 0; i < n; i++) cin >> R[i]; for (int i = 1; i <= 100000; i++) { int xx = 0; for (int j = 0; j < n; j++) { ...
9
#include <bits/stdc++.h> using namespace std; const int N = 110; int n, m; char g[N][N]; struct cell { int x1, y1, x2, y2, x3, y3; }; void cal(char &c) { c = c == '1' ? '0' : '1'; } int main() { int T; cin >> T; while (T--) { vector<cell> v; cin >> n >> m; for (int i = 1; i <= n; i++) cin >> g[i] + ...
7
#include <bits/stdc++.h> using namespace std; map<string, int> ma; int a[1005], b[1005]; int c[5005][1005][2] = {0}; int main() { int n, m; cin >> n >> m; ma["?"] = n + 1; for (int i = 0; i < m; i++) { c[n + 1][i][0] = 0, c[n + 1][i][1] = 1; } for (int i = 1; i <= n; i++) { string s; cin >> s; ...
10
#include <bits/stdc++.h> int n, a[100000], b[100000], s[100000], id[100000], inv[100000]; void sort(int l, int r) { int i = l, j = r, p = s[(l + r) / 2], tmp; while (i <= j) { while (s[i] < p) ++i; while (p < s[j]) --j; if (i <= j) { tmp = s[i]; s[i] = s[j]; s[j] = tmp; tmp = id[...
16
#include <bits/stdc++.h> using namespace std; int n, L, data[200010]; int que[200010], g, h; long long sum[200010]; int ansL = -1, ansR = -1; void check(int l, int r) { if (ansL == -1 || sum[l] + sum[r] > sum[ansL] + sum[ansR] || sum[l] + sum[r] == sum[ansL] + sum[ansR] && l < ansL || sum[l] + sum[r] == s...
7
#include <bits/stdc++.h> using namespace std; inline int read() { int x = 0, f = 1; char ch = getchar(); for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1; for (; isdigit(ch); ch = getchar()) x = (x << 3) + (x << 1) + ch - '0'; return (f == 1) ? x : -x; } const int maxn = 100005; int n, sta[maxn]...
9
#include <bits/stdc++.h> using namespace std; string str; int main() { ios::sync_with_stdio(false); while (cin >> str) { int ans = 0, n = str.size(), l = 0; while (l < n) { for (int k = 0; k < 3; ++k) for (int i = l + k, sum = 0; i < n && i >= l; --i) { sum += str[i] - '0'; ...
7
#include <bits/stdc++.h> using namespace std; const int N = 1000 * 1000 + 100; vector<int> sdohiusdfh; int max_number; int border_dist; void check(int w, int h, int x, int y) { if (x < 0 || x >= w) return; if (y < 0 || y >= h) return; auto v = sdohiusdfh; for (int i = 0; i < w; ++i) { for (int j = 0; j < h;...
15
#include <bits/stdc++.h> using namespace std; const long long MD1 = (long long)1e9 + 7; const long long MD2 = (long long)1e9 + 9; long long n, MX; long long a[100 + 1], cnt[100 + 1]; set<long long> types; long long cnt_c[2][100 * 100 + 5][100 + 5]; long long nCr_memo[100 + 5][100 + 5][2]; long long nCr(long long a, lon...
13
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; int min(set<int>& s) { if (s.empty()) return numeric_limits<int>::max(); return *(s.begin()); } int max(set<int>& s) { if (s.empty()) return numeric_limits<int>::min(); return *prev(s.end()); } int main() { int n; scanf("%d", &n); set<...
13
#include <bits/stdc++.h> using namespace std; const int MaxN(200003); int tag[MaxN << 2], n, m; long long a[MaxN]; struct node_t { int a[11]; node_t operator+(node_t T) { node_t ans; for (int i = 0; i <= m; i++) ans.a[i] = a[T.a[i]]; return ans; } } seg[MaxN << 2][2], s[2]; inline void upd(int rt) { ...
22
#include <bits/stdc++.h> using namespace std; pair<int, int> operator+(pair<int, int> a, pair<int, int> b) { if (a.first > b.second || a.second < b.first) return a; return {max(a.first, b.first), min(a.second, b.second)}; } const int N = 100050; const int inf = 1e9 + 7; struct Color { int deg, cnt, cur, bal; ve...
27
#include <bits/stdc++.h> using namespace std; long long mod = 1000000007; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); pair<int, int> fib(int n) { if (n == 0) return {0, 1}; auto p = fib(n >> 1); int c = p.first * (2 * p.second - p.first); int d = p.first * p.first + p.second * p.second;...
7
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); long long int n, l, r; cin >> n >> l >> r; long long int a[n], p[n], b[n]; for (long long int i = 0; i < n; i++) cin >> a[i]; for (long long int i = 0; i < n; i++) cin >> p[i]; priority_queue<pair<long long int, p...
9
#include <bits/stdc++.h> using namespace std; const int N = 3e3 + 5; int dp[N][3]; int n; int a[N], b[N], c[N]; int solve(int idx, int p) { if (idx == n) { if (p) { return b[idx]; } else return a[idx]; } int &ret = dp[idx][p]; if (ret > -1) return ret; ret = 0; if (!p) { ret = max(re...
10
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); string s, s1, str1, str2; char a[2][2], b[2][2]; for (long long i = 0; i < 2; i++) for (long long j = 0; j < 2; j++) cin >> a[i][j]; for (long long i = 0; i < 2; i++) for (long long j = 0; j <...
4
#include <bits/stdc++.h> using namespace std; queue<int> que; int num[200]; int main() { int n, i; int sco = 0; cin >> n; for (i = 1; i <= n; i++) { cin >> num[i]; if (num[i] == sco + 1) { sco++; que.push(2000 + i); } } cout << sco << endl; while (!que.empty()) { cout << que.fr...
5
#include <bits/stdc++.h> using namespace std; long long n, A, R, M; vector<long long> v; long long ans(long long h) { long long cntu = 0, cntd = 0; for (long long i = 0; i < n; i++) { if (v[i] < h) { cntu += h - v[i]; } else { cntd += v[i] - h; } } if (M > A + R) { return A * cntu + ...
13
#include <bits/stdc++.h> using namespace std; struct node { int x, y; char c; }; int N, Q, aux, Ncoord; int h[4000100]; int v[4000100]; int uh[4000100]; int uv[4000100]; node ops[200100]; set<int> coord; map<int, int> cMap; int cMapInv[4000100]; int mark[4000100]; void create_tree(int* tree, int* update, int pos, i...
14
#include <bits/stdc++.h> using namespace std; int n, p; int main() { cin >> n >> p; int ans = -1; for (int i = 1; i <= 30; i++) { int x = n - p * i; if (x <= 0) { break; } int ked = 0; if (x >= i) { while (x > 0) { ked += x % 2; x /= 2; } if (ked <= i) {...
8
#include <bits/stdc++.h> using namespace std; int n, a, b; vector<int> adj[100005]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; for (int i = (int)1; i <= (int)n - 1; i++) { cin >> a >> b; adj[a].push_back(b); adj[b].push_back(a); } for (int i = (int)1; i <= (i...
8
#include <bits/stdc++.h> using namespace std; const int maxn = 100000 + 5; int a[maxn]; int b[maxn]; int c[maxn]; int f[maxn]; int stk[maxn]; bool vis[maxn]; int main() { int n, m; scanf("%d%d", &n, &m); int l = n + 1, r = 0; for (int i = 1; i <= m; i++) { scanf("%d%d", &a[i], &b[i]); l = min(l, a[i]); ...
15
#include <bits/stdc++.h> using namespace std; const int MAXI = numeric_limits<int>::max() / 2; const int MINI = numeric_limits<int>::min() / 2; const long long MAXL = numeric_limits<long long>::max() / 2; const long long MINL = numeric_limits<long long>::min() / 2; static const int N = 1010; bool a[N][N]; int n, m, dx[...
3
#include <bits/stdc++.h> using namespace std; long long s[300000]; char str[300000]; struct node { char c; long long cnt; long long s; } tem; int get_hash(long long s) { if (s < 0) s *= -7; return s % 100007; } vector<struct node> vec[100007]; void insert(long long &s, char c) { int hash, len, i; hash = g...
10
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int t; cin >> t; while (t--) { int n, f = 1, s = 0; cin >> n; for (int i = 0; i < n; ++i) { int x; cin >> x; if (!s && x == 1 && i != n - 1) { f *= -1; } else s =...
3
#include <bits/stdc++.h> using namespace std; const int MAXN = 6 * 1e5; const int INF = 1e9 + 7; int n, k, f[MAXN][50]; string s; int L[500], R[500]; int i; int main() { ios::sync_with_stdio(false); cin >> n >> k; cin >> s; s = "+" + s; for (i = 1; i <= n; i++) { L[0] = INF; L[1] = f[i - 1][1]; fo...
8
#include <bits/stdc++.h> using namespace std; int n, m; int a[100005]; long long v[500005]; long long read() { long long x; cin >> x; return x; } int main() { int i, j; long long ans = 0; n = read(); m = read(); for (i = 1; i <= n; i++) { a[i] = read(); v[a[i]]++; } for (i = n; i > 0; i--) {...
7
#include <bits/stdc++.h> using namespace std; long long int max(long long int a, long long int b) { if (a > b) return a; else return b; } long long int min(long long int a, long long int b) { if (a < b) return a; else return b; } const int dx[4] = {-1, 1, 0, 0}; const int dy[4] = {0, 0, -1, 1}; ...
10
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n0, n1, n2; cin >> n0 >> n1 >> n2; bool z = false, t = false; if (n2 != 0) { for (int i = 0; i <= n2; i++) cout << "1"; t = true; } if (n0 != 0) { for (int i = 0; i <= n0; i++) c...
7
#include <bits/stdc++.h> using namespace std; int n; int x, ans[100]; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%1d", &x); if (x == 2) ans[++ans[0]] = 2; else if (x == 3) ans[++ans[0]] = 3; else if (x == 4) ans[++ans[0]] = 2, ans[++ans[0]] = 2, ans[++ans[0...
6
#include <bits/stdc++.h> using namespace std; const long double step = 1e-1, eps = 1e-3; const int maxn = 110; int n; bool bad; vector<pair<long double, long double>> ans; long double x, y, dx = 1, dy, co, si, nx, ny, lx, ly, ldx, ldy, z, w, len[maxn]; bool eq(long double a, long double b) { return abs(a - b) < eps; } ...
15
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<long long> vec(n); for (int i = 0; i < n; i++) { cin >> vec[i]; } string s; cin >> s; long long ans1, ans2, res; ans1 = ans2 = res = 0; vector<long long> fix(n, 0), prefix(n, 0), suffix(n, 0); for (int i = 0; i ...
6
#include <bits/stdc++.h> using namespace std; long long j, n, k, m, res, mn, mx, a[100005], x, i, r; int main() { cin >> n >> x; mn = 1999999999; for (i = 0; i < n; i++) { cin >> a[i]; if (mn >= a[i]) { if (mn > a[i]) { mn = a[i]; m = i; if (x - 1 > i) r = x - i - 1...
9
#include <bits/stdc++.h> using namespace std; int main() { long int q; cin >> q; while (q--) { int n; cin >> n; int minY = -100000, maxY = 100000, minX = -100000, maxX = 100000; for (int i = 0; i < n; i++) { int X, Y; cin >> X >> Y; int cur; cin >> cur; if (cur == 0) ...
7
#include <bits/stdc++.h> using namespace std; int p2(int n) { while (n & (n - 1)) n -= (-n & n); return n; } int main() { ios_base::sync_with_stdio(false); int n, b, p; cin >> n >> b >> p; int x = 0, y = n * p; while (n != 1) { int k = p2(n); x += k / 2 * (b * 2 + 1); n = n - k + k / 2; } ...
2
#include <bits/stdc++.h> int64_t n, k; int64_t f[11234], t[11234]; int64_t solve() { int64_t ans = -1e10; for (int i = 0; i < n; ++i) { if (t[i] > k) f[i] -= (t[i] - k); ans = std::max(ans, f[i]); } return ans; } int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); std::cout.tie(n...
1
#include <bits/stdc++.h> using namespace std; using ull = unsigned long long; using ll = long long; using ld = long double; const int mod = 1e9 + 7; const double pi = acos(-1.0); const int inf = INT_MAX; const int N = 1e5 + 5; int n, c, k, a[N], cur = 1; void mergesort(int l, int r, int k) { c++; if (l + 1 == r && ...
10
#include <bits/stdc++.h> using namespace std; const long long mod = 998244353; const long long maxn = 200000 + 5; long long n; long long a[maxn], b[maxn]; signed main() { cin.tie(0); cout.tie(0); cin >> n; for (long long i = 1; i <= n; i++) { cin >> a[i]; a[i] *= (n - i + 1) * i; } for (long long i ...
8
#include <bits/stdc++.h> using namespace std; const long long N = 55; long long n, m, b[55], num[30], sum[N]; long long take[N]; long long cc[N]; string s; char a[N]; void Input() { cin >> s >> m; memset(num, 0, sizeof num); memset(sum, 0, sizeof sum); memset(take, 0, sizeof take); for (long long i = 0; i < s...
10
#include <bits/stdc++.h> using namespace std; int n, m; char a[1010][55]; int cx[127]; int wro[1010]; int main() { scanf("%d%s%d", &n, a[0], &m); for (int i = 1; i <= m; i++) scanf("%s", a[i]); for (int i = 0; i < n; i++) cx[a[0][i]]++; int tmp = m; for (int i = 1; i <= m; i++) { for (int j = 0; j < n; j+...
7
#include <bits/stdc++.h> using namespace std; int main() { int n; long long ans = 0; cin >> n; for (int i = 9; i >= 0; i--) { long long num = (int)(pow(10, i) + 0.1); if (n / num) { ans += (n - num + 1) * (i + 1); n = num - 1; } } cout << ans << endl; return 0; }
4
#include <bits/stdc++.h> using namespace std; const int maxn = 200005; int add[maxn]; int section[maxn]; int main() { int n, k; cin >> n >> k; int a, fu = 0; for (int i = 0; i < n; i++) { cin >> a; if (a < 0) add[fu++] = i; } if (fu > k) { cout << -1 << endl; return 0; } if (fu == 0) { ...
10
#include <bits/stdc++.h> using namespace std; int n, m, ans; bool vis[300000]; vector<vector<int> > g1, g2; void dfs1(int u, map<int, int>& w) { vis[u] = true; int tmp = w.size(); w[u] = tmp; for (int i = 0; i < g1[u].size(); i++) { if (!vis[g1[u][i]]) { dfs1(g1[u][i], w); } } } bool dfs2(int u,...
14
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize("O2") long long dpL[1000001], dpR[1000001], one[1000001], two[1000001], ans; long long n, r1, r2, r3, d, a[1000001]; int main() { ios_base::sync_with_stdio(false), cin.tie(0); cin >> n >> r1 >> r2 >> r3 >> d; for (long long i = (1); i < (n + 1); i...
15
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; int h[n]; for (int i = 0; i < n; i++) cin >> h[i]; long long sum[n]; sum[0] = h[0]; for (int i = 1; i < n; i++) sum[i] = sum[i - 1] + h[i]; long long minSum = sum[k - 1]; int p = 1; for (int i = k; i < n; i++) { ...
3
#include <bits/stdc++.h> using namespace std; using namespace rel_ops; const double PI = acos((double)-1); int ts, ts2, ts3, ts4; int n, m; long long gcd(long long x, long long y) { long long t; for (; y != 0;) { t = x % y; x = y; y = t; } return x; } enum Stt { mul, add, ok, sus }; map<string, Stt>...
18
#include <bits/stdc++.h> using namespace std; vector<int> grp[100002]; int main() { int n, k, i, j, a[100002], flag = 0; scanf("%d%d", &n, &k); ; for (i = 0; i < n; i++) { string s; cin >> s; if (s[0] == '?') a[i] = INT_MIN; else { int sign = 1, l = s.size(); a[i] = 0, j = 0; ...
14
#include <bits/stdc++.h> using namespace std; long long cnt[2][6]; void slv() { int n, m; cin >> n >> m; for (int i = 1; i <= n; i++) cnt[0][i % 5]++; for (int i = 1; i <= m; i++) cnt[1][i % 5]++; long long sum = 0; for (int i = 0; i < 5; i++) { for (int j = 0; j < 5; j++) { if ((i + j) % 5 == 0) ...
3
#include <bits/stdc++.h> using namespace std; auto scan = [] { static long long a; scanf("%lld", &a); return a; }; pair<long long, pair<long long, long long> > broke[500 * 500]; long long board[500][500], n, m, k, q, x, y, t; void printboard(long long n, long long m) { for (int i = 0; i < n; ++i) for (int j...
11
#include <bits/stdc++.h> using namespace std; pair<int, int> a[3]; int main() { for (int i = 0; i < 3; i++) scanf("%d%d", &a[i].first, &a[i].second); sort(a, a + 3); int mid = a[1].first; int mx = max({a[0].second, a[1].second, a[2].second}); int mn = min({a[0].second, a[1].second, a[2].second}); vector<pai...
8
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long int n, t; cin >> n >> t; if (n == 1) cout << 0 << "\n"; else { if (t >= n / 2) cout << n * (n - 1) / 2; else cout << (n) * (n - 1) / 2 - (n - 2 * t)...
4
#include <bits/stdc++.h> using namespace std; const long long INF = 1e9; long long MOD = 1e9 + 7; int n; double a[22][22]; int f; double dp[(1 << 18) + 5]; int main() { cin >> n; for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) cin >> a[i][j]; dp[0] = 1; for (int i = 0; i < (1 << n); i++) { int s...
11
#include <bits/stdc++.h> using namespace std; void dfs(int x, vector<vector<int> > &v, vector<bool> &b, vector<int> &res) { b[x] = 0; for (int i = 0; i < v[x].size(); ++i) { if (b[v[x][i]]) { dfs(v[x][i], v, b, res); } } res.push_back(x); } int main() { cin.tie(NULL); ios_base::sync_with_stdio...
12
#include <bits/stdc++.h> using namespace std; mt19937 rng(time(0)); uniform_int_distribution<int> uid(-1e9, 1e9); vector<vector<int>> g[300008], t[300008]; int t1[300008], t2[300008], T, u[300008]; set<pair<int, int>> st; void dfs(int x, int px) { t1[x] = t2[x] = T++, u[x] = 1; for (auto& i : g[x]) if (i[0] != ...
15
#include <bits/stdc++.h> using namespace std; unsigned long long gcd(unsigned long long a, unsigned long long b) { if (b == 0) return a; return gcd(b, a % b); } bool fail; unsigned long long mult(unsigned long long x, unsigned long long gc, unsigned long long limit) { vector<unsigned long ...
10
#include <bits/stdc++.h> using namespace std; vector<int> z; int n, k; int valid(int x) { int i = 0, j = n - 1, s = 0; while (j >= i) { if (z[i] + z[j] <= x) { i++, j--; } else { j--; } s++; } return s; } int func(int l, int r) { if (l >= r) { return l; } int x = l + r; x...
6
#include <bits/stdc++.h> using namespace std; int n, m; int a[111][111]; int x[111], y[111]; int main() { scanf("%d%d", &n, &m); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { scanf("%d", &a[i][j]); } } while (1) { for (int i = 0; i < n; i++) { int sum = 0; for (int j ...
13
#include <bits/stdc++.h> int inf = 1e9 + 7; using namespace std; long long n, k, d1, d2; long long a[4]; int judge() { long long r = n - k, sum = 0; sort(a, a + 3); if (a[0] < 0) { long long ad = -a[0]; for (int i = 0; i < (3); i++) a[i] += ad; } for (int i = 0; i < (3); i++) sum += a[i]; if (sum > ...
9
#include <bits/stdc++.h> using namespace std; int n; int pos[210000]; double minim, maxim; double ansmid; bool check(double mid) { int left = 0, right = 0; for (int i = 0; i < n; ++i) { if (minim + mid * 2 >= (double)pos[i]) { left++; } else break; } for (int i = n - 1; i >= 0; --i) { if...
10
#include <bits/stdc++.h> const int N = 310000; const long long INF = 0x7fffffffff; inline long long Max(long long a, long long b) { return a > b ? a : b; } int n, u, v, w; int val[N]; long long ans[N], aans = -INF; struct edge { int next, to, val; } e[N << 1]; int ehead[N], ecnt; inline void add_edge(int now, int to,...
10
#include <bits/stdc++.h> using namespace std; template <typename Arg1> void ZZ(const char* name, Arg1&& arg1) { std::cerr << name << " = " << arg1 << endl; } template <typename Arg1, typename... Args> void ZZ(const char* names, Arg1&& arg1, Args&&... args) { const char* comma = strchr(names + 1, ','); std::cerr.w...
0
#include <bits/stdc++.h> using namespace std; using ll = long long int; const int mx = 1e5 + 10; int ar[mx], as[mx], des[mx]; int n, m; int main() { while (cin >> n >> m) { for (int i = 0; i < n; i++) cin >> ar[i]; int mk = 0; des[0] = 0; for (int i = 1; i < n; i++) { if (ar[i - 1] >= ar[i]) { ...
9
#include <bits/stdc++.h> using namespace std; const long long int inf = 1000000000; const long long int mod = 1000000000 + 7; inline void IO() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } inline int dcmp(long double x) { return x < -1e-12 ? -1 : (x > 1e-12); } template <class T> inline int CHECK(T M...
13
#include <bits/stdc++.h> using namespace std; long long int n, k, i, j, u = 0; string s; long long int a[26]; char c; int main() { cin >> n >> k; cin >> s; for (i = 0; i < n; i++) a[s[i] - 'a'] = 1; if (k > n) { cout << s; for (i = 0; i < 26; i++) { if (a[i] != 0) break; } for (j = n; j < ...
7
#include <bits/stdc++.h> using namespace std; const long long inf = 1e10 + 7; const long double eb = 1e-9; const long long mod = 1e9 + 7; template <class T> T add(T v1, T v2, long long mo = mod) { return (v1 % mo + v2 % mo) % mo; } template <class T> T subtract(T v1, T v2, long long mo = mod) { return (v1 % mo - v2...
9
#include <bits/stdc++.h> using namespace std; int main() { int n, a, b; cin >> n >> a >> b; cin.ignore(); string s; cin >> s; if (a > b) swap(a, b); if (s[a - 1] == s[b - 1]) printf("0"); else printf("1"); return 0; }
4
#include<bits/stdc++.h> using namespace std; typedef long long int ll; typedef long double ld; typedef vector<int> vi; typedef vector<vi > vvi; typedef vector<ll> vl; typedef vector<vl> vvl; typedef pair<int,int> pr; typedef unordered_set<int> st; typedef unordered_map<int,int> mp; typedef unordered_map<int,vi> mpv; ...
6
#include <bits/stdc++.h> using namespace std; int main() { long long n, k; cin >> n >> k; long long ans = 0; long long cur = 0; for (int i = 0; i < n; i++) { long long x; cin >> x; cur += x; k -= min(8ll, cur); cur -= min(8ll, cur); ans++; if (k <= 0) { cout << ans; ret...
1
#include <bits/stdc++.h> using namespace std; const int LOG = 22; const int NN = (int)20 + 5; const int MOD = (int)1e9 + 7; const long long INF = (int)1e9 + 7; int n, m; vector<vector<int> > A; vector<vector<int> > B; int can(vector<int>& a, vector<int>& b) { int c = 0, common; for (int i = 0; i < 2; i++) for (...
11
#include <bits/stdc++.h> using namespace std; vector<int> V; vector<int>::iterator it; char s[100005]; int f[100005]; int main() { int i, j, l; while (scanf("%s", s) != EOF) { l = strlen(s); memset(f, -1, sizeof f); for (i = 0; i < l; i++) { if (s[i] == '(' || s[i] == '[') { V.push_back(i)...
9
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { long long int x; cin >> x; cout << "1" << " " << x - 1 << endl; } }
0
#include <bits/stdc++.h> using namespace std; long long arr[300009], n; bool check(int k) { for (long long i = 0; i < n; i++) { if (k * abs(i - 0) > min(arr[i], arr[0])) return 0; if (k * abs(i - n + 1) > min(arr[i], arr[n - 1])) return 0; } return 1; } int main() { cin >> n; for (long long i = 0; i <...
5
#include <bits/stdc++.h> using namespace std; void dfs(vector<vector<int>> &edges, int color[], int node, int cur_color) { color[node] = cur_color; for (int i : edges[node]) { if (color[i] == -1) dfs(edges, color, i, cur_color); } } int main() { long long n, k; cin >> n >> k; vector<vector<int>> edges(n...
9
#include <bits/stdc++.h> using namespace std; const int N = 4010; const int INF = int(1e9) + 10; int d[N][N], r[N], MIN = INF, used[N], n; vector<int> t[N]; int main() { int u, v, m; cin >> n >> m; for (int i = 1; i <= m; ++i) { cin >> u >> v; d[v][u] = 1; d[u][v] = 1; r[u]++; r[v]++; t[u]...
7
#include <bits/stdc++.h> using namespace std; const int e9 = 1000 * 1000 * 1000; const long long e18 = (long long)e9 * (long long)e9; const double pi = 3.1415926535; void pV(int num) { cout << num << " "; } int ri() { int x; scanf("%d", &x); return x; } double rd() { double x; scanf("%lf", &x); return x; } ...
12
#include <bits/stdc++.h> using namespace std; constexpr int N = 3e3 + 1; uint16_t a[N], nxt[N]; uint16_t dp[N][N]; int main() { cin.tie(0), ios::sync_with_stdio(0); int t, n; cin >> t; while (t--) { cin >> n; for (int i = 0; i < n; ++i) { cin >> a[i], --a[i]; } n = unique(a, a + n) - a; ...
19
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, i; cin >> n; if (n % 2 == 0) { for (i = 0; i < n / 2; i++) cout << "1"; } else { cout << "7"; for (i = 0; i < n / 2 - 1; i++) cout << "1"; } cout << "\n"; return 0; }
4
#include <bits/stdc++.h> using namespace std; int x[105][105]; int main() { int n, k, t; cin >> n >> k >> t; int i; for (i = 0; i < k; i++) { int a, b, w; cin >> a >> b >> w; a--; b--; x[a][b] = w; } int tot = 1; for (i = 0; i < n; i++) tot *= n + 1; vector<int> v; for (i = 0; i < ...
10
#include <bits/stdc++.h> using namespace std; const long long mod1 = 19260817; const long long mod2 = 19660813; long long n; long long a[15]; long long b[15]; void init() { a[1] = 9LL; for (long long i = 2; i <= 12; ++i) a[i] = a[i - 1] * 10LL + 9LL; b[1] = 10LL; for (long long i = 2; i <= 12; ++i) b[i] = b[i -...
10
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1.0); const double eps = 1e-11; template <class T> inline void checkmin(T &a, T b) { if (b < a) a = b; } template <class T> inline void checkmax(T &a, T b) { if (b > a) a = b; } template <class T> inline T sqr(T x) { return x * x; } const int m...
10
#include <bits/stdc++.h> using namespace std; int main() { int n; while (scanf("%d", &n) != EOF) { int m = sqrt(n); if (m * m == n) { printf("%d\n", 4 * m); } else { int more = n - m * m; if (more <= m) { printf("%d\n", 4 * m + 2); } else printf("%d\n", 4 * m + 4)...
2
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10, size = 1 << 20, mod = 998244353, inf = 2e9; template <class o> void qr(o& x) { char c = getchar(); x = 0; int f = 1; while (!isdigit(c)) { if (c == '-') f = -1; c = getchar(); } while (isdigit(c)) x = x * 10 + c - '0', c = getchar...
27
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; int n, ca[N], cb[N], u[N], v[N], i, j, z, S, T, deg[N], id[N], X; long long ans; vector<int> e[N], ep; multiset<int> SS; bool b1[N]; int dad[N], dep[N]; void dfs(int x, int fa) { dep[x] = dep[fa] + 1; dad[x] = fa; for (int y : e[x]) if (y !=...
26
#include <bits/stdc++.h> using namespace std; int main() { vector<char> v; char ch; do { ch = getchar(); if (ch >= 'a' && ch <= 'z') { v.push_back(ch); } } while (ch != '\n'); sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end()); cout << v.size(); return 0; }
0
#include <bits/stdc++.h> using namespace std; int main(int argc, char** argv) { int a[100000] = { 0, }; int n, k, res, sum = 0, p, s = 0; cin >> n >> k; for (int i = 0; i < n; i++) { sum = 2 * k; if (i - k < 0) sum -= abs(i - k); if (i + k >= n) sum -= (i + k - (n - 1)); cin >> p; if...
6
#include <bits/stdc++.h> using namespace std; int max(int x, int y) { return x > y ? x : y; } int min(int x, int y) { return x < y ? x : y; } void swap(int &x, int &y) { int t; t = x, x = y, y = t; } struct po { double x, y; void fuck(double tx, double ty) { x = tx, y = ty; } } a[5]; double dx, dy; void init() ...
15
#include <bits/stdc++.h> using namespace std; long long n, r[50005][6]; int main() { long long t; cin >> t; while (t--) { cin >> n; for (long long i = 0; i < n; i++) { for (long long j = 0; j < 5; j++) { cin >> r[i][j]; } } long long ans = 0, x; for (long long i = 1; i < n;...
7
#include <bits/stdc++.h> using namespace std; int n, m; int main() { cin >> n >> m; if (m <= n / 2) cout << max(1, m) << endl; else cout << n - m << endl; return 0; }
1