Submission #392195

# Submission time Handle Problem Language Result Execution time Memory
392195 2021-04-20T15:49:41 Z johutha Packing Biscuits (IOI20_biscuits) C++17
0 / 100
5 ms 332 KB
#include "biscuits.h"
#include <iostream>

#define int long long

using namespace std;

int count_tastiness(int x, vector<int> a)
{
	vector<int> dpref(63);
	vector<int> vpref(63);
	vector<int> dp(62);
	a.resize(64);

	int v = 0;
	int pw = 1;

	for (int i = 0; i < 62; i++, pw *= 2)
	{
		v += a[i]*pw;
		vpref[i] = v;

		int b = v - pw*x;
		int np = pw / 2;
		// cerr << "Starting " << i << ": " << v << " " << b << "\n";

		for (int j = i - 1; j >= 0; j--, np /= 2)
		{
			// cerr << " -> " <<  j << " " << b << " " << np << "\n";
			if (b >= np*x && vpref[j] >= np * x)
			{
				b -= np*x;
				dp[i] += 1 + dpref[j];
			}
		}
		if (b >= 0) dp[i]++;

		dpref[i + 1] = dpref[i] + dp[i];
		// cerr << i << " " << dp[i] << " " << dpref[i] << "\n";
	}

	return dpref.back() + 1;
}

using namespace std;
using ll = long long;
using ull = unsigned long long;
const ull INF = 2e18+1;
 
ll count_correct(ll _x, vector<ll> _a) {
	ull x = _x;
	int k = _a.size();
	vector<ull> a(k+60, 0); for(int i=0; i<k; ++i) a[i] = _a[i];
	
	k+=60;
 
	vector<ull> dp(k), dp0(k), pref(k);
	pref[0] = a[0];
	for(int i=1; i<k; ++i) {
		pref[i] = pref[i-1]/2 + a[i];
	}
	for(int i=0; i<k; ++i) {
		if(i>0) {
			dp0[i] = dp[i-1];
		}
		else {
			dp0[i] = 1;
		}
		ull sum = 0;
		dp[i] = 1;
		for(int j=i; j>=0; --j) {
			if(pref[j] >= x + sum) {
				dp[i] += dp0[j];
				if(sum < INF && sum + x < INF) {
					sum += x;
					if(a[j] > sum) sum = 0;
					else sum -= a[j];
					sum *= 2;
				}
				else {
					sum = INF;
				}
			}
			else {
				if(a[j] > sum) sum = 0;
				else sum -= a[j];
				if(sum < INF) sum *= 2;
				else sum = INF;
			}
		}
	}
	return dp[k-1];
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 296 KB Output is correct
2 Incorrect 1 ms 204 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Incorrect 1 ms 204 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 296 KB Output is correct
2 Incorrect 1 ms 204 KB Output isn't correct
3 Halted 0 ms 0 KB -