結果

問題 No.31 悪のミックスジュース
ユーザー KudeKude
提出日時 2020-09-05 18:39:39
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 100 ms / 5,000 ms
コード長 819 bytes
コンパイル時間 1,059 ms
コンパイル使用メモリ 86,980 KB
実行使用メモリ 76,180 KB
最終ジャッジ日時 2023-08-19 12:19:36
合計ジャッジ時間 4,551 ms
ジャッジサーバーID
(参考情報)
judge10 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 83 ms
75,980 KB
testcase_01 AC 96 ms
75,884 KB
testcase_02 AC 92 ms
75,916 KB
testcase_03 AC 93 ms
75,796 KB
testcase_04 AC 94 ms
75,940 KB
testcase_05 AC 94 ms
75,936 KB
testcase_06 AC 78 ms
71,176 KB
testcase_07 AC 98 ms
76,100 KB
testcase_08 AC 100 ms
76,180 KB
testcase_09 AC 93 ms
76,084 KB
testcase_10 AC 78 ms
71,172 KB
testcase_11 AC 88 ms
76,072 KB
testcase_12 AC 91 ms
75,880 KB
testcase_13 AC 83 ms
75,932 KB
testcase_14 AC 95 ms
76,180 KB
testcase_15 AC 85 ms
75,936 KB
testcase_16 AC 90 ms
75,968 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
# can assume each pair in others not be taken >100 times
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