結果
問題 | No.429 CupShuffle |
ユーザー | tenten |
提出日時 | 2020-12-08 08:39:01 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 1,073 ms / 2,000 ms |
コード長 | 1,605 bytes |
コンパイル時間 | 2,707 ms |
コンパイル使用メモリ | 79,904 KB |
実行使用メモリ | 72,764 KB |
最終ジャッジ日時 | 2023-10-17 17:00:00 |
合計ジャッジ時間 | 10,927 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 221 ms
61,108 KB |
testcase_01 | AC | 152 ms
58,284 KB |
testcase_02 | AC | 157 ms
58,316 KB |
testcase_03 | AC | 155 ms
58,456 KB |
testcase_04 | AC | 216 ms
60,260 KB |
testcase_05 | AC | 153 ms
58,336 KB |
testcase_06 | AC | 226 ms
61,204 KB |
testcase_07 | AC | 227 ms
61,712 KB |
testcase_08 | AC | 159 ms
58,376 KB |
testcase_09 | AC | 227 ms
60,968 KB |
testcase_10 | AC | 445 ms
62,188 KB |
testcase_11 | AC | 958 ms
70,916 KB |
testcase_12 | AC | 957 ms
72,680 KB |
testcase_13 | AC | 1,073 ms
72,680 KB |
testcase_14 | AC | 1,002 ms
72,764 KB |
testcase_15 | AC | 150 ms
58,196 KB |
ソースコード
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[] arr = new int[n]; for (int i = 0; i < n; i++) { arr[i] = i + 1; } ArrayDeque<Integer> lefts = new ArrayDeque<>(); ArrayDeque<Integer> rights = new ArrayDeque<>(); for (int i = 0; i < k; i++) { if (i == x - 1) { sc.next(); sc.next(); continue; } int a = sc.nextInt() - 1; int b = sc.nextInt() - 1; if (i < x - 1) { int tmp = arr[a]; arr[a] = arr[b]; arr[b] = tmp; } else { lefts.push(a); rights.push(b); } } int[] results = new int [n]; for (int i = 0; i < n; i++) { results[i] = sc.nextInt(); } while (lefts.size() > 0) { int a = lefts.pop(); int b = rights.pop(); int tmp = results[a]; results[a] = results[b]; results[b] = tmp; } int first = 0; int second = 0; for (int i = 0; i < n; i++) { if (arr[i] != results[i]) { if (first == 0) { first = i + 1; } else { second = i + 1; } } } System.out.println(first + " " + second); } }