結果

問題 No.672 最長AB列
ユーザー norioc
提出日時 2024-10-16 22:48:15
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 88 ms / 2,000 ms
コード長 200 bytes
コンパイル時間 276 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 94,208 KB
最終ジャッジ日時 2024-10-16 22:48:17
合計ジャッジ時間 2,614 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 16
権限があれば一括ダウンロードができます

ソースコード

diff #

S = input()
d = {0: -1}
h = 0
ans = 0
for i, c in enumerate(S):
    if c == 'A': h += 1
    if c == 'B': h -= 1

    if h in d:
        ans = max(ans, i - d[h])
    else:
        d[h] = i

print(ans)
0