func_code_string stringlengths 59 71.4k |
|---|
#include <bits/stdc++.h> using namespace std; const long long M = 998244353; long long power(long long a, long long b, long long m) { long long res = 1; a %= m; while (b) { if (b & 1LL) res = res * a % m; a = a * a % m; b >>= 1; } return res; } int32_t main() { ios_ba... |
#include <bits/stdc++.h> using namespace std; template <class T> T min_(T a, T b) { return (a < b ? a : b); } template <class T> T max_(T a, T b) { return (a > b ? a : b); } const int MAX_N = 1e5 + 1; vector<pair<unsigned long long, unsigned long long> > notes; int main(int argc, char *argv[... |
#include <bits/stdc++.h> const int N = 500054; const double eps = 3e-10; inline void up(double &x, const double y) { x < y ? x = y : 0.; } inline void down(double &x, const double y) { x > y ? x = y : 0.; } inline double max(const double x, const double y) { return x < y ? y : x; } struct quadratic { do... |
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, k; cin >> n >> k; vector<pair<int, int>> ans; for (int c = 1; c < k; c++) { int r = 0; int C = c; while (ans.size() < n) { ans.emplace_back(r + 1, C + 1); ... |
#include <bits/stdc++.h> using namespace std; struct str { int q, cost; str(int _q = 0, int _cost = 0) { q = _q; cost = _cost; } bool operator<(const str &two) const { return cost > two.cost; } }; struct edge { int u, v, cost; edge(int _u = 0, int _v = 0, int _cost = 0) { u =... |
#include <bits/stdc++.h> using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); int d4x[4] = {1, 0, -1, 0}; int d4y[4] = {0, 1, 0, -1}; int d8x[8] = {0, 1, 1, 1, 0, -1, -1, -1}; int d8y[8] = {1, 1, 0, -1, -1, -1, 0, 1}; const long long oo = 1e18; const long long maxN =... |
#include <bits/stdc++.h> using namespace std; long long int arr[500005], sum[500005]; bool vis[100005]; map<long long int, long long int> hola; map<pair<long long int, long long int>, long long int> con; vector<pair<long long int, long long int>> conn; int main() { long long int n, maxi = INT_MIN; ... |
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1.0); const int INF = 1000000000; const int MAX = 5000; const int MOD = 1000000007; int C[MAX][MAX]; int CL[MAX]; int main() { int n; cin >> n; C[0][0] = 1; for (int i = (1); i < (n + 1); ++i) { C[i][0] = 1; ... |
#include <bits/stdc++.h> using namespace std; const double eps = 1E-8; const int dx4[4] = {1, 0, 0, -1}; const int dy4[4] = {0, -1, 1, 0}; const int inf = 0x3f3f3f3f; const int N = 2E5 + 7; int tree[2][N]; int a[N], p[N]; int n; long long k; int lowbit(int x) { return x & (-x); } void update(int... |
#include <bits/stdc++.h> using namespace std; const int N = 25, M = 300005; int n, a[N][N]; long long f[M], g[N][M], d[N][M], dp[N][M]; map<long long, long long> mp; string st; inline int bp(int x) { return __builtin_popcount(x); } void dfs(int p, int s, int x, long long m) { if (s == n) { lon... |
#include <bits/stdc++.h> #pragma comment(linker, /stack:200000000 ) #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; const long long INF = 1000LL * 1000 * 1000 * 1000 * 1000 * 1000; const ... |
#include <bits/stdc++.h> int main() { int n; scanf( %d , &n); int a[n], i, s = 0; for (i = 0; i < n; i++) { scanf( %d , &a[i]); s = s + a[i]; } if (s == 0) printf( EASY n ); else printf( HARD n ); return 0; } |
#include <bits/stdc++.h> using namespace std; int n, m, t, x, y, ed, pt, bcc, done, cnt, cycl; int qd[400005], qn[400005], l[400005], v[400005], w[400005], vv[400005], d[400005], AP[400005], p[400005], vis[400005]; int col[400005], par[400005], L[400005], C[400005], cc[400005], vc[400005], pp[400005... |
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const int maxn = 1000 + 10; const int mod = 1e9 + 7; int a[3][6]; int vis[100]; int main() { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; for (int i = 0; i < n; i++) for (int j = 0; j < 6; j++) cin... |
#include <bits/stdc++.h> using namespace std; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long tt = 1; cin >> tt; while (tt--) { string t, s, ans; bool f = 0; cin >> t; long long n = t.size(); vector<long long> a(26), b(26), c(26)... |
#include <bits/stdc++.h> using namespace std; int n, k, q, a[int(2e5)], sz; set<pair<int, int> > st; int main() { cin >> n >> k >> q; for (int i = 0; i < n; ++i) { cin >> a[i]; } for (int i = 0; i < q; ++i) { int x, y; cin >> x >> y; if (x == 1) { st.insert(make_p... |
#include <bits/stdc++.h> using namespace std; long long max(long long a, long long b) { return a > b ? a : b; } long long min(long long a, long long b) { return a < b ? a : b; } double max(double a, double b) { return a > b ? a : b; } double min(double a, double b) { return a < b ? a : b; } long long modd(l... |
#include <bits/stdc++.h> using namespace std; int a[13] = {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334}; int run(int x) { if ((x % 4 == 0 && x % 100 != 0) || (x % 400 == 0)) return 1; else return 0; } int main() { int y1, y2, m1, m2, d1, d2; int i, j; scanf( %d:%d:%d ... |
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; if (n <= 2) cout << -1 ; else if (n == 3) cout << 210 ; else { int mod = 1; for (int i = 1; i < n; ++i) mod = (mod * 10) % 210; if (n > 3) cout << 1 ; for (int i = 0; i < n - 4; ++i... |
#include <bits/stdc++.h> using namespace std; void solve() { char a[8][8]; int i, j, c = 0, k, d = 0, e = 1, f = 0; vector<int> v; for (i = 0; i < 8; i++) { for (j = 0; j < 8; j++) { cin >> a[i][j]; } } for (i = 0; i < 8; i++) { d = 0; for (j = 0; j < 8; j++) ... |
#include <bits/stdc++.h> using namespace std; int cho[30]; char str[1005]; int main() { int a, b, ans = 0; cin >> a >> b; for (int i = 0; i < a; i++) { cin >> str[i]; cho[str[i] - 96]++; } int tot = b; for (int i = 1; i <= 26; i++) { if (tot == 0) { break; ... |
#include <bits/stdc++.h> using namespace std; int n, m, ans, tot; int b[200010], rt[200010]; struct nu { int val, id; } a[200010]; char s[200010]; struct node { int ls, rs, sum; } tree[200010 * 20]; inline bool cmp(const nu &x, const nu &y) { if (x.val == y.val) return x.id < y.id; ... |
#include <bits/stdc++.h> using namespace std; long long a[100010], b[100010]; int main() { int t; cin >> t; while (t--) { int n; int flag = 1; long long min = 1e9 + 1; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; b[i] = a[i]; if (min > a[i]... |
#include <bits/stdc++.h> using namespace std; int main() { int n; set<int> set; scanf( %d , &n); for (int i = 0; i < n; i++) { int put; scanf( %d , &put); set.insert(put); } vector<int> arr(set.size()); copy(set.begin(), set.end(), arr.begin()); sort(arr.begin(), ar... |
#include <bits/stdc++.h> using namespace std; struct _ { int a, b, c, d, id; bool operator<(const _ &ob) const { return b < ob.b; } } a[200010]; struct __ { int val, id; bool operator<(const __ &ob) const { return val < ob.val; } }; struct event { int x, y, depth, id; }; queue<event>... |
#include <bits/stdc++.h> using namespace std; long long int seg[800005], lazy[800005]; void push(long long int v) { if (lazy[v] == 0) return; seg[2 * v] |= lazy[v]; seg[2 * v + 1] |= lazy[v]; lazy[2 * v] = lazy[v]; lazy[2 * v + 1] = lazy[v]; lazy[v] = 0; return; } void update(long ... |
#include <bits/stdc++.h> using namespace std; using ll = long long; const int nax = 107; int n, m; char wcz[nax][nax]; int oj[nax]; int fin(int v) { if (oj[v] != v) oj[v] = fin(oj[v]); return oj[v]; } void uni(int v, int u) { oj[fin(v)] = fin(u); } int main() { scanf( %d%d , &n, &m); ... |
#include <bits/stdc++.h> using namespace std; const long long N = 2e5 + 5; long long n, m; long long a[N], ans[N]; set<long long> active; int32_t main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; cin >> n; for (long long i = 1; i <= n; i++) { cin >> a[i]; activ... |
#include <bits/stdc++.h> using namespace std; const int max_n = 22, inf = 1111111111; int n, m, dp[1 << max_n], a[max_n][max_n], nmask[max_n][max_n], res[max_n][max_n]; string s[max_n]; bool get_bit(int x, int poz) { return (bool)(x & (1 << poz)); } int main() { cin >> n >> m; for (int i = 0; ... |
#include <bits/stdc++.h> using namespace std; const int maxn = 1100; int n, a[maxn], ans, t; void go(int lim) { int ret = 0; for (int i = 1; i <= n; i++) ret += min(abs(a[i] - lim), min(abs(a[i] - (lim + 1)), abs(a[i] - (lim - 1)))); if (ret < ans) ans = ret, t = lim; } int main(... |
#include <bits/stdc++.h> using namespace std; long long arr[500005]; long long brr[500005]; long long total[500005]; int n, r; bool fnc(long long mid, long long k) { for (int i = 1; i <= n; i++) brr[i] = 0; long long d = 0; for (int i = 1; i <= n; i++) { d += brr[i]; if (total[i] + d... |
#include <bits/stdc++.h> using namespace std; using cat = long long; struct group { char c; int l, r; group operator+(int x) const { return {c, l + x, r + x}; } group operator-(int x) const { return {c, l - x, r - x}; } }; void apply(vector<group>& gA, vector<group>& gB, int prefA, int prefB, ... |
#include <bits/stdc++.h> using namespace std; const int INF = 2123456789; int a, b, c; int n, m, k; int x, y; string s; int start[500]; int target[500]; vector<pair<int, int> > ops; int calendar[] = {0, 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334}; int search(int base, int val) { for... |
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); long long int m, b, i, x, curr, ma = 0, tot, j; cin >> m >> b; for (i = 0; i <= b; i++) { x = m * (b - i); tot = 0; for (j = i; j >= 0; j--) { curr = x * (x + 1); cur... |
#include <bits/stdc++.h> using namespace std; class ST { private: vector<long long> st; int n; int left(int p) { return p << 1; } int right(int p) { return left(p) + 1; } int query(int p, int L, int R, int i) { if (L > i) return 0; if (R <= i) return st[p]; return query(left... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int t; cin >> t; while (t--) { int n, x, y, b; cin >> n >> x >> y; b = n; int t = y - x, i, k; for (i = n - 1; i >= 1; i--) { if (t % i == 0) break; } ... |
#include <bits/stdc++.h> using namespace std; const int N = 200005; int main() { ios_base ::sync_with_stdio(0); cin.tie(0), cout.tie(0); int T; cin >> T; while (T--) { long long n, k; cin >> n >> k; long long res = 0; while (n > 0) { res += n % k; n -= n... |
#include <bits/stdc++.h> using namespace std; int main() { long long int n; string str; cin >> n; cin >> str; int len = n - 11; int coun = 0, cou = 0; for (int j = 0; j < len + 1; j++) { if (str[j] == 8 ) coun = 1, cou++; ; } if (cou > len / 2) cout << YES ; ... |
#include <bits/stdc++.h> #pragma comment(linker, /STACK:268435456 ) using namespace std; template <typename T> T sqr(const T &x) { return x * x; } template <typename T> T my_abs(const T &x) { return x < 0 ? -x : x; } const int INF = (int)1e9; const long long LINF = (long long)6e18; const ... |
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; int n, k, par[N], siz[N]; bool inv[N]; multiset<int> S; struct dist { int val, id; }; dist tab[N]; bool cmp(dist x, dist y) { return x.val < y.val; } int Find(int x) { if (par[x] != x) par[x] = Find(par[x]); return par[... |
#include <bits/stdc++.h> using namespace std; const int N = 11; const int B = 1 << 10; long long dp[B][B][N]; bool can[N][N]; vector<int> v[N + 1]; int countBits(int n) { int res = 0; while (n) { res += n % 2; n >>= 1; } return res; } bool bit(int n, int pos) { return n & (... |
#include <bits/stdc++.h> using namespace std; const int MAX_PRIMES = 15; vector<int> primes; vector<int> num[(1 << MAX_PRIMES) + 5]; bool used[(1 << MAX_PRIMES) + 5]; vector<int> BFS(int sz, int k) { queue<int> fila; vector<int> ans; fila.push((1 << sz) - 1); used[(1 << sz) - 1] = true; ... |
#include <bits/stdc++.h> using namespace std; const long double pi = acos(-1.0); long long gcd(long long a, long long b) { if (b == 0) return a; return gcd(b, a % b); } bool checkprime(long long n) { long long i = 2; while (i * i <= n) { if (n % i == 0) return 0; i++; } ret... |
#include <bits/stdc++.h> using i64 = int64_t; using u64 = uint64_t; using u32 = uint32_t; int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); int n; i64 k; std::cin >> n >> k; std::vector<int> a(n); for (int i = 0; i < n; i++) { std::cin >> a[i]; k += a[... |
#include <bits/stdc++.h> using namespace std; string s; int main() { cin >> s; int n = s.size(); bool flag = 1; for (int i = 1; i < n; i++) if (!(s[i] >= A && s[i] <= Z )) flag = 0; if (flag) { for (int i = 0; i < n; i++) if ( a <= s[i] && s[i] <= z ) cout <<... |
#include <bits/stdc++.h> using namespace std; long long labs(long long a) { return a < 0 ? (-a) : a; } long long max(long long a, long long b) { return a > b ? a : b; } long long min(long long a, long long b) { return a < b ? a : b; } vector<long long> v; long long Intersect(pair<long long, long long> p1, ... |
#include <bits/stdc++.h> int const MAX = 1e5 + 5; using namespace std; char ans[50][50]; void place(long long s, long long e, long long c, long long cnt) { int f = 0; for (long long i = s; i < e; i += 2) { for (long long j = 0; j < 50; j += 2) { if (cnt == 0) { f = 1; b... |
#include <bits/stdc++.h> long long int MOD = 1000000007; using namespace std; template <class T> inline void sary(T* st, T* nd) { while (st < nd) cin >> *st++; } template <class T> inline double sarys(T* st, T* nd, T sum) { while (st < nd) { cin >> *st++; sum += *st; } return s... |
#include <bits/stdc++.h> using namespace std; long long n; vector<long long> a; void solve() { cin >> n; a.resize(n); for (long long i = 0; i < n; ++i) { cin >> a[i]; } long long ans = 0; for (long long i = 0; i < n - 1; ++i) { if (a[i] >= 0) { a[i + 1] += a[i]; ... |
#include <bits/stdc++.h> using namespace std; struct LazySegTree { int size; vector<long long> seg, delay; LazySegTree() {} LazySegTree(int size) { this->size = size; seg.resize(1 << (size + 1)); delay.resize(1 << (size + 1)); } long long Ident() { return 0; } long long... |
#include <bits/stdc++.h> using namespace std; const int MAXN = 140011, MAXLOG = 20; int ST[MAXN][MAXLOG][4]; int a[MAXN][4]; int lgdos[MAXN]; int n, m; inline void Build() { for (int i = 1; i <= n; ++i) { for (int j = 0; j < 4; ++j) { ST[i][0][j] = a[i][j]; } } lgdos[1] = 0... |
#include <bits/stdc++.h> using namespace std; const int N = 1000; vector<pair<int, int> > type[2]; vector<int> ans[N]; int a[N], t[N]; int main() { int n, k; while (scanf( %d %d , &n, &k) == 2) { type[0].clear(); type[1].clear(); for (int i = 0; i < int(k); i++) ans[i].clear(); ... |
#include <bits/stdc++.h> using namespace std; const int inf = 1 << 30; const long long maxn = 3 * 1e5 + 10; int n, c[maxn]; int main() { cin >> n; for (int i = 1; i <= n; i++) cin >> c[i]; int ans = 0; for (int i = 2; i <= n; i++) { if (c[i] != c[1]) ans = max(ans, i - 1); } for ... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, m; string input; cin >> n >> m; vector<vector<int> > nodes(n, vector<int>(26)); vector<vector<int> > G(n); int indegree[n]; memset(indegree, 0, sizeof(indegree)); ... |
#include <bits/stdc++.h> const int MOD = 1e9 + 7; const int INF = 1e9 + 7; const int MAXN = 1e3 + 5; const double eps = 1e-14; using namespace std; int a[MAXN][5], acp[5], acVasya[5], price[5], curAc[5], curP[5]; int n; int ans = INF + 1; bool cmpFrac(int x, int y, int p, int q) { return (x * q > y * ... |
#include <bits/stdc++.h> using namespace std; const int maxn = 300 + 10; int n, a[maxn], b[maxn]; int main() { scanf( %d , &n); for (int i = 0; i < n; ++i) scanf( %d , a + i); for (int i = 0; i < n; ++i) scanf( %d , b + i); vector<int> seq; for (int i = 0; i < n; ++i) if (b[i] != a[i])... |
#include <bits/stdc++.h> using namespace std; int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } int main() { int n, m, k; cin >> n >> m >> k; int a[n]; long long x, s = m, p; map<int, int> ma; for (int i = 0; i < n; i++) { scanf( %d , &a[i]); ma[a[i]] = i; } for (... |
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10, OO = 0x3f3f3f3f; const int mod = 1e9 + 7; int a[60][60]; int ans[60]; bool done[60]; int main() { int n; scanf( %d , &n); for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { scanf( %d , &a[i][j]); ... |
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const int MAXN = 2e5 + 7; long long a[MAXN]; int dis[233][233]; int val[233][233]; int main(int argc, char const *argv[]) { int n; scanf( %d , &n); for (int i = (1); i <= (n); ++i) { scanf( %lld , &a[i]); if (a[... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); long long n, x1, y1, x2, y2; cin >> x1 >> y1; cin >> x2 >> y2; cin >> n; int res = 0; for (int i = 0; i < n; i++) { long long a, b, c; cin >> a >> b >> c; long long dir1 = a * x1 + ... |
#include <bits/stdc++.h> using namespace std; int _I() { int x; scanf( %d , &x); return x; } long long _L() { long long x; scanf( %lld , &x); return x; } long long gcd(long long a, long long b) { while (b) b ^= a ^= b ^= a %= b; return a; } long long lcm(long long x, long... |
#include <bits/stdc++.h> using namespace std; const int maxn = 110; int n, m; string s; int a[maxn]; int main() { cin >> n >> m; int cnt = 0; while (n--) { cin >> s; if (s[0] == a ) { int x; cin >> x; int num = 0; bool flag = false; for (int i... |
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; int a[n][m], b[n][m]; vector<int> aa[1000]; vector<int> bb[1000]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { cin >> a[i][j]; aa[i + j].push_back(a[i][j]); } } ... |
#include <bits/stdc++.h> using namespace std; long long x[123456]; long long y[123456]; int main() { ios_base::sync_with_stdio(0); long long n, d; cin >> n >> d; if (n * (n - 1) / 2 <= d) { cout << no solution ; } else { for (int i = 0; i < n; ++i) cout << 0 << << i << endl;... |
#include <bits/stdc++.h> using namespace std; const int MAXN = 200010; int ans[MAXN]; void solve(int l, int r) { if (l > r) return; cout << ? << l + 1 << << r + 1 << endl; int x, f; cin >> x >> f; int st = r - f + 1; int en = l + f - 1; if (st <= en) { for (int i = st, T... |
#include <bits/stdc++.h> using namespace std; const int N = 250001; long long po[N]; long long n, p; int main() { cin >> n >> p; po[0] = 1; for (int i = 1; i <= n; i++) { po[i] = 1LL * po[i - 1] * i % p; } int ans = 0; for (int i = 1; i <= n; i++) { int s = 1ll * po[n - i] ... |
#include <bits/stdc++.h> using namespace std; const long double PI = 3.14159265359; const long long MOD = (long long)998244353ll; const long long MAXN = (long long)3e5 + 10; const long long INF = (long long)2242545357980376863; const long double EPS = (long double)1e-8; set<char> st; string s; bool ch... |
#include <bits/stdc++.h> using namespace std; void solve() { int n, m; cin >> n >> m; string s[n]; for (int i = 0; i < n; i++) cin >> s[i]; int ans = 0; for (int i = 0; i < m - 1; i++) { if (s[n - 1][i] == D ) ++ans; } for (int i = 0; i < n - 1; i++) { if (s[i][m - 1] ==... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.precision(20); string s; cin >> s; double x = 10 * (s[0] - 0 ) + s[1] - 0 ; double y = 10 * (s[3] - 0 ) + s[4] - 0 ; if (x < 12) { cout << fixed << x * 30 + y / 2 <... |
#include <bits/stdc++.h> using namespace std; vector<long long int> L, R, a; stack<long long int> same; signed main() { long long int n; cin >> n; a.resize(n, -1); for (long long int i = 0; i < n; i++) { long long int x; cin >> x; L.push_back(x); } for (long long int i ... |
#include <bits/stdc++.h> using namespace std; const long long N = 1e5 + 10; const long long M = 1e7 + 1000; const long long mod = 1e9 + 7; const long long INF = 1e18; const long long inf = -1e18; bool isprime(long long x) { if (x == 1) return false; long long y = sqrt(x); for (int i = 2; i <= ... |
#include <bits/stdc++.h> using namespace std; const int MOD = (int)1e9 + 7; const int INF = (int)1e9; const long long LINF = (long long)1e18; const long double PI = acos((long double)-1); const long double EPS = 1e-9; inline long long gcd(long long a, long long b) { long long r; while (b) { ... |
#include <bits/stdc++.h> using namespace std; const long long int MOD = 1e9 + 7; const vector<long long int> dx = {1, -1, 0, 0}; const vector<long long int> dy = {0, 0, 1, -1}; void solve() { string s; cin >> s; long long int k = s.length(); long long int cnt = 1; char cur = s[0]; long... |
#include <bits/stdc++.h> using namespace std; const int N = 200100; int n, x, y, q; char c; long long a[N], k[N], M[N], A[N]; set<int> s; void update(int x, long long mul, long long val) { while (x < n) { M[x] += mul; A[x] += val; x |= (x + 1); } } void add(int l, int r, long... |
#include <bits/stdc++.h> using namespace std; int a, b, x, y, fen, k; inline int gcd(int x, int y) { if (y == 0) return x; return gcd(y, x % y); } int main() { scanf( %d%d%d%d , &a, &b, &x, &y); k = gcd(x, y); x /= k; y /= k; fen = min(a / x, b / y); printf( %d %d n , fen * x, ... |
#include <bits/stdc++.h> using namespace std; const int inf = 2000000000; const int MOD = 1000000007; int n, m, k = 0, c = 0, q; map<int, char> mp; map<char, int> cnt; int main() { string s; cin >> s; bool f1 = 0, f2 = 0, f3 = 0, f4 = 0; for (int i = 0; i < s.length(); i++) { if (s[i... |
#include <bits/stdc++.h> using namespace std; long long n, r1, r2, r3, d; long long a[1000003]; long long dp[1000003][2]; long long f(int i, int j) { if (i == n) return -d; if (dp[i][j] != -1) return dp[i][j]; long long res1 = 1e18, res2 = 1e18; if (j == 0) { res1 = f(i + 1, 0) + a[i] * ... |
#include <bits/stdc++.h> using namespace std; int n, d; int stone[30000 + 3]; int f[30000 + 3][2 * 300 + 3]; int p[30000 + 3]; int main(int argc, char* argv[]) { scanf( %d %d , &n, &d); for (int i = 0; i < n; i++) { int tmp; scanf( %d , &tmp); stone[tmp]++; p[i] = tmp; } ... |
#include <bits/stdc++.h> using namespace std; int a[100005]; int main() { int t; cin >> t; while (t--) { int k1 = 0, k2 = 0; string s; cin >> s; if (s[0] == 0 ) k2++; if (s[0] == 1 ) k1++; for (int i = 1; i < s.size(); i++) { if (s[i - 1] != s[i]) { ... |
#include <bits/stdc++.h> using namespace std; const double eps = 1e-10; const double pi = 3.1415926535897932; const double eln = 2.718281828459045; vector<int> a[200005]; int p[200005], b[200005], od[200005]; void second(int m, int dah) { p[m] = dah; b[m] = 1; for (int i = 0; i < a[m].size(); ... |
#include <bits/stdc++.h> using namespace std; const int maxn = 400010; pair<int, int> a[maxn], b[maxn]; int tot, cnt[110]; double qpow(double a, int x) { double res = 1.0; while (x) { if (x & 1) res = res * a; a = a * a; x >>= 1; } return res; } int main() { int N, M,... |
#include <bits/stdc++.h> using namespace std; int n, m, sum; int s[200010]; vector<pair<int, int> > G[200010]; int fa[200010]; int vis[200010]; int ans[200010]; void dfs(int x, int fa, int id) { vis[x] = 1; for (int i = 0; i < G[x].size(); i++) { int to = G[x][i].first; int id = G[x]... |
#include <bits/stdc++.h> using namespace std; int main() { int t; scanf( %d , &t); while (t--) { int n; scanf( %d , &n); vector<vector<long long>> a(n); for (int i = 0; i < n; i++) { int m; long long p; scanf( %d , &m); scanf( %lld , &p); a... |
#include <bits/stdc++.h> using namespace std; int ccount[1000000 + 10]; bitset<1000000 + 100> v; unsigned long int N; vector<int> primes; int cc = 0; int primeSize; void generatePrimes() { N = 1000000 + 2; cc = 0; v.set(1); unsigned long int i, j; for (i = 2; i < N + 1; i++) { ... |
#include <bits/stdc++.h> using namespace std; int32_t main() { ios::sync_with_stdio(false); cin.tie(0); long long n; cin >> n; map<pair<long long, long long>, set<pair<long long, long long>>> mp; for (long long i = 1; i <= n; i++) { long long x, y, z; cin >> x >> y >> z; mp... |
#include <bits/stdc++.h> using namespace std; const long long N = 1e5 + 5; long long n, p, a[N], C[N], st, End; void in() { cin >> n >> p; for (long long i = 0; i <= n - 1; i++) cin >> a[i]; sort(a, a + n); } long long bns(long long lim) { long long low = 0, high = n - 1, res = -1; while... |
#include <bits/stdc++.h> using namespace std; int n; map<pair<pair<bool, int>, pair<int, int>>, int> dp; int recurse(bool asc, int cx, int cy, int hm) { if (hm < 0 || cx > n) return 0; if (hm == 0) { if (asc && cx == n) return 1; else return 0; } pair<pair<bool, int>,... |
#include <bits/stdc++.h> using namespace std; long long mod = 1e9 + 7; long long po(long long x, long long y, long long p) { long long res = 1; x = x % p; if (x == 0) return 0; while (y > 0) { if (y & 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res; } ... |
#include <bits/stdc++.h> using namespace std; long long int p[200008] = {0}; int main() { ios_base::sync_with_stdio(false); long long int n, z, x, i; long double p, q; cin >> n; for (i = 0; i < n; i++) { cin >> x; z = x * x - 4 * x; if (z < 0) { cout << N n ; ... |
#include <bits/stdc++.h> using namespace std; string str[500005]; int main() { int n; cin >> n; for (int i = 0; i < n; i++) cin >> str[i]; for (int i = n - 2; i >= 0; i--) { if (str[i] > str[i + 1]) { string temp; for (int j = 0; j < str[i].length(); j++) { if (str[... |
#include <bits/stdc++.h> using namespace std; template <typename T> inline T read(register T& t) { register T f = 1; register char ch = getchar(); t = 0; while (ch < 0 || ch > 9 ) { if (ch == - ) f = -f; ch = getchar(); } while (ch >= 0 && ch <= 9 ) t = t * 10 + ch - 0 ... |
#include <bits/stdc++.h> using namespace std; int main() { long long int n, m, x, p, l, r, e, ans, set; l = r = e = ans = 0; cin >> n >> x; vector<long long int> a(n); set = 0; m = (n + 1) / 2; for (int i = 0; i < n; i++) { cin >> a[i]; if (a[i] < x) l++; if (a[i] > x) ... |
#include <bits/stdc++.h> using namespace std; bool b[33333]; vector<int> pri; vector<pair<int, int> > fac; int n; void init() { for (int i = 2; i < 33333; ++i) { if (!b[i]) { pri.push_back(i); for (int j = i + i; j < 33333; j += i) { b[j] = false; } } } ... |
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; long long l[1001]; long long r[1001]; long long f = 0; long long ar[1005] = {0}; for (int i = 0; i < n; ++i) { cin >> l[i]; if (l[i] > i) f = 1; } for (int i = 0; i < n; ++i) { cin... |
#include <bits/stdc++.h> using namespace std; inline void boost() { ios_base::sync_with_stdio(0); cin.tie(0), cout.tie(0); } string s, fp, sp; bool ok = 0; int pw; void checkF() { if (!(int)fp.size()) { fp = ; return; } int it = 0; string nw = ; string buff = ... |
#include <bits/stdc++.h> using namespace std; int main() { int N, M; scanf( %d%d , &N, &M); if (M == 3 && N > 4) { puts( -1 ); return 0; } for (int i = 1; i <= M; ++i) { printf( %d %d n , i - 101, i * i); } N -= M; for (int i = 1; i <= N; ++i) { printf( %d %d ... |
#include <bits/stdc++.h> using namespace std; const int N = 200005; int a[N], f[N]; long long dis[N], pos[N], res[N]; int n; void add(long long *b, int x, long long v) { for (int i = x; i <= n; i += i & -i) b[i] += v; } long long qry(long long *b, int x) { long long ret = 0; for (int i = x; ... |
#include <bits/stdc++.h> using namespace std; int c1; struct state { int h1, a1, h2, a2, level; int laststate; state() {} state(int a, int b, int c, int d, int e, int f) : h1(a), a1(b), h2(c), a2(d), level(e), laststate(f) {} }; int main() { ios_base::sync_with_stdio(0), cin.tie(0)... |
#include <bits/stdc++.h> using namespace std; const int MX = 3e3 + 5; int n, l[MX], r[MX], q[2 * MX]; int dp[2 * MX][2 * MX]; vector<int> sg[2 * MX]; void inline upmx(int& x, int y) { if (y > x) x = y; } void solve() { cin >> n; for (int i = (0); i < (n); ++i) { int li, ri; cin >... |
#include <bits/stdc++.h> using namespace std; int n, c; long long a[3001]; pair<int, int> sol[3001]; int main() { ios_base::sync_with_stdio(0); cin >> n; for (int i = 0; i < n; ++i) cin >> a[i]; c = 0; for (int i = 0; i < n; ++i) { int mn = i; for (int j = i + 1; j < n; ++j) { ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.