solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> using namespace std; const int oo = 0x3f3f3f3f; const int MAX_N = 100005; const int MAX_M = 100005; struct Operation { int type, x, y; Operation() {} Operation(int type, int x, int y) { this->type = type; this->x = x; this->y = y; } }; struct Node { int size; long long s...
17
#include <bits/stdc++.h> using namespace std; int N; long long d[5][100010]; long long a[5][100010]; long long sum[5][100010]; int main() { scanf("%d", &N); for (int i = 1; i <= 3; i++) { for (int j = 1; j <= N; j++) { scanf("%lld", &a[i][j]); sum[i][j] = sum[i][j - 1] + a[i][j]; sum[4][j] = s...
15
#include <bits/stdc++.h> using namespace std; int a[200000]; int d[200000], d1[200000]; int main() { int n; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < n; i++) { if (i > 0) { d[i] = d[i - 1]; } if (i > 0) { d1[i] = d1[i - 1]; } if (a[i] == 0) ...
8
#include <bits/stdc++.h> using namespace std; const int mx = 1e9; string s; int n; int main() { cin >> n; if (n == 1) { cout << "10 10\n"; cout << "0 0 0 1000000000\n"; return 0; } int lx = 0, rx = mx; for (int i = 1; i <= n / 2; i++) { int mid = lx + rx >> 1; cout << 0 << " " << mid << en...
11
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } sort(a.begin(), a.begin() + n); cout << a[n / 2]; }
0
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; const double PI = 3.14159265359; const long long MOD = 998244353; void i_o() {} vector<vector<long long>> A; long long n, m; long long b00; vector<vector<long long>> dp(101, vector<long long>(101, LLONG_MAX)); long long help() { long long an...
14
#include <bits/stdc++.h> using namespace std; const int mxn = 1000100; int n, d[mxn][2], pr[mxn]; char s[mxn]; int main() { gets(s); n = strlen(s); int pr = -1; for (int i = 0, j; i < n; i = j) { if (s[i] == '0') j = i + 1; else { for (j = i; s[j] == '1'; ++j) ; int k = j - i; ...
11
#include <bits/stdc++.h> using namespace std; void Out(vector<int>& a) { for (int i = 0; i < a.size(); i++) cout << a[i] << ' '; } void Input(vector<int>& a) { for (int i = 0; i < a.size(); i++) { cin >> a[i]; a[i]; } } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; ci...
12
#include <bits/stdc++.h> using namespace std; template <typename T> ostream& operator<<(ostream& os, vector<T>& vect) { for (auto t : vect) os << t << " "; return os; } map<long long, pair<long long, long long> > ans; long long m; vector<long long> kub; void solve(long long a) { if (ans.find(a) != ans.end()) ...
14
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n; int c = 1; pair<int, char> ch; cin >> n; int flag = 0; ch = make_pair(1, 2); for (int i = 0; i < n; i++) { int x; cin >> x; if (ch.first == 1 && ch.second ==...
1
#include <bits/stdc++.h> using namespace std; void fast_input() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); } long long ask(long long x, long long y) { cout << x << ' ' << y << endl; string s; cin >> s; return (s == "black"); } signed main() { fast_input(); long long n; cin >> n; long long ...
11
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long m, n; cin >> n >> m; long long left = abs(m - 1); long long right = abs(n - m); long long ans = 0; if (left >= right) ans = m - 1; else ans = m + 1; ans = max(an...
5
#include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int, int>; using vi = vector<int>; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n; cin >> n; vector<int> vec; int clei = 0, jiro = 0; for (int i = 0; i < n; i++) { int s, e; ...
12
#include <bits/stdc++.h> using namespace std; int f[2005]; int type[2005], h[2005], mass[2005], n, x; int solve(int typ) { int i, j, now = x, ret = 0; int last = typ; memset(f, (0), sizeof(f)); while (1) { int p = -1, best = 0; for (i = 0; i < n; i++) { if (f[i] || last == type[i]) continue; ...
7
#include <bits/stdc++.h> using namespace std; int a[2222]; long long dp[2222][2222]; int main() { int n, h; bool flag = 1; scanf("%d%d", &n, &h); for (int i = 1; i <= n; i++) { scanf("%d", a + i); a[i] = h - a[i]; if (a[i] < 0) flag = 0; } if (!flag) { puts("0"); return 0; } a[n + 1]...
13
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int k, n; cin >> n >> k; int arr[n]; for (int i = 0; i < n; i++) cin >> arr[i]; if (k == 1) cout << *min_element(arr, arr + n); else if (k == 2) cout << max(arr[0], arr[n - 1]); ...
4
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") using namespace std; int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } void read(int arr[], int n) { for (int i = 0; i < n; ++i) cin >> arr[i]; } void printv(vector<int> arr, int n) { for (int i = 0; i < n; ++i) cout << arr[i] << " "; ...
10
#include <bits/stdc++.h> using namespace std; int main() { int n, p; cin >> n; vector<vector<int> > adj(n); for (int i = int(1); i < int(n); i++) { cin >> p; adj[i].push_back(p - 1); adj[p - 1].push_back(i); } vector<int> anterior(n, -1); vector<bool> visitado(n, false); queue<int> q; visi...
1
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int a, b; cin >> a; vector<long long int> v; long long int ar[a]; for (long long int i = 0; i < a; i++) { cin >> ar[i]; v.push_back(ar[i]); } cin >> b; long long int br[b]; ...
8
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; long long sum = 0; long long x; for (int i = 0; i < n; i++) { cin >> x; sum += x; } int cnt = 0; while (true) { float x = (sum / float(n + cnt)); if (round(x) == k) { cout << cnt; return 0; ...
1
#include <bits/stdc++.h> using namespace std; using ulli = unsigned long long int; ulli p3(ulli x) { ulli ret = 0, ar = 1; while (x > 0) { ret += ar * (x & 1); ar *= 3; x /= 2; } return ret; } int main() { ios::sync_with_stdio(0); long long int q; cin >> q; while (q--) { ulli n; cin ...
5
#include <bits/stdc++.h> using namespace std; int X[] = {1, -1, 0, 0}; int Y[] = {0, 0, 1, -1}; const int N = 2e5 + 5; int n, m, q; vector<vector<int> > graph(101); map<pair<int, int>, vector<int> > clr; vector<vector<int> > ans(101, vector<int>(101, 0)); void bfs(int pos) { queue<int> q; q.push(pos); vector<vect...
6
#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; } std::mt19937 rnd(time(NULL)); template <class T> void cxk(T& a, T b) { a = a > b ? a : b...
23
#include <bits/stdc++.h> using namespace std; int n; int main() { int n, odd = 0, even = 0; cin >> n; long long a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; if (a[i] % 2 == 0) even++; else odd++; } even >= odd ? cout << odd : cout << even; cout << endl; return 0; }
1
#include <bits/stdc++.h> using namespace std; vector<int> v[10005]; int main() { int n; scanf("%d", &n); int i; int m; for (i = 1;; i++) { if (i * (i - 1) / 2 <= n) m = i; else break; } cout << m << endl; int j; int cnt = 1; for (i = 1; i <= m; i++) { for (j = i + 1; j <= m; ...
8
#include <bits/stdc++.h> using namespace std; template <typename T> inline void out(T a) { int i = 0; char s[20]; if (a == 0) s[i++] = '0'; if (a < 0) putchar('-'), a = -a; while (a > 0) s[i++] = a % 10 + '0', a /= 10; --i; while (i >= 0) putchar(s[i--]); putchar(' '); } inline void out(char a) { putcha...
6
#include <bits/stdc++.h> using namespace std; int v[200009]; int main() { ios_base::sync_with_stdio(NULL); cin.tie(0); cout.tie(0); int n, p; cin >> n; for (int i = 1; i <= n; ++i) { cin >> v[i]; if (v[i] == n) p = i; } for (int i = p - 1; i > 0; --i) if (v[i] > v[i + 1]) return cout << "NO"...
2
#include <bits/stdc++.h> using namespace std; const int MAX = 1e5; int ans; int res[2 * MAX + 5]; char a[MAX + 5], b[MAX + 5]; int main() { int T; scanf("%d", &T); while (T--) { int N; scanf("%d", &N); getchar(); scanf("%s%s", a + 1, b + 1); for (int i = 1; i <= N; i++) { a[i] = a[i] - '...
5
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int n, q; uint16_t A; cin >> n; uint8_t a[200000]; ...
17
#include<bits/stdc++.h> #define pb push_back #define pf push_front #define mp make_pair #define fi first #define se second #define prec(n) fixed<<setprecision(n) #define ntest 1 using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; const int MOD = (int) 1e9 + 7; int t; void ...
0
#include <bits/stdc++.h> using namespace std; int main() { string a, b, c; cin >> a >> b >> c; if (a[0] == 'r' && b[0] == 's' && c[0] == 's') printf("F"); else if (a[0] == 's' && b[0] == 'r' && c[0] == 's') printf("M"); else if (a[0] == 's' && b[0] == 's' && c[0] == 'r') printf("S"); else if (a[...
1
#include <bits/stdc++.h> using namespace std; void fail() { cout << -1 << endl; exit(0); } int main() { int K, N; cin >> K >> N; set<string> st; for (int i = 0; i < K; i++) { string s; cin >> s; st.insert(s); } vector<string> S; for (auto& s : st) S.push_back(s); K = S.size(); string s...
14
#include <bits/stdc++.h> using namespace std; const long long INF = 1 << 28; const long long LINF = 1ll << 61; int n, m; long long a[111], mod, g[111][111], mx; void failed() { cout << "NO" << endl; exit(0); } int main() { ios::sync_with_stdio(false); cin >> n >> m; for (int i = 1; i <= n; i++) for (int j...
14
#include <bits/stdc++.h> using namespace std; inline void rd(int &res) { res = 0; char c; while (c = getchar(), c < 48) ; do res = (res << 1) + (res << 3) + (c ^ 48); while (c = getchar(), c >= 48); } void print(int x) { if (!x) return; print(x / 10); putchar((x % 10) ^ 48); } void sc(int x) { if ...
8
#include <bits/stdc++.h> using namespace std; long long n, N, sum, p[4 * 4]; bool ok(vector<long long> v) { sort(v.begin(), v.end()); for (long long i = 0; i < N; i++) if (p[i] != v[i]) return false; return true; } long long cnt[4 * 4], ans[4][4], lef[4 * 4 - 4]; vector<vector<long long> > v, vec; set<pair<pa...
13
#include <bits/stdc++.h> using namespace std; const long long N = (1e6 + 10); const long long mod = (1e9 + 7); int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >> n; for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { if (i * j > n && i / j < n && i % j == 0) { cou...
0
#include <bits/stdc++.h> using namespace std; struct edge { int v, next; } e[100000 + 5 << 1]; bool book[1000000 + 5]; int n, cnt, tot, ans = 123456789, a[100000 + 5], h[1000000 + 5], prime[1000000 + 5], dis[1000000 + 5], fa[1000000 + 5]; int read() { char c; int x = 0, f = 1; c = getchar(); ...
18
#include <bits/stdc++.h> using namespace std; const int mn = 3e5 + 5; const long long int mod = 1e9 + 7; const long long int inf = 1e18; long long int inv(long long int a, long long int g) { long long int ag = 1; while (g) { if (g % 2 == 1) { ag = (ag % mod * a % mod) % mod; } a = (a % mod * a % m...
5
#include <bits/stdc++.h> using namespace std; inline long long rd() { long long x = 0; int ch = getchar(), f = 1; while (!isdigit(ch) && (ch != '-') && (ch != EOF)) ch = getchar(); if (ch == '-') { f = -1; ch = getchar(); } while (isdigit(ch)) { x = (x << 1) + (x << 3) + ch - '0'; ch = getch...
17
#include <bits/stdc++.h> using namespace std; const int N = 2010; int n, root, c[N], sz[N]; vector<int> a[N]; int ans[N]; void dfs_sz(int nod) { sz[nod] = 1; for (int i : a[nod]) { dfs_sz(i); sz[nod] += sz[i]; } if (sz[nod] <= c[nod]) { printf("NO"); exit(0); } } vector<int> f; void dfs(int no...
10
#include <bits/stdc++.h> using namespace std; int v[1003]; int main() { int n; cin >> n; int ok = 0; for (int i = 1; i <= n; i++) { cin >> v[i]; } int bst = 0; for (int i = 1; i <= n + 1; i++) { int remove = 0; for (int j = 1; j <= n; j++) { if (v[j]) { if (j < i) { rem...
7
#include <bits/stdc++.h> using namespace std; const int mn = 1000; int T, n, k; char rep[10]; int main() { srand(time(0)); cin >> T; for (int z = 1; z <= T; z++) { cin >> n >> k; bool Gif = false; for (int zz = 1; zz <= 20; zz++) { printf("? 1 1\n"); printf("1\n"); printf("%d\n", ran...
18
#include <bits/stdc++.h> using namespace std; template <typename T> void print(T v) { cout << v << "\n"; } template <typename T> void print(vector<T> a) { for (int i = 0; i < a.size(); i++) { cout << a[i] << " "; } cout << "\n"; } void solve() { long long n; cin >> n; vector<long long> arr(n); bool ...
4
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx") using std::cin; using std::cout; struct BS { static const int size = 200000 / 64 + 1; unsigned long long a[size]; inline int count() const { int sum = 0...
27
#include <bits/stdc++.h> using namespace std; int Size; string str; int m[705]; const int MOD = 1000000007; long long mem[705][705][3][3]; long long DP(int l, int r, int cl, int cr) { long long ret = 0; if (mem[l][r][cl][cr] != -1) return mem[l][r][cl][cr]; if (l > r) return cl == 0 && cr == 0; int k = m[l]; ...
11
#include <bits/stdc++.h> using namespace std; int main() { int n, j, i; string str, str1, str2; cin >> n; for (i = 0; i < n; i++) { cin >> str; if (str.length() % 2 == 0) { j = str.length() / 2; str1 = str.substr(0, j); str2 = str.substr(j, j); if (str1 == str2) { cout <<...
0
#include <bits/stdc++.h> using namespace std; const int maxn = 100010; int s[maxn]; long long ok[maxn << 1]; int n, m, w; bool solve(long long x) { memset(ok, 0, sizeof(ok)); long long mm = m; for (int i = 1; i <= n; i++) { ok[i] += ok[i - 1]; if (ok[i] + s[i] < x) { long long fuck = x - (ok[i] + s[...
9
#include <bits/stdc++.h> using namespace std; int main() { int a, b, m, n, big, cal; cin >> a >> b; m = a; n = b; big = a % 10; while (a != 0) { cal = a % 10; a /= 10; if (cal > big) big = cal; } while (b != 0) { cal = b % 10; b /= 10; if (cal > big) big = cal; } int x = big ...
7
// <-- Coded by Pasindu_Piumal --> #include <bits/stdc++.h> using namespace std; #define ll long long #define ull unsigned long long int #define ld long double #define str string #define F first #define S second #define all(x) begin(x), end(x) #define pb push_back #define mp make_pair inline void io_setup(){ ios_bas...
0
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 6, nBits = 2e8 + 5, M = (1 << 16), MAX = 1111, OO = 0x3f3f3f3f, MOD = 1e9 + 7, inf = 1 << 30; const long long INF = (long long)1e18; long long GCD(long long a, long long b) { return !b ? a : GCD(b, a % b); } long long LCM(long long x, long long...
2
#include <bits/stdc++.h> using namespace std; int n, a[1001], k, d; int main() { cin >> n >> d; for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 1; i <= n; i++) { for (int j = i + 1; j <= n; j++) if (abs(a[i] - a[j]) <= d) k += 2; } cout << k; return 0; }
0
#include <bits/stdc++.h> using namespace std; template <typename TH> void _dbg(const char* sdbg, TH h) { cerr << sdbg << "=" << h << "\n"; } template <typename TH, typename... TA> void _dbg(const char* sdbg, TH h, TA... t) { while (*sdbg != ',') cerr << *sdbg++; cerr << "=" << h << ","; _dbg(sdbg + 1, t...); } ...
3
#include <bits/stdc++.h> using namespace std; const pair<int, int> dir[4] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}}; pair<int, int> operator+(const pair<int, int> &p1, const pair<int, int> &p2) { return make_pair(p1.first + p2.first, p1.second + p2.second); } pair<int, int> operator-(const pair<int, int> &p1, const pair<i...
19
#include <bits/stdc++.h> using namespace std; struct UnionFind { vector<int> f, setSize, edgesOfComp; vector<vector<long long>> waysOfComp; int cantSets, N; void init(int n) { N = n; f.clear(); setSize.clear(); cantSets = n; f.resize(n, -1); setSize.resize(n, 1); edgesOfComp.resize(n...
19
#include <bits/stdc++.h> using namespace std; const int N = 100005; int n, m; vector<int> a[N]; vector<pair<int, int> > v; set<pair<int, int> > s; int c[N]; int tin[N], fup[N]; int ti; void dfs(int x, int p) { c[x] = 1; fup[x] = tin[x] = ti++; for (int i = 0; i < a[x].size(); ++i) { int h = a[x][i]; if (h...
8
#include <bits/stdc++.h> int M, N; int main() { std::string line; std::getline(std::cin, line); std::istringstream iss0(line); iss0 >> N >> M; std::map<std::string, std::vector<char> > variables; variables["?"] = std::vector<char>(M, 2); for (int vi = 0; vi < N; vi++) { std::getline(std::cin, line); ...
10
#include <bits/stdc++.h> using namespace std; vector<long long> lis, lds; int CeilIndex(vector<long long> &v, long long l, long long r, long long key) { while (r - l > 1) { long long m = l + (r - l) / 2; if (v[m] >= key) r = m; else l = m; } return r; } int LIS(vector<long long> &v) { if...
11
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1.0); int dx[] = {-1, 0, 1, 0, 1, 1, -1, -1}; int dy[] = {0, 1, 0, -1, 1, -1, 1, -1}; map<string, int> mm; int n; int main() { char cmd[20]; string a, b, c; cin >> n; mm.clear(); mm["void"] = 0; for (int cas = 0; cas < n; ++cas) { sca...
10
#include <bits/stdc++.h> using namespace std; int main() { long long n, k; cin >> n >> k; string s; cin >> s; if (n == 1 && k >= 1) { cout << 0; return 0; } long long i = 0; while (k != 0 && i < (int)s.length()) { if (i == 0 && s[i] != '1') s[i] = '1', k--; if (i != 0 && s[i] != '0') s[i...
2
#include <bits/stdc++.h> using namespace std; const int N = 2e2 + 5, mod = (int)1e9 + 7; string s; int n, first[N], dp[N][N][N]; inline void build(string &s) { int j = 0; for (int i = (1); i <= (int)(s.size() - 1); ++i) { while (j && s[j] != s[i]) j = first[j - 1]; if (s[j] == s[i]) j++; first[i] = j; ...
15
#include <bits/stdc++.h> using namespace std; int n; int k; int a; int b; int used[101010]; vector<int> g[101010]; int ans = 0; int y = 0; int l; int dp[50007][1001]; void dfs(int v) { used[v] = 1; for (auto to : g[v]) { if (!used[to]) { dfs(to); for (int i = 1; i <= k; i++) { ans += dp[to][...
10
#include <bits/stdc++.h> using namespace std; const int INF = 5e8; int x[5], y[5]; int ans; vector<pair<int, int> > tr; void minimize(int &a, int b) { a = min(a, b); } void maximize(int &a, int b) { a = max(a, b); } int dist(int x1, int y1, int x2, int y2) { if (x1 == x2) return abs(y1 - y2); if (y1 == y2) return a...
22
#include <bits/stdc++.h> using namespace std; vector<vector<long long int> > arr(200001); long long int visited[200001]; long long int level[3][200001]; long long int parent[200001]; long long int path[200001]; vector<pair<long long int, pair<long long int, long long int> > > ppp; vector<long long int> leaf; void dfs(l...
16
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 10; vector<int> adj[maxn], tmp_to[maxn], son[maxn], to[maxn]; void Build(int k, int from) { for (int i = 0; i < adj[k].size(); i++) { if (adj[k][i] != from) { son[k].push_back(adj[k][i]); to[k].push_back(tmp_to[k][i]); } } fo...
9
#include <bits/stdc++.h> using namespace std; int main() { int k, n, t; cin >> n; t = n; k = n; vector<int> routers; while (--n) { int x; cin >> x; routers.push_back(x); } routers.push_back(t); vector<int> answer; while (1) { if (routers[t - 1] <= 1) { break; } answer.p...
1
#include <bits/stdc++.h> using namespace std; const int MN = 1000111; int n, a[MN], f[MN]; int main() { ios ::sync_with_stdio(false); while (cin >> n) { for (int i = (1), _b = (n); i <= _b; i++) cin >> a[i]; sort(a + 1, a + n + 1); int res = 0; for (int i = (1), _b = (n); i <= _b; i++) { int u...
7
#include <bits/stdc++.h> const int N = 100050; const int inf = 1e9 + 7; int gcd(int x, int y) { return x ? gcd(y % x, x) : y; } int min(int a, int b) { return a > b ? b : a; } int dp[N][2], a[N]; int main() { int n, i, g = 0; scanf("%i", &n); for (i = 1; i <= n; i++) scanf("%i", &a[i]), g = gcd(g, a[i]), a[i] %= ...
9
#include <bits/stdc++.h> using namespace std; const int sx[4] = {1, 0, -1, 0}; const int sy[4] = {0, 1, 0, -1}; int i, n, m, D[111000], f[111000], t[111000], p[111000], ii, fl[111000], o[111000], q1, q2, q[111000], vn, qq, v[111000], pr[111000], ret, j, a[111][111], c[111][111], k, x2, y2, it; void addedge(int ...
15
#include <bits/stdc++.h> using namespace std; int main() { double H, L, x; cin >> H >> L; x = ((L * L) - (H * H)) / (2.0 * H); cout.precision(15); cout << x << endl; }
2
#include <bits/stdc++.h> using namespace std; int main(int argc, char** argv) { char s[10000]; int i, n, m; int flag, num; while (cin >> s) { flag = 0; num = 0; n = strlen(s); for (i = 0; i < n; i++) { if (s[i] == '.') { m = i; } } for (i = m + 1; i < n; i++) { ...
0
#include <bits/stdc++.h> int a[100001]; int fx[100001]; int main() { int n, m, k; scanf("%d%d%d", &n, &m, &k); int i; for (i = 1; i <= n; i++) { scanf("%d", &a[i]); fx[a[i]] = i; } long long ans = 0; int x; for (i = 1; i <= m; i++) { scanf("%d", &x); int xtx = fx[x] - k; if (xtx > 0)...
8
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1.0); const double eps = 1E-7; int n, m; int main() { scanf("%d%d", &n, &m); long long ans = 0; for (int i = 1; i <= n; ++i) { int t, p, c, T; scanf("%d%d%d%d", &t, &T, &p, &c); long long k; t = T - t; if (t <= 0) { an...
11
#include <bits/stdc++.h> using namespace std; const int maxn = 5e5 + 5; const long long mod = 1e9 + 7; int dx[] = {1, 0, -1, 0}; int dy[] = {0, 1, 0, -1}; template <typename T> void scan(T& a) { cin >> a; } template <typename T, typename... Args> void scan(T& t, Args&... a) { scan(t); scan(a...); } template <type...
13
#include <bits/stdc++.h> using namespace std; const int N = 2020; int a[N], dp[N]; int getCost(int n, int can) { int ans = n; dp[0] = 0; for (int i = 1; i < n; ++i) { dp[i] = i; for (int j = 0; j < (i); ++j) { if (abs(a[i] - a[j]) <= (long long)(i - j) * can) { dp[i] = min(dp[i], dp[j] + (i ...
12
#include <bits/stdc++.h> using namespace std; const int mod1 = 1000013; const int mod2 = 1000019; std::vector<int> power1(100001); std::vector<int> power2(100001); void Power1(int base, int p, int m) { int res = 1; for (int i = 0; i < p; ++i) { power1[i] = res; res = (res * base) % m; } power1[p] = res;...
16
#include <bits/stdc++.h> using namespace std; int n, res; void mproc(void) { int ok; while (1) { int msqrt = sqrt(n); ok = 0; for (int i = (2); i <= (msqrt + 1); ++i) if (n % i == 0) { ok = 1; n /= i; if (n != 1) res += n; break; } if (!ok) { res += ...
4
#include <bits/stdc++.h> using namespace std; int largest_bit(int x) { return 31 - __builtin_clz(x); } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int N; cin >> N; vector<long long> A(N); for (auto &a : A) cin >> a; sort(A.begin(), A.end()); vector<long long> subset_sum(1 << N, 0); vec...
23
#include <bits/stdc++.h> int x[60000], v[60000], n; int check(double t) { double l = x[0] - v[0] * t, r = x[0] + v[0] * t; for (int i = 1; i < n; i++) { double nl = x[i] - v[i] * t, nr = x[i] + v[i] * t; if (l < nl) l = nl; if (r > nr) r = nr; if (l > r) return 0; } return 1; } int main() { in...
8
#include <bits/stdc++.h> using namespace std; const int INF = 1e9 + 7; int N, M; string s; int main(void) { cin >> N >> M >> s; int cnt = 0; for (int i = 0; i < (int)(N - 1); ++i) if (s[i] == '.' and s[i + 1] == '.') cnt++; for (int mmm = 0; mmm < (int)(M); ++mmm) { int i; char c; cin >> i >> c;...
8
#include <bits/stdc++.h> using namespace std; int n; int in[260], out[260], done[260]; int repr[8], open[260]; vector<pair<int, int>> edges; void active_node(int u) { done[u] = true; if (!repr[out[u]]) { repr[out[u]] = true; } } bool try_connect(int u) { if (repr[in[u]]) { edges.emplace_back(repr[in[u]]...
20
#include <bits/stdc++.h> using namespace std; int N, K; long long a[500500], b[500500], res; int main() { if (1) { scanf("%d %d", &N, &K); for (int i = (0); i < (N); i++) scanf("%lld", &a[i]); for (int i = (0); i < (N); i++) scanf("%lld", &b[i]); } else { srand(time(NULL)); N = 2200, K = rand() ...
16
#include <bits/stdc++.h> using namespace std; const int MAXN = 20010, MAXM = 20010; int n, m, p; int a[MAXN], b[MAXM]; int f[MAXN], g[MAXN]; void dp1(int n, int m, int a[], int b[], int limit) { f[0] = (a[0] + b[0]) % p; for (int i = 1; i <= limit; ++i) { int l = max(0, i - m + 1), r = min(n - 1, i); for (i...
17
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; int temp; int sum = 0; vector<int> current; vector<int> after; for (int i = 0; i < n; i++) { cin >> temp; current.push_back(temp); } for (int i = 0; i < n; i++) { cin >> temp; sum += temp; after.pus...
4
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long int n, v; cin >> n >> v; n--; if (n <= v) { cout << n << endl; } else { long long int cnt = v; for (long long int i = 2; i <= n; i++) { cnt += i; ...
1
#include <bits/stdc++.h> inline int read() { int s = 0; char c; while ((c = getchar()) < '0' || c > '9') ; do { s = s * 10 + c - '0'; } while ((c = getchar()) >= '0' && c <= '9'); return s; } const int N = 155; int n, m, i, j, po, l, r, mid, stp[N], dt, ie, ans, ymd; struct eg { int aa, bb, d; } e...
19
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { long long int n, r, t = 1; cin >> n >> r; if (n == t) { cout << 1 << endl; } else if (n <= r) { cout << 1 + ((n * (n - 1)) / 2) << endl; } else { cout << ((r * (r + 1)) / 2) << endl; ...
4
#include <bits/stdc++.h> using namespace std; const int inf = 1e9; const double eps = 1e-9; const int INF = inf; const double EPS = eps; struct __timestamper {}; class fenv_tree { static int f(int x) { return x & -x; } vector<int> tr; public: fenv_tree(int n) : tr(n + 1, -inf) {} void relax(int x, int v) { ...
16
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf("%d", &n); vector<vector<bool> > grid(n, vector<bool>(n, false)); int tmp; for (int i = int(0); i <= int(n - 1); i++) for (int j = int(0); j <= int(n - 1); j++) { scanf("%d", &tmp); grid[i][j] = tmp; } int q; scanf...
8
#include <bits/stdc++.h> using namespace std; const long double EPS = 1e-9, PI = acos(-1.); const int INF = 0x3f3f3f3f, MOD = 1e9 + 7; const int N = 1e5 + 5; int n, m, a, b[N], p[N]; int main() { scanf("%d%d%d", &n, &m, &a); for (int i = 0; i < n; ++i) scanf("%d", &b[i]); for (int i = 0; i < m; ++i) scanf("%d", &...
10
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { if (b == 0) return a; return gcd(b, a % b); } long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); } int main() { long long n, i, x, p = 0, q = 0; cin >> n; vector<long long> a; for (i = 0; i < n; i++) {...
1
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); int n, num, i; cin >> n; long long int sum = 0ll; int ans = n - 1; map<long long int, int> m; for (i = 0; i < n; ++i) { cin >> num; sum += num; m[sum]++; ans = min(ans, n - m[sum]); } cout << ans <<...
13
#include <bits/stdc++.h> using namespace std; const long long N = 100100; long long n, a, b, c, d, ans = 0; int main() { cin >> n >> a >> b >> c >> d; for (int i = 1; i <= n; ++i) { long long x2 = i + b - c; long long x3 = i + a - d; long long x4 = x3 + b - c; if (x2 < 1 || x3 < 1 || x4 < 1 || x2 > ...
6
#include <bits/stdc++.h> using namespace std; template <typename T> inline T fetch() { T ret; cin >> ret; return ret; } template <typename T> inline vector<T> fetch_vec(long long sz) { vector<T> ret(sz); for (auto& it : ret) cin >> it; return ret; } template <typename T> inline void makeUnique(vector<T>& v)...
9
#include <bits/stdc++.h> using namespace std; int main() { int n, k, r, l, sa, sk, i; scanf("%d%d%d%d%d%d", &n, &k, &l, &r, &sa, &sk); int x = sk / k; int y = sk % k; for (i = 0; i < y; i++) { printf("%d ", x + 1); } for (i = 0; i < k - y; i++) { printf("%d ", x); } if (n - k != 0) { x = (...
6
#include <bits/stdc++.h> using namespace std; const int MAXN = 4 * 105000; int n, can; int a[MAXN]; int sum[MAXN]; int st[MAXN], en[MAXN]; void solve() { scanf("%d %d", &n, &can); for (int i = 0; i < n; i++) scanf("%d", &a[i]); for (int i = 0; i <= 2 * can; i++) { sum[i] = 0; st[i] = 0; en[i] = 0; }...
0
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int c1 = 0, c2 = 0; int x, y; for (int i = 0; i < n; i++) { cin >> x >> y; if (x > y) c1++; else if (y > x) c2++; else continue; } if (c1 > c2) cout << "Mishka" << endl; else if (c2 > c1) ...
0
#include <bits/stdc++.h> using namespace std; int main() { int int_h = 0; int int_m = 0; string h = ""; string m = ""; string str; cin >> str; h.push_back(str[0]); h.push_back(str[1]); m.push_back(str[3]); m.push_back(str[4]); int_h = (str[0] - '0') * 10 + (str[1] - '0'); int_m = (str[3] - '0') ...
2
#include<bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define pb push_back #define vll vector<ll> #define pll pair<ll,ll> #define vpll vector<pll> #define ub upper_bound #define lb lower_bound #define all(v) ((v).begin()),((v).end()) #define allr(v) ((v).rbegin()),((v).rend()) #define...
14
#include <bits/stdc++.h> using namespace std; int readInt() { int x; if (scanf(" %d", &x) != EOF) return x; return -1; } long long int readLint() { long long int x; if (cin >> x) return x; return -1; } string readString() { string s; if (cin >> s) return s; return ""; } struct Graph { int n; vecto...
16
#include <bits/stdc++.h> using namespace std; const int maxn = 100000; const int mod = 1000000007; char c[maxn + 5]; int b[] = {1, 2, 4, 8, 16, 32}; int e[] = {1, 3, 9, 27, 81, 243, 729}; int d[65]; int main() { scanf(" %s", &c); int l = strlen(c); for (int i = 0; i <= 63; ++i) { int x = i; d[i] = 0; ...
7