solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> using namespace std; const int inf = 1000000000; const int MOD = 1000000007; vector<int> g[101]; int d[101][101]; long long dp1[101][101], dp2[101][101]; int main() { int n, m; cin >> n >> m; for (int i = 1; i <= n; ++i) for (int j = 1; j <= n; ++j) d[i][j] = (i != j) * inf; for (in...
11
#include <bits/stdc++.h> int main() { char s[100001]; int a[100001], m, l, r; scanf("%s%d", s, &m); int len = strlen(s); a[1] = 0; for (int i = 1; i < len; ++i) { if (s[i] == s[i - 1]) { a[i + 1] = a[i] + 1; } else { a[i + 1] = a[i]; } } while (m--) { scanf("%d%d", &l, &r); ...
3
#include <bits/stdc++.h> using namespace std; long long ans, a[3000], r, l, n, inf = 1000 * 1000 * 1000; void f(long long x) { if (x > inf) return; a[n++] = x; f(x * 10 + 4); f(x * 10 + 7); } int main() { inf *= 5; cin >> l >> r; f(0); sort(a, a + n); for (int i = 0; i < n; i++) { if (l > r) break...
3
#include <bits/stdc++.h> const int N = 1005; int n, m; long long tr[2][2][N][N]; inline long long rd(void) { long long f = 1; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == '-') f = -1; long long x = 0; for (; isdigit(c); c = getchar()) x = x * 10 + c - '0'; return x * f; } inline int l...
17
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 7; int n, m, a[maxn], w = maxn, e = maxn; long long ans; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> m; for (int i = 1; i <= m; ++i) { cin >> a[i]; } if (a[1] <= a[2]) { ans += a[2] - 1; fo...
2
#include <bits/stdc++.h> using namespace std; int main() { vector<int> data1(2000001, -1), data2(1000001, -1); int n, j, k; scanf("%d", &n); int a[n], b[n], hsl[n]; for (int i = 0; i < n; i++) { scanf("%d %d", &a[i], &b[i]); data1[a[i]] = b[i]; data2[b[i]] = a[i]; } for (int i = 0; i < n; i++)...
7
#include <bits/stdc++.h> using namespace std; long long int M = 1000000007; long long int min(long long int a, long long int b, long long int c, long long int d) { long long int arr[4] = {a, b, c, d}; sort(arr, arr + 4); return arr[0]; } long long int max(long long int a, long long int b, long l...
11
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1); const long long LINF = LLONG_MAX; const int INF = INT_MAX, MOD = 1e9 + 7, N = 2e5 + 10; int n; void test(); int dp[N][2], a[N]; int solve(int idx, int turn); int main() { ios_base ::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t; ci...
7
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; cout << n; for (int i = 1; i < n; i++) { cout << " " << i; } return 0; }
9
#include <bits/stdc++.h> using namespace std; int main() { int n, x; cin >> n >> x; int a[100001]; int sum = 0; for (int i = 0; i < n; i++) { cin >> a[i]; sum += a[i]; } if (sum + n - 1 == x) cout << "YES" << endl; else cout << "NO" << endl; return 0; }
3
#include <bits/stdc++.h> const int N = 1e7 + 2 + 5, M = 1e3 + 5, OO = 0x3f3f3f3f, mod = 1e9 + 7; int dx[] = {0, 0, 1, -1, 1, -1, 1, -1}; int dy[] = {1, -1, 0, 0, -1, 1, 1, -1}; int dxx[] = {-1, 1, -1, 1, -2, -2, 2, 2}; int dyy[] = {-2, -2, 2, 2, 1, -1, 1, -1}; using namespace std; long long gcd(long long x, long long y...
4
#include <bits/stdc++.h> using namespace std; void pairsort(long long a[], long long b[], long long k) { pair<long long, long long> pairt[k]; for (long long i = 0; i < k; i++) { pairt[i].first = a[i]; pairt[i].second = b[i]; } sort(pairt, pairt + k); for (long long i = 0; i < k; i++) { a[i] = pair...
1
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 9, mod = 1e9 + 7; int inv[N], fac[N], n, len, T, pw[N]; char s[N]; bool vis[N]; vector<int> f[N]; void Init(int lim) { fac[0] = inv[0] = inv[1] = pw[0] = 1; for (int i = 1; i <= lim; i++) fac[i] = 1ll * fac[i - 1] * i % mod; for (int i = 2; i <= li...
17
#include <bits/stdc++.h> int main() { int a; char b[][8] = {"Sheldon", "Leonard", "Penny", "Rajesh", "Howard"}; std::cin >> a; while (a > 5) a = a / 2 - 2; std::cout << b[a - 1]; }
3
#include <bits/stdc++.h> using namespace std; const int N = 2e6 + 7; bool fg; int n, k, pt, ans, p[N], pos[N], pot[N], fl[N]; long long s2, tg[N], fe[N], w[N], c[N], g[N], q[N], s[N], f1[N], f2[N], f4[N], f5[N], f7[N], f8[N]; inline void update(int t, long long x) { f1[t] += x, f2[t] += x, f4[t] += x, f7[t] -= x,...
25
#include <bits/stdc++.h> using namespace std; const double eps = 1e-5; const double Pi = 3.1415926535897932; const int dir[4][2] = {-1, 0, 0, -1, 1, 0, 0, 1}; const int maxn = 5000 + 5; int n, m; vector<int> G[maxn]; vector<int> w[maxn][2]; int pn = 0; int flag[maxn]; bool f[maxn][maxn]; int g[maxn][maxn]; int ans[maxn...
13
#include <bits/stdc++.h> using namespace std; int main(int argc, const char* argv[]) { long long h, n; cin >> h >> n; long long nn = 0; n--; for (int i = 0; i < h; i++) { nn = nn * 2 + n % 2; n /= 2; } long long now = 0; long long te = ((long long)(1) << h); bool r = true; for (int i = 0; i ...
9
#include <bits/stdc++.h> using namespace std; int const Nmax = 1e5 + 10; pair<int, int> d[Nmax]; int Tree[Nmax]; int main() { { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } int n; cin >> n; for (int i = (int)1; i <= (int)n; ++i) cin >> d[i].first, d[i].second = i; sort(d + 1, d + n +...
12
#include <bits/stdc++.h> using namespace std; int main() { int n, a, b; cin >> n >> a >> b; int arr[n]; arr[0] = 2; int sum = 0; sum = 2; if (n == 1) { cout << 1; return 0; } if (a > n - 2) { cout << -1; return 0; } for (int i = 1; i <= b; ++i) { arr[i] = sum + 1; sum = arr...
9
#include <bits/stdc++.h> using namespace std; int N, M, K, a, b, c; char inp[500005]; int dp[500005][6]; int main() { scanf("%s", inp + 1); N = strlen(inp + 1); memset(dp, -50, sizeof dp); dp[0][0] = 0; for (int i = 1; i <= N; i++) { dp[i][0] = dp[i - 1][0]; if (inp[i] == '[') { dp[i][1] = max(d...
5
#include <bits/stdc++.h> using namespace std; int n; int b[100005]; int ltr[100005]; int rtl[100005]; int main() { cin >> n; for (int q = 1; q <= n; q++) { cin >> b[q]; ltr[q] = min(b[q], ltr[q - 1] + 1); } for (int q = n; q > 0; q--) { rtl[q] = min(b[q], rtl[q + 1] + 1); } int mx = 0; for (in...
8
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); int n; cin >> n; vector<long long> arr(n); for (int i = 0; i < n; i++) cin >> arr[i]; long long base = arr[0]; long long extra = 0; for...
16
#include <bits/stdc++.h> using namespace std; int n; int a[1000000]; int main() { cin >> n; int Max = 0; for (int i = 0; i < n; ++i) { cin >> a[i]; Max = max(Max, a[i]); } long long s = 0; int i = 0; while (i < n) { s += Max - a[i]; ++i; } cout << s; return 0; }
0
#include <bits/stdc++.h> using namespace std; int t, ans = 0, tot = 0, k = 0; const int mxN = 2e3 + 3, mod = 1e9 + 7; map<char, int> mp; bool check() { for (auto i : mp) if (i.second < 0) return false; return true; } int32_t main() { int n, m, a, b, c, d, i, j, sm = 0, sm1 = 0, sm2 = 0, cn = 0, cn1 = 0, ...
7
#include <bits/stdc++.h> using namespace std; int xx[4] = {0, 0, 1, -1}; int yy[4] = {-1, 1, 0, 0}; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; long double n, sum = 0; cin >> n; vector<long long int> v(n); for (long long int i = 0; i < n; i++) { cin >> v[i]; sum += v[i]; }...
1
#include <bits/stdc++.h> using namespace std; constexpr int MOD = (int)(1e9 + 7); constexpr char INF = 0x3F; constexpr int INF32 = 0x3F3F3F3F; constexpr long long INF64 = 0x3F3F3F3F3F3F3F3FLL; constexpr double EPS = 1e-9; const long double PI = acos(-1.0); template <typename T> bool amin(T& a, T b) { return (b < a) ?...
1
#include <bits/stdc++.h> using namespace std; const int N = 110000; char txt[N]; int czworki[N], siodemki[N]; int main() { scanf("%s", txt); int n = strlen(txt); if (n % 2 == 1) { for (int i = (n - 1); i >= (0); --i) txt[i + 1] = txt[i]; txt[0] = '0'; n++; txt[n] = 0; } int a = 0, b = 0; for...
10
#include <bits/stdc++.h> using namespace std; const char IO_MODE = 3; inline long long ReadInt() { long long x = 0, s = 1; char c = getchar(); while (c < '0' || c > '9') { if (c == '-') s = -1; c = getchar(); } while (c >= '0' && c <= '9') { x = x * 10 + c - '0'; c = getchar(); } return s ...
13
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; long long x = n + 2 * n * (n - 1) + n * (n - 1) * (n - 2) + n * (((n - 1) * (n - 2) / 2) * (n - 3) / 3) + ((((n * (n - 1) / 2) * (n - 2) / 3) * (n - 3) / 4) * (n - 4) / 5); long long y = n + n * (n - 1) + n * (n ...
8
#include <bits/stdc++.h> using namespace std; const long long INF = 1000000000000000000; const int dir_4[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}}; const int dir_8[8][2] = {{1, 0}, {1, 1}, {0, 1}, {-1, 1}, {-1, 0}, {-1, -1}, {0, -1}, {1, -1}}; struct graph { int n, m; int u[10002], v[1...
15
#include <bits/stdc++.h> using namespace std; int main() { int x, y, i, ma = 0, cnt = 0; char g; scanf("%d %d", &x, &y); getchar(); for (i = 0; i < x; i++) { g = getchar(); if (g == '#') { cnt++; if (i == x - 1) { if (cnt > ma) ma = cnt; } } else if (g == '.') { if ...
1
#include <bits/stdc++.h> using namespace std; int main() { int n, sum = 0, ans = INT_MAX; cin >> n; int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < n; i++) { int ld = a[i] * 15; while (a[i]--) { int x; cin >> x; sum += (x)*5; } sum += ld; ...
1
#include <bits/stdc++.h> using namespace std; const int maxn = 3e5 + 10; int a[maxn], reds, blues, ans; vector<int> adj[maxn]; pair<int, int> dfs(int v, int p = -1) { int red = a[v] == 1, blue = a[v] == 2; for (auto i : adj[v]) if (i != p) { pair<int, int> this_res = dfs(i, v); if ((this_res.first =...
10
#include <bits/stdc++.h> using namespace std; const long double pi = acos(-1.0); const long double eps = 1e-9; const long long INF = 100000000000000; const int MAXN = 110; int t, m; int a[MAXN]; map<int, int> start; int ids = 0; int main() { cin >> t >> m; for (long long query = 1; query <= t; ++query) { string...
8
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; const int INF = 2e9; const long long INF64 = 9e18; const long double EPS = 1e-12; const long double PI = 3.14159265358979323846264338327950288419716939937510582097; const long long MD = 1000003; const long long T = 634521; const int N = 100010; ...
10
#include <bits/stdc++.h> using namespace std; const int Max_N(2050); int N, L[Max_N], R[Max_N], P[Max_N], Can[Max_N], Sum[Max_N], D[Max_N]; bool Del[Max_N]; bool check(const int &d) { for (int i = 1; i <= N; ++i) Can[i] = N, Del[i] = false, Sum[i] = N; for (int p = 1, xz; p <= N; ++p) { xz = N + 1; for (int...
21
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 5; int a[maxn]; int ans1[maxn], ans2[maxn]; int main() { int t; cin >> t; while (t--) { int n; cin >> n; memset(ans1, -1, sizeof(ans1)); memset(ans2, -1, sizeof(ans2)); ans1[0] = 0; ans2[0] = 0; int cnt1 = 0, cnt2 = 0...
9
#include <bits/stdc++.h> using namespace std; struct node { int x; bool operator<(const node& p) const { return x >= p.x; } }; long double dp[100002][102]; bool vis[100002][102]; long double dp_func(int n, int r) { if (n < r) return 0; if (r == 0) return 1; if (r == 1) return n; if (n == r) return 1; if (...
8
#include <bits/stdc++.h> using namespace std; int n, m; long long h[101010], p[101010]; bool C(long long num) { int cnt = 0; long long left = -1; for (int i = 0; i < n; i++) { if (h[i] <= p[cnt]) { left = max(left, h[i] + num); } else if (num >= h[i] - p[cnt]) { long long canMove = m...
11
#include <bits/stdc++.h> using namespace std; inline long long read() { long long f = 1, x = 0; char ch = getchar(); while (!isdigit(ch)) { if (ch == '-') f = -1; ch = getchar(); } while (isdigit(ch)) { x = x * 10 + ch - '0'; ch = getchar(); } return x * f; } const int MAXN = 2e5 + 5; cons...
19
#include <bits/stdc++.h> using namespace std; short int t, a1, a2; bool ans; int main() { std::ios::sync_with_stdio(false); cin >> t; cin >> a1; t--; ans = 0; while (t--) { cin >> a2; if (!ans && ((a1 - a2) >= 2 || (a1 - a2) <= -2)) ans = 1; a1 = a2; } if (!ans) cout << "YES"; else ...
8
#include <bits/stdc++.h> using namespace std; const long long INF = 8e18 + 5; const int maxn = 1e5 + 5; const int maxm = 3e5 + 5; struct edge { int v, nex, w; } e[maxm << 1]; int n, m, k, Q, tot; int head[maxn], par[maxn], deep[maxn], fa[maxn][21]; long long dis[maxn], va[maxn][21]; ; vector<pair<long long, int> > E[...
17
#include <bits/stdc++.h> using namespace std; int main() { char arr[105][105]; int n, i, c1, ans = 0, j; cin >> n; getchar(); for (i = 0; i < n; i++) { scanf("%s", arr[i]); c1 = 0; for (j = 0; j < n; j++) { if (arr[i][j] == 'C') { c1++; } } c1 = (c1) * (c1 - 1); c1 ...
0
#include <bits/stdc++.h> using namespace std; using i64 = long long; const int maxN = 111111; int l, r, q; int cnt[maxN], la[maxN], ra[maxN], Lb[maxN], Rb[maxN]; int va[maxN], vb[maxN]; i64 t, xL, xR; array<i64, 2> lb[maxN], rb[maxN]; vector<array<i64, 2> > cond; array<i64, 2> operator+(const array<i64, 2> &a, const ar...
27
#include <bits/stdc++.h> using namespace std; using namespace std; const int MAXN = 1e5 + 5; set<long long> s; long long tmp[MAXN], num; void getp(long long n) { for (long long i = 1; i * i <= n; i++) { if (n % i == 0) s.insert(i), s.insert(n / i); } for (set<long long>::iterator it = s.begin(); it != s.end()...
14
#include <bits/stdc++.h> using namespace std; void re(int& x); void pr(int x); void pr(const char* x); void ps(); template <class T, class... Ts> void ps(const T& t, const Ts&... ts); int n; multiset<int> els[30]; long long s[30]; void solve() { re(n); int eels = 0; for (int i = 0; i < (n); ++i) { char op; ...
20
#include <bits/stdc++.h> int main() { int n; int a[100007]; scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%d", &a[i]); int cur = a[0]; int p1 = 0; int i = 0; int fl = 1; int len = -1; while (i < n) { cur = a[i]; while (i < n && a[i] == cur) i++; if (len == -1) len = i - p1; ...
9
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); ; long long int t; t = 1; while (t--) { long long int n; cin >> n; long long int a[n]; for (long long int i = 0; i < n; i++) cin >> a[i]; map<long long int, long long i...
0
#include <bits/stdc++.h> int main() { int n, a, b; int i, j, sum; scanf("%d", &n); a = 0; b = n; sum = 0; for (i = 0; i <= n; i++) { sum += (a + i) * (b - i); } printf("%d", sum + n); }
2
#include <bits/stdc++.h> using namespace std; char s[120]; vector<int> get(char c) { if (c == 'a') return {c + 1}; else if (c == 'z') return {c - 1}; return {c - 1, c + 1}; } int main() { int T; scanf("%d", &T); while (T--) { int n; scanf("%d%s", &n, s); bool ok = true; for (int i = ...
2
#include <bits/stdc++.h> using namespace std; string s; int main() { long int i, j, a, b, c; string ans; char ch; cin >> s; a = b = 0; for (i = 0; i < s.length(); i++) { if (s[i] == 'x') { a++; } else if (s[i] == 'y') { b++; } } if (a > b) { c = a - b; for (i = 1; i <= c;...
4
#include <bits/stdc++.h> using namespace std; const int MX = 1e5 + 7; const int mod = 1e9 + 7; const int N = 1e9; const int inf = 0x3f3f3f3f; int n, k, tot; int root[MX * 40], ls[MX * 40], rs[MX * 40]; long long sum[MX * 40]; struct node { int x, r, q; bool operator<(const node &A) const { return r > A.r; } } a[MX]...
14
#include <bits/stdc++.h> #include <unordered_map> #include <unordered_set> using namespace std; #define endl "\n" #define ll long long #define sz(s) (int)(s.size()) #define INF 0x3f3f3f3f3f3f3f3fLL #define all(v) v.begin(),v.end() #define watch(x) cout<<(#x)<<" = "<<x<<endl const int dr[] { -1, -1, 0, 1, 1, 1, 0, -1 };...
0
#include <bits/stdc++.h> using namespace std; const int INF = (int)2e9; const long long INFL = (long long)9e18; const int MAXINT = ((~0) ^ (1 << 31)); const long long MAXLL = ((~0) ^ ((long long)1 << 63)); template <class T> inline T pow2(T a) { return a * a; } template <class T> inline bool mineq(T& a, T b) { retu...
6
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long n; const double PI = 3.141592653589793; cin >> n; vector<long long> v(n); for (long long i = 0; i < n; i++) cin >> v[i]; sort(v.begin(), v.end()); long long i = n - 1; long long rn =...
2
#include <bits/stdc++.h> using namespace std; const long long INF = 0x3f3f3f3f3f3f3f3f; int main() { ios::sync_with_stdio(false); long long R, ans = 1; cin >> R; for (long long i = 2;; ++i) { if (i % 2) { long long h = 1 + (i - 1) / 2 * 3; if (h > R) break; ans += 6 * min((long long)sqrt((...
15
#include <bits/stdc++.h> using namespace std; const int Mod = 1000000007; int n, m, tot, sz; int head[100010], to[400010], nxt[400010], t[100010], p2[400010]; long long w[400010], dis[100010], A[400010], P[63]; bool vis[100010]; void Add_Edge(int x, int y, long long z) { to[tot] = y, nxt[tot] = head[x], w[tot] = z, h...
18
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); int i, n1, n2, f = 1; string s1, s2; cin >> s1 >> s2; n1 = s1.size(); n2 = s2.size(); if (n1 != n2) { cout << "No"; return 0; } for (__typeof((n1 - 1)) i = (0); i <= (n1 - 1); i++) { if ((s1[i] == ...
2
#include <bits/stdc++.h> using namespace std; int N; int w[100010]; int main(void) { int i; long long l, r, Ql, Qr; cin >> N >> l >> r >> Ql >> Qr; for ((i) = 0; (i) < (int)(N); (i)++) scanf("%d", &w[i]); long long S = 0; for ((i) = 0; (i) < (int)(N); (i)++) S += w[i]; long long ans = (1ll << 60); long ...
7
#include <bits/stdc++.h> using namespace std; int main() { string s1, s2; cin >> s1; for (int i = 0; i < s1.size(); i++) { if (s1[i] == '>') s2 += "1000"; else if (s1[i] == '<') s2 += "1001"; else if (s1[i] == '+') s2 += "1010"; else if (s1[i] == '-') s2 += "1011"; else...
4
#include <bits/stdc++.h> using namespace std; const long long N = 200 * 1000 + 5; vector<long long> g[N]; long long a[N], n, dp[N] = {0}, ans[N]; long long dfs(long long u, long long p) { for (auto it : g[u]) { if (it == p) continue; dp[u] += max(0ll, dfs(it, u)); } if (a[u]) dp[u] += 1; else dp...
10
#include <bits/stdc++.h> using namespace std; int arr[1000][1000]; int cnt[4][4][1000][1000]; char str[1005]; int getmx(int m1, int m2) { double l1 = (m1 / 10000 * log(3)) + (m1 % 10000 * log(2)); double l2 = (m2 / 10000 * log(3)) + (m2 % 10000 * log(2)); return l1 < l2 ? m2 : m1; } long long modpow(long long b, ...
15
#include <bits/stdc++.h> using namespace std; const int MN = (int)1e6 + 6; int n, m, p, k; long long wyn; int main() { int i, j, a, b, vp, vk; scanf("%d", &n); scanf("%d", &p); k = p; for (i = 0; i < n; i++) { scanf("%d %d", &vp, &vk); if (k < vp) { wyn += vp - k; p = k; k = vp; ...
13
#include <bits/stdc++.h> int main() { char c; int m = 0, f = 0; while ((c = getchar()) != '\n') { if (c == 'M') m++; else if (m) f = ((m > f + 1) ? m : f + 1); } printf("%d\n", f); }
12
#include <bits/stdc++.h> using namespace std; long long mult(long long a, long long b, long long p = (long long)(998244353)) { return ((a % p) * (b % p)) % p; } long long add(long long a, long long b, long long p = (long long)(998244353)) { return (a % p + b % p) % p; } long long fpow(long long n, long long k, long...
5
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") #pragma GCC optimization("unroll-loops") using namespace std; using namespace chrono; long long int sieve_size = 1e6; vector<bool> state(sieve_size, 1); long long int exp(long long int n, long long int k, long lo...
1
#include <bits/stdc++.h> using namespace std; const int maxn = 5e5 + 10, mod = 1e9 + 7, INF = 0x3f3f3f3f; pair<int, int> seg[maxn]; int ans[maxn]; vector<int> to[maxn]; queue<int> q; int mn[maxn << 2], lz[maxn << 2]; void init(int l, int r, int rt) { mn[rt] = lz[rt] = 0; if (l == r) { seg[l].first = seg[l].seco...
13
#include <bits/stdc++.h> using namespace std; struct bus { int s, t; } line[100100]; bool acmp(bus rhs, bus lhs) { return rhs.t < lhs.t; } long long int n, m, dp[100100]; int main() { cin >> n >> m; for (int i = 0; i < m; i++) cin >> line[i].s >> line[i].t; sort(line, line + m + 1, acmp); dp[0] = 1; int cia...
9
#include <bits/stdc++.h> using namespace std; int main() { int nb; cin >> nb; for (int _i = 0; _i < nb; _i++) { string a; cin >> a; string j = a; if (a[0] != a[a.length() - 1]) { cout << a << endl; } else { sort(a.begin(), a.end()); if (j == a) { cout << -1 << endl; ...
1
#include <bits/stdc++.h> using namespace std; const int maxn = 100000 + 10; int n, a[maxn]; vector<int> v1, v2; int gcd(int a, int b) { if (!b) return a; return gcd(b, a % b); } void pri() { for (int i = 1; i <= n; i++) for (int j = 1; j <= a[i]; j++) printf("%c", i + 'a' - 1); cout << endl; } int main() { ...
17
#include <bits/stdc++.h> using namespace std; template <class T> inline void smin(T &a, T b) { if (b < a) a = b; } template <class T> inline void smax(T &a, T b) { if (a < b) a = b; } const int maxn = 3 * 100000 + 1000; int n, k; pair<int, int> p[maxn]; int main() { ios_base::sync_with_stdio(false); cin >> n; ...
12
#include <bits/stdc++.h> using namespace std; int f[21][11][5], g[21][11][5], n, t; int main() { int i, j, k, s, ans = 0; scanf("%d %d", &n, &t); for (i = 1; i <= 4; i++) f[2][1][i] = i - 1; for (i = 1; i <= 4; i++) g[2][1][i] = 0; for (i = 3; i <= n; i++) { for (j = 1; j <= t; j++) { for (k = 1; k ...
11
#include <bits/stdc++.h> using namespace std; const int maxn = 500005, G = 3, p = 998244353; char s[maxn], t[maxn]; int w[1 << 20]; int f[1 << 20], g[1 << 20]; int n, m, k, N; int is[maxn][5], rev[1 << 20], ff[1 << 20]; void change(char &c) { if (c == 'A') c = 0; else if (c == 'C') c = 1; else if (c == 'T...
17
#include <bits/stdc++.h> using namespace std; long long price[100005]; int main() { int N, K; long long b; cin >> N >> K; cin >> b; for (int i = 0; i < N; i++) cin >> price[i]; long long sum = 0, ans = N; priority_queue<long long, vector<long long>, greater<long long> > q; for (int i = N - 2; i >= 0; i-...
9
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 10; int a[maxn]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n; cin >> n; for (int i = 1; i <= n; ++i) cin >> a[i]; vector<int> lis = {a[1]}; for (int i = 2; i <= n; ++i) { if (a[i] > lis.back()) lis.push_bac...
7
#include <bits/stdc++.h> using namespace std; bool init() { string S; cin >> S; return S == "start"; } bool ask(int x, int y) { if (x == y) return true; cout << "? " << x << " " << y << endl; char c; cin >> c; return c == 'x'; } void answer(int x) { cout << "! " << x << endl; } int main() { while (ini...
12
#include <bits/stdc++.h> using namespace std; template <class X> bool mini(X& a, const X& b) { if (a > b) { a = b; return 1; } return 0; } template <class X> bool maxi(X& a, const X& b) { if (a < b) { a = b; return 1; } return 0; } typedef const int& ci; struct trie { trie* child[2]; int...
14
#include <bits/stdc++.h> using namespace std; vector<string> const elems = { "H", "He", "Li", "Be", "B", "C", "N", "O", "F", "Ne", "Na", "Mg", "Al", "Si", "P", "S", "Cl", "Ar", "K", "Ca", "Sc", "Ti", "V", "Cr", "Mn", "Fe", "Co", "Ni", "Cu", "Zn", "Ga", "Ge", "As", "Se", "Br", "Kr", "Rb", "Sr",...
14
#include <bits/stdc++.h> using namespace std; char s[103], mpp[5]; map<char, int> mp, mp2; int main() { scanf("%s", s); int l = strlen(s); int t = 0; char r = 'R', y = 'Y', b = 'B', g = 'G'; for (int i = 0; i < l; i += 4) { if (s[i] != '!') { mp[s[i]] = 1; mpp[1] = s[i]; t += 1; br...
3
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; int l[N], r[N], p; double eval(int i) { double n = r[i] - l[i] + 1; double x = r[i] / p - l[i] / p + (l[i] % p == 0); return x / n; } int main() { int n; cin >> n >> p; for (int i = 0; i < n; i++) cin >> l[i] >> r[i]; double ans = 0.0; ...
9
#include <bits/stdc++.h> using namespace std; const int N = 100; signed main() { int t; cin >> t; while (t--) { int r, c, cnt = 0, x = 0; cin >> r >> c; char a[N][N]; int row[N], column[N]; int b = 1; memset(row, 0, sizeof row); memset(column, 0, sizeof column); for (int i = 1; i <...
10
#include <bits/stdc++.h> using namespace std; vector<int> a; string c; int n; int mem[51][2001]; int dp(int i, int k) { if (k <= 0) return 0; if (mem[i][k] != -1) return mem[i][k]; int mn = 1e9; for (int j = 0; j < n; j++) { if (c[i] != c[j] && a[j] > a[i]) { mn = min(dp(j, k - a[j]) + abs(i - j), mn)...
12
#include <bits/stdc++.h> using namespace std; long long a1, a2, a3, a4, a5, a6, s, x; int main() { ios::sync_with_stdio(0); cin >> a1 >> a2 >> a3 >> a4 >> a5 >> a6; x = 2 * a1 - 1; for (int i = 0; i < a2 + a3; i++) { if (i < a6) x++; else x -= (i > a6); if (i < a2) x++; else ...
8
#include <bits/stdc++.h> using namespace std; long long arr[(int)1e6] = {}; int main() { int n; cin >> n; arr[0] = 1, arr[1] = 13; for (int i = 1; i <= n; i++) { arr[i] = arr[i - 1] + (12 * i); } cout << arr[n - 1]; return 0; }
5
#include <bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; const int N = (int)5e5 + 100; const int M = (int)2e6 + 100; const int inf = (int)1e9 + 100; set<int> v[N][2]; int D[N]; pair<int, int> ma1[N][2]; pair<int, int> ma2[N][2]; pair<int, int> ma3[N][2]; void get(int x, int z, pair<int, int> ma4) { if...
19
#include <bits/stdc++.h> using namespace std; int n; int cnt; long long a[10000005]; long long b[10000005]; long long ans; bool cmp(long long a, long long b) { return a < b; } int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%lld", &a[i]); scanf("%lld", &b[i]); } sort(a + 1, a + 1 + n...
11
#include <bits/stdc++.h> using namespace std; void Read(int &x) { char c; while (c = getchar(), c != EOF) if (c >= '0' && c <= '9') { x = c - '0'; while (c = getchar(), c >= '0' && c <= '9') x = x * 10 + c - '0'; ungetc(c, stdin); return; } } int n, d, MOD, f[1000 + 10][11], g[1000 +...
19
#include <bits/stdc++.h> using namespace std; double n, m, t, x, y, k, a, b, lng, w, l, r, alpha; double f(double p) { return (p * a + sqrt(lng * lng - p * p) * b - p * sqrt(lng * lng - p * p)) / lng; } int main() { cout << fixed << setprecision(12); cin >> a >> b >> lng; double EPS = 0.0000000001; d...
17
#include <bits/stdc++.h> using namespace std; map<long long int, long long int> mp[26]; int main() { int a[27]; for (int i = 0; i < 26; i++) { int b; scanf("%d", &b); a[i] = b; } char f[100005]; scanf("%s", f); long long int sum = 0, ans = 0; for (int i = 0; i < strlen(f); i++) { int t = f...
10
#include <bits/stdc++.h> using namespace std; template <typename T> using vc = vector<T>; using pii = pair<long long, long long>; void xmax(long long& a, long long b) { a = max(a, b); } void xmin(long long& a, long long b) { a = min(a, b); } void print(vc<long long>& a, string second) { cerr << "prinitng " << second ...
14
#include <bits/stdc++.h> using namespace std; long double esp = 1e-11; const long double PI = acos((long double)-1); const long long int INF = 0x3f3f3f3fll; const int MOD = 1000000007ll; const int maxn = 200010; vector<pair<int, int> > q[2]; priority_queue<pair<pair<int, int>, int> > p; int main() { int n, c, d; sc...
10
#include <bits/stdc++.h> using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); inline long long rand(long long x, long long y) { return rng() % (y + 1 - x) + x; } string inline to_string(char c) { string second(1, c); return second; } template <typename T> inline T gcd(T a, T b...
16
#include <bits/stdc++.h> using namespace std; char buf[32000000], *pt = buf, *o = buf; int getint() { int f = 1, x = 0; while ((*pt != '-') && (*pt < '0' || *pt > '9')) pt++; if (*pt == '-') f = -1, pt++; else x = *pt++ - 48; while (*pt >= '0' && *pt <= '9') x = x * 10 + *pt++ - 48; return x * f; } ...
14
#include <bits/stdc++.h> using namespace std; long long n, m, sz[500010], dep[500010], b[500010], ans; vector<long long> zh[500010]; void dfs(long long x, long long fa) { long long i; dep[x] = dep[fa] + 1; sz[x] = 1; for (i = 0; i < zh[x].size(); i++) if (zh[x][i] != fa) { dfs(zh[x][i], x); sz[x...
8
#include <bits/stdc++.h> using namespace std; bool vis[30101]; int a; int n, m; vector<int> v[30101]; void DFS(int u) { if (vis[u]) return; vis[u] = true; for (int i = 0; i < v[u].size(); i++) { DFS(v[u][i]); } a++; if (a == n) printf("%d\n", u); else printf("%d ", u); } int main() { int c, ...
12
#include <bits/stdc++.h> using namespace std; template <typename T> inline T S(T a) { return a * a; } template <class T> inline string tostring(T a) { ostringstream os(""); os << a; return os.str(); } template <typename T> inline long long tolong(T a) { long long res; istringstream os(a); os >> res; ret...
7
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; const double eps = 1e-8; const int maxn = 1e5 + 10; vector<int> vec[maxn]; int a[maxn]; int main() { std::ios::sync_with_stdio(false); std::cin.tie(0); int n; cin >> n; for (int i = 0; i < n; ++i) { cin >> a[i]; vec[a[i]].push_back...
8
#include <bits/stdc++.h> using namespace std; int n; long long ans; priority_queue<int> q; int main() { scanf("%d", &n); for (int i = 1, x; i <= n; i++) { scanf("%d", &x); if (q.empty()) { q.push(-x); continue; } if (-q.top() < x) { ans += x + q.top(); q.pop(), q.push(-x); ...
16
#include <bits/stdc++.h> using namespace std; int n; int dp1[1000005], dp2[1000005]; int ans, s; int main() { scanf("%d", &n); if (n == 2) { puts("10"); return 0; } dp1[1] = 5; dp2[1] = 2; for (int i = 2; i <= (n - 4) >> 1; ++i) { dp2[i] = (dp2[i - 1] << 1) % 1000000009; dp1[i] = ((long long...
18
#include <bits/stdc++.h> using namespace std; const int N = 100005; const int mod = 1e9 + 7; double eps = 1e-9; int n, m, x[N], b[N], ne[N], pos, num, ans[N]; double l, r, mid, f[N]; int sign(double x) { return (x > eps) - (x < -eps); } int main() { scanf("%d%d", &n, &m); for (int i = (1); i < (n + 1); i++) scanf("...
15