제출 #334543

#제출 시각아이디문제언어결과실행 시간메모리
334543giorgikobPacking Biscuits (IOI20_biscuits)C++14
100 / 100
23 ms1388 KiB
#include<bits/stdc++.h>
#define ll long long
#define ff first
#define ss second
#define pb push_back
using namespace std;

#include "biscuits.h"
const int K = 60;

long long count_tastiness(long long x, std::vector<long long> a) {

    vector<ll>dp(K+1,0);
    dp[0] = 1;
    while(a.size() < K+5) a.pb(0);

    vector<ll>gg(K+1,0),g(K+1,0);
    for(int i = 0; i <= K; i++){
        //if(a[i] > x) gg[i] = x*(1LL<<i), a[i] -= x, g[i] = x; else gg[i] = a[i]*(1LL<<i), g[i] = a[i], a[i] = 0;
        //if(i) gg[i] += gg[i-1];
        //a[i+1] += a[i]/2;
        gg[i] = a[i] * (1LL<<i);
        if(i) gg[i] += gg[i-1];
    }

    for(ll i = 1; i <= K; i++){

        ll y = gg[i-1];
        //cout << y << endl;
        for(int k = i-1; k >= 0; k--){
            if((1LL<<k) > (1LL<<K)/x) continue;
            y = min(y,gg[k]);
            if(y < (1LL<<k)*x) continue;
            dp[i] += dp[k];
            y -= (1LL<<k)*x;
            //cout << y << " " << k << endl;
        }
        dp[i]++;
    }
    //cout << endl;
    return dp[K];
}
#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...