#include "prize.h"
#include <bits/stdc++.h>
using namespace std;
int mx = 0;
int ans = -1;
vector<int> pos;
void search(int ll, int lr, int rl, int rr, int cl, int cr, int c);
void search(int L, int R, int cl, int cr, int c){
if (c == 0) return;
//printf("searching %d %d %d %d %d\n",L,R,cl,cr,c);
if (L == R){
//printf("add pos %d\n",L);
//printf("check: %d\n",g[L]);
pos.push_back(L);
return;
}
if (L > R) return;
int mid = (L+R)/2;
//printf("mid %d\n",mid);
search(L, mid, mid+1, R, cl, cr, c);
return;
}
void search(int ll, int lr, int rl, int rr, int cl, int cr, int c){
if (c == 0) return;
//printf("search <%d,%d><%d,%d>, <%d,%d>, %d\n",ll,lr,rl,rr,cl,cr,c);
if (ll == rr){
search(ll, rr, cl, cr, c);
return;
}
int CL, CR;
int q = (rr-rl)>(lr-ll)?rl:lr;
assert(q >= 0);
vector<int> p = ask(q);
CL = p[0], CR = p[1];
//printf("queried %d, got (%d,%d)\n",q,CL,CR);
if (CL + CR != mx){ /// is special
//printf("add pos %d\n",q);
// printf("check: %d\n",g[q]);
pos.push_back(q);
if (q == lr){
if (ll <= lr-1) search(ll, lr-1, rl, rr, cl, cr, c-1);
else search(rl, rr, cl+1, cr, c-1);
}
else if (q == rl){
if (rl+1 <= rr) search(ll, lr, rl+1, rr, cl, cr, c-1);
else search(ll, lr, cl, cr+1, c-1);
}
return;
}
CR -= cr;
CL -= cl;
if (q == lr){
if (ll <= lr-1) search(ll, lr-1,cl,CR+cr,CL);
search(rl, rr,CL+cl,cr,CR);
}
else{
search(ll, lr,cl,CR+cr,CL);
if (rl+1 <= rr) search(rl+1, rr,CL+cl,cr,CR);
}
}
int find_best(int n) {
for (int i = 0; i < min(n,474); i++){
vector<int> p = ask(i);
//if (p[0] == 0 && p[1] == 0) return i;
mx = max(mx,p[0]+p[1]);
}
int L, R;
L = 0, R = n-1;
int mid = (L+R)/2;
search(L, mid, mid+1, R, 0, 0, mx);
// printf("%d , %d\n",pos.size(),nonmax);
for (auto x : pos){
vector<int> p = ask(x);
if (p[0] + p[1] == 0) return x;
}
assert(false);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
368 KB |
Output is correct |
2 |
Correct |
7 ms |
256 KB |
Output is correct |
3 |
Correct |
6 ms |
256 KB |
Output is correct |
4 |
Correct |
5 ms |
256 KB |
Output is correct |
5 |
Correct |
3 ms |
256 KB |
Output is correct |
6 |
Correct |
4 ms |
256 KB |
Output is correct |
7 |
Correct |
9 ms |
256 KB |
Output is correct |
8 |
Correct |
5 ms |
256 KB |
Output is correct |
9 |
Correct |
4 ms |
256 KB |
Output is correct |
10 |
Correct |
6 ms |
256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
288 KB |
Output is correct |
2 |
Correct |
6 ms |
256 KB |
Output is correct |
3 |
Correct |
5 ms |
256 KB |
Output is correct |
4 |
Correct |
7 ms |
256 KB |
Output is correct |
5 |
Correct |
7 ms |
288 KB |
Output is correct |
6 |
Correct |
5 ms |
256 KB |
Output is correct |
7 |
Correct |
5 ms |
256 KB |
Output is correct |
8 |
Correct |
5 ms |
256 KB |
Output is correct |
9 |
Correct |
5 ms |
256 KB |
Output is correct |
10 |
Correct |
8 ms |
256 KB |
Output is correct |
11 |
Correct |
10 ms |
288 KB |
Output is correct |
12 |
Correct |
11 ms |
384 KB |
Output is correct |
13 |
Correct |
10 ms |
256 KB |
Output is correct |
14 |
Correct |
15 ms |
480 KB |
Output is correct |
15 |
Correct |
44 ms |
256 KB |
Output is correct |
16 |
Correct |
54 ms |
256 KB |
Output is correct |
17 |
Correct |
47 ms |
256 KB |
Output is correct |
18 |
Correct |
54 ms |
256 KB |
Output is correct |
19 |
Correct |
50 ms |
256 KB |
Output is correct |
20 |
Correct |
31 ms |
256 KB |
Output is correct |
21 |
Correct |
48 ms |
256 KB |
Output is correct |
22 |
Correct |
46 ms |
256 KB |
Output is correct |
23 |
Correct |
8 ms |
256 KB |
Output is correct |
24 |
Correct |
7 ms |
256 KB |
Output is correct |
25 |
Correct |
39 ms |
256 KB |
Output is correct |
26 |
Correct |
51 ms |
256 KB |
Output is correct |
27 |
Correct |
7 ms |
256 KB |
Output is correct |
28 |
Correct |
54 ms |
288 KB |
Output is correct |
29 |
Correct |
51 ms |
364 KB |
Output is correct |
30 |
Correct |
64 ms |
364 KB |
Output is correct |
31 |
Correct |
34 ms |
256 KB |
Output is correct |
32 |
Correct |
11 ms |
384 KB |
Output is correct |
33 |
Correct |
1 ms |
256 KB |
Output is correct |
34 |
Correct |
46 ms |
256 KB |
Output is correct |
35 |
Correct |
6 ms |
256 KB |
Output is correct |
36 |
Correct |
38 ms |
256 KB |
Output is correct |
37 |
Correct |
11 ms |
256 KB |
Output is correct |
38 |
Correct |
7 ms |
256 KB |
Output is correct |
39 |
Correct |
37 ms |
256 KB |
Output is correct |
40 |
Correct |
44 ms |
256 KB |
Output is correct |
41 |
Correct |
50 ms |
256 KB |
Output is correct |
42 |
Correct |
57 ms |
256 KB |
Output is correct |
43 |
Correct |
32 ms |
256 KB |
Output is correct |
44 |
Correct |
60 ms |
256 KB |
Output is correct |
45 |
Correct |
37 ms |
256 KB |
Output is correct |
46 |
Correct |
37 ms |
256 KB |
Output is correct |
47 |
Correct |
51 ms |
256 KB |
Output is correct |
48 |
Correct |
61 ms |
256 KB |
Output is correct |
49 |
Correct |
52 ms |
256 KB |
Output is correct |
50 |
Correct |
72 ms |
256 KB |
Output is correct |
51 |
Correct |
36 ms |
256 KB |
Output is correct |
52 |
Correct |
36 ms |
256 KB |
Output is correct |
53 |
Correct |
10 ms |
256 KB |
Output is correct |
54 |
Correct |
40 ms |
256 KB |
Output is correct |
55 |
Correct |
47 ms |
256 KB |
Output is correct |
56 |
Correct |
49 ms |
376 KB |
Output is correct |
57 |
Correct |
45 ms |
256 KB |
Output is correct |
58 |
Correct |
45 ms |
256 KB |
Output is correct |
59 |
Correct |
43 ms |
256 KB |
Output is correct |
60 |
Correct |
38 ms |
256 KB |
Output is correct |
61 |
Correct |
5 ms |
256 KB |
Output is correct |
62 |
Correct |
5 ms |
256 KB |
Output is correct |
63 |
Correct |
7 ms |
256 KB |
Output is correct |
64 |
Correct |
4 ms |
288 KB |
Output is correct |
65 |
Correct |
6 ms |
256 KB |
Output is correct |
66 |
Correct |
13 ms |
384 KB |
Output is correct |
67 |
Correct |
11 ms |
384 KB |
Output is correct |
68 |
Correct |
12 ms |
384 KB |
Output is correct |
69 |
Correct |
13 ms |
384 KB |
Output is correct |
70 |
Correct |
9 ms |
512 KB |
Output is correct |
71 |
Partially correct |
55 ms |
256 KB |
Partially correct - number of queries: 5233 |
72 |
Correct |
10 ms |
256 KB |
Output is correct |
73 |
Partially correct |
48 ms |
256 KB |
Partially correct - number of queries: 5170 |
74 |
Partially correct |
41 ms |
256 KB |
Partially correct - number of queries: 5197 |
75 |
Correct |
5 ms |
256 KB |
Output is correct |
76 |
Correct |
41 ms |
384 KB |
Output is correct |
77 |
Correct |
41 ms |
256 KB |
Output is correct |
78 |
Correct |
9 ms |
256 KB |
Output is correct |
79 |
Correct |
31 ms |
256 KB |
Output is correct |
80 |
Correct |
49 ms |
256 KB |
Output is correct |
81 |
Correct |
33 ms |
256 KB |
Output is correct |
82 |
Correct |
25 ms |
368 KB |
Output is correct |
83 |
Correct |
6 ms |
256 KB |
Output is correct |
84 |
Correct |
41 ms |
256 KB |
Output is correct |
85 |
Correct |
26 ms |
376 KB |
Output is correct |
86 |
Correct |
14 ms |
384 KB |
Output is correct |
87 |
Correct |
3 ms |
376 KB |
Output is correct |
88 |
Correct |
15 ms |
372 KB |
Output is correct |
89 |
Correct |
11 ms |
384 KB |
Output is correct |
90 |
Correct |
6 ms |
256 KB |
Output is correct |
91 |
Correct |
10 ms |
384 KB |
Output is correct |
92 |
Correct |
12 ms |
384 KB |
Output is correct |
93 |
Correct |
15 ms |
384 KB |
Output is correct |
94 |
Correct |
14 ms |
384 KB |
Output is correct |
95 |
Correct |
17 ms |
416 KB |
Output is correct |
96 |
Correct |
14 ms |
384 KB |
Output is correct |
97 |
Correct |
13 ms |
384 KB |
Output is correct |