Codeforces Round 593 (Div. 2) |
---|
Finished |
Alice got a new doll these days. It can even walk!
Alice has built a maze for the doll and wants to test it. The maze is a grid with $$$n$$$ rows and $$$m$$$ columns. There are $$$k$$$ obstacles, the $$$i$$$-th of them is on the cell $$$(x_i, y_i)$$$, which means the cell in the intersection of the $$$x_i$$$-th row and the $$$y_i$$$-th column.
However, the doll is clumsy in some ways. It can only walk straight or turn right at most once in the same cell (including the start cell). It cannot get into a cell with an obstacle or get out of the maze.
More formally, there exist $$$4$$$ directions, in which the doll can look:
Standing in some cell the doll can move into the cell in the direction it looks or it can turn right once. Turning right once, the doll switches it's direction by the following rules: $$$1 \to 2$$$, $$$2 \to 3$$$, $$$3 \to 4$$$, $$$4 \to 1$$$. Standing in one cell, the doll can make at most one turn right.
Now Alice is controlling the doll's moves. She puts the doll in of the cell $$$(1, 1)$$$ (the upper-left cell of the maze). Initially, the doll looks to the direction $$$1$$$, so along the row from the first cell to the last. She wants to let the doll walk across all the cells without obstacles exactly once and end in any place. Can it be achieved?
The first line contains three integers $$$n$$$, $$$m$$$ and $$$k$$$, separated by spaces ($$$1 \leq n,m \leq 10^5, 0 \leq k \leq 10^5$$$) — the size of the maze and the number of obstacles.
Next $$$k$$$ lines describes the obstacles, the $$$i$$$-th line contains two integer numbers $$$x_i$$$ and $$$y_i$$$, separated by spaces ($$$1 \leq x_i \leq n,1 \leq y_i \leq m$$$), which describes the position of the $$$i$$$-th obstacle.
It is guaranteed that no two obstacles are in the same cell and no obstacle is in cell $$$(1, 1)$$$.
Print 'Yes' (without quotes) if the doll can walk across all the cells without obstacles exactly once by the rules, described in the statement.
If it is impossible to walk across the maze by these rules print 'No' (without quotes).
3 3 2 2 2 2 1
Yes
3 3 2 3 1 2 2
No
3 3 8 1 2 1 3 2 1 2 2 2 3 3 1 3 2 3 3
Yes
Here is the picture of maze described in the first example:
In the first example, the doll can walk in this way:
Name |
---|