結果
問題 | No.595 登山 |
ユーザー |
|
提出日時 | 2017-11-11 12:43:50 |
言語 | D (dmd 2.109.1) |
結果 |
AC
|
実行時間 | 47 ms / 1,500 ms |
コード長 | 1,145 bytes |
コンパイル時間 | 869 ms |
コンパイル使用メモリ | 108,328 KB |
実行使用メモリ | 13,440 KB |
最終ジャッジ日時 | 2024-06-12 22:29:22 |
合計ジャッジ時間 | 2,238 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 25 |
ソースコード
import std.stdio, std.string, std.conv, std.algorithm, std.numeric;import std.range, std.array, std.math, std.typecons, std.container, core.bitop;void main() {int n, p;scan(n, p);auto h = readln.split.to!(int[]);auto dpr = new long[](n);auto dpl = new long[](n);foreach (i ; 1 .. n) {if (i == 1) {dpr[i] = min(min(dpr[i-1], dpl[i-1]) + p, dpr[i-1] + max(h[i] - h[i-1], 0));dpl[i] = min(dpr[i-1], dpl[i-1]) + p;}else {dpr[i] = min(min(dpr[i-1], dpl[i-1]) + p, dpr[i-1] + max(h[i] - h[i-1], 0));dpl[i] = min(min(dpr[i-1], dpl[i-1]) + p, dpl[i-1] + max(h[i-1] - h[i], 0));}}writeln(min(dpr[n-1], dpl[n-1]));}void scan(T...)(ref T args) {string[] line = readln.split;foreach (ref arg; args) {arg = line.front.to!(typeof(arg));line.popFront();}assert(line.empty);}void fillAll(R, T)(ref R arr, T value) {static if (is(typeof(arr[] = value))) {arr[] = value;}else {foreach (ref e; arr) {fillAll(e, value);}}}