結果
| 問題 |
No.595 登山
|
| ユーザー |
|
| 提出日時 | 2017-11-10 23:42:26 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,958 bytes |
| コンパイル時間 | 1,389 ms |
| コンパイル使用メモリ | 172,872 KB |
| 実行使用メモリ | 9,472 KB |
| 最終ジャッジ日時 | 2024-11-24 15:48:58 |
| 合計ジャッジ時間 | 2,795 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 5 WA * 20 |
ソースコード
#include <bits/stdc++.h>
#define show(x) cerr << #x << " = " << x << endl
using namespace std;
using ll = long long;
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v)
{
os << "sz:" << v.size() << "\n[";
for (const auto& p : v) {
os << p << ",";
}
os << "]\n";
return os;
}
template <typename S, typename T>
ostream& operator<<(ostream& os, const pair<S, T>& p)
{
os << "(" << p.first << "," << p.second
<< ")";
return os;
}
constexpr ll MOD = (ll)1e9 + 7LL;
template <typename T>
constexpr T INF = numeric_limits<T>::max() / 64;
int main()
{
cin.tie(0);
ios::sync_with_stdio(false);
int N;
ll P;
cin >> N >> P;
vector<ll> H(N);
for (int i = 0; i < N; i++) {
cin >> H[i];
}
vector<ll> point;
bool falling = true;
for (int i = 0; i < N - 1; i++) {
if (falling and H[i + 1] > H[i]) {
point.push_back(H[i]);
falling = false;
} else if ((not falling) and H[i + 1] < H[i]) {
point.push_back(H[i]);
falling = true;
}
}
point.push_back(H[N - 1]);
reverse(H.begin(), H.end());
vector<ll> revpoint;
falling = true;
for (int i = 0; i < N - 1; i++) {
if (falling and H[i + 1] > H[i]) {
revpoint.push_back(H[i]);
falling = false;
} else if ((not falling) and H[i + 1] < H[i]) {
revpoint.push_back(H[i]);
falling = true;
}
}
revpoint.push_back(H[N - 1]);
const int size = point.size();
ll sum = 0;
for (int i = 0; i < size - 1; i++) {
if (i % 2 == 0) {
sum += min(P, point[i + 1] - point[i]);
}
}
ll sum2 = P;
for (int i = 0; i < revpoint.size() - 1; i++) {
if (i % 2 == 0) {
sum2 += min(P, revpoint[i + 1] - revpoint[i]);
}
}
cout << min(sum, sum2) << endl;
return 0;
}