Submission #1357546

#TimeUsernameProblemLanguageResultExecution timeMemory
1357546opeleklanosPacking Biscuits (IOI20_biscuits)C++20
0 / 100
1095 ms9148 KiB
#include <iostream>
#include <vector>
#include <map>
using namespace std;

#define ll long long

vector<ll> a;
map<pair<int, int>, int> dp;

// ll lastIndx = 0;

ll solve(ll ind, ll count, ll x){
    if(count > 2*x + 5) return 0;
    if(ind == 0) return (count <= a[ind]);
    
    if(dp.find({ind, count}) != dp.end()) return dp[{ind, count}]; 

    ll ans = 0;

    if(count <= a[ind]) return solve(ind-1, x, x) + solve(ind-1, 0, x);
    
    return dp[{ind, count}] = solve(ind-1, (count - a[ind]) * 2, x);
}

ll count_tastiness(ll x, vector<ll> A){
    a.assign(150, 0);
    for(ll i = 0; i<A.size(); i++) a[i] = A[i];
    for(ll i = 0; i<a.size()-1; i++){
        if((a[i]>=x) && ((a[i] - x) % 2) == 0){
            ll k = ((a[i]-x)/2);
            a[i+1] += k;
            a[i] -= 2*k;
        }
        else if(a[i] >= x){
            ll k = ((a[i]-x-1)/2);
            a[i+1] += k;
            a[i] -= 2*k;
        }

        // if(a[i] != 0) lastIndx = i;
    }

    //dp.assign(150, vector<ll>(3*x + 15, -1));
    
    return solve(149, 0, x);
}
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...