solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; const ld eps = 1e-10; template <class U, class V> ostream& operator<<(ostream& out, const pair<U, V>& p) { return out << "(" << p.first << ", " << p.second << ")"; } template <size_t i, class T> ostream& print_tuple_utils(ostr...
19
#include <bits/stdc++.h> using namespace std; const int N = 525000; long long atg[N], mtg[N]; int sz[N], s[N]; void pushup(int k) { s[k] = (s[k * 2] + s[k * 2 + 1]) % 998244353; } void chg(int k, long long v1, long long v2) { s[k] = (s[k] * v1 + sz[k] * v2) % 998244353; mtg[k] = mtg[k] * v1 % 998244353; atg[k] = ...
17
#include <bits/stdc++.h> using namespace std; int prime[1000005]; int sum[1000005]; int a, b, k; void init() { memset(prime, 0, sizeof(prime)); prime[0] = 1; prime[1] = 1; for (int i = 2; i <= 1000000; i++) { if (!prime[i]) { for (int j = i + i; j <= 1000000; j += i) { prime[j] = 1; } ...
8
#include <bits/stdc++.h> using namespace std; int N, M; int main() { int i, j, k; double res; scanf("%d%d", &N, &M); res = 1.0 / N; if (N * M > 1) res += (1 - 1.0 / N) / (N * M - 1) * (M - 1); printf("%.10f\n", res); return 0; }
13
#include <bits/stdc++.h> using namespace std; int n, i, len, a[100010], cnt, j, flag, Ans, k, tmp; char ans[100010]; int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } int main() { scanf("%d", &n); for (i = 1; i <= n; i++) { scanf("%d", &a[i]); len = len + a[i]; if (a[i] & 1) cnt+...
17
#include <bits/stdc++.h> using namespace std; int g[5005][5005] = {}; int used[5005][5005] = {}; vector<int> edges[5005]; int parents[5005] = {}; int visited[5005] = {}; void buildTree(int cur) { if (visited[cur]) return; visited[cur] = 1; for (int i = 0; i < edges[cur].size(); i++) { int s = edges[cur][i]; ...
12
#include <bits/stdc++.h> using namespace std; int n, k, m; int trans[28][28]; string s, s1, s2; int dp[110][28][110]; bool avi[110][28][110]; int main() { cin >> s; n = s.length(); cin >> k; cin >> m; for (int i = 0; i < m; i++) { int c; cin >> s1 >> s2 >> c; trans[s1[0] - 'a'][s2[0] - 'a'] = c; ...
10
#include <bits/stdc++.h> using namespace std; template <class T> bool setmax(T &_a, T _b) { if (_b > _a) { _a = _b; return true; } return false; } template <class T> bool setmin(T &_a, T _b) { if (_b < _a) { _a = _b; return true; } return false; } template <class T> T gcd(T _a, T _b) { ret...
11
#include <bits/stdc++.h> using namespace std; struct st { int x, y; } s[110]; int cmp(st i, st j) { return i.x > j.x; } int a[110], c1[5005], c2[5005]; int main() { int n, i, j, m, k; while (scanf("%d%d", &n, &m) != EOF) { int x; memset(a, 0, sizeof(a)); for (i = 1; i <= n; i++) { scanf("%d", &x...
10
#include <bits/stdc++.h> using namespace std; namespace FastIO { struct Reader { private: FILE* file; std::vector<char> buffer; int pos; bool was; void read() { if (!buffer.empty()) { buffer.resize(fread(&buffer[0], 1, (int)buffer.size(), file)); pos = 0; } } public: Reader(FILE* fi...
8
#include <bits/stdc++.h> using namespace std; const int mod = 998244353; int power[1000010], a[1000010]; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); power[0] = 1; for (int i = 1; i < 1000010; ++i) power[i] = power[i - 1] * 2 % mod; int n, ans = 0; cin >> n; for (int i = 1; i <= n; ++i) cin...
12
#include <bits/stdc++.h> using namespace std; char st[400005]; int pos[400005], ans[400005]; void solve() { int i, j, k; for (i = j = 0; st[i]; i++) if (st[i] == '.') pos[j++] = i; if (j == 0 || pos[0] > 8 || st[i - 1] == '.' || st[0] == '.') { cout << "NO" << endl; return; } pos[j] = i; k = 0; ...
6
#include <bits/stdc++.h> using namespace std; using ll = long long; template <class t, class u> void chmax(t& first, u second) { if (first < second) first = second; } template <class t, class u> void chmin(t& first, u second) { if (second < first) first = second; } template <class t> using vc = vector<t>; template ...
25
#include <bits/stdc++.h> using namespace std; int main() { int a, m; cin >> a >> m; int i = 0; while (i >= 0) { if (a % m == 0) { cout << "Yes"; break; } else if ((a + (a % m)) % m == 0) { cout << "Yes"; break; } else if (a < m) { a += a % m; } else if (a > m) { ...
6
#include <bits/stdc++.h> using namespace std; const int INF = 10000000000; const int Max = 100 * 1000 + 7; vector<pair<long long, long long> > g[Max]; long long vis[Max]; long long ind[Max]; long long d[Max]; long long n, m, k; int main() { cin >> n >> m >> k; for (int i = 0; i < m; i++) { int x, y, c; cin ...
12
#include <bits/stdc++.h> using namespace std; string s; int nra, nrb, nrc; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin >> s; for (int i = 0; i < s.size(); ++i) { if (s[i] == 'a') ++nra; if (s[i] == 'b') ++nrb; if (s[i] == 'c') ++nrc; if (i >= 1 && s[i] < s...
4
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const int mod = 1e9 + 7; const double eps = 1e-8; struct Edge { int v, next; } eg[1000000]; int head[500000]; int ans[500000]; int tp, fuc, n; int sub[500000], submx[500000]; void Add(int u, int v) { eg[tp].v = v; eg[tp].next = head[u]; h...
15
#include <bits/stdc++.h> #pragma GCC optimize(2) #pragma GCC optimize(3, "Ofast", "inline") using namespace std; const long long mod = 1e9 + 7; const long long M = 1e8 + 5; const long long N = 6e5 + 5; long long n, a[N], flag; map<long long, long long> v; inline void dfs(long long x, long long sum) { if (x == n + 1) ...
10
#include <bits/stdc++.h> using namespace std; map<int, vector<int> > x; int ans = 0; int get(int row, bool upper) { map<int, vector<int> >::iterator it = x.find(row); if (it == x.end()) return upper ? -1 : 1 << 30; return upper ? it->second.back() : it->second.front(); } int main() { int n, m; cin >> n >> m; ...
7
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e2; int n, a[MAXN], maxx, summ; int main() { cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; maxx = max(a[i], maxx); } for (int i = 0; i < n; i++) summ += maxx - a[i]; cout << summ; }
0
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; if (n <= 2) cout << -1 << endl; else { for (int i = n; i > 0; i--) { if (i != n) cout << " "; cout << i; } cout << endl; } return 0; }
1
#include <bits/stdc++.h> using namespace std; int A[50001]; void solve() { long long a, b; cin >> a >> b; if (a < b) swap(a, b); if (a >= b) { if (a % b != 0) { cout << -1; return; } else { long long y = a / b; int x = 0; long long t = 1; while (true) { if (t ...
2
#include <bits/stdc++.h> using namespace std; template <class T> inline void read(T& arr) { for (long long i = 0; i < arr.size(); ++i) cin >> arr[i]; } inline void solve() { long long n; cin >> n; vector<string> v(n); read(v); int ans = 6; vector<set<string> > st(7); for (int i = 0; i < 64; ++i) { s...
6
#include <bits/stdc++.h> using namespace std; const int maxn = 100005, maxm = 4; int n, stk[maxn], top, a[maxn], b[maxn]; double P[maxn], lim[maxn], M; long long t; struct line { double k, b; int id; bool operator<(const line &p) const { if (fabs(k - p.k) > 1e-12) return k < p.k; return b > p.b; } } l[m...
23
#include <bits/stdc++.h> using namespace std; int main() { int n, a, d; cin >> n >> a >> d; vector<int> t; vector<int> v; vector<int> ans; int temp; for (int i = 0; i < n; ++i) { cin >> temp; t.push_back(temp); cin >> temp; v.push_back(temp); } double cur = 0; double tp = 0; double...
8
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f, oo = inf; inline long long read() { register long long x = 0; char f = 0; register char c = getchar(); for (; !isdigit(c); c = getchar()) f |= (c == '-'); for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48); return f ...
20
#include <bits/stdc++.h> using namespace std; void solve() { long long n; int m; cin >> n >> m; int arr[60] = {0}; long long sum = 0; long long a; for (int i = 0; i < m; i++) { cin >> a; sum += a; arr[(int)log2(a)]++; } if (sum < n) { cout << -1 << '\n'; return; } int prev = 0;...
11
#include <bits/stdc++.h> #pragma GCC optimize("O3") #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") using namespace std; namespace debug { template <class c> struct rge { c b, e; }; template <class c> rge<c> range(c i, c ...
16
#include <bits/stdc++.h> using namespace std; const int MN = 1100; const int MM = 2100000; int n, m, nb, nw; vector<int> l[MM], l2[MM]; int vz[MM]; int td[MM][2]; int ind[MM]; char jd[MN][MN]; char C[MN][MN]; int ed[10000000][2]; int que[MM]; int ef; int Con; int mk[4]; int mark[MM]; int dfs(int x) { mark[x] = 1; f...
12
#include<iostream> #include<vector> #include<algorithm> #include<set> #include<map> #include<queue> #include<cmath> #include<iomanip> #include<cstring> #include<complex> #include<cstdio> #define initdp(a,b) for(int i=0;i<=a;i++)for(int j=0;j<=b;j++)dp[i][j]=-1; #define fi first #define se second #define pb push_back #d...
17
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; const long long LINF = 2e16; const int INF = 2e9; const int magic = 348; const double eps = 1e-10; const double pi = 3.14159265; inline int getint() { char ch; int res; bool f; while (!isdigit(ch = getchar()) && ch != '-') { } if (ch == ...
19
#include <bits/stdc++.h> using namespace std; int main() { int a, b, f, k, x, t = 0, y = 0; cin >> a >> b >> f >> k; if (b < f || b < (a - f)) { cout << "-1"; return 0; } if (k == 2 && b < 2 * (a - f)) { cout << "-1"; return 0; } if (k > 2 && (b < 2 * (a - f) || b < 2 * f)) { cout << "...
7
#include <bits/stdc++.h> typedef long long ll; typedef long double ld; typedef unsigned long long ull; #define fi first #define se second #define pb push_back #define pii pair<int,int> #define endl "\n" #define scd(a) scanf("%d",&a) #define scdd(a,b) scanf("%d%d",&a,&b) #define scddd(a,b,c) scanf("%d%d%d",&a,&b,&c) con...
5
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; vector<int> v(m); for (int i = 0; i < m; i++) cin >> v[i]; long long ret = 0; int cur = 1; for (int i = 0; i < m; i++) { if (v[i] >= cur) ret += (v[i] - cur); else ret += (n - cur + v[i]); cur = v[i...
2
#include <bits/stdc++.h> const int N = 45, L = 200005; using namespace std; bool c[N][N], msk[L], ill[(1 << 20) + 5], ill1[(1 << 20) + 5]; int type[L], ks[L]; int f1[(1 << 20) + 5], f2[(1 << 20) + 5]; int n, m; template <typename T> inline void in(T &x) { register char ch; x = 0; while (isspace(ch = getchar())) ...
14
#include<bits/stdc++.h> using namespace std; #define dbg(x) cerr << #x << " = " << x << endl #define rep(i, a, b) for(int i = (a); i <= (b); ++ i) #define MP make_pair #define pb push_back #define int long long template <typename Tp> void read(Tp &x){ x = 0; int op = 1; char ch = getchar(); while(!isdigit(ch)){ if(c...
8
#include <bits/stdc++.h> using namespace std; const int maxn = 105; vector<int> G1[maxn]; int n, m, a, b, q, mp[maxn][maxn], must[maxn][maxn]; int dist[maxn], vis[maxn], p[maxn], fb[maxn], tb[maxn], dp[maxn], Md[maxn]; struct Heap { int u, d; Heap(int _u = 0, int _d = 0) { u = _u; d = _d; } bool operato...
18
#include <bits/stdc++.h> using namespace std; inline long long rd() { char ch = getchar(); long long ret = 0, sgn = 1; while (ch < '0' || ch > '9') { if (ch == '-') sgn = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') ret = ret * 10 + ch - '0', ch = getchar(); return ret * sgn; } inline void o...
18
#include <bits/stdc++.h> using namespace std; string s; int main() { cin >> s; int ans = 0, cnt = 0; for (int i = 0; i < s.size(); i++) { cnt++; if (s[i] == 'A' || s[i] == 'E' || s[i] == 'I' || s[i] == 'O' || s[i] == 'U' || s[i] == 'Y') { ans = max(ans, cnt); cnt = 0; } } ans =...
2
#include <bits/stdc++.h> using namespace std; char buf[1 << 21], *p1 = buf, *p2 = buf; template <class T> void read(T &x) { x = 0; int c = getchar(); int flag = 0; while (c < '0' || c > '9') flag |= (c == '-'), c = getchar(); while (c >= '0' && c <= '9') x = (x << 3) + (x << 1) + (c ^ 48), c = getchar(); ...
23
/* For you, who has never forgotten the magic. It wants you to know it remembers you too.*/ /*J. M. D. */ #include <bits/stdc++.h> using namespace std; #define int long long #define pll pair<int,int> #define ppll ...
6
#include <bits/stdc++.h> using namespace std; int32_t main() { long long int n; cin >> n; long long int a[n]; for (long long int i = 0; i < n; i++) { cin >> a[i]; } vector<long long int> v; for (long long int i = 0; i < n - 1; i++) { for (long long int j = i + 1; j < n; j++) { v.push_back(a[...
4
#include <bits/stdc++.h> using namespace std; int main() { long long c, w1, w2, h1, h2, value = 0; cin >> c >> h1 >> h2 >> w1 >> w2; for (long long i = 0; i < 100000; i++) { if (i * w1 <= c) value = max(value, i * h1 + (c - i * w1) / w2 * h2); if (i * w2 <= c) value = max(value, i * h2 + (c - i * w2) / w1...
12
#include <bits/stdc++.h> using namespace std; int main() { int a, b, f, k; while (cin >> a >> b >> f >> k) { int pos = 0, des = f, last = 0, cnt = 0, g = b; while (k > 0) { if (pos == 0 || pos == a) des = f; else if (pos == f) { des = (last == 0) ? a : 0; last = (last == ...
7
#include <bits/stdc++.h> using namespace std; const int N = 3010; int dp[N << 1], x[N << 1], n, m, t; struct Node { int l, r, w; } a[N]; bool cmp(Node &a, Node &b) { if (a.r != b.r) return a.r < b.r; else return a.r - a.l < b.r - b.l; } int main() { scanf("%d", &t); while (t--) { scanf("%d", &n); ...
15
#include <bits/stdc++.h> using namespace std; struct hh { int x, y, p; bool operator<(hh a) const { if (x == a.x) { if (y == a.y) return p < a.p; return y < a.y; } return x < a.x; } }; int x[100005][2], y[100005][2]; set<hh> s[4]; bool dfs(set<hh> a[4]) { if (a[0].size() <= 1) return 1; ...
17
#include <bits/stdc++.h> using namespace std; int n, m; int a[100000]; int b[100000]; vector<pair<int, int> > v; vector<pair<int, int> > ans; int main() { cin >> n >> m; for (int i = 0; i < n; i++) { cin >> a[i]; b[a[i]]++; } for (int i = 0; i < n; i++) { v.push_back(make_pair(b[a[i]], a[i])); } ...
10
#include <bits/stdc++.h> #pragma GCC optimize("O2") #pragma GCC optimize("O3") #pragma GCC optimize("Ofast") #pragma GCC optimize("inline") #pragma GCC optimize("-fgcse") #pragma GCC optimize("-fgcse-lm") #pragma GCC optimize("-fipa-sra") #pragma GCC optimize("-ftree-pre") #pragma GCC optimize("-ftree-vrp") #pragma GCC...
16
#include <bits/stdc++.h> using namespace std; const int N = 101110; int p[N]; bool fre[N]; vector<int> a[N]; int n, k; void NIE() { puts("NO"); exit(0); } void visit(int u) { a[k].push_back(u); fre[u] = false; if (fre[p[u]]) visit(p[u]); } void print(int u) { puts("YES"); for (int i = 1; i <= n; i++) ...
13
#include <bits/stdc++.h> using namespace std; int main() { int a1, a2, a3; cin >> a1 >> a2 >> a3; int l, w, h; w = sqrt((a3 * a1) / a2); h = (w * a2) / a1; l = a1 / w; cout << 4 * w + 4 * l + 4 * h; return 0; }
3
#include <bits/stdc++.h> using namespace std; template <typename T> inline T abs(T a) { return ((a < 0) ? -a : a); } template <typename T> inline T sqr(T a) { return a * a; } void solve1() { long long n, t; cin >> n; long long sum = 0; for (long long i = (long long)0; i < (long long)(n); i++) { cin >> t...
5
#include <bits/stdc++.h> using namespace std; const int maxn = (1 << 22) + 5; bool col[maxn]; int n, m, a[maxn], b[maxn]; int bu(int x) { return ((1 << n) - 1) ^ x; } void gao(int u) { if (col[u]) return; col[u] = 1; for (int i = 0; i < n; i++) { if (u & (1 << i)) { gao(u ^ (1 << i)); } } if (b[...
17
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7, inv2 = (mod + 1) / 2, mod2 = 1e9 + 9; vector<pair<int, int> > e[111111]; int isused[111111]; int fa[111111], fae[111111]; pair<int, int> operator+(const pair<int, int> &a, const pair<int, int> &b) { return {(a.first + b.first) % mod, (a.second + b...
16
#include <iostream> #include <cstdio> #include <map> using namespace std; const int N = 100005; int n = 0, m = 0; int a[N], u[N], v[N]; map<int, bool> vis; void Sol(int l, int r) { int Mn = 1e9, Mx = -1e9; long long s = 0; for (int i = l; i <= r; i++){ s += a[i]; Mn = min(Mn, a[i]); Mx = max(Mx, a[i]); }...
8
#include <bits/stdc++.h> using namespace std; void sol() { long long int b; cin >> b; if (b == 1) { cout << 1 << endl; return; } long long int ans = 0; long long int i; for (i = 1; i * i < b; i++) { if (b % i == 0) { ans++; } } if (i * i == b) { cout << 2 * ans + 1 << endl; ...
4
#include <bits/stdc++.h> using namespace std; static const double EPS = 1e-10; struct Point { double x; double y; double z; }; double getDist(Point a, Point b) { double dx = fabs(a.x - b.x); double dy = fabs(a.y - b.y); double dz = fabs(a.z - b.z); return sqrt(dx * dx + dy * dy + dz * dz); } double getDti...
13
#include <bits/stdc++.h> using namespace std; long long n, b[200005]; vector<long long> z[3], g, al, res, tmp, h[62]; map<long long, long long> ok; vector<long long> tinh(vector<long long> vec) { vector<long long> ans; for (auto u : vec) ok[u] = 1; for (auto u : vec) { long long dem = 0; long long nho = u...
11
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { int t; scanf("%d", &t); while (t--) { ll n, m, k; scanf("%lld%lld%lld", &n , &m, &k); ll line = (k % n) == 0? n : k % n; ll col = (k + n - 1) / n; printf("%lld\n", m * (line - 1) + col); } return 0; }
0
#include <bits/stdc++.h> using namespace std; const int N = 222222; const int INF = INT_MAX / 2; int n, m; set<int> bTree[N]; vector<int> v; int tree[N * 4]; pair<string, pair<int, int> > q[N]; char buf[N]; void modify(int k, int s, int t, int p, int first) { if (s == t) { tree[k] = first; return; } int m...
20
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; int n = 0; char c = 'a'; string res; while (n < N) { int i = 1; while (i * (i - 1) / 2 + n <= N) ++i; --i; n += i * (i - 1) / 2; for (int l = 0; l < i; ++l) res += c; c++; } if (res.empty()) cout << "...
8
#include <bits/stdc++.h> using namespace std; bool c[500][500]; int s[505]; int main() { int i, a, b, n, m; cin >> n >> m; memset(c, false, sizeof(c)); memset(s, -1, sizeof s); for (i = 0; i < n; ++i) c[i][i] = true; while (m--) { cin >> a >> b; --a; --b; c[a][b] = c[b][a] = true; } for ...
10
#include <bits/stdc++.h> using namespace std; const long long int mod = 1e9 + 7; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long int n, m; cin >> m >> n; vector<string> v(n); for (long long int i = 0; i < n; i++) cin >> v[i]; vector<string> ans(m, ""); for (long long int ...
4
#include <bits/stdc++.h> using namespace std; int parent[55]; int findSet(int u) { while (u != parent[u]) { u = parent[u]; } return u; } void unionSet(int u, int v, long long &res) { int up = findSet(u); int vp = findSet(v); if (up != vp) { parent[vp] = up; res *= 2; } } int main() { int n, ...
6
#include <bits/stdc++.h> using namespace std; int t, n, k; string s; int memo[1000005][2], cant[1000005]; int dp(int pos, int f) { if (pos >= n) return 0; int &ret = memo[pos][f]; if (ret != -1) return ret; int res = 0; if (f == 0) { if (s[pos] == '1') res = min((pos + k > n ? cant[n] : ca...
11
#include <bits/stdc++.h> using namespace std; int main() { int n1, n2, k1, k2; cin >> n1 >> n2 >> k1 >> k2; if (n1 <= n2) cout << "Second"; else cout << "First"; }
0
#include <bits/stdc++.h> using namespace std; const int base = 100003; const int maxn = 1000005; int n, m, a[maxn], cnt[maxn], Block; long long ans[maxn], res; struct data { int l, r, id; } b[maxn]; vector<int> v; bool comp(data a, data b) { if (a.l / Block != b.l / Block) return a.l / Block < b.l / Block; return...
14
#include <bits/stdc++.h> using namespace std; int main() { int n; int a[55][55]; scanf("%d", &n); for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { scanf("%d", &a[i][j]); } } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (a[i][j] != 1) { int flag = ...
0
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const int inf = 1e9; long long powm(long long a, long long p, long long m) { long long r = 1 % m; while (p) { if (p & 1) r = r * a % m; p >>= 1; a = a * a % m; } return r; } struct Node { int x, y, i; }; Node ps[1000000]; bool ...
13
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); int t; cin >> t; while (t--) { int n, c0, c1, h; cin >> n >> c0 >> c1 >> h; string s; cin >> s; int ans = 0; if (c0 + h <= c1) { for (int i = 0; i < n; i++) { if (s[i] == '0') { ...
0
#include <bits/stdc++.h> using namespace std; bool ya = false; char F[100005]; int A[100005], ctos; long long R[100005][5], a, b, men, may, lleva = 0; void busca(int dnde) { if (dnde == 0) { if (lleva >= 0 and lleva <= A[1]) { for (int i = 1; i <= ctos; i++) { printf("%c", F[i]); } print...
11
#include <bits/stdc++.h> using namespace std; template <typename T, typename U> ostream& operator<<(ostream& os, const pair<T, U>& p) { os << "(" << p.first << "," << p.second << ")"; return os; } template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) { os << "["; for (__typeof((v).begin()) ...
12
#include <bits/stdc++.h> using namespace std; int n, a[200009]; bool double_compare(int a, double b) { double tmp = (b + (1e-7)) * 1000000.0; long long tmp2 = tmp, tmp3 = (long long)a * 1000000; return tmp3 > tmp2; } bool valid(double d) { double pos = (double)(a[0]) + d; int num = 1; for (int i = 1; i < n;...
10
#include <bits/stdc++.h> using namespace std; const int maxn = 1111111; const int INF = 0x7f7f7f7f; const int mod = 12345678; const double pi = acos(-1.0); char s[maxn]; char ss[8] = {"1689"}; int c[15]; int ans[maxn]; int main() { int cnt = 0; ss[4] = 0; scanf("%s", s); int len = strlen(s); int M[10] = {1869...
8
#include <bits/stdc++.h> using namespace std; const long long mod = (long long)1e9 + 7; template <class L, class R> ostream &operator<<(ostream &os, pair<L, R> P) { return os << "(" << P.first << "," << P.second << ")"; } template <class T> ostream &operator<<(ostream &os, vector<T> V) { os << "["; for (auto vv :...
10
#include <bits/stdc++.h> using namespace std; stack<int> q; set<int> s; pair<int, int> a[200020]; size_t _, n, ans; int main() { for (scanf("%ld", &_); _--; ans = 0, s.clear()) { scanf("%ld", &n); for (int i = 0; i < n; i++) a[i].second = -i, scanf("%d", &a[i].first); sort(a, a + n); for (int i = 0, j...
13
#include <bits/stdc++.h> using namespace std; template <typename T> inline bool inrange(T a, T l, T r) { if (l > r) swap(l, r); return (a >= l and a <= r); } template <typename T, typename U> inline bool exist(T val, U &any) { return (any.find(val) != any.end()); } template <typename T> inline void inp(T &any) { ...
6
#include <bits/stdc++.h> using namespace std; int main() { long long int n, k; cin >> n >> k; long long int type = 1; long long int MAX = 0; long long int nbrBox = 0; for (int i = 1; i <= k; i++) { long long int a; cin >> a; long long int q = n / a; if ((q * a) > MAX) { type = i; ...
2
#include <bits/stdc++.h> using namespace std; short n, m, i, j; int answer, t; char matrix[5002][5002]; short c[5002], cnt[5002]; int& max(int& x, int& y) { if (x > y) { return x; } return y; } int main() { cin >> n >> m; for (i = 0; i < n; ++i) { cin >> matrix[i]; } for (j = 0; j < m; ++j) { ...
8
#include <bits/stdc++.h> using namespace std; long long int fast_expo(long long int x, long long int p) { if (p == 0) return 1; else if (p % 2 == 0) { long long int t = fast_expo(x, p / 2) % 1000000007; return (t * t) % 1000000007; } else return (x * (fast_expo(x, p - 1)) % 1000000007) % 100000000...
8
#include <bits/stdc++.h> using namespace std; long long n, i = 0, a[100005], x, y = 0, z = 0, cnt = 0; string str; int main(void) { cin >> n >> str; for (i = 0; i < n; i++) { a[i] = str[i] - '0'; if (a[i] == 8) cnt++; } x = (n - 11) / 2; if (cnt < x + 1) return cout << "NO", 0; for (i = 0; i < n && ...
4
#include <bits/stdc++.h> const long long inf = 0x3f3f3f3f3f3f3f3f; using std::max; using std::min; inline long long readll(void) { long long x = 0, w = 1; char ch = getchar(); for (; ch < '0' || ch > '9'; ch - '-' || (w = -w), ch = getchar()) ; for (; ch >= '0' && ch <= '9'; x = (x << 1) + (x << 3) +...
7
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const int maxn = 1e5 + 10; const int MOD = 1e9 + 7; const double pi = acos(-1); char a[maxn]; int main() { scanf("%s", a); int len = strlen(a); int flag = -1; int cnt = 0; for (int i = 0; i < len; i++) { if (a[i] == '1') cnt++; ...
6
#include <bits/stdc++.h> using namespace std; int n, c, a[200005], b[200005]; long long dp[200005][3]; int main() { cin >> n >> c; for (int i = 1; i <= n - 1; i++) cin >> a[i]; for (int i = 1; i <= n - 1; i++) cin >> b[i]; dp[1][1] = c; for (int i = 2; i <= n; i++) { dp[i][0] = min(dp[i - 1][0], dp[i - 1]...
9
#include <bits/stdc++.h> using namespace std; const int nax = 1e6 + 6; bool check[nax] = {0}; int main() { long long n, d, m, l; cin >> n >> d >> m >> l; long long res = 0, cnt = 0; check[0] = true; while (res % m <= l && res / m < n) { res += d; if (!check[res % m]) check[res % m] = true; e...
9
#include <bits/stdc++.h> using LL = long long; using ULL = unsigned long long; int main() { using namespace std; ULL n = 0; cin >> n; vector<ULL> numbers; while (n--) { ULL number = 0; cin >> number; numbers.push_back(number); } sort(numbers.begin(), numbers.end()); vector<ULL> sums; sums....
7
#include <bits/stdc++.h> using namespace std; long long mod = 10000000000; long long gcd(long long a, long long b) { if (b == 0) return a; else return gcd(b, a % b); } long long fastexp(long long x, long long n) { long long result = 1; while (n > 0) { if (n % 2 == 1) result *= x; x *= x; n =...
12
#include <bits/stdc++.h> using namespace std; const int mt = 100000 + 5; vector<int> g[mt]; int pre[mt]; int fa[mt]; int in[mt], out[mt]; int _clock = 0; inline int read() { int num = 0, flag = 1; char ch; do { ch = getchar(); if (ch == '-') flag = -1; } while (ch < '0' || ch > '9'); do { num = nu...
19
#include <bits/stdc++.h> using namespace std; int f[100005], v[100005]; int getf(int n) { if (f[n] == n) return n; f[n] = getf(f[n]); return f[n]; } int main() { int n, m, i, a, b, fa, fb; scanf("%d%d", &n, &m); for (i = 1; i <= n; i++) { scanf("%d", &v[i]); f[i] = i; } while (m--) { scanf("...
5
#include <bits/stdc++.h> using namespace std; template <class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; } template <class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; } template <class T> void inp(T& x) { cin >> x; } template <class H, class... T> void inp(H& h, T&... t) { ...
0
#include <bits/stdc++.h> using namespace std; const int oo = 0x3f3f3f3f; const double eps = 1e-9; int M, N; int dp[51][1 << 12]; int main() { cin >> N >> M; if (N > M) swap(N, M); memset(dp, oo, sizeof(dp)); dp[0][0] = 0; for (int i = (0); i < (M); i++) { for (int j = (0); j < (1 << (2 * N)); j++) { ...
13
#include <bits/stdc++.h> using namespace std; const int maxn = 1e3; const int INF = 0x3f3f3f3f; long long a[maxn], vis[maxn]; int main() { int n; cin >> n; int x = 0, y = 0, z = 0; for (int i = 1; i <= n; i++) { cin >> a[i]; if (a[i] < 0) x++; if (a[i] > 0) y++; if (!a[i]) z++; } sort(a + 1,...
6
#include <bits/stdc++.h> using namespace std; namespace mincost { const int V = 1000, E = 1000000, inf = 1e9; int dis[V], q[V * 300], vis[V], fst[V], pre[V], nxt[E], second[E], f[E], c[E], S, T, flow, cost, tot, tn; void init(int s, int t, int Tn) { tot = 1; tn = Tn; for (int(i) = (0); (i) < (tn); (i)++) fst[...
14
#include <bits/stdc++.h> using namespace std; int ar[200005][3]; char ch[200005]; int n, m, ii, k; long long cnt[200005], cnt1[200005]; void solve() { scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d%d", &ar[i][1], &ar[i][2]); cnt[ar[i][1]]++; cnt1[ar[i][2]]++; } long long re = (long long)n...
9
#include <bits/stdc++.h> using namespace std; int main() { int n; string a; cin >> n; string names[n]; int init = 0; while (init < n) { cin >> a; names[init] = a; init++; } init = 0; while (init < n) { if (names[init].length() > 10) { int b = names[init].length() - 2; cout ...
0
#include <bits/stdc++.h> using namespace std; void err(istream_iterator<string> it) {} template <typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cerr << *it << " = " << a << endl; err(++it, args...); } const int MAXN = 1e6 + 10; vector<int> right_seg[MAXN]; vector<pair<int, ...
14
#include <bits/stdc++.h> using namespace std; int t, n, k; char mp[3][110]; bool f[110][3]; int main() { scanf("%d", &t); while (t--) { memset(f, 0, sizeof(f)); scanf("%d%d", &n, &k); for (int i = 0; i < 3; i++) { scanf("%s", mp[i]); if (mp[i][0] == 's') f[0][i] = 1; } for (int i = 1...
9
#include <bits/stdc++.h> using namespace std; map<long long, int> cnto, cntu; int main() { int omote[100005], ura[100005], n; memset(omote, 0, sizeof(omote)); memset(ura, 0, sizeof(ura)); cin >> n; for (int i = 0; i < n; i++) { cin >> omote[i] >> ura[i]; cnto[omote[i]]++; if (omote[i] != ura[i]) c...
7
#include <bits/stdc++.h> using namespace std; long long a, b; int main() { long long i, ans = 1; scanf("%lld %lld", &a, &b); if (a == b) { printf("1\n"); return 0; } long long mb = b % 10; if (b - a == 4) { if (mb == 9 || mb == 4) printf("4\n"); else printf("0\n"); } else if (b...
3
#include <bits/stdc++.h> using namespace std; const int maxn = 500005, mod = 998244353, inv2 = (mod + 1) / 2; int n, pw, ans; int f[maxn]; vector<int> v[maxn]; void dfs(int x, int last) { f[x] = 1; for (int i = 0; i < v[x].size(); i++) { int y = v[x][i]; if (y == last) continue; dfs(y, x); f[x] = 1l...
20
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; int k; cin >> k; int n = 26; int w[n + 1]; for (int i = 1; i <= n; i++) { cin >> w[i]; } int max = *max_element(w + 1, w + n + 1); int l = s.length(); map<char, int> mp; map<char, int>::iterator it; for (int i =...
2