結果

問題 No.672 最長AB列
ユーザー tamato
提出日時 2020-03-04 20:54:53
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 394 bytes
コンパイル時間 701 ms
コンパイル使用メモリ 82,444 KB
実行使用メモリ 101,292 KB
最終ジャッジ日時 2024-10-14 00:28:47
合計ジャッジ時間 2,660 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 10 WA * 6
権限があれば一括ダウンロードができます

ソースコード

diff #

def main():
    import sys
    input = sys.stdin.readline

    S = input().rstrip('\n')
    dic = {}
    tmp = 0
    ans = 0
    for i, s in enumerate(S):
        if s == 'A':
            tmp += 1
        else:
            tmp -= 1
        if tmp not in dic:
            dic[tmp] = i
        else:
            ans = max(ans, i - dic[tmp])
    print(ans)


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