結果

問題 No.595 登山
ユーザー kurarrrkurarrr
提出日時 2018-02-22 14:43:43
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 32 ms / 1,500 ms
コード長 1,295 bytes
コンパイル時間 1,674 ms
コンパイル使用メモリ 159,760 KB
実行使用メモリ 9,824 KB
最終ジャッジ日時 2024-04-08 16:51:33
合計ジャッジ時間 3,548 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 28 ms
9,568 KB
testcase_05 AC 9 ms
8,176 KB
testcase_06 AC 23 ms
9,056 KB
testcase_07 AC 4 ms
6,676 KB
testcase_08 AC 6 ms
6,676 KB
testcase_09 AC 24 ms
9,056 KB
testcase_10 AC 17 ms
8,416 KB
testcase_11 AC 16 ms
8,416 KB
testcase_12 AC 4 ms
6,676 KB
testcase_13 AC 9 ms
6,676 KB
testcase_14 AC 23 ms
9,824 KB
testcase_15 AC 23 ms
9,824 KB
testcase_16 AC 23 ms
9,824 KB
testcase_17 AC 22 ms
9,824 KB
testcase_18 AC 22 ms
9,824 KB
testcase_19 AC 31 ms
9,824 KB
testcase_20 AC 31 ms
9,824 KB
testcase_21 AC 32 ms
9,824 KB
testcase_22 AC 31 ms
9,824 KB
testcase_23 AC 32 ms
9,824 KB
testcase_24 AC 2 ms
6,676 KB
testcase_25 AC 2 ms
6,676 KB
testcase_26 AC 32 ms
9,824 KB
testcase_27 AC 27 ms
9,824 KB
testcase_28 AC 27 ms
9,824 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:30:21: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   30 |   int N; ll P; scanf("%d%lld",&N,&P);
      |                ~~~~~^~~~~~~~~~~~~~~~
main.cpp:31:17: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   31 |   rep(i,N) scanf("%lld",H+i);
      |            ~~~~~^~~~~~~~~~~~

ソースコード

diff #

#include "bits/stdc++.h"

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i, x, n) for(int i = x; i >= n; i--)
#define rrep(i, n) RREP(i,n,0)
#define pb push_back
#define show_table(n, k, table) rep(i,n){ rep(j,k) cout << table[i][j] << " "; cout << endl;}

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

using namespace std;

using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vvi = vector<vi>;

const int mod=1e9+7,INF=1<<30;
const double EPS=1e-12,PI=3.1415926535897932384626;
const ll lmod = 1e9+7,LINF=1LL<<60;
const int MAX_N = 200005;

ll dp[MAX_N][3],H[MAX_N];

int main(){
  int N; ll P; scanf("%d%lld",&N,&P);
  rep(i,N) scanf("%lld",H+i);
  dp[0][0] = LINF; dp[0][1] = 0;
  rep(i,N-1){
    dp[i+1][1] = min(min(dp[i][0],dp[i][1])+P,dp[i][1]+max(0LL,H[i+1]-H[i]));
    dp[i+1][0] = min(min(dp[i][0],dp[i][1])+P,dp[i][0]+max(0LL,H[i]-H[i+1]));
    // dp[i+1][1] = min(dp[i][1]+min(P,max(0LL,H[i+1]-H[i])),dp[i][0]+P);
    // dp[i+1][0] = min(P + min(P,max(0LL,H[i]-H[i+1])) + dp[i][0],dp[i+1][1]);
  }
  // show_table(N,2,dp);
  cout << min(dp[N-1][0],dp[N-1][1]) << endl;
  return 0;
}
0