結果

問題 No.429 CupShuffle
ユーザー htensaihtensai
提出日時 2019-11-19 20:53:15
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,039 ms / 2,000 ms
コード長 1,163 bytes
コンパイル時間 2,508 ms
コンパイル使用メモリ 78,932 KB
実行使用メモリ 71,632 KB
最終ジャッジ日時 2024-04-15 00:43:53
合計ジャッジ時間 10,098 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 214 ms
57,404 KB
testcase_01 AC 150 ms
55,160 KB
testcase_02 AC 156 ms
55,036 KB
testcase_03 AC 156 ms
55,276 KB
testcase_04 AC 220 ms
57,872 KB
testcase_05 AC 149 ms
54,888 KB
testcase_06 AC 214 ms
57,948 KB
testcase_07 AC 224 ms
58,344 KB
testcase_08 AC 159 ms
55,312 KB
testcase_09 AC 212 ms
57,136 KB
testcase_10 AC 453 ms
59,464 KB
testcase_11 AC 995 ms
67,064 KB
testcase_12 AC 942 ms
69,228 KB
testcase_13 AC 1,006 ms
65,032 KB
testcase_14 AC 1,039 ms
71,632 KB
testcase_15 AC 137 ms
54,608 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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[] arrA = new int[k + 1];
		int[] arrB = new int[k + 1];
		for (int i = 1; i <= k; i++) {
		    if (i == x) {
		        sc.next();
		        sc.next();
		    } else {
		        arrA[i] = sc.nextInt();
		        arrB[i] = sc.nextInt();
		    }
		}
		int[] starts = new int[n + 1];
		int[] ends = new int[n + 1];
		for (int i = 1; i <= n; i++) {
		    starts[i] = i;
		    ends[i] = sc.nextInt();
		}
		for (int i = 1; i < x; i++) {
		    int tmp = starts[arrA[i]];
		    starts[arrA[i]] = starts[arrB[i]];
		    starts[arrB[i]] = tmp;
		}
		for (int i = k; i > x; i--) {
		    int tmp = ends[arrA[i]];
		    ends[arrA[i]] = ends[arrB[i]];
		    ends[arrB[i]] = tmp;
		}
		int first = 0;
		int second = 0;
		for (int i = 1; i <= n; i++) {
		    if (starts[i] != ends[i]) {
		        if (first == 0) {
		            first = i;
		        } else {
		            second = i;
		            break;
		        }
		    }
		}
		System.out.println(first + " " + second);
	}
}
0