제출 #830439

#제출 시각아이디문제언어결과실행 시간메모리
830439amunduzbaev비스킷 담기 (IOI20_biscuits)C++17
21 / 100
7 ms720 KiB
#include "biscuits.h"

#include "bits/stdc++.h"
using namespace std;

#define ar array
typedef long long ll;
//~ #defien int ll

ll count_tastiness(ll x, vector<ll> a) {
	
	int k = 60;
	a.resize(k);
	vector<ll> pref(k);
	for(int i=0;i<k;i++){
		if(i) pref[i] = pref[i - 1];
		pref[i] += a[i] * (1ll << i);
	}
	
	//~ for(int i=0;i<k;i++){
		//~ cout<<pref[i]<<" ";
	//~ }
	//~ cout<<"\n";
	
	ll sum = 1;
	vector<__int128> dp(k), L(k), toob(k);
	
	for(int i=0;i<k;i++){
		L[i] = (1ll << (i + 1));
		if(pref[i] / x < (1ll << i)) continue;
		L[i] = pref[i] / x + 1;
		__int128 L_ = L[i] - (1ll << i);
		dp[i] = sum;
		
		for(int j=i-1;~j;j--){
			if(L_ <= (1ll << j)){
				toob[i] += dp[j];
			} else {
				if(L[j] <= L_) break;
				else toob[i] -= toob[j], L_ -= (1ll << j);
			}
		}
		
		dp[i] -= toob[i];
		
		//~ cout<<dp[i]<<" ";
		sum += dp[i];
	}
	//~ cout<<"\n";
	
	return sum;
}

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