#C7903. Maximum Word Length in Grid
Maximum Word Length in Grid
Maximum Word Length in Grid
You are given a rectangular grid of characters with dimensions \( m \times n \) and a list of words. A word can be constructed from letters of sequentially adjacent cells, where adjacent cells are those horizontally, vertically, or diagonally neighboring (i.e. sharing a side or a corner). Note that the same cell cannot be used more than once in constructing a single word.
Your task is to determine the maximum length among all words in the given list that can be found in the grid. If no word from the list can be found, print \(0\).
Example:
Input: 4 4 abcd efgh ijkl mnop 5 abc fij ghk mnop abcdef</p>Output: 4
inputFormat
The first line contains two integers \( m \) and \( n \) representing the number of rows and columns of the grid respectively. The next \( m \) lines each contain a string of length \( n \), representing the rows of the grid. Following this, an integer \( k \) is given on a new line, representing the number of words to search for. The next \( k \) lines each contain a word.
outputFormat
Output a single integer representing the maximum length of any word from the list that can be found in the grid. If none of the words can be found, output 0.
## sample4 4
abcd
efgh
ijkl
mnop
5
abc
fij
ghk
mnop
abcdef
4