結果

問題 No.246 質問と回答
ユーザー atkrym
提出日時 2016-10-23 17:18:50
言語 Java
(openjdk 23)
結果
AC  
実行時間 197 ms / 2,000 ms
コード長 695 bytes
コンパイル時間 2,008 ms
コンパイル使用メモリ 76,368 KB
実行使用メモリ 70,900 KB
平均クエリ数 31.00
最終ジャッジ日時 2024-07-16 20:06:56
合計ジャッジ時間 9,350 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
import java.math.*;
import java.text.*;

public class Main {
    private static Scanner sc = new Scanner(System.in);
    public static void main(String[] args) throws Exception {
        int ans = 500000000;
        int s = 1;
        int e = 1000000000;
        while (true) {
            System.out.println("? " + ans);
            System.out.flush();
            int ret = sc.nextInt();
            if (ret == 1) {
                s = ans;
            } else {
                e = ans-1;
            }

            ans = (s+e)/2+1;
            
            if (s == e) {
                System.out.println("! " + s);
                break;
            }
        }
    }
}
0