結果

問題 No.672 最長AB列
ユーザー yakeshiba
提出日時 2021-03-13 05:22:14
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 504 bytes
コンパイル時間 184 ms
コンパイル使用メモリ 82,264 KB
実行使用メモリ 134,656 KB
最終ジャッジ日時 2024-10-14 17:59:02
合計ジャッジ時間 2,344 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 10 WA * 6
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict

S = input()

memo = [0]*(len(S))
n = 0
for i,s in enumerate(S):
    if s == "A":
        n += 1
    else:
        n -= 1
    memo[i] = n
    
#print(S)
#print(memo)
memo = [0]+memo
    
first = defaultdict(lambda:-1)
last = defaultdict(lambda:-1)

for i,m in enumerate(memo):
    if first[m] != -1:
        last[m] = i
    else:
        first[m] = i
        
ans = 0
for k,v in first.items():
    if last[k] != -1:
        ans = max(ans, last[m]-first[m])

print(ans)
0