#include <bits/stdc++.h>
#include "prize.h"
using namespace std;
int Q = 10000;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
map<int, vector<int>> ans;
vector<int> query(int x)
{
if (ans.count(x)) return ans[x];
return ans[x] = ask(x);
}
int dc(int ini, int fim, int qMen, int qL, int qR)
{
// cerr << "ini: " << ini << ", fim: " << fim << '\n';
if (ini > fim || qL + qR == qMen) return -1;
if (fim - ini <= 1)
{
vector<int> aL = query(ini), aR = query(fim);
if (aL[0]+aL[1]==0) return ini;
if (aR[0]+aR[1]==0) return fim;
return -1;
}
if (query(ini) == query(fim)) return -1;
if (qMen - (qL + qR) == fim - ini + 1)
{
for (int i = ini; i <= fim; i++)
{
vector<int> a = query(i);
if (a[0]+a[1] == 0) return i;
}
return -1;
}
int mL = (ini+fim)>>1, mR = (ini+fim)>>1;
vector<int> aL, aR;
bool excludeL = 0, excludeD = 0;
while (mL >= ini)
{
aL = query(mL);
if (aL[0]+aL[1] == 0) return mL;
if (aL[0]+aL[1] < qMen) --mL;
else break;
}
while (mR <= fim)
{
aR = query(mR);
if (aR[0]+aR[1] == 0) return mR;
if (aR[0]+aR[1] < qMen) ++mR;
else break;
}
int x = dc(mR, fim, qMen, aR[0], qR);
if (x == -1) return dc(ini, mL, qMen, qL, aL[1]);
return x;
}
int find_best(int n)
{
// if (n <= 5000)
// {
// vector<int> ids(n); iota(ids.begin(), ids.end(), 0);
// shuffle(ids.begin(), ids.end(), rng);
// for (auto i : ids)
// {
// vector<int> a = query(i);
// if (a[0]+a[1] == 0) return i;
// }
// }
vector<int> ids;
for (int i = 0; i < 10; i++) ids.push_back(uniform_int_distribution<int>(0, n-1)(rng));
vector<vector<int>> possQ;
for (auto x : ids) possQ.push_back(query(x));
int qMen = 1;
for (auto &x : possQ) qMen = max(qMen, x[0]+x[1]);
return dc(0, n-1, qMen, 0, 0);
}
Compilation message
prize.cpp: In function 'int dc(int, int, int, int, int)':
prize.cpp:37:18: warning: unused variable 'excludeL' [-Wunused-variable]
37 | bool excludeL = 0, excludeD = 0;
| ^~~~~~~~
prize.cpp:37:32: warning: unused variable 'excludeD' [-Wunused-variable]
37 | bool excludeL = 0, excludeD = 0;
| ^~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
440 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
596 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
596 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
436 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
432 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
2 ms |
344 KB |
Output is correct |
12 |
Correct |
2 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
432 KB |
Output is correct |
14 |
Correct |
5 ms |
344 KB |
Output is correct |
15 |
Correct |
21 ms |
948 KB |
Output is correct |
16 |
Correct |
5 ms |
428 KB |
Output is correct |
17 |
Correct |
23 ms |
992 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
19 |
Correct |
28 ms |
852 KB |
Output is correct |
20 |
Correct |
14 ms |
612 KB |
Output is correct |
21 |
Correct |
16 ms |
660 KB |
Output is correct |
22 |
Correct |
14 ms |
600 KB |
Output is correct |
23 |
Correct |
2 ms |
440 KB |
Output is correct |
24 |
Correct |
3 ms |
344 KB |
Output is correct |
25 |
Correct |
9 ms |
600 KB |
Output is correct |
26 |
Correct |
11 ms |
600 KB |
Output is correct |
27 |
Correct |
0 ms |
344 KB |
Output is correct |
28 |
Correct |
1 ms |
344 KB |
Output is correct |
29 |
Correct |
3 ms |
472 KB |
Output is correct |
30 |
Correct |
1 ms |
344 KB |
Output is correct |
31 |
Correct |
26 ms |
848 KB |
Output is correct |
32 |
Correct |
2 ms |
344 KB |
Output is correct |
33 |
Correct |
1 ms |
344 KB |
Output is correct |
34 |
Correct |
21 ms |
928 KB |
Output is correct |
35 |
Correct |
1 ms |
344 KB |
Output is correct |
36 |
Correct |
21 ms |
808 KB |
Output is correct |
37 |
Correct |
3 ms |
344 KB |
Output is correct |
38 |
Correct |
1 ms |
596 KB |
Output is correct |
39 |
Correct |
14 ms |
800 KB |
Output is correct |
40 |
Correct |
1 ms |
344 KB |
Output is correct |
41 |
Correct |
15 ms |
600 KB |
Output is correct |
42 |
Correct |
8 ms |
600 KB |
Output is correct |
43 |
Correct |
8 ms |
600 KB |
Output is correct |
44 |
Correct |
16 ms |
856 KB |
Output is correct |
45 |
Correct |
15 ms |
644 KB |
Output is correct |
46 |
Correct |
20 ms |
1164 KB |
Output is correct |
47 |
Correct |
12 ms |
736 KB |
Output is correct |
48 |
Correct |
8 ms |
600 KB |
Output is correct |
49 |
Correct |
20 ms |
740 KB |
Output is correct |
50 |
Correct |
1 ms |
344 KB |
Output is correct |
51 |
Correct |
12 ms |
856 KB |
Output is correct |
52 |
Correct |
25 ms |
872 KB |
Output is correct |
53 |
Correct |
0 ms |
344 KB |
Output is correct |
54 |
Correct |
10 ms |
600 KB |
Output is correct |
55 |
Correct |
25 ms |
848 KB |
Output is correct |
56 |
Correct |
0 ms |
344 KB |
Output is correct |
57 |
Correct |
5 ms |
340 KB |
Output is correct |
58 |
Correct |
5 ms |
600 KB |
Output is correct |
59 |
Correct |
8 ms |
516 KB |
Output is correct |
60 |
Correct |
9 ms |
720 KB |
Output is correct |
61 |
Correct |
1 ms |
344 KB |
Output is correct |
62 |
Correct |
1 ms |
344 KB |
Output is correct |
63 |
Correct |
0 ms |
344 KB |
Output is correct |
64 |
Correct |
1 ms |
344 KB |
Output is correct |
65 |
Correct |
1 ms |
344 KB |
Output is correct |
66 |
Correct |
3 ms |
344 KB |
Output is correct |
67 |
Correct |
1 ms |
344 KB |
Output is correct |
68 |
Correct |
3 ms |
344 KB |
Output is correct |
69 |
Correct |
2 ms |
344 KB |
Output is correct |
70 |
Correct |
1 ms |
344 KB |
Output is correct |
71 |
Correct |
20 ms |
880 KB |
Output is correct |
72 |
Correct |
3 ms |
344 KB |
Output is correct |
73 |
Correct |
26 ms |
1016 KB |
Output is correct |
74 |
Correct |
25 ms |
896 KB |
Output is correct |
75 |
Correct |
1 ms |
344 KB |
Output is correct |
76 |
Correct |
32 ms |
816 KB |
Output is correct |
77 |
Correct |
29 ms |
952 KB |
Output is correct |
78 |
Correct |
3 ms |
456 KB |
Output is correct |
79 |
Correct |
15 ms |
596 KB |
Output is correct |
80 |
Correct |
21 ms |
848 KB |
Output is correct |
81 |
Correct |
26 ms |
936 KB |
Output is correct |
82 |
Correct |
32 ms |
1684 KB |
Output is correct |
83 |
Correct |
1 ms |
344 KB |
Output is correct |
84 |
Correct |
24 ms |
932 KB |
Output is correct |
85 |
Correct |
22 ms |
848 KB |
Output is correct |
86 |
Correct |
4 ms |
600 KB |
Output is correct |
87 |
Correct |
1 ms |
344 KB |
Output is correct |
88 |
Correct |
3 ms |
472 KB |
Output is correct |
89 |
Correct |
2 ms |
344 KB |
Output is correct |
90 |
Correct |
1 ms |
344 KB |
Output is correct |
91 |
Correct |
2 ms |
344 KB |
Output is correct |
92 |
Correct |
0 ms |
344 KB |
Output is correct |
93 |
Correct |
2 ms |
344 KB |
Output is correct |
94 |
Correct |
2 ms |
344 KB |
Output is correct |
95 |
Correct |
2 ms |
344 KB |
Output is correct |
96 |
Correct |
2 ms |
344 KB |
Output is correct |
97 |
Correct |
1 ms |
344 KB |
Output is correct |