結果

問題 No.140 みんなで旅行
ユーザー こまるこまる
提出日時 2020-12-14 02:11:14
言語 Haskell
(9.8.2)
結果
WA  
実行時間 -
コード長 5,712 bytes
コンパイル時間 6,009 ms
コンパイル使用メモリ 180,864 KB
実行使用メモリ 30,316 KB
最終ジャッジ日時 2024-09-20 00:22:28
合計ジャッジ時間 7,307 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 2 ms
5,376 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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 #

{-# LANGUAGE BangPatterns #-}

import           Control.Monad.Cont
import           Control.Monad.ST
import           Data.IORef
import qualified Data.Vector.Fusion.Stream.Monadic as VFSM
import qualified Data.Vector.Unboxed               as VU
import qualified Data.Vector.Unboxed.Mutable       as VUM

modulus :: Int
modulus = 1000000007
{-# INLINE modulus #-}

main :: IO ()
main = do
  n <- readLn :: IO Int
  dp <- VUM.unsafeNew 309136 :: IO (VUM.IOVector Int)
  comb <- VUM.unsafeNew 309136 :: IO (VUM.IOVector Int)
  power <- VUM.unsafeNew 309136 :: IO (VUM.IOVector Int)
  VUM.unsafeWrite dp 0 1
  rep1' n $ \i -> rep1' i $ \j -> do
    item1 <- VUM.unsafeRead dp ((i - 1) * 556 + (j - 1))
    item2 <- VUM.unsafeRead dp ((i - 1) * 556 + j)
    VUM.unsafeWrite dp (i * 556 + j) ((item1 + j * item2) `mod` modulus)
  VUM.unsafeWrite comb 0 1
  rep1' n $ \i -> rep' i $ \j -> do
    item1 <- VUM.unsafeRead comb ((i - 1) * 556 + j)
    item2 <- VUM.unsafeRead comb ((i - 1) * 556 + (j - 1))
    VUM.unsafeWrite comb (i * 556 + j) ((item1 + item2) `mod` modulus)
  rep1' n $ \i -> do
    VUM.unsafeWrite power (i * 556) 1
    rep1' n $ \j -> do
      item <- VUM.unsafeRead power (i * 556 + (j - 1))
      VUM.unsafeWrite power (i * 556 + j) (item * i * (i - 1) `mod` modulus)
  ansRef <- newIORef (0 :: Int)
  rep1' n $ \i -> rep1' i $ \j -> do
    combni <- VUM.unsafeRead comb (n * 556 + i)
    dpij <- VUM.unsafeRead dp (i * 556 + j)
    powerjni <- VUM.unsafeRead power (j * 556 + (n - i))
    ans <- readIORef ansRef
    writeIORef ansRef ((ans + combni * dpij `mod` modulus * powerjni) `mod` modulus)
  print =<< readIORef ansRef

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

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

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

rep1' :: Monad m => Int -> (Int -> m ()) -> m ()
rep1' n = flip VFSM.mapM_ (stream 1 (n + 1))
{-# INLINE rep1' #-}

rev :: Monad m => Int -> (Int -> m ()) -> m ()
rev n = flip VFSM.mapM_ (streamR 0 n)
{-# INLINE rev #-}

rev' :: Monad m => Int -> (Int -> m ()) -> m ()
rev' n = flip VFSM.mapM_ (streamR 0 (n + 1))
{-# INLINE rev' #-}

rev1 :: Monad m => Int -> (Int -> m ()) -> m ()
rev1 n = flip VFSM.mapM_ (streamR 1 n)
{-# INLINE rev1 #-}

rev1' :: Monad m => Int -> (Int -> m ()) -> m ()
rev1' n = flip VFSM.mapM_ (streamR 1 (n + 1))
{-# INLINE rev1' #-}

range :: Monad m => Int -> Int -> (Int -> m ()) -> m ()
range l r = flip VFSM.mapM_ (stream l (r + 1))
{-# INLINE range #-}

rangeR :: Monad m => Int -> Int -> (Int -> m ()) -> m ()
rangeR r l = flip VFSM.mapM_ (streamR l (r + 1))
{-# INLINE rangeR #-}

forStep :: Monad m => Int -> Int -> Int -> (Int -> m ()) -> m ()
forStep l r d = flip VFSM.mapM_ (streamStep l r d)
{-# INLINE forStep #-}

forStepR :: Monad m => Int -> Int -> Int -> (Int -> m ()) -> m ()
forStepR r l d = flip VFSM.mapM_ (streamStepR l r d)
{-# INLINE forStepR #-}

forP :: Monad m => Int -> (Int -> m ()) -> m ()
forP p = flip VFSM.mapM_ (streamG 2 p (^) 2 (+) 1)
{-# INLINE forP #-}

forG :: Monad m => Int -> Int -> (Int -> Int -> Int) -> Int -> (Int -> Int -> Int) -> Int -> (Int -> m ()) -> m ()
forG l r f p g d = flip VFSM.mapM_ (streamG l r f p g d)
{-# INLINE forG #-}

forRG :: Monad m => Int -> Int -> (Int -> Int -> Int) -> Int -> (Int -> Int -> Int) -> Int -> (Int -> m ()) -> m ()
forRG r l f p g d = flip VFSM.mapM_ (streamRG r l f p g d)
{-# INLINE forRG #-}

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

streamR :: Monad m => Int -> Int -> VFSM.Stream m Int
streamR !l !r = VFSM.Stream step (r - 1)
  where
    step x
      | x >= l = return $ VFSM.Yield x (x - 1)
      | otherwise = return VFSM.Done
    {-# INLINE [0] step #-}
{-# INLINE [1] streamR #-}

streamStep :: Monad m => Int -> Int -> Int -> VFSM.Stream m Int
streamStep !l !r !d = VFSM.Stream step l
  where
    step x
      | x <= r    = return $ VFSM.Yield x (x + d)
      | otherwise = return VFSM.Done
    {-# INLINE [0] step #-}
{-# INLINE [1] streamStep #-}

streamStepR :: Monad m => Int -> Int -> Int -> VFSM.Stream m Int
streamStepR !l !r !d = VFSM.Stream step r
  where
    step x
      | x >= l    = return $ VFSM.Yield x (x - d)
      | otherwise = return VFSM.Done
    {-# INLINE [0] step #-}
{-# INLINE [1] streamStepR #-}

streamG :: Monad m => Int -> Int -> (Int -> Int -> Int) -> Int -> (Int -> Int -> Int) -> Int -> VFSM.Stream m Int
streamG !l !r !f !p !g !d = VFSM.Stream step l
  where
    step x
      | f x p <= r = return $ VFSM.Yield x (g x d)
      | otherwise  = return VFSM.Done
    {-# INLINE [0] step #-}
{-# INLINE [1] streamG #-}

streamRG :: Monad m => Int -> Int -> (Int -> Int -> Int) -> Int -> (Int -> Int -> Int) -> Int -> VFSM.Stream m Int
streamRG !r !l !f !p !g !d = VFSM.Stream step r
  where
    step x
      | f x p >= l = return $ VFSM.Yield x (g x d)
      | otherwise  = return VFSM.Done
    {-# INLINE [0] step #-}
{-# INLINE [1] streamRG #-}

withBreakIO :: ((r -> ContT r IO b) -> ContT r IO r) -> IO r
withBreakIO = flip runContT pure . callCC
{-# INLINE withBreakIO #-}

withBreakST :: ((r -> ContT r (ST s) b) -> ContT r (ST s) r) -> (ST s) r
withBreakST = flip runContT pure . callCC
{-# INLINE withBreakST #-}
0