結果

問題 No.850 企業コンテスト2位
ユーザー 37zigen37zigen
提出日時 2019-07-05 21:55:17
言語 Java21
(openjdk 21)
結果
RE  
実行時間 -
コード長 1,250 bytes
コンパイル時間 2,516 ms
コンパイル使用メモリ 77,340 KB
実行使用メモリ 74,952 KB
平均クエリ数 237.04
最終ジャッジ日時 2023-09-23 17:24:42
合計ジャッジ時間 15,194 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 192 ms
72,952 KB
testcase_01 AC 190 ms
73,524 KB
testcase_02 AC 190 ms
72,788 KB
testcase_03 AC 188 ms
72,540 KB
testcase_04 AC 200 ms
72,836 KB
testcase_05 AC 203 ms
72,092 KB
testcase_06 AC 189 ms
73,292 KB
testcase_07 AC 253 ms
72,844 KB
testcase_08 AC 288 ms
73,668 KB
testcase_09 AC 289 ms
71,356 KB
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 AC 191 ms
72,408 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.ArrayDeque;
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);
		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 first=que.pop();
		for(int i=1;i<=N;++i) {
			if(i!=first) {
				que.addLast(i);
			}
		}
		
		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