func_code_string stringlengths 59 71.4k |
|---|
#include <bits/stdc++.h> using namespace std; const long long inf = 1e9 + 7; const long long INF = 1LL << 60; template <class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T& a, T b) { if (a > b) { a =... |
#include <bits/stdc++.h> using namespace std; struct union_find { vector<int> uf; vector<int> num_segments; vector<bool> used; union_find(int n) { uf.assign(n, -1); num_segments.assign(n, 0); used.assign(n, false); for (int i = 0; i < n; ++i) { if (i % 2 == 0) num_seg... |
#include <bits/stdc++.h> using namespace std; const pair<int, int> Dir[8] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}, {1, 1}, {1, -1}, {-1, -1}, {-1, 1}}; template <typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), ... |
#include <bits/stdc++.h> using namespace std; int n, k, ad, a[444444], u[444444]; char str[11]; int getnum(char str[]) { int ret = 0, neg = -1, i = 1; if (str[0] != - ) { neg = 1; i = 0; } for (; str[i]; i++) { ret = ret * 10 + str[i] - 0 ; } ret *= neg; return re... |
#include <bits/stdc++.h> using namespace std; const int kMod = 10007; char buf[222]; int m, n, l; int dp[222][222][222]; int f[222]; int s; struct Matrix { int v[444][444]; void clear() { memset(v, 0, sizeof(v)); } } I, A, F; Matrix operator*(const Matrix &a, const Matrix &b) { Matrix c;... |
#include <bits/stdc++.h> using namespace std; long long int c, t, n, a[1000005], b[1000005], used[100005]; int main() { cin >> t; while (t--) { cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; used[i] = 0; } for (int i = 1; i <= n; i++) cin >> b[i]; if (n... |
#include <bits/stdc++.h> #define mp make_pair #define fi first #define se second #define pb push_back #define eb emplace_back #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define forn(i, n) for (int i = 0; i < (int)(n); ++i) #define for1(i, n) for (int i = 1; i <= (in... |
#include <bits/stdc++.h> using namespace std; int n, m; int main() { scanf( %d%d , &n, &m); if (n > m) swap(n, m); int ans; if (n == 1) ans = m; else if (n == 2) { if (m % 4 <= 2) ans = m + m % 4; else ans = m + 1; } else ans = (n * m + 1) / 2; p... |
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) #pragma GCC target( avx,avx2,fma ) using namespace std; long long gcd(long long a, long long b) { return (b == 0) ? a : gcd(b, a % b); } long long lcm(long long a, long long b) { return ((a * b) / (gcd(a, b))); } bool compare(const pair<long long, long ... |
#include <bits/stdc++.h> using namespace std; int a[200100]; int sub[200100]; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; int t; cin >> t; while (t--) { int n; cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; } sort(a + ... |
#include <bits/stdc++.h> using namespace std; const long long int mod = 1000000007ll; const long long int MOD = 1000000009ll; int local_debug = 0; long long int bit_count(long long int _x) { long long int _ret = 0; while (_x) { if (_x % 2 == 1) _ret++; _x /= 2; } return _ret; } ... |
#include <bits/stdc++.h> using namespace std; const int N = 105; int atk[N], atk2[N], def2[N]; bool mark[N]; int main() { int n, len; while (scanf( %d%d , &n, &len) != EOF) { int lena = 0, lend = 0, i, j; for (i = 0; i < n; i++) { char s[5]; int v; scanf( %s%d , s,... |
#include <bits/stdc++.h> using namespace std; int main() { long long n, a[10000], first = -1, val, t = 1; cin >> n; cin >> a[0]; for (int i = 1; i < n; i++) { cin >> a[i]; if (a[i - 1] > a[i] || a[i - 1] == a[i]) t = 0; } if (t == 1) { cout << YES ; return 0; } ... |
#include <bits/stdc++.h> using namespace std; long long int n, a, k; char s[2000007], res[2000007]; bool vis[2000007]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n; long long int maxn = -1; for (long long int i = 0; i < n; ++i) { cin >> s >> k; long long int ... |
#include <bits/stdc++.h> #pragma GCC optimaze( Ofast ); #pragma GCC optimize( unroll-loops ) using namespace std; const long long maxk = 1e8 + 113; const long long maxb = 1e18 + 113; const long long inf = 2e18; struct line { long long k, b; line() { this->k = 0; this->b = 0; } ... |
#include <bits/stdc++.h> using namespace std; void read() { freopen( input.txt , r , stdin); freopen( output.txt , w , stdout); } string a1, a2, b1, b2; void check() { if (a1[0] == X ) swap(a1[0], a1[1]); else if (a1[1] == X ) swap(a1[1], a2[1]); else if (a2[1] == X ) ... |
#include <bits/stdc++.h> using namespace std; int main() { char s[1000000]; cin >> s; int l = strlen(s); int a[26][2]; char x = 0; int diff = 0; for (int i = 0; i < 26; i++) { a[i][0] = 0; a[i][1] = 0; } for (int i = 0; s[i] != 0 ; i++) { x = (int)s[i]; ... |
#include <bits/stdc++.h> using namespace std; template <class T> void debug(T a, T b) { ; } template <class T> void chmin(T& a, const T& b) { if (a > b) a = b; } template <class T> void chmax(T& a, const T& b) { if (a < b) a = b; } namespace std { template <class S, class T> ostrea... |
#include <bits/stdc++.h> using namespace std; const int MAX = 2e5 + 100, inf = 0x3f3f3f3f; const int mod97 = 1e9 + 7, mod33 = 998244353; const int drc[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}}; struct edge { int to, cap, dis, nt; } e[MAX]; int tot, head[555]; int MinCost, MaxFlow; int n, m, K, Q,... |
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; int k = 0, l; int n = s.length(); if (n <= 20) { cout << 1 << << n << endl; cout << s; } else { int m; if (n % 20 == 0) m = n / 20; else m = (n / 20) ... |
#include <bits/stdc++.h> using namespace std; void fastscan(int& number) { bool negative = false; register int c; number = 0; c = getchar(); while (c == 10) c = getchar(); if (c == - ) { negative = true; c = getchar(); } for (; (c > 47 && c < 58); c = getchar()) number =... |
#include <bits/stdc++.h> using namespace std; void solve() { int n; cin >> n; string s; cin >> s; stack<char> stack; int left = 0, right = 0, size = 0; for (int i = 0; i < s.length(); i++) { stack.push(s[i]); if (s[i] == ( ) { left++; continue; } ... |
#include <bits/stdc++.h> using namespace std; const long long MOD = 998244353; const int maxn = 1000000 + 100; long long n, ans; long long inv[maxn], pro[maxn], invpro[maxn]; void Prepare_C() { inv[1] = 1; for (int i = 2; i < maxn; ++i) { inv[i] = (MOD - MOD / i) * inv[MOD % i] % MOD; } ... |
#include <bits/stdc++.h> using namespace std; bool myfunction(int i, int j) { return (i < j); } void solve() { long long n; cin >> n; set<long long> st; long long a; for (long long int i = 0; i < n; i++) { cin >> a; st.insert(a); } if (st.size() > 3) { cout << -1; ... |
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; #define int ll set<int> s; const int N = 200000 + 7; const int M = 998244353; int n; int a[N], pre[2][N], total[N]; int getsumx(int mod, int l, int r) { if (l > r) return 0; return pre[... |
#include <bits/stdc++.h> using namespace std; int in; int a[105][105]; int b[100000]; int max(int l, int n) { int m = a[l][0]; int in = 0; for (int x = 0; x < n; x++) { if (m < a[l][x]) { m = a[l][x]; in = x; } } return in; } int main() { int n, m; c... |
#include <bits/stdc++.h> using namespace std; int a[51]; int b[51]; int d1[51]; int d2[51]; int main() { int n, l; int i, j, k; cin >> n >> l; for (i = 1; i <= n; i++) { cin >> a[i]; if (i >= 2) d1[i] = a[i] - a[i - 1]; } d1[1] = a[1] + l - a[n]; for (i = 1; i <= n; i... |
#include <bits/stdc++.h> using namespace std; int main() { long long int n, i; cin >> n; long long int a[n], b[n], c[n + 1], x = n - 1; for (i = 0; i < n; i++) { b[i] = 0; c[i + 1] = 1; } c[0] = 1; for (i = 0; i < n; i++) { cin >> a[i]; a[i]--; b[a[i]]++; ... |
#include <bits/stdc++.h> using namespace std; const int N = 200010, M = 1000010, P = 1e9 + 7; const int inf = 0x3f3f3f3f; const int INF = 0xcfcfcfcf; const double eps = 1e-9, pi = asin(1) * 2; long long read(); int ADD(int a, int b) { return a + b >= P ? a + b - P : a + b; } int MINUS(int a, int b) { re... |
#include <bits/stdc++.h> using namespace std; signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n, m; cin >> n >> m; vector<int> h(n * m + 1), v(m * n + 1); vector<vector<int> > A(n, vector<int>(m)); for (int i = 0; i < n; i++) { for (int j = ... |
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); long int n, m, a; cin >> n >> m >> a; long int colNum = ceil((double)a / (double)(2 * m)); a -= (colNum - 1) * m * 2; long int rowNum = ceil((double)a / 2); ... |
#include <bits/stdc++.h> using namespace std; int main() { int pas = 0, tem, tem1; int n; cin >> n; vector<int> parent(n + 1, 0); int x, y; vector<vector<int> > s(n + 1, (vector<int>(3))); for (int i = 1; i <= n; i++) { cin >> s[i][1] >> s[i][2]; } for (int i = 1; i <= n; i... |
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; const long long inf = (1LL << 60); const double pi = acos(-1); long long powmod(long long a, long long b) { long long res = 1; a %= mod; assert(b >= 0); for (; b; b >>= 1) { if (b & 1) res = res * a % mod; ... |
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; const long long INF = 1e9 + 5; const long long mod = 1e9 + 7; const double pi = 3.1415926536; int main() { ios::sync_with_stdio(0); cin.tie(0); ios_base::sync_with_stdio(0); ; int n, m; cin >> n >> m; bool valid... |
#include <bits/stdc++.h> using namespace std; int main() { long long t; cin >> t; while (t--) { long long n, q; cin >> n >> q; vector<long long> a(n); for (long long i = 0; i < n; i++) { cin >> a[i]; } long long x = 0, y = 0; for (long long i = 0; i < n;... |
#include <bits/stdc++.h> using namespace std; const long long N = 100005; string A; void solve() { long long n, mi = 0, pl = 0; cin >> A; A = + + A; n = A.size() - 1; stack<char> s; for (__typeof((n)) i = (1); i <= (n); i++) { if (s.empty()) s.push(A[i]); else if (s... |
#include <bits/stdc++.h> using namespace std; const double eps = 1e-7; double L, R, m1, m2, a, b, l; double calc(double alp) { return a * sin(alp) + b * cos(alp) - l * sin(alp) * cos(alp); } int main() { scanf( %lf%lf%lf , &a, &b, &l); if (a > b) swap(a, b); if (l <= b) { printf( %.8lf... |
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<vector<int>> v; v.resize(n, vector<int>(7)); for (int i = 0; i < n; i++) { for (int j = 0; j < 7; j++) { scanf( %1d , &v[i][j]); } } int max_rooms = 0, cur = 0; for (int i = 0; i < ... |
#include <bits/stdc++.h> using namespace std; int main() { int a; long long x[] = { 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8092, 16184, 32368, 64736, 129472,... |
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10, INF = 0x3f3f3f3f, MOD = 1e9 + 7; int n, m, g[405][405]; int in[405], dpv[405], dpb[405]; int bfs() { queue<int> q; q.push(1); memset(dpv, 0x3f, sizeof dpv); dpv[1] = 0; while (q.size()) { int u = q.front(); q... |
#include <bits/stdc++.h> using namespace std; int n, k, mod = 1000000007; char t[2042]; long long dp[2042][2042], suff[2042][2042]; int solve() { dp[n][0] = 1; for (int cInd = n - 1; cInd >= 0; cInd--) { dp[cInd][0] = 1; for (int kLeft = 0; kLeft <= k; kLeft++) { bool f = 0; ... |
#include <bits/stdc++.h> using namespace std; const int c=200002, sok=2e9; long long t[c], kom[c], h[c], ki[c], n, m, maxi; priority_queue<pair<long long, int> > q; vector<pair<long long, int> > ans; int holvan(int a) { if (!ki[a]) { return a; } return ki[a]=holvan(ki[a]); }... |
#include <bits/stdc++.h> using namespace std; unsigned long long x1, out; unsigned long long Fac(unsigned long long x1) { unsigned long long out = 1; for (int i = 1; i <= x1; i++) out = out * i; return out; } unsigned long long Cnk(unsigned long long a, unsigned long long b, ... |
#include <bits/stdc++.h> #pragma comment(linker, /STACK:64000000 ) using namespace std; const int inf = (int)1e9; const int mod = inf + 7; const double eps = 1e-9; const double pi = acos(-1.0); int n; string second; int a[100]; vector<int> g[202]; int dp[77][77][77][4]; int calc(vector<int> &a,... |
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); double t, a, b, c, d, k; cin >> t; while (t--) { cin >> a >> b >> c >> d >> k; double p1, p2; p1 = ceil(a / c); p2 = ceil(b / d); if (p1 + p2 <= k) { cout << p1 <... |
#include <bits/stdc++.h> using namespace std; int n, m; double ax, ay, bx, by, tx, ty, x, y; char s[100100]; double len(double x1, double y1, double x2, double y2) { return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); } int main() { ios_base::sync_with_stdio(false); cin >> ax >> ay >> ... |
#include <bits/stdc++.h> int main() { int n; scanf( %d , &n); char arr[n][n + 1]; int i, j, k; int sum = 0; int count; for (i = 0; i < n; i++) scanf( %s , arr[i]); for (i = 0; i < n; i++) { count = 0; for (j = 0; j < n; j++) { if (arr[i][j] == C ) count++; } ... |
#include <bits/stdc++.h> using namespace std; #define mod1 1000000007 #define mod2 998244353 #define ff first #define ss second #define int long long #define ll unsigned long long #define pb push_back #define mp make_pair #define pii pair<int,int> #define inf 9e18 #define N 150... |
#include <bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; using ld = long double; template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) { for (const auto& x : v) os << x << ; return os << n ; } template <typename T> void opera... |
#include <bits/stdc++.h> using namespace std; string read(char x[]) { scanf( %s , x); return x; } const int N = 8; const int M = 2e5 + 23; int n, m, x[M], y[M], ans; map<int, pair<long long, long long>> mp; void solve() { scanf( %d %d , &n, &m); for (int i = 0; i < n; i++) scanf( %d , x ... |
#include <bits/stdc++.h> using namespace std; bool myfunction(int i, int j) { return (i < j); } int main() { long h[2003]; int n, a, b; scanf( %d%d%d , &n, &a, &b); for (int i = 0; i < n; i++) { scanf( %ld , &h[i]); } sort(h, h + n, myfunction); int x = h[b] - h[b - 1]; print... |
#include <bits/stdc++.h> template <class t> inline void read(t &s) { s = 0; register long long f = 1; register char c = getchar(); while (!isdigit(c)) { if (c == - ) f = -1; c = getchar(); } while (isdigit(c)) s = (s << 3) + (s << 1) + (c ^ 48), c = getchar(); s *= f; re... |
#include <bits/stdc++.h> using namespace std; int b[1002][1002] = {0}; int main() { int a[8][3] = {{7, 3, 5}, {2, 6, 4}, {1, 5, 7}, {0, 4, 6}, {3, 7, 1}, {0, 2, 6}, {1, 3, 5}, {0, 2, 4}}; int x[8]; int y[8]; int d[8]; int n; int m; int tmpx, tmpy; int sum = 0; ... |
#include <bits/stdc++.h> using namespace std; const int M = 100004; unordered_map<string, int> mp; unordered_set<int> st[M]; vector<int> g[M]; string s[M]; int m = 0; int getid(string &t) { if (mp.count(t)) return mp[t]; else { s[++m] = t; return mp[t] = m; } } int val[... |
#include <bits/stdc++.h> using namespace std; void File() { freopen( CF1045H.in , r , stdin); freopen( CF1045H.out , w , stdout); } template <typename T> void read(T &_) { _ = 0; T f = 1; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == - ) f = -1; for (; is... |
#include <bits/stdc++.h> using namespace std; int a[1000001]; int l, r; int jum, jaw; int main() { int n, m, k; cin >> n >> m >> k; k--; for (int i = 1; i <= n; i++) { int dum; cin >> dum; a[dum]++; } l = 1; r = m; for (int i = 1; i <= m; i++) { if (a[i]... |
#include <bits/stdc++.h> using namespace std; const int maxn = 1010; int a[maxn]; int main() { int n = 4; for (int i = 0; i < n; i++) { cin >> a[i]; } sort(a, a + n); int sum, ans; sum = ans = 0; ans = a[3]; int l = 0; n = 2; while (n >= 0) { if (ans > sum) ... |
#include <bits/stdc++.h> using namespace std; const int N = 50010, K = 11; int n, k; int s[N][K]; struct Data { int mn[K], mx[K]; int cnt; Data() { for (int i = 0; i < K; i++) { mn[i] = 1e9; mx[i] = -1e9; } cnt = 0; } }; bool operator<(const Data &u, const... |
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { while (a > 0 && b > 0) { if (a < b) swap(a, b); a %= b; } return a + b; } const int maxN = (int)1e6 + 10; long long a[maxN]; long long k; vector<long long> factor(long long x) { vector<long ... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int n, m; cin >> n >> m; int a[n][m], b[n][m]; for (int i = 0; i < n; ++i) for (int j = 0; j < m; ++j) cin >> a[i][j]; for (int i = 0; i < n; ++i) for (int j = 0; j ... |
#include <bits/stdc++.h> using namespace std; int c[120][120], ct[120], n; int ccc[120], Ciel, Jiro, cnt; int main() { scanf( %d , &n); for (int i = 0; i < n; i++) { scanf( %d , ct + i); int p1 = ct[i] / 2 - 1, p2 = ct[i] - ct[i] / 2; for (int j = 0; j < ct[i]; j++) { scanf( %d... |
#include <bits/stdc++.h> using namespace std; const long long M = 998244353; long long modpow(long long base, long long exp, long long modulus = M) { base %= modulus; long long result = 1; while (exp > 0) { if (exp & 1) result = (result * base) % modulus; base = (base * base) % modulus; ... |
#include <bits/stdc++.h> using namespace std; using PII = pair<int, int>; PII a[300005]; int idx[300005]; map<int, int> mp; int main() { int n; ; scanf( %d , &n); for (int i = 0; i < n; ++i) { scanf( %d %d , &a[i].first, &a[i].second); idx[i] = i; } sort(idx, idx + n, [&]... |
#include <bits/stdc++.h> using namespace std; const long long N = 1e6 + 5; long long n; long long a[N]; int32_t main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; cin >> n; if (n == 0) { cout << 1 1 ; return 0; } long long l = 1, r = n; for (long long... |
#include <bits/stdc++.h> const double Pi = 3.14159265; const int N = 2e5 + 10; const unsigned long long base = 163; const int INF = 0x3f3f3f3f; const int mod = 1e9 + 7; const double eps = 1e-10; const double pi = acos(-1); using namespace std; long long inv[N]; long long dp[N]; int main() { lo... |
#include <bits/stdc++.h> const int N = 2e5 + 5; using namespace std; int n, k, m, ans[N], x[N], y[N], mx; map<pair<int, int>, int> Mp; template <typename T> inline T read() { T x = 0, w = 1; char c = getchar(); while (c < 0 || c > 9 ) { if (c == - ) w = -1; c = getchar(); } ... |
#include <bits/stdc++.h> using namespace std; long long sum[2000005]; int main() { long long n; double k; cin >> n >> k; vector<long long> v; for (int i = 0; i < n; i++) { long long a; cin >> a; v.push_back(a); } for (int i = 1; i <= n; i++) { sum[i] = sum[i - 1... |
#include <bits/stdc++.h> using namespace std; long long rdtsc() { long long tmp; asm( rdtsc : =A (tmp)); return tmp; } inline int myrand() { return abs((rand() << 15) ^ rand()); } inline int rnd(int x) { return myrand() % x; } const int maxn = (int)1600 + 10; int a[maxn][maxn]; int used[ma... |
#include <bits/stdc++.h> using namespace std; const int N = 2000000 + 10; int a[N], b[N]; int n, m; int main() { int x, y; scanf( %d%d , &n, &m); { for (int i = 0; i < m; i++) { scanf( %d%d , &x, &y); x--; y--; a[x]++; a[y]++; } for (int i ... |
#include <bits/stdc++.h> using namespace std; long long n, i, m[6222000], k, a, b, x, y, sum, z, m1[5000]; string s; int main() { cin >> n; for (i = 0; i < n; i++) { cin >> m[i]; } sort(m, m + n); for (i = 1; i < n; i++) { if (m[i] == m[i - 1]) z++; else z =... |
#include <bits/stdc++.h> using namespace std; vector<pair<int, int> > vec; int grid1[2050], grid2[2050]; int main() { int n; cin >> n; int r = 0, c = 0; long long ans = 0; for (int i = 1; i <= n; i++) { int x, y; cin >> x >> y; ans += grid1[x + y]; grid1[x + y]++; ... |
#include <bits/stdc++.h> #pragma GCC optimize Ofast using namespace std; const long long BIG_INF = 1e18; const int N = 1e6 + 7; const int T = 1 << 20; template <class T, class G> ostream &operator<<(ostream &os, const pair<T, G> ¶) { os << para.first << << para.second; return os; } t... |
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 10; set<int> adj[maxn * 2 + 20]; int ans[maxn], n; vector<int> ans_eu; map<pair<int, int>, int> mp; void find_eu(int v) { while (adj[v].size()) { int tmp = *adj[v].begin(); adj[v].erase(tmp); adj[tmp].erase(v); ... |
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0), cin.tie(0); int T; cin >> T; while (T--) { long long p, q; cin >> p >> q; long long ans = -1; for (long long i = 1; i * i <= q; ++i) { long long pp = p; if (q % i == 0) { ... |
#include <bits/stdc++.h> const int N = 100001; int Pri[200005]; int NN, Cnt[100005], Mac[100005]; bool Use[200005]; void GetPrimeList() { int TmpN = sqrt(N); for (int i = 2; i <= N; ++i) Use[i] = true; for (int i = 2; i <= N; ++i) { if (Use[i]) Pri[++Pri[0]] = i; for (int j = 1; j <= P... |
#include <bits/stdc++.h> const int MAXN = 2e5 + 7; struct Edge { int t, next; } edge[MAXN << 1]; int head[MAXN], cnt; std::pair<int, int> p[MAXN]; int color[MAXN]; int n; void add(int u, int v) { edge[++cnt] = (Edge){v, head[u]}; head[u] = cnt; } void dfs(int u, int col) { if (color[... |
#include <bits/stdc++.h> using namespace std; template <typename A, typename B> inline void chmin(A &a, B b) { if (a > b) a = b; } template <typename A, typename B> inline void chmax(A &a, B b) { if (a < b) a = b; } template <class A, class B> ostream &operator<<(ostream &ost, const pair<A, B>... |
#include <bits/stdc++.h> using namespace std; vector<int> v, w; int m; long long int f(int d, int target) { long long int timeSpent = 0; long long int totDone = 0; long long int koytaDone = 0; long long int lastSpent = 0; for (int i = 0; i < v.size(); i++) { if (v[i] <= d) { ti... |
#include <bits/stdc++.h> using namespace std; int dp[1123456], p[1123456]; int main() { int n, i, j; scanf( %d , &n); for (i = 0; i < n; ++i) { scanf( %d , &j); p[j] = i; } dp[1] = 1; int ans = 1; for (i = 2; i <= n; ++i) { if (p[i] > p[i - 1]) { dp[i] = 1 + d... |
#include <bits/stdc++.h> using namespace std; int ans[1005]; void calc() { int i, j; for (i = 2; i < 1000; i++) { if (ans[i] == 0) { ans[i] = 1; int k = i; for (j = 2; j <= 10; j++) { if (k * i < 1000) { ans[k * i] = 1; k = k * i; }... |
#include <bits/stdc++.h> using namespace std; int a[1000][1000]; int b[1000][1000]; int f[1000][1000]; int sum[4][1000][1000]; int dx[4] = {0, 0, -1, 1}; int dy[4] = {-1, 1, 0, 0}; int gcd(int a, int b) { if (a % b == 0) { return b; } else { return gcd(b, a % b); } } int main... |
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; const long long INF = 1e9 + 9; const long long N = 500500; signed main() { ios_base::sync_with_stdio(false); cin.tie(0); long long T; cin >> T; while (T--) { long long n, ans = 0, mx; cin >> n; f... |
#include <bits/stdc++.h> using namespace std; struct edge { int v, w; edge() {} edge(int V, int W) { v = V, w = W; } }; struct node { long long x, y, z; node() {} node(long long X, long long Y, long long Z) { x = X, y = Y, z = Z; } } p[100005]; vector<edge> G[100005]; int n; long... |
#include <bits/stdc++.h> using namespace std; const int N = (int)1e6 + 5; const int mod = (int)1e9 + 7; string a; int x, n; int u[N]; int main() { ios_base::sync_with_stdio(false); cin >> a; cin >> n; for (int i = 1; i <= n; i++) { cin >> x; u[x]++; } for (int i = 1; i ... |
#include <bits/stdc++.h> using namespace std; struct masivs { long long in; long long out; long long poz; }; masivs mas[100005]; long long i, j, k, n, m, a, b, c; vector<pair<pair<long long, long long>, long long> > ab; int main() { std::cin.sync_with_stdio(false); std::cin.tie(0); ... |
#include <bits/stdc++.h> const int MAX_N = 5e2 + 5; int n, f[MAX_N][MAX_N], g[MAX_N]; int main() { scanf( %d , &n); for (int i = 1; i <= n; ++i) scanf( %d , &f[i][i]); for (int l = 1; l < n; ++l) for (int i = 1; i + l <= n; ++i) for (int j = i; j < i + l; ++j) if (f[i][j] && f[... |
#include <bits/stdc++.h> using namespace std; const int N = 400005; int n, m, h[N], p[N]; set<int> S; set<int>::iterator it; inline void read(int &i) { i = 0; char c = getchar(); bool j = 0; for (; !isdigit(c); c = getchar()) if (c == - ) j = 1; for (; isdigit(c); c = getchar()) i... |
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) #pragma GCC target( avx,avx2,fma ) #pragma GCC optimization( unroll-loops ) using namespace std; const int maxn = 1e4 + 5; set<string> st3; int dp[maxn][4]; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); string s1, sx... |
#include <bits/stdc++.h> using namespace std; int k, c, fact[10010], refact[10010]; int POW(int a, int b) { int res; for (res = 1; b; (b & 1) && (res = 1LL * res * a % 1000000007), a = 1LL * a * a % 1000000007, b >>= 1) ; return res; } int C(int n, int m) { if (m > n) return 0; ... |
#include <bits/stdc++.h> const int MAXNUM = 255000; int n; int m; int ecnt; int a[MAXNUM]; int b[MAXNUM]; int inflow[MAXNUM]; int outflow[MAXNUM], direct[MAXNUM]; int head[MAXNUM], to[MAXNUM * 2], next[MAXNUM * 2], c[MAXNUM * 2], from[MAXNUM * 2]; inline int readint() { char c = getchar();... |
#include <bits/stdc++.h> #pragma comment(linker, /STACK:100000000 ) using namespace std; vector<vector<int> > g; vector<int> cl; int q = 0; int n; void dfs(int v) { cl[v] = q; if (cl[g[v][0]] == 0) dfs(g[v][0]); } void swap(int i, int j) { g[i][0] = g[j][0] + g[i][0]; g[j][0] = g[i][0... |
#include <bits/stdc++.h> using namespace std; long long int n; long long int ppow(long long int i, long long int j) { if (i >= 998244353) i %= 998244353; long long int res = 1LL; while (j) { if (j & 1LL) { res *= i; if (res >= 998244353) res %= 998244353; } i *= i; ... |
#include <bits/stdc++.h> void rep(const char *s, int x) { for (int i = 1; i <= x; i++) printf( %s , s); } void leading0() { putchar( 1 ); putchar( r ); rep( 0srt , 30); rep( lst , 30); putchar( l ); putchar( e ); } int main() { printf( r0l ); rep( l , 31); leading0(); ... |
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; for (int i = n; i < 2 * n; ++i) cout << i << ; return 0; } |
#include <bits/stdc++.h> using namespace std; int dp[255][105][105]; int c[255][255]; int cc[1005]; int N; string s; int f(char l, int i, int k) { if (i == N) return 0; if (dp[l][i][k] != -1) return dp[l][i][k]; int r = f(s[i], i + 1, k) + c[l][s[i]]; if (k) { for (char x = a ; x <=... |
#include <bits/stdc++.h> using namespace std; int32_t main() { ios_base::sync_with_stdio(false); long long n, m, k; cin >> n >> m >> k; long long l = 1, r = 1e9 + 1; while (r - l > 1) { long long mid = (l + r) / 2; long long ans = mid; if (k >= mid) ans += ((mid - 1) * mid) / 2... |
#include <bits/stdc++.h> using namespace std; template <class Flow = int, class Cost = int> struct MinCostFlow { const Flow INF_FLOW = 1000111000; const Cost INF_COST = 1000111000111000LL; int n, t, S, T; Flow totalFlow; Cost totalCost; vector<int> last, visited; vector<Cost> dis; ... |
#include <bits/stdc++.h> using namespace std; const int MAX = 1e6 + 6; vector<int> adj[MAX]; bool visited[MAX]; void dfs(int source, int &nodes, int &total) { total += adj[source].size(); visited[source] = true; nodes++; for (auto &each : adj[source]) { if (!visited[each]) { dfs(... |
#include <bits/stdc++.h> using namespace std; long long int M = 1e9 + 7; long long int M1 = 998244353; long long int dr[8] = {-1, 0, 0, 1, -1, -1, 1, 1}; long long int dc[8] = {0, 1, -1, 0, -1, 1, -1, 1}; long long int gcd(long long int a, long long int b) { if (b == 0) return a; return gcd(b, a % b... |
#include <bits/stdc++.h> const double PI = 3.141592653589793238460; long long int gcd(long long int a, long long int b) { if (a == 0) return b; return gcd(b % a, a); } long long int max(long long int a, long long int b) { if (a > b) return a; else return b; } long long int min(lo... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.