結果

問題 No.31 悪のミックスジュース
ユーザー tentententen
提出日時 2021-03-03 19:34:58
言語 Java19
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,483 bytes
コンパイル時間 3,196 ms
コンパイル使用メモリ 73,784 KB
実行使用メモリ 58,124 KB
最終ジャッジ日時 2023-07-26 21:50:20
合計ジャッジ時間 6,619 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 123 ms
55,780 KB
testcase_05 AC 126 ms
56,212 KB
testcase_06 AC 114 ms
56,204 KB
testcase_07 AC 126 ms
55,932 KB
testcase_08 AC 128 ms
56,116 KB
testcase_09 WA -
testcase_10 AC 129 ms
55,740 KB
testcase_11 WA -
testcase_12 AC 127 ms
55,700 KB
testcase_13 AC 119 ms
56,000 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    static long[][] dp;
    static long[] sums;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int v = sc.nextInt();
        sums = new long[n];
        sums[0] = sc.nextInt();
        double min = sums[0];
        int minIdx = 0;
        for (int i = 1; i < n; i++) {
            sums[i] = sums[i - 1] + sc.nextInt();
            if (min > sums[i] / (i + 1.0)) {
                min = sums[i] / (i + 1.0);
                minIdx = i;
            }
        }
        long ans = sums[n - 1];
        v -= n;
        if (v > 0) {
            int div = v / (minIdx + 1);
            ans += sums[minIdx] * div;
            v %= (minIdx + 1);
            dp = new long[n][v + 1];
            for (long[] arr : dp) {
                Arrays.fill(arr, Long.MAX_VALUE / 2);
            }
            ans += dfw(n - 1, v);
        }
        System.out.println(ans);
    }
    
    static long dfw(int idx, int value) {
        if (idx < 0) {
            if (value <= 0) {
                return 0;
            } else {
                return Long.MAX_VALUE / 2;
            }
        }
        if (dp[idx][value] == Long.MAX_VALUE / 2) {
            for (int i = 0; i * (idx + 1) <= value; i++) {
                dp[idx][value] = Math.min(dp[idx][value], dfw(idx - 1, value - i * (idx + 1)) + sums[idx] * i);
            }
        }
        return dp[idx][value];
    }
}
0