func_code_string stringlengths 59 71.4k |
|---|
#include <bits/stdc++.h> using namespace std; using vint = vector<long long>; using pint = pair<long long, long long>; using vpint = vector<pint>; template <typename A, typename B> inline void chmin(A& a, B b) { if (a > b) a = b; } template <typename A, typename B> inline void chmax(A& a, B b) { ... |
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using uint = unsigned int; using ull = unsigned long long; template <class T> bool set_max(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } template <class T> boo... |
#include <bits/stdc++.h> using namespace std; const int M = 1e9 + 7; const int MN = 1e6 + 6; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout << fixed << setprecision(10); long long n; cin >> n; long long p_x = 0, p_y = 0; long long res = 1; for (long long ... |
#include <bits/stdc++.h> using namespace std; int main() { long long int n, a, i, j, mid, cnt = 0; cin >> n; for (i = 0; i < n; i++) { for (j = 0; j < n; j++) { cin >> a; if (i == j) cnt = cnt + a; if (i + j == n - 1) cnt = cnt + a; if (i == n / 2) cnt = cnt + a; ... |
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; int i = n, j = n; vector<int> a(2 * n + 1), b(2 * n + 1); long long s = 0, x = 1, y = a[n] = b[n] = 1; while (n--) { int v; cin >> v; if (v < m) x += a[++i]++, y += b[++j]++; e... |
#include <bits/stdc++.h> using namespace std; template <class T> T abs(T x) { return x > 0 ? x : -x; } int n; int m; int mask[500][500][17]; int x[500], y[500], X[500], Y[500]; double xx[500], yy[500], XX[500], YY[500]; double vect(double x1, double y8687969, double x2, double y2) { return x... |
#include <bits/stdc++.h> using namespace std; int main() { int n, k, x; int A[200010] = {0}, L[200010] = {0}, R[200010] = {0}; scanf( %d%d%d , &n, &k, &x); for (int i = 1; i <= n; i++) { scanf( %d , A + i); } sort(A + 1, A + 1 + n); for (int i = 1; i <= n; i++) { L[i] = A[i] ... |
#include <bits/stdc++.h> using namespace std; int n, k; string s; int main() { cin >> n >> k >> s; int del = (n - k) / 2; stack<int> st; for (char ch : s) { if (ch == ( ) { if (del) { st.push(1); del--; } else { st.push(0); putchar( ... |
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 4; int n, ans, ar[maxn], flag[maxn], dp[maxn]; int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> n; for (int i = 0; i < n; i++) { cin >> ar[i]; } for (int i = 0; i < maxn; i++) dp[i] = 1; for (int i... |
#include <bits/stdc++.h> using namespace std; const int INF = 1.01e9; const double PI = acos(-1); bool eq(double A, double B) { return abs(A - B) < 1e-9; } bool ls(double A, double B) { return A < B && !eq(A, B); } bool le(double A, double B) { return A < B || eq(A, B); } struct pt { double x, y, id; ... |
#include <bits/stdc++.h> using namespace std; int n, t; int ult, casas; string s; int solve(int k) { int u = -1; int acc = k; for (int i = 0; i < n; i++) if (s[i] == S ) { acc++; if (acc >= casas) { u = i; break; } } if (u == -1) return ... |
#include <bits/stdc++.h> using namespace std; const bool ready = []() { ios_base::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(12); return true; }(); const double PI = acos(-1); using ll = long long; using pii = pair<ll, ll>; using pdd = pair<double, double>; using v... |
#include <bits/stdc++.h> using namespace std; template <typename T> T id(T b) { return b; }; template <class It> bool all(It f, It l) { return std::all_of(f, l, id<bool>); } template <class It> bool any(It f, It l) { return std::any_of(f, l, id<bool>); } const int MAX_N = 2000, MAX_A =... |
#include <bits/stdc++.h> using namespace std; int arr[1007]; int main() { char c; int t = 3; while (t--) { scanf( %c , &c); char temp; scanf( %c , &temp); char d; scanf( %c , &d); if (temp == > ) { arr[c]++; arr[d]--; } else { arr[c]-... |
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> q(3 * n + 1); for (int i = 0; i < 3 * n; i++) { int a; cin >> a; q[a] = i; } vector<vector<int>> v(n, vector<int>(3)); for (int i = 0; i < n; i++) { for (int j = 0; j < 3; j++)... |
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { if (b == 0) return a; return gcd(b, a % b); } long long max(long long a, long long b) { return (a > b ? a : b); } void printa(long long arr[], long long n) { for (long long i = 0; i < n; i++) { cout << ar... |
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 7; int n, m, x[N], y[N], num[N], val[N], dp[2][N], cnt; vector<int> adj[N]; bool vis[N]; void DFS(int u) { vis[u] = true; for (int i = 0; i < (int)adj[u].size(); ++i) { int v = adj[u][i]; if (vis[v] == false) DFS(v); }... |
#include <bits/stdc++.h> using namespace std; int main() { int n, m; scanf( %d %d , &n, &m); vector<vector<int>> x(m + 1, vector<int>(n + 1)); for (int i = 1; i <= n; i++) { int k; scanf( %d , &k); for (int j = 1; j <= m; j++) { x[j][i] = x[j][i - 1]; if (j == k) { ... |
#include <bits/stdc++.h> using namespace std; int IN() { int x = 0, f = 0, ch; for (; (ch = getchar()) < 0 || ch > 9 ;) f = (ch == - ); for (; ch >= 0 && ch <= 9 ; (ch = getchar())) x = x * 10 + ch - 0 ; return f ? -x : x; } const double Pi = acos(-1), eps = 1e-11; int N, M, T, C, ID[2... |
#include <bits/stdc++.h> using namespace std; double EPS = 1e-9; int INF = 1000000005; long long INFF = 1000000000000000005ll; double PI = acos(-1); int dirx[8] = {-1, 0, 0, 1, -1, -1, 1, 1}; int diry[8] = {0, 1, -1, 0, -1, 1, -1, 1}; long long MOD = 1000000007; template <typename T_vector> void out... |
#include <bits/stdc++.h> using namespace std; const int N = 100010; const int D = 10000010; const int MAXW = N + 1000; const int mod = 1e9 + 7; int n, m; int pw2[MAXW + 10]; struct edge { int to, nx, w; } ee[N * 2]; int eq[N], en = 1; int dn, flag; int l[D], r[D], hs[D]; int ans[N], root[N... |
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 5; ; const int inf = 1e9 + 5; const int mod = 1e9 + 7; const int logN = 17; int x, y, n, m, a[N], b[N], w[N], p[N], score[N]; vector<int> v[N]; long long ans[N], upsum[N], downsum[N]; bool cmp(int x, int y) { return score[x] < score[y... |
#include <bits/stdc++.h> using namespace std; int main() { int n, potezi = 1, bodovi = 0; scanf( %d , &n); pair<int, int> a[n]; for (int i = 0; i < n; i++) { scanf( %d %d , &a[i].second, &a[i].first); } sort(a, a + n); for (int i = n - 1; i >= 0; i--) { if (!potezi) break; ... |
#include <bits/stdc++.h> using namespace std; string a, b; int pas = 0; int main() { cin >> a >> b; for (int i = 0; i < a.size(); i++) { if (a[i] != b[a.size() - 1 - i]) { pas++; } } if (pas > 0) { cout << NO ; } else { cout << YES ; } } |
#include <bits/stdc++.h> const long long N = 200005; long long hi, ls, n, X[N], t, A[N], bk[N]; using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> n >> t; for (int i = 0; i < n; ++i) { cin >> A[i]; } for (int i = 0; i < n; ++i) { cin >> X[i... |
#include <bits/stdc++.h> using namespace std; int n; string a; void convA() { int c = 0, r = 0; int i; for (i = 1; a[i] != C ; i++) { r *= 10; r += a[i] - 0 ; } i++; for (; i < a.size(); i++) { c *= 10; c += a[i] - 0 ; } vector<int> ans; while (c !=... |
#include <bits/stdc++.h> #pragma GCC optimize( -O3 ) using namespace std; const long long N = 1e6 + 5; void pairsort(long long a[], long long b[], long long n) { pair<long long, long long> pairt[n]; for (long long i = 0; i < n; i++) { pairt[i].first = a[i]; pairt[i].second = b[i]; } ... |
#include <bits/stdc++.h> using namespace std; int m[367], f[367]; int main() { memset(m, 0, sizeof(m)); memset(f, 0, sizeof(f)); int N; cin >> N; char ch; int a, b; for (int i = 0; i < N; ++i) { cin >> ch >> a >> b; if (ch == M ) for (int j = a; j <= b; ++j) ++m[j]... |
#include <bits/stdc++.h> using namespace std; char t; int n, m; char a[11][11]; bool used[11][11]; int kol = 0; int maxleng = 0; void dfs(int x, int y, bool ch, int leng = 0) { if (x < 0 || y < 0 || x >= n || y >= m) return; if (a[x][y] == 2) return; if (used[x][y]) return; used[x][y] = ... |
#include <bits/stdc++.h> using namespace std; const int MAXN = (int)2e5 + 5; int n, t; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); while (cin >> n) { int ans = 0; set<int> s; for (int i = 1; i <= n && cin >> t; ++i) { if (t) { if (s.count(t)... |
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 10; const int inf = 0x3f3f3f3f; int main() { int t; t = 1; while (t--) { long long a, b, c, d; cin >> a >> b >> c >> d; long long ans = 0; for (int i = (a); i < (b + 1); i++) { long long l = b - 1, r... |
#include <bits/stdc++.h> using namespace std; double alto, ancho, altomesa, anchomesa, ancho1, alto1, x_1, x_2, y_1, y_2; double abajo() { if (altomesa <= y_1) return 0; return altomesa - y_1; } double arriba() { if (altomesa <= alto - y_2) return 0; return altomesa - (alto - y_2); } doubl... |
#include <bits/stdc++.h> using namespace std; void run(); signed main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cout << fixed << setprecision(3); srand(42); run(); } template <typename T1, typename T2> bool mini(T1 &a, const T2 &b) { if (a > b) { a = b; ... |
#include <bits/stdc++.h> using namespace std; long long c[2000010]; long long sum[2000010]; int main() { int n, x, y; while (cin >> n >> x >> y) { memset(c, 0, sizeof c); memset(sum, 0, sizeof sum); for (int i = 1; i <= n; i++) { int w; scanf( %d , &w); c[w]++; ... |
#include <bits/stdc++.h> using namespace std; long long int T = 1, inf = 10000000000; bool check(long long int n) { long long int flag = 1; while (n > 0) { if (n % 10 != 4 && n % 10 != 7) { flag = 0; break; } n /= 10; } return flag; } int main() { ios::syn... |
#include <bits/stdc++.h> using namespace std; const int M = 2e5 + 10; const int inf = 0x3f3f3f3f; const long long mod = 1e9 + 7; const int bit = 32; const double pi = acos(-1.0); int a[M]; int dfs(int k, int l, int r) { if (l > r) return 0; if (k < 0) return 1; int mid = r; int t = 1 << ... |
#include <bits/stdc++.h> template <class T> inline void read(T &x) { x = 0; int ne = 0; char c; while (!isdigit(c = getchar())) ne = c == - ; x = c - 48; while (isdigit(c = getchar())) x = (x << 3) + (x << 1) + c - 48; x = ne ? -x : x; return; } const int maxn = 1005; const in... |
#include <bits/stdc++.h> const int oo = 0x7fffffff; const long long OO = 0x7fffffffffffffff; using namespace std; const int NX = 50; typedef bitset<NX * NX * NX * NX> dp_t; int n; array<bitset<NX>, NX> board1, board2, done; dp_t dp1, dp2; int ask(int x1, int y1, int x2, int y2) { cout << ? << (... |
#include <bits/stdc++.h> using namespace std; template <class T> inline void read(T& x) { char c; bool f = 0; while ((c = getchar()) < 0 || 9 < c) f |= (c == - ); for (x = (c ^ 48); 0 <= (c = getchar()) && c <= 9 ; x = (x << 1) + (x << 3) + (c ^ 48)) ; if (f) x = -x; }... |
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; clock_t time_p = clock(); void rtime() { time_p = clock() - time_p; cerr << Time Taken : << fixed << (float)(time_p) / CLOCKS_PER_SEC << n ; } bool isPrime(long long n) { for (long long i = 2; i * i <= n; ++i) {... |
#include <bits/stdc++.h> using namespace std; int read(int &x) { return scanf( %d , &x); } int read(int &x, int &y) { return scanf( %d%d , &x, &y); } int read(int &x, int &y, int &z) { return scanf( %d%d%d , &x, &y, &z); } int read(long long &x) { return scanf( %lld , &x); } int read(long long &x, long long... |
#include <bits/stdc++.h> #pragma GCC optimize(2) #pragma GCC optimize(3) #pragma GCC optimize( Ofast ) #pragma GCC optimize( inline ) #pragma GCC optimize( -fgcse ) #pragma GCC optimize( -fgcse-lm ) #pragma GCC optimize( -fipa-sra ) #pragma GCC optimize( -ftree-pre ) #pragma GCC optimize( -ftree-vrp )... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cerr.tie(0); string s; long long p = 0, q = 0; cin >> s; for (int i = s.size() - 1; i > -1; i--) { if (s[i] == a ) { p += q; p = p % 1000000007... |
#include <bits/stdc++.h> using namespace std; char w[1555][1555]; int nm[1555][1555]; int n, m; struct cell { int x, y; }; void mark(int x, int y, int c) { queue<cell> q; cell T; T.x = x; T.y = y; q.push(T); while (!q.empty()) { T = q.front(); q.pop(); if (T.x... |
#include <bits/stdc++.h> using namespace std; const int sz = 1e5 + 50; map<int, int> prime, mark; void init() { prime[2] = 1; int limit = sqrt(sz) + 1; for (int i = 3; i <= sz; i += 2) { if (!mark[i]) { prime[i] = 1; if (i <= limit) { for (int j = i * i; j <= sz; j +=... |
#include <bits/stdc++.h> using namespace std; const int N = 100 + 7; const int M = 59; const int mid = M / 2; const int mod = 1e9 + 9; const int inf = 1e6 + 3; const long long linf = 1ll * inf * inf; const double pi = acos(-1); const double eps = 1e-7; const double ep = 1e-5; const int maxn = 1e5 ... |
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; int arr[1001]; int main() { int n, m, c; cin >> n >> m >> c; fill(arr, arr + n + 1, -1); int mid = (c + 1) / 2; bool done = 0; for (int j = 0; !done && j < m; j++) { int x; cin >> x; if (x > mid) { ... |
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; unsigned long long a[n], M; for (int i = 0; i < n; ++i) { cin >> a[i]; } stack<unsigned long long> s; M = *max_element(a, a + n); for (int i = 0; i < n; ++i) { a[i] = (M - a[i]) % 2; if (s.e... |
#include <bits/stdc++.h> using namespace std; const int N = 500 + 5, inf = 0x3f3f3f3f; namespace network_flow { struct edge { int to, nxt, val, cost; } e[N << 5]; int head[N], cnt = 1, maxflow, vis[N], dis[N], nxt[N]; int s, t; void add_edge(int x, int y, int z) { e[++cnt].to = y; e[cnt].val... |
#include <bits/stdc++.h> using namespace std; int n, i, j, a[100005], l, r; string s; int main(int argc, char *argv[]) { ios_base::sync_with_stdio(0), cin.tie(NULL); ; cin >> n; for (__typeof(i) i = 0; i < n; ++i) { cin >> a[i]; } cin >> s; l = -1000000000; r = 1000000000; ... |
#include <bits/stdc++.h> using namespace std; int i, j, k, l, x, y, z, m, n, ans; string s, a; int ara[10]; int main() { cin >> a >> s; for (int i = 0; i < s.size(); i++) { int x = s[i] - 0 ; ara[x]++; } for (int i = 0; i < a.size(); i++) { int x = a[i] - 0 ; for (int... |
#include <bits/stdc++.h> using namespace std; long int n, k; bool prime[10000001]; vector<long int> v; void sieve(long int n) { prime[0] = false; prime[1] = false; long int m = (long int)sqrt(n); for (long int i = 2; i <= m; i++) if (prime[i]) for (long int k = i * i; k <= n; k +... |
#include <bits/stdc++.h> const int maxn = 1e5 + 5, lim = 62, maxm = 65; const long long inf = 1e18; template <typename T> inline T min(T a, T b) { return a < b ? a : b; } int n; long long a[maxn], mod, dp[maxm][maxn]; inline bool Comp(long long a, long long b) { return a > b; } void radix_sort() {... |
#include <bits/stdc++.h> using namespace std; const int N = 100000 + 5; int n; int s[N], c[N]; map<int, int> a, b; int main() { int i; scanf( %d , &n); for (i = 0; i < n; i++) { scanf( %d , &s[i]); c[i] = s[i]; } printf( YES n ); if (n == 1) { printf( 0 n%d n , s[0]... |
#include <bits/stdc++.h> using namespace std; const int maxn = 200000 + 5; long long a[maxn]; map<long long, long long> mp, show; int main() { long long n, k, ans = 0; scanf( %lld%lld , &n, &k); for (int i = 0; i < n; i++) scanf( %lld , a + i); for (int i = n - 1; i >= 0; i--) { ans += m... |
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) using namespace std; const long double eps = 1e-7; const int inf = 1000000010; const long long INF = 10000000000000010LL; const int mod = 1000000007; const int MAXN = 200010, LOG = 20; int n, m, k, u, v, x, y, t, a, b; long long A[MAXN]; int par... |
#include <bits/stdc++.h> using namespace std; long long t, n, a[100011], sum[100011], ans; map<long long, long long> mp; signed main() { scanf( %lld , &t); while (t--) { mp.clear(); scanf( %lld , &n); memset(a, 0, sizeof a); memset(sum, 0, sizeof sum); ans = 0; for (r... |
#include <bits/stdc++.h> using namespace std; int main() { int n, k; int i, ans, j, t; int num[2005]; while (scanf( %d%d , &n, &k) != EOF) { ans = 0; for (i = 0; i < n; i++) scanf( %d , &num[i]); for (i = 0; i < n; i++) for (j = 0; j < n - i - 1; j++) if (num[j] >... |
#include <bits/stdc++.h> using namespace std; const long long INF = 3e18 + 5; int N; long long pt[100005][3]; long long ans[3]; pair<long long, long long> gSeg[4]; void input() { cin >> N; for (int i = 0; i < (N); i++) cin >> pt[i][0] >> pt[i][1] >> pt[i][2]; } inline long long mod2(long long ... |
#include <bits/stdc++.h> using namespace std; int i, j, k, sum; string a; int main() { cin >> a; int l = a.size(); j = 0; for (i = 0; i < l; i++) { if (a[i] == a ) { k++; } } if (k > l / 2) { j = l; } else { for (i = l - 1; i > 0; i--) { if (k... |
#include <bits/stdc++.h> using namespace std; int main() { int n, i; scanf( %d , &n); printf( %d n , n + n / 2); for (i = 2; n >= i; i = i + 2) { printf( %d , i); } for (i = 1; n >= i; i = i + 2) { printf( %d , i); } for (i = 2; n >= i; i = i + 2) { printf( %d , ... |
#include <bits/stdc++.h> using namespace std; mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); mt19937 rnf(2106); const int N = 100005; bool c[(1 << 22)]; int d[(1 << 22)]; int p[(1 << 22)]; void solv0(int n) { vector<int> v; for (int x = 0; x < n; ++x) { for (int y = x... |
#include <bits/stdc++.h> using namespace std; void cp() { ios ::sync_with_stdio(false); cin.tie(0); cout.tie(0); } long long power(long long x, long long y) { long long res = 1; while (y > 0) { if (y & 1) res = res * x; y = y >> 1; x = x * x; } return res; } int... |
#include <bits/stdc++.h> using namespace std; void __print(int first) { cerr << first; } void __print(long first) { cerr << first; } void __print(long long first) { cerr << first; } void __print(unsigned first) { cerr << first; } void __print(unsigned long first) { cerr << first; } void __print(unsigned l... |
#include <bits/stdc++.h> using namespace std; template <class T> inline T gcd(T a, T b) { return b == 0 ? a : gcd(b, a % b); } template <class T> inline T lcm(T a, T b) { return (a / gcd(a, b)) * b; } int main() { int n; int d = 210; cin >> n; if (n < 3) { cout << -1 << end... |
#include <bits/stdc++.h> using namespace std; vector<int> v; int main() { long long p, k; cin >> p >> k; while (p) { long long y = p % k; if (y < 0) y += k; v.push_back(y); p -= y; p /= k; p *= -1; } cout << v.size() << endl; for (int i = 0; i < v.size()... |
#include <bits/stdc++.h> using std::cin; using std::cout; using std::deque; using std::endl; using std::map; using std::max; using std::min; using std::multiset; using std::pair; using std::queue; using std::set; using std::sort; using std::stack; using std::string; using std::vector; in... |
#include <bits/stdc++.h> using namespace std; const int MAXN = 100005; struct EDGE { int num, next; } e[MAXN * 2]; int en = 0, start[MAXN]; inline void Add_edge(int p, int q) { en++; e[en].num = q; e[en].next = start[p]; start[p] = en; en++; e[en].num = p; e[en].next = start[... |
#include <bits/stdc++.h> using namespace std; int n, m; bool graph[101][101]; bool traversed[101]; void search(int x) { for (int i = 0; i <= m; i++) if (graph[x][i]) for (int k = 0; k < n; k++) if (graph[k][i] && !traversed[k]) { traversed[k] = true; search(... |
#include <bits/stdc++.h> using namespace std; string s1(const pair<string, string> &x) { return x.first.substr(0, 3); } string s2(const pair<string, string> &x) { return x.first.substr(0, 2) + x.second.substr(0, 1); } const int MAXN = 1050; vector<int> g[MAXN], mt; int used[MAXN]; bool dfs(const int... |
#include <bits/stdc++.h> using namespace std; const int N = 5; int vis[N][N][N]; int l[N], r[N]; double get_frac(int x, int y) { return (1.0 * x) / (1.0 * y); } double dfs(vector<vector<vector<double>>> &dp, int b, int cur, int g, int e, int n) { if (cur == n) { if (g == 0) re... |
#include <bits/stdc++.h> using namespace std; long long solve() { long long n; cin >> n; string str1, str2; cin >> str1 >> str2; long long freq1[26] = {0}; long long freq2[26] = {0}; for (long long i = 0; i < n; i++) { freq1[str1[i] - a ]++; freq2[str2[i] - a ]++; } ... |
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> v(n); for (int i = 0; i < n; ++i) cin >> v[i]; for (int i = 0; i < n; ++i) { if (v[i] != i + 1) { for (int j = n - 1; j >= 0; --j) { if (v[j] != j + 1) { reverse(begin(v) +... |
#include <bits/stdc++.h> using lint = long long int; using pii = std::pair<int, int>; using std::vector; int ve[200100]; bool check[200100]; int main(void) { int N, hol = 0; scanf( %d , &N); for (int i = 1; i <= N; i++) { int temp; scanf( %d , &temp); ve[i] = temp; } fo... |
#include <bits/stdc++.h> using namespace std; int etf(int n) { int res = n, i = 2; while (n > 1) { if (n % i == 0) { res -= res / i; while (n % i == 0) n /= i; } ++i; if (i * i > n) i = n; } return res; } int main() { ios::sync_with_stdio(0); int p... |
#include <bits/stdc++.h> using namespace std; const int N = 1010; int n, w, a[N]; int main() { cin >> n >> w; for (int i = 0; i < n; i++) { cin >> a[i]; } int lo = 0, hi = w, n_lo = 0, n_hi = w; for (int i = 0; i < n; i++) { n_lo += a[i]; n_hi += a[i]; if (n_lo > w ||... |
#include <bits/stdc++.h> using namespace std; const int MAXN = 1000010; struct node { int v, id; } MAX[MAXN], MMAX[MAXN]; int n, f[MAXN]; int main() { scanf( %d , &n); n++; MAX[1].v = MMAX[1].v = 0; MAX[1].id = MMAX[1].id = 1; for (register int i = 2; i <= n; i++) { scanf( %d ,... |
#include <bits/stdc++.h> using namespace std; int a[10000001]; int main() { int n, k = 0; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; } sort(a + 1, a + n); while (a[0] <= a[n - 1]) { a[0]++; a[n - 1]--; k++; sort(a + 1, a + n); } cout << k; ... |
#include <bits/stdc++.h> using namespace std; auto t1 = chrono::high_resolution_clock::now(); bool prime[100001]; long long int expo(long long int a, long long int b) { a = a % 1000000007; b = b % 1000000007; if (b == 0) return 1; if (b % 2) return ((a % 1000000007) * (expo((... |
#include <bits/stdc++.h> using namespace std; int main() { long long int n, l, a, x, y, sum, t[1000009], px, py; sum = 0; px = py = 0; cin >> n >> l >> a; for (int i = 0; i <= n; i++) { if (i == n) { t[i] = l - (px + py); break; } cin >> x >> y; if (i == 0... |
#include <bits/stdc++.h> using namespace std; void print(vector<long long int> &v) { long long int n = v.size(); for (long long int i = 0; i < n; i++) cout << v[i] << ; cout << n ; ; return; } vector<long long int> parent(200001); vector<long long int> size1(200001); long long int f... |
#include <bits/stdc++.h> using namespace std; int main() { int a, c, b, v, d, l, n; cin >> a >> b >> c; v = c / (b * 2); n = c % (b * 2); if (n > 0) { v += 1; } l = n / 2 + n % 2; if (l == 0) { l = b; } if (c % 2 == 0) { cout << v << << l << << R ; ... |
#include <bits/stdc++.h> using namespace std; inline long long read() { long long x = 0, f = 1; char c = getchar(); while (!isdigit(c)) { if (c == - ) f = -1; c = getchar(); } while (isdigit(c)) { x = (x << 3) + (x << 1) + (c ^ 48); c = getchar(); } return f == -... |
#include <bits/stdc++.h> using namespace std; long long solve(vector<long long> arr, int index, int currIndex) { if (currIndex == index) { return 1; } else { return 1 + solve(arr, index, arr[currIndex] - 1); } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); lo... |
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10; int N, M; vector<int> g[maxn]; long long out[maxn], in[maxn]; int main() { cin >> N >> M; for (int i = 1; i <= N; ++i) { g[i].clear(); out[i] = in[i] = 0; } for (int i = 1; i <= M; ++i) { int a, b; ... |
#include <bits/stdc++.h> using namespace std; vector<vector<long long> > neib; struct Square { long long max; long long diff; long long size; }; vector<long long> a; vector<Square> stat; vector<int> color; void dfs(int u) { color[u] = 1; stat[u].max += a[u]; if (neib[u].size() ==... |
#include <bits/stdc++.h> using namespace std; int n, k; int id[105]; int A[105]; int B[105]; long long dp[77][77]; bool check(int left, int right, int pos1, int pos2) { for (int i = 0; i < k; i++) { if (A[i] == pos1) { if (B[i] == pos2 && id[i] == 1) return false; if (B[i] <= lef... |
#include <bits/stdc++.h> using namespace std; void imp() { cout << 0 << endl; exit(0); } int n, m, q; int LCA[20][20]; vector<pair<int, int> > E; bool mat[20][20]; int mat2[20]; int Count[20][20]; int Bio[20]; int CheckDFS(int id, int p) { if (Bio[id] == 1) imp(); if (Bio[id] == 2)... |
#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> vc; vc.clear(); for (int i = 1; i <= sqrt(n); i++) { if (n / i != i) vc.push_back(n / i); ... |
#include <bits/stdc++.h> using namespace std; vector<int> XandY, XXX, YYY; int NOseg; int query(int x, int y) { cout << 0 << << x << << y << endl; int ret; cin >> ret; return ret; } void SOLVE(int l, int r) { if (l > r) return; int mid = (l + r) / 2; int x = query(mid, mi... |
#include <bits/stdc++.h> const int N = 60; int G[N][N], n, m, top; std::vector<int> v[500000]; inline void out() { puts( ); for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { printf( %d , G[i][j]); } puts( ); } puts( ); return; } inline int id(int... |
#include <bits/stdc++.h> using namespace std; long long n; string s, p; long long bin[34][34]; void read() { cin >> n; for (int i = 0; i <= 30; i++) { bin[i][0] = bin[i][i] = 1; for (int j = 1; j < i; j++) { bin[i][j] = bin[i - 1][j - 1] + bin[i - 1][j]; } } } void so... |
#include <bits/stdc++.h> using namespace std; int a, b, c, d, e, f; void read() { cin >> a >> b >> c >> d >> e >> f; } void solve() { int res = 0; res += (a + b + f) * (a + b + f); res -= f * f; res -= b * b; res -= d * d; cout << res << endl; } int main() { read(); solve(); ... |
#include <bits/stdc++.h> using namespace std; int A[100005], B[100005]; long long pwr[15]; int main() { int n, k, i; long long res = 1, MOD = 1000000007, c; cin >> n >> k; for (i = 0; i < n / k; i++) cin >> A[i]; for (i = 0; i < n / k; i++) cin >> B[i]; for (i = pwr[0] = 1; i <= 10; i++)... |
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { int n = 8; bool ww = 1; int con = 0; while (n--) { string s; cin >> s; bool tb = 1; for (int i = 0; i < s.size(); i++) { if (s[i] == W ) { tb = 0; } } if ... |
#include <bits/stdc++.h> using namespace std; template <class T> inline void read(T& x) { char c; bool f = 0; while ((c = getchar()) < 0 || 9 < c) f |= (c == - ); for (x = (c ^ 48); 0 <= (c = getchar()) && c <= 9 ; x = (x << 1) + (x << 3) + (c ^ 48)) ; if (f) x = -x; }... |
#include<bits/stdc++.h> using namespace std; #define int long long void hota(){ int n,m,x; cin>>n>>m>>x; vector<pair<int,int>> v; for (int i = 0; i < n; ++i) { int x; cin>>x; v.push_back(make_pair(x,i+1)); } sort(v.begin(), v.end()); std::vector<int> ans(m,0); ... |
#include <bits/stdc++.h> using namespace std; vector<string> substrings; bool cmp(pair<int, int> &a, pair<int, int> &b) { if (a.first < b.first) return true; if (a.first > b.first) return false; if (substrings[a.second].length() > substrings[b.second].length()) return true; return false; }... |
#include <bits/stdc++.h> using namespace std; map<string, string> mp; string get_type(string s) { if (mp.count(s)) return mp[s]; int n = s.size(); if (s[0] == & && s[n - 1] == * ) return get_type(s.substr(1, n - 2)); if (s[0] == & ) { string ret = get_type(s.substr(1, n - 1)); int ... |
#include <bits/stdc++.h> using namespace std; const int N = 8; int main() { char r1, r2; int x1, x2; while (4 == scanf( %c%d %c%d , &r1, &x1, &r2, &x2)) { int y1 = r1 - a ; int y2 = r2 - a ; --x1; --x2; int ans = 0; for (int y = 0; y < (int)(N); y++) for ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.