結果
問題 | No.429 CupShuffle |
ユーザー | crazybbb3 |
提出日時 | 2016-10-29 14:37:04 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 339 ms / 2,000 ms |
コード長 | 4,030 bytes |
コンパイル時間 | 2,447 ms |
コンパイル使用メモリ | 82,948 KB |
実行使用メモリ | 61,704 KB |
最終ジャッジ日時 | 2024-05-03 15:48:13 |
合計ジャッジ時間 | 6,254 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 115 ms
53,096 KB |
testcase_01 | AC | 79 ms
51,296 KB |
testcase_02 | AC | 78 ms
52,572 KB |
testcase_03 | AC | 82 ms
51,120 KB |
testcase_04 | AC | 101 ms
52,784 KB |
testcase_05 | AC | 90 ms
53,108 KB |
testcase_06 | AC | 103 ms
52,856 KB |
testcase_07 | AC | 103 ms
53,244 KB |
testcase_08 | AC | 79 ms
50,868 KB |
testcase_09 | AC | 98 ms
53,008 KB |
testcase_10 | AC | 176 ms
57,616 KB |
testcase_11 | AC | 339 ms
61,172 KB |
testcase_12 | AC | 330 ms
61,568 KB |
testcase_13 | AC | 328 ms
61,508 KB |
testcase_14 | AC | 333 ms
61,704 KB |
testcase_15 | AC | 71 ms
51,308 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(); } }