結果

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

テストケース

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

ソースコード

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

  writeln(k);

  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