func_code_string stringlengths 59 71.4k |
|---|
#include <bits/stdc++.h> using namespace std; long long n, x, ans, kiri, kanan, sum, i, pos; long long a[300007], dua[300007]; int main() { scanf( %lld , &n); dua[0] = 1; for (i = 1; i <= 300000; i++) dua[i] = (dua[i - 1] * 2) % 1000000007; x = 1; scanf( %lld , &a[0]); pos = -1; for ... |
#include <bits/stdc++.h> using namespace std; int middle(int a, int b, int c) { if ((a <= b && b <= c) || (c <= b && b <= a)) return b; else if ((b <= a && a <= c) || (c <= a && a <= b)) return a; else return c; } template <typename KeyType, typename ValueType> std::pair<KeyType,... |
#include <bits/stdc++.h> using namespace std; int a[200005]; int main() { ios::sync_with_stdio(0); cin.tie(NULL); int t; cin >> t; for (int z = 1; z <= t; z++) { int n; cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; } int res = n; for (int i =... |
#include <bits/stdc++.h> using namespace std; int n; string s; pair<int, int> best; map<pair<int, int>, int> visited, mark; void dfs(int i, int x, int y) { if (i == n) { return; } if (mark[make_pair(x, y)] == 0) { mark[make_pair(x, y)] = 1; visited[make_pair(x, y)] = i; p... |
#include <bits/stdc++.h> using namespace std; int main() { long long i, j, k, n, t; cin >> n; vector<long long> adj[n + 1]; vector<long long> par(n + 1, 0); for (i = 2; i <= n; i++) { cin >> k; par[i] = k; adj[k].push_back(i); } vector<long long> level(n + 1, 0); le... |
#include <bits/stdc++.h> using namespace std; int A, D, C; vector<int> atk, def, ciel; bool used[110]; int partial(void) { int N = min(A, C), i, ans = 0; for ((i) = 0; (i) < (int)(N); (i)++) if (atk[i] < ciel[C - 1 - i]) ans += ciel[C - 1 - i] - atk[i]; return ans; } int search(int x) { ... |
#include <bits/stdc++.h> using namespace std; long long n, k, i, j, a[2 * 100010]; vector<char> ans; int main() { cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; } long long l = 1, r = n, f = -1e18; while (l <= r) { if (f >= a[l] && f >= a[r]) break; if (a[l] <= f && ... |
#include <bits/stdc++.h> using namespace std; vector<int> d[256]; int mask[256]; vector<int> q; bool b[256]; bool good[256]; int kd[256]; vector<int> g; vector<pair<pair<int, int>, pair<int, int> > > res; int n; int need; void Debug(vector<int> A) { for (int i = 0; i < A.size(); i++) { ... |
#include <bits/stdc++.h> using namespace std; struct SUBS { string _s; int l, r; SUBS() {} SUBS(string s, int l, int r) : _s(s), l(l), r(r) {} bool operator<(const SUBS& subs) const { return _s > subs._s; } }; priority_queue<SUBS> pq; string s; long long n, k; int main() { cin >> s... |
#include <bits/stdc++.h> using namespace std; const long double pi = 3.1415926535897932384626433832795l; template <typename T> inline auto sqr(T x) -> decltype(x * x) { return x * x; } template <typename T1, typename T2> inline bool umx(T1& a, T2 b) { if (a < b) { a = b; return 1; ... |
#include <bits/stdc++.h> using namespace std; struct Number { array<int, 4> powers = {{0, 0, 0, 0}}; Number() {} Number(int a) { if (a != -1) powers[a]++; } long double log_value() const { if (powers[0] > 0) return -INFINITY; return powers[2] * log(2L) + powers[3] * log(3L); ... |
#include <bits/stdc++.h> using namespace std; const long long INF = 1e18; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long n, m, k; long long zero = 0; cin >> n >> m >> k; long long x, s; cin >> x >> s; long long a[m], b[m], c[k], d[k]; long lon... |
#include <bits/stdc++.h> using namespace std; int main() { string x; getline(cin, x); sort(x.begin(), x.end()); int res = unique(x.begin(), x.end()) - x.begin(); if (res % 2 == 0) { cout << CHAT WITH HER! ; } else { cout << IGNORE HIM! ; } return 0; } |
#include <bits/stdc++.h> #pragma GCC optimize( Ofast,no-stack-protector ) #pragma GCC target( avx ) using namespace std; template <typename T, typename U> inline void smin(T &a, const U &b) { if (a > b) a = b; } template <typename T, typename U> inline void smax(T &a, const U &b) { if (a < b) a ... |
#include <bits/stdc++.h> using namespace std; int Min(int aa, int bb) { return aa < bb ? aa : bb; } int Max(int aa, int bb) { return aa > bb ? aa : bb; } struct hh { int aaa, bbb; } cc[200005]; char ss[200005]; bool cmp(hh xa, hh ya) { return xa.aaa < ya.aaa; }; int main() { int n, a[200005], cn... |
#include <bits/stdc++.h> using namespace std; bool isPrime(int n) { if (n <= 1) return false; for (int i = 2; i < n; i++) if (n % i == 0) return false; return true; } int main() { int t; cin >> t; while (t--) { int n; cin >> n; int sum = 0; vector<long long>... |
#include <bits/stdc++.h> using namespace std; int main() { int r, c, i; cin >> r >> c; string s; int R[11] = {0}, C[11] = {0}; for (i = 0; i < r; ++i) { cin >> s; for (int j = 0; j < c; ++j) { if (s[j] == S ) { R[i] = 1; C[j] = 1; } } } ... |
#include <bits/stdc++.h> using namespace std; const int N = 1000 * 300 + 100; vector<pair<int, int> > v[N], e; pair<int, int> dir[N]; bool mark[N], mark2[N], use[N]; void sfd(int p) { mark2[p] = true; for (int i = 0; i < v[p].size(); i++) { int id = v[p][i].second, q = v[p][i].first; if ... |
#include <bits/stdc++.h> using namespace std; int n, m, a[110][110]; bool equal_row(int i, int k) { for (int j = 0; j < m; j++) if (a[i][j] != a[k][j]) return false; return true; } bool can(int from, int mid, int end) { int i = mid - 1, k = mid; while (i >= 0 && k < end) { if (!equ... |
#include <bits/stdc++.h> using namespace std; int T, n, m, sum, tot; struct P { int val, x, y; } a[500]; struct R { int x, y; } b[10]; bool cmp1(const P& a, const P& b) { return a.val > b.val; } bool cmp2(const R& a, const R& b) { return a.y > b.y; } bool Judge(int i, int j, int k, int u) { ... |
#include <bits/stdc++.h> using namespace std; vector<int> a(201), b(201); int n, m; int dp[201][2000]; int fun(int ind, int val) { if (ind >= n) return val; if (dp[ind][val] != (-1)) return dp[ind][val]; int i, temp = INT_MAX, j; for (i = 0; i < m; i++) { j = fun(ind + 1, ((a[ind] & b[i]... |
#include <bits/stdc++.h> char c[301][301]; int n, m, k; int v[5][2] = {{0, 0}, {-1, 0}, {1, 0}, {0, -1}, {0, 1}}; void read() { scanf( %d %d %d , &n, &m, &k); for (int i = 0; i < n; i++) scanf( %s , &c[i]); } void print(int i, int j, int r) { for (int z = 0; z < 5; z++) printf( %d %d n , i... |
#include <bits/stdc++.h> using namespace std; const int N = 300020; inline int read() { int s = 0, w = 1; char ch = getchar(); while (ch > 9 || ch < 0 ) { if (ch == - ) w = -1; ch = getchar(); } while (ch >= 0 && ch <= 9 ) s = s * 10 + ch - 0 , ch = getchar(); return s ... |
#include<cstdio> #include<cstring> #include<algorithm> using namespace std; int t,n,m,f[100005]; int main() { scanf( %d ,&t); while(t--) { memset(f,0,sizeof(f)); scanf( %d%d ,&n,&m); for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) { int x; scanf( %d ,&x); f[i+j]^... |
#include <bits/stdc++.h> using namespace std; const int Maxn = 2005; int n, m; char B[Maxn][Maxn]; bool U[Maxn][Maxn], D[Maxn][Maxn], L[Maxn][Maxn], R[Maxn][Maxn]; long long res; int main() { scanf( %d %d , &n, &m); for (int i = 0; i < n; i++) scanf( %s , B[i]); for (int i = 0; i < n; i++) ... |
#include <bits/stdc++.h> using namespace std; int n, m, fs[100010], to[300010], nx[300010], e, sz[300010], as, bs, l[300010], op, ed, yoo, aya, ans[100010]; bool p[100010], done[100010], q[100010], r[100010]; void ins(int x, int y) { nx[++e] = fs[x]; fs[x] = e; to[e] = y; nx[++e] = fs[y]; ... |
#include <bits/stdc++.h> using namespace std; vector<long long> v[70]; int n; long long ans[100010], cur = 0; int main() { cin >> n; for (int i = 1; i <= n; i++) { long long x; cin >> x; for (int j = 60; j >= 0; j--) if ((x >> j) & 1) { v[j].push_back(x); ... |
#include <bits/stdc++.h> using namespace std; int main() { int t; long long int n, ans, c = 1, i; cin >> t; while (t--) { cin >> n; c = 1, ans = 0, i = 1; while (n > 0) { if (n <= 4) { if (i % 2 != 0) { ans = ans + max(c, n - 1); } else ... |
#include <bits/stdc++.h> using namespace std; vector<int> v[200001]; int deg[200001]; bool vis[200001]; void dfs(int s) { vis[s] = 1; deg[s] = 1; for (auto i : v[s]) { if (vis[i]) continue; dfs(i); deg[s] += deg[i]; } } void solve(int s) { for (auto i : v[s]) if... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, h; cin >> n >> h; vector<int> v(n); for (auto &a : v) cin >> a; int res = 0; for (int i = 0; i < n; i++) { if (v[i] <= h) res++; else res += 2; ... |
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int c[n + 1], e[n - 1][2]; for (int i = 0; i < n - 1; ++i) { cin >> e[i][0] >> e[i][1]; } for (int i = 1; i <= n; ++i) { cin >> c[i]; } vector<int> e1; vector<int> e2; for (int i = 0; i < ... |
#include <bits/stdc++.h> using namespace std; void rip() { cout << -1; exit(0); } set<int> st; set<int> seen; vector<int> ans; int main() { int N; cin >> N; for (int i = 1; i <= N; i++) { int x; cin >> x; if (x > 0) { if (!seen.insert(x).second) rip(); ... |
#include <bits/stdc++.h> using namespace std; int n, mz; char tmp; bool t[51][51]; bool m[51][51]; int mel, skm; bool atr; bool state; void apstaig(int x, int y) { int i, j, z; for (i = x; i <= mz; i++) { if (t[i][y] == false) break; else { m[i][y] = !state; ... |
#include <bits/stdc++.h> using namespace std; long long c[100005], a[100005], b[100005], cur[100005]; int n, m; void update(int x, long long y) { while (x <= m) { c[x] += y; if (c[x] >= 1000000007) c[x] -= 1000000007; x += x & (-x); } } long long query(int x) { long long sum = ... |
#include <bits/stdc++.h> using namespace std; const int maxn = 5e3 + 10, INF = 0x3f3f3f3f; struct edge { int x; int y; } e[maxn]; int w[maxn][maxn]; int num[maxn]; vector<int> vec[maxn]; int depth[maxn]; int fa[maxn]; void dfs(int cur, int p, int dep) { fa[cur] = p; depth[cur] = dep;... |
#include <bits/stdc++.h> using namespace std; const int L = 20, N = 1e6 + 5; const long long MOD = 1e9 + 7; int dp[1 << L], n; long long pow2[N]; int main() { scanf( %d , &n); int a; for (int i = (int)1; i <= n; i++) { scanf( %d , &a); dp[a]++; } pow2[0] = 1; for (int i =... |
#include <bits/stdc++.h> const int INF = 107374182; using namespace std; int n, k; int ans[100005][2]; struct sa { int ma, mi; } segTree[1000000]; void build(int l, int r, int root) { if (l == r) { if (l != n + 1) { scanf( %d , &segTree[root].ma); segTree[root].mi = segTree[r... |
#include <bits/stdc++.h> using namespace std; struct two { long long int f, s; }; signed main() { long long int n; cin >> n; map<string, set<string> > mp; while (n--) { string str; cin >> str; for (long long int i = 0; i < str.size(); i++) { string tmp = ; ... |
#include <bits/stdc++.h> inline long long read() { long long x = 0, f = 1; char c = getchar(); for (; c > 9 || c < 0 ; c = getchar()) { if (c == - ) f = -1; } for (; c >= 0 && c <= 9 ; c = getchar()) { x = x * 10 + c - 0 ; } return x * f; } int cnt[27][105]; char ... |
#include <bits/stdc++.h> using namespace std; const int N = 3e3 + 5, mod = 1e9 + 7; struct p { int x, y; } c[N]; int n, D, num; int h[N], w[N]; int f[N][N]; int read() { int x(0); char ch = getchar(); for (; !isdigit(ch); ch = getchar()) ; for (; isdigit(ch); x = x * 10 + ch - ... |
#include <bits/stdc++.h> using namespace std; string to_string(char c) { return string(1, c); } string to_string(string s) { return s; } template <class A, class B> string to_string(pair<A, B> p) { return ( + to_string(p.first) + , + to_string(p.second) + ) ; } template <class T> string to_str... |
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c, x, y, z; cin >> a >> b >> c >> x >> y >> z; int rest = 0, my = 0; a -= x; b -= y; c -= z; if (a > 0) my += (a / 2); else rest += -a; if (b > 0) my += (b / 2); else rest += -b; ... |
#include <bits/stdc++.h> using namespace std; int i, j, k, l, x, y, z, m, n, ans, dir, s, f, current, p, q; pair<int, int> a; pair<int, pair<int, int> > spies[300000]; int main() { scanf( %d %d %d %d , &n, &m, &s, &f); for (i = 0; i < m; i++) { scanf( %d %d %d , &x, &y, &z); a = make_pair(... |
#include <bits/stdc++.h> using namespace std; vector<pair<int, int> > E[200005]; int U[200005], V[200005], D[200005]; int n, m; int vs[200005]; queue<int> q; int dfs(int u, int in) { q.push(u); for (int len = 0;; len++) { int sz = q.size(); if (sz == 0) break; in = len % 2; ... |
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b); long long nCr(long long n, long long r); long long pow(long long b, long long n); void read(long long a[], long long n); void solve() { long long n; cin >> n; vector<long long> v; for (long long i = 2; i *... |
#include <bits/stdc++.h> int main() { long long int k, b, n, t, i; scanf( %I64d %I64d %I64d %I64d , &k, &b, &n, &t); double x = 1; for (i = 0; i < n && x <= t; i++) { x = k * x + b; } if (x > t) { printf( %I64d , n - i + 1); } else { printf( %I64d , n - i); } retu... |
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string nonz; int ans = 0; string s = ; bool zr = false; for (int i = 0; i < n; i++) { string a; cin >> a; if (a == 0 ) zr = true; string x = a; bool beauty = true; int zero ... |
#include <bits/stdc++.h> using namespace std; int main(void) { int n; cin >> n; cout << (n - 1) / 2 << endl; return 0; } |
#include <bits/stdc++.h> using namespace std; bool debug = false; int n, m, k; long long ln, lk, lm; int b[5105], a[5105]; void update(int x) { for (int i = x; i <= n; i += i & -i) { b[i]++; } } int query(int x) { int ret = 0; for (; x > 0; ret += b[x], x -= x & -x) ; ret... |
#include <bits/stdc++.h> using namespace std; vector<int> adj1[1000050], adj2[1000050]; bool vis1[1000050], vis2[1000050]; vector<int> ans; int main() { int n, m; scanf( %d %d , &n, &m); for (int i = 0; i < m; i++) { int u, v; scanf( %d %d , &u, &v); adj1[u].push_back(v); a... |
#include <bits/stdc++.h> using namespace std; int a, b, c; vector<int> ans; int sum(int curr) { int sum = 0; while (curr > 0) { sum += curr % 10; curr = curr / 10; } return sum; } long long go(long long x, int n) { long long ans = 1; for (int i = 0; i < n; i++) { an... |
#include <bits/stdc++.h> int a, b, c, prad[1000001]; using namespace std; int main() { long long pro = 0; for (int i = 1; i < 1000001; ++i) { for (int j = 1; j * i < 1000001; ++j) { ++prad[j * i]; } } cin >> a >> b >> c; for (int j = 1; j < a + 1; ++j) for (int ja = 1... |
#include <bits/stdc++.h> using namespace std; int vis[110000]; int st[110000], top; int main() { int n, m, i, j, k, x; scanf( %d , &n); if (n & 1) { puts( -1 ); return 0; } st[++top] = 0; x = n / 2; while (x) { st[++top] = x; vis[x] = 1; if (x + n >> 1 <... |
#include <bits/stdc++.h> using namespace std; long long n, i, j, x, xx, yy, p = 1e9 + 7, pr[1000010], nt[1000010], jc[1000010], pos[1000010], mu[1000010], a[1000010], num[1000010], ans; vector<long long> v[1000010]; int main() { scanf( %lld , &... |
#include<bits/stdc++.h> #define For(i,a,b) for(register int i=(a);i<=(b);++i) #define Rep(i,a,b) for(register int i=(a);i>=(b);--i) using namespace std; inline int read() { char c=getchar();int x=0;bool f=0; for(;!isdigit(c);c=getchar())f^=!(c^45); for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)... |
#include<bits/stdc++.h> using namespace std; #define f first #define s second using ll = long long; const int mxN = 200000; const int lgN = 18; const int mod = 1e9 + 7; const ll inf = 1e15; void solve() { int n; cin >> n; int a[n + 1]; int check = true; ... |
#include <bits/stdc++.h> using namespace std; const int N = 100050, inf = 1e9 + 7; struct tree { int l, r, mid, rx, id; } t[N << 3]; struct node { int l, r, t, id; bool operator<(const node &p) const { if (l == p.l) return id < p.id; return l < p.l; } } g[N << 1]; int n, m, ans... |
#include <bits/stdc++.h> using namespace std; int t, n, a[5], ans[5], f1[19491001], cxk, f2[19491001]; int mod1 = 19260817, mod2 = 233317; string s; inline int Read() { int x = 0, f = 1; char ch = getchar(); while (!isdigit(ch)) { if (ch == - ) f = -1; ch = getchar(); } while ... |
#include <bits/stdc++.h> using namespace std; long long n, m, k, i, j; string s; int main() { cin >> n; cin >> s; for (i = 1; i <= n; i++) { if (s[i - 1] != s[i]) k++; } cout << min(k + 2, n); } |
#include <bits/stdc++.h> using namespace std; void solve() { int n, m; cin >> n >> m; vector<pair<int, int> > v; v.resize(n * m); for (int i = 1; i <= n; ++i) { for (int j = 1; j <= m; ++j) { v[m * (i - 1) + j - 1] = {i, j}; } } bool low = true; int l = 0, r = m *... |
#include <bits/stdc++.h> #pragma GCC optimize( Ofast,inline,unroll-loops,fast-math ) using namespace std; class Point { public: int x; int y; Point(int _x = 0, int _y = 0) : x(_x), y(_y) { return; } Point operator-(Point that) { return Point(this->x - that.x, this->y - that.y); } ... |
#include <bits/stdc++.h> using namespace std; long long res = 1; long long countn = 1; void solve(long long a[], long long n) { if (n == 0) { res = max(countn, res); cout << res; } else if (a[n] >= a[n - 1]) { countn++; solve(a, n - 1); } else { res = max(countn, res); ... |
#include <bits/stdc++.h> using namespace std; int main() { pair<int, int> a, b, c; int s = 0; cin >> a.first >> a.second >> b.first >> b.second >> c.first >> c.second; s = a.first * a.second + b.first * b.second + c.first * c.second; if ((int)sqrt(s + 0.0) * (int)sqrt(s + 0.0) != s) { cout... |
#include <bits/stdc++.h> using namespace std; template <typename T> inline void ckmax(T& x, T y) { x = (y > x ? y : x); } template <typename T> inline void ckmin(T& x, T y) { x = (y < x ? y : x); } const int MAXN = 80; const int INF = 0x3f3f3f3f; int n, a[MAXN + 5], cnt[2], pos[MAXN + 5], cn... |
#include <bits/stdc++.h> template <class T> inline void read(T &x) { T 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(); } x *= f; } con... |
#include <bits/stdc++.h> using namespace std; const long long N = 10000000; long long n, a, b; long long dp[N + 1]; signed main() { cin >> n >> a >> b; dp[0] = 0; for (long long i = 1; i <= n; i++) if (i & 1) dp[i] = min(dp[i - 1] + a, dp[i + 1 >> 1] + a + b); else dp[i... |
#include <bits/stdc++.h> using namespace std; int main() { string stringg; string test = new string for test ; cin >> stringg; int a = 5, b = 20; int length = stringg.size(); int lower = 5 * 20; for (int i = 1; i <= 5; i++) for (int j = 1; j <= 20; j++) { if (length <= i *... |
#include <bits/stdc++.h> using namespace std; bool sortbysec(const pair<int, int> &a, const pair<int, int> &b); long long int gcd(long long int a, long long int b); int prime(int n); long long int lcm(long long int a, long long int b) { return (a * b) / gcd(a, b); } int main() { ios_base::sync_wit... |
#include <bits/stdc++.h> inline long long gi() { long long x = 0, f = 1; char ch = getchar(); while (!isdigit(ch)) f ^= ch == - , ch = getchar(); while (isdigit(ch)) x = x * 10 + ch - 0 , ch = getchar(); return f ? x : -x; } inline int pow(int x, int y) { int ret = 1; while (y) { ... |
#include <bits/stdc++.h> using namespace std; int mat[1005][1005]; long long cols[1000005]; long long rows[1000005]; priority_queue<long long> pq; int main() { int n, m; long long k, p; scanf( %d %d %lld %lld , &n, &m, &k, &p); for (int i = 0; i < n; i++) { long long sum = 0; for... |
#include <bits/stdc++.h> using namespace std; const long long int Maxn = 2e5 + 5, N = 4e5 + 5, Mod = 1e9 + 7, Inf = 1e18, Log = 22; int n, h[Maxn], r, mx; vector<int> adj[Maxn]; bool mrk[Maxn]; bool flg[2]; void Dfs(int v, int p) { for (int i = 0; i < adj[v].size(); i++) { ... |
#include <bits/stdc++.h> using namespace std; long long a[5000007], b[5000007]; long long mod = 1e9 + 7; unsigned long long power(unsigned long long x, long long y, long long p) { unsigned long long res = 1; x = x % p; while (y > 0) { if (y & 1) res = (res * x) % p; y = y >> 1; x =... |
#include <bits/stdc++.h> using namespace std; void albus() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } bool asec(long long a, long long b) { return a < b; } bool desc(long long a, long long b) { return a > b; } bool Asec_and_desc(pair<long long, pair<long long, long long>> a, ... |
#include <bits/stdc++.h> using namespace std; int main() { int n, m = 0, b, c = 0; cin >> n; int a[1001]; for (int i = 0; i < n; i++) { cin >> b; if (b == 1) { a[m] = c; m += 1; } c = b; } a[m] = c; cout << m << endl; for (int i = 1; i < m + 1;... |
#include <bits/stdc++.h> using namespace std; const int MAXN = 3e5 + 10; long long ans[MAXN]; int vis[MAXN], in[MAXN], worst[MAXN]; vector<int> adj[MAXN], idx[MAXN], path; vector<pair<int, int> > bad, qs[MAXN]; struct BIT { long long b[MAXN]; BIT() { fill(b, b + MAXN, 0); } void upd(int p, lon... |
#include <bits/stdc++.h> using namespace std; int n, pos, l, r, ind, ans = 0, ans1 = 0, ans2 = 0; int main(void) { ios ::sync_with_stdio(0); cin.tie(0); cin >> n >> pos >> l >> r; if (pos < l) { ans += l - pos + 1; if (n - r > 0) { ans += r - l + 1; } } else if (pos >... |
#include <bits/stdc++.h> using namespace std; int main() { int m, n = 0, x, y, s = 0; cin >> m; vector<int> c(m); for (int i = 0; i < (int)(m); ++i) { cin >> c[i]; n += c[i]; } cin >> x >> y; for (int i = 0; i < (int)(m); ++i) { s += c[i]; if (s <= y && s >= x && ... |
#include <bits/stdc++.h> using namespace std; inline int read() { char c = getchar(); int x = 0, f = 1; for (; !isdigit(c); c = getchar()) if (c == - ) f = -1; for (; isdigit(c); c = getchar()) x = x * 10 + c - 0 ; return x * f; } const int MAXN = 1e6 + 5; struct Node { long lo... |
#include <bits/stdc++.h> using namespace std; const int M = 100000 + 100; const int N = 100 + 100; const int Mod = 1000000007; int n, m; int C[M][N], B[M][N], A[M]; int cnt[N]; inline void Pre() { C[0][0] = 1; for (int i = 1; i <= 100000; ++i) { C[i][0] = 1; for (int j = 1; j <= 100;... |
#include <bits/stdc++.h> using namespace std; int n, a, b, k; const int MOD = 1000000007; int dp[5005][5005], sum[5005]; int main() { scanf( %d%d%d%d , &n, &b, &a, &k); for (int i = b; i <= n; i++) sum[i] = 1; dp[0][b] = 1; for (int i = 1; i <= k; i++) { for (int j = 1; j <= n; j++) { ... |
#include <bits/stdc++.h> using namespace std; template <typename T1, typename T2> istream& operator>>(istream& in, pair<T1, T2>& p) { in >> p.first >> p.second; return in; } template <typename T1, typename T2> ostream& operator<<(ostream& out, pair<T1, T2> p) { out << { << p.first << , << p... |
#include <bits/stdc++.h> using namespace std; const int N = 1010; int n, a[N], ans; bool vis[N]; int main() { scanf( %d , &n); for (int i = 1; i <= n; i++) scanf( %d , &a[i]); int now = 1, dir = 0, tot = 0; while (tot < n) { if (dir == 0) { for (int i = now; i <= n; i++) ... |
#include <bits/stdc++.h> using namespace std; const long long mxn = 5e3 + 100; long long dp[25][mxn]; long long arr[mxn]; long long n, k; bool Check(long long id, long long lo, long long hi, long long rtk) { while (lo <= hi) { long long mid = (lo + hi) / 2; if (dp[id][mid] > rtk) hi ... |
#include <bits/stdc++.h> using namespace std; int n, s[100010][200], ans = 0x3f3f3f3f, vis[200], sub, cunt; char a[100010]; bool check(int l, int r) { int cnt = 0; for (int i = 65; i <= 122; i++) if (s[r][i] - s[l - 1][i]) cnt++; return (cnt == cunt); } int find(int pos) { int l = pos,... |
#include <bits/stdc++.h> using namespace std; vector<long long> a; char op[3]; long long res; void Gao(vector<long long> a) { if (a.size() == 1) { if (res == -1) res = a[0]; else res = min(res, a[0]); return; } vector<long long> tmp; for (int i = 0; i < a.size... |
#include <bits/stdc++.h> using namespace std; int a[100005], n, sum = 0, tp = 0, ans = -(1 << 30); int main() { scanf( %d , &n); for (register int i = 1; i <= n; ++i) scanf( %d , &a[i]), sum += a[i]; for (register int i = 1; i <= n; ++i) if (tp + a[i] < 0) tp = 0; else ans ... |
#include <bits/stdc++.h> using namespace std; using namespace std; const int MaxN = 100005, NA = -1, MaxC = 0x3F3F3F3F; int a[MaxN]; int b[MaxN], c[MaxN]; bool f[MaxN]; int d, e, g, m, n; int main(void) { int i; while (scanf( %d %d , &n, &m) != EOF) { memset(b, 0, sizeof(b)); memset... |
#include <bits/stdc++.h> using namespace std; int dp[5000 + 1][5000 + 1]; int f[5000 + 1][5000 + 1]; int a[5000 + 1]; int N, Q; int main() { int i, j, len; cin >> N; for (i = 1; i <= N; i++) cin >> a[i]; for (i = 1; i <= N; i++) dp[i][i] = f[i][i] = a[i]; for (len = 2; len <= N; len++) ... |
#include <bits/stdc++.h> using namespace std; const long long INF = 0x3f3f3f3f; const double PI = acos(-1.0); const double eps = 1e-10; const long long M = 1e9 + 7; const long long N = 1e5 + 5; signed main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long t; cin >> t;... |
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; const int K = 12; int n, k, q; int arr[K][N]; int who[N][K]; int nrr[N * K][K]; int siz; vector<int> lol[N]; int when[1 << K]; int parent[N * K]; bitset<1 << K> bit[N + K]; int idx[N * K]; int main() { scanf( %d %d %d ,... |
#include <bits/stdc++.h> using namespace std; void fastio() { ios_base::sync_with_stdio(false); cin.tie(NULL); } long long int suma(long long int n) { long long int temp = n; long long int sum1 = 0; while (temp != 0) { sum1 += (temp % 10); temp = temp / 10; } return sum1;... |
#include <bits/stdc++.h> using namespace std; int main() { int n; int m; int sum = 0; int a[100005]; int rec[100005] = {0}; cin >> n >> m; for (int i = 0; i < m; i++) { cin >> a[i]; } for (int i = 0; i < m; i++) { int ss = a[i]; if (rec[ss] == 0) { rec[s... |
#include <bits/stdc++.h> using namespace std; int pow(int a, int k) { if (k == 0) return 1; int r = pow(a, k / 2); if (k % 2 == 0) return r * r; return r * r * a; } int main() { int n, ans = 1; scanf( %d , &n); for (int i = 1; (pow(2, i) - 1) * pow(2, i - 1) <= n; i++) { int v ... |
#include <bits/stdc++.h> const double pi = acos(-1.0); const int max_n = 1e5 + 5; template <class Q> void getint(Q &res, char ch = getchar()) { while (!isdigit(ch) && ch != - ) ch = getchar(); bool flag = true; if ( - == ch) flag = false, ch = getchar(); for (res = 0; isdigit(ch); ch = getchar... |
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int sz, n; cin >> sz >> n; int sx, sy, tx, ty; cin >> sx >> sy >> tx >> ty; vector<vector<pair<int, int>>> g(n + 2); g[n].emplace_back(n + 1, abs(tx - sx) + abs(ty - sy)); vector<int> ... |
#include <bits/stdc++.h> using namespace std; const int DBG = 0, INF = int(1e9); int main() { ios_base::sync_with_stdio(0); cout.setf(ios::fixed); int n; cin >> n; vector<int> a(n); for (auto& x : a) cin >> x; int mx = *max_element(a.begin(), a.end()); for (int q = 0; q < mx; ++q) ... |
#include <bits/stdc++.h> using namespace std; int f[8000]; char s[8000]; int main() { scanf( %s , s); int n = strlen(s), m = n; if (s[0] == * || s[0] == / ) { puts( 0 ); return 0; } f[m] = 1; for (int i = 0; i < n; i++) if (!isdigit(s[i])) if (s[i + 1] == * ... |
#include <bits/stdc++.h> using namespace std; int main() { int n; string str1, str2, ans1, ans2; cin >> str1 >> str2; ans1 = str1; ans2 = str2; cout << ans1 << << ans2 << endl; cin >> n; while (n--) { cin >> str1 >> str2; if (str1 == ans1) { ans1 = str2; ... |
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; if (n == 1) { int x; cin >> x; cout << YES ; } else { vector<int> a(n); bool flag = true; cin >> a[0]; for (int i = ... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); long long n, k; cin >> n >> k; vector<long long> ans(n); set<pair<long long, long long>> demid; for (int i = 0; i < k; i++) { long long s, m; cin >> s >> m; demid.insert({s + m, i}); ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.