Minesweeper

notion image
In the game Minesweeper, every cell can either be a number or a bomb. If it’s a number, it shows how many bombs are around that cell (the neighboring 8 cells - the top, bottom, left, right, and all the diagonally adjacent cells).
Given an field, it’s required to place b bombs on the field, and print the final field in the output. All the coordinates with a bomb should have a b instead of a number.
 
The first line of the input contains 2 numbers the height h and width w of the field (1 ≤ h, w ≤ 50). The second line contains the number of bombs b. Each of the next b lines contains the coordinates of the bombs (row and column, where the numbering starts from 1).
The program should output the final grid, where each cell is either a bomb annotated with a b, or one of the numbers which represent the number of adjacent bombs to that cell.
Input
Output
3 2 2 1 1 2 2
b 2 2 b 1 1
 

Constraints

Time limit: 2 seconds

Memory limit: 512 MB

Output limit: 1 MB

To check your solution you need to sign in
Sign in to continue