結果

問題 No.595 登山
ユーザー nebukuro09nebukuro09
提出日時 2017-11-12 00:37:53
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 46 ms / 1,500 ms
コード長 729 bytes
コンパイル時間 816 ms
コンパイル使用メモリ 103,144 KB
実行使用メモリ 15,320 KB
最終ジャッジ日時 2023-09-03 16:51:52
合計ジャッジ時間 2,652 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 39 ms
14,184 KB
testcase_05 AC 10 ms
5,476 KB
testcase_06 AC 30 ms
10,872 KB
testcase_07 AC 4 ms
4,376 KB
testcase_08 AC 7 ms
4,376 KB
testcase_09 AC 31 ms
10,632 KB
testcase_10 AC 23 ms
9,352 KB
testcase_11 AC 20 ms
7,532 KB
testcase_12 AC 4 ms
4,808 KB
testcase_13 AC 10 ms
5,700 KB
testcase_14 AC 25 ms
11,644 KB
testcase_15 AC 27 ms
11,936 KB
testcase_16 AC 27 ms
12,136 KB
testcase_17 AC 26 ms
12,668 KB
testcase_18 AC 25 ms
12,120 KB
testcase_19 AC 44 ms
13,160 KB
testcase_20 AC 44 ms
13,092 KB
testcase_21 AC 43 ms
13,188 KB
testcase_22 AC 44 ms
13,088 KB
testcase_23 AC 44 ms
13,292 KB
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 46 ms
15,320 KB
testcase_27 AC 35 ms
14,336 KB
testcase_28 AC 35 ms
15,244 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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