結果

問題 No.31 悪のミックスジュース
ユーザー 👑 colognecologne
提出日時 2022-01-23 14:25:31
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,054 ms / 5,000 ms
コード長 709 bytes
コンパイル時間 181 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 107,520 KB
最終ジャッジ日時 2024-05-07 02:12:27
合計ジャッジ時間 9,467 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 129 ms
88,576 KB
testcase_01 AC 534 ms
101,120 KB
testcase_02 AC 547 ms
101,720 KB
testcase_03 AC 814 ms
106,544 KB
testcase_04 AC 808 ms
107,300 KB
testcase_05 AC 799 ms
107,520 KB
testcase_06 AC 132 ms
88,576 KB
testcase_07 AC 953 ms
105,600 KB
testcase_08 AC 949 ms
106,056 KB
testcase_09 AC 1,054 ms
106,368 KB
testcase_10 AC 127 ms
88,448 KB
testcase_11 AC 137 ms
89,124 KB
testcase_12 AC 304 ms
94,464 KB
testcase_13 AC 134 ms
88,420 KB
testcase_14 AC 743 ms
105,216 KB
testcase_15 AC 141 ms
88,960 KB
testcase_16 AC 146 ms
89,216 KB
権限があれば一括ダウンロードができます

ソースコード

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(C[-1] + greedy*C[target] + DP[V-(target+1)*greedy])


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