Logo
(追記) (追記ここまで)

13734번 - Buggy Robot 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 512 MB149494531.915%

문제

There is a robot in a 2D grid. The grid consists of obstacles, and there is exactly one cell that is the exit. The robot will exit the grid if it ever reaches the exit cell. Empty cells are denoted as '.', the robot's initial position is denoted as 'R', obstacles are denoted as '#', and the exit is denoted as 'E'.

You can program the robot by sending it a series of commands. The series of commands is a string consisting of characters 'L' (move one square left), 'U' (move one square up), 'R' (move one square right), or 'D' (move one square down). If the robot would run into an obstacle or off the edge of the grid, it will ignore the command (but it will continue onto future commands, if there are any).

Your friend sent a series of commands to the robot, but unfortunately, the commands do not necessarily take the robot to the exit.

You would like to fix the string so that the robot will touch the exit square. (Note: once the robot reaches the exit, it stops, even if there are more commands in the string.)

You can fix the string with a sequence of operations. There are two operations: inserting a command or deleting a command. What is the minimum number of operations you would need to fix the program?

입력

The first line of the input contains the two integers $N$ and $M,ドル 1ドル \le N, M \le 50,ドル which are the width and height of the grid.

The next $N$ lines will contain a string of exactly $M$ characters, each of which is '.' (empty), 'R' (the robot), '#' (an obstacle), or 'E', the exit. There will be exactly one 'R' and one 'E' in the grid, and it will always be possible to navigate the robot to the exit.

The last line contains a string $s$ (1ドル \leq |s| \leq 50$) of commands. The string $s$ will consist only of 'L', 'R', 'U', and 'D'.

출력

Print one line containing the single integer indicating the minimum number of operations necessary to fix the command string so that the robot makes it to the exit.

제한

예제 입력 1

3 3
S..
.#.
..G
DRRDD

예제 출력 1

1

예제 입력 2

3 7
.......
.G.#.S.
.......
LDLDLLDR

예제 출력 2

1

예제 입력 3

3 7
.#.....
.G.##S.
.......
LDLDLLDR

예제 출력 3

2

예제 입력 4

2 4
S.#.
#..G
RRUUDDRRUUUU

예제 출력 4

0

힌트

출처

ICPC > Regionals > North America > Mid-Central Regional > 2016 Mid-Central Regional Programming Contest D번

ICPC > Regionals > North America > Southeast USA Regional > 2016 Southeast USA Regional Programming Contest > Division 1 C번

ICPC > Regionals > North America > Southeast USA Regional > 2016 Southeast USA Regional Programming Contest > Division 2 B번

ICPC > Regionals > North America > Pacific Northwest Regional > 2016 Pacific Northwest Region Programming Contest > Division 1 B번

ICPC > Regionals > North America > Pacific Northwest Regional > 2016 Pacific Northwest Region Programming Contest > Division 2 O번

ICPC > Regionals > North America > Mid-Atlantic Regional > 2016 Mid-Atlantic Regional Programming Contest C번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /