Codeforces Round 754 (Div. 2) |
---|
Finished |
Ashish has a binary string $$$s$$$ of length $$$n$$$ that he wants to sort in non-decreasing order.
He can perform the following operation:
Find the minimum number of operations required to sort the string in non-decreasing order. It can be proven that it is always possible to sort the given binary string in at most $$$n$$$ operations.
The first line contains a single integer $$$t$$$ $$$(1 \le t \le 1000)$$$ — the number of test cases. The description of the test cases follows.
The first line of each test case contains an integer $$$n$$$ $$$(1 \le n \le 1000)$$$ — the length of the binary string $$$s$$$.
The second line of each test case contains a binary string $$$s$$$ of length $$$n$$$ containing only $$$0$$$s and $$$1$$$s.
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$1000$$$.
For each test case output the following:
3 7 0011111 5 10100 6 001000
0 1 4 1 3 4 5 1 3 3 5 6
In the first test case, the binary string is already sorted in non-decreasing order.
In the second test case, we can perform the following operation:
$$$\underline{1}$$$ $$$0$$$ $$$\underline{1}$$$ $$$\underline{0}$$$ $$$\underline{0}$$$ $$$\rightarrow $$$ $$$\underline{0}$$$ $$$0$$$ $$$\underline{0}$$$ $$$\underline{1}$$$ $$$\underline{1}$$$
In the third test case, we can perform the following operation:
$$$0$$$ $$$0$$$ $$$\underline{1}$$$ $$$0$$$ $$$\underline{0}$$$ $$$\underline{0}$$$ $$$\rightarrow $$$ $$$0$$$ $$$0$$$ $$$\underline{0}$$$ $$$0$$$ $$$\underline{0}$$$ $$$\underline{1}$$$
Name |
---|