func_code_string stringlengths 59 71.4k |
|---|
#include <bits/stdc++.h> using namespace std; int main() { long n; while (scanf( %ld , &n) != EOF) { int a, b, c1 = 0, c2 = 0, s1 = 0, s2 = 0, i, r; long x = 100000000; for (i = 0; i < n; i++) { scanf( %d%d , &a, &b); if (a == 0) c1++; else c2++;... |
#include <bits/stdc++.h> #pragma warning(disable : 4996 4018) using namespace std; int n, mod = 1000000007; long long arr[1001], cost[1001]; int main() { cin.tie(0); ios_base::sync_with_stdio(0); cin >> n; for (int i = 1; i <= n; i++) cin >> arr[i]; long long ans = 0; for (int i = 1; i... |
#include <bits/stdc++.h> using namespace std; pair<double, double> p[100100]; double d[100100]; double dist(pair<double, double> x, pair<double, double> y) { double val = pow((x.first - y.first) * (x.first - y.first) + (x.second - y.second) * (x.second - y.second), ... |
#include <bits/stdc++.h> using namespace std; int n, p, p1, p2; char s[201]; int pd(char c) { if ((c >= 0 && c <= 9 ) || (c >= A && c <= Z ) || (c >= a && c <= z ) || (c == _ )) return 1; return 0; } int main() { cin >> s; n = strlen(s); if (n > 70) { cout <... |
#include <bits/stdc++.h> using namespace std; long long first[60]; void do_it(long long n2, long long k2, long long x) { if (n2 == 1) { cout << x + 1; return; } if (n2 == 2) { if (k2 == 1) cout << x + 2 << << x + 1; else cout << x + 1 << << x + 2; ... |
#include <bits/stdc++.h> using namespace std; struct E { int a, b, c; }; struct unionfind { vector<int> p, s; int c; unionfind(int n) : p(n, -1), s(n, 1), c(n) {} int find(int a) { return p[a] == -1 ? a : find(p[a]); } vector<pair<int *, int>> buf; void save(int &a) { buf.emplace_bac... |
#include <bits/stdc++.h> using namespace std; int main() { int n, o, z, t; o = z = t = 0; cin >> n; string s; cin >> s; for (int i = 0; i < n; i++) { if (s[i] == 0 ) z++; else if (s[i] == 1 ) o++; else t++; } for (int i = 0; i < n && z < n ... |
#include <bits/stdc++.h> using namespace std; using namespace std::chrono; long long MOD = 1000000007; struct mi { long long v; explicit operator long long() const { return v; } mi() { v = 0; } mi(long long _v) { v = (-MOD < _v && _v < MOD) ? _v : _v % MOD; if (v < 0) v += MOD; }... |
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n, m, k; cin >> n >> m >> k; vector<int> lx(n), ly(m); vector<int> x(k), y(k); for (int& i : lx) cin >> i; for (int& i : ly) cin >> i; for (int i = 0; i < k; i++) { ... |
#include <bits/stdc++.h> using namespace std; int main() { int n, c, i, j = 1; cin >> n; cin >> c; int arr[n]; for (i = 0; i < n; i++) { cin >> arr[i]; } for (i = 0; i < n - 1; i++) { if (arr[i + 1] - arr[i] <= c) j = j + 1; else if (arr[i + 1] - arr[i] != c && ... |
#include <bits/stdc++.h> using namespace std; long long int n; int main() { cin >> n; long long int s(0); long long int i = 1; while (true) { s += i; if (s >= n) { break; } i++; } long long int sk = s - n; if (sk != 0) { cout << i - 1 << n ; ... |
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; if (n % 2 != 0) { cout << 0 ; } else { int x = n / 2; x = pow(2, x); cout << x; } return 0; } |
#include <bits/stdc++.h> using namespace std; int n, m, t; struct node { int l, r; } a[20050]; int cnt[90000], ans[20050]; bool cmp(const node &a, const node &b) { return a.l < b.l; } int main() { scanf( %d%d%d , &n, &m, &t); int x, y, z; for (int i = (1); i <= (n); i++) { scanf( %d:... |
#pragma GCC optimize( O3 , Ofast , no-stack-protector , unroll-loops , omit-frame-pointer , inline ) //Optimization flags #pragma GCC option( arch=native , tune=native , no-zero-upper ) //Enable AVX // #pragma GCC target( avx2 ) //Enable AVX #include <bits/stdc++.h> #define int long long using namesp... |
#include <bits/stdc++.h> using namespace std; int a, z, k, r; int v[109]; int ans[1000009]; int w[1000009][2]; int main() { scanf( %d , &a); k = 1; for (int i = 1; i < 1000001; i++) { z = i; while (z > 0) { if (z % 10 != 0 && z % 10 != 1) { z = -1; break; ... |
#include <bits/stdc++.h> using namespace std; int main() { int n, m, z; cin >> n >> m; z = 0; int* a = new int[n + 1]; int* s = new int[n + 1]; for (int i = 1; i <= n; i++) cin >> a[i]; s[1] = a[1]; s[0] = 0; for (int i = 2; i <= n; i++) s[i] = a[i] + s[i - 1]; for (int i = 1... |
#include <bits/stdc++.h> using namespace std; int n; int sum[26]; char str[5002]; char str_list[5002][5002]; int main() { double ans = 0.0; scanf( %s , str), n = strlen(str); for (int i = 0; i < 26; i++) { int cnt = 0; int max_total = 0; for (int j = 0; j < n; j++) if (... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); ; long long t; cin >> t; while (t--) { long long n; cin >> n; if (n <= 3) cout << -1 << n ; else { if (n & 1) { for (long long i = 1; i... |
#include <bits/stdc++.h> using namespace std; int mx[4] = {1, 0, -1, 0}; int my[4] = {0, 1, 0, -1}; void dfs(int x, int y, vector<vector<char> > &b, vector<vector<int> > &val, int &c, int &v) { v++; val[x][y] = c; for (int i = 0; i < 4; i++) { int xt = x + mx[i]; int yt = y + ... |
#include <bits/stdc++.h> using namespace std; bool isOk(char c, int v) { return v == (c == B ? -1 : 1); } int main() { int n, m; scanf( %d %d , &n, &m); string a[n]; int v[n][m]; char ch; int vx; int nOp = 0; for (int i = 0; i < n; i++) { fill(v[i], v[i] + m, 0); cin ... |
#include <bits/stdc++.h> #include<unordered_map> //#pragma GCC optimize(2) #define ll long long #define sc(n) scanf( %d ,&n) #define scl(n) scanf( %lld ,&n) //#define int ll using namespace std; inline int rd() { int x = 0, f = 1; char c = getchar(); while (c != - && c < 48)c = getchar(); if (c == - ... |
#include <bits/stdc++.h> using namespace std; int main() { int i, j; long long n, a, b, ans; long long arr[50]; arr[0] = 1; for (i = 1; i < 40; i++) arr[i] = arr[i - 1] * 3; scanf( %I64d , &n); for (i = 0; i < 40; i++) { if (n == arr[i]) { printf( 1 n ); break; ... |
#include <bits/stdc++.h> using namespace std; int ans, n; string str; char ch[101000]; int a[101000]; void init() { cin >> n; for (int i = 1; i <= n; i++) { cin >> ch[i]; } for (int i = 1; i <= n; i++) { cin >> a[i]; } } void work() { int ti = 0; for (int i = 1; t... |
#include <bits/stdc++.h> #include <iostream> using namespace std; const int MAX_N = 1e5 + 5; const int MAX_L = 20; // ~ Log N const long long MOD = 1e9 + 7; const long long INF = 1e9 + 7; typedef long long ll; const int mx = 5e6 + 23; const ll mod = 1e9 + 7; int a[mx], team[mx], org[mx]; int... |
#include <bits/stdc++.h> using namespace std; int n; string s; set<string> st; int main() { cin >> n; for (int i = 0; i < n; i++) { cin >> s; sort(s.begin(), s.end()); s.erase(unique(s.begin(), s.end()), s.end()); st.insert(s); } cout << st.size(); } |
#include <bits/stdc++.h> using namespace std; string s; int main() { long long ans = 0; string in; string un = ><+-.,[] ; cin >> in; for (int i = 0; i < in.size(); i++) { ans = (16 * ans + (un.find(in[i]) + 8)) % 1000003; } cout << ans; return 0; } |
#include <bits/stdc++.h> using namespace std; template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { os << { ; string sep; for (const auto &x : v) os << sep << x, sep = , ; return os << } ; } template <typename T, size_t size> ostream &operator<<(ostream &os, const ... |
#include <bits/stdc++.h> using namespace std; int n, m; int a[50]; int main() { cin >> n >> m; for (int i = 0; i < n; i++) { cin >> a[i]; a[i] %= m; } sort(a, a + n); set<int> S1, S2; for (int i = 0; i < n; i++) { set<int> s = i < n / 2 ? S1 : S2; s.insert(a[i]); ... |
#include <bits/stdc++.h> using namespace std; const int MAXN = 1000 * 100 + 10; const int MOD = 1000 * 1000 * 1000 + 7; long double n, m; long double Pow(long double a, int b) { if (b == 0) return 1; long double x = Pow(a, b / 2); x *= x; if (b % 2) x *= a; return x; } int32_t main() {... |
#include <bits/stdc++.h> using namespace std; int main() { int n, x, y; cin >> n; long long sumX = 0; long long sumY = 0; long long sum = 0; for (int i = n; i > 0; i--) { cin >> x; cin >> y; sumX += x; sum += x * x; sumY += y; sum += y * y; } print... |
#include <bits/stdc++.h> using namespace std; const int MAX = 2005; bool a[MAX][MAX], row[MAX], col[MAX]; int main() { ios::sync_with_stdio(false); int n; cin >> n; for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) { char c; cin >> c; a[i][j] = (c == 1 ); ... |
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> digs; while (n % 10 != 0) { digs.push_back(n % 10); n /= 10; } reverse(digs.begin(), digs.end()); int ans = 1; for (int i = 0; i < digs.size(); i++) { ans *= 2; if (digs[i]... |
#include <bits/stdc++.h> using namespace std; const int N = 505, M = 10; int ST[N][N][M][M], a[N][N], lg[N]; void build(int n, int m) { for (int i = 2; i <= max(n, m); i++) { lg[i] = lg[i / 2] + 1; } for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { ST[i][j][0][0] = a... |
#include <bits/stdc++.h> using namespace std; const int N = 105; const int M = 2005; pair<pair<int, int>, pair<int, int> > adj[N]; int dp[M]; vector<int> way[M]; bool cmp(pair<pair<int, int>, pair<int, int> > a, pair<pair<int, int>, pair<int, int> > b) { return a.second.second < b.second.se... |
#include <bits/stdc++.h> const double eps = 1e-9; using namespace std; double f[2050], p[2050], q[2050]; int fa[2050], fb[2050]; int n, a, b; void calc(double w1, double w2) { for (int i = 1; i <= n; i++) { f[i] = f[i - 1]; fa[i] = fa[i - 1]; fb[i] = fb[i - 1]; if (f[i - 1] + p[i... |
#include <bits/stdc++.h> using namespace std; const int MAXN = 100 + 10; int n, m; int main() { cin >> n >> m; cout << n + m - 1 << endl; cout << 1 1 << endl; for (int i = 2; i <= n; ++i) cout << i << 1 << endl; for (int i = 2; i <= m; ++i) cout << 1 << i << endl; fclose(stdin); ... |
#include <bits/stdc++.h> using namespace std; const int N = 200005; int n, ans, root; int f[N], fa[N]; inline int read() { int a = 0, f = 1; char c = getchar(); while (c < 0 || c > 9 ) { if (c == - ) f = -1; c = getchar(); } while (c >= 0 && c <= 9 ) { a = a * 10 +... |
#include <bits/stdc++.h> using namespace std; int nr, N, K, ap[100009], last_N; pair<int, int> ans[10]; struct line { int a, b, c, init; }; vector<line> v; struct point { long long a, b, c, d; bool operator==(const point &other) const { return (1LL * a * other.b == 1LL * b * other.a && ... |
#include <bits/stdc++.h> using namespace std; const int maxn = 1e3 + 50; const int INF = 1e9 + 7; struct Edge { int from, to, cap, flow, cost; Edge(int from, int to, int cap, int flow, int cost) : from(from), to(to), cap(cap), flow(flow), cost(cost) {} }; struct MCMF { vector<Edge> edge;... |
#include <bits/stdc++.h> int n, m; int a[2000]; int b[2000]; int can[2000]; using namespace std; int main() { int c = 0; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i] >> b[i]; } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (i != j && !can[j] &&... |
#include <bits/stdc++.h> using namespace std; int n, m, k, d[1010][1010], inf, sx, sy, tx, ty, dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1}; char s[1010][1010]; struct P { int x, y; } u, v; int tmp; queue<P> q; int main() { memset(d, 33, sizeof d)... |
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); int n; cin >> n; int sum1 = 0, sum2 = 0, sum3 = 0; int flag1 = 1, flag2 = 0, flag3 = 0; for (int i = 1; i <= n; i++) { int a; cin >> a; if (flag1) { sum1 += a; flag1 = 0;... |
#include <bits/stdc++.h> using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); long long binpow(long long a, long long b) { long long res = 1; while (b != 0) { if (b & 1) res *= a, res %= 1000000007; a *= a, a %= 1000000007; b >>= 1; } return r... |
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e5 + 10; int fn[2][MAXN], a[2][MAXN], ans[MAXN], fans[MAXN]; void add(int p, int val, int id) { for (++p; p < MAXN; p += p & (-p)) fn[id][p] += val; } int get(int p, int id) { int res = 0; for (; p > 0; p -= p & (-p)) res += fn[id][... |
#include <bits/stdc++.h> const int MAXN = 100005; int n; char s[MAXN]; int B = 0, R = 0; int main() { while (scanf( %d , &n) != EOF) { scanf( %s , s); int res = 0; B = 0, R = 0; char pre; for (int i = 0; i < n; i++) { if (i == 0) { pre = s[0]; cont... |
#include <bits/stdc++.h> using namespace std; const long long mx = (1e5) + 1; const long long mod = 1000000007; int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int a, b, x; cin >> a >> b >> x; if (x % 2 == 0) { if (a > b) { for (int i = 0; i < x / 2;... |
#include <bits/stdc++.h> using namespace std; int n, m, k, i, x, y, z, suma; pair<int, pair<int, int> > r1, r2, tr0, v[35]; map<pair<int, pair<int, int> >, pair<int, pair<int, int> > > mp; pair<int, pair<int, int> > make_triplet(int x, int y, int z) { return make_pair(x, make_pair(y, z)); } int getSum... |
#include <bits/stdc++.h> using namespace std; inline void PAUSE() { char tmp; cin >> tmp; } int main() { int f1 = 0, f2 = 0, f3 = 0; char s[101]; cin >> s; int i = 0; while (s[i] != 0 ) { if (s[i] - 0 >= 0 && s[i] - 0 <= 9) f1 = 1; if (s[i] >= a && s[i] <= z ) f2... |
#include <bits/stdc++.h> using namespace std; void yes() { cout << YES << n ; } void no() { cout << NO << n ; } int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } void main_() { string s; cin >> s; int n; n = s.size(); int a, b, c; a = b = c = 0; ... |
#include <bits/stdc++.h> using namespace std; void parr(int arr[], int n, string name) { int i; for (i = 0; i < n; i++) cout << arr[i] << ; cout << n ; } long long int fn(int arr[], int n) { int i; long long int pre[n]; sort(arr, arr + n, greater<int>()); pre[0] = arr[0]; fo... |
#include <bits/stdc++.h> using namespace std; int main() { int n, x, y, count = 0; cin >> n; pair<int, int> a[3005]; set<pair<int, int>> s; for (int i = 0; i < n; i++) { cin >> x >> y; a[i] = pair<int, int>(x, y); s.insert(a[i]); } for (int i = 0; i < n; i++) { fo... |
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const int maxn = 1e5 + 50; const int inf = 1e8 + 10; int l[maxn], e[maxn]; int bs(int a[], int x, int n) { int l = 0, r = n; int m; while (l < r) { m = (l + r) / 2; if (a[m] >= x) r = m; else ... |
#include <bits/stdc++.h> using namespace std; const int N = 1234567; int fenw[N]; void modify(int x, int v) { while (x < N) { fenw[x] += v; x = (x | (x - 1)) + 1; } } int find_sum(int x) { int v = 0; while (x > 0) { v += fenw[x]; x &= x - 1; } return v; } ... |
#include <bits/stdc++.h> using namespace std; string str, txt; int main() { while (cin >> str) { int ind = -1; int n = str.size(); for (int i = n - 1; i >= 0; i--) if (str[i] == 2 ) ind = i; if (ind == -1) { sort(str.begin(), str.end()); txt = str; } else... |
#include <bits/stdc++.h> using namespace std; inline int abs(int x) { return x > 0 ? x : (-x); } int len[505], rod[505], flag[505], mask[505]; int main() { int n, m, x, y, x1, y1, i, j, x0, y0; while (scanf( %d%d , &n, &m) != EOF) { scanf( %d%d , &x1, &y1); x0 = x1, y0 = y1; for (i = 1... |
#include <bits/stdc++.h> using namespace std; int main() { long long int m, n, row[1010], col[1010], ans = 0, sum = 0; char a[1010][1010]; cin >> m >> n; memset(row, 0, sizeof row); memset(col, 0, sizeof col); for (long long int i = 0; i < m; i++) for (long long int j = 0; j < n; j++) ... |
#include <bits/stdc++.h> using namespace std; long long quick(long long x, long long m) { long long ans = 1; while (m > 0) { if (m % 2 == 1) ans *= x; x = x * x; m = m / 2; } return ans; } int main() { long long a, b, k; scanf( %lld%lld%lld , &a, &b, &k); int flag =... |
#include <bits/stdc++.h> using namespace std; bool Geo(vector<int>& a) { int n = a.size(); if (n == 1) return true; if (n == 2) { if (a[0] == 0 && a[1] != 0) return false; return true; } if (a[1] == 0) { for (int i = 2; i < n; ++i) if (a[i] != 0) return false; ret... |
#include <bits/stdc++.h> using namespace std; const long long INF = 1e9; const long long MOD = 1e9 + 7; const long long maxn = 1e5 + 7; const long long maxm = 2e5 + 7; struct Edge { int end, idx, label, vis; }; vector<Edge> adj[maxn]; vector<int> deg[maxn]; int n, ans[maxn], vis[maxn]; int mai... |
#include <bits/stdc++.h> using namespace std; int n, i, ans; int main() { cin >> n; for (int i = 1; i <= n; i += 2) ans += n - i + 1; cout << ans; } |
#include <bits/stdc++.h> using namespace std; struct node { int l; int r; int val; }; node tree[800010]; vector<int> pre[200010]; int ary[200010]; int n, q; void pushup(int cur) { tree[cur].val = min(tree[2 * cur].val, tree[2 * cur + 1].val); } void build(int l, int r, int cur) { ... |
#include <bits/stdc++.h> using namespace std; vector<int> domain; int domain_index(int x) { int id = lower_bound(domain.begin(), domain.end(), x) - domain.begin(); assert(domain[id] == x); return id; } struct Seg { Seg *lc, *rc; int L, M, R; int sum, val; Seg(int l, int r) : L(l), ... |
#include <bits/stdc++.h> using namespace std; long long d[10000005]; int snt[664600], dem; bool p[10000005]; void sieve() { int i, j; snt[0] = 2, dem = 1; p[0] = p[1] = true; for (i = 4; i <= 1e7; i += 2) p[i] = true; for (i = 3; i <= 3163; i += 2) if (!p[i]) { snt[dem++] = i... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); string a, b; cin >> a >> b; string aa = , bb = ; int i = 0; for (; i < a.size(); i++) { if (a[i] != 0 ) break; } for (; i < a.size(); i++) aa += a[i]; ... |
#include <bits/stdc++.h> using namespace std; string name[1010]; int score[1010]; bool good[1010]; map<string, int> mp; int main(void) { int N, i; cin >> N; for ((i) = 0; (i) < (int)(N); (i)++) cin >> name[i] >> score[i]; for ((i) = 0; (i) < (int)(N); (i)++) mp[name[i]] += score[i]; int ... |
#include <bits/stdc++.h> using namespace std; int t, i, j, n, r, it, cc, best, u[22], msk[22], bc[1100100], ok[1100100]; bool c[22][22]; char a[100100], b[100100]; void dfs(int i) { u[i] = it; for (int j = 0; j < 20; j++) if ((c[i][j] || c[j][i]) && u[j] != it) dfs(j); } int main() { sca... |
#include <bits/stdc++.h> using namespace std; const int maxn = 1000 + 10; long long n, m, a, b; long long arr[maxn][maxn]; long long sum[maxn][maxn]; long long Min[maxn][maxn]; set<pair<long long, pair<long long, long long> > > s; multiset<long long> s_; long long minr[maxn][maxn]; long long ground[... |
#include <bits/stdc++.h> using namespace std; int n; int main() { ios::sync_with_stdio(false); cin.tie(0); int test; cin >> test; while (test--) { cin >> n; vector<int> a; int mini = -1; int ii; for (ii = 2; ii * ii < n; ii++) { if (n % ii != 0) continue; ... |
#include <bits/stdc++.h> using namespace std; int longestSubstring(string s) { int i, j; int l = s.length(); int maxi = 0; map<string, int> mpp; for (i = 0; i < l; i++) { string temp = ; for (j = i; j < l; j++) { temp += s[j]; mpp[temp]++; maxi = max(maxi, m... |
#include <bits/stdc++.h> using namespace std; int n; struct node { int pos, len; friend bool operator<(node a, node b) { return a.len > b.len; } } f[100005]; vector<int> po; int main() { scanf( %d , &n); for (int i = 1; i <= n; i++) { int x = i * 2 - 1; f[i].pos = x; scanf(... |
#include <bits/stdc++.h> using namespace std; template <typename T1, typename T2> bool mini(T1 &a, T2 b) { if (a > b) { a = b; return true; } return false; } template <typename T1, typename T2> bool maxi(T1 &a, T2 b) { if (a < b) { a = b; return true; } return... |
#include <bits/stdc++.h> using namespace std; int n, m, k; int a[100001], b[100001], c[100001]; vector<int> rev[100001]; vector<int> e[100001]; int get(int far) { int cur = k; for (int i = 1; i <= n; i++) { int x = e[i].back(); rev[x].push_back(i); } priority_queue<int, vector<in... |
#include <bits/stdc++.h> bool o; int n, m, k, a, t; int dp[2][775], suf[776]; struct poi { int r, c; } p[100010]; bool operator<(poi x, poi y) { return x.c < y.c; } int main() { scanf( %d%d , &n, &k), m = sqrt(6 * k); for (int i = 1; i <= k; ++i) { scanf( %d%d , &p[i].r, &p[i].c); ... |
#include <bits/stdc++.h> using namespace std; int mod = 1e9 + 7, N = 2e5; int mul(int a, int b) { return (a * 1LL * b) % mod; } int mul2(int a, int b) { return (a * 1LL * b) % (mod - 1); } int Pow(int v, long long p) { int ans = 1; while (p) { if (p & 1) { ans = mul(ans, v); } ... |
#include <bits/stdc++.h> int main() { int life[200001], N, a, i; for (i = 0; i < 200001; i++) life[i] = 0; scanf( %d , &N); for (i = 0; i < N; i++) { scanf( %d , &a); if (a != 0) life[a + 100000] = 1; } int diff = 0; for (i = 0; i < 200001; i++) diff += life[i]; printf( %d ... |
#include <bits/stdc++.h> using namespace std; int main() { int n, m; scanf( %d %d , &n, &m); string s; cin >> s; while (m--) { int a1, a2; char a3, a4; scanf( %d %d %c %c , &a1, &a2, &a3, &a4); a1--; a2--; while (a1 <= a2) { if (s[a1] == a3) s[a1] = a4... |
#include <bits/stdc++.h> using namespace std; int num[27]; int num2[27]; inline int idx(char a) { return a - a ; } char sa[5555], sb[5555], sans1[5555], sans2[5555], sans[5555]; inline char rev(int id) { return a + id; } int lena, lenb; bool ans1, ans2; int main() { scanf( %s , sa); scanf( ... |
#include <bits/stdc++.h> using namespace std; const int MAXN = 200100; int arr[MAXN], tmp[MAXN]; vector<int> ve[MAXN]; map<pair<int, int>, vector<int> > mapa; int ind[MAXN]; vector<int> out[MAXN]; int sol = 0; vector<int> t1, t2; vector<int> comp; map<int, int> aaa; void tour(int x, int i) { ... |
#include <bits/stdc++.h> using namespace std; void solve() { long long n, m; cin >> n >> m; set<long long> s; vector<long long> ar(n + 1, 0); for (long long i = 0; i < n; i++) { s.insert(i + 1); } for (long long i = 1; i <= m; i++) { long long li, ri, xi; vector<long lo... |
#include <bits/stdc++.h> using namespace std; const int INF = 1000000002; const long long INFLL = 100000000000000000ll; const long long MOD = 1000000007; int Cycle[100005], N, Real[100005], Pos[100005], V[100005], P[100005][20], D[100005], Edg, K; long long M[100005]; vector<int> E[100005], E2[10000... |
#include <bits/stdc++.h> using namespace std; const int MAXN = 20; const int X = 1 << MAXN; int N, M, K; long long a[MAXN]; long long p[MAXN][MAXN]; long long dp[MAXN][X + 5]; long long max(long long a, long long b) { return a > b ? a : b; } int main() { scanf( %d %d %d , &N, &M, &K); for (int... |
#include <bits/stdc++.h> using namespace std; const long long N = 4e5 + 5, M = 998244353, OO = 0x3f3f3f3f; int t, n; int a[N], b[N]; bool ok; set<pair<int, int>> st; map<pair<int, int>, int> ma; int main() { cin >> t; while (t--) { cin >> n; for (int i = 0; i < n; ++i) cin >> a[i]; ... |
#include <bits/stdc++.h> using namespace std; int main() { int n; set<int> s; cin >> n; int i, j; for (i = 0; i < n; i++) { cin >> j; if (j != 0) s.insert(j); } cout << s.size(); } |
#include <bits/stdc++.h> using namespace std; const long long N = 5e5 + 20; long long n, m, k; long long col[N]; vector<long long> g[N]; struct edge { long long u, v; } e[N]; long long ans; long long dead[N]; map<pair<long long, long long>, bool> vis; map<pair<long long, long long>, vector<pai... |
#include <bits/stdc++.h> using namespace std; const int Maxn = 1000 * 100 + 10; int m[Maxn], c[Maxn], eatd[Maxn]; int ans; int INF = 1000 * 1000 * 10 + 10; int main() { int N, M, y; cin >> N >> M >> y >> y; for (int i = 0; i < N; i++) cin >> m[i]; c[0] = -INF; c[M + 1] = INF; for (in... |
#include <bits/stdc++.h> using namespace std; const long long inf = 0x3f3f3f3f3f3f3f3f; long long n, m, mod, a[1000010]; inline long long max(long long x, long long y) { return (x > y ? x : y); } inline long long min(long long x, long long y) { return (x < y ? x : y); } struct Segment_Tree { vector<long... |
#include <bits/stdc++.h> using namespace std; const int maxn = 1e2 + 10; bool vis[maxn]; int main() { int n, k; cin >> n >> k; for (int i = 0; i < n; i++) { int x; cin >> x; vis[x] = true; } int ans = 0; for (int i = 0; i < k; i++) if (!vis[i]) ans++; if (vis[... |
#include <bits/stdc++.h> using namespace std; const int N = (int)123; long long dp[N]; void solve() { long long n, k; scanf( %lld %lld , &n, &k); if (k == 1) { printf( YES %lld n , n - 1); return; } if (n > 31) { printf( YES %d n , n - 1); return; } long long ... |
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[11][11] = {1}; for (int i = 0; i < n; i++) { a[i][0] = 1; a[0][i] = 1; } for (int i = 1; i < n; i++) { for (int j = 1; j < n; j++) { a[i][j] = a[i - 1][j] + a[i][j - 1]; } } ... |
#include <bits/stdc++.h> #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; vector<int> v1, v2, ps1, ps2; string s1, s2, aux1, aux2; vector<pair<int, int>> ans, aux; void addLast(string &st... |
#include <bits/stdc++.h> using namespace std; int n, m; int main() { scanf( %d%d , &n, &m); while (n--) { int a, b, t, ans; scanf( %d%d%d , &a, &b, &t); if (a == b) { printf( %d n , t); continue; } int d = t / (m - 1); ans = d * (m - 1); if (d % 2 ... |
#include <bits/stdc++.h> using namespace std; int rd(int &x) { return scanf( %d , &x); } int rd(int &x, int &y) { return scanf( %d %d , &x, &y); } int rd(int &x, int &y, int &z) { return scanf( %d %d %d , &x, &y, &z); } int rd(int &x, int &y, int &z, int &s) { return scanf( %d %d %d %d , &x, &y, &z, &s); ... |
#include <bits/stdc++.h> template <typename T> inline bool chkmin(T &a, T b) { return b < a ? a = b, true : false; } template <typename T> inline bool chkmax(T &a, T b) { return b > a ? a = b, true : false; } template <class T> inline T read(T &x) { int sign = 1; char c = getchar_unlocke... |
#include <bits/stdc++.h> using namespace std; long long n, ans; long long f(long long x) { return 3 * x * (x + 1) / 2 - x; } int main() { ios_base::sync_with_stdio(false); cin >> n; ans = 0; for (long long i = 1; f(i) <= n; i++) { if ((n + i) % 3 == 0) { ans++; } } co... |
#include <bits/stdc++.h> using namespace std; int n = 0, c = 0; float y = 0; int main() { if (!n) { scanf( %d , &n); main(); } else if (c == n) { printf( %.3f , 5 + y / n); return 0; } else { float x; scanf( %*f %f , &x); y += x; c++; main(); ... |
#include <bits/stdc++.h> using namespace std; vector<int> con[100005]; int coun[100005]; void serc(int x, int l) { coun[l]++; for (int i = 0; i < con[x].size(); i++) { serc(con[x][i], l + 1); } return; } int main() { int n; cin >> n; int a; for (int i = 2; i <= n; i++) ... |
#include <bits/stdc++.h> using namespace std; long long cil(long long x, long long y) { if (x % y == 0) { return x / y; }; return x / y + 1; } void solve() { long long n; cin >> n; vector<long long> sizes; vector<vector<long long>> a(n); for (long long i = 0; i < n; i++) { ... |
#include <bits/stdc++.h> using namespace std; using ll = long long; const int N = (int)1e5 + 5; int _ = 1; int n, q; int a[N], pos[N]; int nex[N], blo; int calc(int x) { for (int i = 1; i <= blo; i++) x = a[x]; return x; } void work() { scanf( %d%d , &n, &q); blo = sqrt(n) + 1; f... |
#include <bits/stdc++.h> int main() { char a[60]; int l; while (scanf( %s , a) != EOF) { int b = 0; l = strlen(a); for (int i = 0; i < l; i++) { if (a[i] != a[l - i - 1]) { b++; } } if (b) printf( %d n , l); if (b == 0) { int s = 0; ... |
#include <bits/stdc++.h> int main() { int s; scanf( %d , &s); char t[s]; scanf( %s , t); int i, count = 0; for (i = 0; i < s; ++i) { if (t[i] == t[i + 1]) ++count; } printf( %d , count); } |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.