結果

問題 No.31 悪のミックスジュース
ユーザー nebukuro09nebukuro09
提出日時 2018-06-01 15:11:42
言語 D
(dmd 2.105.2)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 1,105 bytes
コンパイル時間 822 ms
コンパイル使用メモリ 113,556 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-03 20:16:11
合計ジャッジ時間 1,798 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, std.bitmanip;

immutable long INF = 1L << 59;

void main() {
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto V = s[1];
    auto C = readln.split.map!(to!long).array;

    if (N >= V) {
        C.sum.writeln;
        return;
    }

    long ans = C.sum;
    V -= N;

    auto P = new Tuple!(int, long)[](N);
    long c = C.sum;
    
    foreach_reverse (i; 0..N) {
        P[i] = tuple(i+1, c);
        c -= C[i];
    }

    if (V > 10000) {
        int VV = V - 10000;
        P.sort!"a[1]*b[0] < a[0]*b[1]";
        ans += P[0][1] * (VV / P[0][0]);
        VV %= P[0][0];
        V = 10000 + VV;
    }

    auto dp = new long[](10200);
    fill(dp, INF);
    dp[0] = 0;

    foreach (i; 0..N) {
        int v = P[i][0];
        long cost = P[i][1];
        foreach (j; 0..10200-v) {
            dp[j+v] = min(dp[j+v], dp[j] + cost);
        }
    }

    ans += dp[V..10200].reduce!min;
    ans.writeln;
}
0