Distribution Center

시간 제한4초메모리 제한2048 MB

요약
밀어서 목적지에 도달할 수 없는 모든 칸을 표시한다. 미는 사람은 어디에든 있을 수 있다고 가정한다.
난이도

어려움10점 중 8점

유형
BFS, 그래프, 구현, 행렬
정답자
아직 제출이 없습니다

문제

Sokoban is the best employee at your town's biggest distribution center. He likes his job because it is simple, albeit a bit physically intensive. Everyday he is pushing crates to some possbile destinations from where they will be loaded in trucks. Unfortunately, Sokoban's youth is behind him, so he starts to feel the effects of the physical labour. Therfore, he came up with an algorithm to help him move the crates optimally: the Fast Pushing Crates (FPC) algorithm. For the algorithm to be complete, he needs a bit of help from you.

His algorithm receives as input the layout of the distribution center, as a grid, and returns the steps he needs to take to efficiently push the crates. In his algorithm, he needs to find out which squares in the grid are dead squares. We call a square a dead square if it is a wall or if it is impossible to push a crate from that square to any of the destinations (even if Sokoban could teleport to any location).

Given the layout of the distribution center, help Sokoban find out which squares are dead squares.

입력

The input consists of:

  • A line with two integers rr and cc (1≤r,c≤1031\leq r,c\leq 10^3), the number of rows and columns of the grid.

  • rr lines, each containing cc characters, where:

    • A '\#' represents a wall. It is guaranteed that the grid is surrounded by walls.
    • A 'D' represents a destination. There can be any number of them, including 00.
    • A '.' represents an empty square.

출력

Output rr lines, each containing cc characters, where the iith character of the jjth line is:

  • 'X' if the square at position (i,j)(i,j) is a dead square.
  • 'O' otherwise.

예제2

  1. 예제 1

    입력
    7 7
    #######
    #.....#
    #.....#
    #..D..#
    #.....#
    #.....#
    #######
    
    예상 출력
    XXXXXXX
    XXXXXXX
    XXOOOXX
    XXOOOXX
    XXOOOXX
    XXXXXXX
    XXXXXXX
    
  2. 예제 2

    입력
    8 8
    ########
    #..#D###
    #..#.###
    #..#.###
    #..#...#
    #..#.###
    #D.#.###
    ########
    
    예상 출력
    XXXXXXXX
    XXXXOXXX
    XOXXOXXX
    XOXXOXXX
    XOXXOOXX
    XOXXOXXX
    XOXXXXXX
    XXXXXXXX