結果

問題 No.253 ロウソクの長さ
ユーザー ciel
提出日時 2015-07-24 23:35:22
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 727 bytes
コンパイル時間 104 ms
コンパイル使用メモリ 22,912 KB
実行使用メモリ 25,220 KB
平均クエリ数 29.72
最終ジャッジ日時 2024-07-16 05:02:24
合計ジャッジ時間 3,373 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 30 WA * 6
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In lambda function:
main.cpp:30:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   30 |                 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){
	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