結果

問題 No.672 最長AB列
ユーザー DrDrpilotDrDrpilot
提出日時 2022-01-21 11:27:56
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 208 ms / 2,000 ms
コード長 364 bytes
コンパイル時間 636 ms
コンパイル使用メモリ 10,992 KB
実行使用メモリ 24,536 KB
最終ジャッジ日時 2023-08-16 15:51:12
合計ジャッジ時間 4,059 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
10,164 KB
testcase_01 AC 18 ms
10,156 KB
testcase_02 AC 18 ms
10,224 KB
testcase_03 AC 17 ms
10,088 KB
testcase_04 AC 17 ms
10,108 KB
testcase_05 AC 16 ms
10,264 KB
testcase_06 AC 17 ms
10,236 KB
testcase_07 AC 18 ms
10,232 KB
testcase_08 AC 18 ms
10,108 KB
testcase_09 AC 129 ms
24,536 KB
testcase_10 AC 154 ms
21,492 KB
testcase_11 AC 179 ms
21,520 KB
testcase_12 AC 205 ms
18,236 KB
testcase_13 AC 208 ms
18,240 KB
testcase_14 AC 202 ms
14,120 KB
testcase_15 AC 204 ms
15,840 KB
testcase_16 AC 204 ms
17,668 KB
testcase_17 AC 187 ms
21,432 KB
testcase_18 AC 200 ms
11,900 KB
権限があれば一括ダウンロードができます

ソースコード

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