結果

問題 No.672 最長AB列
ユーザー yakeshibayakeshiba
提出日時 2021-03-13 05:18:16
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 517 bytes
コンパイル時間 262 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 132,864 KB
最終ジャッジ日時 2024-04-22 18:27:06
合計ジャッジ時間 2,066 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
53,504 KB
testcase_01 AC 43 ms
53,504 KB
testcase_02 AC 40 ms
53,504 KB
testcase_03 AC 46 ms
53,632 KB
testcase_04 AC 42 ms
53,632 KB
testcase_05 AC 40 ms
53,376 KB
testcase_06 AC 42 ms
53,248 KB
testcase_07 AC 41 ms
53,632 KB
testcase_08 AC 40 ms
53,760 KB
testcase_09 AC 124 ms
132,864 KB
testcase_10 AC 103 ms
102,784 KB
testcase_11 AC 104 ms
104,808 KB
testcase_12 AC 83 ms
78,080 KB
testcase_13 WA -
testcase_14 AC 74 ms
78,080 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 108 ms
107,008 KB
testcase_18 AC 69 ms
78,080 KB
権限があれば一括ダウンロードができます

ソースコード

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
    
#print(S)
#print(memo)
    
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])

ans = max(ans,last[0])
ans = max(ans, first[0])

print(ans)
0