結果

問題 No.127 門松もどき
ユーザー tottoripapertottoripaper
提出日時 2015-05-09 22:27:35
言語 Haskell
(9.8.2)
結果
RE  
実行時間 -
コード長 1,486 bytes
コンパイル時間 8,015 ms
コンパイル使用メモリ 201,796 KB
実行使用メモリ 291,260 KB
最終ジャッジ日時 2023-09-19 09:35:12
合計ジャッジ時間 22,394 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
147,064 KB
testcase_01 AC 42 ms
147,092 KB
testcase_02 AC 42 ms
147,240 KB
testcase_03 AC 42 ms
147,060 KB
testcase_04 AC 995 ms
263,352 KB
testcase_05 RE -
testcase_06 AC 123 ms
163,012 KB
testcase_07 AC 52 ms
147,792 KB
testcase_08 AC 42 ms
147,376 KB
testcase_09 AC 42 ms
146,836 KB
testcase_10 AC 42 ms
146,892 KB
testcase_11 AC 53 ms
148,152 KB
testcase_12 AC 565 ms
223,908 KB
testcase_13 AC 735 ms
247,452 KB
testcase_14 AC 674 ms
237,700 KB
testcase_15 AC 935 ms
272,588 KB
testcase_16 AC 645 ms
237,624 KB
testcase_17 AC 743 ms
255,100 KB
testcase_18 AC 624 ms
238,504 KB
testcase_19 AC 404 ms
205,696 KB
testcase_20 AC 414 ms
208,188 KB
testcase_21 AC 212 ms
177,348 KB
testcase_22 AC 1,013 ms
279,280 KB
testcase_23 AC 1,013 ms
291,260 KB
testcase_24 AC 762 ms
237,644 KB
testcase_25 AC 933 ms
253,080 KB
testcase_26 AC 465 ms
205,140 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Loaded package environment from /home/judge/.ghc/x86_64-linux-9.6.1/environments/default
[1 of 2] Compiling Main             ( Main.hs, Main.o )
[2 of 2] Linking a.out

ソースコード

diff #

-- [元のコード] http://yukicoder.me/submissions/15723

import Control.Monad
import qualified Data.Vector as V
import qualified Data.Vector.Unboxed.Mutable as MV
import qualified Data.ByteString.Char8 as B
import Data.Maybe (fromJust)
import Debug.Trace
    
readInts :: B.ByteString -> [Int]
readInts = map (fst . fromJust . B.readInt) . B.words

getInts :: IO [Int]
getInts = liftM readInts B.getLine

main = do
  n <- readLn
  as <- liftM V.fromList getInts
  dp <- MV.replicate (2*3000*3000) (-1 :: Int)
  let
      at l r p =  l + 3000 * (r + 3000 * p)
      f :: Int -> Int -> Int -> IO Int
      f l r p
        | l == r = return 0
        | otherwise = do
            v <- MV.read dp (at l r p)
            if v /= (-1)
            then return v
            else g l r p
      g :: Int -> Int -> Int -> IO Int
      g l r p
        | p == 0 = do
            v <- f l (r-1) p
            v' <- if as V.! l < as V.! r then liftM (+1) (f (l+1) r (1-p)) else return 0
            let res = max v v'
            MV.write dp (at l r p) res
            return res
        | otherwise = do
            v <- f (l+1) r p
            v' <- if as V.! r < as V.! l then liftM (+1) (f l (r-1) (1-p)) else return 0
            let res = max v v'
            MV.write dp (at l r p) res
            return res
      xs = liftM concat $ forM [0..n-1] $ \i ->
               forM [i+1..n-1] $ \j ->
                   liftM2 (((+1).) . max) (f i j 0) (f i j 1)
   in print =<< liftM maximum xs
0