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));
vector<pll> newdpfrfr;
newdpfrfr.reserve(newdp.size());
for(pll i : newdp){
if(newdpfrfr.size() && newdpfrfr.back().ff == i.ff)
newdpfrfr.pop_back();
newdpfrfr.push_back(i);
}
dp.swap(newdpfrfr);
}
return dp[0].ss;
}
Compilation message (stderr)
biscuits.cpp: In function 'long long int count_tastiness(long long int, std::vector<long long int>)':
biscuits.cpp:17:6: warning: unused variable 'k' [-Wunused-variable]
17 | int k = a.size();
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |