DWITE Online Computer Programming Contest
January 2011
Problem 4
Mountain Hiking

Mountain hiking is a very adventurous, yet somewhat dangerous, pastime. On certain mountain ranges, the heights could vary sharply. An amateur hiker can move to an adjacent (left/right, up/down, but not diagonally) location only if the height difference with the current location is at most 1. Given a height map of a mountain range, determine the distance of the shortest viable path between the left and the right edges.

The input file DATA4.txt will contain 5 test cases. Each test case consists of a 10x10 map of digits 0 to 9, each digit representing the height of that location. A line of hyphens ---------- follows each test case for visual separation.

The output file OUT4.txt will contain 5 lines, the lest number of steps to cross the mountain range in each case. If the hiker can't get across, output "IMPOSSIBLE" (without quotes) instead.

Notes: the hiker could start at any of the left-most positions. The steps counted are the transitions from one location to the next. Thus appearing in that very first location requires no steps.

Sample Input (only 1st case shown):
9324892342
1334343293
3524523454
2634232043
0343259235
2454502352
4563589024
7354354256
9343221234
2653560343
----------
		        
Sample Output (only 1st case shown):
11
		        
Explanation for the Sample test case:

9324892342
1334343293
3524523454
2634232043
0343259235
2454502352
4563589024
7354354256
9343221234
2653560343