結果

問題 No.31 悪のミックスジュース
ユーザー 👑 colognecologne
提出日時 2022-01-23 14:25:31
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,261 ms / 5,000 ms
コード長 709 bytes
コンパイル時間 279 ms
コンパイル使用メモリ 87,136 KB
実行使用メモリ 109,264 KB
最終ジャッジ日時 2023-08-19 19:16:58
合計ジャッジ時間 11,881 ms
ジャッジサーバーID
(参考情報)
judge14 / judge10
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 235 ms
89,416 KB
testcase_01 AC 639 ms
102,980 KB
testcase_02 AC 654 ms
102,780 KB
testcase_03 AC 905 ms
108,188 KB
testcase_04 AC 895 ms
109,264 KB
testcase_05 AC 889 ms
108,812 KB
testcase_06 AC 231 ms
89,256 KB
testcase_07 AC 1,130 ms
107,588 KB
testcase_08 AC 1,052 ms
107,932 KB
testcase_09 AC 1,261 ms
107,968 KB
testcase_10 AC 234 ms
89,396 KB
testcase_11 AC 238 ms
90,532 KB
testcase_12 AC 400 ms
95,816 KB
testcase_13 AC 233 ms
89,300 KB
testcase_14 AC 878 ms
106,844 KB
testcase_15 AC 236 ms
90,332 KB
testcase_16 AC 247 ms
90,960 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