#P1859. 不听话的机器人

不听话的机器人

Description

The robot receives NN commands, but it does not want to move onto an obstacle or go out of bounds, so it decides to refuse some commands. Find the minimum number of commands it must refuse.

FORWARD move forward by 1.

BACK move backward by 1.

LEFT turn left by 90 degrees.

RIGHT turn right by 90 degrees.

Initially, the robot is facing upwards.

Input Format

The first line contains M,N,X0,Y0M,N,X_0,Y_0 (M100,N1000M \le 100, N \le 1000), meaning the field size is M×MM\times M, there are NN commands in total, and the starting point is (X0,Y0)(X_0,Y_0).

Next is an M×MM\times M matrix representing the field. Here . denotes an empty cell, and * denotes an obstacle.

Then follow NN lines, each representing one command.

Output Format

Output a single integer: the minimum number of commands to refuse.

4 7 3 3
.***
..**
*..*
****
LEFT
FORWARD
LEFT
BACK
FORWARD
RIGHT
FORWARD
1

Hint

Translated by ChatGPT 5