(UPD: 2024-12-04 14:48 UTC) Judge is not working due to Cloudflare incident. (URL) We can do nothing about it, sorry. After the incident is resolved, we will grade all submissions.

Submission #333312

#TimeUsernameProblemLanguageResultExecution timeMemory
333312katearimaPacking Biscuits (IOI20_biscuits)C++14
100 / 100
487 ms1516 KiB
#include "biscuits.h" #include <bits/stdc++.h> #define ll long long using namespace std; const int k=61; int i; int nearest(ll u){ vector<int> v; while(u>0){ v.push_back(u%2); u/=2; } for(int i=v.size()-1; i>=0; i--){ if(v[i]==1) return i; } return -1; } long long count_tastiness(long long x, vector<long long> a) { vector<ll> s(k+1),ans(k+1), s1(k+1); int n=a.size(); for(i=0; i<n; i++){ ll p=pow(2,i); //s[i]=(long long)((double)a[i]/x*pow(2,i)); s[i]=a[i]*p/x; s1[i]=((a[i]%x)*((ll)pow(2,i)%x))%x; } for(i=1; i<k; i++){ s[i]+=s[i-1]; s1[i]+=s1[i-1]; s[i]+=s1[i]/x; s1[i]%=x; } ans[0]=1; for(i=1; i<k; i++){ ans[i]+=ans[i-1]; int j=i-1; ll c=1; ll p; int t=0; while(c>0){ p=pow(2,j); if(t==0) c=min(s[j],2*p-1)-p; else c=min(s[j], c)-p; if(c==0){ ans[i]++; break; } if(c<0) break; //if(i==58) cout<<c<<endl; j=nearest(c); ans[i]+=ans[j]; t++; } //cout<<i<<" "<<ans[i]<<endl; } return ans[k-1]; return 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...