solution stringlengths 53 181k | difficulty int64 0 13 |
|---|---|
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:167772160000")
using namespace std;
vector<pair<long long, long long> > tables;
long long oneSum = 0;
long long zeroSum = 0;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
for (int i = 0; i < 4; i++) {
char tmp;
int missO... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 5;
const int offset = 1 << 17;
const int LOG = 17;
class TwoSat {
int n;
vector<int> sol;
vector<bool> bio;
vector<int> comp;
vector<vector<int>> adj, rev;
stack<int> order;
public:
void add_variables(int vars) {
n += vars;
for... | 12 |
#include <bits/stdc++.h>
using namespace std;
long long int MOD = 1000000007;
long long int inf = 1e15;
long long int powermod(long long int _a, long long int _b, long long int _m) {
long long int _r = 1;
while (_b) {
if (_b % 2 == 1) _r = (_r * _a) % _m;
_b /= 2;
_a = (_a * _a) % _m;
}
return _r;
}... | 2 |
#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > forw(200001);
vector<vector<int> > backw(200001);
int a[200001];
long long ansb[200001], ansf[200001];
bool flagb[200001], flagf[200001];
void dfs(int pos, long long val, bool f) {
if (!f) {
if (flagb[pos]) {
ansb[pos] = -pos;
} else {
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
vector<int> fav(1e5 + 5, 0), cnt(1e5 + 5, 0), incr(k + 3, 0);
for (int i = 1; i <= k * n; i++) {
int x;
cin >> x;
cnt[x]++;
}
for (int i = 1; i <= n; i++) {
int x;
cin >> x;
fav[x]++;
}
incr[0] = ... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int M = 800000 + 10;
const double pi = acos(-1);
struct vir {
double r, i;
vir(double r = 0.0, double i = 0.0) : r(r), i(i) {}
void print() { printf("%f %f\n", r, i); }
vir operator+(const vir &c) { return vir(r + c.r, i + c.i); }
vir operator-(const vir &c)... | 8 |
#include <bits/stdc++.h>
using namespace std;
long long n, k, g, ans;
long long a[105];
long long Map[102][300005];
long long goes(long long n, long long k) {
if (k == 0) return n;
if (n > 300000) return goes(n, k - 1) - goes(n / a[k - 1], k - 1);
if (Map[k][n] == -1) Map[k][n] = goes(n, k - 1) - goes(n / a[k - 1... | 9 |
#include <bits/stdc++.h>
long long a, b, c, d;
long long r[100];
long long p[100];
void s1() {
int i = 1;
r[i++] = a * b * c + d;
r[i++] = (a * b + c) * d;
r[i++] = (a + b) * c * d;
r[i++] = a * b * d + c;
r[i++] = (a * b + d) * c;
r[i++] = (a + b) * d * c;
r[i++] = a * c * b + d;
r[i++] = (a * c + b)... | 4 |
#include <bits/stdc++.h>
using namespace std;
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1, -1, 1, -1, 0, 0, -1, 1};
int dx4[] = {0, 0, 1, -1};
int dy4[] = {1, -1, 0, 0};
const long long MOD = 1000000007;
template <typename T>
inline T Bigmod(T base, T power, T MOD) {
T ret = 1;
while (power) {
if (p... | 2 |
#include <bits/stdc++.h>
using namespace std;
int n, a[2002], s[2002];
int find_answer() {
int res = 0, cur = 0, k = -1;
for (int i = 0; i < n; ++i) {
cur += a[i];
if (cur < 0) cur = 0, k = i;
res = max(res, (i - k) * cur);
}
return res;
}
int find_my_answer() {
s[0] = a[0];
for (int i = 1; i < ... | 6 |
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define forn(i,n) rep(i,0,n)
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define mp ... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 1 << 29;
int a[200010];
int main() {
int n, k;
scanf("%d%d", &n, &k);
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
long long sum = 0;
int cnt = 0;
for (int i = 1; i <= n; i++) {
if (sum - (long long)a[i] * (n - i) * cnt >= k) {
cnt+... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long int n, t, arr[209][209], brr[209][209], crr[209];
vector<long long int> v;
int main() {
scanf("%lld", &t);
while (t--) {
long long int m;
scanf("%lld %lld", &n, &m);
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) scanf("%lld", &a... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t > 0) {
int a, b, c, d, k, x, y;
cin >> a >> b >> c >> d >> k;
if (a % c == 0)
x = a / c;
else
x = (a / c) + 1;
if (b % d == 0)
y = b / d;
else
y = (b / d) + 1;
if (x + y <= k) {... | 0 |
#include <bits/stdc++.h>
using namespace std;
int q, n;
unsigned long long int sp;
int main() {
cin >> q;
while (q--) {
cin >> n;
vector<int> s;
bool f = false;
for (int i = 0; i < n; ++i) {
cin >> sp;
if (sp < 2048)
s.push_back(log2(sp));
else if (sp == 2048)
f = t... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n, m, x, y;
set<int> st;
cin >> n >> m;
for (int i = 0; i < n; i++) {
cin >> x;
for (int j = 0; j < x; j++) {
cin >> y;
st.insert(y);
}
}
cout << (st.... | 0 |
#include <bits/stdc++.h>
using namespace std;
bool visited[100000];
bool player[100000];
vector<vector<int> > graph;
bool valid = true;
int vcount = 0;
void visit(int pos) {
if (player[pos]) vcount++;
for (auto s : graph[pos]) {
if (valid && visited[s])
valid = player[s] != player[pos];
else if (valid... | 3 |
#include <bits/stdc++.h>
using namespace std;
double maxy, y, d[3000];
int a[3000];
void tao() {
freopen("input.inp", "w", stdout);
cout << "1000 1000" << endl;
for (int i = 1; i <= 1000; i++) cout << 1000 << " ";
}
int main() {
int n, r;
cin >> n >> r;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
... | 3 |
#include <bits/stdc++.h>
using namespace std;
char s[100000 + 10];
char a[] = {"abcdefghijklmnopqrstuvwxyz"};
int main() {
scanf("%s", s);
int n = strlen(s);
int A = 0;
for (int i = 0; i < 26; i++) {
int flag = 1;
for (int j = A; j < n; j++) {
if (a[i] >= s[j]) {
s[j] = a[i];
A = j... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int MAXM = 2000001;
long long int arr[MAXM];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
arr[1] = 0;
arr[2] = 0;
arr[3] = 1;
for (int i = 4; i < MAXM; i++) {
arr[i] = ((arr[i - 1] + 2 * arr[i - 2]) % 1000000007);
if (i % 3 == 0) arr[i] = (arr... | 5 |
#include <bits/stdc++.h>
using namespace std;
const long long int maxn = 2e3 + 1;
long long int dp[maxn][maxn];
long long int solve(long long int s, long long int n, long long int hrs,
long long int h, long long int l, long long int r,
vector<long long int>& v) {
if (s >= n) {
... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 7;
const int inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + 7;
const double eps = 1e-8;
const double PI = acos(-1);
template <class T, class S>
inline void add(T& a, S b) {
a += b;
if (a >= mod) a -= mod;
}
template... | 8 |
#include <bits/stdc++.h>
using namespace std;
struct FT {
vector<long long> s;
FT(int n) : s(n) {}
void update(int pos, long long dif) {
for (; pos < (int)(s).size(); pos |= pos + 1) s[pos] += dif;
}
long long query(int pos) {
long long res = 0;
for (; pos > 0; pos &= pos - 1) res += s[pos - 1];
... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 5;
int ans[MAXN];
vector<int> G[MAXN];
int dp[MAXN], num[MAXN], sum, root;
bool vis[MAXN];
void RiKa(int u, int fa) {
dp[u] = 0;
num[u] = 1;
for (int i = 0; i < G[u].size(); i++) {
int v = G[u][i];
if (vis[v] || v == fa) continue;
Ri... | 6 |
#include <bits/stdc++.h>
using namespace std;
char s[15], t[15];
char m[10][15] = {"monday", "tuesday", "wednesday", "thursday",
"friday", "saturday", "sunday"};
int x, y, cnt;
int main() {
scanf("%s %s", s, t);
for (int i = 0; i < 7; i++) {
if (strcmp(s, m[i]) == 0) x = i + 1;
}
for (int... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int module = 1e9 + 7;
const int inf = (1 << 31) - 1;
const int _inf = 1 << 31;
int main(void) {
int n;
double l, v1, v2;
int p;
while (scanf("%d", &n) == 1) {
scanf("%lf%lf%lf%d", &l, &v1, &v2, &p);
int tang = (n + p - 1) / p;
double x = l * 2.0 * ... | 5 |
#include <bits/stdc++.h>
using namespace std;
int const MaxSize = 1e5 + 10;
int n, maxV, minV;
map<int, int> cnt;
void p(int minC, int midC, int maxC) {
for (int i = int(0); i < int(minC); i++) {
printf("%d ", minV);
}
for (int i = int(0); i < int(midC); i++) {
printf("%d ", minV + 1);
}
for (int i = ... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5 + 10;
const int INF = 1e9 + 7;
const long long mod = 1e9 + 7;
const double eps = 1e-7;
int n, m;
vector<int> g[maxn], id[maxn];
vector<int> ans;
int mark[maxn];
bool vis[maxn];
bool judge(int x, int y) {
if ((int)g[x].size() == 0) {
if (y == 1)
... | 4 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n;
cin >> n;
int a[n + 1][4];
long long int x = 1, y = 0;
for (int i = 2; i < n + 1; i++) {
long long int temp = (y + 2 * x) % 1000000007;
y = 3 * x;
y %= 1000000007;
x = temp;
}
cout << y << endl;
}
int main() {
ios_base::... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long int n, m, a, b;
cin >> n >> m >> a >> b;
if (n == m) {
cout << 0 << endl;
return 0;
}
long long int k = n / m;
long long int k1 = (k + 1) * m;
long long int k... | 1 |
#include <bits/stdc++.h>
using namespace std;
int n, k;
string s;
int main() {
ios_base ::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> k >> s;
if (!k) {
cout << s;
return 0;
}
if (int(s.size()) == 1) {
cout << 0;
return 0;
}
if (s[0] != '1') {
s[0] = '1';
--k;
}
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int busy[101], busy2[101];
int main() {
int n, q, t, k, d, sum;
scanf("%d%d", &n, &q);
for (int i = 0; i < q; i++) {
scanf("%d%d%d", &t, &k, &d);
sum = 0;
int cnt = k;
for (int j = 1; j <= n; j++) {
busy2[j] = busy[j];
}
for (int j = 1; j... | 2 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = (long long)1 << 62;
const long long MOD = 1e9 + 7;
const int iINF = 1 << 30;
const double PI = 3.14159265359;
void solve() {
long long d, m;
cin >> d >> m;
long long curr = 1;
for (; curr * 2 <= d; curr *= 2)
;
long long nxt = d;
long l... | 4 |
#include <bits/stdc++.h>
using namespace std;
int num, arr[10], cu[10];
int main() {
cin >> num;
for (int i = 1; i <= 7; ++i) cin >> arr[i];
int ind;
while (num > 0) {
bool b = true;
for (int i = 1; i <= 7; ++i) {
if (num - arr[i] > 0)
num -= arr[i];
else {
ind = i;
b... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int maxn = (int)1e6 + 3;
long long fact[maxn], facrev[maxn];
long long power(long long a, long long b) {
if (b == 0) return 1;
if (b == 1) return a;
long long c = power(a, b / 2);
c = (c * c) % mod;
if (b % 2) c = (c * a) % mod;
re... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 20, inf = 1e6;
int a[N][N];
int m, n, b, c;
int ans = 0;
int mn = inf, mn1 = inf;
int main() {
std::ios::sync_with_stdio(false);
cin >> m >> n;
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
cin >> a[i][j];
}
}
cin >>... | 2 |
#include <bits/stdc++.h>
using namespace std;
void archit_was_here() {}
void legend_was_here() {}
int main() {
int x[100000];
string s;
cin >> s;
int k = 0;
cin >> k;
int ff = 0, sn = 0, len = s.size();
for (int i = 0; i < len; i++) {
if (s[i] == '?')
ff++;
else if (s[i] == '*')
sn++;
... | 2 |
#include <bits/stdc++.h>
using namespace std;
inline int read() {
char ch = 0;
int x = 0, flag = 1;
while (!isdigit(ch)) {
ch = getchar();
if (ch == '-') flag = -1;
}
while (isdigit(ch)) {
x = (x << 3) + (x << 1) + ch - '0';
ch = getchar();
}
return x * flag;
}
struct link {
int x, y, z;... | 10 |
#include <bits/stdc++.h>
using namespace std;
long long readi() {
long long input = 0;
char c = ' ';
while (c < '-') {
c = getchar();
}
bool negative = false;
if (c == '-') {
negative = true;
c = getchar();
}
while (c >= '0') {
input = 10 * input + (c - '0');
c = getchar();
}
if ... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char *argv[]) {
int x, y, a, b;
long resa[10000] = {0}, resb[10000] = {0};
cin >> x >> y >> a >> b;
long res = 0;
for (int i = a; i <= x; i++) {
for (int l = b; l <= y; l++) {
if (l < i) {
resa[res] = i;
resb[res] = l;
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int gi() {
int x = 0, w = 1;
char ch = getchar();
while ((ch < '0' || ch > '9') && ch != '-') ch = getchar();
if (ch == '-') w = 0, ch = getchar();
while (ch >= '0' && ch <= '9')
x = (x << 3) + (x << 1) + ch - '0', ch = getchar();
return w ? x : -x;
}
const ... | 13 |
#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000;
const long long LINF = INF * (long long)INF;
const int MAX = 100007;
const int MOD = 1000000007;
vector<int> G[MAX];
int up[MAX][20];
int tin[MAX];
int tout[MAX];
int d[MAX];
int timer = 0;
void dfs(int v, in... | 6 |
#include <bits/stdc++.h>
using namespace std;
long long int ara[300007], divisor[4 * 300007], tree[4 * 300007],
mxTree[4 * 300007];
void InitiaLization() {
for (long long int i = 1; i <= 1000000; i++)
for (long long int j = i; j <= 1000000; j += i) divisor[j]++;
}
void build(long long int node, long long int ... | 6 |
#include <bits/stdc++.h>
using namespace std;
int len, base;
vector<long long> fmtOr(vector<long long> A, int nrev = 1) {
for (int i = 0; i < base; ++i)
for (int S = 0; S < len; ++S)
if (~S >> i & 1) A[S | (1 << i)] += nrev * A[S];
return A;
}
int n, ppc[1 << 18], full;
long long f[1 << 18][18], ppcPow[1 ... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 200005;
const long long Mod = 1e9 + 7;
long long a[105];
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(0);
;
long long sum;
int t, n;
cin >> t;
while (t--) {
long long sum = 0;
long long s = 0;
cin >> n;
for (int ... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10, MOD = 998244353, inv = 499122177;
int n, m;
vector<int> a[N], pref[N], flag[N], aux[N];
bool check(int x) {
for (int i = 0; i <= n + 1; i++)
for (int j = 1; j <= m; j++) flag[i][j] = aux[i][j] = 0;
for (int i = 1; i <= n; i++) {
for (int ... | 7 |
#include <bits/stdc++.h>
using namespace std;
int n, k, a[800010], nxt[800010], p[800010], cap, ans;
bool vis[800010];
set<int> S;
set<int>::iterator it;
int main() {
scanf("%d%d", &n, &k);
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
for (int i = 1; i <= n; i++) {
p[i] = n + i;
a[n + i] = i;
}
fo... | 5 |
#include <bits/stdc++.h>
using namespace std;
int n, k, a[1000], h[1000];
int main() {
int y[10];
int g = 0;
char s[1000];
int a, b;
cin >> s;
int l = strlen(s);
a = l % 20 == 0 ? l / 20 : l / 20 + 1;
b = l % a == 0 ? l / a : l / a + 1;
int c = a * b - l;
cout << a << " " << b << "\n";
for (int i ... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2002;
int n, m;
char a[N][N];
int s[N];
int main() {
cin >> n >> m;
for (int i = 0; i < n; ++i) cin >> a[i];
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
if (a[i][j] == '1') s[j]++;
}
}
for (int i = 0; i < n; ++i) {
b... | 2 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
struct node {
int u, l, r, s;
} a[110000];
int cmp(node a, node b) { return a.u < b.u; }
int yl, yr, v, dp[110000];
int h, w, n;
stack<int> b[410000];
void update(int k, int l, int r) {
if (yl <= l && yr >= r)
b[k].push(v);
else {
... | 9 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 0x3f3f3f3f3f3f3f3fLL;
const int inf = 0x3f3f3f3f;
const int maxn = 1e2 + 10;
const double eps = 1e-6;
int di[8][2] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1},
{-1, -1}, {-1, 1}, {1, -1}, {1, 1}};
inline long long rd() {
long long x = 0, f ... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2008, mod = 1 << 30;
unordered_map<long long, int> M[308];
int A, B, C, p[maxn], tot;
long long ans;
bool isp[maxn];
void GetPrime() {
fill(isp + 2, isp + 2001, true);
for (int i = 2; i <= 2000; i++) {
if (isp[i]) p[tot++] = i;
for (int j = 0; j... | 9 |
#include <bits/stdc++.h>
using namespace std;
double a[300005], b[300005], v[300005];
struct node {
int l, r;
double lm, rm, m, sum;
} t[300005 * 5];
void bd(int pos, int l, int r) {
node s, ls, rs;
s.l = l, s.r = r;
if (l == r) {
s.sum = v[l];
s.lm = s.rm = s.m = max(0.0, v[l]);
t[pos] = s;
r... | 7 |
#include <bits/stdc++.h>
using namespace std;
int T;
int answer = 0;
vector<int> v;
int main(void) {
ios::sync_with_stdio(0);
cin.tie(nullptr);
cout.tie(nullptr);
cin >> T;
while (T--) {
v.clear();
int n;
cin >> n;
v.resize(n);
for (int i = 0; i < n; ++i) {
cin >> v[i];
}
sor... | 0 |
#include <bits/stdc++.h>
using namespace std;
int N;
int A[1002], pos[1002];
vector<pair<int, int> > V;
void reduce(int pos1, int pos2, int pos3) {
if (A[pos1] > A[pos2]) swap(pos1, pos2);
if (A[pos1] > A[pos3]) swap(pos1, pos3);
if (A[pos2] > A[pos3]) swap(pos2, pos3);
if (A[pos1] == 0) return;
int quotient ... | 11 |
#include <bits/stdc++.h>
using namespace std;
int a[110];
int n, k, x;
int main() {
int i, l, r, cnt, tmp, ans = 0;
cin >> n >> k >> x;
for (i = 0; i < n; i++) cin >> a[i];
for (i = 0; i < n; i++) {
if (a[i] == x) {
l = r = i;
cnt = 0;
while (a[l] == a[r]) {
tmp = 2;
while ... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
if (n == 1) cout << "1";
if (n == 2) cout << "2";
if (n == 3) cout << "6";
if (n == 4) cout << "20";
if (n == 5) cout << "70";
if (n == 6) cout << "252";
if (n == 7) cout << "924";
if (n == 8) cout << "3432";
if (n == 9) c... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int n;
pair<long long, long long> a[3 * N];
multiset<long long> needs;
multiset<pair<long long, long long>> nexts;
int main() {
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i].firs... | 5 |
#include <bits/stdc++.h>
using namespace std;
struct Product {
int buy_price;
int sell_price;
int count;
Product(int a = 0, int b = 0, int c = 0)
: buy_price(a), sell_price(b), count(c) {}
};
inline int min(int a, int c) { return a < c ? a : c; }
inline int max(int a, int c) { return a > c ? a : c; }
int ... | 2 |
#include <bits/stdc++.h>
using namespace std;
queue<int> q;
int n, a, b, k, num = 0, ans = 0, flag = 0;
char s[200050];
int main() {
scanf("%d %d %d %d", &n, &a, &b, &k);
scanf("%s", s);
int len = strlen(s);
for (int i = 0; i < len; i++) {
if (s[i] == '0')
num++;
else
num = 0;
if (num >=... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n;
int par[200010][18];
int dep[200010];
int lca(int u, int v) {
if (dep[u] < dep[v]) swap(u, v);
for (int i = 18 - 1; i >= 0; i--)
if (dep[par[u][i]] >= dep[v]) u = par[u][i];
if (u == v) return u;
for (int i = 18 - 1; i >= 0; i--)
if (par[u][i] != par[... | 7 |
#include <bits/stdc++.h>
int main() {
std::string s;
std::cin >> s;
int c = 4;
if (s[0] == 'f') c = 3;
s.insert(c, "://");
c = s.find("ru", c + 4);
s.insert(c, ".");
c += 3;
if (c < s.length()) {
s.insert(c, "/");
}
std::cout << s;
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int i, n, a, u, v;
scanf("%d", &n);
u = 101;
v = 101;
for (i = 1; i <= n; i++) {
scanf("%d", &a);
if (u > a) {
v = u;
u = a;
} else if ((v > a) && (a > u))
v = a;
}
if (v != 101)
cout << v << "\n";
else
cout... | 0 |
#include <bits/stdc++.h>
using namespace std;
int a[10];
int main() {
int n;
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
sort(a, a + n);
cout << a[n / 2];
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
template <class V>
struct SegTree {
int n;
vector<V> st;
vector<int> leaves;
SegTree(const int n) : n(n) {
leaves.resize(n);
init(1, 0, n - 1);
}
void init(const int si, const int lo, const int hi) {
if (lo == hi) {
if (si >= (int)st.size()) st... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int MAXN = 1e3 + 100;
const int XX = 5000;
const long double lg2 = log(2);
const long double lg3 = log(3);
int val[XX];
pair<int, int> add(pair<int, int> a, pair<int, int> b) {
return {a.first + b.first, a.second + b.second};
}
pair<int, int... | 7 |
#include <bits/stdc++.h>
int main(void) {
long long int count = 0;
int n, i, temp, ones = 0;
scanf("%d\n", &n);
for (i = 0; i < n; i++) {
scanf("%d", &temp);
if (!temp)
count += ones;
else
ones++;
}
printf("%lld\n", count);
return 0;
}
| 4 |
#include <bits/stdc++.h>
using namespace std;
long long query(long long l, long long r) {
long long i, res = 0;
for (i = 60; i >= 0; i--) {
long long j = 1LL << i;
if ((l & j) == (r & j)) {
long long bit = l & j;
res += bit;
l -= bit;
r -= bit;
} else
break;
}
if (__bui... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long a, b;
cin >> a >> b;
if (b % a != 0) {
cout << "-1\n";
} else {
long long q = b / a;
int steps = 0;
while (q % 2 == 0) {
steps++;
q /= 2;
}
while (q % 3 == 0) {
steps++;
q /= 3;
}
if (q !... | 1 |
#include <bits/stdc++.h>
using namespace std;
int i, j, k, n;
pair<int, int> a[60];
long double lo, mi, hi, eps, c[60], dyn[60][60][60];
bool ok(long double thr) {
for (i = 1; i <= n; i++)
c[i] = (long double)a[i].first - (long double)a[i].second * thr;
for (i = 0; i <= n; i++)
for (j = 0; j <= n; j++)
... | 8 |
#include <bits/stdc++.h>
using namespace std;
char s[50];
unordered_map<long long, bool> mp;
int m;
int q[50];
int qb, qf, used;
struct node {
int nxt[2], fail, cnt;
void clear() {
memset(nxt, -1, sizeof nxt);
fail = -1;
cnt = 0;
}
} mem[50];
struct AC_automation {
int newnode() {
int ans = ++us... | 10 |
#include <bits/stdc++.h>
using namespace std;
int n, mn[1000000], root, hson[1000000];
int timer, size[1000000], sum[1000000];
int dfn[1000000], id[1000000], gra[1000000];
long long dis[1000000];
set<pair<int, int> > s;
set<pair<int, int> >::iterator it;
int read() {
int x = 0, k = 1;
char c;
c = getchar();
whi... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
while (scanf("%d %d ", &n, &m) != EOF) {
if (n < m) {
printf("-1\n");
continue;
}
if (m == 1) {
if (n == 1)
printf("a\n");
else
printf("-1\n");
continue;
}
int k = n - m + 2;
fo... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int max6 = 1e6 + 6;
const int oo = 1e9 + 9;
const long long inf = 1e18 + 18;
int main() {
int T;
cin >> T;
while (T--) {
int s, t, e;
cin >> s >> t >> e;
cout << max(0, e - max((t + e - s + 2) / 2, 0) + 1) << endl;
}
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
const long double inf = 1ll << 60;
const int N = 2e5 + 1;
const int K = 50;
long double dp[K][N];
long double arr[N];
long double fun[N];
long double sum[N];
long double rec[N];
int n, k;
long double func(int l, int r) {
return (fun[r] - fun[l - 1]) - (rec[r] - rec[l - 1]... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string ss;
cin >> ss;
int n = ss.length();
int freq[1010] = {0};
int ii = 0, jj = 0;
vector<pair<int, int>> vex;
for (int i = 0; i < n; i++) {
string s = "";
while (ss[i] != ',' && i < n) {
s += ss[i];
i++;
}
int l = s.... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1000005;
int n;
char s[N], s1[N];
vector<int> pos;
int cnt[N];
inline bool check(int t, char *s) {
int cur = 1, done = 0;
while (cur <= n) {
while (cur <= n && (cur <= done || s[cur] != '*')) {
if (s[cur] == 'P') done = max(done, cur + t);
... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5, inf = 1e9 + 15;
int c[N], g[N][2], h[N][2];
bool least[N];
vector<int> t[N];
void init(int u = 0, int p = -1, int pv = inf) {
if (c[u] < pv) {
least[u] = 1;
pv = c[u];
}
for (int v : t[u]) {
if (v == p) continue;
init(v, u, pv);
... | 6 |
#include <bits/stdc++.h>
using namespace std;
long long N, M, T;
vector<long long> A, B;
bool ok(long long X) {
if (X == 0) return true;
long long d = B[X - 1];
long long sum = 0, crtsum = 0, crt = 0, cnt = 0;
for (long long i = (long long)(0); i < (long long)(N); i++) {
if (A[i] > d) continue;
sum += A... | 6 |
#include <bits/stdc++.h>
using namespace std;
long long in[4], c, mi;
string s[3];
void go(vector<long long> v, int d) {
if (d == 3) {
int i;
for (i = 0; i < 4; i++)
if (v[i] > -1 && v[i] < mi) mi = v[i];
return;
}
int i, j;
for (i = 0; i < 4; i++)
if (v[i] > -1)
for (j = i + 1; j < ... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 101;
int a[N];
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
if (n == 1) {
if (a[0] % 2 == 1) {
cout << -1 << endl;
} else {
cout << "1\n1" ... | 0 |
#include <bits/stdc++.h>
int n, k, v[5];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%d", &k), v[i % 3] += k;
if (v[0] >= v[1] && v[0] >= v[2])
printf("back\n");
else if (v[1] >= v[0] && v[1] >= v[2])
printf("chest\n");
else
printf("biceps\n");
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000010;
int mod = 10007;
int n;
char s1[maxn], s2[maxn];
unsigned int hash1[maxn], hash2[maxn];
unsigned int key = 10007;
char tank(char c) {
if (c == 'N') return 'S';
if (c == 'S') return 'N';
if (c == 'E') return 'W';
if (c == 'W') return 'E';
}
... | 8 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
int main() {
scanf("%d%d", &n, &m);
if (n == 1 && m == 1) {
puts("YES\n1");
return 0;
}
if ((n == 1 && m <= 3) || (m == 1 && n <= 3) || (n == 2 && m <= 3) ||
(m == 2 && n <= 3)) {
puts("NO");
return 0;
}
if (n == 1 && m == 4) {
... | 7 |
#include <bits/stdc++.h>
using namespace std;
long long n;
vector<long long> sa;
vector<long long> sort_cyclic_shifts(string const& s) {
long long n = s.size();
const long long alphabet = 256;
vector<long long> p(n), c(n), cnt(max(alphabet, n), 0);
for (long long i = 0; i < n; i++) cnt[s[i]]++;
for (long long... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2000005;
multiset<int> ms[N];
set<pair<int, int> > S;
int n, m, Q, mn[N], mx[N], s[N], x, y, p[N];
inline void B(const int rt, const int l, const int r) {
mn[rt] = 2e9, mx[rt] = s[rt] = 0;
if (l == r) return p[l] = rt, void();
const int mid = l + r >> 1;... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e6;
const int INF = 1e9 + 9;
const int B = 1e9 + 7;
int n, m;
int a[N];
set<pair<long long, long long> > st;
int main() {
ios_base ::sync_with_stdio(0);
cin.tie(0);
cin >> n;
for (int i = int(1); i <= int(n); ++i) cin >> a[i];
long long lst = -INF;
... | 3 |
#include <bits/stdc++.h>
inline constexpr int ctoi(const char c) { return c - '0'; }
inline constexpr char itoc(const int n) { return n + '0'; }
template <typename T>
inline T clamp(const T& n, const T& lo, const T& hi) {
return std::max(lo, std::min(n, hi));
}
template <class T>
inline void sort(T& a) {
std::sort(... | 2 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 50 + 7;
long long int n, T, cnt = 0, m, mn = N, mx, ans, x, k;
vector<int> v;
string s;
long long int used[N];
void solve() {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> s;
for (int j = 0; j < s.size(); j++) {
if (s[j] == '1') {
... | 0 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
void usort(vector<T> &x) {
sort((x).begin(), (x).end());
x.erase(unique((x).begin(), (x).end()), x.end());
}
template <typename T>
int index(const vector<T> &a, const T &x) {
return lower_bound((x).begin(), (x).end(), x) - a.begin();
}
template <... | 8 |
#include <bits/stdc++.h>
#pragma warning(disable : 4996)
using namespace std;
int n, m, dx, dy;
int a[200000][2];
long long mul_inv(long long a, long long b) {
long long b0 = b, t, q;
long long x0 = 0, x1 = 1;
if (b == 1) return 1;
while (a > 1) {
q = a / b;
t = b, b = a % b, a = t;
t = x0, x0 = x1 ... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cout.setf(ios::fixed);
cout.precision(17);
int n;
cin >> n;
int positives = 0, negatives = 0;
vector<int> v(n);
for (int i = 0; i < n; i++) {
cin >> v[i];
if (v[i] >= 0)
positiv... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
string a, b;
cin >> a >> b;
int size = (int)a.size(), dif = 0;
int sizeb = (int)b.size();
int bb = 0, aa = 0, ans = 0;
for (int i = 0; i <= sizeb - 1; i++) {
if (b[i] == '1') bb++;
if (a[i... | 5 |
#include <bits/stdc++.h>
using namespace std;
int n, i, j, nr, x, sol;
int d[2005], st[2005][2005], dr[2005][2005], sum[2005][2005];
char s[2005];
int modul(int x) {
if (x >= 998244353) {
return x - 998244353;
}
return x;
}
int main() {
cin >> s + 1;
n = strlen(s + 1);
st[0][0] = 1;
for (i = 1; i <= n... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int k;
int l;
int i = 0;
cin >> k;
cin >> l;
if (l % k != 0) {
cout << "NO";
} else {
while ((l % k == 0) && (l != 0)) {
l = l / k;
i = i + 1;
}
if (l == 1) {
cout << "YES" << endl;
cout << i - 1;
} else... | 1 |
#include <bits/stdc++.h>
using namespace std;
int mark[201][201];
pair<int, int> a[201];
pair<int, int> b[201];
int r;
int n;
int m;
bool D = false;
pair<int, int> dad[201][201];
int ti[201][201];
void DFS(int x, int y) {
mark[x][y] = 1;
for (int i = 0; i < n; i++) {
if ((i + 1) > x) break;
if (0 + a[i].fir... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int NMAX = 100010, MOD = 1e9 + 7;
int m;
int f[NMAX];
vector<int> fact[NMAX];
int prime[NMAX], p_cnt;
set<int> pri[NMAX];
int prime_init() {
bitset<NMAX> flag;
flag.reset();
for (int i = 2; i < NMAX; i++) {
if (!flag[i]) {
prime[p_cnt++] = i;
}
... | 7 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using ii = pair<ll, ll>;
using vi = vector<ll>;
using vb = vector<bool>;
using vvi = vector<vi>;
using vii = vector<ii>;
using vvii = vector<vii>;
const int INF = 2000000000;
const ll LLINF = 9000000000000000000;
template <class... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7, M = 1e5 + 7;
int n, m;
struct Graph {
int to[M << 1], head[N], next[M << 1], color[M << 1], tot;
void clear() {
fill(head, head + n, -1);
tot = 0;
}
void _add_edge(int a, int b, int c) {
to[tot] = b, next[tot] = head[a], color[tot]... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int inf(1010101010);
int le_res, aa;
char naam[1000];
int le_naam;
char naam_and_res[1000];
char occ[1000];
int zvals[1000];
void z_functie(char* s, int n, int* z) {
int a(0), b(0);
for (int i(0); i < (n); i++) z[i] = n;
for (int i = 1; i < n; i++) {
int k =... | 6 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.