The Grid Search
medium⏱ 15 mintypescriptchallengesproblem-solving-basic-
2
10 10
7283455864
6731158619
8988242643
3830589324
2229505813
5633845374
6473530293
7053106601
0834282956
4607924137
3 4
9505
3845
3530
15 15
400453592126560
114213133098692
474386082879648
522356951189169
887109450487496
252802633388782
502771484966748
075975207693780
511799789562806
404007454272504
549043809916080
962410809534811
445893523733475
768705303214174
650629270887160
2 2
99
99
Sample case — your program reads stdin and prints to stdout.
Given large grid G (R×C) and pattern grid P (r×c), determine if P appears as a contiguous sub-grid in G. Check all possible starting positions.
Example: G=
7283455864
6731158619
...
P=
9505
3845
3530
Check if P matches any r×c block in G. Output 'YES' if found, 'NO' otherwise.
Input format
First line: t (test cases). For each test: first line R C (grid size), next R lines (grid), then r c (pattern size), next r lines (pattern).
Output format
For each test case, output 'YES' if pattern found, 'NO' otherwise.
Constraints
1 ≤ t ≤ 5, 1 ≤ R, C, r, c ≤ 1000