結果

問題 No.672 最長AB列
ユーザー tamatotamato
提出日時 2020-03-04 20:56:25
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 69 ms / 2,000 ms
コード長 399 bytes
コンパイル時間 189 ms
コンパイル使用メモリ 82,352 KB
実行使用メモリ 100,864 KB
最終ジャッジ日時 2024-04-22 01:50:55
合計ジャッジ時間 1,639 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
51,840 KB
testcase_01 AC 35 ms
51,968 KB
testcase_02 AC 33 ms
51,968 KB
testcase_03 AC 34 ms
52,480 KB
testcase_04 AC 31 ms
51,584 KB
testcase_05 AC 31 ms
51,840 KB
testcase_06 AC 32 ms
51,712 KB
testcase_07 AC 31 ms
52,352 KB
testcase_08 AC 31 ms
52,352 KB
testcase_09 AC 69 ms
100,864 KB
testcase_10 AC 57 ms
86,528 KB
testcase_11 AC 65 ms
87,808 KB
testcase_12 AC 48 ms
69,504 KB
testcase_13 AC 46 ms
67,840 KB
testcase_14 AC 47 ms
68,992 KB
testcase_15 AC 50 ms
69,376 KB
testcase_16 AC 47 ms
68,864 KB
testcase_17 AC 59 ms
88,448 KB
testcase_18 AC 43 ms
67,584 KB
権限があれば一括ダウンロードができます

ソースコード

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