CCCGuide

Problem S2: Escape Room

2020 · S2 · Original problem · DMOJ

Problem Description

You have to determine if it is possible to escape from a room. The room is an MM-by-NN grid with each position (cell) containing a positive integer. The rows are numbered 1,2,…,M1,2,\ldots,M and the columns are numbered 1,2,…,N1,2,\ldots,N. We use (r,c)(r,c) to refer to the cell in row rr and column cc.

You start in the top-left corner at (1,1)(1,1) and exit from the bottom-right corner at (M,N)(M,N). If you are in a cell containing the value xx, then you can jump to any cell (a,b)(a,b) satisfying a×b=xa \times b = x. For example, if you are in a cell containing a 66, you can jump to cell (2,3)(2,3).

Note that from a cell containing a 66, there are up to four cells you can jump to: (2,3)(2,3), (3,2)(3,2), (1,6)(1,6), or (6,1)(6,1). If the room is a 55-by-66 grid, there isn’t a row 66 so only the first three jumps would be possible.

Input Specification

The first line of the input will be an integer MM (1≤M≤1000)(1 \leq M \leq 1000). The second line of the input will be an integer NN (1≤N≤1000)(1 \leq N \leq 1000). The remaining input gives the positive integers in the cells of the room with MM rows and NN columns. It consists of MM lines where each line contains NN positive integers, each less than or equal to 1 000 0001\,000\,000, separated by single spaces.

For 1 of the 15 available marks, M=2M=2 and N=2N=2.

For an additional 2 of the 15 available marks, M=1M=1.

For an additional 4 of the 15 available marks, all of the integers in the cells will be unique.

For an additional 4 of the 15 available marks, M≤200M\leq 200 and N≤200N\leq 200.

Output Specification

Output yes if it is possible to escape from the room. Otherwise, output no.

Sample Input

3
4
3 10 8 14
1 11 12 12
6 2 3 9

Output for Sample Input

yes

Explanation of Output for Sample Input

Starting in the cell at (1,1)(1,1) which contains a 33, one possibility is to jump to the cell at (1,3)(1,3). This cell contains an 88 so from it, you could jump to the cell at (2,4)(2,4). This brings you to a cell containing 1212 from which you can jump to the exit at (3,4)(3,4). Note that another way to escape is to jump from the starting cell to the cell at (3,1)(3,1) to the cell at (2,3)(2,3) to the exit.

Notes