結果

問題 No.1956 猫の額
ユーザー gew1fw
提出日時 2025-06-12 20:49:59
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 909 bytes
コンパイル時間 367 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 284,660 KB
最終ジャッジ日時 2025-06-12 20:53:38
合計ジャッジ時間 9,724 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other MLE * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

def main():
    import sys
    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]))
    idx += N

    sum_total = sum(A)
    dp = [{} for _ in range(C + 1)]
    dp[0][0] = 1

    for a in A:
        for k in range(C, 0, -1):
            if not dp[k-1]:
                continue
            current_dict = dp[k-1]
            for s in list(current_dict.keys()):
                new_s = s + a
                count = current_dict[s]
                if new_s in dp[k]:
                    dp[k][new_s] = (dp[k][new_s] + count) % M
                else:
                    dp[k][new_s] = count % M

    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