結果

問題 No.429 CupShuffle
ユーザー hermione17hermione17
提出日時 2016-10-02 23:56:59
言語 Java19
(openjdk 21)
結果
AC  
実行時間 651 ms / 2,000 ms
コード長 1,207 bytes
コンパイル時間 5,783 ms
コンパイル使用メモリ 76,188 KB
実行使用メモリ 71,844 KB
最終ジャッジ日時 2023-08-13 18:21:29
合計ジャッジ時間 10,714 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 210 ms
58,324 KB
testcase_01 AC 149 ms
56,996 KB
testcase_02 AC 154 ms
56,680 KB
testcase_03 AC 154 ms
56,468 KB
testcase_04 AC 193 ms
57,256 KB
testcase_05 AC 151 ms
57,116 KB
testcase_06 AC 209 ms
58,088 KB
testcase_07 AC 209 ms
56,960 KB
testcase_08 AC 151 ms
56,492 KB
testcase_09 AC 204 ms
58,348 KB
testcase_10 AC 304 ms
60,844 KB
testcase_11 AC 647 ms
69,688 KB
testcase_12 AC 641 ms
69,508 KB
testcase_13 AC 641 ms
69,732 KB
testcase_14 AC 651 ms
71,844 KB
testcase_15 AC 149 ms
56,436 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.PrintStream;
import java.util.Scanner;


public class Y429 {
	Scanner in;
	PrintStream out;
	
	int nextInt() {
		String s = in.next();
		if (s.charAt(0) == '?') return -1;
		else return Integer.valueOf(s);
	}
	
	Y429() throws Exception {
		in = new Scanner(System.in);
		out = new PrintStream(System.out);
		
		int n = in.nextInt(),
				k = in.nextInt(),
				x = in.nextInt();
		
		int[] a = new int[k],
				b = new int[k],
				c = new int[n],
				d = new int[n];
		
		for (int i = 0; i < k; i++) {
			a[i] = nextInt();
			b[i] = nextInt();
		}
		
		for (int i = 0; i < n; i++) {
			d[i] = i + 1;
			c[i] = nextInt();
		}

		for (int i = 0; i < x - 1; i++) {
			int tmp = d[a[i] - 1];
			d[a[i] - 1] = d[b[i] - 1];
			d[b[i] - 1] = tmp;
		}
		
		for (int i = k-1; i>x - 1; i--) {
			int tmp = c[a[i] - 1];
			c[a[i] - 1] = c[b[i] - 1];
			c[b[i] - 1] = tmp;
		}

		int[] ans = new int[2];
		int cnt = 0;
		
		for (int i = 0; i < n; i++) {
			if (c[i] != d[i]) {
				ans[cnt++] = i + 1;
			}
		}
		
		if (ans[0] < ans[1]) out.println("" + ans[0] + " " + ans[1]);
		else out.println("" + ans[1] + " " + ans[0]);
	}

	public static void main(String argv[]) throws Exception {
		new Y429();
	}
}
0