15078 - Mice Bombing   

Description

Elfnt's home has been invaded by mice. So he decides to BOMB THEM ALL!

You are given an grid. Each cell shows the number of mice in it. A cell with is an obstacle.

Bombs have a strength , which starts at . A bomb hits the cell it lands on. Its shockwave then spreads up to cells in each of its directions. In each direction, the shockwave stops at an obstacle or at the edge of the grid, and obstacles are never hit.

For every cell that is hit, including the bomb's own cell, the number of mice decreases by . The number of mice cannot go below .

Process commands in the given order. There are 3 types of commands:

  • + i j k: Drop a cross bomb at . Its shockwave spreads up, down, left and right, and each cell it hits loses mice.
  • X i j k: Drop an X bomb at . Its shockwave spreads in the four diagonal directions, and each cell it hits loses mice.
  • Set s: Set .

Print the final grid.

Rule visualized:

Template

# Input (Read the commands by yourself)
n, m = map(int, input().split())
mp = []
for _ in range(n):
    mp.append(list(map(int, input().split())))
q = int(input())

# Implement here


# Output
for row in mp:
    print(*row)

Input

The first line contains and .

Each of the next lines contains integers describing one row of the grid.

The next line contains .

Each of the next lines contains one command.

Rows and columns are 0-indexed. means row , column , and is the top-left cell.

Constraints

  • Each cell is or an integer from to .
  • ,
  • No bomb is dropped on an obstacle.

Subtasks

  • Test cases 1–2: No obstacles, no Set commands, and no X bombs.
  • Test cases 3–4: No obstacles and no X bombs.
  • Test cases 5–6: No obstacles.
  • Test cases 7–10: No additional constraints.

Output

Print lines with integers each, and print obstacles as .

Separate the integers with single spaces. Do not print trailing spaces. End every line with a newline, including the last.

The template above already reads the input and prints the output in this format.

Sample Input 1  Download

Sample Output 1  Download

Sample Input 2  Download

Sample Output 2  Download

Sample Input 3  Download

Sample Output 3  Download

Sample Input  Download

Sample Output  Download

Tags




Discuss