結果

問題 No.672 最長AB列
コンテスト
ユーザー pika4632
提出日時 2018-05-09 14:29:12
言語 Python3
(3.14.3 + numpy 2.4.2 + scipy 1.17.0)
コンパイル:
python3 -mpy_compile _filename_
実行:
python3 _filename_
結果
WA  
実行時間 -
コード長 487 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 605 ms
コンパイル使用メモリ 20,696 KB
実行使用メモリ 33,492 KB
最終ジャッジ日時 2026-03-16 12:41:53
合計ジャッジ時間 18,675 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge3_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample WA * 3
other WA * 12 TLE * 4
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

S = input()
dictN = {}
listA = [0]
dictMIN = {0:0}
mx = 0
count = 0

for a,b in enumerate(S):
    if b == "A":
        count += 1
    else:
        count -= 1
    if count in dictMIN:
        dictN[count] = a + 1
    else:
        dictMIN[count] = a + 1
        
    if not count in listA:
        listA.append(count)
        
for a in listA:
    try:
        if dictN[a] - dictMIN[a] > mx:
            mx = dictN[a] - dictMIN[a]
    except KeyError:
        pass

print(str(mx) + "\n")
0