結果

問題 No.1050 Zero (Maximum)
ユーザー 👑 tamatotamato
提出日時 2020-05-08 21:41:40
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 145 ms / 2,000 ms
コード長 1,046 bytes
コンパイル時間 1,913 ms
コンパイル使用メモリ 87,268 KB
実行使用メモリ 77,456 KB
最終ジャッジ日時 2023-09-17 02:18:56
合計ジャッジ時間 4,893 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,760 KB
testcase_01 AC 87 ms
76,640 KB
testcase_02 AC 95 ms
76,856 KB
testcase_03 AC 100 ms
77,348 KB
testcase_04 AC 119 ms
76,872 KB
testcase_05 AC 124 ms
76,612 KB
testcase_06 AC 100 ms
76,764 KB
testcase_07 AC 103 ms
77,028 KB
testcase_08 AC 81 ms
76,608 KB
testcase_09 AC 91 ms
76,668 KB
testcase_10 AC 133 ms
77,056 KB
testcase_11 AC 117 ms
76,876 KB
testcase_12 AC 80 ms
76,592 KB
testcase_13 AC 72 ms
71,768 KB
testcase_14 AC 72 ms
71,688 KB
testcase_15 AC 73 ms
71,520 KB
testcase_16 AC 139 ms
77,084 KB
testcase_17 AC 145 ms
77,456 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 1000000007
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

    M, K = map(int, input().split())

    mat = [[0] * M for _ in range(M)]
    for now in range(M):
        for m in range(M):
            new_plus = (now + m) % M
            new_mul = (now * m) % M
            mat[new_plus][now] += 1
            mat[new_mul][now] += 1

    ans = [[0] * M]
    ans[0][0] = 1
    ans = matmul(matpow(mat, K), ans)
    print(ans[0][0])


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