結果
問題 | No.286 Modulo Discount Store |
ユーザー | rpy3cpp |
提出日時 | 2015-10-09 22:59:05 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 476 ms / 2,000 ms |
コード長 | 718 bytes |
コンパイル時間 | 242 ms |
コンパイル使用メモリ | 12,544 KB |
実行使用メモリ | 13,312 KB |
最終ジャッジ日時 | 2024-07-20 04:26:10 |
合計ジャッジ時間 | 4,543 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 40 |
ソースコード
N = int(input()) Ms = [int(input()) for i in range(N)] dp = [float('inf')] * (1 << N) dp[0] = 0 discount = [0] * (1 << N) full = (1 << N) - 1 for m in range(N): msb = 1 << m for mask in range(1 << m): discount[msb + mask] = (discount[mask] + Ms[m]) % 1000 frontiers = [0] for m in range(N): new_frontiers = [] for f in frontiers: dpf = dp[f] dsc = discount[f] for idx in range(N): bit = 1 << idx if bit & f: continue nf = bit | f if dp[nf] == float('inf'): new_frontiers.append(nf) dp[nf] = min(dp[nf], dpf + max(0, Ms[idx] - dsc)) frontiers = new_frontiers print(dp[full])