結果
問題 |
No.45 回転寿司
|
ユーザー |
|
提出日時 | 2021-08-20 15:22:08 |
言語 | Haskell (9.10.1) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 1,030 bytes |
コンパイル時間 | 8,041 ms |
コンパイル使用メモリ | 210,560 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-10-13 18:24:54 |
合計ジャッジ時間 | 9,168 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 30 |
コンパイルメッセージ
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
ソースコード
import Control.Monad.State import Data.Char import Data.Coerce import qualified Data.ByteString.Char8 as BSC8 import qualified Data.Vector.Unboxed as VU import qualified Data.Vector.Unboxed.Mutable as VUM createDP :: Int -> VU.Vector Int -> VU.Vector Int createDP n xs = VU.constructN n $ \dp -> case VU.length dp of 0 -> xs VU.! 0 1 -> max (xs VU.! 0) (xs VU.! 1) q -> max (dp VU.! (q - 1)) (xs VU.! q + (dp VU.! (q - 2))) main :: IO () main = do n <- readLn :: IO Int if n == 1 then (readLn :: IO Int) >>= print else do xs <- seqInput n print $ (createDP n xs) VU.! (n - 1) type Parser a = StateT BSC8.ByteString Maybe a runParser :: Parser a -> BSC8.ByteString -> Maybe (a, BSC8.ByteString) runParser = runStateT {-# INLINE runParser #-} int :: Parser Int int = coerce $ BSC8.readInt . BSC8.dropWhile isSpace {-# INLINE int #-} seqInput :: Int -> IO (VU.Vector Int) seqInput n = VU.unfoldrN n (runParser int) <$> BSC8.getLine {-# INLINE seqInput #-}