solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; for (int k = 0; k < t; k++) { int n; cin >> n; string s; cin >> s; int cnt = 0; for (int i = 0; i < n; ++i) { cnt += s[i] != '?' ? 1 : 0; } if (cnt == 0) s[0] = 'R'; for (int i = 1; i < n; ++i) { ...
1
#include <bits/stdc++.h> const long long N = 1e6 + 5; const long long M = 2e6 + 5; const long long P = 1e9 + 7; long long n, m, cnt; std::vector<long long> E[N][10], Q[N]; long long dis[N], g[N]; long long digit[N], tot; void add_edge(long long u, long long v, long long dis) { tot = 0; while (dis) digit[++tot] = di...
18
#include <bits/stdc++.h> using namespace std; const int sz = 1e5 + 1; int n; int s[sz]; vector<int> prime; void sieve() { for (int i = 2; i <= n; i++) { if (s[i] == 0) { prime.push_back(i); for (int j = i; j <= n; j += i) s[j] = i; } } } int ask(int type, int x) { if (type == 0) cout << "A...
18
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); long long a, b, k = 0; cin >> a >> b; long long c = a * 100 + (b * 10); while (a * 100 + (b * 10) > 219 && b > 1) { if (k % 2 == 0) { long long o = 0; if (a < 1) { b = b - 22; } else...
4
#include <bits/stdc++.h> using namespace std; const int N = 3 * 1e5 + 10; vector<int> adj[N]; long long pt[N], f[N]; long long M = -1e18, cnt; void dfs(int u, int pr) { f[u] = pt[u]; for (auto v : adj[u]) { if (v != pr) { dfs(v, u); f[u] += max(0LL, f[v]); } } } long long update_dfs(int u, int...
16
#include <bits/stdc++.h> using namespace std; int n; const int INF = 1e9 + 7; vector<int> tree; void update(int idx, int l, int r, int pos) { if (l == r) { tree[idx] = 1; return; } int m = (l + r) / 2; if (pos <= m) update(2 * idx, l, m, pos); else update(2 * idx + 1, m + 1, r, pos); tree[id...
10
#include <bits/stdc++.h> #pragma GCC optimize(3) using namespace std; long long n, k, a[200005]; map<long long, long long> mp; int main() { scanf("%lld%lld", &n, &k); for (long long i = 1; i <= n; i++) scanf("%lld", &a[i]); for (long long i = 1; i <= n; i++) a[i] = a[i] ^ a[i - 1]; for (long long i = 0; i <= n;...
11
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; const ld EPS = 1e-12, PI = acos(-1); inline bool eq(ld a, ld b) { return fabs(a - b) < EPS; } inline bool lt(ld a, ld b) { return a + EPS < b; } inline bool le(ld a, ld b) { return a < b + EPS; } inline int sign(ld x) { return e...
19
#include <bits/stdc++.h> using namespace std; int main() { int n, t, pos, neg; bool flag; cin >> t; while (t--) { cin >> n; vector<long long> a(n), b(n); pos = n + 1; neg = n + 1; flag = true; for (int i = 0; i < n; ++i) { cin >> a[i]; if (a[i] == 1 && pos == n + 1) pos = i; ...
3
#include <bits/stdc++.h> using namespace std; inline int read() { int x = 0, f = 1; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == '-') f = -1; for (; isdigit(c); c = getchar()) x = x * 10 + c - '0'; return x * f; } const int MAXN = 100010; int a[MAXN + 1], Sum[MAXN + 1]; int main() { i...
5
#include <bits/stdc++.h> using namespace std; using ll = long long; using PII = pair<int, int>; const int mod = 998244353; const int inf = 1 << 30; const int maxn = 500000 + 5; int n, m, q, a[maxn], qx[maxn]; int from[maxn], to[maxn]; bool op[maxn], del[maxn]; int pre[maxn], siz[maxn]; int find(int x) { return x == pre...
18
#include <bits/stdc++.h> using namespace std; int main() { cout << "Red\n"; return 0; }
10
#include <bits/stdc++.h> using namespace std; int main() { int n, x, y; scanf("%d %d %d", &n, &x, &y); int roz = n * 3; long long tab[roz + 1]; for (int i = 0; i < roz; i++) tab[i] = LLONG_MAX; tab[1] = x; for (int z = 0; z < 6; z++) { for (int i = 1; i < roz; i++) { tab[i + 1] = min(tab[i + 1],...
12
#include <bits/stdc++.h> using namespace std; char a[256]; string s; int main() { a['0'] = '8'; a['1'] = '.'; a['2'] = '.'; a['3'] = '3'; a['4'] = '6'; a['5'] = '9'; a['6'] = '4'; a['7'] = '7'; a['8'] = '0'; a['9'] = '5'; cin >> s; if (s.size() & 1 && a[s[s.size() / 2]] != s[s.size() / 2]) { ...
11
#include <bits/stdc++.h> using namespace std; int main() { int number1; cin >> number1; while (number1) { long long sum; cin >> sum; long long a, b; long long temp = sum / 3; if (sum % 3 == 0) { a = temp; b = temp; } else if (sum % 3 == 1) { a = temp + 1; b = temp; ...
0
#include <bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; const int mod = 998244353; int sum(int a, int b) { int s = a + b; if (s >= mod) s -= mod; return s; } int mult(int a, int b) { return (1LL * a * b) % mod; } int pw(int a, int b) { if (b == 0) return 1; if (b & 1) return mult(a, pw(a, b -...
18
#include <bits/stdc++.h> using namespace std; const double PI = 3.141592653; int main() { int n, R, r; double a; scanf("%d%d%d", &n, &R, &r); if (r > R || 2 * r > R && n > 1) puts("NO"); else { if (n == 1) puts(r <= R ? "YES" : "NO"); else { a = asin((double)r / (R - r)) * n; if ...
9
#include <bits/stdc++.h> using namespace std; int main() { long long int n, m, l, sum = 0; cin >> n >> m; long long int arr[n]; for (int i = 0; i < n; i++) { cin >> arr[i]; } for (int i = 0; i <= n - 3; i++) { l = lower_bound(arr, arr + n, arr[i] + m) - arr; if (arr[l] > arr[i] + m) { l--;...
5
#include <bits/stdc++.h> using namespace std; long long p[(1000000 + 1)], a[(1000000 + 1)], dp[(1000000 + 1)][2], pr[(1000000 + 1)][2]; void solve() { long long n; cin >> n; for (long long i = 0; i < n; i++) { cin >> p[i]; for (long long sign = 0; sign < 2; sign++) { dp[i][sign] = LONG_MAX; ...
20
#include <bits/stdc++.h> using namespace std; template <typename Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 << std::endl; } template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args) { const char* comma = strchr(names + 1, ','); cerr.writ...
9
#include<bits/stdc++.h> #define y1 dmytxdy #define pb push_back #define fi first #define se second #define mp make_pair using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int,int> pii; typedef pair<ll,ll> pll; typedef long double ld; template <typename T> bool chkmin(T &x,T y){r...
25
#include <bits/stdc++.h> using namespace std; int nextInt() { int x; scanf("%d", &x); return x; } long long nextLong() { long long x; scanf("%I64d", &x); return x; } double nextDouble() { double x; scanf("%lf", &x); return x; } const int BUFSIZE = 1000000; char buf[BUFSIZE + 1]; string nextString() { ...
17
#include <bits/stdc++.h> using namespace std; int n, k; long long dp[210][210][6][3]; bool kq[210][210][6][3]; long long c[210][210]; int add(long long u, long long v) { return (u + v) % 1000000007; } int mul(long long u, long long v) { return (u * v) % 1000000007; } int h[5] = {8, 6, 4, 2, 4}; int p[5] = {4, 2, 1, 0, ...
19
#include <bits/stdc++.h> using namespace std; const int N = 2500 + 7; const int M = 20; const int inf = (int)1e9 + 7; const long long base = (long long)1e18; const double pi = acos(-1); const double ep = 1e-18; int n, m, k; string s[N]; int dp[N][N]; int l[7], r[7]; int get(int i, int j, int u, int v) { return dp[u][...
22
#include <bits/stdc++.h> using namespace std; long long A[101000 << 2], n[101000 << 2], col[101000 << 2]; void pushup(int rt) { A[rt] = A[rt << 1] + A[rt << 1 | 1]; if (n[rt << 1] == n[rt << 1 | 1]) n[rt] = n[rt << 1]; else n[rt] = 0; } void pushdown(int rt, int m) { if (col[rt]) { col[rt << 1] += c...
16
#include <bits/stdc++.h> using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); void rset(); void init_test(); void solve(); signed main() { ios::sync_with_stdio(false); cin.tie(0); cout << fixed; cout.precision(20); init_test(); return 0; } template <typename T> void chmi...
11
#include <bits/stdc++.h> using namespace std; long long MOD = 1000000007; long long ex(long long b, long long st) { long long ans = 1; long long now = b; for (long long i = 0; i < 40; i++) { long long ba = (1LL << i) & st; if (ba == 0) { now *= now; now %= MOD; continue; } ans *=...
16
#include <bits/stdc++.h> using namespace std; bool __hack = std::ios::sync_with_stdio(false); auto __hack1 = cin.tie(nullptr); namespace template_util { constexpr int bytecount(uint64_t x) { return x ? 1 + bytecount(x >> 8) : 0; } template <int N> struct bytetype {}; template <> struct bytetype<4> {}; template <> struc...
19
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; const int Inf = 1e9 + 1; const int Mod = 1e9 + 7; const double eps = 1e-15; const int pw = 257; int calc(int m) { int res = m; while (m) res += m % 10, m /= 10; return res; } int main() { ios_base ::sync_with_stdio(false); cin.tie(NULL); i...
4
#include <bits/stdc++.h> using namespace std; const int inf = 1e9; int sz = 0; int pos[1111]; int p[1111]; int head[1111]; int len[1111]; int n, k; bool tr; int knum; int can[2222]; int doit(int x) { if (x == k) tr = 1; if (p[x] == 0) return pos[x]; pos[p[x]] = pos[x] + 1; return doit(p[x]); } int main() { in...
7
#include <bits/stdc++.h> using namespace std; class sp { public: int q; sp *w; sp(int q1, sp *w1) { q = q1; w = w1; } }; sp *a1[26]; int f[26]; bool l(int q) { if (f[q] > 0) return 1; f[q] = 1; for (sp *c = a1[q]; c; c = c->w) if (l(c->q)) return 1; f[q] = -2; return 0; } int main() { i...
8
#include <bits/stdc++.h> using namespace std; template <class c> struct rge { c b, e; }; template <class c> rge<c> range(c i, c j) { return {i, j}; } template <class c> auto dud(c *x) -> decltype(cerr << *x, 0); template <class c> char dud(...); struct debug { template <class c> debug &operator<<(const c &) { ...
19
#include <bits/stdc++.h> using namespace std; const int N = 800005; int head[N], nxt[N << 3], to[N << 3], from[N << 3], no = 0; void link(int a, int b) { nxt[no] = head[a]; from[no] = a; to[no] = b; head[a] = no++; } void addor(int a, int b) { link(a ^ 1, b); link(b ^ 1, a); } void addandor(int a, int b, in...
11
#include <bits/stdc++.h> using namespace std; int ar[1000005], ans[1000006], xxx[1000007][10], tt[1000005]; long long cheak(long long x) { long long i, ans = 1, a; while (x) { a = x % 10; x /= 10; if (a > 0) ans *= a; } return ans; } int main() { long long int i, j, k, n, m = 0, x = 0, x2, a = 1, ...
5
#include <bits/stdc++.h> using namespace std; bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) { return (a.second < b.second); } bool prime[1000000 + 1]; void seive() { long long int N = 1e6 + 1; memset(prime, true, sizeof(prime)); prime[0] = false; prime[1] = false; for (long long int i = 2...
5
#include <bits/stdc++.h> using namespace std; long long SIZE = (long long)1e18; int remains = 200000; vector<set<pair<long long, long long>>> evals; long long need; vector<long long> resLeft; vector<long long> resRight; long long realEval(int fid, long long x) { --remains; assert(remains >= 0); printf("? %d %lld\...
24
#include <bits/stdc++.h> using namespace std; char str[1000005]; int main() { int i, j; while (scanf("%s", &str) != EOF) { int n = strlen(str); int k = 0; long long sum = 1; for (i = 1; i < n; i++) { if ((str[i] - '0') + (str[i - 1] - '0') == 9) { k++; } else { if (k % 2 ...
7
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int t; cin >> t; while (t--) { long long int W, H, x1, y1, x2, y2, w, h, ans = INT_MAX, a = 0; cin >> W >> H >> x1 >> y1 >> x2 >> y2 >> w >> h; if (x2 - x1 + w <= W) { ans = ...
5
#include <bits/stdc++.h> using namespace std; int main() { double a[3]; cin >> a[0] >> a[1] >> a[2]; sort(a, a + 3); cout << ceil(((a[1] - a[0]) / 2) + ((a[2] - a[0]) / 2) + ((a[2] - a[1]) / 2)) << endl; return 0; }
0
#include <bits/stdc++.h> int a[201111], b[201111], n, i, l, r, sum, t; int main() { scanf("%d", &n); for (i = 0; i < n; i++) scanf("%d", &a[i]); for (i = 1; i < n; i++) { t = i - 1; for (l = 1; l <= t; l = r + 1) { r = t / (t / l); if (a[i] < a[t / l]) b[l]++, b[r + 1]--; } if (a[i] < ...
14
#include <bits/stdc++.h> using namespace std; int coinUse[200100]; int coinCount[200100]; vector<int> coin; int main() { int c; scanf("%d", &c); for (int i = 0; i <= c; i++) coinCount[i] = 0; int n; scanf("%d", &n); for (int i = 0; i < n; i++) { int x; scanf("%d", &x); coinCount[x]++; coin.p...
18
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { string a, b, c; cin >> a >> b >> c; int flag = 1; for (int i = 0; i < a.size(); i++) { if (a[i] != c[i] && b[i] != c[i]) { cout << "NO" << endl; flag = 0; break; } } ...
0
#include <bits/stdc++.h> using namespace std; long long lastpos[1000000], rankpos[1000000], rankinv[1000000]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); long long t, n, i, j, c, k, m, x, y, f, ans; cin >> n; vector<long long> adj[n + 5]; vector<pair<long long, long long> > v(n + 1); for (i = 1...
12
#include <bits/stdc++.h> using namespace std; const int Maxn = 100020; int n, k; unsigned long long tp[Maxn]; unsigned long long solve(int num, multiset<int>& S) { int cnt = 1; unsigned long long ret = 1ULL << 63; for (multiset<int>::iterator it = S.begin(); it != S.end(); cnt++, it++) { tp[cnt] = *it; if...
15
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; vector<int> a(n); vector<int> b(n); for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n; i++) cin >> b[i]; sort(a.begin(), a.end()); sort(b.begin(), b.end()); int l = 0; int r = n - 1; int cnt = 0; vec...
11
#include <bits/stdc++.h> using namespace std; template <typename T> istream &operator>>(istream &is, vector<T> &vec) { for (auto &v : vec) is >> v; return is; } template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) { os << "["; for (auto v : vec) os << v << ", "; os << "]"; return os;...
8
#include <bits/stdc++.h> using namespace std; int a[123456]; int sk1[123456]; int sk2[123456]; void print(int n) { for (int i = 1; i <= n; ++i) { for (int j = 0; j < sk1[i]; ++j) cout << '('; cout << a[i]; for (int j = 0; j < sk2[i]; ++j) cout << ')'; if (i != n) cout << "->"; } } int main() { int...
14
#include <bits/stdc++.h> using namespace std; const int max_n = 1000000; const int max_m = 1000000; const int max_bit = 32; int n, m, v, a[max_bit] = {0}, b[max_bit] = {0}, i, j, r = 0; int main() { scanf("%d %d", &n, &m); for (i = 0; i < n; i++) { scanf("%d", &v); for (j = 0; j < max_bit; j++) if ((1...
11
#include <bits/stdc++.h> using namespace std; long long int a[1010][1010]; long long int dp[1010][1010]; long long int v[1010][1010]; long long int n, m; long long int f; long long int dx[4] = {0, 1, 0, -1}; long long int dy[4] = {1, 0, -1, 0}; void dfs(long long int x, long long int y) { if (dp[x][y] != -1) { re...
11
#include <bits/stdc++.h> using namespace std; const long long inf = (long long)1e18; const long long mod = (long long)1e9 + 7; const double pi = acos(-1.0); const double eps = (double)1e-9; const int dx[] = {0, 0, 1, 0, -1}; const int dy[] = {0, 1, 0, -1, 0}; const int L = 200500; const int N = 1000000; const int M = 1...
17
#include <bits/stdc++.h> using namespace std; const int MAX = 3e5 + 5; int n, m, c[MAX]; vector<int> g[MAX]; int main() { scanf("%d%d", &n, &m); for (int i = 1; i <= m; i++) { int a, b; scanf("%d%d", &a, &b); g[a].push_back(b); g[b].push_back(a); } while (1) { int ok = 0; for (int u = 1;...
14
#include <bits/stdc++.h> int main() { int t; scanf("%d", &t); char s[202]; scanf("%s", s); int len = strlen(s); int digit[10], want[10], ans[10]; for (int i = 0; i < 10; i++) { digit[i] = 0; want[i] = 0; ans[i] = 0; } for (int i = 0; i < len; i++) { if (s[i] == '0') digit[0]++; if ...
7
#include <bits/stdc++.h> using namespace std; const int N = 1000007; const int inf = 0x3f3f3f3f; int f[N], pre[N], pos[N]; namespace Pam { int n, s[N], last, tot, anc[N], fail[N], ch[N][27], len[N], diff[N]; void build() { memset(f, 0x3f, sizeof(f)); memset(pre, 0, sizeof(pre)); memset(pos, 0, sizeof(pos)); mem...
25
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector<int> c(n); for (int i = 0; i < n; i++) { cin >> c[i]; } int st_diff = 0; for (int i = 1; i < n; i++) { if (c[i] != c[0]) { st_diff = i; break; } } int...
3
#include <bits/stdc++.h> using namespace std; long long power(long long, long long); long long mpower(long long, long long); long long BIT[1000009]; long long query(long long); void update(long long, long long); long long n, m, t; long long ans[1000009]; set<long long> s; map<long long, long long> dis; int32_t main() {...
10
#include <bits/stdc++.h> using namespace std; long long rev[(long long)2e5]; int main() { char* s = (char*)malloc(sizeof(char) * ((long long)2e5 + 1)); cin >> s; long long len = strlen(s); long long d; cin >> d; for (long long i = 0; i < d; i++) { long long j; cin >> j; rev[j - 1]++; } bool ...
6
#include <bits/stdc++.h> using namespace std; const int maxn = 4e3 + 1; char s[maxn]; int sum[maxn]; long long int t[maxn * 9]; int main() { int n; scanf("%d", &n); scanf("%s", s); int sizee = strlen(s); for (int i = 1; i < sizee + 1; i++) sum[i] = sum[i - 1] + s[i - 1] - '0'; for (int i = 1; i < sizee + 1;...
8
#include <bits/stdc++.h> const int md = 1e9 + 7; const long long hs = 199; const long double eps = 1e-9, pi = acos(-1); using namespace std; int n, d, lim = 80, ans[100002]; long long x; vector<int> a, b, im, p; void nextx() { x = (37 * x + 10007) % md; } void init() { a.resize(n), b.resize(n), p.resize(n + 1); for...
15
#include <bits/stdc++.h> int main() { int x; scanf("%d", &x); printf("%d %d", 10 * x, 9 * x); return 0; }
0
#include <bits/stdc++.h> using namespace std; int n, q; const int maxn = 2e5 + 5; const long long mod = 1e9 + 7; long long a[maxn], w[maxn]; long long lowbit(long long x) { return x & -x; } void add(long long t[], long long x, long long d, int typ) { for (; x < maxn; x += lowbit(x)) { t[x] += d; if (typ) t[x]...
17
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); long long a, b, c, d, e, f, i, j, k, l, m, n, o, x, y; cin >> n >> l >> k; string ss; cin >> ss; deque<char> dq; for (char c : ss) dq.push_back(c); sort(dq.begin(), dq.end()); string s[n + 5]; long...
10
#include <bits/stdc++.h> int T; long long m, d, w, t; long long gcd(long long a, long long b) { if (!b) return a; return gcd(b, a % b); } int main() { scanf("%d", &T); while (T--) { scanf("%lld%lld%lld", &m, &d, &w); long long t = std::min(m, d); long long g = gcd(d - 1, w); w /= g; long lon...
14
#include <bits/stdc++.h> using namespace std; void solve() { long long n; cin >> n; for (int i = 2; 1ll * i * i <= n; ++i) { if (n % i != 0) continue; while (n % i == 0) n /= i; if (n == 1) cout << i << endl; else cout << 1 << endl; return; } cout << n << endl; } int main() { ...
7
#include <bits/stdc++.h> using namespace std; int N, i, j, L, R, A[100000], B[100000]; long long K, M, H; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> N >> K >> M; for (i = 0; i < N; i++) { cin >> A[L]; if (L > 0 && A[L] == A[L - 1]) { B[L] = B[L - 1] + 1; if ...
15
#include <bits/stdc++.h> using namespace std; int trie[300005][26]; int position[300005]; vector<int> adj[300005]; vector<pair<int, int> > upd[300005]; vector<int> qq[300005], tt[300005]; void add(char *s, int k, int id) { static int pos = 1; int node = 0; for (int i = 0; i < k; ++i) { int ind = s[i] - 'a'; ...
18
#include <bits/stdc++.h> using namespace std; template <typename T> void out(T x) { cout << x << endl; exit(0); } const int maxn = 1e6 + 5; int n, m, k; string s; const int N = 10; struct segtree { vector<int> lazy, lastright, firstleft; vector<vector<vector<int>>> t; int n; segtree() {} void init(int n) ...
17
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; int flag = 1; int mx = INT_MIN; long long index = 0; vector<int> vec(n); for (int i = 0; i < n; i++) { int temp; cin >> temp; vec[i] = temp; if (temp > mx)...
1
#include <bits/stdc++.h> using namespace std; const int MAX_N = 100 * 1000 + 10, SQ = 444; int n, m, a[MAX_N], l[MAX_N], r[MAX_N], id[MAX_N], cnt[MAX_N]; int ans[MAX_N], now_ans; void read_input() { scanf("%d%d", &n, &m); for (int i = 0; i < n; i++) scanf("%d", &a[i]); for (int i = 0; i < m; i++) { scanf("%d%...
10
#include <bits/stdc++.h> using namespace std; struct Edge { int to, next, c, v; } edges[10005]; int ans = 0; int n, k, first[1005], te = 1; int dis[1005], a[1005], c[1005], last[1005], now[1005]; int cur[1005], all = 0; bool vis[1005], inq[1005]; queue<int> q; void addE(int a, int b, int c, int d) { edges[++te].to ...
18
#include <bits/stdc++.h> using namespace std; const int N = 55; int n, m; char a[N][N], b[N][N]; vector<pair<int, int> > v; void dfs(int x, int y) { if (a[x][y + 1] == 'L' && a[x + 1][y + 1] == 'U') { dfs(x + 1, y + 1); } if (a[x][y + 1] == 'L' && a[x + 1][y + 1] == 'L') { v.push_back(make_pair(x, y + 1))...
19
#include <bits/stdc++.h> using namespace std; int main() { int n, a, b, k = 1, i_1, j_1; ; cin >> n >> a >> b; if (n > a * b) { cout << "-1" << endl; return 0; } int **ary = new int *[a]; for (int i = 0; i < a; i++) { ary[i] = new int[b]; for (int j = 0; j < b; j++) { ary[i][j] = 0; ...
2
#include <bits/stdc++.h> using namespace std; char s[100050], co[55]; int invco[256], q, l, r; long long num[55], n, W = 1, p[100050], pinv[100050], dp[500050], ans[55][55]; const long long Mod = 1e9 + 7; long long mypow(long long a, long long e) { long long ans = 1, base = a; while (e) { if (e % 2) ans = ans *...
18
#include <bits/stdc++.h> using namespace std; const int maxN = 1e7 + 5; const long long INF = 1e18; const long long MOD = 1e9 + 7; int sieve[maxN]; int phi[maxN]; int numD[maxN]; int ps[maxN]; long long cnt[3]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); iota(phi, phi + maxN, -1); iota...
19
#include <bits/stdc++.h> using namespace std; const int N = 210; int n, k, m, a, g[N], v[N], last[N], st[N]; int main() { scanf("%d%d%d%d", &n, &k, &m, &a); for (int i = 0; i < a; ++i) { scanf("%d", &g[i]); v[g[i]]++; last[g[i]] = i; } vector<pair<pair<int, int>, int> > all; for (int i = 1; i <= n...
13
#include <bits/stdc++.h> using std::cin; using std::cout; #pragma GOVNOCODE optimize("ROFL") const int N = int(1e5) + 2; const int INF = int(1e9) + 1; const int MOD = 998244353; int main() { std::ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, m; cin >> n >> m; std::vector<std::vector<int>...
12
#include <bits/stdc++.h> using namespace std; int main() { long long n, sum = 0, ans = 0; cin >> n; long long arr[n + 2]; for (long long i = 0; i < n; i++) cin >> arr[i], sum += arr[i]; sort(arr, arr + n); if (sum % 2 == 0) return cout << sum, 0; for (long long i = 0; i < n; i++) { if ((sum - arr[i]) ...
1
#include <bits/stdc++.h> long long int mod = 1000000000 + 7; long long int inf = (long long int)(5e18); using namespace std; mt19937 unlucko(chrono::steady_clock::now().time_since_epoch().count()); int main() { iostream::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; cin >> n; vector<string> a[26],...
12
#include <bits/stdc++.h> using namespace std; vector<int> v1, v2; set<int> s; map<int, int> cnt; int n, k, unlucky, dp[1023][2], fct[100001], inv[100001]; const int mod = 1000000007; int cmb(int x, int y) { if (x < y) return 0; if (y < 0) return 0; return 1LL * fct[x] * inv[x - y] % mod * inv[y] % mod; } int qpow...
13
#include <bits/stdc++.h> using namespace std; string s; int prep[510][510]; int dp[510][510]; int way[510][510]; int r(int p, int k) { if (k < 0) return 1000000000; if (p == s.size()) return 0; if (dp[p][k] != -1) return dp[p][k]; int res = 2000000000; for (int i = (p); i < (s.size()); ++i) { int res1 = p...
11
#include <bits/stdc++.h> using namespace std; const double EPS = 10e-11; const double PI = acos(-1); class VagueDouble { public: double vd; VagueDouble() { vd = nan(""); } VagueDouble(const double d) { vd = d; } inline VagueDouble operator-() const { return VagueDouble(-vd); } inline VagueDouble operator+(co...
15
#include <bits/stdc++.h> using namespace std; bool arr[407][407]; int main() { cin.sync_with_stdio(0); int n, m; cin >> n >> m; bool win = false; for (int i = 0; i < m; i++) { int x, y; cin >> x >> y; x--; y--; if ((x == 0 && y == n - 1) || (x == n - 1 && y == 0)) win = true; arr[x][y]...
8
#include <bits/stdc++.h> using namespace std; map<long long, long long> mp; long long pow(long long a, long long b) { long long ans = 1; while (b > 0) { if (b & 1) ans = ans * a % 1000000007; b >>= 1; a = a * a % 1000000007; } return ans; } long long dfs(long long n) { if (mp[n] != 0) return mp[n]...
12
#include <bits/stdc++.h> using namespace std; const int inf = (int)1e9; const double INF = 1e12, EPS = 1e-9; int n, a[100000]; int main() { vector<int> v; cin >> n; for (int i = 0; i < (int)n; i++) cin >> a[i], v.push_back(a[i]); sort((v).begin(), (v).end()); for (int i = 0; i < (int)n; i++) a[i] = lower_...
5
#include <bits/stdc++.h> using namespace std; class qv { public: int v, n; }; int mf(qv a, qv b) { return a.n < b.n; } int n, m; vector<vector<int>> mas; vector<vector<long long>> imas; vector<int> proc; long long MAX = 1000000007; long long msum(long long a, long long b) { return ((a + b) % MAX); } long long mmul(l...
17
#include <bits/stdc++.h> using namespace std; const int MN = 2e5 + 5; int arr[MN], n, k, i, j, nxt[MN]; long long prod, sum, ans; int main() { for (scanf("%d%d", &n, &k), i = 1; i <= n; i++) scanf("%d", &arr[i]); for (i = n; i >= 1; i--) { if (arr[i] == 1) nxt[i] = nxt[i + 1] + 1; } for (i = 1; i <= n; i++)...
13
#include <bits/stdc++.h> unsigned long long int p[1000000], arr[1000000]; int len, s[1000000]; char str[500000]; void pre() { p[0] = 1; for (int i = 1; i <= 2 * len; i++) p[i] = p[i - 1] * 31; } inline int lowbit(int x) { return x & (-x); } void insert(int pos, unsigned long long int add) { for (int i = pos; i <=...
20
#include <bits/stdc++.h> using namespace std; void Weapons19() { string s, t; cin >> s >> t; vector<vector<long long int>> dp(t.size() + 1, vector<long long int>(s.size() + 1)); for (long long int i = 1; i <= t.size(); i++) { for (long long int j = 1; j <= s.size(); j++) {...
9
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int n, p; cin >> n >> p; long long int sum[n]; long long int cur = 0; long long int inp; for (int i = 0; i < n; i++) { cin >> inp; cur += inp; sum[i] = cur; } long long i...
4
#include <bits/stdc++.h> using namespace std; int main() { long long int n; cin >> n; long long int cost[n]; long long int sum = 0; for (int i = 0; i < n; i++) { cin >> cost[i]; sum += cost[i]; } sort(cost, cost + n); long long int m; cin >> m; long long int noOfCoupons[n]; for (int i = 0;...
1
#include <bits/stdc++.h> using namespace std; inline string Next() { string S; cin >> S; return S; } inline string NextLine() { string S; getline(cin, S); return S; } inline int NextInt() { int n; scanf("%d", &n); return n; } inline long long NextLong() { long long n; scanf("%lld", &n); return n...
15
#include <bits/stdc++.h> using namespace std; int main(int argc, const char* argv[]) { long long n, m, k; cin >> n >> m >> k; if (k > n + m - 2) cout << -1; else { long long ans = 0; if (n - 1 >= k) { ans = max(ans, min(n / (k + 1), n - n / (k + 1) * k) * m); } else { long long res =...
9
#include <bits/stdc++.h> using namespace std; int tn, p[100500 >> 2], mu[100500]; bool e[100500]; void sieve(int n) { mu[1] = e[1] = 1; for (int i = 1; i <= n; i++) { if (!e[i]) mu[p[++tn] = i] = -1; for (int j = 1; j <= tn && i * p[j] <= n; j++) { e[i * p[j]] = 1; if (i % p[j] == 0) break; ...
21
#include <bits/stdc++.h> long long powermod(long long _a, long long _b, long long _m) { long long _r = 1; while (_b) { if (_b % 2 == 1) _r = (_r * _a) % _m; _b /= 2; _a = (_a * _a) % _m; } return _r; } using namespace std; template <typename T> void pr(const T& t) { cout << t << "\n"; } template <...
0
#include <bits/stdc++.h> using namespace std; double tick() { static clock_t oldt, newt = clock(); double diff = 1.0 * (newt - oldt) / CLOCKS_PER_SEC; oldt = newt; return diff; } inline long long int read() { long long int f = 1, x = 0; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-'...
8
#include <bits/stdc++.h> using namespace std; int n, k, lim, m, fa[110000]; bool check(int n) { n++; return n == (n & -n); } int main() { scanf("%d%d", &n, &k); lim = max((n - 3) / 2, 0); if (!(n & 1) || (k > lim) || (k == check(n)) || (n == 9 && k == 2)) { puts("NO"); return 0; } puts("YES"); m...
20
#include <bits/stdc++.h> using namespace std; mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count()); const long long INF = INT_MAX; const long long INF_LL = LLONG_MAX; const long double EPS = 1e-9; const long long MOD = 1e9 + 7; long long n; signed main() { cin.tie(0); ios::sync_with_stdio...
5
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long n; cin >> n; if (n % 2 == 0) { cout << "white\n" << "1 2" << endl; } else { cout << "black\n"; } return 0; }
9
#include <bits/stdc++.h> using namespace std; int main() { vector<pair<int, int> > v; for (int i = 3; i <= 360; i++) { for (int j = 1; j <= i - 2; j++) { if (j * 180 % i) continue; v.push_back({i, j * 180 / i}); } } sort(v.begin(), v.end()); int t; cin >> t; while (t--) { int ang; ...
8
#include <bits/stdc++.h> using namespace std; long long a, n, i, k, b, k1, k2, w, c; long double s; int main() { cin >> a >> b; n = a + ((a - 1) / (b - 1)); cout << n << endl; return 0; }
1
#include <bits/stdc++.h> using namespace std; const int MAXN = 100 * 1000 + 17; int n, m, a[MAXN], L[MAXN], R[MAXN], parL[MAXN], parR[MAXN]; long long ans; void set_rootR(int v, int x) { if (parR[v] == v) { parR[v] = x; return; } set_rootR(parR[v], x); parR[v] = x; } void set_rootL(int v, int x) { if ...
17