solution stringlengths 53 181k | difficulty int64 0 13 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-9;
const int N = 1e4 + 11;
char a[N], b[N];
int m, L, R, k;
int main() {
scanf("%s", a + 1);
a[0] = 'p';
int len = strlen(a);
scanf("%d", &m);
while (m--) {
scanf("%d%d%d", &L, &R, &k);
k = k % (R - L + 1);
for (int i = L; i <= R;... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
const int mm = 100005;
char s1[mm], s2[mm];
int check(char *sa, int a, char *sb, int b, int l) {
for (int i = 0; i < l; i++)
if (sa[a + i] != sb[b + i]) return 0;
return 1;
}
int main() {
int n;
while (cin >> n) {
int ans = 0;
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int k;
scanf("%d", &k);
for (int n = (1); n <= (2000); ++n)
if (n * 999999 > k) {
printf("%d\n-1", n + 1);
for (int i = (1); i <= (n); ++i)
printf(" %d", i < n ? 1000000 : (n + k) % 1000000 + 1);
printf("\n");
return 0;... | 6 |
#include <bits/stdc++.h>
using namespace std;
double PI = 3.14159265358979323843;
void Time() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
void print(int n) {
if (n == 0) {
return;
}
print(n - 1);
cout << "Hello world" << endl;
}
long long arr[100000];
int main() {
Time();
... | 2 |
#include <bits/stdc++.h>
using namespace std;
const double PI = 4 * atan(1.0);
void fast_stream() { std::ios_base::sync_with_stdio(0); }
const long long INF = 1000000000000LL;
long long minN = INF;
long long maxN = -INF;
void update(int a, int b, int c) {
minN = min(minN, (long long)(a + 1) * (b + 2) * (c + 2));
mi... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string n;
cin >> n;
int tam = n.size();
for (int i = 0; i < tam; i++) {
if (n[i] == '1' || (n[i] == '4' && (n[i - 1] == '1' || n[i - 2] == '1'))) {
} else {
cout << "NO";
return 0;
}
}
cout << "YES";
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
const int mod = 1e9 + 7;
struct matrix {
long long m[6][6];
void init() {
m[0][0] = m[1][1] = 1;
m[1][0] = m[0][1] = 0;
}
};
matrix data[maxn << 2], lazy[maxn << 2];
matrix operator*(matrix a, matrix b) {
matrix t;
memset(t.m, 0, ... | 7 |
#include<bits/stdc++.h>
#define M 1000000007
#define ll long long
#define pb push_back
#define pi pair<int,int>
#define mp make_pair
#define vi vector<int>
#define vb vector<bool>
#define vll vector <long long>
#define tests int tc; cin>>tc; while(tc--)
#define defsort(arr) sort(arr.begin(), arr.end());
#define csort(a... | 6 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = INT_MAX;
const long long MOD = 998244353;
long long extgcd(long long a, long long b, long long &x, long long &y) {
long long g = a;
x = 1;
y = 0;
if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x;
return g;
}
long long invMod(long long... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int k;
cin >> k;
while (k--) {
int x, y, a, b, tg;
cin >> x >> y >> a >> b;
tg = (y - x) % (a + b);
if (tg == 0)
cout << (y - x) / (a + b) << endl;
else
cout << "-1" << endl;
}
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int xx[] = {0, 1, 0, -1, -1, -1, 1, 1, -1};
int yy[] = {1, 0, -1, 0, 1, 1, -1, -1};
void vin(vector<int> &v, int n) {
int temp;
while (n--) {
cin >> temp;
v.push_back(temp);
}
}
int gcd(int a, int b) {
if (a == 0)
return b;
else
return gcd(b % a, a... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int ip, m;
char cp;
string s;
cin >> s;
ip = s[1] - 48;
cp = s[0];
if ((ip == 1 || ip == 8) && (cp == 'a' || cp == 'h'))
m = 3;
else if ((ip == 1 || ip == 8) && (cp >= 'b' || cp <= 'g'))
m = 5;
else if ((ip >= 2 || ip >= 7) && (cp == '... | 0 |
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1);
const int mo = 1051131, ni2 = (mo + 1) / 2;
int a[((1 << 25) + 10)], ans[((1 << 25) + 10)], m, s;
long long t;
int Pow(int x, long long y) {
int res = 1;
while (y) {
if (y & 1) res = 1ll * res * x % mo;
x = 1ll * x * x % mo;
y /= ... | 11 |
#include <bits/stdc++.h>
using namespace std;
int t, a, b, c, d;
int main() {
scanf("%d", &t);
while (t--) {
scanf("%d%d%d%d", &a, &b, &c, &d);
printf("%d\n", max(a + b, c + d));
}
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 55, D = 51;
int i, j, k, n, nn;
double p1, p2, t, sum, ans;
double a[N][N], b[N][N], f[N][N];
struct matrix {
double a[N][N];
matrix operator*(const matrix &n) const {
matrix t;
int i, j, k;
for (i = 1; i <= D; i++)
for (j = 1; j <= D; j+... | 12 |
#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
using namespace std;
int n, m, u, v, x, y, z;
vector<int> arr[5001];
bool a[5001];
bool vis[5001]{0};
void reset() {
for (int i = 0; i <= n; i++) {
arr[i].clear();
}
}
void ff() {
for (i... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int N = 4e5 + 7;
const int inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 998244353;
const double eps = 1e-8;
const double PI = acos(-1);
template <class T, class S>
inline void add(T& a, S b) {
a += b;
if (a >= mod) a -= mod;
}
templa... | 8 |
#include <bits/stdc++.h>
using namespace std;
double a[1002], b[1002];
int main() {
int n;
double m, cm;
cin >> n >> m;
cm = m;
for (int i = 1; i <= n; i++) {
cin >> a[i];
if (a[i] <= 1.0 + 1e-9) {
cout << "-1";
return 0;
}
}
for (int i = 1; i <= n; i++) {
cin >> b[i];
if (... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t, l, r;
cin >> t;
while (t--) {
cin >> l >> r;
if (l * 2 <= r)
cout << l << " " << l * 2 << endl;
else
cout << "-1 -1" << endl;
}
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int a[100001];
int main() {
int n, k;
scanf("%d %d", &n, &k);
int m;
int ans = 0;
int cnt = 0;
int Z = 0;
for (int i = 0; i < k; i++) {
scanf("%d", &m);
for (int j = 0; j < m; j++) scanf("%d", &a[j]);
if (a[0] == 1) {
cnt = 0;
int z = 1... | 3 |
#include <bits/stdc++.h>
using namespace std;
const long double EPS = 1e-15;
const long double INF = 1e18;
inline long double fix(long double tar) { return fabs(tar) <= EPS ? 0 : tar; }
struct Point {
long double x, y;
Point() {}
Point(long double x_, long double y_) { x = x_, y = y_; }
Point operator+(const Po... | 9 |
#include <bits/stdc++.h>
using namespace std;
int s[100005];
int book[4];
int main() {
int n, i;
memset(book, 0, sizeof(book));
memset(s, 0, sizeof(s));
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%d", &s[i]);
}
for (i = 0; i < n; i++) {
book[s[i]]++;
}
int count = 0;
count += book[4] ... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100010;
int c;
map<int, int> mp;
map<int, int>::iterator it;
struct I {
int f, x;
} ins[maxn];
long long s[maxn << 2][5];
int rev[maxn << 2];
void dorot(int rt, int v) {
long long tmp[5];
for (int i = 0; i < 5; i++) tmp[i] = s[rt][i];
if (v > 0) {
... | 7 |
#include <bits/stdc++.h>
using namespace std;
int n, k;
int ok(double x, double a[]) {
double z1 = 0, z2 = 0;
for (int i = 0; i < n; i++) {
if (x - a[i] > 0) {
z1 += x - a[i];
}
if (x - a[i] < 0) {
double ans = 1 - (k * (double)1) / 100;
z2 += (a[i] - x) * ans;
}
}
if (z1 <= z2... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long MOD = 1000000007;
long long gcd(long long a, long long b) {
long long c;
while (a != 0) {
c = a;
a = b % a;
b = c;
}
return b;
}
signed main() {
cin.tie(0);
ios::sync_with_stdio(false);
long long L[2];
long long R[2];
long long T[2];
... | 5 |
#include <bits/stdc++.h>
using namespace std;
void initMain() {}
int main() {
initMain();
long long N;
cin >> N;
vector<long long> rVec(N);
for (int i = 0; i < N; i++) scanf("%I64d", &rVec[i]);
long long minPos = N;
int ans = 0;
for (int i = N - 1; i >= 0; i--) {
if (i < minPos) ans++;
minPos = ... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long lb(vector<long long> v, long long lo, long long hi, long long ele) {
long long ans = -1;
while (lo <= hi) {
long long md = (lo + hi) / 2;
if (v[md] <= ele) {
ans = md;
lo = md + 1;
} else
hi = md - 1;
}
return ans;
}
int32_t m... | 4 |
#include <bits/stdc++.h>
std::mt19937 rng(
(int)std::chrono::steady_clock::now().time_since_epoch().count());
template <class Info = int, class T = int>
class ColorUpdate {
public:
struct Range {
Range(T _l = 0) : l(_l) {}
Range(T _l, T _r, Info _v) : l(_l), r(_r), v(_v) {}
T l, r;
Info v;
bo... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 23;
int n, m;
char s[maxn];
int a[maxn];
class SegTree {
private:
vector<int> tag, mn, mx;
vector<unsigned long long> st;
int n;
public:
void pushup(int o) {
st[o] = st[o << 1] + st[o << 1 | 1];
mx[o] = max(mx[o << 1], mx[o << 1 | 1... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000 + 10;
int n, k, a[maxn], d[maxn * 2];
int main() {
cin >> n >> k;
for (int i = 0; i < k; ++i) {
int t;
scanf("%d", &t);
a[t] = 1;
}
memset(d, -1, sizeof(d));
queue<int> que;
for (int i = 0; i < maxn; ++i) {
if (a[i]) {
... | 7 |
#include <bits/stdc++.h>
using namespace std;
int n, k, c[1000010], prime[1000010], a[30], len, tot;
bool check[1000010];
int main() {
scanf("%d%d", &n, &k);
for (int i = 1; i <= n; i++) scanf("%d", &c[i]);
for (int i = 2; i <= k; i++) {
if (!check[i]) prime[++tot] = i;
for (int j = 1; j <= tot; j++) {
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, k, mini = 1000000005, sum = 0;
cin >> n >> k;
long long A[n];
for (int i = 0; i < n; ++i) {
cin >> A[i];
mini = min(A[i], mini);
}
for (int i = 0; i < n; ++i) {
A[i] = A[i] - mini;
if (A[i] % k == 0) {
if (A[i] != ... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
inline int read() {
int x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = (x << 1) + (x << 3) + (ch ^ 48);
ch = getchar();
}
r... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int N = 200001;
struct node {
int nxt, to;
} e[N << 1];
int head[N], cnt = 0, siz[N], son[N], fa[N], max_son, col[N], a[N], maxx, n, x,
y, Son;
long long sum, ans[N];
void add(int u, int v) {
e[++cnt].nxt = head[u];
head[u] = cnt;
e[cnt].to = v;
}... | 7 |
#include <bits/stdc++.h>
using namespace std;
long long int n, m, need, visit[1001][1001], a[1001][1001], size[1001][1001],
came[1001][1001];
vector<pair<long long int, pair<long long int, long long int> > > v;
pair<long long int, long long int> par[1001][1001];
int valid(long long int x, long long int y) {
retur... | 6 |
#include <bits/stdc++.h>
using namespace std;
int n, k;
long long x[1003], y[1003];
long long dist[1003][1003];
vector<int> g[1003];
int vis[1003];
bool dfs(int u, int k) {
if (u == n) return true;
if (vis[u]) return dfs(u + 1, k);
for (int i = 0; i < g[u].size(); i++) k -= (!vis[g[u][i]]++);
if (k >= 0 && dfs(... | 11 |
#include <bits/stdc++.h>
int n, m;
long long f[2000006], ans;
int main() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= m; i++) {
int x, y;
scanf("%d%d", &x, &y);
f[x]++;
f[y]++;
}
for (int i = 1; i <= n; i++) {
ans += (n - f[i] - 1) * f[i];
}
ans /= 2;
printf("%I64d\n", 1LL * n * (n - ... | 5 |
#include <bits/stdc++.h>
using namespace std;
int N;
char s[100010];
int sum[26];
int main() {
scanf("%d", &N);
scanf("%s", s);
for (int i = 0; i < N; i++) sum[s[i] - 'a']++;
if (N == 1) return 0 * puts("Yes");
bool ok = false;
for (int i = 0; i < 26; i++) {
if (sum[i] > 1) ok = true;
}
puts(ok ? "Y... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long expo(long long a, long long b, long long m) {
long long result = 1;
while (b) {
if (b & 1) {
result = (result * a) % m;
}
b = (b >> 1) % m;
a = (a * a) % m;
}
return result;
}
bool comp(pair<int, int> a, pair<int, int> b) { return a.s... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long power(long long base, long long exp) {
if (exp == 0) return 1;
long long r = power(base, exp / 2);
r = (r * r) % 1000000007;
if (exp & 1) r = (r * base) % 1000000007;
return r;
}
int main() {
int i, j, t;
long long a, b, c, n;
long long x, y, z;
... | 2 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int lim = 2000000007;
vector <int> seq;
int T;
int n;
int main()
{
for (ll i = 3; i * i <= lim; i += 2)
seq.push_back((i * i + 1) / 2);
scanf("%d", &T);
while (T--) {
scanf("%d", &n);
int ind = upper_bound(seq.begin(), seq.end(), n) ... | 3 |
#include <bits/stdc++.h>
using namespace std;
int a[1004];
int size;
int n, m;
int main(void) {
while (scanf("%d %d", &n, &m) != EOF) {
size = 0;
int i;
for (i = 0; i < n; i++) {
int p;
scanf("%d", &p);
if (p < 0) a[size++] = p;
}
sort(a, a + size);
int sum = 0;
for (i = ... | 0 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
const int maxn = 2e5 + 3;
int n, m;
int a[maxn];
void read() {
cin >> n >> m;
for (int i = 1; i <= n; i++) cin >> a[i];
}
int actual[maxn];
int ans = 0;
void assign(int idx, int val) {
if (idx != 1 && actual[a[idx]] != actual[a[idx - 1]]) an... | 7 |
#include <bits/stdc++.h>
using namespace std;
int inf = 1e9;
const int N = 1e5 + 3;
int a[N];
multiset<pair<int, int>> al, mnset;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
if (i > 1) al.insert({a[i], i});
}
mn... | 5 |
#include <bits/stdc++.h>
using namespace std;
template <typename T1, typename T2>
istream& operator>>(istream& in, pair<T1, T2>& a) {
in >> a.first >> a.second;
return in;
}
template <typename T1, typename T2>
ostream& operator<<(ostream& out, pair<T1, T2> a) {
out << a.first << " " << a.second;
return out;
}
t... | 3 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const double PI = 3.14159265359;
long long twoPow(int val) {
if (!val) return 1;
if (val % 2) return (2 * twoPow(val / 2) * twoPow(val / 2)) % MOD;
return (twoPow(val / 2) * twoPow(val / 2)) % MOD;
}
int main() {
ios_base::sync_with_st... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e6 + 5;
int n, SQR, q;
long long freq[N], a[N];
long long Ans[N], res;
struct Query {
long long L, R, Index, Bucket_index;
} Range[N];
inline bool comp(Query x, Query y) {
if (x.Bucket_index != y.Bucket_index) return x.Bucket_index < y.Bucket_index;
if ... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, k;
cin >> n >> m >> k;
vector<int> data;
for (int i = 0; i < n; i++) {
int temp;
cin >> temp;
data.push_back(temp);
}
int a = 0, b = 0;
for (int i = m; i < n; i++) {
if (data[i] != 0 && data[i] <= k) {
a = i - m + 1... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 211111;
const long long base = 33ll;
int dl, dr, n;
set<pair<int, int> > cars;
vector<pair<int, int> > stay;
int main() {
cin >> n >> dl >> dr;
cars.insert(make_pair(-N, 0 - dl));
cars.insert(make_pair(n + dr, N));
int T;
cin >> T;
while (T--) {
... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 1;
const long long inf = 1e18 + 1;
const long long MOD = 1e9 + 7;
const long long MOD2 = 998244353;
const int MOD3 = 31607;
template <class T>
T _ceil(T a, T b) {
return (a + b - 1) / b;
}
template <class T>
T _min(T a, T b) {
return a > b ? b : a;... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 300000 + 3000;
int n, m;
int a[maxn], l[maxn], r[maxn], pos[maxn];
struct Segtree {
int l, r;
int val;
} node[maxn << 3];
inline int read() {
int x;
scanf("%d", &x);
return x;
}
inline void build(int p, int l, int r) {
node[p].l = l, node[p].r =... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = (int)1e5 * 2 + 7;
int a[maxn], b[maxn], t[4 * maxn], n, W, H;
void build(int v, int l, int r) {
if (r - l == 1) {
t[v] = a[l];
return;
}
build(2 * v + 1, l, (l + r) / 2);
build(2 * v + 2, (l + r) / 2, r);
t[v] = max(t[2 * v + 1], t[2 * v +... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 5;
char s[maxn];
long long num[maxn];
int main() {
long long t;
cin >> t;
while (t--) {
long long n, k, cnt = 0;
scanf("%lld%lld", &n, &k);
scanf("%s", s + 1);
for (long long i = 1; i <= n; i++) {
if (s[i] == '1')
c... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c[1005], used[1005] = {0}, i, j;
cin >> a >> b;
for (i = 1; i <= b; i++) {
int x, y, z, kol = 0;
cin >> x >> y >> z;
for (j = 1; j <= a; j++) {
if (used[j] <= x) kol++;
}
if (kol >= y) {
int ans = 0;
for (j ... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;
void solve() {
long long n;
cin >> n;
vector<long long> a(n);
for (long long i = 0; i < n; i++) cin >> a[i];
for (long long i = 1; i < n; i++) {
if (abs(a[i] - a[i - 1]) >= 2) {
cout << "YES" << endl;
cout << i << " " << i ... | 2 |
#include <bits/stdc++.h>
using namespace std;
int w, h, n;
priority_queue<pair<int, int> > seq[2];
set<int> cuts[2];
int main() {
scanf("%d %d %d ", &w, &h, &n);
seq[0].push(make_pair(h, 0));
seq[1].push(make_pair(w, 0));
for (int i = 0; i < (n); i++) {
char c;
int cut;
scanf("%c %d ", &c, &cut);
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t, n, k, d, ans, count;
cin >> t;
vector<int> v(101);
vector<bool> taken(101, false);
while (t--) {
cin >> n >> k >> d;
ans = INT_MAX;
for (int i = 0; i < n; i++) cin >> v[i];
for (int i = 0; i + d <= n; i++) {
count = 0;
... | 1 |
#include <bits/stdc++.h>
using namespace std;
const long long int Maxn3 = 1e3 + 10;
const long long int Maxn4 = 1e4 + 10;
const long long int Maxn5 = 1e5 + 10;
const long long int Maxn6 = 1e6 + 10;
const long long int Maxn7 = 1e7 + 10;
const long long int Maxn8 = 1e8 + 10;
const long long int Maxn9 = 1e9 + 10;
const lo... | 3 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n, k;
cin >> n >> k;
string s;
cin >> s;
int c0 = 0;
int c1 = 0;
int cq = 0;
for (int i = 0; i < k; i++) {
int f0 = 0;
int f1 = 0;
for (int j = i; j < n; j += k) {
if (s[j] == '0') f0 = 1;
if (s[j] == '1') f1 = 1;
... | 3 |
#include <bits/stdc++.h>
using namespace std;
pair<int, int> dp[20][131073];
map<string, int> atom;
int sum[131073];
int main() {
atom["H"] = 1;
atom["He"] = 2;
atom["Li"] = 3;
atom["Be"] = 4;
atom["B"] = 5;
atom["C"] = 6;
atom["N"] = 7;
atom["O"] = 8;
atom["F"] = 9;
atom["Ne"] = 10;
atom["Na"] = ... | 7 |
#include <bits/stdc++.h>
std::mt19937 rng(
(int)std::chrono::steady_clock::now().time_since_epoch().count());
const long double eps = 1e-7;
struct PT {
long double x, y;
int freq;
PT(long double xx = 0, long double yy = 0) : x(xx), y(yy) {}
PT operator+(const PT &p) const { return PT(x + p.x, y + p.y); }
... | 11 |
#include <bits/stdc++.h>
using namespace std;
struct hero {
int p, e;
hero() {}
hero(int _p, int _e) : p(_p), e(_e) {}
bool operator<(const hero& other) const {
if (p == other.p) {
return e < other.e;
}
return p < other.p;
}
};
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 210;
int n, m;
long long k, f[N], d[N], h[N], qy[2][2];
string p[2], s[2], str[17], suf[N * 10], ans;
inline bool cmp(string a, string b) {
for (int i = 0; i < min(a.length(), b.length()); i++) {
if (a[i] == b[i]) continue;
if (a[i] < b[i])
ret... | 9 |
#include <bits/stdc++.h>
using namespace std;
constexpr int maxn = 400000 + 10;
int lnk[maxn], nxt[maxn], son[maxn], n, m, now, c1, c2, dnt[maxn], mk;
vector<int> nvis[maxn], rt, rv;
vector<vector<int> > res;
bool flag[maxn];
pair<int, int> cnt[maxn];
bool cmp(const int a, const int b) __attribute__((always_inline));
v... | 10 |
#include <bits/stdc++.h>
const int MOD = 1e9 + 7;
const int v1 = 1e5 + 5;
const int N = 3e5 + 5;
using namespace std;
vector<vector<long long>> adj(500);
vector<bool> visited(500);
long long m = 0;
void dfs(long long v) {
visited[v] = true;
for (auto i : adj[v])
if (!visited[i]) dfs(i);
}
int32_t main() {
ios... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int m, n;
int a[200][200];
cin >> m >> n;
for (int i = 0; i < m; i++)
for (int j = 0; j < n; j++) {
cin >> a[i][j];
}
int r[200], c[200];
for (int i = 0; i < m; i++) r[i] = -1;
for (int i = 0; i < n; i++) c[i] = -1;
int val = a[0][... | 4 |
#include <bits/stdc++.h>
using namespace std;
class Array {
public:
long long total;
long long left;
long long right;
long long mmax;
Array() {
this->total = 0;
this->left = -(1 << 30);
this->mmax = -(1 << 30);
this->right = 0;
}
};
vector<Array> v;
vector<int> sequence;
void init(int m, in... | 6 |
#include <bits/stdc++.h>
using namespace std;
short Print_Array[20];
template <typename T>
inline void print(T x, char tm = '\n') {
if (x < 0) putchar('-'), x = -x;
short sz = 0;
while (x) Print_Array[sz++] = x % 10, x /= 10;
if (sz == 0) putchar('0');
for (int i = sz - 1; i >= 0; i--) putchar('0' + Print_Arr... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
map<int, int> ma;
for (int i = 0; i < n; i++) {
int val;
cin >> val;
ma[val] = i + 1;
}
string s = "";
if (n == 1)
cout << 1 << endl;
else {
int ... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
int a[N];
int main() {
int t, n, c;
cin >> t;
while (t--) {
int a0 = 0, a1 = 0;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> c;
a[i] = c & 1;
if (a[i])
a1++;
else
a0++;
}
if (abs(a1 -... | 2 |
#include <bits/stdc++.h>
#pragma optimize("Ofast")
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
unordered_map<string, int> um;
for (int i = 0; i < n; i++) {
string s;
cin >> s;
string t = "";
int n = s.length();
int cnt_k = 0;
for (in... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, tmp = 0, r, s, d;
cin >> n;
long long day;
for (int i = 0; i < n; i++) {
cin >> s >> d;
while (s <= tmp) s += d;
tmp = s;
}
cout << tmp << endl;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
struct people {
int a, d, id;
bool operator<(people other) const {
if (a != other.a) return a > other.a;
return id < other.id;
}
};
people s[111];
int n;
int main() {
int i, j, ans = 0;
scanf("%d", &n);
for (i = 1; i <= n; ++i) {
scanf("%d%d", &s[i].... | 7 |
#include <bits/stdc++.h>
using namespace std;
long long n, m, k, l = 0, r = 2e+5 + 1;
vector<long long> mas;
bool check(long long num) {
long long kc = k, mc = m;
for (long long i = num; i < n; i++) {
if (mc == 0 || k < 0) {
return 0;
}
if (mas[i] <= kc) {
kc -= mas[i];
} else {
kc... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, k, maxx = -1, a, b, prev, curr, counter, i, x;
cin >> n >> k;
deque<int> dq;
for (i = 0; i < n; i++) {
cin >> x;
maxx = max(x, maxx);
dq.push_back(x);
}
if (k > n)
cout << maxx << endl;
else {
counter = 1;
a = ... | 2 |
#include <bits/stdc++.h>
using namespace std;
int arr[300005];
int main() {
int n, k;
scanf("%d%d", &n, &k);
for (int i = 0; i < n; ++i) scanf("%d", &arr[i]);
sort(arr, arr + n);
if (arr[0] <= k + 1)
printf("%d\n", arr[0]);
else {
bool ok = false;
int d = arr[0];
while (1) {
bool updat... | 6 |
#include <bits/stdc++.h>
using namespace std;
ostream &operator<<(ostream &out, vector<long long> &a) {
for (auto i : a) out << i << " ";
return out;
}
istream &operator>>(istream &in, vector<long long> &a) {
for (auto &i : a) in >> i;
return in;
}
int main() {
cin.tie(0);
cout.tie(0);
ios_base::sync_with... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char *argv[]) {
bool prime;
long long n, k;
cin >> n;
while (n--) {
cin >> k;
long long s = floor(sqrt(k));
if (s * s != k || k == 1) {
cout << "NO" << endl;
continue;
} else if (s == 2) {
cout << "YES" << endl;
... | 2 |
#include <bits/stdc++.h>
int n, m, k, g[11][11], f[11][11], cnt[11], lg[1 << 11];
int Dfs(int x, int y) {
if (y > m) x++, y = 1;
if (x > n) return 1;
int res = 0;
for (int tmp = -1, pre = f[x - 1][y] & f[x][y - 1], con = pre, col; con > 0;
con -= ((con) & -(con))) {
col = lg[((con) & -(con))];
f[... | 9 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
using namespace std;
const double eps = 1e-12;
const double PI = acos(-1.0);
const long long INF = 1e18;
const long long MOD = 1e9 + 7;
const long long n... | 0 |
#include <bits/stdc++.h>
using namespace std;
bool solve() {
int n, k;
cin >> n >> k;
string s;
cin >> s;
vector<int> fact(k, -1);
for (int i = 0; i < k; i++) {
for (int j = i; j < n; j += k) {
if (s[j] == '0' && fact[i] == -1) {
fact[i] = 0;
}
if (s[j] == '1' && fact[i] == -1)... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, q;
cin >> n >> q;
map<int, int> mp;
int a[n], temp, ans = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = n - 1; i >= 0; i--) {
if (mp.find(a[i]) == mp.end()) {
mp[a[i]] = i;
}
}
for (int i = 0; i < n; i++... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
int n, k, a[1003], dp[1003][1003], l[1003], res, pre[1003][1003];
int cal(int val) {
for (int i = 0; i <= k; i++)
for (int j = 0; j <= n; j++) dp[i][j] = 0;
l[0] = 0;
for (int i = 1; i <= n; i++) {
l[i] = l[i - 1];
while (a[i] - ... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
set<char> a;
int i, n;
getline(cin, s);
n = s.length();
for (i = 0; i < n; i++) {
a.insert(s[i]);
}
if (a.size() > 3)
cout << a.size() - 4;
else
cout << a.size() - 2;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const long long m = 1e9 + 7;
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; ... | 2 |
#include <bits/stdc++.h>
using namespace std;
const long long int MOD = 998244353;
const long long int INF = 1e18;
int main() {
vector<long long int> a(6);
for (int i = 0; i < 6; i++) cin >> a[i];
int n;
cin >> n;
vector<long long int> b(n);
for (int i = 0; i < n; i++) cin >> b[i];
vector<pair<long long i... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int N = (int)4e5 + 7;
const int M = 20;
int n, a[N];
vector<int> u[M];
set<int> s;
int t[M];
long long dp[(1 << M)];
int bits[M], top;
bool act[M];
long long score[M][M];
int cnt(int col, int p) {
int l = 0, r = (int)u[col].size() - 1, ans = 0;
while (l <= r) {
... | 7 |
#include <bits/stdc++.h>
using namespace std;
vector<int> A, B;
bool check(int val, int c, int n) {
long long int sum = 0;
for (int i = 1, j = n - val + 1; i <= val; i++, j++) {
if (B[i] > A[j]) sum += (B[i] - A[j]);
}
return c >= sum;
}
int main() {
int n, m, c;
cin >> n >> m >> c;
A.resize(n + 1);
... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 6e6 + 10;
int cnt[maxn];
int n, u;
int ch[maxn][2], node_cnt = 0, siz[maxn];
void ins(int x) {
int now = 0;
siz[now]++;
for (int i = 31; i >= 0; i--) {
int idx = (x >> i) & 1;
if (!ch[now][idx]) {
ch[now][idx] = ++node_cnt;
}
now... | 6 |
#include <bits/stdc++.h>
using namespace std;
static inline void canhazfast() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
}
template <typename T>
T gcd(T a, T b) {
return b == 0 ? a : gcd(b, a % b);
}
template <typename T>
T extgcd(T a, T b, T &x, T &y) {
T x0 = 1, y0 = 0, x1 = 0,... | 9 |
#include <bits/stdc++.h>
using namespace std;
int n, m, r, l, maxN;
int a[1000010], cnt[10000010];
vector<int> p, q;
bool check[10000010];
void init() {
memset(check, false, sizeof check);
check[0] = check[1] = true;
p.push_back(0);
q.push_back(0);
for (int i = 2; i <= maxN; i++) {
if (check[i]) continue;... | 4 |
#include <bits/stdc++.h>
using namespace std;
int block[5], dat[20000];
inline int mi(int a, int b) { return a < b ? a : b; }
int main(void) {
int n, k;
int x;
scanf("%d%d", &n, &k);
for (int i = 0; i < k; i++) {
scanf("%d", &x);
dat[x]++;
}
block[2] = n << 1, block[4] = n;
for (int i = 10000; i >... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long a[100005] = {0};
long long sum[100005] = {0};
long long n, t, mx = 0;
long long sumc(int l, int r) { return (r < l ? 0 : sum[r] - sum[l - 1]); }
bool isgood(long long x) {
for (int l = 0, r = x - 1; r < n; ++l, ++r)
if (sumc(l, r) <= t) return true;
return... | 3 |
#include <bits/stdc++.h>
using namespace std;
int a[1003];
int used[1003];
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
bool toR = true;
multiset<int> l, r;
for (int i = 0; i < n; i++) r.insert(a[i]);
int cur = 0, ans = 0;
int i = 0;
while (true) {
if (toR) {
... | 2 |
#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;
void solve(int tcase) {
int n;
cin >> n;
vector<long long> d(n);
for (int i = 0; i < n; ++i) {
c... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5;
int n, m, cntdep[N], type[N];
vector<int> rdep[N];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> m;
for (int i = 0; i < n; ++i) cin >> type[i];
for (int i = 0, u, v; i < m; ++i) {
cin >> u >> v;
++cntde... | 5 |
#include <bits/stdc++.h>
using namespace std;
long a[52000];
void init() {
int i = 0;
int k;
k = 1;
while (1) {
i++;
if ((i + 1) * i >= 2100000000) break;
k = i * (i + 1);
a[i] = k / 2;
}
}
int got(int x) {
int l, r, m;
l = 1;
r = 45825;
m = (l + r) >> 1;
while (1) {
if (x == 997... | 2 |
#include <bits/stdc++.h>
using namespace std;
const long double pi = 3.1415926535897932384626433832795l;
template <typename T>
inline auto sqr(T x) -> decltype(x * x) {
return x * x;
}
template <typename T1, typename T2>
inline bool umx(T1& a, T2 b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template... | 10 |
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O2,no-stack-protector,unroll-loops,fast-math")
const long long maxn = 2e5 + 10, maxm = 1e3 + 10, lg = 21, mod = 1e9 + 7,
inf = 1e18;
long long n, ans;
pair<pair<long long, long long>, long long> a[maxn];
set<pair<long long, long long> >... | 9 |
#include <bits/stdc++.h>
using namespace std;
long long Choose(long long n, long long k) {
long long res = 1;
for (long long i = 0; i < k; i++) {
res *= (n - i);
res /= (i + 1);
}
return res;
}
int main() {
long long n;
cin >> n;
cout << Choose(n, 7) + Choose(n, 6) + Choose(n, 5);
return 0;
}
| 2 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.