solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> using namespace std; int fail[400010], sn[400010][30], nxt = 0, N, fa[400010], H; vector<int> bel[400010]; int laster[400010], root[4000010], root_mark[400010]; char rd[200010]; queue<int> qu; int qxx[400010][2], tt[400010], nn; void add(int u, int v) { qxx[++nn][0] = v; qxx[nn][1] = tt[u];...
20
#include <bits/stdc++.h> using namespace std; const int N = 100; int a[N + 1]; void solve() { int n, m; cin >> n >> m; for (int i = 0, k, f; i < m; i++) { cin >> k >> f; a[k] = f; } if (a[n] != 0) { cout << a[n]; return; } vector<int> ans; for (int h = 1; h <= N; h++) { int f = 1; ...
7
#include <bits/stdc++.h> using namespace std; int main(int argc, char *argv[]) { int n, m; vector<int> room_l, room_w, room_h, wp_l, wp_w, price; cin >> n; for (int i = 0; i < n; i++) { int temp; cin >> temp; room_l.push_back(temp); cin >> temp; room_w.push_back(temp); cin >> temp; r...
8
#include <bits/stdc++.h> using namespace std; char str[105]; int reverse(int num) { int ret = 0, i; for (i = 0; i < 8; i++) { ret *= 2; ret += num % 2; num /= 2; } return ret; } int main() { int pre, i, j; while (gets(str)) { pre = 0; for (i = 0; str[i]; i++) { int cur = reverse(st...
5
#include <bits/stdc++.h> using namespace std; int main() { size_t n; cin >> n; n = 2 * n; vector<pair<int, size_t>> inputs(n); vector<int> heaps(n); int distinctSize[3]; distinctSize[1] = 0; distinctSize[2] = 0; for (int i = 0; i < n; i++) { cin >> inputs[i].first; inputs[i].second = i; } ...
11
#include <bits/stdc++.h> using namespace std; int rdn() { int ret = 0; bool fx = 1; char ch = getchar(); while (ch > '9' || ch < '0') { if (ch == '-') fx = 0; ch = getchar(); } while (ch >= '0' && ch <= '9') ret = ret * 10 + ch - '0', ch = getchar(); return fx ? ret : -ret; } const int N = 5005, m...
15
#include <bits/stdc++.h> int main() { std::ios_base::sync_with_stdio(false); int testsNum; std::cin >> testsNum; for (int z = 0; z < testsNum; z++) { int width; int height; std::cin >> width; std::cin >> height; int lampsNum = height * (width / 2); if (width % 2 == 1) { lampsNum +=...
0
#include <bits/stdc++.h> using namespace std; #pragma warning(disable : 4996) double p[21], ans[21], s[1048576], f[1048576]; inline int pc(int x) { int ret = 0; while (x) { ret += x & 1; x >>= 1; } return ret; } int main() { int n, k, cnt = 0; scanf("%d%d", &n, &k); for (int i = 1; i <= n; i++) { ...
16
#include <bits/stdc++.h> using namespace std; long long p, k; long long ans[120]; int cnt = 0; long long get() { long long x = p % k; if (x < 0) x += k; return x % k; } int main() { cin >> p >> k; while (p != 0) { cnt++; ans[cnt] = get(); p -= ans[cnt]; p /= (-k); } cout << cnt << endl; ...
12
#include <bits/stdc++.h> int n, k, h[100000]; int a, b, r[100000]; int main() { scanf("%d%d", &n, &k); for (int i = 0; i < (int)(n); i++) scanf("%d", h + i); std::multiset<int> s; int t = 0; for (int i = 0; i < (int)(n); i++) { s.insert(h[i]); while ((*s.rbegin() - *s.begin()) > k) s.erase(s.find(h[t+...
11
#include <bits/stdc++.h> using namespace std; template <class T> void _R(T &x) { cin >> x; } void _R(int &x) { scanf("%d", &x); } void _R(int64_t &x) { scanf("%lld", &x); } void _R(double &x) { scanf("%lf", &x); } void _R(char &x) { scanf(" %c", &x); } void _R(char *x) { scanf("%s", x); } void R() {} template <class ...
19
#include <bits/stdc++.h> using namespace std; namespace IO { const int IOsize = 1 << 21; void read(){}; void Write(){}; char buf[IOsize], *pa = buf, *pb = buf; char buffer[IOsize]; int p1 = -1; const int p2 = (IOsize)-1; char gc() { return pa == pb && (pb = (pa = buf) + fread(buf, 1, IOsize, stdin), pa == pb) ...
15
#include <bits/stdc++.h> using namespace std; const int INF = 1000000000; const int MOD = 1000000007; const long long INFLL = 1e18; const double PI = 2 * acos(0.0); signed main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, m; cin >> n >> m; deque<int> a(n); for (int i = 0; i < n; i++) cin >...
9
#include <bits/stdc++.h> using namespace std; int main() { int n, m; string s1, s2; cin >> s1 >> s2; n = s1.size(), m = s2.size(); bool f = 0; if (s1 == s2) f = 1; else if (n == m) { int c1, c2; c1 = c2 = 0; for (int i = 0; i < n; i++) if (s1[i] == '1') c1 = 1; for (int i = 0; i ...
7
#include <bits/stdc++.h> const int kLen = 1000005; const int mod = 998244353; char str[kLen]; int sum_left[kLen], sum_right[kLen]; int sum_left_q[kLen], sum_right_q[kLen]; int C[2][kLen]; int pow(int x, int n) { int ans = 1; while (n) { if (n & 1) { ans = 1ll * ans * x % mod; } n >>= 1; x = 1l...
21
#include <bits/stdc++.h> using namespace std; class Solution { public: void solve(int n, vector<vector<int>>& R, vector<int>& P, vector<int>& ord) { P.clear(); ord.clear(); map<pair<int, int>, vector<int>> M; for (int i = 0; i < R.size(); ++i) { int m = R[i].size(); for (int j = 0; j < m;...
16
#include <bits/stdc++.h> using namespace std; template <class T> void chmin(T &t, T f) { if (t > f) t = f; } template <class T> void chmax(T &t, T f) { if (t < f) t = f; } int n, a_pcnt; long long a[10]; int pcnt[10]; void init() {} void input() { cin >> n; for (int i = (0); i < (n); i++) cin >> a[i]; } int rec...
14
#include <bits/stdc++.h> using namespace std; int n, ans, gsub, all = 1; int l[100005], r[100005], sub[100005], inv[100005], c[100005], f[100005], F[100005]; vector<int> v[100005]; int mul(int x, int y) { return (long long)x * y % 1000000007; } int add(int x, int y) { x += y; if (x >= 1000000007) x -= 100000000...
19
#include <bits/stdc++.h> using namespace std; inline int read() { int ret = 0, t = 1; char c = getchar(); while ((c < '0' || c > '9') && c != '-') c = getchar(); if (c == '-') t = -1, c = getchar(); while (c >= '0' && c <= '9') ret = ret * 10 + c - '0', c = getchar(); return ret * t; } const int MAXN = 2002...
12
#include <bits/stdc++.h> using namespace std; template <class T> void _R(T &x) { cin >> x; } void _R(int &x) { scanf("%d", &x); } void _R(long long &x) { scanf("%lld", &x); } void _R(double &x) { scanf("%lf", &x); } void _R(char &x) { scanf(" %c", &x); } void _R(char *x) { scanf("%s", x); } void R() {} template <clas...
3
#include <bits/stdc++.h> using namespace std; int tot, n, i, j, k; int trie[3000011][2], size[3000011]; long long ans; int p[1000011]; void ins(int p, int now, int x) { for (; x; x /= 2) { int o = p / x; if (trie[now][o] == 0) trie[now][o] = ++tot; p %= x; now = trie[now][o]; size[now]++; } } in...
9
#include <bits/stdc++.h> using namespace std; int main() { long long n, i; scanf("%lld", &n); long long sol = 0; for (i = 1; i < n; i <<= 1) { long long block = (n + i - 1) / i; sol += (block / 2) * i; } printf("%lld\n", sol); return 0; }
11
#include <bits/stdc++.h> using namespace std; const int N = 2e6 + 10; long long a[N], b[N], c[N]; using namespace std; void solve() { long long n, m, k; cin >> n >> m >> k; long long l[m + 1], r[m + 1], d[m + 1]; for (int i = 1; i < n + 1; i++) cin >> a[i]; for (int i = 1; i < m + 1; i++) cin >> l[i] >> r[i] ...
6
#include <bits/stdc++.h> using namespace std; int comp(const pair<int, int> &a, const pair<int, int> b) { return a.first < b.first; } int main() { int T; cin >> T; while (T--) { int n, m; cin >> n >> m; vector<pair<int, int> > arr(m); int x, y; for (int i = 0; i < m; i++) { cin >> x >>...
12
#include <bits/stdc++.h> using namespace std; template <class C> void mini(C& _a4, C _b4) { _a4 = min(_a4, _b4); } template <class C> void maxi(C& _a4, C _b4) { _a4 = max(_a4, _b4); } template <class TH> void _dbg(const char* sdbg, TH h) { cerr << sdbg << '=' << h << endl; } template <class TH, class... TA> void ...
8
#include <bits/stdc++.h> using namespace std; unsigned long long int gcd(unsigned long long int a, unsigned long long int b) { return (b != 0) ? gcd(b, a % b) : a; } int main() { unsigned long long int a, b; cin >> a >> b; unsigned long long int x; x = (a * b) / gcd(a, b); if (x / a > (x / b + 1)) print...
7
#include <bits/stdc++.h> using namespace std; int main() { int age, count = 0, n; char buffer[101]; string alc[12] = {"ABSINTH", "BEER", "BRANDY", "CHAMPAGNE", "GIN", "RUM", "SAKE", "TEQUILA", "VODKA", "WHISKEY", "WINE"}; cin >> n; for (int i = 0; i < n; i++) { scanf("%s", buf...
2
#include <bits/stdc++.h> using namespace std; template <class T> void out(vector<T>& a, string s = "%3d ") { int i, n = a.size(); for ((i) = 0; (i) < (n); (i)++) printf(s.c_str(), a[i]); printf("\n"); } string run(string code) { int i, n = code.length(); string ans = ""; for ((i) = 0; (i) < (n); (i)++) { ...
17
#include <bits/stdc++.h> using namespace std; bool Get() { char c; while (c = getchar(), c != '0' && c != '1') ; return c == '1'; } const int V[4][2] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}}; const double Pi = acos(-1); bool Map[2000][2000]; double Factor_0 = 1, Factor_1 = 1; double Dist(double X, double Y) { ret...
11
#include <bits/stdc++.h> using namespace std; long long power(long long x, long long y, long long p) { long long res = 1; x = x % p; while (y > 0) { if (y & 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res; } long long modInverse(long long n) { long long p = 1000000007; return...
8
#include <bits/stdc++.h> using namespace std; int h[100001]; bool cmp(int a, int b) { return h[a] < h[b]; } int main() { int a[100001], l[100001], r[100001], n, q, L, R, ihOrd[100001]; scanf("%d %d", &n, &q); for (int i = 1; i <= n; i++) { scanf("%d", a + i); if (i > 1) { h[i - 1] = abs(a[i] - a[i -...
13
#include <bits/stdc++.h> using namespace std; int n, nums[5005], sorted[5005]; long long dp[5005]; int main() { cin >> n; for (int i = 1; i <= n; i++) { cin >> nums[i]; sorted[i] = nums[i]; } sort(sorted + 1, sorted + n + 1); for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) { dp[j] ...
14
#include <bits/stdc++.h> using namespace std; int main() { int n, ans = 0; cin >> n; pair<int, int> a[n]; for (int i = 0; i < n; i++) cin >> a[i].first >> a[i].second; for (int i = 0; i < n; i++) { int x = a[i].first, y = a[i].second, fl = 0; for (int j = 0; j < n; j++) { if (a[j].first == x && ...
2
#include <bits/stdc++.h> using namespace std; const int maxn = 600000; const int INF = 99999999; int n, q; int a[maxn], pre[maxn], tmp[maxn], ans[maxn]; struct nod { int num, pre; }; struct nod1 { int l, f; }; vector<nod1> v[maxn]; nod seg[maxn * 5]; bool operator<(nod a, nod b) { return a.pre < b.pre; } inline voi...
16
#include <bits/stdc++.h> using namespace std; vector<int> adj[100004]; int n; int sz[100004]; bool dp[5001] = {0}; bool perm[5001] = {0}; map<pair<int, int>, bool> m; void dfs(int x, int p) { sz[x] = 1; int omar = adj[x].size(); for (int i = 0; i < omar; ++i) { if (adj[x][i] == p) continue; dfs(adj[x][i],...
7
#include <bits/stdc++.h> using namespace std; const int LEAF = 1 << 18; int d; int leaf; int g[200002]; int lcp[200001]; long long tmp[200001]; int cnt[200001]; int s_ix[200001]; int p[200001]; int low[200001]; int high[200001]; int a_ix[200001]; int nxt[200001]; int root[200001]; int st[19 * 200001], l[19 * 200001], r...
20
#include <bits/stdc++.h> using namespace std; template <typename T> T gcd(T a, T b) { T c = a, d = b, r; if (a < b) swap(a, b); if (b == 0) return a; do { r = c % d; c = d; d = r; } while (r); return c; } int main() { ios::sync_with_stdio(false); long long n; cin >> n; vector<int> A(n); ...
8
#include <bits/stdc++.h> using namespace std; int main() { int n, ls = 0; bool first = 0, f = 0; cin >> n; int Arr[n]; long long int cnt = 0; for (int i = 0; i < n; i++) cin >> Arr[i]; for (int i = 1; i < n; i++) if (Arr[i] < Arr[i - 1]) cnt = i; cout << cnt; }
6
#include <bits/stdc++.h> using namespace std; const int MOD = 1000000007; int64_t P(int n, int k) { int64_t res = 1; while (k--) { res = res * n-- % MOD; } return res; } int64_t I(int n) { if (n <= 1) return 1; return (I(n - 1) + (n - 1) * I(n - 2) % MOD) % MOD; } int f(int a, int b) { return P(a + b, b...
15
#include <bits/stdc++.h> using namespace std; int a[100010]; int b[100010]; int main() { int n; while (scanf("%d", &n) != EOF) { for (int i = 1; i <= n; i++) scanf("%d", &a[i]); sort(a + 1, a + n + 1); int l = 1, r = 100010; int ans; while (l < r) { int mid = (l + r) / 2; int num = 1...
4
#include <bits/stdc++.h> using namespace std; int n, k; int l[100000], r[100000]; int visited[100000][2]; bool dij() { stack<pair<int, pair<int, int> > > pq; pq.push(make_pair(0, make_pair(0, 0))); pair<int, pair<int, int> > w; while (!pq.empty()) { w = pq.top(); pq.pop(); if (visited[w.first][w.sec...
6
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; for (int i = 1; i <= N; i++) { string x; cin >> x; auto it = x.find('0'); if (it == string::npos) { cout << "cyan\n"; continue; } for (int i = 0; i < x.size(); i++) { if (x[i] == '0') { x....
2
#include <bits/stdc++.h> using namespace std; const int MAXN = 3e4 + 5; const int inf = 0x3f3f3f3f; int a[MAXN]; void solve(void) { int n; scanf("%d", &n); for (int i = 1; i <= n; ++i) scanf("%d", &a[i]); int lst = inf; for (int i = 1; i <= n; ++i) { int x = max(a[i] - lst, a[i - 1]); if (x > a[i]) { ...
10
#include <bits/stdc++.h> using namespace std; struct as { long long t, c; }; struct as a[1000001]; int main() { long long n, maxi, i, t, c, x, time = 0, prev; cin >> n; for (i = 0; i < n; i++) { cin >> t >> c; a[i].t = t; a[i].c = c; } x = a[0].c; maxi = x; prev = a[0].t; for (i = 1; i < n...
3
#include <bits/stdc++.h> using namespace std; template <typename T> void read(T& x) { static char c; static int f; for (c = getchar(), f = 1; c < '0' || c > '9'; c = getchar()) if (c == '-') f = -f; for (x = 0; c >= '0' && c <= '9'; c = getchar()) x = x * 10 + (c & 15); x *= f; } template <typename T> voi...
21
#include <bits/stdc++.h> using namespace std; const long long MOD = 1000000007; long long gcd(long long x, long long y) { if (!y) return x; return gcd(y, x % y); } long long power(long long x, long long y) { long long res = 1ll; x %= MOD; if (x == 0) return 0; while (y > 0) { if (y & 1) res = (res * x) ...
11
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); long long k, sum = 0; string str; cin >> k; cin.ignore(); cin >> str; for (int i = 0; i < str.length(); i++) { sum += str[i] - '0'; } sort(str.begin(), str.end()); long long diff = k - sum; if (sum >= k) { ...
3
#include <bits/stdc++.h> using namespace std; long long dp[13][1 << 13]; int vis[13][13], lca[13][13], dg[13]; int ok[1 << 13]; int n; long long dfs(int rt, int mask) { if (ok[mask] == -1) return 0; mask -= 1 << rt; long long &ans = dp[rt][mask]; if (ans != -1) return ans; if (!mask) return ans = 1; ans = 0...
18
#include <bits/stdc++.h> using namespace std; const int MAX_N = 1500 + 10; int sign(long long a) { return a < 0 ? -1 : a > 0; } struct Point { long long x, y; Point() {} Point(long long _x, long long _y) : x(_x), y(_y) {} Point operator+(const Point& p) const { return Point(x + p.x, y + p.y); } Point operator...
14
#include <bits/stdc++.h> using namespace std; signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long n, m, d; cin >> n >> m >> d; vector<pair<pair<long long, long long>, long long> > f(m); vector<long long> time; long long sum = 0; for (long long i = 0; i < m; i++) ...
13
#include <bits/stdc++.h> using namespace std; void __print(int x) { cerr << x; } void __print(long x) { cerr << x; } void __print(long long x) { cerr << x; } void __print(unsigned x) { cerr << x; } void __print(unsigned long x) { cerr << x; } void __print(unsigned long long x) { cerr << x; } void __print(float x) { cer...
6
#include <bits/stdc++.h> using namespace std; long long int nCr1[1001][1001]; long long int nCr(long long int n, long long int r) { if (nCr1[n][r]) return nCr1[n][r]; if (r == 1) return nCr1[n][r] = n; if (n == r) return nCr1[n][r] = 1; if (r == 0) return nCr1[n][r] = 1; return nCr1[n][r] = (nCr(n - 1, r) + n...
1
#include <bits/stdc++.h> using namespace std; const int MAXN = 100010, MAXA = 2000000; int head[MAXN], nxt[MAXN << 1], to[MAXN << 1], edgeCnt = 1; int prime_factor[MAXA + 1], factors[70], numFactors; int value[MAXN], nodeTime[MAXN], dfs_time = 0; int n, m; vector<pair<int, int> > nodes[MAXA + 1]; int ansDepth[MAXN], an...
13
#include <bits/stdc++.h> using namespace std; map<int, int> chk; int main() { int n; cin >> n; int a[n + 5], mex = 1; for (int i = 1; i <= n; i++) cin >> a[i], chk[a[i]]++; sort(a + 1, a + n + 1); for (int i = 1; i <= n; i++) { if (mex >= a[i]) { if (mex == a[i]) mex++; continue; } c...
4
#include <bits/stdc++.h> using namespace std; struct SAT2 { const int V; vector<vector<int>> G; SAT2(int V) : V(V), G(2 * V) {} int NOT(int x) { return (x < V) ? (x + V) : (x - V); } void add_or(int u, int v) { G[NOT(u)].push_back(v); G[NOT(v)].push_back(u); } void add_implies(int u, int v) { ...
14
#include <bits/stdc++.h> using namespace std; long long int INF = 1e9 + 5; long long int mod = 998244353; long long int n, k; vector<long long int> ans; vector<vector<pair<long long int, long long int>>> g; void _print(long long int t) { cerr << t; } void _print(int t) { cerr << t; } void _print(string t) { cerr << t; ...
11
#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; ...
13
#include <bits/stdc++.h> using namespace std; FILE *in, *out; int main() { int n, a, b; cin >> n >> a >> b; cout << (a + b - 1 + 100 * n) % n + 1; return 0; }
2
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 1e3 + 7; int n; long long T; double a[N], t[N], su, sd; struct node { double x, y; } o[N]; bool cmp1(node a, node b) { return abs(a.y) < abs(b.y); } bool cmp2(node a, node b) { return abs(a.y) > abs(b.y); } double sx, sy; int main() { scanf("%d%lld",...
12
#include <bits/stdc++.h> using namespace std; const long double pi = 3.141592653589793238462643, eps = 1e-12; const unsigned long long mod = 1e9 + 7; const int MAXN = 5010; int fast_pow(int a, int b) { int res = a, ret = 1; while (b > 0) { if (b % 2) ret = (ret * res) % mod; res = (res * res) % mod; b /...
9
#include <bits/stdc++.h> using namespace std; const long long maxn = 1e6 + 5LL; long long n, k; vector<long long> f(maxn); void add(int i) { for (i++; i <= f.size(); i += -i & i) f[i] += 1; } long long sum(int l, int r) { long long result = 0; for (int i = r + 1; i > 0; i &= i - 1) result += f[i]; for (int i = ...
12
#include <bits/stdc++.h> using namespace std; const int MAX = (int)2e5 + 5; int n, m; vector<int> v[MAX]; int h[MAX]; set<int> s[MAX]; set<int> t[MAX]; int dep[MAX]; int xors[MAX]; vector<pair<int, int> > mxx[MAX]; int bio[MAX]; int p[1000]; void dfs(int cx) { if (bio[cx]) return; bio[cx] = 1; for (int i = (0), _...
24
#include<bits/stdc++.h> using namespace std; #define rep(i,a,b) for(int i=(a);i<=(b);++i) #define per(i,a,b) for(int i=(a);i>=(b);--i) #define dbg1(x) cerr<<#x<<"="<<(x)<<" " #define dbg2(x) cerr<<#x<<"="<<(x)<<"\n" const int A=200,B=330,INF=0x3f3f3f3f; void Min(int &x,int y){x=min(x,y);} int n,dp[55][A*2+5][B*2+5]; //...
21
#include <bits/stdc++.h> using namespace std; const int N = 100000, MOD = 1e9 + 7; int n, a[N]; int mul(int a, int b) { return int(((long long)a * (long long)b) % MOD); } int fastPow(int b, int p) { if (p == 0) return 1; if (p == 1) return b; if (p % 2 == 1) return mul(b, fastPow(b, p - 1)); int r = fastPow(b, ...
12
#include <bits/stdc++.h> int b[200] = {0}; int main() { int n, m, i, x, y, z, j; scanf("%d %d", &n, &m); for (i = 0; i < m; i++) { scanf("%d %d %d", &x, &y, &z); int s1 = 0; for (j = 1; j <= n; j++) { if (b[j] <= x) { s1++; } } if (s1 >= y) { int ans = 0; for (j...
5
#include <bits/stdc++.h> using namespace std; const long double eps = 1e-13; const long double PI = acos(-1); const int INF = (int)1e9; const long long INFF = (long long)1e18; const int mod = 998244353; const int MXN = (int)1e6 + 7; inline long long add(long long v1, long long v2) { v1 += v2; if (v1 >= mod) v1 -= m...
9
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); string s; cin >> s; vector<int> open, close; int i, n = s.size(); for (i = 0; i < n; i++) { if (s[i] == '(') open.push_back(i + 1); else close.push_back(i + 1);...
4
#include <bits/stdc++.h> using namespace std; struct BIT { long long tree[2000005]; inline void mem() { memset(tree, 0, sizeof(tree)); return; } inline long long lowbit(long long x) { return x & (-x); } inline void add(long long pos, long long val) { pos++; while (pos <= 200000) tree[pos] += v...
19
#include <bits/stdc++.h> using namespace std; template <class T> inline void RST(T &A, char x = 0) { memset(A, x, sizeof(A)); } template <class T> inline void SRT(T &A) { sort(A.begin(), A.end()); } template <class T, class C> inline void SRT(T &A, C B) { sort(A.begin(), A.end(), B); } const int DX[4] = {1, -1, 0...
18
#include <bits/stdc++.h> using namespace std; pair<int, int> res, k; map<pair<int, int>, pair<int, int> > Mp; int n, L[26], M[26], W[26], l, mx = -(1LL << 30); long long ans = -1, bas = 1; void fDFS(int now, int v, int a, int b, int c) { if (now == 0) { res = make_pair(b - a, c - a); k = make_pair(v, a); ...
15
#include <bits/stdc++.h> using namespace std; struct edge { int dest; int cost; edge(int dest, int cost) : dest{dest}, cost{cost} {} }; struct node { int index; long long dist; node(int index, long long dist) : index{index}, dist{dist} {} }; bool operator>(const node& a, const node& b) { return a.dist > b.d...
15
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1); const double eps = 1e-9; const int inf = 2000000000; const long long infLL = 9000000000000000000; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; int tc; cin >> tc; while (tc--) { long long n, m, k; cin...
2
#include <bits/stdc++.h> using namespace std; int n; vector<int> res; void input() { ios::sync_with_stdio(false); cin.tie(0); cin >> n; } void output() { ios::sync_with_stdio(false); cin.tie(0); for (int i = 0; i < res.size(); ++i) cout << res[i] << ' '; } void solver() { int tmp = 1, tmp2 = 1; while (t...
0
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { if (b == 0) return a; return gcd(b, a % b); } const int N = 1e5; int a[N], curr; int len(int i) { if (i == 0) return 0; return 1 + len(i / 10); } void solve(int x) { int l = 1, r = N - 1, m, d; while (l < r) { m = (l...
11
#include <bits/stdc++.h> std::ifstream fin("input.txt"); std::ofstream fout("output.txt"); int n, value; int x[200005], a[200005], freq[105]; bool foundSolution; void readInput() { std::cin >> n; for (int i = 0; i < n; i++) std::cin >> x[i]; } bool sortCond(std::pair<int, int> a, std::pair<int, int> b) { return a...
18
#include <bits/stdc++.h> using namespace std; vector<int> ant; vector<int> syn; vector<int> ss; int find_set(int i) { int k = i; while (syn[k] != k) { k = syn[k]; } return k; } int union_set(int i, int j) { if (i == -1 and j == -1) { return -1; } if (i == -1 or j == -1) { return i == -1 ? j : ...
12
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; const int INF = 2e9; const long long INF64 = 1e18; const long double EPS = 1e-16; const long double PI = acos(-1); const long long MD = 1551513443; const long long T = 25923; const int N = 100015; const int M = 25; const int DEBUG = 0; const i...
20
#include <bits/stdc++.h> using namespace std; void solve() { int n, m; cin >> n >> m; vector<int> a(n + 1), b(m); long long sum = 0; for (int i = (1); i < (n + 1); i++) { cin >> a[i]; sum += a[i]; } int x; for (int i = (0); i < (m); i++) { cin >> x; b[i] = a[x]; sum -= b[i]; } so...
6
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c; cin >> a >> b >> c; int min; for (int i = 1; i < 101; i++) { int f = abs(a - i) + abs(b - i) + abs(c - i); if (i == 1) { min = f; } else { if (f < min) { min = f; } } } cout << min << endl; }
0
#include <bits/stdc++.h> using namespace std; int a[10000 + 200000], b[200000 + 10000]; int main() { int n; while (scanf("%d", &n) != EOF) { int i, j = 0; for (i = 0; i < n; i++) { int x; scanf("%d", &x); if (x == 0) { continue; } a[j++] = x; } int pos; j = ...
5
#include <bits/stdc++.h> using namespace std; template <class code> inline code read(const code &a) { code x = 0; short w = 0; char ch = 0; while (!isdigit(ch)) { w |= ch == '-'; ch = getchar(); } while (isdigit(ch)) { x = (x << 3) + (x << 1) + (ch ^ 48); ch = getchar(); } return w ? -x ...
7
#include <bits/stdc++.h> using namespace std; int n, k; int a[100009], b[100009], la, lb; long long dp[100009][2], suma, sumb; int o; int main() { scanf("%d%d", &n, &k); for (int j = 1; j <= n; j++) { if (j % 2) scanf("%d", &a[j / 2 + 1]); else scanf("%d", &b[j / 2]); } la = n / 2; if (n %...
14
#include <bits/stdc++.h> using namespace std; int dist(int n, int a, int b) { int res = b - a; return (res < 0 ? res + n : res); } void solve() { int n, m; cin >> n >> m; vector<int> a(m), b(m); for (int i = 0; i < m; i++) { int u, v; cin >> u >> v; a[i] = u - 1, b[i] = v - 1; } int max_deg ...
9
#include <bits/stdc++.h> using namespace std; template <class T> T setBit(T n, T pos) { return n = n | (1 << pos); } template <class T> T clearBit(T n, T pos) { return n = n & ~(1 << pos); } template <class T> bool checkBit(T n, T pos) { return n & (1 << pos); } template <class T> T togleBit(T n, T pos) { retur...
9
/* PRACTICE MAKES PERFECT */ #include<bits/stdc++.h> using namespace std; void __print(int x) {cerr << x;} void __print(long x) {cerr << x;} void __print(long long x) {cerr << x;} void __print(unsigned x) {cerr << x;} void __print(unsigned long x) {cerr << x;} void __print(unsigned long long x) {cerr << x;} void...
2
#include <bits/stdc++.h> using namespace std; long long brk(long long int x) { int d; long long int ans = 0, t = 1; while (x > 0) { d = x % 10; x /= 10; if (d & 1) d = 1; else d = 0; ans += t * d; t *= 2; } return ans; }; long long int md(char c[], int l) { int i; long ...
6
#include <bits/stdc++.h> using namespace std; struct node { int l, r, N[4][4]; }; int d[4][4]; node g[300000]; int F[1000000]; int t, sul, pos, n, q, i, j; void merge(int a, int b) { int i, j, k, p, z, ll, rr, xx, yy; ll = g[a].l; rr = g[a].r; xx = g[b].l; yy = g[b].r; z = a / 2; for (i = 0; i < 4; i++)...
16
#include <bits/stdc++.h> using namespace std; int c, d, n, m, k, tot, ans = 0x7fffffff; int f[10001]; int main() { scanf("%d%d%d%d%d", &c, &d, &n, &m, &k); memset(f, 127, sizeof(f)); tot = n * m; f[0] = 0; for (int i = 1; i <= tot; i++) { if (i >= n) f[i] = f[i - n] + c; f[i] = min(f[i], f[i - 1] + d)...
7
#include <bits/stdc++.h> using namespace std; int readint() { int i, j, s; while (!isdigit(i = getchar()) && i != '-') ; if (i == '-') { s = -1; j = 0; } else { s = 1; j = i - '0'; } while (isdigit(i = getchar())) j = ((j << 1) + (j << 3) + (i - '0')); return j * s; } const char *ops =...
18
#include <bits/stdc++.h> #define ull unsigned long long #define ul unsigned long #define ll long long #define pb push_back #define sodayoda_C ios_base::sync_with_stdio(false);cin.tie(NULL); #define f(i,a,b) for(int i = a;i<b;i++) #define fb(i,a,b) for(int i = a;i>b;i--) #define endl "\n" #define yes cout<<"YES\n" #de...
8
#include <bits/stdc++.h> using namespace std; int n; int main() { scanf("%d", &n); if (n & 1) { for (int i = 0; i < n; i++) { printf("%d ", i); } printf("\n"); for (int i = 0; i < n; i++) { if (n - i - 1 >= i) printf("%d ", n - i - 1 - i); else printf("%d ", (n - i ...
5
#include <bits/stdc++.h> using namespace std; int dp[1 << 25]; int n, m; int a[30][30]; int qi[30][30]; int st[30][30]; char c[30][30]; int lowbit(int x) { return (x & (-x)); } int main() { scanf("%d", &n); scanf("%d", &m); for (int i = 1; i <= n; i++) scanf("%s", c[i] + 1); for (int i = 1; i <= n; i++) for...
17
#include <bits/stdc++.h> using namespace std; struct frog { int x; long long int t; int l, r; }; struct mosquito { int p, b, i; bool operator<(const mosquito& m) const { if (p == m.p) { if (b == m.b) return i < m.i; return b < m.b; } return p < m.p; } }; struct FenWick { int n; v...
17
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long a, b, c, d; cin >> a >> b >> c >> d; if (a != d) { cout << 0 << endl; return 0; } if (c > 0) { if (a == 0 || d == 0) { cout << 0 << endl; return 0...
3
#include <bits/stdc++.h> using namespace std; long long dp[5002][5002], x[5002], a[5002], b[5002], c[5002], d[5002]; int n, S, E; long long big = (1LL << 55); bool vis[5002][5002]; long long dp_func(int pos, int indeg, int outdeg) { if (indeg < 0 || outdeg < 0) return big; if (pos == n + 1) { if (indeg || outde...
17
#include <bits/stdc++.h> using namespace std; int N, T; double qpow(double num, int pow) { if (pow == 1) return num; if (!pow) return 1; double tpow = qpow(num, pow / 2); if (pow & 1) return (tpow * tpow) * num; else return tpow * tpow; } int main() { cin >> N >> T; double ans = N; for (int i = ...
8
#include <bits/stdc++.h> using namespace std; const string file_name = "testcase.D165"; const int INF = 1 << 30; int n, m; int f[1005][1005]; char fig[1005][1005], draw[2][1005][1005]; class Frame { public: void init_val(void) { memset(f, 0, sizeof(f)); memset(fig, 0, sizeof(fig)); memset(draw, 0, sizeof...
18
#include <bits/stdc++.h> using namespace std; struct edge { int v, w; }; vector<edge> g[200001]; int dfn[200001], low[200001], bel[200001], dfc, bcc; int bcs[200001], *bct = bcs; void bcc_clr(int n) { fill(dfn + 1, dfn + n + 1, 0); } int dfs_bcc(int u, int f) { *bct++ = u; dfn[u] = low[u] = ++dfc; for (edge e :...
16
#include <bits/stdc++.h> using namespace std; int main() { int flag = 0, mx, my, mxx2 = -105, mxy2 = -105, mix2 = 121, miy2 = 112; int x, y, mxx1 = -105, mxy1 = -105, mix1 = 121, miy1 = 121; for (int i = 0; i < 4; i++) { cin >> x >> y; mxx1 = max(mxx1, x); mxy1 = max(mxy1, y); mix1 = min(mix1, x);...
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; } int a[35], pre[35][65][1800], cnt[35]...
20