結果
| 問題 |
No.286 Modulo Discount Store
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-01-31 16:17:27 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 387 ms / 2,000 ms |
| コード長 | 599 bytes |
| コンパイル時間 | 189 ms |
| コンパイル使用メモリ | 82,048 KB |
| 実行使用メモリ | 82,500 KB |
| 最終ジャッジ日時 | 2024-09-28 10:23:02 |
| 合計ジャッジ時間 | 4,418 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 40 |
ソースコード
N=int(input())
M=[]
for _ in range(N):M.append(int(input()))
MAX=1<<N
INF=int(1e18)
dp=[[INF for _ in range(N)] for _ in range(MAX)]
for i in range(N):dp[1<<i][i]=M[i]
for s in range(1,MAX):
for frm in range(N):
if s&(1<<frm)==0:continue
for to in range(N):
if s&(1<<to)==0:continue
bs=s^(1<<to)
if dp[bs][frm]==INF:continue
total=0
for i in range(N):
if bs&(1<<i)>0:total+=M[i]
cost=max(0,M[to]-(total%1000))
dp[s][to]=min(dp[s][to],dp[bs][frm]+cost)
ans=min(dp[-1])
print(ans)