Problem list
Log in
#icpc00207 · ICPC NWERC 2022

Delft Distance

Gold II 5.0 s 2048 MB

You are currently in your hotel at the north-west corner of Delft, and want to go to the contest site at the university in the south-east corner of Delft. To get there, you have to go right through the historical centre of the city. Like Manhattan, the city consists of a grid of $h \times w$ buildings. But unlike Manhattan, the city does not only contain square residential buildings but also some round medieval towers. All the square buildings are axis aligned with a side length of $10~\text{m}$ and all round towers have a diameter of $10~\text{m}$. There is just enough space for a small alley of negligible width between two neighbouring buildings.

Since you are already late for the contest start, you need to find a shortest path from your hotel to the contest site. Fortunately, you have a map of the city. See Figure for an example.

Input

The input consists of:

  • One line with two integers $h$ and $w$ ($1 \leq h,w \leq 700$), the number of rows and the number of columns of buildings shown on the map of the city.
  • $h$ lines, each with $w$ characters which are either 'O' (for round towers) or 'X' (for square buildings) describing the shapes of the buildings.

The map is oriented with the north side 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^{-6}$.

Example 1

Input
3 5
XOOXO
OXOXO
XXXXO
Output
71.4159265359

Example 2

Input
1 4
XOOX
Output
45.7079632679
Source
ICPC NWERC 2022
Appears in
Not part of a ladder, contest or set yet.
Accepted 0 Submissions 0 Acceptance 0% Solvers 0

Discussion

Threads about this problem. Spoilers are collapsed; wrap hints in ||double bars||.

No discussion yet. Start a thread if something here needs explaining.

Recent submissions Open with filters
Code