結果

問題 No.286 Modulo Discount Store
コンテスト
ユーザー mlihua09
提出日時 2020-09-16 16:04:13
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 82 ms / 2,000 ms
コード長 417 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 270 ms
コンパイル使用メモリ 85,016 KB
実行使用メモリ 81,716 KB
最終ジャッジ日時 2026-03-06 09:03:48
合計ジャッジ時間 2,614 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 40
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code


N = int(input())

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

DP = [10 ** 9] * 2 ** N
X = [0] * 2 ** N

DP[0] = 0

from itertools import combinations

for i in range(1, N + 1):
    
    for C in combinations(range(N), r=i):
        
        x = sum([2 ** c for c in C])
        X[x] = X[x - 2 ** C[0]] + M[C[0]]
        
        DP[x] = min([DP[x - 2 ** c] + max(0, M[c] - X[x - 2 ** c] % 1000) for c in C])
print(DP[-1])
0