結果

問題 No.672 最長AB列
ユーザー 👑 horiesinitihoriesiniti
提出日時 2018-05-12 17:05:03
言語 Haskell
(9.8.2)
結果
AC  
実行時間 444 ms / 2,000 ms
コード長 708 bytes
コンパイル時間 1,237 ms
コンパイル使用メモリ 165,140 KB
実行使用メモリ 89,896 KB
最終ジャッジ日時 2023-09-10 18:25:27
合計ジャッジ時間 5,439 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,904 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,904 KB
testcase_03 AC 2 ms
6,836 KB
testcase_04 AC 3 ms
6,972 KB
testcase_05 AC 2 ms
6,900 KB
testcase_06 AC 2 ms
6,896 KB
testcase_07 AC 2 ms
6,904 KB
testcase_08 AC 2 ms
6,876 KB
testcase_09 AC 444 ms
89,896 KB
testcase_10 AC 354 ms
66,676 KB
testcase_11 AC 332 ms
61,508 KB
testcase_12 AC 143 ms
42,996 KB
testcase_13 AC 152 ms
48,200 KB
testcase_14 AC 132 ms
35,316 KB
testcase_15 AC 162 ms
46,060 KB
testcase_16 AC 153 ms
48,264 KB
testcase_17 AC 312 ms
59,968 KB
testcase_18 AC 82 ms
34,196 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 #

import qualified Data.Map as M
import qualified Control.Applicative as CA

f :: (Int,Int) -> Char -> (Int,Int)
f (a,p) c
   |c=='A' =(a+1,p+1)
   |otherwise=(a-1,p+1)

toM1 :: (Ord k)=>[(k,Int)]->M.Map k Int
toM1 xs = M.fromListWith up xs
         where up n1 n2=n1

toM2 :: (Ord k)=>[(k,Int)]->M.Map k Int
toM2 xs = M.fromListWith up xs
         where up n1 n2=n2

f2 (Just x)=x
f2 Nothing =0 

main=do
      x<-getLine
      let ys=scanl f (0,0) x
          as=toM1 ys
          bs=toM2 ys
          cs=M.keys as
          ds=map (\x -> (M.lookup x as)) cs
          es=map (\x -> (M.lookup x bs)) cs
          fs=zip ds es
          ans=maximum $ fmap (\(a,b)->CA.liftA2 (-) a b) fs
      print $ f2 $ ans
0