結果

問題 No.672 最長AB列
ユーザー tails1434
提出日時 2020-01-22 22:10:29
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 480 bytes
コンパイル時間 320 ms
コンパイル使用メモリ 82,236 KB
実行使用メモリ 114,556 KB
最終ジャッジ日時 2024-07-16 03:10:03
合計ジャッジ時間 2,193 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 5 WA * 11
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict

def main():
    S = input()
    cnt = 0
    diff = [(0,0)]
    for i, s in enumerate(S):
        if s == 'A':
            cnt += 1
        else:
            cnt -= 1

        diff.append((cnt,i+1))

    d = defaultdict(int)
    ans = 0

    for cnt, i in diff:
        if d[cnt]:
            ans = max(ans, i - d[cnt])
            d[cnt] = i
        else:
            d[cnt] = i

    print(ans)
    






if __name__ == "__main__":
    main()
0