Submission #399635

#TimeUsernameProblemLanguageResultExecution timeMemory
399635nvmdava비스킷 담기 (IOI20_biscuits)C++17
44 / 100
41 ms1204 KiB
#include "biscuits.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long

map<ll, int> res;
const ll MAX = 1'000'000'000'000'000'000;
ll s[100];
int find(ll r){
	if(r < 0) return 0;
	if(r == 0) return 1;
	if(res.count(r))
		return res[r];
	int i = (int)floor(log2(r));
	while((1LL << i ) > r )
		--i;
	return res[r] = find((1LL << i) - 1) + find(min(r, s[i])- (1LL << i));
}

long long count_tastiness(long long x, std::vector<long long> a) {
	res.clear();
	while(a.size() < 60)
		a.push_back(0);

	for(int i = 0; i < 59; ++i){
		ll t = max(0LL, (a[i] - x) / 2);
		a[i] -= t * 2;
		a[i + 1] += t;
	}
	a[59] = min(a[59], x + 1);
	ll t = 0;
	s[0] = a[0] / x;
	t = a[0] % x;
	for(int i = 1; i < 60; ++i){
		s[i] = s[i - 1];
		for(int j = i; j > 0; --j){
			while(a[i] >= x){
				s[i] = min(MAX, s[i] + (1LL << j));
				a[i] -= x;
			}
			a[i] <<= 1;
		}
		while(a[i] >= x){
			a[i] -= x;
			++s[i];
		}
		t += a[i];
		while(t >= x){
			t -= x;
			++s[i];
		}
	}
	return find(MAX);
}

#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...