結果

問題 No.595 登山
ユーザー chocoruskchocorusk
提出日時 2018-10-09 23:54:04
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 94 ms / 1,500 ms
コード長 919 bytes
コンパイル時間 895 ms
コンパイル使用メモリ 93,724 KB
実行使用メモリ 12,800 KB
最終ジャッジ日時 2024-04-20 19:20:42
合計ジャッジ時間 4,170 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 9 ms
12,544 KB
testcase_01 AC 9 ms
12,672 KB
testcase_02 AC 9 ms
12,672 KB
testcase_03 AC 9 ms
12,800 KB
testcase_04 AC 66 ms
12,800 KB
testcase_05 AC 26 ms
12,800 KB
testcase_06 AC 59 ms
12,800 KB
testcase_07 AC 14 ms
12,800 KB
testcase_08 AC 18 ms
12,672 KB
testcase_09 AC 59 ms
12,672 KB
testcase_10 AC 43 ms
12,800 KB
testcase_11 AC 40 ms
12,672 KB
testcase_12 AC 15 ms
12,800 KB
testcase_13 AC 25 ms
12,672 KB
testcase_14 AC 47 ms
12,800 KB
testcase_15 AC 46 ms
12,672 KB
testcase_16 AC 45 ms
12,800 KB
testcase_17 AC 46 ms
12,672 KB
testcase_18 AC 46 ms
12,672 KB
testcase_19 AC 91 ms
12,800 KB
testcase_20 AC 91 ms
12,800 KB
testcase_21 AC 92 ms
12,672 KB
testcase_22 AC 91 ms
12,800 KB
testcase_23 AC 91 ms
12,672 KB
testcase_24 AC 9 ms
12,672 KB
testcase_25 AC 9 ms
12,672 KB
testcase_26 AC 94 ms
12,800 KB
testcase_27 AC 73 ms
12,672 KB
testcase_28 AC 71 ms
12,672 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:36:30: warning: ‘s1’ may be used uninitialized [-Wmaybe-uninitialized]
   36 |         dp[0]=0, mn1[0]=-s1[1], mn2[0]=-s2[1];
      |                          ~~~~^
main.cpp:25:12: note: ‘s1’ declared here
   25 |         ll s1[200001], s2[200001];
      |            ^~
main.cpp:36:45: warning: ‘s2’ may be used uninitialized [-Wmaybe-uninitialized]
   36 |         dp[0]=0, mn1[0]=-s1[1], mn2[0]=-s2[1];
      |                                         ~~~~^
main.cpp:25:24: note: ‘s2’ declared here
   25 |         ll s1[200001], s2[200001];
      |                        ^~

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <random>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
	int n;
	ll p;
	cin>>n>>p;
	ll s1[200001], s2[200001];
	s1[0]=0, s2[0]=0;
	ll h[200001];
	ll dp[200001], mn1[200001], mn2[200001];
	for(int i=0; i<n; i++){
		cin>>h[i];
		if(i>0){
			s1[i]=s1[i-1]+max(h[i]-h[i-1], 0ll);
			s2[i]=s2[i-1]+max(h[i-1]-h[i], 0ll);
		}
	}
	dp[0]=0, mn1[0]=-s1[1], mn2[0]=-s2[1];
	for(int i=1; i<n; i++){
		dp[i]=s1[i];
		dp[i]=min(dp[i], mn1[i-1]+s1[i]+p);
		dp[i]=min(dp[i], mn2[i-1]+s2[i]+p);
		if(i<n-1){
			mn1[i]=min(mn1[i-1], dp[i]-s1[i+1]);
			mn2[i]=min(mn2[i-1], dp[i]-s2[i+1]);
		}
	}
	cout<<dp[n-1]<<endl;
	return 0;
}
0