solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> const int MAXN = 100011; int N, M; int S; long long T; long long Tim[MAXN]; int Nxt(int Pos) { long long ret = (long long)(Pos); ret += (Pos < M) ? T : (-T); --T; return ((int)(ret % (long long)(N)) + N) % N; } int main() { scanf("%d%d%d%I64d", &N, &M, &S, &T); --S; while (true) {...
21
#include <bits/stdc++.h> using namespace std; int n, r, a, arr[101]; vector<int> ans; int main() { cin >> n; for (int i = 0; i < n; i++) { cin >> r; while (r--) { cin >> a; arr[a]++; } } for (int i = 1; i < 101; i++) { if (arr[i] == n) ans.push_back(i); } for (int i = 0; i < ans....
0
#include <bits/stdc++.h> using namespace std; inline void EnableFileIO(const string& fileName, bool local = 0) { if (fileName.empty()) return; if (local) { freopen((fileName + ".in").c_str(), "r", stdin); freopen((fileName + ".out").c_str(), "w", stdout); return; } freopen((fileName + ".in").c_str()...
18
#include <bits/stdc++.h> using namespace std; int n, m, k; long long memo[1001][101][2][2]; long long _pow[1001]; void pre() { _pow[0] = 1; for (int i = 1; i < 1001; i++) _pow[i] = (_pow[i - 1] * 10) % k; } long long F(int dig, int md, bool f1, bool f2) { if (dig == 0) return f1; if (memo[dig][md][f1][f2] != -1...
14
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; long long x, y; cin >> x >> y; if (y < n) { cout << "-1" << endl; } else { vector<long long> a(n); for (int i = 0; i < n - 1; i++) { a[i] = 1; } a[n - 1] = y - (n - 1); long long sum = (n - 1) + (long l...
6
#include <bits/stdc++.h> using namespace std; const int N = 5e5 + 100; int num[N]; bool vis[N]; vector<int> v; int n, k; int main() { scanf("%d %d", &n, &k); int mn = 1e9 + 100; for (int i = 1; i <= n; i++) { scanf("%d", &num[i]); if (num[i] < mn) { mn = num[i]; vis[i] = true; v.push_bac...
17
#include <string> #include <vector> #include<iostream> #include<cstdio> #include<cstdlib> #include<stack> #include<queue> #include<cmath> #include<algorithm> #include<functional> #include<list> #include<deque> #include<bitset> #include<set> #include<map> #include<unordered_map> #include<unordered_set> #include<cstring>...
14
#include <bits/stdc++.h> using namespace std; long long int gc(long long int kl, long long int yu) { long long int pp; for (pp = min(kl, yu); pp >= 1; pp--) { if (kl % pp == 0 && yu % pp == 0) break; } if (pp == 1) return 1; else return 0; } int isP(long int hj) { long int op; for (op = 2; op ...
1
#include <bits/stdc++.h> using namespace std; const int inf = 2e9 + 5; const long long ll_inf = 1e18 + 5; template <typename T, typename T2> ostream &operator<<(ostream &s, const pair<T, T2> &p) { return s << p.first << ' ' << p.second << ' '; } template <typename T, typename T2> istream &operator>>(istream &s, pair<...
12
#include <bits/stdc++.h> using namespace std; int main() { int arr[5]; for (int i = 1; i <= 4; i++) { cin >> arr[i]; } string s; cin >> s; int n = s.length(); int calories = 0; for (int i = 0; i < n; i++) { calories += arr[int(s[i]) - 48]; } cout << calories; }
0
#include <bits/stdc++.h> using namespace std; const int INF = 1e7; struct fruit { int weight; int cost; }; fruit fruits[110]; int dp[110][50010]; int N = 10000; int rdp(int n_fruits, int total_weight) { if (dp[n_fruits][N + total_weight] != -INF) return dp[n_fruits][N + total_weight]; if (n_fruits == 0) { ...
11
#include <bits/stdc++.h> int main() { int x, y, f_ans = 1, f; scanf("%d %d", &x, &y); if (x <= y) f = x; else f = y; for (;;) { f_ans = f_ans * f; f--; if (f == 0) break; } printf("%d", f_ans); }
0
#include <bits/stdc++.h> using namespace std; void __print(int x) { cerr << x; } void __print(long x) { cerr << x; } void __print(long long x) { cerr << x; } void __print(unsigned x) { cerr << x; } void __print(unsigned long x) { cerr << x; } void __print(unsigned long long x) { cerr << x; } void __print(float x) { cer...
5
#include <bits/stdc++.h> using namespace std; int dcmp(double a, double b) { return fabs(a - b) <= 0.0000000001 ? 0 : (a > b) ? 1 : -1; } vector<string> v; int m, f; bool check(string s) { int n = ((int)(s).size()); if (n >= 4 && s[n - 1] == 's' && s[n - 2] == 'o' && s[n - 3] == 'i' && s[n - 4] == 'l') ...
8
#include <bits/stdc++.h> using namespace std; signed main() { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; int a[n]; for (auto &it : a) { cin >> it; it++; } int dp[3][n]; memset(dp, 0, sizeof(dp)); dp[0][0] = 1; dp[1][0] = !(a[0] == 2 || a[0] == 4); dp[2][0] = !(a[0] == 3 || a[0...
6
#include <bits/stdc++.h> using namespace std; using uint = unsigned int; using ll = long long; using ull = unsigned long long; constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); } template <class T> using V = vector<T>; template <class T> using VV = V<V<T>>; template <class T> using VVV = V<VV<T>>; templa...
22
#include <bits/stdc++.h> using namespace std; char S[100005]; int main() { int N; int len, K; scanf("%d%d\n", &N, &K); gets(S); int grass, insect; for (int i = 0; i < N; i++) { if (S[i] == 'G') grass = i; else if (S[i] == 'T') insect = i; } if (grass > insect) swap(grass, insect); ...
0
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize("O2") vector<long long int> ar[1000001]; long long int vis[1000001], dis[1000001], level[1000001]; const int MAX_SIZE = 1000001; const int N = 2000010; const int mod = 1e9 + 7; vector<int> isprime(MAX_SIZE, true); vector<int> prime; vector<int> SPF(MAX_...
4
#include <bits/stdc++.h> using namespace std; const long long N = 105; long long n; long long a[N]; map<long long, long long> m; long long dp[N][N * N]; int32_t main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; cin >> n; for (long long i = 1; i <= n; i++) { cin >> a[i]; m[a[i]]++; } i...
13
#include <bits/stdc++.h> using namespace std; int Mod = 1e9 + 7; struct Point { long long x, y; }; void ans(int v) { cout << v << endl; exit(0); } struct P3 { Point a, b, c, ta, tb, tc; P3(Point x, Point y, Point z) : a(x), b(y), c(z) {} void refresh(bool transpose) { if (transpose) { ta.x = a.y; ...
9
#include <bits/stdc++.h> #pragma GCC optimize("O3") #pragma GCC target("avx2,avx") #pragma GCC optimize("unroll-loops") using namespace std; template <class T> using pq = priority_queue<T>; template <class T> using pqg = priority_queue<T, vector<T>, greater<T>>; int scan() { return getchar(); } void scan(int &a) { cin ...
17
#include <bits/stdc++.h> using namespace std; int main() { long long int i, n, a, b, c, d, e, f; char s[100005]; cin >> n >> a >> b; cin >> s; if (s[a - 1] == s[b - 1]) cout << "0"; else { cout << "1"; } return 0; }
4
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; int n, t = 0, l, r, a[N], v[N], L[N], R[N]; char s[N]; struct cmp { bool operator()(pair<int, int> &r, pair<int, int> &q) const { if (abs(a[r.first] - a[r.second]) == abs(a[q.first] - a[q.second])) return r.first > q.first; return abs(...
11
#include <bits/stdc++.h> using namespace std; int m, n; int p[30]; int ask(int y) { printf("%d\n", y); fflush(stdout); int ans; scanf("%d", &ans); return ans; } int it = 0; void bs(int lo, int hi) { int mid = (lo + hi) / 2; int t = ask(mid); if (p[it] == 0) t *= -1; it = (it + 1) % n; if (t == 0) re...
10
#include <bits/stdc++.h> using namespace std; long long n, k; void binarysearch() { long long l = 2, r = k, m, sum; while (l <= r) { m = (l + r) / 2; sum = ((m + k) * (k - m + 1) / 2 - (k - m)); if (sum < n && (sum + m - 2) > n) break; else if (sum < n) r = m - 1; else if (sum > n) ...
9
#include <bits/stdc++.h> using namespace std; const int maxn = 4e6 + 10; const int p = 1009; int raw[maxn], cnt[maxn]; struct node { double x, y; node(double xx = 0, double yy = 0) { x = xx, y = yy; } }; node operator*(node J, node Q) { return node(J.x * Q.x - J.y * Q.y, J.x * Q.y + J.y * Q.x); } node operator+(n...
18
#include <bits/stdc++.h> using namespace std; double pi = 3.14159265358979; struct pt { double x; double y; }; struct line { double a; double b; double c; }; line to(pt a, pt b) { line l; l.a = (b.y - a.y); l.b = (a.x - b.x); l.c = (-a.x * l.a - a.y * l.b); return l; } pt perec(line l1, line l2) { ...
15
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; long long int a[n]; for (int i = 0; i < n; i++) cin >> a[i]; long long int max = 0; int ans = -1; if (a[0] != 0) ans = 1; else { for (int i = 1; i < n; i++) { if (a[i - 1] > max) max = a[i - 1]; if (a[i] - ma...
2
#include <bits/stdc++.h> using namespace std; int main() { int n, k, sum = 0; cin >> n >> k; int i; for (i = 0; i < n; i++) { int x; cin >> x; sum += x; } int ans = 2 * (k * n - sum) - n; cout << ((ans > 0) ? ans : 0) << endl; return 0; }
1
#include <bits/stdc++.h> #define int long long using namespace std; const int maxn = 3e5; int a[maxn]; set<int> sr[maxn]; set<pair<int, int>> all_a; set<pair<int, int>> all_sz; int pr[maxn]; vector<pair<int, int>> edges; int n; int x; void make_set() { for (int i = 0; i < maxn; ++i) { pr[i] = i; } } ...
18
#include <bits/stdc++.h> using namespace std; int primes[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53}; int DP[101][(1 << 16) + 5]; int ch[101][(1 << 16) + 5]; int arr[105], sum[105], sol[105]; int masks[61]; vector<int> cans[(1 << 16) + 5]; int n; int solve(int ind, int mask) { if (ind == n) retur...
12
#include <bits/stdc++.h> using namespace std; long long n, k, x, a, c, ans; vector<long long> v; int main() { cin >> n >> k >> x; for (long long i = 0; i < n; i++) { cin >> a; v.push_back(a); ans += a; } c = v.size() - 1; for (long long i = 0; i < k; i++) { if (x < v[c]) { ans -= v[c] - ...
0
#include <bits/stdc++.h> int main() { int x, y, a, b; int t1, t2; scanf("%d %d %d %d", &a, &b, &x, &y); int c; t1 = a; t2 = b; while (a % b) { c = a % b; a = b; b = c; } c = (t1 * t2) / b; printf("%d\n", (y / c) - (x - 1) / c); return 0; }
4
#include <bits/stdc++.h> using namespace std; const long long INF = INT_MAX; const long long N = 2e5 + 5; int n, mn = INF, ans; string s, a = "ACTG"; int main() { ios_base::sync_with_stdio(false), cin.tie(), cout.tie(); cin >> n >> s; for (int i = 0; i < n - 3; i++) { for (int j = 0; j < 4; j++) { int x...
2
#include <bits/stdc++.h> const int SIZE = 1e2 + 5; using namespace std; int Inc[SIZE]; int Dec[SIZE]; int main() { ios_base::sync_with_stdio(0); cin.tie(NULL), cout.tie(NULL); int n, m; cin >> n >> m; while (m-- > 0) { int x, y, z; cin >> x >> y >> z; Inc[x] += z; Dec[y] += z; } int Ans = ...
5
#include <bits/stdc++.h> using namespace std; const long long maxn = 1e4 + 10; const long long ZERO = 0; const long long SADAT = 7.84e-17; const long long INF = 1e9; const long long mod = 1e9 + 7; int q[300]; char r[300]; long double dp[300][300]; int main() { int n, m; long long t; cin >> n >> m >> t; memset(q...
15
#include <bits/stdc++.h> using namespace std; int main() { int n, t; cin >> n >> t; string s; cin >> s; for (int i = 0; i < t; i++) { for (int j = n - 2; j >= 0; j--) { if (s[j] == 'B' && s[j + 1] == 'G') { swap(s[j], s[j + 1]); j--; } } } cout << s; }
0
#include <bits/stdc++.h> using namespace std; int prime(int x) { if (x == 2) return 1; for (int i = 2; i * i <= x; i++) { if (x % i == 0) { return 0; } } return 1; } int main() { int n; cin >> n; if (prime(n)) { cout << 1 << endl << n << endl; return 0; } if (prime(n - 2)) { ...
10
#include <bits/stdc++.h> using namespace std; const int maxn = 4000; long long vis[maxn], cnt[maxn], sum[maxn]; struct Node { int v, rt, p; } aa[maxn]; bool cmp(Node a, Node b) { if (a.v != b.v) return a.v < b.v; return a.p < b.p; } int main() { int n, m; cin >> n >> m; for (int i = 1; i <= n; i++) { ci...
9
#include <bits/stdc++.h> using namespace std; int main() { char a[150], b[150], c[300]; int flag, len, i; while (gets(a)) { gets(b); memset(c, 0, sizeof(c)); flag = 0; len = strlen(a); for (i = 0; i < len; i++) { if (a[i] == b[i]) c[i] = a[i]; else if (a[i] < b[i]) { ...
1
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 5; int prime[maxn]; bool is_prime[maxn]; int pp[maxn]; int sieve(int n) { int p = 0; for (int i = 0; i <= n; ++i) is_prime[i] = true; is_prime[0] = is_prime[1] = false; for (int i = 2; i <= n; ++i) { if (is_prime[i]) { prime[p++] = i...
16
#include <bits/stdc++.h> using namespace std; int n; string cards[105]; map<char, int> m; bool is_distinguishable(string a, string b, int mask) { if (a == b) return true; if (a[0] == b[0]) return (((1 << (a[1] - '0' - 1)) & mask) != 0) || (((1 << (b[1] - '0' - 1)) & mask) != 0); if (a[1] == b[1]) ...
9
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int x, y; cin >> x >> y; vector<char> pn(n); vector<int> px(n), py(n); vector<int> mind(8, ((int)2e9 + 1)); vector<int> minp(8, -1); for (int i = 0; i < n; i++) cin >> pn[i] >> px[i] >> py[i]; int d = 2e9; for (int i = 0; ...
9
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; for (int i = 0; i < t; i++) { long long n, k, mn = -1, mx = 0; cin >> n >> k; map<int, int> x; for (int j = 0; j < n; j++) { int t; cin >> t; t = t % k; x[t]++; if (mx <= x[t] && t != 0) { ...
6
#include <bits/stdc++.h> using namespace std; int main() { long long int n; cin >> n; vector<pair<long long int, pair<long long int, long long int> > > ans; for (long long int i = 0; i < ((long long int)(300)); ++i) for (long long int j = 0; j < ((long long int)(12)); ++j) ans.push_back(make_pair(abs(...
6
#include <bits/stdc++.h> using namespace std; int n, d[15][15], res = -1; int main(int argc, char* argv[]) { scanf("%d", &n); for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) scanf("%d", &d[i][j]); for (int k = 1; k <= n; k++) for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) ...
12
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { long long x, y, z; if (a < b) { x = a; y = b; } else { x = b; y = a; } while (x > 0) { z = x; x = y % x; y = z; } return y; } int main() { long long a[100005], num, g, i, n; scanf("%I64d...
8
#include <bits/stdc++.h> using namespace std; const long long INF = 2000000000000000; int main() { char str[100010]; int b[100010]; int rol = 100010; int minIndex[200100]; for (int i = 0; i < 200100; ++i) minIndex[i] = -2; int len; scanf("%i", &len); scanf("%s", str); b[0] = -1 + 2 * (*str - '0'); f...
7
#include <bits/stdc++.h> using namespace std; int reader_pt = 1048576, reader_last; char reader_buf[1048576]; int writer_pt = 0; char writer_buf[1048576]; void reader(int *x) { int k, m = 0; *x = 0; for (;;) { { if (reader_pt == 1048576) reader_pt = 0, reader_last = fread(reader_buf, siz...
21
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e3 + 5; const long long linf = 1e18; const long double eps = 1e-8; inline void swap(int &a, int &b) { int t = a; a = b; b = t; } inline long double Fabs(long double x) { return x < 0 ? -x : x; } inline bool eq(long double x, long double y) { return F...
16
#include <bits/stdc++.h> const int N = 200005; using namespace std; set<int> col[N]; int seg[N * 3]; int mnv[N * 3]; int mxt[N * 3]; int tag[N * 3]; int lcon[N * 3]; int rcon[N * 3]; inline void _down(int rt) { if (tag[rt]) { mnv[(rt << 1)] += tag[rt]; mnv[(rt << 1 | 1)] += tag[rt]; tag[(rt << 1)] += tag[...
12
#include <bits/stdc++.h> using namespace std; int n, ans = 0, k = INT_MAX; const int MAXN = 1000; char s[MAXN]; int main() { cin >> n; for (int i = 0; i < n; i++) cin >> s[i]; for (int i = 0; i < n - 2; i++) { if (s[i] == '1' && s[i + 1] == '0' && s[i + 2] == '1' && k - i != -2) { ans++; k = i; ...
2
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; int p[N], n, k, m, r[N]; int find(int x) { if (x != p[x]) p[x] = find(p[x]); return p[x]; } int main() { cin >> n >> k; for (int i = 1; i <= n; i++) p[i] = i; for (int i = 1; i <= k; i++) { int a, b; scanf("%d %d", &a, &b); p[fi...
7
#include <bits/stdc++.h> using namespace std; unsigned long long min(unsigned long long x, unsigned long long y) { if (x < y) return x; return y; } unsigned long long max(unsigned long long x, unsigned long long y) { if (x < y) return y; return x; } long long min(long long x, long long y) { if (x < y) return ...
9
#include <bits/stdc++.h> using namespace std; #define ll long long #define ull unsigned long long #define pii pair<int, int> #define mii map<int, int> #define pb push_back #define mk make_pair const int inf = 0x3f3f3f3f; const ll mod = 1000000007; const ll linf = 0x3f3f3f3f3f3f3f3f; #define deb(k) cerr << #k << ": " <<...
21
#include <bits/stdc++.h> using namespace std; long long i, p[100005], j, n, k, flag, ctr, a[100005]; vector<long long> fac; int main() { cin >> n; for (i = 1; i <= sqrt(n); i++) { if (n % i == 0) { fac.push_back(i); fac.push_back(n / i); } } flag = 1; for (i = 0; i < n; i++) { cin >> a...
8
#include <bits/stdc++.h> const int N = 2e5 + 10; int arr[N], arr2[N]; int main(int argc, char const *argv[]) { int n, k, q; scanf("%d%d%d", &n, &k, &q); for (int i = 0; i < n; i++) { int l, r; scanf("%d%d", &l, &r); arr[l] += 1; arr[r + 1] -= 1; } for (int i = 1; i < N; i++) { arr[i] += ar...
6
#include <bits/stdc++.h> using namespace std; int n, m; int ara[2005][2005]; int sum[2005]; char str[2005][2005]; int main() { scanf("%d %d", &n, &m); for (int i = 1; i <= n; i++) { scanf("%s", str[i] + 1); } for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { if (str[i][j] == '1') sum[j...
4
#include <bits/stdc++.h> using namespace std; double dp[205][205][205]; struct y { double p; int num; } haha[205]; bool compare(y a, y b) { if (a.num != b.num) return a.num > b.num; else return a.p >= b.p; } int main() { int n, l, k, q; memset(haha, 0, sizeof(haha)); memset(dp, 0, sizeof(dp)); c...
10
#include <bits/stdc++.h> const int N = 103; using namespace std; int n, m, a[N][N], sum, ans, now, c[N]; pair<int, int> b[N]; int main() { scanf("%d%d", &n, &m); for (int i = 0; i < m; i++) { for (int j = 1; j <= n; j++) scanf("%d", a[i] + j); } ans = m; for (int i = 1; i < n; i++) { sum = 0; for ...
9
#include <bits/stdc++.h> using namespace std; int size_n, size_m, size_q; int result[105][105]; void solve(int curIterate); int main() { int ii, jj; cin >> size_n >> size_m >> size_q; solve(size_q); for (ii = 0; ii < size_n; ii++) { for (jj = 0; jj < size_m; jj++) cout << result[ii][jj] << " "; cout << ...
6
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; if (!(n & 1)) { cout << "white" << endl << 1 << " " << 2 << endl; } else { cout << "black" << endl; } return 0; }
9
#include <bits/stdc++.h> using namespace std; int n, m, Q, w[400010], cnt, dfn[400010], low[400010], tot, blo[400010]; int fa[400010], top[400010], pos[400010], po[400010], dep[400010], size[400010], nxt[400010]; int k, la[400010], ff[400010], tp, q[400010], flag[400010]; struct node { int a, b; } e[400010]; stru...
24
#include <bits/stdc++.h> using namespace std; template <class AT, class UT> struct SegmentTree { AT I; UT NU, v; int N, l, r; vector<AT> A; vector<UT> U; vector<int> L, R; virtual AT op(const AT& i, const AT& j) = 0; virtual AT us(int p, const UT& v) = 0; SegmentTree(int N, AT I = 0, UT NU = INT_MIN) ...
17
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const long long mod = 1000000007; const int MAXN = 150; const int MAXL = 2000100; int l, n; char s1[MAXL], s2[MAXL], ans[MAXN]; struct edge { int from, to, cap, flow, cost; }; inline int ID(char c) { if (c >= 'A' && c <= 'Z') return c - '...
15
#include <bits/stdc++.h> using namespace std; using std::string; long long power(long long b, long long p) { if (p == 0) return 1; long long ans = 1; while (p > 1) { if (p % 2 == 0) { b *= b; b %= 1000000007; p /= 2; } else { ans *= b; ans %= 1000000007; p -= 1; } ...
9
#include <bits/stdc++.h> using namespace std; const long long INF = 1e12; const int MAXN = 1e6 + 1, MODM = 1e9 + 7, P = 1e6 + 3, MULT1 = 30, MULT2 = 239, LUCKY = 13, ELEVEN = 11, MAXM = 101; vector<int> g[MAXN]; vector<pair<int, int> > t[MAXN]; int f[MAXN << 2]; int n, m; void update(int v, int tl, int tr, in...
14
#include <bits/stdc++.h> long long read() { long long x = 0, f = 1; char c; while ((c = getchar()) < '0' || c > '9') { if (c == '-') f = -1; } while (c >= '0' && c <= '9') { x = (x << 3) + (x << 1) + (c ^ 48); c = getchar(); } return x * f; } long long T, n, m, l, r, a[40], b[40], dp[40][1 << ...
15
#include <bits/stdc++.h> using namespace std; string str[3]; vector<int> adj1[4], adj2[4]; pair<int, int> sz[4]; int ted = 0; int main() { cin >> str[0] >> str[1] >> str[2]; for (int i = 0; i < 3; i++) { if (str[i][1] == '>') { adj1[str[i][0] - 'A'].push_back(str[i][2] - 'A'); adj2[str[i][2] - 'A']....
4
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 1; int a[N], sum[N]; int main() { int n, k; cin >> n >> k; for (int i = 0; i < n; i++) { cin >> a[i]; } sum[0] = a[0]; for (int i = 1; i < n; i++) { sum[i] = sum[i - 1] + a[i]; } if (sum[n - 1] % k) { return cout << "No", 0; ...
3
#include <bits/stdc++.h> using namespace std; const int maxN = 50 + 10; long long n, m, l, a, sum[maxN], maxx[maxN], dpl[maxN]; long long first[maxN], ans = -1e6, last, zero, mn; int main() { cin >> n >> m; for (int i = 1; i <= n; i++) { cin >> l; mn = 0; first[i] = ans; maxx[i] = ans; for (int ...
12
#include <bits/stdc++.h> using namespace std; int n; long long a[100005], b[100005]; bool check(int x, int y) { return a[x] > b[y]; } int main() { ios::sync_with_stdio(0); cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; } long long mn = a[n - 1]; for (int i = n - 2; i >= 0; i--) { b[i] = mn; ...
7
#include <bits/stdc++.h> using namespace std; const long long Maxn = 100010; const long long Mod = 1e9 + 7; long long b[Maxn << 2], bl; long long f1[Maxn], f2[Maxn], f[Maxn << 2]; struct lnode { long long l, r; bool operator<(const lnode &A) const { return l == A.l ? r > A.r : l < A.l; } } l1[Maxn], l2[Maxn]; long ...
21
#include <bits/stdc++.h> using namespace std; vector<int> diff, sim; int F(string s1, string s2) { int i; for (i = 0; i < s1.length(); i++) { if (s1[i] - s2[i]) { diff.push_back(i); } else sim.push_back(i); } return diff.size(); } char some(char a, char b) { char p = 'a'; for (int i = 0;...
9
#include <bits/stdc++.h> #pragma GCC optimize(3) using namespace std; const int INF = 0x3f3f3f3f; const long long LINF = 0x3f3f3f3f3f3f3f3f; const int MOD = 998244353; template <typename S, typename T> inline bool Min(S &a, const T &b) { return a > b ? a = b, true : false; } template <typename S, typename T> inline b...
18
#include <bits/stdc++.h> using namespace std; int find_father(vector<int>& f, int p) { if (f[p] == p) { return p; } return f[p] = find_father(f, f[p]); } int mark(vector<int>& f, vector<int>& ns, int p, int idx) { int cnt = 0; while (f[p] == -1) { f[p] = idx; p = ns[p]; cnt++; } return cnt...
13
#include <bits/stdc++.h> using namespace std; int n, k, m; vector<int> start[1000000 + 5], finish[1000000 + 5]; pair<int, int> cp[200005]; long long ans; long long cores[1000000 + 5], cost[1000000 + 5]; void update(int c, int p, int i) { for (; i <= 1000000; i += i & -i) { cores[i] += c; cost[i] += (long long...
12
#include <bits/stdc++.h> using namespace std; struct P { int x, y; bool operator<(const P &a) const { if (x != a.x) return x < a.x; return y < a.y; }; }; int a, b, c, d, i, n, m, e, k, dx[10] = {1, 0, -1, 0, 1, 1, -1, -1}, dy[10] = {0, 1, 0, -1, 1, -1, 1, -1}; int o[333331];...
7
#include <bits/stdc++.h> using namespace std; int main() { unsigned long long k1, k2, k3, t1, t2, t3, n; cin >> k1 >> k2 >> k3 >> t1 >> t2 >> t3 >> n; vector<unsigned long long> c(n); for (int i = 0; i < n; i++) cin >> c[i]; vector<unsigned long long> a1, a2, a3; a1.push_back(c[0] + t1); a2.push_back(c[0]...
10
#include <bits/stdc++.h> using namespace std; const long long MX = 1e5 + 9; const long double pi = acos(-1); bool cmp(int a, int b) { return a > b; } int a[MX]; int main() { int n; cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; } sort(a + 1, a + n + 1); long double ans = 0, c = 0; for (int i = ...
2
#include <bits/stdc++.h> using namespace std; int IN() { int x = 0, f = 0, ch; for (; (ch = getchar()) < '0' || ch > '9';) f = (ch == '-'); for (; ch >= '0' && ch <= '9'; (ch = getchar())) x = x * 10 + ch - '0'; return f ? -x : x; } int N, M, Ans, fa[200005]; long long Sum[200005], Bas[65]; vector<long long> Cy...
18
#include <bits/stdc++.h> using namespace std; int n, p, cds, i, j; bool t, ans; string s; int main() { cin >> n >> p >> s; cds = s.size(); while (1) { j = n; s[j - 1]++; while (j > 1 && s[j - 1] >= 'a' + p) { s[j - 1] -= p; s[--j - 1]++; } if (j == 1 && s[j - 1] >= 'a' + p) break; ...
9
#include <bits/stdc++.h> using namespace std; struct Node { Node *l = 0, *r = 0; int lo, hi; long long val = 0, forb = 0, baseval; Node(int lo, int hi, int odd) : lo(lo), hi(hi) { if (lo + 1 < hi) { int mid = lo + (hi - lo) / 2; l = new Node(lo, mid, odd); r = new Node(mid, hi, odd); ...
27
#include <bits/stdc++.h> using namespace std; const int INF = 2147483647; long long gcd(long long a, long long b) { if (a < b) { return gcd(b, a); } if (a % b == 0) { return b; } return gcd(b, a % b); } long long n, m, x, y, a, b; bool test(long long x1, long long y1, long long x2, long long y2) {} in...
9
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:1280000000") using namespace std; void solve(); void precalc(); clock_t start; int testNumber = 1; bool todo = true; int main() { start = clock(); int t = 1; cout.sync_with_stdio(0); cin.tie(0); precalc(); cout.precision(10); cout << fixed; int te...
15
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); int n; cin >> n; vector<long long> a(n), b(n); for (int i = 0; i < n; ++i) cin >> a[i] >> b[i]; long long ans = 0; for (int i = 0; i < n; ++i) { ans ^= a[i]; a[i] ^= b[i]; } int rk = 0; for (rk = 0; rk <...
16
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int x, y, z; cin >> x >> y >> z; int ans = -1; if (x > y + z) ans = 1; if (y > x + z) { if (ans == -1) ans = 2; else { cout << '?' << endl; return 0; ...
0
#include <bits/stdc++.h> using namespace std; template <class T> inline T _sq(T a) { return a * a; } template <class T> inline T _sqrt(T a) { return (T)sqrt((double)a); } template <class T, class X> inline T _pow(T a, X y) { T z = 1; for (int i = 1; i <= y; i++) { z *= a; } return z; } template <class T...
12
#include <bits/stdc++.h> const int inf = 0x3f3f3f3f; const int maxn = 3e5 + 10; using namespace std; int n; char s1[3], s2[3]; int a[3], b[3]; int ans[maxn]; int cnt[4], p[4]; void doo() { for (int i = 1; i <= 3 * n; i++) cout << ans[i]; cout << endl << endl; } bool ok() { for (int i = 1; i <= min(3 * n - 1, 36);...
11
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<pair<int, int>> xys(n); for (auto& xy : xys) cin >> xy.first >> xy.second; sort(xys.begin(), xys.end()); map<pair<int, int>, int> ma; for (int i = 0; i < xys.size(); ++i) { for (int j = i + 1; j < xys.size(); ++j) { ...
11
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5e4 + 5; int n, q; int w[N]; vector<int> g[N]; int W(char c) { if (c == '?') return 26; return c - 'a'; } set<int> st; int dep[N], cnt = 0, H = 0, p[N], id[N], fa[N]; vector<int> V[N]; void dfs(int u, int p) { fa[u] = p; dep[u] = dep[p] + 1; id...
22
#include <bits/stdc++.h> using namespace std; int main() { long long int p, y, i, flag = 0; cin >> p >> y; if (y % 2 == 0) y--; for (i = y; i > p; i -= 2) { long long int fl = 0; long long int temp = sqrt(y); long long int lo = min(temp, p); for (long long int j = 3; j <= lo; j += 2) { if ...
6
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n, ans = 0; cin >> n; int a[n]; for (int i = 0; i < n; i++) cin >> a[i]; int i = n - 1; while (a[i] <= a[i - 1] && i > 0) i--; while (a[i] >= a[i - 1] && i > 0) i--; cout << i << endl; }...
4
#include <bits/stdc++.h> using namespace std; void Emsawy() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); } const double PI = acos(-1.0); const double eps = 1e-10; const int mod = 1e9 + 7, oo = 1e9; int dx[]{1, -1, 0, 0, 1, -1, 1, -1}; int dy[]{0, 0, 1, -1, 1, -1, -1, 1}; int n, m, k, t, c; vector<vecto...
12
#include <bits/stdc++.h> using namespace std; int dp[320][320]; int a[4]; string s[] = {"BitLGM", "BitAryo"}; int n; int main() { cin >> n; for (int i = 0; i < n; ++i) cin >> a[i]; if (n == 1) cout << s[(a[0] == 0 ? 1 : 0)] << endl; else if (n == 3) cout << s[min(1, a[0] ^ a[1] ^ a[2]) ^ 1] << endl; e...
13
#include <bits/stdc++.h> using namespace std; const int MAXN = 500001; struct Edge { int y, next; } adj[MAXN * 2]; struct State { int size; long long f; } state[MAXN]; int fch[MAXN], size[MAXN]; long long f[MAXN], ans; int que[MAXN]; int n, m; void add(int u, int v) { adj[++m] = (Edge){v, fch[u]}; fch[u] = m;...
19
#include <bits/stdc++.h> using namespace std; template <class T> class TSegmentTree { public: virtual T combine(const T& a, const T& b) = 0; virtual T neutral() = 0; virtual void push_value(T& dst, const T& src, int len) {} vector<T> t; int n; T neutral_; void init(int n_) { n = n_; t.resize(4 * ...
14
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { long long n, k; cin >> n >> k; long long cnt = 0; if (n < k) { cnt = n; cout << cnt << endl; } else { while (n != 0) { long long d; if (n % k == 0) { n = n / k;...
1
#include <bits/stdc++.h> using namespace std; int main() { int n, m; while (cin >> n >> m) { if (n == 1 || m == 1) { printf("%d\n", m + n - 1); continue; } if (n == 2 || m == 2) { int k = 0; if ((m + n - 2) % 4 == 1) k = 2; int ct = (m + n - 2) / 2; ct = ((ct + 1) / 2...
10
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 5; const int dy[] = {0, 1, 1, 1, 0, -1, -1, -1}; const int dx[] = {1, 1, 0, -1, -1, -1, 0, 1}; bool used[350][350][8][35], a[350][350]; int t[35], n; void dfs(int x, int y, int dir, int rec) { if (used[x][y][dir][rec]) return; used[x][y][dir][rec]...
11