結果

問題 No.286 Modulo Discount Store
ユーザー efunyoefunyo
提出日時 2020-03-27 13:32:05
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 182 ms / 2,000 ms
コード長 1,082 bytes
コンパイル時間 829 ms
コンパイル使用メモリ 87,044 KB
実行使用メモリ 78,836 KB
最終ジャッジ日時 2023-08-30 16:23:01
合計ジャッジ時間 7,008 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 96 ms
71,580 KB
testcase_01 AC 108 ms
77,272 KB
testcase_02 AC 131 ms
78,676 KB
testcase_03 AC 103 ms
76,532 KB
testcase_04 AC 105 ms
77,324 KB
testcase_05 AC 93 ms
71,556 KB
testcase_06 AC 144 ms
78,540 KB
testcase_07 AC 93 ms
71,532 KB
testcase_08 AC 92 ms
71,432 KB
testcase_09 AC 93 ms
71,804 KB
testcase_10 AC 122 ms
77,468 KB
testcase_11 AC 101 ms
76,524 KB
testcase_12 AC 101 ms
76,580 KB
testcase_13 AC 135 ms
78,652 KB
testcase_14 AC 94 ms
71,612 KB
testcase_15 AC 94 ms
71,264 KB
testcase_16 AC 108 ms
77,620 KB
testcase_17 AC 182 ms
78,836 KB
testcase_18 AC 123 ms
77,616 KB
testcase_19 AC 94 ms
71,676 KB
testcase_20 AC 116 ms
77,736 KB
testcase_21 AC 95 ms
71,404 KB
testcase_22 AC 97 ms
71,504 KB
testcase_23 AC 137 ms
78,692 KB
testcase_24 AC 97 ms
71,872 KB
testcase_25 AC 122 ms
77,860 KB
testcase_26 AC 94 ms
71,844 KB
testcase_27 AC 120 ms
77,696 KB
testcase_28 AC 144 ms
78,120 KB
testcase_29 AC 95 ms
71,696 KB
testcase_30 AC 96 ms
71,272 KB
testcase_31 AC 115 ms
77,556 KB
testcase_32 AC 119 ms
77,600 KB
testcase_33 AC 95 ms
71,708 KB
testcase_34 AC 96 ms
71,580 KB
testcase_35 AC 113 ms
77,588 KB
testcase_36 AC 92 ms
71,532 KB
testcase_37 AC 119 ms
77,624 KB
testcase_38 AC 98 ms
71,272 KB
testcase_39 AC 147 ms
78,272 KB
testcase_40 AC 95 ms
71,564 KB
testcase_41 AC 92 ms
71,684 KB
testcase_42 AC 94 ms
71,272 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#https://yukicoder.me/problems/528
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate
    #from itertools import product
    from bisect import bisect_left,bisect_right
    import heapq
    from math import floor, ceil
    #from operator import itemgetter

    inf = 10**17
    #mod = 10**9 + 7

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

    dp = [inf]*(1<<N)
    dp[-1] = 0

    def dfs(s):
        if dp[s]!=inf:
            return dp[s]
        
        for i in range(N):
            if s&(1<<i):
                continue
            #品物iを買うことでかかる金額
            total = 0
            for j in range(N):
                if s&(1<<j):
                    total += M[j]
            cost = max(M[i] - total%1000, 0)
            dp[s] = min(dp[s], dfs(s|(1<<i)) + cost)
        return dp[s]

    print(dfs(0))

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