結果

問題 No.672 最長AB列
ユーザー mijimemijime
提出日時 2018-04-15 23:02:37
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 159 ms / 2,000 ms
コード長 266 bytes
コンパイル時間 135 ms
コンパイル使用メモリ 10,604 KB
実行使用メモリ 34,768 KB
最終ジャッジ日時 2023-09-10 04:30:06
合計ジャッジ時間 2,798 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
8,320 KB
testcase_01 AC 19 ms
8,524 KB
testcase_02 AC 19 ms
8,376 KB
testcase_03 AC 19 ms
8,428 KB
testcase_04 AC 19 ms
8,380 KB
testcase_05 AC 18 ms
8,348 KB
testcase_06 AC 18 ms
8,344 KB
testcase_07 AC 19 ms
8,296 KB
testcase_08 AC 19 ms
8,316 KB
testcase_09 AC 116 ms
34,768 KB
testcase_10 AC 134 ms
21,684 KB
testcase_11 AC 137 ms
21,756 KB
testcase_12 AC 146 ms
8,620 KB
testcase_13 AC 159 ms
8,708 KB
testcase_14 AC 152 ms
8,640 KB
testcase_15 AC 156 ms
8,704 KB
testcase_16 AC 154 ms
8,684 KB
testcase_17 AC 141 ms
21,716 KB
testcase_18 AC 151 ms
8,860 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict
S = input()
ans = 0
a = 0
d = defaultdict(lambda: 0)
d[0] = -1
for i,c in enumerate(S):
    if c == 'A':
        a += 1
    else:
        a -= 1
    if a in d:
        ans = max(ans, i - d[a])
    else:
        d[a] = i
print(ans)
0