NOI Contest Archive

Archive / 2022 / April 2022

The Tractor

Medium · National Olympiad in Informatics Sri Lanka - April 2022

There is a remote controlled tractor in a field. consider the field as a grid of plots, with n rows and m columns. Some plots of the field can be cultivated and others are empty.

The tractor can move only to the empty plots within the field. The tractor can be instructed to go up, down, left or right (one plot at a time).

However due to a malfunction every instruction given is processed as follows:

There is a garage somewhere in the field and it has the tools needed to fix the tractor. Mark the plots in the field where it is possible to move the tractor to the garage within a finite number of instructions if the tractor starts in that plot.

Input Format

Output Format

After finding the empty plots that the tractor can be forced to the garage, print the field and use a plus symbol (‘+’) to indicate a plot that the tractor can be forced to the garage after some moves.

Constraints

Sample Input 0

4
3 4
....
.L..
....
1 7
...L.#.
1 1
L
4 8
...#....
.....##L
......#.
........

Sample Output 0

....
.L..
....
+++L+#.
L
...#++++
.....##L
......#+
......++