#GD0000171. Sắp xếp đàn cừu (Arranging The Sheep)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Sắp xếp đàn cừu (Arranging The Sheep)
Arranging The Sheep
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
A row contains consecutive cells. Each cell is either empty (.) or contains exactly one sheep (*). Sheep preserve their left-to-right order because no two sheep can move through one another.
In one move, choose a sheep and move it one cell left or right, provided that the destination is inside the row and empty. The goal is to make all sheep occupy consecutive cells with no empty cell between any pair of sheep. A row with zero or one sheep already meets the goal.
Find the minimum number of individual moves needed to reach such a configuration.
Input
Line 1 contains an integer , the number of cells.
Line 2 contains a string of exactly characters, each . or *, describing the cells from left to right, indexed from to .
Output
Print one nonnegative integer: the minimum number of moves needed to group all sheep in consecutive cells.
Subtasks
- Subtask 1 (20 points): ; has exactly characters, each
.or*. - Subtask 2 (30 points): ; has exactly characters, each
.or*. - Subtask 3 (50 points): ; has exactly characters, each
.or*.
Examples
Input
6
**.*..
Output
1
Explanation
The sheep initially occupy cells , , and . Move the sheep in cell once into empty cell , obtaining ***.... Since the initial state has a gap, zero moves cannot suffice, so the answer is .