結果

問題 No.365 ジェンガソート
ユーザー こまる
提出日時 2020-10-26 03:20:27
言語 Haskell
(9.10.1)
結果
AC  
実行時間 11 ms / 2,000 ms
コード長 770 bytes
コンパイル時間 8,665 ms
コンパイル使用メモリ 212,652 KB
実行使用メモリ 11,392 KB
最終ジャッジ日時 2024-07-21 21:13:56
合計ジャッジ時間 11,242 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 41
権限があれば一括ダウンロードができます
コンパイルメッセージ
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 #

import           Control.Monad.State   (StateT(..))
import           Data.Char             (isSpace)
import           Data.Coerce           (coerce)
import qualified Data.ByteString.Char8 as BSC8
import qualified Data.Vector.Unboxed   as VU

main :: IO ()
main = do
  n  <- readLn :: IO Int
  xs <- seqInput n
  print $ VU.foldr' (\x acc -> if x == acc then acc - 1 else acc) n $ xs

type CParser a = StateT BSC8.ByteString Maybe a

runCParser :: CParser a -> BSC8.ByteString -> Maybe (a, BSC8.ByteString)
runCParser = runStateT
{-# INLINE runCParser #-}

int :: CParser Int
int = coerce $ BSC8.readInt . BSC8.dropWhile isSpace
{-# INLINE int #-}

seqInput :: Int -> IO (VU.Vector Int)
seqInput n = VU.unfoldrN n (runCParser int) <$> BSC8.getLine
{-# INLINE seqInput #-}
0