結果

問題 No.286 Modulo Discount Store
ユーザー 👑 tipstar0125tipstar0125
提出日時 2024-01-31 16:17:27
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 397 ms / 2,000 ms
コード長 599 bytes
コンパイル時間 292 ms
コンパイル使用メモリ 81,572 KB
実行使用メモリ 81,936 KB
最終ジャッジ日時 2024-01-31 16:17:32
合計ジャッジ時間 5,262 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
53,460 KB
testcase_01 AC 61 ms
68,464 KB
testcase_02 AC 137 ms
77,024 KB
testcase_03 AC 46 ms
62,100 KB
testcase_04 AC 52 ms
64,176 KB
testcase_05 AC 35 ms
53,460 KB
testcase_06 AC 207 ms
78,992 KB
testcase_07 AC 36 ms
53,460 KB
testcase_08 AC 36 ms
53,460 KB
testcase_09 AC 36 ms
53,460 KB
testcase_10 AC 94 ms
76,288 KB
testcase_11 AC 47 ms
62,100 KB
testcase_12 AC 46 ms
62,100 KB
testcase_13 AC 136 ms
77,152 KB
testcase_14 AC 38 ms
53,460 KB
testcase_15 AC 37 ms
53,460 KB
testcase_16 AC 74 ms
68,476 KB
testcase_17 AC 397 ms
81,936 KB
testcase_18 AC 91 ms
76,168 KB
testcase_19 AC 38 ms
53,460 KB
testcase_20 AC 67 ms
70,388 KB
testcase_21 AC 38 ms
53,460 KB
testcase_22 AC 37 ms
53,460 KB
testcase_23 AC 135 ms
77,152 KB
testcase_24 AC 38 ms
53,460 KB
testcase_25 AC 74 ms
73,244 KB
testcase_26 AC 36 ms
53,460 KB
testcase_27 AC 80 ms
73,372 KB
testcase_28 AC 211 ms
78,992 KB
testcase_29 AC 37 ms
53,460 KB
testcase_30 AC 36 ms
53,460 KB
testcase_31 AC 64 ms
70,408 KB
testcase_32 AC 61 ms
68,324 KB
testcase_33 AC 39 ms
53,460 KB
testcase_34 AC 37 ms
53,460 KB
testcase_35 AC 63 ms
70,536 KB
testcase_36 AC 37 ms
53,460 KB
testcase_37 AC 75 ms
73,244 KB
testcase_38 AC 38 ms
53,460 KB
testcase_39 AC 213 ms
78,992 KB
testcase_40 AC 37 ms
53,460 KB
testcase_41 AC 38 ms
53,460 KB
testcase_42 AC 40 ms
53,460 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N=int(input())
M=[]
for _ in range(N):M.append(int(input()))
MAX=1<<N
INF=int(1e18)
dp=[[INF for _ in range(N)] for _ in range(MAX)]
for i in range(N):dp[1<<i][i]=M[i]
for s in range(1,MAX):
    for frm in range(N):
        if s&(1<<frm)==0:continue
        for to in range(N):
            if s&(1<<to)==0:continue
            bs=s^(1<<to)
            if dp[bs][frm]==INF:continue
            total=0
            for i in range(N):
                if bs&(1<<i)>0:total+=M[i]
            cost=max(0,M[to]-(total%1000))
            dp[s][to]=min(dp[s][to],dp[bs][frm]+cost)
ans=min(dp[-1])
print(ans)
0