이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "biscuits.h"
#include <bits/stdc++.h>
#define F first
#define S second
#define pb push_back
using namespace std;
typedef long long ll;
const int N = 63;
ll dp[N];
ll Get(ll idx, ll i){
if(idx == 0)
return i;
assert(i < dp[idx]);
if(i < dp[idx - 1])
return Get(idx - 1, i);
return Get(idx - 1, i - dp[idx - 1]) + (1ll << idx);
}
int k;
ll x;
vector<ll> nw;
bool Valid(ll y){
vector<ll> tmp = nw;
tmp.resize(N, 0);
for(int i = 0; i < N; i++){
if(y >> i & 1){
if(tmp[i] < x) return false;
tmp[i] -= x;
}
if(i + 1 != N)
tmp[i + 1] += tmp[i] / 2;
}
return true;
}
ll count_tastiness(ll _x, vector<ll> a) {
a.resize(N, 0);
k = a.size();
nw = a;
x = _x;
// a.insert(a.begin(), 0);
dp[0] = (a[0] >= x ? 2 : 1);
for(int i = 1; i < N; i++){
ll L = -1, R = dp[i - 1], mid;
while(L + 1 < R){
mid = (L + R) >> 1;
if(Valid((1ll << i) + Get(i - 1, mid))){
// cerr << "^ " << (1ll << i) + Get(i - 1, mid) << '\n';
L = mid;
} else {
R = mid;
}
}
// cerr << "!! " << Get(i - 1, 0) << ' ' << dp[i - 1] << ' ' << R << '\n';
dp[i] = dp[i - 1] + R;
}
// cerr << "&& " << Valid(2) << '\n';
// for(int i = 0; i < 5; i++) cerr << dp[i] << ' ';
// cerr << '\n';
return dp[N - 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... |