結果

問題 No.672 最長AB列
ユーザー ronpooronpoo
提出日時 2023-11-21 13:27:36
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 88 ms / 2,000 ms
コード長 277 bytes
コンパイル時間 258 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 111,632 KB
最終ジャッジ日時 2023-11-21 13:27:40
合計ジャッジ時間 3,174 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 47 ms
53,460 KB
testcase_01 AC 35 ms
53,460 KB
testcase_02 AC 35 ms
53,460 KB
testcase_03 AC 37 ms
53,460 KB
testcase_04 AC 36 ms
53,460 KB
testcase_05 AC 36 ms
53,460 KB
testcase_06 AC 40 ms
53,460 KB
testcase_07 AC 38 ms
53,460 KB
testcase_08 AC 37 ms
53,460 KB
testcase_09 AC 88 ms
111,632 KB
testcase_10 AC 76 ms
94,944 KB
testcase_11 AC 80 ms
97,032 KB
testcase_12 AC 66 ms
78,476 KB
testcase_13 AC 64 ms
78,220 KB
testcase_14 AC 65 ms
78,476 KB
testcase_15 AC 65 ms
78,476 KB
testcase_16 AC 64 ms
78,476 KB
testcase_17 AC 78 ms
94,900 KB
testcase_18 AC 60 ms
76,044 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

S = input()
L = len(S)

A = [0]
for i in range(L):
    if S[i] == 'A':
        A.append(A[-1] + 1)
    else:
        A.append(A[-1] - 1)

ans = 0
d = dict()
for i in range(L+1):
    if A[i] not in d:
        d[A[i]] = i
    else:
        ans = max(ans, i - d[A[i]])
print(ans)
0