結果

問題 No.168 ものさし
ユーザー gigurururugigurururu
提出日時 2015-03-20 19:08:48
言語 Haskell
(9.8.2)
結果
AC  
実行時間 1,314 ms / 2,000 ms
コード長 1,267 bytes
コンパイル時間 6,194 ms
コンパイル使用メモリ 165,936 KB
実行使用メモリ 90,700 KB
最終ジャッジ日時 2023-08-25 20:51:48
合計ジャッジ時間 11,704 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 223 ms
31,156 KB
testcase_01 AC 3 ms
7,352 KB
testcase_02 AC 2 ms
7,308 KB
testcase_03 AC 3 ms
7,436 KB
testcase_04 AC 3 ms
7,340 KB
testcase_05 AC 3 ms
7,568 KB
testcase_06 AC 3 ms
7,400 KB
testcase_07 AC 3 ms
7,568 KB
testcase_08 AC 2 ms
7,380 KB
testcase_09 AC 6 ms
9,400 KB
testcase_10 AC 22 ms
12,816 KB
testcase_11 AC 183 ms
24,044 KB
testcase_12 AC 412 ms
40,648 KB
testcase_13 AC 1,253 ms
90,700 KB
testcase_14 AC 22 ms
12,084 KB
testcase_15 AC 3 ms
7,360 KB
testcase_16 AC 4 ms
8,704 KB
testcase_17 AC 12 ms
11,936 KB
testcase_18 AC 8 ms
10,760 KB
testcase_19 AC 473 ms
41,448 KB
testcase_20 AC 242 ms
31,596 KB
testcase_21 AC 1,314 ms
89,508 KB
testcase_22 AC 412 ms
40,576 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
pqNotMember pq n = S.notMember n pq
pqIsEmpty pq    = S.null pq
pqSingleton  n  = S.singleton n

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

solve :: Int -> [[Integer]] -> Integer
solve n l = if ansd^2 < ans then ansd+10 else ansd
  where
    ansd =  (*10) . ceiling . sqrt . (/100) . fromIntegral $ ans
    ans = primlike pqEmpty (pqSingleton (0,0)) 10
    dst i = let [x1,y1] = la!i in map (\[x2,y2]->hypot2 (x1-x2) (y1-y2)) l
    la = listArray (0,n-1) l
    primlike visited pq mx
      | d==n-1       = max mx my
      | pqMember visited d = primlike visited gotpq mx
      | otherwise          = primlike (pqAdd visited d) addedpq $ max mx my
          where
            addedpq = foldl pqAdd gotpq $ filter (pqNotMember visited . snd) $ zip (dst d) [0..]
            ((my,d),gotpq) = 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