結果

問題 No.595 登山
ユーザー HIR180HIR180
提出日時 2017-11-10 22:37:57
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,013 bytes
コンパイル時間 1,430 ms
コンパイル使用メモリ 159,080 KB
実行使用メモリ 7,660 KB
最終ジャッジ日時 2024-05-03 12:52:08
合計ジャッジ時間 3,585 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,812 KB
testcase_01 AC 3 ms
6,944 KB
testcase_02 AC 3 ms
6,940 KB
testcase_03 AC 3 ms
6,940 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 3 ms
6,944 KB
testcase_25 AC 3 ms
6,940 KB
testcase_26 WA -
testcase_27 AC 25 ms
7,372 KB
testcase_28 AC 26 ms
7,220 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:24:41: warning: format ‘%lld’ expects argument of type ‘long long int*’, but argument 2 has type ‘int*’ [-Wformat=]
   24 |         for(int i=1;i<=n;i++) scanf("%lld",&h[i]);
      |                                      ~~~^  ~~~~~
      |                                         |  |
      |                                         |  int*
      |                                         long long int*
      |                                      %d
main.cpp:23:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   23 |         scanf("%d%d",&n,&p);
      |         ~~~~~^~~~~~~~~~~~~~
main.cpp:24:36: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   24 |         for(int i=1;i<=n;i++) scanf("%lld",&h[i]);
      |                               ~~~~~^~~~~~~~~~~~~~

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int n,p,h[200005];
ll dp[200005][2];
int main(){
	scanf("%d%d",&n,&p);
	for(int i=1;i<=n;i++) scanf("%lld",&h[i]);
	rep(i,200005) rep(j,2) dp[i][j] = 1e18;
	dp[1][0] = 0;
	for(int i=2;i<=n;i++){
		dp[i][0] = min(dp[i-1][0]+max(0LL,1LL*h[i]-h[i-1]),dp[i-1][1]+max(0LL,1LL*h[i]-h[i-1])+1LL*p);
		dp[i][1] = min(dp[i-1][1]+max(0LL,1LL*h[i-1]-h[i]),dp[i-1][0]+max(0LL,1LL*h[i-1]-h[i])+1LL*p);
	}
	cout<<min(dp[n][0],dp[n][1])<<endl;
}
0