結果

問題 No.595 登山
ユーザー kuuso1kuuso1
提出日時 2017-11-10 23:32:56
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 1,443 bytes
コンパイル時間 926 ms
コンパイル使用メモリ 113,392 KB
実行使用メモリ 55,764 KB
最終ジャッジ日時 2024-05-03 14:41:48
合計ジャッジ時間 4,367 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 26 ms
26,092 KB
testcase_01 AC 26 ms
24,184 KB
testcase_02 AC 26 ms
23,980 KB
testcase_03 AC 26 ms
23,724 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 26 ms
23,796 KB
testcase_25 AC 26 ms
23,792 KB
testcase_26 AC 121 ms
52,240 KB
testcase_27 AC 101 ms
46,240 KB
testcase_28 AC 99 ms
46,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		int[] R = new int[N];
		R[N-1] = N-1;
		for(int i=N-2;i>=0;i--){
			if(A[i+1] >= A[i]){
				R[i] = R[i+1];
			} else {
				R[i] = i;
			}
		}
		
		long[] dp = new long[N];
		for(int i=0;i<N;i++) dp[i] = long.MaxValue;
		dp[0] = 0;
		
		for(int i=0;i<N-1;i++){
			dp[i+1] = Math.Min(dp[i+1],dp[i] + Math.Max(0,A[i+1] - A[i]));
			if(R[i+1] == N-1){
				dp[N-1] = Math.Min(dp[N-1], dp[i] + P);
			} else {
				dp[i+2] = Math.Min(dp[i+2], dp[i] + P);
			}
		}
		Console.WriteLine(dp[N-1]);
	}
	int N;
	long P;
	long[] A;
	public Sol(){
		var d = ria();
		N = d[0]; P = d[1];
		A = rla();
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}
0