結果

問題 No.621 3 x N グリッド上のドミノの置き方の数
ユーザー 👑 rin204rin204
提出日時 2022-10-18 23:50:12
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 287 ms / 3,000 ms
コード長 1,534 bytes
コンパイル時間 378 ms
コンパイル使用メモリ 86,948 KB
実行使用メモリ 77,848 KB
最終ジャッジ日時 2023-09-11 15:37:28
合計ジャッジ時間 19,589 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 119 ms
77,488 KB
testcase_01 AC 130 ms
77,788 KB
testcase_02 AC 115 ms
77,356 KB
testcase_03 AC 118 ms
77,696 KB
testcase_04 AC 117 ms
77,348 KB
testcase_05 AC 119 ms
77,688 KB
testcase_06 AC 124 ms
77,492 KB
testcase_07 AC 122 ms
77,688 KB
testcase_08 AC 122 ms
77,256 KB
testcase_09 AC 125 ms
77,368 KB
testcase_10 AC 126 ms
77,416 KB
testcase_11 AC 125 ms
77,496 KB
testcase_12 AC 135 ms
77,324 KB
testcase_13 AC 139 ms
77,360 KB
testcase_14 AC 149 ms
77,704 KB
testcase_15 AC 159 ms
77,376 KB
testcase_16 AC 172 ms
77,296 KB
testcase_17 AC 169 ms
77,340 KB
testcase_18 AC 194 ms
77,344 KB
testcase_19 AC 198 ms
77,340 KB
testcase_20 AC 205 ms
77,564 KB
testcase_21 AC 218 ms
77,344 KB
testcase_22 AC 217 ms
77,272 KB
testcase_23 AC 234 ms
77,304 KB
testcase_24 AC 245 ms
77,444 KB
testcase_25 AC 257 ms
77,452 KB
testcase_26 AC 257 ms
77,520 KB
testcase_27 AC 282 ms
77,620 KB
testcase_28 AC 274 ms
77,344 KB
testcase_29 AC 285 ms
77,508 KB
testcase_30 AC 271 ms
77,428 KB
testcase_31 AC 270 ms
77,848 KB
testcase_32 AC 271 ms
77,560 KB
testcase_33 AC 286 ms
77,552 KB
testcase_34 AC 272 ms
77,516 KB
testcase_35 AC 271 ms
77,312 KB
testcase_36 AC 273 ms
77,432 KB
testcase_37 AC 284 ms
77,348 KB
testcase_38 AC 273 ms
77,388 KB
testcase_39 AC 283 ms
77,440 KB
testcase_40 AC 270 ms
77,728 KB
testcase_41 AC 285 ms
77,436 KB
testcase_42 AC 274 ms
77,516 KB
testcase_43 AC 287 ms
77,472 KB
testcase_44 AC 273 ms
77,268 KB
testcase_45 AC 283 ms
77,344 KB
testcase_46 AC 273 ms
77,500 KB
testcase_47 AC 283 ms
77,484 KB
testcase_48 AC 274 ms
77,516 KB
testcase_49 AC 286 ms
77,436 KB
testcase_50 AC 272 ms
77,508 KB
testcase_51 AC 284 ms
77,744 KB
testcase_52 AC 273 ms
77,440 KB
testcase_53 AC 282 ms
77,352 KB
testcase_54 AC 274 ms
77,308 KB
testcase_55 AC 283 ms
77,312 KB
testcase_56 AC 275 ms
77,728 KB
testcase_57 AC 285 ms
77,304 KB
testcase_58 AC 270 ms
77,388 KB
testcase_59 AC 270 ms
77,312 KB
testcase_60 AC 282 ms
77,344 KB
testcase_61 AC 269 ms
77,436 KB
testcase_62 AC 284 ms
77,328 KB
testcase_63 AC 270 ms
77,408 KB
testcase_64 AC 282 ms
77,384 KB
testcase_65 AC 270 ms
77,408 KB
testcase_66 AC 282 ms
77,768 KB
testcase_67 AC 269 ms
77,568 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

MOD = 10 ** 9 + 7

def matpow(A, B, w):
    l = len(A)
    while w:
        if w & 1:
            C = [0] * l
            for i in range(l):
                for j in range(l):
                    C[i] += A[i][j] * B[j]
                    C[i] %= MOD
            B = C
        C = [[0] * l for _ in range(l)]
        for i in range(l):
            for j in range(l):
                for k in range(l):
                    C[i][j] += A[i][k] * A[k][j]
                    C[i][j] %= MOD
        A = C
        w >>= 1
    return B

n = int(input())
m = 64
A = [[0] * m for _ in range(m)]

def f(x):
    A = []
    for _ in range(3):
        A.append(x & 3)
        x >>= 2
    return A

"""
0: 空
1: 左
2: 右
3: 縦
"""

def tate(A):
    c = A.count(3)
    if c & 1:
        return False
    if c == 2:
        if A[0] == A[2] == 3:
            return False
    if A[0] == A[1] == 0:
        return False
    if A[1] == A[2] == 0:
        return False
    return True

def ok(l, r):
    L = f(l)
    R = f(r)

    if not tate(L) or not tate(R):
        return False
    
    for a, b in zip(L, R):
        if a == b == 0:
            return False
        if a == 2 and b == 1:
            pass
        elif a == 2 or b == 1:
            return False

    return True

for l in range(m):
    for r in range(m):
        if ok(l, r):
            A[r][l] = 1

B = [0] * m
B[1 + 4 + 16] = 1
B = matpow(A, B, n)
ans = 0
for i in range(m):
    A = f(i)
    if 2 in A:
        continue
    if tate(A):
        ans += B[i]

print(ans % MOD)

0