solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; const long long int oo = 1e18; const long long int mod = 1e9; const int base = 31; const int tx[4] = {0, 0, 1, -1}; const int ty[4] = {1, -1, 0, 0}; const long long int maxN = 100 + 5; long long int n; string s1; void solve() { cin >> n >> s1; ...
7
#include <bits/stdc++.h> long long n, a[10005], b[10005], ac, hd, tl, mid, c, cnt, lw, hi; int main() { scanf("%I64d%I64d", &n, &c); for (long long i = 1; i <= n; i++) scanf("%I64d%I64d", &a[i], &b[i]); hd = 1; tl = (1 << 30); lw = -1; while (hd <= tl) { mid = (hd + tl) / 2; cnt = 0; for (long l...
9
#include <bits/stdc++.h> using namespace std; const int maxn = 200005; int n; int ans[maxn]; int tree[maxn]; struct node { int val; int id; bool friend operator<(const node u, const node v) { return u.val < v.val; } } p[maxn]; int lowbit(int k) { return k & (-k); } void add(int x) { while (x <= n) { tree[x]...
14
#include <bits/stdc++.h> using namespace std; string slash = "/"; string ad = "://"; string dot = "."; string dom = "ru"; int main() { string str; string strue; cin >> str; int sizee = str.size(); int m = 0; if (str[0] == 'f') { strue = "ftp" + ad; m += 3; } if (str[0] == 'h') { strue = "htt...
3
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t; cin >> t; while (t--) { string s; cin >> s; s.push_back('R'); int cur = 0; int mx = 0; for (int i = 0; i < s.size(); i++) { if (s[i] == 'R') { mx = max(mx, i...
3
#include <bits/stdc++.h> using namespace std; const int inf = 2e9; const double eps = 1e-9; const int mod = 998244353; int n, m, x; void solve(int tc) { cin >> n >> m; vector<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]; } reverse(a.begin(...
13
#include <bits/stdc++.h> using namespace std; int main() { int N, i; cin >> N; long long int num1[N], num2[N], sum = 0; for (i = 0; i < N; i++) { cin >> num1[i]; sum += num1[i]; } for (i = 0; i < N; i++) cin >> num2[i]; sort(num2, num2 + N); if (num2[N - 1] + num2[N - 2] >= sum) cout << "YES...
1
#include <bits/stdc++.h> using namespace std; int n, m, x, y; int nowx, cur = 1, ncur; int st, ed, id; pair<int, int> p[100005]; vector<pair<int, int> > v, nv; int main() { scanf("%d%d", &n, &m); for (int i = 1; i <= m; i++) { scanf("%d%d", &x, &y); p[i] = make_pair(x, y); } sort(p + 1, p + m + 1); v....
17
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; int b[100] = {0}, g[100] = {0}; int B, G; cin >> B; int x; for (int i = 1; i <= B; i++) { cin >> x; b[x] = 1; } cin >> G; for (int i = 1; i <= G; i++) { cin >> x; g[x] = 1; } for (int i = 1; i <= ...
5
#include <bits/stdc++.h> using namespace std; int t,s; struct p{ int x; int y; }; struct a{ int s; p pos[4]; }; char ch; a zip[405]; int main(){ cin>>t; for(int times=0;times<t;times++){ cin>>zip[times].s; int k=0,flag=1; for(int i=1;i<=zip[times].s;i++){ f...
0
#include <bits/stdc++.h> using namespace std; template <class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p) { os << "(" << p.first << ", " << p.second << ")"; return os; } template <class T> ostream& operator<<(ostream& os, const vector<T>& v) { os << "{"; for (int i = 0; i < (int)v.size(); ...
17
#include <bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; const int N = 205, P = 10007; char s[N]; int n, m, f[N][N][N], len, g[N], ans; struct matrix { int f[N * 2][N * 2]; matrix() { memset(f, 0, sizeof(f)); } inline matrix operator*(const matrix &b) const { matrix c; for (int i = 1; i <=...
22
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 100; long long a[maxn], b[maxn]; void solve() { int n, m; scanf("%d%d", &n, &m); for (int i = 0; i < n; ++i) scanf("%lld", &a[i]); sort(a, a + n); long long sum(0), cnt(0); for (int i = 0; i < n; ++i) { if (i) cout << " "; b[i % m]...
7
#include <bits/stdc++.h> using namespace std; long long power(long long a, long long b, long long m) { long long ans = 1; while (b) { if (b & 1) ans = (ans * a) % m; b /= 2; a = (a * a) % m; } return ans; } int main() { long long t = 1, b = 1; while (t--) { map<long long, long long> m[26]; ...
10
#include <bits/stdc++.h> using namespace std; bool s[1001]; int main() { int n; cin >> n; int m; cin >> m; vector<pair<int, int> > v; for (int i = 0; i < m; i++) { int a, b; cin >> a >> b; s[a] = true; s[b] = true; } int sm; for (int i = 1; i <= n; i++) { if (!s[i]) { sm = i;...
5
#include <bits/stdc++.h> using namespace std; int main() { string letter; cin >> letter; pair<int, int> dp[letter.size()]; dp[0] = make_pair(0, islower(letter[0]) ? 1 : 0); for (int i = 1; i < letter.size(); ++i) { if (islower(letter[i])) { dp[i].second = dp[i - 1].second + 1; dp[i].first = dp...
6
#include <bits/stdc++.h> using namespace std; const int INF = (int)1e18; int main() { long long b, c, d, i, j, k, l, n, x, y, t, ans; cin >> n; long long a[n]; for (i = 0; i < n; i++) { cin >> a[i]; } cout << 1 << " " << 1 << endl << -a[0] << endl; a[0] = 0; if (n == 1) { cout << 1 << " " << 1 <...
8
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { if (b == 0) return a; else return gcd(b, a % b); } long long power(long long a, long long n) { long long res = 1; while (n != 0) { if (n % 2) { res = res * a; n--; } else { a = a * a; ...
10
#include <bits/stdc++.h> using namespace std; int n; int a[100 + 10]; int cnt[100 + 10]; int f[10000 + 10][100 + 10]; bool vis[10000 + 10][100 + 10]; int main() { scanf("%d", &n); f[0][0] = 1; int tot = 0; for (int i = 0; i < n; ++i) { scanf("%d", &a[i]); if (cnt[a[i]] == 0) ++tot; ++cnt[a[i]]; } ...
13
#include <bits/stdc++.h> using namespace std; void read(vector<long long> &v) { for (int i = 0; i < v.size(); i++) cin >> v[i]; } void print(vector<long long> v) { for (int i = 0; i < v.size(); i++) cout << v[i] << " "; } long long n, m, a, b, temp; string str; set<long long> s; vector<long long> v; int main() { ...
8
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f, MOD = 1e9 + 7; const int n_ = 1e5 + 1000; long long power(long long a, long long n, long long mod = MOD) { long long p = 1; while (n > 0) { if (n % 2) { p = p * a; p %= mod; } n >>= 1; a *= a; a %= mod; } r...
21
#include <bits/stdc++.h> const int md = 1e9 + 7, inf = 1e9 + 7; using namespace std; void debug(string names) { cout << '\n'; } template <typename A1, typename... A2> void debug(string names, A1 par, A2... left) { int pos = 0; for (; pos < names.size() && names[pos] != ' ' && names[pos] != ','; pos++) cout << n...
20
#include <bits/stdc++.h> using namespace std; int a[100001], b[100001] = {0}, c, d, i, j, n, m, l, r; int main() { cin >> n >> m; l = 0; bool tr = false; for (i = 0; i < n; i++) { cin >> a[i]; if (b[a[i]] == 0) c++; if (c == m && !tr) tr = true, r = i; if (!tr) b[a[i]]++; } if (!tr) cout...
7
#include <bits/stdc++.h> using namespace std; vector<int> ans; int m, n = 1e6; int main() { cin >> m; while (n--) { int s = 0, times = 10, pw = 5; while (times--) { s += n / pw; pw *= 5; } if (m == s) ans.push_back(n); } printf("%d\n", ans.size()); sort(ans.begin(), ans.end()); f...
5
#include <bits/stdc++.h> using namespace std; long long power(long long a, long long n) { long long p = 1; while (n > 0) { if (n % 2) { p = p * a; } n >>= 1; a *= a; } return p; } long long power(long long a, long long n, long long mod) { long long p = 1; while (n > 0) { if (n % 2)...
5
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int T[n]; for (int i = 0; i < n; ++i) cin >> T[i]; string s; cin >> s; int maxp, minl; minl = -1000000000; maxp = 1000000000; int lc = 4; char lch = '0'; for (int i = 4; i < n; ++i) { if (s[i] != lch) { lc = 1;...
8
#include <bits/stdc++.h> using namespace std; using lint = long long; using pi = pair<int, int>; lint ccw(pi a, pi b, pi c) { int dx1 = b.first - a.first; int dy1 = b.second - a.second; int dx2 = c.first - a.first; int dy2 = c.second - a.second; return 1ll * dx1 * dy2 - 1ll * dy1 * dx2; } lint dist(pi a, pi b...
16
#include <bits/stdc++.h> using namespace std; struct cir { int x, y, r; } p[20010]; struct node { long double x, y; }; struct line { long double thi; int id, cnt, dfn; } q[1000010]; int n, D, tot, c[20010], Cnt[50], ord[50]; long double pi = acos(-1), T1[50], T2[50]; void read(int &x) { char ch = getchar(); ...
18
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c, d, sum, t; cin >> a >> b >> c >> d; if (c > a) { t = c; c = a; a = t; } if (b < d) { t = b; b = d; d = t; } sum = (a + 2) * (b + d + 2); sum = sum - (a * (b + d)); cout << sum; }
0
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t) { int n; cin >> n; string s; cin >> s; int p = 0; for (int i = 0; i < n - 1; i++) if (s[i] != s[i + 1]) p = 1; if (p == 0) { if (s[0] == '1') cout << n * 2 << "\n"; else ...
2
#include <bits/stdc++.h> using namespace std; int a[1000], b, c, i, x, n, m, y, k; int main() { cin >> n; for (i = 0; i < n; i++) { cin >> a[i]; } for (i = 0; i < n; i++) { if (a[i] >= a[i + 1]) k++; } cout << k << endl; for (i = 0; i < n; i++) { if (a[i] >= a[i + 1]) cout << a[i] << " "; } ...
0
#include <bits/stdc++.h> using namespace std; int n, m, Q, num = 0, top = 0, tot = 0, d[110010], h[110010], fa[110010][20], id[110010], cut[110010], dfn[110010], low[110010], vis[110010]; pair<int, int> q[110010 << 1]; struct edge { int x, y, next; } mp[110010 << 1]; inline char gc() { static char *S, ...
14
#include <bits/stdc++.h> using namespace std; int t, n, a[300005], k, b[300005]; int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); cin >> t; for (int z = 1; z <= t; z++) { bool ok = true; string s; cin >> n >> k; cin >> s; for (int i = 1; i <= n; i++) if (s[i ...
7
#include <bits/stdc++.h> using namespace std; long long solve() { long long p, q, ma = 1, mi = 1000000000000000000; cin >> p >> q; map<long long, long long> z; if (q > p || p % q != 0) return p; else { while (q % 2 == 0) { q = q / 2; z[2]++; } for (long long i = 3; i <= sqrt(q); i ...
7
#include <bits/stdc++.h> #pragma GCC optimize("O3") 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; } ...
13
#include <bits/stdc++.h> using namespace std; char s[2010]; char u[2010]; char t[6010]; int main() { scanf("%s", s); scanf("%s", u); int ans = 100000; int ls, lu; ls = strlen(s); lu = strlen(u); for (int i = 0; i < lu; i++) t[i] = 1; for (int i = lu; i < (lu + ls); i++) t[i] = s[i - lu]; for (int i = ...
9
#include <bits/stdc++.h> using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long n; deque<long long> pos, a, b; set<pair<long long, long long> > l, r, left; cin >> n; pos.resize(n); a.res...
13
#include <bits/stdc++.h> using namespace std; const int N = 4e5 + 5; vector<int> g[N]; int low[N], dis[N], timer = 0, vis[N] = {0}; int disjoint[N] = {0}, labels[N]; vector<int> bridgeTree[N]; vector<pair<int, int> > bridgeNode[N]; map<pair<int, int>, int> bridg; map<pair<int, int>, int> id; vector<pair<int, int> > edg...
15
#include <bits/stdc++.h> using namespace std; int main() { long long int n; char c; cin >> n >> c; long long int aux = 0; if (c == 'a') aux = 4; if (c == 'b') aux = 5; if (c == 'c') aux = 6; if (c == 'd') aux = 3; if (c == 'e') aux = 2; if (c == 'f') aux = 1; if (n % 4 == 1 || n % 4 == 2) { lo...
4
#include <bits/stdc++.h> using namespace std; const int Maxn = 300005; int ans, cnt1, cnt2, n, x[Maxn], y[Maxn]; bool del1[Maxn], del2[Maxn]; struct line { int x, y, id; bool operator<(const line &tmp) const { return y > tmp.y; } } L1[Maxn], L2[Maxn]; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) s...
10
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; for (int i = 0; i < t; ++i) { int a, b, c; cin >> a >> b >> c; if (a + c <= b) cout << 0 << '\n'; else { int m = 0; if (b + c < a) m = (a - (b + c) + 1) / 2 - 1; cout << (a + c - b + 1) / 2 - m << '...
5
#include <bits/stdc++.h> using namespace std; const int N = 1; const int inf = 1e9; const int M = 1e9; int k; int main() { scanf("%d", &k); if (k & 1) { puts("YES"); int n = 4 * (k - 1) + 2; int m = 2 * (k - 1) * (k - 1) + 2 * (k - 1) + 1 + (k - 1); cout << n << " " << m << endl; int cnt = 2 * k...
11
#include <bits/stdc++.h> using namespace std; int n, k; int a, b; int ans = 1000000007; map<int, int> A, B, C; int main() { scanf("%d", &n); k = n / 2 + n % 2; for (int i = 1; i <= n; i++) { scanf("%d%d", &a, &b); A[a]++; B[b]++; if (a == b) C[a]++; } for (auto i : A) { if (i.second + B[i....
7
#include <bits/stdc++.h> using namespace std; long long int Ceil(long long int a, long long int b) { return a / b + (a % b != 0); } long long int fastModExp(long long int a, long long int b) { long long int res = 1; while (b > 0) { if (b & 1) res = (res * a) % 1000000007; a = (a * a) % 1000000007; b =...
2
#include <bits/stdc++.h> using namespace std; int divs[1000001] = {0}; int mark[1000001] = {0}; void prime() { for (int i = 2; i < 1000000; i++) { if (!mark[i]) { divs[i] = i; int k = 1; if (i < 1000) for (int j = i * i; j <= 1000000; j += i) { if (!mark[j]) { mark[...
13
#include <bits/stdc++.h> using namespace std; struct myComparator { bool operator()(pair<int, pair<int, int> > a, pair<int, pair<int, int> > b) { if (a.first == b.first) { return a.second.first > b.second.first; } return a.first < b.first; } }; int main() { ios_base::sync_with_stdio(false); ci...
8
#include <bits/stdc++.h> using namespace std; map<int, long long> A[2], sum[2]; int ansMax = -1; long long ans, total[2]; void update(int m, long long ways) { if (m > ansMax) { ansMax = m; ans = ways; } else if (m == ansMax) { ans += ways; } } int main() { int N, M; scanf("%d%d", &N, &M); for (i...
20
#include <bits/stdc++.h> using namespace std; int n; int a[100005]; int dp[100005][6]; int solve(int i, int previous) { if (i == n - 1) { return dp[i][previous] = 1; } if (dp[i][previous] != -1) return dp[i][previous]; dp[i][previous] = 0; for (int j = 1; j <= 5; j++) { if (a[i] < a[i + 1] && j > prev...
9
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; cin >> n; set<pair<int, int>> curr; set<pair<int, int>> deleted; for (int i = 0; i < n; ++i) { int left, right; cin >> left >> right; auto it = curr.lower_bound({left,...
13
#include <bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; const int N = 1e5 + 100; const int ITERS = 60; const double eps = 1e-9; double sqr(double x) { return x * x; } struct point { double x, y; point() {} point(double _x, double _y) : x(_x), y(_y) {} friend point ope...
15
#include <bits/stdc++.h> using namespace std; int mymin(vector<long long int> v) { return *min_element(v.begin(), v.end()); } long long int mymax(vector<long long int> v) { return *max_element(v.begin(), v.end()); } long long int power(long long int a, long long int b, long long int p) { long long int res = 1; a ...
9
#include <bits/stdc++.h> using namespace std; const long long MAXN = 30; map<string, long long> mp; set<string> name; set<string> st[MAXN]; bool suffix(string &s, string &t) { if (t.size() > s.size()) return false; long long tln = t.size(), sln = s.size(); for (long long i = sln - tln, j = 0; i < sln; j++, i++) ...
6
#include <bits/stdc++.h> using namespace std; int main() { long long n, x, y, s; cin >> n >> s; long long sum = 1000000 - s; pair<long double, long long> p[n]; for (int i = 0; i < n; i++) { cin >> x >> y >> p[i].second; x = abs(x); y = abs(y); p[i].first = sqrt(x * x + y * y); } sort(p, p ...
4
#include <bits/stdc++.h> using namespace std; const int NMAX = 2010; const int DX[4] = {-1, 0, 0, 1}; const int DY[4] = {0, -1, 1, 0}; int N, M, Deg[NMAX][NMAX]; char A[NMAX][NMAX]; bool Used[NMAX][NMAX]; queue<pair<int, int> > Q; int main() { scanf("%i %i\n", &N, &M); for (int i = 1; i <= N; ++i) gets(A[i] + 1); ...
12
#include <bits/stdc++.h> using namespace std; const int N = 5e5; const int M = N + 7; const int MOD = 1e9 + 7; const long long INF = 1e16 + 17; int st[M], ft[M], tim, ver[M]; int sz[M], big[M]; int h[M], xr[M]; vector<pair<int, int> > g[M]; int mask[M * 10]; int ans[M]; void preCalc(int v) { st[v] = ++tim; ver[tim]...
21
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1.0); const long long INF = 1000000000000; const long long F = LLONG_MIN; const int A = 1234567; long long sum(long long num) { long long re = 0; while (num != 0) { re += num % 10; num /= 10; } return re; } int main() { long long a,...
8
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; cin >> n; while (n--) { string s; cin >> s; int m = s.length(); int f = 1; for (char ch = 'a'; ch <= 'z'; ch++) { if (count(s.begin(), s.end(), ch) == 1) { ...
0
#include <bits/stdc++.h> using namespace std; vector<int> a[100010]; int n, m, i, x, y, ans; int main() { ios::sync_with_stdio(false); cin >> n >> m; for (int i = 1; i <= m; ++i) { cin >> x >> y; a[x].push_back(y); a[y].push_back(x); } for (int i = 1; i <= n; ++i) ans += a[i].size() % 2; ans /= ...
19
#include <bits/stdc++.h> using namespace std; char ch[2010]; int i, j, n, g[2010][2010], f[2010][2010], ans; int main() { scanf("%s", ch + 1); n = strlen(ch + 1); for (i = 0; i <= n + 1; i++) { if (ch[i] == '(') break; f[i][0] = 1; } for (i = n + 1; i >= 1; i--) { if (ch[i] == ')') break; g[i]...
18
#include <bits/stdc++.h> using namespace std; long long max(long long a, long long b) { return a > b ? a : b; } void solve() { int n; cin >> n; long long int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } sort(a, a + n); long long int ans1, ans2, ans3; ans1 = a[n - 1] * a[n - 2] * a[n - 3] * a[n...
4
#include <bits/stdc++.h> using namespace std; int n, s; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> s; int dif = s - n + 1; for (int k = 1; k < s; k++) { int y = s - k; if (k <= n - 1 || y <= n - 1) continue; if (k >= dif || y >= dif) continue; cout << "YE...
6
#include <bits/stdc++.h> using namespace std; void _print(long long t) { cerr << t; } void _print(int t) { cerr << t; } void _print(string t) { cerr << t; } void _print(char t) { cerr << t; } void _print(long double t) { cerr << t; } void _print(double t) { cerr << t; } void _print(unsigned long long t) { cerr << t; } ...
14
#include <bits/stdc++.h> using namespace std; long long k, d[8000000]; int a[105], q; long long ans; int n; int main() { cin >> n >> k; for (int i = 1; i <= n; i++) { cin >> a[i]; for (int j = 1; j * j <= a[i]; j++) { d[q++] = (a[i] + j - 1) / j; d[q++] = j; } k += a[i]; } sort(d, d ...
15
#include <bits/stdc++.h> const long long SZ = 1e5 + 1984; const long long inf = 1e18; const long long MOD = 1e9 + 7; const long long MD = 998244353; long long opnmbr = 1; using namespace std; long long powermod(long long a, long long b) { long long ans = 1; while (b) { if (b & 1) ans = (ans * a) % MOD; b = ...
12
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; long long int arr[n]; for (int i = 0; i < n; i++) { arr[i] = i + 2; } for (int i = 0; i < n; i++) { cout << arr[i] << " "; } cout << endl; } }
0
#include <bits/stdc++.h> using namespace std; int n, ta; set<int> s; set<int>::iterator it; int main() { scanf("%d", &n); while (n--) { scanf("%d", &ta); s.insert(ta); } for (it = s.begin(); it != s.end(); it++) for (int i = 0; i <= 30; i++) if (s.find(*it + (1 << i)) != s.end() && s...
10
#include <bits/stdc++.h> template <class First, class Second> std::ostream& operator<<(std::ostream& out, const std::pair<First, Second>& pair) { out << pair.first << ": " << pair.second; return out; } template <class T> std::ostream& operator<<(std::ostream& out, const std::vector<T>& vec)...
9
#include <bits/stdc++.h> using namespace std; const long long U = 1e18; int n; vector<long long> arr, A, B; void gen(long long u, int i, vector<int> &c, vector<long long> &C) { if (i == c.size()) { C.emplace_back(u); return; } gen(u, i + 1, c, C); for (; u <= U / c[i];) { gen(u *= c[i], i + 1, c, C)...
16
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; int par[1]; int find(int x) { return x == par[x] ? x : par[x] = find(par[x]); } void join(int x, int y) { par[find(x)] = y; } long long mod_expo(long long a, long long b, long long mod) { long long ans = 1; while (b) { if (b & 1) ans =...
7
#include <bits/stdc++.h> using namespace std; const int maxn = 2000 * 100 + 10; int x1, y11111, x2, y2, dist[10][10]; pair<int, int> turnlad[4] = {make_pair(0, 1), make_pair(1, 0), make_pair(-1, 0), make_pair(0, -1)}; pair<int, int> turnslon[4] = {make_pair(1, 1), make_pair(-1, 1), ...
3
#include <bits/stdc++.h> using namespace std; template <class T> inline T bigmod(T p, T e, T M) { long long ret = 1; for (; e > 0; e >>= 1) { if (e & 1) ret = (ret * p) % M; p = (p * p) % M; } return (T)ret; } template <class T> inline T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); } ...
4
#include <bits/stdc++.h> using namespace std; const int N = 200005; int n, k, a[N]; vector<int> g[N]; int dp[N], tp[N]; int Mid; int use[N]; bool vis[N]; void dfs(int u, int p) { vis[u] = true; tp[u] = 0; dp[u] = 0; if (a[u] < Mid) { tp[u] = 1; return; } int Max = 0; for (int i = 0; i < g[u].size(...
18
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e5; long long N, M; long long A[MAXN]; long long r[MAXN]; bool is_good(long long t) { memcpy(r, A, sizeof(A)); for (long long i = N, s = M, b = 0; i > 0;) { if (r[i]) { if (!b) { if (!s) { return false; } b =...
14
#include <bits/stdc++.h> using namespace std; const long long N = 300000 + 77; long long n, Prof, a[N], b[N]; long long A, Profit[N], Mx[N << 2], lz[N << 2]; vector<pair<long long, long long> > V; set<long long> S; vector<pair<long long, long long> > Ql[N], Qr[N]; inline void Shift(long long l, long long r, long long i...
16
#include <bits/stdc++.h> using namespace std; int N; vector<pair<int, int> > edge[110]; void dfs(int x, int first, double len) { double step = 2. / (edge[x].size()); double cur = len; for (int i = 0; i < edge[x].size(); ++i) { if (edge[x][i].first == first) continue; printf("1 %d ", edge[x][i].second + 1)...
17
#include <bits/stdc++.h> using namespace std; vector<int> v[100], a[100]; int mark[50] = {0}; void dfs(int i, int cnt) { a[cnt].push_back(i); mark[i] = 1; int s = v[i].size(); for (int j = 0; j < s; j++) { if (!mark[v[i][j]]) dfs(v[i][j], cnt); } } int main() { int n, m; scanf("%d%d", &n, &m); for (...
7
#include <bits/stdc++.h> using namespace std; const int inf = 1e9, mod = 1e9 + 7; const int N = 5e5 + 5; set<pair<int, int> > S; vector<pair<int, int> > v; int h[N], a[N], x, n; long long ans; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); S.insert(make_pair(i, a[i])); ...
17
#include <bits/stdc++.h> using namespace std; const int inf = 1 << 29; const double dinf = 1e30; const long long linf = 1LL << 55; string s; int cnt[20]; int main() { while (cin >> s) { memset(cnt, 0, sizeof(cnt)); bool found = false; int wenhao = 0; for (int i = 0; i < s.length(); i++) { wenhao...
6
#include <bits/stdc++.h> using namespace std; inline void read_string_to_vector(vector<string> &vec) { string str; getline(cin, str); vec.push_back(str); } template <typename T> inline void read_digit_to_vector(vector<T> &vec) { T t; cin >> t; vec.push_back(t); } long long n, l, r, Ql, Qr; long long w[30000...
7
#include <bits/stdc++.h> using namespace std; int tbl[256]; int main() { int n; cin >> n; for (int i = 0; i < n; i++) { string s; cin >> s; tbl[s[0]]++; } int count = 0; for (int c = 'a'; c <= 'z'; c++) { if (tbl[c]) { int a = tbl[c] / 2 - 1; int b = tbl[c] - tbl[c] / 2 - 1; ...
1
#include <bits/stdc++.h> using namespace std; int n, k; int oldmem[10010]; int newmem[10010]; bool ok[10010]; int procinc(int pos) { int respos = 1; while (oldmem[pos] + oldmem[respos++] > n - pos) ; newmem[pos] += oldmem[--respos]; if (newmem[pos] == n - pos) ok[pos] = 1; return respos; } bool isok() { ...
8
#include <bits/stdc++.h> #pragma GCC optimize("-Ofast") using namespace std; long long int findgcd(long long int a, long long int b) { if (b == 0) return a; return findgcd(b, a % b); } bool check(long long int n, long long int s) { long long int tem = n; long long int sum = 0; while (tem > 0) { sum += tem...
8
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; int a[n]; for (int i = 0; i < n; i++) cin >> a[i]; int sum = 0, l = 0, r = n - 1; while (1) { if (a[l] <= k) { sum++; l++; } else if (a[r] <= k) { sum++; r--; } else break; if (r...
0
#include <bits/stdc++.h> using namespace std; const long long MOD = 1000000007; long long pot[100005]; int nw[100005]; long long mypow(long long x) { if (pot[x] != -1) return pot[x]; if (!x) return 1; return pot[x] = (mypow(x - 1) * 2) % MOD; } int main() { memset(pot, -1, sizeof(pot)); long long n, a, b, l =...
13
#include <bits/stdc++.h> using namespace std; inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; } template <class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); } inline int readInt() { int x; scanf("%d", &x); return x; } double bin_pow...
11
#include <bits/stdc++.h> using namespace std; int main() { float r, d; cin >> r >> d; float y = r, x = r - d; int n; cin >> n; int t = 0; while (n--) { int a, b, rr; cin >> a >> b >> rr; float dist = sqrt(a * a + b * b); if (dist - rr >= x && dist + rr <= y) { t++; } } cout <...
3
#include <bits/stdc++.h> using namespace std; int n, k, q, ti[30005], vi, wi, xi, v[15005], w[15005], st[15005], en[15005]; vector<int> tree[4 * 30005]; int dp[30][1005]; void add(int i, int L, int R, int p, int q, int y) { if ((q < L) || (R < p)) return; if ((p <= L) && (R <= q)) { tree[i].push_back(y); re...
20
#include <bits/stdc++.h> using namespace std; int main() { int sum = 0; int n; double in[100000] = {}; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%lf", &in[i]); sum += (int)floor(in[i]); } for (int i = 0; i < n; i++) { if (sum < 0) { printf("%d\n", (int)ceil(in[i])); if ...
7
#include <bits/stdc++.h> using namespace std; int main() { double n, y, x; cin >> n >> x >> y; double k = n * y / 100; k = ceil(k); if (k > x) cout << k - x; else cout << 0; return 0; }
1
#include <bits/stdc++.h> using namespace std; const long long MOD = 998244353; long long a[1000100], sumf, f[1000100], n, sum[1000100], sums; signed main() { scanf("%lld", &n); for (long long i = 1; i <= n; i++) scanf("%lld", &a[i]); for (long long i = 1; i <= n; i++) sum[i] = (a[i] + sum[i - 1]) % MOD; for (lo...
12
#include <bits/stdc++.h> using namespace std; struct eve { int t, num, s; bool d; bool operator<(const eve& B) const { return t < B.t; } } S[100]; char home[10000], away[10000]; int sav[2][100]; int main() { scanf("%s%s", home, away); int n; scanf("%d", &n); register int i, j; char typ[10]; for (i = 1...
5
#include <bits/stdc++.h> using namespace std; int n, k, A; pair<int, int> X[8]; double maxRes = 0.0; int d[8]; void getCandy(int curr_idx, int k) { if (curr_idx == n) { double res = 0.0; for (int mask = 0; mask < (1 << n); mask++) { int win_votes = 0; int level_sum = 0; double p = 1.0; ...
10
#include <bits/stdc++.h> using namespace std; const int N = 1000 + 19; int f[N][100][2], Pp[N], Pk[N]; int n, k, P; int F(int x, int t, int C) { int &Ans = f[x][t][C]; if (~Ans) return Ans; if (!t && C) return Ans = (x == n ? 1 : 9LL * Pp[n - x - 1] % P); if (x == n) return Ans = 0; Ans = 0; for (int i = 0;...
14
#include <bits/stdc++.h> using namespace std; int main() { float H, L; scanf("%f %f", &H, &L); printf("%.6f", (L * L - H * H) / (2 * H)); return 0; }
2
#include <bits/stdc++.h> using namespace std; const int N = 4005; const int M = 20005; const int T = 40005; struct Item { int c, v, t; Item() {} Item(int t) : t(t) {} bool operator<(const Item& x) const { return t < x.t; } } a[N]; struct Que { int a, b, ans, id; bool operator<(const Que& x) const { return a...
19
#include <cstdio> #include <cstring> #include <algorithm> using namespace std; typedef long long ll; int T,n,m,a[1005][1005],b[1005][1005],x,y,p,st,cnt; char s[100005]; int main(){ scanf("%d",&T); while(T--){ scanf("%d%d",&n,&m); for(int i=1;i<=n;++i) for(int j=1;j<=n;++j) scanf("%d",&a[i][j]); scanf("%s...
19
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1.0); const long long INF = 1e9 + 47; const long long LINF = INF * INF; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); namespace IntModulo { const int mod = 998244353; inline int add(int x, int y, int m = mod) { if (x + y < m)...
18
#include <bits/stdc++.h> using namespace std; int main() { int n, p, q; string s; cin >> n >> p >> q >> s; int a, b, fl = 0; for (int i = (0); i <= (n / p); i++) { if ((n - i * p) % q == 0) { a = i; b = (n - i * p) / q; fl = 1; break; } } if (fl == 0) cout << -1; else...
5
#include <bits/stdc++.h> using namespace std; const int N = 200005; int x[N], a[N], cnta, n; int main() { scanf("%d", &n); int x1, ans = 1; for (int i = 1; i <= n; i++) { scanf("%d", &x1); if (x[x1] <= 1) x[x1]++; else ans = 0; } if (!ans) { printf("NO"); return 0; } for (i...
2
#include <bits/stdc++.h> using namespace std; const int prime = 999983; const int INF = 0x7FFFFFFF; const long long INFF = 0x7FFFFFFFFFFFFFFF; const double pi = acos(-1.0); const double inf = 1e18; const double eps = 1e-6; const long long mod = 1e9 + 7; long long qpow(long long a, long long b) { long long s = 1; wh...
16