結果
| 問題 |
No.595 登山
|
| ユーザー |
tottoripaper
|
| 提出日時 | 2017-11-10 23:14:49 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 925 bytes |
| コンパイル時間 | 1,285 ms |
| コンパイル使用メモリ | 168,020 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-11-24 15:11:53 |
| 合計ジャッジ時間 | 2,772 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 4 WA * 21 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))
using ll = long long;
const int dx[8] = {-1, 1, 0, 0, -1, -1, 1, 1}, dy[8] = {0, 0, -1, 1, -1, 1, -1, 1};
int N, P;
int H[252521];
int main(){
std::cin.tie(nullptr);
std::ios::sync_with_stdio(false);
std::cin >> N >> P;
for(int i=0;i<N;++i){
std::cin >> H[i];
}
int cur = +1;
ll res = 0ll;
for(int i=0,j=0;i+1<N;i=j){
ll cost = 0;
while(j + 1 < N && cur * H[j] >= cur * H[j+1]){
cost += abs(H[j + 1] - H[j]);
++j;
}
// std::cout << i << " -> " << j << std::endl;
if(cur == -1){
res += min(j + 1 == N ? 1ll * P : 1ll * P * 2, cost);
}
cur *= -1;
}
std::cout << res << std::endl;
}
tottoripaper