solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> using namespace std; const long long inf = 1e10; int t; long long k, f[20][20], c[20][20]; int cnt[17]; int enter() { cin >> k >> t; return 0; } int init() { c[0][0] = 1; for (int i = 1; i <= 20; i++) { c[i][0] = 1; for (int j = 1; j <= i; j++) c[i][j] = min(inf, c[i - 1][...
17
#include <bits/stdc++.h> using namespace std; pair<int, int> pr[1050]; map<int, char> mp; int main() { int n; cin >> n; for (int i = 0; i <= n; i++) { cin >> pr[i].first >> pr[i].second; } int sum = 0; for (int i = 1; i <= n; i++) { if (pr[i].first == pr[i - 1].first) { if (pr[i].second < pr[i...
7
#include <bits/stdc++.h> using namespace std; const int mod = 1000000007; const int inf = 0x3f3f3f3f; const double eps = 1e-8; const double pi = acos(-1.0); int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(); int n; while (cin >> n) { int cnt = 0; for (int i = 1; i < n; i++) if ((n...
0
#include <bits/stdc++.h> int main() { int n, i, l, r, room[10] = {0}; scanf("%d ", &n); char c; for (i = 0; i < n; i++) { scanf("%c", &c); for (l = 0; l < 10; l++) if (room[l] == 0) break; for (r = 9; r >= 0; r--) if (room[r] == 0) break; if (c == 'L') room[l] = 1; else if ...
0
#include <bits/stdc++.h> #pragma comment(linker, "/stack:200000000") #pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #pragma GCC optimize("unroll-loops") using namespace std; template <class T> inline T bigmod(T p, T e, T M) { long long ret = 1; for (; e >...
9
#include <bits/stdc++.h> using namespace std; int n, ans = 0; void dfs(int s) { if (s > 0 && s <= n) ans++; if (s >= 100000000) return; for (int i = 0; i <= 9; i++) { int t = s * 10 + i; int cnt[10] = {0}; while (t) { cnt[t % 10]++; t /= 10; } int temp = 0; for (int j = 0; j <=...
8
#include <bits/stdc++.h> using namespace std; const long long P = 998244353; const int INF = 0x3fffffff; const int N = 1005; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); set<int> s1[N], s2[N]; int a[N][N], b[N], nc[N], nr[N], ranki[N][N], rankj[N][N]; int m, n; int main() { scanf("%d%d", &n, &...
8
#include <bits/stdc++.h> using namespace std; int main() { int i, j, n, k; cin >> n; string s[n], t; vector<vector<int> > v(n, vector<int>(3, 0)); for (i = 0; i < n; i++) { cin >> k >> s[i]; for (j = 0; j < k; j++) { cin >> t; if (t[0] == t[1] && t[1] == t[3] && t[3] == t[4] && t[4] == t[6...
4
#include <bits/stdc++.h> using namespace std; const int MAXN = 5003; const int MOD = 1000000007; int n, a, b, k; int dp[MAXN][MAXN]; int ADD(long long a, long long b) { return (a + b) % MOD; } int SUB(long long a, long long b) { return (a - b + MOD) % MOD; } void fill_dp() { for (int i = 1; i <= n; ++i) { dp[0][i...
11
#include <bits/stdc++.h> using namespace std; int main() { int n, k, l, d, c, p, nl, np, x, y, z; cin >> n >> k >> l >> c >> d >> p >> nl >> np; x = (k * l) / nl; y = c * d; z = p / np; cout << min(min(x, y), z) / n; return 0; }
0
#include <bits/stdc++.h> using namespace std; int minim(int val1, int val2) { if (val1 < val2) { return val1; } return val2; } int array1[100005]; int array2[100005]; int main() { int n; int mini = INT_MAX; int j = 0; int mini2 = INT_MAX; cin >> n; for (int i = 0; i < n; i++) { cin >> array1[i...
3
#include <bits/stdc++.h> using namespace std; long long n, k, a[3000003], sum[3000003], ans; bool check(long long x) { for (long long i = x - 1; i < n; i++) { if (a[i] * x - (sum[i] - sum[i - x]) <= k) { return true; } } return false; } int main() { ios_base::sync_with_stdio(false), cin.tie(0), co...
8
#include <bits/stdc++.h> using namespace std; int main() { int n, zero = 0; cin >> n; std::map<int, int> mp; for (int i = 0; i < n; i++) { int temp; cin >> temp; if (temp != 0) { mp[temp]++; } } int sum = 0, count = 0; cout << mp.size() << endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; using pii = pair<int, int>; bool comp(pii a, pii b) { return abs(a.first) + abs(a.second) < abs(b.first) + abs(b.second); } int main() { vector<pii> vp; int n, mv; while (cin >> n) { vp.resize(n); mv = 0; for (pii &x : vp) { cin >> x.first >> x.sec...
8
#include <bits/stdc++.h> using namespace std; int Nextint() { char ch = getchar(); while (ch < '0' || ch > '9') ch = getchar(); int x = 0; while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); } return x; } const int maxn = 100; char S[maxn][maxn]; bool vis[maxn][maxn]; int N, M, l...
16
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10; struct sofa { pair<int, int> X, Y; int id; int cntl, cntr, cntt, cntb; } sofas[maxn]; int d, n, m; int cntl, cntr, cntt, cntb; bool cmp1(sofa a, sofa b) { return a.X < b.X; } bool cmp2(sofa a, sofa b) { return a.Y < b.Y; } bool cmp3(sofa a, ...
12
#include <bits/stdc++.h> std::vector<int> powers(10, 1); void request() { std::map<std::pair<int, int>, int> field; int length; std::cin >> length; int best_length = INT32_MAX; std::pair<int, int> best{-1, -1}; std::pair<int, int> current{0, 0}; field[current] = 0; for (int i = 1; i <= length; ++i) { ...
7
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const double DINF = 1e20; const double pi = acos(-1.0); const double eps = 1e-6; template <class T> inline T sqr(T x) { return x * x; } const int MOD = 1000000007; int main() { int n, m, k; long long res; cin >> n >> m >> k; if (k > n |...
8
#include <bits/stdc++.h> using namespace std; using ll = long long; int const N = 1000 * 1000 + 16; int const M = 1000 * 1000 * 1000 + 7; struct node { int cnt = 0; node* k[2] = {}; ~node() { delete k[0]; delete k[1]; } }; struct trie { node* root = new node; ~trie() { delete root; } void insert(i...
12
#include <bits/stdc++.h> using namespace std; const int maxn = 201111; vector<int> P[maxn]; int tot = 0; deque<int> Sl, Sr; stack<int> SL, SR; char C[maxn]; int main() { scanf("%s", C + 1); int n = strlen(C + 1); for (int i = 1; i <= n; i++) P[i].clear(); while (Sl.size()) Sl.pop_back(); while (Sr.size()) Sr....
19
#include <bits/stdc++.h> using namespace std; int a[300005]; vector<int> v[300005]; int main() { int n,q; scanf("%d%d",&n,&q); for (int i=1;i<=n;i++) { scanf("%d",&a[i]); v[a[i]].push_back(i); } mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); while (q--) ...
12
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 1000; const int M = 1e9 + 7; int n, m; bool comp(pair<int64_t, char> a, pair<int64_t, char> b) { return !(a <= b); } map<char, int64_t> val; int pos[300]; int64_t ans; int64_t cur; set<int> av; int main() { ios_base::sync_with_stdio(0); cin.tie(0); ...
9
#include <bits/stdc++.h> using namespace std; const double eps = 1e-7; const int inf = 0x3f3f3f3f; const long long linf = 0x3f3f3f3f3f3f3f3fLL; struct A { int first, second, color; bool operator<(const A &rhs) const { if (first != rhs.first) return first < rhs.first; return second < rhs.second; } } arr[3]...
9
#include <bits/stdc++.h> using namespace std; int main() { int n, c, r, x, y, p = 0, m, g; bool o = 0; string d = "", w; stringstream ss; char h; cin >> n >> m; r = n, g = m; while (true) { c = n % 10; if (c > p) { p = c; } n = n / 10; if (n == 0) { break; } } whi...
7
#include <bits/stdc++.h> using namespace std; using lli = long long; using lld = long double; using ulli = unsigned long long int; using pll = pair<lli, lli>; using ttt = pair<lli, pll>; using vttt = vector<ttt>; using vll = vector<pll>; using vl = vector<lli>; using vi = vector<int>; using vvi = vector<vector<int>>; u...
16
#include <bits/stdc++.h> using namespace std; template <typename T> bool smax(T &a, const T &b) { if (a > b) return false; a = b; return true; } template <typename T> bool smin(T &a, const T &b) { if (a < b) return false; a = b; return true; } template <typename T> T cd(T a, T b) { return (a + b - 1) / b;...
10
#include <bits/stdc++.h> using namespace std; void solve() { int n, t, m, i, j = 0, k = 0, l, x, y, z, f; long long a[1005], b[10005], sum = 0, summ = 0; vector<long long> v, vip, cp[1005]; vector<int> vv, pp; map<long long, vector<long long>, greater<long long>> mp; cin >> n >> l; for (i = 1; i <= l; i++...
7
#include <bits/stdc++.h> using namespace std; long long n, ck, t, cntA, cntP; void helpMeBro() { cin >> n; vector<long long> allDivisors; for (long long i = 2; i * i <= n; ++i) if (n % i == 0) { allDivisors.push_back(i); if (i * i != n) allDivisors.push_back(n / i); } allDivisors.push_back(n...
13
#include <bits/stdc++.h> using namespace std; int n, k, m; long long dp[1010][105], ten; long long B[1010]; int main() { cin >> n >> k >> m; B[0] = 1LL; ten = 10LL; for (int i = 1; i <= n; i++) { B[i] = (ten * B[i - 1]) % m; } long long ans = 0; ten = 1LL; for (int i = 0; i < n; i++) { if (i != ...
14
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC target( \ "fma,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native") #pragma GCC optimize("unroll-loops") using namespace std; const long long int M = 1000000007; long long int fact[200001] = {}; inline bool comp(long long int x, long long ...
2
#include <bits/stdc++.h> using namespace std; set<pair<long long, long long> > mas; long long ar[2000000]; int main() { long long n, k; cin >> n >> k; for (long long i = 0; i < n; ++i) { long long a; cin >> a; mas.insert(make_pair(a, -i)); } long long end = n; long long f = 0, f1 = 0, ma_f = 0, ...
17
#include <bits/stdc++.h> using namespace std; const long long int maxn = 2e5 + 1; void solve() { long long int a, b, c, ans = 0; cin >> a >> b >> c; while (b > 0 && c > 1) { ans += 3; b -= 1; c -= 2; } while (b > 1 && a > 0) { ans += 3; b -= 2; a--; } cout << ans << "\n"; } int mai...
0
#include <bits/stdc++.h> using namespace std; int main() { int n, m, h; int a[105], b[105], c[105][105]; cin >> n >> m >> h; for (int i = 0; i < m; i++) cin >> a[i]; for (int i = 0; i < n; i++) cin >> b[i]; for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) { cin >> c[i][j]; if (c[i][j]...
4
#include <bits/stdc++.h> using namespace std; inline long long read() { register long long x = 0, f = 1; char ch = getchar(); while (!isdigit(ch)) { if (ch == '-') f = -1; ch = getchar(); } while (isdigit(ch)) { x = (x << 3) + (x << 1) + ch - '0'; ch = getchar(); } return (f == 1) ? x : -x...
20
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; int xi; set<int> sw; for (int i = 0; i < n; i++) { cin >> xi; int yij; for (int j = 0; j < xi; j++) { cin >> yij; sw.insert(yij); } } if (sw.size() == m) cout << "YES"; else cout << "N...
0
#include <bits/stdc++.h> using namespace std; int n; int p[1000005], xsum[1000005]; int main() { scanf("%d", &n); xsum[0] = 0; for (int i = 1; i <= n; ++i) { scanf("%d", p + i); xsum[i] = xsum[i - 1] ^ i; } int q = 0; for (int i = 1; i <= n; ++i) { int v; if ((int(n / i)) & 1) { v = p[...
8
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; inline int mo(const int x) { return x >= mod ? x - mod : x; } int t[52], g[52], fac[52], dp1[51][51][2502], dp2[51][2502], c[51][51], f[52][52][52][3]; int main() { int n, T; cin >> n >> T; for (int i = 0; i <= n; i++) for (int j = c[i...
13
#include <bits/stdc++.h> using namespace std; const int N = 404; int n, m, r, c, vis[N][N]; char a[N][N], b[N][N]; bitset<N> bs[26][N], ans[N]; int get(int x) { return (x % m + m - 1) % m + 1; } int main() { scanf("%d%d", &n, &m); for (int i = 1, iE = n; i <= iE; i++) scanf("%s", a[i] + 1); for (int i = 1, iE = n...
18
#include <bits/stdc++.h> using namespace std; static const double EPS = 1e-5; int powmod(int x, int n, int d) { if (n == 0) return 1; int s = x % d, t = x % d, u = n - 1; while (u) { if (u % 2) s = (s * t) % d; t = (t * t) % d; u /= 2; } return s; } long long getl() { long long ret; scanf("%I6...
18
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const int maxn = 100005; int main() { ios::sync_with_stdio(false); cin.tie(0); int t; long long p, q; cin >> t; while (t--) { cin >> p >> q; if ((q > p) || (p % q != 0)) { cout << p << '\n'; } else { long long ...
7
#include <bits/stdc++.h> using namespace std; string s, t; int cnt[30]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> s >> t; int n = (int)s.size(), m = (int)t.size(); if (n < m) return cout << "need tree", 0; if (n == m) { sort(t.begin(), t.end()); sort(s.begin(),...
6
#include <bits/stdc++.h> using namespace std; char mirror[] = "8??3694705"; int main() { string s; cin >> s; string s2 = s; reverse(s2.begin(), s2.end()); for (char& c : s2) { c = mirror[c - '0']; } cout << (s == s2 ? "Yes" : "No") << endl; return 0; }
11
#include <bits/stdc++.h> using namespace std; const long long INF = 100000000000; long long ch(long long z) { long long p = 0, q = 1, t, r; while (z > 0) { t = z % 10; z /= 10; if ((t == 7) || (t == 4)) { p += t * q; q *= 10; } } return p; } int main() { string a, b; long long a7...
4
#include <bits/stdc++.h> using namespace std; int main() { string s1, s2; int l1, l2, res, w, x, y; w = 0; cin >> s1 >> s2; l1 = s1.length(); l2 = s2.length(); x = l1; y = l2; while (l1 && l2) { if (s1[--l1] == s2[--l2]) w++; else break; } res = (x + y) - (2 * w); cout << res...
1
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:16777216") using namespace std; template <typename T> string toString(T Number) { ostringstream ss; ss << Number; return ss.str(); } template <typename T> T toNumber(const string &Text) { istringstream ss(Text); T result; return ss >> result ? result ...
13
#include <bits/stdc++.h> using namespace std; template <class T> void _R(T &x) { cin >> x; } void _R(int &x) { scanf("%d", &x); } void _R(long long &x) { scanf("%lld", &x); } void _R(double &x) { scanf("%lf", &x); } void _R(char &x) { scanf(" %c", &x); } void _R(char *x) { scanf("%s", x); } template <class T> void _W...
1
#include <bits/stdc++.h> using namespace std; void file() {} void fast() { std::ios_base::sync_with_stdio(0); cin.tie(NULL); } int main() { file(); fast(); int n; cin >> n; string str1, str2; cin >> str1 >> str2; deque<int> de, ans; int carry = 0, x; for (int i = n - 1; i >= 0; i--) { x = carr...
11
#include <bits/stdc++.h> using namespace std; long long ans1[200005], ans2[200005], s; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long n, a[100005]; cin >> n; for (long long i = (long long)0; i < (long long)n + 1; i++) { cin >> a[i]; s += a[i]; } long long ans =...
7
#include <bits/stdc++.h> using namespace std; const int p = 1e9 + 7, F = 2e9; int n, a[500005], b[500005], c[500005], v, f[500005], g[500005], o[500005], bb, aa = F; struct T { int f, g; } t[500005 << 2], w; T Min(T a, T b) { if (a.f == b.f) return (T){a.f, (a.g + b.g) % p}; return a.f < b.f ? a : b; } void U...
15
#include <bits/stdc++.h> using namespace std; int main() { unordered_map<int, int> cnt; int n, a, x; cin >> n; for (int i = 0; i < n; i += 1) { cin >> a >> x; cnt[a] = max(cnt[a], x); } int m, b, y; cin >> m; for (int i = 0; i < m; i += 1) { cin >> b >> y; cnt[b] = max(cnt[b], y); } ...
2
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, k, i, s = 0, j; cin >> n >> k; vector<int> ans; if (k == 0) { for (i = 1; i <= n; i++) ans.push_back(i); } else if (n <= k) ans.push_back(n); else { for (i = k + 1; i > 0; i--) ...
5
#include <bits/stdc++.h> #pragma GCC optimize("Ofast", "unroll-loops", "omit-frame-pointer", "inline") #pragma GCC option("arch=native", "tune=native", "no-zero-upper") #pragma GCC target("avx2") #pragma GCC optimize("03") using namespace std; template <typename T> struct ST { vector<T> st, lazy; int sz; T neutro...
18
#include <bits/stdc++.h> using namespace std; const long long inf = 1LL << 62; const int iinf = 1 << 30; const double dinf = 1e17; const int Mod = 1e9 + 7; struct Point { long long x, y; double ang; Point(long long x = 0, long long y = 0) : x(x), y(y) {} Point operator-(const Point &a) const { return Point(x - ...
19
#include <bits/stdc++.h> using namespace std; int main() { int n, lv, i, v, max, count = 0; scanf("%d", &n); vector<int> votes; vector<int>::iterator it; it = votes.begin(); scanf("%d", &lv); for (i = 0; i < n - 1; i++) { scanf("%d", &v); it = votes.insert(it, v); } make_heap(votes.begin(), vo...
4
#include <bits/stdc++.h> long long n, k, ans, yoyo; int tmp; long long use(long long a) { return n / a + 1; } int main() { scanf("%I64d", &n); k = n; int i = 1; yoyo = 1; while (k) { tmp = k % 3; yoyo *= 3LL; if (tmp != 0) { ans = use(yoyo); break; } k /= 3LL; } printf("%I6...
8
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin.tie(0); cin.sync_with_stdio(0); int n; cin >> n; while (n--) { int x, y; cin >> x >> y; if (x < y) { cout << "Happy Alex"; return 0; } } cout << "Poor Alex"; re...
3
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; long long res = 0; for (int i = 1; i <= n; i++) { long long a; cin >> a; res += a + (a - 1) * (i - 1); } cout << res; exit: return (0); }
3
#include <bits/stdc++.h> using namespace std; template <typename T> using minheap = priority_queue<T, vector<T>, greater<T>>; template <typename T> using maxheap = priority_queue<T>; template <typename T> using dpair = pair<T, T>; template <class T1, class T2> istream &operator>>(istream &is, pair<T1, T2> &p) { retur...
11
#include <bits/stdc++.h> using namespace std; bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) { return (a.second < b.second); } long long powermod(long long x, long long y, long long p) { long long res = 1; x = x % p; while (y > 0) { if (y & 1) res = (res * x) % p; y = y >> 1; x = (...
8
#include <bits/stdc++.h> const int INF = 0x3f3f3f3f; const int mod = 1e9 + 7; const int maxn = 1e5 + 10; using namespace std; struct point { int x; int y; }; bool cmp(point a, point b) { if (a.x != b.x) return a.x < b.x; else return a.y < b.y; } int main() { point a[4]; point b[4]; for (int i = 0;...
8
#include <bits/stdc++.h> using namespace std; vector<int> a[5010]; int n, A, B, cnt; char s[1000010]; int num[5010]; vector<int> gold[5010], tgold[5010]; int gcdv[5010]; int dfn[5010], low[5010], st[5010], top, nq[5010]; int gcd(int x, int y) { if (y == 0) return x; return gcd(y, x % y); } char w[5010][5010]; int t...
26
#include <bits/stdc++.h> using namespace std; int n, t; char s1[1050000], s2[1050000]; struct data { int to, head; } e[500], e1[500]; int plen, len, len1, ans; int p[25], head[25], head1[25], ended[25], flag[25], mvis[25], vis[25]; int a[25][25]; void add(int u, int v) { e[++len].to = v; e[len].head = head[u]; ...
23
#include <bits/stdc++.h> using namespace std; int a, b, c, d; vector<int> g[5010]; int type[5010], size[5010], typeSize[5010]; void dfs(int u) { if (u == a) type[u] = 1; if (u == b) type[u] = 2; if (u == c) type[u] = 3; if (u == d) type[u] = 4; if (g[u].size() == 0) size[u] = 1; for (int& v : g[u]) { df...
21
#include <bits/stdc++.h> using namespace std; int w; long long n, k; pair<long long, long long> o = {0, 0}; pair<long long, long long> csop(long long kezd, long long kim) { long long sum = 0, kov = kezd + k; if (kezd <= kim && kim <= kov) { kov++; } sum = (kov - kezd) * (kov - kezd - 1) / 2; if (log(k) + ...
26
#include <bits/stdc++.h> using namespace std; long long int min(long long int a, long long int b) { return a < b ? a : b; } long long int min(long long int a, long long int b, long long int c) { a = min(a, b); a = min(a, c); return a; } long long int max(long long int a, long long int b) { return a > b ? a : b; }...
7
//#pragma GCC optimize("Ofast") #include"bits/stdc++.h" using namespace std; #define pb push_back #define F first #define S second typedef long long ll ; typedef pair<int , int> pii; typedef pair<ll, ll> pll; typedef pair<pll , int> pip; const ll N = 1e3 + 5 , inf = 1e15 , mod = 1e9 + 7 , base = 27; ll dpl[N][N] , d...
8
#include <bits/stdc++.h> using namespace std; template <typename A> using VE = vector<A>; template <typename A> using USET = unordered_set<A>; template <typename A> using HEAP = priority_queue<A>; template <typename A, typename B> using PA = pair<A, B>; template <typename A, typename B> using UMAP = unordered_map<A, B>...
11
#include <bits/stdc++.h> using namespace std; const int N = 10001; vector<int> all; int a; long long l[N], r[N]; long long ans; int n, m, d; int main() { scanf("%d %d %d", &n, &m, &d); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { scanf("%d", &a); all.push_back(a); } } sort(all...
6
#include <bits/stdc++.h> using namespace std; const int INF = INT_MAX; const long long INFL = LLONG_MAX; const long double pi = acos(-1); int N, K; int A[100100]; int main() { ios_base::sync_with_stdio(0); cout.precision(15); cout << fixed; cout.tie(0); cin.tie(0); cin >> N >> K; for (int i = 1; i <= N; i...
2
#include <bits/stdc++.h> using namespace std; struct cmp { bool operator()(const pair<int, pair<int, int>>& a, const pair<int, pair<int, int>>& b) { return a.second > b.second; } }; pair<int, int> operator+(const pair<int, int>& a, const pair<int, int>& b) { return pair<int, int>(a.first + b...
16
#include <bits/stdc++.h> using namespace std; void swaps(long long &a, long long &b, long long &c) { long long t = 0; if (b > a) { t = b; b = a; a = t; } if (c > b) { t = c; c = b; b = t; } if (b > a) { t = b; b = a; a = t; } } int main() { long long t; cin >> t; ...
0
#include <bits/stdc++.h> using namespace std; long long n, m = 1, l; int main() { scanf("%I64d", &n); while (n > m) m *= 10, l++; long long w = m / 10, sm = 0; sm = 1; for (int i = 1; i <= l; i++) sm = (sm + 45 * w) % n; long long ans = (n - sm) % n; printf("%I64d %I64d\n", ans + 1, m + ans); }
17
#include <bits/stdc++.h> using namespace std; int n, h = 0, t = -1; int que[1000001]; long long int dp[1000001], ans; struct Rect { int r, u; long long int cost; } rec[1000001]; bool comp(Rect a, Rect b) { return a.r < b.r; } inline double slope(int i, int j) { return 1.0 * (dp[i] - dp[j]) / (rec[i].r - rec[j].r)...
16
#include <bits/stdc++.h> using namespace std; long long n, k, ans, x; string str1, str2; int main() { scanf("%lld%lld", &n, &k); cin >> str1; cin >> str2; x = 1; for (int i = 0; i < n; i++) { x *= 2; if (str1[i] == 'b') x--; if (str2[i] == 'a') x--; if (x > k) { ans += (n - i) * k; ...
12
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int a, b, c, d, k; cin >> a >> b >> c >> d >> k; int x = a / c; if (a % c != 0) x++; int y = b / d; if (b % d != 0) y++; if (x + y > k) cout << -1; else cout << x << " " << y; ...
0
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, h, ct, x; cin >> n >> h; ct = 0; while (n--) { cin >> x; if (x > h) ct += 2; else ct++; } cout << ct << "\n"; return 0; }
0
#include <bits/stdc++.h> int main() { int a, b; scanf("%d%d", &a, &b); int m = fabs(a - b); if (a == 9 && b == 1) { printf("9 10"); return 0; } if (a > b || m > 1) printf("-1"); else if (a == b) printf("%d1 %d2", a, b); else printf("%d9 %d0", a, b); return 0; }
1
#include <bits/stdc++.h> using namespace std; vector<long> a[100010]; bool visited[100010] = {false}; long long int c[100010]; long long gcd(long long a, long long b) { if (b == 0) return a; else return gcd(b, a % b); } bool checkprime(unsigned long long n) { if (n <= 1) return false; if (n == 2) return...
3
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; for (int i = 1; i <= t; i++) { long long s; scanf("%I64d", &s); long long j = 0, f = 0; while (j <= 100000) { j++; if (j * j <= s) continue; long long x = j * j; if (sqrt(x - s) == int(sqrt(x - s)))...
9
#include <bits/stdc++.h> using namespace std; struct debugger { static void call(string::iterator it, string::iterator ed) {} template <typename T, typename... aT> static void call(string::iterator it, string::iterator ed, T a, aT... rest) { string b; for (; *it != ','; ++it) if (*it != ' ') b += *i...
7
#pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma") #pragma GCC optimize("unroll-loops") #include <bits/stdc++.h> #include <complex> #include <queue> #include <set> #include <unordered_set> #include <list> #include <chrono> #include <random> #include <iostream> #incl...
0
#include <bits/stdc++.h> using namespace std; const int maxn = 1005; struct node { int next, w; }; vector<node> v[maxn]; vector<node> ans[maxn]; int in[maxn], out[maxn]; int Min[maxn]; bool visit[maxn]; int n, m; void dfs(int u, int id) { int i; visit[u] = true; for (i = 0; i < (int)v[u].size(); i++) { int ...
6
#include <bits/stdc++.h> using namespace std; int n, p, q, cnt = 0; int main() { scanf("%d", &n); for (int i = 0; i < int(n); i++) { scanf("%d %d", &p, &q); if (q - p >= 2) cnt++; } printf("%d", cnt); return 0; }
0
#include <bits/stdc++.h> using namespace std; int main() { std::ios_base::sync_with_stdio(false); cin.tie(0); int t; cin >> t; while (t--) { int n, m, k; cin >> n >> m >> k; cout << min(n / k, m) - (m - min(n / k, m) + k - 2) / (k - 1) << "\n"; } }
2
#include <bits/stdc++.h> using namespace std; int n; int k; bool judge(int v); int main() { while (cin >> n >> k) { int x = 1; int y = n; int v; while (x < y) { v = (x + y) / 2; if (judge(v)) y = v; else x = v + 1; } cout << x << endl; } return 0; } bool j...
7
#include <bits/stdc++.h> using namespace std; char grid[521][521]; int idx[521][521]; int parent[251000]; int qtd[251000]; int cnt, n, m; int qtdx[521][521]; int gox[] = {0, 0, 1, -1}; int goy[] = {-1, 1, 0, 0}; int _find(int v) { if (parent[v] == v) return v; return parent[v] = _find(parent[v]); } void _union() { ...
16
#include <bits/stdc++.h> using namespace std; const int maxn = 400100; int c[maxn]; int a[maxn]; int n, m; int f[maxn]; int b[maxn]; int ask(int x) { int res = 0; for (; x; x -= x & -x) res = max(res, c[x]); return res; } void update(int x, int v) { for (; x <= m; x += x & -x) c[x] = max(c[x], v); } int main() ...
17
#include <bits/stdc++.h> using namespace std; int main() { int a, b, d, e, f, g, sum1 = 0, sum = 0, sum2 = 0, cnt = 0, x = 0, y = 0, z = 0; char c; cin >> a >> c >> b >> c >> d; cin >> e >> c >> f >> c >> g; int s[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; int t[13] =...
5
#include <bits/stdc++.h> using namespace std; int main() { int n, i, j, w = 0, x = 0, y = 0, z = 0, m = 0; cin >> n; int a[n][2]; for (i = 0; i < n; i++) { for (j = 0; j < 2; j++) { cin >> a[i][j]; } } for (i = 0; i < n; i++) { for (j = 0; j < n; j++) { if (j != i) { if (a[j]...
2
#include <bits/stdc++.h> using namespace std; vector<int> a; int main() { int n, i; scanf("%d", &n); a.resize(n); for (i = 0; i < n; i++) scanf("%d", &a[i]); sort(a.begin(), a.end()); int sum = 10, l = 360, penalty = 0; for (i = 0; i < n; i++) { if (sum + a[i] < l) { sum += a[i]; } else if (...
10
#include <bits/stdc++.h> int n, m, l, co[60][60], dis[60][60][4][3], u[60][60][4], v[60][60][4], dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; char s[60]; int main() { scanf("%d%d\n", &m, &n); for (int i = 1; i <= m; ++i) { gets(s); l = strlen(s); for (int j = 1; j <= l; ++j) co[i][j] = s[j - 1] - '0'...
13
#include <bits/stdc++.h> using namespace std; const int maxn = 1010; int n; char ch[maxn][maxn]; int Max; int P; template <class T> T maxT(const T &X, const T &Y) { if (X > Y) return X; else return Y; } void init() { Max = 0; while (gets(ch[++n])) { int N = strlen(ch[n]); Max = maxT(Max, N); }...
4
#include <bits/stdc++.h> using namespace std; int main() { int t, i, n, j, count; cin >> t; string s; for (i = 0; i < t; i++) { cin >> n; cin >> s; string cpy; cpy = s; count = 0; sort(cpy.begin(), cpy.end()); for (j = 0; j < n; j++) { if (s[j] != cpy[j]) { count++; ...
0
#include <bits/stdc++.h> using namespace std; vector<pair<int, int> > adj[5000]; vector<int> adjnorm[5001]; bool vis[5000]; int ass[5001]; int n; int rc(int ro, int co) { return (ro - 1) * n + (co - 1); } void dfs(int node, int col) { if (!vis[node]) { vis[node] = true; ass[node] = col; for (int i = 0; i ...
16
#include <bits/stdc++.h> using namespace std; const int N = 500 + 3; const int K = 500 + 3; const int NEG_INF = -1e9; const int POS_INF = 1e9; int days[N] = {0}; int main() { int n = 0, k = 0; int sum = 0; int res = 0; cin >> n >> k; for (int i = 1; i <= n; i++) cin >> days[i]; days[0] = k; days[n + 1] = ...
2
#include <bits/stdc++.h> using namespace std; template <class T, class U> ostream& operator<<(ostream& out, const pair<T, U>& a) { out << "[" << a.first << " " << a.second << "]"; return out; } template <class T> ostream& operator<<(ostream& out, const vector<T>& a) { out << "[ "; for (auto& it : a) out << it <...
9
#include <bits/stdc++.h> using namespace std; struct node { int id, a, b; }; struct cmp { bool operator()(const node &n1, const node &n2) const { return n1.b - n1.a < n2.b - n2.a; } }; priority_queue<node, vector<node>, cmp> pq; int main() { ios_base::sync_with_stdio(false); string str; cin >> str; in...
18
#include <bits/stdc++.h> using namespace std; long long t, n, m, u, v, q, r, ql, qr, k, l, w, z, x, y, d, p, c, b, a; const int N = 2e5 + 500; const int SN = 300; const int NN = 1e4 + 4; const long long mod = 10007; const long long INF = 1LL << 52LL; string str; vector<int> kk; vector<pair<int, int> > s; int main() { ...
9
#include <bits/stdc++.h> using namespace std; inline int inc(int a, int b) { return a + b < 1000000007 ? a + b : a + b - 1000000007; } inline int dec(int a, int b) { return a < b ? a - b + 1000000007 : a - b; } inline int mul(int a, int b) { return (int)((long long int)a * b % 1000000007); } inline int pow(int a, i...
25
#include <bits/stdc++.h> using namespace std; int main() { string in; cin >> in; for (int i = 0; i <= in.size(); ++i) { for (char c = 'a'; c <= 'z'; ++c) { string temp = in; temp.insert(i, 1, c); string rev = temp; reverse(rev.begin(), rev.end()); if (rev == temp) { cout ...
22