Logo
(追記) (追記ここまで)

19158번 - Find String in a Grid 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
5 초 512 MB93350.000%

문제

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

입력

Input begins with a line containing three integers: R C Q (1 ≤ R, C ≤ 500; 1 ≤ Q ≤ 200 000) 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 200 000. The sum of the length of all Q strings combined is not more than 200 000.

출력

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
  • 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>.

예제 입력 2

2 3 3
AAA
AAA
A
AAA
AAAAA

예제 출력 2

6
4
0

힌트

출처

ICPC > Regionals > Asia Pacific > Indonesia > Jakarta > The 2019 ICPC Asia Jakarta Regional Contest D번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /