結果

問題 No.672 最長AB列
ユーザー ああいい
提出日時 2022-03-30 21:53:25
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 81 ms / 2,000 ms
コード長 301 bytes
コンパイル時間 909 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 97,356 KB
最終ジャッジ日時 2024-11-15 13:09:52
合計ジャッジ時間 2,379 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 16
権限があれば一括ダウンロードができます

ソースコード

diff #

S = input()

from collections import defaultdict
d = defaultdict(int)

now = 0
ans = 0
d[now] = -1
for i in range(len(S)):
    if S[i] == "A":
        now += 1
    else:
        now -= 1
    if now in d:
        if i - d[now] > ans:
            ans = i - d[now]
    else:
        d[now] = i
print(ans)
0