結果

問題 No.45 回転寿司
ユーザー NaruY
提出日時 2016-10-24 11:37:24
言語 Haskell
(9.10.1)
結果
AC  
実行時間 9 ms / 5,000 ms
コード長 496 bytes
コンパイル時間 10,911 ms
コンパイル使用メモリ 175,696 KB
実行使用メモリ 8,064 KB
最終ジャッジ日時 2024-12-27 15:28:36
合計ジャッジ時間 11,104 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
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

ソースコード

diff #

import Control.Monad
import Control.Applicative
import Data.List
import Data.Array

main = do
    n <- readLn
    vs <- (map read .words) <$> getLine
    
    print (solve n vs)

maxs x y = if x >= y then x
                    else y

solve n vs
  | n == 1 = vs !! 0
  | n == 2 = maxs (vs !! 0) (vs !! 1)
  | otherwise = a!n
                where a = array (1,n) (  (1,(vs !! 0)) : (2,maxs (vs !! 0) (vs !! 1)) : [(i,maxs (a!(i-1)) ((vs !! (i-1)) + a!(i-2)) ) | i <- [3,4..n]]  )
                
0