結果

問題 No.286 Modulo Discount Store
ユーザー 👑 tipstar0125tipstar0125
提出日時 2024-01-31 14:34:36
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 345 ms / 2,000 ms
コード長 658 bytes
コンパイル時間 446 ms
コンパイル使用メモリ 81,572 KB
実行使用メモリ 120,852 KB
最終ジャッジ日時 2024-01-31 14:34:42
合計ジャッジ時間 5,448 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
53,460 KB
testcase_01 AC 62 ms
68,372 KB
testcase_02 AC 128 ms
85,020 KB
testcase_03 AC 44 ms
59,708 KB
testcase_04 AC 49 ms
61,856 KB
testcase_05 AC 37 ms
53,460 KB
testcase_06 AC 186 ms
96,916 KB
testcase_07 AC 39 ms
53,460 KB
testcase_08 AC 38 ms
53,460 KB
testcase_09 AC 38 ms
53,460 KB
testcase_10 AC 98 ms
80,356 KB
testcase_11 AC 43 ms
59,708 KB
testcase_12 AC 44 ms
59,708 KB
testcase_13 AC 122 ms
85,148 KB
testcase_14 AC 37 ms
53,460 KB
testcase_15 AC 43 ms
53,460 KB
testcase_16 AC 60 ms
68,372 KB
testcase_17 AC 345 ms
120,852 KB
testcase_18 AC 97 ms
80,112 KB
testcase_19 AC 37 ms
53,460 KB
testcase_20 AC 68 ms
70,428 KB
testcase_21 AC 37 ms
53,460 KB
testcase_22 AC 37 ms
53,460 KB
testcase_23 AC 115 ms
85,020 KB
testcase_24 AC 37 ms
53,460 KB
testcase_25 AC 76 ms
74,148 KB
testcase_26 AC 37 ms
53,460 KB
testcase_27 AC 74 ms
74,148 KB
testcase_28 AC 187 ms
96,788 KB
testcase_29 AC 37 ms
53,460 KB
testcase_30 AC 37 ms
53,460 KB
testcase_31 AC 71 ms
70,968 KB
testcase_32 AC 61 ms
68,368 KB
testcase_33 AC 37 ms
53,460 KB
testcase_34 AC 37 ms
53,460 KB
testcase_35 AC 57 ms
66,288 KB
testcase_36 AC 39 ms
53,460 KB
testcase_37 AC 76 ms
74,036 KB
testcase_38 AC 37 ms
53,460 KB
testcase_39 AC 184 ms
96,916 KB
testcase_40 AC 37 ms
53,460 KB
testcase_41 AC 36 ms
53,460 KB
testcase_42 AC 37 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,0] for _ in range(N)] for _ in range(MAX)]
for i in range(N):dp[1<<i][i]=[M[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][0]==INF:continue
            cost=max(0,M[to]-(dp[bs][frm][1]%1000))
            if dp[bs][frm][0]+cost<dp[s][to][0]:
                dp[s][to][0]=dp[bs][frm][0]+cost
                dp[s][to][1]=dp[bs][frm][1]+M[to]
ans=INF
for i in range(N):ans=min(ans,dp[-1][i][0])
print(ans)
0