This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// IOI20_biscuits
#include <bits/stdc++.h>
#include "biscuits.h"
using namespace std;
#define nl "\n"
#define nf endl
#define ll long long
#define pb push_back
#define _ << ' ' <<
#define INF (ll)1e18
#define mod 1000000007
#define maxn 65
ll i, i1, j, k, k1, t, n, m, res, flag[10], a[maxn], b[maxn];
ll x, dp[maxn], l;
void solve(ll u, ll p) {
// cout << "solve " << u _ p _ a[p] << nl;
ll i;
if (a[p] >= x) {
dp[u] += dp[p - 1]; return;
}
for (i = p - 1; i >= 1; i--) {
a[p] = 2 * a[p] - x;
if (a[p] < -INF) return;
if (x - a[p] <= a[i]) {
a[i] -= x - a[p]; a[p] = x;
} else {
a[p] += a[i]; a[i] = 0;
}
// cout << "i, a[p] = " << i _ a[p] << nl;
if (a[p] >= x) {
dp[u] += dp[i - 1];
solve(u, i); return;
}
}
}
void reset() {
ll i;
for (i = 1; i <= n; i++) a[i] = b[i];
}
long long count_tastiness(long long X, vector<long long> A) {
x = X; n = A.size();
for (i = 1; i <= n; i++) {
a[i] = A[i - 1]; b[i] = A[i - 1];
}
dp[0] = 1;
for (i = 1; i <= n; i++) {
dp[i] += dp[i - 1];
reset(); solve(i, i);
}
/* for (i = 0; i <= n; i++) cout << dp[i] << ' ';
cout << nl; */
res = dp[n];
return res;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |