#P11580. Escape the Room
Escape the Room
Escape the Room
You are trapped in a room represented by an m x n matrix. Each cell of the matrix contains a positive integer. We denote the cell on the x-th row and y-th column as (x,y)
(1-indexed).
You start from cell (1,1)
and your goal is to reach cell (m,n)
. From a cell containing the number \(num\), you can jump to a cell (x,y)
if and only if \(x \times y = num\). For example, if you are in a cell containing \(6\), you may jump to (2,3)
(or (3,2)
if within bounds) because \(2 \times 3 = 6\>.
Determine whether you can escape the room by reaching cell (m,n)
following the above rules.
inputFormat
The first line contains two integers m
and n
(\(1 \leq m,n\leq 1000\), for example), representing the number of rows and columns of the matrix. Each of the next m
lines contains n
positive integers, representing the grid. Note that the matrix is 1-indexed.
outputFormat
Output yes
if it is possible to escape the room, or no
otherwise.
sample
3 4
3 10 8 14
1 11 12 12
6 2 3 9
yes