func_code_string stringlengths 59 71.4k |
|---|
#include <bits/stdc++.h> using namespace std; const int mod = 998244353; long long dp[511][511]; long long tol[511]; int main() { int n, k, i, j, p; scanf( %d%d , &n, &k); for (i = 1; i <= n; ++i) dp[0][i] = 1; for (i = 1; i <= n; ++i) { for (j = 1; j <= n; ++j) { for (p = max(i ... |
#include <bits/stdc++.h> int main(int argc, const char* argv[]) { int n; std::cin >> n; int step = 0; int prev = 0; int first = 0, second = 0; bool prog = true; int x = 0; for (int i = 0; i < n; i++) { std::cin >> x; if (i == 0) first = x; else if (i == 1) { ... |
#include <bits/stdc++.h> using namespace std; int main() { long long N, W; cin >> N >> W; long long lowest = 0, highest = W; long long current = 0, sum = 0; while (N--) { cin >> current; sum += current; lowest = max(lowest, -sum); highest = min(highest, W - sum); } ... |
#include <bits/stdc++.h> using namespace std; class team { public: int x, y, z; }; int search(team *, int, int); int main() { int m, n, t; cin >> n >> m; int *arr1, *arr2; arr1 = new int[m]; arr2 = new int[m]; for (int i = 0; i < m; i++) cin >> arr1[i] >> arr2[i]; team *res ... |
#include <bits/stdc++.h> using namespace std; signed main() { long long n, k; cin >> n >> k; vector<long long> a(n); vector<long long> b(n); for (long long i = 0; i < n; i++) { cin >> a[i]; a[i]--; } for (long long i = 0; i < n; i++) { cin >> b[i]; } long long c... |
#include <bits/stdc++.h> using namespace std; char str[30]; char a[3][30]; int main(void) { int i, j, k, p1, p2; scanf( %s , str + 1); for (p1 = 1; p1 <= 27; p1++) { for (p2 = p1 + 1; p2 <= 27; p2++) if (str[p1] == str[p2]) break; if (p2 <= 27) break; } if (p1 + 1 == p2) ... |
#include <bits/stdc++.h> using namespace std; long long l1, r1, l2, r2, k, ans; int main() { cin >> l1 >> r1 >> l2 >> r2 >> k; if (r1 < l2 || r2 < l1) { ans = 0; } else { long long r = min(r1, r2), l = max(l1, l2); ans = r - l + 1; if (k >= l && k <= r) ans--; } cout <<... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n, sg, m, k; cin >> n >> sg >> m >> k; vector<int> a(n), starts(n, n); for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < sg; i++) { int l, r; ... |
#include <bits/stdc++.h> using namespace std; int w[40]; int main() { int m, n; cin >> m >> n; for (int i = 1; i <= n; i++) { cout << 1 << endl; cin >> w[i]; if (w[i] == 0) { return 0; } } int l = 1, r = m; int index = 1; while (l <= r) { int mid =... |
#include <bits/stdc++.h> using namespace std; map<string, int> mp; const int INF = 0x3F3F3F3F; const int MOD = 1000003; const int dx[] = {-1, 0, 1, 0}; const int dy[] = {0, 1, 0, -1}; vector<vector<char> > mat; int n, m; bool isvalid(int x, int y) { return x >= 0 && x < n && y >= 0 && y < m; } int m... |
#include <bits/stdc++.h> using namespace std; int main() { long long n, i, cnt = 0; cin >> n; long long ar[n]; for (i = 0; i < n; i++) cin >> ar[i]; for (i = 0; i < n; i++) { if (ar[i] % 2 != 0) cnt++; } cout << min(cnt, n - cnt); } |
#include <bits/stdc++.h> using ll = long long; using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; vector<int> arr(n); for (int i = 0; i < n; i++) cin >> arr[i]; sort(arr.begin(), arr.end()); vector<int> fst; for (int i = 0; i < (n / 2); i++)... |
#include <bits/stdc++.h> using namespace std; vector<int> nxt[1 << 13], G[15]; vector<pair<int, int> > lca[13]; bool a[14][14], ok[14][1 << 13]; long long int dp[14][1 << 13][2]; int n; long long int solve(int root, int mask, int check) { if (check == 0) { int i; for (i = 0; i < lca[root].... |
#include <bits/stdc++.h> using namespace std; using ll = long long; using vi = vector<int>; using db = double; const int mxn = 300006; const ll mod = 1E9L + 7; int n; ll a[mxn]; ll p[mxn]; int main() { cin >> n; for (int i = 0; i < n; ++i) scanf( %lld , &a[i]); sort(a, a + n); p[0] =... |
#include <bits/stdc++.h> using namespace std; const long long int inf = 0x3f3f3f3f3f3f3f3fll; const int mx = 15000005; vector<string> adj[2000005]; vector<bool> vis; vector<pair<string, int>> pa; int ind = 0, mxx = 0; void dfs(int d, int ti) { mxx = max(mxx, d); adj[d].push_back(pa[ind].first); ... |
#include <bits/stdc++.h> using namespace std; map<int, int> times; const int INF = 0x3fffffff; struct Node { int l, r; int v; Node() { l = -1, r = -1; } Node(int _l, int _r) { l = _l, r = _r; } } node[120000]; int fa[120000]; int n, v, ls, rs, root; int ans; int Findroot(int t) { i... |
#include <bits/stdc++.h> using namespace std; const int N = 400000 + 10; const double eps = 1e-9; const double pi = acos(-1); int n; long long k; struct Vec { int x, y; double d() { return x * x + y * y; } } p[N]; vector<double> v; int id(double x) { return lower_bound(v.begin(), v.end(), x)... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0), cout.setf(ios::fixed), cout.precision(10); int m, x, y; cin >> m; vector<int> M(m); for (int i = 0; i < (m); ++i) cin >> M[i]; int sum = accumulate(M.begin(), M.end(), 0); cerr << sum << endl; ci... |
#include <bits/stdc++.h> using namespace std; long long dp[5000005]; void solve() { for (long long i = 1; i <= 5000000; i++) dp[i] = i * (i - 1) / 2; for (long long i = 2; i <= 5000000 / 2; i++) { for (long long j = 2; j <= i; j++) { if (i * j > 5000000) break; dp[i * j] = min(dp[i *... |
#include <bits/stdc++.h> using namespace std; struct sak { int x, y; sak(int x1, int y1) { x = x1; y = y1; } }; vector<sak> A, B; vector<int> AA, BB; int findA(int k) { int t1 = -1; for (int i = 0; i < A.size(); i++) if (A[i].x <= k && AA[i] == 0 && (t1 == -1 || A[t1].y... |
#include <bits/stdc++.h> using namespace std; long long gcdExtended(long long a, long long b, long long *x, long long *y) { if (a == 0) { *x = 0; *y = 1; return b; } long long x1, y1; long long gcd = gcdExtended(b % a, a, &x1, &y1); *x = y1 - (b / a) * x1; *y = x1; retu... |
#include <bits/stdc++.h> #pragma comment(linker, /STACK:256000000 ) using namespace std; inline int readChar(); template <class T = int> inline T readInt(); template <class T> inline void writeInt(T x, char end = 0); inline void writeChar(int x); inline void writeWord(const char *s); static const i... |
#include <bits/stdc++.h> using namespace std; long long t, a, b, d; bool fun(long long mid) { long long total = mid * (mid + 1) / 2; if (total >= d) { return true; } return false; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> t; while (t--) { c... |
#include <bits/stdc++.h> using namespace std; string s; int n; bool sogl(char x) { return x != a && x != e && x != i && x != o && x != u ; } int dp[3000], opt[3000]; int main() { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); cin >> s; int n = s.size(); for (int i = 0; i < ... |
#include <bits/stdc++.h> using namespace std; int a[5][5]; int b[] = {0, 1, 2, 3, 4}; long long sol() { int p0 = b[0]; int p1 = b[1]; int p2 = b[2]; int p3 = b[3]; int p4 = b[4]; long long p = a[p0][p1] + a[p1][p0] + a[p2][p3] + a[p3][p2]; p += a[p1][p2] + a[p2][p1] + a[p3][p4] + a[p... |
#include <bits/stdc++.h> using namespace std; const int N = 2e6 + 5; const int mod = 1e9 + 7; int n, k, m, dp[N], lst[300]; char s[N]; inline int add(int x, int y) { return x + y >= mod ? x + y - mod : x + y; } inline int mul(int x, int y) { return (long long int)x * y % mod; } int main() { ios_base... |
#include <bits/stdc++.h> using namespace std; int main() { int r, c; cin >> r >> c; if (r == c and r == 1) return cout << 0, 0; if (r == 1) { for (int i = 0; i < c; i++) cout << 2 + i << ; return 0; } if (c == 1) { for (int i = 0; i < r; i++) cout << 2 + i << ; ... |
#include <bits/stdc++.h> using namespace std; int a[4]; int cmp(int x, int y) { return x > y; } int main() { int t; cin >> t; while (t--) { int ans = 0; cin >> a[0] >> a[1] >> a[2]; sort(a, a + 3, cmp); if (a[0]) { a[0]--; ans++; } if (a[1]) { ... |
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; int a[s.length()]; int ans = -1; int n = s.length(); for (int i = 0; i < s.length(); i++) { a[i] = int(s[i]) - 48; } for (int i = 0; i < n; i++) { if (a[i] % 8 == 0) { ans = a[i]; ... |
#include <bits/stdc++.h> using namespace std; int ans[30][5] = { {1, 0, 0, 1, 0}, {1, 1, 0, 2, 0}, {2, 0, 0, 1, 1}, {2, 1, 0, 1, 2}, {1, 1, 0, 1, 1}, {2, 1, 0, 2, 1}, {2, 2, 0, 2, 2}, {1, 2, 0, 2, 1}, {1, 1, 0, 1, 1}, {1, 2, 0, 1, 2}, {1, 0, 1, 2, 0}, {1, 1, 1, 3, 0}, {2... |
#include <bits/stdc++.h> using namespace std; int n, k, a[3000000]; int main() { ios_base::sync_with_stdio(false); cin >> n >> k; int mini = 2000000; for (int i = 1; i <= n; i++) { int x; cin >> x; mini = min(mini, x); a[max(1, x - k)]++; a[x + 1]--; } for (in... |
#include <bits/stdc++.h> using namespace std; const int MAXN = 3000000; const int MAXM = 200000; const int INF = 1000000010; const long long int MOD = 1000000007; const long long int P = 31; const long double EPS = 1e-6; int N, M, K; char s[MAXN]; long long int dp[26] = {0}; int last_used[26]; i... |
#include <bits/stdc++.h> #pragma GCC optimize( O2 ) #pragma GCC optimize( unroll-loops ) using namespace std; const long double eps = 1e-7; const int inf = 1000000010; const long long INF = 1000000000000001000LL; const int mod = 1000000007; const int MAXN = 300010, LOG = 19; struct Data { long lon... |
#include <bits/stdc++.h> using namespace std; string solve() { int n; cin >> n; int a[n]; for (int i = 0; i < n; i++) cin >> a[i]; if (n % 2 == 0) return YES ; for (int i = 0; i < n - 1; i++) if (a[i] >= a[i + 1]) return YES ; return NO ; } int main() { ios_base::sync_wi... |
#include <bits/stdc++.h> using namespace std; const int MOD = int(1e9) + 7; long long pom[2][2] = {{0, 1}, {1, 1}}; void mulMat(long long *A, long long *B, int n) { long long res[2][2] = {{0}}; for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) for (int k = 0; k < n; k++) { ... |
#include <bits/stdc++.h> using namespace std; long long int mod = 1000000007; void __print(long long int x) { cerr << x; } void __print(unsigned x) { cerr << x; } void __print(unsigned long x) { cerr << x; } void __print(unsigned long long x) { cerr << x; } void __print(float x) { cerr << x; } void __pr... |
#include <bits/stdc++.h> using namespace std; long long n; long long p[16]; long long Count(long long n, int i) { long long ret = (i + 1LL) * (n / p[i]); n %= p[i]; if (n == 0) return ret; return ret + min(Count(n, i - 1), i + 1 + Count(p[i] - n, i - 1)); } int main() { p[0] = 1; for... |
#include <bits/stdc++.h> using namespace std; int a[500010]; int main() { int n; cin >> n; a[0] = 2; vector<pair<int, int> > cumcnt; for (int i = 1; i <= n; ++i) { cin >> a[i]; if (a[i] == a[i - 1]) cumcnt.back().second++; else cumcnt.emplace_back(a[i], 1); ... |
#include <bits/stdc++.h> using namespace std; const int MAXN = 100000 + 7; vector<vector<int> > g, gr; vector<char> used; vector<int> order, component; void dfs1(int v) { used[v] = true; for (size_t i = 0; i < g[v].size(); ++i) if (!used[g[v][i]]) dfs1(g[v][i]); order.push_back(v); } v... |
#include <bits/stdc++.h> using namespace std; string s1, s2; int main() { cin >> s1 >> s2; if (s1.length() != s2.length()) cout << NO ; else { int x = 0; int y = 0; for (int i = 0; i < s1.length(); i++) { if (s1[i] - 0 == 1) x++; if (s2[i] - 0 == 1) y++; ... |
#include <bits/stdc++.h> using namespace std; const long long INF = 1E18; const int MAXN = 2000; int l[MAXN]; int r[MAXN]; int a[MAXN]; long long dp[MAXN]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, k; cin >> n >> k; bool poss = true; long long extra = 0... |
#include <bits/stdc++.h> using namespace std; string n; int k; int main() { cin >> n >> k; if (n[0] == 0 ) { cout << 0 << endl; return 0; } int count = 0, c = 0; for (int i = n.size() - 1; i >= 0; i--) { count += (n[i] == 0 ); c += (n[i] != 0 ); if (count == ... |
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; int n, m, tren, pos[N], cnt[N]; vector<int> g[N]; int dist(int a, int tr) { if (a > tr) return a - tr; else return n + a - tr; } bool cmp(int a, int b) { if (dist(a, tren) < dist(b, tren)) return true; return ... |
#include <bits/stdc++.h> using namespace std; const int size = 100004; char s[size][4]; struct node { int l, r, cnt; long long sum[6]; } tree[size * 4]; int tmp[size], q[size]; void pushup(int rt) { int i; for (i = 0; i < 5; ++i) tree[rt].sum[i] = tree[rt << 1].sum[i] + ... |
#include <bits/stdc++.h> using namespace std; int used[100]; vector<vector<int>> g; int cmp = 0; vector<int> parent, rank1; void make_set(int v) { parent[v] = v; rank1[v] = 0; } int find_set(int v) { if (v == parent[v]) return v; return parent[v] = find_set(parent[v]); } void union_s... |
#include <bits/stdc++.h> using namespace std; int main() { double m, n; long long int r, a, b, c, d, dist, sim; cin >> r >> a >> b >> c >> d; dist = (c - a) * (c - a) + (d - b) * (d - b); m = sqrt(dist); m = m / 2; c = m / r; m = m / r; if (m == c) cout << c; else ... |
#include <bits/stdc++.h> using namespace std; map<int, bool> in; int main() { int n, mx = 0, arr[200], ans = 0; char a[200]; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i] >> arr[i]; if (a[i] == + ) { in[arr[i]] = true; mx++; } else if (a[i] == - ) { ... |
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; cout << n / 2 << endl; if (n % 2) { while (n > 3) { cout << 2 << ; n -= 2; } cout << 3; } else { while (n) { cout << 2 << ; n -= 2; } } cout << ... |
#include <bits/stdc++.h> using namespace std; long sail(char ar[], long a, long m, long n) { for (int k = 0; k < a; k++) { if (m > 0) { if (ar[k] == E ) m--; } if (m < 0) { if (ar[k] == W ) m++; } if (n > 0) { if (ar[k] == N ) n--; } if (n < 0... |
#include <bits/stdc++.h> using namespace std; void solve() { long long int n, cnt = 0; cin >> n; for (long long i = 2; i <= sqrt(n); i++) { long long int temp[n]; if ((i * i * i) <= n) cnt++; } cout << cnt + 1 << endl; } void opti() { long long int n; cin >> n; set<in... |
#include <bits/stdc++.h> using namespace std; int a, b; int main() { cin >> a >> b; cout << a + b << endl; } |
#include <bits/stdc++.h> using namespace std; template <class a, class b> pair<a, b> operator+(pair<a, b> x, pair<a, b> y) { return (pair<a, b>(x.first + y.first, x.second + y.second)); } template <class t> ostream &operator<<(ostream &tout, const vector<t> &s) { tout << [ ; for (long long i = ... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, m, p[2000], d[2000], s[2000]; cin >> n >> m; for (int i = 0; i < 2 * n; ++i) cin >> p[i]; array<int, 2> a[1000]; memset(d, -1, sizeof(d)); for (int i = 0; i < m; ++i) { c... |
#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 l, r; int p = 0, j = 0, i = 0, len = 0, cnt = 0; while (j < n) { if (a[j] == 0) { cnt++; } while (cnt > k) { if (a[... |
#include <bits/stdc++.h> using namespace std; const int N = 100005, MAX = 202; struct Leg { int len, cost; friend bool operator<(const Leg x, const Leg y) { return x.len < y.len; } }; Leg l[N]; int sum[N]; int c[MAX][N]; int f[N]; bool vis[N]; int main() { int n; scanf( %d , &n); ... |
#include <bits/stdc++.h> using namespace std; const int N = 1001; int n, a, b, u; int sol[N][N]; void W() { for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { printf( %d , sol[i][j]); } printf( n ); } } int main() { cin >> n >> a >> b; if (a != 1 && b ... |
#include <bits/stdc++.h> using namespace std; set<pair<int, int> > V; int p[102345]; int main() { int n, m, x, y; scanf( %d%d , &n, &m); for (int i = 1; i <= m; i++) { scanf( %d%d , &x, &y); V.insert(make_pair(x, y)); V.insert(make_pair(y, x)); } for (int i = 0; i < n; i++)... |
#include <bits/stdc++.h> using namespace std; signed main() { std::ios::sync_with_stdio(false); cin.tie(NULL); long long n, k; cin >> n >> k; string s; cin >> s; s = 0 + s + 0 ; for (long long i = 0; i < s.length() - 1; i++) { if (k == 0) break; if (s[i] == 4 && s[i ... |
#include <bits/stdc++.h> using namespace std; long long pow(long long b, long long e, long long m) { long long t = 1; for (; e; e >>= 1, b = b * b % m) e & 1 ? t = t * b % m : 0; return t; } template <class T> inline bool chkmin(T &a, T b) { return a > b ? a = b, true : false; } template <... |
#include <bits/stdc++.h> using namespace std; vector<int> a[100010], dp[100010]; int len[100010]; int main() { int n, m, i, j, k, l, r; while (~scanf( %d%d , &n, &m)) { for (i = 1; i <= n; i++) { a[i].resize(m + 1); for (j = 1; j <= m; j++) scanf( %d , &a[i][j]); } mems... |
#include <bits/stdc++.h> using namespace std; set<char> Set; pair<int, int> p[181]; string s, sn; int i, k, sum; bool pole[181]; int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> s; cin >> k; for (i = 0; i < s.size(); i++) p[s[i] - 96].first++; for (i = 1; i <= 26; i++) p[i]... |
#include <bits/stdc++.h> int main() { int n, m, r; scanf( %d%d%d , &n, &m, &r); if (2 * r <= n && 2 * r <= m) puts( First ); else puts( Second ); } |
#include <bits/stdc++.h> using namespace std; struct edge { int v, u, w; edge() {} edge(int v, int u, int w) : v(v), u(u), w(w) {} }; const int N = 2e5 + 7; vector<pair<int, bool>> g[N]; vector<pair<int, int>> gg[N]; vector<edge> glob_ans; int color[N]; void init(int n) { for (int i = ... |
#include <bits/stdc++.h> using namespace std; int n; vector<long long> v(100005); vector<int> cache(1e5 + 10, -1); int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n; map<int, int> mp; for (long long i = 0; i < n; i++) { int x; cin >> x; set<int> st; for (in... |
#include <bits/stdc++.h> using namespace std; int a[10], b[10]; int main() { int m, n; cin >> m >> n; for (int i = 0; i < m; i++) cin >> a[i]; for (int j = 0; j < n; j++) cin >> b[j]; sort(a, a + m); sort(b, b + n); int flag = 0, ans; for (int i = 0, j = 0; i < m && j < n;) { ... |
#include <bits/stdc++.h> using namespace std; const int maxn = 1005; int n, m; char c[maxn][maxn]; static int dx[] = {-1, 0, 0, 1}; static int dy[] = {0, -1, 1, 0}; namespace dsu { int fa[maxn * maxn]; int cnt[maxn * maxn]; int id(int x, int y) { return x * m + y; } int findfa(int x) { if (fa[... |
#include <bits/stdc++.h> using namespace std; int b, d, ct; int gcd(int x, int y) { return y ? gcd(y, x % y) : x; } int main() { cin >> b >> d; while (gcd(b, d) > 1) { d /= gcd(b, d); ++ct; } if (d == 1) cout << 2-type n << ct << n ; else if (!ct && b % d == 1) co... |
#include <bits/stdc++.h> using namespace std; long long a, b, mod, sumz, sumy, sum, last, first, kol, z; long long run(long long x, long long step) { long long res = 1; while (step) { if (step & 1) res = (res * x) % mod; x = x * x % mod; step >>= 1; } return res % mod; } int ... |
#include <bits/stdc++.h> int main() { int ans = 0; int tub[3] = {0}; int n, a; scanf( %d , &n); for (int i = 1; i <= n; i++) { scanf( %d , &a); tub[a % 3]++; } ans = (tub[0] / 2) + ((tub[1] > tub[2]) ? tub[2] : tub[1]); printf( %d , ans); return 0; } |
#include <bits/stdc++.h> using namespace std; const int INF = 1 << 30; const double EPS = 1e-7; int main() { ios::sync_with_stdio(false); int n; cin >> n; string s; cin >> s; int ans = 0; for (int i = n; i < (int)s.length(); i += n) { bool equal = true; for (int j = 1; j ... |
#include <bits/stdc++.h> using namespace std; const int din[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; bool correct(int d, int m, int y) { if (d > 31 || m > 12 || y > 99) return false; int dc = din[m - 1]; if (y % 4 == 0 && m == 2) dc++; if (d > dc) return false; return true; } ... |
#include <bits/stdc++.h> using namespace std; constexpr int N = 23; int n, m, u, v, adj[N], hamsaye[1 << N], ans = N, ans2; bool connected[1 << N]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> m; if (2 * m == n * (n - 1)) { cout << 0 << n ; ... |
#include <bits/stdc++.h> using namespace std; int main() { int k; cin >> k; auto n = 19; auto t = 1; while (true) { auto temp = n; auto sum = 0; while (temp > 0) { auto a = temp % 10; temp = temp / 10; sum = sum + a; } if (sum == 10) { ... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int k; cin >> k; string s, t; cin >> s; cin >> t; int sarr[k]; int tarr[k]; for (int i = k - 1; i >= 0; i--) { sarr[i] = s[i] - a ; tarr[i] = t[i] - a ; ... |
#include <bits/stdc++.h> using namespace std; int main() { int n, x, c = 0; scanf( %d , &n); for (int i = 1; i <= n; i++) { scanf( %d , &x); if (!x && !c) c = 1; else if (c == 1 && !x) c = 2; } if (n == 1) { if (x) printf( YES n ); else ... |
#include <bits/stdc++.h> using namespace std; const int INF = 1e9 + 10; const long long int INFLL = 1e18 + 10; const long double EPS = 1e-8; const long double EPSLD = 1e-14; const long long int MOD = 1000000007; template <class T> T &chmin(T &a, const T &b) { return a = min(a, b); } template <cl... |
#include <bits/stdc++.h> using namespace std; vector<int> s; vector<vector<int> > t; bool sortFunc(vector<int> a, vector<int> b) { if (a.size() == 0) return false; if (b.size() == 0) return true; return a.size() < b.size(); } int main() { cin.sync_with_stdio(false); cin.tie(0); int n... |
#include <bits/stdc++.h> using namespace std; long long int digSum(long long int n) { long long int sum = 0; while (n != 0) { sum += n % 10; n = n / 10; } return sum; } bool cmp1(int a, int b) { return a < b; } bool cmp2(int a, int b) { return a > b; } int main() { ios_base::... |
#include <bits/stdc++.h> using namespace std; int p, n; vector<int> gra[100010]; double dp[100010], sz[100010]; void dfs(int u) { sz[u] = 1; int m = gra[u].size(); for (int i = 0; i <= m - 1; i++) { dfs(gra[u][i]); sz[u] += sz[gra[u][i]]; } } void solve(int u) { int m = gra... |
#include <bits/stdc++.h> using namespace std; int main() { int n, T, low, mid, high, a[200005], t[200005]; vector<int> ans; scanf( %d%d , &n, &T); for (int i = 1; i <= n; i++) { scanf( %d%d , &a[i], &t[i]); } low = 0; high = n; while (low <= high) { mid = (low + high) / 2... |
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) #pragma GCC target( avx,avx2,fma,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native ) using namespace std; long long MOD = 998244353; long long INF = 1e18; const int N = 100001; long long dp[N][101]; long long sm[N]; long long cnt[N][... |
#include <bits/stdc++.h> using namespace std; const int MAX_N = 100005; int n; int m; int cnt[MAX_N]; int a[MAX_N]; int main() { scanf( %d %d , &m, &n); for (int i = 1; i <= n; i++) { scanf( %d , &a[i]); } int diff = 0; for (int i = 1; i <= n; i++) { cnt[a[i]]++; if (... |
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cerr << Time : << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << ms n ; long long t; cin >> t; while (t--) { long long n, g = 0, s = 0, b = 0, i, gidx, bi... |
#include <bits/stdc++.h> using namespace std; vector<int> graph[2001]; vector<int> level[2001]; int visited[2001]; int a, b; void dfs(int u, int depth) { visited[u] = 1; level[depth].push_back(u); for (int v : graph[u]) { if (!visited[v]) { dfs(v, depth + 1); } } } in... |
#include <bits/stdc++.h> using namespace std; const int maxiz = 1000 * 1000 + 100; int d[maxiz]; int main() { int n; long long A, M = 0; cin >> n >> A; for (int i = 0; i < n; i++) { cin >> d[i]; M = (M + d[i] * 1ll) * 1ll; } for (int i = 0; i < n; i++) { long long maxi,... |
#include <bits/stdc++.h> using namespace std; int f[20001][101]; struct node { int ai, bi; } a[1001]; bool cmp(node x, node y) { return x.bi > y.bi; } int main() { int n, sum1 = 0, sum2 = 0, d = 0; scanf( %d , &n); for (int i = 1; i <= n; i++) { scanf( %d , &a[i].ai); sum1 += a[i... |
#include <bits/stdc++.h> using namespace std; const int N = 110; const int M = 10010; int n, m; char mat[N][M]; int dir[2] = {-1, 1}; long long solve() { long long ans = 0; int x = 0, y = 0, d = 1; bool isLeft = true, isRight = true; int pos[2] = {0, 0}; while (true) { if (!isLef... |
#include <bits/stdc++.h> using namespace std; int t[1000005], r = 1000004; int dp[1000005]; int main() { memset(dp, 0, sizeof(dp)); memset(t, 0, sizeof(t)); int n, ans = 0, x; cin >> n; for (int i = 0; i < n; i++) { cin >> x; cin >> t[x]; } dp[0] = 0; if (t[0] != 0) d... |
#include <bits/stdc++.h> using namespace std; using ll = long long; const int N = 2e5 + 5; int n, q; ll a[N], tree[N << 2], lz[N << 2]; void push(int node, int s, int e) { tree[node] += lz[node]; if (s != e) { lz[node << 1] += lz[node]; lz[node << 1 | 1] += lz[node]; } lz[node] =... |
#include <bits/stdc++.h> const double pi = acos(-1.0), eps = 1e-9; const int dx[8] = {1, -1, 0, 0, 1, 1, -1, -1}; const int dy[8] = {0, 0, 1, -1, 1, -1, -1, 1}; const int MO = (int)(1e9 + 7); using namespace std; int main() { long long n; cin >> n; while (n % 3 == 0) n /= 3; cout << n / 3 + ... |
#include <bits/stdc++.h> using namespace std; void fileio() {} vector<vector<long long int>> g; long long int cube_root(long long int x) { long long int lo = 0, hi = 1e6 + 10; while (lo <= hi) { long long int m = (lo + hi) / 2; long long int val = m * m * m; if (val == x) return m; ... |
#include <bits/stdc++.h> using namespace std; int vis[51]; int main() { string s; int n, len; cin >> len >> n; cin >> s; while (n--) { for (int i = 0; i <= len; i++) { if (s[i] == B && s[i + 1] == G ) { swap(s[i], s[i + 1]); i++; } } } ... |
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; int a[10000], b[10000]; for (int n = 0; n < N; n++) { cout << ? << 0 << << n << endl; cin >> a[n]; } for (int n = 0; n < N; n++) { cout << ? << n << << 0 << endl; cin >> b[n]; ... |
#include <bits/stdc++.h> using namespace std; int ans1 = 0, ans2 = 0; int main(void) { int t, i, j; cin >> t; while (t--) { int n, mx = INT_MIN, ans = 0, sz; cin >> n; int a[n]; set<int> s; for (i = 0; i < n; i++) { cin >> a[i]; mx = max(mx, a[i]); ... |
#include <bits/stdc++.h> using namespace std; int main() { int n, k, a, b; scanf( %d%d , &n, &k); printf( %d , n); for (int i = n - 1; i > k; --i) printf( %d , i); a = 1, b = k; while (a < b) printf( %d %d , a++, b--); if (a == b) printf( %d , a); puts( ); } |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, m, c; cin >> n >> m >> c; int a[n], b[m]; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < m; i++) cin >> b[i]; for (int i = 0; i < n - m + 1; i++) { i... |
#include <bits/stdc++.h> using namespace std; long long a, b, c, l, tl, ans, ca, cb, cc; long long min(long long a, long long b) { return a < b ? a : b; } void cpy() { a = ca, b = cb; c = cc; } int main() { scanf( %lld%lld%lld%lld , &a, &b, &c, &l); ca = a; cb = b; cc = c; for (i... |
#include <bits/stdc++.h> using namespace std; string a, b; bool func(string s, long n) { if (s.size() % n) return false; for (long i = 0; i < s.size(); i++) if (s[i] != a[i % n]) return 0; return 1; } int main() { cin >> a >> b; long ans = 0, i = 1; string p = a, q = b; long ... |
#include <bits/stdc++.h> using namespace std; #pragma warning(disable : 4996) const double PI = acos(-1); const long long N = 500005, md = 1e9 + 7, inf = 1e18, iinf = 1e9 + 5, MX = 3e5; long long g, w, h, x, y, z, i, j, k, q, n, cnt, res, sum, r[N], a[N], b[N]; char c[N]; string s, t; pair<int, int> p[N... |
#include <bits/stdc++.h> using namespace std; bool ask(int val) { cout << ? << val + 1 << endl; string resp; cin >> resp; return resp[0] == Y ? true : false; } void fix() { cout << R << endl; } int main() { int n, k; cin >> n >> k; vector<bool> check(n + 1, 0); int block... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.