Submission #416197

# Submission time Handle Problem Language Result Execution time Memory
416197 2021-06-02T07:05:52 Z InternetPerson10 The Big Prize (IOI17_prize) C++17
97.62 / 100
56 ms 1864 KB
#include "prize.h"
#include <bits/stdc++.h>

using namespace std;

int le[200001], ri[200001];
map<int, int> ge;
vector<int> vec;

int bad, unfound = 0;

vector<int> asksk(int n) {
	if(le[n] >= 0) {
		vector<int> v;
		v.push_back(le[n]);
		v.push_back(ri[n]);
		return v;
	}
	else return ask(n);
}

int rec(int l, int r, int u) {
	// cout << l << ' ' << r << ' ' << u << "\n";
	int k = u;
	if(u == 0) return 0;
	int mid = (l+r)/2;
	int l_r, r_l; l_r = r_l = mid;
	while(l_r > l && u >= 0) {
		auto v = asksk(l_r);
		le[l_r] = v[0]; ri[l_r] = v[1];
		if(le[l_r] + ri[l_r] != bad) u--;
		else {
			u -= rec(l, l_r, le[l_r] - le[l]);
			break;
		}
		l_r--;
	}
	while(r_l < r && u >= 0) {
		auto v = asksk(r_l);
		le[r_l] = v[0]; ri[r_l] = v[1];
		if(le[r_l] + ri[r_l] != bad && r_l != mid) u--;
		else if(le[r_l] + ri[r_l] == bad) {
			u -= rec(r_l, r, k - le[r_l] + le[l]);
			break;
		}
		r_l++;
	}
	return k;
}

int find_best(int n) {
	for(int i = 0; i < n; i++) le[i] = ri[i] = -1;
	int k = 0;
	while(7 * k * k / 8 < n) {
		k++;
		if(k == n) break;
	}
	if(n <= 5000) k = n;
	for(int i = 0; i < k; i++) {
		auto v = asksk(i);
		le[i] = v[0]; ri[i] = v[1];
		if(ge.find(le[i] + ri[i]) == ge.end()) ge[le[i] + ri[i]] = 1;
		else ge[le[i] + ri[i]]++;
	}
	for(auto p : ge) {
		vec.push_back(p.first);
	}
	bad = vec[vec.size() - 1]; // sum of lowest prize
	unfound = bad;
	int st = 0;
	int buffer = 0;
	for(int i = 0; i < k; i++) {
		if(le[i] + ri[i] != bad) {
			buffer++;
		}
		else {
			unfound -= buffer; buffer = 0;
			st = i;
		}
	}
	rec(st, n, unfound);
	for(int i = 0; i < n; i++) {
		if(le[i] + ri[i] == 0) return i;
	}
	rec(0, n, bad);
	for(int i = 0; i < n; i++) {
		if(le[i] + ri[i] == 0) return i;
	}
	return bad+200000;
}
 
