Under construction

Still being built. Things may change

Delft Distance

Time limit4sMemory limit1024 MB

Summary
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 h×wh \times w buildings. Unlike Manhattan, the grid also contains round medieval towers. Every square building is axis aligned with a side length of 10m10 \text{m}, and every round tower has a diameter of 10m10 \text{m}. 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 hh and ww (1≤h,w≤7001 \leq h,w \leq 700), the number of rows and the number of columns of buildings on the map. Each of the next hh lines contains ww 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 10−610^{-6}.

Examples2

  1. Example 1

    Input
    3 5
    XOOXO
    OXOXO
    XXXXO
    
    Expected output
    71.4159265359
    
  2. Example 2

    Input
    1 4
    XOOX
    
    Expected output
    45.7079632679