Submission #287979

# Submission time Handle Problem Language Result Execution time Memory
287979 2020-09-01T07:26:27 Z user202729 The Big Prize (IOI17_prize) C++17
100 / 100
64 ms 5352 KB
// moreflags=grader.cpp
// 11
// :(
#include "prize.h"
#if not LOCAL
#define NDEBUG
#endif
#include<vector>
#include<algorithm>
#include<cassert>

std::vector<std::vector<int>> result;

int find_best(int const n) {
	/*
	if(n<=5000){
		for(int i = 0; ; i++) {
			assert(i<n);
			std::vector<int> res = ask(i);
			if(res[0] + res[1] == 0)
				return i;
		}
	}
	assert(n>5000);
	*/
	
	result.clear(); result.resize(n);
	auto const ask=[&](int pos)->void{
		if(result[pos].empty())
			result[pos]=::ask(pos);
	};

	int maxTotal{};
	for(int index=0; index<473; ++index){
		auto const pos=n*index/473;
		ask(pos);
		maxTotal=std::max(maxTotal, result[pos][0]+result[pos][1]);
	}
	// so far 473 questions asked

	auto const isLollipop=[&](int pos){
		return result[pos][0]+result[pos][1]==maxTotal;
	};

	for(int index=0; index<473; ++index){
		auto left=n*index/473, right=n*(index+1)/473;
		assert(not result[left].empty());
		assert(right==n or not result[right].empty());
		while(left+1<right and not isLollipop(left)) ask(++left);
	}
	// 473+x questions asked, x non-lollipops found

	auto const process=[&](auto process, int left, int right, int countRight, int delta){
		// given delta non-lollipops in (left..right), ask them all in k*delta questions
		// with right-left<=2**k-1
		// countRight=number of non-lollipops in (left..)
		if(delta==0) return;
		assert(delta>0);
		assert(countRight>=delta);
		assert(left<right);

		auto const middle=(left+right)>>1;
		ask(middle);
		int pos=middle;
		while(not isLollipop(pos)){
			++pos;
			if(pos==right) break;
			ask(pos);
		}
		auto const deltaMid=pos-middle;
		if(pos==right){
			for(int pos=middle; pos<right; ++pos) assert(not isLollipop(pos));
			process(process, left, middle, countRight, delta-deltaMid);
		}else{
			auto const countRight1=result[pos][1];
			auto const deltaLeft=countRight-countRight1-deltaMid;
			process(process, left, middle, countRight, deltaLeft);
			process(process, pos+1, right, result[pos][1], delta-deltaLeft-deltaMid);
		}
	};

	auto const cutCondition=[&](int pos){
		return pos==n or (not result[pos].empty() and isLollipop(pos));
	};
	for(int pos=0; pos<n; ++pos) if(cutCondition(pos)){
		int next=pos+1; while(not cutCondition(next)) ++next;
		int right=next;
		while(pos+1<right and not result[right-1].empty()){
			assert(not isLollipop(right-1));
			--right;
		}
		if(pos+1==right) continue;

		assert(std::all_of(result.begin()+pos+1, result.begin()+right, [&](auto const& it){
			return it.empty();}));
		for(int pos=right; pos<next; ++pos)
			assert(not isLollipop(pos));

		assert(isLollipop(pos)); assert(next==n or isLollipop(next));
		int const delta=result[pos][1]-(next==n ? 0: result[next][1]);
		process(process, pos+1, right, result[pos][1], delta-(next-right));
	}

	// all non-lollipops found
	for(int pos=0;; ++pos) if(not result[pos].empty() and result[pos][0]==0 and result[pos][1]==0)
		return pos;
}
# Verdict Execution time Memory Grader output
1 Correct 8 ms 5096 KB Output is correct
2 Correct 7 ms 5120 KB Output is correct
3 Correct 10 ms 4992 KB Output is correct
4 Correct 9 ms 4992 KB Output is correct
5 Correct 9 ms 4992 KB Output is correct
6 Correct 9 ms 4992 KB Output is correct
7 Correct 9 ms 4992 KB Output is correct
8 Correct 9 ms 4992 KB Output is correct
9 Correct 9 ms 4992 KB Output is correct
10 Correct 9 ms 5120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 4984 KB Output is correct
2 Correct 11 ms 4992 KB Output is correct
3 Correct 9 ms 4992 KB Output is correct
4 Correct 7 ms 5088 KB Output is correct
5 Correct 9 ms 4992 KB Output is correct
6 Correct 7 ms 5108 KB Output is correct
7 Correct 11 ms 4992 KB Output is correct
8 Correct 9 ms 4964 KB Output is correct
9 Correct 9 ms 4992 KB Output is correct
10 Correct 9 ms 5096 KB Output is correct
11 Correct 12 ms 4992 KB Output is correct
12 Correct 10 ms 4992 KB Output is correct
13 Correct 10 ms 4992 KB Output is correct
14 Correct 11 ms 896 KB Output is correct
15 Correct 40 ms 5240 KB Output is correct
16 Correct 28 ms 5236 KB Output is correct
17 Correct 41 ms 5096 KB Output is correct
18 Correct 40 ms 5112 KB Output is correct
19 Correct 40 ms 5112 KB Output is correct
20 Correct 28 ms 2808 KB Output is correct
21 Correct 46 ms 5120 KB Output is correct
22 Correct 36 ms 5112 KB Output is correct
23 Correct 7 ms 5116 KB Output is correct
24 Correct 12 ms 4992 KB Output is correct
25 Correct 38 ms 5112 KB Output is correct
26 Correct 40 ms 5240 KB Output is correct
27 Correct 9 ms 4984 KB Output is correct
28 Correct 24 ms 5212 KB Output is correct
29 Correct 22 ms 5176 KB Output is correct
30 Correct 60 ms 5240 KB Output is correct
31 Correct 55 ms 5352 KB Output is correct
32 Correct 15 ms 4992 KB Output is correct
33 Correct 1 ms 256 KB Output is correct
34 Correct 27 ms 5220 KB Output is correct
35 Correct 13 ms 4984 KB Output is correct
36 Correct 42 ms 5112 KB Output is correct
37 Correct 9 ms 5120 KB Output is correct
38 Correct 12 ms 4992 KB Output is correct
39 Correct 36 ms 5128 KB Output is correct
40 Correct 41 ms 5240 KB Output is correct
41 Correct 60 ms 5112 KB Output is correct
42 Correct 57 ms 5112 KB Output is correct
43 Correct 54 ms 5112 KB Output is correct
44 Correct 54 ms 5112 KB Output is correct
45 Correct 50 ms 5112 KB Output is correct
46 Correct 56 ms 5112 KB Output is correct
47 Correct 52 ms 5120 KB Output is correct
48 Correct 40 ms 5112 KB Output is correct
49 Correct 41 ms 5232 KB Output is correct
50 Correct 38 ms 5112 KB Output is correct
51 Correct 39 ms 5112 KB Output is correct
52 Correct 39 ms 5140 KB Output is correct
53 Correct 13 ms 4992 KB Output is correct
54 Correct 34 ms 5180 KB Output is correct
55 Correct 42 ms 5112 KB Output is correct
56 Correct 57 ms 5112 KB Output is correct
57 Correct 46 ms 5244 KB Output is correct
58 Correct 41 ms 5188 KB Output is correct
59 Correct 43 ms 5112 KB Output is correct
60 Correct 53 ms 5112 KB Output is correct
61 Correct 10 ms 4992 KB Output is correct
62 Correct 10 ms 4992 KB Output is correct
63 Correct 10 ms 4992 KB Output is correct
64 Correct 10 ms 4992 KB Output is correct
65 Correct 10 ms 4992 KB Output is correct
66 Correct 13 ms 4992 KB Output is correct
67 Correct 13 ms 4984 KB Output is correct
68 Correct 14 ms 5120 KB Output is correct
69 Correct 14 ms 4992 KB Output is correct
70 Correct 14 ms 4992 KB Output is correct
71 Correct 53 ms 5240 KB Output is correct
72 Correct 13 ms 5120 KB Output is correct
73 Correct 42 ms 5260 KB Output is correct
74 Correct 47 ms 5112 KB Output is correct
75 Correct 10 ms 4992 KB Output is correct
76 Correct 52 ms 5120 KB Output is correct
77 Correct 64 ms 5112 KB Output is correct
78 Correct 14 ms 4992 KB Output is correct
79 Correct 24 ms 5116 KB Output is correct
80 Correct 60 ms 5112 KB Output is correct
81 Correct 49 ms 5168 KB Output is correct
82 Correct 58 ms 5112 KB Output is correct
83 Correct 9 ms 4992 KB Output is correct
84 Correct 45 ms 5112 KB Output is correct
85 Correct 60 ms 5112 KB Output is correct
86 Correct 14 ms 4992 KB Output is correct
87 Correct 8 ms 4992 KB Output is correct
88 Correct 15 ms 4992 KB Output is correct
89 Correct 16 ms 4992 KB Output is correct
90 Correct 11 ms 4972 KB Output is correct
91 Correct 11 ms 5104 KB Output is correct
92 Correct 15 ms 5100 KB Output is correct
93 Correct 13 ms 5136 KB Output is correct
94 Correct 12 ms 5112 KB Output is correct
95 Correct 14 ms 5120 KB Output is correct
96 Correct 17 ms 4992 KB Output is correct
97 Correct 15 ms 5120 KB Output is correct