func_code_string stringlengths 59 71.4k |
|---|
#include <bits/stdc++.h> using namespace std; int n, m, q; vector<int> w[400001]; int check[400001]; int ans; void input() { scanf( %d %d %d , &n, &m, &q); int x, y; for (int i = (0); i < (q); i++) { scanf( %d %d , &y, &x); x--; y--; x += n; w[x].push_back(y); ... |
#include <bits/stdc++.h> using namespace std; int main() { int x, y, a, b, c, num = 0; scanf( %d%d , &x, &y); a = b = c = y; while (a < x || b < x || c < x) { if (a <= b && a <= c) a = b + c - 1; else if (b <= a && b <= c) b = a + c - 1; else c = a + b - 1; ... |
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; long long f[107][10007], C[107][10007]; long long ksm(long long a, long long b) { long long res = 1; for (; b; b >>= 1) { if (b & 1) res = res * a % MOD; a = a * a % MOD; } return res; } int main() { ... |
#include <bits/stdc++.h> using namespace std; string str; set<string> vis; int main() { int n; scanf( %d , &n); vis.clear(); for (int i = 0; i < n; ++i) { cin >> str; if (vis.find(str) != vis.end()) cout << YES << endl; else cout << NO << endl; vis.ins... |
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; string s[n]; unordered_map<string, int> mp; int count = 0; for (int i = 0; i < n; i++) { cin >> s[i]; mp[s[i]] += 1; } for (int i = 0... |
#include <bits/stdc++.h> using namespace std; template <typename T> void prn(T first) { cout << first << n ; } template <typename T, typename... Args> void prn(T first, Args... args) { cout << first << ; prn(args...); } vector<long long> adj[200004]; vector<long long> parent(200004, 0... |
#include <bits/stdc++.h> using namespace std; int main() { long long int t, i, j, n, a[100000], x, y, index, num, l, r, count, count1, temp; vector<int> vect; cin >> n >> t; for (i = 0; i < n; i++) { cin >> a[i]; } while (t > 0) { count = 0; count1 = 0; cin >>... |
#include <bits/stdc++.h> using namespace std; const int max_n = 300000; int a[max_n], b[max_n], p[max_n]; int main() { int n; scanf( %d , &n); for (int i = 0; i < n; i++) { scanf( %d , &a[i]); a[i]--; } for (int i = 0; i < n; i++) { int t; scanf( %d , &t); t--; ... |
#include <bits/stdc++.h> using namespace std; string rs(string s) { for (int i = 0; i < s.size(); i++) { if (s[i] == ) s.erase(i, 1); } return s; } int main() { char s[1100000]; vector<string> v; while (gets(s)) { v.push_back(s); } vector<bool> mag(v.size(), false)... |
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; const long long N = 50; const long long INF = 1e10; vector<string> mat(N); int n, r1, c1, r2, c2; vector<vector<bool>> visited(N, vector<bool>(N)); void dfs(int i, int j, vector<pair<int, int>> &s) { visited[i][j] = true; ... |
#include <bits/stdc++.h> using namespace std; const int INF = 1000000000; int main() { int hy, ay, dy; int hm, am, dm; int ph, pa, pd; scanf( %d%d%d%d%d%d%d%d%d , &hy, &ay, &dy, &hm, &am, &dm, &ph, &pa, &pd); int ans = INF, least = 0; int cur_ay = ay; if (cur_ay < dm + 1) { least... |
#include <bits/stdc++.h> using namespace std; int dx[] = {0, 0, 1, -1}; int dy[] = {1, -1, 0, 0}; bool valid(int x, int y) { return x >= 0 && y >= 0 && x < 3 && y < 3 ? 1 : 0; } int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t; cin >> t; while... |
#include <bits/stdc++.h> using namespace std; int main() { long long t; cin >> t; long long ans = t * (t + 1) / 2; if (ans % 2) cout << 1; else cout << 0; } |
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; int ans = 0; int n = s.size(); for (int i = 0; i < n; i++) ans += (1 << i); for (int i = 0; i < n; i++) { if (s[i] == 7 ) ans += (1 << (n - i - 1)); } cout << ans; } |
#include <bits/stdc++.h> using namespace std; long long int max(long long int a, long long int b) { if (a > b) return a; else return b; } long long int min(long long int a, long long int b) { if (a < b) return a; else return b; } const int dx[4] = {-1, 1, 0, 0}; con... |
/*There is no salvation without suffering*/ #pragma GCC optimize( Ofast ) #pragma GCC target( avx,avx2,fma ) #include<iostream> #include<string> #include<algorithm> #include<numeric> #include<cmath> #include<vector> #include<iomanip> #include<map> #include<set> #include<stack> #include<queue> ... |
#include <bits/stdc++.h> using namespace std; int Mod; const int Nmax = 1005, Kmax = 105; int Dp[Nmax][Kmax]; int main() { ios::sync_with_stdio(false); int N, K; cin >> N >> K >> Mod; for (int i = 1; i < 10; ++i) Dp[1][i % K]++; if (N > 1) Dp[1][K] = 1; for (int i = 2, pw = 10 % K; i <... |
#include<bits/stdc++.h> using namespace std; #pragma GCC target ( avx2 ) #pragma GCC optimize ( Ofast ) #pragma GCC optimize ( unroll-loops ) #pragma GCC target( avx,avx2,fma ) #pragma GCC optimize( O3 ) #define F first #define S second #define sz size() #define pb push_back #define int long long ... |
#include <bits/stdc++.h> #pragma GCC optimize( O3 ) #pragma GCC optimize( Ofast ) using namespace std; vector<vector<int> > vec; set<vector<int> > myset, vis; map<vector<int>, int> p; int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, m, t, a, b; cin >> n >>... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long n, c; cin >> n >> c; vector<long long> a(n); multiset<long long> p; for (long long i = 0; i < n; i++) { cin >> a[i]; } for (long long i ... |
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const double eps = 1e-9; int n, m, l, r; int main() { int T, cas = 1, x = INF; scanf( %d%d , &n, &m); for (int i = 1; i <= m; ++i) { scanf( %d%d , &l, &r); x = min(x, r - l + 1); } printf( %d n , x); ... |
#include <bits/stdc++.h> using namespace std; int main() { int T; scanf( %d , &T); while (T--) { int a[255]; int s = 0; for (int i = 0; i < 250; i++) { scanf( %d , &a[i]); s += a[i]; } double ave = s / 250.0; int cnt = 0; for (int i = 0; i < 250;... |
#include <bits/stdc++.h> using namespace std; template <class T> ostream& prnt(ostream& out, T v) { out << v.size() << n ; for (auto e : v) out << e << ; return out; } template <class T> ostream& operator<<(ostream& out, vector<T> v) { return prnt(out, v); } template <class T> ost... |
#include <bits/stdc++.h> using namespace std; int n, f = -1; int main() { cin >> n; cout << (n * n + 1) / 2; for (int i = 0; i < n; i++) { f = f * (-1); cout << endl; for (int j = 0; j < n; j += 2) { if (f == 1) { if (j != n - 1) cout << C. ; ... |
#include <bits/stdc++.h> using namespace std; int L01P08(vector<int>& arr, int n) { bool check = true; if (arr[0] - 15 > 0) { return 15; } else { for (int i = 0; i < n - 1; i++) { for (int j = 1; j < n; j++) { if (arr[i] + 15 < arr[i + 1]) { return arr[i] + 15; ... |
#include <bits/stdc++.h> using namespace std; vector<long long> adj[200005]; vector<long long> vis(200005); signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long i, j, k = 0, n, t = 1, m, l = 0; for (i = 0; i < 200005; i++) vis[i] = 0; while (t--) { ... |
#include <bits/stdc++.h> using namespace std; const long long int MOD = 1e9 + 7; long long int ne; long long int go(long long int idx, long long int pre) { if (idx == ne) return 0; long long int ans = 1e15; if (idx == 0) ans = min(ans, 1 + go(idx + 1, 0)); else { if (idx == 3) { ... |
#include <bits/stdc++.h> using namespace std; static const double EPS = 1e-8; int main() { istream &fin = cin; ostream &fout = cout; FILE *fpin = stdin; FILE *fpout = stdout; string s; fin >> s; bool p = true; string res; for (int i = s.size() - 1; i >= 0; i--) { if (p &&... |
#include <bits/stdc++.h> using namespace std; template <class T> inline T gcd(T a, T b) { if (a < 0) return gcd(-a, b); if (b < 0) return gcd(a, -b); return (b == 0) ? a : gcd(b, a % b); } template <class T> inline T lcm(T a, T b) { if (a < 0) return lcm(-a, b); if (b < 0) return lcm(a, ... |
#include <bits/stdc++.h> using namespace std; int main() { int n, h, m; int cash[2360] = {0}; scanf( %d , &n); for (int i = 0; i < n; i++) { scanf( %d %d , &h, &m); h *= 100; h += m; cash[h]++; } sort(cash, cash + 2360, greater<int>()); printf( %d n , cash[0]); ... |
#include <bits/stdc++.h> using namespace std; long long pre[26][100005], suff[26][100005]; int main() { string s; cin >> s; int n = s.length(); if (n == 1) { cout << 1 << endl; return 0; } if (n == 2) { if (s[0] == s[1]) { cout << 2 << endl; return 0; ... |
#include <iostream> using namespace std; int t; int n, k; int main() { for (cin >> t; t--; ) { cin >> n >> k; for (n -= k - 3; k != 3; k--) { cout << 1 << ; } if (n == 3) cout << 1 << << 1 << << 1 << endl; else if (n % 4 == 0) cout << n / 2 << << n /... |
#include <bits/stdc++.h> using namespace std; const int64_t N = 5e6 + 10; int64_t n, m; int64_t it[N]; bool hamband[N]; int64_t adj[N]; int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> m; if (m == (n - 1) * n >> 1) { cout << 0; return 0; ... |
#include <bits/stdc++.h> using namespace std; using ll = long long; const int N = 1e5 + 5; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int T; cin >> T; while (T--) { string x, y; cin >> x >> y; int lx = x.size(), ly = y.size(); int py = 1; while ... |
#include <bits/stdc++.h> using namespace std; const long long INF = 1e18; int main() { int n; long long k; cin >> n >> k; vector<long long> a(n + 1); for (int i = 0; i <= n; ++i) cin >> a[i]; vector<long long> suff(n + 1); suff[n] = a[n]; for (int i = n - 1; i >= 0; --i) { su... |
#include <bits/stdc++.h> using namespace std; long long a, b, c, d, e, t1, t2, t3; long long la, lb, lc; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long n, m, s; cin >> n >> m >> s; a = 0; b = 0; long long i = 0; c = 1; if (s <= n) { while (i < n... |
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; long long n, k, m, t, x, b[N], a[N]; int i, j; map<int, long long> C; int main() { cin >> n; for (i = 2; i <= n; i++) { cin >> a[i]; a[i] += a[i - 1]; m = min(m, a[i]); } x = 1 - m; for (i = 1; i <= n;... |
#include <bits/stdc++.h> using namespace std; template <typename T> pair<T, vector<int>> hungarian(const vector<vector<T>>& A) { int n = (int)A.size(), m = (int)A[0].size(); T inf = numeric_limits<T>::max() / 2; vector<int> way(m + 1), p(m + 1), used(m + 1); vector<T> u(n + 1), v(m + 1), minv(m + ... |
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; int cnt, n, vis[305], a[305], C[305][305], sum[305]; map<int, int> m; vector<int> v[305]; int num[305], top; long long jie[305], ans, f[305][305]; void pre() { jie[0] = 1; for (int i = 1; i <= 300; i++) jie[i] = jie[i -... |
#include <bits/stdc++.h> using namespace std; long long n, l, k, v1, v2; bool chk(long double X) { long double curr = 0; long double nn = l; long double f_time; long double x = X; for (long long i = 1; i < (n + k - 1) / k; i++) { long double diss = nn - curr; long double y = ((x * ... |
#include <bits/stdc++.h> using namespace std; char ans[10][10]; long long dp[10][513][513]; pair<pair<long long, long long>, long long> recur[10][513][513]; long long insert[10][513][513]; long long curr, nexty, n, m; long long setBit(long long num, long long i) { return num | (1 << i); } long long unse... |
#include <bits/stdc++.h> using namespace std; int n; int main() { scanf( %d , &n); for (int i = 0; i < 2 * n + 1; i++) { for (int j = 0; j < 2 * n + 1; j++) { if (i < n + 1) { if (j < n - i) { printf( ); } else if (j < n + i) { if (j <= n) { ... |
#include <bits/stdc++.h> using namespace std; template <class T, class U> inline void chmin(T &t, U f) { if (t > f) t = f; } template <class T, class U> inline void chmax(T &t, U f) { if (t < f) t = f; } long long N; char S[11111]; long long ex[27 * 26 * 26]; long long dp[11111][2]; long... |
#include <bits/stdc++.h> using namespace std; map<int, int> m; int main() { map<int, int>::iterator ptr; int n, i, x, a[3]; cin >> n; for (i = 0; i < n; i++) { cin >> x; m[x]++; } if (m.size() > 3) { cout << NO ; return 0; } if (m.size() <= 2) { cout ... |
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1.0); int n; int mt[256][256]; int xy[256], yx[256]; int lx[256], ly[256], slk[256], slkx[256], prv[256]; char S[256], T[256]; void updtree(int x) { for (int y = 0; y < (int)(n); y++) if (lx[x] + ly[y] - mt[x][y] < slk[y]) {... |
#include <bits/stdc++.h> using namespace std; const int MAX = 300; int n, m; struct cell { int mask = 0; bool operator[](int i) { return mask & (1 << i); } }; cell arr[MAX][MAX]; vector<pair<int, int> > adj[MAX][MAX]; int inDegree[MAX][MAX], _Time, visTime[MAX][MAX], lowTime[MAX][MAX], com... |
#include <bits/stdc++.h> using namespace std; template <typename T> T abs(T a) { return a < 0 ? -a : a; } template <typename T> T sqr(T a) { return a * a; } const int INF = (int)1e9; const long double EPS = 1e-9; const long double PI = 3.1415926535897932384626433832795; const int N = 4; ... |
#include <bits/stdc++.h> using namespace std; long long bigmod(long long b, long long p) { if (p == 0) return 1; long long my = bigmod(b, p / 2); my *= my; my %= 1000000009; if (p & 1) my *= b, my %= 1000000009; return my; } int setb(int n, int pos) { return n = n | (1 << pos); } int r... |
#include <bits/stdc++.h> using namespace std; int main() { int n, m, q = 0; cin >> n >> m; int k = n * m; char a[k]; for (int j = 0; j < k; j++) { cin >> a[k]; if (a[k] == M || a[k] == Y || a[k] == C ) { q = 1; } } if (q == 1) { cout << #Color << en... |
#include <bits/stdc++.h> using namespace std; const int N = 500000; int n, m; vector<int> nei[N + 1]; bool vis[N + 1]; int fa[N + 1], dep[N + 1]; void dfs(int x = 1) { vis[x] = true; for (int i = 0; i < nei[x].size(); i++) { int y = nei[x][i]; if (vis[y]) continue; fa[y] = x; ... |
#include <bits/stdc++.h> using namespace std; int in[100005]; int in2[100005]; int remlocate[100005]; int main() { int n; cin >> n; for (int i = 0; i < n; ++i) { cin >> in[i]; } for (int i = 0; i < n; ++i) { cin >> in2[i]; remlocate[in2[i]] = i; } int go1 = n - 1;... |
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; const int MAXN = 1000005; int dp[MAXN]; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; int x; int maxn = 0; for (int i = 0; i < n; i++) { cin >> x; dp[x]++; ... |
#include <bits/stdc++.h> #pragma GCC target( avx2 ) #pragma GCC optimization( O3 ) #pragma GCC optimization( unroll-loops ) using namespace std; using ll = long long; using ld = long double; const ll MOD = 1000000007; const ll root = 62; ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } ll binpow... |
#include <bits/stdc++.h> using namespace std; long long a[100005]; long long b[100005]; long long x; long long n, m; long long c[100005]; long long d[100005]; void solve() { cin >> n >> m; for (long long i = 0; i < n; i++) { cin >> a[i]; if (i) a[i] += a[i - 1]; c[i + 1] = 1e9;... |
#include <bits/stdc++.h> const int N = 1000000 + 9, MOD = 1000000000 + 7; int f[N], n, a, b; int main() { scanf( %d , &n); for (int i = 1, x; i <= n; ++i) { scanf( %d , &x); if (x == 1) ++a; else ++b; } f[1] = 1; f[0] = 1; for (int i = 2; i <= a; ++i) ... |
#include <bits/stdc++.h> using namespace std; const int N = 2e5; vector<int> g[N], used, g1[N]; int gl[N]; bool ok = 1; void dfs(int v, int glb) { used[v] = 1; gl[v] = glb; for (int to : g[v]) if (!used[to]) dfs(to, glb + 1); } void dfs1(int v, int root) { used[v] = 1; for (int... |
#include <bits/stdc++.h> using namespace std; long long n, m, T, k, q; const long long big = 1000000007; const long long big2 = 998244353; long long M[4][4] = {0}; vector<pair<int, int> > ANS; bool inbounds(long long i, long long j) { return i >= 0 && j >= 0 && i < 4 && j < 4; } void clearm() { ... |
#include <bits/stdc++.h> using namespace std; int n, x, y; bool f[1000010]; vector<int> v, b[1000010]; int ans = 0, res = 0; int main(int argc, char **argv) { scanf( %d , &n); if (n == 1) { puts( 1 ); return 0; } for (int i = 0; i < n; ++i) { scanf( %d , &x); b[x].pus... |
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; const int SIZE = 1e6 + 5; const long long INF = 1LL << 55; const double eps = 1e-10; pair<long long, long long> d[1000009]; long long f[1000009]; deque<pair<long long, long long> > dq; long long dsum = 0; int main() { l... |
#include <bits/stdc++.h> using namespace std; bool judge(int x) { for (int i = 2; i * i <= x; i++) { if (x % i == 0) return false; } return true; } int main() { int n; scanf( %d , &n); if (judge(n)) { printf( 1 n ); return 0; } if (n % 2) { if (judge(n - 2... |
#include <bits/stdc++.h> using namespace std; int p[424242]; int main() { long long n; cin >> n; int ans = 0; if (n % 3 == 0) { n /= 3; int kp = 0; for (int d = 1; d <= 50000; d++) if ((4 * n) % d == 0) p[kp++] = d; for (int a = 1; 8LL * a * a * a <= n; a++) ... |
#include <bits/stdc++.h> using namespace std; const int N = 1005; const int M = 11; const int MOD = 1e9 + 7; int n, m; int dp[M][N][N]; int solve(int idx, int a, int b) { if (idx >= m) return 1; int& r = dp[idx][a][b]; if (r != -1) return r; r = solve(idx + 1, a, b); if (a < b) { ... |
#include <bits/stdc++.h> using namespace std; const long double PI = 3.14159265358979323846264338; const long long INF = 1000000000000000000; const long long INF1 = 1000000000; const long long MOD = 1000000007; long long mpow(long long a, long long b) { a %= MOD; if (!b) return 1; long long temp... |
#include <bits/stdc++.h> using namespace std; const int N = 5050; const int inf = 0x3f3f3f3f; int to[N * 2], nxt[N * 2], pre[N * 2], cnt, n, tot[N], dp[N][N][2]; void makeedge(int x, int y) { to[cnt] = x; nxt[cnt] = pre[y]; pre[y] = cnt++; to[cnt] = y; nxt[cnt] = pre[x]; pre[x] = cnt++... |
#include <bits/stdc++.h> using namespace std; int main() { int t, s, q, nr = 0; scanf( %d%d%d , &t, &s, &q); while (s < t) { nr++; s += s * (q - 1); } printf( %d , nr); return 0; } |
#include <bits/stdc++.h> using namespace std; long long int arr[105]; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long int n, x, y, t, l, m, k = 0, r = 0, a, b, c, d, p = 0, q = 0, s, i, j, ans = 0, ans1 = 0; string s1; ... |
#include <bits/stdc++.h> using namespace std; int sci[200005], bn[200005]; int main() { int n; while (scanf( %d , &n) != EOF) { int m, ple = 0, sat = 0, fi = 1, cn; map<int, int> mp; for (int i = 0; i < n; i++) { scanf( %d , &sci[i]); mp[sci[i]]++; } scanf( %d... |
#include <bits/stdc++.h> using namespace std; const int M = (int)1e5 + 5; int n; int a[M]; int q, ans[M]; vector<pair<int, int> > ps[M]; int pas[M], las[M], llas[M], mfr[M]; struct SEGMENT1 { int val[M * 4]; void update(int L, int R, int p, int l, int r, int v) { if (L == l && R == r) { ... |
#include <bits/stdc++.h> using namespace std; const int N = 5e4 + 10, K = 256, B = 16; int a[N], parent[N], depth[N], up[N], ans[N][K]; vector<int> g[N]; bitset<(1 << (B + 1)) + 10> trie; void make_tries(int i, int par); void trie_insert(int val); void trie_clear(int val); int trie_max(int val); int... |
#include <bits/stdc++.h> using namespace std; long long int arr[100001], done[100001], cnt0[100001], cnte[100001], cnto[100001]; long long int dp[105][105][2]; int main() { ios::sync_with_stdio(false); ; cin.tie(0); ; long long int i, j, n, k, l, x, y, evenLeft = 0, oddLeft = 0, z; ... |
#include <bits/stdc++.h> using namespace std; int main(void) { int t, n; cin >> t; string s; for (int k = 0; k < t; k++) { cin >> n; cin >> s; if (s.size() == 2) { if (s[0] < s[1]) { cout << YES << n ; cout << 2 << n ; cout... |
#include <bits/stdc++.h> using namespace std; long long int powmod(long long int a, int b, int n) { long long int rm = 1; while (b) { if (b % 2) { rm = (rm * a) % n; } a = (a * a) % n; b /= 2; } return rm; } int main() { int n; long long int a[110]; ci... |
#include <bits/stdc++.h> using namespace std; string s, t; int arr1[2222], arr2[2222]; char ans[999999]; long long int i, j, lo, hi, mid, cnt, sum, nd; queue<int> q; int main() { cin >> s >> t; for (i = 0; i < t.size(); i++) { arr2[(int)(t[i] - a )]++; } cnt = 0; for (i = 0; i <... |
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b); long long mpower(long long x, long long y, long long c); int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); map<long long, long long> M; vector<long long> aa; set<long long> ... |
#include <bits/stdc++.h> using namespace std; double shortestDisSq(double x1, double y1, double x2, double y2, double x, double y) { double magSq = pow(abs(x2 - x1), 2) + pow(abs(y2 - y1), 2); double proj = ((x - x1) * (x2 - x1) + (y - y1) * (y2 - y1)) / magSq; if (proj > 1) proj ... |
#include <bits/stdc++.h> #pragma comment(linker, /STACK:16777216 ) using namespace std; const long double pi = acos(-1.0); const long double eps = 1e-6; const int INF = 1E9; const int MAXN = 5111; struct node { pair<int, int> key; int pr, cnt; node *l, *r; node(pair<int, int> _key) { ... |
#include <bits/stdc++.h> const int MAXN = 1100000; char s[MAXN]; int n; bool check(int o) { int p = 0; int mx = 0; bool uni = true; for (int i = 0; i < n; i++) { if (s[i] == L ) p--; else { if (p < o - 1) p++; } if (p < mx) { mx = p; uni =... |
#include <bits/stdc++.h> using namespace std; bool primecheck(long long int a) { bool check = true; for (long long int i = 2; i <= sqrt(a); i++) { if (a % i == 0) { check = false; break; } } return (check); } vector<long long int> printDivisors(long long int n) { ... |
#include <bits/stdc++.h> using namespace std; const int maxn = 100005; const int INF = 0x3f3f3f3f; const double pi = acos(-1.0); const double eps = 1e-9; template <class T> inline void read(T &x) { int c; for (c = getchar(); c < 32 && ~c; c = getchar()) ; for (x = 0; c > 32; x = x * 10 +... |
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; const int MX = 2e5 + 5; const long long INF = 1e18; const long double PI = 4 * atan((long double)1); template <class T> bool ckmin(T& a, const T& b) { return a > b ? a = b, 1 : 0; } template <class T> bool ckmax(T& a, const T... |
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007LL; long long dp[64]; long long solve(long long k) { if (dp[k] != -1) return dp[k]; if (k == 0) return 1LL; return ((16LL * solve(k - 1) % mod) * (solve(k - 1) % mod) % mod + mod) % mod; } int main() { ios::sync_wi... |
#include <bits/stdc++.h> using namespace std; int n, A[100], B[100], t, r, x; string s = ; int main() { cin >> n; for (int i = 0; i <= n; i++) { r = 0; for (int j = 0; j <= n; j++) { if ((t + r) == n) { x = 1; break; } r = r + 7; } if... |
#include <bits/stdc++.h> using namespace std; const double PI = 3.14159265; void fastInOut(); const int N = 5003; const long long OO = (long long)1e18; int n, m, k; long long cum[N], memo[N][N]; long long go(int i, int c) { if (i == n + 1) return c == k ? 0 : -OO; long long &ret = memo[i][c]; ... |
#include <bits/stdc++.h> using namespace std; long long int arr[100005]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; long long int sum = 0; for (int i = 0; i < n; ++i) { cin >> arr[i]; sum = sum + arr[i]; } if (sum & 1) { cout <<... |
#include <bits/stdc++.h> using namespace std; int powmod(int a, int p, int m) { int64_t ans = 1, cp = a; for (int i = 0; (1ll << i) <= p; ++i, cp = cp * cp % m) if ((1ll << i) & p) ans = ans * cp % m; return ans; } int divmod(int64_t a, int b, int m) { return a * powmod(b, m - 2, m) % m; } c... |
#include <bits/stdc++.h> using namespace std; int main() { int q; cin >> q; while (q--) { int n; cin >> n; vector<int> p(n); int id = -1; for (int i = 0; i < n; ++i) { cin >> p[i]; if (p[i] == 1) id = i; } bool f1 = 0, f2 = 0; int val = 0; ... |
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 5; int f[11][11][4][maxn]; int n; char s[maxn]; char c[maxn]; int lowbit(int x) { return x & (-x); } int ch(char s) { if (s == A ) return 1; else if (s == T ) return 2; else if (s == G ) return 3; e... |
#include <bits/stdc++.h> using namespace std; long long dp[55][55]; double comb[55]; int a[55]; int main(int argc, char **argv) { int n, p; int tot = 0; double res = 0; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; tot += a[i]; } cin >> p; if (tot <= p) { ... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; int x1, y1, x2, y2; int sum = 0; for (int i = 0; i < n; ++i) { cin >> x1 >> y1 >> x2 >> y2; sum += (abs(x2 - x1) + 1) * (abs(y2 - y1) + 1); ... |
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; bool good[n]; for (int i = 0; i < n; i++) good[i] = 1; for (int i = 0; i < n; i++) { int isGood = 1; for (int j = 0; j < n; j++) { int dum; cin >> dum; if (dum == 1 || dum == 3) ... |
#include <bits/stdc++.h> using namespace std; int main() { int n, s, i, v = 0, a[1010]; cin >> n >> s; for (i = 1; i <= n; i++) { cin >> a[i]; v = v + a[i]; } for (i = 1; i <= n; i++) if ((v - a[i]) <= s) { cout << YES ; return 0; } cout << NO ; ... |
#include <bits/stdc++.h> using namespace std; int a[100005], b[100005]; int main() { int n, m, i; long long sum = 0; scanf( %d%d , &n, &m); for (i = 1; i <= m; i++) { scanf( %d , &a[i]); sum += a[i]; if (a[i] + i > n + 1) { printf( -1 ); return 0; } } ... |
#include <bits/stdc++.h> using namespace std; const int N = 200005; int n, m, in[N], out[N], id[N], dep[N]; vector<int> v[N]; int idx; void dfs(int pos, int dd) { in[pos] = ++idx; id[idx] = pos; dep[idx] = dd; for (auto &i : v[pos]) dfs(i, dd + 1); out[pos] = ++idx; id[idx] = pos; ... |
#include <bits/stdc++.h> using namespace std; int n, k; vector<int> adj[(int)1e5 + 7]; int vis[(int)1e5 + 7]; int deg[(int)1e5 + 7]; int cnt[(int)1e5 + 7]; int main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); ; scanf( %d %d , &n, &k); for (int i = 1; i <= n - 1; i++) { ... |
#include <bits/stdc++.h> using namespace std; const int mod = 1000000007; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t, n, m, a, b, c, q, k, d, x; cin >> n >> m; vector<vector<int>> mat(n + 1, vector<int>(m + 1)), ans(n + 1, vector<int>(m + 1)); char ch; ... |
#include <bits/stdc++.h> using namespace std; double EPS = 1e-9; long long INF = 1000000000000000005ll; double PI = acos(-1); inline string IntToString(long long int a) { char x[100]; sprintf(x, %lld , a); string s = x; return s; } inline long long int StringToInt(string a) { char x[1... |
#include <bits/stdc++.h> using namespace std; template <class T> inline T Min(T x, T y) { return x < y ? x : y; } template <class T> inline T Max(T x, T y) { return x > y ? x : y; } bool MOP1; long long T, n, res; long long head[(105)], nxt[(105)], to[(105)], line; void add(long long x, lo... |
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const double EPS = 1e-9; inline int cmp(double x, double y = 0, double tol = EPS) { return ((x <= y + tol) ? (x + tol < y) ? -1 : 0 : 1); } struct point { long long x, y; point(long long x = 0, long long y = 0) : x(x), y(y... |
#include <bits/stdc++.h> const int mx = 110; int a[mx]; bool ok(char ch) { if (ch == a || ch == e || ch == i || ch == o || ch == u || ch == y ) return true; return false; } int main() { int n; bool flag = 1; scanf( %d , &n); for (int i = 0; i < n; i++) scanf( %... |
#include <bits/stdc++.h> using namespace std; const int maxn = 100 + 2, maxm = 1e7 + 5; struct node { int bg, ed, id; } a[maxn]; int n, ans[maxn]; bool vis[maxm]; bool cmp(node a, node b) { return a.ed < b.ed; } int main() { scanf( %d , &n); for (int i = 0; i < n; i++) { scanf( %d %d ,... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.