結果

問題 No.997 Jumping Kangaroo
ユーザー H3PO4H3PO4
提出日時 2023-06-17 20:20:39
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 134 ms / 2,000 ms
コード長 858 bytes
コンパイル時間 165 ms
コンパイル使用メモリ 11,004 KB
実行使用メモリ 29,780 KB
最終ジャッジ日時 2023-09-07 16:20:07
合計ジャッジ時間 5,679 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 130 ms
29,756 KB
testcase_01 AC 130 ms
29,692 KB
testcase_02 AC 129 ms
29,776 KB
testcase_03 AC 128 ms
29,708 KB
testcase_04 AC 130 ms
29,700 KB
testcase_05 AC 130 ms
29,724 KB
testcase_06 AC 131 ms
29,756 KB
testcase_07 AC 128 ms
29,712 KB
testcase_08 AC 129 ms
29,620 KB
testcase_09 AC 129 ms
29,724 KB
testcase_10 AC 130 ms
29,588 KB
testcase_11 AC 130 ms
29,732 KB
testcase_12 AC 129 ms
29,652 KB
testcase_13 AC 131 ms
29,768 KB
testcase_14 AC 131 ms
29,736 KB
testcase_15 AC 130 ms
29,652 KB
testcase_16 AC 132 ms
29,700 KB
testcase_17 AC 130 ms
29,760 KB
testcase_18 AC 132 ms
29,684 KB
testcase_19 AC 130 ms
29,756 KB
testcase_20 AC 132 ms
29,780 KB
testcase_21 AC 132 ms
29,708 KB
testcase_22 AC 133 ms
29,752 KB
testcase_23 AC 134 ms
29,712 KB
testcase_24 AC 131 ms
29,680 KB
testcase_25 AC 133 ms
29,704 KB
testcase_26 AC 130 ms
29,764 KB
testcase_27 AC 129 ms
29,756 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import numpy as np

N, W, K = map(int, input().split())
A = tuple(map(int, input().split()))
MOD = 10 ** 9 + 7


def pow_matrix_mod(x, n, mod=MOD):
    x = x.astype(object)
    if not n:
        return np.eye(len(x), dtype=object)
    if n % 2 == 0:
        return pow_matrix_mod(x @ x % mod, n // 2) % mod
    else:
        return x @ pow_matrix_mod(x @ x % mod, (n - 1) // 2) % mod


dp1 = [0] * (2 * W + 1)
dp1[0] = 1
for i in range(W + 1):
    dp1[i] %= MOD
    x = dp1[i]
    for a in A:
        if i + a <= W:
            dp1[i + a] += x

dp2 = [0] * (2 * W + 1)
dp2[0] = 1
for i in range(2 * W + 1):
    dp2[i] %= MOD
    if i == W:
        dp2[i] = 0
        continue
    x = dp2[i]
    for a in A:
        if i + a <= 2 * W:
            dp2[i + a] += x

matr = np.array([[0, dp2[2 * W]], [1, dp1[W]]], dtype=int)
print(pow_matrix_mod(matr, K)[1, 1])
0