結果

問題 No.31 悪のミックスジュース
コンテスト
ユーザー nebukuro09
提出日時 2018-06-01 14:09:36
言語 D
(dmd 2.112.0)
コンパイル:
dmd -fPIE -m64 -w -wi -O -release -inline -I/opt/dmd/src/druntime/import/ -I/opt/dmd/src/phobos -L-L/opt/dmd/linux/lib64/ -fPIC _filename_
実行:
./Main
結果
WA  
実行時間 -
コード長 1,139 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 779 ms
コンパイル使用メモリ 105,324 KB
実行使用メモリ 7,720 KB
最終ジャッジ日時 2026-03-05 20:36:54
合計ジャッジ時間 1,429 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 7 WA * 10
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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 << 50;

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];
    }

    P.sort!"a[1]*b[0] < a[0]*b[1]";
    ans += P[0][1] * (V / P[0][0]);
    V %= P[0][0];


    auto dp = new long[][](N+1, V+200);
    foreach (i; 0..N+1) fill(dp[i], INF);
    dp[0][0] = 0;

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

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