func_code_string stringlengths 59 71.4k |
|---|
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; stack<char> st; for (int i = 0; i < s.length(); i++) { if (st.empty()) { st.push(s[i]); } else if (st.top() == s[i]) { st.pop(); } else { st.push(s[i]); } } if (st.e... |
#include <bits/stdc++.h> using namespace std; const long long int N = 1e5 + 5; const long long int mod = 1e15 + 7; long long int dx[] = {1, -1, 0, 0}; long long int dy[] = {0, 0, 1, -1}; long long int y[N], yy[N], len[N]; long long int n, m, low, high, mid1, mid2; double ans = (double)mod; long long i... |
#include <bits/stdc++.h> using namespace std; using ii = tuple<long long, long long>; const long long N = 1e6 + 7, inf = 1e9 + 42; long long binpow(long long a, long long b) { if (b == 0) return 1; long long res = binpow(a, b / 2); if (b % 2) return (res * res * a) % 1000000007; else ... |
#include <bits/stdc++.h> using namespace std; using pil = pair<long long, long long>; using pii = pair<long long, long long>; using pid = pair<double, double>; long long mod = 1e9 + 7; long long power(long long a, long long n) { long long res = 1; while (n) { if (n % 2) res = (res * a) % mod; ... |
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 20; int n, m; struct line { int type, x, y, lag; line() { type = x = y = lag = 0; } line(int a, int b, int c, int d) { type = a, x = b, y = c, lag = d; } bool operator<(const line &a) const { return y > a.y; } } t[7 * N]; int ... |
#include <bits/stdc++.h> using namespace std; template <typename T> inline void read(T &n) { T w = 1; n = 0; char ch = getchar(); while (!isdigit(ch) && ch != EOF) { if (ch == - ) w = -1; ch = getchar(); } while (isdigit(ch) && ch != EOF) { n = (n << 3) + (n << 1) + (ch ... |
#include <bits/stdc++.h> using namespace std; int a, b, n, i, p[1001], sz[1001], cnt[1001]; vector<pair<int, int> > v2; vector<int> v; int find_p(int a) { if (p[a] == a) return a; return p[a] = find_p(p[a]); } void unionn(int a, int b) { int _a = a, _b = b; a = find_p(a); b = find_p(b)... |
#include <bits/stdc++.h> using namespace std; auto main() -> int { int N, X, Y; cin >> N; vector<int> C(N); for (int i = 0; i < N; i++) cin >> C[i]; cin >> X >> Y; int l = 0; int ret = 0; for (int i = 0; i < N; i++) { if (l < X) { if (l + C[i] <= Y) l += C[i];... |
#include <bits/stdc++.h> using namespace std; int N, M, i, j; int a, b, v[105]; bool ok = true; int main() { cin >> N >> M; for (i = 1; i <= N; i++) { cin >> a >> b; a++; v[a]++; v[b + 1]--; } for (i = 1; i <= M; i++) { v[i] += v[i - 1]; if (v[i] == 0) ok = ... |
#include <bits/stdc++.h> using namespace std; const int OO = 1e9, N = 1e5; int main() { long long n, c = 0, o = 0; cin >> n; string s; cin >> s; queue<int> q; for (int i = 0; i < n; i++) { o += (s[i] == ( ); c += (s[i] == ) ); } int sma7 = 0; for (int i = 0; i < n... |
#include <bits/stdc++.h> using namespace std; int n, a[100009], x[100009], h[100009], id[100009], seg[400009]; void upd(int pos, int l, int r, int pp, int v) { if (l == r) { seg[pos] = v; return; } int m = (l + r) / 2; if (m >= pp) upd(2 * pos + 1, l, m, pp, v); else up... |
#include <bits/stdc++.h> using namespace std; vector<int> g[100100]; pair<int, int> DFS(int now) { int all[2][2] = {}; int odd = 1, eve = 0, codd, ceve, todd, teve, csz, sw[2]; pair<int, int> tmp; all[0][0] = all[1][0] = 1; for (int i = 0; i < g[now].size(); i++) { tmp = DFS(g[now][i]); ... |
#include <bits/stdc++.h> using namespace std; int n; int arr[1005]; int res[1005]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n; for (int i = 0; i < n; ++i) cin >> arr[i]; sort(arr, arr + n); int ini = 0, fin = n - 1, idx = 0; while (ini <= fin) { res[idx] ... |
using namespace std; #include <cstdio> #include <cstring> #include <algorithm> #include <ctime> #include <cstdlib> #include <set> #include <map> #define N 1005 #define ll long long ll mul(ll a,ll b,ll mo){ a%=mo,b%=mo; ll c=a*b-(ll)((long double)a*b/mo)*mo; if (c<0) c+=mo; if (c>=mo) c-=... |
#include <bits/stdc++.h> using namespace std; const double eps = 1e-8; const double pi = acos(-1); const long long inf = 0x3f3f3f3f3f3f3f3f; const int INF = 0x3f3f3f3f; const int MAX = 2e5 + 10; const long long mod = 1e9 + 7; long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } ch... |
#include <bits/stdc++.h> using namespace std; const int maxn = 500005, INF = 0x3f3f3f3f; int ta, tb, n, T; long long t[maxn], t1[maxn]; int main(void) { cin >> n >> ta >> tb >> T; string s; char a; cin >> a; if (a == w ) T -= tb; T--; if (T < 0) { cout << 0 << endl; re... |
#include <bits/stdc++.h> using namespace std; bool dif[10]; int p[1005], n, x, y, ans1, ans2; inline void chk(int p) { int i, sz = 0, res; for (i = 1; i <= n; i++) { if (i & (1 << p)) { sz++; } } if (sz == 0) { dif[p] = 0; return; } printf( ? %d , sz); ... |
#include <bits/stdc++.h> using namespace std; string s; queue<char> q; vector<int> sp; int main() { long long n, l = 0, r = 0, k = 0; cin >> s; if (s[0] != a && s[0] != e && s[0] != u && s[0] != o && s[0] != i ) { q.push(s[0]); k = 1; } for (int i = 1; i < s.size(); i+... |
#include <bits/stdc++.h> using namespace std; int arr[100005]; int brr[100005]; char s[1234][1234]; int vis[1234][1234]; int has[1234][1234]; int f[1234567]; int n, m, c, g; void dfs(int x, int y) { if (x < 0 || y < 0 || x == n || y == m || vis[x][y] || s[x][y] == * ) return; if (s[x][y] == ... |
#include <iostream> #include <string> #include <vector> constexpr int N = 1000005; constexpr int p = 1000000007; inline int add(int x, int y) { return (x += y) >= p ? x - p : x; } inline int sub(int x, int y) { return (x -= y) < 0 ? x + p : x; } inline int mul(int x, int y) { return (long long)x * y... |
#include <bits/stdc++.h> int a[] = {0, 2, 3, 5, 7, 13, 17, 19, 31, 61, 89, 107, 127, 521, 607, 1279, 2203, 2281, 3217, 4253, 4423, 9689, 9941, 11213, 19937, 21701, 23209, 44497, ... |
#include <bits/stdc++.h> using namespace std; vector<string> split(const string& s, char c) { if (s.length() == 0) return vector<string>(); vector<string> v; stringstream ss(s); string x; while (getline(ss, x, c)) { v.emplace_back(x); } return std::move(v); } vector<int> splitI... |
#include <bits/stdc++.h> using namespace std; int compare(const void* x1, const void* x2) { return (*(int*)x1 - *(int*)x2); } int main() { int n, a; cin >> n >> a; int k = n / 2; if (a % 2 == 1) cout << a / 2 + 1; else cout << (k - a / 2 + 1); return 0; } |
#include <bits/stdc++.h> using namespace std; int n, x, y, d, T; int main() { cin >> T; while (T--) { cin >> n >> x >> y >> d; int sum; if ((abs(y - x)) % d == 0 || (n - y) % d == 0 || (y - 1) % d == 0) { if ((abs(y - x)) % d == 0) sum = (abs(y - x)) / d; else {... |
#include <bits/stdc++.h> using namespace std; int main() { char s[100001]; int a[100001], m, l, r; scanf( %s%d , s, &m); int len = strlen(s); a[1] = 0; for (int i = 1; i < len; ++i) { if (s[i] == s[i - 1]) { a[i + 1] = a[i] + 1; } else { a[i + 1] = a[i]; } ... |
#include <bits/stdc++.h> using namespace std; inline int read() { static char buf[1 << 21], *p1, *p2; int f = 0, c = 1; char ch = (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2) ? EOF : *p1++); while (ch < 0 || ch > 9 ) { if (ch == ... |
#include <bits/stdc++.h> using namespace std; int vocala(char c) { if (c == a || c == A || c == e || c == E || c == i || c == I || c == o || c == O || c == u || c == U ) return 1; if (c == y || c == Y ) return 1; return 0; } int isprime(long long n) { if (n <=... |
#include <bits/stdc++.h> using namespace std; template <class T> using vv = vector<vector<T>>; template <class T> ostream &operator<<(ostream &os, const vector<T> &t) { os << { ; for (int(i) = 0; (i) < (t.size()); ++(i)) { os << t[i] << , ; } os << } << endl; return os; } tem... |
#include <bits/stdc++.h> using namespace std; int main() { int n, p; cin >> n >> p; string s; cin >> s; if (p > s.length() / 2) { reverse(s.begin(), s.end()); p = (n - p) + 1; } int sum = 0; int t[n], l = -1, r = 0; for (int i = 0; i < s.length() / 2; i++) { if ... |
#include <bits/stdc++.h> using namespace std; int main() { long long a, b, c, d, x, y, g, h, i, j, k, n, t, z = 0, l, r, u; cin >> t; while (t--) { cin >> n; for (i = 0; i < n; i++) cout << 1 << ; cout << endl; } } |
#include<bits/stdc++.h> #define mp make_pair #define pr pair<int,int> #define pb push_back using namespace std; int k[100005],all[200005]; vector<int>a[100005]; struct nd{ int val,id; nd(){} nd(int val,int id):val(val),id(id){} bool operator <(const nd &x)const{ return val<x.val; } };... |
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 100; vector<int> v[maxn], w[maxn]; long long a[maxn]; bool d[maxn]; long long c[maxn][5]; long long n, m; bool mark[maxn][2]; void dfs1(long long i) { c[i][0] = 1; mark[i][0] = 1; for (long long y = 0; y < v[i].size(); y+... |
#include <bits/stdc++.h> using namespace std; int n, p1, p2, tot1, tot2; long long L, W, ans, a[100005], b[100005]; int main() { scanf( %d%lld%lld , &n, &L, &W); long long t; int v; for (int i = 1; i <= n; ++i) { scanf( %lld%d , &t, &v); if (v == 1) a[++tot1] = t; else ... |
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; const long long N = 1e2 + 10; vector<long long> g[N]; void dfs(long long node, long long par, long long dd, vector<long long>& fre) { fre[dd]++; for (auto x : g[node]) if (x != par) dfs(x, node, dd + 1, fre); } long... |
#include <bits/stdc++.h> using namespace std; template <typename T1, typename T2> inline T1 max(T1 a, T2 b) { return a < b ? b : a; } template <typename T1, typename T2> inline T1 min(T1 a, T2 b) { return a < b ? a : b; } const char lf = n ; namespace ae86 { const int bufl = 1 << 15; cha... |
#include <bits/stdc++.h> using namespace std; long long price[200002]; long long a, b, x, y, k; long long gcd(long long aa, long long bb) { return (bb != 0) ? gcd(bb, aa % bb) : aa; } bool check(long long mid) { long long tt = mid / (a * b / gcd(a, b)); long long ta = mid / a; long long tb =... |
#include <bits/stdc++.h> using namespace std; const long long mod = 998244353; const long long N = 2005; long long n, K, ans, sum, sum2, f[N][N], g[N]; long long kuai(long long a, long long b) { if (b == 0) return 1ll; if (b == 1) return a; long long x = kuai(a, b / 2); if (b % 2 == 0) return ... |
#include <bits/stdc++.h> using namespace std; int main() { string ss[100]; int n, ans = 0, cur; cin >> n; for (int i = 0; i < n; i++) cin >> ss[i]; for (char a = a ; a <= z ; a++) for (char b = a ; b <= z ; b++) { cur = 0; for (int i = 0; i < n; i++) { int l =... |
#include <bits/stdc++.h> using namespace std; using namespace std; int main() { int N; cin >> N; int suma = 0; vector<int> a(N); for (int i = 0; i < N; ++i) { cin >> a[i]; suma += a[i]; } if (suma == 1) { cout << -1 << endl; } else { long long answer = LONG_... |
#include <bits/stdc++.h> using namespace std; const long long DIM = 2e5 + 7; long long n, used[27][DIM], a[DIM], tests; int in; int main() { in = scanf( %lld , &tests); for (long long test = 1; test <= tests; test++) { in = scanf( %lld , &n); long long result = 0; for (long long i = ... |
#include <bits/stdc++.h> using namespace std; const int INF = INT_MAX / 3; const double EPS = 1e-14; template <typename U, typename T> void chmin(U &x, T y) { x = min(x, y); } template <typename U, typename T> void chmax(U &x, T y) { x = max(x, y); } const long long int PRIMEMAX = 1e6; lon... |
#include <bits/stdc++.h> using namespace std; void Get(int &T) { char C; bool F = 0; for (; C = getchar(), C < 0 || C > 9 ;) if (C == - ) F = 1; for (T = C - 0 ; C = getchar(), C >= 0 && C <= 9 ; T = T * 10 + C - 0 ) ; F && (T = -T); } int N, M; int X[10005]; int Y[1... |
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 6; int n, m, a[N]; int main() { int x[3], y[3]; cin >> x[0] >> y[0] >> x[1] >> y[1] >> x[2] >> y[2]; int len[3] = {(x[1] - x[0]) * (x[1] - x[0]) + (y[1] - y[0]) * (y[1] - y[0]), (x[2] - x[0]) * (x[2] - x[0]) + (y[2] ... |
#include <bits/stdc++.h> using namespace std; char f[1111][1111]; bool black[1111][1111]; bool is_free(int i, int j) { return f[i][j] != . && (f[i][j] < a || f[i][j] > d ); } bool can_hor(int i, int j) { return (is_free(i, j) && is_free(i, j + 1) && is_free(i, j + 2)) && !black[i][j]... |
#include <bits/stdc++.h> using namespace std; const long long INF = 1000000000 + 7; const double esp = 1e-13; const double pi = 3.141592653589; int n, m, f[100 + 10][100 + 10]; char a[100 + 10][100 + 10]; int main() { ios ::sync_with_stdio(false); cin >> n >> m; for (int i = (1), _b = (n); i <... |
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; int n, a[N], to[N]; vector<int> idx[N]; int is[N]; bool ok() { for (int i = 0; i < n; ++i) is[a[i]] ^= 1; bool prv = 0; for (int i = 1; i <= n; ++i) { if (!is[i]) continue; if (prv) return 0; prv = 1; } ... |
#include <bits/stdc++.h> using namespace std; const int mod = 51123987; char str[152]; int a[152]; int dp[152][52][52][52]; int nxt[152][3]; signed main() { int n; scanf( %d , &n); cin >> str + 1; for (int i = 1; i <= n; i++) a[i] = str[i] - a ; nxt[n + 1][0] = nxt[n + 1][1] = nxt[n +... |
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 10, size = 1 << 20, mod = 998244353, inf = 2e9; const long long INF = 1e15; template <class o> void qr(o& x) { char c = getchar(); x = 0; int f = 1; while (!isdigit(c)) { if (c == - ) f = -1; c = getchar(); } ... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int t; cin >> t; while (t--) { long long int n; cin >> n; long long int ar[n]; for (int i = 0; i < n; i++) cin >> ar[i]; for (int i = n - 1; i >= 0;... |
#include <bits/stdc++.h> using namespace std; const int maxn = 5e3 + 10; long long a[maxn], pre[maxn]; long long dp[maxn][maxn]; int main() { int n, m, k; while (~scanf( %d%d%d , &n, &m, &k)) { for (int i = 1; i < n + 1; i++) { scanf( %lld , &a[i]); pre[i] = pre[i - 1] + a[i]; ... |
#include <bits/stdc++.h> using namespace std; const int M = 110; const int inf = 1000000000; int main() { int n, m, g[M][M] = {0}; double f[M][M] = {0.0}; cin >> n >> m; for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { g[i][j] = inf; f[i][j] = 0; } ... |
#include <bits/stdc++.h> using namespace std; char op[20]; char s[205]; int main() { int n, m, k; scanf( %d%d%d , &n, &m, &k); getchar(); cin.getline(op, 15); int dir; if (op[3] == h ) { dir = 0; } else { dir = 1; } scanf( %s , s); int dir2 = m < k ? 0 : 1; ... |
#include <bits/stdc++.h> using namespace std; using ll = long long; const int Inf = 1e9 + 5; int main() { cin.tie(0); ios_base::sync_with_stdio(0); int t; cin >> t; while (t--) { int n; cin >> n; vector<int> a(n); ll sum = 0; for (int i = 0; i < n; i++) { ... |
#include <bits/stdc++.h> using namespace std; constexpr int kN = int(2E5 + 10), kInf = int(1E9 + 10), kC = int(1E6 + 10); struct seg_tree { long long int val[kN << 2], flag[kN << 2]; void init() { memset(val, 0, sizeof(val)); memset(flag, 0, sizeof(flag)); return; } void addtag(i... |
#include <bits/stdc++.h> using namespace std; int n, a[25], d[25][25], f[1 << 25], ans = INT_MAX; int popcnt(int x) { int cnt = 0; while (x > 0) cnt += (x & 1), x >>= 1; return cnt; } int main() { cin >> n; for (int i = 0; i < n; ++i) { cin >> a[i]; for (int j = 0; j < i; ++j) ... |
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const double pi = 3.1415926535897932384626; inline long long read() { long long x = 0, f = 1; char ch = getchar(); while (ch < 0 || ch > 9 ) { if (ch == - ) f = -1; ch = getchar(); } while (ch >= 0 &&... |
#include <bits/stdc++.h> using namespace std; int main() { int ppl, s = 0, maxn = 0; cin >> ppl; int wel[ppl]; for (int j = 0; j < ppl; j++) { cin >> wel[j]; if (maxn < wel[j]) { maxn = wel[j]; } } for (int i = 0; i < ppl; i++) { s = s + maxn - wel[i]; } ... |
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 10, size = 1 << 20; template <class o> void qr(o &x) { char c = getchar(); x = 0; int f = 1; while (!isdigit(c)) { if (c == - ) f = -1; c = getchar(); } while (isdigit(c)) x = x * 10 + c - 0 , c = getchar(); ... |
#include <bits/stdc++.h> int H[10]; int main() { memset(H, 0, sizeof(H)); for (int _n = 6, i = 0; i < _n; i++) { int v; scanf( %d , &v); H[v]++; } bool n6, n4, n5, n2; n6 = n4 = n5 = n2 = false; for (int _n = 10, i = 0; i < _n; i++) if (H[i] == 4) n4 = true; ... |
#include <bits/stdc++.h> using namespace std; int main() { long long int n, m, k; cin >> n; long long int a[n], b[n], c[n]; for (int i = 0; i < n; i++) { cin >> a[i]; b[i] = 1; c[i] = 1; } long long int ans = 1; for (int i = 1; i < n; i++) { if (a[i] > a[i - 1]) b... |
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; int i; map<string, string> mp1to2; map<string, string> mp2to1; map<string, int> mp1p; map<string, int> mp2p; for (i = 1; i <= m; i++) { string w1, w2; cin >> w1 >> w2; mp1to2[w1] = w... |
#include <bits/stdc++.h> using namespace std; long long fact(long long n) { if (n == 0 || n == 1) return 1; else return n * fact(n - 1); } long long gcd(long long a, long long b) { if (a < 0) a = -a; if (b < 0) b = -b; if (a == 1 || b == 1) return 1; else if (a == 0) ... |
#include <bits/stdc++.h> int main() { int n, x = 0; char arra[10]; scanf( %d , &n); for (int i = 0; i < n; i++) { scanf( %s , arra); if (arra[0] == + || arra[1] == + ) x = x + 1; else if (arra[0] == - || arra[1] == - ) x = x - 1; } printf( %d n , x); }... |
#include <bits/stdc++.h> using namespace std; int n, k; vector<pair<long long, long long> > nums; int main() { cin >> n; nums.resize(n); for (int i = 0; i < n; i++) { long long a, b; cin >> a >> b; nums[i] = make_pair(b, a); } sort(nums.begin(), nums.end()); long long r... |
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 100; int arr[maxn]; int cum[maxn], n, m, k; int dp[2020]; map<int, int> offer; int range(int l, int r) { return (cum[r] - cum[l]); } int solve(int i) { if (i == k) return 0; int &ret = dp[i]; if (ret != -1) return ret; ... |
#include <bits/stdc++.h> using namespace std; FILE *in = stdin; class node { public: long long sum[5], hnode; node() { sum[0] = sum[1] = sum[2] = sum[3] = sum[4] = hnode = 0; return; } node(int x) { for (int q = 0; q < 5; q++) { sum[q] = 0; } sum[0] = x; ... |
#include <bits/stdc++.h> using namespace std; struct point { double x, y; point(double _x = 0, double _y = 0) { x = _x; y = _y; } point operator+(point w) { return point(x + w.x, y + w.y); } point operator-(point w) { return point(x - w.x, y - w.y); } point operator*(double H) { ... |
#include <bits/stdc++.h> using namespace std; int n, m, nrh, nrt, nod1, nod2, d[100006], x, nr1, nr2, nra; vector<int> G[100006]; vector<int> sters; int uz[100006], uz2[100006]; int main() { int i, j, k; cin >> n >> m >> nrh >> nrt; for (i = 1; i <= m; i++) { cin >> nod1 >> nod2; G[n... |
#include <bits/stdc++.h> using namespace std; int i, j; int main() { int n, s, d, flag, last; cin >> n; cin >> s >> d; flag = s; n--; while (n--) { cin >> s >> d; while (flag >= s) s += d; flag = s; } cout << flag; } |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int q; cin >> q; unordered_map<string, string> gr; set<string> ending; for (int i = 0; i < q; i++) { string prev, next; cin >> prev >> next; gr[prev] = ... |
#include <bits/stdc++.h> using namespace std; const int MAXN = 510; const int MAXS = 110; const int MAXM = 1E5 + 10; const double EPS = 1E-8; int siz, n, m, k, ban[MAXN], pos[MAXN], U[MAXM], V[MAXM], d[MAXN], id[MAXN]; vector<int> G[MAXN]; struct Mat { double a[MAXS][MAXS]; Mat() { memset(a, 0, ... |
#include <bits/stdc++.h> using namespace std; const int N = 805; const int INF = 0x3f3f3f3f; int n, m, k, lim; struct Edge { int from, to, flow, cap; Edge(int f, int t, int fl, int c) : from(f), to(t), flow(fl), cap(c) {} }; struct EK { int n; vector<Edge> E; vector<int> g[N]; int ... |
#include <bits/stdc++.h> using namespace std; void solve() { int n, k; cin >> n >> k; long long a1[n], b1[n]; for (int i = 0; i < n; i++) cin >> a1[i] >> b1[i]; long long dp[n][k]; vector<long long> a, b; vector<pair<pair<long long, long long>, long long> > e; vector<long long> ans; ... |
#include <bits/stdc++.h> using namespace std; vector<long long int> v; long long int a[120100], n, dd; map<int, int> mp; int main() { for (long long int i = 1; i <= 2000000000; i *= 2) { v.push_back(i); } cin >> n; for (int i = 0; i < n; i++) { scanf( %lld , &a[i]); mp[a[i]]+... |
#include <bits/stdc++.h> using namespace std; struct node { long long a, b, c; } e[100005]; int cmp(node a, node b) { return a.c > b.c; } int main() { int n, f, i; cin >> n >> f; for (i = 1; i <= n; i++) { scanf( %lld%lld , &e[i].a, &e[i].b); if (e[i].a >= e[i].b) { e[i].c ... |
#include <bits/stdc++.h> using namespace std; const int MaxN = 100010; struct adjList { int id, nxt; } Lst[MaxN * 2]; int LCnt, Head[MaxN]; int N, w[MaxN], root; void addEdge(int a, int b) { Lst[LCnt].id = b; Lst[LCnt].nxt = Head[a]; Head[a] = LCnt++; } pair<long long, long long> dfs(i... |
#include <bits/stdc++.h> using namespace std; const int maxn = 1000000000; map<int, int> mp, mp2; map<int, int>::iterator it; int n, m; int tmp[3] = {2, 3, 5}, flag, t; void bfs(int val, int cnt) { queue<int> q; mp[val] = cnt; q.push(val); while (!q.empty()) { int x = q.front(); ... |
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long n, m, k; cin >> n >> m >> k; if (n > m) swap(n, m); set<long long> vals; for (long long i = 1; i <= n; ++i) { if (vals.count(n / i)) { for (long lo... |
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 5; const int Mod = 1000000007; const int INF = 0x3f3f3f3f; const long long LL_INF = 0x3f3f3f3f3f3f3f3f; const double e = exp(1); const double PI = acos(-1); const double ERR = 1e-10; int main() { long long n; scanf( %lld , &n... |
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 500; const int M = 1e6 + 500; const int INF = 0x3f3f3f3f; const int MOD = 1e9 + 7; const int BASE = 31337; const int LOG = 18; const int OFF = (1 << LOG); const double EPS = 1e-9; const double PI = 3.1415926535; int blok[M], n, bio[... |
#include <bits/stdc++.h> using namespace std; const long long o = 101; const long long p = 6e4; struct qwq { long long x, y; } a[o], b[o]; long long n, m, l, r, f[p + 1], ans = -1; bool cmp1(qwq u, qwq v) { return u.x == v.x ? u.y > v.y : u.x < v.x; } bool cmp2(qwq u, qwq v) { return u.x + u.y > v.x... |
#include <bits/stdc++.h> using namespace std; vector<int> g[5000]; int n, m; int c[100][100]; char t[100][100]; bool used[100][100]; char clr[5000]; bool valid(int i, int j) { return (0 <= i && i < n && 0 <= j && j < m); }; int di[4] = {-1, 1, 0, 0}; int dj[4] = {0, 0, -1, 1}; void dfs(int i, int ... |
#include <bits/stdc++.h> using namespace std; const int N = 1 << 22; int h, g; long long a[N]; vector<int> ans; int path[25]; long long pull(int u) { long long tp = a[u]; int cnt = 0; path[cnt++] = u; a[u] = 0; while ((u << 1) < (1 << h) && max(a[u << 1], a[(u << 1) | 1]) > 0) { ... |
#include <bits/stdc++.h> using namespace std; int cnt[27][1505]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); string s; int n, q, m; char c; cin >> n; cin >> s; for (int i = (0); i <= (25); i++) { char ch = i + a ; for (int j = (0); j <= (n - 1); j++) ... |
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1.0); const double eps = 1e-11; template <class T> inline void checkmin(T& a, T b) { if (b < a) a = b; } template <class T> inline void checkmax(T& a, T b) { if (b > a) a = b; } template <class T> inline T sqr(T x) { ... |
#include <bits/stdc++.h> using namespace std; int main() { int n, cnt; int i, ln, sz; string tx; vector<string> v; cin >> n; getchar(); getline(cin, tx); ln = tx.size(); int s = 0; for (i = 0; i < (ln); i++) if (tx[i] == . || tx[i] == ? || tx[i] == ! ) { v.... |
#include <bits/stdc++.h> using namespace std; long long mp[2050][2050]; int main() { for (int i = 0; i <= 1000; i++) { mp[i][0] = 1; mp[i][i] = 1; } for (int i = 0; i <= 1000; i++) { for (int j = 1; j < i; j++) { mp[i][j] = (mp[i - 1][j] + mp[i - 1][j - 1]) % 1000000007; ... |
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; const int N = 1e5 + 7, M = 1e7, OO = 0x3f3f3f3f; map<int, int> dp; int solve(int num) { if (num == 0) { return 0; } if (dp[num]) { return dp[num]; } vector<int> v; int temp = num; while (temp) ... |
#include <bits/stdc++.h> using namespace std; const int N = 5003; long long a[N + 2], x[N + 2], dp[N + 2]; int l[N + 2], r[N + 2], cnt[N + 2]; int main() { ios_base::sync_with_stdio(0); for (int i = 0; i <= N; i++) { l[i] = 1000000; } int n; cin >> n; for (int i = 0; i < n; i++) ... |
#include <bits/stdc++.h> struct Node { int sum, value; Node *ch[2], *p; __inline Node(int value = 0) : value(value) { sum = 1; ch[0] = ch[1] = p = NULL; } __inline void update() { sum = 1 + (ch[0] ? ch[0]->sum : 0) + (ch[1] ? ch[1]->sum : 0); } } pool[211111], *cur = pool; ... |
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e4 + 5; int a[MAXN]; int dp[MAXN][2005]; int solve(int n) { int len = 2005; for (int i = 1; i <= n; ++i) for (int j = 0; j < len; ++j) dp[i][j] = INT_MAX; for (int j = 0; j < len; ++j) dp[0][j] = j; for (int i = 1; i <= n; +... |
#include <bits/stdc++.h> using namespace std; const int maxn = (int)1e5 + 1; char s[maxn]; const int ci = 26; struct vertex { vertex *go[ci]; vertex *suf; bool term; int len; int d[2]; vertex(int _len = 0) : suf(0), term(0), len(_len) { for (int i = 0; i < ci; i++) go[i] = 0; ... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long tc; cin >> tc; while (tc--) { long long n, m; cin >> n >> m; vector<long long> p(n); for (long long z = 0; (1 > 0 and z < n) or (1 < 0... |
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 50; long long a[MAXN], b[MAXN], dp[MAXN]; long long la[MAXN], lb[MAXN]; int sz, cur, n; double cross(int x, int y) { return (double)(lb[x] - lb[y]) / (la[y] - la[x]); } void newLine(long long p, long long q) { la[sz] = p; lb[sz] ... |
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int tc; cin >> tc; while (tc--) { int n, m, x1, y1, x2, y2, w, h; cin >> n >> m >> x1 >> y1 >> x2 >> y2 >> w >> h; int right = n - x2; int left = x1; int up = m... |
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; vector<int> E; vector<int> a[N]; int value[N]; long long down[N]; long long max_path[N]; int n; long long calc_down(int edge_index) { long long &ans = down[edge_index]; if (ans != -1) return ans; int v = E[edge_index]; ... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n, m; cin >> n >> m; vector<int> v(n), inc(n, -1), dec(n, n - 1); for (int i = 0; i < n; i++) { cin >> v[i]; if (i > 0) { if (v[i] > v[i - 1]) inc[i] = i... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); int n, b, a; cin >> n >> b >> a; int a_cap = a; int x, c = 0; while (a + b) { cin >> x; if (!x) { if (a) a--; else b--; ... |
#include <bits/stdc++.h> using namespace std; int main() { int n; string l; cin >> n; for (int i = 0; i < n; i++) { cin >> l; int a = l.length(); if (a > 10) { cout << l[0] << a - 2 << l[a - 1] << endl; } else { cout << l << endl; } } return 0; ... |
#include <bits/stdc++.h> using namespace std; auto fastio = (ios::sync_with_stdio(false), cin.tie(nullptr)); void solve() { long long n, m; cin >> n >> m; string s; cin >> s; vector<long long> p(m); for (long long i = 0; i < (m); ++i) { cin >> p[i]; } sort((p).begin(), (p).en... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.