func_code_string stringlengths 59 71.4k |
|---|
#include <bits/stdc++.h> using namespace std; const int NMAX = 300000; const double eps = 1e-6; double sy, a, b; int n, q; double L[NMAX], R[NMAX]; double sum[NMAX]; int dcmp(double x, double y) { if (fabs(x - y) < eps) return 0; if (x > y) return 1; return -1; } int bin_search(double x)... |
#include <bits/stdc++.h> using namespace std; inline long long int gcd(long long int a, long long int b) { return b ? gcd(b, a % b) : a; } inline long long int fast_pow(long long int a, long long int b, long long int mod) { long long int res = 1; a %= mod; while (... |
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5, MOD = 1e9 + 7; const double EPS = 1e-9; double PI = acos(-1); double square(long long x) { double ret = double(x) * double(x); return ret; } vector<pair<double, int> > V; double deg(double x) { return (x * 180) / PI; } double... |
#include <bits/stdc++.h> long long CMB[50][50]; void computeCMB() { for (long long i = 0; i < 50; ++i) { CMB[i][0] = 1; for (long long j = 1; j <= i; ++j) { CMB[i][j] = CMB[i - 1][j - 1] + CMB[i - 1][j]; } } } long long n; long long pathsFrom(long long i, long long j) { l... |
#include <bits/stdc++.h> using vi = std::vector<long long int>; using vvi = std::vector<vi>; using pii = std::pair<long long int, long long int>; using vpii = std::vector<pii>; using vvpii = std::vector<vpii>; using namespace std; const long long int N = 2e6 + 10; const long long int inf = 1e18 + 10; ... |
#include <bits/stdc++.h> #pragma GCC optimize( O3 ) #pragma GCC optimize( unroll-loops ) #pragma GCC target( avx2 ) using namespace std; const int MOD = 1000 * 1000 * 1000 + 7; signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int a, b, x1, y1, x2, y2; cin >> a >> b >> x1 >> y... |
#include <bits/stdc++.h> using namespace std; vector<int> a[200005], b; set<int> c1; int n, k, p, f[200005], x[200005], c[200005], c2[200005]; int getdeepth(int i) { for (vector<int>::iterator j = a[i].begin(); j != a[i].end(); j++) if ((*j) != f[i]) { f[*j] = i; int x = getdeepth(*j... |
#include <bits/stdc++.h> using namespace std; int n, val[200100], m; set<pair<int, int> > s[200100]; struct opt { int tp, x, y; } q[200100]; inline void read(int &x) { x = 0; register char c = getchar(); while (c > 9 || c < 0 ) c = getchar(); while (c >= 0 && c <= 9 ) x = (x ... |
#include <bits/stdc++.h> template <typename T, typename U> inline void swap(T &a, U &b) { a = a ^ b; b = a ^ b; a = a ^ b; } inline void swap(int &a, int &b) { a = a ^ b; b = a ^ b; a = a ^ b; } inline void swap(long long &a, long long &b) { a = a ^ b; b = a ^ b; a = a ^ ... |
#include <bits/stdc++.h> using namespace std; int main() { long long n, m, i, j; string s; cin >> s; n = s.size(); string cur; if (s.size() <= 6) { cout << 0; return 0; } for (i = 5; i < s.size(); i++) { cur += s[i]; } if (cur.size() == 2) { cout << 1 ... |
#include <bits/stdc++.h> using namespace std; int main() { int a, k1 = 0, k2 = 0; cin >> a; string h; cin >> h; string *s = new string[a]; for (int i = 0; i < a; i++) { cin >> s[i]; if (s[i].substr(s[i].size() - 3, 3) == h) k1++; else k2++; } if (k1 ... |
#include <bits/stdc++.h> using namespace std; int main() { long long p, d, i, j, tmp, res; cin >> p >> d; res = p; for (i = 999999999999999999ll; i; i /= 10) { j = i + 1; if (i > p) continue; if (i == p) break; if (p % j == i) { tmp = (p / j) * j + i; if (p - ... |
#include <bits/stdc++.h> using namespace std; const int mason[] = {2, 3, 5, 7, 13, 17, 19, 31, 61, 89, 107, 127, 521, 607, 1279, 2203, 2281, 3217, 4253, 4423, 9689, ... |
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6; int n; int l[maxn], c[maxn]; int gcd(int x, int y) { if (x == 0) return y; else return gcd(y % x, x); } map<int, int> mp; int main() { while (scanf( %d , &n) != EOF) { for (int i = 1; i <= n; i++) scanf( %d... |
#include <bits/stdc++.h> using namespace std; long long n, mx[400000], mn[400000]; long long seg[400000 * 4]; vector<long long> compress(vector<long long> x) { vector<long long> ans = x; vector<pair<long long, long long>> p; p.push_back({0, 0}); for (long long i = 1; i < x.size(); i++) { p... |
#include <bits/stdc++.h> using namespace std; const int maxn = 25; const int maxm = 3000; char maze[maxn][maxn]; int g[maxn * maxn][maxn * maxn]; int n, m, N, M; int src, sink; long long ans; struct Node { int r, c, t; Node() {} Node(int r, int c, int t) : r(r), c(c), t(t) {} }; vector... |
#include <bits/stdc++.h> int n; long long ans = 0x7fffffffffffffff, sum, p[1000002]; int a[1000002], b[1000002], c[1000002], pcnt; inline int abs(int x) { return x > 0 ? x : -x; } signed main() { scanf( %d , &n); for (register int i = 1; i <= n; i++) scanf( %d , &a[i]), sum += a[i]; register long ... |
#include <bits/stdc++.h> int main() { int a, b, y, ans; scanf( %d%d , &a, &b); y = a * b; ans = y / 2; printf( %d , ans); return 0; } |
#include <bits/stdc++.h> using namespace std; int main() { int n, k; long long res = 0; cin >> n; vector<bool> v(6000, false); for (int i = 0; i < n; ++i) { cin >> k; if (!v[k - 1]) v[k - 1] = true; else while (v[k - 1]) { ++res; ++k; ... |
#include <bits/stdc++.h> using namespace std; const long long int mod = 1000000007; int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); long long int n, h; cin >> n >> h; long long int arr[n]; for (long long int i = 0; i < n; i++) cin >> arr[i]; long long int ... |
#include <bits/stdc++.h> using namespace std; int main() { int n, p, q, a, c = 1, b; cin >> n; cin >> a >> b; p = a; q = b; int num = n; n--; int max = 1; while (n--) { cin >> a >> b; if (p == a && q == b) { c++; } else if (c > 1) { if (max < c) ... |
#include <bits/stdc++.h> using namespace std; const int M = 2e5; int infty = 1e9; int p[M], t[M]; int main() { int n, d, h; cin >> n >> d >> h; if (2 * h < d || (n > 2 && d == 1)) { cout << -1 << n ; } else { int h1 = h, h2 = d - h, cur = 2; for (int i = 0; i < h; i++) { ... |
#include <bits/stdc++.h> #pragma comment(linker, /STACK:102400000,102400000 ) using namespace std; int a[(100000 + 10)], cur[(100000 + 10)]; double dp[(100000 + 10)][110]; int C[110][110]; void init() { C[0][0] = 1; int n = 110; for (int i = 1; i < n; ++i) { C[i][0] = C[i][i] = 1; f... |
#include <bits/stdc++.h> using namespace std; const long long N = 1e6 + 10, P = 1e9 + 7, U = 1e6 - 1; long long f1[N], f2[N], f3[N], n, A[N], t[N], val[N], bit[N], ans; int main() { cin >> n; for (long long i = bit[0] = 1; i <= 6; i++) bit[i] = 10 * bit[i - 1]; for (long long i = t[0] = 1; i <= n; i... |
#include <bits/stdc++.h> int main() { long long t; scanf( %lld , &t); long int n, x = 1; for (int i = 0; i < t; i++) { scanf( %ld , &n); int k = 1, p = 1, x; for (; p <= n;) { k++; p = p + pow(2, k - 1); if (n % p == 0) { x = n / p; break; ... |
#include <bits/stdc++.h> #pragma GCC omptimize( unroll-loops ) #pragma optimize( SEX_ON_THE_BEACH ) #pragma GCC optimize( no-stack-protector ) #pragma comment(linker, /STACK:1000000000 ) using namespace std; using ll = long long int; using ull = unsigned long long int; using dd = long double; using l... |
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int t; cin >> t; while (t--) { int n; cin >> n; std::vector<pair<long long int, long long int> > ev; std::vector<pair<long long int, long long int> > od; for (int i = 1; ... |
#include <bits/stdc++.h> using namespace std; void FAST(); long long int big_mod(long long int val, long long int pow, long long int mod); long long int mod_inverse(long long int val, long long int mod); int main() { FAST(); int m, n; scanf( %d %d , &n, &m); if (m < 2) { printf( 1 ); ... |
#include <bits/stdc++.h> using namespace std; int n, d; long long h[100001]; struct A { long long h; int i; bool operator<(const A &B) const { return h < B.h || h == B.h && i < B.i; } } H[100001]; map<long long, int> MP; map<long long, int> MPSORT; int N, Kn; int st[100001 << 2]; int sti... |
#include <bits/stdc++.h> using namespace std; const int maxn = 5007; int a[maxn], b[maxn], n, m, g[maxn]; int gcd(int a, int b) { if (a < b) return gcd(b, a); if (b == 0) return a; return gcd(b, a % b); } bool found(int v) { int l = 1, r = m, mid; while (l <= r) { mid = (l + r) / 2... |
#include <bits/stdc++.h> using namespace std; int main() { int n, x, y; char sex; int m[367], f[367]; memset(m, 0, sizeof(m)); memset(f, 0, sizeof(f)); cin >> n; for (int i = 0; i < n; i++) { cin >> sex >> x >> y; if (sex == M ) { for (int j = x; j <= y; j++) m[j]++;... |
#include <bits/stdc++.h> using namespace std; int main() { int j = 0; string a, b; cin >> a; cin >> b; for (int i = a.length() - 1; i >= 0; i--) { if (a[i] == b[j]) { j++; } else { cout << NO ; return 0; } } cout << YES ; } |
#include <bits/stdc++.h> using namespace std; bool isPrime(int n) { if (n <= 3) { return true; } if (n % 2 == 0 || n % 3 == 0) return false; for (int i = 5; i * i <= n; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } int main() { ios_base::sync_wit... |
#include <bits/stdc++.h> using namespace std; int main() { int n, m, r, i; cin >> n >> m; r = m % ((n * (n + 1) / 2)); for (i = 0; i < n; i++) { if (i + 1 > r) { cout << r; break; } else r -= i + 1; } return 0; } |
#include <bits/stdc++.h> #pragma GCC optimize( O3 ) #pragma GCC target( sse4 ) using namespace std; const int dx[8] = {1, 1, 1, 0, 0, -1, -1, -1}; const int dy[8] = {1, -1, 0, 1, -1, -1, 1, 0}; template <class T> T gcd(T a, T b) { return ((b == 0) ? a : gcd(b, a % b)); } int n, m; vector<string>... |
#include <bits/stdc++.h> using namespace std; long long int inf = pow(10, 9); int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long int n; cin >> n; vector<pair<long long int, string>> v(n); for (long long int i = 0; i < n; ++i) cin >> v[i].first >> v[i].second;... |
#include <bits/stdc++.h> using namespace std; string s, t; int dp[1005][1005]; int solve(int i, int j) { if (i == s.size()) return t.size() - j; if (j == t.size()) return s.size() - i; if (dp[i][j] != -1) return dp[i][j]; if (s[i] == t[j]) return solve(i + 1, j + 1); int c1 = solve(i + 1, j ... |
#include <bits/stdc++.h> using namespace std; void solve() { int a, b, c, d, e, f; cin >> a >> b >> c >> d >> e >> f; int suit1 = min(a, d); int suit2 = min(b, min(c, d)); long long cost = 0; for (int i = 0; i <= suit1; i++) { long long temp = i * e; temp += min(b, min(c, d - i))... |
#include <bits/stdc++.h> using namespace std; const int BITS = 20; template <typename T> struct xor_basis { T basis[BITS]; int n = 0; T min_value(T start = 0) const { for (int i = 0; i < n; i++) start = min(start, start ^ basis[i]); return start; } T max_value(T start = 0) const ... |
#include <bits/stdc++.h> using namespace std; template <class T> inline T bigmod(T p, T e, T M) { T 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; retu... |
#include <bits/stdc++.h> using namespace std; int knigths[300006]; set<int> s; int main() { ios_base::sync_with_stdio(0); cin.tie(NULL), cout.tie(NULL); ios::sync_with_stdio(false), cin.tie(0); int n, m; cin >> n >> m; for (int i = 1; i <= n + 1; i++) s.insert(i); for (int i = 0; i <... |
#include <bits/stdc++.h> using namespace std; const int MAXN = 4e5 + 5; const string s[] = { NW , NE , SE , SW }; inline int read() { int x = 0; char ch = getchar(); while (!isdigit(ch)) ch = getchar(); while (isdigit(ch)) { x = x * 10 + ch - 0 ; ch = getchar(); } return ... |
#include <bits/stdc++.h> using namespace std; int main() { long long t; cin >> t; while (t--) { long long n; cin >> n; vector<int> v(n); for (int i = 0; i < (int)n; ++i) cin >> v[i]; sort((v).begin(), (v).end()); for (int i = (int)n - 1; i >= 0; --i) cout << v[i] << ... |
#include <bits/stdc++.h> using namespace std; string s; map<string, vector<int> > m; map<string, int> memoria; string codigo(string s1, string s2) { return s1 + # + s2; } int calculadicot(int la, vector<int> &va, int lb, vector<int> &vb) { int sol = 1000000000; for (int ia = 0; ia < int(va.size())... |
#include <queue> #include <cstdio> #include <cstring> using namespace std; const int Maxn=200000; const int Inf=0x3f3f3f3f; int n,k; int head[Maxn+5],arrive[Maxn<<1|5],nxt[Maxn<<1|5],tot; void add_edge(int from,int to){ arrive[++tot]=to; nxt[tot]=head[from]; head[from]=tot; } queue<int> q; ... |
#include <bits/stdc++.h> using namespace std; const int N = 1000000 + 5; int vis[N], n, m; pair<int, int> Get(int x) { int a, b; if (x >= n) a = x - n + 1; else a = n - x + 1; x = m - x + 1; if (x >= n) b = m - (x - n + 1) + 1; else b = m - (n - x + 1) + 1; re... |
#include <bits/stdc++.h> using namespace std; int gcd(int a, int b) { if (a == 0) return b; if (b == 0) return a; if (a == b) return a; if (a > b) return gcd(a - b, b); return gcd(a, b - a); } void sol() { long long int L, v, l, r, count = 0; cin >> L >> v >> l >> r; long long in... |
#include <bits/stdc++.h> using namespace std; int main() { int n; long long x, y, z; scanf( %d , &n); for (int i = 1; i <= n; i++) { long long ans = 0; scanf( %lld%lld , &x, &y); if (x >= y) { ans += y; printf( %lld n , ans); continue; } long lon... |
#include <bits/stdc++.h> using namespace std; const int N = 200005, P = 1000000007; int n, l[N], r[N], p[N], p2[N], ans; int power(int a, int x) { int ans = 1; for (; x; x >>= 1, a = 1LL * a * a % P) if (x & 1) ans = 1LL * ans * a % P; return ans; } int main() { scanf( %d , &n); fo... |
#include <bits/stdc++.h> using namespace std; int main() { int n; string s; cin >> s; int count = 0, check = 0; for (int i = 0; i < s.size(); i++) { if (s[i] == 1 ) { check = 1; } if (check == 1 && s[i] == 0 ) count++; } if (count >= 6) cout << yes ; ... |
#include <bits/stdc++.h> using namespace std; int value[100005]; int main() { int n, k, m; while (cin >> n >> k >> m) { map<string, int> mymap; for (int i = 1; i <= n; i++) { string s; cin >> s; mymap[s] = i; } for (int i = 1; i <= n; i++) scanf( %d , &value... |
#include <bits/stdc++.h> using namespace std; int main() { char a[250]; int k; cin >> a; cin >> k; int temp = k; int curr = 0; a[strlen(a)] = 0 ; if (strlen(a) > 1) { while (temp) { int max_v = a[curr] - 48, max_p = curr; for (int j = curr + 1; j <= curr + tem... |
#include <bits/stdc++.h> using namespace std; const int maxn = 105; int n, m; char g[maxn][maxn]; int vis[3]; map<char, int> mp; int main() { mp[ R ] = 0; mp[ G ] = 1; mp[ B ] = 2; scanf( %d%d , &n, &m); for (int i = 0; i < n; i++) scanf( %s , g[i]); bool ok = true; if (g[0][0]... |
#include <bits/stdc++.h> #pragma comment(linker, /STACK:256000000 ) using namespace std; const long long inf = 1e18; const double eps = 1e-9; const double pi = 4 * atan(1.0); const int N = int(2e5) + 100; const int ITERS = 80; int m; pair<int, int> a[N]; vector<pair<int, int> > group[N]; long lon... |
#include <bits/stdc++.h> using namespace std; const int INF = (int)1e9; int main() { int n; cin >> n; long long int a; cin >> a; while (1) { if (a % 2 == 0) a /= 2; else if (a % 3 == 0) a /= 3; else break; } bool f = 1; for (int i = 0; i < ... |
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; int nums[n]; for (int i = 0; i < n; i++) { cin >> nums[i]; } int ans = 0; int maxi = 0; int mini = 1e9; for (int i = 0; i < n; i++) { maxi = max(ma... |
#include <bits/stdc++.h> using namespace std; int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } int main() { int t; cin >> t; while (t--) { int n; cin >> n; int ar[n]; for (int i = 0; i < n; i++) { cin >> ar[i]; --ar[i]; } ... |
#include <bits/stdc++.h> using namespace std; void solve() { string Fillipino = po ; string Japanese1 = desu ; string Japanese2 = masu ; string Korean = mnida ; string s; cin >> s; long long n = s.size(); if (s.substr(n - 2, 2) == Fillipino) { cout << FILIPINO << endl; ... |
#include <bits/stdc++.h> using namespace std; vector<int> st; int main() { ios::sync_with_stdio(0); int n, x; cin >> n; for (int i = 0; i < n; i++) { cin >> x; if (st.empty()) st.push_back(x); else { st.push_back(x); while (st.size() > 1) { if (s... |
#include <bits/stdc++.h> using namespace std; const double ovo = 0.001; const double eps = 1e-14; double x, y, k[50005], b[50005]; struct node { double p, q; int tp, tq, id; } t[50005]; struct qwq { int pos, t, td, del; } c[100005]; double a[100005], d[100005]; int n, m, p[100005], sz; ... |
#include <bits/stdc++.h> using namespace std; int read() { int xx = 0, ff = 1; char ch = getchar(); while (ch > 9 || ch < 0 ) { if (ch == - ) ff = -1; ch = getchar(); } while (ch >= 0 && ch <= 9 ) { xx = xx * 10 + ch - 0 ; ch = getchar(); } return xx * ff;... |
#include <bits/stdc++.h> using namespace std; long long int mod = 1000000007; long long int store[2002][2002] = {0}; long long int ncrModp(long long int n, long long int r, long long int p) { long long int value[9999] = {0}; value[0] = 1; for (long long int e = 1; e <= n; e++) { store[e][0] = ... |
#include <bits/stdc++.h> using namespace std; template <class T> void show(T a, int n) { for (int i = 0; i < n; ++i) cout << a[i] << ; cout << endl; } template <class T> void show(T a, int r, int l) { for (int i = 0; i < r; ++i) show(a[i], l); cout << endl; } const int N = 20; const... |
#include <bits/stdc++.h> using namespace std; long long int gcd(long long int n1, long long int n2) { if (n2 != 0) return gcd(n2, n1 % n2); else return n1; } long long int power(long long int a, long long int b) { if (b == 0) return 1; if (b == 1) return a; long long int x = powe... |
#include <iostream> #include <string> #include <string.h> #include <cstring> #include <math.h> #include <iomanip> #include <vector> #include <cmath> #include <algorithm> #include <numeric> #include <cctype> #include <utility> #include <set> #include <map> #include <sstream> #include <itera... |
#include <bits/stdc++.h> using namespace std; int main() { int n; float x, y, avg = 0, result = 0; cin >> n; for (int i = 0; i < n; i++) { cin >> x >> y; avg += y; } avg = avg / n + 5; printf( %3f , avg); return 0; } |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0); int64_t a, b; cin >> a; a = a * (a + 1) / 2; while (cin >> b) a -= b; cout << a; } |
#include <bits/stdc++.h> using namespace std; const int N = 300005; int k, u, v, a[N], n; long long ans, dp[N]; vector<int> G[N]; void dfs(int u, int v, int flag) { dp[u] = a[u]; for (int i : G[u]) { if (i != v) { dfs(i, u, flag); dp[u] += max(dp[i], 0ll); } } if ... |
#include <bits/stdc++.h> using namespace std; int main() { long long a[36] = { 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8092, 16184, 32368, 64736, 129472, ... |
#include <bits/stdc++.h> using namespace std; const int MAXN = 1024; double p[MAXN][MAXN]; int a[MAXN]; int main() { int n, m; scanf( %d%d , &n, &m); for (int i = 0; i < n; ++i) { scanf( %d , a + i); for (int j = 0; j < i; ++j) p[i][j] = a[i] > a[j], p[j][i] = 1 - p[i][j]; } fo... |
#include <bits/stdc++.h> using namespace std; long long N; string S; long long sol; long long dim; long long e; long long last() { long long d = 1ll; long long n = 0ll; long long sz = (long long)(S.size()); int zero = 0; for (long long i = sz - 1; i >= sz - dim && i >= 0 && n < N; i--)... |
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; long long dp[2005][2005]; int main() { long long n, k, sum = 0; cin >> n >> k; for (long long i = 1; i <= n; i++) dp[1][i] = 1; for (int i = 2; i <= k; i++) { for (long long j = 1; j <= n; j++) { for (int a = j;... |
#include <bits/stdc++.h> using namespace std; const int max_n = 1005; int n, m, k, now; char s[max_n], a[max_n][max_n], b[max_n][max_n]; int ans[max_n][max_n]; inline int gcd(int a, int b) { if (!b) return a; else return gcd(b, a % b); } int main() { scanf( %d%d%d n , &n, &m, &k)... |
#include <bits/stdc++.h> #pragma GCC optimize( O3 ) using namespace std; stringstream output; inline void eOP(); inline void solve() { int n, k; cin >> n >> k; string s; cin >> s; bool* letters = new bool[26](); for (int i = 0; i < n; ++i) { letters[s[i] - a ] = true; } ... |
#include <bits/stdc++.h> using namespace std; const int OO = 1e9 + 9; const int MAX = 1e5 + 9; int n, m, freq[MAX], dp[2][MAX]; vector<int> adj[MAX]; vector<pair<int, int> > a; bool vis[MAX]; template <typename T> void Minimize(T& a, T b) { a = min(a, b); } void Add(int cnt, int x) { int p... |
#include <iostream> using namespace std; #define ll long long ll t,n,m,k,x,y,ans; int main(){ cin>>t; while(t--){ cin>>n>>m>>k; x=(k-1)/n+1,y=(k-1)%n+1; ans=x+(y-1)*m; cout<<ans<<endl; } return 0; } |
#include <bits/stdc++.h> using namespace std; int read() { int s = 0; char c = getchar(), lc = + ; while (c < 0 || 9 < c) lc = c, c = getchar(); while ( 0 <= c && c <= 9 ) s = s * 10 + c - 0 , c = getchar(); return lc == - ? -s : s; } void write(int x) { if (x < 0) { putc... |
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 10; int n, m, s[N], t[N], nxt[N]; int kmp() { for (int i = 1, j = 0; i < n; i++) { while (j && s[i] != s[j]) j = nxt[j]; nxt[i + 1] = s[i] == s[j] ? ++j : 0; } int cnt = 0; for (int i = 0, j = 0; i < m; i++) { wh... |
#include <bits/stdc++.h> using namespace std; const long double PI = 3.1415926535897932384626433832795; const long double EPS = 1e-11; int n; set<string> st; string s, ts; map<string, int> mapp; string tos(signed long long i) { string s = ; while (i > 0) { s = char(i % 10 + 0 ) + s; ... |
#include <bits/stdc++.h> using namespace std; long long x, y, l, r; long long xx[105], yy[105]; vector<long long> ans; void readcase() { cin >> x >> y >> l >> r; xx[0] = 1; yy[0] = 1; int lena = 1; int lenb = 1; while (r / x >= xx[lena - 1]) { xx[lena] = xx[lena - 1] * x; l... |
#include <bits/stdc++.h> using namespace std; const int N = 10050; const int D = 600050; const int M = 8000050; const int INF = 20000000; int s, t, nds; namespace Maxflow { int dis[D], q[M * 2], f, r, tot = 1; int head[D], to[M], nex[M], fl[M], now[D]; void addedge(int u, int v, int f) { tot++; ... |
#include <bits/stdc++.h> using namespace std; const int maxn = 200005; int fa[maxn][20], d[maxn], n, p, q, ans, b, c; int dist(int x, int y) { int res = d[x] + d[y]; if (d[x] < d[y]) swap(x, y); for (int j = 18; j >= 0; j--) if (d[fa[x][j]] >= d[y]) x = fa[x][j]; if (x == y) return res - 2... |
#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 n, m; cin >> n >> m; bool ch1 = false; if (m % 2 == 0) ch1 = true; bool ch2 = false; for (int i = 0; i ... |
#include <bits/stdc++.h> using namespace std; unsigned long long int power(unsigned long long int n, unsigned long long int p) { unsigned long long int m = 1; while (p > 0) { m *= n; p--; } return m; } void sieveOfEratosthenes(int n, bool prime[]) { ... |
#include <bits/stdc++.h> using namespace std; int n, s[55], l, r; long long m, po; int main() { scanf( %d %I64d , &n, &m); po = 1; for (int i = 1; i < n; i++) po *= 2; m--; l = 1, r = n; for (int i = 1; i < n; i++) { po /= 2; if (m >= po) { m -= po; s[r--] = i... |
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; int v[n + 1]; for (int i = 1; i <= n; i++) { cin >> v[i]; } int menor = 0x3f3f3f3f, aux; for (int i = 1; i <= n; i++) { aux = 0; for (int j = 1; j <=... |
#include <bits/stdc++.h> using namespace std; const int MAXN = 300300; int n, k, uf[2 * MAXN], cnt[2 * MAXN], ans; vector<int> f[MAXN]; char s[MAXN]; int find(int x) { return (uf[x] != -1 ? uf[x] = find(uf[x]) : x); } void join(int x, int y) { if ((x = find(x)) == (y = find(y))) return; cnt[x] += ... |
#include <bits/stdc++.h> using namespace std; using ll = long long; const int maxn = 2e5 + 5, mod = 998244353; vector<int> vs[maxn]; inline int add(int x, int y) { return (x + y) % mod; } inline int mul(int x, int y) { return (1ll * x * y) % mod; } int fpow(int a, int b) { int res = 1; for (; b > ... |
#include <bits/stdc++.h> using namespace std; long long n, m; long long o = 0; bool b[1000001]; int main() { long long i, j, x, w; scanf( %lld%lld , &n, &m); o = 0; for (i = 1; i <= n; i++) { x = min(i * i, m); o += x * 2; } for (i = 1; i <= n; i++) { x = min(2 * n - ... |
#include <bits/stdc++.h> using namespace std; #define fz(i,a,b) for(int i=a;i<=b;i++) #define fd(i,a,b) for(int i=a;i>=b;i--) #define ffe(it,v) for(__typeof(v.begin()) it=v.begin();it!=v.end();it++) #define fi first #define se second #define fill0(a) memset(a,0,sizeof(a)) #define fill1(a) memset(a,-1,si... |
#include <bits/stdc++.h> using namespace std; const int inf = (1 << 29); int n, k; string str[2505][4], rhy[2505]; int sch[4]; string sub(string s, int k) { string res = ; int t = k; for (int i = s.size() - 1; i >= 0; --i) { res = s[i] + res; if (s[i] == a || s[i] == e || s[i] ... |
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1.0); const int inf = 0x3f3f3f3f; const double eps = 1e-15; int arr[1100]; int sc[1100]; int main() { int n, k, p, x, y; while (cin >> n >> k >> p >> x >> y) { int now = 0; for (int i = 1; i <= k; ++i) { cin ... |
#include <bits/stdc++.h> using namespace std; int main() { int i; int n, m1; cin >> n >> m1; int a[n + 1]; for (i = 1; i <= n; i++) cin >> a[i]; int t, r; stack<pair<int, int> > s; pair<int, int> use; for (i = 1; i <= m1; i++) { cin >> t >> r; while (!s.empty() && (s.... |
#include <bits/stdc++.h> using namespace std; const int M = 1e5 + 50; int ch(char a) { if (a == tolower(a)) return a - a ; else return a - A + 26; } int get_ans(int n) { char s[M]; scanf( %s , s); int cnt[52], mm = 0, len = strlen(s); memset(cnt, 0, sizeof(cnt)); for... |
#include <bits/stdc++.h> using namespace std; int main() { cin.sync_with_stdio(0); int t; cin >> t; string p, h; while (t--) { cin >> p >> h; int n = p.size(); int cnt[26]; memset(cnt, 0, sizeof cnt); for (int i = 0; i < n; i++) cnt[p[i] - a ]++; int m = h.si... |
#include <bits/stdc++.h> using namespace std; void canhazfast() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); } template <typename T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; } template <typename T> T extgcd(T a, T b, T &x, T &y) { T x0 = 1, y0 = 0, ... |
#include <bits/stdc++.h> using namespace std; int const N = 2005; long long f(long long x, long long n) { long long t = (x % 2 == 1 ? 1 : 2); long long h = 1; long long res = 0; while (true) { if ((x * h) > n) return res; res += (t - (x * h + t - 1 - min(x * h + t - 1, n))); t <<... |
#include <bits/stdc++.h> using namespace std; int f, dp[2][2][30][30][30], ans; void add(int &u, int x) { u += x; if (u >= 1000000009) u -= 1000000009; } int main() { int n, h; scanf( %d %d , &n, &h); dp[f][1][0][0][0] = 4; for (int i = 1, F; i < n; i++, f = F) { F = f ^ 1; ... |
#include <bits/stdc++.h> using namespace std; const int maxn = 100007; int n, m; long long h[maxn], p[maxn]; bool check(long long time) { int x = 1, old_x; for (int i = 1, _c = n; i <= _c; i++) { if (x > m) return 1; if (p[x] <= h[i]) { if (h[i] - p[x] > time) return 0; old... |
#include <bits/stdc++.h> using namespace std; const int MX = (int)1e6 + 17; const int MOD = (int)1e9 + 7; const long long oo = (long long)1e18 + 7; const int INF = (int)999999999; const int N = (int)1e5 + 17; const int di[4] = {-1, 0, 1, 0}; const int dj[4] = {0, 1, 0, -1}; inline long long IN() { ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.