solution
stringlengths
53
181k
difficulty
int64
0
13
#include <bits/stdc++.h> using namespace std; int q[100010], t, n; bool cmp(int a, int b) { return a < b; } int main() { scanf("%d", &t); for (int i = 1; i <= t; i++) { scanf("%d", &n); for (int j = 1; j <= n; j++) { scanf("%d", &q[j]); } int flag = 1; sort(q + 1, q + n + 1, cmp); for ...
0
#include <bits/stdc++.h> using namespace std; const int N = 100005; int n; char ch[N]; unsigned f[N]; int main() { scanf("%d%s", &n, ch + 1); if (n & 1) return puts("0"), 0; f[0] = 1; int m = n / 2, q = 0; for (int i = 1; i <= n; i++) if (ch[i] == '?') for (int j = i >> 1; n - i + j >= m && j; j--) ...
10
#include <bits/stdc++.h> using namespace std; int mon[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; map<string, int> mp; vector<pair<int, string> > vis; int isCorrect(string s) { int year, month, day; if (s[0] == '-' || s[1] == '-' || s[3] == '-' || s[4] == '-' || s[6] == '-' || s[7] == '-' || s[...
4
#include <bits/stdc++.h> using namespace std; const long long M = 1e9 + 1; bool f = false; map<string, int> mp, mp_2; set<long long> st; string s, p, q; int main() { ios::sync_with_stdio(false); cin.tie(0); long long tt, a, b, d = 0, sum = 0, sum_2; vector<long long> v, v_2; cin >> tt >> b; while (tt--) { ...
2
#include <bits/stdc++.h> using namespace std; const int maxn = 4e5 + 5; int a[maxn]; int dp[maxn]; int dif[maxn]; int n, I, k; int main() { scanf("%d%d", &n, &I); I *= 8; k = I / n; k = 1 << min(k, 20); for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); } sort(a + 1, a + n + 1); dp[0] = 0; int num...
4
#include <bits/stdc++.h> using namespace std; long long mod = 95542721; struct node { long long sums[48]; int indx, lazy; node() { indx = 0, lazy = 0; } long long val() { return sums[indx]; } }; node st[4 * (int)1e5 + 100]; int n; long long a[(int)1e5 + 100]; void mrg(int p) { int id1 = st[2 * p].indx; int ...
9
#include <bits/stdc++.h> using namespace std; const int kMaxR = 505, kMaxN = 1e5 + 5, kInf = 0x3f3f3f3f; int r, n, X[kMaxN], Y[kMaxN], T[kMaxN]; int f[kMaxN]; int main() { scanf("%d %d", &r, &n); for (int i = 1; i <= n; ++i) { scanf("%d %d %d", T + i, X + i, Y + i); } int res = 0, cur = 0, ans = 0; fill(f...
6
#include <bits/stdc++.h> int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); size_t n; std::cin >> n; std::string result = "ROYGBIV"; while (result.size() < n) { result += result[result.size() - 4]; } std::cout << result << '\n'; }
2
#include <bits/stdc++.h> using namespace std; const int N = 205; inline int read() { int f = 1, x = 0; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = x * 10 + ch - 48; ch = getchar(); } return f * x; } int n...
5
#include <bits/stdc++.h> using namespace std; int d[1 << 13]; int j[1 << 13][32]; int jcost[1 << 13][32]; int parentedge[1 << 13]; struct Edge { int u, v, w; Edge(int u, int v, int w) : u(u), v(v), w(w){}; }; vector<Edge> edges; vector<int> adj[1 << 13]; int N; void dfs(int u, int p, int pc, int dist, int pe) { j...
6
#include <bits/stdc++.h> using namespace std; int main() { char board[10][10]; int i, j, w = 0, b = 0; for (i = 0; i < 8; i++) for (j = 0; j < 8; j++) { cin >> board[i][j]; if (board[i][j] >= 'A' && board[i][j] <= 'Z') { if (board[i][j] == 'Q') w = w + 9; if (board[i][j] == 'R') w ...
0
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); int n; cin >> n; int a[n][n]; long long l[n][n], r[n][n]; for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { cin >> a[i][j]; l[i][j] = r[i][j] = a[i][j]; } } for (int i = 0; i < n; +...
5
#include <bits/stdc++.h> using namespace std; bool debug = 1; int n, m, k; int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0}; long long ln, lk, lm; struct point { int x, y; }; point b[2105], r[2105]; bool cmpb(point p, point q) { if (p.y == q.y) return p.x < q.x; return p.y < q.y; } bool cmpr(point p, point q) { ...
9
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using pii = pair<int, int>; const int maxn = 5e5 + 100; const int mod = 1e9 + 7; mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count()); vector<int> add[2 * maxn], rem[2 * maxn]; int par[maxn], siz[maxn], e...
6
#include <bits/stdc++.h> using namespace std; int main() { int n, k, i = 0; char c = 'c'; cin >> n >> k; if (k > n || (k == 1 && n > 1) || n + k == 2) { n + k == 2 ? cout << 'a' : cout << "-1"; return 0; } k -= 2; n -= k; while (n--) { cout << (i % 2 == 0 ? 'a' : 'b'); i++; } while (...
2
#include <bits/stdc++.h> using namespace std; bool a[1100]; int n, k; int d[3100]; bool v[3100]; vector<int> u; int main() { scanf("%d%d", &n, &k); for (int i = 1; i <= k; i++) { int t; scanf("%d", &t); if (a[t] == 0) { u.push_back(t - n); a[t] = 1; } } queue<int> q; q.push(1000); ...
7
#include <bits/stdc++.h> using namespace std; int main() { int n, i, k, a[3 * 100000 + 5]; long long int res, tt; scanf("%d", &n); for (i = tt = 0; i < n; i++) scanf("%I64d", &a[i]), tt += a[i]; sort(a, a + n); res = tt; for (i = 0; i < n; i++) { res += a[i]; tt -= a[i]; res += tt; } print...
2
#include <bits/stdc++.h> using namespace std; const double eps = 1e-9, PI = acos(-1); const int N = 2e5 + 5, oo = 1e6, M = 1e5 + 5; int32_t main() { int n; cin >> n; int last[N]; for (int i = 0; i < N; i++) last[i] = 1e6; for (int i = 1; i <= n; i++) { int a; cin >> a; last[a] = i; } int mn = ...
1
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:5000000000") const long long mod = 1000000007; long long Inf = (long long)2e9; long long LINF = (long long)1e18 + 1e17; using namespace std; int main() { int n; double m; cin >> n >> m; double ans = Inf; for (int(i) = 0; (i) < n; (i)++) { double a, ...
0
#include <bits/stdc++.h> using namespace std; const long long mod = 998244353, mod2 = 1e9 + 9, p1 = 5807, p2 = 8573; const long long N = 2e4 + 5, M = 21; const long double pi = acos(-1); long long power(long long x, unsigned long long y, long long p) { long long res = 1; x = x % p; while (y > 0) { if (y & 1) ...
8
#include <bits/stdc++.h> int main() { int n, s = 0; scanf("%d", &n); char a[200]; scanf("%s", &a); for (int i = 0; a[i] != '\0'; i++) { if (a[i] == 120) s++; } if (s == n / 2) { printf("0\n"); puts(a); } else { int c = s; if (s < n / 2) { for (int i = 0; i < n; i++) { i...
0
#include <bits/stdc++.h> using namespace std; const int MAXN = 505; const int MAXM = MAXN * MAXN * 2; int n, m, que[MAXM], head, tail, pre[MAXN], tim, g[MAXN], tot, match[MAXN], fa[MAXN], type[MAXN], tic[MAXN]; int u[MAXN], v[MAXN]; struct edge { int to, next; } e[MAXM]; int findf(int x) { return fa[x] == x ? fa[...
7
#include <bits/stdc++.h> using namespace std; int IsPrime(int k) { for (int u = 2; u * u <= k; u++) if (k % u == 0) return false; return (k != 1); } int printnum(int num, int base) { int curr = 0, ans[10]; while (num != 0) { ans[curr++] = num % base; num /= base; } for (int x = curr - 1; x >= 0;...
2
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const int maxn = 2e2 + 6e1; const int mod = 1e9 + 7; const double eps = 1e-5; const double pi = asin(1.0) * 2; const double e = 2.718281828459; void fre() { freopen("in.txt", "r", stdin); } int n, k; int p[maxn]; int input; int temp; int main() {...
4
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:20000000") using namespace std; int ri() { int x; scanf("%d", &x); return x; } long long rll() { long long x; scanf("%I64d", &x); return x; } int mas[1000 * 1050]; void solve() { int n = ri(); mas[0] = 0; for (int i = (int)(1); i <= (int)(n); i+...
1
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf("%d", &n); (n % 2 == 0) ? printf("%d", n / 2 - 1) : printf("%d", n / 2); return 0; }
1
#include <bits/stdc++.h> using namespace std; const int maxm = (1 << 14) + 5; int pv[maxm], nw[maxm]; int r[maxm]; int num[maxm]; int a[maxm]; int root(int x) { return x == r[x] ? x : r[x] = root(r[x]); } int main() { ios::sync_with_stdio(false); cin.tie(0); int n, m, ans = 0; cin >> n >> m; for (int i = 0; i...
8
#include <bits/stdc++.h> using namespace std; using lli = long long int; using pii = pair<int, int>; using vi = vector<int>; using vb = vector<bool>; using vvi = vector<vector<int>>; using vlli = vector<long long int>; using vpii = vector<pair<int, int>>; int main() { ios_base::sync_with_stdio(false); cin.tie(0); ...
0
#include <bits/stdc++.h> using ll = long long; using namespace std; const int INF = 1e9 + 7; void fail() { cout << "No\n"; exit(0); } struct DD { ll up, down; DD(int u, int d) : up(u), down(d) {} bool operator<(const DD& other) { return up * other.down < down * other.up; } }; int main() { ios_base::sync_wit...
4
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 5; vector<int> G[maxn]; int dis[maxn], n, ans = 0; void dfs(int x, int step) { dis[step]++; for (int i = 0; i < G[x].size(); i++) { int u = G[x][i]; dfs(u, step + 1); } } int main() { int m; scanf("%d", &n); for (int i = 2; i <= n;...
3
#include <bits/stdc++.h> using namespace std; long long w, m, carry; vector<int> vec; int main() { ios_base::sync_with_stdio(0); cin >> w >> m; while (m) { vec.push_back(m % w); m /= w; } for (auto &e : vec) { long long cur = (e + carry) % w; if (cur == 0 or cur == 1) { carry = (e + carr...
5
#include <bits/stdc++.h> using namespace std; #define int long long const int max_n = 200005, mod = 1000000007; int dp[max_n]; signed main(){ for(int i=0; i<9; i++)dp[i] = 2; dp[9] = 3; for(int i=10; i<max_n; i++){ dp[i] = (dp[i-9] + dp[i-10])%mod; } ios_base::sync_with_stdio(false); ...
4
#include <bits/stdc++.h> using namespace std; int main() { long long int n, k; cin >> n >> k; vector<long long int> c; for (long long int i = 1; (long long)i * i <= (n); i++) { if (n % i == 0) { c.push_back(i); if ((n / i) != i) c.push_back(n / i); } } sort(c.begin(), c.end()); if (k >...
3
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); int n; cin >> n; vector<string> a(n + 1), b(n + 1); vector<int> c(n + 1); vector<long long> f1(n + 1), f2(n + 1); for (int i = 1; i <= n; ++i) { cin >> c[i]; } for (int i = 1; i <= n; ++i) { cin >> a[i]; ...
4
#include <bits/stdc++.h> int ara[1001]; int main() { int a, b, t; scanf("%d", &t); for (int i = 1; i < t; i++) { scanf("%d%d", &a, &b); ara[a]++; ara[b]++; } int c = 0; for (int i = 1; i <= t; i++) { if (ara[i] == 1) c++; } printf("%d\n", c); return 0; }
1
#include <bits/stdc++.h> using namespace std; int main() { int x, t, a, b, da, db; cin >> x >> t >> a >> b >> da >> db; if (x == 0) { cout << "YES" << endl; return 0; } if ((x <= a && x > a - da * t && (a - x) % da == 0) || (x <= b && x > b - db * t && (b - x) % db == 0)) { cout << "YES" << ...
2
#include <bits/stdc++.h> using namespace std; #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define sz(x) (x).size() #define FT(x) get<0>(x) #define ST(x) get<1>(x) #define TT(x) get<2>(x) #define pb push_back #define endl '\n' #define F first #define S second typedef long double ld...
4
#include <bits/stdc++.h> using namespace std; long long mod = pow(10, 9) + 7; int gcdExtended(int a, int b, int *x, int *y); int modInverse(int b, int m) { int x, y; int g = gcdExtended(b, m, &x, &y); if (g != 1) return -1; return (x % m + m) % m; } int gcdExtended(int a, int b, int *x, int *y) { if (a == 0) ...
4
#include <bits/stdc++.h> const int MOD = 1e9 + 7; using namespace std; int main() { long long t, n, m, a; cin >> t; for (int jjj = 0; jjj < t; jjj++) { long long cnt = 0; string s; vector<pair<string, long long> > v; cin >> n >> s; string t = s; for (int i = 0; i < n; i++) { cnt = 0;...
3
#include <bits/stdc++.h> using namespace std; const long long inf = 1e18 + 9; const int mod = 1e9 + 7; string s1[] = {"cool", "not bad", "don't touch me!", "don't think so", "great"}; string s2[] = {"terrible", "worse", "go die in a hole", "are you serious?", "don't even", "no way"}; int mai...
5
#include <bits/stdc++.h> using namespace std; string arr[] = { "111111101010101111100101001111111", "100000100000000001010110001000001", "101110100110110000011010001011101", "101110101011001001111101001011101", "101110101100011000111100101011101", "100000101010101011010000101000001", "111111101010101010...
3
#include <bits/stdc++.h> using namespace std; const long long N = 1e5 + 2; long long solve() { long long n; cin >> n; long long a[n]; map<long long, long long> mp; long long ans = 0; for (long long i = 0; i < n; i++) { cin >> a[i]; mp[a[i] - i - 1] += a[i]; ans = max(ans, mp[a[i] - i - 1]); } ...
3
#include <bits/stdc++.h> using namespace std; const long long INF64 = 3e18; const int mod = (int)1e9 + 7; const int MAX_N = 100000 + 5; long long binp(long long a, long long b) { if (b == 0) return 1; long long ans = binp(a, b / 2); long long tmp = (ans * ans); if (b % 2) return ((tmp * a)); return ((tmp)); }...
1
#include <bits/stdc++.h> using namespace std; const int maxn = 100200; int main() { char ch[20]; int ans = 0; for (int i = 0; i < 8; i++) { scanf("%s", ch); for (int j = 0; j < 8; j++) { if (ch[j] == 'Q') ans += 9; else if (ch[j] == 'q') ans -= 9; if (ch[j] == 'R') ...
0
#include <bits/stdc++.h> using namespace std; long long int max(long long int a, long long int b) { if (a > b) return a; return b; } long long int min(long long int a, long long int b) { if (a < b) return a; return b; } long long int msb(long long int n) { long long int ans; for (long long int i = 31; i >= ...
5
#include <bits/stdc++.h> using namespace std; long long sum[1000007]; int cnta; long long Pow(long long x, long long y) { long long res = 1; while (y > 0) { if (y & 1) res = (res * x) % 1000000007; x = (x * x) % 1000000007; y >>= 1; } return res; } void solve() { sum[0] = 1; for (int i = 1; i < ...
3
#include <bits/stdc++.h> using namespace std; const long long INF = 1e18; const int32_t M = 1e9 + 7; const int32_t MM = 998244353; void solve() { int n; cin >> n; vector<pair<long long int, long long int>> v(n); for (int i = 0; i < n; i++) { cin >> v[i].first; v[i].second = i + 1; } sort((v).begin()...
4
#include <bits/stdc++.h> using namespace std; long long int checkyear(char ch1, char ch2, char ch3, char ch4) { if (ch1 == '2' && ch2 == '0' && ch3 == '1' && (ch4 == '3' || ch4 == '4' || ch4 == '5')) return 1; else return 0; } long long int checkmonth(char ch1, char ch2) { if (ch1 == '0' && ch2 == '...
4
#include <bits/stdc++.h> using namespace std; vector<int> D[100005]; long long dfffs[100006]; const long long p = 1e9 + 7; void dfs_1(int u, int v) { dfffs[u] = 1; int odw = 0; for (int i = 0; i < D[u].size(); i++) { int f = D[u][i]; if (f != v) { odw = 1; dfs_1(f, u); dfffs[u] = (dfffs[...
6
#include <bits/stdc++.h> using namespace std; const int maxn = 100100; const int INF = 1E9; char s[10 * maxn]; char st[10 * maxn]; int top = 0; bool open(char c) { if (c == '{') return 1; if (c == '[') return 1; if (c == '(') return 1; if (c == '<') return 1; return 0; } bool eq(char c, char d) { if (c == '...
3
#include <bits/stdc++.h> const int N = 35; bool vis[N]; long long ans = 0; int n, u, r, p[N], K[N], b[N]; long long a[N]; void dfs(int idx) { if ((u - idx) % 2 == 0) { long long get = 0; for (int i = 1; i <= n; ++i) get += (long long)a[i] * K[i]; if (get > ans) ans = get; } if (u == idx) return; lon...
6
#include <bits/stdc++.h> using namespace std; const long double pi = 3.14159265358979323846; long long MOD = 998244353; const char nl = '\n'; const long long inf = 1e15; long long mul(long long x, long long y) { return (1ll * (x % MOD) * (y % MOD)); } long long modpow(long long x, long long y) { long long z = 1; ...
3
#include <bits/stdc++.h> using namespace std; int main() { long long b; cin >> b; long long cnt = 0; for (long long i = 1; i * i <= b; i++) { if (b % i == 0) { if (i * i == b) { cnt++; } else cnt += 2; } } cout << cnt; }
2
#include <bits/stdc++.h> using namespace std; const double pi = acos(0.0) * 2.0; const double eps = 1e-12; const int step[8][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}, {1, 1}, {1, -1}, {-1, 1}, {-1, -1}}; template <class T> inline T abs1(T a) { return a < 0 ? -a : a; } template <class T> inline ...
4
#include <bits/stdc++.h> using namespace std; using Int = long long; void solve() { Int n; cin >> n; vector<Int> a(n); for (Int i = 0; i < n; i++) cin >> a[i]; vector<Int> cnt(n + 1); vector<unordered_map<Int, Int>> nxt(n + 1); Int ans = 0; for (Int i = n - 1; i >= 0; i--) { if (nxt[i + 1].count(a[i...
9
#include <bits/stdc++.h> using namespace std; int main() { int k; cin >> k; switch (k) { case 0: cout << "+------------------------+" << endl; cout << "|#.#.#.#.#.#.#.#.#.#.#.|D|)" << endl; cout << "|#.#.#.#.#.#.#.#.#.#.#.|.|" << endl; cout << "|#.......................|" << endl; ...
1
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); string s; cin >> s; long long i; vector<long long> v; long long p = s.length(); long long pp = 0; for (i = 0; i <= p - 1; i++) { if (s[i] != 'a') { v.push_back(i); pp++; } } long lon...
2
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1.0); const double eps = 1e-8; struct Tpoint { double x, y; Tpoint() {} Tpoint(double _x, double _y) { x = _x; y = _y; } inline void read() { scanf("%lf%lf", &x, &y); } inline void show() { printf("%lf %lf\n", x, y); } inline do...
4
#include <bits/stdc++.h> using namespace std; const int N = 200006; const int MAX = 1000 * 100 + 1; const long long INF = 1e18; const int MOD = 1000 * 1000 * 1000 + 7; const int dx[8] = {-1, -1, -1, 0, 1, 1, 1, 0}; vector<long long> v[N], v1, v2; long long a[N], b[N]; int main() { ios_base::sync_with_stdio(0); cin....
3
#include <bits/stdc++.h> using namespace std; using ll = long long; const int N = 500100, mod = 998244353; int n, tt, m; void fn() { cin >> n; cout << n - 1 << endl; for (int i = 2; i <= n; i++) { cout << i << " "; } cout << endl; return; } int main() { ios::sync_with_stdio(0); cin.tie(0); ; cin...
0
#include <bits/stdc++.h> using namespace std; char s[10000]; int main() { int n; cin >> n; getchar(); long long int *a = new long long int[1000]; long long int count = 1; long long int count1 = 1; for (int i = 1; i <= n; i++) { cin.getline(s, sizeof(s)); long long int v1 = (s[1] - '0') * 10 + (s[2...
5
#include <bits/stdc++.h> using namespace std; int a[101]; int main() { int n, i, j; cin >> n; for (i = 0; i < n; i++) { cin >> j; a[j]++; } int numbox = 0, piles = 0, flag; while (1) { numbox = 0; flag = 0; for (i = 0; i <= 100; i++) { if (a[i] > 0 && numbox <= i) { flag = ...
3
#include <bits/stdc++.h> using namespace std; void run() { long long n, m; cin >> n >> m; long long cl, ce, v; cin >> cl >> ce >> v; vector<long long> stairs(cl); for (int i = 0; i < cl; ++i) { cin >> stairs[i]; } vector<long long> lift(ce); for (int i = 0; i < ce; ++i) { cin >> lift[i]; } ...
4
#include <bits/stdc++.h> using namespace std; int main() { string s, r; cin >> s >> r; reverse(s.begin(), s.end()); if (s == r) cout << "YES" << endl; else cout << "NO" << endl; return 0; }
0
#include<bits/stdc++.h> #define rep(i,a,b) for(int i=a;i<b;i++) #define ret(x) return cout<<x,0; #define rety return cout<<"YES",0; #define retn return cout<<"NO",0; typedef long long ll; typedef double db; typedef long double ld; #define stt string #define ve vector<ll> #define se set<ll> #define ar array ll mod=1e...
1
#include <bits/stdc++.h> using namespace std; int main() { int arr[101], arr1[101]; int n, m; cin >> n >> m; int flag = 0; for (int i = 0; i < n; i++) { cin >> arr[i]; } for (int i = 0; i < m; i++) { cin >> arr1[i]; } int max1 = arr[0]; int min1 = arr[0]; for (int i = 0; i < n; i++) { ...
2
#include <bits/stdc++.h> using namespace std; int main() { long long t, tc; cin >> tc; for (t = 1; t <= tc; t++) { long long i, p, q, n, x, y, prex, prey, a, b, j, flag = 0; string s = ""; cin >> n; vector<pair<long long, long long>> v; for (i = 0; i < n; i++) { cin >> p >> q; v.pu...
2
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const int _inf = 0xc0c0c0c0; const long long INF = 0x3f3f3f3f3f3f3f3f; const long long _INF = 0xc0c0c0c0c0c0c0c0; const long long mod = (int)1e9 + 7; long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } long long ksm(long lon...
4
#include <bits/stdc++.h> inline int read() { char c; int x; for (c = getchar(); !isdigit(c); c = getchar()) ; for (x = 0; isdigit(c); c = getchar()) { x = x * 10 + c - '0'; } return x; } const int N = 1e6 + 5; int n, k, s, t, rs, rt, len, ans0, a[N], b[N], ft[N], dis[N], dit[N], deg[N]; long long an...
2
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s; vector<vector<int> > v(n, vector<int>(7, 0)); for (int i = 0; i < n; i++) { cin >> s; for (int j = 0; j < 7; j++) v[i][j] = s[j] - '0'; } vector<int> cnt(7, 0); for (int i = 0; i < 7; i++) { for (int j = 0;...
0
#include <bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; int debug = 0; const int N = 2e5 + 10, C = 470; int n, k, freq, alone, ans, q, a[N], p[N], was[N * 3], cnt[N], id[N]; vector<array<int, 2>> cnts; vector<int> clrs; int main() { cin >> n; for (int i = 1; i < n + 1; ++i) { cin >> a[i]; c...
9
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; int n, i, a[200005], temp; int main() { scanf("%d", &n); for (i = 0; i < n; i++) scanf("%d", &a[i]); sort(a, a + n); temp = 1e9 + 7; for (i = 0; i < n / 2; i++) { temp = min(temp, a[i + n / 2] - a[i]); } printf("%d\n", temp); }
7
#include <bits/stdc++.h> using namespace std; int main() { int sum = 0; bool flag = false, flag0 = false; string s; cin >> s; for (int i = 0; i < s.length(); ++i) { if (s[i] == '1') flag0 = true; if (flag0 && s[i] == '0') ++sum; if (sum == 6) { flag = true; break; } } cout << (...
1
#include <bits/stdc++.h> using namespace std; mt19937 mt_rand( chrono::high_resolution_clock::now().time_since_epoch().count()); const int N = 2e5; const int HS = 3; int MOD[HS]; struct hash_number { int v[HS]; hash_number() { memset(v, 0, sizeof v); } hash_number(long long x) { for (int i = 0; i < HS; i+...
7
#include <bits/stdc++.h> using namespace std; int main() { long long int n; cin >> n; vector<long long int> a(n); vector<long long int> b; for (long long int i = 0; i < n; i++) cin >> a[i]; sort(a.begin(), a.end()); long long int diff = LLONG_MAX; long long int c = 1; for (long long int i = 0; i < n -...
1
#include <bits/stdc++.h> using namespace std; long long SUM = 0; int n, m, a[10001]; int main() { cin >> n >> m; for (int i = 0; i < n; i++) { cin >> a[i], SUM += a[i]; } sort(a, a + n); if (SUM - a[n - 1] > m) { cout << "NO"; } else cout << "YES"; return 0; }
0
#include <bits/stdc++.h> using namespace std; vector<long long int> v, a1, b1; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long int n, k; cin >> n >> k; pair<long long int, pair<long long int, long long int> > p[n]; for (long long int i = 0; i < n; i++) { long lo...
4
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 5; char s[maxn], t[maxn]; int pos[maxn][26]; int main() { int T; scanf("%d", &T); while (T--) { scanf("%s%s", s, t); memset(pos, 0x3f3f3f3f, sizeof(pos)); for (int i = strlen(s) - 1; i >= 0; i--) { for (int j = 0; j < 26; j++) ...
4
#include <bits/stdc++.h> using namespace std; void fun() {} long long int __gcda(long long int a, long long int b) { if (b == 0) { return a; } else if (a == 0) { return b; } else if (a == b) { return a; } else if (b > a) { return __gcda(a, b % a); } else if (a > b) { return __gcda(a % b, b...
4
#include <bits/stdc++.h> using namespace std; const int N = 55; int n; char s[N][N]; int dp[N][N][N][N]; int solve(int a, int b, int x, int y) { if (dp[a][b][x][y] != -1) return dp[a][b][x][y]; if (a == x && b == y) return s[a][b] == '#'; int ans = max(x - a + 1, y - b + 1); for (int i = a; i < x; i++) ans ...
7
#include <bits/stdc++.h> const int N = 200000; const int MOD = (int)1e9 + 7; void update(int& x, int a) { x += a; if (x >= MOD) { x -= MOD; } } int head[N], to[N], next[N], degree[N]; bool visited[N], used[N]; void solve(int n, int* ways, int s) { std::vector<int> edges; int v = s; while (true) { vi...
10
#include <bits/stdc++.h> using namespace std; const long long MOD = 1000000007; const long long MOD1 = 998244353; const long long MIN_LL = -1e18; const long long MAX_LL = 1e18; const int MAX_INT = 1e9; const int MIN_INT = -1e9; const long double pie = 3.1415926535; long long fpow(long long n, long long p) { ; long ...
0
#include <bits/stdc++.h> using namespace std; int t, n, mint = 99999999, minn, ans; struct bus { int s, d; }; bus x; int bl[10001]; int main() { scanf("%d%d", &n, &t); for (int i = 1; i <= n; i++) { scanf("%d%d", &x.s, &x.d); if (x.s < t) { ans = t - x.s; ans = ans % x.d; if (ans == 0) {...
1
#include <bits/stdc++.h> using namespace std; template <typename T> class binary_indexed_tree { vector<T> _t; T sum(int r) { T result = 0; while (r > 0) { result += _t[r]; r = (r & (r + 1)) - 1; } return result; } public: binary_indexed_tree(const size_t n) { _t.assign(n + 1, 0); }...
7
#include <bits/stdc++.h> using namespace std; int n; char a[100005]; int ans[100005]; int main() { scanf("%s", a); n = strlen(a); int cnt = 0, s_cnt = 0, last = -1; for (int i = 0; i < n; ++i) { if (a[i] == '(') cnt++; else cnt--; if (cnt < 0) { printf("-1"); return 0; } ...
3
#include <bits/stdc++.h> using namespace std; vector<unsigned long long int> vec; void factors(unsigned long long int n) { if (n % 2LL == 0) { while (n % 2LL == 0) { n /= 2LL; vec.push_back(2LL); } } for (unsigned long long int i = 3; i * i <= n; i += 2) { if (n % i == 0) { while (n ...
3
#include <bits/stdc++.h> using namespace std; struct node { long long x, y; int id; } s[200005]; struct Bridge { long long x; int id; bool operator<(const Bridge &A) const { if (x != A.x) return x < A.x; return id < A.id; } } bg[200005]; set<Bridge> st; set<Bridge>::iterator it; bool cmp(node A, nod...
6
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); string s; cin >> s; int n = s.length(); int posH = INT_MAX, posE = INT_MAX, posI = INT_MAX, posD = INT_MAX, posI2 = 0; for (int i = 0; i < n; i++) { if (s[i] == 'h') { posH = i; } if (s[i] == ...
0
#include <bits/stdc++.h> using namespace std; using namespace std; const long long mod = 1e9 + 7; int arr[601]; int main() { std::ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, m, k, i, j, x, y, z; int t, r; memset(arr, 0, sizeof(arr)); cin >> m >> t >> r; vector<long long> a(m); for (i ...
4
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int ch = 0, c = 0, i = 0; string x; cin >> x; while (x[i] == 'a') { i++; } if (i == x.length()) { x[x.length() - 1] = 'z'; } else { for (i; i < x.size(); i++) { if (x[i] == 'a') { ...
2
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") using namespace std; const int INF = 2e9 + 9; const long long INF1 = 1e18 + 9; const long long MAXN = 2e5 + 7; const long long MAXN1 = 1 << 11; const long long MAXN2 = 4e6 + 9; const long long MOD = 998244353; const long long MOD1 = 1e9 + 9; const long long ALPH = ...
8
#include <bits/stdc++.h> using namespace std; using ll = long long; signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long T = 1; cin >> T; while (T--) { long long n, k; cin >> n >> k; vector<long long> mon(n); vector<long long> peaks(n, 0); for (long long i = 0; i < n;...
2
#include <bits/stdc++.h> using namespace std; inline int gcd(int a, int b) { while (1) { a = a % b; if (a == 0) return b; b = b % a; if (b == 0) return a; } } const int maxN = 1000 + 100; const int inf = 1e9; int a[3]; inline int f(int b, int c, int d) { if (b == 1) return c * d; else re...
2
#include <bits/stdc++.h> #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #pragma GCC target("avx2") using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long k; cin >> k; long long pref = 0; vector<long long> poww10(17); poww10[0] = 1; for (int i = 1; i...
5
#include <bits/stdc++.h> using namespace std; int main() { long long n, k, c = 1; cin >> n >> k; while (true) { while (k - 3 >= 0 && (n - c) * 2 <= k - 3 && c <= n && c++) k -= 3; while (k - 4 >= 0 && (n - c) * 2 <= k - 4 && c <= n && c++) k -= 4; while (k - 5 >= 0 && (n - c) * 2 <= k - 5 && c <= n &&...
0
#include <bits/stdc++.h> using std::max; using std::min; const int inf = 0x3f3f3f3f, Inf = 0x7fffffff; const long long INF = 0x3f3f3f3f3f3f3f3f; std::mt19937 rnd(std::chrono::steady_clock::now().time_since_epoch().count()); template <typename _Tp> _Tp gcd(const _Tp &a, const _Tp &b) { return (!b) ? a : gcd(b, a % b);...
11
#include <bits/stdc++.h> using namespace std; int l; char a[200010], b[200010]; int main() { scanf("%s", a); l = 0; for (int i = 0; a[i]; i++) if (l == 0 || a[i] != b[l - 1]) b[l++] = a[i]; else l--; b[l++] = 0; puts(b); return 0; }
3
#include <bits/stdc++.h> using namespace std; vector<int> adj[100000 + 5], ans1, ans2; int color[100000 + 5]; bool ok = 1; void dfs(int u, int col) { color[u] = col; int sz = adj[u].size(); for (int i = 0; i < sz; ++i) { int v = adj[u][i]; if (color[v] == -1) { dfs(v, 1 - col); } else { if...
3
#include <bits/stdc++.h> using namespace std; void solve() { int r1, r2, c1, c2, d1, d2; cin >> r1 >> r2 >> c1 >> c2 >> d1 >> d2; for (int i = 1; i < 10; i++) { for (int j = 1; j < 10; j++) { if (i + j == r1 && i != j) { for (int k = 1; k < 10; k++) { if (i + k == c1 && k + j == d2 && ...
1
#include <bits/stdc++.h> using namespace std; const int maxN = 1e3 + 13; int k, q, n; double dp[maxN * 30][maxN]; vector<pair<double, int>> vec; int main() { cin >> k >> q; n = k * log2(k) + 13; for (int i = 1; i < n; i++) { for (int j = 1; j <= k; j++) { if (i == 1 && j == 1) dp[i][j] = 1; ...
7