Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from collections import deque
- def check_index(matrix, bomb_row, bomb_col):
- neighbors = [
- [bomb_row - 1, bomb_col - 1],
- [bomb_row - 1, bomb_col],
- [bomb_row - 1, bomb_col + 1],
- [bomb_row, bomb_col - 1],
- [bomb_row, bomb_col + 1],
- [bomb_row + 1, bomb_col - 1],
- [bomb_row + 1, bomb_col],
- [bomb_row + 1, bomb_col + 1]
- ]
- valid = []
- for row, col in neighbors:
- if 0 <= row < len(matrix) and 0 <= col < len(matrix) and matrix[row][col] > 0:
- valid.append([row, col])
- return valid
- rows = int(input())
- matrix = []
- for _ in range(rows):
- row = [int(x) for x in input().split()]
- matrix.append(row)
- bombs = deque(input().split())
- while bombs:
- bomb_coordinates = bombs.popleft()
- bomb_row, bomb_col = [int(x) for x in bomb_coordinates.split(",")]
- bomb_value = matrix[bomb_row][bomb_col]
- if bomb_value <= 0:
- continue
- matrix[bomb_row][bomb_col] = 0
- neighbours = check_index(matrix, bomb_row, bomb_col)
- for row, col in neighbours:
- matrix[row][col] -= bomb_value
- alive_cells = 0
- sum_cells = 0
- for row_i in range(rows):
- for col_i in range(rows):
- if matrix[row_i][col_i] > 0:
- alive_cells += 1
- sum_cells += matrix[row_i][col_i]
- print(f"Alive cells: {alive_cells}")
- print(f"Sum: {sum_cells}")
- for i in range(rows):
- print(*matrix[i])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement