結果

問題 No.672 最長AB列
コンテスト
ユーザー ducktail
提出日時 2018-08-27 14:46:12
言語 Haskell
(9.14.1)
コンパイル:
ghc -rtsopts -with-rtsopts=-K1G -o a.out -O2 _filename_
実行:
./a.out
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 461 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,479 ms
コンパイル使用メモリ 164,736 KB
最終ジャッジ日時 2026-03-21 22:03:06
合計ジャッジ時間 4,903 ms
ジャッジサーバーID
(参考情報)
judge3_1 / judge1_1
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
Loaded package environment from /home/judge/.ghc/x86_64-linux-9.14.1/environments/default
[1 of 2] Compiling Main             ( Main.hs, Main.o )
Main.hs:3:1: error: [GHC-87110]
    Could not load module ‘Data.IntMap’.
    It is a member of the hidden package ‘containers-0.8’.
    Use -v to see a list of the files searched for.
  |
3 | import Data.IntMap (IntMap, (!))
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Main.hs:4:1: error: [GHC-87110]
    Could not load module ‘Data.IntMap’.
    It is a member of the hidden package ‘containers-0.8’.
    Use -v to see a list of the files searched for.
  |
4 | import qualified Data.IntMap as IM
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

ソースコード

diff #
raw source code

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