Submission #417924

#TimeUsernameProblemLanguageResultExecution timeMemory
417924TheScrasse비스킷 담기 (IOI20_biscuits)C++14
0 / 100
13 ms364 KiB
// 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 70

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--) {
        if (a[p] < -INF) return;
        a[p] = 2 * a[p] - x;
        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 = 0; i < maxn; i++) a[i] = b[i];
}

long long count_tastiness(long long X, vector<long long> A) {
    for (i = 0; i < maxn; i++) {
        a[i] = 0; b[i] = 0;
    }

    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 < maxn; i++) {
        dp[i] = dp[i - 1];
        reset(); solve(i, i);
    }

    /* for (i = 0; i <= n; i++) cout << dp[i] << ' ';
    cout << nl; */

    res = dp[maxn - 1];

    return res;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...