CF1252D.Find String in a Grid
NOI/NOI+/CTSC
通过率:0%
时间限制:5.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You have a grid G containing R rows (numbered from 1 to R, top to bottom) and C columns (numbered from 1 to C, left to right) of uppercase characters. The character in the rth row and the cth column is denoted by Gr,c. You also have Q strings containing uppercase characters. For each of the string, you want to find the number of occurrences of the string in the grid.
An occurrence of string S in the grid is counted if S can be constructed by starting at one of the cells in the grid, going right 0 or more times, and then going down 0 or more times. Two occurrences are different if the set of cells used to construct the string is different. Formally, for each string S, you would like to count the number of tuples ⟨r,c,Δr,Δc⟩ such that:
- 1≤r≤R and r≤r+Δr≤R
- 1≤c≤C and c≤c+Δc≤C
- S=Gr,cGr,c+1…Gr,c+ΔcGr+1,c+Δc…Gr+Δr,c+Δc
你有一个包含 R 行(从上到下编号为 1 至 R)和 C 列(从左到右编号为 1 至 C)的大写字母网格 G。第 r 行第 c 列的字符记为 Gr,c。此外,你还有 Q 个由大写字母组成的字符串。对于每个字符串,你需要找出它在该网格中出现的次数。
字符串 S 在网格中的一次出现定义为:从网格中的某个单元格出发,向右移动 0 次或多次,然后向下移动 0 次或多次,从而拼出字符串 S。若构造字符串所使用的单元格集合不同,则视为两次不同的出现。形式化地,对每个字符串 S,你需要统计满足以下条件的四元组 ⟨r,c,Δr,Δc⟩ 的数量:
- 1≤r≤R 且 r≤r+Δr≤R
- 1≤c≤C 且 c≤c+Δc≤C
- S=Gr,cGr,c+1…Gr,c+ΔcGr+1,c+Δc…Gr+Δr,c+Δc
输入格式
Input begins with a line containing three integers: R C Q (1≤R,C≤500; 1≤Q≤200000) representing the size of the grid and the number of strings, respectively. The next R lines each contains C uppercase characters representing the grid. The cth character on the rth line is Gr,c. The next Q lines each contains a string S containing uppercase characters. The length of this string is a positive integer not more than 200000. The sum of the length of all Q strings combined is not more than 200000.
输入的第一行包含三个整数:R、C 和 Q(1≤R,C≤500;1≤Q≤200000),分别表示网格的尺寸以及字符串的数量。接下来的 R 行,每行包含 C 个大写字符,表示该网格。第 r 行的第 c 个字符为 Gr,c。随后的 Q 行,每行包含一个由大写字符组成的字符串 S。该字符串的长度为正整数,且不超过 200000。所有 Q 个字符串的总长度不超过 200000。
输出格式
For each query in the same order as input, output in a line an integer representing the number of occurrences of the string in the grid.
对于每个查询,按照输入中的相同顺序,在一行中输出一个整数,表示该字符串在网格中出现的次数。
输入输出样例
输入#1
3 3 5 ABC BCD DAB ABC BC BD AC A
输出#1
2 3 1 0 2
输入#2
2 3 3 AAA AAA A AAA AAAAA
输出#2
6 4 0
说明/提示
Explanation for the sample input/output #1
- There are 2 occurrences of "ABC", represented by the tuples ⟨1,1,1,1⟩ and ⟨1,1,0,2⟩.
- There are 3 occurrences of "BC", represented by the tuples ⟨1,2,0,1⟩, ⟨1,2,1,0⟩, and ⟨2,1,0,1⟩.
- There is 1 occurrence of "BD", represented by the tuple ⟨2,1,1,0⟩.
- There is no occurrence of "AC".
- There are 2 occurrences of "A", represented by the tuples ⟨1,1,0,0⟩ and ⟨3,2,0,0⟩.
样例输入/输出 #1 的说明
- “ABC” 出现了 2 次,对应的四元组为 ⟨1,1,1,1⟩ 和 ⟨1,1,0,2⟩。
- “BC” 出现了 3 次,对应的四元组为 ⟨1,2,0,1⟩、⟨1,2,1,0⟩ 和 ⟨2,1,0,1⟩。
- “BD” 出现了 1 次,对应的四元组为 ⟨2,1,1,0⟩。
- “AC” 未出现。
- “A” 出现了 2 次,对应的四元组为 ⟨1,1,0,0⟩ 和 ⟨3,2,0,0⟩。
输入解题思路,AI测评打分。不知道怎么写?