結果

問題 No.595 登山
ユーザー nebukuro09nebukuro09
提出日時 2017-11-10 23:25:18
言語 D
(dmd 2.106.1)
結果
WA  
実行時間 -
コード長 1,015 bytes
コンパイル時間 1,125 ms
コンパイル使用メモリ 103,116 KB
実行使用メモリ 14,132 KB
最終ジャッジ日時 2023-09-03 16:50:04
合計ジャッジ時間 3,435 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 56 ms
13,908 KB
testcase_27 AC 45 ms
14,132 KB
testcase_28 AC 45 ms
14,080 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;

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;

    long[] peaks;
    int p;

    while (p < N-1 && H[p] >= H[p+1])
        ++p;
    peaks ~= p;

    if (p == N-1) {
        writeln(0);
        return;
    }


    bool up = true;
    while (p < N-1) {
        if (up && H[p] > H[p+1]) {
            peaks ~= p;
            up = false;
        } else if (!up && H[p] < H[p+1]) {
            peaks ~= p;
            up = true;
        }
        ++p;
    }

    if (up && H[$-1] >= H[$-2])
        peaks ~= N-1;


    long ans = 0;
    p = 1;
    while (p < peaks.length) {
        if (H[peaks[p]] - H[peaks[p-1]] < P)
            ans += H[peaks[p]] - H[peaks[p-1]];
        else
            ans += P;
        p += 2;
    }

    ans.writeln;
}
0