結果

問題 No.31 悪のミックスジュース
ユーザー szkhtsszkhts
提出日時 2021-07-07 10:46:18
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 566 ms / 5,000 ms
コード長 767 bytes
コンパイル時間 76 ms
コンパイル使用メモリ 11,000 KB
実行使用メモリ 8,820 KB
最終ジャッジ日時 2023-09-14 04:36:02
合計ジャッジ時間 6,788 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 34 ms
8,652 KB
testcase_01 AC 510 ms
8,776 KB
testcase_02 AC 531 ms
8,740 KB
testcase_03 AC 566 ms
8,560 KB
testcase_04 AC 558 ms
8,624 KB
testcase_05 AC 564 ms
8,656 KB
testcase_06 AC 13 ms
8,260 KB
testcase_07 AC 554 ms
8,584 KB
testcase_08 AC 543 ms
8,776 KB
testcase_09 AC 546 ms
8,616 KB
testcase_10 AC 14 ms
8,312 KB
testcase_11 AC 143 ms
8,820 KB
testcase_12 AC 363 ms
8,656 KB
testcase_13 AC 19 ms
8,364 KB
testcase_14 AC 566 ms
8,776 KB
testcase_15 AC 100 ms
8,560 KB
testcase_16 AC 205 ms
8,820 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n, v = map(int, input().split())
c = list(map(int, input().split()))
for i in range(1, n):
    c[i] += c[i - 1]

v -= n
if v <= 0:
    print(c[-1])
    exit(0)

num_cost_pairs = list(enumerate(c, 1))

class Rational:
    def __init__(self, p):
        # p[1] / p[0]
        self.n = p[1]
        self.d = p[0]
    def __lt__(self, r):
        return self.n * r.d < self.d * r.n

num_cost_pairs.sort(key=Rational)

(mn, mc), *others = num_cost_pairs
INF = 10 ** 18
MX = 100 * 100
dp = [INF] * (MX + 1)
dp[0] = 0
for i in range(MX):
    for num, cost in others:
        j = i + num
        if j <= MX:
            dp[j] = min(dp[j], dp[i] + cost)
ans = INF
for vi in range(v % mn, min(MX, v) + 1, mn):
    ans = min(ans, dp[vi] + (v - vi) // mn * mc)
print(ans + c[-1])
0