func_code_string stringlengths 59 71.4k |
|---|
#include <bits/stdc++.h> using namespace std; const long long md = 1000000007; int main() { long long n, s, a, t1, t2; cin >> n; s = n * 2; vector<long long> v(s); for (int i = 0; i < s; i++) { cin >> a; v[i] = a; } sort(v.begin(), v.end(), greater<long long>()); t1 = 0... |
#include <bits/stdc++.h> using namespace std; void segmentedSieve(long long L, long long R) { long long lim = sqrt(R); vector<bool> mark(lim + 1, false); vector<long long> primes; for (long long i = 2; i <= lim; ++i) { if (!mark[i]) { primes.emplace_back(i); for (long long j = ... |
#include <bits/stdc++.h> using namespace std; int main(int argc, char *argv[]) { int n, k, i, o; cin >> n >> k; o = n - k; for (i = 1; i <= o - 1; i++) cout << i << ; for (i = n; i >= o; i--) cout << i << ; return 0; } |
#include <bits/stdc++.h> using namespace std; template <class T> T By(T x, T y, T P) { T F1 = 0; while (y) { if (y & 1) { F1 += x; if (F1 < 0 || F1 >= P) F1 -= P; } x <<= 1; if (x < 0 || x >= P) x -= P; y >>= 1; } return F1; } template <class T> ... |
#include <bits/stdc++.h> using namespace std; const int mod = 998244353; const int maxn = 2e5 + 10; const int inf = 0x3f3f3f3f; const double eps = 1e-6; int n, a[maxn]; int num[maxn]; int pre[maxn]; int lst[maxn]; int up = 500; int mx = 0; int c0[maxn], c[maxn]; void add(int x) { c0[c[x]]-... |
#include <bits/stdc++.h> const long long mod = 1000000007; int n; long long x[1 << 20]; long long y[1 << 20]; long long d[1 << 20]; long long sx[1 << 20]; long long sy[1 << 20]; long long sd[1 << 20]; long long ssd[1 << 20]; long long cirsm(int s, int v, long long sa[] = sd) { long long ar = 0; ... |
#include <bits/stdc++.h> using namespace std; const int mod = 1000000007; long long a, b, c, d, e, f, k; bool check(long long x, long long y) { if (k == 0) { return x == c && y == d; } return ((c - x) * e + (d - y) * f) % k == 0 && (e * (d - y) + f * (x - c)) % k == 0; } int mai... |
#include <bits/stdc++.h> using namespace std; long long MOD = 1e9 + 7; const long double E = 1e-7; unsigned char ccc; bool _minus = false; template <typename T> inline T sqr(T t) { return (t * t); } inline void read(long long &n) { n = 0; _minus = false; while (true) { ccc = getc... |
#include <bits/stdc++.h> using namespace std; int main() { int r, c; cin >> r >> c; char mat[r + 5][c + 5]; for (int i = 1; i <= r; i++) { for (int j = 1; j <= c; j++) { cin >> mat[i][j]; } } for (int i = 1; i <= r; i++) { for (int j = 1; j <= c; j++) { if (... |
#include <bits/stdc++.h> int t[100003] = {0}; int main() { int L, b, f, n; scanf( %d%d%d%d , &L, &b, &f, &n); t[L] = 1000; for (int i = 1; i <= n; i++) { int req, len; scanf( %d%d , &req, &len); if (req == 1) { bool e = 0; for (int a = 0; a < L; a++) { if ... |
#include <bits/stdc++.h> using namespace std; const long long N = 200009; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long t = 1; cin >> t; while (t--) { long long n, m; cin >> n >> m; long long a[n + 5]; long long na[n + 5]; f... |
#include <bits/stdc++.h> int main() { char g[100]; scanf( %s , g); for (int w = 0; g[w] != 0 ; w++) { if (g[w] >= 65 && g[w] <= 90) g[w] = g[w] + 32; } for (int w = 0; g[w] != 0 ; w++) { if (!(g[w] == a || g[w] == e || g[w] == i || g[w] == o || g[w] == u || g[... |
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 5; const int mod = 1e9 + 7; int arr[500]; int main() { int k, n; scanf( %d , &n); for (int i = 0; i < n; i++) { int a; scanf( %d , &a); if (a % 2) { cout << First << endl; return 0; } } ... |
#include <bits/stdc++.h> using namespace std; bool vis[30010][210][2][2][2]; int pd[30010][210][2][2][2]; int v[30010]; int n, K; int solve(int ind, int cut, int s1, int s2, int tem) { if (cut == K) return 0LL; if (ind == n) return -0x3f3f3f3f; int &ans = pd[ind][cut][s1][s2][tem]; if (vis[i... |
#include <bits/stdc++.h> using namespace std; const int MX = (1 << 19); string str; vector<pair<int, char> > sorted; int cnt[MX], done[MX], K; int main() { cin >> str >> K; for (int j = 0; j < str.size(); j++) cnt[str[j] - a ]++; for (int j = 0; j < 26; j++) { sorted.push_back(make_pair(c... |
#include <bits/stdc++.h> using namespace std; bool isSubSequence(string str1, string str2, int m, int n) { if (m == 0) return true; if (n == 0) return false; if (str1[m - 1] == str2[n - 1]) return isSubSequence(str1, str2, m - 1, n - 1); return isSubSequence(str1, str2, m, n - 1); } int ma... |
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; string s[n]; for (int i = 0; i < n; i++) cin >> s[i]; long long a[m]; for (int i = 0; i < m; i++) cin >> a[i]; long long ans = 0; for (int i = 0; i < m; i++) { long long maxi = 0; for (cha... |
#include <bits/stdc++.h> using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); int d4x[4] = {1, 0, -1, 0}; int d4y[4] = {0, 1, 0, -1}; int d8x[8] = {0, 1, 1, 1, 0, -1, -1, -1}; int d8y[8] = {1, 1, 0, -1, -1, -1, 0, 1}; const long long oo = 1e18; const long long maxN =... |
#include <bits/stdc++.h> using namespace std; char s[20]; int m; long long dp[1 << 18][110]; int cnt[20]; int main() { ios::sync_with_stdio(false); cin >> s >> m; memset(dp, 0, sizeof(dp)); memset(cnt, 0, sizeof(cnt)); dp[0][0] = 1; int l = strlen(s); long long x = 1 << l, d = 1;... |
#include <bits/stdc++.h> using namespace std; int main() { long long n, i, j, s, x; map<long long, long long> mp; map<long long, long long>::iterator it; cin >> n; s = 0; for (i = 0; i < n; i++) { cin >> x; s += x; mp[s]++; } i = -1; for (it = mp.begin(); it != ... |
#include<bits/stdc++.h> using namespace std; #define FASTio ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); #define ll long long int #define all(v) (v).begin(), (v).end() #define mp make_pair #define pb push_back #define pf push_front #define ff first #define ss second #define lcm(a, b... |
#include <bits/stdc++.h> using namespace std; void start(vector<int> &arr, pair<char, int> &prefAns, pair<char, int> &sufAns, string &s) { int i; for (i = 0; i < s.size(); ++i) { int cnt = 0; while (i + 1 != s.size() && s[i] == s[i + 1]) { ++cnt; ++i; } a... |
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; const long long inf = 0x3f3f3f3f; const long long llinf = 1e18; const long long nax = 0; long long n; vector<long long> arr(5005); vector<bool> ada(5005), masuk(5005); int main() { ios_base::sync_with_stdio(0); cin.ti... |
#include <bits/stdc++.h> using namespace std; int n, k; int l, r; long long pw[500007], inv[500007], ans = 0; pair<int, int> p[500007]; const long long mod = 1e9 + 7; long long pwr(long long x, long long y) { if (y == 0) return 1LL; if (y == 1) return x; long long ret = pwr(x, y / 2); if (... |
#include <bits/stdc++.h> using namespace std; int main() { long long k, d; cin >> k >> d; if (d == 0) { if (k == 1) cout << 0 << endl; else cout << No solution << endl; } else { cout << d; for (int i = 0; i < k - 1; i++) cout << 0 ; } return 0; } ... |
#include <bits/stdc++.h> using namespace std; const int MAXN = 5 * 100 * 1000 + 13; queue<int> bfsq; set<int> bfsS; set<pair<int, int> > forbid; vector<int> compV[MAXN], toDel; int main() { ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); int n, m; cin >> n >> m; for (int i = 1; ... |
#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; long long int N; set<int> P; void setP(long long int n, int x, int y) { if (n > N) return; if (n != 0) P.insert(n); if (n != 0 || x != 0) setP(n * 10 + x, x, y); if (n != 0 || y != 0) setP(n * 10 + y, x, y); } int main() { cin >> N; for (... |
#include <bits/stdc++.h> using namespace std; int main() { int hit[12]; string notes[12] = { C , C# , D , D# , E , F , F# , G , G# , A , B , H }; string x, y, z; cin >> x >> y >> z; for (int i = 0; i < 12; i++) { if (x == notes[i] || y == notes[i] || ... |
#include <bits/stdc++.h> int main() { int i, l, j; char t; char kb[100] = qwertyuiopasdfghjkl;zxcvbnm,./ ; char s[1000]; scanf( %c , &t); scanf( %s , s); l = strlen(s); for (i = 0; i < l; i++) { for (j = 0; j < 30; j++) { if (kb[j] == s[i]) { if (t == R ) { ... |
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); long long n, k, ans = 0; cin >> n >> k; if (k >= n / 2) ans = (n * (n - 1)) / 2; else { ans = (n * (n - 1)) / 2 - (((n - k) * (n - k - 1)) / 2) + k * (n - 2 * k) + (k * (k - 1)) / 2; }... |
#include <bits/stdc++.h> using namespace std; void runTest() { long long int n, a, b, k; cin >> n >> a >> b >> k; long long int ans = 0; vector<long long int> v; for (long long int i = 0; i < n; i++) { long long int val; cin >> val; long long int temp = ((val % (a + b... |
#include <bits/stdc++.h> using namespace std; long long n, sum; int main() { cin >> n; int ans = 0; for (int i = 1; i <= 1000000; i++) { sum += i; ans += (n + i) % 3 == 0 && (n + i) / 3 >= sum; } cout << ans << n ; return 0; } |
#include <bits/stdc++.h> using namespace std; const int ROOT = 0, MAXN = 100000; const char WHITE = 0, GRAY = 1, BLACK = 2; vector<int> graph[MAXN]; int n, m, a, b, i; char k[MAXN] = {WHITE}; inline int dfs(const int& v = ROOT) { k[v] = GRAY; int i, t, p = -1; for (i = 0; i < (int)(graph[v].si... |
#include <bits/stdc++.h> using namespace std; int r; char s[110]; int main() { scanf( %*d %s , s); for (int i = 1; s[i]; i++) r += s[i] == s[i - 1]; printf( %d , r); } |
#include <bits/stdc++.h> #pragma optimize( SEX_ON_THE_BEACH ) #pragma GCC optimize( unroll-loops ) #pragma GCC optimize( O3 ) #pragma GCC optimize( Ofast ) #pragma GCC optimize( fast-math ) #pragma GCC optimize( no-stack-protector ) #pragma GCC target( sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native ) us... |
#include <bits/stdc++.h> using namespace std; int main() { int pushes = 0; int buttons; cin >> buttons; for (int i = 1; i <= buttons; i++) { pushes += 1 + (i * (buttons - i)); } cout << pushes << endl; return 0; } |
#include <bits/stdc++.h> using namespace std; int main() { long long cnt = 0; int H; scanf( %d , &H); ; long long N; cin >> N; N--; long long n = 0; int d = 0; for (int h = (0); h < (H); h++) { long long msk = ((1LL) << (long long)(H - h - 1)); if (N & msk) { ... |
#include <bits/stdc++.h> using namespace std; const int inf = 1e9 + 7; template <class T> void dbs(string str, T t) { cout << str << : << t << endl; } template <class T, class... second> void dbs(string str, T t, second... s) { int idx = str.find( , ); cout << str.substr(0, idx) << : <... |
#include <bits/stdc++.h> using namespace std; int main() { int n, p = 0; scanf( %d , &n); while (n--) { int x; scanf( %d , &x); p = (p + x) % 2 + 1; printf( %d n , p); } } |
#include <bits/stdc++.h> using namespace std; int n, t, b[100020], cnt, p, q; char s[100020], s1[100020], s2[100020]; char chose(char x, char y) { if (x != a && y != a ) return a ; else if (x != b && y != b ) return b ; else return c ; } int main() { scanf( %d%d , ... |
#include <bits/stdc++.h> using namespace std; int main() { int test; cin >> test; while (test--) { int n, m; cin >> n >> m; vector<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]; } ve... |
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 3; const int mod = 998244353; int n; map<int, int> a; char s[N]; long long ans = 0; int main() { scanf( %d , &n); for (int i = 1; i <= n; i++) { scanf( %s , s + 1); int x = 0, l = strlen(s + 1); for (int j = 1; j... |
#include <bits/stdc++.h> using namespace std; map<int, int> working; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, q; cin >> n >> q; working[-1] = -1; working[2E9] = 2E9; working[1] = n; int answer = n; while (q--) { int l, r, k; cin >> l >> r >> k; ... |
#include <bits/stdc++.h> #pragma GCC optimize( Ofast,unroll-loops ) #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native ) using namespace std; void itval(istream_iterator<string> it) {} template <typename T, typename... Args> void itval(istream_iterator<string> it, T a, ... |
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const int maxn = 1e5 + 5; const int mod = 1e9 + 7; const double eps = 1e-8; int t, n; int main() { scanf( %d , &t); while (t--) { scanf( %d , &n); if (n == 1) puts( 0 ); else if (n == 2) put... |
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 10; const int MAXM = 1e5 + 10; const int INF = 1e9; struct edge { int u, v; long long w; int next; } e[MAXM * 2]; int first[MAXN]; int idx; int n; long long len, wei; struct node { long long weight, dist; int ... |
#include <bits/stdc++.h> using namespace std; int nodes[2050], depth, score = 0; int abs(int a) { if (a > 0) return a; return -a; } int max(int a, int b) { if (a > b) return a; return b; } int dfs(int d, int i, int total) { if (d == depth) return nodes[i]; int r = dfs(d + 1, i * 2,... |
#include <bits/stdc++.h> using namespace std; class Solution { public: bool split(vector<int>& A, vector<int>& inc, vector<int>& dec) { map<int, int> map; for (int e : A) map[e]++; for (const pair<int, int>& p : map) { if (p.second > 2) return false; inc.push_back(p.first); ... |
#include <bits/stdc++.h> using namespace std; int main() { unsigned int n; cin >> n; const int N = n; unsigned int m[N], sum = 0; for (int i(0); i < n; i++) { cin >> m[i]; sum += m[i]; } sort(m, m + n); unsigned int myMonets = 0, count = 0; for (int i(n - 1); i >= 0; ... |
#include <bits/stdc++.h> using namespace std; int n, p, mp[20][20], pre[20], cnt[100005][20]; int ban[1 << 17], usd[1 << 17][20][20], can[1 << 17], sum[1 << 17]; char s[100005]; int main() { scanf( %d%d , &n, &p); scanf( %s , s); for (int i = 0; i < p; i++) for (int j = 0; j < p; j++) scanf(... |
#include <bits/stdc++.h> using namespace std; long base; vector<long> vec[2000]; long can[200][200]; long lcm[200]; long long n, k; vector<vector<long> > mult(vector<vector<long> > a, vector<vector<long> > b) { vector<vector<long> > v; v.resize(a.size()); for (int i = 0; i < v.size(); i++) v[i... |
#include <bits/stdc++.h> using namespace std; using LL = long long; const int N = 2e5 + 4; int n, m, p[N], idx[N]; LL v1[N], v2[N]; vector<int> vals[N]; struct BIT { int s[N]; void init() { memset(s, 0, sizeof(s)); } void add(int i, int v) { for (; i <= n; i += i & (-i)) s[i] += v; }... |
#include <bits/stdc++.h> using namespace std; const long long M = 1e9 + 7; const long long inf = 4e18; const long long N = 1e6; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long t; cin >> t; while (t--) { long long n, m, k; cin >> n >> m >> k; ch... |
#include <bits/stdc++.h> using namespace std; void solve() { string s; cin >> s; int a = 0, b = 0; int i, j; int n = s.size(); for (i = 1; i < n; ++i) { if (s[i] == b && s[i - 1] == a ) { ++a; } if (s[i] == a && s[i - 1] == b ) { ++b; } } ... |
#include <bits/stdc++.h> int n, m, i, ans; int main() { scanf( %d , &n); for (i = 0; i < n; i++) scanf( %d , &m), ans += (i + 1) * m; printf( %d n , ans); return 0; } |
#include <bits/stdc++.h> using namespace std; string a[2006]; int row[2006], cal[2006]; int w[2006]; int main() { int n, ans = 0; cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = n - 1; i >= 0; i--) { for (int j = 0; j < i; j++) { int t = cal[j] + row[i]; i... |
#include <bits/stdc++.h> #pragma GCC optimize( O3 ) #pragma GCC target( sse4 ) using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); int64_t dr8[] = {1, 1, 0, -1, -1, -1, 0, 1}; int64_t dc8[] = {0, 1, 1, 1, 0, -1, -1, -1}; int64_t dr4[] = {1, 0, 0, -1}; int64_t dc4[] ... |
#include <bits/stdc++.h> using namespace std; int main() { int a; cin >> a; vector<int> b(a); vector<int> c(a); for (int i = 0; i < a; i++) { cin >> b[i]; c[i] = b[i]; } sort(b.begin(), b.end()); int i0 = 0, i1 = 0; for (int i = 0; i < a; i++) { if (c[i] == b[0]... |
#include <bits/stdc++.h> using namespace std; int a[1000004]; int main(void) { int n; scanf( %d , &n); int s = 1000000 + 1; printf( %d n , n); int p = 0; for (int i = 0; i < n; i++) { int t; scanf( %d , &t); a[t] = 1; if (a[s - t] == 1) p++; } for (int i = 1... |
#include <bits/stdc++.h> using namespace std; template <typename T1, typename T2> ostream& operator<<(ostream& os, const pair<T1, T2>& a) { os << ( << a.first << , << a.second << ) ; return os; } int main() { int n, m; cin >> n; vector<int> a(n); for (int i = 0; i < n; ++i) scanf(... |
#include <bits/stdc++.h> using namespace std; const long long int N = 1e5 + 5, inf = 1e18; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long int a, b, l, r; cin >> a >> b >> l >> r; l--; r--; long long int ans = 0; long long int d = (l) / (... |
#include <bits/stdc++.h> using namespace std; void err(istream_iterator<string> it) {} template <typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cerr << *it << = << a << endl; err(++it, args...); } mt19937 rng(chrono::steady_clock::now().time_since_epoch(... |
#include <bits/stdc++.h> int a, b, n, x; int temp; int absa, absb, absx; int main() { int i; scanf( %d%d%d , &a, &b, &n); temp = 1; if (a == 0 && b != 0) { printf( No solution n ); } else if (a == 0) { printf( 5 n ); } else if (b / a * a != b) { printf( No solution n );... |
#include <bits/stdc++.h> using namespace std; const long long maxn = 2e5 + 5; const long long mod = 1e18; const long long inf = 1e18; long long n, q, a[maxn], seg[maxn * 4], bl[maxn * 4], br[maxn * 4]; long long ans, al, ar; void fix(long long ind, long long v = 1, long long s = 0, long long e = n) { ... |
#include <bits/stdc++.h> using namespace std; struct st { deque<int> q; int cnt[100004]; int use[100004]; int u_s = 0; st() { memset(cnt, 0, sizeof(cnt)); memset(use, 0, sizeof(use)); q.clear(); } void push_back(int x) { q.push_back(x); if (use[x] != u_s) { ... |
#include <bits/stdc++.h> using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const long long maxn = 3e6; const long long mod = 1e9 + 7; const long double PI = acos((long double)-1); long long pw(long long a, long long b, long long md = mod) { long long res = 1; ... |
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7, SZ = 10000007; int nxt[200009]; char a[200][200]; int n, m, k, vid; vector<int> spf(SZ); vector<int> primes; void sieve() { for (int i = 1; i < SZ; i++) spf[i] = i; for (long long i = 2; i * i < SZ; i++) { if (spf... |
#include <bits/stdc++.h> using namespace std; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int n; cin >> n; ; vector<int> a(n); for (int i = 0; i < n; i++) cin >> a[i]; sort(a.begin(), a.end()); int current = 1; for (int i = 0; i < n; i++) { if (a[i] < cu... |
#include <iostream> #include <string> #include <cmath> #include <vector> #include <algorithm> #include <utility> #include <bitset> #include <climits> #include <set> #include <map> #include <iomanip> #include <queue> #include <cstring> using namespace std; #define ll long long #define pll p... |
#include <bits/stdc++.h> using namespace std; const int N = 2000 + 1; int n; int c[N]; vector<int> g[N]; int a[N], sz[N]; void inc(int v, int x) { if (a[v] >= x) ++a[v]; for (int u : g[v]) inc(u, x); } int dfs(int v, int t = 1) { a[v] = t + c[v]; sz[v] = 1; int new_t = t; for (... |
#include <bits/stdc++.h> using namespace std; const int INF = INT_MAX; const double EPS = 1e-10; inline double SQR(double x) { return x * x; } inline long long SQR(long long x) { return x * x; } inline int SQR(int x) { return x * x; } inline double SQR3(double x) { return x * x * x; } inline void DEBUG(... |
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; const int inf = 0x3c3c3c3c; const long long infl = 0x3c3c3c3c3c3c3c3c; const int MAX_N = 5e5 + 9; int a[MAX_N]; int minElements[MAX_N]; int cntElements[MAX_N]; int partialSum[MAX_N]; int main() { cin.ti... |
#include <bits/stdc++.h> using namespace std; const long long mod = (long long)1e9 + 7; long long power(long long x, long long y, long long p) { long long res = 1; x = x % p; if (x == 0) return 0; while (y > 0) { if (y & 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } ... |
#include <bits/stdc++.h> std::pair<int, int> advance(std::pair<int, int> pos, int dir) { switch (dir) { case 0: return {pos.first + 1, pos.second}; case 1: return {pos.first + 1, pos.second + 1}; case 2: return {pos.first, pos.second + 1}; case 3: return {po... |
#include <bits/stdc++.h> using namespace std; int mod = 1000000007; long long int gcd(long long int a, long long int b) { return b ? gcd(b, a % b) : a; } int lcm(int a, int b) { return a * b / gcd(a, b); } long long int bpow(long long int a, long long int b) { long long int res = 1; while (b > 0... |
#include <bits/stdc++.h> using namespace std; const int RULE = 100005; const int BUF = 100005; const int MOD = 1000000007; const int MOD2 = 1000000006; int mul(int a, int b) { return 1LL * a * b % MOD; } int add(int a, int b) { return (a + b) % MOD; } string init; int nRule; pair<int, string> rule[R... |
#include <bits/stdc++.h> using namespace std; const int maxn = 200009; const int MOD = 1e9 + 7; int main() { ios_base::sync_with_stdio(false), cout.tie(0), cin.tie(0); int n, k, v; cin >> n >> k >> v; vector<int> A(n + 1); for (int i = 1; i <= n; ++i) cin >> A[i]; vector<pair<pair<int, i... |
#include <bits/stdc++.h> inline long long MAX2(long long a, long long int b) { return (a) > (b) ? (a) : (b); } inline long long MAX3(long long a, long long b, long long c) { return (a) > (b) ? ((a) > (c) ? (a) : (c)) : ((b) > (c) ? (b) : (c)); } inline long long MIN2(long long a, long long b) { re... |
#include <bits/stdc++.h> using namespace std; int main() { long long n, m, k; cin >> n >> m >> k; long long a[n]; long long b[m]; for (long long i = 0; i < n; i++) { cin >> a[i]; } for (long long i = 0; i < m; i++) { cin >> b[i]; } sort(a, a + n); sort(b, b + m); ... |
#include <bits/stdc++.h> using namespace std; const long long MAXN = 1e2 + 10; pair<long long, long long> a[MAXN]; long long b[MAXN]; long long res[MAXN]; int main() { ios_base ::sync_with_stdio(false); cin.tie(0); long long n, w; cin >> n >> w; for (long long i = 0; i < n; i++) { ... |
#include <bits/stdc++.h> using ll = long long; const int MN = 1e5 + 100; const int MP = 1e4 + 100; const int MOD = 1e9 + 7; ll pw(ll b, int p) { ll r = 1LL; for (; p; p >>= 1, b = b * b % MOD) if (p & 1) r = r * b % MOD; return r; } int N, K; int p[MP], q[MN]; int t[MN], l[MN], T[MN]... |
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const double pi = acos(-1); map<int, int> p; int a[300010], l[300010], r[300010]; int main() { int n; scanf( %d , &n); for (int i = 1; i <= n; i++) scanf( %d , &a[i]); int ans = 0; l[ans] = 1; p[a[1]]++; for (... |
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n; int arr[n]; int sum = 0; int coun = 0; for (int i = 0; i < n; i++) { cin >> arr[i]; sum += arr[i]; } for (int i = 0; i < n; i++) { if ((sum - arr[i]) % 2 == 0) coun++; } cout << c... |
#include <bits/stdc++.h> using namespace std; inline int read() { int x = 0, f = 1; char c = getchar(); while (c < 0 || c > 9 ) { if (c == - ) f = -1; c = getchar(); } while (c >= 0 && c <= 9 ) x = (x << 3) + (x << 1) + (c ^ 0 ), c = getchar(); return x * f; } c... |
#include <bits/stdc++.h> using namespace std; const long long MAX = 1000001; vector<bool> prime(MAX, true); void sieve(vector<bool> &prime) { prime[0] = prime[1] = false; for (int i = 2; i * i < MAX; i++) { if (prime[i]) { for (int j = i * i; j < MAX; j += i) prime[j] = false; } ... |
#include <bits/stdc++.h> using namespace std; void Rd(int &res) { res = 0; char p; while (p = getchar(), p < 0 ) ; do { res = (res << 1) + (res << 3) + (p ^ 48); } while (p = getchar(), p >= 0 ); } void Pt(long long x) { if (x == 0) return; Pt(x / 10); putchar(x % 1... |
#include <bits/stdc++.h> using namespace std; const int MN = 70; struct mat { long long T[MN][MN]; void O() { for (int i = 0; i < MN; i++) for (int j = 0; j < MN; j++) T[i][j] = 1e18; } }; mat mult(mat a, mat b) { mat ret; ret.O(); for (int i = 0; i < MN; i++) { for... |
#include <bits/stdc++.h> using namespace std; int main() { long long n; scanf( %lld , &n); long long a[n + 100]; for (long long i = 0; i < n; i++) scanf( %lld , &a[i]); sort(a, a + n); long long q, x; scanf( %lld , &q); while (q--) { long long c = 0; scanf( %lld , &x); ... |
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; for (int i = 0; i < t; i++) { int n; int m; cin >> n >> m; int count = 0; for (int j = 0; j < n - 1; j++) { string s; cin >> s; if (s[m - 1] == R ) { count++; ... |
#include <bits/stdc++.h> using namespace std; using ll = long long; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); template <class T> T rand(T a, T b) { return uniform_int_distribution<T>(a, b)(rng); } template <class T> T rand() { return uniform_int_distribution<T>()(rng);... |
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e6 + 100; const int MOD = 1e9 + 7; vector<long long> child[MAXN]; long long dpzooj[MAXN]; long long dpfard[MAXN]; void dfs(long long v) { if (child[v].size() == 0) { dpzooj[v] = 1, dpfard[v] = 1; return; } for (auto u ... |
#include <bits/stdc++.h> using namespace std; const long long inf = 1ll << 50; const int maxn = 400005; const int maxm = 65; const long long mod = 1e9 + 7; int ehead[maxn], ecnt = 1; struct edge { int u, v; long long w; int next; } edg[maxn]; void add(int u, int v, long long w) { edg[+... |
#include <bits/stdc++.h> using namespace std; const int maxn = 301; int main() { int n; scanf( %d , &n); vector<map<int, int> > rank(n); for (int i = 0; i < (n); ++i) { for (int j = 0; j < (n); ++j) { int a; scanf( %d , &a); --a; rank[i][a] = j; } } ... |
#include <bits/stdc++.h> using namespace std; int main() { long long int n, base, number1 = 0, number2 = 0; int temp; vector<int> numbers; cin >> n >> base; while (n--) cin >> temp, numbers.insert(numbers.begin(), temp); for (long long int i = 0, j = 1; i < numbers.size(); i++, j *= base) ... |
#include <bits/stdc++.h> using namespace std; long long a[10]; int main() { int n; while (scanf( %d , &n) != EOF) { memset(a, 0, sizeof(a)); for (int i = 1; i <= n; ++i) a[i % 9]++; long long ans = 0; for (int i = 0; i < 9; ++i) for (int j = 0; j < 9; ++j) ans += a[i] * a[j... |
#include <bits/stdc++.h> using namespace std; void solve() { int n, kk; cin >> n >> kk; vector<string> v(n); unordered_map<string, int> mp; for (int i = 0; i < n; i++) { cin >> v[i]; mp[v[i]]++; } int ans = 0; string req; for (int i = 0; i < n; i++) { for (int j... |
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 5; int a[maxn], b[maxn], s[maxn], n; int main() { cin >> n; for (int i = 0; i < n; i++) cin >> a[i] >> b[i]; int cnt = max(a[0], b[0]); for (int i = 1; i < n; i++) { if (max(a[i], b[i]) <= cnt) cnt = max(a[i], b[i... |
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<pair<int, int>> a(n); for (int i = 0; i < n; ++i) { cin >> a[i].first; a[i].second = i; } sort(a.begin() + 1, a.end()); reverse(a.begin() + 1, a.end()); int nxt = 1; vector<pair<int, in... |
#include <bits/stdc++.h> using namespace std; const int MAX = 3e5 + 9; int sz[MAX], ans[MAX], p[MAX], n, q; vector<int> g[MAX]; int dfs(int v) { sz[v] = 1; for (auto u : g[v]) sz[v] += dfs(u); return sz[v]; } void calc(int v) { int bes = -1; for (auto u : g[v]) { calc(u); i... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.