結果

問題 No.595 登山
ユーザー ferinferin
提出日時 2017-11-11 12:22:53
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 77 ms / 1,500 ms
コード長 1,309 bytes
コンパイル時間 1,137 ms
コンパイル使用メモリ 160,368 KB
実行使用メモリ 8,216 KB
最終ジャッジ日時 2024-05-03 16:30:11
合計ジャッジ時間 3,525 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 54 ms
7,936 KB
testcase_05 AC 17 ms
5,376 KB
testcase_06 AC 47 ms
7,168 KB
testcase_07 AC 7 ms
5,376 KB
testcase_08 AC 10 ms
5,376 KB
testcase_09 AC 47 ms
7,296 KB
testcase_10 AC 36 ms
5,888 KB
testcase_11 AC 31 ms
5,888 KB
testcase_12 AC 6 ms
5,376 KB
testcase_13 AC 16 ms
5,376 KB
testcase_14 AC 36 ms
8,064 KB
testcase_15 AC 36 ms
8,064 KB
testcase_16 AC 35 ms
7,936 KB
testcase_17 AC 35 ms
8,216 KB
testcase_18 AC 37 ms
7,936 KB
testcase_19 AC 76 ms
8,192 KB
testcase_20 AC 76 ms
8,136 KB
testcase_21 AC 75 ms
8,140 KB
testcase_22 AC 76 ms
7,968 KB
testcase_23 AC 77 ms
8,012 KB
testcase_24 AC 1 ms
5,376 KB
testcase_25 AC 2 ms
5,376 KB
testcase_26 AC 77 ms
8,192 KB
testcase_27 AC 58 ms
8,008 KB
testcase_28 AC 58 ms
8,088 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
#define int ll
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define IN(a, b, x) (a<=x&&x<b)
#define MP make_pair
#define PB push_back
#ifdef int
const ll INF = (1LL<<60);
#else
const int INF = (1LL<<30);
#endif
const double PI = 3.14159265359;
const double EPS = 1e-12;
const int MOD = 1000000007;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }

int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};

int h[200010], dp[2][200010];
signed main(void)
{
  int n, p;
  cin >> n >> p;
  REP(i, n) cin >> h[i];

  REP(i, 2) REP(j, n) dp[i][j] = INF;
  dp[0][0] = 0;

  FOR(i, 1, n) {
    dp[0][i] = min(min(dp[0][i-1], dp[1][i-1])+p, dp[0][i-1] + max(0LL, h[i]-h[i-1]));
    dp[1][i] = min(min(dp[0][i-1], dp[1][i-1])+p, dp[1][i-1] + max(h[i-1]-h[i], 0LL));
  }

  // REP(i, 2) {
  //   REP(j, n) cout << dp[i][j] << " ";
  //   cout << endl;
  // }

  cout << min(dp[0][n-1], dp[1][n-1]) << endl;

  return 0;
}
0