solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
long long binpow(long long a, long long b, long long mod) {
long long res = 1;
while (b > 0) {
if (b & 1) res = res * a % mod;
a = a * a % mod;
b >>= 1;
}
return res % mod;
}
const int dx[] = {1, -1, 0, 0};
const int dy[] =... | 7 |
#include <bits/stdc++.h>
using namespace std;
int fa[250005], n;
struct hh {
vector<int> d[250005];
int fa[20][250005], dep[250005], deg[250005], sk[250005], mk[250005], l, r;
void dfs(int x, int f) {
dep[x] = dep[f] + 1;
fa[0][x] = f;
for (int i = 0; i < (int)d[x].size(); ++i) {
int v = d[x][i]... | 24 |
#include <bits/stdc++.h>
struct Frog {
int p, a, n;
bool operator<(const Frog &o) const { return p < o.p; }
};
const int N = 1e5;
int n, m, inv[N], next[N], prev[N], when[N];
bool gg[N];
Frog a[N];
long long add[N];
std::set<std::pair<int, int> > event;
template <class T1, class T2>
inline bool cmin(T1 &a, const T2... | 20 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
vector<bool> prime(1e6 + 5, true);
void SieveOfEratosthenes(long long int n) {
prime[0] = false;
prime[1] = false;
for (long long unsigned int p = 2; p * p <= n; p++) {
if (prime[p] == true) {
for (long long unsigned int i = p * p; i... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c, d, e, f;
cin >> a >> b >> c >> d;
e = max(3 * a / 10, a - (a * c / 250));
f = max(3 * b / 10, b - (b * d / 250));
if (e > f)
cout << "Misha";
else {
if (e < f)
cout << "Vasya";
else
cout << "Tie";
}
return 0;... | 1 |
#include <bits/stdc++.h>
using namespace std;
int maxn = 1e6;
vector<int> a(maxn), b(maxn);
int f(int i, int val) { return min(b[i] - a[i] + val, b[i]); }
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t = 1;
cin >> t;
for (; t; t--) {
int n;
cin >> n;
for (int i = 0... | 16 |
#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
long long rand(long long l, long long r) {
uniform_int_distribution<long long> uid(l, r);
return uid(rng);
}
const int mod = 1e9 + 7;
const int mod1 = 998244353;
const int B = 37;
int pwr(int a, long l... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int N = 500010;
int p[N];
inline int find_set(int x) {
if (x != p[x]) {
p[x] = find_set(p[x]);
}
return p[x];
}
vector<pair<int, int> > edges[N];
inline void unite(int x, int y) {
x = find_set(x);
y = find_set(y);
assert(x != y);
if (x == y) {
re... | 24 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int n = s.size();
vector<long long> part_sums(n, 0);
for (int i = 0; i < n; i++) {
if (s[i] == 'A' || s[i] == 'E' || s[i] == 'I' || s[i] == 'O' ||
s[i] == 'U' || s[i] == 'Y') {
part_sums[i]++;
}
if (i - 1 ... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
while (n--) {
string a = "", b = "";
cin >> b;
a += b[0];
for (int i = 1; i < b.length() - 1; i++) {
if (b[i] == b[i + 1]) {
a += b[i];
i++;
} else {
a += b[i];
a += b[i + 1];
... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long int n, k;
long long int dp[105][105];
int main() {
cin >> n >> k;
string str;
cin >> str;
memset(dp, 0, sizeof(dp));
vector<int> pos(30, -1);
for (int i = 0; i <= n; i++) dp[i][0] = 1;
for (int i = 1; i <= n; i++) {
for (int len = 1; len <= i; le... | 12 |
#include <bits/stdc++.h>
const int N_MAX = 200003;
int len, g[7][7], lim[7], now[7], res[7], vis[7];
inline bool Hall() {
for (int S = 1; S + 1 < 1 << len; ++S) {
int L = 0, R = 0;
for (int i = 1; i <= len; ++i)
if (S >> (i - 1) & 1) L += res[i];
for (int i = 1; i <= len; ++i)
for (int j = i; ... | 24 |
#include <bits/stdc++.h>
using namespace std;
const int MAXM = 1e5 + 10, MOD = 1e9 + 7;
int add(int x, int y) { return (x + y) % MOD; }
void addeq(int &x, int y) { x = add(x, y); }
int subtr(int x, int y) {
x -= y;
return x < 0 ? x + MOD : x;
}
struct fenwick {
int bit[MAXM];
void update(int x, int v) {
for... | 9 |
#include <bits/stdc++.h>
using namespace std;
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 * 10 + ch - '0';
ch = getchar();
}
return x * f;
}
int a[5];
int ans;
int main() ... | 10 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
T max(T a, T b, T c) {
return max(a, max(b, c));
}
template <class T>
T min(T a, T b, T c) {
return min(a, min(b, c));
}
void fastio() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}
bool prime[100005];
void SieveOfEratosthenes(long long int ... | 5 |
#include <bits/stdc++.h>
using namespace std;
long n, k;
double prob[10][1000 + 100];
double ans;
double ev[10][1000 + 100];
double pup, prem;
double rev[100000];
int main() {
ios_base::sync_with_stdio(0);
cin >> n >> k;
double gz = 1.0 / k;
for (int i = 1; i <= 1000 + 1000; i++) rev[i] = 1.0 / i;
prob[0][1] ... | 19 |
#include <bits/stdc++.h>
using namespace std;
int xi[410], yi[410];
int f[810][810];
double co[810][810];
vector<int> ed[810];
inline void adde(int x, int y, int ca, double cost) {
f[x][y] = ca;
f[y][x] = 0;
co[x][y] = cost;
co[y][x] = -cost;
ed[x].push_back(y);
ed[y].push_back(x);
}
inline double sq(double... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int i, j, n, y, ass, bss;
string a, b, c(256, 0);
cin >> a;
for (char i : a) c[i] = 1;
cin >> a >> n;
ass = a.size();
while (n--) {
y = 1;
cin >> b;
bss = b.size();
for (i = j = 0; y && i < ass; i++) {
if (a[i] == '*') {
... | 8 |
#include <bits/stdc++.h>
using namespace std;
int dx[] = {0, 0, 1, -1, -1, -1, 1, 1};
int dy[] = {1, -1, 0, 0, -1, 1, 1, -1};
template <class T>
inline T biton(T n, T pos) {
return n | ((T)1 << pos);
}
template <class T>
inline T bitoff(T n, T pos) {
return n & ~((T)1 << pos);
}
template <class T>
inline T ison(T n... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, maxm = 0;
string f2 = "";
cin >> a >> b;
char arr[a][b];
for (int t = 0; t < a; t++) {
for (int p = 0; p < b; p++) {
cin >> arr[t][p];
}
}
for (int t = 0; t < a - 1; t++) {
for (int p = 0; p < b - 1; p++) {
f2 = "... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long lcm(long long a, long long b) { return a * (b / gcd(a, b)); }
long long power(long long x, long long y, long long p) {
long long res = 1;
x = x % p;
while (y > 0) {
if (y & 1)... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 500004;
const int MOD = 1000003;
char *dd[MAXN];
int a1[MAXN], b1[MAXN];
int n, m;
void solve() {
long long ret = 1;
int cnt = 0;
for (int i = 0; i < n; i++) {
dd[i] = new char[m + 1];
scanf("%s", dd[i]);
}
memset(a1, -1, sizeof(a1));
me... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5e5 + 5;
const int MAXA = 2e6 + 3;
const long long int INF = 1000000000000000;
int n, xy;
long long int ans, x, y, cnt[MAXA], sum[MAXA];
long long int C(int i, int j) {
if (i > j) return 0;
return cnt[j] - cnt[i - 1];
}
long long int S(int i, int j) {
... | 13 |
#include <bits/stdc++.h>
using namespace std;
int n, res, t;
int main() {
res = 240;
scanf("%d%d", &n, &t);
res -= t;
for (int i = 1; i <= n; i++) {
if (res >= 5 * i) {
res -= 5 * i;
} else {
return printf("%d\n", i - 1), 0;
}
}
printf("%d\n", n);
return 0;
}
| 0 |
#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
signed main() {
vector<bool> used(10, false);
long long int n;
cin >> n;
string s;
cin >> s;
for (auto c : s) ... | 0 |
#include <bits/stdc++.h>
using namespace std;
int n;
double p, q;
double a[100001], b[100001];
double f(double x) {
double y = 1.0;
for (int i = 0; i < n; i++)
y = y > (1.0 - b[i] * x) / a[i] ? (1.0 - b[i] * x) / a[i] : y;
return p * y + q * x;
}
int main() {
cin >> n >> p >> q;
for (int i = 0; i < n; i++... | 16 |
#include <bits/stdc++.h>
int n, a[100000];
int main() {
int n = 0;
while (scanf("%d,", &a[n]) == 1) n++;
std::sort(a, a + n);
int i = 0, l, r;
while (i < n) {
l = a[i];
i++;
while (i < n && (a[i] == a[i - 1] || a[i] == a[i - 1] + 1)) i++;
if (a[i - 1] != l)
printf("%d-%d", l, a[i - 1]);
... | 5 |
#include <bits/stdc++.h>
using namespace std;
long n, a[20000], b[20000], c[20000];
long long arp[20000], dsum[20000], upsum[20000], subsize[20000];
vector<pair<long, long> > g[7000];
long csize;
long long ans, minsum, minsum1;
long long tans;
long tresize;
void dfs1(long v) {
arp[v] = 1;
subsize[v] = 1;
for (int... | 15 |
#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
std::pair<T, U> operator+(const std::pair<T, U>& l, const std::pair<T, U>& r) {
return {l.first + r.first, l.second + r.second};
}
const long long INF64 = 1e18;
const long long INF32 = 1e9;
const long long U = 2e5;
long long n, first, las... | 18 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
using min_queue = priority_queue<T, vector<T>, greater<T>>;
template <typename... Args>
void read(Args&... args) {
((cin >> args), ...);
}
template <typename... Args>
void print(Args... args) {
((cout << args << " "), ...);
}
template <typename... Arg... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
int arr[n], c = 0;
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
for (int i = 0; i < n; i++) {
if (arr[i] <= (5 - k)) c++;
}
cout << c / 3;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int n, a[2000], mx, k = 1, r = 1;
int main() {
cin >> n;
for (int i = 0; i < n; i++) cin >> a[i];
sort(a, a + n);
for (int i = 0; i < n - 1; i++)
if (a[i] == a[i + 1])
k++;
else {
mx = max(mx, k);
k = 1;
r++;
}
mx = max(mx, k);
... | 2 |
#include <bits/stdc++.h>
int main() {
long long t, n;
int i, j;
scanf("%I64d", &t);
for (i = 0; i < t; i++) {
scanf("%I64d", &n);
j = 1;
while (j <= n) j = j * 2;
printf("%I64d", n * (n + 1) / 2 - 2 * (j - 1));
printf("\n");
}
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
bool comp(int a, int b) { return a > b; }
int main() {
int n;
cin >> n;
int a[n];
for (int i = 0; i < n; ++i) cin >> a[i];
sort(a, a + n, comp);
vector<unsigned long long int> res;
for (int i = 0; i < n - 1; ++i) {
if (a[i] - a[i + 1] <= 1) {
res.pus... | 8 |
#include <bits/stdc++.h>
using namespace std;
int aux[15], a[15], a2[15], aux2[15];
int getNueve() {
int nueves = 0;
for (int i = 0; i < 10; ++i) nueves += min(aux[i], aux2[9 - i]);
return nueves;
}
int main() {
char s[100005];
int l;
scanf("%s", &s);
l = strlen(s);
memset(a, 0, sizeof(a));
memset(a2,... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int a, b, c;
cin >> a >> b >> c;
if (a + b == c || b + c == a || a + c == b || (a == b && c % 2 == 0) ||
(c == b && a % 2 == 0) || (a == c && b % 2 == 0)) {
cout << "YES\n";
} else {
cout ... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 30;
const int MAXN = 100010;
int n, m;
pair<pair<int, int>, int> a[MAXN], b[MAXN];
long long f[MAXN][4];
pair<int, int> g[MAXN][4];
int ansN;
pair<int, int> ans[MAXN];
int main() {
cin >> n;
for (int i = 0; i < n; i++)
cin >> a[i].first.second >... | 17 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, arr[100009], cum1[100009], cum2[100009];
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> arr[i];
}
for (int i = 1; i <= n; ++i) {
cum1[i] = arr[i] + cum1[i - 1];
}
sort(arr, arr + n + 1);
for (int i = 1; i <= n; ++i) {
c... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, a[100000], b[100000], e[100000], f[100000], d[100000], m;
set<int> v;
set<int>::iterator it;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
for (int i = 0; i < n; i++) {
scanf("%d", &b[i]);
}
d[0] = a[0] - ... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int N = 60;
char a[N][2];
int f[N][10];
int n;
map<vector<string>, int> ap;
bool done(int kil) {
if (1 == kil) return true;
if (kil - 2 >= 0) {
if (a[kil - 2][0] == a[kil - 1][0] || a[kil - 2][1] == a[kil - 1][1]) {
char c1 = a[kil - 2][0];
char c2... | 11 |
#include <bits/stdc++.h>
using namespace std;
int n, m, x, y, ans;
vector<int> d[100010];
int main() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= m; i++) {
scanf("%d%d", &x, &y);
d[x].push_back(y), d[y].push_back(x);
}
for (int i = 1; i <= n; i++)
if ((d[i].size()) & 1) ans++;
ans >>= 1;
for (i... | 19 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s, d;
cin >> s >> d;
string ans = "";
bool flag = true;
for (int i = 0; i < s.length(); i++) {
if (d[i] > s[i]) {
flag = false;
break;
} else if (d[i] == s[i]) {
if (s[i] != 'z')
ans.push_back(s[i] + 1);
... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long dp[4040][4040];
char t[4040][4040];
char c[2020][2020];
long long f(long long x, long long y) {
long long &r = dp[x][y];
if (r >= 0) return r;
if (t[x][y] == '.') {
return r = 0;
}
if (x == 0 || y == 0) {
return r = 1;
}
if (t[x - 1][y - 1] !... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int dim = 50;
bool cmp(const string &a, const string &b) {
auto x = a + b, y = b + a;
return x < y;
}
int main() {
int n;
cin >> n;
vector<string> s(n);
for (int i = 0; i < n; ++i) {
cin >> s[i];
}
sort(s.begin(), s.end(), cmp);
for (int i = 0; i... | 9 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
T gcd(T a, T b) {
if (a == 0) return b;
return gcd(b % a, a);
}
template <typename T>
T pow(T a, T b, long long m) {
T ans = 1;
while (b > 0) {
if (b % 2 == 1) ans = (ans * a) % m;
b /= 2;
a = (a * a) % m;
}
return ans % m;
}
lo... | 16 |
#include <bits/stdc++.h>
using namespace std;
const long long UNDEF = -1;
const long long INF = 1e18;
template <typename T>
inline bool chkmax(T& aa, T bb) {
return aa < bb ? aa = bb, true : false;
}
template <typename T>
inline bool chkmin(T& aa, T bb) {
return aa > bb ? aa = bb, true : false;
}
static char stdinB... | 18 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s1, s2, s3;
cin >> s1 >> s2 >> s3;
string s4 = s1 + s2;
sort(s4.begin(), s4.end());
sort(s3.begin(), s3.end());
if (s4 == s3) {
cout << "YES";
} else {
cout << "NO";
}
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int w, h;
cin >> w >> h;
long long ans = 0;
for (int i = 1; i <= h / 2; ++i) {
for (int j = 1; j <= w / 2; ++j) {
ans += (h - 2 * i + 1) * (w - 2 * j + 1);
}
}
cout << ans << endl;
return 0;
}
| 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, j;
scanf("%d", &n);
int i;
int a[n];
for (i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
sort(a, a + n);
scanf("%d", &m);
int b[m];
for (j = 0; j < m; j++) {
scanf("%d", &b[j]);
}
sort(b, b + m);
printf("%d %d", a[n - 1],... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int cnt = 0, cn = 0;
char a[100010];
char b[100010];
scanf("%s", a);
scanf("%s", b);
int len = strlen(a);
for (int i = 0; i < len; ++i) {
if (a[i] != b[i]) {
if (a[i] == '4')
++cnt;
else
++cn;
}
}
printf("%d... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 3e4 + 100;
const int K = 205;
const int INF = 0x3f3f3f3f;
const int kof[4] = {-2, 0, 0, 2};
int dp[N][K][4], dp2[N][K][4], a[N], n, k;
int dinamika() {
int sm = 0;
dp[0][1][0] = -a[0];
dp[0][1][1] = -a[0];
dp[0][1][2] = a[0];
dp[0][1][3] = a[0];
dp... | 19 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios ::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
int t;
cin >> t;
while (t--) {
long long n, k;
cin >> n >> k;
if (n <= k) {
cout << "1\n";
continue;
}
set<int, greater<int>> left;
set<int, greater<int>> r... | 5 |
#include <bits/stdc++.h>
using namespace std;
int t, n, x, y, p, q;
int main() {
cin >> t;
while (t--) {
cin >> x >> y >> p >> q;
if (p == 0) {
cout << (x == 0 ? 0 : -1) << endl;
continue;
}
if (p == q) {
cout << (x == y ? 0 : -1) << "\n";
continue;
}
int t1 = (x + p ... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, x, ans = 0, curr = 0, i, a, b;
cin >> n >> x;
for (i = 0; i < n && cin >> a >> b; curr = b, i++)
ans += (a - curr) % x + (b - a) + (int)((a - curr) % x == 0) * x;
cout << ans << "\n";
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
int F() {
char ch;
int x, a;
while (ch = getchar(), (ch < '0' || ch > '9') && ch != '-')
;
if (ch == '-')
ch = getchar(), a = -1;
else
a = 1;
x = ch - '0';
while (ch = getchar(), ch >= '0' && ch <= '9')
x = (x << 1) + (x << 3) + ch - '0';
ret... | 13 |
#include <bits/stdc++.h>
using namespace std;
int arr[11111];
int out[11111];
int temp[11111];
int main() {
int n, k;
scanf("%d %d", &n, &k);
for (int i = (1); i < (n); ++i) arr[i] = 1;
arr[n] = 0;
int qtd = 0;
int ct = 5;
while (arr[1] != n - 1) {
memcpy(temp, arr, sizeof arr);
out[qtd++] = n;
... | 8 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimization("unroll-loops")
const int N = 2e5 + 5;
const long long int mod = 1e9 + 7;
const long long int Mod = 998244353;
const long double Pi = acos(-1);
const long long int Inf = 4e18;
using namespace std;
void TestCase() {
int n, k, pos = n + 1;
... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, k, A[100], i, j;
cin >> n >> k;
for (i = 0; i < n; i++) {
cin >> A[i];
}
sort(A, A + n);
cout << A[n - k];
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
const int mx = 1e5 + 5;
unordered_map<int, int> mp;
int block, ans[mx], n, m;
struct query {
int l, r, id;
};
bool comp(query x, query y) {
if (x.l / block != y.l / block) return x.l / block < y.l / block;
return x.r < y.r;
}
void find_ans(int a[], query q[]) {
bloc... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int zero = 201, maxn = 507, maxnum = 100000000;
int x, y, n, d;
int dx[maxn], dy[maxn];
int sg[maxn][maxn];
int dis(int x, int y) {
return (x - zero) * (x - zero) + (y - zero) * (y - zero);
}
int SG(int x, int y) {
if (dis(x, y) > d) return 1;
if (sg[x][y] != -1... | 11 |
#include <bits/stdc++.h>
using namespace std;
long long int n, k;
int main() {
cin >> n >> k;
cout << min(1LL, min(n - k, k)) << " " << min(n - k, k * 2) << "\n";
return 0;
}
| 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> v;
int c, sumb = 0, sumc = 0;
for (int i = 0; i < n; i++) {
int a;
cin >> a;
v.push_back(a);
}
sort(v.begin(), v.end());
for (int i = 0; i < v.size(); ++i) {
if (v[i] <= 0)
sumc += v[i];
els... | 0 |
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-6;
const int mod = 1e9 + 7;
const int maxn = 2e5 + 100;
const long long INF = 0x3f3f3f3f3f3f3f3f;
const int maxm = 2e6 + 100;
const int inf = 0x3f3f3f3f;
const double pi = acos(-1.0);
long long ans;
int cnt[maxn], tnc[maxn];
struct node {
int trie[ma... | 16 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const long long INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
long long powmod(long long a, long long b) {
long long res = 1;
a %= mod;
for (; b > 0; b >>= 1) {
if (b & 1) res = res * a % mod;
a = a * a % mod;
}
re... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long cal(long long x) {
long long sum = 0;
while (x) {
sum += x % 10;
x /= 10;
}
return sum;
}
long long pre[100];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
long long n;
cin >> n;
pre[1] = 9;
for (long long i = 2; i <= 15; ++i) {
... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long fact[2000010], inv[2000010];
void init() {
long long n = 2000010 - 5;
fact[0] = 1;
for (long long i = 1; i <= n; ++i) {
fact[i] = i * fact[i - 1] % 1000000007;
}
inv[1] = 1;
for (long long i = 2; i <= n; ++i) {
inv[i] = 1000000007 - (1000000007... | 22 |
#include <bits/stdc++.h>
using namespace std;
const long long int INF = 1e18;
const int inf = 1e9;
const int MOD = 1e9 + 7;
const int nax = 1000000 + 10;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
int ans = 1;
cin >> n;
for (int k = 2; k < 33; k++) {
int a = pow(2, k);
a--;
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int n, x, y;
char s[666666];
int main() {
scanf("%d%d%d%s", &n, &x, &y, s + 1);
int b = 0;
long long ans = 8e18;
for (int i = 1; i <= n; ++i)
if (s[i] == '0' && s[i - 1] != '0') ++b;
if (!b) ans = 0;
for (int i = 0; i < b; ++i)
ans = min(ans, y * (long l... | 7 |
#include <bits/stdc++.h>
using namespace std;
long long mult(long long a, long long b, long long p = 1000000007) {
return ((a % p) * (b % p)) % p;
}
long long add(long long a, long long b, long long p = 1000000007) {
return (a % p + b % p) % p;
}
long long fpow(long long n, long long k, long long p = 1000000007) {
... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 1 << 30;
const int N = 100100;
int n, a[N], k, l;
int main() {
scanf("%d %d %d", &n, &k, &l);
for (int i = 1; i <= n * k; i++) scanf("%d", a + i);
int nn = n * k;
sort(a + 1, a + 1 + nn);
int idx = 1;
while (idx <= nn) {
if (a[idx] - a[1] <= ... | 7 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:300000000")
#pragma warning(disable : 4800)
using namespace std;
void showTime() { cerr << (double)clock() / CLOCKS_PER_SEC << endl; }
const double pi = 3.1415926535897932384626433832795;
template <class T>
T abs(const T &a) {
return a >= 0 ? a : -a;
};
templat... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, l, r;
scanf("%lld", &n);
scanf("%lld", &l);
scanf("%lld", &r);
long long i, j, k = 1, li;
if (l == 1) li = k;
for (i = 2; i <= r; i++) {
k = k * 2;
if (i == l) li = k;
}
long long mini = 0, maxi = 0, ri = 1;
for (i = 0; ... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long n, m, k;
long long read() {
long long s = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
s = s * 10 + ch - '0';
ch = getchar();
}
return s * f;
}... | 15 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 1e6 + 5;
long long max(long long a, long long b) {
if (a >= b)
return a;
else
return b;
}
long long min(long long a, long long b) {
if (a >= b)
return b;
else
return a;
}
long long diff(long long a, long long b) {
if (a >= b)
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> k;
vector<vector<int> > neighbours;
long long f(int v, int parent) {
vector<long long> subtrees;
for (vector<int>::const_iterator u = neighbours[v].begin();
u != neighbours[v].end(); u++) {
if (k[*u] > 0 && *u != parent) {
k[*u]--;
... | 13 |
#include <bits/stdc++.h>
using namespace std;
int arr[1004];
int n, k, p, x, y, tot, c;
void Readinput() {
tot = 0;
c = 0;
int i = 0;
scanf("%d", &n);
scanf("%d", &k);
scanf("%d", &p);
scanf("%d", &x);
scanf("%d", &y);
for (i = 0; i < k; i++) {
scanf("%d", &arr[i]);
tot += arr[i];
if (arr[... | 9 |
#include <bits/stdc++.h>
using namespace std;
inline void pisz(int n) { printf("%d\n", n); }
const int POWERS_MAX = 19;
long long p10[POWERS_MAX];
void compute_powers() {
p10[0] = 1;
for (int(i) = (1); (i) <= (POWERS_MAX - 1); ++i) {
p10[i] = 10 * p10[i - 1];
}
}
int len(long long n) {
if (n == 0) return 1;... | 7 |
#include <bits/stdc++.h>
using namespace std;
int black[3000][3000];
int main() {
int n, m, k;
scanf("%d%d%d", &n, &m, &k);
int T;
for (int i = 1; i <= k; i++) {
int a, b;
scanf("%d%d", &a, &b);
if (!black[a][b]) {
black[a][b] = i;
}
}
bool flag = 0;
T = 1000000;
for (int i = 1; i ... | 3 |
#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> nei[5005];
int dp[5005], masize[5005], oth[5005], size[5005];
bitset<5005> C, tmp;
void dfs(int v, int pa) {
size[v] = 1;
vector<int> al;
for (int i = 0; i < nei[v].size(); i++) {
int u = nei[v][i];
if (u == pa) continue;
dfs(u, v);
... | 7 |
#include <bits/stdc++.h>
int n, k;
int xc, yc;
int tot[111];
short int sum[111][111];
int abs(int a) { return a > 0 ? a : -a; }
void solve(int m) {
if (m > k) {
puts("-1");
return;
}
int mn = 1000000000, x, yl, yr;
for (int i = 1; i <= k; i++) {
for (int j = 1; j <= k - m + 1; j++)
if (sum[i][... | 7 |
#include <bits/stdc++.h>
int main() {
long long m, p, b, ans = 0;
std::cin >> m >> b >> p;
p *= m;
while (m > 1) {
long long k = 1 << 30;
while (k > m) k >>= 1;
long long d = m - k;
ans += k * b + (k >> 1);
m = d + (k >> 1);
}
std::cout << ans << ' ' << p << std::endl;
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 3010, mod = 1e9 + 7;
const long long inf = 1e18;
vector<int> v[maxn];
pair<int, int> fr[2][3][maxn];
int h[maxn];
queue<int> q;
pair<int, pair<pair<int, int>, pair<int, int> > > ans;
void Push(int a, int b, pair<int, int> p) {
if (fr[a][0][b] < p)
fr[... | 12 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
struct point {
long long x, y;
point() {}
point(int x, int y) : x(x), y(y) {}
};
point a[510];
point b[510];
int c[510][510];
point operator-(point &xx, point &yy) {
return point(xx.x - yy.x, xx.y - yy.y);
}
long long vect(point xx, point yy) { return xx.x... | 18 |
#include <bits/stdc++.h>
int main() {
int n, h;
int width = 0;
std::cin >> n >> h;
int* a = new int[n];
for (int i = 0; i < n; i++) std::cin >> a[i];
for (int i = 0; i < n; i++) {
width++;
if (a[i] > h) width++;
}
std::cout << width;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 1e5 + 10;
const long long INF = 1e18;
const long long MOD = 1e9 + 7;
long long se[26][26][26], du[26][26], q[MAXN];
string v[MAXN], dp[MAXN];
int main() {
string s;
cin >> s;
long long k = 0;
q[s.size()] = 2;
for (int i = s.size() - 2; i >= ... | 10 |
#include <bits/stdc++.h>
using namespace std;
int c[100005][6][6];
const int modo = 1000000007;
int sum[100005][6];
int val[1 << 18][6];
int a[100005];
int tag[1 << 18];
void updates(int num, int l, int mid, int r) {
register int i;
for (i = 0; i <= 5; i++) {
val[num][i] = val[num * 2 + 1][i];
int j;
fo... | 17 |
#include <bits/stdc++.h>
const int MAXN = 1e5 + 5;
int n;
long long a[MAXN];
std::vector<std::pair<int, long long> > G[MAXN];
bool vis[MAXN];
inline void add(int u, int v, long long w) {
G[u].push_back(std::make_pair(v, w));
G[v].push_back(std::make_pair(u, w));
}
inline void dfs(int v, int fa, long long sum) {
v... | 8 |
#include <bits/stdc++.h>
using namespace std;
constexpr long long INF = 1999999999999999997;
int main() {
ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
string s;
cin >> s;
vector<int> v;
int mn = 28;
for (int i = 0; i... | 6 |
#include <bits/stdc++.h>
using namespace std;
const long long inf = 0x3f3f3f3f;
const long long MAXN = 1e6 + 10;
const long long mod = 1e9 + 7;
signed main() {
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
long long t;
cin >> t;
while (t--) {
long long n, x;
long long maxx = -1;
cin >> n >... | 5 |
#include <bits/stdc++.h>
const int maxn = 1000005;
long long n, m, cnt[maxn], a, b, res;
int main() {
scanf("%lld%lld", &n, &m);
for (int i = 0; i < m; ++i) {
scanf("%lld%lld", &a, &b);
++cnt[a];
++cnt[b];
}
if (n <= 2)
puts("0");
else {
for (int i = 1; i <= n; ++i) res += cnt[i] * (n - 1 ... | 11 |
#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:10240000000,10240000000")
char ch;
int bo;
inline bool blank(char ch) {
return ch == ' ' || ch == '\n' || ch == '\r' || ch == '\t';
}
inline void rd(int &x) {
x = bo = 0;
for (ch = getchar(); ch < '0' || ch > '9'; ch = getchar())
if... | 7 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
bool dbg = 0;
clock_t start_time = clock();
void bad(string mes = "Impossible") {
cout << mes;
exit(0);
}
void bad(int mes) {
cout << mes;
exit(0);
}
template <typename T>
string bin(T x, int st = 2) {
string ans = "";
while (x > 0)... | 15 |
#include <bits/stdc++.h>
using namespace std;
bool visi[100001];
int main() {
int n, k;
cin >> n >> k;
int a = 1, b = n;
bool change = false;
for (int i = 0; i < k; i++)
if (!change) {
change = true;
visi[a] = true;
cout << a << " ";
a++;
} else {
change = false;
vi... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 9, P = 1e9 + 7;
int n, f[N], x[N], y[N], h[N], t, er[N], size[N], ans = 1;
bool s[N];
int find(int x) {
while (x != f[x]) x = f[x] = f[f[x]];
return x;
}
int main() {
scanf("%d", &n);
er[0] = 1;
for (int i = 1; i <= (n << 1); ++i) er[i] = er[i ... | 15 |
#include <bits/stdc++.h>
using namespace std;
vector<int> mp[150000];
int vis[150000];
int dp[150000];
int fa[150000];
int Id[150000];
int F[150000];
int n, m, d;
void Dfs(int u, int from) {
if (vis[u] == 1) dp[u] = 0;
int maxn = -0x3f3f3f3f;
for (int i = 0; i < mp[u].size(); i++) {
int v = mp[u][i];
if (... | 12 |
#include <bits/stdc++.h>
using namespace std;
inline long long max_(long long a, long long b) { return (a > b) ? a : b; }
inline long long min_(long long a, long long b) { return (a < b) ? a : b; }
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
if (fopen("inp.txt", "r")) {
freopen("inp.txt", "r", st... | 4 |
#include <bits/stdc++.h>
using namespace std;
void data() {}
const long long N = 2e5 + 200, mod = 1e9 + 7;
int n, x, timer;
vector<int> leaf, g[N];
int up[N][25], tin[N], tout[N], dp[N], dp2[N];
void dfs(int v, int p) {
tin[v] = ++timer;
up[v][0] = p;
for (int i = 1; i <= 20; i++) {
up[v][i] = up[up[v][i - 1]... | 9 |
#include <bits/stdc++.h>
using namespace std;
int n;
int g[10001];
inline void fail() {
printf("No solution\n");
exit(0);
}
inline int change(int a, int b) {
int res = 0;
for (int i = 0; i < 4; ++i) {
res += (a % 10 != b % 10);
a /= 10, b /= 10;
}
return res;
}
int main() {
scanf("%d", &n);
g[0]... | 9 |
#include <bits/stdc++.h>
using namespace std;
char z[1000005];
long long k, len, ind;
vector<long long> vis, c;
string str;
void pf(long long, long long);
string lcs2(string, string, long long, long long);
long long bfs(vector<long long>[], long long, long long);
void solve() {
long long n, i, j, x, y1, y, l = 1, b, ... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int w = 0;
string s1, s2;
map<char, char> m;
cin >> s1 >> s2;
for (int i = 0; i < s1.size(); i++) {
if (m[s1[i]] != s2[i] && m[s1[i]] != 0) {
cout << -1 << endl;
return 0;
}
if (m[s2[i]] != s1[i] && m[s2[i]] != 0) {
cout ... | 7 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.