結果

問題 No.3212 SUPER Guess the Number
ユーザー ks2m
提出日時 2025-07-25 22:35:45
言語 Java
(openjdk 23)
結果
AC  
実行時間 194 ms / 2,000 ms
コード長 668 bytes
コンパイル時間 4,948 ms
コンパイル使用メモリ 77,544 KB
実行使用メモリ 63,912 KB
平均クエリ数 21.83
最終ジャッジ日時 2025-07-25 22:35:54
合計ジャッジ時間 8,696 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 12
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int[] x = new int[25];
		System.out.println("? 0");
		int i = 0;
		int ok = 1000001;
		int ng = 0;
		while (Math.abs(ok - ng) > 1) {
			int mid = (ok + ng) / 2;
			int cx = x[i];
			i++;
			int nx = mid * 2 + 1 - cx;
			x[i] = nx;
			System.out.println("? " + nx);
			int res = sc.nextInt();
			if (cx < nx) {
				if (res == 0) {
					ok = mid;
				} else {
					ng = mid;
				}
			} else {
				if (res == 1) {
					ok = mid;
				} else {
					ng = mid;
				}
			}
		}
		System.out.println("! " + ok);
		sc.close();
	}
}
0