結果

問題 No.2215 Slide Subset Sum
ユーザー tktk_snsntktk_snsn
提出日時 2023-02-10 22:49:03
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 884 bytes
コンパイル時間 299 ms
コンパイル使用メモリ 87,236 KB
実行使用メモリ 105,700 KB
最終ジャッジ日時 2023-09-21 23:58:03
合計ジャッジ時間 6,882 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 384 ms
104,984 KB
testcase_01 AC 297 ms
105,700 KB
testcase_02 TLE -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 998244353
div2 = pow(2, mod-2, mod)


def calc_ans(dp, k):
    ans = 0
    for i in range(0, len(dp), k):
        ans += dp[i]
        ans % mod
    return (ans - 1) % mod


def main():
    N, M, K = map(int, input().split())
    A = list(map(lambda x: int(x) % K, input().split()))

    U = (K - 1) * M
    dp = [0] * (U + 1)
    dp[0] = 1

    for i in range(M):
        for j in range(A[i], U+1)[::-1]:
            dp[j] += dp[j-A[i]]
            dp[j] %= mod

    print(calc_ans(dp, K))
    for i in range(M, N):
        for j in range(A[i], U+1)[::-1]:
            dp[j] += dp[j-A[i]]
            dp[j] %= mod
        if A[i-M] != 0:
            for j in range(A[i-M], U+1):
                dp[j] -= dp[j-A[i-M]]
                dp[j] %= mod
        else:
            for j in range(U + 1):
                dp[j] = dp[j] * div2 % mod
        print(calc_ans(dp, K))


main()
0