solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> bool possible(std::vector<int> &s, std::vector<int> &d) {} int main() { int64_t r, k; std::string s, d; std::cin >> s >> d; std::vector<int> S(27, 0), D(26, 0), Add(26, 0); for (int i = 0; i < s.size(); i++) { if (s[i] != '?') { S[s[i] - 'a']++; } else { S[26]++; ...
7
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:667772160") using namespace std; struct __isoff { __isoff() { if (0) freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout); srand('C' + 'T' + 'A' + 'C' + 'Y' + 'M' + 'B' + 'A'); } ~__isoff() {} } __osafwf; const unsigned long long p1 ...
18
#include <bits/stdc++.h> using namespace std; const int MAX_N = 1000; const int MOD = 1000000007; int as[MAX_N], ds[MAX_N]; int fs[MAX_N + 1], invfs[MAX_N + 1], es[MAX_N + 1]; int powmod(int a, int n) { int pm = 1; while (n > 0) { if (n & 1) pm = (long long)pm * a % MOD; a = (long long)a * a % MOD; n >>...
11
#include <bits/stdc++.h> char a[105][105]; int main() { int n, i, j, cnt; char ent; scanf("%d", &n); scanf("%c", &ent); for (i = 0; i < n; i++) { for (j = 0; j < n; j++) { scanf("%c", &a[i][j]); } scanf("%c", &ent); } int flg = 1; for (i = 0; i < n; i++) { cnt = 0; for (j = 0; ...
2
#include <bits/stdc++.h> #include <iostream> typedef long long int ll; typedef unsigned long long int ull; typedef long double ld; using namespace std; #define fast ios_base::sync_with_stdio(false);cin.tie(NULL); #define fr(i,l,r) for(int i=(l);i<(r);i++) #define test(t) int t;cin>>t; while(t--) #define...
2
#include <bits/stdc++.h> using namespace std; int main() { long long int n, i, m, j, p, q; string s1, s2 = ""; char ch; cin >> n >> s1; for (i = n - 2; i >= 0; i -= 2) { if (i >= 0) { s2 += s1[i]; } } i = 1; if (n % 2 == 1) { s2 += s1[0]; i = 2; } for (j = i; j < n; j += 2) { ...
1
#include <bits/stdc++.h> using namespace std; const int MAX = 100005; int t[MAX * 2]; int n; void build() { for (int i = n - 1; i > 0; i--) t[i] = max(t[i << 1], t[i << 1 | 1]); } void update(int i, int val) { for (t[i += n] = val; i >>= 1;) t[i] = max(t[i << 1], t[i << 1 | 1]); } int query(int l, int r) { int an...
10
#include <bits/stdc++.h> using namespace std; const int N = 2005, M = 1 << 16; using arr = int[M]; bitset<N> f[M]; priority_queue<pair<int, int> > q; int n, k, T, Sum, a[20], Rank[20]; void dfs(int S, int p) { if (!S) return; int r = 0; for (; p * k <= Sum && f[S][p * k]; p *= k, ++r) ; for (int i = 0; i < ...
23
#include <bits/stdc++.h> using namespace std; long long Calc(int x) { int temp = 1; long long sum = 0; while (temp <= x) { sum += (1ll * (x - temp + 1) * (x - temp + 2)) / 2; temp *= 10; } return sum; } long long Calc2(int x) { int temp = 1; long long sum = 0; while (temp <= x) { sum += x - ...
11
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 100; int arr[maxn]; multiset<int> s; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; cin >> n; for (int i = 0; i < n; i++) { int x; cin >> x; s.insert(x); } int ans = 1; while (s.size() > 1)...
7
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; const int INF = 1e9; const int N = 1e5 + 4; long long powmod(long long a, long long b, long long mod) { long long res = 1; a %= mod; for (; b; b >>= 1) { if (b & 1) res = (res * a) % mod; a = (a * a) % mod; } return res % MOD; } in...
3
#include <bits/stdc++.h> using namespace std; template <class T> inline void read(T& n) { T X = 0, w = 1; char ch = -1; while (ch < '0' || ch > '9') { if (ch == '-') w = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { X = (X << 3) + (X << 1) + ch - '0'; ch = getchar(); } n = X * w; ...
3
#include <bits/stdc++.h> using namespace std; const static int inf = 10000000; int main() { long long n, k; while (cin >> n >> k) { vector<int> a(n); map<int, int> cnt; vector<pair<int, int> > stat; for (int i = 0; i < (int)(n); i++) { cin >> a[i]; ++cnt[a[i]]; } for (__typeof((c...
9
#include <bits/stdc++.h> using namespace std; int n, m, op, x, u, v, a[300010]; vector<int> ice[300010]; vector<int> G[300010]; bool vis[300010]; void dfs(int u, int fa) { vector<int> t; for (int i = 0; i < ice[u].size(); i++) { int v = ice[u][i]; if (a[v]) { t.push_back(v); vis[a[v]] = 1; }...
14
#include <bits/stdc++.h> using namespace std; const int MAX_N = 3e5 + 10, MAX_V = 1048576 + 10; int px[MAX_N], cnt[MAX_V][2]; int main() { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; px[0] = 0; for (int i = 0; i < n; ++i) { cin >> px[i + 1]; px[i + 1] ^= px[i]; } int64_t ans = 0; cnt...
8
#include <bits/stdc++.h> using namespace std; int c, d, n, m, k, s; int main() { cin >> c >> d >> n >> m >> k; s = n * m - k; if (s <= 0) { puts("0"); return 0; } int ans = 0; if (c < d * n) { int num_ma = s / n; ans += num_ma * c; int resman = s % n; ans += min(resman * d, c); } e...
7
#include <bits/stdc++.h> template <int MOD> struct ModInt { using lint = long long; int val; ModInt(lint v = 0) : val(v % MOD) { if (val < 0) val += MOD; }; ModInt operator+() const { return ModInt(val); } ModInt operator-() const { return ModInt(MOD - val); } ModInt inv() const { return this->pow(MOD...
15
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:16777216") using namespace std; int n, m; char g[31][31]; int N; int node[30][30]; bool used[30][30]; vector<int> G[14]; bool gem[7][7]; int ncolor[7]; int vcolor[14]; int ret; bool outputed; char gret[30][30]; bool cused[7]; void rec(int v) { if (v == N) { ...
16
#include <bits/stdc++.h> using namespace std; char ans[1000010][35]; int main() { priority_queue<int, vector<int>, greater<int> > Q; char ch[10]; int num; int n, pos = 0; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%s%d", ch, &num); if (strcmp(ch, "insert") == 0) { Q.push(num); ...
8
#include <bits/stdc++.h> using namespace std; unsigned long long n, k, m; int l; vector<vector<unsigned long long> > mul( vector<vector<unsigned long long> > &a, vector<vector<unsigned long long> > &b) { vector<vector<unsigned long long> > c( a.size(), vector<unsigned long long>(b[0].size())); for (in...
13
#include <bits/stdc++.h> using namespace std; int main() { int a, b; cin >> a >> b; if (a > b) swap(a, b); int di = b - a; if (b % a == 0 || b % di == 0) cout << 0; else { int best = di - b % di; for (int i = 1; i * i <= di; i++) { if (di % i == 0) { if (i >= a) best = min(best, i ...
10
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; int t; cin >> t; while (t--) { vector<int> v; int n, x, i; cin >> n; for (i = 0; i < n; i++) { cin >> x; v.push_back(x); } bool flag = false; for (i =...
0
#include <bits/stdc++.h> using namespace std; int read() { int x = 0, f = 1; char ch = getchar(); while (ch - '0' < 0 || ch - '0' > 9) { if (ch == '-') f = -1; ch = getchar(); } while (ch - '0' >= 0 && ch - '0' <= 9) { x = x * 10 + ch - '0'; ch = getchar(); } return x * f; } int n, Q; int ...
23
#include <bits/stdc++.h> using namespace std; int a[10000010], b[10000010], p; string s1, s2; int main() { cin >> s1 >> s2; for (int i = 0; i < s1.size(); ++i) a[i + 1] = s1[i] - 48; for (int i = 0; i < s2.size(); ++i) b[i + 1] = s2[i] - 48; sort(b + 1, b + s2.size() + 1); p = s2.size(); for (int i = 1; i <...
3
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; long long int fac(long long int a) { long long int tmp = 1; for (long long int i = 1; i <= a; i++) tmp *= i; return tmp; } void solve() { long long int a; cin >> a; cout << (fac(a) / (fac(a / 2) * fac(a / 2)) * fac(a / 2 - 1) * ...
5
#include <bits/stdc++.h> using namespace std; int pi[100001], res[100001], nres; void kmp(string text, string pattern) { nres = 0; pi[0] = -1; for (int i = 1; i < pattern.size(); ++i) { pi[i] = pi[i - 1]; while (pi[i] >= 0 && pattern[pi[i] + 1] != pattern[i]) pi[i] = pi[pi[i]]; if (pattern[pi[i] + 1] ...
4
#include <bits/stdc++.h> using namespace std; int a[100010]; int main() { int n, k, amin; long long sum = 0; bool ans = true; scanf("%d%d", &n, &k); for (int i = 0; i < n; i++) scanf("%d", &a[i]); amin = *min_element(a, a + n); for (int i = 0; i < n; i++) { if ((a[i] - amin) % k != 0) ans = fals...
1
#include <bits/stdc++.h> using namespace std; int main() { int n, g[100005] = {}, m[100005] = {}; cin >> n; for (int i = 3; i <= n; ++i) { bool f[500] = {}; for (int j = 2; j * (j + 1) / 2 <= i; ++j) { int k = 0, gi = 0; if ((i - (j + 1) * j / 2) % j == 0) { k = (i - (j + 1) * j / 2) /...
12
#include <bits/stdc++.h> using namespace std; template <typename T> void maxtt(T& t1, T t2) { t1 = max(t1, t2); } template <typename T> void mintt(T& t1, T t2) { t1 = min(t1, t2); } bool debug = 0; int n, m, k; int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0}; string direc = "URDL"; long long ln, lk, lm; void etp(b...
7
#include <bits/stdc++.h> #pragma GCC optimize(2) using namespace std; const double eps = 1e-8; const long long inf = 0x3f3f3f3f; const long long INF = 0x3f3f3f3f3f3f3f3f; const double pi = acos(-1.0); void debug_out() { cerr << endl; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cer...
3
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string a; cin >> a; int z = 0, o = 0; for (int i = 0; i < n; i++) { if (a[i] == '0') z++; else o++; } if (o > 0) cout << 1; while (z--) { cout << 0; } }
0
#include <bits/stdc++.h> using namespace std; int main() { long long n, max = 0, ans = 0; cin >> n; vector<long long> input(n); vector<long long> numberOfMaxes; for (int i = 0; i < input.size(); i++) { cin >> input[i]; if (input[i] > max) max = input[i]; } long long maxCount = 0; for (int i = 0;...
3
#include <bits/stdc++.h> using namespace std; int main() { long long s, x, y, t1, t2, p, d; cin >> s >> x >> y >> t1 >> t2 >> p >> d; long long time_on_foot = abs(x - y) * t2, time_by_tram, cnt = 0; bool meet = false, reach = false; if (d == 1) { if (p == x) meet = true; for (int i = p + 1; i <= s; i+...
8
#include <bits/stdc++.h> using namespace std; int main() { long long l, w; cin >> l >> w; if (l < w) swap(l, w); long long count = 0; while (l > 0 && w > 0) { count += l / w; l = l % w; if (l < w) swap(l, w); } cout << count << endl; }
3
#include<bits/stdc++.h> #define ll long long #define arr vector<ll> #define pb push_back #define loop(i, a, b) for(int i=a;i<b;i++) #define endl "\n" using namespace std; arr read(ll n) { arr a(n); loop(i, 0, n) { cin>>a[i]; } return a; } bool is_ord(ll n) { ll v = n%10; while(n!=0) { ...
2
#include <bits/stdc++.h> using namespace std; template <class A, class B> ostream& operator<<(ostream& o, const pair<A, B>& p) { return o << "(" << p.first << ", " << p.second << ")"; } template <class T> ostream& operator<<(ostream& o, const vector<T>& v) { o << "["; for (__typeof((v).end()) it = (v).begin(); it...
2
#include <bits/stdc++.h> using namespace std; string f(string s, int num, vector<vector<int>> vpp) { int n = s.length(); if (num == 2) { if (vpp[2].size() < 2) return ""; vector<bool> used(n, 1); used[vpp[2][0]] = used[vpp[2][1]] = 0; string t = ""; for (int i = 0; i < n; ++i) { if (used[i...
12
#include <bits/stdc++.h> using namespace std; template <typename first> inline first abs(const first& a) { return a < 0 ? -a : a; } template <typename first> inline first sqr(const first& a) { return a * a; } const int INF = 1000 * 1000 * 1000; const long double EPS = 1e-9; const long double PI = 3.1415926535897932...
5
#include <bits/stdc++.h> using namespace std; int main() { long long int x[3]; int i, n, j; cin >> n >> x[0] >> x[1] >> x[2]; long long int arr[n]; long long int mtx[4][n + 1]; for (i = 0; i < n; i++) cin >> arr[i]; for (i = 0; i <= n; i++) mtx[0][i] = 0; for (i = 1; i < 4; i++) mtx[i][0] = LLONG_MIN; ...
7
#include <bits/stdc++.h> using namespace std; const int N = 1e5, inf = 0x3f3f3f3f; int n, m, tl, tr; int l[N + 1], r[N + 1]; vector<int> e[N + 1]; int p1 = inf, p2; int col[N + 1]; int read() { int ret = 0; char c = getchar(); while (!isdigit(c)) { c = getchar(); } while (isdigit(c)) { ret = ret * 10 ...
24
#include <bits/stdc++.h> using namespace std; const int MAXN = 105; int dp[MAXN][MAXN][2]; int A[MAXN]; int main() { int n; cin >> n; memset(dp, 0x3f, sizeof dp); for (int i = 1; i <= n; ++i) { cin >> A[i]; if (A[i]) A[i] = A[i] & 1; else A[i] = -1; } dp[0][0][0] = dp[0][0][1] = 0; ...
10
#include <bits/stdc++.h> using namespace std; const int INF = INT_MAX; const int maxn = 4005; struct edge { long long to, cap; long double cost; long long flow; size_t back; }; vector<vector<edge> > g(maxn); void add_edge(long long a, long long to, long long cap, long double cost) { edge r1 = {to, cap, cost, ...
16
#include <bits/stdc++.h> using namespace std; int a[110], b[110]; int cmp(int x, int y) { return a[x] < a[y]; } int main() { int s = 0, w, n, y; scanf("%d%d", &n, &w); for (int i = 1; i <= n; i++) scanf("%d", &a[i]); for (int i = 1; i <= n; i++) b[i] = i; sort(b + 1, b + n + 1, cmp); for (int i = 1; i <= n;...
16
#include "bits/stdc++.h" using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int z; cin >> z; for (int q = 0; q < z; q++) { int n, d; cin >> n >> d; vector<int> v(n); for (int i = 0; i < n; i++) cin >> v[i]; sort(v.begin(), v.end()); ...
0
#include <bits/stdc++.h> using namespace std; const long long N = 2e5 + 5; long long n, m, q, col = 0; long long color[N], root[N], sz[N]; string a[N]; map<long long, long long> c; map<string, long long> convert; void init() { for (long long i = 1; i <= n; i++) { root[i] = i; sz[i] = 1; root[i + n] = i + ...
12
#include <bits/stdc++.h> using namespace std; int n, m, q; const int N = 55; double cap[N][N]; double cap2[N][N]; double fnet[N][N]; int Prev[N]; const double INFY = 1e20; double maxflow(int n, int s, int t) { for (int i = 0; i <= n; i++) for (int j = 0; j <= n; j++) fnet[i][j] = 0; double flow = 0; while (tr...
14
#include <bits/stdc++.h> using namespace std; int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } int p[(1 << 16) - 10], pri[(1 << 16) - 10], ps[(1 << 16) - 10], g[(1 << 16) - 10], gc[(1 << 16) - 10]; int n, m; int cnt = 0; int cred(int pp) { if (pp == 1) return 0; int ind = lower_bound(p, p + m, pp) - p; ...
10
#include <bits/stdc++.h> using namespace std; const int N = 1 << 20; int n; int part[N][2]; bool vis[N]; vector<int> ans; vector<pair<int, int> > G[N]; void dfs(int u) { vis[u] = true; for (auto v : G[u]) if (!vis[v.first]) dfs(v.first); } bool check(int Mask) { for (int i = 0; i <= Mask; ++i) G[i].clear(), v...
17
#include <bits/stdc++.h> using namespace std; const long long MAXN = 2e3, INF = 1e18; long long dp[MAXN][MAXN], sum[MAXN][MAXN]; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, m; cin >> n >> m; for (int i = 1; i <= n; ++i) { for (int j = 1; j <= m; ++j) { cin >> sum[...
11
#include <bits/stdc++.h> using namespace std; vector<long long> revtopo, tree[200005], ans; long long arr[200005], giftto[200005]; bool required[200005], vis[200005]; void dfs1(long long x) { vis[x] = 1; long long sz = tree[x].size(); for (long long i = (long long)(0); i <= (long long)(sz - 1); i++) if (!vis[...
12
#include <bits/stdc++.h> using namespace std; string sort(string in) { sort(in.begin(), in.end()); return in; } bool isValid(string a, string b) { int c = 0; for (int i = 0; i < a.size(); i++) c += a[i] != b[i]; return c == 2; } int main() { string a, b; cin >> a >> b; cout << ((sort(a) == sort(b) && is...
3
#include <bits/stdc++.h> using namespace std; template <class T> inline T bigmod(T p, T e, T M) { long long int ret = 1; for (; e > 0; e >>= 1) { if (e & 1) ret = (ret * p) % M; p = (p * p) % M; } return (T)ret; } template <class T> inline T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b)...
10
#include <bits/stdc++.h> using namespace std; long long maxx(long long a, long long b) { if (a > b) return a; return b; } int main() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); long long n, h, ans = 0, sm = 0, mx = 0; cin >> n >> h; vector<long long> v(n); for (int i = 0; i < n; i++...
6
#include <bits/stdc++.h> using namespace std; double EPS = 1e-9; int INF = 2000000000; long long INFF = 8000000000000000000LL; double PI = acos(-1); int dirx[8] = {-1, 0, 0, 1, -1, -1, 1, 1}; int diry[8] = {0, 1, -1, 0, -1, 1, -1, 1}; inline string IntToString(int a) { char x[100]; sprintf(x, "%d", a); string s =...
15
#include <bits/stdc++.h> using namespace std; int n, l, K; struct data { int x; double p; bool operator<(const data &a) const { return x > a.x; } } a[205]; double f[205][205][205]; double ans; int main() { cin >> n >> l >> K; for (int i = 1; i <= n; i++) { int x; cin >> x; a[i].p = 1.0 * x / 100; ...
10
#include <bits/stdc++.h> using namespace std; template <typename T1, typename T2> void chkmin(T1 &x, T2 y) { if (x > y) x = y; } template <typename T1, typename T2> void chkmax(T1 &x, T2 y) { if (x < y) x = y; } namespace fastio { char rbuf[1 << 23], *p1 = rbuf, *p2 = rbuf, wbuf[1 << 23], *p3 = wbuf; inline char ge...
18
#include <bits/stdc++.h> using namespace std; bool isPossible(int median, const int allowed_op, vector<int>& v) { int start_i = (v.size() % 2 == 0) ? (v.size() - 1) / 2 : v.size() / 2; int N = v.size(); int current_op = 0; for (int i = N / 2 - (N + 1) % 2; i < v.size(); i++) { if (v[i] < median) { cur...
6
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; string s; cin >> s; for (char j = 'a'; j <= 'z'; j++) { for (int i = 0; k > 0 && i < s.length();) { if (s[i] == j) { s.erase(i, 1); i = i; k--; } else i++; } if (k <= 0) ...
4
#include <bits/stdc++.h> using namespace std; int N, a, b; int main() { while (cin >> N) { map<int, pair<int, int> > C; for (int i = 0; i < N; ++i) { cin >> a >> b; C[a].first++; C[a].second++; if (a != b) C[b].first++; } int inf = N * 2, n = inf; for (map<int, pair<int, in...
7
#include <bits/stdc++.h> using namespace std; const int N = 23; bool dp[2][1 << N]; int num[N], n; bool work(int len) { memset(dp, 0, sizeof(dp)); dp[0][1] = 1; for (int j = 0; j < n; j++) { int m = j + 1; memset(dp[j + 1 & 1], 0, sizeof(dp[0])); if (j == n - 1) { for (int msk = 0; msk < (1 << n...
14
#include <bits/stdc++.h> using namespace std; int cnt[27]; int num[27]; int main() { string s; int k, mx; int ans; int n; string t; int m; cin >> s >> n; for (int i = 0; i < s.size(); ++i) { ++cnt[s[i] - 'a']; } m = 0; for (int i = 0; i < 26; ++i) { if (cnt[i]) ++m; } if (n < m) { ...
6
#include <bits/stdc++.h> using namespace std; string s; int fin(int i1) { int mi = 999999999; for (int d = 1; d <= 9; d++) { for (int i = i1; i < i1 + 10; i++) { if (i + 2 * d < s.length()) { if (s[i] == s[i + d] && s[i] == s[i + 2 * d]) { mi = min(mi, i + 2 * d); } } }...
11
#include <bits/stdc++.h> using namespace std; const int MAXV = 512; const int MAXN = 512; struct Edge { int to, cap; Edge(int a, int b) { to = a; cap = b; } }; vector<int> adj[MAXV]; vector<Edge> edge; int ptr[MAXV], dinic_dist[MAXV]; inline void addEdge(int u, int v, int cap) { adj[u].push_back(edge.si...
15
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; template <class T, class U> inline void add_self(T &a, U b) { a += b; if (a >= mod) a -= mod; if (a < 0) a += mod; } template <class T, class U> inline void min_self(T &x, U y) { if (y < x) x = y; } template <class T, class U> inline void ma...
7
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const int MAXN = 100100; int F[MAXN], L[MAXN], R[MAXN], val[MAXN]; int Min[MAXN], Max[MAXN]; double ans[MAXN]; double sum[MAXN * 4]; int num[MAXN * 4]; struct Cmd { int val, pos; Cmd() {} Cmd(int val) : val(val) {} }; bool operator<(const C...
14
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 100; int main() { ios::sync_with_stdio(0); cin.tie(0); cout << setprecision(12) << fixed; int n, r; cin >> n >> r; vector<int> c(1 << n); long long sum = 0; for (int i = 0; i < (1 << n); i++) { cin >> c[i]; sum += c[i]; } cout...
17
#include <bits/stdc++.h> using namespace std; int main() { string s, c; cin >> s >> c; int cnt = 0; bool q = true; int z = s.size(), x = c.size(); if (z > x) { for (int i = x - 1; i >= 0; i--) { if (c[i] != s[i + (z - x)]) break; else cnt++; } } else if (x > z) { fo...
1
#include <bits/stdc++.h> using namespace std; const long long N = (long long)2e5 + 7; long long n, w, ret; long long x[N], v[N]; map<long double, long long> f; long long t1[N], t2[N]; vector<long long> ord; bool cmp(long long i, long long j) { return t1[i] < t1[j]; } long double get(long long i, long long a) { return...
17
#include <bits/stdc++.h> int b[305][305]; int dx[4] = {0, -1, 0, 1}; int dy[4] = {-1, 0, 1, 0}; struct Operation { int x, y, t; int id; Operation(int x, int y, int t, int id) : x(x), y(y), t(t), id(id) {} }; std::vector<Operation> op[2000005]; int count[2000005]; int p[90005]; int find(int u) { if (p[u] == u) ...
20
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 5; const int inf = 1e9; const long long mod = 1e17 + 12345654321; long long ans; long long p[maxn]; long long hash1[maxn]; long long hash2[maxn]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; int n, m; scanf("%d%d",...
15
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1); const long long N = 1e5 + 5, M = 1e9 + 7; int main() { ios_base::sync_with_stdio(0); cin.tie(0); long long x, y, xx, yy, ans = 8; cin >> x >> y >> xx >> yy; ans += max(abs(xx - x) - 1, 0ll) * 2; ans += max(abs(yy - y) - 1, 0ll) * 2; ...
3
#include <bits/stdc++.h> using namespace std; int main() { int x, n, a, b; cin >> n >> a >> b; map<int, int> mp; for (int i = 0; i < a; i++) { cin >> x; mp[x] = 1; } for (int i = 0; i < b; i++) { cin >> x; mp[x] = 2; } for (int i = 1; i <= n; i++) cout << mp[i] << ' '; return 0; }
0
#include <stdio.h> #define N 1500 #define K 10 int min(int a, int b) { return a < b ? a : b; } int main() { static int aa[N][N], aaa[N + 1][N + 1][K + 1], sss[N + 1][N + 1][K + 1], kk[N + 1][N + 1], ans[N + 1]; static char used[N * N]; int n, k_, k1, k2, k, h1, h2, i, j, s; scanf("%d%d", &n, &k_); for (i =...
21
#include <bits/stdc++.h> using namespace std; long long n, m; vector<int> a, b; vector<int> gist; int main() { ios_base::sync_with_stdio(false); cin >> n; a.resize(n); for (int i = 0; i < n; ++i) cin >> a[i]; cin >> m; b.resize(m); gist.assign(n, 0); for (int i = 0; i < m; ++i) { cin >> b[i]; gi...
16
#include <bits/stdc++.h> using namespace std; int main() { string n, m; cin >> n; cin >> m; int s = 0, a[26] = {0}, b[26] = {0}; for (int i = 0; n[i] >= 'a' && n[i] <= 'z'; ++i) ++a[int(n[i]) - int('a')]; for (int i = 0; m[i] >= 'a' && m[i] <= 'z'; ++i) ++b[int(m[i]) - int('a')]; for (int i = 0; i < 26 &&...
4
#include <bits/stdc++.h> using namespace std; long long GCD(long long a, long long b) { if (a < b) swap(a, b); return (b == 0 ? a : GCD(b, a % b)); } long long LCM(long long a, long long b, long long c) { long long ans; ans = a * b / GCD(a, b); ans = ans * c / GCD(ans, c); return ans; } int main() { int i...
8
#include <bits/stdc++.h> using namespace std; int main() { int a, b; while (~scanf("%d%d", &a, &b)) { if (a == 0 && b == 0) puts("NO"); else if (abs(a - b) > 1) puts("NO"); else puts("YES"); } return 0; }
2
#include <bits/stdc++.h> using namespace std; const int N = 201110, T = 510; struct Quer { int l, r, id; } quer[N]; int s[N], DP[N], P[N], res[N]; vector<int> G[N]; int n, m, Q; bool comp(Quer u, Quer v) { return u.r < v.r; } void update(int x, int v) { for (; x <= n; x += x & -x) s[x] = max(s[x], v); } int getMax(...
22
#include <bits/stdc++.h> using namespace std; struct edge { int v, w, indx; }; int invalid; vector<int> visit(1005), chk(1005), height(1005), depth(1005), up(1005); vector<edge> adj[1005]; void dfs(int node, int dest) { chk[node] = 1; if (node == dest) chk[node] = 2; up[node] = -1; for (auto x : adj[node]) { ...
18
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); set<long long> used; long long last, n, cur, k; vector<pair<long long, long long> > ans; k = 0; last = 1; cin >> n; for (int i = 0; i < n; i++) { cin >> cur; if (used.find(cur) != used.end()) {...
7
#include <bits/stdc++.h> using namespace std; int main() { long long a = 4, b = 9, x; for (long i = 0; i < long(3); i++) { cin >> x; a += x; } for (long i = 0; i < long(3); i++) { cin >> x; b += x; } cin >> x; if ((int)(a / 5) + (int)(b / 10) <= x) cout << "YES"; else cout << "NO...
0
#include <bits/stdc++.h> using namespace std; int N, Vx, Vy; int A[1010][1010]; vector<int> S; struct SEG { SEG* s[2]; int Mask, Min; SEG() { Mask = Min = 0; s[0] = s[1] = NULL; } int _Min() { return max(Mask, Min); } }; SEG* emp(int L, int R) { SEG* ret = new SEG; if (L < R) { int Mid = (L + ...
19
#include <bits/stdc++.h> using namespace std; const int inf = 1 << 30; const long long INF = 1ll << 60; const double pi = acos(-1); const double eps = 1e-9; const long long mod = 1e9 + 7; const int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0}; int n, A, B; vector<int> a; int main() { ios::sync_with_stdio(0); cin.ti...
2
#include <bits/stdc++.h> using namespace std; const long long llinf = 2e18 + 7; const int inf = 2e9 + 7; const long long mod = 1e9 + 7; const long long N = 1e6 + 7; const long double pi = 3.14159265358979; bool intersection(long long x1, long long y1, long long x2, long long y2) { long long minn = max(x1, x2); long...
5
#include <bits/stdc++.h> using namespace std; int main() { int a[100000], n, i, j = 0; cin >> n; for (i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); for (i = 1; i < n - 1; i++) { if ((a[i - 1] + a[i]) > a[i + 1]) { cout << "YES" << endl; j++; break; } } if (j == 0) cout << "NO" ...
2
#include <bits/stdc++.h> using namespace std; const int MAXN = 100007; int N, deg[MAXN], match[MAXN]; vector<int> comp[MAXN], G[MAXN]; unordered_set<int> temp[MAXN]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> N; for (int i = 0; i < N - 1; ++i) { int u, v; cin >> u >> v; G[u].push_...
13
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ; int n; cin >> n; string a; cin >> a; char v[9]; int flag = 0; for (int i = 0; i < 9; i++) { cin >> v[i]; } for (int i = 0; i < n; i++) { int x = a[i] - '1'; if (flag == 1 && ...
5
#include <bits/stdc++.h> using namespace std; int N, L, R, ans, Sum, mx; int st[1000005]; char s[1000005]; void Work(int l, int r) { int qwq = 0, qwqq = 0, ans = -1; L = 1, R = 1; Sum = 0; for (int i = l; i <= r; i++) { if (s[i] == '(') Sum++, st[Sum] = i; else Sum--; if (Sum == 3 && s[i...
17
#include <bits/stdc++.h> using namespace std; char MAX[100]; bool check[100]; int main() { int student, subject; string arr[100]; cin >> student >> subject; for (int i = 0; i < student; i++) { cin >> arr[i]; for (int j = 0; j < subject; j++) if (arr[i][j] > MAX[j]) MAX[j] = arr[i][j]; } int su...
1
#include <bits/stdc++.h> using namespace std; int main() { long long n, k; scanf("%lld%lld", &n, &k); long long m = n / k; if (m & 1) printf("YES\n"); else printf("NO\n"); }
0
#include <bits/stdc++.h> using namespace std; int n, m, a[600000], b[600000], ans[600000], f[600000], cnt, fa[600000], edge[600000], flag[600000], d[600000]; vector<pair<int, int> > g[600000]; vector<int> c[600000]; bool vis[600000]; void dfs(int u) { vis[u] = 1; d[u] = d[fa[u]] + 1; for (auto e : g[u]) { ...
26
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; const long double PI = 4 * atan((long double)1); const long long INF = 1e18; const long long NINF = -1e18; long long get_hash(string s) { long long N = 1000001; long long base[N], A = 11, MD = 1110111110111; base[0] = 1; for (long long...
8
#include <bits/stdc++.h> using namespace std; const int N = 44; bool vis[N][N][2]; int f[N][N][2], p1[N][N][2], p2[N][N][2]; int s1[N], s2[N]; void update(int& f, int& p1, int& p2, int val, int sl, int sr) { if (val < f || (val == f && (sl + sr < p1 + p2))) f = val, p1 = sl, p2 = sr; } int dp(int l, int r, int dif) {...
20
#include <bits/stdc++.h> using namespace std; const int N = 100000 + 5; const int K = 100 + 5; const int MOD = 998244353; inline int add(int a, int b) { return a + b >= MOD ? a + b - MOD : a + b; } inline int sub(int a, int b) { return a - b < 0 ? a - b + MOD : a - b; } int dp[N][K], sum[N], cnt[N][K]; int main() { i...
16
#include <bits/stdc++.h> using namespace std; char ans[105][105]; int a, b, c, d, n; int x[27]; bool isValid(pair<int, int> curr) { if (!(curr.first >= 1 && curr.first <= a + c)) { return false; } if (curr.first <= a) { return curr.second >= 1 && curr.second <= b && ans[curr.second][curr.first]...
11
#include <bits/stdc++.h> using namespace std; int kase, n; vector<int> vc; int main() { scanf("%d", &kase); while (kase--) { scanf("%d", &n); vc.clear(); vc.push_back(0); for (int i = 1; i * i <= n; i++) { vc.push_back(i); vc.push_back(n / i); if (i == n / i) vc.pop_back(); } ...
6
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e5 + 5; int n, k, deg[MAXN], D, ans[MAXN]; vector<pair<int, int>> G[MAXN]; void dfs(int u, int fa, int pre) { int color = 0; for (auto i : G[u]) { if (i.first == fa) continue; if (color == pre) color = (color + 1) % D, pre = -1; ans[i.secon...
11
#include <bits/stdc++.h> using namespace std; const int N = 100003; const int MOD = 1000000007; int a, b, m; double vx, vy, vz; int main() { while (cin >> a >> b >> m >> vx >> vy >> vz) { double det = fabs(m / vy); double sx = a * 0.5 + det * vx; double sz = det * vz; int t = (int)(sz / (2 * b)); ...
9
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 7; char str[maxn]; int ar[10]; int br[10]; int aar[10]; int bbr[10]; int main() { cin >> str; int cnt = 0; vector<int> s, t; int pp; int len = strlen(str); for (int i = 0; i < len; i++) { aar[str[i] - '0']++; bbr[str[i] - '0']++; ...
11
#include <bits/stdc++.h> using namespace std; int t, m; bool use[128]; map<int, pair<int, int> > bl; map<int, int> d; int main() { int cnt = 0; cin >> t >> m; for (int op = 0; op < t; op++) { string s; cin >> s; if (s == "alloc") { int n; cin >> n; int pos = 0; while (pos + n <...
8