結果

問題 No.246 質問と回答
ユーザー YamaKasaYamaKasa
提出日時 2018-09-06 18:14:13
言語 Java21
(openjdk 21)
結果
AC  
実行時間 210 ms / 2,000 ms
コード長 594 bytes
コンパイル時間 4,133 ms
コンパイル使用メモリ 73,804 KB
実行使用メモリ 73,756 KB
平均クエリ数 32.23
最終ジャッジ日時 2023-09-23 20:28:33
合計ジャッジ時間 10,482 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 210 ms
71,688 KB
testcase_01 AC 196 ms
71,972 KB
testcase_02 AC 199 ms
71,528 KB
testcase_03 AC 194 ms
72,132 KB
testcase_04 AC 202 ms
73,756 KB
testcase_05 AC 203 ms
72,032 KB
testcase_06 AC 207 ms
72,040 KB
testcase_07 AC 199 ms
72,488 KB
testcase_08 AC 198 ms
72,444 KB
testcase_09 AC 203 ms
72,236 KB
testcase_10 AC 201 ms
72,032 KB
testcase_11 AC 203 ms
71,568 KB
testcase_12 AC 201 ms
71,716 KB
testcase_13 AC 199 ms
71,572 KB
testcase_14 AC 201 ms
72,228 KB
testcase_15 AC 207 ms
71,984 KB
testcase_16 AC 205 ms
70,304 KB
testcase_17 AC 206 ms
72,084 KB
testcase_18 AC 205 ms
71,772 KB
testcase_19 AC 202 ms
70,000 KB
testcase_20 AC 204 ms
72,560 KB
testcase_21 AC 199 ms
69,488 KB
testcase_22 AC 204 ms
72,080 KB
testcase_23 AC 202 ms
71,900 KB
testcase_24 AC 201 ms
72,128 KB
testcase_25 AC 201 ms
71,752 KB
testcase_26 AC 201 ms
72,056 KB
testcase_27 AC 200 ms
72,304 KB
testcase_28 AC 202 ms
72,176 KB
testcase_29 AC 197 ms
72,732 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(cnt == 2) {
				System.out.println("! " + mid);
				System.exit(0);
			}

		}
		scan.close();
	}
}
0