結果

問題 No.1073 無限すごろく
ユーザー 👑 tamatotamato
提出日時 2020-06-05 22:04:47
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 79 ms / 2,000 ms
コード長 992 bytes
コンパイル時間 293 ms
コンパイル使用メモリ 87,344 KB
実行使用メモリ 76,828 KB
最終ジャッジ日時 2023-08-22 15:35:47
合計ジャッジ時間 4,071 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,616 KB
testcase_01 AC 70 ms
71,712 KB
testcase_02 AC 77 ms
76,812 KB
testcase_03 AC 71 ms
71,824 KB
testcase_04 AC 70 ms
71,452 KB
testcase_05 AC 75 ms
76,140 KB
testcase_06 AC 75 ms
76,140 KB
testcase_07 AC 75 ms
76,320 KB
testcase_08 AC 74 ms
75,888 KB
testcase_09 AC 74 ms
76,136 KB
testcase_10 AC 74 ms
76,260 KB
testcase_11 AC 73 ms
76,240 KB
testcase_12 AC 75 ms
75,964 KB
testcase_13 AC 75 ms
76,716 KB
testcase_14 AC 76 ms
76,588 KB
testcase_15 AC 76 ms
76,764 KB
testcase_16 AC 77 ms
76,820 KB
testcase_17 AC 77 ms
76,788 KB
testcase_18 AC 76 ms
76,788 KB
testcase_19 AC 75 ms
76,588 KB
testcase_20 AC 76 ms
76,764 KB
testcase_21 AC 77 ms
76,760 KB
testcase_22 AC 75 ms
76,708 KB
testcase_23 AC 77 ms
76,648 KB
testcase_24 AC 77 ms
76,472 KB
testcase_25 AC 78 ms
76,472 KB
testcase_26 AC 79 ms
76,732 KB
testcase_27 AC 78 ms
76,652 KB
testcase_28 AC 78 ms
76,472 KB
testcase_29 AC 79 ms
76,736 KB
testcase_30 AC 78 ms
76,796 KB
testcase_31 AC 79 ms
76,828 KB
testcase_32 AC 78 ms
76,720 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 1000000007
six = 166666668
eps = 10**-9


def main():
    import sys
    input = sys.stdin.readline

    def matmul(A, B):
        C = [[0] * len(B[0]) for _ in range(len(A))]
        for i in range(len(A)):
            for k in range(len(B)):
                for j in range(len(B[0])):
                    C[i][j] = (C[i][j] + A[i][k] * B[k][j]) % mod
        return C

    def matpow(A, p):
        n = len(A)
        B = [[0] * n for _ in range(n)]
        for i in range(n):
            B[i][i] = 1
        while p > 0:
            if p & 1:
                B = matmul(B, A)
            A = matmul(A, A)
            p >>= 1
        return B

    N = int(input())
    vec = [[1], [0], [0], [0], [0], [0]]
    mat = [
        [six] * 6,
        [1, 0, 0, 0, 0, 0],
        [0, 1, 0, 0, 0, 0],
        [0, 0, 1, 0, 0, 0],
        [0, 0, 0, 1, 0, 0],
        [0, 0, 0, 0, 1, 0],
    ]
    vec2 = matmul(matpow(mat, N), vec)
    print(vec2[0][0])


if __name__ == '__main__':
    main()
0