結果
問題 | No.658 テトラナッチ数列 Hard |
ユーザー | こまる |
提出日時 | 2020-10-24 20:28:46 |
言語 | Haskell (9.8.2) |
結果 |
AC
|
実行時間 | 9 ms / 2,000 ms |
コード長 | 2,060 bytes |
コンパイル時間 | 7,208 ms |
コンパイル使用メモリ | 215,156 KB |
実行使用メモリ | 9,088 KB |
最終ジャッジ日時 | 2024-07-21 15:36:51 |
合計ジャッジ時間 | 8,133 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,816 KB |
testcase_01 | AC | 2 ms
6,940 KB |
testcase_02 | AC | 2 ms
6,944 KB |
testcase_03 | AC | 2 ms
6,944 KB |
testcase_04 | AC | 8 ms
8,832 KB |
testcase_05 | AC | 8 ms
8,704 KB |
testcase_06 | AC | 8 ms
8,576 KB |
testcase_07 | AC | 8 ms
8,576 KB |
testcase_08 | AC | 9 ms
8,704 KB |
testcase_09 | AC | 8 ms
8,960 KB |
testcase_10 | AC | 9 ms
9,088 KB |
コンパイルメッセージ
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
ソースコード
{-# LANGUAGE BangPatterns #-} import Control.Monad.State import Data.Char import Data.Coerce import qualified Data.ByteString.Char8 as BSC8 import qualified Data.Vector.Fusion.Stream.Monadic as VFSM import qualified Data.Vector.Unboxed as VU import qualified Data.Vector.Unboxed.Mutable as VUM main :: IO () main = do t <- VUM.unsafeNew 10001 VUM.unsafeWrite t 0 (0 :: Int) VUM.unsafeWrite t 1 (0 :: Int) VUM.unsafeWrite t 2 (0 :: Int) VUM.unsafeWrite t 3 (1 :: Int) rep1 $ \i -> do item1 <- VUM.unsafeRead t (i - 1) item2 <- VUM.unsafeRead t (i - 2) item3 <- VUM.unsafeRead t (i - 3) item4 <- VUM.unsafeRead t (i - 4) VUM.unsafeWrite t i ((item1 + item2 + item3 + item4) `mod` 17) q <- readLn :: IO Int qs <- parseN1 q rep2 q $ \i -> print =<< VUM.unsafeRead t (mod (qs VU.! i) 4912) stream1 :: Monad m => Int -> Int -> VFSM.Stream m Int stream1 !l !r = VFSM.Stream step l where step x | x <= r = return $ VFSM.Yield x (x + 1) | otherwise = return $ VFSM.Done {-# INLINE [0] step #-} {-# INLINE [1] stream1 #-} rep1 :: Monad m => (Int -> m ()) -> m () rep1 = flip VFSM.mapM_ (stream1 4 10000) {-# INLINE rep1 #-} stream2 :: Monad m => Int -> Int -> VFSM.Stream m Int stream2 !l !r = VFSM.Stream step l where step x | x < r = return $ VFSM.Yield x (x + 1) | otherwise = return $ VFSM.Done {-# INLINE [0] step #-} {-# INLINE [1] stream2 #-} rep2 :: Monad m => Int -> (Int -> m ()) -> m () rep2 n = flip VFSM.mapM_ (stream2 0 n) {-# INLINE rep2 #-} 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 #-} int1 :: CParser Int int1 = fmap (subtract 1) int {-# INLINE int1 #-} parseN1 :: Int -> IO (VU.Vector Int) parseN1 n = VU.unfoldrN n (runCParser int1) <$> BSC8.getContents {-# INLINE parseN1 #-}