#include "biscuits.h"
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx,avx2")
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
#include<chrono>
#include<iomanip>
using namespace std;
typedef long long ll;
namespace{
int ori[20], a[20];
}
long long count_tastiness(ll k, std::vector<long long> vec) {
auto st = clock();
ll sum = 0;
while(!vec.empty() && vec.back() == 0) vec.pop_back();
int n = (int)vec.size();
for(int i = 0; i < n; i++) sum += (vec[i] << i);
if(k == 1){
ll now = 0, base = 1, ans = 1;
for(int i = 0; i < n; i++){
now += vec[i] * base;
if(now < base * 2){
ans *= (now / k + 1);
now = 0;
base = 1;
}
else base *= 2;
}
return ans * (now / k + 1);
}
for(int i = 0; i < n; i++) ori[i] = vec[i];
auto f = [&](int now){
for(int i = 0; i < n; i++) a[i] = ori[i];
for(int times = 0; times < k; times++){
int x = now;
for(int i = n - 1; i >= 0; i--){
if(x == 0) break;
if(a[i] < (x >> i)){
x -= (a[i] << i);
a[i] = 0;
}
else{
a[i] -= (x >> i);
x -= ((x >> i) << i);
}
}
if(x != 0) return 0;
}
return 1;
};
int ans = 0;
for(int i = 0; i * k <= sum; i++){
ans += f(i);
//if(f(i) == 1) cout << i << endl;
if(float(clock() - st) / CLOCKS_PER_SEC > 0.085) return ans;
}
return ans;
}
// g++ -std=c++17 -Wall -Wextra -Wshadow -fsanitize=undefined -fsanitize=address -o run -g biscuits.cpp grader.cpp
# | 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... |