結果

問題 No.672 最長AB列
ユーザー ttrttr
提出日時 2020-02-12 21:57:25
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 245 ms / 2,000 ms
コード長 288 bytes
コンパイル時間 165 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 28,068 KB
最終ジャッジ日時 2024-04-14 23:02:15
合計ジャッジ時間 3,805 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
10,624 KB
testcase_01 AC 30 ms
10,624 KB
testcase_02 AC 30 ms
10,624 KB
testcase_03 AC 30 ms
10,752 KB
testcase_04 AC 30 ms
10,752 KB
testcase_05 AC 29 ms
10,624 KB
testcase_06 AC 30 ms
10,624 KB
testcase_07 AC 30 ms
10,624 KB
testcase_08 AC 30 ms
10,752 KB
testcase_09 AC 166 ms
28,068 KB
testcase_10 AC 204 ms
24,988 KB
testcase_11 AC 200 ms
25,016 KB
testcase_12 AC 244 ms
21,736 KB
testcase_13 AC 239 ms
21,844 KB
testcase_14 AC 238 ms
21,920 KB
testcase_15 AC 244 ms
21,844 KB
testcase_16 AC 243 ms
21,840 KB
testcase_17 AC 207 ms
24,940 KB
testcase_18 AC 245 ms
21,804 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

S = input()

N = len(S)
L = [N]*(N+1)
ans = 0
memo = [-1]*(2*N+1)
memo[N] = 0
for i in range(N):
    if S[i] == "A":
        L[i+1] = L[i]+1
    else:
        L[i+1] = L[i]-1
    if memo[L[i+1]] < 0:
        memo[L[i+1]] = i+1
    else:
        ans = max(ans, i+1-memo[L[i+1]])
print(ans)
0