이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "biscuits.h"
#include <algorithm>
#include <iostream>
#include <numeric>
#include <cassert>
#include <vector>
#include <map>
typedef long long llong;
const int MAXN = 64;
const llong INF = 1e18;
struct Key
{
int bit;
llong max;
friend bool operator < (const Key &a, const Key &b)
{
return a.bit < b.bit || (a.bit == b.bit && a.max < b.max);
}
};
int n;
llong x;
llong a[MAXN];
llong s[MAXN];
std::map <Key, llong> mem;
llong f(int bit, llong max)
{
if (max < 0)
{
return 0;
}
if (bit == -1)
{
return 1;
}
if (max > (1LL << bit + 1))
{
return f(bit - 1, max);
}
if (mem.count({bit, max}))
{
return mem[{bit, max}];
}
mem[{bit, max}] = f(bit - 1, std::min(max, (1LL << bit) - 1));
mem[{bit, max}] += f(bit - 1, std::min(max, s[bit] / x) - (1LL << bit));
return mem[{bit, max}];
}
llong count_tastiness(llong X, std::vector <llong> A)
{
n = A.size();
x = X;
for (int i = 0 ; i < MAXN ; ++i)
{
if (i < n)
{
a[i] = A[i];
s[i] = a[i] * (1LL << i);
} else
{
s[i] = 0;
}
if (i > 0) s[i] += s[i - 1];
}
mem.clear();
return f(60, INF);
}
컴파일 시 표준 에러 (stderr) 메시지
biscuits.cpp: In function 'llong f(int, llong)':
biscuits.cpp:42:27: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
42 | if (max > (1LL << bit + 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... |