solution
stringlengths
53
181k
difficulty
int64
0
13
#include <bits/stdc++.h> using namespace std; const int N = 1000100; const double EPS = 1e-9; int dp[N][10]; int cnt(int l, int r, int val) { return dp[r][val] - dp[l - 1][val]; } long long a; int main() { dp[0][0] = dp[1][0] = 1; for (int i = 2; i < N; ++i) { long long l = pow(i, 0.25); while (l * l * l * ...
7
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 50; const long long mod = 1e9 + 7; const long long INF = 1000000000; int dx[4] = {0, 0, 1, -1}; int dy[4] = {1, -1, 0, 0}; bool compare(const pair<long long, long long>& i, const pair<long long, long long>& j) { return i.second < j.second;...
2
#include <bits/stdc++.h> using namespace std; const int n = 1e7; int main() { long long a, b, c, ans = 0; cin >> a >> b >> c; long long mx = max(a, max(b, c)); long long sum = (a + b + c) - mx; if (sum * 2 <= mx) cout << sum << endl; else cout << (a + b + c) / 3 << endl; }
5
#include <bits/stdc++.h> using namespace std; int n, m, x, K, y; set<int> s; set<pair<int, int> > a; vector<int> ans[500005]; inline void dfs(int nod) { set<int>::iterator it; for (it = s.begin(); it != s.end();) { if (!a.count(make_pair(min(*it, nod), max(*it, nod)))) { int x = *it; s.erase(x); ...
6
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; int n, dp[5001][5001][2]; char s[5001]; int calc(int i, int indentationLevel, bool open) { if (i == n) { return !open; } int& ret = dp[i][indentationLevel][open]; if (ret != -1) { return ret; } ret = 0; if (open) { ret = ca...
5
#include <bits/stdc++.h> int main() { int n; scanf("%d", &n); int a, b, x; double c; int counter = 0; a = 1; b = 1; for (a = 1; a <= n; a++) { for (b = a; b <= n; b++) { x = (a * a) + (b * b); c = sqrt(x); if (c == (int)c && c <= n) { counter++; } } } printf("...
2
#include <bits/stdc++.h> using namespace std; map<int, int> mp; int main() { cin.tie(0); cout.tie(0); ios::sync_with_stdio(0); int n, cnt = 0, tk; cin >> n; vector<int> vc, s; for (int i = 1; i <= n; i++) cin >> tk, vc.push_back(tk), s.push_back(tk); sort(s.begin(), s.end()); for (int i = 0; i < n; i+...
2
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s1; cin >> s1; for (int i = 0; i < n; i++) { if (s1[i] == 'o' && s1[i + 1] == 'g' && s1[i + 2] == 'o') { s1.erase(i, 3); s1.insert(i, "***"); } if (s1[i] == '*' && s1[i + 1] == 'g' && s1[i + 2] == 'o') {...
0
#include <bits/stdc++.h> using namespace std; int n, p; string x; string ans; vector<int> pos; int main() { cin >> n >> p >> x; for (int i = 0; i < x.size(); i++) { if (x[i] == '.') pos.push_back(i); ans += x[i]; } for (int i = 0; i < 1000; i++) { for (int j = 0; j < pos.size(); j++) ans[pos[j]] = (...
2
#include <bits/stdc++.h> using namespace std; int main() { int k; cin >> k; int p[k]; int max = -1; for (int i = 0; i < k; ++i) { cin >> p[i]; if (p[i] > max) { max = p[i]; } } if (max - 25 <= 0) { cout << 0 << endl; } else { cout << max - 25 << endl; } }
0
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 10; int a[maxn], f[maxn]; void solve() { int n, k; cin >> n >> k; if (k % (n - 1) == 0) { cout << k / (n - 1) * n - 1 << endl; } else { cout << k / (n - 1) * n + k % (n - 1) << endl; } } int main() { ios_base::sync_with_stdio(0); ...
2
#include <bits/stdc++.h> using namespace std; struct debugger { template <typename T> debugger& operator,(const T& v) { cerr << v << " "; return *this; } } dbg; int a[501][501], n, m; char b[501][501]; int check(int i_a, int j_a) { return (i_a >= 0 && j_a >= 0 && i_a < n && j_a < m && b[i_a][j_a] == '.'...
4
#include <bits/stdc++.h> using namespace std; map<string, int> list; int price[101]; int highp[101]; int listn[101]; typedef struct _data { string s; int n; } data; data dat[101]; int cmp1(int i, int j) { return i > j; } int cmp3(data i, data j) { return i.n > j.n; } int main() { int n, m; scanf("%d%d", &n, &m)...
1
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t-- > 0) { int n, m; cin >> n >> m; vector<pair<int, int> > out; int x, y; vector<vector<pair<int, bool> > > g(n + 2); for (int i = 0; i < m; ++i) { scanf("%d%d", &x, &y); g[x].push_back({y, 0});...
7
#include <bits/stdc++.h> using namespace std; long long a[200009]; priority_queue<int> q[26]; char s[200009]; int main() { long long n, k, ans = 0; cin >> n >> k; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n; i++) cin >> s[i]; q[s[0] - 'a'].push(a[0]); for (int i = 1; i < n; i++) { q[s...
2
#include <bits/stdc++.h> using namespace std; int n, m; int num[102]; int t[5005]; struct node { int ti; int c; } q[5005]; bool cmp(node a, node b) { return a.ti > b.ti; } struct Res { int l, r; } res[5005]; int main() { while (scanf("%d %d", &n, &m) != EOF) { memset(num, 0, sizeof(num)); int p; for...
5
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t; cin >> t; while (t--) { int n, k; cin >> n >> k; string s; cin >> s; int last = -1, ans = 0, ps; for (int i = 0; i < n; i++) { if (s[i] - '0' == 1) { if (las...
2
#include <bits/stdc++.h> using namespace std; string s; int epos; int d, b; deque<char> ans; int main() { cin >> s; for (int i = 0; i < s.size(); i++) { if (s[i] == 'e') epos = i; } for (int i = epos - 1; i > 1; i--) { d += int(s[i] - '0') * pow(10.0, epos - 1 - i); } for (int i = s.size() - 1; i > ...
3
#include <bits/stdc++.h> using namespace std; int main() { int n, a, b; cin >> n >> a >> b; cout << n - max(a + 1, n - b) + 1; }
1
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t; cin >> t; while(t--) { string s; cin >> s; bool IND = false; for(int m = 0; m <= s.size(); m++) { bool ind = true; ...
1
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const int maxn = 2e6 + 5; char a[maxn], b[maxn]; int n; int cnta, cntb, ansa, ansb; int main() { while (~scanf("%d", &n)) { cnta = cntb = ansa = ansb = 0; scanf("%s", &a); scanf("%s", &b); int both = 0; for (int i = 0; i < 2...
3
#include <bits/stdc++.h> using namespace std; int main() { int k = 0, i; int n; cin >> n; int arr[n]; for (i = 0; i < n; i++) { cin >> arr[i]; } for (i = 1; i < n - 1; i++) { if (arr[i - 1] == 1 && arr[i] == 0 && arr[i + 1] == 1) { k++; i = i + 2; } } cout << k; }
1
#include <bits/stdc++.h> using namespace std; int main() { int n, k, ans; cin >> n >> k; int r = (n - 1) / k; if ((n - 1) % k == 0) ans = 2 * r; else if ((n - 1) % k == 1) ans = 2 * r + 1; else ans = 2 * r + 2; cout << ans << endl; for (int i = 2; i < 2 + k; i++) printf("1 %d\n", i); for (...
5
#include <bits/stdc++.h> #pragma GCC target("popcnt") #pragma comment(linker, "/stack:200000000") #pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native" using namespace std; template <typename T, typename K> inline bool smax(T &x, const K &y) { return x < y ? x = y,...
5
#include <bits/stdc++.h> using namespace std; const int N = 1000 + 20; int e[N][N]; int n, m; void init() { for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) e[i][j] = i == j ? 0 : 0x3f3f3f3f; } struct Dijkstra { int vis[N], dis[N]; void dijkstra(int st) { for (int i = 1; i <= n; i++) { dis[...
4
#include <bits/stdc++.h> using namespace std; vector<vector<int> > tb; int dpsolve(string str) { int n = str.length(); tb.assign(2, vector<int>(n, 0)); tb[0][0] = (str[0] == '1'); tb[1][0] = (str[0] == '0'); int cnt1 = (str[0] == '1'); for (int i = int(1); i <= int(n - 1); i++) { tb[0][i] = min(tb[0][i ...
5
#include <bits/stdc++.h> using namespace std; int main() { unsigned long long n, t; long long dx[7] = {2, 1, -1, -2, -1, 1, 2}, dy[7] = {0, 2, 2, 0, -2, -2, 0}, k, x, y; cin >> n; if (n == 0) { cout << "0 0"; return 0; } else { t = sqrt((double)n / 3); while (3 * t * (t + 1) < n) t...
6
#include <bits/stdc++.h> using namespace std; template <class _T> inline _T sqr(const _T& x) { return x * x; } template <class _T> inline string tostr(const _T& a) { ostringstream os(""); os << a; return os.str(); } const long double PI = 3.1415926535897932384626433832795L; const long double EPS = 1e-11; char T...
4
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const int maxn = 1000010; int n, m, r, h = 1; char mp[1010][1010]; bool vis[2020]; int pre[2020], deg[2020], q[2020], val[1000010]; int head[2020], tot = 0; struct node { int v, next, w; node(int _v = 0, int _next = 0, int _w = 0) : v(_v), ne...
6
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; for (int i = sqrt(n); i >= 1; i--) { if (n % i == 0) { cout << i << " " << n / i; return 0; } } return 0; }
0
#include <bits/stdc++.h> using namespace std; int main() { long l, r, ans; cin >> l >> r; if (l == r) cout << l; else cout << 2; }
1
#include <bits/stdc++.h> using namespace std; long long read() { long long x = 0, F = 1; char c = getchar(); while (c < '0' || c > '9') { if (c == '-') F = -1; c = getchar(); } while (c >= '0' && c <= '9') { x = x * 10 + c - '0'; c = getchar(); } return x * F; } int ans; int T, n, m, siz[1...
5
#include <bits/stdc++.h> using namespace std; const int N = 100000 + 10; const int M = 1000000007; const double PI = atan(1) * 4; const int oo = 1000000000; int n, v[N], fr[N]; int main() { cin >> n; for (int i = 0; i < n; ++i) cin >> v[i]; for (int i = n - 1; i >= 0; --i) v[i] += v[i + 1]; int mx = v[0]; for...
3
#include <bits/stdc++.h> using namespace std; const long long oo = 1e18 + 7; long long n, a[300005], suff[300005], IT[1200005], l[300005], r[300005]; pair<pair<long long, long long>, long long> ques[600005]; stack<long long> stk; unordered_map<long long, long long> uomp; void upd(long long id, long long l, long long r,...
8
#include <bits/stdc++.h> using namespace std; int a[66], b[66]; int main() { int n; scanf("%d", &n); while (n--) { long long l, r; cin >> l >> r; int ac = 0, bc = 0; while (l) { a[ac++] = l % 2; l /= 2; } while (r) { b[bc++] = r % 2; r /= 2; } reverse(a, a +...
4
#include <bits/stdc++.h> using namespace std; const double eps = 1e-10; inline void get(complex<double> &a) { double x, y; cin >> x >> y; a = complex<double>(x, y); } bool intersect(complex<double> a, double ra, complex<double> b, double rb, complex<double> c, double rc) { if (abs(a - b) > ra + r...
9
#include <bits/stdc++.h> using namespace std; int N, K, ans; int p[205]; int main() { int i; scanf("%d", &N); for (i = 1; i <= 2 * N - 1; i++) { scanf("%d", &p[i]); if (p[i] >= 0) K++; else p[i] = -p[i]; ans += p[i]; } sort(p + 1, p + 2 * N); if ((2 * N - 1 - K) % 2 == 1) if ...
5
#include <bits/stdc++.h> using namespace std; const int inf = 1e9 + 7; const int maxn = 5005; const int maxm = 200005; int Read() { int x = 0, t = 1; char c = getchar(); if (c == '-') { t = -1; c = getchar(); } while (c > '9' || c < '0') c = getchar(); while (c >= '0' && c <= '9') x = x * 10 + c - '...
7
#include <bits/stdc++.h> using namespace std; const int N = 2048; const int M = 8192; struct data { int s[N]; int p[N]; int l, r; void clear() { l = 1; r = 0; } void insert(int d, int k) { while (l <= r && s[r] > d) r--; r++; s[r] = d; p[r] = k; } int pos() { return p[l]; } int...
10
#include <bits/stdc++.h> using namespace std; const int maxn = 100 + 15; int n; int a[maxn]; int b[maxn]; int main() { cin >> n; for (int(i) = (1); (i) != (n + 1); (i)++) { scanf("%d", &a[i]); b[i] = b[i - 1] + a[i]; } int max_inc = -1; for (int(i) = (1); (i) != (n + 1); (i)++) { for (int(j) = (i)...
2
#include <bits/stdc++.h> using namespace std; int n; const int MaxN = 3e5; vector<int> adj[MaxN]; vector<int> prec[MaxN]; void dfs(const int u, const int p) { prec[u] = {1, n}; adj[u].erase(remove(adj[u].begin(), adj[u].end(), p), adj[u].end()); for (auto &&v : adj[u]) { dfs(v, u); prec[u][0] = max(prec[u...
9
//#pragma GCC target ("avx2") //#pragma GCC optimization ("O3") //#pragma GCC optimization ("unroll-loops") #include<bits/stdc++.h> //#include <ext/pb_ds/assoc_container.hpp> //#include <ext/pb_ds/tree_policy.hpp> //using namespace __gnu_pbds; #define eps 1e-8 #define eq(x,y) (fabs((x)-(y)) < eps) using namespace std; ...
7
#include <bits/stdc++.h> using namespace std; int data[100005], n; long long g[2][100005], h[2][100005]; int main() { scanf("%d", &n); for (int i = 1; i < n; i++) scanf("%d", &data[i]); g[0][1] = g[1][1] = 0; for (int i = 2; i <= n; i++) { if (data[i - 1] == 0) g[1][i] = 0; else g[1][i] = ma...
6
#include <bits/stdc++.h> using namespace std; const int LIM = 1e5 + 5, MOD = 1e9 + 7; long long gcd(long long a, long long b) { if (b == 0) return a; return gcd(b, a % b); } long long fastpowMOD(long long a, long long p, long long MOD) { if (p == 0) return 1; long long z = fastpowMOD(a, p / 2, MOD); z = (z * ...
5
#include <bits/stdc++.h> using namespace std; long long int power(long long int a, long long int b) { long long int res = 1; a = a % 1000000007; while (b > 0) { if (b & 1) { res = (res * a) % 1000000007; b--; } a = (a * a) % 1000000007; b >>= 1; } return res; } long long int gcd(lo...
2
#include <bits/stdc++.h> using namespace std; inline long long read() { long long x = 0, f = 1; char c = getchar(); while (c < '0' || c > '9') { if (c == '-') f = -1; c = getchar(); } while (c >= '0' && c <= '9') x = (x << 1) + (x << 3) + (c ^ '0'), c = getchar(); return x * f; } inline void wri...
9
#include <bits/stdc++.h> using namespace std; const int maxn = 100009; struct E { int u, v; long long val; } edges[maxn]; vector<int> neigh[maxn]; long long val[maxn]; int be = -1; int depth[maxn]; long long cur_val[maxn]; void dfs(int v, int p) { int bck; for (int i : neigh[v]) { int u = (edges[i].v == v ?...
9
#include <bits/stdc++.h> using namespace std; const int N = 1e4 + 5; vector<int> graph[N]; unordered_map<int, string> name; unordered_map<string, int> id; bitset<N> adj[N]; int getId(string &x) { if (id.count(x)) return id[x]; int t = int(id.size()); name[t] = x; return id[x] = t; } int go(int x) { int n = in...
7
#include <bits/stdc++.h> #pragma GCC target("avx,avx2,fma") #pragma GCC optimization("O3") #pragma GCC optimization("unroll-loops") using namespace std; const long long int N = 5e5 + 30, mod = 1e9 + 7, inf = 1e12; const long double eps = 0.0001; int n, m; bool visited[N]; set<pair<int, int> > st; set<int> ve; vector<in...
6
#include <bits/stdc++.h> using namespace std; template <typename T> void cetak(T t) { cout << t << ')' << endl; } template <typename T, typename... V> void cetak(T t, V... v) { cout << t; if (sizeof...(v)) cout << ", "; cetak(v...); } typedef int (*func)(int, int); const int MOD = 1e9 + 7; int add(int x, int y)...
6
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1); void fsint(int& inp) { register char c = getchar_unlocked(), prev = '+'; for (; !isdigit(c); c = getchar_unlocked()) prev = c; inp = 0; for (; isdigit(c); c = getchar_unlocked()) { inp = (inp << 3) + (inp << 1) + (c - '0'); } if (...
7
#include <bits/stdc++.h> using namespace std; int main() { int ok = 1; int a, b, c, n; cin >> a >> b >> c >> n; a -= c; b -= c; if (a < 0 || b < 0) ok = 0; if (a + b + c >= n) ok = 0; if (!ok) { cout << "-1\n"; return 0; } cout << n - (a + b + c) << "\n"; }
1
#include <bits/stdc++.h> using namespace std; int main() { int niza[17]; niza[1] = 1; niza[2] = 0; niza[3] = 0; niza[4] = 1; niza[5] = 0; niza[6] = 1; niza[7] = 0; niza[8] = 1; niza[9] = 1; niza[10] = 1; niza[11] = 0; niza[12] = 0; niza[13] = 1; niza[14] = 0; niza[15] = 1; niza[16] = 0...
4
#include <bits/stdc++.h> using namespace std; long long a[] = {0, 4, 10, 20, 35, 56, 83, 116, 155, 198, 244, 292}; int main() { long long n; cin >> n; if (n <= 11) cout << a[n]; else cout << 292 + (n - 11) * 49; return 0; }
6
#include <bits/stdc++.h> using namespace std; const int maxN = 10; int n, m, a[maxN], b[maxN]; double chia; void init() { cin >> n; for (int i = 0; i < n; i++) cin >> a[i] >> b[i]; chia = 1; for (int i = 0; i < n; i++) chia = chia * (b[i] - a[i] + 1); } double cal(double l, double r, double x) { if (x < l) re...
6
#include <bits/stdc++.h> using namespace std; template <class T> int size(const T &x) { return x.size(); } const int INF = ~(1 << 31); const double pi = acos(-1); const double EPS = 1e-9; vector<int> lis(vector<int> a) { int n = a.size(), l = 0, lo, hi, mid; vector<int> dp(n + 1, INF), rtn; dp[0] = -1; for (c...
5
#include <bits/stdc++.h> using namespace std; int main() { ios ::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t; cin >> t; while (t--) { long long x, b = 2; cin >> x; int cnt = 0; while (true) { long long c = (b - 1) * (b) / 2; if (c > x) break; x -= c; ...
2
#include <bits/stdc++.h> #define ld long double #define endl "\n" #define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define pb push_back #define mp(a,b) make_pair(a,b) #define ms(v,x) memset(v,x,sizeof(v)) #define all(v) v.begin(),v.end() #define ff first #define ss second #define rep(i, a, b) for(int...
9
#include <bits/stdc++.h> using namespace std; int N, H; long double p, q; long double dp[4][2005][2005]; int pos[2005]; double solve(int msk, int l, int r) { if (l > r) { return 0; } if (dp[msk][l][r] + 1) { return dp[msk][l][r]; } int cstll, cstlr, cstrl, cstrr; dp[msk][l][r] = 0; if (msk & 1) { ...
7
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using str = string; using pi = pair<int, int>; using pl = pair<ll, ll>; using pd = pair<ld, ld>; using vi = vector<int>; using vb = vector<bool>; using vl = vector<ll>; using vd = vector<ld>; using vs = vector<str>; using vpi = ...
0
#include <bits/stdc++.h> using namespace std; int main() { int d; long i, n, x, y, r1, r, coun; cin >> r >> d; cin >> n; coun = 0; for (i = 0; i < n; i++) { cin >> x >> y >> r1; if (x * x + y * y >= (r - d + r1) * (r - d + r1) && x * x + y * y <= (r - r1) * (r - r1) && 2 * r1 <= d) cou...
1
#include <bits/stdc++.h> using namespace std; const int N = 5e5 + 5; struct node { int l, r, m, tg, s; } t[N << 2]; inline void upd(int x) { t[x].s = t[x].tg ? 0 : t[x << 1].s + t[x << 1 | 1].s; } inline void build(int i, int l, int r) { t[i] = node{l, r, l + r >> 1, 0, r - l + 1}; if (l == r) return; build(i <...
8
#include <bits/stdc++.h> using namespace std; namespace modular { const int mod = 1000000007; inline int add(int x, int y) { return x + y >= mod ? x + y - mod : x + y; } inline int dec(int x, int y) { return x - y < 0 ? x - y + mod : x - y; } inline int mul(int x, int y) { return 1ll * x * y % mod; } } // namespace mo...
11
#include <bits/stdc++.h> using namespace std; vector<pair<pair<int, int>, char> > A[4]; bool check(char x, int indx) { if (x == 'Q') return 1; if (x == 'R' && (indx == 0 || indx == 1)) return 1; if (x == 'B' && (indx == 2 || indx == 3)) return 1; return 0; } int main() { int n; cin >> n; int x0, y0; cin...
4
#include <bits/stdc++.h> using namespace std; long long dp[5010][5010]; int A[300010]; int main() { ios_base::sync_with_stdio(0); int n, k; cin >> n >> k; for (int i = 0; i < n; i++) cin >> A[i]; sort(A, A + n); dp[0][0] = 0; int lsize = (n + k - 1) / k; int ssize = lsize - 1; int llim = n % k; if (...
6
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, m, gn1 = 0, gj1 = 0, gn2 = 0, gj2 = 0; cin >> n >> m; for (int i = 0; i < n; i++) { int x; cin >> x; if (x % 2 == 0) gn1++; else gj1++; } for (int i = 0; i...
0
#include <bits/stdc++.h> using namespace std; int n; pair<long long, long long> a[200007]; long long cnt[200007]; long long gcd(long long a, long long b) { while (b) { a %= b; swap(a, b); } return a; } long long gg[200007]; vector<vector<long long> > t; vector<int> mod = {1000066153, 1000025129, 100007405...
9
#include <bits/stdc++.h> using namespace std; int n, k, a, b, l; int main() { for (std::cin >> n >> k; n; n--) { std::cin >> a; b = 0; while (a) { if (a % 10 <= k) b |= 1 << a % 10; a /= 10; } if (b + 1 == 2 << k) l++; } std::cout << l; }
1
#include <bits/stdc++.h> using namespace std; vector<pair<pair<int, int>, int> > aq; bool aquecido(pair<int, int> coord, pair<pair<int, int>, int> ac) { int xg = coord.first; int yg = coord.second; int xa = ac.first.first; int ya = ac.first.second; int r = ac.second; if ((pow((xa - xg), 2) + (pow((ya - yg),...
2
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; int m; int x, y, ans; int dx[5] = {0, 0, 1, -1}; int dy[5] = {1, -1, 0, 0}; int b[4][100005], dp[100005][(1 << 3)], nxt[100005]; char a[4][10005]; bool vis[1 << 4]; bool inside(int x, int y) { if (0 <= x && x <= 2 && 1 <= y && y <= m) return 1; ...
6
#include <bits/stdc++.h> using namespace std; const int N = 1e5; int f[N], mem[N], sv[N]; int h[N]; inline int get(int p) { if (f[p] == p) return p; return get(f[p]); } inline void join(int a, int b) { a = get(a); b = get(b); if (a == b) return; if (h[a] < h[b]) f[a] = b; else f[b] = a; if (h[a]...
8
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; int main() { int n, sum = 0; scanf("%d", &n); sum += n / 100; n %= 100; sum += n / 20; n %= 20; sum += n / 10; n %= 10; sum += n / 5; n %= 5; sum += n / 1; printf("%d\n", sum); return 0; }
0
#include <bits/stdc++.h> using namespace std; int n; pair<long long, long long> p[100010]; bool used[100010]; inline pair<long long, long long> operator-( const pair<long long, long long> &a, const pair<long long, long long> &b) { return {a.first - b.first, a.second - b.second}; } inline long long cross(const pai...
6
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); long long n, m; cin >> n >> m; vector<long long> a(n), 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()); ...
3
#include <bits/stdc++.h> using namespace std; const int N = 1e3 + 10; int a[N], sum[N]; int main() { int n, w; scanf("%d%d", &n, &w); for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); sum[i] = sum[i - 1] + a[i]; } sort(sum + 1, sum + n + 1); int x = sum[1], y = sum[n]; int minn = max(0, -x), maxx...
3
#include <bits/stdc++.h> using namespace std; long long int mod = 1e9 + 7; long long int pow1(long long int first, long long int n, long long int m) { long long int result = 1; while (n > 0) { first %= m; if (n % 2 == 1) result = (result * first) % m; first = (first * first) % m; n = n / 2; } re...
4
#include <bits/stdc++.h> using namespace std; long long dp[400 + 5][400 + 5]; void init() { memset(dp, 0, sizeof(dp)); dp[1][1] = dp[1][0] = 1; for (int i = 2; i <= 400; i++) for (int j = 0; j <= 400; j++) for (int k = 0; k + j <= 400; k++) { long long temp = (dp[i - 1][j] * dp[i - 1][k]) % 1000...
10
#include <bits/stdc++.h> using namespace std; int main() { long long int n, x, y; cin >> n >> x >> y; long long int a[n + 1]; a[1] = x; for (int i = 2; i <= n; i++) { if (i % 2 == 0) { a[i] = min(a[i - 1] + x, a[i / 2] + y); } else { a[i] = min(a[i - 1] + x, a[(i + 1) / 2] + y + x); } ...
6
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t; long long int n, m; cin >> n >> m; int arr[m][3]; for (int i = 0; i < m; i++) { long long int a, b, c; cin >> a >> b >> c; arr[i][0] = a; arr[i][1] = b; arr[i][2] =...
3
#include <bits/stdc++.h> using namespace std; const int maxn = 100010; int gcd(int x, int y) { if (y == 0) return x; return gcd(y, x % y); } int main() { int n; cin >> n; vector<int> v(n); for (long long i = 0; i < n; i++) cin >> v[i]; int max = 0; if (n < 3) { cout << n; return 0; } for (lo...
1
#include <bits/stdc++.h> using namespace std; int n, m, c[9][9], a[9][9], ans = 0; bool flag = 0; int w[4][5][2] = {{{0, 0}, {0, 1}, {0, 2}, {1, 1}, {2, 1}}, {{0, 2}, {1, 0}, {1, 1}, {1, 2}, {2, 2}}, {{0, 1}, {1, 1}, {2, 0}, {2, 1}, {2, 2}}, {{0, 0}, {1, 0}, {1, 1},...
7
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { int n; cin >> n; static int a[23]; for (int i = 0; i < n; ++i) { cin >> a[i]; } static int dp[1 << 23]; dp[0] = 0; dp[1] = 1; vector<pair<int, int> > p[23]; for (int i = 0; i < n; ++i) { for (int x = 0; x < i; +...
7
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 22; int n, a, b, c, d, t0, t1, cnt; char res[MAXN]; int f(int x) { for (__typeof(1e5) i = (0) - ((0) > (1e5)); i != (1e5) - ((0) > (1e5)); i += 1 - 2 * ((0) > (1e5))) { if (i * (i - 1) > 2 * x) { cout << "Impossible"; exit(0);...
5
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int n, sum = 0; cin >> n; long long int A[n][n], i, j; for (i = 0; i < n; i++) for (j = 0; j < n; j++) cin >> A[i][j]; for (i = 0; i < n; i++) for (j = 0; j < n; j++) if (i =...
0
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; long long ans = 0; for (int i = (0); i < (n); ++i) { long long t, T, x, cost; cin >> t >> T >> x >> cost; if (t >= T) { ans += cost + m * x; continue; } long long aux1 = cost; if (m > (T - t))...
5
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); ; int t; cin >> t; while (t--) { long long a, b, n, c = 0, d; cin >> a >> b >> n; if (a < b) swap(a, b); while (a <= n) { b += a; c++; swap(a, b); } cout << c << endl; ...
0
#include <bits/stdc++.h> using namespace std; int main() { int t, b, w, x, y; scanf("%d", &t); while (t--) { scanf("%d%d", &b, &w); x = 3; y = 2; if (b > w) { swap(b, w); x--; } if (w <= 3 * b + 1) { printf("YES\n"); while (b >= 1) { printf("%d %d\n", x, y);...
5
#include <bits/stdc++.h> using namespace std; int main() { int tc = 1; cin >> tc; while (tc--) { string st; cin >> st; int r = 0, s = 0, p = 0, mx = 0; for (int i = 0; i < st.size(); i++) { if (st[i] == 'S') s++; if (st[i] == 'P') p++; if (st[i] == 'R') r++; } mx = max(ma...
3
#include <bits/stdc++.h> using namespace std; int lsb(int val) { return val & ((val ^ (val - 1))); } pair<int, pair<int, int> > a[600666]; int Arb[600666], SEG[600666], result[600666]; bool comp(pair<int, pair<int, int> > i1, pair<int, pair<int, int> > i2) { return i1.second.second < i2.second.second; } int query(int...
5
#include <bits/stdc++.h> using namespace std; const int MAX = 1e6 + 6; vector<pair<int, int> > g[MAX], g1[MAX]; int p[MAX]; vector<int> calc[MAX]; vector<long long> pref[MAX]; void dfs(int v, int pr) { p[v] = pr; for (auto u : g[v]) if (u.first != pr) { dfs(u.first, v); g1[v].push_back(u); } } i...
7
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int pc[1 << 10]; for (size_t i = 0; i < (1 << 10); i++) { int buf = 0; for (int j = 0; j < 10; j++) { if ((1 << j) & i) buf++; } pc[i] = buf; } int n, m; cin ...
6
#include <bits/stdc++.h> using namespace std; vector<string> depth[1500000]; int w, k = 0; int a = 0; struct Test { string in; int child; } P[1500000]; void compute(int dep) { w = max(w, dep); while (a != k) { int sz = 0; depth[dep].push_back(P[a].in); int ws = a; while (P[ws].child != sz) { ...
4
#include <bits/stdc++.h> using namespace std; const long long INF = 1e15; const long long MX = 500; const long long INF2 = 1e9; struct Hungarian { long long matchRow[MX]; long long matchCol[MX]; long long assign(vector<vector<long long>> A) { long long n = A.size(); long long m = A[0].size(); vector<l...
8
#include <bits/stdc++.h> using namespace std; #pragma comment(linker, "/stack:256000000") long long qs(long long n) { long long s = 0; for (long long i = (n / 4) * 4; i <= n; i++) s ^= i; return s; } long long f(long long i, long long n) { long long q = n / i, p = n % i, s = 0; if (q % 2 != 0) s = qs(i - 1); ...
4
#include <bits/stdc++.h> using namespace std; int n; int a[100005]; int d[1 << 13]; int pv[1 << 13]; queue<int> q; void bfs(int k, bool tp) { memset(d, 0x3f, sizeof d); if (tp) { for (int i = 0; i < (signed)(1 << 5); i++) { d[i] = 0; q.push(i); } } else { d[0] = 0; q.push(0); } int...
9
#include <bits/stdc++.h> using namespace std; const int MAXN = 300 + 5; const int MBIT = 15 + 5; const int INF = 0x3f3f3f3f; int n, m, MT, dp[MBIT][MAXN][MAXN]; int ans[2][MAXN][MAXN]; inline void umax(int& a, const int& b) { a = max(a, b); } void init() { MT = (int)floor(log2((long double)n)); for (int s = 0; s <=...
8
#include <bits/stdc++.h> using namespace std; long long t; int a[1000000], i, j, k, n, m, x, y, z; int main() { cin >> n >> k; for (i = 1; i <= n; i++) scanf("%d", a + i); int l = 1; int r = 2 * 2e9; while (l < r) { int mid = ((long long)l + r) / 2; if (l == mid) mid++; t = 0; for (i = 1; i <=...
6
#include <bits/stdc++.h> using namespace std; const int mod = (int)1e9 + 7; pair<long long int, long long int> s4[4] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}}; pair<long long int, long long int> s8[8] = { {-1, -1}, {-1, 0}, {-1, 1}, {0, -1}, {0, 1}, {1, 1}, {1, 0}, {1, -1}}; void judge() {} void solve() { long long in...
2
#include <bits/stdc++.h> using namespace std; int main() { int n, m, cnt = 0; scanf("%d %d", &n, &m); int a[n]; int b[m]; for (int i = 0; i < n; i++) { scanf("%d", &a[i]); } for (int i = 0; i < m; i++) { scanf("%d", &b[i]); } for (int i = 0, j = 0; i < n; i++) { while (b[j] < a[i] && j < m...
2
#include <bits/stdc++.h> using namespace std; pair<long long int, int> trains[3 * 100005]; bool used[100005]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int n, m, h, k; cin >> n >> h >> m >> k; for (int i = 0; i < n; i++) { int temp; long long int val; cin >> temp >> v...
7