結果

問題 No.672 最長AB列
ユーザー tamato
提出日時 2020-03-04 20:56:25
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 81 ms / 2,000 ms
コード長 399 bytes
コンパイル時間 238 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 100,864 KB
最終ジャッジ日時 2024-10-14 00:28:49
合計ジャッジ時間 1,985 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 16
権限があれば一括ダウンロードができます

ソースコード

diff #

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

    S = input().rstrip('\n')
    dic = {0: -1}
    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