solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> using namespace std; int n, x, y, Son, Max; int tot, point[100005], nxt[100005 * 2], v[100005 * 2]; int c[100005], size[100005], son[100005], cnt[100005]; long long sum, ans[100005]; void add(int x, int y) { ++tot; nxt[tot] = point[x]; point[x] = tot; v[tot] = y; } void getson(int x, in...
15
#include <bits/stdc++.h> using namespace std; const int N = 200005; struct node { int size; node *left, *right; node(node *left = NULL, node *right = NULL) : left(left), right(right) { size = 0; if (left) size += left->size; if (right) size += right->size; } }; map<int, int> mapper; int size; node *...
14
#include <bits/stdc++.h> using namespace std; const int N = 100050; int cnt[1 << 6], sub[1 << 6], mask[N]; bool Check(int m, int c) { for (int i = 0; i < 1 << 6; i++) { int a = cnt[i], b = sub[i]; if ((i & c) == c) a--; if ((i & m) == m) b--; if (a < b) return 0; } return 1; } void Del(int m, int ...
16
#include <bits/stdc++.h> using namespace std; int dp[4010][4010], n, last, ans, a[4010]; int main() { ans = 0, last = 0; scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d", &a[i]); for (int i = 1; i <= n; i++) { last = 0; for (int j = 0; j < i; j++) { dp[i][j] = dp[j][last] + 1; if (a[...
7
#include <bits/stdc++.h> using namespace std; const int INF = 2e9; const long long LINF = 2e18; void inv(bool e); template <typename T> T sign(T a); template <typename T> void die(T &a); template <typename T> void umax(T &a, T b); template <typename T> void umin(T &a, T b); bool brute, alter; int cnt_tests = 1; int n, ...
4
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; const long long mxN = 1e5 + 5; long long a[(1 << 18)]; long long seg[4 * (1 << 18)]; void build_tree(long long id, long long left, long long right, long long depth) { if (left == right) { seg[id] = a[left]; return; ...
9
#include <bits/stdc++.h> using namespace std; const int MAX = 105; int a[MAX], even[MAX], odd[MAX]; int main() { int t, n; scanf("%d", &t); while (t--) { int tol1 = 0, tol2 = 0; scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); if (a[i] % 2 == 0) even[tol1++] = i;...
0
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using pii = pair<int, int>; using vi = vector<int>; void solve() { int n; cin >> n; vi p(n); for (auto& x : p) { cin >> x; x /= 100; } sort(begin(p), end(p)); int x, a, y, b; ll k; cin >> x >> a >> y >>...
8
#include <bits/stdc++.h> using namespace std; const long long INF = (long long)1e18; const long long MAXN = (long long)1e5 + 10; const long long MOD = (long long)998244353; const long double EPS = (long double)1e-10; long long power(long long x, long long n, long long mod = 1e9 + 7) { if (n == 0) return 1ll; if (n ...
10
#include <bits/stdc++.h> using namespace std; int ar[] = {0, 0, 1, -1}; int ac[] = {1, -1, 0, 0}; long long fast_pow(int n, int m) { long long res = 1; long long p = n; while (m) { if (m % 2) res *= p; p *= p; m /= 2; } return res; } int n, m, k; int sat[20]; int gain[20][20]; long long dp[(1 << 1...
10
#include <bits/stdc++.h> using namespace std; const int module = 1e9 + 7; const int inf = (1 << 31) - 1; const int _inf = 1 << 31; int main(void) { int n; double l, v1, v2; int p; while (scanf("%d", &n) == 1) { scanf("%lf%lf%lf%d", &l, &v1, &v2, &p); int tang = (n + p - 1) / p; double x = l * 2.0 * ...
11
#include <bits/stdc++.h> using namespace std; const int INF = 1000000000; const int N = 400005; const int MOD = 1000000007; int n, p, q, sz; pair<int, int> a[N]; inline double get(double x, int i, int j) { double P, Q; P = p - a[i].first * x; Q = q - a[i].second * x; return max(0.0, max(P / a[j].first, Q / a[j]...
16
#include <bits/stdc++.h> using namespace std; int mult(int x, int y) { long long int ans, x1 = (long long int)x, y1 = (long long int)y; ans = (x1 * y1) % 1000000007; return (int)ans; } int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); } int lcm(int a, int b) { return a * (b / gcd(a, b)); } long long int ...
13
#include <bits/stdc++.h> using namespace std; const int INF = int(1e9); const long long INFll = 1ll * INF * INF; const int MOD = 1000000007; int main() { cin.tie(0); ios_base::sync_with_stdio(0); int n, m; cin >> n >> m; vector<int> used(n + 1); vector<int> need(n + 1); int K = 0; for (int i = 1; i <= m...
10
#include <bits/stdc++.h> int d[101][51][2][2]; char s[101]; int n, k; int main(void) { while (isalpha(s[n++] = getchar())) ; --n; int i, j, p, t; scanf("%d", &k); for (i = 0; i < n; ++i) { for (j = 0; j <= k; ++j) { d[i][j][0][0] = -10000000; d[i][j][0][1] = 10000000; d[i][j][1][0] =...
10
#include <bits/stdc++.h> using namespace std; const int maxn = 200010; const int mod = 1000000007; int n, l, r; int dp[maxn][3]; long long read() { long long s = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { ...
7
#include <bits/stdc++.h> #define forn(i,s,t) for(register int i=(s);i<=(t);++i) using namespace std; typedef long long LL; const int N = 1e5 + 3, M = 24; struct List {int dir, nxt;} E[N<<1]; int G[N], cnt; inline void Add(int u, int v) { E[++cnt].dir = v, E[cnt].nxt = G[u], G[u] = cnt; } int n, k; LL a[N], F[N][M][2],...
17
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; const ll infll = 1ll * INT_MAX * INT_MAX; const long double PI = 3.141592653589793238462643383279502884197169399375105820974944; ll max(ll a, ll b) { return (a > b ? a : b); } ll min(ll a, ll b) { return (a > b ? b : a); } l...
10
#include <bits/stdc++.h> using namespace std; int main() { int x1, x2, x3, x4, x5, x6, y1, y2, y3, y4, y5, y6; cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> x4 >> y4 >> x5 >> y5 >> x6 >> y6; if (x1 >= x3 && x2 <= x4 && y3 <= y1 && y4 >= y2) cout << "NO"; else { if (x1 >= x3 && x2 <= x4 && y3 <= y1) y1 = ma...
9
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 4; const int maxk = 12; const int maxlog = 20; const long long inf = 1e18; const int mod = 1e9 + 7; const long long base = 307; long long seg[4 * maxn][maxk]; long long dp[maxn][maxk]; long long get(int ind, int l, int r, int x, int y, int k) { if (...
11
#include <bits/stdc++.h> const int NMAX = 100009; using namespace std; vector<int> a[NMAX]; bool be[NMAX]; int t[4 * NMAX + 1]; int build(bool a[], int v, int tl, int tr) { if (tl == tr - 1) { t[v] = a[tl]; return t[v]; } int p = (tl + tr) / 2; int suml = build(a, 2 * v, tl, p); int sumr = build(a, 2 ...
8
#include <bits/stdc++.h> using namespace std; int main() { bool ok = 0; int m, a, b; cin >> m; for (int i = 0; i < m; i++) { cin >> a >> b; if (a != b) { ok = 1; break; } } if (ok) puts("Happy Alex"); else puts("Poor Alex"); return 0; }
3
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> v(n); for (int i = 0; i < n; ++i) { cin >> v[i]; } sort(begin(v), end(v)); if (n % 2 == 1) { cout << v[n / 2]; } else { cout << v[n / 2 - 1]; } return 0; }
0
#include <bits/stdc++.h> using namespace std; int main() { cin.sync_with_stdio(false); cin.tie(0); long double a, b, c; cin >> a >> b >> c; if (a == 0 and b == 0 and c == 0) cout << -1; else if ((a == 0 and b == 0) or b * b - 4 * a * c < 0) cout << 0; else if (a == 0) cout << fixed << setpreci...
12
#include <bits/stdc++.h> using namespace std; long long n; long long a[15]; long long tt[110][110]; long long dp[15][110]; const int mod = 1e9 + 7; void cal() { for (int i = 0; i <= n; ++i) { for (int j = 0; j <= i; ++j) { if (j == 0 || i == j) tt[i][j] = 1; else tt[i][j] = (tt[i - 1][...
11
#include <bits/stdc++.h> using namespace std; int dp[1000000]; int rk[1000000], fa[1000000], cnt[1000000]; bool vis[1000000]; int n, x, y; void init() { for (int i = 0; i <= n; i++) fa[i] = i, rk[i] = 0; } int find(int a) { if (fa[a] != a) { int t = fa[a]; fa[a] = find(fa[a]); rk[a] += rk[t]; } retu...
8
#include <bits/stdc++.h> using namespace std; int i, j, k; int n; string a[501]; vector<string> t; string ans(string s) { multiset<string> p, q; for (i = 0; i < n - 1; i++) p.insert(s.substr(0, i + 1)); for (i = 0; i < n - 1; i++) q.insert(s.substr(n - i - 1, i + 1)); string out = ""; for (i = 0; i < 2 * n - ...
9
#include <bits/stdc++.h> using namespace std; void _print(long long int 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...
12
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int p, n; cin >> p >> n; map<int, int> hashtable; bool conf = false; for (int i = 0; i < n; i++) { int x; cin >> x; if (hashtable[x % p]) { cout << i + 1 << endl; ...
0
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") using namespace std; mt19937_64 mt_rand(chrono::system_clock::now().time_since_epoch().count()); template <typename T1, typename T2> inline bool upmax(T1& a, T2 b) { return (a < b ? (a = b, true) : false); } template <typename...
20
#include <bits/stdc++.h> using namespace std; void Cout(int x, int y) { int res = 0, y2 = 0, num[1005]; memset(num, 0, sizeof(num)); while (y) { num[y2++] = y % x; y /= x; } for (int i = y2 - 1; i >= 0; i--) cout << num[i]; } int n; int main() { cin >> n; for (int i = 1; i < n; i++) { for (int...
5
#include <bits/stdc++.h> using namespace std; int sum; string s; int main() { cin >> s; int l = s.size(); for (int i = 0; i < l; i++) { if (isupper(s[i])) { sum += s[i] - '@'; continue; } if (islower(s[i])) { sum -= s[i] - '`'; continue; } } cout << sum; return 0; }
12
#include <bits/stdc++.h> using namespace std; string a; bool check(int i, int j) { for (int s = i; s <= j; s++) { if (a[s] != a[j - s + i]) return 0; } return 1; } int ans; int main() { cin >> a; for (int i = 0; i < a.length(); i++) { for (int j = i; j < a.length(); j++) { if (!check(i, j)) ans ...
1
#include <bits/stdc++.h> using namespace std; inline int read() { int x = 0; char ch = getchar(); bool positive = 1; for (; ch < '0' || ch > '9'; ch = getchar()) if (ch == '-') positive = 0; for (; ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0'; return positive ? x : -x; } const long doub...
17
#include <bits/stdc++.h> using namespace std; template <typename T> using maxHeap = priority_queue<T, vector<T>, less<T>>; template <typename T> using minHeap = priority_queue<T, vector<T>, greater<T>>; template <typename Iter> ostream& _out(ostream& s, Iter b, Iter e) { s << "["; for (auto it = b; it != e; it++) s...
12
#include <bits/stdc++.h> using namespace std; inline int getint() { int num = 0, flag = 1; char c; while ((c = getchar()) < '0' || c > '9') if (c == '-') flag = -1; while (c >= '0' && c <= '9') num = num * 10 + c - 48, c = getchar(); return num * flag; } int n, m, Q; bitset<505> f[505][505], g[505][505]; ...
22
#include <bits/stdc++.h> using namespace std; int main() { long long n, x; cin >> n; long long i, j, k, ans = 9 * n + 9, mx = 0; for (i = 1; i <= sqrt(n); i++) { if (n % i == 0) { x = n / i; for (j = 1; j <= sqrt(n); j++) { if (x % j == 0) { k = x / j; ans = min(ans, ...
8
#include <bits/stdc++.h> using namespace std; void solve() { int T; cin >> T; while (T--) { string s; cin >> s; sort(s.begin(), s.end()); int n = 1; for (int i = 0; i < s.length(); i++) { if (s[i] == s[i + 1]) n++; } if (n == s.length()) { cout << -1 << "\n"; continue...
1
#include <bits/stdc++.h> using namespace std; const int N = 100000 + 5; const int M = 100000 + 5; const int S = 1 << 19; int n, m, cnt, op[M], v[N << 1], fa[N], L[N], R[N]; vector<int> seg[S]; pair<int, int> q[M]; inline void rd(int& x) { static char ch; static bool flag; for (flag = 0; !isdigit(ch = getchar()); ...
22
#include <bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; int t = (2 * n / 3); int TOT = 0; for (int i = 0; i < t; i++) { cout << i << " " << 0 << '\n'; TOT++; } for (int i = 0; i < t; i += 2) { ...
18
#include <bits/stdc++.h> using namespace std; using ld = long double; using ll = long long; int32_t main() { cin.tie(nullptr); cout.tie(nullptr); ios_base::sync_with_stdio(false); long long n; cin >> n; vector<long long> v(n), u(n), m(n); cin >> v[0], u[0] = m[0] = 1; for (long long i = 1; i < n; i++) ...
9
#include <bits/stdc++.h> using namespace std; const int inf = 1e9 + 5143; const long long Linf = 1e18 + 5413; template <class T> inline void umax(T &a, T b) { if (a < b) a = b; } template <class T> inline void umin(T &a, T b) { if (a > b) a = b; } template <class T> inline T abs(T a) { return a > 0 ? a : -a; } te...
11
#include <bits/stdc++.h> using namespace std; const long long INF = LONG_LONG_MAX; const long long N = 4e2 + 5; const long long mod = 998244353; long long fsp(long long base, long long power) { if (power == 0) return 1; if (power == 1) return base; long long ans = fsp(base, power / 2); ans = (ans * ans); if (...
8
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:1024000000,1024000000") using namespace std; const int P = 1000000007; const int V = 510; const int QN = 300100; char mp[V][V]; int id(char c) { if (c == 'R') return 0; if (c == 'G') return 1; if (c == 'Y') return 2; else return 3; } int s[V][V][4...
17
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 5; const int M = 6e5 + 5; int t, n, m, q, t2; string num; int arr[N]; bool sw[19]; class Trie { public: Trie *child[2]; }; Trie rev_trie; void recins(int idx, Trie *curr) { if (idx > 18) return; if (num[idx] == '0') { if ((*curr).child[0] == 0...
12
#include <bits/stdc++.h> using namespace std; const double EPS = 1e-9; const double PI = 3.1415926535897932384626433832795; unsigned long long mod = 1000 * 1000 * 1000 + 7; vector<int> v(20000001, 1); int main() { int a, n; cin >> a >> n; for (int i = 1; i * i < a + n; i++) { int sq = i * i; for (int j = ...
7
#include <bits/stdc++.h> using namespace std; const long long MOD = 1000000007; string str, test, cf = {"CODEFORCES"}; int main() { cin >> str; int l = str.length(); for (int i = 0; i < l; i++) { for (int j = 0; j <= l; j++) { test = str.substr(0, i) + str.substr(j); if (test == cf) { cout...
6
#include <bits/stdc++.h> using namespace std; long long debugVal = 1; const long long inf = 2e19; #pragma GCC optimize("unroll-loops") long long r(long long x) { return (sqrt(1 + 8 * x) + 1) / 2; } signed main() { long long n; cin >> n; long long t, p; cin >> t >> p; long long a[n + 1], cur[n + 1]; a[0] = 0...
24
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0), cin.tie(0); int n, bp = 0, aux; vector<int> v, ans; cin >> n; for (int i = 0; i < n; i++) { cin >> aux; v.push_back(aux); } sort(v.begin(), v.end()); ans.assign(n, 0); for (int i = 0; i < v.size(); i += 2)...
2
#include <bits/stdc++.h> using namespace std; const int maxn = 75; unsigned long long f[maxn][maxn]; vector<pair<int, int> > x[maxn]; int n, K, a, b; char op1, op2; bool check(int l, int r, int a, int b) { for (int i = 0; i < x[a].size(); i++) { if (x[a][i].second == 1 && l < x[a][i].first && x[a][i].first < r) ...
16
#include <bits/stdc++.h> using namespace std; int n; int a[100010]; int b[100010]; int c[100010]; map<int, int> M; map<int, int> T[100010 * 4]; void upd(int t, int x, int y, int l, int r, int node) { T[node][x] += y; if (l == r) return; if (t <= (l + r) / 2) upd(t, x, y, l, (l + r) / 2, node * 2); else ...
12
#include <bits/stdc++.h> using namespace std; int main() { long long int x, i, n = 0; cin >> x; i = 1; while (x - 5 * i > 0) { x = x - 5 * i; i = i * 2; n++; } if (x > 0 && x <= i) cout << "Sheldon"; else if (x > i && x <= 2 * i) cout << "Leonard"; else if (x > 2 * i && x <= 3 * i) ...
3
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c, d; cin >> a >> b >> c >> d; if (a + b <= max(c, d) || a < c && b - 1 < d || a - 1 < c && b < d) { puts("Polycarp"); } else { puts("Vasiliy"); } return 0; }
9
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); long long int n, q, inp; cin >> n >> q; while (q--) { cin >> inp; if ((inp + 1) % 2 == 0) { cout << (inp + 1) / 2 << endl; continue; } long long int x = (n + inp / 2) - inp; whi...
9
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; int se = 0, f = 0; int len = s.size(); for (int i = 0; i < len; i++) { if (s[i] == '4') f++; if (s[i] == '7') se++; } if (f >= se) { if (!f) cout << -1; else cout << 4; } else if (f < se) cout ...
2
#include <bits/stdc++.h> using namespace std; void solve() { long long n, k; cin >> n >> k; long long a[n], b[n], ans = 0, x, c = 0; for (long long i = 0; i < n; i++) cin >> b[i]; cin >> x; for (long long i = 0; i < n; i++) cin >> a[i]; priority_queue<long long, vector<long long>, greater<long long>> m; ...
7
#include <bits/stdc++.h> namespace ST { const int NMAX = 200 * 1000 + 1, PMAX = 18; int min[PMAX][NMAX], log2[NMAX + 1]; std::vector<int> sum; void init() { for (int i = 2; i <= NMAX; ++i) { log2[i] = 1 + log2[i / 2]; } } template <typename T> void build(const std::vector<T>& arr) { sum.assign((int)(arr).size...
12
#include <bits/stdc++.h> using namespace std; template <typename T> void Max(T &a, T b) { if (a < b) a = b; } template <typename T> void Min(T &a, T b) { if (a > b) a = b; } const int N = 5000 + 10; const int M = 2 * N + 10; int T; int n, m, k; int a[N]; int main() { scanf("%d", &T); while (T--) { scanf("%d...
8
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; if (n == 2) { cout << 3 << "\n"; return 0; } long long t = sqrt(n); if (t * t == n) { cout << 2 * t << "\n"; return 0; } for (long long i = 1; i <= 100000; i++) { if (n > (i - 1) * (i - 1) && n < i * i)...
3
#include <bits/stdc++.h> using namespace std; const int go[4][2] = {0, 1, 1, 0, 0, -1, -1, 0}; int n, sx, sy; int cnt[11]; int main() { scanf("%d%d%d", &n, &sx, &sy); for (int i = 0; i < n; i++) { int x, y; scanf("%d%d", &x, &y); x -= sx; y -= sy; if (y > 0) cnt[0]++; if (x > 0) cnt[1]++; ...
5
#include <bits/stdc++.h> using namespace std; int main() { vector<pair<string, int> > players; pair<string, int> temp; int i, k, s; double d, n; cin >> n; for (i = 0; i < n; i++) { cin >> temp.first >> temp.second; for (k = 0; k < players.size(); k++) if (temp.first == players[k].first) { ...
6
#include <bits/stdc++.h> using namespace std; const int N = 1005; struct P { long long x, y, z; P(long long _x = 0, long long _y = 0, long long _z = 0) { x = _x, y = _y, z = _z; } void init() { scanf("%lld%lld%lld", &x, &y, &z); } friend P operator-(P a, P b) { return P(a.x - b.x, a.y - b.y, a.z - b.z); }...
23
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 5, mod = 1e9 + 7; struct matrix { vector<vector<long long> > x; matrix(int m) { x.resize(m + 1); for (int i = 0; i <= m; ++i) for (int j = 0; j <= m; ++j) x[i].push_back(0); } void adjust() { int m = x.size() - 1; x[1][1]...
13
#include <bits/stdc++.h> using namespace std; int main() { int n, star = 0, que = 0; string s, ans; cin >> s >> n; ans = ""; for (int i = 0; i < s.size(); i++) { if (s[i] == '*') star++; else if (s[i] == '?') que++; } if (star == 0) { if (n > s.size() - que || n < s.size() - 2 * qu...
4
#include <bits/stdc++.h> using namespace std; int main() { long long int n; cin >> n; long long int pos[n]; char color[n]; for (long long int i = 0; i < n; i++) { cin >> pos[i]; cin >> color[i]; } vector<long long int> r; vector<long long int> b; long long int lastP = 0x3f3f3f3f3f3f3f3f; lon...
14
#include <bits/stdc++.h> using namespace std; const long long N = 1e6 + 9; long long par[N], dis[N], mrk[N], what[N], cnt = -1, q[N]; char c[N]; vector<pair<long long, char> > adj[N]; multiset<long long> s; bool CMP(pair<long long, char> i, pair<long long, char> j) { return i.second < j.second; } void DFS(long long u...
18
#include <bits/stdc++.h> using namespace std; int w[15]; int cnt[500005]; vector<int> v; int num[5005][5005]; int n, m, q, k; int getval(char s[], int len) { int ans = 0; reverse(s, s + len); int temp = 1; for (int i = 0; i < len; i++) { ans += temp * (s[i] - '0'); temp *= 2; } return ans; } int mai...
11
#include <bits/stdc++.h> int Inp() { char c = getchar(); int Neg = 1; while (c < '0' || c > '9') { if (c == '-') Neg = -1; c = getchar(); } int Sum = 0; while (c >= '0' && c <= '9') { Sum = ((Sum << 3) + (Sum << 1)) + c - '0'; c = getchar(); } return Neg * Sum; } std::map<int, int> ls; i...
10
#include <bits/stdc++.h> using namespace std; char str[300000]; int main() { int n, k, i, in, inn, ind, indd, i1, i2; scanf("%d", &n); scanf("%s", str); int d = 0, r = 0, last = 1; int poc = 0; while (1) { bool je = 0; for (i = 0; i < n; i++) { if (str[i] == 'D') { if (r > 0) { ...
7
#include <bits/stdc++.h> int main() { char a[200]; int n, d, sum[200], i, j, r, m, b[200], max; while (scanf("%d %d", &n, &d) == 2) { r = 0; max = 0; for (i = 0; i < d; i++) { sum[i] = 0; scanf("%s", a); for (j = 0; j < n; j++) { if (a[j] == '0') m = 0; else...
0
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 10; const long long mod = 1000696969; long long pw, H, k, ans; vector<pair<int, string> > adj[N]; vector<long long> hsh; void dfs(int v) { for (auto e : adj[v]) { int u = e.first; string s = e.second; for (int i = 0; i < s.size(); i++) { ...
12
#include <bits/stdc++.h> using namespace std; int n, k; const int N = 45; int a[N]; double dp[N][N], tp[N][N]; int main() { scanf("%d%d", &n, &k); for (int i = 0; i < n; i++) scanf("%d", a + i); for (int i = 0; i < n; i++) for (int j = i + 1; j < n; j++) dp[i][j] = (a[i] > a[j]); double val = (n * (n + 1.))...
10
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0), cin.tie(0); int n; cin >> n; int a[n]; for (int i = 0; i < n; ++i) { cin >> a[i]; } sort(a, a + n); for (int j = 0; j < 22; ++j) { int l = 0, r = n - 1; while (l < r) { while (l < r and (a[l] & (1LL << ...
9
#include <bits/stdc++.h> using namespace std; pair<int, bool> convert(string s) { int hour = 0; bool ap; if (s[1] == '1' && s[2] == '2') { s[1] = '0'; s[2] = '0'; } hour = (int)s[1] - '0'; hour = 10 * hour + (int)s[2] - '0'; hour = 10 * hour + (int)s[4] - '0'; hour = 10 * hour + (int)s[5] - '0';...
11
#include <bits/stdc++.h> using namespace std; int main() { int test; cin >> test; while (test--) { int num; bool ok = true; cin >> num; int arr[num]; for (int i = 0; i < num; i++) { cin >> arr[i]; } sort(arr, arr + num); for (int i = 1; i < num; i++) { if (arr[i] - arr[...
0
#include <bits/stdc++.h> using namespace std; vector<pair<int, int>> arr; int dp[3000 + 5], n, tree[530000 + 5]; bool in(int a, int b) { return arr[a].second >= arr[b].second and arr[a].first <= arr[b].first; } int get(int id, int l, int r, int rl, int rr) { if (l > r or r < rl or l > rr) { return 0; } if (...
15
#include <bits/stdc++.h> using namespace std; const int maxint = -1u >> 1; int x, k; double p; double dp[210][210]; int main() { scanf("%d%d%lf", &x, &k, &p); p /= 100.0; for (int i = 0; i <= k; i++) { for (int j = x + i; j % 2 == 0; j /= 2) { dp[0][i] += 1.0; } } for (int i = 0; i < k; i++) { ...
16
#include <bits/stdc++.h> using namespace std; const int inf = 2000000000; const int N = 100005; vector<pair<int, int> > g[N]; int s[N], t[N], T[N]; double dp[N]; bool cmp(int i, int j) { long long T1 = T[i]; long long T2 = T[j]; long long k1 = s[i]; long long k2 = s[j]; return k2 * T1 < k1 * T2; } void dfs(in...
15
#include <bits/stdc++.h> using namespace std; long long int n, a[100100], res = 0; vector<pair<long long int, long long int> > v[100100]; bool vis[100100] = {0}; void dfs(long long int node, bool d, long long int dis) { vis[node] = 1; if (d) { res++; } else if (dis > a[node]) { d = 1; res++; } for...
8
#include <bits/stdc++.h> using namespace std; using namespace std; int main() { long long a, b, c; scanf("%lld %lld", &a, &b); while (1) { if (a == 0 || b == 0) break; else if (a >= 2 * b) { c = a / (2 * b); a -= 2 * b * (c); } else if (b >= 2 * a) { c = b / (2 * a); b -=...
3
#include <bits/stdc++.h> const int MOD = 1000000009; int pai[100010]; int lvl[100010]; void clean() { for (int i = 0; i < 100010; i++) { pai[i] = i; lvl[i] = 0; } } void uniao(int x, int y) { if (lvl[x] < lvl[y]) { pai[x] = y; } else { pai[y] = x; if (lvl[x] == lvl[y]) lvl[y]++; } } int ac...
15
#include <bits/stdc++.h> using namespace std; const long long mxN = 2e5, mod = 1e9 + 7; const long long INF = 1e18; vector<long long> findans(string &s1, string &s) { long long n = s.size(); long long n1 = n / 3; long long n2 = n % 3; string s2 = ""; for (long long i = 0; i < n1; i++) { s2 += s1; } s2...
8
#include <bits/stdc++.h> using namespace std; vector<int> edges[66000]; int out[66000], in[66000], cnt[66000]; string ans; void dfs(int i) { while (cnt[i] < edges[i].size()) { dfs(edges[i][cnt[i]++]); } ans += (char)i % 256; } int main() { int n, u, v, start = 0; scanf("%d", &n); string s; for (int i ...
17
#include <bits/stdc++.h> using namespace std; const double eps = 1e-8; const double pi = acos(-1.0); template <class T> int chkmin(T &a, T b) { return a > b ? a = b, 1 : 0; } template <class T> int chkmax(T &a, T b) { return a < b ? a = b, 1 : 0; } template <class T> T sqr(T a) { return a * a; } template <class T...
10
#include <bits/stdc++.h> using namespace std; int n, m, q; long long f[2][300005], a[2][300005], s[2][300005], p, px, py; int main() { scanf("%d", &n); for (int i = 0; i <= 1; i++) for (int j = 0; j < n; j++) cin >> a[i][j]; for (int i = 0; i <= 1; i++) for (int j = n - 1; j >= 0; j--) { px = i ^ 1;...
10
#include <bits/stdc++.h> using namespace std; struct SegTree { int l, r, mid, len, color, lazy; SegTree() {} SegTree(int __l, int __r, int __color) { l = __l; r = __r; color = __color; mid = (l + r) >> 1; len = r - l + 1; lazy = 0; } } t[300010 << 2]; int n, m; int L[300010], R[300010], ...
7
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:66777216") using namespace std; const int N = 10000; int n; int l[10], r[10]; void solve() { cin >> n; int mi = 0, ma = 0; for (int i = 0; i < (int)(n); ++i) { cin >> l[i] >> r[i]; ma = max(r[i], ma); mi = max(l[i], mi); } long double ans = ...
12
#include <bits/stdc++.h> using namespace std; int chkpower2(int x) { return (x && !(x & x - 1)); } void solve() { string s1; int cnt = 0, ans1 = 0, ans2 = 0; cin >> s1; for (int i1 = 0; i1 < s1.size(); i1++) { if (s1[i1] == '+') { cnt++; } if (s1[i1] == '-') { cnt--; } int d1 = c...
6
#include <bits/stdc++.h> using namespace std; int a, b, d, g, dx[] = {+1, -1, 0, 0}, dy[] = {0, 0, +1, -1}, nx, ny, dis[1009][1009]; char c[1009][1009]; int _x, _y, w; long long sm; queue<pair<int, int> > q; int das(int xy, int yx) { if (xy > a or xy < 1 or yx > b or yx < 1 or c[xy][yx] == 'T') return...
7
#include <bits/stdc++.h> using namespace std; const long double e = exp(1.0); int t; int a[257]; long double q[2007][2507]; long double poiss(int p) { long double res = 0; for (int i = 1; i <= 250; ++i) { res += log(q[p][a[i]]); } return res; } long double uni(int p) { long double res = 0; for (int i = ...
14
#include <bits/stdc++.h> long long exp(long long x, long long y, long long p) { long long res = 1; while (y) { if (y % 2) res = (res * x % p) % p; x = (x * x) % p; y /= 2; } return res; } long long expo(long long x, long long y) { long long res = 1; while (y) { if (y % 2) res = (res * x % ((...
9
#include <bits/stdc++.h> using namespace std; const int maxn = 8008; string s; int dp[maxn], length[maxn]; vector<int> kmp(int startIndex) { string x = ""; for (int i = startIndex - 1; i < s.size(); i++) { x += s[i]; } vector<int> ret; ret.push_back(-1); int k = -1; for (int i = 1; i < x.size(); i++) ...
16
#include <bits/stdc++.h> using namespace std; bool comp(const pair<long long, long long>& a, const pair<long long, long long>& b) { return a.first + a.second > b.first + b.second; } signed main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long T = 1; while (T--) { long long n, r;...
13
#include <bits/stdc++.h> using namespace std; #define F first #define S second #define pb push_back #define ll long long #define Mid ((L+R)/2) #define pi pair<int,int> #define pii pair<pi,int> #define deb(x) cout<<#x<<"="<<x<<endl #define go ios::sync_with_stdio(0); cin.tie(0); cout.tie(0) int n,k; string s; const int ...
17
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0), cout.tie(0); int t; cin >> t; int ans[t]; for (int i = 0; i < t; i++) { int n, d; cin >> n >> d; int a[n]; for (int j = 0; j < n; j++) cin >> a[j]; int j = 1; while (d > 0 && j < n) {...
0
#include <bits/stdc++.h> using namespace std; double dp[1003][1003]; int w, b; double dfs(int w, int b) { if (w == 0 && b == 0) return 0; if (w == 0) return 0; if (b == 0) return 1; if (dp[w][b]) return dp[w][b]; double tmp = 1.0 * w / (w + b); if (b >= 2) tmp += 1.0 * b * (b - 1) / (w + b) / (w + b - 1...
10
#include <bits/stdc++.h> using namespace std; long long l1[4], l2[4], tot; int main() { long long t; cin >> t; while (t--) { long long a, b, c, d, e, f; cin >> a >> b >> c; long long ans = INT_MAX; for (int i = 1; i <= 2 * a; i++) { for (int j = i; j <= 2 * b; j += i) { long long g =...
12
#include <bits/stdc++.h> using namespace std; long long A, B, x, y, Cx, Cy; bool ok(long long x, long long y, long long A, long long B, long long Cx, long long Cy) { if (Cx * Cx + Cy * Cy == 0) { bool flg = 0; if (x == A && y == B) flg = 1; if (y == A && -x == B) flg = 1; if (-x == A && -y == ...
12
#include <bits/stdc++.h> using namespace std; const int mod = 998244353, MAX = 200003, INF = 1 << 30; vector<int> G[MAX]; int size[MAX]; long long ans = 1; void DFS(int u, int p) { size[u]++; for (int to : G[u]) { if (to == p) continue; DFS(to, u); size[u] += size[to]; } } void solve(int u, int p) { ...
11
#include <bits/stdc++.h> using namespace std; const int maxn = 2e4 + 7, mod = 998244353, inf = 1e9, MAXN = 1e6 + 7; const double eps = 1e-9; mt19937 rnd(time(0)); int n; vector<int> gr[maxn]; int p[maxn], dist[maxn]; int used[maxn]; int cycle[maxn]; vector<int> path; void dfs(int u, int pr, int d) { used[u] = 1; di...
20