#include <iostream>
#include <stdio.h>
#include <math.h>
#include <assert.h>
#include "prize.h"
using namespace std;
int all[200005];
int l[200005],r[200005];
int ans=0;
int F(int L,int R)
{
//printf("%d %d\n",L,R);
vector < int > t;
int x;
if(l[(L+R)/2]==-1)
{
ans++;
assert(ans<=10000);
t=ask((L+R)/2);
l[(L+R)/2]=t[0];
r[(L+R)/2]=t[1];
}
if(l[R]==-1)
{
ans++;
assert(ans<=10000);
t=ask(R);
l[R]=t[0];
r[R]=t[1];
}
if(l[L]==-1)
{
ans++;
assert(ans<=10000);
t=ask(L);
l[L]=t[0];
r[L]=t[1];
}
if(l[L]==0&&r[L]==0) return L;
if(l[R]==0&&r[R]==0) return R;
if(l[(L+R)/2]==0&&r[(L+R)/2]==0) return (L+R)/2;
if(L==R)
{
if(l[L]||r[L]) return -1;
return L;
}
else if(L+1==R)
{
if(l[L]||r[L])
{
if(l[R]||r[R]) return -1;
return R;
}
return L;
}
else
{
//printf("%d %d %d %d %d %d\n",l[L],r[L],l[(L+R)/2],r)
if(r[R]==r[(L+R)/2]) return F(L,(L+R)/2);
else if(l[L]==l[(L+R)/2]) return F((L+R)/2+1,R);
else
{
x=F((L+R)/2+1,R);
if(x!=-1) return x;
return F(L,(L+R)/2);
}
}
}
int find_best(int n)
{
vector < int > t;
int i,j,all=0;
for(i=0;i<n;i++) l[i]=r[i]=-1;
ans++;
assert(ans<=10000);
t=ask(0);
l[0]=t[0];
r[0]=t[1];
ans++;
assert(ans<=10000);
t=ask(n-1);
l[n-1]=t[0];
r[n-1]=t[1];
return F(0,n-1);
}
Compilation message
prize.cpp: In function 'int find_best(int)':
prize.cpp:75:11: warning: unused variable 'j' [-Wunused-variable]
int i,j,all=0;
^
prize.cpp:75:13: warning: unused variable 'all' [-Wunused-variable]
int i,j,all=0;
^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
1784 KB |
Output is correct |
2 |
Correct |
4 ms |
2048 KB |
Output is correct |
3 |
Correct |
3 ms |
1912 KB |
Output is correct |
4 |
Correct |
4 ms |
1912 KB |
Output is correct |
5 |
Correct |
3 ms |
1912 KB |
Output is correct |
6 |
Correct |
3 ms |
1916 KB |
Output is correct |
7 |
Correct |
3 ms |
1920 KB |
Output is correct |
8 |
Correct |
4 ms |
1912 KB |
Output is correct |
9 |
Correct |
4 ms |
1912 KB |
Output is correct |
10 |
Correct |
4 ms |
1792 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
1792 KB |
Output is correct |
2 |
Correct |
4 ms |
1828 KB |
Output is correct |
3 |
Correct |
4 ms |
1792 KB |
Output is correct |
4 |
Correct |
4 ms |
1920 KB |
Output is correct |
5 |
Correct |
3 ms |
1788 KB |
Output is correct |
6 |
Correct |
3 ms |
1920 KB |
Output is correct |
7 |
Correct |
5 ms |
1784 KB |
Output is correct |
8 |
Correct |
4 ms |
1784 KB |
Output is correct |
9 |
Correct |
4 ms |
1784 KB |
Output is correct |
10 |
Correct |
5 ms |
1792 KB |
Output is correct |
11 |
Correct |
8 ms |
1784 KB |
Output is correct |
12 |
Correct |
9 ms |
1784 KB |
Output is correct |
13 |
Correct |
5 ms |
1784 KB |
Output is correct |
14 |
Correct |
15 ms |
384 KB |
Output is correct |
15 |
Partially correct |
50 ms |
1792 KB |
Partially correct - number of queries: 5574 |
16 |
Correct |
12 ms |
1784 KB |
Output is correct |
17 |
Partially correct |
70 ms |
1936 KB |
Partially correct - number of queries: 6875 |
18 |
Correct |
4 ms |
1784 KB |
Output is correct |
19 |
Partially correct |
27 ms |
2048 KB |
Partially correct - number of queries: 6495 |
20 |
Correct |
27 ms |
1024 KB |
Output is correct |
21 |
Correct |
40 ms |
1920 KB |
Output is correct |
22 |
Correct |
40 ms |
1920 KB |
Output is correct |
23 |
Correct |
6 ms |
1784 KB |
Output is correct |
24 |
Correct |
11 ms |
1856 KB |
Output is correct |
25 |
Correct |
27 ms |
1848 KB |
Output is correct |
26 |
Correct |
17 ms |
1784 KB |
Output is correct |
27 |
Correct |
6 ms |
1856 KB |
Output is correct |
28 |
Correct |
5 ms |
2040 KB |
Output is correct |
29 |
Correct |
7 ms |
1848 KB |
Output is correct |
30 |
Correct |
4 ms |
1784 KB |
Output is correct |
31 |
Partially correct |
48 ms |
1784 KB |
Partially correct - number of queries: 6825 |
32 |
Correct |
6 ms |
1784 KB |
Output is correct |
33 |
Correct |
2 ms |
256 KB |
Output is correct |
34 |
Correct |
23 ms |
1912 KB |
Output is correct |
35 |
Correct |
6 ms |
1852 KB |
Output is correct |
36 |
Partially correct |
41 ms |
1784 KB |
Partially correct - number of queries: 5275 |
37 |
Correct |
10 ms |
1832 KB |
Output is correct |
38 |
Correct |
4 ms |
1856 KB |
Output is correct |
39 |
Correct |
32 ms |
2040 KB |
Output is correct |
40 |
Correct |
4 ms |
1936 KB |
Output is correct |
41 |
Correct |
14 ms |
1912 KB |
Output is correct |
42 |
Correct |
25 ms |
1784 KB |
Output is correct |
43 |
Correct |
14 ms |
1932 KB |
Output is correct |
44 |
Correct |
40 ms |
2068 KB |
Output is correct |
45 |
Correct |
38 ms |
1812 KB |
Output is correct |
46 |
Partially correct |
57 ms |
1960 KB |
Partially correct - number of queries: 6934 |
47 |
Correct |
33 ms |
1852 KB |
Output is correct |
48 |
Correct |
11 ms |
1936 KB |
Output is correct |
49 |
Partially correct |
29 ms |
1944 KB |
Partially correct - number of queries: 6435 |
50 |
Correct |
5 ms |
1944 KB |
Output is correct |
51 |
Correct |
33 ms |
1792 KB |
Output is correct |
52 |
Partially correct |
29 ms |
1936 KB |
Partially correct - number of queries: 6866 |
53 |
Correct |
5 ms |
1784 KB |
Output is correct |
54 |
Correct |
38 ms |
1912 KB |
Output is correct |
55 |
Partially correct |
52 ms |
2040 KB |
Partially correct - number of queries: 6908 |
56 |
Correct |
4 ms |
1912 KB |
Output is correct |
57 |
Correct |
19 ms |
1784 KB |
Output is correct |
58 |
Correct |
10 ms |
2048 KB |
Output is correct |
59 |
Correct |
25 ms |
1792 KB |
Output is correct |
60 |
Correct |
16 ms |
1852 KB |
Output is correct |
61 |
Correct |
4 ms |
1856 KB |
Output is correct |
62 |
Correct |
5 ms |
1912 KB |
Output is correct |
63 |
Correct |
2 ms |
1912 KB |
Output is correct |
64 |
Correct |
4 ms |
1920 KB |
Output is correct |
65 |
Correct |
4 ms |
2040 KB |
Output is correct |
66 |
Correct |
4 ms |
1852 KB |
Output is correct |
67 |
Correct |
4 ms |
1920 KB |
Output is correct |
68 |
Correct |
3 ms |
1912 KB |
Output is correct |
69 |
Correct |
4 ms |
1788 KB |
Output is correct |
70 |
Correct |
4 ms |
1912 KB |
Output is correct |
71 |
Partially correct |
55 ms |
1792 KB |
Partially correct - number of queries: 7160 |
72 |
Correct |
11 ms |
1920 KB |
Output is correct |
73 |
Partially correct |
51 ms |
1792 KB |
Partially correct - number of queries: 7069 |
74 |
Partially correct |
53 ms |
1920 KB |
Partially correct - number of queries: 7108 |
75 |
Correct |
7 ms |
1792 KB |
Output is correct |
76 |
Partially correct |
51 ms |
1792 KB |
Partially correct - number of queries: 6224 |
77 |
Partially correct |
56 ms |
1920 KB |
Partially correct - number of queries: 7401 |
78 |
Correct |
6 ms |
2048 KB |
Output is correct |
79 |
Correct |
24 ms |
1792 KB |
Output is correct |
80 |
Partially correct |
52 ms |
1920 KB |
Partially correct - number of queries: 7380 |
81 |
Partially correct |
56 ms |
1840 KB |
Partially correct - number of queries: 7392 |
82 |
Partially correct |
30 ms |
1920 KB |
Partially correct - number of queries: 7379 |
83 |
Correct |
5 ms |
1792 KB |
Output is correct |
84 |
Partially correct |
44 ms |
1792 KB |
Partially correct - number of queries: 6270 |
85 |
Partially correct |
60 ms |
1792 KB |
Partially correct - number of queries: 7429 |
86 |
Correct |
7 ms |
1860 KB |
Output is correct |
87 |
Correct |
7 ms |
1792 KB |
Output is correct |
88 |
Correct |
15 ms |
1920 KB |
Output is correct |
89 |
Correct |
6 ms |
1920 KB |
Output is correct |
90 |
Correct |
4 ms |
1856 KB |
Output is correct |
91 |
Correct |
8 ms |
1792 KB |
Output is correct |
92 |
Correct |
4 ms |
1792 KB |
Output is correct |
93 |
Correct |
8 ms |
1792 KB |
Output is correct |
94 |
Correct |
8 ms |
1920 KB |
Output is correct |
95 |
Correct |
7 ms |
1792 KB |
Output is correct |
96 |
Correct |
9 ms |
1920 KB |
Output is correct |
97 |
Correct |
4 ms |
1840 KB |
Output is correct |