結果

問題 No.595 登山
ユーザー NekosyndromeNekosyndrome
提出日時 2017-11-10 23:04:35
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 955 bytes
コンパイル時間 1,291 ms
コンパイル使用メモリ 157,424 KB
実行使用メモリ 8,448 KB
最終ジャッジ日時 2024-05-03 13:25:21
合計ジャッジ時間 2,604 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 14 ms
6,144 KB
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 2 ms
5,376 KB
testcase_25 AC 1 ms
5,376 KB
testcase_26 AC 28 ms
8,320 KB
testcase_27 AC 22 ms
8,320 KB
testcase_28 AC 23 ms
8,320 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:27:33: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   27 |                 REP(i,1,n) scanf("%lld",&in[i]);
      |                            ~~~~~^~~~~~~~~~~~~~~

ソースコード

diff #

#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 200005
void 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,bk
int main()
{
	while(~scanf("%d %lld",&n,&p))
	{
		REP(i,1,n) scanf("%lld",&in[i]);
		
		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] + max(in[i-1]-in[i], 0LL);
			
			dp[i][1] = min(dp[i][1], dp[i-1][0] + p);
			dp[i][0] = min(dp[i][0], dp[i-1][1] + p);
		}
		
		printf("%lld\n", min(dp[n][0], dp[n][1]));
		
	}
	return 0;
}

0