#include<bits/stdc++.h>
#include "grader.h"
using namespace std;
bool go_lg(int &bg,int &en,int &tmp)
{
if(tmp==0)
return true;
else if(tmp==-1)
en=(bg+en-1)/2;
else
bg=(bg+en+2)/2;
return false;
}
bool go_gl(int &bg,int &en,int &tmp)
{
if(tmp==0)
return true;
else if(tmp==1)
en=(bg+en-1)/2;
else
bg=(bg+en+2)/2;
return false;
}
int HC(int N)
{
if(N==1)
return 1;
if(N==2)
{
Guess(1);
int tmp=Guess(2);
if(tmp==1)
return 2;
return 1;
}
mt19937 gen(2913319);
int bg=1,en=N;
int l=-1;
while(bg<en)
{
if(l==bg)
{
int nl=en;
int tmp=Guess(nl);
if(go_lg(bg,en,tmp))
return (bg+en)/2;
l=nl;
}
else if(l==en)
{
int nl=bg;
int tmp=Guess(nl);
if(go_gl(bg,en,tmp))
return (bg+en)/2;
l=nl;
}
else
{
l=(bg+en-1)/2;
int nl=(bg+en+2)/2;
if(uniform_int_distribution<int>{0,1}(gen))
{
Guess(nl);
int tmp=Guess(l);
if(go_gl(bg,en,tmp))
return (bg+en)/2;
}
else
{
Guess(l);
int tmp=Guess(nl);
if(go_lg(bg,en,tmp))
return (bg+en)/2;
l=nl;
}
}
}
return bg;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
728 ms |
1292 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
742 ms |
1276 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
771 ms |
1276 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
6438 ms |
24372 KB |
Output is partially correct - alpha = 0.137931034483 |