結果
問題 |
No.429 CupShuffle
|
ユーザー |
![]() |
提出日時 | 2020-12-08 08:39:01 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 968 ms / 2,000 ms |
コード長 | 1,605 bytes |
コンパイル時間 | 2,958 ms |
コンパイル使用メモリ | 80,424 KB |
実行使用メモリ | 73,596 KB |
最終ジャッジ日時 | 2024-09-17 14:27:02 |
合計ジャッジ時間 | 10,115 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 16 |
ソースコード
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int k = sc.nextInt(); int x = sc.nextInt(); int[] arr = new int[n]; for (int i = 0; i < n; i++) { arr[i] = i + 1; } ArrayDeque<Integer> lefts = new ArrayDeque<>(); ArrayDeque<Integer> rights = new ArrayDeque<>(); for (int i = 0; i < k; i++) { if (i == x - 1) { sc.next(); sc.next(); continue; } int a = sc.nextInt() - 1; int b = sc.nextInt() - 1; if (i < x - 1) { int tmp = arr[a]; arr[a] = arr[b]; arr[b] = tmp; } else { lefts.push(a); rights.push(b); } } int[] results = new int [n]; for (int i = 0; i < n; i++) { results[i] = sc.nextInt(); } while (lefts.size() > 0) { int a = lefts.pop(); int b = rights.pop(); int tmp = results[a]; results[a] = results[b]; results[b] = tmp; } int first = 0; int second = 0; for (int i = 0; i < n; i++) { if (arr[i] != results[i]) { if (first == 0) { first = i + 1; } else { second = i + 1; } } } System.out.println(first + " " + second); } }