func_code_string stringlengths 59 71.4k |
|---|
#include <bits/stdc++.h> using namespace std; pair<int, int> sorted_pair(int x, int y) { if (x > y) { return pair<int, int>(y, x); } else { return pair<int, int>(x, y); } } int main() { int n; cin >> n; vector<vector<int>> graph(n + 1, vector<int>()); set<pair<int, int>> ... |
#include <bits/stdc++.h> using namespace std; struct quad { pair<int, int> points[4]; void read() { for (int i = 0; i < 4; i++) { cin >> points[i].first >> points[i].second; } } int cross(int a, int b, int c, int d) { return a * d - b * c; } int sgn(int x) { if (x < 0) ... |
#include <bits/stdc++.h> const int N = 2000010; using namespace std; char s[N], t[N]; int main() { int n; scanf( %d , &n); scanf( %s%s , s, t); int a[5] = {}; for (int i = 0; i < 2 * n; i++) { a[((s[i] == 1 ) << 1) | (t[i] == 1 )]++; } int s0 = 0, s1 = 0; int t = 0; w... |
#include <bits/stdc++.h> using namespace std; int main() { long long m, n; cin >> m >> n; double sum; sum = m; for (double i = m - 1; i > 0; i--) { sum -= pow(i / m, n); } cout << fixed; cout << setprecision(12) << sum << n ; return 0; } |
#include <bits/stdc++.h> using namespace std; const int maxn = 100007, dx[8] = {1, 1, 1, 0, 0, -1, -1, -1}, dy[8] = {1, 0, -1, 1, -1, 1, 0, -1}; int xs, ys, xt, yt, n, r[maxn], a[maxn], b[maxn], d[maxn] = {}, cnt = 0; bool vis[maxn] = {}; vector<int> row, col[maxn]; vector<pair<int, int> > seg[m... |
#include <bits/stdc++.h> using namespace std; int main() { int t, i, j, c = 0, d = 0, a, b, k = 0, sum = 0, sum1 = 0; cin >> t; string s; stack<char> st; cin >> s; for (i = 0; i < s.size(); i++) { if (s[i] == ( ) { sum++; } else { sum1++; } if (s[i] =... |
#include <bits/stdc++.h> using namespace std; inline int nxt() { int x; scanf( %d , &x); return x; } int main() { mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); int n = nxt(); vector<int> a(n); for (int i = 0; i < n; ++i) { a[i] = nxt(); } int s = ... |
#include <bits/stdc++.h> using namespace std; int main() { size_t found; vector<string> str; string a, b, c, in, out; long long i, j, k, m, n, l, t; cin >> t; while (t--) { cin >> in; for (i = 0, j = 0, k = 0; i < in.size(); i++) { if (in[i] == : && i == 0) { ... |
#include <bits/stdc++.h> using namespace std; const int MaxN = 100000 + 5; int N; map<int, int> Numbers; int main(void) { scanf( %d , &N); if (N % 2) { printf( NO n ); return 0; } for (int i = 0; i < N; i++) { int Number; scanf( %d , &Number); Numbers[Number]++; ... |
#include <bits/stdc++.h> using namespace std; int main() { int a, b, i, c = 1; cin >> a >> b; if (b < a) a = b; for (i = 2; i <= a; i++) c *= i; cout << c << endl; } |
#include <bits/stdc++.h> using namespace std; int main() { int n, a, b, c, d, l = 1, v[1001]; cin >> n; for (int i = 0; i < n; i++) { cin >> a >> b >> c >> d; v[i] = a + b + c + d; if (v[0] < v[i]) l++; } cout << l; return 0; } |
#include <bits/stdc++.h> using namespace std; const int N = 100 * 1000 + 5; int n, m, cnt; short int mark[N]; bool visited[N]; vector<int> in[N], out[N], comp[N]; void input() { cin.tie(0); cin >> n >> m; int v, u; for (int i = 0; i < m; i++) { cin >> v >> u; v--, u--; ou... |
#include <bits/stdc++.h> using namespace std; using namespace std; long long n, m, f, t, d, val; vector<long long> a, c; set<pair<long long, long long> > s; int main() { cin.tie(0); cout.tie(0); ios::sync_with_stdio(0); cin >> n >> m; a.resize(n); c.resize(n); for (auto& i : a) c... |
#include <bits/stdc++.h> using namespace std; inline long long read() { register long long w = 1, x = 0, ch = getchar(); for (; ch < 0 || ch > 9 ; ch = getchar()) if (ch == - ) w = -1; for (; ch >= 0 && ch <= 9 ; ch = getchar()) x = x * 10 + ch - 0 ; return x * w; } const long long... |
#include <bits/stdc++.h> using namespace std; long long dp[20]; int main() { memset(dp, 0, sizeof(dp)); long long n, i, dig; cin >> dig; cin >> n; while (n != 0) { long long r = n % 10; if (r == 0 || r == 1) { n = n / 10; continue; } if (r >= 9) dp[3] +=... |
#include <bits/stdc++.h> #pragma gcc optimize( Ofast ) using namespace std; inline void input(int &_x) { _x = 0; int _tmp = 1; char _tc = getchar(); while ((_tc < 0 || _tc > 9 ) && _tc != - ) _tc = getchar(); if (_tc == - ) _tc = getchar(), _tmp = -1; while (_tc >= 0 && _tc <= 9 ) ... |
#include <bits/stdc++.h> using namespace std; int main() { int n, k = 100000000, t; cin >> n; int a[n]; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 1; i < n; i++) { t = max(a[i - 1], a[i]); k = min(t, k); } cout << min(min(a[0], a[n - 1]), k); return 0; } |
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); int ar1[100], ar2[100]; memset(ar1, 0, sizeof(ar1)); memset(ar2, 0, sizeof(ar2)); string s1, s2; cin >> s1 >> s2; int t; cin >> t; vector<pair<pair<int, char>, pair<int, char> > > v(t); fo... |
#include <bits/stdc++.h> using namespace std; const int arrmax = 200005; char str[arrmax]; int reversetimes[arrmax / 2]; int main() { int m, a, sum, len; while (~scanf( %s %d , str, &m)) { len = strlen(str); memset(reversetimes, 0, 2 * len); while (m--) { scanf( %d , &a); ... |
#include <bits/stdc++.h> using namespace std; int n, m; string res[101]; int dx[] = {0, 0, -1, 1}; int dy[] = {-1, 1, 0, 0}; inline bool in(int x, int y) { if (x < 0 || y < 0 || x >= n || y >= m) return 0; return 1; } int main(int argc, char **argv) { cin >> n >> m; for (int i = 0; i <= ... |
#include <bits/stdc++.h> using namespace std; int x, y, a, b, c, ans; int main() { cin >> x >> y; if (x > y) swap(x, y); a = b = c = x; while (true) { a = b + c - 1; ans++; if (a >= y) break; b = a + c - 1; ans++; if (b >= y) break; c = a + b - 1; an... |
#include <bits/stdc++.h> using namespace std; long long n, a[500011], L[500011], R[500011], aL[500011], aR[500011], ans[500011]; int32_t main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n; for (long long i = 1; i <= n; i++) cin >> a[i]; stack<pair<long long, long long> > st; for ... |
#include <bits/stdc++.h> using namespace std; int main() { long long int n; string s; cin >> n; cin >> s; map<char, long long int> M; long long int i; for (i = 0; i < n; i++) { M[s[i]]++; } long long int z = n / 3; if (M[ 0 ] < z) { for (i = 0; i < n; i++) { ... |
#include <bits/stdc++.h> using namespace std; int n; char buf[100], name[100], op[100], tmp[100]; struct widget { long long x, y; bool finish; int type, border, spacing; vector<int> w; widget(long long xx = 0, long long yy = 0, int t = 0) { x = xx; y = yy; type = t; w... |
#include <bits/stdc++.h> using namespace std; int main() { int n, a[5], sum = 0; for (int i = 0; i < 5; i++) { cin >> a[i]; sum += a[i]; } n = sum / 5; if (sum == 0) cout << -1; else if (n * 5 == sum) cout << n; else cout << -1; return 0; } |
#include <bits/stdc++.h> using namespace std; bool b[150000] = {0}; bool dfs(int n, vector<set<int>>& v) { b[n] = 1; for (auto itr = v[n].begin(); itr != v[n].end(); itr++) { if (!b[*itr]) if (v[n] != v[*itr]) return 0; if (!b[*itr]) dfs(*itr, v); } return 1; } int main() {... |
#include <bits/stdc++.h> using namespace std; const int maxn = 3 * 1e5 + 10, maxm = (1 << 17), mod = 1e9 + 7; const double PI = 3.14159265359; vector<int> g[maxn]; int d[maxn]; bool r[maxn]; set<int> s; int main() { ios::sync_with_stdio(0); int n, a, b, m; cin >> n >> m; for (int i = 0; ... |
#include <bits/stdc++.h> using namespace std; struct node { int t, d, p, id; } s[110]; int dp[2010]; vector<int> v[2010]; int cmp(node a, node b) { return a.d < b.d; } int main() { int n; scanf( %d , &n); for (int i = 1; i <= n; i++) { scanf( %d%d%d , &s[i].t, &s[i].d, &s[i].p), s[i]... |
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> a; int cnt = 0; int sum = 0; for (int i = 0; i < 2 * n - 1; ++i) { int x; cin >> x; a.push_back(abs(x)); if (x < 0) cnt++; sum += abs(x); } cnt %= n; queue<int> q... |
#include <bits/stdc++.h> using namespace std; int main(int argc, char **argv) { ios_base::sync_with_stdio(false); cin.tie(0); int m, n; cin >> n >> m; vector<string> s(n); vector<pair<int, int>> t(n, {-1, -1}); for (int i = 0; i < n; i++) cin >> s[i]; bool ok = true; for (int i =... |
#include <bits/stdc++.h> using namespace std; using ii = pair<int, int>; using vi = vector<int>; using vvi = vector<vi>; using vii = vector<ii>; using vb = vector<bool>; using ll = long long; template <typename A, typename B> istream &operator>>(istream &in, pair<A, B> &p) { in >> p.first >> p.sec... |
#include <bits/stdc++.h> using namespace std; bool fun(int x, int y) { return x > y; } int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); ; int n, s; cin >> n >> s; if (s <= n) { cout << 1 << n ; } if (s > n && s % n == 0) { cout << s / n <<... |
#include <bits/stdc++.h> using namespace std; template <class T> ostream& operator<<(ostream& os, vector<T> V) { os << [ ; for (auto v : V) os << v << ; return os << ] ; } template <class T> ostream& operator<<(ostream& os, set<T> S) { os << { ; for (auto s : S) os << s << ; ... |
#include <bits/stdc++.h> using namespace std; long double ans; long long one, two; map<pair<long long, long long>, pair<long long, long long> > o, t; map<pair<long long, long long>, pair<long long, long long> >::iterator ii; void add(long long a, long long b, long long c, long long ind) { pair<long long... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t; cin >> t; for (int i = 0; i < t; ++i) { int n, a[150000]{}; cin >> n; for (int j = 0; j < n; ++j) { cin >> a[j]; } int min = a[n - 1], cnt = 0;... |
#include <bits/stdc++.h> using namespace std; int n, m; long long k; long long a[21][21]; map<long long, int> mp[21][21]; int Color[21][21]; queue<pair<int, int>> q; void BFS(int x, int y, int depthMax, vector<pair<int, int>> d) { Color[x][y] = 1; mp[x][y][a[x][y]] = 1; q.push(make_pair(x, y... |
#include <bits/stdc++.h> using namespace std; int n, m, a, b[101]; void read() { int c, d, k = 0; cin >> n >> m; for (int i = 1; i <= n; i++) cin >> a, b[i] = a + b[i - 1]; for (int i = 0; i < m; i++) { cin >> c >> d; k += (b[d] - b[c - 1] > 0 ? b[d] - b[c - 1] : 0); } cout << ... |
#include <bits/stdc++.h> using namespace std; const long double eps = 1e-9; const long double pi = acos(-1.0); const int inf = 1e+9; long long gcd(long long a, long long b) { return (b == 0) ? a : gcd(b, a % b); } int xabs(int a) { return a >= 0 ? a : -a; } int sign(int a) { return (a < 0) ? -1 : 1; } i... |
#include <bits/stdc++.h> using namespace std; const double Pi = acos((double)-1); const double Eps = 1E-6; int read() { int $x; scanf( %d , &$x); return $x; } long long sqr(long long $x) { return $x * $x; } int x[100000], N, A, B; int main() { A = read(), B = read(); N = A + B + 1; ... |
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { if ((i + j) % 2) cout << W ; else cout << B ; } cout << endl; } } |
#include <bits/stdc++.h> const int N = 100010; char s[N], str[3][N]; int len; int solve(int type, int ret) { int ans = 0; memcpy(str[type], s, sizeof(s)); for (int i = len - 1; i >= 0; --i) { if ((str[type][i] - 0 ) % 3 == type) { str[type][i] = 0 ; ++ans; ret = (ret... |
#include <bits/stdc++.h> using namespace std; int main() { int h1, a1, c1, i; int h2, a2; scanf( %d%d%d%d%d , &h1, &a1, &c1, &h2, &a2); vector<int> v; while (true) { if (h1 - a2 <= 0 && h2 - a1 <= 0) { h1 -= a2; h2 -= a1; v.push_back(1); break; } else ... |
#include <bits/stdc++.h> using namespace std; struct edge { long long int A; long long int B; }; bool edgecompare(edge lhs, edge rhs) { if (lhs.B != rhs.B) return lhs.B < rhs.B; else return lhs.A < rhs.A; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ... |
#include <bits/stdc++.h> using namespace std; int main() { vector<int> times; int n, k; cin >> n >> k; for (int i = 0; i < n; ++i) { int x; cin >> x; times.push_back(x); } int ans = 0; for (int i = 1; i < n; ++i) { if (times[i] + times[i - 1] < k) { ans +=... |
#include<iostream> #include<string.h> #include <fstream> #include <string> #include <vector> #include <iomanip> #include <cmath> #include <cstdlib> #include<map> #include <ctime> using namespace std; int main(){ long long int t; cin>>t; for(long long int mat=0;mat<t;mat=mat+1){ lon... |
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1.0); int main() { int n, r; cin >> n >> r; double deg = (1.0 / n) * pi; double bi = sin(deg); cout << setiosflags(ios::fixed) << setprecision(10) << (bi / (1 - bi) * r) << endl; return 0; } |
#include <bits/stdc++.h> using namespace std; struct ghost { long long vx, vy; long long magic; ghost(long long x, long long y, long long a) : vx(x), vy(y), magic((long long)a * x - y) {} }; bool cmp1(const ghost& x, const ghost& y) { return x.magic < y.magic; } bool cmp2(const ghost& x, c... |
#include <bits/stdc++.h> using namespace std; struct problem { long long ts, tl, ss, sl, p; } pro[1005]; pair<long long, double> f[1005][1566]; int n, t; bool cmp(problem a, problem b) { return a.tl * a.p * (1000000 - b.p) < b.tl * b.p * (1000000 - a.p); } bool better(pair<long long, double> &a,... |
#include <bits/stdc++.h> using namespace std; bool Check(long long n, long long pos) { return (n & (1 << pos)); } long long Set(long long n, long long pos) { return (n | (1 << pos)); } string s; long long n, mod; long long dp[(1 << 18) + 2][102]; long long call(long long mask, long long val) { if (mas... |
#include <bits/stdc++.h> using namespace std; int n, m; const int MAXN = 1000005; char a[MAXN], b[MAXN]; int mi[MAXN], ma[MAXN]; long long ans = 0; int trs(char a, char b) { int s = 0; if (a == R ) s += 6; else if (a == B ) s += 3; if (b == R ) s += 2; else if (b =... |
#include <bits/stdc++.h> using namespace std; template <class T, class L> bool smax(T &x, L y) { return x < y ? (x = y, 1) : 0; } template <class T, class L> bool smin(T &x, L y) { return y < x ? (x = y, 1) : 0; } const int maxn = 20, maxm = 1e5 + 17; char c[maxm]; int n, m, col[maxm]; int... |
#include <bits/stdc++.h> using namespace std; int main() { int i, n, l, k = 0, maxi; scanf( %d , &n); long long int count = 0; int a[15]; l = n; while (l) { a[k] = l % 10; l = l / 10; k++; } while (k > 0) { maxi = 0; for (i = 0; i < k; i++) if (a... |
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 1e4; int a[maxn], mod; int b[maxn]; int n; int pow(int a, int b) { if (b == 1) return a; int t = pow(a, b >> 1); t = 1LL * t * t % mod; if (b & 1) t = 1LL * t * a % mod; return t; } int ny(int a) { return pow(a, mod... |
#include <bits/stdc++.h> using namespace std; const int N = (int)2e5 + 5; int seg[N], ans[N]; vector<pair<int, int> > beg[N], fin[N]; set<pair<int, int> > pending; set<pair<int, int> >::iterator it1, it2; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, m; cin >> n >> m; fo... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long int t; cin >> t; while (t--) { long long int n, m, a, b; cin >> n >> m >> a >> b; long long int arr[n + 5][m + 5]; long long int i, j;... |
#include <bits/stdc++.h> const int maxn = 200005, maxm = maxn << 1; int n, m, e, s1, s2, s, maxx, col, flg, mid; int start[maxn], to[maxm], then[maxm], dep[maxn], f[maxn], ans[maxn], flen[maxn], slen[maxn]; inline void add(int x, int y) { then[++e] = start[x], start[x] = e, to[e] = y; } void dfs(int x, ... |
#include <bits/stdc++.h> using namespace std; int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); } const int MAXN = 100000; int n, mxdepth, MOD; int INV2; int inv[2 * MAXN + 1]; vector<int> parts; void rec(int l, int r, int h) { if (l > r) return; if (h == 1 || l == r) { parts.push... |
#include <bits/stdc++.h> using namespace std; const int maxn = 100; int a[maxn], s[maxn], f[maxn], n, ans; int pmin, pmax; int main() { scanf( %d , &n); for (int i = 0; i < n; i++) scanf( %d , a + i), f[i] = -1; sort(a, a + n); swap(a[0], a[n - 1]); for (int i = 0; i < n; i++) printf( %d ... |
#include <bits/stdc++.h> using namespace std; int a[10]; int main() { for (int i = 1; i <= 6; i++) cin >> a[i]; cout << (a[1] + a[2] + a[3]) * (a[1] + a[2] + a[3]) - a[1] * a[1] - a[3] * a[3] - a[5] * a[5]; return 0; } |
#include <bits/stdc++.h> using namespace std; const int NMAX = 210, INF = 0x3f3f3f3f, VMAX = 20010; int N, A[NMAX], Source, Sink, Flow[NMAX][NMAX], Cap[NMAX][NMAX], Father[NMAX], Even, Odd; bool Used[NMAX], Prime[VMAX]; vector<int> G[NMAX], FlowG[NMAX], CurrentTable; vector<vector<int> > Ans; bool B... |
#include <bits/stdc++.h> const double eps = 1e-3; const double PI = 3.1415926535897932384626433832795; const int maxn = 9999999; using namespace std; char name[1001][40]; int grade[1001]; int main() { int n; while (~scanf( %d , &n)) { map<string, int> mp; for (int i = 1; i <= n; i++) {... |
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define all(x) (x).begin(), (x).end() typedef vector<bool> vb; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<vector<bool>> vvb; typedef vector<vector<int>> vvi; typedef vector<vector<ll>> vvl; typedef pair<int,int... |
#include <bits/stdc++.h> int main() { int n, k, i, j; int hols, arr[1000]; int temp, loop, flag = 0; scanf( %d%d , &n, &k); scanf( %d , &hols); for (i = 0; i <= n; i++) { arr[i] = 0; } for (i = 0; i < hols; i++) { scanf( %d , &temp); arr[temp] = 2; } for (i = ... |
#include <bits/stdc++.h> const double eps = 1e-9; const double pi = acos(-1); using namespace std; struct sx {}; bool cmp(int a, int b) { return a > b; } long long t1, t2, t3; int main() { int n, m; cin >> n >> m; int x = (n + m) / 3; while (t1 < x && ((n >= 1 && m >= 2) || (n >= 2 && m >=... |
#include <bits/stdc++.h> using namespace std; int main() { string str1, str2; cin >> str1 >> str2; for (int i = 0; i < str1.size(); i++) { str1[i] = tolower(str1[i]); str2[i] = tolower(str2[i]); } if (str1 == str2) cout << 0 ; else if (str1 < str2) cout << -1 ; ... |
#include <bits/stdc++.h> using namespace std; int n, m; vector<int> v; set<int> g[100005]; vector<pair<int, int> > f; int main() { ios::sync_with_stdio(false); cin >> n >> m; for (int i = 1; i * i <= n; i++) { if (n % i == 0) { v.push_back(i); if (i * i != n && i != 1) v.pu... |
#include <bits/stdc++.h> using namespace std; using ull = unsigned long long; using ll = long long; using ld = long double; const int mod = 1e9 + 7; const double pi = acos(-1.0); const int inf = INT_MAX; const int N = (1 << 22); int h, g, a[N]; bool ok(int i) { while (true) { if (a[i << 1]... |
#include <bits/stdc++.h> using namespace std; int v[1000000]; int buggy_sorting(int n) { if (n == 1 || n == 2) return 0; v[0] = 5; v[1] = 6; v[2] = 1; for (int i = 3; i < n; i++) v[i] = i; return 1; } void median() { int t, n, k, pas, cnt; long long int s; cin >> t; for... |
#include <bits/stdc++.h> using namespace std; bool used[100001]; int ans[100001], a[100001]; int main() { int n; cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; if (a[i] <= n && !used[a[i]]) { used[a[i]] = 1; ans[i] = a[i]; } } int first = 1; for (... |
#include <bits/stdc++.h> using namespace std; inline int read() { int s = 0, f = 1; char ch = getchar(); while (ch < 0 || ch > 9 ) { if (ch == - ) f = -1; ch = getchar(); } while (ch >= 0 && ch <= 9 ) s = s * 10 + ch - 0 , ch = getchar(); return s * f; } const int max... |
#include <bits/stdc++.h> using namespace std; int main() { long long n, k, p, d, x; cin >> n >> k >> d; p = n - k; for (int i = 0; i < d; i++) { cin >> x; x--; if (p <= k) { if (x % 2 == 0 && x / 2 < p) { cout << . ; } else { cout << X ; ... |
#include <bits/stdc++.h> using namespace std; void solve() { long long int n; cin >> n; string s; vector<long long int> arr(n + 1); for (long long int i = 1; i <= n; i++) cin >> arr[i]; cin >> s; vector<long long int> pre(n, 0); if (s.back() == 1 ) pre[n - 1] = 1; for (int i = n... |
#include <bits/stdc++.h> using namespace std; unsigned char G[301][301]; unsigned char bv[301]; int ints[301]; int main() { int n; cin >> n; for (register int i = 1; i <= n; i++) cin >> ints[i]; for (register int i = 1; i <= n; i++) { for (register int j = 1; j <= n; j++) { char ... |
#include <bits/stdc++.h> #pragma GCC optimize(2) using namespace std; const int INF = 0x3f3f3f3f; const long long MOD = 1e9 + 7; long long n, sum[100002][2], sqsum[100002][2], cnt[100002][2], all_7[100002], s[100002], ten[200002]; long long solve(string str) { n = str.length(); memset(all_7, 0... |
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); long long n, i, j, x, k; cin >> n >> k; string s, t; cin >> s; t = s; for (i = 0; i < n; i++) { if (i - k >= 0) t[i] = t[i - k]; } if (t > s) { cout << n << n <<... |
#include <bits/stdc++.h> using namespace std; void err(istream_iterator<string> it) { cerr << endl; } template <typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cerr << *it << = << a << endl; err(++it, args...); } const int N = 1000 + 5, mod = 1000000007; ... |
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { long long int n, r, an; cin >> n >> r; if (r < n) an = (r) * (r + 1) / 2; else { an = (n) * (n - 1) / 2; an++; } cout << an; cout << n ; } }... |
#include <bits/stdc++.h> using namespace std; const int N = 2e5; int n; long long seg[4 * N], lazy[4 * N]; void update(int st, int en, long long v, int idx = 1, int L = 0, int R = n - 1) { if (L > en || R < st) { return; } if (L >= st && R <= en) { seg[idx] += v; la... |
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf( %d , &n); bool val = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { int a; scanf( %d , &a); if (i == j) { val ^= a; } } } int q; scanf( %d , &q);... |
#include <bits/stdc++.h> using namespace std; const long long BINF = 1e18 + 10; signed main() { ios_base::sync_with_stdio(false); long long T; cin >> T; while (T--) { long long n, a, b; cin >> n >> a >> b; vector<long long> c(n); for (auto &it : c) { char kek; ... |
#include <bits/stdc++.h> using namespace std; int N; typedef struct Nodo { long long int v, l; } Nodo; int S; Nodo segtree[2000024]; inline void st_init(int N) { if (__builtin_popcount(N) <= 1) { S = N; } else { for (; __builtin_popcount(N) > 1; N -= N & -N) ; S = N <... |
#include <bits/stdc++.h> using namespace std; const long long MOD = (long long)1e9 + 7; const long double PI = 3.141592653589793238462643383279502884197; priority_queue<int, vector<int>, greater<int> > pq; vector<int> v; int cnt[512]; pair<int, int> vec[512]; pair<int, int> sec[512]; int main() { ... |
#include <bits/stdc++.h> using namespace std; int N, K; struct Level { int lo[10 + 5], hi[10 + 5], sz; bool operator<(const Level &l) const { for (int i = 0; i < K; i++) { if (hi[i] >= l.lo[i]) return false; } return true; } }; Level s[50000 + 5]; set<Level> ps; void ... |
#include <bits/stdc++.h> using namespace std; int arr[100005], lazy[4 * 100005], num, value; bool flag; struct Node { int maxi, mini, one, two; } tree[4 * 100005]; Node merge(Node a, Node b) { Node temp; int num = max(a.maxi, b.maxi); temp.maxi = num, temp.one = num == a.maxi ? a.one : b.one... |
#include <bits/stdc++.h> using namespace std; const int N = 50; int x[N][N], y[N], True[N], False[N], ans; int n, m; bool flag = false; void dfs(int pos) { if (pos > n) { ans++; return; } bool f = true; for (int i = 1; i <= m; i++) { if (!x[i][pos]) True[i]++; ... |
#include <bits/stdc++.h> using namespace std; const int N = 300010, mod = 998244353; int a[N]; int n; int fac[N], inv[N]; inline int add(int a, int b) { return a + b >= mod ? a + b - mod : a + b; } inline int del(int a, int b) { return a < b ? a - b + mod : a - b; } inline int mul(int a, int b) { return... |
#include <bits/stdc++.h> using namespace std; vector<long long> return_digit(long long num) { vector<long long> arr; while (num != 0) { long long rem = num % 10; arr.push_back(rem); num /= 10; } return arr; } long long product_minmax(vector<long long> v) { long long max_val... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int t; cin >> t; while (t--) { int n, T, a, b; cin >> n >> T >> a >> b; vector<pair<int, int>> qstn(n); int totA = 0, totB = 0; for (auto& i : qstn) { cin >>... |
#include <bits/stdc++.h> using namespace std; int s[1000 * 1000]; int main() { int cnt = 1; for (int i = 1; i <= 1005; i++) { int t = i; int a[10]; int cnt1 = 1; while (t) { int tmp = t % 10; a[cnt1++] = tmp; t = t / 10; } for (cnt1--; cnt1; cnt1... |
#include <bits/stdc++.h> using namespace std; char a[100001]; int n, f = 1, x, ans; int main() { cin >> a; n = strlen(a); for (int i = 0; i < n; i++) { if (a[i] < 0 || a[i] > 9 ) { ans += x * f; x = 0; if (a[i] == - ) f = -1; if (a[i] == + ) f = 1; ... |
#include <bits/stdc++.h> using namespace std; void fast() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } void solve() { int n, m; cin >> n >> m; map<vector<int>, int> tiles; for (int i = 0; i < n; i++) { vector<int> temp; for (int j = 0; j < 4; j++) ... |
#include <bits/stdc++.h> using namespace std; long long ans; int n, m, k; long long C[1100][1100]; long long s1[1100][1100]; long long p[1100][1100]; long long f[1100100]; long long Pow(long long i, int x) { long long tmp = 1; while (x) { if (x & 1) tmp = tmp * i % (1000000007LL); i ... |
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; long long ar[n]; for (int i = 0; i < n; i++) cin >> ar[i]; int maxi = -1000000001; long long sum = 0; for (int i = 0; i < n; i++) { if (ar[i] > max... |
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int m = 1; while (m * (m - 1) <= 2 * n) m++; m = m - 1; cout << m << n ; int arr[m + 4][m + 3]; long long k = 1; for (int i = 0; i < m; i++) { long long count = 0; for (int j = i; j < m - 1;... |
#include <bits/stdc++.h> using namespace std; template <typename F, typename S> ostream &operator<<(ostream &os, const pair<F, S> &p) { return os << ( << p.first << , << p.second << ) ; } template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { os << { ; typename vecto... |
#include<bits/stdc++.h> using namespace std; #pragma region atcoder /*#include <atcoder/all> using namespace atcoder; //using mint = modint998244353; //using mint = modint1000000007;*/ #pragma endregion #pragma region macros using ll = long long; using pii = pair<int, int>; using pll = pair<ll, ll... |
#include <bits/stdc++.h> using namespace std; bool isPrime(long long n) { if (n <= 1) return false; for (int i = 2; i <= sqrt(n); i++) if (n % i == 0) return false; return true; } long long factorial(long long n) { if (n == 0) return 1; else return n * factorial(n - 1); }... |
#include <bits/stdc++.h> using namespace std; const int maxn = 2510; int sum[maxn][maxn]; char s[maxn][maxn]; int n, m, K; long long ans; int p1[10], p2[10]; int cal(int x1, int y1, int x2, int y2) { return sum[x2][y2] - sum[x1 - 1][y2] - sum[x2][y1 - 1] + sum[x1 - 1][y1 - 1]; } void div(int x1,... |
#include <bits/stdc++.h> using namespace std; long long n, s, h; string s2, s1; long long gw(long long n, long long x) { long long rs = 0; for (__typeof(n) i = (0) - ((0) > (n)); i != (n) - ((0) > (n)); i += 1 - 2 * ((0) > (n))) { for (__typeof(n) j = (0) - ((0) > (n)); j != (n) - ((0) > ... |
#include <bits/stdc++.h> using namespace std; long long n, k; int main() { cin >> n >> k; int ans = 1; while ((k & 1LL) == 0) { ++ans; k = k >> 1; } printf( %d n , ans); return 0; } |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.