solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> const int inf = 0x3f3f3f3f; const int N = 400005; using namespace std; int a[N], b[N]; vector<int> v[N]; bool ex[N]; set<pair<int, int> > s; int main() { int n, k; scanf("%d%d", &n, &k); int i, j; for (i = 0; i < n; i++) { scanf("%d", &a[i]); v[a[i]].push_back(i); } for (i =...
10
#include <bits/stdc++.h> using namespace std; const int N = 2e6; const int INF = 1e9 + 9; const int B = 1e9 + 7; const double PI = 3.1415926535897932384626433832795; pair<double, double> operator+(const pair<double, double> &a, const pair<double, double> &b) { return pair<double, double...
17
#include <bits/stdc++.h> using namespace std; string S; int main() { bool State = true; cin >> S; for (int i = 1; i < S.length(); i++) { if (S[i] >= 'a' && S[i] <= 'z') { State = false; } } if (State) { for (int i = 1; i < S.length(); i++) { S[i] = tolower(S[i]); } if (S[0] >= ...
2
#include <bits/stdc++.h> using namespace std; int main() { int n; bool r, f; string s; cin >> n; getchar(); while (n--) { getline(cin, s); r = f = 0; if (s.rfind("lala.") == s.size() - 5) f = 1; if (s.find("miao.") == 0) r = 1; if ((f && r) || (!f && !r)) cout << "OMG>.< I don't kn...
3
#include <bits/stdc++.h> void Sort(int *BS, int idx2) { int i = 1, j = 0, k = 0; int tmp; for (i = 1; i < idx2; i++) { for (j = 0; j < idx2 - i; j++) { if (*(BS + j) > *(BS + (j + 1))) { tmp = *(BS + j); *(BS + j) = *(BS + (j + 1)); *(BS + (j + 1)) = tmp; } } } } int ...
10
#include <bits/stdc++.h> using namespace std; int n, m; unordered_map<string, string> dns; int main() { ios::sync_with_stdio(0); cin >> n >> m; while (n--) { string x, y; cin >> x >> y; dns[y] = x; } while (m--) { string x, y; cin >> x >> y; cout << x << " " << y << " #" << dns[y.subst...
1
#include <bits/stdc++.h> using namespace std; char a[120][120]; int main() { int n, m, x, y, count = 0, flag = 0; cin >> n >> m; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if (a[i][j] == 'B') { flag = 1; x = i; y = j; ...
0
#include <bits/stdc++.h> using namespace std; string s; int l, r, u, d; int main() { cin >> s; for (int i = 0; i < s.size(); ++i) if (s[i] == 'L') l++; else if (s[i] == 'R') r++; else if (s[i] == 'U') u++; else d++; d = fabs(d - u); l = fabs(r - l); if (d != l) { in...
3
#include <bits/stdc++.h> using namespace std; const int maxN = 1 << 17; struct Fenw { vector<int> A; vector<int> F; Fenw() { A = F = vector<int>(maxN, 0); } void upd(int i, int x) { int d = x - A[i]; A[i] += d; for (; i < maxN; i |= i + 1) { F[i] += d; } } int get(int l, int r) { i...
14
#include <bits/stdc++.h> using namespace std; char a[5505]; int main() { cin >> a; int n = strlen(a); int dp[5505]; dp[0] = 1; int MAX = 1; int anumber = 0; int bnumber = 0; int beforeb = 0; if (a[0] == 'b') bnumber++; else anumber++; for (int i = 1; i < n; i++) { if (a[i] == a[i - 1])...
7
#include <bits/stdc++.h> using namespace std; const int N = 100100; const int M = 200010; const long long inf = 1e15; const int mod = 1000000007; long long qpow(long long a, long long b) { long long ans = 1; while (b) { if (b & 1) ans = ans * a % mod; a = a * a % mod; b /= 2; } return ans; } long lo...
7
#include <bits/stdc++.h> using namespace std; inline int read(); const int N = 5e5 + 5; int n; int v[N], he[N], ne[N], to[N], id[N], f[20][N]; long long sum, w; void Link(int x, int y) { v[x] > v[y] ? f[0][x] = y : f[0][y] = x; } void Chkmin(long long& x, long long y) { if (y < x) x = y; } bool Cmp(int x, int y) { re...
20
#include <bits/stdc++.h> using namespace std; int main() { int i; char c[101]; for (i = 0;; i++) { cin >> c[i]; if (c[i] == '?') { break; } } if (c[i - 1] == 'A' || c[i - 1] == 'a' || c[i - 1] == 'u' || c[i - 1] == 'U' || c[i - 1] == 'y' || c[i - 1] == 'Y' || c[i - 1] == 'i' || c...
0
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 123; int N, val[maxn]; vector<int> v[2]; int main() { scanf("%d", &N); for (int i = 1, a; i <= N; i++) { scanf("%d%d", &a, &val[i]); v[a].push_back(i); } for (int i = 0, j = 0, k = 1; k < N; k++) { int a = v[0][i], b = v[1][j]; ...
13
#include <bits/stdc++.h> using namespace std; const int inf = int(1e9); const double eps = 0.0000000001, pi = 3.14159265358979323; const int maxn = int(2e5 + 100); vector<vector<int> > g; bool visited[maxn]; int main() { ios::sync_with_stdio(0); cin.tie(0); int a[5], o = -1, I = -1, sum = 0; for (int i = 1; i <...
11
#include <bits/stdc++.h> using namespace std; int n, m; char grid[50][50]; bool is_valid(int x, int y) { vector<bool> exist(7, false); exist[grid[x][y] - 'a'] = true; exist[grid[x + 1][y] - 'a'] = true; exist[grid[x][y + 1] - 'a'] = true; exist[grid[x + 1][y + 1] - 'a'] = true; if (exist['f' - 'a'] && exist...
1
#include <bits/stdc++.h> using namespace std; const long long N = 2e5 + 1303; long long k; long long ans = 0; vector<long long> adj[N]; long long uni[N]; long long dfs(long long x, long long par) { long long sub_uni = uni[x]; for (auto &ch : adj[x]) if (par != ch) sub_uni += dfs(ch, x); ans += min(2 * k - sub...
10
#include <bits/stdc++.h> const int INF = 2147483647; const long long LLINF = 2e18; using namespace std; typedef long long ll; const int maxn = 2e5 + 5; const int MOD = 1e9 + 7; inline int read() { int x = 0, f = 1; char ch = getchar(); while (!isdigit(ch)) { if (ch == '-') f = -1; ch = getchar(); } while (isdigit(ch...
11
#include <bits/stdc++.h> using namespace std; string s1, s2, s3, s4, s5, s6; bool check(string s) { if (s1 == s || s2 == s || s3 == s || s4 == s || s5 == s || s6 == s) { return 1; } else { return 0; } } string process(string s) { string out; for (int i = 0; i < s.length(); i++) { if (s[i] == ';' |...
5
#include <bits/stdc++.h> using namespace std; int n, m, q, f[400050]; int F(int x) { return f[x] == x ? x : f[x] = F(f[x]); } int main() { scanf("%d%d%d", &n, &m, &q); for (int i = 1; i <= n + m; i++) f[i] = i; for (int i = 1, x, y; i <= q; i++) { scanf("%d%d", &x, &y); y += n; x = F(x), y = F(y); ...
11
#include <bits/stdc++.h> using namespace std; string tobin(int x, int len) { string c; while (x > 0) { c.push_back(x % 2 + '0'); x >>= 1; } while (int((c).size()) < len) c.push_back('0'); reverse((c).begin(), (c).end()); return c; } const int MXN = 100000; int n, ar[MXN + 5]; int pls[MXN + 5], ma; l...
6
#include <bits/stdc++.h> using namespace std; int main() { int t; int m, n, a, b; cin >> t; while (t--) { cin >> m >> n >> a >> b; cout << ((n - m) % (a + b) == 0 ? (n - m) / (a + b) : -1) << endl; } return 0; }
0
#include <bits/stdc++.h> using namespace std; int n, m, q; int sum[2555][2555]; map<pair<pair<int, int>, pair<int, int> >, int> mp; void add(int x, int y, int val) { for (int i = x; i <= n; i += (i & (-i))) { for (int j = y; j <= m; j += (j & (-j))) { sum[i][j] += val; } } } int query(int x, int y) { ...
16
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using pii = pair<int, int>; using vi = vector<int>; ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; } ll dist(const pii& a, const pii& b) { ll dx = a.first - b.first; ll dy = a.second - b.second; return dx * dx + dy * d...
15
#include <bits/stdc++.h> using namespace std; int main() { long long int t; cin >> t; while (t--) { long long int n; cin >> n; long long int a[2 * n]; for (long long int i = 0; i < 2 * n; i++) { cin >> a[i]; } sort(a, a + 2 * n); cout << a[n] - a[n - 1] << endl; } return 0; }...
2
#include <bits/stdc++.h> using namespace std; long long modPow(long long b, long long e, long long mod) { long long result = 1; b %= mod; while (e) { if (e & 1) result = ((long long)result * b) % mod; b = (b * b) % mod; e >>= 1; } return result; } int main(int argc, char const* argv[]) { ios_bas...
6
#include <bits/stdc++.h> using namespace std; inline int read() { char ch = 0; int x = 0, flag = 1; while (!isdigit(ch)) { ch = getchar(); if (ch == '-') flag = -1; } while (isdigit(ch)) { x = (x << 3) + (x << 1) + ch - '0'; ch = getchar(); } return x * flag; } int n, m, k, f[110][110]; ch...
15
#include <bits/stdc++.h> using namespace std; long long a[1000000]; long long s, i, j, d; int main() { d = 1; j = 1; cin >> s; for (i = 0; i < s; i++) { cin >> a[i]; } for (i = 0; i < (s - 1); i++) { if (a[i] < a[i + 1]) d++; else d = 1; j = max(j, d); } cout << j << endl; ...
0
#include <bits/stdc++.h> const long long maxn = 110; const long long maxpfn = 10010; const long long mo = 1000000007; long long f[2][maxpfn], C[maxn + 1][maxn + 1], ci[maxn + 1], yh[maxn + 1][maxn + 1]; long long n, m, K; long long result; long long mi(long long a, long long p) { long long b; bool first = true;...
11
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e6 + 3; const int N = 1e6 + 5; long long fac[2 * N]; long long binPow(long long x, long long p) { if (p == 0) return 1LL; long long r = binPow(x, p / 2LL); r = (r * r) % MOD; r *= (p % 2LL ? x : 1LL); return r % MOD; } long long getCnk(int k...
10
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t; cin >> t; while (t--) { int n, m; cin >> n >> m; bool z = false; for (int i = 0; i < n; i++) { int a, b, c, d; cin >> a...
1
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int len; cin >> len; vector<pair<int, int>> join; int arr[len]; for (int i = 0; i < len; i++) cin >> arr[i]; for (int i = 1; i < len; i++) { int mi = min(arr[i - 1], arr[i]);...
6
#include <bits/stdc++.h> using namespace std; char St[100007]; stack<pair<char, int> > S1; stack<pair<int, int> > S2; vector<pair<int, int> > V; int Pre[100007]; int main() { int i, j, k, l, m, n, x, y, z, a, b, r, ans; scanf("%s", St); n = strlen(St); for (i = 0; i < n; i++) { if ((S1.empty()) || (St[i] ==...
9
#include <bits/stdc++.h> int main() { int n; while (scanf("%d", &n) == 1) { int a = n - n % 10; int b = n + 10 - n % 10; if (n - a > b - n) printf("%d\n", b); else printf("%d\n", a); } return 0; }
0
#include <bits/stdc++.h> using namespace std; const int inf = 2e9 + 10; const int N = 300000 + 10; int a[N]; vector<int> e[N]; multiset<int> s; int main() { int n, u, v; scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); s.insert(a[i]); } for (int i = 1; i <= n - 1; i++) { scanf("...
11
#include <bits/stdc++.h> using namespace std; int n, m; int x[5005]; struct hole { int p, c; bool operator<(const hole& other) const { return p < other.p; } } h[5005]; long long d[2][5005]; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cerr.tie(nullptr); cin >> n >> m...
18
#include <bits/stdc++.h> using namespace std; template <class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; } template <class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; } vector<int> l, r; vector<vector<int>> dp; vector<vector<int>> rg; int fun(int l, int r) { if (l > r) retur...
15
#include <bits/stdc++.h> using namespace std; const int INF = 1000000007; int main() { int n; cin >> n; int R1[n]; for (int i = 0; i < n; i++) { cin >> R1[i]; } sort(R1, R1 + n); int m; cin >> m; int P1[m]; for (int i = 0; i < m; i++) { cin >> P1[i]; } sort(P1, P1 + m); int k; cin >>...
5
#include <bits/stdc++.h> using namespace std; const int N = 100005; int n, m, vis[N], in[N], d[N]; vector<int> e[N], g[N], s; int ask(int u, int v) { printf("? %d %d\n", u, v); fflush(stdout); int x; scanf("%d", &x); return x; } void dfs(int u) { vis[u] = in[u] = 1; for (auto v : e[u]) { if (!in[v]) g...
24
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 5, md = 1e9 + 7; int n, m, ans, fac[N], iv[N], pn[N], pm[N], k; inline int pow(int a, int b) { int res = 1; for (; b; b >>= 1, a = (unsigned long long)a * a % md) if (b & 1) res = (unsigned long long)res * a % md; return res; } inline int C(int...
16
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; for (int i = 0; i < t; i++) { int n, k; cin >> n >> k; while (n > 0) { for (int i = 0; i < k; i++) { cout << char(97 + i); n--; if (n == 0) break; } } cout << endl; } }
0
#include <bits/stdc++.h> using namespace std; int n, k; long long ans, m, p, h[100005], a[100005], now[100005]; struct node { long long v; int x; friend bool operator<(node a, node b) { return a.v > b.v; } }; priority_queue<node> q; bool check(long long mid) { for (int i = 1; i <= n; i++) { now[i] = mid; ...
21
#include <bits/stdc++.h> using namespace std; struct treenode { int rev, sum, max, maxl, maxr, min, minl, minr; int maxposl, maxposr, maxlpos, maxrpos, minposl, minposr, minlpos, minrpos; }; treenode tree[400000]; treenode tmp; int g[120000]; int u[30], v[30]; int i, j, m, n, s, t, w, x, y, z; inline int fastscanf(...
20
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; auto match = [](string s, string t) -> int { assert(s.size() == t.size() && s.size() == 2); return (s[0] == '_' || s[0] == t[0]) && (s[1] == '_' || s[1] == t[1]); }; auto solve = [&](string s) -> int { if (s.size() == 1...
10
#include <bits/stdc++.h> using namespace std; int A[100010], B[100010], f[1000]; bool cmp(int aa, int bb) { return aa > bb; } bool vis[1000]; int n, m, an = 0, dn = 0; int solve(int def) { int i = 1, top = 1; if (def == 1) top = an; int kill = 0, sum = 0; int ret = 0; for (; top <= an; top++) { i = top; ...
11
#include <bits/stdc++.h> using namespace std; struct BIT { long long n; vector<long long> bit; BIT(long long sz) { bit.resize(sz + 1); n = sz; } long long sum(long long i) { long long s = 0; while (i > 0) { s += bit[i]; i -= i & -i; } return s; } void add(long long i, l...
10
#include <bits/stdc++.h> using namespace std; vector<int> name, pseu; vector<pair<int, int>> vet; long long sum = 0; struct Trie { vector<int> N, P; map<char, Trie> children; int h; void insert(string &str, bool is_name, int x, int pos) { if (pos < (int)str.size()) { if (children.find(str[pos]) == chi...
15
#include <bits/stdc++.h> using namespace std; template <class T> inline bool Up(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } template <class T> inline bool Down(T &a, const T &b) { if (a > b) { a = b; return true; } return false; } inline int getus() { int tmp, c;...
23
#include <bits/stdc++.h> using namespace std; int fx[] = {1, -1, 0, 0}; int fy[] = {0, 0, 1, -1}; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int t; cin >> t; for (int tc = 1; tc <= t; tc++) { int n; cin >> n; cout << fixed << setprecision(10) << cos(acos(-1.0) / (4 * n)) / sin...
12
#include <bits/stdc++.h> using namespace std; const int INF = 2147483647, MOD = 1000 * 1000 * 1000 + 7; const double eps = 1e-8; const int sz = 2200; int n, m, orig[sz], base; bool les(int a[sz], int b[sz]) { for (int i = 0; i < (m + 1); i++) { if (a[i] < b[i]) return true; if (a[i] > b[i]) return false; } ...
15
#include <bits/stdc++.h> using namespace std; int main() { string s1, s2; cin >> s1 >> ws >> s2; int t; cin >> t; vector<pair<string, string> > v; for (int i = 0; i < t; i++) { string a, b; cin >> a >> ws >> b; v.push_back(make_pair(a, b)); } cout << s1 << " " << s2 << endl; for (int i = 0...
1
#include <bits/stdc++.h> using namespace std; int n, m; struct point { long long x, y; } p[100010], o; inline long long cross(point a, point b, point c) { return (b.x - a.x) * (c.y - a.y) - (c.x - a.x) * (b.y - a.y); } inline bool cmp(point x, point y) { return cross(o, x, y) > 0; } int main() { scanf("%d", &n); ...
17
#include <bits/stdc++.h> using namespace std; char in[1011], in1[1000011]; int main() { int i, j, k; scanf("%s%s", in, in1); for (i = j = 0; in[i] && in1[j]; j++) { if (in[i] == in1[j]) { i++; } } k = j; while (in[i]) { i++; } while (in1[k]) { k++; } for (i--, k--; ~i && ~k; k-...
6
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); int n; cin >> n; int cnt = 1, a[n], l, r; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n; i++) { int cur_sec = 1, cur = i; l = i - 1, r = i + 1; while (l >= 0) { if (a[l] <= a[cur]) cur_sec+...
3
#include <bits/stdc++.h> using namespace std; const long long int maxN = 1E5 + 10; const long long int mod = 1E9 + 7; const long long int INF = 1E9; int32_t main() { long long int n; cin >> n; long long int turn = 1, ind = 1; vector<long long int> otp; while (turn < n) { ind += turn; ind %= n; if ...
0
#include <bits/stdc++.h> using namespace std; int n, _2[200010]; struct sa { char s[200010]; int rk[200010], sa[200010], id[200010], b[200010]; int mn[200010][23]; bool opt; void sa_sort(int m) { for (int i = 1; i <= m; i++) b[i] = 0; for (int i = 1; i <= n; i++) b[rk[i]]++; for (int i = 1; i <= m...
15
#include <bits/stdc++.h> using namespace std; int main() { int r, g, b; scanf("%d%d%d", &r, &g, &b); int time = 0; while (1) { if (time % 3 == 0) r -= 2; if (time % 3 == 1) g -= 2; if (time % 3 == 2) b -= 2; if (r <= 0 && g <= 0 && b <= 0) break; time++; } time += 30; printf("%d\n", ti...
2
#include <bits/stdc++.h> using namespace std; const int MOD = 1000000007; const int INF = 2e9; const long long INFLL = 1e18; const int MAX_N = 1000; vector<int> vt; vector<pair<int, int> > v; int ans[MAX_N + 10][MAX_N + 10]; int N; int idx[MAX_N + 1]; int main() { scanf("%d", &N); for (int i = 1; i <= N; i++) { ...
18
#include <bits/stdc++.h> using namespace std; int main() { int n, m; vector<vector<pair<int, int>>> x(10005); cin >> n >> m; for (int i = 1; i <= n; i++) x[i].push_back(make_pair(i, i)); for (int i = 0; i < m; i++) { int a, b; cin >> a >> b; if (a == b) continue; if (a > b) swap(a, b); x[a...
9
#include <bits/stdc++.h> using namespace std; void solve() { int n; int num = 1; cin >> n; for (int i = 1; i < n; i++) { if ((num + i) <= n) { num = num + i; cout << num << " "; } else { num = num + i - n; cout << num << " "; } } } int main() { cin.tie(0)->sync_with_stdio...
0
#include <bits/stdc++.h> using namespace std; int X, Y; char grid[9][9]; bool all_filled(int x, int y) { for (int i = 3 * x; i <= 3 * x + 2; i++) for (int j = 3 * y; j <= 3 * y + 2; j++) if (grid[i][j] == '.') return false; return true; } int main() { ios::sync_with_stdio(0); for (int i = 0; i < 9; i+...
6
#include <bits/stdc++.h> #pragma comment(linker, "/Stack:256000000") using namespace std; int main() { string R = "RIGHT\n", L = "LEFT\n", P = "PRINT "; int n, k; char s[150]; scanf("%d%d\n%s", &n, &k, &s); int id = (k > n / 2) ? 1 : 0; if (id) { for (int i = 0; i < n - k; ++i) printf("%s", R.data()); ...
1
#include <bits/stdc++.h> using namespace std; char mp[2005][2005]; int dp[2005][2005]; int main() { int n, m; int sum = 0; scanf("%d %d", &n, &m); for (int i = 1; i <= n; i++) { getchar(); for (int j = 1; j <= m; j++) { scanf("%c", &mp[i][j]); } } for (int i = 1; i <= n; i++) { for (in...
13
#include <bits/stdc++.h> using namespace std; int lmx[1600005], rmx[1600005], lmn[1600005], rmn[1600005], sum[1600005], lans[1600005], rans[1600005], whans[1600005], mans[1600005]; void upd(int now) { sum[now] = sum[now << 1] + sum[now << 1 | 1]; lmx[now] = max(lmx[now << 1], sum[now << 1] + lmx[now << 1 | 1]);...
19
#include <bits/stdc++.h> using namespace std; int n, x, y, counter; vector<int> nod[200005]; int dist[200005], parent[200005]; bool ap[200005]; void go_visit(int pos, int last) { for (int i = 0; i < nod[pos].size(); i++) { if (nod[pos][i] == last) continue; parent[nod[pos][i]] = pos; dist[nod[pos][i]] = d...
13
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; char a[110][110]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { cin >> a[i][j]; } } for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if (a[i][j] != 'W' && a[i][j] != 'B' && a[...
0
#include <bits/stdc++.h> using namespace std; struct point { int x, y; } a[100010]; const double pi = acos(-1.0); double d[100010], p[100010]; int n, m, tt; inline int rd() { int x = 0, f = 1; char ch = getchar(); for (; ch < '0' || ch > '9'; ch = getchar()) if (ch == '-') f = -1; for (; ch >= '0' && ch <...
23
#include <bits/stdc++.h> using namespace std; const char nl = '\n'; const int INF = 0x3f3f3f3f; const long long INFLL = 0x3f3f3f3f3f3f3f3f; const long long MOD = 1e9 + 7; const long double EPS = 1e-10; mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count()); struct suff_array { const int L; str...
16
#include <bits/stdc++.h> using namespace std; char c[1001]; int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; int a[101][101]; int main() { int n; int ans = 1; int h = 0, m = 0; int q = 0; scanf("%d\n", &n); for (int i = 0; i < n; i++) { char c; int ch, cm; scanf("[%d:%d %c.m.]: "...
11
#include <bits/stdc++.h> using namespace std; const long double PI = acos(-1); const int INF = 1e9; const int N = 1e4 + 1; const int LOG = 30; vector<int> inds[N]; vector<pair<int, int> > answer[2]; int a[N], b[N]; void f(int* a, int i, int j, int ai) { answer[ai].push_back({i, j}); a[i] ^= a[j]; } vector<int> gaus...
19
#include <bits/stdc++.h> #pragma GCC optimize("Ofast", "unroll-loops", "no-stack-protector") using namespace std; using ll = long long; using ld = long double; using pii = pair<int, int>; using uint = unsigned int; using ull = unsigned long long; mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); defa...
15
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 1; const int maxbit = 30; int n, a[maxn], cnt[maxn][maxbit]; int L[maxn], R[maxn]; stack<int> Stack; void Input() { cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 1; i <= n; i++) { for (int j = 0; j < maxbit; j++) cnt...
14
#include <bits/stdc++.h> using namespace std; int mark[1002][1002]; int area[1002][1002]; char res[1002][1002]; int total_area; int fy, fx; int n, m; void fill_area(vector<pair<int, int> > P) { int sz = P.size(); int unusable[10] = {0}; for (int i = 0; i < sz; i++) { int y = P[i].first, x = P[i].second; a...
14
#include <bits/stdc++.h> using namespace std; template <class T1, class T2> bool chmin(T1 &a, T2 b) { return b < a && (a = b, true); } template <class T1, class T2> bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); } const long double eps = 1e-8; long double dot(complex<long double> a, complex<long double> b...
12
#include <bits/stdc++.h> using namespace std; long long coe[72]; int main() { long long t, a, b, i, n; cin >> t >> a >> b; int ret = 0; if ((t == 1) && a == 1 && b == 1) { printf("inf\n"); return 0; } if (a == b) ++ret; if (a == t) { if (b == a) printf("2\n"); else printf("0\n"...
20
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e5 + 5; long long s[2 * MAXN]; int main() { int n; scanf("%d", &n); for (int i = 0; i < 2 * n; i++) { scanf("%lld", &s[i]); } sort(s, s + 2 * n); long long ans = (s[n - 1] - s[0]) * (s[2 * n - 1] - s[n]); for (int i = 1; i < n; i++) { ...
7
#include <bits/stdc++.h> using namespace std; int n, m; bool debug = false; int k; int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0}; const int N = 2005; struct Nxt { int nxt[26]; }; char s[1000025], t[N]; int lt; int a[N]; vector<Nxt> v[N], w; pair<int, int> ans[N]; int main() { scanf("%d", &n); for (int(i) = 0; ...
17
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7, sz = 200; long long dp[11][11], n, ans; int fc3() { int x; cin >> x; return x; } int func2(int i, int j) { return i < n ? fc3() : 0; } int fc(int i, int j) { i += j / n; j %= n; dp[i][j] = func2(i, j); return i < n ? fc(i, j + 1)...
12
#include <bits/stdc++.h> using namespace std; int c[100005]; vector<int> G[100005]; int if_visited[100005]; int mini; void dfs(int node) { if_visited[node] = 1; int l = G[node].size(); for (int i = 0; i < l; i++) { if (if_visited[G[node][i]] == 0) { if (mini > c[G[node][i]]) mini = c[G[node][i]]; ...
5
#include <bits/stdc++.h> int main() { int i, x, y, a, b, d = 1, turns = (-1), m = 1, x1 = 0, y1 = 0, x2 = 0, y2 = 0; scanf("%d %d", &x, &y); a = b = 0; while (1) { x1 = a; y1 = b; if (m == 1) { a = a + d; m++; turns++; } else if (m == 2) { b = b + d; m++; d++;...
6
#include <bits/stdc++.h> using namespace std; const int N = 500005; int n, m, p, l[N], r[N], pp[N]; char s[N], opt[N]; stack<int> st; int main() { scanf("%d%d%d", &n, &m, &p); scanf("%s%s", s + 1, opt + 1); for (int i = 1; i <= n; i++) { if (s[i] == '(') st.push(i); else { int cur = st.top(); ...
9
#include <bits/stdc++.h> using namespace std; const int MAX_INT = (1 << 31) - 1; const long long MAX_LL = (1LL << 63) - 1; int month[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; struct date { int y, m, d; date() : y(1900), m(1), d(1) {} }; istream& operator>>(istream& in, date& d) { in >> d.y; in.ig...
5
#include <bits/stdc++.h> using namespace std; template <class T> T Bitcnt(T a) { int sum = 0; while (a) { if (a & 1) sum++; a /= 2; } return sum; } template <class T> T Max3(T a, T b, T c) { return max(a, max(b, c)); } template <class T> T Lcm(T a, T b) { T tmp = __gcd(a, b); return (a / tmp) * b;...
11
#include <bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:36777216") template <class T> inline T &RD(T &); template <class T> inline void OT(const T &); inline long long RD() { long long x; return RD(x); } inline char &RC(char &c) { scanf(" %c", &c); return c; } inline char RC() { char c; ...
21
#include <bits/stdc++.h> using namespace std; inline int Mid(int x, int y) { return (x + y) >> 1; } struct node { int l, r, siz, sum; } tree[10004 * 4]; void push_up(int id) { tree[id].sum = tree[(id << 1)].sum + tree[(id << 1 | 1)].sum; tree[id].siz = tree[(id << 1)].siz + tree[(id << 1 | 1)].siz; } void build(i...
13
#include <bits/stdc++.h> using namespace std; int b[30], c[30]; int a[4][4], j; int n, sum, sum1; int s[30]; int d[30], r[30]; void get(int num) { if (num == 2 * n && s[0] != s[1]) return; if (num == 3 * n && s[0] != s[2]) return; if (num == 4 * n && s[0] != s[3]) return; if (num == (n - 1) * n + 2 && d[0] != d...
11
#include <bits/stdc++.h> using namespace std; const long long maxn = 3e5 + 10; long long n, m, a[maxn], d[1000010]; struct seg_tree { struct nodes { long long l, r, sum, max_num; } node[maxn << 2]; void up(long long now) { return ( void)(node[now].sum = node[(now << 1)].sum + node[(now << 1 | 1)]....
12
#include <bits/stdc++.h> using namespace std; const int MAXN = 200005; int n, m; int p[MAXN], s[MAXN], b[MAXN], inc[MAXN], pref[MAXN]; int tmp[MAXN], ans[MAXN]; struct Data { int ty, x, y, z, id; Data() {} Data(int ty, int x, int y, int z, int id) : ty(ty), x(x), y(y), z(z), id(id) {} } a[MAXN], d[MAXN]; in...
17
#include <bits/stdc++.h> using namespace std; int main() { unsigned long long n; cin >> n; unsigned long long arr[n]; for (int i = 0; i < n; i++) cin >> arr[i]; unsigned long long p1 = 0, p2 = 0; for (unsigned long long i = 1; i < n; i++) { if (arr[p1] * (i + 1) < arr[i] * (p1 + 1)) p1 = i; if ((arr...
10
#include <bits/stdc++.h> using namespace std; void fast() { ios_base ::sync_with_stdio(0); cin.tie(0); cout.tie(0); } int main() { fast(); int n; cin >> n; int l = n, r = 1, sz = 0; if (n % 2 == 0) { for (int i = 0; i < n / 2; ++i) { cout << l-- << " " << r++ << " "; } } else { cout ...
4
#include <bits/stdc++.h> using namespace std; int n, a[2][210000], b[210000], c[210000], flg[210000]; int lowbit(int x) { return (x & (-x)); } void add(int index, int val) { while (index <= n) { b[index] += val; index = index + lowbit(index); } } int sum(int index) { int tot; tot = 0; while (index > 0...
12
#include <bits/stdc++.h> using namespace std; long long max(long long a, long long b) { if (a > b) { return a; } else { return b; } } long long min(long long a, long long b) { if (a < b) { return a; } else { return b; } } struct P { double x, y; P() {} P(int x, int y) : x(double(x)), y...
10
#include <bits/stdc++.h> using namespace std; template <typename T1, typename T2> ostream &operator<<(ostream &O, pair<T1, T2> &t) { return O << "(" << t.first << "," << t.second << ")"; } template <typename T> ostream &operator<<(ostream &O, vector<T> &t) { for (int _ = 0; _ < (int)t.size(); ++_) O << t[_] << " ";...
5
#include <bits/stdc++.h> using namespace std; typedef priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> rpqpi; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long n, k, s, mi, ma; cin >> n >> k >> s; mi = k; ma = k * (n...
8
#include <bits/stdc++.h> using namespace std; int a[10], n, m, k, l, o, i, j; int main() { cin >> a[1] >> a[2] >> a[3] >> a[4]; sort(a + 1, a + 5); for (i = 1; i <= 2; i++) for (j = i + 1; j <= 3; j++) for (l = j + 1; l <= 4; l++) if (a[i] + a[j] > a[l]) { cout << "TRIANGLE"; ...
1
#include <bits/stdc++.h> using namespace std; const int a[] = {0, 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51, 1, 2, 1, 14, 1, 2, 2, 14, 1, 6, 1, 4, 2, 2, 1, 52, 2, 5, 1, 5, 1, 15, 2, 13, 2, 2,...
6
#include <bits/stdc++.h> using namespace std; int num[5000 + 20]; int length[20]; int ww[100000 + 20]; int dp[5000 + 20][5000 + 20]; void upd(int &a, int b) { if (a < b) a = b; } int main() { memset(dp, 0, sizeof(dp)); memset(num, 0, sizeof(num)); int n; scanf("%d", &n); memset(length, 0, sizeof(length)); ...
18
#include <bits/stdc++.h> using namespace std; int n; string str; long long A[2000]; long long B[2005]; int id; bool used[2005]; int main() { cin >> n; for (int i = 0; i < n; i++) { scanf("%I64d %I64d", &A[i], &B[i]); } cin >> str; str = str + 'L'; id = -1; for (int i = 0; i < n; i++) { if (id == -...
18
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, m; cin >> n >> m; long long int ar[n + 2]; for (int i = 1; i <= n; i++) { cin >> ar[i]; } sort(ar + 1, ar + n + 1); int pos = (n + 1) / 2; long long int ans = ar[pos]; long long r...
6
#include <bits/stdc++.h> constexpr int P = 998244353; int power(int a, int b) { int res = 1; for (; b; b >>= 1, a = 1ll * a * a % P) if (b & 1) res = 1ll * res * a % P; return res; } int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); int n, k; std::cin >> n >> k; n /= 2; std::ve...
16