結果

問題 No.1138 No Bingo!
ユーザー こまるこまる
提出日時 2020-10-14 17:39:28
言語 Haskell
(9.8.2)
結果
AC  
実行時間 22 ms / 3,000 ms
コード長 1,806 bytes
コンパイル時間 1,903 ms
コンパイル使用メモリ 167,148 KB
実行使用メモリ 13,388 KB
最終ジャッジ日時 2023-09-28 00:42:30
合計ジャッジ時間 3,891 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
9,076 KB
testcase_01 AC 3 ms
9,000 KB
testcase_02 AC 2 ms
8,900 KB
testcase_03 AC 12 ms
11,344 KB
testcase_04 AC 22 ms
13,388 KB
testcase_05 AC 3 ms
8,960 KB
testcase_06 AC 3 ms
8,956 KB
testcase_07 AC 3 ms
8,968 KB
testcase_08 AC 2 ms
8,916 KB
testcase_09 AC 11 ms
11,648 KB
testcase_10 AC 22 ms
12,736 KB
testcase_11 AC 22 ms
13,044 KB
testcase_12 AC 6 ms
10,456 KB
testcase_13 AC 3 ms
9,296 KB
testcase_14 AC 22 ms
12,932 KB
testcase_15 AC 7 ms
10,888 KB
testcase_16 AC 22 ms
12,748 KB
testcase_17 AC 12 ms
12,760 KB
testcase_18 AC 12 ms
12,656 KB
testcase_19 AC 12 ms
11,764 KB
testcase_20 AC 22 ms
12,704 KB
testcase_21 AC 12 ms
12,620 KB
testcase_22 AC 12 ms
12,396 KB
testcase_23 AC 3 ms
9,088 KB
testcase_24 AC 12 ms
11,536 KB
testcase_25 AC 7 ms
10,640 KB
testcase_26 AC 5 ms
10,368 KB
testcase_27 AC 7 ms
11,284 KB
testcase_28 AC 6 ms
10,320 KB
testcase_29 AC 5 ms
10,292 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               #-}

import           Control.Monad
import           Control.Monad.ST
import           Data.STRef
import qualified Data.Vector.Fusion.Stream.Monadic as VFSM
import qualified Data.Vector.Unboxed.Mutable       as VUM
import           GHC.Exts

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 #-}

rep1 :: Monad m => Int -> (Int -> m ()) -> m ()
rep1 n = flip VFSM.mapM_ (stream 1 (n + 1))

rep2 :: Monad m => Int -> (Int -> m ()) -> m ()
rep2 n = flip VFSM.mapM_ (stream 2 (n + 1))

main :: IO ()
main = readLn >>= print . solver

solver :: Int -> Int
solver n = runST $ do
  as <- VUM.unsafeNew 202020
  bs <- VUM.unsafeNew 202020
  ss <- newSTRef (1 :: Int)
  rep1 n $ \i -> modifySTRef' ss (\s -> s * i `mod` 998244353)
  VUM.unsafeWrite as 0 (1 :: Int)
  VUM.unsafeWrite bs 0 (1 :: Int)
  rep2 n $ \i -> do
    itemA1 <- VUM.unsafeRead as (i - 1)
    itemA2 <- VUM.unsafeRead as (i - 2)
    VUM.unsafeWrite as i ((i - 1) * (itemA1 + itemA2) `mod` 998244353)
    when (i >= 4) $ do
      if even i
        then do
          itemb1 <- VUM.unsafeRead bs (i - 1)
          itemb4 <- VUM.unsafeRead bs (i - 4)
          VUM.unsafeWrite bs i (((i - 1) * itemb1 + 2 * (i - 2) * itemb4) `mod` 998244353)
        else do
          itemb1 <- VUM.unsafeRead bs (i - 1)
          itemb2 <- VUM.unsafeRead bs (i - 2)
          VUM.unsafeWrite bs i (((i - 1) * itemb1 + 2 * (i - 1) * itemb2) `mod` 998244353)
  item0 <- readSTRef ss
  item1 <- VUM.unsafeRead as n
  item2 <- VUM.unsafeRead bs n
  return $ flip mod 998244353 $ item0 - item1 - item1 + item2 + 998244353 + 998244353
0