QOJ.ac

QOJ

Limite de temps : 5.0 s Limite de mémoire : 256 MB Points totaux : 100

#13144. 在网格中查找字符串

Statistiques

你有一个包含 $R$ 行(从上到下编号为 $1$ 到 $R$)和 $C$ 列(从左到右编号为 $1$ 到 $C$)的大写字符网格 $G$。第 $r$ 行第 $c$ 列的字符记为 $G_{r,c}$。你还有 $Q$ 个包含大写字符的字符串。对于每个字符串,你需要找出该字符串在网格中出现的次数。

如果字符串 $S$ 可以通过从网格中的某个单元格开始,向右移动 $0$ 次或多次,然后向下移动 $0$ 次或多次来构造,则称其为网格中出现了一次。如果构造字符串所使用的单元格集合不同,则视为两次不同的出现。形式化地,对于每个字符串 $S$,你想要计算满足以下条件的元组 $\langle r, c, \Delta r, \Delta c \rangle$ 的数量:

  • $1 \le r \le R$ 且 $r \le r + \Delta r \le R$
  • $1 \le c \le C$ 且 $c \le c + \Delta c \le C$
  • $S = G_{r,c}G_{r,c+1} \dots G_{r,c+\Delta c}G_{r+1,c+\Delta c} \dots G_{r+\Delta r,c+\Delta c}$

输入格式

输入的第一行包含三个整数:$R, C, Q$ ($1 \le R, C \le 500; 1 \le Q \le 200\,000$),分别表示网格的大小和字符串的数量。接下来的 $R$ 行,每行包含 $C$ 个大写字符,表示网格。第 $r$ 行的第 $c$ 个字符为 $G_{r,c}$。接下来的 $Q$ 行,每行包含一个由大写字符组成的字符串 $S$。字符串的长度为不超过 $200\,000$ 的正整数。所有 $Q$ 个字符串的长度之和不超过 $200\,000$。

输出格式

对于每个查询,按照输入顺序,输出一行一个整数,表示该字符串在网格中出现的次数。

样例

样例输入 1

3 3 5
ABC
BCD
DAB
ABC
BC
BD
AC
A

样例输出 1

2
3
1
0
2

说明 1

  • “ABC” 有 2 次出现,分别由元组 $\langle 1, 1, 1, 1 \rangle$ 和 $\langle 1, 1, 0, 2 \rangle$ 表示。
  • “BC” 有 3 次出现,分别由元组 $\langle 1, 2, 0, 1 \rangle$、$\langle 1, 2, 1, 0 \rangle$ 和 $\langle 2, 1, 0, 1 \rangle$ 表示。
  • “BD” 有 1 次出现,由元组 $\langle 2, 1, 1, 0 \rangle$ 表示。
  • “AC” 没有出现。
  • “A” 有 2 次出现,分别由元组 $\langle 1, 1, 0, 0 \rangle$ 和 $\langle 3, 2, 0, 0 \rangle$ 表示。

样例输入 2

2 3 3
AAA
AAA
A
AAA
AAAAA

样例输出 2

6
4
0

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.