結果
問題 |
No.45 回転寿司
|
ユーザー |
|
提出日時 | 2018-06-12 21:20:19 |
言語 | Haskell (9.10.1) |
結果 |
AC
|
実行時間 | 11 ms / 5,000 ms |
コード長 | 669 bytes |
コンパイル時間 | 10,799 ms |
コンパイル使用メモリ | 180,784 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-12-27 19:03:17 |
合計ジャッジ時間 | 12,911 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.Applicative ((<$>), (<*>)) import Data.ByteString.Char8 (ByteString) import qualified Data.ByteString.Char8 as B import Data.List (unfoldr) import Data.Char (isSpace) main :: IO () main = solve <$> readLn <*> (readil B.readInt <$> B.getLine) >>= print solve :: Int -> [Int] -> Int solve n (v:vs) = dp !! n where dp = 0 : v : unfoldr f (0, vs) where f (_, []) = Nothing f (i, (x:xs)) = Just (max (dp !! (i+1)) (x + dp !! i), (i+1, xs)) readil :: Integral a => (ByteString -> Maybe (a, ByteString)) -> ByteString -> [a] readil f = unfoldr g where g s = do (n, s') <- f s return (n, B.dropWhile isSpace s')