Minesweeper
InterviewTime limit4sMemory limit1024 MB
Given a solved Minesweeper board, check that every digit equals the number of flagged squares next to it.
- Level
Easy2 of 10
- Topics
- Matrix, Implementation, Simulation
- Solved
- No attempts yet
Statement
Minesweeper is a single-player computer game. The objective of the game is to clear an abstract minefield without detonating a mine. When the game starts, the player is presented with a grid of blank squares. If the player clicks a square without a mine, a digit is revealed in that square. The digit is the number of adjacent squares that contain mines. Two squares are adjacent if they share an edge or a corner, so a square can have at most 8 adjacent squares. Using logic, players can often deduce that certain other squares are mine-free or mine-filled. They then click more squares to clear them, or mark them with flag graphics to show a mine.

Clark Kent is a Minesweeper addict. With help from his Kryptonian powers, he solves them at lightning speed and gives them to you. Your job is to tell him whether the solved version is correct. A board is correctly solved if and only if every flagged square contains a mine, and every square containing a number X has exactly X adjacent flagged squares.
Input
The first line contains an integer , the number of test cases.
Each test case is formatted as follows.
- The first line contains two integers and separated by a single space, where and .
- The next lines contain characters each. Each character is a digit from 0 to 8 or 'F'. 'F' means Clark flagged the square. A digit is the number of mines in the adjacent squares.
Output
Output one line per test case.
- Output 'Well done Clark!' if the board was solved successfully.
- Output 'Please sweep the mine again!' otherwise.