結果

問題 No.672 最長AB列
ユーザー 👑 KazunKazun
提出日時 2020-11-13 15:30:21
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 130 ms / 2,000 ms
コード長 228 bytes
コンパイル時間 544 ms
コンパイル使用メモリ 87,136 KB
実行使用メモリ 113,324 KB
最終ジャッジ日時 2023-09-30 02:06:52
合計ジャッジ時間 4,182 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 68 ms
71,396 KB
testcase_01 AC 69 ms
71,452 KB
testcase_02 AC 69 ms
71,196 KB
testcase_03 AC 70 ms
71,272 KB
testcase_04 AC 70 ms
71,412 KB
testcase_05 AC 69 ms
71,552 KB
testcase_06 AC 68 ms
71,048 KB
testcase_07 AC 69 ms
71,240 KB
testcase_08 AC 68 ms
71,540 KB
testcase_09 AC 130 ms
113,324 KB
testcase_10 AC 96 ms
91,196 KB
testcase_11 AC 100 ms
91,220 KB
testcase_12 AC 80 ms
76,808 KB
testcase_13 AC 79 ms
76,672 KB
testcase_14 AC 81 ms
76,688 KB
testcase_15 AC 82 ms
76,636 KB
testcase_16 AC 81 ms
76,808 KB
testcase_17 AC 97 ms
91,100 KB
testcase_18 AC 77 ms
76,324 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

S=input()
N=len(S)
D={0:[-1,-1]}

X=0
for i in range(N):
    if S[i]=="A":
        X+=1
    else:
        X-=1

    if X in D:
        D[X][1]=i
    else:
        D[X]=[i,i]

K=0
for x in D:
    K=max(K,D[x][1]-D[x][0])
print(K)
0