結果

問題 No.168 ものさし
ユーザー gigurururugigurururu
提出日時 2015-03-21 00:19:54
言語 Haskell
(9.8.2)
結果
AC  
実行時間 793 ms / 2,000 ms
コード長 1,398 bytes
コンパイル時間 3,842 ms
コンパイル使用メモリ 183,040 KB
実行使用メモリ 181,520 KB
最終ジャッジ日時 2023-09-11 09:07:46
合計ジャッジ時間 9,027 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 92 ms
36,612 KB
testcase_01 AC 2 ms
7,204 KB
testcase_02 AC 3 ms
7,168 KB
testcase_03 AC 3 ms
7,140 KB
testcase_04 AC 2 ms
7,132 KB
testcase_05 AC 2 ms
7,228 KB
testcase_06 AC 3 ms
7,180 KB
testcase_07 AC 2 ms
7,204 KB
testcase_08 AC 2 ms
7,180 KB
testcase_09 AC 7 ms
9,008 KB
testcase_10 AC 23 ms
12,644 KB
testcase_11 AC 112 ms
26,744 KB
testcase_12 AC 593 ms
125,216 KB
testcase_13 AC 782 ms
181,500 KB
testcase_14 AC 793 ms
181,520 KB
testcase_15 AC 4 ms
7,248 KB
testcase_16 AC 5 ms
7,856 KB
testcase_17 AC 12 ms
9,160 KB
testcase_18 AC 22 ms
13,264 KB
testcase_19 AC 344 ms
76,988 KB
testcase_20 AC 364 ms
77,804 KB
testcase_21 AC 365 ms
77,980 KB
testcase_22 AC 364 ms
77,516 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
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