이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define forint(i, N) for (long long i = 0; i < (N); i++)
using namespace std;
void takeout(vector<long long>& a, long long pos, long long val) {
if (a[pos] * (1ll << pos) < val) {
takeout(a, pos-1, val - a[pos] * (1ll << pos));
a[pos] = 0;
return;
}
long long v = val / (1ll << pos);
a[pos] -= v;
if (v * (1ll << pos) < val) {
takeout(a, pos-1, val - v * (1ll << pos));
}
}
long long count(long long x, vector<long long>& a, long long max_y) {
if (max_y == 0) {
return 1;
}
if (max_y == 1) {
if (a[0] >= x) {
return 2; // 0 & 1;
}
else {
return 1; // 0 only
}
}
long long k = a.size();
vector<long long> sum(61, 0);
sum[0] = a[0];
for (long long i = 1; i < k; i++) {
sum[i] = sum[i - 1] + a[i] * (1ll << i);
}
for (long long i = k; i < 61; i++) {
sum[i] = sum[i-1];
}
// find i
long long i = 0;
while ((1ll << i) < max_y) {
i++;
}
if (max_y == (1ll << i)) {
if (sum[i] >= max_y * x) {
return count(x, a, max_y - 1) + 1;
}
else {
return count(x, a, max_y - 1);
}
}
long long aa = count(x, a, 1ll << (i-1));
if (sum[i-1] < (1ll << (i-1)) *x ) {
return aa;
}
else {
vector<long long> b(i, 0);
forint(j, i) {
b[j] = a[j];
}
takeout(b, i-1, (1ll << (i-1))*x);
return aa + count(x, b, max_y - (1ll << (i-1))) - 1; // 0 has been counted
}
}
long long count_tastiness(long long x, vector<long long> a) {
return count(x, a, 1e18);
}
# | 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... |