solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10; int vis[maxn]; int d[maxn]; vector<int> mp[maxn]; vector<int> tpath, rpath; void dfs(int s) { for (int i = 0; i < mp[s].size(); i++) { int to = mp[s][i]; if (vis[to] || d[to] > 1) continue; vis[to] = 1; tpath.push_back(to); d...
7
#include <bits/stdc++.h> using std::min; const int MAXN = 305; const int MOD = 1000000007; int N, A[MAXN], size[MAXN], tot_s = 0, DP[MAXN][MAXN], C[MAXN][MAXN], Fac[MAXN]; bool grp[MAXN] = {0}; inline bool pfct_sq(long long x) { long long sqr = floor(sqrt(x + 0.5)); return sqr * sqr == x; } inline void updata(int& ...
17
#include <bits/stdc++.h> using namespace std; const long double EPS = 1e-10; const long long MOD = 1e9 + 7; const long long INF = 1e18; const long double PI = 3.1415926535897932384626433832795028841; map<string, int> ssol; void checkAdd(string vs) { if (ssol.find(vs) != ssol.end()) { return; } ssol[vs] = 1; }...
17
#include <bits/stdc++.h> using namespace std; const int mod = (int)1e9 + 7; const int inf = (int)1e9 + 123; const long long infl = (long long)1e18 + 123; const double eps = 1e-10; const int MAX_N = (int)3e5 + 123; int n; int dist[2005][2005]; long long ans[2005]; bool used[2005]; int main() { scanf("%d", &n); int m...
19
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1.0); const int INF = 0x3f3f3f3f; const int maxn = 1e5 + 50; int n, k, m; long long a[maxn]; string s[maxn]; map<string, long long> M; queue<string> Q; int main() { ios::sync_with_stdio(false); cin >> n >> k >> m; for (int i = 1; i <= n; i++) {...
4
#include <bits/stdc++.h> int main() { size_t t; std::cin >> t; while (t-- > 0) { std::string s; std::cin >> s; size_t suf0, suf1, pref0, pref1; suf0 = suf1 = pref0 = pref1 = 0; for (auto it : s) { suf0 += (it == '0'); suf1 += (it == '1'); } size_t ans = std::min(suf0, suf1)...
6
#include <bits/stdc++.h> using namespace std; const string exam = "z1w2e3"; string inttostr(int x) { string ans = ""; while (x) ans += char('0' + x % 10), x /= 10; reverse(ans.begin(), ans.end()); return ans; } int strtoint(const string &s) { int ans = 0; for (int i = 0; i < s.size(); i++) if ('a' <= s[...
14
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); int m, n, st[1005][1005], cnt = 0, pref[1005][1005]; cin >> n >> m; for (int i = 0; i < n + 1; i++) { pref[i][0] = 0; } for (int i = 0; i < m + 1; i++) { pref[0][i] = 0; } for (int i = 1; i <= n; i++) { f...
4
#include <bits/stdc++.h> long long gcd(long long a, long long b) { if (b == 0) return a; return gcd(b, a % b); } long long lcm(long long a, long long b) { return a * b / gcd(a, b); } using namespace std; int main() { long long a, b; cin >> a >> b; long long lc = lcm(a, b); long long DashaFreq = (lc / a) - 1...
7
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; int head[N]; struct Edge { int next, to, len; } ed[N * 2]; int ecnt; inline void addedge(int u, int v, int l) { ed[ecnt].next = head[u]; ed[ecnt].to = v; ed[ecnt].len = l; head[u] = ecnt++; } long long h1[N], h2[N]; int id[N]; void dfs1(int ...
20
#include <bits/stdc++.h> using namespace std; ifstream in("input.txt"); ofstream out("output.txt"); ; long long n, k; vector<long long> vec; void input() {} void init() { input(); } unordered_map<long long, long long> mp; void solve() {} signed main() { string s; cin >> s; long long sz = s.size(); long long cur...
4
#include <bits/stdc++.h> using namespace std; void stop() {} void fast() { std::ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); } long long gcd(long long a, long long b) { return !b ? a : gcd(b, a % b); } long long lcm(long long a, long long b) { return (a / gcd(a, b)) * b; } int dx[] = {0, 0, 1, -1,...
9
#include <bits/stdc++.h> using namespace std; const int N = 201010; int main() { ios_base::sync_with_stdio(0); int test; cin >> test; while (test--) { int n, a, b; cin >> a >> b >> n; int f[3] = {a, b, a ^ b}; cout << f[n % 3] << endl; } return 0; }
1
#include <bits/stdc++.h> int main() { int n, v, i, sum = 0; scanf("%d%d", &n, &v); int a[n], b[n]; float c[n], ans, x1, x2; for (i = 0; i < n; i++) { scanf("%d", &a[i]); sum = sum + a[i]; } for (i = 0; i < n; i++) scanf("%d", &b[i]); for (i = 0; i < n; i++) c[i] = ((float)b[i]) / a[i]; x2 = c[...
6
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 100; vector<pair<int, int>> graph[maxn]; int n, k; long long dp[maxn][2]; void dfs(const int &u, const int &p) { if (graph[u].size() == 1 && p != -1) return; vector<pair<long long, int>> dpChildren; int idx = -1; for (const auto &[v, c] : grap...
13
#include <bits/stdc++.h> using namespace std; int main() { int n, h, a, b, k; int t1, f1, t2, f2; scanf("%d%d%d%d%d", &n, &h, &a, &b, &k); while (k--) { scanf("%d%d%d%d", &t1, &f1, &t2, &f2); if (t1 != t2) { int ff; long long res = 0; if (f1 > b) { ff = b; res += f1 - b...
2
#include <bits/stdc++.h> using namespace std; void next() { string a, b; cin >> a >> b; for (int i = 0; i < a.length(); ++i) { if (a[i] == b[i]) cout << "0"; else cout << "1"; } } int main() { next(); }
0
#include <bits/stdc++.h> using namespace std; const int maxN = 105; int n, k; int a[maxN][maxN]; char board[maxN][maxN]; void ReadInput() { cin >> n >> k; for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) cin >> board[i][j]; fill_n(&a[0][0], sizeof(a) / sizeof(a[0][0]), 0); } bool Ngang(int x, int y) { ...
5
#include <bits/stdc++.h> using ll = long long; using ull = unsigned long long; using vi = std::vector<int>; using vll = std::vector<ll>; using vull = std::vector<ull>; using pii = std::pair<int, int>; using pll = std::pair<ll, ll>; using namespace std; int lft[300005], rgt[300005]; int minsuffix[300005], maxsuffix[3000...
8
#include <bits/stdc++.h> int n, m; int main() { long long ans; int b, c, A, B, C, l; scanf("%d%d", &n, &m); n++; m++; ans = 0; for (c = m; c <= n >> 1; c++) { C = (n * n - n * c + c * c) << 1; A = (n << 1) - c; for (b = n - m; b >= m; b--) { B = b * (n + c); l = (C - B) / (A - b); ...
19
#include <bits/stdc++.h> using namespace std; string s; int main() { int t; cin >> t; while (t--) { cin >> s; int lastR = 0; int maxDist = 0; int n = s.length(); for (int i = 0; i < n; i++) { if (s[i] == 'R') { maxDist = max(maxDist, i + 1 - lastR); lastR = i + 1; }...
3
#include <bits/stdc++.h> using namespace std; using ll = long long; template <class T> using vec = vector<T>; template <class T> using vvec = vector<vec<T>>; template <class T> bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> bool chmax(T& a, T b) { if (a < b...
9
#include <bits/stdc++.h> using namespace std; const int N = 110, S = int(1e4 + 10); int a[N]; int dp[S][N]; bool pre[S][N]; int process[S][N]; int cnt[N]; int test; int main() { ios::sync_with_stdio(false); cin.tie(NULL); int n; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", &a[i]); cnt[a[...
13
#include <bits/stdc++.h> using namespace std; using lol = long long int; const int N = 300; const lol modcon = 1000000007, mod = 998244353, hval = 31, inf = 2 * 1e9 + 5; const double eps = 1e-7; void recur(vector<int> &z, vector<int> &v, int q) { if (q == 0) return; int k = distance(v.begin(), max_element(v.begin()...
10
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const int mod = 1e9 + 7; const int N = 2e5 + 10; long long A; string B, C; string to_roman(int x) { string I[] = {"", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX"}; string X[] = {"", "X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX",...
12
#include <bits/stdc++.h> inline int n_black(int n, int m) { return (n * m + 1) >> 1; } int main(void) { int n, m, x; std::cin >> n >> m >> x; x = (x << 1) - 1; if (std::min(n, m) < x) { std::cout << "0\n"; } else { int answer = n_black(n - x + 1, m - x + 1); if (std::min(n, m) >= x + 2) { an...
8
#include <bits/stdc++.h> using namespace std; struct Query { int id, l, r, solution; Query() {} void olvas(int i) { id = i; cin >> l >> r; l--; r--; } const bool operator<(Query masik) const { return r < masik.r; } }; const int maxn = 500005; vector<Query> task; int n, q; int a[maxn], f[maxn];...
16
#include <bits/stdc++.h> using namespace std; const int kMaxR = 505, kMaxN = 1e5 + 5, kInf = 0x3f3f3f3f; int r, n, X[kMaxN], Y[kMaxN], T[kMaxN]; int f[kMaxN]; int main() { scanf("%d %d", &r, &n); for (int i = 1; i <= n; ++i) { scanf("%d %d %d", T + i, X + i, Y + i); } int res = 0, cur = 0, ans = 0; fill(f...
12
#include <bits/stdc++.h> using namespace std; const long double eps = 1e-16; const int MOD = 1000000007; const long long INF = (long long)1e9 * 500; template <typename T> vector<T> readVector0(int n) { vector<T> res(n); for (int i = 0; i < n; i++) cin >> res[i]; return res; } template <typename T> vector<T> readV...
17
#include <bits/stdc++.h> using namespace std; long long int maxN = 1000000000000000000; long long int res[100001]; long long int n; long long int gcd(long long int a, long long int b) { if (b == 0) return a; return gcd(b, a % b); } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ; int t; t =...
8
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[n]; int total = 0; for (int i = 0; i < n; i++) { cin >> a[i]; total = total + a[i]; } int sum = 0; total = total / 2; sort(a, a + n); int c = 0; for (int i = n - 1; i >= 0; i--) { sum = sum + a[i]; c+...
1
#include <bits/stdc++.h> using namespace std; int a[3][6]; int sum[1000]; int main() { int n; scanf("%d", &n); for (int i = 0; i < n; i++) { for (int j = 0; j < 6; j++) { scanf("%d", &a[i][j]); sum[a[i][j]]++; } } for (int k = 0; k < n; k++) { for (int i = 0; i < 6; i++) { for (i...
5
#include <bits/stdc++.h> using namespace std; struct Q { int l, r, id; bool operator<(const Q& b) const { return r < b.r; } } b[200010]; struct node { int mi, num, lazy, sum; long long ans; } tree[200010 << 2]; long long res[200010]; int n, q, top1, top2, a[200010], stk1[200010], stk2[200010]; void up(int i) { ...
22
#include <bits/stdc++.h> using namespace std; typedef long long int lld; typedef pair<int,int> pi; typedef pair<lld,lld> pl; typedef pair<int,lld> pil; typedef pair<lld,int> pli; typedef vector<int> vit; typedef vector<vit> vitt; typedef vector<lld> vlt; typedef vector<vlt> vltt; typedef vector<pi> vpit; typedef vector...
13
#include <bits/stdc++.h> using namespace std; int main() { string s, t; getline(cin, s); for (int i = 0; i < s.size(); i++) { if (s[i] == ' ') s.erase(i, 1); } for (int i = 0; i < s.size(); i++) { if (s[i] == ' ') s.erase(i, 1); } for (int i = 0; i < s.size(); i++) { if (s[i] == ' ') s.erase(i...
0
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 5; const int mod = 1000000007; long long qp(long long a, long long n) { long long res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } struct mint { int n; mint(int n_ = 0) : n(n_) ...
12
#include <bits/stdc++.h> using namespace std; const int N = 110; int dp[N][N][N], n, m, k, p, c[N][N], fac[N]; inline int dfs(int i, int d, int k) { if (i < 0) return 0; if (~dp[i][d][k]) return dp[i][d][k]; if (d == m) return 0; int &g = dp[i][d][k]; g = 0; for (int j = 0; j <= (i - 1) / 2; ++j) for (i...
18
#include <bits/stdc++.h> using namespace std; int a[2005][2005]; int b[10005]; char res[2000055]; int main() { int ch, x; int n; int cnt = 0; scanf("%d", &n); for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { cin >> a[i][j]; } if (a[i][i] == 1) { cnt++; } } for (int i...
8
#include <bits/stdc++.h> using namespace std; long long ans[54322]; int main() { ans[3] = 1, ans[4] = 4; int n; long long c = 1; for (long long i = 5; i <= 54321; i++) { ans[i] = i * (c + 1) - c; c++; } while (~scanf("%d", &n)) { cout << ans[n] << endl; } return 0; }
3
#include <bits/stdc++.h> using namespace std; const int MAXN = 2005, MOD = 998244353; int f[MAXN][MAXN], mat[MAXN][MAXN], g[MAXN], h[MAXN], fac[MAXN], n; int cnt[MAXN], bit1[MAXN], bit2[MAXN]; void add(int *bit, int x) { for (; x <= n; x += x & -x) ++bit[x]; } int sum(int *bit, int x) { int res = 0; for (; x; x -...
21
#include <bits/stdc++.h> using namespace std; int main() { float l, d, v, g, r, t1, t2, temp; cin >> l >> d >> v >> g >> r; t1 = d / v; int count = 0; while (t1 >= g + r) { t1 -= (g + r); count++; } if (t1 < g) { t1 = t1 + count * (g + r); } else { t1 = (count + 1) * (g + r); } t2 = ...
7
#include <bits/stdc++.h> using namespace std; int n, m; int pref[1 << 20]; int a[50013], b[50013]; int dp[50013]; int l[5013], r[5013]; int ans[5013]; int main() { pref[0] = 0; for (int i = 1; i < (1 << 20); i++) pref[i] = pref[i - 1] ^ i; scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) { scanf("%d", &a...
20
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") const int N = 1e5 + 5; vector<int> g[N]; int vis[N][2], pre[N][2], col[N]; bool cyc(int u) { col[u] = 1; for (int v : g[u]) { if (col[v] == 1) { return 1; } if (col[v] == 0) { if (c...
13
#include <bits/stdc++.h> using namespace std; int n; string wzor; string s; bool check() { int j = 0; for (int i = 0; i < wzor.size(); i++) { if (wzor[i] == 'H') { if (s[j] != 'H') return 0; j++; } else { if (n - wzor.size() < j) return 0; for (int u = 0; u < wzor.size(); u++) { ...
17
#include <bits/stdc++.h> using namespace std; const int oo = 0x3f3f3f3f; const int MAX_N = 1000005; const int Mod = 1000000007; int N, Ones, Twos, DP[MAX_N], Solution; void Solve() { Solution = 1; for (; Twos > 0; --Twos, --N) Solution = (1LL * Solution * N) % Mod; DP[0] = 1; for (int i = 1; i <= N; ++i) { ...
15
#include <bits/stdc++.h> long long INF = 1e9 + 7; long double eps = 1e-9; using namespace std; bool comp(int a, int b) { return a > b; } class compare { public: template <class T> bool operator()(T a, T b) { return comp(a, b); } }; char *string_to_char(string temp) { char *ans = new char[temp.length() + 1]...
8
#include <bits/stdc++.h> using namespace std; long long f(long long n) { long long k = ceil(sqrt(n)); for (long long i = k; i; i--) { if (n % i == 0) { return i; } } } long long e(long long n) { long long k = ceil(cbrt(n)), mn = 1e12, x, x1; for (long long i = k; i; i--) { if (n % i == 0) { ...
8
#include <bits/stdc++.h> using namespace std; const int N = 2222; struct node { int val, cnt1, cnt2; node(int e, int x, int y) { val = e; cnt1 = x; cnt2 = y; } node() { val = cnt1 = cnt2 = 0; } }; node operator+(const node &x, const node &y) { node sum; sum.cnt1 = x.cnt1 + y.cnt1; sum.cnt2 = x...
10
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; int A[109], B[109]; for (int i = 0; i < n; i++) cin >> A[i]; sort(A, A + n); int l = 0, i; for (i = n - 1; i >= 0; i--) { l++; if (l == k) break; } cout << A[i]; return 0; }
1
#include <bits/stdc++.h> using namespace std; long long arr[2000000] = {0}, vis[300000] = {0}; vector<long long> vec[300000]; string str; long long mod = 1000000007; map<long long, long long> mp; long long fac(long long n) { long long i, prod = 1; for (i = 1; i <= n; i++) prod = ((i % mod) * (prod % mod)) % mod; ...
9
// Problem: B. Replace and Keep Sorted // Contest: Codeforces - Codeforces Round #701 (Div. 2) // URL: https://codeforces.com/contest/1485/problem/B // Memory Limit: 256 MB // Time Limit: 2000 ms // // Powered by CP Editor (https://cpeditor.org) #include <algorithm> #include <bitset> #include <cassert> #include <chron...
4
#include <bits/stdc++.h> using namespace std; long long int n, m; bool visited[1000000] = {false}; long long int BFS(long long int n, long long int m) { queue<pair<long long int, long long int> > q1; q1.push(make_pair(0, n)); visited[n] = true; while (q1.size() > 0) { long long int x = q1.front().second; ...
6
#include <bits/stdc++.h> using namespace std; using ll = long long; bool like(int a, int b) { return a <= b && 2 * a >= b; } int main() { int v1, v2, v3, vm; cin >> v1 >> v2 >> v3 >> vm; v1 *= 2; v2 *= 2; v3 = max(v3, 2 * min(v3, vm)); if (!like(vm, v1) && !like(vm, v2) && like(vm, v3)) { printf("%d\n%d...
5
#include <bits/stdc++.h> using namespace std; const int maxn = 2e6 + 10; int n, k, nxt[maxn], to[maxn], hd[maxn], tot = 0, f[maxn], d[maxn]; std::set<pair<int, int>> S; inline void add(int u, int v) { nxt[++tot] = hd[u]; to[tot] = v; hd[u] = tot; return; } inline void dfs(int u, int fa, int dst) { d[u] = dst;...
13
#include <bits/stdc++.h> using namespace std; int p[200010], fa[200010], dep[200010], a[200010]; int id[200010], num[200010], tot; vector<int> son[200010]; struct Node { int x; Node operator=(const int &X) { x = X; return *this; } bool operator<(const Node &X) const { return dep[x] < dep[X.x]; } } f[400...
21
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int u = 0, l = 0, d = 0; string s; cin >> s; for (int i = 0; i < int(s.size()); i++) { if (s[i] > 96 && s[i] < 123) u = 1; if (s[i] > 64 && s[i] < 91) l = 1; if (s[i] > 47 && s[i] < 58) d = 1; } i...
0
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 10, mod = 1e9 + 7; long long n, T, ans; long long t[N], pre[N], p[N]; long long fac[N], inv[N]; long long qpow(long long a, long long b) { long long ret = 1; for (; b; b >>= 1) { if (b & 1) ret = ret * a % mod; a = a * a % mod; } return r...
16
#include <bits/stdc++.h> using namespace std; vector<int> p[1010]; vector<int> q[1010]; int a[1010], b[1010], vis[1010]; int s[1010], n, m, w; void dfs(int x, int y) { int i, j, k; k = p[x].size(); for (i = 0; i < k; i++) { j = p[x][i]; if (vis[j] == 0) { vis[j] = y; dfs(j, y); } } } int...
8
#include <bits/stdc++.h> using namespace std; int main() { long long n, m, i, c; cin >> n >> m; long long x[n]; c = 0; for (i = 0; i < n; i++) { cin >> x[i]; if (x[i] > m) c++; } cout << c + n << endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 10; int cnt = 0; long long p[maxn], k[maxn]; int main() { long long n, b; cin >> n >> b; long long s = sqrt(b); for (long long i = 2; i <= s; i++) { if (b % i == 0) { p[cnt] = i; while (b && b % i == 0) k[cnt]++, b /= i; ...
9
#include <bits/stdc++.h> using namespace std; const int maxn = 100005; long long in[maxn]; long long out[maxn]; long long gx[maxn]; vector<int> e[maxn]; int main() { int n, m; scanf("%d %d", &n, &m); for (int i = 0; i < m; i++) { int x, y; scanf("%d %d", &x, &y); if (x < y) swap(x, y); out[x]++; ...
16
#include <bits/stdc++.h> using namespace std; int cx[51], cy[51]; int main() { ios::sync_with_stdio(0); cin.tie(0); vector<pair<int, int> > v; int n; cin >> n; for (int i = 0; i != 4 * n + 1; ++i) { int x, y; cin >> x >> y; cx[x]++; cy[y]++; v.push_back({x, y}); } int x1 = 51, x2 = -...
8
#include <bits/stdc++.h> using namespace std; int grundy(int heap_size, int k) { if (k % 2 == 0) { if (heap_size <= 2) return heap_size; else return 1 - (heap_size % 2); } else { if (heap_size < 4) return heap_size % 2; else if (heap_size >= 4 && heap_size % 2 != 0) return 0;...
14
#include <bits/stdc++.h> using namespace std; const int N = 4005; int n, dp[N][80][80][2], a[N]; int calc(int l, int diff, int prev, bool turn) { int r = n - l + 1 - diff; if (turn) diff += 80; int &ret = dp[l][diff][prev][turn]; if (turn) diff -= 80; if (ret != -1) return ret; if (r - l + 1 < prev) return ...
17
#include <bits/stdc++.h> using namespace std; string s[] = {"vaporeon", "jolteon", "flareon", "espeon", "umbreon", "leafeon", "glaceon", "sylveon"}; int main() { int n; string str; bool A[8]; for (int i = 0; i < 8; ++i) { A[i] = true; } cin >> n; cin >> str; if (n == 8) { cout << ...
2
#include <bits/stdc++.h> using namespace std; void eraseDups(vector<int>& a) { a.erase(unique(a.begin(), a.end()), a.end()); } int strToInt(string& a) { stringstream x(a); int b; x >> b; return b; } int bitCnt(int a) { bitset<64> b(a); return b.count(); } int bitCnt(string a) { bitset<64> b(a); return b...
14
#include <bits/stdc++.h> using namespace std; string s[100005]; int p[100005]; auto cmp = [](int x, int y) { return s[x] > s[y]; }; priority_queue<int, vector<int>, decltype(cmp)> q(cmp); string ss; int k; int main() { cin >> ss >> k; int len = ss.size(); for (int i = 0; i < len; ++i) { s[i] = ss[i]; p[i]...
13
#include <bits/stdc++.h> using namespace std; int Query(vector<int> s, vector<int> t, int v) { cout << s.size() << endl; for (int i : s) cout << i << ' '; cout << endl << t.size() << endl; for (int i : t) cout << i << ' '; cout << endl << v << endl; cin >> v; return v; } vector<int> Cut(vector<int> a, int...
23
#include <bits/stdc++.h> using namespace std; long long d[100003], sum[403], shelf[403]; int n, m; int main() { cin >> n >> m; for (int i = 0; i < n; i++) { long long x; int t; cin >> t; for (int j = 1; j <= t; j++) { cin >> x; sum[j] = ((j == 1) ? 0LL : sum[j - 1]) + x; } memset...
11
#include <bits/stdc++.h> using namespace std; const int ms = 4e5 + 5, inf = 0x3f3f3f3f; map<int, int> tipo; map<int, int> pos; int inicioIdx[ms], sz[ms]; int seg[2 * ms], lazy[2 * ms]; int ciclo[ms], posicaoNoCiclo[ms]; int n; int h; int *t, *d; void calc(int p, int k) { if (d[p] == -1) t[p] = max(t[p << 1], t[p ...
11
#include <bits/stdc++.h> using namespace std; bool comp(unsigned long long x, unsigned long long y) { return x > y; } int dx[] = {0, 0, 1, -1, 1, 1, -1, -1}; int dy[] = {1, -1, 0, 0, -1, 1, 1, -1}; long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } long long mod = 1000000000 + 7; void solveA() { ...
3
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:102400000,102400000") template <class T> inline void gmax(T &a, T b) { if (b > a) a = b; } template <class T> inline void gmin(T &a, T b) { if (b < a) a = b; } using namespace std; const int N = 2e5 + 10, M = 2e6 + 10, Z = 1e9 + 7, maxint = 2147483647, ...
11
#include <bits/stdc++.h> using namespace std; vector<int> ans; int pod[27]; int main() { long long n; int cnt = 0; string s; cin >> n; cin >> s; if (s.size() > 26) { cout << -1; return 0; } for (int i = 0; i < s.size(); i++) { pod[int(s[i] - 'a')]++; } for (int i = 0; i < 26; i++) { ...
2
#include <bits/stdc++.h> using namespace std; long long n, k; int arr[100010]; long long ans = 0; long long hun = 0, cop, total; int main() { scanf("%d%d", &n, &k); cop = k; total = n * 100; for (int i = 0; i < n; i++) { scanf("%d", &arr[i]); hun += arr[i]; ans += (arr[i] / 10); arr[i] %= 10; ...
6
// Exported by Exporter.exe // Included from g.cpp // Compile flags -Wall -Wextra -Wshadow -D_GLIBCXX_ASSERTIONS -DDEBUG -ggdb3 -fmax-errors=2 #include <bits/stdc++.h> using namespace std; #define PB push_back #define F first #define S second #define MP make_pair #define MTP make_tuple typedef long long int ll; const...
23
#include <bits/stdc++.h> using namespace std; class NumArray { public: NumArray(vector<int> &nums) : nums_(nums) { bit_ = vector<int>(nums_.size() + 1); for (int i = 1; i < bit_.size(); ++i) { bit_[i] = nums[i - 1] + bit_[i - 1]; } for (int i = bit_.size() - 1; i >= 1; --i) { int last_i =...
9
#include <bits/stdc++.h> using namespace std; int main() { int q; cin >> q; long long int x, y; while (q--) { scanf("%lld%lld", &x, &y); long long int c = (cbrt(x * y)); long long int X = x / c, Y = y / c; if (X * X * Y == x && Y * Y * X == y) printf("Yes\n"); else printf("No\n")...
9
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 10; long long n, x[MAXN], y[MAXN]; vector<long long> adj[MAXN]; long long dx[] = {1, -1, 0, 0}; long long dy[] = {0, 0, -1, 1}; void precalc() {} bool read() { if (scanf("%lld", &n) < 1) { return false; } for (long long i = 1; i < n; i++) { ...
12
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; vector<pair<int, int>> v; int main() { ios_base::sync_with_stdio(0), ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); ; int n, x, d; cin >> n; for (int i = 1; i <= n; ++i) { cin >> x >> d; v.push_back({x, d}); } for (int i...
2
#include <bits/stdc++.h> using namespace std; long long maxx = 1e15; template <class T> istream &operator>>(istream &in, vector<T> &v) { for (auto &x : v) in >> x; return in; } template <class T> ostream &operator<<(ostream &out, vector<T> &v) { for (auto x : v) out << x << ' '; return out; } bool sortbyfir(con...
6
#include <bits/stdc++.h> using namespace std; int n, m; int E[411][411]; int V[411]; int bfs(int state) { memset(V, 0, sizeof(V)); int ans = -1; queue<pair<int, int> > q; q.push({1, 0}); while (q.size() > 0) { pair<int, int> pt = q.front(); q.pop(); int node = pt.first; int t0 = pt.second + 1;...
8
#include <bits/stdc++.h> using namespace std; inline int in() { int x; scanf("%d", &x); return x; } const long long N = 1200021; int cntP[N], isP[N]; int main() { for (int i = 2; i < N; i++) if (!isP[i]) for (int j = i; j < N; j += i) isP[j] = i; int n = in(), k = in(); for (int i = 0; i < n; i++)...
10
#include <bits/stdc++.h> int main() { int n; scanf("%d", &n); if (n == 1) { puts("2"); } else if (n == 2) { puts("3"); } else if (n == 3) { puts("1"); } else if (n == 4) { puts("2"); } else if (n == 5) { puts("1"); } }
5
#include <bits/stdc++.h> using namespace std; const int N = 2020; int n, a[N]; bool vis[N]; double p[N][N], f[N], g[N], pr[N]; int read() { int x = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = x * 10 + c...
19
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 5; int T, n, tot, du[maxn], vis[maxn], id[maxn]; struct yz { int y, z, id; }; struct delta { int x, y, z; } a[maxn]; map<int, vector<yz> > mp; void Swap(int& x, int& y, int& z) { if (x > y) swap(x, y); if (y > z) swap(y, z); if (x > y) swap(...
16
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t; cin >> t; while (t--) { long long n, l, r; cin >> n >> l >> r; long long idx = 1; bool p = false; bool end = false; for (long long i = 1; i <= n - 1; i++) { ...
10
#include <bits/stdc++.h> using namespace std; bool check(const vector<int>& arr, const int m, const int k, int p) { for (int i = m - 1; i >= 0; i -= k) { p -= arr[i]; if (p < 0) { return false; } } return true; } int main() { int t; cin >> t; vector<int> arr; while (t--) { int n, p, ...
6
#include <bits/stdc++.h> using namespace std; vector<int> ans; int a[100009]; int main() { int n; scanf("%d", &n); for (int i = int(0); i <= int(n - 1); i++) { scanf("%d", &a[i]); } for (int i = 31; i >= 0; i--) { int val = (1 << 31) - 1; for (int j = int(0); j <= int(n - 1); j++) { if (a[j]...
10
#include <bits/stdc++.h> using namespace std; bool compare(long long x, long long y) { return x > y; } long long isprime(long long n) { if (n == 1) return 0; else if (n == 2) return 1; else { for (long long i = 2; i <= sqrt(n); i++) { if (n % i == 0) return 0; } return 1; } } vector<lo...
4
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; cin >> n; vector<pair<int, int>> v; for (int i = 0; i < n; i++) { int a, b; cin >> a >> b; v.push_back({a, b}); } sort(v.begin(), v.end()); int cur = v[0].second; ...
7
#include <bits/stdc++.h> using namespace std; int d[1 << 16], s[1 << 16]; vector<pair<int, int> > res; int resn; vector<int> c; int main() { int n; cin >> n; for (int(i) = 0; i < (n); ++i) { int x, y; cin >> d[i] >> s[i]; } for (int(i) = 0; i < (n); ++i) { if (d[i] == 1) c.push_back(i); } whil...
7
#include <bits/stdc++.h> using namespace std; const int MAX = 1e5 + 1; int n; bool is = true, vis[MAX]; vector<int> arr[MAX]; pair<int, int> ans[MAX], delta[4] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}}; void dfs(int v, int len, int x, int y, int direction) { vis[v] = true; ans[v].first = x; ans[v].second = y; int pn...
12
#include <queue> #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #define pii pair <int , int> #define mp make_pair #define fs first #define sc second using namespace std; typedef long long LL; template <typename T> void read(T &x) { T f=1;x=0;char s=getchar(); while(s<'0'||s>'9') {if(s=...
19
#include <bits/stdc++.h> using namespace std; int n, sum, a[26 * 2], w[2][26]; bitset<26 * 50000> f[26 * 2][26]; int main() { scanf("%d", &n); for (int i = 1; i <= n * 2; ++i) scanf("%d", a + i); sort(a + 1, a + n * 2 + 1); w[0][1] = a[1]; w[1][n] = a[2]; f[2][0][0] = 1; for (int i = 3; i <= n * 2; ++i) {...
23
#include <bits/stdc++.h> using namespace std; const int inf = 1039714778; template <typename T> inline void chmin(T &x, const T &b) { x = (x < b ? x : b); } template <typename T> inline void chmax(T &x, const T &b) { x = (x > b ? x : b); } int n; long long a[5005]; int dp[5005]; int main() { cin >> n; for (int ...
16
#include <bits/stdc++.h> using namespace std; void solve() { float x, y; cin >> x >> y; double dis = sqrt(x * x + y * y); if ((x > 0 && y > 0) || (x < 0 && y < 0)) { long long a = floor(dis); if (a == dis) { cout << "black"; return; } if (a % 2) cout << "white"; else ...
5
#include <bits/stdc++.h> using namespace std; int n, x[210000], y[210000], tx[210000], a[210000]; bool used[210000]; vector<int> ve[210000]; bool cmp(int a, int b) { return x[a] < x[b]; } void add(int x, int y) { ve[x].push_back(y); } void dfs(int k, int c) { used[k] = true; a[k] = c; for (int i = 0; i < (int)ve[...
8
#include <bits/stdc++.h> using namespace std; bool a[510][510]; int seq[510], seq0[510], seq1[510], _R[510]; int llen[510], L[510], R[510], S[510], T[510]; char s[510]; bool b[510], c[510]; int n; inline void fail() { printf("NO\n"); exit(0); } void update() { int i, j; for (i = 1; i <= n; i++) { L[i] = n +...
22
#include <bits/stdc++.h> using namespace std; int done[1005] = {0}; vector<long long int> graph[1005]; pair<long long int, long long int> dfs(long long int src) { long long int n = 0, m = 0; stack<long long int> s; s.push(src); while (!s.empty()) { long long int x = s.top(); s.pop(); if (done[x]) co...
7
#include <bits/stdc++.h> using namespace std; struct node { int id; int v; } p[1005]; bool comp(node a, node b) { return a.v < b.v; } int main() { int n; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", &p[i].v); p[i].id = i + 1; } sort(p, p + n, comp); int count = 0; for (int i = 1;...
5