結果

問題 No.672 最長AB列
ユーザー yomo3
提出日時 2020-03-20 17:45:41
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 131 ms / 2,000 ms
コード長 444 bytes
コンパイル時間 360 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 43,272 KB
最終ジャッジ日時 2024-12-14 12:09:58
合計ジャッジ時間 2,447 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 16
権限があれば一括ダウンロードができます

ソースコード

diff #

from itertools import accumulate

def main():
    S = [0] + list(input())

    d = list(accumulate(S, lambda s, c: s + 1 if c == 'A' else s-1))

    l, r = {}, {}

    for i in range(len(d)):
        if d[i] in l:
            r[d[i]] = i
        else:
            l[d[i]] = i

    ans = 0
    for rk, rv in r.items():
        if rk in l:
            span = rv - l[rk]
            if span > ans:
                ans = span
    print(ans)

main()
0