Problem D
John Dillermand
For most episodes, this task has been adequately performed by training your university’s machine-learned information curation algorithms to remove red and white pixels from individual frames. However, the Christmas episode S1E11, John redder julen, needs more attention. Many of the scenes involve candy canes, Danish flags, and other Christmas decorations that must be kept for narrative cohesion.
![\includegraphics[width=.25\textwidth ]{img/sample1.jpg}](/problems/johndillermand/file/statement/en/img-0002.jpg)
It turns out that removing only John Dillermand’s eponymous protuberance from these frames requires a lot more delicacy than what deep learning can provide. Instead of editing every frame manually, you decide to write a plug-in to the image processing software that automates this task.
Input
The input represents a single image of the episode, called a frame. On the first line, the frame’s dimensions as two space-separated integers $h$ and $w$. Then follow $h$ lines of $w$ symbols, each representing a pixel, with “#” meaning red, “O” meaning white, and “.” meaning anything else. The top left corner is guaranteed to be either white or red and is an endpoint of John’s appendage. The appendage is one pixel wide, alternates between red and white neighbouring pixels, and does neither touch nor intersect itself, nor does it touch other red or white pixels in the frame. Two pixels are considered touching if they share a horizontal or vertical side.
Output
Print $h$ lines of $w$ symbols: The improved frame, where the pixels that make up John’s appendage have been replaced by “.”. No other pixels may be changed.
| Sample Input 1 | Sample Output 1 |
|---|---|
20 20 O.#O#O#O#O#O........ #...........#....... O...........O....... #.........O#........ O................... #O#O#O#......#...... ......O......#...... ......#....#.#.#.... ......O...#######... ...O#O#...#O#O#O#... ...#.......#O#O#.... ...O#O......#O#..... .....#O#.....#...... ................O#.. ...............#..O. .##O####..........#. .##O####.........O.. .OOOOOOO........#... .##O####.......O.... .##O####......#..... |
..#O#O#O#O#O........ ............#....... ............O....... ..........O#........ .................... .............#...... .............#...... ...........#.#.#.... ..........#######... ..........#O#O#O#... ...........#O#O#.... ............#O#..... .............#...... ................O#.. ...............#..O. .##O####..........#. .##O####.........O.. .OOOOOOO........#... .##O####.......O.... .##O####......#..... |
| Sample Input 2 | Sample Output 2 |
|---|---|
4 5 #.... O.... ...#O ...O# |
..... ..... ...#O ...O# |
| Sample Input 3 | Sample Output 3 |
|---|---|
2 2 #. .O |
.. .O |
| Sample Input 4 | Sample Output 4 |
|---|---|
2 2 #. O# |
.. .. |
| Sample Input 5 | Sample Output 5 |
|---|---|
1 1 O |
. |
