Robot

아직 제출이 없습니다시간 제한1초메모리 제한512 MB

문제

There is a robot which is placed on a field modeled as a n ×mn \times m grid. Some of these grid cells are walls.

The robot accepts 4 types of instructions: up, down, left, right.

Suppose the robot is currently at the coordinate (x,y)(x, y). Then the effect of executing the instructions will be as follows:

  • up : If x=0x = 0 or (x1,y)(x - 1, y) is a wall, the robot does not move. Else, the robot moves to (x1,y)(x - 1, y)
  • down : If x=n1x = n - 1 or (x+1,y)(x + 1, y) is a wall, the robot does not move. Else, the robot moves to (x+1,y)(x + 1, y)
  • left : If y=0y = 0 or (x,y1)(x, y - 1) is a wall, the robot does not move. Else the robot moves to (x,y1)(x, y - 1)
  • right: If y=m1y = m - 1 or (x,y+1)(x, y + 1) is a wall, the robot does not move. Else the robot moves to (x,y+1)(x, y + 1).

You know that the starting position of the robot is either (a,b)(a, b) or (c,d)(c, d). Find a sequence of at most q instructions such that the robot always ends up at (0,0)(0, 0) when the robot starts from either (a,b)(a, b) or (c,d)(c, d). It can be proven that there exists a solution for all inputs satisfying the problem constraint.

제한

  • 1 n101 \le n \le 10
  • 1m101 \le m \le 10
  • 0an 10 \le a \le n - 1
  • 0bm10 \le b \le m - 1
  • 0cn10 \le c \le n - 1
  • 0dm10 \le d \le m - 1
  • g\[0]\[0]=g\[a]\[b]=g\[c]\[d]=0g\[0]\[0] = g\[a]\[b] = g\[c]\[d] = 0
  • There exists a finite sequence of instructions to move the robot from (a,b)(a, b) to (0,0)(0, 0)
  • There exists a finite sequence of instructions to move the robot from (c,d)(c, d) to (0,0)(0, 0)
  • q=700q = 700