#abc285g. G - Tatami

G - Tatami

Score : 600600 points

问题描述

我们有一个具有 HH 行(水平)和 WW 列(垂直)的网格。我们用格子 (i,j)(i,j) 表示从上数第 ii 行、从左数第 jj 列的格子。

我们希望使用 1×11 \times 1 的瓷砖和 1×21 \times 2 的瓷砖覆盖这个网格,使得没有瓷砖重叠且每个位置都被至少一块瓷砖覆盖。(瓷砖可以旋转摆放。)

每个格子上写有数字 12 或者 ?,其中格子 (i,j)(i, j) 上所写的字符为 ci,jc_{i,j}

  • 写有数字 1 的格子必须被一块 1×11 \times 1 的瓷砖覆盖;
  • 写有数字 2 的格子必须被一块 1×21 \times 2 的瓷砖覆盖;
  • 写有 ? 的格子可以用任意类型的瓷砖进行覆盖。

请确定是否存在这样的瓷砖放置方案。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

We have a grid with HH horizontal rows and WW vertical columns. We denote by square (i,j)(i,j) the square at the ii-th row from the top and jj-th column from the left.

We want to cover this grid with 1×11 \times 1 tiles and 1×21 \times 2 tiles so that no tiles overlap and everywhere is covered by a tile. (A tile can be rotated.)

Each square has 1, 2, or ? written on it. The character written on square (i,j)(i, j) is ci,jc_{i,j}.
A square with 1 written on it must be covered by a 1×11 \times 1 tile, and a square with 2 by a 1×21 \times 2 tile. A square with ? may be covered by any kind of tile.

Determine if there is such a placement of tiles.

Constraints

  • 1H,W3001 \leq H,W \leq 300
  • HH and WW are integers.
  • ci,jc_{i,j} is one of 1, 2, and ?.

Input

The input is given from Standard Input in the following format:

HH WW

c1,1c1,2c1,Wc_{1,1}c_{1,2}\ldots c_{1,W}

\vdots

cH,1cH,2cH,Wc_{H,1}c_{H,2}\ldots c_{H,W}

Output

Print Yes if there is a placement of tiles to satisfy the conditions in the Problem Statement; print No otherwise.

Sample Input 1

3 4
2221
?1??
2?21

Sample Output 1

Yes

For example, the following placement satisfies the conditions.

Sample Input 2

3 4
2?21
??1?
2?21

Sample Output 2

No

There is no placement that satisfies the conditions.

Sample Input 3

5 5
11111
11111
11211
11111
11111

Sample Output 3

No

update @ 2024/3/10 11:56:30

}