結果

問題 No.168 ものさし
ユーザー gigurururugigurururu
提出日時 2015-03-20 20:24:52
言語 Haskell
(9.8.2)
結果
AC  
実行時間 1,103 ms / 2,000 ms
コード長 1,294 bytes
コンパイル時間 796 ms
コンパイル使用メモリ 165,292 KB
実行使用メモリ 97,968 KB
最終ジャッジ日時 2023-08-25 20:52:57
合計ジャッジ時間 5,905 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 193 ms
28,880 KB
testcase_01 AC 3 ms
7,200 KB
testcase_02 AC 3 ms
7,112 KB
testcase_03 AC 2 ms
7,272 KB
testcase_04 AC 2 ms
7,268 KB
testcase_05 AC 2 ms
7,184 KB
testcase_06 AC 2 ms
7,252 KB
testcase_07 AC 2 ms
7,104 KB
testcase_08 AC 2 ms
7,256 KB
testcase_09 AC 5 ms
8,936 KB
testcase_10 AC 22 ms
12,676 KB
testcase_11 AC 163 ms
29,044 KB
testcase_12 AC 332 ms
39,752 KB
testcase_13 AC 1,053 ms
97,968 KB
testcase_14 AC 22 ms
11,880 KB
testcase_15 AC 3 ms
7,196 KB
testcase_16 AC 4 ms
8,324 KB
testcase_17 AC 12 ms
11,780 KB
testcase_18 AC 8 ms
10,340 KB
testcase_19 AC 433 ms
54,440 KB
testcase_20 AC 212 ms
29,936 KB
testcase_21 AC 1,103 ms
95,472 KB
testcase_22 AC 402 ms
52,568 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:: Int -> Int -> Int
hypot2 x y = x*x+y*y

solve :: Int -> [[Int]] -> Int
solve n l = adjust
  where
    adjust = if ansd*ansd < ans then ansd+10 else ansd
    ansd =  (*10) . ceiling . sqrt . (/100) . fromIntegral $ ans
    ans :: Int
    ans = primlike pqEmpty (pqAdd pqEmpty (0,0)) 10
    dst:: Int -> [(Int,Int)]
    dst i = let [x1,y1] = (la!i) in map (\(j,[x2,y2])->(hypot2 (x1-x2) (y1-y2),j)) $ zip [0..] l
    la = listArray (0,n-1) l
    primlike:: S.Set (Int) -> S.Set ((Int,Int)) -> Int -> Int
    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.readInt) . B.words <$> B.getLine
  print $ solve n l
0