結果

問題 No.672 最長AB列
ユーザー tak
提出日時 2018-06-08 07:41:33
言語 F#
(F# 4.0)
結果
AC  
実行時間 385 ms / 2,000 ms
コード長 520 bytes
コンパイル時間 6,781 ms
コンパイル使用メモリ 184,720 KB
実行使用メモリ 64,500 KB
最終ジャッジ日時 2024-06-30 10:37:51
合計ジャッジ時間 14,617 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 16
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.fsproj を復元しました (243 ms)。
MSBuild のバージョン 17.9.6+a4ecab324 (.NET)
  main -> /home/judge/data/code/bin/Release/net8.0/main.dll
  main -> /home/judge/data/code/bin/Release/net8.0/publish/

ソースコード

diff #

let S = stdin.ReadLine().ToCharArray()

let ans = 
    let mem = System.Collections.Generic.Dictionary<int,int>()
    mem.Add(0,-1)
    S 
    |> Array.indexed
    |> Array.fold(fun (counter,maxLen) (idx,c) ->
        let counter = match c with |'A' -> counter + 1 | _  -> counter - 1
        match mem.TryGetValue counter with
        | true, lIdx -> (counter, max maxLen (idx - lIdx))
        | _          -> mem.Add(counter,idx); (counter, maxLen)) (0,0)
    |> fun (counter,maxLen) -> maxLen
    
ans |> printfn "%i"
0