TopCoder

User's AC Ratio

NaN% (0/0)

Submission's AC Ratio

NaN% (0/0)

Tags

Description

You are given a 5x5 board containing at most 5 pieces. Your task is to move the pieces so that the cells occupied by them form a connected component. A connected component is a set of cells where each pair of cells is connected by at least one path. Consecutive cells in a path must all be adjacent. Two cells are called adjacent if they share a common edge.

You are given five strings, where the j-th character of the i-th string is '*' if cell (i, j) is occupied by a piece and '.' otherwise. Return the minimum number of moves required to achieve your goal. Each move consists of moving one piece to an adjacent empty cell.

Input Format

There are several testcase, seperated by blank lines. Each testcase has exactly five lines and each line has exactly five character, which will be either '*' or '.'.

Output Format

For each testcase, print the minimum number of moves to reach the goal.

Sample Input 1

.....
..**.
.....
...*.
.....

.....
.....
.**..
.*...
**...

*...*
.....
.....
.....
*...*

Sample Output 1

1
0
12

Hints

Problem Source

Migrated from old NTUJ.

Subtasks

No. Testdata Range Score

Testdata and Limits

No. Time Limit (ms) Memory Limit (VSS, KiB) Output Limit (KiB) Subtasks
0 10000 65536 200