#include <bits/stdc++.h>
#include "prize.h"
#ifdef ONPC
#include "t_debug.cpp"
#else
#define debug(...) 42
#endif
#define sz(a) ((int)(a).size())
using namespace std;
using ll = long long;
const int INF = 1e9;
const ll INFL = 1e18;
const int RANDOM = chrono::high_resolution_clock::now().time_since_epoch().count();
mt19937 rng(RANDOM);
template<typename T, typename U> istream& operator>>(istream& is, pair<T, U>& p) { return is >> p.first >> p.second; }
const int N = 2e5, LOGN = 17, MOD = 1e9+7;
int find_best(int n) {
vector<int> res;
int mx = 0, L = 0, R = n-1;
for (int i = 0; i < min(n, 500); i++) {
res = ask(i);
if (res[0] + res[1] > mx) {
mx = res[0] + res[1];
L = i;
} else if (res[0] + res[1] == 0) {
return i;
}
}
for (; R >= L; R--) {
res = ask(R);
if (res[0] + res[1] == mx) break;
else if (res[0] + res[1] == 0) return R;
}
int ans = -1;
function<void(int,int,int)> solve = [&](int L, int R, int count)->void {
if (count <= 0) return;
if (L > R) return;
if (~ans) return;
if (R - L + 1 == count) {
for (int i = L; i <= R; i++) {
auto res = ask(i);
if (res[0] + res[1] == 0) ans = i;
break;
}
return;
}
vector<int> res;
while (true) {
res = ask(L);
if (res[0] + res[1] == 0) {
ans = L;
return;
}else if (res[0] + res[1] == mx) break;
else {L++; count--;}
}
int mid1 = (L + R) / 2;
int mid2 = mid1;
while (true) {
auto res2 = ask(mid2);
if (res2[0] + res2[1] < mx) {
if (res2[0] + res2[1] == 0) {
ans = mid2;
return;
}
mid2++;
} else {
int rem = mid2 - mid1;
int count1 = res2[0] - res[0] - rem;
int count2 = count - count1 - rem;
solve(L+1, mid1-1, count1);
solve(mid2+1, R, count2);
return;
}
}
};
debug(mx, L, R, res);
solve(L, R, res[0]);
return ans;
}
/*
█████ █████ ███ ████
▒▒███ ▒▒███ ▒▒▒ ▒▒███
███████ ████████ ███████ ████ ▒███ █████ ████ ██████ ████████
███▒▒███ ▒▒███▒▒███ ███▒▒███ ▒▒███ ▒███ ▒▒███ ▒███ ███▒▒███▒▒███▒▒███
▒███ ▒███ ▒███ ▒▒▒ ▒███ ▒███ ▒███ ▒███ ▒███ ▒███ ▒███ ▒███ ▒███ ▒▒▒
▒███ ▒███ ▒███ ▒███ ▒███ ▒███ ▒███ ▒███ ▒███ ▒███ ▒███ ▒███
▒▒████████ █████ ▒▒████████ █████ █████ ▒▒███████ ▒▒██████ █████
▒▒▒▒▒▒▒▒ ▒▒▒▒▒ ▒▒▒▒▒▒▒▒ ▒▒▒▒▒ ▒▒▒▒▒ ▒▒▒▒▒███ ▒▒▒▒▒▒ ▒▒▒▒▒
███ ▒███
▒▒██████
▒▒▒▒▒▒
*/
Compilation message
prize.cpp: In function 'int find_best(int)':
prize.cpp:6:24: warning: statement has no effect [-Wunused-value]
6 | #define debug(...) 42
| ^~
prize.cpp:78:5: note: in expansion of macro 'debug'
78 | debug(mx, L, R, res);
| ^~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
296 KB |
Output is correct |
2 |
Correct |
5 ms |
208 KB |
Output is correct |
3 |
Correct |
3 ms |
296 KB |
Output is correct |
4 |
Correct |
3 ms |
208 KB |
Output is correct |
5 |
Correct |
3 ms |
208 KB |
Output is correct |
6 |
Correct |
1 ms |
296 KB |
Output is correct |
7 |
Correct |
4 ms |
292 KB |
Output is correct |
8 |
Correct |
4 ms |
208 KB |
Output is correct |
9 |
Correct |
7 ms |
208 KB |
Output is correct |
10 |
Correct |
6 ms |
208 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
292 KB |
Output is correct |
2 |
Correct |
3 ms |
208 KB |
Output is correct |
3 |
Correct |
3 ms |
292 KB |
Output is correct |
4 |
Correct |
7 ms |
296 KB |
Output is correct |
5 |
Correct |
3 ms |
336 KB |
Output is correct |
6 |
Correct |
0 ms |
292 KB |
Output is correct |
7 |
Correct |
3 ms |
208 KB |
Output is correct |
8 |
Correct |
5 ms |
208 KB |
Output is correct |
9 |
Correct |
4 ms |
208 KB |
Output is correct |
10 |
Correct |
6 ms |
208 KB |
Output is correct |
11 |
Correct |
12 ms |
208 KB |
Output is correct |
12 |
Correct |
8 ms |
208 KB |
Output is correct |
13 |
Correct |
11 ms |
208 KB |
Output is correct |
14 |
Correct |
6 ms |
208 KB |
Output is correct |
15 |
Correct |
12 ms |
296 KB |
Output is correct |
16 |
Partially correct |
71 ms |
292 KB |
Partially correct - number of queries: 6879 |
17 |
Correct |
6 ms |
208 KB |
Output is correct |
18 |
Partially correct |
83 ms |
208 KB |
Partially correct - number of queries: 8254 |
19 |
Correct |
2 ms |
336 KB |
Output is correct |
20 |
Correct |
16 ms |
296 KB |
Output is correct |
21 |
Correct |
24 ms |
208 KB |
Output is correct |
22 |
Correct |
10 ms |
300 KB |
Output is correct |
23 |
Correct |
7 ms |
296 KB |
Output is correct |
24 |
Correct |
3 ms |
296 KB |
Output is correct |
25 |
Correct |
35 ms |
296 KB |
Output is correct |
26 |
Correct |
16 ms |
292 KB |
Output is correct |
27 |
Correct |
6 ms |
208 KB |
Output is correct |
28 |
Partially correct |
34 ms |
296 KB |
Partially correct - number of queries: 7033 |
29 |
Partially correct |
27 ms |
208 KB |
Partially correct - number of queries: 5581 |
30 |
Partially correct |
58 ms |
208 KB |
Partially correct - number of queries: 8089 |
31 |
Correct |
3 ms |
288 KB |
Output is correct |
32 |
Correct |
10 ms |
292 KB |
Output is correct |
33 |
Correct |
1 ms |
208 KB |
Output is correct |
34 |
Correct |
29 ms |
300 KB |
Output is correct |
35 |
Correct |
3 ms |
300 KB |
Output is correct |
36 |
Correct |
25 ms |
296 KB |
Output is correct |
37 |
Correct |
8 ms |
208 KB |
Output is correct |
38 |
Correct |
7 ms |
208 KB |
Output is correct |
39 |
Correct |
40 ms |
296 KB |
Output is correct |
40 |
Partially correct |
55 ms |
292 KB |
Partially correct - number of queries: 7261 |
41 |
Correct |
24 ms |
292 KB |
Output is correct |
42 |
Correct |
41 ms |
208 KB |
Output is correct |
43 |
Correct |
41 ms |
208 KB |
Output is correct |
44 |
Correct |
34 ms |
296 KB |
Output is correct |
45 |
Correct |
26 ms |
296 KB |
Output is correct |
46 |
Correct |
4 ms |
292 KB |
Output is correct |
47 |
Correct |
32 ms |
276 KB |
Output is correct |
48 |
Partially correct |
64 ms |
292 KB |
Partially correct - number of queries: 6002 |
49 |
Correct |
15 ms |
288 KB |
Output is correct |
50 |
Partially correct |
77 ms |
296 KB |
Partially correct - number of queries: 8237 |
51 |
Correct |
29 ms |
296 KB |
Output is correct |
52 |
Correct |
8 ms |
208 KB |
Output is correct |
53 |
Correct |
8 ms |
208 KB |
Output is correct |
54 |
Correct |
17 ms |
288 KB |
Output is correct |
55 |
Correct |
4 ms |
296 KB |
Output is correct |
56 |
Partially correct |
34 ms |
296 KB |
Partially correct - number of queries: 8279 |
57 |
Partially correct |
22 ms |
296 KB |
Partially correct - number of queries: 5929 |
58 |
Partially correct |
57 ms |
296 KB |
Partially correct - number of queries: 5986 |
59 |
Correct |
32 ms |
208 KB |
Output is correct |
60 |
Correct |
44 ms |
296 KB |
Output is correct |
61 |
Correct |
3 ms |
300 KB |
Output is correct |
62 |
Correct |
3 ms |
336 KB |
Output is correct |
63 |
Correct |
8 ms |
208 KB |
Output is correct |
64 |
Correct |
3 ms |
296 KB |
Output is correct |
65 |
Correct |
2 ms |
208 KB |
Output is correct |
66 |
Correct |
5 ms |
296 KB |
Output is correct |
67 |
Correct |
4 ms |
292 KB |
Output is correct |
68 |
Correct |
7 ms |
300 KB |
Output is correct |
69 |
Correct |
5 ms |
292 KB |
Output is correct |
70 |
Correct |
4 ms |
400 KB |
Output is correct |
71 |
Partially correct |
83 ms |
208 KB |
Partially correct - number of queries: 9546 |
72 |
Correct |
14 ms |
208 KB |
Output is correct |
73 |
Partially correct |
84 ms |
208 KB |
Partially correct - number of queries: 9427 |
74 |
Partially correct |
79 ms |
208 KB |
Partially correct - number of queries: 9478 |
75 |
Correct |
5 ms |
300 KB |
Output is correct |
76 |
Partially correct |
62 ms |
208 KB |
Partially correct - number of queries: 8322 |
77 |
Partially correct |
68 ms |
304 KB |
Partially correct - number of queries: 8540 |
78 |
Correct |
10 ms |
208 KB |
Output is correct |
79 |
Correct |
47 ms |
208 KB |
Output is correct |
80 |
Partially correct |
80 ms |
208 KB |
Partially correct - number of queries: 8502 |
81 |
Partially correct |
49 ms |
208 KB |
Partially correct - number of queries: 8536 |
82 |
Partially correct |
86 ms |
208 KB |
Partially correct - number of queries: 8458 |
83 |
Correct |
7 ms |
208 KB |
Output is correct |
84 |
Partially correct |
62 ms |
292 KB |
Partially correct - number of queries: 7126 |
85 |
Partially correct |
85 ms |
208 KB |
Partially correct - number of queries: 8418 |
86 |
Correct |
5 ms |
208 KB |
Output is correct |
87 |
Correct |
3 ms |
336 KB |
Output is correct |
88 |
Correct |
7 ms |
208 KB |
Output is correct |
89 |
Correct |
6 ms |
208 KB |
Output is correct |
90 |
Correct |
6 ms |
208 KB |
Output is correct |
91 |
Correct |
5 ms |
304 KB |
Output is correct |
92 |
Correct |
5 ms |
208 KB |
Output is correct |
93 |
Correct |
8 ms |
208 KB |
Output is correct |
94 |
Correct |
11 ms |
208 KB |
Output is correct |
95 |
Correct |
11 ms |
208 KB |
Output is correct |
96 |
Correct |
13 ms |
208 KB |
Output is correct |
97 |
Correct |
5 ms |
208 KB |
Output is correct |