# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
829107 | definitelynotmee | Packing Biscuits (IOI20_biscuits) | C++17 | 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 "biscuits.h"
#include"grader.cpp"
#include<bits/stdc++.h>
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
using namespace std;
using ll = long long;
using pii = pair<int,int>;
const ll INFL = numeric_limits<ll>::max();
using pll = pair<ll,ll>;
long long count_tastiness(long long x, std::vector<long long> a) {
a.resize(60,0);
int k = a.size();
vector<pll> dp;
auto resp_for_carry =[&](ll carry){
return lower_bound(all(dp),pll({carry,0ll}))->ss;
};
auto getdp =[&](ll vi, ll carry){
return resp_for_carry(2*(carry-vi)) + resp_for_carry(2*(carry+x-vi));
};
dp.push_back({0,1});
dp.push_back({INFL,0});
auto dc =[&](ll l, ll r, ll respl, ll respr, ll vi, vector<pll> & newdp, auto dc) -> void {
if(l > r || respl == respr)
return;
ll m = (l+r)>>1;
ll cur = getdp(vi,m);
newdp.push_back({m,cur});
dc(l,m-1,respl,cur,vi,newdp,dc);
dc(m+1,r,cur,respr,vi,newdp,dc);
};
for(int i = 0; i < 60; i++){
vector<pll> newdp;
newdp.push_back({0,getdp(a[i],0)});
newdp.push_back({INFL,0});
dc(1,4e18, newdp[0].ss, 0, a[i], newdp, dc);
sort(all(newdp));
dp.swap(newdp);
}
return dp[0].ss;
}