結果
問題 |
No.1956 猫の額
|
ユーザー |
![]() |
提出日時 | 2025-06-12 18:08:13 |
言語 | PyPy3 (7.3.15) |
結果 |
MLE
|
実行時間 | - |
コード長 | 761 bytes |
コンパイル時間 | 208 ms |
コンパイル使用メモリ | 82,752 KB |
実行使用メモリ | 117,296 KB |
最終ジャッジ日時 | 2025-06-12 18:10:13 |
合計ジャッジ時間 | 24,429 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | MLE * 21 |
ソースコード
n, M, C = map(int, input().split()) A = list(map(int, input().split())) sumA = sum(A) # Initialize DP table. dp[j][k] is the count of ways to choose j elements summing to k. dp = [[0] * (sumA + 1) for _ in range(C + 1)] dp[0][0] = 1 for a in A: # Iterate j from C down to 1 to avoid using the same element multiple times in the same step for j in range(C, 0, -1): # Iterate k from sumA down to a to prevent overwriting values that are yet to be processed for k in range(sumA, a - 1, -1): if dp[j-1][k - a]: dp[j][k] = (dp[j][k] + dp[j-1][k - a]) % M # Prepare the result for C elements, from s=1 to sumA result = [] for s in range(1, sumA + 1): result.append(str(dp[C][s] % M)) print(' '.join(result))