solution stringlengths 53 181k | difficulty int64 0 13 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
const long long INF = LLONG_MAX;
const long long mod = 1000000007;
const double pi = 3.14159265358979323846;
long long powmod(long long a, long long b) {
long long res = 1;
a %= mod;
assert(b >= 0);
for (; b; b >>= 1) {
if (b & 1) res = res * a % mod;
a = a ... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int maxn = 1000000;
int vis[maxn];
int n, m;
int sum = 0;
set<int> ns;
vector<int> v[maxn];
void dfs(int x) {
printf("%d ", x);
sum++;
ns.erase(x);
vis[x] = 1;
if (sum == n) return;
int kk = 0;
int qw = v[x].size();
for (int... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
n = 2 * n;
int a[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
int ans = 0;
for (int i = 0; i < n - 1; i = i + 2) {
for (int j = i + 1; j < n; j++) {
if (a[i] == a[j]) {
for (int k = j; k >= i + 2; k--) ... | 3 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const long long inf = (long long)1e15;
const long double eps = 1e-12;
const long long N = (int)1e5 + 5;
const long long LOGN = 19;
const long double PI = 3.14159265358979323846;
long long mul(long long a, long long b, long long m = mod) {
... | 4 |
#include <bits/stdc++.h>
using namespace std;
string solve(string& input) {
string int_part = "";
string dec_part = "";
string b_part = "";
int st = -1;
for (int i = 0; i < input.size(); i++) {
if (input[i] == '.') {
st = i + 1;
break;
}
int_part += input[i];
}
for (int i = st; i <... | 3 |
#include <bits/stdc++.h>
using namespace std;
const long long inf = 0x3f3f3f3f;
const double eps = 1e-8;
const long long mod = 1000000007;
const double pi = acos(-1);
inline void gn(long long& x) {
long long sg = 1;
char c;
while (((c = getchar()) < '0' || c > '9') && c != '-')
;
c == '-' ? (sg = -1, x = 0)... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int Maxn = 400 + 10;
int n, m, adj[Maxn][Maxn], dis[Maxn];
bool mark[Maxn];
queue<int> q;
void bfs(int v, int a) {
q.push(v);
mark[v] = true;
while (!q.empty()) {
int u = q.front();
for (int i = 0; i < n; i++)
if (!mark[i] && adj[u][i] == a) {
... | 4 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool fs(T &x) {
int c = getchar();
int sgn = 1;
while (~c && c < '0' || c > '9') {
if (c == '-') sgn = -1;
c = getchar();
}
for (x = 0; ~c && '0' <= c && c <= '9'; c = getchar()) x = x * 10 + c - '0';
x *= sgn;
return ~c;
}
in... | 5 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
void read(T &x) {
char c;
bool op = 0;
while (c = getchar(), c < '0' || c > '9')
if (c == '-') op = 1;
x = c - '0';
while (c = getchar(), c >= '0' && c <= '9') x = x * 10 + c - '0';
if (op) x = -x;
}
template <class T>
void write(T x) {
... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e6 + 5;
int n, m;
map<int, int> dir;
char s[200][200];
bool ok;
int b[200];
void dfs(int x, int y, int i) {
if (x < 1) return;
if (x > n) return;
if (y < 1) return;
if (y > m) return;
if (s[x][y] == '#') return;
if (s[x][y] == 'E') {
ok = true... | 2 |
#include <bits/stdc++.h>
using namespace std;
const long long int MOD = 1e9 + 7;
inline long long int gcd(long long int a, long long int b) {
return b ? gcd(b, a % b) : a;
}
inline long long int lcm(long long int a, long long int b) {
return a * b / gcd(a, b);
}
inline long long int add(long long int a, long long i... | 4 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
using min_heap = priority_queue<T, vector<T>, greater<T>>;
template <class T>
using max_heap = priority_queue<T, vector<T>, less<T>>;
int solve2(const vector<string> &vec, char c) {
int n = vec.size();
vector<int> val(n);
for (int i = 0; i < n; i++)... | 3 |
#include <bits/stdc++.h>
using namespace std;
int t, n;
int a[55];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
sort(a + 1, a + 1 + n);
if (a[1] == a[n / 2 + 1])
cout << "Bob";
else
cout << "Alice";
return 0;
}
| 6 |
#include <bits/stdc++.h>
using namespace std;
int k, d;
int a[100000], b[100000];
int main() {
cin >> k;
for (int i = 0; i < k; i++) {
cin >> a[i];
b[i] = a[i];
}
sort(b, b + k);
for (int i = 0; i < k; i++) {
if (a[i] != b[i]) d++;
}
if ((d == 2) || (d == 0)) {
cout << "YES";
} else {
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, arr[(int)1e5 + 2], c = 2, mx = 0;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> arr[i];
if (i > 1 && arr[i] == arr[i - 1] + arr[i - 2])
c++;
else
mx = max(mx, c), c = 2;
}
if (n <= 2) return cout << n, 0;
return... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;
const long long inf = 92233720368547758;
long long T = 1;
vector<vector<long long> > v;
long long n, m, x, y, k;
vector<long long> dp, vis, depth;
string s;
long long ceil_(long long x, long long y) {
if (x % y == 0) return x / y;
return (x / y)... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long str_to_int, sub_ans, t;
string s, sp;
char str2[6];
cin >> s;
str2[0] = s[0];
str2[1] = s[2];
str2[2] = s[4];
str2[3] = s[3];
str2[4] = s[1];
sp = str2;
stringstream x(sp);
x >> str_to_int;
sub_ans = str_to_int;
for (int i ... | 3 |
#include <bits/stdc++.h>
using namespace std;
void oblivious() {
long long int a, b, c, r;
cin >> a >> b >> c >> r;
long long int a1 = min(a, b);
long long int a2 = max(a, b);
a = a1;
b = a2;
if (c >= a && c <= b) {
if (c + r <= b && c - r >= a) {
cout << b - a - 2 * r << endl;
} else if (c ... | 0 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e9;
const long double EPS = 1e-14;
int K;
vector<long double> inv;
int nInvers(vector<int> a) {
int sum = 0;
for (int i = 0; i < int(a.size()); i++) {
for (int j = i + 1; j < a.size(); j++) {
if (a[j] < a[i]) {
sum++;
}
... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e4 + 5;
int cnt[27];
int k;
char str[N];
int main(void) {
cin >> str;
scanf("%d", &k);
if (k > strlen(str)) {
printf("impossible\n");
return 0;
}
for (int i = 0; i < strlen(str); ++i) {
++cnt[str[i] - 'a'];
}
int val = 0;
for (int ... | 1 |
#include <bits/stdc++.h>
using namespace std;
struct team {
string nam;
int pnts, sc, mis;
};
int n;
team t[50];
void add(const string &s, int a, int b) {
for (int i = 0; i < n; ++i)
if (t[i].nam == s) {
if (a > b)
t[i].pnts += 3;
else if (a == b)
t[i].pnts += 1;
t[i].sc += a... | 3 |
#include <bits/stdc++.h>
using namespace std;
int num[200005];
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", num + i);
}
sort(num, num + n);
n = unique(num, num + n) - num;
int maxs = 0;
for (int i = 0; i < n - 1; i++) {
if (num[i] == 1) continue;
int h = num... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
const int INF = 1000000001;
int n, q;
long long segSum[800005], segMult[800005], w[200005], a[200005];
void update(long long seg[], int v, int l, int r, int index, long long x);
long long get(long long seg[], int v, int l, int r, int cl, int cr);... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 10;
char kkm[maxn];
int cnt[maxn];
int main() {
int n;
scanf("%d", &n);
scanf("%s", kkm + 1);
int x = 0;
for (int i = 1; i <= n; i++) {
if (kkm[i] == '(')
x++;
else
x--;
cnt[i] = x;
}
for (int i = n - 1; i >= 1; i... | 5 |
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <queue>
#i... | 6 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n;
cin >> n;
string num;
cin >> num;
if (n == 1) {
if ((num[0] - '0') % 2 == 0) {
cout << 2 << endl;
return;
}
cout << 1 << endl;
return;
}
int e, o = 0;
if (n % 2 == 0) {
for (int i = 1; i < num.length(); i... | 0 |
#include <bits/stdc++.h>
using namespace std;
string s = "FESTIVAL";
long long dp[1010][10];
int a[1010];
int main(void) {
int i, j, k;
dp[0][0] = 1;
for ((i) = 0; (i) < (int)(1000); (i)++)
for ((j) = 0; (j) < (int)(8); (j)++)
for ((k) = 0; (k) < (int)(8); (k)++)
if (j <= k) dp[i + 1][k] = min(d... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cout << 1 << " ";
}
cout << endl;
}
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
map<int, int> m;
int n, a, x, maxi;
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &x);
m[x] = m[x - 1] + 1;
a = m[x];
maxi = max(a, maxi);
}
printf("%d", n - maxi);
return 0;
}
| 4 |
#include <bits/stdc++.h>
using namespace std;
int n, a[1111][1111], a1[1111][1111], a2[1111][1111], f1[1111][1111],
f2[1111][1111], p1[1111][1111], p2[1111][1111], x = -1, y, xx, yy, as1, bs1,
as2, bs2, s1, s2;
string ans1, ans2;
int main() {
cin >> n;
for (in... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int Z = (int)2e3 + 228;
const int N = (int)4e5 + 600;
const int INF = (int)1e9 + 228;
const int MOD = (int)1e9 + 7;
struct Bor {
Bor *next[26];
Bor() {
for (int i = 0; i < 26; i++) next[i] = nullptr;
}
};
Bor *root = new Bor();
bool good[26];
int ans, k;
voi... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 5000 + 100;
const int maxm = 300000 + 100;
const long long INF = 100000000000000000LL;
long long dp[maxn][maxn], n, k;
long long a[maxm], sum[maxm], ts;
int main() {
scanf("%lld%lld", &n, &k);
for (int i = 1; i <= n; ++i) scanf("%lld", &a[i]);
ts = 0;... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6;
int p[maxn];
void solve() {
int n;
cin >> n;
int fl = 0;
for (int i = 1; i <= n; i++) {
scanf("%d", &p[i]);
if (i > 1 && p[i - 1] >= p[i]) fl = 1;
}
if (n % 2 == 1 && fl == 0)
cout << "NO" << endl;
else
cout << "YES" << en... | 1 |
#include <bits/stdc++.h>
using namespace std;
map<long long int, int> mp;
int re[100022], ad[100022], cou[100022];
long long int arr[100022], val[100022], aa[100022], ansa[100022];
struct node {
int l, r, in;
} q[100222];
int cmp(node a, node b) {
if (a.l / 333 != b.l / 333) return a.l / 333 < b.l / 333;
return a... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100010;
int pos[maxn];
int main() {
int n, tem;
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &tem);
pos[tem] = i;
}
int cou = 0, MAX = -1;
for (int i = 1; i <= n; i++) {
if (i == 1) {
cou++;
MAX = 1;
} ... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n;
int p[100005];
bool vis[100005];
bool par = true;
int res1 = -1, res2 = -1;
int pareja;
int k, szz;
int main() {
cin >> n;
for (int i = 1; i < n + 1; i++) cin >> p[i];
for (int i = 1; i < n + 1; i++) {
if (!vis[i]) {
vis[i] = true;
k = p[i];
... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
cin.tie(0);
ios_base::sync_with_stdio(false);
long long k, temp = 9, t = 1, d = 1, l, m, n;
cin >> k;
while (k - temp * t > 0) {
k -= temp * t;
temp *= 10;
t++;
}
m = (k - 1) % t + 1;
n = (k - 1) / t;
for (int i = 1; i < t; i++) d ... | 5 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
int n, L, minID;
string s;
void fill(int id, char c) {
L -= (s[id] == 'L');
s[id] = c;
minID = min(minID, id);
}
void query(char cmd, string str) {
cout << cmd << " " << str << '\n';
cout.flush();
if (cmd == '?') {
int k;
ci... | 13 |
#include <bits/stdc++.h>
using namespace std;
map<int, int> cnt;
multiset<long long> have;
vector<long long> used;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
srand(time(NULL));
int n;
cin >> n;
for (int i = 0; i < n; i++) {
long long a;
cin >> a;
cnt[a]++;
}
for (map<in... | 5 |
#include <bits/stdc++.h>
using namespace std;
struct node {
int num;
int l, r;
} Mem[10000];
int cnt;
string s[1024];
void init(int root) {
Mem[root].num = 2;
Mem[root].l = -1;
Mem[root].r = -1;
}
string Str;
bool insert(int root, int len) {
if (len == 0) {
Mem[root].num = 0;
return true;
}
if (... | 5 |
#include <bits/stdc++.h>
using namespace std;
struct edge {
int v, rev, cap, flow, cost;
edge(int _v, int _rev, int _cap, int _flow, int _cost) {
v = _v;
rev = _rev;
cap = _cap;
flow = _flow;
cost = _cost;
}
edge() {}
};
vector<pair<int, int> > path;
vector<vector<edge> > AdjList;
int f = 0;... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
void add(int& a, const int& b) {
a += b;
if (a >= mod) a -= mod;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
string s;
cin >> s;
int suf0 = 0;
while (!s.empty() && s.back() == '0') {
s.pop_back();
suf0++;
}
if... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 300010, maxm = 300010, maxs = 610;
struct Task {
int idx, x, d;
} q[maxn];
long long f[maxn], ans[maxm];
int w[maxn], n, m, S;
inline bool cmp_ask(const Task &u, const Task &v) { return u.d < v.d; }
void init() {
scanf("%d", &n), S = sqrt(n);
for (int... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long int n;
cin >> n;
long long int brr[2 * n + 10];
long long int arr[n + 5];
long long int i;
for (i = 0; i < n; i++) cin >> arr[i];
long long int b = 0;
for (i = 0; i < n; i += 2) {... | 6 |
#include <bits/stdc++.h>
using namespace std;
int n, k, m, x, y, r, A[100000 + 5], B[100000 + 5], Bh, C[100000 + 5], Ch,
D[100000 + 5], Dh, G[100000 + 5], F[100000 + 5][350 + 5], fr[100000 + 5],
en[100000 + 5], Fs[350 + 5][350 + 5], ToT[100000 + 5], Ans;
const long long Maxn = 2e9;
inline bool cmp(int x, int y)... | 11 |
#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> v, pl;
vector<pair<int, int>> s;
vector<vector<int>> ans;
vector<int> rec(int ind, vector<int>& t, map<int, bool>& ch) {
if (ch[ind]) return t;
t.push_back(ind + 1);
ch[ind] = 1;
int x = pl[ind];
pl[ind] = -1;
return rec(x, t, ch);
}
int main(... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int T;
cin >> T;
while (T--) {
int n;
cin >> n;
vector<int> a(n + 1, 0);
int most = 0;
int mostCount = 0;
for (int i = 0; i < int(n); i++) {
int cake;
cin >> cake;
a[cake]++;
if (a[cake] > most) {
mo... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n, c;
int bs[31];
int main() {
cin >> n;
int tx = 0;
for (int i = 0; i < n; i++) {
cin >> c;
tx ^= c;
for (int j = 30; j >= 0; j--) {
if (c & (1 << j)) {
if (bs[j])
c ^= bs[j];
else {
bs[j] = c;
break... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int i, j, k, ans = 0, n;
cin >> n;
string s;
cin >> s;
for (i = 0; i < s.size(); i++) {
if (s[i] == 'R') {
for (j = i + 1; j < s.size(); j++)
if (s[j] == 'L') {
for (k = i; k <= j; k++) s[k] = '0';
if ((j - i) % 2... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, s, v(0);
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 0; i < n - 1; i++)
if (a[i] > a[i + 1]) s = i, v++;
if (a[n - 1] > a[0]) s = n - 1, v++;
if (v == 0)
cout << 0 << endl;
else if (v > 1)
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int x[1005], y[1005], r[1005];
int main() {
int gnrs, c1 = 1, c2 = 1, c3 = 1, c4 = 1, gnr, x1, x2, y1, y2, n, i, j, k,
minx, miny, maxx, maxy, xx, yy;
cin >> x1 >> y1 >> x2 >> y2 >> n;
for (i = 0; i < n; i++) cin >> x[i] >> y[i] >> r[i];
minx = min(x1, x... | 2 |
#include <bits/stdc++.h>
using namespace std;
const long long int N = 5e5 + 5;
long long int n, m, k, a, b, temp;
string str;
set<long long int> s;
vector<long long int> v;
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
;
long long int i;
cin >> n >> m;
cin >> k;
v.res... | 5 |
#include <bits/stdc++.h>
using namespace std;
int n, k;
int a[400005][5];
int c[2] = {-1, 1};
int mx[800005][1 << 5];
int calc(int* x, int s) {
int ret = 0;
for (int i = 0; i < k; i++) {
ret += c[s >> i & 1] * x[i];
}
return ret;
}
void merge(int o) {
for (int i = 0; i < (1 << k); i++) {
mx[o][i] = ma... | 7 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
char a[1100][1100];
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
bool u[10];
void G(const int x, const int y) {
for (int i = 0; i <= 3; ++i) {
int X = x + dx[i], Y = y + dy[i];
if (a[X][Y] <= 'D' && a[X][Y] >= 'A') u[a[X][Y] - 'A'] = 1;
}
}
bool ok(... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t = 1;
while (t--) {
int n, m;
cin >> n >> m;
int a[n + 1];
long long minsuma[n + 1];
for (int i = 1; i <= n; i++) {
cin >> a[i];
minsuma[i] = 1e18;
}
int b[m +... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a1, b1, a2, b2;
scanf("%d%d%d%d", &a1, &b1, &a2, &b2);
int valid = 0;
if (a1 <= b2 + 1 && b2 <= 2 * (a1 + 1)) valid = 1;
if (b1 <= a2 + 1 && a2 <= 2 * (b1 + 1)) valid = 1;
if (valid)
printf("YES");
else
printf("NO");
return 0;
}
| 2 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:1000000000")
using namespace std;
const int maxn = (int)3e5 + 10;
struct vt {
double x, y;
vt() : x(0), y(0) {}
vt(double x, double y) : x(x), y(y) {}
};
vt operator+(vt a, vt b) {
a.x += b.x;
a.y += b.y;
return a;
}
struct mat {
double a[2][2];
m... | 8 |
#include <bits/stdc++.h>
using namespace std;
int fa[100010];
int Find(int x) { return fa[x] == x ? x : fa[x] = Find(fa[x]); }
int main() {
int n, k, x, y;
scanf("%d%d", &n, &k);
for (int i = 1; i <= n; i++) fa[i] = i;
int ans = 0;
for (int i = 1; i <= k; i++) {
scanf("%d%d", &x, &y);
int g1 = Find(x)... | 4 |
#include <bits/stdc++.h>
using namespace std;
double dp[51][200001];
double A[200001];
double suf[200002];
double cst[200002];
double inv[200002];
const double EPS = 1e-9;
inline double compute(int L, int R) {
return cst[L] - cst[R + 1] - (suf[L] - suf[R + 1]) * (inv[R + 1]);
}
int cost(int n, int qL, int qR, int k) ... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int INF = (1 << 30) - 1;
const int maxn = 1 << 17;
long long n, pos[maxn];
int vis[maxn];
struct node {
long long id, d, s;
} t[maxn];
int main() {
queue<int> Q;
long long cnt = 0;
scanf("%I64d", &n);
for (long long i = 0; i < n; ++i) {
scanf("%I64d%I64d... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2000;
long long grafo[MAXN][MAXN];
int main() {
long long sum = 0, cnt = 0;
int n = 0, k = 0, temp = 0;
cin >> n >> k;
for (int i = 0; i < n - 1; ++i) {
grafo[i][i] = -1;
for (int j = i + 1; j < n; ++j) {
scanf("%d", &temp);
graf... | 8 |
#include <bits/stdc++.h>
using namespace std;
int L[5];
long long c;
long long A[100000], B[100000];
int n;
long long days(long long mid) {
long long act = n;
for (int i = (0); i < (n); i++) {
if (A[i]) act += (mid / B[i]);
if (act > c) return c + 1;
}
act = n;
for (int i = (0); i < (n); i++) {
ac... | 4 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:20000000")
using namespace std;
int ri() {
int x;
scanf("%d", &x);
return x;
}
long long rll() {
long long x;
scanf("%lld", &x);
return x;
}
long long fact[200500];
long long rev[200500];
long long MOD = 1e9 + 7;
long long bin_s(long long x, long long... | 7 |
#include <bits/stdc++.h>
using namespace std;
long long int mod = 1e9 + 7;
const long double error = 2e-6;
const long double PI = acosl(-1);
mt19937 rng((unsigned)chrono::system_clock::now().time_since_epoch().count());
inline long long int MOD(long long int x, long long int m = mod) {
long long int y = x % m;
retu... | 8 |
#include <bits/stdc++.h>
using namespace std;
int t, n, a[1010], s[2];
int main() {
scanf("%d", &t);
while (t--) {
scanf("%d", &n);
s[0] = s[1] = 0;
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
s[a[i]]++;
}
if (s[0] >= n / 2) {
printf("%d\n", s[0]);
for (int i = 0; i... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string s1, s2, s3 = "";
cin >> s1 >> s2;
for (int i = 0; i < n; i++) {
s3 += to_string(((s1[i] - '0') + (s2[i] - '0')) % 2);
}
s3 += '0';
int count = 0;
for (int i = 0; i < n; i++) {
if (s3[i] == '1') {
if (s3[i ... | 2 |
/*
* CM = March
* M = April
* IM = July
* GM = September
* IGM = December
*/
// region config
#include <bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define mp make_pair
typedef long long int lli;
#define pll pair<lli, lli>
#define pil pair<int, lli>
#define pli pair<lli, int>
#de... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 30010;
struct State {
bitset<MAX> left;
bitset<MAX> right;
long long len = 0, res = 0;
};
int n;
bitset<MAX> all;
State Unite(const State &a, const State &b) {
State c;
c.len = a.len + b.len;
c.res = a.res + b.res;
c.left = a.left;
c.right = ... | 13 |
#include <bits/stdc++.h>
using namespace std;
typedef struct {
int x, y;
} Tlho;
bool bunga(Tlho a, Tlho b) {
if (a.x + a.y != b.x + b.y) return a.x + a.y < b.x + b.y;
return a.x < b.x;
}
vector<Tlho> wew;
int main() {
int N;
scanf("%d", &N);
int y;
for (y = N / 7; y >= 0; y--) {
int sisa = N - 7 * y;... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long mod = 1e9 + 7;
int t;
cin >> t;
while (t--) {
long long n, ans = 1;
cin >> n;
for (int i = 3; i <= 2 * n; i++) {
ans = (ans * i) % mod;
}
cout << ans << endl;
}
return 0;
}
| 0 |
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <random>
using namespace std;
const int N = 1005;
const int M = 10005;
const double P = 0.6892;
int n, m;
char s[N];
int wrong[N];
double pr[M];
mt19937 gen(19260817);
void solve()
{
scanf("%s", s);
double sum = 0.0;
int mn = *min_element(wr... | 9 |
#include <bits/stdc++.h>
int main(void) {
int w, h, k, c, e;
scanf("%d %d %d", &w, &h, &k);
c = 0;
do {
e = (w * h) - ((w - 2) * (h - 2));
w -= 4;
h -= 4;
c += e;
} while (--k);
printf("%d", c);
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
static int N;
static int M;
static int Q;
static int w[500000];
static int C[4096];
static int cost[4096];
static int ans[4096][101];
static int read10(void) {
int c;
while ((c = getchar()) < '0') continue;
int n = 0;
do n = 10 * n + c - '0';
while ((c = getchar()... | 5 |
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long t, n, i, j, k, m, q;
string s;
t = 1;
while (t--) {
cin >> n;
vector<vector<long long>> grid(3, vector<long long>(n, 0));
vector<vector<long long>> dp(
3, vec... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, i;
cin >> n;
int arr[n], tot = 0, mx = 0;
for (i = 0; i < n; i++) {
cin >> arr[i];
tot += arr[i];
mx = max(mx, arr[i]);
}
mx--;
int tot2 = 0;
while (tot2 <= tot) {
mx++;
tot2 = 0;
for (i = 0; i < n; i++) {
to... | 0 |
#include <bits/stdc++.h>
using namespace std;
int n, k, t;
struct Stats {
long long int nBefore, nAfter, sLeft, sRight;
};
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> k;
map<int, int> num;
for (int i = 0; i < n; i++) {
cin >> t;
if (num[t]) {
num[t]++;
} else
nu... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 5;
const int mod = 1e9 + 7;
const long long INF = 2e15;
long long qpower(long long a, long long b) {
long long ans = 1;
while (b > 0) {
if (b & 1) ans = ans * a % mod;
b >>= 1;
a = a * a % mod;
}
return ans;
}
long long n, k;
int m... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e6 + 5;
int n, A[N], P[N], f[N];
void solve() {
scanf("%d", &n);
for (int i = 0; i < n; ++i) scanf("%d", &A[i]);
for (int i = 1; i < 2 * n; ++i) P[i] = -1, f[i] = n + 1;
f[0] = f[1] = -n;
for (int i = 1; i < n; ++i)
for (int x = 0; x < 2; ++x)
... | 10 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 1e6 + 5;
int n, m, deg[N], fa[N], vis[N], rt;
ll ans, s, k;
int fd(int x) { return fa[x] == x ? x : fa[x] = fd(fa[x]); }
int main() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; ++i) fa[i] = i;
for (int i = 1, x, y; i <= m; ++i) ... | 6 |
#include <bits/stdc++.h>
using namespace std;
int a[25];
void rotate(vector<int> t) {
for (int j = 0; j < 2; j++) {
int temp = a[t[0]];
for (int i = 1; i < t.size(); i++) a[t[i - 1]] = a[t[i]];
a[t.back()] = temp;
}
}
void move(int type) {
if (type == 0) rotate({1, 3, 5, 7, 9, 11, 24, 22});
if (type... | 3 |
#include <bits/stdc++.h>
using namespace std;
vector<int> in(1024, 0);
bool check(int k) {
for (int i = 0; i < 1024; i++) {
if (in[i] && in[i ^ k] == 0) return 0;
}
return 1;
}
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
int t;
cin >... | 2 |
#include <bits/stdc++.h>
using namespace std;
char str[50009];
int A[50009], B[50009];
struct node {
int id, cost;
node() {}
node(int n1, int n2) : id(n1), cost(n2) {}
};
bool operator<(const node &elem1, const node &elem2) {
return elem1.cost > elem2.cost;
}
int n;
void solve() {
int balance = 0;
long long... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
vector<pair<long long, int> > a;
for (int i = 0; i < n; ++i) {
long long x;
cin >> x;
a.push_back(make_pair(x, i + 1));
}
vector<int> m(2 * n + 10, 1);
sort(a.begin(), a.end());
vector<int> ans(n + 1);
long... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int inf = int(1e9);
const double eps = 0.0000000001, pi = 3.14159265358979323;
const int maxn = int(2e5 + 100);
bool u[maxn];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n;
string s;
set<int> r, d;
cin >> n >> s;
for (int i = 0; i < n; ++i) {
... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long Factorial[2000003], F_Inv[2000003];
long long Power(long long base, long long times) {
if (base == 0) return 0L;
if (times == 1) return base;
long long ans = 1;
long long base_binary = base;
while (times > 0) {
if (times % 2 == 1)
ans = ((ans %... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 7340033;
long long dp[31][1001];
void init() {
dp[0][0] = 1;
for (int i = 1; i < 31; i++) {
long long tmp[5][1001];
memset(tmp, 0, sizeof(tmp));
tmp[0][0] = 1;
for (int j = 0; j < 4; j++) {
for (int k = 0; k < 1001; k++) {
f... | 7 |
#include <bits/stdc++.h>
using namespace std;
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
long long q;
cin >> q;
while (q--) {
string tmp;
cin >> tmp;
string num;
for (long long i = 4; i < (long long)tmp.size(); i++) {
num.push_back(tmp[i]);
}
long long k ... | 6 |
#include <bits/stdc++.h>
using namespace std;
char getc() {
char c = getchar();
while ((c < 'A' || c > 'Z') && (c < 'a' || c > 'z') && (c < '0' || c > '9'))
c = getchar();
return c;
}
int gcd(int n, int m) { return m == 0 ? n : gcd(m, n % m); }
int read() {
int x = 0, f = 1;
char c = getchar();
while (c... | 11 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18;
const long long SIZE = 5e3 + 5;
const long long mod = 1e9 + 7;
bool ok[SIZE];
bool vis[SIZE];
vector<long long> adj[SIZE];
vector<pair<long long, long long> > conn;
long long cap, cnt;
void dfs(long long u) {
if (ok[u]) return;
ok[u] = 1;
l... | 6 |
#include <bits/stdc++.h>
using namespace std;
inline int L(int i) { return i << 1; }
inline int R(int i) { return (i << 1) | 1; }
inline int B(int i) { return 1 << i; }
inline int low_bit(int x) { return x & (-x); }
long long cnt[1010], top;
long long tmp, mul;
bool must_win(long long a, long long b) {
if (a == 0 || ... | 7 |
#include <bits/stdc++.h>
using namespace std;
bool cmp(pair<int, int> &a, pair<int, int> &b) {
if (a.first == b.first) return a.second < b.second;
return a.first > b.first;
}
bool isSquare(int n) {
int s = sqrt(n);
return (s * s == n);
}
bool isFibo(int n) {
return isSquare(5 * n * n + 4) || isSquare(5 * n * ... | 0 |
#include <bits/stdc++.h>
using namespace std;
int l, r, p, prime[110], rez;
vector<int> V, dp, counted;
bool check(int x) {
for (int i = 2; i < x; ++i)
if (x % i == 0) return 0;
return 1;
}
void rek(int a, int b) {
if (b > p) return;
if (prime[b]) {
if ((long long)a > r / b) return;
rek(a, b + 1);
... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int viz[N];
vector<int> v[N], vt[N];
bool has, viz1[N], viz2[N];
void check(int x) {
viz[x] = 1;
for (auto it : v[x]) {
if (viz[it] == 1) has = 1;
if (!viz[it]) check(it);
}
viz[x] = 2;
}
void dfs1(int x) {
viz1[x] = 1;
for (auto i... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int n;
pair<int, int> event[N];
int nxt2[N], nxt4[N];
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", &event[i].first);
if (event[i].first == 1 || event[i].first == 3) {
scanf("%d", &event[i].second);
}
... | 5 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void checkmin(T &a, T b) {
if (b < a) a = b;
}
template <class T>
inline void checkmax(T &a, T b) {
if (b > a) a = b;
}
int N, K;
vector<int> G[50061];
int dp[50061][510];
long long ans;
void dfs(int u, int p) {
for (int i = (0); i < (int)(((... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
long long node[4 * N], root[4 * N], inds[N], indf[N], h[N], CNT, n, q;
vector<int> adj[N];
void DFS(int v, int par) {
inds[v] = CNT++;
for (int i = 0; i < adj[v].size(); i++)
if (adj[v][i] != par) {
h[adj[v][i]] = h[v] + 1;
DFS(ad... | 6 |
#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 100100;
const long long INF = 2000000100;
const long long MOD = 998244353;
long long N, S, startS, BC;
long long P[MAXN], maxH;
vector<long long> VH[MAXN];
void output() {
cout << "Yes\n";
for (int i = 2; i <= N; i++) {
cout << P[i] << (i == N... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 100500;
const int maxn = 450;
int n, m;
int e[maxn][maxn];
void scan() {
scanf("%d%d", &n, &m);
for (int i = 0; i < (int)(m); ++i) {
int x, y;
scanf("%d%d", &x, &y), --x, --y;
e[x][y] = e[y][x] = 1;
}
}
int d[maxn], q[maxn];
int bfs()... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 5005;
const int inf = 1e9 + 7;
int pr[] = {2, 3, 5, 7, 11, 13};
int up;
int tot[105];
int q[50000005], vis[1000005];
int sz;
pair<int, int> srt[1000005];
void dfs(int x, int y) {
if (y == sz) {
q[x] = 1;
return;
}
dfs(x, y + 1);
x *= pr[y];
w... | 7 |
#include <bits/stdc++.h>
using namespace std;
string a;
int n, k;
int main() {
cin >> a >> k;
n = a.length();
if (n % k != 0) {
cout << "NO";
return 0;
}
int z = n / k;
for (int i = 0; i < k; i++)
for (int j = 0; j < z / 2; j++)
if (a[i * z + j] != a[(i + 1) * z - 1 - j]) {
cout <<... | 1 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.