Codeforces Round 483 (Div. 2) [Thanks, Botan Investments and Victor Shaburov!]
B
Minesweeper
Codeforces
1100
原题
← AC →
翻译中…

One day Alex decided to remember childhood when computers were not too powerful and lots of people played only default games. Alex enjoyed playing Minesweeper that time. He imagined that he saved world from bombs planted by terrorists, but he rarely won.

翻译中…

Alex has grown up since then, so he easily wins the most difficult levels. This quickly bored him, and he thought: what if the computer gave him invalid fields in the childhood and Alex could not win because of it?

翻译中…

He needs your help to check it.

翻译中…

A Minesweeper field is a rectangle $n \times m$, where each cell is either empty, or contains a digit from $1$ to $8$, or a bomb. The field is valid if for each cell:

翻译中…
  • if there is a digit $k$ in the cell, then exactly $k$ neighboring cells have bombs.
  • if the cell is empty, then all neighboring cells have no bombs.
翻译中…

Two cells are neighbors if they have a common side or a corner (i. e. a cell has at most $8$ neighboring cells).

翻译中…

Input

翻译中…

The first line contains two integers $n$ and $m$ ($1 \le n, m \le 100$) — the sizes of the field.

翻译中…

The next $n$ lines contain the description of the field. Each line contains $m$ characters, each of them is "." (if this cell is empty), "*" (if there is bomb in this cell), or a digit from $1$ to $8$, inclusive.

翻译中…

Output

翻译中…

Print "YES", if the field is valid and "NO" otherwise.

翻译中…

You can choose the case (lower or upper) for each letter arbitrarily.

翻译中…

Note

翻译中…

In the second example the answer is "NO" because, if the positions of the bombs are preserved, the first line of the field should be *2*1.

翻译中…

You can read more about Minesweeper in Wikipedia's article.

翻译中…

样例

Input #1
3 3
111
1*1
111
Output #1
YES
InputCopy OutputCopy
Input #2
2 4
*.*.
1211
Output #2
NO
InputCopy OutputCopy
题目信息
题号
984B
时间限制
1 s
内存限制
256 MB
标签
模拟

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。