結果

問題 No.850 企業コンテスト2位
ユーザー 37zigen37zigen
提出日時 2019-07-05 22:03:01
言語 Java21
(openjdk 21)
結果
RE  
実行時間 -
コード長 1,452 bytes
コンパイル時間 2,448 ms
コンパイル使用メモリ 83,988 KB
実行使用メモリ 75,272 KB
平均クエリ数 164.25
最終ジャッジ日時 2023-09-23 17:27:15
合計ジャッジ時間 13,185 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 216 ms
72,768 KB
testcase_01 RE -
testcase_02 AC 183 ms
72,684 KB
testcase_03 RE -
testcase_04 AC 204 ms
73,476 KB
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 AC 251 ms
73,412 KB
testcase_10 RE -
testcase_11 AC 292 ms
74,272 KB
testcase_12 RE -
testcase_13 AC 288 ms
73,804 KB
testcase_14 RE -
testcase_15 AC 288 ms
73,604 KB
testcase_16 RE -
testcase_17 AC 287 ms
73,016 KB
testcase_18 RE -
testcase_19 AC 290 ms
73,668 KB
testcase_20 RE -
testcase_21 AC 296 ms
73,956 KB
testcase_22 AC 289 ms
74,140 KB
testcase_23 AC 288 ms
74,476 KB
testcase_24 AC 286 ms
73,680 KB
testcase_25 AC 295 ms
72,132 KB
testcase_26 AC 281 ms
74,224 KB
testcase_27 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		new Main().run();
	}

	void run() {

		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		ArrayDeque<Integer> que = new ArrayDeque<>();
		for (int i = 1; i <= N; ++i)
			que.addLast(i);
		ArrayList<Integer>[] loser = new ArrayList[N];
		for (int i = 0; i < N; ++i)
			loser[i] = new ArrayList<>();
		while (que.size() > 1) {
			ArrayDeque<Integer> next = new ArrayDeque<>();
			while (!que.isEmpty()) {
				if (que.size() >= 2) {
					int a = que.pop();
					int b = que.pop();
					System.out.println("? " + a + " " + b);
					int ans = sc.nextInt();
					next.add(ans);
					loser[ans].add((a ^ b) ^ ans);
				} else if (que.size() == 1) {
					next.add(que.pop());
				}
			}
			que = next;
		}
		int first = que.pop();
		for (int v : loser[first])
			que.addLast(v);
		// 2*n-1-n=n-1
		while (que.size() > 1) {
			ArrayDeque<Integer> next = new ArrayDeque<>();
			while (!que.isEmpty()) {
				if (que.size() >= 2) {
					System.out.println("? " + que.pop() + " " + que.pop());
					int ans = sc.nextInt();
					next.add(ans);
				} else if (que.size() == 1) {
					next.add(que.pop());
				}
			}
			que = next;
		}
		int second = que.pop();
		System.out.println("! " + second);
	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}
0