solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n, m, k; cin >> n >> m >> k; vector<long long> a(n); for (int i = 0; i < n; ++i) { cin >> a[i]; } sort(a.rbegin(), a.rend()); cout << m / (k + 1) * (a[0] * k + a[1]) + m % (k + 1) * a[0] <...
2
#include <bits/stdc++.h> using namespace std; const int MAX = 2001000; int n, m, N; int A[MAX]; long long Sl[MAX], Sr[MAX]; int v[MAX]; void srt(int l, int r, int s, int lvl) { if (l == r) return; else { srt(l, (l + r) / 2, s / 2, lvl - 1); srt((l + r) / 2 + 1, r, s / 2, lvl - 1); int cnt = 0, id = ...
13
#include <bits/stdc++.h> using namespace std; void solve() { long long n; cin >> n; long long a[n + 1], n1 = 0, w = 0; a[0] = 0; for (long long i = 1; i < n + 1; i++) { cin >> a[i]; if (a[i] == 1) { n1++; } if (a[i] == 1 && a[i - 1] == 0) { w++; } } if (n1 == 0) { cout ...
2
#include <bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:16777216") vector<string> hor, ver; inline bool isHor(string s) { for (int i = 0; (i) < (((int)(hor).size())); ++(i)) if (hor[i] == s) return true; return false; } inline bool isVer(string s) { for (int i = 0; (i) < (((int)(ver).siz...
15
#include <bits/stdc++.h> using namespace std; int main() { int n; int i = 0, j = 0, cnt = 0; char s[200007]; scanf("%d", &n); scanf("%s", s); for (int k = 0; k < n; k++) { if (s[k] == 'R') { if (i < 0) { cnt++; i = 0; j = 0; } i++; } else if (s[k] == 'L') { ...
6
#include <bits/stdc++.h> int main() { int n, ans, i, j = 0; scanf("%d", &n); ans = 0; for (i = 0; i < n; i++) { ans = ans + (n - i - 1) * j + n - j; j++; } printf("%d\n", ans); return 0; }
2
#include <bits/stdc++.h> using namespace std; const double eps = 1e-8; int n; int main() { scanf("%d", &n); double mn = 0, mx = 1e100; for (int i = 0; i < n; i++) { double x; scanf("%lf", &x); mn = max(x / (i + 1), mn); mx = min((x + 1) / (i + 1), mx); } int l = (mn + eps) * (n + 1); int r =...
10
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; cout << 25; return 0; }
0
#include <bits/stdc++.h> using namespace std; struct Node { int u, v, len, next; } edge[301000]; int n, nm, m, cnt; int head[301000], path[301000], h[301000], d[301000], c[301000], dis[301000]; bool vis[301000]; bool ok; int p[301000 * 10]; queue<int> q; int ch[301000]; void addedge(int a, int b, int c) { edge[nm]....
14
#include <bits/stdc++.h> using namespace std; long long int inv[128], fac[128]; int N, A[10]; long long int dp[128][10]; bool vis[128][10]; long long int solve(int n, int d) { if (d == 10) { if (n == 0) return 1; else return 0; } if (vis[n][d]) return dp[n][d]; vis[n][d] = true; long long ...
11
#include <bits/stdc++.h> using namespace std; const int mo = 1000000007; int n, m, K, ans, C[105][105]; int f[55][55][55][105]; void UPD(int &x, int y) { (x += y) >= mo ? x -= mo : 233; } int main() { scanf("%d%d%d", &n, &m, &K); for (int i = (int)(0); i <= (int)(100); i++) C[i][0] = 1; for (int i = (int)(1); i <...
20
#include <bits/stdc++.h> using namespace std; int main() { int q; cin >> q; while (q--) { int n, a, b, c; string s; cin >> n >> a >> b >> c >> s; string ans(n, '0'); int v = 0; for (int i = 0; i < n; i++) { if (s[i] == 'R') { if (b) { ans[i] = 'P'; b--; ...
4
#include <bits/stdc++.h> using namespace std; int main() { int n, m, z = 0, w = 0; cin >> n >> m; if (n == 1 || n == 3 || n == 5 || n == 7 || n == 8 || n == 10 || n == 12) z = 31; else if (n == 2) z = 28; else z = 30; z += m - 1; w = z / 7; if (z % 7 != 0) w++; cout << w; return 0; }
0
#include <bits/stdc++.h> using namespace std; const int MAX = 1e7 + 5; long long a[MAX], dp[MAX]; int main() { ios_base::sync_with_stdio(0), cin.tie(0), cin.tie(0), cout.tie(0), cout.precision(15); int n; while (cin >> n) { for (int i = int(1); i < int(n + 1); i++) cin >> a[i]; for (int i = int(1); ...
13
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 10; const int base = 31337; const int mod = 1e9 + 7; const int inf = 0x3f3f3f3f; const int logo = 20; const int off = 1 << logo; const int treesiz = off << 1; int n; vector<int> graph[maxn][2]; bool bio[maxn]; int col[maxn][2]; int siz[maxn][2]; int d...
14
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); long long n; cin >> n; long long ans = 0; for (long long i = 3; i <= n; i++) { ans += i * (i - 1ll); } cout << ans << endl; return 0; }
4
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6; int c, v0, v1, a, l; int main() { while (cin >> c >> v0 >> v1 >> a >> l) { if (v0 >= c) cout << "1\n"; else { int s = v0; for (int i = 2;; i++) { int d = v0 + a * (i - 1); d = min(d, v1); d -= l; ...
1
#include <bits/stdc++.h> using namespace std; int main() { int n, k, i; cin >> n >> k; for (i = 0; i < k; i++) { if (n % 10 == 0) n = n / 10; else n--; } cout << n; return 0; }
0
#include <bits/stdc++.h> using namespace std; int main() { long long t; scanf("%lld", &t); while (t--) { long long n, x, y; scanf("%lld %lld %lld", &n, &x, &y); long long xy = y - x; long long k = 1; while (1) { if (xy % k == 0 && xy / k + 1 <= n) break; else k++; ...
4
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; i++) cin >> a[i]; sort(a.begin(), a.end()); int t = a[0], s = INT_MAX, ts = INT_MAX, rt; do { if (s > ts) { s = ts; rt = t; } ts = 0; for (int i = 0; i < n; i++)...
3
#include <bits/stdc++.h> using namespace std; const int NMAX = 101; vector<pair<int, int> > g[NMAX]; bool usd[NMAX]; bool flag; int l = 0, r = 0, f; void dfs(int v) { usd[v] = true; flag = true; for (int i = 0; i < (int)g[v].size(); i++) { int to = g[v][i].second; if (!usd[to]) { flag = false; ...
6
#include <bits/stdc++.h> using namespace std; const long long maxN = 1e18; const long long minN = -1e18; const long long MOD = 1e9 + 7; const long long MOD1 = 998244353; const int baseHash = 331; const int bigNumLength = 5000; const long double PI = acos(-1); const long long limit = 2e5 + 5; const long long limit1 = 1e...
11
#include <bits/stdc++.h> using namespace std; #define Debug(n) cout << n << " "; #define dou double #define ll long long #define ull unsigned long long #define FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define pb push_back #define mp make_pair #define fi first #define se second const ll Div=10e9+7...
0
#include <bits/stdc++.h> using namespace std; const int MAX = 4000005, TOP = 1000000; namespace segment_tree { int pre[MAX], sum[MAX], lazy[MAX], maxx[MAX]; void build(int p, int l, int r) { if (l == r) { sum[p] = maxx[p] = pre[l]; return; } int mid = (l + r) >> 1; build(p << 1, l, mid); build(p << 1 ...
14
#include <bits/stdc++.h> using namespace std; void init() { ios::sync_with_stdio(); cin.tie(0); } int main() { init(); int n; cin >> n; int* arr = new int[n]; for (int i = 1; i <= n; i++) cin >> arr[i]; int m; cin >> m; int x, y; for (int i = 1; i <= m; i++) { cin >> x >> y; arr[x - 1] += ...
0
#include <bits/stdc++.h> using namespace std; int n, m, x, y, Max, Min[(20009)], cnt[(20009)]; int Calc(int x, int y) { return (y < x) ? n - x + y : y - x; } int main() { cin >> n >> m; memset(Min, 0x7f, sizeof(Min)); for (int i = 1; i <= m; ++i) { cin >> x >> y; if (x == y) continue; cnt[x]++; Mi...
9
#include <bits/stdc++.h> using namespace std; const int MAXN = 400100; const int offset = (1 << 20); const int MOD = 1e9 + 7; int add(int x, int y) { x += y; if (x >= MOD) x -= MOD; return x; } int mul(int x, int y) { return (long long)x * y % MOD; } struct tournament { pair<int, int> p[offset * 2]; void init...
18
#include <bits/stdc++.h> using namespace std; bool debug = false; int n, m, k; int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0}; bool fg = 0; int lf[2005][2005], rf[2005][2005]; int ffl(int row, int x) { return x == lf[row][x] ? x : lf[row][x] = ffl(row, lf[row][x]); } int ffr(int row, int x) { return x == rf[row][...
16
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; inline void chmax(int& x, int y) { if (x < y) x = y; } inline void chmin(int& x, int y) { if (x > y) x = y; } inline int LSB(int i) { return (i & -i); } int n, m, res[1005][2]; map<string, int> mp; bitset<1005> b[5005][2]; int main() { ios_...
10
#include <bits/stdc++.h> using namespace std; const int N = 2e3 + 69; const int OO = 0x3f3f3f3f; const int mod = 1000000007; long long n, k; vector<long long> st; void fd() { for (long long i = 1; i * i <= n; ++i) { if (n % i == 0 && i != n / i) { st.push_back(i); st.push_back(n / i); } else ...
11
#include <bits/stdc++.h> using namespace std; char buf[1 << 21], *p1 = buf, *p2 = buf; template <class T> inline bool cmin(T& a, const T& b) { return a > b ? a = b, 1 : 0; } template <class T> inline bool cmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; } inline int read() { char ch; bool flag = 0; int r...
17
#include <bits/stdc++.h> using namespace std; char s[35][35]; double eps = 1e-5; int val[1 << 8], inf = 1 << 28; int n, m, x, x1, i, q; int abs(int a) { return a > 0 ? a : -a; } void work(int a, int b) { int i, j, s2, t; s2 = max(a - x1, 0); t = min(a + x1, n - 1); for (i = s2; i <= t; i++) { int s1, e1; ...
7
#include <bits/stdc++.h> using namespace std; long long i, i1, j, k, t, n, m, res, check1, a, b, s, mat[1010][1010]; char x; vector<pair<long long, long long>> lst; vector<long long> v; map<vector<long long>, pair<long long, long long>> h; int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n >> m; for (i ...
11
#include <bits/stdc++.h> using namespace std; const int dx[] = {0, 1, 0, -1}; const int dy[] = {1, 0, -1, 0}; int n, x, y, i, sol, a, b, t; int main() { cin.sync_with_stdio(0); cout.sync_with_stdio(0); cin >> t; for (; t; t--) { cin >> a >> b; if (a > b) swap(a, b); sol = 0; while (b > a) { ...
0
#include <bits/stdc++.h> using namespace std; const int MAXN = 100010; pair<int, int> A[MAXN], L[MAXN], R[MAXN]; long long len[MAXN], p[MAXN], s[MAXN]; int pre[MAXN]; const int inf = 1e9 + 7; int N; long long sqr(int x) { return x * 1LL * x; } pair<int, int> update(pair<int, int> q, pair<int, int> p) { pair<int, int>...
21
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const long long INF64 = 0x3f3f3f3f3f3f3f3f; const double EPS = 1e-8; const int MOD = 1000000007; const int N = 2e6 + 10; const int M = 1e5 + 10; int main() { ios::sync_with_stdio(false); cin.tie(0); int m, n; cin >> m >> n; double ans =...
8
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long int n, k; long long int i, l, r; long long int sum = 0; cin >> n >> k; for (i = 0; i < n; i++) { cin >> l >> r; sum += (r - l + 1); } float temp = (float)sum / k; ...
3
#include <bits/stdc++.h> using namespace std; long long int mod = 1000000007; long long int POWER[65]; long long int power(long long int x, long long int y, long long int mod) { long long int res = 1; x %= mod; while (y) { if (y & 1) res = (res * x) % mod; y >>= 1; x = (x * x) % mod; } return res;...
7
#include <bits/stdc++.h> using namespace std; char arr[55][55], ans[105][105], arr2[55][55]; int main() { int i, j, k; int n; scanf("%d", &n); for (i = 0; i < n; i++) scanf("%s", arr[i]); vector<pair<int, int> > pos; for (i = 0; i < n; i++) { for (j = 0; j < n; j++) { if (arr[i][j] == 'o') { ...
10
#include <bits/stdc++.h> using namespace std; const long long INF = numeric_limits<long long>::max() / 4; struct MinCostMaxFlow { int N; vector<vector<long long> > cap, flow, cost; vector<int> found; vector<long long> dist, pi, width; vector<pair<int, int> > dad; MinCostMaxFlow(int N) : N(N), ...
12
#include <bits/stdc++.h> using namespace std; const int MAXN = 1000005; char str[MAXN]; int k; void two_pointers_solution(); void bin_search_solution(); void dp_solution(); int find_lower_bound(int *sum, int left, int right, int x); int find_upper_bound(int *sum, int left, int right, int x); int main() { two_pointers...
8
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(); cin.tie(nullptr); cout.tie(nullptr); int t; cin >> t; int x, y, z; while (t--) { cin >> x >> y >> z; int ans = 0; int tmp = min(min(x, y), z); ans += tmp; x -= tmp; y -= tmp; z -= tmp; if (x ...
4
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); ; int t; cin >> t; for (int i = 0; i < int(t); i++) { int n; cin >> n; string a, b; cin >> a >> b; vector<int> moves; bool actC = (a[0] == '1'); for (int j = 0; j < int(n); j...
5
#include <bits/stdc++.h> #pragma GCC optimize(2) using namespace std; const int maxn = 1e6 + 7; const int mod = 1e9 + 7; long long int m, n, i, j, ans = 0, t; long long int a[maxn], b[maxn]; map<long long int, long long int> mp; int main() { cin >> t; while (t--) { cin >> n >> m; for (long long int i = 1; i...
6
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long t; cin >> t; while (t--) { long long n; cin >> n; n++; cout << n / 2 << "\n"; } }
0
#include <bits/stdc++.h> using namespace std; const int N = 1 << 20; const long long MOD = 1e9 + 7; int n, m; long long dp[21][N]; long long g[N]; bool s[N]; void init() { scanf("%d", &n); g[0] = 1; for (int i = 1; i <= n; i++) g[i] = (g[i - 1] << 1LL) % MOD; int f0; for (int i = 1; i <= n; i++) { scanf("...
16
#include <bits/stdc++.h> using namespace std; vector<pair<int, int> > v[100005]; int mk[100005], vis[100005]; queue<int> q; vector<int> now[2]; vector<int> ans[2]; vector<int> bk; int bfs(int x, int f, int y, int id) { bk.clear(); while (!q.empty()) q.pop(); mk[x] = y; vis[x] = 1; if (mk[x]) now[y].push_back(...
14
#include <bits/stdc++.h> using namespace std; const int maxn = 110000; int N; long long K; int A[maxn], B[maxn]; int main() { scanf("%d%I64d", &N, &K); for (int i = 0; i < N; ++i) scanf("%d", A + i); for (int i = 0; i < N; ++i) { B[i] = A[i]; } sort(B, B + N); long long d = 0; int j = N; for (int i ...
10
#include <bits/stdc++.h> using namespace std; set<int> S; int n; void gen(int prev, int k_left, int nth) { int next = prev; if (nth == n && k_left == 0 && S.find(prev) == S.end()) S.insert(prev); if (nth == n) return; for (int i = (0); i < (k_left + 1); ++i) { gen(prev * 10 + i, k_left - i, nth + 1); } } ...
10
#include <bits/stdc++.h> using namespace std; int par[1001], ran[1001] = {}, cnt[1001] = {}; int main() { int n, t, i; cin >> n; for (i = 2; i <= n; i++) { cin >> par[i]; ran[par[i]]++; } for (i = 1; i <= n; i++) { if (!ran[i]) cnt[par[i]]++; } for (i = 1; i <= n; i++) { if (ran[i] && cnt[...
4
#include <bits/stdc++.h> using namespace std; const int MAXN = 1007; const int oo = 1e9 + 7; int dir[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}}; char G[MAXN][MAXN]; struct node { int step[3]; } a[MAXN][MAXN]; struct point { int x, y; }; void BFS(int M, int N, int k) { queue<point> Q; point q, s; for (int i = ...
14
#include <bits/stdc++.h> using namespace std; int rev[100005], ar[100005], track[100005], cnt, ans[100005]; vector<pair<pair<int, int>, pair<int, int> > > v; map<int, int> save; void reduce(int val, int actual) { track[val]--; if (track[val] == actual - 1) cnt--; else if (track[val] == actual) cnt++; } vo...
10
#include <bits/stdc++.h> using namespace std; int main() { vector<int> c; int n, k; cin >> n >> k; int a; for (int i = 0; i < n; i++) { cin >> a; c.push_back(a); } sort(c.rbegin(), c.rend()); cout << c[k - 1] << endl; return 0; }
1
#include <bits/stdc++.h> #pragma GCC optimize(3) using namespace std; const long long N = 1010; inline long long read() { long long s = 0, w = 1; register char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') w = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') s = (s << 3) + (s <...
17
#include <bits/stdc++.h> using namespace std; typedef struct point { int x, y; } point; int graph[1010][1010]; int known[1010][1010]; int dist[1010][1010]; int n, m; vector<point> enemies; vector<int> num_enemies; point s, e; void bfs(point start); int main() { int i, j; n = ({ int x; scanf("%d", &x); ...
7
#include <bits/stdc++.h> using namespace std; int main(void) { int n, best, worst, d, ans = 0; cin >> n; cin >> d; best = d; worst = d; for (int i = 1; i < n; i++) { cin >> d; if (d > best) { best = d; ans++; } if (d < worst) { worst = d; ans++; } } cout << an...
0
#include <bits/stdc++.h> int ans[300005]; using namespace std; int main() { int n; scanf("%d", &n); for (int i = 0; i < n; ++i) scanf("%d", &ans[i]); int max_cnt = 0; for (int i = 0; i < n; ++i) { if (ans[i] != ans[0]) max_cnt = max(max_cnt, i); if (ans[n - 1] != ans[i]) { max_cnt = max(max_cnt,...
3
#include <bits/stdc++.h> using namespace std; void bla() { ios::sync_with_stdio(0); ios_base::sync_with_stdio(0); cin.tie(0), cout.tie(0); } int main() { bla(); int n, d; cin >> n >> d; int arr[n]; long long s = 0; for (int i = 0; i < int(n); i++) cin >> arr[i], s += arr[i]; long long sum = 0, i = 0...
1
#include <bits/stdc++.h> using namespace std; const int N = 1010; int g[N][N]; vector<int> res; int n, m; bool st[N][N]; void bfs(int sx, int sy) { queue<pair<int, int>> q; q.push({sx, sy}); st[sx][sy] = true; int dx[] = {0, 1, 0, -1}, dy[] = {-1, 0, 1, 0}; int cnt = 0; while (q.size()) { auto t = q.fro...
6
#include <bits/stdc++.h> #pragma GCC optimize(3) using namespace std; long long n; int main() { scanf("%d", &n); if (n % 2 == 0) printf("home"); else printf("contest"); return 0; }
1
#include <bits/stdc++.h> using std::pair; using std::string; using std::vector; const int oo = 0x3f3f3f3f; template <typename T> inline bool chkmax(T &a, T b) { return a < b ? a = b, true : false; } template <typename T> inline bool chkmin(T &a, T b) { return b < a ? a = b, true : false; } string procStatus() { s...
22
#include <bits/stdc++.h> using namespace std; void swap(int &a, int &b) { int tmp = a; a = b; b = tmp; } int main() { int n, k; cin >> n >> k; long long x, y, orang[1005]; double jarak[1005]; for (int i = 0; i < n; i++) { cin >> x >> y >> orang[i]; jarak[i] = sqrt(x * x + y * y); } for (int ...
4
#include <bits/stdc++.h> using namespace std; inline int read() { int n = 0; char c; for (c = getchar(); c < '0' || c > '9'; c = getchar()) ; for (; c >= '0' && c <= '9'; c = getchar()) n = n * 10 + c - 48; return n; } const int maxn = 5e5 + 5, mo = 998244353, re1 = ((mo + 1) >> 1) - 1; int i, j, n, f[max...
20
#include <bits/stdc++.h> using namespace std; long long a[1200000], s[1200000]; set<int> ss; int main() { ios::sync_with_stdio(false); int n, ans = 0, ans2; cin >> n; for (int i = 1; i <= n; i += 1) cin >> a[i]; sort(a + 1, a + n + 1, greater<long long>()); for (int i = 1; i <= n; i += 1) s[i] = s[i - 1] + ...
16
#include <bits/stdc++.h> using namespace std; void solve() { long long int i, j, k = 0, l, m, n, o, p, q, r, po[11]; cin >> n; p = n; n += n - 1; q = r = 0; po[0] = 1; for (i = 1; i <= 10; i++) po[i] = po[i - 1] * 10; while (n > 0) { k++; if (n % 10 != 9) { r = 1; } n /= 10; q ...
10
#include<bits/stdc++.h> using namespace std; #define ll long long int main() { int k; cin>>k; while(k--){ int n; cin>>n; vector<long long int> vec; for(int i=0;i<n;i++){ int x; cin>>x; vec.push_back(x); } ll cnt=0; f...
7
#include <bits/stdc++.h> using namespace std; const int MAXN = 100000; const double EPS = 1e-9; bool operator<(const complex<double>& a, const complex<double>& b) { if (fabs(a.imag() - b.imag()) > EPS) return a.imag() < b.imag(); return a.real() + EPS < b.real(); } class cmp { public: complex<double> about; cm...
13
#include <bits/stdc++.h> std::queue<int> q; const int N = 300005; struct Edge { int x, y; } a[N]; int r[N], f[N], p[N], last[N], Next[N << 1], to[N << 1], n, x, y, edge, m, cnt; void add(int x, int y) { to[++edge] = y; Next[edge] = last[x]; last[x] = edge; } void tuopu() { int rest = n; for (int i = 1; i <=...
21
#include <bits/stdc++.h> using namespace std; int main() { long long int n, k, i = 0; cin >> k; string s = "codeforces"; vector<int> v(10, 1); n = 1; while (n < k) { n /= v[i]; v[i]++; n *= v[i]; i++; i %= 10; } for (i = 0; i < 10; i++) { while (v[i]--) { cout << s[i]; ...
7
#include <bits/stdc++.h> using namespace std; int main() { long long n, k; cin >> n >> k; int arr[n]; int cnt[101] = {0}; for (int i = 0; i < n; i++) { cin >> arr[i]; cnt[arr[i]] += 1; } int m = INT_MIN; int c = 0; for (int i = 1; i <= 100; i++) { if (cnt[i] > 0) c++; if (cnt[i] > m) m...
1
#include <bits/stdc++.h> using namespace std; int p[100000 + 10], f[100000 + 10]; bool mark[100000 + 10]; int find(int x) { return f[x] == x ? x : find(f[x]); } int main() { int n; scanf("%d", &n); int ans = 0; for (int i = 0; i < n - 1 + 1; i++) { int x; scanf("%d", &x); if (x - 1 == i) ans++; ...
5
#include <bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; using db = double; using ld = long double; template <typename T> using V = vector<T>; template <typename T> using VV = vector<vector<T>>; constexpr ll mod = 1000000007; constexpr ll INF = 1000000099; constexpr ll LINF = ...
13
#include <bits/stdc++.h> const int N = 110; const double EPS = 1e-10; inline int sig(double p) { return (p > EPS) - (p < -EPS); } inline double sqr(double p) { return p * p; } double dp[N]; int x[N], y[N]; int main() { int n, k, eps; scanf("%d%d%d", &n, &k, &eps); int x0, y0; scanf("%d%d", &x0, &y0); for (int...
13
#include <bits/stdc++.h> using namespace std; int arr[300005][2]; int n, m; bool check(int x, int y) { for (int i = 1; i <= m; i++) if (arr[i][0] != x && arr[i][1] != x && arr[i][0] != y && arr[i][1] != y) return 0; return 1; } int main() { cin >> n >> m; for (int i = 1; i <= m; i++) scanf("%d%d", &ar...
7
#include <bits/stdc++.h> using namespace std; int a[1001], sum, minSum = 1000000000, minT, t, n, maxElement; int main() { if (0) { freopen("CP.inp", "r", stdin); freopen("CP.out", "w", stdout); } ios_base::sync_with_stdio(false); cin >> n; for (int i = 1; i <= n; ++i) { cin >> a[i]; maxElement...
3
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") #define ll long long ll ceil(ll a, ll b) { return (a + b - 1) / b; } int main() { ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); int tt; cin >> tt; while(tt --) { ll A, B, n, ans = 1; ...
1
#include <bits/stdc++.h> using namespace std; const int INF = 2000000000; const double PI = 3.141592653589793; const double EPS = 1e-9; vector<long long> mas; long long pl, pr, vl, vr, k; void Generate() { mas.push_back(4); mas.push_back(7); int p = 0; int q = 10; while (q < 1000000000) { int i = p; p...
11
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; const int N = 1e6 + 6; const int inf = 1e18; struct segt { vector<ll> t, ta; int d; segt(vector<ll> v) { for (d = 2; d < v.size(); d <<= 1) ; t.assign(d * 2, inf); ta.assign(d * 2, 0LL); for (int i = ...
16
#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...
10
#include <bits/stdc++.h> using namespace std; vector<int> g[10]; bool used[10], matr[10][10]; void dfs(int v) { used[v] = true; for (int i = 0; i < (int)g[v].size(); i++) { int u = g[v][i]; if (!used[u]) dfs(u); } return; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, m; cin >> ...
9
#include <bits/stdc++.h> using namespace std; template <class A, class B> inline bool mina(A &first, B second) { return (first > second) ? (first = second, 1) : 0; } template <class A, class B> inline bool maxa(A &first, B second) { return (first < second) ? (first = second, 1) : 0; } const double EPS = 1e-6; map<c...
16
#include <bits/stdc++.h> using namespace std; int n; vector<int> parent; vector<vector<int>> children; int max_degree; vector<pair<int, int>> result; void into(int root, int time) { int orig_time = time; result.emplace_back(root + 1, time); for (int i = 0; i < children[root].size(); i++) { time++; if (tim...
18
#include <bits/stdc++.h> using namespace std; inline void setmin(int &x, int y) { if (y < x) x = y; } inline void setmax(int &x, int y) { if (y > x) x = y; } inline void setmin(long long &x, long long y) { if (y < x) x = y; } inline void setmax(long long &x, long long y) { if (y > x) x = y; } const int N = 2000...
19
#include <bits/stdc++.h> using namespace std; int main() { long long int a, b, c; cin >> a >> b >> c; long long int n; cin >> n; vector<long long int> usb, ps; long long int val; string name; for (long int i = 0; i < n; i++) { cin >> val >> name; if (name == "USB") { usb.push_back(val); ...
6
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, i, j; cin >> n; int l[n], r[n], l1[n], l2[n], r1[n], r2[n]; for (i = 0; i < n; i++) { cin >> l[i] >> r[i]; } int max1 = -1, max2 = -1; int min1 = INT_MAX, min2 = INT_MAX; for (i = 0...
8
#include <bits/stdc++.h> using namespace std; int n, a, p1, p2; int main() { cin >> n; for (int i = 0; i < n; i++) { cin >> a; if (a == n) { p2 = i + 1; } if (a == 1) { p1 = i + 1; } } cout << max((n - min(p1, p2)), (max(p1, p2) - 1)); }
0
#include <bits/stdc++.h> using namespace std; const int MOD = 1000000007; int K; long long PA, PB, dem; long long dp[1005][1005]; long long expo(long long a, long long b) { if (b == 0) return 1; if (b == 1) return a; if (b % 2 == 0) return expo(a * a % MOD, b / 2); return a * expo(a * a % MOD, (b - 1) / 2) % MO...
14
#include <bits/stdc++.h> using namespace std; int t, n; void solve() { int b, f = 1; for (int i = 1; i <= n; i++) { cin >> b; int k = 0; while (b % (i + 1 - k) == 0 && k <= i - 1) k++; if (k == i) f = 0; } cout << (f ? "YES" : "NO"); } void read_file() { freopen("traffic.in", "r", stdin); fr...
5
#include <bits/stdc++.h> using namespace std; vector<bool> visited; vector<vector<int>> v; vector<bool> cats; int nodes; int cnt; int ans = 0; int catsNum; void dfs(int x, int cnt) { int count = cnt; visited[x] = true; if (cats[x]) count++; else count = 0; if (count > catsNum) return; if (v[x].size(...
7
#include <bits/stdc++.h> using namespace std; vector<vector<int> > g; vector<int> root; vector<bool> visited; vector<int> level; void DFS(int source) { visited[source] = true; for (auto u : g[source]) { if (!visited[u]) { level[u] = level[source] + 1; DFS(u); } } } int main() { int n; cin ...
1
#include <bits/stdc++.h> using namespace std; long long n, m, k, ans; long long a[2510][2510], s[2510][2510], sum[2][2510]; long long read() { long long r = 0, f = 1; char c = getchar(); while (c < '0' || c > '9') { if (c == '-') f = -1; c = getchar(); } while (c <= '9' && c >= '0') r = (r << 1) + (r ...
22
#include <bits/stdc++.h> using namespace std; int tc, cnt[30]; string s, t; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> tc; while (tc--) { cin >> s >> t; memset(cnt, 0, sizeof(cnt)); for (int i = 0; i < s.size(); i++) { cnt[s[i] - 'a'] |= 1; cnt[t[i] ...
2
#include <bits/stdc++.h> const char Directory[300] = "/Users/carlosjosetoribio/NetBeansProjects/Runner/dist/Debug/GNU-MacOSX/" "runner"; using namespace std; int ppl[1003]; int main(int argc, char** argv) { if (strcmp(argv[0], Directory) == 0) { freopen("in.txt", "r", stdin); } int N, M, H; scanf("%...
8
#include <bits/stdc++.h> using namespace std; const long long MOD = 1000000007; const int nMax = 2005; const int kMax = 1000005; long long comb[nMax][nMax]; long long fact[kMax]; void SetVals() { comb[0][0] = 1; for (int i = 1; i < nMax; ++i) { comb[i][0] = 1; for (int j = 1; j <= i; ++j) comb[i][j] =...
15
#include <bits/stdc++.h> int main() { char text[101]; scanf("%s", text); for (int i = 1; text[i] != '\0'; i++) { if (text[i] >= 'a' && text[i] <= 'z') { printf("%s", text); return 0; } } for (int i = 0; text[i] != '\0'; i++) { printf("%c", text[i] ^ 32); } return 0; }
2
#include <bits/stdc++.h> using namespace std; const int max_n = 42, max_m = 11, max_q = 9, mod = 1000000007, max_log = 20, inf = 1011111111; const long double eps = 1e-7; int n, m, b, x[max_n][max_m * 2], cost[max_m], sum[2][max_n + max_m * 2], T, true_m, used1[max_m], used[max_n + max_m * 2], privet, ptr...
25
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string f, s; cin >> f >> s; int num11 = 0, num10 = 0, num01 = 0; for (int i = 0; i < 2 * n; i++) { if (f[i] == '1' && s[i] == '1') num11++; if (f[i] == '1' && s[i] == '0') num10++; if (f[i] == '0' && s[i] == '1') num01++...
7
#include <bits/stdc++.h> using namespace std; char car[] = {'v', '<', '^', '>'}; bool checa(int ini, int fin, int pasos) { pasos %= 4; int aux = 4 + pasos; aux %= 4; ini = (ini + aux) % 4; return (ini == fin); } int num(char c) { int ret = 0; for (int i = 0; i < 4; i++) { if (car[i] == c) { retu...
1
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); int a, b, c, d; cin >> a >> b >> c >> d; cout << (((b + c - 1) / c) * a + d - 1) / d; }
0
#include <bits/stdc++.h> using namespace std; long long t = 1, n, m, x, y, s, k, r; vector<pair<long long, long long>> a; vector<vector<long long>> d; bool tr(long long f, long long h) { long long z = 1; for (int i = 0; i < n; i++) { if (h <= i) r = i - h; else r = n - (h - i); if (d[i].size...
9