結果

問題 No.513 宝探し2
ユーザー aim_cpoaim_cpo
提出日時 2018-02-26 02:48:19
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 28 ms / 2,000 ms
コード長 786 bytes
コンパイル時間 1,347 ms
コンパイル使用メモリ 164,860 KB
実行使用メモリ 24,252 KB
平均クエリ数 22.58
最終ジャッジ日時 2023-09-23 15:51:21
合計ジャッジ時間 2,535 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
24,060 KB
testcase_01 AC 24 ms
23,820 KB
testcase_02 AC 23 ms
23,628 KB
testcase_03 AC 24 ms
24,000 KB
testcase_04 AC 24 ms
24,000 KB
testcase_05 AC 22 ms
23,976 KB
testcase_06 AC 24 ms
24,252 KB
testcase_07 AC 23 ms
23,652 KB
testcase_08 AC 22 ms
23,640 KB
testcase_09 AC 22 ms
24,216 KB
testcase_10 AC 24 ms
23,412 KB
testcase_11 AC 24 ms
24,024 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

inline int check(int minx,int maxx){
  cout<<minx<<" "<<0<<"\n";
  int d1;cin>>d1;
  if(d1==0)return -1;
  cout<<maxx<<" "<<0<<"\n";
  int d2;cin>>d2;
  if(d2==0)return -1;
  if(d1==d2)return 0;
  else if(d1>d2)return 2;
  else return 1;
}

int main(){
  int minx=0,maxx=100000;
  int resx=0;
  bool flag=0;
  while(maxx-minx>1){
    int temp=check(minx,maxx);
    if(temp==-1)return 0;
    else if(temp==0){
      resx=(minx+maxx)/2;
      flag=1;
      break;
    }else if(temp==1){
      maxx=(minx+maxx)/2;
    }else{
      minx=(minx+maxx)/2;
    }
  }
  if(!flag){
    int temp=check(minx,maxx);
    if(temp==1)resx=minx;
    else resx=maxx;
  }
  cout<<resx<<" "<<0<<endl;
  int dd;cin>>dd;
  cout<<resx<<" "<<dd<<endl;
  return 0;
}
0