Advertisement
Kamend1

08. Bombs

Jan 16th, 2024
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.01 KB | None | 0 0
  1. from collections import deque
  2.  
  3. size = int(input())
  4. matrix = [[int(x) for x in input().split()] for _ in range(size)]
  5. coordinates = deque(input().split())
  6.  
  7. while coordinates:
  8.     current_bomb = coordinates.popleft()
  9.     current_row = int(current_bomb[0])
  10.     current_col = int(current_bomb[2])
  11.     current_damage = matrix[current_row][current_col]
  12.     row = current_row - 1
  13.     col = current_col - 1
  14.     for i in range(3):
  15.         for j in range(3):
  16.             if 0 <= row < size and 0 <= col < size and matrix[row][col] > 0:
  17.                 matrix[row][col] -= current_damage
  18.                 col += 1
  19.             else:
  20.                 col += 1
  21.         row += 1
  22.         col = current_col - 1
  23.  
  24. number_alive = 0
  25. sum_alive = 0
  26.  
  27. for row in range(size):
  28.     for col in range(size):
  29.         if matrix[row][col] > 0:
  30.             number_alive += 1
  31.             sum_alive += matrix[row][col]
  32.  
  33. print(
  34.     f"Alive cells: {number_alive}\n"
  35.     f"Sum: {sum_alive}"
  36. )
  37.  
  38. for list in matrix:
  39.     print(*list)
  40.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement