結果

問題 No.595 登山
ユーザー nebukuro09nebukuro09
提出日時 2017-11-12 00:33:32
言語 D
(dmd 2.105.2)
結果
WA  
実行時間 -
コード長 727 bytes
コンパイル時間 929 ms
コンパイル使用メモリ 103,124 KB
実行使用メモリ 16,340 KB
最終ジャッジ日時 2023-09-03 16:51:49
合計ジャッジ時間 3,161 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 1 ms
4,380 KB
testcase_02 WA -
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 39 ms
15,652 KB
testcase_05 WA -
testcase_06 AC 31 ms
10,284 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 23 ms
9,252 KB
testcase_11 AC 20 ms
8,840 KB
testcase_12 AC 4 ms
4,376 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 25 ms
12,932 KB
testcase_18 WA -
testcase_19 AC 45 ms
13,148 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 1 ms
4,380 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 36 ms
14,404 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] = 0;

    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