結果

問題 No.672 最長AB列
ユーザー hedwig100hedwig100
提出日時 2020-05-07 23:17:02
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 171 ms / 2,000 ms
コード長 233 bytes
コンパイル時間 176 ms
コンパイル使用メモリ 10,544 KB
実行使用メモリ 34,408 KB
最終ジャッジ日時 2023-09-16 08:10:37
合計ジャッジ時間 3,882 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
7,836 KB
testcase_01 AC 15 ms
7,844 KB
testcase_02 AC 15 ms
7,812 KB
testcase_03 AC 15 ms
7,880 KB
testcase_04 AC 15 ms
7,776 KB
testcase_05 AC 15 ms
8,000 KB
testcase_06 AC 15 ms
7,804 KB
testcase_07 AC 15 ms
7,872 KB
testcase_08 AC 15 ms
7,844 KB
testcase_09 AC 122 ms
34,408 KB
testcase_10 AC 146 ms
21,356 KB
testcase_11 AC 151 ms
21,368 KB
testcase_12 AC 158 ms
8,300 KB
testcase_13 AC 171 ms
8,272 KB
testcase_14 AC 166 ms
8,372 KB
testcase_15 AC 166 ms
8,324 KB
testcase_16 AC 163 ms
8,328 KB
testcase_17 AC 149 ms
21,328 KB
testcase_18 AC 165 ms
8,304 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

s = input()
N = len(s)
ab = {0:-1}
a = 0
b = 0
ans = 0
for i in range(N):
    if s[i] == 'A':
        a += 1
    else:
        b += 1
    if a - b in ab:
        ans = max(ans,i - ab[a - b])
    else:
        ab[a - b] = i
print(ans)
0