solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
string s;
int main() {
cin >> s;
int n = s.size(), p = 0;
for (int i = n - 1; i >= 0; i--) {
if (s[i] == '0')
p++;
else {
if (p)
p--;
else
s[i] = '0';
}
}
cout << s;
return 0;
}
| 12 |
#include <bits/stdc++.h>
using namespace std;
vector<int> G[100008];
int a[100008];
int main() {
int m, n, tmp, t1, t2;
scanf("%d%d", &n, &m);
for (int i = 0; i < (m); i++) {
scanf("%d%d", &t1, &t2);
G[t1].push_back(t2);
G[t2].push_back(t1);
}
for (int i = 1; i <= n; i++) a[i] = i;
bool flag = f... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[]) {
int a, b, c, l = 1, m = 1, n = 1;
cin >> a >> b >> c;
cout << 4 * (sqrt(a * b / c) + sqrt(b * c / a) + sqrt(a * c / b)) << endl;
return 0;
}
| 3 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
using namespace std;
struct point {
int x, w, sum;
};
bool cmp(struct point a, struct point b) { return a.sum < b.sum; }
void TestCase() {
int n;
cin >> n;
vector<struct point> v(n)... | 10 |
#include <bits/stdc++.h>
using namespace std;
int dp[1000000], arr[1000000], arr2[300], n, t, maxn = 1, mx = 1;
int main() {
cin >> n;
cin >> t;
for (int i = 0; i < n; ++i) {
cin >> arr[i];
arr2[arr[i]]++;
mx = max(mx, arr2[arr[i]]);
dp[i] = 1;
}
int k = min(n, t);
for (int i = n; i < n * k;... | 11 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("tune=native")
#pragma GCC optimize("fast-math")
using namespace std;
const int DEBUG = 0;
mt19937 gen(
(unsigned)chrono::high_resolution_clock::now().time_since_epoch().count());
#pragma comment(linker, "/STACK:16777216")
struct mhash {
unsig... | 17 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
void pv(T &c) {
for (typename T::iterator i = c.begin(); i != c.end(); i++) cout << *i << " ";
cout << "\n";
}
int ar[30];
int cpy[30];
int main() {
int i, l, n;
string s;
cin >> s;
cin >> n;
l = s.length();
for ((i) = 0; (i) < (l); (i)++)... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 99;
int n, m, RES, CLK;
string s;
vector<int> v[N], dp[N], to(N);
int ans(int n, int m, string s, int x[], int y[]) {
int i = 0;
for (int i = 0; i < m; i++) {
v[x[i]].push_back(y[i]);
++to[y[i]];
}
queue<int> q;
for (int i = 1; i <= n; ... | 9 |
#include <bits/stdc++.h>
using namespace std;
int a[100001];
int ans[100001];
int main() {
int n, k;
cin >> n >> k;
for (int i = 1; i <= n; i++) {
cin >> a[i];
int l = max(1, i - k);
int r = min(i + k, n);
if (!a[i]) {
ans[i] = r - l + 1;
continue;
} else {
l = max(l, min(a[i... | 6 |
#include<cstdio>
#include<iostream>
#include<queue>
#include<algorithm>
#include<cstring>
#include<set>
#include<array>
#include<vector>
#include<cmath>
#define PII pair<int,int>
#define pb push_back
#define ep emplace_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
inline int read(){
... | 18 |
#include <algorithm>
#include <array>
#include <bitset>
#include <cctype>
#include <chrono>
#include <cmath>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iso646.h>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long mex(long long x, long long y) {
long long res = 1;
x = x;
if (x == 0) return 0;
while (y > 0) {
if (y & 1) res = (res * x);
y = y >> 1;
x = (x * x);
}
return res;
}
long long find(long long x, long long pika) {
for (int i = pika; i >= 0; ... | 5 |
#include <bits/stdc++.h>
using namespace std;
vector<long long int> get_factors(
map<long long int, long long int> prime_factorzn) {
long long int total = 1;
vector<long long int> powers, primes, answer;
for (auto it : prime_factorzn) {
total *= (it.second + 1);
powers.push_back(it.second + 1);
pr... | 11 |
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
template<class A, class B>void tostring(pair<A, B>p) { cerr<<"(" + to_string(p.first) + ", " + to_string(p.second) + ")";}
template<class A>void tostring(A v) {int f = 1;string r = "{";for (auto& x : v) {if (!f) {r += ", ";}f = 0;r += to_string(x);}r += "}... | 3 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
T power(T N, T P) {
return (P == 0) ? 1 : N * power(N, P - 1);
}
template <class T>
T gcd(T a, T b) {
if (b == 0) return a;
return gcd(b, a % b);
}
template <class T>
T lcm(T a, T b) {
return (a / gcd(a, b)) * b;
}
int toInt(string p) {
int ret ... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100000;
int n, sg[N + 1], stamp[N];
vector<pair<int, int> > choices[N + 1];
int main() {
scanf("%d", &n);
for (int init = 1; init <= n; ++init) {
int sum = 0;
int length = 0;
while (true) {
sum += init + (length++);
if (sum > n) {
... | 12 |
#include <bits/stdc++.h>
using namespace std;
void init() {
cin.tie(0);
cin.sync_with_stdio(0);
cout.tie(0);
}
long long second(long long x) {
long long s = 0;
while (x) {
s += x % 10;
x /= 10;
}
return s;
}
long long powe(long long a, long long n) {
if (n == 1) return a;
return a * powe(a, n ... | 11 |
#include <bits/stdc++.h>
using namespace std;
const long long m = 1000000007;
long long power(long long a, long long b) {
if (b == 0)
return 1;
else if (b == 1)
return a;
long long y = power(a, b / 2) % m;
if (b % 2) return (y * y * a) % m;
return (y * y) % m;
}
int main() {
long long n;
cin >> n;... | 5 |
#include <bits/stdc++.h>
using namespace std;
int imperfect(string &s) {
int n = s.size(), cnt = 0;
for (int i = 0; i + 1 < n; i++) {
if (s[i] == s[i + 1]) cnt++;
}
return cnt;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int tc, n;
string s;
cin >> tc;
while (tc--) {
cin >> ... | 1 |
#include <bits/stdc++.h>
using namespace std;
int n, cnt, l, r, u, d, arr[2005][2005];
int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1};
void dfs(int x, int y) {
arr[x][y] = 0;
cnt++;
if (x > d || (x == d && y > r)) {
d = x;
r = y;
}
if (x < u || (x == u && y < l)) {
u = x;
l = y;
}
for (int... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e3 + 5;
int n, m, k;
char a[maxn][maxn], ans[maxn][maxn];
vector<int> x, y, s;
int main() {
cin.tie(0)->sync_with_stdio(0);
cin >> n >> m;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
cin >> a[i][j];
if (a[i][j] == '*')... | 9 |
#include <bits/stdc++.h>
using namespace std;
typedef struct N {
int a, b, index, sign;
} node;
node no[200000];
int compare(node a, node b) {
if (b.a != a.a) return a.a > b.a;
if (a.b != b.b) return a.b > b.b;
return a.sign < b.sign;
}
int compare2(node a, node b) {
if (b.b != a.b) return a.b < b.b;
if (a.... | 14 |
#include <bits/stdc++.h>
using namespace std;
void __print(long long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x)... | 8 |
#include <bits/stdc++.h>
using namespace std;
int frc[262144], ifr[262144];
long long quickpow(long long x, int k) {
long long ret = 1;
for (; k; k >>= 1, x = x * x % 998244353)
(k & 1) && (ret = ret * x % 998244353);
return ret;
}
int main() {
int n;
long long k;
scanf("%d%lld", &n, &k);
if (k >= n) ... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 43;
bool isp[MAXN];
int phi[MAXN];
long long mod = 1e9 + 7;
long long add(long long a, long long b) { return (a + b) % mod; }
long long ml(long long a, long long b) { return (a * b) % mod; }
long long cnt[MAXN];
bool usd[MAXN];
vector<int> divs[MAXN];... | 14 |
#include <bits/stdc++.h>
using namespace std;
char s[120];
int main() {
int n, i, j;
cin >> n >> s;
if (n & 1) {
if (n < 4) {
cout << s;
} else {
printf("%c%c", s[0], s[1]);
for (i = 2; i < n - 3; i += 2) {
printf("-%c%c", s[i], s[i + 1]);
}
printf("-%c%c%c", s[n - 3]... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int MSK = 1 << 9;
int cnt[MSK];
vector<pair<int, int>> v[MSK];
int main() {
int n, m;
cin >> n >> m;
for (int i = 0; i < n; i++) {
int f, b, msk = 0;
cin >> f;
for (int j = 0; j < f; j++) {
cin >> b;
msk |= (1 << (b - 1));
}
cnt[m... | 13 |
#include <bits/stdc++.h>
using namespace std;
namespace IO {
const int buffer_size = 1e5 + 5;
char buf[buffer_size], *S, *T;
bool flag_EOF;
inline char read_char() {
if (S == T) T = (S = buf) + fread(buf, 1, buffer_size, stdin);
return S != T ? *(S++) : EOF;
}
inline int read_int() {
int flag = 1;
char c = read... | 19 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, k, i, c = 0;
cin >> n >> k;
long long int x[n];
for (i = 0; i < n; i++) cin >> x[i];
for (i = 1; i < n; i++) {
if (x[i] + x[i - 1] < k) {
c += k - (x[i] + x[i - 1]);
x[i] += k - (x[i] + x[i - 1]);
}
}
cout << c... | 2 |
#include <bits/stdc++.h>
using namespace std;
namespace {
template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()) {
v.assign(a, vector<T>(b, t));
}
template <class F, class T>
void convert(const F &f, T &t) {
stringstream ss;
ss << f;
ss >> t;
}
void mainmain() {
string in;
cin... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 205;
const int MAXVAL = 1000000000;
int a[MAXN];
int dp[MAXN][MAXN * MAXN];
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < 2 * n - 1; ++i) scanf("%d", a + i);
for (int i = 0; i < MAXN; ++i)
for (int j = 0; j < MAXN * MAXN; ++j) dp[i][j... | 10 |
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ff first
#define ss second
#define rep(i,m,n) for(int i=m;i<n;i++)
#define pb push_back
#define pii pair<int,int>
#define all(v) v.begin(),v.end()
void solve() {
int n;
cin >> n;
string s;
cin >> s;
int cnt = 0;
rep(i, 0, n) {
if (s[i] ... | 11 |
#include <bits/stdc++.h>
using namespace std;
int a[100005];
struct segment {
int mn, mx;
} seg[300015];
void build(int node, int l, int r) {
if (l == r) {
seg[node].mn = seg[node].mx = a[l];
} else {
build(2 * node, l, (l + r) / 2);
build(2 * node + 1, (l + r) / 2 + 1, r);
seg[node].mn =
... | 11 |
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout << setprecision(10) << fixed;
long long int n, a, b, k;
cin >> n >> a >> b >> k;
vector<long long int> v;
long long int t;
long long int c = 0;
for (long long int i = 0; i < n; i++) {
... | 7 |
#include <bits/stdc++.h>
using namespace std;
int n;
string s;
int main() {
cin >> n >> s;
for (int i = 1; i <= n; i++) {
if (n % i) continue;
string a = s.substr(0, i);
string b = s.substr(i, n);
reverse(a.begin(), a.end());
s = a + b;
}
cout << s << endl;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
vector<int> v;
int x;
for (int i = 0; i < 4 * n; i++) {
cin >> x;
v.push_back(x);
}
int k = 0;
sort(v.begin(), v.end());
int s = v.size() - 1;
long long ar... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int n;
string str[N];
string vv = "aeoiu";
vector<pair<int, int>> pos[10];
int index(char c) {
for (int i = 0; i < ((int)(vv).size()); i++)
if (vv[i] == c) return i;
return ((int)(vv).size());
}
int main() {
ios::sync_with_stdio(false);
ci... | 9 |
#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 * 10 + ch - '0';
ch = getchar();
}
return x * f;
}
int n, sg[1 << 20], a[1... | 14 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 998244353;
vector<long long> fact, finv;
struct __init {
__init(int n) {
fact.resize(n + 1);
finv.resize(n + 1);
fact[0] = finv[n] = 1;
for (int i = 1; i <= n; i++) fact[i] = fact[i - 1] * i % MOD;
for (long long x = MOD - 2, a = ... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, x, y;
cin >> n >> m;
vector<int> N(n, 0), M(m, 0);
cin >> x;
for (int i = 0; i < x; i++) {
int k;
cin >> k;
N[k] = 1;
}
cin >> y;
for (int i = 0; i < y; i++) {
int k;
cin >> k;
M[k] = 1;
}
int unhapp = n + m... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long int Fun(long long int X, long long int *ar, long long int N) {
long long int Sum = 0, C = 0, cnt = ar[1];
for (int i = 2; i <= N; i++) {
if (ar[i] == 1) cnt++;
if (ar[i] == ar[i - 1] && ar[i] == 1) {
Sum++;
if (Sum + 1 >= X) C++;
} else... | 7 |
#include <bits/stdc++.h>
using namespace std;
const unsigned long long int N = 5e5 + 5;
void fun() {}
unsigned long long int md = 1e9 + 7;
unsigned long long int __gcd(unsigned long long int a,
unsigned long long int b) {
if (b == 0) return a;
return __gcd(b, a % b);
}
unsigned long lon... | 12 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void read(T &x) {
x = 0;
int f = 0;
char ch = getchar();
while (ch < '0' || ch > '9') f |= (ch == '-'), ch = getchar();
while (ch <= '9' && ch >= '0')
x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
x = f ? -x : x;
return;
}
... | 4 |
#include <bits/stdc++.h>
using namespace std;
void dfs(int *k, int i, int j);
char maze[500 + 2][500 + 2];
int main() {
int n, m, k, a, b, d = 1;
char c;
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> n;
cin >> m;
cin >> k;
for (int i = 0; i <= n + 1; ++i) maze[0][i] = 0;
for (in... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
struct {
int op;
long long l, r;
} e[N];
long long b[N << 2];
struct {
char v, tag;
void upd(char x) { v = x, tag = 0; }
void flip() {
if (v != -1)
v ^= 1;
else
tag ^= 1;
}
} tr[N << 4];
int n;
void pd(int o) {
if (t... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
int n;
int x[maxn], y[maxn];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; ++i) {
scanf("%d%d", &x[i], &y[i]);
}
while (1) {
int s = 0;
for (int i = 1; i <= n; ++i) {
if (x[i] + y[i] & 1) {
++s;
}
... | 15 |
#include <bits/stdc++.h>
using namespace std;
int n, m, x, xsol, tp, ng;
pair<int, int> cr;
pair<int, int> cmmdc(int a, int b) {
if (a == 1 && b == 1) return make_pair(1, 0);
if (a == 1) return make_pair(b, b - 1);
if (b == 1) return make_pair(a, a - 2);
if (a == 0 || b == 0) return make_pair(-1000000, -1000000... | 13 |
#include <bits/stdc++.h>
using namespace std;
template <typename A, typename B>
string to_string(pair<A, B> p);
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);
string to_string(const string... | 14 |
#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:255000000")
bool firstout = 1;
template <class T>
T &minn(T &a, T b) {
if (b < a) a = b;
return a;
}
template <class T>
T &maxx(T &a, T b) {
if (a < b) a = b;
return a;
}
int &madd(int &a, int b) {
a += b;
if (a >= 1000000007) a -... | 13 |
#include <bits/stdc++.h>
using namespace std;
const long long pp = 998244353;
const long double eps = 1e-8;
inline long long ksm(long long x, long long y = pp - 2) {
x = (x % pp + pp) % pp;
long long ans = 1;
while (y) {
if (y & 1) ans = ans * x % pp;
x = x * x % pp;
y >>= 1;
}
return ans;
}
inlin... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long t, m, n;
cin >> t;
while (t--) {
cin >> n >> m;
if (n % m) {
cout << "NO" << endl;
} else {
cout << "YES" << endl;
}
}
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
long long int dp[5001][5001];
int main() {
string s1, s2;
cin >> s1 >> s2;
memset(dp, 0, sizeof(dp));
for (int i = 1; i <= ((int)s1.size()); i++) {
for (int j = 1; j <= ((int)s2.size()); j++) {
dp[i][j] = dp[i][j - 1] % 1000000007;
if (s1[i - 1] == s... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 5;
int par[MAXN * 2];
map<string, int> m;
int find(int x) { return par[x] == x ? par[x] : par[x] = find(par[x]); }
void unit(int a, int b) {
a = find(a);
b = find(b);
if (a != b) {
par[a] = b;
}
}
bool isSame(int a, int b) {
a = find(a);... | 12 |
#include <bits/stdc++.h>
using namespace std;
int cmp(const void *a, const void *b) { return *(int *)a - *(int *)b; }
int z[1000005];
int main() {
int n, a, i;
i = 1;
cin >> n;
for (a = 0; n > a; a++) {
cin >> z[a];
}
qsort(z, n, sizeof(z[0]), cmp);
for (a = 0; n > a; a++) {
if (z[a] >= i) {
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n, p = 1, q;
int a[100005];
int seg[300005][60];
void fix(int at) {
for (int j = 0; j < 60; j++) {
int x = seg[2 * at][j];
seg[at][j] = seg[2 * at + 1][(x + j) % 60] + x;
}
}
void update(int at, int lo, int hi, int x) {
if (hi < x || lo > x) return;
if (... | 16 |
#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> arr(n);
map<int, int> s;
for (int i = (0); i < (n); i++) {
cin >> arr[i];
s[i] = arr[i];
}
auto cur = s.begin();
auto prev = s.begin();
cur++... | 11 |
#include <bits/stdc++.h>
using namespace std;
int n, x, t, ans;
multiset<int> arr;
int main() {
cin >> n >> x;
for (int i = 0; i < n; i++) {
cin >> t;
arr.insert(t);
}
for (int i = 0; i < x; i++) {
if (!arr.count(i)) ans++;
}
if (arr.count(x)) ans++;
cout << ans << endl;
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 210010;
struct Node {
int id, len, color;
bool operator<(const Node &other) const {
if (color != other.color) return color < other.color;
return len > other.len;
}
} node[MAXN];
long long Max1[MAXN], Max2[MAXN];
int src1[MAXN], src2[MAXN];
int... | 9 |
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
struct Star {
int cx, cy, r;
};
char grid[105][105];
bool used[105][105] = {0};
int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
void init(int n, int m) {
for (int i = 1; i <= 100; ++i) {
for (int j = 1; j <= 100; ++j) {
grid[i][j] = '.';... | 9 |
#include <bits/stdc++.h>
using namespace std;
long long q, t, x, l, k, n, temp, v, rs[100], pos;
int main() {
cin >> q;
while (q--) {
cin >> t >> x;
l = log2(x) + 1;
if (t == 1) {
cin >> k;
n = 1LL << (l - 1);
temp = (k % n + n) % n;
rs[l] = (rs[l] + temp) % n;
} else if (t =... | 13 |
#include <bits/stdc++.h>
using namespace std;
vector<int> graph[100];
int found = 0;
int color[100];
void dfs(int u, int a, int n) {
color[u] = 1;
for (int i = 0; i < graph[u].size(); i++) {
int v = graph[u][i];
if (v == a) {
found = 1;
}
if (color[v] == 0) {
dfs(v, a, n);
}
}
co... | 7 |
#include <bits/stdc++.h>
int main() {
int n;
char a[101];
std::cin >> a;
n = strlen(a);
int count = 0;
int c;
for (int i = 97; i < 123; ++i) {
c = 0;
for (int j = 0; j < n; ++j)
if (a[j] == char(i)) c++;
if (c) count++;
}
if (count % 2)
std::cout << "IGNORE HIM!";
else
std:... | 0 |
#include <bits/stdc++.h>
using namespace std;
int N;
int a[100000], b[100000];
int p[100000], diff[100000];
set<pair<int, int> > pos;
set<pair<int, int>, greater<pair<int, int> > > neg;
int main() {
cin >> N;
for (int i = 0; i < N; i++) {
cin >> a[i];
p[a[i]] = i;
}
for (int i = 0; i < N; i++) {
cin... | 13 |
#include <bits/stdc++.h>
using namespace std;
int results[101][101];
bool successful[101];
int main() {
int n;
int m;
cin >> n >> m;
memset(results, 0, sizeof(results));
memset(successful, 0, sizeof(successful));
for (int i = 0; i < n; i++) {
string s;
cin >> s;
for (int j = 0; j < m; j++) {
... | 1 |
#include <bits/stdc++.h>
const int N = 100010;
const int inf = 0x3f3f3f3f;
using namespace std;
bool vis[110][110];
int main() {
int n, ret = -1;
cin >> n;
for (int i = 1; i <= 100; i++)
if (i * (i - 1) * (i - 2) / 6 > n) {
ret = i;
break;
}
int cnt = 0;
for (int i = 0; i < 100; i++) {
... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100010;
int is[MAXN], notIs[MAXN];
int val[MAXN];
int main() {
int n, m;
while (scanf("%d%d", &n, &m) != EOF) {
for (int i = 0; i < n; ++i) is[i] = notIs[i] = 0;
int sumNotIs(0);
for (int i = 1, j; i <= n; ++i) {
scanf("%d", &j);
... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, a, b;
cin >> n >> a >> b;
long long l = 0, r = a + b;
while (r - l > 1) {
long long m = (r + l) / 2;
if (b / m + a / m >= n && b >= m && a >= m)
l = m;
else
r = m;
}
cout << l;
return 0;
}
| 4 |
#include <bits/stdc++.h>
int dx[] = {-1, -1, -1, 0, 1, 1, 1, 0};
int dy[] = {-1, 0, 1, 1, 1, 0, -1, -1};
using namespace std;
long long power(long long a, long long p, long long M) {
long long r = 1;
a = a % M;
while (p > 0) {
if (p % 2) r = (r * a) % M;
a = (a * a) % M;
p /= 2;
}
return r % M;
}
... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100050, INF = 0x3f3f3f3f;
struct Node {
int id;
long long value;
};
bool cmp(Node a, Node b) {
if (a.value == b.value) a.id < b.id;
return a.value > b.value;
}
Node tr[N];
long long sum[N];
long long a[N];
int main() {
int n, r;
long long maxs = 0,... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 300000 + 10;
int fa[maxn][20], n, m, dep[maxn], f[maxn], up[maxn], flag[maxn], d[maxn], tot,
now, vis[maxn], en[maxn], out[maxn], ans;
struct node {
int to, id;
};
int lca(int x, int y) {
if (dep[x] < dep[y]) swap(x, y);
int t = dep[x] - dep[y];
... | 13 |
#include <bits/stdc++.h>
using namespace std;
int w[55][55];
int n;
int lx[55], ly[55];
int LEFT[55];
bool s[55], t[55];
bool match(int i) {
s[i] = 1;
for (int j = 1; j <= n; j++) {
if (lx[i] + ly[j] == w[i][j] && !t[j]) {
t[j] = 1;
if (!LEFT[j] || match(LEFT[j])) {
LEFT[j] = i;
retu... | 15 |
#include <bits/stdc++.h>
using namespace std;
int64_t gcd(int64_t a, int64_t b) {
if (b == 0) return a;
return gcd(b, a % b);
}
int64_t lcm(int64_t a, int64_t b) { return (a * b) / gcd(a, b); }
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int64_t a, b;
cin >> a >> b;
int64_t at = 0, bt = 0;
int64_t... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int N = 5005;
int n, c[N], pr[N], cnt[N], pos[N];
pair<int, int> max1, max2;
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) scanf("%d", &c[i]);
for (int i = 0; i < n; i++) {
memset(cnt, 0, sizeof cnt), memset(pos, -1, sizeof pos);
max1 = make_... | 7 |
#include <bits/stdc++.h>
using namespace std;
int A[500000];
int B[500000];
int ans = 0;
void addedge(int a, int b) {
A[ans] = a;
B[ans++] = b;
return;
}
void print(void) {
printf("%d\n", ans);
for (int i = 0; i < ans; i++) printf("%d %d\n", A[i] + 1, B[i] + 1);
return;
}
int n, m, cnt = -1;
int fir[100000]... | 18 |
#include <bits/stdc++.h>
using namespace std;
;
const double eps = 1e-8;
const int mod = 1000000007;
const int maxn = 500000 + 7;
const double pi = acos(-1);
const int inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3fLL;
int cnt, n, q, x, y, op;
int ls[maxn], rs[maxn], fa[maxn];
vector<int> G[maxn];
struct nod... | 13 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const double eps = 1e-9;
vector<int> mapp[100010];
int n, m, ans;
int in[100010], num[100010];
void init() {
for (int i = 0; i <= n; i++) {
mapp[i].clear();
}
memset(in, 0, sizeof(in));
ans = n;
}
void topu() {
int vis[100010];
... | 15 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
int value = 0;
double sum = 0;
cin >> n;
while (n--) {
sum = 0;
cin >> k;
for (int i = 0; i < k; i++) {
cin >> value;
sum += value;
}
int p = ceil(sum / k);
cout << p << endl;
}
return 0;
}
| 0 |
#include <bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;
template <class T>
bool umin(T& a, const T& b) {
return b < a ? a = b, 1 : 0;
}
template <class T>
bool umax(T& a, const T& b) {
return a < b ? a = b, 1 : 0;
}
const int MOD = 998244353;
const long long inf = 1e18;
const long long mod = 1e9 + ... | 10 |
#include <bits/stdc++.h>
using namespace std;
long long t, n, m, u, v, q, k, l, r;
const int N = 2e5 + 500;
const int SN = 331;
const long long mod = 1e9 + 7;
const long long INF = 1LL << 57;
long long arr[N], brr[N];
string str, ss;
long long dp[11][70][1100][2];
long long solve(int base, int pos, int mask, bool start... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5;
int n, k, ans;
int pre[N];
char str[N];
int p[N], s[N][2];
int d[N], type[N];
vector<int> F[N];
int find(int x) {
if (x == pre[x]) return x;
int y = pre[x];
pre[x] = find(pre[x]);
d[x] = (d[x] + d[y]) & 1;
return pre[x];
}
int main() {
sca... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int inf = (int)1e9 + 100;
const long double eps = 1e-12;
const long double pi = acos(-1.0L);
int myrand() { return rand(); }
unsigned rdtsc() {
unsigned ans;
asm("rdtsc" : "=a"(ans));
return ans;
}
int rnd(int x) { return myrand() % x; }
void precalc() {}
const ... | 18 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
while (cin >> n >> k) {
if (k > n * n)
cout << -1 << endl;
else {
int a[n][n];
memset(a, 0, sizeof(a));
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (a[i][j] == 0) {
i... | 6 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
long long p[1024][1024];
long long dt[1024];
long long facts[1000003];
long long invfacts[1000003];
long long xyl[1024];
pair<long long, long long> extended_gcd(long long a, long long b) {
if (b == 0) return make_pair(1, 0);
pair<long l... | 15 |
#include <bits/stdc++.h>
using namespace std;
int len;
string str;
bool isletter(char c) {
if (c >= 'A' && c <= 'Z') return true;
if (c >= 'a' && c <= 'z') return true;
if (c >= '0' && c <= '9') return true;
return false;
}
int main() {
cin >> str;
len = str.size();
if (str.find("@") == -1) {
cout << ... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 100;
struct node {
int par, sz;
} lab[N];
vector<int> ed[N];
int a[N], n, m, pos[N], vis[N];
int get(int u) { return lab[u].par == u ? u : lab[u].par = get(lab[u].par); }
bool cmp(int x, int y) { return a[x] > a[y]; }
int main() {
ios_base::sync_with... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int N = 109;
int n, m;
int lft[N][N], rgt[N][N];
bool seen[N][N];
int sv[N][N];
int solve(int l, int r) {
if (l > r) return 0;
if (seen[l][r]) {
return sv[l][r];
}
int ret = 0;
for (int k = l; k <= r; ++k) {
int cand = 0;
cand += solve(l, k - 1);... | 21 |
#include <bits/stdc++.h>
int main() {
int n, x, y, m;
scanf("%d %d %d", &n, &x, &y);
double s;
s = (y / 100.0) * n;
if (s == (int)s)
m = (int)s;
else
m = (int)s + 1;
if (m <= x)
printf("0\n");
else
printf("%d\n", m - x);
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
void solution() {
long long int n;
cin >> n;
long long int arr[n + 6];
long long int Max = 1234567899;
long long int cnt = 0;
for (long long int i = 1; i <= n; i++) {
cin >> arr[i];
if (Max > arr[i]) {
Max = arr[i];
cnt = i;
}
}
long ... | 1 |
#include <bits/stdc++.h>
using namespace std;
int a[26];
int main() {
char s;
cin >> s;
int ans = 0;
while (s != '}') {
cin >> s;
if (s != ' ' && s != ',' && s != '{') {
a[tolower(s) - 97]++;
}
}
for (int i = 0; i < 26; i++) {
if (a[i] >= 1) ans++;
}
cout << ans;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[]) {
int i, n;
cin >> n;
int A[n];
for (i = 0; i < n; i++) {
cin >> A[i];
}
int turns = -1, data = 0, flag = 0;
int mark[n];
memset(mark, 0, sizeof(mark));
i = -1;
int k = 1;
while (data != n) {
i = 0;
tu... | 4 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline int maximize(T& a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T>
inline int minimize(T& a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
const int N = 152, INF = 0x3f3f3f3f, mod = 1000000007;... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
long long ans = 0;
for (int i = (0); i < (n); ++i) {
long long t, T, x, cost;
cin >> t >> T >> x >> cost;
if (t >= T) {
ans += cost + m * x;
continue;
}
long long aux1 = cost;
if (m > (T - t))... | 11 |
#include <bits/stdc++.h>
const int mo = 1000000009;
using namespace std;
int n, w, b;
long long fac[8010];
long long mul(long long a, int b) {
long long ans = 1, w = a % mo;
while (b) {
if (b & 1) ans = (ans * w) % mo;
w = (w * w) % mo;
b /= 2;
}
return ans;
}
int main() {
scanf("%d%d%d", &n, &w, ... | 13 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
bool get_int(T &x) {
char t = getchar();
bool neg = false;
x = 0;
for (; (t > '9' || t < '0') && t != '-' && t != EOF; t = getchar())
;
if (t == '-') neg = true, t = getchar();
if (t == EOF) return false;
for (; t <= '9' && t >= '0'; ... | 22 |
#include <bits/stdc++.h>
using namespace std;
const int nsz = 100, asz = 26, inf = 0x3f3f3f3f;
int n, m, k, pre = 0, cur = 1, dp[2][nsz + 5][asz], w[nsz + 5][nsz + 5],
ans = -inf;
string s;
void inline upd(int &a, int b) { a = max(a, b); }
int main() {
ios_base::sync_with_stdio(0);
cin >> s >> k >> m;
... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string arr;
int x = 0;
for (int i = 0; i < n; i++) {
cin >> arr;
if (arr == "++X")
++x;
else if (arr == "X++")
x++;
else if (arr == "--X")
--x;
else
x--;
}
cout << x << endl;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int con[1048578], lg[1048578], f[1048578];
long long a[1048578], sum[1048578];
bool check(int s) {
for (int t = (s - 1) & s; (t << 1) >= s && t; t = (t - 1) & s) {
long long tmp = abs(sum[t] - sum[s ^ t]);
if (tmp < con[s] && ((con[s] - tmp) & 1)) return 1;
}
... | 23 |
#include <bits/stdc++.h>
using namespace std;
const long long M = 201;
const long long N = 501;
vector<long long> g[N], ng[N], rg[N];
long long n, m;
string al;
bool gett(char c) { return c == 'C'; }
bool gett1(char c) { return gett(al[c - 'a']); }
void add(long long u, bool ut, long long v, bool vt, vector<long long> ... | 18 |
#include <bits/stdc++.h>
using namespace std;
int n, w[60], vis[60], P[60], UF[60];
long long D[60], INF = 1e18 + 123, F[60];
int Find(int a) {
if (a == UF[a]) return a;
return UF[a] = Find(UF[a]);
}
long long Calc(int m) {
int i, cnt = 0, j;
for (i = 1; i <= n; i++) vis[i] = 0;
for (i = 1; i <= m; i++) {
... | 19 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
bitset<N> dp;
int brute(int n) {
dp.reset();
dp[0] = 1;
for (int i = 1; i <= n; ++i) {
dp = (dp << 1) | (dp << 5) | (dp << 10) | (dp << 50);
}
return dp.count();
}
long long solve(int n) {
if (n < 1000) {
return brute(n);
}
lon... | 12 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.