solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> using namespace std; const int mn = 201000; struct Node { int p, d; } a[mn], x; int ans[mn][2], n, i, s, d, len = 0; priority_queue<Node> q; bool operator<(Node a, Node b) { return a.d < b.d; } int main() { scanf("%d%d", &n, &s); for (i = 1; i <= n; ++i) if (scanf("%d", &d)) { x...
14
#include <bits/stdc++.h> using namespace std; int main() { int N, M, H; while (cin >> N >> M >> H) { vector<int> s; int sum = 0; H--; for (int i = 0; i < M; i++) { int si; cin >> si; s.push_back(si); sum += si; } if (sum < N) { cout << "-1.0" << endl; cont...
8
#include <bits/stdc++.h> using namespace std; int n, m, a[13][2002], cost[2002][1 << 12]; int dp[2002][1 << 12]; void solve() { cin >> n >> m; for (int i = 1; i < n + 1; i++) { for (int j = 1; j < m + 1; j++) { cin >> a[i][j]; } } memset(cost, 0, sizeof cost); for (int i = 1; i < m + 1; i++) { ...
12
#include <bits/stdc++.h> #pragma GCC optimize("-Ofast") using namespace std; int power(int x, int y) { int temp; if (y == 0) return 1; temp = (power(x, y / 2)) % 1000000007; if (y % 2 == 0) return ((temp % 1000000007) * temp) % 1000000007; else return ((x * temp % 1000000007) * temp) % 1000000007; } i...
0
#include <bits/stdc++.h> using namespace std; int cal(string s) { int res = 0; while (true) { int cnt = 0; for (int i = 1; i < s.length(); ++i) cnt += (s[i - 1] == 'M' && s[i] == 'F'); if (cnt == 0) break; for (int i = 1; i < s.length(); ++i) if (s[i - 1] == 'M' && s[i] == 'F') { ...
12
#include <bits/stdc++.h> using namespace std; int n, m, a[512], p[521]; char c[512]; int bio[22][1 << 20], dp[22][1 << 20]; int rek(int x, int mask) { if (x == m) return 0; int &ref = dp[x][mask]; if (bio[x][mask]) return ref; bio[x][mask] = 1; int mn = 0; if (c[x] == 'p') { for (int i = 0; i < n; ++i) ...
14
#include <bits/stdc++.h> using namespace std; int main() { int ara[10]; int n, k, ct = 0; cin >> n >> k; for (int i = 0; i < n; i++) { memset(ara, 0, sizeof(ara)); int a; cin >> a; while (a > 0) { int b = a % 10; a /= 10; ara[b] = 1; } int f = 1; for (int i = 0; i <...
3
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") using namespace std; const long long MAX = 1e18 + 1; const double pi = 3.1415926535897932384626433832; const long long M = 1e9 + 7; long long modpow(long long x, long long n, long long mod1) { if (n == 0) return 1 % mod1; long long u = modpow(x, n / 2, mod1); ...
6
#include <bits/stdc++.h> using namespace std; int f[100010][5], ans[100010][5]; int i, j, k, g[100010], len; char s[100010]; int main() { g[2] = 10; g[3] = 100; scanf("%s", s); len = strlen(s); for (i = 0; i <= 7; i++) for (j = 1; j <= 3; j++) f[i][j] = -1; for (i = len - 1; i >= 0; i--) if (f[(s[i]...
7
#include <bits/stdc++.h> using namespace std; int n; char mat[110][110]; int marki[110], markj[110]; int main() { int i, j, k; scanf("%d", &n); for (i = 0; i < n; i++) { marki[i] = 0; markj[i] = 0; } for (i = 0; i < n; i++) { for (j = 0; j < n; j++) { scanf(" %c", &mat[i][j]); if (mat[...
7
#include <bits/stdc++.h> using namespace std; void solve() { int n, k; cin >> n >> k; long long arr[n]; long long sum = 0; long long num = 0; long long ans = 0; map<long long, long long> ma; long long maxi = 0; for (int i = 0; i < n; i++) { cin >> arr[i]; } for (long long i = 0; i < n; i++) { ...
5
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, m; cin >> n >> m; vector<vector<int>> g(n); int a, b; for (int i = 0; i < m; i++) { cin >> a >> b; a--; b--; g[a].push_back(b); g[b].push_back(a); } vector<pair<int, int>> t; ...
9
#include <bits/stdc++.h> using namespace std; int ans1, a[2][120000], n, m, x, y, i; long long ans2; void renew(int x, long long y) { if (!y) return; if (x == ans1) ans2 += y; else if (x > ans1) ans1 = x, ans2 = y; } long long C(int n, int k) { long long res = 1; for (int i = n; i >= n - k + 1; --i) r...
20
#include <bits/stdc++.h> using namespace std; const int N = 1000020; int Tes, n, i, j, k, cnt, id[N]; int nxt[N], pre[N], Ans, ok[N]; int st[N], top, r[N], op[N]; char s[N], ch; long long val; void init() { n = cnt = 0; Ans = 0; scanf("%lld", &val); n = 0; top = 0; while ((ch = getchar()) >= 32) { if (c...
21
#include <bits/stdc++.h> using namespace std; const long long N = 1e5 + 5; signed main() { ios::sync_with_stdio(false); cin.tie(0); long long n, m, v; cin >> n >> m >> v; if (m < n - 1) { cout << -1 << endl; return 0; } if (m > (n - 1) * (n - 2) / 2 + 1) { cout << -1 << endl; return 0; }...
9
#include <bits/stdc++.h> int n, k, m; int r, g, b; int main() { scanf("%d %d %d", &r, &g, &b); if (r > 0) n = (r - 1) / 2 * 3 + 30; if (g > 0) m = (g - 1) / 2 * 3 + 31; if (b > 0) k = (b - 1) / 2 * 3 + 32; if (n > m) m = n; if (k > m) m = k; printf("%d", m); return 0; }
2
#include <bits/stdc++.h> using namespace std; const double eps = 1e-8; const int maxn = 300000; const int max0 = 1e6; int n, q, a, b; int x[maxn + 5]; struct node { int k; long long b; double l, r; double delta; int deltak; long long deltab; node *p, *c[2]; node(const int &_k = 0, const long long &_b = ...
22
#include <bits/stdc++.h> using namespace std; char s[500010]; int pre[500010], nxt[500010]; char op[500010]; int match[500010]; void del(int l, int r) { pre[nxt[r]] = pre[l]; nxt[pre[l]] = nxt[r]; } int main() { int n, m, p; scanf("%d%d%d", &n, &m, &p); scanf("%s", s + 1); stack<int> st; for (int i = 1; i...
9
#include <bits/stdc++.h> using namespace std; int main() { int a[10001] = {4, 22, 27, 58, 85, 94, 121, 166, 202, 265, 274, 319, 346, 355, 378, 382, 391, 438, 454, 483, 517, 526, 535, 562, 576, 588, 627, 634, 636, 645}, n; cin >> n; cout << a[n - 1]; return 0; }
11
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 * 4; inline int get() { int x; cin >> x; return x; } inline long long getlong() { long long x; cin >> x; return x; } inline string getString() { string s; cin >> s; return s; } template <typename T> inline vector<T> getvector(int len) ...
1
#include <bits/stdc++.h> using namespace std; const long long N = 1e5 + 43; const long long INF = 1e9; long long st[N << 2]; vector<long long> a; long long n; void build(long long id, long long l, long long r) { if (l == r) { st[id] = 1; return; } long long mid = (l + r) / 2; build(id * 2, l, mid); bu...
8
#include <bits/stdc++.h> using namespace std; int n, m; int a[110000], b[110000]; int check(long long x) { int head = 1; for (int i = 1; i <= n; i++) { while (abs(b[head] - a[i]) > x && head < m) head++; if (abs(b[head] - a[i]) > x) return 0; } return 1; } int main() { scanf("%d %d", &n, &m); for (i...
7
#include <bits/stdc++.h> using namespace std; int n, m, g[100010], fa[100010], xiao[100010], a, b; int xia[100010]; int findf(int x) { int z = x; int y; while (fa[x] != x) x = fa[x]; while (fa[z] != z) { y = z; z = fa[z]; fa[y] = x; } return x; } void unio(int c, int d) { int a = findf(c); i...
5
#include <bits/stdc++.h> using namespace std; double a, h; double r; int dcmp(double x) { return (x > 1e-6) - (x < -1e-6); } int main() { while (cin >> r) { int ok = 0; for (a = 1; a <= 10; a++) { for (h = 1; h <= 10; h++) { if (dcmp((a * h) / sqrt(a * a + 4 * h * h) - r) == 0) { cout ...
10
#include <bits/stdc++.h> using namespace std; template <class T> void print(vector<T> v) { cerr << "["; if (v.size()) cerr << v[0]; for (int i = (1); i < (v.size()); ++i) cerr << ", " << v[i]; cerr << "]\n"; } template <class T> string i2s(T x) { ostringstream o; o << x; return o.str(); } vector<string> s...
9
#include <bits/stdc++.h> using namespace std; inline int readint() { char c = getchar(); while (!isdigit(c)) c = getchar(); int x = 0; while (isdigit(c)) { x = x * 10 + c - '0'; c = getchar(); } return x; } inline long long readlong() { char c = getchar(); while (!isdigit(c)) c = getchar(); lo...
9
#include <bits/stdc++.h> using namespace std; vector<int> nexti[1005], previ[1005]; int visit[1005]; vector<int> f; void func(int s) { int pp = s; while (pp != 0) { s = pp; pp = previ[pp][0]; } while (s != 0) { visit[s] = 1; f.push_back(s); s = nexti[s][0]; } } int main() { int N, i, j, ...
7
#include <bits/stdc++.h> using namespace std; int main() { int n, x; cin >> n >> x; vector<int> a(n); for (int i = 0; i < n; ++i) { cin >> a[i]; } sort(a.begin(), a.end()); if (a[(n + 1) / 2 - 1] == x) { cout << "0\n"; return 0; } int j = lower_bound(a.begin(), a.end(), x) - a.begin(); i...
7
#include <bits/stdc++.h> using namespace std; int dx[] = {0, 0, 1, -1}; int dy[] = {1, -1, 0, 0}; int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1}; int dy8[] = {1, -1, -1, 0, 1, -1, 0, 1}; int kx8[] = {1, 1, 2, 2, -1, -1, -2, -2}; int ky8[] = {2, -2, 1, -1, 2, -2, 1, -1}; long long bigmod(long long a, long long b, long long c) ...
15
#include <bits/stdc++.h> using namespace std; long long xo, yo, ax, ay, bx, by, x, y, t; vector<pair<long long, long long> > v; int main() { cin >> xo >> yo >> ax >> ay >> bx >> by >> x >> y >> t; while (xo <= 3 * 1e16 + 10 and yo <= 3 * 1e16 + 10) { v.emplace_back(xo, yo); xo = ax * xo + bx; yo = ay * ...
9
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5, pr = 31, mod = 1e9 + 9; long long powers[N], hash_p[N], arr[N], n; void cal() { powers[0] = 1; for (int i = 1; i < N; i++) powers[i] = (powers[i - 1] * pr) % mod; hash_p[0] = 0; for (int i = 0; i < n; i++) hash_p[i + 1] = (hash_p[i] + powe...
14
#include <bits/stdc++.h> const int maxn = 1e5 + 10; using namespace std; long long gcd(long long p, long long q) { return q == 0 ? p : gcd(q, p % q); } long long qpow(long long p, long long q) { long long f = 1; while (q) { if (q & 1) f = f * p; p = p * p; q >>= 1; } return f; } inline void umax(int...
16
#include <bits/stdc++.h> using namespace std; const double PI = 3.14159265358979323846264338327950288; int in_c() { int c; while ((c = getchar()) <= ' ') { if (!~c) return ~0; } return c; } int in() { int x = 0, c; while ((unsigned int)((c = getchar()) - '0') >= 10) { if (c == '-') return -in(); ...
5
#include <bits/stdc++.h> using namespace std; const int MOD = 1000 * 1000 * 1000 + 7; const int N = 200500; vector<int> E[N]; int A[N], B[N]; long long W[N]; int was[N]; long long path[N]; const int M = 62; vector<long long> Q; vector<long long> paths; void DFS(int x, int p) { was[x] = true; paths.push_back(path[x]...
18
#include <bits/stdc++.h> using namespace std; int main() { int n; char s[] = {'v', '<', '^', '>'}; char q[3], w[3]; scanf("%s%s", q, w); scanf("%d", &n); n %= 4; int flag = 0; int st, ed; for (int i = 0; i < 4; i++) { if (s[i] == q[0]) st = i; if (s[i] == w[0]) ed = i; } int t = st; int ...
1
#include <bits/stdc++.h> using namespace std; const long long N = 5e5 + 7; int i, n, k, x, y, t, v, u, vs[N]; vector<int> group; void bfs(int node, vector<vector<int>> &graph) { vs[node] = 1; queue<int> q; q.push(node); while (!q.empty()) { node = q.front(); group.push_back(node); q.pop(); for (...
5
#include <bits/stdc++.h> using namespace std; const long long mod = 998244353; const long long inf = 1e18; const int maxn = 3e6 + 7; int q1[maxn], q2[maxn], a[maxn], ans[25]; int c1, c2; int main() { ios::sync_with_stdio(false); ; long long t, n; cin >> t; while (t--) { cin >> n; cout << (n - 1) / 2 <...
0
#include <bits/stdc++.h> using namespace std; string bs(long long int left, long long int right, long long int val) { while (left <= right) { long long int l = left * (left + 1) / 2, r = right * (right + 1) / 2; if (l + r == val) { return "YES"; } else if (l + r > val) { right--; } else { ...
5
#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; while (t--) { int i, n; cin >> n; int a[n + 1]; int pos[n + 1]; char ans[n + 1]; for (i = 1; i <= n; i++) { cin >> a[i]; pos[a[i]] = i; ...
5
#include <bits/stdc++.h> using namespace std; char s[10][100] = {"vaporeon", "jolteon", "flareon", "espeon", "umbreon", "leafeon", "glaceon", "sylveon"}; int n; char S[100]; int main() { cin >> n >> S; for (int i = 0; i <= 7; i++) { int len = strlen(s[i]); if (len == n) { bool flag...
2
#include <bits/stdc++.h> using namespace std; void solve() { int n, m; cin >> n >> m; vector<vector<int>> a(n, vector<int>(m)); for (int i = 0; i < n; ++i) for (int j = 0; j < m; ++j) cin >> a[i][j]; vector<vector<int>> row(n, vector<int>(m)), col(n, vector<int>(m)); vector<int> row_max(n), col_max(m); ...
8
#include <bits/stdc++.h> using namespace std; long long angka[100005]; int main() { long long tc, i, j, banyak, perlu, tampung; scanf("%lld", &banyak); getchar(); for (i = 0; i < banyak; i++) { scanf("%lld", &angka[i]); getchar(); } if (banyak == 1) { printf("1 1\n"); printf("1\n"); prin...
8
#include <bits/stdc++.h> using namespace std; int sum[100005], sz; vector<int> v, ans; int main() { ios_base::sync_with_stdio(0); cin.tie(0); string s; cin >> s; sz = s.size(); int pos = -1, add = 0; for (int i = sz - 1; i >= 0; i--) { if (s[i] == ')') add--; else if (s[i] == '(') add+...
7
#include <bits/stdc++.h> using namespace std; map<char, int> mp; char s[10][10]; int main() { mp['Q'] = 9; mp['q'] = 9; mp['K'] = 0; mp['k'] = 0; mp['R'] = 5; mp['r'] = 5; mp['B'] = 3; mp['b'] = 3; mp['n'] = 3; mp['N'] = 3; mp['P'] = 1; mp['p'] = 1; int i, j, w = 0, b = 0; for (i = 0; i < 8;...
1
#include <bits/stdc++.h> using namespace std; struct event { long long id, t, h; int type; bool operator<(const event &r) const { return t > r.t; } bool operator==(const event &r) const { return id == r.id && t == r.t && h == r.h && type == r.type; } void print() { cout << id << " " << t << " " << h << ...
17
#include <bits/stdc++.h> using namespace std; void debug_out() { cerr << '\n'; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...); } const long long MAXN = 5e2 + 10; long long n, k, c[MAXN], dp[2][MAXN][MAXN]; vector<long long> vec; void dp_update() { ...
11
#include <bits/stdc++.h> using namespace std; long long mod = 998244353; long long inf = 1e15; long long m_inf = INT_MIN; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); std::cout.unsetf(std::ios::floatfield); std::cout.precision(15); long long n, k; cin >> n >> k; long...
5
#include <bits/stdc++.h> using namespace std; int main() { char s[111]; cin >> s; int l = strlen(s); int flag = 0; for (int i = 0; i < l; i++) { if (s[i] == 'H' || s[i] == 'Q' || s[i] == '9') { flag = 1; cout << "YES" << endl; break; } } if (flag == 0) cout << "NO" << endl; ret...
1
#include <bits/stdc++.h> using namespace std; int n; int num[100010]; int main() { while (~scanf("%d", &n)) { for (int i = 1; i <= n; ++i) scanf("%d", num + i); sort(num + 1, num + n + 1); if (n != 1) printf("1 "); else if (num[1] == 1) puts("2"); else puts("1"); bool flag = ...
5
#include <bits/stdc++.h> using namespace std; const int N = 2010; int f[N][N]; char a[N][N]; char us[N][N]; vector<pair<int, int> > g[2 * N + 28]; int main() { int n, k; cin >> n >> k; for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) cin >> a[i][j]; if (n == 1) { if (a[0][0] != 'a' && k) a[0][0] ...
11
#include <bits/stdc++.h> using namespace std; bool ff; int n, k, i, x, y, l, r, mid, ans, tot, fir[400400], ne[400400], la[400400], g[400400], zs[400400], g2[400400], f[400400], sum[400400], up[400400], a[400400]; void ins(int x, int y) { la[++tot] = y; ne[tot] = fir[x]; fir[x] = tot; } void dfs(int x, in...
18
#include <bits/stdc++.h> using namespace std; int n; vector<vector<int>> tab; vector<int> sx, sy; vector<pair<int, pair<int, int>>> steps; void swapcol(int i, int j, int sz) { swap(sy[i], sy[j]); steps.push_back({2, {i + 1, j + 1}}); for (int k = 0; k < sz; k++) { if (tab[k][i] != tab[k][j]) swap(tab[k][i], t...
13
#include <bits/stdc++.h> using namespace std; const long long MODULE = 998244353; const int MAXPOLY = 1048576; long long add(long long a, long long b) { long long res = a + b; res %= MODULE; return res; } long long mul(long long a, long long b) { long long res = a * b; res %= MODULE; return res; } long long...
16
#include <bits/stdc++.h> using namespace std; const long mm = 1000000007; const int maxn = 200005; template <class TYPE> TYPE gcd(TYPE x, TYPE y) { if (y) return gcd(y, x % y); else return x; } template <class TYPE> TYPE lcm(TYPE x, TYPE y) { TYPE t = gcd(x, y); return t ? (x / t * y) : 0; } string s[10...
6
#include <bits/stdc++.h> using namespace std; const int N = 200005, M = 2000005, P = 1000000007; int p[N], cnt[M], mm[M], cp[N]; int ip[M], pr[M], mp[M], np; vector<int> F[N]; int main() { int n; scanf("%d", &n); int flag = 0; for (int i = 0; i < n; ++i) { scanf("%d", p + i); } sort(p, p + n); for (in...
21
#include <bits/stdc++.h> using namespace std; int Get() { char c; while (c = getchar(), c < '0' || c > '9') ; int X = c - 48; while (c = getchar(), c >= '0' && c <= '9') X = X * 10 + c - 48; return X; } int Pow(int A, int B, int Mod) { if (!B) return 1; int T = Pow((long long)A * A % Mod, B / 2, Mod);...
21
#include <bits/stdc++.h> template <typename T> using Vector2D = std::vector<std::vector<T>>; template <typename T> using Vector3D = std::vector<Vector2D<T>>; using PairInt = std::pair<int, int>; using PairInt64 = std::pair<int64_t, int64_t>; using MapInt = std::map<int, int>; using MMapInt64 = std::multimap<int64_t, in...
8
#include<bits/stdc++.h> using namespace std; #define fastio ios_base::sync_with_stdio(0);cin.tie(0) #define f(i,m,n) for(int i = (m); i < (n); i++) #define pb push_back #define mp make_pair #define fst first #define snd second #define all(v) sort(v.begin(),v.end()) #define sz(v) int(v.size()) const int MOD=1e9+7; const...
0
// by shik #include <cstdio> #include <cstring> #include <algorithm> #include <queue> #include <cmath> #define N 2010 #define SZ(x) ((int)(x).size()) #define FOR(it,c) for ( __typeof((c).begin()) it=(c).begin(); it!=(c).end(); it++ ) using namespace std; double sqr( double x ) { return x*x; } const int dx[]={-1,-1,-1,0...
11
#include <bits/stdc++.h> using namespace std; const int MAXN = 100005; bool vis[MAXN]; bool inQueue[MAXN]; int layer[MAXN]; int sons[MAXN]; bool yes = true; vector<int> graph[MAXN]; int main() { int ans = 0, n, k; scanf("%d%d", &n, &k); queue<int> que; for (int i = 0; i < n - 1; i++) { int u, v; scanf("...
10
#include <bits/stdc++.h> using namespace std; int dir[] = {0, 1, 0, -1, 1, 0, -1, 0}; void solve() { int n, k; cin >> n >> k; vector<int> id(n + 1); for (int i = 1; i <= n; i++) cin >> id[i]; for (int i = 1; i <= n; i++) { if (i >= k) { cout << id[k] << endl; return; } k -= i; } } in...
2
#include <bits/stdc++.h> using namespace std; int a[100001]; int main() { ios_base::sync_with_stdio(0); int n, k; cin >> n >> k; long long s = 0; for (int i = 1; i <= n; i++) { cin >> a[i]; s = s + a[i]; } if (s % k != 0) { cout << "No"; return 0; } long long t = s / k; long long sum...
3
#include <bits/stdc++.h> using namespace std; const int maxn = 3e5 + 5; long long a[maxn]; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; scanf("%d", &n); for (int i = 1; i <= n; ++i) scanf("%d", &a[i]); sort(a + 1, a + n + 1); long long ans = 0; for (int i = 1; i < n; ++i) ans ...
4
#include <bits/stdc++.h> using namespace std; int main() { long long int n, t; int v; cin >> t; long long int a = 6, b = 10, c = 14; while (t--) { cin >> n; if (n <= 30) cout << "NO" << endl; else if (n == 36 || n == 40 || n == 44) { cout << "YES" << endl; cout << "6 10 15 " << n...
0
/*input 2 4 1 20100 1 202 202 3 100 1 1 1 */ #include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); int T; cin >> T; while(T--) { long long n, k; cin >> n >> k; vector<long long> p(n); for(int i = 0; i < n; i++) { ...
5
#include <bits/stdc++.h> using namespace std; int i, j, m, n, tot; long long l, r, k, mid, a[100005], Tree[100005], Q[100005]; int lowbit(int x) { return x & -x; } void insert(int x) { for (; x <= tot; x += lowbit(x)) Tree[x]++; } long long ask(int x) { long long sum = 0; for (; x; x -= lowbit(x)) sum += Tree[x];...
14
#include <bits/stdc++.h> #pragma GCC optimize("O2") using namespace std; const int MXN = 1e5 + 10; const int SQR = 330; int n, m; int A[MXN], B[MXN]; int Max[MXN]; vector<int> dq[MXN], cop, Kol; void Reset() { Kol.clear(); for (int i = 0; i <= m; i++) { for (int j = 0; j < (int)dq[i].size(); j++) { Kol.pu...
15
#include <bits/stdc++.h> using namespace std; using ll = long long; template <typename T> bool in_range(int x, int a, int b) { return a <= x && x < b; } const int MAXN = 1000005; int N; int P[MAXN]; map<int, int> pos; int cntPos, cntNeg, cntZero; int main() { scanf("%d", &N); for (int i = 0, _n = N; i < _n; i++) ...
11
#include <bits/stdc++.h> using namespace std; const int N = 21; const long long mod = 998244353LL; string s[N]; int32_t main() { ios::sync_with_stdio(false); cin.tie(NULL); int n, m, end = -1; cin >> n >> m; for (int i = 0; i < n; ++i) { cin >> s[i]; for (char c : s[i]) { if (c == '1' && end == ...
8
#include <bits/stdc++.h> using namespace std; int a[100000]; int main() { long long n; long long x, y; cin >> n >> x >> y; if (n > y) { cout << -1 << endl; return 0; } long long fst = y - n + 1; long long sq = fst * fst; if (sq + n - 1 >= x) { cout << fst << endl; for (int i = 0; i < n -...
6
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e6 + 7, MAXM = 1e6 + 7, MAXK = 1e6 + 7; long long a[MAXN], b[MAXN], ans; int father[MAXN], num; vector<int> p[MAXN]; void dfs(int x, int fa) { int len = p[x].size(); father[x] = fa; for (int i = 0; i < len; i++) { if (p[x][i] != fa) { dfs(p...
16
#include <bits/stdc++.h> using namespace std; const int N = 2e3 + 100; const int MOD = 998244353; string s; struct Graph { bool bipartite; int color[N]; int n; struct Edge { int u, v, same; Edge(int u = 0, int v = 0, int same = 0) : u(u), v(v), same(same){}; int nxt(int x) { return x ^ u ^ v; } };...
16
#include <bits/stdc++.h> using namespace std; map<string, int> m; string ans; int cnt = 0; int days[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; int main() { string s; cin >> s; for (int i = 0; i <= s.length() - 10; i++) { if (!(isdigit(s[i]) && isdigit(s[i + 1]) && s[i + 2] == '-' && is...
8
#include <bits/stdc++.h> using namespace std; long long clr[100009 + 2][4]; vector<long long> adj[100009]; bool vis[100009]; long long val[100009]; long long ox(long long a, long long b) { if ((a == 1) && (b == 2)) { return 3ll; } else if ((a == 2) && (b == 1)) { return 3ll; } else if ((a == 1) && (b == 3...
10
#include <bits/stdc++.h> using namespace std; int num[200005]; int a[200005]; int main() { int n; scanf("%d", &n); int mx = 0; for (int i = 0; i < n; i++) { scanf("%d", &a[i]); mx = max(mx, a[i]); num[a[i]]++; } sort(a, a + n); for (int i = 1; i <= mx; i++) num[i] += num[i - 1]; long long an...
11
#include <bits/stdc++.h> using namespace std; int a, b, c, x, y, z, ans; int main() { cin >> a >> b >> c; cin >> x >> y >> z; a = a - x; b = b - y; c = c - z; if (a >= 0) ans += a / 2; else ans += a; if (b >= 0) ans += b / 2; else ans += b; if (c >= 0) ans += c / 2; else an...
4
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007LL; long long pow_mod(long long a, long long n) { long long ans = 1; while (n) { if (n & 1) (ans *= a) %= mod; (a *= a) %= mod; n >>= 1; } return ans; } inline long long inv(long long a) { return pow_mod(a, mod - 2); } lon...
18
#include <bits/stdc++.h> using namespace std; using ll = long long; using P = pair<int, string>; using PP = pair<P, int>; int n; P ans[3][1 << 8]; bool v[3][1 << 8]; priority_queue<PP, vector<PP>, greater<PP> > pr; int qiu(string s) { int ss = 0; for (int i = 0; i < 8; ++i) { if (s[i] == '1') ss |= 1 << i; } ...
16
#include <bits/stdc++.h> using namespace std; int main() { int n, i = 0, res = 0; cin >> n; int h[n], a[n]; while (i < n) { cin >> h[i] >> a[i]; i++; } for (i = 0; i < n; i++) for (int j = 0; j < n; j++) if (h[i] == a[j]) res++; cout << res; return 0; }
0
#include <bits/stdc++.h> using namespace std; int main(void) { int r, c; cin >> r >> c; vector<vector<long long> > m(r, vector<long long>(c)); vector<long long> accr(r, 0); vector<long long> accc(c, 0); for (int i = 0; i < r; i++) for (int j = 0; j < c; j++) { cin >> m[i][j]; accr[i] += m[i]...
10
#include <bits/stdc++.h> const int N = 100001; int num[N]; int main() { int n, x, i; while (~scanf("%d", &n)) { if (n == 1) { scanf("%d", &x); if (x) puts("NO"); else puts("YES\n0"); continue; } for (i = 1; i <= n; ++i) scanf("%d", num + i); if (num[n]) { ...
14
#include <bits/stdc++.h> const long long INF = 4e18L + 1; const int IINF = 2e9 + 1; using namespace std; template <class TH> void _dbg(const char* sdbg, TH h) { cerr << sdbg << '=' << h << endl; } template <class TH, class... TA> void _dbg(const char* sdbg, TH h, TA... a) { while (*sdbg != ',') cerr << *sdbg++; c...
26
#include <bits/stdc++.h> using namespace std; const int maxs = 91; long long fib[maxs]; void getfib() { fib[0] = 1; fib[1] = 2; for (int i = 2; i < maxs; i++) fib[i] = fib[i - 1] + fib[i - 2]; } long long counting(long long x) { static bool used[maxs]; for (int i = maxs - 1; i >= 0; i--) if (fib[i] <= x) ...
15
#include <bits/stdc++.h> using namespace std; int n, dui; long long L, cnt; long long Ci[35]; long long ans; void Dui() { long long Bi = 2; for (dui = 1; Bi <= L; dui++) Bi <<= 1; dui += 1; } int main() { int a; for (int i = 1; i <= 343000000; i++) { a *= 2; a -= 1212; a /= 23; a = a = a = a =...
8
#include <bits/stdc++.h> using namespace std; #define INF (int)1e9 #define eps (int)1e-9 #define ll long long typedef vector<int> vi; void solve(){ int n; cin >> n; int sum=0; int ct=1; while(sum<n){ sum+=ct; ct++; } if (sum-n==1){ cout << ct << endl; return...
4
#include <bits/stdc++.h> using namespace std; int a, b; string s; int dx = 0, dy = 0; int main() { cin >> a >> b; if (a == 0 && b == 0) { puts("Yes"); return 0; } cin >> s; for (auto c : s) { if (c == 'R') dx++; else if (c == 'L') dx--; else if (c == 'U') dy++; else ...
9
#include <bits/stdc++.h> using namespace std; const int MOD = 1000000007; long double PI = 4 * atan(1); long long n, a[200001], Max, prv, cnt, ans; vector<int> v; void check(long long i) { long long cur = 0; for (int j = v.size() - 1; j >= 0; j--) { if (v[j] >= i) cur += i; else break; if (i...
10
#include <bits/stdc++.h> #pragma comment(linker, "/stack:64000000") using namespace std; const int MAX = 111111; int A[MAX]; int B[MAX]; bool lucky[MAX / 10]; int n; bool isLucky(int x) { while (x != 0) { int d = x % 10; if (d != 4 && d != 7) return false; x /= 10; } return true; } void add(int i, int...
16
#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(v.begin(), v.end()); int cnt(0), sum(0); for (int i = 0; i < n; ++i) { if (v[i] >= sum) { cnt++; sum += v[i]; } } cout << cnt; }
5
#include <bits/stdc++.h> using namespace std; vector<int> a; int main(int argc, const char *argv[]) { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; a.resize(n); for (auto &i : a) { cin >> i; i = n - i; } vector<int> rem(n + 1, 0), lst(n + 1, -1), ans; int type = 1; for...
7
#include <bits/stdc++.h> using namespace std; const int MAXN = 305; int N, M, T, tp, tu, td; int grid[MAXN][MAXN]; int row1[MAXN][MAXN], row2[MAXN][MAXN], col1[MAXN][MAXN], col2[MAXN][MAXN]; int main() { scanf("%d %d %d", &N, &M, &T); scanf("%d %d %d", &tp, &tu, &td); for (int i = 0; i < N; i++) for (int j = ...
15
#include <bits/stdc++.h> int main() { int x, y, z; scanf("%d %d %d", &x, &y, &z); printf("%.0f\n", 4 * (sqrt(x * y / z) + sqrt(x * z / y) + sqrt(y * z / x))); return 0; }
3
#include<iostream> #include<algorithm> #include<cstdio> #include<string> #include<cmath> #include<cstring> #include<map> #include<queue> #include<set> #include<stack> #define LL long long #define rep(i,l,r) for(int i=l;i<=r;++i) #define ios_speed_up ios::sync_with_stdio(0) #define dep(i,l,r) for(int i=l;i>=r;--i) #defi...
4
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize("O2,no-stack-protector,unroll-loops,fast-math") const long long maxn = 1e5 + 10, maxm = 5e2 + 10, lg = 21, mod = 1e9 + 7, inf = 1e18; long long n, q, sum = 0; struct node { bool bb = 0; pair<long long, long long> p1 = {-inf, -inf}, p...
18
#include <bits/stdc++.h> using namespace std; const long long INF = 1e18; const int N = 2e5 + 5; int a[N]; void fast() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } int freq[N]; int main() { fast(); int t; cin >> t; while (t--) { int x; cin >> x; int ans = 1; for (in...
0
#include <bits/stdc++.h> using namespace std; int main() { long long int w1, h1, w2, h2; cin >> w1 >> h1 >> w2 >> h2; cout << 2 * (h1 + h2 + 2) + w2 + w1 + (w1 - w2); return 0; }
0
#include <bits/stdc++.h> using namespace std; double PI = acos(-1); int main() { for (int n, r, v; ~scanf("%d %d %d", &n, &r, &v);) { for (int i = 0; i < n; ++i) { int s, f; scanf("%d %d", &s, &f); double dist = f - s; double t = floor(dist / (2 * PI * r)); double remain = dist - t *...
17
#include <bits/stdc++.h> using namespace std; int main() { stack<char> s; string s1; cin >> s1; int l = s1.length(), i, j, k; char c[l]; c[l - 1] = s1[l - 1]; for (i = l - 2; i >= 0; i--) { c[i] = min(s1[i], c[i + 1]); } for (i = 0; i < l; i++) { while (!s.empty() && c[i] >= s.top()) { c...
9
#include <bits/stdc++.h> const double pi = 4.0 * atan(1.0); const double e = exp(1.0); using namespace std; int g[1100][1100]; bool vis[1100]; int n, a, b; void dfs(int x) { for (int i = 1; i <= n; i++) { if (!vis[i] && g[x][i]) { vis[i] = 1; dfs(i); } } } int main() { ios::sync_with_stdio(fal...
9
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); ; long long t; cin >> t; while (t--) { long long n, i, ans = 0, p = 0, q = -10000000000; cin >> n; long long a[n]; i = 1; cin >> a[0]; if (a[0] > 0) { p = a[0]; ...
4