atcoder#ABC285G. [ABC285G] Tatami
[ABC285G] Tatami
Score : points
Problem Statement
We have a grid with horizontal rows and vertical columns. We denote by square the square at the -th row from the top and -th column from the left.
We want to cover this grid with tiles and 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 is .
A square with 1
written on it must be covered by a tile, and a square with 2
by a tile. A square with ?
may be covered by any kind of tile.
Determine if there is such a placement of tiles.
Constraints
- and are integers.
- is one of
1
,2
, and?
.
Input
The input is given from Standard Input in the following format:
Output
Print Yes
if there is a placement of tiles to satisfy the conditions in the Problem Statement; print No
otherwise.
3 4
2221
?1??
2?21
Yes
For example, the following placement satisfies the conditions.
3 4
2?21
??1?
2?21
No
There is no placement that satisfies the conditions.
5 5
11111
11111
11211
11111
11111
No