func_code_string stringlengths 59 71.4k |
|---|
#include <bits/stdc++.h> using namespace std; const int MAX = 100; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, pos, l, r, ans = 0; cin >> n >> pos >> l >> r; if (abs(pos - l) > abs(pos - r)) { ans += abs(pos - r) + 1; if (n == r) ans -= abs(pos - r) + 1; ... |
#include <bits/stdc++.h> using namespace std; int main() { long long int x, y, t, neg = 0, pos = 0; cin >> t; while (t--) { cin >> x >> y; if (x < 0) neg++; else pos++; } if (neg <= 1 || pos <= 1) cout << YES << endl; else cout << NO << endl;... |
#include <bits/stdc++.h> using namespace std; template <typename Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << : << arg1 << std::endl; } template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args) { const char* comma = strchr(names + 1, ... |
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize( -O2 ) const int LIM = 5e5 + 5, MOD = 1e9 + 7; int t, n, m, k, x, y; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int tests; cin >> tests; cout << setprecision(10) << fixed; while (tests--) { ... |
#include <bits/stdc++.h> using namespace std; int X[1 << 11]; int Y[1 << 11]; int B[1 << 11]; int NX[1 << 11]; int NY[1 << 11]; int E[1 << 11][1 << 11]; int gN; int dfs(int a) { if (a == gN - 1) return 1; B[a] = 1; int i; for (i = (0); i < (gN); ++i) if (B[i] == 0 && E[a][i] > 0 ... |
#include <bits/stdc++.h> using namespace std; vector<int> scs(const string& s) { int n = s.size(); vector<int> p(n), c(s.begin(), s.end()); vector<vector<int>> g(max(n, 256)); for (int i = 0; i < n; i++) g[c[i]].push_back(i); int b = 0; for (auto& gr : g) { for (int x : gr) p[b++] = x;... |
#include <bits/stdc++.h> using namespace std; int n, m, tot; bool ok(int i, int j) { if (i < 0 or i >= n or j < 0 or j >= m) return 0; return 1; } long long int c[20][20] = {0}; void matcpy(long long int a[20][20], long long int b[20][20]) { for (int i = 0; i < tot; i++) { for (int j = 0; ... |
#include <bits/stdc++.h> using namespace std; int main() { int n, m, b[100] = {0}, g[100] = {0}, t, k, c = 0; cin >> n >> m; cin >> t; while (t--) { cin >> k; b[k] += 1; c += 1; } cin >> k; while (k--) { cin >> t; g[t] += 1; c += 1; } for (int ... |
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; if (n & 1) { cout << 1 ; for (int i = 2; i < n + 1; i++) { cout << i + 1 << << i << ; i += 1; } cout << endl; } else { for (int i = 1; i < n + 1; i++) { cout << ... |
#include <bits/stdc++.h> using namespace std; const int maxn = 300050; int a[maxn << 2]; int ll[maxn], rr[maxn], x[maxn], N, M; void getdown(int cur) { a[cur << 1] = a[cur]; a[(cur << 1) | 1] = a[cur]; a[cur] = 0; } void Insert(int cur, int L, int R, int l, int r, int u) { int mid = (L + R... |
#include <bits/stdc++.h> int len, rest; int space[10][110] = {0}; int num = 0; int ans[21000][3] = {0}; void Check() { for (int i = 1; i <= len; i++) if (space[1][i] != 0 && space[1][i] == space[2][i]) { num++; rest--; ans[num][0] = space[2][i]; ans[num][1] = 1; ... |
#include <bits/stdc++.h> using namespace std; void enable_comma() {} string tostring(char c) { string s = ; s += c; return s; } string tostring(string s) { return + s + ; } string tostring(const char *c) { return tostring((string)c); } string tostring(long long x) { if (x < 0) ret... |
#include <bits/stdc++.h> using namespace std; const int N = 4002; int n = 0, a; char ch[N]; long long ans = 0, sum[N][N], all; long long d[N * 9]; int val(int ind) { return ch[ind - 1] - 0 ; } int main() { cin >> a; while (cin >> ch[n]) n++; for (int i = 1; i <= n; ++i) { for (int j =... |
#include <bits/stdc++.h> using namespace std; const int md = 998244853; long long ans, f[4005][4005], x, y, n, m; int main() { cin >> n >> m; for (int i = 0; i <= n + m; i++) f[i][0] = f[i][i] = 1; for (int i = 0; i <= n + m; i++) for (int j = 0; j < i; j++) f[i][j] = (f[i - 1][j - 1] ... |
#include <bits/stdc++.h> using namespace std; const int MAX_BUF_SIZE = 16384; char BUFOR[MAX_BUF_SIZE]; int BUF_SIZE, BUF_POS; char ZZZ; const int MXN = 50010; const int C = 262144; const int INF = 1000000001; int n, czas, skla; vector<int> G[6 * MXN], GT[6 * MXN], H[6 * MXN], vert[6 * MXN]; vecto... |
#include <bits/stdc++.h> using namespace std; long long dp[1050000], k[25][25], a[1050000]; int main() { long long n, m; while (scanf( %lld%lld , &n, &m) == 2) { string s; cin >> s; memset(k, 0, sizeof(k)); for (int i = 1; i < s.length(); i++) { k[s[i - 1] - a ][s[i] - a ... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long a; cin >> a; vector<long long> x; for (long long i = 0; i < a; i++) { long long b; cin >> b; x.push_back(b); } bool done[101] = ... |
#include <bits/stdc++.h> using namespace std; int ar[100001], csum[100001]; int main() { ios::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL); int n, q; cin >> n; for (int i = 0; i < n; i++) cin >> ar[i]; for (int i = 1; i <= n; i++) { csum[i] = csum[i - 1] + ar[i - 1]; } cin >... |
#include <bits/stdc++.h> using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); int main() { int n; cin >> n; cout << n / 2 - 2; return 0; } |
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 7; long long a[N], b[N]; deque<int> mx, mn; int main() { long long n; cin >> n; long long i; for (i = 1; i <= n; i++) cin >> a[i]; for (i = 1; i <= n; i++) cin >> b[i]; long long j, ans = 0; for (j = 1, i = 1; i <= n... |
#include <bits/stdc++.h> const double eps = 1e-8; const int mod = 8 * 9 * 7 * 11 * 13 * 5; const int maxn = 205; const double pi = acos(-1.0); const int INF = 0x7f7f7f7f; const double inf = 1e50; template <class T> inline T minx(T a, T b) { return (a == -1 || b < a) ? b : a; } template <class T>... |
#include <bits/stdc++.h> #pragma warning(disable : 4786) #pragma warning(disable : 4996) using namespace std; int c[200005], d[200005]; int main() { int n; scanf( %d , &n); int val = 0; int lb, ub; lb = -1000000000; ub = 1000000000; for (int i = 1; i <= n; i++) { scanf( %d %d... |
#include <bits/stdc++.h> int main() { char a[1000005]; scanf( %s , a); int i; long long ans = 0, b = 0; for (i = strlen(a) - 1; i >= 0; i--) { if (a[i] == b ) b++; else if (a[i] == a ) { ans += b; b <<= 1; } ans %= 1000000007; b %= 1000000007... |
#include <bits/stdc++.h> using namespace std; long long n, m, k, ans, cnt; char c[333][333]; pair<int, pair<int, int> > p[3 * int(1e5)]; int main() { cin >> n >> m >> k; for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { cin >> c[i][j]; } } for (int q = 1; q <= m... |
#include <bits/stdc++.h> using namespace std; int n, a[100100], a1[100100], a2[100100]; int main() { while (scanf( %d , &n) != -1) { int ans1 = -1, ans2 = -1; for (int i = 0; i < n; i++) scanf( %d , a + i); for (int i = 0; i < n - 1; i++) scanf( %d , a1 + i); for (int i = 0; i < n - 2;... |
#include <bits/stdc++.h> using namespace std; int main() { string ff, ll; cin >> ff >> ll; string ans = ; ans += ff[0]; for (int i = 1; i < ff.length(); i++) { if (ff[i] >= ll[0]) { ans += ll[0]; break; } ans += ff[i]; if (i == ff.length() - 1) { ... |
#include <bits/stdc++.h> using namespace std; void solve() { int n; cin >> n; vector<int> a(n); int psum = 0, msum = 0; int zero = 0; for (int i = 0; i < n; i++) { cin >> a[i]; if (a[i] > 0) psum += a[i]; if (a[i] < 0) msum += a[i]; } if (psum > abs(msum)) { p... |
#include <bits/stdc++.h> using namespace std; int main() { int n, p; scanf( %d %d , &n, &p); int nums[n]; int sum = 0; for (int i = 0; i < n; i++) { cin >> nums[i]; nums[i] %= p; sum += nums[i]; sum %= p; } int max_part = 0; int left = 0; int right = sum; ... |
#include <bits/stdc++.h> #pragma GCC target( avx2 ) #pragma GCC optimization( O3 ) #pragma GCC optimization( unroll-loops ) using namespace std; template <class T> using vec = std::vector<T>; template <class T> using vec2d = std::vector<std::vector<T>>; template <class T> vec2d<T> makeVec2d(const in... |
#include <bits/stdc++.h> using namespace std; const long long mod = 998244353; const long long N = 2e5 + 1; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long n; cin >> n; vector<long long> nums(n); for (long long i = 0; i < n; i++) { long long k; cin >> ... |
#include <bits/stdc++.h> using namespace std; class point { public: int x, y; point(int _x, int _y) { x = _x; y = _y; } string str() { stringstream ss; ss << ( << x << , << y << ) ; return ss.str(); } }; int main() { int n; cin >> n; point m... |
#include <bits/stdc++.h> using namespace std; struct node { long long mx, sm, idx; node() { mx = 0; sm = 0; idx = 0; } }; struct segTree { long long n; vector<node> st; segTree(long long n) { this->n = n; st.resize(4 * n + 5); } void combine(long lon... |
#include <bits/stdc++.h> using namespace std; const int N = 6e6 + 500; int pt[N << 1], tn, m; pair<int, pair<int, int> > seg1[N], seg2[N]; int n1, n2; int getdep(const pair<int, int> &u) { return u.first + u.second; } int lowbit(const int &x) { if (!x) return 1 << 30; return x & -x; } pair<int... |
#include <bits/stdc++.h> using namespace std; const long long int mod = 1000000000 + 7; const long long int N = 10000000 + 6; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, m, k; cin >> n >> m >> k; int ind[k + 1]; int arr[k]; for (int i = 0; i < k; i++... |
#include <bits/stdc++.h> using namespace std; vector<int> graf[300007]; struct zap { long long zmiana; long long gle; }; vector<zap> z[300007]; int ojc[300007]; long long liczba[300007]; map<long long, long long> zmiany; void licz(int poz, int pop, long long zmiana, long long gl) { for (in... |
#include <bits/stdc++.h> using namespace std; int main() { int x; cin >> x; int j; for (j = 1; (j * j + 1) < 2 * x; j = j + 2) ; if (x == 3) j = 5; cout << j << endl; } |
#include <bits/stdc++.h> using namespace std; int main() { int n; string s[1000]; scanf( %d , &n); for (int i = 0; i < n; i++) { cin >> s[i]; } char ch = s[0][0]; int flg = 0, cnc = 0, cnch = 0; char c = s[0][1]; if (c == ch) flg = 1; for (int i = 0; i < n; i++) { ... |
#include <bits/stdc++.h> using namespace std; long long t = 1, tt; void solve() { long long n; cin >> n; string a, b; cin >> a >> b; if (n == 1) { if (a == b) cout << 0; else cout << 1; return; } long long ans = 0; for (long long i = 0; i < n / 2; ... |
#include <bits/stdc++.h> using namespace std; const int N = 100100; int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } int tree[N << 2]; void pushup(int ind) { tree[ind] = gcd(tree[ind << 1], tree[ind << 1 | 1]); } int a[N]; void build(int ind, int ll, int rr) { if (ll == ... |
#include <bits/stdc++.h> using namespace std; inline int gi() { int data = 0, fu = 1; char ch = 0; while (ch != - && (ch < 0 || ch > 9 )) ch = getchar(); if (ch == - ) fu = -1, ch = getchar(); while ( 0 <= ch && ch <= 9 ) data = (data << 1) + (data << 3) + (ch ^ 48), ch = getchar()... |
#include <bits/stdc++.h> using namespace std; const long long N = 1e+6 + 5; long long big = 1e+18 + 3; long long mod = 1e+9 + 7; long long freq[26] = {0}, vis[N]; long long maxv = -1; long long sz = 0; void dfs(string &s, vector<vector<long long>> &gr, long long ind) { vis[ind] = 1; sz++; fr... |
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 30; int Par[N], cnt_S, cnt_M, ok = 1, n, m; struct Edge { int v, u; char col; bool mark; } E[N]; int Find(int x) { return (Par[x] == x ? x : Par[x] = Find(Par[x])); } bool Union(int e) { int x = Find(E[e].v), y = Find(E[e].u... |
#include <bits/stdc++.h> using namespace std; const unsigned long long INF = 1000 * 1000 * 1000; const double eps = 1e-9; int main() { string s; cin >> s; int pos = 0; for (char c = z ; c >= a ; c--) { int tek = pos; for (int i = tek; i < s.size(); i++) if (s[i] == c) { ... |
#include <bits/stdc++.h> using namespace std; void addEdge(vector<long long> adj[], long long u, long long v) { adj[u].push_back(v); adj[v].push_back(u); } void DFSUtil(vector<long long> adj[], long long v, bool visited[]) { visited[v] = true; for (long long i = 0; i < adj[v].size(); ++i) ... |
#include <bits/stdc++.h> using namespace std; map<int, vector<int>> pos; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int tt; cin >> tt; while (tt--) { int n; cin >> n; vector<int> a(n), b(n); for (int i = 0; i < n; i++) { cin >> a[i]; } ... |
#include <bits/stdc++.h> using namespace std; const int maxtop = 1025; const int maxn = 100010; const int mo = 1000000007; int top; int repeat[maxtop + 1]; int rest; int a[maxn + 1]; int n, K; int C[maxn + 1]; int f[2][maxtop + 1], old, now; long long result; void init() { int i; scanf... |
#include <bits/stdc++.h> using namespace std; long long n; long long res, rem; long long narr[100001]; long long tempint; int main() { scanf( %I64d , &n); for (int i = 0; i < n; ++i) scanf( %I64d , narr + i); sort(narr, narr + n); reverse(narr, narr + n); for (int i = 0; i < n; ++i) res ... |
#include <bits/stdc++.h> using namespace std; const int MAXN = 1005; char mp[MAXN][MAXN]; int ansmp[MAXN][MAXN]; int dire[4][2] = {0, -1, 0, 1, -1, 0, 1, 0}; int n, m; void fillansmap(int x0, int y0, int x1, int y1) { bool colorflag[5]; int dx = (x1 - x0 > 0); int dy = (y1 - y0 > 0); int d... |
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) using namespace std; const int INF = 2e9 + 9; const long long INF1 = 1e18 + 9; const long long MAXN = 4e5 + 7; const long long MAXN1 = 1 << 11; const long long MAXN2 = 4e6 + 9; const long long MOD = 1e9 + 7; const long long MOD1 = 1e9 + 9; const... |
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const int MAXN = 1e4 + 10; int a[MAXN], b[MAXN], c[MAXN]; int n; void fun(int pre) { for (int i = 0; i < n; i++) c[i] = a[i]; for (int i = 0; i <= pre; i++) { c[i] = a[n - pre - 1 + i]; c[n - pre - 1 + i] = a[i]; ... |
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf( %d , &n); int a[n + 2]; a[0] = 0; for (int i = 1; i < n; i++) { scanf( %d , &a[i]); } for (int i = 1; i < n; i++) { a[i] = a[i - 1] + a[i]; } int x, y; scanf( %d%d , &x, &y); printf( %d ,... |
#include <bits/stdc++.h> using namespace std; void init_code() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } long long dp[5002][5002]; long long solve(vector<long long>& v, long long k, long long n, long long idx) { if (k == 0) return 0; if (idx >= n) return 0; if (dp[idx]... |
#include <bits/stdc++.h> using namespace std; int a1, a2, b1, b2; bool sol(int a, int b) { if (b + 1 < a) return 0; if (b > (a + 1) * 2) return 0; return 1; } int main() { cin >> a1 >> a2 >> b1 >> b2; if (sol(a1, b2) || sol(a2, b1)) cout << YES ; else cout << NO ; ret... |
#include <bits/stdc++.h> using namespace std; pair<int, int> arr[1000006]; int main() { int n, v, ans = 0, i, j, a, b, v1; scanf( %d , &n); scanf( %d , &v); for (i = 0; i < n; ++i) { scanf( %d , &a); scanf( %d , &b); arr[a].first += b; arr[a + 1].second += b; } for ... |
#include <bits/stdc++.h> int main() { int a[6][6], i, j, k; int dx[4] = {-1, 0, 1, -1}, dy[4] = {-1, -1, -1, 0}; char x; memset(a, -1, sizeof(a)); for (i = 1; i < 5; i++) { for (j = 1; j < 5; j++) { x = getchar(); if (x == x ) a[i][j] = 1; if (x == . ) a[i][j] = 0; ... |
#include <bits/stdc++.h> using namespace std; int t; int n, q; vector<int> vi[300005]; bool used[300005]; int pre[300005]; vector<pair<int, int> > pos[300005]; int poss[300005]; int main() { cin >> t; while (t--) { scanf( %d%d , &n, &q); for (int i = 0; i < q; i++) vi[i].clear(); ... |
#include <bits/stdc++.h> using namespace std; bool a[55][55], b[55][55], ans[55][55]; int n, m, ans_cnt; int main() { cin >> n >> m; for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) cin >> a[i][j]; for (int i = 1; i <= n - 1; i++) for (int j = 1; j <= m - 1; j++) if (a[i... |
#include <bits/stdc++.h> using namespace std; int main() { int n, ans; long long sum = 0; map<long long, int> d; cin >> n; ans = n - 1; for (int i = 0; i < n; i++) { int t; cin >> t; sum += t; d[sum]++; ans = min(ans, n - d[sum]); } cout << ans << n ; ... |
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; int n = (int)s.size(); int pos[n + 1]; int st = 1, end = n; int temp = 1; for (auto x : s) { if (st > end) break; if (x == l ) { pos[end--] = temp++; } else { pos[st++] = tem... |
#include <bits/stdc++.h> using namespace std; inline long long max(long long a, long long b) { return a > b ? a : b; } class Box { public: string name; int type, border, spacing; vector<Box *> con; bool hcalc, wcalc; long long w, h; Box() { hcalc = wcalc = 0; } Box(string ni, int t)... |
#include <bits/stdc++.h> using namespace std; const long long N = 1e5 + 7; vector<long long> vec; long long solve(vector<long long>& a, long long i) { if (i == -1) return 0; vector<long long> a1, a0; for (long long x : a) if (x & (1 << i)) a1.push_back(x); else a0.push_ba... |
#include <bits/stdc++.h> using namespace std; template <class T> inline T bigmod(T p, T e, T M) { long long ret = 1; for (; e > 0; e >>= 1) { if (e & 1) ret = (ret * p) % M; p = (p * p) % M; } return (T)ret; } template <class T> inline T gcd(T a, T b) { if (b == 0) return a; ... |
#include <bits/stdc++.h> const int MAX_N = 20; int n, k, t; int e[MAX_N + 1][MAX_N + 1]; int choosen[MAX_N + 1]; int mid; int cnt; void dfs(int x, int now_cost_sum) { if (now_cost_sum > mid) return; if (cnt >= t) return; if (x > n) { cnt++; return; } dfs(x + 1, now_cost_sum... |
#include <bits/stdc++.h> using namespace std; priority_queue<pair<long long int, long long int> > p_que; long long int arr[300005]; long long int ans[300005]; int main(int argc, char const *argv[]) { long long int n, k; cin >> n >> k; for (int i = 1; i <= n; i++) { cin >> arr[i]; } f... |
#include <bits/stdc++.h> const long long MX = 2 * 100 * 1000 + 1000, inf = 3e18, mod = 1000 * 1000 * 1000 + 7; using namespace std; vector<long long> ans[MX]; int32_t main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); string s; cin >> s; long long n = s.size(); ... |
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int n, m; cin >> n >> m; vector<int> V(n); for (int i = 0; i < m; ++i) { int k; cin >> k; V[k - 1]++; } int mn = 1e9; for (int i = 0; i < n; ++i) mn = min(mn, V[i]); ... |
#include <bits/stdc++.h> using namespace std; int a[1000 * 1000]; int main() { int t; cin >> t; double s = 0; for (int i = 0; i < t; i++) { cin >> a[i]; s += a[i]; } vector<int> ind; for (int i = 0; i < t; i++) { double p = ((s - a[i]) / (t - 1)); if (a[i] == p)... |
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 5; int n; long long pts[MAXN][2]; unsigned long long area(int i, int j, int k) { return (abs(pts[i][0] * pts[j][1] + pts[j][0] * pts[k][1] + pts[k][0] * pts[i][1] - pts[i][1] * pts[j][0] - pts[j][1] * pts[... |
#include <bits/stdc++.h> #pragma GCC optimize( O3 ) #pragma GCC target( sse4,avx2,abm,fma,tune=native ) #pragma GCC optimize( unroll-loops ) using namespace std; const long long INF = 0x3f3f3f3f; const long long inf = pow(10, 18); long long modulo = pow(10, 9) + 7; long long valn[100100]; long long va... |
#include <bits/stdc++.h> #pragma GCC optimize( O3 ) using namespace std; const char E = n ; const int N = 20015; const int NN = 1000000; const long long md = 1e9 + 7; int main() { cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0); int tttt; cin >> tttt; while (tttt--) { ... |
#include <bits/stdc++.h> using namespace std; long long dp[5011][5011]; void solve() { long long n, m; cin >> n >> m; string s1, s2; cin >> s1 >> s2; s1 = . + s1; s2 = . + s2; long long ans = 0; for (long long i = 1; i <= n; i++) { for (long long j = 1; j <= m; j++) { ... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); ; int t; cin >> t; while (t--) { int a[3]; cin >> a[0] >> a[1] >> a[2]; sort(a, a + 3); if (a[2] == a[0] + a[1]) cout << YES ; else... |
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 15; const int LL = 1e9 + 15; const int SSS = 1e6 + 15; int dx[10] = {0, 1, -1, 1, -1, 2, -2, 2, -2}; int dy[10] = {0, 2, 2, -1, -1, 1, 1, -1, -1}; int n, ii, a[5010], ans[5010], mx, st[5010]; int main() { cin >> n; for (int i = 1;... |
#include <bits/stdc++.h> using namespace std; signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long n; cin >> n; vector<char> v; long long ca = 0, ci = 0, cf = 0; for (long long i = 0; i < n; i++) { char a; cin >> a; v.push_back(a); ... |
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const long long LINF = 0x3f3f3f3f3f3f3f3f; const int MAXA = 2e5 + 10; const int MAX = 2e3 + 10; int n, m, k; int a[MAXA]; int M = 0; pair<int, int> p[MAX]; long long sum[MAX]; long long memo[MAX]; int main() { ios_base... |
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c, d, e, f, g; cin >> a >> b >> c; d = a + b + c; e = 2 * (a + b); f = 2 * (b + c); g = 2 * (c + a); if (d <= e && d <= f && d <= g) { cout << d; } else if (e <= f && e <= g) { cout << e; } else if (... |
#include <bits/stdc++.h> using namespace std; template <typename T> T BigMod(T b, T p, T m) { if (p == 0) return 1; if (p % 2 == 0) { T s = BigMod(b, p / 2, m); return ((s % m) * (s % m)) % m; } return ((b % m) * (BigMod(b, p - 1, m) % m)) % m; } template <typename T> T ModInv(T ... |
#include <bits/stdc++.h> using namespace std; long long n, s, x, y, nb; vector<pair<long long, long long> > t, v; long long dp[102]; bool cmp(pair<long long, long long> a, pair<long long, long long> b) { return a.first + a.second > b.first + b.second; } int main() { ios_base::sync_with_stdio(0); ... |
#include <bits/stdc++.h> using namespace std; struct dulieu { long int gt, tt; }; long int n; dulieu a[3 * 100005]; bool sx1(dulieu a, dulieu b) { return a.gt < b.gt; } bool sx2(dulieu a, dulieu b) { return a.tt < b.tt; } int main() { cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]... |
#include <bits/stdc++.h> using namespace std; char a[1001], b[1001]; int main() { int sa, sb, i, j, ta = 0, tb = 0; cin >> a >> b; sa = strlen(a); sb = strlen(b); for ((i) = 0; (i) < (sa); (i)++) if (a[i] == 1 ) ta++; for ((i) = 0; (i) < (sb); (i)++) if (b[i] == 1 ) tb++; ... |
#include <bits/stdc++.h> using namespace std; vector<int> tree[100005]; int bad[100005]; vector<int> result; int SubTree[100005]; int dfs(int v, int pv) { SubTree[v] = (int)(bad[v] == 1); for (auto u : tree[v]) { if (u == pv) continue; SubTree[v] += dfs(u, v); } if (SubTree[v] ==... |
#include <bits/stdc++.h> using namespace std; const int inf = 1e9; const int mod = 1000000007; int N; vector<int> g[100001]; vector<int> time_in(100001); vector<int> time_out(100001); int cnt; void dfs(int v) { cnt++; time_in[v] = cnt; for (int i : g[v]) { if (time_in[i] == 0) dfs(i)... |
#include <bits/stdc++.h> using namespace std; const int maxn = 100009; long long n, a[maxn], b[maxn], c[maxn], in[maxn], color[maxn]; void read(long long a[]) { for (int i = 1; i <= n; i++) scanf( %lld , &a[i]); } void over() { cout << -1; exit(0); } vector<int> vec[maxn]; void dfs(int now... |
#include <bits/stdc++.h> using namespace std; unordered_set<int> int_set; set<int, greater<int> > divisors; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; string a; cin >> a; if ((a.size()) == 1) { cout << a << a << n ; return 0; } else { str... |
#include <bits/stdc++.h> using namespace std; const double PI = 2.0 * acos(0.0); const double EPS = 1e-6; int a[100005]; bitset<100005> sign; int main() { int n; scanf( %d , &n); for (int i = 0; i < n; i++) scanf( %d , a + i); long long sum = 0LL; for (int i = n - 1; i >= 0; i--) { ... |
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; struct Node { long long x, y; } p[N]; int n; double ans, a, b, c, xx, x1, yy1, x2, x3, y2, y3, x, y; int tf; map<pair<long long, long long>, int> f; inline double dis(Node a, Node b) { return sqrt((a.x - b.x) * (a.x - b.x) +... |
#include <bits/stdc++.h> using namespace std; int n; int main() { scanf( %d , &n); int m = n / 3; for (int i = 1; i <= m; i++) printf( %d %d n , 4, 2 * i); for (int i = 1; i <= n - m; i++) printf( %d %d n , 1, i); return 0; } |
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; void solve() { int m, n; cin >> n >> m; vector<long long> v(n); for (int i = 0; i < n; i++) { string s; cin >> s; for (char c : s) { v[i] *= 2; v[i] += c - 0 ; } } long long n... |
#include <bits/stdc++.h> using namespace std; int q; int cnt[1 << 20]; int trans(long long v) { int rt = 0; for (int i = 0; i < 18; i++, v /= 10) { if ((v % 10) & 1) { rt |= 1 << i; } } return rt; } void insert(long long v) { cnt[trans(v)]++; } void erase(long long v) {... |
#include <bits/stdc++.h> using namespace std; int dp[201]; int main() { int n, t, w, sumt = 0, sumw = 0; memset(dp, -1, sizeof(dp)); dp[0] = 0; scanf( %d , &n); for (int i = 0; i < n; i++) { scanf( %d %d , &t, &w); sumt += t; sumw += w; for (int j = 200; j >= t; j--) { ... |
#include <bits/stdc++.h> using namespace std; const int maxn = 100005; const int inf = (1 << 28) - 1; struct Point { double x, y; Point() {} Point(double _x, double _y) { x = _x; y = _y; } Point operator-(const Point &b) const { return Point(x - b.x, y - b.y); } double operat... |
#include <bits/stdc++.h> using namespace std; int main() { ios ::sync_with_stdio(0); cin.tie(0); long long n; int k; cin >> n >> k; long long num = 0; long long idx = 1; long long todie = n; for (int i = 0; i < k; ++i) { long long x; cin >> x; if (n % x < todie)... |
#include <bits/stdc++.h> using namespace std; int main(void) { int N; scanf( %d , &N); long long res = 0; for (int i = 2; i <= N / 2; i++) { long long m = N / i; res += (m * (m + 1) / 2 - 1) * 4; } printf( %lld n , res); } |
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1.0); const double eps = 1e-6; const int INF = 0x3f3f3f3f; const int MAXN = 2e3 + 10; int ans[MAXN * 3], vis[MAXN][MAXN]; int dp[MAXN][MAXN], n, kk, dir[4][2] = {1, 0, 0, 1}; char mp[MAXN][MAXN]; struct Node { int x, y, s; N... |
#include <bits/stdc++.h> using namespace std; void read(int &sum) { sum = 0; char c = getchar(); bool f = 0; while (c < 0 || c > 9 ) { if (c == - ) f = 1; c = getchar(); } while (c >= 0 && c <= 9 ) { sum = sum * 10 + c - 0 ; c = getchar(); } if (f) sum... |
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; const int MAXN = 1000010; int prime[5005]; long long f[MAXN][22]; void getPrime() { for (int i = 2; i <= 5000; i++) { if (!prime[i]) prime[++prime[0]] = i; for (int j = 1; j <= prime[0] && prime[j] <= 5000 / i; j++) { ... |
#include <bits/stdc++.h> using namespace std; inline int gi() { int x; scanf( %d , &x); return x; } struct Segment_Tree { int dep, f, tag; } t[200005 << 2]; struct Qry { int x, tm, id; } q[200005]; struct _Edge { int to, next; } Edge[200005 << 1]; int head[200005], CNT; int... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t; cin >> t; while (t--) { int n, i; int d = 0, c = 0; cin >> n; string s; cin >> s; for (i = n - 1; i >= 0; i--) { if (... |
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const long long inf = 1e18; const int maxn = 2e5 + 10; const double eps = 1e-7; const double pi = 3.14159265359; long long n, m, a[maxn], par[maxn]; bool check(int x) { long long now = 0; long long cnt = 0; long long cal ... |
#include <bits/stdc++.h> using namespace std; char c[100005]; int cut[100005], num[100005]; int f[100005], h[2][100005]; int main() { int n, m; cin >> n >> c + 1 >> m; for (int i = 1; i <= n; i++) { num[i] = num[i - 1]; if (c[i] == a ) h[0][i] = h[1][i - 1] + 1; else if ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.