## DWITE '10 R4 #4 - Mountain Hiking

View as PDF

Points: 7
Time limit: 1.0s
Memory limit: 64M

Problem type
Allowed languages
Ada, Assembly, Awk, Brain****, C, C#, C++, COBOL, CommonLisp, D, Dart, F#, Forth, Fortran, Go, Groovy, Haskell, Intercal, Java, JS, Kotlin, Lisp, Lua, Nim, ObjC, OCaml, Octave, Pascal, Perl, PHP, Pike, Prolog, Python, Racket, Ruby, Rust, Scala, Scheme, Sed, Swift, TCL, Text, Turing, VB, Zig
##### DWITE Online Computer Programming Contest, January 2011, Problem 4

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 . 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 will contain 5 test cases. Each test case consists of a map of digits to , each digit representing the height of that location. A line of hyphens ---------- follows each test case for visual separation.

The output will contain 5 lines, the least number of steps to cross the mountain range in each case. If the hiker can't get across, output IMPOSSIBLE 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

9324892342
1334343293
3524523454
2634232043
0343259235
2454502352
4563589024
7354354256
9343221234
2653560343
----------

#### Sample Output

11