Submission #579740

#TimeUsernameProblemLanguageResultExecution timeMemory
579740SlavicG비스킷 담기 (IOI20_biscuits)C++17
0 / 100
2 ms380 KiB
#include "biscuits.h"
#include "bits/stdc++.h"

#define ll long long
std::map<ll, ll> dp;

const int K = 63;
ll s[K];
ll rec(ll n, ll x) {
    if(n <= 0) return 0;
    if(n == 1) return 1;
    if(dp.count(n)) return dp[n];
    ll largestSmaller = 0;
    for(ll i = 0; i < K; ++i) {
        if((1LL << i) < n) largestSmaller = i;
    }

    ll ans = rec(1LL << largestSmaller, x) + rec(std::min(n, 1 + s[largestSmaller] / x) - (1LL << largestSmaller), x);
    dp[n] = ans;
    return ans;

}
long long count_tastiness(long long x, std::vector<long long> a) {
    for(int i = 0; i < (int)a.size(); ++i) {
        s[i] = a[i] * (1LL << i);
        if(i) s[i] += s[i - 1];
    }
    return rec(s[(int)a.size() - 1] + 1, x);
}

#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...