結果
| 問題 | No.672 最長AB列 | 
| コンテスト | |
| ユーザー |  lllllll88938494 | 
| 提出日時 | 2023-04-15 09:47:26 | 
| 言語 | PyPy3 (7.3.15) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 121 ms / 2,000 ms | 
| コード長 | 285 bytes | 
| コンパイル時間 | 639 ms | 
| コンパイル使用メモリ | 82,176 KB | 
| 実行使用メモリ | 107,520 KB | 
| 最終ジャッジ日時 | 2024-10-10 22:21:03 | 
| 合計ジャッジ時間 | 2,313 ms | 
| ジャッジサーバーID (参考情報) | judge3 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 16 | 
ソースコード
from collections import defaultdict
s = input()
cnt = defaultdict(list)
cnt[0].append(0)
ans = 0
t = 0
for i in range(len(s)):
    if s[i] == 'A':
        t += 1
    else:
        t -= 1
    if len(cnt[t]) > 0:
        ans = max((i+1)-cnt[t][0],ans)
    cnt[t].append(i+1)
print(ans)
            
            
            
        