Submission #1054812

#TimeUsernameProblemLanguageResultExecution timeMemory
1054812pccPacking Biscuits (IOI20_biscuits)C++17
21 / 100
1087 ms436 KiB
#include "biscuits.h"
#include <bits/stdc++.h>
using namespace std;

#define ll long long

const ll B = 62;

bool check(ll cnt,ll tar,vector<ll> v){
	ll b = __lg(tar);
	while(v.size()<=b)v.push_back(0);
	for(int i = 0;i<=b;i++){
		ll need = cnt*((tar>>i)&1);
		if(need>v[i])return false;
		ll rest = v[i]-need;
		rest>>=1;
		if(i+1<=b)v[i+1] += rest;
	}
	return true;
}

ll calc(vector<ll> &v){
	ll sum = 0;
	for(int i = 0;i<v.size();i++)sum += v[i]*(1ll<<i);
	return sum+1;
}

long long count_tastiness(long long x, std::vector<long long> a) {
	int n = a.size();
	ll sum = 0;
	for(int i = 0;i<a.size();i++)sum += a[i]*(1ll<<i);
	ll ans1,ans2;

	if(x != 1){
		ans1 = 1;
		for(int i = 1;i<=sum;i++)ans1 += check(x,i,a);
		return ans1;
	}
	else{
		ans2 = 1;
		while(a.size()<B)a.push_back(0);
		for(int i = 0;i+1<a.size();i++){
			if(a[i] == 0)continue;
			ll rest = (a[i]-1)>>1;
			a[i+1] += rest;
			a[i] -= rest<<1;
		}
		//for(auto &i:a)cerr<<i<<',';cerr<<endl;
		vector<ll> v;
		for(int i = 0;i<a.size();i++){
			if(a[i] == 0){
				ans2 *= calc(v);
				v.clear();
			}
			else{
				v.push_back(a[i]);
			}
		}
		ans2 *= calc(v);
		v.clear();
		return ans2;
	}

	//cerr<<"ANSES: "<<ans1<<','<<ans2<<endl;
}

Compilation message (stderr)

biscuits.cpp: In function 'bool check(long long int, long long int, std::vector<long long int>)':
biscuits.cpp:11:16: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   11 |  while(v.size()<=b)v.push_back(0);
      |        ~~~~~~~~^~~
biscuits.cpp: In function 'long long int calc(std::vector<long long int>&)':
biscuits.cpp:24:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |  for(int i = 0;i<v.size();i++)sum += v[i]*(1ll<<i);
      |                ~^~~~~~~~~
biscuits.cpp: In function 'long long int count_tastiness(long long int, std::vector<long long int>)':
biscuits.cpp:31:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |  for(int i = 0;i<a.size();i++)sum += a[i]*(1ll<<i);
      |                ~^~~~~~~~~
biscuits.cpp:42:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |   for(int i = 0;i+1<a.size();i++){
      |                 ~~~^~~~~~~~~
biscuits.cpp:50:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |   for(int i = 0;i<a.size();i++){
      |                 ~^~~~~~~~~
biscuits.cpp:29:6: warning: unused variable 'n' [-Wunused-variable]
   29 |  int n = a.size();
      |      ^
#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...