結果

問題 No.253 ロウソクの長さ
ユーザー cielciel
提出日時 2015-07-24 23:21:38
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 715 bytes
コンパイル時間 1,029 ms
コンパイル使用メモリ 25,632 KB
実行使用メモリ 24,384 KB
平均クエリ数 27.33
最終ジャッジ日時 2023-09-07 22:45:48
合計ジャッジ時間 7,083 ms
ジャッジサーバーID
(参考情報)
judge2 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 26 ms
23,640 KB
testcase_01 AC 25 ms
24,036 KB
testcase_02 AC 25 ms
24,300 KB
testcase_03 AC 25 ms
24,360 KB
testcase_04 WA -
testcase_05 AC 24 ms
23,856 KB
testcase_06 AC 24 ms
23,508 KB
testcase_07 AC 25 ms
23,568 KB
testcase_08 AC 24 ms
23,508 KB
testcase_09 WA -
testcase_10 AC 25 ms
23,400 KB
testcase_11 AC 25 ms
24,036 KB
testcase_12 AC 25 ms
23,808 KB
testcase_13 AC 25 ms
23,388 KB
testcase_14 WA -
testcase_15 AC 24 ms
23,352 KB
testcase_16 AC 25 ms
24,012 KB
testcase_17 AC 26 ms
24,000 KB
testcase_18 AC 25 ms
23,652 KB
testcase_19 WA -
testcase_20 AC 26 ms
24,384 KB
testcase_21 AC 25 ms
23,868 KB
testcase_22 WA -
testcase_23 AC 28 ms
23,352 KB
testcase_24 AC 25 ms
23,652 KB
testcase_25 AC 25 ms
24,024 KB
testcase_26 AC 24 ms
23,364 KB
testcase_27 AC 25 ms
24,372 KB
testcase_28 AC 26 ms
23,376 KB
testcase_29 AC 25 ms
23,532 KB
testcase_30 AC 25 ms
24,036 KB
testcase_31 AC 25 ms
24,240 KB
testcase_32 AC 24 ms
24,012 KB
testcase_33 TLE -
testcase_34 -- -
testcase_35 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>

// cpp_binarysearch (C) @cielavenir under Boost Software License.
// type F should be something like std::function<bool(T)>.

template<typename T,typename F>
T binarysearch(T lo,T hi,T eps,const F &checker){
	int c=0;
	bool f=true;
	for(;/*lo+eps<hi*/;c++){
		T mi=(lo+hi)/2;
		//if(f)mi=10;
		int z=checker(mi);
		if(z==0)return mi+c;
		if(z==1)lo=mi-1,hi=hi-1;
		if(z==-1)hi=mi-1,lo=lo-1;
		if(lo<0)lo=0;
		if(hi<0)hi=0;
	}
}
template<typename T,typename F>
T binarysearch(T lo,T hi,const F &checker){return binarysearch(lo,hi,1,checker);}

int main(){
	printf("! %d\n",binarysearch(1,1000000000,[&](int t){
		printf("? %d\n",t);
		fflush(stdout);
		int f;
		scanf("%d",&f);
		return f;
	}));
}
0