func_code_string stringlengths 59 71.4k |
|---|
#include <bits/stdc++.h> using namespace std; int N; char S[1010]; int E[1010], F[1010][2]; int main() { scanf( %d , &N); scanf( %s , S); memset(E, 0, sizeof(E)); for (int i = 0; i < N; i++) { E[i + 1] = S[i] - 0 ; F[i + 1][0] = F[i + 1][1] = 0x3f3f3f3f; } F[0][0] = F[0][1... |
#include <bits/stdc++.h> using namespace std; int main() { long long t; cin >> t; while (t--) { long long n, k, i; cin >> n >> k; long long a[n], s = INT_MAX, l = INT_MIN; for (i = 0; i < n; i++) { cin >> a[i]; s = min(s, a[i]); l = max(l, a[i]); } ... |
#include <bits/stdc++.h> using namespace std; int main() { list<unsigned long long int> blind; list<unsigned long long int>::iterator bite, tempite; unsigned long long int total, l, maxarea = 0, sum, i; cin >> total >> l; for (i = 0; i < total; ++i) { cin >> sum; if (sum >= l) blind.... |
#include <bits/stdc++.h> using namespace std; vector<int> g[100006]; vector<int> located[100006]; int parent[100006], level[100006], visited[100006]; int ancestor[100006][18]; vector<int> st[100006][18]; void dfs(int u) { visited[u] = 1; for (int i = 0; i < g[u].size(); i++) { int v = g[u][i... |
#include <bits/stdc++.h> using namespace std; int main() { double i, j, h, l, num; cin >> h >> l; num = (l * l - h * h) / (2 * h); cout << (fixed) << setprecision(12) << num; return 0; } |
#include <bits/stdc++.h> using namespace std; const int N = 100005; long long b, q, l, m, a[N]; map<long long, int> vis; int main() { scanf( %lld%lld%lld%lld , &b, &q, &l, &m); while (m--) { long long x; scanf( %lld , &x); vis[x] = 1; } if (max(-b, b) > l) { printf( 0 n... |
#include <bits/stdc++.h> using namespace std; int dp[100001]; int res[100001]; vector<vector<pair<int, int> > > g(1e5 + 2); int check(int v) { if (dp[v]) { return dp[v]; } dp[v] = 1; for (int i = 0; i < g[v].size(); i++) { int nxt = g[v][i].first; if (check(nxt) + 1 > dp[v]) ... |
#include <bits/stdc++.h> using namespace std; const int N = 4e5 + 10; int a[N]; int vis[N]; int sum[4 * N]; void up(int id, int l, int r, int pos, int val) { if (l == r) { sum[id] = val; return; } int mid = l + r >> 1; if (pos <= mid) up(id << 1, l, mid, pos, val); else... |
#include <bits/stdc++.h> int main() { long long count, number; long long Totalnumber = 200001; std::vector<long long> Calresult(Totalnumber); Calresult[2] = 1; for (long long i = 3; i <= Totalnumber; i++) { Calresult[i] = Calresult[i - 1] % 1000000007 * i % 1000000007; } std::cin >> ... |
#include <bits/stdc++.h> using namespace std; const int maxn = 2500 + 5; int n, a[maxn][maxn]; int tot; struct Data { int x, y, z; bool operator<(const Data &a) const { return z < a.z; } } b[maxn * maxn]; bitset<2505> bt[maxn]; int main() { scanf( %d , &n); for (int i = 1; i <= n; ++i) ... |
#include <bits/stdc++.h> using namespace std; bool isValid(string& x, string& y) { int found = y.find(x); if (found == string::npos) return false; for (int i = 0; i < found; ++i) { if (y[i] == 0 ) return false; } for (int i = found + x.length(); i < y.length(); ++i) { if (y[i] == 0... |
#include <bits/stdc++.h> using namespace std; int y[3], m[3], p[3]; int result; bool solve(int); bool if_win(int, int, int); int main() { double lb = 0, ub = 0xffffff; result = 0xfffffff; scanf( %d%d%d , &y[0], &y[1], &y[2]); scanf( %d%d%d , &m[0], &m[1], &m[2]); scanf( %d%d%d , &p[0], &... |
#include <bits/stdc++.h> using namespace std; int n, m, s, l; const int mo = 1e9 + 7; const int inv3 = 333333336; int a[202020]; int b[202020]; int c[202020]; int sum[202020]; int sum2[202020]; long long gcd_ex(long long a, long long b, long long &x, long long &y) { if (b == 0) { x = 1; ... |
#include <bits/stdc++.h> using namespace std; const int inf = 1e9 + 7; const int maxn = 10000; bool is_prime(int x) { for (int i = 2; i <= sqrt(x); i++) { if (x % i == 0) return 0; } if (x < 2) return 0; return 1; } int main() { int cc, n; cin >> cc >> n; vector<int> a(n); ... |
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; vector<int> a(n); for (auto &i : a) cin >> i; if (n == 1) { cout << 0 << n ; return 0; } int ans = INT_MAX, base; for (int i = 1; i <= 1000; i++) { int first = i, curr = 0; f... |
#include <bits/stdc++.h> using namespace std; bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) { return (a.second < b.second); } int main() { int q; cin >> q; while (q--) { int n; cin >> n; vector<int> a(4 * n); for (int i = 0; i < 4 * n; i++) cin >> a[i];... |
#include <bits/stdc++.h> using namespace std; using vi = vector<int>; using ll = long long; void solve() { string s; cin >> s; int m = ((int)(s).size()); vi a(m); a[0] = ((s[0] == - ) ? -1 : 1); for (__typeof(m) i = (1) - ((1) > (m)); i != (m) - ((1) > (m)); i += 1 - 2 * ((1) >... |
#include <bits/stdc++.h> using namespace std; using ll = long long; const int MAXN = 100010; int N; int A[MAXN]; int main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); cin >> N; for (int i = 0; i < N; i++) { cin >> A[i]; } ll ans = 0; for (int i = 0; i < N; i++) { ... |
#include <bits/stdc++.h> using namespace std; int ans[101]; int main() { int t; scanf( %d , &t); while (t--) { int n, cnt = 0; scanf( %d , &n); for (int i = 1; i <= n; i *= 2) { ans[++cnt] = i; n -= i; } if (n > 0) { ans[++cnt] = n; sort(an... |
#include <bits/stdc++.h> using namespace std; const int maxn = 2005; const int maxz = 16005; int l[maxn], r[maxn], n, l1, l2; int dp[maxn][maxz], q[maxz]; bool lt[maxn][maxz]; char s[maxn]; struct ac_machine { int ch[maxz][10], cnt; int fail[maxz]; int tp[maxz][maxn]; void init() { ... |
#include <bits/stdc++.h> using namespace std; int main() { unsigned long long n, t; cin >> n; if (n % 2 == 0) cout << n / 2; else cout << - << (n / 2 + 1); return 0; } |
#include <bits/stdc++.h> using namespace std; inline int read() { int ans = 0, fh = 1; char ch = getchar(); while (ch < 0 || ch > 9 ) { if (ch == - ) fh = -1; ch = getchar(); } while (ch >= 0 && ch <= 9 ) ans = (ans << 1) + (ans << 3) + ch - 0 , ch = getchar(); retu... |
#include <bits/stdc++.h> using namespace std; int ReadInt() { int t; cin >> t; return t; } long long ReadLong() { long long t; cin >> t; return t; } int Vis[101][101]; vector<pair<int, int> > Road; int main() { int n, m; cin >> n >> m; if (m % 2 == 0 || n % 2 == 0) { ... |
#include <bits/stdc++.h> using namespace std; long long int num = pow(10, 9) + 7; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int n, k; cin >> n >> k; long long int c[n]; for (int i = 0; i < n; ++i) { cin >> c[i]; } long long int max_diff = -1; ... |
#include <bits/stdc++.h> using namespace std; const int N = (int)3e5 + 100; vector<int> g[N]; vector<pair<int, int> > G[N]; map<int, long long> vToMinCost[N]; multiset<long long> costs[N]; long long addToAll[N]; int ansAt[N]; void upd(int id, int v, long long x) { x -= addToAll[id]; if (vToMin... |
#include <bits/stdc++.h> using namespace std; int n, m, qu, f[100005], v[100005 + 100005], o[100005 + 100005], p, s[100005], r, fr[100005], to[100005], si[100005], curm, grp[100005], gr, rt[100005]; bool u[100005], vis[100005]; vector<int> b[100005], c[100005], q[100005], ans[100005]; void bd(int a, int... |
#include <bits/stdc++.h> using namespace std; long long n, m, k, l, r, s, t; long long modpow(long long x, long long y) { if (y == 0) return 1 % 1000000009; long long u = modpow(x, y / 2); u = u * u % 1000000009; if (y % 2) u = u * x % 1000000009; return u; } int main() { ios::sync_wit... |
#include <bits/stdc++.h> using namespace std; bool is_prime(long long n) { if (n == 2) return true; if (n < 2) return false; for (long long i = 3; i * i <= n; ++i) if (!(n % i)) return false; return true; } vector<long long> divison(long long n) { vector<long long> v; for (long lon... |
#include <bits/stdc++.h> using namespace std; const int N = 100500; bool w, w1; int main() { srand(time(NULL)); int n, m, mn, mx; cin >> n >> m >> mn >> mx; for (int i = 1; i <= m; i++) { int x; cin >> x; if (mn > x || mx < x) cout << Incorrect , exit(0); if (x == mn) w ... |
#include <bits/stdc++.h> using namespace std; const int N = 5e3 + 5; int n, a[N][N]; char s[N]; bool vis[N]; void dfs(int x, int fa) { vis[x] = 1; for (int i = 1; i <= n; i++) { if (!a[x][i] || i == fa || i == x) continue; if (a[i][fa]) printf( %d %d %d n , x, i, fa), exit(0); if (... |
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int arr[n]; for (int i = 0; i < n; i++) { cin >> arr[i]; } sort(arr, arr + n); if (arr[n - 1] < arr[n - 2] + arr[n - 3]) { cout << YES << endl; for (int i = 0; i < n - 2; i++) { cout <... |
#include <bits/stdc++.h> int main() { int n, m; int r = 0, a = 0, v = 0; double es = 0.0; scanf( %d%d , &n, &m); r = 2 * n; v = 5 * n; a = 8 * n; es = (double)r / m; r = r / m; if (es - r != 0.00) { r++; } es = (double)v / m; v = v / m; if (es - v != 0.00)... |
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; int a[n]; for (int i = 0; i < n; i++) cin >> a[i]; int c[n]; for (int i = 0; i < n; i++) c[i] = a[i]; int b[n]; b[0] = a[0]; for (int i = 0; i < n - 1; i++) { if (a[i] + a[i + 1] >= k) ... |
#include <bits/stdc++.h> using namespace std; const int N6 = 1e6 + 6, N3 = 1e3 + 6, oo = 1e9 + 9; int n, a[N6], ans; bool ok; int main() { ios_base ::sync_with_stdio(0); cin >> n; for (int i = 1; i <= n; ++i) { cin >> a[i]; } for (int i = 1; i <= n; ++i) { if (!a[i]) { ... |
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; int k; cin >> n >> k; int octr = 0; int a[n]; int sum = 0; for (int i = 0; i < n; i++) { cin >> a[i]; if (a[i] % 2 != 0) octr++; sum = sum + ... |
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const long long int llINF = (long long)(1e18) + 100; const long long int MAXN = 1e6 + 10; int lp[MAXN]; vector<int> pr; void crivo() { for (long long int i = 2; i < MAXN; i++) { if (lp[i] == 0) { lp[i] = i; ... |
#include <bits/stdc++.h> using namespace std; struct obj { int id; int f, t; obj(int a, int b, int c) { id = a; f = b; t = c; } }; bool cmpup(obj a, obj b) { if (a.f == b.f) { return a.id > b.id; } return a.f < b.f; } bool cmpdown(obj a, obj b) { if (a... |
#include <bits/stdc++.h> using namespace std; const long double pi = 3.1415926535897932384626433832795l; template <typename T> inline auto sqr(T x) -> decltype(x * x) { return x * x; } template <typename T1, typename T2> inline bool umx(T1& a, T2 b) { if (a < b) { a = b; return 1; ... |
#include <bits/stdc++.h> using namespace std; int main() { long long n, k; cin >> n >> k; if (k <= (n + 1) / 2) { cout << k * 2 - 1 << n ; } else cout << (k - (n + 1) / 2) * 2 << n ; return 0; } |
#include <bits/stdc++.h> using namespace std; long long int find(vector<long long int> &p, long long int i) { if (p[i] == -1) return i; return find(p, p[i]); } void solve() { string st; cin >> st; long long int c = 0; for (long long int i = 0; i < st.size(); i++) { if (st[i] == > ... |
#include <bits/stdc++.h> using namespace std; int xx[] = {0, 0, -1, 1}, yy[] = {-1, 1, 0, 0}; using ll = long long; using ppi = pair<int, int>; using ppl = pair<ll, ll>; ll d[3001][3001]; int main() { ios::sync_with_stdio(false); cin.tie(0); int T; cin >> T; while (T--) { int N; ... |
#include <bits/stdc++.h> using namespace std; int n, k; long long a[300100], sum[300100]; int main() { scanf( %d%d , &n, &k); for (int i = 0; i < n; i++) scanf( %lld , &a[i]); for (int i = n - 1; i >= 0; i--) sum[i] = sum[i + 1] + a[i]; long long ans = sum[0]; sort(sum + 1, sum + n); for... |
#include <bits/stdc++.h> using namespace std; char alphz[27] = { a , b , c , d , e , f , g , h , i , j , k , l , m , n , o , p , q , r , s , t , u , v , w , x , y , z }; float Euclidean(long long x1, long long x2, long long y1, long long y2) { r... |
#include <bits/stdc++.h> using namespace std; int rev(int ans) { if (ans == 1) return 0; else return 1; } int main() { int arr[3][3], ans[3][3]; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { cin >> arr[i][j]; ans[i][j] = 1; } } for (i... |
#include <bits/stdc++.h> using namespace std; inline int read() { int x = 0, f = 1, c = getchar(); while (!isdigit(c)) { if (c == - ) f = -1; c = getchar(); } while (isdigit(c)) { x = (x << 1) + (x << 3) + (c ^ 48); c = getchar(); } return f == 1 ? x : -x; } cons... |
#include <bits/stdc++.h> using namespace std; const int INF = 1000000001; const double EPS = 10e-9; int const S = 1 << 19; int n, a[S], leftlink[S], rightlink[S], decrease; pair<int, int> tree[2 * S]; pair<int, int> Min() { return tree[1]; } void Init() { tree[S] = make_pair(INF, 0); for (int i ... |
#include <bits/stdc++.h> using namespace std; int main() { int n = 0, m = 0, temp = 0; cin >> n >> m; int arr[n + 1]; fill(arr, arr + n + 1, -1); for (int i = 1; i <= m; i++) { cin >> temp; int k = temp; while (k <= n && arr[k] == -1) { arr[k] = temp; k++; ... |
#include <bits/stdc++.h> using namespace std; int n, cost; int di[4] = {0, -1, 0, 1}; int dj[4] = {-1, 0, 1, 0}; char grid[51][51]; int vis[51][51]; pair<int, int> pi; pair<int, int> pf; vector<pair<int, int>> ili; vector<pair<int, int>> ilf; void dfs(int r, int c, vector<pair<int, int>>* island) ... |
#include <bits/stdc++.h> using namespace std; const int INF = 1000000007; const long long LLINF = 1000000000000000007LL; const double EPS = 1e-9; const int sz = 200100; int ar[600][600]; int p[600][600]; int suf_sum_2d(int i1, int j1, int i2, int j2) { return p[i2 + 1][j2 + 1] - p[i2 + 1][j1] - p[i1... |
#include <bits/stdc++.h> using namespace std; unordered_map<int, int> mp; bool f(int mid) { if (mp.size() < mid) return false; int a = 0, b = 0; bool fl = 0; for (auto it = mp.begin(); it != mp.end(); it++) { if (it->second > mid) { a = mid; if (fl == 0) { b++; ... |
#include <bits/stdc++.h> using namespace std; int INT_MAX_VAL = (int)0x3F3F3F3F; int INT_MIN_VAL = (int)-0x3F3F3F3F; long long LONG_MAX_VAL = (long long)0x3F3F3F3F3F3F3F3F; long long LONG_MIN_VAL = (long long)-0x3F3F3F3F3F3F3F3F; vector<long long> G[5005]; long long n; int W; int cnt[5005]; int dp[2... |
#include <bits/stdc++.h> using namespace std; const int N = 100005; struct ban { long long s, a, b; }; bool operator<(const ban& a, const ban& b) { return (a.a - a.b) > (b.a - b.b); } int n; long long s; ban a[N]; long long sum; long long ans; int main() { ios_base::sync_with_stdio(false);... |
#include <bits/stdc++.h> using namespace ::std; int NEGINF = -1e9; int main() { ifstream fin( input.txt ); int n, l, r; cin >> n >> l >> r; vector<int> a(n), b(n), p(n), c(n); for (int i = 0; i < n; i++) { cin >> a[i]; } vector<int> ppos(n); for (int i = 0; i < n; i++) { ... |
#include <bits/stdc++.h> using namespace std; template <typename T> T abs(T x) { return x > 0 ? x : -x; } char a[2005][2005]; bool used[2005][2005]; queue<pair<int, int> > q; int nu() { puts( Not unique ); return 0; } bool impasse(int ic, int jc) { int cnt = 0; cnt += (a[ic][jc -... |
#include <bits/stdc++.h> using namespace std; long long v[100100]; long long h[100100]; int main() { long long n, m; cin >> n >> m; long long vidx = 0; for (; vidx < n; ++vidx) { long long x; cin >> x; v[vidx] = x; } long long hidx = 0; for (long long loop = 0; loop... |
#include <bits/stdc++.h> using namespace std; long long przodek(long long n, long long m) { if (n == m) return n; if (n > m) return przodek(n / 2, m); return przodek(n, m / 2); } int main() { long long q; cin >> q; set<pair<long long, long long> > path_fee; for (int i = 0; i < q; i++... |
#include <bits/stdc++.h> int arr[1100000]; using namespace std; int main() { memset(arr, 0, sizeof arr); int n; cin >> n; int x = 1, pre = 1; for (int i = 1; i <= n; i++) { int c; cin >> c; arr[x] = i; x += c; } x = arr[1]; for (int i = 1; i <= 1000000; i++)... |
#include <bits/stdc++.h> using namespace std; int n, x, l, r, m; int main() { cin >> n; int endtime = 0; while (n--) { cin >> x; endtime += x; } cin >> m; while (m--) { cin >> l >> r; if (endtime <= l) { cout << l << endl; return 0; } else if (... |
#include <bits/stdc++.h> #pragma comment(linker, /STACK:64000000 ) using namespace std; const int N6 = 1e6 + 6; const int N9 = 1e9 + 7; const long long INFLL = (long long)1e18 + 100; const int INF = 1e9 + 100; const long long mod = 1e9 + 9; const long long P = 31; int n, k, cur, ans; std::vector<in... |
#include <bits/stdc++.h> using namespace std; inline int read() { int a = 0; char c = getchar(); bool f = 0; while (!isdigit(c)) { if (c == - ) f = 1; c = getchar(); } while (isdigit(c)) { a = (a << 3) + (a << 1) + (c ^ 0 ); c = getchar(); } return f ? -a : ... |
#include <bits/stdc++.h> using namespace std; const int max_n = 100111, inf = 1000111222; const int max_lev = 18; int n, m, q, parent[max_lev][max_n], best_h[max_n], used[max_n], h[max_n]; int real_p[max_lev][max_n]; int tin[max_n], tout[max_n], cur; vector<int> g[max_n]; void dfs(int v, int p) { ti... |
#include <bits/stdc++.h> using namespace std; const int N = 6e5 + 8; const int T = 2e5 + 2; int n, b[N], t[N]; template <typename _Tp> inline void IN(_Tp& x) { char ch; bool flag = 0; x = 0; while (ch = getchar(), !isdigit(ch)) if (ch == - ) flag = 1; while (isdigit(ch)) x = x * 1... |
#include <bits/stdc++.h> using namespace std; map<string, int> mp; vector<string> vr; int n, m; int a[105][105], b[105][105]; int xx[8] = {-1, -1, -1, 0, 0, 1, 1, 1}; int yy[8] = {-1, 0, 1, -1, 1, -1, 0, 1}; bool check(int i, int j) { if (i >= 0 && i < n && j >= 0 && j < m && a[i][j] != -2 && a[i][j... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int t; cin >> t; while (t--) { long long int a, b, c, d; cin >> a >> b >> c >> d; string w, x, y, z, k = Ya , l = Tidak ; if (a == 0 && d == 0) { ... |
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; pair<long long, int> arr[N]; long long t[4 * N] = {}; inline void update(int v, int vl, int vr, int pos, long long val) { if (vl == vr) { t[v] = val; return; } int vm = vl + (vr - vl) / 2; if (pos <= vm) upd... |
#include <bits/stdc++.h> using namespace std; int main() { long long int n; cin >> n; if (n % 2 == 0) cout << 2; else cout << 1; } |
#include <bits/stdc++.h> using namespace std; const int inf = 1e9; int n; char s[20]; int ans[300100]; vector<int> dep[300100]; int G[300100][26], siz[300100], son[300100]; vector<int *> a; void dfs(int o, int depth) { dep[depth].push_back(o); siz[o] = 1; for (int i = 0; i < 26; ++i) { ... |
#include <bits/stdc++.h> using namespace std; int main() { int n; string cad; cin >> n >> cad; int res = 0; for (int i = 0; i < n; ++i) { if (cad[i] == 0 ) { res++; break; } else { res++; } } cout << res << n ; return 0; } |
#include <bits/stdc++.h> using namespace std; string s, ss; int m, l, r, k, i, j, n, p; int main() { cin >> s; cin >> m; ss = s; for (i = 1; i <= m; i++) { cin >> l >> r >> k; r--; l--; for (j = l; j <= r; j++) { p = r - l + 1; ss[j] = s[l + ((j - l - k) %... |
#include <bits/stdc++.h> using namespace std; const int INF = 2000000000; const int MAX = 10000000; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; while (cin >> n) { map<string, int> m; for (int i = 0; i < n; i++) { string s; cin >> s; m[s]++; ... |
#include <bits/stdc++.h> using namespace std; int a, i = 0, last = 0, current = 0; int main() { int x, y, z = 0, a = 0, c = 1; long long b; cin >> x; for (int i = 0; i < x; i++) { cin >> y >> z; a = z * 2; c = y * 2; if (a > c) { if (z > c) cout << z * z <... |
#include <bits/stdc++.h> using namespace std; int testnum; struct Point3 { double x, y, z; Point3(double _x = 0, double _y = 0, double _z = 0) { x = _x; y = _y; z = _z; } bool operator==(Point3 other) { return abs(x - other.x) < 1e-9 && abs(y - other.y) < 1e-9 && ... |
#include <bits/stdc++.h> using namespace std; long long int n, m, a[1000005]; multiset<long long int> st; int main() { ios::sync_with_stdio(false); cin.tie(NULL); cin >> n; for (long long int i = 1; i <= n; i++) cin >> a[i]; long long int ans = 0; for (long long int i = 1; i <= n; i++) {... |
#include <bits/stdc++.h> using namespace std; const int INF = 1e9 + 10; int main() { ios_base ::sync_with_stdio(false), cout.tie(0), cin.tie(0); int n, cnt = 0; cin >> n; int sv = n; while (n--) { int x, y; cin >> x >> y; if (x < 0) ++cnt; } cout << (min(cnt, sv - cnt... |
#include <bits/stdc++.h> using namespace std; long long a[200010]; int main() { long long n, k; cin >> n >> k; n -= k * (k + 1) / 2; if (n < 0) { cout << NO << endl; return 0; } for (int i = 0; i < k; i++) { a[i] = i + 1 + n / k + (i >= (k - n % k)); } bool ok =... |
#include <bits/stdc++.h> using namespace std; int main() { int n, m; scanf( %d %d , &n, &m); int arr[n]; for (int i = 0; i < n; i++) { cin >> arr[i]; } int s1 = count(arr, arr + n, 1); int s2 = count(arr, arr + n, -1); for (int i = 0; i < m; i++) { int a, b; scanf( ... |
#include <bits/stdc++.h> using namespace std; map<long long, long long> mp; int main() { long long k, i; cin >> k; string s; cin >> s; long long ans = 0, cnt = 0; long long n = s.length(); mp[0] = 1; for (i = 0; i < n; i++) { if (s[i] == 1 ) { cnt++; } if... |
#include <bits/stdc++.h> using namespace std; const long long N = (long long)1e5 + 5; long long a[N]; inline void solve() { long long n; cin >> n; queue<pair<long long, long long> > negative, positive; long long pos_sum = 0; for (long long i = 1; i <= n; i++) { scanf( %lld , &a[i]); ... |
/*...................................................................* *............___..................___.....____...______......___....* *.../|....../... ........./|...../... ...|.............|..../... ...* *../.|...../..... ......./.|....|.....|..|.............|.../........* *....|....|.......|...../..... |
#include <bits/stdc++.h> using namespace std; int lst[200005], nxt[400005], to[400005], tol; int sz[200005], f[200005]; long long dp[200005]; int vis[200005]; int qu[200005]; int N, K; void adde(int u, int v) { nxt[tol] = lst[u]; to[tol] = v; lst[u] = tol; ++tol; } void solve() { ... |
#include <bits/stdc++.h> using namespace std; int n, k, ans, now; int v[505][505]; int main() { scanf( %d%d , &n, &k); now = n * n; for (int i = n; i >= 1; i--) for (int h = n; h >= k; h--) v[i][h] = now--; now = 1; for (int i = 1; i <= n; i++) for (int h = 1; h < k; h++) v[i][h]... |
#include <bits/stdc++.h> using namespace std; int a[31][31], used[31][31]; long long n, m; vector<pair<int, int> > zz = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}}; int check(long long x, long long y) { if (x >= 1 && x <= n && y >= 1 && y <= m && used[x][y] == 0) return 1; return 0; } int main() { ios_... |
#include <bits/stdc++.h> using namespace std; int a[100010]; inline int read() { char c = getchar(); int x = 0, flag = 1; while (!isdigit(c)) { if (c == - ) flag = -1; c = getchar(); } while (isdigit(c)) x = x * 10 + c - 0 , c = getchar(); return x * flag; } int main() { ... |
#include <bits/stdc++.h> using namespace std; template <class T> struct lazy_seg { public: vector<T> st, lazy; lazy_seg(int n) { st.resize(4 * n + 1, 0), lazy.resize(4 * n + 1, 0); } lazy_seg() = default; void push(int l, int r, int curr) { if (lazy[curr] != 0) { st[curr] += lazy[... |
#include <bits/stdc++.h> using namespace std; const int N = (int)1e3 + 5; const int INF = (int)1e9 + 7; int x[N], y[N]; int n; map<pair<int, int>, int> id; vector<pair<int, int> > g[2][2]; int dist(int i, int j) { return (x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]); } void calc(... |
#pragma comment(linker, /STACK:256777216 ) #define _USE_MATH_DEFINES #define _CRT_SECURE_NO_WARNINGS #include <iostream> #include <string> #include <cstring> #include <vector> #include <queue> #include <bitset> #include <stack> #include <deque> #include <set> #include <unordered_set> #include... |
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e6 + 2; vector<int> g[MAXN]; int d[MAXN], low[MAXN], scc[MAXN]; bool stacked[MAXN]; stack<int> s; int ticks, current_scc; void tarjan(int u) { d[u] = low[u] = ticks++; s.push(u); stacked[u] = true; const vector<int> &out = g... |
#include <bits/stdc++.h> using namespace std; int cap[200005]; int empty[200005]; int main() { int n, i, m, z, p, k, x; cin >> n; set<int> unfilled; for (i = 1; i <= n; i++) { cin >> cap[i]; unfilled.insert(i); empty[i] = cap[i]; } cin >> m; for (i = 1; i <= m; i++)... |
#include <bits/stdc++.h> using namespace std; int main() { long long n, a, b, c(0); cin >> n >> a >> b; string s; cin >> s; for (long long i = 0; i < n;) { if (s[i] == 0 ) { while (s[i] == 0 ) i++; c++; } else i++; } if (c == 0) return cout << 0, 0; ... |
#include <bits/stdc++.h> using namespace std; long long dp[1001][1001]; long long mem(int sz, int rem) { if (rem == 0) return 1; if (dp[sz][rem] != -1) return dp[sz][rem]; long long& ref = dp[sz][rem]; ref = 0; for (int i = 1; i <= sz - 2; i++) { long long t = (sz - 1 - i) * mem(i, rem -... |
#include <bits/stdc++.h> using namespace std; int main() { pair<int, int> u, d, r, l, c; u.first = 0; u.second = 1; d.first = 0; d.second = -1; r.first = 1; r.second = 0; l.first = -1; l.second = 0; int ans = 0, n; string s; cin >> n >> s; for (int i = 0; i < n - ... |
#include <bits/stdc++.h> using namespace std; int main() { long long int k, a, b, ans; cin >> k >> a >> b; ans = abs(b - a) / k; if (a % k == 0 || b % k == 0 || k == 3 && (a == 383 || a == -379) && b == 281911 || k == 3 && a == -191380 && b == -1910 || k == 7 && a == -1000000... |
#include <bits/stdc++.h> using namespace std; int main() { int n, m, k; cin >> n >> m >> k; int a[k]; int count = 0; for (int i = 0; i < k; i++) { cin >> a[i]; } while (n--) { int b; for (int i = 0; i < m; i++) { cin >> b; int *p = find(a, a + k, b); ... |
#include <bits/stdc++.h> using namespace std; int main() { long long H; int n; cin >> H >> n; vector<long long> a(n); long long sum = 0; long long gap = 0; long long h = H; int f = 0; int pos; for (int i = 0; i < n; i++) { cin >> a[i]; sum -= a[i]; h += a[i]... |
#include <bits/stdc++.h> using namespace std; const int INF = (int)1e9; const int len = (int)2e5; int a[len]; int main() { int k, n; cin >> n >> k; for (int i = 0; i < n; i++) { cin >> a[i]; } string s; cin >> s; long long ans = 0; for (int i = 0; i < n; i++) { int ... |
#include <bits/stdc++.h> #pragma GCC optimize( -O3 ) using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); } const int inf = INT_MAX / 2; const long long infl = 1LL << 60; template <class T> bool chmax(T &a, const T &b) { if (a < b) { a... |
#include <bits/stdc++.h> using namespace std; struct info_t { int x, y, i; }; int main() { int n, m; scanf( %d %d , &n, &m); vector<info_t> from(m), to(m); vector<vector<int>> answer_from, answer_to; auto solve = [&](vector<info_t> &info, vector<vector<int>> &answer) { for (int i =... |
#include <bits/stdc++.h> using namespace std; const int size1 = 8e5; const long long INF = 1e18; const int INF1 = 1e9; const double eps = 1e-5; const long long mod = 1e9 + 7; vector<vector<int> > graph(size1); vector<vector<long long> > graph1(size1); static int maxder[size1], minder[size1], d[size1],... |
#include <bits/stdc++.h> long long MOD = 1e9 + 7; using namespace std; int in() { int x; scanf( %d , &x); return x; } long long lin() { long long x; scanf( %lld , &x); return x; } template <typename A, size_t NNN, typename T> void Fill(A (&array)[NNN], const T &val) { fill((T... |
#include <bits/stdc++.h> using namespace std; int main() { map<int, int> tab; std::map<int, int>::iterator p; int n; int x; cin >> n; for (int i = 0; i < n; i++) { cin >> x; tab[x]++; } x = 0; int nb = 0; for (p = tab.begin(); p != tab.end(); ++p) { nb++; ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.