A photograph of a small meteor of an unusual shape was posted on the Internet. In that photo, the meteor is falling from a great height towards an uneven ground. There was also a photograph taken just after the meteor fell, but it is sadly lost and needs to be reconstructed.
The photograph is simplified and represented as a matrix of characters. The character X
represents
a part of the meteor, the character #
represents a part of the ground and the rest of the image
(air) consists of the characters .
.
The meteor is connected. In other words, a path exists between each two parts of the meteor that passes only through the meteor and consists of steps up, down, left and right. Also, all parts of the ground are connected in the same way.
In the given photograph, the meteor is located strictly above ground. More precisely, there is at least one row of air (dots), the meteor is completely above it and the ground is completely below it. In addition, the entire bottom row of the image is a part of the ground.
The meteor was falling vertically downward. When it fell on the ground, it kept its shape, and the same goes for the ground. Reconstruct the photograph after the meteor fall!
Input
The first line of input contains the integers and , the number of rows and the number of columns of the photograph.
The following lines contain the photograph described in the task.
Output
Output the required photograph (dimensions ) after the meteor fall.
Sample Input 1
5 6
.XXXX.
...X..
......
#..###
######
Sample Output 1
......
.XXXX.
...X..
#..###
######
Sample Input 2
9 7
XXX.XXX
X.XXX.X
X..X..X
X.....X
.......
.#...#.
.##.##.
.#####.
#######
Sample Output 2
.......
.......
.......
.......
XXX.XXX
X#XXX#X
X##X##X
X#####X
#######
Comments
Python 3 barely AC, #5: AC [0.570s<0.6s,17.55 MB<64]; PyPy 3 MLE, #5: MLE[0.210s<0.6s,74.80 MB>64]
It seems that in Python, simply creating a two-dimensional array of all of the characters in the 'photograph' uses up too much memory, even with PyPy.
Then use C++. Not all problems are solvable with Python.
Has the memory limit been extended for the problem as well?
(In re Ship and Shop comment)
This problem comes from a contest where the time and memory limits are explicitly stated (unlike past CCCs, where you could run it on your own server if you wished).
Upon further research, the official hsin.hr/coci solution is in Python and TLEs on your judge.
It doesn't matter. As long as there is at least one solution in any language that can pass, the problems and constraints are considered valid.
Not yet. There are a number of problems that would benefit from extended resource limits, though.
Hey Fatal,
Just wondering if it's possible to do this question using Java without having to time out.
No idea. The input and output are pretty large for this problem, which Java might have issues with. As you can see, COCI favors C/C++/Pascal.
But that would entail learning C++...
Hob get rekt by c++ master race