#P17328. [ICPC 2018 Nanjing R] Kangaroo Puzzle

    ID: 19670 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 显示难度普及+/提高− 上传者: 标签>搜索2018Special Judge随机化ICPC南京

[ICPC 2018 Nanjing R] Kangaroo Puzzle

Problem Description

Your friend has made a computer video game called "Kangaroo Puzzle" and wants you to give it a try for him. As the name of this game indicates, there are some (at least 2) kangaroos stranded in a puzzle and the player's goal is to control them to gather. As long as all the kangaroos in the puzzle get together, they can escape the puzzle by the miraculous power of kangaroos.

The puzzle is a n×mn \times m grid consisting of nmnm cells. There are walls in some cells and the kangaroos cannot enter these cells. The other cells are empty. The kangaroos can move in the following direction: up, down, left and right. It is guaranteed that one kangaroo can move from an empty cell to any other. It is also guaranteed that there is no cycle in the puzzle \text{---} that is, it's impossible that one kangaroo can move from an empty cell, pass by several distinct empty cells, and then back to the original cell.

There is exactly one kangaroo in every empty cell at the beginning. You can control the kangaroos by pressing the button U,D,L,R\texttt{U}, \texttt{D}, \texttt{L}, \texttt{R} on your keyboard. The kangaroos will move simultaneously according to the button you press. For instance, if you press the button U\texttt{U}, a kangaroo would move to the upper cell if it exists and is empty; otherwise, the kangaroo will stay still. You can press the buttons for at most 5000050000 times. If there are still two kangaroos standing in different cells after 5000050000 steps, you will lose the game.

Input Format

The first line contains two integers, nn and mm (1n,m201 \leq n,m \leq 20), the height and the width of the puzzle, respectively. Each of the next nn lines contains a (0,1\texttt{0,1})-string of length mm, representing the puzzle. If the jj-th character of the i+1i+1-th line is 1\texttt{1}, then the cell at the ii-th row and the jj-th column is empty;otherwise (i.e. it is 0\texttt{0}), the corresponding cell is blocked and cannot be entered.

Output Format

Print a string consisting of U,D,L,R\texttt{U}, \texttt{D}, \texttt{L}, \texttt{R}, such that all kangaroos will get together after pressing the buttons in the order of this string. The length of the string should not exceed 5000050000. There are many possible valid answers, so just print any of them.

4 4
1111
1001
1001
1110
LLUUURRRDD
2 15
111111111111111
101010101010101
ULLLLLLLLLLLLLL