func_code_string stringlengths 59 71.4k |
|---|
#include <bits/stdc++.h> using namespace std; int n; pair<pair<int, int>, int> p[200005]; int t[200005], ans[2000005], a[200005]; void san() { for (int i = 1; i <= n; ++i) t[i] = p[i].first.first; sort(t + 1, t + 1 + n); for (int i = 1; i <= n; ++i) p[i].first.first = lower_bound(t + 1, t + ... |
#include <bits/stdc++.h> using namespace std; int main() { string x, y, z; cin >> x; cin >> y; cin >> z; x += y; sort(x.begin(), x.end()); sort(z.begin(), z.end()); if (x.length() != z.length()) cout << NO << n ; else { for (int i = 0; i < x.length(); i... |
#include <bits/stdc++.h> using namespace std; const int MAX = 510; int n, k; int a[MAX], b[MAX]; void init() { cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; cin >> k; for (int i = 1; i <= k; i++) cin >> b[i]; } bool valid(int i, int l, int r) { int x = i, y = i, sum = a[i]; w... |
#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> ostrea... |
#include <bits/stdc++.h> using namespace std; int a[2 * 50004]; int main(void) { int n, k; cin >> n >> k; for (int i = 1; i <= 2 * n; i++) { a[i] = i; } for (int i = 1; i <= k; i++) { swap(a[2 * i], a[2 * i - 1]); } for (int i = 1; i <= 2 * n; i++) { cout << a[i] << ... |
#include <bits/stdc++.h> using namespace std; int dx[5] = {0, -1, 1, 0, 0}, dy[5] = {0, 0, 0, -1, 1}; int n, m, k, i, j, dis[2005][2005], vis[2005][2005], s1, s2; bool check(int x, int y, int d, bool f = 0) { int i, l = max(1, x - d), r = min(n, x + d); if (f) l = s1; for (i = l; i <= r; i++) { ... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0), cout.tie(0); int n, m; cin >> n >> m; vector<int> a(n); for (int i = 0; i < n; ++i) { cin >> a[i]; } cout << 0 ; vector<int> cnt(110, 0); cnt[a[0]]++; for (int w =... |
#include <bits/stdc++.h> const int N = 100010; using namespace std; namespace YKY { inline int rnd() { int res = 0, f = 1; char ch = getchar(); while (ch < 0 || ch > 9 ) { if (ch == - ) f = -1; ch = getchar(); } while (ch >= 0 && ch <= 9 ) { res = res * 10 + ch - 0 ... |
#include <bits/stdc++.h> using namespace std; struct point { int x, y; bool operator<(const point &other) const { return x <= other.x && y <= other.y; } }; map<int, set<point> > m; int main() { int n; scanf( %d , &n); for (int i = 0; i < n; i++) { point p; scanf( %d %... |
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10; int a[maxn]; int main() { int n, m, k; scanf( %d%d%d , &n, &m, &k); if (n > min(m, k)) printf( No n ); else printf( Yes n ); return 0; } |
#include <bits/stdc++.h> #pragma GCC optimize(2) using namespace std; inline int read() { int x = 0, f = 1; char ch = getchar(); for (; ch < 0 || ch > 9 ; ch = getchar()) if (ch == - ) f = -1; for (; ch >= 0 && ch <= 9 ; ch = getchar()) x = (x << 1) + (x << 3) + ch - 0 ; re... |
#include <bits/stdc++.h> using namespace std; int cur; bool c[1011][1011]; int x[33], y[33], z[33]; void connect(int target, int between) { for (int i = (1), _b = (between); i <= _b; i++) z[i] = ++cur; z[between + 1] = target; z[0] = 1; for (int i = (0), _b = (between); i <= _b; i++) c[z[i]][z... |
#include <bits/stdc++.h> using namespace std; int main(int argc, char const *argv[]) { int t; cin >> t; bool even; bool odd; for (int i = 1; i <= t; i++) { int size; even = false; odd = false; cin >> size; int arr[size]; for (int j = 0; j < size; j++) cin >> a... |
#include <bits/stdc++.h> using namespace std; using vint = vector<int>; using pint = pair<int, int>; using vpint = vector<pint>; template <typename A, typename B> inline void chmin(A& a, B b) { if (a > b) a = b; } template <typename A, typename B> inline void chmax(A& a, B b) { if (a < b) a = ... |
#include <bits/stdc++.h> const int mod = 1000000007; using namespace std; pair<int, int> a[12345]; vector<int> ans[3]; map<pair<int, int>, bool> used; map<int, int> cnts; int main() { int n; cin >> n; for (int i = 0; i < n; ++i) { scanf( %d , &a[i].first); a[i].second = i + 1; ... |
#include <bits/stdc++.h> using namespace std; template <class T> void max_swap(T& a, const T& b) { a = max(a, b); } template <class T> void min_swap(T& a, const T& b) { a = min(a, b); } const double EPS = 1e-8; const double PI = acos(-1.0); const int dx[] = {0, 1, 0, -1}; const int dy[] = ... |
#include <bits/stdc++.h> using namespace std; int n, m; char block[][3][4] = {{ ### , .#. , .#. }, { #.. , ### , #.. }, { .#. , .#. , ### }, { ..# , ### , ..# }}; int cell[10][10], anscell[10][10]; int bcnt, ans; bool isPlacable... |
#include <bits/stdc++.h> using namespace std; int main() { long long int n, i, o = 0, e = 0; cin >> n; for (i = 0; i < n; i = i + 1) { long long int x; cin >> x; if (x % 2 == 0) e = e + 1; else o = o + 1; } long long int res = min(o, e); o = o - res; ... |
#include <bits/stdc++.h> #pragma GCC optimize( O3 ) using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); 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) -> d... |
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using pii = pair<int, int>; using cd = complex<ld>; int query(int l, int r) { cout << ? << l << << r << endl; cin >> l; return l; } int main() { ios_base::sync_with_stdio(false); cin.ti... |
#include <bits/stdc++.h> using namespace std; long long ar[100009], f[100009], b[100009], fl = 1; map<long long, long long> mb, mf; int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long n, m; cin >> n >> m; for (long long i = 1; i <= n; i++) { cin >> f[i... |
#include <bits/stdc++.h> using namespace std; int main() { int n, i, x = 0; scanf( %d , &n); for (i = 2; i <= n / 2; i += 2) { if ((n - i) % 2 == 0 && i / 2 != (n - i) / 2) x++; } printf( %d n , x); } |
#include <bits/stdc++.h> using namespace std; vector<long long> foo; long long add = 0; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; cin >> n; for (int i = 0; i < n; i++) { int k; cin >> k; foo.push_back(k); } cout << n + 1 << ... |
#include <bits/stdc++.h> int main() { int a, b, c, d, num, e; int flag = 1; scanf( %d , &num); num++; while (1) { e = num; a = num % 10; num = num / 10; b = num % 10; num = num / 10; c = num % 10; d = num / 10; if (a != b && a != c && a != d && b !=... |
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; const int MMAX = 1e4 + 7; const int MAXDEG = 55; long long v[MAXDEG][MMAX]; vector<long long int> revs = {0}; void rev_begin() { vector<long long int> y; long long t = MOD - 2; while (t > 0) { y.push_back(t % 2)... |
#include <bits/stdc++.h> using namespace std; int main() { long long ans = 0; int n; cin >> n; char str[65000]; cin >> str; for (int i = 0; i < n; i++) { if ((str[i] - 0 ) % 2 == 0) { ans += i + 1; } } cout << ans; return 0; } |
#include <bits/stdc++.h> using namespace std; vector<int> a[2000007]; vector<int> deg(2000007, 0); vector<pair<int, int>> ans; int n, m; void bfs(int node) { vector<bool> used(n); used[node] = true; queue<int> q; q.push(node); while (!q.empty()) { int currnode = q.front(); q.... |
#include <bits/stdc++.h> using namespace std; set<pair<int, int> > s0, s; int K; long long xx[200010], yy[200010]; void func(long long x, long long y) { while (K > 0 && yy[K - 1] < y) K--; while (K >= 2) { long long tmp = (x - xx[K - 2]) * (yy[K - 1] - yy[K - 2]) - (xx[K - ... |
#include <bits/stdc++.h> using namespace std; const int N = 5005, M = 95; int n, T[N][5], fl[N][5]; int PP[5], GG[5], ans; int f[M][M][M]; int g[M][M][M]; void UPD(int &x, int y) { x < y ? x = y : 233; } int main() { scanf( %d , &n); for (int i = (int)(1); i <= (int)(n); i++) for (int j = ... |
#include <bits/stdc++.h> int main(void) { char s[1001]; char t[1001]; scanf( %s %s , s, t); int idx = 0; while (s[idx] != 0 ) { if (t[idx] == 0 ) { puts( No ); return 0; } char cs = s[idx]; char ct = t[idx]; int cvowel = 0; int tvowel = 0; ... |
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } int kolvo = 0; int kolvo1 = 0; for (int i = 0; i < n; i++) { if (a[i] == 5) { kolvo++; } if (a[i] == 0) { ... |
#include <bits/stdc++.h> using namespace std; const int N = 200200; vector<long long int> g[N], e[N]; set<pair<long long int, long long int> > S; int n, m; long long int d[N]; int main() { ios_base::sync_with_stdio(0); cin >> n >> m; for (int i = 1; i <= m; i++) { long long int x, y, z; ... |
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const long long mod = 1000000007; const double e = 2.718281828459; long long gcd(long long a, long long b) { if (!b) return a; return gcd(b, a % b); } long long gcd1(int a, int b) { if (!b) return a; return gcd(b, a ... |
#include <bits/stdc++.h> int main() { int n, h, m, h0, m0, c(1), cash(1); scanf( %d , &n); scanf( %d%d , &h0, &m0); while (--n) { scanf( %d%d , &h, &m); if (h == h0 && m == m0) { c += 1; if (c > cash) { cash = c; } } else { c = 1; } ... |
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf( %d , &n); int count = 0; vector<long long> ans; int k = 0; for (int i = 0; i < n; i++) { int u; scanf( %d , &u); if (count > 0 && u != 0) { if (k != 0) ans.push_back(count + 1); ... |
#include <bits/stdc++.h> using namespace std; int main() { int n, m; for (; ~scanf( %d%d , &n, &m);) { if (n == 1) { if (m == 1) puts( 0 ); else { for (int i = 1; i <= m; ++i) printf( %d , i + 1); puts( ); } } else { if (m == 1) ... |
#include <bits/stdc++.h> using namespace std; vector<pair<long long, long long> > V1, V2; int n, s; int main() { while (~scanf( %d%d , &n, &s)) { V1.clear(); V2.clear(); long long sum1 = 0; long long sum2 = 0; long long ans = 0; for (int i = 0; i < n; i++) { long ... |
#include <bits/stdc++.h> using namespace std; void solve() { long long n, k; cin >> n >> k; vector<long long> a(n); for (long long i = 0; i < n; i++) { cin >> a[i]; } vector<long long> step(100, 0); for (long long i = 0; i < n; i++) { long long x = 0; while (a[i] > 0) {... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; map<int, int> m; int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; m[a[i]] = i; } long long int b[n]; map<int, int> freq; for (int i... |
#include <bits/stdc++.h> using namespace std; int size[3010], fa[3010], sum[3010], head[10010]; struct node { int x, y, next; } e[3010]; int find(int x) { if (x != fa[x]) fa[x] = find(fa[x]); return fa[x]; } int main() { int n; scanf( %d , &n); for (int i = 1; i < n; i++) { i... |
#include <bits/stdc++.h> const int maxx = 2e6 + 5; using namespace std; long long a[maxx]; long long biaoji[maxx] = {0}; int main() { long long t, i, j, m, n; cin >> n; long long maxl = 0; for (i = 1; i <= n; i++) { scanf( %lld , &a[i]); maxl = max(maxl, a[i]); biaoji[a[i]]++... |
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf( %d , &n); long long val, sum = 0, minOdd = 1000000001; for (int i = 0; i < n; i++) { scanf( %lld , &val); if (val & 1) minOdd = min(minOdd, val); sum += val; } printf( %lld n , (sum & 1) ? sum - minOdd... |
#include <bits/stdc++.h> namespace pb_ds { namespace io { const int MaxBuff = 1 << 15; const int Output = 1 << 23; char B[MaxBuff], *S = B, *T = B; char Out[Output], *iter = Out; inline void flush() { fwrite(Out, 1, iter - Out, stdout); iter = Out; } } // namespace io template <class Type> ... |
#include <bits/stdc++.h> const double pi = std::acos(-1); using namespace std; const long long int mod = 1000000000 + 7; long long int power(long long int x, long long int y, long long int md) { long long int res = 1; x = x % md; if (x == 0) return 0; while (y > 0) { if (y & 1) res = (res ... |
#include <bits/stdc++.h> using namespace std; long long int power(long long int a, long long int b) { long long int result = 1; while (b > 0) { int lastbit = (b & 1); if (lastbit) { result = (result * a); } a = (a * a); b = b >> 1; } return result; } long lo... |
#include <bits/stdc++.h> using namespace std; int main() { int n; string s, t; cin >> n; vector<vector<int> > DP(26, vector<int>(26, -10000000)); for (int i = 0; i < n; i++) { t = s; cin >> s; if (i > 0) DP[t[0] - a ][t[t.length() - 1] - a ] = max(DP[t[0] ... |
#include <bits/stdc++.h> using namespace std; int n; long long int w, x[200005]; int main() { cin >> n >> w; for (int i = 0; i < n * 2; i++) cin >> x[i]; sort(x, x + n * 2); double mid; mid = min((double)x[n] / 2, (double)x[0]); mid = (mid + mid * 2) * n; mid = min(mid, (double)w); ... |
#include <bits/stdc++.h> using namespace std; int main() { int a, t, f, k, y = 0, w, j = 0, x = 0; cin >> a >> t >> f >> k; w = t; for (;;) { if (x == 0) { if (j % 2 == 1) j++; if (j == k) break; if (w >= f) { x = f; w -= f; } else { ... |
#include <bits/stdc++.h> using namespace std; void cp() { ios ::sync_with_stdio(false); cin.tie(0); cout.tie(0); } int main() { cp(); { string s, t; cin >> s >> t; if (s.length() == t.length() + 1) { long long m = 0; long long in = -1; char f; ... |
#include <bits/stdc++.h> using namespace std; const int MX = 100 * 1000 + 7; int a[MX]; int hup[MX], hdown[MX]; long long cup[MX], cdown[MX]; 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++) { int cost = 0;... |
#include <bits/stdc++.h> using namespace std; struct ww { long long x, y; } c[400][400]; int i, j, k, n, m, ma, ren, C, kuai; int cov[400], zhi[400]; long long b[400][400], s[400][400]; vector<int> a[100010]; inline void gao(int x) { int i, n = kuai - 1, g[400], r = 0; long long jum[400]; ... |
#include <bits/stdc++.h> using namespace std; int n, ans; int a[200][10]; int p[10]; struct Node { double l, r; int w; } c[10]; struct Point { int S, T; } u[10], v[10]; void Op() { c[1].l = -(1e-7); c[1].r = 1.00 / 32.00; c[1].w = 3000; c[2].l = 1.00 / 32.00; c[2].r = 1... |
#include <bits/stdc++.h> using namespace std; int main() { int n, t, x, y, arr1[2] = {0, 0}, arr2[2] = {0, 0}; cin >> n; for (int i = 0; i < n; i++) { cin >> t >> x >> y; if (t == 1) { arr1[0] += x; arr1[1] += y; } if (t == 2) { arr2[0] += x; arr2[... |
#include <bits/stdc++.h> using namespace std; vector<long long> v; bitset<101> usado; long long dfs(long long nodo) { if (usado[nodo]) return 0; usado.set(nodo); return 1 + dfs(v[nodo]); } long long calcmcd(long long a, long long b) { if (a % b == 0) return b; return calcmcd(b, a % b); ... |
#include <bits/stdc++.h> #pragma GCC optimize( O3 ) #pragma GCC optimize( Ofast,no-stack-protector ) using namespace std; void err(istream_iterator<string> it) {} template <typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cerr << *it << = << a << n ; err... |
#include <bits/stdc++.h> using std::vector; const long double EPS = 1e-10; int n; int x[5], y[5], r[5]; inline int sqr(int x) { return x * x; } namespace solver2 { bool get(int a, int b) { int dist2 = sqr(x[a] - x[b]) + sqr(y[a] - y[b]); return dist2 < sqr(r[a] + r[b]) && dist2 > sqr(r[a] - r[b]);... |
#include <bits/stdc++.h> using namespace std; int t[1000009][11]; int main() { int n, i, j, x, y, ans; cin >> ans; for (i = 0; i <= 10; i++) { t[0][i] = 1; } for (i = 1; i < 1000009; i++) { for (j = 1; j <= 10; j++) { x = (i - j >= 0) ? t[i - j][j] : 0; y = (j > 1) ... |
#include <bits/stdc++.h> using namespace std; void fun() {} long long mod = 1000000000 + 7; long long powe(long long x, long long y) { x = x % mod, y = y % (mod - 1); long long ans = 1; while (y > 0) { if (y & 1) { ans = (1ll * x * ans) % mod; } y >>= 1; x = (1ll * x ... |
#include <bits/stdc++.h> using namespace std; double x[100010], y[100010], X, Y, mem[100010]; int id[100010], len; int cmp(int i, int j) { if (fabs(x[i] - x[j]) > 1e-8) return x[i] < x[j]; return y[i] > y[j]; } int main() { int n, i, j, k, A, B, C, D; scanf( %d %d/%d %d/%d , &n, &A, &B, &C, ... |
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; long long power(long long x, long long y, long long p) { long long res = 1; x = x % p; while (y > 0) { if (y & 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res; } const long long... |
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 111; int a[maxn]; int getid[maxn]; int b[maxn]; int lpos[maxn]; vector<int> savepos[maxn]; vector<int> G[maxn]; vector<int> v; int n, m, q; int vis[maxn]; void dfs(int pos, int fa) { v.push_back(pos); vis[pos] = 1; ... |
#include <bits/stdc++.h> using namespace std; int flag[100005]; int ok, a[100005], b[100005], vis[100005]; vector<int> G[100005]; void Sech(int u, int p) { int i, v; vis[u] = 1; if (flag[u] == 1) ok = -1; flag[u] = -1; for (i = 0; i < G[u].size(); i++) { v = G[u][i]; if (v == p... |
#include <bits/stdc++.h> using namespace std; int toint(char a) { return (a - 0 ); } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int tst; cin >> tst; while (tst--) { string a, s; cin >> a >> s; long long int num = stoll(a); long long int sum = st... |
#include <bits/stdc++.h> using namespace std; long long a[100001], i, l, r, n, j, c44, c1, c4, c, x, ans, h, y, m, step[101], v, b[100500], d[100500]; string s; int main() { cin >> n; for (i = 1; i <= n; i++) { cin >> a[i]; b[i] = a[i]; } sort(b + 1, b + n + 1); for (i = 1;... |
#include <bits/stdc++.h> using namespace std; const int MAXN = 1000030; int num[MAXN]; int a[MAXN], b[MAXN]; int dex[MAXN]; int res[MAXN]; int bsch(int le, int ri, int key) { int l = le, r = ri; while (l <= r) { int m = (l + r) / 2; if (res[m] == key) return m; else if (r... |
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; int n, m, num[40][40], len = 0, stat[20], sv[20], ans = 0; bool vis[10][10], vis2[10][10], usedr[10], have = false; string s[40]; vector<pair<int, int> > coo[400]; vector<int> pr[20]; bool stane = false; bool check(int pos) {... |
#include <bits/stdc++.h> using namespace std; void solve() { int m, k; cin >> m >> k; if (m % 2 == 0) { printf( %d n , m + k * 2); } else { int t; for (int i = 3; i <= m; i += 2) { if (m % i == 0) { t = i; break; } } k--; m += t... |
#include <bits/stdc++.h> using namespace std; long long m = 1e9 + 7; double eps = 1e-6; bool good[256]; long long n, spos = -1; int main(int argc, char *argv[]) { ios::sync_with_stdio(0); string g, pat; cin >> g; cin >> pat; cin >> n; for (int i = 0; (i) < (256); ++i) good[i] = false... |
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; i++) cin >> a[i]; vector<int> s(n, 0); s[n - 1] = a[n - 1]; for (int i = n - 2; i >= 0; i--) s[i] = max(a[i], s[i + 1]); for (int i = 0; i < n - 1; i++) cout << max(0,... |
#include <bits/stdc++.h> using namespace std; struct pr { int a, b, n, x; pr(int a, int b, int n) : a(a), b(b), n(n) {} pr() : a(0), b(0), n(-1) {} }; int n, m; vector<pr> a, b; void connect(int x1, int& x2, int& y2) { if ((x2 != -1 && x2 != x1) || (y2 != -1 && y2 != x1)) { cout << -1;... |
#include <bits/stdc++.h> using namespace std; const int MAXN = 70, MAXM = 100, MOD = 1e9 + 7, INF = 1e9; char c[] = { c , o , d , e , f , o , r , c , e , s }; void solve() { long long n; cin >> n; long long x = 0, x1 = 0; while (pow(x + 1, 10) <= n) x++; while (pow(x, 10 - x1) * pow... |
#include <bits/stdc++.h> using namespace std; const double SUCK = 999999999999999999.99; const int MX = 51 * 101; int n; int r; int f[55]; int s[55]; int p[55]; double cp[55]; double dp[55][MX]; bool isOk(double det) { for (int i = 0; i <= r; i++) { dp[n][i] = 0; } for (int i = n... |
#include <bits/stdc++.h> using namespace std; const int maxn = 400010, inf = 1 << 30; int N, M, father[maxn], nxt[maxn], toit[maxn], len[maxn], side[maxn], id[maxn], seq[maxn], D[maxn], cnt; int DFN, dfn[maxn], top[maxn], size[maxn], con[maxn], ans[maxn], tree[maxn << 2], cover[maxn << 2]; bool ex... |
#include <bits/stdc++.h> using namespace std; int read() { int x = 0, f = 1; char a = getchar(); for (; !isdigit(a); a = getchar()) if (a == - ) f = -1; for (; isdigit(a); a = getchar()) x = x * 10 + a - 0 ; return x * f; } const unsigned long long INF = 1ULL << 63; const int N = 2... |
#include <bits/stdc++.h> const int INF = 0x3f3f3f3f; const std::string str = ATGC ; int main() { int n, m; std::vector<std::string> s; std::vector<std::string> tmp; std::vector<std::string> ans; int min_ans = INF, pos; std::cin >> n >> m; for (int i = 0; i < n; ++i) { std::strin... |
#include <bits/stdc++.h> using namespace std; const long long base = 233; const long long ff = 4e5 + 1; const long long mod = 1e9 + 7; const long long inf = 1e17 + 1; long long read() { long long x; scanf( %lld , &x); return x; } inline long long Read() { long long x = 0, f = 1; char... |
#include <bits/stdc++.h> int main() { int n, m; scanf( %d%d , &n, &m); if (n % 2 != 0) { printf( %d , n); } else { int a[n][m]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { scanf( %d , &a[i][j]); } } bool isSymmetric = true; ... |
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; vector<int> questions(k); vector<int> previsited(n + 1, 0); vector<int> posvisited(n + 1, 0); vector<int> vis; int tot_non = n; for (int i = 0; i < k; i++) { cin >> questions[i]; if (!prev... |
#include <bits/stdc++.h> using namespace std; const long long int MOD = (pow(10, 9) + 7); void vec_p(vector<long long int> &a) { for (long long int i = 0; i < a.size(); i++) { cout << a[i] << ; } cout << n ; } long long int vec_sum(vector<long long int> a) { long long int s = 0; ... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, m; cin >> n >> m; int a[n + 1]; for (int i = 1; i <= n; ++i) cin >> a[i]; int ans = 0; for (int i = 0; i < m; ++i) { int u, v; cin >> u >> v; ans += mi... |
#include <bits/stdc++.h> using namespace std; int main() { int a[101], b[101] = {0}, c[101] = {0}, n, m, i, j, k; scanf( %d%d , &n, &m); for (i = 1; i <= m; i++) { for (j = 1; j <= n; j++) { scanf( %d , &a[j]); c[j] += a[j]; } k = 0; for (j = 1; j <= n; j++) ... |
#include <bits/stdc++.h> using namespace std; const int inf = (int)1e9; const double INF = 1e12, EPS = 1e-9; int n; pair<int, int> p[5000]; int main() { cin >> n; for (int i = 0; i < (int)n; i++) { int a, b; cin >> a >> b; p[i] = pair<int, int>(a, b); } sort(p, p + n); ... |
#include <bits/stdc++.h> using namespace std; int main() { string str; cin >> str; stack<char> s; map<char, char> type = {{ ( , ) }, { { , } }, { < , > }, { [ , ] }}; int ans = 0; for (auto it : str) { if (it == { || it == ( || it == < || it == [ ) { s.push(it); ... |
#include <bits/stdc++.h> using namespace std; const int maxn = (int)1e5 + 10; bool isp[maxn]; int _prime[maxn], lp = 0; int _minCost[maxn]; void InitPrime() { isp[0] = isp[1] = true; for (int i = 4; i < maxn; i += 2) isp[i] = true; for (int i = 3; i * i < maxn; i += 2) if (!isp[i]) ... |
#include <bits/stdc++.h> using namespace std; const int INF = INT_MAX; const long long INFL = LLONG_MAX; const long double pi = acos(-1); int N; int A[300100]; long long S[300100]; int shouldCut[300100]; map<int, vector<int> > mymap; vector<int> v; int main() { ios_base::sync_with_stdio(0); ... |
#include <bits/stdc++.h> using namespace std; const int inf = 1999999999; const double pi = acos(-1.0); const double eps = 1e-9; char gc() { char c; while (isspace(c = getchar())) ; return c; } int gs(char* s) { if (!fgets(s, 9999999, stdin)) return -1; int l = strlen(s); whi... |
#include <bits/stdc++.h> using namespace std; const int N = 24; int n, m, a[N][N], f[1 << 20]; char str[N][N]; void work() { int i, j, k, x; scanf( %d%d , &n, &m); for (i = 0; i < n; ++i) scanf( %s , str[i]); for (i = 0; i < n; ++i) for (j = 0; j < m; ++j) scanf( %d , &a[i][j]); for ... |
#include <bits/stdc++.h> using namespace std; long long int pw(long long int a, long long int b, long long int mod) { if (!b) return 1; if (b & 1) return a * pw(a * a % mod, b / 2, mod) % mod; return pw(a * a % mod, b / 2, mod) % mod; } const long long int MAXN = 1e5 + 10; const long long int MAXK... |
#include <bits/stdc++.h> using namespace std; template <typename T> void read(T &x) { cin >> x; } template <typename T, typename T0> void read(T &x, T0 &y) { cin >> x >> y; } template <typename T, typename T0, typename T1> void read(T &x, T0 &y, T1 &z) { cin >> x >> y >> z; } bool isPo... |
#include <bits/stdc++.h> using namespace std; int main() { int n, p, k; long long a, ans = 0; map<long long, long long> mp; scanf( %d %d %d , &n, &p, &k); for (int i = 0; i < n; i++) { scanf( %lld , &a); ans += mp[((((a * a) % p) * ((a * a) % p)) % p - (k * a) % p + p) % p]++; } ... |
#include <bits/stdc++.h> int abss(int a); int main() { int size; scanf( %d , &size); int colunm[size + 10][2]; int i; int left = 0, right = 0; for (i = 1; i <= size; i++) { scanf( %d %d , &colunm[i][0], &colunm[i][1]); left += colunm[i][0]; right += colunm[i][1]; } ... |
#include <bits/stdc++.h> using namespace std; int n, k; int num[500005]; long long dp[500005]; int cnt[500005]; bool ok(int cost) { dp[0] = dp[1] = cnt[0] = cnt[1] = 0; for (int i = (2); i <= (n); i += (1)) { dp[i] = dp[i - 1]; cnt[i] = cnt[i - 1]; long long v = dp[i - 2] + num[i] ... |
#include <bits/stdc++.h> using namespace std; int main() { int ans = 0; long long p = 1, q = 2, r, n; cin >> n; while (q <= n) { ans++; r = q; q = p + q; p = r; } printf( %d n , ans); return 0; } |
#include <bits/stdc++.h> using namespace std; const int N = 8; const int dx[9] = {-1, -1, -1, 0, 0, 0, 1, 1, 1}; const int dy[9] = {-1, 0, 1, -1, 0, 1, -1, 0, 1}; string a[N]; int v[105][N][N], f[105][N][N]; int main() { for (int i = 0; i < N; ++i) cin >> a[i]; memset(v, 0, sizeof(v)); for (in... |
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> p(n); for (int i = 0; i < n; ++i) { cin >> p[i]; } vector<int> f(n + 1, 0); for (int& x : p) { f[x] = f[x - 1] + 1; } cout << n - *max_element(f.begin(), f.end()); } |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n, h, l = 0, c = 0, a = 0, b = 0, d; cin >> n >> h; while (n--) { cin >> d; c += d; if (c > a) a = c; else if (c < b) b = c;... |
#include <bits/stdc++.h> using namespace std; const double eps = 1e-9; const double PI = acos(-1.0); const long long int mod = 1e9 + 9; const int MAXN = 1e6 + 5; long long int fpow(long long int x, long long int y) { long long int res = 1; while (y > 0) { if (y & 1) res = (res % mod * x % mod)... |
#include <bits/stdc++.h> using namespace std; int i, m, x = 0, n, a[1000], j; int main() { cin >> n; for (i = 0; i < n; i++) cin >> a[i]; for (i = 0; i < n; i++) { m = 1; for (j = i - 1; j >= 0; j--) if (a[j] <= a[j + 1]) ++m; else break; for (j = ... |
#include <bits/stdc++.h> using namespace std; int n; double ans = 0; void calc(vector<int> arr, int d, double p) { if (d == 0) { int tmp = 0; for (int i = 0; i < n; ++i) { for (int j = 0; j < i; ++j) { if (arr[j] > arr[i]) { tmp++; } } } ... |
#include <bits/stdc++.h> using namespace std; int main() { long long int n, p, i, j, val, sum = 0, ans = 0; scanf( %lld %lld , &n, &p); long long int a[n]; for (i = 0; i < n; i++) { scanf( %lld , &a[i]); sum += a[i]; } sum %= p; val = 0; for (i = 0; i < n - 1; i++) { ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.