func_code_string stringlengths 59 71.4k |
|---|
#include <bits/stdc++.h> using namespace std; struct edge { long long a, b, index; long long u, v; }; bool compare(edge i, edge j) { if (i.a == j.a) return i.b > j.b; return i.a < j.a; } bool compare2(edge i, edge j) { return i.index < j.index; } int main() { ios::sync_with_stdio(false... |
#include <bits/stdc++.h> using namespace std; const int MAXN = 1086; const int MAXT = 1586; const long long R = 1000000; struct query { long long ts, tl; long double ss, sl, p; query() {} query(long double _ss, long double _sl, long long _ts, long long _tl, long double _p) : ... |
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int n, d; cin >> n; unordered_set<int> s; int mx = n; int c = 0; for (int i = 0; i < n; i++) { cin >> d; if (d == mx) { for (int i = 0; i < c; i++) cout << n ; ... |
#include <bits/stdc++.h> using namespace std; bool a[2][100010]; int n, q, nr, x, y; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> q; for (int i = 1; i <= q; i++) { cin >> x >> y; x--; if (a[x][y]) nr -= a[(x + 1) % 2][y - 1] + ... |
#include <bits/stdc++.h> using namespace std; double n, h; char c[10]; double ans; double ksm(double x, long long y) { double maretu = 1.0; for (; y; y >>= 1) { if (y & 1) { maretu *= x; } x *= x; } return maretu; } int main() { scanf( %s , c); if (c[0] ==... |
#include <bits/stdc++.h> using namespace std; int main() { int n, t, cont[8] = {0}, i; cin >> n; for (int i = 0; i < n && cin >> t; i++) cont[t]++; if (cont[1] != n / 3 || cont[5] + cont[7] || cont[4] > cont[2] || cont[3] > cont[6] || cont[2] + cont[3] != cont[4] + cont[6]) cout << -1;... |
#include <bits/stdc++.h> using namespace std; const long long maxm = 2e5 + 5; vector<long long> g[maxm]; long long mark[maxm]; long long p[maxm]; long long c[maxm]; long long ans; long long n; void solve(long long x) { vector<long long> s; while (!mark[x]) { s.push_back(x); mark[x]... |
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; int n = s.size(); int pref = 0; int kol = 0; for (int i = 0; i < n; i++) { if (s[i] == # ) kol++; if (s[i] == ( ) pref++; else pref--; if (pref < 0) { cout << -1 ... |
#include <bits/stdc++.h> using namespace std; map<long long, long long> dist; int main() { long long n, m; cin >> n >> m; long long x; queue<long long> q; for (long long i = 0; i < n; i++) { cin >> x; dist[x] = 0; q.push(x); } long long total = 0; vector<long long... |
#include <bits/stdc++.h> using namespace std; int n, A, B; long long toi(string s) { istringstream is(s); long long x; is >> x; return x; } string tos(long long t) { stringstream st; st << t; return st.str(); } long long F[1000005], FP[1000005]; bool f(long long x) { whil... |
#include <bits/stdc++.h> using namespace std; class qry { public: int l, r, idx; qry(int l, int r, int idx) : l(l), r(r), idx(idx) {} }; int a[500001], n, m, res[500001]; vector<qry> q; int getans(vector<int> b) { int res = 0; for (int i = 0; i < b.size(); i++) { if ((res ^ b[i]) > ... |
#include <bits/stdc++.h> int main(int argc, const char* argv[]) { int n, k; scanf( %d%d , &n, &k); if (k > n / 2) k = n / 2; printf( %I64d n , k * (2 * n - 2 * k - 1ll)); return 0; } |
#include <bits/stdc++.h> using namespace std; const int MAXN = 1005, MAXM = 200005; int n, m, q, f[MAXN][MAXN], head[MAXM], nxt[MAXM], x[MAXM], y[MAXM]; struct Q { int l, r, s, t; } s[MAXM]; bool ans[MAXM]; int main() { scanf( %d%d%d , &n, &m, &q); for (register int i = 1; i <= m; ++i) scanf( ... |
#include <bits/stdc++.h> using namespace std; const int inf = (int)1e9; const long long int INF = (long long int)1e18; const int N = 100005; const long long int MOD = 1000000007; const double EPS = 1e-7; const double PI = acos(-1.0); const int dx[] = {+1, -1, +0, +0}; const int dy[] = {+0, +0, +1, -1}... |
#include <bits/stdc++.h> using namespace std; set<int> E[100005]; vector<int> L[100005]; int True = 0; int vst[100005]; int main() { int n, m, h, t, i, u, v, _h, _t, j, k; cin >> n >> m >> h >> t; for (i = 0; i < (m); i++) { scanf( %d%d , &u, &v); L[u].push_back(v); L[v].push_b... |
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const int mod2 = 1e9 + 9; inline int pow_(long long a, int n, int p = mod) { int r = 1; while (n) { if (n & 1) r = r * a % p; n >>= 1; a = a * a % p; } return r; } int main(void) { int n, l; long... |
#include <bits/stdc++.h> using namespace std; int x, y, n, m, i, k, ans; string s[30], s1[30]; int main() { cin >> n >> m; for (i = 0; i < n; i++) { cin >> s[i]; } for (i = 0; i < m; i++) { cin >> s1[i]; } cin >> k; for (i = 0; i < k; i++) { cin >> x; if (x % ... |
#include <bits/stdc++.h> const int MAXN = 1e9 + 7; const int INF = 1e9 + 7; const signed long long MOD = 1e9 + 7; using namespace std; bool comp1(signed long long a, signed long long b) { return (sin(a) < sin(b)); } signed long long binpow(signed long long a, signed long long b) { signed long long res =... |
#include <bits/stdc++.h> using namespace std; vector<pair<int, int> > ans; bool is_prime(int v) { if (v == 1 || v == 0) return 0; for (int i = 2; i * i <= v; i++) { if (v % i == 0) return 0; } return 1; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ... |
#include <bits/stdc++.h> using namespace std; const long long INF = 1e9 + 7; const int N = 3e5 + 10; int flag[N]; set<int> s[N]; int a[N]; int pos[N]; int main() { int n, m; scanf( %d%d , &n, &m); for (int i = 1; i <= n; i++) { scanf( %d , &a[i]); pos[a[i]] = i; } while (... |
#include <bits/stdc++.h> using namespace std; mt19937 rd(time(0)); vector<long long> v(100010), val(100010), con[100010], st(100010, 0), en(100010, 0), d(100010, 0); pair<long long, long long> t[20][100010]; long long cur = 0; void dfs(long long node, long long par, long long dep) { st[node] = ++c... |
#include <bits/stdc++.h> using namespace std; struct edge { short to, cap, rev; edge(int _a = 0, int _b = 0, int _c = 0) { to = _a; cap = _b; rev = _c; } }; int S, T; int dist[30010]; int cur[30010]; vector<edge> adj[30010]; int q[30010]; int hd, tl; inline void addedge... |
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; template <class S, class T> ostream &operator<<(ostream &os, const pair<S, T> v) { os << ( << v.first << , << v.second << ) ; return os; } template <class T> ostream &operator<<(ostream &os, const ... |
#include <bits/stdc++.h> using namespace std; template <typename T> void print(T v) { cout << v << n ; } template <typename T> void print(vector<T> a) { for (int i = 0; i < a.size(); i++) { cout << a[i] << ; } cout << n ; } long long help(long long a, long long b, long long ... |
#include <bits/stdc++.h> using namespace std; int n, m; char ch[201][201]; int main() { cin >> m >> n; n *= 2; m *= 2; for (int i = 1; i <= n; i += 2) for (int j = 1; j <= m; j += 2) { cin >> ch[i][j]; ch[i + 1][j] = ch[i][j + 1] = ch[i + 1][j + 1] = ch[i][j]; } f... |
#include <bits/stdc++.h> using namespace std; int main() { string s; int n; int arr[26]; int arr2[26]; cin >> s; int value; int sum = 0; int add; int length = s.size(); cin >> n; for (int i = 0; i < 26; i++) { cin >> arr[i]; arr2[i] = arr[i]; } sort(ar... |
#include <bits/stdc++.h> using namespace std; template <typename T, typename U> std::istream& operator>>(std::istream& i, pair<T, U>& p) { i >> p.first >> p.second; return i; } template <typename T> std::istream& operator>>(std::istream& i, vector<T>& t) { for (auto& v : t) { i >> v; }... |
#include <bits/stdc++.h> using namespace std; int n, m; vector<pair<int, int>> G[262144]; int d1[26][262144]; pair<int, int> d2[2][262144]; int vis[2][262144]; long long mod = 998244353ll; long long qpow(long long x, long long y) { long long a = x, ans = 1; while (y) { if (y & 1) ans = (an... |
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; long long ans = 0; for (int i = (0); i < (n); ++i) { long long t, T, x, cost; cin >> t >> T >> x >> cost; if (t >= T) { ans += cost + m * x; continue; } long long aux1 = ... |
#include <bits/stdc++.h> using namespace std; int main() { int n, m; scanf( %d %d , &n, &m); vector<int> att, def, my(m); for (int i = 0; i < n; i++) { char a, b, c; int s; scanf( %c%c%c %d , &a, &b, &c, &s); if (a == A ) att.push_back(s); else def.pus... |
#include <bits/stdc++.h> using namespace std; int n; long long a[1010]; long long ans; long long vis[1010]; map<long long, long long> mp; void dfs(long long x, long long y, long long cnt) { ans = max(cnt, ans); if (mp[x + y]) { mp[x + y]--; dfs(y, x + y, cnt + 1); mp[x + y]++; ... |
#include <bits/stdc++.h> using namespace std; int t[24], n; bool ok(int n) { set<int> u; int e = 0; for (int(i) = (0); (i) < (n); (i)++) for (int(j) = (0); (j) < (i); (j)++) { e++; u.insert(abs(t[i] + t[j])); } return (e == u.size()); } int main() { scanf( %d , ... |
#include <bits/stdc++.h> using namespace std; int main() { int sum; cin >> sum; int a, b, c = -1; for (int i = 0; i * 7 <= sum; i++) { if ((sum - i * 7) % 4 == 0) { int j = (sum - i * 7) / 4; if (c == -1 || i + j < c) { c = i + j; a = j; b = i; ... |
#include <bits/stdc++.h> using namespace std; long long n, m, l, r; vector<long long> A[200001]; set<pair<int, int> > se; void add(long long y) { for (auto b : A[y]) se.insert({b, y}); } void del(long long y) { for (auto b : A[y]) se.erase({b, y}); } int main() { ios_base::sync_with_stdio(... |
#include <bits/stdc++.h> int main() { static int vv[100][100], tt[100][100], kk[100]; int n, s, h, i, j, k, t, t_, d1, d2, cnt, lead; scanf( %d%d , &n, &s); for (i = 0; i < n; i++) { scanf( %d , &kk[i]); for (j = 0; j < kk[i]; j++) scanf( %d%d , &vv[i][j], &tt[i][j]); for (j = 1; j <... |
#include <bits/stdc++.h> using namespace std; const double eps = 1e-8; long long ii = 1; vector<long long> prime; bitset<1000000> bs; void sieve() { bs.set(); bs[0] = bs[1] = 0; prime.push_back(2); for (long long i = 3; i <= 1000000; i += 2) { if (bs[i]) { for (long long j = i ... |
#include <bits/stdc++.h> using namespace std; struct Lem { int m, v, id; bool operator<(Lem b) const { return m < b.m || (m == b.m && v < b.v); } }; int n, k, h; Lem a[(100000 + 10)]; bool can(long double t) { int j = k; for (int i(n - 1), _l(0); i >= _l; --i) { if (j > 0 && (long doub... |
#include <bits/stdc++.h> using namespace std; int n, m, k, l, r; int rd() { int re = 0, f = 1; char c = getchar(); while ((c < 0 ) || (c > 9 )) { if (c == - ) f = -f; c = getchar(); } while ((c >= 0 ) && (c <= 9 )) { re = re * 10 + c - 0 ; c = getchar(); } ... |
#include <bits/stdc++.h> using namespace std; const int MAXN = 130; int a[MAXN]; int main() { int N; cin >> N; for (int i = 1; i < (N + 1); ++i) cin >> a[i]; bool ok = 0; if ((a[N] & 1) == 0 || (a[1] & 1) == 0) ok = 0; else if (N & 1) ok = 1; if (ok) cout << Yes <... |
#include <bits/stdc++.h> using namespace std; struct segment_tree { long long a[1 << 20][5]; int sz[1 << 20]; int N; void initi(int x) { N = 1; while (N < x) N <<= 1; } void pushup(int x) { int pos = x + N - 1; while (x > 0) { x = (x - 1) >> 1; sz[x] =... |
#include <bits/stdc++.h> using namespace std; const int N = 100010; void answer(int u) { printf( ! %d n , u); fflush(stdout); } int ask(int u) { printf( ? %d n , u); fflush(stdout); int res; scanf( %d , &res); return res; } bool inside(int u, pair<int, int> v) { return ((u ... |
#include <bits/stdc++.h> using namespace std; const int INFL = (int)1e9; const long long int INFLL = (long long int)1e18; const double INFD = numeric_limits<double>::infinity(); const double PI = 3.14159265358979323846; bool nearlyeq(double x, double y) { return abs(x - y) < 1e-9; } bool inrange(int x, in... |
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; for (int i = 0; i < n; i++) { cout << 1 << ; } cout << endl; } return 0; } |
#include <bits/stdc++.h> using namespace std; void display(vector<int> v1) { for (long long int i = 0; i < v1.size(); i++) { cout << v1[i] << ; } cout << endl; } long long int dx[8] = {0, 1, 0, -1, 1, 1, -1, -1}; long long int dy[8] = {1, 0, -1, 0, 1, -1, 1, -1}; int n, dp[9000][2]; v... |
#include <bits/stdc++.h> using namespace std; const int mod = 998244353; const int N = 5e5 + 5; long long l[N], r[N], x[N], d[N], s[N], pre[N], dp[N]; int n, m; inline long long solve(int u) { for (int i = 1; i <= n; i++) d[i] = s[i] = pre[i] = 0; for (int i = 1; i <= m; i++) { if (x[i] >> u &... |
#include <bits/stdc++.h> using namespace std; long long mod = 1e9 + 7; int inf = 1e9; double eps = 1e-6; int main() { int n, k; cin >> n >> k; vector<int> a; for (int i = 0; i < n; i++) { int t; cin >> t; a.push_back(t); } if (k == 1) { int ans = a[0]; for... |
#include <bits/stdc++.h> int a[100005] = {}; int p[100005] = {}; int mbuy[100005] = {}; int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(NULL); std::cout.tie(NULL); int n, currmin = 1000000, buy = 0, last = 0; std::cin >> n; for (int i = 0; i < n; i++) std::cin >> a[i] >>... |
#include <bits/stdc++.h> using namespace std; const int N = 1e5; const int inf = 1e7; int tree[4 * N + 100], ans[2 * N + 100]; vector<int> R[N + 100], C[N + 100]; vector<pair<pair<int, int>, pair<int, int> > > qr[N + 100], qc[N + 100]; void update(int v, int tl, int tr, int idx, int val) { if (tl == t... |
#include <bits/stdc++.h> using namespace std; const int inf = 1 << 30; const long long INF = 1ll << 60; const double Inf = 1e20; const double eps = 1e-9; void gmax(int &a, int b) { a = (a > b ? a : b); } void gmin(int &a, int b) { a = (a < b ? a : b); } const int P = 1e9 + 7; const int maxn = 1000050;... |
#include <bits/stdc++.h> using namespace std; const int N = 5e5 + 7; const int MX = 1e9 + 7; const long long int INF = 1e18 + 9LL; int n, m, k; long long int value[N]; pair<long long int, pair<int, int> > edge[N]; int pt[N]; int rep[N]; int res = 0; int Find(int a) { if (rep[a] == a) return a;... |
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; string s; while (n--) cin >> s; bool wall = false; int segments = 0, i = 0; while (i < s.size()) { if (!wall && s[i] == B ) { segments++; wall = true; } else if (wall && s[i] ... |
#include <bits/stdc++.h> using namespace std; const long long INF = (long long)1e18; const int mod = (int)1e9 + 7; const int MAXN = (int)3e5 + 5; long long n; string s; bool vr[27]; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cin >> s; for (int... |
#include <bits/stdc++.h> using namespace std; const int nax = 200005; const int mod = 998244353; vector<int> graph[nax]; vector<int> degree(nax); vector<int> level(nax); vector<int> vis(nax); vector<int> parent(nax); vector<int> str[nax]; void dfs(int node, int l) { vis[node] = 1; level[node... |
#include <bits/stdc++.h> int main() { int t; scanf( %d , &t); while (t--) { int n; scanf( %d , &n); int flag; if (n & 1) { flag = 2; for (int i = 1, tmp; i <= n; i++) { scanf( %1d , &tmp); if ((i & 1) && (tmp & 1)) flag = 1; } pri... |
#include <bits/stdc++.h> using namespace std; const string T = abacaba ; bool check(string s) { int cnt = 0; for (int i = 0; i < s.length() - 6; i++) if (s.substr(i, 7) == T) cnt++; return (cnt == 1); } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t; ... |
#include <bits/stdc++.h> int main() { int i = 0, j = 0, l, k; char a[100], s[100], shift; scanf( %c , &shift); scanf( %s , a); l = strlen(a); for (k = 0; k < l; k++) { if (shift == R && i <= l && a[i] == w ) { a[i] = q ; i++; } else if (shift == R && i <= l &&... |
#include <bits/stdc++.h> using namespace std; int cnt[26]; bool work() { char ch; while (isalpha(ch = getchar())) ++cnt[ch - a ]; int c = 0; for (int x = 0; x < 26; ++x) if (cnt[x] & 1) ++c; return c == 0 || (c & 1); } int main() { puts(work() ? First : Second ); } |
#include <bits/stdc++.h> const int mod = 998244353; using namespace std; long long gcd(long long a, long long b) { if (a == 0) return b; return gcd(b % a, a); } long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); } long long power(long long x, long long y) { long long res = 1; ... |
#include <bits/stdc++.h> using namespace std; signed main() { long long t, n, m, xa, ya, xb, yb; scanf( %lld , &t); while (t--) { scanf( %lld%lld%lld%lld%lld%lld , &n, &m, &xa, &ya, &xb, &yb); long long miny = min(ya, yb), minx = min(xa, xb), maxy = max(ya, yb), maxx = max(xa... |
#include <bits/stdc++.h> using namespace std; const long long int N = 5e3 + 7; vector<vector<long long int> > v(N); long long int cl[N]; void dfs(long long int s, long long int c) { if (cl[s] == -1 || cl[s] == c) return; cl[s] = c; for (auto it = v[s].begin(); it != v[s].end(); it++) { if (c... |
#include <bits/stdc++.h> using namespace std; const int maxn = 1e18; const int INF = 0x3f3f3f3f; int a[200010]; int dp[1000010]; int main() { int n, m, k; cin >> n >> m >> k; for (int i = 0; i < n; i++) { cin >> a[i]; dp[a[i]] = 1; } int t = 0, p = 0; int res = 0; for... |
#include <bits/stdc++.h> using namespace std; long long n, W, B, X, dp[1001][10001], c[1001], cum[1001], cost[1001]; int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); cin >> n >> W >> B >> X; for (int i = 0; i < n; i++) { cin >> c[i]; if (i == 0) cum[i] = c[i]; el... |
#include <bits/stdc++.h> using namespace std; long long int temp; vector<long long int> v; long long int n; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int t = 1; cin >> t; while (t--) { long long int n, strt, cnst, lwr = 0, upr = 0, t, l, r, pt = 0, f... |
#include <bits/stdc++.h> using namespace std; #pragma optimize( O3 ) const int N = 200005; int arr[N]; int fst[1000000], lst[1000000]; int minVal(int x, int y) { return (x < y) ? x : y; } int getMid(int s, int e) { return s + (e - s) / 2; } int RMQUtil(int *st, int ss, int se, int qs, int qe, int index)... |
#include <bits/stdc++.h> using namespace std; template <class T> bool umin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } template <class T> bool umax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } int arr[100009], val[100009], n, k; ... |
#include <bits/stdc++.h> using namespace std; bool check[41][41]; int above[41][41]; int dp[41][41][41][41]; int main() { int n, m, q, s1, s2, s3, s4; char s[42]; scanf( %d %d %d , &n, &m, &q); for (int i = 1; i <= n; i++) { scanf( %s , s + 1); for (int j = 1; j <= m; j++) ... |
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { long long n; cin >> n; set<int> used; for (int i = 2; i * i <= n; i++) { if (n % i == 0 && !used.count(i)) { used.insert(i); n /= i; break; } ... |
#include <bits/stdc++.h> using namespace std; int main() { int q; cin >> q; for (int i = 0; i < q; ++i) { int n; cin >> n; vector<int> a(n); for (int j = 0; j < n; ++j) { cin >> a[j]; --a[j]; } int pos = 0; while (pos < n) { int nxt = min... |
#include <bits/stdc++.h> using namespace std; int ar[1000000], br[1000000]; int main() { int t; cin >> t; while (t--) { int a, b, c, d; cin >> a >> b >> c; int ans = 0; if (a > 0) { ans++; a--; } if (b > 0) { ans++; b--; } ... |
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> PII; const int maxn=111111,mod=998244353; const double PI=3.141592653589793; #define MP make_pair #define PB push_back #define lson o<<1,l,mid #define rson o<<1|1,mid+1,r #define FOR(i,a,b) for(int i=(a);i<=(b);... |
#ifndef _MY #pragma GCC optimize( Ofast ) #pragma GCC optimize( unroll-loops ) #pragma GCC target( sse,sse2,sse3,ssse3,abm,mmx,tune=native ) #endif #include bits/stdc++.h #define int ll #define all(x) (x).begin(), (x).end() using namespace std; typedef long long ll; typedef long double ld; const... |
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; const int inf = 1e9 + 10; const long long INF = 1e18; const long double EPS = 1e-10; const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1}; const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1}; template <class T> bool chmax(T &a, const T... |
#include <bits/stdc++.h> using namespace std; int main() { int test; cin >> test; for (int t = 0; t < test; t++) { int n; cin >> n; int k = 2; while (n % (int)(pow(2, k) - 1) != 0) { k++; } int ans = n / (pow(2, k) - 1); cout << ans << endl; } re... |
#include <bits/stdc++.h> using namespace std; const int Max = 1e5 + 5; struct node { int x, y; } Node1[Max], Node2[Max]; int hash1[Max], hash2[Max]; bool cmp(const node a, const node b) { if (a.y == b.y) return a.x < b.x; return a.y < b.y; } int main() { int n, m; while (scanf( %d%d ... |
#include <bits/stdc++.h> using namespace std; signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, m; cin >> n >> m; string a, b; cin >> a >> b; if (a.size() - 1 > b.size()) { cout << NO n ; return 0; } if (a == b) { cout << YE... |
#include <bits/stdc++.h> using namespace std; const int MAXN = 100010; char str[MAXN]; int k1, k0, k2; int main() { scanf( %s , str); int n = strlen(str); k1 = k2 = k0 = 0; for (int i = 0; i < n; i++) { if (str[i] == 0 ) k0++; if (str[i] == 1 ) k1++; if (str[i] == ? ) k2++... |
#include <bits/stdc++.h> using namespace std; unsigned int dp[100010][400]; vector<int> nima[100010]; int a[100010], b[100010]; int n, m, s, e; int main() { while (cin >> n >> m >> s >> e) { memset(dp, -1, sizeof(dp)); for (int i = 0; i < n; ++i) { scanf( %d , &a[i]); } f... |
#include <bits/stdc++.h> using namespace std; struct compleks { double x, y; }; compleks operator*(compleks a, compleks b) { compleks c; c.x = a.x * b.x - a.y * b.y; c.y = a.x * b.y + a.y * b.x; return c; } compleks operator-(compleks a, compleks b) { compleks c; c.x = a.x - b.x,... |
#include <bits/stdc++.h> using namespace std; int n, m, deg[8012], ans1, ans2, ans3, cn = 0, mx[8012], X[8012]; bool w[8012][8012], vis[8012]; queue<int> q; long long ans = 0; int main() { scanf( %d , &n); m = n >> 2; int i, j, k, v, x, y, o; char ch; for (i = 0, getchar(); i < n; ++i, g... |
#include <bits/stdc++.h> using namespace std; long long i, n, m, k, x, z, c, a[500007], b[500007], ans, bad, total; int main() { cin >> n; for (i = 1; i <= n; i++) cin >> a[i]; set<long long> st; for (i = 1; i <= n; i++) { st.insert(a[i]); if (st.find(i) != st.end()) st.erase(i); ... |
#include <bits/stdc++.h> using namespace std; vector<long long int> primes; void Sieve(long long int n) { vector<bool> prime(n + 1, true); for (long long int p = 2; p * p <= n; p++) { if (prime[p] == true) { for (long long int i = p * p; i <= n; i += p) prime[i] = false; } } fo... |
#include <bits/stdc++.h> using namespace std; int main() { int d; cin >> d; for (int i = 0; i < d; ++i) { long long n; cin >> n; if (n * (n - 4) >= 0) { cout << Y << fixed << setprecision(9) << (n + sqrt(n * n - 4 * n)) / 2 << << n - (n + sqrt(n * n - 4 * n)... |
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 10; char s[N], t[N]; int vis[N], vs[N]; int main() { cin >> s + 1 >> t + 1; int j = 1; int n = strlen(s + 1); int m = strlen(t + 1); for (int i = 1; i <= n && j <= m; ++i) { if (s[i] == t[j]) { vis[j] = i; ... |
#include <bits/stdc++.h> using namespace std; long long modexpo(long long x, long long p) { long long res = 1; x = x % 1000000007; while (p) { if (p % 2) res = res * x; p >>= 1; x = x * x % 1000000007; res %= 1000000007; } return res; } struct compare { bool opera... |
#include <bits/stdc++.h> using namespace std; const int MAXN = 1 << 18; const long long INF = 0x3f3f3f3f; int n, k; bool fav[MAXN]; long long dp[MAXN][18][2][2]; inline void get_max(long long &, long long); int main() { scanf( %d%d , &n, &k); for (register int i = 1; i <= k; ++i) { int tmp... |
#include <bits/stdc++.h> using namespace std; const int MAXN = 3e5 + 7; const int inf = 1e9; char s[60][60]; char s1[60]; int l; int n; int num[60]; int check(char *s) { for (int i = 0; i < l; ++i) { int j; for (j = 0; j < l; ++j) { if (s1[j] != s[(j + i) % l]) break; } ... |
#include <bits/stdc++.h> using namespace std; char s[2][100]; int fun(char a, char b) { if (a == 8 ) { if (b == [ ) return 1; else if (b == ( ) return -1; else return 0; } if (a == [ ) { if (b == 8 ) return -1; else if (b == ( ) ... |
#include <bits/stdc++.h> using namespace std; int main() { char c1, c2; cin >> c1 >> c2; int n; cin >> n; if (n % 2 == 0) { cout << undefined << endl; } else { int n1, n2; switch (c1) { case ^ : n1 = 1; break; case > : n1 = ... |
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; const int MOD = 1000000007; long long power(long long a, long long n, long long m) { if (n == 0) return 1; long long p = power(a, n / 2, m); p = (p * p) % m; if (n % 2) p = (p * a) % m; return p; } int fact[N]; int if... |
#include <bits/stdc++.h> using namespace std; long long power(long long x, long long y) { long long res = 1; while (y > 0) { if (y & 1) res = (res * x); y = y >> 1; x = (x * x); } return res; } long long summ(long long a) { long long ans = 0; while (a) { ans += a ... |
#include <bits/stdc++.h> using namespace std; int n; long long k, x; long long a[200010]; int main() { int n; while (cin >> n >> k >> x) { int negative = 0; for (int i = 0; i < n; i++) { cin >> a[i]; if (a[i] < 0) ++negative; } if (negative % 2 == 0) { i... |
#include <bits/stdc++.h> using namespace std; template <class T> inline T sqr(T x) { return x * x; } const double PI = acos(-1.0); using namespace std; double dp[1005][1005]; int main(void) { int n, m; scanf( %d %d , &n, &m); if (n == 1) { puts( 1.0000000 ); return 0; } ... |
#include <bits/stdc++.h> int main() { int n; scanf( %d , &n); std::vector<std::pair<int, int> > a(n + 1); for (int p = 0; p < n; p++) { int x; scanf( %d , &x); a[p] = std::make_pair(x, p + 1); } sort(++a.begin(), a.end(), std::greater<std::pair<int, int> >()); int ind(0);... |
#include <bits/stdc++.h> using namespace std; const long long N = 200005; int main() { long long n, z, x, y; cin >> n; z = (n * (n - 1) * (n - 2) * (n - 3) * (n - 4)) / 120; x = (z * (n - 5)) / 6; y = (x * (n - 6)) / 7; cout << z + x + y << n ; return 0; } |
#include <bits/stdc++.h> using namespace std; using ll = int64_t; int main(int argc, char* argv[]) { std::ios::sync_with_stdio(false); cin.tie(nullptr); cout.precision(10); int n; cin >> n; auto g = vector<vector<ll>>(n, vector<ll>(n, 2000000000)); for (int i = 0; i < (n - 1); ++i) ... |
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 99; int n, m, pre[maxn], nxt[maxn], vst[maxn], flag[maxn]; vector<int> G[maxn]; void del(int i) { nxt[pre[i]] = nxt[i]; if (~nxt[i]) pre[nxt[i]] = pre[i]; } void bfs(int id) { queue<int> que; que.push(id); while (!que... |
#include <bits/stdc++.h> using namespace std; int t[200001]; int main() { memset(t, 0x3f, sizeof(t)); int n, k; string str; cin >> n >> k >> str; for (int x = 0; x < n; x++) if (str[x] == str[(x + 1) % n] || str[x] == str[(x - 1 + n) % n]) t[x] = 0; for (int x = 0; x < 2 * n; x++) ... |
#include <bits/stdc++.h> using namespace std; int arr[1000000]; int main() { int n; while (scanf( %d , &n) != -1) { if (n == 1) { printf( 1 n ); continue; } if ((n & 1) && (n - 1) % 4) { printf( -1 n ); continue; } if (!(n & 1) && n % 4) { ... |
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; const int INF = 1e9; const long long mod = 1e9 + 7; bool dp[105][55][2][2][205]; string s; int n, sz, realans; int offset(int x) { return x + 100; } bool f(int idx, int sisa, bool flip, bool arah, int ans) { if (idx == sz + 1) { ... |
#include <bits/stdc++.h> using namespace std; int n, a[500005], tot, s[500005], c[500005], tmp[1500005], num; priority_queue<int> q; bool cmp(int x, int y) { return x > y; } int main() { long long ans = 0; scanf( %d , &n); for (int i = 1; i <= n; i++) scanf( %d , &a[i]), ans += a[i]; sort(a + ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.