結果

問題 No.1073 無限すごろく
ユーザー tamatotamato
提出日時 2020-06-05 22:04:47
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 55 ms / 2,000 ms
コード長 992 bytes
コンパイル時間 187 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 61,440 KB
最終ジャッジ日時 2024-05-09 21:19:40
合計ジャッジ時間 2,808 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
52,096 KB
testcase_01 AC 42 ms
52,736 KB
testcase_02 AC 45 ms
59,776 KB
testcase_03 AC 40 ms
52,736 KB
testcase_04 AC 44 ms
52,864 KB
testcase_05 AC 45 ms
58,496 KB
testcase_06 AC 45 ms
58,624 KB
testcase_07 AC 44 ms
58,368 KB
testcase_08 AC 44 ms
58,624 KB
testcase_09 AC 44 ms
58,624 KB
testcase_10 AC 44 ms
58,624 KB
testcase_11 AC 46 ms
58,624 KB
testcase_12 AC 45 ms
58,752 KB
testcase_13 AC 47 ms
59,776 KB
testcase_14 AC 47 ms
60,032 KB
testcase_15 AC 46 ms
59,904 KB
testcase_16 AC 47 ms
59,648 KB
testcase_17 AC 46 ms
59,776 KB
testcase_18 AC 46 ms
59,776 KB
testcase_19 AC 46 ms
59,904 KB
testcase_20 AC 47 ms
59,904 KB
testcase_21 AC 46 ms
60,032 KB
testcase_22 AC 48 ms
60,288 KB
testcase_23 AC 48 ms
60,928 KB
testcase_24 AC 47 ms
60,928 KB
testcase_25 AC 47 ms
61,056 KB
testcase_26 AC 47 ms
61,272 KB
testcase_27 AC 49 ms
61,056 KB
testcase_28 AC 51 ms
61,312 KB
testcase_29 AC 49 ms
61,440 KB
testcase_30 AC 50 ms
61,440 KB
testcase_31 AC 55 ms
61,184 KB
testcase_32 AC 51 ms
61,340 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