답안 #137061

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
137061 2019-07-27T03:28:50 Z StevenH Hotter Colder (IOI10_hottercolder) C++14
78 / 100
835 ms 8312 KB
#include "grader.h"
#include <cstdio>
int HC(int N){
	int k=N,kk=0;
	while(k>1)k/=2,kk++;
	k=0;
	if(N==1)return 1;
    int left=1,right=N;
    bool last = 0;
    Guess(left);
    k++;
    while(left+1 < right)
    {
    	//printf("left = %d ,right = %d\n",left,right);
    	int res;
    	int mid=(left+right)/2;
 		if(last==0)
 		{
    		if(k==2*kk && N<=500)return 1;
 			res = Guess(right);
 			k++;
 			if(res == -1)
 			{

	 			if((left+right)%2==0)right = mid - 1;
 				else right = mid;
	 			//Guess(right);
	 			//last = 1;
    			if(k==2*kk && N<=500)return 1;
	 			Guess(left);
	 			last = 0;
	 			k++;
	 		}
 			else if(res == 1)
 			{
 				left = mid+1;
 				last = 1;	
 			}
 			else if(res == 0)
 			{
 				return mid;
 			}
 		}
 		else
 		{
    		if(k==2*kk && N<=500)return 1;
 			res = Guess(left);
 			k++;
 			if(res == -1)
 			{
 				left = mid+1;
    			if(k==2*kk && N<=500)return 1;
 				//Guess(left);
 				//last = 0;
 				Guess(right);
	 			last = 1;
	 			k++;
 			}
 			else if(res == 1)
 			{
	 			if((left+right)%2==0)right = mid - 1;
 				else right = mid;
 				last = 0;	
 			}
 			else if(res == 0)
 			{
 				return mid;
 			}
 		}


    }
    if(left == right)return left;

    if(k==2*kk && N<=500)return 1;
    if(right == left+1)
    {
    	//printf("%d %d\n",left,right);
    	int res;
    	if(last == 0)
    	{
    		res = Guess(right);
    		if(res == 1)return right;
    		else return left;
    	}
    	else if(last == 1)
    	{
    		res = Guess(left);
    		if(res == 1)return left;
    		else return right;
    	}
    }
}

Compilation message

hottercolder.cpp: In function 'int HC(int)':
hottercolder.cpp:93:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 1272 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 1272 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 1272 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Partially correct 835 ms 8312 KB Output is partially correct - alpha = 0.120000000000