結果

問題 No.31 悪のミックスジュース
ユーザー te-shte-sh
提出日時 2017-02-15 15:56:17
言語 D
(dmd 2.107.1)
結果
AC  
実行時間 197 ms / 5,000 ms
コード長 1,053 bytes
コンパイル時間 908 ms
コンパイル使用メモリ 106,468 KB
実行使用メモリ 6,780 KB
最終ジャッジ日時 2023-09-03 01:31:51
合計ジャッジ時間 2,504 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

import std.algorithm, std.conv, std.range, std.stdio, std.string;
import std.typecons;  // Tuple, Nullable, BigFlags

void main()
{
  auto rd = readln.split, n = rd[0].to!size_t, v = rd[1].to!long;
  auto ci = readln.split.to!(long[]);

  foreach (i, c; ci.drop(1)) ci[i + 1] = ci[i] + c;
  v -= n;

  if (v <= 0) {
    writeln(ci.back);
    return;
  }

  auto k = ci.enumerate!long
    .map!(ec => Tuple!(long, real)(ec.index, ec.value.to!real / (ec.index + 1))).array
    .sort!"a[1] < b[1]".front[0];

  auto dp = new long[]((k + 1) * n);
  dp[] = long.max;
  dp[0] = 0;

  foreach (i; n.iota) {
    auto dp2 = dp.dup;
    foreach (dpi, dpv; dp) {
      if (dpv != long.max) {
        foreach (j; (k + 1).iota) {
          auto idx = dpi + (i + 1) * j;
          if (idx < dp.length)
            dp2[idx] = min(dp2[idx], dpv + ci[i] * j);
        }
      }
    }
    dp = dp2;
  }

  auto r = dp.enumerate!long
    .filter!(d => d.value != long.max)
    .map!(d => d.value + (v - d.index + k) / (k + 1) * ci[k]);

  writeln(r.fold!min + ci.back);
}
0