結果
問題 | No.590 Replacement |
ユーザー | 夕叢霧香(ゆうむらきりか) |
提出日時 | 2017-11-03 23:07:31 |
言語 | Java21 (openjdk 21) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,893 bytes |
コンパイル時間 | 2,252 ms |
コンパイル使用メモリ | 77,372 KB |
実行使用メモリ | 65,352 KB |
最終ジャッジ日時 | 2024-05-02 20:35:13 |
合計ジャッジ時間 | 10,306 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 127 ms
46,412 KB |
testcase_01 | AC | 122 ms
41,192 KB |
testcase_02 | AC | 126 ms
41,424 KB |
testcase_03 | AC | 114 ms
40,120 KB |
testcase_04 | AC | 132 ms
41,212 KB |
testcase_05 | AC | 134 ms
41,324 KB |
testcase_06 | AC | 136 ms
41,208 KB |
testcase_07 | AC | 404 ms
47,108 KB |
testcase_08 | AC | 299 ms
45,852 KB |
testcase_09 | AC | 424 ms
47,120 KB |
testcase_10 | AC | 301 ms
46,056 KB |
testcase_11 | AC | 203 ms
42,932 KB |
testcase_12 | AC | 455 ms
47,120 KB |
testcase_13 | TLE | - |
testcase_14 | -- | - |
testcase_15 | -- | - |
testcase_16 | -- | - |
testcase_17 | -- | - |
testcase_18 | -- | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
testcase_24 | -- | - |
testcase_25 | -- | - |
testcase_26 | -- | - |
testcase_27 | -- | - |
testcase_28 | -- | - |
testcase_29 | -- | - |
testcase_30 | -- | - |
testcase_31 | -- | - |
testcase_32 | -- | - |
testcase_33 | -- | - |
testcase_34 | -- | - |
testcase_35 | -- | - |
testcase_36 | -- | - |
testcase_37 | -- | - |
testcase_38 | -- | - |
testcase_39 | -- | - |
testcase_40 | -- | - |
testcase_41 | -- | - |
testcase_42 | -- | - |
testcase_43 | -- | - |
testcase_44 | -- | - |
testcase_45 | -- | - |
testcase_46 | -- | - |
ソースコード
import java.util.*; class Main { static final long MOD = 1000000007; static int[] inverse(int[] permutation) { int n = permutation.length; int[] result = new int[n]; for (int i = 0; i < n; ++i) { result[permutation[i]] = i; } return result; } static int[] twice(int[] permutation) { int n = permutation.length; int[] result = new int[n]; for (int i = 0; i < n; ++i) { result[i] = permutation[permutation[i]]; } return result; } static final int B = 17; public static void main(String[] args) { Scanner scan = new Scanner(System.in); int n = Integer.parseInt(scan.next()); int[] a = new int[n]; int[] b = new int[n]; for (int i = 0; i < n; ++i) { a[i] = Integer.parseInt(scan.next()) - 1; } for (int i = 0; i < n; ++i) { b[i] = Integer.parseInt(scan.next()) - 1; } int[][] aDouble = new int[B][]; int[][] bDouble = new int[B][]; aDouble[0] = inverse(a); bDouble[0] = inverse(b); for (int i = 1; i < B; ++i) { aDouble[i] = twice(aDouble[i - 1]); bDouble[i] = twice(bDouble[i - 1]); } // System.err.println(Arrays.deepToString(aDouble)); // System.err.println(Arrays.deepToString(bDouble)); long total = 0; for (int i = 0; i < n; ++i) { // (i, i) no gyaku long pos = 0; int ai = i; int bi = i; while (true) { if (pos > 0 && ai == bi) { break; } ai = aDouble[0][ai]; bi = bDouble[0][bi]; pos++; } total = (total + pos * (pos - 1) / 2) % MOD; } System.out.println(total); } }