CF984B.Minesweeper

普及-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

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×mn \times m, where each cell is either empty, or contains a digit from 11 to 88, or a bomb. The field is valid if for each cell:

  • if there is a digit kk in the cell, then exactly kk 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 88 neighboring cells).

有一天,Alex 决定回忆童年时光——那时计算机性能还不太强大,许多人只玩系统自带的默认游戏。Alex 当时很喜欢玩扫雷游戏。他想象自己正在拯救世界,拆除恐怖分子埋设的炸弹,但很少获胜。

自那以后,Alex 已经长大,如今他能轻松通关最难的关卡。这很快让他感到厌烦,于是他想:如果童年时电脑给他生成的是无效的棋盘,而 Alex 当时无法获胜,会不会正是因为这个原因呢?

他需要你的帮助来验证这一点。

扫雷棋盘是一个 n×mn \times m 的矩形,其中每个格子要么为空,要么包含一个从 11 到 88 的数字,要么是一颗地雷。当且仅当满足以下条件时,该棋盘是有效的:

  • 若某格子中有一个数字 kk,则其恰好有 kk 个相邻格子含有地雷;
  • 若某格子为空,则其所有相邻格子均不含地雷。

两个格子被称为相邻,当且仅当它们有一条公共边或一个公共角(即:一个格子最多有 88 个相邻格子)。

输入格式

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

The next nn lines contain the description of the field. Each line contains mm characters, each of them is "." (if this cell is empty), "*" (if there is bomb in this cell), or a digit from 11 to 88, inclusive.

第一行包含两个整数 nn 和 mm(1≤n,m≤1001 \le n, m \le 100)—— 表示场地的尺寸。

接下来的 nn 行描述该场地。每行包含 mm 个字符,每个字符为:.(表示该格子为空)、*(表示该格子中有一颗炸弹),或一个从 11 到 88(含)的数字。

输出格式

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

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

如果该字段有效,则输出 "YES",否则输出 "NO"。

对于每个字母,你可以任意选择其大小写(小写或大写)。

输入输出样例

  • 输入#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 Wikipedia's article.

在第二个例子中,答案为“NO”,因为如果炸弹的位置保持不变,则场地的第一行应为 *2*1。

您可以在 维基百科的文章 中了解有关扫雷游戏的更多信息。

输入解题思路,AI测评打分。不知道怎么写?

首页