結果

問題 No.672 最長AB列
ユーザー lloyzlloyz
提出日時 2022-07-16 22:25:01
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 205 ms / 2,000 ms
コード長 296 bytes
コンパイル時間 1,044 ms
コンパイル使用メモリ 87,260 KB
実行使用メモリ 124,752 KB
最終ジャッジ日時 2023-09-11 08:18:38
合計ジャッジ時間 5,752 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 94 ms
71,644 KB
testcase_01 AC 96 ms
71,596 KB
testcase_02 AC 95 ms
71,220 KB
testcase_03 AC 95 ms
71,360 KB
testcase_04 AC 94 ms
71,636 KB
testcase_05 AC 95 ms
71,500 KB
testcase_06 AC 95 ms
71,632 KB
testcase_07 AC 94 ms
71,684 KB
testcase_08 AC 95 ms
71,356 KB
testcase_09 AC 205 ms
124,752 KB
testcase_10 AC 166 ms
111,568 KB
testcase_11 AC 173 ms
111,412 KB
testcase_12 AC 132 ms
89,012 KB
testcase_13 AC 122 ms
80,868 KB
testcase_14 AC 130 ms
88,968 KB
testcase_15 AC 131 ms
88,816 KB
testcase_16 AC 121 ms
81,184 KB
testcase_17 AC 170 ms
111,676 KB
testcase_18 AC 123 ms
93,032 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict

S = list(input())

n = len(S)
C = defaultdict(list)
cnt = 0
C[0].append(0)
for i in range(n):
    if S[i] == 'A':
        cnt += 1
    else:
        cnt -= 1
    C[cnt].append(i + 1)
ans = 0
for L in C.values():
    ans = max(ans, max(L) - min(L))
print(ans)
0