solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> using namespace std; const int maxn = 3e5 + 10; int a[maxn], b[maxn]; int main() { int n, m; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", &a[i]); } scanf("%d", &m); for (int i = 0; i < m; i++) { scanf("%d", &b[i]); } int l = 0, r = 0, cnt = 0; long long s...
8
#include <bits/stdc++.h> struct edge_t { struct edge_t *next; int v; }; struct edge_t *e[100005], e_pool[100005 * 2], *ep_top = e_pool; int deg[100005]; void add_edge(int u, int v) { deg[u]++, deg[v]++; ep_top->v = v; ep_top->next = e[u]; e[u] = ep_top++; ep_top->v = u; ep_top->next = e[v]; e[v] = ep_...
18
#include <bits/stdc++.h> using namespace std; int main() { unsigned long long n; cin >> n; unsigned long long l = 1000000001, r = 0; long long pos = -1, flag = 0; for (unsigned long long i = 1, x, y; i <= n; i++) { cin >> x >> y; if (x <= l and r <= y) { pos = i; l = x; r = y; } ...
3
#include <bits/stdc++.h> using namespace std; long long n, m, pos = 1, ans; int main() { cin >> n >> m; for (long long i = 1, x; i <= m; ++i) { cin >> x; if (x < pos) { ans += n - pos + x; } else { ans += x - pos; } pos = x; } cout << ans; return 0; }
2
#include <bits/stdc++.h> using namespace std; struct ww { double x, y, z; inline double bei() const { return x * x + y * y; } inline ww operator-(const ww &A) { return (ww){x - A.x, y - A.y, 0}; } inline double operator*(const ww &A) { return x * A.y - y * A.x; } } a[100010], O; struct w { double a; int id;...
22
#include <bits/stdc++.h> using namespace std; bool mark[4000000 + 10]; int n, m; int get(int x, int y) { if (x < 1 || x > n || y < 1 || y > m) return 0; if (x == 1) return y; if (x == n) return m + 2 * n - 4 + y; return m + 2 * (x - 1) - (y == 1); } void dfs(int v) { if (mark[v]) return; mark[v] = true; i...
13
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; long long an = 1; for (long long i = 2; i <= sqrt(n); i++) { long long c = 0; while (n % i == 0) { c++; n /= i; } if (c) an *= i; } if (n >= 2) an *= n; cout << an << endl; return 0; }
5
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:32000000") using namespace std; const double pi = 3.1415926535897932384626433832795; template <class T> inline T Sqr(const T &x) { return x * x; } template <class T> inline T Abs(const T &x) { return x >= 0 ? x : -x; } long long res; int l, r; void test(long ...
8
#include <bits/stdc++.h> using namespace std; int main() { int a1, a2, a3, a4; cin >> a1 >> a2 >> a3 >> a4; int s[a1 + a2]; for (int i = 0; i < a1 + a2; i++) s[i] = 0; if ((a3 > a4) || (a3 == a4 && a1 > a3)) { s[0] = 4; a1--; int i = 1; while (a3 != 0 || a4 != 0) { if (a3 != 0 && s[i - 1...
10
#include <bits/stdc++.h> #pragma GCC optimize "03" using namespace std; const long long int N = 1e5 + 5; const long long int B = 44; const long long int mod = 1e9 + 7; const long long int inf = 1e9 + 9; struct trie { long long int z, o, v; } t[40 * N]; long long int a[N], c = 1; void merge(long long int nd) { long ...
14
#include<bits/stdc++.h> #define endl "\n" using ll = long long; using namespace std; ll arr[103]; ll ans[103]; void recurse_fill(ll l, ll r, ll d){ if(l > r){ return; } ll posm, mx; mx = -1; for(ll i = l; i <= r; ++i){ if(arr[i] > mx){ mx = arr[i]; posm = ...
4
#include<cstdio> #include<cstring> #include<algorithm> using namespace std; #define ll long long int #define mod 998244353 inline int sum(int a,int b){return a+b<mod?a+b:a+b-mod;} inline int mul(int a,int b){return (int)((ll)a*b%mod);} inline int pow(int a,int b) { int res=1; while(b>0){ if(b&1) res=mul(res,a); a...
22
#include <bits/stdc++.h> using namespace std; long long find_1(vector<long long> A) { for (long long i = 0; i < A.size(); i++) { if (A[i] == 1) { return i; } } assert(false); return -1; } int main() { long long n; cin >> n; vector<long long> A(n, 0); for (long long i = 0; i < n; i++) { ...
5
#include <bits/stdc++.h> using namespace std; struct SegmentTree { SegmentTree *left, *right; int a, b; long long sum; bool lazy; SegmentTree(int a, int b) : left(NULL), right(NULL), a(a), b(b), sum(0), lazy(false) {} }; void flip(SegmentTree *tree) { if (tree == NULL) return; tree->sum = tree->b - ...
12
#include <bits/stdc++.h> using namespace std; long long nikita = 1000000007; long long bin_pow(int a, int m) { if (m == 1) return a; long long ans = bin_pow(a, m / 2); ans = (ans * ans) % nikita; if (m % 2 == 1) { ans = ans * a; } return ans % nikita; } int main() { int n, m; cin >> n >> m; cout <...
7
#include <bits/stdc++.h> using namespace std; int main() { int n, x = 0; string str; cin >> n >> str; for (int i = 0; i < n; i++) if (str[i] == 'X') x++; if (x < n / 2) { cout << (n / 2) - x << endl; for (int i = 0; i < n; i++) { if (str[i] == 'x') str[i] = 'X', x++; if (x == n / 2) br...
1
#include <bits/stdc++.h> using namespace std; long long dp[18][(1 << 16) + 5]; int ans[20], chk[20], pos[20]; int n, m; long long k; long long Update(int p) { memset(dp, 0, sizeof(dp)); dp[1][0] = 1; memset(chk, -1, sizeof(chk)); for (int i = 1; i <= p; ++i) chk[ans[i]] = i; for (int i = 1; i <= n; ++i) { ...
16
#include <bits/stdc++.h> using namespace std; struct Point { double X, Y; Point(double x, double y) { X = x; Y = y; } }; bool doubleEqual(double lhs, double rhs) { return fabs(lhs - rhs) <= 1e-12; } double pointsEqual(Point *lhs, Point *rhs) { return doubleEqual(lhs->X, rhs->X) && doubleEqual(lhs->Y, rh...
17
#include <bits/stdc++.h> using namespace std; int c[2005]; vector<pair<int, int> > v; int main() { ios::sync_with_stdio(0); int n; while (cin >> n) { v.clear(); int aux, aux2; int h = 0; int op = 1; for (int i = 0; i < 2005; i++) c[i] = 0; for (int i = 0; i < n; ++i) { int a; c...
5
#include <bits/stdc++.h> using namespace std; int l, r, n, a[4][2], tot, ans[8], b[4]; bool pd; int Query(int r1, int c1, int r2, int c2) { int ret; printf("? %d %d %d %d\n", r1, c1, r2, c2); fflush(stdout); scanf("%d", &ret); return ret; } int main() { scanf("%d", &n); l = 1, r = n; while (l < r) { ...
14
#include <bits/stdc++.h> using namespace std; int main() { long long k, a, b; cin >> k >> a >> b; string s; cin >> s; long long n = s.size(); if (n >= k * a && n <= k * b) { long long j = 0, p, l = n - (k * a); for (int i = 0; i < k; i++) { p = min(b, a + l); l -= min(b, a + l) - a; ...
6
#include <bits/stdc++.h> using namespace std; template <typename T> void read(T &x) { x = 0; int op = 1; char c = getchar(); while (!isdigit(c)) { if (c == '-') op = -1; c = getchar(); } while (isdigit(c)) { x = (x << 1) + (x << 3) + (c ^ 48); c = getchar(); } x *= op; } inline void swap...
19
#include <bits/stdc++.h> using namespace std; int n, hi[51], vi[51], h, v; int main() { cin >> n, n *= n; for (int i = 1; i <= n; i++) { cin >> h >> v; if (!hi[h] && !vi[v]) hi[h]++, vi[v]++, cout << i << " "; } }
2
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0), cout.tie(0); int n, m; cin >> n >> m; vector<string> s(n); for (int i = 0; i < n; ++i) { cin >> s[i]; } vector<vector<int>> sum(n, vector<int>(m)); sum[0][0] = (s[0][0] == 'X'); for (int j = 1; j ...
14
#include <bits/stdc++.h> using namespace std; using ll = long long; using ss = stringstream; using ul = unsigned long long; template <typename T> inline T LCM(T a, T b) { return (a * b) / GCD(a, b); } template <typename T> inline T GCD(T a, T b) { ll t; while (a) { t = a; a = b % a; b = t; } retur...
6
#include <bits/stdc++.h> using namespace std; int n, m; vector<int> g[500010]; vector<int> bfstree[500010]; vector<int> st, ed; int p[500010]; char used[500010]; char oncycle[500010]; vector<vector<int>> cycles; int cyclenum[500010]; int l[500010], z[500010]; int an[500010]; multiset<int> ms[500010]; int fi[500010]; ve...
21
#include <bits/stdc++.h> using namespace std; long long read() { long long a = 0, b = getchar(), c = 1; while (!isdigit(b)) c = b == '-' ? -1 : 1, b = getchar(); while (isdigit(b)) a = a * 10 + b - '0', b = getchar(); return a * c; } long long d, k, a, b, t, x, y, z, ans; int main() { d = read(), k = read(), ...
11
#include <bits/stdc++.h> using namespace std; int a[100010]; int b[100010]; int n, m; int main() { scanf("%d%d", &n, &m); for (int i = 1; i <= n; ++i) { scanf("%d", &a[i]); } for (int i = 1; i <= m; ++i) { scanf("%d", &b[i]); } sort(a + 1, a + n + 1); sort(b + 1, b + m + 1); int ans = 0; for (...
7
#include <bits/stdc++.h> using namespace std; inline int read() { char c = getchar(); int x = 0; bool f = 0; for (; !isdigit(c); c = getchar()) f ^= !(c ^ 45); for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48); if (f) x = -x; return x; } int now, n, a[200005]; char str[200005]; char Rev...
18
#include <bits/stdc++.h> using namespace std; int main() { long long i, j, k, m, n, x, y, ans, cnt, d; while (scanf("%I64d%I64d%I64d%I64d", &n, &x, &m, &y) != EOF) { if (x > y) { swap(x, y); swap(n, m); } if (x == y) { printf("%d\n", max(n, m) + 1); } else { ans = 1; if...
15
#include <bits/stdc++.h> using namespace std; const int INF = 1e9 + 7; const int maxn = 1e5 + 5; int n; int a[maxn]; long long ans; vector<pair<int, int> > vec; int main() { scanf("%d", &n); for (int i = (0); i < (n); ++i) scanf("%d", a + i); if (n == 1) { if (!(a[0] & 1) || (!a[0])) puts("cslnb"); ...
10
#include <bits/stdc++.h> using namespace std; long long n, m, p, v[50100], ans = 1e15, minn; long long b[200100], bb[200100]; long long check(long long dis) { memset(v, 0, sizeof(v)); for (int i = 1, jj = 1; i <= n; i++) { if (abs(bb[jj] - p) + abs(b[i] - bb[jj]) <= dis && jj <= m) { v[i] = 1; jj++;...
10
#include <bits/stdc++.h> using namespace std; int g[100][100]; int n; int l1, r1, l2, r2; long long t[52][52]; long long t1[52][52]; bool better(const pair<int, int>& a, const pair<int, int>& b) { if (a.first != b.first) return a.first < b.first; return a.second < b.second; } long long solve(int w, int l) { for (...
16
#include <bits/stdc++.h> using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); inline void cpuTime() { cerr << "cpu time : " << double(clock()) / CLOCKS_PER_SEC << "\n"; return; } using ll = long long; using ull = unsigned long long; using F = float; using D = double; using vi = ...
1
#include <bits/stdc++.h> using namespace std; int dfs(int x, const vector<vector<int> > &g, vector<char> &used, vector<vector<int> > &ans) { used[x] = 1; vector<pair<int, int> > from; vector<int> sons, kill; for (int dest : g[x]) if (!used[dest]) { sons.push_back(dest); int cur = dfs(des...
15
#include <bits/stdc++.h> using namespace std; long long int mod = 1e9 + 7; const double error = 1e-7; const double PI = acos(-1); mt19937 rng( (unsigned int)chrono::system_clock::now().time_since_epoch().count()); inline long long int MOD(long long int x, long long int m = mod) { if (x < m) return x; return x %...
21
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 100; map<int, int> mp; vector<int> V[MAXN]; int cnt, tel; struct node { int x; int id; } a[MAXN]; int get_id(int x) { if (mp.find(x) != mp.end()) return mp[x]; return mp[x] = cnt++; } int main() { ios::sync_with_stdio(false); int n, flag, ...
14
#include <bits/stdc++.h> using namespace std; vector<long long> b, a; int main() { long long p, k; scanf("%lld %lld", &p, &k); for (long long pre = p; pre;) { long long now = (k - pre) / k; if (now * k >= k - pre) --now; b.push_back(pre = now); } a.push_back(p); for (int i = 0; i < b.size(); ++i...
12
#include <bits/stdc++.h> using namespace std; template <typename T> void read(T &x); template <typename T> void write(T x); template <typename T> void writesp(T x); template <typename T> void writeln(T x); const long long N = 37, M = 1ull << 19; long long n, m; long long num[N]; long long lsh[2][M], h[2]; inline void d...
10
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:102400000,102400000") using namespace std; const int block_size = 360; const long long mod = 1e9 + 7; const long double eps = 1e-9; long long p, k; long long fast(long long a, long long b, long long mod) { long long ans = 1; while (b > 0) { if (b % 2 == 0...
10
#include <bits/stdc++.h> using namespace std; long long n, m, l, r, k, x, a[50000]; int main() { cin >> m >> n; for (int i = 1; i <= n; i++) { cout << i << endl; cin >> a[i]; if (a[i] == 0) { return 0; } } l = n + 1; r = m; k = 0; while (l <= r) { k++; long long mid = (l + r)...
10
#include <bits/stdc++.h> using namespace std; int n, m, i, x, y, q, tp, v, Ans, j; vector<int> g[1400005]; bitset<1000> t[1400005]; int tag[1400005]; int ps[1400005]; int sz[1400005]; bitset<1000> X; int a[1400005]; int ord[1400005]; bool vis[1400005]; int P[2222]; void dfs(int x, int p) { ord[++q] = x; ps[x] = q, ...
20
#include <bits/stdc++.h> using namespace std; long long int a, b, c, d, e; string s; int main() { cin >> a >> s; for (long long int i = 0; i < a; i++) { if ((s[i] - '0') % 2 == 0) { b += i + 1; } } cout << b << endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; int main() { long long int l, r; cin >> l >> r; cout << "YES" << endl; for (long long int i = l; i <= r; i += 2) { cout << i << " " << i + 1 << endl; } return 0; }
2
#include <bits/stdc++.h> using namespace std; int main() { long long m, h1, h2, a1, a2, x1, y1, x2, y2; cin >> m >> h1 >> a1 >> x1 >> y1 >> h2 >> a2 >> x2 >> y2; long long res1, res2, rep1, rep2, count = 0; res1 = res2 = rep1 = rep2 = -1; for (int i = 1; i <= 2 * m; i++) { h1 = (x1 * h1 + y1) % m; if ...
14
#include <bits/stdc++.h> using namespace std; const int MOD1 = 1e9 + 7; const int MOD2 = 998244353; const long long INF = 2 * 1e18; const long double PI = 3.14159265358979323846; int main() { long long n, cnt = 0, t = 0; bool x = 0; string s; cin >> n >> s; if (n % 2) { cout << ":("; return 0; } f...
9
#include <bits/stdc++.h> using namespace std; int a[101000], n; int w[101000 / 50 + 1][60]; void calc(int i) { int t; for (t = 0; t < 60; t++) { int b = i * 50; int e = b + 50; int v = t; for (int j = b; j < e; v++) { if (v % a[j]) j++; } w[i][t] = v - t; } } int main() { int n, i,...
16
#include <bits/stdc++.h> using namespace std; int dsu[2001]; int size[2001]; void assign(int n) { for (int i = 0; i <= n; i++) { dsu[i] = i; size[i] = 1; } } int find(int i) { while (i != dsu[i]) { dsu[i] = dsu[dsu[i]]; i = dsu[i]; } return i; } void unionn(int x, int y) { int xx = find(x); ...
7
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; long long f1 = 2, f2 = 3; long long ans = 2; if (n == 2) { cout << 1 << endl; return 0; } long long x; while (f2 <= n) { ans++; x = f2; f2 += f1; f1 = x; } cout << ans - 1 << endl; return 0; }...
8
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1); const double eps = 1e-9; const int inf = 2000000000; const long long infLL = 9000000000000000000; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; int tc; cin >> tc; while (tc--) { int a, b, c, d; cin >>...
0
#include <bits/stdc++.h> using namespace std; const int nu = (int)3e6 + 10; int n; char s[nu]; int main() { ios_base::sync_with_stdio(0), cin.tie(0); scanf("%d %s", &n, s); int d = 0, r = 0, curd = 0, curr = 0; for (int i = 0; i <= n - 1; i += 1) { if (s[i] == 'D') curd++; else curr++; } ...
7
#include <bits/stdc++.h> using std::copy; using std::fill; using std::swap; const int MaxN = 1 << 19; const int mod_base = 119, mod_exp = 23; const int mod_v = (mod_base << mod_exp) + 1; const int primitive_root = 3; int epsilon_num; int eps[MaxN], inv_eps[MaxN], inv2; int dec(int x, int v) { x -= v; return x < 0 ?...
23
#include <bits/stdc++.h> using namespace std; long long MOD(long long, long long); void doublesetprecision(double, int); bool isEven(long long); int gcd(int, int); int n, m, o, ans, k; int a[1000000]; void solve() { cin >> n; for (long long i = 0; i < n; i++) cin >> a[i]; map<int, int> mm; for (long long i = 0;...
2
#include <bits/stdc++.h> using namespace std; int main() { int n, s = 0, sum; char c; bool flag; cin >> n; vector<int> V(n); for (int i = 0; i < n; ++i) { cin >> c; V[i] = (int)c - 48; } for (int i = 0; i < n - 1; ++i) { s += V[i]; sum = 0; flag = false; for (int j = i + 1; j < n...
5
#include <bits/stdc++.h> using namespace std; int cnt[100]; string st; int main() { cin >> st; for (int i = 0; i < st.size(); i++) cnt[st[i] - 48]++; cnt[1]--, cnt[6]--, cnt[8]--, cnt[9]--; int rest = 0; for (int i = 9; i > 0; i--) for (int j = 1; j <= cnt[i]; j++) { printf("%d", i); rest = (r...
8
#include <bits/stdc++.h> using namespace std; int main() { long long n, a, b, c; cin >> n; a = 1; b = 1; c = n - 2; if (c % 3 == 0) { b = b + 1; c = c - 1; } cout << a << " " << b << " " << c << endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; int N; long long area[1001]; vector<pair<long long, int>> leftOfMaxArea; vector<pair<long long, int>> rightOfMaxArea; int main() { cin >> N; int p1 = 1; int p2 = 2; for (int sign, i = 3; i <= N; i++) { if (i == p1 or i == p2) continue; printf("2 %d %d %d\n",...
15
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int a, b, c, d; cin >> a >> b >> c >> d; cout << (max(a + b, c + d)) << endl; } return 0; }
1
#include <bits/stdc++.h> using namespace std; int a[100100]; int b[100100]; map<int, int> us; void solve() { int n; cin >> n; a[0] = -1; vector<int> v; for (int i = 1; i <= n; i++) { cin >> a[i]; if (a[i] != a[i - 1]) { v.push_back(a[i]); } us[a[i]] = 1; } v.push_back(-1); int l = ...
8
#include <bits/stdc++.h> using namespace std; int l = -1; long long N, M, f[262150][105], w[20], sum[10], jc[20]; int main() { cin >> N >> M; for (; N; N /= 10) w[++l] = N % 10; for (int i = 0; i <= l; ++i) { sum[w[i]]++; if (w[i]) f[1 << i][w[i] % M] = 1; } for (int i = 1; i <= (1 << l + 1) - 1; ++i)...
12
#include <bits/stdc++.h> using namespace std; template <typename T, typename U> inline void smin(T &a, U b) { if (a > b) a = b; } template <typename T, typename U> inline void smax(T &a, U b) { if (a < b) a = b; } struct point { double first, second; point(double first = 0, double second = 0) : first(first), se...
12
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; long long cal(long long a, long long x) { long long ans = 1; while (x) { if (x & 1) ans = (ans * a) % MOD; x >>= 1; a = (a * a) % MOD; } return ans; } int main() { long long p, k; scanf("%lld%lld", &p, &k); if (k == 0) { ...
10
#include <bits/stdc++.h> using namespace std; struct pnt { int x, y; }; bool operator<(pnt x, pnt y) { return x.x < y.x; } bool operator>(pnt x, pnt y) { return x.x > y.x; } bool operator==(pnt x, pnt y) { return x.x == y.x; } int main() { int n, k, sum, cnt; pnt a[101]; while (cin >> n) { cin >> k; for...
2
#include <bits/stdc++.h> using namespace std; int dist[30][30]; int main() { int i, j, k; int n, m; int u, v; for (i = 0; i < 30; i++) { for (j = 0; j < 30; j++) dist[i][j] = 100000000; } for (i = 0; i < 30; i++) dist[i][i] = 0; string s, t; cin >> s >> t; if (s.length() != t.length()) { cout ...
10
#include <bits/stdc++.h> using namespace std; const int inf = 1000000007; const long long linf = 1ll * inf * inf; const int N = 200000 + 7; const int M = 31; const int multipleTest = 0; int n, m; vector<int> a[N]; int r[N]; int get(int u) { return r[u] < 0 ? u : r[u] = get(r[u]); } void uni(int u, int v) { if (u == v...
13
#include <bits/stdc++.h> int n; long long m; int xi, yi; long long check(long long k) { long long sum = (2 * k * k - 2 * k + 1); if (k > xi + 1) { long long tmp = k - (xi + 1); sum -= ((2 * tmp * tmp - 2 * tmp + 1) - (2 * tmp - 1)) / 2 + (2 * tmp - 1); } if (k > yi + 1) { long long tmp = k - (yi + 1...
10
#include <bits/stdc++.h> using namespace std; const int MAXN = 1002; vector<vector<long long> > digl(MAXN, vector<long long>(MAXN)); vector<vector<long long> > digr(MAXN, vector<long long>(MAXN)); vector<vector<long long> > H(MAXN, vector<long long>(MAXN)); vector<vector<long long> > V(MAXN, vector<long long>(MAXN)); i...
17
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n; cin >> k; int array[n]; int min = 1000000001; for (int i = 0; i < n; i++) { cin >> array[i]; if (min > array[i]) { min = array[i]; } } bool flag = true; long long result = 0; for (int i = 0; i < n; i++) ...
1
#include <bits/stdc++.h> using namespace std; const int inf = 1000000007; const long long linf = 1000000000000000000LL; const double eps = 0.000001; const double pi = 3.14159265358979323846; template <class T> T abs(T k) { return k >= 0 ? k : -k; } template <class T> T sqr(T n) { return n * n; } template <class T> ...
7
#include <bits/stdc++.h> using namespace std; const int N = 5e3 + 10; const int inf = 1e9; const int mo = 998244353; int a[N]; int main() { int n; scanf("%d", &n); for (auto i = (1); i <= (n); ++i) a[i] = n; for (auto i = (1); i <= (n); ++i) { int x; scanf("%d", &x); x = min(x, n); for (auto i =...
14
#include <bits/stdc++.h> using namespace std; const int siz = 10 + 1e6; const int siz1 = 5e5 + 10; int f[siz], a[siz1], n, k, len, L, R; int main() { scanf("%d%d", &n, &k); for (int i = 0; i < n; i++) scanf("%d", &a[i]); int l = 0, r = 0, cnt = 0; while (r < n) { if (f[a[r]] == 0) cnt++; f[a[r]]++; ...
8
#include <bits/stdc++.h> using namespace std; long long dp[2][200005], mod = 1e9 + 7; int add(int a, int b) { if (a + b > mod) { return a + b - mod; } return a + b; } int main() { int r, g; scanf("%d%d", &r, &g); int i, j; if (r < g) { swap(r, g); } dp[0][0] = 1; int h = 0; for (i = 1; i <...
12
#include <bits/stdc++.h> using namespace std; const long long maxn = 2e6 + 10; const double Pi = acos(-1.0); struct Complex { double x, y; Complex(double xx = 0, double yy = 0) { x = xx, y = yy; } } a[maxn], b[maxn]; Complex operator+(Complex a, Complex b) { return Complex(a.x + b.x, a.y + b.y); } Complex operato...
15
#include <bits/stdc++.h> using namespace std; using ll = long long; using ii = pair<int, int>; using vi = vector<int>; using vll = vector<ll>; using vii = vector<ii>; const ll MOD = 998244353; const int INF = 1e9 + 9; const int MAXN = 1000; int n, m, k, a[MAXN][MAXN], b[MAXN][MAXN], good, bad; bool feasible = true; cha...
7
#include <bits/stdc++.h> using namespace std; int main() { int n, m, x, y, z; double max = 0, temp; scanf("%d %d", &n, &m); int a[n]; for (int i = 0; i < n; i++) scanf("%d", &a[i]); for (int i = 0; i < m; i++) { scanf("%d %d %d", &x, &y, &z); temp = (double)(a[x - 1] + a[y - 1]) / z; if (temp > ...
8
#include <bits/stdc++.h> using namespace std; int N, K, T, a[22][22], t[22]; char s[200010], q[22], l; int c[1 << 22]; int main() { ios::sync_with_stdio(false); cin >> N >> K >> T >> s; for (int i = 0; i < K; i++) cin >> t[i]; for (int i = 0; i < K; i++) for (int j = 0; j < K; j++) cin >> a[i][j]; for (in...
19
#include <bits/stdc++.h> using namespace std; const int MAX_N = 300000; int ts0[MAX_N], ts1[MAX_N], ts2[MAX_N]; long long tss[MAX_N + 1]; pair<long long, int> ps[MAX_N + 1]; int mxs0[MAX_N + 1], mxs1[MAX_N + 1], mxs2[MAX_N + 1]; void calcmx(int n, int ts[], int mxs[]) { tss[0] = 0; ps[0] = pair<long long, int>(0, 0...
22
#include <bits/stdc++.h> using namespace std; long long mod = 1e9 + 7; long long power(long long a, long long b) { long long res = 1; while (b) { if (b & 1) res = res * a % mod; a = a * a % mod; b /= 2; } return res; } long long mod_inv(long long a) { return power(a, mod - 2); } int k; const int K =...
14
#include <bits/stdc++.h> using namespace std; int n, t, F[200000 + 5], A[200000 + 5], T[200000 + 5], q[200000 + 5], Neg[200000 + 5], Pos[200000 + 5], Zero[200000 + 5]; void Prepare() { for (int i = 2; i <= n; i++) { if (!F[i]) F[i] = q[++q[0]] = i; for (int j = 1; i * q[j] <= n && j <= q[0]; j++) { ...
12
#include <bits/stdc++.h> using namespace std; int x, y, a, b; int main(void) { scanf("%d%d%d%d", &x, &y, &a, &b); if (a <= 0 && 0 <= b) { if (x + a <= y && y <= x + b) printf("FIRST\n%d\n", y); else puts("DRAW"); } else { int d = y - x; bool flag = 0; if (a <= b && b < 0) { d...
16
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int nax = 1e7+7; const int MOD = 1e9+7; void printarr(vector<int> v){ for(int i=0; i<v.size(); i++){ cout<<v[i]<<" "; } cout<<endl; } int main(){ int t; cin>>t; while(t--){ int n; cin>>n; stack<int>...
4
#include <bits/stdc++.h> using namespace std; const long long mo = 1000000007; long long f[105][100 * 100 + 5], c[105][105], a[105]; long long cal(long long i, long long j) { if (j == 1) return i; if (j % 2 == 1) return cal(i, j - 1) * i % mo; long long k = cal(i, j / 2); return k * k % mo; } int main() { lon...
11
#include <bits/stdc++.h> using namespace std; long long fpow(long long a, int b, int mod) { long long res = 1; for (; b > 0; b >>= 1) { if (b & 1) res = res * a % mod; a = a * a % mod; } return res % mod; } const int mod = 1e9 + 7; const int N = 1e4 + 100; long long gcd(long long a, long long b) { retur...
7
#include <bits/stdc++.h> using namespace std; const int M = 100 + 5; int a[M]; vector<int> exam[M]; int ihash[M]; int main() { int k, n; cin >> n >> k; int per = n / k; for (int i = 1; i <= n; i++) { cin >> a[i]; } int q; cin >> q; double minv = 1e+6; double maxv = 0; for (int i = 0; i < q; i++)...
11
#include <bits/stdc++.h> using namespace std; int main() { int a[1000][1000] = {0}; int n, t; int m = 0; cin >> n; for (int i = 1; i <= n; i++) { cin >> t; if (t > m) m = t; for (int j = 1; j <= t; j++) a[i][j] = 1; } int p = 0; for (int i = 1; i <= m; i++) { p = 0; for (int j = 1; j...
1
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; vector<int> v(n); vector<int> v1; set<int> s; for (long long i = (0); i < (n); i++) { cin >> v[i]; if (s.find(v[i]) == s.end()) { v1.push_back(v[i]); } ...
4
#include <bits/stdc++.h> using namespace std; bool prime[10000004] = {0}; int main() { int i, j, n, m; while (cin >> n) { for (i = 4; i <= 10000004; i += 2) prime[i] = 1; prime[2] = 0; for (i = 3; i <= sqrt(10000004); i += 2) { for (j = i * i; j <= 10000004; j += 2 * i) prime[j] = 1; } for...
0
#include <bits/stdc++.h> using namespace std; vector<int> a, d; int n, Min = -1; int getans() { if (n == 0) return 0; if (n >= Min) { int ans = 0; int m = n; for (int i = n - 1; i >= n - Min; i--, m--) ans += a[i]; n = m; if (n > 1) n -= 2; else if (n > 0) n -= 1; return geta...
6
#include <bits/stdc++.h> using namespace std; int h, w; char s[505][505]; int num[505][505]; int A[505][505]; int B[505][505]; int main() { cin >> h >> w; for (int i = 1; i <= h; i++) scanf("%s", s[i] + 1); for (int i = 1; i <= h; i++) for (int j = 1; j <= w; j++) if (s[i][j] == '.') num[i][j] =...
7
#include <bits/stdc++.h> long long res = 0; int n, m, d, q, lim, ar[200010], lol[200010], tmp[200010], tree[(200010 / 2000) + 5][200010]; void update(int *tree, int p, int v) { while (p <= lim) { tree[p] += v; p += (p & (-p)); } } int query(int *tree, int p) { int res = 0; while (p) { res += tre...
14
#include <bits/stdc++.h> using namespace std; template <class A, class B> A cvt(B x) { stringstream ss; ss << x; A y; ss >> y; return y; } double PI = acos(-1.0); int n; int p[1000]; double area[1000]; vector<int> ch[1000]; long long sqr(long long x) { return x * x; } long long dist2(vector<int> &c1, vector<i...
12
#include <bits/stdc++.h> using namespace std; int m, n, a, b, c, d; int main() { cin >> a >> b >> c >> d; m = max((3 * a) / 10, a - (a / 250 * c)); n = max((3 * b) / 10, b - (b / 250 * d)); if (m == n) cout << "Tie"; else if (m > n) cout << "Misha"; else cout << "Vasya"; }
1
#include <bits/stdc++.h> using namespace std; const int oo = 1e9 + 7; int n, k1, k2, cnt = 0; deque<int> p1, p2; int main() { scanf("%d", &n); scanf("%d", &k1); for (int i = 1; i <= k1; ++i) { int u; scanf("%d", &u); p1.push_back(u); } scanf("%d", &k2); for (int i = 1; i <= k2; ++i) { int u;...
6
#include <bits/stdc++.h> using namespace std; int n, m, k; char a[2001][2001]; int ans[2001]; void init() { scanf("%d%d%d", &n, &m, &k); for (int i = 1; i <= n; i++) scanf("%s", &a[i][0]); for (int i = 1; i <= n; i++) for (int j = 0; j < m; j++) { if (j - i + 1 >= 0 && a[i][j - i + 1] == 'R') ans[j]++; ...
6
#include <bits/stdc++.h> using namespace std; const int MAXN = 100005; int n, q, v; int ans[MAXN]; int laz1[MAXN << 2]; char tp; bool laz2[MAXN << 2]; vector<int> pos[MAXN]; vector<int> neg[MAXN]; void fill(vector<int> &sou, vector<int> &tar) { while (sou.size()) { tar.push_back(sou.back()); sou.pop_back(); ...
16
#include <bits/stdc++.h> using namespace std; int main(int argc, char *argv[]) { long long n, m, ans = 0; cin >> n >> m; vector<vector<long long> > c(n + m + 1, vector<long long>(n + m + 1)); for (int i = 0; i < c.size(); i++) { c[i][0] = c[i][i] = 1; for (int j = 1; j <= i / 2; j++) c[i][j] = c[i...
15
#include <bits/stdc++.h> using namespace std; template <typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; } template <typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; } const int oo = 0x3f3f3f3f; const int maxn = 30000, max0 = 4; int n, qn; long long a[ma...
22
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0), cout.tie(0); long long a, b, ans = 0; cin >> a >> b; long long x, y, z; cin >> x >> y >> z; long long s1 = 2 * x + y - a; long long s2 = 3 * z + y - b; if (s1 > 0) { ans += s1; } if (s2 > 0) { a...
0
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long n, k, c = INT_MAX, x, t; cin >> n >> k; for (int i = 1; i <= sqrt(n); ++i) { if (n % i == 0) { t = (i * k + (n / i)); if ((i * k + (n / i)) < c && (t / k) * (t % k...
3
#include <bits/stdc++.h> using namespace std; char s[100000 + 10]; int main() { cin >> s; int len = strlen(s), ok = 0, mn = 0, num = s[len - 1] - '0'; for (int i = 0; i < len - 1; ++i) if (!((s[i] - '0') & 1)) { ok = 1; mn = max(mn, i); if (s[i] - '0' < num) { swap(s[i], s[len - 1]);...
5