結果
| 問題 |
No.595 登山
|
| ユーザー |
|
| 提出日時 | 2025-08-23 13:11:11 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 90 ms / 1,500 ms |
| コード長 | 591 bytes |
| コンパイル時間 | 2,249 ms |
| コンパイル使用メモリ | 194,988 KB |
| 実行使用メモリ | 8,300 KB |
| 最終ジャッジ日時 | 2025-08-23 13:11:16 |
| 合計ジャッジ時間 | 4,740 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 25 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200010;
const long long INF = 1e18;
long long H[MAXN], r[MAXN], l[MAXN];
int main() {
int N; long long P;
cin >> N >> P;
for (int i=1; i<=N; ++i) cin >> H[i];
r[1] = 0;
l[1] = INF;
for (int i=2; i<=N; ++i) {
long long new_r = min(r[i-1], l[i-1]) + P;
long long cont_r = r[i-1] + max(0LL, H[i] - H[i-1]);
r[i] = min(new_r, cont_r);
long long new_l = min(r[i-1], l[i-1]) + P;
long long cont_l = l[i-1] + max(0LL, H[i-1] - H[i]);
l[i] = min(new_l, cont_l);
}
cout << min(r[N], l[N]) << endl;
return 0;
}