Submission #428533

#TimeUsernameProblemLanguageResultExecution timeMemory
428533PetiPacking Biscuits (IOI20_biscuits)C++14
100 / 100
14 ms1304 KiB
#include <bits/stdc++.h>
#include "biscuits.h"

using namespace std;

const int bitc = 60;

long long count_tastiness(long long x, std::vector<long long> a) {
    vector<long long> ossz(bitc, 0), dp(bitc, 0);
    ossz[0] = a[0];
    for(int i = 1; i < (int)a.size(); i++)
        ossz[i] = ossz[i-1] + (1ll<<i)*a[i];
    for(int i = (int)a.size(); i < bitc; i++)
        ossz[i] = ossz[i-1];

    for(int i = 0; i < bitc; i++){
        if((1ll<<i)*x > (long long)1e18)
            return dp[i-1] + 1ll;
        if(ossz[i] >= (1ll<<i)*x){
            //cout<<"\nbit: "<<i<<"\n";
            //cout<<ossz[i]<<" ossz------------\n";
            long long c = ossz[i] - (1ll<<i)*x;
            //cout<<"c: "<<c<<"\n";
            for(int j = i-1; j >= 0; j--){
                if(((1ll<<(j+1))-1ll)*x <= c){
                    //cout<<j<<" all good\n";
                    dp[i] += dp[j];
                    break;
                } else if((1ll<<j)*x <= c && ossz[j] >= (1ll<<j)*x){
                    c = min(c, ossz[j]) - (1ll<<j)*x;
                    //cout<<j<<" "<<dp[j-1]+1ll<<" one\n";
                    dp[i] += (j > 0 ? dp[j-1]+1ll : 1ll);
                }
            }
            dp[i] += 1ll;
            //cout<<"dp: "<<dp[i]<<"\n";
        }

        if(i > 0)
            dp[i] += dp[i-1];
        //cout<<i<<" dp: "<<dp[i]<<"\n";
    }

	return dp[bitc-1]+1ll;
}

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