結果
| 問題 |
No.31 悪のミックスジュース
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-07-30 21:34:04 |
| 言語 | D (dmd 2.109.1) |
| 結果 |
AC
|
| 実行時間 | 5 ms / 5,000 ms |
| コード長 | 867 bytes |
| コンパイル時間 | 4,244 ms |
| コンパイル使用メモリ | 203,144 KB |
| 実行使用メモリ | 7,716 KB |
| 最終ジャッジ日時 | 2025-07-30 21:34:09 |
| 合計ジャッジ時間 | 5,428 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 17 |
ソースコード
module main;
// https://kmjp.hatenablog.jp/entry/2015/07/13/1000 より
// 動的計画法
import std;
// aとbを比較してbの方が小さいならばaの値をbに更新する
void chMin(T)(ref T a, in T b)
{
if (a > b) a = b;
}
void main()
{
int N;
long V;
readln.chomp.formattedRead("%d %d", N, V);
auto C = 0L ~ readln.split.to!(long[]);
// S は C の累積和
auto S = C.cumulativeFold!"a + b"(0L).array;
if (V <= N) {
writeln(S[N]);
return;
}
V -= N;
int x = 1;
foreach (i; 2 .. N + 1) {
if (S[i] * x < S[x] * i) x = i;
}
auto cost = new long[](min(V, 20_200));
auto len = cost.length;
cost[] = 1L << 60;
foreach (i; 0 .. len) {
if ((V - i) % x == 0) cost[i] = (V - i) / x * S[x];
}
foreach_reverse (i, ref c; cost) {
foreach (j; 1 .. N + 1)
if (i + j < len) chMin(c, cost[i + j] + S[j]);
}
writeln(cost[0] + S[N]);
}