# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
552064 | neki | Packing Biscuits (IOI20_biscuits) | C++14 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define vc vector
#define ll __int128
#define loop(i, a, b) for(ll i=a;i<b;++i)
#define pool(i, a, b) for(ll i=a-1;i>=b;--i)
ll min(ll a, ll b){return (a>b) ? b:a;}
long long count_tastiness(ll x, vc<ll> A){
ll k=A.size();
ll mk=124;
vc<ll> a(mk); loop(i, 0, k) a[i+1]=A[i];
vc<ll> dp(mk, 0);dp[0]=1;
loop(ti, 1, mk){
dp[ti]=dp[ti-1];
if(a[ti]>=x) dp[ti]+=dp[ti-1];
else{
ll i=ti;
vc<ll> na=a;
pool(j, ti, 1){
ll rpot=((ll)1<<(i-j));
ll kok=min((x-na[i]) * rpot, na[j]- na[j]%rpot);
na[i]+=kok/rpot;
na[j]-=kok;
if(x>na[i]) na[j-1]+=2 * na[j];
else{
if(na[j]>=x){dp[ti]+=dp[j];break;}
else{
dp[ti]+=dp[j-1];
i=j;
}
}
}
}
}
return (long long ) dp[mk-1];
}