結果
問題 | No.595 登山 |
ユーザー |
|
提出日時 | 2017-11-10 23:18:27 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 31 ms / 1,500 ms |
コード長 | 976 bytes |
コンパイル時間 | 1,920 ms |
コンパイル使用メモリ | 157,300 KB |
実行使用メモリ | 8,448 KB |
最終ジャッジ日時 | 2024-11-24 15:17:40 |
合計ジャッジ時間 | 3,701 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 25 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:43:33: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 43 | REP(i,1,n) scanf("%lld",&in[i]); | ~~~~~^~~~~~~~~~~~~~~
ソースコード
#include<bits/stdc++.h>#define REP(x,y,z) for(int x=y;x<=z;x++)#define FORD(x,y,z) for(int x=y;x>=z;x--)#define MSET(x,y) memset(x,y,sizeof(x))#define FOR(x,y) for(__typeof(y.begin()) x=y.begin();x!=y.end();x++)#define F first#define S second#define MP make_pair#define PB push_back#define SZ size()#define M 200005void RI(){}template<typename... T>void RI( int& head, T&... tail ) {scanf("%d",&head);RI(tail...);}using namespace std;typedef long long LL;int n;long long in[M],p;long long dp[M][2];//fr,bkLL calc(){dp[1][0] = 0;dp[1][1] = (1LL)<<60;REP(i,2,n){dp[i][0] = dp[i-1][0] + min(max(in[i]-in[i-1],0LL), p);dp[i][1] = dp[i-1][1] + min(max(in[i-1]-in[i], 0LL), p);dp[i][1] = min(dp[i][1], dp[i-1][0] + p);dp[i][0] = min(dp[i][0], dp[i-1][1] + p);}return min(dp[n][0], dp[n][1]);}int main(){while(~scanf("%d %lld",&n,&p)){REP(i,1,n) scanf("%lld",&in[i]);printf("%lld\n", calc());}return 0;}