結果
| 問題 |
No.1956 猫の額
|
| ユーザー |
gew1fw
|
| 提出日時 | 2025-06-12 18:08:49 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
MLE
|
| 実行時間 | - |
| コード長 | 1,256 bytes |
| コンパイル時間 | 286 ms |
| コンパイル使用メモリ | 82,292 KB |
| 実行使用メモリ | 285,224 KB |
| 最終ジャッジ日時 | 2025-06-12 18:11:06 |
| 合計ジャッジ時間 | 8,896 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | MLE * 21 |
ソースコード
import sys
from collections import defaultdict
def main():
N, M, C = map(int, sys.stdin.readline().split())
A = list(map(int, sys.stdin.readline().split()))
total_sum = sum(A)
# Initialize DP: dp[j] is a dictionary where keys are sums and values are counts mod M
dp = [defaultdict(int) for _ in range(C + 1)]
dp[0][0] = 1 # Base case: 0 elements selected, sum 0
for a in A:
# Process in reverse to avoid overwriting the current state
for j in range(C - 1, -1, -1):
current_dict = dp[j]
next_dict = dp[j + 1]
# Iterate over a copy of the keys to avoid modifying the dict during iteration
for k in list(current_dict.keys()):
count = current_dict[k]
new_sum = k + a
next_dict[new_sum] = (next_dict[new_sum] + count) % M
# Prepare the result for sums from 1 to total_sum
result = [0] * (total_sum + 1)
for s, cnt in dp[C].items():
if 1 <= s <= total_sum:
result[s] = cnt % M
# Generate the output string
output = []
for s in range(1, total_sum + 1):
output.append(str(result[s]))
print(' '.join(output))
if __name__ == '__main__':
main()
gew1fw