func_code_string stringlengths 59 71.4k |
|---|
#include <bits/stdc++.h> using namespace std; const int N = 1E5 + 10; int n, tot; int a[N], vis[N], twom[N], threem[N]; vector<int> x, y; stack<int> one, two, three; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> n; for (int i = 1; i <= n; ++i) cin >> a[i]; for (int ... |
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { if (b == 0) return a; return gcd(b, a % b); } vector<pair<long long, int> > v; int main() { long long a, b, d; cin >> a; cin >> b; d = a * b / gcd(a, b); if (a < b) { for (int i = 0; i * a... |
#include <bits/stdc++.h> using namespace std; map<long long, long long> mp; long long ar[200005]; long long br[200005]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t; t = 1; while (t--) { int n; cin >> n; for (int i = 1; i <= n; i++) { cin >>... |
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> a(n + 1); vector<int> b(n + 1); for (int i = 1; i <= n; i++) cin >> a[i]; sort(a.begin() + 1, a.end()); for (int i = 1; i <= n / 2; i++) b[2 * i] = a[i]; for (int i = n / 2 + 1; i <= n; i++) b[(i ... |
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; cout << (n * n) / 4 << endl; for (int i = 1; i <= n / 2; i++) cout << n << << i << endl; for (int i = 1; i <= n / 2; i++) for (int j = n / 2 + 1; j < n; j++) cout << i << << j << endl; } |
#include <bits/stdc++.h> using namespace std; short memo[6][40][1 << 6][1 << 6][1 << 6]; int n, m; short roll(int row, int col, int a, int b, int c) { if (col == m) { return (n - __builtin_popcount(a)); } if (row == n) { return roll(0, col + 1, b, c, 0) + (col > 0 ? (n - __b... |
#include <bits/stdc++.h> using namespace std; const int modulo = 1e9 + 7; const int max_n = 111; const int max_k = max_n * max_n; int bin_pow(int base, long long pw) { if (pw == 0) return 1; if (pw & 1) return (1LL * base * bin_pow(base, pw - 1)) % modulo; return bin_pow((1LL * base * base) % modu... |
#include <bits/stdc++.h> using namespace std; int cube[8][3]; long long len[28]; long long dist(int a, int b) { long long ret = 0; for (int i = 0; i < 3; i++) ret += (long long)(cube[a][i] - cube[b][i]) * (cube[a][i] - cube[b][i]); return ret; } bool check() { int idx = 0; for (int... |
#include <bits/stdc++.h> using namespace std; int main() { int n, i; cin >> n; bool t[2 * n], s[2 * n]; char tmp; for (i = 0; i < 2 * n; i++) { cin >> tmp; t[i] = (tmp == 1 ); } for (i = 0; i < 2 * n; i++) { cin >> tmp; s[i] = (tmp == 1 ); } int t_sum = ... |
#include <bits/stdc++.h> using namespace std; const int N = 105; int v[N], ans[N]; int main() { cin.tie(0), ios_base::sync_with_stdio(false); int n, k, s = 0; cin >> n >> k; for (int i = 0; i < n; i++) cin >> v[i], s += v[i], ans[i % k] += v[i]; int tans = 0; for (int i = 0; i < k; i++) ... |
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; const long long int MXN = 1e18; struct node { double x, y; } p, p1, p2, p3, p4; double ji(node a, node b, node c) { return (b.x - a.x) * (c.y - a.y) - (c.x - a.x) * (b.y - a.y); } bool jug(node a) { if ((ji(p1, p2, a) * ji(... |
#include <bits/stdc++.h> using namespace std; struct pl { int num, t1, t2, h1, h2; }; vector<pl> h[(1 << 16) + 5]; int n, k, su; int s[22], sum[(1 << 16) + 5], si[(1 << 16) + 5]; bitset<200000000> fl, ft; int work(int a) { if (a % k == 0) return work(a / k); return a; } int change(int a,... |
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; for (int i = 0; i < n; i++) { int a, b, c; cin >> a >> b >> c; int totmake = (a + b + c) / 3; if (a == 0 || b == 0 || totmake == 0) { cout << 0 << endl; } else if (a <= b && a <= totmake) { ... |
#include <bits/stdc++.h> using namespace std; int main() { string s, t; cin >> s >> t; map<char, char> m; bool ans = true; vector<pair<char, char>> v; int count = 0; for (int i = 0; i < s.size(); i++) { if (m.find(s[i]) != m.end()) { if (m[s[i]] != t[i]) { ans = f... |
# include <bits/stdc++.h> using namespace std; const int N=1e3+10; int n,m,a[N][N],sum1[N],sum2[N],c1[N],c2[N],c3[N]; map<int,int>mp,tt; signed main() { scanf( %d%d ,&n,&m); for (int i=1;i<=m;i++) for (int j=1;j<=n;j++) { scanf( %d ,&a[i][j]); sum1[i]+=a[i][j]; sum2[i]+=a[i][j]*a[i... |
#include <bits/stdc++.h> using namespace std; int main() { string s, s1, s2; long long a, b, c = 0; cin >> s; b = stoi(s); while (b > 0) { s1 = s; sort(s1.begin(), s1.end()); int d = stoi(s1) % 10; b = b - d; c++; s = to_string(b); } cout << c << n ;... |
#include <bits/stdc++.h> using namespace std; int main() { int a0, a1, a2, b0, b1, b2, n; cin >> a0 >> a1 >> a2; int cnt = (a0 + a1 + a2) / 5; if ((a0 + a1 + a2) % 5) cnt++; cin >> b0 >> b1 >> b2; cnt += ((b0 + b1 + b2) / 10); if ((b0 + b1 + b2) % 10) cnt++; cin >> n; if (cnt <= ... |
#include <bits/stdc++.h> using namespace std; long long x, y; string tt(long long a) { string ans = ; while (a != 0) ans += (a % 10) + 0 , a /= 10; int p = ans.length(); for (int i = 0; i * 2 < p; ++i) swap(ans[i], ans[p - i - 1]); return ans; } int main() { cin >> x >> y; strin... |
#include <bits/stdc++.h> using namespace std; double Cnk(int n, int k) { double result = 1; for (int i = 1; i <= k; ++i) { result *= n - k + i; result /= i; } return result; } double Power(int n, int power) { double result = 1; for (int i = 0; i < power; ++i) { result *... |
#include <bits/stdc++.h> using namespace std; using ull = unsigned long long; int main() { int t; cin >> t; while (t--) { ull n, k, x; cin >> n >> k >> x; cin.ignore(); string arr; getline(cin, arr); vector<pair<ull, ull>> values; for (int i = arr.size(); i-- ... |
#include <bits/stdc++.h> using namespace std; const int M = 1000000007; const int MM = 998244353; template <typename T, typename U> static inline void amin(T &x, U y) { if (y < x) x = y; } template <typename T, typename U> static inline void amax(T &x, U y) { if (x < y) x = y; } int _runtime... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long n, i, j, k, l, m, b, t, sum, sum1, flag, max1, min1; cin >> n >> m; long long a[n + 1]; for (i = 1; i <= n; i++) { cin >> a[i]; } sum = 0; long long pre[100... |
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; template <class T> void out(T x) { if (x < 0) { putchar( - ); x = -x; } if (x > 9) out(x / 10); putchar(x % 10 + 0 ); } long long dp[2005]; struct node { int x, y; } a[2005]; bool cmp(node a, ... |
#include <bits/stdc++.h> using namespace std; vector<vector<int>> adj[101]; int vis[101][101]; int id; bool dfs(const int &idx, int cur, int to) { if (cur == to) return true; bool ret = false; for (int i = 0; i < (int)adj[idx][cur].size(); i++) { if (vis[idx][adj[idx][cur][i]] == id) continu... |
#include <bits/stdc++.h> using namespace std; const int Maxn = 1e5 + 7; int H, ans; int cnt[10007][444], a[Maxn], flag[Maxn]; int mark[Maxn]; vector<int> luck; void lucky(int p) { if (p > 10000) return; luck.push_back(p); mark[p] = true; p *= 10; lucky(p + 4); lucky(p + 7); } v... |
#include <bits/stdc++.h> using namespace std; const double eps = 1e-8; char img[2007][2007]; int c[2007], r[2007]; int main() { int n; cin >> n; for (int i = 0; i < n; i++) scanf( %s , img[i]); for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) img[i][j] -= 0 ; int ans = 0; ... |
#include <bits/stdc++.h> #pragma comment(linker, /STACK:102400000,102400000 ) using namespace std; const int maxn = 1e6 + 3000; const long long mod = 1e9 + 7; long long k, p; int f[maxn]; bool vis[maxn]; long long cnt[maxn]; long long qpow(long long x, long long p) { long long ans = 1; while ... |
#include <bits/stdc++.h> using namespace std; void reset(int& n, int first) { n = n & ~(1 << first); } bool check(int n, int first) { return (bool)(n & (1 << first)); } const int mx = 55; long long inf = 1e18; unsigned long long f[mx], v; int a[mx]; int main() { f[0] = f[1] = 1; int i, j, k, n; ... |
#include <bits/stdc++.h> using ll = long long; int main() { std::ios_base::sync_with_stdio(0); std::cin.tie(0); std::string s; std::cin >> s; int n = s.length(); std::vector<std::set<int>> adj(26); for (int i = 0; i < n; ++i) { int d = s[i] - a ; adj[d].insert(i); } ... |
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c, d, i = 0, j = 0; cin >> a >> b >> c >> d; while (a != 0) { a = a - 1; i++; } while (b != 0) { b = b - 1; j++; } if (j >= i) cout << Second ; else cout << First ; } |
#include <bits/stdc++.h> using namespace std; using INT = long long; int n; int a[200010]; vector<int> B[200010]; void add(int u, int val) { for (; u <= n; u += u & -u) B[u].push_back(val); } int calc(int u, int val) { int ans = 0; for (; u; u -= u & -u) { int id = lower_bound(B[u].beg... |
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 10; bool a[maxn]; int main() { int n, k; while (~scanf( %d%d , &n, &k)) { int p = (n - k) / 2 + 1; int t = n / p; while (t--) { for (int i = 0; i < p; i++) { if (i == p - 1) printf( 0 ); ... |
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; int o = 0; int z = 0; for (int i = 0; i < n; i++) { int y; cin >> y; if (y == 1) o++; else z++; } if (z... |
#include <bits/stdc++.h> using namespace std; int n, x, i, w[100005], sum; int main() { cin >> n >> x; for (i = 1; i <= n; i++) { cin >> w[i]; sum = sum + w[i]; } if (sum + n - 1 == x) cout << YES ; else cout << NO ; } |
#include <bits/stdc++.h> using namespace std; int n, k, A, B, a[200006]; long long ask(int l, int r) { long long ans; int mid = (l + r) / 2, num = upper_bound(a + 1, a + k + 1, r) - lower_bound(a + 1, a + k + 1, l); if (num == 0) return A; else ans = 1LL * B * num * (r - l + 1)... |
#include <bits/stdc++.h> const int M = 1e5 + 5; int len; long long lsh[M * 3]; int n, m, k, p, t[M], v[M], nxt[M], pre[M]; long long CB[M * 3]; long long now, val[M], ans[M]; struct Query { int L, R, p, id; inline bool operator<(const Query& it) const { return p == it.p ? p & 1 ? R < it.R : ... |
#include <bits/stdc++.h> using namespace std; int n, m, d[200], g[200][200], dp[200][200], ans[200]; int cnt, st[200], ed[200]; bool flag[200]; void dfs1(int u) { flag[u] = true; st[u] = ++cnt; for (int i = 1; i <= n; i++) if (g[u][i] == 1 && !flag[i]) dfs1(i); ed[u] = ++cnt; } void ... |
#include <bits/stdc++.h> using namespace std; const int NMax = 101000; int N; vector<pair<int, int> > A, B, C, D; bool cmp1(pair<int, int> a, pair<int, int> b) { if (a.first < b.first) return 1; if (a.first > b.first) return 0; if (a.second < b.second) return 1; return 0; } bool cmp2(pair<... |
#include <bits/stdc++.h> using namespace std; int main() { int n; char a[110]; cin >> n >> a; for (int i = 2; i <= n; i++) { if (n % i == 0) reverse(a, a + i); } cout << a << endl; return 0; } |
#include <bits/stdc++.h> using namespace std; int main() { long long n, m, k, minn = 10000, a[1000], temp = 0; cin >> n >> m >> k; for (long long i = 0; i < n; i++) { cin >> a[i]; if (a[i] <= k && a[i] != 0) { temp = abs(i + 1 - m) * 10; if (temp < minn) minn = temp; } ... |
#include <bits/stdc++.h> using namespace std; int gi() { int a; scanf( %d , &a); return a; } long long gli() { long long a; scanf( %I64d , &a); return a; } long long gcd(long long a, long long b) { if (a == 0) return b; if (b == 0) return a; if (a > b) return gcd(a % b, b... |
#include <bits/stdc++.h> using namespace std; const int N = 55; const unsigned long long M = 1000000009LL; const int K = 3; const int LIT = 2500; const int INF = 1 << 30; const double eps = 1e-6; const unsigned long long MOD = 1000000007LL; const int dir[][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}}; un... |
#include <bits/stdc++.h> using namespace std; int th[100080], bl[100080]; int main() { int i, j, n, k, mx = 0, sum, fl, fval; scanf( %d %d , &n, &k); for (i = 0; i < n; i++) { scanf( %d , &th[i]); } for (i = 0; i < n; i++) { scanf( %d , &bl[i]); } j = 0; i = 0; sum ... |
#include <bits/stdc++.h> using namespace std; long long Solve(long long n, long long k) { long long low = 1; long long high = ((long long)1 << n) - 1; long long mid = low + (high - low) / 2; if (mid == k) return n; else if (mid < k) return Solve(n - 1, k - mid); else return... |
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf( %d , &n); for (int i = 1; i <= 2 * n / 3; i++) printf( %d %d n , i, 1); for (int i = 1; i <= n - 2 * n / 3; i++) printf( %d %d n , i * 2, 4); return 0; } |
#include <bits/stdc++.h> using namespace std; const int N = 200; long long n, num[N], tmp; int main() { cin >> n; for (int i = 0, v; i < n; i++) cin >> v, num[v]++; for (int i = 1; i <= 100; i++) { for (int j = 1; j < i; j++) tmp = max(0ll, min(num[0] - num[j], num[i])), num[j] += tmp,... |
#include <bits/stdc++.h> using namespace std; int n; int main() { cin >> n; cout << n / 2 - !(n % 2) - (n % 4 == 2) << << n / 2 + 1 + (n % 4 == 2); return 0; } |
#include <bits/stdc++.h> using namespace std; const double eps = 1e-9; bool doubleEquals(double a, double b) { return abs(a - b) < eps; } bool db_less(double a, double b) { return a < b - eps; } bool db_equal(double a, double b) { return abs(a - b) < eps; } bool db_less_equal(double a, double b) { return a ... |
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[n]; a[0] = 1; a[1] = 5; a[2] = 13; a[3] = 25; for (int i = 4; i < n; i++) { a[i] = a[i - 1] + 4 * (i); } cout << a[n - 1] << endl; return 0; } |
#include <bits/stdc++.h> using namespace std; const long long MOD = 1000000007; class Matrix { public: long long m[4][4]; Matrix(){}; Matrix(long long k[4][4]) { for (int i = 0; i < 4; i++) for (int j = 0; j < 4; j++) m[i][j] = k[i][j]; } }; Matrix operator*(const Matrix &a, c... |
#include <bits/stdc++.h> using namespace std; const int N = 100005; int n, deg[N], fa[N]; int root = 0; vector<pair<pair<int, int>, int> > ans; struct edge { int to, val; edge() {} edge(int to, int val) : to(to), val(val) {} }; vector<edge> G[N]; vector<int> leaf[N]; void add_edge(int x,... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; int mc = 0, i = 1, j = n; while (1) { cout << i << ; mc++; if (mc == n) break; cout << j << ; i++; j--; mc++; if ... |
#include <iostream> #include <sstream> #include <cstdio> #include <cmath> #include <cstring> #include <cctype> #include <string> #include <vector> #include <set> #include <unordered_set> #include <map> #include <unordered_map> #include <queue> #include <stack> #include <algorithm> #include... |
#include <bits/stdc++.h> using namespace std; void solve() { long long n; cin >> n; vector<long long> a(n); long long p1 = 0; for (long long i = 0; i < n; i++) { long long x; cin >> x; a[i] = x; p1 = max(p1, x); } long long m; cin >> m; vector<pair<long lo... |
#include <bits/stdc++.h> using namespace std; const int inf = (1 << 30) - 1; const long long linf = (1ll << 62) - 1; const int N = 1e6; int n; int p[N]; int division[2][N]; int dln[2]; bool u[N]; int main() { cin >> n; for (int i = 0; i < n; i++) { scanf( %d , &p[i]); p[i]--; ... |
#include <bits/stdc++.h> using namespace std; int main() { int n, h; cin >> n; int a[n]; cin >> a[0]; h = a[0]; for (int i = 1; i < n; i++) { cin >> a[i]; h = h + abs(a[i] - a[i - 1]) + 1; } cout << h + n; } |
#include <bits/stdc++.h> using namespace std; const int N = 5000 + 7; const int inf = 0x3f3f3f3f; const long long INF = 0x3f3f3f3f3f3f3f3f; const int mod = 998244353; const double eps = 1e-8; const double PI = acos(-1); template <class T, class S> inline void add(T& a, S b) { a += b; if (a >= ... |
#include <bits/stdc++.h> using namespace std; string s; int main() { getline(cin, s); int n, flag = 0; n = s.length(); for (int i = n; i >= 0; i--) { if ((s[i] >= a && s[i] <= z ) || (s[i] >= A && s[i] <= Z )) { if (s[i] == a || s[i] == e || s[i] == i || s[i] == o || ... |
#include <bits/stdc++.h> using namespace std; vector<long long> arr; pair<int, long long> doit(long long n) { if (n <= 7) return make_pair(n, n); vector<long long>::iterator ite = upper_bound(arr.begin(), arr.end(), n); int ind = (ite - arr.begin()); ind--; pair<int, long long> te1 = doit(n - ... |
#include <bits/stdc++.h> using namespace std; double xp, yp, vp; double x, y, v, r; const double pi = acos(-1); double cal(double x0, double y0, double x1, double y1) { double ji = x0 * x1 + y0 * y1; double L0 = sqrt(x0 * x0 + y0 * y0); double L1 = sqrt(x1 * x1 + y1 * y1); double cosA = ji / L... |
#include <bits/stdc++.h> using namespace std; int main() { std::ios::sync_with_stdio(false); cin.tie(0); int t, i, n, j, e; char grid[8][8]; map<int, bool> black, white; for (i = 0; i < 8; i++) { cin >> grid[i]; } int min = INT_MAX; int flag = 0; for (i = 0; i < 8; i++)... |
#include <bits/stdc++.h> using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); void coder_RB6() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } bool comp(long long int a, long long int b) { return (a > b); } int32_t main() { coder_RB6(); lon... |
#include <bits/stdc++.h> using namespace std; int n, m, f, t; const int N = 1e3 + 5; vector<int> adj[N]; int col[N], vis[N], row[N]; int dj[N][N]; int mn = -1e9, id = 1; void dfs(int u, int ret) { if (u == n + 1) { ret = 0; for (int i = 1; i <= 6; i++) { for (int j = i; j <= 6; j... |
#include <bits/stdc++.h> using namespace std; int n, m; int dot[510]; inline long double max(long double a, long double b) { return a > b ? a : b; } int main() { scanf( %d%d , &n, &m); for (int i = 1; i <= n; i++) { scanf( %d , dot + i); } double ans = 0.0; for (int i = 1; i <= m; i+... |
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; const long long int BOUND = 1.5e6; const long long int SQ_BOUND = BOUND * BOUND; vector<complex<long long int> > arr; long long int s[N]; inline long long int norm_sq(const complex<long long int> &z) { return (z * conj(z)).real(); ... |
// Say:He is the Most Merciful,We have believed in him and upon him we have relied [67:29] //#pragma GCC optimize ( Ofast ) //#pragma GCC target ( avx2 ) //#pragma GCC optimize( unroll-loops ) #include<bits/stdc++.h> using namespace std; /... |
#include <bits/stdc++.h> using namespace std; int num[100 + 5][100 + 5], ans[100 + 5][100 + 5]; int row[100 + 5], col[100 + 5]; int main() { int n, m; while (scanf( %d%d , &m, &n) != EOF) { int i, j, k; int ii, jj, kk; memset(row, 0, sizeof(row)); memset(col, 0, sizeof(col)); ... |
#include <bits/stdc++.h> using namespace std; const int N = 501; int n, m, a[N]; bool dp[2][N][N]; vector<int> sol; int main() { scanf( %d%d , &n, &m); for (int i = 0; i < n; ++i) scanf( %d , &a[i]); dp[0][0][0] = dp[0][a[0]][0] = dp[0][a[0]][a[0]] = true; int at = 0; for (int i = 1; i <... |
#include <bits/stdc++.h> template <typename T> inline void read(T& x) { T res = 0, flag = 1; char ch; ch = getchar(); while (!isdigit(ch)) { if (ch == - ) flag = -1; ch = getchar(); } while (isdigit(ch)) { res = res * 10 + ch - 48; ch = getchar(); } x = res *... |
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n, a; vector<int> v; cin >> n; for (int i = 0; i < n; i++) { cin >> a; v.push_back(a); } reverse(v.begin(), v.end()); for (int i = 0; i < n; i++) { ... |
#include <bits/stdc++.h> #pragma gcc optimize(o3) using namespace std; long long qpow(long long x, long long y) { return y ? (y & 1 ? x * qpow(x, y - 1) % 1000000007 : qpow(x * x % 1000000007, y / 2)) : 1; } template <typename T> inline void read(T& x) { x = 0; ... |
#include <bits/stdc++.h> using namespace std; const long long N = (long long)(2e5 + 1); bool bipartite = true; vector<long long> colour; vector<long long> adj[N]; vector<long long> visited; void dfs(long long node, long long par, long long col) { visited[node] = 1; colour[node] = col; for (aut... |
#include <bits/stdc++.h> using namespace std; char buf[10000001], *ptr = buf - 1; inline int read() { int x = 0, c = *++ptr; while (c < 48) c = *++ptr; while (c > 47) x = x * 10 + c - 0 , c = *++ptr; return x; } const int MAXN = 500005; const int MOD = 1000000007; int s[MAXN], a[MAXN], b[... |
#include <bits/stdc++.h> using namespace std; const int MaxN = 1e5; int m, n; long long sum[MaxN + 5], a[MaxN + 5]; long long Gcd(long long x, long long y) { if (y == 0) return x; else return Gcd(y, x % y); } void pdo() { long long ans = 0; for (int i = 1; i <= n; i++) { ... |
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) #pragma GCC target( sse,sse2,sse3,ssse3,sse4 ) using namespace std; using ll = long long; using ld = long double; using itn = int; using dd = double; mt19937 gen(41); const dd eps = 1e-7; const ll MAXN = 2097152; const ll INF = 1e9; const dd... |
#include <bits/stdc++.h> using namespace std; #define ll long long int ll mod=1e9+7; ll mul(ll a,ll b) { return ((a%mod)*(b%mod))%mod; } ll add(ll a,ll b) { return ((a%mod)+(b%mod))%mod; } ll sub(ll a,ll b) { return ((a%mod)-(b%mod)+mod)%mod; } ll po(ll a, ll b) { if(... |
#include <bits/stdc++.h> using namespace std; long long int dp[50][50]; int m, n; int main() { for (int x = 0; x < 36; x++) { dp[0][x] = 1; } for (int x = 1; x < 36; x++) for (int y = 1; y < 36; y++) for (int z = 0; z < x; z++) { dp[x][y] += dp[z][y - 1] * dp[x - z - 1]... |
#include <bits/stdc++.h> using namespace std; template <typename T> void print(T t) { cout << t << endl; } long long n = 0, t = 0; long long small = -1e18, big = 1e18; const long long mod = 1e9 + 7; map<long long, long long> occ; map<pair<long long, long long>, long long> occP; void print2dVec(v... |
#include <bits/stdc++.h> using namespace std; int main() { int n, a, b; cin >> n >> a >> b; int rem = b % n; int sum = a + rem; if (sum <= 0) cout << n + sum; else if (sum > n) cout << sum - n; else cout << sum; return 0; } |
#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; if (n == 1) { cout << -1 n ; return 0; } if (n & 1) { cout << -1 n ; return 0; } for (int i = 1; i <= n; i++) { i... |
#include <bits/stdc++.h> using namespace std; const int MAX_N = 100030; const long long MODD = 1000000009; int ctr[128]; void do_case() { int n, k; cin >> n >> k; string s; cin >> s; for (int i = 0; i < s.size(); i++) ctr[s[i]]++; sort(ctr, ctr + 128); reverse(ctr, ctr + 128); ... |
#include <bits/stdc++.h> using namespace std; vector<vector<long long> > g; vector<bool> used; void dfs(long long v, long long &h, long long &e) { used[v] = true; h++; e += g[v].size(); for (int i = 0; i < g[v].size(); ++i) { if (!used[g[v][i]]) dfs(g[v][i], h, e); } } int main() {... |
#include <bits/stdc++.h> using namespace std; void solve() { long long n; cin >> n; vector<int> res; for (int i = n + 1;; i++) { if (res.size() == n) { break; } res.push_back(i); } for (auto x : res) { cout << x << ; } } int main() { long long t... |
#include <bits/stdc++.h> using namespace std; const int inf = 99999999; struct seg_tree { int seg[3 * 1000009], lazy[3 * 1000009]; void construct_segtree(int start, int end, int pos) { lazy[pos] = -inf; if (end == start + 1) seg[pos] = 0; else { int mid = (start + end) / ... |
#include <bits/stdc++.h> using namespace std; long long labs(long long a) { return a < 0 ? (-a) : a; } long long max(long long a, long long b) { return a > b ? a : b; } long long min(long long a, long long b) { return a < b ? a : b; } int main() { int n; cin >> n; int h = 1; vector<vector<int>... |
#include <bits/stdc++.h> using namespace std; int main() { std::ios_base::sync_with_stdio(false); float dist, h, w, t; cin >> dist; cin >> h; cin >> w; t = dist / (h + w); printf( %.12lf n , t * h); return 0; } |
#include <bits/stdc++.h> using namespace std; const int infinity = 1e9; int N, M; int A[509][509]; int P[509][509]; int squaresum(int cx, int cy, int k) { int ax = cx - k / 2; int ay = cy - k / 2; int bx = cx + k / 2; int by = cy + k / 2; return P[bx][by] - P[ax - 1][by] - P[bx][ay - 1] ... |
#include <bits/stdc++.h> using namespace std; const int maxn = 100005; int cnt[maxn], num[maxn], t[maxn], r[maxn], last[maxn]; char ans[maxn]; int main() { int T, m, k; scanf( %d , &T); while (T--) { scanf( %d%d , &m, &k); for (int i = 1; i <= k; i++) { scanf( %d , &num[i]); ... |
#include <bits/stdc++.h> using namespace std; const int Maxn = 1000; int n, m; char B[Maxn][Maxn]; bool takeHor(int r, int c1, int c2) { if (c2 >= m) return false; if (B[r][c1] != W || B[r][c1 + 1] != B || B[r][c2] != W ) return false; bool ctake[4]; fill(ctake, ctake + 4, true); if (... |
#include <bits/stdc++.h> using namespace std; const int N = 100005, P = 1e9 + 7; int n, s, ans, c[N], f[N]; inline int pw(int a, int b) { int r = 1; for (; b; b >>= 1, a = 1ll * a * a % P) if (b & 1) r = 1ll * r * a % P; return r; } int main() { scanf( %d , &n); for (int i = 1; i <... |
#include <bits/stdc++.h> using namespace std; const int LIMIT = 1e7; int prime[LIMIT], palin[LIMIT]; int pr[LIMIT], pa[LIMIT]; int cnt_dig(int x) { if (x == 0) return 1; else { int ans = 0; while (x > 0) { x /= 10; ans++; } return ans; } } int main... |
#include <bits/stdc++.h> using namespace std; const int inf = INT_MAX / 2; const int Maxn = 305; int a[Maxn + 5][Maxn + 5], f[Maxn + 5][Maxn + 5], g[Maxn + 5][Maxn + 5], n; int solve() { for (int(i) = (1); (i) <= (n); ++(i)) for (int(j) = (1); (j) <= (n); ++(j)) f[i][j] = -inf; f[1][1] = a[1][1]... |
#include <bits/stdc++.h> using namespace std; int msb(long long x) { union { double a; int32_t b[2]; }; a = x; return (b[1] >> 20) - 1023; } void sol() { int n, x, y; vector<int> a(4), b(4); for (int i = (0); i < (4); i++) { cin >> a[i]; } if ((a[0] + a[1]) ... |
#include <bits/stdc++.h> int main() { int n, k; scanf( %d %d , &n, &k); char a[n]; scanf( %s , a); int i, start, end; for (i = 0; i < n; i++) { if (a[i] == G ) start = i; if (a[i] == T ) end = i; } int sign = start - end; if (start > end) k = -k; while ((sign * (s... |
#include <bits/stdc++.h> using namespace std; const long long MAXN = 1e3 + 10, inf = 1e18, mod = 1e9 + 7; struct pair_hash { template <class T1, class T2> std::size_t operator()(const std::pair<T1, T2> &p) const { auto h1 = std::hash<T1>{}(p.first); auto h2 = std::hash<T2>{}(p.second); r... |
#include <bits/stdc++.h> using namespace std; long long t, i, n, res, mx, a[300009]; map<int, int> mp; int main() { cin >> n; for (i = 1; i <= 2 * n; i++) { cin >> a[i]; } for (i = 1; i <= 2 * n; i++) { mp[a[i]]++; if (mp[a[i]] == 1) { res++; } else { res-... |
#include <bits/stdc++.h> #pragma warning(disable : 4996) #pragma comment(linker, /stack:200000000 ) #pragma GCC optimize( Ofast ) #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native ) #pragma GCC optimize( -ffloat-store ) using namespace std; clock_t time_p = clock(); void aryan... |
#include <bits/stdc++.h> using namespace std; vector<int> adj[100005]; int n; long long sz[100005]; long double E[100005]; void dfs1(int u, int p) { sz[u] = 1; for (auto v : adj[u]) { if (v == p) continue; dfs1(v, u); sz[u] += sz[v]; } } void dfs2(int u, int p) { if (u)... |
#include <bits/stdc++.h> using namespace std; long long E[50]; int get_len(long long s) { int cnt(0); while (s) cnt++, s /= 10; return cnt; } int find(long long n, int l) { if (n == 0) return 0; int len = get_len(n); if (n < E[l]) { return min(find(n, l - 1), find(E[l] - n, l - 1... |
#include <bits/stdc++.h> using namespace std; int main() { map<int, int> pos1; map<int, int> pos2; int n; cin >> n; int a[n], b[n]; for (int i = 0; i < n; i++) { cin >> a[i]; pos1[a[i]] = i; } for (int i = 0; i < n; i++) { cin >> b[i]; pos2[b[i]] = i; } ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.