問題一覧 > 通常問題

No.672 Longest AB Sequence

レベル : / AI推定難易度 : 700 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 295
作問者 : nmnmnmnmnmnmnm / テスター : はむこ
お気に入りにしたユーザー ProblemId : 1486 / 自分の提出
問題文最終更新日: 2026-06-26 06:07:25
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 188 (順位表) の他の問題:

Problem Statement

There is a string $S$ consisting of the characters 'A' and 'B'.
Find the maximum length of a contiguous section of $S$ in which the number of 'A's and the number of 'B's are equal.

Input

$S$

The string $S$ consists of the characters 'A' and 'B'. $1 \le S$'s length$ \le 200000$.

Output

Output the length that is the answer on one line.
If there is no string that qualifies as the answer, output a length of 0.
Print a newline at the end.

Sample

Sample 1
Input
AAABBA
Output
4

The longest ones are "AABB" and "ABBA".
Their length is 4.

Sample 2
Input
ABBBBBA
Output
2

The longest ones are "AB" and "BA".
Their length is 2.

Sample 3
Input
B
Output
0

If there is no answer, treat the length as 0.

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。