Submission #777026

#TimeUsernameProblemLanguageResultExecution timeMemory
777026Soumya1Packing Biscuits (IOI20_biscuits)C++17
100 / 100
49 ms1340 KiB
#include "biscuits.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll x;
vector<ll> a, sum;
map<ll, ll> dp;
ll solve(ll n) {
	if (n <= 1) return n;
	if (dp.find(n) != dp.end()) return dp[n];
	int i = 63 - __builtin_clzll(n);
	if ((1LL << i) == n) i--;
	return dp[n] = solve(1LL << i) + solve(max(0LL, min(n, sum[i] / x + 1) - (1LL << i)));
}
long long count_tastiness(long long _x, std::vector<long long> _a) {
	x = _x, a = _a;
	sum.clear();
	dp.clear();
	while (a.size() < 60) a.push_back(0);
	for (int i = 0; i < 60; i++) {
		sum.push_back((sum.empty() ? 0LL : sum.back()) + a[i] * (1LL << i));
	}
	return solve(1LL << 60);
}

#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...