func_code_string stringlengths 59 71.4k |
|---|
#include <bits/stdc++.h> using namespace std; const int maxn = 100000 + 5; int g[10][10]; int a[5]; int ans; int cal() { int sum = 0; for (int i = 0; i < 5; ++i) { for (int j = i; j < 4; j += 2) sum += g[a[j]][a[j + 1]] + g[a[j + 1]][a[j]]; } return sum; } int main() { for (int... |
#include <bits/stdc++.h> using namespace std; long long arr[330]; set<long long> st; map<long long, bool> mp; int main() { long long t, n, i, j, k, l, m; ios_base::sync_with_stdio(0); cin.tie(0); long long p; cin >> t; while (t--) { cin >> n; for (i = 1; i <= n; i++) cin >>... |
#include <bits/stdc++.h> using namespace std; int n, m, s; int even_odd[100005][2]; int visited[100005]; vector<int> ans; vector<int> v[100005]; int dfs(int s, int p) { if (v[s].empty() && p) { ans.push_back(s); return 1; } for (auto it : v[s]) { if (even_odd[it][p ^ 1] == 0)... |
#include <bits/stdc++.h> using namespace std; int main() { long long t; scanf( %lld , &t); while (t--) { long long a, b, c, d, k; scanf( %lld%lld%lld , &a, &b, &c); scanf( %lld %lld , &d, &k); long long x = (a - 1 + c) / c; long long y = (b + d - 1) / d; if (x + y <= ... |
#include <bits/stdc++.h> int a[100010], i, j, k, n, x, y; int main() { while (scanf( %d , &n) == 1) { if (n % 4 != 1 && n % 4 != 0) { printf( -1 n ); continue; } if (n == 1) { printf( 1 n ); continue; } if (n % 4 == 1) { a[n / 2 + 1] = n / 2 ... |
#include <bits/stdc++.h> using namespace std; double n, sum = 0; int a[21], b[21]; int main() { cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < n; i++) { cin >> b[i]; } for (int i = 0; i < 1000000; i++) { for (int j = 0; j < n; j++) { ... |
#include <bits/stdc++.h> using namespace std; const int maxc = 1000000000; int main() { long long n, k, l, r; scanf( %lld%lld%lld%lld , &n, &l, &r, &k); long long d = r - l + 1; if (l > r) { d = n - l + 1 + r; } if (d == n) { long long ans = -1; for (long long i = 1; i * ... |
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10; signed main() { int a, b, c, d, e, f; cin >> a >> b >> c >> d >> e >> f; int ans = 0; if (e >= f) { int dec = min(a, d); a -= dec; d -= dec; ans += dec * e; ans += min(min(b, c), d) * f; } el... |
#include <bits/stdc++.h> using namespace std; const int M = 1e9 + 7; template <class T> T ABS(const T& x) { return x > 0 ? x : -x; } long long int gcd(long long int n1, long long int n2) { return n2 == 0 ? ABS(n1) : gcd(n2, n1 % n2); } long long int lcm(long long int n1, long long int n2) { ... |
#include <bits/stdc++.h> using namespace std; namespace jyy { const int mod = 998244353, N = 600010; const double eps = 1e-8; inline int read() { static int x = 0, f = 1; x = 0, f = 1; static char ch = getchar(); while (ch < 0 || ch > 9 ) { (ch == - ) ? f *= -1 : f; ch = getcha... |
#include <bits/stdc++.h> using namespace std; bool sortinrev(const pair<int, int> &a, const pair<int, int> &b) { return (a.first > b.first); } double gcd(double a, double b) { if (b == 0) return a; return gcd(b, double(int(a) % int(b))); } long long int power(long long int b, long long int e, lo... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long n, k, p; cin >> n >> k >> p; bool odd = false, even = false; string ans = ; if (n % 2 == 0) even = true; else { odd = true; k--; } ... |
#include <bits/stdc++.h> using namespace std; int n, start, x; int order[50005]; pair<int, int> ask(int idx) { printf( ? %d n , idx); fflush(stdout); int val, nxt; scanf( %d%d , &val, &nxt); return pair<int, int>(val, nxt); } int main() { srand(time(0)); for (int i = 1; i < 50005... |
#include <bits/stdc++.h> int main() { long int i, j, l, i1, k = 0, c1 = 0, t, c[100000]; char a[100000], b[100000]; scanf( %s , &a); l = strlen(a); for (j = 0; j < l; j++) { if (((int)a[j]) % 2 == 0) { b[k] = a[j]; c[k] = j; k++; } } if (k == 0) pr... |
#include <bits/stdc++.h> using namespace std; void optIO() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } const long long mod = 1e9 + 7, mod2 = 998244353, mod3 = 1e9 + 9; long long p[5020], pp = 31, hh[5020]; long long p2[5020], pp2 = 37, hh2[5020]; int dp[5020]; bool can[5020][5... |
#include <bits/stdc++.h> int n, x, y, att, cnt; using namespace std; int main() { cin >> n >> x >> y; if (x > y) return cout << n, 0; for (int i = (1); i <= (n); i++) { cin >> att; if (att <= x) cnt++; } cout << (cnt + 1) / 2; } |
#include <bits/stdc++.h> using namespace std; const int M = 6e5; int n, d, f[M]; int main() { cin >> n >> d; f[0] = 1; int now = 0, times = 0; for (int i = 0; i < n; i++) { int x; cin >> x; for (int j = M - 1; j >= x; j--) f[j] |= f[j - x]; } while (1) { int old =... |
#include <bits/stdc++.h> using namespace std; struct point { double x, y; point operator-(point A) { return (point){x - A.x, y - A.y}; } double operator*(point A) { return x * A.y - y * A.x; } double dis() { return sqrt(x * x + y * y); } } a[1005][1005], t[1005], E[1005]; int n, vis[1005][1005];... |
#include <bits/stdc++.h> using namespace std; int Solve(int n) { int ten = 1; int ans = 0; while (n != 0) { if (n % 10 != 0) { ans += (ten * (n % 10)); ten *= 10; } n /= 10; } return ans; } long long int gcd(long long int a, long long int b) { if (b == 0... |
#include <bits/stdc++.h> using namespace std; long long n; long long calcCards(long long x) { return x * (x + 1) + (x - 1) * x / 2; } bool P(int x) { return calcCards(x) <= n; } long long bs(long long l = 0, long long h = n) { long long m; while (l < h) { m = (l + h + 1) / 2; if (P(m)) ... |
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1.0); void Fast() { std::ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } long long gcd(long long a, long long b) { return a ? gcd(b % a, a) : b; } long long lcm(long long a, long long b) { return a / gcd(a, b) * b; } ... |
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n, d; cin >> n >> d; int ld = 0, rd = n * (n - 1) / 2; for (int i = 1, cd = 0; i <= n; ++i) { if (!(i & (i - 1))) ++cd; ld += cd - 1; } if (!(ld <= d && d <= ... |
#include <bits/stdc++.h> using namespace std; int N, K, D[1010], S[1010], ans, tt, crtMax; int main() { int i; scanf( %i %i , &N, &K); for (i = 1; i <= N; i++) scanf( %i , &D[i]); for (i = 1; i <= N; i++) scanf( %i , &S[i]); for (i = 1; i <= N; i++) { crtMax = max(crtMax, S[i]); an... |
#include <bits/stdc++.h> using namespace std; const int N = 200000 + 10; const long long INF = 0x3f3f3f3f3f3f3f3fLL; long long dp[105][105][105]; long long c[105], val[105][105], ans = INF; int main() { int i, j, K, n, m, k; cin >> n >> m >> K; for (i = 1; i <= n; i++) cin >> c[i]; for (i = ... |
#include <bits/stdc++.h> using namespace std; long long fast_power(long long x, long long y) { if (y == 0) return 1; long long temp = fast_power(x, y / 2); temp = ((temp % 1000000007) * (temp % 1000000007)) % 1000000007; if (y % 2 != 0) temp = ((temp % 1000000007) * (x % 1000000007)) % 1000000007; ... |
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); int n, m; cin >> n >> m; vector<int> a(n); for (auto& x : a) cin >> x, --x; vector<int> k(m); for (auto& x : k) cin >> x; for (int i = 0; i < n; ++i) for (int j = i + 1; j <= n; ++j) { ... |
#include <bits/stdc++.h> using namespace std; template <typename T> void nexts(T *, int); template <typename T> void dump(T *arr, int cnt, char sep = ); void __init__(bool, bool); const int MAXMAXMAX = 1000 * 1000 * 1000; string a, b, c; char ans[100015]; vector<int> cnt_a(26); vector<int> cnt_... |
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c; cin >> a >> b >> c; int x = sqrt(a * c / b), y = sqrt(a * b / c), z = sqrt(b * c / a); cout << (x + y + z) * 4; return 0; } |
#include <bits/stdc++.h> using namespace std; long long nMod = 1e9 + 7; inline long long GCD(long long a, long long b) { while (b != 0) { long long c = a % b; a = b; b = c; } return a; }; inline long long LCM(long long a, long long b) { return (a / GCD(a, b)) * b; }; int m, n, ... |
#include <bits/stdc++.h> #pragma GCC optimize( O3,unroll-loops ) #pragma pack(0) using namespace std; vector<string> v[1000001]; string s; int ptr = 0, maxd = 0; void dfs(int dis) { maxd = max(maxd, dis); int k = 0, f = ptr; for (; ptr < s.length(); ptr++) if (s[ptr] == , ) break; s... |
#include <bits/stdc++.h> using namespace std; class Solution { int n, x[2]; vector<pair<long long, int>> A; public: void run() { cin >> n >> x[0] >> x[1]; for (int i = 0; i < n; ++i) { int c; cin >> c; A.emplace_back(c, i); } sort(A.begin(), A.end())... |
#include <bits/stdc++.h> using namespace std; bool isPrime(int a, int p) { return (a <= p) || ((a % p != 0) && (isPrime(a, p + 1))); } int main() { const int N = 256; int freq[N] = {0}; string s; cin >> s; int len = s.size(); for (int p = 0; p < len; p++) { ++freq[s[p]]; } ... |
#include <bits/stdc++.h> using namespace std; int n, m; bool cmp(pair<int, int> a, pair<int, int> b) { if (a.first != b.first) return a.first > b.first; return a.second < b.second; } bool cmp2(pair<int, int> a, pair<int, int> b) { return a.second < b.second; } int main() { ios_base::sync_with_st... |
#include <bits/stdc++.h> using namespace std; using ll = long long; using PII = pair<int, int>; const int mod = 998244353; const int inf = 1 << 30; const int maxn = 200000 + 5; int n, tot, tin[maxn], tout[maxn], rid[maxn], vis[maxn], deg[maxn]; vector<int> edge[maxn]; int query(int x, int y) { cou... |
#include <bits/stdc++.h> using namespace std; const int INF = 1000000000; const long long LINF = 4000000000000000000LL; const double eps = 1e-9; void prepare() {} int a, n; int day[10000008]; void read() { scanf( %d%d , &a, &n); } void solve() { read(); for (int i = 1; i * i < a + n; i++) { ... |
#include <bits/stdc++.h> using namespace std; const long long N = 100005; long long t, l, i, j, k, p, q, u, v, n, color[1000005]; string s; vector<long long> zro; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> q; for (l = 1; l <= q; l++) { cin >> n >... |
#include <bits/stdc++.h> using namespace std; int main() { int a, sum = 0; string s; cin >> a; for (int i = 0; i < a; i++) { cin >> s; if (s == Tetrahedron ) sum = sum + 4; else if (s == Cube ) sum = sum + 6; else if (s == Octahedron ) sum = sum + 8... |
#include <bits/stdc++.h> #pragma GCC optimize( O3 , unroll-loops ) using namespace std; namespace { const int MOD107 = 1000000007; const int MOD998 = 998244353; using ll = long long; using ull = unsigned long long; using pii = pair<int, int>; using pll = pair<ll, ll>; template <class T> using min... |
#include <bits/stdc++.h> using namespace std; ofstream file( debug.txt ); template <typename Int> ostream &operator<<(ostream &s, const vector<Int> &v) { s << [ ; for (auto i = v.begin(); i != v.end(); i++) { s << *i; if (i != prev(v.end())) s << , ; } s << ] ; return s; } ... |
#include <bits/stdc++.h> using namespace std; int main() { int n, s, ans, x, y, a; bool flag = false; cin >> n >> s; s = s * 100; ans = -1; for (int i = 0; i < n; i++) { cin >> x >> y; a = x * 100 + y; if (a <= s) { ans = max(ans, (100 - a % 100) % 100); } ... |
#include <bits/stdc++.h> #pragma GCC optimize(2) using namespace std; inline int read() { char c = getchar(); int x = 0; bool f = 0; for (; !isdigit(c); c = getchar()) f ^= !(c ^ 45); for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48); if (f) x = -x; return x; } b... |
#include <bits/stdc++.h> using namespace std; const long long N = 100010; long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } long long n, m, p, a[N], b[N], q[N], yue[N], miu[N], f[N], tot; long long ans; long long power(long long a, long long b, long long m) { long long re = 1; ... |
#include <bits/stdc++.h> using namespace std; const double eps = 1e-8; const double pi = acos(-1.0); int n, m; bool check(int x) { int a2 = x / 2, a3 = x / 3, a6 = x / 6; a2 -= a6; a3 -= a6; if (max(n - a2, 0) + max(m - a3, 0) <= a6) return true; else return false; } int ma... |
#include <bits/stdc++.h> using namespace std; const int N = 5e5 + 10; const int K = 23; const long long INF = 1e18; int id[N], a[N], b[N], w[N]; int n, m; vector<int> pos[N]; long long dp[N]; int ls[N * K], rs[N * K], rootcnt = 0; long long vs[N * K]; void copy(int root, int newroot) { ls[newr... |
#include <bits/stdc++.h> using namespace std; long long Pow_Mod(long long a, long long b) { if (b == 0) return 1; long long tmp = Pow_Mod(a, b / 2); tmp = (tmp * tmp) % 1000003; if (b % 2) return (tmp * a) % 1000003; return tmp; } long long C(long long a, long long b) { if (b == 0 || b =... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ; long long t; cin >> t; while (t--) { int n, k, x, rem; cin >> n >> k; x = k / (n - 1); rem = k - x * (n - 1); if (!rem) cout... |
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) #pragma GCC optimize( unroll-loops ) using namespace std; using pii = pair<int, int>; const int MOD = 1e9 + 7, N = 2e3 + 10; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long n; cin >> n; vector<pair<long l... |
#include <bits/stdc++.h> using namespace std; const int maxn = 3e5 + 123; const int mod = 1e9 + 9; int n; long long k, d; int a[maxn]; int m; int L[maxn]; long long t[maxn * 4]; long long ad[maxn * 4]; void build(int v, int l, int r) { ad[v] = 0; t[v] = 0; if (l == r) { } else { ... |
#include <bits/stdc++.h> using namespace std; const int N = 123, BITS = 11, MAX = 7; int c[N], num[N]; int a[MAX][MAX]; char s[N]; int bit(int x) { int res = 0; while (x != 0) { res += x % 2; x /= 2; } return res; } int main() { int n; scanf( %d , &n); for (int i ... |
#include <bits/stdc++.h> using namespace std; bool graf[100][100]; int n, m; bool visited[100]; bool spoken[100]; int stupid; int tab[100]; int main() { ios::sync_with_stdio(false); cin >> n >> m; for (int i = 0; i < n; i++) { int x; cin >> x; if (x == 0) stupid++; fo... |
#include <bits/stdc++.h> using namespace std; int a, b, n, m, l, t; bool check(int r) { if (a + 1ll * b * (r - 1) <= t && (1ll * a * (r - l + 1) + 1ll * b * (1ll * r * (r - 1) / 2 - 1ll * (l - 1) * (l - 2) / 2)) <= 1ll * m * t) return 1; else return 0; } int ma... |
#include <bits/stdc++.h> using namespace std; int n, k; int a[100005]; set<long long> present; int ans; int main() { scanf( %d%d , &n, &k); for (int i = 0; i < n; i++) scanf( %d , &a[i]); sort(a, a + n); for (int i = n - 1; i >= 0; i--) { if (present.find((long long)a[i] * k) == presen... |
#include <bits/stdc++.h> using namespace std; template <class T> void pp(T v) { for (__typeof((v).begin()) it = (v).begin(); it != (v).end(); ++it) cout << *it << ; cout << endl; } template <class T> void pp(T v, int n) { for (int i = 0; i < (int)n; i++) cout << v[i] << ; cout <<... |
// Created by aadi // Never give up , Miracles never happen in real life. #include<bits/stdc++.h> using namespace std ; #define FAST ios_base::sync_with_stdio(false);cin.tie(NULL); #define int long long int #define MIN LLONG_MIN #define MAX LLONG_MAX #define set1D(a,val,n) { for(int i=0;i<n;i... |
#include <bits/stdc++.h> const int N = 2001, INF = 1e9 + 7; long long g[N][N], f[N][N]; int main() { int n, k; std::cin >> n >> k; std::string s; std::cin >> s; f[0][0] = g[0][0] = 1; for (int i = 1; i <= n; ++i) for (int j = 0; j <= k; ++j) { g[i][j] = f[i - 1][j] * (s[n - i... |
#include <bits/stdc++.h> using namespace std; template <typename T> void read(T &t) { t = 0; char ch = getchar(); int f = 1; while ( 0 > ch || ch > 9 ) { if (ch == - ) f = -1; ch = getchar(); } do { (t *= 10) += ch - 0 ; ch = getchar(); } while ( 0 <= ch &&... |
#include <bits/stdc++.h> using namespace std; template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const map<T0, T1>& v) { for (typename map<T0, T1>::const_iterator p = v.begin(); p != v.end(); p++) { os << p->first << : << p->second << ; } return os; } templa... |
#include <bits/stdc++.h> using namespace std; const int INF = 1e9 + 7; int n, g, p, d, a, b, act, nxt; long long res; int Next[(1000000 + 6)]; pair<int, int> Stacje[(1000000 + 6)]; stack<int> S; int main() { scanf( %d %d %d , &d, &g, &n); p = g; for (int i = 1; i <= n; i++) { scanf( %d... |
#include <bits/stdc++.h> using namespace std; template <typename T> void read(T &x) { x = 0; char c = getchar(); T sig = 1; for (; !isdigit(c); c = getchar()) if (c == - ) sig = -1; for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + c - 0 ; x *= sig; } class Solution {... |
#include <bits/stdc++.h> using namespace std; const int MOD = (int)1e9 + 7; template <typename T> static T aabs(T x) { if (x < 0) return -x; return x; } template <typename T> static void read(T &S) { char K[1000009]; scanf( %s , &K); S = K; } template <typename T, typename U> sta... |
#include <bits/stdc++.h> int main() { int n; scanf( %d , &n); int S = 0; for (int i = 1; S < n; ++i) S += i; puts(S == n ? YES : NO ); return 0; } |
#include <bits/stdc++.h> using namespace std; const int INF = 2000000000; struct pkt { int k, r; }; struct prze { int k, r1, r2; }; bool porownanie(pkt a, pkt b) { if (a.k < b.k) return true; if (a.k > b.k) return false; if (a.r < b.r) return true; return false; } int main() { ... |
#include <bits/stdc++.h> using namespace std; const int maxi = 1e6 + 10; const long long mo = 1e9 + 7; long long a[maxi]; long long m, l, r, k; string s; vector<int> v[maxi]; long long mat[53][3][3]; void mul_mat(int idx1, int idx2, int idx) { for (int i = 1; i <= 2; i++) for (int j = 1; j <... |
#include <bits/stdc++.h> using namespace std; long long read() { char c = getchar(); long long x = 1; long long s = 0; while (c < 0 || c > 9 ) { if (c == - ) x = -1; c = getchar(); } while (c >= 0 && c <= 9 ) { s = s * 10 + c - 0 ; c = getchar(); } ret... |
#include <bits/stdc++.h> using namespace std; const int MAXN = 1100; const long long MOD = 998244353; int N, K; int arr[MAXN]; int dp[MAXN][MAXN]; int ps[MAXN][MAXN]; long long figure(int k) { if (k * (K - 1) > arr[N - 1]) return 0; for (int i = 0; i <= N; i++) for (int j = 0; j <= K; j++)... |
#include <bits/stdc++.h> using namespace std; const int N = 200010; inline int gi() { register int x = 0; register char c = getchar(); bool f = 0; while (c != - && (c < 0 || c > 9 )) c = getchar(); if (c == - ) c = getchar(), f = 1; while (c >= 0 && c <= 9 ) x = x * 10 + c - 0 , ... |
#include <bits/stdc++.h> using namespace std; int n, m; int r[200], l[200]; int main() { memset(l, 10, sizeof(l)); memset(r, -1, sizeof(r)); cin.sync_with_stdio(false); cin >> n >> m; string s; int w = 0; for (int i = 0; i < n; ++i) { cin >> s; for (int j = 0; j < m; ++j)... |
#include <bits/stdc++.h> int main() { int sum, n, i, t, p, sum1; char z[260]; scanf( %d , &n); getchar(); for (i = 0; i < n; i++) { scanf( %c , &z[i]); } getchar(); sum = 0; sum1 = 0; p = 0; t = 0; for (i = 0; i < n; i++) { if (z[i] >= a && z[i] <= z ) { ... |
#include <bits/stdc++.h> using namespace std; template <class A, class B> istream &operator>>(istream &o, pair<A, B> &p) { o >> p.first >> p.second; return o; } template <class type> istream &operator>>(istream &o, vector<type> &v) { for (int i = 0; i < (int)v.size(); i++) o >> v[i]; return ... |
#include <bits/stdc++.h> using namespace std; long long a[100010], b[100010], x[100010], y[100010]; int main() { ios::sync_with_stdio(false); cin.tie(0); long long n, m, ans = 0; cin >> n >> m; for (int i = 1; i <= n; i++) cin >> a[i]; a[0] = 0; a[n + 1] = m; for (int i = 1; i <= n... |
#include <bits/stdc++.h> using namespace std; const int S = 1003; bool a[S]; bool b[S]; string s; int k; int i, j; int main() { cin >> s; j = s.size() - 1; while (i < j) { if (s[i] == ( && s[j] == ) ) { b[i] = 1; b[j] = 1; k++; i++; j--; ... |
#include <bits/stdc++.h> using namespace std; int N, M; string str[2005]; long long pr[2005][2005], pc[2005][2005]; long long dpr[2005][2005], dpd[2005][2005]; int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> N >> M; for (int i = 0; i <= N - 1; i++) cin >> str[i]; bool has = ... |
#include <bits/stdc++.h> using namespace std; vector<pair<int, int> > b, c; map<vector<pair<int, int> >, int> d; ; int n, m, ask, a[100086]; long long ans; int main() { scanf( %d %d , &n, &m); ans = 0ll; for (int i = 1; i <= n; i++) { scanf( %d , &a[i]); b.clear(); c.clear();... |
#include <bits/stdc++.h> using namespace std; long long _pow(long long base, long long exp) { return exp == 0 ? 1 : base * _pow(base, exp - 1); } string int_to_str(int x) { string xs; stringstream ss; ss << x; xs = ss.str(); return xs; } int str_vec_find(string x, vector<string> y) {... |
#include <bits/stdc++.h> using namespace std; long long nc2[(int)1e5]; void pre() { for (long long i = 1; i < 1e5; ++i) { nc2[i] = i * (i - 1) / 2; } } int binSearch(int l, int r, int val) { while (l <= r) { int mid = (l + r) / 2; if (nc2[mid] == val) return mid; el... |
#include <bits/stdc++.h> using namespace std; vector<long long> matches; void computeLPSArray(vector<pair<char, long long> >& pat, long long M, long long* lps); void KMPSearch(vector<pair<char, long long> >& pat, vector<pair<char, long long> >& txt) { long long M = pa... |
#include <bits/stdc++.h> using namespace std; template <class T> ostream& operator<<(ostream& os, vector<T> v) { for (T x : v) os << x << ; return os; } template <class T> istream& operator>>(istream& is, vector<T> v) { for (T& x : v) is >> x; return is; } const long long INF = 1LL <<... |
#include <bits/stdc++.h> using namespace std; const int maxn = 1000 + 5; const int mod = 1000 * 1000 * 1000 + 7; vector<int> p[maxn]; int main() { ios_base::sync_with_stdio(false); int n; cin >> n; for (int i = 0; i < n; i++) { int k; cin >> k; p[i].resize(k); for (int ... |
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) using namespace std; int t; long long n; vector<int> v; long long cnt[30]; long long pos[30]; long long fact[21]; void init() { for (int i = 0; i < int(30); i++) cnt[i] = pos[i] = 0; v.clear(); } int main() { cin.tie(0); ios_ba... |
#include <bits/stdc++.h> using namespace std; const int N = 100005; int n, m, K, w[N]; inline char nc() { static char buf[100000], *p1 = buf, *p2 = buf; if (p1 == p2) { p2 = (p1 = buf) + fread(buf, 1, 100000, stdin); if (p1 == p2) return EOF; } return *p1++; } inline void read(in... |
#include <bits/stdc++.h> using namespace std; int n, a[12345]; int calc(int x, int y) { int ret = 0; vector<int> v; for (int i = 0; i < 2 * n; ++i) { if (i != x && i != y) v.push_back(a[i]); } for (int i = 0; i < v.size(); i += 2) ret += abs(v[i] - v[i + 1]); return ret; } int ma... |
#include <iostream> #include <cstdio> #include <cmath> #include <cstring> #include <vector> #include <map> #include <set> #include <cmath> #include <queue> #include <algorithm> #include <numeric> using namespace std; typedef long long ll; const int N=1e6+5; const int M=1e3+5; const int ... |
#include <bits/stdc++.h> using namespace std; int main() { int t, c, i, a, m, l, r; cin >> t >> i >> m >> a >> l; r = i; c = 1; t = t - r; while (t > 0) { c++; r = r + a; if (r > m) r = m; t = t + l - r; if (t < 0) t = 0; } cout << c; return 0; } ... |
#include <bits/stdc++.h> using namespace std; int q, n, m, u1, d1, l1, r1, u2, d2, l2, r2, u3, d3, l3, r3; long long count(int a, int b) { return (1ll * a * b + 1) / 2; } long long count(int u, int d, int l, int r) { return count(d, r) + count(u - 1, l - 1) - count(d, l - 1) - count(u - 1, r); } int mai... |
#include <bits/stdc++.h> using namespace std; int n, m; string in[1003]; int a[1003][1003]; int X[] = {-1, 0, 0, 1}; int Y[] = {0, -1, 1, 0}; bool d[1003][1003]; int getSm(int i, int j, int u, int v) { return a[u][v] - a[i - 1][v] - a[u][j - 1] + a[i - 1][j - 1]; } bool check() { for (int i ... |
#include <bits/stdc++.h> using namespace std; const int maxn = 3e3 + 5; const int mod = 998244353; char s[maxn], t[maxn]; int m, n, dp[maxn][maxn]; int main() { scanf( %s%s , s + 1, t + 1); n = strlen(s + 1); m = strlen(t + 1); for (int i = 1; i <= n; i++) { if (i > m || t[i] == s[1]) ... |
#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; int main() { int k = 0, t = 0, l = 0, q = 0, z = 0; string s, s1, s2; cin >> s; if (s[0] == - ) { q = -1; s.erase(0, 1); } k = s.size(); for (int i = 0; i < s.size(); i++) if (s[i] == . ) { t = i; break; ... |
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; long long a3, b3; bool check1(long long a1, long long b1, long long a2, long long b2) { if ((a2 * a3 + b2 * b3 + a1 * b3 - a3 * b1) % (a3 * a3 + b3 * b3)) return false; if ((a2 * b3 - b2 * a3 - a1 * a3 - b1 * b3) % (a3 * a3 + b3... |
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const long long LINF = 0x3f3f3f3f3f3f3f3fll; template <bool directed> struct Euler { int N; vector<vector<pair<int, int>>> adj; vector<vector<pair<int, int>>::iterator> its; vector<bool> used; Euler(int N_) : N(N_), ... |
#include <bits/stdc++.h> using namespace std; const int mxN = 1e3 + 1; int n, d[mxN], k; vector<int> adj[mxN]; vector<string> a[mxN]; signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n >> k; for (int i = 0, c; i < n; i++) { cin >> c; string s1; for (i... |
#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> #pragma GCC optimize( Ofast ) using namespace std; clock_t clk = clock(); long long int i, j, k; void solve(void); int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ; int t = 1; while (t--) solve(); return 0; } void solve() { long long int... |
#include <bits/stdc++.h> using namespace std; int main() { vector<set<string> > N, F; vector<pair<string, string> > ans; set<string> p; for (int i = 0; i < 26; ++i) { N.push_back(p); F.push_back(p); } int n, k, c; cin >> n; c = (int) A ; string s; for (int i = 0; ... |
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; const long double PI = 4 * atan((long double)1); const long long INF = 1e18; const long long NINF = -1e18; long long get_hash(string s) { long long N = 1000001; long long base[N], A = 11, MD = 1110111110111; base[0] = 1... |
#include <bits/stdc++.h> using namespace std; const int N = 505; char g[N][N]; int id[N][N]; int cnt = 1; int dx[] = {0, 0, 1, -1}; int dy[] = {1, -1, 0, 0}; int amt[N * N]; int sz[N * N]; int sum; int n, k; void dfs(int i, int j, int idx) { if (g[i][j] == X or id[i][j]) return; id[i][... |
#include <bits/stdc++.h> using namespace std; struct pair_hash { template <class T1, class T2> size_t operator()(pair<T1, T2> const &pair) const { size_t h1 = std::hash<T1>()(pair.first); size_t h2 = std::hash<T2>()(pair.second); return h1 ^ h2; } }; unordered_set<pair<int, int>, p... |
#include <bits/stdc++.h> using namespace std; int p, first, cnts, cntw, S, W; int solve(long long picked) { int cap1 = p, cap2 = first, cnt1 = cnts, cnt2 = cntw; long long temp = picked; cap1 -= (picked * S); cnt1 -= picked; if (cap1 >= W) { temp += min(cap1 / W, cnt2); cnt2 -= min... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ; long long a, b, x, y, i, k, j, t, n, s; cin >> t; while (t--) { cin >> n >> k; if (n % 2 == 0) { s = n + (k * 2); cout << s << endl; } else { ... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); long long p, k; cin >> p >> k; long long d = (k - p) / k; if ((((k - p) % k) + k) % k == 0 || (d <= 0 && p > k)) d--; vector<long long> res; res.push_back(d); if (k > p) return co... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.