結果
| 問題 |
No.1956 猫の額
|
| ユーザー |
gew1fw
|
| 提出日時 | 2025-06-12 13:05:30 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
MLE
|
| 実行時間 | - |
| コード長 | 991 bytes |
| コンパイル時間 | 244 ms |
| コンパイル使用メモリ | 82,304 KB |
| 実行使用メモリ | 285,952 KB |
| 最終ジャッジ日時 | 2025-06-12 13:10:52 |
| 合計ジャッジ時間 | 7,985 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | MLE * 21 |
ソースコード
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()
gew1fw