Submission #1014906

#TimeUsernameProblemLanguageResultExecution timeMemory
1014906UnforgettableplPacking Biscuits (IOI20_biscuits)C++17
21 / 100
1099 ms24880 KiB
#include <bits/stdc++.h> using namespace std; #define int long long const int LIMIT = 60; map<int,int> right_shift(int x,map<int,int> &inp){ map<int,int> ans; for(auto[a,b]:inp)ans[a+x]=b; if(!ans.empty()){ int offset = ans.begin()->second; ans.erase(ans.begin()); ans[0]=offset; } return ans; } map<int,int> left_shift(int x,map<int,int> &inp){ map<int,int> ans; for(auto[a,b]:inp)ans[a-x]=b; auto iter = ans.begin(); int currsum = 0; while(iter!=ans.end()){ if(iter->first>=0)break; currsum+=iter->second; iter = ans.erase(iter); } ans[0]+=currsum; return ans; } void add(map<int,int> &inp1,map<int,int> &inp2){ for(auto[a,b]:inp2){ inp1[a]+=b; if(inp1[a]==0)inp1.erase(a); } } map<int,int> shift(int x,map<int,int> &inp){ if(x<0)return right_shift(-x,inp); else if(0<x)return left_shift(x,inp); return inp; } map<int,int> collapse(map<int,int> &inp){ map<int,int> ans; for(auto[a,b]:inp)ans[(a+1ll)/2ll]+=b; return ans; } long long count_tastiness(long long x, std::vector<long long> a) { map<pair<int,int>,long long> memo; function<long long(long long,long long)> calc = [&](long long i,long long j){ j=max(j,0ll); if(i==-1)return j==0 ? 1ll : 0ll; if(j>(((long long)1e18)/(1ll<<i)))return 0ll; if(memo.count({i,j}))return memo[{i,j}]; long long ac = calc(i-1,2ll*(j-a[i])); if(ac>0)return memo[{i,j}] = calc(i-1,2ll*(j-a[i]+x))+ac; else return memo[{i,j}]=0ll; }; a.resize(LIMIT+1); map<int,int> curr; curr[1]=-1; curr[0]=1; for(int i=0;i<=LIMIT;i++){ map<int,int> t = shift((-a[i]),curr); map<int,int> tt = shift((-a[i]+x),curr); add(t,tt); curr = collapse(t); } return curr[0]; }
#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...