Submission #1048281

# Submission time Handle Problem Language Result Execution time Memory
1048281 2024-08-08T06:21:52 Z Gromp15 The Big Prize (IOI17_prize) C++17
90 / 100
37 ms 8280 KB
#include "prize.h"
#include <bits/stdc++.h>
#define ar array
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
using namespace std;

const int N = 500;

int find_best(int n) {
	map<int, vector<int>> mp;
	auto _ask = [&](int x) {
		if (mp.count(x)) return mp[x];
		auto res = ask(x);
		return mp[x] = res;
	};
	int mx = 0;
	for (int i = 0; i < min(n, N); i++) {
		auto res = _ask(i);
		mx = max(mx, res[0] + res[1]);
		if (res[0] + res[1] == 0) return i;
	}
	int ANS = -1;
	auto solve = [&](auto&& s, vector<int> ask, int ml, int mr) -> void {
		if (ml > mr || ask.empty()) return;
		int want = (ml + mr) / 2;
		int tl = 0, tr = sz(ask) - 1, ans = -1;
		/*
		cerr << "CUR ML MR WANT " << ml << " " << mr << " " << want << '\n';
		for (int x : ask) cerr << x << " ";
		cerr << '\n';
		*/
		while (tl <= tr) {
			int mid = (tl + tr) / 2;
			auto res = _ask(ask[mid]);
			//cerr << "ASK " << ask[mid] << " " << res[0] << " " << res[1] << endl;
			if (res[0] + res[1] == 0) {
				ANS = ask[mid]; return;
			}
			if (res[0] + res[1] < mx) {
				ask.erase(ask.begin() + mid);
				tr--; continue;
			}
			else {
				if (res[0] >= want) ans = mid, tr = mid - 1;
				else tl = mid + 1;
			}
		}
		/*
		cerr << "DONE " << ans << endl;
		for (int x : ask) cerr << x << " ";
		cerr << '\n';
		*/
		if (!~ans) return;
		auto res = _ask(ask[ans]);
		if (res[0] + res[1] == 0) {
			ANS = ask[ans]; return;
		}
		if (ans - 2 >= 0 && !~ANS) {
			s(s, vector<int>(ask.begin(), ask.begin() + ans - 1), ml, want - 1);
		}
		if (ans + 1 < sz(ask) && !~ANS) {
			s(s, vector<int>(ask.begin() + ans + 1, ask.end()), want + 1, mr);
		}
	};
	vector<int> idx(n);
	iota(all(idx), 0);
	solve(solve, idx, 1, mx);
	return ANS;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1880 KB Output is correct
2 Correct 3 ms 2220 KB Output is correct
3 Correct 3 ms 2020 KB Output is correct
4 Correct 3 ms 1968 KB Output is correct
5 Correct 3 ms 1964 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 3 ms 2016 KB Output is correct
8 Correct 3 ms 2028 KB Output is correct
9 Correct 3 ms 2028 KB Output is correct
10 Correct 3 ms 2008 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1984 KB Output is correct
2 Correct 3 ms 1880 KB Output is correct
3 Correct 4 ms 1968 KB Output is correct
4 Correct 3 ms 1968 KB Output is correct
5 Correct 4 ms 1964 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 3 ms 1968 KB Output is correct
8 Correct 3 ms 1880 KB Output is correct
9 Correct 3 ms 1996 KB Output is correct
10 Correct 4 ms 1980 KB Output is correct
11 Correct 4 ms 2800 KB Output is correct
12 Correct 3 ms 2548 KB Output is correct
13 Correct 6 ms 2908 KB Output is correct
14 Correct 4 ms 696 KB Output is correct
15 Correct 7 ms 3108 KB Output is correct
16 Correct 23 ms 3608 KB Output is correct
17 Correct 2 ms 448 KB Output is correct
18 Partially correct 26 ms 3436 KB Partially correct - number of queries: 5776
19 Correct 3 ms 344 KB Output is correct
20 Correct 8 ms 1748 KB Output is correct
21 Correct 11 ms 2924 KB Output is correct
22 Correct 4 ms 2904 KB Output is correct
23 Correct 4 ms 2392 KB Output is correct
24 Correct 5 ms 2392 KB Output is correct
25 Correct 15 ms 3216 KB Output is correct
26 Correct 14 ms 3168 KB Output is correct
27 Correct 3 ms 1880 KB Output is correct
28 Partially correct 22 ms 3340 KB Partially correct - number of queries: 5498
29 Correct 14 ms 3160 KB Output is correct
30 Partially correct 24 ms 3548 KB Partially correct - number of queries: 5686
31 Correct 2 ms 344 KB Output is correct
32 Correct 4 ms 2908 KB Output is correct
33 Correct 0 ms 344 KB Output is correct
34 Correct 11 ms 2828 KB Output is correct
35 Correct 4 ms 2904 KB Output is correct
36 Correct 8 ms 2768 KB Output is correct
37 Correct 4 ms 3104 KB Output is correct
38 Correct 3 ms 2392 KB Output is correct
39 Correct 17 ms 3196 KB Output is correct
40 Partially correct 37 ms 3104 KB Partially correct - number of queries: 5075
41 Correct 12 ms 3132 KB Output is correct
42 Correct 11 ms 3164 KB Output is correct
43 Correct 14 ms 3160 KB Output is correct
44 Correct 15 ms 3220 KB Output is correct
45 Correct 11 ms 2904 KB Output is correct
46 Correct 2 ms 344 KB Output is correct
47 Correct 12 ms 2988 KB Output is correct
48 Correct 25 ms 3332 KB Output is correct
49 Correct 7 ms 2904 KB Output is correct
50 Partially correct 30 ms 3568 KB Partially correct - number of queries: 5750
51 Correct 17 ms 3092 KB Output is correct
52 Correct 4 ms 2904 KB Output is correct
53 Correct 4 ms 2892 KB Output is correct
54 Correct 14 ms 3056 KB Output is correct
55 Correct 2 ms 344 KB Output is correct
56 Partially correct 37 ms 3420 KB Partially correct - number of queries: 5793
57 Correct 16 ms 3080 KB Output is correct
58 Correct 20 ms 3208 KB Output is correct
59 Correct 24 ms 3340 KB Output is correct
60 Correct 13 ms 3308 KB Output is correct
61 Correct 4 ms 2892 KB Output is correct
62 Correct 3 ms 2392 KB Output is correct
63 Correct 3 ms 2892 KB Output is correct
64 Correct 4 ms 2648 KB Output is correct
65 Correct 4 ms 3540 KB Output is correct
66 Correct 10 ms 1964 KB Output is correct
67 Correct 3 ms 1880 KB Output is correct
68 Correct 3 ms 600 KB Output is correct
69 Correct 6 ms 2100 KB Output is correct
70 Correct 3 ms 2088 KB Output is correct
71 Partially correct 27 ms 3244 KB Partially correct - number of queries: 5884
72 Correct 5 ms 3084 KB Output is correct
73 Partially correct 23 ms 3268 KB Partially correct - number of queries: 5829
74 Partially correct 25 ms 3368 KB Partially correct - number of queries: 5888
75 Correct 4 ms 2760 KB Output is correct
76 Partially correct 23 ms 3204 KB Partially correct - number of queries: 5150
77 Partially correct 22 ms 3276 KB Partially correct - number of queries: 6002
78 Correct 4 ms 2904 KB Output is correct
79 Correct 14 ms 3084 KB Output is correct
80 Partially correct 29 ms 3580 KB Partially correct - number of queries: 6015
81 Partially correct 25 ms 3312 KB Partially correct - number of queries: 6003
82 Partially correct 28 ms 3444 KB Partially correct - number of queries: 5983
83 Correct 4 ms 3140 KB Output is correct
84 Partially correct 24 ms 3384 KB Partially correct - number of queries: 5105
85 Partially correct 26 ms 3396 KB Partially correct - number of queries: 6026
86 Correct 13 ms 8280 KB Output is correct
87 Correct 5 ms 5976 KB Output is correct
88 Correct 12 ms 8280 KB Output is correct
89 Correct 12 ms 8280 KB Output is correct
90 Correct 4 ms 4444 KB Output is correct
91 Correct 9 ms 8280 KB Output is correct
92 Correct 14 ms 8280 KB Output is correct
93 Correct 13 ms 6412 KB Output is correct
94 Correct 15 ms 6380 KB Output is correct
95 Correct 12 ms 6044 KB Output is correct
96 Correct 13 ms 6232 KB Output is correct
97 Correct 11 ms 8280 KB Output is correct