結果

問題 No.595 登山
ユーザー pekempeypekempey
提出日時 2017-11-11 18:47:30
言語 Haskell
(9.8.2)
結果
AC  
実行時間 594 ms / 1,500 ms
コード長 474 bytes
コンパイル時間 970 ms
コンパイル使用メモリ 159,860 KB
実行使用メモリ 67,752 KB
最終ジャッジ日時 2023-08-16 07:45:56
合計ジャッジ時間 10,468 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
7,124 KB
testcase_01 AC 2 ms
7,188 KB
testcase_02 AC 2 ms
7,240 KB
testcase_03 AC 2 ms
7,132 KB
testcase_04 AC 434 ms
67,692 KB
testcase_05 AC 122 ms
23,804 KB
testcase_06 AC 402 ms
61,308 KB
testcase_07 AC 42 ms
15,092 KB
testcase_08 AC 73 ms
18,640 KB
testcase_09 AC 402 ms
61,548 KB
testcase_10 AC 263 ms
37,932 KB
testcase_11 AC 232 ms
37,996 KB
testcase_12 AC 42 ms
15,320 KB
testcase_13 AC 111 ms
23,916 KB
testcase_14 AC 282 ms
37,244 KB
testcase_15 AC 272 ms
37,256 KB
testcase_16 AC 272 ms
37,024 KB
testcase_17 AC 272 ms
37,276 KB
testcase_18 AC 282 ms
37,280 KB
testcase_19 AC 584 ms
67,620 KB
testcase_20 AC 594 ms
67,596 KB
testcase_21 AC 563 ms
67,668 KB
testcase_22 AC 574 ms
67,652 KB
testcase_23 AC 585 ms
67,680 KB
testcase_24 AC 3 ms
7,044 KB
testcase_25 AC 2 ms
7,100 KB
testcase_26 AC 584 ms
67,592 KB
testcase_27 AC 445 ms
67,752 KB
testcase_28 AC 434 ms
67,636 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Loaded package environment from /home/judge/.ghc/x86_64-linux-9.6.1/environments/default
[1 of 2] Compiling Main             ( Main.hs, Main.o )
[2 of 2] Linking a.out

ソースコード

diff #

import Data.List

main = do
  [_, p] <- map read . words <$> getLine
  h <- map read . words <$> getLine
  print $ solve p h

solve :: Int -> [Int] -> Int
solve p a = uncurry min . foldl' f (0, p) $ zip a (tail a)
  where
    f :: (Int, Int) -> (Int, Int) -> (Int, Int)
    f (dpR, dpL) (h0, h1) = (v0, v1)
      where
        r = max 0 (h1 - h0)
        l = max 0 (h0 - h1)
        v0 = minimum [dpR + r, dpR + p, dpL + p]
        v1 = minimum [dpL + l, dpL + p, dpR + p]

0