結果
| 問題 | No.672 最長AB列 | 
| コンテスト | |
| ユーザー |  lam6er | 
| 提出日時 | 2025-03-20 21:11:06 | 
| 言語 | PyPy3 (7.3.15) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 77 ms / 2,000 ms | 
| コード長 | 339 bytes | 
| コンパイル時間 | 205 ms | 
| コンパイル使用メモリ | 82,312 KB | 
| 実行使用メモリ | 95,256 KB | 
| 最終ジャッジ日時 | 2025-03-20 21:11:21 | 
| 合計ジャッジ時間 | 2,051 ms | 
| ジャッジサーバーID (参考情報) | judge1 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 16 | 
ソースコード
S = input().strip()
sum_map = {0: -1}
current_sum = 0
max_len = 0
for i, c in enumerate(S):
    current_sum += 1 if c == 'A' else -1
    if current_sum in sum_map:
        current_len = i - sum_map[current_sum]
        if current_len > max_len:
            max_len = current_len
    else:
        sum_map[current_sum] = i
print(max_len)
            
            
            
        