답안 #138970

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
138970 2019-07-31T05:25:50 Z baluteshih Hotter Colder (IOI10_hottercolder) C++14
85 / 100
695 ms 8236 KB
#include "grader.h"
#include <stdlib.h>
#include <stdio.h>
#include <chrono>
#define jizz ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define pb push_back
#define ET cout << "\n"
#define F first
#define S second
#define MP make_pair
#define ALL(v) v.begin(),v.end()
#define MEM(i,j) memset(i,j,sizeof i)
#define DB(a,s,e) {for(int i=s;i<e;++i) cout << a[i] << " ";ET;}
using namespace std;
typedef long long ll;

int ls=-1;

int guess(int x)
{
	//printf("guess %d: ",x);
	int t=Guess(x);
	//printf("%d\n",t);
	ls=x;
	return t;
}

void handle(int &l,int &r)
{
	while(l<r)
	{
		int m=l+r>>1;
		if(ls!=l&&ls!=r)
			guess(l);
		if(ls==l)
		{
			if(l==m)
			{
				if(guess(r)==-1) r=l;
				else l=r;
				break;
			}
			int t=guess(m);
			if(t==0)
			{
				l=r=(l+m)/2;
				break;
			}
			else if(t==-1) r=(l+m)/2;
			else
			{
				t=guess(r);
				if(t==0)
				{
					l=r=(m+r)/2;
					break;
				}
				else if(t==-1)
				{
					l=(l+m)/2+1,r=(m+r)/2;
					break;
				}
				else l=(m+r)/2+1;
			}
		}
		else
		{
			int t=guess(m);
			if(l==m)
			{
				if(t==-1) l=r;
				else r=l;
				break;
			}
			if(t==0)
			{
				l=r=(m+r)/2;
				break;
			}
			else if(t==-1) l=(m+r)/2+1;
			else
			{
				t=guess(l);
				if(t==0)
				{
					l=r=(l+m)/2;
					break;
				}
				else if(t==-1)
				{
					l=(l+m)/2+1,r=(m+r)/2;
					break;
				}
				else r=(l+m)/2;
			}
		}
	}
}

int HC(int N)
{
	ls=-1;
	int l=1,r=N;
	handle(l,r);
	while(l<r)
	{
		if(l+r-ls<1||l+r-ls>N)
		{
			handle(l,r);
			continue;
		}  
		int m=l+r>>1,tmp=ls,t=guess(l+r-ls);
		if(t==0)
		{
			l=r=m;
			break;
		}
		else if(t==-1)
			if(tmp>ls) l=m+1;
			else r=m;
		else
			if(tmp>ls) r=m;
			else l=m+1;
	}
	return l;
}

Compilation message

hottercolder.cpp: In function 'void handle(int&, int&)':
hottercolder.cpp:32:10: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   int m=l+r>>1;
         ~^~
hottercolder.cpp: In function 'int HC(int)':
hottercolder.cpp:112:10: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   int m=l+r>>1,tmp=ls,t=guess(l+r-ls);
         ~^~
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 1272 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 1272 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 1272 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Partially correct 695 ms 8236 KB Output is partially correct - alpha = 0.400000000000