func_code_string stringlengths 59 71.4k |
|---|
#include <bits/stdc++.h> using namespace std; set<int> vis; vector<int> ans; map<int, int> d; int main() { int n, m; cin >> n >> m; queue<int> q; int count = 0; for (int i = 0; i < n; i++) { int x; scanf( %d , &x); q.push(x); vis.insert(x); d[x] = 0; } ... |
#include <bits/stdc++.h> using namespace std; int A[1 << 20]; long long R[2][256][2]; long long S[256][2]; int main() { int n; scanf( %d , &n); int i, j, k; for (i = (0); i < (n); ++i) scanf( %d , &A[i]); memset(R, 0, sizeof(R)); memset(S, 0, sizeof(S)); R[0][0][0] = 1; for (i ... |
#include <bits/stdc++.h> using namespace std; long long T = 0, n, t, a; long long mu10(int b) { long long c = 1; for (int i = 1; i <= b; i++) c = c * 10; return c; } long long solve(long long c) { int m = 1; long long T = 0; while (T < c) { T += ((mu10(m)) - (mu10(m - 1))) * m; ... |
#include <bits/stdc++.h> int prime[20000000 + 1] = {0}; int palin[20000000 + 1] = {0}; bool check[20000000 + 1] = {1, 1, 0}; void primecheck() { for (int i = 2; i <= 20000000; i++) { if (check[i]) { prime[i] = prime[i - 1]; continue; } prime[i] = prime[i - 1] + 1; for... |
#include <bits/stdc++.h> using db = double; int read() { int x; scanf( %d , &x); return x; } const int N = 50007; const db eps = 1e-10; db x, y, k[N], b[N], ans; int n, c, t[N * 2], las[N], L[N * 2], R[N * 2]; struct node { db ang; int id; } a[N * 2]; db sqr(db a) { return a * a;... |
#include <bits/stdc++.h> using namespace std; static const double PI = acos(-1.0); static const double EPS = 1e-9; long long n; long long a[200010]; long long dp[200010][2]; inline bool border(long long x) { return 0 <= x && x < n; } long long dfs(long long x, long long step) { if (dp[x][step] != -1... |
#include <bits/stdc++.h> using namespace std; int main() { int n, t; cin >> n >> t; n--; t--; int arr[n]; for (int i = 0; i < n; i++) { cin >> arr[i]; } for (int i = 0; i <= n; i) { if (i == t) { cout << YES n ; return 0; } else { if (i < n)... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); int n; vector<int> pl; vector<int> sum; int a; int otv = 0; cin >> n; int m = pow(2, n + 1) - 2; pl.push_back(0); for (int i = 1; i <= m; ++i) { cin >> a; pl.push_back(a); ... |
#include <bits/stdc++.h> using namespace std; int CONST = z - a + 1; struct Node { Node() { chars.resize(CONST); for (int i = 0; i < CONST; i++) chars[i].reset(nullptr); } vector<unique_ptr<Node> > chars; }; int prefix(Node* node, const string& word, int index) { while (true) {... |
#include <bits/stdc++.h> using namespace std; template <class A> void pr(A a) { cout << a; cout << n ; } template <class A, class B> void pr(A a, B b) { cout << a << ; pr(b); } template <class A, class B, class C> void pr(A a, B b, C c) { cout << a << ; pr(b, c); } ... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, m, i; cin >> n >> m; map<int, int> mp; for (i = 0; i < 3; i++) { int t; cin >> t; if (i == 0) mp[t] = 1; if (i == 1) mp[t] = 2; if (i == 2) mp[t] =... |
#include <bits/stdc++.h> using namespace std; int n, x, res, p[(1 << 20)]; int main() { for (cin >> n; n--;) scanf( %d , &x), p[x]++; for (int i = 0; i < (1 << 20); i++) res += p[i] & 1, p[i + 1] += p[i] / 2; cout << res << endl; } |
#include <bits/stdc++.h> using namespace std; template <typename T> void trace(T a) { cout << a << n ; } template <typename T, typename... Args> void trace(T a, Args... args) { cout << a << ; trace(args...); } int recNum = 0; void prTabs() { for (int i = 0; i < recNum; i++) cout <... |
#include <bits/stdc++.h> int A[1000000], i, j, k, l, m, n, a, b, c, d, e, f, g, B[500000]; int main() { scanf( %d%d%d%d , &a, &b, &m, &A[0]); for (i = 1; i <= 100005; i++) { A[i] = (a * A[i - 1] + b) % m; if (B[A[i]]) { printf( %d , i - B[A[i]]); return 0; } B[A[i]] =... |
#include <bits/stdc++.h> using namespace std; const long long int infinity = 9e18; bool possible(long long int x1, long long int x2, long long int y1, long long int y2, long long int n, long long int m, string s, long long int dx, long long int dy) { long long int a = m / n; ... |
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 5; vector<int> g[N], gr[N]; bool used[N]; vector<int> order, component; pair<int, int> edge[N]; int par[N]; vector<int> v[N]; int f(int i) { if (par[i] != i) par[i] = f(par[i]); return par[i]; } void merge(int a, int b) { ... |
#include <bits/stdc++.h> using namespace std; int n; double first[10005], second[10005], w, u, v; double eps = 1e-9; signed main() { ios::sync_with_stdio(0); cin.tie(NULL), cout.tie(NULL); cin >> n >> w >> u >> v; for (int i = 0; i < n; i++) cin >> first[i] >> second[i]; double ans = w / v... |
#include <bits/stdc++.h> using namespace std; char s[110]; bool a[10]; int main() { int x, y, pow = 1, t, k, b = 0; gets(s); k = strlen(s); for (int i = 0; i < k; i++) { for (int j = 0; j < 8; j++) a[j] = 0; x = (int)s[i]; for (int j = 0; j < 8; j++) { if (x % 2 == 1) ... |
#include <bits/stdc++.h> using namespace std; int n; int pow2[50]; int l[50]; int level(long long p) { long long comp = 1; int ans = 0; while (comp <= p) { comp <<= 1; ans++; } return ans - 1; } bool ispow2(long long p) { long long comp = 1; while (comp < p) { ... |
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 5; long long n, l[MAXN], r[MAXN], vall[MAXN], valr[MAXN], pos[MAXN], d[MAXN], tree[4 * MAXN], ind[MAXN]; bool validl[MAXN], validr[MAXN], dead; pair<long long, long long> sortr[MAXN]; void computeleft() { l[0] = -1, r[0] = 1, r[n... |
#include <bits/stdc++.h> using namespace std; const int K = 103, N = 30005; double f[K], sum[K]; double pr[N][K]; double mem[N][K]; int main() { string s; cin >> s; int n, H; cin >> n >> H; H++; if (s == Bob ) { cout << n << endl; return 0; } for (int i = 1; i <=... |
#include <bits/stdc++.h> int p[100100]; void solve(int n, int m) { int i, j, k, x, s = 0, l = 0, r = n; for (i = 0; i < 100100; i++) p[i] = 0; for (i = 0; i <= n; i++) p[i] = i; for (k = 0; k < m; k++) { scanf( %d , &x); if (x == 1) { scanf( %d , &x); if (s == 0) { ... |
#include <bits/stdc++.h> #pragma comment(linker, /STACK:100000000 ) #pragma GCC ostarimize( O500 ) using namespace std; const bool db = false; set<pair<int, int>> s; int a[200100]; int main() { int n, k, q; scanf( %d %d %d n , &n, &k, &q); for (int i = 1; i <= n; i++) scanf( %d , &a[i]); ... |
#include <bits/stdc++.h> using namespace std; int main() { int a, b; cin >> a >> b; cout << (a + b); return 0; } |
#include <bits/stdc++.h> using namespace std; struct Point { long long x, y; int id; Point() {} Point(long long a, long long b, int c) : x(a), y(b), id(c) {} Point operator-(Point b) { return Point(x - b.x, y - b.y, 0); } bool operator<(const Point &b) const { return (x != b.x) ? x < b... |
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const int N = 1e6 + 5; int n, m, k; bool vis[N]; int main() { ios::sync_with_stdio(false); cin >> n >> m >> k; int h; for (int i = 1; i <= m; i++) { cin >> h; vis[h] = 1; } bool fg = 0; int bone... |
#include <bits/stdc++.h> int min(int a, int b) { return a < b ? a : b; } int max(int a, int b) { return a > b ? a : b; } unsigned int X; void srand_() { struct timeval tv; gettimeofday(&tv, NULL); X = tv.tv_sec ^ tv.tv_usec | 1; } int rand_() { return (X *= 3) >> 1; } int *ej[1000], eo[1000]; ... |
#include <bits/stdc++.h> using namespace std; const long long MIN = numeric_limits<long long>::min(); class WindowHeap { public: WindowHeap() {} long long top() { if (_i >= _h.size()) return MIN; return _h[_i].first; } void erase(int idx) { if (!_h.empty() && _h[_i].second == ... |
#include <bits/stdc++.h> long double read() { int x; scanf( %d , &x); return x / 1000.0L; } const long double eps = 1e-9, Eps = 1e-7; const int N = 1e5 + 5, V = 4e7 + 5; int n, m, q, rb[N], vol, stc[V]; std::pair<int, int> p[N]; long double k, ox, oy, a[N], b[N], cx[N], cy[N]; long double an... |
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; vector<int> v[100000]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >> n; map<int, int> m; for (int i = 0; i < n; i++) { int a; cin >> a; for (int j = 2; j <= sqrt(a); j... |
#include <iostream> #include <queue> #include <algorithm> #include <cstring> #include <cmath> #include <vector> using namespace std; typedef long long LL; const LL mod = 1e9 + 7; const int N = 1e6 + 10; LL l[N], r[N]; LL c[N], a[N], b[N]; int main() { int T;cin >> T; while (T--) { ... |
#include <bits/stdc++.h> using namespace std; const int N = 20; const int V = (1 << 20) + 10; const int P = 1000000007; int Pow(int x, int y) { int ret = 1; while (y) { if (y & 1) ret = (long long)ret * x % P; x = (long long)x * x % P; y /= 2; } return ret; } void utf(int... |
#include <bits/stdc++.h> int main() { int n, i, j, ans = 0; char c[101]; scanf( %d , &n); scanf( %s , c); int l; for (l = 1; l <= n; l++) { for (i = 0; i < n - 4 * l; i++) { if (c[i] == * && c[i + l] == * && c[i + 2 * l] == * && c[i + 3 * l] == * && c[i + 4 * ... |
#include <bits/stdc++.h> using namespace std; template <class T> T sq(T x) { return x * x; } const long long inf = 2147383647; const double pi = 2 * acos(0.0); const double eps = 1e-9; const long long maxint = 2147483647; const long long minint = -2147483648; long long gcd(long long a, long long... |
#include <bits/stdc++.h> using namespace std; long long n, l, r, k, i, ans; int main() { scanf( %I64d%I64d%I64d%I64d , &n, &l, &r, &k); r = (r + n - l + 1) % n; if (k < r) { printf( -1 ); return 0; } if (2 * r >= k) { ans = min(k + n - r * 2 + 1, n); if (ans >= k - r) {... |
#include <bits/stdc++.h> using namespace std; inline int in() { int32_t x; scanf( %d , &x); return x; } inline string get() { char ch[1000010]; scanf( %s , ch); return ch; } const int MAX_LG = 21; const long long maxn = 5e5 + 10; const long long base = 29; const long long mod =... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t; cin >> t; while (t--) { long long int n; cin >> n; long long int count = 2; while (n % ((1 << count) - 1) != 0) { count++; ... |
#include <bits/stdc++.h> using namespace std; map<long long, string> mp; long long n; int main() { scanf( %I64d , &n); for (long long i = 2; i * i <= n; i++) { for (long long j = i * i, k = 2; j <= n; j *= i, k++) { string tmp = to_string(i) + ^ + to_string(k); if (!mp.count(j)) ... |
#include <bits/stdc++.h> using namespace std; char ch[100010]; int flag[26]; int main() { while (~scanf( %s , ch)) { memset(flag, 0, sizeof(flag)); flag[0] = 1; flag[ H - A ] = 1; flag[ I - A ] = 1; flag[ M - A ] = 1; flag[ O - A ] = 1; flag[ T - A ] = 1; ... |
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const long long LINF = 0x3f3f3f3f3f3f3f3fll; const mt19937 rng((int)chrono::steady_clock::now().time_since_epoch().count()); const int MOD = 998244353; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int t; cin ... |
#include <bits/stdc++.h> using namespace std; bool solve(int x) { if (x == 0) return true; if (x % 1000 == 144) { return solve(x / 1000); } else if (x % 100 == 14) { return solve(x / 100); } else if (x % 10 == 1) { return solve(x / 10); } return false; } int main() { ... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); int n; cin >> n; map<double, int> mp2; map<string, double> mp1; vector<string> S; while (n--) { string x; cin >> x; S.push_back(x); int plus = 0, ... |
#include <bits/stdc++.h> int main() { std::ios_base::sync_with_stdio(false); std::cout.tie(nullptr); std::cin.tie(nullptr); std::cerr.tie(nullptr); int64_t n, k; std::cin >> n >> k; if (k == 1) std::cout << 1 n ; if (k == 2) { int64_t res = (n * (n - 1)) / 2 + 1; std::cout... |
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using pii = pair<int, int>; using pll = pair<ll, ll>; using vi = vector<int>; using vll = vector<ll>; constexpr int MOD = 1e9 + 7; constexpr int INF = INT_MAX; constexpr ll LLINF = LLONG_MAX; template <clas... |
#include <bits/stdc++.h> using namespace std; template <typename Arg1> void __f(const char* name, Arg1&& arg1) { cout << name << : << arg1 << n ; } template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args) { const char* comma = strchr(names + 1, , ); ... |
#include <bits/stdc++.h> using namespace std; const int INF = 1e9 + 96; const int MAXN = 1e6 + 5; const int MAXK = 8e6 + 5; const int MOD = 1e9 + 7; const int MAX_ASCII_CODE = 26; const int MAX_NUMBER_OF_NODES = 1e5 + 5; int n, m; int arr[MAXN]; int rea[MAXK]; int foo(int v) { if (v == 0) retu... |
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; const int N = 100000 + 100; const int inf = 0x7fffffff; int n, a, b, c; int f[N]; int main() { scanf( %d%d%d%d , &n, &a, &b, &c); f[a] = 1; f[b] = 1; f[c] = 1; for (int i = min(a, min(b, c)); i <= n; i++) {... |
#include <bits/stdc++.h> using namespace std; /* find my code templates at https://github.com/galencolin/cp-templates also maybe subscribe please thanks */ #define send {ios_base::sync_with_stdio(false);} #define help {cin.tie(NULL);} #define f first #define s second #define getunique(v) {s... |
#include <bits/stdc++.h> using namespace std; int m, n, a[2000100], b[2000100], d[2000100], ans = 1, pos[2000100]; int between(int x, int y, int z) { if (z < y) return x < z || x > y; return x > y && x < z; } int main() { memset(d, -1, sizeof(d)); cin >> m >> n; for (int i = 0; i < m; i++)... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int n, m, k, i, j; cin >> n >> m >> k; long long int a[n]; vector<pair<long long int, long long int> > v; for (i = 0; i < n; i++) { cin >> a[i]; v.push_back(m... |
#include <bits/stdc++.h> using namespace std; const int MAXN = 3e5 + 7; vector<pair<int, int> > G[MAXN]; int n; int sz[MAXN]; long long MAX, MIN; void dfs(int u, int fa) { sz[u] = 1; for (pair<int, int> edge : G[u]) { int v = edge.first; if (v == fa) continue; dfs(v, u); sz... |
#include <bits/stdc++.h> using namespace std; const double eps = 1e-8; int s[2], t[200007][2]; int x[200007]; int n, m, st[200007]; int absi(int x) { return x > 0 ? x : -x; } int main() { cin >> n >> m; for (int i = 0; i < n; i++) scanf( %d , &x[i]); memset(s, 0, sizeof(s)); memset(t, 0, s... |
#include <bits/stdc++.h> using namespace std; inline long long getnum() { char c = getchar(); long long num, sign = 1; for (; c < 0 || c > 9 ; c = getchar()) if (c == - ) sign = -1; for (num = 0; c >= 0 && c <= 9 ;) { c -= 0 ; num = num * 10 + c; c = getchar(); } ... |
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int cnt = 0; while (n > 0) { if (n >= 100) { n -= 100; cnt++; } else if (n >= 20) { n -= 20; cnt++; } else if (n >= 10) { n -= 10; cnt++; } else if (n >... |
#include <bits/stdc++.h> using namespace std; int num[105]; int main() { int n; cin >> n; set<int> s; while (n--) { int a; cin >> a; s.insert(a); num[a]++; } if (s.size() == 2 && num[*s.begin()] == num[*s.rbegin()]) { cout << YES n ; cout << *s.begin() ... |
#include <bits/stdc++.h> using namespace std; int main() { int n, q, acum = 0, ultimo = 0, type, a, count; scanf( %d%d , &n, &q); vector<queue<int>> notificaciones_app(n); unordered_set<int> todas_notificaciones; while (q--) { scanf( %d%d , &type, &a); a--; switch (type) { ... |
#include <bits/stdc++.h> using namespace std; int main() { int t; scanf( %d , &t); while (t--) { int n, p; scanf( %d , &n); scanf( %d , &p); vector<pair<int, int> > ans; int edges = 2 * n + p; for (int i = int(1); i <= int(n); i++) { for (int j = int(i + 1); j... |
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); string a, b; cin >> a >> b; if (a.size() < b.size()) a = string(b.size() - a.size(), 0 ) + a; if (b.size() < a.size()) b = string(a.size() - b.size(), 0 ) + b; if (a == b) c... |
#include <bits/stdc++.h> using namespace std; struct point { int x, y, h; } a[100010]; bool cmp(point a, point b) { if (a.y != b.y) return a.y < b.y; return a.x < b.x; } int dp[100010]; int main() { int n; while (~scanf( %d , &n)) { for (int i = 0; i < n; i++) scanf( %d%d%d , &a[... |
#include <bits/stdc++.h> using namespace std; int main() { int m[10][10] = {0}; for (int i = 1; i <= 3; i++) { for (int j = 1; j <= 3; j++) { cin >> m[i][j]; } } int s = 0; for (int i = 1; i <= 3; i++) { for (int j = 1; j <= 3; j++) { s = m[i][j]; s += m... |
#include <bits/stdc++.h> using namespace std; int n, m; int main() { scanf( %d%d , &n, &m); for (int i = 1; i <= n / 2; i++) { for (int j = 1; j <= m; j++) { printf( %d %d n , i, j); printf( %d %d n , n - i + 1, m - j + 1); } } if (n & 1) { for (int i = 1; i <= m ... |
#include <bits/stdc++.h> using namespace std; vector<vector<int>> edges; vector<int> large; bool ok = true; vector<pair<long long, long long>> dfs(int cur) { vector<pair<long long, long long>> child; for (int i : edges[cur]) { auto temp = dfs(i); child.insert(child.end(), temp.begin(), tem... |
#include <bits/stdc++.h> using namespace std; template <typename T> void maxtt(T& t1, T t2) { t1 = max(t1, t2); } template <typename T> void mintt(T& t1, T t2) { t1 = min(t1, t2); } bool debug = 0; int n, m, k; int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0}; string direc = URDL ; cons... |
#include <bits/stdc++.h> using namespace std; int main() { int a, b, n; cin >> n >> a >> b; cout << min(n - a, b + 1); return 0; } |
#include <bits/stdc++.h> using namespace std; template <class T> inline T sqr(const T &a) { return a * a; } template <class T> inline T middle(const T &a, const T &b) { return (a + b) / 2; } template <class T> inline int len(const T &c) { return static_cast<int>(c.size()); } const long... |
#include <bits/stdc++.h> using namespace std; int n, a, b, c, D, e; int cs[200020]; int all[200020], A[4], AA[4]; int i, x, y, z, tmp, tim, m; int main() { cin >> n; cin >> a >> b >> c; if (a > c) swap(a, c); if (a > b) swap(a, b); if (b > c) swap(b, c); A[1] = a; A[2] = b; A... |
#include <bits/stdc++.h> template <class C, class E> inline bool contains(const C &container, const E &element) { return container.find(element) != container.end(); } template <class T> inline void checkmin(T &a, T b) { if (b < a) a = b; } template <class T> inline void checkmax(T &a, T b) { ... |
#include <bits/stdc++.h> using namespace std; using LL = long long; LL g_l, g_r; LL gcd(LL a, LL b) { if (b == 0) return a; return gcd(b, a % b); } bool input() { cin >> g_l >> g_r; if (cin.eof()) return false; return true; } void solve() { for (LL i = g_l; i <= g_r; ++i) { ... |
#include <bits/stdc++.h> using namespace std; const int N = 100010; long long read() { long long x = 0, f = 1; char ch = getchar(); while (ch < 0 || ch > 9 ) { if (ch == - ) f = -1; ch = getchar(); } while (ch >= 0 && ch <= 9 ) { x = (x << 3) + (x << 1) + ch - 0 ; ... |
#include <bits/stdc++.h> using namespace std; struct BipartiteMatcher { vector<vector<int>> g; vector<int> L, R; vector<bool> vis; BipartiteMatcher(int n, int m) : g(n), L(n, -1), R(m, -1), vis(n) {} void addEdge(int a, int b) { g[a].emplace_back(b); } bool match(int x) { if (vis[x]) r... |
#include <bits/stdc++.h> using namespace std; long long x[60002]; long long v[60002]; double ans = 1e12; long long n; double ma(double a, double b) { if (a > b) return a; return b; } double calc(double xx, double& bd) { double time = -1; for (int i = 0; i < n; i++) { double d = abs... |
#include <bits/stdc++.h> int main() { int t; scanf( %d , &t); while (t--) { int n; scanf( %d , &n); int a[20005], b[20005]; for (int i = 0; i < n; i++) scanf( %d %d , &a[i], &b[i]); int num = 1; for (int i = 0; i < n; i++) { if (num < a[i]) { num = a[i... |
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const long long int INFL = 0x3f3f3f3f3f3f3f3fLL; const int MOD = 1e9 + 7; const int MAX = 1e5 + 5; int a[1001]; int __attribute__((optimize( -O3 ))) main() { cin.sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; ... |
#include <bits/stdc++.h> using namespace std; const int INF = 522133279; const int MAXN = 100000; const int TOTN = 100 + 100; const long long MOD = 1000000007; bool _su[MAXN]; vector<int> su; vector<int> suc; int n, k; void shai() { memset((_su), true, sizeof(_su)); for (int i = (2); i < (MA... |
#include <bits/stdc++.h> using namespace std; int n, m; int p[100000]; int h[100000]; int queries[100000][3]; vector<pair<int, int> > type3[100000]; vector<int> adj[100000]; int visited[100000]; vector<int> who; int top[100000]; int ok[100000]; vector<pair<int, int> > need[100000]; int which[1... |
#include <bits/stdc++.h> using namespace std; int st[1000010]; int mod = 1000000007; vector<vector<int> > g; int dp[1000010][2]; int n, m, k; int a[1000010]; int main() { st[0] = 1; for (int i = (1); i < (1000010); ++i) { st[i] = st[i - 1] + st[i - 1]; if (st[i] >= mod) st[i] -= mod;... |
#include <bits/stdc++.h> using namespace std; int main() { int n, s; string c; cin >> n >> c; s = n; string r = ; while (n > 0) { if (n % 2 == 0) { string y = ; y += c[s - n]; y += r; r = y; } else { r += c[s - n]; } n--; ... |
#include <bits/stdc++.h> using namespace std; int M, N, maxH[100009], d[100009]; void dfs(int nod) { if (nod >= (1 << N)) { maxH[nod] = 0; return; } int f1 = nod << 1, f2 = f1 | 1; dfs(f1), dfs(f2); maxH[nod] = max(maxH[f1] + d[f1], maxH[f2] + d[f2]); } int ans = 0; void solv... |
#include <bits/stdc++.h> using namespace std; int L, f, b; int n; int pos[110]; map<int, int> lot; int findpos(int L) { map<int, int>::iterator cur, next; cur = lot.begin(), next = cur; next++; for (; next != lot.end(); cur++, next++) { int back = cur->first + cur->second, front = next... |
#include <bits/stdc++.h> using namespace std; const long long INF = 1 << 28; const long long LINF = 1ll << 61; string B, N; long long b, pw[10], C; int main() { ios::sync_with_stdio(false); cin >> B >> N >> C; int it = N.size(); for (int i = N.size() - 1; i >= 0; i--) { N[i]--; i... |
#include <bits/stdc++.h> using namespace std; int main() { int a, b, cnt = 1; cin >> a >> b; int d = a; bool flag = true; while (d >= cnt) { if (flag) { a -= cnt; flag = false; d = b; } else { b -= cnt; flag = true; d = a; } ... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); int t; cin >> t; while (t--) { long long n; cin >> n; long long tripleIndx = n / 3; if (!(n % 3)) tripleIndx--; stack<long long> st; while (tripleIndx--) { st.push... |
#include <bits/stdc++.h> using namespace std; const int maxn = 110; int a[maxn]; int main() { int n; while (cin >> n) { int ans = 0; for (int i = 1; i <= n; i++) { cin >> a[i]; if (a[i]) ans++; } for (int i = 1; i <= n; i++) { if (a[i] == 1) { if... |
#include <bits/stdc++.h> using namespace std; int a[1000005]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); ; int n; cin >> n; for (long long(i) = (0); (i) < (n); (i)++) cin >> a[i]; int tmp = n + 1; int ans = 0; for (int i = n; i >= 1; --i) { if (i < tmp) ans++;... |
#include<bits/stdc++.h> using namespace std; int cumsum[200005]; int a[200005]; int main() { int t; scanf( %d ,&t); while(t--) { int n; scanf( %d ,&n); for(int i=0;i<n;i++) { scanf( %d ,&a[i]); } for(int i=0;i<n;i++) { cumsum[i] = 0; } for(int i=0;i... |
#include <bits/stdc++.h> using namespace std; priority_queue<long long, vector<long long>, greater<long long> > q; int main() { long long n; while (cin >> n) { long long e = 0, o = 0; for (long long i = 1; i <= n; i++) { long long x; cin >> x; if (x % 2) o++; ... |
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } const int NCARDS = 8; const int NVALS = 5; const int NSTATE = 495; vector<vector<int> > states; map<vector<int>, int> mp; void genstates(vector<int> &v, int at, int rem) { if ... |
#include <bits/stdc++.h> using namespace std; vector<int> S; vector<int> ack; int pop[1100100]; int kol[1100100]; int k[1234]; char c[1234]; const int INF = 1000000000; int parse(int a) { if (a == INF) return -INF; return a; } int main() { int n, m; scanf( %d , &n); for (int i ... |
#include <bits/stdc++.h> using namespace std; int main() { int ans = 0; int n, a = 0, b; cin >> n; for (int i = 0; i < n; i++) { cin >> b; a += b; } int m, c, d; cin >> m; for (int i = 0; i < m; i++) { cin >> c >> d; if (ans == 0) { if (a >= c && a <= ... |
#include <bits/stdc++.h> using namespace std; const int maxn = 20000; struct node { int flow; int ff[5]; int ru; } mat[maxn]; int n, m; int kk[500]; int now; int getup(int id) { int ret = -1; int k = id - m; while (k >= 1) { if (mat[k].flow != -1) { ret = k; ... |
#include <bits/stdc++.h> using namespace std; const long long N = 1e6 + 100, MOD = 1e9 + 9, INF = 1e15, SQ = 370, LOG = 30; int n, m, x, y, x2, y2, z, t, now, l, r; int ans, dp[4][4 * N]; bool lazy[4 * N]; string s; void bld(int b, int e, int pos) { if (b == e - 1) { if (s[b] == 7 ) { d... |
#include <bits/stdc++.h> using namespace std; std::vector<std::string> alph; class IAlphabet { public: virtual int encode(char symbol) = 0; virtual char decode(int code) = 0; virtual int size() = 0; }; class alphabet_eng : public IAlphabet { public: virtual int encode(char symbol); v... |
#include <bits/stdc++.h> #pragma comment(linker, /STACK:36777216 ) using namespace std; const int inf = 1 << 30; const long long Inf = 1LL << 62; const int dx[] = {-1, 0, 1, 0, -1, -1, 1, 1, 0}; const int dy[] = {0, 1, 0, -1, -1, 1, 1, -1, 0}; const double eps = 1e-9; const double pi = 3.14159265358979... |
#include <bits/stdc++.h> using namespace std; const int INF = 1e9 + 7; using namespace std; int n; int main() { cin >> n; int k1 = 0; int x = n; while (x % 10 != 0) { x++; k1++; } int k2 = 0; while (n % 10 != 0) { n--; k2++; } if (k1 > k2) cout... |
#include <bits/stdc++.h> using namespace std; int n, m; int p[20000000 / 5], cnt; bool flag[20000000]; void prepare() { flag[1] = 1; for (int i = 2; i <= m; i++) { if (!flag[i]) { p[cnt++] = i; } for (int j = 0; j < cnt && i * p[j] <= m; j++) { flag[i * p[j]] = 1; ... |
#include <bits/stdc++.h> using namespace std; struct ww { long double x, y; } a[100010]; int i, j, k, n, m, xx, yy; long double LU[100010], RU[100010], LD[100010], RD[100010]; inline bool judge(long double len) { int i, j; j = 0; for (i = 1; i <= n; i++) { for (; a[j + 1].x + len < a[i... |
#include <bits/stdc++.h> using namespace std; const int MOD = 998244353; template <typename T> struct modular { constexpr modular() : val(0) {} constexpr modular(const modular<T>& _m) : val(_m.val) {} template <typename U> constexpr modular(const U& _r = U()) { val = -MOD <= _r && _r < MOD... |
#include <bits/stdc++.h> using namespace std; const long double epsilon = 1e-9; string minus1(const string& str) { string str1(str); for (int i = str.size() - 1; i >= 0; i--) { if (str1[i] != 0 ) { str1[i]--; break; } else str1[i] = 9 ; } return str1; } lo... |
#include <bits/stdc++.h> using namespace std; int n, a, b, sum; int main() { cin >> n; b = -1; sum = 0; for (int i = 0; i < n; i++) { cin >> a; if (a == 0 || (a == b && b != 3)) { sum++; b = 0; } else if (a == 3 && b == 1) b = 2; else if (a == 3 && b... |
#include <bits/stdc++.h> using namespace std; template <class T> inline void umax(T &a, T b) { if (a < b) a = b; } template <class T> inline void umin(T &a, T b) { if (a > b) a = b; } template <class T> inline T abs(T a) { return a > 0 ? a : -a; } template <class T> inline T gcd(T a,... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.