結果

問題 No.672 最長AB列
ユーザー yakeshibayakeshiba
提出日時 2021-03-13 05:09:00
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 448 bytes
コンパイル時間 184 ms
コンパイル使用メモリ 82,372 KB
実行使用メモリ 132,992 KB
最終ジャッジ日時 2024-04-22 18:20:59
合計ジャッジ時間 2,529 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
53,632 KB
testcase_01 AC 42 ms
53,504 KB
testcase_02 AC 48 ms
53,632 KB
testcase_03 AC 44 ms
53,760 KB
testcase_04 WA -
testcase_05 AC 44 ms
53,632 KB
testcase_06 AC 42 ms
53,888 KB
testcase_07 AC 42 ms
54,016 KB
testcase_08 AC 44 ms
53,376 KB
testcase_09 AC 131 ms
132,992 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict

S = input()

memo = [0]*(len(S))
n = 0
for i,s in enumerate(S):
    if s == "A":
        n += 1
    else:
        n -= 1
    memo[i] = n
    
first = defaultdict(int)
last = defaultdict(int)

for i,m in enumerate(memo):
    if first[m]:
        last[m] = i+1
    else:
        first[m] = i+1
        
ans = 0
for k,v in first.items():
    if last[k]:
        ans = max(ans, last[m]-first[m])
        
print(ans)
0