이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "biscuits.h"
#include <bits/stdc++.h>
using namespace std;
template<typename T>
using min_heap = priority_queue<T, vector<T>, greater<T>>;
template<typename T>
using max_heap = priority_queue<T, vector<T>, less<T>>;
using int64 = long long;
using ld = long double;
constexpr int kInf = 1e9 + 10;
constexpr int64 kInf64 = 1e15 + 10;
constexpr int kMod = 1e9 + 7;
constexpr int kBits = 17;
string to_bin(const int64 y) {
string ans;
for (int bit = 0; bit < kBits; bit++) {
ans += (y & (1LL << bit)) ? '1' : '0';
}
return ans;
}
int64 count_tastiness(int64 x, vector<int64> a) {
while (a.back() == 0) a.pop_back();
while (a.size() < kBits) a.push_back(0);
const int n = a.size();
int64 total = 0;
for (int i = 0; i < n; i++) {
total += (a[i] << i);
}
const int64 ymax = total / x;
auto check = [&](vector<int64> &biscuits, const string &y) -> bool {
int64 need = 0;
for (int i = y.size() - 1; i >= 0; i--) {
if (y[i] == '1') need++;
const int64 dec = min(need, biscuits[i]);
biscuits[i] -= dec;
need -= dec;
need *= 2;
}
return not need;
};
int64 ans = 0;
for (int y = 0; y <= ymax; y++) {
auto biscuits = a;
string bin = to_bin(y).substr(0, n);
bool flag = true;
for (int bag = 0; bag < x; bag++) {
flag &= check(biscuits, bin);
}
ans += flag;
}
return ans;
}
# | 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... |