結果

問題 No.595 登山
ユーザー nanaenanae
提出日時 2017-11-11 12:43:50
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 48 ms / 1,500 ms
コード長 1,145 bytes
コンパイル時間 1,555 ms
コンパイル使用メモリ 95,984 KB
実行使用メモリ 14,020 KB
最終ジャッジ日時 2023-09-03 16:51:23
合計ジャッジ時間 2,625 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 37 ms
13,216 KB
testcase_05 AC 11 ms
5,424 KB
testcase_06 AC 32 ms
11,056 KB
testcase_07 AC 4 ms
4,376 KB
testcase_08 AC 6 ms
5,328 KB
testcase_09 AC 31 ms
9,788 KB
testcase_10 AC 23 ms
8,396 KB
testcase_11 AC 20 ms
8,328 KB
testcase_12 AC 4 ms
4,380 KB
testcase_13 AC 10 ms
5,180 KB
testcase_14 AC 26 ms
10,332 KB
testcase_15 AC 26 ms
10,396 KB
testcase_16 AC 27 ms
10,852 KB
testcase_17 AC 27 ms
10,428 KB
testcase_18 AC 26 ms
11,760 KB
testcase_19 AC 44 ms
13,720 KB
testcase_20 AC 44 ms
14,020 KB
testcase_21 AC 44 ms
13,764 KB
testcase_22 AC 45 ms
13,960 KB
testcase_23 AC 44 ms
13,784 KB
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 48 ms
13,400 KB
testcase_27 AC 35 ms
13,124 KB
testcase_28 AC 35 ms
13,156 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.stdio, std.string, std.conv, std.algorithm, std.numeric;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;

void main() {
    int n, p;
    scan(n, p);
    auto h = readln.split.to!(int[]);

    auto dpr = new long[](n);
    auto dpl = new long[](n);

    foreach (i ; 1 .. n) {
        if (i == 1) {
            dpr[i] = min(min(dpr[i-1], dpl[i-1]) + p, dpr[i-1] + max(h[i] - h[i-1], 0));
            dpl[i] = min(dpr[i-1], dpl[i-1]) + p;
        }
        else {
            dpr[i] = min(min(dpr[i-1], dpl[i-1]) + p, dpr[i-1] + max(h[i] - h[i-1], 0));
            dpl[i] = min(min(dpr[i-1], dpl[i-1]) + p, dpl[i-1] + max(h[i-1] - h[i], 0));
        }
    }

    writeln(min(dpr[n-1], dpl[n-1]));
}



void scan(T...)(ref T args) {
    string[] line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}
0