# Verdict Execution time Memory Grader output
1 Correct 6 ms 1728 KB Output is correct
2 Correct 6 ms 1824 KB Output is correct
3 Correct 4 ms 1864 KB Output is correct
4 Correct 3 ms 1832 KB Output is correct
5 Correct 4 ms 1816 KB Output is correct
6 Correct 6 ms 1736 KB Output is correct
7 Correct 6 ms 1824 KB Output is correct
8 Correct 3 ms 1864 KB Output is correct
9 Correct 6 ms 1736 KB Output is correct
10 Correct 5 ms 1736 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 1736 KB Output is correct
2 Correct 4 ms 1816 KB Output is correct
3 Correct 3 ms 1824 KB Output is correct
4 Correct 5 ms 1824 KB Output is correct
5 Correct 5 ms 1820 KB Output is correct
6 Correct 3 ms 1820 KB Output is correct
7 Correct 5 ms 1736 KB Output is correct
8 Correct 3 ms 1820 KB Output is correct
9 Correct 5 ms 1736 KB Output is correct
10 Correct 6 ms 1736 KB Output is correct
11 Correct 10 ms 1736 KB Output is correct
12 Correct 5 ms 1820 KB Output is correct
13 Correct 14 ms 1804 KB Output is correct
14 Correct 14 ms 456 KB Output is correct
15 Correct 39 ms 1728 KB Output is correct
16 Partially correct 54 ms 1828 KB Partially correct - number of queries: 5075
17 Partially correct 47 ms 1736 KB Partially correct - number of queries: 5090
18 Partially correct 37 ms 1736 KB Partially correct - number of queries: 5093
19 Correct 50 ms 1816 KB Output is correct
20 Correct 36 ms 1060 KB Output is correct
21 Partially correct 51 ms 1724 KB Partially correct - number of queries: 5051
22 Correct 34 ms 1832 KB Output is correct
23 Correct 6 ms 1832 KB Output is correct
24 Correct 10 ms 1824 KB Output is correct
25 Correct 51 ms 1804 KB Output is correct
26 Correct 44 ms 1804 KB Output is correct
27 Correct 5 ms 1820 KB Output is correct
28 Correct 45 ms 1736 KB Output is correct
29 Correct 46 ms 1736 KB Output is correct
30 Partially correct 48 ms 1816 KB Partially correct - number of queries: 5074
31 Partially correct 25 ms 1856 KB Partially correct - number of queries: 5070
32 Correct 6 ms 1820 KB Output is correct
33 Correct 2 ms 200 KB Output is correct
34 Partially correct 51 ms 1820 KB Partially correct - number of queries: 5058
35 Correct 7 ms 1816 KB Output is correct
36 Partially correct 24 ms 1824 KB Partially correct - number of queries: 5057
37 Correct 10 ms 1728 KB Output is correct
38 Correct 8 ms 1736 KB Output is correct
39 Partially correct 24 ms 1856 KB Partially correct - number of queries: 5055
40 Correct 42 ms 1816 KB Output is correct
41 Partially correct 42 ms 1828 KB Partially correct - number of queries: 5092
42 Partially correct 45 ms 1824 KB Partially correct - number of queries: 5092
43 Correct 52 ms 1736 KB Output is correct
44 Partially correct 46 ms 1804 KB Partially correct - number of queries: 5063
45 Correct 22 ms 1820 KB Output is correct
46 Partially correct 24 ms 1816 KB Partially correct - number of queries: 5054
47 Correct 38 ms 1736 KB Output is correct
48 Partially correct 48 ms 1820 KB Partially correct - number of queries: 5079
49 Partially correct 47 ms 1736 KB Partially correct - number of queries: 5099
50 Partially correct 46 ms 1728 KB Partially correct - number of queries: 5056
51 Partially correct 24 ms 1820 KB Partially correct - number of queries: 5103
52 Partially correct 39 ms 1820 KB Partially correct - number of queries: 5086
53 Correct 5 ms 1736 KB Output is correct
54 Partially correct 50 ms 1832 KB Partially correct - number of queries: 5057
55 Partially correct 39 ms 1820 KB Partially correct - number of queries: 5092
56 Partially correct 28 ms 1736 KB Partially correct - number of queries: 5102
57 Partially correct 46 ms 1816 KB Partially correct - number of queries: 5036
58 Partially correct 46 ms 1824 KB Partially correct - number of queries: 5079
59 Partially correct 44 ms 1804 KB Partially correct - number of queries: 5091
60 Partially correct 39 ms 1728 KB Partially correct - number of queries: 5068
61 Correct 7 ms 1828 KB Output is correct
62 Correct 6 ms 1816 KB Output is correct
63 Correct 7 ms 1812 KB Output is correct
64 Correct 7 ms 1728 KB Output is correct
65 Correct 6 ms 1736 KB Output is correct
66 Correct 13 ms 1824 KB Output is correct
67 Correct 9 ms 1836 KB Output is correct
68 Correct 8 ms 1832 KB Output is correct
69 Correct 8 ms 1736 KB Output is correct
70 Correct 9 ms 1820 KB Output is correct
71 Partially correct 44 ms 1736 KB Partially correct - number of queries: 5238
72 Correct 10 ms 1736 KB Output is correct
73 Partially correct 26 ms 1736 KB Partially correct - number of queries: 5175
74 Partially correct 46 ms 1736 KB Partially correct - number of queries: 5202
75 Correct 7 ms 1736 KB Output is correct
76 Correct 43 ms 1736 KB Output is correct
77 Partially correct 56 ms 1736 KB Partially correct - number of queries: 5214
78 Correct 7 ms 1736 KB Output is correct
79 Correct 27 ms 1736 KB Output is correct
80 Partially correct 43 ms 1736 KB Partially correct - number of queries: 5217
81 Partially correct 45 ms 1736 KB Partially correct - number of queries: 5168
82 Partially correct 42 ms 1736 KB Partially correct - number of queries: 5178
83 Correct 9 ms 1736 KB Output is correct
84 Correct 38 ms 1736 KB Output is correct
85 Partially correct 44 ms 1736 KB Partially correct - number of queries: 5175
86 Correct 5 ms 1736 KB Output is correct
87 Correct 5 ms 1736 KB Output is correct
88 Correct 8 ms 1824 KB Output is correct
89 Correct 6 ms 1736 KB Output is correct
90 Correct 10 ms 1736 KB Output is correct
91 Correct 5 ms 1828 KB Output is correct
92 Correct 5 ms 1736 KB Output is correct
93 Correct 9 ms 1736 KB Output is correct
94 Correct 11 ms 1736 KB Output is correct
95 Correct 7 ms 1736 KB Output is correct
96 Correct 7 ms 1736 KB Output is correct
97 Correct 7 ms 1736 KB Output is correct