This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#include "biscuits.h"
using namespace std;
using ll = long long;
ll count_tastiness(ll x, vector<ll> a) {
ll ans = 1;
priority_queue<pair<ll, ll>> pq;
for(int i=a.size()-1;i>=0;i--){
ll u = 1ll << i;
if(a[i]){
ll p = 0;
queue<pair<ll, ll>> q;
while(!pq.empty() && pq.top().first > u){
auto [x, y] = pq.top(); pq.pop();
ll s = min(x / u, a[i] + 1);
p += (s - 1) * y;
ans += (s - 1) * y;
if(x > u * s) q.push({x - u * s, y});
else p += y;
}
while(!q.empty()) pq.push(q.front()), q.pop();
ans += a[i];
pq.push({u, a[i] + p});
}
}
// while(!pq.empty()) printf("%lld %lld\n",pq.top().first,pq.top().second), pq.pop();
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... |