This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "biscuits.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
#define sz(x) (int)(x).size()
#define pb push_back
int k;
vl a;
ll x;
ll tpow[61];
bool possible(ll y){
vl A = a;
for(int i = 0; i <= 59; i++){
if((y>>i)&1){
A[i]-=x;
}
if(A[i] < 0) return 0;
if(i+1 < 60){
A[i+1]+=A[i]/2;
}
}
//cout << y << "\n";
return 1;
}
ll solveCase1(){
while(sz(a) < 60){
a.pb(0);
}
int ans = 0;
for(int y = 0; y <= 100000; y++){
if(possible(y)){
ans++;
}
}
return ans;
}
ll restr[60];
ll dp[60];
ll getDP(ll v, int bitnum){
assert(v >= 0);
if(bitnum == 0){
if(v == 0){
return 1;
}
else if(v == 1){
return dp[bitnum];
}
assert(false);
}
if(v < tpow[bitnum]){
return getDP(v, bitnum-1);
}
if(restr[bitnum] < tpow[bitnum]){
return getDP(v-tpow[bitnum], bitnum-1);
}
return dp[bitnum-1]+getDP(min(v-tpow[bitnum], restr[bitnum]-tpow[bitnum]), bitnum-1);
}
ll count_tastiness(ll _x, vl _a) {
x = _x;
a = _a;
while(sz(a) < 60){
a.pb(0);
}
k = sz(a);
tpow[0] = 1;
for(int i = 1; i <= 60; i++){
tpow[i] = tpow[i-1]*2;
}
// bool CASE1 = 1;
// if(CASE1){
// return solveCase1();
// }
restr[0] = a[0];
for(int i = 1; i <= 59; i++){
restr[i] = restr[i-1]+tpow[i]*a[i];
}
for(int i = 0; i <= 59; i++){
restr[i]/=x;
}
if(restr[0] >= 1){
dp[0] = 2;
}
else{
dp[0] = 1;
}
for(int i = 1; i <= 59; i++){
dp[i] = getDP(tpow[i+1]-1, i);
}
//assert(solveCase1() == dp[59]);
return dp[59];
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |