結果

問題 No.253 ロウソクの長さ
ユーザー cielciel
提出日時 2015-07-24 23:35:22
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 727 bytes
コンパイル時間 2,151 ms
コンパイル使用メモリ 25,264 KB
実行使用メモリ 24,420 KB
平均クエリ数 29.72
最終ジャッジ日時 2023-09-23 05:01:13
合計ジャッジ時間 4,459 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
23,940 KB
testcase_01 AC 29 ms
23,904 KB
testcase_02 AC 28 ms
23,508 KB
testcase_03 AC 28 ms
23,424 KB
testcase_04 WA -
testcase_05 AC 35 ms
23,532 KB
testcase_06 AC 32 ms
23,328 KB
testcase_07 AC 29 ms
23,280 KB
testcase_08 AC 30 ms
23,532 KB
testcase_09 WA -
testcase_10 AC 32 ms
23,892 KB
testcase_11 AC 33 ms
23,436 KB
testcase_12 AC 31 ms
23,280 KB
testcase_13 AC 32 ms
24,228 KB
testcase_14 WA -
testcase_15 AC 32 ms
24,228 KB
testcase_16 AC 31 ms
24,228 KB
testcase_17 AC 29 ms
23,532 KB
testcase_18 AC 29 ms
23,280 KB
testcase_19 WA -
testcase_20 AC 32 ms
24,156 KB
testcase_21 AC 31 ms
23,952 KB
testcase_22 WA -
testcase_23 AC 30 ms
23,400 KB
testcase_24 AC 28 ms
23,532 KB
testcase_25 AC 28 ms
24,252 KB
testcase_26 AC 28 ms
23,832 KB
testcase_27 AC 28 ms
23,424 KB
testcase_28 AC 29 ms
23,412 KB
testcase_29 AC 28 ms
23,508 KB
testcase_30 AC 28 ms
23,280 KB
testcase_31 AC 28 ms
23,520 KB
testcase_32 AC 30 ms
24,216 KB
testcase_33 AC 29 ms
23,520 KB
testcase_34 WA -
testcase_35 AC 28 ms
23,544 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+1;
}
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