Submission #1207896

#TimeUsernameProblemLanguageResultExecution timeMemory
1207896simona1230Packing Biscuits (IOI20_biscuits)C++20
100 / 100
927 ms5656 KiB
#include "biscuits.h" #include <bits/stdc++.h> using namespace std; long long p[64]; long long ans,nd,b[64]; long long s[64]; vector<long long> v; long long dp[64][10001]; map<long long,long long> mp,in; long long compute(long long i) { if(i==0)return 1; if(i<0)return 0; if(!in[i]) { int j=0; while(j<59&&p[j+1]<=i)j++; long long y=i-p[j]; mp[i]=compute(p[j]-1)+compute(min(y,s[j]/nd-p[j])); in[i]=1; } //cout<<i<<" "<<mp[i]<<endl; return mp[i]; } long long count_tastiness(long long x, std::vector<long long> a) { mp.clear(); in.clear(); p[0]=1; for(int i=1; i<60; i++) p[i]=p[i-1]*2; vector<long long> h=a; while(a.size()<60)a.push_back(0); if(x<=10000) { for(int i=0; i<a.size(); i++) { if(a[i]>=x) { long long lf=a[i]-x; a[i]=x+lf%2; a[i+1]+=lf/2; } } dp[60][0]=1; for(int i=59; i>=0; i--) { //cout<<a[i]<<" "; for(int j=0; j<=10000; j++) { dp[i][j]=0; if((j+a[i])/2<=10000)dp[i][j]=dp[i+1][(j+a[i])/2]; if(j+a[i]>=x&&(j+a[i]-x)/2<=10000)dp[i][j]+=dp[i+1][(j+a[i]-x)/2]; //cout<<i<<" "<<j<<" "<<dp[i][j]<<endl; } } //cout<<endl; //return dp[0][0]; //cout<<dp[0][0]<<endl; } nd=x; s[0]=a[0]; for(int i=1; i<60; i++) s[i]=s[i-1]+a[i]*p[i]; //cout<<"out"<<endl; return compute(s[59]); ans=0; v.clear(); v.push_back(0); for(int i=0; i<60; i++) { int sz=v.size(); int j=0; while(j<sz&&(v[j]+p[i])<=s[i]/nd) { v.push_back(v[j]+p[i]); j++; } } /*cout<<"? "<<v.size()<<endl; if(v.size()!=dp[0][0]) { cout<<x<<endl; for(int i=0;i<a.size();i++) cout<<a[i]<<" "; cout<<endl; exit(0); }*/ return v.size(); } /* vector<long long> c(10); void gen() { int k=5; int x=rand()%5+2; for(int i=0; i<k; i++) c[i]=rand()%100; cout<<count_tastiness(x,c)<<endl; } int main() { while(1) { gen(); } } */
#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...