結果

問題 No.672 最長AB列
ユーザー 👑 SPD_9X2
提出日時 2025-08-01 03:48:47
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 70 ms / 2,000 ms
コード長 225 bytes
コンパイル時間 277 ms
コンパイル使用メモリ 82,348 KB
実行使用メモリ 95,772 KB
最終ジャッジ日時 2025-08-01 03:48:50
合計ジャッジ時間 2,591 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 16
権限があれば一括ダウンロードができます

ソースコード

diff #

S = input()

s = 0
dic = {}
dic[0] = -1
ans = 0

for i,c in enumerate(S):
    if c == "A":
        s += 1
    else:
        s -= 1

    if s in dic:
        ans = max(ans, i-dic[s])
    else:
        dic[s] = i

print (ans)
0