DWITE '10 R4 #4 - Mountain Hiking

View as PDF

Submit solution

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 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 will contain 5 test cases. Each test case consists of a 10 \times 10 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 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


Sample Output


Attribution-NonCommercial-ShareAlike 3.0 Unported (CC BY-NC-SA 3.0) Problem Resource: DWITE


  • 3
    RyanLi  commented on Aug. 13, 2019, 9:48 a.m.

    the lest number of steps

    Typo on least