結果

問題 No.672 最長AB列
ユーザー ducktailducktail
提出日時 2018-08-27 14:26:18
言語 Haskell
(9.8.2)
結果
WA  
実行時間 -
コード長 494 bytes
コンパイル時間 4,585 ms
コンパイル使用メモリ 160,996 KB
実行使用メモリ 31,852 KB
最終ジャッジ日時 2023-09-13 19:32:25
合計ジャッジ時間 4,900 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
7,040 KB
testcase_01 AC 2 ms
7,100 KB
testcase_02 AC 3 ms
6,988 KB
testcase_03 AC 2 ms
7,064 KB
testcase_04 AC 2 ms
7,028 KB
testcase_05 AC 3 ms
7,108 KB
testcase_06 AC 2 ms
7,096 KB
testcase_07 AC 2 ms
7,024 KB
testcase_08 AC 2 ms
7,032 KB
testcase_09 WA -
testcase_10 AC 52 ms
20,588 KB
testcase_11 AC 52 ms
19,520 KB
testcase_12 AC 22 ms
11,336 KB
testcase_13 AC 22 ms
11,372 KB
testcase_14 AC 22 ms
11,380 KB
testcase_15 AC 22 ms
11,416 KB
testcase_16 AC 22 ms
11,412 KB
testcase_17 AC 43 ms
19,712 KB
testcase_18 AC 12 ms
11,312 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 <$> getContents >>= 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 if c == 'B' then d-1 else 200000
0