이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//Challenge: Accepted
#include <bits/stdc++.h>
using namespace std;
#ifdef zisk
void debug(){cout << endl;}
template<class T, class ... U> void debug(T a, U ... b){cout << a << " ", debug(b...);}
template<class T> void pary(T l, T r){
while (l != r) cout << *l << " ", l++;
cout << endl;
}
#else
#define debug(...) 0
#define pary(...) 0
#endif
#define ll long long
#define lb __int128
#define maxn 100005
#define pii pair<int, int>
#define ff first
#define ss second
#include "biscuits.h"
vector<lb> f, sum;
lb getcnt(lb v, int k) {
if (v < 0) return 0;
if (k < 0) return 1;
if (v>>k) {
return (k ? sum[k-1] : 1) + getcnt(min(v - ((v>>k)<<k), f[k]), k-1);
} else {
return getcnt(v, k-1);
}
}
long long count_tastiness(long long x, std::vector<long long> a) {
for (int i = 0;i < 30;i++) a.push_back(0);
int k = a.size();
for (int i = 0;i < k-1;i++) {
ll d = max(0LL, ((a[i] - x)/2)*2);
a[i] -= d;
a[i+1] += d/2;
}
f.clear(), sum.clear();
f.resize(k, 0);
sum.resize(k, 0);
for (int i = 0;i < k;i++) {
lb tot = 0;
for (int j = i-1;j >= 0;j--) {
tot <<= 1;
tot += a[j];
}
tot = min(tot, tot + (((lb)(a[i] - x))<<i));
if (tot < 0) tot = -1;
else tot = tot / x;
f[i] = tot;
}
//pary(f.begin(), f.end());
for (int i = 0;i < k;i++) {
//debug(f[i], i-1, getcnt(f[i], i-1));
sum[i] = (i ? sum[i-1] : 1) + getcnt(f[i], i-1);
}
return sum[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... |