solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(NULL); long long i, j, n, m; cin >> n; string s; cin >> s; long long dp[n + 1][2]; memset(dp, 0, sizeof(dp)); for (i = 1; i <= n; i++) { if (s[i - 1] == '0') { dp[i][0] = max(dp[i - 1][0], dp[i - 1][1...
8
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; vector<string> v; int i; string s1(""); for (i = 0; i <= s.size(); i++) { if (s[i] == '.' || i == s.size()) { v.push_back(s1); s1.clear(); } else { s1.push_back(s[i]); } } if (v[0].size() > 8 || ...
6
#include <bits/stdc++.h> using namespace std; const int MAX = 8388608; const int N = 23; int power[31] = {0}; int dp[MAX + 1] = {false}; int is[MAX + 1] = {false}; int arr[MAX + 1]; void solve() { int n; cin >> n; for (int j = 1; j <= n; j++) { cin >> arr[j]; is[arr[j]] = arr[j]; } for (int mask = 0; ...
14
#include <bits/stdc++.h> using namespace std; const long long N = 200100; const long long MOD = 998244353; void solve() { long long a, b, c, d, ans = 0, k; cin >> a >> b >> c >> d; if (a <= b) { cout << b << endl; return; } ans += b; a -= b; if (c <= d) { cout << "-1\n"; return; } k = ...
1
#include <bits/stdc++.h> const int N = 105; const int mod = 1e9; int a[N], f[N]; int main() { int n, m, t, l, r, p, x, i; scanf("%i %i", &n, &m); for (i = 1; i <= n; i++) scanf("%i", &a[i]); f[1] = 1; for (i = 2; i <= n; i++) f[i] = (f[i - 1] + f[i - 2]) % mod; while (m--) { scanf("%i", &t); if (t =...
7
#include <bits/stdc++.h> using namespace std; int a[10000], f[10000]; int main() { int n; cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; sort(a + 1, a + n + 1); bool flag = 1; int ans = 0; while (flag) { flag = 0; int now = 0; for (int i = 1; i <= n; i++) { if (f[i]) continue; ...
4
#include <bits/stdc++.h> using namespace std; const int MaxN = 1e5; const long long Inf = 1LL << 60; long long dis[8 * MaxN + 5]; vector<pair<long long, int> > G[8 * MaxN + 5]; int mp[MaxN + 5]; bool vis[8 * MaxN + 5]; pair<long long, int> nxt; void build(int now, int l, int r) { vis[now] = vis[now + 4 * MaxN] = true...
15
#include <bits/stdc++.h> using namespace std; const int maxr = 10000000; char rd[maxr], prt[maxr]; int rpos, ppos, mmx; inline char readc() { if (!rpos) mmx = fread(rd, 1, maxr, stdin); char c = rd[rpos++]; if (rpos == maxr) rpos = 0; if (rpos > mmx) return 0; return c; } template <typename T> inline void rea...
18
#include <bits/stdc++.h> using namespace std; const int N = 12, M = 2010; int n, m; int grid[N][M]; int mxcol[M]; int tot; vector<pair<int, int> > v; vector<int> arr; int tmp[N]; void shift(int col) { for (int i = 0; i < n; i++) { if (i == n - 1) tmp[0] = grid[i][col]; else tmp[i + 1] = grid[i][co...
17
#include <bits/stdc++.h> using namespace std; int main() { int n, i, small, index = 0; int x[101]; cin >> n; for (i = 0; i < n; i++) { cin >> x[i]; } x[n] = x[0]; small = abs(x[0] - x[1]); for (i = 0; i < n; i++) { if (small > abs(x[i] - x[i + 1])) { small = abs(x[i] - x[i + 1]); } }...
0
#include <bits/stdc++.h> using namespace std; const int N = 2 * 1e3 + 7; const long double pi = 3.14159265359; const long long INF = 1e9 + 7; string s, t; vector<int> v; int main() { ios_base::sync_with_stdio(); cin.tie(0); cout.tie(0); srand(time(0)); ; int n; cin >> n; cin >> s >> t; string str1 = s...
4
#include <bits/stdc++.h> using namespace std; void swapi(int *a, int *b) { int temp; temp = *a; *a = *b; *b = temp; } void swapc(char *a, char *b) { char temp; temp = *a; *a = *b; *b = temp; } template <typename T> void fscan(T &x) { x = 0; bool neg = 0; register T c = getchar(); if (c == '-') n...
3
#include <bits/stdc++.h> using namespace std; template <typename T> void _R(T &x) { cin >> x; } void _R(int &x) { scanf("%d", &x); } void _R(long long &x) { scanf("%" PRId64, &x); } void _R(double &x) { scanf("%lf", &x); } void _R(char &x) { scanf(" %c", &x); } void _R(char *x) { scanf("%s", x); } void R() {} templat...
16
#include <bits/stdc++.h> using namespace std; int dx[] = {0, 0, -1, 1}; int dy[] = {1, -1, 0, 0}; const int N = 1e3 + 1e2; bool Grid[N][N]; int n, m, t; inline bool isValid(int i, int j) { return (0 <= i && i < n && 0 <= j && j < m); } inline bool CanChangeTheCell(int i, int j) { bool Re = false; for (int move = ...
12
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int a, b, c, d; cin >> a >> b >> c >> d; for (int i = 1; i <= 200; i++) { for (int j = 1; j <= 200; j++) { for (int z = 1; z <= 200; z++) { if (i >= a && j >= b && z >= c && z >= d && i >...
5
#include <bits/stdc++.h> using namespace std; const int N = 5555; int hackable[N]; int sols[N]; int pts[N][13]; int score[N]; int z[N]; int bound[N]; int cnt_hack[N]; int rgt[N]; int task[N][13]; int guys[N]; int main() { int n; scanf("%d", &n); for (int j = 0; j < 3; j++) { hackable[j] = 0; sols[j] = 0; ...
23
#include <bits/stdc++.h> using namespace std; map<long long, long long> vis; deque<long long> que; signed main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long n; cin >> n; long long k; cin >> k; for (long long i = 1; i <= n; i++) { long long tp; cin >> tp; if (!vis[tp]) { ...
2
#include <bits/stdc++.h> using namespace std; template <typename t> t power(t a, t p) { if (p == 1 || p == 0) { return (p == 1) ? a : 1; } t temp = power(a, p / 2); temp = temp * temp; if (p & 1) { temp = temp * a; } return temp; } template <typename t> t power(t a, t p, t M) { if (p == 1 || p =...
10
#include <bits/stdc++.h> using namespace std; inline void smin(int &a, int b) { if (b < a) a = b; } inline void smax(int &a, int b) { if (b > a) a = b; } struct Node { Node *pre, *ch[2]; int id, sz; void up() { sz = ch[0]->sz + ch[1]->sz + 1; } void down() {} }; struct Splaytree { int top; Node node[100...
14
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 7; int n, w, h; int g[maxn], p[maxn], t[maxn], ansx[maxn], ansy[maxn]; vector<int> s[maxn * 2], xs, ys; int main() { scanf("%d%d%d", &n, &w, &h); for (int i = 1; i <= n; i++) { scanf("%d%d%d", &g[i], &p[i], &t[i]); s[p[i] - t[i] + maxn].pu...
11
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; long long ans = 0; int x; for (int i = 1; i <= N; i++) { cin >> x; ans += x * i; } cout << ans; }
12
#include <bits/stdc++.h> using namespace std; int n, a, b, q, k, l; vector<int> bid[200001]; vector<int> nc; set<int> iid; map<int, int> maxBid; int main() { ios::sync_with_stdio(false); cin >> n; for (int i = 0; i < n; i++) { cin >> a >> b; bid[a].push_back(b); iid.insert(a); } for (set<int>::ite...
12
#include <bits/stdc++.h> using namespace std; const int inf = (int)1e9; const double INF = 1e12, EPS = 1e-9; const int mod = inf + 7; inline long long inv(long long a) { long long b = mod, x = 1, y = 0; while (b) { long long t = a / b; a -= t * b; swap(a, b); x -= t * y; swap(x, y); } return...
10
#include <bits/stdc++.h> using namespace std; template <class T> void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()) { v.assign(a, vector<T>(b, t)); } template <class F, class T> void convert(const F &f, T &t) { stringstream ss; ss << f; ss >> t; } struct UF { vector<int> par; UF(int m) : par...
13
#include <bits/stdc++.h> using namespace std; inline int read() { int x = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); } return x * f; } const int N = 2005, M =...
13
#include <bits/stdc++.h> using namespace std; int n, m; int ans; int s[111111]; int main() { cin >> n >> m; int i, j; ans = 1e7; for (i = 1; i <= m; i++) { int a, b; scanf("%d%d", &a, &b); int temp = b - a + 1; ans = min(ans, temp); } i = 1; j = 0; while (i <= n) { s[i] = j; i++;...
9
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 500; int fa[N << 1], top, n, K, dep[N << 1]; inline int find(int x) { return fa[x] == x ? x : find(fa[x]); } struct Edge { int from, to, st; Edge(int a = 0, int b = 0, int c = 0) { from = a, to = b, st = c; } }; bool operator<(Edge a, Edge b) { ret...
17
#include <bits/stdc++.h> using namespace std; int n, a, s = 0, c = 0, ans = 0; int main() { cin >> n; for (int i = 0; i < n; i++) { cin >> a; if (a == 1) { if (s == 1 && c != 0) ans += 2; else ans++; s = 0; c++; } else s++; } cout << ans; return 0; }
1
#include <bits/stdc++.h> using namespace std; long long dig[65], cnt, pw[62], cur, f[65]; long long solve(long long k) { long long val = 0, ans = 0; for (long long i = 1; i < k + 2; i++) { if (i == k + 1) { if (val <= cur) ans++; } else { if (i > 1 && dig[i] == 1) { ans += pw[k - i]; ...
13
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; multiset<int, less<int>> s; multiset<int, less<int>>::iterator iter; while (n--) { int x; cin >> x; s.insert(x); } iter = s.begin(); int count = 0; int sum = 0; for (; (iter != s.end()) && (count != m); c...
1
#include <bits/stdc++.h> using namespace std; int x[505], y[505], rod[505], ans[505]; bool vis[505], flag; int n, m; int main() { scanf("%d%d", &n, &m); for (int i = 0; i < n; i++) { scanf("%d%d", &x[i], &y[i]); } for (int i = 0; i < m; i++) { scanf("%d", &rod[i]); } for (int i = 0; i < 2; i++) { ...
8
#include <bits/stdc++.h> using namespace std; int main() { int n, m, i, j, cnt = 0, st, en, ans = 0; char s[105][105]; cin >> n >> m; for (i = 0; i < n; i++) { for (j = 0; j < m; j++) { cin >> s[i][j]; } } for (j = 0; j < m; j++) { if (s[n - 1][j] == 'B') { cnt++; en = j; }...
4
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 7; long long exgcd(long long a, long long b, long long &x, long long &y) { if (b == 0) { x = 1; y = 0; return a; } long long ret = exgcd(b, a % b, y, x); y -= a / b * x; return ret; } long long inv(long long a, long long M) { s...
13
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; int p[4000], c[4000]; int cnt[4000] = {0}; vector<int> belong[4000]; int pos[4000] = {0}; for (int i = 1; i <= n; i++) { cin >> p[i] >> c[i]; cnt[p[i]]++; belong[p[i]].push_back(c[i]); } for (int i = 1; i <...
9
#include <bits/stdc++.h> using namespace std; 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 lcm(long long int a, long long int b) { return a * b / gcd(a, b); } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t ...
5
#include <bits/stdc++.h> #define rep(i,n) for(int i=0; i<(n); i++) #define reps(i,s,n) for(int i=(s); i<(n); i++) #define all(v) v.begin(),v.end() #define outve(v) for(auto i : v) cout << i << " ";cout << endl #define outmat(v) for(auto i : v){for(auto j : i) cout << j << " ";cout << endl;} #define in(n,v) for(int i=0;...
1
#include <bits/stdc++.h> using namespace std; long long mod = (long long)1e9 + 7; long long powerMod(long long a, long long n) { if (n == 0) return 1; long long res = powerMod((a % mod * a % mod) % mod, n / 2) % mod; if (n % 2) return (a % mod * res % mod) % mod; return res; } long long n; long long a[111111]; ...
9
#include <bits/stdc++.h> using namespace std; vector<long long> prefix(200005, 0); class DSU { vector<long long> parent, rank; public: DSU(long long n) { parent.resize(n); rank.resize(n); for (int i = 0; i < n; i++) { parent[i] = i; rank[i] = 1; } } long long get(long long a) { ...
10
#include <bits/stdc++.h> using namespace std; long long a[1000000]; int main() { long long p, k, d, i; cin >> p >> k; a[0] = p; if (p < k) return cout << "1" << endl << p, 0; a[1] = p / k * -1; d = 1; while (a[d] != 1 && a[d] != 0) { d++; if (a[d - 1] % k == 0) a[d] = a[d - 1] / k * -1; ...
12
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 30; const long long mod = 1e9 + 7; const long long lg = 25; long long dp[maxn + 10][lg + 5]; long long mark[maxn + 10]; long long pw(long long a, long long b) { if (b == 0) return 1; if (b % 2 == 0) { return pw((a * a) % mod, b / 2) % mod; }...
12
#include <bits/stdc++.h> using namespace std; int n, k, a[233], dep[233]; bitset<2005> s[12 + 1][1 << 16]; int main() { scanf("%d%d", &n, &k); for (int i = 0; i < n; ++i) scanf("%d", a + i); s[0][0][0] = 1; for (int i = 1; i <= 12; ++i) { for (int g = 0; g < (1 << n); ++g) for (int w = 2000 / k; w >= ...
23
#include <bits/stdc++.h> using namespace std; const int maxn = 1050, maxv = 2e6 + 50; int n, x, y, z, N, cnt, tot, a[maxn], b[maxn]; unordered_map<int, int> mp[30]; int read() { int x = 0; char c = getchar(); while (c < '0' || c > '9') c = getchar(); while (c >= '0' && c <= '9') x = x * 10 + (c ^ 48), c = getch...
18
#include <bits/stdc++.h> using namespace std; template <typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; } template <typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; } template <typename T> inline bool smin(T &a, const T &b) { return a > b ? a = b : a;...
10
#include <bits/stdc++.h> int n, type, fq[3]; int main() { scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", &type); fq[type]++; } if (fq[1] && fq[2]) { fq[1]--; fq[2]--; printf("2 1 "); } while (fq[2]--) printf("2 "); while (fq[1]--) printf("1 "); return 0; }
4
#include <bits/stdc++.h> using namespace std; vector<vector<int>> adj; bool visited[1000005]; bool booly[1000005]; long long int cnter1 = 0; long long int cnter2 = 0; int e = 0; void dfs(int v) { visited[v] = true; for (auto u : adj[v]) { if (!visited[u]) { e++; dfs(u); } } } int main() { io...
13
#include <bits/stdc++.h> using namespace std; int n, a[200100], b[200100], m, f[200100], id[200100], ans[200100], h; long long k, sum; void run() { int i, t = 0; for (i = 0; i < m; i++) { int tp = b[i]; if (i) tp -= b[i - 1]; sum = 1LL * (n - t) * tp; if (sum > k) break; k -= sum; t += f[i];...
10
#include <bits/stdc++.h> int n, m, type, x, y, z, sx, sy, sz, Ix, Iy, Iz, cx, cy, k, tot, Q, A, S, tmp; int L[100005 * 25], R[100005 * 25], a[100005 * 25], rt[100005], son[100005], next[100005], In[100005], Out[100005], v[100005], d[100005], f[100005][20]; void dfs(int x) { In[x] = m++; for (int y = son[x]; y; ...
21
#include <bits/stdc++.h> using namespace std; int n, m, ans, maxn; int num[(int)2e5 + 5]; int main() { cin >> n; for (int i = 0; i < n; i++) { cin >> num[i]; maxn = max(num[i], maxn); } sort(num, num + n); n = unique(num, num + n) - num; for (int i = 0; i < n; i++) { for (int j = num[i]; j - num...
13
#include <bits/stdc++.h> using namespace std; template <typename A, typename B> ostream &operator<<(ostream &s, const pair<A, B> &p) { return s << "(" << p.first << "," << p.second << ")"; } template <typename T> ostream &operator<<(ostream &s, const vector<T> &c) { s << "[ "; for (auto it : c) s << it << " "; ...
14
#include <bits/stdc++.h> using namespace std; const int fx[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}}; const int fxx[8][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}, {1, 1}, {1, -1}, {-1, 1}, {-1, -1}}; template <typename T, typename TT> ostream& operator<<(ostream& s, pair<T, TT> t) { return s << "...
0
#include <bits/stdc++.h> using namespace std; const int maxN = 550; const int vc = 1e9 + 7; int a[maxN], b[maxN], c[maxN], p[maxN], s[maxN]; char q[maxN]; int n, m, k; bool ok; bool check(int l, int r, int s, int phanbu) { int mx = -1; for (int i = l; i <= r; i++) { c[i] = a[i]; mx = max(mx, a[i]); } wh...
10
#include <bits/stdc++.h> using namespace std; int n, m, i, it, x, y, ans, a[400000], b[400000], v[400000][2]; int main() { scanf("%d%d%d%d", &n, &m, &x, &y); for (i = 1; i <= n; ++i) scanf("%d", &a[i]); for (i = 1; i <= m; ++i) scanf("%d", &b[i]); ans = 0, it = 1; for (i = 1; i <= n; ++i) { while ((b[it] ...
5
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1); const long long inf = 1e9 + 9; long long read() { long long x = 0, f = 1; char ch = getchar(); while (!isdigit(ch)) { if (ch == '-') f = -1; ch = getchar(); } while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar(); return f...
4
#include <bits/stdc++.h> using namespace std; inline long long getint() { long long _x = 0, _tmp = 1; char _tc = getchar(); while ((_tc < '0' || _tc > '9') && _tc != '-') _tc = getchar(); if (_tc == '-') _tc = getchar(), _tmp = -1; while (_tc >= '0' && _tc <= '9') _x *= 10, _x += (_tc - '0'), _tc = getchar();...
22
#include <bits/stdc++.h> using namespace std; int n, m, q, y; string s[22], t[22]; int main() { ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); cin >> n >> m; for (int i = 0; i < n; i++) cin >> s[i]; for (int i = 0; i < m; i++) cin >> t[i]; cin >> q; while (q--) { cin >> y; if (!(y % n))...
0
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { ios::sync_with_stdio(0); cin.tie(0); ll n, t; cin >> n >> t; vector<ll> a(n); ll burl = 0; ll candy = 0; for (ll i = 0; i < n; i++) { cin >> a[i]; if (burl + a[i] <= t) { burl += a[i]; candy++; } }...
9
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 1000; const int LOGN = 20; const long long lMAX = 1e18; int n, m, h[N], d[N], two[50], pos[2][LOGN][N]; long long sum[N], st[2][LOGN][N]; long long max(const long long &a, const long long &b) { return a > b ? a : b; } void swap(int &a, int &b) { a ^= b...
15
#include <bits/stdc++.h> using namespace std; void PLAY() { cout << fixed << setprecision(10); ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long n, k; cin >> n >> k; vector<long long> x(n), c(n); for (int i = 0; i < n; i++)...
7
#include <bits/stdc++.h> using namespace std; int check(string s) { int n = s.size(); for (int i = 0; i < n / 2; i++) if (s[i] != s[n - i - 1]) return 0; return 1; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); string s; cin >> s; int n = s.size(); int ok = 0; for (int i = 0; i < n...
10
#include <bits/stdc++.h> using namespace std; int main() { int n; int t; bool flag = false; cin >> n >> t; t = t - 1; vector<int> graph(n - 1); for (int i = 0; i < n - 1; i++) cin >> graph[i]; graph.push_back(1); for (int i = 0; i < n; i = i + graph[i]) { if (i == t) { flag = true; bre...
2
#include <bits/stdc++.h> using namespace std; const int N = 105; const int M = 1e6 + 100; const int mod = 1e9 + 7; int n, m, k, P; int num[N][N][N]; char s[N][N][N]; int dx[] = {1, 0, 0}; int dy[] = {0, 1, 0}; int dz[] = {0, 0, 1}; int d[M], ans; vector<int> g[M], gr[M]; bool was[M], bad[M]; bool can(int x, int y, int ...
10
#include <bits/stdc++.h> using namespace std; template <class T> T MAX(T a, T b) { return a > b ? a : b; } template <class T> T MIN(T a, T b) { return a < b ? a : b; } template <class T1> void __(T1 p) { cout << p << endl; } template <class T1> void deb(T1 p) { cout << "Debugging: " << p << endl; } template <cl...
15
#include <bits/stdc++.h> using namespace std; long long int mod = 1e9 + 7; bool comp(pair<double, int> a, pair<double, int> b) { if (a.first > b.first) return true; if (a.first == b.first) { if (a.second < b.second) return true; } return false; } long long int power(long long int x, long long int y, long lo...
5
#include <bits/stdc++.h> using namespace std; template <typename T> void out(T x) { cout << x << endl; exit(0); } const int maxn = 1e6 + 11; int n; double vb, vs; double stops[maxn]; double xu, yu; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n; cin >> vb >> vs; for (in...
4
#include <bits/stdc++.h> using namespace std; bool fit(int a1, int b1, int a2, int b2, int a3, int b3) { if ((a2 + a3 <= a1 && b2 <= b1 && b3 <= b1) || (a2 + b3 <= a1 && b2 <= b1 && a3 <= b1) || (b2 + a3 <= a1 && a2 <= b1 && b3 <= b1) || (b2 + b3 <= a1 && a2 <= b1 && a3 <= b1)) return true; el...
4
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; 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; a = a * a % mod; } return res; } const int N = 1010000; int n, m, u, v, f[N],...
13
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 10, mod = 1e9 + 7, SQ1 = 1400, SQ2 = 145; const long long inf = 1e18; struct fenwick { int sm[maxn]; void add(int ind, int x) { while (ind < maxn) sm[ind] += x, ind += (ind & -ind); } int ask(int ind) { int ans = 0; while (ind > 0)...
16
#include <bits/stdc++.h> int main() { std::ios::sync_with_stdio(0); std::cin.tie(0); int n; std::cin >> n; if (n & 1) { std::cout << "YES\n"; int const n2 = 2 * n; for (int i = 1; i < n2; i += 2) std::cout << (i + (i >> 1 & 1)) << ' '; for (int i = 1; i < n2; i += 2) std::cout << (i + !(i >> 1...
4
#include <bits/stdc++.h> using namespace std; int main() { long long int n, k, s1 = 0, s2 = 0, s3 = 0, i; cin >> n; for (i = 0; i < n; i++) { cin >> k; s1 = s1 + k; } for (i = 0; i < n - 1; i++) { cin >> k; s2 = s2 + k; } for (i = 0; i < n - 2; i++) { cin >> k; s3 = s3 + k; } c...
3
#include <bits/stdc++.h> using namespace std; int main() { long long int n, m; cin >> n >> m; long long int x, k, y; cin >> x >> k >> y; long long 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]; int in = -1; long long int ans = 0, ct = 0, mx = 0; for...
12
#include <bits/stdc++.h> using namespace std; const int inf = 2e9; bool ok(int a, int b, int c, int d, int x, int y, int z, int w) { bool inx = !(a > z or c < x); bool iny = !(b > w or d < y); return inx and iny; } int main() { int n; cin >> n; int a[n], b[n], c[n], d[n]; int minx[2][n], maxx[2][n], miny[...
8
#include <bits/stdc++.h> long long gi() { long long x = 0, f = 1; char ch = getchar(); while (!isdigit(ch)) f ^= ch == '-', ch = getchar(); while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar(); return f ? x : -x; } int in[310], out[310], que[310], hd = 1, tl = 1; long long val[310]; int dp[100010]; int m...
13
#include <bits/stdc++.h> using namespace std; const int maxN = 2000; int id[maxN], sz[maxN]; void initialize(int n) { for (int i = 0; i < n; i++) { id[i] = i; sz[i] = 1; } } int root(int x) { while (x != id[x]) { id[x] = id[id[x]]; x = id[x]; } return x; } void unionxy(int x, int y) { x = ro...
8
#include <bits/stdc++.h> using namespace std; int dp[200000 + 5][2]; int main() { int r, g; int h = 0; cin >> r >> g; while (h * (h + 1) / 2 <= r + g) h++; h--; int t = h * (h + 1) / 2; signed long long int ans = 0; int z = 1; dp[0][0] = dp[0][1] = 1; for (int j = 1; j <= h; ++j) { for (int i = ...
12
#include <bits/stdc++.h> using namespace std; string smallest(string s) { int l = s.length(); string ans = ""; for (int i = 0; i < l - 1; i++) { if (s[i] > s[i + 1]) { for (int j = 0; j < l; j++) { if (i != j) ans += s[j]; } return ans; } } ans = s.substr(0., l - 1); return...
4
#include <bits/stdc++.h> #pragma GCC optimize("O3") #pragma comment(linker, "/stack:200000000") #pragma GCC optimize("unroll-loops") using namespace std; using namespace std; inline long long int addmod(long long int a, long long int b) { return (a % 1000000007 + b % 1000000007) % 1000000007; } inline long long int s...
4
#include <bits/stdc++.h> using namespace std; int a[100005] = {0}; int main() { int c, d, n, m, k; cin >> c >> d >> n >> m >> k; int kol = n * m - k; if (kol <= 0) { cout << 0; return 0; } int ans = 100000000; for (int i = 0; i <= kol; i++) { int dop = max(kol - i * n, 0); ans = min(ans, i...
7
#include <bits/stdc++.h> using namespace std; int main() { int len, n, r, nlen; string s; cin >> len; if (len < 3) cout << -1 << endl; else if (len == 3) cout << 210 << endl; else { s += '1'; for (int i = 1; i < len; i++) { s += '0'; } n = 1; for (int i = 1; i < len; i++) {...
6
#include <bits/stdc++.h> #pragma GCC optimize(1) #pragma G++ optimize(1) #pragma GCC optimize(2) #pragma G++ optimize(2) #pragma GCC optimize(3) #pragma G++ optimize(3) #pragma GCC optimize("-funsafe-loop-optimizations") #pragma GCC optimize("-funroll-loops") #pragma GCC optimize("-fwhole-program") #pragma GCC optimize...
15
#include <bits/stdc++.h> using namespace std; const int MAXN = 100233, B = 100, INF = 0x7f7f7f7f; int n, w, Q, K[MAXN], pos[MAXN]; int ans[MAXN]; int a[MAXN], nxt[MAXN]; int t[MAXN], mi[MAXN][17], mx[MAXN][17]; bool cmp(const int &aa, const int &bb) { return K[aa] < K[bb]; } struct node { int v, x, y; node() {} n...
26
#include <bits/stdc++.h> using namespace std; const int MAXN = 200007; const double EPS = 1e-10; int n; double l, v1, v2; double a[MAXN]; double ans[MAXN]; int main() { cin >> n >> l >> v1 >> v2; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n; i++) a[i + n] = a[i] + 2 * l; a[n + n] = 1e+20; do...
13
#include <bits/stdc++.h> using namespace std; long long power(long long x, long long y) { long long ans = 1; while (y) { if (y % 2) ans = ans * x; y /= 2; x = x * x; } return ans; } int main() { long long n, k; cin >> n >> k; vector<long long> v; vector<long long> ans; long long m = n, cou...
6
#include <bits/stdc++.h> using namespace std; template <typename T> using Matrix = vector<vector<T>>; template <typename T> bool relax(T& r, const T& first) { if (r > first) { r = first; return true; } return false; } template <typename T> bool heavy(T& h, const T& first) { if (h < first) { h = firs...
11
#include <bits/stdc++.h> using namespace std; const int maxn = 100; int p[maxn]; int n; int main() { scanf("%d", &n); for (int i = 0; i < n; ++i) { int mx = 0; for (int j = 0; j < n; ++j) { int x; scanf("%d", &x); mx = max(mx, x); } p[i] = mx; } int fl = 0; for (int i = 0; i ...
3
#include <bits/stdc++.h> int anz[100100]; int main(void) { std::vector<int> seq; int n, p; scanf("%d %d", &n, &p); int a; for (int i = 0; i < n; i++) { scanf("%d", &a); seq.push_back(a); }; std::sort(seq.begin(), seq.end()); int x = seq[0]; int cnt = 0; std::priority_queue<std::pair<int, int...
11
#include <bits/stdc++.h> using namespace std; const double eps = 1e-9; const double pi = acos(-1.0); const int maxn = (int)1e5 + 10; const int mod = (int)1e9; double aabs(double a) { return a < 0 ? -a : a; } long a[150005]; int main() { long int n, k, i, s, j; s = 0; cin >> n >> k; j = 0; a[0] = 0; for (i =...
3
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int h, q; cin >> h >> q; map<long long, pair<int, int> > m; vector<pair<long long, long long> > bad; int q1 = 0; for (int _ = 0; _ < q; ++_) { int i, ans; long long l, r; cin >> i >> l >> r >...
15
#include <bits/stdc++.h> using namespace std; long long int gcd(long long int a, long long int b) { return (b == 0LL ? a : gcd(b, a % b)); } long double dist(long double x, long double arayikhalatyan, long double x2, long double y2) { return sqrt((x - x2) * (x - x2) + (arayikhalatyan ...
18
#include <bits/stdc++.h> using namespace std; template <class T> ostream& operator<<(ostream& os, const vector<T>& v) { for (auto i = begin(v); i != end(v); i++) os << *i << (i == end(v) - 1 ? "" : " "); return os; } template <class T> istream& operator>>(istream& is, vector<T>& v) { for (auto i = begin(v); i...
17
#include <bits/stdc++.h> using namespace std; const int N = 100000; struct xxx { int x, y; } a[N]; int b[N]; int tmp, ans; int c[N]; int n, r; int t; inline int dist(xxx a, xxx b) { return (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y); } void dfs(int k, int use, int tmp) { if (use > n) return; if (use =...
19
#include <bits/stdc++.h> using namespace std; const int MOD = 1000000007; int a[51][51], b[51][51]; int A[51][51], B[51][51]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, m; cin >> n >> m; vector<pair<int, pair<int, int> > > vec; for (int i = 0; i < n; ++i) for (int j...
6
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t; cin >> t; while (t--) { long long i, j, k, n, m; cin >> n >> k; long long a[n + 1]; for (i = 1; i <= n; i++) cin >> a[i]; long long dp[n + 1][n + 1]; mem...
12
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; int main() { string s; int l = 0; cin >> s; l = s.length(); if (s[0] >= 97 && s[0] <= 122) { printf("%c", s[0] - 32); } else printf("%c", s[0]); for (int i = 1; i < l; i++) { printf("%c", s[i]); } cout << endl; return ...
0
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int midpt = n / 2; for (int i = 0; i < n; i++) { cout << string(abs(midpt - i), '*'); cout << string((n - abs(midpt - i) * 2), 'D'); cout << string(abs(midpt - i), '*') << endl; } return 0; }
0
#include <bits/stdc++.h> using namespace std; using ld = long long; int arr[int(2e5 + 5)]; int rs[11]; int length(int x) { int ans = 0; while (x > 0) ans++, x /= 10; return ans; } int main() { map<int, int> m[11]; int n, k; scanf("%d%d", &n, &k); for (int i = 0; i < n; ++i) { int val; scanf("%d", ...
11
#include <bits/stdc++.h> using namespace std; void solve() { string s; cin >> s; vector<int> rsp(3, 0); for (int i = 0; i < s.size(); ++i) { if (s[i] == 'R') { ++rsp[0]; } if (s[i] == 'S') { ++rsp[1]; } if (s[i] == 'P') { ++rsp[2]; } } int max_idx = 0; char win_sy...
6
#include <bits/stdc++.h> using namespace std; int main() { int t; t = 1; while (t--) { string s1, s2, s3; cin >> s1 >> s2 >> s3; int n = s1.length(); map<char, char> mp; for (int i = 0; i < n; i++) { mp[s1[i]] = s2[i]; } n = s3.length(); for (int i = 0; i < n; i++) { if...
0
#include <bits/stdc++.h> const long long mod = 1000000007; using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int test; cin >> test; while (test--) { int n, f = 0, i; cin >> n; vector<long long> arr(n); unordered_map<long long, long long> cnt; fo...
2
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0), cout.tie(0); string s1, s2; cin >> s1 >> s2; bool vis[30] = {0}; set<int> se[30]; for (int i = 0; i < s1.size(); i++) vis[s1[i] - 'a'] = true; for (int i = 0; i < s2.size(); i++) if (!vis[s2[i] - 'a']...
7
#include <bits/stdc++.h> using namespace std; int a[100000]; int n, l, r, x; int sum = 0; void dfs(int i, int num, int ge, int minn, int maxx, int flag) { if (flag == 0 && ge >= 2 && num >= l && num <= r && maxx != 0 && minn != 100000 && maxx - minn >= x) { sum++; flag = 1; } if (i > n - 1) return; ...
6