#ifndef Chai
#include "prize.h"
#endif
#ifdef Chai
#include "grader.cpp"
#endif
#include <bits/stdc++.h>
using namespace std;
#define X first
#define Y second
#define pb push_back
#define mp make_pair
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector< ii > vii;
typedef long long LL;
int lim = 472;
vi res[200005];
int best;
int solve(int a, int b, int five, int fivestoleft, int fivestoright)
{
if(five == 0)
{
for(int i = b; i>= a; i--)
{
res[i] = ask(i);
if(res[i][0]+res[i][1] == 0) return i;
}
return -1;
}
if(five == b-a+1) return -1;
if(a> b) return -1;
int M = (a+b)/2;
int locate = -1;
res[M] = ask(M);
if(res[M][0]+res[M][1] == 0) return M;
if(res[M][0]+res[M][1] == best) locate = M;
int zone_left, zone_right;
zone_left = zone_right = M;
for(int i = 1; locate==-1; i++)
{
res[M-i] = ask(M-i);
if(res[M-i][0]+res[M-i][1] == 0) return M-i;
if(res[M-i][0]+res[M-i][1] == best)
{
locate = M-i;
break;
}
zone_left = M-i;
res[M+i] = ask(M+i);
if(res[M+i][0]+res[M+i][1] == 0) return M+i;
if(res[M+i][0]+res[M+i][1] == best)
{
locate = M+i;
break;
}
zone_right = M+i;
}
assert(locate != -1);
int ans1;
int Left = res[locate][0], Right = res[locate][1];
if(locate> M)
{
int szL = zone_left-a;
int szR = b-locate;
int fL = szL-(Left-fivestoleft);
int fR = szR-(Right-fivestoright);
int nfL = szL-fL;
int nfR = szR-fR;
ans1 = solve(a, zone_left-1, fL, fivestoleft, nfR+fivestoright);
if(ans1 != -1) return ans1;
return solve(locate+1, b, fR, fivestoleft+nfL, fivestoright);
}
else
{
int szL = locate-a;
int szR = b-zone_right;
int fL = szL-(Left-fivestoleft);
int fR = szR-(Right-fivestoright);
int nfL = szL-fL;
int nfR = szR-fR;
ans1 = solve(a, locate-1, fL, fivestoleft, nfR+fivestoright);
if(ans1 != -1) return ans1;
return solve(zone_right+1, b, fR, fivestoleft+nfL, fivestoright);
}
}
int find_best(int n)
{
best = 0;
int five = 0;
for(int i = 0; i< n; i++) res[i].assign(2, -1);
for(int i = 0; i< lim; i++)
{
vi x = ask(i);
res[i] = x;
if(x[0]+x[1] == 0) return i;
best = max(best, x[0]+x[1]);
}
int left_border = -1, right_border = -1;
for(int i = 0; i< lim; i++)
{
if(res[i][0]+res[i][1] == best)
{
left_border = i;
five++;
}
}
int tot5 = n-best;
int k = solve(left_border+1, n-1, tot5-five, left_border+1-five, 0);
return k;
}
/*
8
3 2 3 1 3 3 2 3
*/
Compilation message
prize.cpp: In function 'int find_best(int)':
prize.cpp:99:24: warning: unused variable 'right_border' [-Wunused-variable]
int left_border = -1, right_border = -1;
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
12916 KB |
Output is correct |
2 |
Correct |
14 ms |
12916 KB |
Output is correct |
3 |
Correct |
13 ms |
12916 KB |
Output is correct |
4 |
Correct |
6 ms |
12916 KB |
Output is correct |
5 |
Correct |
6 ms |
12916 KB |
Output is correct |
6 |
Correct |
8 ms |
12916 KB |
Output is correct |
7 |
Correct |
14 ms |
12916 KB |
Output is correct |
8 |
Correct |
6 ms |
12916 KB |
Output is correct |
9 |
Correct |
10 ms |
12916 KB |
Output is correct |
10 |
Correct |
6 ms |
12916 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
12916 KB |
Output is correct |
2 |
Correct |
13 ms |
12916 KB |
Output is correct |
3 |
Correct |
7 ms |
12916 KB |
Output is correct |
4 |
Correct |
5 ms |
12916 KB |
Output is correct |
5 |
Correct |
13 ms |
12916 KB |
Output is correct |
6 |
Correct |
10 ms |
12916 KB |
Output is correct |
7 |
Correct |
16 ms |
12916 KB |
Output is correct |
8 |
Correct |
5 ms |
12916 KB |
Output is correct |
9 |
Correct |
16 ms |
12916 KB |
Output is correct |
10 |
Correct |
10 ms |
12916 KB |
Output is correct |
11 |
Correct |
10 ms |
12916 KB |
Output is correct |
12 |
Correct |
14 ms |
12916 KB |
Output is correct |
13 |
Correct |
11 ms |
12916 KB |
Output is correct |
14 |
Correct |
0 ms |
7372 KB |
Output is correct |
15 |
Correct |
23 ms |
12916 KB |
Output is correct |
16 |
Correct |
18 ms |
12916 KB |
Output is correct |
17 |
Correct |
3 ms |
12916 KB |
Output is correct |
18 |
Partially correct |
18 ms |
12916 KB |
Partially correct - number of queries: 5385 |
19 |
Correct |
7 ms |
12916 KB |
Output is correct |
20 |
Correct |
8 ms |
9880 KB |
Output is correct |
21 |
Correct |
20 ms |
12916 KB |
Output is correct |
22 |
Correct |
14 ms |
12916 KB |
Output is correct |
23 |
Correct |
12 ms |
12916 KB |
Output is correct |
24 |
Correct |
11 ms |
12916 KB |
Output is correct |
25 |
Correct |
17 ms |
12916 KB |
Output is correct |
26 |
Correct |
32 ms |
12916 KB |
Output is correct |
27 |
Correct |
10 ms |
12916 KB |
Output is correct |
28 |
Correct |
8 ms |
12916 KB |
Output is correct |
29 |
Correct |
22 ms |
12916 KB |
Output is correct |
30 |
Partially correct |
22 ms |
12916 KB |
Partially correct - number of queries: 5351 |
31 |
Correct |
13 ms |
12916 KB |
Output is correct |
32 |
Correct |
5 ms |
12916 KB |
Output is correct |
33 |
Correct |
2 ms |
6712 KB |
Output is correct |
34 |
Correct |
15 ms |
12916 KB |
Output is correct |
35 |
Correct |
8 ms |
12916 KB |
Output is correct |
36 |
Correct |
16 ms |
12916 KB |
Output is correct |
37 |
Correct |
6 ms |
12916 KB |
Output is correct |
38 |
Correct |
13 ms |
12916 KB |
Output is correct |
39 |
Correct |
13 ms |
12916 KB |
Output is correct |
40 |
Correct |
25 ms |
12916 KB |
Output is correct |
41 |
Correct |
7 ms |
12916 KB |
Output is correct |
42 |
Correct |
16 ms |
12916 KB |
Output is correct |
43 |
Correct |
28 ms |
12916 KB |
Output is correct |
44 |
Correct |
11 ms |
12916 KB |
Output is correct |
45 |
Correct |
13 ms |
12916 KB |
Output is correct |
46 |
Correct |
14 ms |
12916 KB |
Output is correct |
47 |
Correct |
16 ms |
12916 KB |
Output is correct |
48 |
Correct |
12 ms |
12916 KB |
Output is correct |
49 |
Correct |
14 ms |
12916 KB |
Output is correct |
50 |
Partially correct |
17 ms |
12916 KB |
Partially correct - number of queries: 5381 |
51 |
Correct |
16 ms |
12916 KB |
Output is correct |
52 |
Correct |
9 ms |
12916 KB |
Output is correct |
53 |
Correct |
22 ms |
12916 KB |
Output is correct |
54 |
Correct |
13 ms |
12916 KB |
Output is correct |
55 |
Correct |
16 ms |
12916 KB |
Output is correct |
56 |
Partially correct |
22 ms |
12916 KB |
Partially correct - number of queries: 5391 |
57 |
Correct |
23 ms |
12916 KB |
Output is correct |
58 |
Correct |
15 ms |
12916 KB |
Output is correct |
59 |
Correct |
30 ms |
12916 KB |
Output is correct |
60 |
Correct |
17 ms |
12916 KB |
Output is correct |
61 |
Correct |
10 ms |
12916 KB |
Output is correct |
62 |
Correct |
13 ms |
12916 KB |
Output is correct |
63 |
Correct |
14 ms |
12916 KB |
Output is correct |
64 |
Correct |
21 ms |
12916 KB |
Output is correct |
65 |
Correct |
16 ms |
12916 KB |
Output is correct |
66 |
Correct |
17 ms |
12916 KB |
Output is correct |
67 |
Correct |
7 ms |
12916 KB |
Output is correct |
68 |
Correct |
6 ms |
12916 KB |
Output is correct |
69 |
Correct |
12 ms |
12916 KB |
Output is correct |
70 |
Correct |
9 ms |
12916 KB |
Output is correct |
71 |
Partially correct |
18 ms |
12916 KB |
Partially correct - number of queries: 5231 |
72 |
Correct |
13 ms |
12916 KB |
Output is correct |
73 |
Partially correct |
7 ms |
12916 KB |
Partially correct - number of queries: 5168 |
74 |
Partially correct |
16 ms |
12916 KB |
Partially correct - number of queries: 5195 |
75 |
Correct |
14 ms |
12916 KB |
Output is correct |
76 |
Correct |
23 ms |
12916 KB |
Output is correct |
77 |
Partially correct |
21 ms |
12916 KB |
Partially correct - number of queries: 5392 |
78 |
Correct |
12 ms |
12916 KB |
Output is correct |
79 |
Correct |
15 ms |
12916 KB |
Output is correct |
80 |
Partially correct |
21 ms |
12916 KB |
Partially correct - number of queries: 5411 |
81 |
Partially correct |
29 ms |
12916 KB |
Partially correct - number of queries: 5401 |
82 |
Partially correct |
23 ms |
12916 KB |
Partially correct - number of queries: 5374 |
83 |
Correct |
13 ms |
12916 KB |
Output is correct |
84 |
Correct |
20 ms |
12916 KB |
Output is correct |
85 |
Partially correct |
16 ms |
12916 KB |
Partially correct - number of queries: 5404 |
86 |
Correct |
13 ms |
12916 KB |
Output is correct |
87 |
Correct |
9 ms |
12916 KB |
Output is correct |
88 |
Correct |
18 ms |
12916 KB |
Output is correct |
89 |
Correct |
7 ms |
12916 KB |
Output is correct |
90 |
Correct |
17 ms |
12916 KB |
Output is correct |
91 |
Correct |
17 ms |
12916 KB |
Output is correct |
92 |
Correct |
4 ms |
12916 KB |
Output is correct |
93 |
Correct |
17 ms |
12916 KB |
Output is correct |
94 |
Correct |
16 ms |
12916 KB |
Output is correct |
95 |
Correct |
14 ms |
12916 KB |
Output is correct |
96 |
Correct |
9 ms |
12916 KB |
Output is correct |
97 |
Correct |
3 ms |
12916 KB |
Output is correct |