func_code_string stringlengths 59 71.4k |
|---|
#include <bits/stdc++.h> using namespace std; const long long MAX = (long long)1e6 + 100; long long inf = (long long)1e18; long long mod = (long long)1e9 + 7; long long n, a, b, c, d; long long get_maxi() { long long uk1 = 0, uk2 = c + 1; while (uk2 - uk1 > 1) { long long mid = (uk2 + uk1) / 2... |
#include <bits/stdc++.h> using namespace std; int main() { long long n, k, h, i, a, d, p; cin >> n >> k; d = k; p = k; a = n; while (a % 2 == 0 && d > 0) { a = a / 2; d--; } while (a % 5 == 0 && p > 0) { a = a / 5; p--; } while (d > 0) { n *= 2; ... |
#include <bits/stdc++.h> using namespace std; int a[150]; int b[150]; int n, k; string s; bool ok[400005], dem = -1; int main() { cin.tie(NULL); cin >> n >> k; cin.ignore(); cin >> s; for (int i = 1; i <= 50; i++) a[i] = 0; for (int i = 0; i < n; i++) { a[int(s[i]) - 96]++; ... |
#include <bits/stdc++.h> using namespace std; namespace io { const int SI = 1 << 21 | 1; char IB[SI], *IS, *IT, OB[SI], *OS = OB, *OT = OS + SI - 1, c, ch[100]; int f, t; inline void flush() { fwrite(OB, 1, OS - OB, stdout), OS = OB; } inline void pc(char x) { *OS++ = x; if (OS == OT) flush(); }... |
#include <bits/stdc++.h> using namespace std; int main() { int flag1 = 0, flag2 = 0, j = 0, k = 0, ma = 0, end = 0; int a[5], b[5], i; vector<int> ans; string s; cin >> s; int lenth = s.size(); for (i = 0; s[i] != : ; i++) { if (flag1 == 0) { if (s[i] != 0 ) { f... |
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int cnt = 0; int val; int min = 1000; int evesum = 0, total = 0, oddsum = 0; for (int i = 0; i < n; i++) { cin >> val; if (val % 2 == 0) { evesum += val; } else { oddsum += val; ... |
#include <bits/stdc++.h> using namespace std; const long long N = 200005; const long long M = 1000000007; long long n, d; string s, t1, t2, t; long long rt = 1, tot = 1, ch[15][N], ed[N], fail[N]; void insert(string x) { long long len = x.length(), now = rt; for (long long i = 0; i < len; i++) { ... |
#include <bits/stdc++.h> using namespace std; map<pair<int, int>, int> cnt; map<char, int> id; vector<pair<char, char> > v; map<pair<char, char>, bool> vis; map<char, int> counter; int main() { id[ R ] = 4; id[ G ] = 3; id[ B ] = 2; id[ Y ] = 1; id[ W ] = 0; id[ 1 ] = 9; id[ 2 ... |
#include <bits/stdc++.h> using namespace std; const int mod = 1000000007; long long fac[2005], c[2005][2005]; int p[2005], a[2005], N, M = 0, K = 0; int main() { scanf( %d , &N); for (int i = 1, x; i <= N; ++i) { scanf( %d , &x); if (x == i) { puts( 0 ); exit(0); } ... |
#include <bits/stdc++.h> using namespace std; int dx[]{1, -1, 0, 0, 1, -1, 1, -1}; int dy[]{0, 0, 1, -1, 1, -1, -1, 1}; int main() { long long n, m, g; string s; while (cin >> n >> m) { vector<int> v(n); for (int i = 0; i < n; i++) cin >> v[i]; int ans = 0; for (int i = 0; i ... |
#include <bits/stdc++.h> using namespace std; const int maxn = 3e5 + 10; const int inf = 0x3f3f3f3f; long long mod = 998244353; pair<int, int> a[maxn]; int n, len; long long aa, b, c, d, sta; int check(int x) { long long tmp = sta; for (int i = 1; i <= n; i++) { if (a[i].second) { ... |
#include <bits/stdc++.h> using namespace std; const int maxn = 1e2 + 10; const int maxm = 22; const int mod = 1e9 + 7; vector<int> G[maxn]; int dp[maxn][maxn][maxm]; int sum[maxn][maxn][maxm]; int n, k; void init() { for (int i = 0; i <= n; ++i) G[i].clear(); } void addEdge(int a, int b) { ... |
#include <bits/stdc++.h> using namespace std; int main() { string h, t; getline(cin, h); getline(cin, t); map<char, int> m; int flag = 0; for (int i = 0; i < h.length(); i++) { if (h[i] == ) continue; m[h[i]]++; } for (int i = 0; i < t.length(); i++) { if (t[i] =... |
#include <bits/stdc++.h> using namespace std; int ans[200005]; int roots[105]; struct node { int l, r; } tree[200005 * 20]; int cnt = 0; void build(int &x, int pos, int l, int r) { if (!x) x = ++cnt; if (l == r) return; int mid = (l + r) >> 1; if (pos <= mid) build(tree[x].l, pos... |
#include <bits/stdc++.h> struct pt { double x, y; } p[305], q[305]; int k, n, cnt, cnt2; double y[301][302], ans[301], prod[305]; double area() { double ans = 0; for (int i = 1; i <= cnt; i++) ans += (p[i].x * p[i % cnt + 1].y - p[i].y * p[i % cnt + 1].x) / 2; return ans; } int main(... |
#include <bits/stdc++.h> using namespace std; int s[500005]; int main() { int i, n = 0; char c; memset(s, 0, sizeof(s)); while ((c = getchar()) != n ) { ++n; if (c == I || c == E || c == A || c == O || c == U || c == Y ) ++s[n]; s[n] += s[n - 1]; } do... |
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 7, mod = 1e9 + 7, inf = 1e9 + 7; const long long linf = (long long)1e18 + 7; const long double eps = 1e-15, pi = 3.141592; const int dx[] = {-1, 0, 1, 0, 1, -1, -1, 1}, dy[] = {0, 1, 0, -1, 1, -1, 1, -1}; inline long long get_ll()... |
#include <bits/stdc++.h> using namespace std; inline int rd() { int x = 0, y = 1; char c = getchar(); while (!isdigit(c)) { if (c == - ) y = -y; c = getchar(); } while (isdigit(c)) x = x * 10 + c - 0 , c = getchar(); return x * y; } int k; inline void init() { k = rd(); }... |
#include <bits/stdc++.h> using namespace std; bool vouel(char c) { return (c == a || c == e || c == i || c == o || c == u ); } int main() { string s; cin >> s; string new_s = ; bool same = false; int streak = 0; char c = 0 ; for (int i = 0; i < s.length(); ++i) { ... |
#include <bits/stdc++.h> #pragma GCC optimize( O3 ) #pragma GCC target( avx ) #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 = 1e18; const long long NEG_INF = -1 * (... |
#include <bits/stdc++.h> using namespace std; const int INF = 1000000001; const int MAXN = 251; struct Person { int cnt, last; int id; Person(int id = -1) : id(id) { cnt = 0; last = 0; } bool operator<(const Person& p) const { if (cnt != p.cnt) return cnt > p.cnt; ret... |
#include <bits/stdc++.h> using namespace std; const int maxn = 1505; int n, a[maxn], sum[maxn], ans, val, ID; int d[maxn * maxn], cnt; vector<int> v[maxn * maxn]; vector<int> vv[maxn]; unordered_map<int, int> mp, L[maxn]; int main() { scanf( %d , &n); for (int i = 1; i <= n; i++) scanf( %d , &a[... |
#include <bits/stdc++.h> using namespace std; const int mod = 51123987; int len, n; char s[4000010], tmp[2000010]; long long p[4000010]; long long sum, ans; long long le[4000010], ri[4000010]; int main() { scanf( %d%s , &len, tmp + 1); s[++n] = @ ; for (int i = 1; i <= len; i++) { s[+... |
#include <bits/stdc++.h> using namespace std; const int N = 55; const int dx[4] = {0, 0, -1, 1}; const int dy[4] = {-1, 1, 0, 0}; int n, m, cnt, cur; char a[N][N], s[N][N]; bool vis[N][N]; inline void dfs(int x, int y) { vis[x][y] = 1; ++cur; for (int xx, yy, k = 0; k < 4; k++) { xx = ... |
#include <bits/stdc++.h> using namespace std; const bool debug = 0; int main() { if (!debug) { cin.tie(0); cout.tie(0); ios::sync_with_stdio(0); } int q; cin >> q; while (q--) { int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; i++) cin >> a[i]... |
#include <bits/stdc++.h> using namespace std; long long int modulo = 1000000009; int h; long long int expo2[31]; long long int expo3[31]; long long int expo4[31]; long long int memmaneres0[1001]; long long int maneres0(int n) { long long int &mem = memmaneres0[n]; if (mem != -1) return mem; ... |
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; vector<long long> a(n); long long i; for (i = 0; i < n; i++) cin >> a[i]; map<long long, long long> m; long long add = 0; for (i = 0; i < n; i++) { auto it = m.find(a[i]); if (it != m.end())... |
#include <bits/stdc++.h> using namespace std; long long min(long long x, long long y) { if (x < y) { return x; } return y; } int main() { long long a, b, c; cin >> a >> b >> c; cout << min(min(a + b + c, 2 * a + 2 * b), min(2 * a + 2 * c, 2 * b + 2 * c)); return 0; } |
#include <bits/stdc++.h> using namespace std; long long const mod = 1e9 + 7; long long const inf = 2e18; inline long long add(long long a, long long b) { return (a % mod + b % mod + mod) % mod; } inline long long mul(long long a, long long b) { return (a % mod * b % mod + mod) % mod; } inline lo... |
#include <bits/stdc++.h> using namespace std; void p(double t) { cout << fixed << setprecision(13) << t << endl; exit(0); } struct tank { int hp, time, lo, hi, prob; void scan() { cin >> hp >> time >> lo >> hi >> prob; prob = 100 - prob; } }; int moven; vector<int> moves; ... |
#include <bits/stdc++.h> using namespace std; const int L = 21; const int N = 1 << L; int n, ans, a[N], best[N][3]; void add(int mask, int value) { auto &b = best[mask]; b[2] = value; if (b[2] > b[1]) swap(b[2], b[1]); if (b[1] > b[0]) swap(b[1], b[0]); } bool possible() { for (int i =... |
#include <bits/stdc++.h> using namespace std; mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count()); const int N = (int)(5e5) + 7; int cnt[N]; int last[N]; int slast[N]; int pcnt[N]; long long psum[N]; int main() { ios::sync_with_stdio(0); cin.tie(0); int n; cin ... |
#include <bits/stdc++.h> using namespace std; int n, m, x, y, z, k, w, a, b, res, dist; vector<int> edge[200005], new_edge[200005]; int deg[200005], depth[200005], far[200005], far_dist[200005]; pair<int, int> dp[200005]; bool has_crit_point[200005]; void DFS(int x, int y, int pre) { if (y == 0) ... |
#include <bits/stdc++.h> #pragma comment(linker, /STACK:36777216 ) using namespace std; const double pi = acos(-1.0); const double eps = 1e-11; const int oo = 0x3f3f3f3f; template <class T> inline void checkmin(T &a, T b) { if (b < a) a = b; } template <class T> inline void checkmax(T &a, T b) ... |
#include <bits/stdc++.h> int main() { int sign = 1; int current = 0; int value = 0; for (char c; n != (c = getchar());) { if (c == + or c == - ) { value += sign * current; sign = (c == + ? 1 : -1); current = 0; } current *= 10; current += c - 0 ... |
#include <bits/stdc++.h> using namespace std; inline int IN() { int x = 0, ch = getchar(), f = 1; while (!isdigit(ch) && (ch != - ) && (ch != EOF)) ch = getchar(); if (ch == - ) { f = -1; ch = getchar(); } while (isdigit(ch)) { x = (x << 1) + (x << 3) + ch - 0 ; ch = g... |
#include <bits/stdc++.h> using namespace std; int arr[100001]; int tree[100001 * 3]; void init(int node, int b, int e) { if (b == e) { tree[node] = arr[b]; return; } int Left = node * 2; int Right = node * 2 + 1; int mid = (b + e) / 2; init(Left, b, mid); init(Right, mid ... |
#include <bits/stdc++.h> using namespace std; int main() { long long n, m; cin >> n >> m; long long ans = n; for (__typeof(m) i = 0; i < m; i++) { long long a, b; cin >> a >> b; ans = min(ans, b - a + 1); } cout << ans << endl; for (__typeof(n) i = 0; i < n; i++) { ... |
#include <bits/stdc++.h> using namespace std; struct MaxFlow { int T; struct node { int to, nxt, cap; } ed[811 * 811 << 1]; int head[811], cur[811], cnt, ans; int h[811]; void addedge(int u, int v, int cap) { ed[cnt].to = v, ed[cnt].cap = cap, ed[cnt].nxt = head[u], head[u] = cnt... |
#include <bits/stdc++.h> using namespace std; int n, m; int a[205], b[205]; int main() { cin >> n >> m; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < m; i++) cin >> b[i]; for (int i = 0; i < 512; i++) { int cnt = 0; for (int j = 0; j < n; j++) { for (int k = 0;... |
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; char cur = a ; vector<char> res(s.size()); for (int i = 0; i < s.size(); i++) { if (cur > z ) { res[i] = s[i]; } else if (s[i] <= cur) { res[i] = cur; cur++; } else { ... |
#include <bits/stdc++.h> using namespace std; const int inf = 1e9; const int N = 1e6 + 10; signed main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int n, m; cin >> n >> m; int g[n]; for (int i = 0; i < n; ++i) cin >> g[i]; sort(g, g + (sizeof(g) / s... |
#include <bits/stdc++.h> using namespace std; const int N = 5000010; vector<long long> v[N]; int a[N]; long long com2(long long n) { return n * (n - 1) / 2; } int main() { long long n, m; cin >> n >> m; for (int i = 1; i <= n; i++) { scanf( %d , &a[i]); if (a[i] >= m) { print... |
#include <bits/stdc++.h> #pragma GCC optimize( O2 ) using namespace std; const int MAX = 2e5 + 5; const long long MAX2 = 11; const int MOD = 1000000000 + 7; const long long INF = 20000; const int dr[] = {1, 0, -1, 0, 1, 1, -1, -1}; const int dc[] = {0, 1, 0, -1, 1, -1, 1, -1}; const double pi = acos(-... |
#include <bits/stdc++.h> using namespace std; int n, k; int a[11]; int tmpa[11]; int sum; int main() { cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; tmpa[i] = a[i]; sum += a[i]; } sort(a, a + n); if (n == 1) { cout << -1 << endl; } else { if (n ==... |
#include <bits/stdc++.h> using namespace std; int n, vis[5009], d[5009][5009]; vector<int> e; vector<vector<int> > g; char s[5009]; void dfs(int v, int pr = -1) { int i; vis[v] = 1; for (auto u : g[v]) { if (d[u][pr] == 1 && pr != -1) { cout << u << << pr << << v; e... |
#include <bits/stdc++.h> using namespace std; int main(int argc, char const *argv[]) { int n, m; char c[2000][2000]; int rowcount[2000]; int colcount[2000], wallcount = 0; for (int i = 0; i < 2000; i++) { rowcount[i] = 0; colcount[i] = 0; } scanf( %d , &n); scanf( %d , &m... |
#include <bits/stdc++.h> using namespace std; const long long N = 30000; long long t, n, a[N], l, r; bool possible() { if (l > r) return 1; long long o = a[l - 1]; a[l - 1] = 0; for (long long i = l; i <= r; i++) { long long v = max(a[i - 1], a[i] - o); if (v > a[r + 1]) return 0; ... |
#include <bits/stdc++.h> using namespace std; const int MAXN = 200005; const int INFTY = 1 << 30; int D, N, M; pair<int, int> pos[MAXN]; vector<int> S; int nxt[MAXN]; int main() { scanf( %d %d %d , &D, &N, &M); for (int i = 0; i < M; i++) scanf( %d %d , &pos[i].first, &pos[i].second); sort(p... |
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int n, a, b; cin >> n >> a >> b; map<long long, int> M; map<pair<int, int>, int> M2; long long ans = 0; for (int i = 0; i < n; ++i) { int x, vx, vy; cin >> x >> vx >> vy; ... |
#include <bits/stdc++.h> using namespace std; long long a[200001], b[200001]; int n; int main(void) { int t; cin >> t; while (t--) { cin >> n; long long sum = 0LL; for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < n; i++) { cin >> b[i]; ... |
#include <bits/stdc++.h> using namespace std; using ll = long long; using vi = vector<int>; using vvi = vector<vi>; using vll = vector<ll>; using vvll = vector<vll>; using vb = vector<bool>; using vd = vector<double>; using vs = vector<string>; using pii = pair<int, int>; using pll = pair<ll, ll>;... |
#include <bits/stdc++.h> using namespace std; int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } void solve() { int m, d, w; long long int ans = 0, lim, g, x, y; scanf( %d%d%d , &m, &d, &w); lim = min(m, d); if (d == 1) ans = lim * lim; else { g = gcd(d - 1, w); w /=... |
#include <bits/stdc++.h> using namespace std; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); long long n; cin >> n; vector<long long> tpa[6], tpb[4]; long long amt[6]; fill(amt, amt + 6, 0); for (long long i = 0; i < n; ++i) { long long a, b, c; cin >> a >> b >... |
#include <bits/stdc++.h> using namespace std; int n; long double ans1[1000000]; long double ans2[1000000]; long double sa[1000000]; long double sb[1000000]; long double x1[1000000]; long double x[1000000]; long double sqr(long double x) { return x * x; } long double sqrtt(long double x) { if (x ... |
#include <bits/stdc++.h> using namespace std; const int N = 123, mod = 1e9 + 7; int n, b, p, x; int cnt[N]; vector<vector<int>> t, a, res; void add(int& a, int b) { a = (a + b); if (a >= mod) { a -= mod; } } int mult(int a, int b) { a = (a * 1ll * b) % mod; return a; } vect... |
#include <bits/stdc++.h> using namespace std; int n, m, ans; int l[255 * 2], r[255 * 2], str[255 * 2], po[27]; char s[255][255]; int solve(int bas, int son) { int tot = 0; l[bas - 1] = bas; r[bas - 1] = bas - 1; for (int i = bas; i <= son; i++) { if (r[i - 1] < i) { l[i] = r[i] =... |
#include <bits/stdc++.h> using namespace std; const int N = 200005; vector<int> v[N]; int n, kk; int dis[N], ans[N]; void dfs1(int pos, int fa) { for (auto &i : v[pos]) if (i != fa) dfs1(i, pos), dis[pos] = max(dis[pos], dis[i]); ++dis[pos]; } bool dfs2(int pos, int fa, const multiset<int,... |
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; string ans[N]; int len[N]; int dp[N]; string get_ans(const string &add) { if (add.size() <= 10) { auto res = add; reverse(res.begin(), res.end()); return res; } string res; int t = add.size(); for (int... |
#include <bits/stdc++.h> using namespace std; long long int n, h[100001], root[100001], par[100001][25], size[100001], dp_down_0[100001], dp_down_1[100001], dp_up_0[100001], dp_up_1[100001]; vector<pair<long long int, long long int> > v[100001]; long long int add(long long int x, long long int y) { re... |
#include <bits/stdc++.h> using namespace std; const int DIM = 55; char mat[2][DIM][DIM]; vector<pair<int, int>> lst1, lst2; void move(int k, int p, int q, vector<pair<int, int>> &lst) { lst.push_back(make_pair(p, q)); if (mat[k][p][q] == U ) { assert(mat[k][p + 0][q + 0] == U and mat[k][p + 0... |
#include <bits/stdc++.h> using namespace std; void bug() { cout << << endl; } template <class T> void bug(T a) { cout << a << ; } template <class T> void bug(T* a, int n) { for (int i = 0; i < (n); i++) bug(a[i]); } int n, m; vector<pair<pair<int, int>, bool> > e; int ans = 1000000... |
#include <bits/stdc++.h> using namespace std; bool Pfunc(string); int main() { string st; cin >> st; for (int i = st.size(); i > 0; i--) { bool b = false; for (int k = 0; k <= st.size() - i; k++) { if (Pfunc(st.substr(k, i)) == false) { cout << i; b = true; ... |
#include <bits/stdc++.h> using namespace std; int c, bi, ba; int main() { int n; cin >> n; for (int i = 0; i < n; i++) { int x; cin >> x; if (i % 3 == 0) c += x; else if (i % 3 == 1) bi += x; else ba += x; } if (c > bi && c > ba) cout... |
#include <bits/stdc++.h> using namespace std; long long n, k, ans = 0, a, b; vector<long long> v, sum, sumk; vector<pair<long long, long long> > maxsumk, maxsum2k; int main() { cin >> n >> k; v.resize(n); for (int i = 0; i < n; i++) cin >> v[i]; sum.resize(n); sumk.resize(n); sum[0] = ... |
#include <bits/stdc++.h> using namespace std; long long x, off = 10; vector<long long> vec[15]; inline long long mul(long long a, long long b) { bool neg = false; long long res = 0; if (b < 0) { neg = true; b = -b; } while (b) { if (b & 1) res = (res + a) % off; a = (... |
#include <bits/stdc++.h> using namespace std; int main() { string s, t; while (cin >> t) s += t; vector<string> str; int pos = 0; vector<int> a, ans; while (pos != ((int)(s).size())) { if (s.substr(pos, 7) == <table> ) { a.push_back(0); pos += 7; } else if (s.sub... |
#include <bits/stdc++.h> using namespace std; int main() { int n, t; cin >> n >> t; char pos[50]; cin >> pos; while (t--) { for (int i = 0; i < n; i++) { if (pos[i] == B ) { if ((i + 1) < n && pos[i + 1] == G ) { char temp = pos[i]; pos[i] = pos[... |
#include <bits/stdc++.h> using namespace std; long long int mod = 1e9 + 7; long long int inf = 9 * 1e18; const long long maxn = 2e5 + 100; long long pow(long long a, long long b) { if (b < 0) return 0LL; long long ans = 1; while (b) { if (b & 1) ans = ans * a; a = a * a; b >>= 1;... |
#include <bits/stdc++.h> int start, n, m; bool edge[25][25]; long long memory[25][(1 << 19) + 5]; long long dfs(int u, int mask) { if (memory[u][mask] != -1) return memory[u][mask]; int visit = 0; for (int i = 0; i < n; i++) { if (mask & (1 << i)) visit++; } long long result = 0; i... |
#include <bits/stdc++.h> using namespace std; const double EPS = (double)1e-9; const double PI = (double)acos(-1.0); int irand(int lo, int hi) { return (((double)rand()) / (RAND_MAX + 1.0)) * (hi - lo + 1) + lo; } string toString(long long x) { stringstream ss; ss << x; return ss.str(); } ... |
#include <bits/stdc++.h> using namespace std; vector<char> v; string s; int main() { cin >> s; for (int i = 0; i < s.size(); i++) { if (!v.empty() && v.back() == s[i]) v.pop_back(); else v.push_back(s[i]); } cout << (v.empty() ? Yes : No ); } |
#include <bits/stdc++.h> using namespace std; long long DP[20][4]; void init() { DP[0][3] = DP[0][2] = DP[0][1] = DP[0][0] = 1; for (int i = 1; i <= 18; i++) { DP[i][0] = 1; for (int j = 1; j <= 3; j++) { DP[i][j] = 9 * DP[i - 1][j - 1] + DP[i - 1][j]; } } } long long sol... |
#include <bits/stdc++.h> using namespace std; int N, K, ma; int A[1000005]; int dp[10000005]; bool ok(int val) { int nr = 0; for (int i = 1; i <= ma; i++) { dp[i] = 0; if (val <= i) dp[i] = 1; if (i % 2) dp[i] = max(dp[i], dp[i >> 1] + dp[(i + 1) >> 1]); else dp... |
#include <bits/stdc++.h> namespace io { int F() { int F = 1, n = 0; char ch; while ((ch = getchar()) != - && (ch < 0 || ch > 9 )) ; ch == - ? F = 0 : n = ch - 0 ; while ((ch = getchar()) >= 0 && ch <= 9 ) n = n * 10 + ch - 0 ; return F ? n : -n; } long long G() { lo... |
#include <bits/stdc++.h> using namespace std; int main() { int n, m, flag = 0; cin >> n >> m; char c; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { cin >> c; if (c == B || c == W || c == G ) continue; else flag = 1; } } ... |
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; int a, b; double gia[n]; for (int i = 0; i < n; i++) { cin >> a >> b; gia[i] = (double)a / b; } double kq = gia[0]; for (int i = 1; i < n; i++) { if (kq > gia[i]) kq = gia[i]; } ... |
#include <bits/stdc++.h> using namespace std; string s; string p; int a[2005]; int A[2005]; int ans[2005]; int dp[2005][2005]; int main() { cin >> s >> p; memset(a, -1, sizeof(a)); a[0] = 0; for (int i = 0; i < s.size(); i++) { for (int j = p.size() - 1; j >= 0; j--) { if (... |
#include <bits/stdc++.h> using namespace std; const int INF = 2147483647; const int maxn = 21; const int dx[4] = {0, 0, 1, -1}; const int dy[4] = {1, -1, 0, 0}; int Map[maxn][maxn], Value[maxn], X[maxn], Y[maxn], XX[maxn], YY[maxn]; int vis[maxn][maxn][260][129], VV[maxn][maxn][260][129], inq[maxn][... |
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; int n, m, dp[250][1 << 15][2][2]; char g[250][251]; int calc(int r, int c, int left, int up, int emp) { if (r == n) { for (int i = 0; i < 15; i++) if (c + 1 < m && (left & (1 << i)) && g[i][c + 1] == x ) left &... |
#include <bits/stdc++.h> using namespace std; int main() { int A[5][5], x, y, p, q, sum; for (int i = 0; i < 5; i++) { for (int j = 0; j < 5; j++) { cin >> A[i][j]; if (A[i][j] == 1) { x = i; y = j; } } cout << endl; } if (x == 2 && y == ... |
#include <bits/stdc++.h> using namespace std; int a[100005], b[100005], m[100005]; int main() { int n; scanf( %d , &n); for (int i = 1; i <= n; i++) scanf( %d , &a[i]); for (int i = 1; i <= n; i++) scanf( %d , &b[i]); m[1] = a[1] - b[1]; for (int i = 2; i <= n; i++) m[i] = m[i - 1] + a[i] ... |
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; const int inf = 1e9; int n, m; int mp[3][N]; char ch[N]; struct node { int d1, d2, d3, d4; }; struct tree { int l, r; node d; } t[N * 5]; node merge(node a, node b) { node tmp; tmp.d1 = min(inf, min(a.d1 + b.d... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t = 0; cin >> t; for (int i = 0; i < t; i++) { long long m = 0; int n = 0; cin >> n; for (int j = n; j > 2; j -= 2) { m += (2 * pow((j - 1), 2)); ... |
#include <bits/stdc++.h> using namespace std; int n, q, a[100010], l[100010], r[100010]; int st[100010], top; int main() { scanf( %d%d , &n, &q); for (int i = 1; i <= n; i++) scanf( %d , &a[i]); n--; for (int i = 1; i <= n; i++) a[i] = abs(a[i + 1] - a[i]); for (int i = 1; i <= n; i++) { ... |
#include <bits/stdc++.h> using namespace std; long long pw(long long a, long long b) { long long t = 1; if (b == 0) return t; if (b % 2) { t = t * a; } t %= 1000000009; long long x = pw(a, b / 2); x = x * x; x %= 1000000009; t *= x; t %= 1000000009; return t; } ... |
#include <bits/stdc++.h> using namespace std; int Solution() { int n; cin >> n; string s; cin >> s; int cnt = 0; for (int i = 0; i < n; ++i) cnt += (s[i] == H ); s += s; int ans = 0x7fffffff; for (int i = 0; i < n; ++i) { int dif = 0; for (int j = 0; j < cnt; ++j) ... |
#include <bits/stdc++.h> using namespace std; int gcd(int x, int y) { if (y == 0) return x; return gcd(y, x % y); } int lcm(int x, int y) { return x * y / gcd(x, y); } string in; int check(string s) { int ret = 0; while (true) { bool beforem = s[0] == M ; bool changed = false; ... |
#include <bits/stdc++.h> using namespace std; const long long INF = 1e18; template <typename T1, typename T2> istream& operator>>(istream& in, pair<T1, T2>& a) { in >> a.first >> a.second; return in; } template <typename T1, typename T2> ostream& operator<<(ostream& out, pair<T1, T2> a) { out ... |
#include <bits/stdc++.h> using namespace std; int xd[] = {0, 1, 0, -1}; int yd[] = {1, 0, -1, 0}; int xx[] = {0, 1, 0, -1, 1, -1, 1, -1}; int yy[] = {1, 0, -1, 0, 1, 1, -1, -1}; int kx[] = {-2, -1, -2, -1, 1, 2, 2, 1}; int ky[] = {1, 2, -1, -2, -2, -1, 1, 2}; bool islucky(int x) { int four = 0, seve... |
#include <bits/stdc++.h> using int_t = long long int; template <typename T, typename FirstOp = std::plus<T>, typename SecondOp = std::multiplies<T>, typename UpdateOp = std::plus<T>> class SegmentTree { public: explicit SegmentTree(std::size_t size, FirstOp first_operation = FirstOp... |
#include <bits/stdc++.h> using namespace std; int D[100010]; int TN[100010]; vector<int> G[100010]; vector<int> T[100010]; vector<long long int> TS[100010]; map<int, double> S[100010]; struct Furthest { int s, t, x, maxl, N; void DFS1(int u, int f, int l) { if (l > maxl) { x = u; ... |
#include <bits/stdc++.h> using namespace std; int n, cnt; char s[111]; void dfs(int id, int d) { if (id >= n) return; if (s[id] == * ) cnt++; else return; dfs(id + d, d); } int main() { scanf( %d n , &n); gets(s); bool fl = 0; for (int i = 0; i < n; ++i) { ... |
#include <bits/stdc++.h> using namespace std; const int NR = 5005; void Min(int& x, int y) { x = min(x, y); } void Max(int& x, int y) { x = max(x, y); } int read() { int x = 0, f = 1; char ch = getchar(); while (ch < 0 || ch > 9 ) { if (ch == - ) f = -1; ch = getchar(); } w... |
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; long long n, a[100010]; int main() { long long n, mx = 0, sum = 0; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; if (a[i] > mx) mx = a[i]; sum += a[i]; } long long s = (sum + n - 2) / (n - 1... |
#include <bits/stdc++.h> using namespace std; int main() { long long n, m, tr; cin >> n >> m; vector<long long> a, b; for (int i = 1; i <= n; i++) { cin >> tr; a.push_back(tr); } for (int i = 1; i <= m; i++) { cin >> tr; b.push_back(tr); } long long max, ans =... |
#include <bits/stdc++.h> using namespace std; vector<string> m; int main() { int n, k; cin >> n >> k; int e = 0; for (int i = 1; i < k; i++) { string t = ; t += char( A + e / 26); t += char( a + e % 26); e++; m.push_back(t); } for (int i = k; i <= n; i++) ... |
#include <bits/stdc++.h> using namespace std; vector<long long> v; vector<pair<long long, long long> > ans; long long sz, n, m, pos; long long p2(long long x) { long long y = sqrt(x); for (long long i = y - 1; i <= y + 1; i++) if (i * i == x) return y; return false; } bool fnd(long long ... |
#include <bits/stdc++.h> using namespace std; int main() { long long n, m, h; cin >> n >> m >> h; long long r[n], c[m], a[n][m]; for (long long i = 0; i < m; i++) { cin >> c[i]; } for (int i = 0; i < n; i++) { cin >> r[i]; } for (int i = 0; i < n; i++) { for (int j ... |
#include <bits/stdc++.h> using namespace std; const int MAXN = -1; struct dot { long long x, y; dot(long long x = 0, long long y = 0) : x(x), y(y) {} }; bool operator<(dot a, dot b) { return ((a.x + a.y) == (b.x + b.y) ? a.x < b.x : (a.x + a.y) < (b.x + b.y)); } bool Amber(dot a, dot b) { retu... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.