結果
| 問題 |
No.1956 猫の額
|
| ユーザー |
lam6er
|
| 提出日時 | 2025-04-15 21:19:14 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
MLE
|
| 実行時間 | - |
| コード長 | 938 bytes |
| コンパイル時間 | 181 ms |
| コンパイル使用メモリ | 82,704 KB |
| 実行使用メモリ | 114,720 KB |
| 最終ジャッジ日時 | 2025-04-15 21:25:07 |
| 合計ジャッジ時間 | 22,203 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | MLE * 21 |
ソースコード
import sys
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]))
total = sum(A)
# Initialize DP table with two layers to save memory
dp = [[0] * (total + 1) for _ in range(C + 1)]
dp[0][0] = 1 % M
for a in A:
# Iterate c from C down to 1 to avoid overwriting data we still need to process
for c in range(C, 0, -1):
# Iterate s from total down to a to ensure we don't reuse the same element multiple times in the same step
for s in range(total, a - 1, -1):
if dp[c - 1][s - a]:
dp[c][s] = (dp[c][s] + dp[c - 1][s - a]) % M
result = []
for s in range(1, total + 1):
result.append(str(dp[C][s] % M))
print(' '.join(result))
if __name__ == '__main__':
main()
lam6er