結果
| 問題 |
No.253 ロウソクの長さ
|
| コンテスト | |
| ユーザー |
latte0119
|
| 提出日時 | 2015-08-06 12:41:55 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 25 ms / 2,000 ms |
| コード長 | 601 bytes |
| コンパイル時間 | 1,273 ms |
| コンパイル使用メモリ | 157,276 KB |
| 実行使用メモリ | 25,220 KB |
| 平均クエリ数 | 22.08 |
| 最終ジャッジ日時 | 2024-07-16 21:10:04 |
| 合計ジャッジ時間 | 3,632 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 36 |
コンパイルメッセージ
main.cpp: In function ‘int ask(int)’:
main.cpp:8:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
8 | scanf("%d",&res);
| ~~~~~^~~~~~~~~~~
ソースコード
#include<bits/stdc++.h>
using namespace std;
int ask(int Y){
printf("? %d\n",Y);
fflush(stdout);
int res;
scanf("%d",&res);
return res;
}
int main(){
int ub,lb,cnt=1;
if(ask(100)==-1){
ub=100;
lb=0;
}
else{
ub=1e9;
lb=0;
}
while(ub-lb>1){
int mid=(ub+lb)/2;
int r=ask(mid);
if(r==1)lb=mid;
else if(r==-1)ub=mid;
else{
printf("! %d\n",mid+cnt);
fflush(stdout);
return 0;
}
cnt++;
ub--;
lb--;
}
return 0;
}
latte0119