func_code_string stringlengths 59 71.4k |
|---|
#include <bits/stdc++.h> using namespace std; int main(int argc, char* argv[]) { cin.sync_with_stdio(0); cout.sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, r[100], b[100], sumr, sumb, ans = 1, check = 1; cin >> n; for (int i = 0; i < n; i++) cin >> r[i]; for (int i = 0; i < n; ... |
#include <bits/stdc++.h> using namespace std; int n, r; long long A[1000005], sum; int main() { scanf( %d %d , &n, &r); for (int i = (0); i < (1 << n); i++) scanf( %lld , &A[i]), sum += A[i]; printf( %.12lf n , 1.0 * sum / (1 << n)); for (int i = (0); i < (r); i++) { int x; long long... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); vector<int> a; int n, t; cin >> n; a.reserve(n); while (n--) { cin >> t; if (t != 0) { a.push_back(t); } } sort(a.begin(), a.e... |
#include <bits/stdc++.h> using namespace std; const int N = int(2e5); int g[N]; int ans = 0; int n; bool used[N]; void bfs(int start) { queue<int> q; q.push(start); used[start] = true; while (!q.empty()) { int from = q.front(); q.pop(); int to = g[from]; if (!used[t... |
#include <bits/stdc++.h> using namespace std; int main() { long long int n, m, ans; int d; char c; cin >> n >> c; m = n - 1; if (c == f ) { d = 1; } if (c == e ) { d = 2; } if (c == d ) { d = 3; } if (c == a ) { d = 4; } if (c == b... |
#include <bits/stdc++.h> using namespace std; long long cnt[10]; long long w, ans; void dfs(int pos, long long c) { long long rec; if (pos > 8) { ans = max(ans, w - c); return; } rec = min(cnt[pos], c / pos); for (long long i = rec; i >= max(rec - 8, 0LL); i--) dfs(pos + 1,... |
#include <bits/stdc++.h> using namespace std; const int MAX_N = 300000; vector<int> g[MAX_N]; int sz[MAX_N]; int x[MAX_N]; int p[MAX_N]; int N; int dfs(int v) { sz[v] = 1; p[v] = N; x[N++] = v; for (int i = 0; i < g[v].size(); i++) { sz[v] += dfs(g[v][i]); } return sz[v]; ... |
#include <bits/stdc++.h> using namespace std; long long n, k; long long pr[300005], cr[300005]; long long nr[300005][2], fr[300005][2]; bool visit[300005], visit1[300005]; char str[300005]; vector<long long> vr[300005], br[300005]; void pre(), dfs(long long, long long); long long uni(long long, long l... |
#include <bits/stdc++.h> using namespace std; int n; vector<string> s; int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> n; s.resize(n); for (int i = 0; i < n; i++) cin >> s[i]; for (int i = n - 1; i > 0; i--) { int l = 1, r = min(s[i].length(), s[i - 1].length()); ... |
#include <bits/stdc++.h> using namespace std; inline char gc() { static char buf[100000], *p1 = buf, *p2 = buf; return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2) ? EOF : *p1++; } inline long long read() { long long x = 0; char ch = getcha... |
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int t, i, j, k, z, x, num[2]; string s; cin >> t; while (t--) { cin >> s; memset(num, 0, sizeof(num)); for (i = 0; i < s.size(); i++) { if (s[i] == 1 ) num[1]+... |
#include <bits/stdc++.h> using namespace std; int const MAX = 2005; int mp[MAX][MAX]; int main() { int n; bool flag = true; scanf( %d , &n); for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) scanf( %d , &mp[i][j]); for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j+... |
#include <bits/stdc++.h> using namespace std; const int MAXPOW = 20; const int MAXA = 1048577; const int MAXN = 100009; const int MAXM = 100009; const int INF = 1e9 + 7; struct Node { Node(int val) : val(val) {} int val; }; struct MinIntervalTree { MinIntervalTree(int n, int val) { N... |
#include <bits/stdc++.h> using namespace std; int main(int argc, char const *argv[]) { long long x, d, k = 1; cin >> x >> d; vector<long long> ans; while (x) { long long rem = 0; for (int i = 31; i >= 0; --i) { if (x >> i & 1) { long long tmp = i; if (i == 0) ... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int t, n, k; cin >> t; while (t--) { cin >> n >> k; long long a[n], b[n], c = 0; for (int i = 0; i < n; i++) cin >> a[i], b[i] = (a[i] % k); sort(b, b + n); reverse(... |
#include <bits/stdc++.h> using namespace std; map<int, vector<pair<int, int> > > mp; int n, tt; int arr[300000]; int main() { cin >> n; for (int i = 1; i <= n; i++) cin >> arr[i]; for (int r = 1; r <= n; r++) { long long sum = 0; for (int l = r; l >= 1; l--) { sum += arr[l]; ... |
#include <bits/stdc++.h> using namespace std; int n, d, v[102], c, g[102], k, S; int main(void) { cin >> n >> d; for (int i = 1; i <= n; i++) cin >> v[i]; for (int i = 1; i < n; i++) { if (v[i] % 2) c++; else c--; if (c == 0) g[k++] = abs(v[i] - v[i + 1]); } s... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); int n, m, k; cin >> n >> m >> k; if (k > 1) { if (m == n) { cout << 2 * k + 1 << endl; for (int i = (int)(1); i < ((int)k + 1); i++) { cout << 1 << ; } cout... |
#include <bits/stdc++.h> int** arr; std::vector<int> opers; void del3(int x, int y) { if (arr[x][y] && arr[x + 1][y] && arr[x][y + 1]) { opers.push_back(x + 1); opers.push_back(y + 1); opers.push_back(x + 2); opers.push_back(y + 1); opers.push_back(x + 1); opers.push_back(y... |
#include <bits/stdc++.h> using namespace std; long long n, m, k, ans = 0; int main() { cin >> n >> m >> k; if (n - 1 + m - 1 < k) { cout << -1 << endl; return 0; } long long buf = sqrt(n); buf++; for (int i = 0; i <= buf; i++) { long long x = n / (i + 1); if (k - i ... |
#include <bits/stdc++.h> using namespace std; void solve() { int N; cin >> N; long long int dp_D = 1, dp = 0, dp_temp; for (int i = 0; i < N; i++) { dp_temp = dp_D; dp_D = 3 * dp; dp = dp * 2 + dp_temp; dp %= 1000000007; dp_D %= 1000000007; } cout << dp_D << end... |
#include <bits/stdc++.h> using namespace std; long long cal(long long x) { return (x + 1) * (x + 2) >> 1; } int main() { int a, b, c, l; while (scanf( %d%d%d%d , &a, &b, &c, &l) != EOF) { long long ans = 0; for (int i = 0; i <= l; i++) ans += 1LL * (i + 1) * (i + 2) / 2; for (long long i... |
#include <bits/stdc++.h> using namespace std; const int maxn = 1e9 + 3; long long n, sum; vector<int> vec; int32_t main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); cin >> n; for (int i = n - 100; i <= n; i++) { long long x = i; while (x) { sum += x % 10; ... |
#include <bits/stdc++.h> using namespace std; inline void read(int &x) { int v = 0, f = 1; char c = getchar(); while (!isdigit(c) && c != - ) c = getchar(); if (c == - ) f = -1; else v = (c & 15); while (isdigit(c = getchar())) v = (v << 1) + (v << 3) + (c & 15); x = v * f;... |
#include <bits/stdc++.h> using namespace std; int main() { string d[] = { monday , tuesday , wednesday , thursday , friday , saturday , sunday }; string a, b; int e, c, g, f, u; bool o; cin >> a >> b; for (int i = 0; i < 7; i++) { if (a == d[i]) { e = i... |
#include <bits/stdc++.h> using namespace std; void solve() { long long n; cin >> n; long long arr[n]; for (long long i = 0; i < n; ++i) { cin >> arr[i]; } stack<pair<long long, long long>> s1, s2; s1.push({0, -1}); long long left[n], right[n]; for (long long i = 0; i < n; +... |
#include <bits/stdc++.h> using namespace std; long long a, b, c, d, cnt = 1; string s; bool ok = true, mtest = true; void solve() { cin >> b; vector<int> v(b), vc(b); for (auto& i : v) cin >> i; for (auto& i : vc) cin >> i; sort(v.begin(), v.end()); sort(vc.begin(), vc.end()); for ... |
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n; vector<int> a(n); vector<pair<int, int> > d; for (int i = 0; i < n; i++) { cin >> a[i]; d.push_back(make_pair(a[i], 0)); } cin >> m; vector<int> b(m); vector<pair<int, int> > c(n + m); ... |
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 1, M = 1e9 + 7; mt19937 rng(std::chrono::system_clock::now().time_since_epoch().count()); int n, q, bit[N], inv[N], a[N], last[N], INVER[N], ans[N]; bool prime[N]; vector<int> v[N]; struct query { int l, r, id; void sc(int temp) { ... |
#include <bits/stdc++.h> using namespace std; int ans[300005]; int main() { int n, m; scanf( %d%d , &n, &m); set<int> alive; for (int i = 1; i <= n; i++) alive.insert(i); for (int i = 0; i < m; i++) { int l, r, x; scanf( %d%d%d , &l, &r, &x); set<int>::iterator it = alive.low... |
#include <bits/stdc++.h> using namespace std; pair<int, long long> da; inline long long p(long long x) { return x * x * x; } long long m; void dfs(long long now, int sum, long long maxnum) { if (!now) da = max(da, make_pair(sum, maxnum)); else { long long i = 1; for (; p(i + 1) <= no... |
#include <bits/stdc++.h> std::map<std::string, std::string> opcodes; std::string next(std::string s) { std::string res = s; res[res.size() - 1]++; for (int i = (int)res.size() - 1; i >= 0; i--) { if (res[i] > f ) { res[i] = a ; res[i - 1]++; } } return res; } in... |
#include <bits/stdc++.h> using namespace std; const long long int MOD = 1e9 + 7; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int n; cin >> n; long long int a[n]; for (long long int i = 0; i < n; i++) { cin >> a[i]; } if (n == 1) { cout <<... |
#include <bits/stdc++.h> using namespace std; const double EPS = 1e-8; const int mod = 1e9 + 7; const int N = 1e6 + 10; const long long INF = 1e18; long long power(long long x, long long y) { long long t = 1; while (y > 0) { if (y % 2) y -= 1, t = t * x % mod; else y /= 2... |
#include <bits/stdc++.h> using namespace std; const long long M = 5005; const int MOD = 998244353; const int MX = 3e5 + 5; const long long INF = 1e18; const long double PI = acos((long double)-1); void msm() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); } int sol... |
#include <bits/stdc++.h> using namespace std; template <typename T1, typename T2> inline void chkmin(T1 &x, T2 y) { if (x > y) x = y; } template <typename T1, typename T2> inline void chkmax(T1 &x, T2 y) { if (x < y) x = y; } template <typename T, typename U> inline ostream &operator<<(ostream... |
#include <bits/stdc++.h> using namespace std; long long n, m, d, l; int main() { cin >> n >> d >> m >> l; long long x = 0; for (long long i = 0; i < n; i++) { if (x < i * m) { break; } while (x <= i * m + l) x = (((i * m + l) / d) + 1) * d; } cout << x << endl; re... |
#include <bits/stdc++.h> using namespace std; const int N = 40; const int M = 20; long long incident_mask[N]; vector<int> g[N]; int n, m, used[N]; long long ans = 0; long long cntmask[1 << M]; template <typename T> inline void chkmax(T &x, T y) { x = max(x, y); } template <typename T> inli... |
#include <bits/stdc++.h> using namespace std; const int INF = 1E9; int main() { int n; string s; cin >> n >> s; for (int len = 1; len <= n; len++) { bool ok = true; for (int i = 0; i < n; i++) { if (i + len * 4 < n && s[i] == * && s[i] == s[i + len] && s[i] == s[i... |
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e7 + 100; const int INF = 0x3FFFFFFF; bool vis[MAXN]; int main() { long long a, b, m; cin >> a >> b >> m; for (int i = 1; i <= a; i++) { long long t = 1e9; long long mod = i * t % m; if (vis[mod]) break; vis[mo... |
#include <bits/stdc++.h> using namespace std; const int N = 710, size = 1 << 20, mod = (int)1e9 + 7, inf = 2e9; const long long INF = 1e15; template <class o> void qr(o& x) { char c = getchar(); x = 0; int f = 1; while (!isdigit(c)) { if (c == - ) f = -1; c = getchar(); } ... |
#include <bits/stdc++.h> using namespace std; const int INF = 1e5; int a[100][100]; int main() { int n, i = 0; cin >> n; cin >> a[i / n][i % n]; i++; a[i / n][i % n] = (i >= n * n ? INF : a[i / n][i % n]); cin >> a[i / n][i % n]; i++; a[i / n][i % n] = (i >= n * n ? INF : a[i / n... |
#include <bits/stdc++.h> using namespace std; int a[100005], ans[100005], ti[100005], app[100005], t, n; int cnt(int k) { int ret = 1, count = 0; ++t; for (int i = 1; i <= n; i++) { if (ti[a[i]] != t) { ti[a[i]] = t; app[a[i]] = false; } if (!app[a[i]]) { if (... |
#include <bits/stdc++.h> #pragma GCC optimize(2) using namespace std; inline void read(long long &x) { x = 0; long long f = 1; char s = getchar(); while (s < 0 || s > 9 ) { if (s == - ) f = -1; s = getchar(); } while (s >= 0 && s <= 9 ) { x = (x << 3) + (x << 1) + ... |
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); string s[4]; for (int i = 0; i < 4; i++) cin >> s[i]; int x = 0; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { x = s[i][j] == # ; x += s[i + 1][j] == # ; ... |
#include <bits/stdc++.h> using namespace std; int main() { int n, S; cin >> n >> S; vector<int> a(n); for (int i = 0; i < n; i++) cin >> a[i]; long long z = LLONG_MAX; sort(a.begin(), a.end()); long long fh = 0, sh = 0; for (int i = 0; i < n / 2; i++) { if (a[i] > S) fh += a[i]... |
/* problem : CF1466I The Riddle of the Sphinx reference : https://www.luogu.com.cn/blog/CXY07/solution-cf1466i */ #include <bits/stdc++.h> #define mp std::make_pair #define pb push_back #define fi first #define se second #define gc getchar #define pc putchar #define ep emplace #define eb empla... |
#include <bits/stdc++.h> using namespace std; const long long maxn = 3e5 + 30; long long N, M, T, X[maxn], ans[maxn], shift; char W[maxn]; vector<pair<long long, long long> > v; vector<long long> last; int main() { cin >> N >> M >> T; for (long long i = 1; i <= N; i++) { scanf( %lld %c , &X[... |
#include <bits/stdc++.h> using namespace std; vector<pair<double, pair<int, int> > > s; int n, x; pair<double, pair<int, int> > tmp; signed main() { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); cin >> n; for (register int i = 1; (1 < n) ? (i <= n) : (i >= n); i += (1 < n) ? 1 : (-1))... |
#include <bits/stdc++.h> using namespace std; long long X[(int)1e5 + 9]; long long C[(int)1e5 + 9]; int main() { ios_base::sync_with_stdio(NULL); cin.tie(NULL); cout.tie(NULL); long long n, k, a, c, cost; cin >> n >> k; for (int i = 1; i <= n; i++) { cin >> X[i]; } cin >> a... |
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; long long ans = 0; long long a = 1, b = 2, c; while (b <= n) { ans++; c = a + b; a = b; b = c; } cout << ans << endl; return 0; } |
#include <bits/stdc++.h> using namespace std; const long long MOD = 1000000009; vector<long long> vec; long long powmod(long long a, long long m) { long long ret = 1 % MOD; for (; m; m >>= 1) { if (m & 1) { ret *= a; if (ret >= MOD) ret %= MOD; } a *= a; if (a >= ... |
#include <bits/stdc++.h> using namespace std; int main() { int d[100008] = {0}; int n = 0, f = 0; cin >> n; for (f = 0; f < n; f++) cin >> d[f]; sort(d, d + n); if (d[n - 1] >= d[n - 2] + d[n - 3]) cout << NO ; else { cout << YES n ; for (f = n - 1; f >= 0; f -= 2) co... |
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 7; const int inf = INT_MAX; const long long inff = 1e18; const long long mod = 1e9 + 7; int p[30]; int n; string s; int used[40]; int Find(int x) { return p[x] == x ? x : p[x] = Find(p[x]); } void Union(int x, int y) { p[Find(x)]... |
#include <bits/stdc++.h> using namespace std; const int N = 100005; int dr8[] = {0, 0, 1, -1, 1, 1, -1, -1}; int dc8[] = {1, -1, 0, 0, -1, 1, -1, 1}; int dr4[] = {0, 1, -1, 0}; int dc4[] = {1, 0, 0, -1}; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; int on = 1023; ... |
#include <bits/stdc++.h> using namespace std; vector<vector<int> > ad(123456); vector<int> vis(123456, 0), par(123456, -1), hc(123456, 0), hp(123456, 0), v(123456, 0); void dfs(int s) { int i, a, x = ad[s].size(), y = 0; for (i = 0; i < x; i++) { a = ad[s][i]; if (vis[a] == 0) par[a] =... |
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 100, M = 52 + 10, LG = 30, base = 2; const int MOD = 1e9 + 7, mod = 1e9 + 9; const long long INF = 1e9, inf = 1e18; long long p, q, m, k; string w, s, t; vector<long long> a, b; vector<long long> ans; int main() { ios_base::sync_wit... |
#include <bits/stdc++.h> using namespace std; long long cal(long long a, long long b) { long long sign = 1; if (a < 0) { a = -a; sign = -sign; } if (b < 0) { b = -b; sign = -sign; } unsigned long long n = (unsigned long long)a * b; long long r = n % 4000000000LL; ... |
#include <bits/stdc++.h> using namespace std; const int NR = 1005; 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 << 3) + (x << 1) + (ch ^ 48); ch = getc... |
#include<bits/stdc++.h> #define ll long long #define pll pair<ll,ll> #define pii pair<int,int> #define rep(i,a,b) for(int i=a;i<=b;++i) #define per(i,a,b) for(int i=a;i>=b;--i) #define mem0(x) memset(x,0,sizeof(x)) #define meminf(x) memset(x,0x3f,sizeof(x)) #define VI vector<int> #define VL vector<ll>... |
#include <bits/stdc++.h> using namespace std; void ch_max(int &x, int y) { if (x < y) x = y; } void ch_min(int &x, int y) { if (x > y) x = y; } const double pi = acos(-1.0); const double eps = 1e-9; bool solve(long long a, long long b) { if (a == 0 || b == 0) return false; if (a < b) swa... |
#include <bits/stdc++.h> using namespace std; using LL = long long; void err() { cout << endl; } template <template <typename...> class T, typename t, typename... Args> void err(T<t> a, Args... args) { for (auto x : a) cout << x << ; err(args...); } template <typename T, typename... Args> voi... |
#include <bits/stdc++.h> using namespace std; int n, head[100005], tot, de[100005], le[100005], lf[100005]; struct node { int to, next; } edge[100005 * 2]; void add_edge(int u, int v) { de[u]++; edge[tot].to = v; edge[tot].next = head[u]; head[u] = tot++; } void dfs(int cnt, int pre) {... |
#include <bits/stdc++.h> using namespace std; const int MAXN = 3e5 + 10; long long n, a, d[MAXN], v[MAXN], P[MAXN]; vector<pair<int, long long> > vc; long long ans; int main() { cin >> n >> a; vc.push_back({0, 0}); P[0] = -1e18; for (int i = 0; i < n; i++) { cin >> d[i] >> v[i]; ... |
#include <bits/stdc++.h> using namespace std; signed main() { long long n; cin >> n; long long ans = 0; long long L = -4 * 45, R = 45; map<long long, long long> vls; for (long long i = L; i <= R; i++) vls[i] = 1e18; for (long long i = 0; i < 100; i++) { for (long long j = 0; j < 10... |
// #include<bits/stdc++.h> #include<iostream> #include<algorithm> #include<cmath> /* #include<vector> #include<set> #include<map> #include<unordered_map> #define umap unordered_map #include<unordered_set> #define uset unordered_set */ #define pii pair<int,int> #define F first #define S sec... |
#include <bits/stdc++.h> using namespace std; int y; int main() { long long int a, b, s; cin >> a >> b >> s; a = abs(a); b = abs(b); if (s >= a + b && (s - a - b) % 2 == 0) { cout << YES ; } else cout << NO ; } |
#include <bits/stdc++.h> using namespace std; bool cmp(int a, int b) { return a > b; } const int maxen = 1e5 + 5, minn = 1e-5; string a[1005]; int main() { int n; cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; int res = 0, mn = 13; for (int i = 0; i < n - 1; i++) { for (int j = i... |
#include <bits/stdc++.h> #define pb push_back #define mp make_pair #define ll long long #define mod 1000000007 using namespace std; void factorial(ll int *fact) { fact[0]=1; for(ll int i=1;i<=200000;i++) { fact[i]=(fact[i-1]*i)%mod; } } int main() { int t=1; cin>>... |
#include <bits/stdc++.h> using namespace std; void solve() { long long int n, i, t, j, p, q, a, b, m; cin >> t; while (t--) { cin >> n >> m; string s[n]; bool ck = true; ; p = (n * m); if (p % 2 == 0) a = (p / 2) - 1; else a = p / 2; for (i... |
#include <bits/stdc++.h> using namespace std; vector<vector<int> > arr; double ans = 0; void dfs(int x, int h, int p) { ans += 1.0 / h; for (int i = 0; i < arr[x].size(); i++) { if (arr[x][i] != p) dfs(arr[x][i], h + 1, x); } } int main() { int n; cin >> n; int x, y; arr.re... |
#include <bits/stdc++.h> using namespace std; int MOD = 1e9 + 7; long long int power(long long int a, long long int b) { long long int res = 1; a = a % MOD; while (b > 0) { if (b & 1) { res = (res * a) % MOD; b--; } a = (a * a) % MOD; b >>= 1; } return r... |
#include <bits/stdc++.h> using namespace std; vector<int> tree[2010]; int cs[2010], ps[2010]; int numDesc(int node) { int descendants = 0; for (int x : tree[node]) { descendants += 1 + numDesc(x); } if (descendants < cs[node]) return 10000; return descendants; } void solve(int node... |
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; char s[110]; int main() { while (~scanf( %s , s) && s[0] != e ) { char op[10]; int x = 0, y = 0, p, ans = 0; for (int i = 0; i <= 30; i++) { x = (i == 0 ? 0 : 1 << (i - 1)); y = 1 << i; cout ... |
#include <bits/stdc++.h> using namespace std; long long t, n, m, u, v, cnt = 0; long long head[400005], depth[200005], visited[200005]; vector<long long> ve[5]; struct edge { long long next; long long to; } e[400005]; queue<long long> q; inline void add_edge(long long u, long long v) { cnt++... |
#include <bits/stdc++.h> using namespace std; const long long INF = 2e18; const long long INFINT = 2e9; const int N = 1000006; const int NN = 1006; const int MOD = 1000000007; int main() { ios_base::sync_with_stdio(0); long double n, h; cin >> n >> h; long double s = 1.0 * 1 * h / 2; l... |
#include <bits/stdc++.h> using namespace std; const int N = (int)1e5 + 9; long long power(long long x, long long y) { if (y == 0) return 1; long long temp = power(x, y / 2); if (y % 2 == 1) return temp * temp * x; else return temp * temp; } bool check(string a, string b) { sort... |
#include <bits/stdc++.h> using namespace std; int n, m, p, q, c, x, y, mod, lo[100000], z[3005][3005]; long long ans; struct segment_tree { int a[3005][13]; void update(int x, int y) { a[x][0] = y; } void build(int n) { for (int i = 1; i <= lo[n]; i++) for (int j = 1; j + (1 << i) - 1 ... |
#include <bits/stdc++.h> using namespace std; int t, k; int main() { cin >> t; while (t--) { vector<vector<pair<int, int>>> graph; cin >> k; graph.resize(2 * k); for (int i = 0; i < 2 * k - 1; ++i) { int a, b, c; cin >> a >> b >> c; a--; b--; ... |
#include <bits/stdc++.h> using namespace std; int bit[200050]; int n; int lowbit(int x) { return x & (-x); } int sum(int x) { int sum = 0; while (x > 0) { sum += bit[x]; x -= lowbit(x); } return sum; } void push(int pos, int num) { while (pos <= n) { bit[pos] += num; ... |
#include <bits/stdc++.h> using namespace std; int main() { long long T, n, k, a, b; cin >> T; while (T--) { cin >> n >> k >> a >> b; n -= k; bool flag = 0; if (a < b) swap(a, b); if ((2 * a + b) <= n && (n - 2 * a - b) % 3 == 0 && (2 * b + a) <= k && (k - 2 * b - ... |
#include <bits/stdc++.h> using namespace std; bool prime(long long x) { if (x == 2) return 1; if (x % 2 == 0) return 0; for (long long j = 3; j * j <= x; j += 2) { if (x % j == 0) return 0; } return 1; } int main() { long long t; cin >> t; while (t--) { long long n, m... |
#include <bits/stdc++.h> using namespace std; mt19937 rnd(time(0)); const long long inf = 0x3f3f3f3f3f3f3f3fLL; const long long N = 35; const long long MOD = 1e9 + 7; long long n, u, r, ans = -inf; long long a[N], b[N], k[N], p[N], dp[N][N]; void go(long long pos, long long lst) { if ((u - pos) % 2 ... |
#include <iostream> #include <algorithm> #define int long long using namespace std; void solve () { int a, b, c, d; cin >> a >> b >> c >> d; int arr[4] = {a,b,c,d}; sort (arr, arr+4); int max1 = arr[4-1]; int max2 = arr[4-2]; int win1 = max (a, b); int win2 = max (c, d); if (win1 == m... |
#include <bits/stdc++.h> using namespace std; long long int MOD = 1e9 + 7; long long int prime[10000000]; long long int fac[200100], ifac[200100]; long long int inv[200100]; vector<long long int> primes; long long int gcd(long long int a, long long int b) { if (b == 0) return a; return gcd(b, a % ... |
#include <bits/stdc++.h> using namespace std; int n; int main() { scanf( %d , &n); if (n <= 2) { printf( -1 n ); return 0; } printf( %d , n); for (n--; n; n--) printf( %d , n); return 0; } |
#include <bits/stdc++.h> using namespace std; int c[25]; bool vis[25]; int n, m; bool dfs(int p, int s, int k) { if (p > n) return m == n - 1; if (!k) return dfs(p + 1, p, c[p + 1]); for (; s; s--) if (!vis[s] && c[s] + 1 < c[p] && c[s] + 1 <= k) { vis[s] = true; k -= c[s] + ... |
#include <bits/stdc++.h> using namespace std; string s; class SegmentTree { struct data { int ans; int opened; int closed; }; public: data merge(data A, data B) { int extra = min(A.opened, B.closed); return data{A.ans + B.ans + extra, A.opened + B.opened - extra, ... |
#include <bits/stdc++.h> using namespace std; int main() { int a; cin >> a; if (a > 36) { cout << -1 ; } else { while (a >= 2) { a -= 2; cout << 8 ; } if (a == 1) { cout << 4 ; } } } |
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s; getline(cin, s); for (int i = 0; i < n; i++) { getline(cin, s); if (s.length() >= 5) { if ((s.substr(0, 5) == miao. ) && (s.substr(s.length() - 5, 5) != lala. )) cout... |
#include <bits/stdc++.h> using namespace std; const int MAXN = 1010; char mtr[MAXN][MAXN]; int main() { int n, m; cin >> n >> m; set<int> s; bool ok = true; for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { cin >> mtr[i][j]; } } for (int i = 1; i <= n;... |
#include <bits/stdc++.h> using namespace std; int main() { string a; int count = 0, c = 0; cin >> a; count = a.size(); for (int i = 0; a[i] != 0 ; i++) { if (a[i] >= A && a[i] <= Z ) c++; } if ((c == count) || ((c == count - 1) && (a[0] >= a && a[0] <= z ))) { for (in... |
#include <bits/stdc++.h> using namespace std; template <typename T> void chmin(T &x, const T &y) { if (x > y) x = y; } template <typename T> void chmax(T &x, const T &y) { if (x < y) x = y; } char readc() { char c; while ((c = getchar()) < - ) ; return c; } int read() { ... |
#include <bits/stdc++.h> using namespace std; const int MAXN = 150000 + 10; int len, n, h; int a[MAXN], b[MAXN]; int dp[1 << 20], all[1 << 20]; inline void go(int root, int lo, int hi, int s, int e, int key) { if (hi < s || e < lo) return; if (s <= lo && hi <= e) { all[root] += key; dp[r... |
#include <bits/stdc++.h> using namespace std; int n, m, q, ans, top[200005 << 1]; int find(int u) { if (top[u] == u) return u; return top[u] = find(top[u]); } inline void work() { scanf( %d %d %d , &n, &m, &q); for (int i = 1; i <= n + m; i++) top[i] = i; for (int i = 1, u, v; i <= q; i++)... |
#include <bits/stdc++.h> using namespace std; int getMin(int l, int r, char a[], char ch) { int count = 0; for (int i = l; i <= r; i++) { if (a[i] != ch) { count++; } } return count; } int findans(int l, int r, char a[], char ch) { if (l == r) { if (a[l] == ch) { ... |
#include <bits/stdc++.h> using namespace std; void MAIN(); int main() { MAIN(); return 0; } const long long N = 5e3 + 1, mod = 1e9 + 7; int n, m, best[N][N], len[N][N]; char s[N][N]; void MAIN() { scanf( %d%d , &n, &m); for (int i = 1; i <= n; ++i) { scanf( %s , s[i] + 1); fo... |
#include <bits/stdc++.h> using namespace std; vector<int> parent; vector<string> names; void parse(int par) { string str; char c; while (isalpha(cin.peek())) { cin >> c; str += c; } names.push_back(str); parent.push_back(par); int id = names.size() - 1; while (cin.pee... |
#include <bits/stdc++.h> using namespace std; const long long sz = 1e5 + 10; long long ara[sz], n, p; ; bool isValid(long long now) { long long ptr = 1; for (long long i = 1; i <= n; ++i) { while (ptr <= n && ara[ptr] <= now) ptr++; if (ptr - i >= p) return 0; now++; } return... |
#include <bits/stdc++.h> struct state { int n : 24; int c : 8; state const *prev; }; state b[128][128][128] = {}; void print(state const &s) { if (s.n) { state const &p = *s.prev; print(p); if (p.n < s.n) printf( %c , s.c); } } int main() { char s1[128]; char s2... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.