結果

問題 No.672 最長AB列
ユーザー ntuda
提出日時 2024-01-22 21:21:25
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 104 ms / 2,000 ms
コード長 314 bytes
コンパイル時間 142 ms
コンパイル使用メモリ 82,500 KB
実行使用メモリ 107,648 KB
最終ジャッジ日時 2024-09-28 06:29:50
合計ジャッジ時間 2,275 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 16
権限があれば一括ダウンロードができます

ソースコード

diff #

S = input()
tmp = 0
from collections import defaultdict
dic = defaultdict(list)
dic[0].append(0)
for i, s in enumerate(S, start=1):
    if s == "A":
        tmp += 1
    else:
        tmp -= 1
    dic[tmp].append(i)
ans = 0
for k,V in dic.items():
    if len(V) >= 2:
        ans = max(ans,V[-1] - V[0])
print(ans)
0