結果
| 問題 |
No.595 登山
|
| ユーザー |
vjudge1
|
| 提出日時 | 2025-08-23 12:59:04 |
| 言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 84 ms / 1,500 ms |
| コード長 | 591 bytes |
| コンパイル時間 | 4,683 ms |
| コンパイル使用メモリ | 209,140 KB |
| 実行使用メモリ | 8,140 KB |
| 最終ジャッジ日時 | 2025-08-23 12:59:13 |
| 合計ジャッジ時間 | 7,536 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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;
}
vjudge1