結果
問題 | No.621 3 x N グリッド上のドミノの置き方の数 |
ユーザー | 37zigen |
提出日時 | 2017-12-25 03:49:56 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 184 ms / 3,000 ms |
コード長 | 2,481 bytes |
コンパイル時間 | 2,803 ms |
コンパイル使用メモリ | 78,592 KB |
実行使用メモリ | 42,880 KB |
最終ジャッジ日時 | 2024-05-10 00:04:24 |
合計ジャッジ時間 | 15,657 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 138 ms
41,568 KB |
testcase_01 | AC | 154 ms
41,712 KB |
testcase_02 | AC | 135 ms
41,552 KB |
testcase_03 | AC | 137 ms
41,544 KB |
testcase_04 | AC | 139 ms
41,700 KB |
testcase_05 | AC | 138 ms
41,656 KB |
testcase_06 | AC | 146 ms
41,568 KB |
testcase_07 | AC | 158 ms
41,388 KB |
testcase_08 | AC | 163 ms
41,652 KB |
testcase_09 | AC | 162 ms
41,652 KB |
testcase_10 | AC | 153 ms
41,856 KB |
testcase_11 | AC | 166 ms
41,496 KB |
testcase_12 | AC | 171 ms
41,188 KB |
testcase_13 | AC | 176 ms
41,528 KB |
testcase_14 | AC | 166 ms
41,688 KB |
testcase_15 | AC | 167 ms
41,572 KB |
testcase_16 | AC | 172 ms
41,804 KB |
testcase_17 | AC | 166 ms
41,856 KB |
testcase_18 | AC | 169 ms
41,888 KB |
testcase_19 | AC | 170 ms
41,832 KB |
testcase_20 | AC | 169 ms
41,792 KB |
testcase_21 | AC | 171 ms
41,856 KB |
testcase_22 | AC | 171 ms
42,112 KB |
testcase_23 | AC | 172 ms
41,960 KB |
testcase_24 | AC | 171 ms
42,068 KB |
testcase_25 | AC | 179 ms
41,932 KB |
testcase_26 | AC | 177 ms
42,180 KB |
testcase_27 | AC | 175 ms
42,216 KB |
testcase_28 | AC | 174 ms
42,196 KB |
testcase_29 | AC | 173 ms
42,224 KB |
testcase_30 | AC | 174 ms
41,828 KB |
testcase_31 | AC | 180 ms
42,040 KB |
testcase_32 | AC | 167 ms
41,848 KB |
testcase_33 | AC | 173 ms
42,236 KB |
testcase_34 | AC | 175 ms
42,084 KB |
testcase_35 | AC | 175 ms
42,124 KB |
testcase_36 | AC | 177 ms
42,240 KB |
testcase_37 | AC | 182 ms
41,860 KB |
testcase_38 | AC | 175 ms
42,192 KB |
testcase_39 | AC | 178 ms
42,880 KB |
testcase_40 | AC | 177 ms
42,360 KB |
testcase_41 | AC | 176 ms
42,152 KB |
testcase_42 | AC | 182 ms
42,180 KB |
testcase_43 | AC | 180 ms
42,168 KB |
testcase_44 | AC | 183 ms
42,024 KB |
testcase_45 | AC | 184 ms
42,360 KB |
testcase_46 | AC | 176 ms
42,088 KB |
testcase_47 | AC | 177 ms
42,068 KB |
testcase_48 | AC | 181 ms
42,128 KB |
testcase_49 | AC | 177 ms
42,200 KB |
testcase_50 | AC | 169 ms
42,112 KB |
testcase_51 | AC | 180 ms
42,820 KB |
testcase_52 | AC | 178 ms
41,980 KB |
testcase_53 | AC | 176 ms
42,072 KB |
testcase_54 | AC | 180 ms
42,396 KB |
testcase_55 | AC | 177 ms
42,344 KB |
testcase_56 | AC | 183 ms
42,112 KB |
testcase_57 | AC | 174 ms
42,236 KB |
testcase_58 | AC | 175 ms
42,140 KB |
testcase_59 | AC | 178 ms
42,316 KB |
testcase_60 | AC | 156 ms
42,080 KB |
testcase_61 | AC | 179 ms
42,496 KB |
testcase_62 | AC | 182 ms
42,260 KB |
testcase_63 | AC | 171 ms
41,900 KB |
testcase_64 | AC | 172 ms
41,720 KB |
testcase_65 | AC | 171 ms
42,224 KB |
testcase_66 | AC | 172 ms
41,664 KB |
testcase_67 | AC | 179 ms
41,964 KB |
ソースコード
import java.util.Arrays; import java.util.Scanner; class Main { int pow(int a, int n) { return (int) Math.pow(a, n); } int at(int a, int pos) { return a / pow(3, pos) % 3; } final long MOD = 1_000_000_000 + 7; long[][] mul(long[][] a, long[][] b) { long[][] ret = new long[a.length][b[0].length]; for (int i = 0; i < a.length; ++i) { for (int j = 0; j < b[i].length; ++j) { for (int k = 0; k < a[i].length; ++k) { ret[i][j] += a[i][k] * b[k][j] % MOD; ret[i][j] %= MOD; } } } return ret; } long[][] pow(long[][] a, long n) { long[][] ret = new long[a.length][a.length]; for (int i = 0; i < ret.length; ++i) ret[i][i] = 1; for (; n > 0; n >>= 1, a = mul(a, a)) { if (n % 2 == 1) { ret = mul(ret, a); } } return ret; } void run() { Scanner sc = new Scanner(System.in); long n = sc.nextLong(); long[][] mat = new long[3 * 3 * 3][3 * 3 * 3]; //0:空白 //1:未完成 //2:完成 for (int from = 0; from < 3 * 3 * 3; ++from) { in: for (int to = 0; to < 3 * 3 * 3; ++to) { int cur = to; {//未完成が前列に残っていない for (int i = 0; i < 3; ++i) { if (at(from, i) == 1 && at(to, i) != 2) { continue in; } else if (at(from, i) == 1 && at(to, i) == 2) { cur = cur - pow(3, i); } } } if (at(cur, 0) == 2 && at(cur, 1) == 2) { cur -= pow(3, 0); cur -= pow(3, 1); } if (at(cur, 1) == 2 && at(cur, 2) == 2) { cur -= pow(3, 1); cur -= pow(3, 2); } if (at(cur, 0) == 2 || at(cur, 1) == 2 || at(cur, 2) == 2) { continue in; } {//空白が無い for (int i = 0; i < 3; ++i) { if (at(from, i) == 0 && at(to, i) == 0) continue in; } if (at(to, 0) == 0 && at(to, 1) == 0) continue in; if (at(to, 1) == 0 && at(to, 2) == 0) continue in; if (at(from, 0) == 0 && at(from, 1) == 0) continue in; if (at(from, 1) == 0 && at(from, 2) == 0) continue in; } mat[to][from]++; } } long ans = 0; long[][] v = new long[3 * 3 * 3][1]; v[3 * 3 * 3 - 1][0] = 1; v = mul(pow(mat, n), v); for (int i = 0; i < 3 * 3 * 3; ++i) { if (at(i, 0) == 1 || at(i, 1) == 1 || at(i, 2) == 1) continue; ans = (ans + v[i][0]) % MOD; } System.out.println(ans); } void tr(Object... objects) { System.out.println(Arrays.deepToString(objects)); } public static void main(String[] args) { new Main().run(); } }