ECOO '15 R3 P3 - Roadie Cross

View as PDF

Submit solution

Points: 10 (partial)
Time limit: 1.0s
Memory limit: 64M

Problem types

Somewhere in a parallel world, one of Taylor Swift's roadies is trying to get across a busy road carrying a huge load of equipment. She's so loaded down that she can't go left, right or backwards. She can only step forward or wait where she is. Can you help her get across the road?

Roads are strange in this parallel world. Each road consists of a number of lanes of traffic, but the first lane moves left, the next moves right, and then the lanes continue to alternate directions until you get to the other side. Each lane contains a looping pattern of cars and empty car-sized areas.

Time and space are also strange. Time moves forward in discrete chunks and people and cars can jump from one location to another in car-sized or lane-sized jumps without having to cross the intervening space. As a result, a road crossing situation for the roadie described above could unfold as shown in the series of pictures below (R is the Roadie, asterisks * are cars).

                                                                  R
-***-   ***--   **--*   *--**   --***   -***-   ***--   **R-*   *--**
*----   -*---   --*--   ---*-   --R-*   *-R--   -*R--   --*--   ---*-
-**-*   **-*-   *-*-*   -*R**   *-**-   -**-*   **-*-   *-*-*   -*-**
-*---   --*--   --R*-   ----*   *----   -*---   --*--   ---*-   ----*
--*--   -*R--   *----   ----*   ---*-   --*--   -*---   *----   ----*
  R

        STEP    STEP    STEP    STEP    WAIT    WAIT    STEP    STEP

The input will contain 10 test cases. The first line of each test case contains two integers L and W separated by a space. L indicates the number of lanes (1 \le L \le 100) and W indicates the width of each lane (W = 2k+1, 0 \le k \le 250). The next L lines contain a representation of each lane in which a hyphen character (ASCII 45) indicates an empty area and an asterisk (ASCII 42) indicates a car.

Every lane contains at least one car. The roadie starts her journey below the bottom lane of the road and centered with respect to the initial configuration of traffic patterns on the road (as in the example above). In each time step, she can move forwards (up) or wait. Your job is to output the minimum number of time steps for the roadie to cross the road. If it is not possible for her to cross the road at all, you should output the string Not Possible.

Sample Input

5 5
-***-
*----
-**-*
-*---
--*--
4 13
-*----*--*---
--*----------
**--*---*****
----***-*****
4 13
*------*****-
---****---*--
--**--*-****-
***-**--*--*-

Sample Output

8
Not Possible
5

Note: Only 3 cases are shown in this sample.

Educational Computing Organization of Ontario - statements, test data and other materials can be found at ecoocs.org


Comments

There are no comments at the moment.