結果

問題 No.595 登山
ユーザー tetsutetsu
提出日時 2017-11-11 23:04:23
言語 Java21
(openjdk 21)
結果
AC  
実行時間 825 ms / 1,500 ms
コード長 658 bytes
コンパイル時間 3,438 ms
コンパイル使用メモリ 77,140 KB
実行使用メモリ 60,180 KB
最終ジャッジ日時 2024-05-03 16:50:08
合計ジャッジ時間 18,855 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 111 ms
40,152 KB
testcase_01 AC 124 ms
41,240 KB
testcase_02 AC 121 ms
41,532 KB
testcase_03 AC 110 ms
41,560 KB
testcase_04 AC 669 ms
54,392 KB
testcase_05 AC 449 ms
48,584 KB
testcase_06 AC 651 ms
53,016 KB
testcase_07 AC 289 ms
47,876 KB
testcase_08 AC 360 ms
47,868 KB
testcase_09 AC 705 ms
52,808 KB
testcase_10 AC 610 ms
49,000 KB
testcase_11 AC 593 ms
49,440 KB
testcase_12 AC 256 ms
47,600 KB
testcase_13 AC 434 ms
48,216 KB
testcase_14 AC 635 ms
53,636 KB
testcase_15 AC 685 ms
53,632 KB
testcase_16 AC 663 ms
53,432 KB
testcase_17 AC 624 ms
55,088 KB
testcase_18 AC 615 ms
55,120 KB
testcase_19 AC 768 ms
60,108 KB
testcase_20 AC 740 ms
59,368 KB
testcase_21 AC 743 ms
58,664 KB
testcase_22 AC 825 ms
60,180 KB
testcase_23 AC 753 ms
58,476 KB
testcase_24 AC 117 ms
41,064 KB
testcase_25 AC 110 ms
41,196 KB
testcase_26 AC 767 ms
58,436 KB
testcase_27 AC 619 ms
55,180 KB
testcase_28 AC 623 ms
57,436 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package yukicoder;

import java.util.*;

public class P595 {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long P = sc.nextLong();
		long[] H = new long[N];
		for(int i=0; i<N; i++) {
			H[i] = sc.nextLong();
		}
		long[] dpr = new long[N];
		long[] dpl = new long[N];
		dpl[0] = 1000000000;
		for(int i=1; i<N; i++) {
			dpr[i] = Math.min(Math.min(dpr[i-1], dpl[i-1])+P, dpr[i-1]+Math.max(0, H[i]-H[i-1]));
			dpl[i] = Math.min(Math.min(dpr[i-1], dpl[i-1])+P, dpl[i-1]+Math.max(0, H[i-1]-H[i]));
		}
		System.out.println(Math.min(dpr[N-1], dpl[N-1]));
	}

}
0