結果

問題 No.253 ロウソクの長さ
ユーザー Shuz*Shuz*
提出日時 2018-09-10 02:16:42
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 27 ms / 2,000 ms
コード長 726 bytes
コンパイル時間 516 ms
コンパイル使用メモリ 63,764 KB
実行使用メモリ 24,360 KB
平均クエリ数 56.11
最終ジャッジ日時 2023-09-24 01:53:45
合計ジャッジ時間 2,967 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 27 ms
24,048 KB
testcase_01 AC 20 ms
23,640 KB
testcase_02 AC 21 ms
24,348 KB
testcase_03 AC 20 ms
23,700 KB
testcase_04 AC 20 ms
23,556 KB
testcase_05 AC 22 ms
23,388 KB
testcase_06 AC 23 ms
23,808 KB
testcase_07 AC 22 ms
23,676 KB
testcase_08 AC 22 ms
23,664 KB
testcase_09 AC 20 ms
24,048 KB
testcase_10 AC 21 ms
23,520 KB
testcase_11 AC 21 ms
23,652 KB
testcase_12 AC 23 ms
23,988 KB
testcase_13 AC 27 ms
24,264 KB
testcase_14 AC 22 ms
24,048 KB
testcase_15 AC 22 ms
23,412 KB
testcase_16 AC 22 ms
23,652 KB
testcase_17 AC 22 ms
23,676 KB
testcase_18 AC 24 ms
23,808 KB
testcase_19 AC 20 ms
23,436 KB
testcase_20 AC 21 ms
23,208 KB
testcase_21 AC 23 ms
23,640 KB
testcase_22 AC 21 ms
24,360 KB
testcase_23 AC 22 ms
23,436 KB
testcase_24 AC 20 ms
24,036 KB
testcase_25 AC 22 ms
23,400 KB
testcase_26 AC 22 ms
24,312 KB
testcase_27 AC 21 ms
24,312 KB
testcase_28 AC 22 ms
23,664 KB
testcase_29 AC 23 ms
24,048 KB
testcase_30 AC 22 ms
24,048 KB
testcase_31 AC 22 ms
24,072 KB
testcase_32 AC 21 ms
24,360 KB
testcase_33 AC 23 ms
23,556 KB
testcase_34 AC 20 ms
23,364 KB
testcase_35 AC 22 ms
23,868 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//これは他の方のコードです。
#include <iostream>
using namespace std;

int ask(int Y){
	cout << "? " << Y << endl;
	int res;
	cin >> res;
	return res;
}

int solve(){
	int askCount = 0;
	for(int i=2;i<=50;i++,askCount++){
		int res = ask(i);
		if(res < 0){
			return i - 1 + askCount;
		}
		if(res == 0){
			return i + askCount;
		}
	}
	// [lo, hi]
	int lo = 50, hi = 1e9 - askCount;
	for(;;++askCount){
		int mid = (lo + hi) / 2;
		int res = ask(mid);
		if(res == 0){
			return mid + askCount;
		}
		if(res < 0){
			hi = mid - 1;
		} else {
			lo = mid + 1;
		}
		if(lo == hi){
			return lo + askCount;
		}
		--lo;
		--hi;
	}
	return -1;
}

int main(){
	int Y = solve();
	cout << "! " << Y << endl;
	return 0;
}
0