結果

問題 No.707 書道
ユーザー momen999momen999
提出日時 2019-03-13 19:10:40
言語 Haskell
(9.8.2)
結果
AC  
実行時間 22 ms / 2,000 ms
コード長 1,071 bytes
コンパイル時間 5,484 ms
コンパイル使用メモリ 163,124 KB
実行使用メモリ 10,592 KB
最終ジャッジ日時 2023-09-06 01:49:54
合計ジャッジ時間 3,443 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
7,440 KB
testcase_01 AC 2 ms
7,584 KB
testcase_02 AC 5 ms
7,732 KB
testcase_03 AC 2 ms
7,492 KB
testcase_04 AC 3 ms
7,280 KB
testcase_05 AC 6 ms
7,956 KB
testcase_06 AC 12 ms
10,088 KB
testcase_07 AC 22 ms
10,592 KB
testcase_08 AC 3 ms
7,572 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 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)
0