結果

問題 No.595 登山
コンテスト
ユーザー ikd
提出日時 2017-11-29 23:05:25
言語 D
(dmd 2.112.0)
コンパイル:
dmd -fPIE -m64 -w -wi -O -release -inline -I/opt/dmd/src/druntime/import/ -I/opt/dmd/src/phobos -L-L/opt/dmd/linux/lib64/ -fPIC _filename_
実行:
./Main
結果
AC  
実行時間 84 ms / 1,500 ms
コード長 671 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 676 ms
コンパイル使用メモリ 86,132 KB
実行使用メモリ 26,492 KB
最終ジャッジ日時 2026-03-05 17:43:25
合計ジャッジ時間 2,976 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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));
  }
}
0