solution
stringlengths
53
181k
difficulty
int64
0
13
#include <bits/stdc++.h> using namespace std; int n, m; long long ans = 0; long long mul = 0; long long dec(long long tmp) { tmp = tmp - 1; tmp %= 1000000009; tmp += 1000000009; tmp %= 1000000009; return tmp; } void fm(int mm) { ans = 1; while (mm--) { ans = ans << 1; if (ans >= 1000000009) ans %=...
2
#include <bits/stdc++.h> using namespace std; namespace IO { char buf[500005], *p1 = buf, *p2 = buf, out[500005], *pout = out, *eout = out + 500000; inline char nc() { return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 500000, stdin), p1 == p2) ? EOF : *p1++; } inline void...
12
#include <bits/stdc++.h> using namespace std; const int N = 150003; const long double eps = 1e-10L; template <typename T> inline void read(T &x) { int ch = getchar(); x = 0; for (; ch < '0' || ch > '9'; ch = getchar()) ; for (; ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0'; } template <typen...
10
#include <bits/stdc++.h> using namespace std; const int MAXN = 35; const int MAXL = 100005; const int CNT = 2; int bas[CNT], mod[CNT]; bool isPrime(int x) { for (int i = 2; i * i <= x; i++) if (x % i == 0) return 0; return 1; } void build() { srand(time(NULL)); int la = 128; for (int i = 0; i < CNT; i++) ...
12
#include <bits/stdc++.h> using namespace std; vector<long long int> v; long long int a[1000000]; long long int gu[2]; long long int vis[1000000]; long long int print[1000000]; void fail() { cout << "NO"; exit(0); } void dfs(long long int p) { v.push_back(p); vis[p] = 1; if (vis[a[p]] == 1) return; else ...
6
#include <bits/stdc++.h> using namespace std; const int MaxN = 100003; int n; struct Edge { int u, v, w, id; } e[MaxN]; int dep[MaxN]; vector<int> g[MaxN]; void dfs(int x, int from) { dep[x] = dep[from] + 1; for (int i : g[x]) if (i != from) dfs(i, x); } inline bool cmp(const Edge& a, const Edge& b) { retur...
7
#include <bits/stdc++.h> using namespace std; float fast_exp(float n, int p) { float ret = 1; while (p) { if (p & 1) ret *= n; n *= n; p >>= 1; } return ret; } int main() { ios_base::sync_with_stdio(false); int n, m; scanf("%d %d", &m, &n); float ans = 0; for (float i = 1; i < m; i++) { ...
4
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int i, j, f; vector<pair<int, int> > po, ng; for (i = 0; i < n; i++) { int x, a; cin >> x >> a; if (x > 0) { po.push_back(make_pair(x, a)); } else { ng.push_back(make_pair((x * (-1)), a)); } } sort(...
1
#include <bits/stdc++.h> int n, type, fq[3]; int main() { scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", &type); fq[type]++; } if (fq[1] && fq[2]) { fq[1]--; fq[2]--; printf("2 1 "); } while (fq[2]--) printf("2 "); while (fq[1]--) printf("1 "); return 0; }
2
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; const int mxN = 1e6 + 1; int main() { int n, cb; cin >> n >> cb; int c[n]; for (int(i) = 0; (i) < (n); (i)++) cin >> c[i]; int usable[mxN]; int cnt[mxN] = {0}; fill_n(usable, mxN, 1); usable[cb] = 0; for (int(i) = 0; (i) < (n); (i)...
4
#include <bits/stdc++.h> using namespace std; string s, t; const int maxn = 5005; const int mod = 1000000007; int pre[maxn], now[maxn]; int main() { while (cin >> s >> t) { int i, j, k; memset(pre, 0, sizeof(pre)); memset(now, 0, sizeof(now)); for (i = 0; i < t.size(); i++) { for (j = 0; j < s.s...
4
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10; const int mod = 1e9 + 7; const long long inf = 1e17; char a[maxn], b[maxn], s[maxn]; int v[200]; int main() { int q; scanf("%s%s", a, b); int n = strlen(a); for (int i = 0; i < n; ++i) v[a[i]] = 1; n = strlen(b); scanf("%d", &q); whi...
4
#include <bits/stdc++.h> using namespace std; const long long inf = INT_MAX, df = 1e5 + 7, mod = 1e9 + 7; struct edge { long long to, nxt; } e[df << 2]; long long i, j, k, l, m, n, o = 1, p, q, r, s, t, u, v, w, x, y, z; long long fa[df], dfn[df], pos[df], head[df], son[df], siz[df], top[df], cnt, dp[df][305], a[...
8
#include <bits/stdc++.h> using namespace std; const long long INF = 1e9; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t; cin >> t; int x = t / 2; cout << x << endl; if (t % 2 != 0) { x--; while (x--) cout << 2 << " "; cout << 3 << endl; } else { while (x--) cout << 2...
0
#include <bits/stdc++.h> using namespace std; int main(int argc, char** argv) { unsigned long long p, k, q0, q1; cin >> p >> k; unsigned long long t = 0; queue<unsigned long long> ansq; q0 = p; while (true) { if (!t) { q1 = q0 / k; ansq.push(q0 - q1 * k); } else { q1 = q0 / k + (q0...
6
#include <bits/stdc++.h> using namespace std; struct segt { double value, lz; }; segt tree[262192]; map<int, int> mp; vector<int> disc; void build(int l, int r, int index) { if (l > r) return; tree[index].value = 1.0 * (double)mp[disc[l]]; tree[index].lz = 1.0; if (l == r) return; int mid = l + (r - l) / 2;...
7
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using ii = pair<ll, ll>; using vi = vector<ll>; using vb = vector<bool>; using vvi = vector<vi>; using vii = vector<ii>; using vvii = vector<vii>; const int INF = 2000000000; const ll LLINF = 9000000000000000000; template <class...
4
#include <bits/stdc++.h> using namespace std; signed main() { long long int t, a, b; cin >> t; while (t--) { cin >> a >> b; long long int diff = abs(a - b); for (long long int i = 0;; i++) { long long int h = (i * (i + 1) / 2) - diff; if (h >= 0 && !(h % 2)) { cout << i << "\n"; ...
3
#include <bits/stdc++.h> using namespace std; const int MAX = 1e5 + 10; const int inf = 2e9 + 10; const int mod = 1e9 + 7; const double eps = 1e-15; int n, m, k; pair<long long, long long> p[1111]; long long x[1111], y[1111], r[1111]; bitset<1001> po[1001]; int to[1001][1001]; bool incp(int a, int b) { return (p[a].f...
6
#include <bits/stdc++.h> using namespace std; struct pt { long long x, y; pt operator-(pt a) { return {x - a.x, y - a.y}; } void read() { cin >> x >> y; } }; long long cross(pt a, pt b) { return a.x * b.y - b.x * a.y; } vector<pt> v; bool sol(pt a, pt b) { vector<pt> vv; for (auto u : v) { if (cross(b - a...
6
#include <bits/stdc++.h> using namespace std; int main() { unsigned long long a; cin >> a; unsigned long long m = a, t = 1; int k = 1; while (m) { k++; m /= 10; t *= 10; } m = 45 * (k - 1); k = k - 2; while (k || m >= a) { if (m >= a) m -= a; else { k--; m *= 10; ...
8
#include <bits/stdc++.h> using namespace std; int a[1005], b[1005], n; int main() { int k = 0, v = 0; std::cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; k += a[i]; } for (int i = 0; i < n; i++) { cin >> b[i]; v += b[i]; } if (k >= v) std::cout << "YES" << std::endl; else s...
0
#include <bits/stdc++.h> using namespace std; int cansel_sync = (ios::sync_with_stdio(0), cin.tie(0), 0); const long long INF = 1ll << 60; const int MAXN = 114514; int n; long long d; long long a[MAXN]; void solve() { cin >> n >> d; for (int i = (1); i <= (n); i++) cin >> a[i]; a[0] = -INF; a[n + 1] = INF; in...
0
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5, inf = 1e9 + 7; int n, k; const int MAXN = 2010; int CINF = 1e9; int INF = 1e9; struct graph { struct Edge { int x, y; int cap; int cost; int id; }; int N, prev[MAXN]; int dist[MAXN], phi[MAXN]; vector<Edge> E; vector<int> g...
8
#include <bits/stdc++.h> using namespace std; long long arr[300000]; long long a[300000]; long long freq[300000]; long long up[200000][3]; long long q[200000][2]; int main() { int n, m, k; cin >> n >> m >> k; int i; for (i = 1; i <= n; i++) { cin >> arr[i]; } memset(freq, 0, sizeof(freq)); for (i = 1;...
3
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; const int N = 2e5 + 5; template <typename T> inline istream& operator>>(istream& is, vector<T>& v) { for (int ii = 0; ii < (int)v.size(); ++ii) { is >> v[ii]; } return is; } template <typename T> inline ostream& operator<<(ostream& os, vec...
6
#include <bits/stdc++.h> using namespace std; const int maxN = 2e5 + 10; int n, q; int a[maxN]; long long t[4 * maxN]; int mn[4 * maxN]; int cnt[4 * maxN]; int lazy[4 * maxN]; int mx[4 * maxN]; void merge(int v) { mn[v] = min(mn[2 * v], mn[2 * v + 1]); mx[v] = max(mx[2 * v], mx[2 * v + 1]); t[v] = t[2 * v] + t[2 ...
9
#include <bits/stdc++.h> using namespace std; template <class TT> TT abs(TT a) { if (a < 0) return -a; return a; } template <class ZZ> ZZ max(ZZ a, ZZ b, ZZ c) { return max(a, max(b, c)); } template <class ZZ> ZZ min(ZZ a, ZZ b, ZZ c) { return min(a, min(b, c)); } typedef struct { double x, y, z; void scan(...
6
#include<bits/stdc++.h> using namespace std; #define rep(i,n) for (int i=0;i<(int)(n);++i) #define rep1(i,n) for (int i=1;i<=(int)(n);++i) typedef long long ll; namespace internal { int ceil_pow2(int n) { int x = 0; while ((1U << x) < (unsigned int)(n)) x++; return x; } } template <class S, S (*op)(S, S), S (*e)()> str...
12
#include <bits/stdc++.h> using namespace std; int it[1000001]; int dp[1000001][2]; pair<int, int> ba[1000001][2]; int ma[2]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t; cin >> t; while (t--) { int n; cin >> n; int st = 1; ma[0] = -1; ma[1] = 1; for (int i = 0; ...
10
#include <bits/stdc++.h> using namespace std; const int N = 252; const int M = 26; char s[N][N]; int pre[N][N][M]; bool isRowPalindrome(int l, int r, int row) { int odd = 0; for (int i = 0; i < M; ++i) { int cc = pre[row][r][i] - pre[row][l - 1][i]; if (cc & 1) { ++odd; } if (odd > 1) { ...
8
#include <bits/stdc++.h> using namespace std; void showvector(vector<long long int> v) { for (long long int x : v) cout << x << " "; cout << endl; } bool comp(pair<long long int, long long int> a, pair<long long int, long long int> b) { return (a.first > b.first); } void fun() { long long int n; whi...
0
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 50; const int inf = 0x3f3f3f3f; const int MOD = 1e9 + 7; int dfs(long long a, long long b) { if (a > b) swap(a, b); if (a == 0) return 0; if (b % a == 0 || !dfs(b % a, a) || (b / a) % (a + 1) % 2 == 0) return 1; return 0; } int main() { int ...
7
#include <bits/stdc++.h> using namespace std; int main() { int i, j, n, a, b; int chairs[100][100] = {0}; int count = 1; cin >> n >> a >> b; if (n > a * b) { cout << -1; } else { for (i = 0; i < a; i++) { if (b % 2 == 1 || i % 2 == 0) for (j = 0; j < b; j++) { chairs[i][j] = ...
1
#include <bits/stdc++.h> using namespace std; const int P = 1000 * 1000 * 1000 + 7, N = 50 + 5; long long n, dp[3 * N + 1][N][N], cnt[2], c[N][N], k, ans = 1; void com() { for (int i = 0; i < N; i++) c[i][0] = 1; for (int i = 1; i < N; i++) for (int j = 1; j <= i; j++) c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) ...
6
#include <bits/stdc++.h> using namespace std; void printvector(std::vector<long long> v) { for (long long i = 0; i < v.size(); ++i) { cout << v[i] << " "; } cout << "" << endl; } void printarray(long long a[], long long n) { for (long long i = 0; i < n; ++i) { cout << a[i] << " "; } cout << "" << en...
6
#include <bits/stdc++.h> using namespace std; long long int ansL1, ansB1, ansL2, ansB2; struct node { long long int a, b, c, d; int cnt; node() {} node(long long int A, long long int B, long long int C, long long int D, int count) { a = A, b = B, c = C, d = D, cnt = count; } }; map<pair<long long i...
5
#include <bits/stdc++.h> using namespace std; const int N = 25; int ans_top, n, m, a[N][N]; vector<int> ans[100005]; pair<int, int> p[N * N]; void SWP(int x, int y) { swap(p[x], p[y]); swap(a[p[x].first][p[x].second], a[p[y].first][p[y].second]); } void insert(vector<int> v) { ans[++ans_top] = v; for (int i = (...
11
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const long long LINF = 0x3f3f3f3f3f3f3f3fll; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int t; cin >> t; while (t--) { int n; cin >> n; int A[2][2] = {{0, 0}, {0, 0}}; vector<int> X[2][2]; vector<string> ...
5
#include <bits/stdc++.h> using namespace std; const int mod = 1000003; long double pi = 3.1415926536; const int mx = 1000003; long long gcd(long long x, long long y) { if (y == 0) return x; return gcd(y, x % y); } long long bp(long long a, long long b) { long long ans = 1; while (b > 0) { if (b & 1) ans = (...
2
#include <bits/stdc++.h> const int N = 1005; int v[N], w[N], dp[N] = {0}; int main() { int i, j, V = 0, n; scanf("%d", &n); for (i = 0; i < n; i++) { scanf("%d%d", &w[i], &v[i]); V += w[i]; } for (i = 1; i <= V; i++) dp[i] = V; for (i = 0; i < n; i++) for (j = V; j >= w[i]; j--) dp[j] = (d...
4
#include <bits/stdc++.h> using namespace std; int main() { int n, m, b, g, x, y; bool women[100], man[100]; cin >> n >> m; cin >> b; for (int i = 0; i < n; i++) man[i] = 0; for (int i = 0; i < m; i++) women[i] = 0; for (int i = 0; i < b; i++) { cin >> x; man[x] = 1; } cin >> g; for (int i = ...
2
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1.0); const int MOD = 1000 * 1000 * 1000 + 7; const int MAX = 100017; int n, m, k; int x, y; long long gcd(long long a, long long b, long long& x, long long& y) { if (a == 0) { x = 0; y = 1; return b; } long long x1, frgrwegreg; l...
5
#include <bits/stdc++.h> using ll = long long; using ld = long double; using ull = unsigned long long; using namespace std; struct nodes { int mx[103], mn[103], cnt; } node[20002]; const int INF = 1e9 + 9; int p, m, t = 0; string E; bool flag = 1; stack<int> pos; int main() { ios_base::sync_with_stdio(false); cin...
7
#include <bits/stdc++.h> using namespace std; int main() { int n; bool check = false; cin >> n; int arr[n]; for (int i = 0; i < n; i++) { cin >> arr[i]; } for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { if (arr[i] == arr[j]) { arr[j] = 0; } } } sort(arr,...
0
#include <bits/stdc++.h> using namespace std; int n, m; const int N = 203600; vector<int> g[N]; set<int> brg[N]; bool vis[N], ap[N]; int low[N], bt[N], lv; void dfs(int u, int fr) { vis[u] = 1; bt[u] = low[u] = lv++; int nChild = 0; for (int j = (0); j < (int)(g[u].size()); j++) { int i = g[u][j]; if (!...
4
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); int n, s; cin >> n >> s; s--; vector<int> v(n); for (int i = 0; i < n; i++) cin >> v[i]; int mx = 0; int ans = 0; if (v[s] != 0) { v[s] = 0; ans++; } if (n == 1) { cout << ans << endl; return 0...
5
#include <bits/stdc++.h> using namespace std; const int MaxN = 2241; char a[MaxN][MaxN]; int n, display[MaxN][MaxN]; bool propagetDown[MaxN][MaxN], propagateLeft[MaxN][MaxN]; bool propagateUp[MaxN][MaxN], propagateRight[MaxN][MaxN]; int main() { cin.sync_with_stdio(0); cin >> n; for (int i = 1; i <= n; i++) f...
6
#include <bits/stdc++.h> using namespace std; using pii = pair<int, int>; using ll = long long; using llu = long long unsigned; using ld = long double; const ld EPS = 1e-9; inline int cmp(ld first, ld second = 0, ld tol = EPS) { return (first <= second + tol) ? (first + tol < second) ? -1 : 0 : 1; } const int MOD = 1...
2
#include <bits/stdc++.h> using namespace std; struct P { int x; int y; }; int dx[4] = {0, 1, 0, -1}; int dy[4] = {1, 0, -1, 0}; bool visit[1005][1005]; bool grid[1005][1005]; int n, m; int sx, sy; int allarea = 0; vector<P> l, r; void bfs(int sx, int sy) { int countt = 0; P sp; sp.x = sx, sp.y = sy; queue<P...
6
#include <bits/stdc++.h> using namespace std; void task(); int main() { srand(time(0)); task(); return 0; } const int N = 1e5 + 10; char buf[N]; string s, rs; string t; vector<int> z_func(string s) { int n = s.length(); vector<int> z(n, 0); int l = 0, r = 0; for (int i = 1; i < n; ++i) { if (r >= i) z...
7
#include <bits/stdc++.h> using namespace std; int num[10005]; int w, m; int main() { while (scanf("%d%d", &w, &m) != EOF) { int cnt = 0; bool flag = false; memset(num, 0, sizeof(num)); while (m) { num[cnt++] = m % w; m /= w; } for (int i = 0; i < cnt; i++) { if (num[i] == 0 |...
5
#include <bits/stdc++.h> using namespace std; const int N = 100000 + 10; int n; vector<pair<int, int> > q; int ans[N]; vector<int> pool[N], mem[N]; inline int read() { int x = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch ...
11
#include <bits/stdc++.h> using namespace std; int a[100010]; int main() { int n; scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d", &a[i]); sort(a + 1, a + 1 + n); if (a[n] >= a[n - 1] + a[n - 2]) printf("NO"); else { printf("YES\n"); for (int i = 1; i < n - 1; i++) printf("%d ", a[i]); ...
1
#include <bits/stdc++.h> const int kMaxn = 1010, kMaxw = 1010; int n, m, w, id, a[kMaxn], b[kMaxn], v[kMaxn], dp[2][kMaxw], ans, aa, bb; class Edge { public: int v; Edge *next; Edge(int V, Edge *ne) : v(V), next(ne) {} } * g[kMaxn]; void add(int x, int y) { g[x] = new Edge(y, g[x]); g[y] = new Edge(x, g[y]);...
4
#include <bits/stdc++.h> using namespace std; const int N = (int)2e5 + 5; const int offset = (int)1e5 + 1; unordered_map<string, int> m; int parent[N]; int find_parent(int v) { if (v != parent[v]) { parent[v] = find_parent(parent[v]); } return parent[v]; } void disjoint_set_union(int u, int v) { parent[find...
6
#include <bits/stdc++.h> using namespace std; const int inf = 2e9; const long long INF = 8e18; const int maxn = 3e3 + 5; int n, m; int a[maxn], sz[maxn]; pair<int, long long> dp[maxn][maxn], dpp[maxn][maxn]; vector<int> e[maxn]; inline void init() { for (int i = 0; i < n + 5; ++i) e[i].clear(); } inline void dfs(int ...
8
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; int lft = 0; int a; for (int i = 1; i <= n; ++i) { cin >> a; lft += a; if (lft >= 8) { k -= 8; lft -= 8; } else { k -= lft; lft = 0; } if (k <= 0) { cout << i << endl; ...
0
#include <bits/stdc++.h> using namespace std; int main() { int n, i, j, line[35], column[35], var, count; cin >> n; for (i = 1; i <= n; ++i) line[i] = column[i] = 0; for (i = 1; i <= n; ++i) for (j = 1; j <= n; ++j) { cin >> var; line[i] += var; column[j] += var; } count = 0; for (...
0
#include <bits/stdc++.h> using namespace std; bool sortbysec(const pair<long long, long long> &a, const pair<long long, long long> &b) { return (a.second < b.second); } int main() { vector<pair<long long, long long>> v; int n, f[26] = {}, i, t; cin >> n; char h1 = 'n', h2 = 'z'; string s; c...
0
#include <bits/stdc++.h> using namespace std; long long f(int a, int b) { while (a != 0 && b != 0) { if (a > b) a %= b; else b %= a; } return a + b; } long long a, b, k; int main() { cin >> a >> b; k = 7 - max(a, b); cout << k / f(k, 6) << "/" << 6 / f(k, 6); }
0
#include <bits/stdc++.h> using namespace std; int arr[1024 * 1024]; int main() { int n, maxv = 0, pos; scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d", &arr[i]); if (arr[i] > maxv) { maxv = arr[i]; pos = i; } } bool flag = true; for (int i = pos + 1; i <= n; i++) { if ...
1
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int t; cin >> t; while (t--) { int n, x, num; cin >> n >> x; vector<int> cnt(1000, 0); for (__typeof(0) i = (0); i < (n); i++) { cin >> num; cnt[num]++; } int i = 1; ...
0
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); string s, p; cin >> s >> p; long l = s.size(); s += "#"; p += "#"; long x = 0, y = 0; for (long i = 0; i < l; i++) { if (s[i] != p[i]) { if (s[i] == '4') x++; else ...
2
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e5 + 51; mt19937 mt(20050103); int n, st, x, v, nxt, c, vx, nxtx; inline int read() { register int num = 0, neg = 1; register char ch = getchar(); while (!isdigit(ch) && ch != '-') { ch = getchar(); } if (ch == '-') { neg = -1; ch = g...
6
#include <bits/stdc++.h> using namespace std; const int maxn = 200100, mod = 998244353; inline int ksm(int a, int b) { int res = 1; for (; b; b >>= 1, a = 1ll * a * a % mod) if (b & 1) res = 1ll * res * a % mod; return res; } int f[maxn], g[maxn], n, k; vector<int> v[2]; inline int check(const vector<int> &v)...
7
#include <bits/stdc++.h> using namespace std; const long long MAX_N = 1e5 + 5; long long n, k, ans; long long Arr[MAX_N]; long long Brr[MAX_N]; long long fenL[MAX_N], fenR[MAX_N]; long long getL(long long tmp) { long long res = 0; for (; tmp; tmp -= tmp & -tmp) res += fenL[tmp]; return res; } long long getR(long ...
8
#include <bits/stdc++.h> using namespace std; int main() { bool a[51][51]; int r, c; cin >> r >> c; getchar(); for (int i = (0); i < (r); i++) { for (int j = (0); j < (c); j++) { char a1 = getchar(); if (a1 == 'W') a[i][j] = 1; else a[i][j] = 0; } getchar(); } ...
4
#include <bits/stdc++.h> using namespace std; int32_t main() { ios::sync_with_stdio(false); cin.tie(0); long long n, x; cin >> n; bool down = true; for (long long i = 0; i < n; i++) { cin >> x; if (x % 2 == 0) { cout << x / 2 << '\n'; } else { if (down) { if (x < 0) ...
1
#include <bits/stdc++.h> int fa[200010], ch[200010][26], len[200010], cnt = 1, las = 1; int ls[200010 * 40], rs[200010 * 40], ntot, n; int nxt[200010 << 1], to[200010 << 1], head[200010], rcnt; int root[200010]; void insert(int &u, int l, int r, int p) { if (!u) u = ++ntot; if (l == r) return; int mid = (l + r) >...
12
#include <bits/stdc++.h> using namespace std; string s; int n, i, kol, ans; int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n; getline(cin, s); getline(cin, s); for (i = 0; i < n; i++) { if (isupper(s[i])) kol++; else if (s[i] == ' ') kol = 0; ans = max(ans, kol); } cout...
0
#include <bits/stdc++.h> using namespace std; const int INF = 1e9 + 7; int N, M; string s; int main(void) { cin >> N >> M >> s; int cnt = 0; for (int i = 0; i < (int)(N - 1); ++i) if (s[i] == '.' and s[i + 1] == '.') cnt++; for (int mmm = 0; mmm < (int)(M); ++mmm) { int i; char c; cin >> i >> c;...
4
#include <bits/stdc++.h> using namespace std; map<int, int> num; set<int> score; int main() { int tc, n, g, s, b, solve[400005]; cin >> tc; while (tc--) { cin >> n; g = s = b = 0; for (int i = 1; i <= n; i++) cin >> solve[i], num[solve[i]]++, score.insert(-1 * solve[i]); for (auto i = score....
3
#include <bits/stdc++.h> #pragma GCC optimize "O3" using namespace std; const char E = '\n'; int main() { cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0); int n; cin >> n; string s; cin >> s; int mx = 1; for (int i = 1; i < n; i += 2) { string s1 = ""; string s2 = ""; for (int j = 0;...
3
#include <bits/stdc++.h> using namespace std; int Set(int N, int pos) { return N = N | (1 << pos); } int reset(int N, int pos) { return N = N & ~(1 << pos); } bool check(int N, int pos) { return (bool)(N & (1 << pos)); } int main() { map<pair<int, int>, pair<int, int> > ob; int n; scanf("%d", &n); double r1 = -...
4
#include <bits/stdc++.h> using namespace std; const long double PI = acos(-1); int d1[4][2] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}}; int d2[8][2] = {{1, 0}, {0, 1}, {0, -1}, {-1, 0}, {1, 1}, {-1, 1}, {1, -1}, {-1, -1}}; long long cnt(long long a, long long b, long long c) { long long mx = max((a), max((...
2
#include <bits/stdc++.h> using namespace std; template <class T> void show(T a, int n) { for (int i = 0; i < n; ++i) cout << a[i] << ' '; cout << endl; } template <class T> void show(T a, int r, int l) { for (int i = 0; i < r; ++i) show(a[i], l); cout << endl; } const int N = 120000; const int M = 120000; const...
7
#include <bits/stdc++.h> using namespace std; const int MAX = 1e6 + 6; int t, n; vector<int> v(MAX); vector<bool> check(MAX); void file_io(char *input, char *output) { freopen(input, "r", stdin); freopen(output, "w", stdout); } void fast_io() { ios::sync_with_stdio(false); cin.tie(0); } void input() { cin >> ...
4
#pragma GCC optimize ("O3") #pragma GCC target ("sse4") #include <bits/stdc++.h> #include <ext/pb_ds/tree_policy.hpp> #include <ext/pb_ds/assoc_container.hpp> #include <ext/rope> using namespace std; using namespace __gnu_pbds; using namespace __gnu_cxx; typedef long long ll; typedef long double ld; typedef complex...
12
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); long long int n; unsigned long long int ar; cin >> n >> ar; ar % n == 0 ? cout << ar / n : cout << ar / n + 1; return 0; }
1
#include <bits/stdc++.h> using namespace std; using ll = long long; using db = long double; using str = string; using pi = pair<int, int>; using pl = pair<ll, ll>; using pd = pair<db, db>; template <class T> using V = vector<T>; template <class T, size_t SZ> using AR = array<T, SZ>; template <class T> using PR = pair<T...
5
#include <bits/stdc++.h> using namespace std; bool isprime(int n) { if (n < 2) return false; if (n == 2) return true; for (int i = 2; i <= sqrt(n); i++) if (n % i == 0) return false; return true; } int main() { ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); double d, l, v1, v2; cin >> d >> l >>...
0
#include <bits/stdc++.h> using namespace std; long long m, w; int bi[1000]; int pos = 0; int main() { cin >> w >> m; while (m) { bi[++pos] = m % w; m /= w; } for (int i = 1; i <= pos; i++) { if (bi[i] != 1 && bi[i] != w && bi[i] != w - 1 && bi[i] != 0) { cout << "NO"; return 0; } ...
5
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int t; cin >> t; vector<long long> v; v.push_back(2); for (int i = 2;; ++i) { long long ans = v.back() + 3 * (i - 1) + 2; v.push_back(ans); if (ans > 1e9) break; } while (t--) { long lo...
1
#include <bits/stdc++.h> using namespace std; void solve() { int N; cin >> N; vector<int> T(N), H(N); for (int i = 0; i < N; i++) { cin >> T[i]; } for (int i = 0; i < N; i++) { cin >> H[i]; } long long ans = 0; vector<vector<int>> adj(N); vector<int> in(N), out(N); for (int i = 0; i < N - ...
10
#include <bits/stdc++.h> using namespace std; struct node { int l, r; } sl[100005], sr[100005]; bool cmpl(node x, node y) { return x.l < y.l; } bool cmpr(node x, node y) { return x.r < y.r; } int n, m, a[100005], nowl, nowr, d[100005], lzy[600005]; bool mark[600005]; void doit(int ind, int l, int r) { mark[ind] ^= ...
10
#include <bits/stdc++.h> using namespace std; const int maxn = 2 * 100005; bool vis[maxn], par[maxn]; vector<int> edge[maxn]; pair<int, int> seg[maxn]; int n; void add(int a, int b) { edge[a].push_back(b), edge[b].push_back(a); } void dfs(int x, int cur) { if (vis[x]) return; vis[x] = true; par[x] = cur; for (i...
11
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 7; const int inf = 1e9 + 7; const long double eps = 1e-6; int gcd(int a, int b) { if (b == 0) { return a; } return gcd(b, a % b); } signed main() { int m; cin >> m; vector<int> s(m); for (auto(i) = (0); (i) < (m); ++i) cin >> s[i]; ...
5
#include <bits/stdc++.h> using ll = long long; const ll MOD = 998244353; const int INF = (ll)1e9 + 7; const ll INFLL = (ll)1e18; using namespace std; template <class t> using vvector = vector<vector<t>>; template <class t> using vvvector = vector<vector<vector<t>>>; template <class t> using priority_queuer = priority_q...
8
#include <bits/stdc++.h> using namespace std; int main() { int n = 0, k = 0; cin >> n >> k; vector<int> p(n); for (int i = 0; i < n; i++) { cin >> p[i]; } vector<int> c(256); vector<bool> used(256, false); for (int i = 0; i < 256; i++) { c[i] = i; } vector<int> ans(n, 0); for (int i = 0; i...
4
#include <bits/stdc++.h> using namespace std; const int maxn = 5005; const int maxl = 105; double dp[maxn][maxn]; int n, tot; int t[maxn]; int p[maxn]; double ans; int main() { cin >> n >> tot; for (int i = 1; i <= n; i++) { cin >> p[i] >> t[i]; } dp[0][0] = 1; for (int i = 1; i <= n; i++) { double no...
8
#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 read_value(string s) { T result; istringstream sin(s); sin >> r...
8
#include <bits/stdc++.h> using namespace std; string str; int main() { int N; cin >> N; cin >> str; int ans = 0; for (int i = 0; i < N; ++i) if (str[i] == '<') ++ans; else break; for (int i = N - 1; i >= 0; --i) if (str[i] == '>') ++ans; else break; cout << ans << '...
1
#include <bits/stdc++.h> using namespace std; bool debug = false; int n, m, k; int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1}; long long ln, lk, lm; int a[10]; bool v[9], vv[9]; bool walk(int x) { v[x] = 1; if (a[x] == 1 || vv[a[x]]) return vv[x] = 1; if (v[a[x]]) return 0; return vv[x] = walk(a[x]); } bool c...
3
#include <bits/stdc++.h> int main() { int n; scanf("%d", &n); std::vector<double> q(n); for (int i = 0; i < n; ++i) { int p; scanf("%d", &p); q[i] = 1. - p / 100.; } if (n == 1) { puts("1"); } else { std::vector<double> pw(n); for (int i = 0; i < n; ++i) { pw[i] = q[i]; }...
9
#include <bits/stdc++.h> using namespace std; long long int a[1000009]; int main() { long long int n, d, j = 1, num = 0; scanf("%I64d %I64d", &n, &d); for (int i = 1; i <= n; i++) { scanf("%I64d", &a[i]); } for (int i = 1; i <= n; i++) { while (a[i] - a[j] > d && j <= n) { j++; } num += ...
2
#include <bits/stdc++.h> using namespace std; void P1(int n, char A[]) { for (int i = 0; i < n; i++) { int x = A[i] - '0' + 1; if (x == 10) A[i] = '0'; else A[i] = x + '0'; } return; } void P2(int n, char A[]) { char aux[1001] = {}; aux[0] = A[0]; strcpy(A, A + 1); A[n - 1] = aux[0...
3
#include <bits/stdc++.h> using namespace std; const long long N = 500010; long long n, k; long long dp[N][2]; vector<pair<long long, long long>> g[N]; void dfs(long long v, long long p) { vector<pair<long long, long long>> s; for (auto [w, u] : g[v]) { if (u != p) { dfs(u, v); s.emplace_back(dp[u][1...
6
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 10; int n, par[maxn], fen[maxn]; map<char, int> vowel; int get(int val, int idx) { int now = 0; for (int i = 20; i >= 0; i--) { if (now + (1 << i) > n + 1) continue; if (val < fen[now + (1 << i)]) now += (1 << i); } return idx - now; }...
6
#include <bits/stdc++.h> using namespace std; int s[1000005]; int n, m; int main() { int i, j, k, t1, t2, t3; long long l1, l2, l3; while (scanf("%d%d", &n, &m) != EOF) { memset(s, 0, sizeof(s)); for (i = 0; i != m; ++i) { scanf("%d%d", &t1, &t2); ++s[t1]; ++s[t2]; } l1 = 0; ...
5