solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> using namespace std; struct Solution { int N, W; vector<int> A, B; int Find(const vector<int> s, const vector<int>& s1) { if (s1.empty()) return s.size() + 1; vector<int> next(s1.size() + 1); next[0] = -1; int k = -1; for (int i = 0; i < s1.size(); ++i) { while (...
10
#include <bits/stdc++.h> using namespace std; const int MAX = 8; char a[MAX][MAX]; int main() { ios_base::sync_with_stdio(false); int posA, posB; bool check = 0; char c; for (long long i = 0; i < 8; i++) { for (long long j = 0; j < 8; j++) { cin >> a[i][j]; } } for (long long i = 0; i < 8; i...
4
#include <bits/stdc++.h> using namespace std; inline long long read() { char ch = getchar(); long long p = 1, data = 0; while (ch < '0' || ch > '9') { if (ch == '-') p = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { data = data * 10 + (ch ^ 48); ch = getchar(); } return p * data; ...
5
#include <bits/stdc++.h> using namespace std; const long long int mod = 1e9 + 7; const long long int inf = 2e9 + 5; double PI = 3.14159265358979323846; void solve() { long long int n; cin >> n; vector<long long int> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } long long int ans = 0; for (int i =...
6
#include <bits/stdc++.h> using namespace std; const int N = 100000; struct person { int id, s, f, effect; long long t; bool operator<(const person &p) const { return t > p.t; } }; set<int> waiting; queue<person> flr[N + 1]; long long ans[N]; long long curT; int curF = 1, curP; int main() { waiting.insert(-10000...
14
#include <bits/stdc++.h> using namespace std; string t[100]; int n, p; int main() { cin >> n; for (int i = 0; i < n; i++) { cin >> t[i]; } for (int i = 0; i < n; i++) { p = t[i].length(); if (t[i].substr(p - 2, p) == "po") { cout << "FILIPINO" << endl; } else if (t[i].substr(p - 4, p) == "...
0
#include <bits/stdc++.h> using namespace std; bool prime[100005] = {false}; void sieve() { prime[0] = true; prime[1] = true; for (long long i = 2; i < 100005; i++) { if (prime[i] == false) { for (long long j = i * i; j < 100005; j += i) prime[j] = true; } } } void solve() { long long n, j, a, cn...
5
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int i = 0; vector<int> x(n); int z = 1; while (i < n) { cin >> x[i]; i++; } sort(x.begin(), x.end()); i = 0; while (i < n) { if (x[i] >= z) z++; i++; } cout << z; return 0; }
4
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int arr[100000]; int freq[8]; for (int i = 0; i <= 7; i++) freq[i] = 0; bool failed = 0; for (int i = 0; i < n; i++) { cin >> arr[i]; if (arr[i] == 5 || arr[i] == 7) { failed = 1; break; } freq[arr[i]]+...
4
#include <bits/stdc++.h> int main() { char s[1010]; int num[256], f[1010]; int len, i, j, k, t; gets(s); len = strlen(s); memset(num, 0, sizeof(num)); for (i = 0; i < len; i++) num[s[i]]++; k = 0; for (i = 1; i < 256; i++) if (num[k] < num[i]) k = i; memset(f, 1, sizeof(f)); for (i = 2; i + i ...
5
#include <bits/stdc++.h> using namespace std; long long a[100000]; int main() { long long y, k, n, i = 0, h = 0; cin >> y >> k >> n; while (i < n) { i += k; if (i <= n && i > y) { a[h] = i - y; h++; } } if (h == 0) { a[h] = -1; h++; } for (int x = 0; x < h; x++) printf("%ld...
4
#include <bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; typedef unsigned long long ull; typedef long long ll; bool isUpperCase(char c) { return c >= 'A' && c <= 'Z'; } bool isLowerCase(char c) { return c >= 'a' && c <= 'z'; } bool isVowel(char c) { return (c == 'a' || c == 'e' || c == 'i' || c == 'o'...
2
#include <bits/stdc++.h> using namespace std; void amax(int& x, int y) { if (x < y) x = y; } void amin(int& x, int y) { if (x > y) x = y; } int gcd(int a, int b) { if (b) { return gcd(b, a % b); } return a; } struct custom_hash { static uint64_t splitmix64(uint64_t x) { x += 0x9e3779b97f4a7c15; ...
4
#include <bits/stdc++.h> using namespace std; void solve(){ long long A,S,N; cin>>A>>S>>N; long long p[N]; long long h[N]; vector<pair<long long,long long>>M; for(int i=0;i<N;i++){ cin>>p[i]; } for(int i=0;i<N;i++){ cin>>h[i]; } for(int i=0;i<N;i++){ M.push_back(make_pair(p[i],h[i])); ...
1
#include <bits/stdc++.h> using namespace std; long long arr[26]; string s; const long long N = 100000; vector<long long> v1[N]; long long sum[N]; int main() { for (long long i = 0; i < 26; i++) cin >> arr[i]; cin >> s; long long n = s.size(); sum[0] = arr[s[0] - 'a']; for (long long i = 1; i < n; i++) { s...
10
#include <bits/stdc++.h> using namespace std; #define ll long long int int main() { ll t,n,i,a,b,c,x,y,k; cin>>t; while(t--) { cin>>a>>b>>c; if(c==min(a,b)) { x=pow(10,a-1); y=pow(10,b-1); } else { x=pow(10,a-1); ...
3
#include <bits/stdc++.h> using namespace std; vector<pair<int, int>> v; vector<string> v3, v1; map<int, int> m2, m; int n, i, j, cnt = 0, sum[100000], a, b; string s, s1; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); ; cin >> n; for (i = 0; i < n; i++) { cin >> a >> b; v.pu...
4
#include <bits/stdc++.h> using namespace std; int main(int argc, char *argv[]) { int m, n; cin >> n >> m; vector<int> playlist(n, 0); vector<int> count(m + 1, 0); for (int i = 0; i < n; ++i) { cin >> playlist[i]; if (playlist[i] <= m) ++count[playlist[i]]; } int v = n / m; int res = 0; for (in...
8
#include <bits/stdc++.h> using namespace std; const int N = 100005; const int BLOCK = 316; struct node { long long down, val, up; } v[N]; long long temp[N]; vector<long long> sorted; int ap[3 * N]; struct query { int l, r, i; } Q[N]; bool comp(query a, query b) { if (a.l / BLOCK == b.l / BLOCK) { return a.r <...
15
#include <bits/stdc++.h> using namespace std; long long n, a[200005], t; int main() { cin >> t; for (int w = 1; w <= t; w++) { cin >> n; cout << n << endl; } return 0; }
1
#include <bits/stdc++.h> #pragma warning(disable : 4996) template <typename T> T min(T x, T y) { return x < y ? x : y; } template <typename T> T max(T x, T y) { return x > y ? x : y; }; const int MAXN = 100005; struct tree1 { private: int mx; int l; int r; tree1 *lson; tree1 *rson; public: tree1() { ...
21
#include <bits/stdc++.h> using namespace std; long long n, m, K; long long a[105], f[105][105]; long long dfs(long long len, long long cnt, bool limit) { if (len == 0) return cnt == K; if (!limit && f[len][cnt] != -1) return f[len][cnt]; long long mx = limit ? a[len] : 1; long long res = 0; for (long long i =...
13
#include <bits/stdc++.h> using namespace std; const long long inf = 1e8; string s; vector<int> d; bool cmp(int a, int b) { return a > b; } int main() { ios::sync_with_stdio(false); cin.tie(0); long long kase; cin >> kase; for (register long long kas = (1); kas <= (kase); ++kas) { cin >> s; int now = 0...
0
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const long long LINF = 0x3f3f3f3f3f3f3f3fll; template <typename T, bool MULTI = false, typename SIZE_T = int> struct sms_mo { static_assert(std::is_integral<T>::value, "Not an integral type"); static_assert(std::is_integral<SIZE_T>::value, "N...
9
#include <bits/stdc++.h> using namespace std; long t, n, m, x, y, b; long f[1000001], a[1000001]; bool check(long x, long y, long n, long m) { if (x > n || y > m) return 0; memset(f, 0, sizeof(f)); for (long i = 1; i <= n; i++) for (long j = 1; j <= m; j++) { f[abs(i - x) + abs(j - y)]++; } for (l...
15
#include <bits/stdc++.h> using namespace std; int n, ma; vector<int> v, liste, use, cycle, image; int gist[205]; vector<long long> vnok; long long gcd(long long a, long long b) { return (b > 0 ? gcd(b, a % b) : a); } long long lcm(long long a, long long b) { return (a / gcd(a, b) * b); } int main() { ios_base::sync_w...
12
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int a, b, c, d, k, x, y; cin >> a >> b >> c >> d >> k; if (a % c == 0) x = a / c; else x = (a / c) + 1; if (b % d == 0) y = b / d; else y = (b / d) + 1; if (x + y <= k) ...
0
#include <bits/stdc++.h> #pragma GCC target( \ "sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native") #pragma GCC optimize("unroll-loops") #pragma GCC optimize("fast-math") #pragma comment(linker, "/STACK:167077260") using namespace std; const long double EPS = 0; const long double EPS2 = 1e-12; const long...
16
#include <bits/stdc++.h> using namespace std; int cnt, n, m, a[5000005], ans, En, head[5000005], vis[5000005]; struct Edge { int next, to; } E[5000005]; void add(int from, int to) { En++; E[En].next = head[from]; E[En].to = to; head[from] = En; } void dfs(int k) { vis[k] = 1; for (int i = head[k]; i; i = ...
17
#include <bits/stdc++.h> const double pi = 4.0 * atan(1.0); const double e = exp(1.0); const int maxn = 3e6 + 8; const long long mod = 1e9 + 7; const unsigned long long base = 1e7 + 7; using namespace std; bool vis[maxn]; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; cin >> n; in...
0
#include <bits/stdc++.h> using namespace std; int main() { int i, n, stairways = 1, z; vector<int> max_stairs, x; cin >> n; for (i = 0; i < n; i++) { cin >> z; x.push_back(z); if (x[i] == 1 && i != 0) { stairways++; max_stairs.push_back(x[i - 1]); } } max_stairs.push_back(x.back(...
0
#include <bits/stdc++.h> using namespace std; int P[1001]; vector<int> p; int n, u, z; int main() { cin >> n; for (int i = 2; i <= n; ++i) { if (P[i] == 0) { P[i] = i; p.push_back(i); } for (int j = 0; j < (int)p.size() && p[j] <= P[i] && i * p[j] <= n; ++j) P[i * p[j]] = p[j]; } f...
7
#include <bits/stdc++.h> using namespace std; bool comp_by_y( pair<pair<long long, long long>, pair<long long, long long>>& lhs, pair<pair<long long, long long>, pair<long long, long long>>& rhs) { return lhs.second < rhs.second; } bool process( vector<pair<pair<long long, long long>, pair<long long, long...
17
#include <bits/stdc++.h> using namespace std; int n; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> n; if (n <= 10) { for (int i = 0; i < (signed)(n); i++) { cout << i << " " << i << "\n"; } return 0; } int v = (n + 5) / 3; cout << "0 0\n"; int x = 1; for (int i = ...
18
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; bool neg = s[0] == '-'; if (neg) s = s.substr(1); int p; string d; if ((p = s.find('.')) != -1) { d = s.substr(p + 1); s = s.substr(0, p); } if (((int)(d).size()) < 2) d += "000"; if (neg) cout << '('; cout << '...
4
#include <bits/stdc++.h> using namespace std; template <typename T> bool chkmx(T &x, T y) { return x < y ? x = y, true : false; } template <typename T> bool chkmn(T &x, T y) { return x > y ? x = y, true : false; } template <int T> using A = array<int, T>; const int maxn = 2e5; const int maxlg = 17; int n, m, a[maxn...
25
#include <bits/stdc++.h> using namespace std; unsigned long long C[64][64]; int main() { C[0][0] = 1; for (int i = 1; i < 64; i++) { C[i][0] = C[i][i] = 1; for (int j = 1; j < i; j++) C[i][j] = C[i - 1][j - 1] + C[i - 1][j]; } int n, m, t; while (cin >> n >> m >> t) { unsigned long long x = 0; ...
6
#include <bits/stdc++.h> using namespace std; char str[1000005]; char s[1000005]; vector<int> a[26]; int main() { int i, j, n, m, ans, k, t; char ch; scanf("%s%s", str, s); n = strlen(str); for (i = 0; i < n; i++) { a[str[i] - 'a'].push_back(i); } n = strlen(s); t = -1; k = 1; for (i = 0; i < n;...
7
#include <bits/stdc++.h> using namespace std; int n, cnt[30], ans; string s; int main() { cin >> n; for (int i = 0; i < n; i++) { cin >> s; cnt[s[0] - 'a']++; } for (int i = 0; i <= 'z' - 'a'; i++) { int a = cnt[i] / 2; int b = cnt[i] - a; ans += (a * (a - 1)); ans += (b * (b - 1)); } ...
1
#include <bits/stdc++.h> int main() { int test; std::cin >> test; while (test--) { int n; std::cin >> n; if (n % 4 == 0 && n >= 4) { std::cout << "YES\n"; } else { std::cout << "NO\n"; } } return 0; }
0
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; map<pair<long long, long long>, long long> dp; long long n, k, a, b; vector<long long> vec; long long solve(long long l, long long r) { if (dp.count({l, r})) return dp[{l, r}]; long long it1 = lower_bound(vec.begin(), vec.end(), l) - vec.b...
9
#include <bits/stdc++.h> using namespace std; int n, m, k; map<int, int> mpX, _mpX, mpY, _mpY; vector<pair<int, int> > lineX[100010], lineY[100010]; int a = 0, b = 0; int getLeft(vector<pair<int, int> > vec, int n) { int ed = 0; for (int i = 0; i < vec.size(); i++) if (vec[i].second > ed) { n -= (vec[i].s...
16
#include <bits/stdc++.h> using namespace std; const int dx[4] = {-1, 0, 1, 0}; const int dy[4] = {0, 1, 0, -1}; const int dxo[8] = {-1, -1, -1, 0, 1, 1, 1, 0}; const int dyo[8] = {-1, 0, 1, 1, 1, 0, -1, -1}; inline bool is_down(char x) { return ('a' <= x && x <= 'z'); } inline bool is_upper(char x) { return ('A' <= x &...
9
#include <bits/stdc++.h> using namespace std; long long get_parent(vector<int> &parent, int a) { if (parent[a] == a) return a; else { parent[a] = get_parent(parent, parent[a]); return parent[a]; } } void union_set(vector<int> &parent, int a, int b) { a = get_parent(parent, a); b = get_parent(paren...
7
#include <bits/stdc++.h> using namespace std; long long bit[200005]; void add(long long idx, long long val) { for (int i = idx; i < 200005; i += (i & (-i))) { bit[i] += val; } } long long query(long long i) { long long ans = 0; for (; i > 0; i -= (i & (-i))) ans += bit[i]; return ans; } long long b[200005...
11
#include <bits/stdc++.h> using namespace std; int n, i, j, k, a[50050], c, ansMin, ansMax; int main() { char s[50050]; scanf("%d%d", &n, &k); for (i = 0; i < n; i++) { scanf("%s", s); a[strlen(s)]++; } scanf("%s", s); for (i = 1; i < strlen(s); i++) { c += a[i]; } ansMin = ((5 * (c / k)) + c...
3
#include <bits/stdc++.h> using namespace std; namespace acm { char ch[200][200]; int r, c; int dp[200][200]; void update(int &a, int b) { a = min(a, b); } void solve() { memset((dp), (0x3f), sizeof(dp)); dp[0][0] = 0; pair<int, int> pos = make_pair(0, 0); for (int i = 0; i < (int)(r); ++i) { if (i & 1) { ...
7
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; long long read() { long long a = 0; bool opt = 0; char c = getchar(); while (c < '0' || c > '9') opt |= c == '-', c = getchar(); while (c >= '0' && c <= '9') a = (a << 3) + (a << 1) + (c ^ 48), c = getchar(); return opt ? -a : a; } i...
24
#include <bits/stdc++.h> using namespace std; string a, b; int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin >> a >> b; int c7 = 0, c4 = 0; for (int i = 0; i < a.length(); i++) { if (a[i] == '7' && b[i] == '4') c7++; else if (a[i] == '4' && b[i] == '7') c4++; ...
4
#include <bits/stdc++.h> using namespace std; int n, k, ans; map<int, int> m; int main() { scanf("%d%d", &n, &k); k = (n + 1) / 2; for (int i = 0; i < n; i++) { int tmp; scanf("%d", &tmp); m[tmp]++; } for (auto& i : m) { int tmp = i.second / 2; ans += tmp; k -= tmp; } ans = ans * 2...
2
#include <bits/stdc++.h> using namespace std; const long double PI = acosl(-1); mt19937_64 rng( (unsigned)chrono::system_clock::now().time_since_epoch().count()); const int nmax = 1e6 + 5; int perm[nmax]; long long int tree[4 * nmax]; long long int lazy[4 * nmax]; void build(int id, int l, int r) { lazy[id] = 0; ...
17
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); double R, x_1, x_2, y_1, y_2, x_3, y_3; scanf("%lf%lf%lf%lf%lf", &R, &x_1, &y_1, &x_2, &y_2); double d = sqrt((x_2 - x_1) * (x_2 - x_1) + (y_2 - y_1) * (y_2 - y_1)); if (d >= R) { printf("%.16lf %.16...
8
#include <bits/stdc++.h> using namespace std; const long long int inf = 1e9 + 7; const double pie = 3.14159265358979323846; const char nl = '\n'; const char spc = ' '; template <typename Type> istream &operator>>(istream &in, vector<Type> &v) { long long int n = v.size(); for (int i = 0; i < n; i++) in >> v[i]; r...
5
#include <bits/stdc++.h> inline int read() { char c = getchar(); int x = 0; while (c < '0' || c > '9') c = getchar(); while (c >= '0' && c <= '9') x = (x << 3) + (x << 1) + c - 48, c = getchar(); return x; } const int mod = 1e9 + 7; const int maxn = 1e5 + 5; struct E { int v, nxt; } e[maxn << 1]; struct Ask...
19
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; int count = 0; for (int i = 0; i < s.size() / 2; i++) { if (s[i] != s[s.size() - i - 1]) count++; } if (s.size() % 2 == 0) { if (count != 1) cout << "NO"; else cout << "YES"; } else { if (count > 1) ...
2
#include <bits/stdc++.h> using namespace std; int isprime(long long int n) { if (n == 1) { return (0); } if (n == 2) { return (1); } for (long long int i = 2; i * i <= n; ++i) { if (n % i == 0) { return (0); } } return (1); } int main() { ios_base::sync_with_stdio(false); cin.tie...
3
#include <bits/stdc++.h> using namespace std; vector<pair<int, int> > v[200005]; vector<int> mi[200005]; struct compare { bool operator()(const pair<int, int>& l, const pair<int, int>& r) { return l.first < r.first; } }; int main() { int t, k, i, j, n, m, x, y, q, c; int l, r; cin >> n >> x; for (i = 0;...
8
#include <bits/stdc++.h> long long mod = 1000000007; using namespace std; struct DynamicSegTreeNode { int low, high, value; DynamicSegTreeNode *left, *right; DynamicSegTreeNode(int lo, int hi) { low = lo, high = hi; left = right = NULL; value = 0; } DynamicSegTreeNode() {} void Upd(int idx, int ...
13
#include <bits/stdc++.h> using namespace std; const int MAX_NB_TOURS = 100 * 1000 + 1; int nbTours, nbTypes; double expect[2][700]; double cumul[700]; int main() { cin >> nbTours >> nbTypes; for (int iTour = nbTours; iTour > 0; iTour--) { int c = iTour % 2; int n = 1 - c; for (int iPos = 1; iPos < 600; ...
19
#include <bits/stdc++.h> using namespace std; long long read() { long long x = 0, f = 1; char ch = ' '; while (!isdigit(ch)) { ch = getchar(); if (ch == '-') f = -1; } while (isdigit(ch)) x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar(); return x * f; } int n, a[400005], b[400005], cnt[400005], a...
15
#include <bits/stdc++.h> using namespace std; int main() { int h, m, n, ans = 0; scanf("%d%d%d", &h, &m, &n); vector<int> v(h, -1); char ch; int id, hash; unordered_map<int, int> um; for (int i = 0; i < n; ++i) { scanf(" %c %d", &ch, &id); if (ch == '+') { scanf("%d", &hash); while (v[...
8
#include <bits/stdc++.h> using namespace std; inline int read() { int x = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); } return x * f; } bitset<2010> a[2010], b...
20
#include <bits/stdc++.h> using namespace std; bool cmp(int a, int b) { return a > b; } int m[200], n; int mx[200]; bool isok(int r) { for (int i = 0; i < r; ++i) mx[i] = m[i]; int j = 0; for (int i = r; i < n; ++i) { if (mx[j]) { --mx[j]; mx[j] = min(mx[j], m[i]); ++j; if (j == r) j = ...
6
#include <bits/stdc++.h> using namespace std; int main() { int m; scanf("%d", &m); int num, x, sum = 0; for (int i = 1; i <= 100000; i++) { num = 1; x = i; while (1) { if (x % 5 == 0) { num++; x = x / 5; } else break; } sum += num; if (sum == m) { ...
5
#include <bits/stdc++.h> using namespace std; long long int drz[2 * 131072 + 5]; void aktu(int a, int war) { a += 131072; drz[a] = war; a /= 2; while (a) { drz[a] = (drz[2 * a] * drz[2 * a + 1]) % 777777777; a /= 2; } } set<int>::iterator it; long long int pop[77788]; long long int nast[77788]; long l...
16
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; vector<long double> v(n); for (long long i = 0; i < n; i++) cin >> v[i]; sort(v.begin(), v.end()); bool f = 0; long double ans = 0; for (long long i = n - 1; i >= 0; i--) { if (f == 0) { ans = ans + v[i] * v[i]; ...
2
#include <bits/stdc++.h> using namespace std; template <class T1> void deb(T1 e1) { cout << e1 << endl; } template <class T1, class T2> void deb(T1 e1, T2 e2) { cout << e1 << " " << e2 << endl; } template <class T1, class T2, class T3> void deb(T1 e1, T2 e2, T3 e3) { cout << e1 << " " << e2 << " " << e3 << endl; ...
15
#include <bits/stdc++.h> using namespace std; long long read() { fflush(stdout); long long x; scanf("%lld", &x); return x; } long long ans, TT, mp[50005]; void work(long long x, long long n) { for (long long i = 2; i <= n; i++) { if (mp[i]) continue; long long anss = 0; if (x % i == 0) { lon...
18
#include <bits/stdc++.h> using namespace std; struct mystruct { long long v; mystruct *next; }; int structcmp(const void *v1, const void *v2) { return ((mystruct *)v1)->v - ((mystruct *)v2)->v; } int intcmp(const void *v1, const void *v2) { return *(int *)v1 - *(int *)v2; } long long minn(long long v1, long long ...
15
#include <bits/stdc++.h> using namespace std; vector<int> G[200004]; int n, k, x, y, i, A[200004]; long long s; bool F[200004]; void DFS(int x, int f) { A[x] = F[x]; int i, y; for (i = 0; i < G[x].size(); i++) { y = G[x][i]; if (y == f) continue; DFS(y, x); A[x] += A[y]; } s += min(A[x], k - A...
10
#include <bits/stdc++.h> using namespace std; const int MAXN = 100 * 1000; int n; int t[MAXN]; int main() { ios_base::sync_with_stdio(0); cin >> n; int maxl = -1; int sum = 0; for (int a = 0; a < n; ++a) { cin >> t[a]; maxl = max(maxl, t[a]); sum += t[a]; } if (sum - maxl >= maxl) cout << ...
3
#include <bits/stdc++.h> using namespace std; int i, j, x, n, m, QtieRu4, iConst = 100; char s[128]; int hp[256][2][2]; bool f[128][64][256][2]; int getMin(int x, int y) { if (x < y) return x; else return y; } int main() { gets(s); scanf("%d", &n); m = strlen(s); memset(f, false, sizeof(f)); for (...
10
#include <bits/stdc++.h> using namespace std; int main() { int n; while (scanf("%d", &n) == 1) { if ((n / 2) & 1) printf("-1\n"); else { if (n & 1) { int t = n; for (int i = 1; i <= n; i++) { if (i == n / 2 + 1) { printf("%d", i); t -= 2; ...
6
#include <bits/stdc++.h> using namespace std; const int N = 3000 + 20, mod = 998244353; int n, m, dp[2][N], ans; string s, t; int sum(int a, int b) { return ((1LL * a + b) % mod + mod) % mod; } int mul(int a, int b) { return ((1LL * a * b) % mod + mod) % mod; } int main() { ios_base::sync_with_stdio(false), cin.tie(0...
14
#include <bits/stdc++.h> using namespace std; map<int, bool> vis; long long a[100000][32] = {0}, b[100000][32], c = 0, d, i, j, n, m[100000], k, a1; int main() { cin >> n; for (i = 0; i < n; i++) { cin >> m[i]; a1 = m[i]; j = 0; while (a1 > 0) { a[i][j++] = a1 % 2; a1 = a1 / 2;...
8
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; const long long inf = LLONG_MAX - 100000; long long pw(long long x, long long y, long long p = inf) { long long res = 1; x = x % p; if (x == 0) return 0; while (y > 0) { if (y & 1) res = (res * x) % p; y = y >> 1; x = (x...
7
#include <bits/stdc++.h> using namespace std; int n, m; const int maxN = 50, maxM = maxN; string grid[maxN]; bool visited[maxN][maxM]; bool visited2[maxN][maxM]; bool isValid(int x, int y) { if (x >= 0 && x < n && y >= 0 && y < m) return true; return false; } void dfs(int x, int y, char ch, int px, int py) { visi...
7
#include <bits/stdc++.h> using namespace std; using ull = unsigned long long; using ll = long long; using ld = long double; const int mod = 1e9 + 7; const double pi = acos(-1.0); const int inf = INT_MAX; const int N = 3e5 + 5; namespace modular { template <typename> struct is_modular : std::false_type {}; template <typ...
20
#include <bits/stdc++.h> using namespace std; int32_t main() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); long long n, extra = 0; map<long double, long long> mp; cin >> n; vector<long double> a(n), b(n); for (long long i = 0; i < n; i++) cin >> a[i]; for (long long i = 0; i < n; i++)...
7
#include<iostream> #define ll long long int using namespace std; int main(){ int t; cin>>t; while(t--){ ll a,b,d; cin>>a>>b>>d; if(max(a,b)-min(a,b)<=d){ cout<<"YES"; }else{ if((max(a,b)/(d+1))<min(a,b) || (max(a,b)/(d+1))<=min(a,b) && (max(a,b)%(d+1))==0){ cout<<"YES"; }else{ cout<<"NO"; ...
0
#include <bits/stdc++.h> bool vert, horiz; int main(void) { std::string s; std::cin >> s; for (auto c : s) { int i, j; if (c == '0') { if (vert) { i = 3; j = 1; } else { i = j = 1; } vert = !vert; } else { if (horiz) { i = 4; j = 1;...
6
#include <bits/stdc++.h> using namespace std; struct node { int ini, fim, s, sum; }; int n, n1, n2, n3, v[100010]; node SEG[4 * 100010]; void build(int id, int i, int j) { SEG[id].ini = i; SEG[id].fim = j; SEG[id].sum = 0; SEG[id].s = 0; if (i == j) return; int m = (i + j) / 2; build(2 * id, i, m); bu...
14
#include <bits/stdc++.h> using namespace std; int a[123456], n, x, y, m, ans, b[2253455]; int main() { scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", &x); b[x]++; } for (int i = 0; i <= 2000000; i++) { b[i + 1] += b[i] / 2; if (b[i] % 2 == 1) ans++; } cout << ans; return 0; }
7
#include <bits/stdc++.h> using namespace std; bool solve() { int n; cin >> n; vector<int> a(1 << (n + 1)); vector<int> s(1 << (n + 1)); for (int i = 2; i < (1 << (n + 1)); ++i) cin >> a[i]; long long res = 0; for (int i = (1 << n) - 1; i >= 1; --i) { s[i] = max(a[i * 2] + s[i * 2], a[i * 2 + 1] + s[i ...
6
#include <bits/stdc++.h> using namespace std; struct Lt { int x; long long s; } Q[400000 + 3]; int n, m, Now, Lx, Rx; void Edit(int w, int l, int r, int x) { if (l == r) { Q[w].x = Q[w].s = Now; return; } int mid = (l + r) >> 1; if (x <= mid) Edit(w << 1, l, mid, x); else Edit(w << 1 | 1, ...
15
#include <bits/stdc++.h> using namespace std; int n, m, k, x, y, b = 0, p; string c = "AEIOUYaeiouy"; int main() { string s; getline(cin, s); for (int i = s.size() - 1; i >= 0; i--) { if (s[i] != '?' && s[i] != ' ') { for (int j = 0; j < 12; j++) if (s[i] == c[j]) return cout << "YES", 0; ...
0
#include <bits/stdc++.h> using namespace std; int dau[100010]; int m, x; bool kt() { while (dau[m] != 1) { dau[m] = 1; if (m % x == 0) return true; m = (m + m % x) % x; } return false; } int main() { scanf("%d%d", &m, &x); if (kt()) cout << "Yes"; else cout << "No"; fclose(stdin); fc...
6
#include <bits/stdc++.h> using namespace std; int n; int a[2][22][22]; int second, T; int yy[8888], cs[8888], xx[8888], pp[8888], fl[8888]; int f[8888], d[8888], ww[8888], pr[8888]; int kk; void ae(int x, int y, int ff, int coco) { yy[++kk] = y; cs[kk] = coco; fl[kk] = ff; pp[kk] = xx[x]; xx[x] = kk; yy[++k...
19
#include <bits/stdc++.h> using namespace std; const int MAXL = 1e5 + 100; long long A(long long n, long long k) { long long res = 1; for (int i = 0; i < k; i++) res *= n - i; return res; } char s[MAXL + 1]; int main() { while (scanf("%s", s) >= 1) { int cq = 0; vector<bool> was(26, false); for (int ...
6
#include <bits/stdc++.h> using namespace std; struct laptops { int kalite; int para; } dizi[100006]; bool operator<(laptops a, laptops b) { return a.para < b.para; } int main() { int plp = 0; int a; scanf("%d", &a); for (int i = 0; i < a; i++) { cin >> dizi[i].para >> dizi[i].kalite; } sort(dizi, di...
3
#include <bits/stdc++.h> using namespace std; int a[200001]; vector<int> s; int main() { int n, i, j, x; scanf("%d", &n); for (i = 1; i <= n; i++) { cin >> x; if (x == 1) s.push_back(i); if (x == 0) a[i] = a[i - 1] + 1; else a[i] = a[i - 1]; } long long ans = 0; for (i = 0; i < s...
8
#include <bits/stdc++.h> using namespace std; int n; bitset<2015> mat[2015], num[2015]; int zyo[2015][2015]; vector<int> zy[2015]; priority_queue<pair<int, int> > p, q; bitset<2015> ng(0); int print(bitset<2015> in) { vector<int> t; for (int i = 0; i < 2010; i++) { if (in[i]) t.push_back(i); } cout << t.siz...
19
#include <bits/stdc++.h> using namespace std; const int N = 255; int n, sz[N], val[N], l[N], r[N], mid; bool dp[N][2][3], vis[N][2][3]; inline bool c(int x, int y, int z) { return x == z || y == z ? z : !z; } bool dfs(int pos, int w, int s) { if (val[pos] != -1) return val[pos] > mid; else if (sz[pos] == 1) ...
24
#include <bits/stdc++.h> using namespace std; vector<pair<long long, long long> > h; vector<vector<long long> > g; long long p[500001][21]; long long volume[500001]; long long n, ans, s, f; void dfs(long long v, long long m) { p[v][0] = m; for (long long i = 0; i < g[v].size(); i++) { long long k = g[v][i]; ...
14
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; for (int i = 2; i <= n; i++) printf("%d ", i); printf("1\n"); return 0; }
9
#include <bits/stdc++.h> using namespace std; long double EPS = (long double)1e-11L; const double PI = 3.141592653589793238462; const int INF = 1e9 + 7; const long long LINF = 1e18 + 7; const int MOD = 1e9 + 7; const int S = 21; int n, m, s; vector<long long> bad, ans; vector<vector<long long> > T; vector<vector<long l...
16
#include <bits/stdc++.h> using namespace std; int sg[5050]; int f[5050]; char s[5050]; int n; int search(int l, int r) { int tmp = 0; int ret = 0; for (int i = l + 1; i < r; i++) if (s[i - 1] == s[i + 1]) tmp++; else { ret ^= sg[tmp]; tmp = 0; } ret ^= sg[tmp]; return ret; } int ...
15
#include <bits/stdc++.h> using namespace std; const long long N = 1e5 + 5; long long n, m, temp, ans = 0; long long a[N]; long long check(long long cur) { if (cur % 2) return (cur * (cur - 1) / 2 + 1) <= n; else return (cur * (cur - 1) / 2 + cur / 2) <= n; } int32_t main() { ios::sync_with_stdio(0); cin...
12
#include <bits/stdc++.h> #define ll long long int using namespace std; int main() { ll t; cin>>t; while(t--) { ll n,m,i,j; string a,b,c; cin>>n>>a; vector<int> v; for(i=0;i<n;i++) { if(a[i]=='r') b+='r'; else c+=a[i]; }...
0
#include <bits/stdc++.h> using namespace std; template <typename Arg1> void __f(const char *name, Arg1 &&arg1) { cerr << name << " : " << arg1 << endl; } template <typename Arg1, typename... Args> void __f(const char *names, Arg1 &&arg1, Args &&...args) { const char *comma = strchr(names + 1, ','); cerr.write(nam...
13