結果

問題 No.595 登山
ユーザー tetsutetsu
提出日時 2017-11-11 23:04:23
言語 Java21
(openjdk 21)
結果
AC  
実行時間 881 ms / 1,500 ms
コード長 658 bytes
コンパイル時間 3,618 ms
コンパイル使用メモリ 77,004 KB
実行使用メモリ 68,544 KB
最終ジャッジ日時 2023-08-16 07:51:26
合計ジャッジ時間 22,709 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 128 ms
55,680 KB
testcase_01 AC 128 ms
55,268 KB
testcase_02 AC 128 ms
55,684 KB
testcase_03 AC 129 ms
55,480 KB
testcase_04 AC 733 ms
66,348 KB
testcase_05 AC 466 ms
60,736 KB
testcase_06 AC 683 ms
65,016 KB
testcase_07 AC 302 ms
60,300 KB
testcase_08 AC 360 ms
60,260 KB
testcase_09 AC 670 ms
65,236 KB
testcase_10 AC 599 ms
62,864 KB
testcase_11 AC 563 ms
60,364 KB
testcase_12 AC 294 ms
60,060 KB
testcase_13 AC 458 ms
60,336 KB
testcase_14 AC 664 ms
66,344 KB
testcase_15 AC 666 ms
66,504 KB
testcase_16 AC 675 ms
66,056 KB
testcase_17 AC 686 ms
66,916 KB
testcase_18 AC 692 ms
66,644 KB
testcase_19 AC 820 ms
66,904 KB
testcase_20 AC 810 ms
68,544 KB
testcase_21 AC 881 ms
68,468 KB
testcase_22 AC 866 ms
66,788 KB
testcase_23 AC 869 ms
66,556 KB
testcase_24 AC 129 ms
55,252 KB
testcase_25 AC 126 ms
55,648 KB
testcase_26 AC 858 ms
66,976 KB
testcase_27 AC 764 ms
66,620 KB
testcase_28 AC 761 ms
67,264 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