제출 #1052513

#제출 시각아이디문제언어결과실행 시간메모리
1052513noyancanturk비스킷 담기 (IOI20_biscuits)C++17
35 / 100
8 ms1372 KiB
#include "biscuits.h"

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

using lint=long long;
using llint=__int128_t;

lint count_tastiness(lint x,vector<lint> a) {
	int n=a.size();
	llint b[n+31]{};
	llint need[n+31];
	need[0]=x;
	for(int i=1;i<n+31;i++){
		need[i]=need[i-1]*2;
	}
	llint dude=1;
	for(int i=0;i<n+31;i++){
		if(i<n)b[i]+=a[i]*dude;
		if(need[i]<b[i]){
			b[i+1]=b[i]-need[i];
			b[i]=need[i];
		}
		dude*=2;
		//cerr<<lint(b[i])<<" ";
	}//cerr<<"\n";
	llint dp[n+31]{};
	llint dppref[n+31];
	for(int i=0;i<n+31;i++){
		if(b[i]==need[i]){
			if(i)dp[i]=dppref[i-1];
			else dp[i]=1;
		}else{
			dp[i]=0;
			llint neednow=need[i],have=0;
			for(int j=i;0<=j;j--){
				have+=b[j];
				if(neednow<=have){
					if(j)dp[i]+=dppref[j-1];
					else dp[i]++;
					have-=neednow;
					neednow=need[j];
				}
			}
		}
		dppref[i]=dp[i];
		if(i)dppref[i]+=dppref[i-1];
		else dppref[i]++;
	}
	lint ans=1;
	for(int i=0;i<n+31;i++){
		ans+=dp[i];
		//if(i<5)cerr<<lint(dp[i])<<" "<<lint(dppref[i])<<" "<<i<<" dpval\n";
	}
	return ans;
}

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