CF1236D.Alice and the Doll

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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 nn rows and mm columns. There are kk obstacles, the ii -th of them is on the cell (xi,yi)(x_i, y_i) , which means the cell in the intersection of the xix_i -th row and the yiy_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 44 directions, in which the doll can look:

  1. The doll looks in the direction along the row from the first cell to the last. While moving looking in this direction the doll will move from the cell (x,y)(x, y) into the cell (x,y+1)(x, y + 1) ;
  2. The doll looks in the direction along the column from the first cell to the last. While moving looking in this direction the doll will move from the cell (x,y)(x, y) into the cell (x+1,y)(x + 1, y) ;
  3. The doll looks in the direction along the row from the last cell to first. While moving looking in this direction the doll will move from the cell (x,y)(x, y) into the cell (x,y1)(x, y - 1) ;
  4. The doll looks in the direction along the column from the last cell to the first. While moving looking in this direction the doll will move from the cell (x,y)(x, y) into the cell (x1,y)(x - 1, y) .

.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: 121 \to 2 , 232 \to 3 , 343 \to 4 , 414 \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)(1, 1) (the upper-left cell of the maze). Initially, the doll looks to the direction 11 , 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 nn , mm and kk , separated by spaces ( 1n,m105,0k1051 \leq n,m \leq 10^5, 0 \leq k \leq 10^5 ) — the size of the maze and the number of obstacles.

Next kk lines describes the obstacles, the ii -th line contains two integer numbers xix_i and yiy_i , separated by spaces ( 1xin,1yim1 \leq x_i \leq n,1 \leq y_i \leq m ), which describes the position of the ii -th obstacle.

It is guaranteed that no two obstacles are in the same cell and no obstacle is in cell (1,1)(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).

输入输出样例

  • 输入#1

    3 3 2
    2 2
    2 1
    

    输出#1

    Yes
  • 输入#2

    3 3 2
    3 1
    2 2
    

    输出#2

    No
  • 输入#3

    3 3 8
    1 2
    1 3
    2 1
    2 2
    2 3
    3 1
    3 2
    3 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:

  • The doll is in the cell (1,1)(1, 1) , looks to the direction 11 . Move straight;
  • The doll is in the cell (1,2)(1, 2) , looks to the direction 11 . Move straight;
  • The doll is in the cell (1,3)(1, 3) , looks to the direction 11 . Turn right;
  • The doll is in the cell (1,3)(1, 3) , looks to the direction 22 . Move straight;
  • The doll is in the cell (2,3)(2, 3) , looks to the direction 22 . Move straight;
  • The doll is in the cell (3,3)(3, 3) , looks to the direction 22 . Turn right;
  • The doll is in the cell (3,3)(3, 3) , looks to the direction 33 . Move straight;
  • The doll is in the cell (3,2)(3, 2) , looks to the direction 33 . Move straight;
  • The doll is in the cell (3,1)(3, 1) , looks to the direction 33 . The goal is achieved, all cells of the maze without obstacles passed exactly once.
首页