結果

問題 No.2803 Bocching Star
ユーザー ducktail
提出日時 2024-07-13 22:25:49
言語 Haskell
(9.10.1)
結果
AC  
実行時間 1,041 ms / 2,000 ms
コード長 874 bytes
コンパイル時間 12,082 ms
コンパイル使用メモリ 180,908 KB
実行使用メモリ 58,960 KB
最終ジャッジ日時 2024-07-13 22:26:31
合計ジャッジ時間 26,969 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 35
権限があれば一括ダウンロードができます
コンパイルメッセージ
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 #

{-# LANGUAGE OverloadedStrings #-}
import Data.ByteString.Char8 (ByteString)
import qualified Data.ByteString.Char8 as B
import Data.List
import Data.Char (isSpace)

main :: IO ()
main = do
  [n, s] <- f
  solve n s <$> f >>= prt
  where
    f = readil B.readInt <$> B.getLine

solve :: Int -> Int -> [Int] -> [Int]
solve n s ps = f [] sps
  where
    sps = sort $ (10 ^ 18, n + 1)  : (-(10 ^ 18), 0) : (zip ps [1..])
    f :: [Int] -> [(Int, Int)] -> [Int]
    f hs ((p0, _) : (p1, i1) : (p2, i2) : ps)
      | p1 - p0 > s && p2 - p1 > s = f (i1 : hs) ((p1, i1) : (p2, i2) : ps)
      | otherwise = f hs ((p1, i1) : (p2, i2) : ps)
    f hs _ = sort hs
    
prt :: [Int] -> IO ()
prt l = do
  print $ length l
  putStrLn $ unwords $ map show l

readil :: Integral a =>  (ByteString -> Maybe (a, ByteString)) -> ByteString -> [a]
readil f = unfoldr $ f . B.dropWhile isSpace
0