#P10498. 石头游戏

石头游戏

Problem Description

The stone game is played on a grid with nn rows and mm columns. Each cell corresponds to an operation sequence. There are at most 1010 kinds of operation sequences, denoted by the digits 090 \sim 9.

An operation sequence is a string of length at most 66 that repeats in a cycle, executing one character per second.

Every second, all cells execute the next character in their own operation sequence at the same time.

Each character in a sequence is one of the following:

  1. A digit 090 \sim 9: move 090 \sim 9 stones into this cell.
  2. NWSE: push all stones in this cell to an adjacent cell. N means up, W means left, S means down, and E means right. If the operation is invalid (i.e., the stones would be pushed out of the grid), then the stones disappear.
  3. D: remove all stones from this cell.

You are given the string for each operation sequence, and for each cell in the grid, which operation sequence it uses. Find, after tt seconds, how many stones are in the cell that has the most stones.

At the start of the game, the grid is empty.

Input Format

The first line contains 44 integers n,m,t,actn, m, t, act.

The next nn lines each contain mm characters, indicating the operation sequence used by each cell.

The last actact lines each contain one string, describing each operation sequence starting from 00.

Output Format

Output one integer: after tt seconds, the maximum number of stones among all cells.

1 6 10 3
011112
1E
E
0
3

Hint

For all testdata, 1m,n81 \le m, n \le 8, 1t1081 \le t \le 10^8, 1act101 \le act \le 10.

Translated by ChatGPT 5