結果

問題 No.31 悪のミックスジュース
ユーザー szkhtsszkhts
提出日時 2021-07-07 10:45:12
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 845 bytes
コンパイル時間 114 ms
コンパイル使用メモリ 10,952 KB
実行使用メモリ 8,936 KB
最終ジャッジ日時 2023-09-14 04:35:55
合計ジャッジ時間 8,049 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 16 ms
8,244 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 17 ms
8,260 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
権限があれば一括ダウンロードができます

ソースコード

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
print(mn, mc, others)
# 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