結果

問題 No.595 登山
ユーザー vjudge1
提出日時 2025-08-26 21:10:29
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 30 ms / 1,500 ms
コード長 531 bytes
コンパイル時間 1,465 ms
コンパイル使用メモリ 161,940 KB
実行使用メモリ 8,472 KB
最終ジャッジ日時 2025-08-26 21:10:33
合計ジャッジ時間 4,139 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 25
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:11:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   11 |         scanf("%lld%lld",&n,&V);
      |         ~~~~~^~~~~~~~~~~~~~~~~~
main.cpp:12:24: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   12 |         FL(i,1,n) scanf("%lld",&h[i]);
      |                   ~~~~~^~~~~~~~~~~~~~

ソースコード

diff #

#include<bits/stdc++.h>
#define FL(i,a,b) for(ll i=(a);i<=(b);i++)
#define FR(i,a,b) for(ll i=(a);i>=(b);i--)
#define ll long long
using namespace std;
const ll MAXN = 2e5 + 10;
ll n,V;
ll h[MAXN];
ll f[MAXN][2];
signed main(){
	scanf("%lld%lld",&n,&V);
	FL(i,1,n) scanf("%lld",&h[i]);
	memset(f,0x3f,sizeof(f));
	f[1][1]=0,f[1][0]=V;
	FL(i,1,n){
		f[i+1][0]=min(f[i][0]+max(0ll,h[i]-h[i+1]),min(f[i][0],f[i][1])+V);
		f[i+1][1]=min(f[i][1]+max(0ll,h[i+1]-h[i]),min(f[i][0],f[i][1])+V);
	}
	printf("%lld\n",min(f[n][0],f[n][1]));
}
0