func_code_string stringlengths 59 71.4k |
|---|
#include <bits/stdc++.h> using namespace std; template <typename Arg1> void __f(const char* name, Arg1&& arg1) { cout << name << : << arg1 << std::endl; } template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args) { const char* comma = strchr(names + 1, ... |
#include <bits/stdc++.h> template <typename T> T pow(T a, T b, long long m) { T ans = 1; while (b > 0) { if (b % 2 == 1) ans = (ans * a) % m; b /= 2; a = (a * a) % m; } return ans % m; } using namespace std; const long long N = 2e5 + 77; string s; void sol() { long lo... |
#include <bits/stdc++.h> using namespace std; const int MAXN = 100050; int item[MAXN]; int main() { int dcnt; while (scanf( %d , &dcnt) == 1) { int discount = MAXN; for (int i = 0; i < dcnt; i++) { int tmp; scanf( %d , &tmp); discount = min(discount, tmp); } ... |
#include <bits/stdc++.h> int main() { int n, m; scanf( %d%d , &n, &m); int min_row = n, max_row = 0, min_col = m, max_col = 0; char S[105][105]; for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { scanf( %c , &S[i][j]); if (S[i][j] == * ) { min_row = std... |
#include <bits/stdc++.h> using namespace std; const char dig[10][8] = { 1110111 , 0010010 , 1011101 , 1011011 , 0111010 , 1101011 , 1101111 , 1010010 , 1111111 , 1111011 }; int n, m; char s[2022][8]; int det[2022][10]; bool f[2022][2022]; int calc(int id1, int id2) { ... |
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 10; long long n, sum; int a[maxn], ans[maxn]; int main() { scanf( %I64d%I64d , &n, &sum); long long tot = 0; for (int i = 1; i <= n; i++) { scanf( %d , &a[i]); tot += a[i]; } for (int i = 1; i <= n; i++) { ... |
#include <bits/stdc++.h> using namespace std; const long long MX = 300005; long long a[MX], b[MX]; int32_t main() { long long n, p, k; cin >> n >> p >> k; for (long long i = 0; i < n; i++) { cin >> a[i]; b[i] = (((a[i] * a[i]) % p) * ((a[i] * a[i]) % p) - (k * a[i]) + (k * p)) ... |
#include <bits/stdc++.h> using namespace std; int main() { long long t, h, g, n; scanf( %lld , &t); while (t--) { scanf( %lld %lld , &h, &g); n = 1ll << h; pair<long long, long long> p[n - 1]; for (long long i = 1; i < n; i++) scanf( %lld , &p[i - 1].first), p[i - 1].seco... |
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1.0); const int inf = 0x3f3f3f3f; const double eps = 1e-15; const long long INF = (1LL << 60); const int N = 200000 + 100; int xis[N << 1]; bool vis[N << 1]; struct QUE { bool flag; int x, y; } que[N]; struct SegTree { ... |
#include <cstdio> #include <algorithm> #define ll long long int using namespace std; const int MAX = 1e7+10; int t, c; int ans[MAX]; int prime[MAX], pcount; bool vis[MAX]; ll d[MAX], f[MAX]; void eular() { for (int i = 1; i <= MAX; i++) ans[i] = MAX; ans[1] = 1; for (int i = 2; i <... |
#include <bits/stdc++.h> using namespace std; const int N = 1000010; int n, arr[N], arr2[N], seg[4 * N], lazy[4 * N]; inline void fix(int s, int e, int idx) { seg[idx] += lazy[idx]; if (s != e) { lazy[(idx << 1)] += lazy[idx]; lazy[(idx << 1) + 1] += lazy[idx]; } lazy[idx] = 0; } ... |
#include <bits/stdc++.h> using namespace std; const int MX = 6; int n, Arr[6]; int solve(int rem, int mask) { if (mask == ((1 << MX) - 1)) return 0; int Ans = 50; for (int i = 0; i < MX; i++) { if (!(mask & (1 << i))) { if (rem < Arr[i]) Ans = min(Ans, 1 + solve(n - Arr[i], m... |
#include <bits/stdc++.h> using namespace std; inline int in() { int x, y; y = scanf( %d , &x); return x; } const int MAXN = 2e6 + 10; int n, p[MAXN], sec[MAXN], pt[MAXN]; string s; int nxt[MAXN], prv[MAXN]; int d[MAXN][2]; bool ok(int mid, int sz) { memset(d, 0, sizeof(d)); d[0][0]... |
#include <bits/stdc++.h> using namespace std; const long long inf = 1e15; int n, B, c0[5010], c1[5010]; vector<int> e[5010]; vector<long long> f[5010], g[5010]; void combine(vector<long long>& a, const vector<long long>& b) { int la = a.size(), lb = b.size(), lc = la + lb - 1; vector<long long> c(lc... |
#include <bits/stdc++.h> using namespace std; struct keep { int pos; int apples; }; keep inp[1000]; bool cmp(keep x, keep y) { if (x.pos < y.pos) return 1; return 0; } int main() { int n; cin >> n; int l = 0, r = 0; int sum = 0; for (int i = 0; i < n; i++) { cin >... |
#include <bits/stdc++.h> int main() { long int n, k, i, *a, *b, t, max, j; scanf( %ld , &t); while (t--) { scanf( %ld , &n); a = (long int *)malloc(n * sizeof(long int)); b = (long int *)malloc(n * sizeof(long int)); for (i = 0; i < n; i++) { scanf( %ld , &a[i]); b[... |
#include <bits/stdc++.h> using namespace std; const int maxn = 300010; const int INF = 1e9 + 7; struct node { int x, y; } p[maxn]; int s[maxn]; int dis(int i, int j) { return abs(p[i].x - p[j].x) + abs(p[i].y - p[j].y); } int main() { int n, top, i, num, ans, maxx, maxy, minx, miny, tmp, j, pos1... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, k; cin >> n >> k; vector<int> arr(k); for (int i = 0; i < k; i++) { arr[i] = i + 1; } vector<string> allPos; do { string s = ; for (int x : arr) ... |
#include <bits/stdc++.h> using namespace std; int q; char s[5050]; bool f[5000][5000]; int g[5000][5000]; int main() { scanf( %s , s); int n = strlen(s); for (int i = 0; i < n; i++) { for (int j = i; j >= 0; j--) { if (i - j == 0) f[j][i] = 1; else if (i - j == 1 ... |
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; long long dp[200100][2]; long long ans[200100]; int main(int argc, char const *argv[]) { int T, k; cin >> T >> k; dp[k][1] = 1; dp[1][0] = 1; for (int i = 2; i <= 100000; i++) { if (i - k <= 0) { ... |
#include <bits/stdc++.h> using namespace std; int main() { long long n, m, fl = 0, a[200005], c[200005] = {0}, ans, i, j; cin >> n >> m; for (i = 0; i < n; i++) { cin >> a[i]; } sort(a, a + n); for (i = 0; i < n; i++) { a[i] = a[i] % m; c[a[i]]++; if (c[a[i]] > 1) fl ... |
#include <bits/stdc++.h> using namespace std; const int MAX = 4e5 + 5; int vis[MAX]; vector<int> adj[MAX]; vector<vector<int> > trip; void dfs(int x) { vis[x] = 1; for (auto u : adj[x]) { if (!vis[u]) { for (auto v1 : adj[x]) { for (auto v2 : adj[u]) { if (!vis[v1... |
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 5; int v1[10], v2[10]; int main() { memset(v1, 0, sizeof(v1)); memset(v2, 0, sizeof(v2)); int n; scanf( %d , &n); for (int i = 0, a; i < n; i++) { scanf( %d , &a); v1[a]++; } for (int i = 0, a; i < n; i++) ... |
#include <bits/stdc++.h> const long long MAXN = 80000 + 5; std::vector<long long> G[MAXN]; long long n; long long sz[MAXN], fa[MAXN]; inline void dfs1(long long v, long long faa = 0) { sz[v] = 1; fa[v] = faa; for (auto x : G[v]) { if (x == faa) continue; dfs1(x, v); sz[v] += sz[x... |
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; int a[N], n; int dp[N]; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n; for (int i = 1; i <= n; ++i) { cin >> a[i]; } for (int i = 1; i <= n; ++i) { dp[i] = dp[i - 1] + 20; for (i... |
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; const int N = 1000000 + 5; const int K = 26 + 5; char s[N], t[N]; int ns[K], nt[K], ans[K]; int main() { scanf( %s %s , s, t); for (int i = 0; t[i]; ++i) { nt[t[i] - a ]++; } int cnt = 0; for (int i ... |
#include <bits/stdc++.h> const long long INF = 0x3f3f3f3f3f3f3f3fLL; const int inf = 0x3f3f3f3f; const int mod = 1e9 + 7; const double eps = 1e-6; template <class T> inline void read(T& x) { int sign = 1; char c = getchar(); x = 0; while (c > 9 || c < 0 ) { if (c == - ) sign = -1; ... |
#include <bits/stdc++.h> using namespace std; const double eps = 1e-10; pair<double, double> za, zb, zc, zd; pair<double, double> a, b, c, d, e; pair<double, double> A, B, C, D; double cha(pair<double, double> a, pair<double, double> b, pair<double, double> c) { return (b.first - a.first) *... |
#include <bits/stdc++.h> using namespace std; const int MAXN = 200009; long long N, M; long long Max[MAXN], A[MAXN]; long long maxLL(long long num1, long long num2) { return (num1 > num2 ? num1 : num2); } void Update(int x, long long nh) { for (int i = x; i <= N; i += (i & (-i))) Max[i] = maxLL(Ma... |
#include <bits/stdc++.h> using namespace std; vector<pair<long double, int> > v; int main() { int n; cin >> n; for (int i = 1; i <= n; i++) { long double x, y; cin >> x >> y; v.push_back(make_pair(atan2(y, x), i)); } sort(v.begin(), v.end()); v.push_back(v[0]); if (v.... |
#include <bits/stdc++.h> using namespace std; const int inf = 1e9 + 10; int main() { int n; cin >> n; int an[n]; vector<int> p; vector<pair<int, int> > st; int i = 0; for (int a = 0; a < n * 2; a++) { char sy; cin >> sy; if (sy == + ) { p.push_back(i++); ... |
#include <bits/stdc++.h> using namespace std; int arr[2010], money, mn, mx, ans; vector<pair<int, int> > tmp; int main() { int n, b; cin >> n >> b; for (int i = 0; i < n; i++) { cin >> arr[i]; tmp.push_back(make_pair(arr[i], i)); } sort(tmp.rbegin(), tmp.rend()); for (int i =... |
#include <bits/stdc++.h> using namespace std; bool comp(string s, string t, vector<int> rows) { int i = 0; int m = s.size(); while (i < m && (s[i] == t[i] || (find(rows.begin(), rows.end(), i) != rows.end()))) i++; if (i == m) return false; return s[i] < t[i]; } int main() {... |
#include <bits/stdc++.h> using namespace std; const long long p = 1000000007; int q[200005][3]; int n, cnt = 1; vector<int> c[200005]; int v[200005]; int l[200005]; int r[200005]; int f[200005]; long long rev[200005]; void eec_solve(long long& a, const long long x, long long& b, c... |
#include <bits/stdc++.h> using namespace std; int o[101]; int main() { int t; cin >> t; for (int i = 0; i < t; i++) { int e; cin >> e; if (e % 7 == 0) { o[i] = e / 7; } else { o[i] = e / 7 + 1; } } for (int i = 0; i < t; i++) { cout << o[i] <... |
#include <bits/stdc++.h> using namespace std; const int maxn = 3e5 + 5; int n, m, col[maxn]; set<int> s; set<int>::iterator t[maxn]; int main() { while (~scanf( %d %d , &n, &m)) { s.clear(); for (int i = 1; i <= n; i++) s.insert(i); int cnt = 0; while (m--) { int l, r, c;... |
#include <bits/stdc++.h> using namespace std; int main() { int n, m; scanf( %d%d , &n, &m); vector<int> mp(32); vector<int> A(m); for (int i = 0; i < n; i++) { int no; scanf( %d , &no); for (int ii = 0; ii < 31; ii++) if (no & (1 << ii)) mp[ii]++; } for (int i =... |
#include <bits/stdc++.h> using namespace std; const long long N = 1e2 + 7; const long long nol = 0; long long n; string g, s; void vkoshp() { cin >> n; while (n >= 2) { g += 1 ; n -= 2; } if (n == 1) { s += 7 ; g.erase(g.begin()); s += g; g = s; } ... |
#include <bits/stdc++.h> using namespace std; const long long int mod = 1e9 + 7; const long long int N = 1e5 + 5; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long int i, j, tc; cin >> tc; while (tc--) { long long int n, w; cin >> n >> w; ... |
#include <bits/stdc++.h> using namespace std; constexpr long long N = 600500; constexpr long long D = 2000010; constexpr long double EPS = 1e-8; ofstream fout; ifstream fin; int flag = -1; long long n, m, k; vector<vector<int> > v; vector<int> h; vector<int> was; bool comp(int a, int b) { return... |
#include <bits/stdc++.h> using namespace std; template <typename First> void debug_print_in(First first) { cerr << first << endl; return; } template <typename First, typename... Rest> void debug_print_in(First first, Rest... rest) { cerr << first << ; debug_print_in(rest...); return; ... |
#include <bits/stdc++.h> using namespace std; template <typename T> inline void read(T &x) { x = 0; char c = getchar(); bool flag = false; while (!isdigit(c)) { if (c == - ) flag = true; c = getchar(); } while (isdigit(c)) { x = (x << 1) + (x << 3) + (c ^ 48); c = ... |
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int sc[1005]; int n, k, p, x, y; cin >> n >> k >> p >> x >> y; for (int i = 1; i <= k; i++) { cin >> sc[i]; x -= sc[i]; } if (x < 0) { cout << -1 << ... |
#include <bits/stdc++.h> using namespace std; const int MAXN = 505; vector<int> ans; struct node { int val, id; bool operator<(const node &o) const { if (val == o.val) return id < o.id; return val < o.val; } }; node a[MAXN], b[MAXN]; void doit(int n) { for (int i = 1; i <= n - ... |
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } vector<int> records; int max = a[0]; records.push_back(0); int case1 = -1; int case1_records; for (int i = 1; i < n; i++) { if (m... |
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize( O2,no-stack-protector,unroll-loops,fast-math ) const long long maxn = 1e5 + 10, maxm = 1e6 + 10, lg = 17, mod = 998244353, inf = 1e18; long long n, len, a, b, par[maxn][lg + 1], h[maxn], zuz[maxn], tguz; pair<long long, long... |
#include <bits/stdc++.h> using namespace std; bool visit[4]; long long dfs(vector<long long> &v, vector<char> &chars) { long long res = LLONG_MAX; if (v.size() == 1) { return v.front(); } for (int i = 0; i < v.size() - 1; i++) { for (int j = i + 1; j < v.size(); j++) { vector<l... |
#include<bits/stdc++.h> using namespace std; const int N = 55; void solve() { int n; int ans=0; scanf( %d , &n); for(int i=1;i<=n;i++) { int x; scanf( %d , &x); if(x!=2) ans++; } cout<<ans<<endl; } int main() { int t; ... |
#include <bits/stdc++.h> using namespace std; int work() { long long n, q; cin >> n >> q; while (q--) { long long x, y; cin >> x >> y; if ((x + y) % 2 == 0) { long long w = 0; long long a = (x - 1) / 2; w += a * n; if (x % 2 == 1) { w += (y + 1... |
#include <bits/stdc++.h> using namespace std; void solve(void) { string a, b, c; cin >> a >> b >> c; int n = a.length(); for (int i = 0; i < n; i++) { if (c[i] != a[i] && c[i] != b[i]) { cout << NO n ; return; } } cout << YES n ; } int main(void) { ios_b... |
#include <bits/stdc++.h> using namespace std; string mapp[105]; int main() { int n, m; cin >> n >> m; for (int i = 0; i < n; i++) cin >> mapp[i]; int sx = 0x3f3f3f3f, sy = 0x3f3f3f3f, ex = 0, ey = 0, cnt = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if (mapp[i]... |
#include <bits/stdc++.h> using namespace std; int v, s, vs, sv; void printAns() { cout << vier: << v << sieben: << s << vs: << vs << sv: << sv << endl; } int main() { cin >> v >> s >> vs >> sv; string ans = ; bool flag = true; if (v < vs || s < vs || v < sv || v <... |
#include <bits/stdc++.h> using namespace std; inline long long GCD(long long a, long long b) { while (b != 0) { int t = a; a = b; b = t % b; } return a; } inline long long LCM(long long a, long long b) { if (a == 0 || b == 0) return GCD(a, b); return a * b / GCD(a, b); } ... |
#include <bits/stdc++.h> using namespace std; const int maxn = 205; int mat[maxn][maxn], tmp[maxn][maxn]; int r[maxn], c[maxn]; int n, m; void invRow(int row) { for (int j = 1; j <= m; ++j) { tmp[row][j] ^= 1; } } void invCol(int col) { for (int i = 1; i <= n; ++i) { tmp[i][col] ... |
#include <bits/stdc++.h> using namespace std; int main() { string a, b; cin >> a >> b; long long n, m, i, j, k = 200000; n = a.size(); m = b.size(); for (i = 1; i <= k; i++) { if (n - i >= 0 && m - i >= 0) { if (a[n - i] != b[m - i]) break; } else break; } ... |
#include <bits/stdc++.h> using namespace std; const int MAX = 500004; long long p, pos1, pos2, q, x, l, ans = 0, r, y, z, k, n, m, t, d, c = 0, sum = 0; long long int mn = 0x3f3f3f3f, len, cnt = 1, mx = -1000; std::vector<int> v[MAX]; string s[10004], s1, s2; int main()... |
#include <bits/stdc++.h> using namespace std; long a, b, c, n, res; int main() { cin >> a >> b >> c >> n; long s[n + 1]; for (long i = 1; i <= n; ++i) { cin >> s[i]; if (s[i] > b && s[i] < c) res++; } cout << res; return 0; } |
#include <bits/stdc++.h> using namespace std; long long int powermod(long long int B, long long int P, long long int M) { long long int r = 1; if (B >= M) B %= M; while (P > 0) { if ((P & 1) == 1) { r *= B; if (r >= M) r %= M; } P >>= 1; B *= B; if (B >= M) ... |
#include <bits/stdc++.h> using namespace std; template <typename X, typename Y> static inline void xmin(X &x, Y y) { if (y < x) x = y; } template <typename X, typename Y> static inline void xmax(X &x, Y y) { if (x < y) x = y; } long long pw(long long x, long long y, long long md) { if (!y) r... |
#include <bits/stdc++.h> using namespace std; bool hell(vector<int>& v1, vector<int>& v2) { return v1.size() < v2.size(); } int main() { int n; cin >> n; vector<vector<int> > f(100); int a[2 * n + 1]; for (int i = 1; i <= 2 * n; i++) { cin >> a[i]; f[a[i]].push_back(i); } i... |
#include <bits/stdc++.h> using namespace std; int n, v; int main() { cin >> n >> v; int ans = 0; int p = 1; int cur = 0; for (int i = n - 1; i >= 0; i--, p++) { if (cur >= i) continue; ans += p * (min(i, v - cur)); cur = cur + min(i, v - cur) - 1; } cout << ans << end... |
#include <bits/stdc++.h> using namespace std; const long long MAXN = 810, maxn = 200010; long long n, m, k, top, cnt, num; struct wy { long long x, y, z; } t[maxn]; inline long long cmp(wy a, wy b) { return a.z < b.z; } long long b[MAXN], c[MAXN], a[MAXN][MAXN], w[maxn]; inline void discrete() { ... |
#include <bits/stdc++.h> using namespace std; int main() { string n; int k = 0; cin >> n; if (n[0] <= Z ) { for (int i = 0; i < n.size(); i++) { if (n[i] <= Z ) k++; } if (k == n.size()) { transform(n.begin(), n.end(), n.begin(), (int (*)(int))tolower); co... |
#include <bits/stdc++.h> int main() { int tp, x, ans; while (~scanf( %d , &x)) { x = x < 0 ? -x : x, ans = ceil((-1 + sqrt(1 + 8.0 * x)) / 2), tp = ans * (ans + 1) / 2 - x; while (tp & 1) ans++, tp += ans; printf( %d n , ans); } return 0; } |
#include <bits/stdc++.h> using namespace std; int main() { { int t; cin >> t; long long int a[t]; for (int i = 0; i < t; i++) { cin >> a[i]; if (a[i] % 2 == 0 && a[i] != 0) cout << a[i] - 1 << ; else cout << a[i] << ; } } re... |
#include <bits/stdc++.h> using namespace std; int T, a[260]; int main() { scanf( %d , &T); while (T--) { int s = 0; int ct = 0; for (int i = 0; i < 250; i++) { scanf( %d , &a[i]); s += a[i]; } double ave = s / 250.0; for (int i = 0; i < 250; i++) { ... |
#include <bits/stdc++.h> using namespace std; int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); } int main() { int a, b; while (scanf( %d%d , &a, &b) != EOF) { int g = gcd(a, b); int x = -1, y = -1; for (int dx = 1; dx <= 1000; ++dx) for (int dy = 1; dy <= 1000; ++dy) ... |
#include <bits/stdc++.h> using namespace std; char str[200005]; int arr[200005]; int cum[200005]; int main() { scanf( %s , &str); int n = strlen(str); int q, idx; scanf( %d , &q); while (q--) { scanf( %d , &idx); int l = idx, r = n - idx + 1; arr[l]++; arr[r + 1]--;... |
#include <bits/stdc++.h> using namespace std; int main() { long int n, m; cin >> n; cin >> m; char str[2002][2002]; long int A[10002][2]; long int cnt = 0; long int i, j; for (i = 0; i < n; i++) { cin >> str[i]; for (j = 0; j < m; j++) { if (str[i][j] == w ) { ... |
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1); int n, ans = 0; int b[1000001]; int num; void dfs(int u, int d) { if (u == n) { num = min(num, ans); return; } if (abs(b[u] - b[u - 1] - d) > 1) return; int d1 = b[u] - b[u - 1]; if (d1 < d) { b[u... |
#include <bits/stdc++.h> using namespace std; void DBG() { cerr << endl; } template <class Head, class... Tail> void DBG(Head H, Tail... T) { cerr << << H; DBG(T...); } using ll = long long; using ld = long double; template <class T> using vec = vector<T>; template <class... Args> inli... |
#include <bits/stdc++.h> using namespace std; const long long inf = LONG_MAX; const long long arr = 1000000; bool comp(pair<string, long long> a, pair<string, long long> b) { return a.second > b.second; } int main(void) { long long n; cin >> n; vector<pair<long long, long long> > v; for ... |
#include <bits/stdc++.h> using namespace std; const long long Mod = 7 + 1e9; const long long INF32 = 5 + 2e9; const long long INF64 = 1 + 1e18; const long long MAX = 5 + 3e5; int N, M, ans = 4; int main() { cin >> N >> M; for (int i = 1; i <= N; i++) for (int j = 1; j <= M; j++) { bo... |
#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; const int mod = (int)1e9 + 7; long long int pow(long long int base, long long int exp, int m) { if (exp == 0) return 1; else if (exp == 1) return base; long long int root = pow(base, exp >> 1, m); if ((exp & 1) == 0) return (root * ro... |
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; vector<int> v(n); for (int i = 0; i < n; i++) cin >> v[i]; int mn = INT_MAX; int cnt = 0; for (int i = n - 1; i >= 0; i--) { if (v[i] > mn) cnt++; ... |
#include <bits/stdc++.h> using namespace std; template <typename T, typename U> std::istream& operator>>(std::istream& i, pair<T, U>& p) { i >> p.first >> p.second; return i; } template <typename T> std::istream& operator>>(std::istream& i, vector<T>& t) { for (auto& v : t) { i >> v; }... |
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 5; int n, m; int a[maxn]; int b[maxn]; int ans[maxn]; int main() { cin >> n >> m; int num = 0; for (int i = 0; i < m; i++) { scanf( %d , a + i); if (b[a[i]] == 0) num++; b[a[i]]++; if (num == n) { ... |
#include <bits/stdc++.h> using namespace std; mt19937 myrand(time(0)); bool isprime(long long n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; for (long long i = 5; i * i <= n; i += 6) { if (n % i == 0 || n % (i + 2) == 0) return false; ... |
#include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int, int>; template <typename... T> void rd(T&... args) { ((cin >> args), ...); } template <typename... T> void wr(T... args) { ((cout << args << ), ...); cout << endl; } int main() { ios::sync_wi... |
#include <bits/stdc++.h> using namespace std; int main() { string x; cin >> x; int sum = 0, s; s = x.size(); for (int i = 0; i < x.size(); i++) { if (x[i] == x[s - i - 1] && (x[i] == A || x[i] == H || x[i] == I || x[i] == M || x[i] == O || x[i] == T || x[i]... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); vector<long long> v; long long last; int q, a, b, lo, hi, one, two; long double aa, bb; cin >> q; cout << fixed; cout << setprecision(6); while (q--) { cin >> a; ... |
#include <bits/stdc++.h> using namespace std; long long int n; int main() { cin >> n; long long int cnt = 0, c; for (long long int i = 2; i <= sqrt(n); i++) { if (n % i == 0) cnt++; } if (cnt == 0) { cout << n; goto skip; } for (long long int i = 2; i <= sqrt(n); i++)... |
#include <bits/stdc++.h> template <typename T> T gcd(T a, T b) { if (!b) return a; return gcd(b, a % b); } template <typename T> T lcm(T a, T b) { return a * b / gcd(a, b); } template <typename T> void chmin(T& a, T b) { a = (a > b) ? b : a; } template <typename T> void chmax(T& a,... |
#include <bits/stdc++.h> using namespace std; int add(int x, int y) { return ((x + y) % 998244353 + 998244353) % 998244353; } int mul(int x, int y) { return (long long)x * y % 998244353; } int mypow(int x, int c) { int ret = 1; while (c > 0) { if (c & 1) { ret = mul(ret, x); } ... |
#include <bits/stdc++.h> using namespace std; void solve() { long long a, b; cin >> a >> b; if (b / 2 >= a) cout << (b % (b / 2 + 1)); else cout << b % a; cout << n ; return; } signed main() { ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); srand(time(NUL... |
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 15; const int M = 20; bool used[N]; vector<int> adj[N]; int a[N], b[N], w[N]; int out[N]; int dsu[N]; int f(int x) { return dsu[x] == x ? x : dsu[x] = f(dsu[x]); } bool merge(int id) { int u = f(a[id]), v = f(b[id]); if (u != ... |
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[n]; for (int i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); cout << a[(n - 1) / 2] << endl; return 0; } |
#include <bits/stdc++.h> using namespace std; const int MOD = 1000000007; int n, p[1002]; long long f[1002][2]; int main() { int i; scanf( %d , &n); for (i = 1; i <= n; i++) scanf( %d , &p[i]); f[1][1] = 0; f[1][0] = 1; for (i = 2; i <= n + 1; i++) { f[i][1] = (f[i - 1][0] + 1) %... |
#include<bits/stdc++.h> using namespace std; typedef long long int ll; #define MAX 2000000000 vector<ll> feaseable; void setfun(){ for(ll i = 3; i<MAX; i+=2){ ll sq = i * i; if(sq>MAX){ break; } ll c = (sq + 1)/2; feaseable.push_back(c); ... |
#include <bits/stdc++.h> using namespace std; int main() { long n, k, a; cin >> n >> k >> a; long n_moves; cin >> n_moves; set<pair<long, long> > s; s.insert(make_pair(n, 1)); long max_ships = (n + 1) / (a + 1); for (int i = 1; i <= n_moves; i++) { long x; cin >> x; ... |
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) #pragma GCC target( avx,avx2,fma ) #pragma GCC optimization( unroll-loops ) using namespace std; int parent[150000]; int size[150000]; long long int edges[150000]; struct dsu { void init(int n) { for (int i = 0; i < n; ++i) { paren... |
#include <bits/stdc++.h> using namespace std; const int mod = 100000007; const int M = 100005; const double pi = acos(-1); struct pt { long long x, y, EWGDFGdfgfsdhfdshfdhf; bool operator<(const pt &a) const { return (x < a.x); } bool operator>(const pt &a) const { return (x > a.x); } }; long ... |
#include <bits/stdc++.h> using namespace std; const int maxn = 100 + 10; char s[maxn][maxn]; int main() { int a, b; for (int i = 0; i < 11; i++) gets(s[i]); scanf( %d%d , &a, &b); int r = (a - 1) % 3, c = (b - 1) % 3; int flag = 0; for (int i = r * 3 + r; i < (r + 1) * 3 + r; i++) { ... |
#include <bits/stdc++.h> using namespace std; int main() { char arr[100][100]; int m, n, k = 0; cin >> n >> m; for (int i = 0; i < n; i++) { cin >> arr[i]; } if (m == 1 || n == 1) { cout << 0; return 0; } for (int i = 0; i < n - 1; i++) { for (int j = 0; j < m... |
#include <bits/stdc++.h> using namespace std; int main() { int m, n, count = 0, count1 = 0, x = 0; cin >> m >> n; int a[m][n], b[m][n]; for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { cin >> b[i][j]; a[i][j] = 1; } } for (int i = 0; i < m; i++) { ... |
#include <bits/stdc++.h> using namespace std; long long int getLength(long long int x) { long long int c = 0; while (x > 0) { c++; x /= 10; } return c; } int main() { long long int n, k, i, j; cin >> n >> k; long long int a[n], lengths[n]; for (i = 0; i < n; i++) { ... |
#include <bits/stdc++.h> using namespace std; long long int eet(long long int a, long long int b, long long int *x, long long int *y) { if (a == 0) { *x = 0; *y = 1; return b; } long long int x1, y1; long long int gcd = eet(b % a, a, &x1, &y1); *x = y1 - (b ... |
#include <bits/stdc++.h> using namespace std; long long ans; vector<long long> all, aa, bb; int main() { aa.clear(); bb.clear(); all.clear(); long long a, b; cin >> a >> b; ans = 2 * (a + b + 1); for (long long i = 1; i * i <= (a + b); i++) if ((a + b) % i == 0) all.push_back(i... |
#include <bits/stdc++.h> using namespace std; int n, d; int v[50 + 5]; bool F[5000000 + 5]; int main() { scanf( %d%d , &n, &d); for (int i = 1; i <= n; i++) scanf( %d , &v[i]); F[0] = true; int sum = 0; for (int i = 1; i <= n; i++) { sum += v[i]; for (int j = sum; j >= v[i]; j-... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.