Hyundai Mobis Autonomous Driving Testing 2
Time limit1sMemory limit1024 MB
Given sample 2-row tracks joined in order, find the minimum moves from the first column to the last using only road cells, or -1 if impossible.
- Level
Medium6 of 10
- Topics
- Matrix, Dynamic programming, Shortest path
- Solved
- No attempts yet
Problem
This problem has a different input format from Hyundai Mobis Autonomous Driving Testing 1. Code written for this problem cannot solve Hyundai Mobis Autonomous Driving Testing 1.
Hyundai Mobis is a mobility platform provider that actively conducts software R&D in autonomous driving, electrification, connectivity, and other fields to lead the era of the Software Defined Vehicle (SDV). At the Seosan test track of Hyundai Mobis, test drives for developing self-driving cars are underway.
There are kinds of sample tracks, numbered from 1 to . Sample track has 2 rows and columns, and each cell is either a road or an obstacle. A test track is made by joining sample tracks in order. If the sample track numbers used for the test track are in order, the test track has 2 rows and columns.
The car can move on the track in two ways:
- Lane change: the car moves to the other row in the same column. From row 1 column it moves to row 2 column , and from row 2 column it moves to row 1 column .
- Straight: the car moves to the next column in the same row. From row column it moves to row column .
In both cases, the destination cell must not be an obstacle.
The test drive starts at the first column of the test track and ends when the car reaches the last column. The starting cell and the ending cell can be chosen freely, but both must be roads. Determine whether the car can complete the test track. If it can, find the minimum number of moves needed to complete it.
Input
The first line contains the number of sample track kinds and the number of times sample tracks are joined, separated by a space. ()
The second line contains the sample track numbers in order, separated by spaces. ()
From the third line, the information for the sample tracks is given over lines. Line contains a string of length that represents row 1 of sample track . Line contains a string of length that represents row 2 of sample track . ()
Every string consists only of . and #. . is a road and # is an obstacle. The sum of all is at most 500000.
Output
Print the minimum number of moves the car needs to complete the test track. If the car cannot complete the test track, print -1.