結果

問題 No.672 最長AB列
ユーザー tails1434tails1434
提出日時 2020-01-23 07:19:44
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 139 ms / 2,000 ms
コード長 397 bytes
コンパイル時間 1,712 ms
コンパイル使用メモリ 86,848 KB
実行使用メモリ 108,256 KB
最終ジャッジ日時 2023-09-25 13:28:13
合計ジャッジ時間 5,339 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 96 ms
71,596 KB
testcase_01 AC 93 ms
71,640 KB
testcase_02 AC 96 ms
71,708 KB
testcase_03 AC 96 ms
71,796 KB
testcase_04 AC 93 ms
71,540 KB
testcase_05 AC 95 ms
71,508 KB
testcase_06 AC 93 ms
71,592 KB
testcase_07 AC 93 ms
71,564 KB
testcase_08 AC 92 ms
71,504 KB
testcase_09 AC 139 ms
108,256 KB
testcase_10 AC 122 ms
91,560 KB
testcase_11 AC 128 ms
91,592 KB
testcase_12 AC 115 ms
77,392 KB
testcase_13 AC 112 ms
76,948 KB
testcase_14 AC 115 ms
77,132 KB
testcase_15 AC 115 ms
76,936 KB
testcase_16 AC 115 ms
77,148 KB
testcase_17 AC 124 ms
91,444 KB
testcase_18 AC 107 ms
76,860 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict

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

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

    print(ans)
    






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