結果

問題 No.246 質問と回答
ユーザー YamaKasaYamaKasa
提出日時 2018-09-06 18:17:17
言語 Java21
(openjdk 21)
結果
AC  
実行時間 199 ms / 2,000 ms
コード長 596 bytes
コンパイル時間 3,563 ms
コンパイル使用メモリ 73,512 KB
実行使用メモリ 72,692 KB
平均クエリ数 30.90
最終ジャッジ日時 2023-09-23 20:28:56
合計ジャッジ時間 10,187 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 199 ms
72,316 KB
testcase_01 AC 185 ms
72,296 KB
testcase_02 AC 184 ms
72,288 KB
testcase_03 AC 179 ms
71,636 KB
testcase_04 AC 183 ms
72,692 KB
testcase_05 AC 179 ms
71,960 KB
testcase_06 AC 183 ms
72,008 KB
testcase_07 AC 184 ms
71,820 KB
testcase_08 AC 186 ms
71,444 KB
testcase_09 AC 184 ms
71,984 KB
testcase_10 AC 178 ms
71,836 KB
testcase_11 AC 183 ms
71,832 KB
testcase_12 AC 179 ms
72,184 KB
testcase_13 AC 180 ms
72,352 KB
testcase_14 AC 181 ms
71,720 KB
testcase_15 AC 181 ms
71,544 KB
testcase_16 AC 179 ms
71,920 KB
testcase_17 AC 182 ms
71,868 KB
testcase_18 AC 182 ms
72,680 KB
testcase_19 AC 176 ms
72,052 KB
testcase_20 AC 180 ms
69,820 KB
testcase_21 AC 188 ms
70,492 KB
testcase_22 AC 187 ms
71,908 KB
testcase_23 AC 186 ms
72,304 KB
testcase_24 AC 186 ms
72,208 KB
testcase_25 AC 186 ms
71,984 KB
testcase_26 AC 191 ms
71,924 KB
testcase_27 AC 190 ms
72,500 KB
testcase_28 AC 192 ms
72,232 KB
testcase_29 AC 190 ms
71,596 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int l = 1;
		int r = 1000000000;
		int mid = (l + r) / 2;
		int cnt = 0;
		int n = mid;
		for(int i = 0; i < 100; i++) {
			System.out.println("? " + mid);
			int t = scan.nextInt();
			if(t == 1) {
				l = mid;
				mid = (l + r) / 2;
			}else {
				r = mid;
				mid = (l + r) / 2;
			}
			if(n == mid) {
				cnt++;
			}else {
				cnt = 0;
				n = mid;
			}
			if(r - l == 1) {
				System.out.println("! " + mid);
				System.exit(0);
			}

		}
		scan.close();
	}
}
0