#P1354. Shortest Path in a Walled Room

    ID: 14641 Type: Default 1000ms 256MiB

Shortest Path in a Walled Room

Shortest Path in a Walled Room

You are given a square room of side length \(10\) with an entrance at \((0,5)\) and an exit at \((10,5)\). Inside the room, there are several vertical walls. Each wall is located at \(x\) (with \(0 < x < 10\)) and has two gaps (openings) specified by the intervals \([y_{1s}, y_{1e}]\) and \([y_{2s}, y_{2e}]\). The wall occupies the full vertical span of the room except for these two gaps. Your task is to compute the length of the shortest path from the entrance to the exit, where the path is allowed to cross a wall only through one of its gaps. All formulas are in LaTeX format.

Note: A point lying exactly on a wall is considered valid if its \(y\) coordinate lies within one of the gap intervals (endpoints are included). The straight-line segment between two points is valid only if for every wall, the intersection point (if any) with the line \(x=x_w\) lies inside one of the gap intervals.

inputFormat

The first line contains an integer \(n\), the number of walls. Each of the following \(n\) lines contains five numbers:

  • \(x\): the x-coordinate of the wall,
  • \(y_{1s}\) and \(y_{1e}\): the start and end of the first gap,
  • \(y_{2s}\) and \(y_{2e}\): the start and end of the second gap.

The room is a \(10 \times 10\) square with the entrance at \((0,5)\) and the exit at \((10,5)\).

outputFormat

Output a single line containing the length of the shortest path from the entrance to the exit, rounded to three decimal places.

sample

1
5 2 4 6 8
10.198