#include "prize.h"
#include<bits/stdc++.h>
#define F first
#define S second
using namespace std;
pair<int,int>p,p1;
vector<int>v,v1;
int A[200005];
int ANS[200005];
int ANS1[200005];
int ans=-1;
void go(int L,int R)
{
if(ans>=0)return ;
if(L>R)return;
if(L==R)
{
v.clear();
if(ANS[L]>=0)
v.push_back(ANS[L]),v.push_back(ANS1[L]);
else
v=ask(L),ANS[L]=v[0],ANS1[L]=v[1];
A[v[0]]=min(A[v[0]],L);
if(v[0]+v[1]==0)
{
ans=L;
return;
}
return;
}
else
{
v1.clear();
if(ANS[R]>=0)
v1.push_back(ANS[R]),v1.push_back(ANS1[R]);
else
v1=ask(R),ANS[R]=v1[0],ANS1[R]=v1[1];
A[v1[0]]=min(A[v1[0]],R);
if(v1[0]+v1[1]==0)
{
ans=R;
return;
}
v.clear();
if(ANS[L]>=0)
v.push_back(ANS[L]),v.push_back(ANS1[L]);
else
v=ask(L),ANS[L]=v[0],ANS1[L]=v[1];
A[v[0]]=min(A[v[0]],L);
if(v[0]+v[1]==0)
{
ans=L;
return;
}
if(v[0]==v1[0] || v[1]==v1[1])return;
int mid=(L+R)/2;
if(ans==-1)
go(L,mid);
if(ans==-1)
go(mid+1,R);
}
}
int find_best(int n) {
for(int i=0;i<n;i++)
ANS[i]=ANS1[i]=-1;
if(n==1)
return 0;
for(int i=0;i<n;i++)
A[i]=1e9;
int mid=(n-1)/2;
go(0,mid);
if(ans==-1)
go(mid+1,n-1);
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
2552 KB |
Output is correct |
2 |
Correct |
4 ms |
2756 KB |
Output is correct |
3 |
Correct |
4 ms |
2932 KB |
Output is correct |
4 |
Correct |
4 ms |
2932 KB |
Output is correct |
5 |
Correct |
4 ms |
2932 KB |
Output is correct |
6 |
Correct |
4 ms |
2932 KB |
Output is correct |
7 |
Correct |
4 ms |
2932 KB |
Output is correct |
8 |
Correct |
4 ms |
2932 KB |
Output is correct |
9 |
Correct |
4 ms |
2932 KB |
Output is correct |
10 |
Correct |
4 ms |
2932 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
2932 KB |
Output is correct |
2 |
Correct |
5 ms |
2932 KB |
Output is correct |
3 |
Correct |
4 ms |
2932 KB |
Output is correct |
4 |
Correct |
4 ms |
2932 KB |
Output is correct |
5 |
Correct |
4 ms |
2976 KB |
Output is correct |
6 |
Correct |
4 ms |
2976 KB |
Output is correct |
7 |
Correct |
4 ms |
2976 KB |
Output is correct |
8 |
Correct |
4 ms |
2976 KB |
Output is correct |
9 |
Correct |
4 ms |
2976 KB |
Output is correct |
10 |
Correct |
4 ms |
2976 KB |
Output is correct |
11 |
Correct |
6 ms |
2976 KB |
Output is correct |
12 |
Correct |
4 ms |
2976 KB |
Output is correct |
13 |
Correct |
7 ms |
2976 KB |
Output is correct |
14 |
Correct |
4 ms |
2976 KB |
Output is correct |
15 |
Correct |
8 ms |
2976 KB |
Output is correct |
16 |
Partially correct |
30 ms |
2976 KB |
Partially correct - number of queries: 6730 |
17 |
Correct |
4 ms |
2976 KB |
Output is correct |
18 |
Partially correct |
59 ms |
2976 KB |
Partially correct - number of queries: 8129 |
19 |
Correct |
5 ms |
2976 KB |
Output is correct |
20 |
Correct |
15 ms |
2976 KB |
Output is correct |
21 |
Correct |
28 ms |
2976 KB |
Output is correct |
22 |
Correct |
7 ms |
2976 KB |
Output is correct |
23 |
Correct |
4 ms |
2976 KB |
Output is correct |
24 |
Correct |
4 ms |
2976 KB |
Output is correct |
25 |
Correct |
19 ms |
3004 KB |
Output is correct |
26 |
Correct |
30 ms |
3004 KB |
Output is correct |
27 |
Correct |
4 ms |
3004 KB |
Output is correct |
28 |
Partially correct |
47 ms |
3004 KB |
Partially correct - number of queries: 6947 |
29 |
Partially correct |
25 ms |
3004 KB |
Partially correct - number of queries: 5414 |
30 |
Partially correct |
54 ms |
3004 KB |
Partially correct - number of queries: 8066 |
31 |
Correct |
4 ms |
3004 KB |
Output is correct |
32 |
Correct |
7 ms |
3004 KB |
Output is correct |
33 |
Correct |
2 ms |
3004 KB |
Output is correct |
34 |
Correct |
21 ms |
3004 KB |
Output is correct |
35 |
Correct |
6 ms |
3004 KB |
Output is correct |
36 |
Correct |
15 ms |
3004 KB |
Output is correct |
37 |
Correct |
4 ms |
3004 KB |
Output is correct |
38 |
Correct |
4 ms |
3004 KB |
Output is correct |
39 |
Correct |
28 ms |
3004 KB |
Output is correct |
40 |
Partially correct |
46 ms |
3004 KB |
Partially correct - number of queries: 7040 |
41 |
Correct |
31 ms |
3004 KB |
Output is correct |
42 |
Correct |
23 ms |
3004 KB |
Output is correct |
43 |
Correct |
30 ms |
3004 KB |
Output is correct |
44 |
Correct |
17 ms |
3004 KB |
Output is correct |
45 |
Correct |
13 ms |
3004 KB |
Output is correct |
46 |
Correct |
4 ms |
3004 KB |
Output is correct |
47 |
Correct |
26 ms |
3004 KB |
Output is correct |
48 |
Partially correct |
33 ms |
3004 KB |
Partially correct - number of queries: 5785 |
49 |
Correct |
8 ms |
3004 KB |
Output is correct |
50 |
Partially correct |
56 ms |
3004 KB |
Partially correct - number of queries: 8117 |
51 |
Correct |
26 ms |
3004 KB |
Output is correct |
52 |
Correct |
4 ms |
3004 KB |
Output is correct |
53 |
Correct |
5 ms |
3004 KB |
Output is correct |
54 |
Correct |
24 ms |
3004 KB |
Output is correct |
55 |
Correct |
4 ms |
3004 KB |
Output is correct |
56 |
Partially correct |
55 ms |
3004 KB |
Partially correct - number of queries: 8124 |
57 |
Partially correct |
33 ms |
3004 KB |
Partially correct - number of queries: 5705 |
58 |
Partially correct |
42 ms |
3004 KB |
Partially correct - number of queries: 5802 |
59 |
Correct |
36 ms |
3004 KB |
Output is correct |
60 |
Correct |
29 ms |
3004 KB |
Output is correct |
61 |
Correct |
5 ms |
3004 KB |
Output is correct |
62 |
Correct |
4 ms |
3004 KB |
Output is correct |
63 |
Correct |
6 ms |
3004 KB |
Output is correct |
64 |
Correct |
5 ms |
3004 KB |
Output is correct |
65 |
Correct |
4 ms |
3004 KB |
Output is correct |
66 |
Correct |
4 ms |
3004 KB |
Output is correct |
67 |
Correct |
4 ms |
3004 KB |
Output is correct |
68 |
Correct |
4 ms |
3004 KB |
Output is correct |
69 |
Correct |
4 ms |
3004 KB |
Output is correct |
70 |
Correct |
4 ms |
3004 KB |
Output is correct |
71 |
Partially correct |
57 ms |
3004 KB |
Partially correct - number of queries: 8104 |
72 |
Correct |
9 ms |
3004 KB |
Output is correct |
73 |
Partially correct |
52 ms |
3004 KB |
Partially correct - number of queries: 7999 |
74 |
Partially correct |
47 ms |
3004 KB |
Partially correct - number of queries: 8044 |
75 |
Correct |
6 ms |
3004 KB |
Output is correct |
76 |
Partially correct |
50 ms |
3004 KB |
Partially correct - number of queries: 7024 |
77 |
Partially correct |
61 ms |
3004 KB |
Partially correct - number of queries: 8106 |
78 |
Correct |
7 ms |
3004 KB |
Output is correct |
79 |
Correct |
28 ms |
3004 KB |
Output is correct |
80 |
Partially correct |
54 ms |
3004 KB |
Partially correct - number of queries: 8111 |
81 |
Partially correct |
60 ms |
3004 KB |
Partially correct - number of queries: 8109 |
82 |
Partially correct |
56 ms |
3004 KB |
Partially correct - number of queries: 8044 |
83 |
Correct |
5 ms |
3004 KB |
Output is correct |
84 |
Partially correct |
40 ms |
3004 KB |
Partially correct - number of queries: 6782 |
85 |
Partially correct |
36 ms |
3004 KB |
Partially correct - number of queries: 8113 |
86 |
Correct |
13 ms |
3004 KB |
Output is correct |
87 |
Correct |
6 ms |
3004 KB |
Output is correct |
88 |
Correct |
17 ms |
3004 KB |
Output is correct |
89 |
Correct |
11 ms |
3004 KB |
Output is correct |
90 |
Correct |
5 ms |
3004 KB |
Output is correct |
91 |
Correct |
7 ms |
3004 KB |
Output is correct |
92 |
Correct |
4 ms |
3004 KB |
Output is correct |
93 |
Correct |
8 ms |
3004 KB |
Output is correct |
94 |
Correct |
8 ms |
3004 KB |
Output is correct |
95 |
Correct |
9 ms |
3004 KB |
Output is correct |
96 |
Correct |
8 ms |
3004 KB |
Output is correct |
97 |
Correct |
5 ms |
3004 KB |
Output is correct |