Submission #378246

# Submission time Handle Problem Language Result Execution time Memory
378246 2021-03-16T10:25:50 Z Thistle Packing Biscuits (IOI20_biscuits) C++14
0 / 100
1000 ms 296572 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,0));
	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]));
	}
	queue<ll>q[60];
	q[0].push(0);
	ll ans=0;
	rep(i,60){
		while(!q[i].empty()){
			ll t=q[i].front()+a[i];q[i].pop();
			int r=val[i][lower_bound(all(num[i]),t)-num[i].begin()];
			if(r==60) ans++;
			else {
				q[r].push(t>>(r-i)+csum[i][r]);
			}
			if(t<x) continue;
			t-=x;
			r=val[i][lower_bound(all(num[i]),t)-num[i].begin()];
			if(r==60) ans++;
			else {
				q[r].push(t>>(r-i)+csum[i][r]);
			}
		}
	}
	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:78:2: note: in expansion of macro 'rep'
   78 |  rep(i,60){
      |  ^~~
biscuits.cpp:84:23: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   84 |     q[r].push(t>>(r-i)+csum[i][r]);
biscuits.cpp:91:23: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   91 |     q[r].push(t>>(r-i)+csum[i][r]);
# Verdict Execution time Memory Grader output
1 Correct 5 ms 748 KB Output is correct
2 Correct 3 ms 364 KB Output is correct
3 Correct 2 ms 364 KB Output is correct
4 Correct 6 ms 492 KB Output is correct
5 Correct 3 ms 364 KB Output is correct
6 Correct 14 ms 748 KB Output is correct
7 Correct 3 ms 364 KB Output is correct
8 Correct 11 ms 748 KB Output is correct
9 Correct 3 ms 492 KB Output is correct
10 Correct 2 ms 364 KB Output is correct
11 Correct 2 ms 364 KB Output is correct
12 Incorrect 5 ms 492 KB Output isn't correct
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 748 KB Output is correct
2 Execution timed out 1105 ms 282500 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1123 ms 296572 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1096 ms 1172 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 748 KB Output is correct
2 Correct 3 ms 364 KB Output is correct
3 Correct 2 ms 364 KB Output is correct
4 Correct 6 ms 492 KB Output is correct
5 Correct 3 ms 364 KB Output is correct
6 Correct 14 ms 748 KB Output is correct
7 Correct 3 ms 364 KB Output is correct
8 Correct 11 ms 748 KB Output is correct
9 Correct 3 ms 492 KB Output is correct
10 Correct 2 ms 364 KB Output is correct
11 Correct 2 ms 364 KB Output is correct
12 Incorrect 5 ms 492 KB Output isn't correct
13 Halted 0 ms 0 KB -