Problem list
Log in
#coci00705 · COCI 2025/2026 Contest 2

Minesweeper

Gold IV 5.0 s 512 MB

Marko is a regular university student who still shows up to every lecture, even though his stomach and head often ache from studying late into the night. Because he’s also a gifted student, he often finds the lectures boring, so instead of listening he plays his favorite game, Minesweeper. Eventually, even that got boring, so he decided to create his own version of the game. In Marko’s version of Minesweeper, he starts the game already knowing the positions of all $k$ bombs on a board with $n$ rows and $m$ columns. Each cell can contain at most one bomb. His task is to fill every non-bomb cell with the number of bombs in the eight surrounding cells. Cells that contain bombs are marked with "B". Your task is to output the matrix generated according to Marko’s rules.

Input

In the first line are the natural numbers $n$, $m$ and $k$ ($1 \le n$, $m \le 500$, $1 \le k \le n \cdot m$), the numbers from the problem statement. In each of the following $k$ lines are the numbers $r_{i}$ and $s_{i}$ ($1 \le r_{i} \le n$, $1 \le s_{i} \le m$), the row and column in which one of the bombs is located. Izlazni podaci In $n$ rows, output $m$ characters separated by a space, the matrix produced according to the rules of Marko’s game. Scoring Subtask Points Constraints 1 15 $n = 1$ 2 18 $k = 1$ 3 17 No additional constraints.

Example 1

Input
1 6 1
1 3
Output
0 1 B 1 0 0

Example 2

Input
3 3 3
1 1
2 3
1 3
Output
B 3 B
1 3 B
0 1 1

Clarification of the first example: In the cell in the 3rd column there is a bomb (the letter "B"). The cells of the matrix in the 2nd and 4th columns (marked with the number 1) are adjacent to it.

Source
COCI 2025/2026 Contest 2
Appears in
Not part of a ladder, contest or set yet.
Accepted 0 Submissions 0 Acceptance 0% Solvers 0

Discussion

Threads about this problem. Spoilers are collapsed; wrap hints in ||double bars||.

No discussion yet. Start a thread if something here needs explaining.

Recent submissions Open with filters
Code