#include<bits/stdc++.h>
#include "prize.h"
using namespace std;
int i,j,n,m,l,r,c,xl,xr,maz,rez,mas[200005][2];
vector<int> xx;
vector<int> aask(int h)
{
if (mas[h][0]==-1&&mas[h][1]==-1)
{
xx=ask(h);
mas[h][0]=xx[0];
mas[h][1]=xx[1];
}
else
{
xx[0]=mas[h][0];
xx[1]=mas[h][1];
}
return xx;
}
int find_best(int n)
{
i=0;
while (i<n-1)
{
mas[i][0]=-1;
mas[i][1]=-1;
i++;
}
l=0;
r=n-1;
rez=0;
maz=0;
while (true)
{
while (l<r)
{
c=l+(r-l)/2;
xx=aask(c);
xl=xx[0];
xr=xx[1];
if (xl+xr==0)
{
return c;
}
if (xl+xr>maz)
{
l=0;
r=n-1;
rez=0;
maz=xl+xr;
}
else if (xl+xr<maz)
{
r=c;
}
else if (xl>rez)
{
r=c-1;
}
else
{
l=c+1;
}
}
if (l<=n-1)
{
xx=aask(l);
xl=xx[0];
xr=xx[1];
}
if (xl+xr==0)
{
return l;
}
rez++;
l++;
if (l<=n-1)
{
xx=(aask(l));
xl=xx[0];
xr=xx[1];
if (xl+xr==0)
{
return l;
}
}
while (xl+xr<maz&&l<n-1)
{
l++;
rez++;
xx=(aask(l));
xl=xx[0];
xr=xx[1];
if (xl+xr==0)
{
return l;
}
}
if (xl+xr>maz)
{
maz=xl+xr;
l=0;
r=n-1;
rez=0;
}
r=n-1;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
1832 KB |
Output is correct |
2 |
Correct |
4 ms |
1844 KB |
Output is correct |
3 |
Correct |
4 ms |
1880 KB |
Output is correct |
4 |
Correct |
5 ms |
1944 KB |
Output is correct |
5 |
Correct |
4 ms |
1956 KB |
Output is correct |
6 |
Correct |
3 ms |
2028 KB |
Output is correct |
7 |
Correct |
3 ms |
2092 KB |
Output is correct |
8 |
Correct |
6 ms |
2104 KB |
Output is correct |
9 |
Correct |
4 ms |
2104 KB |
Output is correct |
10 |
Correct |
5 ms |
2104 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
2104 KB |
Output is correct |
2 |
Correct |
5 ms |
2104 KB |
Output is correct |
3 |
Correct |
5 ms |
2104 KB |
Output is correct |
4 |
Correct |
6 ms |
2104 KB |
Output is correct |
5 |
Correct |
4 ms |
2104 KB |
Output is correct |
6 |
Correct |
4 ms |
2104 KB |
Output is correct |
7 |
Correct |
4 ms |
2104 KB |
Output is correct |
8 |
Correct |
5 ms |
2104 KB |
Output is correct |
9 |
Correct |
4 ms |
2108 KB |
Output is correct |
10 |
Correct |
4 ms |
2108 KB |
Output is correct |
11 |
Correct |
8 ms |
2108 KB |
Output is correct |
12 |
Correct |
5 ms |
2108 KB |
Output is correct |
13 |
Correct |
13 ms |
2108 KB |
Output is correct |
14 |
Correct |
6 ms |
2108 KB |
Output is correct |
15 |
Correct |
26 ms |
2108 KB |
Output is correct |
16 |
Partially correct |
100 ms |
2108 KB |
Partially correct - number of queries: 6654 |
17 |
Correct |
3 ms |
2108 KB |
Output is correct |
18 |
Partially correct |
78 ms |
2108 KB |
Partially correct - number of queries: 7793 |
19 |
Correct |
4 ms |
2108 KB |
Output is correct |
20 |
Correct |
13 ms |
2108 KB |
Output is correct |
21 |
Correct |
25 ms |
2108 KB |
Output is correct |
22 |
Correct |
10 ms |
2108 KB |
Output is correct |
23 |
Correct |
4 ms |
2108 KB |
Output is correct |
24 |
Correct |
4 ms |
2108 KB |
Output is correct |
25 |
Correct |
74 ms |
2108 KB |
Output is correct |
26 |
Correct |
39 ms |
2108 KB |
Output is correct |
27 |
Correct |
7 ms |
2108 KB |
Output is correct |
28 |
Partially correct |
40 ms |
2108 KB |
Partially correct - number of queries: 7327 |
29 |
Partially correct |
80 ms |
2108 KB |
Partially correct - number of queries: 5583 |
30 |
Partially correct |
77 ms |
2108 KB |
Partially correct - number of queries: 7728 |
31 |
Correct |
5 ms |
2108 KB |
Output is correct |
32 |
Correct |
9 ms |
2108 KB |
Output is correct |
33 |
Correct |
2 ms |
2108 KB |
Output is correct |
34 |
Correct |
41 ms |
2108 KB |
Output is correct |
35 |
Correct |
8 ms |
2108 KB |
Output is correct |
36 |
Correct |
24 ms |
2108 KB |
Output is correct |
37 |
Correct |
6 ms |
2108 KB |
Output is correct |
38 |
Correct |
4 ms |
2108 KB |
Output is correct |
39 |
Correct |
54 ms |
2112 KB |
Output is correct |
40 |
Partially correct |
91 ms |
2112 KB |
Partially correct - number of queries: 6613 |
41 |
Correct |
73 ms |
2112 KB |
Output is correct |
42 |
Correct |
82 ms |
2112 KB |
Output is correct |
43 |
Correct |
38 ms |
2112 KB |
Output is correct |
44 |
Correct |
32 ms |
2112 KB |
Output is correct |
45 |
Correct |
32 ms |
2112 KB |
Output is correct |
46 |
Correct |
4 ms |
2112 KB |
Output is correct |
47 |
Correct |
46 ms |
2112 KB |
Output is correct |
48 |
Partially correct |
87 ms |
2112 KB |
Partially correct - number of queries: 5782 |
49 |
Correct |
18 ms |
2112 KB |
Output is correct |
50 |
Partially correct |
106 ms |
2112 KB |
Partially correct - number of queries: 7793 |
51 |
Correct |
38 ms |
2112 KB |
Output is correct |
52 |
Correct |
6 ms |
2112 KB |
Output is correct |
53 |
Correct |
7 ms |
2112 KB |
Output is correct |
54 |
Correct |
46 ms |
2112 KB |
Output is correct |
55 |
Correct |
5 ms |
2112 KB |
Output is correct |
56 |
Partially correct |
97 ms |
2112 KB |
Partially correct - number of queries: 7791 |
57 |
Partially correct |
49 ms |
2112 KB |
Partially correct - number of queries: 5682 |
58 |
Partially correct |
64 ms |
2112 KB |
Partially correct - number of queries: 5765 |
59 |
Correct |
57 ms |
2112 KB |
Output is correct |
60 |
Correct |
51 ms |
2112 KB |
Output is correct |
61 |
Correct |
5 ms |
2112 KB |
Output is correct |
62 |
Correct |
6 ms |
2112 KB |
Output is correct |
63 |
Correct |
5 ms |
2112 KB |
Output is correct |
64 |
Correct |
6 ms |
2112 KB |
Output is correct |
65 |
Correct |
4 ms |
2112 KB |
Output is correct |
66 |
Correct |
9 ms |
2112 KB |
Output is correct |
67 |
Correct |
4 ms |
2112 KB |
Output is correct |
68 |
Correct |
10 ms |
2112 KB |
Output is correct |
69 |
Correct |
20 ms |
2112 KB |
Output is correct |
70 |
Correct |
4 ms |
2112 KB |
Output is correct |
71 |
Partially correct |
91 ms |
2112 KB |
Partially correct - number of queries: 7752 |
72 |
Correct |
8 ms |
2112 KB |
Output is correct |
73 |
Partially correct |
105 ms |
2112 KB |
Partially correct - number of queries: 7667 |
74 |
Partially correct |
73 ms |
2112 KB |
Partially correct - number of queries: 7709 |
75 |
Correct |
5 ms |
2112 KB |
Output is correct |
76 |
Partially correct |
104 ms |
2112 KB |
Partially correct - number of queries: 6621 |
77 |
Partially correct |
71 ms |
2112 KB |
Partially correct - number of queries: 7824 |
78 |
Correct |
10 ms |
2112 KB |
Output is correct |
79 |
Correct |
32 ms |
2112 KB |
Output is correct |
80 |
Partially correct |
81 ms |
2112 KB |
Partially correct - number of queries: 7835 |
81 |
Partially correct |
79 ms |
2112 KB |
Partially correct - number of queries: 7832 |
82 |
Partially correct |
85 ms |
2112 KB |
Partially correct - number of queries: 7764 |
83 |
Correct |
6 ms |
2112 KB |
Output is correct |
84 |
Partially correct |
31 ms |
2112 KB |
Partially correct - number of queries: 6385 |
85 |
Partially correct |
56 ms |
2112 KB |
Partially correct - number of queries: 7815 |
86 |
Partially correct |
56 ms |
2112 KB |
Partially correct - number of queries: 6234 |
87 |
Correct |
15 ms |
2112 KB |
Output is correct |
88 |
Partially correct |
56 ms |
2112 KB |
Partially correct - number of queries: 5997 |
89 |
Partially correct |
103 ms |
2112 KB |
Partially correct - number of queries: 6188 |
90 |
Correct |
11 ms |
2112 KB |
Output is correct |
91 |
Correct |
21 ms |
2112 KB |
Output is correct |
92 |
Partially correct |
91 ms |
2112 KB |
Partially correct - number of queries: 5657 |
93 |
Correct |
8 ms |
2112 KB |
Output is correct |
94 |
Correct |
9 ms |
2112 KB |
Output is correct |
95 |
Correct |
6 ms |
2112 KB |
Output is correct |
96 |
Correct |
9 ms |
2112 KB |
Output is correct |
97 |
Correct |
5 ms |
2112 KB |
Output is correct |