solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
vector<int> w[200020];
int a, b, ar[200020], bas[200020], son[200020], tmp, tek[200020], ger[200020],
ters[200020], segment[200020 * 5][2];
void dfs(int n, int der) {
bas[n] = ++tmp;
tek[n] = der % 2;
for (int i = 0; i < w[n].size(); i++)
if (!bas[w[n][i]]) df... | 12 |
#include <bits/stdc++.h>
using namespace std;
vector<int> pat[500000];
vector<int> rev[500000];
vector<bool> flag[500000];
int pt[500000];
void adde(int a, int b) {
pat[a].push_back(b);
flag[a].push_back(false);
}
vector<int> euler;
void calceuler(int node) {
for (;;) {
if (pt[node] == pat[node].size()) break... | 23 |
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>
#include <ctime>
using namespace std;
const int maxN = 601000;
//const int maxN = 200;
int t[4 * maxN];
int d[4 * maxN];
void build(vector... | 15 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int i;
long long int n;
cin >> n;
if (n % 2 == 0) {
while (n % 2 == 0 && (n / 2) % 2 == 0) {
n = n / 2;
}
}
for (i = 3; i <= sqrt(n); i += 2) {
if (n % i == 0) {
while (n % i == 0 && (n / i) % i == 0) {
n = n / i;
... | 5 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
string s;
cin >> s;
string aux = "hello";
int p = 0;
for (int i = 0; i < 5; i++) {
while (p < s.size() && s[p] != aux[i]) p++;
if (p >= s.size()) {
cout << "NO\n";
return;
}
p++;
}
cout << "YES\n";
}
int main() {
io... | 2 |
#include <bits/stdc++.h>
using namespace std;
int q[211111], q1, q2;
int dp[211111][2], cnt[211111][2];
int n;
int main() {
ios::sync_with_stdio(false);
cin >> n;
int sz;
cin >> sz;
vector<int> e[2];
e[0].resize(sz);
for (int i = 0; i < sz; i++) cin >> e[0][i];
cin >> sz;
e[1].resize(sz);
for (int i... | 12 |
#include <bits/stdc++.h>
using namespace std;
int dsu[100005], sz[100005];
int get(int v) { return dsu[v] == v ? v : dsu[v] = get(dsu[v]); }
bool un(int v, int u) {
v = get(v);
u = get(u);
if (v != u) {
if (sz[v] > sz[u]) swap(v, u);
dsu[v] = u;
sz[u] += sz[v];
return 1;
}
return 0;
}
int n, m... | 11 |
#include <bits/stdc++.h>
using namespace std;
bool check;
long long dem;
long long st;
long long kt;
long long d[500010];
long long dd[500010];
vector<long long> a[500010];
long long n;
long long cont;
long long res = 1;
long long p0w[500010];
long long base = 1e9 + 7;
void io() {
ios_base::sync_with_stdio(false);
... | 11 |
#include <bits/stdc++.h>
using namespace std;
vector<int> used;
vector<int> ord;
vector<vector<int>> dir;
void dfs(int node) {
used[node] = 1;
for (auto i : dir[node]) {
if (!used[i]) dfs(i);
}
ord.push_back(node);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
ci... | 12 |
#include <bits/stdc++.h>
using namespace std;
long long int me(long long int x, long long int n) {
if (n == 0)
return 1;
else if (n % 2 == 0)
return me((x * x) % 1000000007, n / 2);
else
return (x * me((x * x) % 1000000007, (n - 1) / 2)) % 1000000007;
}
bool IsPrime(long long int n) {
if (n <= 1) re... | 8 |
#include <bits/stdc++.h>
using namespace std;
int n;
vector<vector<pair<int, int>>> graph(101);
int mask[101];
int moving(int start, int move, int sum) {
if (mask[graph[move][0].first] == 0) {
mask[graph[move][0].first] = 1;
return moving(start, graph[move][0].first, sum + graph[move][0].second);
} else if ... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 5;
int sum[N], num[N], n, c, a[N];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> c;
for (int i = 1; i <= n; i++) {
cin >> a[i];
sum[i] = sum[i - 1] + (a[i] == c);
}
int ans = 0;
for (int i = 1; i <= n; i++) {
... | 12 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n;
string s;
cin >> n >> s;
pair<int, int> cur = {0, 0};
map<pair<int, int>, int> arr;
arr[cur] = 0;
int l = -1, r = n;
for (int i = 0; i < n; i++) {
if (s[i] == 'L')
cur.first++;
else if (s[i] == 'R')
cur.first--;
... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
vector<string> s(3);
cin >> s[0] >> s[1] >> s[2];
if (s[0][0] != s[2][2] || s[0][1] != s[2][1] || s[0][2] != s[2][0] ||
s[1][0] != s[1][2] || s[1][2] != s[1][0])
cout << "NO";
else
cout << "YES";
return 0;
}
| 0 |
#include <bits/stdc++.h>
#pragma GCC optimize("no-stack-protector,Ofast")
using namespace std;
unsigned int seed = 880301;
int rnd() { return seed = (seed * 880301) ^ 7122; }
struct node {
node *l, *r;
int sz, val, pri;
int lz() { return l ? l->sz : 0; }
int rz() { return r ? r->sz : 0; }
void psz() { sz = lz... | 14 |
#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;
}
const int INF = (int)1E9 + 7;
const long double EPS = 1E-9;
const long double PI = 3.1415926535897932384626433832795;
const int N = 200000;
i... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
vector<int> v;
cin >> n >> k;
for (int i = 0; i < k; i++) v.push_back(i);
string s[n];
int c = n;
while (n--) cin >> s[n];
int ans = 1000000000;
do {
int x, mn = 1000000000, mx = -1;
for (int i = 0; i < c; i++) {
x = 0;... | 6 |
#include <bits/stdc++.h>
using namespace std;
int remainedGood[200005];
int remainedBad[200005];
int subarb[200005];
long long good, bad;
vector<pair<int, int>> graph[200005];
void dfs(int node, int father, int distance, int n) {
remainedGood[node] = remainedBad[node] = subarb[node] = 1;
for (auto x : graph[node]) ... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
char a[100100], s[100100];
scanf("%s%s", a, s);
int sa = strlen(a), ss = strlen(s);
bool all = true;
sort(s, s + ss, greater<char>());
int i = 0, j = 0;
while (i < sa && j < ss) {
if (a[i] < s[j]) {
swap(a[i], s[j]);
++i, ++j;
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int n, k, s[100005], L[100005], R[100005];
char a[100005];
bool flag1;
void prepare() {
L[1] = 1, R[n] = n;
for (int i = 2; i <= n; ++i) {
if (s[i] == s[i - 1])
L[i] = L[i - 1];
else
L[i] = i;
}
for (int i = n - 1; i >= 1; --i) {
if (s[i] == ... | 15 |
#include <bits/stdc++.h>
using namespace std;
bool gimme(long long x) {
while (x != 0) {
if (x % 10 == 8 || x % 10 == -8) {
return 1;
}
x = x / 10;
}
return 0;
}
int main() {
long long n, i = 1;
cin >> n;
while (gimme(n + i) == 0) {
i++;
}
cout << i;
return 0;
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
int m, l[103], r[103];
bool vis[103];
vector<int> v[103];
bool in(int x, int y) {
return ((l[y] < l[x] && l[x] < r[y]) || (l[y] < r[x] && r[x] < r[y]));
}
void dfs(int x) {
vis[x] = true;
for (int i = 0; i < v[x].size(); i++)
if (!vis[v[x][i]]) dfs(v[x][i]);
ret... | 7 |
#include <bits/stdc++.h>
using namespace std;
long long a[300005];
int u, l, x, y, z;
map<vector<vector<int>>, int> mp;
vector<vector<int>> v;
int mex(vector<int> v) {
int i;
for (i = 0; i < v.size(); i++) {
int ok = 1;
for (auto it : v)
if (i == it) ok = 0;
if (ok == 1) return i;
}
return i;
... | 17 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long y, n, k;
cin >> y >> k >> n;
long long x = 0;
long long y_;
long long temp = y % k;
if ((y - temp) % k == 0) {
y_ = y - temp;
y_ += k;
x = y_ - y;
} else {
y_ = y + tem... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long fac[1000001];
void powe(long long p) {
fac[0] = 1;
for (long long i = 1; i <= 1000000; i++) fac[i] = (fac[i - 1] * i) % p;
}
long long power(long long x, long long y, long long p) {
long long res = 1;
x = x % p;
while (y > 0) {
if (y & 1) res = (res ... | 6 |
#include <bits/stdc++.h>
using namespace std;
using namespace std;
int nos(int node, int n) {
int r = -1, l = -1, most = node;
while (most <= n) {
r++;
most = 2 * most + 1;
}
most = node;
while (most <= n) {
l++;
most = 2 * most;
}
return (1 << r + 1) - 1 + (l - r) * (n - most / 2 + 1);
}
... | 20 |
#include <bits/stdc++.h>
using namespace std;
vector<int> g[200005];
int len[200005];
int visited[200005];
vector<int> v;
int dfs(int node) {
v.push_back(node);
visited[node] = 1;
int ans = 1;
for (int i = 0; i < g[node].size(); i++) {
if (visited[g[node][i]] == 0) {
ans += dfs(g[node][i]);
}
}
... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b;
cin >> a >> b;
for (int x1 = -1; x1 > -a; x1--) {
int y1_sq = a * a - x1 * x1;
int y1 = sqrt(y1_sq);
if (y1 * y1 != y1_sq) continue;
for (int x2 = b - 1; x2 > 0; x2--) {
int y2_sq = b * b - x2 * x2;
int y2 = sqrt(y2_s... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 1999;
vector<vector<bool> > ar;
struct st {
int x, l, r, sum;
};
st my_f(int m) {
int y = (int)ar[0].size() / 2;
st ans;
ans.sum = ans.x = INF;
for (int i = 0; i < (int)ar.size(); ++i) {
for (int j = 0; j < (int)ar[i].size(); ++j) {
... | 7 |
#include <bits/stdc++.h>
using namespace std;
priority_queue<pair<int, int>, vector<pair<int, int> >,
greater<pair<int, int> > >
que;
stringstream ssin;
const long long LINF = 0x7fffffffffffffffll;
const int N = 4e5 + 5, M = 4e5 + 5, mod = 1e9 + 7, INF = 0x3f3f3f3f;
int n, m, rt, idx, flag;
int c[N];... | 10 |
#include <bits/stdc++.h>
using namespace std;
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<string> s(n);
vector<int> bal(n);
vector<int> mn(n);
vector<unordered_map<int, int>> get(n);
for (int i = 0; i < n; ++i) {
cin >> s[i];
int sum = 0;
int mnn =... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, d;
cin >> n >> d;
int m;
cin >> m;
for (int i = 0; i < m; i++) {
int x, y, flag = 0;
cin >> x >> y;
if ((y - x) <= d) flag++;
if ((x + y) >= d) flag++;
if ((x - y) <= d) f... | 3 |
#include <bits/stdc++.h>
using namespace std;
unsigned char cache[101][10001][2];
int main() {
ios_base::sync_with_stdio(false);
int rows, cols;
cin >> rows >> cols;
cin.ignore();
string* grid = new string[rows];
for (int i = 0; i < rows; i++) {
getline(cin, grid[rows - i - 1]);
}
int x = 0, y = row... | 12 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<int> c[5005], c1[5005];
void solve() {
cin >> n >> m;
for (int i = 0; i < m; i++) {
int u, v;
cin >> u >> v;
c[u].push_back(v);
}
int maxi = 0;
for (int i = 0; i < n; i++) {
maxi = max(maxi, int(c[i + 1].size()));
}
int ans = 0... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n, m;
cin >> n >> m;
long long a[n];
for (int i = 0; i < n; i++) cin >> a[i];
long long left_sum[n], right_sum[n];
left_sum[0] = 0;
long long count = 0;
for (int i = 1; i... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
pair<long long, long long> tree[4 * N];
long long a[N], dp[N];
void build(int node, int s, int e) {
if (s == e) {
tree[node] = {a[s], s};
return;
}
int md = (s + e) >> 1;
build(node << 1, s, md);
build((node << 1) + 1, md + 1, e);
... | 15 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
int a[2000005];
int b[2005];
int main() {
ios_base::sync_with_stdio(false);
int t;
cin >> t;
while (t--) {
cin >> n;
memset(b, 0, sizeof(b));
for (int i = 0; i < n; i++) {
cin >> a[i];
b[a[i]]++;
}
vector<int> v;
while (... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 26;
int n;
string s;
vector<pair<string, string> > ans;
set<string> name[maxn], snam[maxn];
int main() {
ios::sync_with_stdio(0);
cin >> n;
for (int i = 0; i < n; i++) {
cin >> s;
name[s[0] - 'A'].insert(s);
}
for (int i = 0; i < n; i++) {... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 110000;
const long double epsilon = 1e-7;
struct lem {
long double m, v;
int id;
inline bool operator<(const lem &l) const {
if (fabs(m - l.m) > epsilon) return m < l.m;
return v < l.v;
}
};
int n, k, h;
long double can[maxn];
lem data[maxn]... | 12 |
#include <bits/stdc++.h>
using namespace std;
int ispresent(vector<char> v, char a) {
for (std::vector<char>::iterator ir = v.begin(); ir != v.end(); ir++) {
if (*ir == a) return 1;
}
return 0;
}
int main() {
ios::sync_with_stdio(0), cin.tie(0);
string goo, s;
cin >> goo >> s;
int n;
cin >> n;
vec... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string x;
map<char, bool> vis;
long long res = 1;
int size = 10;
cin >> x;
for (char i = 'A'; i <= 'J'; i++) vis[i] = false;
for (int i = 0; i < x.size(); i++) {
if (x[i] == '?' && i != 0)
res *= 10;
else if (x[i] == '?' && i == 0)
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int mi = INT_MAX, ma = INT_MIN;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int T = 1;
while (T--) {
int n;
cin >> n;
int b[n], d[n];
for (int i = 0; i < n; ++i) {
cin >> b[i] >> d[i];
}
sort(b, b + n);
s... | 5 |
#include <bits/stdc++.h>
using namespace std;
int N = 26;
vector<vector<int> > g(N, vector<int>(N, 0));
vector<int> v;
queue<int> q;
int cycle = 0;
void dfs(int u) {
v[u] = 1;
for (int i = 0; i < N; ++i)
if (g[u][i]) {
if (!v[i]) dfs(i);
if (v[i] == 1) cycle = 1;
}
v[u] = 2;
q.push(u);
}
voi... | 8 |
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
long long x1, y1, x2, y2;
cin >> x1 >> y1 >> x2 >> y2;
long long x, y;
x = x2 - x1;
y = y2 - y1;
if (x == y && x > 0 && y > 0) {
cout << x1 << " " << y1 + y << " " << x1 + x << " " << y1;
} else if (x == y && x < 0 && y < 0)
cout << x2... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
long long ans = 0;
void add(long long &a, long long b) {
if (b < 0) b += MOD;
a = (a + b) % MOD;
ans += a;
if (ans >= MOD) ans -= MOD;
}
int main() {
int n, m;
cin >> n >> m;
if (m < n) swap(m, n);
long long a[n + 2][n + 1], b[n + 1]... | 16 |
#include <bits/stdc++.h>
using namespace std;
int n, m, cl, ce, v, q;
int e[100010], s[100010];
int main() {
cin >> n >> m >> cl >> ce >> v;
memset(e, 0, sizeof(e));
memset(s, 0, sizeof(s));
for (int i = 0; i < cl; i++) cin >> s[i];
for (int i = 0; i < ce; i++) cin >> e[i];
cin >> q;
while (q--) {
int... | 8 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long n, sum;
cin >> n >> sum;
vector<int> v;
long long a, b, tem1 = 0, tem2 = 0;
for (int i = 0; i < n; i++) {
cin >> a >> b;
tem1 += a;
tem2 += b;
v.push_back(abs(a - b));
}
int cnt = 0;
sort(v.begin(), v.end(), greater<l... | 3 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
string S, T;
cin >> S >> T;
int cnt[26] = {};
for (char c : S) cnt[c - 'a']++;
if (T != "abc" || cnt[0] == 0 || cnt[1] == 0 || cnt[2] == 0)
sort(S.begin(), S.end());
else {
map<char, int> m{{'b', 'c'}, {'c', 'b'}};
sort(S.begin(), S.en... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 70 + 3, M = (1 << 19) + 3;
long long MOD = 1e9 + 7;
int primes[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29,
31, 37, 41, 43, 47, 53, 59, 61, 67};
int freq[N], masks[N], oddity[N];
int mem[N][M];
long long dp(int x, int msk) {
if (!~x) return m... | 12 |
#include <bits/stdc++.h>
using namespace std;
inline long long read() {
long long res = 0;
char c;
bool zf = 0;
while (((c = getchar()) < '0' || c > '9') && c != '-')
;
if (c == '-')
zf = 1;
else
res = c - '0';
while ((c = getchar()) >= '0' && c <= '9')
res = (res << 3) + (res << 1) + c - ... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int V = 200100;
char s[V], t[V];
long long sl[V][26], sr[V][26];
int n;
int main() {
while (~scanf("%d", &n)) {
memset(sl, 0, sizeof(sl));
memset(sr, 0, sizeof(sr));
scanf("%s%s", s, t);
for (int i = 0; i < n; i++) {
for (int j = 0; j < 26; j++... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
cout << 2 * (n - 1) + 1 << ' ' << 2 << '\n' << 1 << ' ' << 2;
return 0;
}
| 6 |
#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1);
const long long INF = 1e13;
const int MAXN = 51;
long long dp[MAXN][MAXN][MAXN * 100];
int main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(0);
int n;
cin >> n;
vector<long long> a(n), b(n);
vector<pair<long long, long lon... | 17 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
T abs(T x) {
return x > 0 ? x : -x;
}
template <typename T>
T sqr(T x) {
return x * x;
}
template <typename T>
ostream &operator<<(ostream &s, const vector<T> &x) {
s << "[";
for (auto it : x) {
s << it << ", ";
}
s << "]";
return s;
... | 8 |
#include <bits/stdc++.h>
using namespace std;
struct point {
double x, y;
};
int t;
double cross(point a, point b, point c) {
return (a.x * b.y + b.x * c.y + c.x * a.y) -
(a.y * b.x + b.y * c.x + c.y * a.x);
}
bool can(point a, point b, point c) {
double a1, b1, c1, a2, b2, c2, xa, xb, xc, xd, ya, yb, yc... | 18 |
#include <bits/stdc++.h>
int main() {
int n, i, k = 0, arr[100000];
scanf("%d", &n);
for (i = 1; i <= n; i++) {
arr[k++] = 1;
while (k > 1 && arr[k - 1] == arr[k - 2]) {
arr[k - 2]++;
k--;
}
}
for (i = 0; i < k; i++) printf("%d ", arr[i]);
printf("\n");
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int n, k, unit, tot;
int be[(100005)], st[(100005)], en[(100005)], a[(100005)], sum[2055][2055],
f[(100005)], pre[(100005)], now[(100005)], lazy[(100005)], S[(100005)];
const int P = 998244353;
template <typename T>
void read(T& t) {
t = 0;
bool fl = true;
char p ... | 21 |
#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
int n, k, ans, ansi, a[N];
int main() {
int T;
scanf("%d", &T);
while (T--) {
scanf("%d%d", &n, &k), ++k, ansi = -1;
for (int i = 1; i <= n; ++i) scanf("%d", a + i);
for (int i = 1; i <= n - k + 1; ++i) {
int t = max((a[i] + a[i... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
int num = 0;
cin >> s;
int n = s.size();
for (int i = 0; i < n; i++) {
if (s[i] == 'a' || s[i] == 'e' || s[i] == 'i' || s[i] == 'o' ||
s[i] == 'u' || s[i] == '1' || s[i] == '3' || s[i] == '5' ||
s[i] == '7' || s[i] == '9'... | 0 |
#include <bits/stdc++.h>
using namespace std;
map<int, int> sum;
int main() {
long long ans = 0;
int n, x;
cin >> n;
while (n--) {
cin >> x;
ans += sum[-x];
sum[x]++;
}
cout << ans;
}
| 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6;
pair<int, int> pp[N + 2];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int d, n, m;
cin >> d >> n >> m;
for (int i = 1; i <= m; i++) cin >> pp[i].first >> pp[i].second;
sort(pp + 1, pp + m + 1);
deque<pair<int, int> > dq;
dq.push... | 14 |
#include <bits/stdc++.h>
using namespace std;
struct TP {
TP() {}
};
bool cmp(pair<int, pair<int, int>> a, pair<int, pair<int, int>> b) {
return abs(b.second.first - b.second.second) <
abs(a.second.first - a.second.second);
}
bool cmp2(pair<int, pair<int, int>> a, pair<int, pair<int, int>> b) {
return a.... | 7 |
#include <bits/stdc++.h>
using namespace std;
int M = 1e9;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, k;
cin >> n >> k;
map<int, int> min_amount;
while (n--) {
int a;
cin >> a;
int amount = a;
for (int i = 1; i <= k; ++i) {
int &value = min_amount[amount];
valu... | 11 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pll = pair<ll, ll>;
using vll = vector<ll>;
using vpll = vector<pll>;
using gr = vector<vll>;
using wgr = vector<vpll>;
struct d_ {
template <typename T>
d_ &operator,(const T &x) {
cerr << ' ' << x;
return *th... | 19 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int a[2 * n], b[n], c[n - 1];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
int min = 5000, x, y;
for (int i = 1; i < n; i++) {
if (abs(a[i] - a[i - 1]) < min) {
min = abs(a[i] - a[i - 1]);
x = i;
y = i - ... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
cin.sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
vector<int> a(n + 1, 0);
for (int i = 1; i <= n; i++) {
cin >> a[i];
a[i] += a[i - 1];
}
map<int, vector<pair<int, int> > > mp;
for (int i = 1; i <= n; i++) {
... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int N = 300010;
const long long INF = 1LL << 50;
map<int, int> mp;
int a[N];
int n;
vector<int> c;
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) scanf("%d", &a[i]);
long long ans = -INF;
int l, r;
for (int i = 0; i < n; i++)
for (int... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
;
long long n, m;
cin >> n >> m;
vector<long long> v(n);
for (int i = 0; i < n; ++i) cin >> v[i];
if (n > m) return cout << 0, 0;
long long a = 1;
for (int i = 0; i < n; ++i) {
for ... | 8 |
#include <bits/stdc++.h>
using namespace std;
struct node {
int ch[2];
};
int cnt = 0;
node nn[7000000];
void add(int a, int root, int d) {
if (d < 0) {
return;
}
bool isr = false;
if (a & (1 << d)) {
isr = true;
}
if (!nn[root].ch[isr]) {
cnt++;
nn[cnt].ch[1] = 0;
nn[cnt].ch[0] = 0;
... | 15 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n;
int *rw = new int[n];
int *rl = new int[n];
int *rh = new int[n];
for (int i = 0; i < n; i++) {
cin >> rw[i] >> rl[i] >> rh[i];
}
cin >> m;
int *a = new int[m];
int *b = new int[m];
int *c = new int[m];
for (int i... | 8 |
#include <bits/stdc++.h>
using namespace std;
const long long lt = 100005;
long long mod = 1000000007;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long n, m, q;
cin >> n >> m >> q;
vector<long long> a, b;
long long i, val;
for (i = 0; i < n; i++) {
cin >> val;
... | 13 |
#include <bits/stdc++.h>
using namespace std;
string decTotarnary(long long int n) {
long long int tarnaryNum[1000];
string s;
long long int i = 0;
while (n > 0) {
tarnaryNum[i] = n % 3;
n = n / 3;
i++;
}
for (long long int j = i - 1; j >= 0; j--) {
s += tarnaryNum[j] + '0';
}
return s;
... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 505;
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const double eps = 1e-6;
void solve() {
int n;
cin >> n;
vector<int> a(n);
for (int &i : a) cin >> i;
sort(a.begin(), a.end());
for (int i = 1; i <= n - 2; ++i) {
if (a[i - 1] + a[i]... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
char s[maxn];
int vis[55];
int main() {
cin >> s;
int len = strlen(s);
memset(vis, 0, sizeof(vis));
for (int i = 0; i < len; i++) {
vis[s[i] - 'A']++;
}
int m = 1111111;
m = min(m, vis['a' - 'A'] / 2);
m = min(m, vis['s' - 'A'])... | 2 |
#include <bits/stdc++.h>
using namespace std;
bool prime(int a) {
if (a == 2) {
return 1;
}
for (int i = 2; i * i <= a; ++i) {
if (a % i == 0) {
return 0;
}
}
return 1;
}
int main(int argc, char const *argv[]) {
long n;
cin >> n;
if (prime(n)) {
printf("1\n");
return 0;
} els... | 8 |
#include <bits/stdc++.h>
using namespace std;
int n;
int num[150000 + 5];
vector<int> vec;
set<pair<int, int> > S;
int check(int x) {
if (x == 1)
if (num[x] < num[x + 1]) return 1;
if (x == n) {
if (x % 2 == 0 && num[x] > num[x - 1]) return 1;
if (x % 2 && num[x] < num[x - 1]) return 1;
} else {
i... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int maxSum = 205, maxSet = 1 << 8, flag = 1 << 30, maxinf = 1 << 29;
int n, m, k, sum, dis[maxSum][maxSum], solDis[maxSum][maxSum],
dp[maxSum][maxSet], sol[maxSum][maxSet], tar[10], w[maxSum];
int encode(int x, int y) { return x * m + y; }
void decode(int grid, in... | 17 |
#include <bits/stdc++.h>
long long a[300000], T, n;
long long ok[300000];
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin >> T;
for (int t = 1; t <= T; t++) {
cin >> n;
memset(ok, 0, sizeof(ok));
long long minn = 0x7fffffffffffffff;
for (int i = 1; i <= n; i++) {
cin >> a[i];
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
long long int n;
while (t--) {
cin >> n;
long long int k = n / 2;
long double s = 4.0 * (k) * (k + 1);
long double y = 0.0;
for (long long int i = 2; i <= k; i++) y = y + i * (i - 1);
y = y * 8;
string p = to... | 2 |
#include <bits/stdc++.h>
using namespace std;
int fastMax(int x, int y) { return (((y - x) >> (32 - 1)) & (x ^ y)) ^ y; }
int fastMin(int x, int y) { return (((y - x) >> (32 - 1)) & (x ^ y)) ^ x; }
const long long int N = 20;
const long long int MAXN = 1 << N;
const long long int MOD = 1e9 + 7;
long long int power(long... | 16 |
#include <bits/stdc++.h>
using namespace std;
int i, j, n, w, m, r, c, k;
bool arr[11][11];
int count(int a, int b, int c, int d) {
int v = 0;
for (int i = a; i <= c; i++) {
for (int j = b; j <= d; j++) {
v += arr[i][j];
}
}
return v;
}
int main() {
scanf("%d %d %d %d", &r, &c, &n, &k);
int x,... | 22 |
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c> {i, j}; }
... | 10 |
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1LL << 62;
const int iinf = 1 << 30;
const double dinf = 1e17;
const int Mod = 1e9 + 7;
const int MAXBUF = 10000;
char buf[MAXBUF], *ps = buf, *pe = buf + 1;
bool isdigit(char n) {
if (n >= '0' && n <= '9') return true;
return false;
}
inline void ... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int inf = ~0U >> 4;
bool a[1010][1010], b[1010][1010];
int U[1010][1010], D[1010][1010];
int L[1010][1010], R[1010][1010];
int N, M, Q;
void Renew(int x, int y) {
U[x][y] = U[x - 1][y] + 1;
D[x][y] = D[x + 1][y] + 1;
L[x][y] = L[x][y - 1] + 1;
R[x][y] = R[x][y... | 12 |
#include <bits/stdc++.h>
using namespace std;
signed main() {
ios_base::sync_with_stdio(0);
long long n;
cin >> n;
vector<long long> a(n);
for (long long i = 0; i < n; i++) {
cin >> a[i];
}
long long ans = 360;
for (long long i = 0; i < n; i++) {
long long p = 0;
for (long long j = 0; j < n;... | 4 |
#include <bits/stdc++.h>
int get_int() {
int x = 0, y = 1;
char ch = getchar();
while (!isdigit(ch) && ch != '-') ch = getchar();
if (ch == '-') y = -1, ch = getchar();
while (isdigit(ch)) {
x = x * 10 + ch - '0';
ch = getchar();
}
return x * y;
}
int main() {
int T = get_int();
while (T--) {
... | 3 |
#include <bits/stdc++.h>
using namespace std;
set<long long int> values;
void states(long long int k) {
if (values.count(k)) return;
values.insert(k);
if (k == 1) return;
if (k % 2 == 0)
states(k / 2);
else {
states(k / 2);
states((k / 2) + 1);
}
}
map<long long int, long long int> M, R, pwr10;
... | 12 |
#include <bits/stdc++.h>
using namespace std;
int const inf = 1000 * 1000 * 1000;
long long const inf64 = 1ll * inf * inf;
bool solve() {
int n, c;
scanf("%d %d", &n, &c);
vector<vector<int> > a(n);
for (int l, i = 0; i < n; i++) {
scanf("%d", &l);
a[i].resize(l);
for (int j = 0; j < l; j++) {
... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<int> a(n);
for (long long i = 0; i < (n); i++) cin >> a[i];
long long ans = LLONG_MIN;
for (long long x = (1); x < (n / 3 + 1); x++) {
if (n % x) continue;
for (long long i... | 5 |
#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast, unroll-loops", "omit-frame-pointer", "inline")
#pragma GCC option("arch=native", "tune=native", "no-zero-upper")
#pragma GCC target( \
"sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native,avx2")
using namespace std... | 18 |
#include <bits/stdc++.h>
using namespace std;
int A[1000 + 10], B[1000 + 10];
bool vis[1000 + 10];
int main() {
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%d", A + i);
A[0] = -1;
for (int i = 1; i <= n; i++) scanf("%d", B + i);
B[0] = -2;
vector<int> ID;
for (int i = 1; i <= n; i++)
... | 5 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
using v2d = vector<vector<T> >;
template <class T>
bool uin(T &a, T b) {
return a > b ? (a = b, true) : false;
}
template <class T>
bool uax(T &a, T b) {
return a < b ? (a = b, true) : false;
}
mt19937 rng(chrono::system_clock::now().time_since_epoch(... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int N = 7e3 + 100;
const int INF = 0x3f3f3f3f;
inline long long dpow(long long a, long long b) {
long long r = 1, t = a;
while (b) {
if (b & 1) r = (r * t) % MOD;
b >>= 1;
t = (t * t) % MOD;
}
return r;
}
inline long long f... | 9 |
#include <bits/stdc++.h>
using namespace std;
int n, a[6], b[6], i, j, m;
inline void wrt(int x) {
if (x > 9) wrt(x / 10);
putchar(x % 10 + 48);
}
inline void wk(int x) {
wrt(x);
putchar(' ');
}
inline void wr(int x) {
wrt(x);
putchar('\n');
}
void sol(int x, int X, int y, int Y) {
wk(x), wr(y);
wk(X), ... | 23 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<bool> p(1000000, true);
p[0] = false;
p[1] = false;
for (int i = 2; i < p.size(); i++) {
if (!p[i]) continue;
for (int j = 2; i * j < p.size(); j++) p[i * j] = false;
}
int i = 1;
while (n) {
if (p[i]) {
... | 8 |
#include <bits/stdc++.h>
using namespace std;
long long int a[200005];
int res, idx;
long long int b[200005];
int binsearch(int n, int m, long long int key) {
long long int result;
int i;
int low = 0;
int high = n - 1;
int mid;
while (low <= high) {
mid = (low + high) / 2;
if (a[mid] > key) {
... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
class DSU {
public:
vector<int> uf, rank;
DSU(int n): uf(n), rank(n, 1) {iota(uf.begin(), uf.end(), 0);};
int find(int x){
if (uf[x] != x) uf[x] = find(uf[x]);
return uf[x];
}
bool unify(int x, int y){
... | 13 |
#include <bits/stdc++.h>
using namespace std;
bool isPrime(int n) {
if (n <= 1) return false;
if (n <= 3) return true;
if (n % 2 == 0 || n % 3 == 0) return false;
for (int i = 5; i * i <= n; i = i + 6)
if (n % i == 0 || n % (i + 2) == 0) return false;
return true;
}
void solve() {
long double k, d, t;
... | 9 |
#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&... | 9 |
#include <bits/stdc++.h>
using namespace std;
int n, i, j, k;
char s[10010];
struct sx {
int h[4];
};
sx opcje[2][2000100];
int opcje_count[2];
int main(void) {
scanf("%d %s", &n, s);
opcje[0][0].h[0] = 0;
opcje[0][0].h[1] = 0;
opcje[0][0].h[2] = 0;
opcje[0][0].h[3] = 0;
opcje_count[0] = 1;
for (i = 0; ... | 14 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.