func_code_string stringlengths 59 71.4k |
|---|
#include <bits/stdc++.h> using namespace std; const int N = 400000; int a[N], t[N], type[N], us[N]; int main() { ios::sync_with_stdio(0); int n, w, k; cin >> n >> w >> k; for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < n; i++) { cin >> t[i]; } int r =... |
#include <bits/stdc++.h> #pragma GCC optimize( O3 ) using namespace std; using ll = long long; using pii = pair<ll, int>; const int INF = 1e9 + 1e2; void fin() {} const bool flag = 0; const int N = 1e5 + 10; int MOD; int mult(ll a, ll b) { return a * 1ll * b % MOD; } ll binpow(ll a, int b) { l... |
#include <bits/stdc++.h> using namespace std; bool sePuede(int rango[], int x) { if (x % 2 == 1 && rango[0] == 1 && rango[x - 1] == 1) return true; return false; } int main() { int x = 0; int impar = 0; cin >> x; int rango[x]; for (int y = 0; y < x; y++) { cin >> rango[y]; ... |
#include <bits/stdc++.h> using namespace std; void go(int parent, int node, int depth, int& odd_count, int& even_count, vector<vector<int>>& tree) { int count = 0; for (int i = 0; i < tree[node].size(); i++) { if (tree[node][i] != parent) { count++; go(node, tree[node][i], de... |
#include <bits/stdc++.h> using namespace std; string s; int main() { cin >> s; bool ms = false; string a; string b; if (s[0] == - ) ms = true; bool flag = false; bool p = ms; for (int i = 0; i < s.size(); i++) { if (p) { p = false; continue; } if ... |
#include <bits/stdc++.h> using namespace std; int main() { long long t; cin >> t; while (t--) { long long n; cin >> n; int a[n], b[n]; for (int i = 0; i < n; i++) cin >> a[i]; string s; cin >> s; vector<pair<long long, pair<long long, long long>>> c(n); fo... |
#include <bits/stdc++.h> using namespace std; long long dp_cata[3021][5021]; int main() { dp_cata[0][0] = 1; for (long long j = 0; j <= 5001; j++) for (long long i = 0; i <= 3001; i++) { if (i == 0) { if (j != 0) dp_cata[i][j] = dp_cata[i + 1][j - 1]; } else dp_ca... |
#include <bits/stdc++.h> using namespace std; int n, m, ans; int G[10][10]; int p[10]; bool vis[10][10]; void dfs(int cur) { if (cur > n) { memset(vis, 0, sizeof(vis)); int cnt = 0; for (int i = 1; i <= n; i++) { for (int j = i + 1; j <= n; j++) { if (!G[i][j]) contin... |
#include<bits/stdc++.h> #define ll long long #define ld long double #define ff first #define ss second #define eb emplace_back #define pb push_back #define mp make_pair #define all(x) begin(x), end(x) #define endl n int dx[4] = {1, -1, 0, 0}; int dy[4] = {0, 0, -1, 1}; // ll dp[100005]; ... |
#include <bits/stdc++.h> using namespace std; int main() { map<pair<int, int>, int> dat; vector<pair<int, int> > p; int np; cin >> np; int res = 0; while (np--) { int x, y; cin >> x >> y; p.push_back(make_pair(x, y)); dat[make_pair(x, y)] = 1; } int sz = p.siz... |
#include <iostream> #include <cstdio> #define mod 998244353 #define int long long using namespace std; int n,k,sa[200005],rk[200005]; int num; inline int Qpow(register int a,register int p){ if (p==0)return 1; register int t=Qpow(a,p/2); t=t*t%mod; if (p%2==1)t=t*a%mod; return t; } inli... |
#include <bits/stdc++.h> using namespace std; int arr[7]; int main() { int n, len; string str; scanf( %d n , &n); for (int i = 0; i < n; i++) { getline(cin, str); for (int j = 0; j < 7; j++) { arr[j] += (str[j] - 0 ); } } int mx = 0; for (int i = 0; i < 7; i+... |
#include <bits/stdc++.h> using namespace std; struct P { double x, y; } a[259]; long long f[259][259]; int n; int read() { long long x = 0, f = 1; char ch = getchar(); while (!isdigit(ch)) { if (ch == - ) f = -1; ch = getchar(); } while (isdigit(ch)) { x = x * 10 +... |
#include <bits/stdc++.h> using namespace std; long long n, f, a, b; vector<long long> V; long long ans; int main() { scanf( %lld %lld , &n, &f); for (int i = 1; i <= n; i++) { scanf( %lld %lld , &a, &b); if (a >= b) { V.push_back(0); ans += b; } else { if (a *... |
#include <bits/stdc++.h> using namespace std; int customer[1000][1000]; int main() { int n, m, k; cin >> n >> m >> k; deque<int> dq; for (int i = 0; i < k; i++) { int x; cin >> x; dq.push_back(x); } for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) cin >> cu... |
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; string s; cin >> n >> s; string an = ; for (int i = 0; i < s.length(); i += 2) { cout << s[i]; } cout << endl; } } |
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; if (n == 1) { cout << 1; return 0; } for (long long i = 2; i * i <= n; i++) { if (n % i == 0) { while (n % i == 0) { n /= i; } if (n == 1) { cout << i; ... |
#include <bits/stdc++.h> using namespace std; void solve() { int n; cin >> n; string s = bitset<32>(n).to_string(); vector<int> v; for (int i = 31; i >= 0; i--) { if (s[i] == 1 ) { v.push_back(32 - i); } } reverse(v.begin(), v.end()); for (int& a : v) { cou... |
#include <bits/stdc++.h> using namespace std; const int N = 42; long long dp[N][N]; int f[N], n; string s; long long Solve(int x) { memset(dp, 0, sizeof dp); dp[0][x] = 1; for (int i = 0; i < n; i++) { for (int j = 0; j < s.size(); j++) { int m = j; while (m && s[m] != 0 )... |
#include <bits/stdc++.h> using namespace std; const int maxn = 200000 + 10; const int hashnum = 3; long long base[] = {233, 23, 97}; long long mod[] = {122420729, 1000000007, 1000000009}; int sum[maxn]; char s[maxn]; long long power[hashnum][maxn]; int n; struct node { long long hv[hashnum]; ... |
#include <bits/stdc++.h> const double Pi = 3.14159265; const int N = 1e6 + 50; const int M = 1e5 + 15; const unsigned long long base = 163; const int INF = 0x3f3f3f3f; using namespace std; int a[N]; int main() { int n; scanf( %d , &n); int l = 0, r = 0; for (int i = 1; i <= n; i++) { ... |
#include <bits/stdc++.h> using namespace std; const int INF = 1e9 + 7; const int MOD = 1e9 + 7; const int MAXN = 1e6 + 3; struct Rcompare { bool operator()(pair<int, int> lhs, pair<int, int> rhs) { return lhs.first > rhs.first; } }; struct compare { bool operator()(pair<int, int> lhs, pa... |
#include <bits/stdc++.h> using namespace std; int n; int bin[31]; int cnt; int ch[6000010][2]; void insert(int x) { for (int i = 30; i >= 0; --i) { bin[i] = x & 1; x >>= 1; } int now = 0; for (int i = 0; i <= 30; ++i) { if (!ch[now][bin[i]]) { ch[now][bin[i]] = ++cn... |
#include <bits/stdc++.h> using namespace std; int arr[4], sum; string s; int main() { cin >> arr[0] >> arr[1] >> arr[2] >> arr[3] >> s; for (int i = 0; i < s.size(); i++) { sum += arr[s[i] - 49]; } cout << sum; } |
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const long long INFL = 0x3f3f3f3f3f3f3f3fLL; const long double eps = 1e-8; const int MAXN = 100000 + 5; pair<long double, long double> X[MAXN << 2]; inline pair<long double, long double> calc(const int& a, const int& b) { long d... |
#include <bits/stdc++.h> using namespace std; template <typename T> inline T read() { T x = 0, f = 0; char c = getchar(); while (!isdigit(c)) f = c == - , c = getchar(); while (isdigit(c)) x = x * 10 + c - 48, c = getchar(); return f ? -x : x; } namespace run { const long long N = 2e5 +... |
#include <bits/stdc++.h> using namespace std; struct Node { int id, a, b; } node[111111], zhan[111111]; bool cmp1(Node a, Node b) { return a.a > b.a || (a.a == b.a && a.b > b.b); } bool cmp2(Node a, Node b) { return a.b > b.b || (a.b == b.b && a.a < b.a); } int main() { int n, p, k; scanf( %d%d%... |
#include <bits/stdc++.h> using namespace std; struct ent { int val, pos; inline bool operator<(const ent &cpr) const { return val < cpr.val; } }; set<ent> pq; int n; int val[300005]; long long sum[300005]; long long ret; int a, b; int del[300005]; int dcnt; int main() { ret = -100000... |
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 100; const int LVL = 18; int n, m; int a[N]; int b[N]; int c[N]; int h[N]; int inplace[N], parent[N]; int inmst[N]; int dp[N][LVL], mini[N][LVL], maxi[N][LVL]; int ans[N]; vector<int> tree[N]; int find(int node) { if (pare... |
#include <bits/stdc++.h> using namespace std; template <typename T, typename U> inline void smin(T &a, U b) { if (a > b) a = b; } template <typename T, typename U> inline void smax(T &a, U b) { if (a < b) a = b; } template <typename T> inline void gn(T &first) { char c, sg = 0; while (... |
#include <bits/stdc++.h> using namespace std; int main() { set<string> s1, s2, s3; s3.clear(); s1.clear(); s2.clear(); int n, m; cin >> n >> m; string str = ; for (int i = 0; i < n; i++) { cin >> str; s1.insert(str); } for (int i = 0; i < m; i++) { cin >> ... |
#include <bits/stdc++.h> using namespace std; int card[10010]; int main() { int n, r, s = 0, d = 0, l = 1, num = 0; cin >> n; r = n; for (int i = 1; i <= n; i++) { cin >> card[i]; } while (l <= r) { num++; if (num & 1) { if (card[l] > card[r]) { s += car... |
#include <bits/stdc++.h> using namespace std; int dp[200010][33]; void generate() { for (long long i = 1; i <= (200000); i++) { for (long long j = 0; j < (32); j++) { dp[i][j] = dp[i - 1][j] + !((1 << j) & i); } } } int main() { ios::sync_with_stdio(false); cin.tie(0); ... |
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; const long long inf = 9e18; struct NODE { long long v, id; bool operator<(const NODE& other) const { return v > other.v || (v == other.v && id > other.id); } } node[N]; long long a[N], b[N]; long long n; long long f(... |
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5, M = 2e4 + 5, inf = 0x3f3f3f3f, mod = 1e9 + 7; void Print(int *a, int n) { for (int i = 1; i < n; i++) printf( %d , a[i]); printf( %d n , a[n]); } int e[N], nt[N]; void Gnt(string a, int *nt) { int k = 0, p = 0, n = (int)a.size... |
#include <bits/stdc++.h> using namespace std; vector<int> gr[50005]; int parent[50005]; void dfs(int src, int par) { parent[src] = par; for (auto nbr : gr[src]) { if (nbr != par) dfs(nbr, src); } } int main() { int n, x, y; cin >> n >> x >> y; for (int i = 1; i <= n; i++) { ... |
#include <bits/stdc++.h> using namespace std; int main() { int casos; cin >> casos; while (casos > 0) { int a, b; cin >> a >> b; if (a > b) { int dif = a - b; b -= dif; a -= dif * 2; } else if (b > a) { int dif = b - a; a -= dif; b ... |
#include <bits/stdc++.h> using namespace std; int n, m, a[100005], is[100005], isn[100005], N, used[100005]; vector<int> v; int main() { cin >> n >> m; for (int i = 1; i <= n; i++) { char t; int ind; cin >> t >> ind; a[i] = ind; if (t == + ) is[ind]++; else {... |
#include <bits/stdc++.h> using namespace std; bool solved; const int MX = 1500000; int cache_map[1 << 22]; int nxt; int cache[MX][22]; void check_solution(vector<int>& g, vector<int>& sol, int n) { int mask(0); int ind(nxt); nxt += 1; if (nxt == MX) nxt = 0; if (((int)sol.size()) != 1)... |
#include <bits/stdc++.h> using namespace std; const int N = 100009; int n; long long a[N]; void print_ans(int l, int r, vector<long long>& v) { cout << l << << r << n ; for (long long vv : v) { cout << vv << ; } cout << n ; } int main() { ios_base::sync_with_stdio(fals... |
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; long long f = n * (n - 1) * (n - 2) * (n - 3) * (n - 4); cout << (f / 120) * ((n * n) - (4 * n) + 37) / 42; return 0; } |
#include <bits/stdc++.h> using namespace std; int n, k, x; vector<long long> a; void ans() { for (int i = 0; i < n; i++) { cout << a[i] << ; } exit(0); } int main(int argc, char* argv[]) { srand((unsigned int)time(NULL)); cin >> n >> k >> x; a.resize(n); int ch = 1; ... |
#include <bits/stdc++.h> using namespace std; int t; long long n; int main() { cin >> t; while (t--) { cin >> n; long long num; for (long long i = 1; i < n; i++) { if (i * i > n) { num = i - 1; break; } else if (i * i == n) { num = i; ... |
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; vector<int> v(n), v1(m); for (int i = 0; i < n; ++i) { cin >> v[i]; } for (int i = 0; i < m; ++i) { cin >> v1[i]; } vector<int> ans; for (int i = 0; i < n; ++i) { for (int j = 0;... |
#include <bits/stdc++.h> using namespace std; int n, d; int main() { cin >> n >> d; int m; cin >> m; for (int i = 1; i <= m; i++) { int x, y; cin >> x >> y; puts((d <= x + y && x + y <= 2 * n - d && -d <= x - y && x - y <= d) ? YES : NO ); } ... |
#include <bits/stdc++.h> using namespace std; int n, m; int x[2600], y[2600]; string a[60]; bool valid(int y, int x1, int y1, int x, int x2, int y2) { for (int i = min(x1, x2); i <= max(x1, x2); i++) { if (a[i][y] != B ) { return false; } } for (int i = min(y1, y2); i <= max(y... |
#include <bits/stdc++.h> using namespace std; const long long MAX_N = 1e5 + 5; long long n, val; pair<pair<long long, long long>, pair<long long, long long> > edge[MAX_N]; long long par[MAX_N]; long long len[MAX_N]; vector<long long> h; vector<long long> ans; vector<pair<long long, long long> > G[MAX_... |
#include <bits/stdc++.h> template <typename T> struct xgcd_s { T m, n, gcd; }; template <typename T> xgcd_s<T> xgcd(T a, T b) { T m[] = {1, 0}, n[] = {0, 1}, q[] = {0, 0}; for (int i = 0;; i ^= 1) { m[i] -= m[i ^ 1] * q[i]; n[i] -= n[i ^ 1] * q[i]; if (!b) return xgcd_s<T>{m[i], ... |
#include <bits/stdc++.h> using namespace std; int m, k, d; void print(int a, int b) { printf( %d %d n , a, b); a += d, b += d; printf( %d %d n , a, b); } int main() { cin >> k; if (k % 2 == 0) { cout << NO ; return 0; } cout << YES << endl; d = 4 * k - 2, m = (k ... |
#include <bits/stdc++.h> const long long int mod = 9999999999999983; long long int primes[6] = {1125899906842597, 1495921043, 1005985879, 1495921043, 1005985879, 1495921043}; using namespace std; vector<string> vect; long long int level[1000009]; vector<string> vt[1000009]... |
#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); } int a[100005]; long long s[100005], b[100005]; int main() { int n; cin >> n; for (int i = 0; i < n; ++i) scanf( %d , a + i); sort(a, a + n); s[0] ... |
#include <bits/stdc++.h> using namespace std; int main() { int n, count = 0; vector<int> vect, keep; cin >> n; while (n != 0) { keep.push_back(n % 10); n = n / 10; ++count; } reverse(keep.begin(), keep.end()); for (auto itr = keep.begin(); itr != keep.end(); itr++) { ... |
#include <bits/stdc++.h> using namespace std; struct QUERY { int query, time, number; }; vector<map<int, int> > tree; void update(int v, int tl, int tr, int pos, int query, int value) { int tm = (tl + tr) / 2; if (query == 1) { if (tl == tr) return; tree[v][value]++; if (pos <= t... |
#include <bits/stdc++.h> using namespace std; const int maxn = 1010; set<int> X, Y; int n, m; char st[maxn][maxn], sz[maxn][maxn]; bool fill(int x1, int y1, int x2, int y2) { int i; for (i = x1; i <= x2; ++i) { if (st[i][y1] == . ) return 0; if (st[i][y2] == . ) return 0; sz[i][y... |
#include <bits/stdc++.h> int s, k; long long f[1000], res[1000]; int main() { scanf( %d %d , &s, &k); f[0] = 0; f[1] = 1; int i; for (i = 2; f[i - 1] <= s; i++) for (int j = 1; i - j > 0 && j <= k; j++) f[i] += f[i - j]; int cnt = 0; for (i = i - 1; i >= 0; i--) if (f[i] <=... |
#include <bits/stdc++.h> using namespace std; int main() { int w, h, h1, w1, h2, w2; cin >> w >> h >> w1 >> h1 >> w2 >> h2; for (int i = h; i >= 0; i--) { w += i; if (i == h1) w -= w1; if (i == h2) w -= w2; if (w < 0) w = 0; } cout << w << endl; return 0; } |
#include <bits/stdc++.h> using namespace std; long long n, m, cnt, num, sub_d[(2600)], d[(2600)], root, cut[(2600)], t; char s[55][55]; bool mark[(2600)], p, cycle; vector<long long> e[(2600)]; void dfs(long long x, long long par = 0) { bool tmp = 0; if (!t) cnt++; mark[x] = 1; sub_d[x] = d[... |
#include <bits/stdc++.h> using ll = long long int; int main() { int n, m; std::cin >> n >> m; std::vector<std::vector<int>> matr1(n); std::vector<std::vector<int>> matr2(n); std::vector<std::vector<int>> matr_min(n); std::vector<std::vector<int>> matr_max(n); for (int i = 0; i < n; i++) ... |
#include <bits/stdc++.h> using namespace std; int ans[15]; int n, q; string in; string tmp; void go(int l, int r) { tmp = + in.substr(l - 1, r - l + 1); string::iterator cp = tmp.begin() + 1; int dp = 1; while (cp != tmp.begin() && cp != tmp.end()) { if (*cp >= 0 && *cp <= 9 ) {... |
#include <bits/stdc++.h> using namespace std; string to_string(char c) { return string(1, c); } string to_string(bool b) { return b ? true : false ; } string to_string(const char* s) { return (string)s; } string to_string(string s) { return s; } template <class A> string to_string(complex<A> c) { s... |
#include <bits/stdc++.h> using namespace std; int n; string s[] = { Mahmoud , Ehab }; int main() { cin >> n; cout << s[n % 2]; } |
#include <bits/stdc++.h> using namespace std; using pii = pair<int, int>; int m, n; pii a[100001]; vector<int> adj[100001]; bool is_chosen[100001]; bool is_visited[100001]; int cnt = 0; template <typename T> inline T read() { T x = 0; T multiplier = 1; char ch = getchar(); while (ch ... |
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); long long n; cin >> n; long long result = 1; long long x = n; for (long long i = 2; i * i <= x; ++i) { if (n % i == 0) { result *= i; while (n % i == 0) n /= i; } } res... |
#include <bits/stdc++.h> using namespace std; int n, k, a[100005], vis[100005], cnt, t; void Solve() { scanf( %d %d , &n, &k); for (int i = 1; i <= n; ++i) { scanf( %d , &a[i]); if (!vis[a[i]]) cnt++; ++vis[a[i]]; if (cnt == k) { t = 1; while (cnt == k) { ... |
#include <bits/stdc++.h> using namespace std; char s[200010]; int n; bool query(int x) { int t = -1, l = -1; for (int i = 0; i < n; i++) { l--; if (s[i] == . ) continue; if (s[i] == P ) { if (t == -1) t = i; int tmp = max(x - (i - t) * 2, (x - (i - t)) / 2); l... |
#include <bits/stdc++.h> using namespace std; int read() { int x = 0, sgn = 1; char ch = getchar(); for (; !isdigit(ch); ch = getchar()) if (ch == - ) sgn = -1; for (; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + (ch ^ 48); return x * sgn; } const int N = 1e5 + 10; int n; ... |
#include <bits/stdc++.h> using namespace std; const long long N = 1e5 + 5; const long long mod = 1e9 + 7; void solve(); signed main() { ios::sync_with_stdio(false); cin.tie(0); long long tests = 1; while (tests--) solve(); return 0; } void solve() { long long n; cin >> n; p... |
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native ) template <class T = int> inline T readInt(); inline double readDouble(); inline int readUInt(); inline int readChar(); inline void readWord(char *s); inline bool readLin... |
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 10; const long long INF = 1e9 + 19; int n; pair<long long, long long> b[N]; long long T; void read() { scanf( %d , &n); long long w; scanf( %lld%lld , &T, &w); n--; for (int i = 0; i < n; i++) { scanf( %lld%lld , &... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cout.precision(10); int n; cin >> n; if (n % 2) { cout << black n ; } else { cout << white n ; cout << 1 << << 2 << endl; } retu... |
#include <bits/stdc++.h> using namespace std; const long long N = 1e6 + 10, inf = 1e18, mod = 1e9 + 7; long long a[N], b[N], q[N], q2[N]; unordered_map<int, int> mp; vector<long long> cmp; struct node { int l, r, col = 0; int size() { return r - l; } int unity(int lq, int rq) { return max(0, min... |
#include <bits/stdc++.h> using namespace std; void solve() { long long n, x; cin >> n >> x; set<long long> s; long long a; for (long long i = 0; i < n; i++) { cin >> a; s.insert(a); } for (auto it = s.begin(); it != s.end(); it++) { if (*it <= x) x++; else... |
#include <bits/stdc++.h> using namespace std; int n, m, flow[200100][2], dtion[200100], Eg[200100]; bool vis[200100]; queue<int> q; struct node { int v, d, i; node *next; } edge[200100 * 2]; node *cnt = &edge[0]; node *adj[200100]; void Addedge(int u, int v, int d, int i) { node *p = ++cnt... |
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const long long mod = 1e9 + 7; const int maxn = 1e5 + 5; long long a[15], b[15]; int main() { for (int i = 0; i < 14; ++i) { cin >> a[i]; } long long ans = 0; for (int i = 0; i < 14; ++i) { if (a[i] == 0) c... |
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; int arr[N + 1]; for (int i = 0; i < N; i++) { cin >> arr[i]; } sort(arr, arr + N); if (arr[0] != arr[N / 2]) cout << Alice << endl; else cout << Bob << endl; return 0; } |
#include <bits/stdc++.h> using namespace std; int ans = 0; int n; int tree[10001]; int dp[10001] = {0}; int main() { cin >> n; int a[100001]; int tot = pow(2, n + 1) - 2; for (int i = 2; i <= tot + 1; i++) { cin >> a[i]; } tree[0] = 0; tree[1] = 0; int ma = 0; for (... |
#include <bits/stdc++.h> using namespace std; long long mod = 1e9 + 7; int mem[2005][2005], n, h, l, r; int arr[2005]; int f(int inx, int hour) { if (inx >= n) return 0; if (mem[inx][hour] != -1) return mem[inx][hour]; int a = f(inx + 1, (hour + arr[inx]) % h); int b = f(inx + 1, (hour + arr[i... |
#include <bits/stdc++.h> using namespace std; int main() { int n, k, i = 0, d = 2; cin >> n >> k; vector<int> v; while (i < k - 1 && n != 1) { if (n % d == 0) { n /= d; v.push_back(d); i++; } else { d++; } } if (n != 1) v.push_back(n); if... |
#include <bits/stdc++.h> using namespace std; const int MAX_N = 1000000 + 20; int used[MAX_N]; int a[MAX_N]; int n, k; int main() { ios::sync_with_stdio(false); cin >> n >> k; for (int i(0); i < int(n); i++) { int x; cin >> x; ++used[x]; } int sum = 0; for (int i = ... |
#include <bits/stdc++.h> using namespace std; int main() { int n, a; long long k; cin >> n >> k; vector<int> arr(n), c(n); for (int i = 0; i < n; i++) { cin >> arr[i]; } cin >> a; for (int i = 0; i < n; i++) { cin >> c[i]; } set<int> m; long long ans = 0; ... |
#include <bits/stdc++.h> using namespace std; int n; int dpr[300005]; int dpl[300005]; int A[300005]; pair<int, int> B[300005]; int fr(int pos) { if (A[pos] == 0) return pos - 1; if (pos == n - 1) return n - 1; if (dpr[pos] != -1) return dpr[pos]; dpr[pos] = fr(pos + 1); return dpr[pos... |
#include <bits/stdc++.h> #pragma GCC optimize( O3 , unroll-loops ) #pragma GCC target( avx2 ) using namespace std; inline long long add(long long a, long long b) { return ((a + b) < 1000000007 ? (a + b) : (a + b - 1000000007)); } int prime[1000005]; void seive() { prime[0] = prime[1] = 1; for... |
#include <bits/stdc++.h> using namespace std; map<string, int> f, reff; int n, m, q, w[13], ans[4097][101]; string s; string tob(int x) { string t = ; while (x > 0) { x % 2 == 0 ? t = 0 + t : t = 1 + t; x /= 2; } while (t.length() < n) { t = 0 + t; } return t;... |
#include <bits/stdc++.h> int main(int agrc, char* argv[]) { int N, M; scanf( %d %d , &N, &M); char room[625]; for (int i = 0; i < N * M; i++) scanf( %c , room + i); int dp[625]; for (int i = 0; i < M * M; i++) dp[i] = 0; int best = 0; for (int r = 0; r < N; r++) { for (int pl = ... |
#include <bits/stdc++.h> using namespace std; const long long INF = (1LL << 60); priority_queue<long long> pqr, pqc; int sum_r[1005], sum_c[1005], k, p; long long row[1000001], col[1000001]; void cal(int cnt, priority_queue<long long> pq, long long res[1000001]) { long long ans = 0; for (int i = 1; ... |
#include <iostream> #include <cmath> using namespace std; int main() { int t; cin >> t; while (t--) { double n; cin >> n; if (sqrt(n / 2) == (int)sqrt(n / 2)) { cout << YES n ; } else { if (sqrt(n / 4) == (int)sqrt(n / 4)) { cout << YES n ; } else cout <... |
#include <bits/stdc++.h> using namespace std; bool cmp(int a, int b) { return a > b; } int main() { long long a[100005]; long long b[100005]; int n; cin >> n; long long sum = 0; for (int i = 1; i <= n; i++) { cin >> a[i]; sum += a[i]; } for (int i = 1; i <= n; i++) cin ... |
/* Miles Morales : When will I know I m ready? Peter B. Parker : You won t. It s a leap of faith. That s all it is, Miles. A leap of faith. */ //KEEP IT SIMPLE STUPID #include <bits/stdc++.h> #pragma GCC optimize( O3 ) #pragma GCC target( avx ) #pragma GCC optimize( Ofast ) #pragma GCC optimize(... |
#include <bits/stdc++.h> using namespace std; const int N = 2004; int dp[N], dq[N], a[N], n; int main() { scanf( %d , &n); for (int i = 1; i <= n; i++) scanf( %d , &a[i]); for (int i = 1; i <= n; i++) { dp[i] = 1; for (int j = 1; j < i; j++) if (a[i] >= a[j]) dp[i] = max(dp[i], d... |
#include <bits/stdc++.h> using namespace std; const double PI = 3.14159265358979323846; const double eps = (1e-9); int dcmp(double x, double y) { return fabs(x - y) <= eps ? 0 : x < y ? -1 : 1; } int n, m; int mem[200000]; int minMoves(int x) { if (x == m) return 0; int& ret = mem[x]; if (ret ... |
#include <bits/stdc++.h> using namespace std; int main() { int a, b, f, k; cin >> a >> b >> f >> k; int now = b; int ret = 0; for (int i = 1; i <= k; i++) { if (i % 2 == 1) { if (now < f) { return puts( -1 ), 0; } if (i == k) { if (now < a) { ... |
#include <bits/stdc++.h> using namespace std; typedef struct SPoint { double X, Y; SPoint(double X = 0, double Y = 0) : X(X), Y(Y) {} double abs() { return sqrt(X * X + Y * Y); } double sqrAbs() { return X * X + Y * Y; } } TPoint; TPoint operator-(const TPoint& shl, const TPoint& shr) { retu... |
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 7; int a[MAXN], n, p, lim = 0; bool check(int val) { for (int i = 1; i <= n; ++i) if (val + i - 1 < a[i]) return 0; return 1; } bool valid(int val) { int sta = 0; for (int i = 0; i < n; ++i) { while (sta + 1 <= ... |
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; long long p = 1000000000; vector<int> a; a.resize(n); long long fib[100]; fib[0] = 1; fib[1] = 1; for (long long i = 2; i < 100; i++) fib[i] = (fib[i - 1] + fib[i - 2]) % p; for (int i = 0; i ... |
#include <bits/stdc++.h> using namespace std; const int M = 5555; const int N = 205; int col[2][M][N]; void dfs(int p, int x, int y, int c0, int c1) { int t = col[p ^ 1][y][c0]; col[p][x][c0] = y; col[p ^ 1][y][c0] = x; if (!t) { col[p ^ 1][y][c1] = 0; return; } dfs(p ^ 1, ... |
#include <bits/stdc++.h> using namespace std; int main() { int n, a; cin >> n; long long arr[n], sum[n], ans[n]; for (int i = 0; i < n; i++) { cin >> arr[i]; sum[i] = arr[i]; if (i > 0) sum[i] += sum[i - 1]; } sort(arr, arr + n); for (int i = 0; i < n; i++) { ans[... |
#include <bits/stdc++.h> using namespace std; int main() { int i, n, k; cin >> n >> k; for (i = 0; i < k; i++) { if (n % 10 == 0) { n /= 10; } else { n--; } } cout << n << endl; return 0; } |
#include <bits/stdc++.h> using namespace std; class BigInt { public: int sign; string s; BigInt() : s( ) {} BigInt(string x) { *this = x; } BigInt(int x) { *this = to_string(x); } BigInt negative() { BigInt x = *this; x.sign *= -1; return x; } BigInt normalize(i... |
#include <bits/stdc++.h> using namespace std; int main() { int ans, n, m; cin >> n >> m; ans = (n * m) / 2; cout << ans; return 0; } |
#include <bits/stdc++.h> const double PI = acos(-1.0); const double e = exp(1.0); const int INF = 0x7fffffff; ; template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; } template <class T> T lcm(T a, T b) { return a / gcd(a, b) * b; } template <class T> inline T Min(T a, T b) ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.