結果
| 問題 | No.595 登山 | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2017-11-12 00:37:53 | 
| 言語 | D (dmd 2.109.1) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 44 ms / 1,500 ms | 
| コード長 | 729 bytes | 
| コンパイル時間 | 680 ms | 
| コンパイル使用メモリ | 117,700 KB | 
| 実行使用メモリ | 15,324 KB | 
| 最終ジャッジ日時 | 2024-06-12 22:29:46 | 
| 合計ジャッジ時間 | 2,360 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 25 | 
ソースコード
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop;
immutable long INF = 1L << 60;
void main() {
    auto s = readln.split;
    auto N = s[0].to!int;
    auto P = s[1].to!long;
    auto H = readln.split.map!(to!long).array;
    auto dp = new long[][](2, N);
    dp[0][0] = 0;
    dp[1][0] = INF;
    foreach (i; 1..N) {
        dp[0][i] = min(dp[0][i-1] + max(0, H[i]-H[i-1]),
                       min(dp[0][i-1], dp[1][i-1]) + P);
        dp[1][i] = min(dp[1][i-1] + max(0, H[i-1]-H[i]),
                       min(dp[0][i-1], dp[1][i-1]) + P);
    }
    min(dp[0][N-1], dp[1][N-1]).writeln;
}
            
            
            
        