結果

問題 No.595 登山
ユーザー kuuso1kuuso1
提出日時 2017-11-11 00:05:26
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 1,881 bytes
コンパイル時間 959 ms
コンパイル使用メモリ 107,776 KB
実行使用メモリ 43,648 KB
最終ジャッジ日時 2024-05-03 14:57:28
合計ジャッジ時間 4,414 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 24 ms
17,792 KB
testcase_01 AC 25 ms
17,536 KB
testcase_02 AC 25 ms
17,920 KB
testcase_03 AC 25 ms
17,920 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
17,792 KB
testcase_25 AC 25 ms
18,048 KB
testcase_26 AC 130 ms
43,520 KB
testcase_27 AC 117 ms
43,008 KB
testcase_28 AC 117 ms
43,136 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(){
		
		long Inf = (long) 1e16;
		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[2][];
		for(int i=0;i<2;i++){
			dp[i] = new long[N];
			for(int j=0;j<N;j++) dp[i][j] = Inf;
		}
		dp[0][0] = 0;
		
		for(int i=0;i<N-1;i++){
			dp[0][i+1] = Math.Min(dp[0][i+1],dp[0][i] + Math.Max(0,A[i+1] - A[i]));
			if(R[i] > i){
				if(R[i] == i+1){
					dp[0][i+1] = Math.Min(dp[0][i+1],dp[0][i] + P);
				} else {
					dp[1][R[i]] = Math.Min(dp[1][R[i]], dp[0][i] + P);
				}
			} else {
				if(R[i+1] == i+1){
					dp[0][i+1] = Math.Min(dp[0][i+1],dp[0][i] + P);
				} else {
					dp[1][R[i+1]] = Math.Min(dp[1][R[i+1]], dp[0][i] + P);
				}
			}
			
			dp[0][i+1] = Math.Min(dp[0][i+1],dp[1][i] + P);
			dp[1][R[i+1]] = Math.Min(dp[1][R[i+1]],dp[1][i] + P);
		}
		
		Console.WriteLine(Math.Min(dp[0][N-1],dp[1][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