結果
問題 |
No.595 登山
|
ユーザー |
|
提出日時 | 2017-11-10 23:25:18 |
言語 | D (dmd 2.109.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,015 bytes |
コンパイル時間 | 698 ms |
コンパイル使用メモリ | 116,896 KB |
実行使用メモリ | 13,532 KB |
最終ジャッジ日時 | 2024-06-12 22:27:51 |
合計ジャッジ時間 | 2,560 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 5 WA * 20 |
ソースコード
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; }