結果
問題 | No.429 CupShuffle |
ユーザー | crazybbb3 |
提出日時 | 2016-10-29 14:37:04 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 349 ms / 2,000 ms |
コード長 | 4,030 bytes |
コンパイル時間 | 2,800 ms |
コンパイル使用メモリ | 83,328 KB |
実行使用メモリ | 61,680 KB |
最終ジャッジ日時 | 2024-11-24 17:57:10 |
合計ジャッジ時間 | 6,683 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 110 ms
53,328 KB |
testcase_01 | AC | 81 ms
51,472 KB |
testcase_02 | AC | 90 ms
52,812 KB |
testcase_03 | AC | 85 ms
53,000 KB |
testcase_04 | AC | 106 ms
53,104 KB |
testcase_05 | AC | 87 ms
51,532 KB |
testcase_06 | AC | 111 ms
53,252 KB |
testcase_07 | AC | 113 ms
53,224 KB |
testcase_08 | AC | 85 ms
51,188 KB |
testcase_09 | AC | 108 ms
53,176 KB |
testcase_10 | AC | 190 ms
57,564 KB |
testcase_11 | AC | 349 ms
61,180 KB |
testcase_12 | AC | 325 ms
61,680 KB |
testcase_13 | AC | 334 ms
61,640 KB |
testcase_14 | AC | 347 ms
61,540 KB |
testcase_15 | AC | 82 ms
51,364 KB |
ソースコード
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.lang.reflect.Array; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.StringTokenizer; public class Main { static BufferedReader in; static PrintWriter out; static StringTokenizer tok; void solve() throws IOException { int n = ni(); int k = ni(); int x = ni(); int[] a = new int[k]; int[] b = new int[k]; for (int i = 0; i < k; i++) { if (i != x - 1) { a[i] = ni() - 1; b[i] = ni() - 1; } else { in.readLine(); } } int[] c = nia(n); int[] d = new int[n]; for (int i = 0; i < n; i++) { d[i] = i + 1; } for (int i = 0; i < x - 1; i++) { int tmp = d[a[i]]; d[a[i]] = d[b[i]]; d[b[i]] = tmp; } for (int i = k - 1; i >= x; i--) { int tmp = c[a[i]]; c[a[i]] = c[b[i]]; c[b[i]] = tmp; } ArrayList<Integer> list = new ArrayList<>(); for (int i = 0; i < n; i++) { if (c[i] != d[i]) { list.add(i + 1); } } Collections.sort(list); out.println(list.get(0) + " " + list.get(1)); } void output(int x, int y) { String ans = ""; if (x < 0) { for (int i = 0; i < y; i++) { if (i == 0) ans += "w"; else ans += "wC"; } for (int i = 0; i < x; i++) { ans += "cW"; } } else if (y < 0) { for (int i = 0; i < x; i++) { if (i == 0) ans += "c"; else ans += "cC"; } for (int i = 0; i < x; i++) { ans += "wW"; } } else { for (int i = 0; i < y; i++) { if (i == 0) ans += "c"; else ans += "cC"; } for (int i = 0; i < x; i++) { if ("".equals(ans)) ans += "w"; ans += "wC"; } } out.println(ans); } int gcd(int a, int b) { return a == 0 ? b : gcd(b % a, a); } int lcm(int a, int b) { return a / gcd(a, b) * b; } int[] extgcd(int a, int b, int[] is) { if (a == 0) { is[0] = 0; is[1] = 1; is[2] = b; } else { extgcd(b % a, a, is); int x = is[1] - b / a * is[0]; is[1] = is[0]; is[0] = x; } return is; } String ns() throws IOException { while (!tok.hasMoreTokens()) { tok = new StringTokenizer(in.readLine(), " "); } return tok.nextToken(); } int ni() throws IOException { return Integer.parseInt(ns()); } long nl() throws IOException { return Long.parseLong(ns()); } double nd() throws IOException { return Double.parseDouble(ns()); } String[] nsa(int n) throws IOException { String[] res = new String[n]; for (int i = 0; i < n; i++) { res[i] = ns(); } return res; } int[] nia(int n) throws IOException { int[] res = new int[n]; for (int i = 0; i < n; i++) { res[i] = ni(); } return res; } long[] nla(int n) throws IOException { long[] res = new long[n]; for (int i = 0; i < n; i++) { res[i] = nl(); } return res; } public static void main(String[] args) throws IOException { in = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); tok = new StringTokenizer(""); Main main = new Main(); main.solve(); out.close(); } }