buggy_code
stringlengths 11
625k
| fixed_code
stringlengths 17
625k
| bug_type
stringlengths 2
4.45k
| language
int64 0
8
| token_count
int64 5
200k
| change_count
int64 0
100
|
|---|---|---|---|---|---|
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
struct BUG {
LL out, in;
bool operator<(const BUG &t) const { return out < t.out; }
};
bool cmp(const BUG &a, const BUG &b) { return a.in > b.in; };
int n;
BUG bug[300001];
bool solve(int x) {
priority_queue<BUG> que;
LL sum = 0;
int i;
for (i = 0; i < x; i++) {
que.push(bug[i]);
sum += bug[i].out;
}
for (; i < n; i++) {
if (i > x) {
que.push(bug[i]);
sum += bug[i].out;
BUG b = que.top();
que.pop();
sum -= b.out;
}
if (sum <= bug[i].in * x) {
return true;
}
}
return false;
}
/*
bool solve(int x)
{
int lim = x - 1;
while (true){
priority_queue<BUG> que;
for (int i = 0; i <= lim; i++){
que.push(bug[i]);
}
puts("");
LL sum = 0;
for (int i = 0; i < x; i++){
BUG b = que.top(); que.pop();
printf("%lld\n", b.out);
sum += b.out;
}
if (sum <= bug[lim].in * x) return true;
else {
lim++;
if (lim == n) return false;
}
}
}
*/
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%lld %lld", &bug[i].out, &bug[i].in);
}
sort(bug, bug + n, cmp);
int l = 1, r = n;
while (l <= r) {
int m = (l + r) / 2;
if (solve(m))
l = m + 1;
else
r = m - 1;
}
if (r == -1)
puts("0");
else
printf("%d\n", r);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
struct BUG {
LL out, in;
bool operator<(const BUG &t) const { return out < t.out; }
};
bool cmp(const BUG &a, const BUG &b) { return a.in > b.in; };
int n;
BUG bug[300001];
bool solve(int x) {
priority_queue<BUG> que;
LL sum = 0;
int i;
for (i = 0; i < x; i++) {
que.push(bug[i]);
sum += bug[i].out;
}
for (i--; i < n; i++) {
if (i >= x) {
que.push(bug[i]);
sum += bug[i].out;
BUG b = que.top();
que.pop();
sum -= b.out;
}
if (sum <= bug[i].in * x) {
return true;
}
}
return false;
}
/*
bool solve(int x)
{
int lim = x - 1;
while (true){
priority_queue<BUG> que;
for (int i = 0; i <= lim; i++){
que.push(bug[i]);
}
puts("");
LL sum = 0;
for (int i = 0; i < x; i++){
BUG b = que.top(); que.pop();
printf("%lld\n", b.out);
sum += b.out;
}
if (sum <= bug[lim].in * x) return true;
else {
lim++;
if (lim == n) return false;
}
}
}
*/
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%lld %lld", &bug[i].out, &bug[i].in);
}
sort(bug, bug + n, cmp);
int l = 1, r = n;
while (l <= r) {
int m = (l + r) / 2;
if (solve(m))
l = m + 1;
else
r = m - 1;
}
if (r == -1)
puts("0");
else
printf("%d\n", r);
return 0;
}
|
[["+", 0, 14, 8, 9, 0, 7, 10, 27, 28, 22], ["+", 0, 14, 8, 9, 0, 7, 10, 27, 17, 68], ["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 47], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 20]]
| 1
| 353
| 4
|
#include <bits/stdc++.h>
#define int long long int
#define F first
#define S second
#define MP make_pair
using namespace std;
typedef pair<int, int> PII;
typedef pair<int, PII> PIP;
int n;
PII ab[300010];
priority_queue<PIP> q;
int ans = 0;
struct segtree {
int tree[1048576];
int size;
void reset() {
size = 1;
while (size < n + 1) {
size <<= 1;
}
}
void add(int where, int value) {
int now = size - 1 + where;
while (true) {
tree[now] += value;
if (now == 0) {
break;
}
now = (now - 1) / 2;
}
}
int sum(int end, int left, int right, int now) {
if (end < left) {
return 0;
} else if (right <= end) {
return tree[now];
} else {
return sum(end, left, (left + right) / 2, now * 2 + 1) +
sum(end, (left + right) / 2 + 1, right, now * 2 + 2);
}
}
} tr_sum, tr_many;
bool judge(int mid, int nowb) {
if (tr_sum.sum(mid, 0, tr_sum.size - 1, 0) <=
nowb * tr_many.sum(mid, 0, tr_many.size - 1, 0)) {
return true;
}
return false;
}
int bs(int nowb) {
int bss = 0, bse = tr_many.size;
while (bse - bss > 1) {
int mid = (bss + bse) / 2;
if (judge(mid, nowb)) {
bss = mid;
} else {
bse = mid;
}
}
return tr_many.sum(bss, 0, tr_many.size - 1, 0);
}
signed main() {
scanf("%lld", &n);
for (int i = 1; i <= n; i++) {
scanf("%lld%lld", &ab[i].first, &ab[i].second);
}
sort(ab, ab + n);
for (int i = 1; i <= n; i++) {
q.push(MP(ab[i].S, MP(ab[i].F, i)));
}
tr_sum.reset();
tr_many.reset();
for (int i = 0; i < n; i++) {
PIP now = q.top();
q.pop();
tr_sum.add(now.S.S, now.S.F);
tr_many.add(now.S.S, 1);
ans = max(ans, bs(now.F));
}
printf("%lld\n", ans);
return 0;
}
|
#include <bits/stdc++.h>
#define int long long int
#define F first
#define S second
#define MP make_pair
using namespace std;
typedef pair<int, int> PII;
typedef pair<int, PII> PIP;
int n;
PII ab[300010];
priority_queue<PIP> q;
int ans = 0;
struct segtree {
int tree[1048576];
int size;
void reset() {
size = 1;
while (size < n + 1) {
size <<= 1;
}
}
void add(int where, int value) {
int now = size - 1 + where;
while (true) {
tree[now] += value;
if (now == 0) {
break;
}
now = (now - 1) / 2;
}
}
int sum(int end, int left, int right, int now) {
if (end < left) {
return 0;
} else if (right <= end) {
return tree[now];
} else {
return sum(end, left, (left + right) / 2, now * 2 + 1) +
sum(end, (left + right) / 2 + 1, right, now * 2 + 2);
}
}
} tr_sum, tr_many;
bool judge(int mid, int nowb) {
if (tr_sum.sum(mid, 0, tr_sum.size - 1, 0) <=
nowb * tr_many.sum(mid, 0, tr_many.size - 1, 0)) {
return true;
}
return false;
}
int bs(int nowb) {
int bss = 0, bse = tr_many.size;
while (bse - bss > 1) {
int mid = (bss + bse) / 2;
if (judge(mid, nowb)) {
bss = mid;
} else {
bse = mid;
}
}
return tr_many.sum(bss, 0, tr_many.size - 1, 0);
}
signed main() {
scanf("%lld", &n);
for (int i = 1; i <= n; i++) {
scanf("%lld%lld", &ab[i].first, &ab[i].second);
}
sort(ab + 1, ab + n + 1);
for (int i = 1; i <= n; i++) {
q.push(MP(ab[i].S, MP(ab[i].F, i)));
}
tr_sum.reset();
tr_many.reset();
for (int i = 1; i <= n; i++) {
PIP now = q.top();
q.pop();
tr_sum.add(now.S.S, now.S.F);
tr_many.add(now.S.S, 1);
ans = max(ans, bs(now.F));
}
printf("%lld\n", ans);
return 0;
}
|
[["+", 0, 1, 0, 2, 3, 4, 0, 16, 17, 72], ["+", 0, 1, 0, 2, 3, 4, 0, 16, 12, 13], ["-", 8, 9, 0, 7, 10, 43, 49, 50, 51, 13], ["+", 8, 9, 0, 7, 10, 43, 49, 50, 51, 13], ["-", 0, 14, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 14, 8, 9, 0, 7, 15, 16, 17, 19]]
| 1
| 585
| 8
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(), in.end()
#define shosu(x) fixed << setprecision(x)
using namespace std;
// kaewasuretyuui
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef pair<int, pii> pip;
typedef vector<pip> vip;
const double PI = acos(-1);
const double EPS = 1e-8;
const int inf = 1e8;
int main() {
int n;
cin >> n;
vp in(n);
rep(i, n) cin >> in[i].second >> in[i].first;
rep(i, n) in[i].first *= -1;
sort(all(in));
int l = 0, r = n + 1;
while (r - l > 1) {
int h = (l + r) / 2;
ll sum = 0;
priority_queue<int> q;
bool H = false;
rep(i, n) {
if (i < h) {
sum += in[i].second;
q.push(in[i].second);
} else {
int t = q.top();
q.pop();
sum += in[i].second - t;
q.push(in[i].second);
}
if (i >= h && sum <= (-in[i].first) * h)
H = true;
}
if (H)
l = h;
else
r = h;
}
cout << l << endl;
}
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(), in.end()
#define shosu(x) fixed << setprecision(x)
using namespace std;
// kaewasuretyuui
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef pair<int, pii> pip;
typedef vector<pip> vip;
const double PI = acos(-1);
const double EPS = 1e-8;
const int inf = 1e8;
int main() {
int n;
cin >> n;
vp in(n);
rep(i, n) cin >> in[i].second >> in[i].first;
rep(i, n) in[i].first *= -1;
sort(all(in));
int l = 0, r = n + 1;
while (r - l > 1) {
ll h = (l + r) / 2;
ll sum = 0;
priority_queue<int> q;
bool H = false;
rep(i, n) {
// cout<<l<<" "<<r<<" "<<sum<<endl;
if (i < h) {
sum += in[i].second;
q.push(in[i].second);
} else {
int t = q.top();
q.pop();
sum += in[i].second - t;
q.push(in[i].second);
}
if (i + 1 >= h && sum <= (-in[i].first) * h)
H = true;
}
if (H)
l = h;
else
r = h;
}
cout << l << endl;
}
|
[["-", 8, 9, 0, 52, 8, 9, 0, 43, 39, 40], ["+", 8, 9, 0, 52, 8, 9, 0, 43, 39, 78], ["+", 15, 339, 51, 16, 31, 16, 31, 16, 17, 72], ["+", 15, 339, 51, 16, 31, 16, 31, 16, 12, 13]]
| 1
| 380
| 4
|
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef pair<int, int> P;
struct BIT {
vector<long long> data;
int n;
BIT(int n) : n(n) { data.resize(n + 1); }
long long sum(int i) {
long long s = 0LL;
for (int x = i + 1; x > 0; x -= x & -x)
s += data[x];
return s;
}
void add(int i, long long v) {
for (int x = i + 1; x <= n; x += x & -x)
data[x] += v;
}
};
int N;
P A[300000], B[300000];
int main() {
cin >> N;
for (int i = 0; i < N; i++) {
int a, b;
cin >> a >> b;
A[i] = P(a, b);
}
sort(A, A + N);
BIT s(N), v(N);
for (int i = 0; i < N; i++) {
B[i] = P(A[i].second, i);
s.add(i, A[i].first);
v.add(i, 1);
}
sort(B, B + N);
int m = 0;
for (int i = 0; i < N; i++) {
int u = B[i].second;
long long b = A[u].second;
int lo = 0, hi = N + 1;
while (hi - lo > 1) {
int mid = (lo + hi) / 2;
if (s.sum(mid) <= b * v.sum(mid))
lo = mid;
else
hi = mid;
}
if (s.sum(lo) <= b * v.sum(lo)) {
m = max(m, (int)v.sum(lo));
}
s.add(u, -A[u].first);
v.add(u, -1);
}
cout << m << "\n";
return 0;
}
|
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef pair<int, int> P;
struct BIT {
vector<long long> data;
int n;
BIT(int n) : n(n) { data.resize(n + 1); }
long long sum(int i) {
long long s = 0LL;
for (int x = i + 1; x > 0; x -= x & -x)
s += data[x];
return s;
}
void add(int i, long long v) {
for (int x = i + 1; x <= n; x += x & -x)
data[x] += v;
}
};
int N;
P A[300000], B[300000];
int main() {
cin >> N;
for (int i = 0; i < N; i++) {
int a, b;
cin >> a >> b;
A[i] = P(a, b);
}
sort(A, A + N);
BIT s(N), v(N);
for (int i = 0; i < N; i++) {
B[i] = P(A[i].second, i);
s.add(i, A[i].first);
v.add(i, 1);
}
sort(B, B + N);
int m = 0;
for (int i = 0; i < N; i++) {
int u = B[i].second;
long long b = A[u].second;
int lo = 0, hi = N;
while (hi - lo > 1) {
int mid = (lo + hi) / 2;
if (s.sum(mid) <= b * v.sum(mid))
lo = mid;
else
hi = mid;
}
if (s.sum(lo) <= b * v.sum(lo)) {
m = max(m, (int)v.sum(lo));
}
s.add(u, -A[u].first);
v.add(u, -1);
}
cout << m << "\n";
return 0;
}
|
[["-", 8, 9, 0, 43, 49, 50, 51, 16, 17, 72], ["-", 8, 9, 0, 43, 49, 50, 51, 16, 12, 13]]
| 1
| 460
| 2
|
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
int n;
pair<int, int> p[300000];
bool ok(int t) {
priority_queue<int> Q;
ll sum = 0;
for (int i = n - 1; i >= n - t + 1; i--) {
Q.push(p[i].second);
sum += p[i].second;
}
for (int i = n - t; i >= 0; i--) {
if (p[i].first * (ll)t >= sum + p[i - 1].second)
return 1;
if (!Q.empty() && Q.top() > p[i].second) {
sum -= Q.top() - p[i].second;
Q.pop();
Q.push(p[i].second);
}
}
return 0;
}
int main() {
scanf("%d", &n);
rep(i, n) {
int a, b;
scanf("%d%d", &a, &b);
p[i] = {b, a};
}
sort(p, p + n);
int a = 0, b = n;
while (a != b) {
int t = (a + b) / 2;
if (b - a == 1)
t = b;
if (ok(t))
a = t;
else
b = t - 1;
}
printf("%d\n", a);
}
|
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
int n;
pair<int, int> p[300000];
bool ok(int t) {
priority_queue<int> Q;
ll sum = 0;
for (int i = n - 1; i >= n - t + 1; i--) {
Q.push(p[i].second);
sum += p[i].second;
}
for (int i = n - t; i >= 0; i--) {
if (p[i].first * (ll)t >= sum + p[i].second)
return 1;
if (!Q.empty() && Q.top() > p[i].second) {
sum -= Q.top() - p[i].second;
Q.pop();
Q.push(p[i].second);
}
}
return 0;
}
int main() {
scanf("%d", &n);
rep(i, n) {
int a, b;
scanf("%d%d", &a, &b);
p[i] = {b, a};
}
sort(p, p + n);
int a = 0, b = n;
while (a != b) {
int t = (a + b) / 2;
if (b - a == 1)
t = b;
if (ok(t))
a = t;
else
b = t - 1;
}
printf("%d\n", a);
}
|
[["-", 12, 118, 28, 69, 341, 342, 0, 16, 17, 33], ["-", 12, 118, 28, 69, 341, 342, 0, 16, 12, 13]]
| 1
| 331
| 42
|
#include <bits/stdc++.h>
#define P pair<int, int>
#define int long long
using namespace std;
P a[300000];
signed main() {
int b;
cin >> b;
for (int c = 0; c < b; c++) {
scanf("%lld%lld", &a[c].first, &a[c].second);
}
sort(a, a + b, [](P n, P m) {
if (n.first != m.first)
return n.first < m.first;
return n.second >= m.second;
});
double sum = 0;
int MIN = LLONG_MAX / 3;
auto k = [](P n, P m) {
if (n.first != m.first)
return n.first < m.first;
return n.second >= m.second;
};
priority_queue<P, vector<P>, decltype(k)> Q(k);
int MAX = 0;
for (int i = 0; i < b; i++) {
sum += a[i].first;
Q.push(P(a[i].second, a[i].first));
MIN = min(MIN, a[i].second);
while (sum / Q.size() > MIN) {
P t = Q.top();
Q.pop();
sum -= t.second;
if (Q.size() == 0) {
MIN = LLONG_MAX / 3;
break;
}
P w = Q.top();
MIN = w.first;
}
MAX = max(MAX, (int)Q.size());
}
cout << MAX << endl;
}
|
#include <bits/stdc++.h>
#define P pair<int, int>
#define int long long
using namespace std;
P a[300000];
signed main() {
int b;
cin >> b;
for (int c = 0; c < b; c++) {
scanf("%lld%lld", &a[c].first, &a[c].second);
}
sort(a, a + b, [](P n, P m) {
if (n.first != m.first)
return n.first < m.first;
return n.second >= m.second;
});
double sum = 0;
int MIN = LLONG_MAX / 3;
auto k = [](P n, P m) {
if (n.first != m.first)
return n.first > m.first;
return n.second <= m.second;
};
priority_queue<P, vector<P>, decltype(k)> Q(k);
int MAX = 0;
for (int i = 0; i < b; i++) {
sum += a[i].first;
Q.push(P(a[i].second, a[i].first));
MIN = min(MIN, a[i].second);
while (sum / Q.size() > MIN) {
P t = Q.top();
Q.pop();
sum -= t.second;
if (Q.size() == 0) {
MIN = LLONG_MAX / 3;
break;
}
P w = Q.top();
MIN = w.first;
}
MAX = max(MAX, (int)Q.size());
}
cout << MAX << endl;
}
|
[["-", 8, 9, 0, 57, 64, 37, 0, 16, 17, 18], ["+", 8, 9, 0, 57, 64, 37, 0, 16, 17, 47], ["-", 51, 218, 8, 9, 0, 37, 0, 16, 17, 20], ["+", 51, 218, 8, 9, 0, 37, 0, 16, 17, 19]]
| 1
| 351
| 4
|
#include <bits/stdc++.h>
using namespace std;
#define repl(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repl(i, 0, n)
#define mp(a, b) make_pair((a), (b))
#define pb(a) push_back((a))
#define all(x) (x).begin(), (x).end()
#define uniq(x) sort(all(x)), (x).erase(unique(all(x)), end(x))
#define fi first
#define se second
#define dbg(x) cout << #x " = " << ((x)) << endl
template <class T, class U>
ostream &operator<<(ostream &o, const pair<T, U> &p) {
o << "(" << p.fi << "," << p.se << ")";
return o;
}
template <class T> ostream &operator<<(ostream &o, const vector<T> &v) {
o << "[";
for (T t : v) {
o << t << ",";
}
o << "]";
return o;
}
#define INF 2147483600
int main() {
int n;
cin >> n;
vector<pair<long, long>> vec(n);
rep(i, n) cin >> vec[i].se >> vec[i].fi;
sort(all(vec), greater<pair<long, long>>());
int l = 0, r = n;
while (r - l > 1) {
int k = (r + l) / 2;
auto f = [&]() {
if (k == 0)
return true;
// fi:b, se:a
priority_queue<long> pq;
long acc = 0;
rep(i, k) {
pq.push(vec[i].se);
acc += vec[i].se;
}
if (acc <= k * vec[k - 1].fi)
return true;
repl(i, k, n) {
long mx = pq.top();
pq.pop();
acc -= mx;
pq.push(min(mx, vec[i].se));
acc += min(mx, vec[i].se);
if (acc <= k * vec[i].fi)
return true;
}
return false;
};
if (f())
l = k;
else
r = k;
}
cout << l << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define repl(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repl(i, 0, n)
#define mp(a, b) make_pair((a), (b))
#define pb(a) push_back((a))
#define all(x) (x).begin(), (x).end()
#define uniq(x) sort(all(x)), (x).erase(unique(all(x)), end(x))
#define fi first
#define se second
#define dbg(x) cout << #x " = " << ((x)) << endl
template <class T, class U>
ostream &operator<<(ostream &o, const pair<T, U> &p) {
o << "(" << p.fi << "," << p.se << ")";
return o;
}
template <class T> ostream &operator<<(ostream &o, const vector<T> &v) {
o << "[";
for (T t : v) {
o << t << ",";
}
o << "]";
return o;
}
#define INF 2147483600
int main() {
int n;
cin >> n;
vector<pair<long, long>> vec(n);
rep(i, n) cin >> vec[i].se >> vec[i].fi;
sort(all(vec), greater<pair<long, long>>());
int l = 0, r = n + 1;
while (r - l > 1) {
int k = (r + l) / 2;
auto f = [&]() {
if (k == 0)
return true;
// fi:b, se:a
priority_queue<long> pq;
long acc = 0;
rep(i, k) {
pq.push(vec[i].se);
acc += vec[i].se;
}
if (acc <= k * vec[k - 1].fi)
return true;
repl(i, k, n) {
long mx = pq.top();
pq.pop();
acc -= mx;
pq.push(min(mx, vec[i].se));
acc += min(mx, vec[i].se);
if (acc <= k * vec[i].fi)
return true;
}
return false;
};
if (f())
l = k;
else
r = k;
}
cout << l << endl;
return 0;
}
|
[["+", 8, 9, 0, 43, 49, 50, 51, 16, 17, 72], ["+", 8, 9, 0, 43, 49, 50, 51, 16, 12, 13]]
| 1
| 457
| 2
|
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(a) a.begin(), a.end()
typedef long long ll;
typedef pair<int, int> Bug;
vector<Bug> bug;
int N;
int solve(int l, int r) {
if (l + 1 == r)
return l;
int k = (l + r) / 2;
ll sumA = 0;
priority_queue<int> pq;
rep(i, k) {
sumA += bug[i].second;
pq.push(bug[i].second);
}
if (sumA <= (ll)k * bug[k - 1].first) {
return solve(k, r);
}
for (int i = k; i < N; i++) {
int d = pq.top() - bug[i].second;
if (d > 0) {
sumA -= d;
pq.pop();
pq.push(bug[i].second);
if (sumA <= (ll)k * bug[i].first) {
return solve(k, r);
}
}
}
return solve(l, k);
}
int main(void) {
cin >> N;
bug.resize(N);
rep(i, N) cin >> bug[i].second >> bug[i].first;
sort(all(bug), greater<Bug>());
cout << solve(0, N) << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(a) a.begin(), a.end()
typedef long long ll;
typedef pair<int, int> Bug;
vector<Bug> bug;
int N;
int solve(int l, int r) {
if (l + 1 == r)
return l;
int k = (l + r) / 2;
ll sumA = 0;
priority_queue<int> pq;
rep(i, k) {
sumA += bug[i].second;
pq.push(bug[i].second);
}
if (sumA <= (ll)k * bug[k - 1].first) {
return solve(k, r);
}
for (int i = k; i < N; i++) {
int d = pq.top() - bug[i].second;
if (d > 0) {
sumA -= d;
pq.pop();
pq.push(bug[i].second);
if (sumA <= (ll)k * bug[i].first) {
return solve(k, r);
}
}
}
return solve(l, k);
}
int main(void) {
cin >> N;
bug.resize(N);
rep(i, N) cin >> bug[i].second >> bug[i].first;
sort(all(bug), greater<Bug>());
cout << solve(0, N + 1) << endl;
return 0;
}
|
[["+", 31, 16, 12, 2, 3, 4, 0, 16, 17, 72], ["+", 31, 16, 12, 2, 3, 4, 0, 16, 12, 13]]
| 1
| 310
| 2
|
#include <algorithm>
#include <cstdio>
#include <set>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
int n, hp[100000], emit[100000];
// num 匹の微生物を生かせるかを判定
bool check(int num) {
multiset<int> S;
ll emit_sum = 0;
for (int i = n - 1; i >= 0; i--) { // 生かす微生物の最小 HP を決めうち
emit_sum += emit[i];
S.insert(emit[i]);
if (S.size() < num)
continue;
if (S.size() > num) { // S.size()==num+1
emit_sum -= *S.rbegin();
S.erase(--S.end());
}
if ((ll)num * hp[i] >= emit_sum)
return true;
}
return false;
}
int main() {
scanf("%d", &n);
static pair<int, int> tmp[100000];
rep(i, n) scanf("%d%d", &tmp[i].first, &tmp[i].second);
sort(tmp, tmp + n);
rep(i, n) {
hp[i] = tmp[i].first;
emit[i] = tmp[i].second;
}
int lo = 0, hi = n;
while (lo < hi) {
int mi = (lo + hi + 1) / 2;
if (check(mi))
lo = mi;
else
hi = mi - 1;
}
printf("%d\n", lo);
return 0;
}
|
// O(n log^2 n)
#include <algorithm>
#include <cstdio>
#include <set>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
int n, hp[300000], emit[300000];
// num 匹の微生物を生かせるかを判定
bool check(int num) {
multiset<int> S;
ll emit_sum = 0;
for (int i = n - 1; i >= 0; i--) { // 生かす微生物の最小 HP を決めうち
emit_sum += emit[i];
S.insert(emit[i]);
if (S.size() < num)
continue;
if (S.size() > num) { // S.size()==num+1
// emit が一番大きい微生物は使わない
emit_sum -= *S.rbegin();
S.erase(--S.end());
}
if ((ll)num * hp[i] >= emit_sum)
return true;
}
return false;
}
int main() {
scanf("%d", &n);
static pair<int, int> tmp[300000];
rep(i, n) scanf("%d%d", &tmp[i].second, &tmp[i].first);
sort(tmp, tmp + n);
rep(i, n) {
hp[i] = tmp[i].first;
emit[i] = tmp[i].second;
}
int lo = 0, hi = n;
while (lo < hi) {
int mi = (lo + hi + 1) / 2;
if (check(mi))
lo = mi;
else
hi = mi - 1;
}
printf("%d\n", lo);
return 0;
}
|
[["-", 36, 36, 0, 30, 0, 43, 49, 80, 81, 13], ["+", 36, 36, 0, 30, 0, 43, 49, 80, 81, 13], ["-", 0, 14, 8, 9, 0, 43, 49, 80, 81, 13], ["+", 0, 14, 8, 9, 0, 43, 49, 80, 81, 13], ["-", 0, 2, 3, 4, 0, 66, 28, 118, 119, 120], ["+", 0, 2, 3, 4, 0, 66, 28, 118, 119, 120]]
| 1
| 318
| 10
|
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <vector>
using namespace std;
#define REP0(i, n) for (int i = 0; i < n; ++i)
#define REP1(i, n) for (int i = 1; i <= n; ++i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef pair<int, int> P;
struct bg {
ll a, b, num;
}; // num=aのソートでの順番
bool sorta(const bg &l, const bg &r) {
return l.a == r.a ? l.b < r.b : l.a < r.a;
}
bool sortbinv(const bg &l, const bg &r) {
return l.b == r.b ? l.a < r.a : l.b > r.b;
}
ll segsum[1 << 20];
int segcnt[1 << 20];
vector<bg> bug;
void update(int id) {
int l = id * 2 + 1, r = id * 2 + 2;
segsum[id] = segsum[l] + segsum[r];
segcnt[id] = segcnt[l] + segcnt[r];
if (id == 0)
return;
update((id - 1) / 2);
}
ll sum(int x, int y, int l, int r, int id) {
if (y <= l || r <= x)
return 0;
if (x <= l && r <= y)
return segsum[id];
return sum(x, y, l, (l + r) / 2, id * 2 + 1) +
sum(x, y, (l + r) / 2, r, id * 2 + 2);
}
int cnt(int x, int y, int l, int r, int id) {
if (y <= l || r <= x)
return 0;
if (x <= l && r <= y)
return segcnt[id];
return cnt(x, y, l, (l + r) / 2, id * 2 + 1) +
cnt(x, y, (l + r) / 2, r, id * 2 + 2);
}
int main() {
int n, p2 = 1, ans = -1;
scanf("%d", &n);
while (p2 < n)
p2 *= 2;
REP0(i, n) {
ll a, b;
scanf("%lld%lld", &a, &b);
bg hoge = {a, b, 0};
bug.push_back(hoge);
}
sort(ALL(bug), sorta);
REP0(i, n) bug[i].num = i;
sort(ALL(bug), sortbinv);
REP0(i, n) {
int p = p2 - 1 + bug[i].num;
segsum[p] = bug[i].a;
segcnt[p] = 1;
update((p - 1) / 2);
int ub = n, lb = 0;
while (ub - lb > 1) {
int mid = (ub + lb) / 2;
if (sum(0, mid, 0, p2, 0) <= bug[i].b * cnt(0, mid, 0, p2, 0))
lb = mid;
else
ub = mid;
}
ans = max(ans, cnt(0, lb, 0, p2, 0));
}
printf("%d\n", ans);
return 0;
}
|
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <vector>
using namespace std;
#define REP0(i, n) for (int i = 0; i < n; ++i)
#define REP1(i, n) for (int i = 1; i <= n; ++i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef pair<int, int> P;
struct bg {
ll a, b, num;
}; // num=aのソートでの順番
bool sorta(const bg &l, const bg &r) {
return l.a == r.a ? l.b < r.b : l.a < r.a;
}
bool sortbinv(const bg &l, const bg &r) {
return l.b == r.b ? l.a < r.a : l.b > r.b;
}
ll segsum[1 << 20];
int segcnt[1 << 20];
vector<bg> bug;
void update(int id) {
int l = id * 2 + 1, r = id * 2 + 2;
segsum[id] = segsum[l] + segsum[r];
segcnt[id] = segcnt[l] + segcnt[r];
if (id == 0)
return;
update((id - 1) / 2);
}
ll sum(int x, int y, int l, int r, int id) {
if (y <= l || r <= x)
return 0;
if (x <= l && r <= y)
return segsum[id];
return sum(x, y, l, (l + r) / 2, id * 2 + 1) +
sum(x, y, (l + r) / 2, r, id * 2 + 2);
}
int cnt(int x, int y, int l, int r, int id) {
if (y <= l || r <= x)
return 0;
if (x <= l && r <= y)
return segcnt[id];
return cnt(x, y, l, (l + r) / 2, id * 2 + 1) +
cnt(x, y, (l + r) / 2, r, id * 2 + 2);
}
int main() {
int n, p2 = 1, ans = -1;
scanf("%d", &n);
while (p2 < n)
p2 *= 2;
REP0(i, n) {
ll a, b;
scanf("%lld%lld", &a, &b);
bg hoge = {a, b, 0};
bug.push_back(hoge);
}
sort(ALL(bug), sorta);
REP0(i, n) bug[i].num = i;
sort(ALL(bug), sortbinv);
REP0(i, n) {
int p = p2 - 1 + bug[i].num;
segsum[p] = bug[i].a;
segcnt[p] = 1;
update((p - 1) / 2);
int ub = n + 1, lb = 0;
while (ub - lb > 1) {
int mid = (ub + lb) / 2;
if (sum(0, mid, 0, p2, 0) <= bug[i].b * cnt(0, mid, 0, p2, 0))
lb = mid;
else
ub = mid;
}
ans = max(ans, cnt(0, lb, 0, p2, 0));
}
printf("%d\n", ans);
return 0;
}
|
[["+", 8, 9, 0, 43, 49, 50, 51, 16, 17, 72], ["+", 8, 9, 0, 43, 49, 50, 51, 16, 12, 13]]
| 1
| 706
| 2
|
import java.util.*;
public class Main {
public static void main(String[] args) {
int pasta[] = new int[3];
int juice[] = new int[2];
Scanner sc = new Scanner(System.in);
for (int i = 0; i < 3; i++) {
pasta[i] = sc.nextInt();
}
for (int i = 0; i < 2; i++) {
juice[i] = sc.nextInt();
}
int minp = 3000;
for (int i = 0; i < 3; i++) {
if (minp < pasta[i]) {
minp = pasta[i];
}
}
int minj = 3000;
for (int i = 0; i < 2; i++) {
if (minj < juice[i]) {
minj = juice[i];
}
}
int sum = minp + minj;
sum = sum - 50;
System.out.println(sum);
}
}
|
import java.util.*;
public class Main {
public static void main(String[] args) {
int pasta[] = new int[3];
int juice[] = new int[2];
Scanner sc = new Scanner(System.in);
for (int i = 0; i < 3; i++) {
pasta[i] = sc.nextInt();
}
for (int i = 0; i < 2; i++) {
juice[i] = sc.nextInt();
}
int minp = 3000;
for (int i = 0; i < 3; i++) {
if (minp > pasta[i]) {
minp = pasta[i];
}
}
int minj = 3000;
for (int i = 0; i < 2; i++) {
if (minj > juice[i]) {
minj = juice[i];
}
}
int sum = minp + minj;
sum = sum - 50;
System.out.println(sum);
}
}
|
[["-", 8, 196, 0, 57, 15, 15, 0, 16, 17, 18], ["+", 8, 196, 0, 57, 15, 15, 0, 16, 17, 47]]
| 3
| 211
| 4
|
import java.util.Scanner;
class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int men[] = new int[3];
int nomi[] = new int[2];
for (int i = 0; i < 3; i++) {
men[i] = sc.nextInt();
}
for (int j = 0; j < 2; j++) {
nomi[j] = sc.nextInt();
}
int taihi, taihi2;
for (int i = 0; i < 3; i++) {
for (int k = i + 1; k < 3; k++) {
if (men[i] > men[k]) {
taihi = men[i];
men[i] = men[k];
men[k] = taihi;
}
}
}
for (int i = 0; i < 2; i++) {
for (int k = i + 1; k < 2; k++) {
if (nomi[i] > nomi[k]) {
taihi2 = nomi[i];
nomi[i] = nomi[k];
nomi[k] = taihi2;
}
}
}
int a = men[0] + nomi[0];
System.out.println(a);
}
}
|
import java.util.Scanner;
class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int men[] = new int[3];
int nomi[] = new int[2];
for (int i = 0; i < 3; i++) {
men[i] = sc.nextInt();
}
for (int j = 0; j < 2; j++) {
nomi[j] = sc.nextInt();
}
int taihi, taihi2;
for (int i = 0; i < 3; i++) {
for (int k = i + 1; k < 3; k++) {
if (men[i] > men[k]) {
taihi = men[i];
men[i] = men[k];
men[k] = taihi;
}
}
}
for (int i = 0; i < 2; i++) {
for (int k = i + 1; k < 2; k++) {
if (nomi[i] > nomi[k]) {
taihi2 = nomi[i];
nomi[i] = nomi[k];
nomi[k] = taihi2;
}
}
}
int a = men[0] + nomi[0] - 50;
System.out.println(a);
}
}
|
[["+", 8, 196, 0, 503, 49, 200, 51, 16, 17, 33], ["+", 8, 196, 0, 503, 49, 200, 51, 16, 12, 499]]
| 3
| 281
| 2
|
#include <stdio.h>
int main(void) {
int ne[6];
int ans[2];
int i;
for (i = 0; i < 5; i++) {
scanf("%d", &ne[i]);
}
if (ne[0] < ne[1] && ne[0] < ne[2])
ans[0] = ne[0];
if (ne[1] < ne[0] && ne[1] < ne[2])
ans[0] = ne[1];
else
ans[0] = ne[2];
if (ne[3] < ne[4])
ans[1] = ne[3];
else
ans[1] = ne[4];
printf("%d\n", ans[0] + ans[1] - 50);
return 0;
}
|
#include <stdio.h>
int main(void) {
int ne[6];
int ans[2];
int i;
for (i = 0; i < 5; i++) {
scanf("%d", &ne[i]);
}
if (ne[0] < ne[1] && ne[0] < ne[2])
ans[0] = ne[0];
else if (ne[1] < ne[0] && ne[1] < ne[2])
ans[0] = ne[1];
else
ans[0] = ne[2];
if (ne[3] < ne[4])
ans[1] = ne[3];
else
ans[1] = ne[4];
printf("%d\n", ans[0] + ans[1] - 50);
return 0;
}
|
[["+", 0, 14, 8, 9, 0, 57, 75, 76, 0, 95]]
| 0
| 183
| 1
|
#include <stdio.h>
int min(int a, int b) {
if (a < b)
return a;
else
return b;
}
int main() {
int P = 10000, p, J = 10000, j, i;
for (i = 0; i < 3; i++) {
scanf("%d", &p);
P = min(P, p);
}
for (i = 0; i < 2; i++) {
scanf("%d", &j);
J = min(J, j);
}
printf("%d\n", P + J);
return 0;
}
|
#include <stdio.h>
int min(int a, int b) {
if (a < b)
return a;
else
return b;
}
int main() {
int P = 10000, p, J = 10000, j, i;
for (i = 0; i < 3; i++) {
scanf("%d", &p);
P = min(P, p);
}
for (i = 0; i < 2; i++) {
scanf("%d", &j);
J = min(J, j);
}
printf("%d\n", P + J - 50);
return 0;
}
|
[["+", 0, 1, 0, 2, 3, 4, 0, 16, 17, 33], ["+", 0, 1, 0, 2, 3, 4, 0, 16, 12, 13]]
| 0
| 130
| 2
|
#include <stdio.h>
int main(void) {
int p[3], j[2];
int i, n;
int min = 5000;
for (i = 0; i < 3; i++) {
scanf("%d", &p[i]);
}
for (i = 0; i < 2; i++) {
scanf("%d", &j[i]);
}
for (i = 0; i < 3; i++) {
for (n = 0; n < 2; n++) {
if (min > p[i] + j[n])
min = p[i] + j[n];
else
;
}
}
printf("%d\n", min);
return 0;
}
|
#include <stdio.h>
int main(void) {
int p[3], j[2];
int i, n;
int min = 5000;
for (i = 0; i < 3; i++) {
scanf("%d", &p[i]);
}
for (i = 0; i < 2; i++) {
scanf("%d", &j[i]);
}
for (i = 0; i < 3; i++) {
for (n = 0; n < 2; n++) {
if (min > p[i] + j[n])
min = p[i] + j[n];
else
;
}
}
printf("%d\n", min - 50);
return 0;
}
|
[["+", 0, 1, 0, 2, 3, 4, 0, 16, 17, 33], ["+", 0, 1, 0, 2, 3, 4, 0, 16, 12, 13]]
| 0
| 157
| 2
|
#include <stdio.h>
int main(void) {
int pas[3], lpas, ju[2], lju, i, j;
for (i = 0; i < 3; i++) {
scanf("%d", &pas[i]);
if (i == 0)
lpas = pas[0];
if (lpas > pas[i])
lpas = pas[i];
}
for (j = 0; j < 2; j++) {
scanf("%d", &ju[j]);
if (j == 0)
lju = ju[0];
if (lju > ju[i])
lju = ju[i];
}
printf("%d\n", lpas + lju - 50);
return 0;
}
|
#include <stdio.h>
int main(void) {
int pas[3], lpas, ju[2], lju, i, j;
for (i = 0; i < 3; i++) {
scanf("%d", &pas[i]);
if (i == 0)
lpas = pas[0];
if (lpas > pas[i])
lpas = pas[i];
}
for (j = 0; j < 2; j++) {
scanf("%d", &ju[j]);
if (j == 0)
lju = ju[0];
if (lju > ju[j])
lju = ju[j];
}
printf("%d\n", lpas + lju - 50);
return 0;
}
|
[["-", 0, 57, 15, 23, 0, 16, 12, 69, 71, 22], ["+", 0, 57, 15, 23, 0, 16, 12, 69, 71, 22], ["-", 0, 57, 64, 1, 0, 11, 12, 69, 71, 22], ["+", 0, 57, 64, 1, 0, 11, 12, 69, 71, 22]]
| 0
| 159
| 4
|
#include <stdio.h>
int main(void) {
int pas[3], ju1, ju2, i, box1, box2;
for (i = 0; i < 3; i++)
scanf("%d", &pas[i]);
scanf("%d%d", &ju1, &ju2);
if (pas[0] < pas[1] && pas[0] < pas[2])
box1 = pas[0];
if (pas[0] < pas[1] && pas[0] > pas[2])
box1 = pas[2];
if (pas[0] > pas[1] && pas[0] < pas[2])
box1 = pas[1];
else {
if (pas[1] < pas[2])
box1 = pas[1];
else
box1 = pas[2];
}
if (ju1 < ju2)
box2 = ju1;
else
box2 = ju2;
printf("%d\n", box1 + box2 - 50);
return 0;
}
|
#include <stdio.h>
int main(void) {
int pas[3], ju1, ju2, i, box1, box2;
for (i = 0; i < 3; i++)
scanf("%d", &pas[i]);
scanf("%d%d", &ju1, &ju2);
if (pas[0] < pas[1] && pas[0] < pas[2])
box1 = pas[0];
else if (pas[0] < pas[1] && pas[0] > pas[2])
box1 = pas[2];
else if (pas[0] > pas[1] && pas[0] < pas[2])
box1 = pas[1];
else {
if (pas[1] < pas[2])
box1 = pas[1];
else
box1 = pas[2];
}
if (ju1 < ju2)
box2 = ju1;
else
box2 = ju2;
printf("%d\n", box1 + box2 - 50);
return 0;
}
|
[["+", 0, 14, 8, 9, 0, 57, 75, 76, 0, 95], ["+", 0, 57, 75, 76, 0, 57, 75, 76, 0, 95]]
| 0
| 213
| 2
|
#include <stdio.h>
int main(void) {
int a, b, c, x, y, m, n, sum;
scanf("%d %d %d %d %d", &a, &b, &c, &x, &y);
if (a <= b)
m = a;
else if (b <= c)
m = b;
else
m = c;
if (x <= y)
n = x;
else
n = y;
sum = m + n - 50;
printf("%d\n", sum);
return 0;
}
|
#include <stdio.h>
int main(void) {
int a, b, c, x, y, m, n, sum;
scanf("%d %d %d %d %d", &a, &b, &c, &x, &y);
if (a <= b && a <= c)
m = a;
else if (b <= c)
m = b;
else
m = c;
if (x <= y)
n = x;
else
n = y;
sum = m + n - 50;
printf("%d\n", sum);
return 0;
}
|
[["+", 8, 9, 0, 57, 15, 23, 0, 16, 17, 98], ["+", 0, 57, 15, 23, 0, 16, 12, 16, 31, 22], ["+", 0, 57, 15, 23, 0, 16, 12, 16, 17, 19], ["+", 0, 57, 15, 23, 0, 16, 12, 16, 12, 22]]
| 0
| 110
| 4
|
#include <stdio.h>
int main(void) {
int a, b, c;
scanf("%d%d%d%d%d", &a, &b, &c);
if (a > b) {
a = b;
}
if (a > c) {
a = c;
}
scanf("%d%d%d", &b, &c);
if (b > c) {
b = c;
}
printf("%d\n", a + b - 50);
return 0;
}
|
#include <stdio.h>
int main(void) {
int a, b, c;
scanf("%d%d%d", &a, &b, &c);
if (a > b) {
a = b;
}
if (a > c) {
a = c;
}
scanf("%d%d", &b, &c);
if (b > c) {
b = c;
}
printf("%d\n", a + b - 50);
return 0;
}
|
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
| 0
| 98
| 4
|
a;
main(b, c, d, e) {
scanf("%d%d%d%d%d", &a, &b, &c, &d, &e);
a = !printf("%d\n", ((c < (a < b ? a : b) ? c
: a < b
? a
: b) + d <
e
? d
: e) -
50);
}
|
a;
main(b, c, d, e) {
scanf("%d%d%d%d%d", &a, &b, &c, &d, &e);
a = !printf("%d\n",
((c < (a < b ? a : b) ? c : (a < b ? a : b)) + (d < e ? d : e)) -
50);
}
|
[["+", 0, 16, 31, 23, 0, 41, 75, 23, 0, 24], ["+", 0, 16, 31, 23, 0, 41, 75, 23, 0, 25], ["+", 0, 16, 31, 23, 0, 16, 12, 23, 0, 24], ["+", 0, 16, 31, 23, 0, 16, 12, 23, 0, 25]]
| 0
| 84
| 4
|
#include <stdio.h>
int main(void) {
int a, b, c, d, e, f, g, h;
scanf("%d%d%d%d%d", &a, &b, &c, &d, &e);
if (a <= b && b <= c) {
f = a;
} else if (a <= c && c <= b) {
f = a;
} else if (b <= c && c <= a) {
f = b;
} else if (b <= a && a <= c) {
f = b;
} else if (c <= a && a <= b) {
f = c;
} else if (c <= b && b <= a) {
f = c;
}
if (d < e) {
g = d;
} else if (e < d) {
g = e;
}
h = f + g - 50;
printf("%d\n", h);
return 0;
}
|
#include <stdio.h>
int main(void) {
int a, b, c, d, e, f, g, h;
scanf("%d%d%d%d%d", &a, &b, &c, &d, &e);
if (a <= b && b <= c) {
f = a;
} else if (a <= c && c <= b) {
f = a;
} else if (b <= c && c <= a) {
f = b;
} else if (b <= a && a <= c) {
f = b;
} else if (c <= a && a <= b) {
f = c;
} else if (c <= b && b <= a) {
f = c;
}
if (d <= e) {
g = d;
} else if (e <= d) {
g = e;
}
h = f + g - 50;
printf("%d\n", h);
return 0;
}
|
[["-", 8, 9, 0, 57, 15, 23, 0, 16, 17, 18], ["+", 8, 9, 0, 57, 15, 23, 0, 16, 17, 19], ["-", 75, 76, 0, 57, 15, 23, 0, 16, 17, 18], ["+", 75, 76, 0, 57, 15, 23, 0, 16, 17, 19]]
| 0
| 195
| 4
|
#include <stdio.h>
int main(void) {
int a[5], i, t, u;
for (i = 0; i < 5; i++) {
scanf("%d", &a[i]);
}
if (a[0] < a[1] && a[0] < a[2]) {
t = a[0];
} else if (a[1] < a[0] && a[1] < a[2]) {
t = a[1];
} else {
t = a[2];
}
if (a[3] < a[4]) {
u = a[3];
} else {
u = a[4];
}
printf("%d\n", t + u);
return 0;
}
|
#include <stdio.h>
int main(void) {
int a[5], i, t, u;
for (i = 0; i < 5; i++) {
scanf("%d", &a[i]);
}
if (a[0] < a[1] && a[0] < a[2]) {
t = a[0];
} else if (a[1] < a[0] && a[1] < a[2]) {
t = a[1];
} else {
t = a[2];
}
if (a[3] < a[4]) {
u = a[3];
} else {
u = a[4];
}
printf("%d\n", t + u - 50);
return 0;
}
|
[["+", 0, 1, 0, 2, 3, 4, 0, 16, 17, 33], ["+", 0, 1, 0, 2, 3, 4, 0, 16, 12, 13]]
| 0
| 168
| 2
|
#include <stdio.h>
int main(void) {
int pasta[3];
int juice[2];
int pastaMin;
int juiceMin;
int i;
pastaMin = 2001;
for (i = 0; i < 3; i++) {
scanf("%d", &pasta[i]);
if (pastaMin < pasta[i]) {
pastaMin = pasta[i];
}
}
juiceMin = 2001;
for (i = 0; i < 2; i++) {
scanf("%d", &juice[i]);
if (juiceMin < juice[i]) {
juiceMin = juice[i];
}
}
printf("%d\n", pastaMin + juiceMin - 50);
return (0);
}
|
#include <stdio.h>
int main(void) {
int pasta[3];
int juice[2];
int pastaMin;
int juiceMin;
int i;
pastaMin = 2001;
for (i = 0; i < 3; i++) {
scanf("%d", &pasta[i]);
if (pastaMin > pasta[i]) {
pastaMin = pasta[i];
}
}
juiceMin = 2001;
for (i = 0; i < 2; i++) {
scanf("%d", &juice[i]);
if (juiceMin > juice[i]) {
juiceMin = juice[i];
}
}
printf("%d\n", pastaMin + juiceMin - 50);
return (0);
}
|
[["-", 8, 9, 0, 57, 15, 23, 0, 16, 17, 18], ["+", 8, 9, 0, 57, 15, 23, 0, 16, 17, 47]]
| 0
| 149
| 4
|
i;
a[9];
b = 1e5;
main(j) {
for (; i - 5;)
scanf("%d", a + i++);
for (i = -1; ++i - 5; b = b > j ? j : b)
j = a[i % 3] + a[3 + i / 3] - 50;
printf("%d", b);
return 0;
}
|
i;
a[9];
b = 1e5;
main(j) {
for (; i - 5;)
scanf("%d", a + i++);
for (i = -1; ++i - 6; b = b > j ? j : b)
j = a[i % 3] + a[3 + i / 3] - 50;
printf("%d\n", b);
return 0;
}
|
[["-", 0, 14, 8, 9, 0, 7, 15, 16, 12, 13], ["+", 0, 14, 8, 9, 0, 7, 15, 16, 12, 13], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 44]]
| 0
| 90
| 3
|
#define m(a, b) a < b ? a : b
main(a, b, c, d, e) {
scanf("%d%d%d%d%d", &a, &b, &c, &d, &e);
b = m(a, b);
printf("%d\n", m(b, c) + m(d, e) - 50);
return 0;
}
|
#define m(a, b) (a < b ? a : b)
main(a, b, c, d, e) {
scanf("%d%d%d%d%d", &a, &b, &c, &d, &e);
b = m(a, b);
printf("%d\n", m(b, c) + m(d, e) - 50);
return 0;
}
|
[["-", 36, 36, 36, 36, 0, 30, 0, 112, 51, 59], ["+", 36, 36, 36, 36, 0, 30, 0, 112, 51, 59]]
| 0
| 81
| 2
|
#include <stdio.h>
int main() {
int a, b, c, d, e;
scanf("%d%d%d%d%d", &a, &b, &c, &d, &e);
a = a > b ? b : a > c ? c : a;
d = d > e ? e : d;
printf("%d\n", -50 + a + d);
return 0;
}
|
#include <stdio.h>
int main() {
int a, b, c, d, e;
scanf("%d%d%d%d%d", &a, &b, &c, &d, &e);
a = a > b ? b > c ? c : b : a > c ? c : a;
d = d > e ? e : d;
printf("%d\n", -50 + a + d);
return 0;
}
|
[["+", 0, 11, 12, 41, 64, 41, 15, 16, 17, 47], ["+", 0, 11, 12, 41, 64, 41, 15, 16, 12, 22], ["+", 0, 1, 0, 11, 12, 41, 64, 41, 0, 101], ["+", 0, 1, 0, 11, 12, 41, 64, 41, 64, 22], ["+", 0, 1, 0, 11, 12, 41, 64, 41, 0, 102], ["+", 0, 1, 0, 11, 12, 41, 64, 41, 75, 22]]
| 0
| 84
| 6
|
#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;
int n, k;
int dp[102][4][2];
int yt[102];
void debug() {
for (int d = 0; d <= n; d++) {
printf("%2d ", d);
for (int i = 1; i <= 3; i++) {
printf("(%5d,%5d) ", d, dp[d][i][0], dp[d][i][1]);
}
cout << endl;
}
}
int solve() {
if (yt[1] == 0) {
dp[1][1][0] = dp[1][2][0] = dp[1][3][0] = 1;
} else {
dp[1][yt[1]][0] = 1;
}
for (int d = 2; d <= n; d++) {
for (int i = 1; i <= 3; i++) {
if (yt[d] != 0 && yt[d] != i) {
dp[d][i][0] = dp[d][i][1] = 0;
continue;
}
dp[d][i][1] = dp[d - 1][i][0] % 10000;
dp[d][i][0] = 0;
for (int j = 1; j <= 3; j++) {
if (i == j)
continue;
dp[d][i][0] += (dp[d - 1][j][0] + dp[d - 1][j][1]) % 10000;
}
}
}
int ans = 0;
debug();
for (int i = 1; i <= 3; i++) {
ans += (dp[n][i][0] + dp[n][i][1]) % 10000;
}
return ans % 10000;
}
int main() {
cin >> n >> k;
int a, b;
for (int i = 0; i < k; i++) {
cin >> a >> b;
yt[a] = b;
}
cout << solve() << endl;
}
|
#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;
int n, k;
int dp[102][4][2];
int yt[102];
void debug() {
for (int d = 0; d <= n; d++) {
printf("%2d ", d);
for (int i = 1; i <= 3; i++) {
printf("(%5d,%5d) ", d, dp[d][i][0], dp[d][i][1]);
}
cout << endl;
}
}
int solve() {
if (yt[1] == 0) {
dp[1][1][0] = dp[1][2][0] = dp[1][3][0] = 1;
} else {
dp[1][yt[1]][0] = 1;
}
for (int d = 2; d <= n; d++) {
for (int i = 1; i <= 3; i++) {
if (yt[d] != 0 && yt[d] != i) {
dp[d][i][0] = dp[d][i][1] = 0;
continue;
}
dp[d][i][1] = dp[d - 1][i][0] % 10000;
dp[d][i][0] = 0;
for (int j = 1; j <= 3; j++) {
if (i == j)
continue;
dp[d][i][0] += (dp[d - 1][j][0] + dp[d - 1][j][1]) % 10000;
}
}
}
int ans = 0;
for (int i = 1; i <= 3; i++) {
ans += (dp[n][i][0] + dp[n][i][1]) % 10000;
}
return ans % 10000;
}
int main() {
cin >> n >> k;
int a, b;
for (int i = 0; i < k; i++) {
cin >> a >> b;
yt[a] = b;
}
cout << solve() << endl;
}
|
[["-", 0, 14, 8, 9, 0, 1, 0, 2, 63, 22], ["-", 8, 9, 0, 1, 0, 2, 3, 4, 0, 24], ["-", 8, 9, 0, 1, 0, 2, 3, 4, 0, 25], ["-", 0, 30, 0, 14, 8, 9, 0, 1, 0, 35]]
| 1
| 478
| 4
|
#include <iostream>
#include <string.h>
using namespace std;
int dp[101][4][4]; //何日目から、どのぱすたを、何日連続で食べているか
int plan[101]; //先に決められている予定 要素:日付
#define MOD 10000;
int main(void) {
int day;
int k;
cin >> day >> k;
memset(plan, 0, sizeof(plan));
for (int i = 0; i < k; ++i) {
int d, p;
cin >> d >> p;
plan[d] = p;
}
memset(dp, 0, sizeof(dp));
for (int i = 1; i <= 3; ++i) {
if (plan[1] != 0)
dp[1][plan[1]][1] = 1;
else
dp[1][i][1] = 1;
}
for (int d = 2; d <= day; ++d) { //どの日から?
for (int p = 1; p <= 3; ++p) { //どのパスタを?
if (plan[d]) {
dp[d][plan[d]][1] =
(dp[d - 1][(plan[d] + 1) % 3 + 1][1] +
dp[d - 1][(plan[d] + 1) % 3 + 1][2] +
dp[d - 1][plan[d] % 3 + 1][1] + dp[d - 1][plan[d] % 3 + 1][2]) %
MOD;
dp[d][plan[d]][2] = dp[d - 1][plan[d]][1] % MOD;
} else {
dp[d][p][1] =
(dp[d - 1][(p + 1) % 3 + 1][1] + dp[d - 1][(p + 1) % 3 + 1][2] +
dp[d - 1][p % 3 + 1][1] + dp[d - 1][p % 3 + 1][2]) %
MOD;
dp[d][p][2] = dp[d - 1][p][1] % MOD;
}
}
}
int ans = dp[day][1][1] + dp[day][2][1] + dp[day][3][1] + dp[day][1][2] +
dp[day][2][2] + dp[day][3][2];
cout << ans << endl;
return 0;
}
|
#include <iostream>
#include <string.h>
using namespace std;
int dp[101][4][4]; //何日目から、どのぱすたを、何日連続で食べているか
int plan[101]; //先に決められている予定 要素:日付
#define MOD 10000;
int main(void) {
int day;
int k;
cin >> day >> k;
memset(plan, 0, sizeof(plan));
for (int i = 0; i < k; ++i) {
int d, p;
cin >> d >> p;
plan[d] = p;
}
memset(dp, 0, sizeof(dp));
for (int i = 1; i <= 3; ++i) {
if (plan[1] != 0)
dp[1][plan[1]][1] = 1;
else
dp[1][i][1] = 1;
}
for (int d = 2; d <= day; ++d) { //どの日から?
for (int p = 1; p <= 3; ++p) { //どのパスタを?
if (plan[d]) {
dp[d][plan[d]][1] =
(dp[d - 1][(plan[d] + 1) % 3 + 1][1] +
dp[d - 1][(plan[d] + 1) % 3 + 1][2] +
dp[d - 1][plan[d] % 3 + 1][1] + dp[d - 1][plan[d] % 3 + 1][2]) %
MOD;
dp[d][plan[d]][2] = dp[d - 1][plan[d]][1] % MOD;
} else {
dp[d][p][1] =
(dp[d - 1][(p + 1) % 3 + 1][1] + dp[d - 1][(p + 1) % 3 + 1][2] +
dp[d - 1][p % 3 + 1][1] + dp[d - 1][p % 3 + 1][2]) %
MOD;
dp[d][p][2] = dp[d - 1][p][1] % MOD;
}
}
}
int ans = (dp[day][1][1] + dp[day][2][1] + dp[day][3][1] + dp[day][1][2] +
dp[day][2][2] + dp[day][3][2]) %
MOD;
cout << ans << endl;
return 0;
}
|
[["+", 0, 43, 49, 50, 51, 16, 31, 23, 0, 24], ["+", 0, 43, 49, 50, 51, 16, 31, 23, 0, 25], ["+", 8, 9, 0, 43, 49, 50, 51, 16, 17, 109], ["+", 8, 9, 0, 43, 49, 50, 51, 16, 12, 22]]
| 1
| 542
| 4
|
#include <cstdio>
#include <cstring>
#define MOD (10000)
using namespace std;
int sum(int *p) { return (p[0] + p[1]); }
int main(void) {
int n, k;
static int dp[100][3][2];
int done[100];
scanf("%d %d", &n, &k);
memset(done, -1, sizeof(done));
for (int i = 0; i < k; i++) {
int a, b;
scanf("%d %d", &a, &b);
done[--a] = --b;
}
for (int i = 0; i < 3; i++) {
if (~done[0])
dp[0][done[i]][0] = 1;
else
dp[0][i][0] = 1;
}
for (int i = 1; i < n; i++) {
for (int j = 0; j < 3; j++) {
if (~done[i]) {
j = done[i];
dp[i][j][0] =
(sum(dp[i - 1][(j + 1) % 3]) + sum(dp[i - 1][(j + 2) % 3])) % MOD;
dp[i][j][1] = dp[i - 1][j][0] % MOD;
break;
} else {
dp[i][j][0] =
(sum(dp[i - 1][(j + 1) % 3]) + sum(dp[i - 1][(j + 2) % 3])) % MOD;
dp[i][j][1] = dp[i - 1][j][0] % MOD;
}
}
}
int s = 0;
for (int i = 0; i < 3; i++) {
s += sum(dp[n - 1][i]);
}
printf("%d\n", s % MOD);
return (0);
}
|
#include <cstdio>
#include <cstring>
#define MOD (10000)
using namespace std;
int sum(int *p) { return (p[0] + p[1]); }
int main(void) {
int n, k;
static int dp[100][3][2];
int done[100];
scanf("%d %d", &n, &k);
memset(done, -1, sizeof(done));
for (int i = 0; i < k; i++) {
int a, b;
scanf("%d %d", &a, &b);
done[--a] = --b;
}
for (int i = 0; i < 3; i++) {
if (~done[0])
dp[0][done[0]][0] = 1;
else
dp[0][i][0] = 1;
}
for (int i = 1; i < n; i++) {
for (int j = 0; j < 3; j++) {
if (~done[i]) {
j = done[i];
dp[i][j][0] =
(sum(dp[i - 1][(j + 1) % 3]) + sum(dp[i - 1][(j + 2) % 3])) % MOD;
dp[i][j][1] = dp[i - 1][j][0] % MOD;
break;
} else {
dp[i][j][0] =
(sum(dp[i - 1][(j + 1) % 3]) + sum(dp[i - 1][(j + 2) % 3])) % MOD;
dp[i][j][1] = dp[i - 1][j][0] % MOD;
}
}
}
int s = 0;
for (int i = 0; i < 3; i++) {
s += sum(dp[n - 1][i]);
}
printf("%d\n", s % MOD);
return (0);
}
|
[["-", 28, 69, 341, 342, 0, 69, 341, 342, 0, 22], ["+", 28, 69, 341, 342, 0, 69, 341, 342, 0, 13]]
| 1
| 451
| 2
|
#include <stdio.h>
int field[105][105], n, m;
int dfs(int x, int y) {
if (x < 0 || x > n + 2 || y < 0 || y > m + 1)
return 0;
if (field[x][y] == 1)
return 1;
if (field[x][y] == 2)
return 0;
int res = 0;
field[x][y] = 2;
res += dfs(x, y + 1);
res += dfs(x, y - 1);
res += dfs(x + 1, y);
res += dfs(x - 1, y);
if (x % 2 == 0) {
res += dfs(x - 1, y - 1);
res += dfs(x + 1, y - 1);
} else {
res += dfs(x - 1, y + 1);
res += dfs(x + 1, y + 1);
}
return res;
}
int main() {
int i, j;
scanf("%d%d", &n, &m);
for (i = 1; i <= m; i++) {
for (j = 1; j <= n; j++) {
scanf("%d", &field[i][j]);
}
}
printf("%d\n", dfs(0, 0));
return 0;
}
|
#include <stdio.h>
int field[105][105], n, m;
int dfs(int x, int y) {
if (x < 0 || x > m + 2 || y < 0 || y > n + 2)
return 0;
if (field[x][y] == 1)
return 1;
if (field[x][y] == 2)
return 0;
int res = 0;
field[x][y] = 2;
res += dfs(x, y + 1);
res += dfs(x, y - 1);
res += dfs(x + 1, y);
res += dfs(x - 1, y);
if (x % 2 == 0) {
res += dfs(x - 1, y - 1);
res += dfs(x + 1, y - 1);
} else {
res += dfs(x - 1, y + 1);
res += dfs(x + 1, y + 1);
}
return res;
}
int main() {
int i, j;
scanf("%d%d", &n, &m);
for (i = 1; i <= m; i++) {
for (j = 1; j <= n; j++) {
scanf("%d", &field[i][j]);
}
}
printf("%d\n", dfs(0, 0));
return 0;
}
|
[["-", 31, 16, 31, 16, 12, 16, 12, 16, 31, 22], ["+", 31, 16, 31, 16, 12, 16, 12, 16, 31, 22], ["-", 15, 23, 0, 16, 12, 16, 12, 16, 31, 22], ["+", 15, 23, 0, 16, 12, 16, 12, 16, 31, 22], ["-", 15, 23, 0, 16, 12, 16, 12, 16, 12, 13], ["+", 15, 23, 0, 16, 12, 16, 12, 16, 12, 13]]
| 0
| 296
| 6
|
#include <cstdlib>
#include <cstring>
#include <iostream>
using namespace std;
constexpr int mod = 10000000;
constexpr int MAX_DIGIT = 500;
constexpr int MAX_M = 500;
int dp[MAX_DIGIT + 1][MAX_M][10][2]
[2]; // digit, modulo m, prev, less flag, zig-zag flag
int calc(const string &limit, int m) {
const int n = limit.size();
memset(dp, 0, sizeof(dp));
for (int i = 0; i < n; ++i) {
for (int j = 0; j < 10; ++j) {
const bool lt = (j < limit[i] - '0');
const bool le = (j <= limit[i] - '0');
if (j && (i || le)) {
(dp[i + 1][j % m][j][i || lt][true] += 1) %= mod;
(dp[i + 1][j % m][j][i || lt][false] += 1) %= mod;
}
for (int k = 0; k < m; ++k) {
const int next_rest = (k * 10 + j) % m;
for (int l = 0; l < j; ++l) {
(dp[i + 1][next_rest][j][true][true] += dp[i][k][l][true][false]) %=
mod;
if (le) {
(dp[i + 1][next_rest][j][lt][true] += dp[i][k][l][false][false]) %=
mod;
}
}
for (int l = j + 1; l < 10; ++l) {
(dp[i + 1][next_rest][j][true][false] += dp[i][k][l][true][true]) %=
mod;
if (le) {
(dp[i + 1][next_rest][j][lt][false] += dp[i][k][l][false][true]) %=
mod;
}
}
}
}
}
int res = 0;
for (int i = 0; i < 10; ++i) {
res += dp[n][0][i][true][true];
res += dp[n][0][i][true][false];
if (i && (n > 1 || i < limit.back() - '0') && i % m == 0) {
--res;
}
}
return res % mod;
}
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
string a, b;
int m;
cin >> a >> b >> m;
int carry = 1;
for (int i = b.size() - 1; i >= 0; --i) {
b[i] += carry;
if (b[i] <= '9') {
carry = 0;
break;
} else {
b[i] = '0';
}
}
if (carry)
b = '1' + b;
cout << (calc(b, m) - calc(a, m) + mod) % mod << endl;
return EXIT_SUCCESS;
}
|
#include <cstdlib>
#include <cstring>
#include <iostream>
using namespace std;
constexpr int mod = 10000;
constexpr int MAX_DIGIT = 500;
constexpr int MAX_M = 500;
int dp[MAX_DIGIT + 1][MAX_M][10][2]
[2]; // digit, modulo m, prev, less flag, zig-zag flag
int calc(const string &limit, int m) {
const int n = limit.size();
memset(dp, 0, sizeof(dp));
for (int i = 0; i < n; ++i) {
for (int j = 0; j < 10; ++j) {
const bool lt = (j < limit[i] - '0');
const bool le = (j <= limit[i] - '0');
if (j && (i || le)) {
(dp[i + 1][j % m][j][i || lt][true] += 1) %= mod;
(dp[i + 1][j % m][j][i || lt][false] += 1) %= mod;
}
for (int k = 0; k < m; ++k) {
const int next_rest = (k * 10 + j) % m;
for (int l = 0; l < j; ++l) {
(dp[i + 1][next_rest][j][true][true] += dp[i][k][l][true][false]) %=
mod;
if (le) {
(dp[i + 1][next_rest][j][lt][true] += dp[i][k][l][false][false]) %=
mod;
}
}
for (int l = j + 1; l < 10; ++l) {
(dp[i + 1][next_rest][j][true][false] += dp[i][k][l][true][true]) %=
mod;
if (le) {
(dp[i + 1][next_rest][j][lt][false] += dp[i][k][l][false][true]) %=
mod;
}
}
}
}
}
int res = 0;
for (int i = 0; i < 10; ++i) {
res += dp[n][0][i][true][true];
res += dp[n][0][i][true][false];
if (i && (n > 1 || i < limit.back() - '0') && i % m == 0) {
--res;
}
}
return res % mod;
}
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
string a, b;
int m;
cin >> a >> b >> m;
int carry = 1;
for (int i = b.size() - 1; i >= 0; --i) {
b[i] += carry;
if (b[i] <= '9') {
carry = 0;
break;
} else {
b[i] = '0';
}
}
if (carry)
b = '1' + b;
cout << (calc(b, m) - calc(a, m) + mod) % mod << endl;
return EXIT_SUCCESS;
}
|
[["-", 36, 36, 0, 30, 0, 43, 49, 50, 51, 13], ["+", 36, 36, 0, 30, 0, 43, 49, 50, 51, 13]]
| 1
| 693
| 2
|
#include <iostream>
#include <numeric>
#include <vector>
using namespace std;
class range {
private:
struct Iterator {
int val;
int operator*() { return val; }
bool operator!=(Iterator &itr) { return val < itr.val; }
void operator++() { ++val; }
};
Iterator i, n;
public:
range(int n) : i({0}), n({n}) {}
range(int i, int n) : i({i}), n({n}) {}
Iterator &begin() { return i; }
Iterator &end() { return n; }
};
template <class T> T at(vector<T> v, int i) {
return v[(i % (int)v.size() + v.size()) % v.size()];
}
const long long MOD = 10000;
class Inverse {
private:
vector<long long> inv;
public:
Inverse(int n) {
inv = vector<long long>(n, 1);
for (int i : range(2, n))
inv[i] = inv[MOD % i] * (MOD - MOD / i) % MOD;
}
long long operator()(long long a) const {
if (a < (int)inv.size())
return inv[a];
long long b = MOD, x = 1, y = 0;
while (b) {
long long t = a / b;
swap(a -= t * b, b);
swap(x -= t * y, y);
}
return (MOD + x % MOD) % MOD;
}
};
Inverse inv(1000000);
class Mint {
private:
long long val;
public:
Mint() {}
Mint(long long val) : val(val % MOD) {}
Mint operator+=(const Mint &m) {
val += m.val;
if (val >= MOD)
val -= MOD;
return *this;
}
Mint operator-=(const Mint &m) {
val -= m.val;
if (val < 0)
val += MOD;
return *this;
}
Mint operator*=(const Mint &m) {
val *= m.val;
val %= MOD;
return *this;
}
Mint operator/=(const Mint &m) {
val *= inv(m.val);
val %= MOD;
return *this;
}
Mint operator+(const Mint &m) const {
Mint res = *this;
res += m;
return res;
}
Mint operator-(const Mint &m) const {
Mint res = *this;
res -= m;
return res;
}
Mint operator*(const Mint &m) const {
Mint res = *this;
res *= m;
return res;
}
Mint operator/(const Mint &m) const {
Mint res = *this;
res /= m;
return res;
}
Mint operator++() { return val += 1; }
Mint operator--() { return val -= 1; }
Mint operator=(int n) { return *this = Mint(n); }
operator long long() { return val; }
};
ostream &operator<<(ostream &os, Mint a) {
os << (long long)a;
return os;
}
istream &operator>>(istream &is, Mint &a) {
long long n;
is >> n;
a = Mint(n);
return is;
}
#include <sstream>
template <class A, class B> B convert(A a) {
stringstream ss;
ss << a;
B b;
ss >> b;
return b;
}
bool iszigzag(int a, int m) {
if (a % m)
return false;
string s = convert<int, string>(a);
for (int i : range(s.size() - 1)) {
if (i % 2 == 0 && s[i] <= s[i + 1])
return false;
if (i % 2 == 1 && s[i] >= s[i + 1])
return false;
}
return true;
}
bool iszagzig(int a, int m) {
if (a % m)
return false;
string s = convert<int, string>(a);
for (int i : range(s.size() - 1)) {
if (i % 2 == 1 && s[i] <= s[i + 1])
return false;
if (i % 2 == 0 && s[i] >= s[i + 1])
return false;
}
return true;
}
Mint solve(string s, Mint m) {
if (s == "0")
return 0;
Mint res = 0;
for (int t : range(2)) {
vector<vector<vector<Mint>>> dp(
2, vector<vector<Mint>>(11, vector<Mint>(m, 0)));
for (int i : range(1, s[0] - '0'))
dp[0][i][i % m] = 1;
dp[0][10][int(s[0] - '0') % m] = 1;
for (int i : range(1, s.size())) {
if (i % 2 == t) {
for (int mm : range(m))
for (int j : range(10))
for (int k : range(j))
dp[1][j][(mm * 10 + j) % m] += dp[0][k][mm];
for (int mm : range(m))
for (int j : range(s[i] - '0'))
if (j > s[i - 1] - '0')
dp[1][j][(mm * 10 + j) % m] += dp[0][10][mm];
if (s[i - 1] < s[i])
for (int mm : range(m))
dp[1][10][(mm * 10 + s[i] - '0') % m] = dp[0][10][mm];
for (int j : range(1, 10))
++dp[1][j][j % m];
} else {
for (int mm : range(m))
for (int j : range(10))
for (int k : range(j + 1, 10))
dp[1][j][(mm * 10 + j) % m] += dp[0][k][mm];
for (int mm : range(m))
for (int j : range(s[i] - '0'))
if (j < s[i - 1] - '0')
dp[1][j][(mm * 10 + j) % m] += dp[0][10][mm];
if (s[i - 1] > s[i])
for (int mm : range(m))
dp[1][10][(mm * 10 + s[i] - '0') % m] = dp[0][10][mm];
for (int j : range(1, 10))
++dp[1][j][j % m];
}
dp[0] = dp[1];
for (auto &i : dp[1])
fill(i.begin(), i.end(), 0);
}
for (const auto &i : dp[0])
res += i[0];
}
if (s.size() == 1u) {
for (int i : range(1, convert<string, int>(s)))
if (i % m == 0)
--res;
} else {
for (int i : range(1, 10))
if (i % m == 0)
--res;
}
return res;
}
int main() {
string a, b;
Mint m;
cin >> a >> b >> m;
for (int i = a.size() - 1; i >= 0; --i) {
if (a[i] != '0') {
--a[i];
break;
} else {
a[i] = '9';
}
}
while (a.size() > 1u && a[0] == '0')
a = a.substr(1);
cout << solve(b, m) - solve(a, m) << endl;
}
|
#include <iostream>
#include <numeric>
#include <vector>
using namespace std;
class range {
private:
struct Iterator {
int val;
int operator*() { return val; }
bool operator!=(Iterator &itr) { return val < itr.val; }
void operator++() { ++val; }
};
Iterator i, n;
public:
range(int n) : i({0}), n({n}) {}
range(int i, int n) : i({i}), n({n}) {}
Iterator &begin() { return i; }
Iterator &end() { return n; }
};
template <class T> T at(vector<T> v, int i) {
return v[(i % (int)v.size() + v.size()) % v.size()];
}
const long long MOD = 10000;
class Inverse {
private:
vector<long long> inv;
public:
Inverse(int n) {
inv = vector<long long>(n, 1);
for (int i : range(2, n))
inv[i] = inv[MOD % i] * (MOD - MOD / i) % MOD;
}
long long operator()(long long a) const {
if (a < (int)inv.size())
return inv[a];
long long b = MOD, x = 1, y = 0;
while (b) {
long long t = a / b;
swap(a -= t * b, b);
swap(x -= t * y, y);
}
return (MOD + x % MOD) % MOD;
}
};
Inverse inv(1000000);
class Mint {
private:
long long val;
public:
Mint() {}
Mint(long long val) : val(val % MOD) {}
Mint operator+=(const Mint &m) {
val += m.val;
if (val >= MOD)
val -= MOD;
return *this;
}
Mint operator-=(const Mint &m) {
val -= m.val;
if (val < 0)
val += MOD;
return *this;
}
Mint operator*=(const Mint &m) {
val *= m.val;
val %= MOD;
return *this;
}
Mint operator/=(const Mint &m) {
val *= inv(m.val);
val %= MOD;
return *this;
}
Mint operator+(const Mint &m) const {
Mint res = *this;
res += m;
return res;
}
Mint operator-(const Mint &m) const {
Mint res = *this;
res -= m;
return res;
}
Mint operator*(const Mint &m) const {
Mint res = *this;
res *= m;
return res;
}
Mint operator/(const Mint &m) const {
Mint res = *this;
res /= m;
return res;
}
Mint operator++() { return val += 1; }
Mint operator--() { return val -= 1; }
Mint operator=(int n) { return *this = Mint(n); }
operator long long() { return val; }
};
ostream &operator<<(ostream &os, Mint a) {
os << (long long)a;
return os;
}
istream &operator>>(istream &is, Mint &a) {
long long n;
is >> n;
a = Mint(n);
return is;
}
#include <sstream>
template <class A, class B> B convert(A a) {
stringstream ss;
ss << a;
B b;
ss >> b;
return b;
}
bool iszigzag(int a, int m) {
if (a % m)
return false;
string s = convert<int, string>(a);
for (int i : range(s.size() - 1)) {
if (i % 2 == 0 && s[i] <= s[i + 1])
return false;
if (i % 2 == 1 && s[i] >= s[i + 1])
return false;
}
return true;
}
bool iszagzig(int a, int m) {
if (a % m)
return false;
string s = convert<int, string>(a);
for (int i : range(s.size() - 1)) {
if (i % 2 == 1 && s[i] <= s[i + 1])
return false;
if (i % 2 == 0 && s[i] >= s[i + 1])
return false;
}
return true;
}
Mint solve(string s, Mint m) {
if (s == "0")
return 0;
Mint res = 0;
for (int t : range(2)) {
vector<vector<vector<Mint>>> dp(
2, vector<vector<Mint>>(11, vector<Mint>(m, 0)));
for (int i : range(1, s[0] - '0'))
dp[0][i][i % m] = 1;
dp[0][10][int(s[0] - '0') % m] = 1;
for (int i : range(1, s.size())) {
if (i % 2 == t) {
for (int mm : range(m))
for (int j : range(10))
for (int k : range(j))
dp[1][j][(mm * 10 + j) % m] += dp[0][k][mm];
for (int mm : range(m))
for (int j : range(s[i] - '0'))
if (j > s[i - 1] - '0')
dp[1][j][(mm * 10 + j) % m] += dp[0][10][mm];
if (s[i - 1] < s[i])
for (int mm : range(m))
dp[1][10][(mm * 10 + s[i] - '0') % m] += dp[0][10][mm];
for (int j : range(1, 10))
++dp[1][j][j % m];
} else {
for (int mm : range(m))
for (int j : range(10))
for (int k : range(j + 1, 10))
dp[1][j][(mm * 10 + j) % m] += dp[0][k][mm];
for (int mm : range(m))
for (int j : range(s[i] - '0'))
if (j < s[i - 1] - '0')
dp[1][j][(mm * 10 + j) % m] += dp[0][10][mm];
if (s[i - 1] > s[i])
for (int mm : range(m))
dp[1][10][(mm * 10 + s[i] - '0') % m] += dp[0][10][mm];
for (int j : range(1, 10))
++dp[1][j][j % m];
}
dp[0] = dp[1];
for (auto &i : dp[1])
fill(i.begin(), i.end(), 0);
}
for (const auto &i : dp[0])
res += i[0];
}
if (s.size() == 1u) {
for (int i : range(1, convert<string, int>(s)))
if (i % m == 0)
--res;
} else {
for (int i : range(1, 10))
if (i % m == 0)
--res;
}
return res;
}
int main() {
string a, b;
Mint m;
cin >> a >> b >> m;
for (int i = a.size() - 1; i >= 0; --i) {
if (a[i] != '0') {
--a[i];
break;
} else {
a[i] = '9';
}
}
while (a.size() > 1u && a[0] == '0')
a = a.substr(1);
cout << solve(b, m) - solve(a, m) << endl;
}
|
[["-", 0, 57, 64, 338, 8, 1, 0, 11, 17, 32], ["+", 0, 57, 64, 338, 8, 1, 0, 11, 17, 107]]
| 1
| 1,809
| 4
|
#include <bits/stdc++.h>
using namespace std;
#define DUMP(x) cerr << #x << "=" << x << endl
#define DUMP2(x, y) \
cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")" << endl
#define BINARY(x) static_cast<bitset<16>>(x)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, m, n) for (int i = m; i < (int)(n); i++)
#define in_range(x, y, w, h) \
(0 <= (int)(x) && (int)(x) < (int)(w) && 0 <= (int)(y) && (int)(y) < (int)(h))
#define ALL(a) (a).begin(), (a).end()
typedef long long ll;
const int INF = 1e9;
typedef pair<int, int> PII;
int dx[4] = {0, -1, 1, 0}, dy[4] = {-1, 0, 0, 1};
const int MOD = 10000;
int dp[501][500][10][3][2];
int M, L;
string N;
int solve(int n, int m, int last, int up, int same) {
if (n == L)
return !m;
if (dp[n][m][last][up][same] != -1)
return dp[n][m][last][up][same];
int res = 0;
rep(d, 10) {
int nsame = 0;
if (same && d > N[n] - '0')
break;
if (same && d == N[n] - '0')
nsame = 1;
int nup = (up + 1) % 2;
if (up == 0 && last >= d)
continue;
if (up == 1 && last <= d)
continue;
if (up == 2 && last && last == d)
continue;
if (up == 2) {
if (last == 0)
nup = 2;
else if (last < d)
nup = 1;
else if (last > d)
nup = 0;
else
assert(false);
}
res += solve(n + 1, (m * 10 + d) % M, d, nup, nsame);
res %= MOD;
}
return dp[n][m][last][up][same] = res;
}
/**
int calc(string N, int M)
{
int L = N.size();
memset(dp, 0, sizeof(dp));
dp[0][0][0][2][1] = 1;
rep(i, L) rep(m, M) rep(last, 10) rep(up, 3) rep(same, 2) {
if (dp[i][m][last][up][same] == 0) continue;
rep(d, 10) {
int nup = (up + 1) % 2;
if (up == 0 && last >= d) continue;
if (up == 1 && last <= d) continue;
if (up == 2) {
if (last == 0) nup = 2;
else if (last < d) nup = 1;
else if (last > d) nup = 0;
else continue;
}
int nsame = 0;
if (same && d > N[i] - '0') break;
if (same && d == N[i] - '0') nsame = 1;
dp[i+1][(m*10 + d) % M][d][nup][nsame] += dp[i][m][d][up][same];
// dp[i+1][(m*10 + d) % M][d][nup][nsame] %= MOD;
cerr << "A" << endl;
}
}
#if 1
rep(i, L) rep(m, M) rep(last, 10) rep(up, 3) rep(same, 2) {
cerr << i+1 << " " << m << " " << last << " " << up << " " << same << "
: "; cerr << dp[i+1][m][last][up][same] << endl;
}
#endif
int res = 0;
rep(last, 10) rep(up, 2) rep(same, 2) {
res += dp[L][0][last][up][same];
}
return res - 1;
}
*/
int main() {
/*
int M;
string A, B;
cin >> A >> B >> M;
cout << calc(B, M) - calc(A, M) + sim(A, true) + sim(A, false) << endl;
*/
string A, B;
cin >> A >> B >> M;
// A -= 1
for (int i = A.size() - 1; i >= 0; i--) {
if (A[i] == '0')
A[i] = '9';
else {
A[i]--;
break;
}
}
N = A;
L = N.size();
memset(dp, -1, sizeof(dp));
int tmpa = solve(0, 0, 0, 2, 1);
N = B;
L = N.size();
memset(dp, -1, sizeof(dp));
int tmpb = solve(0, 0, 0, 2, 1);
cout << (tmpb - tmpa + M) % M << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
#define DUMP(x) cerr << #x << "=" << x << endl
#define DUMP2(x, y) \
cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")" << endl
#define BINARY(x) static_cast<bitset<16>>(x)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, m, n) for (int i = m; i < (int)(n); i++)
#define in_range(x, y, w, h) \
(0 <= (int)(x) && (int)(x) < (int)(w) && 0 <= (int)(y) && (int)(y) < (int)(h))
#define ALL(a) (a).begin(), (a).end()
typedef long long ll;
const int INF = 1e9;
typedef pair<int, int> PII;
int dx[4] = {0, -1, 1, 0}, dy[4] = {-1, 0, 0, 1};
const int MOD = 10000;
int dp[501][500][10][3][2];
int M, L;
string N;
int solve(int n, int m, int last, int up, int same) {
if (n == L)
return !m;
if (dp[n][m][last][up][same] != -1)
return dp[n][m][last][up][same];
int res = 0;
rep(d, 10) {
int nsame = 0;
if (same && d > N[n] - '0')
break;
if (same && d == N[n] - '0')
nsame = 1;
int nup = (up + 1) % 2;
if (up == 0 && last >= d)
continue;
if (up == 1 && last <= d)
continue;
if (up == 2 && last && last == d)
continue;
if (up == 2) {
if (last == 0)
nup = 2;
else if (last < d)
nup = 1;
else if (last > d)
nup = 0;
else
assert(false);
}
res += solve(n + 1, (m * 10 + d) % M, d, nup, nsame);
res %= MOD;
}
return dp[n][m][last][up][same] = res;
}
/**
int calc(string N, int M)
{
int L = N.size();
memset(dp, 0, sizeof(dp));
dp[0][0][0][2][1] = 1;
rep(i, L) rep(m, M) rep(last, 10) rep(up, 3) rep(same, 2) {
if (dp[i][m][last][up][same] == 0) continue;
rep(d, 10) {
int nup = (up + 1) % 2;
if (up == 0 && last >= d) continue;
if (up == 1 && last <= d) continue;
if (up == 2) {
if (last == 0) nup = 2;
else if (last < d) nup = 1;
else if (last > d) nup = 0;
else continue;
}
int nsame = 0;
if (same && d > N[i] - '0') break;
if (same && d == N[i] - '0') nsame = 1;
dp[i+1][(m*10 + d) % M][d][nup][nsame] += dp[i][m][d][up][same];
// dp[i+1][(m*10 + d) % M][d][nup][nsame] %= MOD;
cerr << "A" << endl;
}
}
#if 1
rep(i, L) rep(m, M) rep(last, 10) rep(up, 3) rep(same, 2) {
cerr << i+1 << " " << m << " " << last << " " << up << " " << same << "
: "; cerr << dp[i+1][m][last][up][same] << endl;
}
#endif
int res = 0;
rep(last, 10) rep(up, 2) rep(same, 2) {
res += dp[L][0][last][up][same];
}
return res - 1;
}
*/
int main() {
/*
int M;
string A, B;
cin >> A >> B >> M;
cout << calc(B, M) - calc(A, M) + sim(A, true) + sim(A, false) << endl;
*/
string A, B;
cin >> A >> B >> M;
// A -= 1
for (int i = A.size() - 1; i >= 0; i--) {
if (A[i] == '0')
A[i] = '9';
else {
A[i]--;
break;
}
}
N = A;
L = N.size();
memset(dp, -1, sizeof(dp));
int tmpa = solve(0, 0, 0, 2, 1);
N = B;
L = N.size();
memset(dp, -1, sizeof(dp));
int tmpb = solve(0, 0, 0, 2, 1);
cout << (tmpb - tmpa + MOD) % MOD << endl;
}
|
[["-", 31, 16, 12, 16, 31, 23, 0, 16, 12, 22], ["+", 31, 16, 12, 16, 31, 23, 0, 16, 12, 22], ["-", 0, 1, 0, 16, 31, 16, 12, 16, 12, 22], ["+", 0, 1, 0, 16, 31, 16, 12, 16, 12, 22]]
| 1
| 584
| 4
|
#include <bits/stdc++.h>
#define MOD 10000
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
int dp[502][2][10][500][3], m, len[2];
char S[2][550];
int solve(int o) {
memset(dp, 0, sizeof(dp));
dp[0][0][0][0][0] = 1;
rep(i, len[o]) rep(j, 2) rep(k, 10) rep(l, m) rep(d, 3) {
if (dp[i][j][k][l][d] == 0)
continue;
int s, g, p = S[o][i] - '0';
if (d == 1)
s = k + 1, g = (j ? 9 : p);
else if (d == 2)
s = 0, g = (j ? k - 1 : min(k - 1, p));
else
s = 0, g = (j ? 9 : p);
for (int x = s; x <= g; x++) {
if (x && k == x)
continue;
int y;
if (d == 1)
y = 2;
else if (d == 2)
y = 1;
else {
if (k == 0)
y = 0;
else if (x < k)
y = 1;
else
y = 2;
}
(dp[i + 1][j || x < p][x][(l * 10 + x) % m][y] += dp[i][j][k][l][d]) %=
MOD;
}
}
int sum = 0;
rep(i, 2) rep(j, 10) rep(t, 3) {
if (!i && !o)
continue;
(sum += dp[len[o]][1][j][0][t]) %= MOD;
}
return sum;
}
int main() {
scanf("%s%s%d", S[0], S[1], &m);
rep(i, 2) len[i] = strlen(S[i]);
printf("%d\n", (solve(1) + MOD - solve(0)) % MOD);
}
|
#include <bits/stdc++.h>
#define MOD 10000
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
int dp[502][2][10][500][3], m, len[2];
char S[2][550];
int solve(int o) {
memset(dp, 0, sizeof(dp));
dp[0][0][0][0][0] = 1;
rep(i, len[o]) rep(j, 2) rep(k, 10) rep(l, m) rep(d, 3) {
if (dp[i][j][k][l][d] == 0)
continue;
int s, g, p = S[o][i] - '0';
if (d == 1)
s = k + 1, g = (j ? 9 : p);
else if (d == 2)
s = 0, g = (j ? k - 1 : min(k - 1, p));
else
s = 0, g = (j ? 9 : p);
for (int x = s; x <= g; x++) {
if (x && k == x)
continue;
int y;
if (d == 1)
y = 2;
else if (d == 2)
y = 1;
else {
if (k == 0)
y = 0;
else if (x < k)
y = 1;
else
y = 2;
}
(dp[i + 1][j || x < p][x][(l * 10 + x) % m][y] += dp[i][j][k][l][d]) %=
MOD;
}
}
int sum = 0;
rep(i, 2) rep(j, 10) rep(t, 3) {
if (!i && !o)
continue;
(sum += dp[len[o]][i][j][0][t]) %= MOD;
}
return sum;
}
int main() {
scanf("%s%s%d", S[0], S[1], &m);
rep(i, 2) len[i] = strlen(S[i]);
printf("%d\n", (solve(1) + MOD - solve(0)) % MOD);
}
|
[["-", 28, 69, 28, 69, 28, 69, 341, 342, 0, 13], ["+", 28, 69, 28, 69, 28, 69, 341, 342, 0, 22]]
| 1
| 506
| 2
|
#include <algorithm>
#include <cstring>
#include <iostream>
#include <string>
const int MOD = 10000;
std::string a, b; // <=1e500
int m; // <=500
int dp[2][2][510][510][15][3];
char Ch(int i) { return '0' + i; }
int func(bool lower, bool upper, int mod, int idx, int prev,
int stat) { // stat: 0: zero, 1: ?¢???????, 2: ??????
if (idx >= a.size()) {
if (lower && upper && mod % m == 0) {
return true;
} else {
return false;
}
}
if (dp[lower][upper][mod][idx][prev][stat] != -1) {
return dp[lower][upper][mod][idx][prev][stat];
}
mod *= 10;
int ans = 0;
for (int i = 0; i <= 9; ++i) {
int nm = (mod + i) % m;
char c = '0' + i;
bool newLower;
bool newUpper;
int newStat;
if (lower) {
newLower = lower;
} else {
if (b[idx] < c) {
continue;
}
if (b[idx] == c && idx != a.size() - 1) {
newLower = false;
} else {
newLower = true;
}
}
if (upper) {
newUpper = true;
} else {
if (a[idx] > c) {
continue;
}
if (a[idx] == c && idx != a.size() - 1) {
newUpper = false;
} else {
newUpper = true;
}
}
if (stat == 0) {
if (prev == 0) {
newStat = 0;
} else if (prev > i) {
newStat = 1;
} else if (prev < i) {
newStat = 2;
} else {
continue;
}
} else if (stat == 1) {
if (i <= prev) {
continue;
}
newStat = 2;
} else {
if (i >= prev) {
continue;
}
newStat = 1;
}
ans += func(newLower, newUpper, nm, idx + 1, i, newStat);
ans %= MOD;
}
return dp[lower][upper][mod][idx][prev][stat] = ans;
}
int main() {
std::cin >> a >> b >> m;
while (a.size() < b.size()) {
a = std::string("0") + a;
}
memset(dp, -1, sizeof(dp));
std::cout << func(false, false, 0, 0, 0, 0) << std::endl;
}
|
#include <algorithm>
#include <cstring>
#include <iostream>
#include <string>
const int MOD = 10000;
std::string a, b; // <=1e500
int m; // <=500
int dp[2][2][510][510][15][3];
char Ch(int i) { return '0' + i; }
int func(bool lower, bool upper, int mod, int idx, int prev,
int stat) { // stat: 0: zero, 1: ?¢???????, 2: ??????
if (idx >= a.size()) {
if (lower && upper && mod % m == 0) {
return true;
} else {
return false;
}
}
if (dp[lower][upper][mod][idx][prev][stat] != -1) {
return dp[lower][upper][mod][idx][prev][stat];
}
mod *= 10;
int ans = 0;
for (int i = 0; i <= 9; ++i) {
int nm = (mod + i) % m;
char c = '0' + i;
bool newLower;
bool newUpper;
int newStat;
if (lower) {
newLower = lower;
} else {
if (b[idx] < c) {
continue;
}
if (b[idx] == c && idx != a.size() - 1) {
newLower = false;
} else {
newLower = true;
}
}
if (upper) {
newUpper = true;
} else {
if (a[idx] > c) {
continue;
}
if (a[idx] == c && idx != a.size() - 1) {
newUpper = false;
} else {
newUpper = true;
}
}
if (stat == 0) {
if (prev == 0) {
newStat = 0;
} else if (prev > i) {
newStat = 1;
} else if (prev < i) {
newStat = 2;
} else {
continue;
}
} else if (stat == 1) {
if (i <= prev) {
continue;
}
newStat = 2;
} else {
if (i >= prev) {
continue;
}
newStat = 1;
}
ans += func(newLower, newUpper, nm, idx + 1, i, newStat);
ans %= MOD;
}
return dp[lower][upper][mod / 10][idx][prev][stat] = ans;
}
int main() {
std::cin >> a >> b >> m;
while (a.size() < b.size()) {
a = std::string("0") + a;
}
memset(dp, -1, sizeof(dp));
std::cout << func(false, false, 0, 0, 0, 0) << std::endl;
}
|
[["+", 28, 69, 28, 69, 341, 342, 0, 16, 17, 85], ["+", 28, 69, 28, 69, 341, 342, 0, 16, 12, 13]]
| 1
| 555
| 2
|
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <time.h>
#include <tuple>
#include <vector>
#define ll long long
#define fi first
#define se second
using namespace std;
const ll MOD = 10000;
string a, b;
int m;
ll dp[501][2][500][11][3][2];
/*inline ll solve(string s){
int n=(int)s.length();
for(int i=0;i<510;i++)for(int j=0;j<2;j++)for(int k=0;k<500;k++)for(int
l=0;l<11;l++)for(int o=0;o<3;o++)for(int h=0;h<2;h++)dp[i][j][k][l][o][h]=0;
dp[0][0][0][0][0][0]=1;
for(int i=0;i<n;i++)for(int j=0;j<2;j++)for(int k=0;k<m;k++)for(int
l=0;l<11;l++)for(int o=0;o<3;o++)for(int h=0;h<2;h++){ int lim=j?9:s[i]-'0';
for(int d=0;d<lim+1;d++){
if(l==0 && i==0){
dp[i+1][j || d<lim][(10*k+d)%m][d+1][0][h || (l!=1 &&
l!=0)]+=dp[i][j][k][l][o][h];
//cout<<i+1<<" "<<(int)(j || d<lim)<<" "<<(10*k+d)%m<<" "<<d+1<<"
"<<o<<endl; continue;
}
if(o!=1){
if(d>l-1){
dp[i+1][j || d<lim][(10*k+d)%m][d+1][(o==2?1:(h || l!=1)?1:0)][h ||
l!=1]+=dp[i][j][k][l][o][h];
//cout<<i+1<<" "<<(int)(j || d<lim)<<" "<<(10*k+d)%m<<" "<<d+1<<"
"<<1<<endl;
}
}
if(o!=2){
if(d<l-1){
dp[i+1][j || d<lim][(10*k+d)%m][d+1][(o==1?2:(h || l!=1)?2:0)][h ||
l!=1]+=dp[i][j][k][l][o][h];
//cout<<i+1<<" "<<(int)(j || d<lim)<<" "<<(10*k+d)%m<<" "<<d+1<<"
"<<2<<endl;
}
}
}
}
ll res=0;
for(int i=0;i<2;i++)for(int j=0;j<500;j++)for(int k=1;k<11;k++)for(int
l=1;l<3;l++){ if(j==0) res+=dp[n][i][j][k][l][1]; if(dp[n][i][j][k][l][1]>0 &&
j==0)cout<<i<<" "<<j<<" "<<k<<" "<<l<<"="<<dp[n][i][j][k][l][1]<<endl;
}
return res;
}*/
inline ll solve(string s) {
int n = (int)s.length();
for (int i = 0; i < 510; i++)
for (int j = 0; j < 2; j++)
for (int k = 0; k < 500; k++)
for (int l = 0; l < 11; l++)
for (int mm = 0; mm < 3; mm++)
for (int o = 0; o < 2; o++)
dp[i][j][k][l][mm][o] = 0;
dp[0][0][0][0][0][0] = 1;
for (int i = 0; i < n; i++) {
for (int j = 0; j < 2; j++) {
for (int k = 0; k < m; k++) {
for (int l = 0; l < 11; l++) {
for (int mm = 0; mm < 3; mm++) {
for (int o = 0; o < 2; o++) {
int lim = j ? 9 : s[i] - '0';
int pre = l - 1;
for (int d = 0; d < lim + 1; d++) {
if (d == 0 && o == 0) {
(dp[i + 1][j || d < lim][(10 * k + d) % m][0][0][0] +=
dp[i][j][k][l][mm][o]) %= MOD;
continue;
}
if (pre == -1) {
(dp[i + 1][j || d < lim][(10 * k + d) % m][d + 1][0][1] +=
dp[i][j][k][l][mm][o]) %= MOD;
continue;
}
if (pre < d && mm != 1) {
(dp[i + 1][j || d < lim][(10 * k + d) % m][d + 1][1][1] +=
dp[i][j][k][l][mm][o]) %= MOD;
}
if (pre > d && mm != 2) {
(dp[i + 1][j || d < lim][(10 * k + d) % m][d + 1][2][1] +=
dp[i][j][k][l][mm][o]) %= MOD;
}
}
}
}
}
}
}
}
ll ans = 0;
for (int i = 0; i < 2; i++)
for (int j = 1; j < 11; j++)
for (int k = 0; k < 3; k++) {
(ans += dp[n][i][0][j][k][1]) %= MOD;
}
return ans;
}
inline string min1(string s) {
int n = (int)s.length();
for (int i = n - 1; i >= 0; i--) {
int now = s[i] - '0';
if (now - 1 < 0) {
s[i] = '9';
} else {
s[i] = '0' + now - 1;
break;
}
}
for (int i = 0; i < n; i++) {
if (s == "0")
break;
if (s[i] == '0')
s = s.substr(1, s.length() - 1);
else
break;
}
return s;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.precision(10);
cout << fixed;
#ifdef LOCAL_DEFINE
freopen("in", "r", stdin);
freopen("out", "w", stdout);
#endif
ll ansa, ansb;
cin >> a >> b >> m;
// while(cin>>a>>b>>m){
a = min1(a);
ansb = solve(b);
// cout<<b<<" ansb="<<ansb<<endl;
ansa = solve(a);
// cout<<a<<" ansa="<<ansa<<endl;
cout << (ansb + MOD - ansa) % MOD << "\n";
#ifdef LOCAL_DEFINE
cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
return 0;
}
|
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <time.h>
#include <tuple>
#include <vector>
#define ll long long
#define fi first
#define se second
using namespace std;
const ll MOD = 10000;
string a, b;
int m;
ll dp[502][2][500][11][3][2];
/*inline ll solve(string s){
int n=(int)s.length();
for(int i=0;i<510;i++)for(int j=0;j<2;j++)for(int k=0;k<500;k++)for(int
l=0;l<11;l++)for(int o=0;o<3;o++)for(int h=0;h<2;h++)dp[i][j][k][l][o][h]=0;
dp[0][0][0][0][0][0]=1;
for(int i=0;i<n;i++)for(int j=0;j<2;j++)for(int k=0;k<m;k++)for(int
l=0;l<11;l++)for(int o=0;o<3;o++)for(int h=0;h<2;h++){ int lim=j?9:s[i]-'0';
for(int d=0;d<lim+1;d++){
if(l==0 && i==0){
dp[i+1][j || d<lim][(10*k+d)%m][d+1][0][h || (l!=1 &&
l!=0)]+=dp[i][j][k][l][o][h];
//cout<<i+1<<" "<<(int)(j || d<lim)<<" "<<(10*k+d)%m<<" "<<d+1<<"
"<<o<<endl; continue;
}
if(o!=1){
if(d>l-1){
dp[i+1][j || d<lim][(10*k+d)%m][d+1][(o==2?1:(h || l!=1)?1:0)][h ||
l!=1]+=dp[i][j][k][l][o][h];
//cout<<i+1<<" "<<(int)(j || d<lim)<<" "<<(10*k+d)%m<<" "<<d+1<<"
"<<1<<endl;
}
}
if(o!=2){
if(d<l-1){
dp[i+1][j || d<lim][(10*k+d)%m][d+1][(o==1?2:(h || l!=1)?2:0)][h ||
l!=1]+=dp[i][j][k][l][o][h];
//cout<<i+1<<" "<<(int)(j || d<lim)<<" "<<(10*k+d)%m<<" "<<d+1<<"
"<<2<<endl;
}
}
}
}
ll res=0;
for(int i=0;i<2;i++)for(int j=0;j<500;j++)for(int k=1;k<11;k++)for(int
l=1;l<3;l++){ if(j==0) res+=dp[n][i][j][k][l][1]; if(dp[n][i][j][k][l][1]>0 &&
j==0)cout<<i<<" "<<j<<" "<<k<<" "<<l<<"="<<dp[n][i][j][k][l][1]<<endl;
}
return res;
}*/
inline ll solve(string s) {
int n = (int)s.length();
for (int i = 0; i < n + 1; i++)
for (int j = 0; j < 2; j++)
for (int k = 0; k < m; k++)
for (int l = 0; l < 11; l++)
for (int mm = 0; mm < 3; mm++)
for (int o = 0; o < 2; o++)
dp[i][j][k][l][mm][o] = 0;
dp[0][0][0][0][0][0] = 1;
for (int i = 0; i < n; i++) {
for (int j = 0; j < 2; j++) {
for (int k = 0; k < m; k++) {
for (int l = 0; l < 11; l++) {
for (int mm = 0; mm < 3; mm++) {
for (int o = 0; o < 2; o++) {
int lim = j ? 9 : s[i] - '0';
int pre = l - 1;
for (int d = 0; d < lim + 1; d++) {
if (d == 0 && o == 0) {
(dp[i + 1][j || d < lim][(10 * k + d) % m][0][0][0] +=
dp[i][j][k][l][mm][o]) %= MOD;
continue;
}
if (pre == -1) {
(dp[i + 1][j || d < lim][(10 * k + d) % m][d + 1][0][1] +=
dp[i][j][k][l][mm][o]) %= MOD;
continue;
}
if (pre < d && mm != 1) {
(dp[i + 1][j || d < lim][(10 * k + d) % m][d + 1][1][1] +=
dp[i][j][k][l][mm][o]) %= MOD;
}
if (pre > d && mm != 2) {
(dp[i + 1][j || d < lim][(10 * k + d) % m][d + 1][2][1] +=
dp[i][j][k][l][mm][o]) %= MOD;
}
}
}
}
}
}
}
}
ll ans = 0;
for (int i = 0; i < 2; i++)
for (int j = 1; j < 11; j++)
for (int k = 0; k < 3; k++) {
(ans += dp[n][i][0][j][k][1]) %= MOD;
}
return ans;
}
inline string min1(string s) {
int n = (int)s.length();
for (int i = n - 1; i >= 0; i--) {
int now = s[i] - '0';
if (now - 1 < 0) {
s[i] = '9';
} else {
s[i] = '0' + now - 1;
break;
}
}
for (int i = 0; i < n; i++) {
if (s == "0")
break;
if (s[i] == '0')
s = s.substr(1, s.length() - 1);
else
break;
}
return s;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.precision(10);
cout << fixed;
#ifdef LOCAL_DEFINE
freopen("in", "r", stdin);
freopen("out", "w", stdout);
#endif
ll ansa, ansb;
cin >> a >> b >> m;
// while(cin>>a>>b>>m){
a = min1(a);
ansb = solve(b);
// cout<<b<<" ansb="<<ansb<<endl;
ansa = solve(a);
// cout<<a<<" ansa="<<ansa<<endl;
cout << (ansb + MOD - ansa) % MOD << "\n";
#ifdef LOCAL_DEFINE
cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
return 0;
}
|
[["-", 49, 80, 49, 80, 49, 80, 49, 80, 81, 13], ["+", 49, 80, 49, 80, 49, 80, 49, 80, 81, 13], ["-", 0, 14, 8, 9, 0, 7, 15, 16, 12, 13], ["+", 8, 9, 0, 7, 15, 16, 12, 16, 31, 22], ["+", 8, 9, 0, 7, 15, 16, 12, 16, 17, 72], ["+", 8, 9, 0, 7, 15, 16, 12, 16, 12, 13], ["-", 0, 7, 8, 7, 8, 7, 15, 16, 12, 13], ["+", 0, 7, 8, 7, 8, 7, 15, 16, 12, 22]]
| 1
| 1,023
| 8
|
#include <iostream>
using namespace std;
int main() {
int a, b, c, d, L;
int hi, tuki;
float fhi, ftuki;
cin >> L >> a >> b >> c >> d;
hi = a / c;
fhi = (float)a / c;
tuki = b / d;
ftuki = (float)b / d;
if (hi < fhi) {
fhi++;
}
if (tuki < ftuki) {
ftuki++;
}
if (hi > tuki) {
cout << L - hi << '\n';
} else {
cout << L - tuki << '\n';
}
return 0;
}
|
#include <iostream>
using namespace std;
int main() {
int a, b, c, d, L;
int hi, tuki;
float fhi, ftuki;
cin >> L >> a >> b >> c >> d;
hi = a / c;
fhi = (float)a / c;
tuki = b / d;
ftuki = (float)b / d;
if (hi < fhi) {
hi++;
}
if (tuki < ftuki) {
tuki++;
}
if (hi > tuki) {
cout << L - hi << '\n';
} else {
cout << L - tuki << '\n';
}
return 0;
}
|
[["-", 0, 57, 64, 9, 0, 1, 0, 27, 28, 22], ["+", 0, 57, 64, 9, 0, 1, 0, 27, 28, 22]]
| 1
| 131
| 4
|
#include <iostream>
using namespace std;
int main() {
int L, A, B, C, D, K, E, F;
cin >> L >> A >> B >> C >> D;
E = A / C;
F = B / D;
if (A % C > 0) {
E += 1;
}
if (B % D > 0) {
F += 1;
}
if (E < F) {
K = L - E;
} else
K = L - F;
cout << K << '\n';
return 0;
}
|
#include <iostream>
using namespace std;
int main() {
int L, A, B, C, D, K, E, F;
cin >> L >> A >> B >> C >> D;
E = A / C;
F = B / D;
if (A % C > 0) {
E += 1;
}
if (B % D > 0) {
F += 1;
}
if (E > F) {
K = L - E;
} else
K = L - F;
cout << K << '\n';
return 0;
}
|
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 18], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 47]]
| 1
| 113
| 2
|
#include <iostream>
using namespace std;
int main() {
int L, A, B, C, D, a, b;
cin >> L;
cin >> A;
cin >> B;
cin >> C;
cin >> D;
a = A / C;
b = B / D;
if (A % C > 0)
a++;
if (B % D > 0)
b++;
if (a > b)
cout << L - a << '\n';
if (a < b)
cout << L - b << '\n';
return 0;
}
|
#include <iostream>
using namespace std;
int main() {
int L, A, B, C, D, a, b;
cin >> L;
cin >> A;
cin >> B;
cin >> C;
cin >> D;
a = A / C;
b = B / D;
if (A % C > 0)
a++;
if (B % D > 0)
b++;
if (a > b)
cout << L - a << '\n';
else
cout << L - b << '\n';
return 0;
}
|
[["-", 0, 30, 0, 14, 8, 9, 0, 57, 0, 121], ["-", 0, 14, 8, 9, 0, 57, 15, 339, 0, 24], ["-", 8, 9, 0, 57, 15, 339, 51, 16, 31, 22], ["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 18], ["-", 8, 9, 0, 57, 15, 339, 51, 16, 12, 22], ["-", 0, 14, 8, 9, 0, 57, 15, 339, 0, 25], ["+", 0, 14, 8, 9, 0, 57, 75, 76, 0, 95]]
| 1
| 116
| 7
|
#include <algorithm>
#include <cmath>
#include <iostream>
using namespace std;
#define REP(i, n) for (int i = 0; i < (n); ++i)
int main() {
int l, a, b, c, d;
cin >> l >> a >> b >> c >> d;
int day = max(ceil((double)a / c), ceil((double)c / d));
int ans = l - day;
cout << ans << endl;
return 0;
}
|
#include <algorithm>
#include <cmath>
#include <iostream>
using namespace std;
#define REP(i, n) for (int i = 0; i < (n); ++i)
int main() {
int l, a, b, c, d;
cin >> l >> a >> b >> c >> d;
int day = max(ceil((double)a / c), ceil((double)b / d));
int ans = l - day;
cout << ans << endl;
return 0;
}
|
[["-", 0, 2, 3, 4, 0, 16, 31, 74, 51, 22], ["+", 0, 2, 3, 4, 0, 16, 31, 74, 51, 22]]
| 1
| 89
| 2
|
#include <algorithm>
#include <iostream>
using namespace std;
int main() {
int a, b, c, d, e;
cin >> a >> b >> c >> d >> e;
cout << a - max(b / d + (b % c == 0 ? 0 : 1), c / e + (c % e == 0 ? 0 : 1))
<< endl;
}
|
#include <algorithm>
#include <iostream>
using namespace std;
int main() {
int a, b, c, d, e;
cin >> a >> b >> c >> d >> e;
cout << a - max(b / d + (b % d == 0 ? 0 : 1), c / e + (c % e == 0 ? 0 : 1))
<< endl;
}
|
[["-", 12, 23, 0, 41, 15, 16, 31, 16, 12, 22], ["+", 12, 23, 0, 41, 15, 16, 31, 16, 12, 22]]
| 1
| 78
| 2
|
#include "bits/stdc++.h"
#include <unordered_map>
#include <unordered_set>
#pragma warning(disable : 4996)
using namespace std;
using ld = long double;
template <class T> using Table = vector<vector<T>>;
const ld eps = 1e-9;
//// < "D:\D_Download\Visual Studio
///2015\Projects\programing_contest_c++\Debug\a.txt" > "D:\D_Download\Visual
///Studio 2015\Projects\programing_contest_c++\Debug\b.answer"
int main() {
int L, A, B, C, D;
cin >> L >> A >> B >> C >> D;
int a = (A + 1) / C + 1;
int b = (B + 1) / D + 1;
cout << L - max(a, b) << endl;
return 0;
}
|
#include "bits/stdc++.h"
#include <unordered_map>
#include <unordered_set>
#pragma warning(disable : 4996)
using namespace std;
using ld = long double;
template <class T> using Table = vector<vector<T>>;
const ld eps = 1e-9;
//// < "D:\D_Download\Visual Studio
///2015\Projects\programing_contest_c++\Debug\a.txt" > "D:\D_Download\Visual
///Studio 2015\Projects\programing_contest_c++\Debug\b.answer"
int main() {
int L, A, B, C, D;
cin >> L >> A >> B >> C >> D;
int a = (A - 1) / C + 1;
int b = (B - 1) / D + 1;
cout << L - max(a, b) << endl;
return 0;
}
|
[["-", 51, 16, 31, 16, 31, 23, 0, 16, 17, 72], ["+", 51, 16, 31, 16, 31, 23, 0, 16, 17, 33]]
| 1
| 116
| 4
|
#include <iostream>
using namespace std;
int main() {
int l, a, b, c, d, e, f, m;
cin >> l >> a >> b >> c >> d;
e = a / c;
m = a % c;
if (m != 0)
e++;
f = b / d;
m = b % c;
if (m != 0)
f++;
if (e > f) {
cout << l - e << endl;
} else {
cout << l - f << endl;
}
return 0;
}
|
#include <iostream>
using namespace std;
int main() {
int l, a, b, c, d, e, f, m;
cin >> l >> a >> b >> c >> d;
e = a / c;
m = a % c;
if (m != 0)
e++;
f = b / d;
m = b % d;
if (m != 0)
f++;
if (e > f) {
cout << l - e << endl;
} else {
cout << l - f << endl;
}
return 0;
}
|
[["-", 8, 9, 0, 1, 0, 11, 12, 16, 12, 22], ["+", 8, 9, 0, 1, 0, 11, 12, 16, 12, 22]]
| 1
| 113
| 2
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c, d, e;
scanf("%d%d%d%d%d", &a, &b, &c, &d, &e);
(b % d) ? (b = b / d + 1) : (b = b / d);
(c % e) ? (c = c / e + 1) : (c = c / e);
printf("%d\n", 20 - max(b, c));
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c, d, e;
scanf("%d%d%d%d%d", &a, &b, &c, &d, &e);
(b % d) ? (b = b / d + 1) : (b = b / d);
(c % e) ? (c = c / e + 1) : (c = c / e);
printf("%d\n", a - max(b, c));
}
|
[["-", 0, 1, 0, 2, 3, 4, 0, 16, 31, 13], ["+", 0, 1, 0, 2, 3, 4, 0, 16, 31, 22]]
| 1
| 110
| 2
|
#include <iostream>
using namespace std;
int main() {
int l, a, b, c, d;
cin >> l >> a >> b >> c >> d;
while (a > 0 && b > 0) {
a -= c;
b -= d;
--l;
}
cout << l << endl;
}
|
#include <iostream>
using namespace std;
int main() {
int l, a, b, c, d;
cin >> l >> a >> b >> c >> d;
while (a > 0 || b > 0) {
a -= c;
b -= d;
--l;
}
cout << l << endl;
}
|
[["-", 8, 9, 0, 52, 15, 339, 51, 16, 17, 98], ["+", 8, 9, 0, 52, 15, 339, 51, 16, 17, 106]]
| 1
| 64
| 2
|
#include <iostream>
using namespace std;
int main() {
int l, a, b, c, d;
cin >> l >> a >> b >> c >> d;
while (a > 0 && b > 0) {
a -= c;
b -= d;
l--;
}
cout << l << endl;
return 0;
}
|
#include <iostream>
using namespace std;
int main() {
int l, a, b, c, d;
cin >> l >> a >> b >> c >> d;
while (a > 0 || b > 0) {
a -= c;
b -= d;
l--;
}
cout << l << endl;
return 0;
}
|
[["-", 8, 9, 0, 52, 15, 339, 51, 16, 17, 98], ["+", 8, 9, 0, 52, 15, 339, 51, 16, 17, 106]]
| 1
| 67
| 2
|
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;
//#define int long long
#define DBG 1
#define dump(o) \
if (DBG) { \
cerr << #o << " " << o << endl; \
}
#define dumpc(o) \
if (DBG) { \
cerr << #o; \
for (auto &e : (o)) \
cerr << " " << e; \
cerr << endl; \
}
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define each(it, c) for (auto it = (c).begin(); it != (c).end(); it++)
#define all(c) c.begin(), c.end()
const int INF =
sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);
const double EPS = 1e-10;
signed main() {
int l, a, b, c, d;
cin >> l >> a >> b >> c >> d;
cout << l - max((a + c - 1 / c), (b + d - 1 / d)) << endl;
return 0;
}
|
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;
//#define int long long
#define DBG 1
#define dump(o) \
if (DBG) { \
cerr << #o << " " << o << endl; \
}
#define dumpc(o) \
if (DBG) { \
cerr << #o; \
for (auto &e : (o)) \
cerr << " " << e; \
cerr << endl; \
}
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define each(it, c) for (auto it = (c).begin(); it != (c).end(); it++)
#define all(c) c.begin(), c.end()
const int INF =
sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);
const double EPS = 1e-10;
signed main() {
int l, a, b, c, d;
cin >> l >> a >> b >> c >> d;
cout << l - max((a + c - 1) / c, (b + d - 1) / d) << endl;
return 0;
}
|
[["+", 12, 2, 3, 4, 0, 16, 31, 23, 0, 25], ["-", 12, 16, 12, 2, 3, 4, 0, 23, 0, 25]]
| 1
| 161
| 4
|
#include <algorithm>
#include <iostream>
using namespace std;
int main() {
int a, b, c, d, l;
cin >> l >> a >> b >> c >> d;
int da = a / c;
if (a - da * c > 0)
da++;
int db = b / d;
if (b - da * d > 0)
db++;
cout << l - max(da, db) << endl;
return 0;
}
|
#include <algorithm>
#include <iostream>
using namespace std;
int main() {
int a, b, c, d, l;
cin >> l >> a >> b >> c >> d;
int da = a / c;
if (a - da * c > 0)
da++;
int db = b / d;
if (b - db * d > 0)
db++;
cout << l - max(da, db) << endl;
return 0;
}
|
[["-", 15, 339, 51, 16, 31, 16, 12, 16, 31, 22], ["+", 15, 339, 51, 16, 31, 16, 12, 16, 31, 22]]
| 1
| 93
| 2
|
#include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
int main() {
int l;
int a, b;
int c, d;
int ans;
int j, m;
scanf(" %d %d %d %d %d", &l, &a, &b, &c, &d);
j = m = 0;
if (a % c != 0) {
j = 1;
}
if (b % d != 0) {
m = 1;
}
ans = max(a / b + j, b / d + m);
printf("%d\n", l - ans);
return 0;
}
|
#include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
int main() {
int l;
int a, b;
int c, d;
int ans;
int j, m;
scanf(" %d %d %d %d %d", &l, &a, &b, &c, &d);
j = m = 0;
if (a % c != 0) {
j = 1;
}
if (b % d != 0) {
m = 1;
}
ans = max(a / c + j, b / d + m);
printf("%d\n", l - ans);
return 0;
}
|
[["-", 12, 2, 3, 4, 0, 16, 31, 16, 12, 22], ["+", 12, 2, 3, 4, 0, 16, 31, 16, 12, 22]]
| 1
| 125
| 2
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int homework[5] = {
0}; //{ day , Japanese , Math , maxJapanesePage , maxMathPage }
int freeday = 0;
for (int i = 0; i < 5; i++) {
cin >> homework[i];
}
freeday = homework[0] - max(ceil((double)homework[1] / homework[3]),
ceil((double)homework[3] / homework[4]));
cout << freeday << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int homework[5] = {
0}; //{ day , Japanese , Math , maxJapanesePage , maxMathPage }
int freeday = 0;
for (int i = 0; i < 5; i++) {
cin >> homework[i];
}
freeday = homework[0] - max(ceil((double)homework[1] / homework[3]),
ceil((double)homework[2] / homework[4]));
cout << freeday << endl;
return 0;
}
|
[["-", 0, 16, 31, 74, 51, 69, 341, 342, 0, 13], ["+", 0, 16, 31, 74, 51, 69, 341, 342, 0, 13]]
| 1
| 102
| 2
|
#include <iostream>
using namespace std;
int main(void) {
// Your code here!
int L, A, B, C, D, AC, BD;
cin >> L >> A >> B >> C >> D;
if (A % C == 0)
AC = L - (A / C);
else
AC = L - (A / C + 1);
if (B % D == 0)
BD = L - (B / D);
else
BD = L - (B / D + 1);
if (AC > BD)
cout << AC << endl;
else
cout << BD << endl;
}
|
#include <iostream>
using namespace std;
int main(void) {
// Your code here!
int L, A, B, C, D, AC, BD;
cin >> L >> A >> B >> C >> D;
if (A % C == 0)
AC = L - (A / C);
else
AC = L - (A / C + 1);
if (B % D == 0)
BD = L - (B / D);
else
BD = L - (B / D + 1);
if (AC < BD)
cout << AC << endl;
else
cout << BD << endl;
}
|
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 47], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 18]]
| 1
| 122
| 2
|
#include <stdio.h>
int main(void) {
int l, a, b, c, d, x, y, z;
scanf("%d %d %d %d %d", &l, &a, &b, &c, &d);
x = a % c;
if (a % c > 0) {
x + 1;
}
y = b % d;
if (b % d > 0) {
y + 1;
}
if (x > y) {
z = l - x;
} else {
z = l - y;
}
printf("%d\n", z);
return 0;
}
|
#include <stdio.h>
int main(void) {
int l, a, b, c, d, x, y, z;
scanf("%d %d %d %d %d", &l, &a, &b, &c, &d);
x = a / c;
if (a % c > 0) {
x += 1;
}
y = b / d;
if (b % d > 0) {
y += 1;
}
if (x > y) {
z = l - x;
} else {
z = l - y;
}
printf("%d\n", z);
return 0;
}
|
[["-", 8, 9, 0, 1, 0, 11, 12, 16, 17, 109], ["+", 8, 9, 0, 1, 0, 11, 12, 16, 17, 85], ["-", 0, 57, 64, 9, 0, 1, 0, 16, 17, 72], ["+", 0, 57, 64, 9, 0, 1, 0, 11, 17, 107]]
| 1
| 124
| 8
|
#include <iostream>
using namespace std;
int main() {
int a, b, c, d, l, x, y, z;
cin >> l >> a >> b >> c >> d;
if (a % c > 0) {
x = a / c + 1;
} else {
x = a / c;
}
if (b % d > 0) {
x = b / d + 1;
} else {
x = b / d;
}
z = max(x, y);
cout << l - z << endl;
return 0;
}
|
#include <iostream>
using namespace std;
int main() {
int a, b, c, d, l, x, y, z;
cin >> l >> a >> b >> c >> d;
if (a % c > 0) {
x = a / c + 1;
} else {
x = a / c;
}
if (b % d > 0) {
y = b / d + 1;
} else {
y = b / d;
}
z = max(x, y);
cout << l - z << endl;
return 0;
}
|
[["-", 0, 57, 64, 9, 0, 1, 0, 11, 31, 22], ["+", 0, 57, 64, 9, 0, 1, 0, 11, 31, 22], ["-", 75, 76, 0, 9, 0, 1, 0, 11, 31, 22], ["+", 75, 76, 0, 9, 0, 1, 0, 11, 31, 22]]
| 1
| 115
| 4
|
#include <iostream>
#include <string>
using namespace std;
int main() {
/*
int a,b,c,d,e;
cin >> a >> b >> c >> d >> e;
int x;
if(a > 0){
x = e*(b-a);
}
if(a == 0){
x = e*b + d;
}
if(a < 0){
x = -c*a + e*b + d;
}
cout << x <<endl;
*/
/*
int a,b,c,d,e,f;
cin >> a >> b >> c >> d >> e >> f;
int m,n;
int x = a + b + c + d + e + f;
if(e<f)
{
x = x - e;
if(a<b)
{
if(a<c)
{
if(a<d)
{
cout << x-a << endl;
}
else
{
cout << x-d << endl;
}
}
else
{
if(c<d)
{
cout << x-c << endl;
}
else
{
cout << x-d << endl;
}
}
}
else
{
if(b<c)
{
if(b<d)
{
cout << x-b << endl;
}
else
{
cout << x-d << endl;
}
}
else
{
if(c<d)
{
cout << x-c << endl;
}
else
{
cout << x-d << endl;
}
}
}
}
else
{
x = x - f;
if(a<b)
{
if(a<c)
{
if(a<d)
{
cout << x-a << endl;
}
else
{
cout << x-d << endl;
}
}
else
{
if(c<d)
{
cout << x-c << endl;
}
else
{
cout << x-d << endl;
}
}
}
else
{
if(b<c)
{
if(b<d)
{
cout << x-b << endl;
}
else
{
cout << x-d << endl;
}
}
else
{
if(c<d)
{
cout << x-c << endl;
}
else
{
cout << x-d << endl;
}
}
}
}
*/
/*
int n;
cin >> n;
int a;
cin >> a;
int max = a,min = a;
int i = 1;
while(i<n){
cin >> a;
if(a > max){
max = a;
}
if(a < min){
min = a;
}
i++;
}
cout << max << endl << min << endl;
*/
/*
string s;
cin >> s;
int j,o,i;
for(int i;i < s.size;i++){
}
*/
/*
int n;
cin >> n;
int A;
int X[100000];
int n=0;
for(int i=0;i<n;i++){
cin >> A;
}
*/
/*
int a,b,c,d,p;
cin >> a >> b >> c >> d >> p;
int X,Y=b;
X = a*p;
if(p>c){
Y += d*(p-c);
}
if(X > Y){
cout << Y << endl;
}
else{
cout << X << endl;
}
*/
int l, a, b, c, d;
cin >> l >> a >> b >> c >> d;
int Jap = a / c;
if (a % c != 0) {
Jap += 1;
}
int Math = b / d;
if (b % d != 0) {
Math += 1;
}
int day;
if (Jap < Math) {
day = Math;
}
cout << l - day << endl;
return 0;
}
|
#include <iostream>
#include <string>
using namespace std;
int main() {
/*
int a,b,c,d,e;
cin >> a >> b >> c >> d >> e;
int x;
if(a > 0){
x = e*(b-a);
}
if(a == 0){
x = e*b + d;
}
if(a < 0){
x = -c*a + e*b + d;
}
cout << x <<endl;
*/
/*
int a,b,c,d,e,f;
cin >> a >> b >> c >> d >> e >> f;
int m,n;
int x = a + b + c + d + e + f;
if(e<f)
{
x = x - e;
if(a<b)
{
if(a<c)
{
if(a<d)
{
cout << x-a << endl;
}
else
{
cout << x-d << endl;
}
}
else
{
if(c<d)
{
cout << x-c << endl;
}
else
{
cout << x-d << endl;
}
}
}
else
{
if(b<c)
{
if(b<d)
{
cout << x-b << endl;
}
else
{
cout << x-d << endl;
}
}
else
{
if(c<d)
{
cout << x-c << endl;
}
else
{
cout << x-d << endl;
}
}
}
}
else
{
x = x - f;
if(a<b)
{
if(a<c)
{
if(a<d)
{
cout << x-a << endl;
}
else
{
cout << x-d << endl;
}
}
else
{
if(c<d)
{
cout << x-c << endl;
}
else
{
cout << x-d << endl;
}
}
}
else
{
if(b<c)
{
if(b<d)
{
cout << x-b << endl;
}
else
{
cout << x-d << endl;
}
}
else
{
if(c<d)
{
cout << x-c << endl;
}
else
{
cout << x-d << endl;
}
}
}
}
*/
/*
int n;
cin >> n;
int a;
cin >> a;
int max = a,min = a;
int i = 1;
while(i<n){
cin >> a;
if(a > max){
max = a;
}
if(a < min){
min = a;
}
i++;
}
cout << max << endl << min << endl;
*/
/*
string s;
cin >> s;
int j,o,i;
for(int i;i < s.size;i++){
}
*/
/*
int n;
cin >> n;
int A;
int X[100000];
int n=0;
for(int i=0;i<n;i++){
cin >> A;
}
*/
/*
int a,b,c,d,p;
cin >> a >> b >> c >> d >> p;
int X,Y=b;
X = a*p;
if(p>c){
Y += d*(p-c);
}
if(X > Y){
cout << Y << endl;
}
else{
cout << X << endl;
}
*/
int l, a, b, c, d;
cin >> l >> a >> b >> c >> d;
int Jap = a / c;
if (a % c != 0) {
Jap += 1;
}
int Math = b / d;
if (b % d != 0) {
Math += 1;
}
int day = Jap;
if (Jap < Math) {
day = Math;
}
cout << l - day << endl;
return 0;
}
|
[["+", 0, 14, 8, 9, 0, 43, 49, 50, 0, 32], ["+", 0, 14, 8, 9, 0, 43, 49, 50, 51, 22]]
| 1
| 111
| 2
|
#include <iostream>
using namespace std;
int main() {
int L, A, B, C, D;
cin >> L >> A >> B >> C >> D;
cout << L - max((A + C - 1) / C, (B + D - 1) / B) << endl;
}
|
#include <iostream>
using namespace std;
int main() {
int L, A, B, C, D;
cin >> L >> A >> B >> C >> D;
cout << L - max((A + C - 1) / C, (B + D - 1) / D) << endl;
}
|
[["-", 12, 16, 12, 2, 3, 4, 0, 16, 12, 22], ["+", 12, 16, 12, 2, 3, 4, 0, 16, 12, 22]]
| 1
| 64
| 2
|
#include <iostream>
using namespace std;
int main(void) {
int l, a, b, c, d, p, q, ans;
cin >> l >> a >> b >> c >> d;
p = a / c;
a = a % c;
p += (a) ? 1 : 0;
q = b / d;
b = b % c;
q += (b) ? 1 : 0;
cout << l - ((p > q) ? p : q) << endl;
return 0;
}
|
#include <iostream>
using namespace std;
int main(void) {
int l, a, b, c, d, p, q, ans;
cin >> l >> a >> b >> c >> d;
p = a / c;
a = a % c;
p += (a) ? 1 : 0;
q = b / d;
b = b % d;
q += (b) ? 1 : 0;
cout << l - ((p > q) ? p : q) << endl;
return 0;
}
|
[["-", 8, 9, 0, 1, 0, 11, 12, 16, 12, 22], ["+", 8, 9, 0, 1, 0, 11, 12, 16, 12, 22]]
| 1
| 107
| 2
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
typedef long long ll;
int main() {
int L, A, B, C, D;
cin >> L >> A >> B >> C >> D;
cout << L - max(A / C + (A % C != 0), B / D + (B % C != 0)) << endl;
return 0;
}
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
typedef long long ll;
int main() {
int L, A, B, C, D;
cin >> L >> A >> B >> C >> D;
cout << L - max(A / C + (A % C != 0), B / D + (B % D != 0)) << endl;
return 0;
}
|
[["-", 0, 16, 12, 23, 0, 16, 31, 16, 12, 22], ["+", 0, 16, 12, 23, 0, 16, 31, 16, 12, 22]]
| 1
| 116
| 2
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define reep(n1, n2, n3) for (int n1 = n3; n1 < n2; n1++)
#define rep(n1, n2) reep(n1, n2, 0)
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define INF 1e9
using namespace std;
typedef long long int lint;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<pair<int, int>> vp;
typedef pair<int, int> pi;
typedef pair<int, pair<int, int>> pii;
typedef vector<string> vs;
const double PI = acos(-1.0);
int main() {
int a, b, c, d, l;
cin >> l >> a >> b >> c >> d;
cout << l - max((a + c) / c, (b + d) / d) << endl;
}
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define reep(n1, n2, n3) for (int n1 = n3; n1 < n2; n1++)
#define rep(n1, n2) reep(n1, n2, 0)
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define INF 1e9
using namespace std;
typedef long long int lint;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<pair<int, int>> vp;
typedef pair<int, int> pi;
typedef pair<int, pair<int, int>> pii;
typedef vector<string> vs;
const double PI = acos(-1.0);
int main() {
int a, b, c, d, l;
cin >> l >> a >> b >> c >> d;
cout << l - max((a + c - 1) / c, (b + d - 1) / d) << endl;
}
|
[["+", 3, 4, 0, 16, 31, 23, 0, 16, 17, 33], ["+", 3, 4, 0, 16, 31, 23, 0, 16, 12, 13]]
| 1
| 194
| 4
|
#include <iostream>
using namespace std;
int main() {
int natu, suugaku, kokugo, suu, koku;
cin >> natu >> kokugo >> suugaku >> koku >> suu;
int km = (kokugo / koku);
if (kokugo % koku > 0)
km++;
int sm = (suugaku / suu);
if (suugaku % suu > 0)
suu++;
if (km > sm) {
cout << natu - km << endl;
} else {
cout << natu - sm << endl;
}
return 0;
}
|
#include <iostream>
using namespace std;
int main() {
int natu, suugaku, kokugo, suu, koku;
cin >> natu >> kokugo >> suugaku >> koku >> suu;
int km = (kokugo / koku);
if (kokugo % koku > 0)
km++;
int sm = (suugaku / suu);
if (suugaku % suu > 0)
sm++;
if (km > sm) {
cout << natu - km << endl;
} else {
cout << natu - sm << endl;
}
return 0;
}
|
[["-", 8, 9, 0, 57, 64, 1, 0, 27, 28, 22], ["+", 8, 9, 0, 57, 64, 1, 0, 27, 28, 22]]
| 1
| 105
| 2
|
#include <algorithm>
#include <iostream>
using namespace std;
int main() {
int p, a, b, c, d, x, y;
cin >> p;
cin >> a;
cin >> b;
cin >> c;
cin >> d;
x = a / c;
if (a % c)
x++;
y = b / d;
if (b & d)
y++;
cout << p - max(x, y) << endl;
return 0;
}
|
#include <algorithm>
#include <iostream>
using namespace std;
int main() {
int p, a, b, c, d, x, y;
cin >> p;
cin >> a;
cin >> b;
cin >> c;
cin >> d;
x = a / c;
if (a % c)
x++;
y = b / d;
if (b % d)
y++;
cout << p - max(x, y) << endl;
return 0;
}
|
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 67], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 109]]
| 1
| 95
| 2
|
#include <stdio.h>
#define max(A, B) (A > B ? A : B)
int l, a, b, c, d;
main() {
scanf("%d%d%d%d%d", &l, &a, &b, &c, &d);
printf("%d\n", l - max(a / c + !!a % c, b / d + !!b % d));
return 0;
}
|
#include <stdio.h>
#define max(A, B) (A > B ? A : B)
int l, a, b, c, d;
main() {
scanf("%d%d%d%d%d", &l, &a, &b, &c, &d);
printf("%d\n", l - max(a / c + !!(a % c), b / d + !!(b % d)));
return 0;
}
|
[["+", 0, 16, 12, 91, 28, 91, 28, 23, 0, 24], ["+", 0, 16, 12, 91, 28, 91, 28, 23, 0, 25]]
| 1
| 84
| 4
|
l=gets.chomp.to_i
a=gets.chomp.to_i
b=gets.chomp.to_i
c=gets.chomp.to_i
d=gets.chomp.to_i
m=a/c
n=b/d
if a%c>0
m+=1
end
if b%d>0
n+=1
end
puts 1-[m,n].max
|
l=gets.chomp.to_i
a=gets.chomp.to_i
b=gets.chomp.to_i
c=gets.chomp.to_i
d=gets.chomp.to_i
m=a/c
n=b/d
if a%c>0
m+=1
end
if b%d>0
n+=1
end
puts l-[m,n].max
|
[["-", 0, 493, 0, 652, 3, 4, 0, 738, 31, 612], ["+", 0, 493, 0, 652, 3, 4, 0, 738, 31, 22]]
| 4
| 75
| 2
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
using namespace std;
const long double eps = 1e-12;
typedef long long ll;
typedef pair<int, int> pt;
#define sz(a) ((int)a.size())
#define LL(x) (x << 1)
#define RR(x) ((x << 1) | 1)
#define For(i, a, b) for (int i = a; i <= b; i++)
#define Ford(i, a, b) for (int i = a; i >= b; i--)
#define Rep(i, n) for (int i = 0; i < n; i++)
const int maxn = 200000 + 1912;
int n, m, K, Q;
struct edge {
int u, v, w;
};
vector<edge> V[maxn];
vector<pt> e;
bool fes[maxn];
void ReadData() {
cin >> n >> m >> K >> Q;
For(i, 1, m) {
int u, v, w;
cin >> u >> v >> w;
V[u].push_back((edge){u, v, w});
V[v].push_back((edge){v, u, w});
e.push_back(make_pair(u, v));
}
For(i, 1, K) {
int x;
cin >> x;
fes[x] = true;
}
}
const long long INF = 1000LL * 1000 * 1000 * 1000 * 1000 * 1000 + 1912;
long long d[maxn];
priority_queue<pair<long long, int>> qu;
void Dijkstra() {
For(i, 1, n) d[i] = INF;
For(i, 1, n) if (fes[i]) {
d[i] = 0;
qu.push(make_pair(0, i));
}
while (sz(qu)) {
pair<long long, int> tt = qu.top();
qu.pop();
long long cur = -tt.first;
int u = tt.second;
if (d[u] != cur)
continue;
Rep(i, sz(V[u])) {
int v = V[u][i].v, w = V[u][i].w;
if (d[v] > d[u] + w) {
d[v] = d[u] + w;
qu.push(make_pair(-d[v], v));
}
}
}
}
//--------------------------------------------------------------------------
int lab[maxn];
int fin(int u) { return lab[u] <= 0 ? u : lab[u] = fin(lab[u]); }
void Join(int a, int b) {
if (lab[a] < lab[b])
lab[b] = a;
else {
if (lab[a] == lab[b])
lab[b]--;
lab[b] = a;
}
}
bool ProcessEdge(int a, int b) {
a = fin(a), b = fin(b);
if (a != b) {
Join(a, b);
return true;
}
return false;
}
//--------------------------------------------------------------------------
bool cmp(pt a, pt b) {
return min(d[a.first], d[a.second]) < min(d[b.first], d[b.second]);
}
const int lg = 17;
vector<pair<int, long long>> E[maxn];
int level[maxn], papa[maxn][lg + 2];
long long dp[maxn][lg + 2];
inline void dfs(const int u, const int prev) {
Rep(i, sz(E[u])) {
int v = E[u][i].first;
if (v == prev)
continue;
long long w = E[u][i].second;
papa[v][0] = u;
dp[v][0] = w;
level[v] = level[u] + 1;
dfs(v, u);
}
}
long long Query(int p, int q) {
long long res = INF;
if (level[p] > level[q])
swap(p, q);
int diff = level[q] - level[p];
Rep(i, lg + 1) if ((diff >> i) & 1) {
res = min(res, dp[q][i]);
q = papa[q][i];
}
if (p != q) {
Ford(i, lg, 0) if (papa[q][i] != papa[p][i]) {
res = min(res, min(dp[p][i], dp[q][i]));
q = papa[q][i], p = papa[p][i];
}
res = min(res, min(dp[p][0], dp[q][0]));
}
return res;
}
void Process() {
Dijkstra();
sort(e.begin(), e.end());
Ford(i, sz(e) - 1, 0) {
int u = e[i].first, v = e[i].second;
if (ProcessEdge(u, v)) {
E[u].push_back(make_pair(v, min(d[u], d[v])));
E[v].push_back(make_pair(u, min(d[u], d[v])));
}
}
dfs(1, 0);
For(i, 1, lg) For(u, 1, n) papa[u][i] = papa[papa[u][i - 1]][i - 1];
For(i, 1, lg) For(u, 1, n) dp[u][i] =
min(dp[u][i - 1], dp[papa[u][i - 1]][i - 1]);
while (Q--) {
int s, t;
cin >> s >> t;
cout << Query(s, t) << "\n";
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
// freopen("/users/youaremysky/documents/workspace/input.inp" , "r" , stdin);
ReadData();
Process();
}
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
using namespace std;
const long double eps = 1e-12;
typedef long long ll;
typedef pair<int, int> pt;
#define sz(a) ((int)a.size())
#define LL(x) (x << 1)
#define RR(x) ((x << 1) | 1)
#define For(i, a, b) for (int i = a; i <= b; i++)
#define Ford(i, a, b) for (int i = a; i >= b; i--)
#define Rep(i, n) for (int i = 0; i < n; i++)
const int maxn = 200000 + 1912;
int n, m, K, Q;
struct edge {
int u, v, w;
};
vector<edge> V[maxn];
vector<pt> e;
bool fes[maxn];
void ReadData() {
cin >> n >> m >> K >> Q;
For(i, 1, m) {
int u, v, w;
cin >> u >> v >> w;
V[u].push_back((edge){u, v, w});
V[v].push_back((edge){v, u, w});
e.push_back(make_pair(u, v));
}
For(i, 1, K) {
int x;
cin >> x;
fes[x] = true;
}
}
const long long INF = 1000LL * 1000 * 1000 * 1000 * 1000 * 1000 + 1912;
long long d[maxn];
priority_queue<pair<long long, int>> qu;
void Dijkstra() {
For(i, 1, n) d[i] = INF;
For(i, 1, n) if (fes[i]) {
d[i] = 0;
qu.push(make_pair(0, i));
}
while (sz(qu)) {
pair<long long, int> tt = qu.top();
qu.pop();
long long cur = -tt.first;
int u = tt.second;
if (d[u] != cur)
continue;
Rep(i, sz(V[u])) {
int v = V[u][i].v, w = V[u][i].w;
if (d[v] > d[u] + w) {
d[v] = d[u] + w;
qu.push(make_pair(-d[v], v));
}
}
}
}
//--------------------------------------------------------------------------
int lab[maxn];
int fin(int u) { return lab[u] <= 0 ? u : lab[u] = fin(lab[u]); }
void Join(int a, int b) {
if (lab[a] < lab[b])
lab[b] = a;
else {
if (lab[a] == lab[b])
lab[b]--;
lab[b] = a;
}
}
bool ProcessEdge(int a, int b) {
a = fin(a), b = fin(b);
if (a != b) {
Join(a, b);
return true;
}
return false;
}
//--------------------------------------------------------------------------
bool cmp(pt a, pt b) {
return min(d[a.first], d[a.second]) < min(d[b.first], d[b.second]);
}
const int lg = 17;
vector<pair<int, long long>> E[maxn];
int level[maxn], papa[maxn][lg + 2];
long long dp[maxn][lg + 2];
inline void dfs(const int u, const int prev) {
Rep(i, sz(E[u])) {
int v = E[u][i].first;
if (v == prev)
continue;
long long w = E[u][i].second;
papa[v][0] = u;
dp[v][0] = w;
level[v] = level[u] + 1;
dfs(v, u);
}
}
long long Query(int p, int q) {
long long res = INF;
if (level[p] > level[q])
swap(p, q);
int diff = level[q] - level[p];
Rep(i, lg + 1) if ((diff >> i) & 1) {
res = min(res, dp[q][i]);
q = papa[q][i];
}
if (p != q) {
Ford(i, lg, 0) if (papa[q][i] != papa[p][i]) {
res = min(res, min(dp[p][i], dp[q][i]));
q = papa[q][i], p = papa[p][i];
}
res = min(res, min(dp[p][0], dp[q][0]));
}
return res;
}
void Process() {
Dijkstra();
sort(e.begin(), e.end(), cmp);
Ford(i, sz(e) - 1, 0) {
int u = e[i].first, v = e[i].second;
if (ProcessEdge(u, v)) {
E[u].push_back(make_pair(v, min(d[u], d[v])));
E[v].push_back(make_pair(u, min(d[u], d[v])));
}
}
dfs(1, 0);
For(i, 1, lg) For(u, 1, n) papa[u][i] = papa[papa[u][i - 1]][i - 1];
For(i, 1, lg) For(u, 1, n) dp[u][i] =
min(dp[u][i - 1], dp[papa[u][i - 1]][i - 1]);
while (Q--) {
int s, t;
cin >> s >> t;
cout << Query(s, t) << "\n";
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
// freopen("/users/youaremysky/documents/workspace/input.inp" , "r" , stdin);
ReadData();
Process();
}
|
[["+", 8, 9, 0, 1, 0, 2, 3, 4, 0, 21], ["+", 8, 9, 0, 1, 0, 2, 3, 4, 0, 22]]
| 1
| 1,331
| 2
|
import java.util.Scanner;
public class Main {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
int l = sc.nextInt();
double a = sc.nextInt();
double b = sc.nextInt();
double c = sc.nextInt();
double d = sc.nextInt();
int j, m;
j = (int)Math.ceil(a / c);
m = (int)Math.ceil(b / d);
if (j > m)
System.out.println(j);
else
System.out.println(m);
}
}
|
import java.util.Scanner;
public class Main {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
int l = sc.nextInt();
double a = sc.nextInt();
double b = sc.nextInt();
double c = sc.nextInt();
double d = sc.nextInt();
int j, m;
j = (int)Math.ceil(a / c);
m = (int)Math.ceil(b / d);
if (j > m)
System.out.println(l - j);
else
System.out.println(l - m);
}
}
|
[["+", 64, 1, 0, 492, 3, 4, 0, 16, 31, 22], ["+", 64, 1, 0, 492, 3, 4, 0, 16, 17, 33], ["+", 75, 1, 0, 492, 3, 4, 0, 16, 31, 22], ["+", 75, 1, 0, 492, 3, 4, 0, 16, 17, 33]]
| 3
| 138
| 4
|
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int l = sc.nextInt();
int a = sc.nextInt();
int b = sc.nextInt();
int c = sc.nextInt();
int d = sc.nextInt();
int l1 = a / c;
int l2 = b / d;
if (a % c != 0)
l1 += 1;
if (b % d != 0)
l2 += 1;
if (l1 < l2)
l1 = l2;
System.out.println(l1);
}
}
|
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int l = sc.nextInt();
int a = sc.nextInt();
int b = sc.nextInt();
int c = sc.nextInt();
int d = sc.nextInt();
int l1 = a / c;
int l2 = b / d;
if (a % c != 0)
l1 += 1;
if (b % d != 0)
l2 += 1;
if (l1 < l2)
l1 = l2;
System.out.println(l - l1);
}
}
|
[["+", 0, 1, 0, 492, 3, 4, 0, 16, 31, 22], ["+", 0, 1, 0, 492, 3, 4, 0, 16, 17, 33]]
| 3
| 137
| 2
|
#include <stdio.h>
int max(int a, int b) {
if (a >= b)
return a;
return b;
}
int main() {
int a, b, c, d, e;
int n, m;
scanf("%d %d %d %d %d", &a, &b, &c, &d, &e);
if (b % d)
n = b / d + 1;
else
n = b / d;
if (c / e)
m = c / e + 1;
else
m = c / e;
printf("%d\n", a - max(n, m));
return 0;
}
|
#include <stdio.h>
int max(int a, int b) {
if (a >= b)
return a;
return b;
}
int main() {
int a, b, c, d, e;
int n, m;
scanf("%d %d %d %d %d", &a, &b, &c, &d, &e);
if (b % d)
n = b / d + 1;
else
n = b / d;
if (c % e)
m = c / e + 1;
else
m = c / e;
printf("%d\n", a - max(n, m));
return 0;
}
|
[["-", 8, 9, 0, 57, 15, 23, 0, 16, 17, 85], ["+", 8, 9, 0, 57, 15, 23, 0, 16, 17, 109]]
| 0
| 131
| 2
|
#include <math.h>
#include <stdio.h>
int main() {
int a, b, c, d, day;
int japanese, math, play;
scanf("%d %d %d %d %d", &day, &a, &b, &c, &d);
japanese = ceil((double)a / (double)c);
math = ceil((double)b / (double)d);
if (japanese < math) {
play = day - math;
} else if (japanese > math) {
play = day - japanese;
}
printf("%d\n", play);
return 0;
}
|
#include <math.h>
#include <stdio.h>
int main() {
int a, b, c, d, day;
int japanese, math, play = 0;
scanf("%d %d %d %d %d", &day, &a, &b, &c, &d);
japanese = ceil((double)a / (double)c);
math = ceil((double)b / (double)d);
if (japanese < math) {
play = day - math;
} else if (japanese >= math) {
play = day - japanese;
}
printf("%d\n", play);
return 0;
}
|
[["+", 0, 14, 8, 9, 0, 43, 49, 50, 0, 32], ["+", 0, 14, 8, 9, 0, 43, 49, 50, 51, 13], ["-", 75, 76, 0, 57, 15, 23, 0, 16, 17, 47], ["+", 75, 76, 0, 57, 15, 23, 0, 16, 17, 20]]
| 0
| 122
| 4
|
#include <stdio.h>
int main() {
int i, A, B, C, D, L, day, x, y, ja, ma;
scanf("%d\n", &L);
scanf("%d\n", &A);
scanf("%d\n", &B);
scanf("%d\n", &C);
scanf("%d\n", &D);
ja = A / C;
ma = B / D;
x = A % C;
y = B % D;
if (x = !0) {
ja = ja + 1;
}
if (y = !0) {
ma = ma + 1;
}
if (ja > ma) {
L = L - ja;
} else {
L = L - ma;
}
printf("%d\n", L);
return 0;
}
|
#include <stdio.h>
int main() {
int i, A, B, C, D, L, day, x, y, ja, ma;
scanf("%d\n", &L);
scanf("%d\n", &A);
scanf("%d\n", &B);
scanf("%d\n", &C);
scanf("%d\n", &D);
ja = A / C;
ma = B / D;
x = A % C;
y = B % D;
if (x != 0) {
ja = ja + 1;
}
if (y != 0) {
ma = ma + 1;
}
if (ja > ma) {
L = L - ja;
} else {
L = L - ma;
}
printf("%d\n", L);
return 0;
}
|
[["-", 8, 9, 0, 57, 15, 23, 0, 11, 17, 32], ["-", 0, 57, 15, 23, 0, 11, 12, 91, 17, 111], ["+", 8, 9, 0, 57, 15, 23, 0, 16, 17, 79]]
| 0
| 176
| 6
|
#include <stdio.h>
int main() {
int L, A, B, C, D, x, y, z;
scanf("%d \n %d \n %d \n %d \n %d", &L, &A, &B, &C, &D);
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) {
z = L - x;
} else {
z = L - y;
}
printf("%d\n", z);
return 0;
}
|
#include <stdio.h>
int main() {
int L, A, B, C, D, x, y, z;
scanf("%d \n %d \n %d \n %d \n %d", &L, &A, &B, &C, &D);
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) {
z = L - x;
} else {
z = L - y;
}
printf("%d\n", z);
return 0;
}
|
[["-", 0, 57, 15, 23, 0, 16, 31, 16, 17, 85], ["+", 0, 57, 15, 23, 0, 16, 31, 16, 17, 109], ["-", 64, 9, 0, 1, 0, 11, 12, 16, 17, 109], ["+", 64, 9, 0, 1, 0, 11, 12, 16, 17, 85], ["-", 0, 1, 0, 11, 12, 16, 31, 16, 17, 109], ["+", 0, 1, 0, 11, 12, 16, 31, 16, 17, 85]]
| 0
| 145
| 12
|
#include <stdio.h>
int main(void) {
int l, a, b, c, d;
scanf("%d", &l);
scanf("%d", &a);
scanf("%d", &b);
scanf("%d", &c);
scanf("%d", &d);
if ((a - 1) / c > (b - 1) / d)
printf("%d", l - (a - 1) / c);
else
printf("%d", l - (b - 1) / d);
return 0;
}
|
#include <stdio.h>
int main(void) {
int l, a, b, c, d;
scanf("%d", &l);
scanf("%d", &a);
scanf("%d", &b);
scanf("%d", &c);
scanf("%d", &d);
if ((a - 1) / c > (b - 1) / d)
printf("%d\n", l - (a - 1) / c - 1);
else
printf("%d\n", l - (b - 1) / d - 1);
return 0;
}
|
[["+", 64, 1, 0, 2, 3, 4, 0, 5, 0, 44], ["+", 64, 1, 0, 2, 3, 4, 0, 16, 17, 33], ["+", 64, 1, 0, 2, 3, 4, 0, 16, 12, 13], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 44], ["+", 0, 1, 0, 2, 3, 4, 0, 16, 17, 33], ["+", 0, 1, 0, 2, 3, 4, 0, 16, 12, 13]]
| 0
| 126
| 6
|
#include <stdio.h>
int main() {
int a[5], i, c, d;
for (i = 0; i < 4; i++) {
scanf("%d\n", &a[i]);
}
c = a[1] / a[3];
if (a[1] % a[3] > 0)
c++;
d = a[2] / a[4];
if (a[2] % a[4] > 0)
d++;
if (c >= d) {
i = a[0] - c;
} else
i = a[0] - d;
printf("%d\n", i);
return 0;
}
|
#include <stdio.h>
int main() {
int a[5], i, c, d;
for (i = 0; i < 5; i++) {
scanf("%d\n", &a[i]);
}
c = a[1] / a[3];
if (a[1] % a[3] > 0)
c++;
d = a[2] / a[4];
if (a[2] % a[4] > 0)
d++;
if (c >= d) {
i = a[0] - c;
} else
i = a[0] - d;
printf("%d\n", i);
return 0;
}
|
[["-", 0, 14, 8, 9, 0, 7, 15, 16, 12, 13], ["+", 0, 14, 8, 9, 0, 7, 15, 16, 12, 13]]
| 0
| 147
| 2
|
#include <math.h>
#include <stdio.h>
int main(int argc, const char *argv[]) {
int l, a, b, c, d;
int jday, mday, result;
scanf("%d %d %d %d %d", &l, &a, &b, &c, &d);
if (a % c == 0) {
jday = a / c;
} else {
jday = (a / c) + 1;
}
if (b % d == 0) {
mday = b / d;
} else {
mday = (b / d) + 1;
}
if (jday > mday) {
result = 1 - jday;
} else {
result = 1 - mday;
}
printf("%d\n", result);
return 0;
}
|
#include <math.h>
#include <stdio.h>
int main(int argc, const char *argv[]) {
int l, a, b, c, d;
int jday, mday, result;
scanf("%d %d %d %d %d", &l, &a, &b, &c, &d);
if (a % c == 0) {
jday = a / c;
} else {
jday = (a / c) + 1;
}
if (b % d == 0) {
mday = b / d;
} else {
mday = (b / d) + 1;
}
if (jday > mday) {
result = l - jday;
} else {
result = l - mday;
}
printf("%d\n", result);
return 0;
}
|
[["-", 64, 9, 0, 1, 0, 11, 12, 16, 31, 13], ["+", 64, 9, 0, 1, 0, 11, 12, 16, 31, 22], ["-", 0, 9, 0, 1, 0, 11, 12, 16, 31, 13], ["+", 0, 9, 0, 1, 0, 11, 12, 16, 31, 22]]
| 0
| 153
| 4
|
#include <stdio.h>
int main() {
int a, b, c, d, l;
int la, lb;
scanf("%d%d%d%d%d", &l, &a, &b, &c, &d);
la = l;
lb = l;
while (1) {
if (a <= 0) {
break;
} else {
a = a - c;
la = la - 1;
}
}
while (1) {
if (b <= 0) {
break;
} else {
b = b - d;
lb = lb - 1;
}
}
if (la < lb) {
printf("%d\n", la);
} else if (la > lb) {
printf("&d\n", lb);
} else {
printf("%d\n", la);
}
return 0;
}
|
#include <stdio.h>
int main() {
int a, b, c, d, l;
int la, lb;
scanf("%d%d%d%d%d", &l, &a, &b, &c, &d);
la = l;
lb = l;
while (1) {
if (a <= 0) {
break;
} else {
a = a - c;
la = la - 1;
}
}
while (1) {
if (b <= 0) {
break;
} else {
b = b - d;
lb = lb - 1;
}
}
if (la < lb) {
printf("%d\n", la);
} else if (la > lb) {
printf("%d\n", lb);
} else {
printf("%d\n", la);
}
return 0;
}
|
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
| 0
| 169
| 2
|
a[], i;
main() {
for (; ~scanf("%d", a + i++) ||
!printf("%.f\n", *a - fmax(~-a[1] / a[3], ~-a[2] / a[4]) - 1);)
;
exit(0);
}
|
a[5], i;
main() {
for (; ~scanf("%d", a + i++) ||
!printf("%.f\n", *a - fmax(~-a[1] / a[3], ~-a[2] / a[4]) - 1);)
;
exit(0);
}
|
[["+", 36, 36, 0, 30, 0, 1, 0, 69, 71, 13], ["+", 0, 1, 0, 2, 3, 4, 0, 25, 0, 35]]
| 0
| 75
| 2
|
L;
main(A, B, C, D) {
scanf("%d%d%d%d%d", &L, &A, &B, &C, &D);
L = !printf("%.f\n", L - fmax(++A / C, ++B / D) - 1);
}
|
L;
main(A, B, C, D) {
scanf("%d%d%d%d%d", &L, &A, &B, &C, &D);
L = !printf("%.f\n", L - fmax(--A / C, --B / D) - 1);
}
|
[["-", 12, 2, 3, 4, 0, 16, 31, 27, 17, 29], ["+", 12, 2, 3, 4, 0, 16, 31, 27, 17, 68]]
| 0
| 65
| 4
|
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int main() {
int a, b, c, d, e;
cin >> a;
cin >> b;
cin >> c;
cin >> d;
cin >> e;
cout << a - max((b + d - 1) / b, (c + e - 1) / e) << endl;
}
|
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int main() {
int a, b, c, d, e;
cin >> a;
cin >> b;
cin >> c;
cin >> d;
cin >> e;
cout << a - max((b + d - 1) / d, (c + e - 1) / e) << endl;
}
|
[["-", 12, 16, 12, 2, 3, 4, 0, 16, 12, 22], ["+", 12, 16, 12, 2, 3, 4, 0, 16, 12, 22]]
| 1
| 77
| 2
|
#include "bits/stdc++.h"
using namespace std;
int main() {
int answer;
int A, B, C, D, L;
int math, Japanese;
cin >> L >> A >> B >> C >> D;
math = (B - 1) / C + 1;
Japanese = (B - 1) / C + 1;
cout << L - max(math, Japanese) << endl;
/*
int datanum = 0;
for(int dataset = 0; dataset < 1; dataset++){
if(input == 0) break;
answer[dataset] = sum;
datanum++;
}
for(int dataset = 0; dataset < datanum; dataset++){
cout << answer[dataset] << endl;
}
*/
return 0;
}
|
#include "bits/stdc++.h"
using namespace std;
int main() {
int answer;
int A, B, C, D, L;
int math, Japanese;
cin >> L >> A >> B >> C >> D;
math = (B - 1) / D + 1;
Japanese = (A - 1) / C + 1;
cout << L - max(math, Japanese) << endl;
/*
int datanum = 0;
for(int dataset = 0; dataset < 1; dataset++){
if(input == 0) break;
answer[dataset] = sum;
datanum++;
}
for(int dataset = 0; dataset < datanum; dataset++){
cout << answer[dataset] << endl;
}
*/
return 0;
}
|
[["-", 0, 1, 0, 11, 12, 16, 31, 16, 12, 22], ["+", 0, 1, 0, 11, 12, 16, 31, 16, 12, 22], ["-", 12, 16, 31, 16, 31, 23, 0, 16, 31, 22], ["+", 12, 16, 31, 16, 31, 23, 0, 16, 31, 22]]
| 1
| 86
| 4
|
#include <bits/stdc++.h>
typedef long long LL;
using namespace std;
int main() {
double L, A, B, C, D;
cin >> L >> A >> B >> C >> D;
cout << L - ceil(A / C) - ceil(B / D) << endl;
}
|
#include <bits/stdc++.h>
typedef long long LL;
using namespace std;
int main() {
double L, A, B, C, D;
cin >> L >> A >> B >> C >> D;
cout << L - max(ceil(A / C), ceil(B / D)) << endl;
}
|
[["+", 0, 16, 31, 16, 12, 16, 12, 2, 63, 22], ["+", 31, 16, 12, 16, 12, 2, 3, 4, 0, 24], ["-", 0, 1, 0, 16, 31, 16, 12, 16, 17, 33], ["+", 31, 16, 12, 16, 12, 2, 3, 4, 0, 21], ["+", 12, 2, 3, 4, 0, 2, 3, 4, 0, 25]]
| 1
| 60
| 5
|
#include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
int main() {
int L, A, B, C, D, day[2];
cin >> L >> A >> B >> C >> D;
day[0] = A / C;
if (day[0] * C != A) {
day[0]++;
}
day[1] = B / D;
if (day[1] * D != B) {
day[1]++;
}
sort(day, day + 1);
cout << L - day[1] << endl;
}
|
#include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
int main() {
int L, A, B, C, D, day[2];
cin >> L >> A >> B >> C >> D;
day[0] = A / C;
if (day[0] * C != A) {
day[0]++;
}
day[1] = B / D;
if (day[1] * D != B) {
day[1]++;
}
sort(day, day + 2);
cout << L - day[1] << endl;
}
|
[["-", 0, 1, 0, 2, 3, 4, 0, 16, 12, 13], ["+", 0, 1, 0, 2, 3, 4, 0, 16, 12, 13]]
| 1
| 120
| 2
|
#include <iostream>
using namespace std;
int main() {
int day, J, M, Jday, Mday, asobuz;
cin >> day;
cin >> J;
cin >> M;
cin >> Jday;
cin >> Mday;
int a = 0;
while (J >= 0) {
J -= Jday;
a++;
}
int b = 0;
while (M >= 0) {
M -= Mday;
b++;
}
if (a > b) {
asobuz = a;
} else {
asobuz = b;
}
day -= asobuz;
cout << day << endl;
}
|
#include <iostream>
using namespace std;
int main() {
int day, J, M, Jday, Mday, asobuz;
cin >> day;
cin >> J;
cin >> M;
cin >> Jday;
cin >> Mday;
int a = 0;
while (J > 0) {
J -= Jday;
a++;
}
int b = 0;
while (M > 0) {
M -= Mday;
b++;
}
if (a > b) {
asobuz = a;
} else {
asobuz = b;
}
day -= asobuz;
cout << day << endl;
}
|
[["-", 8, 9, 0, 52, 15, 339, 51, 16, 17, 20], ["+", 8, 9, 0, 52, 15, 339, 51, 16, 17, 47]]
| 1
| 114
| 4
|
#include <stdio.h>
int main() {
int L, A, B, C, D;
int t1, t2;
scanf("%d", &L);
scanf("%d", &A);
scanf("%d", &B);
scanf("%d", &C);
scanf("%d", &D);
t1 = A / C;
if (A % C != 0)
t1++;
t2 = B / D;
if (B % D != 0)
t2++;
if (t2 > t1)
t1 = t2;
L = L - t1;
printf("%d\n", t1);
return 0;
}
|
#include <stdio.h>
int main() {
int L, A, B, C, D;
int t1, t2;
scanf("%d", &L);
scanf("%d", &A);
scanf("%d", &B);
scanf("%d", &C);
scanf("%d", &D);
t1 = A / C;
if (A % C != 0)
t1++;
t2 = B / D;
if (B % D != 0)
t2++;
if (t2 > t1)
t1 = t2;
L = L - t1;
printf("%d\n", L);
return 0;
}
|
[["-", 8, 9, 0, 1, 0, 2, 3, 4, 0, 22], ["+", 8, 9, 0, 1, 0, 2, 3, 4, 0, 22]]
| 1
| 137
| 2
|
#include <stdio.h>
int main(void) {
int n, a, b, c, d;
int s, ss;
scanf("%d", &n);
scanf("%d", &a);
scanf("%d", &b);
scanf("%d", &c);
scanf("%d", &d);
s = a / c;
// printf("s=%d\n",s);
if (a % c != 0) {
s = s + 1;
// printf("s1=%d\n",s);
}
ss = b / d;
// printf("ss=%d\n",ss);
if (b % s != 0) {
ss = ss + 1;
// printf("ss=%d\n",ss);
}
if (s >= ss) {
n = n - s;
printf("%d\n", n);
} else if (ss > s) {
n = n - ss;
printf("%d\n", n);
}
return 0;
}
|
#include <stdio.h>
int main(void) {
int n, a, b, c, d;
int s, ss;
scanf("%d", &n);
scanf("%d", &a);
scanf("%d", &b);
scanf("%d", &c);
scanf("%d", &d);
s = a / c;
// printf("%d\n",s);
if (a % c != 0) {
s = s + 1;
}
ss = b / d;
// printf("%d\n",ss);
if (b % d != 0) {
ss = ss + 1;
}
if (s >= ss) {
n = n - s;
printf("%d\n", n);
} else if (ss > s) {
n = n - ss;
printf("%d\n", n);
}
return 0;
}
|
[["-", 0, 57, 15, 339, 51, 16, 31, 16, 12, 22], ["+", 0, 57, 15, 339, 51, 16, 31, 16, 12, 22]]
| 1
| 175
| 2
|
#include <stdio.h>
int main(void) {
int L, A, B, C, D;
int a, b, c;
scanf("%d", &L);
scanf("%d", &A);
scanf("%d", &B);
scanf("%d", &C);
scanf("%d", &D);
a = A / C;
if (A / C != 0) {
a = A / C;
a = a + 1;
}
b = B / D;
if (B / D != 0) {
b = B / D;
b = b + 1;
}
if (a > b) {
c = L - a;
} else if (a < b) {
c = L - b;
}
printf("%d\n", c);
return 0;
}
|
#include <stdio.h>
int main(void) {
int L, A, B, C, D;
int a, b, c;
scanf("%d", &L);
scanf("%d", &A);
scanf("%d", &B);
scanf("%d", &C);
scanf("%d", &D);
a = A / C;
if (A % C != 0) {
a = A / C;
a = a + 1;
}
b = B / D;
if (B % D != 0) {
b = B / D;
b = b + 1;
}
if (a >= b) {
c = L - a;
} else if (a < b) {
c = L - b;
}
printf("%d\n", c);
return 0;
}
|
[["-", 0, 57, 15, 339, 51, 16, 31, 16, 17, 85], ["+", 0, 57, 15, 339, 51, 16, 31, 16, 17, 109], ["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 47], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 20]]
| 1
| 175
| 6
|
#include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
int main() {
int day, a, b, c, d;
cin >> day >> a >> b >> c >> d;
if (a % c != 0) {
a = 1 + (a / c);
} else
a /= c;
if (b % d != 0) {
b = 1 + (b / d);
} else
d /= d;
if (a > b)
day -= a;
else
day -= b;
cout << day << endl;
return 0;
}
|
#include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
int main() {
int day, a, b, c, d;
cin >> day >> a >> b >> c >> d;
if (a % c != 0) {
a = 1 + (a / c);
} else
a /= c;
if (b % d != 0) {
b = 1 + (b / d);
} else
b /= d;
if (a > b)
day -= a;
else
day -= b;
cout << day << endl;
return 0;
}
|
[["-", 0, 57, 75, 76, 0, 1, 0, 11, 31, 22], ["+", 0, 57, 75, 76, 0, 1, 0, 11, 31, 22]]
| 1
| 113
| 2
|
#include <algorithm>
#include <cstring>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
const int MOD = 10000;
vector<int> A, B;
int M;
int dp[505][10][3][505][2];
void sub1(vector<int> &q) {
for (int i = q.size() - 1; i >= 0; ++i) {
if (q[i] == 0) {
q[i] = 9;
} else {
--q[i];
return;
}
}
return;
}
int ZigZag(const vector<int> v, int idx, int prv, int updown, int mod,
bool free) {
if (idx == v.size())
return !mod;
if (~dp[idx][prv][updown][mod][free])
return dp[idx][prv][updown][mod][free];
int r = (free ? 9 : v[idx]);
int ret = 0;
for (int i = 0; i <= r; ++i, ret %= MOD) {
if (updown == 0 && prv <= i)
continue;
if (updown == 1 && prv >= i)
continue;
if (updown == 2 && prv && prv == i)
continue;
int u;
if (updown == 2) {
if (prv == 0) {
u = 2;
} else if (prv > i) {
u = 1;
} else {
u = 0;
}
} else
u != updown;
ret += ZigZag(v, idx + 1, i, u, (mod * 10 + i) % M, free | (i != v[idx]));
}
return dp[idx][prv][updown][mod][free] = ret % MOD;
}
int main() {
string a, b;
cin >> a >> b >> M;
for (int i = 0; i < a.size(); ++i)
A.push_back(a[i] - '0');
for (int j = 0; j < b.size(); ++j)
B.push_back(b[j] - '0');
sub1(A);
memset(dp, -1, sizeof(dp));
int ra = ZigZag(A, 0, 0, 2, 0, false);
memset(dp, -1, sizeof(dp));
int rb = ZigZag(B, 0, 0, 2, 0, false);
int ret = (rb - ra + MOD) % MOD;
cout << ret << endl;
return 0;
}
|
#include <algorithm>
#include <cstring>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
const int MOD = 10000;
vector<int> A, B;
int M;
int dp[505][10][3][505][2];
void sub1(vector<int> &q) {
for (int i = q.size() - 1; i >= 0; --i) {
if (q[i] == 0) {
q[i] = 9;
} else {
--q[i];
return;
}
}
return;
}
int ZigZag(const vector<int> v, int idx, int prv, int updown, int mod,
bool free) {
if (idx == v.size())
return !mod;
if (~dp[idx][prv][updown][mod][free])
return dp[idx][prv][updown][mod][free];
int r = (free ? 9 : v[idx]);
int ret = 0;
for (int i = 0; i <= r; ++i, ret %= MOD) {
if (updown == 0 && prv <= i)
continue;
if (updown == 1 && prv >= i)
continue;
if (updown == 2 && prv && prv == i)
continue;
int u;
if (updown == 2) {
if (prv == 0) {
u = 2;
} else if (prv > i) {
u = 1;
} else {
u = 0;
}
} else
u = !updown;
ret += ZigZag(v, idx + 1, i, u, (mod * 10 + i) % M, free | (i != v[idx]));
}
return dp[idx][prv][updown][mod][free] = ret % MOD;
}
int main() {
string a, b;
cin >> a >> b >> M;
for (int i = 0; i < a.size(); ++i)
A.push_back(a[i] - '0');
for (int j = 0; j < b.size(); ++j)
B.push_back(b[j] - '0');
sub1(A);
memset(dp, -1, sizeof(dp));
int ra = ZigZag(A, 0, 0, 2, 0, false);
memset(dp, -1, sizeof(dp));
int rb = ZigZag(B, 0, 0, 2, 0, false);
int ret = (rb - ra + MOD) % MOD;
cout << ret << endl;
return 0;
}
|
[["-", 0, 14, 8, 9, 0, 7, 26, 27, 17, 29], ["+", 0, 14, 8, 9, 0, 7, 26, 27, 17, 68], ["-", 0, 57, 75, 76, 0, 1, 0, 16, 17, 79], ["+", 0, 57, 75, 76, 0, 1, 0, 11, 17, 32], ["+", 75, 76, 0, 1, 0, 11, 12, 91, 17, 111]]
| 1
| 546
| 5
|
#include <stdio.h>
int main(void) {
char joi[1000001];
int i, len;
int rj, ro, ri;
int level;
scanf("%s", joi, &len);
level = 0;
for (i = 0; i < len; i++) {
if (joi[i] == 'J') {
for (rj = 0; joi[i] == 'J'; rj++, i++)
;
for (ro = 0; joi[i] == 'O'; ro++, i++)
;
for (ri = 0; joi[i] == 'I'; ri++, i++)
;
if (ri >= ro && rj >= ro)
level = level > ro ? level : ro;
i--;
}
}
printf("%d\n", level);
return (0);
}
|
#include <stdio.h>
int main(void) {
char joi[1000001];
int i, len;
int rj, ro, ri;
int level;
scanf("%s%n", joi, &len);
level = 0;
for (i = 0; i < len; i++) {
if (joi[i] == 'J') {
for (rj = 0; joi[i] == 'J'; rj++, i++)
;
for (ro = 0; joi[i] == 'O'; ro++, i++)
;
for (ri = 0; joi[i] == 'I'; ri++, i++)
;
if (ri >= ro && rj >= ro)
level = level > ro ? level : ro;
i--;
}
}
printf("%d\n", level);
return (0);
}
|
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
| 0
| 178
| 2
|
#include <stdio.h>
int main(void) {
int n1, n2, n3, max = 0;
for (; ~scanf("%*[^J]");) {
n1 = n2 = n3 = 0;
scanf("%*[J]%n%*[O]%n%*[I]%n", &n1, &n2, &n3);
n3 -= n2;
n2 -= n1;
if (n1 >= n2 && n2 <= n3)
if (max < n2)
max = n2;
}
printf("%d\n", n2);
return 0;
}
|
#include <stdio.h>
int main(void) {
int n1, n2, n3, max = 0;
for (; ~scanf("%*[^J]");) {
n1 = n2 = n3 = 0;
scanf("%*[J]%n%*[O]%n%*[I]%n", &n1, &n2, &n3);
n3 -= n2;
n2 -= n1;
if (n1 >= n2 && n2 <= n3)
if (max < n2)
max = n2;
}
printf("%d\n", max);
return 0;
}
|
[["-", 8, 9, 0, 1, 0, 2, 3, 4, 0, 22], ["+", 8, 9, 0, 1, 0, 2, 3, 4, 0, 22]]
| 0
| 99
| 6
|
#include <stdio.h>
int main(void) {
int n1, n2, n3, max = 0;
for (; ~scanf("%*[^J]");) {
n1 = n2 = n3 = 0;
scanf("%*[J]%n%*[O]%n%*[I]%n", &n1, &n2, &n3);
n3 -= n2;
n2 -= n1;
if (n1 >= n2 && n2 <= n3)
if (max < n2)
max = n2;
}
printf("%d\n", n2);
return 0;
}
|
#include <stdio.h>
int main(void) {
int n1, n2, n3, max = 0;
while (~scanf("%*[^J]")) {
n1 = n2 = n3 = 0;
scanf("%*[J]%n%*[O]%n%*[I]%n", &n1, &n2, &n3);
n3 -= n2;
n2 -= n1;
if (n1 >= n2 && n2 <= n3)
if (max < n2)
max = n2;
}
printf("%d\n", max);
return 0;
}
|
[["-", 0, 30, 0, 14, 8, 9, 0, 7, 0, 88], ["+", 0, 30, 0, 14, 8, 9, 0, 52, 0, 89], ["-", 0, 30, 0, 14, 8, 9, 0, 7, 0, 35], ["-", 8, 9, 0, 1, 0, 2, 3, 4, 0, 22], ["+", 8, 9, 0, 1, 0, 2, 3, 4, 0, 22]]
| 0
| 99
| 6
|
#include <cstdio>
#include <iostream>
#include <string>
using namespace std;
int main() {
int cou = 0, ans = 0, j, i, o;
char joi[1111111];
string tmp;
scanf("%s", joi);
tmp = joi;
int len = tmp.size();
while (len > cou) {
if (joi[cou] != 'J') {
cou++;
continue;
}
j = 0, o = 0, i = 0;
while (joi[cou] == 'J' && len > cou) {
cou++;
j++;
}
while (joi[cou] == 'O' && len > cou) {
cou++;
o++;
}
while (joi[cou] == 'I' && len > cou) {
cou++;
i++;
}
if (j == o && o == i && ans < j) {
ans = j;
}
}
cout << ans << endl;
}
|
#include <cstdio>
#include <iostream>
#include <string>
using namespace std;
int main() {
int cou = 0, ans = 0, j, i, o;
char joi[1111111];
string tmp;
scanf("%s", joi);
tmp = joi;
int len = tmp.size();
while (len > cou) {
if (joi[cou] != 'J') {
cou++;
continue;
}
j = 0, o = 0, i = 0;
while (joi[cou] == 'J' && len > cou) {
cou++;
j++;
}
while (joi[cou] == 'O' && len > cou) {
cou++;
o++;
}
while (joi[cou] == 'I' && len > cou) {
cou++;
i++;
}
if (j >= o && o <= i && ans < o) {
ans = o;
}
}
cout << ans << endl;
}
|
[["-", 15, 339, 51, 16, 31, 16, 31, 16, 17, 60], ["+", 15, 339, 51, 16, 31, 16, 31, 16, 17, 20], ["-", 15, 339, 51, 16, 31, 16, 12, 16, 17, 60], ["+", 15, 339, 51, 16, 31, 16, 12, 16, 17, 19], ["-", 0, 57, 15, 339, 51, 16, 12, 16, 12, 22], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 12, 22], ["-", 0, 57, 64, 9, 0, 1, 0, 11, 12, 22], ["+", 0, 57, 64, 9, 0, 1, 0, 11, 12, 22]]
| 1
| 195
| 8
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, e) for (int i = (s); i < (e); i++)
#define pb(n) push_back((n))
#define mp(n, m) make_pair((n), (m))
#define all(r) r.begin(), r.end()
#define fi first
#define se second
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
void print(vi v) {
for (int i = 0; i < v.size(); i++) {
cout << " " << v[i];
}
cout << endl;
}
int main() {
string s;
cin >> s;
vi v(s.size(), 1);
for (int i = 1; i < s.size(); i++) {
if (s[i] == s[i - 1]) {
v[i] = v[i - 1] + 1;
} else {
reverse(v.begin() + (i - v[i - 1]), v.begin() + i);
}
}
reverse(v.begin() + (v.size() - 1 - v[v.size() - 2]), v.begin() + (v.size()));
print(v);
// print(v);
int ans = 0;
for (int i = 0; i < s.size(); i++) {
if (s[i] == 'J') {
if (i + v[i] < s.size() && s[i + v[i]] == 'O' && v[i + v[i]] == v[i]) {
if (i + v[i] * 2 < s.size() && s[i + v[i] * 2] == 'I' &&
v[i + v[i] * 2] >= v[i + v[i]]) {
ans = max(ans, v[i]);
}
}
}
}
cout << ans << endl;
}
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, e) for (int i = (s); i < (e); i++)
#define pb(n) push_back((n))
#define mp(n, m) make_pair((n), (m))
#define all(r) r.begin(), r.end()
#define fi first
#define se second
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
void print(vi v) {
for (int i = 0; i < v.size(); i++) {
cout << " " << v[i];
}
cout << endl;
}
int main() {
string s;
cin >> s;
vi v(s.size(), 1);
for (int i = 1; i < s.size(); i++) {
if (s[i] == s[i - 1]) {
v[i] = v[i - 1] + 1;
} else {
reverse(v.begin() + (i - v[i - 1]), v.begin() + i);
}
}
reverse(v.begin() + (v.size() - 1 - v[v.size() - 2]), v.begin() + (v.size()));
// print(v);
// print(v);
int ans = 0;
for (int i = 0; i < s.size(); i++) {
if (s[i] == 'J') {
if (i + v[i] < s.size() && s[i + v[i]] == 'O' && v[i + v[i]] == v[i]) {
if (i + v[i] * 2 < s.size() && s[i + v[i] * 2] == 'I' &&
v[i + v[i] * 2] >= v[i + v[i]]) {
ans = max(ans, v[i]);
}
}
}
}
cout << ans << endl;
}
|
[["-", 0, 14, 8, 9, 0, 1, 0, 2, 63, 22], ["-", 8, 9, 0, 1, 0, 2, 3, 4, 0, 24], ["-", 8, 9, 0, 1, 0, 2, 3, 4, 0, 22], ["-", 8, 9, 0, 1, 0, 2, 3, 4, 0, 25], ["-", 0, 30, 0, 14, 8, 9, 0, 1, 0, 35]]
| 1
| 495
| 5
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <queue>
using namespace std;
int main() {
string str;
cin >> str;
int Jcou = 0, Ocou = 0, Icou = 0;
int ans = 0;
for (int i = 0; i < str.size(); i++) {
if (Ocou == 0 && Icou == 0 && str[i] == 'J')
Jcou++;
else if (Jcou != 0 && Icou == 0 && str[i] == 'O')
Ocou++;
else if (Jcou != 0 && Ocou != 0 && str[i] == 'I')
Icou++;
else {
if (Jcou < Ocou || Ocou < Icou)
Ocou = 0;
ans = max(ans, min(Jcou, min(Ocou, Icou)));
Jcou = 0, Ocou = 0, Icou = 0;
if (str[i] == 'J')
Jcou++;
}
// printf("[%d][%d][%d][%d]\n",Jcou,Ocou,Icou,ans);
}
if (Jcou < Ocou || Ocou < Icou)
Ocou = 0;
ans = max(ans, min(Jcou, min(Ocou, Icou)));
cout << ans << endl;
return 0;
}
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <queue>
using namespace std;
int main() {
string str;
cin >> str;
int Jcou = 0, Ocou = 0, Icou = 0;
int ans = 0;
for (int i = 0; i < str.size(); i++) {
if (Ocou == 0 && Icou == 0 && str[i] == 'J')
Jcou++;
else if (Jcou != 0 && Icou == 0 && str[i] == 'O')
Ocou++;
else if (Jcou != 0 && Ocou != 0 && str[i] == 'I')
Icou++;
else {
if (Jcou < Ocou || Ocou > Icou)
Ocou = 0;
ans = max(ans, min(Jcou, min(Ocou, Icou)));
Jcou = 0, Ocou = 0, Icou = 0;
if (str[i] == 'J')
Jcou++;
}
// printf("[%d][%d][%d][%d]\n",Jcou,Ocou,Icou,ans);
}
if (Jcou < Ocou || Ocou > Icou)
Ocou = 0;
ans = max(ans, min(Jcou, min(Ocou, Icou)));
cout << ans << endl;
return 0;
}
|
[["-", 0, 57, 15, 339, 51, 16, 12, 16, 17, 18], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 17, 47]]
| 1
| 238
| 4
|
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define LL long long
#define ULL unsigned long long
const int LL_INF = ~(ULL)0 >> 1;
signed main() {
string s;
cin >> s;
int max = 0;
for (int i = 0; i < s.size(); ++i) {
if (s[i] != 'J')
continue;
int j, o, sti;
for (j = i; j < s.size(); ++j) {
if (s[j] != 'J')
break;
}
for (o = j; o < s.size(); ++o) {
if ((s[o] != 'O') || (j - i < o - j))
break;
}
for (sti = o; sti < s.size(); ++sti) {
if (s[sti] != 'I')
break;
}
int lenj = j - i, leno = o - j, leni = sti - o;
if ((leno <= lenj) && (leni < leno) && (0 < lenj) && (0 < leno) &&
(0 < leni)) {
int temp = min(leni, min(lenj, lenj));
if (max < temp)
max = temp;
}
i = j;
}
cout << max << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define LL long long
#define ULL unsigned long long
const int LL_INF = ~(ULL)0 >> 1;
signed main() {
string s;
cin >> s;
int max = 0;
for (int i = 0; i < s.size(); ++i) {
if (s[i] != 'J')
continue;
int j, o, sti;
for (j = i; j < s.size(); ++j) {
if (s[j] != 'J')
break;
}
for (o = j; o < s.size(); ++o) {
if ((s[o] != 'O') || (j - i < o - j))
break;
}
for (sti = o; sti < s.size(); ++sti) {
if (s[sti] != 'I')
break;
}
int lenj = j - i, leno = o - j, leni = sti - o;
if ((leno <= lenj) && (leno <= leni) && (0 < lenj) && (0 < leno) &&
(0 < leni)) {
int temp = min(leni, min(leno, lenj));
if (max < temp)
max = temp;
}
i = j;
}
cout << max << endl;
return 0;
}
|
[["-", 31, 16, 31, 16, 12, 23, 0, 16, 31, 22], ["-", 31, 16, 31, 16, 12, 23, 0, 16, 17, 18], ["+", 31, 16, 31, 16, 12, 23, 0, 16, 17, 19], ["+", 31, 16, 31, 16, 12, 23, 0, 16, 12, 22], ["-", 51, 2, 3, 4, 0, 2, 3, 4, 0, 22], ["+", 51, 2, 3, 4, 0, 2, 3, 4, 0, 22]]
| 1
| 284
| 6
|
#include <iostream>
using namespace std;
char a[1000001];
char w[] = "JOI";
int k = 0, l[3];
int main() {
cin >> a;
for (char *c = a; *c != '\0'; ++c) {
for (int i = 0; i < 3; ++i) {
l[i] = 0;
while (*c != '\0' && *c == w[i]) {
++l[i];
++c;
}
}
if (l[0] >= l[1] && l[2] >= l[1])
k = (k < l[1] ? l[1] : k);
}
cout << k << endl;
return 0;
}
|
#include <iostream>
using namespace std;
char a[1000001];
char w[] = "JOI";
int k = 0, l[3];
int main() {
cin >> a;
for (char *c = a; *c != '\0';) {
for (int i = 0; i < 3; ++i) {
l[i] = 0;
while (*c != '\0' && *c == w[i]) {
++l[i];
++c;
}
}
if (l[0] >= l[1] && l[2] >= l[1])
k = (k < l[1] ? l[1] : k);
}
cout << k << endl;
return 0;
}
|
[["-", 0, 14, 8, 9, 0, 7, 26, 27, 17, 29], ["-", 0, 14, 8, 9, 0, 7, 26, 27, 28, 22]]
| 1
| 161
| 2
|
#include <bits/stdc++.h>
using namespace std;
int main() {
char str;
int n[3] = {}, ans = 0, x;
while (cin >> str) {
if (str == 'J' && n[1] == 0 && n[2] == 0)
n[0]++;
else if (str == 'O' && n[1] < n[0] && n[2] == 0)
n[1]++;
else if (str == 'I' && n[2] < (x = min(n[0], n[1])))
if ((n[2] += 1) == x)
ans = max(ans, x);
else {
for (int i = 0; i < 3; i++)
n[i] = 0;
if (str == 'J')
n[0] = 1;
}
}
cout << ans << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
char str;
int n[3] = {}, ans = 0, x;
while (cin >> str) {
if (str == 'J' && n[1] == 0 && n[2] == 0)
n[0]++;
else if (str == 'O' && n[1] < n[0] && n[2] == 0)
n[1]++;
else if (str == 'I' && n[2] < (x = min(n[0], n[1]))) {
if ((n[2] += 1) == x)
ans = max(ans, x);
} else {
for (int i = 0; i < 3; i++)
n[i] = 0;
if (str == 'J')
n[0] = 1;
}
}
cout << ans << endl;
}
|
[["+", 0, 57, 75, 76, 0, 57, 64, 9, 0, 45], ["+", 0, 57, 75, 76, 0, 57, 64, 9, 0, 46]]
| 1
| 196
| 29
|
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
int main() {
string str;
cin >> str;
stack<pair<char, int>> st;
int max_l = 0;
st.emplace(str[0], 1);
for (int i = 1; i < str.size(); i++) {
auto n = st.top();
if (str[i] == n.fi) {
n.se++;
st.pop();
st.emplace(n);
continue;
}
st.emplace(str[i], 1);
}
char ex = 'I';
char j, o, i;
int a, b, c;
while (!st.empty()) {
pair<char, int> po = st.top();
st.pop();
j = po.fi;
a = po.se;
if (a > b && c > b && j == 'J' && o == 'O' && i == 'I') {
max_l = max(max_l, b);
}
c = b;
b = a;
i = o;
o = j;
}
cout << max_l << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
int main() {
string str;
cin >> str;
stack<pair<char, int>> st;
int max_l = 0;
st.emplace(str[0], 1);
for (int i = 1; i < str.size(); i++) {
auto n = st.top();
if (str[i] == n.fi) {
n.se++;
st.pop();
st.emplace(n);
continue;
}
st.emplace(str[i], 1);
}
char ex = 'I';
char j, o, i;
int a, b, c;
while (!st.empty()) {
pair<char, int> po = st.top();
st.pop();
j = po.fi;
a = po.se;
if (a >= b && c >= b && j == 'J' && o == 'O' && i == 'I') {
max_l = max(max_l, b);
}
c = b;
b = a;
i = o;
o = j;
}
cout << max_l << endl;
}
|
[["-", 31, 16, 31, 16, 31, 16, 31, 16, 17, 47], ["+", 31, 16, 31, 16, 31, 16, 31, 16, 17, 20], ["-", 31, 16, 31, 16, 31, 16, 12, 16, 17, 47], ["+", 31, 16, 31, 16, 31, 16, 12, 16, 17, 20]]
| 1
| 252
| 4
|
#include <bits/stdc++.h>
#define r(i, a, n) for (i = 0; i < n; i++)
using namespace std;
int main() {
string s;
int i, j, k, l, sum = 0, a, b, c;
cin >> s;
r(i, 0, s.size()) {
a = b = c = 0;
for (; s[i] == 'J'; a++)
i++;
for (; s[i] == 'O'; b++)
i++;
for (; s[i] == 'I'; c++)
i++;
if (b <= a && b <= c)
sum = max(b, sum);
}
cout << sum << endl;
}
|
#include <bits/stdc++.h>
#define r(i, a, n) for (i = 0; i < n;)
using namespace std;
int main() {
string s;
int i, j, k, l, sum = 0, a, b, c;
cin >> s;
r(i, 0, s.size()) {
a = b = c = 0;
for (; s[i] == 'J'; a++)
i++;
for (; s[i] == 'O'; b++)
i++;
for (; s[i] == 'I'; c++)
i++;
if (b <= a && b <= c)
sum = max(b, sum);
}
cout << sum << endl;
}
|
[["-", 36, 36, 36, 36, 0, 30, 0, 112, 51, 59], ["+", 36, 36, 36, 36, 0, 30, 0, 112, 51, 59]]
| 1
| 150
| 2
|
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using namespace std;
int main(int argc, char *argv[]) {
string str;
int ans = 0;
int n1, n2, n3;
cin >> str;
for (int i = 0; i < str.length(); ++i) {
n1 = n2 = n3 = 0;
while (str[i] == 'J') {
n1++;
i++;
}
while (str[i] == 'O') {
n2++;
i++;
}
while (str[i] == 'I') {
n3++;
i++;
}
if (n2 <= n1 && n2 <= n3)
ans = max(ans, n2);
}
cout << ans << endl;
return 0;
}
|
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using namespace std;
int main(int argc, char *argv[]) {
string str;
int ans = 0;
int n1, n2, n3;
cin >> str;
for (int i = 0; i < str.length(); ++i) {
n1 = n2 = n3 = 0;
while (str[i] == 'J') {
n1++;
i++;
}
while (str[i] == 'O') {
n2++;
i++;
}
while (str[i] == 'I') {
n3++;
i++;
}
if (n2 <= n1 && n2 <= n3)
ans = max(ans, n2);
i--;
}
cout << ans << endl;
return 0;
}
|
[["+", 0, 7, 8, 9, 0, 1, 0, 27, 28, 22], ["+", 0, 7, 8, 9, 0, 1, 0, 27, 17, 68], ["+", 8, 9, 0, 7, 8, 9, 0, 1, 0, 35]]
| 1
| 166
| 3
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define rep(i, n) REP(i, 0, n)
#define REP(i, s, e) for (int i = (s); i < (int)(e); i++)
#define pb push_back
//#define mp make_pair
#define all(r) r.begin(), r.end()
#define rall(r) r.rbegin(), r.rend()
#define fi first
#define se second
#define println(X) cout << X << endl;
#define DBG(X) cout << #X << " : " << X << endl;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;
const double PI = acos(-1);
vi a, b;
int nxt;
map<int, vi> mp;
bool getIdx(int idx, int s) {
vi v = mp[s];
auto it = upper_bound(all(v), idx);
if (it == v.end())
return false;
nxt = *it;
return true;
}
int main() {
int n, m, tmp;
cin >> n >> m;
rep(i, n) cin >> tmp, a.pb(tmp);
rep(i, m) cin >> tmp, b.pb(tmp);
for (int i = 0; i < n; i++) {
mp[a[i]].pb(i);
}
int ans = 0;
for (int i = 0; i < b.size(); i++) {
int idx = 0;
tmp = 0;
while (i + tmp < b.size() && idx < n && getIdx(idx, b[i + tmp])) {
tmp++;
idx = nxt;
}
ans = max(ans, tmp);
}
cout << ans << endl;
}
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define rep(i, n) REP(i, 0, n)
#define REP(i, s, e) for (int i = (s); i < (int)(e); i++)
#define pb push_back
//#define mp make_pair
#define all(r) r.begin(), r.end()
#define rall(r) r.rbegin(), r.rend()
#define fi first
#define se second
#define println(X) cout << X << endl;
#define DBG(X) cout << #X << " : " << X << endl;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;
const double PI = acos(-1);
vi a, b;
int nxt;
map<int, vi> mp;
bool getIdx(int idx, int s) {
vi v = mp[s];
auto it = upper_bound(all(v), idx);
if (it == v.end())
return false;
nxt = *it;
return true;
}
int main() {
int n, m, tmp;
cin >> n >> m;
rep(i, n) cin >> tmp, a.pb(tmp);
rep(i, m) cin >> tmp, b.pb(tmp);
for (int i = 0; i < n; i++) {
mp[a[i]].pb(i);
}
int ans = 0;
for (int i = 0; i < b.size(); i++) {
int idx = -1;
tmp = 0;
while (i + tmp < b.size() && idx < n && getIdx(idx, b[i + tmp])) {
tmp++;
idx = nxt;
}
ans = max(ans, tmp);
}
cout << ans << endl;
}
|
[["-", 0, 7, 8, 9, 0, 43, 49, 50, 51, 13], ["+", 0, 7, 8, 9, 0, 43, 49, 50, 51, 13]]
| 1
| 408
| 2
|
#include <algorithm>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
int main() {
int a, b;
int ca[5000], cb[5000];
cin >> a >> b;
for (int i = 0; i < a; i++)
cin >> ca[i];
for (int i = 0; i < b; i++)
cin >> cb[i];
int sum = 0;
for (int i = 0; i < b; i++) {
int c = -1, sum2 = 1;
for (int j = 0; j < a; j++) {
if (cb[i] == ca[j]) {
c = j;
break;
}
}
if (c == -1) {
goto stop;
}
for (int j = i + 1; j < b; j++) {
bool l = false;
for (int z = c + 1; z < a; z++) {
if (ca[z] == cb[j]) {
l = true;
break;
}
}
if (l) {
sum2++;
} else {
break;
}
}
sum = max(sum, sum2);
stop:;
}
cout << sum << endl;
}
|
#include <algorithm>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
int main() {
int a, b;
int ca[5000], cb[5000];
cin >> a >> b;
for (int i = 0; i < a; i++)
cin >> ca[i];
for (int i = 0; i < b; i++)
cin >> cb[i];
int sum = 0;
for (int i = 0; i < b; i++) {
int c = -1, sum2 = 1;
for (int j = 0; j < a; j++) {
if (cb[i] == ca[j]) {
c = j;
break;
}
}
if (c == -1) {
goto stop;
}
for (int j = i + 1; j < b; j++) {
bool l = false;
for (int z = c + 1; z < a; z++) {
if (ca[z] == cb[j]) {
l = true;
c = z;
break;
}
}
if (l) {
sum2++;
} else {
break;
}
}
sum = max(sum, sum2);
stop:;
}
cout << sum << endl;
}
|
[["+", 0, 57, 64, 9, 0, 1, 0, 11, 31, 22], ["+", 0, 57, 64, 9, 0, 1, 0, 11, 17, 32], ["+", 0, 57, 64, 9, 0, 1, 0, 11, 12, 22], ["+", 8, 9, 0, 57, 64, 9, 0, 1, 0, 35]]
| 1
| 254
| 4
|
s=map(int,input().split())
if len(s)==2:c=s[0];d=s[1]
else:c=s[0];d=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
e=0;i=0
while i<d-e:
p=i;q=0
for j in range(c):
if a[j]==b[p]:q+=1;p+=1
e=max(e,q)
i+=1
print(e)
|
s=list(map(int,input().split()))
if len(s)==2:c=s[0];d=s[1]
else:c=s[0];d=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
e=0;i=0
while i<d-e:
p=i;q=0
for j in range(c):
if a[j]==b[p]:q+=1;p+=1
e=max(e,q)
i+=1
print(e)
|
[["+", 0, 656, 0, 1, 0, 662, 12, 652, 63, 22], ["+", 0, 1, 0, 662, 12, 652, 3, 4, 0, 24], ["+", 0, 652, 3, 4, 0, 652, 3, 4, 0, 25]]
| 5
| 148
| 3
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.