結果
| 問題 | No.595 登山 | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2017-11-11 18:47:30 | 
| 言語 | Haskell (9.10.1) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 578 ms / 1,500 ms | 
| コード長 | 474 bytes | 
| コンパイル時間 | 5,535 ms | 
| コンパイル使用メモリ | 171,776 KB | 
| 実行使用メモリ | 66,176 KB | 
| 最終ジャッジ日時 | 2024-11-24 19:23:15 | 
| 合計ジャッジ時間 | 10,721 ms | 
| ジャッジサーバーID (参考情報) | judge2 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 25 | 
コンパイルメッセージ
Loaded package environment from /home/judge/.ghc/x86_64-linux-9.8.2/environments/default
[1 of 2] Compiling Main             ( Main.hs, Main.o )
Main.hs:9:52: warning: [GHC-63394] [-Wx-partial]
    In the use of ‘tail’
    (imported from Data.List, but defined in GHC.List):
    "This is a partial function, it throws an error on empty lists. Replace it with drop 1, or use pattern matching or Data.List.uncons instead. Consider refactoring to use Data.List.NonEmpty."
  |
9 | solve p a = uncurry min . foldl' f (0, p) $ zip a (tail a)
  |                                                    ^^^^
[2 of 2] Linking a.out
            
            ソースコード
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]
            
            
            
        