結果

問題 No.672 最長AB列
ユーザー prd_xxxprd_xxx
提出日時 2018-04-14 01:26:11
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
AC  
実行時間 158 ms / 2,000 ms
コード長 266 bytes
コンパイル時間 292 ms
コンパイル使用メモリ 10,484 KB
実行使用メモリ 34,844 KB
最終ジャッジ日時 2023-09-10 04:22:46
合計ジャッジ時間 3,136 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
8,384 KB
testcase_01 AC 19 ms
8,388 KB
testcase_02 AC 19 ms
8,340 KB
testcase_03 AC 19 ms
8,300 KB
testcase_04 AC 18 ms
8,296 KB
testcase_05 AC 19 ms
8,268 KB
testcase_06 AC 19 ms
8,340 KB
testcase_07 AC 19 ms
8,432 KB
testcase_08 AC 18 ms
8,368 KB
testcase_09 AC 122 ms
34,844 KB
testcase_10 AC 135 ms
21,772 KB
testcase_11 AC 137 ms
21,668 KB
testcase_12 AC 146 ms
8,632 KB
testcase_13 AC 158 ms
8,696 KB
testcase_14 AC 156 ms
8,704 KB
testcase_15 AC 149 ms
8,680 KB
testcase_16 AC 154 ms
8,628 KB
testcase_17 AC 145 ms
21,852 KB
testcase_18 AC 147 ms
8,624 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