#P6226. [BalticOI 2019] 潜艇 / Nautilus
[BalticOI 2019] 潜艇 / Nautilus
Description
A submarine is secretly traveling in the ocean.
The ocean is an grid, where # represents an island and . represents water. The submarine can travel only in water.
Every minute, the submarine sends a radio signal that indicates the direction it will move. Directions are represented by the following letters: North (N), East (E), South (S), West (W).
Now the eavesdropper has set up a radar to intercept the submarine’s signals. During the last minutes, the radar collected signals, represented by a string of length , for example WS?EE??. Some collected signals cannot be decoded and are represented by ?.
The eavesdropper does not know the submarine’s initial position, but wants to use the map to determine the submarine’s current position. Please help compute how many possible current positions the submarine may be in.
Input Format
The first line contains three integers .
The next lines each contain characters describing the sea map.
The last line is a string of length , representing the intercepted signals. It is guaranteed that the string contains only N, E, S, W, ?.
Output Format
Output one integer: the number of possible current positions of the submarine.
5 9 7
...##....
..#.##..#
..#....##
.##...#..
....#....
WS?EE??
22
Hint
The scores and Constraints for each subtask are as follows:
- Subtask 1 (29 points): , and there is no
?in the intercepted signals. - Subtask 2 (37 points): .
- Subtask 3 (34 points): , .
Translated by ChatGPT 5
京公网安备 11011102002149号