Minesweeper

면접 대비

시간 제한4초메모리 제한1024 MB

요약
해결된 지뢰찾기 보드가 올바른지 판정한다. 깃발 칸은 모두 지뢰여야 하고, 각 숫자는 인접한 깃발 칸 수와 일치해야 한다.
난이도

쉬움10점 중 3점

유형
행렬, 구현, 시뮬레이션
정답자
아직 제출이 없습니다

문제

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 is started, the player is presented with a grid of n x m blank squares. If the player clicks on a square without a mine, a digit is revealed in that square, the digit indicating the number of adjacent squares that contains mines. Two squares are adjacent if they share an edge or a corner, i. e. a square can have at most 8 adjacent squares. By using logic, players can in many instances use this information to deduce that certain other squares are mine-free (or mine-filled), and proceed to click on additional squares to clear them or mark them with flag graphics to indicate the presence of a mine.

Clark Kent is a Minesweeper addict. And with help from his Kryptonian (a planet far far away from earth) powers he solves them at lightning speed and gives them to you. Your job is to tell him whether the solved version is correct or not. A board is correctly solved iff all flagged squares should contain a mine and every square containing a number X has exactly X adjacent squares flagged.

입력

The first line of input will contain an integer T ≤ 20 denoting the number of test cases.

Each test case will be formatted as follows:-

  • The first line will contain two integers separated by a single space denoting 1≤n≤20 and 1 ≤ m≤20 respectively.
  • The next n lines will contain m characters each. Each character will either be a digit (0 to 8 inclusive) or 'F'. The presence of 'F' indicates that Clark has flagged the square. The digits indicate the number of mines in the adjacent squares.

출력

Output one line per case:-

  • 'Well done Clark!' if the board was solved successfully.
  • 'Please sweep the mine again!' otherwise.

Note that quotes are for clarity only.

예제1

  1. 예제 1

    입력
    2
    8 8
    F1012210
    1101FF21
    121234F1
    F2F11F21
    12111121
    1100012F
    F21101F2
    12F10111
    8 8
    F1012210
    1101FF21
    121234F1
    F2FF1F21
    12111121
    1100012F
    F21101F2
    12F10111
    
    예상 출력
    Well done Clark!
    Please sweep the mine again!