solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> using namespace std; int n, m, ax, ay; bool o; char x[1005][1005]; bool v[1005][1005][4][3]; int dx[] = {0, 0, 1, -1}; int dy[] = {1, -1, 0, 0}; void dfs(int a, int b, int c, int d) { if (v[a][b][c][d] || o) return; v[a][b][c][d] = 1; if (x[a][b] == 'T') { o = 1; return; } for...
8
#include <bits/stdc++.h> using namespace std; int n; vector<int> v; int main() { cin >> n; int cnt = 1; int sum = 0; while (sum + cnt <= n) { v.push_back(cnt); sum += cnt; cnt++; } v[v.size() - 1] += n - sum; cout << v.size() << "\n"; for (int i = 0; i < v.size(); i++) cout << v[i] << " "; ...
2
#include <bits/stdc++.h> using namespace std; const int N = 5e2 + 10; struct Edge { int to, nxt; } e[N * N]; int n, m, tot, ret; int head[N], cnt[N], v[N], a[N], b[N]; void Build(int x, int y) { e[++tot].to = y; e[tot].nxt = head[x]; head[x] = tot; e[++tot].to = x; e[tot].nxt = head[y]; head[y] = tot; } v...
10
#include <bits/stdc++.h> using namespace std; const int n7 = 250123; struct dino { int to, nxt; long long w; } e[n7 * 2]; struct cafe { int p, q, w; } ee[n7 * 2]; int n, ecnt, id[n7], vis[n7], deg[n7], fst[n7]; long long f[n7][2], s[n7]; multiset<long long> a[n7]; int rd() { int shu = 0; bool fu = 0; char c...
26
#include <bits/stdc++.h> using namespace std; const int inf = 1000000000, dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; const double eps = 1e-8; void read(int &k) { k = 0; char x = getchar(); while (x < '0' || x > '9') x = getchar(); while (x >= '0' && x <= '9') { k = k * 10 - 48 + x; x = getchar(); } }...
14
#include <bits/stdc++.h> using namespace std; const int maxn = 1e3 + 5; const int maxm = 3e3 + 5; struct DSU { int lab[maxn]; void Init(void) { memset(lab, -1, sizeof lab); } int finds(int u) { if (lab[u] < 0) return u; return lab[u] = finds(lab[u]); } bool same(int u, int v) { return finds(u) == find...
12
#include <bits/stdc++.h> using namespace std; template <class T> inline T min(T &a, T &b) { return a < b ? a : b; } template <class T> inline T max(T &a, T &b) { return a > b ? a : b; } template <class T> void read(T &x) { char ch; while ((ch = getchar()) && !isdigit(ch)) ; x = ch - '0'; while ((ch = ge...
14
#include <bits/stdc++.h> using namespace std; int main() { long long int n, i; int k, t; cin >> n; t = 0; while (n % 10 == 0) n = n / 10; i = n; while (n > 0) { k = n % 10; t = (t * 10) + k; n = n / 10; } if (t == i) cout << "YES" << endl; else cout << "NO" << endl; return 0; }...
1
#include <bits/stdc++.h> using namespace std; long long getCnt(long long L, long long R, long long targD, map<long long, long long>& memo) { if (L + 1 == R) { return 0; } long long d = (R - L) / 2; if (d < targD) { return 0; } auto it = memo.find(R - L); if (it != memo.end()) { ...
21
#include <bits/stdc++.h> using namespace std; int n, va, vb, oneb, temp, deny; int main() { oneb = 0, deny = 0; cin >> n >> va >> vb; for (int i = 0; i < n; i++) { cin >> temp; if (temp == 1) { if (va > 0) va--; else { if (vb > 0) { vb--; oneb++; } e...
4
#include <bits/stdc++.h> using namespace std; const int LIM = 1e+5 + 10; const int MOD = 987100417; const int BASE = 37; const int NUMS = 10; struct node { long long l, r, pos, hash, val; node() : l(-1), r(-1), pos(-1), hash(-1), val(-1) {} }; node tree[2 * LIM]; int size = 1; int root = 0; long long powers[LIM]; i...
17
#include <bits/stdc++.h> using namespace std; int IN() { int c, f, x; while (!isdigit(c = getchar()) && c != '-') ; c == '-' ? (f = 1, x = 0) : (f = 0, x = c - '0'); while (isdigit(c = getchar())) x = (x << 1) + (x << 3) + c - '0'; return !f ? x : -x; } const int N = 5000 + 19; const int M = 200000; const...
18
#include <bits/stdc++.h> using namespace std; long long int MOD = 1e9 + 7; void solve() { int n; cin >> n; map<long long int, long long int> ma; for (int i = 0; i < n; i++) { long long int x; cin >> x; x = (x + i) % n; if (x < 0) x += n; ma[x]++; } for (auto i : ma) { if (i.second > ...
8
#include <bits/stdc++.h> using namespace std; int n, k, a, b, c, ans; int main() { int i, t; scanf("%d%d", &n, &k), a = b = c = k; while (1) { if (a > b) swap(a, b); if (a > c) swap(a, c); t = max(a + b, b + c), t = max(t, a + c); if (t > n) break; a = b + c - 1, ans++; } return printf("%d...
8
#include <bits/stdc++.h> using namespace std; int n, m; int c[100005]; set<int> s[100005]; set<int> colors; int main() { scanf("%d%d", &n, &m); for (int i = 0; i < n; i++) { scanf("%d", &c[i]); colors.insert(c[i]); } for (int i = 0; i < m; i++) { int v1, v2; scanf("%d%d", &v1, &v2); v1--; ...
8
#include <bits/stdc++.h> using namespace std; int main() { int i, j = 1, t, n, z, a[100000]; cin >> z; while (j <= z) { cin >> n; t = n / 2; if (t % 2 != 0) cout << "NO" << endl; else { cout << "YES" << endl; i = 0; while (i < t) { cout << 2 + 2 * i << endl; ...
0
#include <bits/stdc++.h> using namespace std; int n, k, a[300005], dp[5005][5005]; int main() { scanf("%d%d", &n, &k); for (int i = 1; i <= n; i++) scanf("%d", &a[i]); sort(a + 1, a + n + 1); int sum = a[n] - a[1], x = n % k, y = k - x, t = n / k; for (int i = 1; i < n; i++) a[i] = a[i + 1] - a[i]; for (int...
12
#include <bits/stdc++.h> using namespace std; template <typename Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 << std::endl; } template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args) { const char* comma = strchr(names + 1, ','); cerr.writ...
6
#include <bits/stdc++.h> using namespace std; int main() { int n, m, v[100], a = 0; cin >> n >> m; for (int i = 1; i <= n; i++) v[i] = i * m; a = n; for (int i = 1; i <= a; i++) { if (v[i] <= n) n++; } cout << n << endl; return 0; }
1
#include <bits/stdc++.h> using namespace std; const int MOD = 998244353; const int maxn = 1010; const int K = 11; const int INF = 1e9 + 10; const double eps = 1e-13; const long long mo = 1000000000039ll, base = 9971; const int N = 2005, M = 205; map<long long, int> f; int n, m; char a[N][M]; char b[M][N]; int main() { ...
12
#include <bits/stdc++.h> int main(void) { int a[4]; for (int i = 0; i < 4; i++) scanf("%d", &a[i]); while (a[0] > 1 || a[1] > 1 || a[2] > 1 || a[3] > 1) { int f = 0; for (int i = 0; i < 4; i++) { if (a[i] % 2 == 0 && (a[(i + 1) % 4] % 2 == 0)) { printf("/%d\n", i + 1); a[i] /= 2; ...
14
#include <bits/stdc++.h> using namespace std; int ans[128]; char maze[128][128]; int main() { int n; scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%s", maze[i]); bool isok = true; for (int i = 0; i < n && isok; i++) { bool ok = false; for (int j = 0; j < n && !ok; j++) if (maze[i][j] == '....
7
#include <bits/stdc++.h> using namespace std; int cnt = 0; int vec[10]; int L[19], R[19]; int cnt2 = 0, cnt3; void go(int nxt, int sum) { if (nxt == 10 && sum == 19) { cnt2++; bool ok = 0; int vec2[10]; for (int i = 0; i < 10; i++) vec2[i] = vec[i]; for (int i = 0; i < 19; i++) { if (L[i] ==...
19
#include <bits/stdc++.h> using namespace std; const int MOD = 1000000007; int N, M; long long power(long long a, long long b) { if (b == 0) return 1; if (b == 1) return a; if (b % 2 == 0) return power(a * a % MOD, b / 2); return a * power(a * a % MOD, (b - 1) / 2) % MOD; } int main() { cin >> N >> M; long l...
19
#include <bits/stdc++.h> using namespace std; int n, m; int a[1005][1005], sx, sy[1005], fx[1005], fy[1005]; int bx[1005], by[1005], num; int next2[4][2] = {{0, 1}, {-1, 0}, {0, -1}, {1, 0}}; void dfs(int x, int y) { a[x][y] = -1; for (int i = 0; i < 4; i++) { int nx = x + next2[i][0]; int ny = y + next2[i]...
12
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") using namespace std; const long long inf = 1e9; int digit(int n) { return n < 10 ? 1 : 1 + digit(n / 10); } void faltu() { long long sum = 0; int ...
11
#include <bits/stdc++.h> using namespace std; void qs(int *a, int l, int r) { int i = l; int j = r; int y, p = a[(l + r) >> 1]; do { while (a[i] < p && i < r) i++; while (a[j] > p && j > l) j--; if (i <= j) { y = a[i]; a[i] = a[j]; a[j] = y; i++; j--; } } while (i...
12
#include <bits/stdc++.h> using namespace std; const int MN = 101010; map<int, int> m; int ans[MN], a[MN]; int num[2]; bool is_good(int x) { deque<int> q; q.push_back(x); bool cur1 = 0, cur2 = 1; while (true) { int nex = num[cur1] - q.back(); if (!m.count(nex) || nex == q.front() || nex == q.back()) brea...
12
#include<bits/stdc++.h> using namespace std; #define ri register int typedef long long ll; const int maxn=1e4+10; int n,t; ll a,ans,f[maxn]; int main(){ scanf("%d",&t); while(t--){ scanf("%d",&n); memset(f,0,sizeof f); ans=0; for(ri i=1;i<=n;++i){ scanf("%lld",&a); for(ri j=min((ll)n,i+a);j>i+1;--j)++f[...
9
#include <bits/stdc++.h> using namespace std; vector<int> adj[500006]; vector<int> depth[500006]; int par[500006]; int ancestor[500006][20]; int cnt[500006][27]; int vis[500006]; int height[500006]; int prev_2[500006]; int idx[500006]; int mp[500006]; char s[500006]; void bfs() { queue<pair<int, int> > q; q.push(ma...
14
#include <bits/stdc++.h> using namespace std; template <class T> int size(const T& x) { return x.size(); } struct intvl { char c; int st; int cnt; bool minimize; int ansst; }; void EMinlexes(std::istream& in, std::ostream& out) { string s; in >> s; int n = s.length(); vector<intvl> ints; char c = ...
19
#include <bits/stdc++.h> using namespace std; int n, m; int main(int argc, const char* argv[]) { scanf("%d%d", &n, &m); if (n + m == 2) printf("1\n"); else if (n + m < 5 && n + m > 2) printf("-1\n"); else { int b = n * m / 2; int x = 1; int y = b + 1; for (int i = 1; i <= n; i++) { ...
10
#include <bits/stdc++.h> using namespace std; void FASTIO() { ios_base::sync_with_stdio(false); cin.tie(NULL); } int main() { int n, k; cin >> n >> k; set<int> friendsIds; queue<int> conversations; for (int idx = 0; idx < n; idx++) { int friendId; cin >> friendId; if (friendsIds.count(friendId...
5
#include <bits/stdc++.h> using namespace std; const int N = 1000000; struct edge { int a, b; int cap; int flow; int back; edge(int a, int b, int cap, int flow) { this->a = a; this->b = b; this->cap = cap; this->flow = flow; back = 0; } }; vector<int> g[N]; vector<edge> e; int level[N]; i...
10
#include <bits/stdc++.h> using namespace std; int z[102][103], y[102][102]; int a[104]; int b[104]; int g[104]; int main() { int n, k; cin >> n >> k; for (int i = 1; i <= n; i++) cin >> a[i]; for (int j = 1; j <= n; j++) cin >> b[j]; int e = 0; for (int i = 1; i <= n; i++) { if (a[i] != i) e = 1; z[...
10
#include <bits/stdc++.h> using namespace std; const int inf = (int)1e9 + 123; const long long infl = (long long)1e18 + 123; const double eps = 1e-9; const int MAX_N = (int)3e5 + 5; const int mod = (int)1e9 + 7; int n, m; vector<int> g[MAX_N], contains[MAX_N]; set<int> first[MAX_N]; int p[MAX_N], cl[MAX_N]; bool cmp(int...
16
#include <bits/stdc++.h> using namespace std; const int maxn = 300010; struct edge { int v; edge *next; edge(int _v, edge *_next) : v(_v), next(_next) {} }; int n, bad[maxn], color[maxn]; bool inq[maxn]; edge *E[maxn]; queue<int> Q; void calc(int x) { bad[x] = 0; for (edge *e = E[x]; e; e = e->next) if (c...
14
#include <bits/stdc++.h> using namespace std; long long n, k, p, i, j, k2, cnt, a[100005], b[100005], t, k1, p2, kt, pos, pp, cc; int main() { cin >> n >> kt >> p; k = 1, k1 = 1; for (i = 1; i <= n; i++) { cin >> t; if (t % 2 == 0) a[k++] = t; else b[k1++] = t; } pos = k - 1; pp ...
9
#include <bits/stdc++.h> using namespace std; int a[100]; long long cnt, k, f[100]; int n; void dfs(int l) { { if (l == n) { { for (int i = 0; i < n; ++i) { printf("%d%c", a[i], i != n - 1 ? ' ' : '\n'); } } return; } dfs(l + 1); if (l < n - 1) { swap(...
11
#include <bits/stdc++.h> using namespace std; const int N = 10010; int ml = N, mr, l[5], r[5], n; double ans, p1[5], p2[5], p3[5]; int main() { scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d%d", &l[i], &r[i]); ml = min(ml, l[i]); mr = max(mr, r[i]); } for (int i = ml; i <= mr; i++) { d...
12
#include <bits/stdc++.h> using namespace std; set<pair<int, int> > ren1, ren2; int n, m; int check(pair<int, int> x, pair<int, int> y) { int a = x.first, b = x.second, c = y.first, d = y.second; if (a == c && b == d) return 0; if (a == c || a == d) return a; if (b == c || b == d) return b; return 0; } int mai...
11
#include <bits/stdc++.h> using namespace std; void sc(int& x) { x = 0; char c = getchar(); while (c > '9' || c < '0') c = getchar(); for (; c >= '0' && c <= '9'; c = getchar()) x = x * 10 + c - '0'; } const int N = 2e5 + 7; namespace Treap { int ch[N][2], sz[N], val[N], key[N], stk[N], ans[N], num[N], top, tot,...
20
#include <bits/stdc++.h> using namespace std; int n, m; int power(int a, int n, int modulo) { int result = 1 % modulo; int e = a; while (n > 0) { if (n & 1) { result = (long long)result * e % modulo; } e = (long long)e * e % modulo; n >>= 1; } return result; } int main() { cin >> n >> ...
6
#include <bits/stdc++.h> #define ll long long #define fl float #define pb push_back #define pf push_front #define mk make_pair #define fr front() #define bc back() #define ft first #define sc second #define tp top() #define pp pop() #define bn begin() #define en end() #define sz size() #define em empty() #define fast i...
0
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1); const int N = (int)1e6 + 7, mod = 1000000007, M = 2e9; int n, m, a[5007], dp[5007][5007]; double t; int slv(int i = 0, int c = 1) { if (i == n) return 0; if (c > m) return n - i; int& ret = dp[i][c]; if (~ret) return ret; return ret = m...
9
#include <bits/stdc++.h> using namespace std; int main() { long long n, k, q; cin >> n >> k; vector<long long> a(n); vector<pair<long long, long long> > b; for (long long i = 0; i < n; i++) { cin >> a[i]; for (long long j = 1; j <= k; j++) { b.push_back(make_pair(a[i] * j, j)); } } sort(...
11
#include <bits/stdc++.h> using namespace std; int main() { int n, P1, P2, P3, T1, T2, previous_start, previous_end, power; cin >> n >> P1 >> P2 >> P3 >> T1 >> T2 >> previous_start >> previous_end; power = P1 * (previous_end - previous_start); while (--n > 0) { int start, end; cin >> start >> end; po...
1
#include <bits/stdc++.h> using namespace std; vector<vector<double>> IDENT() { vector<vector<double>> A(3, vector<double>(3)); for (int i = 0; i < 3; i++) A[i][i] = 1; return A; } vector<vector<double>> mul(vector<vector<double>> A, vector<vector<double>> B) { vector<vector<double>> C(A.size(), vector<double>(B...
23
#include <bits/stdc++.h> using namespace std; const int NMAX = 1005; char v[NMAX][NMAX]; int vf[NMAX]; int fata[NMAX]; struct ABC { int nr; int c; }; ABC a[NMAX]; bool cmp(ABC first, ABC second) { return first.nr > second.nr; } int cif[NMAX]; int main() { int n; scanf("%d", &n); for (int i = 1; i <= n; ++i) {...
9
#include <bits/stdc++.h> using namespace std; const long long MAX = 1e6 + 1; void solve() { long long n; cin >> n; unordered_map<long long, long long> mp; long long a[n]; for (long long i = 0; i < n; i++) { cin >> a[i]; mp[a[i]]++; } for (long long i = 0; i < n; i++) { if (mp[a[i]] > 2) { ...
2
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const long long int llINF = (long long)(1e18) + 100; const int MAXN = 3e2 + 10; const int MAXM = 9e4; int ned, first[MAXN], work[MAXN], dist[MAXN], q[MAXN]; int cap[MAXM], to[MAXM], nxt[MAXM]; void init() { memset(first, -1, sizeof first); ne...
21
#include <bits/stdc++.h> using namespace std; template <typename T> using v = vector<T>; const long long inf = 4611686018427387903; const long double EPS = 1e-10; void read() {} template <typename Arg, typename... Args> void read(Arg& arg, Args&... args) { cin >> (arg); read(args...); } void print() {} template <ty...
9
#include <bits/stdc++.h> using namespace std; const long long dx[] = {0, 1, 0, -1}; const long long dy[] = {1, 0, -1, 0}; const long long inf = 2e6; const long long mod = 1e9 + 7; const long long N = 2e6 + 11; const long long INF64 = 3e18 + 1; const double eps = 1e-14; const double PI = acos(-1); long long n, a[N], t[4...
16
#include <bits/stdc++.h> using namespace std; void solve() { string s1, s2; cin >> s1 >> s2; int n = s1.length(), m = s2.length(), ans = 0, i; int h1[26], h2[26]; memset(h1, 0, sizeof(h1)); memset(h2, 0, sizeof(h2)); for (i = 0; i < n; i++) h1[s1[i] - 'a']++; for (i = 0; i < m; i++) h2[s2[i] - 'a']++; ...
4
#include <bits/stdc++.h> using namespace std; long long dp[5000016], prime[5000016]; void sieve() { for (long long i = 1; i < 5000016; i++) prime[i] = i; for (long long i = 2; i <= sqrt(5000000); i++) { if (prime[i] == i) { for (long long j = 2 * i; j <= 5000000; j = j + i) prime[j] = i; } } } int m...
10
#include <bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; long long n, l, r, memo[200005][3], c[3]; long long solve(long long x = 0, long long rem = 0) { if (x == n) return (!rem ? 1 : 0); long long &ans = memo[x][rem]; if (~ans) return ans; ans = 0; for (int i = 0; i < 3; i++) ans = ...
7
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:100000000000000") using namespace std; long long n, k, l, arr[1000011]; int startPos[1000011], startPos2[1000011]; vector<long long> dp[1000011], vec, vec2; long long rec(int p, int rem) { if (rem == 0) return 1; if (p >= vec.size()) return 0; if (~dp[p][re...
13
#include <bits/stdc++.h> using namespace std; int n, m, b[1000000], t1, t0, l, r, x, a[1000000], z, num[10000000], q[10000000]; int main() { cin >> n >> m; for (int i = 0; i <= 1000; i++) b[i] = -1; for (int i = 0; i < n; i++) { cin >> a[i]; num[i] = i; } for (int i = 0; i <= n; i++) { for (in...
8
#include <bits/stdc++.h> using namespace std; char a[110]; int main() { while (cin >> a) { int i, flag = 0; int cnt = 1; for (i = 1; i < strlen(a); i++) { if (a[i] != a[i - 1]) { if (cnt >= 7) { flag = 1; } cnt = 1; } else { cnt++; } } if...
1
#include <bits/stdc++.h> using namespace std; const int inf = 1000000000; template <class T> vector<T> takeInput(int n) { vector<T> list; T a; int i; for (i = 0; i < n; i++) { cin >> a; list.push_back(a); } return list; } long long ncr[305][305] = {0}; void gen_ncr(int n) { int i, j; for (i = 0;...
11
#include <bits/stdc++.h> using namespace std; const int MAX = (int)1E5 + 10; const int dx[] = {0, -1, 0, 1}; const int dy[] = {-1, 0, 1, 0}; int n, m, cookie; set<pair<int, int> > A, B; int touch[MAX], minr[MAX], maxr[MAX]; vector<pair<int, int> > cv; bool is_four(int x, int y) { if (x < 1 || x > n) return false; i...
18
#include <bits/stdc++.h> using namespace std; const int N = 55; int R, C, KK; char ssG[N][N]; int stx, sty; struct nodexx { string str; int x, y, val; nodexx(string str00, int x00, int y00, int val00) { str = str00, x = x00, y = y00, val = val00; } bool operator<(const nodexx t) const { int lenaa = st...
16
#include <bits/stdc++.h> using namespace std; vector<int> g[2000]; long long cost[2000][2000]; bool is_special[2000][2000]; int main(void) { int n, m, L, s, t; scanf("%i %i %i %i %i", &n, &m, &L, &s, &t); vector<int> from(m), to(m); for (int i = 0; i < m; i++) { int u, v, w; scanf("%i %i %i", &u, &v, &w...
15
#include <bits/stdc++.h> using namespace std; namespace red { inline long long read() { long long x = 0; char ch, f = 1; for (ch = getchar(); (ch < '0' || ch > '9') && ch != '-'; ch = getchar()) ; if (ch == '-') f = 0, ch = getchar(); while (ch >= '0' && ch <= '9') { x = (x << 1) + (x << 3) + ch - '0'...
16
#include <bits/stdc++.h> using namespace std; long long a, b, c, l, ans; long long magic(long long a, long long b, long long c, long long l) { l = min(l, a - b - c); if (l < 0) return 0; return (l + 1) * (l + 2) / 2; } int main(int argc, char const *argv[]) { cin >> a >> b >> c >> l; ans = (l + 1) * (l + 2) *...
13
#include <bits/stdc++.h> using namespace std; int a[500500]; int dp[101][500001]; int mn[500001]; int k, p; inline int ps(int a, int b) { int u = dp[1][b] - dp[1][a]; if (u < 0) u += p; if (u >= p) u -= p; return u; } inline void print(int a) {} int main() { int n; scanf("%d", &n); scanf("%d", &k); scan...
17
#include <bits/stdc++.h> using namespace std; const int sz = 3e5 + 5; bool ya[4]; int x, y, z, dep[6][6][6], per[6][6][6]; vector<vector<int>> a, dp[6][6][6]; vector<int> cut; long long ara[sz]; void solve() { auto &a = dp[x][y][z] = {vector<int>(3, 0)}; map<vector<vector<int>>, int> mp; vector<vector<int>> last(...
17
#include <bits/stdc++.h> using namespace std; int num[1000005]; int main() { int n; scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d", &num[i]); sort(num + 1, num + n + 1); int ans = 0, r = 1; for (int i = 1; i <= n; i++) { while (r <= n && num[r] <= num[i]) r++; if (r <= n) { ans++; ...
5
#include <bits/stdc++.h> using namespace std; int t, n, x, temp, odd, even; int main() { scanf("%d", &t); while (t--) { scanf("%d %d", &n, &x); odd = 0; even = 0; for (int i = 0; i < n; i++) { scanf("%d", &temp); if (temp % 2 == 0) even++; else odd++; } if (...
4
#include <bits/stdc++.h> using namespace std; long long N, M, K, x, y, a[110][110]; int main() { cin >> N >> M >> K >> x >> y; int i, j; long long mn = K, mx = 0; if (N == 1) { long long aux = K / M; K %= M; for (i = 1; i <= M; i++) { a[1][i] += aux; if (i <= K) a[1][i]++; } K = ...
9
#include <bits/stdc++.h> using namespace std; #define lli long long int const int N = 200100; int t, n, m; lli a, b; vector<lli>v[3]; pair<lli, lli> p[N]; void solve () { cin >> n; for (int i = 1; i <= n; i++) { cin >> a >> b; p[i]=make_pair(a, b); v[0].push_back(a); v[1].push_back(b); } lli mini=1e13; ...
10
#include <bits/stdc++.h> using namespace std; int main() { long long n, m; cin >> n >> m; long long x = 1, y = 0; for (int i = 1; i <= 10000; ++i) { x = (x * 3) % m; y = (y * 3 + 2) % m; } long long ans = 0; while (n > 10000) { ans = (ans * x + y) % m; n -= 10000; } while (n) { ans...
6
#include <bits/stdc++.h> using namespace std; int Q, K, l, r; long long dp[100001]; struct STnode { long long sum; void merge(STnode& left, STnode& right) { sum = ((left.sum % 1000000007) + (right.sum % 1000000007)) % 1000000007; } }; STnode ST[4 * 100001]; void dpSubSet() { for (int i = 0; i < K; i++) dp[i...
9
#include <bits/stdc++.h> int n, k, MOD, len; long long pw[1010]; long long f[1002][1002][2][2][2]; long long dfs(int l, int yu, bool lst, bool z, bool ok) { if (l == len + 1) return ok && lst; if (~f[l][yu][lst][z][ok]) return f[l][yu][lst][z][ok]; long long ans = 0; bool ok2, z2; int yu2; for (int i = 0; i...
14
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); } long long min(long long a, long long b) { return a < b ? a : b; } long long max(long long a, long long b) { return a > b ? a : b...
10
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0); int a, b, c, d; cin >> a >> b >> c >> d; long long int ans, ans1; ans = max((3 * a) / 10, a - ((a / 250) * c)); ans1 = max((3 * b) / 10, b - ((b / 250) * d)); if (ans > ans1) { ...
1
#include <bits/stdc++.h> using namespace std; struct __timestamper {}; vector<vector<vector<int>>> g; vector<string> s; void build(int aid, int bid, vector<vector<int>>& ga) { string str = s[bid] + '$' + s[aid]; vector<int> p(str.size()); ga[0].push_back(bid); for (int i = 1; i < (int)str.size(); i++) { int...
24
#include <bits/stdc++.h> using namespace std; const int INF = INT_MAX; const long long INFL = LLONG_MAX; const long double pi = acos(-1); struct BIT { int N; vector<long long> v; BIT(int n) : N(n), v(n + 1) {} long long sum(int i) { long long s = 0; for (; i > 0; s += v[i], i -= i & -i) ; retu...
12
#include <bits/stdc++.h> using namespace std; inline int read() { char ch = getchar(); int nega = 1; while (!isdigit(ch)) { if (ch == '-') nega = -1; ch = getchar(); } int ans = 0; while (isdigit(ch)) { ans = ans * 10 + ch - 48; ch = getchar(); } if (nega == -1) return -ans; return ans...
12
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; bool prime[1000001]; long long f[1000005]; long long pow1(long long x, long long y) { long long res = 1; x = x % mod; if (x == 0) return 0; while (y > 0) { if (y & 1) res = (res * x) % mod; y = y >> 1; x = (x * x) % mod; ...
9
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { long long n, r, temp; cin >> n >> r; set<long long> s; for (int i = 0; i < n; i++) { cin >> temp; s.insert(temp); } vector<long long> grid(s.begin(), s.end()); bool flag = 0; for (...
5
#include <bits/stdc++.h> using namespace std; int main() { long long int t; cin >> t; while (t--) { long long int n; cin >> n; vector<long long int> v(n); vector<long long int> v1(n); for (long long int i = 0; i < n; i++) cin >> v[i]; for (long long int i = 0; i < n; i++) cin >> v1[i]; ...
0
#include <bits/stdc++.h> using namespace std; using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>; using ll = long long int; using vll = vector<ll>; using vvll = vector<vll>; using vvvll = vector<vvll>; using vd = vector<double>; using vvd = vector<vd>; using vvvd = vector<vvd>; using P = pair<int,...
13
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); unsigned long long n, sum = 0, sum1 = 0, a, b; cin >> n; for (unsigned long long i = 0; i < n; i++) { cin >> a; sum = sum | a; } for (unsigned long long i = 0; i < n; i++) { ...
1
#include <bits/stdc++.h> using namespace std; void fast() { ios_base::sync_with_stdio(false); cin.tie(NULL); } void solve() { int n; cin >> n; int a[n + 1], r[n + 1]; for (__typeof(n + 1) i = (1) - ((1) > (n + 1)); i != (n + 1) - ((1) > (n + 1)); i += 1 - 2 * ((1) > (n + 1))) r[i] = -1; set<int...
2
#include <bits/stdc++.h> using namespace std; const double PI = 2.0 * acos(0.0); const double E = exp(1); template <class T1> void deb(T1 e) { cout << e << 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,...
16
#include <bits/stdc++.h> using namespace std; map<long long, long long> primeFactor; long long m, x; long long d = 1, answer = 1, cnt, p, fp; const long long MOD = (long long)1e9 + 7; long long binPow(long long a, long long q, long long MOD) { a %= MOD; if (q == 0) return 1; return ((q % 2 == 1 ? a : 1) * binPow(...
12
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 7; struct RMQ { vector<int> t; int n; RMQ(int n) : n(n) { t.resize(n << 1, 0); } void modify(int p, int v) { for (t[p += n] = v; p > 1; p >>= 1) t[p >> 1] = (t[p] + t[p ^ 1]); } int query(int l, int r) { int res = 0; for (l += n, ...
12
#include <bits/stdc++.h> using namespace std; template <typename G1, typename G2 = G1, typename G3 = G1> struct triple { G1 first; G2 second; G3 T; }; pair<long long, char> read() { string s; cin >> s; int x = 0; for (int i = 0; i < s.size() - 2; i++) x = 10 * x + (s[i] - '0'); return {x, s.back()}; } v...
13
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") using namespace std; int main() { ios_base::sync_with_stdio(0), cin.tie(0); string s; cin >> s; long long ans = 0; map<pair<char, char>, long long> b; map<char, long long> cnt; for (int i = (int)0; i < (int)(int)(s).size(); i++) { for (char c = 'a...
7
#include <bits/stdc++.h> using namespace std; long long n; long long a[10001]; bool f[1000001]; long long gcd(long long x, long long y) { while (y != 0) { long long m = x % y; x = y; y = m; } return x; } void Solve() { fill_n(&f[0], sizeof(f) / sizeof(f[0]), false); for (int i = 1; i <= n; i++) f[...
11
#include <bits/stdc++.h> using namespace std; template <class T> void read(T &u) { u = 0; char c = getchar(); int flag = 0; while (c < '0' || c > '9') flag |= (c == '-'), c = getchar(); while (c >= '0' && c <= '9') u = (u << 3) + (u << 1) + (c ^ 48), c = getchar(); if (flag) u = -u; } template <class T>...
17
#include <bits/stdc++.h> using namespace std; int main() { long long int n, i, j, d = 0; cin >> n; for (i = 1; i <= n; i++) { for (j = i; j <= n; j++) { long long int k = i ^ j; if (k >= j && i + j > k && i + k > j && j + k > i && k <= n) d++; } } cout << d << endl; }
5
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s; cin >> s; string a = ""; for (int i = 0; i < s.length(); i++) { if (s[i] == '2') a += '2'; else if (s[i] == '3') a += '3'; else if (s[i] == '4') { a += '2'; a += '2'; a += '3'; ...
6
#include <bits/stdc++.h> using namespace std; #pragma GCC target("avx2") #pragma GCC optimization("O3") #pragma GCC optimization("unroll-loops") template <typename T> void write(T a) { if (a < 0) { putchar('-'); write(-a); return; } if (a < 10) { putchar('0' + a); return; } write(a / 10); ...
6
#include <bits/stdc++.h> using namespace std; class DSU { public: DSU(int n = 0) { parent = vector<int>(n + 1); for (int i = 0; i < n + 1; ++i) parent[i] = i; Rank = vector<int>(n + 1); sets_num = n; } int sets_num; int find_set(int v) { if (v == parent[v]) return v; return v = find_set...
9
#include <bits/stdc++.h> using namespace std; int n, c, ans = 0; int a[105]; int main() { cin >> n >> c; for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 1; i < n; i++) if (a[i] - a[i + 1] > ans) ans = a[i] - a[i + 1]; ans = ans - c; if (ans > 0) cout << ans << endl; else cout << "0\n"; ...
2
#include <bits/stdc++.h> using namespace std; template <typename T, typename S> inline bool upmin(T& a, const S& b) { return a > b ? a = b, 1 : 0; } template <typename T, typename S> inline bool upmax(T& a, const S& b) { return a < b ? a = b, 1 : 0; } template <typename N, typename PN> inline N flo(N a, PN b) { r...
14
#include <bits/stdc++.h> using namespace std; const int N = 104, NN = N * N, K = 904; int a[N]; int id[N][N]; vector<pair<int, double>> p[NN], q[NN]; double dp[2][NN]; int get(int i, int l, int r) { if (i < l || i > r) return i; return l + r - i; } int main() { ios::sync_with_stdio(0); cin.tie(0); int n, k; ...
23
#include <bits/stdc++.h> using namespace std; priority_queue<long long> c, r; long long a[1040][1040]; long long sr[1000400], sc[1000400]; int main() { long long n, m, k, p, i, j, s, o, cc, cr; cin >> n >> m >> k >> p; for (i = 0; i < n; i++) { s = 0; for (j = 0; j < m; j++) { cin >> a[i][j]; ...
12