結果

問題 No.672 最長AB列
ユーザー DrDrpilot
提出日時 2022-01-21 11:27:56
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 297 ms / 2,000 ms
コード長 364 bytes
コンパイル時間 389 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 27,232 KB
最終ジャッジ日時 2024-11-25 05:34:25
合計ジャッジ時間 3,783 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 16
権限があれば一括ダウンロードができます

ソースコード

diff #

s=input()
cnt=[0]*(len(s)+1)
now=0
for i in range(len(s)):
    if s[i]=='A':
        now+=1
    else:
        now-=1
    cnt[i+1]=now
if min(cnt)<0:
    d=min(cnt)
    for i in range(len(s)+1):
        cnt[i]+=d
ind=[-1]*(3*10**5)
ans=0
for i in range(len(s)+1):
    if ind[cnt[i]]==-1:
        ind[cnt[i]]=i
    else:
        ans=max(ans,i-ind[cnt[i]])
print(ans)
0