solution stringlengths 53 181k | difficulty int64 0 13 |
|---|---|
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
const int mod = 1000000007;
const int N = 500005;
void Getnext(string &s, int *fail) {
int id = -1;
fail[0] = -1;
for (int i = 1; i < s.size(); ++i) {
while (~id && s[id + 1] != s[i]) id = fail[id];
if (s[id + 1] == s[i]) ++id;
f... | 9 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
long long MOD = 1e9 + 7;
const int N = (int)1e6;
long long mul(long long a, long long b, long long m) {
return ((a % m) * (b % m)) % m;
}
long long factorial(long long fac) {
if (fac <= 1) return 1;
long long res = 2;
for (int i = 3; i <= ... | 2 |
#include <bits/stdc++.h>
using namespace std;
string htb(char s) {
if (s == '0')
return "0000";
else if (s == '1')
return "0001";
else if (s == '2')
return "0010";
else if (s == '3')
return "0011";
else if (s == '4')
return "0100";
else if (s == '5')
return "0101";
else if (s == '6... | 5 |
#include <bits/stdc++.h>
using namespace std;
int n, m, k;
int a[2000][2000];
string s[1 << 20];
int main() {
cin >> n >> m >> k;
for (int i = 0; i < 2 * n - 1; i++) cin >> s[i];
if (k == 1) {
int c = 0;
for (int i = 0; i < 2 * n - 1; i++)
c += count(s[i].begin(), s[i].end(), 'E');
int tot = 2 *... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
int n, m, ans;
int val[maxn];
vector<int> adj[maxn], len[maxn];
bool vis[maxn];
int gcd(int a, int b) {
if (!a || !b) return a + b;
return gcd(b, a % b);
}
void dfs(int cur, int id) {
vis[cur] = 1;
val[cur] = id;
for (int i = 0; i < adj[c... | 7 |
#include <bits/stdc++.h>
using namespace std;
int num[105];
char str[105], st[105];
int main() {
int n, q, pos, flag, dir, l, r, i;
while (scanf("%d%d%s", &n, &q, str) != EOF) {
while (q--) {
memset(num, 0, sizeof(num));
memcpy(st, str, sizeof(str));
scanf("%d%d", &l, &r);
l--;
r--... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2000;
set<pair<int, int>> old, nw;
int n, kl[N][N];
int main() {
cin.tie(0);
int k, k1, k2, i, j, mxdp = 0;
string a[N];
cin >> n >> k;
for (i = 0; i < n; i++) cin >> a[i];
for (i = 0; i < n; i++) {
for (j = 0; j < n; j++) {
if (i && j)
... | 5 |
#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> adjMat(1001, vector<int>(1001));
void connect(vector<int> &a, vector<int> &b) {
for (int x : a) {
for (int y : b) adjMat[x][y] = adjMat[y][x] = 1;
}
a = move(b);
b.clear();
}
int main() {
int k;
cin >> k;
int node = 3;
for (int i = 0;... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int c = 805;
int n, ans[c], rem[c][10], ee;
bool v[c], kesz[c];
vector<int> spec, kell = {2, 3, 4, 5, 7, 8};
int veg1, veg2;
bool kerd() {
int db = 0;
for (int i = 1; i <= n; i++) {
db += v[i];
}
cout << "? " << db << " ";
for (int i = 1; i <= n; i++) {
... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 5;
int n;
int s[MAXN], e[MAXN];
int cnt, tot;
struct unq {
int val, id, op;
} u[4 * MAXN];
struct tr {
int cov, l, r, sum;
} t[16 * MAXN], an;
int ans;
bool cmp(const unq &a, const unq &b) { return a.val < b.val; }
tr operator+(const tr &a, const ... | 7 |
#include <bits/stdc++.h>
using namespace std;
vector<int> construct(int n) {
vector<int> ret = {3};
for (int i = 1; i < n; ++i) ret.push_back(i + 1 < n ? 2 : 2 * n);
return ret;
}
int main() {
int n, m;
scanf("%d%d", &n, &m);
vector<int> u = construct(n);
vector<int> v = construct(m);
for (int i = 0; i ... | 8 |
#include <bits/stdc++.h>
using namespace std;
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
vector<vector<int>> card(n);
int f = 0;
int s = 0;
for (int i = 0; i < n; i++) {
int sz;
cin >> sz;
card[i].resize(sz);
for (auto &t : card[i]) {
cin >... | 6 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
long long INF = 1e9;
const int N = 200031;
int n, k, m;
int cost[100][100];
int dp[100][100][100][3];
int main() {
ios_base::sync_with_stdio(0);
cin >> n >> k;
cin >> m;
for (int i = 0; i <= n + 1; i++) {
for (int j = 0; j <= n + 1; j+... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, a, maxDays;
cin >> n;
vector<int> days(n);
cin >> a;
maxDays = a;
days[0] = a;
for (int i = 1; i < n; i++) {
cin >> a;
days[i] = a;
}
if (a < maxDays) maxDays = a;
for (int i = 0; i < n; i++) {
if (days[i] < maxDays) {
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
vector<int> a;
cin >> n;
int x;
for (int i = 0; i < n; i++) {
cin >> x;
a.push_back(x);
}
sort(a.begin(), a.end());
int tt = 10;
int np = 0;
int pt = 0;
int i = 0;
for (i = 0; i < n; i++) {
if (a[i] + tt > 720) break;
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie();
cout.tie();
;
long long n, p, w, d;
cin >> n >> p >> w >> d;
for (long long i = 0; i < w; i++) {
long long val = p - i * d;
if (val % w == 0 && val / w + i <= n && val >= 0) {
cout << val ... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
int a[n + 10];
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
vector<int> v;
int k = 0, l = 0;
for (int i = 1; i <= n; i++) {
l++;
if (a[i] < 0) k++;
if... | 1 |
#include <bits/stdc++.h>
using namespace std;
void readi(int &x) {
int v = 0, f = 1;
char c = getchar();
while (!isdigit(c) && c != '-') c = getchar();
if (c == '-')
f = -1;
else
v = v * 10 + c - '0';
while (isdigit(c = getchar())) v = v * 10 + c - '0';
x = v * f;
}
void readll(long long &x) {
l... | 7 |
#include <bits/stdc++.h>
using namespace std;
int cnt[3600];
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
int h, m;
scanf("\n%d:%d", &h, &m);
cnt[h * 60 + m]++;
}
int ans = 0;
for (int i = 0; i < 1440; i++) {
if (cnt[i] == 0) {
int cur = 1, j = (i + 1) % 1440;
whil... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, a, b;
cin >> n >> a >> b;
int ans = a + b;
while (ans <= 0) {
ans += n;
}
while (ans > n) {
ans -= n;
}
cout << ans;
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
long long n, q, x, y, a[200010], st[500], ed[500], ans = 0, t;
vector<long long> v[500];
int main() {
cin >> n >> q;
for (int i = 0; i < 495; i++) st[i] = -1;
t = (long long)sqrt(n);
for (int i = 0; i < n; i++) {
if (st[i / t] == -... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int maxn = 1e6 + 50;
const int maxa = 2e6 + 50;
int n, a[maxn];
pair<int, int> dp[maxa];
void updata(int x, int pos) {
if (dp[x].first < pos) {
dp[x].second = dp[x].first;
dp[x].first = pos;
} else if (dp[x].second < pos && pos ... | 9 |
#include <bits/stdc++.h>
using namespace std;
inline void prep() {
cin.tie(0);
cin.sync_with_stdio(0);
}
const int MOD = (int)1e9 + 7;
const int MX = (int)2e5 + 1;
int ds[MX];
bool marked[MX];
int Find(int x) { return ds[x] < 0 ? x : ds[x] = Find(ds[x]); }
bool Unite(int x, int y) {
int xx = Find(x);
int yy = F... | 4 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const int N = 200000 + 7;
int main() {
std::ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t;
cin >> t;
while (t--) {
long long n;
cin >> n;
if (n < 15LL) {
cout << "NO\n";
} else {
n... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int nmax = 100005;
int st[nmax], dr[nmax];
long long sum[nmax];
int n, m, mn, mx, i, j, nr, cnt;
struct cv {
long long a;
int b, ind;
} v[nmax], el;
struct CMP {
bool operator()(cv unu, cv doi) { return unu.a > doi.a; }
};
priority_queue<cv, vector<cv>, CMP> pq;... | 4 |
#include <bits/stdc++.h>
inline int read() {
register int x = 0;
register int c = getchar();
while (c < '0' || c > '9') c = getchar();
while (c >= '0' && c <= '9') {
x = x * 10 + (c ^ 48);
c = getchar();
}
return x;
}
int n;
int ex[105];
int a, b;
int sum;
int main() {
n = read();
for (int i = 1... | 0 |
#include <bits/stdc++.h>
using namespace std;
set<long long> factores;
void fact(int n) {
for (int i = 2; i * i <= n; i++) {
if (n % i == 0) {
factores.insert(n / i);
factores.insert(i);
}
}
factores.insert(n);
return;
}
long long mulMod(long long a, long long b, long long m = 1000000007) {
... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int tc;
cin >> tc;
while (tc--) {
int N;
cin >> N;
for (int i = 0; i < N; i++) {
if (N & 1) {
if (i == N / 2) {
cout << 'b';
} else if (i == N / 2 + 1) {
cout << 'c';
} else {
cout <<... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, i, k = 1;
cin >> n;
int t[n];
for (i = 0; i < n; i++) {
cin >> t[i];
if (t[i]) k = 0;
}
if (k)
cout << "EASY";
else
cout << "HARD";
}
| 0 |
#include <bits/stdc++.h>
#pragma GCC optimize(2)
#pragma GCC optimize(3)
using namespace std;
inline int read() {
int x = 0, neg = 1;
char op = getchar();
while (!isdigit(op)) {
if (op == '-') neg = -1;
op = getchar();
}
while (isdigit(op)) {
x = 10 * x + op - '0';
op = getchar();
}
return... | 5 |
#include <bits/stdc++.h>
using namespace std;
int arr[13];
int main() {
int n;
cin >> n;
int i;
int maxi = 0;
for (i = 0; i < n; i++) {
cin >> arr[i];
maxi = max(maxi, arr[i]);
}
cout << (maxi ^ arr[n - 1]) << endl;
}
| 5 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T bigmod(T p, T e, T M) {
long long ret = 1;
for (; e > 0; e >>= 1) {
if (e & 1) ret = (ret * p) % M;
p = (p * p) % M;
}
return (T)ret;
}
template <class T>
inline T gcd(T a, T b) {
if (b == 0) return a;
return gcd(b, a % b);
}
... | 7 |
#include <bits/stdc++.h>
using namespace std;
long long powmod(long long base, long long exponent, long long mod) {
long long ans = 1;
while (exponent) {
if (exponent & 1) ans = (ans * base) % mod;
base = (base * base) % mod;
exponent /= 2;
}
return ans;
}
long long gcd(long long a, long long b) {
... | 4 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vd = vector<double>;
using vs = vector<string>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<doub... | 9 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
int32_t main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
long long n;
cin >> n;
vector<long long> v(n + 1);
for (long long i = 1; i <= n; i++) {
cin >> v[i];
}
vector<long long> s(n + 1), p(n + 1);
for (lo... | 6 |
#include <bits/stdc++.h>
using namespace std;
string s;
int main() {
cin >> s;
int ans = 0;
for (int lenght = 1, checker; lenght < s.length(); lenght++) {
checker = 0;
for (int i = 0; i <= s.length() - lenght; i++) {
checker = 1;
for (int j = i + 1; j <= s.length() - lenght; j++) {
if ... | 2 |
#include <bits/stdc++.h>
int main() {
using namespace std;
ios_base::sync_with_stdio(false), cin.tie(nullptr);
string S;
cin >> S;
int N = int(S.size());
int X;
cin >> X;
int factor_mask = 0;
for (int v = 1; v < X; v++) {
if (X % v == 0) {
factor_mask |= 1 << (v - 1);
}
}
vector<int>... | 10 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5;
const long long mod = 1e9 + 7;
long long test, n, query, q, k, value, m, x, val, a, b, c;
long long arr[N], brr[N];
int main() {
scanf("%lld", &test);
while (test--) {
scanf("%lld", &n);
arr[0] = 0;
for (int i = 1; i <= n; ++i) {
... | 1 |
#include <bits/stdc++.h>
using namespace std;
double const EPS = 1e-9, PI = acos(-1);
const int N = 1e6 + 9, M = 3e4 + 9, OO = 1e9 + 7, MOD = 1e9 + 7;
const long long inf = 1e18;
long long arr[N], mem[N][4], a, b;
int n, val;
set<int> primes;
vector<int> vec;
void factorize(int n) {
if (!(n & 1)) primes.insert(2);
... | 7 |
#include <bits/stdc++.h>
using namespace std;
int a[60][60], b[60][60];
int n, m;
int main() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++) scanf("%d", &a[i][j]);
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++) scanf("%d", &b[i][j]);
for (int i = 1; i <= n; ... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string *s = new string[n];
for (int i = 0; i < n; i++) {
cin >> s[i];
}
int groups = 0;
for (int i = 0; i < n; i++) {
int j = i;
for (; j < n; j++) {
if (s[j][0] == s[i][1]) {
break;
}
}
gro... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
const vector<int> mods = {998244353, 1000000007, 1000000009};
const long long inf = 3e18;
const double pi = acos(-1.0);
const double eps = 0.0000001;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template <class... K>
using ... | 12 |
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-10;
long long sqr(long long a) { return a * a; }
struct gr {
bool l[111];
};
long long n, m;
vector<gr> v;
gr g;
int main() {
cin >> n >> m;
long long ans = 0;
for (int i = 0; i < n; ++i) {
int k;
cin >> k;
for (int j = 1; j <= m; +... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 30 + 20;
int n, a[N][N], row[N], col[N], sum;
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
cin >> a[i][j];
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
row[i] += a[i][j];
... | 0 |
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-8;
const int maxn = 1e5 + 9;
const double pi = 3.14159265358979323846264;
const long long inf = 2e17;
const int mod = 10007;
double x[maxn], y[maxn];
double sol(double x1, double y1, double x2, double y2) {
return sqrt((x1 - x2) * (x1 - x2) + (y1 - y... | 5 |
#include <bits/stdc++.h>
using namespace std;
int arr[5];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL), cout.tie(NULL);
int n, a;
cin >> n;
while (n--) {
cin >> a;
arr[a]++;
}
int ans = 0;
int tmp = min(arr[1], arr[2]);
arr[3] += tmp;
arr[1] -= tmp;
arr[2] -= tmp;
ans += ... | 6 |
#include <bits/stdc++.h>
using namespace std;
int n, k, a[16], b[16];
bitset<2005> f[1 << 16];
bool vis[16];
void solve(int s, int i) {
if (!(s & (s - 1))) return;
for (int u = 0; u <= n - 1; ++u)
if (s >> u & 1 && a[u] < i && f[s ^ (1 << u)][i - a[u]]) {
solve(s ^ (1 << u), i - a[u]);
return;
}... | 11 |
#include <bits/stdc++.h>
using namespace std;
int debug = 0;
bool is_vowel(char c);
bool is_prime(long long n);
long long bigmod(long long base, long long exp, long long mod);
vector<long long> factor(long long n);
char ara[200010];
int pal(int s, int e, int l, int r) {
if (l > s or r < e) return 0;
if (ara[s] != a... | 2 |
#include <bits/stdc++.h>
using namespace std;
int w, h, n, p, p1, p2;
char c;
set<int> a[4];
multiset<int> b[2];
set<int>::iterator wi, hi;
void solve(int d, int p) {
p1 = *a[d].lower_bound(p);
p2 = -(*a[d + 2].lower_bound(-p));
a[d].insert(p);
a[d + 2].insert(-p);
b[d].erase(b[d].find(p1 - p2));
b[d].inser... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
float n, k;
cin >> n >> k;
if (k / 2 <= n) {
cout << n;
} else {
k = k - 2 * n;
if (n - k < 0) {
cout << "0";
} else
cout << n - k;
}
return 0;
}
| 0 |
#include <bits/stdc++.h>
int c[105];
int N;
int X, Y;
int t;
int main() {
int i;
scanf("%d", &N);
for (i = 1; i <= N; i++) {
scanf("%d", &t);
c[i] += t;
}
for (i = 1; i <= N; i++) {
c[i] += c[i - 1];
}
scanf("%d %d", &X, &Y);
for (i = 1; i <= N; i++) {
if ((X <= c[i - 1] && c[i - 1] <= Y... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
cout << "? ";
for (int i = 0; i < 100; i++) cout << i << " ";
cout << endl;
int first;
cin >> first;
cout << "? ";
int cnt = 128;
for (int i = 0; i < 100; i++) {
cout << cnt << " ";
cnt += 128;
}
cout << endl;
int second;
cin >> ... | 3 |
#include <bits/stdc++.h>
using namespace std;
using INT = long long;
int main() {
int n;
cin >> n;
if (n % 4 == 2 || n % 4 == 3) return puts("NO"), 0;
puts("YES");
vector<pair<int, int> > ans;
for (int i = 1; i < n; i += 2)
for (int j = i + 2; j < n; j += 2) {
ans.push_back({i, j});
ans.push... | 11 |
#include <bits/stdc++.h>
using namespace std;
int n, m, k;
long long cnt, sum, mx, ans = 0;
bool flag, gov[1010], vis[1010];
vector<int> vec, edges[1010];
void dfs(int u) {
vis[u] = 1;
for (int v : edges[u])
if (!vis[v]) dfs(v);
++cnt;
flag |= gov[u];
}
int main() {
int u, v, i;
cin >> n >> m >> k;
fo... | 3 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
cerr << *it << " = " << a << endl;
err(++it, args...);
}
long long mod = 1e9 + 7;
long long powm(lon... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
bool wa = false;
int n, x0, first, last, s, e;
scanf("%d%d", &n, &x0);
scanf("%d%d", &s, &e);
first = min(s, e);
last = max(s, e);
for (int i = 1; i < n; i++) {
scanf("%d%d", &s, &e);
if (min(s, e) > first) first = min(s, e);
if (max(s... | 1 |
#include <bits/stdc++.h>
using namespace std;
int N, M;
int A[100004];
int B[100004];
int freqA[100004];
int freqB[100004];
set<int, greater<int> > S;
vector<pair<int, int> > P[100004];
int next(int x) {
int res = *S.begin();
set<int, greater<int> >::const_iterator it = S.upper_bound(M - x);
if (it != S.end()) {
... | 7 |
#include <bits/stdc++.h>
int main() {
int n, x, y, a, b, v;
double t, t2;
scanf("%d %d %d", &x, &y, &n);
scanf("%d %d %d", &a, &b, &v),
t = (double)sqrt(pow((a - x), 2) + pow((b - y), 2)) / v;
for (int i = 1; i < n; i++) {
scanf("%d %d %d", &a, &b, &v),
t2 = (double)sqrt(pow((a - x), 2) + po... | 0 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int dfs(vector<int>& v, int bit) {
if (bit == -1) {
return 0;
}
vector<int> zero, one;
for (int i = (int)0; i < (int)v.size(); ++i) {
if (v[i] & 1 << bit) {
one.push_back(v[i]);
} else {
zero.push_back(v[i]);
}
}
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int n, m, a[111][111], mn, k, mx = -2000000000;
int main() {
cin >> n >> m;
for (int i = 1; i <= n; i++) {
mn = 2000000000;
for (int j = 1; j <= m; j++) {
cin >> a[i][j];
mn = min(a[i][j], mn);
}
if (mn > mx) {
mx = mn;
k = i;
... | 1 |
#include <bits/stdc++.h>
using namespace std;
void Weapons19() {
cin.sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
}
vector<vector<long long int>> d;
void sieve() {
for (long long int i = 1; i < 100005; i++) {
for (long long int j = i; j < 100005; j += i) {
d[j].push_back(i);
}
}
}
int32_t ma... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, m;
cin >> n >> m;
string s;
cin >> s;
long long c = 0, v = 0, f = 0;
for (long long i = 0; i < s.size(); i++) {
if (s[i] == '.') {
c++;
f = 1;
}
if (s[i] != '.' and f == 1) {
v += c - 1;
c = 0;
... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e5;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t;
cin >> t;
while (t--) {
string cad;
cin >> cad;
if (cad.size() >= 5) {
if (cad[cad.size() - 2] == 'p' && cad[cad.size() - 1] == 'o')
... | 0 |
#include <bits/stdc++.h>
using namespace std;
vector<long long int> tree[800020];
vector<long long int> ad[200005];
set<long long int> S;
long long int a[200005];
void build(long long int st, long long int en, long long int idx) {
if (st == en) {
tree[idx].push_back(a[st]);
} else {
long long int md = (st +... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 152;
const int inf = 1e9;
int dp[maxn][maxn][maxn];
int res[maxn][maxn];
char s[maxn];
int a[maxn];
int main() {
int n, ans;
scanf("%d", &n);
for (int i = 0; i < n; i++) scanf("%d", &a[i + 1]);
a[0] = -1;
scanf("\n%s", s);
memset(dp, -1, sizeof(... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
int l[300001], r[300001];
vector<int> x(n);
for (int i = 0; i <= n; i += 1) {
l[i] = n;
r[i] = 0;
}
for (int i = 0; i < n; i += 1) {
cin >> x[i];
l[x[i]] =... | 6 |
#include <bits/stdc++.h>
using namespace std;
struct TrieNode {
int child[5];
void config(int x) { memset(child, -1, sizeof(child)); }
};
TrieNode nodePool[2000000];
class Trie {
int cnt;
TrieNode *ptr;
public:
Trie() {
nodePool[0].config(0);
ptr = nodePool;
cnt = 1;
}
void addWord(const cha... | 6 |
#include <bits/stdc++.h>
using namespace std;
char s[1005][100];
bool val[1005];
int main() {
int n;
scanf("%d", &n);
scanf("%s", s[0]);
int m;
scanf("%d", &m);
for (int i = 1; i <= m; i++) scanf("%s", s[i]);
for (int i = 1; i <= m; i++) val[i] = true;
for (int i = 1; i <= m; i++) {
for (int j = 0; ... | 3 |
#include <bits/stdc++.h>
using namespace std;
char s[1000000];
const int ati = 2 * '0';
int main() {
int n = 0;
for (int i = 0; scanf("%c", s + i) != EOF; i++, n++)
;
char x, y;
long long cnt = 0;
long long ans = 1;
for (int i = 1; i < n; i++) {
if (s[i - 1] + s[i] - ati == 9) {
cnt = 1;
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int frc[262144], ifr[262144];
long long quickpow(long long x, int k) {
long long ret = 1;
for (; k; k >>= 1, x = x * x % 998244353)
(k & 1) && (ret = ret * x % 998244353);
return ret;
}
int main() {
int n;
long long k;
scanf("%d%lld", &n, &k);
if (k >= n) ... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n;
cin >> n;
cout << n;
for (int i = 1; i < n; i++) {
cout << " " << i;
}
return 0;
}
| 4 |
#include <bits/stdc++.h>
using namespace std;
const int SIZE = 128;
char astr[SIZE], bstr[SIZE], img[SIZE];
int n, m, k;
int pref[SIZE];
int res[SIZE][SIZE][SIZE];
int father[SIZE][SIZE][SIZE];
void relax(int &xres, int &xf, int nres, int nf) {
if (xres < nres) {
xres = nres;
xf = nf;
}
}
int main() {
sca... | 6 |
#include <bits/stdc++.h>
int n, m, tot;
std::pair<int, int> diag[(100010)];
std::vector<int> vec[(100010)];
std::vector<int> node[(100010)];
int ans[(100010)], sz[(100010)];
bool vis[(100010)];
bool cmp(const std::pair<int, int> &A, const std::pair<int, int> &B) {
int a = std::min(A.second - A.first - 1, (n - 2) - (A... | 10 |
#include <bits/stdc++.h>
using namespace std;
int can[4][1100];
int can2[1100];
int can3[1100];
int can4[1100];
int main() {
int n, m;
cin >> n >> m;
int a, b;
for (int i = 0; i < m; i++) {
scanf("%d%d", &a, &b);
can[0][a]++;
can[1][b]++;
can[2][a]++;
can[3][b]++;
}
int cou = 0;
for (i... | 5 |
#include <bits/stdc++.h>
using namespace std;
int k[500000], c[500000], a;
void s2(int x1, int y1, int x2, int y2) {
int l = x1, x = x1;
while ((x1 <= y1 || x2 <= y2) && l <= y2) {
if (x1 == y1 + 1) {
c[l] = k[x2];
x2++;
l++;
} else if (x2 == y2 + 1) {
c[l] = k[x1];
l++;
... | 4 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
void maxtt(T& t1, T t2) {
t1 = max(t1, t2);
}
template <typename T>
void mintt(T& t1, T t2) {
t1 = min(t1, t2);
}
bool debug = 0;
int n, m, k;
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
string direc = "RDLU";
long long ln, lk, lm;
void etp(b... | 8 |
#include <bits/stdc++.h>
using namespace std;
namespace thecold {
inline int read() {
int res = 0;
bool flag = false;
char c = getchar();
while (!isdigit(c)) flag = (c == '-'), c = getchar();
while (isdigit(c)) res = res * 10 + (c ^ 48), c = getchar();
return !flag ? res : -res;
}
const int Max_n = 5e5 + 5;... | 13 |
#include <bits/stdc++.h>
using namespace std;
long long n, mod, l, k, fibonacci, cnt, ones, zeroes, twopow;
pair<long long, pair<long long, pair<long long, long long>>> matrice_mod(
long long pw) {
if (pw == 1) return {0, {1, {1, 1}}};
pair<long long, pair<long long, pair<long long, long long>>> fibbo =
m... | 6 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
int n, d;
int p[2050];
long long dp[2050];
vector<int> v[2050];
void dfs(int x, int pre, int st) {
int i, j, k;
dp[x] = 1;
for (i = 0; i < v[x].size(); i++) {
if (v[x][i] == pre)
continue;
else
dfs(v[x][i], x, st);... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, i;
cin >> n;
int a[n];
stack<int> st;
for (i = 0; i < n; i++) {
cin >> a[i];
if (st.empty())
st.push(a[i]);
else if (abs(st.top() - a[i]) % 2 == 0)
st.pop();
else
st.push(a[i]);
}
if (st.size() > 1)
cou... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
string str;
int k;
int ans = 0;
cin >> n >> k;
for (int i = 0; i < (n); i++) {
int check = 0;
bool used[10] = {0};
cin >> str;
for (int j = 0; j < (str.size()); j++) {
used[str[j] - '0'] = true;
}
for (int j = 0;... | 1 |
#include <bits/stdc++.h>
using namespace std;
template <typename T1, typename T2>
inline ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
return os << "(" << p.first << ", " << p.second << ")";
}
template <typename T, size_t N>
inline ostream &operator<<(ostream &os, const array<T, N> &a) {
os << "[";
in... | 9 |
#include <bits/stdc++.h>
int ex[] = {1, -1, 0, 0};
int wye[] = {0, 0, 1, -1};
using namespace std;
char second[1005], an[1005];
int a[130], n, tmp, tpp;
vector<int> vt[1005], cnt;
bool visit[1005];
void seieve() {
for (int i = 2; i <= n; i++) {
if (visit[i]) continue;
for (int j = i + i; j <= n; j += i) {
... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10, mod = 1e9 + 7;
int T, p[maxn], tot, f[maxn], g[maxn];
vector<int> ve[maxn];
vector<pair<int, int> > ans;
void sieve(int n) {
tot = 0, f[1] = 1;
for (int i = 1; i <= n; i++) g[i] = f[i] = 0, ve[i].clear();
for (int i = 2; i <= n; i++) {
i... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int xy[4][2] = {{1, 0}, {0, -1}, {0, 1}, {-1, 0}};
int n, i, j, a[2222][2222], k1 = 0, k2 = 0, o[1111111][2];
long long ans = 0;
void white(int x, int y) {
int o1 = 1, o2 = 0;
o[0][0] = x;
o[0][1] = y;
while (o1 != o2) {
int x1 = o[o2][0], y1 = o[o2][1];
... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long max(long long i, long long j) { return i > j ? i : j; }
long long min(long long i, long long j) { return i < j ? i : j; }
int hcf(int a, int b) {
if (b == 0) return a;
return hcf(b, a % b);
}
int ncr(int n, int r) {
if (r == 0) return 1;
if (n == r) return... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int X = 55;
int n, m;
char str[X][X];
int x[X * X], y[X * X], top;
bool col(int a, int b, int yy) {
for (int j = min(b, yy); j <= max(b, yy); j++)
if (str[a][j] == 'W') return false;
return true;
}
bool row(int a, int b, int xx) {
for (int i = min(a, xx); i ... | 4 |
#include <bits/stdc++.h>
using namespace std;
int dir4[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
int dir8[8][2] = {{-1, 0}, {1, 0}, {0, 1}, {0, -1},
{-1, 1}, {1, -1}, {1, 1}, {-1, -1}};
int dir8h[8][2] = {{2, 1}, {-2, -1}, {-1, 2}, {1, -2},
{1, 2}, {-2, 1}, {2, -1}, {-1, -2}};
l... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 9;
int a[maxn], k, n, m;
pair<int, int> as[maxn];
vector<pair<int, int>> add[maxn];
vector<pair<long double, int>> mul;
int stac[maxn], top, op[maxn];
bool cmp(int x, int y) { return op[x] < op[y]; }
int main() {
cin >> k >> n >> m;
for (int i = 1... | 10 |
#include <bits/stdc++.h>
using namespace std;
long long m, k, h, n, i;
int main() {
cin >> m;
for (i = 5;; i += 5) {
h = i;
while (h % 5 == 0) {
n++;
h /= 5;
}
if (n > m) {
cout << 0;
return 0;
} else if (n == m) {
break;
}
}
cout << 5 << endl;
cout << i <... | 2 |
#include <bits/stdc++.h>
using namespace std;
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("O2")
#pragma GCC optimization("unroll-loops")
void read() { return; }
void wrt() { cout << (string) "\n"; }
void wrt(long long t) { cout << t; }
void wrt(int t) { cout << t; }
void wrt(char t) { cout << t; }
void ... | 4 |
#include <bits/stdc++.h>
int main() {
int n;
long long s;
long long a[1005];
scanf("%d%lld", &n, &s);
int i, j;
long long min = 1e9;
long long Sum = 0;
int flag = 0;
for (i = 0; i < n; i++) {
scanf("%lld", &a[i]);
if (a[i] < min) min = a[i];
Sum += a[i];
}
if (s > Sum) flag = 2;
long... | 2 |
#include <bits/stdc++.h>
using namespace std;
string s;
int n;
int z[8008];
void Zrocks_KMPsucks(string s) {
int l = 1, r = 1;
int n = s.size() - 1;
for (int i = 2; i <= n; ++i) {
if (r < i) {
l = r = i;
int st = 1;
while (r <= n && s[r] == s[st]) {
r++;
st++;
}
z... | 8 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
int main() {
ios::sync_with_stdio(0);
int n;
cin >> n;
vector<long long> a(n);
for (int i = 0; i < (n); i++) cin >> a[i];
long long ans = 0;
sort(a.begin(), a.end());
vector<long long> power2(n);
long long p = 1;
for (in... | 3 |
#include <bits/stdc++.h>
using namespace std;
char a[9][9];
int up[9], down[9], s1, s2;
const int Max = 1e9 + 1;
int main() {
s1 = s2 = Max;
for (int i = 1; i <= 8; i++)
for (int j = 1; j <= 8; j++) {
cin >> a[i][j];
if (a[i][j] == 'B') {
if (!down[j])
down[j] = 8 - i + 1;
... | 2 |
#include <bits/stdc++.h>
using namespace std;
template <typename A, typename B>
inline void smax(A &a, const B &b) {
if (a < b) a = b;
}
int a[51], w[51], dp[51][51][51][51];
int main() {
int n, A, B;
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%d", a + i);
for (int i = 1; i <= n; i++) {
int len ... | 8 |
#include <bits/stdc++.h>
using namespace std;
int n, m, x, y, t, ans, res, sum, mn = 1e9, cnt, mx, k, z, mnn = 1e9, mxx,
b = 1, i;
string s1, s3, s2, s;
set<int> st;
pair<int, int> p[1000001];
vector<int> v, v1, v3, v4, v2;
map<char, int> mp, mpp;
char c, d, e, a;
bool tr = false, fl =... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
const int L = 19;
int Lca[L][N], Depth[N], Dist, Deepest[N];
vector<int> graf[N];
int up(int a, int u) {
for (int i = 0; i < L; i++)
if (u & (1 << i)) a = Lca[i][a];
return a;
}
int lca(int a, int b) {
if (Depth[a] > Depth[b]) swap(a, b);
... | 11 |
#include <bits/stdc++.h>
using namespace std;
int n, a;
bool now, now2;
long long ans;
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &a);
if (!a) {
now2 = 1;
ans++;
continue;
}
if (a < 0) {
now ^= 1;
ans += -1 - a;
} else
ans += a - ... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
char brr[n][m];
for (int i = 0; i < n; i += 2) {
for (int j = 0; j < m; j += 2) brr[i][j] = 'B';
}
for (int i = 1; i < n; i += 2) {
for (int j = 1; j < m; j += 2) brr[i][j] = 'B';
}
for (int i = 0; i < n; i += 2)... | 2 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.