結果

問題 No.168 ものさし
ユーザー gigurururugigurururu
提出日時 2015-03-20 18:05:08
言語 Haskell
(9.8.2)
結果
AC  
実行時間 1,164 ms / 2,000 ms
コード長 1,310 bytes
コンパイル時間 1,103 ms
コンパイル使用メモリ 163,608 KB
実行使用メモリ 89,648 KB
最終ジャッジ日時 2023-08-25 20:51:59
合計ジャッジ時間 7,729 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 202 ms
28,148 KB
testcase_01 AC 2 ms
7,392 KB
testcase_02 AC 2 ms
7,404 KB
testcase_03 AC 3 ms
7,484 KB
testcase_04 AC 2 ms
7,396 KB
testcase_05 AC 2 ms
7,676 KB
testcase_06 AC 3 ms
7,608 KB
testcase_07 AC 3 ms
7,660 KB
testcase_08 AC 3 ms
7,588 KB
testcase_09 AC 6 ms
9,468 KB
testcase_10 AC 22 ms
12,896 KB
testcase_11 AC 193 ms
27,760 KB
testcase_12 AC 363 ms
38,400 KB
testcase_13 AC 1,104 ms
89,648 KB
testcase_14 AC 22 ms
12,156 KB
testcase_15 AC 2 ms
7,448 KB
testcase_16 AC 4 ms
8,764 KB
testcase_17 AC 12 ms
11,940 KB
testcase_18 AC 12 ms
11,028 KB
testcase_19 AC 473 ms
51,640 KB
testcase_20 AC 262 ms
37,600 KB
testcase_21 AC 1,164 ms
88,692 KB
testcase_22 AC 433 ms
49,700 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 Data.Array
import Data.Maybe
import qualified Data.Set as S
import qualified Data.ByteString.Char8 as B
 
pqEmpty         = S.empty
pqAdd     pq n  = S.insert n pq
pqGet     pq    = S.deleteFindMin pq
pqMember  pq n  = S.member n pq
pqIsEmpty pq    = S.null pq

hypot2:: Integer -> Integer -> Integer
hypot2 x y = x*x+y*y

solve :: Int -> [[Integer]] -> Integer
solve n l = adjust
  where
    adjust = if ansd*ansd < ans then ansd+10 else ansd
    ansd =  (*10) . ceiling . sqrt . (/100) . fromIntegral $ ans
    ans :: Integer
    ans = primlike pqEmpty (pqAdd pqEmpty (0,0)) 10
    dst:: Int -> [(Integer,Int)]
    dst i = let [x1,y1] = (l!!i) in map (\(j,[x2,y2])->(hypot2 (x1-x2) (y1-y2),j)) $ zip [0..] l
    primlike:: S.Set (Int) -> S.Set ((Integer,Int)) -> Integer -> Integer
    primlike visited pq mx
      | d==n-1       = max my mx
      | pqMember visited d = primlike visited nextpq mx
      | otherwise          = primlike (pqAdd visited d) (foldl pqAdd nextpq $ filter (not . pqMember visited . snd) (dst d)) $ max mx my
          where
            ((my,d),nextpq) = pqGet pq
 
main = do
  n <- fst . fromJust . B.readInt <$> B.getLine
  l <- replicateM n $ map (fst . fromJust . B.readInteger) . B.words <$> B.getLine
  print $ solve n l
0