結果
問題 | No.429 CupShuffle |
ユーザー | hermione17 |
提出日時 | 2016-10-02 23:56:59 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 753 ms / 2,000 ms |
コード長 | 1,207 bytes |
コンパイル時間 | 4,162 ms |
コンパイル使用メモリ | 79,564 KB |
実行使用メモリ | 68,080 KB |
最終ジャッジ日時 | 2024-11-21 14:57:08 |
合計ジャッジ時間 | 9,490 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 16 |
ソースコード
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(); } }