結果

問題 No.672 最長AB列
ユーザー lloyzlloyz
提出日時 2022-07-16 22:25:16
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 367 ms / 2,000 ms
コード長 296 bytes
コンパイル時間 132 ms
コンパイル使用メモリ 10,712 KB
実行使用メモリ 52,508 KB
最終ジャッジ日時 2023-09-11 08:18:52
合計ジャッジ時間 2,970 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 20 ms
8,324 KB
testcase_01 AC 20 ms
8,352 KB
testcase_02 AC 20 ms
8,416 KB
testcase_03 AC 18 ms
8,356 KB
testcase_04 AC 18 ms
8,328 KB
testcase_05 AC 18 ms
8,352 KB
testcase_06 AC 19 ms
8,384 KB
testcase_07 AC 19 ms
8,316 KB
testcase_08 AC 18 ms
8,344 KB
testcase_09 AC 367 ms
52,508 KB
testcase_10 AC 231 ms
33,736 KB
testcase_11 AC 234 ms
33,804 KB
testcase_12 AC 108 ms
17,868 KB
testcase_13 AC 109 ms
18,168 KB
testcase_14 AC 102 ms
18,072 KB
testcase_15 AC 104 ms
18,132 KB
testcase_16 AC 106 ms
17,928 KB
testcase_17 AC 247 ms
33,912 KB
testcase_18 AC 94 ms
17,580 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