結果

問題 No.595 登山
ユーザー ikdikd
提出日時 2017-11-29 23:05:25
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 72 ms / 1,500 ms
コード長 671 bytes
コンパイル時間 977 ms
コンパイル使用メモリ 87,696 KB
実行使用メモリ 25,256 KB
最終ジャッジ日時 2023-09-03 17:06:31
合計ジャッジ時間 3,163 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 60 ms
23,180 KB
testcase_05 AC 18 ms
7,320 KB
testcase_06 AC 51 ms
15,788 KB
testcase_07 AC 6 ms
4,380 KB
testcase_08 AC 8 ms
4,888 KB
testcase_09 AC 51 ms
17,588 KB
testcase_10 AC 35 ms
13,968 KB
testcase_11 AC 33 ms
12,692 KB
testcase_12 AC 5 ms
5,296 KB
testcase_13 AC 16 ms
7,304 KB
testcase_14 AC 48 ms
18,256 KB
testcase_15 AC 48 ms
19,412 KB
testcase_16 AC 49 ms
19,136 KB
testcase_17 AC 49 ms
19,152 KB
testcase_18 AC 46 ms
19,628 KB
testcase_19 AC 64 ms
22,652 KB
testcase_20 AC 67 ms
25,256 KB
testcase_21 AC 65 ms
23,480 KB
testcase_22 AC 66 ms
24,044 KB
testcase_23 AC 67 ms
22,968 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 72 ms
24,500 KB
testcase_27 AC 59 ms
24,008 KB
testcase_28 AC 60 ms
24,904 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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