solution
stringlengths
53
181k
difficulty
int64
0
13
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1.0); const int mod = 1e9 + 7; void init() { ios_base::sync_with_stdio(false); std::cin.tie(NULL); } void solve() { long long n; cin >> n; long long cn = 1; long long arr[n][n]; for (int i = 0; i < n; i++) { if (i % 2 == 0) { ...
2
#include <bits/stdc++.h> using namespace std; const int N = 21; const int M = 1048577; const double eps = 1e-10; int n, k, cnt; double p[N], ans[N], f[M]; int check(int x) { int ret = 0; for (int i = 0; i < n; ++i) if (x & (1 << i)) ++ret; return ret; } int main() { scanf("%d%d", &n, &k); for (int i = 0; ...
8
#include <bits/stdc++.h> using namespace std; long long int mod = 1000000007; int main() { ios_base ::sync_with_stdio(false); cin.tie(NULL); long long int n; cin >> n; if (n == 1) { cout << 2; return 0; } if (n == 2) { cout << 3; return 0; } long long int curr = 2, line = 3, to = 2; ...
1
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 10; int N; char op[maxn]; int vis[maxn * 2]; int solve_0() { int pos = 0; vis[maxn + pos] = 1; for (int i = 1; i <= N; ++i) { if (op[i] == 'R') ++pos; else --pos; ++vis[maxn + pos]; } return vis[maxn + pos] > 1 ? 0 : ...
7
#include <bits/stdc++.h> using namespace std; int t, a, b, c; int main() { cin >> t; for (; t; t--) { cin >> a >> b >> c; int res = 0; if (c >= b) { swap(b, c); } if (b >= a) { swap(a, b); } if (c > 0) { c--; res++; } if (b > 0) { b--; res++; ...
0
#include <bits/stdc++.h> using namespace std; const int M = 5e5 + 5; int n, m, x; map<int, int> a; struct cinema { int cnt, sum1, sum2; } ans[M]; bool cmp(cinema a, cinema b) { if (a.sum1 == b.sum1) return a.sum2 > b.sum2; else return a.sum1 > b.sum1; } int main() { scanf("%d", &n); for (int i = 1; i ...
2
#include <bits/stdc++.h> using namespace std; int n, x, y; void solve(int val) { val %= x + y; long long lb = 0, rb = (long long)x * y; while (lb <= rb) { long long mid = (rb - lb) / 2 + lb; long long hit = mid / x + mid / y; if (hit >= val) rb = mid - 1; else lb = mid + 1; } int f...
5
#include <bits/stdc++.h> using namespace std; int main() { int h, m; int add; scanf("%d:%d%d", &h, &m, &add); int tm = (h * 60 + m + add) % (24 * 60); printf("%02d:%02d\n", tm / 60, tm % 60); return 0; }
0
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 2; const int M = 1e5 + 2; const int mod = 1e9 + 7; const int inf = 1e9; const long long INF = 1e18; void data() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); } int n, m, p[2 * N], ans[2 * N], t[8 * N]; pair<pair<int, int>, int> k[2 * N]; pair<...
5
#include <bits/stdc++.h> using namespace std; int n, m, ans, c[10]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> m; int a[m], b[m]; for (int i = 0; i < m; i++) { cin >> a[i] >> b[i]; if (c[b[i] - 1] == 0) { c[b[i] - 1] = i + 1; } else { a[c[b[i] - 1] - 1] += a[i];...
0
#include <bits/stdc++.h> using namespace std; using ll = long long; using vi = vector<int>; using vvi = vector<vi>; using vll = vector<ll>; using vvll = vector<vll>; using vb = vector<bool>; using vd = vector<double>; using vs = vector<string>; using pii = pair<int, int>; using pll = pair<ll, ll>; using pdd = pair<doub...
8
#include <bits/stdc++.h> #pragma GCC optimize(2) #pragma G++ optimize(2) using namespace std; const int maxn = 1e4 + 5; int n, a[maxn]; bool check(int x) { bitset<2005> dp, tmp; for (int i = 0; i <= x; ++i) dp[i] = 1; tmp = dp; for (int i = 1; i <= n; ++i) { dp = (dp << a[i]) | (dp >> a[i]); dp &= tmp; ...
7
#include <bits/stdc++.h> using namespace std; int tt(int n) { int c = 0; while (n) { n >>= 1; c++; } return c; } int main() { int n; cin >> n; cout << tt(n) << endl; }
2
#include <bits/stdc++.h> using namespace std; int color[1000000]; bool flag = true; vector<vector<int> > g; void dfs(int v, int prevColor) { int curColor = 3 - prevColor; color[v] = curColor; for (int i = 0; i < g[v].size(); i++) { if (color[g[v][i]] == curColor) { flag = false; } else { if (c...
3
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); char c; cin >> c; while (1) { if (c == '1') { if (!(cin >> c)) break; if (c == '4') { if (!(cin >> c)) break; if (c == '4') { if (!(cin >> c)) break; } ...
0
#include <bits/stdc++.h> using namespace std; struct op { int id, t; long long b; bool operator<(const op &o) const { return b > o.b; } }; struct ov { double delta; int id; bool operator<(const ov &o) const { return delta > o.delta; } }; vector<op> v[100005]; long long oval[100005]; int k, n, m; vector<ov> ...
10
#include <bits/stdc++.h> using namespace std; const int INF = 2e9; const int maxN = 1e5 + 69; struct segment { int l, r, p; bool operator<(const segment& oth) const { return l < oth.l; } }; int n, m, k; vector<segment> vec; struct PersistentSegmentTree { static const int maxNodes = maxN * 19; struct Node { ...
8
#include <bits/stdc++.h> using namespace std; const int N = 100; const int K = 1e4; const int INF = 0x3f3f3f3f; int n, st, k, f[N + 10][K + 10]; char s[N + 10]; struct data { int va, x; } a[N + 10]; bool cmp(data p, data q) { return p.va < q.va; } int Abs(int x) { return (x < 0) ? (-x) : x; } int main() { scanf("%d...
6
#include <bits/stdc++.h> int markk[200000], n, len[200000]; char mapp[200000]; int fin(int i) { int x; if (i >= n || i < 0) { return 0; } if (markk[i] == 1) { return 1; } markk[i] = 1; if (mapp[i] == '>') { return fin(i + len[i]); } if (mapp[i] == '<') { return fin(i - len[i]); } } i...
1
#include <bits/stdc++.h> using namespace std; const int MOD = 119 << 23 | 1; const int FFTMOD = 119 << 23 | 1; const int INF = (int)1e9 + 23111992; const long long LINF = (long long)1e18 + 23111992; const long double PI = acos((long double)-1); const long double EPS = 1e-9; inline long long gcd(long long a, long long b...
10
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1); const double eps = 1e-8; const int maxn = 205; int x[maxn], y[maxn]; struct Matrix { double a[maxn][maxn]; void init() { memset(a, 0, sizeof(a)); for (int i = 0; i < maxn; ++i) { a[i][i] = 1; } } } P[14]; Matrix mul(Matrix...
9
#include <bits/stdc++.h> using namespace std; const int MAX_N = 1e6 + 6; const int P1 = 792924877; const int P2 = 1017450191; const int P3 = 614677073; const int P4 = 809880751; const int P5 = 1061596561; const int DIGIT = 401016061; struct HASH { const int MOD; long long p[MAX_N], h[MAX_N], rh[MAX_N]; HASH() = d...
3
#include <bits/stdc++.h> using namespace std; int dx[] = {0, 0, 1, -1, -1, -1, 1, 1}; int dy[] = {1, -1, 0, 0, -1, 1, 1, -1}; template <class T> inline T biton(T n, T pos) { return n | ((T)1 << pos); } template <class T> inline T bitoff(T n, T pos) { return n & ~((T)1 << pos); } template <class T> inline T ison(T n...
0
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c; cin >> a >> b >> c; cout << (b == a || c != 0 && (b - a) % c == 0 && (b - a) / c >= 0 ? "YES" : "NO"); }
1
#include <bits/stdc++.h> using namespace std; int N, K; int A[200]; int inside[200], outside[200]; int main(int argc, char** argv) { std::ios::sync_with_stdio(false); cin >> N >> K; int mx = -100000; for (int i = 0; i < N; i++) { cin >> A[i]; mx = max(mx, A[i]); } int ans; if (mx <= 0) { ans =...
3
#include <bits/stdc++.h> using namespace std; const int maxn = (int)1e5 + 100; const int mod = (int)1e9 + 7; const int P = (int)1e6 + 7; int n, cnt[33], dp[2666][2666]; pair<int, int> par[2666][2666]; char second[maxn]; int calc(int l, int r) { if (l > r) return 0; if (l == r) return 1; int &res = dp[l][r]; if ...
5
#include <bits/stdc++.h> using namespace std; const long long INF = 0x1fffffffffffffff; const double INFD = 1e20; const double EPS = 1e-9; const double PI = atan(1) * 4; const long long M = 1000000007; long long scan() { long long r; scanf("%lld", &r); return r; } void scanstr(char *buf) { scanf("%s", buf); } voi...
10
#include <bits/stdc++.h> using namespace std; const int N = 5005; int a[N], L[N], R[N], f[N]; bool st[N]; int main() { int n; scanf("%d", &n); for (int i = 1; i <= n; ++i) { scanf("%d", &a[i]); if (!L[a[i]]) L[a[i]] = i; R[a[i]] = i; } for (int i = 1; i <= n; ++i) { for (int j = 0; j <= N - 1;...
5
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 5; struct node { int banfcc; int t; }; queue<node> q; vector<int> v; map<pair<int, int>, int> mp; int main() { int n, k; cin >> n >> k; for (int i = 1; i <= k; i++) { int x; scanf("%d", &x); v.push_back(x); } sort(v.begin(), ...
7
#include <bits/stdc++.h> using namespace std; const int MAXN = 200100; const int MAXP = 2000100; const long long MOD = 1e9 + 7; int N; int pprime[MAXP]; int arr[MAXN]; int pord[MAXN]; map<int, int> pv; map<int, int> nd; int nvp[MAXP]; int nf[MAXP]; int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); cin >> ...
10
#include <bits/stdc++.h> using namespace std; using ll = long long; using vi = vector<int>; using pi = pair<int, int>; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ; int n; cin >> n; if (n % 2 == 0) { cout << "home" << endl; } else { cout << "contest" << endl; ...
0
#include <bits/stdc++.h> using namespace std; const int MOD = 1000000007; struct Modint { int val; Modint(int new_val = 0) { val = new_val; } Modint operator+(Modint r) { return (val + r.val) % MOD; } Modint operator-(Modint r) { return (val + MOD - r.val) % MOD; } Modint operator*(Modint r) { return 1LL * va...
8
//#include <bits/stdc++.h> #include<cstdio> #include<cstring> #include<algorithm> #include<iostream> #include<string> #include<vector> #include<stack> #include<bitset> #include<cstdlib> #include<cmath> #include<set> #include<list> #include<deque> #include<map> #include<queue> #define ll long long #define LL long long ...
0
#include <bits/stdc++.h> using namespace std; const int MOD = (int)1e9 + 7; const int INF = (int)1e9; const long long LINF = (long long)1e18; const long double PI = acos((long double)-1); const long double EPS = 1e-9; long long gcd(long long a, long long b) { if (a < b) swap(a, b); long long r; while (b) { r ...
5
#include <bits/stdc++.h> using namespace std; long long in[100005]; set<long long> S; int n, k; int main() { cin >> n >> k; for (int i = 0; i < n; i++) { scanf("%I64d", &in[i]); } int ans = 0; sort(in, in + n); for (int i = 0; i < n; i++) { if (in[i] % k != 0 || (in[i] % k == 0 && S.find(in[i] / k) ...
3
#include <bits/stdc++.h> using namespace std; int main() { int num; long long int temp; vector<long long int> vi; scanf("%d", &num); set<int> st; for (int i = 0; i < num; i++) { scanf("%lld", &temp); st.insert(temp); } for (set<int>::iterator it = st.begin(); it != st.end(); it++) vi.push_ba...
3
#include <bits/stdc++.h> using namespace std; int main() { string s; int k; cin >> s >> k; vector<int> B(26, 0); vector<pair<int, int> > A(26, make_pair(0, 0)); for (int i = 0; i < 26; i++) { A[i].first = 0; A[i].second = -1; } for (int i = 0; i < s.length(); i++) { A[s[i] - 'a'].first++; ...
2
#include <bits/stdc++.h> using namespace std; stack<vector<string> > st; char inp[200]; string modify() { int j = 0, len = strlen(inp); string ret = ""; for (j = 0; j < len; j++) { if (inp[j] == '(' || inp[j] == ')' || inp[j] == ',' || inp[j] == '\"') { ret += " "; } else ret += inp[j]; } ...
5
#include <bits/stdc++.h> using namespace std; const int N = 1010; const int M = 55; const int K = 26; const int Inf = 1e8; template <class c> struct rge { c b, e; }; template <class c> rge<c> range(c i, c j) { return rge<c>{i, j}; } template <class c> auto dud(c* x) -> decltype(cerr << *x, 0); template <class c> ch...
6
#include <bits/stdc++.h> using namespace std; int n; bool A[2010][2010]; bool B[2010][2010]; int C1[2010], C2[2010]; int C11[2010], C22[2010]; int D[2010]; int S, S1; void load() { cin >> n; string T; for (int i = 1; i <= n; ++i) { cin >> T; for (size_t j = 0; j < T.size(); ++j) if (T[j] == '1') A[i...
6
#include <bits/stdc++.h> using namespace std; int main() { int i, n, m, len, a, b, ans, ansa = 0, ansb = 0; char s[200005]; scanf("%d", &n); scanf("%s", s); len = strlen(s); for (auto i = 0; i < len; i++) { if (s[i] == '<') ansa++; else break; } for (auto i = len - 1; i > -1; i--) { ...
1
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n, x; int a1 = 0; int a2 = 0; int flag1 = 0; int flag2 = 0; cin >> n; int h[101]; memset(h, 0, sizeof(h)); for (int i = 0; i < n; i++) { cin >> x; h[x]++; } for (in...
0
#include <bits/stdc++.h> using namespace std; int cnt; int v[1000001]; int siz[1000001]; vector<int> e[1000001]; int dp[1000001]; void get_siz(int u) { if (e[u].empty()) siz[u] = 1; for (int i = 0; i < e[u].size(); i++) { get_siz(e[u][i]); siz[u] += siz[e[u][i]]; } } int dfs(int u) { if (e[u].empty()) r...
5
#include <bits/stdc++.h> using namespace std; int main() { string str; int i, a, num = 0; cin >> a; cin >> str; for (i = 1; i < a - 1; i++) { if (str[i] == 'x') { if ((str[i + 1] == 'x') && (str[i - 1] == 'x')) { num++; } } } cout << num << endl; return 0; }
0
#include <bits/stdc++.h> int m, n, c[40]; int main() { scanf("%d%d", &m, &n); for (int i = 1; i <= n; i++) { puts("1"); fflush(stdout); int t; scanf("%d", &t); if (t == 0) return 0; if (t == -1) c[i] = -1; else c[i] = 1; } int low = 1, up = m, mid; int i = 1; while (1...
5
#include <bits/stdc++.h> using namespace std; const int NMAX = 105, MMAX = 1e4 + 5; int n, m; string table[NMAX]; int idx[NMAX][MMAX]; int main() { cin >> n >> m; for (int r = 0; r < n; ++r) { cin >> table[r]; memset(idx[r], MMAX, sizeof(idx[r])); int c; for (c = 0; c < m; ++c) { if (table[r][...
3
#include <bits/stdc++.h> int min(int a, int b) { return a < b ? a : b; } int *ej[100000], eo[100000], *ej_[100000], eo_[100000], *dp[100000], deg[100000], n; void append(int i, int j) { int o = eo[i]++; if (o >= 2 && (o & o - 1) == 0) ej[i] = (int *)realloc(ej[i], o * 2 * sizeof *ej[i]); ej[i][o] = j; } c...
13
#include <bits/stdc++.h> const long long M = 1e9 + 7; const double pi = 3.14159265358979323846; using namespace std; vector<long long> adj[100005]; signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long t = 1; cin >> t; while (t--) { long long n; cin >> n; lon...
2
#include <bits/stdc++.h> #pragma GCC optimize("O3", "unroll-loops") #pragma GCC target("avx2") using namespace std; template <class T, class U> inline void checkmin(T& x, U y) { if (y < x) x = y; } template <class T, class U> inline void checkmax(T& x, U y) { if (y > x) x = y; } template <class T, class U> inline b...
0
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx,avx2") using namespace std; template <class T> bool umin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } template <class T> bool umax(T& a, T b) { if (a < b) { a = b; return 1; } ...
10
#include <bits/stdc++.h> using namespace std; int main() { float l, d, v, g, r, t = 0, x, y, z, z2; cin >> l >> d >> v >> g >> r; if (d == l) t = t + (l / v); else { t = t + (d / v); l = l - d; x = t; while (x > 0) { y = x; x = x - g; if (x > 0) { y = x; x =...
3
#include <bits/stdc++.h> #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") using namespace std; mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); void ioi(string name) { freopen((name + ".in")....
1
#include <bits/stdc++.h> using namespace std; int main() { string s; int flag = 0, counter = 0; int a[20] = {2, 4, 3, 9, 5, 25, 7, 49, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53}; for (int i = 0; i < 20; i++) { cout << a[i] << endl; fflush(stdout); cin >> s; if (s == "ye...
3
#include <bits/stdc++.h> using namespace std; int main() { int t = 1; while (t--) { int k = 0; cin >> k; if (k > 36) cout << -1 << endl; else { while (k > 1) { cout << 8; k -= 2; } if (k == 1) cout << 4; } cout << endl; } }
2
#include <bits/stdc++.h> using namespace std; set<int> v[200005]; int x[200005]; int y[200005]; int an[200005]; set<pair<int, int> > s; void r(int i, int k) { if (v[x[i]].size() >= k && v[y[i]].size() >= k) { s.erase(pair<int, int>(v[x[i]].size(), x[i])); s.erase(pair<int, int>(v[y[i]].size(), y[i])); v[x...
7
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 6; struct node { int n4, n7, n47, n74, lazy; }; node it[N << 2]; int n, m; string s; void build(int k, int l, int r) { if (l == r) { if (s[l - 1] == '4') it[k].n4 = 1; if (s[l - 1] == '7') it[k].n7 = 1; it[k].n47 = it[k].n74 = 1; retu...
8
#include <bits/stdc++.h> using namespace std; int main(void) { long long x1, y1, x2, y2, x3, y3; cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3; for (int i = 0; i < 4; i++) { long long dx = x2 - x1; long long dy = y2 - y1; long long u = dx * x3 + dy * y3; long long v = dx * y3 - dy * x3; long long w ...
6
#include <bits/stdc++.h> using namespace std; vector<int> zeroes; int binarySearch(int p, int low, int high) { int ans = INT_MAX; while (low <= high) { int mid = (low + high) >> 1; ans = min(ans, abs(p - zeroes[mid])); if (zeroes[mid] > p) { high = mid - 1; } else if (zeroes[mid] < p) { ...
2
#include <bits/stdc++.h> using namespace std; int n, a[100000]; long long sum, suffsum, prefsum, ans; int suff[100001]; int main() { cin >> n; for (int i = 0; i < n; ++i) cin >> a[i], sum += a[i]; if (sum % 3) return !printf("0\n"); sum /= 3; for (int i = n - 1; i > -1; --i) { suffsum += a[i]; suff[i]...
6
#include <bits/stdc++.h> using namespace std; int q; int n; int idx[300005]; int l[300005]; int ans[300005]; int main() { scanf("%d", &q); while (q--) { scanf("%d", &n); int t; for (int i = 0; i <= n; i++) idx[i] = ans[i] = l[i] = 0; for (int i = 1; i <= n; i++) { scanf("%d", &t); l[t] =...
3
#include<bits/stdc++.h> using namespace std; const int M=998244353; const long long inf=101010101010101ll; const int N=1000005; int n,i,j,k,f[N],m,u,x[N],y[N],p[N],id[N]; struct str{ int u,v; }; vector<str> ans; int Find(int x) { return f[x]?f[x]=Find(f[x]):x; } void uniot(int x,int y) { int u=Find(x),v=Find(y); if...
11
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); ; string str; cin >> str; int ans = 0; int len = str.length(); for (int i = 0; i < len - 2; i++) { if (str[i] == 'A' && str[i + 1] == 'B' && str[i + 2] == 'C') ans = 1; if (str[i] == 'A' && st...
0
#include <bits/stdc++.h> int min(int a, int b) { if (a > b) return b; return a; } int a[1001][1001], b[1001], u, v, sum = 0; int main() { int n, m, i, j; scanf("%d%d", &n, &m); for (i = 1; i <= n; i++) { scanf("%d", &b[i]); } for (i = 0; i < m; i++) { scanf("%d%d", &u, &v); sum += min(b[u], b[...
3
#include <bits/stdc++.h> const int N = 2e4 + 10; int n, m; int a[N], b[N], used[2 * N]; int main() { scanf("%d", &n); for (int i = 1; i <= n; ++i) scanf("%d", &a[i]), used[a[i]] = 1; scanf("%d", &m); for (int i = 1; i <= m; ++i) scanf("%d", &b[i]), used[b[i]] = 1; for (int i = 1; i <= n; ++i) for (int j =...
0
#include <bits/stdc++.h> int main() { int a, b, r; scanf("%d %d %d", &a, &b, &r); if (a < 2 * r || b < 2 * r) printf("Second"); else printf("First"); return 0; }
4
#include <bits/stdc++.h> using namespace std; queue<int> q; int main() { long long int n, b, i, ans[200005]; long long int start[200005], timetaken[200005], a; scanf("%lld %lld", &n, &b); for (i = 0; i < n; i++) { scanf("%lld %lld", &start[i], &timetaken[i]); } long long int current = 0; i = 0; whil...
4
#include <bits/stdc++.h> using namespace std; int main() { int d1, d2, d3; scanf("%d%d%d", &d1, &d2, &d3); d3 = d3 > d1 + d2 ? d1 + d2 : d3; d1 = d1 > d2 + d3 ? d2 + d3 : d1; d2 = d2 > d1 + d3 ? d1 + d3 : d2; printf("%d\n", d1 + d2 + d3); return 0; }
0
#include <bits/stdc++.h> using namespace std; vector<int> e[1000010]; long long n, m; long long vis[1000010]; long long du[1000010]; long long c = 0; void dfs(int rt) { vis[rt] = 1; int Size = e[rt].size(); for (int i = 0; i < (Size); i++) { if (vis[e[rt][i]]) continue; dfs(e[rt][i]); } } int main() { ...
6
#include <bits/stdc++.h> using namespace std; const int N = 105; const int mod = 1e9 + 7; void pp(int& x, int y) { x += y; if (x >= mod) x -= mod; } int n; long long a[N]; long long k; struct Mat { int v[N][N]; Mat() { memset(v, 0, sizeof(v)); } Mat operator*(const Mat& c) const { Mat ans; for (int i ...
5
#include <bits/stdc++.h> using namespace std; char a[1001][1001]; int visit[1001][1001]; void dfs(int i, int j, int n, int m, int cc) { visit[i][j] = cc; if (i != 0 && a[i - 1][j] == '#' && visit[i - 1][j] == -1) dfs(i - 1, j, n, m, cc); if (j != 0 && a[i][j - 1] == '#' && visit[i][j - 1] == -1) dfs(i, j ...
6
#include <bits/stdc++.h> using namespace std; int arr[112345]; void init() {} void solve() { int n, h, k; scanf("%d%d%d", &n, &h, &k); for (int i = 0; i < n; i++) { scanf("%d", &arr[i]); } int left = 0; int idx = 0; long long ans = 0; int temp; while (idx < n || left > 0) { while (idx < n && l...
3
#include <bits/stdc++.h> using namespace std; int main() { int n, b, d, waste, ctr; cin >> n >> b >> d; int orange[n]; for (int i = 0; i < n; i++) cin >> orange[i]; waste = 0, ctr = 0; for (int i = 0; i < n; i++) { if (orange[i] > b) continue; else { waste += orange[i]; if (waste >...
0
#include <bits/stdc++.h> using namespace std; const int Maxn = 505; double PI = acos(-1), INF = 1e20, EPS = 1e-6; double g[Maxn][Maxn]; struct Point { double x, y; Point() {} Point(double tx, double ty) { x = tx; y = ty; } bool operator<(const Point &ta) const { return x <= ta.x; } Point operator-(c...
9
#include <bits/stdc++.h> using namespace std; void file_open() { freopen("test.txt", "rt", stdin); freopen("test.out", "wt", stdout); } void xuli1(char s[]) { int row, col; row = 0; col = 0; int i = 1; while (s[i] != 'C') { row = row * 10 + s[i] - 48; ++i; } ++i; while (s[i]) { col = col...
4
#include <bits/stdc++.h> using namespace std; const long long inf = 4e18; const long long maxn = 5010; const long long mod = 1e9 + 7; long long dp[30][maxn], tot[maxn], sm[maxn]; int main() { long long n; cin >> n; string s; cin >> s; for (int i = int(1); i <= int(n); i++) { long long c = s[i - 1] - 'a'; ...
8
#include <bits/stdc++.h> using namespace std; char str; int n; struct point { int a, b; friend bool operator<(point A, point B) { return A.b < B.b; } } p[204800]; long long tr[4 * 204800]; struct edge { int to; int nxt; long long val; } nd[2 * 204800]; int head[204800], cnt; int inval[204800]; long long dist[...
7
#include <bits/stdc++.h> using namespace std; struct node { int a, o, id; } s[300005]; bool vis[300005]; int cmp(node x, node y) { return x.a < y.a; } int main() { int T, n; long long suma, sumo, s1, s2; scanf("%d", &T); while (T--) { memset(vis, false, sizeof(vis)); suma = sumo = 0; scanf("%d", &...
8
#include <bits/stdc++.h> using namespace std; const long long maxn = 2e5 + 100; const long long mod = 1e9 + 7; const long long inf = 1e18; long long n, t, dp[maxn], c[maxn], s, ans; vector<long long> g[maxn]; long long pw(long long pa, long long push_back) { if (push_back == 0) return 1; long long pc = pw(pa, push_...
7
#include <bits/stdc++.h> using namespace std; const int MOD = 1000000007; struct Sync_stdio { Sync_stdio() { cin.tie(NULL); ios_base::sync_with_stdio(false); } } _sync_stdio; template <class T> class SegmentTree { int maxn = 1000000; vector<T> t; void build(const vector<T> &a, int v, int tl, int tr) {...
8
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e6 + 5; int lmin[MAXN], lmax[MAXN], rmin[MAXN], rmax[MAXN]; int n, c; int pos = 0; int ans[MAXN]; int ct; bool flag = true; void dfs(int largest) { int u = ++pos; if (n + 1 != lmin[u]) { if (lmin[u] <= pos) { flag = false; return; }...
8
#include <bits/stdc++.h> using namespace std; void solve() { int n; cin >> n; vector<int> dishes(n); for (auto &x : dishes) cin >> x, x -= 1; sort(dishes.begin(), dishes.end()); vector<vector<int>> dp(n, vector<int>(3 * n)); for (int i = 0; i < n; i++) dp[i][0] = 1e9; dp[0][0] = dishes[0]; for (int j ...
5
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; int l = s.size(); int len = 0; string ans = ""; for (int i = 0; i < l; i++) { len = ans.size(); if (s[i] == s[i - 1] && s[i] == s[i - 2]) { continue; } else if (len > 2 && (s[i] == ans[len - 1] &&...
3
#include <bits/stdc++.h> using namespace std; bool inside(string s, vector<long long> &l, vector<long long> &r) { stringstream ss(s); long long cur; ss >> cur; int sz = l.size(); for (int i = 0; i < sz; i++) if (l[i] <= cur && cur <= r[i]) return true; return false; } int main() { ios_base::sync_with_...
6
#include <bits/stdc++.h> using namespace std; vector<int> s[1005], t[15]; unordered_map<int, vector<int>> mp; unordered_map<int, int> f[1005]; int g[(1 << 12) + 5], h[(1 << 12) + 5]; int rasp = 0, m; int nr(unsigned int num) { return 32 - __builtin_clz(num); } int dfs(int nod, int ta) { vector<int> aux; for (auto i...
10
#include <bits/stdc++.h> using namespace std; double x[101010], b[101010], pre[101010], suc[101010]; int n, zero, m; const double eps = 1e-6; const int inf = 100000000; int cmp(double x) { if (fabs(x) <= eps) return 0; if (x > eps) return 1; else return -1; } int check(int n) { if (n == 1) return 1; d...
7
#include <bits/stdc++.h> using namespace std; inline long long read() { long long 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 << 1) + (x << 3) + c - '0'; c = getchar(); } return x * f; } int n, ...
8
#include <bits/stdc++.h> using namespace std; const int N = 105; const int inf = 1000 * 1000 * 1000 * 2; char a[15] = {'a', 'e', 'i', 'o', 'u', 'y'}; int x[N]; char s[505]; int n; int main() { cin >> n; for (int i = 1; i <= n; i++) cin >> x[i]; bool flag = true; for (int i = 0; i <= n; i++) { cin.getline(s,...
2
// #pragma GCC optimize("Ofast,unroll-loops") // #pragma GCC target("avx,avx2,fma") #include <bits/stdc++.h> using namespace std; #define ll long long #define ull unsigned long long #define dd double #define ld long double #define sl(n) scanf("%lld", &n) #define si(n) scanf("%d", &n) #define sd(n) scanf("%lf", &n) #d...
6
#include <bits/stdc++.h> using namespace std; int main() { int i, j, k; int n; cin >> n; int a[n]; for (i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); swap(a[0], a[n - 1]); for (i = 0; i < n; i++) cout << a[i] << " "; return 0; }
2
#include <bits/stdc++.h> using namespace std; int n; int main() { cin >> n; cout << 2 * n - 1 << ' ' << 2 << '\n' << 1 << ' ' << 2; }
3
#include <bits/stdc++.h> using namespace std; int sqr(int a, int b) { return a * 2 + (b - 2) * 2; } int main() { long long int a, b, c, d, o, ar, oifi = 0; cin >> a >> b >> c; for (d = 0; d < c; d++) { ar = (a - 4 * d); o = (b - 4 * d); oifi = oifi + sqr(ar, o); } cout << oifi << endl; }
0
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 7; const int maxe = 5e6 + 7; int n, m, d, num[maxe]; int getid(int i, int j) { return i + n * (j - 1); } int tot, to[maxe], nxt[maxe], head1[maxe]; void addedge(int x, int y) { to[++tot] = y; nxt[tot] = head1[x]; head1[x] = tot; } int tot2, to2[...
8
#include <bits/stdc++.h> using namespace std; int main() { long long int n, k, i, l, j, m; long long int sum, prev; cin >> n; vector<long long int> a, v; for (i = 1; i < sqrt(n); i++) { if (n % i == 0) { a.push_back(i); a.push_back(n / i); } } if ((long long)(sqrt(n)) * (long long)(sqr...
3
#include <bits/stdc++.h> using namespace std; const int N = 1000005; int n, dfn, rt, tot, p[N], dp[N], ll[N], rr[N], len[N], lk[N], T[N << 2], fa[20][N], ch[N][26]; vector<int> g[N]; char s[N]; int extend(int p, int c) { int np = ++tot; len[np] = len[p] + 1; while (p && !ch[p][c]) ch[p][c] = np, p = lk[p]; ...
12
#include <bits/stdc++.h> using namespace std; const int N = 100 * 1000 + 10; int n; string s; int main() { cin >> n; cin >> s; for (int i = 0; i < n; ++i) { for (int j = 1; i + 4 * j < n; ++j) { bool f = 1; int t = 0; for (int k = i; k < n; k += j) { t++; if (t > 5) break; ...
2
#include <bits/stdc++.h> using namespace std; void __print(int x) { cerr << x; } void __print(long x) { cerr << x; } void __print(long long x) { cerr << x; } void __print(unsigned x) { cerr << x; } void __print(unsigned long x) { cerr << x; } void __print(unsigned long long x) { cerr << x; } void __print(float x) { cer...
5
#include <bits/stdc++.h> using namespace std; struct __s { __s() { srand(time(NULL)); if (1) { ios_base::Init i; } } ~__s() { if (!1) fprintf(stderr, "Execution time: %.3lf s.\n", (double)clock() / CLOCKS_PER_SEC); long long n; cin >> n; } } __S; bool l, r, u, d...
3
#include <bits/stdc++.h> using namespace std; const int MAXN = 3e5 + 5; const int INF = INT_MAX / 2; const long long LLINF = 9223372036854775807 / 2; int a[MAXN]; void solve() { int n; scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d", &a[i]); queue<pair<int, int> > q; int res = 0; q.push(make_pair(1...
4
#include <bits/stdc++.h> using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const long long base = 998244353; const long long oo = 1e6 + 10; const long long gh = 1e3 + 3; const long long inf = 1e15 + 5; double pi = 2 * asin(1); long long n, m, k; long long a[oo]; long long a1[oo],...
3
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; const long long INF = 1ll << 60; const double EPS = 1e-7; const long long MOD = 998244353; int n; char s[N]; int x, y; int prex[N], prey[N]; bool check(int mid) { for (int i = (1); i <= (n - mid + 1); i++) { int xx = x - (prex[n] - prex[i + mid ...
5