結果
| 問題 |
No.595 登山
|
| コンテスト | |
| ユーザー |
test
|
| 提出日時 | 2017-11-11 14:48:03 |
| 言語 | Haskell (9.10.1) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 468 bytes |
| コンパイル時間 | 5,382 ms |
| コンパイル使用メモリ | 176,376 KB |
| 実行使用メモリ | 66,432 KB |
| 最終ジャッジ日時 | 2024-11-24 19:06:14 |
| 合計ジャッジ時間 | 12,270 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 4 WA * 21 |
コンパイルメッセージ
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:5:1: warning: [GHC-94817] [-Wtabs]
Tab character found here, and in 18 further locations.
Suggested fix: Please use spaces instead.
|
5 | [n, p] <- map read . words <$> getLine
| ^^^^^^^^
Main.hs:10:48: 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."
|
10 | solve x p = minPair $ foldl' f (0, p) $ zip x (tail x)
| ^^^^
[2 of 2] Linking a.out
ソースコード
import Data.List main :: IO () main = do [n, p] <- map read . words <$> getLine h <- map read . words <$> getLine print $ solve h p solve :: [Int] -> Int -> Int solve x p = minPair $ foldl' f (0, p) $ zip x (tail x) where f :: (Int, Int) -> (Int, Int) -> (Int, Int) f (dp0, dp1) (h0, h1) = (v0, v1) where v0 = min (dp0 + max 0 (h1 - h0)) (dp1 + p) v1 = min (dp1 + max 0 (h0 - h1)) (dp0 + p) minPair :: (Int, Int) -> Int minPair (x, y) = min x y
test