Good Bye 2017
B
New Year and Buggy Bot
Codeforces
1200
原题
← AC →
翻译中…

Bob programmed a robot to navigate through a 2d maze.

翻译中…

The maze has some obstacles. Empty cells are denoted by the character '.', where obstacles are denoted by '#'.

翻译中…

There is a single robot in the maze. Its start position is denoted with the character 'S'. This position has no obstacle in it. There is also a single exit in the maze. Its position is denoted with the character 'E'. This position has no obstacle in it.

翻译中…

The robot can only move up, left, right, or down.

翻译中…

When Bob programmed the robot, he wrote down a string of digits consisting of the digits 0 to 3, inclusive. He intended for each digit to correspond to a distinct direction, and the robot would follow the directions in order to reach the exit. Unfortunately, he forgot to actually assign the directions to digits.

翻译中…

The robot will choose some random mapping of digits to distinct directions. The robot will map distinct digits to distinct directions. The robot will then follow the instructions according to the given string in order and chosen mapping. If an instruction would lead the robot to go off the edge of the maze or hit an obstacle, the robot will crash and break down. If the robot reaches the exit at any point, then the robot will stop following any further instructions.

翻译中…

Bob is having trouble debugging his robot, so he would like to determine the number of mappings of digits to directions that would lead the robot to the exit.

翻译中…

Input

翻译中…

The first line of input will contain two integers $*n*$ and $*m*$ ($2 ≤ *n*, *m* ≤ 50$), denoting the dimensions of the maze.

翻译中…

The next $*n*$ lines will contain exactly $*m*$ characters each, denoting the maze.

翻译中…

Each character of the maze will be '.', '#', 'S', or 'E'.

翻译中…

There will be exactly one 'S' and exactly one 'E' in the maze.

翻译中…

The last line will contain a single string $*s*$ ($1 ≤ |*s*| ≤ 100$) — the instructions given to the robot. Each character of $*s*$ is a digit from 0 to 3.

翻译中…

Output

翻译中…

Print a single integer, the number of mappings of digits to directions that will lead the robot to the exit.

翻译中…

Note

翻译中…

For the first sample, the only valid mapping is image, where $*D*$ is down, $*L*$ is left, $*U*$ is up, $*R*$ is right.

翻译中…

样例

Input #1
5 6
.....#
S....#
.#....
.#....
...E..
333300012
Output #1
1
InputCopy OutputCopy
Input #2
6 6
......
......
..SE..
......
......
......
01232123212302123021
Output #2
14
InputCopy OutputCopy
Input #3
5 3
...
.S.
###
.E.
...
3
Output #3
0
InputCopy OutputCopy
题目信息
题号
908B
所属比赛
时间限制
1 s
内存限制
256 MB
标签
暴力
模拟

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。