solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
int n1, n2;
vector<int> v1, v2;
int k, m;
int main() {
cin >> n1 >> n2;
cin >> k >> m;
v1.resize(n1);
v2.resize(n2);
for (int i = 0; i < n1; i++) cin >> v1[i];
for (int i = 0; i < n2; i++) cin >> v2[i];
bool ok = 1;
for (int i = 0; i < m; i++) {
if (v1[k... | 1 |
#include <bits/stdc++.h>
using namespace std;
stack<int> S;
int A[1000000];
int main() {
int n, i, t, x;
scanf("%d", &n);
for (i = 0; i < n; i++) scanf("%d", &A[i]);
scanf("%d", &t);
for (i = 0; i < t; i++) {
scanf("%d", &x);
x--;
A[x] = -A[x];
}
for (i = n - 1; i >= 0; i--) {
if (S.empty(... | 13 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n;
cin >> n;
cout << ((n * (n - 1) * (n - 2) * (n - 3) * (n - 4)) / 120) *
(n * (n - 1) * (n - 2) * (n - 3) * (n - 4));
}
| 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k, a = 1, b;
cin >> n >> k;
for (int i = 0; i < n; i++) {
cin >> b;
if (a < b && k % b == 0) a = b;
}
cout << k / a;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
inline long long read() {
long long f = 1, ans = 0;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-') f = -1;
c = getchar();
}
while (c >= '0' && c <= '9') {
ans = ans * 10 + c - '0';
c = getchar();
}
return f * ans;
}
const long l... | 18 |
#include <bits/stdc++.h>
using namespace std;
int limit[] = {1, 10, 100, 1000, 10000, 100000, 1000000};
int to7(int n, int *N) {
vector<int> digits;
int ret = 0;
while (n > 0) {
digits.push_back(n % 7);
n /= 7;
}
for (int i = digits.size() - 1; i >= 0; i--) {
ret = (ret * 10) + digits[i];
}
*N... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long a, b;
long long mi, ma, val, t;
while (cin >> a >> b) {
mi = 0;
ma = 0;
val = 0;
for (int i = 0; i < a; i++) {
scanf("%lld", &t);
val += t;
if (val > ma) ma = val;
if (val < mi) mi = val;
}
mi *= -... | 6 |
#include <bits/stdc++.h>
using namespace std;
long long a[100010];
long long s[100010];
long long split(long long first, long long n) {
long long q = first / n;
long long r = first % n;
return r * (q + 1) * (q + 1) + (n - r) * q * q;
}
long long get_bon(long long first, long long cnt) {
if (cnt == first) return... | 14 |
#include <bits/stdc++.h>
using namespace std;
mt19937 rng32(chrono::steady_clock::now().time_since_epoch().count());
long long inf = 1e18, MOD = 1e9 + 7;
const int nax = 2e5 + 10;
vector<int> adj[nax];
int func(int j, int num) {
if (num > j) return num;
if (num < j) return num + 1;
return 1;
}
int main() {
ios_... | 12 |
#include <bits/stdc++.h>
using namespace std;
long long int MOD = 998244353, n, k = 0;
void print(long long int arr[], long long int n) {
for (int i = 0; i <= n - 1; i += 1) cout << arr[i] << " ";
cout << endl;
}
int main() {
long long int t = 1;
cin >> t;
while (t--) {
cin >> n;
string s, temp1, temp... | 1 |
#include <bits/stdc++.h>
using namespace std;
void solve();
template <class T, class... U>
void pr(T&& a, U&&... b) {
cout << forward<T>(a);
(int[]){(cout << " " << forward<U>(b), 0)...};
cout << "\n";
}
template <class T, class... U>
void re(T&& a, U&&... b) {
cin >> forward<T>(a);
(int[]){(cin >> forward<U>... | 7 |
#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 Min(int x, int y) {
if (x < y) return x;
return y;
}
const double fai = (1.0 + sqrt(5.0)) * 0.5;
double dp[110000][1... | 18 |
#include <bits/stdc++.h>
using namespace std;
long long arr[10000001];
int main() {
int n, arr[101], m, x, y;
cin >> n;
for (int i = 1; i <= n; ++i) cin >> arr[i];
cin >> m;
while (m--) {
cin >> x >> y;
arr[x - 1] += (y - 1);
arr[x + 1] += (arr[x] - y);
arr[x] = 0;
}
for (int i = 1; i <= n... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
int c = 0;
while (n--) {
int a, b;
cin >> a >> b;
c += abs(b - a) + 1;
}
cout << (k - c % k) % k;
return 0;
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 10;
const int MOD = 1e9 + 7;
struct Martix {
int a[2][2];
Martix operator+(const Martix &tm) const {
Martix retm;
for (int i = 0; i < 2; ++i) {
for (int j = 0; j < 2; ++j) retm.a[i][j] = (a[i][j] + tm.a[i][j]) % MOD;
}
return... | 15 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 2007, inf = 0x3f3f3f3f;
long long n, k, a[N], f[N];
inline bool chk(long long mid) {
long long mx = 0;
for (register long long i = 1; i <= n; ++i) {
f[i] = 1;
for (register long long j = 1; j <= i - 1; ++j)
if (mid * (i - j) >= abs(a[i]... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
long long n;
string s;
cin >> n >> s;
bool ok = 0;
for (int i = 0; i < n; i++) {
if (n - i >= 11 && s[i] == '8') {
ok = 1;
break;
}
}
if (ok == 1) {
cout << "YES"... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long ans[101];
void pre() {
set<long long> s;
for (long long i = 1; i <= 100; i++) {
s.insert(0);
for (long long f1 = 0; f1 <= i; f1++) {
for (long long f2 = 0; f1 + f2 <= i; f2++) {
s.insert(4 * f1 + 9 * f2 + 49 * (i - f1 - f2));
}
... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e2 + 7;
const int MOD = 1e9 + 7;
int n, k, C[10][10], dp[N][N][5][3];
inline void inc(int &x, int y) {
x += y;
if (x >= MOD) x -= MOD;
}
inline int mul(int x, int y) { return 1ll * x * y % MOD; }
const int tri[] = {4, 3, 2, 1, 2};
const int cor[] = {4, 2,... | 19 |
#include <bits/stdc++.h>
int main() {
long long n, k, x;
int p, i;
scanf("%I64d %I64d %d", &n, &k, &p);
if (n % 2 == 1 && k > 0) {
n--;
k--;
}
for (i = 0; i < p; i++) {
scanf("%I64d", &x);
if (x > n) {
putchar('X');
} else if (k >= n / 2) {
if (x % 2 == 1 && (x + 1) / 2 <= n ... | 11 |
#include <bits/stdc++.h>
using namespace std;
int n, k, c[9];
long long ans;
bool b[9];
inline void check() {
for (int i = 1; i <= k; i++) {
bool ok = false;
memset(b, false, sizeof(b));
for (int j = i;;) {
if (j == 1) {
ok = true;
break;
}
b[j] = true;
j = c[j];
... | 7 |
#include <bits/stdc++.h>
using namespace std;
long long mod = 1000000007;
long long p1 = 998244353;
long long power(long long x, long long y) {
long long ans = 1;
x = x % p1;
while (y > 0) {
if (y & 1) ans = (ans * x) % p1;
y = y >> 1;
x = (x * x) % p1;
}
return ans;
}
int main() {
ios_base::syn... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
bool vis[N];
bool pro[N];
int p[N];
int pos[N];
int ans = 0;
void dfs(int u, int x, vector<int> adj[]) {
vis[u] = 1;
p[u] = x;
for (int v : adj[u]) {
if (!vis[v]) {
if (u == 1) p[u] = v;
dfs(v, u, adj);
}
}
if (!pro[u]) {... | 13 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pli = pair<ll, int>;
const int INF = 0x3f3f3f3f, N = 1e5 + 5;
const ll LINF = 1e18 + 5;
int n, m, blo, d[N];
int id[N << 1], first[N], dep[N << 1], tot, dp[N << 1][25], dis[N];
bool col[N];
vector<int> G[N], red;
void ... | 16 |
#include <bits/stdc++.h>
using namespace std;
class Codeforce {
public:
bool task(long long n, long long k, long long d1, long long d2) {
if (n % 3 != 0) return false;
long long t = n / 3;
if (d1 > t || d2 > t) return false;
if (((k - d1 + d2) % 3 == 0 && (k - d1 + d2) / 3 >= 0 &&
(k - d1 + ... | 9 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
inline int read() {
int x = 0, f = 1;
char ch = getchar();
while (!isdigit(ch)) {
if (ch == '-') f = -1;
ch = getchar();
}
while (isdigit(ch)) {
x = (x << 1) + (x << 3) + ch - '0';
ch = getchar();
}
return x * f;
}
const l... | 22 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
int b = 1e9;
long long int ans = 0;
while (n >= 1) {
if (9 >= n) {
ans += n;
break;
}
if (b ... | 1 |
#include <bits/stdc++.h>
using namespace std;
void get_sections(vector<pair<int, int> >& sections, int n, string s) {
int q, p = 1, e = n;
while (p < n) {
if (s[p] != s[p - 1]) break;
p++;
}
if (p == n) sections.push_back({0, n - 1});
while (p < n) {
if (s[p] == s[(p + 1) % n]) break;
p++;
}... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5, M = 2e6 + 5, OO = 0x3f3f3f3f;
int n;
long long A[N];
bool canWeCover(long long d) {
long long lastCovered = -OO, used = 0;
for (int i = 0; i < n; ++i) {
if (A[i] > lastCovered) {
lastCovered = A[i] + d;
used++;
}
}
return u... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int k, a, b, v;
int res = 0, val = 0;
cin >> k >> a >> b >> v;
for (int i = 1; i < 1000; i++) {
int res = min(k * i, b + i);
if (res * v >= a) {
cout << i << endl;
break;
}
}
}
| 3 |
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define ll long long
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define rep(i,a,b) for(ll i=a; i<b; i++)
const int INF = 1e9 + 7;
void solve() {
int n;
ci... | 0 |
#include <bits/stdc++.h>
using namespace std;
string s[30];
int r, c, k;
bool all;
int main() {
for (int i = 0; i < 27; i++) {
cin >> s[i];
}
cin >> r >> c;
all = true;
r = (r - 1) % 3;
c = (c - 1) % 3;
for (int i = r * 9 + c, k = 0; k < 3; i += 3, k++) {
for (int j = 0; j < 3; j++) {
if (s[... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
long long x;
cin >> x;
int largest_prime = 0;
int p[n];
int a = 0, b = 0, c = 0, d = 0;
for (int i = 0; i < n; i++) {
p[i] = x % 10;
x /= 10;
if (p[i] == 2) a++;
if (p[i] == 3) {
a++;
b++;
}
i... | 6 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
inline int read();
struct Comper {
int val, r, c;
bool operator<(const Comper& b) const {
if (val != b.val) return val > b.val;
if (r != b.r) return r < b.r;
return c < b.c;
}
};
int n, m;
int save[16][2048];
int ndcols;
int cpp[16], ... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
int ans = INT_MIN;
for (int i = 0; i < n; i++) {
int a, b;
cin >> a >> b;
int d = a;
if (b > k) d = a - (b - k);
ans = max(ans, d);
}
cout << ans << "\n";
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
inline void swap(long long *a, long long *b) {
long long temp = *a;
*a = *b;
*b = temp;
}
inline long long add(long long a, long long b, long long m) {
return a + b >= m ? a + b - m : a + b;
}
inline long long sub(long long a, long long b, long long m) {
return a ... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int n, u, v;
vector<int> g[100005 + 2];
int used[100005 + 2], coun[100005 + 2];
int dfs(int v) {
used[v] = 1, coun[v] = 1;
for (int x : g[v]) {
if (used[x]) continue;
coun[v] += dfs(x);
}
return coun[v];
}
int main() {
ios_base::sy... | 7 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:64000000")
using std::cerr;
using std::cin;
using std::cos;
using std::cout;
using std::endl;
using std::make_pair;
using std::max;
using std::min;
using std::next_permutation;
using std::pair;
using std::priority_queue;
using std::queue;
using std::random_shuffl... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100010;
vector<int> s[maxn];
bool Big[maxn];
int flag[maxn];
int n, m;
vector<int> pointa[maxn];
void Debug() {
for (int i = 1; i <= m; i++) printf("%d\n", flag[i]);
}
bool check_min(int x) {
int len1 = s[x].front();
int len2 = s[x + 1].front();
if ... | 13 |
#include <bits/stdc++.h>
using namespace std;
long long func(int i, int j, int time, vector<long long>& arr1,
vector<long long>& arr2, vector<long long>& arr3,
vector<long long>& a, vector<long long>& b) {
if (i == (arr1.size() - 1)) {
long long prev = time * (a[i] + b[i]);
if (j... | 10 |
#include <bits/stdc++.h>
using namespace std;
void checkDefine();
long long int n;
long long int a[200005];
set<long long int> myset;
int main() {
cin >> n;
for (int i = (0), _b = (n - 1); i <= _b; i++) {
cin >> a[i];
}
long long int res = -1;
for (int i = (n - 1), _b = (0); i >= _b; i--) {
long long ... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int MaxN = int(1e5);
const int INF = int(1e9);
int n, a[MaxN + 256], x, y, dif = 1, u[MaxN + 256];
vector<pair<int, int> > v;
void change() {
for (int i = 0; i < v.size() - 1; ++i) {
if (v[i].first == v[i + 1].first && !u[i]) {
swap(v[i].second, v[i + 1].s... | 5 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n;
cin >> n;
vector<int> v(2 * n);
for (int i = 0; i < 2 * n; i++) {
cin >> v[i];
}
sort(v.begin(), v.end());
cout << v[n] - v[n - 1] << endl;
}
int main() {
int t;
t = 1;
cin >> t;
while (t--) {
solve();
}
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
inline int read() {
char c = getchar();
int t = 0, f = 1;
while ((!isdigit(c)) && (c != EOF)) {
if (c == '-') f = -1;
c = getchar();
}
while ((isdigit(c)) && (c != EOF)) {
t = (t << 3) + (t << 1) + (c ^ 48);
c = getchar();... | 25 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
if ((int)s[0] <= 122 && (int)s[0] >= 97) {
s[0] = s[0] - 32;
}
cout << s;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;
long long n, target, need_run, max_jump;
long long x[200500];
int jump_from[200500];
vector<string> ans;
void no() {
cout << "IMPOSSIBLE" << endl;
exit(0);
}
void run(long long high, long long low) {
if (high == low) return;
ans.push_bac... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int c = 82, k = c * c;
int n, m, t[c][c], kezd, veg, tav[k], fel[k];
vector<int> sz[k], s[k], ert[k], pos[k];
void add(int a, int b, int c) {
pos[a].push_back(sz[b].size()), pos[b].push_back(sz[a].size());
sz[a].push_back(b), s[a].push_back(1), ert[a].push_back(c)... | 15 |
#include <bits/stdc++.h>
using namespace std;
int n, m, size1;
int key[200010], first[200010];
struct node {
int next, to;
};
node bian[200010 << 1];
int exist[200010], dad[200010];
int dp[200010], mx[200010], se[200010];
void inser(int a, int b) {
size1++;
bian[size1].to = b;
bian[size1].next = first[a];
fir... | 18 |
#include <bits/stdc++.h>
using namespace std;
int Set(int N, int pos) { return N = N | (1 << pos); }
int reset(int N, int pos) { return N = N & ~(1 << pos); }
bool check(int N, int pos) { return (bool)(N & (1 << pos)); }
struct edge {
int w, s;
};
bool cmp(const edge &a, const edge &b) { return a.w < b.w; }
bool ispr... | 6 |
#include <bits/stdc++.h>
using namespace std;
int n, a, b, cnt, root, head[200005], ma1[200005], ma2[200005], id1[200005],
id2[200005], size[200005], val[200005];
bool isleaf[200005], f1[200005], f2[200005], used[200005];
struct node {
int to, next;
} e[200005 << 1];
void insert(int u, int v) {
e[++cnt].to = v;... | 17 |
#include <bits/stdc++.h>
using namespace std;
using namespace std;
const int MOD = 1e9 + 7;
int fx[] = {-1, +0, +1, +0, +1, +1, -1, -1, +0};
int fy[] = {+0, -1, +0, +1, +1, -1, +1, -1, +0};
template <typename T>
inline T GCD(T a, T b) {
a = abs(a);
b = abs(b);
if (a < b) swap(a, b);
while (b) {
a = a % b;
... | 11 |
#include <bits/stdc++.h>
using namespace std;
long long ask(int t, int i, int j, int k) {
cout << t << " " << i << " " << j << " " << k << endl;
long long ans;
cin >> ans;
return ans;
}
int main(int argc, char const *argv[]) {
int n;
cin >> n;
int piv = 2;
for (int i = 3; i <= n; i++) {
if (ask(2, 1... | 15 |
#include <bits/stdc++.h>
using namespace std;
long long int r, j, l, m, c, n, s, f, q, i, p, k, d, t, u, e, g;
string s1, s2, s3, s4;
long long int x[1000001], y[1000001], z[1000001];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> s1;
for (long long int i = 0; i < s1.size(); i++) {
if ... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int N = 5000;
long long int d[N][N];
vector<long long int> g[N];
vector<long long int> out(N, 0);
pair<long long int, long long int> dfs(long long int u) {
if (!g[u].size()) {
return {INT32_MAX, u};
}
pair<long long int, long long int> p = dfs(g[u][0]);
re... | 6 |
#include <bits/stdc++.h>
using namespace std;
long long int mpow(long long int a, long long int x) {
long long int res = 1;
while (x > 0) {
if (x & 1) {
res = (res * a) % 1000000007;
}
a = (a * a) % 1000000007;
x >>= 1;
}
return res;
}
inline long long int modI(long long int a) { return mp... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3f;
const int N = 200 + 7;
const int M = 12;
int main() {
for (int i = 0; i < 10; i++) {
cout << i << endl;
fflush(stdout);
char s[100];
gets(s);
int len = strlen(s);
if (len == 2) c... | 11 |
#include <bits/stdc++.h>
using namespace std;
void __print(int x) { cout << x; }
void __print(long x) { cout << x; }
void __print(long long x) { cout << x; }
void __print(unsigned x) { cout << x; }
void __print(unsigned long x) { cout << x; }
void __print(unsigned long long x) { cout << x; }
void __print(float x) { cou... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int P = 1000 * 1000 * 1000 + 7, N = 50 + 5;
long long n, dp[3 * N + 1][N][N], cnt[2], c[N][N], k, ans = 1;
void com() {
for (int i = 0; i < N; i++) c[i][0] = 1;
for (int i = 1; i < N; i++)
for (int j = 1; j <= i; j++) c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) ... | 13 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
scanf("%d", &t);
long int x, y, a, b;
long int ans, p, q;
while (t--) {
scanf("%ld %ld %ld %ld", &x, &y, &a, &b);
p = y - x;
q = a + b;
if ((y - x) % (a + b) != 0)
printf("-1\n");
else {
ans = (y - x) / (a + b);
... | 0 |
#include <bits/stdc++.h>
const int mod = 1000000007;
const int gmod = 3;
const int inf = 1039074182;
const double eps = 1e-9;
const long long llinf = 2LL * inf * inf;
template <typename T1, typename T2>
inline void chmin(T1 &x, T2 b) {
if (b < x) x = b;
}
template <typename T1, typename T2>
inline void chmax(T1 &x, T... | 17 |
#include <bits/stdc++.h>
using namespace std;
namespace __SarcasticMonk {
template <typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
cerr << name << " : " << arg1 << "\n";
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
const char *comma = strchr(names... | 8 |
#include <bits/stdc++.h>
using namespace std;
string s;
int a[26];
int main() {
int count = 0;
cin >> s;
for (int i = 0; i < s.size(); i++) {
a[s[i] - 'a']++;
}
for (int i = 0; i < 26; i++) {
if (a[i] != 0) {
count++;
}
}
if (count % 2 == 0)
cout << "CHAT WITH HER!" << endl;
else
... | 0 |
#include <bits/stdc++.h>
const double pi = 3.1415926535897932384626433832795;
int gcd(int a, int b) {
if (a == 0) return b;
return gcd(b % a, a);
}
using namespace std;
void ifd() {}
void tme() {}
int main() {
ifd();
int n;
int a[105];
cin >> n;
for (int i = (0); i < (n); ++i) cin >> a[i];
sort(a, a + n... | 10 |
#include <bits/stdc++.h>
using namespace std;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
string blank = "";
const int N = 2e5 + 10;
vector<double> arr(N);
int n;
vector<double> ans(3);
bool can(double mid) {
int i, k;
for (i = 0, k = 0; k < 3; k++) {
ans[k] = arr[i] + mid;
i = upper_bound(arr.begin... | 10 |
#include <bits/stdc++.h>
using namespace std;
template <typename S, typename T>
ostream& operator<<(ostream& out, pair<S, T> const& p) {
out << '(' << p.first << ", " << p.second << ')';
return out;
}
template <typename T>
ostream& operator<<(ostream& out, vector<T> const& v) {
int l = v.size();
for (int i = 0;... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000 + 50;
int n, m;
int a[maxn][maxn];
int b[maxn][maxn];
int t[maxn];
int mark[maxn][maxn];
bool check() {
memset(mark, 0, sizeof mark);
for (int i = 0, _n = (int)(n); i < _n; i++) {
for (int j = 0, _n = (int)(t[i]); j < _n; j++)
for (int k ... | 13 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, h, m, mx;
vector<int> vp;
cin >> n;
m = n;
while (n--) {
cin >> h;
vp.push_back(h);
}
mx = vp[m - 1];
vp[m - 1] = 0;
for (int i = m - 2; i >= 0; i--) {
if (vp[i] <= mx)
vp[i] = mx - vp[i] + 1;
else if (vp... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
int t;
cin >> t;
while (t--) {
double a, b, ans;
cin >> a >> b;
if (b == 0) {
cout << 1.00 << endl;
continue;
}
if (a > 4 * b)
ans = (a - b * 2) / a;
else
ans = a / 8.0 / b;
... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
long long int n, k, c = 0, t = 1;
cin >> n >> k;
vector<long long int> vec;
for (int i = 0; i < n; i++) {
long long int x;
cin >> x;
vec.push_back(x);
}
sort(vec.begin(), vec.end());
for (int i = 1; ... | 4 |
#include <bits/stdc++.h>
using namespace std;
multiset<int> a;
int main() {
int n, x;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> x;
a.insert(x);
}
int t = 1;
while (true) {
auto it = a.lower_bound(t);
if (it == a.end()) break;
t++;
a.erase(it);
}
cout << t << endl;
}
| 4 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 20;
pair<int, int> operator+(pair<int, int> a, pair<int, int> b) {
return pair<int, int>(a.first + b.first, a.second + b.second);
}
pair<int, int> operator-(pair<int, int> a, pair<int, int> b) {
return pair<int, int>(a.first - b.first, a.second - ... | 19 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t, n, a, b;
cin >> t;
while (t--) {
int rmin = INT_MAX, lmax = -1;
cin >> n;
vector<pair<int, int>> v;
for (int i = 0; i < n; i++) {
cin >> a >> b;
if (b < rmin) rmin = b;
if (a > lmax) lmax = a;
sort(v.begin(),... | 3 |
#include <bits/stdc++.h>
using namespace std;
string s;
int main() {
cin >> s;
int c = 0;
int vowel_chk = 0;
for (int i = 0; i < s.length(); ++i) {
if (vowel_chk == 1) {
if (s[i] == 'a' || s[i] == 'o' || s[i] == 'u' || s[i] == 'i' ||
s[i] == 'e')
vowel_chk = 0;
else {
c... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long int n;
vector<long long int> vec;
long long int add(long long int _a, long long int _b) {
_a = (_a + 1000000007) % 1000000007;
_b = (_b + 1000000007) % 1000000007;
return (_a + _b) % 1000000007;
}
long long int mul(long long int _a, long long int _b) {
_a ... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int NIL = -1;
template <class T>
inline T mx(T a, T b) {
return a > b ? a : b;
}
template <class T>
inline T mi(T a, T b) {
return a < b ? a : b;
}
template <class T>
inline void sw(T &a, T &b) {
T t = a;
a = b;
b = t;
}
template <class T>
inline T mabs(T x)... | 14 |
#include <bits/stdc++.h>
using namespace std;
double PI = acos(-1);
double EPS = 1e-7;
int INF = 1000000000;
int MOD = 1000000007;
int MAXINT = 2147483647;
long long INFLL = 1000000000000000000LL;
long long MAXLL = 9223372036854775807LL;
int mx[8] = {-1, 1, 0, 0, -1, -1, 1, 1};
int my[8] = {0, 0, -1, 1, -1, 1, -1, 1};
... | 17 |
#include <bits/stdc++.h>
using namespace std;
int k;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> k;
cout << 2000 << endl << -1 << " ";
for (int i = 1; i < 1999; ++i) cout << (k + 2000) / 1998 << " ";
cout << (k + 2000) % 1998;
return 0;
}
| 12 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 2e9;
const int mod = 1e9 + 7;
const int MAXN = 1e5 + 5;
int a[2], b[2];
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
int x, y;
cin >> x >> y;
a[x]++;
b[y]++;
}
cout << min(a[0], a[1]) + min(b[0], b[1]);
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
long long n, x, a, f[3], ans, d;
signed main() {
cin >> n >> x;
for (long long i = 1; i <= n; ++i) {
cin >> a;
f[0] = max(d, f[0] + a);
f[1] = max(f[0], f[1] + x * a);
f[2] = max(f[1], f[2] + a);
ans = max(ans, f[2]);
}
cout << ans;
return 0;
}... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
string su;
cin >> su;
int z, s;
int l = su.length(), a, b;
for (int i = 1; i <= 5; ++i) {
z = (int)ceil((double)l / i);
s = i * z - l;
if (z <= 20) {
a = i;
b = z... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
vector<int> primes;
cin >> n >> k;
primes.push_back(2);
for (int i = 3; i <= n; ++i) {
bool prime = true;
for (int j = 2; j < i; ++j)
if (i % j == 0) {
prime = false;
break;
}
if (prime) primes.push_ba... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long n, k, s;
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin >> n >> k >> s;
int o = k;
int pos = 1;
vector<int> v;
v.push_back(1);
long long S = s;
while (k--) {
if (s - max(pos - 1LL, n - pos) >= k) {
if (pos - 1 > n - po... | 8 |
#include <bits/stdc++.h>
int gcd(int x, int y) { return x ? gcd(y % x, x) : y; }
int main() {
int x, y, a, b, lcm;
scanf("%d%d%d%d", &x, &y, &a, &b);
lcm = x * y / gcd(x, y);
printf("%d", b / lcm - (a - 1) / lcm);
return 0;
}
| 4 |
#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
inline void smin(T &a, U b) {
if (a > b) a = b;
}
template <typename T, typename U>
inline void smax(T &a, U b) {
if (a < b) a = b;
}
template <class T>
inline void gn(T &first) {
char c, sg = 0;
while (c = getchar(), (c > '9' || c ... | 9 |
#include <bits/stdc++.h>
int main() {
char LR;
char str[101];
char key[40] = "qwertyuiopasdfghjkl;zxcvbnm,./";
scanf("%c", &LR);
scanf("%s", &str);
if (LR == 'L') {
int len = strlen(str);
for (int i = 0; i < len; i++) {
for (int j = 0; j < 30; j++) {
if (str[i] == key[j]) {
p... | 1 |
#include <bits/stdc++.h>
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize(4)
using namespace std;
const int N = 3e5 + 5;
int a[N], n, q, x, y;
int nxt[N][19], can[N][19];
int main() {
scanf("%d %d", &n, &q);
for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
for (int i = 0; i < 19; ++i) nxt[n + ... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int inft = 1000000009;
const int MAXN = 1000006;
void solve() {
long long n, k;
cin >> n >> k;
vector<int> P(n);
int beg = 0, kon = n - 1;
for (int i = 0; i < (n); ++i) {
if (k <= (1LL << (n - 2 - i)))
P[beg++] = i + 1;
else {
k -= 1LL <<... | 10 |
#include <bits/stdc++.h>
using namespace std;
long long n, m, k, ans;
int main() {
cin >> n >> m >> k;
m -= n;
while (m >= 0) {
if (min(ans, k) == k && min(ans - 1, n - k) == n - k) {
ans += m / n + 1;
break;
} else {
ans++;
m -= min(ans, k);
m -= min(ans - 1, n - k);
}
... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int64_t mod = 1000000007;
const int64_t MOD = 998244353;
int64_t maxm(int64_t a, int64_t b) { return a > b ? a : b; }
int64_t minm(int64_t a, int64_t b) { return a > b ? b : a; }
int64_t powr(int64_t x, int64_t n) {
int64_t result = 1;
while (n > 0) {
if (n % ... | 9 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
T mabs(const T &a) {
return a < 0 ? -a : a;
}
bool check(long long n, long long m, long long k, long long cnt) {
m -= cnt * k;
long long left = n - cnt * k;
long long can = left / k * (k - 1) + left % k;
return can >= m;
}
const int mod = 1e9... | 8 |
#include <bits/stdc++.h>
int main() {
int m(0), k(0);
scanf("%d %d", &m, &k);
int *distance = new int[m];
int *refill = new int[m];
for (int p = 0; p < m; p++) {
scanf("%d", distance + p);
}
for (int p = 0; p < m; p++) {
scanf("%d", refill + p);
}
long fuel(0), time(0), maxSoFar(0);
for (int... | 5 |
#include <bits/stdc++.h>
using namespace std;
int f[1010];
int main() {
int n, k;
scanf("%d%d", &n, &k);
int wa = 0;
for (int i = 0; i < n; i++) {
int t;
scanf("%d", &t);
f[t]++;
}
int cnt = 0;
for (int i = 1; i <= k; i++) {
if (f[i] % 2 == 0) {
wa += f[i];
} else {
wa += f... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = 60;
const int INF = 1e9;
int n, m;
int cost[N][N];
pair<int, int> bitr[N][N];
int d[1 << 20];
vector<string> s;
map<int, int> pows;
int lazy(int mask) {
if (d[mask] == -1) {
d[mask] = INF;
int last = pows[mask - (mask & (mask - 1))];
for (int c =... | 17 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, h;
cin >> n >> h;
vector<int> a(n);
for (int &i : a) cin >> i;
int lo = 1, hi = n;
int ans = -1;
vector<pair<int, int>> b;
for (int i = 0; i < n; ++i) b.push_back({a[i], ... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int n, m;
long long a[N], d[N], sum[N];
int q;
long long l, r, L;
vector<long long> V;
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%lld", &a[i]);
sort(a + 1, a + n + 1);
for (int i = 1; i <= n - 1; i++) d[i] = a[i + 1] -... | 10 |
#include <bits/stdc++.h>
using namespace std;
int a, b, r, d;
int main() {
scanf("%d%d%d", &a, &b, &r);
d = r * 2;
if (a >= d && b >= d)
printf("First\n");
else
printf("Second\n");
return 0;
}
| 8 |
#include <bits/stdc++.h>
using namespace std;
long long a, b;
long long mina, minb;
long long gcd(long long a, long long b) { return a ? gcd(b % a, a) : b; }
int main() {
cin.tie(0), ios_base::sync_with_stdio(0), cout.tie(0);
cin >> a >> b;
long long fin = (a * b) / gcd(a, b);
mina = minb = 0;
long long multa... | 7 |
#include <bits/stdc++.h>
using namespace std;
int tree[(1 << 18)];
void update(int x, int V) {
if (x <= 0) return;
while (x < (1 << 18)) {
tree[x] += V;
x += (x & -x);
}
}
int get(int K) {
int ret = 0;
for (int i = 16; i >= 0; --i) {
if (tree[ret + (1 << i)] <= K) {
K -= tree[ret + (1 << i)]... | 16 |
#include <bits/stdc++.h>
using namespace std;
int myrand(int n) { return (RAND_MAX * rand() + rand()) % n; }
const long double PI = 3.141592653589793;
const long double EXP = 0.000001;
const long long LLINF = 8e18;
const int MOD = 1e9 + 7;
const int INF = 2e9;
const int N = 5e2;
int n, m, k, ans;
int dp[N + 1][N + 1];
... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5;
int n, f, a[N];
string s[N];
bool done[N];
struct move1 {
string a, b;
move1(string x = "", string y = "") {
a = x;
b = y;
}
};
vector<move1> ans;
struct node {
string s;
node(string a = "") { s = a; }
bool operator<(const node a) cons... | 14 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.