solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
const int MAX = 54;
int matr[MAX][MAX];
bool tryIn(int x, int y) {
int f = 0;
if (matr[y][x] == 1 && matr[y + 1][x - 1] == 1 && matr[y + 1][x] == 1 &&
matr[y + 1][x + 1] == 1 && matr[y + 2][x] == 1) {
matr[y][x] = 2;
matr[y + 1][x - 1] = 2;
matr[y + 1]... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
int b[n + 1];
int i, j;
for (int i = 1; i <= n; i++) cin >> b[i];
int a[2 * n + 1];
bool vis[2 * n + 1];
for (int i = 0; i <= 2 * n; i++) vis[i] = false;
for (int i = 1; i... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 100;
long long dp[N];
long long aa[3 * N];
int main() {
int n;
long long L, v1, v2;
while (scanf("%d%lld%lld%lld", &n, &L, &v1, &v2) != EOF) {
L *= (v1 + v2);
long long len = L - L / (v1 + v2) * v1;
for (int i = 0; i < n; i++) {
s... | 13 |
#include <bits/stdc++.h>
const int N = 500005;
int H[N], id;
struct Edge {
int v, nt;
} e[N * 4];
int n, m;
int next[N];
std::vector<int> block[N];
int num, head;
int p[N];
void AddEdge(int u, int v) {
e[id].v = v;
e[id].nt = H[u];
H[u] = id++;
}
int main() {
scanf("%d%d", &n, &m);
id = 1;
num = 0;
int ... | 13 |
#include <bits/stdc++.h>
using namespace std;
char s[10005][10005];
int main() {
int n, v;
int i, j, k, l, h, r, cont;
cin >> n >> v;
for (i = 0; i < 4 * n; i++) cin >> &s[i][0];
char schm[5] = {"aaaa"};
char c[5][10005];
for (i = 0; i < 4 * n; i += 4) {
for (j = i, h = 0; j < i + 4; h++, j++) {
... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, shots;
cin >> n;
int arr[n];
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
cin >> shots;
int w[shots], o[shots];
for (int i = 0; i < shots; i++) {
cin >> w[i] >> o[i];
}
for (int i = 0; i < shots; i++) {
int temp = w[i] -... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100000 + 10;
const int NINF = -1e9;
int d[maxn];
int main() {
int n;
while (scanf("%d", &n) == 1) {
for (int i = 0; i < n; i++) scanf("%d", &d[i]);
int odd, even;
odd = even = NINF;
for (int i = 0; i < n; i++) {
if (d[i] % 2 == 0) ... | 6 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
int ara[100005];
vector<int> st[100005], en[100005];
int l[100005], r[100005];
int main() {
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
};
cin >> n >> m;
for (int i = 1; i <= n; i++) cin >> ara[i];
for (int i = 1; i <= m; i++) {
cin >>... | 10 |
#include <bits/stdc++.h>
int main() {
int a[100] = {0};
int A, n;
scanf("%d%d", &n, &A);
A--;
for (int i = 0; i < n; i++) scanf("%d", &a[i]);
int l = A, r = A, ans = 0;
if (a[A] == 1) ans++;
while (l >= 0 || r < n) {
l--;
r++;
if (l >= 0 && r < n)
if (a[l] == a[r] && a[l] == 1) ans += ... | 2 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 200 * 1000 + 100;
int n, a[N];
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
;
int test = 1;
while (test--) {
cin >> n;
set<int> ans;
set<int> P;
for (int i = 0; i < n; i++) {
i... | 8 |
#include <bits/stdc++.h>
using namespace std;
int f[200000], t[200000];
int nx[26][200000], ny[26][200000];
int main() {
string a, b;
cin >> a >> b;
for (int i = 0; i < (26); i++) {
nx[i][a.size()] = a.size();
for (int j = a.size() - 1; j >= 0; j--) {
if (a[j] - 'a' == i)
nx[i][j] = j;
... | 13 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<int> edge[505];
int c[505][505];
int main() {
cin >> n >> m;
string s;
for (int i = 0; i < n; i++) s += "a";
for (int i = 0; i < m; i++) {
int a, b;
cin >> a >> b;
a--, b--;
edge[a].push_back(b);
edge[b].push_back(a);
c[a][b]... | 10 |
#include <bits/stdc++.h>
int n;
char str[10];
bool ok[8];
int main() {
scanf("%d %s", &n, str);
for (int i = 0; i < 8; i++) ok[i] = true;
for (int i = 0; i < n; i++) {
switch (str[i]) {
case '0':
ok[2] = ok[3] = ok[4] = ok[5] = ok[6] = false;
break;
case '1':
ok[5] = ok[6] ... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
vector<long long int> v;
string a;
for (long long int i = 0; i < s.length(); i++) {
if (s[i] == 'a' || s[i] == 'b') a += s[i];
}
for (long long int i = 0; i < a.length(); i++) {
long long int count = 0;
if (a[i] == ... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 12 + 5;
int main() {
int t, len = 6, ret[maxn], cnt;
char s[maxn], r[] = {1, 2, 3, 4, 6, 12};
while (scanf("%d", &t) == 1) {
while (t--) {
cnt = 0;
scanf("%s", s);
for (int i = len - 1; i >= 0; i--) {
int a = 12 / r[i];
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int dx[] = {-1, 1, 0, 0, -1, -1, 1, 1};
int dy[] = {0, 0, -1, 1, -1, 1, 1, -1};
const int maxn = 1000000 + 66;
const int maxm = 100000 + 66;
const long long mod = 1e9 + 7;
const long long inf = 0x3f3f3f3f3f3f3f3fLL;
const int INF = 99999999;
int du[maxn];
int f[maxn];
int v... | 16 |
#include <bits/stdc++.h>
using namespace std;
long long N, Q;
long long even_above(long long row) {
if (N % 2 == 0) {
return row * N / 2;
} else {
long long even_rows = (row + 1) / 2;
long long odd_rows = row - even_rows;
return even_rows * ((N + 1) / 2) + odd_rows * (N / 2);
}
}
long long even_be... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
inline int ReadIn() {
char ch = getchar();
int data = 0;
while (ch < '0' || ch > '9') ch = getchar();
do {
data = data * 10 + ch - '0';
ch = getchar();
} while (ch >= '0' && ch <= '9');
return data;
}
char str[1001][7];
int ma... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, sum = 0, s = 0;
cin >> n >> m;
int a[n];
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 0; i < n; i++) {
if (sum + a[i] > m) {
sum = 0;
s++;
i--;
} else
sum += a[i];
}
if (sum != 0) s++;
cout << s... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7;
int n, m, f[N], L[N], R[N], id2q[N];
struct Query {
int t, x, y;
} q[N];
inline int get(int x) { return x == f[x] ? x : f[x] = get(f[x]); }
struct SegTree {
vector<int> id[N << 2];
void merge(int t, int l, int r, int P, int ID) {
for (int i ... | 22 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
const long long MOD = 1e9 + 7;
const long long mult = 15265731;
int n, m, p;
char s1[N], s2[N];
int dp[N][35];
long long h1[N], h2[N];
long long h[N];
long long geth(long long H[], int x, int y) {
long long dec = H[x - 1] * h[y - x + 1] % MOD;
ret... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int N = 21;
const int M = 101000;
const int INF = 0x3f3f3f3f;
const int mod = 1000000007;
void MOD(long long &a) {
if (a >= mod) a -= mod;
}
void MOD(long long &a, long long c) {
if (a >= c) a -= c;
}
void ADD(long long &a, long long b) {
a += b;
MOD(a);
}
voi... | 17 |
#include <bits/stdc++.h>
using namespace std;
const long long int zero = 0L;
long long int prime_table[] = {1009L, 10007L, 100003L, 1000003L,
10000019L, 100000007L, 1000000007L};
const long long int maxn_1 = 3.1e1;
const long long int maxn_2 = 3.1e2;
const long long int maxn_3 ... | 2 |
#include <iostream>
#include <iomanip>
using namespace std;
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <string>
#include <algorithm>
#include <cmath>
#include <cassert>
#include <utility>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstrin... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5;
struct operate {
int l, r, id;
} a[N + 5];
int n, m, b[N * 2 + 5], id[N * 2 + 5], cost[N * 4 + 5], tot, pos;
struct Segment_tree {
int sgm[N * 16 + 5], sum[N * 16 + 5], lazy[N * 16 + 5];
void build(int o, int l, int r) {
if (l == r) {
sgm[... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int nax = 304;
char mapka[nax][nax];
bool check(int x, int y, int radius) {
if (mapka[x][y] == '*' && mapka[x + radius][y] == '*' &&
mapka[x - radius][y] == '*' && mapka[x][y + radius] == '*' &&
mapka[x][y - radius] == '*') {
return true;
} else {
... | 8 |
#include <bits/stdc++.h>
using namespace std;
int c[1000001];
int main(void) {
stack<int> s;
int max = 0;
int cnt = 0;
int n = 0;
char cha;
int i = -1;
while (cin >> cha) {
i++;
if (cha == '(') {
s.push(i);
c[i] = -1;
} else {
if (s.empty()) {
c[i] = -1;
} else ... | 11 |
#include <bits/stdc++.h>
using namespace std;
struct Edge {
int v, id, next;
} edge[100050 * 2];
int e, ft[10050];
int n, m;
int cnt, dfn[10050], low[10050];
int dsu[100050], col[100050], size[100050];
bool flag[100050];
int find(int k) { return dsu[k] ^ k ? dsu[k] = find(dsu[k]) : k; }
void merge(int u, int v) {
u... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100 * 1000 + 20;
int t, n, x, ps[N];
string s;
int main() {
ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
cin >> t;
while (t--) {
int ans = 0;
bool flag = false;
cin >> n >> x >> s;
ps[0] = (s[0] == '0' ? 1 : -1);
for (i... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int M = 1e9 + 7;
const long long INF = 1e18;
long long biex(long long a, long long b) {
if (b == 0) return 1;
long long ans = biex(a, b / 2);
ans = ans * ans;
if (b & 1)
return ans * a;
else
return ans;
}
const int N = 1e5;
long long fact[N] = {0};
v... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, sp = 0, t = 0;
bool lock = false, L = false;
cin >> n;
char s[n];
for (int i = 0; i < n; ++i) cin >> s[i];
for (int i = 0; i < n; ++i) {
if (s[i] == '.')
continue;
else if (s[i] == 'R' && (!lock)) {
sp = i + 1;
lock ... | 5 |
#include <bits/stdc++.h>
using namespace std;
inline long long int modadd(long long int n, long long int m,
long long int p = 1000000007) {
return ((n + m) % p + p) % p;
}
inline long long int modsub(long long int n, long long int m,
long long int p = 1000000007... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
int openwindows = 0;
for (int i = 0; i < (n); i++) {
for (int j = 0; j < (m); j++) {
int x, y;
cin >> x >> y;
if (x or y) openwindows++;
}
}
cout << openwindows << endl;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int N, b[309], bst[1009], sol[309][2009];
int main() {
scanf("%d", &N);
for (int i = 1; i <= N; i++) scanf("%d", &b[i]);
sol[0][0] = 1;
for (int i = 1; i <= N; i++) {
bool ok = 1;
for (int j = 0; j <= sol[i - 1][0]; j++) {
sol[i][j] = sol[i - 1][j];
... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f2f1f0f;
const long long LINF = 1ll * INF * INF;
int main() {
int Q;
cin >> Q;
while (Q--) {
int n;
scanf("%d", &n);
if (n % 4 == 0)
printf("%d\n", n / 4);
else if (n % 4 == 1) {
if (n < 9)
printf("-1\n");
e... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main(void) {
int n, m, v;
vector<int> boys;
vector<int> girls;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> v;
boys.push_back(v);
}
sort(boys.begin(), boys.end());
cin >> m;
for (int i = 0; i < m; i++) {
cin >> v;
girls.push_back(v);
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int A[300005];
int P[300005];
struct data {
bool endmark;
data* next[5];
int tot[5];
data() {
for (int i = 0; i < 2; i++) {
next[i] = NULL;
tot[i] = 0;
}
endmark = false;
}
} * root;
void INSERT(int val) {
data* now = root;
for (int i =... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 2020;
char all[MAX][MAX];
bool safe[MAX][MAX];
int n, m;
int dx[8] = {0, -1, -1, -1, 0, 1, 1, 1};
int dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int ma(int x, int y) {
int an = 0;
for (int i = 0; i < 8; i += 2) {
int tmp = 0;
for (int j = 0; j < 3; ++j... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int l, r, a;
cin >> l >> r >> a;
while (a--) l <= r ? l++ : r++;
cout << 2 * min(l, r) << endl;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:1024000000,1024000000")
int _MAX(int a, int b) { return a > b ? a : b; }
int _MIN(int a, int b) { return a > b ? b : a; }
int Scan() {
int res = 0, flag = 0;
char ch;
if ((ch = getchar()) == '-')
flag = 1;
else if (ch >= '0' && ch... | 4 |
#include <bits/stdc++.h>
using namespace std;
int t, n, k;
string s1, s;
char c[200010];
int main() {
cin >> n >> k;
s = "v";
string a;
cin >> s1;
s += s1;
a = s;
int len = n - k;
for (int i = 1; i <= len; i++) {
a[i + k] = a[i];
}
while (a < s) {
if (a[k] < '9')
a[k]++;
else {
... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n;
cin >> n;
vector<long long int> v;
long long int i = 5;
while (i <= 1000000000) {
v.push_back(i);
i *= 2;
}
int k = 0;
while (n > 0) {
n -= v[k];
k++;
}
k--;
n += v[k];
long long int x = v[k];
x = x / 5... | 3 |
#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 Mod = 1e9 + 7;
const int maxn = 500;
struct data ... | 22 |
#include <bits/stdc++.h>
using namespace std;
int a[500100];
int b[500100];
set<pair<int, int>> s;
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) scanf("%d", a + i);
sort(a, a + n);
for (int i = 0; i < n; i++) {
s.insert({a[i], i});
}
int ans = n;
for (int i = 0; i < n; i++) {
auto it... | 8 |
#include <bits/stdc++.h>
using namespace std;
vector<int> a;
int sup(int c, int n) {
int x = 0;
for (int i = 0; i < n; i++) {
if (a[i] > c) ++x;
}
return x;
}
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
int f;
cin >> f;
a.push_back(f);
}
for (int i = 0; i < n; i++) cout... | 0 |
#include <bits/stdc++.h>
using namespace std;
int maxDiff(int arr[], int arr_size) {
int max_diff = arr[0] - arr[1];
int max_element = arr[0];
for (int i = 1; i < arr_size; ++i) {
if (max_element - arr[i] > max_diff) max_diff = max_element - arr[i];
if (arr[i] > max_element) max_element = arr[i];
}
re... | 7 |
#include <bits/stdc++.h>
using namespace std;
namespace SA {
char s[100005];
int n, lcp[200005], cnt[200005], vy[200005], rk[200005], tmp[200005],
ls[200005];
void bsort() {
int i;
memset(cnt, 0, sizeof(cnt));
for (i = 0; i < n; ++i) ++cnt[vy[i]];
for (i = 1; i <= n + 3 || i <= 30; ++i) cnt[i] += cnt[i - 1]... | 18 |
#include <bits/stdc++.h>
using namespace std;
int a[100005];
int main() {
long k, n;
cin >> n >> k;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
long sum = 0;
for (int i = 0; i < n; i++) {
sum += a[i];
}
if (sum % k != 0)
cout << "No" << endl;
else {
long j = 0;
long x = 0;
lon... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
map<int, int> a;
int aux = 0;
for (int i = 0; i < int(n); i++) {
int v;
cin >> v;
a[v]++;
aux = max(aux, a[v]);
}
cout << n - aux << '\n';
}
| 5 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 998244353;
const int gg = 3;
const int maxn = 2520210;
int mp[maxn], a[maxn], f[maxn];
int n, m;
int ord[maxn];
int fast_pow(int now, int p) {
if (p == 0) return 1;
if (p == 1) return now;
int z = fast_pow(now, p / 2);
z = (1ll * z * z) % mod;
... | 20 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
inline int Gcd(int X, int Y) { return Y ? Gcd(Y, X % Y) : X; }
inline long long Gcd(long long X, long long Y) { return Y ? Gcd(Y, X % Y) : X; }
inline int Max(int X, int Y) { return X < Y ? Y : X; }
inline int Min(int X, int Y) { return X < Y ? X... | 16 |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
if (b == 0) return a;
return gcd(b, a % b);
}
long long ispalindrome(string ss) {
long long n = ss.size();
for (long long i = 0; i < (n + 1) / 2; i++) {
if (ss[i] != ss[n - i - 1]) return 0;
}
return 1;
}
long long m... | 7 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 0x3f3f3f3f;
const int N = 1e6 + 10;
const int M = 1 << 21;
const long long mod = 1e9 + 7;
const double PI = acos(-1);
int v[N];
int node[N << 2];
int gg[N];
void add(int v, int x, int l, int r, int o) {
node[o]++;
if (l == r) {
gg[l] = x;
r... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1 << 10;
unordered_map<string, int> tok;
map<tuple<int, char, int>, int> op;
struct node {
string nem;
tuple<int, char, int> dep;
bool leaf;
} T[4 * N];
bool seen[4 * N];
int lcnt;
ostringstream os;
void dfs(int at) {
if (seen[at] || T[at].leaf) return... | 19 |
#include <bits/stdc++.h>
int get() {
int x = 0;
char s = getchar();
while (s < '0' || s > '9') s = getchar();
while (s >= '0' && s <= '9')
x = (x << 3) + (x << 1) + (s ^ 48), s = getchar();
return x;
}
int has(const char c) {
if (c == 'A') return 0;
if (c == 'T') return 1;
if (c == 'G') return 2;
... | 13 |
#include <bits/stdc++.h>
using namespace std;
inline void in(long long &now) {
char Cget = getchar();
now = 0;
while (Cget > '9' || Cget < '0') Cget = getchar();
while (Cget >= '0' && Cget <= '9') {
now = now * 10 + Cget - '0';
Cget = getchar();
}
}
long long gcd(long long a, long long b) { return b ?... | 9 |
#include <bits/stdc++.h>
using namespace std;
int dig[20];
const int M = 262145;
long long dp[262145][101];
int m;
int pos;
long long dfs(int state, int x) {
long long ans = 0;
if (state == (1 << pos) - 1) return x == 0;
long long &dpAns = dp[state][x];
if (dpAns != -1) return dpAns;
int vis[10] = {0};
for ... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, x, y;
cin >> n;
vector<int> vis(n, 0);
for (int i = 0; i < n - 1; i++) {
cin >> x >> y;
vis[x - 1]++;
vis[y - 1]++;
}
int flag = 0;
for (int i = 0; i < n; i++) {
if (vis[i] == 2) {
flag = 1;
break;
}
}
if... | 8 |
#include <bits/stdc++.h>
using namespace std;
string f(char c) {
switch (toupper(c)) {
case '0':
return "0000";
case '1':
return "0001";
case '2':
return "0010";
case '3':
return "0011";
case '4':
return "0100";
case '5':
return "0101";
case '6':
r... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 100;
int n, m, p;
int xx[N], yy[N];
int dp1[2][N], dp2[2][N];
int fun(int i, int j) { return (xx[i] + yy[j]) % p; }
void getdp1(int a, int b, int c, int d, int dp[2][N]) {
for (int i = a; i <= c; i++) {
int x = i % 2;
for (int j = b; j <= d; j+... | 17 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int b, k;
cin >> b >> k;
int A[k];
for (int i = 0; i < k; i++) {
cin >> A[i];
}
if (b % 2 == 0) {
if (A[k - 1] % 2 == 0)
cout << "even";
else
cout << "odd";
} else {
int count = 0;
for (int i = 0; i < k; i++) {
... | 1 |
#include <bits/stdc++.h>
using namespace std;
struct Ahri {
int x, y, z;
Ahri(int a = 0, int b = 0, int c = 0) : x(a), y(b), z(c) {}
void read() { scanf("%d%d", &x, &y); }
bool operator<(const Ahri &A) const { return x < A.x; }
} p[101000 << 1];
long long ans[101000];
map<int, int> l;
int n, m, s[30001000], t[3... | 18 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5e5 + 10;
const int MAXM = 2e6 + 10;
const long long MOD = 1e9 + 7;
const long long INF = 0x3f3f3f3f;
const unsigned long long BASE = 233;
const int base = 5;
char rubbish[110];
bool GETDATA;
inline long long read() {
long long x = 0, f = 1;
char ch;
... | 17 |
#include <bits/stdc++.h>
using namespace std;
int n, k, a[1005], dem[1005], cnt, ans;
int main() {
scanf("%d %d", &n, &k);
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
dem[a[i]]++;
}
cnt = (n + 1) / 2;
for (int i = 1; i <= k; i++) {
if (cnt >= dem[i] / 2) {
ans += (dem[i] / 2) * 2;
... | 2 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:100000000")
using namespace std;
const double PI = acos(-1.0);
const int INF = 1e9;
const int MOD = INF + 7;
const double EPS = 1e-9;
const long long BIGINF = 1e17;
mt19937 rng(time(0));
uniform_int_distribution<int> uid(0, INF / 2);
vector<int> v;
vector<int> us... | 4 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7LL;
const int MXN = 2e5 + 1;
long long N, A[MXN], CMB[MXN];
inline long long solve(int i) {
long long ans = 0;
for (int j = i, cnt = 0; j < N; j += 2, cnt++) {
ans = ((A[j] * CMB[cnt]) % MOD + ans) % MOD;
}
return ans;
}
inline long ... | 14 |
#include <bits/stdc++.h>
using namespace std;
int n, m, k;
int c[550000];
int fa[550000 * 2];
int rk[550000 * 2];
struct Pair {
int l, r;
} p[550000];
int cnt;
bool vis[550000];
bool cmp(Pair x, Pair y) {
return c[x.l] == c[y.l] ? c[x.r] < c[y.r] : c[x.l] < c[y.l];
}
pair<int, int> rkstk[550000 * 4], fastk[550000 *... | 17 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 7;
int far[maxn][2];
int cnt[maxn][2];
void init() {
for (int i = 0; i < maxn; i++)
far[i][0] = far[i][1] = i, cnt[i][0] = cnt[i][1] = 1;
}
int Find(int x, int type) {
return far[x][type] == x ? x : far[x][type] = Find(far[x][type], type);
}
v... | 14 |
#include <bits/stdc++.h>
using namespace std;
int n;
vector<string> a;
bool comp(string p, string t) {
string s1 = p, s2 = t;
s1.append(t), s2.append(p);
return (s1 < s2);
}
int main() {
ios_base::sync_with_stdio(0);
cin >> n;
a.resize(n);
for (int i = 0; i < n; ++i) cin >> a[i];
sort(a.begin(), a.end()... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, h, a, sum = 0;
cin >> n >> h;
while (n--) {
cin >> a;
if (a > h)
sum = sum + 2;
else
sum++;
}
cout << sum;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int mo = 1e9 + 7;
const int N = 105;
long long inv[N], n, ans[N][N], nex[N];
long long p[N], pc[N][N], sum;
int cnt, K;
int c[N], cc[N];
void dfs(int x) {
if (x > cnt) {
long long now = 1;
for (int i = 1; i <= cnt; i++) {
now = pc[i][cc[i]] % mo * ans[... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
set<char> myset;
string s;
getline(cin, s);
for (int i = 0; i < s.size(); i++) {
if (s[i] >= 97 && s[i] <= 122) {
myset.insert(s[i]);
}
}
cout << myset.size() << endl;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int team_number, strenght;
cin >> team_number;
vector<tuple<int, int, int> > v;
for (int j = 2; j <= team_number * 2; j++) {
for (int i = 1; i <= j - 1; i++) {
cin >> strenght;
v.push_back(make_tuple(strenght, i, j));
}
}
sort(v.... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long a[100005];
long long n, k;
long long f(long long mid) {
long long s = 0, maxi = INT_MIN, additions = INT_MAX;
for (long long i = 0; i < mid; i++) s += a[i];
additions = mid * a[mid - 1] - s;
if (additions <= k) return a[mid - 1];
for (long long i = mid; ... | 8 |
#include <bits/stdc++.h>
const int maxp = 500, maxe = 20000;
using namespace std;
vector<int> as[300], bs[300];
int da[300], db[300];
int n, m, k, t;
int p[maxp], ne[maxe], e[maxe], ev[maxe], ew[maxe], ec;
int S = 1, T = 2;
int nowchooser;
struct edge {
int a, b, flag;
} es[maxe];
map<pair<int, int>, int> fp;
int cut... | 22 |
#include <bits/stdc++.h>
using namespace std;
struct Point {
int x[5];
void read() {
for (int i = 0; i < 5; ++i) scanf("%d", &x[i]);
}
} p[105];
long long operator*(const Point& a, const Point& b) {
long long ret = 0;
for (int i = 0; i < 5; ++i) ret += (long long)a.x[i] * b.x[i];
return ret;
}
Point ope... | 9 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
struct persistent_array {
int tree_n = 0;
vector<T> values;
vector<int> left, right;
persistent_array(int n = 0, int reserve_size = 0) {
if (n > 0) init(n, reserve_size);
}
persistent_array(const vector<T> &v, int reserve_size = 0) {
... | 18 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 5e5;
const long long M = 20;
const long long SQ = 320;
const long long INF = 1e16;
const long long MOD = 1e9 + 7;
int n, m;
int a[N], b[N], b1[N], c[N];
vector<int> v, v1;
int l[N], r[N];
vector<pair<int, int> > q[N];
int d[N];
int ans[N];
int main() {
... | 18 |
#include <bits/stdc++.h>
using namespace std;
long long extendedGcd(long long a, long long b, long long &x, long long &y);
void addEdge(vector<long long> adj[], long long u, long long v);
void DFSUtil(long long u, vector<long long> adj[], vector<bool> &visited);
void DFS(vector<long long> adj[], long long V, long long ... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int modN = 1e9 + 7;
const double PI = 3.1415926535897932384626433832795028841;
int main() {
string a, b, x, name;
int n;
while (cin >> name >> n) {
map<string, int> m;
while (n--) {
cin >> a >> x;
m[a];
if (x == "posted") {
cin ... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1000010;
int n, a[N], c[N << 1], pcnt, ncnt;
long long psum, nsum;
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
if (a[i] - i > 0)
c[a[i] - i]++, pcnt++, psum += a[i] - i;
else
ncnt++, nsum += i - ... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 9000005;
int prim[maxn];
bool vis[maxn];
int cnt;
long long ans1[maxn];
long long ans2[maxn];
bool is(int x) {
int a[11];
int c = 0;
while (x) a[c++] = x % 10, x /= 10;
for (int i = 0, j = c - 1; i < j; i++, j--)
if (a[i] != a[j]) return 0;
re... | 8 |
#include <bits/stdc++.h>
using namespace std;
int n, m, maxs, ans, tot[100], dp[50][100][100];
inline int lowbit(int x) { return x & -x; }
int calc(int x) {
int res = 0;
while (x) {
res++;
x -= lowbit(x);
}
return res;
}
bool check(int x, int y, int z) {
int sta = x | y | z | (y << 1) | (y >> 1);
if... | 13 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
int a[2000002];
int b[2000002];
int main() {
scanf("%d%d", &n, &m);
for (int i = 0; i < m; ++i) scanf("%d%d", &a[i], &b[i]);
int ans = 0;
for (int i = 0; i < m; ++i) {
ans = max(ans, b[i]);
int d2 = a[i];
int h2 = b[i];
int t = 0;
if (!... | 8 |
#include <bits/stdc++.h>
std::mt19937 rng(
(int)std::chrono::steady_clock::now().time_since_epoch().count());
using namespace std;
long long mod = (1000000007LL);
inline long long Mod(long long a, long long b) { return (a % b); }
inline long long poww(long long a, long long b) {
long long res = 1;
while (b > 0)... | 17 |
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
long long n, m;
scanf("%lld %lld", &n, &m);
vector<vector<long long>> subjects(m);
for (long long i = 0; i < n; i++) {
long long si, ri;
scanf("%lld %lld", &si, &ri);
si--;
subjects[si].push_back(ri);
}
for (long long i = 0; i < ... | 8 |
#include <bits/stdc++.h>
using namespace std;
string s;
int getLen(int i) {
int j = i;
while (s[j] != ',') j++;
return j - i;
}
vector<int> st;
string com[1000000];
int dep[1000000];
int cid[1000000];
bool cmp(int a, int b) {
if (dep[a] == dep[b]) return a < b;
return dep[a] < dep[b];
}
int main() {
cin.tie... | 9 |
#include <bits/stdc++.h>
using namespace std;
long long n;
int main() {
cin >> n;
cout << 1 + 12 * (n * (n - 1) / 2) << endl;
return 0;
}
| 5 |
#include <bits/stdc++.h>
using namespace std;
int dr[] = {1, 0, -1, 0, -1, -1, 1, 1};
int dc[] = {0, -1, 0, 1, -1, 1, -1, 1};
const int MAX = 500 + 7;
const int MOD = 1e9 + 7;
int main() {
int n, m;
cin >> n >> m;
for (long long i = 0; i < n; ++i) {
int s, e, t;
cin >> s >> e >> t;
if (s == e) {
... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = (int)1e5 + 5;
const int maxm = (int)1e5 + 5;
int n, m, k;
int cnt[maxn];
struct edge {
int u, v, w;
void read() { scanf("%d%d%d", &u, &v, &w); }
bool operator<(const edge &rhs) const { return w < rhs.w; }
} e[maxm];
int ans;
int lab[maxn];
int root(in... | 10 |
#include <bits/stdc++.h>
using namespace std;
inline int read() {
int x = 0;
bool flag = 1;
char c = getchar();
for (; !isdigit(c); c = getchar())
if (c == '-') flag = 0;
for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
return flag ? x : -x;
}
int n;
int main() {
n = read();
if (n == 1) {
... | 11 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
template <class T>
istream& operator>>(istream& is, vector<T>& vec) {
for (int i = 0; i < vec.size(); ++i) is >> vec[i];
return is;
}
template <class T>
ostream& operator<<(ostream& os, vector<T>& vec) {
for (auto& t : vec... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int L = 23, N = 110;
const int B = 1e9 + 7;
int no;
int n, k;
vector<int> e[N];
long long dp[N][L][L];
void add(long long &x, long long y) {
x = (x + y) % B;
if (x < 0) x += B;
}
void cpy(long long a[L][L], long long c[L][L]) {
for (int i = 0; i <= no; ++i)
... | 17 |
#include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
const char* comma = strchr(names + 1, ',');
cerr.write(name... | 16 |
#include <bits/stdc++.h>
using namespace std;
map<long long, long long> a;
map<long long, vector<long long>> adj;
long long cnt, mx;
pair<long long, long long> dfs(long long x) {
if (adj[x].size() == 0) {
mx = max(mx, (long long)a[x]);
return {1, a[x]};
}
long long sum = 0, ct = 0;
for (auto y : adj[x])... | 11 |
#include <bits/stdc++.h>
using namespace std;
int n, p, q, c[5005 << 1], T = (5005 << 1) - 5, bas = 5002;
long long ans = 0;
struct node {
int x, l, r;
} a[5005], b[5005];
bool cmp(node x, node y) { return x.x < y.x; }
bool cmp_(node x, node y) { return x.l < y.l; }
inline void add(int x) {
for (; x <= T; x += x & ... | 14 |
#include <bits/stdc++.h>
int main() {
const unsigned MAX_DELTA = 5U;
unsigned n;
std::cin >> n;
std::vector<unsigned> a(n);
for (unsigned i = 0U; i < n; i++) {
std::cin >> a[i];
}
std::sort(a.begin(), a.end());
auto left = a.begin();
auto right = a.begin();
while (right != a.end() - 1U) {
if... | 4 |
#include <bits/stdc++.h>
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("O8")
#pragma GCC optimization("unroll-loops")
using namespace std;
const long long int N = 2e2 + 20, mod = 1e9 + 7, inf = 1e18, dlt = 12250,
maxm = 2e6;
int poww(long long a, int k) {
if (!k) return 1;
if (k ==... | 12 |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
long long a[100010];
long long po[300010], r[300010];
vector<int> v[300010];
void solve(int b, int p) {
if (r[p] != -1) return;
... | 13 |
#include <bits/stdc++.h>
using namespace std;
struct __s {
__s() {
srand(time(NULL));
if (1) {
ios_base::Init i;
cin.sync_with_stdio(0);
cin.tie(0);
}
}
~__s() {
if (!1)
fprintf(stderr, "Execution time: %.3lf s.\n",
(double)clock() / CLOCKS_PER_SEC);
long ... | 15 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.