solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
string cod = "CODEFORCES";
if (s.length() < cod.length()) {
cout << "NO\n";
return 0;
}
if (s[0] == 'C') {
int in = 0;
while (in < cod.length() && in < s.length() && s[in] == cod[in]) in++;
if (in == cod.lengt... | 6 |
#include<bits/stdc++.h>
using namespace std;
//======================
//
// Template OleschY
//
// Die M�glichkeiten der deutschen Grammatik k�nnen
// einen, wenn man sich darauf, was man ruhig, wenn
// man m�chte, sollte, einl�sst, �berraschen.
// - @Gedankenbalsam
//
//======================
//=====================... | 16 |
#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> adj[101101];
int col[101101];
double l[101101];
double dfs(int v) {
if (col[v]) return l[v];
col[v] = 1;
double ret = 0;
int sz = adj[v].size();
for (int i = 0; i < sz; i++) {
int u = adj[v][i];
if (!col[u]) ret += (dfs(u) + 1) / (sz - 1... | 7 |
#include <bits/stdc++.h>
using namespace std;
int func(int g, int b) { return (g - 1 <= b && b <= 2 * (g + 1)); }
int main() {
int al, ar, bl, br;
cin >> al >> ar >> bl >> br;
if (func(al, br) || func(ar, bl))
cout << "YES" << endl;
else
cout << "NO" << endl;
return 0;
}
| 5 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = INT_MAX;
const long long INFll = LLONG_MAX;
const long long mod = 998244353;
const double EPS = 1e-17;
void solveA();
void solveB();
void solveC();
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
solveA();
... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
vector<int> v;
int n;
cin >> n;
int a[5001] = {0};
for (int i = 2; i * i <= 5000; i++) {
if (a[i] == 0) {
for (int j = i * i; j <= 5000; j += i) a[j] = 1;
}
}
for (int i = 2; i <= ... | 7 |
#include <bits/stdc++.h>
using namespace std;
long long MOD = 1000000007;
double eps = 1e-12;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
string S;
cin >> S;
string initial;
int n = S.size();
int center = (n - 1) / 2;
initial += S[center];
for (int i = 1; i < center... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int maxN = 100224;
const double timeLimit = 2.94;
set<pair<int, int> > s;
int n, m, perm[maxN];
int main() {
cin.sync_with_stdio(0);
cin.tie(0);
cin >> n >> m;
clock_t start = clock();
for (int i = 0; i < m; i++) {
int u, v;
cin >> u >> v;
if (u ... | 16 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 2e17;
int al[30];
int main() {
int n;
cin >> n;
int ans = 0;
bool k = 0;
for (int i = 0; i < n - 1; i++) {
char a;
string b;
cin >> a >> b;
if (a == '.') {
for (char j : b) al[j - 'a'] = -1;
} else
ans += k;
... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int c = 4002, k = -1e9;
int n, m, l[c], s[c], f[c], dp[c][c], maxi;
void upd(int a, int b) {
if (a > m) return;
for (int i = 1; i <= b + 1; i++) {
int x = i - 1;
dp[a][x] =
max(dp[a][x], f[a] * x + max(dp[a - 1][2 * x], dp[a - 1][2 * x + 1]));
}
... | 20 |
#include <bits/stdc++.h>
using namespace std;
void debug() {
fflush(stdin);
printf("Press any key to continue");
getc(stdin);
fflush(stdin);
}
int k;
int a[105][105];
int fun(int n, int i) {
int ans = 0;
for (int j = 1; j < n; j++) {
if (j != i && a[n][j] == 1 && a[i][j] == 1) {
ans++;
}
}
... | 8 |
#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > roads;
vector<int> edge[100005];
int par[100005], kids[100005], edge_w[100005];
void dfs(int u) {
kids[u] = 1;
for (int i = 0, v; i < edge[u].size(); i++) {
v = edge[u][i];
if (v == par[u]) {
continue;
}
par[v] = u;
dfs(... | 11 |
#include <bits/stdc++.h>
using namespace std;
int n, q;
int a[100005];
int dp[100005][405];
int getdp(int p, int k) {
if (p > n) return 0;
if (k > (int)sqrt(n)) return 1 + getdp(p + a[p] + k, k);
int& ret = dp[p][k];
if (ret != -1) return ret;
return ret = 1 + getdp(p + a[p] + k, k);
}
int main() {
cin >> n... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, k;
cin >> n >> m >> k;
vector<int> items(k + 1);
for (int i = 1; i <= k; i++) {
int num;
cin >> num;
items[num] = i;
}
int ans = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
int num, index;
c... | 6 |
#include <bits/stdc++.h>
using namespace std;
string cal(string s) {
int64_t tmp1 = 0;
char ch;
int64_t tmp2 = 0;
int i;
for (i = 0; i < s.size(); i++) {
if (s[i] != '*' && s[i] != '+')
tmp1 = tmp1 * 10 + s[i] - '0';
else {
ch = s[i];
break;
}
}
for (i = i + 1; i < s.size(); ... | 13 |
#include <bits/stdc++.h>
using namespace std;
int n, m, t;
string a[510];
int iWeekJClasses[510][510];
int total[510];
int dp[510][510];
int minHours(int week, int classes) {
int minHrs = 300010;
int last = 0;
int cnt = 0;
int j = 0;
while (j < m && a[week][j] != '1') ++j;
for (int i = (j); i < (m); ++i) {
... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 5;
set<int> e[MAXN], st;
bool vis[MAXN], on_edge[MAXN];
int main() {
ios::sync_with_stdio(false);
int n, m, x, y;
cin >> n >> m;
for (int i = 1; i <= m; i++) {
cin >> x >> y;
e[x].insert(y);
e[y].insert(x);
}
for (int i = 1; i ... | 11 |
#include <bits/stdc++.h>
using namespace std;
void affiche(int t[], int n) {
for (int i = 0; i < n; i++) cout << t[i] << " ";
cout << '\n';
}
void afficheV(vector<long long> t) {
for (int i = 0; i < t.size(); i++) cout << t[i] << " ";
cout << '\n';
}
int main() {
ios_base::sync_with_stdio(0), cin.tie(0);
in... | 4 |
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
using namespace std;
#define Ri register
typedef long long ll;
const int N = 1e5 + 100, M = 500;
int n, f[N], son[N], dep[N], A, B, maxdep;
int ansnum, ls[N], tot, fre[N], dp[M][N];
char ans[N];
vector<int> ed[N], d[N];
in... | 23 |
#include <bits/stdc++.h>
using namespace std;
struct ha {
long long x;
long long a;
};
bool cmp(ha a, ha b) {
if (a.x == b.x) return a.a < b.a;
return a.x < b.x;
}
vector<ha> v;
int main() {
long long h, q, i, cl, cr, ch, ii, l, r, br = 1, a, p = 1, n = 1;
ha e;
cin >> h >> q;
for (i = 1; i < h; i++) {
... | 15 |
#include <bits/stdc++.h>
using namespace std;
int gcdExtended(int a, int b, int *x, int *y) {
if (a == 0) {
*x = 0, *y = 1;
return b;
}
int x1, y1;
int gcd = gcdExtended(b % a, a, &x1, &y1);
*x = y1 - (b / a) * x1;
*y = x1;
return gcd;
}
long long int modInverse(int a, int m) {
int x, y;
int g... | 7 |
#include <bits/stdc++.h>
void print(std::string& in, int pos) {
int i = 0;
for (i; i < in.length(); i++) {
if (in[i] == '1') {
break;
}
}
for (i; i < in.length(); i++) {
if (i != pos) {
std::cout << in[i];
}
}
std::cout << std::endl;
}
void process(std::string& in) {
for (int i... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e5 + 9;
string s;
int l, r, st[MAX], t = 1, cnt[MAX], ans;
int main() {
cin >> s;
s += 's';
for (int i = s.size(); i >= 1; i--) s[i] = s[i - 1];
s[0] = ' ';
for (int i = 1; i < s.size(); i++) {
cnt[i] = cnt[i - 1] + (s[i] == '[');
if (s[i]... | 9 |
#include <bits/stdc++.h>
using namespace std;
int m, n;
string s;
const int m_ = 2010;
long long int mm = (long long int)(1e9 + 7);
long long int dp[m_][m_];
int main() {
cin >> n >> m;
cin >> s;
for (int i = 0; i <= 2000; i++) {
for (int j = 0; j <= 2000; j++) {
dp[i][j] = 0;
}
}
dp[0][0] = 1;
... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c, d, e, can_delete = 0, i, star = 0;
string s, temp, ans;
cin >> s;
cin >> a;
for (i = 0; i < s.length(); i++) {
if (s[i] == '?')
can_delete++;
else if (s[i] == '*') {
can_delete++;
star = 1;
} else
temp ... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
if (n / 10 >= 1) {
if (n % 10 != 0) {
if (n / 10 == 9) cout << "ninety-";
if (n / 10 == 8) cout << "eighty-";
if (n / 10 == 7) cout << "seventy-";
if (n / 10 == 6) cout << "sixty-";
if (n / 10 == 5) cout ... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int L = 840;
const int UP = 8 * L;
long long f[9][UP + 3], a[9], n;
int main() {
scanf("%lld", &n);
memset(f, -1, sizeof(f));
f[0][0] = 0;
for (int i = 1; i <= 8; ++i) {
scanf("%lld", &a[i]);
for (long long j = 0; j <= min(a[i], (long long)L / i); ++j)... | 15 |
#include <bits/stdc++.h>
using namespace std;
int prioridade[220 * 2];
int resp[220 * 2];
int fixo[220 * 2];
unsigned long long dp[220 * 2][220 * 2];
int M[110 * 2][110 * 2];
int v[220 * 2];
int n, m;
bool comp(int a, int b) { return prioridade[a] < prioridade[b]; }
unsigned long long get(int x, int qnt) {
("x=%d qnt... | 15 |
#include <bits/stdc++.h>
using namespace std;
int t;
map<int, int> has;
long long fj[55][50], gs[55], bh;
long long n, k;
const long long S = 31624000;
const long long mf = 1e5 + 10;
bool is[S];
long long p[2000000];
void init() {
for (int i = 2; i < S; i++) {
if (!is[i]) p[++p[0]] = i;
for (int j = 1; j <= p... | 25 |
#include <bits/stdc++.h>
using namespace std;
long long n, k;
vector<long long> a;
int f(int x) {
if (x == 1) return 1;
if (x == 2) return 0;
if (x == 3) return 1;
if (x == 4) return 2;
if (x % 2) return 0;
return (f(x / 2) == 1 ? 2 : 1);
}
int g(int x) {
if (x == 1) return 1;
if (x == 2) return 2;
re... | 14 |
#include <bits/stdc++.h>
using namespace std;
vector<int> rez;
int n;
string a, b, s1, s2;
int main() {
cin >> n;
cin >> a >> b;
s1 = a;
sort(s1.begin(), s1.end());
s2 = b;
sort(s2.begin(), s2.end());
if (s1 != s2) {
cout << -1;
return 0;
}
for (int i = 0; i < n; i++) {
for (int j = i; j <... | 15 |
#include <bits/stdc++.h>
using namespace std;
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(long double x) { cerr << x; }
void... | 7 |
#include <bits/stdc++.h>
using namespace std;
long long ax[300000], ay[300000], x[300000], y[300000], n, J;
int main() {
int i, j, k;
while (cin >> n >> J) {
cin >> x[0] >> y[0];
for (i = 0; i < n; i++) {
cin >> ax[i] >> ay[i];
ax[i + n] = ax[i];
ay[i + n] = ay[i];
}
for (i = 1; i ... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 7;
int szx[N << 1], szy[N << 1], fa[N << 1];
long long ans = 0;
int Find(int x) { return x == fa[x] ? x : Find(fa[x]); }
void Union(int x, int y, stack<int> &S) {
x = Find(x), y = Find(y);
if (x == y) return;
ans += szx[x] * szy[y] + szy[x] * szx[y... | 18 |
#include <bits/stdc++.h>
using namespace std;
long long fac[200010];
long long pow(long long a, long long b) {
long long ret = 1;
while (b) {
if (b & 1) ret = (ret * a) % ((long long)1e9 + 7);
b >>= 1;
a = (a * a) % ((long long)1e9 + 7);
}
return ret;
}
long long C(long long a, long long b) {
retu... | 13 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string word, word2;
cin >> word;
for (int i = 1; i < n; ++i) {
cin >> word2;
word2.resize(word.size());
while (word != word2) {
if (word.size() == 0) {
cout << '0';
return 0;
}
word.resize... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 7;
template <class T>
void dbs(string str, T t) {
cout << str << " : " << t << endl;
}
template <class T, class... second>
void dbs(string str, T t, second... s) {
int idx = str.find(',');
cout << str.substr(0, idx) << " : " << t << ",";
dbs(st... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long xyp(long long x, long long y) {
if (y == 0) return 1LL;
if (y == 1) return x;
if (y % 2) {
long long p = xyp(x, y - 1);
return (x * p) % 1000000007;
}
long long p = xyp(x, y / 2);
return (p * p) % 1000000007;
}
long long inv(long long x) { retu... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b;
cin >> a >> b;
int res = abs(a) + abs(b);
int x, y;
x = res;
y = res;
if (b < 0) {
y = 0 - y;
}
bool w = true;
if (a < 0) {
x = 0 - x;
cout << x << " " << 0 << " ";
w = false;
}
cout << 0 << " " << y;
if (w) {... | 2 |
#include <bits/stdc++.h>
using namespace std;
const long long MAX = 1000000000;
int test;
void slove() {
int n;
cin >> n;
vector<long long> a(n + 1, 0), b(n + 1, 0);
long long mina = MAX, minb = MAX;
for (int i = 0; i < n; i++) {
cin >> a[i];
mina = min(mina, a[i]);
}
for (int i = 0; i < n; i++) {... | 0 |
#include <bits/stdc++.h>
using namespace std;
void getint(int &v) {
char ch, fu = 0;
for (ch = '*'; (ch < '0' || ch > '9') && ch != '-'; ch = getchar())
;
if (ch == '-') fu = 1, ch = getchar();
for (v = 0; ch >= '0' && ch <= '9'; ch = getchar()) v = v * 10 + ch - '0';
if (fu) v = -v;
}
const int MO = 1e9 ... | 18 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
int main() {
char w[500][500];
int i, j;
long long k, ans;
while (scanf("%d%d\n", &n, &m) != EOF) {
ans = 1;
for (i = 0; i < n; i++) scanf("%s", w[i]);
for (i = 0; i < m; i++) {
bool u[100];
memset(u, 0, sizeof(u));
for (j = 0... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
cout << __builtin_popcount(n);
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
long long a[n], b[n], sum = 0;
map<long long, long long> m;
for (int i = 0; i < n; i++) {
cin >> a[i];
m[a[i]]++;
}
for (int i = 0; i < n; i++) {
cin >> b[i];
}
vector<long long> v;
for (auto i : m) {
if (i.s... | 9 |
#include <bits/stdc++.h>
using namespace std;
struct standing {
int point = 0, scored_goals = 0, missed_goals = 0;
string name = "";
};
bool cmp(const standing &a, const standing &b) {
if (a.point != b.point) return a.point > b.point;
int diff_a = a.scored_goals - a.missed_goals,
diff_b = b.scored_goals -... | 10 |
#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;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++) cin >> a[i];
int k = 0;
for (int i = 1; i < n - 1; i++) {
if (a[i - 1] == 1 && a[i + 1] == 1 && a[i] == 0) {
k+... | 2 |
#include <bits/stdc++.h>
using namespace std;
int n, f, inp;
long long ans;
struct my {
long long p, c, ip;
} a[100100];
bool cmp(my a, my b) { return a.p > b.p; }
int main() {
ios_base::sync_with_stdio(NULL);
cin.tie(0);
cin >> n >> f;
for (int i = 0; i < n; i++) {
cin >> a[i].p >> a[i].c;
a[i].ip = ... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int k;
string s;
cin >> k >> s;
int n = (int)s.length();
vector<int> a(n, 0), b(1, 0);
for (int(i) = (0); (i) < (n); (i)++) {
if (i) a[i] += a[i - 1];
if (s[i] == '1') {
a[i]++;
b.push_back(i);
}
}
long long ans = 0;
fo... | 8 |
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define fill0(a) memset(a,0,sizeof(a))
#define fill1(a) memset(a,-1,sizeof(a))
#define fillbig(a) memset(a,63,sizeof(a))
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
templa... | 19 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll dp[15][1 << 15];
ll tree[15][1 << 15];
int edge[15];
vector<int> lca[15];
int main(void) {
int n, m, q;
cin >> n >> m >> q;
for (int i = int(0); i < int(m); ++i) {
int a, b;
cin >> a >> b;
a--, b--;
edge[a] |= (1 << b);
edg... | 18 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
char S[200005];
cin >> n >> k >> S;
if (k > 0) {
if (n > 1) {
if (S[0] != '1') {
S[0] = '1';
k--;
}
for (int i = 1; i < n && k != 0; i++) {
if (S[i] != '0') {
S[i] = '0';
k--;
... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
int n, m, f[N], to[N];
pair<int, int> a[N];
bool done[N];
int find(int x) {
while (x != f[x]) {
x = f[x] = f[f[x]];
}
return x;
}
int main() {
scanf("%d %d", &n, &m);
for (int i = 1; i <= n; ++i) {
scanf("%d", &a[i].first);
a[i].s... | 23 |
#include <bits/stdc++.h>
using namespace std;
int mapp[200][200];
int n;
char s[200010], t[200010];
int main() {
while (scanf("%d", &n) != EOF) {
memset(mapp, 0, sizeof(mapp));
scanf("%s%s", s, t);
int ans = 0;
for (int i = 0; i < n; ++i)
if (s[i] != t[i]) {
mapp[s[i]][t[i]] = i + 1;
... | 7 |
#include <bits/stdc++.h>
using namespace std;
int a[100005], b[100005], c[100005];
int main() {
int n, m, i, cnt = 0;
long long sum = 0;
cin >> n >> m;
for (i = 0; i < n; i++) {
cin >> a[i] >> b[i];
sum += a[i];
c[i] = a[i] - b[i];
}
sort(c, c + n);
n--;
while (sum > m && n >= 0) {
sum -... | 3 |
#include <bits/stdc++.h>
using namespace std;
struct Mat {
long long int v[110][110];
int c, r;
void creat(int c0, int r0) {
c = c0;
r = r0;
for (int i = 0; i < r; i++)
for (int j = 0; j < c; j++) v[i][j] = (i == j) ? 1 : 0;
}
};
long long int adjust(long long int num) {
if (num >= 100000000... | 11 |
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main() {
ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
ios_base::sync_with_stdio(false);
cin.t... | 1 |
#include <bits/stdc++.h>
using ll = long long;
using ld = long double;
using namespace std;
const int N = 1e5 + 64;
int XOR[4 * N], ass_[4 * N];
int ls(int v) { return 2 * v + 1; }
int rs(int v) { return 2 * v + 2; }
void push(int v) {
if (ass_[v]) {
ass_[ls(v)] = ass_[v];
XOR[ls(v)] = 0;
ass_[rs(v)] = as... | 16 |
#include <bits/stdc++.h>
using namespace std;
struct ofl {
long double value;
int precision;
inline ofl(long double value, int precision)
: value(value), precision(precision) {}
};
const int seed = hash<string>()("alex256");
const int inf = (int)1e9 + 7;
const int64_t llInf = (int64_t)2e18 + 256;
const int ... | 17 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
const int maxn = 2500;
vector<int> road[2500];
const int inf = 0x3f3f3f3f;
int dis(int a, int b) {
if (a <= b)
return b - a;
else
return n - a + b;
}
int main() {
scanf("%d%d", &n, &m);
for (int i = 0; i < m; i++) {
int a, b;
scanf("%d%d", ... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
char a[n][n];
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
cin >> a[i][j];
}
}
char b[n][n];
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
cin >> b[i][j];
}
}
int i, j;
... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int N, M, k = 1, cnt = 0;
double ans = 1;
cout.precision(14);
cout << fixed;
cin >> N >> M;
while (M >= k) {
k *= 2;
cnt++;
}
k /= 2;
for (double i = 2; i <= N; i++) {
double x = (i - 1) / N, ret = 1;
vector<double> v;
for ... | 8 |
#include <bits/stdc++.h>
using namespace std;
int cnt1, cnt2, x, y;
bool check(long long v) {
long long n1, n2, n3, cn1 = cnt1, cn2 = cnt2;
n3 = v - v / x - v / y + v / (x * y);
n1 = v - v / x - n3;
n2 = v - v / y - n3;
cn1 -= min(cn1, n1);
cn2 -= min(cn2, n2);
return n3 >= cn1 + cn2;
}
int main() {
ios... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, a, b, c, d, ma, cnt, mi;
cnt = 0;
int ar[150];
int ans = 0;
memset(ar, 0, sizeof(ar));
scanf("%d %d %d", &a, &b, &c);
int a1 = a / 3;
int b1 = b / 2;
int c1 = c / 2;
int o = min(min(a1, b1), c1);
ans += 7 * o;
a = a - o * 3;
b =... | 6 |
#include <bits/stdc++.h>
using namespace std;
struct pr {
int val, nums;
} tp;
int cnt[3][1000005];
int num[3][3];
vector<pr> vec;
vector<long long> wtf;
long long temp, gg, mt, nowans;
long long ask(long long x, int y) {
long long now = 1;
while (y) {
if (y % 2) now *= x;
x *= x;
y /= 2;
}
return... | 21 |
#include <bits/stdc++.h>
using namespace std;
const long double EPS = 1e-9;
int n;
long double p, q, a, b;
vector<int> B(2), N;
vector<vector<long double>> D(4);
void Init() {
for (int i = 0; i < n; ++i) {
cin >> a >> b;
D[0][i] = -a;
D[1][i] = -b;
}
D[0][n] = D[1][n] = -1;
D[0][n + 1] = -p;
D[1][... | 16 |
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
const int N = 1e4;
char s[N + 3];
bool v[2][N + 3];
set<string> ans;
int main() {
ios_base::sync_with_stdio(false), cin.tie(0), cout << fixed;
cin >> s;
int n = strlen(s);
v[0][n] = v[1][n] = true;
for (int i = n - 2; i > 4; i--) {
... | 10 |
#include <bits/stdc++.h>
int n, a, b;
int f[44444][33];
bool g[44444][33];
int In() {
register int c, f, s;
for (; c = getchar(), c != '-' && !isdigit(c);)
;
for (s = (f = c == '-') ? 0 : c - '0'; c = getchar(), isdigit(c);)
s = s * 10 + c - '0';
return f ? -s : s;
}
bool ck(register int a, register int... | 12 |
#include <bits/stdc++.h>
using namespace std;
int lwb(vector<int>& a, int b) {
return int(lower_bound((a).begin(), (a).end(), b) - a.begin());
}
int upb(vector<int>& a, int b) {
return int(upper_bound((a).begin(), (a).end(), b) - a.begin());
}
long long updiv(long long a, long long b) {
return a / b + ((a ^ b) > ... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int nmax = 111111;
int main() {
int n = 0;
int a[nmax], p[nmax];
scanf("%d\n", &n);
for (int i = 0; i < n; i++) {
scanf("%d%d\n", &a[i], &p[i]);
}
int res = 0;
int price = 100000000;
for (int i = 0; i < n; i++) {
price = min(price, p[i]);
r... | 1 |
#include <bits/stdc++.h>
using namespace std;
string int_to_str(int a) {
string s;
char c;
if (a < 10) {
c = '0' + a;
s += c;
} else {
c = '0' + a / 10;
s += c;
c = '0' + a % 10;
s += c;
}
return s;
}
int main() {
int n;
cin >> n;
int l;
cin >> l;
int* a = new int[n];
int... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long power(long long n, long long p);
int main() {
long long n, bx, m, by, x = 0, x1, y = 0, y1;
cin >> n >> bx;
for (long long i = n - 1; i >= 0; i--) {
cin >> x1;
x = x + x1 * power(bx, i);
}
cin >> m >> by;
for (long long j = m - 1; j >= 0; j--) ... | 3 |
#include <bits/stdc++.h>
int main() {
int a, b, c, d;
scanf("%d%d%d%d", &a, &b, &c, &d);
double s, z;
s = 1.0 * a / b;
z = 1.0 * c / d;
double p = 1.0 * a / b;
double q = (1 - 1.0 * c / d) * (1 - 1.0 * a / b);
p = 1.0 * a / b;
q = (1 - 1.0 * c / d);
double a1 = p;
double r = (1 - p) * q;
printf(... | 5 |
#include <bits/stdc++.h>
using namespace std;
void er(char s) {
if (s == 's')
puts("Stannis");
else
puts("Daenerys");
exit(0);
}
int main() {
int n, k;
cin >> n >> k;
int a = 0, b = 0;
for (int i = 0; i < n; i++) {
int x;
scanf("%d", &x);
if (x % 2 == 0)
b++;
else
a++;
... | 14 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
void read(T &x) {
x = 0;
char c = getchar();
int f = 1;
while (c != '-' && (c < '0' || c > '9')) c = getchar();
if (c == '-') f = -1, c = getchar();
while (c >= '0' && c <= '9')
x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
x *= f;
... | 11 |
#include <bits/stdc++.h>
using namespace std;
const unsigned long long int N = 1e5 + 9;
vector<unsigned long long int> g[N], inic;
vector<pair<unsigned long long int, unsigned long long int> > rec;
unsigned long long int gcd(unsigned long long int a, unsigned long long int b) {
if (b == 0) return a;
return gcd(b, a... | 13 |
#include <bits/stdc++.h>
using namespace std;
vector<long long> v;
long long n, q, ans, dsum;
long long gcd(long long a, long long b) {
while (a && b) a > b ? a %= b : b %= a;
return a + b;
}
int main() {
ios_base::sync_with_stdio(0);
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> q;
v.push_back(q);
... | 8 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
const int oo = numeric_limits<int>::max() / 2;
mt19937 rnd(std::chrono::steady_clock::now().time_since_epoch().count());
ll count(const int n) {
ll m = (n + 1) / 2;
ll r1 = m * m;
m = n / 2;
ll r2 = m * (m + 1);
... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
struct data {
int nt, to, w;
} a[N << 1];
int head[N], pre[N], c[N], vis[N], d[N], dis[N], q[N];
int mx = 0, cnt = 0;
void add(int x, int y, int w) {
a[++cnt].to = y, a[cnt].w = w, a[cnt].nt = head[x], head[x] = cnt;
a[++cnt].to = x, a[cnt].w =... | 16 |
#include <bits/stdc++.h>
using namespace std;
vector<int> V[10];
int g(int x) {
if (x < 10) return x;
int ret = 1;
while (x) {
if (x % 10) ret *= x % 10;
x /= 10;
}
return g(ret);
}
int main() {
int q, l, r, k;
for (q = 1; q < 1000009; ++q) V[g(q)].push_back(q);
scanf("%d", &q);
while (q--)
... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long jc[100];
int main() {
long long i, j, n, m;
jc[1] = 2;
long long bz = 1000000000000000000ll;
int jz;
cin >> n >> m;
for (i = 2; 1; i++) {
jc[i] = jc[i - 1] * 2;
if (jc[i] > bz) {
jz = i;
break;
}
}
if (n == 0 && m == 0)
... | 9 |
#include <bits/stdc++.h>
using namespace std;
int a[1010], b[1010];
int n;
int ans[1010];
bool used[1010];
bool judge() {
memset(used, false, sizeof(used));
for (int i = 1; i <= n; ++i) {
int tmp = ans[i];
if (used[tmp]) return false;
used[tmp] = true;
}
return true;
}
int main() {
scanf("%d", &n)... | 5 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
ll x;
cin >> x;
ll sum = 0;
for (int i = 1; i <= x; i++) sum += pow(2, i);
cout << sum << endl;
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, k, i, sum = 0, ans = 0, t = 0, d, j, m, c = 1, x, y, p = 1;
cin >> n;
int a[n];
for (i = 1; i <= n; i++) {
cin >> a[i];
}
for (i = 1; i < n; i++) {
if (a[i] > a[i + 1]) {
p = i;
break;
}
}
for (i = 2; i <... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b;
scanf("%i%i", &a, &b);
if (a < b)
printf("-1");
else
printf("%.12lf", (a + b) / (2.0 * ((a + b) / (2 * b))));
}
| 9 |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e6 + 6;
const int MOD = 1e9 + 7;
string func(string str) {
if (str.size() <= 1) return str;
int zeroes = 0, ones = 0;
for (auto s : str) {
if (s == '0')
zeroes++;
else
ones++;
}
string result;
if (ones) result += '1';
for (... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int m;
cin >> m;
vector<int> v;
int s2 = 0;
int s5 = 0;
for (int i = 1;; i++) {
int x = i;
while (x % 2 == 0) {
s2++;
x /= 2;
}
while (x % 5 == 0) {
s5++;
x /= 5;
... | 5 |
#include <bits/stdc++.h>
using namespace std;
inline long long read() {
long long s = 0, w = 1;
char c;
while (c = getchar(), c > '9' || c < '0')
if (c == '-') w = -1;
while (c >= '0' && c <= '9') s = s * 10 + c - '0', c = getchar();
return s * w;
}
inline void write(long long x) {
if (x < 0) putchar('-... | 16 |
#include <bits/stdc++.h>
int main() {
long long int c = 0, n1, n2, i, mean;
scanf("%lli", &c);
for (i = 0; i < c; i++) {
scanf("%lli %lli", &n1, &n2);
if ((n1 * 2) <= n2) printf("%lli %lli\n", n1, n1 * 2);
}
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main(void) {
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
};
int n, i;
cin >> n;
string s;
cin >> s;
if (n & 1)
cout << ":(";
else {
int a = n / 2, b = n / 2, c = 0, bad = 0;
for (i = 0; i < n; i++) {
if (s[i] == '(') a--;... | 9 |
#include <bits/stdc++.h>
using namespace std;
inline int read() {
int w = 0, x = 0;
char c = getchar();
while (!isdigit(c)) w |= c == '-', c = getchar();
while (isdigit(c)) x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
return w ? -x : x;
}
namespace star {
const int maxn = 2e5 + 10;
inline void work() {
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int INF = 1000000005;
vector<int> sieveOfEratosthenes(int n) {
vector<int> v;
bool prime[n + 1];
memset(prime, true, sizeof(prime));
v.push_back(0);
v.push_back(0);
for (int i = 2; i < n + 1; i++) {
if (prime[i]) {
for (int j = i; j <= n; j += i) {
... | 8 |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 2e5+15;
const int mod = 1e9 + 7;
int add(int x,int y) {
return ((x+y)%mod+mod)%mod;
}
int mul(int x,int y) {
return (ll)x*y%mod;
}
int mypow(int x,int c) {
int ret = 1;
while(c>0) {
if(c&1) {
ret = mul(ret,x);
}
... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int MXN = 3e6 + 10;
long long m, r, c, x, MX = 3e6, A[MXN];
long double P[MXN];
long long Solve(long long n) {
long long t = (long long)(x - P[n - 1] +
(((long double)n) * n * (n - 1) / 2)),
k = (n * n + n) / 2;
if (t % k !=... | 11 |
#include <bits/stdc++.h>
using namespace std;
int MOD;
inline int ADD(int a, int b) {
a += b;
if (a >= MOD) a -= MOD;
return (int)a;
}
inline void ADDTO(int &a, int b) {
a += b;
if (a >= MOD) a -= MOD;
}
inline void SUBTO(int &a, int b) {
a -= b;
if (a < 0) a += MOD;
}
inline int MUL(int a, int b) { retur... | 12 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
bool typetest;
inline void fastIOfileinput() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
typetest = 0;
}
const int N = 5e5 + 1;
int n;
ll k, p;
ll a[N];
void Read() {
cin >> n >>... | 15 |
#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
while (a && b) a > b ? a %= b : b %= a;
return a + b;
}
long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); }
long long fast_exp(long long base, long long exp) {
long long res = 1;
while (exp > 0) {
if (exp % 2 == 1)
... | 6 |
#include <bits/stdc++.h>
using namespace std;
long long bit[100005];
int n;
void update(long long i, long long a) {
while (i <= n) {
bit[i] = max(bit[i], a);
i += i & -i;
}
}
long long read(long long i) {
long long r = 0;
while (i > 0) {
r = max(bit[i], r);
i -= i & -i;
}
return r;
}
int mai... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n, q, f = 0, s = 1, t, c = 0, x;
cin >> n >> q;
while (q--) {
cin >> t;
if (t == 1) {
cin >> x;
f += x;
s += x;
f %= n;
s %= n;
f += n;
... | 10 |
#include <bits/stdc++.h>
#define ll long long
#define endl "\n"
#define pb push_back
#define mp make_pair
#define ms(v,x) memset(v,x,sizeof(v))
#define td(v) v.begin(),v.end()
#define rtd(v) v.rbegin(),v.rend()
#define ff first
#define ss second
using namespace std;
std::mt19937 rng((int) std::chrono::steady_clock::no... | 9 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.