20.51m
import sys
input = sys.stdin.readline
r, s = list(map(int, input().rstrip().split()))
pic = [list(input().rstrip()) for _ in range(r)]
res = [p[:] for p in pic]
min_dist = sys.maxsize
for j in range(s):
start = r - 1
for i in range(r - 2, -1, -1):
if pic[i][j] == '#':
start = i
elif pic[i][j] == 'X':
min_dist = min(min_dist, start - i - 1)
break
for i in range(r - 1, -1, -1):
for j in range(s - 1, -1, -1):
if pic[i][j] == 'X':
res[i + min_dist][j] = 'X'
res[i][j] = '.'
for r in res:
print(*r, sep='')
간단한 시뮬레이션 문제였다! 마지막에 탐색할때 반대로 가는게 키포인트였던것같당