結果
問題 | No.657 テトラナッチ数列 Easy |
ユーザー | こまる |
提出日時 | 2020-11-06 13:40:32 |
言語 | Haskell (9.8.2) |
結果 |
AC
|
実行時間 | 8 ms / 2,000 ms |
コード長 | 2,060 bytes |
コンパイル時間 | 5,268 ms |
コンパイル使用メモリ | 215,296 KB |
実行使用メモリ | 8,704 KB |
最終ジャッジ日時 | 2024-07-22 11:46:38 |
合計ジャッジ時間 | 6,066 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,248 KB |
testcase_02 | AC | 2 ms
5,248 KB |
testcase_03 | AC | 1 ms
5,248 KB |
testcase_04 | AC | 2 ms
5,376 KB |
testcase_05 | AC | 7 ms
8,320 KB |
testcase_06 | AC | 2 ms
5,376 KB |
testcase_07 | AC | 1 ms
5,376 KB |
testcase_08 | AC | 2 ms
5,376 KB |
testcase_09 | AC | 7 ms
8,448 KB |
testcase_10 | AC | 7 ms
8,320 KB |
testcase_11 | AC | 8 ms
8,448 KB |
testcase_12 | AC | 7 ms
8,576 KB |
testcase_13 | AC | 7 ms
8,576 KB |
testcase_14 | AC | 7 ms
8,704 KB |
testcase_15 | AC | 7 ms
8,448 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 #-}