結果

問題 No.246 質問と回答
ユーザー takeya_okino
提出日時 2019-08-04 16:32:22
言語 Java
(openjdk 23)
結果
AC  
実行時間 210 ms / 2,000 ms
コード長 519 bytes
コンパイル時間 2,383 ms
コンパイル使用メモリ 76,224 KB
実行使用メモリ 58,700 KB
平均クエリ数 30.97
最終ジャッジ日時 2024-07-16 20:21:26
合計ジャッジ時間 10,457 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int l = 1;
    int r = (int)Math.pow(10, 9) + 1;
    int ans = 0;
    while(l < r) {
      int med = (l + r) / 2;
      System.out.println("?" + " " + med);
      System.out.flush();
      int ret = sc.nextInt();
      if(ret == 1) {
        ans = med;
        l = med + 1;
      } else {
        r = med;
      }
    }
    System.out.println("!" + " " + ans);
    System.out.flush();
  }
}
0