제출 #1081650

#제출 시각아이디문제언어결과실행 시간메모리
1081650GrindMachinePacking Biscuits (IOI20_biscuits)C++17
21 / 100
1090 ms600 KiB
#include <bits/stdc++.h>
using namespace std;

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

#define pb push_back
#define endl '\n'
#define conts continue
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define sz(a) (int)a.size()
#define ceil2(x,y) ((x+y-1)/(y))

#define rep(i,n) for(int i = 0; i < n; ++i)
#define rep1(i,n) for(int i = 1; i <= n; ++i)
#define rev(i,s,e) for(int i = s; i >= e; --i)
#define trav(i,a) for(auto &i : a)

template<typename T>
void amin(T &x, T y){
	x = min(x,y);
}

template<typename T>
void amax(T &x, T y){
	x = max(x,y);
}

template<typename A,typename B>
string to_string(pair<A,B> p);

string to_string(const string &s){
	return "'"+s+"'";
}

string to_string(const char* s){
	return to_string((string)s);
}

string to_string(bool b){
	return b?"true":"false";
}

template<typename A>
string to_string(A v){
	string res = "{";
	trav(x,v){
		res += to_string(x)+",";
	}
	if(res.back() == ',') res.pop_back();
	res += "}";
	return res;
}

template<typename A,typename B>
string to_string(pair<A,B> p){
	return "("+to_string(p.ff)+","+to_string(p.ss)+")";
}

#define debug(x) cout << "[" << #x << "]: "; cout << to_string(x) << endl

const int MOD = 1e9 + 7;
const int N = 1e5 + 5;
const int inf1 = 1e9 + 5;
const ll inf2 = (ll)1e18 + 5;

#include "biscuits.h"

void go(){
	ll n = 2e4;
	ll ans = inf2;

	for(int B = 2; B <= n; B += 2){
		ll cost = B-1;
		ll cnt = n;
		ll sub = B/2;

		rep1(iter,inf1){
			if(cnt <= 0) break;
			cost++;
			cnt -= sub;
			if(iter&1) sub++;
		}

		amin(ans,cost);

		// ll cost = B-1+ceil2((n-B),(B/2));
		// amin(ans,cost);
		// if(B == 100){
		// 	debug(cost);
		// }
	}

	debug(ans);
}

long long count_tastiness(long long x, std::vector<long long> a) {
	// go();

	ll n = sz(a);
	ll sum = 0;
	rep(i,n) sum += a[i]*(1ll<<i);

	if(sum == 0){
		return 1;
	}

	if(x == 1){
		while(sz(a) < 65) a.pb(0);
		n = sz(a);

		ll ans = 1;
		ll curr_sum = 0;
		ll bit = 0;

		rep(i,n){
			curr_sum += a[i]*(1ll<<bit);
			bit++;
			if(curr_sum < (1ll<<bit)){
				ans *= (curr_sum+1);
				curr_sum = 0, bit = 0;
			}
		}	

		assert(!bit);
		return ans;
	}

	ll ans = 1;

	rep1(y,sum/x){
		auto b = a;
		bool ok = true;

		rep1(iter,x){
			ll v = y;
			rev(i,n-1,0){
				ll f = 1ll<<i;
				ll sub = min(v/f,b[i]);
				b[i] -= sub;
				v -= sub*f;
			}

			if(v){
				ok = false;
				break;
			}
		}

		ans += ok;
	}

	// ll siz = sz(vals);
	// for(int i = 1; i < siz; i <<= 1){
	// 	vector<int> curr;
	// 	for(int j = i; j < (i<<1) and j < siz; ++j){
	// 		curr.pb(vals[j]);
	// 	}

	// 	reverse(all(curr));
	// 	assert(is_sorted(all(curr)));
	// }

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