結果

問題 No.31 悪のミックスジュース
ユーザー te-shte-sh
提出日時 2017-02-15 15:41:34
言語 D
(dmd 2.106.1)
結果
WA  
実行時間 -
コード長 1,026 bytes
コンパイル時間 2,266 ms
コンパイル使用メモリ 105,296 KB
実行使用メモリ 39,904 KB
最終ジャッジ日時 2023-09-03 01:31:26
合計ジャッジ時間 16,662 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 914 ms
12,632 KB
testcase_02 AC 1,397 ms
23,864 KB
testcase_03 WA -
testcase_04 AC 2,693 ms
35,436 KB
testcase_05 AC 2,700 ms
39,904 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 31 ms
6,444 KB
testcase_08 AC 22 ms
6,480 KB
testcase_09 AC 2,744 ms
35,756 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 5 ms
5,180 KB
testcase_12 AC 510 ms
13,708 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 13 ms
6,732 KB
testcase_15 AC 2 ms
4,384 KB
testcase_16 AC 4 ms
4,940 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, long)(ec.index, ec.value / (ec.index + 1))).array
    .sort!"a[1] < b[1]".front[0];

  auto dp = new long[]((k + 1) * n * (n + 1) / 2);
  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;
          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