solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
int h;
long long n;
long long cal(int h, long long n, bool d) {
if (h == 0) return 0;
if (d == 0) {
if (n <= (1LL << (h - 1)))
return 1LL + cal(h - 1, n, 1);
else
return (1LL << h) + cal(h - 1, n - (1LL << (h - 1)), 0);
} else {
if (n > 1LL << ... | 9 |
#include <bits/stdc++.h>
using namespace std;
int arr1[100005 + 5], arr2[100005 + 5];
int main() {
ios_base ::sync_with_stdio(false);
cin.tie(NULL);
int i, j, k, n, cs = 0, tc;
int m;
cin >> n >> m;
for (i = 0; i < n; i++) cin >> arr1[i];
for (i = 0; i < m; i++) cin >> arr2[i];
int ans = 0;
for (i = 0... | 7 |
#include <bits/stdc++.h>
using namespace std;
int val[15][4];
int main() {
int n, m, k, s;
scanf("%d %d %d %d", &n, &m, &k, &s);
for (int i = 0; i < 10; i++)
for (int j = 0; j < 4; j++) val[i][j] = -100000;
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++) {
int tem;
scanf("%d", &tem);... | 14 |
#include <bits/stdc++.h>
using namespace std;
string s1, s2;
bool check(string s1, string s2) {
string s3 = s1 + s1;
if (s3.find(s2) != std::string::npos) {
return true;
} else {
return false;
}
}
int main() {
int n;
cin >> n;
int x;
s1 = "";
s2 = "";
for (int i = 0; i < n; ++i) {
scanf(... | 5 |
#include <bits/stdc++.h>
using namespace std;
int P;
long long N, K, q;
bool Solve(long long n) {
if (N % 2 == 0) {
if ((N - n) % 2 == 0 && (N - n) / 2 < K) {
return true;
}
if ((N - n) % 2 == 1 && (N - n + 1) / 2 <= K - N / 2) {
return true;
}
} else {
if (n == N) return K > 0;
... | 11 |
#include <bits/stdc++.h>
using namespace std;
string a, b;
int main(void) {
ios_base::sync_with_stdio(false);
cin >> a >> b;
if (a.size() != b.size()) {
cout << "NO" << endl;
return 0;
}
bool az = 1, bz = 1;
for (char c : a) {
if (c == '1') az = 0;
}
for (char c : b) {
if (c == '1') bz =... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const long double eps = 1e-9;
const int maxn = 1e5 + 10;
double seg[maxn << 2], Tag_Multi[maxn << 2], Tag_Plus[maxn << 2];
double ans = 0;
inline int read() {
int x = 0, flag = 1;
char ch = getchar();
while (!isdigit(ch) && ch != '-') ch = getchar... | 15 |
#include <bits/stdc++.h>
using namespace std;
long long int m, n;
long long int people[200010];
long long int c_or_d[200010];
long long int leftdriver[200010];
long long int rightdriver[200010];
long long int driverans[200010];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> m >> n;
for (long long... | 4 |
#include <bits/stdc++.h>
int main() {
int n;
std::cin >> n;
std::vector<int> a(n), b(n);
int mx = 160000;
for (int i = 0; i < n; i++) {
std::cin >> a[i];
}
for (int i = 0; i < n; i++) {
std::cin >> b[i];
}
double sm1 = 0;
double sm2 = 0;
for (int d = 0; d < mx; d++) {
bool flag = false... | 9 |
#include <bits/stdc++.h>
using namespace std;
int n, cnt, maxi = 0, ans1 = 0, ans2 = 0;
string s;
int a, c, g, t;
int main() {
cin >> n;
cin >> s;
if (n % 4 == 0) {
for (int i = 0; i < s.length(); i++) {
if (s[i] == 'A') a++;
if (s[i] == 'C') c++;
if (s[i] == 'G') g++;
if (s[i] == 'T')... | 1 |
#include <bits/stdc++.h>
using namespace std;
int n, x, sum;
int a[101];
void doit() {
scanf("%d", &n);
int sum = 0, ans = 0;
for (int i = 0; i < n; i++) scanf("%d", &x), a[x]++, sum += x;
for (int i = 1; i < 101; i++)
if ((i % 2 == sum % 2) && a[i] > 0) ans += a[i];
printf("%d\n", ans);
}
int main() { do... | 1 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
template <class T>
ostream &operator<<(ostream &os, const ... | 17 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n, k;
cin >> n >> k;
vector<long long> ans(n, 0), v(n);
for (long long &i : v) cin >> i;
for (int i = 0; i < k; i++) {
int a, b;
cin >> a >> b;
a--;
b--;
if (v[a] > v[b]) ans[a]--;
if (v[b] > v[a]) ans[b]--;
}
vector<... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, cnt = 0, a = 0, b = 0;
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> a;
if (a != b) {
cnt++;
b = a;
}
}
cout << cnt;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
cout << n - 1 << "\n";
for (int i = 2; i <= n; i++) {
cout << i << " ";
}
cout << "\n";
}
}
| 0 |
#include <bits/stdc++.h>
const int N = 100005, bit = 21;
int n, q, cnt, e_cnt, v_cnt, top;
int heads[N], vheads[N], a[N], stk[N], f[bit][N], dep[N], dfn[N];
bool key[N], c[N];
struct Edge {
int v, nxt;
} e[N << 1], g[N << 1];
inline void add(int u, int v, int *heads, Edge *e, int &e_cnt) {
e[++e_cnt].v = v, e[e_cnt... | 20 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:32000000")
using namespace std;
inline bool read(int& val) { return scanf("%d", &val) != -1; }
inline bool read(long long& val) { return scanf("%I64d", &val) != -1; }
inline bool read(double& val) { return scanf("%lf", &val) != -1; }
inline bool read(char* val) {... | 14 |
#include <bits/stdc++.h>
using namespace std;
priority_queue<int, vector<int>, greater<int> > q;
int op[1000005], x[1000005], ans[1000005];
signed main() {
ios::sync_with_stdio(false), cin.tie(0);
int t = 1;
while (t--) {
int n;
cin >> n;
char c;
for (int i = 1; i <= n * 2; ++i) {
cin >> c;
... | 9 |
#include <bits/stdc++.h>
using namespace std;
long long dist(long long x1, long long y1, long long x2, long long y2) {
return (x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1);
}
int main() {
int n;
cin >> n;
long long x1, y1, x2, y2;
string s;
vector<pair<string, pair<long long, long long> > > pp1, pp2, pp3, p... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
long long int n, x, i, j, k = 0;
cin >> n >> x;
for (i = 1, j = 1; (i - k) <= x; i = (j + k)) {
if ((i - k) == j) {
k++;
j++;
}
}
cout << x + k << endl;
}
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 2000000000;
static inline int Rint() {
struct X {
int dig[256];
X() {
for (int i = '0'; i <= '9'; ++i) dig[i] = 1;
dig['-'] = 1;
}
};
static X fuck;
int s = 1, v = 0, c;
for (; !fuck.dig[c = getchar()];)
;
if (c == '-'... | 16 |
#include <bits/stdc++.h>
using namespace std;
int n, m, k;
char b[16][128];
int x[16], y[16];
int dp[16][2];
int f(int i, int j) {
if (dp[i][j] >= 0) return dp[i][j];
int r;
if (i == k) {
assert(y[i] >= 0 && x[i] < m);
if (j == 0)
r = y[i];
else
r = m - 1 - x[i];
} else {
if (y[i] < ... | 8 |
#include <bits/stdc++.h>
#pragma comment(linker, "/stack:225450978")
#pragma GCC optimize("Ofast")
using namespace std;
const long long Mod = 1000000007LL, INF = 1e9, LINF = 1e18;
const long double Pi = 3.141592653589793116, EPS = 1e-9,
Gold = ((1 + sqrt(5)) / 2);
long long keymod[] = {1000000007LL, 1... | 18 |
#include <bits/stdc++.h>
using namespace std;
int n, k, le[200005], y[200005];
char x[20];
map<int, int> v[20];
long long cur, ans;
int main() {
scanf("%d%d", &n, &k);
for (int i = 0; i < n; i++) {
scanf("%s", x);
le[i] = strlen(x);
sscanf(x, "%d", y + i);
v[le[i]][y[i] % k]++;
}
for (int i = 0;... | 11 |
#include <bits/stdc++.h>
using namespace std;
int a[200];
int main() {
int sum1 = 0, sum2 = 0;
int n;
cin >> n;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
if (x > 0)
sum1 += x;
else
sum2 += x;
}
cout << sum1 - sum2;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
string graph[505];
int vis[505][505], n, m, k;
int x[5] = {0, 1, 0, -1};
int y[5] = {1, 0, -1, 0};
bool valid(int a, int b) {
return ((a >= 0 and a < n) and (b >= 0 and b < m)) ? true : false;
}
void dfs(int i, int j) {
vis[i][j]++;
for (int ii = 0; ii < 4; ii++) {
... | 8 |
#include <bits/stdc++.h>
const int inf = 1e9;
const int oo = 1e9;
const long long infll = (1LL << 60) - 1;
namespace network_flow {
const int max0 = 100000, max1 = 100000;
struct edge {
int id, g, nxt;
edge() {}
edge(int id, int g, int nxt) : id(id), g(g), nxt(nxt) {}
};
int st[max0 + 5], en = 0;
edge e[max1 + 5]... | 16 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = (long long)1e9;
const long long inf = (long long)1e18;
const long double eps = (long double)1e-6;
const long long mod = (long long)1e9 + 7;
const long long MAXN = 1001;
const long long MAXLOG = 19;
const long long maxlen = (long long)1e5;
const long lo... | 18 |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
if (a == 0) return b;
return gcd(b % a, a);
}
int main() {
long long n, k;
cin >> n >> k;
for (int i = 0; i < k; i++) {
if (n % 2 == 0) n /= 2;
if (n % 5 == 0) n /= 5;
}
cout << n;
for (int i = 0; i < k; i++)... | 3 |
#include <bits/stdc++.h>
using namespace std;
inline void swap(int &a, int &b) {
a ^= b;
b ^= a;
a ^= b;
}
const int MAXN = 100010;
int n;
int a[MAXN];
int w[MAXN];
int p[MAXN];
int ans[2][MAXN * 5];
int cnt = 0;
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", a + i);
w[a[i]] ... | 10 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long n;
cin >> n;
cout << -(n - 1) << " " << n << endl;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long t = 1;
cin >> t;
while (t--) solve();
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
bool Map[500][500];
int Sum[500][500];
int main() {
int M, N, K;
cin >> M >> N >> K;
for (int i = 0; i < M; i++)
for (int j = 0; j < N; j++) {
char c = getchar();
while (c != '0' && c != '1') c = getchar();
Map[i][j] = (c == '1');
}
memset(... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string chars[5] = {"Sheldon", "Leonard", "Penny", "Rajesh", "Howard"};
long long n;
cin >> n;
if (n <= 5) {
cout << chars[n - 1] << endl;
return 0;
}
int sheldon = 1;
for (int i = 0; i < 30; i++) {
sheldon = sheldon + (5 * pow(2, i));
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long t, n, k, steps, remainder;
cin >> t;
for (int l = 0; l < t; l++) {
steps = 0;
cin >> n >> k;
if (k == 1) {
cout << "1" << endl;
continue;
}
while (n > 0) {
remainder = n % k;
if (remainder == 0) {
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int n, k;
map<int, int> ma;
int a[200000];
bool prov(int x) {
int kol = 0;
for (auto it : ma) {
kol += it.second / x;
}
if (kol >= k)
return 1;
else
return 0;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> k;
... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
long long int n, m;
cin >> n >> m;
long long int a, b;
long long int portal = 0;
for (long long int i = 0; i < n; i++) {
cin >> a >> b;
if (portal >= a) {
portal = max(port... | 3 |
#include <bits/stdc++.h>
long i, n, pr[45050];
bool flag;
void search(long low, long high, long p) {
if (high < low || flag == 0) return;
long mid = (high + low) / 2;
if (pr[mid] == p) {
flag = 0;
return;
} else if (pr[mid] > p)
search(low, mid - 1, p);
else
search(mid + 1, high, p);
}
int mai... | 5 |
#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > pp;
int ma, an[12], d[12], n, r;
int f(int s[]) {
int res = 0;
for (int i = 0; i < (n); ++i)
for (int j = (i + 1); j < (n); ++j) {
res += (pp[s[i]].first - pp[s[j]].first) *
(pp[s[i]].first - pp[s[j]].first) +
... | 19 |
#include <bits/stdc++.h>
using namespace std;
int n;
int a[100005];
int main() {
int i, j, k;
while (~scanf("%d", &n)) {
for (i = 1; i <= n; i++) scanf("%d", &a[i]);
if (a[n] == 1) {
printf("NO\n");
continue;
}
if (n == 1) {
if (a[1] == 0)
printf("YES\n0\n");
else
... | 14 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 100100;
ll n, k, ans = 0;
bool srt(pair<ll, ll> p1, pair<ll, ll> p2) {
if (p1.first == p2.first) return p1.second < p2.second;
return p1.first < p2.first;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> k;
vect... | 8 |
#include <bits/stdc++.h>
using namespace std;
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 << 3) + (x << 1) + (ch ^ 48);
ch = getchar();
}
return x * f;
}
const int... | 20 |
#include <bits/stdc++.h>
using namespace std;
long long int calc(long long int a, long long int b, long long int base) {
long long int carry = 0;
long long int l = 0;
while (a > 0 || b > 0) {
if (a % 10 >= base || b % 10 >= base) return -1;
carry = (a % 10 + b % 10 + carry) / base;
l++;
a /= 10;
... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
s += '.';
vector<int> result;
vector<int> braces;
for (int i = 0; i < s.size(); i++) {
if (s[i] == '(') {
braces.push_back(i);
} else if (s[i] == ')') {
if (braces.empty()) {
cout << -1 << endl;
... | 7 |
#include <bits/stdc++.h>
using namespace std;
vector<long long int> vec;
int main() {
long long int result = 0, i, sz, median, inp, mid_array;
while (cin >> sz >> median) {
vec.clear();
result = 0;
for (i = 0; i < sz; i++) {
cin >> inp;
vec.push_back(inp);
}
sort(vec.begin(), vec.end... | 5 |
#include <bits/stdc++.h>
const double pi = acos(-1.0);
const int maxn = 0;
const int maxm = 0;
using namespace std;
int edg[1000006];
vector<long long> ed[1000006];
long long con(int root, int h, int last) {
if (h <= 0) return 0;
if (root == 0) return 0;
long long int ans = 0;
if (last > 0)
ans += con(last ... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const int MAXN = 300005;
string perm = "ACGT";
int n, m;
string grid[MAXN];
string ans[MAXN];
int absolute_min = INF;
int shift[MAXN];
void solve() {
int cur_cost = 0;
for (int i = 0; i < n; ++i) {
int cost_no_shift = 0;
int cost_shift = 0;
... | 13 |
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<set>
#include<map>
#include<iostream>
const int inf = 0x3f3f3f3f;//1.06e9大小
const double PI = acos ( -1 );
const double eps = 1e-6;
typedef unsigned long long ull;
typedef long long ll;
#define pii pair<int ,int>
#define X ... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100010;
const int MAXM = 110;
map<long long, int> p;
long long a[MAXN];
long long use[MAXM];
int main() {
int n;
scanf("%d", &n);
int cnt = 0;
memset(a, 0, sizeof(a));
for (int i = 1; i <= n; i++) {
int k;
scanf("%d", &k);
long long u,... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 2147483647;
const int MAX = 1000000;
long long res;
int c, hr, hb, wr, wb, counter, kr, kb;
int main() {
scanf("%d %d %d %d %d", &c, &hr, &hb, &wr, &wb);
res = 0;
kr = 0;
counter = 0;
while (counter < MAX) {
if (kr * 1LL * wr > c) {
break... | 12 |
#include <bits/stdc++.h>
unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
using namespace std;
double gcd(double a, double b) { return a < 0.01 ? b : gcd(fmod(b, a), a); }
long long bpow(long long a, long long b, long long m) {
a %= m;
long long res = 1;
while (b > 0) {
if (b & 1) ... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7;
int a[N], b[N], n, m, x, y;
vector<pair<int, int> > res;
int main() {
scanf("%d", &n);
scanf("%d", &m);
scanf("%d", &x);
scanf("%d", &y);
for (int i = (1), _i = (n); i <= _i; ++i) {
scanf("%d", &a[i]);
}
for (int i = (1), _i = (m); i... | 5 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
ll n, m;
cin >> n >> m;
vector<ll> ar(n);
vector<ll> br(n);
map<ll, ll> a, b;
for (auto &x : ar) {
cin >> x;
a[x]++;
}
for (auto &x : br) {
cin >> x;
b... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int mx = (int)1e3 + 7;
const int inf = (int)1e9;
const int mod = (int)1e9 + 7;
vector<pair<int, int>> adj[mx + 7];
vector<vector<int>> dist(mx + 1, vector<int>(mx + 1, inf));
int n, m, k;
void dij(int s) {
dist[s][s] = 0;
priority_queue<pair<int, int>, vector<pair... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
const int maxm = 4e5 + 10;
const long long mod = 1e9 + 7;
const int inf = 0x3ffffff;
const double eps = 1e-5;
int a00, a01, a10, a11;
int a[maxn];
map<long long, int> m;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
ci... | 11 |
#include <bits/stdc++.h>
using namespace std;
long n;
int main() {
cin >> n;
int total = 0;
for (int i = 0, b, rec = 0; i < n; i++) {
cin >> b;
if (b > 0) {
rec += b;
continue;
}
if (rec > 0)
rec--;
else
total++;
}
cout << total;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 7;
struct v_dist {
int val[2];
};
vector<int> ans;
vector<char> cl;
bool dfs_c(vector<list<int> > &v, int x) {
cl[x] = 1;
list<int>::iterator it1;
for (it1 = v[x].begin(); it1 != v[x].end(); ++it1) {
int to = *it1;
if (cl[to] == 0) {
... | 13 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int i, n, m, a[10][1000] = {0}, j;
bool logica = false, x;
cin >> n >> m;
for (i = 0; i < n; i++)
for (j = 0; j < m; j++) {
cin >> x;
if (x)
if (i == 0 || i == n - 1 || j == 0 || j == m - 1) logica = 1;
}
cout << 4 - 2 * lo... | 2 |
#include <bits/stdc++.h>
using namespace std;
vector<int> numdig(int num) {
vector<int> temp;
for (int i = 0; i < 4; i++) {
temp.push_back(num % 10);
num /= 10;
}
reverse(temp.begin(), temp.end());
return temp;
}
pair<int, int> valid(int a, int b) {
int x = 0, y = 0;
vector<int> A = numdig(a);
v... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int N = 51;
const int G = 3;
const int TT = 2505;
const int mod = 1e9 + 7;
int add(int x, int y) { return ((x + y) % mod + mod) % mod; }
int mul(int x, int y) {
long long ret = (long long)x * y;
ret %= mod;
return ret;
}
int t[N], g[N];
int dp[G][N][TT];
vector<... | 13 |
#include <bits/stdc++.h>
using namespace std;
int d[1000100], two[1000100];
int main() {
int i, j, k, n, mi = 100000000, ma = 0, cnt = 0, m;
long long res = 0;
two[0] = 1;
for (i = 1; i < 1000100; i++) {
two[i] = two[i - 1] << 1;
if (two[i] >= 1000000007) two[i] -= 1000000007;
}
scanf("%d%d%d", &n, ... | 14 |
#include <bits/stdc++.h>
using namespace std;
int Q = 0;
mt19937 mt_rand(time(NULL));
int query(vector<long long> seq) {
Q++;
int k = seq.size();
assert(1 <= k && k <= 10000);
assert(is_sorted((seq).begin(), (seq).end()));
cout << k;
for (long long x : seq) cout << " " << x;
cout << endl;
int ret = 0;
... | 22 |
#include <bits/stdc++.h>
using namespace std;
long long us[20000], user[20000], i, n, k, j, a[60][60], kol, mx, t;
vector<long long> v;
int main() {
cin >> n;
for (i = 1; i <= n; i++)
for (j = 1; j <= n; j++) cin >> a[i][j];
for (t = 1; t <= n; t++) {
for (i = 1; i <= n; i++) {
for (j = 1; j <= n; j... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long a[100000];
long long d[100000];
int main() {
long long n;
cin >> n;
map<long long, long long> m;
int ds = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
sort(a, a + n);
for (int i = 1; i < n; i++) {
if (++m[a[i] - a[i - 1]] == 1) d[ds++] =... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int a[n];
int sum = 0, count = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
sum += a[i];
if (a[i] == 0) {
count++;
}
}
if (count == 0) {
cout << "-1";
return 0;
} else {
if (sum < 45) {
c... | 2 |
#include <bits/stdc++.h>
using namespace std;
struct node {
double x, y;
};
struct square {
node f[5];
} A, B;
inline bool cal(const node &a, const square &b) {
double u = -999999999, r = -999999999, d = 999999999, l = 999999999;
for (int i = 1; i <= 4; i++) {
d = min(d, b.f[i].y);
u = max(u, b.f[i].y);... | 8 |
#include <bits/stdc++.h>
using namespace std;
long long n;
vector<long long> p;
long long x, a;
long long y, b;
long long k;
bool check(long long m) {
long long ans = 0;
vector<long long> kek(n);
for (long long i = 0; i < m; i++) {
if ((i + 1) % a == 0) kek[i] += x;
if ((i + 1) % b == 0) kek[i] += y;
}
... | 8 |
#include <bits/stdc++.h>
using namespace std;
inline int cmp(double a, double b = 0.0) {
if (fabs(a - b) <= (1e-9)) return 0;
if (a < b) return -1;
return 1;
}
int n;
int minf[7][7], maxf[7][7], cost[7][7];
vector<int> sol;
int fs, cs;
map<vector<int>, int> m;
int solve() {
if (sol[0] == n - 1) return 0;
if (... | 14 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
ostream cnull(NULL);
const int INF = 1000 * 1000 * 1000;
const long long LINF = 1LL * INF * INF;
const int MAX = 100010;
const long double PI = acos(-1.);
const double EPS = 1e-6;
const long long mod = INF + 7;
int n, m, k;
long long binpow(lon... | 8 |
#include <bits/stdc++.h>
int head[10005], n, m, tot, ans, g[10005], f[10005], num, deep[10005];
bool can[20005];
struct node {
int to, next;
} e[20005];
void dfs(int u, int fa) {
bool b = 0;
for (int i = head[u]; i; i = e[i].next) {
int v = e[i].to;
if (v == fa && !b) {
b = 1;
continue;
}
... | 21 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, mark[2048 + 8], r = 0;
cin >> n;
int cnt = pow(2, n + 1) - 2;
for (int i = 0; i < cnt; i++) cin >> mark[i];
for (int i = cnt - 1; i >= 0; i -= 2) {
r += abs(mark[i] - mark[i - 1]);
mark[i / 2 - 1] += max(mark[i], mark[i - 1]);
}
cou... | 6 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline bool chkmin(T &a, const T &b) {
return b < a ? a = b, 1 : 0;
}
template <typename T>
inline bool chkmax(T &a, const T &b) {
return a < b ? a = b, 1 : 0;
}
const int oo = 0x3f3f3f3f;
const int maxn = 200000;
const int maxabs = 1 << 20;
struct... | 16 |
#include<bits/stdc++.h>
#define int long long
#define ld long double
#define ull unsigned long long
#define pb push_back
#define mod 1000000007
#define rep(i,a,b) for(auto i=a;i<b;i++)
using namespace std;
using pii = pair<int,int>;
// to do lucas theorem and ncr with modulus
string solve()
{
int n;
cin>>n;
... | 11 |
#include <bits/stdc++.h>
using namespace std;
int n, m, i = 0;
vector<string> v, res, now;
map<pair<string, string>, bool> mp;
void bitMask(int i = 0, string s = "") {
if (i == n) {
now.clear();
for (int i = 0; i < n; i++)
if (s[i] == '1') {
now.push_back(v[i]);
for (int j = 0; j < now.s... | 7 |
#include <bits/stdc++.h>
using namespace std;
int const N = 1e5 + 10;
int const M = 1e6 + 10;
int const mod = 1e9 + 7;
int const inf = 0x3f3f3f3f;
long long const inf2 = 1e18 + 10;
int prime[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31};
int tag[1010];
int a[1010];
map<int, int> ma;
int main() {
for (int i = 0; i < 11... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int N = 110, M = 100010;
int primes[M], cnt;
bool st[M];
int a[N];
unordered_map<int, int> state, f;
void init() {
for (int i = 2; i < M; i++) {
if (!st[i])
primes[cnt++] = i;
else {
for (int j = 0; primes[j] < M / i; j++) {
st[primes[j] ... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 25;
const int MAXS = 1 << 20;
template <typename T>
void chkmax(T &x, T y) {
x = max(x, y);
}
template <typename T>
void chkmin(T &x, T y) {
x = min(x, y);
}
template <typename T>
void read(T &x) {
x = 0;
int f = 1;
char c = getchar();
for (; !i... | 23 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int main() {
long long x, y;
long long l, r;
cin >> x >> y >> l >> r;
vector<long long> a, b, c;
long long z = 1ll;
while (r / z >= x) {
a.push_back(z);
z *= x;
}
a.pu... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
int a[200005];
for (int i = 0; i < n; ++i) {
scanf("%d", a + i);
}
long long presum = 0, cursum = 0, prebest;
for (int i = 0; i < k; ++i) {
presum += a[i];
}
for (int i = k; i < 2 * k; ++i) {
cursum += a[i]... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 100005;
long long a[MAX], b[MAX];
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) cin >> a[i];
long long max = a[n - 1];
b[n - 1] = 0;
for (int i = n - 2; i >= 0; i--) {
if (a[i] > max) {
max = a[i];
b[i] = 0;
} else... | 3 |
#include <bits/stdc++.h>
const int maxn = 3e3 + 10;
const int N = 4e5 + 10;
using namespace std;
long long gcd(long long p, long long q) { return q == 0 ? p : gcd(q, p % q); }
long long qmul(long long p, long long q, long long mo) {
long long f = 0;
while (q) {
if (q & 1) f = (f + p) % mo;
p = (p + p) % mo;... | 19 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long int n, k;
cin >> n >> k;
long long int A[k];
map<long long int, pair<long long int, long long int> > pos;
for (long long int i = 1; i <= n; i += 1) {
pos[i].first = std::n... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e7 + 5;
long long dp[maxn];
int main() {
int n, x, y;
scanf("%d%d%d", &n, &x, &y);
for (int i = 0; i <= n + 1; i++) dp[i] = 1e18;
dp[1] = x;
for (int i = 2; i <= n; i++) {
if (i % 2 == 0) {
dp[i] = min(dp[i], dp[i / 2] + 1ll * y);
... | 12 |
#include <bits/stdc++.h>
using namespace std;
#define ar array
#define ll long long
const int MAX_N = 1e5 + 1;
const ll MOD = 1e9 + 7;
const ll INF = 1e9;
void solve() {
ll n, k;
cin>>n>>k;
ll p = k/2;
ll ans = p + n-k;
if(k >= (2*n)) {
cout<<n<<endl;
for(l... | 0 |
#include <bits/stdc++.h>
using namespace std;
namespace mine {
const int INF = 0x3f3f3f3f;
long long qread() {
long long ans = 0;
char c = getchar();
int f = 1;
while (c < '0' or c > '9') {
if (c == '-') f = -1;
c = getchar();
}
while ('0' <= c and c <= '9') ans = ans * 10 + c - '0', c = getchar();
... | 19 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
string s;
cin >> s;
string a = s.substr(0, 1);
string b = s.substr(1, 2);
if (stoi(a) < stoi(b)) {
cout << "YES" << endl << 2 << endl << a << " " << s.substr(1) << endl;
... | 1 |
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("fast-math")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")
const long long N = 2010;
long long v[N][N], color[N][N], sum[N][N], sum1[N][N], n;
void start(long... | 11 |
#include <bits/stdc++.h>
using namespace std;
int inf_int = 2e9;
long long inf_ll = 2e18;
const double pi = 3.1415926535898;
template <typename T, typename T1>
void prin(vector<pair<T, T1> >& a) {
for (int i = 0; i < a.size(); i++) {
cout << a[i].first << " " << a[i].second << "\n";
}
}
template <typename T, ty... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int n, pos2, res = 1, pos1;
string s;
int main() {
cin >> s;
n = s.length();
s = ' ' + s;
pos2 = n;
for (int i = n - 1; i >= 1; i--)
if (s[i] != s[i + 1])
pos2--;
else
break;
pos1 = 1;
for (int i = 2; i <= n; i++)
... | 8 |
#include <bits/stdc++.h>
using namespace std;
int A[100010], sz;
int segtree[400010][21];
int lazy[400010][21];
void build_tree(int node, int start, int end) {
int i, j;
if (start > end) return;
if (start == end) {
for (i = 0; i <= 20; i++)
segtree[node][i] = ((A[start] & (1 << i)) ? 1 : 0);
return;... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main(void) {
int c, n, k, r = 0;
cin >> n >> k;
vector<int64_t> A(n);
for (auto& a : A) cin >> a;
sort(A.begin(), A.end());
for (int i = 0; i < n; ++i) {
c = k + A[i];
if (c <= 5) r++;
}
cout << r / 3;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a;
cin >> a;
cout << a / 2 + 1;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 2000000000;
const double pi = acos(-1.0);
int main() {
std::ios_base::sync_with_stdio(false);
int n;
while (cin >> n) {
string s;
int v;
map<string, int> m;
m.clear();
for (int i = 0; i < n; i++) {
cin >> s >> v;
m[s] = ... | 6 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void cmin(T &a, T b) {
((a > b) && (a = b));
}
template <class T>
inline void cmax(T &a, T b) {
((a < b) && (a = b));
}
char IO;
template <class T = int>
T rd() {
T s = 0;
int f = 0;
while (!isdigit(IO = getchar())) f |= IO == '-';
do s... | 22 |
#include <bits/stdc++.h>
using namespace std;
const double PI = 3.1415926535897932384626433832795;
const long long mod = 1000000007;
long long a[] = {1, 2, 9, 64, 625, 7776, 117649, 2097152};
int main() {
long long n, k;
cin >> n >> k;
long long ans = a[k - 1];
for (int i = (0); i < (n - k); ++i) {
ans *= (... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long n, ans = 0, i, j;
long long a[13];
for (n = 1; n <= 12; ++n) {
ans = 0;
for (i = 0; i < 9; ++i) {
for (j = 0; j < 9; ++j) {
if (i >= 1 && j >= 5) continue;
... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
int g[N], ans[N][10];
int G(int x) {
if (g[x] != -1) return g[x];
if (x < 10) return g[x] = x;
int p = 1, y = x;
while (y) {
if (y % 10) p *= y % 10;
y /= 10;
}
return g[x] = G(p);
}
void init() {
memset(g, -1, sizeof(g));
for ... | 5 |
#include <bits/stdc++.h>
int diru[] = {-1, -1, -1, 0, 0, 1, 1, 1};
int dirv[] = {-1, 0, 1, -1, 1, -1, 0, 1};
using namespace std;
template <class T>
T sq(T n) {
return n * n;
}
template <class T>
T gcd(T a, T b) {
return (b != 0 ? gcd<T>(b, a % b) : a);
}
template <class T>
T lcm(T a, T b) {
return (a / gcd<T>(a,... | 6 |
#include <bits/stdc++.h>
using namespace std;
const long double pi = 4 * atan((long double)1);
const long long mod = 1e9 + 7;
const long long inf = 1e9;
const long long llinf = 1e18;
const long long nax = 0;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
string s1, s2;
getline(c... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100001;
int n;
struct Edge {
int to, next;
} edge[N << 1];
int head[N], cnt;
void add_edge(int u, int v) {
cnt++;
edge[cnt].to = v;
edge[cnt].next = head[u];
head[u] = cnt;
return;
}
int num[N], sum[N][6];
inline int calc(int u) {
if (sum[u][5] |... | 15 |
#include <bits/stdc++.h>
using namespace std;
const long long oo = 0x3f3f3f3f3f3f3f3fll;
const int LGN = 25;
const int MOD = 1e9 + 7;
const int N = 75 + 5;
int n, cnt[N][3], idx[N][3];
char s[N];
char w[3] = {'V', 'K', 'X'};
int f(int v, int k, int x, int isv) {
if (v + k + x == n) return 0;
static int dp[N][N][N][... | 17 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.