func_code_string stringlengths 59 71.4k |
|---|
#include <bits/stdc++.h> using namespace std; const int M = 100000 + 10; int leaf[M]; vector<int> adj[M]; int childnum[M]; void dfs(int cur, int par) { for (int i = 0; i < adj[cur].size(); i++) { int nxt = adj[cur][i]; if (nxt != par) { childnum[cur]++; dfs(nxt, cur); }... |
#include <bits/stdc++.h> using namespace std; int main() { int m, n; cin >> m >> n; cout << ((m % 2) ? m * (n / 2) + (n % 2) * (m / 2) : n * (m / 2) + (m % 2) * (n / 2)); return 0; } |
#include <bits/stdc++.h> using namespace std; int n; long long a[300000]; int main() { while (cin >> n) { for (int i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); long long ans = 0; for (int i = 0; i < n; i++) { int x = (i == n - 1 ? -1 : 0); ans += (x + i + 2) * a[i]... |
#include <bits/stdc++.h> using namespace std; bool check(const string &str) { vector<string> vec{ ABSINTH , BEER , BRANDY , CHAMPAGNE , GIN , RUM , SAKE , TEQUILA , VODKA , WHISKEY , WINE }; for (int i = 0; i < (int)vec.size(); ++i) { if (str == vec[i]) return... |
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n, m; cin >> n >> m; vector<vector<int> > a(n), b(m); for (int i = 0; i < n; i++) { a[i].resize(m); for (int j = 0; j < m; j++) cin >> a[i][j]; } for (int j =... |
#include <bits/stdc++.h> using namespace std; int yy[100005], id; int n, m; int st[100005 * 4], lz[100005 * 4]; int a[100005]; int l[305], r[305]; inline void pu(int rt) { st[rt] = max(st[2 * rt + 1], st[2 * rt + 2]); } void pd(int rt, int l, int r, int m) { if (lz[rt]) { int t = lz[rt]; ... |
#include <bits/stdc++.h> using namespace std; const int maxn = 10; const int INF = 2147000000; int n, k; int a[maxn][maxn]; int b[maxn], vis[maxn]; int ans = INF; int make(int num) { int res = 0; for (int i = 1; i <= k; i++) { int c = b[i]; res = res * 10 + a[num][c]; } retur... |
#include <bits/stdc++.h> using namespace std; int m, n, arr[2000][2000], temp[2000][2000]; char ctrl(int i) { for (int j = 1; j <= n; j++) if (arr[i][j] and arr[i][j] != temp[i][j]) return 0; return 1; } char solve(int a, int b, int c, int d, int ttt = 0) { if (ttt) ttt = 3; for (int i =... |
#include <bits/stdc++.h> using namespace std; struct Data { int r, c, v; bool operator<(const Data &r) const { return v < r.v; } }; vector<vector<int> > mat, ans; Data sorteds[1001000]; int mR[1001000], mC[1001000]; map<pair<int, int>, vector<int> > mr, mc; void recursiveFix(int rr, int cc) { ... |
#include <bits/stdc++.h> using namespace std; struct EDGE { EDGE(int _v, int _cap, int _edgeidx) : v(_v), cap(_cap), edgeidx(_edgeidx) {} int v; int cap; int edgeidx; }; int DEBUG = 0; const int MAXN = 200001; vector<EDGE> edge[MAXN]; int in[MAXN], total[MAXN], dir[MAXN]; int mark[MAXN];... |
#include <bits/stdc++.h> using namespace std; const double eps = 1.0e-8; const int maxn = 1e6 + 10; const int maxm = 300; const int turn[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}}; long long mod = 1e9 + 7; vector<int> tree[10005]; int ans[10005]; int anser = 0; void dfs(int x, int pre, int c) { ... |
#include <bits/stdc++.h> clock_t t = clock(); namespace my_std { using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); template <typename T> inline T rnd(T l, T r) { return uniform_int_distribution<T>(l, r)(rng); } template <typename T> inline bool chkmax(T &x, ... |
#include <bits/stdc++.h> using namespace std; const long long int hell = 1000000007; void solve() { long long int n, m; cin >> n >> m; vector<long long int> used(3 * n + 5, 0); vector<long long int> mx; long long int ctr = 1; for (long long int i = 1; i <= m; i++) { long long int u, ... |
#include <bits/stdc++.h> using namespace std; int n; vector<long long> S; vector<int> N, L, R; vector<bool> E; pair<long long, pair<int, int>> merge(int l, int r, int mid, pair<long long, pair<int, int>> L, pair<long long, pair<... |
#include <bits/stdc++.h> using namespace std; const int N = 505; int n, in[N], out[N], w[N], s[N], v[N]; vector<int> st[N << 1]; int f1[N][N << 1], f2[N][N << 1]; int dfs(int x, int S) { if (S < 0) return 0; if (~f1[x][S]) return f1[x][S]; f2[x][out[x] + 1] = 0; for (int i = out[x]; i >= in[... |
#include <bits/stdc++.h> using namespace std; void fr(int &a, bool f = 0, char ch = getchar()) { for (a = 0; ch < 0 || ch > 9 ; ch = getchar()) ch == - ? f = 1 : 0; for (; ch >= 0 && ch <= 9 ; ch = getchar()) a = a * 10 + ch - 0 ; a = f ? -a : a; } int fr() { int a; return fr(a), a;... |
#include <bits/stdc++.h> using namespace std; int ans[2020], cnt = 0, k; int main() { cin >> k; k++; ans[++cnt] = -1; while (k >= 1e6 - 1) { k -= 1e6 - 1; ans[++cnt] = 1e6 - 1 + 1; } ans[++cnt] = k + 1; cout << cnt << endl; for (int i = 1; i <= cnt; i++) cout << ans[i] ... |
#include <bits/stdc++.h> using namespace std; int main() { std::ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long f = 0, j, q = 1, i, n; while (q--) { long long y, k = 1, x, M, s; cin >> n >> M >> s >> f; unordered_map<int, pair<int, int> > m; for (i = ... |
#include <bits/stdc++.h> using namespace std; int main() { string ch1, ch2, ch3; getline(cin, ch1); getline(cin, ch2); for (int s = 0; s < ch1.size(); s++) { if (ch1[s] != ch2[s]) { ch3 += 1 ; } else { ch3 += 0 ; } } cout << ch3 << n ; return 0; } ... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); long long n, k; cin >> n >> k; long long l = 0; long long r = n; while (l != r) { long long mid = (l + r) / 2; if (mid * (mid + 1) / 2 - (n - ... |
#include <bits/stdc++.h> using namespace std; struct Solve { bool mark[(int)(3e5 + 10)]; vector<pair<int, int>> ed[(int)(3e5 + 10)]; vector<int> mtch; int n, m, T; void go() { T = 0; input(); find_mx_match(); if (T >= 2 * n) prnt_match(); else prnt_i... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ; long long t; cin >> t; while (t--) { long long n, x, m, i, flag = 0, a, b, l, r, sum = 2, ones = 0, zero = 0, output = 0, j; vector<pair<long ... |
#include <bits/stdc++.h> using namespace std; int main() { long long int t; cin >> t; while (t--) { long long int c, m, x; cin >> c >> m >> x; long long int y = c + m + x; y = y / 3; long long int ans = 0; if (c >= 1 && m >= 1) { long long int v = min(c, m); ... |
#include <bits/stdc++.h> using namespace std; struct Edge { int t, next; Edge() {} Edge(int a, int b) : t(a), next(b) {} }; Edge e[200005]; int head[100005]; vector<int> g[100005]; queue<int> bel[100005]; int d[100005], scc_cnt; namespace Graph { int dfn[100005], low[100005], dfs_cnt; ... |
#include <bits/stdc++.h> using namespace std; int d[66000], s[66000]; int que[66000]; bool f[66000]; int n, m; vector<pair<int, int> > res; int biton(int x, int k) { return (x | (1 << k)); } int Minus(int x, int y) { int z = 0; for (int i = 0; i < 17; i++) { int u = ((x >> i) & 1); i... |
#include <bits/stdc++.h> using namespace std; long long a[200005]; int main() { int t; cin >> t; while (t--) { memset(a, 0, sizeof(a)); int n; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; } sort(a, a + n); if (a[0] != a[n - 1]) { printf... |
#include <bits/stdc++.h> using namespace std; void _fill_int(int* p, int val, int rep) { int i; for (i = 0; i < rep; i++) p[i] = val; } signed long long GETi() { signed long long i; scanf( %lld , &i); return i; } int N, M; int A[10000], B[10000]; int T[4][10000]; void solve() { ... |
#include <bits/stdc++.h> using namespace std; int n, t; int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> t; while (t--) { cin >> n; if (n == 1) { cout << -1 << endl; continue; } string ans = 2 ; for (int i = 1; i < n; i++) ans += 3 ; ... |
#include <bits/stdc++.h> using namespace std; int MinDist(int n, int k, const string& s) { int first_cow_pos = 0; while (first_cow_pos < n && s[first_cow_pos] == 1 ) { ++first_cow_pos; } int last_cow_pos = first_cow_pos; int rooms = 1; while (rooms < k + 1) { ++last_cow_pos; ... |
#include <bits/stdc++.h> using namespace std; const int inf = 1e9; const long long INF = 1e18; long long n, sum, ans; long long a[200010]; struct BIT { long long tree[600010]; BIT() { memset(tree, 0, sizeof(tree)); } void update(long long i, long long x) { while (i <= 600000) { tre... |
#include <bits/stdc++.h> using namespace std; struct city_t : array<bitset<99>, 4> { int n, k, m, p; city_t() { cin >> n >> k, m = n / 2, p = n - 2; } void hotel(int i, int j) { if (!(*this)[i][j] && k > 0) (*this)[i][j] = true, k--; } void solve() { if (k % 2) hotel(1, m); for... |
#include <bits/stdc++.h> using namespace std; template <class T> inline void smin(T &a, T b) { if (a > b) a = b; } template <class T> inline void smax(T &a, T b) { if (a < b) a = b; } int V, E, src, tar; int head[60000], work[60000], dis[60000]; int to[2000000], cap[2000000], nxt[2000000]; ... |
#include <bits/stdc++.h> using namespace std; long long n, m, k, x, y, z; int main() { cin >> n >> k >> m; if (m <= k) cout << m << endl; else if (m <= n) cout << k << endl; else { long long tmp = n + k; cout << tmp - m << endl; } return 0; } |
#include <bits/stdc++.h> using namespace std; vector<int> E[3010]; int mark[3010]; int c, f; bool find(int i, int p) { if (mark[i] == 1) { c = i; f = 1; return true; } mark[i] = 1; for (vector<int>::iterator to = E[i].begin(); to < E[i].end(); to++) { if (*to != p && fi... |
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) #pragma GCC optimize( unroll-loops ) int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); int n, k; std::cin >> n >> k; int64_t s1 = 0; int s2 = 0; for (int i = 0; i < k; ++i) { int a, b; std::cin >> a ... |
#include <bits/stdc++.h> using namespace std; int main() { vector<int> a(26), a2(26), a3(26); string s1, s2, s3; char ss1[100001], ss2[100001], ss3[100001]; scanf( %s%s%s , ss1, ss2, ss3); s1 = ss1; s2 = ss2; s3 = ss3; for (int i = 0; i < s1.size(); i++) a[s1[i] - a ]++; for (in... |
#include <bits/stdc++.h> using namespace std; const int N = 501; int dp[N][N][2]; char a[N][N]; const int MOD = 1e9 + 7; void add(int &a, int b) { a += b; if (a >= MOD) a -= MOD; if (a < 0) a += MOD; } int mul(int a, int b) { return (long long)a * b % MOD; } int power(int a, int b) { i... |
#include <bits/stdc++.h> using namespace std; int main() { int t, n, x, y, good, bad; scanf( %d , &t); while (t--) { scanf( %d%d%d , &n, &x, &y); bad = min(n, x + y - 1); if (x + y <= n) good = 1; else good = min(n, x + y - n + 1); printf( %d %d n , good, ba... |
#include <bits/stdc++.h> using namespace std; long long int gcd(long long int a, long long int b) { return b ? gcd(b, a % b) : a; } long long int lcm(long long int a, long long int b) { return a * b / gcd(a, b); } int n, m, cnt[11][11], a[22], b[22], tr[11], mx; void bktk(int i) { if (i == n +... |
#include <bits/stdc++.h> using namespace std; int main() { long long q; cin >> q; if (q == 1) { cout << 1 n0 n ; return 0; } long long a = -1, b = -1; for (long long d = 2; d * d <= q; d++) { if (q % d) continue; a = d; b = q / d; break; } if (a =... |
#include <bits/stdc++.h> #pragma GCC optimize( O3 ) using namespace std; const int MAX = 5e5 + 10; const long long MAX2 = 11; const long long MOD = 1000000007; const long long MOD2 = 1000000006; const long long INF = 2e18; const int dr[] = {1, 0, -1, 0, 1, 1, -1, -1, 0}; const int dc[] = {0, 1, 0, -1,... |
#include <bits/stdc++.h> using namespace std; void main0(); int main() { ios::sync_with_stdio(false); cin.tie(0); main0(); return 0; } const int dx[8] = {0, 1, -1, 0, 1, 1, -1, -1}; const int dy[8] = {1, 0, 0, -1, 1, -1, -1, 1}; const int N = 2e3 + 1; const int INF = 0x3f3f3f3f; const ... |
#include <bits/stdc++.h> using namespace std; const int N = int(1e5 + 5); vector<int> g[N]; int cnt[N]; void dfs(int v, int depth = 0) { cnt[depth]++; for (int to : g[v]) { dfs(to, depth + 1); } } int main() { ios::sync_with_stdio(0); int n; cin >> n; for (int i = 2; i <=... |
#include <bits/stdc++.h> using namespace std; int ans[110000], add[110000]; int n, m, a, cnt, me; char temp[3]; int main() { while (~scanf( %d%d , &n, &m)) { for (int i = 1; i <= n; i++) ans[i] = 1, add[i] = 0; ; cnt = 0; me = 0; for (int i = 1; i <= m; i++) { scanf( ... |
#include <bits/stdc++.h> using namespace std; int main() { string str[1009]; int n, m; while (cin >> n >> m) { for (int i = 0; i < n; i++) cin >> str[i]; int ret = 0, cury = 0; for (int i = 0; i < n; i++) { int right = cury; if (i % 2 == 0) { for (int j = 0; j... |
#include <bits/stdc++.h> using namespace std; int dis[3]; int n; int main() { scanf( %d , &n); scanf( %d %d %d , &dis[0], &dis[1], &dis[2]); int ans = 0; n--; int idx = 0; while (n--) { if (dis[idx] < dis[(idx + 1) % 3]) { ans += dis[idx]; idx = (idx + 2) % 3; ... |
#include <bits/stdc++.h> using namespace std; const int maxl = 1000 * 100 + 5; int n, k; string s; int dis[30][maxl]; int main() { cin >> n >> k >> s; memset(dis, -1, sizeof dis); for (int i = 0; i < 27; i++) { queue<int> q; for (int j = 0; j < k; j++) if (s[j] == (char)(i + ... |
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; string s(200, a ); cout << s << endl; for (int i = 0; i < n; i++) { int u; cin >> u; s[u] = s[u] == a ? b : a ; cout << s << endl... |
#include <bits/stdc++.h> using namespace std; vector<vector<long long>> gr; vector<bool> used; vector<long long> tin, up; const long long Nmax = 400000; long long p[Nmax]; long long sz[Nmax]; long long timer = 0; long long diametr(long long u, vector<vector<long long>> gr) { queue<long long> q; ... |
#include <bits/stdc++.h> #pragma GCC optimize( O3 ) #pragma GCC target( sse4 ) using namespace std; using ll = long long; using vi = vector<int>; using pii = pair<int, int>; const int MX = 1e5 + 10; template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto i = begin(v); i !=... |
#include <bits/stdc++.h> using namespace std; const int inf = (int)1e6 + 5; void compute() { int n, m; scanf( %d %d , &n, &m); vector<int> v(n); for (int i = 0; i < n; ++i) scanf( %d , &v[i]); vector<pair<int, int> > seg(m); vector<vector<int> > lf(n), rg(n); for (int i = 0; i < m; ++i... |
#include <bits/stdc++.h> using namespace std; int main() { long long n, k; bool odd = false, even = false; cin >> n >> k; if (n & 1) { if (k > (n / 2 + 1)) { even = true; k -= (n / 2 + 1); } else odd = true; } else { if (k > n / 2) { even = true;... |
#include <bits/stdc++.h> #pragma GCC optimize(3) using namespace std; bool Finish_read; template <class T> inline void read(T &x) { Finish_read = 0; x = 0; int f = 1; char ch = getchar(); while (!isdigit(ch)) { if (ch == - ) f = -1; if (ch == EOF) return; ch = getchar();... |
#include <bits/stdc++.h> using namespace std; long long a[(200020)], b[(200020)], close[100][2]; set<pair<long long, long long> > vis; signed main() { long long n; cin >> n; for (long long i = 1; i <= n; i++) scanf( %lld , &a[i]); for (long long i = 1; i <= n; i++) b[i] = b[i - 1] + a[i]; lo... |
#include <bits/stdc++.h> using namespace std; int n, s, i, j, k, a, b, w, l1, l2, c, rt, lw; double v[109][109], t[109][109], tp, tc, p1, p2, t1, t2; int main() { cin >> n >> s; for (i = 0; i < n; i++) { cin >> k; for (j = 0; j < k; j++) cin >> v[i][j] >> t[i][j]; t[i][k] = 9999999.0; ... |
#include <bits/stdc++.h> int main(void) { double a, v, l, d, w, t = 0; scanf( %lf%lf%lf%lf%lf , &a, &v, &l, &d, &w); if (2 * a * d <= w * w || w >= v) { if (l * a * 2 >= v * v) { t += v / a; t += (l - v * v / (2 * a)) / v; } else { t += sqrt(2 * l / a); } } el... |
#include <bits/stdc++.h> int main() { int t; scanf( %d , &t); while (t--) { long long int n, k; scanf( %lld %lld , &n, &k); long long int ans = 0; ans += (n / k) * k; if (n - ans > k / 2) ans += k / 2; else ans = n; printf( %lld n , ans); } }... |
#include <bits/stdc++.h> using namespace std; const int N = 105; int freq[N]; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, m; cin >> n >> m; for (int i = 0; i < m; i++) { int type; cin >> type; freq[type]++; } int start = 1, end = 100; while (sta... |
#include <bits/stdc++.h> using namespace std; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long TC = 1; while (TC--) { long long n; cin >> n; vector<long long> a(n); for (long long i = 0; i < n; i++) cin >> a[i]; long long lcnt = 1, rcnt = 1; ... |
#include <bits/stdc++.h> using namespace std; const int MAXN = 100005; const double eps = 1.0e-8; const double pi = acos(-1.0); complex<double> p[MAXN], P; double cross(complex<double> a, complex<double> b) { return (conj(a) * b).imag(); } double check(complex<double> a, complex<double> b) { dou... |
#include <bits/stdc++.h> using namespace std; const int MAXN = 100000; int f[MAXN + 5]; int main() { memset(f, 0, sizeof(f)); int m = 0, a = 0, r0 = 0, b = 0, ans = 1; cin >> a >> b >> m >> r0; f[r0] = 1; for (int i = 2;; ++i) { r0 = (a * r0 + b) % m; ++ans; if (f[r0] != 0)... |
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, m, count = 0; cin >> n >> m; int x = min(n, m); n = n - x; m = m - x; int rest = (n / 2) + (m / 2); cout << x << << rest << endl; return 0; } |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int t; cin >> t; while (t--) { unordered_map<char, int> mp; int n; cin >> n; string arr[n]; for (int i = 0; i < n; i++) { cin >> arr[i]; for (aut... |
#include <bits/stdc++.h> using namespace std; int main() { long long int a, b, c, l; cin >> a >> b >> c >> l; long long int Total = (l + 1) * (l + 2) * (l + 3) / 6; for (long long int la = 0; la <= l; la++) { long long int mini = min(a - b - c + la, l - la); if (mini < 0) continue; ... |
#include <bits/stdc++.h> using namespace std; using ll = long long; const int MAX = 1 << 20; bitset<MAX> dpgl, mv, dp[20]; map<char, int> to; char rv[20]; int cnt[20], le[20], ri[20], n, A, B, b; void solve(int ms) { int L = 1e9, R = -1, tot = 0; vector<int> tr, chr, oth; for(int... |
#include <bits/stdc++.h> using namespace std; const int INF = 1e9+7, M = (1e9+7), MAXN = 1 * 2e5; int A[MAXN], C[MAXN]; int64_t modpow(int64_t a, int64_t b) { int64_t res = 1; for(; b; b >>= 1) { if(b&1) res=res*a%M; a=a*a%M; } return res; } ... |
#include <iostream> #include <fstream> #include <vector> #include <algorithm> #include <cmath> #include <iomanip> #include <cstring> std::ifstream fin( input.txt ); std::ofstream fout( output.txt ); int main(){ std::ios_base::sync_with_stdio(false); std::cin.tie(NULL); std::... |
#include <bits/stdc++.h> using namespace std; const int N = 100010; long long int A[N]; vector<int> g[N]; long long int dfs(int x, int p) { A[x] = 1; for (int i = 0; i < g[x].size(); ++i) { int y = g[x][i]; if (y == p) continue; A[x] += dfs(y, x); } return A[x]; } long do... |
#include <bits/stdc++.h> using namespace std; const int MAX = 1200; int x, y; bool run() { bool fox = true; while (1) { if (fox) { if (x == 0) { if (y >= 22) { y -= 22; } else { return false; } } else if (x == 1) { if ... |
#include <bits/stdc++.h> using namespace std; const int maxn = 1e3 + 5; const int maxm = 1 << 13; int n; long long k; pair<int, long long> dp[maxn][maxm]; int pre[maxn][maxm]; long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } vector<long long> v; void get_div(long long k... |
#include <bits/stdc++.h> int dp[1000]; int mm[200][200]; int main() { int i, j, n, m, t; dp[3] = 3; for (i = 4; i < 1000; ++i) dp[i] = dp[i - 1] + i - 1; while (scanf( %d , &n) != EOF) { for (i = 3; i < 1000; ++i) { if (dp[i] > n) break; } m = i - 1; printf( %d n , ... |
#include<bits/stdc++.h> #include<string.h> #define int long long #include<vector> #define rep(i,a,b) for(int i=a;i<b;i++) #define pb push_back #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); using namespace std; const int N=2e5+5; vector<int> v[N]; int siz[N];... |
#include <bits/stdc++.h> using namespace std; long long ans = -((long long)1 << 62); int n, u, r; int a[105]; int b[105]; int k[105]; int p[105]; void process(int m, int op) { if (((u - m) & 1) == 0) { long long an = 0; for (int i = 1; i <= n; i++) an += a[i] * k[i]; ans = max(an, ... |
#include <bits/stdc++.h> using namespace std; int main() { int n; int m; int k; vector<vector<int> > A; cin >> n >> m >> k; for (int i = 0; i < n; i++) { vector<int> X; for (int j = 0; j < m; j++) { int l; cin >> l; X.push_back(l); } A.push_bac... |
#include <bits/stdc++.h> using namespace std; const int maxh = 200 * 1000 + 5; struct item { int pos, hash; item(int pos, int hash) : pos(pos), hash(hash) {} }; bool operator<(item a, item b) { return a.pos < b.pos; } int n, m, h; set<item> S[maxh]; map<int, int> M; int pos[maxh]; int Len[ma... |
#include <bits/stdc++.h> using namespace std; long long const MAXN = 5e1 + 8; long long const INF = 3e3 + 8; long long const delta = 1000000007; long long a[MAXN]; long long dp[MAXN][MAXN][INF]; double calc(long long t, long long n, long long b) { double ans = t; for (long long i = b + 1; i <= n; ... |
#include <bits/stdc++.h> using namespace std; const int N = 5005; const int K = 100005; int n, m, k; int t, p; int l[N], c[N], x[K]; int main() { scanf( %d%d%d , &n, &m, &k); x[0] = 0; for (int i = 1; i <= k; ++i) { scanf( %d%d%d , &t, &p, &x[i]); if (t == 1) l[--p] = i; ... |
#include <bits/stdc++.h> using namespace std; int N, K; long double ans, s; int R[1000010], data[100010]; int v[1000010], c[1000010]; int STv[20][1000010], STc[20][1000010]; int calcv(int l, int r) { int delta = r - l + 1; int t = log(delta) / log(2); return max(STv[t][l], STv[t][r - (1 << t) ... |
#include <bits/stdc++.h> int main() { int i; char a[1000]; gets(a); for (i = 0; i < strlen(a); i++) { printf( %c , a[i]); } for (i = strlen(a) - 1; i >= 0; i--) { printf( %c , a[i]); } return 0; } |
#include <bits/stdc++.h> using namespace std; const int N = 42, K = 11; int n, k, cnt, mark[N], nw[K]; vector<long long> v[K], mask[K]; void do_it(long long u, int x) { for (int i = 0; i < nw[x] + 1; i++) { int cnt = i + __builtin_popcountll(u & mask[x].back()); v[x + 1].push_back((u & (1ll <<... |
#include <bits/stdc++.h> using namespace std; long long PRIME = 1000000007; long long n, m, k; long long maxm = (long long)(-10e13); long long a[100005][6]; long long max_in_range[100005][6][20]; long long ans[6]; long long times(long long length) { long long cnt = 0; while (length >= 2) { ... |
#include <bits/stdc++.h> using namespace std; long long int max(long long int a, long long int b) { if (a >= b) return a; else return b; } long long int min(long long int a, long long int b) { if (a >= b) return b; else return a; } long long int diff(long long int a, ... |
#include <bits/stdc++.h> using namespace std; struct p { int x, y, z; }; int c[102][102][102] = {0}; bool ck(int x, int y, int z) { if (!c[x][y][z]) return false; if (c[x - 1][y][z] && c[x + 1][y][z]) return true; if (c[x][y - 1][z] && c[x][y + 1][z]) return true; if (c[x][y][z - 1] && c[x... |
#include <bits/stdc++.h> using namespace std; const int BIT = (1 << 17), M = 110, N = 25; int n, m, cnt[BIT], a[M]; long long f[BIT][N], b[N], p[N], year; void solve(int x) { memset(f, 0, sizeof(f)); f[0][0] = 1; int maxb = (1 << n); for (int i = 0; i < maxb; i++) { for (int j = 0; j <= ... |
#include <bits/stdc++.h> using namespace std; multiset<int> all[40]; long long s[40]; int getpos(int x) { int ret = 0; while ((1 << ret) < x) ret++; return ret; } void check() { long long tot = 0LL; int ret = 0; for (int i = 0; i <= 31; i++) { ret += all[i].size(); ret -=... |
#include <bits/stdc++.h> using namespace std; long long n, c, r[200001], u, v, i, t, k; vector<long long> graph[200001], ans; bool dfs(long long x, long long p) { long long s = 0; for (auto i : graph[x]) if (i != p) s += dfs(i, x); if (r[x] && !s) ans.push_back(x); return s + (long long)(r... |
#include <bits/stdc++.h> using namespace std; const int n0 = 1003, m = 1e5, mod = 998244353; int n, k, a[n0], dp[2][n0], b[n0]; int calc(int gap) { for (int i = 1; i <= n; i++) b[i] = upper_bound(a + 1, a + n + 1, a[i] - gap) - a - 1; memset(&dp, 0, sizeof(dp)); for (int j = 0; j <= n; j++) dp... |
#include <bits/stdc++.h> using namespace std; struct Room { int length, width, height, total_length; } room[500]; struct Wallpaper { int length, width, price; } wallpaper[500]; int main() { int n, m, i, j, ans, tmp, price, ret; cin >> n; for (i = 0; i < n; ++i) { cin >> room[i].len... |
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; if (n == 1) cout << 1; else if (abs(n - m) > abs(m - 1)) { cout << m + 1; } else { cout << m - 1; } } |
#include <bits/stdc++.h> using namespace std; int main() { long long int n, a, b, diff; cin >> n >> a >> b; vector<long long int> v; long long int arr[n]; for (long long int i = 0; i < n; i++) { cin >> arr[i]; v.push_back(arr[i]); } sort(v.begin(), v.end()); diff = v[n - ... |
#include <bits/stdc++.h> using namespace std; int n, q, k; vector<int> v[1000010]; int lastans = 0, res[1000010]; void dfs(int np, int fath, int val) { res[np] = val; for (auto &x : v[np]) { if (x == fath) continue; dfs(x, np, min(val, x)); } } int main() { scanf( %d%d , &n, &q... |
#include <bits/stdc++.h> using namespace std; long long a[100]; long long b[100]; vector<long long> pos[101]; int main() { long long i, j, k, l, m, n, t; scanf( %lld , &n); scanf( %lld , &k); for (i = 0; i < n; i++) { scanf( %lld , &a[i]); pos[a[i]].push_back(i); } long lon... |
#include <bits/stdc++.h> using namespace std; int dx[] = {0, 0, 1, -1, -1, -1, 1, 1}; int dy[] = {1, -1, 0, 0, -1, 1, 1, -1}; template <class T> inline T biton(T n, T pos) { return n | ((T)1 << pos); } template <class T> inline T bitoff(T n, T pos) { return n & ~((T)1 << pos); } template <cl... |
#include <bits/stdc++.h> using namespace std; int n, k, A[2005], DP[2005]; inline int ok(int X) { memset(DP, 0, sizeof(DP)); int i, j; long long l1, r1, l2, r2; for (i = 1; i <= n; i++) DP[i] = i - 1; for (i = 2; i <= n; i++) if (abs(A[i] - A[i - 1]) <= X) DP[i] = 0; else ... |
#include <bits/stdc++.h> using namespace std; int N; int A[100005]; int G[100005]; int m; int main() { scanf( %d , &N); for (int i = 0; i < N; ++i) scanf( %d , &A[i]); for (int i = 0; i < N; ++i) { if (i < N / 2) { if (A[i] - i >= 1) ++G[A[i] - i]; } else { if (A[i] -... |
#include <bits/stdc++.h> using namespace std; const int size = 1007; const long long modulo = 1000000007; const long long oo = 1e18; const double EPS = 1e-13; const double PI = acos(-1.0); int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n, m; cin >> n >> m; vector<vector... |
#include <bits/stdc++.h> using namespace std; int main() { int test, a, sum = 0, wait = 0, counter = 0; priority_queue<int, vector<int>, greater<int> > q; queue<int> qqq; cin >> test; int num = test; while (test--) { cin >> a; sum += a; q.push(a); qqq.push(a); } ... |
#include <bits/stdc++.h> using namespace std; const int N = 3010; const int M = 11; const int INF = 1 << 30; const double EPS = 1e-8; const int MOD = 1000000007LL; int n, tot[N]; vector<int> edge[N], edge2[N]; int dfs(int u, int fa) { int num = 0, sz; sz = edge[u].size(); for (int i = 0; i... |
#include <bits/stdc++.h> using namespace std; #define rep(i,a,b) for(int i = (a); i < b; ++i) #define rrep(i,a,b) for(int i = (b); i --> (a);) #define trav(x, v) for(auto &x : v) #define all(v) (v).begin(),(v).end() #define sz(v) (int)(v).size() bool que_big(int s, string x){ cout << s+1 << << x... |
#include <bits/stdc++.h> inline long long read() { long long x = 0, f = 1; char c = getchar(); for (; c > 9 || c < 0 ; c = getchar()) { if (c == - ) f = -1; } for (; c >= 0 && c <= 9 ; c = getchar()) { x = x * 10 + c - 0 ; } return x * f; } int dp[18][(1 << 18)][2][... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.