結果

問題 No.253 ロウソクの長さ
ユーザー cielciel
提出日時 2015-07-24 23:33:29
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 725 bytes
コンパイル時間 183 ms
コンパイル使用メモリ 25,612 KB
実行使用メモリ 24,468 KB
平均クエリ数 29.72
最終ジャッジ日時 2023-09-23 05:00:51
合計ジャッジ時間 3,968 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 26 ms
24,036 KB
testcase_01 AC 25 ms
24,036 KB
testcase_02 AC 25 ms
24,240 KB
testcase_03 AC 25 ms
24,012 KB
testcase_04 WA -
testcase_05 AC 24 ms
23,688 KB
testcase_06 AC 25 ms
24,012 KB
testcase_07 AC 24 ms
24,024 KB
testcase_08 AC 26 ms
23,388 KB
testcase_09 WA -
testcase_10 AC 26 ms
24,024 KB
testcase_11 AC 24 ms
23,424 KB
testcase_12 AC 25 ms
24,396 KB
testcase_13 AC 24 ms
23,652 KB
testcase_14 WA -
testcase_15 AC 25 ms
24,300 KB
testcase_16 AC 25 ms
23,472 KB
testcase_17 AC 25 ms
24,288 KB
testcase_18 AC 25 ms
23,700 KB
testcase_19 WA -
testcase_20 AC 25 ms
23,424 KB
testcase_21 AC 25 ms
23,424 KB
testcase_22 WA -
testcase_23 AC 25 ms
23,424 KB
testcase_24 AC 24 ms
24,396 KB
testcase_25 AC 25 ms
23,436 KB
testcase_26 AC 25 ms
24,036 KB
testcase_27 AC 25 ms
23,376 KB
testcase_28 AC 25 ms
24,048 KB
testcase_29 AC 24 ms
23,700 KB
testcase_30 AC 25 ms
24,036 KB
testcase_31 AC 25 ms
23,652 KB
testcase_32 AC 24 ms
23,460 KB
testcase_33 WA -
testcase_34 WA -
testcase_35 AC 27 ms
24,024 KB
権限があれば一括ダウンロードができます

ソースコード

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;
	}
	return lo+c;
}
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