結果
問題 |
No.850 企業コンテスト2位
|
ユーザー |
|
提出日時 | 2019-07-05 21:55:17 |
言語 | Java (openjdk 23) |
結果 |
RE
|
実行時間 | - |
コード長 | 1,250 bytes |
コンパイル時間 | 2,253 ms |
コンパイル使用メモリ | 85,056 KB |
実行使用メモリ | 73,020 KB |
平均クエリ数 | 237.04 |
最終ジャッジ日時 | 2024-07-16 17:18:23 |
合計ジャッジ時間 | 14,268 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 10 RE * 17 |
ソースコード
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)); } }