Canadian Computing Competition: 2020 Stage 1, Junior #5, Senior #2
You have to determine if it is possible to escape from a room. The room is an -by- grid with each position (cell) containing a positive integer. The rows are numbered and the columns are numbered . We use to refer to the cell in row and column .
You start in the top-left corner at and exit from the bottom-right corner at . If you are in a cell containing the value , then you can jump to any cell satisfying . For example, if you are in a cell containing a , you can jump to cell .
Note that from a cell containing a , there are up to four cells you can jump to: , , or . If the room is a -by- grid, there isn't a row so only the first three jumps would be possible.
Input Specification
The first line of the input will be an integer (). The second line of the input will be an integer (). The remaining input gives the positive integers in the cells of the room with rows and columns. It consists of lines where each line contains positive integers, each less than or equal to , separated by single spaces.
For 1 of the 15 available marks, and .
For an additional 2 of the 15 available marks, .
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, and .
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
Sample Output
yes
Sample Explanation
Starting in the cell at which contains a , one possibility is to jump to the cell at . This cell contains an so from it, you could jump to the cell at . This brings you to a cell containing from which you can jump to the exit at . Note that another way to escape is to jump from the starting cell to the cell at to the cell at to the exit.
Comments