結果

問題 No.1956 猫の額
ユーザー gew1fw
提出日時 2025-06-12 18:08:37
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 991 bytes
コンパイル時間 264 ms
コンパイル使用メモリ 82,548 KB
実行使用メモリ 285,988 KB
最終ジャッジ日時 2025-06-12 18:10:33
合計ジャッジ時間 6,748 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other MLE * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from collections import defaultdict

def main():
    input = sys.stdin.read().split()
    idx = 0
    N = int(input[idx]); idx +=1
    M = int(input[idx]); idx +=1
    C = int(input[idx]); idx +=1
    A = list(map(int, input[idx:idx+N]))
    sum_total = sum(A)
    
    # Initialize DP: list of defaultdicts for each c (0 to C)
    dp = [defaultdict(int) for _ in range(C+1)]
    dp[0][0] = 1  # Base case: 0 elements selected, sum 0
    
    for a in A:
        # Iterate c from C down to 1 to avoid overwriting
        for c in range(C, 0, -1):
            prev = dp[c-1]
            if not prev:
                continue
            current = dp[c]
            for s_prime, cnt in prev.items():
                s = s_prime + a
                current[s] = (current[s] + cnt) % M
    
    # Prepare the result
    result = []
    for s in range(1, sum_total + 1):
        result.append(str(dp[C].get(s, 0) % M))
    print(' '.join(result))

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