제출 #422717

#제출 시각아이디문제언어결과실행 시간메모리
422717MazaalaiPacking Biscuits (IOI20_biscuits)C++14
100 / 100
89 ms1324 KiB
#include "biscuits.h"
#include <vector>
#include <map>

using namespace std;
map<long long, long long> m;
int lg(long long a) {
	for (int i = 60; i > 0; i--) {
		if (1ll<<i & a) return i;
	}
	return 0;
}
long long f(vector<long long> &s, long long x, long long n) {
    if(n<=0) return 0;
    if(n==1) return 1;
    if(m.find(n)!=m.end()) {
        return m[n];
    }
    long long a = lg(n-1);
    return m[n] = f(s,x,1LL<<a) + f(s,x,min(n,1+s[a]/x)-(1LL<<a));
}
long long count_tastiness(long long x, std::vector<long long> a) {
    m.clear();
    for(int i=1; i<(int)a.size(); i++) {
        a[i] = a[i-1] + (a[i]<<i);
    }
    while(a.size()<=60) a.push_back(a.back());
	return f(a, x, 1+a.back());
}
#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...