func_code_string stringlengths 59 71.4k |
|---|
#include <bits/stdc++.h> using namespace std; const double eps = 1e-8; const int inf = 0x3f3f3f3f; const int mod = 1000000007; const int maxn = 100000 + 10; string s, str[maxn]; int n; long long bit[10], len[10]; bool used[10]; long long Qpow(int x, long long b) { long long tmp = x, ret = 1; ... |
#include <bits/stdc++.h> using namespace std; int k, i, j, n; double ans, x[100010], xp, yp, xk; double C(int z) { return hypot(x[z] - xp, yp); } double A(int l, int r) { return x[r] - x[l] + min(C(l), C(r)); } double B(int l, int r) { return x[r] - x[l] + min(abs(xk - x[l]) + C(r), abs(xk - x[r]) + C(l... |
#include <bits/stdc++.h> using namespace std; vector<long long> tri(100005); void solve() { long long n; cin >> n; for (long long i = 1; i < 100005; i++) { tri[i] = (i * (i + 1)) / 2LL; } for (int i = 1; i <= 100000; i++) { long long x = n - tri[i]; if (x <= 0) { cout... |
#include <bits/stdc++.h> using namespace std; const double pi = atan(1) * 4; const double EXP = 1e-8; struct node { int x, y; double a; } light[30]; double cal(double pos, node l) { double len = sqrt((l.x - pos) * (l.x - pos) + l.y * l.y); if (pos > l.x) { if (l.a < atan(l.y * 1.0 / (p... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr); long long int t; cin >> t; while (t--) { long long int n; cin >> n; vector<long long int> a(n); vector<long long int> b(n); for (long long i... |
#include <bits/stdc++.h> using namespace std; int a[3003]; int main() { int n, inv = 0; cin >> n; for (int i = 0; i < n; ++i) cin >> a[i]; for (int i = 0; i < n; ++i) for (int j = i + 1; j < n; ++j) if (a[i] > a[j]) ++inv; if (inv % 2 == 0) cout << fixed << setprecision(6) ... |
#include <bits/stdc++.h> template <class t> inline void read(t &s) { s = 0; register int f = 1; register char c = getchar(); while (!isdigit(c)) { if (c == - ) f = -1; c = getchar(); } while (isdigit(c)) s = (s << 3) + (s << 1) + (c ^ 48), c = getchar(); s *= f; return; ... |
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 100010; const ll INF = 1e9 + 69; int n, a[N]; string good; bitset <N> mul; void fuck (int ss, int ee) { int st = ss, en = ee; while (st <= ee and a[st] == 1) ++st; while (en >= ss and a[en] == 1)... |
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 10; int p[N], a[N], idx, pre[N]; void xxs() { int kns = 0; for (int i = 2; i <= N; i++) { if (!a[i]) { p[++idx] = i; kns++; } for (int j = 1; j <= idx && i * p[j] <= N; j++) { a[i * p[j]] = 1; ... |
#include <bits/stdc++.h> using namespace std; const int Maxn = 20005; const long long Inf = 1000000000000000000ll; int n, m, k; int s1, s2, f; int a[Maxn], b[Maxn], lef[Maxn], rig[Maxn]; vector<pair<int, int> > neigh[Maxn]; long long dist1[Maxn], dist2[Maxn]; void Solve(bool wineq) { fill(dist1, d... |
#include <bits/stdc++.h> using namespace std; const int mm = 100010; double f[mm][110], ans; int a[mm], b[mm], x, y, k, i, j, l, n, m; int main() { scanf( %d , &n); for (i = 1; i <= n; ++i) scanf( %d , &a[i]), f[i][b[i] = a[i]] = 1, ans += f[i][0]; scanf( %d , &m); for (i = 1; i <= m; ++... |
#include <bits/stdc++.h> using namespace std; map<pair<int, int>, bool> mp; pair<int, int> ara[400005]; int main() { int n, m, x; scanf( %d %d , &n, &m); for (int i = 1; i <= m; i++) { scanf( %d %d , &ara[i].first, &ara[i].second); ara[i].first %= n, ara[i].second %= n; if (ara[i].... |
#include <bits/stdc++.h> using namespace std; int main(void) { int n; cin >> n; int a[n]; int ans = 0; int i, j, k; for (i = 0; i < n; i++) cin >> a[i]; for (i = 1; i < n - 1; i++) { if (((a[i] > a[i + 1]) && (a[i] > a[i - 1])) || ((a[i] < a[i - 1]) && (a[i] < a[i + 1])))... |
#include <bits/stdc++.h> using namespace std; const string c[5] = { S , M , L , XL , XXL }; int n[5], m, i, j, l, r, x; char st[7]; string s; int main() { for (i = 0; i < 5; i++) scanf( %d , &n[i]); scanf( %d , &m); for (i = 0; i < m; i++) { scanf( %s , st); s = st; for (j ... |
#include <bits/stdc++.h> using namespace std; int n, t[155][4], m, f[155][55][55][55], c[4]; char s[155]; int main() { scanf( %d , &n); scanf( %s , s + 1); for (int i = 1; i <= n; ++i) s[i] -= a ; for (int i = n; i >= 1; --i) { c[s[i]] = i; for (int j = 0; j <= 2; ++j) t[i][j] = c[j... |
#include <bits/stdc++.h> using namespace std; template <typename T, typename A> istream& operator>>(istream& in, vector<T, A>& p) { for (auto& i : p) in >> i; return in; } template <typename T, typename A> ostream& operator<<(ostream& out, std::vector<T, A> const& v) { for (auto i : v) out << i ... |
#include <bits/stdc++.h> using namespace std; const int MOD = 998244353; long long int memo[1005][2005][4]; int n, k; void solve() { for (int i = 2; i <= n; i++) { for (int j = 1; j <= i * 2; j++) { memo[i][j][0] = (memo[i - 1][j][0] + memo[i - 1][j][1] + memo[i - 1]... |
#include <bits/stdc++.h> using namespace std; inline void re(int &x) { x = 0; bool flag = false; char c = getchar(); while (c < 0 || c > 9 ) { flag = c == - ; c = getchar(); } while (c >= 0 && c <= 9 ) { x = (x << 1) + (x << 3) + (c ^ 0 ); c = getchar(); }... |
#include <bits/stdc++.h> using namespace std; int n, a[1010], dp[1010][260], g[10], f[10][1010], h[1010]; int check(int x) { memset(dp, -0x3f3f3f3f, sizeof(dp)); dp[0][0] = 0; for (int i = 0; i < n; i++) for (int j = 0; j < 256; j++) { if (i > 0) dp[i][j] = dp[i - 1][j]; if (j & ... |
#include <bits/stdc++.h> using namespace std; template <typename T> ostream& operator<<(ostream& out, const vector<T>& v) { out << [ ; for (const T& x : v) { out << x << , ; } return out << ] ; } template <typename S, typename T> ostream& operator<<(ostream& out, const pair<S, T>& ... |
#include <bits/stdc++.h> using namespace std; const int mx = (int)1e5 + 5; const long long mo = 998244353; int a[mx], cnt[mx][105]; long long d[mx][105], sum[mx]; int main() { int n, k, len; cin >> n >> k >> len; for (int i = 1; i <= n; i++) scanf( %d , &a[i]); for (int i = 1; i <= n; i++) {... |
#include <bits/stdc++.h> using namespace std; long long t, x, n; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin >> t; while (t--) { vector<long long> v; cin >> x; for (long long i = 0; i < x; i++) { cin >> n; v.push_back(n); ... |
#include <bits/stdc++.h> using namespace std; bool sum(int num) { int ssum = 0; while (num > 0) { ssum = ssum + num % 10; num = num / 10; } if (ssum == 10) { return true; } else { return false; } } int main() { int test, num = 19; cin >> test; while (t... |
#include <bits/stdc++.h> using namespace std; using ll = long long; int const nmax = 1000; int const modulo = 1000000007; int dp[1 + nmax][1 + nmax]; int sum[1 + nmax][1 + nmax]; int main() { int n, m, cond; cin >> n >> m >> cond; if (m < n) { cout << 0; return 0; } dp[0][0... |
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 5; int n, q; set<pair<int, int> > st; set<int> unread[N]; int32_t main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; cin >> n >> q; int cnt = 0; while (q--) { int type, x; cin >> type; i... |
#include <bits/stdc++.h> using namespace std; void solve() { long long n, i, s = 0; cin >> n; long long a[n]; for (i = 0; i < n; i++) { cin >> a[i]; } s = s + a[0]; for (i = 1; i < n; i++) { if (a[i] != 1) { s = s + i * (a[i] - 1) + a[i]; } else { s = s ... |
#include <bits/stdc++.h> using namespace std; const long long MAXN = 100005; const long long INF = 1000000000; struct edge { long long a, b, cap, flow; }; long long n, s, t, d[MAXN], ptr[MAXN], q[MAXN]; vector<edge> e; vector<long long> g[MAXN]; void add_edge(long long a, long long b, long long ca... |
#include <bits/stdc++.h> using namespace std; const long long inf = 1e15; long long l, r; void Input() { cin >> l >> r; } void Solve() { if (r <= 10) { long long Res = 0; for (long long a = l; a <= r; ++a) { for (long long b = l; b <= a; ++b) Res = max(Res, a % b); } cout <... |
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s; cin >> s; int i, cnt = 0; for (i = 0; i < s.size(); i++) { if (s[i] == x && s[i + 1] == x && s[i + 2] == x && i < n - 2) cnt++; } cout << cnt << endl; } |
#include <bits/stdc++.h> using namespace std; const int BLOCK = 316; const int N = 100100; vector<int> vc, g[N]; int col[N], l[N], r[N], nm[N], kol[N], ans[N], sum[N]; int tin[N], tout[N], n, q, kl[N]; void dfs(int v, int p) { tin[v] = ((int)vc.size()); vc.push_back(v); for (int u : g[v]) { ... |
#include <bits/stdc++.h> using namespace std; int f[10001]; int main() { int a, b = -99999, c = 0; cin >> a; for (int i = 1; i <= a; i++) cin >> f[i]; for (int i = 1; i <= a; i++) b = max(b, f[i]); for (int i = 1; i <= a; i++) c += (b - f[i]); cout << c << endl; return 0; } |
#include <bits/stdc++.h> using namespace std; const int oo = (int)1e9, MAXN = (int)1e3; const long long ooll = 1000000000000000000ll; int weight[MAXN][MAXN], length[MAXN][MAXN], ride[MAXN], cost[MAXN], n, m, first, last; vector<vector<int> > graph; int temp[MAXN]; void calculate(int v) { memset(... |
#include <bits/stdc++.h> using namespace std; const int N = 300005; int a[N], mx[N], ans[N]; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; vector<pair<int, int> > vec; for (int i = 1; i <= n; i++) { cin >> a[i]; vec.emplace_back(a[i], i); } ... |
#include <bits/stdc++.h> using namespace std; inline int setBit(int N, int pos) { return N = N | (1 << pos); } inline int resetBit(int N, int pos) { return N = N & ~(1 << pos); } inline bool checkBit(int N, int pos) { return (bool)(N & (1 << pos)); } const long long MAX = 300005; int n; vector<int> graph[... |
#include <bits/stdc++.h> using namespace std; const int maxn = 5005; int id[maxn][maxn]; char s[maxn][maxn]; char c[maxn]; int l[maxn], r[maxn], u[maxn], d[maxn]; int n, m, t; void init() { int i, j; for (i = 1; i <= n; i++) { for (j = 1; j <= m; j++) { l[id[i][j]] = id[i][j - 1]; ... |
#include <bits/stdc++.h> using namespace std; void printv(vector<int> v) { for (int i = 0; i < v.size(); i++) cout << v[i] << ; cout << endl; } unsigned long long summ(unsigned long long n) { return ((n * n) + n) / 2; } bool isubseq(string s, string s1) { int ln = s1.length(); int lll = s.l... |
#include <bits/stdc++.h> using namespace std; template <typename T> inline void read(T &x) { x = 0; char c = getchar(); bool flag = false; while (!isdigit(c)) { if (c == - ) flag = true; c = getchar(); } while (isdigit(c)) { x = (x << 1) + (x << 3) + (c ^ 48); c = ... |
#include <bits/stdc++.h> using namespace std; const double ESP = 1e-9; const int N = 2e5 + 1; int arr[N], n; bool canCover(double d) { int used = 0; double lastcoverd = 0.0; for (int i = 0; i < n; ++i) { if (arr[i] > lastcoverd) { lastcoverd = arr[i] + (2 * d); ++used; ... |
#include <bits/stdc++.h> using namespace std; const long long N = 200005; int32_t main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long n; cin >> n; vector<long long> v(n); for (long long i = 0; i < n; i++) cin >> v[i]; vector<long long> ans(n); sort(v.begin(), v... |
#include <bits/stdc++.h> using namespace std; const int mn = 200005; const int mod = 1e9 + 7; int n, m; unordered_set<int> h[mn]; priority_queue<pair<int, int> > q; int sum = 0; int maxi, mini; vector<tuple<int, int, int> > ans; int main() { scanf( %d%d , &n, &m); for (int i = 1; i <= n; i++... |
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[n]; for (int i = 0; i < n; i++) scanf( %d , &a[i]); string s; cin >> s; int c1[n], c2[n]; c2[0] = a[0]; if (s[0] == 1 ) c1[0] = a[0]; else c1[0] = 0; for (int i = 1; i < n; i++)... |
#include <bits/stdc++.h> using namespace std; inline int read() { register int X = 0; register char ch = 0; while (ch < 48 || ch > 57) ch = getchar(); while (ch >= 48 && ch <= 57) X = X * 10 + (ch ^ 48), ch = getchar(); return X; } int n, m; struct Point { int l, r, x, y; } b[600500]... |
#include <bits/stdc++.h> using namespace std; const long long orz = 1e9 + 7; char s[500100]; vector<long long> xc; vector<long long> yc; vector<long long> tempx; vector<long long> tempy; int n, h, w, len, x, y, ly, uy, lx, rx, i, nx, ny, xs, ys, flag; long long ans, temp; int main() { scanf( %d%... |
#include <bits/stdc++.h> using namespace std; const int OO = 1e9; const double EPS = 1e-9; #define ndl cout << n #define sz(v) int(v.size()) #define pb push_back #define mp make_pair #define fs first #define sc second #define present(a, x) (a.find(x) != a.end()) #ifdef LOCAL #define ... |
#include <bits/stdc++.h> using namespace std; long long Hash(char* s, int sz) { const int p = 31; long long hash = 0, p_pow = 1; for (size_t i = 0; i < sz; ++i) { hash += (s[i] - a + 1) * p_pow; p_pow *= p; } return hash; } int gcd(int a, int b) { while (b) { a %= b; ... |
#include <bits/stdc++.h> using namespace std; int ans[5432][5432], p[5432], b[5432], p_true[5432], b_true[5432]; int main() { int n; scanf( %d , &n); int x; for (int i = 0; i < n; i++) { printf( ? %d %d n , i, 0); fflush(stdout); scanf( %d , &x); ans[i][0] = x; } fo... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long int t, n; cin >> t; while (t--) { cin >> n; long long int a[n]; for (int i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); if (a[0] == a... |
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; vector<int> ed[N], leaves; int n, root = -1; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin >> n; for (int i = 1; i < n; i++) { int u, v; cin >> u >> v; ed[u].push_back... |
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<pair<long long, long long> > f(n); for (int i = 0; i < n; ++i) cin >> f[i].first >> f[i].second; sort(f.begin(), f.end()); vector<long long> v(n); v[n - 1] = f[n - 1].second; for (int i = n - 2; i >= 0... |
#include <bits/stdc++.h> using namespace std; bool isOk(string s) { for (long long i = 0; i + 1 < s.size(); i++) { if (s[i] == 1 && s[i + 1] == 1 ) { return false; } } return true; } int main() { long long n; cin >> n; string s; cin >> s; if (!isOk(s)) { ... |
#include <bits/stdc++.h> using namespace std; long long N, M, a, b, c, t[100007], C, D, S, nn, ans; char s[100007]; int main() { scanf( %I64d%I64d%I64d , &N, &C, &D); for (long long i = 1; i <= N; i++) { scanf( %d , &t[i]); scanf( %c%c , &s[i], &s[i]); } scanf( %d , &t[N + 1]); a... |
#include <bits/stdc++.h> using namespace std; int main() { char str[105]; int n, d; while (~scanf( %d%d , &n, &d)) { int sum = 0, flag = 0; int maxn = 0; for (int i = 0; i < d; i++) { scanf( %s , str); for (int i = 0; i < strlen(str); i++) { if (str[i] == 0 )... |
#include <bits/stdc++.h> int main() { int n; scanf( %d , &n); int a[1001] = {0}, t, x; bool flag = false; if (n % 2 == 0) x = n / 2; else x = n / 2 + 1; for (int i = 0; i < n; i++) { scanf( %d , &t); a[t]++; if (a[t] > x) flag = true; } if (flag) ... |
#include <bits/stdc++.h> using namespace std; long long GCD(long long a, long long b) { if (b == 0) return a; return (a % b == 0 ? b : GCD(b, a % b)); } long long POW(long long base, long long exp) { long long val; val = 1; while (exp > 0) { if (exp % 2 == 1) { val = (val * bas... |
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; int n, fa, h[N]; vector<int> G[N], p, q; int main() { scanf( %d , &n); for (int i = (1); i <= (n - 1); ++i) scanf( %d , &fa), G[fa].push_back(i); function<void(int)> dfs = [&](int u) { for (int v : G[u]) dfs(v), h[u] = max... |
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { long long d[3]; cin >> d[0] >> d[1] >> d[2]; sort(d, d + 3); if (d[2] >= d[0] + d[1]) cout << d[0] + d[1] << endl; else { cout << d[2] + (d[1] + d[0] - d[2]) / 2 << end... |
#include <bits/stdc++.h> using namespace std; pair<long long, long long> orderA[500005]; pair<long long, long long> orderB[500005]; void copyArray(int mBegin, int mEnd) { for (int i = mBegin; i < mEnd; i++) { orderA[i] = orderB[i]; } } void doMerge(int mBegin, int mMid, int mEnd) { int i =... |
#include <bits/stdc++.h> using namespace std; int n, h[260], f = 1, c, g, i; string s; int main() { cin >> s >> n; if (n > s.length()) return cout << impossible , 0; for (i = 0; i < s.length(); i++) h[s[i]]++; for (i = 97; i <= 122; i++) if (h[i] > 0) g++; if (g < n) c = n - g; ... |
#include <bits/stdc++.h> using namespace std; double EPS = 1e-11; double a[4]; double p[4][2] = {{-1, -1}, {1, -1}, {-1, 1}, {1, 1}}; bool poss(double thr) { double min03 = numeric_limits<double>::infinity(); double max03 = -numeric_limits<double>::infinity(); double min12 = numeric_limits<double>... |
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e5 + 5; int vecinos[MAXN]; int prof[MAXN]; int n; set<int> arbol[MAXN]; void dfs(int i, int p, int profund) { prof[i] = profund; for (int h : arbol[i]) { if (h == p) continue; dfs(h, i, profund + 1); } } int main()... |
#include <bits/stdc++.h> using namespace std; int main() { int64_t t, a, b; cin >> t; while (t--) { cin >> a >> b; cout << max(a, max(b, min(a, b) * 2)) * max(a, max(b, min(a, b) * 2)) << endl; } } |
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 100, LG = 19; struct edge { int u, v, w, c, i, in; bool operator<(const edge &b) const { return w < b.w; } } arr[N]; vector<pair<int, int> > adj[N]; int ST[N][LG], mx[N][LG], in[N], out[N]; bool isAncestor(int u, int v) { return in[... |
#include <bits/stdc++.h> using namespace std; int main() { int n, count = 0, i, flag = 1; cin >> n; char s[n + 1], c; cin >> s; int l = 0, r = 0; l++; for (i = 1; i < n; i++) { c = s[i]; if (c == s[0]) l++; else r++; if (r > l && flag == 1) { ... |
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const int N = 1e6 + 10; const long long INF = 1e18; const long double EPS = 1e-12; long long w[200005]; long long h[200005]; long long c[200005]; long long rgcd[200005]; map<long long, vector<pair<long long, long long> > > ma; ... |
#include <bits/stdc++.h> using namespace std; long long m, e, h, x, y; long long cal() { for (int i = 0; i <= m * 2; i++) { h = (h * x + y) % m; if (h == e) return i + 1; } return -1; } void exgcd(long long a, long long b, long long& d, long long& x, long long& y) { if (!b) d... |
#include <bits/stdc++.h> using namespace std; int main() { int n, t, p = 0, k = 0; cin >> n; for (int i = 0; i <= n; i++) { if (i < n) cin >> t; else t = 90; if (t - p > 15 && k == 0) { k = p + 15; } else p = t; } if (k == 0) k = p; cou... |
#include <bits/stdc++.h> using namespace std; const int N_ = 25; int N; char D[N_][N_]; int Table[40][1 << 20]; bool Chk[40][1 << 20]; int wh[26][N_ + N_]; int cst[2][2] = {{1, -1}, {-1, 1}}; int solve(int x, int state) { if (x == N + N - 1) return 0; if (Chk[x][state]) return Table[x][state];... |
#include <bits/stdc++.h> int cmpfunc(const void *a, const void *b) { return (*(int *)a) - (*(int *)b); } int main() { int n, arr[200000], i, r, count = 0; long long int result = 0; double root; scanf( %d , &n); for (i = 0; i < n; i++) scanf( %d , &arr[i]); for (i = 0; i < n; i++) { roo... |
#include <bits/stdc++.h> using namespace std; const int B = 31; const int N = 107; int a[N]; bool vis[1000007]; map<int, int> state; map<int, int> sgn; int tc = -1; inline int grrr(int mask) { if (mask < 2) return 0; auto it = sgn.find(mask); if (it != sgn.end()) return it->second; vec... |
#include <bits/stdc++.h> using namespace std; bool isprime[1000001]; void sieve() { for (long long i = 0; i <= 1000001; i++) { isprime[i] = true; } isprime[0] = false; isprime[1] = false; for (long long i = 2; i * i <= 1000001; i++) { if (isprime[i] == true) { for (long lon... |
#include <bits/stdc++.h> using namespace std; long long solve(long long a, long long b, long long n, long long l, long long r) { if (b <= l || r <= a) return 0; if (a <= l && r <= b) return n; long long mid = (l + r) / 2; long long lch = solve(a, b, n / 2, l, mid); long long rc... |
#include <bits/stdc++.h> using namespace std; int main(void) { int n, S; scanf( %d , &n); scanf( %d , &S); string st; map<int, int> b, s; for (int i = 0; i < n; i++) { cin >> st; int p, q; scanf( %d , &p); scanf( %d , &q); if (st[0] == B ) { b[p] += q; ... |
#include <bits/stdc++.h> using namespace std; const int mn = 1005; int n, v[mn]; int main() { ios_base::sync_with_stdio(false); cin >> n; for (int x = 0; x < n; ++x) cin >> v[x]; int ans = 0; for (int x = 0; x < n; ++x) { if (v[x] == 0) continue; while (v[x] == 1 && x < n) ++ans,... |
#include <bits/stdc++.h> using namespace std; const int mod = 1e6; int q, lstAns, flag; long long m; struct point { long long x, y; point(long long x, long long y) : x(x), y(y) {} inline bool operator<(const point &a) const { if (flag) return y < a.y; return x < a.x; } inline p... |
#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--) { long long int n, y, k; cin >> n >> y >> k; if (n < y) swap(n, y); if (k < n) { cout << -1 << endl; co... |
#include <bits/stdc++.h> using namespace std; inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; } const int inf = 1 << 29; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t; cin >> t; while (t--) { long long a, b, c, d; cin >> a >> b >> c >> d; ... |
#include <bits/stdc++.h> using namespace std; vector<int> e[3005]; int a, b, step[3005][3005], N, M, p[5], res = -1, ans[5], q[3005], qe, st[3005][5], ed[3005][5]; inline void bfs(int x) { step[x][x] = 0; qe = 0; q[qe++] = x; for (int i = 0; i < qe; i++)... |
#include <bits/stdc++.h> using namespace std; const long long inf = (1ll << 60); int n, k, p; int a[2005], b[2005]; long long dp[2005][2005]; long long rec(int pos, int key) { if (pos == n) { return 0; } if (key == k) return inf; long long &ret = dp[pos][key]; if (ret != -1) return... |
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; vector<int> adj[n], in[n]; int ot[n]; for (int i = 0; i < n; i++) ot[i] = 0; for (int i = 0; i < m; i++) { int x, y; cin >> x >> y; x--; y--; adj[x].push_back(y); in[y].pus... |
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; long long n, a[N], subtree[N], total, ans, initCost; vector<int> g[N]; void costfromRoot(int v, int prnt, int d) { initCost += d * a[v]; subtree[v] += a[v]; for (int u : g[v]) if (u != prnt) { costfromRoot(u, v, d +... |
#include <bits/stdc++.h> using namespace std; struct point { int x, y; }; struct ConvexHull { vector<point> hull; int m; ConvexHull() : m(0) { hull.clear(); } bool ccw(point x, point y, point z) { return ((y.x - x.x) * (z.y - x.y) > (y.y - x.y) * (z.x - x.x)); } void MakeHull(i... |
#include <bits/stdc++.h> #pragma GCC optimize( O3 ) using namespace std; const int N = 2e5 + 10; vector<int> g[N]; int type[N]; bool noleaf = 1; int cnt = 0; void dfs(int v, int p) { for (auto u : g[v]) { if (u == p) continue; dfs(u, v); if (type[u] == 0) { type[v] = 1; ... |
#include <bits/stdc++.h> using namespace std; void ga(int N, int *A) { for (int i(0); i < N; i++) scanf( %d , A + i); } map<int, vector<pair<int, int> > > T[4]; int N, M, a, b, f[10], C[100005]; int main(void) { scanf( %d%d , &N, &M); for (int i(0); i < M; i++) scanf( %d%d , &a, &b), T[0][... |
#include <bits/stdc++.h> using namespace std; int main() { long long n, i, lki, kills = 0, temp; long long* L = new long long[1000001]; cin >> n; for (i = 0; i < n; i++) { scanf( %ld , &L[i]); } lki = (n - 1) - L[n - 1]; kills += min(L[n - 1], n - 1); for (i = n - 2; i > 0; i--... |
#include <bits/stdc++.h> using namespace std; long long n, m, k, temp; int main() { scanf( %d%d%d , &n, &m, &k); if (n % 2 == 0 || m < (n / 2 + 1)) { printf( 0 n ); return 0; } long long minA = (m / (n / 2 + 1)) * k; for (int i = 0; i < n; i++) { scanf( %d , &temp); if ... |
#include <bits/stdc++.h> const double pi = acos(-1.0); const double eps = 1e-9; using namespace std; const long long MOD = 998244353; const int N = 2e5 + 10; long long mult(long long x, long long y) { x %= MOD; y %= MOD; return x * y % MOD; } long long bin_pow(long long x, long long n) { ... |
#include <bits/stdc++.h> using namespace std; set<int> s; int solve(vector<int> v, int k, int n) { s.clear(); for (int i = 0; i < k; i++) s.insert(v[i]); if (s.size() == k && *(s.begin()) == 1 && *(s.rbegin()) == k) { s.clear(); for (int i = k; i < n; i++) s.insert(v[i]); if (s.size(... |
#include <bits/stdc++.h> using namespace std; using ll = long long; bool compare(const pair<int, int>& a, const pair<int, int>& b) { return a.second < b.second; } bool not_fixed(vector<int>& v) { for (int i = 1; i < v.size() - 1; i++) { if (v[i] == 0 && v[i - 1] == 1 && v[i + 1] == 1) return tru... |
#include <bits/stdc++.h> using namespace std; int main() { long long n, i, j = 0, r = 0, c = 1; cin >> n; long long matrix[n][n]; for (i = 0; i < n - 1; i++) { for (j = 0; j < n - 1; j++) { matrix[i][j] = (i + j) % (n - 1) + 1; } } for (i = 0; i < n - 1; i++) { matr... |
#include <bits/stdc++.h> using namespace std; int f(string s) { int ans = 0; for (int i = 0; i < s.length(); i++) { if (s[i] == 1 ) { ans++; } } return ans; } int main() { string a, b; cin >> a >> b; int c1 = f(a); if (c1 % 2 != 0) { c1++; } if ... |
#include <bits/stdc++.h> using namespace std; const int N = 200002, SQ = 450; int n, c, a[N], first[N]; long long sum[SQ]; bool solve() { int x = c; for (int i = x; i >= 1; --i) { i = min(i, x); if (!sum[i / SQ]) { i = i / SQ * SQ; continue; } if (sum[i / SQ] <=... |
#include<bits/stdc++.h> using namespace std; int main(){ ios::sync_with_stdio(false),cin.tie(0),cout.tie(0); int t; cin >> t; while(t--){ int n ; cin >> n; vector<int> ans(n+1,1); string str; cin >> str; int cnt=0; char now=str[0]; for(int i=0 ; i<n ; ++i){ if(str[i] != now)... |
#include <bits/stdc++.h> using namespace std; const int mod = 7 + 1e9; const int inf = 1e9 + 5; const long long INF = (long long)1e18 + 5; const int N = 100 + 5; int a[N]; int fr[10000]; int main() { int n; string s; getline(cin, s); sscanf(s.c_str(), %d , &n); for (int i = 0; i < (... |
#include <bits/stdc++.h> using namespace std; bool near(long long A, long long B, long long X, long long Y, long long T) { if ((X - Y * T) < 0) return (0); if ((A - B * T) * Y != (X - Y * T) * B) return ((A - B * T) * Y > (X - Y * T) * B); return (B < Y); } int main() { int t1, t2, x1, x2,... |
#include <bits/stdc++.h> using namespace std; const int N(150010), INF((1 << 30) - 1); int ty, n, k; int yy[4 * N], c1[4 * N], c2[4 * N]; int ord[N], dis[N], ans[N]; struct Point { int x, y; Point() : x(0), y(0) {} Point(int _x, int _y) : x(_x), y(_y) {} void get() { scanf( %d%d , &x, &y); }... |
#include <bits/stdc++.h> using namespace std; int main() { int n, t; double p; cin >> n >> p >> t; vector<vector<double> > dp(2010, vector<double>(2010, 0)); vector<vector<double> > now(2010, vector<double>(2010, 0)); dp[0][0] = 1; for (int i = 0; i < t; i++) { for (int j = 0; j < ... |
#include <bits/stdc++.h> using namespace std; int main() { int n, x; long long amt = 0; cin >> n; vector<pair<int, int> > a; vector<int> p(n); vector<long long> count(6, 0); for (int i(0); i < (n); i++) { cin >> p[i]; } for (int i(0); i < (5); i++) { cin >> x; a... |
#include <bits/stdc++.h> const double eps = 1e-15; const int N = 10000 + 10; struct node { double x, y, z; node() {} node(double _x, double _y, double _z) { x = _x; y = _y; z = _z; } }; node a[N], st; int n; double Time[N], len[N], v1, v2; double sqr(double x) { return ... |
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; if (s.size() == 1) { int a = s[0] - 48; if (a % 4 == 0) cout << 4; else cout << 0; } else { int a = (s[s.size() - 2] - 48) * 10 + (s[s.size() - 1] - 48); if (a % 4 == 0) ... |
#include <bits/stdc++.h> using namespace std; const int Maxn = 400000 + 10; struct Point { long long x, y; Point operator+(const Point &A) { return (Point){x + A.x, y + A.y}; } Point operator-(const Point &A) { return (Point){x - A.x, y - A.y}; } } P[Maxn]; int n, A[Maxn], cnt; long long sum[Max... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.