제출 #333305

#제출 시각아이디문제언어결과실행 시간메모리
333305katearima비스킷 담기 (IOI20_biscuits)C++14
44 / 100
32 ms1336 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), s2(k+1); int n=a.size(); for(i=0; i<n; i++){ s[i]=(ll)((double)a[i]/x*pow(2,i)); s1[i]=((a[i]%x)*((ll)pow(2,i)%x))%x; } /*for(i=0; i<10; i++){ cout<<s[i]<<" "<<s1[i]<<endl; }*/ for(i=1; i<k; i++){ s[i]+=s[i-1]; s1[i]+=s1[i-1]; s[i]+=s1[i]/x; s1[i]%=x; } /*for(i=0; i<10; i++){ cout<<s[i]<<endl; }*/ 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; // /x else c=min(s[j], c)-p; if(c==0){ ans[i]++; break; } if(c<0) break; j=nearest(c); ans[i]+=ans[j]; t++; } //cout<<i<<" "<<ans[i]<<endl; } //cout<<ans[k-1]<<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...