結果
| 問題 |
No.595 登山
|
| ユーザー |
|
| 提出日時 | 2017-11-12 00:33:32 |
| 言語 | D (dmd 2.109.1) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 727 bytes |
| コンパイル時間 | 852 ms |
| コンパイル使用メモリ | 117,668 KB |
| 実行使用メモリ | 16,692 KB |
| 最終ジャッジ日時 | 2024-06-12 22:29:44 |
| 合計ジャッジ時間 | 2,593 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 WA * 2 |
| other | AC * 9 WA * 16 |
ソースコード
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;
}