func_code_string stringlengths 59 71.4k |
|---|
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, k; cin >> n >> k; string s; cin >> s; int l = -1; for (int i = 0; i < n - 1 && k > 0; i++) { if (s[i] == 4 && s[i + 1] == 7 ) { if (i % 2 == 1) { if (... |
#include <bits/stdc++.h> using namespace std; int main() { std::ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long t = 1; while (t--) { long long n, i, j = 0, x; cin >> n; string s = ; stack<long long> q; deque<long long> d; for (i = 0; i <... |
#include <bits/stdc++.h> using namespace std; const int MOD(1000000007); const int Max_W(1000050); inline int Mult(const int &a, const int &b) { return (a * 1LL) * b % MOD; } constexpr int Add(int a, int b) { return a + b >= MOD ? a + b - MOD : a + b; } constexpr int Sub(int a, int b) { return a - b < 0 ? a... |
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; void solve() { int n, k; cin >> n >> k; string s; cin >> s; set<char> st; for (auto i : s) st.insert(i); if (k > n) { string p = s; char ch = *st.begin(); for (int i = 0; i < k - n; i++) { ... |
#include <bits/stdc++.h> using namespace std; long long a, b, c; int n; long long X1, Y1, X2, Y2; long long sign(long long a) { if (a > 0) return 1; if (a < 0) return -1; return 0; } int main() { cin >> X1 >> Y1 >> X2 >> Y2; cin >> n; int ans = 0; for (int i = 0; i < n; ++i) { ... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long t; cin >> t; while (t--) { long long n; cin >> n; vector<long long> v(n); set<long long> s; for (long long x = 0; x < n; x++) { ... |
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const int maxn = 110000; int n, m, h; int head[maxn], num; struct road { int to, next; } edge[maxn * 2]; void add(int u, int v) { edge[num].to = v; edge[num].next = head[u]; head[u] = num++; } int dfn[maxn], lo... |
#include <bits/stdc++.h> using namespace std; const long long int N = 200001; const long long int M = 21; struct point { long long int x, y, cur; bool operator==(const point b) { if (this->x == b.x && this->y == b.y) return 1; return 0; } bool operator!=(const point b) { return !(*th... |
#include <bits/stdc++.h> using namespace std; const int oo = 0x3f3f3f3f; const double eps = 1e-9; vector<int> p, vg; set<pair<int, int> > done; bool cando(int i, int j) { return done.find(make_pair(min(i, j), max(i, j))) == done.end(); } int moves = 0; void doswap(int i, int j) { ++moves; ... |
#include <bits/stdc++.h> using namespace std; const int INF = 1e9; const int Mod = 1e9 + 7; const int Mod2 = 49157; const int p = 10; inline long long Read() { long long Ans = 0; char Ch = getchar(), Las = ; while (!isdigit(Ch)) { Las = Ch; Ch = getchar(); } while (isdigit... |
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1); const double EPS = 1e-7; const int inf = 1e8; int main() { int n, sum = 0; cin >> n; vector<int> in(n); for (int i = 0; i < n; i++) cin >> in[i]; for (int i = 0; i < n; i++) sum += in[i]; vector<int> used(n); ... |
#include <bits/stdc++.h> using namespace std; long long n, p, q, r, e, ans; vector<long long> fst, lst, mid, Ans; int main() { cin >> n >> p >> q >> r; for (int i = 0; i < n; i++) { cin >> e; fst.push_back(p * e); mid.push_back(q * e); lst.push_back(r * e); } long long mx... |
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; int a[m][n]; for (int i = 0; i < m; i++) for (int j = 0; j < n; j++) cin >> a[i][j]; int ans[n]; memset(ans, 0, sizeof(ans)); int k = 0; int x = 0, y = 0; int ma = INT_MIN; for (int i = ... |
#include <bits/stdc++.h> using namespace std; map<string, set<string> > ma; set<string> hostname; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; while (n--) { string s; cin >> s; int i = s.find( / , 7); if (i != -1) { string ... |
#include <bits/stdc++.h> template <typename T> T min(T x, T y) { return x < y ? x : y; } template <typename T> T max(T x, T y) { return x > y ? x : y; } template <typename T> T abs(T x) { return x > 0 ? x : -x; } template <typename T> T gcd(T x, T y) { return x ? gcd(y % x, x) : y;... |
#include <bits/stdc++.h> using namespace std; template <typename num_t> inline void addmod(num_t& a, const long long& b, const int& m) { a = (a + b) % m; if (a < 0) a += m; } template <typename num_t> inline void update_max(num_t& a, const num_t& b) { a = max(a, b); } template <typename num_... |
#include <bits/stdc++.h> int next[1 + (1000 * (1000 - 1)) * 2], hh[1 + (1000 * (1000 - 1)) * 2], l_; int link(int l, int h) { next[l_] = l; hh[l_] = h; return l_++; } int ij[(1000 * (1000 - 1))], ww[(1000 * (1000 - 1))], ao[1000]; long long ww_[1000][1000]; int pq[1 + 1000], iq[1000], cnt; lon... |
#include <bits/stdc++.h> using namespace std; struct Point { int x, y, nr; bool t; }; const int N = 2e4 + 7; int n, m; int ans[N]; Point tab[N]; bool cmp(Point a, Point b) { if (a.x == b.x) return a.y < b.y; return a.x < b.x; } int xr, yr; void change(Point &a) { xr = a.x; ... |
#include <bits/stdc++.h> using namespace std; const int mo = 1000000007; char S[2005], A[2][2005]; int ans, n, m, P[2][2005][2005], Q[2][2005][2005]; long long H[2005], w[2][2005], W[2005], N[2005]; bool IS(int u, int p, int q, int l, int r) { return (w[u][q] - w[u][p - 1]) * H[2000 - p] == (... |
#include <iostream> #include <vector> #include <set> #include <algorithm> #include<map> #include <math.h> using namespace std; void solve(){ int n,x,t; cin>>n>>x>>t; cout<<(long long)max(0,n-t/x)*(t/x) + (long long)min(n,t/x)*min(n-1,t/x-1)/2<<endl; } int main() { #ifndef... |
#include <bits/stdc++.h> using namespace std; long long max(long long a, long long b) { if (a > b) return a; else return b; } long long min(long long a, long long b) { if (a < b) return a; else return b; } long long power(long long B, long long P) { if (P == 0) re... |
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; void solve() { long long int n, k; long long int right = (long long int)2e9; long long int left = 0; cin >> n >> k; long long int a[n], b[n]; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n; i++) cin ... |
#include <bits/stdc++.h> using namespace std; struct dat { int x, rev, f, cap, cost; dat(int x = 0, int rev = 0, int f = 0, int cap = 0, int cost = 0) : x(x), rev(rev), f(f), cap(cap), cost(cost) {} }; vector<dat> v[5100]; void add(int s, int t, int ca, int co) { int n = v[s].size(); i... |
#include <bits/stdc++.h> using namespace std; int n; vector<int> g[100010]; int vis[100010]; struct node { int num; long long inc; long long dec; int val; } nodes[100010]; void dfs(node &u) { vis[u.num] = 1; for (int v : g[u.num]) { if (!vis[v]) { dfs(nodes[v]); ... |
#include <bits/stdc++.h> using namespace std; int Q; long long int N; int cheats[20] = {0, 0, 1, 2, 3, 4, 6, 7, 8, 10, 12}; int main() { scanf( %d , &Q); for (int qi = 0; qi < Q; qi++) { scanf( %lld , &N); if (N < 10) { printf( %d n , cheats[(int)N]); continue; } ... |
#include <bits/stdc++.h> using namespace std; int dx[] = {0, 0, 1, -1, 1, -1, 1, -1}; int dy[] = {1, -1, 0, 0, -1, 1, 1, -1}; long long gcd(long long a, long long b) { return !b ? a : gcd(b, a % b); } long long lcm(long long a, long long b) { return (a / gcd(a, b)) * b; } void PLAY() { cout << fixed << ... |
#include <bits/stdc++.h> using namespace std; vector<int> g[200005]; int sz[200005]; void init(int node) { sz[node] = 1; for (auto it : g[node]) { init(it); sz[node] = sz[node] + sz[it]; } } void dfs(int node) { for (auto it : g[node]) { if (!(sz[it] & 1)) dfs(it); } ... |
#include <bits/stdc++.h> typedef struct acv { int x, y; int l; int mark; } node; int abs(int a) { return a > 0 ? a : -a; } int main() { int m, n; while (scanf( %d %d , &n, &m) != EOF) { int i, j; node nail[505]; int rod[505], sign[505] = {0}; for (i = 1; i <= n; i++) ... |
#include <bits/stdc++.h> using namespace std; inline long long read() { long long s = 0, f = 1; char c = getchar(); while (c < 0 || c > 9 ) f *= c == - ? -1 : 1, c = getchar(); while (c >= 0 && c <= 9 ) s = s * 10 + c - 0 , c = getchar(); return s * f; } struct edge { int from, ... |
#include <bits/stdc++.h> using namespace std; double d[100100]; int s[1010]; int main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); int n, m, h, sum(0); cin >> n >> m >> h; h--; for (int i = 0; i < m; i++) { cin >> s[i]; sum += s[i]; } if (sum < n) { co... |
#include <bits/stdc++.h> using namespace std; int gcd(int a, int b) { while (a && b) a > b ? a %= b : b %= a; return a + b; } long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); } long long fast_exp(long long base, long long exp) { long long res = 1; while (exp > 0) { i... |
#include <bits/stdc++.h> using namespace std; char a[1000100], ans[3000], s[3000], ans1[3000]; int tmp, p, i, len1, len12, len2, lens, k, o; bool flag; bool smaller() { for (int i = 1; i <= len2; i++) if (ans1[i] > ans[i]) return false; else if (ans1[i] < ans[i]) return true; ... |
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int N, M; cin >> N >> M; vector<pair<string, int> > A(N); for (int i = 0; i < N; i++) { string S; cin >> S; for (int j = 1; j < S.size(); j += 2) S[j] = Z - (S[j] - ... |
#include <bits/stdc++.h> using namespace std; #define ll long long const int N = 3e5+10, oo = 1e9+10; void solve() { int n; cin >> n; vector<ll> a(n+1); ll ans = 0; vector<ll> answers; answers.reserve(n-1); for(int i = 1; i <= n; ++i) { cin >> a[i]; ans += a[i]; } answers.push... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t; cin >> t; while (t--) { long long n, one = 0, z = 0; string s, s1; cin >> n >> s; if (n == 1) { cout << s << endl; continue; } fo... |
#include <bits/stdc++.h> using namespace std; vector<vector<int> > graph; vector<int> AL; vector<int> visited; void dfs(int u) { visited[u] = 1; for (auto v : graph[u]) { if (!visited[v]) { dfs(v); } } } int main() { ios::sync_with_stdio(false); cin.tie(NULL); i... |
#include <bits/stdc++.h> #pragma GCC optimize( unroll-loops,no-stack-protector ) #pragma GCC target( sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native ) using namespace std; const int MOD = 1e9 + 7; const int INF32 = 1 << 30; const long long INF64 = 1LL << 60; const long double pi = acos(-1); long long... |
#include <bits/stdc++.h> using namespace std; const int maxn = (int)1e6 + 10; const int mod = (int)1e9 + 7; const int inf = (1 << 30) - 1; int n, m, q; int a[maxn]; int good[maxn]; vector<int> g[maxn]; int p[maxn]; int dx[] = {-1, 1, 0, 0}; int dy[] = {0, 0, -1, 1}; char dir[] = { U , D , L , ... |
#include <bits/stdc++.h> using namespace std; int const N = 400010; int const M = 1001000; int n, m; struct edges { int u, next; } e[M]; int p[N], idx; void addedge(int u, int v) { e[idx].u = v, e[idx].next = p[u], p[u] = idx++; } void init() { idx = 0; memset(p, (0xff), sizeof p); } i... |
#include <bits/stdc++.h> using namespace std; const int N = 5010; struct SA { bool _t[N * 2]; int _s[N * 2], _sa[N * 2], _c[N * 2], x[N], _p[N], _q[N * 2], hei[N], r[N]; int operator[](int i) { return _sa[i]; } void build(int *s, int n, int m) { memcpy(_s, s, sizeof(int) * n); sais(_s,... |
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int t; cin >> t; for (int i = 0; i < t; i++) { long long n, k; cin >> n >> k; if (n < k * k) { cout << NO << n ; } else if (n % 2 != k % 2) { cout << NO <... |
#include <bits/stdc++.h> using namespace std; char save[550][550]; int n, m; bool vis[550][550]; int dir[4][2] = {-1, 0, 0, 1, 1, 0, 0, -1}; int ans; bool iscan(int x, int y) { if (x < 1 || x > n || y < 1 || y > m) return false; return true; } struct Rec { char k; int x, y; } rec[110... |
#include <bits/stdc++.h> using namespace std; int main() { int k, i, j, t; char c; string s; cin >> k; for (i = 1; i < k; i++) { for (j = 1; j < k; j++) { if (j > 1) { cout << ; } t = i * j; s = ; while (t > 0) { c = t % k + ... |
#include <bits/stdc++.h> using namespace std; const int mxn = 2000; int x[mxn]; int main() { int n, a, b; cin >> n >> a >> b; for (int(i) = (0); (i) < (n); (i)++) cin >> x[i]; sort(x, x + n); cout << x[n - a] - x[n - a - 1]; } |
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const long long LINF = 0x3f3f3f3f3f3f3f3f; const double EPS = 1e-9; const int maxn = (int)1e5 + 9; int n, q, t[maxn], k[maxn], d[maxn]; int x[150]; int ans[maxn]; void Solve() { while (cin >> n >> q) { for (int i = (1)... |
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { string s; cin >> s; sort(s.begin(), s.end()); if (s[0] == s[s.size() - 1]) cout << -1 << n ; else cout << s << n ; } } |
#include <bits/stdc++.h> using namespace std; int dfs(const vector<vector<array<int, 3>>>& edges, vector<int>& ans, vector<int>& s, vector<char>& used, int v) { used[v] = true; int sum = 0; for (auto& w : edges[v]) { if (!used[w[0]]) { int d = dfs(edges, ans, s, used, w[0]); ... |
#include <bits/stdc++.h> using namespace std; int gcd(int p, int q) { return q == 0 ? p : gcd(q, p % q); } int main() { int n, num[35][35], sumh[35], suml[35]; cin >> n; memset(sumh, 0, sizeof(sumh)); memset(suml, 0, sizeof(suml)); for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j... |
#include <bits/stdc++.h> using namespace std; int n, m, sx, sy, dx, dy; string s[1022]; bool vis[1002][1002][5][5]; bool f(int i, int j, int dir, int steps) { if (i < 0 || j < 0 || i == n || j == m || steps > 2 || s[i][j] == * || (dir != -1 && vis[i][j][dir][steps])) return false; if (... |
#include <bits/stdc++.h> using namespace std; inline int readint() { int a; cin >> a; return a; } int toInt(string &s) { const static int Mod = 998244353; const static long long bas = 29; int res = 0; for (int i = 0, n = s.length(); i < n; ++i) res = (res * bas + s[i] - a + 1... |
#include <bits/stdc++.h> int main() { int n, m, count, x; while (scanf( %d %d , &n, &m) == 2) { x = 0; count = 0; while (n != 0) { count++; if (count % m == 0) x = 1; n = (n - 1) + x; x = 0; } printf( %d n , count); } return 0; } |
#include <bits/stdc++.h> #pragma comment(linker, /STACK:100000000 ) #pragma GCC optimize( O3 ) using namespace std; const long long N = 1e5 + 10; const long long mod = 1e9 + 7; const long long INF = 1e18; const long long inf = -1e18; const long long M = 1e6; int n, x, y, a[5 * N]; bool us[1000010];... |
#include <bits/stdc++.h> using namespace std; void doit(long long int a[], long long int i, long long int sz) { long long int x; x = i + sz - 1; a[i] = x; for (i++; i <= x; i++) a[i] = i - 1; return; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int n,... |
#include <bits/stdc++.h> int a[101], b[101]; int main() { int n, i, q, x, y, k, t, s, ls; for (scanf( %d , &n), i = 1; i <= n; i++) { scanf( %d , &a[i]); b[a[i]] = i; } for (scanf( %d , &q), i = 0; i < q; i++) { scanf( %d%d%d , &k, &x, &y); if (k == 1) { for (s = 0, l... |
#include <bits/stdc++.h> using namespace std; const int N = 1E6 + 5, K = 1E6 + 5, INF = 1E9 + 7; int n, k, c, v, ans = 0, dsu[K]; char s[N]; vector<int> adj[N]; struct node { int l, r, xo; node(int _l = 0, int _r = 0, int _xo = 0) : l(_l), r(_r), xo(_xo) {} int get() { return min(l, r); } in... |
#include <bits/stdc++.h> using namespace std; const int mod = 1000000007; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long int q, n, i, j, k, t; long long int a[3]; cin >> t; long long int area[5]; while (t--) { long long int a, b, x, y; ... |
#include <bits/stdc++.h> using namespace std; int rem = 10; set<char> st; int main() { string s; cin >> s; long long ans = 1; int zeroes = 0; for (int i = 0; i < s.size(); i++) { if (s[i] >= 0 && s[i] <= 9 ) continue; if (s[i] == ? ) { if (i == 0) ans *= 9; ... |
#include <bits/stdc++.h> using namespace std; const int N = (int)1e6 + 5; const int MACX = (int)1e9 + 7; const int dx[] = {1, -1, 0, 0}; const int dy[] = {0, 0, 1, -1}; long long n, a[N], b[N], c[N]; multiset<long long> ms, ms2; int main() { ios_base ::sync_with_stdio(0); cin.tie(0); cout.ti... |
#include <bits/stdc++.h> using namespace std; bool debug = 0; int n, m, k; int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0}; string direc = RDLU ; long long ln, lk, lm; void etp(bool f = 0) { puts(f ? YES : NO ); exit(0); } void addmod(int &x, int y, int mod = 1000000007) { assert(y >=... |
#include <bits/stdc++.h> using namespace std; long long n, d, b; long long a[500005], c[500005]; long long x, xx; void read(long long &x) { x = 0; long long k = 1; char c = getchar(); while ((c != - ) && (c < 0 || c > 9 )) c = getchar(); if (c == - ) k = -1, c = getchar(); while (... |
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 7; pair<int, int> a[N]; int n; int main() { ios_base::sync_with_stdio(0); cin >> n; for (int i = 0; i < n; ++i) cin >> a[i].first >> a[i].second; sort(a, a + n); int ans = 0; int mxb = -1; for (int i = 0; i < n; ++i)... |
#include <bits/stdc++.h> using namespace std; vector<pair<int, int> > pts; vector<pair<int, int> > rods1; vector<pair<int, int> > rods2; vector<int> r1; vector<int> r2; vector<int> rr1; vector<int> rr2; bool cmp(const pair<int, int> &a, const pair<int, int> &b) { return a.first < b.first; } in... |
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int a, b, c = 0, e, i, n; cin >> n; vector<char> v; char s[n + 1]; cin >> s; for (i = 0; i < n; i++) { if ((s[i] - 0 ) % 2 != 0) { c++; v.push_back(s... |
#include <bits/stdc++.h> using namespace std; const double eps = 1e-8; const int inf = 0x3f3f3f3f; const int Minf = 0x7f7f7f7f; const long long INF = 0x3f3f3f3f3f3f3f3fll; const long long MINF = 0x7f7f7f7f7f7f7f7fll; const int N = 1e6 + 50; long long val[N], fa[N]; int pp[N], ps[N]; int to[N][2], cn... |
#include <bits/stdc++.h> using namespace std; long long int powr(long long int a, long long int b) { long long int res = 1; while (b) { if (b % 2) res = (a * res) % 1000000007; a = (a * a) % 1000000007; b /= 2; } return res; } void extentded_eucledian(long long int a, long long... |
#include <bits/stdc++.h> using namespace std; int main() { long int n, t; cin >> n >> t; long int arr[n + 1]; bool visited[n + 1]; for (long int i = 1; i < n; i++) { cin >> arr[i]; visited[i] = false; } long int i = 1; while (visited[i] == false && i != t && i != n) { ... |
#include <bits/stdc++.h> int a[2][200000], b[2][200000], c[2][200000], n, m, i, j, x, y, z; char s[2][200000 + 1]; int main() { scanf( %d%d%s%s , &n, &m, s[0], s[1]); for (i = n - 1, x = n; i >= 0; i--) { if (s[0][i] == X ) x = i; c[0][i] = x; } for (i = n - 1, x = n; i >= 0; i--) { ... |
#include <bits/stdc++.h> using namespace std; double find(int x, int y) { return (sqrt(x * x + y * y)); } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int r, d; int t; cin >> r >> d; cin >> t; int c = 0; while (t--) { int x, y, q; cin >> x >> y >> q; ... |
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5; const int MAXR = 1; const int MAXC = 1; const int INF = (int)1e9; priority_queue<int, vector<int>, greater<int>> q1; priority_queue<int, vector<int>, less<int>> q2; int arr[MAXN]; vector<pair<int, int>> v(MAXN); vector<vector<int>> ... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int a, b; cin >> a >> b; if (a == b) { cout << (a * 10) << << (b * 10) + 1; } else if (a + 1 == b) { cout << (min(a, b) * 10) + 9 << << (max(a, b) * 10); } else... |
#include <bits/stdc++.h> using namespace std; #pragma comment(linker, /STACK:256000000 ) struct __ { __() { ios_base::sync_with_stdio(false); cin.tie(NULL); } } _; template <typename I> inline void in(I l, I r) { while (l != r) cin >> *l, ++l; } template <typename I> inline vo... |
#include <bits/stdc++.h> using namespace std; void solve() { int n; cin >> n; long long coins = 0; vector<long long> arr(n); for (int i = 0; i < n; i++) cin >> arr[i]; int i = 0, j = 0; while (i < n && j < n) { while (i < n && arr[i] <= 0) i++; while (j < n && (arr[j] >= 0 ||... |
#include <bits/stdc++.h> using namespace std; template <typename T> T mabs(const T &a) { return a < 0 ? -a : a; } int n, m, p, bss; vector<int> a, b; map<int, int> bCounts; vector<int> checkPos(int sp) { vector<int> res; map<int, int> aCounts; int wrongCounts = bss; for (int i = (0),... |
#include <bits/stdc++.h> int input[1001]; int ans[1001][2]; int main() { int n, i, answer; scanf( %d , &n); for (i = 0; i < n; i++) scanf( %d , &input[i]); ans[0][0] = 1; for (i = 1; i < n; i++) { if (input[i] >= input[i - 1]) ans[i][0] = 1 + ans[i - 1][0]; else ans... |
#include <bits/stdc++.h> using namespace std; int main() { int n, m, count_zero = 0, count_max = 0; cin >> n >> m; int data[n][m]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { cin >> data[i][j]; count_max += data[i][j]; if (data[i][j] == 0) { co... |
#include <bits/stdc++.h> int cc[3000]; int good(int i) { return !(cc[i] == 0 && cc[i + 1] == 0 && cc[i + 2] == 1 && cc[i + 3] == 1) && !(cc[i] == 0 && cc[i + 1] == 1 && cc[i + 2] == 0 && cc[i + 3] == 1) && !(cc[i] == 1 && cc[i + 1] == 1 && cc[i + 2] == 1 && cc[i + 3] == 0) && !(... |
#include <bits/stdc++.h> using namespace std; const int maxn = 1000; vector<int> a[maxn]; bool flag[maxn]; int ans[maxn]; int n; bool judge(int x, int y) { int cnt = 0; memset(flag, false, sizeof(flag)); for (int i = 0; i < (int)a[x].size(); i++) { flag[a[x][i]] = true; } for (in... |
#include <bits/stdc++.h> using namespace std; int main() { long int n; cin >> n; int event, police = 0, ans = 0; for (int i = 0; i < n; i++) { cin >> event; if (event == -1) { if (police == 0) ans++; else police--; } else police += event;... |
#include <bits/stdc++.h> using namespace std; const int N = 5000 + 10; int n, a[N], dp[N][N][2]; int calc(int i, int rem, bool isLess) { if (rem == 0) return 0; if (i >= n) return 2e9; int &ret = dp[i][rem][isLess]; if (ret != -1) return ret; ret = 2e9; if (isLess) { if (i != n - 1... |
#include <bits/stdc++.h> using namespace std; long long int power(long long int x, long long int y, long long int p) { long long int res = 1; x = x % p; while (y > 0) { if (y & 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res; } long long int modInverse(lon... |
#include <bits/stdc++.h> using namespace std; int n; int res[51][51]; int main() { scanf( %d , &n); for (int i = 0; i < n * (n - 1) / 2 - 1; i++) { int a, b; scanf( %d%d , &a, &b); res[a][b] = 1; res[b][a] = -1; } int q1, q2; for (int i = 1; i < n + 1; i++) for ... |
#include <bits/stdc++.h> using namespace std; vector<pair<int, int> > Div[5 * int(1e5 + 100)]; int a[2 * int(1e5 + 100)]; bool Have[2 * int(1e5 + 100)]; int calc[5 * int(1e5 + 100)]; int root[5 * int(1e5 + 100)]; int val = 1; void Prime(int x) { int u = x; root[x] = 1; for (int i = 2; i <= s... |
#include <bits/stdc++.h> using namespace std; map<float, int> mp; float cnt[200005]; int main() { int m; cin >> m; for (int i = 1; i <= m; i++) { char s1, s2, s3, s4; int a, b, c; cin >> s1 >> a >> s2 >> b >> s3 >> s4 >> c; cnt[i] = (((a + b) * 1.0) / c); mp[cnt[i]]++; ... |
#include <bits/stdc++.h> using namespace std; int T, n, a[100005], b[100005], f[22], F[22], u[22], m, dp[2222222], cnt[2222222], C; void ope(int x) { dp[x] = 0; for (int i = 1; i <= 20; ++i) { if ((1 << i) & x) { int y = x ^ (1 << i); if (dp[y] == -1) ope(y); if (!(y & ... |
#include <bits/stdc++.h> #pragma comment(linker, /STACK:16777216 ) using namespace std; int a, b, c, d, i, j, n, m, k, ans, T; char str[200003]; int p[22], cs[22][22], dp[1 << 22]; pair<int, int> cur[26]; int main() { scanf( %d%d%d , &n, &k, &T); scanf( %s , str); for (int _n((k)-1), i(0); i ... |
#include <bits/stdc++.h> using namespace std; int n, m, p = 1000000; bool checkDias(int a, const vector<unsigned long long int> &v) { for (int i = p; i < n + 1; i += 1) { unsigned long long int d = i / a; unsigned long long int r = i % a; if (v[i] >= (unsigned long long int)m + r * (d + 1) *... |
#include <bits/stdc++.h> using namespace std; inline char nc() { static char buf[1000000], *p1 = buf, *p2 = buf; return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin), p1 == p2) ? EOF : *p1++; } template <typename T> inline void read(T& sum) { char ch = ... |
#include <bits/stdc++.h> using namespace std; const double EPS = 1e-6; const long long mod = 1000000007ll; const long long mod1 = 1000000009ll; const long long mod2 = 1100000009ll; const double PI = 3.14159265359; const long long MX = 1000000000000ll; int INF = 2147483645; long long INFINF = (long lon... |
#include <bits/stdc++.h> using namespace std; int main() { int n, x = 0; cin >> n; while (n > 0) { if (n >= 100) { x += n / 100; n %= 100; } else if (n >= 20 && n < 100) { x += n / 20; n %= 20; } else if (n >= 10 && n < 50) { x += n / 10; ... |
#include <bits/stdc++.h> using namespace std; bool check(int c1, int c2, int c3, int v1, int v2, int v3, int m) { return (c1 >= v1 && c1 <= 2 * v1 && c2 >= v2 && c2 <= 2 * v2 && c3 >= v3 && c3 <= 2 * v3 && 2 * m >= c3 && 2 * m < c2 && c3 < c2 && c2 < c1 && m <= c3); } int main() { ... |
#include <bits/stdc++.h> using namespace std; template <typename A, typename B, typename C> struct triple { A X; B Y; C Z; triple(A a = 0, B b = 0, C c = 0) : X(a), Y(b), Z(c) {} }; template <typename A, typename B, typename C> triple<A, B, C> make_triple(A a = 0, B b = 0, C c = 0) { ret... |
#include <bits/stdc++.h> using namespace std; bool comp[30000]; int P[30000]; int seive(int n, int* P) { int p, q, K = 0; comp[1] = true; char even = 1; for (p = 2; p * p <= n; p += 2) { if (!comp[p]) { for (q = p * p; q <= n; q += p * (2 - even)) comp[q] = true; } if (... |
#include <bits/stdc++.h> const long long int inf = 9e18; const long double pi = 2 * acos(0.0); using namespace std; long long int power(long long int a, long long int n) { if (n == 0) { return 1; } long long int p = power(a, n / 2) % 998244353; p = (p * p) % 998244353; if (n % 2 == 1) ... |
#include <bits/stdc++.h> using namespace std; inline int read() { int s = 0, w = 1; char ch = getchar(); while (ch < 0 || ch > 9 ) { if (ch == - ) w = -1; ch = getchar(); } while (ch >= 0 && ch <= 9 ) s = s * 10 + ch - 0 , ch = getchar(); return s * w; } vector<int> v... |
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); string s; int temp; long long sol = 0; cin >> s; if ((s[0] - 0 ) % 4 == 0) { sol++; } for (int a = s.length() - 1; a > 0; a--) {... |
#include <bits/stdc++.h> using namespace std; int s[200010], univ[200010]; int n, k, n_univ; vector<int> edges[200010]; bool visited[200010]; int dist[200010]; int getSum(int node) { int sum = univ[node]; visited[node] = true; for (auto e : edges[node]) { if (!visited[e]) sum += getSum(e... |
#include <bits/stdc++.h> int main() { char n[101], a[4] = 127 , b[6] = 32767 , c[11] = 2147483647 , d[20] = 9223372036854775807 ; int i, l, count, mark; while (~scanf( %s , n)) { l = strlen(n); if (l < 3) { printf( byte n ); continue; } if (l ==... |
#include <bits/stdc++.h> using namespace std; string second[100]; int x[100], y[100]; vector<int> a, b; bool u[100][100]; bool uu[100][100]; bool ux[100], uy[100]; int n, m; void dfs(int x, int y) { ux[x] = uy[y] = true; u[x][y] = true; for (int i = 0; i < n; i++) if (second[i][y] ==... |
#include <bits/stdc++.h> using namespace std; struct node { int x, y; }; vector<node> answer; int dis[1000005], a[1000005], pre[1000005]; bool prime[1000005]; void getprime() { for (int i = 2; i < 1000005 - 5; i++) { if (!prime[i]) { for (int j = i * 2; j < 1000005 - 5; j += i) { ... |
//#pragma comment(linker, /STACK:102400000,102400000 ) #include<bits/stdc++.h> using namespace std; typedef long long ll; #define int ll typedef pair<int,int>pii; #define ff first #define ss second #define debug(x) std:: cerr << #x << = << x << std::endl; const int maxn=2010,inf=0x3f3f3f3f,mod=10... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.