제출 #824841

#제출 시각아이디문제언어결과실행 시간메모리
824841NothingXD비스킷 담기 (IOI20_biscuits)C++17
100 / 100
49 ms1324 KiB
#include "biscuits.h"
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

void debug_out(){cerr << endl;}
template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T){
	cerr << H << ' ';
	debug_out(T...);
}

#define debug(...) cerr << "(" << #__VA_ARGS__ << "): ", debug_out(__VA_ARGS__)
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define MP(x, y) make_pair(x, y)

const int maxn = 100;
const ll inf = 2e18;

ll dp[maxn][2];

long long count_tastiness(long long x, std::vector<long long> a) {
	dp[0][0] = dp[0][1] = 1;
	for (int i = 1; i <= a.size(); i++){
		dp[i][0] = dp[i][1] = 0;
		ll tmp = (x-a[i-1]%x) % x;
		dp[i][0] = (dp[i-1][1]) * ((a[i-1]+x-1) / x);
		ll idx = i-1;
		while(idx > 0){
			tmp *= 2;
			tmp = min(tmp, inf);
		//	debug(dp[i][0], idx, a[idx-1], tmp);
			if (a[idx-1] < tmp){
				tmp -= a[idx-1];
				idx--;
				continue;
			}
			dp[i][0] += (dp[idx-1][1]) * ((a[idx-1]-tmp+x-1) / x);
			tmp = (x-(a[idx-1]-tmp)%x) % x;
			idx--;
		}
		//debug(tmp);
		if (tmp == 0) dp[i][0]++;
		//debug(i, dp[i][0]);
		if (i == a.size()) break;
		tmp = 0;
		idx = i;
		ll lim = x;
		bool ok = true;
		while(idx > 0){
			tmp *= 2;
			tmp = min(tmp, inf);
		//	debug(dp[i][1], idx, tmp, lim);
			if (lim < a[idx-1]){
				if (tmp > lim){
					ok = false;
					break;
				}
		//		debug((lim-1)-tmp);
				dp[i][1] += dp[idx-1][1] * ((lim-tmp) / x + 1);
				ok = false;
				break;
			}
			if (a[idx-1] < tmp){
				tmp -= a[idx-1];
				lim -= a[idx-1];
				lim *= 2;
				lim = min(lim, inf);
				lim += x;
				lim = min(lim, inf);
				idx--;
				continue;
			}
			dp[i][1] += (dp[idx-1][1]) * ((a[idx-1]-tmp+x-1) / x);
			tmp = (x-(a[idx-1]-tmp)%x) % x;
			lim -= a[idx-1];
			lim *= 2;
			lim = min(lim, inf);
			lim += x;
			lim = min(lim, inf);
			idx--;
		}
		if (ok && tmp == 0) dp[i][1]++;
	//	debug(i, dp[i][1]);
	}
	//debug(a.size(), dp[a.size()][0]);
	return dp[a.size()][0];
}

컴파일 시 표준 에러 (stderr) 메시지

biscuits.cpp: In function 'long long int count_tastiness(long long int, std::vector<long long int>)':
biscuits.cpp:30:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |  for (int i = 1; i <= a.size(); i++){
      |                  ~~^~~~~~~~~~~
biscuits.cpp:51:9: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |   if (i == a.size()) break;
      |       ~~^~~~~~~~~~~
#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...