Submission #1048285

# Submission time Handle Problem Language Result Execution time Memory
1048285 2024-08-08T06:24:34 Z Gromp15 The Big Prize (IOI17_prize) C++17
91.3 / 100
34 ms 8656 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;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define rint(l, r) uniform_int_distribution<int>(l, r)(rng)

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 (rint(0, 1)) {
			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);
			}
		}
		else {
			if (ans + 1 < sz(ask) && !~ANS) {
				s(s, vector<int>(ask.begin() + ans + 1, ask.end()), want + 1, mr);
			}
			if (ans - 2 >= 0 && !~ANS) {
				s(s, vector<int>(ask.begin(), ask.begin() + ans - 1), ml, want - 1);
			}
		}
	};
	vector<int> idx(n - N);
	iota(all(idx), N);
	solve(solve, idx, 1, mx);
	return ANS;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1880 KB Output is correct
2 Correct 3 ms 1972 KB Output is correct
3 Correct 3 ms 1880 KB Output is correct
4 Correct 4 ms 2012 KB Output is correct
5 Correct 3 ms 1880 KB Output is correct
6 Correct 0 ms 428 KB Output is correct
7 Correct 3 ms 1996 KB Output is correct
8 Correct 2 ms 1880 KB Output is correct
9 Correct 3 ms 1880 KB Output is correct
10 Correct 3 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 1880 KB Output is correct
3 Correct 4 ms 2260 KB Output is correct
4 Correct 2 ms 1880 KB Output is correct
5 Correct 4 ms 1880 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 3 ms 1880 KB Output is correct
8 Correct 3 ms 2136 KB Output is correct
9 Correct 3 ms 1880 KB Output is correct
10 Correct 3 ms 2012 KB Output is correct
11 Correct 5 ms 2928 KB Output is correct
12 Correct 6 ms 2956 KB Output is correct
13 Correct 5 ms 3008 KB Output is correct
14 Correct 13 ms 740 KB Output is correct
15 Correct 5 ms 3160 KB Output is correct
16 Correct 7 ms 2904 KB Output is correct
17 Correct 2 ms 344 KB Output is correct
18 Correct 22 ms 3696 KB Output is correct
19 Correct 2 ms 600 KB Output is correct
20 Correct 8 ms 1736 KB Output is correct
21 Correct 14 ms 3064 KB Output is correct
22 Correct 18 ms 3108 KB Output is correct
23 Correct 5 ms 2600 KB Output is correct
24 Correct 3 ms 2648 KB Output is correct
25 Correct 18 ms 3728 KB Output is correct
26 Correct 10 ms 2932 KB Output is correct
27 Correct 3 ms 1880 KB Output is correct
28 Correct 22 ms 3728 KB Output is correct
29 Correct 11 ms 2968 KB Output is correct
30 Partially correct 33 ms 3732 KB Partially correct - number of queries: 5674
31 Correct 2 ms 600 KB Output is correct
32 Correct 5 ms 2956 KB Output is correct
33 Correct 0 ms 344 KB Output is correct
34 Correct 5 ms 2732 KB Output is correct
35 Correct 4 ms 3160 KB Output is correct
36 Partially correct 34 ms 3128 KB Partially correct - number of queries: 5559
37 Correct 3 ms 3416 KB Output is correct
38 Correct 3 ms 2980 KB Output is correct
39 Correct 20 ms 3160 KB Output is correct
40 Correct 12 ms 2972 KB Output is correct
41 Correct 7 ms 2960 KB Output is correct
42 Correct 4 ms 2648 KB Output is correct
43 Correct 12 ms 2964 KB Output is correct
44 Correct 8 ms 2908 KB Output is correct
45 Correct 17 ms 3240 KB Output is correct
46 Correct 2 ms 344 KB Output is correct
47 Correct 17 ms 2992 KB Output is correct
48 Correct 24 ms 3244 KB Output is correct
49 Correct 5 ms 2904 KB Output is correct
50 Correct 8 ms 2904 KB Output is correct
51 Correct 4 ms 2648 KB Output is correct
52 Correct 8 ms 2904 KB Output is correct
53 Correct 4 ms 2720 KB Output is correct
54 Correct 15 ms 3276 KB Output is correct
55 Correct 2 ms 344 KB Output is correct
56 Correct 10 ms 3008 KB Output is correct
57 Correct 25 ms 3344 KB Output is correct
58 Correct 18 ms 3316 KB Output is correct
59 Correct 12 ms 3204 KB Output is correct
60 Correct 12 ms 3076 KB Output is correct
61 Correct 4 ms 2892 KB Output is correct
62 Correct 5 ms 2904 KB Output is correct
63 Correct 4 ms 2892 KB Output is correct
64 Correct 4 ms 2972 KB Output is correct
65 Correct 4 ms 3416 KB Output is correct
66 Correct 5 ms 1992 KB Output is correct
67 Correct 3 ms 1876 KB Output is correct
68 Correct 2 ms 344 KB Output is correct
69 Correct 4 ms 1880 KB Output is correct
70 Correct 4 ms 1880 KB Output is correct
71 Partially correct 31 ms 3428 KB Partially correct - number of queries: 5677
72 Correct 6 ms 2904 KB Output is correct
73 Partially correct 24 ms 3460 KB Partially correct - number of queries: 5699
74 Correct 14 ms 3200 KB Output is correct
75 Correct 3 ms 2708 KB Output is correct
76 Partially correct 17 ms 3084 KB Partially correct - number of queries: 5024
77 Partially correct 25 ms 3236 KB Partially correct - number of queries: 5870
78 Correct 5 ms 3084 KB Output is correct
79 Correct 14 ms 3072 KB Output is correct
80 Correct 11 ms 3016 KB Output is correct
81 Partially correct 21 ms 3332 KB Partially correct - number of queries: 5581
82 Partially correct 23 ms 3420 KB Partially correct - number of queries: 5757
83 Correct 4 ms 2704 KB Output is correct
84 Partially correct 21 ms 3148 KB Partially correct - number of queries: 5132
85 Partially correct 30 ms 3332 KB Partially correct - number of queries: 5751
86 Correct 6 ms 8132 KB Output is correct
87 Correct 4 ms 5976 KB Output is correct
88 Correct 6 ms 8280 KB Output is correct
89 Correct 6 ms 8280 KB Output is correct
90 Correct 3 ms 4184 KB Output is correct
91 Correct 5 ms 8148 KB Output is correct
92 Correct 5 ms 8280 KB Output is correct
93 Correct 9 ms 6668 KB Output is correct
94 Correct 6 ms 6380 KB Output is correct
95 Correct 6 ms 6272 KB Output is correct
96 Correct 5 ms 5976 KB Output is correct
97 Correct 8 ms 8656 KB Output is correct