solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> using namespace std; namespace fft { struct num { double x, y; num() { x = y = 0; } num(double x, double y) : x(x), y(y) {} }; inline num operator+(num a, num b) { return num(a.x + b.x, a.y + b.y); } inline num operator-(num a, num b) { return num(a.x - b.x, a.y - b.y); } inline num opera...
19
#include <bits/stdc++.h> using namespace std; vector<vector<int> > gr; vector<vector<int> > grs; vector<int> col; int k = 0; int gcd(int a, int b) { while (b) { a %= b; swap(a, b); } return a; } int f(int c) { if (k == 0) return c; return (c % k + k) % k; } const int MAX = 1e9; void dfs(int v, int c) ...
14
#include <bits/stdc++.h> typedef long long int ll; using namespace std; int main() { ll t; cin>>t; //t=1; while(t--) { ll n,m,k,j,i,y,x,z,a,b,c,d,o; ll count=0,ans=0,maxi=LLONG_MIN,mini=LLONG_MAX,flag=0; char ch; vector<long long int> vecy,vect; string str,strs; map<ll,ll> mp; ...
9
#include <bits/stdc++.h> using namespace std; int N, x[5005], y[5005], L = 1e9, R = -1e9, D = 1e9, U = -1e9; int main() { scanf("%d", &N); for (int i = 1, X, Y; i <= N; i++) scanf("%d%d", &X, &Y), x[i] = X - Y, y[i] = X + Y, L = min(L, x[i]), R = max(R, x[i]), D = min(D, y[i]), U = ma...
18
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; int cnt[5] = {0, 0, n * 2, 0, n}; for (int i = 0; i < k; i++) { int a; cin >> a; while (cnt[4] and a >= 4) a -= 4, cnt[4]--; while (cnt[2] and a >= 2) a -= 2, cnt[2]--; while ((cnt[1] or cnt[2] or cnt[4]) and...
11
#include <bits/stdc++.h> using namespace std; const int MAXN = 1000000; int a[1 + MAXN], b[1 + MAXN]; int v[1 + MAXN]; void Try(int la, int lb, int c) { int i = 1; while (i <= la && i <= lb && a[i] == b[i]) i++; if (i > la) { v[0]++; return; } if (i > lb) { printf("-1\n"); exit(0); } int x...
14
#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 = 2e5 + 123; const long long inf = 1e9 + 123; const long long linf = 1e18 + 123; const long long mod = 1e9 + 7; const double eps = 1e-9; const double pi = acos(-1); int ...
7
#include <bits/stdc++.h> using namespace std; const long long N = 1000000000; vector<int> build(int n) { vector<int> g(n, 1); if (n == 1) { g[0] = 1; } else if (n == 2) { g[0] = 3; g[1] = 4; } else if (n % 2) { g[0] = 2; g[n - 1] = (n + 1) / 2; } else { g[n - 1] = (n - 1) / 2; } re...
16
#include <bits/stdc++.h> using namespace std; int main() { int n, m, t, mod, i; cin >> n >> m; for (i = 1; i <= 500000; i++) { if (n > m) { n -= 2; m -= 1; } else { m -= 2; n -= 1; } if (n < 0 or m < 0) return cout << i - 1, 0; } return 0; }
5
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; int i; if (s.size() > 2) { for (i = 0; i < s.size() - 2; i++) { if (s[i] != '.' && s[i + 1] != '.' && s[i + 2] != '.') { if (s[i] != s[i + 1] && s[i + 1] != s[i + 2] && s[i + 2] != s[i]) { cout << "Yes"; ...
1
#include <bits/stdc++.h> using namespace std; int n, l, r; int main() { cin >> n; cin >> l; r = l; long long ans = 0; for (int i = 1; i <= n; ++i) { int L, R; cin >> L >> R; if (L <= l && r <= R) continue; if (R <= l) { ans += l - R; r = l; l = R; } else if (r < L) { ...
13
#include <bits/stdc++.h> using namespace std; int main() { int num; cin >> num; string str; cin >> str; int n = str.length(); char a = '4', b = '7'; for (int i = 0; i < n; i++) { if (str[i] != a and str[i] != b) { cout << "NO"; return 0; } } int count1 = 0, count2 = 0; for (int i...
0
#include <bits/stdc++.h> using namespace std; int arr[102], arr2[102]; int freq[2000]; int main() { int tests; cin >> tests; string s; cin >> s; for (int i = 0; i < tests; i++) { cin >> arr[i] >> arr2[i]; } vector<int> time; for (int i = 0; i < s.size(); i++) { if (s[i] == '1') { for (int ...
5
#include <bits/stdc++.h> using namespace std; int main() { long long n, i, a, b, arr[6] = {0}; bool flag; cin >> n; for (i = 0; i < n; i++) { cin >> a >> b; arr[a]++; arr[b]++; } flag = false; for (i = 1; i < 6; i++) { if (arr[i] >= 3 || arr[i] <= 1) { flag = true; break; }...
5
#include <bits/stdc++.h> using namespace std; int solve(int watps, int dowps, int tlength) { if (watps <= dowps) return 0; int start = 0; int end = (watps * tlength) / dowps; int res = 0; while (start <= end) { int mid = start + (end - start) / 2; if (watps * tlength == dowps * (tlength + mid)) ...
2
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize("-O3") const long long MAXN = (long long)1e5; long long tab[MAXN]; long long n, k; long long eval(long long x) { return -3 * x * x - 3 * x - 1; } void input() { cin >> n >> k; for (long long i = 0; i < (n); ++i) cin >> tab[i]; } long long ile(long l...
19
#include <bits/stdc++.h> using namespace std; int main() { int a, b, n, m; cin >> a >> b; n = min(a, b); m = max(a, b); if (n == 1) cout << m << endl; else if (n == 2) cout << 2 * (2 * (m / 4) + min(2, m % 4)); else cout << (n * m) - ((n * m) / 2); return 0; }
10
#include <bits/stdc++.h> using namespace std; const int N = 50005; map<int, int> v; int x; int main() { int t; scanf("%d", &t); while (t--) { int n; v.clear(); scanf("%d", &n); int f = 0; for (int i = 1; i <= n; i++) { cin >> x; if (v[x] == 0) { v[x] = i; } else { ...
3
#include <bits/stdc++.h> using namespace std; int i, i0, n, m, a[200005], maxi; map<int, int> dic; int main() { while (scanf("%d", &n) != EOF) { for (i = 0; i < n; i++) scanf("%d", &a[i]); for (i = 0; i < n; i++) dic[a[i]] = dic[a[i] - 1] + 1; maxi = 0; for (i = 0; i < n; i++) if (dic[maxi] <= d...
9
#include <bits/stdc++.h> using namespace std; int main() { int n, m, k; cin >> n >> m >> k; cout << (m * (m - 1)) / 2 << '\n'; for (int i = 1; i < m; ++i) { for (int j = i + 1; j <= m; ++j) { if (k) cout << j << ' ' << i; else cout << i << ' ' << j; cout << '\n'; } } ...
7
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 5; struct node { int dep, diamater, deplca, depa, atolca, btolca; node() {} node(int dep, int diamater, int deplca, int depa, int atolca, int btolca) : dep(dep), diamater(diamater), deplca(deplca), depa(depa), ...
19
#include <bits/stdc++.h> using namespace std; const double eps(1e-12); const double pi(3.14159265358979); const int N = 5050, T = 5050; int n, m, t[N] = {}; double u1[T] = {}, p[N] = {}, u2[T] = {}, ans = 0; void init() { cin >> n >> m; for (int i = 1, x = 0; i <= n; ++i) { cin >> x >> t[i]; p[i] = x / 100....
16
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:32777216") using namespace std; int n, rr, v; double x, y; double bp(double l, double r) { for (int i = 0; i < 100; i++) { double x = (l + r) / 2; if (2 * rr * x + rr * cos(acos(-1.0) / 2 - x) - rr * cos(acos(-1.0) / 2 + x) > y) ...
17
#include <bits/stdc++.h> using namespace std; const int maxn = 3000; int a[maxn]; int main() { int n, k; long long sum = 0; cin >> n >> k; for (int i = 0; i < n; i++) { cin >> a[i]; } sort(a, a + n); for (int i = 0; i < k; i++) { sum += a[i]; } cout << sum; return 0; }
4
#include <bits/stdc++.h> using namespace std; vector<int> graph[3005]; int dist[3005][3005]; int n; priority_queue<pair<int, int>> max1[3005], max2[3005]; vector<pair<int, int>> max11[3005], max12[3005]; bool visit[3005]; void bfs(int t) { memset(visit + 1, 0, n); queue<int> que; visit[t] = true; dist[t][t] = 0...
12
#include <bits/stdc++.h> using namespace std; template <class T> T gcd(T a, T b) { return a ? gcd(b % a, a) : b; } template <class T> T lcm(T a, T b) { return a / gcd(a, b) * b; } const int MAXN = 1e3; int N; int A[MAXN]; int main() { ios_base::sync_with_stdio(0); cin >> N; priority_queue<int> vals; priorit...
9
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; const int MAXN = 2e5 + 10; inline int bin_pow(int base, int exp) { if (!exp) return 1; if (exp & 1) return (unsigned long long)bin_pow(base, exp - 1) * base % MOD; else return bin_pow((unsigned long long)base * base % MOD, exp >> 1); }...
15
#include <bits/stdc++.h> using namespace std; int main() { int n, i, j, z, m; cin >> n; z = 0; m = n; for (i = 1; i <= n; i++) { j = m + (m - 1) * (i - 1); m--; z += j; } cout << z << endl; return 0; }
2
/* #pragma GCC target("avx2") #pragma GCC optimization("O3") #pragma GCC optimization("unroll-loops") ordered_set -> less -> less_equal ordered_set find_by_order(k) -> k element ordered_set order_of_key(k) -> returns the number of elements in a set strictly smaller than k */ #include <bits/stdc++.h> #include <random> /...
7
#include <bits/stdc++.h> using namespace std; const int MAX = 100005; int a[MAX]; unordered_map<int, int> cont; int main() { int n, k; char no[] = "Nothing"; scanf("%d%d", &n, &k); for (int i = 0; i < n; i++) scanf("%d", &a[i]); set<int> maxi; for (int i = 0; i < k; i++) { int &c = cont[a[i]]; if (c...
10
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; cout << (n % 2 ? "contest" : "home") << endl; return 0; }
1
#include <bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:64000000") const double pi = 3.14159265358979323846; const double eps = 1e-6; const long long maxn = 200051; const long long inf = 1000000007; const long long mod = 1000000007; long long m, w; long long bpow(long long x, long long n) { if (...
19
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 10; int head[N], cnt, fa[N]; vector<int> G[N]; void dfs(int u, int f) { fa[u] = min(u, fa[f]); for (auto it : G[u]) if (it != f) dfs(it, u); } int main() { fa[0] = 1e9; int n, q; scanf("%d %d", &n, &q); for (int i = 1; i < n; i++) { i...
17
#include <bits/stdc++.h> using namespace std; char _; const long long N = 1e6 + 5; const long long INF = 1e9; const long long mod = 1e9 + 7; const long long LOGN = 15; int a[N][10]; void solve() { int n, m, k1; cin >> n >> m >> k1; for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) cin >> a[i][j]; mu...
12
#include <bits/stdc++.h> using namespace std; template <typename T> T abs(T a) { return a < 0 ? -a : a; } template <typename T> T sqr(T a) { return a * a; } const int INF = (int)1e9; const long double EPS = 1e-9; const long double PI = 3.1415926535897932384626433832795; const int N = 2000000; int n, m; long long c[...
11
#include <bits/stdc++.h> using namespace std; long long bty[1000001]; int main() { long long n, k; cin >> n >> k; long long sum = 0; for (long long i = 1; i <= n; i++) { cin >> bty[i]; sum += bty[i]; } long long res = 0; for (long long i = 1; i <= k; i++) { long long x; cin >> x; sum -...
6
#include <bits/stdc++.h> using namespace std; constexpr int N = 2e5 + 10; int seg[4 * N], light[N]; bool seg2[4 * N]; pair<int, int> pos[N]; bool mark[N]; vector<int> adj[N], dfs; int n; int dfs_sort(int v) { int sub = 1; pos[v].first = dfs.size(); dfs.push_back(v); mark[v] = true; for (auto i : adj[v]) i...
12
#include <bits/stdc++.h> using namespace std; class abc { public: int n, k; bool check(float); void get(); }; bool abc::check(float f) { if ((k - f) > 0.5) return false; else return true; } void abc::get() { cin >> n; cin >> k; float arr[100]; for (int i = 0; i < n; i++) cin >> arr[i]; floa...
1
#include <bits/stdc++.h> using namespace std; template <class T> inline int size(const T& t) { return t.size(); } int N; int lewy[100001], prawy[100001], ojciec[100001]; int val[100001]; int korzen; pair<int, int> wewn[100001]; int lm[100001], rm[100001]; int lmnr[100001]; int poz[100001]; long long suma[100001]; int...
14
#include <bits/stdc++.h> using namespace std; struct debugger { template <typename T> debugger& operator,(const T& v) { cerr << v << " "; return *this; } } debug; int n; int main() { do { std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } while (0); int n, tmp; int a[10...
6
#include <bits/stdc++.h> const int N = 1e6 + 5; const int mod = 1e9 + 7; const int INF = 0x3f3f3f3f; using namespace std; double a[N]; int b[N]; int n; long long sum1, sum2; int main() { cin >> n; for (int i = 0; i < n; i++) { scanf("%lf", &a[i]); if (a[i] >= 0) sum1 += a[i]; else sum2 += a[...
7
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); string s; cin >> s; int n = s.size(); vector<pair<char, int>> a; for (int i = 0; i < n; i++) { if (i > 0 && a.back().first == s[i]) { a.back().second++; } else { ...
1
#include <bits/stdc++.h> using namespace std; const int oo = 1e9, mxn = 100010; int color[mxn]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); memset(color, -1, sizeof color); int n, m; cin >> n >> m; while (m--) { int A[3]; cin >> A[0] >> A[1] >> A[2]; A[0]--; A[1]--; A[2]--...
6
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; stack<char> st; int cnt = 0; for (int i = 0; i < s.length(); i++) { if (!st.empty() && st.top() == s[i]) { st.pop(); cnt++; } else { st.push(s[i]); } } if (cnt & 1) cout << "Yes" << endl; els...
4
#include <bits/stdc++.h> using namespace std; int a[100100]; bool cmp(const int &a, const int &b) { return a > b; } int main() { int n, n1, n2, i; cin >> n >> n1 >> n2; for (i = 0; i < n; i++) scanf("%d", a + i); sort(a, a + n, cmp); int tp = min(n1, n2); double res = 0; double sum = 0; for (i = 0; i < ...
3
#include <bits/stdc++.h> using namespace std; const double eps = 0.000000001; int vp, vd, t, f; double c; vector<double> s1, s2; bool isEqual(double a, double b) { return abs(a - b) < eps; } bool isLesser(double a, double b) { return (a < b) && (isEqual(a, b) == false); } int main() { cin >> vp >> vd >> t >> f >> c...
7
#include <bits/stdc++.h> int a[] = {0, 0, 1, 1, 1, 2, 1, 1, 14, 8, 4, 2, 41, 13, 21, 1, 22, 4, 19, 19, 4, 2, 1, 16, 13, 4, 35, 19, 4, 2, 41, 4, 87, 41, 115, 2, 59, 31, 49, 8, 28, 4, 31, 44, 50, 13, 151, 16, 91, 56, 14}, n; int main() { scanf("%d", &n); for (int i = ...
19
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 10; const int MOD = 1e9 + 9; long long sup[MAXN]; long long x[MAXN], y[MAXN], del[MAXN]; map<pair<long long, long long>, int> mp; int be_supported(long long x, long long y) { int cnt = 0; for (int j = -1; j < 2; j++) { long long nx = x + j, ny...
13
#include <bits/stdc++.h> using namespace std; int uf[2001]; int find(int a) { if (uf[a] == a) return a; else return uf[a] = find(uf[a]); } void uni(int a, int b) { a = find(a); b = find(b); if (a == b) return; uf[a] = b; } int main(void) { cin.tie(0); ios_base::sync_with_stdio(false); int n; ...
11
#include <bits/stdc++.h> using namespace std; int main() { long double n, m, k, l; cin >> n >> m >> k >> l; long double up = (l + k); long double x = up / m; long long int val = ceil(x); long long int val2 = m * val; if (val2 > n) { puts("-1"); } else { printf("%lld\n", val); } return 0; }
6
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int arr[n + 1]; for (int i = 1; i <= n; i++) { cin >> arr[i]; } int cnt = 0; int final[n + 1]; int k = 0; for (int i = 1; i <= n; i++) { if (arr[i] == 1) { cnt++; final[k++] = arr[i - 1]; } } final[...
0
#include <bits/stdc++.h> using namespace std; int gcd(int x, int y) { if (y) return gcd(y, x % y); else return x; } int c[1000000][26]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); long long n, x, y, i, j, g, l; string a, b; cin >> n >> n >> a >> b; x = a.size(); y = b.size(); g = ...
11
#include <bits/stdc++.h> using namespace std; long long c[200][200], k, dp[200][20], n; int status[20], ans[200]; int tim; long long calc(int len) { memset(dp, 0, sizeof(dp)); for (int i = 0; i <= min(len, status[0]); i++) dp[i][0] = 1; for (int i = 0; i <= len; i++) { for (int j = 1; j < 16; j++) { for...
17
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") using namespace std; inline long long max3(long long a, long long b, long long c) { return (a) > (b) ? ((a) > (c) ? (a) : (c)) : ((b) > (c) ? (b) : (c)); } inline long long min3(long long a, long long b, long long c) { return (a) < (b) ? ((a) < (c) ? (a) : (c))...
4
#include <bits/stdc++.h> using namespace std; const int M = 1e5 + 1; int n, k, cnt, mark[322], mx, m, uncp, unct, l; string s, was; char flag; pair<int, char> pp[M]; int main() { cin >> s >> k; n = (int)s.size(); if (k >= n) { cout << 0 << "\n"; cout << ""; return 0; } for (int i = 0; i < n; i++) ...
4
#include <bits/stdc++.h> long long mpow(long long a, long long n, long long mod) { long long ret = 1; long long b = a; while (n) { if (n & 1) ret = (ret * b) % mod; b = (b * b) % mod; n >>= 1; } return (long long)ret; } inline void read(long long &x) { x = 0; register char c = getchar(); for...
10
#include <bits/stdc++.h> using namespace std; int main() { int start; int end; int sec; int d; cin >> start >> end >> sec >> d; int a = max(start, end); int b = min(start, end); int m = sec - 2; int sum = a + b; for (int i = 1; i <= sec - 2; i++) { a += d; end: if (a - (m * d) > b) { ...
6
#include <bits/stdc++.h> using namespace std; const int MXN = (int)1e5 + 7; const int MOD = (int)1e9 + 7; int n, k; long long num = 1, pref, ans; vector<long long> v; map<long long, int> kek; int main() { cin >> n >> k; if (k == -1) v.push_back(-1); v.push_back(1); if (abs(k) > 1) { while (abs(num) < 1e14) ...
10
#include<bits/stdc++.h> using namespace std; typedef long long int lli; typedef long int li; typedef long long ll; typedef long double ld; typedef vector<lli> vlli; typedef vector<li> vli; typedef vector<int> vi; typedef vector<ld> vld; #define all(x) (x).begin(),(x).end() lli MOD=1e9+7; /*vlli fun(lli q) { vlli r...
0
#include <bits/stdc++.h> using namespace std; int angles[190]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int t; cin >> t; while (t--) { int x; cin >> x; int ans = -1; for (int i = 3; i <= 360; i++) { int g = x * i; if (g % 180 == 0) { g /= 180; if (...
8
#include <bits/stdc++.h> const int maxn = 3e5 + 10; struct segment { int l, r, val; } t[maxn * 4]; long long a[maxn]; int v[maxn]; int n, m; int sign(long long x) { if (x > 0) return 1; if (x < 0) return -1; else return 0; } void cal(int rt, int l, int r) { int mid = (l + r) / 2; t[rt].val = std::ma...
17
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 10; const long long inf = 2e18 + 42; long long a[N], skip[N]; int main() { int n; long long k; cin >> n >> k; for (int i = 1; i <= n; ++i) { cin >> a[i]; } long long ans = 0; for (int i = n; i >= 1; --i) { if (a[i] == 1) { ski...
13
#include <bits/stdc++.h> using namespace std; int main() { bool f = false; int i; string s; while (getline(cin, s)) { bool t = false; for (i = 0; i < s.size(); i++) if (s[i] != ' ') if (s[i] == '#') { t = true; break; } else break; if (t) { i...
9
#include <bits/stdc++.h> using namespace std; const int NMAX = 100010, MOD = 1e9 + 7; int m; int f[NMAX]; vector<int> fact[NMAX]; int prime[NMAX], p_cnt; set<int> pri[NMAX]; int prime_init() { bitset<NMAX> flag; flag.reset(); for (int i = 2; i < NMAX; i++) { if (!flag[i]) { prime[p_cnt++] = i; } ...
15
#include <bits/stdc++.h> using namespace std; template <class T> inline T sqr(T x) { return x * x; } const int inf = ~0u >> 1; const double eps = 1e-8; const double pi = acos(-1.0); int sgn(double x) { return fabs(x) < eps ? 0 : x < -eps ? -1 : 1; } void rotate(long long &x, long long &y, int p) { if (p == 1) { ...
12
#include <bits/stdc++.h> using namespace std; const int MAX = 300003; int n, q, p; vector<int> g[MAX]; int cnt[MAX], centroid[MAX], parent[MAX]; int dfs1(int u) { int c = 1; for (int i = 0; i < g[u].size(); i++) c += dfs1(g[u][i]); cnt[u] = c; return c; } bool iscentroid(int u, int y) { if (cnt[u] % 2 == 0 &&...
11
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const long long LINF = 0x3f3f3f3f3f3f3f3fll; const long double pi = acos(-1); const int MOD = 1e9 + 7; int g[22]; int n, m; int dp[1 << 22]; int MAXI; int solve(int mask) { if (mask == MAXI) return 0; if (dp[mask] != -1) return dp[mask]; in...
16
#include <bits/stdc++.h> int val[262149]; int main() { int n, r; scanf("%d%d", &n, &r); long long sum(0LL); for (int i = 0; i < (1 << n); i++) { scanf("%d", &val[i]); sum += val[i]; } printf("%.10lf\n", (sum * 1.0) / (1 << n)); for (int i = 0; i < r; i++) { int a, b; scanf("%d%d", &a, &b);...
17
#include <bits/stdc++.h> using namespace std; const int MOD = 1000000007; const int MAX = 1005; const int MASK = 130; int ct1[MASK]; int ct2[MASK]; int dig = 0; int dig2 = 0; int f(int n, int mode) { vector<int> v; if (n == 0) { v.push_back(0); } while (n > 0) { v.push_back(n % 7); n /= 7; } int...
9
#include <bits/stdc++.h> using namespace std; int a[100000], b[100000]; int main() { int n, x, w = 0; scanf("%d%d", &n, &x); for (int i = 0; i < n; ++i) scanf("%d", a + i); for (int i = 0; i < n; ++i) scanf("%d", b + i); sort(a, a + n); sort(b, b + n); int l = n - 1, h = 0; while (l != -1 && h != n) { ...
11
#include <bits/stdc++.h> using namespace std; std::vector<long long int> v; long long int arr[300005]; long long int sum = 0; int main() { int n, k; cin >> n >> k; for (int i = 1; i <= n; i++) { cin >> arr[i]; if (i == 1) continue; long long int dif = arr[i] - arr[i - 1]; v.push_back(dif); sum...
6
#include <bits/stdc++.h> using namespace std; int read() { int 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; } const double eps = 1e-9; const int maxn...
3
#include <bits/stdc++.h> using namespace std; template <typename T> inline T gcd(T a, T b) { if (b) return gcd(b, a % b); return a; } template <typename T> inline T ext_gcd(T a, T b, T& x, T& y) { if (a == 0) { x = 0; y = 1; return b; } T x1, y1; T g = ext_gcd(b % a, a, x1, y1); x = y1 - (b / ...
10
#include <bits/stdc++.h> using namespace std; using ll = long long; using Vi = vector<int>; using Pii = pair<int, int>; int uplg(int n) { return 32 - __builtin_clz(n); } int uplg(ll n) { return 64 - __builtin_clzll(n); } void run(); int main() { cin.sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(18...
7
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") using namespace std; const int maxn = 2e5; const int INF = 1e9; const long long MOD = 998244353; const int base = 31; const int UP = 1e8; long long n, m; long long dp[maxn + 5]; struct EuclidReturn { long long u, v, d; EuclidReturn(long long _u, long long _v, l...
9
#include <bits/stdc++.h> using namespace std; constexpr int maxn = 100005; int n, b[maxn], mapping[maxn]; int C[maxn]; int lowbit(int x) { return x & (-x); } void update(int i, int k) { while (i <= n) { C[i] += k; i += lowbit(i); } } int getsum(int i) { int res = 0; while (i > 0) { res += C[i]; ...
5
#include <bits/stdc++.h> using namespace std; const int inf = 1000000000; struct edge { int t, next; } g[410001]; long long ans; int i, j, k, n, c1, c2, h[210001], tot, dep[210001], md, f[210001][2], d2; void addedge(int x, int y) { g[++tot].t = y; g[tot].next = h[x]; h[x] = tot; g[++tot].t = x; g[tot].next...
14
#include <bits/stdc++.h> using namespace std; int n; int main() { cin >> n; if (n == 3) { cout << 1; return 0; } if (n == 1) { cout << 2; return 0; } if (n == 4) { cout << 2; return 0; } if (n == 2) { cout << 3; return 0; } if (n == 5) { cout << 1; return 0; ...
5
#include <bits/stdc++.h> using namespace std; using LL = long long; const int MAXN(5e5 + 100); struct Node { int left, right, val, lazy; } tree[MAXN << 2]; int n, nx[MAXN], in[MAXN], ans[MAXN]; vector<int> G[MAXN]; inline int read() { int f = 1, x = 0; char ch; do { ch = getchar(); if (ch == '-') f = -1...
13
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 10; int a[N], af[N], ab[N]; vector<int> seg[4 * N]; void build(int l, int r, int node) { if (l == r) { seg[node].push_back(ab[l]); return; } int mid = (l + r) / 2; build(l, mid, 2 * node); build(mid + 1, r, 2 * node + 1); merge(seg[2 ...
10
#include <bits/stdc++.h> using namespace std; string s[10]; bool a[10][10][10]; int n; int main() { n = 8; for (int i = 0; i < n; i++) { getline(cin, s[i]); } memset(a, false, sizeof(a)); a[n - 1][0][0] = true; for (int t = 1; t <= n; t++) { for (int i = 0; i < n; i++) { for (int j = 0; j < n;...
7
#include <bits/stdc++.h> using namespace std; int treeArr[1048576]; int result[524288]; int resLoc[524288]; struct QueryNode { int loc; int id; bool operator<(const QueryNode other) const { return loc < other.loc; } void read(int v_id) { scanf("%d", &loc); id = v_id; } } queryNodes[524288]; int qlen; ...
14
#include <bits/stdc++.h> using namespace std; long long n; int main() { scanf("%I64d", &n); long long i = 1, Rec = 0; while (Rec + i < n) { Rec = Rec + i; i++; } printf("%I64d\n", n - Rec); return 0; }
2
#include <bits/stdc++.h> int N; long long T[200002]; int segL[200002], segR[200002], G; int f[200002], g[200002], from[200002][2]; int S_not_given[200002]; long long min_select(long long L1, long long R1, long long L2, long long R2, long long need) { L1 = N - L1 + 1; L2 = N - L2 + 1; R1 = N -...
27
#include <bits/stdc++.h> using namespace std; #define ll long long #define value(x) cout<<#x<<" "<<x<<endl; void solve(){ int w,h,n; cin>>w>>h>>n; int cnt = 1; while(!(w&1) || !(h&1)){ if(w % 2 == 0){ cnt *= 2; w = w / 2; } if(h % 2 == 0){ cn...
0
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10; string S[maxn]; map<long long, int> Map; long long f(string A) { long long res = 0; for (int i = 0; i < A.size(); i++) { res ^= 1 << (A[i] - 'a'); } return res; } int main() { std::ios::sync_with_stdio(0); int n; cin >> n; Map....
8
#include <bits/stdc++.h> using namespace std; const int MX = 50005; const int INF = 1111111111; int C[MX], Cn; vector<int> conV[MX]; struct Edge { int id; int u, v, c, t; void in() { scanf("%d%d%d%d", &u, &v, &c, &t); u--, v--; conV[u].push_back(id); conV[v].push_back(id); C[Cn++] = c; } } e...
23
#include <bits/stdc++.h> using namespace std; vector<vector<int> > g, r; int n; vector<int> color, st, scc; int nSCC; void dfs(int v, int flag) { color[v] = 1; for (int u : (flag ? g[v] : r[v])) if (!color[u]) dfs(u, flag); if (flag) st.push_back(v); else scc[v] = nSCC; } void traverse() { color =...
11
#include <bits/stdc++.h> using namespace std; long long int mod = 1000000007; long long int v[100004]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; long long int t = 1; while (t--) { long long int n; cin >> n; string s, t; cin >> s >> t; long long int ct00 = 0, c...
7
#include <bits/stdc++.h> using namespace std; int n, m, h[500005], tot, v[500005]; struct edge { int to, nxt; } e[500005 << 2]; void add(int x, int y) { e[++tot].nxt = h[x]; h[x] = tot; e[tot].to = y; } vector<int> c[500005]; bool dfs(int x, int fa, int d) { c[d].push_back(x); v[x] = 1; if (d * 2 >= n) { ...
18
#include <bits/stdc++.h> using namespace std; struct node { int curr, prev, i; }; node a[7005], b[7005]; int p[20][7005], mul, f[7005]; int v[7005]; int lcp(int x, int y, int lvl, int n) { int i, ans = 0; for (i = lvl; i >= 0 && x < n && y < n; i--) if (p[i][x] == p[i][y]) { ans += (1 << i); x += ...
12
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> a(n + 1); int u, v; for (int i = 0; i < n - 1; i++) { cin >> u >> v; a[u]++; a[v]++; } bool check = false; for (int i = 1; i <= n; i++) if (a[i] == 2) check = true; if (check) cout << "NO"; el...
8
#include <bits/stdc++.h> using namespace std; int main() { int a, b, x, y; cin >> a >> b >> x >> y; x = abs(a - x); y = abs(b - y); (x > y) ? cout << x << endl : cout << y << endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; inline char gc() { return getchar(); static char buf[100000], *l = buf, *r = buf; return l == r && (r = (l = buf) + fread(buf, 1, 100000, stdin), l == r) ? EOF : *l++; } template <class T> void rd(T &x) { x = 0; int f = 1, ch = gc(); wh...
23
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; long long p = 0; long long a[n]; pair<long long, long long> k[5]; for (long long i = 0; i < n; i++) { cin >> a[i]; } for (long long i = 0; i < 5; i++) { cin >> k[i].first; k[i].second = i; } sort(k, k + 5);...
4
#include <bits/stdc++.h> using namespace std; const int N = 1e3 + 10, T = 3; int n, m; char grid[N][N]; int sx = -1, sy = -1; int tx = -1, ty = -1; bool solve() { int lsy, rsy; for (int j = sy; j < m; j++) { if (grid[sx][j] == 'T') return true; if (grid[sx][j] == '*') break; rsy = j; } for (int j = ...
8
#include <bits/stdc++.h> const int N = 1e6 + 5, M = 1e3 + 5; int n, k, a[N], dis[M << 1]; int bfs() { std::queue<int> q; for (int i = 1; i <= n; ++i) dis[a[i] + M] = 1, q.push(a[i] + M); while (!q.empty()) { int u = q.front(); q.pop(); for (int i = 1; i <= n; ++i) { int v = u + a[i]; if (v...
15
#include <bits/stdc++.h> using namespace std; int main() { string s1, s2; getline(cin, s1); getline(cin, s2); string answer(s1.size(), '0'); int diff = 0, like = 0; int a1 = 0, a2 = 0; for (int i = 0; i < s1.size(); ++i) { if (s1[i] != s2[i]) { diff++; if (a1 < a2) { a1++; ...
3
#include<bits/stdc++.h> using namespace std; #define Going_supersonic ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define pb push_back #define all(a) a.begin(),a.end() #define allr(v) v.rbegin(),v.rend() #define sz() size() #define l() length() #define ll long long int #define Ed endl #define ed endl #define i...
0
#include <bits/stdc++.h> using namespace std; int main(int argc, char const *argv[]) { int n, m; cin >> n >> m; vector<int> a(n), b(n); set<int> s; for (int i = 0; i < n; ++i) cin >> a[i]; for (int i = 0; i < n; ++i) cin >> b[i]; sort((b).begin(), (b).end()); sort((a).begin(), (a).end()); int val, tem...
7