結果
| 問題 | No.595 登山 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-11-11 18:47:30 |
| 言語 | Haskell (9.14.1) |
| 結果 |
AC
|
| 実行時間 | 401 ms / 1,500 ms |
| コード長 | 474 bytes |
| 記録 | |
| コンパイル時間 | 1,574 ms |
| コンパイル使用メモリ | 196,736 KB |
| 実行使用メモリ | 68,352 KB |
| 最終ジャッジ日時 | 2026-05-18 21:54:21 |
| 合計ジャッジ時間 | 8,375 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge1_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 25 |
コンパイルメッセージ
Loaded package environment from /home/judge/.ghc/x86_64-linux-9.14.1/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.Internal.List):
"This is a partial function, it throws an error on empty lists. Replace it with 'drop' 1, or use pattern matching or 'GHC.Internal.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]