結果

問題 No.595 登山
ユーザー mkawa2mkawa2
提出日時 2020-05-24 22:29:48
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 372 ms / 1,500 ms
コード長 1,008 bytes
コンパイル時間 332 ms
コンパイル使用メモリ 10,684 KB
実行使用メモリ 38,176 KB
最終ジャッジ日時 2023-08-02 14:09:51
合計ジャッジ時間 9,342 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 20 ms
8,628 KB
testcase_01 AC 20 ms
8,580 KB
testcase_02 AC 20 ms
8,660 KB
testcase_03 AC 20 ms
8,724 KB
testcase_04 AC 344 ms
33,052 KB
testcase_05 AC 111 ms
15,344 KB
testcase_06 AC 300 ms
31,096 KB
testcase_07 AC 47 ms
10,492 KB
testcase_08 AC 64 ms
11,876 KB
testcase_09 AC 304 ms
31,408 KB
testcase_10 AC 214 ms
22,096 KB
testcase_11 AC 192 ms
23,232 KB
testcase_12 AC 44 ms
10,760 KB
testcase_13 AC 101 ms
14,324 KB
testcase_14 AC 336 ms
25,768 KB
testcase_15 AC 336 ms
25,532 KB
testcase_16 AC 338 ms
25,428 KB
testcase_17 AC 341 ms
25,276 KB
testcase_18 AC 337 ms
23,624 KB
testcase_19 AC 370 ms
37,356 KB
testcase_20 AC 369 ms
37,800 KB
testcase_21 AC 372 ms
37,156 KB
testcase_22 AC 368 ms
38,176 KB
testcase_23 AC 366 ms
37,204 KB
testcase_24 AC 21 ms
8,624 KB
testcase_25 AC 19 ms
8,684 KB
testcase_26 AC 370 ms
35,776 KB
testcase_27 AC 341 ms
31,720 KB
testcase_28 AC 340 ms
31,632 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from operator import itemgetter
from itertools import *
from bisect import *
from collections import *
from heapq import *
import sys

sys.setrecursionlimit(10 ** 6)

def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def SI(): return sys.stdin.readline()[:-1]
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
int1 = lambda x: int(x) - 1
def MI1(): return map(int1, sys.stdin.readline().split())
def LI1(): return list(map(int1, sys.stdin.readline().split()))
p2D = lambda x: print(*x, sep="\n")
dij = [(1, 0), (0, 1), (-1, 0), (0, -1)]

def main():
    n,p=MI()
    hh=LI()
    dpf=[0]*n
    dpb=[p]*n
    for i in range(1,n):
        warp=min(dpf[i-1],dpb[i-1])+p
        dpf[i]=min(warp,dpf[i-1]+max(0,hh[i]-hh[i-1]))
        dpb[i]=min(warp,dpb[i-1]+max(0,-hh[i]+hh[i-1]))
    print(min(dpf[-1],dpb[-1]))

main()
0