結果

問題 No.997 Jumping Kangaroo
ユーザー tamatotamato
提出日時 2020-03-18 11:40:23
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 81 ms / 2,000 ms
コード長 1,105 bytes
コンパイル時間 300 ms
コンパイル使用メモリ 86,912 KB
実行使用メモリ 75,556 KB
最終ジャッジ日時 2023-08-20 19:46:37
合計ジャッジ時間 3,941 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,428 KB
testcase_01 AC 75 ms
71,316 KB
testcase_02 AC 78 ms
71,428 KB
testcase_03 AC 75 ms
71,224 KB
testcase_04 AC 76 ms
71,504 KB
testcase_05 AC 75 ms
71,148 KB
testcase_06 AC 75 ms
71,236 KB
testcase_07 AC 75 ms
71,156 KB
testcase_08 AC 76 ms
71,320 KB
testcase_09 AC 78 ms
71,036 KB
testcase_10 AC 76 ms
71,368 KB
testcase_11 AC 76 ms
71,388 KB
testcase_12 AC 75 ms
71,452 KB
testcase_13 AC 75 ms
71,308 KB
testcase_14 AC 75 ms
71,316 KB
testcase_15 AC 74 ms
71,216 KB
testcase_16 AC 80 ms
75,556 KB
testcase_17 AC 73 ms
71,408 KB
testcase_18 AC 78 ms
75,212 KB
testcase_19 AC 75 ms
70,976 KB
testcase_20 AC 81 ms
75,396 KB
testcase_21 AC 76 ms
71,192 KB
testcase_22 AC 78 ms
75,492 KB
testcase_23 AC 79 ms
75,428 KB
testcase_24 AC 75 ms
71,092 KB
testcase_25 AC 75 ms
71,320 KB
testcase_26 AC 75 ms
71,284 KB
testcase_27 AC 77 ms
70,988 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

    mod = 1000000007
    N, W, K = map(int, input().split())
    A = list(map(int, input().split()))

    def matmul(A, B):
        C = [[0] * len(B[0]) for _ in range(len(A))]
        for i in range(len(A)):
            for j in range(len(B[0])):
                for k in range(len(B)):
                    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

    dp = [0] * (2*W+1)
    dp[0] = 1
    for i in range(2*W):
        for a in A:
            if i+a <= 2*W:
                dp[i+a] = (dp[i+a] + dp[i])%mod
    w = dp[W]
    ww = (dp[W*2] - w**2)%mod
    if K == 1:
        print(w)
        exit()

    mat = [[w, ww], [1, 0]]
    vec = [[w], [1]]
    ans = matmul(matpow(mat, K-1), vec)
    print(ans[0][0])


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