Submission #834793

#TimeUsernameProblemLanguageResultExecution timeMemory
834793Johann비스킷 담기 (IOI20_biscuits)C++14
100 / 100
58 ms1320 KiB
#include "biscuits.h"
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()

ll X;
ll base[64];
vector<ll> S;

map<ll, ll> G;
ll g(ll n)
{
	if (n <= 1)
		return max(0LL, n);
	if (G.find(n) != G.end())
		return G[n];
	int power = (lower_bound(base, base + 62, n) - base) - 1;
	return G[n] = g(1LL << power) + g(min(n, S[min(power, sz(S) - 1)] / X + 1) - (1LL << power));
}

long long count_tastiness(long long _X, std::vector<long long> a)
{
	X = _X;
	G.clear();
	S.assign(sz(a) + 1, 0);
	base[0] = 1;
	for (int i = 0; i < 62; ++i)
		base[i + 1] = 2 * base[i];
	for (int i = 0; i < sz(a); ++i)
	{
		S[i] += a[i] * base[i];
		S[i + 1] += S[i];
	}

	return g(S.back() / X + 1);
}
#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...