func_code_string stringlengths 59 71.4k |
|---|
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5, M = 1e9 + 7; int n, a[N]; long long bigmod(long long b, long long p) { long long t = 1; for (; p; b = (b * b) % M, p >>= 1) if (p & 1) t = (t * b) % M; return t; } long long go(int now) { vector<int> div; for (int... |
#include <bits/stdc++.h> const int MX = 1e5 + 23; const long long MOD = 998244353; int read() { char k = getchar(); int x = 0; while (k < 0 || k > 9 ) k = getchar(); while (k >= 0 && k <= 9 ) x = x * 10 + k - 0 , k = getchar(); return x; } struct node { int l, r; int sum, mx... |
#include <bits/stdc++.h> using namespace std; int n; long long x, y; vector<pair<pair<long long, long long>, int> > p; long long dx, dy; bool dot(long long x, long long y) { long long x1 = x - p[0].first.first; long long x2 = x - p[1].first.first; long long y1 = y - p[0].first.second; long l... |
#include <bits/stdc++.h> using namespace std; int n; string a[55]; long long f[(1LL << (21))]; double fac[55]; int main() { cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; int l = a[0].size(); fac[0] = 1; for (int i = 1; i <= l; i++) fac[i] = fac[i - 1] * i; for (int i = 0; i < n;... |
#include <bits/stdc++.h> using namespace std; using ll = long long; const int N = 2 * 1e5 + 10; ll res; ll a[N]; void solve() { ll t, x, y, ex, ey, neast = 0, nnorth = 0, nsouth = 0, nwest = 0; map<char, int> mp; cin >> t >> x >> y >> ex >> ey; ll k = ex - x; ll l = ey - y; string s;... |
#include <bits/stdc++.h> using namespace std; const int MN = 1000 * 100 + 100; int arr[MN], n, s_l, s_r; int main() { cin >> n; for (int i = 0; i < n; i++) { cin >> arr[i]; s_r += arr[i]; } s_r -= arr[0]; s_l = arr[0]; int cnt = 0; for (int i = 1; i < n; i++) { if (... |
#include <bits/stdc++.h> using namespace std; using ll = int64_t; using ii = pair<ll, ll>; int main() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); ll n, m; cin >> n >> m; ll nn = n - 2; ll n1 = nn / 2; ll n2 = nn - n1; ll sm = (n1 + 1) * n1 / 2 + (n2 + ... |
#include <bits/stdc++.h> int main() { int n, i, j, g, k, a[3]; while (~scanf( %d , &n)) { for (i = 0, k = 0; i < n; i++) { for (j = 0, g = 0; j < 3; j++) { scanf( %d , &a[j]); if (a[j] == 1) { g++; } } if (g >= 2) { k++; ... |
#include <bits/stdc++.h> const int MAX_N = 500000; const int MAX_M = 500000; const int MOD = 998244353; int l[MAX_M], r[MAX_M], val[MAX_M]; int smen[1 + MAX_N + 1], left[1 + MAX_N], dp[1 + MAX_N], _sp[1 + 1 + MAX_N], *sp = _sp + 1; int solve(int n, int m, int bit) { int last = 0, p = 0; for (i... |
#include <bits/stdc++.h> using namespace std; int d[3 * 1000001], v1[3 * 1000001], v2[3 * 1000001], a[1000001], i, n, tt, tt2, kq; void BFS1(int s, int k) { queue<int> q; if (v1[s] == 0) { q.push(s); v1[s] = k; } while (q.size() > 0) { int u = q.front(); q.pop(); ... |
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> ans; int x[n], y[n]; for (int i = 0; i < n; i++) { cin >> x[i] >> y[i]; x[i] += 1e8; y[i] += 1e8; } while (1) { for (int i = 0; i < n; i++) { if ((x[i] + y[i]) & 1) ans... |
#include <bits/stdc++.h> int n; int mat[3][6]; int solv[6]; int pt[6]; int main() { memset(solv, 0, sizeof solv); memset(mat, -1, sizeof mat); scanf( %d , &n); int i, j; for (i = 0; i < 2; i++) for (j = 0; j < 5; j++) { scanf( %d , &mat[i][j]); if (mat[i][j] != -1) so... |
#include <bits/stdc++.h> using namespace std; const double PI = 2.0 * acos(0.0); const double eps = 1e-9; template <class T> T Abs(T x) { return x > 0 ? x : -x; } template <class T> string toString(T n) { ostringstream ost; ost << n; ost.flush(); return ost.str(); } template <cla... |
#include <bits/stdc++.h> using namespace std; string s[105]; int main() { int n, m, cnt = 0, t, tt, temp, dis = 0, ans = 0, len; int row = 0, rowup = 2e9, rowdn = -1, col = 0, collft = 2e9, colrt = -1; int rowupcol, rowdncol, collftrow, colrtrow; scanf( %d %d , &n, &m); for (int i = 0; i < n; ... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base ::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long i, j, k, n, m, ans = 0, sum = 0, a[100005] = {0}, mn = 2e9, mx = 0, cnt = 1, index = 0, x, y, z, xptr, yptr, id1, id2, ... |
#include <bits/stdc++.h> using namespace std; template <class T> using vec = vector<T>; template <typename Iter> ostream &_IterOutput_(ostream &o, Iter b, Iter e, const string ss = , const string se = ) { o << ss; for (auto it = b; it != e; it++) o << (it == b ? : , ) ... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0), cout.tie(0); int n; cin >> n; vector<int> a(n + 1), b(n + 1), p(n + 1); for (int i = 1; i <= n; ++i) { cin >> a[i]; p[a[i]] = 0; } for (int i = 1; i <= n; ++i) { cin... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, t; cin >> n >> t; if (n == 1 && t == 10) { cout << -1 ; return 0; } if (t != 10) cout << t; else cout << 1 ; for (int i = 1; i < ... |
#include <bits/stdc++.h> using namespace std; long long h[1000010], dp[1000010][2]; int n; int main() { int i, j; while (scanf( %d , &n) != EOF) { for (i = 1; i <= n; i++) scanf( %lld , &h[i]), h[i]--; for (i = 1; i <= n; i++) { dp[i][0] = (dp[i - 1][0] + dp[i - 1][1] * min(h[i], h[i... |
#include <bits/stdc++.h> using namespace std; char board[8][8]; int main() { for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) scanf( %c , &board[i][j]); } int minA = 100, minB = 100; for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) { if (board[i][j] == W ) {... |
#include <bits/stdc++.h> using namespace std; int main() { long long x, y; cin >> x >> y; long long d = x * x + y * y; if (x == 0 || y == 0) { cout << black << endl; return 0; } for (long long i = 1; i <= 10000; i++) { if (d < i * i) { bool white = (i % 2 == 0 && ... |
#include <bits/stdc++.h> using namespace std; int gcd(int f, int s) { if (s == 0) return f; else return gcd(s, f % s); } int const N = 1002006; long long const M = 998244353; long double const ep = .000000000000000001; vector<int> G[N]; long long pw[N]; int od = 0, ev = 0; int vi... |
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const int mx = 705; long long int dp[mx][mx][3][3]; char s[mx]; int p[mx]; stack<int> st; long long int dfs(int l, int r, int lc, int rc) { if (l >= r) return 1; if (dp[l][r][lc][rc] != -1) return dp[l][r][lc][rc]; int x ... |
#include <bits/stdc++.h> using namespace std; const int maxn = 200005; int a[maxn], cnt[maxn], n, q; long long ans = 0; map<pair<long long, long long>, int> mp; int main() { ios::sync_with_stdio(false); cin.tie(0), cout.tie(0); cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; ... |
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; long long n, i, j, pw = 1, ans1, ans2, diff = 1; char a[100000], b[100000]; int main() { ios_base::sync_with_stdio(0); cin.tie(); cin >> n; for (i = 0; i < n; i++) cin >> a[i]; for (i = 0; i < n; i++) cin >> b[... |
#include <bits/stdc++.h> using namespace std; const long double pi = acos(-1.0); vector<long long> v1, v2; long long ans = 0, x, y; long long fact[1008], dp[1008][1008]; void pow1(long long a[], long long i, long long end, long long sum) { if (i == end) { v1.push_back(sum); return; } ... |
#include <bits/stdc++.h> using namespace std; const int maxn = 1000 + 10; int n, m; int a[maxn]; int res0, res1; void output(int l, int r) { printf( ? ); for (int i = 1; i < l; i++) printf( 0 ); for (int i = l; i <= r; i++) printf( 1 ); for (int i = r + 1; i <= n; i++) printf( 0 ); prin... |
#include <bits/stdc++.h> using namespace std; const int mmax = 1e6 + 10; const int eps = 1e-9; struct node { string name; } s[105]; long long cmp(node a, node b) { if (a.name == b.name) return a.name < b.name; return a.name < b.name; } int main() { long long n; while (cin >> n) { ... |
#include <bits/stdc++.h> using namespace std; int n, m, k, kk; vector<int> g[10], e[10]; int cnt = 0; bool used[10] = {}, vis[10] = {}; int usedCnt, visCnt; long long cur; int st; int pc[1024]; void go(int v) { vis[v] = true, ++visCnt; vector<int> &f = e[v]; int sz = 0; for (int x : ... |
#include <bits/stdc++.h> using namespace std; long long s; int main() { int n, a, b, c, d; cin >> n >> a >> b >> c >> d; for (int x = 1; x <= n; x++) { int y = x + b - c; int z = x + a - d; int w = y + a - d; if (y <= n && z <= n && w <= n && y > 0 && z > 0 && w > 0) s++; }... |
#include <bits/stdc++.h> using namespace std; int main() { int n = 0, m = 0; string s; cin >> s; for (int i = 0; i < s.length(); i++) if (s[i] == x ) n++; else m++; if (n > m) for (int i = 1; i <= n - m; i++) cout << x ; else if (n < m) for (int i = ... |
#include <bits/stdc++.h> const int N = 1e5 + 10; int ri() { char c = getchar(); int x = 0, f = 1; for (; c < 0 || c > 9 ; c = getchar()) if (c == - ) f = -1; for (; c >= 0 && c <= 9 ; c = getchar()) x = (x << 1) + (x << 3) - 0 + c; return x * f; } struct Pt { long long x, ... |
#include <bits/stdc++.h> using namespace std; vector<int> vc[200007]; int main() { int n; scanf( %d , &n); int res = 0; for (auto i = (1); i <= (n); ++i) { int m; scanf( %d , &m); vc[i].resize(m); for (auto j = (0); j <= (m - 1); ++j) scanf( %d , &vc[i][j]); sort(vc[i... |
#include <bits/stdc++.h> using namespace std; long long int a, i, j, ct = 0; int main() { cin >> a; for (i = 0; i < a; i++) { ct++; if (ct == 1 || ct == 2) { cout << a ; } if (ct == 3 || ct == 4) { cout << b ; if (ct == 4) { ct = 0; } ... |
#include <bits/stdc++.h> #pragma comment(linker, /STACK:1024000000,1024000000 ) using namespace std; int n, k; char str[100005]; long long jie[100005]; long long ni[100005]; long long sum[100005]; long long extend_gcd(long long a, long long b, long long &x, long long &y) { if (b == 0) { x = 1... |
#include <bits/stdc++.h> using namespace std; using ll = long long; vector<string> s(100, string(100, . )); int n, k; int solve() { ios::sync_with_stdio(false), cin.tie(0); cin >> n >> k; if (n - 2 == k) { for (int i = 1; i < n - 1; i++) { s[1][i] = # ; } return 1; ... |
#include <bits/stdc++.h> using namespace std; void hashLine(int n) { for (int i = 0; i < n; i++) cout << # ; cout << endl; } void right(int n) { cout << . ; for (int i = 1; i < n - 1; i++) cout << . ; cout << # n ; } void left(int n) { cout << # ; for (int i = 1; i < n - 1; ... |
#include <bits/stdc++.h> using namespace std; bool a[1000009]; int main() { int n, x; cin >> n; for (int i = 0; i < n; i++) { cin >> x; if (x == 1) { cout << -1 ; return 0; } a[x] = 1; } for (int i = 1; i <= n; i++) { if (a[i] == 0) { cout... |
#include <bits/stdc++.h> using namespace std; const int maxn = 222222; unsigned long long p4423[maxn]; struct State { unsigned long long hashValue; int count; void assign(int value) { if (value == 0) { hashValue = 0; count = 0; } else { hashValue = value; ... |
#include <bits/stdc++.h> using namespace std; signed main() { long long int t; cin >> t; while (t--) { long long int n; cin >> n; long long int a[n]; for (long long int i = 0; i < n; i++) cin >> a[i]; long long int x = a[0]; for (long long int i = n - 1; i > 0; i--) {... |
#include <bits/stdc++.h> using namespace std; int n, m; vector<pair<long long, int> > vertices; bool cmp(pair<long long, int> x, pair<long long, int> y) { return x.first < y.first; } bool cmp2(pair<long long, pair<int, int> > x, pair<long long, pair<int, int> > y) { return x.first < y.fi... |
#include <bits/stdc++.h> using namespace std; vector<string> com; vector<int> num; vector<string> adj[1000010]; struct node { string s; int i; node() {} node(string x, int idx) { s = x; i = idx; } }; int toNum(string s) { int i, j, k; int l = s.length(); k = 1; ... |
#include <bits/stdc++.h> using namespace std; int main() { int n, m, k; cin >> n; cin >> m; cin >> k; bool done = false; int num = 0; int lanes = 0; int desks = 0; int d = 0; while (num < k) { desks = 0; done = false; num += 2 * m; lanes++; while... |
#include <bits/stdc++.h> using namespace std; const long long INF = 0x3f3f3f3f; const long long MAXN = 3e5 + 5; long long n, MOD, k, ans; map<long long, long long> mp; signed main() { scanf( %lld%lld%lld , &n, &MOD, &k); for (long long i = 1; i <= n; i++) { long long x; scanf( %lld , &x)... |
#include <bits/stdc++.h> using namespace std; long long binpow(long long a, long long b) { a = a % 1000000007; long long res = 1; while (b > 0) { if (b & 1) res *= a % 1000000007; a = a * a % 1000000007; b = b >> 1; } return res; } void speedup() { ios::sync_with_stdio(... |
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { long long int a, b, c, r, x, y, z, i, j, k, count = 0, result; cin >> a >> b >> c >> r; x = c - r; y = c + r; r = (a >= b) ? a : b; z = (a <= b) ? a : b; a = z; b = r... |
#include <bits/stdc++.h> using namespace std; const int INF = 1e9 + 7; using namespace std; const string tp[4] = { aaaa , aabb , abab , abba }; int n, k; int m; string w[10000]; int prime(int x) { if (x == 1) return 0; for (int i = 2; i * i <= x; i++) if (x % i == 0) return 0; retur... |
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e6 + 5; int n, k, l, sm[MAXN]; char s[MAXN]; pair<long long, long long> dp[MAXN]; long long solve(char a) { for (int i = 1; i <= n; i++) sm[i] = sm[i - 1] + (s[i] == a); int lo = 0, hi = l; long long ans = 0; while (lo <= hi) { ... |
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 9; int main() { long long n, m; cin >> n >> m; vector<int> row(n), col(n); int r = 0, c = 0; int x, y; long long ans = n * n; for (int i = 0; i < m; i++) { scanf( %d %d , &x, &y); long long v = 0; ... |
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; long long tecpoint = 0; vector<long long> mas(n); for (int i = 0; i < n; i++) { long long a; cin >> mas[i]; } vector<long long> questions(m); vector<bool> visited(n); for (int i = 0; i... |
#include <bits/stdc++.h> using namespace std; int main(int argc, char *argv[]) { int n, m, i; scanf( %d , &n); m = 1; for (i = 1; i < n; i++) { m = (m + i); if (m > n) m -= n; printf( %d , m); if (i < n) printf( ); else printf( n ); } return E... |
#include <bits/stdc++.h> using namespace std; long long x, y, c; int n; const int maxn = 300009; char str[maxn]; long long cnt = 0; int main() { cin >> n >> x >> y; cin >> str; int now = 0; for (int i = 0; i < n; ++i) { if (str[i] == 1 ) { if (now != 0) cnt++; now = ... |
#include <bits/stdc++.h> int main() { int n, bags[100000], i; scanf( %d , &n); for (i = 0; i < (n * n); i++) bags[i] = (i + 1); for (i = 0; i < ((n * n) / 2); i += 2) { printf( %d , bags[i]); printf( %d , bags[(n * n) - i - 1]); } printf( n ); for (i = 1; i <= (((n * n) / 2)... |
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 10; int n; vector<int> g[MAXN]; int d[MAXN]; int bio[MAXN]; void dfs(int x, int dep) { d[x] = dep; bio[x] = 1; for (int i : g[x]) if (!bio[i]) dfs(i, dep + 1); } int main() { scanf( %d , &n); int a, b; f... |
#include <bits/stdc++.h> using namespace std; inline long long read() { char c = getchar(); long long 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; } const long long... |
#include <bits/stdc++.h> using namespace std; const int maxn = 200009; const int MOD = 1e9 + 7; int main() { ios_base::sync_with_stdio(false), cout.tie(0), cin.tie(0); int n, k, tot; cin >> n >> k; tot = n; vector<int> sta, vis(n + 2); vis[n + 1] = 1; int cur = 1; vector<int> ans... |
#include <bits/stdc++.h> using namespace std; long long arr[200005], lazy[4 * 200005], seg[4 * 200005]; void build(int node, int start, int end) { int mid = (start + end) / 2; if (start == end) { lazy[node] = 0; seg[node] = arr[start]; return; } build(2 * node, start, mid); b... |
#include <bits/stdc++.h> using namespace std; int sa[100005], s1[100005]; char s[100005]; int save[6]; int main() { int n; while (scanf( %d , &n) != EOF) { for (int a = 1; a <= n; a++) scanf( %d , &sa[a]); scanf( %s , s + 1); int l = -1000000000, r = 1000000000; for (int a = 1;... |
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); int a, b, c, x, y, z; cin >> a >> b >> c >> x >> y >> z; int cnt = 0; if (a > x) cnt += (a - x) / 2; if (b > y) cnt += (b - y) / 2; if (c > z) cnt += (c - z) / 2; if (a < x) if (x - a <= cnt... |
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 5; int n, to[N << 1], nxt[N << 1], head[N], cnt; int len[N], son[N], tmp[N], *f[N], *id = tmp, ans[N]; void link(int u, int v) { to[++cnt] = v; nxt[cnt] = head[u]; head[u] = cnt; to[++cnt] = u; nxt[cnt] = head[v]; head[v... |
#include <bits/stdc++.h> using namespace std; long long int power(long long int n, long long int k) { long long int ans = 1; long long int mod = 1000000007; while (k) { if (k & 1) ans = (ans * n) % mod, k--; n = (n * n) % mod, k >>= 2; } return ans; } long long int mod(long long ... |
#include <bits/stdc++.h> using namespace std; int main() { int n, ar[110]; while (cin >> n) { for (int i = 0; i < n; i++) { cin >> ar[i]; } if ((n % 2 == 1) && (ar[0] % 2 == 1) && (ar[n - 1] % 2 == 1)) cout << Yes << endl; else cout << No << endl; } ... |
#include <bits/stdc++.h> const double inf = 1e19; const double eps = 1e-9; int ch[600050][2]; double K[600050], B[600050], L[600050], R[600050]; double TK[600050], TB[600050], TX[600050]; int fa[600050]; double x[300050], y[300050]; double q, a, b; int n, tot, root; inline int dir(int x) { return x ... |
#include <bits/stdc++.h> using namespace std; static const int N = 500005; long long l[N]; long long d[N]; char s[N]; int main() { int a, b, t, n; cin >> n >> a >> b >> t; scanf( %s , &s); l[0] = 1 + b * (s[0] == w ); for (int i = 1; i < n; i++) l[i] = 1 + l[i - 1] + a + b * (s[i] == w... |
#include <bits/stdc++.h> using namespace std; const int nod = 1e9 + 7; const int modulo = (119 << 23) + 1; const int maxn = 3e5 + 1; int n, m; vector<int> a(maxn); int test() { std::ios::sync_with_stdio(false); std::cin.tie(0); cin >> n >> m; for (int i = 0; i < n; i++) cin >> a[i]; in... |
#include <bits/stdc++.h> using namespace std; char a[200000], b[200000]; int kmp[200000]; int n, m, i, j, first, curr, val[200000], l; int dyn[200000]; int sum[200000]; int MOD = 1000000007; int main(void) { cin >> b >> a; n = strlen(a); m = strlen(b); kmp[0] = 1; if (n == 1) { ... |
#include <bits/stdc++.h> using namespace std; const long long INF = 1e9, MOD = INF + 7; const int N = 1e5 + 5; int n, a[N], nxt[N], lucky[N]; struct Node { int mn = INF, cnt = 0, idx = -1, lazy = 0; } seg[4 * N]; int doLuck(int i, int x) { if (x > 1e4) return i; if (x) lucky[i] = x, i++; i... |
#include <bits/stdc++.h> using namespace std; const long long MOD = 998244353; long long qpow(long long x, long long y) { long long ret = 1; while (y) { if (y & 1) ret = ret * x % MOD; y >>= 1; x = x * x % MOD; } return ret % MOD; } int main() { long long n, sum = 0, C = ... |
#include <bits/stdc++.h> using namespace std; int mp[200005]; int a[200005]; int n; int main() { int y, T, n, m, i, t, j, k, x; scanf( %d , &n); for (i = 0; i < n; i++) { scanf( %d , &x); mp[x] = i + 1; } for (i = 0; i < n; i++) { scanf( %d , &x); a[i] = mp[x]; ... |
#include <bits/stdc++.h> using namespace std; void equalse(int arr[], int n) { int m = 0, c = 0; for (int i = 0; i < n; i += 2) { if (arr[i] > arr[i + 1]) m++; if (arr[i] < arr[i + 1]) c++; } if (c > m) cout << Chris ; if (m > c) cout << Mishka ; if (m == c) cout << Friendship... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n, i, j; cin >> n; int x[n], y[n]; for (i = 0; i < n; ++i) { cin >> x[i] >> y[i]; } long long int c1 = 0, c2 = 0; std::map<pair<double, double... |
#include <bits/stdc++.h> using namespace std; map<long long, long long> f; long long n, mm, ret, cur; long long a[200005], sum[200005]; long long calc(long long m) { f.clear(); ret = cur = 0; for (long long i = 0; i < n; i++) { sum[i + 1] = sum[i] + (a[i] < m ? -1 : 1); f[sum[i + 1]]++... |
#include <bits/stdc++.h> using namespace std; int main() { int h, m; scanf( %d:%d , &h, &m); int tmp = 0; int htmp = h; tmp = h % 10; tmp = tmp * 10; tmp = tmp + h / 10; if (tmp >= m && tmp < 60) printf( %d n , tmp - m); else { h++; while (true) { tmp = ... |
#include <bits/stdc++.h> using namespace std; int n, a[200010], pos[200010][3], tag[200010][3]; long long ans, num1, num2, cnt1, cnt2; int main() { int i; scanf( %d , &n); for (i = 1; i <= n * 2; i++) { scanf( %d , &a[i]); pos[a[i]][0]++; pos[a[i]][pos[a[i]][0]] = i; } pos[... |
#include <bits/stdc++.h> using namespace std; const long long MAX = 3e5 + 10; const long long INF = 1e18; const long long M = 1e6 + 10; int main() { int n, i, j, k, l, p, q; string s; cin >> n >> s; set<char> a; char st[3] = { R , G , B }; for (i = 0; i < n; i++) a.insert(s[i]); ... |
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; void _IOS() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin.sync_with_stdio(0); } long long a[500009], b[500009]; long long n, m, k; map<long long, bool> pg; long long dp[100009][3]; int main() { _... |
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 100; int len, S, T; bool o[N * 40][15]; char str[N]; long long n, Ans; struct matrix { long long f[4][4]; matrix() { memset(f, 63, sizeof(f)); } } Trans, bin[70], X; void cmin(long long& x, long long y) { x = x < y ? x : y; } ... |
#include <bits/stdc++.h> using namespace std; int main() { long long q, t, v, u, w; map<long long, long long> cost; cin >> q; while (q--) { cin >> t; if (t == 1) { cin >> v >> u >> w; while (v != u) { while (u > v) { cost[u] += w; u >>= 1... |
#include <bits/stdc++.h> using namespace std; const int INF = 1e9; const long long LINF = 1e17; const double DINF = numeric_limits<double>::max(); const int ITER = 300; const int MOD = 1e9 + 7; const double EPS = 1e-10; const int MAXN = 1e5 + 10; int n, m; vector<pair<int, int> > v; void solve() {... |
#include <bits/stdc++.h> using namespace std; const int INF = INT_MAX; int n, root = 0; vector<vector<int>> adj; vector<int> d; void dfs() { d.assign(n, INF); d[root] = 0; queue<int> q; q.push(root); while (!q.empty()) { int cur = q.front(); q.pop(); for (auto nxt : adj... |
#include <bits/stdc++.h> using namespace std; int main() { int n, h; while (~scanf( %d%d , &n, &h)) { for (int i = 1; i < n; i++) { printf( %f , h * (sqrt((double)i / n))); } printf( n ); } return 0; } |
#include <bits/stdc++.h> using namespace std; int n, m, dx[]{-1, 0, 0, 1}, dy[]{0, -1, 1, 0}; vector<string> tab; vector<vector<int>> dist; priority_queue<pair<int, pair<int, int>>> PQ; int dijkstra(int x, int y) { dist.assign(n, vector<int>(m, INT_MAX / 2)); dist[x][y] = 1; PQ.push({0, {x, y}})... |
#include <bits/stdc++.h> using namespace std; int dp1[101010] = {0}, dp2[101010] = {0}; int main() { cin.sync_with_stdio(0); cin.tie(0); int n; cin >> n; int h[101010]; for (int i = 0; i < n; i++) cin >> h[i]; dp1[0] = 1; for (int i = 1; i < n - 1; i++) { dp1[i] = dp1[i - 1] ... |
#include <bits/stdc++.h> using namespace std; const int N = 111, dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0}; bool a[N][N][4]; int w, h, n, c[N][N], now; vector<int> ans; int dfs(int x, int y) { c[x][y] = now; int res = 1; for (int d = 0; d < 4; ++d) if (a[x][y][d]) { int nx = x +... |
#include <bits/stdc++.h> using namespace std; double ans = 1; int main() { int n, m, k; scanf( %d%d%d , &n, &m, &k); if (k >= m) printf( 1 n ); else if (n + k < m) printf( 0 n ); else { for (int i = 1; i <= k + 1; i++) ans = ans * (m - i + 1) / (n + i); ans = 1.0 - ans;... |
#include <bits/stdc++.h> using namespace std; map<long long, long long> M[400004]; vector<long long> Z[400004]; map<long long, long long> MA; map<long long, long long> AM; long long MAer; bool cmp(long long& a, long long& b) { return a > b; } long long xa[200002], xb[200002]; signed main() { long ... |
#include <bits/stdc++.h> using namespace std; int gcd(int a, int b) { return !b ? a : gcd(b, a % b); } int A[100], B[40200], n, N, M[40200]; long long r1; int lis() { int L = 0, lo, hi, mid, i; for (i = 0; i < N; i++) { lo = 1; hi = L; while (lo <= hi) { mid = (lo + hi) / 2 +... |
#include <bits/stdc++.h> using namespace std; inline void normal(long long &a) { a = (a + 998244353) % 998244353; } inline long long modMul(long long a, long long b) { a %= 998244353, b %= 998244353; normal(a), normal(b); return (a * b) % 998244353; } inline long long modAdd(long long a, long long... |
#include <bits/stdc++.h> using namespace std; int main() { iostream::sync_with_stdio(0); long long n; cin >> n; vector<long long> q{1, 1}; while (q.back() < 1e18) q.push_back(q.back() + q[q.size() - 2]); cout << upper_bound(q.begin(), q.end(), n) - q.begin() - 2; return 0; } |
#include <bits/stdc++.h> const int maxn = 1e5 + 10; using namespace std; long long gcd(long long p, long long q) { return q == 0 ? p : gcd(q, p % q); } long long qpow(long long p, long long q) { long long f = 1; while (q) { if (q & 1) f = f * p; p = p * p; q >>= 1; } return f; ... |
#include <bits/stdc++.h> using namespace std; long long dp[2000005]{}; long long dp2[2000005]{}; int main() { long long n, t; cin >> t; while (t--) { string ss; cin >> n; cin >> ss; memset(dp, 0, n * 8 + 40); memset(dp2, 0, n *... |
#include <bits/stdc++.h> using namespace std; void qSort(int *A, int low, int high, int *ii) { int i = low; int j = high; int x = A[(low + high) / 2]; do { while (A[i] < x) ++i; while (A[j] > x) --j; if (i <= j) { int temp = A[i]; int buf = ii[i]; ii[i] = ii... |
#include <bits/stdc++.h> using namespace std; int n; int n1, n2, n3, n4, n5, n6, n7; int a, b, c; void doA(int i) { if (n1 >= i) n1 -= i; else n1 = 0; } void doB(int i) { if (n2 >= i) n2 -= i; else { doA(i - n2); n2 = 0; } } void doC(int i) { if (n... |
#include <bits/stdc++.h> using namespace std; inline int read() { int x = 0, f = 1; char ch = getchar(); while (ch < 0 || ch > 9 ) { if (ch == - ) f = -1; ch = getchar(); } while (ch >= 0 && ch <= 9 ) { x = x * 10 + ch - 0 ; ch = getchar(); } return x * f;... |
#include <bits/stdc++.h> using namespace std; const int maxn = 300010; const int INF = 2000000010; int n, m, k; int mi[maxn], ma[maxn], a[maxn], sum[maxn], v[maxn], la[maxn]; vector<pair<int, int>> G; void add(int x, int cnt) { for (int i = x; i <= max(n, m); i += (i & -i)) { sum[i] += cnt; ... |
#include <bits/stdc++.h> using namespace std; long long int get(long long int s, long long int w, long long int cs, long long int cw, long long int p) { if (s > w) return get(w, s, cw, cs, p); if (s * cs >= p) return p / s; return cs + min(cw, (p - s * cs) / w); }; void solve() {... |
#include <bits/stdc++.h> using namespace std; long long a[8], pro[1 << 8]; int bit_cnt[1 << 8]; vector<long long> pp; bitset<1000000> p; map<long long, int> H; int N, an; int qq(long long x) { if (H.count(x)) return H[x]; long long X = x; int res = 0; for (int i = 0; i < ((int)(pp).size(... |
#include <bits/stdc++.h> using namespace std; int x, y, a, b, num_of_results; pair<int, int> game, results[10101]; int main() { scanf( %d %d %d %d , &x, &y, &a, &b); num_of_results = 0; if (b >= x) printf( 0 n ); else { for (int i = a; i <= x; i++) { for (int j = b; j <= y; j... |
#include <bits/stdc++.h> using namespace std; const int N = 16 + 5; string a[N], x, y; int n, m, M = -1; map<string, map<string, int> > mm; bool vis[N]; void dfs(int deep, int mod) { if (deep > n + 1) return; if (deep == n + 1) { int tot = 0, f = 1; for (int i = 1; i <= n; ++i) tot += ... |
#include <bits/stdc++.h> using namespace std; const int MAXN = 1100; struct VIS { int c, p; int id; bool operator<(const VIS& t) const { if (p == t.p) return c < t.c; return p > t.p; } } A[MAXN]; struct TAB { int c; int id; bool operator<(const int t) const { return c <... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.