結果
| 問題 | No.253 ロウソクの長さ |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2015-07-24 23:33:29 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 725 bytes |
| 記録 | |
| コンパイル時間 | 101 ms |
| コンパイル使用メモリ | 23,040 KB |
| 実行使用メモリ | 25,604 KB |
| 平均クエリ数 | 29.72 |
| 最終ジャッジ日時 | 2024-07-16 05:02:10 |
| 合計ジャッジ時間 | 3,498 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 29 WA * 7 |
コンパイルメッセージ
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);
| ~~~~~^~~~~~~~~
ソースコード
#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;
}));
}