結果
問題 |
No.707 書道
|
ユーザー |
|
提出日時 | 2019-03-13 19:10:40 |
言語 | Haskell (9.10.1) |
結果 |
AC
|
実行時間 | 24 ms / 2,000 ms |
コード長 | 1,071 bytes |
コンパイル時間 | 7,895 ms |
コンパイル使用メモリ | 174,592 KB |
実行使用メモリ | 7,808 KB |
最終ジャッジ日時 | 2024-06-23 20:52:22 |
合計ジャッジ時間 | 6,015 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 6 |
コンパイルメッセージ
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:33:13: warning: [GHC-63394] [-Wx-partial] In the use of ‘head’ (imported from Prelude, but defined in GHC.List): "This is a partial function, it throws an error on empty lists. Use pattern matching or Data.List.uncons instead. Consider refactoring to use Data.List.NonEmpty." | 33 | print $ head $ sort $ solve (getWaku w h) (getMasu 0 w h ps) | ^^^^ [2 of 2] Linking a.out
ソースコード
import Control.Monad (replicateM) import Data.List (sort) distance :: (Int, Int) -> (Int, Int) -> Double distance a b = sqrt $ distance2 a b distance2 :: (Int, Int) -> (Int, Int) -> Double distance2 a b = x2 + y2 where x2 = (fromIntegral (fst a) - fromIntegral (fst b)) ** 2 y2 = (fromIntegral (snd a) - fromIntegral (snd b)) ** 2 solve :: [(Int, Int)] -> [(Int, Int)] -> [Double] solve [] _ = [] solve (w:ws) ms = d : solve ws ms where d = foldr (\x y -> distance w x + y) 0.0 ms getWaku w h = [ (x, 0) | x <- [1..w] ] ++ [ (0, y) | y <- [1..h] ] ++ [ (x, h + 1) | x <- [1..w] ] ++ [ (w + 1, y) | y <- [1..h] ] getMasu _ _ _ [] = [] getMasu i w h (c:ps) | c == '1' = masu : getMasu (i + 1) w h ps | otherwise = getMasu (i + 1) w h ps where (d, m) = divMod i w masu = (m + 1, d + 1) main = do [h, w] <- map read . words <$> getLine :: IO [Int] ps <- foldr (++) [] <$> replicateM h getLine :: IO String print $ head $ sort $ solve (getWaku w h) (getMasu 0 w h ps)