solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> const int N = 55; const double inf = 1e17; using namespace std; int n; struct node { int h, w; double val; bool friend operator<(node a, node b) { return a.h > b.h || (a.h == b.h && a.val < b.val); } } a[N]; double f[N][N]; void upd(double &x, double y) { if (y < x) x = y; } bool ...
17
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); long long int x, y, z, t1, t2, t3, ts, te; cin >> x >> y >> z >> t1 >> t2 >> t3; ts = t1 * (abs(y - x)); te = (3 * t3) + (t2 * (abs(z - x) + abs(y - x))); if (te <= ts) cout << "YES\n"; else cout << "NO\n"...
0
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 10; const int M = 1000000007; void add(int &x, int y) { x += y; if (x >= M) x -= M; } void sub(int &x, int y) { x -= y; if (x < 0) x += M; } bool ban[maxn]; int n, k, a[maxn], sz[maxn], ans, cnt[maxn], way[maxn], mx, tc[maxn], tw[maxn]; int sc...
18
#include <bits/stdc++.h> int main() { int n; while (scanf("%d", &n) == 1) { int M[1000]; int first, sec, ptrf, ptrs; for (int i = 0; i < n; i++) scanf("%d", M + i); first = sec = 0; ptrf = ptrs = -1; for (int i = 0; i < n; i++) { if (M[i] > first) { sec = first, ptrs = ptrf; ...
0
#include <bits/stdc++.h> using namespace std; int main() { char s[1000001]; scanf("%s", s); int l = strlen(s); for (int i = 0; i < l; ++i) if (s[i] == 'r') { printf("%d\n", (i + 1)); } for (int i = l - 1; i >= 0; --i) if (s[i] == 'l') { printf("%d\n", (i + 1)); } return 0; }
4
#include <bits/stdc++.h> using namespace std; inline char gc() { static char buf[100000], *p1 = buf, *p2 = buf; return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2) ? EOF : *p1++; } inline long long read() { long long first = 0; char ch = getchar(); bool posi...
20
#include <bits/stdc++.h> using namespace std; string alpha = "abcdefghijklmnopqrstuvwxyz"; const int MAX = 1e8 + 10; const int N = 1e5 + 5; const int J = 550; const int K = 5500; int n, m, x, y, rem, mx, z, mid, sum, ans2; double ans; double dis, larg; vector<pair<double, int>> vec; int main() { scanf("%d", &n), scan...
4
#include <bits/stdc++.h> using namespace std; const long long INFLL = 0x3f3f3f3f3f3f3f3f; namespace isdh { struct Line { long long m, b, start; Line() : m(0), b(INFLL) {} Line(long long x, long long y) : m(x), b(y), start(-INFLL) {} long long isecX(const Line& o) const { if (m == o.m) return -INFLL; lon...
21
#include <bits/stdc++.h> using namespace std; long long a = 1, n; int main() { cin >> n; while (1 == 1) { if (n % a != 0) { cout << n / a + 1; break; } if (a > n) { cout << a * 3; break; } a = a * 3; } }
8
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t, n, m, i, j, s, k, p; cin >> t; vector<int> a; for (i = 1; i <= 1700; i++) { if (i % 3 != 0 && i % 10 != 3) { a.push_back(i); } } while (t--) { cin >> k; cout << a[k - ...
0
#include <bits/stdc++.h> using namespace std; int n; int main() { cin >> n; if (n == 3) { cout << 7; return 0; } vector<int> answer; for (int i = 0; i < (n / 2) - 1; i++) { answer.push_back(1); } if (n % 2 == 0) answer.push_back(1); else answer.push_back(7); sort(answer.rbegin(), a...
4
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; const int N = 1E5 + 7; const int INF = 0x3f3f3f3f; int a[N]; int dp1[N]; int dp2[N]; int f1[N]; int f2[N]; int n, q; int main() { scanf("%d %d", &q, &n); for (int i = 1; i <= q; i++) { int l, r; scanf("%d %d", &l, &r...
11
#include <bits/stdc++.h> using namespace std; const int inf = (int)1e9 + 7; const long long MOD = (long long)1e9 + 7; const double eps = 1e-7; const int N = (int)1e5; const int L = (int)1e6 + 1; const int ALPH = 26; struct node { int nxt[ALPH], link, parent, len; long long cost; node() { cost = 0; fill(nx...
19
#include <bits/stdc++.h> using namespace std; long long n, m, rx1, rx2, ry1, ry2, px, py, ans = 0; long long rx[501], ry[501], bx[501], by[501], cnt[501][501]; bool fix(int x1, int y1, int x2, int y2, int x3, int y3) { long long dx1 = x2 - x1; long long dy1 = y2 - y1; long long dx2 = x3 - x1; long long dy2 = y3...
18
#include <bits/stdc++.h> int N, x, y, i, j, v; int main() { scanf("%d", &N); for (i = N; i--;) { x = 0; for (j = N; j--;) scanf("%d", &y), x = x > y ? x : y; printf("%d ", x == N - 1 ? x + v++ : x); } }
3
#include <bits/stdc++.h> namespace chtholly { inline int read() { int x = 0, f = 1; char c = getchar(); for (; !isdigit(c); c = getchar()) f ^= c == '-'; for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + (c ^ '0'); return f ? x : -x; } template <typename mitsuha> inline bool read(mitsuha &x) { x =...
15
#include <bits/stdc++.h> using namespace std; int main() { long long x, y; cin >> x >> y; long long z = x - y; cout << (z < 0 || z & 1 || (z / 2) & y ? 0 : (1ll << __builtin_popcountll(y)) - 2 * (x == y)); }
9
#include <bits/stdc++.h> int f[42][65][65], v[65]; int n, m; void dfs(int i, int j, int k, int now, int a, int b, int c) { if (now > n) f[i + 1][b][c] = ((f[i + 1][b][c]) > (f[i][j][k] + n - v[a]) ? (f[i + 1][b][c]) : (f[i][j][k] + n - v[a])); else { ...
13
#include <bits/stdc++.h> using namespace std; const int maxn = 5e5; long long a[maxn]; long long t[maxn]; int n; void add(int x, long long k) { while (x <= n) { t[x] += k; x += x & (-x); } } long long query(int x) { long long ans = 0; while (x) { ans += t[x]; x -= x & (-x); } return ans; } l...
14
#include <bits/stdc++.h> using namespace std; int main() { long long int i, j, k, l, x, mn, mx, n, s = 0, a, fg = 0, b, lo, mid, hi; string st; scanf("%lld", &n); while (n--) { s = 0; scanf("%lld %lld %lld %lld", &k, &j, &a, &b); mx = 0; k--; fg = 0; lo = 0, hi = k / a, mid = (lo + hi) /...
6
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0), cin.tie(0); int N; cin >> N; vector<int> A(N); for (int i = 0; i < N; i++) cin >> A[i]; vector<vector<int>> dp(N, vector<int>(N + 1, -1)); for (int i = 0; i < N; i++) dp[i][i + 1] = A[i]; for (int l = N - 1; l >= 0; l--)...
13
#include <bits/stdc++.h> using namespace std; struct SA { struct state { int len, link, nxt[26], c = 0; state() : len(0), link(-1) { fill(begin(nxt), end(nxt), 0); } }; vector<state> d; int last = 0; SA() { d.push_back(state()); } void add(char ch, int occ) { int cur = d.size(); d.push_back(...
16
#include <bits/stdc++.h> using namespace std; int main() { char p; string key = "qwertyuiopasdfghjkl;zxcvbnm,./", s; cin >> p; if (p == 'R') { cin >> s; for (int i = 0; i < s.size(); i++) { for (int j = 0; j < key.size(); j++) { if (s[i] == key[j]) { cout << key[j - 1]; ...
1
#include <bits/stdc++.h> using namespace std; vector<int> v[3005]; int r[3005]; int f(int a) { if (r[a] == a) return a; else return r[a] = f(r[a]); } void u(int a, int b) { a = f(a); b = f(b); if (a == b) return; r[a] = b; } vector<int> o[3005], in[3005]; vector<int> top; int st[3005]; bool ff; void...
12
#include <bits/stdc++.h> using namespace std; const int MAXN = 3000 + 14; long long a[MAXN], sorted[MAXN], dp[2][MAXN]; int main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); int n; cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; a[i] -= i; sorted[i] = a[i]; } sort(sorted + 1,...
15
#include <bits/stdc++.h> using namespace std; double eps = 1e-9; int inf = 1000000005; int mod = 1000000007; long long INFF = 1000000000000000005ll; double PI = acos(-1); void cp() {} int main() { ios_base::sync_with_stdio(0); cin.tie(0); int i, j, k; int t; cin >> t; while (t--) { long long n; cin ...
4
#include <bits/stdc++.h> using namespace std; set<int> px, py; int pp[110][2], top; int used[110]; int cur[4]; int ans[4]; double bans; double dis(int a, int b) { return sqrt(((double)((pp[a][0] - pp[b][0]) * (pp[a][0] - pp[b][0]) + (pp[a][1] - pp[b][1]) * (pp[a][1] - pp[b][1])))); } void go(i...
10
#include <bits/stdc++.h> using namespace std; int main() { int n, i, j, k, l, m, a[1000]; cin >> n; for (i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); k = 1; for (i = 1; i < n; i++) { l = i / k; if (l > a[i]) k++; } cout << k; return 0; }
6
#include <bits/stdc++.h> using namespace std; int main() { int k, n; cin >> n >> k; for (int i = 0; i < k; i++) { if (n % 10 == 0) { n /= 10; } else { n--; } } cout << n; }
0
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 1; int p_exp[N], n; bool vis[N]; int main() { scanf("%d", &n); memset(p_exp, 0, sizeof(p_exp)); memset(vis, 0, sizeof(vis)); for (int i = 2; i * i <= n; i++) { if (p_exp[i]) continue; for (int j = i * i; j <= n; j += i) { p_exp[j] =...
17
#include <bits/stdc++.h> using namespace std; const int N = 100005; long long ne[N], e[N], a[N], res[N], t[N], j; vector<long long> v[N]; pair<long long, long long> p[N]; void dfs(long long n) { for (long long first : v[n]) { if (a[first] < a[n]) res[first] = res[n] + ne[n]; else res[first] = res[...
14
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef long double ld; #define F first #define S second const int MOD = 1e9 + 7;//XXX const int C = 26;//XXX void add(int &x, int y){ x += y; while (x >= MOD) x -= MOD; while (x < 0) x += MOD; } int fix(int x)...
15
#include <bits/stdc++.h> const int N = 500005; int q[N], l, r, n; long long ans[N], top[N], now; template <typename T> void read(T& a) { a = 0; char c = getchar(); for (; c < 48 || c > 57; c = getchar()) ; for (; c > 47 && c < 58; c = getchar()) a = (a << 1) + (a << 3) + c - 48; } int main() { int mi = 1;...
11
#include <bits/stdc++.h> using namespace std; int main() { string s, t; cin >> s >> t; string q(t.length(), '#'); s = q + s; s = s + q; int n = s.length(); int m = t.length(); int ret = 0; for (int i = 0; i + m <= n; i++) { int tmp = 0; for (int j = 0; j < m; j++) { if (s[i + j] == t[j])...
9
#include <bits/stdc++.h> using namespace std; const int maxn = 210000; int n, m, maxx; int p[maxn]; map<int, vector<int> > mp; int c[maxn]; int sc[maxn]; struct soc { int id; int p; friend int operator<(const soc& a, const soc& b) { int tn = sizeof(soc) / sizeof(unsigned long long); unsigned long long* it...
13
#include <bits/stdc++.h> using namespace std; int N, M, Q; char S[45][45]; int D[45][45][45][45], E[45][45]; int dfs(int x1, int y1, int x2, int y2) { if (y1 > y2) return 0; if (D[x1][y1][x2][y2] != -1) return D[x1][y1][x2][y2]; int sum = dfs(x1, y1, x2, y2 - 1) + dfs(x1, y1 + 1, x2, y2) - dfs(x1, y1 ...
11
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf("%d", &n); for (int i = 2; i <= n; i++) printf("%d ", i); printf("1"); return 0; }
9
#include <bits/stdc++.h> using namespace std; int reduce(int *a, int n) { int i, m = 0; sort(a, a + n); for (i = 0; i < n; i++) if (!i || a[i] != a[i - 1]) a[m++] = a[i]; return m; } const int NMAX = 100000; const int QMAX = 100000; struct XD { int key, type, id; bool operator<(const XD &q) const { ...
18
#include <bits/stdc++.h> using namespace std; int main() { ios_base ::sync_with_stdio(0), cin.tie(0), cout.tie(0); ; long long cnt = 0; long long ans = 0; long long n, m = 0; string s[1005]; long long posC = 0; cin >> n; if (n % 2 == 0) { ans = n * (n / 2); } else { ans = (n * n) / 2 + 1; ...
0
#include <bits/stdc++.h> using namespace std; const int N = 1005; int n, nxt[N]; bool vis[N]; inline void read(int &X) { X = 0; char ch = 0; int op = 1; for (; ch > '9' || ch < '0'; ch = getchar()) if (ch == '-') op = -1; for (; ch >= '0' && ch <= '9'; ch = getchar()) X = (X << 3) + (X << 1) + ch - 48...
2
#include <bits/stdc++.h> using namespace std; int q; struct query { int n, k; string s; }; query x[2020]; int o[2020]; inline char r(int i) { if (i % 3 == 0) return 'R'; else if (i % 3 == 1) return 'G'; else return 'B'; } inline char g(int i) { return r(i + 1); } inline char b(int i) { return r(i ...
7
#include <bits/stdc++.h> const int O = 100005; typedef struct E { int n, v; } E; E edge[2 * O]; int Adj[O], tot; void addedge(int u, int v) { edge[tot].v = v; edge[tot].n = Adj[u]++; Adj[u] = tot++; edge[tot].v = u; edge[tot].n = Adj[v]++; Adj[v] = tot++; } int n, u, v, sum; int a[O]; int goal[O]; int vis...
5
#include <bits/stdc++.h> int dr[] = {2, 2, -2, -2, 1, -1, 1, -1}; int dc[] = {1, -1, 1, -1, 2, 2, -2, -2}; int dr1[] = {0, 0, 1, 1, 1, -1, -1, -1}; int dc1[] = {1, -1, 1, 0, -1, 0, 1, -1}; int dr2[] = {0, 0, 1, -1}; int dc2[] = {1, -1, 0, 0}; using namespace std; int main() { long long n, i, j, x, y; while (cin >> ...
3
#include <bits/stdc++.h> using namespace std; int n, m, q, w[14], k, ans[1 << 13][110], a[1 << 13], cnt[1 << 13]; char s[14]; int main() { scanf("%d%d%d", &n, &m, &q); for (int i = n; i >= 1; i--) { scanf("%d", &w[i]); } for (int i = 0; i <= 1 << n; i++) { int x = i, j = 1, sum = 0; while (x) { ...
11
#include <bits/stdc++.h> int main() { char s[1000005]; scanf("%s", s); int len = strlen(s), i, nb = 0, start = -1, end = -1; long long ans = 0, b = 0; for (i = 0; i < len; i++) { if (s[i] == 'a' && start == -1) { start = i; } if (s[i] == 'b') { end = i; } } if (start == -1 || e...
6
#include <bits/stdc++.h> using namespace std; inline long long get_num(char ch) { if (ch == '-') return 0; else if (ch >= 'a' && ch <= 'z') { return 1 + (ch - 'a'); } else if (ch >= 'A' && ch <= 'Z') { return 27 + (ch - 'A'); } else if (ch >= '0' && ch <= '9') { return 53 + (ch - '0'); } } inl...
11
#include <bits/stdc++.h> using namespace std; template <class T> void splitstr(const string &s, vector<T> &out) { istringstream in(s); out.clear(); copy(istream_iterator<T>(in), istream_iterator<T>(), back_inserter(out)); } template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; } static void redirec...
18
#include <bits/stdc++.h> using namespace std; bool vis[1000] = {}; int main() { int n; scanf("%d", &n); int a[4][10] = {}; for (int i = 0; i < n; ++i) { for (int j = 0; j < 6; ++j) { scanf("%d", &a[i][j]); } } if (n >= 1) { if (n >= 1) { for (int i = 0; i < 6; ++i) { vis[a[0]...
5
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 5; int A[maxn]; bool used[maxn]; vector<int> G[maxn]; int n, m; void dfs(int u, vector<int> &pos, vector<int> &val) { used[u] = true; pos.push_back(u); val.push_back(A[u]); for (auto v : G[u]) { if (!used[v]) { dfs(v, pos, val); ...
9
#include <bits/stdc++.h> using namespace std; const int N = 105000; const int T = 1000000; const int M = 2005000; const double mi = 1e-8; const int inf = 1987654321; int n; int cha; int a[N], b[N]; int minz[M], maxz[M]; int l, r; int cc[M]; double ans = 0.0; long long m; void getData() { int i; scanf("%d", &n); f...
19
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; int i = 0, x = -1, ans = 0; while (i < s.length()) { if (s[i] % 3 == 0) { x = i; ans++; } else { int j = i, sum = 0; while (j > x) { sum += s[j]; if (sum % 3 == 0) { j = x; ...
7
#include <bits/stdc++.h> using namespace std; int main() { int i, j, k, t, n; float a, b, ans; cin >> n; cin >> a; cin >> b; ans = (n / (a + b)) * a; cout << ans << endl; return 0; }
1
#include <bits/stdc++.h> using namespace std; int a[11000]; int b[11000]; int main() { int n; int i; int sum; while (scanf("%d", &n) != EOF) { for (i = 0; i < n; i++) { scanf("%d", &a[i]); b[i] = a[i]; } sort(a, a + n); sum = 0; for (i = 0; i < n; i++) sum += a[i]; if (sum % ...
5
#include <bits/stdc++.h> using namespace std; int numOfDivisors(long long n) { int cnt = 0; long long sq = sqrt(n); for (int i = 2; i <= sq; ++i) { if (n % i == 0) cnt += 2; } if (sq * sq == n) --cnt; return cnt; } int main() { ios::sync_with_stdio(false); cin.tie(0); int tt; cin >> tt; while ...
8
#include <bits/stdc++.h> using namespace std; void solve() { long long n; cin >> n; string s; cin >> s; bool r[10]; for (long long i = 0; i < 10; ++i) r[i] = false; for (long long i = 0; i < s.size(); ++i) { if (s[i] == 'L') { for (long long j = 0; j < 10; ++j) if (r[j] == false) { ...
0
#include <bits/stdc++.h> using namespace std; const int seed = 131; const long long LLMAX = 2e18; const int MOD = 1e9 + 7; const double eps = 1e-8; const int MAXN = 1e4 + 10; const int hmod1 = 0x48E2DCE7; const int hmod2 = 0x60000005; inline long long sqr(long long x) { return x * x; } inline int sqr(int x) { return x ...
18
#include <bits/stdc++.h> using namespace std; long long nsd(long long a, long long b) { if (b == 0) return a; else return nsd(b, a % b); } char s[1111111]; char t[1111111]; int cs[36]; int ct[36]; int main() { long long n, m; cin >> n; cin >> m; scanf(" %s %s", s, t); long long x = strlen(s); lo...
11
#include <bits/stdc++.h> int main() { int il, ir, id, iu, l, l1, l2, r, r1, r2, d, d1, d2, u, u1, u2; r1 = u1 = 1 << 30; l1 = d1 = -r1; int n; scanf("%d", &n); while (n--) { scanf("%d%d%d%d", &l, &d, &r, &u); if (l > l1) { il = n; l2 = l1; l1 = l; } else if (l > l2) l2 = ...
8
#include <bits/stdc++.h> using namespace std; void solve() { int n; cin >> n; vector<int> v(n); long long ans = 0; for (int i = 0; i < n; i++) { cin >> v[i]; if (i > 0) ans += max(0, v[i - 1] - v[i]); } cout << ans << '\n'; } int main() { ios::sync_with_stdio(false); cin.tie(0); int tt; ci...
4
#include <bits/stdc++.h> using namespace std; const int maxn = 5e5 + 10; vector<pair<int, int> > qs[maxn]; vector<int> g[maxn]; vector<int>* vec[maxn]; int cnt[maxn][26]; char val[maxn]; int sz[maxn]; int depth[maxn]; int ans[maxn]; int N, Q; void getsz(int v, int p, int d) { sz[v] = 1; depth[v] = d; for (int u :...
14
#include <bits/stdc++.h> using namespace std; const int dx[] = {-1, 0, 1, 0}; const int dy[] = {0, -1, 0, 1}; bool a[2010][2010]; int n; int kp; short x[4000010], y[4000010]; bool u[2010][2010]; int s[2010][2010]; void dfs(int cx, int cy) { x[kp] = cx; y[kp] = cy; u[cx][cy] = true; kp++; for (int q = 0; q < (...
12
#include <bits/stdc++.h> template <typename T, typename U> std::istream& operator>>(std::istream& input, std::pair<T, U>& v) { return input >> v.first >> v.second; } template <typename T> std::istream& operator>>(std::istream& input, std::vector<T>& v) { for (T& a : v) input >> a; return input; } void answer(unsi...
5
#include <bits/stdc++.h> using namespace std; template <typename T, typename C = T> struct min_cost_flow { struct edge { int src, dst; T cap, flow; C cost; int rev; }; int n; vector<vector<edge>> adj; min_cost_flow(int n) : n(n), adj(n) {} void add_edge(int src, int dst, T cap, C cost) { ...
18
#include <bits/stdc++.h> int n, x; int main() { scanf("%d%d", &n, &x); if (n == 5 && x == 5) { puts(">...v"); puts("v.<.."); puts("..^.."); puts(">...."); puts("..^.<"); puts("1 1"); } if (n == 3 && x == 2) { puts(">vv"); puts("^<."); puts("^.<"); puts("1 3"); } if (n...
17
#include <bits/stdc++.h> using namespace std; const int inf = 1e9 + 233, mod = 1e9 + 7; int n, N, x; int a[1 << 17], b[1 << 17], c[1 << 17], f[1 << 17], h[18][1 << 17], g[18][1 << 17], cnt[1 << 17]; template <typename T> inline void read(T &k) { int f = 1; k = 0; char c = getchar(); while (c < '0' || c > '9...
18
#include <bits/stdc++.h> using namespace std; int n, h, a, b, k; vector<int> ans; int dist(int, int, int, int); int abs(int); void print(); int main() { ios_base ::sync_with_stdio(false); cin.tie(0); cin >> n >> h >> a >> b >> k; for (int i = 0; i < k; i++) { int t1, f1, t2, f2; cin >> t1 >> f1 >> t2 >>...
2
#include <bits/stdc++.h> using namespace std; const int maxn = 3e5 + 3; const int maxm = 1e6 + 3; const int mod = 1e9 + 7; const int oo = 1e9 + 5; ; const long double pi = 3.141592653589793238462643383279502884; void input() { if (fopen("abc" ".inp", "r")) { freopen( "abc" ...
11
#include <bits/stdc++.h> using namespace std; long long modpow(long long base, long long exponent, long long modulus) { if (base == 0 && exponent == 0) return 0; long long result = 1; while (exponent > 0) { if (exponent % 2 == 1) result = (result * base) % modulus; exponent = exponent >> 1; base = (ba...
14
#include <bits/stdc++.h> using namespace std; int n, mas[100100], t[100100][2]; bool fl[100100]; map<int, int> mp; multiset<int> l, r; void DFS(int v) { if (v < 0) return; bool flag = true; if (l.size()) if (mas[v] > *l.begin()) flag = false; if (r.size()) if (mas[v] < *r.rbegin()) flag = false; if (f...
13
#include <bits/stdc++.h> using namespace std; template <typename T> inline T sqr(T x) { return x * x; } const double EPS = 1e-9; const int MAXN = int(1e5) + 10; int n, m; vector<int> all_x; vector<int> row_y[MAXN]; pair<int, int> pairs[MAXN]; int main() { scanf("%d%d", &n, &m); for (int i = 0; i < (int)m; i++) { ...
17
#include<bits/stdc++.h> using namespace std; int a[110]; int main(){ int t; scanf("%d",&t); while(t--){ int n; scanf("%d",&n); int mx=0x7fffffff; for(int i=1;i<=n;i++){ scanf("%d",&a[i]); mx=min(mx,a[i]); } int ans=0; int flag=1; for(int i=1;i<=n;i++){ if(i!=n){ if(a[i]!=a[i+1]){ flag...
0
#include <bits/stdc++.h> using namespace std; int a[401], n, i, j, k, p, c, t, ans = -1; int main() { cin >> n; for (i = 0; i < n; i++) cin >> a[i]; for (i = 0; i < n; i++) for (j = i; j < n; j++) { p = a[i] - 1, c = 1, t = a[j]; for (k = 0; k <= j; k++) c += p / a[k], t += p / a[k] * a[k], p %= a...
18
#include <bits/stdc++.h> int main() { int k, i, j; int a[5][5]; char temp; scanf("%d", &k); for (i = 0; i < 4; i++) { for (j = 0; j < 4; j++) { scanf("%c", &temp); if (temp == '.') { a[i][j] = -1; } else if (temp == '\n') { j--; } else { temp -= '0'; ...
1
#include <bits/stdc++.h> using namespace std; mt19937 rnd(time(0)); bool isPrime(long long a) { int i; for (i = 2; i * i <= a; i++) { if (a % i == 0) { return 0; } } return (a != 1); } bool isPalindrom(const string& s, int l, int r) { for (int i = 0; i < (r - l + 1) / 2; i++) { if (s[l + i] ...
18
#include <bits/stdc++.h> using namespace std; const long long MOD = 1000000007; const double PI = 3.1415926535897; long long tt[400400], a[400400], t[400400], p[400400], ans[400400]; void build(int v, int tl, int tr) { if (tl == tr) tt[v] = 0; else { int tm = (tl + tr) / 2; build(v * 2, tl, tm); bui...
8
#include <bits/stdc++.h> using namespace std; int n, k; vector<int> a; string s; int main() { cin >> n >> k; a.resize(n); for (int i = 0; i < n; i++) { cin >> a[i]; } cin >> s; long long ans = 0; multiset<int, greater<int> > mx; mx.insert(a[0]); for (int i = 1; i < n; i++) { if (s[i] == s[i - ...
5
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; const long long inf = mod * mod; int p[210000]; int v[210000]; int main() { int a; scanf("%d", &a); for (int i = 0; i < a; i++) { scanf("%d", p + i); p[i]--; } int ret = 0; int par = -1; int sec = -1; for (int i = 0;...
9
#include<iostream> #include<string> #include<cstring> #include<algorithm> #include<cmath> using namespace std; bool cmp(int a,int b) { return a > b; } int t; int main() { cin>>t; while(t--) { int n; int b[2000] = {-1}; int a[100] = {0}; cin>>n; for(int i = 0;i...
0
#include <bits/stdc++.h> using namespace std; const int OO = numeric_limits<int>::max() / 2; const bool debug = false; struct pt { int x, y; pt() {} pt(int x, int y) : x(x), y(y) {} pt operator+(const pt& p) const { return pt(x + p.x, y + p.y); } pt operator-(const pt& p) const { return pt(x - p.x, y - p.y); ...
18
#include <bits/stdc++.h> using namespace std; template <class X, class Y> void minimize(X &x, const Y &y) { if (x > y) x = y; } template <class X, class Y> void maximize(X &x, const Y &y) { if (x < y) x = y; } template <class T> T Abs(const T &x) { return (x < 0 ? -x : x); } long long a[1111], k; int n, numDiv, n...
18
#include <bits/stdc++.h> using namespace std; const long long int NUM = 2e5 + 5; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long int num_tests = 1; cin >> num_tests; while (num_tests-- > 0) { long long int n; cin >> n; vector<long long int> a(n); for (lo...
10
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ; int n; cin >> n; int p[n]; long long a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } memset(p, 0, sizeof(p)); p[0] = 0; p[1] = 0; int maxi = 0; for (int i = ...
3
#include <bits/stdc++.h> using namespace std; int main() { long long int n; cin >> n; string s; cin >> s; map<char, vector<long long int>> adj; for (long long int i = 0; i < n; i++) adj[s[i]].push_back(i + 1); long long int m; cin >> m; while (m--) { string t; cin >> t; long long int cnt =...
5
#include <bits/stdc++.h> using namespace std; int max(int a, int b) { return a > b ? a : b; } int min(int a, int b) { return a > b ? b : a; }; int main() { int n; cin >> n; vector<vector<int> > v(n + 2, vector<int>(n + 2, 0)); for (int i = 1; i <= n; ++i) { for (int j = 1; j <= n; ++j) { char c; ...
2
#include <bits/stdc++.h> using namespace std; int main() { int n, k, x = -1, y = -1, res = 0; cin >> n >> k; char** a = new char*[n]; for (int i = 0; i < n; i++) a[i] = new char[k]; for (int i = 0; i < n; i++) { for (int j = 0; j < k; j++) { cin >> a[i][j]; } } for (int i = 0; i < k; i++) { ...
4
#include <bits/stdc++.h> using namespace std; inline void upd(int& a, int b) { a > b ? a = b : 0; } int n, K, l[105], r[105], z, g[100005], id[100005]; struct tree { int mi[100005 << 2]; tree() { memset(mi, 0x3f, sizeof mi); } inline void modify(int x, int l, int r, int L, int R, int v) { if (l > R || l > r) ...
16
#include <bits/stdc++.h> using namespace std; int a[200005]; int ai[200005]; int shift[200005]; int b[200005]; int bi[200005]; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; int ii = 0, jj = 0; for (int i = 0; i < n; ++i) { cin >> a[i]; ai[a[i]] = i; shift[i] =...
6
#include <bits/stdc++.h> using namespace std; const int mod = 1000000007; const int N = 100004; int sz[N], c[N]; vector<pair<int, int> > qu[N]; vector<int> e[N]; int ans[N]; void dfs0(int u, int p) { sz[u] = 1; for (auto v : e[u]) if (v != p) { dfs0(v, u); sz[u] += sz[v]; } } int ft[N]; int maxn...
16
#include <bits/stdc++.h> using namespace std; int main() { long long int a{0}, b{0}, count{0}; cin >> a >> b; while (a > 0 && b > 0) { if (a > b) { long long int rem = a % b; count += (a - rem) / b; a = rem; } else { long long int rem = b % a; count += (b - rem) / a; b ...
3
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); string s; cin >> s; int i = 0; while (i < s.size()) { if (s[i] == '.') { cout << 0; } else { if (s[i + 1] == '.') { cout << 1; } else { ...
0
#include <bits/stdc++.h> using namespace std; struct vec { long long x, id; } a[2 * 100000 + 17], b[2 * 100000 + 17]; bool cmp(vec c, vec d) { return c.x < d.x; } bool cmp1(vec c, vec d) { return c.id < d.id; } int main() { int n; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i].x; a[i].id = i; } ...
5
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 7, M = 31700000; struct query { long long n, k; int id; } q[N]; int t, cnt, qs, qe, l, ans[N], vis[M], pri[M], que[N * 20]; long long p[N], f[N]; bool cmp(query a, query b) { return a.k < b.k; } long long qpow(long long a, long long b, long long mod)...
25
#include <bits/stdc++.h> using namespace std; int main() { int outa = 100005, outb = 100005, max; char a[100005], b[100005], c[100005]; scanf("%s %s %s", a, b, c); int counta[26] = {0}, countb[26] = {0}, countc[26] = {0}; for (int i = 0; a[i] != '\0'; ++i) counta[a[i] - 'a']++; for (int i = 0; b[i] != '\0';...
10
#include <bits/stdc++.h> using namespace std; const long long mod = 998244353; inline long long add(long long a, long long b) { a += b; if (a >= mod) a -= mod; return a; } inline long long sub(long long a, long long b) { a -= b; if (a < 0) a += mod; return a; } inline long long mul(long long a, long long b)...
2
#include <bits/stdc++.h> using namespace std; const string INPUT_FILE = "in.txt"; const string OUTPUT_FILE = "out.txt"; inline bool IS_UPPERCH(char C) { return C >= 'A' && C <= 'Z'; } inline bool IS_LOWERCH(char C) { return C >= 'a' && C <= 'z'; } inline bool IS_LETTERCH(char C) { return IS_UPPERCH(C) || IS_LOWERCH(C);...
6
#include <bits/stdc++.h> using namespace std; string s; map<string, int> mp; int n; void FileInit() { { freopen( "" ".inp", "r", stdin); freopen( "" ".out", "w", stdout); }; } void FileDebug() { { freopen( "" ".inp", "r", stdin); ...
1
#include <bits/stdc++.h> using namespace std; int cnt, icnt, n, k, b[10], a[10]; void rec(int step) { if (step == k + 1) { cnt++; for (int i = 1; i <= n; i++) for (int j = i + 1; j <= n; j++) if (b[i] > b[j]) icnt++; return; } else { for (int l = 1; l <= n; l++) { for (int r = l;...
10
#include <bits/stdc++.h> using namespace std; int main() { long long int n, i, j, c = 0; cin >> n; set<int> a; for (i = 0; i < n; i++) { cin >> j; a.insert(j); } if (a.count(0)) cout << a.size() - 1 << endl; else cout << a.size() << endl; }
0
#include <bits/stdc++.h> const int MAXN = 1e5 * 5; const int INF = 1e9 + 7; using namespace std; int n, h; int a[MAXN]; void add(int &a, int b) { a += b; if (a >= INF) a -= INF; } int f[2011][2011]; int duyet(int i, int c) { if (f[i][c] > -1) return f[i][c]; if (i > n) return c == 0; int ans = 0; int cur = ...
13
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int d = 3; while (1) { if ((d * d + d) / 2 > n) break; d += 1; } vector<vector<int> > v(d + 1); int m = 1; for (int i = 1; i < d; i++) { for (int k = i + 1; k <= d; k++) { v[i].push_back(m); v[k].push_bac...
8