結果
| 問題 |
No.595 登山
|
| ユーザー |
kurarrr
|
| 提出日時 | 2018-02-22 14:42:34 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 1,292 bytes |
| コンパイル時間 | 2,338 ms |
| コンパイル使用メモリ | 159,236 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-10-01 08:58:19 |
| 合計ジャッジ時間 | 6,618 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 2 RE * 23 |
コンパイルメッセージ
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);
| ~~~~~^~~~~~~~~~~~
ソースコード
#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 = 302;
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;
}
kurarrr