結果

問題 No.533 Mysterious Stairs
ユーザー 👑 rin204rin204
提出日時 2022-03-26 14:58:15
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 54 ms / 5,000 ms
コード長 993 bytes
コンパイル時間 139 ms
コンパイル使用メモリ 82,160 KB
実行使用メモリ 66,700 KB
最終ジャッジ日時 2024-04-23 06:55:37
合計ジャッジ時間 2,321 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
55,412 KB
testcase_01 AC 38 ms
53,828 KB
testcase_02 AC 43 ms
60,028 KB
testcase_03 AC 43 ms
61,400 KB
testcase_04 AC 44 ms
61,344 KB
testcase_05 AC 45 ms
61,688 KB
testcase_06 AC 44 ms
62,604 KB
testcase_07 AC 43 ms
62,364 KB
testcase_08 AC 45 ms
63,140 KB
testcase_09 AC 46 ms
62,792 KB
testcase_10 AC 46 ms
62,956 KB
testcase_11 AC 46 ms
64,008 KB
testcase_12 AC 45 ms
64,208 KB
testcase_13 AC 48 ms
62,800 KB
testcase_14 AC 46 ms
63,076 KB
testcase_15 AC 47 ms
62,920 KB
testcase_16 AC 49 ms
65,604 KB
testcase_17 AC 54 ms
65,832 KB
testcase_18 AC 52 ms
65,188 KB
testcase_19 AC 52 ms
65,120 KB
testcase_20 AC 51 ms
65,060 KB
testcase_21 AC 51 ms
65,076 KB
testcase_22 AC 50 ms
66,700 KB
testcase_23 AC 48 ms
66,136 KB
testcase_24 AC 51 ms
65,308 KB
testcase_25 AC 49 ms
65,176 KB
testcase_26 AC 50 ms
64,924 KB
testcase_27 AC 50 ms
66,104 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from copy import deepcopy
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.copy()
        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 = deepcopy(C)
        w >>= 1
    return B

n = int(input())

B =  [1, 1, 1, 0, 1, 0, 1, 0, 0]
A = [[0, 1, 1, 0, 0, 0, 0, 0, 0],
     [0, 0, 0, 1, 0, 1, 0, 0, 0],
     [0, 0, 0, 0, 0, 0, 1, 1, 0],
     [1, 0, 0, 0, 0, 0, 0, 0, 0],
     [0, 1, 0, 0, 0, 0, 0, 0, 0],
     [0, 0, 1, 0, 0, 0, 0, 0, 0],
     [0, 0, 0, 1, 0, 0, 0, 0, 0],
     [0, 0, 0, 0, 1, 0, 0, 0, 0],
     [0, 0, 0, 0, 0, 1, 0, 0, 0]]
     
B = matpow(A, B, n - 1)
ans = sum(B[6:])
print(ans % MOD)
0