solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> using namespace std; const long long inf = (long long)1000000000 * 1000000000 / 4; bool f; vector<int> v[100]; pair<long long, long long> ans[100]; void solve(int u, int fa, int d, long long lx, long long rx, long long ly, long long ry) { if (u <= 0) return; if (v[u].size() > 4 |...
12
#include <bits/stdc++.h> using namespace std; void test() { cerr << endl; } template <typename T, typename... Args> void test(T x, Args... args) { cerr << x << " "; test(args...); } const int MAXN = (int)1e5 + 5; const int MOD = (int)1e9 + 7; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie...
11
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e4 + 5; const double EPS = 1e-16; const long long INF = 1000000000 + 5; const int MAXN2 = 2e5 + 5; int g[10][10]; int main() { int m; scanf("%d", &m); int u, v; for (int i = 0; i < m; i++) { scanf("%d%d", &u, &v); g[u][v] = g[v][u] = 1; }...
5
#include <bits/stdc++.h> using namespace std; int main() { long a, b, x, i, c = 0; cin >> a >> b >> x; if (a != 1) for (i = 0; i < (a - x / 2); i++) { c++; cout << 0; } for (i = 0; i < x / 2 - 1; i++) cout << 1 << 0; if (x / 2 > 0) { cout << 1; if (x % 2 == 1) cout << 0; } if (...
5
#include <bits/stdc++.h> using namespace std; const int di[] = {-1, 0, 1, 0, -1, 1, 1, -1}; const int dj[] = {0, 1, 0, -1, -1, 1, -1, 1}; const long long MOD = 1e9 + 7; const long long INF = 1e9; const long double EPS = 1e-7; struct Max { long long v1 = 0, v2 = 0; int c1 = -1, c2 = -1; void add(long long& v, long...
12
#include <bits/stdc++.h> using namespace std; const double PI = 2 * asin(1.0); const int INF = 1000000000; const double EPS = 1e-10; inline int cmp(double x, double y = 0, double tol = EPS) { return (x <= y + tol) ? (x + tol < y) ? -1 : 0 : 1; } inline long long gcd(long long a, long long b) { return b == 0 ? abs(a...
6
#include <bits/stdc++.h> using namespace std; const long long maxn = 12; long long n, p[maxn], no; struct point { double x, y; point() { x = y = 0; } point operator-(point xx) { point yy; yy.x = x - xx.x; yy.y = y - xx.y; return yy; } double operator*(point xx) { return x * xx.y - y * xx.x; } ...
12
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 10; const long long INFL = 0x3f3f3f3f3f3f3f3fLL; int n, m, q, aSize; int a[N], b[N]; int main() { scanf("%d%d%d", &n, &m, &q); int p = 0; aSize = 0; for (int i = 1; i <= m; ++i) { int v; scanf("%d", &v); for (int j = p; j <= v - 1; ++...
13
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const long long int llINF = 0x3f3f3f3f3f3f3f; const int MAXN = 100100; const long long int mod = 1e9 + 7; const int LMAXN = 20; int mx[4] = {1, -1, 0, 0}; int my[4] = {0, 0, -1, 1}; int n, m, p; int freq[11], s[11]; set<tuple<int, int, int> > fil...
11
#include <bits/stdc++.h> using namespace std; const int N = 301; const int INF = (int)2e9; int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a); } int n; int l[N], c[N]; map<pair<int, int>, int> dp; int solve(int pos, int g) { if (pos == n) { if (g == 1) return 0; else return INF...
11
#include <bits/stdc++.h> using namespace std; int main() { int test; cin >> test; int i = 0; while (i < test) { int a, b; cin >> a >> b; int w = b - a; int p = 0, q = 0, sum = 0; int data; if (w > 0) { data = w; } if (w < 0) { data = -w; } if (w == 0) { ...
0
#include <bits/stdc++.h> using namespace std; long long t, k; long long m[4]; int main() { cin >> t; for (int i = 1; i <= t; i++) { k = 0; cin >> m[1] >> m[2] >> m[3]; sort(m + 1, m + 4); if (m[3] == m[2]) { k = m[2] + m[1] / 2; } else if (m[3] - m[2] <= m[1]) { m[1] -= m[3] - m[2]; ...
3
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:100000000000,100000000000") using namespace std; const double eps = 1E-9; const double Exp = 2.718281828459045; const double Pi = 3.1415926535897932; const int NMAX = 1000 + 5; const int MMAX = 100000 + 5; const int INF = 1000000000; const int BASE = 1000000007; ...
8
#include <bits/stdc++.h> using namespace std; int main() { int n, m, mas[101], cnt = 0; cin >> n >> m; for (int i = 1; i <= m; i++) mas[i] = 0; for (int i = 0; i < n; i++) { int a, b; cin >> a >> b; for (int j = a; j <= b; j++) mas[j] = 1; } for (int i = 1; i <= m; i++) if (mas[i] == 0) cnt+...
0
#include <bits/stdc++.h> using namespace std; int main() { long long int v; cin >> v; if (v == 2) { cout << 2 << endl; return 0; } cout << 1 << endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; long long extended_gcd(long long A, long long B, long long& k, long long& l) { long long s = 0, s2 = 1; long long t = 1, t2 = 0; long long r = B, r2 = A; while (r) { long long q = r2 / r; long long aux = r; r = r2 - q * aux; r2 = aux; aux = s; ...
18
#include <bits/stdc++.h> using namespace std; const int INF = (int)(1e9 + 7); struct Vertex { Vertex *l, *r; long long mini; Vertex(long long val) : l(nullptr), r(nullptr), mini(val) {} Vertex(Vertex* l, Vertex* r) : l(l), r(r), mini(INF) { if (l) mini = min(mini, l->mini); if (r) mini = min(mini, r->mi...
16
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; const int MAXN = 1e5 + 5; int fastexpo(int b, int exp) { if (exp == 0) return 1; if (exp == 1) return b; int ans = (fastexpo(b, exp / 2) % MOD); ans *= ans; ans %= MOD; if (exp % 2 == 1) { ans *= b; } ans %= MOD; return ans; } ...
10
#include <bits/stdc++.h> using namespace std; int n; vector<pair<long long, vector<long long>>> v; long long maxx = 0; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; v.resize(n); for (int i = 0; i < n; i++) { int x; cin >> x; v[i].second.resize(x); v[i].first = 0; ...
5
#include <bits/stdc++.h> using namespace std; const int siz1 = 9e4, siz2 = 3e5, siz3 = 1e6; int t, n, m, bit[siz1 + 5], sts[siz1 + 5]; pair<int, int> arr[siz1 + 5]; int sum(int r) { int ret = 0; for (; r >= 0; r = (r & (r + 1)) - 1) ret += bit[r]; return ret; } int sum(int l, int r) { return sum(r) - sum(l - 1); ...
8
#include <bits/stdc++.h> using namespace std; vector<int> primes = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47}; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int cnt = 0; int x; for (auto a : primes) { cout << a << endl; string temp; cin >> temp; if (temp == "yes") { ...
6
#include <bits/stdc++.h> using namespace std; string st; int n; int dp[101][201][2][51]; int best = -1; int ABS(int x) { if (x < 0) return -x; return x; } void result(int i, int y, bool pos, int change) { if (i == st.size()) { if (change % 2 == 0) { if (y >= 100) best = max(best, y - 100); ...
10
#include <bits/stdc++.h> using namespace std; const long long C = 6; const long long K = 60; const long long P = 1e9 + 7; long long dp[K]; long long mod(long long x) { return x > 0 ? x : -x; } long long invalid(long long x) { return mod(x) == 3 or x == 0; }; void fillDp() { for (long long k = 0; k < K; k++) { if ...
15
#include <bits/stdc++.h> using namespace std; #pragma comment(linker, "/stack:200000000") #pragma GCC optimize("Ofast") #pragma GCC optimize(3) #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #pragma GCC target("sse3", "sse2", "sse") #pragma GCC target("avx", "sse4", "sse4.1", "sse4.2", "s...
19
#include <bits/stdc++.h> using namespace std; const int maxn = 710; int gcd(int a, int b) { return a ? gcd(b % a, a) : b; } int dp[maxn][maxn][2], mp[maxn][maxn], n, a[maxn]; int solve(int l, int r, int k) { if (dp[l][r][k] >= 0) return dp[l][r][k]; dp[l][r][k] = 0; int fa = k ? l - 1 : r; if (l >= r) return dp...
13
#include <bits/stdc++.h> using namespace std; char s[1000000]; int bo[1000], n, m, ans, t, boo; int main() { scanf("%s", s); n = strlen(s); for (int i = 1; i < n; i++) { ++bo[s[i] % 3]; t = (t + s[i]) % 3; if (s[i] == 48) ++boo; } t = (t + s[0]) % 3; if (!t) { for (int i = 0; i < n; i++) pri...
12
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:256000000") using namespace std; string num2str(int i) { stringstream ss; ss << i; return ss.str(); } std::vector<std::string> Split(std::string str, std::string pattern) { std::string::size_type pos; std::vector<std::string> result; str += pattern; ...
4
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; long long test, n, m, k, x, y, ans, a[N], b[N]; void solve() { cin >> n >> k; cout << (n / k % 2 ? "YES" : "NO"); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); solve(); }
0
#include <bits/stdc++.h> using namespace std; int n, m, k, a[1000009], b[1000009]; int main() { scanf("%d%d%d", &n, &m, &k); int i, q = 0, t, l, r; for (i = 1; i <= m; i++) { scanf("%d", &t); b[t] = 1; } a[1] = 1; t = 1; if (b[1] == 1) q = 1; for (i = 1; i <= k; i++) { scanf("%d%d", &l, &r);...
5
#include <bits/stdc++.h> using namespace std; int dp[8], wtf[8], n, m, i; string s; int main() { for (i = 1; i < 8; i++) dp[i] = 1 << 30; for (scanf("%d%d", &n, &m), i = 1; i <= n; i++) { cin >> s; copy(dp, dp + 8, wtf); for (int j = 0; j < s.size(); j++) { int idx = 2; if (s[j] >= 'a' && s[...
7
#include <bits/stdc++.h> char* concat(char* str1, char* str2) { char* str3 = (char*)malloc(1 + strlen(str1) + strlen(str2)); strcpy(str3, str1); strcat(str3, str2); return str3; } char* intToString(int i) { char* ans = (char*)malloc(65); sprintf(ans, "%d", i); return ans; } int stringToInt(char* str) { re...
8
#include <bits/stdc++.h> using namespace std; mt19937 myrand(chrono::steady_clock::now().time_since_epoch().count()); template <typename Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 << '\n'; } template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&.....
12
#include <bits/stdc++.h> using namespace std; const long long MAX = 200100; const long long TOP = 2e9; long long N, K, S, T; long long C[MAX], V[MAX]; long long G[MAX], lo, hi; long long g(long long v, long long d) { if (d > v) return TOP + 10; long long f = min(v - d, d); return f + (d - f) * 2; } bool p(long lo...
9
#include <bits/stdc++.h> using namespace std; template <typename TH> void _dbg(const char *sdbg, TH h) { cerr << sdbg << "=" << h << "\n"; } template <typename TH, typename... TA> void _dbg(const char *sdbg, TH h, TA... t) { while (*sdbg != ',') { cerr << *sdbg++; } cerr << "=" << h << ","; _dbg(sdbg + 1,...
8
#include <bits/stdc++.h> using namespace std; int a[int(2e5) + 10] = {0}; long long x[111][2600]; int main() { ios::sync_with_stdio(false); cin.tie(0); int t; cin >> t; memset(x, 0, sizeof(x[0][0]) * 2600 * 111); for (int i = 0; i < 26; i++) x[1][i] = 1; for (int i = 2; i < 111; i++) { for (int j = 0;...
12
#include <bits/stdc++.h> using namespace std; int main() { int t, n, i; cin >> t; for (i = 0; i < t; i++) { cin >> n; int sum = 0, sumEven = 0, sumOdd = 0; int array[n]; for (int i = 1; i <= n; i++) { scanf("%d", &array[i]); sum += array[i]; if (array[i] % 2 == 0) { sumEv...
0
#include <bits/stdc++.h> using namespace std; int main() { string str; cin >> str; int n = str.length(); int count1 = 0; int count2 = 0; for (int i = 0; i < n; i++) { if (str[i] == '-') { count1++; } else { count2++; } } if (count1 == 0) { cout << "YES\n"; return 0; } ...
1
#include <bits/stdc++.h> using namespace std; int sign(double x) { if (x > 1e-10) return 1; else if (x < 1e-10) return -1; return 0; } double cal(double a, double b) { if (b < 1e-10) return 1; else if (a < 1e-10) return 0.5; else { double x = a / 4; int s = sign(x - b); if (s >= ...
10
#include <bits/stdc++.h> using namespace std; vector<pair<long long, long long> > factor(long long x) { vector<pair<long long, long long> > res; for (long long i = 2; i * i <= x and x != 1; ++i) { int qtt = 0; while (x % i == 0) { ++qtt; x /= i; } if (qtt > 0) res.push_back(pair<long lon...
6
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 15; set<int> st[N]; int l, r, x, p, n, m, t, A[N]; struct fen { unordered_map<int, long long> mp[N]; fen() { for (int i = 1; i <= N - 1; i++) mp[i].max_load_factor(0.12); } void add(int l, int R, int d) { for (l++; l < N; l += l & (-l)) ...
18
#pragma GCC optimize(3) #pragma GCC optimize("Ofast") #include<bits/stdc++.h> using namespace std; #define ll long long int t,n,k,p1[30],p2[30]; string a,b; int main() { ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); cin>>t; while(t--) { cin>>n>>k; cin>>a>>b; memset(p1,0,sizeof(p1)); memset(p2,0,s...
6
#include <bits/stdc++.h> int main() { long long int n, k, d; std::cin >> n >> k >> d; long long int k__d = k, possible = 0; for (int i = 0; i < d; i++) { if (n <= k__d) { possible = 1; break; } k__d = k__d * k; } if (!possible) { printf("-1"); return 0; } long long int t ...
11
#include <bits/stdc++.h> using namespace std; long long M = 1e9 + 7; const long long N = 1000 + 10; const long long IM = 1e15 + 37; const long long PI = 3.14159265; void PV(vector<long long> v) { for (long long i = 0; i < v.size(); i++) cout << v[i] << " "; cout << "\n"; } void PA(long long v[], long long n, long l...
5
#include <bits/stdc++.h> using namespace std; int main() { int TUX; cin >> TUX; int FOO = 0, BAR = 0, BAZ = 0, QUZ = 1; while (TUX--) { int PUR; cin >> PUR; FOO = FOO + PUR; BAR = BAR + 1; if (FOO * QUZ > BAZ * BAR) { BAZ = FOO; QUZ = BAR; } } cout << (double)BAZ / QUZ <<...
9
#include <bits/stdc++.h> using namespace std; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long int t; cin >> t; while (t--) { long long int n, x; cin >> n >> x; long long int a[n]; map<long long int, long long int> p; for (long long int i = 0; i...
4
#include <bits/stdc++.h> using namespace std; int flag[100001]; int a[100001], b[100001], c[100001]; int work = 0; int deep = 0; int dfs(int a_val, int b_val, int c_val, int m) { int ach = 0; int bch = 0; int cch = 0; deep++; if (!flag[a[deep]]) { ach = 1; flag[a[deep]] = a_val; } if (!flag[b[deep...
6
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); long long l, r, x, y, k; cin >> l >> r >> x >> y >> k; for (size_t i = (x); i < (y + 1); i++) { if (i * k >= l && i * k <= r) { puts("YES"); return 0; } } puts("NO"); }
4
#include <bits/stdc++.h> using namespace std; int h; long long n; long long dfs(int d, long long n, int lr) { if (d == h) return 0; if (!lr && n > (1LL << (h - d - 1))) return (1LL << (h - d)) + dfs(d + 1, n - (1LL << (h - d - 1)), 0); if (lr && n <= (1LL << (h - d - 1))) return (1LL << (h - d)) + dfs(d +...
9
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); int n; cin >> n; if (n == 1) { cout << -1 << endl; return 0; } vector<int> a(n); for (int i = 0; i < n; i++) cin >> a[i]; sort(a.begin(), a.end()); map<int, int> s; for (int i = 1; i < n; i++) { int ...
9
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 11; const int mod = 1e9 + 7; char s[N]; int sum[N]; long long p[N]; long long fac[N]; long long fac_ni[N]; pair<long long, long long> extend_gcd(long long a, long long b) { if (b == 0) return make_pair(1, 0); pair<long long, long long> t = extend_gcd...
14
#include <iostream> #include <cstdio> using namespace std; // <|°_°|> const int MAX_VALEURS = (100 * 1000 + 2); int Val[MAX_VALEURS]; int Last[MAX_VALEURS]; int Next[MAX_VALEURS]; int Top[2]; int nbValeurs; void Read() { scanf("%d", &nbValeurs); int ans = 0; Next[0] = MAX_VALEURS + 2; for (int i...
13
#include <bits/stdc++.h> using namespace std; const int maxN = 2e5 + 10; queue<int> que[maxN]; int ans[maxN]; int main() { int n, x; scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d", &x); que[x].push(i); } int now = 0; for (int i = 1; i <= n; i++) { while (que[now].empty() && now - 3 >...
11
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 5; int a[N]; int main() { int n; long long k; scanf("%d %lld", &n, &k); long long sum = 1LL * n * (n + 1) / 2; if (sum > k) { puts("-1"); return 0; } for (int i = 1; i <= n; i++) a[i] = i; int l = 1; long long dre = k - sum; f...
16
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; long long powmod(long long a, long long b) { long long res = 1; a %= mod; for (; b; b >>= 1) { if (b & 1) res = res * a % mod; a = a * a % mod; } return res; } int n, m; vector<string> input; int dp[1 << 20]; int cost[20][...
17
#include <bits/stdc++.h> using namespace std; const int MAXN = 2005; int N, M, Q, ans[MAXN], Ans; int Up[MAXN][MAXN], Do[MAXN][MAXN]; int Le[MAXN][MAXN], Ri[MAXN][MAXN]; int dp[MAXN][MAXN]; char c[MAXN][MAXN]; int d[MAXN], u[MAXN]; struct Node { int x, y; } s[MAXN]; void Prepare() { for (int i = 1; i <= M; i++) Do[...
20
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long n; cin >> n; string s; cin >> s; long long cnt = 0; for (long long i = 0; i <= n - 1; i++) { if (s[i] == 'T') cnt++; } long long ma = LLONG_MAX; for (long long i = ...
8
#include <bits/stdc++.h> using namespace std; const int N = 125010; const double pi = acos(-1); char s[N], t[N]; int rev[N << 2], num[6][6][N << 2], fa[8]; struct cp { double real, imag; cp(double x = 0, double y = 0) { real = x; imag = y; } cp operator+(const cp &t) const { return cp(real + t.real, ima...
14
#include <bits/stdc++.h> using namespace std; const int M = 1000000000; const int N = 1000 + 10; struct re { int x, y; }; int n, m, q, _n, _m; int a[N][N], f[N][N]; int area(int x, int y, int u, int v) { return f[u][v] - f[x - 1][v] - f[u][y - 1] + f[x - 1][y - 1]; } void init() { for (int i = (1); (i <= (n)); ++...
17
#include <bits/stdc++.h> using namespace std; string s; int mx = 0; int m, n; const long long mod = (long long)(1e9 + 7); long long dp[2001][2001]; int main() { ios::sync_with_stdio(false); cin >> n >> m; cin >> s; int cnt = 0; mx = -INT_MAX; for (int i = 0; i < m; ++i) { if (s[i] == ')') cnt++; ...
12
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; const long long N = 200005; long long n, arr[N], t, k, poss[2 * N], a, b, ans; signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> t; while (t--) { cin >> n >> k; memset(poss, 0, sizeof poss);...
0
#include <bits/stdc++.h> using namespace std; int main() { int n, k, x = 0; cin >> n >> k; int* a = new int[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < n - 1; i++) { if (a[i] + a[i + 1] < k) { x += k - (a[i] + a[i + 1]); a[i + 1] += k - (a[i] + a[i + 1]); } ...
2
#include <bits/stdc++.h> using namespace std; signed main() { ios_base::sync_with_stdio(false); cin.tie(0); long long t; cin >> t; for (long long i = 0; i < t; i++) { long long n; cin >> n; string str; cin >> str; long long mini = n + 1; long long left = 1; long long right = n; ...
7
#include <bits/stdc++.h> using namespace std; int main() { vector<int> v1, v2, res; int n, m, no; cin >> n >> m; v1.resize(n + 1, 0); res.resize(n + 1, 0); for (int i = 0; i < n; i++) { cin >> no; res[no] = i + 1; v1[no]++; } for (int i = 0; i < m; i++) { cin >> no; v2.push_back(no);...
7
#include <bits/stdc++.h> using namespace std; const int NN = 2004; int l[NN], s[NN], c[NN * 2], f[NN * 2][NN]; int main() { int n, m; scanf("%d%d", &n, &m); m = n + m; for (int i = n; i; i--) scanf("%d", &l[i]); for (int i = n; i; i--) scanf("%d", &s[i]); for (int i = 1; i <= m; i++) scanf("%d", &c[i]); m...
20
#include <bits/stdc++.h> using namespace std; int n, x, y; int main() { cin >> n, x = n / 3, y = n - 2 * x; for (int i = 1; i <= x; i++) cout << 1 << " " << 2 * i << "\n" << 3 << " " << 2 * i << "\n"; for (int i = 1; i <= y; i++) cout << 2 << " " << 2 * i + 1 << "\n"; return 0; }
18
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 5; long long n, k; vector<long long> primes; long long prime[N]; void sieve() { long long i, j; prime[0] = prime[1] = 1; for (i = 2; i < N; i++) { if (prime[i] == 0) { for (j = i + i; j < N; j += i) prime[j] = 1; primes.push_back(i)...
8
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 5; long long sum[N * 4], maxn[N * 4]; void pushup(int root) { sum[root] = sum[root << 1] + sum[root << 1 | 1]; maxn[root] = max(maxn[root << 1] + sum[root << 1 | 1], maxn[root << 1 | 1]); } void build(int l, int r, int root) { if (l == r) { max...
16
#include <bits/stdc++.h> using namespace std; const vector<int> dx = {0, 1, 0, -1, 0, 1, 1, -1, -1}; const vector<int> dy = {0, 0, 1, 0, -1, 1, -1, 1, -1}; void solve() { int n; cin >> n; vector<int> res(2 * n, -1); int nxt = 0; for (int i = 1; i <= n; i += 2) { res[nxt] = i; res[nxt + (n - i)] = i; ...
11
#include <bits/stdc++.h> using namespace std; template <class T> void Print_v(T &a) { int s = a.size(); for (int i = 0; i < s; i++) cout << a[i] << " "; cout << endl; } long long powmod(long long a, long long b) { long long ans = 1; while (b) { if (b & 1) ans = ans * a; a = a * a; b /= 2; } re...
9
#include <bits/stdc++.h> using namespace std; const long long MOD = 998244353; const long long INF = 0x3f3f3f3f3f3f3f3fLL; const int MAXN = 300000 + 5; const int MAXM = 600000 + 5; struct node { int no, a, b; } s[MAXN]; bool cmp_no(const node &p, const node &q) { return p.no < q.no; } bool cmp_a(const node &p, const ...
7
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int t, n, s, a, b, c, d; cin >> t; while (t--) { s = 0; cin >> a >> b; cin >> c >> d; if (max(a, b) == max(c, d)) { if (min(a, b) + min(c, d) == max(c, d)) s++; } ...
1
#include <bits/stdc++.h> using namespace std; const int MX = 200005; int ttime; void dfs(int node, int p, int lev, vector<vector<int>>& g, vector<int>& in, vector<int>& out, vector<int>& level) { in[node] = ttime++; level[node] = lev; for (auto& i : g[node]) { if (i == p) continue; dfs(i, node, l...
12
#include <bits/stdc++.h> using namespace std; long long n, m; map<string, long long> m1[102], m2[102]; string getss(string a, string b) { sort(a.begin(), a.end()); sort(b.begin(), b.end()); if (a[0] != b[0]) return b.substr(0, 1); for (int i = 1; i < a.size(); i++) { if (a[i] != b[i]) return b.substr(i, 1);...
16
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:1024000000,1024000000") using namespace std; const int maxn = 2005; int n, m; long long ans = 0; int h[maxn][maxn], d[maxn][maxn], cou1[maxn], cou2[maxn], cou3[maxn], cou4[maxn]; char mp[maxn][maxn]; void slove() { for (int i = 1; i <= n; i++) for (int ...
15
#include <bits/stdc++.h> using namespace std; int v[1000002], c[1000002], dp[1000002]; double p[1000002]; int main() { int n, m, i, j, k; double ans; scanf("%d%d", &n, &k); for (i = 1; i <= n; i++) { scanf("%d", &v[i]); v[i] *= 100; } for (i = 1; i <= n; i++) scanf("%d", &c[i]); p[n - 1] = 1.0 * k...
16
#include <bits/stdc++.h> using namespace std; int main() { long long int t; cin >> t; for (long long int i = 0; i < t; i++) { long long int r, g, b; cin >> r >> g >> b; if (g > r) { swap(r, g); } if (b > g) { swap(g, b); } if (g > r) { swap(r, g); } if (r >= g...
3
#include <bits/stdc++.h> using namespace std; inline void boost() { ios_base::sync_with_stdio(); cin.tie(0); cout.tie(0); } const long long maxn = 1e5 + 123; const long long inf = 1e9 + 123; const long long mod = 1e9 + 7; const double pi = acos(-1); int main() { boost(); int n, p, q; cin >> n >> p >> q; s...
5
#include <bits/stdc++.h> using namespace std; void solve() { int x, y, n; cin >> x >> y >> n; int p = n - y; int t = x; if (p % t == 0) cout << n << '\n'; else cout << p / t * x + y << '\n'; } signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int TESTS = 1; cin >> ...
0
#include <bits/stdc++.h> int *TheArray; int cmp(const void *a, const void *b) { int ia = *(int *)a; int ib = *(int *)b; return (TheArray[ia] > TheArray[ib]) - (TheArray[ia] < TheArray[ib]); } int compare(const void *a, const void *b) { return (*(int *)a - *(int *)b); } int main() { int n; scanf("%d", &n); i...
5
#include <bits/stdc++.h> using namespace std; string get_string(int delim) { string ret; int a; while ((a = getchar()) != delim && a != EOF) { ret += a; } return ret; } int main() { string s; s = get_string('\n'); for (int i = 1; i < s.size() - 1; i++) { if (s[i] == s[i - 1] && s[i] == s[i + 1])...
5
#include<bits/stdc++.h> using namespace std; int main(){ int t;cin>>t; while(t--){ int n;cin>>n; int a[2*n],b[2*n]; for(int i=0;i<2*n;i++){ cin>>a[i]; } int asize = sizeof(a) / sizeof(a[0]); sort(a, a + asize); for(int i=0;i<2*n;i++){ if(i%2==0) b[i]=a[i/2]; else b[i...
0
#include <bits/stdc++.h> using namespace std; const int N = 105; vector<int> x(2), y(2); void makeu(vector<int>& v) { sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end()); assert(v.size() < N); } struct TEdge { int from, to; long long capacity, flow; TEdge* reverse; }; TEdge edgePool[10000...
17
#include <bits/stdc++.h> const double eps = 1e-9; const int int_inf = 2000000000; const long long i64_inf = 1000000000000000000LL; const double pi = acos(-1.0); using namespace std; int n; int x[4000]; int y[4000]; bool t[4000][4000]; int main() { memset(t, 0, sizeof(t)); cin >> n; for (int i = 0; i < (int)n; i++...
5
#include <bits/stdc++.h> using namespace std; const int inf = (1 << 30) - 1; const long double eps = 1e-9; const long double pi = fabs(atan2(0.0, -1.0)); void ML() { int *ass; for (;;) { ass = new int[2500000]; for (int i = 0; i < 2500000; i++) ass[i] = rand(); } } int n; pair<int, int> a[1030]; void LoAd...
11
#include <bits/stdc++.h> using namespace std; long long int n, k; long long int a[100005]; long long int b[200005]; long long int grp[266]; set<long long int> s; long long int c[100005]; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); s.insert(0); memset(grp, -1, sizeof grp); cin >> n >> ...
9
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; const long long modx = 998244353; const long long Nx = 1e7 + 2; const long long inf = (long long)(1e19 + 10LL); bitset<Nx> bs; void sieve() { bs.set(); bs[0] = bs[1] = 0; for (long long i = 2; i < Nx; i++) { if (bs[i]) { for (l...
9
#include <bits/stdc++.h> using namespace std; int main() { int c, d, m, n, k; while (cin >> c >> d) { cin >> n >> m; cin >> k; int need = m * n; need -= k; if (need <= 0) { cout << 0 << endl; continue; } if (c >= n * d) cout << need * d << endl; else { int ans...
7
#include <bits/stdc++.h> using namespace std; vector<int> al; int n; string c1 = "23456789TJQKA"; string c2 = "SDHC"; int ha[256]; int rec[52][52][52][52]; bool mat(int a, int b) { bool r = ((a % 4) == (b % 4)) || ((a / 4) == (b / 4)); return r; } int dp(int x, int a, int b, int c) { int *p = &rec[x][a][b][c]; ...
11
#include <bits/stdc++.h> using namespace std; const int N = 200010; int lazy[4 * N]; enum { NONE, NTOP, PTON, FLIP }; int combine(int op1, int op2) { if (op1 == NONE) return op2; if (op2 == NONE) return op1; if (op1 == op2) { if (op1 == FLIP) return NONE; return op1; } if (op1 == PTON) return NTOP; ...
16
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; const long long MM = 1e15 + 37; clock_t time_p = clock(); void rtime() { time_p = clock() - time_p; cerr << "Time Taken : " << fixed << (float)(time_p) / CLOCKS_PER_SEC << "\n"; } long long rr[] = {0, 1, 1, 1, 0, -1, -1, -1}; long long cc[...
7
#include <bits/stdc++.h> using namespace std; const int N = 2005; int n, m, fa[N], inDeg[N], val[N]; string s[1005]; vector<int> g[N]; int fi(int x) { return fa[x] == x ? x : fi(fa[x]); } void unite(int x, int y) { fa[fi(y)] = fi(x); } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> n >> m; fo...
12
#include <bits/stdc++.h> using namespace std; int main() { int t, i, n; cin >> t; for (i = 1; i <= t; i++) { cin >> n; if (n % 4 != 0) { cout << "NO" << endl; } else { cout << "YES" << endl; for (int j = 1; j <= n; j++) { if (j % 2 == 0) cout << j << " "; } for (i...
0
#include <bits/stdc++.h> using namespace std; void solve() { long long n; cin >> n; for (int i = n; i > 0; i--) { cout << i << " "; } cout << endl; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int t; cin >> t; while (t--) { solve(); } return 0; }
0
#include <bits/stdc++.h> using namespace std; template <typename T, typename U> inline void smin(T &a, U b) { if (a > b) a = b; } template <typename T, typename U> inline void smax(T &a, U b) { if (a < b) a = b; } template <class T> inline void gn(T &first) { char c, sg = 0; while (c = getchar(), (c > '9' || c ...
14
#include <bits/stdc++.h> using namespace std; int main() { int s1t[10002][26]; string s1; char c; int i, j, k, n; cin >> s1; for (j = 0; j < 26; j++) { s1t[s1.length() - 1][j] = -1; } s1t[s1.length() - 1][s1[s1.length() - 1] - 'a'] = 0; for (i = s1.length() - 2; i >= 0; i--) { for (j = 0; j < ...
7
#include <bits/stdc++.h> using namespace std; const int maxn = 300000 + 123; struct Tlevel { int a, b, idx; bool operator<(const Tlevel& a) const { return b < a.b; } }; Tlevel levels[maxn]; long long nsum = 0; long long tsum = 0; multiset<int> S; long long minn; int ap; vector<pair<int, int> > vans; int n, w; int a...
18
#include<iostream> using namespace std; #include<bits/stdc++.h> #include<string.h> #include <iomanip> #include <ctype.h> #define ll long long int #define test cout<<"Nevil\n"; #define ios ios_base::sync_with_stdio(false); cin.tie(NULL) #define pi 3.14159265359 int main() { ios; ll cases=1; cin>>cases; ...
0
#include <bits/stdc++.h> using namespace std; const int maxn = 500005; const long long mod = 1e9 + 7; const long long INF = 1e18; const double eps = 1e-6; int n, q, cnt; int tree[maxn << 2]; int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } void pushup(int rt) { tree[rt] = gcd(tree[rt << 1], tree[rt << 1 | 1]); }...
11
#include <bits/stdc++.h> using namespace std; int main(void) { long long n; cin >> n; string s; cin >> s; long long ans = 0; long long l = -1, r = -1; for (int i = 0; i < (n - 1); i++) { if (s[i] != s[i + 1]) { l = i; break; } } for (int i = n - 1; i > 0; i--) { if (s[i] != s[i...
5
#include <bits/stdc++.h> using namespace std; int main() { int n, r[11000]; cin >> n; for (int i = 0; i < n; i++) { int l; cin >> l >> r[i]; } int k, t = 0; cin >> k; for (int i = 0; i < n; i++) { if (r[i] >= k) { t++; } } cout << t; }
0