結果

問題 No.777 再帰的ケーキ
ユーザー 👑 horiesinitihoriesiniti
提出日時 2019-01-02 07:38:33
言語 Haskell
(9.8.2)
結果
TLE  
実行時間 -
コード長 1,771 bytes
コンパイル時間 7,054 ms
コンパイル使用メモリ 162,776 KB
実行使用メモリ 13,472 KB
最終ジャッジ日時 2023-08-10 22:47:53
合計ジャッジ時間 13,604 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
7,788 KB
testcase_01 AC 3 ms
7,804 KB
testcase_02 AC 2 ms
7,796 KB
testcase_03 AC 3 ms
7,804 KB
testcase_04 AC 3 ms
7,716 KB
testcase_05 AC 2 ms
7,748 KB
testcase_06 AC 3 ms
7,896 KB
testcase_07 AC 2 ms
8,008 KB
testcase_08 AC 2 ms
7,668 KB
testcase_09 AC 3 ms
7,800 KB
testcase_10 AC 2 ms
7,860 KB
testcase_11 AC 2 ms
7,852 KB
testcase_12 AC 2 ms
7,804 KB
testcase_13 AC 3 ms
7,800 KB
testcase_14 AC 2 ms
7,824 KB
testcase_15 AC 3 ms
7,712 KB
testcase_16 AC 3 ms
7,844 KB
testcase_17 AC 3 ms
7,792 KB
testcase_18 AC 2 ms
7,868 KB
testcase_19 AC 3 ms
7,848 KB
testcase_20 AC 2 ms
7,800 KB
testcase_21 AC 122 ms
13,472 KB
testcase_22 AC 122 ms
13,296 KB
testcase_23 AC 4 ms
9,556 KB
testcase_24 AC 3 ms
9,324 KB
testcase_25 AC 122 ms
13,360 KB
testcase_26 AC 132 ms
13,420 KB
testcase_27 AC 6 ms
11,564 KB
testcase_28 TLE -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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 #

{-# LANGUAGE ViewPatterns #-}
import qualified Data.Sequence as Sq
import Data.Sequence (ViewL(..),ViewR(..),(><),(<|),(|>),Seq)
import Data.List
import qualified Data.ByteString.Char8 as BC
import Data.Maybe (fromJust)

f::[BC.ByteString]->[(Int,Int,Int)]
f []=[]
f (s:ss)=let (x:y:c:[]) = map (fst . fromJust . BC.readInt) $ BC.words s
         in (x,y,c):f ss

left :: Seq a -> a
left (Sq.viewl -> (l :< _)) = l

left2 :: Seq a -> Seq a
left2 (Sq.viewl -> (_ :< ls)) = ls

f3::Sq.Seq (Int,Int)->Sq.Seq (Int,Int)->Sq.Seq (Int,Int)
f3 old now
   |Sq.null old=now
   |otherwise=let a=left old
                  old2=left2 old
              in f3 old2 (now |> a)

f2::Int->Int->Int->Int->[(Int,Int,Int)]->Sq.Seq (Int,Int)->Sq.Seq (Int,Int)->Int
f2 _ ans _ _ [] _ _=ans
f2 x ans nowC nowC2 xs3@((x2,y2,c2):xs2) old now
         |x<x2=f2 x2 ans 0 0 xs3 (f3 old now) (Sq.empty :: Sq.Seq (Int,Int))
         |Sq.null old=let c4=max (nowC+c2) nowC2
                      in f2 x (max ans c4) nowC c4 xs2 old (now |> (y2,c4))
         |otherwise=let (y3,c3)=left old
                        old2=left2 old
                        c5=(max nowC c3)
                        c6=(max nowC2 (c5+c2))
                    in if y2 > y3 then f2 x (max ans c6) c5 c6 xs3 old2 (now |> (y3,c5))
                                  else f2 x (max ans c5) nowC nowC2 xs2 old (now |> (y2,(max (nowC+c2) nowC2)))

f4::(Int,Int,Int)->Int
f4 (a,_,_)=a

f5::[(Int,Int,Int)]->[(Int,Int,Int)]
f5  (x:[])=[x]
f5 ((x,y,c):(x1,y1,c1):xs)
   |x==x1&& y==y1=f5 ((x1,y1,c1):xs)
   |otherwise=(x,y,c):f5 ((x1,y1,c1):xs)


main = do
       e<-getLine
       t<-BC.lines <$> BC.getContents
       let q=(Sq.fromList [(0::Int,0::Int)])
           xs=f5 $ sort $ f t
       print $ f2 (f4 (head xs)) 0 0 0 xs q q
0