#include <bits/stdc++.h>
using namespace std;
using i32 = int;
using i64 = long long;
template <typename T>
using V = vector<T>;
template <typename T>
using VV = V<V<T>>;
template <typename T>
using VVV = V<VV<T>>;
template <typename T>
bool chmin(T &x, const T &y) {
if (x > y) {
x = y;
return true;
}
return false;
}
template <typename T>
bool chmax(T &x, const T &y) {
if (x < y) {
x = y;
return true;
}
return false;
}
#define OVERRIDE4(a, b, c, d, ...) d
#define REP2(i, n) for (i32 i = 0; i < (i32)(n); ++i)
#define REP3(i, l, r) for (i32 i = (i32)(l); i < (i32)(r); ++i)
#define REP(...) OVERRIDE4(__VA_ARGS__, REP3, REP2)(__VA_ARGS__)
#define PER2(i, n) for (i32 i = (i32)(n)-1; i >= 0; --i)
#define PER3(i, l, r) for (i32 i = (i32)(r)-1; i >= (i32)(l); --i)
#define PER(...) OVERRIDE4(__VA_ARGS__, PER3, PER2)(__VA_ARGS__)
#define LEN(x) (i32) size(x)
#define ALL(x) begin(x), end(x)
void dbg(i32 x) { cerr << x; }
void dbg(i64 x) { cerr << x; }
template <typename T, typename U>
void dbg(pair<T, U> p) {
cerr << "(";
dbg(p.first);
cerr << ", ";
dbg(p.second);
cerr << ")";
}
template <typename T>
void dbg(V<T> arr) {
cerr << "[";
REP(i, LEN(arr)) {
if (i) {
cerr << ", ";
}
dbg(arr[i]);
}
cerr << "]";
}
void debug() { cerr << '\n'; }
template <typename Head, typename... Tail>
void debug(Head head, Tail... tail) {
dbg(head);
cerr << ", ";
debug(tail...);
}
#ifdef DEBUGF
#define DBG(...) \
do { \
cerr << #__VA_ARGS__ << " : "; \
debug(__VA_ARGS__); \
} while (false)
#else
#define DBG(...) (void)0
#endif
#include "prize.h"
pair<i32, i32> ask2(i32 x) {
static i32 q;
++q;
if (q == 10000) {
assert(false);
}
V<i32> ret = ask(x);
return pair<i32, i32>(ret[0], ret[1]);
}
i32 subtask_1(i32 n) {
i32 ok = -1, ng = n - 1;
while (ng - ok > 1) {
i32 mid = (ok + ng) / 2;
auto [l, r] = ask2(mid);
if (r) {
ok = mid;
} else {
ng = mid;
}
}
return ng;
}
i32 find_best(i32 n) {
mt19937 mt(random_device{}());
i32 cands = 0;
{
uniform_int_distribution<> dist(0, n - 1);
REP(i, 50) {
auto [l, r] = ask2(dist(mt));
chmax(cands, l + r);
}
}
auto rec = [&](auto rec, i32 l, i32 r, i32 lc, i32 rc) -> i32 {
i32 tc = cands - lc - rc;
if (tc == 0) {
return -1;
}
DBG(l, r, lc, rc);
i32 mid = (l + r) / 2;
auto [lm, rm] = ask2(mid);
DBG(mid, lm, rm);
if (lm + rm == 0) {
return mid;
}
if (lm + rm == cands) {
i32 tmp = rec(rec, l, mid, lc, rm);
if (tmp != -1) {
return tmp;
}
return rec(rec, mid, r, lm, rc);
}
// to left
if (lm != 0) {
i32 x = mid - 1;
while (x >= l) {
auto [lx, rx] = ask2(x);
if (lx + rx == 0) {
return x;
}
if (lx + rx == cands) {
i32 tmp = rec(rec, l, x, lc, rx);
if (tmp != -1) {
return tmp;
}
break;
}
if (lm == 0) {
break;
}
--x;
}
}
// to right
{
i32 x = mid + 1;
while (x < r) {
auto [lx, rx] = ask2(x);
if (lx + rx == 0) {
return x;
}
if (lx + rx == cands) {
i32 tmp = rec(rec, x + 1, r, lx, rc);
if (tmp != -1) {
return tmp;
}
break;
}
++x;
}
}
return -1;
};
i32 ans = rec(rec, 0, n, 0, 0);
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 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 |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 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 |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
2 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
3 ms |
344 KB |
Output is correct |
14 |
Correct |
2 ms |
344 KB |
Output is correct |
15 |
Correct |
3 ms |
344 KB |
Output is correct |
16 |
Correct |
21 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
19 ms |
344 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
7 ms |
344 KB |
Output is correct |
21 |
Correct |
5 ms |
344 KB |
Output is correct |
22 |
Correct |
1 ms |
344 KB |
Output is correct |
23 |
Correct |
1 ms |
344 KB |
Output is correct |
24 |
Correct |
1 ms |
344 KB |
Output is correct |
25 |
Correct |
11 ms |
344 KB |
Output is correct |
26 |
Correct |
11 ms |
344 KB |
Output is correct |
27 |
Correct |
1 ms |
344 KB |
Output is correct |
28 |
Correct |
20 ms |
344 KB |
Output is correct |
29 |
Correct |
15 ms |
344 KB |
Output is correct |
30 |
Correct |
24 ms |
344 KB |
Output is correct |
31 |
Correct |
1 ms |
344 KB |
Output is correct |
32 |
Correct |
2 ms |
344 KB |
Output is correct |
33 |
Correct |
0 ms |
344 KB |
Output is correct |
34 |
Correct |
7 ms |
344 KB |
Output is correct |
35 |
Correct |
1 ms |
344 KB |
Output is correct |
36 |
Correct |
3 ms |
344 KB |
Output is correct |
37 |
Correct |
1 ms |
344 KB |
Output is correct |
38 |
Correct |
1 ms |
424 KB |
Output is correct |
39 |
Correct |
9 ms |
344 KB |
Output is correct |
40 |
Correct |
17 ms |
344 KB |
Output is correct |
41 |
Correct |
13 ms |
344 KB |
Output is correct |
42 |
Correct |
15 ms |
344 KB |
Output is correct |
43 |
Correct |
16 ms |
344 KB |
Output is correct |
44 |
Correct |
9 ms |
344 KB |
Output is correct |
45 |
Correct |
7 ms |
344 KB |
Output is correct |
46 |
Correct |
0 ms |
424 KB |
Output is correct |
47 |
Correct |
13 ms |
344 KB |
Output is correct |
48 |
Correct |
12 ms |
344 KB |
Output is correct |
49 |
Correct |
2 ms |
344 KB |
Output is correct |
50 |
Correct |
21 ms |
344 KB |
Output is correct |
51 |
Correct |
6 ms |
344 KB |
Output is correct |
52 |
Correct |
1 ms |
344 KB |
Output is correct |
53 |
Correct |
1 ms |
344 KB |
Output is correct |
54 |
Correct |
8 ms |
344 KB |
Output is correct |
55 |
Correct |
1 ms |
344 KB |
Output is correct |
56 |
Correct |
22 ms |
344 KB |
Output is correct |
57 |
Correct |
16 ms |
344 KB |
Output is correct |
58 |
Correct |
12 ms |
344 KB |
Output is correct |
59 |
Correct |
16 ms |
344 KB |
Output is correct |
60 |
Correct |
15 ms |
340 KB |
Output is correct |
61 |
Correct |
1 ms |
344 KB |
Output is correct |
62 |
Correct |
0 ms |
344 KB |
Output is correct |
63 |
Correct |
1 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 |
1 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 |
30 ms |
344 KB |
Output is correct |
72 |
Correct |
2 ms |
344 KB |
Output is correct |
73 |
Correct |
20 ms |
344 KB |
Output is correct |
74 |
Correct |
14 ms |
344 KB |
Output is correct |
75 |
Correct |
1 ms |
344 KB |
Output is correct |
76 |
Correct |
14 ms |
344 KB |
Output is correct |
77 |
Correct |
19 ms |
344 KB |
Output is correct |
78 |
Correct |
2 ms |
344 KB |
Output is correct |
79 |
Correct |
12 ms |
344 KB |
Output is correct |
80 |
Correct |
18 ms |
344 KB |
Output is correct |
81 |
Correct |
28 ms |
344 KB |
Output is correct |
82 |
Correct |
32 ms |
344 KB |
Output is correct |
83 |
Correct |
1 ms |
344 KB |
Output is correct |
84 |
Correct |
30 ms |
344 KB |
Output is correct |
85 |
Correct |
25 ms |
344 KB |
Output is correct |
86 |
Correct |
5 ms |
344 KB |
Output is correct |
87 |
Correct |
2 ms |
344 KB |
Output is correct |
88 |
Partially correct |
42 ms |
340 KB |
Partially correct - number of queries: 9137 |
89 |
Partially correct |
61 ms |
344 KB |
Partially correct - number of queries: 9202 |
90 |
Correct |
1 ms |
344 KB |
Output is correct |
91 |
Partially correct |
41 ms |
344 KB |
Partially correct - number of queries: 9852 |
92 |
Correct |
6 ms |
344 KB |
Output is correct |
93 |
Correct |
2 ms |
344 KB |
Output is correct |
94 |
Correct |
3 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 |