이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// biscuits-likai-ac
#include "biscuits.h"
#include <vector>
using namespace std;
long long count_tastiness(long long X, std::vector<long long> A) {
int K = 63;
while (A.size() < 63) A.push_back(0);
vector<long long> MEM(K); //number of solutions in range [0..2^i-1]
vector<long long> PTH(K); //previous thresholds
long long CURSUM = 0;
for (int i = 0; i < K; i++) {
if (i) CURSUM += A[i - 1] * (1LL << (i - 1));
MEM[i] = 0;
long long CTH = CURSUM / X; //maximum possible solution
PTH[i] = CTH;
if (i == 0) {
MEM[i] = 1;
continue;
}
for (int j = i - 1; j >= 0; j--) {
if (j == 0) { //special case: 0 or 1
if (CTH >= 1) MEM[i] += 2;
else MEM[i] += 1;
}
else if (CTH >= (1LL << (j + 1))) { //threshold is bigger than entire range
MEM[i] += 2LL * MEM[j];
break;
}
else if (CTH >= (1LL << j)) { //threshold is bigger than half the range
MEM[i] += MEM[j];
CTH = min(CTH - (1LL << j), PTH[j]);
}
else CTH = min(CTH, PTH[j]);
}
}
return MEM[K - 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... |