Submission #1048283

# Submission time Handle Problem Language Result Execution time Memory
1048283 2024-08-08T06:23:12 Z Gromp15 The Big Prize (IOI17_prize) C++17
90 / 100
38 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 - N);
	iota(all(idx), N);
	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 1880 KB Output is correct
3 Correct 3 ms 1880 KB Output is correct
4 Correct 4 ms 1880 KB Output is correct
5 Correct 3 ms 1880 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 3 ms 1984 KB Output is correct
8 Correct 2 ms 2000 KB Output is correct
9 Correct 3 ms 1880 KB Output is correct
10 Correct 4 ms 1880 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1880 KB Output is correct
2 Correct 3 ms 1876 KB Output is correct
3 Correct 3 ms 1996 KB Output is correct
4 Correct 6 ms 1960 KB Output is correct
5 Correct 3 ms 1880 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 5 ms 1880 KB Output is correct
8 Correct 3 ms 1880 KB Output is correct
9 Correct 3 ms 1956 KB Output is correct
10 Correct 3 ms 1880 KB Output is correct
11 Correct 4 ms 2724 KB Output is correct
12 Correct 6 ms 2648 KB Output is correct
13 Correct 7 ms 2920 KB Output is correct
14 Correct 3 ms 600 KB Output is correct
15 Correct 7 ms 2824 KB Output is correct
16 Correct 22 ms 3316 KB Output is correct
17 Correct 2 ms 344 KB Output is correct
18 Partially correct 25 ms 3336 KB Partially correct - number of queries: 5788
19 Correct 3 ms 344 KB Output is correct
20 Correct 10 ms 1860 KB Output is correct
21 Correct 12 ms 2992 KB Output is correct
22 Correct 6 ms 2796 KB Output is correct
23 Correct 4 ms 2568 KB Output is correct
24 Correct 3 ms 2516 KB Output is correct
25 Correct 18 ms 3120 KB Output is correct
26 Correct 17 ms 3156 KB Output is correct
27 Correct 3 ms 1880 KB Output is correct
28 Partially correct 28 ms 3172 KB Partially correct - number of queries: 5492
29 Correct 19 ms 3488 KB Output is correct
30 Partially correct 27 ms 3368 KB Partially correct - number of queries: 5674
31 Correct 2 ms 344 KB Output is correct
32 Correct 6 ms 2896 KB Output is correct
33 Correct 0 ms 344 KB Output is correct
34 Correct 11 ms 3016 KB Output is correct
35 Correct 6 ms 2848 KB Output is correct
36 Correct 9 ms 2908 KB Output is correct
37 Correct 5 ms 3220 KB Output is correct
38 Correct 5 ms 2520 KB Output is correct
39 Correct 14 ms 3016 KB Output is correct
40 Partially correct 28 ms 3592 KB Partially correct - number of queries: 5079
41 Correct 26 ms 3116 KB Output is correct
42 Correct 21 ms 3068 KB Output is correct
43 Correct 19 ms 3216 KB Output is correct
44 Correct 13 ms 3116 KB Output is correct
45 Correct 10 ms 2964 KB Output is correct
46 Correct 3 ms 344 KB Output is correct
47 Correct 13 ms 2992 KB Output is correct
48 Correct 15 ms 3136 KB Output is correct
49 Correct 7 ms 2904 KB Output is correct
50 Partially correct 27 ms 3180 KB Partially correct - number of queries: 5770
51 Correct 9 ms 2972 KB Output is correct
52 Correct 4 ms 2648 KB Output is correct
53 Correct 5 ms 2976 KB Output is correct
54 Correct 16 ms 3224 KB Output is correct
55 Correct 2 ms 344 KB Output is correct
56 Partially correct 26 ms 3324 KB Partially correct - number of queries: 5821
57 Correct 15 ms 3144 KB Output is correct
58 Correct 17 ms 3440 KB Output is correct
59 Correct 16 ms 3076 KB Output is correct
60 Correct 19 ms 3056 KB Output is correct
61 Correct 4 ms 2976 KB Output is correct
62 Correct 3 ms 2392 KB Output is correct
63 Correct 4 ms 2976 KB Output is correct
64 Correct 3 ms 2648 KB Output is correct
65 Correct 3 ms 3544 KB Output is correct
66 Correct 5 ms 1880 KB Output is correct
67 Correct 3 ms 2136 KB Output is correct
68 Correct 3 ms 708 KB Output is correct
69 Correct 3 ms 1880 KB Output is correct
70 Correct 5 ms 1880 KB Output is correct
71 Partially correct 38 ms 3496 KB Partially correct - number of queries: 5752
72 Correct 7 ms 2904 KB Output is correct
73 Partially correct 24 ms 3416 KB Partially correct - number of queries: 5812
74 Partially correct 33 ms 3400 KB Partially correct - number of queries: 5745
75 Correct 3 ms 2828 KB Output is correct
76 Partially correct 32 ms 3444 KB Partially correct - number of queries: 5025
77 Partially correct 23 ms 3236 KB Partially correct - number of queries: 6044
78 Correct 9 ms 2904 KB Output is correct
79 Correct 15 ms 3400 KB Output is correct
80 Partially correct 24 ms 3332 KB Partially correct - number of queries: 6036
81 Partially correct 24 ms 3332 KB Partially correct - number of queries: 6038
82 Partially correct 20 ms 3408 KB Partially correct - number of queries: 5984
83 Correct 3 ms 2828 KB Output is correct
84 Partially correct 22 ms 3340 KB Partially correct - number of queries: 5128
85 Partially correct 36 ms 3648 KB Partially correct - number of queries: 5995
86 Correct 7 ms 8280 KB Output is correct
87 Correct 5 ms 5976 KB Output is correct
88 Correct 5 ms 8280 KB Output is correct
89 Correct 6 ms 8280 KB Output is correct
90 Correct 4 ms 4184 KB Output is correct
91 Correct 6 ms 8280 KB Output is correct
92 Correct 7 ms 8280 KB Output is correct
93 Correct 7 ms 6924 KB Output is correct
94 Correct 6 ms 6800 KB Output is correct
95 Correct 7 ms 6240 KB Output is correct
96 Correct 6 ms 6232 KB Output is correct
97 Correct 6 ms 8280 KB Output is correct