Delft Distance
Time limit4sMemory limit1024 MB
Find the shortest path from the north-west to the south-east corner of a grid of square buildings and round towers, passing only through the alleys between them.
- Level
Medium7 of 10
- Topics
- Shortest path, Geometry, Matrix
- Solved
- No attempts yet
Problem
You are staying at a hotel in the north-west corner of Delft and want to reach the contest site at the university in the south-east corner. The route goes straight through the historical centre of the city. Like Manhattan, the city is a grid of buildings. Unlike Manhattan, the grid also contains round medieval towers. Every square building is axis aligned with a side length of , and every round tower has a diameter of . Between two neighbouring buildings there is just enough room for a small alley of negligible width. The contest has already started and you are late, so you need a shortest path from the hotel to the contest site. Fortunately, you have a map of the city. See Figure D.1.

Figure D.1: The city map from the first input, with a shortest path shown in red.
Input
The first line contains two integers and (), the number of rows and the number of columns of buildings on the map. Each of the next lines contains characters, each either 'O' (a round tower) or 'X' (a square building). The map is oriented with north up.
Output
Output the length of a shortest path from the north-west corner to the south-east corner of Delft in metres. Your answer may have a relative or absolute error of at most .