結果
| 問題 |
No.595 登山
|
| ユーザー |
vjudge1
|
| 提出日時 | 2025-08-23 12:34:17 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 7 ms / 1,500 ms |
| コード長 | 987 bytes |
| コンパイル時間 | 541 ms |
| コンパイル使用メモリ | 45,424 KB |
| 実行使用メモリ | 7,716 KB |
| 最終ジャッジ日時 | 2025-08-23 12:34:19 |
| 合計ジャッジ時間 | 2,231 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 25 |
ソースコード
#include <algorithm>
#include <cmath>
#include <cstdio>
using namespace std;
namespace IO {
const int MAX_SIZE = 1 << 20;
char buf[MAX_SIZE], *p1 = buf, *p2 = buf;
char gc() {
return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, MAX_SIZE, stdin), p1 == p2) ? EOF : *p1++;
}
template <typename T> void R(T &x) {
x = 0;
char ch = gc();
while (ch < '0' || ch > '9') ch = gc();
while (ch >= '0' && ch <= '9') {
x = (x << 3) + (x << 1) + (ch ^ 48);
ch = gc();
}
}
} // namespace IO
using IO::R;
const long long inf = 0x3f3f3f3f3f3f3f3f;
int n, w, h1, h2;
long long p, b = inf, f;
void solve() {
R(n), R(w), R(h1);
for (int i = 2; i <= n; ++i) {
R(h2);
f = min(p, b);
p = min(f + w, p + (h1 < h2) * (h2 - h1));
b = min(f + w, b + (h2 < h1) * (h1 - h2));
h1 = h2;
}
printf("%lld", min(p, b));
}
int main() {
solve();
return 0;
}
vjudge1