ご近所の川を訪ねると、そこには二種類の石がちゃっかりと並べられていました。佳純ちゃんはこれを見て、番号の1のような見た目をした石が隣接するよう並び替えたいと思い付きます。
一回の操作では、二種類の石が同数含まれている区間を一つ選択し、その範囲内の石の種類を反転します。佳純ちゃんは、最小で何回の操作を必要としますか?
N S
7 1001011
2
以下の遷移を辿ることで達成可能です。()->()->()
14 11010001000011
4
4 0101
1
Visiting a local river awaited Kasumi a series of two kinds of rocks aligned carefully. She would like to sort it so that rocks that look like a digit 1 would sit contiguously.
One operation involves a selection of a range consisting of an equal number of both kinds to swap them together. What is the minimum number of operation to achieve her mission?
7 1001011
2
This is feasible by undergoing following transitions: (1001011)->(0110011)->(0111100)