func_code_string stringlengths 59 71.4k |
|---|
#include <bits/stdc++.h> using namespace std; const int OO = (int)1e9 + 7; const int mod = (int)1e9 + 7; const int MAX = (int)1e5 + 5; int main(void) { ios_base::sync_with_stdio(false); int n; while (cin >> n) { vector<pair<int, int> > h; for (int i = 0; i < n; i++) { int cur; ... |
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 5; const long long inf = 3e18; long long t, a[maxn], b[maxn], x[maxn]; long long l[maxn], r[maxn]; int n; int main() { scanf( %d%lld , &n, &t); for (int i = 1; i <= n; i++) scanf( %lld , a + i); for (int i = 1; i <= n; i++) s... |
#include <bits/stdc++.h> using namespace std; int main(int argc, char *argv[]) { long long n, k, a[55]; cin >> n >> k; for (int i = 1; i <= n; i++) cin >> a[i]; sort(a + 1, a + 1 + n); if (k > n) cout << -1 << endl; else { cout << a[n + 1 - k] << << a[n + 1 - k] << endl; ... |
#include <bits/stdc++.h> using namespace std; const int maxn = 10000; vector<int> nei[maxn]; bool mark[maxn]; vector<int> nei2[maxn]; bool markk[maxn]; int n, m, comp = 0, comp2 = 0; void dfs(int v) { mark[v] = true; for (int i = 0; i < nei[v].size(); i++) { int u = nei[v][i]; if (!m... |
#include <bits/stdc++.h> using namespace std; long long int binpow(long long int a, long long int b) { long long int res = 1; while (b > 0) { if (b & 1) res = res * a; a = a * a; b >>= 1; } return res; } void solve() { long long int n, k; cin >> n >> k; vector<long ... |
#include <bits/stdc++.h> using namespace std; long long pre[2010000]; int n, i, m, j, vis[2010000], la[2010000], lr[2010000], s[2010000], q[2010000], tr[2010000], a[2010000], tim, jid; inline int gi() { int s = 0; char c = getchar(); while (c < 0 || c > 9 ) c = getchar(); while (c >= 0... |
#include <bits/stdc++.h> using namespace std; const int N = 2005; long long dp[N], a[N]; int n, k, ans; bool check(long long x) { for (int i = 1; i <= n; i++) { dp[i] = i - 1; for (int j = 1; j < i; j++) { if (abs(a[i] - a[j]) <= (i - j) * x) { dp[i] = min(dp[i], dp[j] + (i -... |
#include <bits/stdc++.h> using namespace std; int N, V, M; int Size[310], Final[310], T[310]; vector<int> G[310]; vector<pair<pair<int, int>, int> > ANS; int source, sink, flow; void FindSource(int node) { if (Size[node] > Final[node]) { source = node; return; } for (vector<int>::i... |
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; int flag = 0, ans = 0; for (int i = 0; i < m; i++) { int k; cin >> k; set<int> check; flag = 1; for (int j = 0; j < k; j++) { int t; cin >> t; if (check.count(-t)... |
#include <bits/stdc++.h> using namespace std; template <class T> inline T Abs(const T& x) { return x < 0 ? -x : x; } template <class T> inline T Sqr(const T& x) { return x * x; } const int maxn = 110; const int maxk = 210; double a[maxn][maxn][maxk]; int n, k; int Get(int l, int r, int p... |
#include <bits/stdc++.h> using namespace std; int N, a[100010], b[100010], posA[100010]; multiset<int> S; int get(int x) { multiset<int>::iterator it = S.lower_bound(x), jt = it; return min(abs(*it - x), abs(*--jt - x)); } int main() { scanf( %d , &N); for (int i = 1; i <= N; i++) scanf( %d ... |
#include <bits/stdc++.h> using namespace std; double safe_sqrt(double x) { return sqrt(max((double)0.0, x)); } long long GI(long long& x) { return scanf( %lld , &x); } const long long MOD = 1e9 + 7; const long long MN = 1000111; long long gt[MN]; vector<long long> h[MN]; int main() { ios::sync_with_... |
#include <bits/stdc++.h> using namespace std; struct node { int x; int i; }; node a[300010]; int b[300010]; map<int, int> mp; bool cmp(node p, node q) { return (p.x < q.x); } int main() { int x, y, i, j, n, k; cin >> n; for (i = 0; i < n; i++) { cin >> a[i].x; mp[a[i].x]+... |
#include<bits/stdc++.h> using namespace std; #define forg(i,x) for(register int i=fir[x];i;i=nxt[i]) #define uu unsigned #define scanf a14=scanf #define rint register int #define fre(x) freopen(#x .in , r ,stdin),freopen(#x .out , w ,stdout) typedef long long ll; typedef uu long long ull; typedef pair... |
#include <bits/stdc++.h> using namespace std; int ans[105], a[105], sum[105]; int main() { int n, b; cin >> n >> b; for (int i = 0; i < n; i++) scanf( %d , a + i); int t = 0, nn = 0; for (int i = 0; i < n - 1; i++) { if (a[i] % 2) t++; else t--; if (t == 0) { ... |
#include <bits/stdc++.h> using namespace std; int main() { int t, n, sumaP, sumaI, ultimo, primero; cin >> t; while (t--) { cin >> n; if (n % 4 != 0) cout << NO << endl; else { sumaP = (n / 2) * (n / 2 + 1); sumaI = (n / 2 - 1) * (n / 2 - 1); ultimo = ... |
#include <bits/stdc++.h> using namespace std; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout << setprecision(20) << fixed; long long t; cin >> t; while (t--) { long long n; cin >> n; long long a[n]; vector<long long> b, c; long long s = 0... |
#include <bits/stdc++.h> struct Side { int x, y; Side(int x, int y) : x(x), y(y) {} }; struct Part { int id, z; Part() {} Part(int id, int z) : id(id), z(z) {} }; struct Answer { int a, b; Answer(){}; Answer(int a, int b) : a(a), b(b) {} }; bool operator<(const Side &left, ... |
#include <bits/stdc++.h> using namespace std; int main() { cin.tie(0); ios::sync_with_stdio(false); int N, H; cin >> N >> H; vector<int> A(N); for (int i = 0; i < N; i++) cin >> A[i]; vector<long long> b; int ans = 0; for (int i = 0; i < N; i++) { b.push_back(A[i]); s... |
#include <bits/stdc++.h> using namespace std; bool MySort(const pair<int, int>& A, const pair<int, int>& B) { return A.first > B.first; } int main() { int T; cin >> T; while (T--) { long long X, Y, K; cin >> X >> Y >> K; long long Ans = 0; long long All = Y * K + K; ... |
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; while (k--) { if (n % 10 == 0) n = n / 10; else n--; } cout << n; return 0; } |
#include <bits/stdc++.h> using namespace std; int32_t main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; long long n; cin >> n; long long arr[2 * n]; for (long long i = 0; i < 2 * n; i++) cin >> arr[i]; long long m = 0; for (long long i = 0; i < 2 * n; i++) { ... |
#include <bits/stdc++.h> using ll = long long; using namespace std; const ll N = 1e5 + 1, mod = 1e9 + 7; struct point { ll x, y; } p[N]; ll n; bool line[N]; signed main() { ios_base::sync_with_stdio(0), cin.tie(0); cin >> n; for (ll i = 1; i <= n; ++i) { cin >> p[i].x >> p[i].y; ... |
#include <bits/stdc++.h> using namespace std; long long gcd(int a, int b) { if (!b) return a; return gcd(b, a % b); } bool isprime(long long n) { if (n == 2) { return true; } if (n % 2 == 0) { return false; } for (long long i = 3; i <= sqrt(n); i += 2) { if (n % i =... |
#include <bits/stdc++.h> using namespace std; struct Q { int r, c, id; } q[100001]; int m, n; bool cmph(Q a, Q b) { if (a.r != b.r) return a.r < b.r; return a.c < b.c; } bool cmps(Q a, Q b) { if (a.c != b.c) return a.c < b.c; return a.r < b.r; } bool cmpp(Q a, Q b) { if (a.r + ... |
#include <bits/stdc++.h> using namespace std; const int maxn = 1005; int n; vector<int> point[2]; vector<pair<long long, int> > area[2], vec[4]; long long query(int type, int i, int j, int k) { printf( %d %d %d %d n , type, i, j, k); fflush(stdout); long long res; scanf( %lld , &res); re... |
#include <bits/stdc++.h> int a[200001]; int main() { int n, i, ans = 0; scanf( %d , &n); for (i = 0; i < n; i++) { int x; scanf( %d , &x); if (a[100000 + x] == 0 && x != 0) { ans++; a[100000 + x] = 1; } } printf( %d n , ans); return 0; } |
#include <bits/stdc++.h> using namespace std; int n, m; int v[1010][1010]; int dpa[1010][1010]; int dpreva[1010][1010]; int dpb[1010][1010]; int dprevb[1010][1010]; int solvea(int currx, int curry) { if (currx == n && curry == m) return dpa[currx][curry] = v[currx][curry]; int& ret = dpa[currx][... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); long long n, m, k, l; cin >> n >> m >> k >> l; if (((k + l + m - 1) / m) * m > n) { cout << -1; return 0; } cout << (k + l + m - 1) / m; } |
#include <bits/stdc++.h> using namespace std; const int maxn = 200005; const int maxm = 300005; const int maxq = 500005; const int inf = 0x3f3f3f3f; int n, m, Q, a[maxn], fa[maxn], x_[maxm], y_[maxm], u_[maxq], v_[maxq]; bool vis[maxm]; set<int> s[maxn]; set<int>::iterator it, itl, itr; struct oper ... |
#include <bits/stdc++.h> using namespace std; const int mod = 998244353; const int maxn = 2e5 + 10; const int inf = 0x3f3f3f3f; const double eps = 1e-6; mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count()); int n; int l[maxn], r[maxn], t[maxn]; struct node { int id; boo... |
#include <bits/stdc++.h> using namespace std; const int MOD = 1000000007; const int INF = 1000000007; const double EPS = 1e-10; const double PI = 3.14159265359; int n; int a[200005]; int cnt[200005]; int main() { int t; cin >> t; while (t--) { set<int> st; int mx = 0; mem... |
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; if (n == 1) { cout << yes << endl; cout << 1 1 n ; return 0; } vector<int> a(n); for (int i = 0; i < n; i++) cin >> a[i]; int l = 0, r = 0; while (l + 1 < n && a[l] < a[l + 1]) l++; r... |
#include <bits/stdc++.h> using namespace std; int n, k, a[2000005]; int val[2000005], sumVal[2000005]; int getSum(int l, int r) { if (l == 0) return sumVal[r]; else return sumVal[r] - sumVal[l - 1]; } int main() { cin >> n >> k; for (int i = 0; i < n; i++) { cin >> a[i]; ... |
#include <bits/stdc++.h> using namespace std; char ch[500005]; bool vis[200]; int n; double f[500005], g[500005]; void init() { vis[ I ] = vis[ E ] = vis[ A ] = vis[ O ] = vis[ U ] = vis[ Y ] = true; int i; n = strlen(ch + 1); f[0] = g[0] = 0.0; for (i = 1; i <= n; i++) { f[i] = f[... |
#include <bits/stdc++.h> using namespace std; string s; vector<char> v; int main() { ios_base::sync_with_stdio(false); getline(cin, s); int cnt = 0; bool mark; for (int i = 0; i < s.size(); i++) { if (s[i] == ) cnt++; else { v.push_back(s[i]); if (s[i] ... |
#include <bits/stdc++.h> using namespace std; int main() { std::ios::sync_with_stdio(false); int n; double m, mm; cin >> n >> mm; m = mm; double *a = new double[n]; double *b = new double[n]; for (int i = 0; i < n; ++i) { cin >> a[i]; if (a[i] == 1) { cout << -1; ... |
#include <bits/stdc++.h> using namespace std; vector<int> e[3001], u; int v[3001], d[3001]; bool dfs(int x, int from) { if (v[x]++) { for (v[x] = -1; u.back() != x; u.pop_back()) v[u.back()] = -1; return true; } u.push_back(x); for (size_t i = 0; i < e[x].size(); i++) if (e[x][... |
#include <bits/stdc++.h> using namespace std; mt19937 rd(chrono ::steady_clock ::now().time_since_epoch().count()); long long Rand(long long l, long long h) { return l + rd() % (h - l + 1); } template <typename T> inline void read(T &x) { register char c; bool sign = 0; for (c = getchar(); !isdigi... |
#include <bits/stdc++.h> static const int MOD = 1000000007; using ll = long long; using u32 = unsigned; using u64 = unsigned long long; using namespace std; template <class T> constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208; template <u32 M = 1000000007> struct modint { u32 val; m... |
#include <bits/stdc++.h> using namespace std; int main() { int n, x = 0, y = 0, x0 = 0, y0 = 0, k = 1, ans = 1; string s; cin >> n >> s; for (int i = 0; i < n; i++) { if (s[i] == L ) x--; if (s[i] == R ) x++; if (s[i] == D ) y--; if (s[i] == U ) y++; if (abs(x - x0)... |
#include <bits/stdc++.h> const long long mod = (long long)1e9 + 7; using namespace std; vector<long long> parent, sz; void make_set(long long v) { parent[v] = v; sz[v] = 1; } long long find_set(long long v) { if (v == parent[v]) return v; return parent[v] = find_set(parent[v]); } void un... |
#include <bits/stdc++.h> using namespace std; int static_init = []() { ios_base::sync_with_stdio(false), cin.tie(0), cout << fixed; return 0; }(); constexpr int N = 2e5; int32_t n, a[N]; bool v[N]; int main() { int64_t t, ans = 0; cin >> n >> t; for (int i = 0; i < n; i++) cin >> a[i];... |
#include <bits/stdc++.h> using namespace std; template <typename T> inline bool uax(T &x, T y) { return (y > x) ? x = y, true : false; } template <typename T> inline bool uin(T &x, T y) { return (y < x) ? x = y, true : false; } string to_string(char c) { return + string(1, c) + ; } stri... |
#include <bits/stdc++.h> using namespace std; int main() { int t, n; cin >> t; while (t--) { cin >> n; int ar[n], e = 0, o = 0; for (int i = 0; i < n; i++) cin >> ar[i]; for (int i = 0; i < n; i++) { if (ar[i] % 2 == 0) e = e + 1; else o = o + ... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); int k, n, w; cin >> k >> n >> w; long long t = k * (w) * (w + 1) / 2, h = 0; cout << max(h, t - n) << endl; } |
#include <bits/stdc++.h> using namespace std; const int N = 3005; const int MOD = 998244353; int f[N][N]; char s[N], t[N]; int main() { scanf( %s %s , s + 1, t + 1); int n = strlen(s + 1), m = strlen(t + 1); for (int l = 1; l <= n; ++l) { for (int r = n; r >= l; --r) { int pos = r ... |
#include <bits/stdc++.h> using namespace std; vector<string> a, b; int n, m, k; string s; int main() { cin >> n >> m; for (int i = 0; i < n; ++i) { cin >> s; a.push_back(s); } for (int i = 0; i < m; ++i) { cin >> s; b.push_back(s); } for (int i = 0; i < n; ++i) ... |
#include <bits/stdc++.h> using namespace std; int n, p; long double intial[100009], usage[100009]; bool solve(long double x) { long double pp = p * x; for (int i = 0; i < n; i++) { pp -= max(x * usage[i] - intial[i], (long double)0); if (pp < -1e-10) return false; } return true; } ... |
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 10; int a[N]; int b[N]; int n; int mp[2 * N]; int ans; unordered_map<int, int> num; int sol_01(int a[], int n) { memset(mp, -1, sizeof mp); int cur = 0; int ans = 0; int offset = 2e5; for (int i = 1; i <= n; i++) { ... |
#include <bits/stdc++.h> using namespace std; int main() { string st; while (getline(cin, st)) { int f = 0; int s = st.size() - 2; if (st[s] == ) { while (st[s] == ) { if (st[s - 1] == a || st[s - 1] == e || st[s - 1] == i || st[s - 1] == o || ... |
#include <bits/stdc++.h> using namespace std; int wrapper(int n) { while (n) { int a = n % 3; n = n / 3; if (a == 2) return 0; } return 1; } void solve() { int n; cin >> n; while (wrapper(n) == 0) n++; cout << n << n ; } int main() { ios::sync_with_stdio(0... |
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 5; const int MOD = 1e9 + 7; int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); string s; cin >> s; sort(s.begin(), s.end()); long long int sz = (int)s.size(); int i = 0, ct = 0; while (s[... |
#include <bits/stdc++.h> #include <stdio.h> using namespace std; typedef long long ll; typedef unsigned long long ul; #define len (int)1e5+5 #define mod (ll)(1e9+7) #define pq(a) priority_queue< a > #define pqd(b) priority_queue< b , vector< b > , greater< b >> #define MP make_pair #define v(i) v... |
#include <bits/stdc++.h> using namespace std; long long a, b, c, d, e, f[200009], i, j, zx, xc, s, lf[200009], rg[200009], tim, up[200009]; vector<long long> v[200009], shv[200009]; pair<long long, long long> dp[200009]; bool bo[200009], ka[200009]; bool anc(long long q, long long w) { if (lf[q] <... |
#include <bits/stdc++.h> using namespace std; const long long oo = 0x7FFFFFFF; int n; char bad[105][105]; int len[105]; char st[105]; int leng; char let[5], letter; bool mai[105]; bool alterar[105]; void read() { scanf( %d , &n); char *c; for (int i = 0; i < n; i++) { scanf( %s ,... |
#include <bits/stdc++.h> using namespace std; int n, k; int odd, even; bool win(int k, int odd, int even) { if (odd * 2 <= k || (even * 2 <= k && (k - even) % 2 == odd % 2)) return false; return true; } int main() { scanf( %d%d , &n, &k); for (int i = 1; i <= n; i++) { int x; ... |
#include <bits/stdc++.h> using namespace std; vector<pair<long long, long long> > v; long long x; long long k; int broj; int main(void) { cin >> x; k = 0; long long i = 1; for (long long i = 1; i <= sqrt(x); ++i) { if (k + i * i > (1000000000000000000)) goto van; k = k + i * i; ... |
#include <bits/stdc++.h> using namespace std; int main() { int n; long long k; scanf( %d , &n); scanf( %I64d , &k); int a; scanf( %d , &a); int ans = a; int count = 0; if (k > n - 2) { for (int i = 1; i < n; ++i) { scanf( %d , &a); if (a > ans) ans = a; ... |
#include <bits/stdc++.h> using namespace std; int main() { int t, n; scanf( %d , &t); while (t--) { scanf( %d , &n); for (int i = n * 4, cnt = 1; cnt < n; cnt++, i -= 2) printf( %d , i); printf( %d n , n * 2 + 2); } return 0; } |
#include <bits/stdc++.h> using namespace std; class BigInt { public: string value; bool sign; BigInt(); BigInt(string); BigInt(long long); BigInt operator+(BigInt &); BigInt operator-(BigInt &); bool operator==(BigInt &); bool operator!=(BigInt &); bool operator>(BigInt &)... |
#include <bits/stdc++.h> using namespace std; const long long INF = 1e18; namespace BF { long long solve(int N, int M, int K, const vector<int>& T, const vector<int>& A, const vector<int>& B) { long long res = INF; for (int mask = 0, _n = (1 << N); mask < _n; ++mask) { if ((__bui... |
#include <bits/stdc++.h> using namespace std; int n, m, q; char s[111111][12]; const int OFF = 128, BITS = 7, MASK = 127; int dy[111111][12], dx[111111][12]; char qu[5]; int mx; void go(int &y, int &x, int upTo) { for (int z = 0; z < (int)(mx); ++z) { if (s[y][x] == ^ ) { --y; ... |
#include <bits/stdc++.h> using namespace std; using LL = long long; constexpr int N = 2e5 + 5; int p[N]; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; for (int i = 2; i <= n; i++) { int x; cin >> x; p[i] = x; } vector<int> path; ... |
#include <bits/stdc++.h> using namespace std; int main() { int i, j, k, res, n, sum, t, w, temp, sz1, sz2; while (scanf( %d , &n) == 1) { vector<int> v[3]; sum = 0; for (i = 0; i < n; i++) { scanf( %d%d , &t, &w); v[t].push_back(w); sum += w; } sort(v[1]... |
#include <bits/stdc++.h> using namespace std; bool valid(long long num, long long den) { if (den == 0) { return num == 0; } else { return (num % den) == 0; } } long long gcd(long long a, long long b) { if (b == 0) { return a; } else { return gcd(b, a % b); } } ... |
#include <bits/stdc++.h> using namespace std; double pi = 4 * atan(1.0); double eps = 1e-9; string stringmin = ! ; string stringmax = ~ ; int main() { cout.precision(14); int n; cin >> n; vector<int> v(n), vlen(n); for (auto &i1 : v) cin >> i1; for (int i = 0; i < n; i++) { i... |
#include <bits/stdc++.h> using namespace std; struct S { int dist, u, v; S(int dd, int uu, int vv) { dist = dd; u = uu; v = vv; } bool operator<(const S& a) const { if (dist != a.dist) return dist < a.dist; return u < a.u; } bool operator>(const S& a) const { ... |
#include <bits/stdc++.h> using namespace std; int main() { int t; scanf( %d , &t); while (t--) { int n, s1 = 0, s2 = 0; scanf( %d , &n); int a[100] = {0}; for (int i = 0; i < n; i++) { scanf( %d , a + i); if (a[i] % 2) s1++; else s2++; ... |
#include <bits/stdc++.h> using namespace std; int main() { long long l1, r1, l2, r2, k, l, r; cin >> l1 >> r1 >> l2 >> r2 >> k; l = max(l1, l2); r = min(r1, r2); if (r < l) cout << 0; else if (l <= k && k <= r) cout << r - l; else cout << r - l + 1 << endl; return 0... |
#include <bits/stdc++.h> using namespace std; int putere(long long int a, long long int b) { if (b == 0) { return 1; } else { if (b == 1) return a % 1000000007; else { long long int r; r = putere(a, b / 2); r = (r * r) % 1000000007; if (b % 2 == 0) ... |
#include <bits/stdc++.h> using namespace std; int main() { long long int k, n, first = -1, sum = 0; cin >> n >> k; long long int a[n]; long long int ans = 0; for (long long int i = 0; i < n; ++i) cin >> a[i]; string s; cin >> s; int flag = 0; for (long long int i = 0; i < n; ++i)... |
#include <bits/stdc++.h> using namespace std; struct DSU { long long int parent[500001], connected[500001]; void intialize(int x) { for (long long int i = 1; i <= x; i++) { parent[i] = i; connected[i] = 1; } } long long int getparent(long long int k) { while (k != p... |
#include <bits/stdc++.h> using namespace std; string str; bool judge(char c) { return (c == _ || islower(c) || isdigit(c) || isupper(c)); } int main() { int cnt = 0, count = 0, type = 0, len; cin >> str; type = 0; len = str.length(); for (int i = 0; i < len; i++) { char c = str... |
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; struct cc { int x, y, z; bool operator<(const cc &t) const { if (y != t.y) return y > t.y; else return x > t.x; } } a[N]; struct xx { int w, id; } q[N]; long long dp[N]; int main() { int ... |
#include <bits/stdc++.h> using namespace std; int num[300005]; long long dp[300005], ans = -LONG_LONG_MAX; vector<int> G[300005]; int cnt = 0; void dfs(int now, int fa) { for (int k : G[now]) { if (k != fa) { dfs(k, now); dp[now] += max((long long)0, dp[k]); } } ans =... |
#include <bits/stdc++.h> using namespace std; int kmp(string s) { vector<int> lps(s.size(), 0); for (int i = 1; i < s.size(); ++i) { int index = lps[i - 1]; while (index > 0 && s[i] != s[index]) index = lps[index - 1]; if (s[i] == s[index]) lps[i] = index + 1; else lp... |
#include <bits/stdc++.h> using namespace std; long long power(long long x, long long y, long long m) { long long r = 1; for (; y; y >>= 1) { if (y & 1) r = r * x % m; x = x * x % m; } return r; } const long long N = 105, M = 105; long long a[N][M]; int run_test() { long long ... |
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf( %d , &n); if (n < 6) printf( -1 n ); else { printf( 1 2 n2 3 n2 4 n3 5 n3 6 n ); for (int i = 7; i <= n; i++) printf( 3 %d n , i); } for (int i = 2; i <= n; i++) printf( %d %d n , i - 1, i); return... |
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const long long int LINF = 0x3f3f3f3f3f3f3f3fll; const long double pi = acos(-1); const int MOD = 1e9 + 7; int main() { int n, i; double ans = 0.0; scanf( %d , &n); for (i = 1; i <= n; i++) { ans += 1 / (float)i;... |
#include <bits/stdc++.h> using namespace std; constexpr int maxn = 120000; int p[maxn], sz[maxn], top[maxn], hs[maxn], dfn[maxn], ssz[maxn]; namespace segtree { bool marked[maxn << 2]; int sum[maxn << 2], mss[maxn << 2]; void push_down(int v, int tl, int tr) { if (marked[v]) { sum[(v << 1)] = -(... |
#include <bits/stdc++.h> using namespace std; int N, M, Q, A[100][100], B[10000][4], i, j; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> N >> M >> Q; for (i = 0; i < Q; i++) { cin >> B[i][0] >> B[i][1]; B[i][1]--; if (B[i][0] == 3) { cin >... |
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; if (n == 0) { cout << 0 << endl; } else if ((n + 1) % 2 == 0) { cout << (n + 1) / 2 << endl; } else { cout << n + 1 << endl; } return 0; } |
#include <bits/stdc++.h> using namespace std; map<int, int> mp; int main() { ios::sync_with_stdio(false); int n, m; cin >> n >> m; int a[n + 1]; int ev = 2, od = 1; int tev = 0, tod = 0; int tot = 0; for (int i = 0; i < n; i++) { cin >> a[i]; mp[a[i]]++; if (a[i] ... |
#include <bits/stdc++.h> using namespace std; using namespace std::chrono; long long power(long long x, unsigned long long y) { long long res = 1; while (y > 0) { if (y & 1) { res = res * x; } y = y >> 1; x = x * x; } return res; } long long powermod(long long x... |
#include <bits/stdc++.h> using namespace std; template <class T, class U> inline T max(T &a, U &b) { return a > b ? a : b; } template <class T, class U> inline T min(T &a, U &b) { return a < b ? a : b; } template <class T> T gcd(T a, T b) { return (b != 0 ? gcd<T>(b, a % b) : a); } tem... |
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; int a[n]; for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = n; i >= 1; i--) cout << a[i] << ; cout << endl; } } |
#include <bits/stdc++.h> using namespace std; template <typename T> T in() { char ch; T n = 0; bool ng = false; while (1) { ch = getchar(); if (ch == - ) { ng = true; ch = getchar(); break; } if (ch >= 0 && ch <= 9 ) break; } while (1) { ... |
#include <bits/stdc++.h> using namespace std; const int N = 300005; const int mod = 1e9 + 7; const double eps = 1e-8; const double PI = acos(-1.0); long long qpow(long long a, long long b, long long p) { long long res = 1; while (b) { if (b & 1) res = res * a % p; a = a * a % p; b ... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int T; cin >> T; while (T--) { int n; cin >> n; vector<int> arr(n); vector<pair<int, int>> vpr(n); for (long long i = 0; i <= n - 1; i++) { cin >> arr... |
#include <bits/stdc++.h> using namespace std; long long const mod = 1000000007; long long const md = 998244353; long long mypow(long long a, long long b) { long long res = 1; a %= mod; assert(b >= 0); for (; b; b >>= 1) { if (b & 1) res = res * a % mod; a = a * a % mod; } ret... |
#include <bits/stdc++.h> using namespace std; template <typename T> istream& operator>>(istream& is, vector<T>& v) { for (auto& i : v) is >> i; return is; } template <typename T> ostream& operator<<(ostream& os, vector<T>& v) { for (auto& i : v) os << i << ; return os; } template <typ... |
#include <bits/stdc++.h> using namespace std; string S, T; int L = -1, R = -1; void solve() { int i, j, k, l, r, x, y; string s; cin >> S >> T; x = 0; for (i = 0; i < T.size(); i++) { if (T[i] == S[x]) { x++; if (x == S.size()) { L = i; break; ... |
#include <bits/stdc++.h> using namespace std; int N; string A; string B; int main() { ios_base::sync_with_stdio(NULL); cout.tie(NULL); cin.tie(NULL); cin >> N; cin >> A >> B; int answer = 0; for (int i = 0; i < N - 1; ++i) { if (A[i] == B[i]) continue; if (A[i + 1] == B... |
#include <bits/stdc++.h> using namespace std; vector<int> toOrder; map<int, set<int>> offersByDays; map<int, set<int>> offers; int totSum; int bSearch(int a, int b) { if (a == b) { return a; } int curSum = totSum; int mid = (a + b) / 2; int money = 0; for (int i = 0; i <= mid; ... |
#include <bits/stdc++.h> using namespace std; int main() { long long int i, n, d, h; cin >> n >> d >> h; if (n >= d + 1 && d >= h + 1 && d <= 2 * h && h + 1 <= n && d >= 2) { for (i = 1; i <= h; i++) { cout << i << << i + 1 << endl; } i++; int f = 0; if (d - h >... |
#include <bits/stdc++.h> using namespace std; const long long INF = 1e9 + 7; const long long MOD = 1e6 + 7; long long gcd(long long a, long long b) { if (a % b) return gcd(b, a % b); return b; } long long n, m; long long a[200005], c[6]; string s[200005]; int main() { ios_base::sync_with_s... |
#include <bits/stdc++.h> using namespace std; int main() { int n, m, k; cin >> n >> m >> k; std::vector<int> power(n, -1), school(n, -1), chosen(k, -1); int ans = 0; for (int i = 0; i < n; i++) { cin >> power[i]; } for (int i = 0; i < n; i++) { cin >> school[i]; } for... |
#include<bits/stdc++.h> using namespace std; #define int long long int n, k; int mod(int i){return (i%n+n)%n;} int q(int x){ x = mod(x) + 1; cout << ? << x << endl; int ret; cin >> ret; return ret; } int32_t main(){ cin >> n >> k; int i=0, j=0, x; int lo, hi; while(1... |
#include <bits/stdc++.h> using namespace std; const int N = 55; char arr[N][N] = {}; bool vis[N][N] = {}; int n, m; inline bool valid(int nx, int ny) { return (nx >= 1 && nx <= n && ny >= 1 && ny <= m && !vis[nx][ny] && arr[nx][ny] == # ); } void dfs(int xx, int yy) { vis[xx][yy] = ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.