結果
| 問題 |
No.253 ロウソクの長さ
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2015-07-25 01:27:23 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 23 ms / 2,000 ms |
| コード長 | 780 bytes |
| コンパイル時間 | 148 ms |
| コンパイル使用メモリ | 24,192 KB |
| 実行使用メモリ | 25,324 KB |
| 平均クエリ数 | 28.81 |
| 最終ジャッジ日時 | 2024-07-16 20:50:53 |
| 合計ジャッジ時間 | 2,747 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 36 |
コンパイルメッセージ
main.cpp: In function ‘int ask(int)’:
main.cpp:8:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
8 | scanf("%d",&f);
| ~~~~~^~~~~~~~~
ソースコード
#include <cstdio>
#include <cstdlib>
int ask(int t){
printf("? %d\n",t);
fflush(stdout);
int f;
scanf("%d",&f);
return f;
}
__attribute__((noreturn)) int ans(int t){
printf("! %d\n",t);
exit(0);
}
// 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(int i=1;lo+eps<hi;i++){
T mi=(lo+hi)/2;
int z=checker(mi-i);
if(z==0)return mi;
if(z==1)lo=mi+1;
if(z==-1)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(){
if(ask(35)==-1)for(int i=1;;i++)if(ask(0)==0)ans(i);
ans(binarysearch(10,1000000000,ask));
}