Submission #1054893

#TimeUsernameProblemLanguageResultExecution timeMemory
1054893pccPacking Biscuits (IOI20_biscuits)C++17
9 / 100
1091 ms448 KiB
#include "biscuits.h" #include <bits/stdc++.h> using namespace std; #define ll long long const ll B = 62; bool check(ll cnt,ll tar,vector<ll> v){ ll b = __lg(tar); while(v.size()<=b)v.push_back(0); for(int i = 0;i<=b;i++){ ll need = cnt*((tar>>i)&1); if(need>v[i])return false; ll rest = v[i]-need; rest>>=1; if(i+1<=b)v[i+1] += rest; } return true; } ll calc(vector<ll> &v){ ll sum = 0; for(int i = 0;i<v.size();i++)sum += v[i]*(1ll<<i); return sum+1; } bool carry(int s,int e,ll tar,vector<ll> v){ for(int i = s;i<e;i++){ v[i+1] += v[i]>>1; } return v[e]>=tar; } ll SUPER(ll x,vector<ll> a){ while(a.size()<B)a.push_back(0); for(int i = 0;i+1<a.size();i++){ if(a[i]<x)continue; ll rest = (a[i]-x)>>1; a[i+1] += rest; a[i] -= rest<<1; } vector<ll> pre(a.size(),-1); for(int i = 0;i<a.size();i++){ for(int j = i;j>=0;j--){ if(carry(j,i,x,a)){ pre[i] = j; break; } } } vector<ll> dp(a.size(),0); for(int i = 0;i<a.size();i++){ if(pre[i] == -1)dp[i] = 0; else if(pre[i] == 0)dp[i] = 1; else{ dp[i] = 1; for(int j = 0;j<pre[i];j++)dp[i] += dp[j]; } } /* cerr<<"A: "<<endl;for(auto &i:a)cerr<<i<<' ';cerr<<endl; cerr<<"PRE: "<<endl;for(auto &i:pre)cerr<<i<<' ';cerr<<endl; cerr<<"DP: "<<endl;for(auto &i:dp)cerr<<i<<' ';cerr<<endl; */ ll re = 1; for(int i = 0;i<a.size();i++)re += dp[i]; return re; } long long count_tastiness(long long x, std::vector<long long> a) { int n = a.size(); ll sum = 0; for(int i = 0;i<a.size();i++)sum += a[i]*(1ll<<i); ll ans1,ans2,ans3; ans3 = SUPER(x,a); ans1 = 1; for(int i = 1;i<=sum;i++)ans1 += check(x,i,a); ans2 = 1; while(a.size()<B)a.push_back(0); for(int i = 0;i+1<a.size();i++){ if(a[i] == 0)continue; ll rest = (a[i]-1)>>1; a[i+1] += rest; a[i] -= rest<<1; } //for(auto &i:a)cerr<<i<<',';cerr<<endl; vector<ll> v; for(int i = 0;i<a.size();i++){ if(a[i] == 0){ ans2 *= calc(v); v.clear(); } else{ v.push_back(a[i]); } } ans2 *= calc(v); v.clear(); //cerr<<"ANSES: "<<ans1<<','<<ans2<<','<<ans3<<endl; return ans1; }

Compilation message (stderr)

biscuits.cpp: In function 'bool check(long long int, long long int, std::vector<long long int>)':
biscuits.cpp:11:16: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   11 |  while(v.size()<=b)v.push_back(0);
      |        ~~~~~~~~^~~
biscuits.cpp: In function 'long long int calc(std::vector<long long int>&)':
biscuits.cpp:24:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |  for(int i = 0;i<v.size();i++)sum += v[i]*(1ll<<i);
      |                ~^~~~~~~~~
biscuits.cpp: In function 'long long int SUPER(long long int, std::vector<long long int>)':
biscuits.cpp:37:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |  for(int i = 0;i+1<a.size();i++){
      |                ~~~^~~~~~~~~
biscuits.cpp:44:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |  for(int i = 0;i<a.size();i++){
      |                ~^~~~~~~~~
biscuits.cpp:53:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |  for(int i = 0;i<a.size();i++){
      |                ~^~~~~~~~~
biscuits.cpp:67:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   67 |  for(int i = 0;i<a.size();i++)re += dp[i];
      |                ~^~~~~~~~~
biscuits.cpp: In function 'long long int count_tastiness(long long int, std::vector<long long int>)':
biscuits.cpp:74:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   74 |  for(int i = 0;i<a.size();i++)sum += a[i]*(1ll<<i);
      |                ~^~~~~~~~~
biscuits.cpp:84:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   84 |  for(int i = 0;i+1<a.size();i++){
      |                ~~~^~~~~~~~~
biscuits.cpp:92:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   92 |  for(int i = 0;i<a.size();i++){
      |                ~^~~~~~~~~
biscuits.cpp:72:6: warning: unused variable 'n' [-Wunused-variable]
   72 |  int n = a.size();
      |      ^
biscuits.cpp:75:15: warning: variable 'ans3' set but not used [-Wunused-but-set-variable]
   75 |  ll ans1,ans2,ans3;
      |               ^~~~
#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...