Submission #378241

# Submission time Handle Problem Language Result Execution time Memory
378241 2021-03-16T10:18:29 Z Thistle Packing Biscuits (IOI20_biscuits) C++14
12 / 100
1000 ms 14444 KB
#include "biscuits.h"
#include <vector>
#include<iostream>
#include<algorithm>
#include<unordered_map>
#include<queue>
#include<map>
using namespace std;
using ll=long long;
using H=pair<ll, ll>;
using vi=vector<ll>;
#define rng(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define rep(i,n) rng((i),(0),(n))
#define pb push_back
#define vec vector
#define all(a) (a).begin(),(a).end()
#define fs first
#define sc second
#define siz(a) ll((a).size())


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

	ll k=siz(a);
	a.resize(60);
	rng(i,k,60) a[i]=0;
	unordered_map<ll, ll>mp[61];
	//remain cookie -> able number

	//i no jiten de no atai ga t ika dattara j made tobashimasu
	//i+1 ha t ijou no atai nara soko ni iku keishiki ni narimasu
	vec<vi> csum(60,vi(60));
	rep(i,60){
		ll sum=0;
		rng(j,i+1,60){
			sum>>=1;
			csum[i][j]=sum;
			sum+=a[j];
		}
	}
	vec<vi> num(60),val(60);
	rep(i,60){
		ll sum=0,mn=1000000000000000000;
		rng(j,i+1,60){
			sum>>=1;
			sum+=a[j];
			if(sum>=x){
				num[i].pb(mn);
				val[i].pb(j);
				mn=-1;
				break;
			}
			else{
				int g=-100;
				rep(r,60) if(((x-sum)>>r)&1) g=r;
				if(g+(j-i)>=60) continue;

				ll t=(x-sum)<<(j-i);
				if(mn>=t){
					num[i].pb(mn);
					val[i].pb(j);
					mn=t-1;
				}
			}
		}
		if(mn>=0){
			num[i].pb(mn);
			val[i].pb(60);
		}
	}
	rep(i,60) {
		reverse(all(num[i]));
		reverse(all(val[i]));
	}
	mp[0][0]=1;
	rep(i,60){
		auto& now=mp[i];
		auto& nxt=mp[(i+1)];
		for(auto g:now){
			ll t=g.fs;
			t+=a[i];
			int r=val[i][lower_bound(all(num[i]),t)-num[i].begin()];
			mp[r][t>>(r-i)+csum[i][r]]+=g.sc;
			t-=x;
			if(t>=0){
				r=val[i][lower_bound(all(num[i]),t)-num[i].begin()];
				mp[r][t>>(r-i)+csum[i][r]]+=g.sc;
			}
		}
	}

	ll ans=0;
	for(auto g:mp[60]){
		ans+=g.sc;
	}
	return ans;
}

Compilation message

biscuits.cpp: In function 'long long int count_tastiness(long long int, std::vector<long long int>)':
biscuits.cpp:12:28: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   12 | #define rng(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
      |                            ^
biscuits.cpp:26:2: note: in expansion of macro 'rng'
   26 |  rng(i,k,60) a[i]=0;
      |  ^~~
biscuits.cpp:12:28: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   12 | #define rng(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
      |                            ^
biscuits.cpp:13:18: note: in expansion of macro 'rng'
   13 | #define rep(i,n) rng((i),(0),(n))
      |                  ^~~
biscuits.cpp:33:2: note: in expansion of macro 'rep'
   33 |  rep(i,60){
      |  ^~~
biscuits.cpp:12:28: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
   12 | #define rng(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
      |                            ^
biscuits.cpp:35:3: note: in expansion of macro 'rng'
   35 |   rng(j,i+1,60){
      |   ^~~
biscuits.cpp:12:28: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   12 | #define rng(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
      |                            ^
biscuits.cpp:13:18: note: in expansion of macro 'rng'
   13 | #define rep(i,n) rng((i),(0),(n))
      |                  ^~~
biscuits.cpp:42:2: note: in expansion of macro 'rep'
   42 |  rep(i,60){
      |  ^~~
biscuits.cpp:12:28: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
   12 | #define rng(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
      |                            ^
biscuits.cpp:44:3: note: in expansion of macro 'rng'
   44 |   rng(j,i+1,60){
      |   ^~~
biscuits.cpp:12:28: warning: unnecessary parentheses in declaration of 'r' [-Wparentheses]
   12 | #define rng(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
      |                            ^
biscuits.cpp:13:18: note: in expansion of macro 'rng'
   13 | #define rep(i,n) rng((i),(0),(n))
      |                  ^~~
biscuits.cpp:55:5: note: in expansion of macro 'rep'
   55 |     rep(r,60) if(((x-sum)>>r)&1) g=r;
      |     ^~~
biscuits.cpp:12:28: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   12 | #define rng(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
      |                            ^
biscuits.cpp:13:18: note: in expansion of macro 'rng'
   13 | #define rep(i,n) rng((i),(0),(n))
      |                  ^~~
biscuits.cpp:71:2: note: in expansion of macro 'rep'
   71 |  rep(i,60) {
      |  ^~~
biscuits.cpp:12:28: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   12 | #define rng(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
      |                            ^
biscuits.cpp:13:18: note: in expansion of macro 'rng'
   13 | #define rep(i,n) rng((i),(0),(n))
      |                  ^~~
biscuits.cpp:76:2: note: in expansion of macro 'rep'
   76 |  rep(i,60){
      |  ^~~
biscuits.cpp:83:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   83 |    mp[r][t>>(r-i)+csum[i][r]]+=g.sc;
biscuits.cpp:87:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   87 |     mp[r][t>>(r-i)+csum[i][r]]+=g.sc;
biscuits.cpp:78:9: warning: unused variable 'nxt' [-Wunused-variable]
   78 |   auto& nxt=mp[(i+1)];
      |         ^~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 364 KB Output is correct
2 Correct 2 ms 364 KB Output is correct
3 Correct 2 ms 364 KB Output is correct
4 Correct 2 ms 364 KB Output is correct
5 Correct 2 ms 364 KB Output is correct
6 Correct 2 ms 364 KB Output is correct
7 Correct 2 ms 364 KB Output is correct
8 Correct 2 ms 364 KB Output is correct
9 Correct 2 ms 364 KB Output is correct
10 Correct 2 ms 364 KB Output is correct
11 Correct 3 ms 384 KB Output is correct
12 Incorrect 2 ms 364 KB Output isn't correct
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 2 ms 364 KB Output is correct
4 Correct 2 ms 364 KB Output is correct
5 Correct 2 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 2 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 65 ms 14444 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1087 ms 10060 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 364 KB Output is correct
2 Correct 2 ms 364 KB Output is correct
3 Correct 2 ms 364 KB Output is correct
4 Correct 2 ms 364 KB Output is correct
5 Correct 2 ms 364 KB Output is correct
6 Correct 2 ms 364 KB Output is correct
7 Correct 2 ms 364 KB Output is correct
8 Correct 2 ms 364 KB Output is correct
9 Correct 2 ms 364 KB Output is correct
10 Correct 2 ms 364 KB Output is correct
11 Correct 3 ms 384 KB Output is correct
12 Incorrect 2 ms 364 KB Output isn't correct
13 Halted 0 ms 0 KB -