結果
問題 | No.621 3 x N グリッド上のドミノの置き方の数 |
ユーザー | maspy |
提出日時 | 2020-04-08 14:25:16 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
AC
|
実行時間 | 2,228 ms / 3,000 ms |
コード長 | 1,893 bytes |
コンパイル時間 | 79 ms |
コンパイル使用メモリ | 12,928 KB |
実行使用メモリ | 44,744 KB |
最終ジャッジ日時 | 2024-07-18 11:50:52 |
合計ジャッジ時間 | 102,047 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 517 ms
44,092 KB |
testcase_01 | AC | 577 ms
44,128 KB |
testcase_02 | AC | 510 ms
44,352 KB |
testcase_03 | AC | 509 ms
44,092 KB |
testcase_04 | AC | 530 ms
44,092 KB |
testcase_05 | AC | 534 ms
44,096 KB |
testcase_06 | AC | 546 ms
44,476 KB |
testcase_07 | AC | 551 ms
44,220 KB |
testcase_08 | AC | 557 ms
44,104 KB |
testcase_09 | AC | 545 ms
44,356 KB |
testcase_10 | AC | 543 ms
44,736 KB |
testcase_11 | AC | 541 ms
44,732 KB |
testcase_12 | AC | 616 ms
43,968 KB |
testcase_13 | AC | 654 ms
44,096 KB |
testcase_14 | AC | 755 ms
44,476 KB |
testcase_15 | AC | 870 ms
44,476 KB |
testcase_16 | AC | 922 ms
44,392 KB |
testcase_17 | AC | 927 ms
44,608 KB |
testcase_18 | AC | 1,086 ms
44,744 KB |
testcase_19 | AC | 1,096 ms
44,504 KB |
testcase_20 | AC | 1,212 ms
44,096 KB |
testcase_21 | AC | 1,226 ms
44,356 KB |
testcase_22 | AC | 1,366 ms
44,360 KB |
testcase_23 | AC | 1,377 ms
44,092 KB |
testcase_24 | AC | 1,453 ms
44,356 KB |
testcase_25 | AC | 1,626 ms
44,096 KB |
testcase_26 | AC | 1,631 ms
44,096 KB |
testcase_27 | AC | 1,796 ms
43,964 KB |
testcase_28 | AC | 1,768 ms
44,096 KB |
testcase_29 | AC | 1,864 ms
44,224 KB |
testcase_30 | AC | 1,779 ms
44,744 KB |
testcase_31 | AC | 1,729 ms
44,104 KB |
testcase_32 | AC | 1,655 ms
44,676 KB |
testcase_33 | AC | 1,842 ms
44,480 KB |
testcase_34 | AC | 1,752 ms
44,348 KB |
testcase_35 | AC | 1,684 ms
44,612 KB |
testcase_36 | AC | 1,733 ms
44,356 KB |
testcase_37 | AC | 1,857 ms
44,484 KB |
testcase_38 | AC | 1,889 ms
44,612 KB |
testcase_39 | AC | 1,896 ms
44,480 KB |
testcase_40 | AC | 1,910 ms
44,228 KB |
testcase_41 | AC | 1,914 ms
44,744 KB |
testcase_42 | AC | 1,883 ms
44,224 KB |
testcase_43 | AC | 1,911 ms
44,360 KB |
testcase_44 | AC | 1,896 ms
44,476 KB |
testcase_45 | AC | 1,910 ms
44,648 KB |
testcase_46 | AC | 2,094 ms
44,488 KB |
testcase_47 | AC | 2,027 ms
44,364 KB |
testcase_48 | AC | 1,900 ms
44,356 KB |
testcase_49 | AC | 1,947 ms
44,220 KB |
testcase_50 | AC | 1,898 ms
44,100 KB |
testcase_51 | AC | 1,909 ms
44,352 KB |
testcase_52 | AC | 1,920 ms
44,472 KB |
testcase_53 | AC | 1,917 ms
44,096 KB |
testcase_54 | AC | 1,920 ms
44,224 KB |
testcase_55 | AC | 1,927 ms
44,224 KB |
testcase_56 | AC | 1,924 ms
44,224 KB |
testcase_57 | AC | 1,939 ms
44,484 KB |
testcase_58 | AC | 1,703 ms
44,096 KB |
testcase_59 | AC | 2,173 ms
44,092 KB |
testcase_60 | AC | 2,184 ms
43,968 KB |
testcase_61 | AC | 2,194 ms
43,968 KB |
testcase_62 | AC | 2,228 ms
44,612 KB |
testcase_63 | AC | 1,352 ms
44,232 KB |
testcase_64 | AC | 1,367 ms
44,476 KB |
testcase_65 | AC | 1,372 ms
44,360 KB |
testcase_66 | AC | 1,381 ms
43,964 KB |
testcase_67 | AC | 1,371 ms
44,740 KB |
ソースコード
#!/usr/bin/ python3.8 import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines import itertools import numpy as np MOD = 10 ** 9 + 7 # 0: empty, 1~: RULD def cnt_mat(i, j): x1, y1, z1 = i % 5, (i // 5) % 5, i // 25 x2, y2, z2 = j % 5, (j // 5) % 5, j // 25 # 2つ連続の空マスは許容しない if any(s == t == 0 for s, t in ((x1, x2), (y1, y2), (z1, z2), (x1, y1), (y1, z1), (x2, y2), (y2, z2))): return 0 # 貼り合わせ右 if any(s == 1 and t != 3 for s, t in ((x1, x2), (y1, y2), (z1, z2))): return 0 # 貼り合わせ左 if any(s == 3 and t != 1 for s, t in ((x2, x1), (y2, y1), (z2, z1))): return 0 # 貼り合わせ下 if any(s == 4 and t != 2 for s, t in ((x1, y1), (y1, z1), (x2, y2), (y2, z2))): return 0 # 貼り合わせ上 if any(s != 4 and t == 2 for s, t in ((x1, y1), (y1, z1), (x2, y2), (y2, z2))): return 0 # はみ出し if x1 == 2 or x2 == 2 or z1 == 4 or z2 == 4: return 0 return 1 mat = np.zeros((125, 125), np.int64) for i, j in itertools.product(range(125), repeat=2): mat[i, j] = cnt_mat(i, j) def mat_mul(A, B): mask = (1 << 15) - 1 A1 = A >> 15 A2 = A & mask B1 = B >> 15 B2 = B & mask X = np.dot(A1, B1) % MOD Y = np.dot(A2, B2) % MOD Z = (np.dot(A1 + A2, B1 + B2) - X - Y) % MOD W = (np.dot(A1, B2) + np.dot(A2, B1)) % MOD return ((X << 30) + (Z << 15) + Y) % MOD def power(A, n): if n == 1: return A B = power(A, n // 2) B = mat_mul(B, B) return mat_mul(A, B) if n & 1 else B N = int(read()) init = 93 A = power(mat, N)[init, :] answer = 0 for i in range(125): x, y, z = i % 5, (i // 5) % 5, i // 25 if x != 1 and y != 1 and z != 1 and A[i] != 0: answer += A[i] answer %= MOD print(answer)