No.559 swapAB列
タグ : / 解いたユーザー数 440
作問者 :
nmnmnmnmnmnmnm
/ テスター :
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
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もしくは右上の雲マークをクリックしてアカウントを作成してください。