結果
問題 | No.429 CupShuffle |
ユーザー |
|
提出日時 | 2018-06-11 00:07:51 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 1,136 ms / 2,000 ms |
コード長 | 1,131 bytes |
コンパイル時間 | 3,586 ms |
コンパイル使用メモリ | 80,484 KB |
実行使用メモリ | 73,908 KB |
最終ジャッジ日時 | 2024-06-30 13:24:48 |
合計ジャッジ時間 | 11,872 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 16 |
ソースコード
import java.util.*;public class No429{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[] start = new int[N];for(int i = 0; i < N; i++){start[i] = i+1;}int[][] AB = new int[K][2];for(int i = 0; i < K; i++){if(i == X-1){String a = sc.next();String b = sc.next();AB[i][0] = 0;AB[i][1] = 0;continue;}AB[i][0] = sc.nextInt();AB[i][1] = sc.nextInt();}int[] C = new int[N];for(int i = 0; i < N; i++){C[i] = sc.nextInt();}for(int i = 0; i < X-1; i++){start = perm(start, AB[i][0]-1, AB[i][1]-1);}for(int i = K-1; i > X-1; i--){C = perm(C, AB[i][0]-1, AB[i][1]-1);}List<Integer> answer = new ArrayList<Integer>();for(int i = 0; i < N; i++){if(start[i] != C[i]) answer.add(i+1);}System.out.println(answer.get(0)+" "+answer.get(1));}private static int[] perm(int[] list, int idx1, int idx2){int num1 = list[idx1];int num2 = list[idx2];list[idx1] = num2;list[idx2] = num1;return list;}}