結果

問題 No.246 質問と回答
ユーザー lunnear
提出日時 2018-11-14 13:57:59
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 51 ms / 2,000 ms
コード長 605 bytes
コンパイル時間 700 ms
コンパイル使用メモリ 55,232 KB
実行使用メモリ 25,220 KB
平均クエリ数 31.30
最終ジャッジ日時 2024-07-16 20:19:47
合計ジャッジ時間 3,463 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>

#define MIN 1
#define	MAX	1000000000

int Center(int lower, int higher)
{
	higher -= lower;
	higher /= 2;

	return lower + higher;
}

int main()
{
	int min = MIN;
	int max = MAX;

	int in;

	for(int i = 0; i < 99; i++)
	{
		int c = Center(min, max);
		std::cout << "? " << c << std::endl;
		std::cout << std::flush;

		std::cin >> in;

		(in == 1)? min = c : max = c - 1;

		if ((max - min) <= 1)
			break;
	}
	
	std::cout << "? " << max << std::endl;
	std::cout << std::flush;
	std::cin >> in;
	
	int ans = (in == 0)? min : max;

	std::cout << "! " << ans << std::endl;

	return 0;
}
0