結果

問題 No.286 Modulo Discount Store
ユーザー tcltktcltk
提出日時 2021-05-17 15:46:15
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 325 ms / 2,000 ms
コード長 1,288 bytes
コンパイル時間 184 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 92,672 KB
最終ジャッジ日時 2024-04-16 04:11:06
合計ジャッジ時間 8,297 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 132 ms
86,528 KB
testcase_01 AC 157 ms
89,216 KB
testcase_02 AC 201 ms
89,472 KB
testcase_03 AC 138 ms
87,296 KB
testcase_04 AC 150 ms
89,652 KB
testcase_05 AC 130 ms
87,000 KB
testcase_06 AC 234 ms
89,472 KB
testcase_07 AC 130 ms
86,772 KB
testcase_08 AC 132 ms
86,784 KB
testcase_09 AC 130 ms
86,656 KB
testcase_10 AC 168 ms
89,472 KB
testcase_11 AC 137 ms
87,124 KB
testcase_12 AC 135 ms
86,784 KB
testcase_13 AC 200 ms
89,472 KB
testcase_14 AC 132 ms
86,528 KB
testcase_15 AC 133 ms
86,676 KB
testcase_16 AC 154 ms
89,344 KB
testcase_17 AC 325 ms
92,672 KB
testcase_18 AC 166 ms
89,548 KB
testcase_19 AC 132 ms
86,784 KB
testcase_20 AC 161 ms
89,344 KB
testcase_21 AC 130 ms
86,680 KB
testcase_22 AC 131 ms
86,528 KB
testcase_23 AC 200 ms
89,472 KB
testcase_24 AC 134 ms
86,912 KB
testcase_25 AC 160 ms
89,088 KB
testcase_26 AC 135 ms
86,720 KB
testcase_27 AC 166 ms
89,600 KB
testcase_28 AC 230 ms
89,644 KB
testcase_29 AC 133 ms
86,784 KB
testcase_30 AC 137 ms
86,656 KB
testcase_31 AC 158 ms
89,344 KB
testcase_32 AC 160 ms
89,088 KB
testcase_33 AC 134 ms
86,780 KB
testcase_34 AC 132 ms
86,784 KB
testcase_35 AC 153 ms
89,728 KB
testcase_36 AC 132 ms
86,908 KB
testcase_37 AC 162 ms
89,216 KB
testcase_38 AC 132 ms
86,784 KB
testcase_39 AC 226 ms
89,344 KB
testcase_40 AC 130 ms
86,604 KB
testcase_41 AC 129 ms
86,400 KB
testcase_42 AC 132 ms
86,784 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#region Header
#!/usr/bin/env python3
# from typing import *

import sys
import io
import math
import collections
import decimal
import itertools
import bisect
import heapq


def input():
    return sys.stdin.readline()[:-1]


# sys.setrecursionlimit(1000000)
#endregion

# _INPUT = """14
# 5060
# 4872
# 2727
# 5342
# 4017
# 6139
# 3309
# 8257
# 7731
# 7938
# 877
# 1419
# 9136
# 9795
# """
# sys.stdin = io.StringIO(_INPUT)


def main():
    N = int(input())
    M = [int(input()) for _ in range(N)]

    dp = [0] * (1<<N)
    for i in range(N):
        dp_next = [0] * (1<<N)

        for s in range(1<<N):
            regular_price = 0
            n = 0
            for j in range(N):
                if s & (1<<j) > 0:
                    n += 1
                    regular_price += M[j]
            if n > i:
                continue
            discount = regular_price % 1000

            for k in range(N):
                # 商品k が購入されていないなら、購入する
                if s & (1<<k) == 0:
                    s1 = s | (1<<k)
                    dp_next[s1] = max(dp_next[s1], dp[s] + min(discount, M[k]))
        dp = dp_next

    max_discount = dp[(1<<N)-1]
    price = sum(M) - max_discount
    print(price)


if __name__ == '__main__':
    main()
0