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 <cassert>
#include <algorithm>
#include <cstdio>
#include <map>
long long x;
std::vector<long long> s;
std::map<long long, long long> mp;
long long g(long long n, int i) {
if(n <= 0) return 0;
if(n == 1) return 1;
if(mp.count(n)) return mp[n];
// retorno quantos caras menores que n são validos
// opção 1: não usar o i-ésimo bit
long long ans = g(1ll<<i, i-1);
// opção 2: usar o i-ésimo bit, porém tenho que garantir que a soma do valor é suficiente
// aka as: s[i] >= y*x ==(estou usando o i-ésimo bit)=> s[i]/x > (y + 1<<i) - 1 ==> s[i]/x + 1 - (1<<i) > y
ans += g(std::min(n, s[i]/x + 1) - (1ll << i), i-1);
mp[n] = ans;
return ans;
}
long long count_tastiness(long long X, std::vector<long long> a) {
mp.clear();
x = X;
s.resize(a.size());
s[0] = a[0];
for(int i = 1; i < (int)s.size(); i++)
s[i] = (1ll << i) * a[i] + s[i-1];
return g(1ll<<s.size(), s.size()-1);
}
# | 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... |