#include<bits/stdc++.h>
#include "prize.h"
using namespace std;
int i,j,n,m,l,r,c,xl,xr,maz,rez,h[5][2];
vector<int> xx;
int find_best(int n)
{
h[0][0]=-1;
h[1][0]=-1;
h[2][0]=-1;
h[3][0]=-1;
h[4][0]=-1;
l=0;
r=n-1;
rez=0;
maz=0;
while (true)
{
//cout << l << " " << r << "\n";
while (l<r)
{
c=l+(r-l)/2;
xx=ask(c);
xl=xx[0];
xr=xx[1];
//cout << l << " " << c << " " << r << " " << maz << " " << xl << " " << xr << "\n" << h[0][0] << " " << h[1][0] << " " << h[2][0] << " " << h[3][0] << " " << h[4][0] << "\n" << h[0][1] << " " << h[1][1] << " " << h[2][1] << " " << h[3][1] << " " << h[4][1] << "\n";
if (xl+xr==h[0][0]||h[0][0]==-1)
{
h[0][0]=xl+xr;
}
else if (xl+xr==h[1][0]||h[1][0]==-1)
{
h[1][0]=xl+xr;
}
else if (xl+xr==h[2][0]||h[2][0]==-1)
{
h[2][0]=xl+xr;
}
else if (xl+xr==h[3][0]||h[3][0]==-1)
{
h[3][0]=xl+xr;
}
else if (xl+xr==h[4][0]||h[4][0]==-1)
{
h[4][0]=xl+xr;
}
if (xl+xr==0)
{
return c;
}
if (xl+xr>maz)
{
l=0;
r=n-1;
rez=0;
maz=xl+xr;
h[0][1]=0;
h[1][1]=0;
h[2][1]=0;
h[3][1]=0;
h[4][1]=0;
}
else if ((h[0][0]==xl+xr&&xl>h[0][1])||(h[1][0]==xl+xr&&xl>h[1][1])||(h[2][0]==xl+xr&&xl>h[2][1])||(h[3][0]==xl+xr&&xl>h[3][1])||(h[4][0]==xl+xr&&xl>h[4][1]))
{
r=c-1;
}
else
{
l=c+1;
}
}
if (l<=n-1)
{
xx=ask(l);
xl=xx[0];
xr=xx[1];
}
if (xl+xr==0)
{
return l;
}
rez++;
l++;
//cout << l << " " << r << "\n";
if (l<=n-1)
{
xx=(ask(l));
xl=xx[0];
xr=xx[1];
if (xl+xr==h[0][0]||h[0][0]==-1)
{
h[0][0]=xl+xr;
}
else if (xl+xr==h[1][0]||h[1][0]==-1)
{
h[1][0]=xl+xr;
}
else if (xl+xr==h[2][0]||h[2][0]==-1)
{
h[2][0]=xl+xr;
}
else if (xl+xr==h[3][0]||h[3][0]==-1)
{
h[3][0]=xl+xr;
}
else if (xl+xr==h[4][0]||h[4][0]==-1)
{
h[4][0]=xl+xr;
}
if (h[0][0]>=xl+xr)
{
h[0][1]++;
}
if (h[1][0]>=xl+xr)
{
h[1][1]++;
}
if (h[2][0]>=xl+xr)
{
h[2][1]++;
}
if (h[3][0]>=xl+xr)
{
h[3][1]++;
}
if (h[4][0]>=xl+xr)
{
h[4][1]++;
}
if (xl+xr==0)
{
return l;
}
}
while (xl+xr<maz&&l<n-1)
{
l++;
rez++;
//cout << l << " " << r << "\n";
xx=(ask(l));
xl=xx[0];
xr=xx[1];
if (xl+xr==h[0][0]||h[0][0]==-1)
{
h[0][0]=xl+xr;
}
else if (xl+xr==h[1][0]||h[0][0]==-1)
{
h[1][0]=xl+xr;
}
else if (xl+xr==h[2][0]||h[0][0]==-1)
{
h[2][0]=xl+xr;
}
else if (xl+xr==h[3][0]||h[0][0]==-1)
{
h[3][0]=xl+xr;
}
else if (xl+xr==h[4][0]||h[0][0]==-1)
{
h[4][0]=xl+xr;
}
if (h[0][0]>=xl+xr)
{
h[0][1]++;
}
if (h[1][0]>=xl+xr)
{
h[1][1]++;
}
if (h[2][0]>=xl+xr)
{
h[2][1]++;
}
if (h[3][0]>=xl+xr)
{
h[3][1]++;
}
if (h[4][0]>=xl+xr)
{
h[4][1]++;
}
if (xl+xr==0)
{
return l;
}
}
if (xl+xr>maz)
{
maz=xl+xr;
l=0;
r=n-1;
rez=0;
h[0][1]=0;
h[1][1]=0;
h[2][1]=0;
h[3][1]=0;
h[4][1]=0;
}
r=n-1;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
292 KB |
Output is correct |
2 |
Correct |
4 ms |
440 KB |
Output is correct |
3 |
Correct |
3 ms |
440 KB |
Output is correct |
4 |
Correct |
3 ms |
440 KB |
Output is correct |
5 |
Correct |
2 ms |
440 KB |
Output is correct |
6 |
Correct |
4 ms |
440 KB |
Output is correct |
7 |
Correct |
5 ms |
440 KB |
Output is correct |
8 |
Correct |
2 ms |
448 KB |
Output is correct |
9 |
Correct |
2 ms |
448 KB |
Output is correct |
10 |
Correct |
3 ms |
448 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
448 KB |
Output is correct |
2 |
Correct |
2 ms |
448 KB |
Output is correct |
3 |
Correct |
3 ms |
492 KB |
Output is correct |
4 |
Correct |
2 ms |
492 KB |
Output is correct |
5 |
Correct |
2 ms |
492 KB |
Output is correct |
6 |
Correct |
3 ms |
560 KB |
Output is correct |
7 |
Correct |
3 ms |
560 KB |
Output is correct |
8 |
Correct |
3 ms |
560 KB |
Output is correct |
9 |
Correct |
3 ms |
560 KB |
Output is correct |
10 |
Correct |
3 ms |
560 KB |
Output is correct |
11 |
Correct |
4 ms |
560 KB |
Output is correct |
12 |
Correct |
3 ms |
560 KB |
Output is correct |
13 |
Execution timed out |
1036 ms |
560 KB |
Time limit exceeded |
14 |
Halted |
0 ms |
0 KB |
- |