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 "biscuits.h"
#include <algorithm>
#include <queue>
#include <iostream>
using ll = long long;
std::vector<ll> ori_dp;
std::vector<ll> sum_ori_dp;
long long func1(long long x,std::vector<long long> a) {
if(a.size() == 0) return 1;
if(a.size() == 1) return a.back() >= x ? 2 : 1;
ll ans = sum_ori_dp[a.size() - 2];
std::vector<ll> s(a.begin(),a.begin() + a.size() - 1);
ll require = x - a.back();
while(require > 0 && s.size()) {
require *= 2;
if(require >= s.back()) {
require -= s.back();
s.pop_back();
}
else {
s.back() -= require;
require = 0;
break;
}
}
while(s.back() == 0 && s.size()) s.pop_back();
if(require <= 0) ans += func1(x,s);
return ans;
}
long long count_tastiness(long long x, std::vector<long long> a) {
ori_dp.clear();
sum_ori_dp.clear();
ori_dp.push_back(a[0] >= x ? 2 : 1);
sum_ori_dp.push_back(a[0] >= x ? 2 : 1);
for(int q = 1;q < a.size();q++) {
ll local_ans = 0;
std::vector<ll> s(a.begin(),a.begin() + q);
ll require = x - a[q];
while(require > 0 && s.size()) {
require *= 2;
if(s.back() <= require) {
require -= s.back();
s.pop_back();
}
else {
s.back() -= require;
require = 0;
break;
}
}
while(s.back() == 0 && s.size()) s.pop_back();
if(require <= 0)
local_ans += func1(x,s);
//std::cout << "local ans" << local_ans << std::endl;
ori_dp.push_back(local_ans);
sum_ori_dp.push_back(sum_ori_dp.back() + ori_dp.back());
}
// for(int q = 0;q < ori_dp.size();q++) {
// std::cout << ori_dp[q] << " ";
// }
// std::cout << std::endl;
return sum_ori_dp.back();
}
// #include <cassert>
// #include <cstdio>
// using namespace std;
// int main() {
// int q;
// assert(scanf("%d", &q) == 1);
// vector<int> k(q);
// vector<long long> x(q);
// vector<vector<long long>> a(q);
// vector<long long> results(q);
// for (int t = 0; t < q; t++) {
// assert(scanf("%d%lld", &k[t], &x[t]) == 2);
// a[t] = vector<long long>(k[t]);
// for (int i = 0; i < k[t]; i++) {
// assert(scanf("%lld", &a[t][i]) == 1);
// }
// }
// fclose(stdin);
// for (int t = 0; t < q; t++) {
// results[t] = count_tastiness(x[t], a[t]);
// }
// for (int t = 0; t < q; t++) {
// printf("%lld\n", results[t]);
// }
// fclose(stdout);
// return 0;
// }
Compilation message (stderr)
biscuits.cpp: In function 'long long int count_tastiness(long long int, std::vector<long long int>)':
biscuits.cpp:41:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
41 | for(int q = 1;q < a.size();q++) {
| ~~^~~~~~~~~~
# | 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... |