Submission #286859

# Submission time Handle Problem Language Result Execution time Memory
286859 2020-08-31T05:48:56 Z egekabas The Big Prize (IOI17_prize) C++14
97.95 / 100
62 ms 5248 KB
#include "prize.h"
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pull;
typedef pair<int, int> pii;
typedef pair<ld, ld> pld;
	
int ans = -1;
int curval;
vector<int> dp[200009];
vector<int> q(int x){
	if(dp[x].size())
		return dp[x];
	return dp[x] = ask(x);
}
void binsearch(int l, int r, int lval, int rval){
	int cnt = curval-lval-rval;
	if(cnt == 0 || l > r || ans != -1)
		return;
	int mid = (l+r)/2;
	for(int i = 0; (mid-i) >= l || (mid+i) <= r; ++i){
		int extra = 0;
		if(ans != -1 || cnt <= 0) return;
		if((mid-i) >= l){
			int id = (mid-i);
			vector<int> res = q(id);
			if(ans != -1) return;
			if(res[0]+res[1] == curval){
				binsearch(l, id-1, lval, res[1]);
				binsearch(max(mid+i,mid+1), r, res[0]+extra, rval);
				return;
			}
			else if(res[0]+res[1] == 0){
				ans = id;
				return;
			}
			else{
				--cnt;
				++extra;
			}
		}
		if(ans != -1 || cnt <= 0) return;
		if(i != 0 && (mid+i) <= r){
			int id = mid+i;
			vector<int> res = q(id);
			if(ans != -1) return;
			if(res[0]+res[1] == curval){
				binsearch(l, mid-i-1, lval, res[1]+extra);
				binsearch(id+1, r, res[0], rval);
				return;
			}
			else if(res[0]+res[1] == 0){
				ans = id;
				return;
			}
			else{
				--cnt;
				++extra;
			}
		}
	}
}
int find_best(int n) {
	srand(time(NULL));
	int times = 470;
	while(times--){
		vector<int> res = q(rand()%n);
		curval = max(curval, res[0]+res[1]);
	}
	binsearch(0, n-1, 0, 0);
	assert(ans != -1 && q(ans)[0] == 0 && q(ans)[1] == 0);
	return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 6 ms 5076 KB Output is correct
2 Correct 9 ms 5072 KB Output is correct
3 Correct 10 ms 4992 KB Output is correct
4 Correct 6 ms 5072 KB Output is correct
5 Correct 10 ms 4992 KB Output is correct
6 Correct 9 ms 4992 KB Output is correct
7 Correct 8 ms 4992 KB Output is correct
8 Correct 8 ms 4992 KB Output is correct
9 Correct 10 ms 4992 KB Output is correct
10 Correct 13 ms 4992 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 4992 KB Output is correct
2 Correct 9 ms 5056 KB Output is correct
3 Correct 9 ms 4992 KB Output is correct
4 Correct 9 ms 4992 KB Output is correct
5 Correct 11 ms 4992 KB Output is correct
6 Correct 10 ms 4992 KB Output is correct
7 Correct 7 ms 5076 KB Output is correct
8 Correct 8 ms 4992 KB Output is correct
9 Correct 8 ms 5068 KB Output is correct
10 Correct 10 ms 4992 KB Output is correct
11 Correct 10 ms 4992 KB Output is correct
12 Correct 10 ms 4992 KB Output is correct
13 Correct 11 ms 4992 KB Output is correct
14 Correct 11 ms 4992 KB Output is correct
15 Correct 13 ms 4992 KB Output is correct
16 Correct 48 ms 5240 KB Output is correct
17 Correct 11 ms 4992 KB Output is correct
18 Correct 47 ms 5112 KB Output is correct
19 Correct 10 ms 4992 KB Output is correct
20 Correct 20 ms 4992 KB Output is correct
21 Correct 29 ms 5112 KB Output is correct
22 Correct 12 ms 4992 KB Output is correct
23 Correct 9 ms 4992 KB Output is correct
24 Correct 8 ms 4992 KB Output is correct
25 Correct 27 ms 5120 KB Output is correct
26 Correct 26 ms 5244 KB Output is correct
27 Correct 9 ms 4992 KB Output is correct
28 Correct 50 ms 5112 KB Output is correct
29 Correct 35 ms 5112 KB Output is correct
30 Correct 44 ms 5112 KB Output is correct
31 Correct 8 ms 4992 KB Output is correct
32 Correct 11 ms 4992 KB Output is correct
33 Correct 4 ms 4992 KB Output is correct
34 Correct 21 ms 5112 KB Output is correct
35 Correct 9 ms 4992 KB Output is correct
36 Correct 11 ms 5156 KB Output is correct
37 Correct 11 ms 5112 KB Output is correct
38 Correct 8 ms 4992 KB Output is correct
39 Correct 28 ms 5120 KB Output is correct
40 Correct 54 ms 5112 KB Output is correct
41 Correct 37 ms 5112 KB Output is correct
42 Correct 21 ms 5168 KB Output is correct
43 Correct 30 ms 5140 KB Output is correct
44 Correct 29 ms 5112 KB Output is correct
45 Correct 24 ms 5120 KB Output is correct
46 Correct 10 ms 4992 KB Output is correct
47 Correct 18 ms 5160 KB Output is correct
48 Correct 44 ms 5112 KB Output is correct
49 Correct 8 ms 5144 KB Output is correct
50 Correct 46 ms 5240 KB Output is correct
51 Correct 25 ms 5112 KB Output is correct
52 Correct 10 ms 4992 KB Output is correct
53 Correct 9 ms 4992 KB Output is correct
54 Correct 23 ms 5112 KB Output is correct
55 Correct 9 ms 4992 KB Output is correct
56 Correct 46 ms 5112 KB Output is correct
57 Correct 37 ms 5240 KB Output is correct
58 Correct 46 ms 5060 KB Output is correct
59 Correct 24 ms 5200 KB Output is correct
60 Correct 36 ms 5112 KB Output is correct
61 Correct 11 ms 4992 KB Output is correct
62 Correct 8 ms 4992 KB Output is correct
63 Correct 7 ms 5092 KB Output is correct
64 Correct 8 ms 4992 KB Output is correct
65 Correct 10 ms 4992 KB Output is correct
66 Correct 14 ms 4992 KB Output is correct
67 Correct 8 ms 4992 KB Output is correct
68 Correct 11 ms 4992 KB Output is correct
69 Correct 15 ms 4992 KB Output is correct
70 Correct 10 ms 4992 KB Output is correct
71 Partially correct 54 ms 5112 KB Partially correct - number of queries: 5205
72 Correct 12 ms 4992 KB Output is correct
73 Partially correct 61 ms 5248 KB Partially correct - number of queries: 5144
74 Partially correct 62 ms 5248 KB Partially correct - number of queries: 5179
75 Correct 11 ms 4992 KB Output is correct
76 Correct 55 ms 5176 KB Output is correct
77 Correct 31 ms 5196 KB Output is correct
78 Correct 14 ms 4992 KB Output is correct
79 Correct 27 ms 5112 KB Output is correct
80 Correct 60 ms 5112 KB Output is correct
81 Correct 56 ms 5112 KB Output is correct
82 Correct 42 ms 5112 KB Output is correct
83 Correct 9 ms 4992 KB Output is correct
84 Correct 39 ms 5120 KB Output is correct
85 Correct 28 ms 5128 KB Output is correct
86 Correct 51 ms 5112 KB Output is correct
87 Correct 11 ms 4992 KB Output is correct
88 Correct 39 ms 5112 KB Output is correct
89 Correct 33 ms 5112 KB Output is correct
90 Correct 10 ms 4992 KB Output is correct
91 Correct 16 ms 5112 KB Output is correct
92 Correct 15 ms 5128 KB Output is correct
93 Correct 26 ms 5176 KB Output is correct
94 Correct 40 ms 5132 KB Output is correct
95 Correct 42 ms 5240 KB Output is correct
96 Correct 36 ms 5112 KB Output is correct
97 Correct 44 ms 5136 KB Output is correct