#include "grader.h"
#include <cstdio>
#include <cassert>
#include <algorithm>
char cost[10+2][10+2][10+2];//l,r,x
void Brute(int N){
for(int l=0;l<=N;l++){
for(int r=0;r<=N;r++){
for(int x=1;x<=N;x++){
cost[l][r][x]=50;
}
}
}
for(int l=1;l<=N;l++){
for(int x=1;x<=N;x++){
cost[l][l][x]=0;
}
}
//Assuming OPT will never make a guess without reducing interval
//Seems to be true from experimentation
for(int l=N;l>0;l--){
for(int r=l;r<=N;r++){
for(int x=1;x<=N;x++){
int k=-1;
for(int y=1;y<=N;y++){
if(y==x) continue;
int ml=(x+y-1)/2;
int mr=(x+y)/2+1;
int v=1+std::max(cost[l][std::min(r,ml)][y],cost[std::max(l,mr)][r][y]);
if(cost[l][r][x]>v){
cost[l][r][x]=v;
k=y;
}
}
//printf("cost[%d][%d][%d]=%d (%d)\n",l,r,x,cost[l][r][x],k);
}
}
}
}
int N;
int l,r;
int last;
void Refine(int g){
//printf("[%d,%d]: [%d,%d] (%d) %d\n",1,N,l,r,last,g);
assert(last!=-1);
g=std::max(1,std::min(N,g));
if(last==g){
if(g==1) g++;
else if(g==N) g--;
else if(rand()%2){
g++;
}else{
g--;
}
}
//assert(g>=1&&g<=N);
int res=Guess(g);
//printf("Guess(%d)=>%d\n",g,res);
if(res==0){
l=r=(last+g)/2;
return;
}
int ml=(last+g-1)/2;
int mr=(last+g)/2+1;
if((g<last)^(res<0)){
r=std::min(r,ml);
}else{
l=std::max(l,mr);
}
last=g;
}
int HC(int N){
//printf("HC(%d)\n",N);
::N=N;
l=1,r=N;
if(N<=10){
Brute(N);
Guess(last=std::min_element(cost[1][N]+1,cost[1][N]+N+1)-cost[1][N]);
while(l<r){
int x=last;
for(int y=1;y<=N;y++){
int ml=(x+y-1)/2;
int mr=(x+y)/2+1;
if(cost[l][r][x]==1+std::max(cost[l][std::min(r,ml)][y],cost[std::max(l,mr)][r][y])){
Refine(y);
break;
}
}
}
return l;
}
Guess(last=(l+r)/2);
Refine(last+1);
int p1=0,p2=0;
while(l==1&&(l<r)){
Refine(l+int((r-l)*0.4));
p1++;
}
while((r==N)&&(l<r)){
Refine(r-int((r-l)*0.4));
p1++;
}
while(l<r){
Refine(l+r-last);
p2++;
}
//printf("HC(%d,%d): %d+%d\n",N,l,p1,p2);
return l;
}
Compilation message
hottercolder.cpp: In function 'void Brute(int)':
hottercolder.cpp:26:6: warning: variable 'k' set but not used [-Wunused-but-set-variable]
int k=-1;
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
37 ms |
1144 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
39 ms |
1272 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
36 ms |
1336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
941 ms |
8312 KB |
Output is partially correct - alpha = 0.800000000000 |