結果

問題 No.168 ものさし
ユーザー gigurururu
提出日時 2015-03-21 00:19:54
言語 Haskell
(9.10.1)
結果
AC  
実行時間 808 ms / 2,000 ms
コード長 1,398 bytes
コンパイル時間 3,994 ms
コンパイル使用メモリ 193,792 KB
実行使用メモリ 179,712 KB
最終ジャッジ日時 2024-06-28 23:48:29
合計ジャッジ時間 8,679 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 19
権限があれば一括ダウンロードができます
コンパイルメッセージ
Loaded package environment from /home/judge/.ghc/x86_64-linux-9.8.2/environments/default
[1 of 2] Compiling Main             ( Main.hs, Main.o )
[2 of 2] Linking a.out

ソースコード

diff #

import Control.Applicative
import Control.Monad
import Control.Monad.ST
import Data.Maybe
import Data.Either
import Data.List
import Data.Array.ST
import qualified Data.ByteString.Char8 as B

unionfind :: (Int,Int) -> [Either Int (Int,Int)] -> [Int]
unionfind bounds@(lower,upper) queryList = runST $ do
  un <- newListArray bounds [lower..upper] :: ST s (STUArray s Int Int)
  let 
      f ret x = do
        t <- either find union x
        return (t:ret)
      find n        = do
        nn <- readArray un n
        if n==nn then return n else do
          nnn <- find nn
          writeArray un n nnn
          return nnn
      union (a,b)   = do
        aa <- find a
        bb <- find b
        writeArray un aa bb
        return (-1)
  filter (/= -1) <$> foldM f [] queryList

hypot2 x y = x*x+y*y

solve n ls = bsearch 0 200000000
  where
    dst = [((i,j),hypot2 (xi-xj) (yi-yj))|(i,[xi,yi])<-zip [0..] ls,(j,[xj,yj])<-zip [0..] ls,i<j]
    bsearch l r
      | l>=r      = l*10
      | check     = bsearch l c
      | otherwise = bsearch (c+1) r
        where
          c       = (l+r)`div`2
          check   = a==b
          [a,b]   = unionfind (0,n-1) $ (map (Right . fst) $ filter ((100*c*c>=).snd) dst)++(map Left [0,n-1])

main = do
  n  <- fst . fromJust . B.readInt <$> B.getLine
  ls <- replicateM n $ map (fst . fromJust . B.readInt) . B.words <$> B.getLine
  print $ solve n ls
0