City and Bitcoin
InterviewTime limit1sMemory limit512 MB
Determines whether a path exists from the top-left to the bottom-right of a grid using only right and down moves through open cells.
- Level
Easy2 of 10
- Topics
- Matrix, Dynamic programming
- Solved
- No attempts yet
Problem
Bitcoin's price rose by a full million won from the previous day one morning, and Woojin decides to go to the exchange to sell some. The price keeps falling, so he must reach the exchange as quickly as possible.
The city is a grid with columns and rows. Some cells are empty ground or roads that Woojin can pass through, while other cells contain buildings he cannot enter. Woojin starts at the top-left corner, and the exchange is at the bottom-right corner.
Because he must hurry, he has to reach the exchange by moving only east (right) or south (down). Write a program that determines whether Woojin can reach the exchange. His current position may already be the exchange.
Input
The first line contains and (), the width and height of the city.
The next lines each contain integers separated by spaces. A 1 marks a cell Woojin can enter, and a 0 marks a cell he cannot enter.
The top-left and bottom-right cells are both 1.
Output
Print Yes if Woojin can reach the exchange. Otherwise, print No.