結果

問題 No.31 悪のミックスジュース
ユーザー 👑 colognecologne
提出日時 2022-01-23 14:24:44
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 701 bytes
コンパイル時間 592 ms
コンパイル使用メモリ 87,012 KB
実行使用メモリ 109,440 KB
最終ジャッジ日時 2023-08-19 19:15:58
合計ジャッジ時間 13,056 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

import itertools
import sys
import fractions

input = sys.stdin.readline


def main():
    N, V = map(int, input().split())
    *C, = itertools.accumulate(map(int, input().split()))

    V -= N
    if V <= 0:
        print(C[-1])
        return

    L = (N**3-N)//2
    DP = [0] + [float('inf')]*L

    for i in range(1, L+1):
        for j in range(N):
            if i > j:
                DP[i] = min(DP[i], DP[i-(j+1)]+C[j])

    if V <= L:
        print(C[-1] + DP[V])
    else:
        target = min(range(N), key=lambda i: fractions.Fraction(C[i], i+1))
        greedy = (V-(L+1))//(target+1) + 1
        print(greedy*C[target] + DP[V-(target+1)*greedy])


if __name__ == '__main__':
    main()
0