solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> using namespace std; struct event { int type; int where; bool operator<(const event that) const { return where < that.where; } }; int n, k; vector<event> lis; long long F[200001]; long long invF[200001]; long long mod = 1000000007LL; long long power(long long a, long long b) { long long...
12
#include <bits/stdc++.h> using namespace std; struct fast_ios { fast_ios() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_; template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &x : v) is >> x; return is; } template <typename T...
13
#include <bits/stdc++.h> using namespace std; char str[105]; int main() { int n, d; scanf("%d%d", &n, &d); int tmp = 0, ans = 0; for (int it = 0; it < d; it++) { scanf("%s", str); bool ok = 0; for (int i = 0; i < n; i++) { if (str[i] == '0') ok = 1; } if (ok) tmp++; else ...
0
#include <bits/stdc++.h> using namespace std; const long long inf = 2e18; int n, m, l, t; long long ma[10], ta[30], tca[30]; pair<long long, long long> tt[30]; long long dist[30][1 << 8][1 << 8]; vector<int> cs; void getDist() { for (int i = 0; i < 1 << m; i++) { int c = 0; for (int j = 0; j < m; j++) i...
21
#include <bits/stdc++.h> using namespace std; long long int powe(long long int x, long long int y, long long int m) { if (y == 0) return 1; long long int p = powe(x, y / 2, m) % m; p = (p * p) % m; return (y % 2 == 0) ? p : (x * p) % m; } int gcd(int a, int b) { if (a == 0) return b; return (b % a, a); } in...
4
#include <bits/stdc++.h> using namespace std; const int N = 11000, M = 4e7 + 100; int n, m, st[100][100], a[N]; char s[N], t[N], as[N], at[N]; int day[13] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; queue<int> q; inline int read() { int f = 1, x = 0; char s = getchar(); while (s < '0' || s > '9') { ...
12
#include <bits/stdc++.h> using namespace std; using ll = long long int; using dl = double; const int N = 2e5 + 10; ll aarray[200000 + 10]; ll magic[101][101]; vector<ll> primes; bool prime[1000001]; int main() { ios_base::sync_with_stdio(false); string str; ll i, j, n, m, k; cin >> n; ll sum = 0; multiset<l...
4
#include <bits/stdc++.h> using namespace std; int N; string s; int main() { scanf("%d\n", &N); cin >> s; if (N == 1) { cout << 1 << endl; return 0; } if (N == 2) { cout << 2 << endl; return 0; } int ans = 1; for (int i = 1; i < N; i++) if (s[i] != s[i - 1]) ans++; if (ans == N) { ...
8
#include <bits/stdc++.h> using namespace std; const int maxn = 2e4 + 7; int res[maxn], t[2]; struct node { int x, y, c, id; double sn; node(int x = 0, int y = 0, int c = 0, int id = 0) { this->x = x, this->y = y, this->c = c, this->id = id; } inline friend bool operator<(const node &a, const node &b) { ...
19
#include <bits/stdc++.h> using namespace std; int n, color; int cnt[105]; int dp[105][10005]; int main() { cin >> n; for (int i = 1; i <= n; i++) { int x; cin >> x; color += !cnt[x]; cnt[x]++; } if (color <= 2) return cout << n, 0; dp[0][0] = 1; for (int i = 1; i <= 100; i++) { for (int ...
13
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; int a[n + 1]; fill(a, a + n + 1, 0); priority_queue<pair<int, int>> q; priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> temp;...
8
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); long long k, l, r; cin >> k >> l >> r; long long u = ((long long)1e18 / k + 1) * k; l += u; r += u; cout << r / k - (l - 1) / k; return 0; }
8
#include <bits/stdc++.h> using namespace std; int main() { long long clock[3]; for (int i = 0; i < 3; i++) cin >> clock[i]; clock[0] *= 50000; clock[1] *= 100; long long t1, t2; cin >> t1 >> t2; if (t1 > t2) { long long zhan = t1; t1 = t2; t2 = zhan; } t1 *= 50000; t2 *= 50000; int fla...
6
#include <bits/stdc++.h> using namespace std; const int MAXN = 99999; const int INF = (1 << 30); const double PI = acos(-1.0); const double EPS = 1e-11; int n, m, atk[105], def[105], c[105]; int size_atk, size_def; int input() { int i; string s; cin >> n >> m; size_atk = size_def = 0; for (i = 0; i < n; i++) ...
11
#include <bits/stdc++.h> using namespace std; int son[500][26][26]; int memo[500][26][26]; int cambios[500][26][26]; char A[500][500]; int m, n; void solve(int x, int y, int z) { for (int row = 0; row < x; row++) for (int a = 0; a < y; a++) for (int b = 0; b < z; b++) { int &aux = son[row][a][b]; ...
12
#include <bits/stdc++.h> char s[20], t[20]; int main() { int n; scanf("%s", s); n = strlen(s); for (int i = 0; i <= n; i++) { int j; for (j = 0; j < i; j++) { t[j] = s[j]; } for (j = i; j < n; j++) { t[j + 1] = s[j]; } t[i] = t[n - i]; for (j = 0; j <= n; j++) { if ...
22
#include <bits/stdc++.h> using namespace std; const int N = 505; int source, sink, n, residual[N][N], f, parent[N]; void augment(int u, int flow) { if (u == source) { f = flow; } else if (parent[u] != -1) { augment(parent[u], min(flow, residual[parent[u]][u])); residual[parent[u]][u] -= f; residual[...
15
#include <bits/stdc++.h> using namespace std; int cal(double v, int k) { int cnt = 0; while (v > 0) { cnt += (int)v; v /= k; } return cnt; } int bs(int l, int r, int n, int k) { int middle = (l + r) / 2; if (cal(middle, k) >= n) { if (cal(middle - 1, k) < n) return middle; else r...
7
#include <bits/stdc++.h> using namespace std; long long MOD = 1000000007; const int MAXX = 100000; int max(int a, int b) { if (a > b) return a; return b; } int min(int a, int b) { if (a < b) return a; return b; } struct point { int x, y; long long d2; double tan2; bool operator==(const point& p) const {...
20
#include <bits/stdc++.h> #define all(i) (i).begin(), (i).end() #define debug(x) cerr << "Line(" << __LINE__ << ") -> " << #x << " is " << x << endl using namespace std; template<typename T1, typename T2> ostream& operator << (ostream &i, pair<T1, T2> j) { return i << j.first << ' ' << j.second; } template<typename ...
19
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; int ans = (s.size() + 1) * 26, t = 1; for (int i = 1; i < s.size(); i++) { if (s[i] == s[i - 1]) { t++; } else { ans -= t; t = 1; } } ans -= t; cout << ans; }
1
#include <bits/stdc++.h> using namespace std; int n, cnt; struct node { int x, y; } a[8000009]; struct hsh { int tot, fst[20000003], pnt[8000009], len[8000009], nxt[8000009]; void ins(int x, int y) { int z = x % 20000003; pnt[++tot] = x; len[tot] = y; nxt[tot] = fst[z]; fst[z] = tot; } int...
14
#include <bits/stdc++.h> #pragma ide diagnostic ignored "OCUnusedGlobalDeclarationInspection" #pragma ide diagnostic ignored "OCUnusedMacroInspection" using namespace std; #define itn int #define sqr(a) ((a)*(a)) #define cub(a) ((a)*(a)*(a)) #define forn(i, n) for(int i = 0; i < (int)n; ++i) #define rep(i, k, n) for(...
8
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize("O3") const int mod = (1e9) + 7; const double eps = 1e-10; const int siz = 1e5 + 5, siz2 = 18, siz3 = 5032108; int n, k, deg[siz], del[siz]; vector<int> adj[siz], temp; queue<int> cur; bool vis[siz]; int main() { scanf("%d%d", &n, &k); for (int i = ...
10
#include <bits/stdc++.h> using namespace std; template <typename T, typename S> inline bool REMIN(T& a, const S& b) { return a > b ? a = b, 1 : 0; } template <typename T, typename S> inline bool REMAX(T& a, const S& b) { return a < b ? a = b, 1 : 0; } int bit(long long x, int pos) { return (x >> pos) & 1; } long lo...
7
#include <bits/stdc++.h> using namespace std; int pos[100005], a[100005], b[100005], n; multiset<int> s; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d", &a[i]); for (int i = 1; i <= n; i++) pos[a[i]] = i; for (int i = 1; i <= n; i++) scanf("%d", &b[i]); for (int i = 1; i <= n; i++) s.in...
13
#include <bits/stdc++.h> using namespace std; int main() { char a[4][4]; for (int i = 1; i <= 3; i++) { for (int j = 1; j <= 3; j++) { cin >> a[i][j]; } } if (a[1][1] == a[3][3] && a[1][2] == a[3][2] && a[1][3] == a[3][1] && a[2][1] == a[2][3]) { cout << "YES"; } else { cout << "NO...
0
#include <cstdio> #include <vector> #include <iostream> #include <algorithm> using namespace std; const int Maxn=100000; vector<int> e[Maxn+5]; vector<int> level[Maxn+5]; vector<int> cnt[Maxn+5]; int dep[Maxn+5]; int depd[755],depc[755],tot; int mdep; bool f[755][Maxn+5]; int ccnt[Maxn+5]; int maxn[Maxn+5]; bool cmp(ve...
23
#include <bits/stdc++.h> using namespace std; vector<bool> done; vector<int> par, dep; vector<vector<int> > bs, es; void dfs(int u, int p, int d) { done[u] = true; dep[u] = d; par[u] = p; for (const auto& v : es[u]) { if (v == p) continue; if (done[v]) bs[u].push_back(v); else dfs(v, u, ...
19
#include <bits/stdc++.h> using namespace std; int n, c[210], p[210], d[210]; bool b[210], a[210][210]; int find(int k) { for (int i = 1; i <= n; i++) if (c[i] == k) if (d[i] == 0 && b[i]) return i; return n + 1; } int calc(int k) { memset(b, true, sizeof(b)); for (int i = 1; i <= n; i++) d[i] = p[i]; ...
9
#include <bits/stdc++.h> #pragma GCC optimize("O3", "unroll-loops") #pragma GCC target("avx2") using namespace std; template <class T, class U> inline void checkmin(T &x, U y) { if (y < x) x = y; } template <class T, class U> inline void checkmax(T &x, U y) { if (y > x) x = y; } template <class T, class U> inline b...
2
#include <bits/stdc++.h> using namespace std; const int N = 300010; queue<pair<pair<int, int>, int> > Q; struct recc { int a, b, c, d, e; }; int n; int f[N], g[N]; pair<int, int> t[N * 4]; recc a[N]; void print(int n) { if (f[n] != 0) print(g[n]); printf("%d ", a[n].e); } void build(int i, int l, int r) { int m...
17
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (--t >= 0) { int n, i = 0, se = 0, so = 0; cin >> n; int a[n]; if ((n / 2) % 2 != 0) { cout << "NO" << endl; continue; } cout << "YES" << endl; while (i < n) { if (i < n / 2) { a...
0
#include <bits/stdc++.h> using namespace std; struct point { int x, y; }; int n; int p[8] = {1, 0, -1, 0, 1, 1, -1, -1}; int q[8] = {0, 1, 0, -1, 1, -1, 1, -1}; bool is_check(point K, point Q) { return Q.x == K.x || Q.y == K.y || abs(Q.x - K.x) == abs(Q.y - K.y); } bool vis[1005][1005]; point Q; bool bfs(point K, p...
2
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const long long int llINF = (long long)(1e18) + 100; const int MAXN = 3e2 + 10; const int MAXM = 9e4; int ned, first[MAXN], work[MAXN], dist[MAXN], q[MAXN]; int cap[MAXM], to[MAXM], nxt[MAXM]; void init() { memset(first, -1, sizeof first); ne...
21
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 100; int n, m; vector<pair<int, int>> g[N]; int U[N], V[N], W[N]; int top[N]; bool can(int MAX) { vector<int> in(n + 1); vector<vector<int>> g(n + 1); for (int i = 0; i < m; i++) { if (W[i] <= MAX) { continue; } g[U[i]].push_back(...
14
#include <bits/stdc++.h> using namespace std; map<int, vector<int> > m; set<int> ss; void dfs(int s) { cout << s << ' '; ss.insert(s); for (typeof((m[s]).begin()) it = (m[s]).begin(); it != (m[s]).end(); ++it) if (!((ss).find(*it) != (ss).end())) dfs(*it); } int main() { ios_base::sync_with_stdio(false); ...
9
#include <bits/stdc++.h> using namespace std; int main() { string a, b; cin >> a >> b; int len1 = a.length(); int len2 = b.length(); int count1 = 0; for (int i = 0; i < len1; ++i) { if ((i + len2) > len1) break; string s1 = a.substr(i, len2); if (s1 == b) { count1++; i = (i + len2 - ...
4
#include <bits/stdc++.h> using namespace std; double a, b, l; double calc(double x) { double y = sqrt(l * l - x * x); return (b / x + a / y - 1) / sqrt(1 / x / x + 1 / y / y); } int main() { scanf("%lf%lf%lf", &a, &b, &l); if (a > b) swap(a, b); if (l <= a) { printf("%.8f\n", l); return false; } i...
17
#include <bits/stdc++.h> using namespace std; int main() { int r, g, b; cin >> r >> g >> b; r = (r / 2) + (!(!(r % 2))); g = (g / 2) + (!(!(g % 2))); b = (b / 2) + (!(!(b % 2))); cout << 30 + max((r - 1) * 3, max((g - 1) * 3 + 1, (b - 1) * 3 + 2)) << endl; }
2
#include <bits/stdc++.h> using namespace std; const int N = 205; int n, t, k; long long a[N], b[N], c[N], sa[N], sb[N]; long long f0[N][N], g0[N][N], f[N][N], g[N][N]; int main() { cin >> n >> t >> k; for (int i = 1; i <= n; i++) cin >> a[i] >> b[i] >> c[i]; n++, a[n] = b[n] = k, c[n] = 1ll << 60; for (int i = ...
26
#include <bits/stdc++.h> using namespace std; int main() { long long n, ans = 0, mul = 1; cin >> n; while (n % mul == 0) { ans++; mul *= 3; } cout << n / mul + 1; return 0; }
8
#include <bits/stdc++.h> using namespace std; int main() { int n, x; cin >> n >> x; int i, j, a, b; int arr[1005] = {0}; for (i = 0; i < n; i++) { cin >> a >> b; if (a > b) { int t = a; a = b; b = t; } for (j = a; j <= b; j++) { arr[j]++; } } int st = -1, end = ...
2
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10; int a[maxn], b[maxn]; int c[maxn]; signed main() { int n; scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d", &a[i]); for (int i = 1; i <= n; i++) scanf("%d", &b[i]); for (int i = 1; i <= n; i++) { c[a[i]] = b[i]; } for (in...
4
#include <bits/stdc++.h> using namespace std; const int maxm = 210; int T, now; char str[maxm], c[100], *key = c + 50; bool flag = true; set<char> s; bool null(int x) { return key[x] == '\0'; } int check(char ch, int pos) { if (key[pos - 1] == ch) return -1; else if (key[pos + 1] == ch) return 1; return 0...
8
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; if (n == 0) { cout << 1 << '\n'; return 0; } if (n == 1) { cout << 8 << '\n'; } else if (n == 2) cout << 4 << '\n'; else if (n == 3) cout << 2 << '\n'; else if (n ...
2
#include <bits/stdc++.h> using namespace std; const int MAX = 500007, N = 1e6 + 7; int main() { long long int n, help = 1; cin >> n; for (int i = 1; i <= (n / 2); i++) cout << i << " " << n + 1 - i << " "; if (n % 2) { cout << (n + 1) / 2; } cout << "\n"; return 0; }
4
#include <bits/stdc++.h> #pragma GCC optimize(2) #pragma G++ optimize(2) using namespace std; struct my_deque { int head, tail; int t0, t1; pair<long long, int> dat[1010]; void dq_init() { head = tail = 0; t0 = t1 = 0; memset(dat, 0x3f, sizeof(dat)); } void dq_push(int key) { while (tail >= ...
17
#include <bits/stdc++.h> using namespace std; inline void read(int& x) { x = 0; char c = getchar(); while (c < '0' || c > '9') c = getchar(); while (c >= '0' && c <= '9') { x = (x << 3) + (x << 1) + (c ^ 48); c = getchar(); } } struct edge { int u, v, w; inline edge(int u = 0, int v = 0, int w = 0...
16
#include <bits/stdc++.h> using namespace std; const int maxn = 200002; long long po(long long a, long long b) { return !b ? 1 : po(a * a % 1000000007ll, b / 2) * (b & 1 ? a : 1) % 1000000007ll; } long long inv(long long b) { return po(b, 1000000007ll - 2); } long long dp[maxn], d[maxn]; long long a[maxn],...
8
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, k; cin >> n >> k; std::vector<int> v(n); for (int i = 0; i < n; ++i) { cin >> v[i]; } int left = -1; for (int i = 0; i < n; ++i) { if (v[i] > k) break; else left++...
0
#include <bits/stdc++.h> using namespace std; int read() { int t; scanf("%d", &t); return t; } int n; struct wangluoliu { int head[40010], last[800000], val[800000], v[800000], p = 1; int dep[40010], cur[40010]; void add(int a, int b, int c) { v[++p] = b; last[p] = head[a]; head[a] = p; val[...
25
#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...
7
#include <bits/stdc++.h> using namespace std; const int rx[] = {0, -1, 0, 1, -1, 1, 1, -1}; const int cy[] = {1, 0, -1, 0, 1, 1, -1, -1}; double a, d; int n; int chk(double x, double y) { if ((x >= 0 && x <= a) && (y == 0)) return 1; else if ((x == a) && (y >= 0 && y <= a)) return 2; else if ((x >= 0 && x...
7
#include <bits/stdc++.h> using namespace std; struct T { int i, v; T(int i = 0, int v = 0) : i(i), v(v) {} }; bool operator<(T a, T b) { return a.v > b.v; } int l, n, u[10010], w[10010], p[10010], a[2 * 100010], c[2 * 100010], e[2 * 100010]; vector<int> m[10010]; priority_queue<T> q; void push(int i, int v, int...
16
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int A[n + 1]; for (int i = 1; i <= n; i++) { cin >> A[i]; } int mi = 1; int ma = n; int posmin, posmax, posmin1, posmax1; for (int i = 1; i <= n; i++) { if (mi == A[i]) { posmin = i; } if (ma == A[i]) { ...
0
#include <bits/stdc++.h> using namespace std; const int INFint = 2147483547; const long long INF = 9223372036854775807ll; const long long MOD = 1000000007ll; const long double EPS = 1e-13; int main() { ios_base::sync_with_stdio(0); int n, b; cin >> n >> b; vector<pair<int, int> > qrs(n); for (int i = 0; i < n...
9
#include <bits/stdc++.h> using namespace std; const int N = 2003; char a[N][N]; vector<pair<int, int> > q; pair<int, int> tmp; int n, m; inline bool f(int x, int y) { int res = 0; if (a[x][y] != '.') return false; if (a[x + 1][y] == '.') res++; if (a[x - 1][y] == '.') res++; if (a[x][y - 1] == '.') res++; i...
12
#include <bits/stdc++.h> using namespace std; string line; bool getLine() { line = ""; char c; read: if (scanf("%c", &c) == EOF) { return false; } if (c == 10 || c == 13) return true; line += c; goto read; } int main() { vector<string> v; int maxt = 0, cur, left, right; char isleft = true; whi...
4
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; const int N = 1e5 + 5; const long long inf = 1e18; char s[N]; int i, j, aux[200]; int main() { scanf("%s", s); int len = strlen(s); int index = 123; for (i = 0; i < len; i++) aux[s[i]] = i; for (i = 122; i >= 97; i--) { for (j = aux[in...
3
#include <bits/stdc++.h> using namespace std; int mod = 1e9 + 7; void solve() { int n, m; cin >> n >> m; long long a[m + 1][n + 1], b[m + 1][n + 1]; for (int i = 1; i <= n; i++) { a[1][i] = 1; b[1][i] = n - i + 1; } for (int i = 2; i <= m; i++) { long long sum = 0; for (int j = 1; j <= n; j+...
8
#include <bits/stdc++.h> using namespace std; const int N = 5005; long long dp[2][N]; int buf[N], a[N]; int cnt; long long min(const long long &x, const long long &y) { return x < y ? x : y; } inline int pos(int x) { return lower_bound(buf, buf + cnt, x) - buf; } int main() { int n; cin >> n; for (int i = 0; i < ...
14
#include <bits/stdc++.h> using namespace std; int main() { int t; scanf("%d", &t); while (t--) { int n; scanf("%d", &n); vector<int> a(2 * n + 1); vector<int> mx(2 * n + 1); for (int i = 1; i <= 2 * n; i++) { scanf("%d", &a[i]); mx[i] = max(mx[i - 1], a[i]); } vector<vector...
10
#include <bits/stdc++.h> using namespace std; int main() { int n, k; scanf("%d%d", &n, &k); vector<long long> a(n, 0); for (int i = 0; i < n; ++i) { int x; scanf("%d", &x); a[i] = x; } int kol = 0; long long sum = 0; for (int i = 0; i < n; ++i) { long long d = sum - (long long)kol * (n -...
8
#include <bits/stdc++.h> using namespace std; const int N = 20005; struct EDGE { int to, next; } e[N]; int laste[N], eid; void add_edge(int u, int v) { e[eid].to = v; e[eid].next = laste[u]; laste[u] = eid++; } int n, m, bd, lastbd; int used[N], lst[N], dep[N]; int dp1[N], dp2[N]; void dfs(int u, int D) { use...
21
#include <bits/stdc++.h> using namespace std; struct node { long long x, y; int id; node() {} node(long long _x, long long _y, int _id) { x = _x; y = _y; id = _id; } friend node operator-(const node &a, const node &b) { return node(a.x - b.x, a.y - b.y, 0); } friend long long operator*(c...
14
#include <bits/stdc++.h> using namespace std; vector<int> bin, v; int find(int n) { bin.clear(); int b = 1, num = 0; while (n) { bin.push_back(n % 2); n /= 2; } for (int i = 7; i >= 0; i--) { int t; if (i < bin.size()) t = bin[i]; else t = 0; num += t * b; b *= 2; } ...
5
#include <bits/stdc++.h> using namespace std; const long long INF = 1e15; struct edge { int from, to; long long w; bool operator<(edge other) const { return w < other.w; } }; edge edg[100011]; vector<pair<int, long long>> g[100011]; long long dist[100011]; int origion[100011]; int n, k, m; int portal[100011]; int...
18
#include <bits/stdc++.h> using namespace std; int a[100]; int main() { long long n, k; scanf("%lld%lld", &n, &k); long long m = n, len = 0, res = 0; int cnt = 1; while (m) { len++; if (m & 1) res++; a[cnt++] = m % 2; m = m / 2; } cnt = cnt - 1; if (k != 1) printf("%lld\n", (long long...
5
#include <bits/stdc++.h> using namespace std; long long int a, b, c, d, t, k; long long int bs(long long int l, long long int r, long long int val) { if (r == l) { if (l * (l - 1) / 2 == val) return l; return -1; } if (r - l == 1) { if (l * (l - 1) / 2 == val) return l; else if (r * (r - 1) ...
11
#include <bits/stdc++.h> using namespace std; int main() { int t, k; string x, y; vector<pair<string, string> > v; cin >> t; while (t--) { k = 0; cin >> x >> y; for (int i = 0; i < v.size(); i++) { if (x == v[i].second) { v[i].second = y; k = 1; break; } } ...
3
#include <bits/stdc++.h> using namespace std; deque<long long> d; vector<pair<long long, long long> > v; int main() { long long n, q, m = 0; long long a[100001]; cin >> n >> q; for (long long i = 0; i < n; i++) { cin >> a[i]; m = max(m, a[i]); d.push_back(a[i]); } long long x = a[0]; v.push_ba...
7
#include <bits/stdc++.h> using namespace std; const int MAXN = 200042, B = 30; int tab[MAXN], gol[MAXN][32], gor[MAXN][32]; int bigl[MAXN], bigr[MAXN]; int main() { ios_base::sync_with_stdio(0); int n; cin >> n; for (int i = (1); i <= (n); ++i) { int x; cin >> x; tab[i] = x; } for (int i = (1); ...
14
#include <bits/stdc++.h> using namespace std; char a[110][110]; int n, m, i, j, b[110], ans = 0; bool check() { int ii, x = j, y = j - 1; for (ii = 1; ii <= ans; ii++) if (a[x][b[ii]] > a[y][b[ii]]) return 1; return a[x][i] >= a[y][i] ? 1 : 0; } int main() { cin >> n >> m; for (i = 0; i < n; i++) cin >> a...
7
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; if (n <= 2) cout << 1 << endl << 1 << endl; else if (n == 3) cout << 2 << endl << 1 << " " << 3 << endl; else if (n == 4) cout << 4 << endl << 3 << " " << 1 << " " << 4 << " " << 2 << endl; else { cout << n << endl; ...
3
#include <bits/stdc++.h> using namespace std; const int MN = 101234; long double fac[MN] = {}, ans = 0; long double chs(int x, int y) { return fac[y] - fac[x] - fac[y - x]; } int main() { for (int i = 1; i < MN; i++) fac[i] = fac[i - 1] + log(i); int n, m, k, good; cin >> n >> m >> k; for (int i = 0; i <= n; i+...
19
#include <bits/stdc++.h> using namespace std; namespace IO { const int buffer_size = 1e5 + 5; char buf[buffer_size], *S, *T; bool flag_EOF; inline char read_char() { if (S == T) T = (S = buf) + fread(buf, 1, buffer_size, stdin); return S != T ? *(S++) : EOF; } inline int read_int() { int flag = 1; char c = read...
14
#include <bits/stdc++.h> using namespace std; class TaskA { public: void solve(std::istream& in, std::ostream& out) { ios::sync_with_stdio(false); int n; string home, res; in >> n; if (n % 2 == 0) { res = "home"; } else { res = "contest"; } out << res << endl; } }; int m...
1
#include <bits/stdc++.h> #define ll long long int #define pb push_back #define ff first #define sss second using namespace std; int main() { ll t,n; cin >> t; set<ll>s; for(ll i=1;i<=10000;i++) { s.insert(i*i*i); } while(t--) { cin >> n; ll f=0; for(auto x...
3
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; vector<bool> v(n); int cnt = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { int a, b; cin >> a >> b; cnt += a || b; } } cout << cnt; return 0; }
0
#include <bits/stdc++.h> using namespace std; template <typename T> inline T abs(T a) { return ((a < 0) ? -a : a); } template <typename T> inline T sqr(T a) { return a * a; } const int N = 5009; const int logN = 20; const int sqrN = 450; const int MOD = 100000; const int INF = 1e9; const long long INF64 = 1e18; con...
12
#include <bits/stdc++.h> using namespace std; template <typename T, typename L> inline bool smax(T &x, L y) { return x < y ? (x = y, true) : false; } template <typename T, typename L> inline bool smin(T &x, L y) { return y < x ? (x = y, true) : false; } constexpr int MAXN = 256; int n; string s; set<int> st; int cn...
2
#include <bits/stdc++.h> using namespace std; void c_p_c() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } const long long N = 123456; vector<long long> graph[N + 1]; long long dist[N + 1]; void dfs(long long src, long long par, long long& maxlen, long long& snode, set<long long>& s) { if (s...
14
#include <bits/stdc++.h> using namespace std; int ch[100005][26], sz[100005], ed[100005], top; multiset<int>* se[100005]; void dfs(int u, int d) { int heavy = -1, mx = 0; for (int i = 0; i < 26; i++) { if (ch[u][i] && sz[ch[u][i]] > mx) { heavy = i; mx = sz[ch[u][i]]; } } if (heavy == -1) { ...
14
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; const int N = 1e6 + 6; int S; ll br(int l, int r, vector<ll> &s) { ll res = 0; for (int i = l; i <= r; ++i) for (int j = i; j <= r; ++j) if (s[i] - s[j + 1] == S) ++res; return res; } int main() { ios::sync_wit...
15
#include <bits/stdc++.h> using namespace std; bool comp(pair<long long, long long> p1, pair<long long, long long> p2) { return (p1.second != p2.second ? p1.second > p2.second : p1.first > p2.first); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, m; cin >> n >> m; vector<vector<pair<long lon...
11
#include <bits/stdc++.h> using namespace std; stack<char> stk; char ch; int fn(char ch) { if (ch == '<' || ch == '(' || ch == '[' || ch == '{') return 1; else return 0; } int main() { int cnt = 0; while (scanf("%c", &ch) == 1 && ch != '\n') { if (stk.empty()) { stk.push(ch); } else if (fn(...
6
#include <bits/stdc++.h> using namespace std; const int N = 1000; int a, b; void input() { cin >> a >> b; } void solve() { vector<pair<int, int> > u, v; for (int i = -N; i <= N; ++i) { if (!i) continue; for (int j = 1; j <= N; ++j) { int k = i * i + j * j; if (k == a * a) u.push_back(make_pair(i...
8
#include <bits/stdc++.h> using namespace std; template <class T1> inline void debug(T1 _x) { cout << _x << '\n'; } template <class T1, class T2> inline void debug(T1 _x, T2 _y) { cout << _x << ' ' << _y << '\n'; } template <class T1, class T2, class T3> inline void debug(T1 _x, T2 _y, T3 _z) { cout << _x << ' ' <...
8
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c; char nt = ':'; cin >> a >> nt >> b; cin >> c; if (c >= 60) { a += c / 60; b += c % 60; } else b += c; if (b >= 60) { a += b / 60; b = b % 60; } if (a > 23) a = a % 24; if (a / 10 == 0 && b / 10 == 0) cout...
1
#include <bits/stdc++.h> using namespace std; int n; long long k; long long d[300002]; long long df[300002]; long long c[300002]; int bef[300002]; int aft[300002]; struct SparseMin { long long sp[20][300002]; void build() { for (int LOG = 1; LOG < 20; LOG++) for (int i = 0; i <= n + 1; i++) { int ...
16
#include <bits/stdc++.h> using namespace std; long long dp[(int)(1e5 + 10)][(1 << 8) + 5]; struct nod { long long a; long long s[10]; } mem[(int)(1e5 + 10)]; int cmp(nod x, nod y) { return x.a > y.a; } int cnt(int n) { int res = 0; while (n) { if (n & 1) res++; n >>= 1; } return res; } int main() { ...
15
#include <bits/stdc++.h> using namespace std; vector<int> v; int solve(int l, int h) { if (l > h) { return 0; } int mid = (l + h) / 2; if (h - l + 1 == 2) { v.push_back(l + 1); v.push_back(l); v.push_back(l + 1); return 3; } if (h - l + 1 == 3) { v.push_back(l + 1); v.push_back(l...
8
#include <bits/stdc++.h> using namespace std; int dp[2][507][507]; int ct[507], prefix[507]; int main() { int n, m; scanf("%d%d", &n, &m); dp[0][0][0] = 1; for (int i = 0; i < n; i++) { memset(dp[(i & 1) ^ 1], 0x00, sizeof(dp[(i & 1) ^ 1])); for (int j = 0; j <= n; j++) for (int k = 0; k <= n; k++...
13
#include <bits/stdc++.h> using namespace std; static const int INF = 500000000; template <class T> void debug(T a, T b) { for (; a != b; ++a) cerr << *a << ' '; cerr << endl; } int b, d; string a, c; int where[105], done[105]; int solve(int len) { string tmp; int n = a.size(), m = c.size(); for (int i = 0; i ...
12
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using pii = pair<int, int>; using ull = unsigned long long; vector<int> a[1001001]; const ll mod = 1000000007; int main() { int n, m; cin >> n >> m; int g, h; for (int i = 0; i < n; ++i) { cin >> g; for (int j = ...
11
#include <bits/stdc++.h> using namespace std; long long d[100005]; long long t[10]; long long gcd(long long a, long long b) { while (b) { long long r = a % b; a = b; b = r; } return a; } long long x1[] = {1, 4, 6, 7}; long long x2[] = {2, 4, 5, 7}; long long x3[] = {3, 5, 6, 7}; map<vector<long long>,...
16
#include <bits/stdc++.h> using namespace std; long long solve(long long n, int h, bool f) { if (!h) return 0; long long ret = 1; long long total = (1ll << h) - 1, leaf = 1ll << (h - 1); if (f) { if (leaf < n) { ret += total; ret += solve(n - leaf, h - 1, f); } else ret += solve(n, h - ...
9
#include <bits/stdc++.h> const double PI = 3.141592653589793238460; using namespace std; int E[1000001], S[1000001], F[1000001]; int main() { string st; int mx = 0; stack<int> stk; cin >> st; for (int i = 0; i < st.size(); i++) { char ch = st[i]; if (ch == '(') { stk.push(i); } else { ...
11
#include <bits/stdc++.h> using namespace std; long long ABS(long long a) { if (a >= 0) return a; return -a; } struct num { long long a; long long mod; num(long long a) { this->a = a; } num() {} num(long long a, long long mod) { this->a = a % mod; this->mod = mod; } num operator+(const num &o) ...
9