結果

問題 No.672 最長AB列
ユーザー ducktailducktail
提出日時 2018-08-27 14:46:12
言語 Haskell
(9.8.2)
結果
AC  
実行時間 93 ms / 2,000 ms
コード長 461 bytes
コンパイル時間 660 ms
コンパイル使用メモリ 162,808 KB
実行使用メモリ 30,756 KB
最終ジャッジ日時 2023-09-13 19:33:24
合計ジャッジ時間 2,466 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
7,016 KB
testcase_01 AC 2 ms
6,972 KB
testcase_02 AC 3 ms
7,048 KB
testcase_03 AC 3 ms
6,976 KB
testcase_04 AC 3 ms
6,952 KB
testcase_05 AC 2 ms
6,928 KB
testcase_06 AC 3 ms
6,960 KB
testcase_07 AC 3 ms
7,028 KB
testcase_08 AC 3 ms
7,028 KB
testcase_09 AC 93 ms
30,756 KB
testcase_10 AC 92 ms
30,692 KB
testcase_11 AC 82 ms
28,836 KB
testcase_12 AC 53 ms
18,548 KB
testcase_13 AC 53 ms
18,416 KB
testcase_14 AC 52 ms
18,520 KB
testcase_15 AC 52 ms
18,520 KB
testcase_16 AC 52 ms
18,484 KB
testcase_17 AC 72 ms
27,772 KB
testcase_18 AC 33 ms
18,536 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 Control.Applicative
import Data.List
import Data.IntMap (IntMap, (!))
import qualified Data.IntMap as IM

main :: IO ()
main = solve <$> getLine >>= print

solve :: String -> Int
solve = (\(_, _, x, _) -> x) . foldl' f (1, IM.insert 0 0 IM.empty, 0, 0)
  where
    f (i, mp, mx, d) c
      | IM.member nd mp = (i+1, mp, max mx (i - mp ! nd), nd)
      | otherwise = (i+1, IM.insert nd i mp, mx, nd)
      where
        nd = if c == 'A' then d+1 else d-1
0