#include "prize.h"
#include <algorithm>
#include <iostream>
#include <cassert>
#include <numeric>
#include <vector>
typedef long long llong;
const int MAXN = 200000 + 10;
const int INF = 1e9;
int ans, n;
std::vector <int> res;
std::pair <int,int> asked[MAXN];
inline std::pair <int,int> query(int pos)
{
assert(1 <= pos && pos <= n);
if (asked[pos].first != -1) return asked[pos];
res = ask(pos - 1);
asked[pos] = {res[0], res[1]};
if (res[0] == 0 && res[1] == 0) ans = pos;
return asked[pos];
}
int leftCnt;
int rightCnt;
int cntBig;
int binaryCnt;
int binarySearchLeft(int from, int to)
{
int l = from, r = to, mid;
while (l < r - 1)
{
mid = (l + r) / 2;
auto [left, right] = query(mid);
if (ans != 0) return 0;
if (left + right != cntBig)
{
r = mid;
continue;
}
if (left != leftCnt)
{
r = mid;
continue;
}
l = mid;
}
query(r);
leftCnt++;
return r;
}
int binarySearchRight(int from, int to)
{
int l = from, r = to, mid;
while (l < r - 1)
{
mid = (l + r) / 2;
auto [left, right] = query(mid);
if (ans != 0) return 0;
if (left + right != cntBig)
{
l = mid;
continue;
}
if (right != rightCnt)
{
l = mid;
continue;
}
r = mid;
}
query(l);
rightCnt++;
return l;
}
int find_best(int N)
{
n = N;
srand(6686889);
std::fill(asked + 1, asked + 1 + n, std::make_pair(-1, -1));
for (int i = 1 ; i <= std::min(n, 500) ; ++i)
{
query(i);
cntBig = std::max(cntBig, asked[i].first + asked[i].second);
}
if (ans != 0) return ans - 1;
for (int i = 1 ; i <= 500 ; ++i)
{
leftCnt += (asked[i].first + asked[i].second != cntBig);
}
int l = 447, r = n + 1;
while (ans == 0 && l < r - 1)
{
if (rand()%2 == 0) l = binarySearchLeft(l, r);
else r = binarySearchRight(l, r);
}
if (ans == 0 && l != 0) query(l);
if (ans == 0 && r != n + 1) query(r);
assert(asked[ans].first == 0 && asked[ans].second == 0);
return ans - 1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
1832 KB |
Output is correct |
2 |
Correct |
3 ms |
1836 KB |
Output is correct |
3 |
Correct |
4 ms |
1832 KB |
Output is correct |
4 |
Correct |
7 ms |
1824 KB |
Output is correct |
5 |
Correct |
5 ms |
1840 KB |
Output is correct |
6 |
Correct |
5 ms |
1824 KB |
Output is correct |
7 |
Correct |
3 ms |
1744 KB |
Output is correct |
8 |
Correct |
3 ms |
1744 KB |
Output is correct |
9 |
Correct |
3 ms |
1832 KB |
Output is correct |
10 |
Correct |
5 ms |
1744 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
1840 KB |
Output is correct |
2 |
Correct |
4 ms |
1744 KB |
Output is correct |
3 |
Correct |
3 ms |
1844 KB |
Output is correct |
4 |
Correct |
3 ms |
1832 KB |
Output is correct |
5 |
Correct |
7 ms |
1920 KB |
Output is correct |
6 |
Correct |
4 ms |
1744 KB |
Output is correct |
7 |
Correct |
3 ms |
1836 KB |
Output is correct |
8 |
Correct |
3 ms |
1840 KB |
Output is correct |
9 |
Correct |
4 ms |
1836 KB |
Output is correct |
10 |
Correct |
5 ms |
1744 KB |
Output is correct |
11 |
Correct |
10 ms |
1736 KB |
Output is correct |
12 |
Correct |
5 ms |
1836 KB |
Output is correct |
13 |
Correct |
5 ms |
1744 KB |
Output is correct |
14 |
Correct |
11 ms |
464 KB |
Output is correct |
15 |
Correct |
11 ms |
1840 KB |
Output is correct |
16 |
Correct |
25 ms |
1832 KB |
Output is correct |
17 |
Correct |
6 ms |
1828 KB |
Output is correct |
18 |
Correct |
6 ms |
1836 KB |
Output is correct |
19 |
Correct |
3 ms |
1832 KB |
Output is correct |
20 |
Correct |
30 ms |
1068 KB |
Output is correct |
21 |
Partially correct |
48 ms |
1840 KB |
Partially correct - number of queries: 6258 |
22 |
Correct |
17 ms |
1744 KB |
Output is correct |
23 |
Correct |
6 ms |
1744 KB |
Output is correct |
24 |
Correct |
3 ms |
1872 KB |
Output is correct |
25 |
Partially correct |
47 ms |
1836 KB |
Partially correct - number of queries: 7757 |
26 |
Partially correct |
74 ms |
1836 KB |
Partially correct - number of queries: 7875 |
27 |
Correct |
4 ms |
1736 KB |
Output is correct |
28 |
Correct |
9 ms |
1824 KB |
Output is correct |
29 |
Correct |
21 ms |
1744 KB |
Output is correct |
30 |
Correct |
5 ms |
1828 KB |
Output is correct |
31 |
Correct |
5 ms |
1736 KB |
Output is correct |
32 |
Correct |
10 ms |
1812 KB |
Output is correct |
33 |
Correct |
1 ms |
208 KB |
Output is correct |
34 |
Partially correct |
36 ms |
1836 KB |
Partially correct - number of queries: 5345 |
35 |
Correct |
6 ms |
1840 KB |
Output is correct |
36 |
Correct |
18 ms |
1836 KB |
Output is correct |
37 |
Correct |
6 ms |
1736 KB |
Output is correct |
38 |
Correct |
5 ms |
1744 KB |
Output is correct |
39 |
Partially correct |
62 ms |
1840 KB |
Partially correct - number of queries: 7043 |
40 |
Correct |
3 ms |
1840 KB |
Output is correct |
41 |
Partially correct |
55 ms |
1744 KB |
Partially correct - number of queries: 6476 |
42 |
Partially correct |
50 ms |
1744 KB |
Partially correct - number of queries: 6476 |
43 |
Partially correct |
51 ms |
1836 KB |
Partially correct - number of queries: 6995 |
44 |
Partially correct |
51 ms |
1824 KB |
Partially correct - number of queries: 6625 |
45 |
Partially correct |
58 ms |
1744 KB |
Partially correct - number of queries: 5457 |
46 |
Correct |
4 ms |
1832 KB |
Output is correct |
47 |
Partially correct |
59 ms |
1836 KB |
Partially correct - number of queries: 7427 |
48 |
Partially correct |
43 ms |
1744 KB |
Partially correct - number of queries: 5087 |
49 |
Correct |
17 ms |
1744 KB |
Output is correct |
50 |
Correct |
6 ms |
1828 KB |
Output is correct |
51 |
Partially correct |
51 ms |
1828 KB |
Partially correct - number of queries: 6652 |
52 |
Correct |
3 ms |
1828 KB |
Output is correct |
53 |
Correct |
5 ms |
1832 KB |
Output is correct |
54 |
Partially correct |
61 ms |
1744 KB |
Partially correct - number of queries: 6865 |
55 |
Correct |
5 ms |
1816 KB |
Output is correct |
56 |
Correct |
6 ms |
1832 KB |
Output is correct |
57 |
Partially correct |
20 ms |
1832 KB |
Partially correct - number of queries: 5166 |
58 |
Partially correct |
22 ms |
1840 KB |
Partially correct - number of queries: 5105 |
59 |
Partially correct |
60 ms |
1836 KB |
Partially correct - number of queries: 6476 |
60 |
Partially correct |
57 ms |
1744 KB |
Partially correct - number of queries: 7316 |
61 |
Correct |
4 ms |
1828 KB |
Output is correct |
62 |
Correct |
5 ms |
1740 KB |
Output is correct |
63 |
Correct |
3 ms |
1744 KB |
Output is correct |
64 |
Correct |
5 ms |
1744 KB |
Output is correct |
65 |
Correct |
5 ms |
1836 KB |
Output is correct |
66 |
Correct |
4 ms |
1840 KB |
Output is correct |
67 |
Correct |
8 ms |
1744 KB |
Output is correct |
68 |
Correct |
4 ms |
1824 KB |
Output is correct |
69 |
Correct |
6 ms |
1840 KB |
Output is correct |
70 |
Correct |
6 ms |
1836 KB |
Output is correct |
71 |
Partially correct |
74 ms |
1744 KB |
Partially correct - number of queries: 8326 |
72 |
Correct |
9 ms |
1744 KB |
Output is correct |
73 |
Partially correct |
71 ms |
1744 KB |
Partially correct - number of queries: 8205 |
74 |
Partially correct |
85 ms |
1744 KB |
Partially correct - number of queries: 8239 |
75 |
Correct |
7 ms |
1744 KB |
Output is correct |
76 |
Partially correct |
30 ms |
1748 KB |
Partially correct - number of queries: 7135 |
77 |
Partially correct |
41 ms |
1744 KB |
Partially correct - number of queries: 8179 |
78 |
Correct |
10 ms |
1744 KB |
Output is correct |
79 |
Correct |
37 ms |
1744 KB |
Output is correct |
80 |
Partially correct |
69 ms |
1744 KB |
Partially correct - number of queries: 8177 |
81 |
Partially correct |
73 ms |
1744 KB |
Partially correct - number of queries: 7923 |
82 |
Partially correct |
71 ms |
1744 KB |
Partially correct - number of queries: 8081 |
83 |
Correct |
4 ms |
1832 KB |
Output is correct |
84 |
Partially correct |
55 ms |
1744 KB |
Partially correct - number of queries: 6702 |
85 |
Partially correct |
65 ms |
1768 KB |
Partially correct - number of queries: 8125 |
86 |
Correct |
4 ms |
1744 KB |
Output is correct |
87 |
Correct |
6 ms |
1744 KB |
Output is correct |
88 |
Correct |
5 ms |
1744 KB |
Output is correct |
89 |
Correct |
3 ms |
1840 KB |
Output is correct |
90 |
Correct |
5 ms |
1744 KB |
Output is correct |
91 |
Correct |
5 ms |
1836 KB |
Output is correct |
92 |
Correct |
6 ms |
1744 KB |
Output is correct |
93 |
Correct |
8 ms |
1744 KB |
Output is correct |
94 |
Correct |
14 ms |
1744 KB |
Output is correct |
95 |
Correct |
11 ms |
1744 KB |
Output is correct |
96 |
Correct |
8 ms |
1744 KB |
Output is correct |
97 |
Correct |
5 ms |
1744 KB |
Output is correct |