This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#include "grader.h"
using namespace std;
int hist=-1;
int cnt=0;
int hidden,n;
/*int Guess(int g)
{
if(g<1||g>n)cout<<"err: "<<g<<endl;
cnt++;
if(hist==-1)
{
hist=g;
return 0;
}
int dist1=abs(hidden-hist),dist2=abs(hidden-g);
hist=g;
if(dist1==dist2)return 0;
if(dist1>dist2)return 1;
return -1;
}*/
int HC(int N)
{
srand(69);
Guess(1);
int last=1,l=1,r=N;
while(l<r)
{
int mid=r+l-last;
while(mid>N)mid--;
while(mid<1)mid++;
if(mid==last&&mid+1<=N)mid++;
if(mid==last&&mid-1>=1)mid--;
//cout<<l<<" "<<r<<" "<<mid<<endl;
int t=Guess(mid);
//cout<<t<<endl;
int l1=N+1,r1=0;
for(int j=l;j<=r;j++)
{
int dist1=abs(mid-j);
int dist2=abs(last-j);
if(t==0&&dist1==dist2)
{
l1=min(l1,j);
r1=max(r1,j);
}
if(t==1&&dist1<dist2)
{
l1=min(l1,j);
r1=max(r1,j);
}
if(t==-1&&dist1>dist2)
{
l1=min(l1,j);
r1=max(r1,j);
}
}
last=mid;
l=l1;r=r1;
}
return l;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |