結果

問題 No.286 Modulo Discount Store
ユーザー tobusakana
提出日時 2022-10-23 19:54:38
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 70 ms / 2,000 ms
コード長 582 bytes
コンパイル時間 216 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 68,224 KB
最終ジャッジ日時 2024-07-02 10:21:11
合計ジャッジ時間 3,618 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 40
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
readline = sys.stdin.readline

N = int(readline())
M = [int(readline()) for i in range(N)]

INF = 1 << 60
dp = [INF] * (1 << N)
dp[0] = 0

for status in range(1 << N):
  # 現状態でのdiscount額を求める
  discount = 0
  for i in range(N):
    if (status >> i) & 1:
      discount += M[i]
  discount %= 1000
  for target in range(N):
    if (status >> target) & 1:
      continue
    next_status = status | (1 << target)
    price = max(0, M[target] - discount)
    if dp[next_status] > dp[status] + price:
      dp[next_status] = dp[status] + price

print(dp[-1])
0