#include "prize.h"
#include <iostream>
#include <vector>
#include <random>
#include <chrono>
#include <map>
#define ll long long
using namespace std;
ll f;
map <ll, vector<int> > mp;
vector <int> R;
vector <int> query(ll u) {
if (mp.find(u) != mp.end()) return mp[u];
else return mp[u] = ask(u);
}
void solve(ll l, ll r, ll ql, ll qr) {
if (l > r || ql + qr == R[0] + R[1]) return;
ll mid = (l+r)/2;
for (int i=mid; i<=r; ++i) {
auto u = query(i);
if (!u[0] && !u[1]) {
f = i;
return;
}
else if (u[0]+u[1] == R[0]+R[1]) {
solve(l, mid-1, ql, u[1]+(i-mid));
if (f != -1) return;
solve(i+1, r, u[0], qr);
return;
}
else if (u[0]+u[1] > R[0]+R[1]) {
R = u;
f = 1e18;
return;
}
}
solve(l, mid-1, ql, qr+(r-mid+1));
}
int find_best(int n) {
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
R = {-1, -1};
for (int i=0; i<100; ++i) {
ll id = rng() % n;
auto u = query(id);
if (!u[0] && !u[1]) return id;
if (u[0]+u[1] > R[0]+R[1]) swap(u, R);
}
while (true) {
f = -1;
solve(0, n-1, 0, 0);
if (f != 1e18) break;
}
return f;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
440 KB |
Output is correct |
2 |
Correct |
1 ms |
444 KB |
Output is correct |
3 |
Correct |
1 ms |
620 KB |
Output is correct |
4 |
Correct |
1 ms |
440 KB |
Output is correct |
5 |
Correct |
1 ms |
444 KB |
Output is correct |
6 |
Correct |
1 ms |
444 KB |
Output is correct |
7 |
Correct |
1 ms |
444 KB |
Output is correct |
8 |
Correct |
1 ms |
444 KB |
Output is correct |
9 |
Correct |
1 ms |
444 KB |
Output is correct |
10 |
Correct |
1 ms |
440 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
444 KB |
Output is correct |
2 |
Correct |
1 ms |
444 KB |
Output is correct |
3 |
Correct |
1 ms |
444 KB |
Output is correct |
4 |
Correct |
1 ms |
444 KB |
Output is correct |
5 |
Correct |
1 ms |
440 KB |
Output is correct |
6 |
Correct |
1 ms |
444 KB |
Output is correct |
7 |
Correct |
1 ms |
444 KB |
Output is correct |
8 |
Correct |
1 ms |
688 KB |
Output is correct |
9 |
Correct |
1 ms |
444 KB |
Output is correct |
10 |
Correct |
1 ms |
436 KB |
Output is correct |
11 |
Correct |
1 ms |
464 KB |
Output is correct |
12 |
Correct |
1 ms |
440 KB |
Output is correct |
13 |
Correct |
2 ms |
752 KB |
Output is correct |
14 |
Correct |
1 ms |
440 KB |
Output is correct |
15 |
Correct |
4 ms |
976 KB |
Output is correct |
16 |
Correct |
16 ms |
1504 KB |
Output is correct |
17 |
Correct |
1 ms |
692 KB |
Output is correct |
18 |
Correct |
21 ms |
1604 KB |
Output is correct |
19 |
Correct |
1 ms |
444 KB |
Output is correct |
20 |
Correct |
6 ms |
980 KB |
Output is correct |
21 |
Correct |
10 ms |
724 KB |
Output is correct |
22 |
Correct |
2 ms |
984 KB |
Output is correct |
23 |
Correct |
1 ms |
444 KB |
Output is correct |
24 |
Correct |
1 ms |
616 KB |
Output is correct |
25 |
Correct |
11 ms |
1568 KB |
Output is correct |
26 |
Correct |
13 ms |
816 KB |
Output is correct |
27 |
Correct |
1 ms |
444 KB |
Output is correct |
28 |
Correct |
21 ms |
1080 KB |
Output is correct |
29 |
Correct |
19 ms |
1440 KB |
Output is correct |
30 |
Correct |
23 ms |
2012 KB |
Output is correct |
31 |
Correct |
1 ms |
596 KB |
Output is correct |
32 |
Correct |
2 ms |
472 KB |
Output is correct |
33 |
Correct |
1 ms |
440 KB |
Output is correct |
34 |
Correct |
7 ms |
804 KB |
Output is correct |
35 |
Correct |
1 ms |
444 KB |
Output is correct |
36 |
Correct |
5 ms |
700 KB |
Output is correct |
37 |
Correct |
1 ms |
700 KB |
Output is correct |
38 |
Correct |
1 ms |
440 KB |
Output is correct |
39 |
Correct |
10 ms |
1264 KB |
Output is correct |
40 |
Correct |
18 ms |
1444 KB |
Output is correct |
41 |
Correct |
13 ms |
1288 KB |
Output is correct |
42 |
Correct |
10 ms |
988 KB |
Output is correct |
43 |
Correct |
9 ms |
1004 KB |
Output is correct |
44 |
Correct |
10 ms |
1572 KB |
Output is correct |
45 |
Correct |
8 ms |
1248 KB |
Output is correct |
46 |
Correct |
1 ms |
444 KB |
Output is correct |
47 |
Correct |
9 ms |
700 KB |
Output is correct |
48 |
Correct |
14 ms |
960 KB |
Output is correct |
49 |
Correct |
3 ms |
716 KB |
Output is correct |
50 |
Correct |
22 ms |
1428 KB |
Output is correct |
51 |
Correct |
10 ms |
984 KB |
Output is correct |
52 |
Correct |
1 ms |
440 KB |
Output is correct |
53 |
Correct |
1 ms |
440 KB |
Output is correct |
54 |
Correct |
12 ms |
740 KB |
Output is correct |
55 |
Correct |
1 ms |
444 KB |
Output is correct |
56 |
Correct |
21 ms |
1744 KB |
Output is correct |
57 |
Correct |
14 ms |
1124 KB |
Output is correct |
58 |
Correct |
17 ms |
956 KB |
Output is correct |
59 |
Correct |
16 ms |
1092 KB |
Output is correct |
60 |
Correct |
10 ms |
1372 KB |
Output is correct |
61 |
Correct |
1 ms |
440 KB |
Output is correct |
62 |
Correct |
1 ms |
444 KB |
Output is correct |
63 |
Correct |
1 ms |
440 KB |
Output is correct |
64 |
Correct |
2 ms |
696 KB |
Output is correct |
65 |
Correct |
1 ms |
444 KB |
Output is correct |
66 |
Correct |
2 ms |
712 KB |
Output is correct |
67 |
Correct |
3 ms |
964 KB |
Output is correct |
68 |
Correct |
1 ms |
436 KB |
Output is correct |
69 |
Correct |
2 ms |
464 KB |
Output is correct |
70 |
Correct |
2 ms |
700 KB |
Output is correct |
71 |
Correct |
23 ms |
1436 KB |
Output is correct |
72 |
Correct |
3 ms |
476 KB |
Output is correct |
73 |
Correct |
25 ms |
2416 KB |
Output is correct |
74 |
Correct |
22 ms |
1020 KB |
Output is correct |
75 |
Correct |
1 ms |
460 KB |
Output is correct |
76 |
Correct |
22 ms |
1212 KB |
Output is correct |
77 |
Correct |
20 ms |
1132 KB |
Output is correct |
78 |
Correct |
2 ms |
436 KB |
Output is correct |
79 |
Correct |
12 ms |
1236 KB |
Output is correct |
80 |
Correct |
20 ms |
1204 KB |
Output is correct |
81 |
Correct |
24 ms |
1460 KB |
Output is correct |
82 |
Correct |
22 ms |
1508 KB |
Output is correct |
83 |
Correct |
1 ms |
440 KB |
Output is correct |
84 |
Correct |
17 ms |
992 KB |
Output is correct |
85 |
Correct |
23 ms |
1724 KB |
Output is correct |
86 |
Correct |
8 ms |
952 KB |
Output is correct |
87 |
Correct |
2 ms |
696 KB |
Output is correct |
88 |
Correct |
6 ms |
1272 KB |
Output is correct |
89 |
Correct |
9 ms |
692 KB |
Output is correct |
90 |
Correct |
1 ms |
436 KB |
Output is correct |
91 |
Correct |
8 ms |
1360 KB |
Output is correct |
92 |
Correct |
3 ms |
696 KB |
Output is correct |
93 |
Correct |
2 ms |
708 KB |
Output is correct |
94 |
Correct |
2 ms |
724 KB |
Output is correct |
95 |
Correct |
2 ms |
948 KB |
Output is correct |
96 |
Correct |
2 ms |
728 KB |
Output is correct |
97 |
Correct |
1 ms |
440 KB |
Output is correct |