solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
long long n;
long long sum = 0;
int main() {
cin >> n;
cout << (n * (n + 1) / 2) / (n + 1) - (n & 1 ? 0 : 1) << "\n";
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
int a[100009], b[100009];
int t, n, m;
int f1, f_1, f0;
int flag = 1;
int main() {
scanf("%d", &t);
while (t--) {
scanf("%d", &n);
f_1 = 0, f1 = 0;
flag = 1;
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
for (int i = 1; i <= n; i++) scanf("%d", &b... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int sum = 0, m[6], w[6], h1, h2;
for (int i = 1; i <= 5; i++) cin >> m[i];
for (int i = 1; i <= 5; i++) cin >> w[i];
cin >> h1 >> h2;
for (int i = 1; i <= 5; i++)
sum += max(i * 150, i * 2 * (250 - m[i]) - w[i] * 50);
sum += (h1 * 100 - h2 * 50)... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 105;
int n, m;
int a[maxn][maxn];
bool f(int i, int j) {
for (int k = 0; k < m; k++) {
if (a[i][k] != a[j][k]) {
return false;
}
}
return true;
}
int main() {
while (~scanf("%d %d", &n, &m)) {
for (int i = 0; i < n; i++) {
fo... | 5 |
#include <bits/stdc++.h>
using namespace std;
int p[20 + 1];
int dp[2 * 1000 * 1000][20 + 1];
long long get_sum(int l, int r) {
if (l != 0) return get_sum(0, r) - get_sum(0, l - 1);
int idx = 0;
long long ans = 0;
for (int i = 20; i >= 0; i--) {
if (idx + p[i] - 1 <= r) {
ans += dp[idx][i];
idx ... | 12 |
#include <bits/stdc++.h>
using namespace std;
int arr[4];
int main() {
int a, b, c, d;
scanf("%d %d %d %d", &arr[0], &arr[1], &arr[2], &arr[3]);
int sumi = arr[0] + arr[1] + arr[2] + arr[3];
sort(arr, arr + 4);
if (sumi % 2 == 1) {
printf("NO");
return 0;
}
sumi /= 2;
sumi -= arr[3];
if (sumi ... | 0 |
#include <bits/stdc++.h>
using namespace std;
void fillTable(bool *primes, int lastNumber, vector<long long> &primesList) {
memset(primes, 1, (lastNumber + 1) * sizeof(bool));
primes[0] = primes[1] = false;
for (int i = 2; i <= lastNumber; i++) {
if (primes[i]) {
primesList.push_back(i);
int value... | 13 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n;
cin >> n;
int total = 0;
vector<int> data[5];
for (int i = 0; i < n; i = i + 1) {
string temp;
cin >> temp;
for (int j = 0; j < 5; j++) data[j].push_back(-temp.length());
total += temp.length();
for (int j = 0; j < temp.le... | 7 |
#include <bits/stdc++.h>
using namespace std;
int a[1000000];
map<int, int> m;
int main() {
int n, k;
cin >> n >> k;
for (int i = 1; i <= k; i++) {
cin >> a[i];
m[a[i]] = i;
}
for (int i = 1; i <= k; i++) {
cout << a[i] << " ";
int un = 1;
for (int j = 1; j <= n * k; j++) {
if (un ==... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long n, m, k, b;
cin >> n >> m >> k;
if (k < n) {
cout << k + 1 << " " << 1;
return 0;
} else {
long long a = (k - n + 1) / (m - 1);
if ((k - n + 1) % (m - 1) == 0)
... | 5 |
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
void debugi(vector<int>& vec) {
int n = (int)vec.size();
for (int i = 0; i < n; i++) {
cout << vec[i] << " ";
}
cout << endl;
}
void debugl(vector<ll>& vec) {
int n = (int)vec.size();
for (int i = 0; i < n; i++) {
cout << vec[i] << ... | 12 |
#include <bits/stdc++.h>
using namespace std;
using namespace std;
int main() {
int n, j, i, t;
double m;
while (scanf("%d%d", &n, &t) != EOF) {
m = pow(1.000000011, t);
m = n * m;
printf("%lf\n", m);
}
return 0;
}
| 4 |
#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
using namespace std;
template <typename T>
constexpr long long infValue =
std::is_same<T, int>::value ? 2000100007 : 860000000000000... | 16 |
#include <bits/stdc++.h>
using namespace std;
int _search(int i, int n, vector<int> &mio) {
int ans = i;
for (int j = i + 1; j < n; ++j)
if (mio[j] < mio[ans]) ans = j;
return ans;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
map<int, int> cod;
int n;
cin >> n;
int _id = 0;
ve... | 7 |
#include <bits/stdc++.h>
using namespace std;
int lowBit(int i) { return i & -i; }
int take(int i) { return 1 << i; }
void checkMax(int& a, int b) {
if (b > a) a = b;
}
void findSegment(int l, int r, int i, int k, vector<pair<int, int> >& res) {
if ((k--) == 0) return;
if (lowBit(l) > take(i)) ++l;
if (l > r) r... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int N = 300;
int n, x, y, z, f[N][N];
int dp(int x, int y) {
f[0][0] = 1;
for (int i = 1; i <= x; ++i) {
for (int j = 1; j <= y; ++j) {
int l = min(i, j), flag = false;
for (int k = 1; k <= l; ++k) {
if (f[i - k][j - k]) flag = true;
... | 13 |
#include <bits/stdc++.h>
int main() {
size_t n, m;
std::cin >> n >> m;
std::vector<std::pair<size_t, size_t>> pairs(m);
size_t a, b, val1, val2;
std::cin >> val1 >> val2;
size_t n_1 = 1, n_2 = 1;
pairs[0] = {val1, val2};
for (size_t i = 1; i != m; ++i) {
std::cin >> a >> b;
pairs[i] = {a, b};
... | 7 |
#include <bits/stdc++.h>
using ll = long long;
int const nmax = 200000;
std::vector<std::vector<char>> v;
std::vector<std::vector<int>> id1, id2;
std::vector<int> g[1 + nmax], g2[1 + nmax];
int g2in[1 + nmax], gin[1 + nmax];
int start[1 + nmax], stop[1 + nmax], currptr = 0;
void dfs(int node) {
start[node] = ++currpt... | 24 |
#include <bits/stdc++.h>
using namespace std;
struct point {
double x, y, z;
};
const double eps = 1e-8;
point p[1000];
int x[1000], y[1000], z[1000];
int a, b, c;
int n, m;
bool flag, note = false;
void add(int i, int a, int b, int c, int x, int y, int z) {
double t = double(a * x + b * y + c * z) / double(a * a +... | 16 |
#include <bits/stdc++.h>
using namespace std;
vector<int> arr;
set<int> s;
int main() {
int n;
cin >> n;
for (int i = 1; i * (i + 1) / 2 <= 1000000000; i++) {
arr.push_back(i * (i + 1) / 2);
s.insert(arr.back());
}
for (int i = 0; i < arr.size(); i++)
if (s.find(n - arr[i]) != s.end()) {
cou... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long d, k, a, b, t;
int main() {
cin >> d >> k >> a >> b >> t;
long long ans = 0;
if (d <= k) {
cout << a * d;
exit(0);
}
d -= k;
ans += a * k;
if (k * b > a * k + t) {
if (d % k == 0) {
cout << ans + d / k * (a * k + t);
exit(0);
... | 11 |
#include <bits/stdc++.h>
int main() {
long long int x, y, z, a, b;
scanf("%lld%lld%lld", &x, &y, &z);
if (x % z == 0) {
a = (x / z);
} else if (x % z != 0) {
a = (x / z) + 1;
}
if (y % z == 0) {
b = (y / z);
} else if (y % z != 0) {
b = (y / z) + 1;
}
printf("%lld\n", a * b);
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
int d[1100][1 << 12], m[1100][4], a[5];
vector<int> s[3] = {{1, 2, 4, 8}, {51, 102, 204}, {-2185, -274}};
int main() {
int N;
cin >> N;
for (int i = 0; i < 4; i++) cin >> a[i];
for (int r = 0; r < 4; r++)
for (int c = 0; c < N; c++) {
char x;
cin >> ... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x7fffffff;
const int MAXN = 40 + 3;
int n, m, ans, k;
int g[MAXN][MAXN];
bool ok(const int &x, const int &y) {
return (x > 0 && x <= n && y > 0 && y <= m);
}
void dfs(const int &x, const int &y) {
if (k >= ans || k + (n * m - x * m - y) / 5 >= ans) retu... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int maxN = 22;
const int maxO = 9;
const int INF = 1000;
int value[maxO], dist[maxN][maxN][1 << maxO], tasir[maxN][maxN][5],
mark[maxN][maxN][1 << maxO];
int xstep[4] = {-1, 0, 0, 1}, ystep[4] = {0, -1, 1, 0};
int n, m, o, sx, sy, vs;
char matrix[maxN][maxN];
queu... | 18 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, sum, i;
cin >> n;
string s;
int flag1, flag2;
while (n--) {
sum = 0, flag1 = 0, flag2 = 0;
cin >> s;
for (i = 0; i < s.size(); i++) {
sum += s[i] - 48;
if (s[i] == '0') ++flag1;
if (s[i] == '2' || s[i] == '4' || s[... | 2 |
#include <bits/stdc++.h>
using namespace std;
#pragma warning(disable : 4996)
long long bit[2][2509][2509], H, W, q, p1, p2, p3, p4, p5;
map<tuple<int, int, int, int, int>, long long> M;
void add(long long e, long long p, long long q, long long x) {
long long r = p, s = q;
while (p <= 2508) {
while (q <= 2508) ... | 16 |
#include <bits/stdc++.h>
char a[5];
int conta;
int resp() {
int x = 0;
int t = strlen(a);
for (int i = 0; i < t; i++)
if (a[i] == '4' || a[i] == '7') x++;
return x;
}
int main() {
int n, k;
scanf("%d%d", &n, &k);
for (int i = 1; i <= n; i++) {
scanf("%s", a);
if (resp() <= k) conta++;
}
pr... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, flag = 0;
cin >> n;
int a[n];
for (int i = 0; i < n; i++) cin >> a[i];
sort(a, a + n);
for (int i = 0; i < n - 2; i++) {
if ((a[i + 1] == a[i] + 1)) {
for (int j = i + 1; j < n - 1; j++) {
if (a[j + 1] - 1 == a[i + 1]) {
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int hashu[505][505];
int ar[501][501];
int xline[250001], yline[250001], fline[250001];
int main() {
int n, m, a, b;
cin >> n >> m;
memset(ar, 0, sizeof(ar));
memset(hashu, -1, sizeof(hashu));
for (int i = 0; i < m; ++i) {
cin >> a >> b;
ar[a][++ar[a][0]] ... | 16 |
#include <bits/stdc++.h>
const double PI = acos(-1.0);
const double e = exp(1.0);
const int INF = 0x7fffffff;
;
template <class T>
T gcd(T a, T b) {
return b ? gcd(b, a % b) : a;
}
template <class T>
T lcm(T a, T b) {
return a / gcd(a, b) * b;
}
template <class T>
inline T Min(T a, T b) {
return a < b ? a : b;
}
... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long int frame[100005], pos[100005], a[100005];
int main() {
long long int n, m, k;
cin >> n >> m >> k;
int l = 0, fr_no = 1, i;
for (i = 1; i <= n; i++) {
cin >> a[i];
pos[a[i]] = i;
frame[a[i]] = fr_no;
l++;
if (l == k) {
fr_no++;
... | 8 |
#include <bits/stdc++.h>
using namespace std;
int num[200005];
int num1[200005];
int n;
bool check(int x) {
for (int i = 1; i <= n; i++) num1[i] = num[i];
for (int i = n; i >= 1; i--) {
if (num1[i] - 3 >= x && i >= 3) {
int tmp = min(num1[i] - x, num[i]);
num1[i - 1] += tmp / 3;
num1[i - 2] +=... | 8 |
#include <bits/stdc++.h>
using namespace std;
const long long maxn = 5 * 100000 + 5;
const long long UP = 2000000 + 5;
long long n;
long long x, y;
bool vis[UP];
vector<long long> prim;
long long sum[UP];
long long cnt[UP], a[maxn];
long long gcd(long long A, long long B) { return B == 0 ? A : gcd(B, A % B); }
void sei... | 13 |
#include <bits/stdc++.h>
using namespace std;
int n, a[100005], flag, start;
int main() {
while (~scanf("%d", &n)) {
flag = 0;
start = n + 1;
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
if (a[i] < a[i - 1] && (!flag)) {
flag = 1;
start = i;
}
}
a[n + 1] = 1... | 4 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
void show(const vector<T> &a) {
for (T x : a) cout << x << " ";
cout << '\n';
}
const long long N = 2e5 + 100, oo = 1e18 + 500;
const long long mod = 998244353;
const long double eps = 1e-9, PI = 2 * acos(0.0);
long long n, m, k;
long long cnt = 0;
ve... | 10 |
#include <bits/stdc++.h>
using namespace std;
map<pair<long long, long long>, bool> memo;
bool win(long long a, long long b) {
if (a < b) {
long long t = a;
a = b;
b = t;
}
pair<long long, long long> pp;
pp = make_pair(a, b);
if (b == 0) return false;
if (memo.count(pp)) return memo[pp];
if (!... | 15 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int ct = 0;
char type_ln = s[0];
for (char &c : s) {
if (c == type_ln)
ct++;
else {
ct = 1;
type_ln = c;
}
if (ct > 6) {
cout << "YES" << '\n';
return 0;
}
}
cout << "NO" << '\n... | 1 |
#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> v(300005);
unordered_map<int, int> m;
vector<pair<int, int> > moves;
void swapElems(int a, int b) {
m[v[a]] = b;
m[v[b]] = a;
swap(v[a], v[b]);
moves.push_back({a, b});
}
int main() {
ios_base::sync_with_stdio(false);
cin >> n;
for (int i = ... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int gi() {
int x = 0, o = 1;
char ch = getchar();
while (!isdigit(ch) && ch != '-') ch = getchar();
if (ch == '-') o = -1, ch = getchar();
while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
return x * o;
}
int n, fa[N], ans[N], le... | 17 |
#include <bits/stdc++.h>
using namespace std;
long long int prime = 100000007;
int main() {
long long int i, j, k, n, ca = 1, tc, ans = 0, a = 0, b = 0, c, l = 0, r = 0;
cin >> n >> k;
cout << prime << " " << prime << endl;
for (i = 1; i < n - 1; i++) cout << i << " " << i + 1 << " 1" << endl;
cout << i << " ... | 8 |
#include <bits/stdc++.h>
using namespace std;
int mul[4] = {1, 2, 4, 8};
const int MAX = 25;
int track[MAX], a[MAX], b[MAX], m[MAX];
int ans[MAX], ana[MAX], anb[MAX], anm[MAX];
int n;
int opt;
void sol(int pos, int limit) {
if (track[pos] == n) {
if (pos - 1 < opt) {
for (int i = 1; i <= pos; i++)
a... | 17 |
//Rafiqul Islam, MBSTU,ICT
#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>
#include <queue>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#defin... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int N = 200003;
template <typename T>
bool chmax(T &a, const T &b) {
if (a < b) return a = b, 1;
return 0;
}
int T, n, m, cnt, mx, sum, wei, pos[N], bu[26], bbu[N], stk[N], tp, seg[N << 2],
ansl[N], ansr[N];
char str[N];
void del(int c) {
c -= 'a';
--bbu[b... | 23 |
#include <bits/stdc++.h>
using namespace std;
int fx[] = {0, 1, -1, 0, 0, 1, 1, -1, -1};
int fy[] = {0, 0, 0, 1, -1, 1, -1, 1, -1};
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)); }
long long gcd... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e5 + 55;
int x[2 * MAX];
vector<pair<pair<int, int>, int>> v;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
for (int i = 0; i < n; i++) cin >> x[i];
v.push_back({{2, n}, 1});
v.push_back({{1, n}, 100000... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 3e5;
const int INF_ = 0x3f3f3f3f;
bool flag[MAX_N + 10];
int fa[MAX_N + 10];
vector<int> sons[MAX_N + 10];
int sons_size[MAX_N + 10];
int pos[MAX_N + 10];
void dfs(int v) {
if (sons[v].size() == 0) {
sons_size[v] = 1;
pos[v] = 1;
return;
}
... | 11 |
#include <bits/stdc++.h>
const int MN = 500005;
int N, A[MN], S;
std::vector<int> G[MN];
int dep[MN], faz[MN][19];
long long Ans;
void DFS(int u, int f) {
dep[u] = dep[faz[u][0] = f] + 1;
for (int j = 0; 2 << j < dep[u]; ++j) faz[u][j + 1] = faz[faz[u][j]][j];
if (u != S) {
long long mn = 0x3f3f3f3f3f3f3f3f;
... | 20 |
#include <bits/stdc++.h>
using namespace std;
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long t;
cin >> t;
while (t--) {
long long n;
cin >> n;
string s;
cin >> s;
long long ans = 0;
for (long long i = 0; i < n; i++) {
if (s[i] != '0') {
... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 200010;
int k, n, m;
int cnt;
long long a[N], b[N], c[N], g;
map<long long, bool> M;
map<long long, int> S;
long long Gcd(long long x, long long y) { return !y ? x : Gcd(y, x % y); }
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++)
scanf("%I6... | 18 |
#include <bits/stdc++.h>
using namespace std;
long long n, a;
long long ans = -1e9;
int main() {
cin.sync_with_stdio(0);
cin.tie(0);
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> a;
long long t;
if (a < 0)
ans = max(ans, a);
else {
t = sqrt(a);
if (t * t != a) {
ans =... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long a, b, ans = 0;
cin >> a >> b;
for (long long i = 1; i <= 2000000000; i *= 2)
for (long long j = 1; i * j <= 2000000000; j *= 3)
if (i * j >= a && i * j <= b) ans++;
cout << ans << ... | 5 |
#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
if (b == 0) return a;
return gcd(b, a % b);
}
void es(int n, vector<int> &p) {
vector<bool> pr(n, true);
for (int i = 2; i < n; i++) {
if (pr[i]) {
p.push_back(i);
for (int j = i; j < n; j += i) {
pr[j] = false;
... | 10 |
#include <bits/stdc++.h>
using namespace std;
int DST[15][15];
int DP[32768], ans;
int deg[15], x, y, c;
int n, m, M, i, j, k;
int main() {
cin >> n >> m;
for (i = 0; i < n; i++)
for (j = 0; j < n; j++) DST[i][j] = 1000000000;
for (i = 1; i <= m; i++) {
cin >> x >> y >> c;
deg[--x]++;
deg[--y]++;
... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 200000 + 10;
int arr[maxn];
int main() {
int n, sum = 0;
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
int x;
scanf("%d", &x);
arr[i] = arr[i - 1] + x;
sum += x;
}
int half = (sum + 1) / 2;
for (int i = 1; i <= n; i++)
if (... | 5 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:16777216")
using namespace std;
int main() {
int p;
cin >> p;
int n = 0;
for (int(x) = (1); x < (p); ++(x)) {
long long xx = x;
bool b = 1;
for (int(k) = (1); k < (p - 1); ++(k)) {
if ((xx - 1) % p == 0) {
b = false;
brea... | 6 |
#include <bits/stdc++.h>
using namespace std;
char s[123456];
int a[2][2];
int main() {
long long sum1 = 0, sum2 = 0;
gets(s);
for (int i = 0; s[i]; i++) {
int x;
if (s[i] == 'a')
x = 1;
else
x = 0;
++a[x][i & 1];
sum1 += a[x][i & 1];
sum2 += a[x][(i & 1) ^ 1];
}
cout << su... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
using ll = long long;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
int n;
map<ll, vector<pair<ll, ll>>> mp;
vector<pair<ll, ll>> f;
bool check() {
for (auto &i : mp) {
if (i.second.size() != f.size()) return 0;
ll tt = 0;
for (aut... | 18 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 110000;
const int mod = 1e9 + 9;
int pw(int x, int k) {
int re = 1;
for (; k; k >>= 1, x = (long long)x * x % mod)
if (k & 1) re = (long long)re * x % mod;
return re;
}
int inv(int x) { return pw(x, mod - 2); }
int cal(int x, int k) {
if (x == 1... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
long long int qt;
cin >> qt;
double arr[qt];
double d = 0;
double n = 0;
for (long long int i = 0; i < qt; i++) {
cin >> arr[i];
d += 10;
double temp = (arr[i] / 100) * 10;
n += temp;... | 0 |
#include <bits/stdc++.h>
using namespace std;
struct Point {
int x, y;
Point(int xx = 0, int yy = 0) { x = xx, y = yy; }
bool operator<(Point p) { return x < p.x || (x == p.x && y < p.y); }
} p[4][100005];
int n, head[400005][4], tail[400005][4], pre[4][400005], nxt[4][400005];
int tmp[4][400005], top, tot;
bool ... | 17 |
#include <bits/stdc++.h>
using namespace std;
const long long maxn = 1e6 + 1e2;
long long n, k, p, bb;
long long a[maxn];
vector<int> b;
int main() {
cin >> n >> k >> p;
for (long long i = 0; i < n; i++) {
cin >> a[i];
}
for (long long i = 0; i < k; i++) {
cin >> bb;
b.push_back(bb);
}
sort(a, a... | 10 |
#include <bits/stdc++.h>
using namespace std;
constexpr int UNDEF = -1;
class Application {
public:
inline void Run();
private:
inline void LoadData();
inline void Solve();
int size_;
map<int, int> M;
};
int main() {
ios_base::sync_with_stdio(false);
Application app;
app.Run();
}
inline void Applicat... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n, a[12], f[120000];
int main() {
cin >> n >> a[1] >> a[2] >> a[3];
memset(f, -1, sizeof(f));
f[0] = 0;
for (int i = 1; i <= 3; i++)
for (int j = a[i]; j <= n; j++) {
if (f[j - a[i]] < 0) continue;
f[j] = max(f[j], f[j - a[i]] + 1);
}
cout ... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int maxN = 700 + 10;
struct bint {
vector<int> a;
bint() {}
bint(int x) {
while (x) a.push_back(x % 10), x /= 10;
}
int size() { return a.size(); }
void norm() {
int dby = 0;
for (int i = 0; i < a.size(); i++) dby += a[i], a[i] = dby % 10, dby ... | 17 |
#include <bits/stdc++.h>
#pragma GCC optimize(3, "Ofast", "inline")
#pragma GCC target("avx,avx2")
using namespace std;
template <class t>
inline t read(t &x) {
char c = getchar();
bool f = 0;
x = 0;
while (!isdigit(c)) f |= c == '-', c = getchar();
while (isdigit(c)) x = (x << 1) + (x << 3) + (c ^ 48), c = g... | 21 |
#include <bits/stdc++.h>
using namespace std;
inline void R(int &x) {
x = 0;
int f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = x * 10 + ch - '0';
ch = getchar();
}
x *= f;
}
void Redirect() {
fre... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
void solve() {
string s;
cin >> s;
vector<int> arr;
int ones = 0;
for (char c : s) {
if (c == '1')
ones++;
else {
if (ones) arr.push_back(ones);
ones = 0;
}
}
if (ones) arr.push_back(ones);
if (arr.em... | 0 |
#include <bits/stdc++.h>
#pragma GCC optimize "03"
using namespace std;
long long int a[200005], b[200005], c[200005];
vector<long long int> g[200005];
long long int ans = 0;
pair<long long int, long long int> dfs(long long int node, long long int par,
long long int cost) {
cost... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long x, y, n;
cin >> x >> y >> n;
long long a0 = 100000, b0 = 1;
long long a1, b1, a2, b2, a, b, p;
for (int i = 1; i <= n; i++) {
p = i * x / y;
for (int j = 1; j <= 2; j++, p++) {
a1 = p * y - i * x;
if (a1 < 0) a1 = -a1;
... | 9 |
#include <bits/stdc++.h>
using namespace std;
double ma[100010];
double mi[100010];
double ans1[100010];
double ans2[100010];
void solve(double a, double b, double c, double &x, double &y) {
x = (-b - sqrt(fabs(b * b - 4 * a * c))) / (2 * a);
y = (-b + sqrt(fabs(b * b - 4 * a * c))) / (2 * a);
if (x > y) swap(x, ... | 16 |
#include <bits/stdc++.h>
using namespace std;
vector<pair<long long, long long> > ans;
vector<pair<long long, long long> > ans2;
int main() {
std::ios_base::sync_with_stdio(false);
unsigned long long x;
cin >> x;
int limit;
long double rad = x * 1.0;
rad = pow(rad, 1.0 / 3.0);
rad = rad * 2.0;
limit = 2... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3f;
const long long mod = 1e9 + 7;
const double PI = acos(-1.0);
const double eps = 1e-10;
const int K = 13;
int n, k;
struct P {
int l[K], r[K], num;
P() {
memset(l, 0, sizeof l);
memset(r, 0, s... | 19 |
#include <bits/stdc++.h>
using namespace std;
vector<long long int> v;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long int i, j = 1, s;
while (1) {
if (j > INT_MAX) break;
v.push_back(j);
j = j << 1;
}
s = v.size();
long long int test;
cin >> test;
while (test--) {
... | 1 |
#include <bits/stdc++.h>
using ll = long long;
using ull = unsigned long long;
using vi = std::vector<int>;
using vll = std::vector<ll>;
using vull = std::vector<ull>;
using pii = std::pair<int, int>;
using pll = std::pair<ll, ll>;
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr)... | 13 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, m, a[55], b[55], ans[55];
cin >> n >> m;
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 0; i < m; i++) cin >> b[i];
for (int i = 0; i < n; i++) {
ans[i] = a[i] * b[0];
for (int j = 0; j < m; j++) ans[i] = max(ans[i], a[i] *... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 5;
const long long mod = 998244353;
int main() {
long long n, k, a, b;
scanf("%lld%lld%lld%lld", &n, &k, &a, &b);
if (k == 1 || n < k) {
printf("%lld\n", (n - 1) * a);
return 0;
}
long long ans = (n - 1) * a;
long long ans1 = 0;
... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 5;
int N, W, cnt;
int A[MAXN], B[MAXN];
int S[2 * MAXN], Z[2 * MAXN];
void ZFunction() {
int L = 0, R = 0;
Z[0] = N;
for (int i = 1; i < N; i++) {
if (i > R) {
L = R = i;
while (R < N && S[R] == S[R - L]) {
R++;
}
... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 2e+9;
const int LIM = 2014;
int d[LIM][LIM];
int p[LIM];
vector<bool> used(LIM);
vector<int> dist(LIM);
vector<vector<int> > g(LIM, vector<int>());
vector<vector<int> > c(LIM, vector<int>());
int get_p(int id) {
if (p[id] == id) return id;
return p[id] =... | 11 |
// --------------------------------------------------<TEMPLATE>--------------------------------------------------
// --------------------<optimizations>--------------------
/*
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx,avx2,fma")
*/
// -------------------</optimizations>--------------------
/... | 17 |
#include <bits/stdc++.h>
using namespace std;
const char IN[] = "_.in";
const char OUT[] = "_.out";
const int maxn = 200;
int ntest = 0, test, n;
bool ok;
bool c[maxn][maxn];
int a[maxn], d[maxn];
int main() {
cin >> n;
memset((c), (false), sizeof(c));
for (int i = (1); i <= (n); i++) cin >> a[i];
for (int i = ... | 8 |
#include <bits/stdc++.h>
using namespace std;
int A[100000];
int main() {
ios_base::sync_with_stdio(false);
cout.tie(0);
cin.tie(0);
int n, m, i, j, k, x, y, z, a, b, c;
cin >> n >> m;
while (m--) {
cin >> a;
if (a == 1) {
cin >> x >> y;
A[x] = A[y] = 1;
} else {
cin >> x;
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int area = 0, xy1[2], xy2[2], xmax = 0, ymax = 0, xmin = 32000, ymin = 32000,
n, i;
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%d%d%d%d", &xy1[0], &xy1[1], &xy2[0], &xy2[1]);
area += (xy2[0] - xy1[0]) * (xy2[1] - xy1[1]);
if (xmax... | 7 |
#include <bits/stdc++.h>
using namespace std;
long long wt, i, j, id, vis[100005], dp[1005][1005], w[10005], b[10005], n, m,
u, uu, mat[1005][1005], ans;
vector<long long> g[1005], v[1005];
long long go(long long i, long long cwt) {
if (cwt > wt) return -(1e10);
if (i == id) return 0;
if (dp[i][cwt] != -1) re... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 30;
long long v[maxn];
int notes[maxn], coins[maxn], w[maxn], n, x;
struct Node {
int id;
long long val;
Node(int _id = 0) {
id = _id;
val = v[id];
}
bool operator<(const Node& p) const { return val > p.val; }
} tmp;
priority_queue<N... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
vector<int> Num;
scanf("%d", &n);
Num.resize(n);
for (int i = 0; i < n; i++) scanf("%d", &Num[i]);
for (int i = 0; i + 1 < n; i++)
if (abs(Num[i] - Num[i + 1]) > 1) {
printf("No\n");
return 0;
}
printf("Yes\n");
return... | 8 |
#include <bits/stdc++.h>
using namespace std;
long long int comb(long long int n, long long int x) {
long long int num, den;
for (long long int i = (n - x + 1); i <= n; i++) num *= i;
for (long long int i = x; i > 1; i--) den *= i;
return (num / den);
}
long long int bin(long long int n) {
long long int d = 0... | 3 |
#include <bits/stdc++.h>
template <typename T>
inline void read(T &x) {
x = 0;
char c = getchar();
bool flag = false;
while (!isdigit(c)) {
if (c == '-') flag = true;
c = getchar();
}
while (isdigit(c)) x = x * 10 + (c ^ 48), c = getchar();
if (flag) x = -x;
}
using namespace std;
const int P = 99... | 26 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string x;
int count = 0;
int total = 0;
while (getline(cin, x)) {
if (x[0] == '+')
count++;
else if (x[0] == '-')
count--;
else if (x[0] != '+' && x[0] != '-') {
int l = (x.length() - 1) - x.find(':');
total += l * co... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
char a[1000011], b[1000011];
long long int i = 0, j = 0, ln_1, ln_2;
scanf("%s %s", &a, &b);
ln_1 = strlen(a);
ln_2 = strlen(b);
while (a[i] == '0') i++;
while (b[j] == '0') j++;
if (ln_1 - i > ln_2 - j)
printf(">\n");
else if (ln_1 - i < ... | 1 |
#include <bits/stdc++.h>
using namespace std;
struct cup {
int vol, ord, num;
cup(int v, int o, int n) : vol(v), ord(o), num(n){};
};
int main(int argc, char** argv) {
int n, w, a;
cin >> n >> w;
vector<cup> cups;
for (int i = 0; i < n; i++) {
cin >> a;
cups.push_back(cup(a, i, 0));
}
sort(cups.... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
const int inf = 0x3f3f3f3f;
long long gcd(long long first, long long second) {
if (second == 0)
return first;
else
return gcd(second, first % second);
}
long long ksm(long long a, long long b) {
long long r = 1;
while (b) {
if ... | 11 |
#include <bits/stdc++.h>
using namespace std;
struct E {
int x, y, g, s;
} e[50005];
int n, m, g, s, k;
int p[202];
long long ans = (long long)(4 * 1e18);
bool cmpg(const E& a, const E& b) { return a.g < b.g; }
bool cmps(const E& a, const E& b) { return a.s < b.s; }
int root(int x) { return p[x] < 0 ? x : p[x] = root... | 14 |
#include<iostream>
#include<cstdio>
using namespace std;
typedef long long ll;
ll re() {
char c = getchar(); ll all = 0, pd = 1;
for (; c > '9' || c < '0'; c = getchar()) if (c == '-') pd = -1;
while (c >= '0' && c <= '9') all = all * 10 + c - '0', c = getchar();
return all * pd;
}
ll judge(ll a, ll b, ll n,ll t) {... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 1;
;
vector<pair<int, int> > adj[N];
vector<int> lis;
set<int> lucky_ver;
int sum, dem[N], ar[10], mul[10];
;
bool used[N];
void dfs(int x) {
for (int i = 0; i < adj[x].size(); i++) {
if (!lucky_ver.count(adj[x][i].second) && !used[adj[x][i].first]... | 11 |
#include <bits/stdc++.h>
using namespace std;
vector<pair<long long, long long> > p[4];
int st[4], mid_pos[4], pos[4];
pair<long long, long long> operator+(const pair<long long, long long> &a,
const pair<long long, long long> &b) {
return make_pair(a.first + b.first, a.second + b.... | 18 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1010;
int n, res, a, b;
string s;
int main() {
res = 0;
cin >> n >> a >> b;
for (int i = 1; i <= n; i++) {
if (i - 1 >= a && n - i <= b) res++;
}
cout << res;
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = 4000000;
int nans, aans[N], bans[N], cans[N], dans[N], A, B, C, D;
vector<int> v, vv, va, vb, vc;
int need, n, x[20], j;
bool is[20];
int AA, BB, CC;
bool good(int A) {
if (A > 255) return false;
v.clear();
if (A == 0LL) {
v.push_back(0);
if (nee... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
bitset<200005> ans;
int k;
for (int i = 0; i < n; i++) cin >> k, ans[k] = 1;
cout << n - ans.count() + 1 << '\n';
return 0;
}
| 5 |
#include <bits/stdc++.h>
struct MI {
private:
char bb[1 << 14];
FILE *f;
char *bs, *be;
char e;
bool o, l;
public:
MI() : f(stdin), bs(0), be(0) {}
inline char get() {
if (o) {
o = 0;
return e;
}
if (bs == be) be = (bs = bb) + fread(bb, 1, sizeof(bb), f);
if (bs == be) {
... | 23 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.