solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> const double PI = acos(-1.0); const int INF = 0x3f3f3f3f; const double eps = 1e-8; const int MAXN = 1e6 + 10; const int MOD = 1e9 + 7; const int dir[][2] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}}; const int seed = 131; int cases = 0; int main() { int n; scanf("%d", &n); int i; for (i = 0; i ...
2
#include <bits/stdc++.h> using namespace std; long long INF = 1e7; long long ans = INT_MIN; long long xx[] = {0, 0, 1, 1, 1, -1, -1, -1}; long long yy[] = {-1, 1, -1, 0, 1, -1, 0, 1}; void solve() { long long n, k; cin >> n >> k; unordered_map<long long, long long> mp; long long temp; for (long long j = 0; j ...
2
#include <bits/stdc++.h> using namespace std; void __print(int x) { cout << x; } void __print(long x) { cout << x; } void __print(long long x) { cout << x; } void __print(unsigned x) { cout << x; } void __print(unsigned long x) { cout << x; } void __print(unsigned long long x) { cout << x; } void __print(float x) { cou...
13
#include <bits/stdc++.h> using namespace std; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long a, b; cin >> a >> b; long long ans = 0; while (1) { if (a == 1 && b == 1) { ans++; break; } long long ct = b / a; ans += ct; long long f = b - ct *...
8
#include <bits/stdc++.h> int main() { unsigned long long n; int status_i = 1; int status = 1; unsigned long long p = 1; int p_start; std::cin >> n; for (int i = 2; i < (int(pow(n, 0.5)) + 1); i++) { if (n % i == 0) { p = i; break; } } p_start = p; if (p == 1) { std::cout << n...
7
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; int main() { ios::sync_with_stdio(false), cin.tie(0); int n, m; cin >> n >> m; vector<vector<vector<int>>> g(n, vector<vector<int>>(10)); for (int i = 1; i <= m; ++i) { int x, y, k, j; cin >> x >> y; --x, --y; string ...
18
#include <bits/stdc++.h> template <class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } const long long MAX = 5100000; const long long INF = 1LL << 60; const long long...
5
#include <bits/stdc++.h> using namespace std; int a, b, c, d, e, i, j, ii, jj, zx, xc, p[10009], ji; pair<int, int> k[109]; int ask(int q, int w) { int qw = 0; cout << "? " << q << " " << w << endl; cin >> qw; return qw; } int fun(int q) { int qw = 0; if (q != k[0].first) { qw = ask(q, k[0].first); } ...
19
#include <bits/stdc++.h> using namespace std; long long solve(long long s, long long x) { vector<long long> xv; vector<long long> sv; while (x) { xv.push_back(x % 2); x /= 2; } while (s) { sv.push_back(s % 2); s /= 2; } long long mSz = max(sv.size(), xv.size()); sv.resize(mSz); xv.resi...
9
#include <bits/stdc++.h> const int N = 155; using namespace std; int n; int m; int l[N]; int r[N]; int last; char c[N][N]; int main() { cin >> n >> m; for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { cin >> c[i][j]; if (c[i][j] == 'W') { if (l[i] == 0) l[i] = j; r[i] = j...
7
#include <bits/stdc++.h> using namespace std; const long long inf = 1e18; const long long mod = 998244353; const long long mx = 3e5 + 5; long long n, r1, r2; vector<long long> adj[mx]; long long par[mx]; bool vis[mx]; void dfs(long long u) { vis[u] = 1; for (long long i = 0; i < adj[u].size(); i++) { long long ...
8
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") using namespace std; const long double eps = 1e-7; const int inf = 1000000010; const long long INF = 10000000000000010LL; const int mod = 1000000007; const int MAXN = 1010, LOG = 20; long long powmod(long long a, long long b) { if (!b) return 1; if (b & 1) retu...
11
#include <bits/stdc++.h> using namespace std; using ll = long long; using pll = pair<ll, ll>; bool cmpx(const pll& a, const pll& b) { return a.first < b.first; } bool cmpy(const pll& a, const pll& b) { return a.second < b.second; } ll sq(const ll& first) { return first * first; } ll dis(const pll& a, const pll& b) { ...
14
#include <bits/stdc++.h> using namespace std; const int N = 1100000; int cj[N], inv[N]; int sum[N]; int power(int x, int y, int mod) { int ret = 1; for (; y; y >>= 1, x = 1ll * x * x % mod) { if (y & 1) ret = 1ll * ret * x % mod; } return ret; } int work(int a, int x, int mod) { int i; for (i = 2; i * i...
14
#include <bits/stdc++.h> using namespace std; long long n, m, a[5005], f[5005][5005], pos; int main() { scanf("%lld%lld", &n, &m); for (long long i = 1; i <= n; i++) scanf("%lld", &a[i]); sort(a + 1, a + 1 + n); for (long long i = 1; i <= m; i++) for (long long j = i; j <= n; j++) { f[j][i] = f[j][i -...
10
#include <bits/stdc++.h> int main(void) { int n; scanf("%d", &n); if (n % 2 == 0) printf("0\n"); else if (n % 2 != 0) printf("1\n"); return 0; }
0
#include <bits/stdc++.h> using namespace std; const int N = 100000; vector<vector<int> > g; int depth[N], cnt[N], up[N][30], tin[N], tout[N]; int lg = 0, timer = 0, n, m, x, y; bool upper(int a, int b) { return tin[a] <= tin[b] && tout[a] >= tout[b]; } int binUp(int a, int b) { for (int i = lg - 1; i >= 0; i--) { ...
13
#include <bits/stdc++.h> using namespace std; int main() { vector<pair<int, int>> columns; int n, l, r, ltot = 0, rtot = 0; pair<int, int> best; cin >> n; for (int i = 0; i != n; ++i) { cin >> l >> r; ltot += l; rtot += r; columns.push_back(make_pair(l, r)); } best = make_pair(0, abs(ltot ...
3
#include <bits/stdc++.h> using namespace std; const double EPS = 1e-6; const int MOD = 1e9 + 7; int a[5000], pref[5001]; int main() { int n, k; scanf("%d%d", &n, &k); pref[0] = 0; for (int i = 0; i < n; i++) { scanf("%d", &a[i]); pref[i + 1] = pref[i] + a[i]; } double mx = 0; for (int i = 0; i < n...
5
#include <bits/stdc++.h> inline int inp() { int x = 0, sign = 1; char c; while (((c = getchar()) < '0' || c > '9') && c != '-') ; if (c == '-') sign = -1, c = getchar(); while (c >= '0' && c <= '9') x = (x << 3) + (x << 1) + c - 48, c = getchar(); return sign * x; } int main() { int n = inp(), a, b, f...
3
#include <bits/stdc++.h> using namespace std; const int MOD = 1000000007; template <class T> typename T::value_type arr_sum(const T& v, int n) { typename T::value_type sum = 0; for (int i = (0); i < (n); ++i) sum += v[i]; return sum; } struct Sync_stdio { Sync_stdio() { cin.tie(NULL); ios_base::sync_wit...
11
#include <bits/stdc++.h> using namespace std; const int MAXN = 100100; const int MAXA = 20; const long double PI = acos(-1.0); int N, M; pair<long long, long long> pt[MAXN]; long double pdist[MAXN]; long double pang[MAXN]; long double hlo[MAXN], hhi[MAXN]; long double nhi[MAXN]; int nnext[2 * MAXN]; long long njump[MAX...
23
#include <bits/stdc++.h> const uint32_t M = 1000000007; class rBIT { std::vector<uint32_t> c; uint32_t& r_sum(uint32_t& i) { s = c[0]; for (; i; i &= i - 1) (s += c[i]) %= M; return s; } public: uint32_t s; rBIT(uint32_t& n) : c(n, 0) { c[0] = 1; } template <typename C> void add(uint32_t i, ...
9
#include <bits/stdc++.h> const int N = 1e6 + 10; const int mod = 998244353; using namespace std; int n, w, k, a[N], r[N], st[N]; long long ans[N]; void work() { int t = 0; for (int i = k; i >= 1; --i) { while (t > 0 && a[i] > a[st[t]]) t--; r[i] = (t == 0 ? w + 1 : st[t]); st[++t] = i; } int now = 1...
14
#include <bits/stdc++.h> using namespace std; double f[100005][110], c[500105][10]; int n, now[100005], num[100005], q, u, v, k, t_n = 0; int main() { double res = 0; scanf("%d", &n); for (register int i = 1; i <= n; i++) scanf("%d", &now[i]), f[i][now[i]] = 1, num[i] = now[i], res += f[i][0]; scanf("%d", &...
18
#include <bits/stdc++.h> using namespace std; int n, k, x[100000][5], len, now; void print(int k1) { printf("%d\n", k1 * k); for (int i = 1; i <= len; i++) { if (x[i][0] == 4) printf("%d %d %d %d\n", x[i][1] * k, x[i][2] * k, x[i][3] * k, x[i][4] * k); } } int gcd(int k1, int k2) { if (k2...
11
#include <bits/stdc++.h> using namespace std; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >> n; priority_queue<pair<int, int>> pq; int ls[n]; int ds[n]; int freq[201]; for (int i = 0; i <= 200; i++) freq[i] = 0; for (int i = 0; i < n; i++) cin >> ls[i]; for (int i = 0; i <...
11
#include <bits/stdc++.h> using namespace std; int sum(int n) { if (n == 0) return 0; return (n % 8 == 1) + sum(n / 8); } int main() { int n; cin >> n; cout << sum(n); return 0; }
13
#include <bits/stdc++.h> using namespace std; const int MAX = 500000; const double PI = 2 * asin(1.0); const long long mod = 1e9 + 7; const double EPS = 1e-10; inline int cmp(double x, double y = 0, double tol = EPS) { return (x <= y + tol) ? (x + tol < y) ? -1 : 0 : 1; } int main() { double n, a, b; cin >> n >> ...
1
#include <bits/stdc++.h> using namespace std; void debug_out() { cerr << endl; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); } double dp[10005][1005]; long long s[1005]; int main() { ios::sync_with_stdio(false); cin.tie(0), cout.ti...
14
#include <bits/stdc++.h> using namespace std; const long long N = 200005; const long double pi = 3.14159265358979323846; int32_t main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long d, h, v, e; cin >> d >> h >> v >> e; long double rate = ((4 * v) / (pi * d * d)) - e; if (rate <= 0) cou...
3
#include <bits/stdc++.h> using namespace std; using namespace std; long long canGo(vector<long long> X, long long L, long long F) { X[0] = X.back() = F; vector<long long> P(X.size()); P[0] = F; for (int i = 1, j = 0; i < X.size(); ++i) { while (i - j > L) j++; while (j < i && X[i]) { long long mn ...
11
#include <bits/stdc++.h> int main() { int n, a, b, ctr = 0; scanf("%d %d %d", &n, &a, &b); for (int i = 1; i <= n; i++) { if (i - 1 <= b && (n - i) >= a) { ctr++; } } printf("%d\n", ctr); return 0; }
2
#include <bits/stdc++.h> using namespace std; vector<pair<int, int> > v, queries; vector<int> adj[1000009]; int val[200009]; int neww, tree[4000009], qvalue[1000009], visited[1000009], endd[1000009], k, p[2000009], n, m, q, present[300009], parent[1000009]; void update(int node, int start, int endd, int ind, int va...
18
#include <bits/stdc++.h> using namespace std; const int mod = (int)1e9 + 7; const int mod2 = 998244353; long long exp(long long taban, long long us, long long md) { long long carpan = taban % md; if (carpan == 0) return 0; long long temp = us; long long res = 1; while (temp) { if (temp % 2) res = (res * c...
4
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10; int f[maxn], t[maxn], in[maxn]; int main() { int n, s; scanf("%d%d", &n, &s); for (int i = 1; i < n; i++) { scanf("%d%d", &f[i], &t[i]); in[f[i]]++; in[t[i]]++; } int cnt = 0; for (int i = 1; i < n; i++) { if (in[f[i]] ...
9
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; string num, num1; cin >> num; num1 = num; if (n == 1 && (num1[0] - '0') % 2 == 0) { cout << "2" << endl; } else if (n == 1 && (num1[0] - '0') % 2 != 0) { cout << "1" <...
1
#include <bits/stdc++.h> using namespace std; long long ar[200001]; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long t, n, k, val, ans, v; cin >> t; while (t--) { cin >> n >> k; for (int i = 0; i < n; i++) cin >> ar[i]; ans = 1000000000; for (int i = 0; i + k < n; i++...
8
#include <bits/stdc++.h> using namespace std; vector<pair<int, int> > v; int max_r = 0; int cal(string ar[], int n, int s) { if (n == 0) { if (s == 0) return v[n].first; else return v[n].second; } int ans1; int ans2; if (s == 0) { int ad = cal(ar, n - 1, 0); if (ad) { ans1 = ...
8
#include <bits/stdc++.h> using namespace std; template <class c> struct rge { c b, e; }; template <class c> rge<c> range(c i, c j) { return rge<c>{i, j}; } template <class c> auto dud(c* x) -> decltype(cerr << *x, 0); template <class c> char dud(...); struct debug { template <class c> debug& operator<<(const c&...
20
#include <bits/stdc++.h> using namespace std; int main() { ifstream myFile("task.in"); if (!myFile.fail()) { assert(freopen("task.in", "r", stdin)); } long long n, s; cin >> n >> s; long long a[n + 10]; for (int i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); int mid = (n / 2); if (s == a[mid]) ...
5
#include <bits/stdc++.h> using namespace std; const int mo = 998244353; const int N = 1001; struct node { int x, y; } p[N * N]; int X, Y, n, m, a[N][N], tot, V; long long f, fs, xs, ys, fsw, xsw, ysw; int getint(); bool cmp(node x, node y) { return a[x.x][x.y] < a[y.x][y.y]; } long long ks(long long t, long long k) {...
15
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int x = 0, n, p = 0, i, j; string s; cin >> s; n = s.length(); for (i = n - 1, j = 0; i >= 0; i--, j++) { if (j % 2 == 0) { x++; } if (s[i] == '1' && i != 0) { p++;...
2
#include <bits/stdc++.h> using namespace std; mt19937_64 mt(time(0)); const int MAXN = 5e5 + 10; struct Item { bool head; int len = 0; int8_t type[2] = {}; int in = 0; int cnt[2] = {}; Item() = default; Item(int h) { head = h; len = 1; type[1 - h] = 1; cnt[1 - h] = 1; } }; string s; Item...
20
#include <bits/stdc++.h> using namespace std; inline bool isPowerOfTwo(int x) { return (x != 0 && (x & (x - 1)) == 0); } double pi = 3.141592653589793238462643; int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1}; int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1}; inline int add(int a, int b, int m = 1000000007) { a += b; if (a >= m) a ...
7
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; const long long mx = 2e5 + 5; vector<long long> prime; long long isPrime[mx]; void seive() { for (long long i = 2; i < mx; ++i) { if (isPrime[i] == 0) { prime.push_back(i); for (long long j = i * i; j < mx; j += i) { ...
3
#include <bits/stdc++.h> using namespace std; int main() { int a, b = 0, c = 0, d, e = 1; cin >> a; while (1) { c = c + ((e * (e + 1)) / 2); if (c <= a) { b++; } else { break; } e++; } cout << b << endl; }
0
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cout.tie(NULL); cin.tie(NULL); long long int n, k, m, i, mincost, j; vector<string> vec; map<string, long long int> mapi; cin >> n >> k >> m; for (i = 0; i < n; i++) { string vecp; cin >> vecp; vec.p...
4
#include <bits/stdc++.h> using namespace std; int f[505]; bool mp[505][505]; int main() { ios::sync_with_stdio(0); int t; cin >> t; while (t--) { int a, b; cin >> a >> b; if (a < b) { if ((b - a) % 2) puts("1"); else puts("2"); } else if (a == b) puts("0"); ...
0
#include <bits/stdc++.h> using namespace std; const int INF = INT_MAX; const long long INFL = LLONG_MAX; int main() { int n, q; cin >> n >> q; int a = 0, b = 1; while (q--) { int t; scanf("%d", &t); if (t == 1) { int x; scanf("%d", &x); a = (a + x); if (a < 0) a += n; i...
10
#include <bits/stdc++.h> using namespace std; struct Edge { int from, next, to; long long w, p, delta; } a[1000005]; int n, cnt, h[1000005], fa[1000005], sum[1000005]; void Addedge(int x, int y, long long w, long long p) { a[++cnt].next = h[x]; a[cnt].from = x; a[cnt].to = y; a[cnt].w = w; a[cnt].p = p; ...
18
#include <bits/stdc++.h> using namespace std; string f0 = "What are you doing at the end of the world? Are you busy? Will you save " "us?"; string q1 = "What are you doing while sending \""; string q2 = "\"? Are you busy? Will you send \""; string q3 = "\"?"; string f1 = q1 + f0 + q2 + f0 + q3; vector<char> ans...
9
#include <bits/stdc++.h> using namespace std; long long l, r, k, x, t; int main() { scanf("%I64d%I64d%I64d", &l, &r, &k); x = 1; for (int i = 1; i <= 1000; i++) { if (x >= l && x <= r) printf("%I64d ", t = x); if (x * k / k == x) x = x * k; else break; } if (t == 0) printf("-1"); }
7
#include <bits/stdc++.h> using namespace std; long long n, m, k; long long v[20]; long long adj[20][20]; long long mem[20][300000]; long long tsp(long long x, long long bm) { if (mem[x][bm] != -1) return mem[x][bm]; long long cmax = 0; for (long long i = 0; i < n; i++) { if (i == x) continue; if (bm & (1 ...
10
#include <bits/stdc++.h> using namespace std; const int N = 2e6 + 5; const int inf = 0x7fffffff; int a[N]; char str[N]; int main() { int n; scanf("%d", &n); while (n--) { queue<int> que0; queue<int> que1; int m; int cnt = 0; scanf("%d", &m); scanf("%s", str); for (int i = (0); i < (m);...
7
#include <bits/stdc++.h> using namespace std; int64_t solve(const vector<pair<int, int>>& fences) { int n = fences.size(); vector<int> by_parity(4, 0); for (int i = 0; i < n; ++i) { by_parity[(fences[i].first & 2) + ((fences[i].second >> 1) & 1)]++; } int64_t ans = 0; for (int i1 = 0; i1 < 4; ++i1) { ...
15
#include <bits/stdc++.h> using namespace std; int main() { int n, k, m; cin >> n >> k >> m; string words[n]; map<string, int> data; int costs[n]; for (int i = 0; i < n; i++) { cin >> words[i]; } for (int i = 0; i < n; i++) { cin >> costs[i]; } for (int i = 0; i < n; i++) { data[words[i]]...
4
#include <bits/stdc++.h> using namespace std; long long f[6]; const int maxn = 1e6 + 5; long long dp[maxn]; vector<int> g; int pw[6] = {1, 10, 100, 1000, 10000, 100000}; int td[10] = {0, 0, 0, 1, 0, 0, 2, 0, 0, 3}; const long long inf = 0x3f3f3f3f3f3f3f3f; int main() { int k; scanf("%d", &k); g.clear(); int num...
21
#include <bits/stdc++.h> using namespace std; int n; vector<vector<int> > g(3001); vector<char> cl(3001); vector<int> p(3001); vector<int> u(3001); vector<int> d(3001); queue<int> q; int cycle_st, cycle_end; bool dfs(int v, int pr) { u[v] = 1; cl[v] = 1; for (size_t i = 0; i < g[v].size(); ++i) { int to = g[v...
8
#include <bits/stdc++.h> using namespace std; bool can[26]; int n, m, k, q, res = 0; char s[31][31]; char ss[1000000]; vector<pair<int, int>> ch[26], sh; inline int dist(int i, int j, int shr, int shc) { return (i - shr) * (i - shr) + (j - shc) * (j - shc); } inline bool check(int i, int j) { for (int w = 0; w < sh...
7
#include <bits/stdc++.h> using namespace std; const long long MOD = 1000000007; int N, M; long long ans; map<int, int> weight; set<int> vvv; set<int> vst; map<int, vector<int>> E; bool has(long long p) { if (vvv.count(p)) return true; long long l = p * 2; long long r = p * 2 + 1; while (true) { if (vvv.uppe...
20
#include <bits/stdc++.h> using namespace std; int main() { int T; unsigned long long int x, y, a, b; cin >> T; while (T--) { unsigned long long int cost1 = 0, cost = 0; cin >> x >> y >> a >> b; cost1 = a * (x + y); if (x == 0 && y == 0) cout << 0 << endl; else { if (x > y) { ...
2
#include <bits/stdc++.h> using namespace std; vector<long long> G[800000]; long long a[800000], pre[800000], suf[800000]; int main() { long long n; cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; pre[i] = pre[i - 1] + (a[i] == 1); } for (int i = n; i >= 2; i--) suf[i] = suf[i + 1] + (a[i] == 2);...
10
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; const unsigned gen_seed = std::chrono::system_clock::now().time_since_epoch().count(); std::mt19937_64 gen(gen_seed); long long v(pair<int, int> &p1, pair<int, int> p2) { return llabs((long long)p1.first - p2.first) + llabs((...
13
#include <bits/stdc++.h> using namespace std; int main() { int n, k; scanf("%d %d", &n, &k); int blocked[2][100005] = {0}; int flag = 0; while (k--) { int x, y; scanf("%d %d", &x, &y); x--; if (blocked[x][y]) { blocked[x][y] = 0; if (blocked[(x + 1) % 2][y - 1]) { flag--; ...
6
#include <bits/stdc++.h> using namespace std; unsigned long long a[20][20]; int main(int argc, char* argv[]) { ios_base::sync_with_stdio(false); unsigned long long n; cin >> n; map<unsigned long long, unsigned long long> v; unsigned long long n2 = n * n; for (unsigned long long i = 0; i < n2; ++i) { uns...
9
#include <bits/stdc++.h> using namespace std; int main() { int a1, b1, a2, b2; scanf("%d%d%d%d", &a1, &b1, &a2, &b2); int valid = 0; if (a1 <= b2 + 1 && b2 <= 2 * (a1 + 1)) valid = 1; if (b1 <= a2 + 1 && a2 <= 2 * (b1 + 1)) valid = 1; if (valid) printf("YES"); else printf("NO"); return 0; }
5
#include <bits/stdc++.h> using namespace std; int a, n, k, i, sum1, sum2; int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n >> k; for (i = 1; i <= n; i++) { cin >> a; sum1 += a; sum2 += min(sum1, 8); if (sum2 >= k) { cout << i << '\n'; return 0; } sum1 -= min(sum1, 8...
1
#include <bits/stdc++.h> using namespace std; long long int bin_expo(long long int x, long long int n, long long int m) { if (n == 0) return 1; else if (n % 2 == 0) return bin_expo((x * x) % m, n / 2, m); else return x * bin_expo((x * x) % m, (n - 1) / 2, m); } void coder99() { ios_base::sync_with_s...
0
#include <bits/stdc++.h> using namespace std; int main() { int a[100]; int n, i, j, Max = 0, Xor = 0; cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; for (i = 0; i < n; i++) { if (a[i] > Max) Max = a[i]; Xor = 0; for (j = i; j < n; j++) { Xor ^= a[j]; if (Xor > Max) Max = Xor; }...
3
#include <bits/stdc++.h> using namespace std; const int maxn = 100010; int A[maxn], B[maxn], C[maxn], id[maxn]; int N, K; pair<int, int> ans[maxn]; int main() { cin >> N >> K; double t = time(0); for (int i = 1; i <= N; i++) scanf("%d%d%d", &A[i], &B[i], &C[i]); srand(970516); for (int T = 1; T <= 4e7 / N; T+...
20
#include <bits/stdc++.h> using namespace std; const long long maxn = 1e5; long long a[6]; long long b[maxn]; pair<long long, long long> help[6 * maxn]; signed main() { ios::sync_with_stdio(false); cin.tie(nullptr); for (long long i = 0; i < 6; ++i) { cin >> a[i]; } sort(a, a + 6); reverse(a, a + 6); l...
11
#include <bits/stdc++.h> using namespace std; const int inf = (int)(1e9); const int mod = inf + 9; const double pi = acos(-1.0); const double eps = 1e-9; long long n, m, k; long long bin(long long a, long long k) { if (k == 0ll) return 1ll; long long res = bin(a, k / 2); res = (res * 1ll * res) % mod; if (k % 2...
8
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false), cin.tie(nullptr); int tt; cin >> tt; while (tt--) { int x; cin >> x; int k = log10(x) + 1; x = x % 10; int ans = (10 * (x - 1)) + (k * (k + 1)) / 2; cout << ans << "\n"; } return 0; }
0
#include <bits/stdc++.h> using namespace std; const double eps = 1e-7; const int inf = 0x3f3f3f3f; const long long linf = 0x3f3f3f3f3f3f3f3fLL; int mat[2005][2005], n; int T[2005], P[2005][20], L[2005]; void pre() { memset(P, -1, sizeof P); for (int i = (0); i < (n); ++i) P[i][0] = T[i]; for (int j = 1; (1 << j) ...
11
#include <bits/stdc++.h> using namespace std; long long getArea(vector<int> &a, vector<int> &b) { long long x = *max_element(a.begin(), a.end()) - *min_element(a.begin(), a.end()) + 1; long long y = *max_element(b.begin(), b.end()) - *min_element(b.begin(), b.end()) + 1; return x * y; } long long Solv...
13
#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--) { string s1, s2, s3; cin >> s1 >> s2 >> s3; int a = 0, b = 0; for (int i = 0; i < s1.size(); i++) { if (s1[i] == s3[i] || s2[i] == s3[i]) b++; ...
0
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; struct hash_pair { template <class T1, class T2> size_t operator()(const pair<T1, T2>& p) const { auto hash1 = hash<T1>{}(p.first); auto hash2 = hash<T2>{}(p.second); return hash1 ^ hash2; } }; unordered_map<pair<int, int>, i...
9
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const long long inf = 3e18 + 5; int add(int a, int b) { return (a += b) < mod ? a : a - mod; } int mul(int a, int b) { return 1LL * a * b % mod; } int sub(int a, int b) { return (a -= b) < 0 ? a + mod : a; } int ctz(int x) { return __builtin_ctz(x);...
14
#include <bits/stdc++.h> const double EPS = 1e-7, PI = acos(-1.0); using namespace std; template <class T> inline T IN(T& num) { num = 0; char c = getchar(), f = 0; while (c != '-' && (c < '0' || c > '9')) c = getchar(); if (c == '-') f = 1, c = getchar(); while ('0' <= c && c <= '9') num = num * 10 + c - '0'...
10
#include <bits/stdc++.h> using namespace std; char s[1000002]; int l, r, n, m, dp[3][21][1000002] = {0}; int main(int argc, char **argv) { std::ios::sync_with_stdio(false); cin >> (s + 1); cin >> m; n = strlen(s + 1); for (int i = 0; i < 21; i++) { for (int j = 1; j + (1 << i) - 1 <= n; j++) { if (i...
12
#include <bits/stdc++.h> using namespace std; long long BigMod(long long B, long long P, long long M) { long long R = 1; while (P > 0) { if (P % 2 == 1) { R = (R * B) % M; } P /= 2; B = (B * B) % M; } return R; } template <class T1> void deb(T1 e1) { cout << e1 << endl; } template <class...
12
#include <bits/stdc++.h> using namespace std; int mod = 1e9 + 7; const int N = 100017; int n, k, A, B; int a[2 * N]; vector<int> v; int get_sum(int l, int r) { int x = lower_bound(v.begin(), v.end(), l) - v.begin(); int y = upper_bound(v.begin(), v.end(), r) - v.begin(); return y - x; } long long rec(int l, int r...
9
#include <bits/stdc++.h> using namespace std; double helen(double a, double b, double c) { double p = (a + b + c) / 2; return sqrt(p * (p - a) * (p - b) * (p - c)); } struct Node { int wei; int dir; } node[208]; string str; int dir; int n; char ch[208]; int get(int pos) { if (node[pos].dir == 2) { return ...
7
#include <bits/stdc++.h> using namespace std; int main() { int n, small = INT_MAX, x, y; cin >> n; int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } if (n == 2) { cout << "1 " << "2" << endl; return 0; } for (int i = 0; i < n; i++) { if (abs(a[i] - a[i + 1]) < small) { ...
0
#include <bits/stdc++.h> using namespace std; int main() { long long n, i, ans = 0, j; cin >> n; vector<long long> v(n), f(n + 1, 0), b(n + 1, 0); for (i = 0; i < n; i++) cin >> v[i]; for (i = 1; i < n + 1; i++) { f[i] = v[i - 1] + f[i - 1]; b[n - i] = v[n - i] + b[n + 1 - i]; } f.erase(f.begin())...
4
#include <bits/stdc++.h> using namespace std; const int N = 203, INF = 1e9; int dp[N][N], a[N]; int dpnw[N]; vector<int> adj[N]; int n, k; void dfs(int u, int par) { dp[u][0] = a[u]; for (int v : adj[u]) { if (v == par) continue; dfs(v, u); dp[u][0] += max(dp[v][k], 0); } for (int v : adj[u]) { ...
14
#include<bits/stdc++.h> using namespace std; int n; queue<int>ji,ou; int main() { int T,x; scanf("%d",&T); while(T--) { scanf("%d",&n); for(int i=1;i<=n;i++) { scanf("%d",&x); if(x&1) ji.push(x); else ou.push(x); } while(!ji.empty()) printf("%d ",ji.front()),ji.pop(); while(!ou.empty()) printf(...
0
#include <bits/stdc++.h> using namespace std; int a[200005]; int p[200005]; int f[200005]; int ptr; int main() { int n, m, s, d; scanf("%d%d%d%d", &n, &m, &s, &d); a[0] = -1; for (int i = 1; i <= n; i++) scanf("%d", &a[i]); sort(a + 1, a + n + 1); for (int i = 1; i <= n; i++) if (a[i] - a[i - 1] - 2 >= ...
8
#include <bits/stdc++.h> using namespace std; template <class T> inline bool Up(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } template <class T> inline bool Down(T &a, const T &b) { if (a > b) { a = b; return true; } return false; } inline int getus() { int tmp, c;...
0
#include <bits/stdc++.h> using namespace std; const int inf = 1e9 + 7; const long long big = inf * 1LL * inf; const int maxn = 1e6; int n, m; string s; int cnt[26][26]; int dp[1 << 21]; int solve(int mask) { if (!mask) return dp[mask] = 0; if (dp[mask] != inf) return dp[mask]; int cntBit = 0; for (int i = 0; i ...
14
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 100; struct node { int p, t; } a[N]; bool operator<(const node &a, const node &b) { return a.p > b.p; } bool cmp(const node &a, const node &b) { if (a.t != b.t) return a.t < b.t; else return a.p < b.p; } set<int> st; priority_queue<node> pq...
15
#include <bits/stdc++.h> int main() { long long r = 1e18, t; scanf("%I64d", &t); long long l = t - (9 * ((r * 9) % t)) % t; printf("%I64d %I64d\n", l, r + l - 1); return 0; }
17
#include <bits/stdc++.h> using namespace std; signed main() { long long t; cin >> t; while (t--) { long long p, q, ans = 0; cin >> p >> q; if (p % q) { cout << p << endl; continue; } vector<pair<long long, long long>> v; for (long long i = 2; i * i <= q; ++i) { if (q % i ...
7
#include <bits/stdc++.h> using namespace std; int main() { vector<pair<char, char>> k(256); k[113] = {'///', 'w'}; k[119] = {'q', 'e'}; k[101] = {'w', 'r'}; k[114] = {'e', 't'}; k[116] = {'r', 'y'}; k[121] = {'t', 'u'}; k[117] = {'y', 'i'}; k[105] = {'u', 'o'}; k[111] = {'i', 'p'}; k[112] = {'o', ...
1
#include <bits/stdc++.h> using namespace std; int main() { long long int x, y; cin >> x >> y; long long int sum = (100 * x) + (10 * y); long long int count = 0; while (sum >= 220) { if (count % 2 == 0) { if (x >= 2 && y >= 2) { x = x - 2; y = y - 2; } else if (x == 1 && y >= 12...
4
#include <bits/stdc++.h> using namespace std; long long a[300005]; int main() { long long n, i, k, sum = 0; cin >> n; for (i = 1; i <= n; i++) cin >> a[i]; sort(a + 1, a + n + 1); for (i = 1; i <= n; i++) { k = abs(a[i] - i); sum += k; } cout << sum << endl; return 0; }
4
#include <bits/stdc++.h> using namespace std; int main() { int b, g, n; cin >> b >> g >> n; int temp = min(b, min(g, n)); int cnt = 0; int s = max(b, g); for (int i = temp; i >= 0; --i) { if (n - i <= s) ++cnt; else break; } cout << cnt; }
3
#include <bits/stdc++.h> using namespace std; const int MAXN = 1000 + 10; int n, sz = 0; int f[MAXN], ch[MAXN][30], danger[MAXN], dp[MAXN][MAXN]; char s[MAXN], t[MAXN]; void insert(char *s, int v) { int now = 0, len = strlen(s); for (int i = 0; i < len; i++) { int c = s[i] - 'a'; if (!ch[now][c]) ch[now][c]...
13
#include <bits/stdc++.h> using namespace std; bool deb_mode = 0; class debugger { vector<string> vars; public: template <typename T> debugger &operator,(const T v) { stringstream ss; ss << v, vars.push_back(ss.str()); return *this; } void printall() { int j = 0, l = vars.size(); for (int...
2