solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 5; int tree[4 * MAXN]; int maxTree[4 * MAXN]; int p[MAXN]; int n; void push(int v) { if (tree[v]) { tree[2 * v] += tree[v]; tree[2 * v + 1] += tree[v]; maxTree[2 * v] += tree[v]; maxTree[2 * v + 1] += tree[v]; tree[v] = 0; } } ...
14
#include <bits/stdc++.h> using namespace std; long long n, k, a[200005]; long long suffix[200005]; set<int> pos; int main() { int i, j; scanf("%lld", &n); scanf("%lld", &k); for (i = 1; i <= n; i++) scanf("%lld", &a[i]); for (i = n; i >= 1; i--) { if (a[i] == 1) { suffix[i]++; if (a[i + 1] == ...
13
#include <bits/stdc++.h> using namespace std; mt19937 mt_rand(chrono::system_clock::now().time_since_epoch().count()); template <typename T1, typename T2> inline bool upmax(T1& a, T2 b) { if (a < b) { a = b; return 1; } return 0; } template <typename T1, typename T2> inline bool upmin(T1& a, T2 b) { if ...
21
#include <bits/stdc++.h> using namespace std; using ll = long long; const int N = 1e5 + 4; const int dx[] = {-1, -1, -1, 0, 1, 1, 1, 0}; const int dy[] = {-1, 0, 1, 1, 1, 0, -1, -1}; map<string, string> maap; vector<int> circle; int vis[N]; int parent[N]; int chk[N]; int color[N]; int tim[2][N]; int dis[N]; int positio...
5
#include <bits/stdc++.h> long long l[15], r[15], ans[15], fn, sn, ft, st, i, j, n, a, res; bool p[15]; int main() { l[1] = 1, r[1] = 3, ans[1] = 0; fn = 1, sn = 2; for (i = 2; i <= 13; i++) { l[i] = r[i - 1] + 1; ft = r[fn] * r[fn] * r[fn] * r[fn]; st = l[sn] * l[sn] - 1; for (j = 0; j <= 13; j++)...
14
#include <bits/stdc++.h> using namespace std; template <typename T> void __read(T &a) { cin >> a; } template <typename T, typename... Args> void __read(T &a, Args &...args) { cin >> a; __read(args...); } constexpr long long M7 = 1000000007ll; constexpr long long M9 = 1000000009ll; constexpr long long MFFT = 99824...
17
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long n, m; cin >> n >> m; vector<long long> v(n); for (long long i = 0; i < n; i++) cin >> v[i]; sort(v.begin(), v.end()); vector<long long> p; if (v[0] != 1) { for (long long i = 1; i ...
4
#include <bits/stdc++.h> char str[1048576]; typedef struct { int start; int end; unsigned hash[3]; unsigned m[3]; unsigned table[3][20]; } sectionhash; int testhash(const unsigned ha[3], const unsigned hb[3], const unsigned hc[3], const unsigned m[3]); inline int testhash(const unsigned ha[3], co...
15
#include <bits/stdc++.h> const int maxn = 100005; int main() { int dp1[maxn], dp2[maxn], str[maxn] = {0}, n, l, r, m, rec[maxn], now; scanf("%d%d", &n, &m); for (int i = 0; i < n; i++) { scanf("%d%d", &l, &r); str[l]++; str[r + 1]--; } for (int i = 2; i <= m; i++) str[i] += str[i - 1]; now = 0; ...
11
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; long long gcd(long long a, long long b) { if (b == 0) return a; return gcd(b, a % b); } long long expo(long long base, long long pow) { long long ans = 1; while (pow != 0) { if (pow & 1 == 1) { ans = ans * base; ans = a...
10
#include <bits/stdc++.h> using namespace std; const double PI = 2 * acos(0.0); struct edge { int from, to; long long w; edge(int from, int to, long long w) : from(from), to(to), w(w) {} edge() {} }; template <class T> void show(const set<T> &a) { for (T x : a) cout << x << " "; cout << endl; } template <cla...
8
#include <bits/stdc++.h> using namespace std; int t; long long a, b; void swap(long long &a, long long &b) { const long long t = a; a = b, b = t; } bool solve(long long a, long long b) { if (a > b) swap(a, b); if (!a) return false; long long x = b / a; bool f = solve(b % a, a); if (!f) return true; if (...
15
#include <bits/stdc++.h> using namespace std; int N, M; vector<vector<int>> parents; vector<vector<int>> children; vector<bool> skip; vector<bool> in_group; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin >> N >> M; parents.resize(N); children.resize(N); skip.resize(N, false); in_group.res...
22
#include <bits/stdc++.h> #pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") using namespace std; template <class T, class S> ostream &operator<<(ostream &o, const pair<T, S> &p) { return o << '(' << p.first << ", " << p.second << ')'; } template <template <class, class...> clas...
1
#include <bits/stdc++.h> using namespace std; mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); const int SZ = 1e5 + 4; const double EPS = 1e-7; const int mod = 1e9 + 7; const int hashpow = 2; const int inf = 2e9; struct custom_hash { static uint64_t splitmix64(uint64_t x) { x += 0x9e3779b97f4a...
12
#include <bits/stdc++.h> using namespace std; int main() { int n, k; vector<int> f, t, a; cin >> n >> k; f.resize(n); t.resize(n); a.resize(n); for (int i = 0; i < n; ++i) { cin >> f[i] >> t[i]; } for (int i = 0; i < n; ++i) { if (t[i] > k) f[i] = f[i] - (t[i] - k); } int max = f[0]; for...
1
#include <bits/stdc++.h> using namespace std; const int max_n = 150005; const long long inf = 0x3f3f3f3f3f3f3f3f; struct LineContainer { static const long long inf = 2e18; static bool modeQ; struct Line { mutable long long a, b, end; long long intersect(const Line& r) const { if (a == r.a) return b ...
19
#include <bits/stdc++.h> using namespace std; string s; long long int calcula(int i1, int i2) { long long int x = 0; int i = i1; while (i <= i2) { long long int y = s[i] - '0'; while (i < i2 and s[i + 1] == '*') { i += 2; y *= s[i] - '0'; } x += y; i += 2; } return x; } long lo...
13
#include <bits/stdc++.h> using namespace std; char **g; int **lx, **rx; int **ly, **ry; int n, m; template <class T> void getarr(T **&a) { a = (T **)malloc((n + 10) * sizeof(T *)); for (int i = 0; i < n + 10; i++) { a[i] = (T *)malloc((m + 10) * sizeof(T)); } } void del(int x, int y) { rx[x][lx[x][y]] = rx[...
15
#include <bits/stdc++.h> using namespace std; long long s, x, a, a1, s1, k, ans; long long st(long long a, long long b) { long long ans = 1; for (int i = 1; i <= b; i++) ans *= a; return ans; } int main() { cin >> s >> x; if ((s - x) % 2 != 0) { cout << 0; return 0; } a = (s - x) / 2; a1 = a; ...
9
#include <bits/stdc++.h> using namespace std; int ip[200000][4]; int main() { int n, k; char str[64]; while (cin >> n >> k) { map<int, int> M; for (int i = 0; i < n; i++) { cin >> str; int t = 0; char* tok = strtok(str, "."); while (tok) { ip[i][t++] = atoi(tok); to...
8
#include <bits/stdc++.h> using namespace std; int n; long long a, b, t, m; long long sum[1000100]; void init() { sum[0] = 0; sum[1] = a; for (long long i = 2; i <= 1000000; i = i + 1LL) sum[i] = sum[i - 1] + a + (i - 1LL) * b; } int main() { long long tmp; scanf("%I64d%I64d%I64d", &a, &b, &n); init(); ...
11
#include <bits/stdc++.h> using namespace std; int main() { int m, n, count; cin >> m >> n; count = (int)m * n / 2; cout << count; return 0; }
0
#include <bits/stdc++.h> using namespace std; int main(int argc, char const *argv[]) { int n, k = 0, l = 0; cin >> n; int ar[n][n]; for (int i = 0; i < n; i++) { char c; cin.ignore(numeric_limits<streamsize>::max(), '\n'); for (int j = 0; j < n; j++) { c = getchar(); if (c == '#') { ...
3
#include <bits/stdc++.h> using namespace std; string s; int main() { cin >> s; for (int i = 1; i < s.size(); i++) if (s[i] == s[i - 1]) for (s[i] = 'a'; s[i] == s[i - 1] || s[i] == s[i + 1]; s[i]++) ; cout << s << endl; }
5
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 10; int n, m; set<int> adj[MAXN]; int per[MAXN]; int main() { ios::sync_with_stdio(0); cin >> n >> m; for (int i = 0; i < m; i++) { int u, v; cin >> u >> v; adj[u].insert(v); adj[v].insert(u); } for (int d = 0; d < 100; d++) ...
16
#include <bits/stdc++.h> #pragma GCC optimize(3) #pragma GCC optimize(2) using namespace std; int n, k, mod; long long dp[1011][111][2], p10[1011]; long long p12[1011]; int main() { int i, j, p; scanf("%d%d%d", &n, &k, &mod); p10[0] = 1 % k; p12[0] = 1; for (i = 1; i <= n; ++i) { p10[i] = (p10[i - 1] * 10...
14
#include <bits/stdc++.h> using namespace std; const int mod = 1000000007; long long n, k, i, j, d[2000005], mb[2000005], pw[2000005]; vector<int> v[2000005]; long long POW(int a, int n) { if (!n) return 1; if (n % 2) return (a * POW(a, n - 1)) % mod; long long res = POW(a, n / 2); return (res * res) % mod; } vo...
15
#include <bits/stdc++.h> using namespace std; const int N = 110; struct Candidates { int votes; int lst; int id; } c[N]; int n, k, m, a, ans[N], rk[N]; int read() { int x = 0, f = 1; char c = getchar(); while (c < '0' || c > '9') { if (c == '-') f = -1; c = getchar(); } while (c >= '0' && c <= '...
13
#include <bits/stdc++.h> using namespace std; const long long mos = 0x7FFFFFFFLL; const long long nmos = 0x80000000LL; const int inf = 0x3f3f3f3f; const long long inff = 0x3f3f3f3f3f3f3f3fLL; const double PI = acos(-1.0); template <typename T> inline T read(T& x) { x = 0; int f = 0; char ch = getchar(); while (...
12
#include <bits/stdc++.h> using namespace std; bool ok(int x) { int vis[10]; memset(vis, 0, sizeof(vis)); while (x) { if (vis[x % 10]) return false; vis[x % 10] = 1; x /= 10; } return true; } int main() { ios::sync_with_stdio(0); int L, R; cin >> L >> R; for (int i = L; i <= R; i++) { i...
0
#include <bits/stdc++.h> using namespace std; const int N = 406; int a[N][N]; int num[N][N][8]; int dx[] = {-1, 0, 1, 0, -1, 1, 1, -1}; int dy[] = {0, 1, 0, -1, 1, 1, -1, -1}; int n, m; int go(int i, int j, int k) { int& ret = num[i][j][k]; if (ret >= 0) return ret; if (a[i][j]) return ret = 0; int ii = i + dx[...
12
#include <bits/stdc++.h> using namespace std; const int N = (int)6005, mod = (int)1e9 + 7; int len; int seg[N << 2], mx[N << 2], sum[N << 2], ch[N << 2], px[N], py[N], pc[N], o[N], sx[N], sy[N], sc[N]; set<pair<int, int>> col[N]; vector<int> allx, ally; int get_pos(int first) { return lower_bound((ally).begin(), ...
25
#include <bits/stdc++.h> using namespace std; template <class T> void debug(T a, T b) { ; } template <class T> void chmin(T& a, const T& b) { if (a > b) a = b; } template <class T> void chmax(T& a, const T& b) { if (a < b) a = b; } namespace std { template <class S, class T> ostream& operator<<(ostream& out, cons...
18
#include <bits/stdc++.h> using namespace std; int N; string H; int q = 0; vector<string> ask(int L, int R) { vector<string> V; cout << "? " << L << " " << R << endl; int len = R - L + 1; int i; if (H.size()) { for (int l = L; l <= R; l++) for (int r = l; r <= R; r++) V.push_back(H.substr(l - 1, r - ...
16
#include <bits/stdc++.h> using namespace std; const int maxn = 1000 + 12; bool games[maxn][maxn]; int n, k; vector<pair<int, int> > ans; int main() { scanf("%d%d", &n, &k); memset(games, 0, sizeof(games)); for (int i = 1; i <= n; ++i) { int tok = k; for (int j = 1; j <= n && tok > 0; ++j) if (j != i...
6
#include <bits/stdc++.h> using namespace std; template <typename T> void read(T &a) { T 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 << 1) + (x << 3) + (ch ^ 48); ch = getchar(); } a = x *...
16
#include <bits/stdc++.h> using namespace std; template <typename t> t in(t q) { cin >> q; return q; } template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) { os << "["; for (int i = 0; i < ((int)size(v)); ++i) { os << v[i]; if (i != ((int)size(v)) - 1) os << ","; } os << "]"; ...
11
#include <bits/stdc++.h> using namespace std; char s[1000005]; long long v[100005]; int main() { cin.sync_with_stdio(false); int maax = 0, n; long long sol = 0; cin >> s; n = strlen(s); for (int i = 0; i < n; i++) { v[s[i]]++; } for (int i = 0; i < 1000; i++) sol += v[i] * v[i]; cout << sol; ret...
7
#include <bits/stdc++.h> #pragma GCC optimize("O2") using namespace std; const int N = 2e5 + 10; const long long mod = 1e9 + 7; const long long mod2 = 998244353; const long long inf = 1e18; const int LOG = 22; long long pw(long long a, long long b, long long M) { return (!b ? 1 : (b & 1 ? (a * pw(a * a %...
16
#include <bits/stdc++.h> using namespace std; int n; int main() { ios_base::sync_with_stdio(0); cin >> n; int a[1001]; for (int i = 0; i < n; i++) { cin >> a[i]; } int not_done = n, turns = 0, info = 0; vector<int> seen(n, 0); while (not_done > 0) { for (int d = 1; d >= -1; d--) { if (!d) ...
4
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; long long t = n / 3; if (n == 1) cout << 1 << endl; else if (n % 3 == 0) cout << 2 * t << endl; else cout << (2 * t) + 1 << endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; vector<long long> vc; int main() { long long n, k, s, i, j, hi, d, cur, m; scanf("%lld", &n); scanf("%lld", &k); scanf("%lld", &s); m = k; hi = (n - 1) * k; if (k > s || hi < s) { printf("NO\n"); return 0; } cur = 1; cout << "YES" << endl; for ...
8
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 9; long long bin(long long x, long long y) { long long r = 1; while (y) { if (y & 1) r = (r * x) % mod; x = (x * x) % mod; y >>= 1; } return r; } int main() { long long n, m; cin >> n >> m; long long x = bin(2LL, m); x...
5
#include <bits/stdc++.h> #pragma GCC optimize("O3") 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> ...
24
#include <bits/stdc++.h> using namespace std; int main() { int r, d; cin >> r >> d; int n; cin >> n; int innerr = r - d; int a, b, r1; int cont = 0; for (int i = 0; i < n; i++) { cin >> a >> b >> r1; double dor = sqrt(a * a + b * b); if ((dor == r || dor == innerr) && r1 == 0) { cont++...
3
#include <bits/stdc++.h> using namespace std; const int N = 400100; struct edge { int next, to; edge(int next = 0, int to = 0) : next(next), to(to) {} } e[N << 1]; bool mark[N << 1], vis[N]; int pa[N], head[N], n, m, cnt, top, tot = 1; int dfn[N], low[N], sta[N], bel[N], size[N], nm, sym[N]; inline void in(int &x) ...
15
#include <bits/stdc++.h> using namespace std; const long long MOD = 1000 * 1000 * 1000 + 7; const long long INF = 1ll * 1000 * 1000 * 1000 * 1000 * 1000 * 1000 + 7; const long long MOD2 = 998244353; const long long N = 1000 * 100 + 10; const long long N2 = 70; const long double PI = 3.141592653589793; long long gcd(lon...
8
#include <bits/stdc++.h> using namespace std; const int N = 105; int n, ans = 0; char s[N]; int bj[N]; int work(int x) { int sum = 0; for (int i = 1; i <= n; i++) { if (bj[i]) continue; if (s[i] == 'a' + x) { for (int j = i - 1; j >= 1; j--) { if (!bj[j]) { if (s[j] == 'a' + x - 1) s...
8
#include <bits/stdc++.h> using namespace std; long long s, ans, f[60][120][2]; bool check(long long num, int o) { int cnt = 0; while (num) cnt += (num & 1), num >>= 1; return cnt == o; } void dp(int l, int r, int k, long long num) { for (int i = 0; (1ll << i) <= num << 1; ++i) for (int j = 0; j <= min(k + 2...
24
#include <bits/stdc++.h> using namespace std; int quick_pow(int a, int b, int MOD) { a %= MOD; int res = 1; while (b) { if (b & 1) res = (res * a) % MOD; b /= 2; a = (a * a) % MOD; } return res; } const int maxn = 300000 + 10; const int MOD = 1e9 + 7; int L[maxn], R[maxn], l[maxn], r[maxn]; vector...
13
#include <bits/stdc++.h> using std::cerr; using std::cin; using std::cout; using std::endl; using std::pair; using std::string; using std::tuple; using std::vector; int64_t ReadData(); vector<size_t> Solution(int64_t data); void WriteAnswer(const vector<size_t>& answer); void WriteError(); int main() { std::ios_base:...
11
#include <iostream> #include <cstdio> #include <cstdlib> #include <algorithm> #include <string> #include <sstream> #include <cstring> #include <cctype> #include <cmath> #include <vector> #include <set> #include <map> #include <stack> #include <queue> #include <ctime> #include <cassert> #define _for(i,a,b) for(int i=(a)...
24
#include <bits/stdc++.h> using namespace std; const int N = 1100000; int n, a[N], b[N]; struct node { int to; int u, v; node() {} node(int x, int y, int z) : to(x), u(y), v(z) {} }; int fir[N]; vector<node> e[N]; vector<int> rev[N], print; vector<bool> vis[N]; void dfs(int from) { for (int &i = fir[from]; i <...
17
#include <bits/stdc++.h> using namespace std; int main() { char m[9][9]; char ha; int h = 0, k = 0; while (h < 9) { cin >> ha; if ((ha == '.') || (ha == 'x') || (ha == 'o')) { m[h][k] = ha; k++; if (k == 9) { k = 0; h++; } } } int x, y; cin >> x >> y; ...
6
#include <bits/stdc++.h> using namespace std; long long int mod = 1000000007; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long int n, k, seg[202] = {0}; cin >> n >> k; pair<long long int, long long int> a[n]; for (long long int i = 0; i < n; i++) { cin >> a[i...
10
#include <bits/stdc++.h> using namespace std; int n; int main() { long long a, b, s = 1; cin >> a >> b; long long ans = b - a; if (ans > 5) return puts("0"), 0; for (int i = 0; i < ans; ++i) { long long t = b; t = b % 10; s *= t; b--; } cout << s % 10; return 0; }
3
#include <bits/stdc++.h> using namespace std; int main() { int i, k, l, n, m, a, b, c; scanf("%d", &n); while (n--) { string st; cin >> st; int arr[4]; a = b = c = 0; m = st.size(); for (i = 0; i < m; i++) { if (st[i] >= 'a' && st[i] <= 'z') a++; else if (st[i] >= 'A' &...
4
#include <bits/stdc++.h> using namespace std; const double PI = 3.1415926535897932384626433832795; struct frnd { char g; int x; int y; }; int l[100005]; int main() { int n; while (cin >> n) { int avg = 0; for (int i = 0; i < n; i++) { cin >> l[i]; avg += l[i]; } sort(l, l + n); ...
3
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1.0); const int inf = (int)1e9; const double eps = 1e-7; const int ss = (int)1e6 + 3; const int base = inf; bool pred1(const pair<int, int>& i, const pair<int, int>& j) { if (i.first == j.first) return i.second > j.second; else return i.f...
15
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; if (n % 2) cout << "Ehab"; else cout << "Mahmoud"; return 0; }
0
#include <bits/stdc++.h> using namespace std; const bool debug = false; const int maxn = 1e5 + 7; const int inf = 1e9 + 7; const long long mod = 1e9 + 7; int pre[maxn]; long long bp(long long a, long long p) { if (p == 0) return 1; if (p % 2) { return (bp(a, p - 1) * a) % mod; } else { long long re = bp(a...
8
#include <bits/stdc++.h> using namespace std; int n; int a[120][5]; int cur_maxpoint[5]; int nb_solved[5]; int optimal_config[5]; int idx_to_maxpoint[6]; int new_nb_solved[5]; int new_maxpoint[5]; int finalRs = 2000000000; int calculate_score(int idx, int* maxpoints) { int rs = 0; for (int j = 0; j < 5; j++) { ...
12
#include <bits/stdc++.h> using namespace std; const long long MAX_LL = (1LL << 63) - 1LL; long long get_max_ll(long long x) { long long tmp = MAX_LL; long long res = 1; while (tmp / x >= res) res *= x; return res; } int main() { long long t, a, b; cin >> t >> a >> b; if (a == 1) { if (t == 1) { ...
20
#include <bits/stdc++.h> using namespace std; const int MOD = (int)1e6 + 3; int mul(int a, int b) { return (long long)a * b % MOD; } int sub(int a, int b) { a -= b; if (a < 0) a += MOD; return a; } int bin_pow(int a, int b) { int res = 1; while (b > 0) { if (b % 2 == 1) res = mul(res, a); a = mul(a, a...
10
#include <bits/stdc++.h> using namespace std; int main() { long long n, k, num, digit, luckydigits = 0, cnt = 0; cin >> n >> k; long long arr[n]; for (int i = 0; i < n; i++) { cin >> arr[i]; num = arr[i]; while (num != 0) { digit = num % 10; num /= 10; if (digit == 4 || digit == 7)...
0
#include <bits/stdc++.h> const int inf = 0x3f3f3f3f; using namespace std; int main() { int n; int a[365]; int sum[365]; while (scanf("%d", &n) != EOF) { int i, j, k; for (i = 1; i <= n; i++) scanf("%d", &a[i]); int s; int m1, m2; k = 1; int flag; for (i = 1; i <= n; i++) { s = ...
4
#include <bits/stdc++.h> using std::map; int n, m, l, a[1000009]; long long ans, c[1000009]; map<int, int> s, t; long long sum(int k) { long long sum = 0; for (int i = k; i; i -= i & -i) sum += c[i]; return sum; } void add(int k) { for (int i = k; i <= n; i += i & -i) ++c[i]; } int main() { scanf("%d", &n); ...
10
#include <bits/stdc++.h> using namespace std; const int N = 800040; int e[N], ne[N], h[N], idx, n, root = 1, ans = 0x3f3f3f3f; int d[N][2], f[N], vis[N], size[N], sum, pos[N]; void add(int a, int b) { e[idx] = b, ne[idx] = h[a], h[a] = idx++; } int dfs1(int u) { vis[u] = 1; int res = 0, sum = 1; for (int i = h[u]...
15
#include <bits/stdc++.h> using namespace std; long long A[100005], f[100005], d[100005]; int main() { long long n; cin >> n; f[0] = 0; for (long long i = 0; i < n; i++) { cin >> A[i]; if (i) { d[i - 1] = abs(A[i] - A[i - 1]); if (i % 2) f[i] = f[i - 1] + d[i - 1]; else ...
8
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; long long int n = s.length(); long long int *a = new long long int[n]; long long int i, j; long long int curr = 0; for (i = 0; i < n; i++) { a[i] = s[i] - '0'; curr += a[i]; } long long int ans = 0; long long int ...
5
#include <bits/stdc++.h> #pragma comment(linker, "/stack:640000000") using namespace std; const double EPS = 1e-9; const int INF = 0x7f7f7f7f; const double PI = acos(-1.0); template <class T> inline T gcd(T a, T b) { return (b) == 0 ? (a) : gcd((b), ((a) % (b))); } template <class T> inline T lcm(T a, T b) { return...
9
#include <bits/stdc++.h> using namespace std; const int N = 200005; int a[N]; int f[N]; int n; void add(int x, int val) { for (; x <= n; x += x & (-x)) { f[x] += val; } } int query(int x) { int sum = 0; for (; x >= 1; x -= x & (-x)) { sum += f[x]; } return sum; } int main() { ios::sync_with_stdio(...
11
#include <bits/stdc++.h> using namespace std; long long cal(string x) { int ndig = x.length(); if (ndig == 1) return atoll(x.c_str()); long long sol = 0; if (x[0] == x[ndig - 1]) { string xx = x; xx.pop_back(); xx.erase(xx.begin()); if (xx == "") { int f = x[0] - 48; sol += f; } ...
7
#include <bits/stdc++.h> using namespace std; const int N = 100001; int n; vector<int> adjList[N]; int deg[N]; bool failed; vector<pair<int, int> > ans; void dfs(int node, int p, int root) { bool leaf = true; for (int ch : adjList[node]) { if (ch == p) continue; leaf = false; dfs(ch, node, root); } ...
6
#include <bits/stdc++.h> const int N = 1e5 + 10, wyp = 998244353; int n, len; struct z { int32_t x; z(int32_t x = 0) : x(x) {} friend inline z operator*(z a, z b) { return (int64_t)a.x * b.x % wyp; } friend inline z operator-(z a, z b) { return (a.x -= b.x) < 0 ? a.x + wyp : a.x; } friend inline z opera...
23
#include <bits/stdc++.h> using namespace std; const int N = 100005; int t[4 * N]; int m[4 * N]; int d[4 * N]; void upd(int v, int x) { m[v] += x; d[v] += x; } void pull(int v) { m[v] = min(m[2 * v + 1], m[2 * v + 2]); t[v] = (m[2 * v + 1] == m[v] ? t[2 * v + 1] : 0) + (m[2 * v + 2] == m[v] ? t[2 * v + ...
16
#include <bits/stdc++.h> using namespace std; const double eps = 1e-10; const int inf = 1 << 28; int in() { int x; scanf("%d", &x); return x; } long long In() { long long x; cin >> x; return x; } double inreal() { double x; scanf("%lf", &x); return x; } string instr() { char buf[1001]; scanf("%s",...
1
#include <bits/stdc++.h> using namespace std; int n, m, f; void dfs(vector<string> &v, vector<vector<bool> > &vstd, int a, int b) { vstd[a][b] = true; char c = v[a].at(b); int z = 0; if (a - 1 >= 0 && vstd[a - 1][b] && v[a - 1].at(b) == c) z++; if (b - 1 >= 0 && vstd[a][b - 1] && v[a].at(b - 1) == c) z++; i...
7
#include <bits/stdc++.h> using namespace std; map<int, int> mp; int q, n, s; int main() { scanf("%d", &q); while (q--) { scanf("%d", &n); mp.clear(); for (int i = 1; i <= n; i++) { scanf("%d", &s); mp[s]++; } for (int i = 1; i <= 2048; i <<= 1) { if (mp[i] >= 2) { mp[i ...
2
#include <bits/stdc++.h> using namespace std; int n; int all[1000008]; int li[1000008], ri[1000008]; int id[1000008]; int vis[1000008]; int main() { scanf("%d", &n); while (~scanf("%d", &n)) { for (int i = 1; i <= n; i++) li[i] = 1e9, ri[i] = 0, id[i] = 0, vis[i] = 0; int num = 0; vector<int> kl; fo...
12
#include <bits/stdc++.h> using namespace std; int arr[100010 + 1], dp[100010 + 1]; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; long long s = 0LL, f = 0LL, sol = 0LL; cin >> n; for (int i = 0; i < n; i++) { cin >> arr[i]; s += arr[i]; } if (s % 3 != 0) { cout <...
4
#include <bits/stdc++.h> using namespace std; int n; long long k; long long fib[100]; int main() { scanf("%d%I64d", &n, &k); fib[0] = 1; fib[1] = 1; for (int i = 2; i <= 84; i++) fib[i] = fib[i - 1] + fib[i - 2]; for (int i = 1; i <= n; i++) { if (k <= fib[n - i]) printf("%d ", i); else { ...
11
#include <bits/stdc++.h> using namespace std; const int MAXN = 2500 + 5; long long sumv[MAXN + 5][MAXN + 5]; long long f[MAXN + 5][MAXN + 5]; int N, M, Q; int lowbit(int x) { return x & (-x); } void Add(int a, int b, long long v) { int tot = a; while (tot <= N) { int cnt = b; while (cnt <= M) sumv[tot][cnt]...
16
#include <bits/stdc++.h> using namespace std; template <class T> T max(T a, T b, T c) { return max(a, max(b, c)); } int32_t main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); long long a, b, c, d, e; cin >> a >> b >> c >> d >> e; long long sum = a + b + c + d + e; if (sum == 0) {...
3
#include <bits/stdc++.h> using namespace std; const int oo = 0x7fffffff; const long long OO = 0x7fffffffffffffff; const int NX = 1123; const long long MOD = 998244353; long long dp[NX], arr[NX], bin[NX][NX]; int main() { ios_base::sync_with_stdio(false); for (int i = 0; i < NX; i++) { bin[i][i] = bin[i][0] = 1;...
11
#include <bits/stdc++.h> using namespace std; int main() { int n, k, t; cin >> n >> k >> t; int z = t * n * k / 100; if (z / k < n) { for (int i = 0; i < z / k; i++) cout << k << " "; cout << z - (z / k) * k << " "; int j = z / k + 1; while (j < n) { cout << 0 << " "; j++; } } ...
5
#include <bits/stdc++.h> using namespace std; char a[8][8]; int per[] = {1, 2, 3, 4, 5, 6, 7, 8}; int main() { int n, k; int ans = 1000000000; scanf("%d", &n); scanf("%d ", &k); for (int i = 0; i < n; i++) gets(a[i]); int max, min; do { max = -1; min = 1000000000; for (int j = 0; j < n; j++) {...
6
#include <bits/stdc++.h> using namespace std; const int maxn = 110, maxl = 60, maxm = 17, maxx = 1 << maxm; int a[maxn], dp[maxn][maxx], fact[maxn], par[maxn][maxx]; int pr[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59}; int main() { for (int i = 1; i < maxl; i++) for (int j = 0; j < maxm; j...
12
#include <bits/stdc++.h> int cmpfunc(const void* a, const void* b) { return (*(int*)a - *(int*)b); } int main() { int i, n, j, t, m, k, l, max, c1 = 0, c2 = 0, c3 = 0, c4 = 0, c5 = 0; scanf("%d", &n); char st[n][20]; for (i = 0; i < n; i++) { scanf("%s", st[i]); if (strcasecmp("Tetrahedron", st[i]) == 0...
0
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; vector<int> v; for (int i = 1; i < n; i *= 2) { v.push_back(i); n -= i; } if (n > 0) { v.push_back(n); sort(v.begin(), v.end()); } cout << v.size() - 1...
11
#include <bits/stdc++.h> #pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math,inline") #pragma GCC target( \ "sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native") using namespace std; template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep; ...
27
#include <bits/stdc++.h> using namespace std; long long read() { long long f = 1, x = 0; char s = getchar(); while (s < '0' || s > '9') { if (s == '-') f = -1; s = getchar(); } while (s >= '0' && s <= '9') { x = x * 10 + s - '0'; s = getchar(); } return x * f; } struct Edge { int u, v; ...
18
#include <bits/stdc++.h> using namespace std; const long long MOD = 1000000007; long long dp[100005], ans; int v[100005]; vector<int> divs[100005]; void FindDivs(int ind) { for (int i = 1; i * i <= v[ind]; i++) if (v[ind] % i == 0) { divs[ind].push_back(i); if (i != v[ind] / i) divs[ind].push_back(v[i...
9
#include <bits/stdc++.h> using namespace std; double const EPS = 1.0E-9; int const MOD = (int)1e9 + 7; inline void read(int &x) { scanf("%d", &(x)); } inline void read(long long &x) { scanf("%lld", &x); } inline void read(double &x) { scanf("%lf", &x); } inline long long gcd(long long x, long long y) { return y == 0 ...
4
#include <bits/stdc++.h> using namespace std; namespace mainns { class Solver208B { public: void run(); }; void Solver208B::run() { size_t nCards; cin >> nCards; string cards = "xxxx"; for (size_t i = 0; i < nCards; ++i) { string card; cin >> card; cards.append(card); } nCards += 2; unorder...
11
#include <bits/stdc++.h> using namespace std; FILE *in; FILE *out; const int MAX = 128; int n; char a[MAX][MAX]; int main(void) { in = stdin; out = stdout; int n; fscanf(in, "%d", &n); for (int i = 0; i < n; i++) fscanf(in, "%s", a[i]); map<int, int> q; for (int i = 0; i < n; i++) { for (int c = 0; c ...
7
#include <bits/stdc++.h> using namespace std; bool dfs(int cur, int edge, vector<vector<pair<int, int> > > &g, set<int> &edges, vector<int> &p, vector<bool> &visited) { visited[cur] = true; int cur_p = p[cur]; for (int i = 0; i < g[cur].size(); i++) { int next = g[cur][i].first, next_p = g[cur][i].se...
13
#include <bits/stdc++.h> const int inf = 1e9; using namespace std; int low[15], disc[15], r[15]; pair<int, int> p[15]; vector<int> g[15]; vector<pair<int, int>> cur, ans(225); int u; mt19937 ran(time(0)); void scc(int nod, int t) { r[nod] = low[nod] = disc[nod] = ++u; shuffle(g[nod].begin(), g[nod].end(), ran); f...
20
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int a, b, cnt = 0; cin >> a >> b; if (a < b) { if ((b - a) % 2) cnt = 1; else cnt = 2; } else if (a > b) { if ((a - b) % 2 == 0) cnt = 1; else cnt = 2; ...
0