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 test cases. The first line of each test case contains two integers and separated by a space. indicates the number of lanes and indicates the width of each lane . The next lines contain a representation of each lane in which a hyphen character (ASCII ) indicates an empty area and an asterisk (ASCII ) 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 cases are shown in this sample.
Educational Computing Organization of Ontario - statements, test data and other materials can be found at ecoocs.org
Comments