A11840 | Minesweeper
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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).
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).
输入格式
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.
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.
输出格式
Print "YES", if the field is valid and "NO" otherwise.
You can choose the case (lower or upper) for each letter arbitrarily.
You can choose the case (lower or upper) for each letter arbitrarily.
输入输出样例
输入 #1
3 3 111 1*1 111
输出 #1
YES
输入 #2
2 4 *.*. 1211
输出 #2
NO
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 <a>Wikipedia's article</a>.
You can read more about Minesweeper in <a>Wikipedia's article</a>.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted