#include "grader.h"
#include <cstdio>
#include <cassert>
#include <algorithm>
const int SMALL=42;
char cost[SMALL+2][SMALL+2][SMALL+2][SMALL+2];//l,r,x
void Brute(int N){
if(cost[N][1][N][1]) return;
for(int l=0;l<=N;l++){
for(int r=0;r<=N;r++){
for(int x=1;x<=N;x++){
cost[N][l][r][x]=50;
}
}
}
for(int l=1;l<=N;l++){
for(int x=1;x<=N;x++){
cost[N][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[N][l][std::min(r,ml)][y],cost[N][std::max(l,mr)][r][y]);
if(cost[N][l][r][x]>v){
cost[N][l][r][x]=v;
k=y;
}
}
//printf("cost[%d][%d][%d]=%d (%d)\n",l,r,x,cost[N][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<=SMALL){
Brute(N);
Guess(last=std::min_element(cost[N][1][N]+1,cost[N][1][N]+N+1)-cost[N][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[N][l][r][x]==1+std::max(cost[N][l][std::min(r,ml)][y],cost[N][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:29:6: warning: variable 'k' set but not used [-Wunused-but-set-variable]
int k=-1;
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
117 ms |
3192 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
124 ms |
3192 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
120 ms |
3252 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
1022 ms |
10152 KB |
Output is partially correct - alpha = 0.851851851852 |