1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
| import sys
input = sys.stdin.readline
R, C, N = map(int, input().split())
board = list()
char2id = lambda x: 0 if x == '.' else 1
id2char = lambda x: '.' if x == 0 else 'O'
for _ in range(R):
board.append(list(map(char2id, input().strip())))
board = [[state+1 if state > 0 else 0 for state in row] for row in board]
for s in range(2,N+1):
board = [[state+1 for state in row] for row in board]
bomb = set()
for i in range(R):
for j in range(C):
if board[i][j] > 3:
neighbor = [(0,0),(1,0),(-1,0),(0,1),(0,-1)]
[bomb.add((i+dy,j+dx)) for dy,dx in neighbor]
for i,j in bomb:
if 0 <= i < R and 0 <= j < C:
board[i][j] = 0
for row in board:
print(''.join(list(map(id2char, row))))
|