아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Chairs

시간 제한1초메모리 제한1024 MB

요약
좌상단에서 우하단까지 최단 경로 중 모든 의자 칸을 지나는 경로를 찾고, 불가능하면 Impossible을 출력하며 가능하면 사전순으로 가장 작은 이동 문자열을 출력한다.
난이도

보통10점 중 7점

유형
BFS, 최단 경로, 구현
정답자
아직 제출이 없습니다

문제

Ostap and Kisa found themselves at a chair sale. They are facing two problems. First, they must leave the sale as soon as possible, because their rival company, represented by father Theodore, is breathing down their necks; second, they must get all chairs at the sale.

The sale site is a rectangular table of NN rows and MM columns, with some of its cells occupied by chairs that need to be collected. Initially our enterpreneurs are in the top-left corner --- the cell with the coordinates (1,1)(1, 1), and the exit is located in the bottom-right corner --- the cell with the coordinates (N,M)(N, M). A single move can transfer them from a given sell to any of adjacent by a side cells. Passing through a cell with a chair, they take the chair with them. Find a shortest path from the starting to the ending cell. Among all such paths, find one passing through all cells with chairs, or find out if such a path doesn't exist.

입력

The first line contains three integers: NN, MM, KK --- size of the table and the number of chairs, respectively (2≤N,M≤1002 \le N, M \le 100, 0≤K≤10000 \le K \le 1000).

The following KK lines of the input data each contain two integers: X_iX\_i --- the number of the row in which the ii-th chair is located, and Y_iY\_i --- the number of the column in which the ii-th chair is located (1≤X_i≤N1 \le X\_i \le N, 1≤Y_i≤M1 \le Y\_i \le M). A single cell cannot contain multiple chairs.

출력

If collecting all chairs along any single shortest path is impossible, print a single word <<Impossible>> (without brackets) in the output file.

If such a path exists, print it as a line containing the sequence of moves, with each move coded by a single symbol according to the following:

  • R --- move right;
  • D --- move down;

If several solutions are possible, print the lexicographically smallest solution.

예제2

  1. 예제 1

    입력
    3 3 2
    1 2
    3 3
    
    예상 출력
    RDDR
    
  2. 예제 2

    입력
    3 3 2
    1 2
    2 1
    
    예상 출력
    Impossible