問題一覧 > 通常問題

No.559 swapAB列

レベル : / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 440
作問者 : nmnmnmnmnmnmnm / テスター : Nafmo2
お気に入りにしたユーザー ProblemId : 1655 / 自分の提出
問題文最終更新日: 2026-06-26 06:07:47
swapAB String
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. Show the original
yukicoder contest 172 (順位表) の他の問題:

Problem Statement

There is a string consisting of the characters 'A' and 'B'.
The following operation is allowed on the string.

・In one operation, swap two adjacent characters.

Find the minimum number of operations required to move all characters 'A' to the left and all characters 'B' to the right.

Input

$S$

$S$ is a string consisting of the characters 'A' and 'B'. $ 1 \le$ length of the string $S$ $\le 12$.

Output

Output the answer.

Sample

Sample 1
Input
BA
Output
1

BA can be swapped into AB with one operation.

Sample 2
Input
B
Output
0

The string may consist of a single character.
In this case, the character 'B' cannot move any further to the right, so it is considered to be already moved to the right.

Sample 3
Input
ABAABA
Output
4

"ABAABA" → "ABAAAB" → "AABAAB" → "AAABAB" → "AAAABB".
For example, with a procedure like this, a minimum of 4 operations is required.

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