#include "prize.h"
#include <bits/stdc++.h>
using namespace std;
int m,ball=0,a[200005][2],ans=-1,tag[1000005];
int find(int x)
{
if(a[x][0]==-1)
{
std::vector<int> res = ask(x);
a[x][0]=res[0];
a[x][1]=res[1];
}
return 0;
}
int solve(int s,int e){
//cout<<s<<" "<<e<<endl;
if(s>=e-1)return 0;
if(ans!=-1)return 0;
int ne,ns,c1=1,c2=1;
ne=(s+e)/2,ns=(s+e)/2;
while(ns<e)
{
find(ns);
if(a[ns][0]+a[ns][1]==0)
{
ans=ns;
return 0;
}
if(a[ns][0]+a[ns][1]!=ball)
{
if(a[ns][0]+a[ns][1]>ball)
{
ball=a[ns][0]+a[ns][1];
break;
}
if(a[ns][1]==0)
{
c1=0;
break;
}
ns++;
}
else break;
}
while(s<ne)
{
find(ne);
if(a[ne][0]+a[ne][1]==0)
{
ans=ne;
break;
}
if(a[ne][0]+a[ne][1]!=ball)
{
if(a[ne][0]+a[ne][1]>ball)
{
ball=a[ne][0]+a[ne][1];
break;
}
if(a[ne][0]==0)
{
c2=0;
break;
}
ne--;
}
else break;
}
//cout<<ne<<" "<<ns<<endl;
if(c1==1 && a[ns][1]!=a[e][1])solve(ns,e);
if(c2==1 && a[s][0]!=a[ne][0])solve(s,ne);
}
int find_best(int n) {
for(int i=0;i<n;i++)
{
a[i][0]=-1;
a[i][1]=-1;
}
for(int t = 0; t < 200; t++) {
long long int i=rand();
i%=n;
while(tag[i]==1)
{
i=rand();
i%=n;
}
tag[i]=1;
find(i);
//cout<<a[i][0]<<" "<<a[i][1]<<endl;
if(a[i][0]+a[i][1]==0)
{
ans=i;
break;
}
if(a[i][0] + a[i][1] > ball)
{
m=i;
ball=a[i][0]+a[i][1];
}
}
if(ans!=-1)return ans;
// cout<<m<<endl;
int start=0,end=n-1;
while(true)
{
find(start);
if(a[start][0]+a[start][1]==0)ans=start;
if(a[start][0]+a[start][1]!=ball)
{
if(a[start][0]+a[start][1]>ball)
{
ball=a[start][0]+a[start][1];
break;
}
start++;
}
else break;
}
while(true)
{
find(end);
if(a[end][0]+a[end][1]==0)ans=end;
if(a[end][0]+a[end][1]!=ball)
{
if(a[end][0]+a[end][1]>ball)
{
ball=a[end][0]+a[end][1];
break;
}
end--;
}
else break;
}
if(ans!=-1)return ans;
//cout<<start<<" "<<end<<endl;
solve(start,m);
solve(m,end);
return ans;
}
Compilation message
prize.cpp: In function 'int solve(int, int)':
prize.cpp:75:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
2344 KB |
Output is correct |
2 |
Correct |
4 ms |
2432 KB |
Output is correct |
3 |
Correct |
4 ms |
2424 KB |
Output is correct |
4 |
Correct |
2 ms |
2336 KB |
Output is correct |
5 |
Correct |
3 ms |
2328 KB |
Output is correct |
6 |
Correct |
4 ms |
2336 KB |
Output is correct |
7 |
Correct |
4 ms |
2432 KB |
Output is correct |
8 |
Correct |
4 ms |
2424 KB |
Output is correct |
9 |
Correct |
3 ms |
2432 KB |
Output is correct |
10 |
Correct |
4 ms |
2432 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
2412 KB |
Output is correct |
2 |
Correct |
4 ms |
2424 KB |
Output is correct |
3 |
Correct |
3 ms |
2424 KB |
Output is correct |
4 |
Correct |
3 ms |
2560 KB |
Output is correct |
5 |
Correct |
3 ms |
2336 KB |
Output is correct |
6 |
Correct |
3 ms |
2428 KB |
Output is correct |
7 |
Correct |
4 ms |
2424 KB |
Output is correct |
8 |
Correct |
4 ms |
2432 KB |
Output is correct |
9 |
Correct |
3 ms |
2432 KB |
Output is correct |
10 |
Correct |
5 ms |
2560 KB |
Output is correct |
11 |
Correct |
3 ms |
2424 KB |
Output is correct |
12 |
Correct |
4 ms |
2336 KB |
Output is correct |
13 |
Correct |
4 ms |
2336 KB |
Output is correct |
14 |
Correct |
5 ms |
512 KB |
Output is correct |
15 |
Correct |
16 ms |
2424 KB |
Output is correct |
16 |
Correct |
3 ms |
2304 KB |
Output is correct |
17 |
Correct |
23 ms |
2424 KB |
Output is correct |
18 |
Correct |
22 ms |
2408 KB |
Output is correct |
19 |
Correct |
24 ms |
2432 KB |
Output is correct |
20 |
Correct |
16 ms |
1408 KB |
Output is correct |
21 |
Correct |
7 ms |
2432 KB |
Output is correct |
22 |
Correct |
19 ms |
2424 KB |
Output is correct |
23 |
Correct |
5 ms |
2424 KB |
Output is correct |
24 |
Correct |
6 ms |
2432 KB |
Output is correct |
25 |
Correct |
38 ms |
2424 KB |
Output is correct |
26 |
Correct |
35 ms |
2424 KB |
Output is correct |
27 |
Correct |
5 ms |
2424 KB |
Output is correct |
28 |
Correct |
23 ms |
2428 KB |
Output is correct |
29 |
Correct |
17 ms |
2424 KB |
Output is correct |
30 |
Correct |
21 ms |
2432 KB |
Output is correct |
31 |
Correct |
21 ms |
2432 KB |
Output is correct |
32 |
Correct |
5 ms |
2332 KB |
Output is correct |
33 |
Correct |
1 ms |
256 KB |
Output is correct |
34 |
Correct |
11 ms |
2412 KB |
Output is correct |
35 |
Correct |
5 ms |
2424 KB |
Output is correct |
36 |
Correct |
13 ms |
2424 KB |
Output is correct |
37 |
Correct |
5 ms |
2432 KB |
Output is correct |
38 |
Correct |
5 ms |
2424 KB |
Output is correct |
39 |
Correct |
5 ms |
2424 KB |
Output is correct |
40 |
Correct |
25 ms |
2432 KB |
Output is correct |
41 |
Correct |
36 ms |
2432 KB |
Output is correct |
42 |
Correct |
36 ms |
2432 KB |
Output is correct |
43 |
Correct |
31 ms |
2424 KB |
Output is correct |
44 |
Correct |
6 ms |
2432 KB |
Output is correct |
45 |
Correct |
9 ms |
2424 KB |
Output is correct |
46 |
Correct |
27 ms |
2424 KB |
Output is correct |
47 |
Correct |
5 ms |
2432 KB |
Output is correct |
48 |
Correct |
32 ms |
2432 KB |
Output is correct |
49 |
Correct |
18 ms |
2424 KB |
Output is correct |
50 |
Correct |
21 ms |
2424 KB |
Output is correct |
51 |
Correct |
8 ms |
2424 KB |
Output is correct |
52 |
Correct |
20 ms |
2432 KB |
Output is correct |
53 |
Correct |
5 ms |
2432 KB |
Output is correct |
54 |
Correct |
6 ms |
2424 KB |
Output is correct |
55 |
Correct |
21 ms |
2424 KB |
Output is correct |
56 |
Correct |
22 ms |
2424 KB |
Output is correct |
57 |
Correct |
30 ms |
2432 KB |
Output is correct |
58 |
Correct |
30 ms |
2424 KB |
Output is correct |
59 |
Correct |
38 ms |
2408 KB |
Output is correct |
60 |
Correct |
31 ms |
2432 KB |
Output is correct |
61 |
Correct |
4 ms |
2412 KB |
Output is correct |
62 |
Correct |
4 ms |
2424 KB |
Output is correct |
63 |
Correct |
4 ms |
2432 KB |
Output is correct |
64 |
Correct |
4 ms |
2424 KB |
Output is correct |
65 |
Correct |
3 ms |
2432 KB |
Output is correct |
66 |
Correct |
7 ms |
2424 KB |
Output is correct |
67 |
Correct |
8 ms |
2424 KB |
Output is correct |
68 |
Correct |
6 ms |
2432 KB |
Output is correct |
69 |
Correct |
8 ms |
2432 KB |
Output is correct |
70 |
Correct |
6 ms |
2432 KB |
Output is correct |
71 |
Correct |
39 ms |
2432 KB |
Output is correct |
72 |
Correct |
8 ms |
2432 KB |
Output is correct |
73 |
Correct |
55 ms |
2432 KB |
Output is correct |
74 |
Correct |
52 ms |
2432 KB |
Output is correct |
75 |
Correct |
4 ms |
2432 KB |
Output is correct |
76 |
Correct |
51 ms |
2432 KB |
Output is correct |
77 |
Correct |
55 ms |
2432 KB |
Output is correct |
78 |
Correct |
8 ms |
2432 KB |
Output is correct |
79 |
Correct |
21 ms |
2432 KB |
Output is correct |
80 |
Correct |
45 ms |
2356 KB |
Output is correct |
81 |
Correct |
54 ms |
2452 KB |
Output is correct |
82 |
Correct |
54 ms |
2432 KB |
Output is correct |
83 |
Correct |
6 ms |
2432 KB |
Output is correct |
84 |
Correct |
35 ms |
2460 KB |
Output is correct |
85 |
Correct |
48 ms |
2432 KB |
Output is correct |
86 |
Correct |
15 ms |
2432 KB |
Output is correct |
87 |
Correct |
7 ms |
2432 KB |
Output is correct |
88 |
Correct |
20 ms |
2432 KB |
Output is correct |
89 |
Correct |
6 ms |
2432 KB |
Output is correct |
90 |
Correct |
4 ms |
2432 KB |
Output is correct |
91 |
Correct |
14 ms |
2432 KB |
Output is correct |
92 |
Correct |
4 ms |
2340 KB |
Output is correct |
93 |
Correct |
11 ms |
2432 KB |
Output is correct |
94 |
Correct |
9 ms |
2432 KB |
Output is correct |
95 |
Correct |
11 ms |
2432 KB |
Output is correct |
96 |
Correct |
6 ms |
2432 KB |
Output is correct |
97 |
Correct |
4 ms |
2432 KB |
Output is correct |