結果

問題 No.291 黒い文字列
ユーザー h_noson
提出日時 2015-10-16 23:54:21
言語 Haskell
(9.10.1)
結果
TLE  
実行時間 -
コード長 691 bytes
コンパイル時間 7,200 ms
コンパイル使用メモリ 172,928 KB
実行使用メモリ 13,888 KB
最終ジャッジ日時 2024-07-22 06:40:52
合計ジャッジ時間 10,960 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 7 TLE * 1 -- * 18
権限があれば一括ダウンロードができます
コンパイルメッセージ
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.Applicative
import Data.Maybe
import Data.List
import Data.Array

solve :: Array Int Int -> [Int] -> [Int]
solve arr [] = return $ arr ! 4
solve arr (x:xs) = do
    i <- if x == 5
        then 0 : filter (\i -> arr!(i-1) > 0) [1..4]
        else [x]
    if i == 0
        then return . maximum $ solve (arr // [(0,arr!0+1)]) xs
        else if arr!(i-1) > 0
            then return . maximum $ solve (arr // [(i-1,arr!(i-1)-1),(i,arr!i+1)]) xs
            else return . maximum $ solve arr xs

main :: IO ()
main = do
    s <- map (\x -> fromMaybe 6 $ findIndex (== x) "KUROI?") . filter (`elem` "KUROI?") <$> getLine
    print . maximum $ solve (listArray (0,4) $ repeat 0) s
0