## DMOPC '13 Contest 3 P3 - Crossing Field

View as PDF

Points: 10 (partial)
Time limit: 6.0s
Memory limit: 256M

Author:
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

You are about to cross an by meter field. However, you are not sure if it's actually possible to do so. Each square meter of the field has an elevation value — you may only cross into an adjacent square meter if the distance between the centres of the squares is equal to one and if the elevation difference between the squares is less than or equal to .

Determine whether it is possible to cross the field or not if you start at the top left corner, square , and end in the bottom right corner, square .

#### Input Specification

The first line of input will contain 2 integers: and .

The next lines will contain integers each, the elevation of that square meter of the field. The elevation will be an integer between and .

#### Output Specification

On a single line, output yes if you can cross the field; otherwise, output no.

#### Constraints

Test Case BatchMarksConstraints
1 [5 cases]80
2 [2 cases]20

#### Sample Input

4 3
3 6 4 9
7 1 2 3
7 7 2 2
7 7 1 5

#### Sample Output

yes

#### Explanation for Sample Output

From the top left square, you can go right, right, down, down, right, down to reach the bottom right square.

• commented on June 18, 2020, 12:48 p.m.

Does diagnol count as going to an adjacent square?

• commented on June 18, 2020, 3:05 p.m.

No

• commented on March 19, 2016, 5:08 p.m. edited

On Batch 1 Case 4 and Batch 2 Case 1, I keep getting an Invalid Return. I have reviewed my code and I can't find the problem. Could you give me a hint as to what's wrong with my program? Am I forgetting a certain edge case? Thanks

• commented on March 19, 2016, 5:40 p.m.

Put this at the top of your code.

import sys
sys.setrecursionlimit(1000000)

Your code is exceeding python's built in recursion limit, which is 999.

• commented on March 19, 2016, 6:02 p.m.

Thanks!