結果
| 問題 | 
                            No.286 Modulo Discount Store
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2022-10-25 14:42:25 | 
| 言語 | PyPy3  (7.3.15)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 99 ms / 2,000 ms | 
| コード長 | 877 bytes | 
| コンパイル時間 | 547 ms | 
| コンパイル使用メモリ | 82,452 KB | 
| 実行使用メモリ | 79,968 KB | 
| 最終ジャッジ日時 | 2024-07-03 13:41:01 | 
| 合計ジャッジ時間 | 3,632 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge4 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 40 | 
ソースコード
#!/usr/bin/python
# -*- coding: utf-8 -*-
# import
from sys import stdin, setrecursionlimit
setrecursionlimit(10**8)
def int_map():
    return map(int,input().split())
def int_list():
    return list(map(int,input().split()))
def int_mtx(N):
    x = [list(map(int, stdin.readline().split())) for _ in range(N)]
    return x
def str_mtx(N):
    x = [list(stdin.readline()[:-1]) for _ in range(N)]
    return x
def print_space(l):
    return print(" ".join([str(x) for x in l]))
"""    main code    """
N = int(input())
M = []
for _ in range(N):
    Mi = int(input())
    M.append(Mi)
dp = [[float("INF"),0] for _ in range(2**N)]
dp[0][0] = 0
for s in range(2**N):
    for u in range(N):
        if s >> u & 1 == 0:
            dp[s+2**u][0] = min(dp[s+2**u][0],dp[s][0]+max(0,M[u]-dp[s][1]))
            dp[s+2**u][1] = (dp[s][1]+M[u])%1000
print(dp[2**N-1][0])