solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> using namespace std; const int maxn = 200100; bool c[maxn][10]; char s[maxn]; int n; void work() { for (int i = n; i >= 1; --i) { for (int j = s[i] - '0' - 1; j >= 0; --j) { if (i == 1 && j == 0) continue; int left = 0; for (int k = 0; k < 10; ++k) { if (k == j) ...
14
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const int N = 100005; vector<int> tree[N]; struct node { int l, r; } mem[N * 2]; int ansl[N], L, ansr[N], R; int vt[N], V; int main() { int n, m, h, t; while (cin >> n >> m >> h >> t) { for (int i = 1; i <= n; ++i) tree[i].clear(); ...
12
#include <bits/stdc++.h> using namespace std; using pii = pair<int, int>; using ll = long long; using ld = long double; using pll = pair<ll, ll>; using ull = unsigned long long; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ll a, b, c, d; cin >> a >> b >> c >> d; int n, m; cin >> n >> m; ...
3
#include <bits/stdc++.h> using namespace std; inline int read() { int a = 0; char c = getchar(); bool f = 0; while (!isdigit(c)) { if (c == '-') f = 1; c = getchar(); } while (isdigit(c)) { a = (a << 3) + (a << 1) + (c ^ '0'); c = getchar(); } return f ? -a : a; } int point[51][3], N; vo...
14
#include <bits/stdc++.h> using namespace std; struct hash_pair { template <class T1, class T2> size_t operator()(const pair<T1, T2>& p) const { auto hash1 = hash<T1>{}(p.first); auto hash2 = hash<T2>{}(p.second); return hash1 ^ hash2; } }; bool prime[10000001]; long long P = 1000000007 - 2; long long ...
3
#include <bits/stdc++.h> const bool debug = false; using namespace std; long long powmod(long long a, long long b, long long MOD) { long long res = 1; a %= MOD; for (; b; b >>= 1) { if (b & 1) res = res * a % MOD; a = a * a % MOD; } return res; } void buginfo(const char* f, ...) { if (!debug) return...
2
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const unsigned long long LLINF = 2e18; const int maxN = 1e5; unsigned long long solve(vector<unsigned long long> &A, vector<unsigned long long> &B) { int na = A.size(), nb = B.size(); unsigned long long a_sum = 0; f...
11
#include <bits/stdc++.h> using namespace std; long long howMany(long long x, long long y, long long turn, long long size) { long long result = (2 + 2 * turn) * turn; if (x + turn > size) { result -= (x + turn - size) * (x + turn - size); } if (x - turn < 1) { long long temp = abs(x - turn - 1); resu...
10
#include <bits/stdc++.h> template <typename T> inline T max(T a, T b) { return a > b ? a : b; } template <typename T> inline T min(T a, T b) { return a < b ? a : b; } template <typename T> inline T abs(T a) { return a > 0 ? a : -a; } template <typename T> inline bool repr(T &a, T b) { return a < b ? a = b, 1 : ...
19
#include <bits/stdc++.h> using namespace std; const int maxN = 1e5 + 7; long long n, k, D, M, ans; int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n >> k >> M >> D; ans = M; for (int i = 1; i <= D; i++) { long long l = 0, r = M + 1; while (r - l > 1) { long long mid = (l + r) / 2; ...
12
#include <bits/stdc++.h> using namespace std; const int mxn = 400; const int inf = 1e7; int m[410][410]; vector<int> r[420]; vector<int> b[420]; int p, q; int visit[410]; int dr[410], db[410]; void bfs1() { queue<int> Q; Q.push(1); memset(visit, 0, sizeof visit); for (int i = 1; i <= p; i++) dr[i] = inf; visi...
8
#include <bits/stdc++.h> using namespace std; const long long ALPH = 26 * 2 + 10; const long long MX = ALPH * ALPH; struct Graph { long long indegree[MX]; long long outdegree[MX]; vector<pair<long long, long long>> edges; void clear(long long n) { edges.clear(); for (long long i = 0; i < (long long)n; i...
17
#include <bits/stdc++.h> using namespace std; signed main() { ios::sync_with_stdio(false); cin.tie(nullptr); long long t; cin >> t; while (t--) { long long n; cin >> n; string s; cin >> s; vector<long long> d(n); for (long long i = 0; i < n; i++) { d[i] = s[i] - '0'; } bo...
1
#include <bits/stdc++.h> using namespace std; bool prime[1000000 + 10]; vector<int> v[1000000 + 10]; int sz[1000000 + 10]; int res; void dfs(int st, int mul, int ji, int mid, int p) { if (mul > mid) return; if (st == sz[p]) { if (ji == 0) return; if (ji & 1) res += mid / mul; else res -= mid...
14
#include <bits/stdc++.h> using namespace std; int main() { int n; long long x, y; cin >> n >> x >> y; long long a = (y - n + 1); if (a <= 0 || a * a + n - 1 < x) { cout << -1; } else { cout << a << endl; for (int i = 1; i < n; i++) { cout << 1 << endl; } } }
6
#include <bits/stdc++.h> using namespace std; const int N = 2 * 1e5 + 5; int n, a[N], l[N], r[N]; map<int, int> mp; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d", &a[i]), r[i] = n + 1; for (int i = 0; i <= 31; i++) { int res = 0; for (int j = 1; j <= n; j++) { if ((a[j] >> i)...
14
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") using namespace std; template <typename T, typename TT> inline ostream &operator<<(ostream &os, const pair<T, TT> &t) { return os << t.first << " " << t.second; } template <typename T> inline ostream &operator<<(ostream &os, const vector<T> &t) { for (T i : t) ...
7
#include <bits/stdc++.h> using namespace std; void del(int edge, vector<set<int>>& g, map<int, int>& degr, int k) { degr.erase(degr.find(edge)); for (auto neigh : g[edge]) { g[neigh].erase(edge); auto it = degr.find(neigh); if (it != degr.end()) { if (--degr[neigh] < k) { del(neigh, g, deg...
14
#include <bits/stdc++.h> using namespace std; const int mx = 1e5 + 10; int a[mx], ans = 0; long long sum; string s; int main() { cin >> s; int p = 0; int len = s.size(); for (int i = 1; i < len; i++) { if (s[i] == '1') p = 1; } if (p == 1 || len % 2 == 0) cout << (len - 1) / 2 + 1 << endl; else ...
2
#include <bits/stdc++.h> using namespace std; bool comp(int a, int b) { return (a > b); } int main() { int n, k, i = 0; char data[100005]; scanf("%d %d", &n, &k); scanf("%s", &data); while (i + 1 < n && k > 0) { if (data[i] == '4' && data[i + 1] == '7') { if (i % 2 == 1) { if (i > 0 && data[...
7
#include <bits/stdc++.h> using adj_t = std::unordered_map<std::string, std::vector<std::string>>; adj_t adj; std::unordered_map<std::string, int> In; std::string x, y, Ans, S; bool valid = 1; int n; void dfs(std::string s) { std::string a; while (!adj[s].empty()) { a = adj[s].back(); adj[s].pop_back(); ...
17
#include <bits/stdc++.h> using namespace std; void solve(); set<long long> s1; bool prime[1000001]; void sieve() { long long i; prime[1] = 1; prime[0] = 1; for (i = 0; i <= 1000001; i++) prime[i] = 1; for (i = 2; i * i <= 1000000; i++) { if (prime[i] == 1) { for (long long j = i * i; j <= 1000000; j...
2
#include <bits/stdc++.h> using namespace std; int main() { int a[6], t = 0, m; for (int i = 0; i < 6; i++) { cin >> a[i]; } while (a[1] != 0 && a[5] != 0) { t = t + (2 * a[0] + 1); a[0]++; a[1]--; a[5]--; } t = t + 2 * a[0] * a[5] + 2 * a[0] * a[1]; while (a[4] != 0 && a[2] != 0) { ...
8
#include <bits/stdc++.h> int main() { int x, y; scanf(" %d", &x); y = x; int n = 1, m; while (x > 9) { x = x / 10; n *= 10; } printf("%d", ((x + 1) * n - y)); return 0; }
1
#pragma GCC optimize ("O3") #pragma GCC target ("sse4") #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef complex<ld> cd; typedef pair<int, int> pi; typedef pair<ll,ll> pl; typedef pair<ld,ld> pd; typedef vector<int> vi; typedef vector<ld> vd; typedef vector<l...
23
#include <bits/stdc++.h> using namespace std; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long t; cin >> t; while (t--) { long long n; cin >> n; long long down = 1e9, up = 0; bool ok = true; while (n--) { long long a; cin >> a; if (a - up...
10
#include <bits/stdc++.h> using std::vector; const int maxn = 1e6 + 1; vector<int> e[maxn], to[maxn]; struct Segment_Tree { int val[maxn << 2], cnt[maxn << 2]; inline void pushup(int rt, int l, int r) { if (cnt[rt]) val[rt] = (r - l + 1); else val[rt] = val[rt << 1] + val[rt << 1 | 1]; } inli...
16
#include <bits/stdc++.h> using namespace std; class Timer { private: string scope_name; chrono::high_resolution_clock::time_point start_time; public: Timer(string name) : scope_name(name) { start_time = chrono::high_resolution_clock::now(); } ~Timer() { auto stop_time = chrono::high_resolution_cloc...
12
#include <bits/stdc++.h> using namespace std; void Read(int &x) { static char c; while (!isdigit(c = getchar())) ; x = (c ^ 48); while (isdigit(c = getchar())) x = x * 10 + (c ^ 48); return; } void Print(int x, char end) { static int i; for (i = 1; i * 10LL <= x; i *= 10) ; for (; i; i /= 10) pu...
23
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 5; int tot = 0; int head[maxn], vis[maxn], c[maxn]; long long d[maxn]; struct edge { int v, next; } e[maxn * 2]; void add(int u, int v) { e[tot].v = v; e[tot].next = head[u]; head[u] = tot++; } void dfs(int x) { vis[x] = 1; int y; for (i...
13
#include <bits/stdc++.h> using namespace std; const int MAXN = 5e3 + 100; const int mod = 1e9 + 7; int n, A[MAXN << 2], prod[MAXN << 2], f[MAXN][MAXN << 1], ret[MAXN << 2], invp[MAXN << 2]; int ksm(int a, int b) { int ret = 1; while (b) { if (b & 1) ret = 1ll * ret * a % mod; b >>= 1; a = 1ll * a * ...
17
#include <bits/stdc++.h> using namespace std; int arr[2005], arr1[2005], arr2[2005]; int main() { int t, ind = 1, count = 1; scanf("%d", &t); for (int i = 0; i < t; i++) { scanf("%d", &arr[i]); arr1[i] = arr[i]; } sort(arr, arr + t); for (int i = t - 1; i >= 0; i--) { arr2[arr[i]] = ind; if ...
0
#include <bits/stdc++.h> using namespace std; long n, k, bad[1 << 20]; vector<long> vec[1 << 20]; long cnt; int main() { ios_base::sync_with_stdio(0); cin >> n >> k; for (int i = 1; i <= n; i++) { vec[i].push_back(6 * i - 4); vec[i].push_back(6 * i - 5); vec[i].push_back(6 * i - 3); vec[i].push_ba...
11
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; double cnt = 0; const double pi = 3.1415926536; double inp[n], ans[n]; for (int i = 0; i < n; i++) { cin >> inp[i]; } sort(inp, inp + n); ans[0] = pi * pow(inp[0], 2); for (int i = 1; i < n; i++) { ans[i] = pi * (pow...
2
#include <bits/stdc++.h> using namespace std; pair<int, int> s[100000]; int a[100000], b[100000], as[100000], bs[100000]; int main() { int n, i, x; cin >> n; for (i = 0; i < n; i++) { cin >> x; s[i] = pair<int, int>(x, i); } sort(s, s + n); for (i = 0; i < n / 3; i++) { a[i] = i; b[i] = s[i]...
16
#include <bits/stdc++.h> template <typename T> inline T abs(T a) { return a < 0 ? -a : a; } template <typename T> inline T min(T a, T b) { return a < b ? a : b; } template <typename T> inline T max(T a, T b) { return a > b ? a : b; } template <typename T> inline void swap(T &a, T &b) { T t = a; a = b, b = t; ...
20
#include <bits/stdc++.h> using namespace std; signed main() { long long n, sum = 0, t; long double ans = 0; map<long long, unsigned> mp; scanf("%I64d", &n); for (long long i = 0; i < n; i++) { scanf("%I64d", &t); ans += t * i - sum - mp[t - 1] + mp[t + 1]; mp[t]++; sum += t; } cout << fixe...
14
#include <bits/stdc++.h> using namespace std; int lnb[50], n, a[101000], q, l, x, usd, nus; int sub[101000], pw[101050]; const int Md = 1e9 + 7; struct qur { int l, x, t; } qr[100100]; bool cmp(qur p, qur q) { if (p.l != q.l) return p.l < q.l; else return p.x < q.x; } void gtlnb(int k) { for (int i = 30...
16
#include <bits/stdc++.h> using namespace std; const double eps = 1e-7; int dcmp(double x) { return (fabs(x) < eps) ? (0) : ((x < 0) ? (-1) : (1)); } typedef class Point { public: double x, y; int id; Point(double x = 0.0, double y = 0.0, int id = 0) : x(x), y(y), id(id) {} double length(); Point normal(); ...
24
#include <bits/stdc++.h> using namespace std; int number(char c) { if (c == 'A') return 0; else if (c == 'C') return 1; else if (c == 'G') return 2; else return 3; } int lowbit(int x) { return x & -x; } int n, m; struct BIT { int c[100005]; void update(int x, int y) { while (x <= n) { ...
13
#include <bits/stdc++.h> const int maxN = 100000, maxQ = 100000; struct Edge { int x, y; inline bool operator==(const Edge r) const { return x == r.x && y == r.y; } }; struct EdgeHasher { inline unsigned long long operator()(const Edge e) const { return (static_cast<unsigned long long>(e.x) << 32) | e.y; } ...
17
#include <bits/stdc++.h> using namespace std; template <class c> struct rge { c b, e; }; template <class c> rge<c> range(c i, c j) { return rge<c>{i, j}; } template <class c> auto dud(c* x) -> decltype(cerr << *x, 0); template <class c> char dud(...); struct debug { template <class c> debug& operator<<(const c&...
14
#include <bits/stdc++.h> using namespace std; const int N = 705; long long int b[5][N][N]; int deg[N]; int main() { int n, m; cin >> n >> m; for (int i = 0; i < m; i++) { int v, u; cin >> v >> u; v--, u--; b[0][v][u] = b[0][u][v] = 1; deg[v]++, deg[u]++; } long long int sum = 0; for (int...
16
#include <bits/stdc++.h> inline int read() { int data = 0, w = 1; char ch = getchar(); while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar(); if (ch == '-') w = -1, ch = getchar(); while (ch >= '0' && ch <= '9') data = data * 10 + (ch ^ 48), ch = getchar(); return data * w; } constexpr int N(1e6 + 10),...
21
#include <bits/stdc++.h> using namespace std; int main() { int ans = 0, ans1 = 0; char a, c; int b, d; cin >> a >> b >> c >> d; a = a - 'a', c = c - 'a'; b = b - 1, d = d - 1; for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) { if ((i == a || j == b) || (i == c && j == d) || (a...
4
#include <bits/stdc++.h> using namespace std; int n; double dis(int x, int y) { return sqrt(1LL * x * x + 1LL * y * y); } struct vec { int x, y; int num; }; vector<vec> V; int w[200005]; int ans[100005]; int ch[200005][2]; int cnt; void find() { int s, t, q; for (int i = 0; i < 3; i++) { for (int j = i + 1;...
15
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; long long ans = 0; for (int i = (0); i < (n); ++i) { long long t, T, x, cost; cin >> t >> T >> x >> cost; if (t >= T) { ans += cost + m * x; continue; } long long aux1 = cost; if (m > (T - t))...
11
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n, m; cin >> n >> m; if ((n == 1 || m == 1) || (n == 2 && m == 2)) { cout << "YES\n"; } else { cout << "NO\n"; } } }
0
#include <bits/stdc++.h> #include <iostream> #include <vector> #include <algorithm> #include <string> #define range(x) x.begin(), x.end() #define pb push_back using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<ll> vl; typedef unsigned long long ull; void print(vector<int> &a) { for...
0
#include <bits/stdc++.h> #define int long long using namespace std; const int N = 2e5 + 10; int a[N], b[N], c[N]; signed main() { int n, k; cin >> n >> k; for(int i = 1; i <= n; ++i) { cin >> a[i]; b[i] = a[i]; } sort(b + 1, b + n + 1); int l = 1; int ans; int r = n; while(l <= r) { int mid = l + ((r...
13
#include <bits/stdc++.h> using namespace std; int n, m, k, r[5001], c[5001], a[100001]; void read() { int f, g; cin >> n >> m >> k; for (int i = 1; i <= k; i++) { cin >> f >> g >> a[i]; if (f == 1) r[g] = i; else c[g] = i; } } void solve() { for (int i = 1; i <= n; i++) { for (int ...
4
#include <bits/stdc++.h> using namespace std; bool isprime[100000 + 10]; long prime[100000 + 10]; long int s; void seive() { memset(isprime, true, sizeof(isprime)); isprime[0] = isprime[1] = false; s = 0; for (long i = 2; i <= 100000; i++) { if (!isprime[i]) continue; prime[s++] = i; for (long j = 2...
10
#include <bits/stdc++.h> using namespace std; vector<int> tr[31]; int fr[31], R, D, dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0}; pair<long long, long long> an[31]; void no() { printf("NO\n"); exit(0); } int sz(int v = R, int p = 0) { int an = 0; for (int i = 0; i < (int)tr[v].size(); ++i) if (tr[v][i] != p...
12
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; const long long inf = 1e9 + 5; void min_self(long long& a, long long b) { a = min(a, b); } void max_self(long long& a, long long b) { a = max(a, b); } void add_self(long long& a, long long b) { a = (a + b) % mod; } void solve() { long long n...
4
#include <bits/stdc++.h> using namespace std; const int N = 2e5; int gi() { int w = 0; bool q = 1; char c = getchar(); while ((c < '0' || c > '9') && c != '-') c = getchar(); if (c == '-') q = 0, c = getchar(); while (c >= '0' && c <= '9') w = w * 10 + c - '0', c = getchar(); return q ? w : -w; } int head...
25
#include <bits/stdc++.h> using namespace std; int gcd(int a, int b) { if (a % b == 0) return b; return gcd(b, a % b); } int main() { int n; scanf("%d", &n); int a1[n], a2[n]; map<pair<int, int>, int> teste; for (int i = 0; i < n; i++) { scanf("%d", &a1[i]); } for (int i = 0; i < n; i++) { scan...
7
#include <bits/stdc++.h> using i64 = long long; const int N = 1e5 + 9; int n, m, a[N], v[N], t[N], tot, ls[N], L[N], R[N]; struct Fenwick { int n, init; std::vector<int> s; Fenwick(int n, int init = 0) : n(n), init(init), s(n + 1, init) {} void update(int x, int k) { if (init != 0) { while (x <= n) { ...
13
#include <bits/stdc++.h> using namespace std; struct Point { int x, y; }; struct Edge { int to, cap; double cost; int next; }; Edge E[340000]; int head[1050], ne = 1; int NV; inline void addEdge(int from, int to, int cap, double cost) { E[++ne] = {to, cap, cost, head[from]}, head[from] = ne; E[++ne] = {from...
16
#include <bits/stdc++.h> using namespace std; long long pref[1000005]; int main() { ios::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); long long N; cin >> N; long long pref[1000005]; memset(pref, 0, sizeof pref); long long x[N + 5]; for (int i = 1; i <= N; i++) { cin >> x[i]; if (!pref[x[...
13
#include <bits/stdc++.h> using namespace std; template <class T> void _R(T &x) { cin >> x; } void _R(int &x) { scanf("%d", &x); } void _R(long long &x) { scanf("%lld", &x); } void _R(unsigned long long &x) { scanf("%llu", &x); } void _R(double &x) { scanf("%lf", &x); } void _R(char &x) { scanf(" %c", &x); } void _R(c...
1
#include <bits/stdc++.h> #pragma GCC optimize(2) using namespace std; const int mod = 998244353; const int inv2 = (mod + 1) >> 1; int qpow(int a, int b) { int ret = 1; while (b) { if (b & 1) ret = 1ll * ret * a % mod; a = 1ll * a * a % mod; b >>= 1; } return ret; } void fwt(vector<int> &a, int f) { ...
24
#include <bits/stdc++.h> using namespace std; struct node { int nxt[6]; int num, vis, len; node() { memset(nxt, 0, sizeof(nxt)); num = 0; vis = 0; len = 0x3f3f3f; } }; struct Node { int loc, pos; }; queue<Node> Q; vector<node> trie; int n, m, tot; node u; char s[100]; int main() { scanf("%d%...
9
#include <bits/stdc++.h> using namespace std; int n; int sum = 0, d; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d", &d); sum += d * i; } printf("%d\n", sum); return 0; }
12
#include <bits/stdc++.h> using namespace std; const int NM = 1000010; const long long MOD = 1000000007; int N, K, M; long long L; long long A[NM]; int Ind[NM]; bool cmpByA(const int& a, const int& b) { return A[a] < A[b]; } long long DP[NM]; long long ANS; int main() { ios::sync_with_stdio(false); cin >> N >> L >> ...
13
#include<bits/stdc++.h> #define ll long long using namespace std; struct cc { int num, id; bool operator < (const cc& tmp) const { return num >tmp.num; } }cnt[3]; int main() { ios::sync_with_stdio(false); cin.tie(0); int t; cin >> t; while (t--) { string a; cin >> a; for (int i = 0; i < 3; i++) { cnt[i].n...
1
#include <bits/stdc++.h> int n, k, l; std::vector<int> pref; std::vector<int> A; inline int sum(int a, int b) { return pref[b + 1] - pref[a]; } std::pair<long long, int> withcost(int cost) { std::vector<std::pair<long long, int> > dp(n + 1); for (int i = (1); i < (n + 1); ++i) { int b = std::max(0, i - l); ...
20
#include <bits/stdc++.h> using namespace std; int main() { long long n, two = 2, res = 0, i = 0; cin >> n; while (n != 1) { n = n / 2; ++res; } cout << res + 1; return 0; }
5
#include <bits/stdc++.h> using namespace std; vector<vector<char> > mt; vector<vector<char> > dp; char p[4] = {'A', 'T', 'C', 'G'}; int n, m; int expandrow(int r, char x, char y) { int id = 0; int cnt = 0; while (id + 1 < m) { if (mt[r][id] == x) cnt++; if (mt[r][id + 1] == y) cnt++; id = id + 2; } ...
13
#include <bits/stdc++.h> using namespace std; ifstream in("in.in"); ofstream out("out.out"); int n, m; const int inf = 1000000005; struct segTree { int l, r, lazy = inf, Max = inf; segTree *lChild, *rChild; segTree(int l, int r) : l(l), r(r) { if (l != r) { int mij = (l + r) / 2; lChild = new segT...
13
#include <bits/stdc++.h> using namespace std; bool f(long long n, long long k) { long long m = n; long long a = 0; long long b = 0; while (n >= k) { n -= k; a += k; b += n / 10; n -= n / 10; if (a * 2 >= m) { return true; } if (b * 2 > m) { return false; } } a += ...
7
#include <bits/stdc++.h> using namespace std; int arr[400000]; void solve(void) { int n; int i; cin >> n; for (i = 0; i < n; i++) { cin >> arr[i]; } int prev = arr[0], cnt = 1, pos = 0; for (i = 1; i < n; i++) { if (prev != arr[i]) { prev = arr[i]; pos = i - 1; } cnt++; if ...
7
#include <bits/stdc++.h> using namespace std; inline int read() { int 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; } inline long long readll() { long long f ...
15
#include <bits/stdc++.h> using namespace std; char ch[105]; inline void change(int x) { if (ch[x] == 'V') ch[x] = 'K'; else ch[x] = 'V'; } int main() { scanf("%s", ch + 1); int n = strlen(ch + 1); int ans, sum = 0; for (int j = 1; j < n; j++) sum += (ch[j] == 'V' && ch[j + 1] == 'K'); ans = sum, s...
3
#include <bits/stdc++.h> using namespace std; int n, m; int g, r; int d[10007][1007]; bool vis[10007][1007]; int a[10007]; struct Node { int p, v; }; long long bfs() { deque<Node> q; q.push_back({0, 0}); vis[0][0] = 1; long long ans = -1; while (!q.empty()) { Node now = q.front(); q.pop_front(); ...
16
#include <bits/stdc++.h> using namespace std; const int INF = 1e9; int n, m, dp[100005]; int h[100005], l[100005], r[100005]; vector<pair<int, int> > v; set<pair<int, int> > c, s; vector<int> ch[100005]; inline int dist(int x, int y) { return min(r[x], r[y]) - max(l[x], l[y]); } inline int dfs(int x) { if (dp[x] != 0...
18
#include <bits/stdc++.h> using namespace std; const int maxn = 3e5 + 17; int n; vector<int> v[128]; int main() { ios::sync_with_stdio(0), cin.tie(0); cin >> n; for (int i = 0; i < n; i++) { int x; char c; cin >> x >> c; if (c == 'P') c = 'G'; v[c].push_back(x); } long long ans = 0; if (v...
14
#include <bits/stdc++.h> const double pi = acos(-1); const int MOD = 1e9 + 7; const int INF = 1e9 + 7; const int MAXN = 1e6 + 5; const double eps = 1e-9; using namespace std; double xp, yp, vp, x, y, v, r, R; double P, len, L; pair<double, double> pos[2]; double f(double dphi) { if (dphi > pi) dphi = 2 * pi - dphi; ...
16
#include <bits/stdc++.h> using namespace std; vector<int> gen(int n) { vector<int> ans; if (n == 1) { ans.push_back(1); return ans; } if (n == 2) { ans.push_back(3); ans.push_back(4); return ans; } int i; for (i = 0; i < n - 1; i++) ans.push_back(1); if (n & 1) ans[0] = 2, ans.pu...
16
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int arr1[n]; for (int i = 0; i < n; i++) { cin >> arr1[i]; } int m; cin >> m; int arr2[m]; for (int i = 0; i < m; i++) { cin >> arr2[i]; } int ms = 0; vector<int> v; for (int i = 0; i < n; i++) { for (int j...
1
#include <bits/stdc++.h> using namespace std; int main() { int n, a; cin >> n; while (n--) cin >> a; vector<string> ans; for (char i = '0'; i < '9'; i++) { string tmp = ""; tmp += i; tmp += "??<>"; tmp += char(i + 1); ans.push_back(tmp); } ans.push_back("9??>>??0"); ans.push_back("??...
17
#include <bits/stdc++.h> using namespace std; long long powmod(long long a, long long l, long long md) { long long res = 1; while (l) { if (l & 1) res = res * a % md; l /= 2; a = a * a % md; } return res; } void solve() { string s; cin >> s; long long o = 0, z = 0; for (long long i = 0; i < ...
6
#include <bits/stdc++.h> using namespace std; const long long INF = 0x3f3f3f; const int maxn = 1e3 + 10; char mp[maxn][maxn]; long long dis[maxn][maxn]; int dir[4][2] = {1, 0, 0, 1, 0, -1, -1, 0}; int main() { int n, m, t, x, y; cin >> n >> m >> t; for (int i = 1; i <= n; i++) scanf("%s", mp[i] + 1); queue<pair...
12
#include <bits/stdc++.h> using namespace std; long long strtoll(string s) { stringstream str(s); long long number = 0; str >> number; return number; } string lltostr(long long n) { stringstream ss; ss << n; return ss.str(); } const int MOD = 1e9 + 7; char a[505][505]; bool in[505][505]; int main() { ios...
5
#include <bits/stdc++.h> using namespace std; double rad[11][11]; int main() { double x; cin >> x; for (int i = 1; i <= 10; i++) for (int j = 1; j <= 10; j++) rad[i][j] = (i * j / 2.0) / sqrt(i * i + j * j / 4.0); int ai = 1; int aj = 1; for (int i = 1; i <= 10; i++) for (int j = 1; j <= 10; j...
10
#include <bits/stdc++.h> using namespace std; vector<int> a[100005], e[100005]; int dep[100005], low[100005]; int u[100005], g[100005]; int FIND(int x) { return g[x] == x ? x : g[x] = FIND(g[x]); } void UNION(int x, int y) { g[FIND(x)] = FIND(y); } void go(int lev, int x, int from = -1) { u[x] = 1; dep[x] = lev; ...
8
#include <bits/stdc++.h> using namespace std; vector<long long> graph[300001]; long long A[300001], dp[300001][3]; long long cst = 0; void dfs(long long u, long long pr) { for (long long v : graph[u]) { if (v != pr) { dfs(v, u); dp[u][0] = max(dp[u][0], dp[v][0]); dp[u][1] = max(dp[u][1], dp[v][...
10
#include <bits/stdc++.h> const int N = 2000005; int pre[N], cnt[N], a[N], n, m; int main() { scanf("%d%d", &n, &m); for (int i = 0; i < n; i++) { scanf("%d", &a[i]); a[i + n] = a[i]; } for (int i = 0; i < m; i++) { long long k, inq = 0; int ans = n; scanf("%I64d", &k); int l = 0; mem...
16
#include <bits/stdc++.h> using namespace std; int main() { int n, total = 0; string moves; cin >> n; cin >> moves; for (int i = n; i < moves.size(); i += n) { char current = moves[i - 1]; bool valid = true; for (int j = 2; j < 4; j++) { valid = valid && current == moves[i - j]; } if ...
5
#include <bits/stdc++.h> using namespace std; const int MAX = 2e5 + 9; vector<int> g[MAX]; long long b[MAX], n, m, ans; void dfs(int v, int p = -1) { for (auto u : g[v]) if (u != p) dfs(u, v), b[v] += b[u]; ans += min(b[v], 2 * m - b[v]); } int main() { cin >> n >> m; for (int i = 0, x; i < 2 * m; i++) cin ...
10
#include <bits/stdc++.h> using namespace std; const int maxn = 100010; pair<int, pair<int, int> > data[maxn], A[maxn]; int n, m, s; int v[maxn], cost; struct queNode { int num, cost, no; queNode() {} queNode(int num, int cost, int no) : num(num), cost(cost), no(no) {} bool operator<(const queNode& B) const { ...
11
#include <bits/stdc++.h> using namespace std; struct edge { int to; bool s; edge(int y, bool z) { to = y; s = z; } }; vector<edge> graph[100005]; int D1[100005], DN[100005], MaxOp[100005], parent[100005], path[100005]; int from[100005], to[100005]; bool opened[100005], visited[100005]; int main() { in...
13
#include <bits/stdc++.h> using namespace std; int64_t find_() { int n, cont1 = 0, cont2 = 0, ans = 0; cin >> n; string s; cin >> s; for (int i = 0; i < n; i++) { if (s[i] == '(') cont1++; if (s[i] == ')') cont2++; if (s[i] == ')') { if (cont2 > cont1) { ans++; cont2--; ...
2
#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<vector<int>> v; v.resize(n); set<pair<int, vector<int>>> s; set<vector<int>> s1; for (int i = 0; i < n; i++) { int x; cin >> x; while (x--) { in...
12
#include <bits/stdc++.h> using namespace std; int n, m; int S[5001], A[5001], X[5001]; int op[5001][4]; int main() { scanf("%d%d", &n, &m); for (int i = 1; i < n + 1; i++) { A[i] = 1000000000; S[i] = 0; } for (int i = 0; i < m; i++) { int t; scanf("%d", &t); if (t == 1) { int l, r, d; ...
9
#include <bits/stdc++.h> using namespace std; int main() { int m, n, t, sum = 0; char a[1000][1000]; int x[1000], y[1000]; scanf("%d %d", &n, &m); for (int i = 0; i < n; i++) { scanf("%s", a[i]); x[i] = 0; for (int j = 0; j < m; j++) if (a[i][j] == '*') { x[i]++; sum++; ...
6
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1); void _case() { int z, n, o; string a; cin >> n >> a; o = a.find('1'); reverse(a.begin(), a.end()); z = a.find('1'); if (z < 0 and o < 0) cout << n << '\n'; else { cout << 2 * n - 2 * min(z, o) << '\n'; } } int main() { ...
2
#include <bits/stdc++.h> using namespace std; const int N = 100005, M = 1 << 17, mod = 998244353, inv2 = (mod + 1) / 2; int n, k, len, A[N], B[N], C[N]; long long a, b, c, f[M], mxt[M][4][5]; int getint() { char ch; while (!isdigit(ch = getchar())) ; int x = ch - 48; while (isdigit(ch = getchar())) x = x * ...
24
#include <bits/stdc++.h> using namespace std; int main() { string a = "102120210201021012"; int x, y; cin >> x >> y; int p = (x % 6) * 3; if (p == 0) { cout << a[15 + y] << endl; } else { cout << a[p - 1 - (2 - y)] << endl; } }
2
#include <bits/stdc++.h> using namespace std; int lo[100001]; int main(void) { long long ans, mi, ma; mi = ma = 0; bool f = false; int n; scanf("%d", &n); for (int i = 0; i < n; ++i) { scanf("%lld", &lo[i]); } sort(lo, lo + n); int mid = n / 2; for (int i = 0; i < n; ++i) { if (i < mid) ...
1
#include <bits/stdc++.h> using namespace std; long long int max(long long int a, long long int b) { if (a > b) { return a; } return b; } long long int gcd(long long int a, long long int b) { if (a == 0) { return b; } return gcd(b % a, a); } long long int min(long long int a, long long int b) { if ...
9