結果
| 問題 |
No.595 登山
|
| コンテスト | |
| ユーザー |
ikd
|
| 提出日時 | 2017-11-29 23:05:25 |
| 言語 | D (dmd 2.109.1) |
| 結果 |
AC
|
| 実行時間 | 83 ms / 1,500 ms |
| コード長 | 671 bytes |
| コンパイル時間 | 915 ms |
| コンパイル使用メモリ | 101,376 KB |
| 実行使用メモリ | 21,788 KB |
| 最終ジャッジ日時 | 2024-06-12 22:43:07 |
| 合計ジャッジ時間 | 3,392 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 25 |
ソースコード
void main(){
import std.stdio, std.string, std.conv, std.algorithm;
int n; long p;
rd(n, p);
auto h=readln.split.to!(long[]);
auto rec=new long[][](n, 3);
const R=0, L=1, JP=2;
rec[1][L]=1_000_000_000_000_000_000;
foreach(i; 1..n){
rec[i][R]=min(rec[i-1][R], rec[i-1][JP])+max(0, h[i]-h[i-1]);
if(i>=2) rec[i][L]=min(rec[i-1][L], rec[i-1][JP])+max(0, h[i-1]-h[i]);
rec[i][JP]=min(rec[i-1][R], rec[i-1][L], rec[i-1][JP])+p;
}
writeln(reduce!(min)(rec[n-1]));
}
void rd(T...)(ref T x){
import std.stdio, std.string, std.conv;
auto l=readln.split;
assert(l.length==x.length);
foreach(i, ref e; x){
e=l[i].to!(typeof(e));
}
}
ikd