結果

問題 No.672 最長AB列
ユーザー mlihua09mlihua09
提出日時 2020-09-14 21:25:13
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 97 ms / 2,000 ms
コード長 278 bytes
コンパイル時間 279 ms
コンパイル使用メモリ 86,940 KB
実行使用メモリ 83,036 KB
最終ジャッジ日時 2023-09-04 00:48:44
合計ジャッジ時間 3,428 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 68 ms
71,112 KB
testcase_01 AC 70 ms
71,448 KB
testcase_02 AC 68 ms
71,148 KB
testcase_03 AC 70 ms
71,336 KB
testcase_04 AC 73 ms
71,404 KB
testcase_05 AC 68 ms
71,060 KB
testcase_06 AC 73 ms
71,240 KB
testcase_07 AC 71 ms
71,172 KB
testcase_08 AC 70 ms
71,292 KB
testcase_09 AC 92 ms
82,900 KB
testcase_10 AC 92 ms
82,804 KB
testcase_11 AC 97 ms
82,980 KB
testcase_12 AC 92 ms
82,860 KB
testcase_13 AC 89 ms
82,884 KB
testcase_14 AC 89 ms
82,700 KB
testcase_15 AC 91 ms
82,804 KB
testcase_16 AC 88 ms
82,892 KB
testcase_17 AC 89 ms
83,036 KB
testcase_18 AC 84 ms
82,792 KB
権限があれば一括ダウンロードができます

ソースコード

diff #


S = input()

n = len(S)

M = [-1] * (2 * n + 1)
m = [n] * (2 * n + 1)

x = 0
m[n] = -1
for i in range(n):
    if S[i] == 'A':
        x += 1
    else:
        x -= 1
    M[x + n] = i
    if m[x + n] == n:
        m[x + n] = i

print(max(M[i] - m[i] for i in range(2 * n + 1)))
0