結果

問題 No.707 書道
ユーザー ducktailducktail
提出日時 2018-08-30 13:10:15
言語 Haskell
(9.8.2)
結果
AC  
実行時間 6 ms / 2,000 ms
コード長 799 bytes
コンパイル時間 6,255 ms
コンパイル使用メモリ 164,260 KB
実行使用メモリ 7,736 KB
最終ジャッジ日時 2023-10-11 20:57:04
合計ジャッジ時間 7,053 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
7,316 KB
testcase_01 AC 3 ms
7,300 KB
testcase_02 AC 4 ms
7,468 KB
testcase_03 AC 3 ms
7,260 KB
testcase_04 AC 3 ms
7,152 KB
testcase_05 AC 4 ms
7,580 KB
testcase_06 AC 5 ms
7,664 KB
testcase_07 AC 6 ms
7,736 KB
testcase_08 AC 3 ms
7,392 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.Applicative
import Control.Monad

main :: IO ()
main = do
  [h, w] <- f
  solve [h, w] <$> replicateM h getLine >>= print
  where
    f = map read <$> words <$> getLine

solve :: [Int] -> [String] -> Double
solve [h, w] pss = minimum $ do
  (rx, ry) <- rs
  return $ sum $ do
    (bx, by) <- bs
    return $ dist (rx, ry) (bx, by)
  where
    rs = map (\x -> (x, 0)) [1..w] ++ map (\x -> (x,h+1)) [1..w]
         ++ map (\y -> (0, y)) [1..h] ++ map (\y -> (w+1,y)) [1..h]
    bs :: [(Int, Int)]
    bs = do
      (y, s) <- zip [1..] pss
      (x, c) <- zip [1..] s
      guard $ c == '1'
      return (x, y)

dist :: (Int, Int) -> (Int, Int) -> Double
dist (x0, y0) (x1, y1) = sqrt $ (fromIntegral dx) ^ 2 + (fromIntegral dy) ^ 2
  where
    dx = abs (x0 - x1)
    dy = abs (y0 - y1)
0