#C9291. Temple Grid Pattern Search
Temple Grid Pattern Search
Temple Grid Pattern Search
You are given a grid representing the layout of a temple and a smaller grid representing a specific pattern. Your task is to determine whether the smaller pattern grid is present anywhere in the temple grid. The pattern must match exactly with a subgrid of the temple grid.
More formally, you are given a temple grid of size \(N \times M\) and a pattern grid of size \(P \times Q\). You need to check if there exists an index \(i, j\) such that for every \(0 \le x < P\) and \(0 \le y < Q\), the equality \[ \texttt{temple_grid}[i+x][j+y] = \texttt{pattern_grid}[x][y] \] holds. If such an index exists, print "Found"; otherwise, print "Not Found".
Example:
Input: 1 4 5 1 2 3 4 5 5 6 7 8 9 1 2 3 4 5 0 1 2 3 4 2 3 7 8 9 3 4 5</p>Output: Found
inputFormat
The first line contains an integer \(T\), denoting the number of test cases.
For each test case, the input is as follows:
- One line with two integers \(N\) and \(M\), representing the number of rows and columns in the temple grid.
- Next \(N\) lines, each containing \(M\) integers representing the temple grid.
- One line with two integers \(P\) and \(Q\), representing the number of rows and columns in the pattern grid.
- Next \(P\) lines, each containing \(Q\) integers representing the pattern grid.
All input is provided via standard input (stdin).
outputFormat
For each test case, output a single line: "Found" if the pattern grid is present in the temple grid, or "Not Found" otherwise. The output should be printed to standard output (stdout).
## sample1
4 5
1 2 3 4 5
5 6 7 8 9
1 2 3 4 5
0 1 2 3 4
2 3
7 8 9
3 4 5
Found
</p>