結果
| 問題 |
No.45 回転寿司
|
| ユーザー |
|
| 提出日時 | 2021-08-20 15:19:43 |
| 言語 | Haskell (9.10.1) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 5,000 ms |
| コード長 | 1,095 bytes |
| コンパイル時間 | 13,990 ms |
| コンパイル使用メモリ | 210,048 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-10-13 18:22:15 |
| 合計ジャッジ時間 | 15,041 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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 -> IO (VU.Vector Int)
createDP n xs = do
return $ VU.constructN n $ \dp -> do
let i = VU.length dp
case i 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
dp <- createDP n xs
print $ dp 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 #-}