結果

問題 No.246 質問と回答
ユーザー ciel
提出日時 2015-07-17 22:49:51
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 60 ms / 2,000 ms
コード長 601 bytes
コンパイル時間 165 ms
コンパイル使用メモリ 22,784 KB
実行使用メモリ 25,220 KB
平均クエリ数 30.90
最終ジャッジ日時 2024-07-16 19:42:20
合計ジャッジ時間 3,741 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 30
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In lambda function:
main.cpp:26:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   26 |                 scanf("%d",&f);
      |                 ~~~~~^~~~~~~~~

ソースコード

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){
	for(;lo+eps<hi;){
		T mi=(lo+hi)/2;
		if(checker(mi)){
			lo=mi;
		}else{
			hi=mi;
		}
	}
	return lo;
}
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