結果

問題 No.314 ケンケンパ
ユーザー こまるこまる
提出日時 2020-10-13 17:43:35
言語 Haskell
(9.8.2)
結果
AC  
実行時間 22 ms / 1,000 ms
コード長 975 bytes
コンパイル時間 4,584 ms
コンパイル使用メモリ 164,620 KB
実行使用メモリ 13,908 KB
最終ジャッジ日時 2023-09-28 00:12:33
合計ジャッジ時間 6,061 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 22 ms
13,908 KB
testcase_01 AC 2 ms
6,844 KB
testcase_02 AC 2 ms
6,868 KB
testcase_03 AC 2 ms
6,780 KB
testcase_04 AC 2 ms
6,880 KB
testcase_05 AC 2 ms
6,760 KB
testcase_06 AC 2 ms
6,900 KB
testcase_07 AC 2 ms
6,772 KB
testcase_08 AC 2 ms
6,820 KB
testcase_09 AC 2 ms
6,888 KB
testcase_10 AC 2 ms
6,784 KB
testcase_11 AC 2 ms
6,896 KB
testcase_12 AC 2 ms
6,792 KB
testcase_13 AC 2 ms
6,856 KB
testcase_14 AC 3 ms
6,892 KB
testcase_15 AC 2 ms
6,944 KB
testcase_16 AC 3 ms
6,944 KB
testcase_17 AC 3 ms
7,572 KB
testcase_18 AC 11 ms
9,852 KB
testcase_19 AC 22 ms
13,632 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 #

{-# LANGUAGE BangPatterns       #-}
{-# LANGUAGE NumericUnderscores #-}

import qualified Data.Vector.Fusion.Stream.Monadic as VFSM
import qualified Data.Vector.Unboxed.Mutable       as VUM

stream :: Monad m => Int -> Int -> VFSM.Stream m Int
stream !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] stream #-}

rep :: Monad m => Int -> (Int -> m ()) -> m ()
rep n = flip VFSM.mapM_ (stream 3 n)
{-# INLINE rep #-}

modulo :: Int
modulo = 1_000_000_007
{-# INLINE modulo #-}

main :: IO ()
main = do
  n  <- readLn :: IO Int
  dp <- VUM.unsafeNew (n + 1)
  VUM.unsafeWrite dp 0 (1 :: Int)
  VUM.unsafeWrite dp 1 (2 :: Int)
  VUM.unsafeWrite dp 2 (2 :: Int)
  rep n $ \i -> do
    item1 <- VUM.unsafeRead dp (i - 2)
    item2 <- VUM.unsafeRead dp (i - 3)
    VUM.unsafeWrite dp i (mod (item1 + item2) modulo)
  print =<< VUM.unsafeRead dp (n - 1)
0