#include <bits/stdc++.h>
#include "prize.h"
//#include "Lgrader.cpp"
using namespace std;
template<class T, class T2> inline int chkmax(T &x, const T2 &y) { return x < y ? x = y, 1 : 0; }
template<class T, class T2> inline int chkmin(T &x, const T2 &y) { return x > y ? x = y, 1 : 0; }
const int MAXN = (1 << 20);
vector<int> memo[MAXN];
int Q = 0;
bool stop;
bool dummy[MAXN];
vector<int> query(int i)
{
if(!memo[i].empty()) return memo[i];
if(stop || dummy[i]) return vector<int>(2, 1e9);
memo[i] = ask(i), Q++;
if(Q == 10000) assert(false);
return memo[i];
}
int n;
mt19937 mt(42);
int cnt(int l, int r);
int cnt1(int l, int r);
int sum(int x) { return query(x)[0]+query(x)[1];}
int better(int l, int r)
{
return sum(l)>sum(r);
}
int abetter(int l, int r)
{
return sum(l)>=sum(r);
}
int cnt1(int l, int r) { return query(r)[0] - query(l)[0]; }
int cnt(int l, int r) { return query(l)[1] - query(r)[1] - better(l,r); }
bool useless(int l, int r)
{
if(sum(l) == sum(r) && cnt1(l, r) == 0) return true;
//if(query(r)[0] - query(l)[0] == 0) return true;
return false;
}
void rec(int l, int r)
{
if(r < l) return;
int mid = (l + r) >> 1;
if(query(l - 1)[0] + query(l - 1)[1] == 0) stop = 1;
if(query(mid)[0] + query(mid)[1] == 0) stop = 1;
if(query(r + 1)[0] + query(r + 1)[1] == 0) stop = 1;
if(useless(l - 1, r + 1))
{
for(int i = l; i <= r; i++)
memo[i] = query(l - 1);
return;
}
/*
if(cnt() && )
{
for(int i = l; i< mid;i++)dummy[i] = 1;
for(int i = mid+1; i< r+1;i++)dummy[i] = 1; return;
}
*/
if(sum(l - 1) == sum(r + 1) && cnt1(l - 1, r + 1) == 1 && sum(l - 1) > sum(mid))
{
for(int i = l; i <= r; i++)
if(i != mid) dummy[i] = 1;
return;
}
if(cnt(l - 1, mid) > cnt(mid, r + 1))
{
if(useless(l - 1, mid))
for(int i = l; i < mid; i++)
dummy[i] = 1;
else
rec(l, mid - 1);
if(useless(mid, r + 1))
for(int i = mid + 1; i <= r; i++)
dummy[i] = 1;
else
rec(mid + 1, r);
}
else
{
if(useless(mid, r + 1))
for(int i = mid + 1; i <= r; i++)
dummy[i] = 1;
else
rec(mid + 1, r);
if(useless(l - 1, mid))
for(int i = l; i < mid; i++)
dummy[i] = 1;
else
rec(l, mid - 1);
}
}
int find_best(int n)
{
::n = n;
rec(1, n - 2);stop=
1;for(int i = 0; i < n; i++)
if(query(i)[0] + query(i)[1] == 0)
return i;
return -1;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
28 ms |
25064 KB |
Output is correct |
2 |
Correct |
40 ms |
25268 KB |
Output is correct |
3 |
Correct |
33 ms |
25268 KB |
Output is correct |
4 |
Correct |
45 ms |
25292 KB |
Output is correct |
5 |
Correct |
36 ms |
25296 KB |
Output is correct |
6 |
Correct |
29 ms |
25372 KB |
Output is correct |
7 |
Correct |
48 ms |
25372 KB |
Output is correct |
8 |
Correct |
36 ms |
25396 KB |
Output is correct |
9 |
Correct |
38 ms |
25396 KB |
Output is correct |
10 |
Correct |
60 ms |
25396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
30 ms |
25396 KB |
Output is correct |
2 |
Correct |
39 ms |
25396 KB |
Output is correct |
3 |
Correct |
41 ms |
25396 KB |
Output is correct |
4 |
Correct |
49 ms |
25396 KB |
Output is correct |
5 |
Correct |
36 ms |
25396 KB |
Output is correct |
6 |
Correct |
27 ms |
25396 KB |
Output is correct |
7 |
Correct |
40 ms |
25396 KB |
Output is correct |
8 |
Correct |
35 ms |
25396 KB |
Output is correct |
9 |
Correct |
35 ms |
25404 KB |
Output is correct |
10 |
Correct |
57 ms |
25404 KB |
Output is correct |
11 |
Correct |
36 ms |
25404 KB |
Output is correct |
12 |
Correct |
36 ms |
25404 KB |
Output is correct |
13 |
Correct |
62 ms |
25404 KB |
Output is correct |
14 |
Correct |
32 ms |
25404 KB |
Output is correct |
15 |
Correct |
38 ms |
25404 KB |
Output is correct |
16 |
Correct |
47 ms |
25424 KB |
Output is correct |
17 |
Correct |
98 ms |
25424 KB |
Output is correct |
18 |
Correct |
65 ms |
25424 KB |
Output is correct |
19 |
Correct |
91 ms |
25572 KB |
Output is correct |
20 |
Correct |
48 ms |
25572 KB |
Output is correct |
21 |
Correct |
46 ms |
25572 KB |
Output is correct |
22 |
Correct |
47 ms |
25572 KB |
Output is correct |
23 |
Correct |
30 ms |
25572 KB |
Output is correct |
24 |
Correct |
32 ms |
25572 KB |
Output is correct |
25 |
Correct |
59 ms |
25572 KB |
Output is correct |
26 |
Correct |
56 ms |
25572 KB |
Output is correct |
27 |
Correct |
30 ms |
25572 KB |
Output is correct |
28 |
Correct |
71 ms |
25572 KB |
Output is correct |
29 |
Correct |
80 ms |
25572 KB |
Output is correct |
30 |
Correct |
59 ms |
25572 KB |
Output is correct |
31 |
Correct |
74 ms |
25572 KB |
Output is correct |
32 |
Correct |
39 ms |
25572 KB |
Output is correct |
33 |
Correct |
28 ms |
25572 KB |
Output is correct |
34 |
Correct |
37 ms |
25572 KB |
Output is correct |
35 |
Correct |
38 ms |
25572 KB |
Output is correct |
36 |
Correct |
53 ms |
25572 KB |
Output is correct |
37 |
Correct |
36 ms |
25572 KB |
Output is correct |
38 |
Correct |
30 ms |
25572 KB |
Output is correct |
39 |
Correct |
72 ms |
25572 KB |
Output is correct |
40 |
Correct |
52 ms |
25572 KB |
Output is correct |
41 |
Correct |
64 ms |
25572 KB |
Output is correct |
42 |
Correct |
65 ms |
25572 KB |
Output is correct |
43 |
Correct |
44 ms |
25572 KB |
Output is correct |
44 |
Correct |
49 ms |
25572 KB |
Output is correct |
45 |
Correct |
33 ms |
25572 KB |
Output is correct |
46 |
Correct |
97 ms |
25572 KB |
Output is correct |
47 |
Correct |
54 ms |
25572 KB |
Output is correct |
48 |
Correct |
40 ms |
25572 KB |
Output is correct |
49 |
Correct |
57 ms |
25572 KB |
Output is correct |
50 |
Correct |
69 ms |
25572 KB |
Output is correct |
51 |
Correct |
46 ms |
25572 KB |
Output is correct |
52 |
Correct |
94 ms |
25572 KB |
Output is correct |
53 |
Correct |
48 ms |
25572 KB |
Output is correct |
54 |
Correct |
37 ms |
25572 KB |
Output is correct |
55 |
Correct |
94 ms |
25572 KB |
Output is correct |
56 |
Correct |
74 ms |
25572 KB |
Output is correct |
57 |
Correct |
66 ms |
25572 KB |
Output is correct |
58 |
Correct |
82 ms |
25572 KB |
Output is correct |
59 |
Correct |
55 ms |
25572 KB |
Output is correct |
60 |
Correct |
52 ms |
25572 KB |
Output is correct |
61 |
Correct |
43 ms |
25572 KB |
Output is correct |
62 |
Correct |
28 ms |
25572 KB |
Output is correct |
63 |
Correct |
41 ms |
25572 KB |
Output is correct |
64 |
Correct |
39 ms |
25572 KB |
Output is correct |
65 |
Correct |
46 ms |
25572 KB |
Output is correct |
66 |
Correct |
62 ms |
25572 KB |
Output is correct |
67 |
Correct |
41 ms |
25572 KB |
Output is correct |
68 |
Correct |
27 ms |
25572 KB |
Output is correct |
69 |
Correct |
40 ms |
25572 KB |
Output is correct |
70 |
Correct |
45 ms |
25572 KB |
Output is correct |
71 |
Correct |
71 ms |
25572 KB |
Output is correct |
72 |
Correct |
41 ms |
25572 KB |
Output is correct |
73 |
Correct |
92 ms |
25572 KB |
Output is correct |
74 |
Correct |
90 ms |
25572 KB |
Output is correct |
75 |
Correct |
30 ms |
25572 KB |
Output is correct |
76 |
Correct |
92 ms |
25572 KB |
Output is correct |
77 |
Correct |
72 ms |
25572 KB |
Output is correct |
78 |
Correct |
30 ms |
25572 KB |
Output is correct |
79 |
Correct |
49 ms |
25572 KB |
Output is correct |
80 |
Correct |
75 ms |
25572 KB |
Output is correct |
81 |
Correct |
71 ms |
25572 KB |
Output is correct |
82 |
Correct |
74 ms |
25572 KB |
Output is correct |
83 |
Correct |
28 ms |
25572 KB |
Output is correct |
84 |
Correct |
89 ms |
25572 KB |
Output is correct |
85 |
Correct |
87 ms |
25584 KB |
Output is correct |
86 |
Correct |
32 ms |
25584 KB |
Output is correct |
87 |
Correct |
31 ms |
25584 KB |
Output is correct |
88 |
Correct |
30 ms |
25584 KB |
Output is correct |
89 |
Correct |
36 ms |
25584 KB |
Output is correct |
90 |
Correct |
54 ms |
25584 KB |
Output is correct |
91 |
Correct |
33 ms |
25584 KB |
Output is correct |
92 |
Correct |
46 ms |
25584 KB |
Output is correct |
93 |
Correct |
33 ms |
25584 KB |
Output is correct |
94 |
Correct |
45 ms |
25584 KB |
Output is correct |
95 |
Correct |
39 ms |
25584 KB |
Output is correct |
96 |
Correct |
39 ms |
25584 KB |
Output is correct |
97 |
Correct |
63 ms |
25584 KB |
Output is correct |