Problem:


Score : 200 points

Problem Statement

You are given an image A composed of N rows and N columns of pixels, and a template image B composed of M rows and M columns of pixels.

A pixel is the smallest element of an image, and in this problem it is a square of size 1×1.

Also, the given images are binary images, and the color of each pixel is either white or black.  

In the input, every pixel is represented by a character: . corresponds to a white pixel, and # corresponds to a black pixel.

The image A is given as N strings A_1,...,A_N.

The j-th character in the string A_i corresponds to the pixel at the i-th row and j-th column of the image A (1≦i,j≦N).

Similarly, the template image B is given as M strings B_1,...,B_M.

The j-th character in the string B_i corresponds to the pixel at the i-th row and j-th column of the template image B (1≦i,j≦M).  

Determine whether the template image B is contained in the image A when only parallel shifts can be applied to the images.  

Constraints

1≦M≦N≦50 

A_i is a string of length N consisting of # and ..

B_i is a string of length M consisting of # and ..

Input

The input is given from Standard Input in the following format:

N M
A_1
A_2
:  
A_N
B_1
B_2
:  
B_M

Output

Print Yes if the template image B is contained in the image A. Print No otherwise.

Sample Input 1

3 2
#.#
.#.
#.#
#.
.#

Sample Output 1

Yes

The template image B is identical to the upper-left 2 × 2 subimage and the lower-right 2 × 2 subimage of A. Thus, the output should be Yes.

Sample Input 2

4 1
....
....
....
....
#

Sample Output 2

No

The template image B, composed of a black pixel, is not contained in the image A composed of white pixels.



Sample input:
3 2
#.#
.#.
#.#
#.
.#


Sample output:
Yes

Submission status: Accepted

Solution code:
import sys
N,M = map(int,input().split())
A,B = [],[]
for i in range(N):
    A.append(input())
for i in range(M):
    B.append(input())
for i in range(N-M+1):
    for j in range(N-M+1):
        check = True
        for di in range(M):
            for dj in range(M):
                if A[i+di][j+dj] != B[di][dj]:
                    check = False
        if check:
            print("Yes")
            sys.exit()
else:
    print("No")

Submission status: Accepted

Solution code:
n, m = map(int, input().split())

pic_n, pic_m = [], []
for i in range(n):
    pic_n.append([j for j in input()])
for i in range(m):
    pic_m.append([j for j in input()])

corr = "No"
for i in range(n):
    for j in range(n):
        if pic_n[i][j] == pic_m[0][0]:
            for k in range(m):
                if i + k >= n:
                    break
                for l in range(m):
                    if j + l >= n or pic_n[i+k][j+l] != pic_m[k][l]:
                        break
                else:
                    continue
                break
            else:
                corr = "Yes"

print(corr)

Submission status: Accepted

Solution code:
N,M = map(int,input().split())

A,B = [],[]
for i in range(N): A.append(input())
for j in range(M): B.append(input())
    
isok = False
for h in range(0,N-M+1):
    for w in range(0,N-M+1):
        #始点を合わせたら照合開始
        search = True #照合を仮定(ダメなら-1に変更)
        for j in range(M):
            if A[h+j][w:w+M] != B[j]:
                search = False
                break
        if search:
            isok = True
            break
        #照合ここまで
    if search:break
        
if isok:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
n,m = list(map(int,input().split()))
s = n-m+1
a = []
for i in range(n):
    a.append(list(input()))

b = []
for i in range(m):
    b.append(list(input()))


ans = 'No'
for i in range(s):
    for j in range(s):
        flag = 0
        for k in range(m):
            if b[k] == a[i+k][j:j+m]:
                flag += 1
        if flag == m:
            ans = 'Yes'
            break

print(ans)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
A, B = [], []
for i in range(N):
    A.append(input())
for i in range(M):
    B.append(input())
ans = 'No'
end = 0
for i in range(N-M+1):
    for j in range(N-M+1):
        temp = []
        for k in range(M):
            temp.append(A[i+k][j:j+M])
        if temp == B:
            ans = 'Yes'
            end = 1
            break
    if end == 1:
        break
print(ans)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
A = [input() for k in range(N)]
B = [input() for k in range(M)]

for k in range(N-M+1):
    for l in range(len(A[0])-len(B[0])+1):
        t = 0
        for p in range(len(B[0])):
            for q in range(M):
                if A[k+q][l+p] == B[q][p]:
                    t += 1
        if t == len(B[0])*M:
            print("Yes")
            exit(0)
print("No")

Submission status: Accepted

Solution code:
N, M = map(int, input().split(' '))
i_A = [list(input()) for _ in range(N)]
i_B = [list(input()) for _ in range(M)]
flag = 0
for i in range(N-M+1):
    for j in range(N-M+1):
        if i_B[0] == i_A[i][j:j+M]:
            flag = 1
            for k in range(1, M):
                if i_B[k] != i_A[i+k][j:j+M]:
                    flag = 0
            if flag == 1: break
        else: flag = 0
    if flag == 1: break
if flag == 1: print('Yes')
else: print('No')

Submission status: Accepted

Solution code:
import sys

n, m = list(map(int, input().split()))

a = []
for _ in range(n):
    a.append(list(input()))
    
b = []
for _ in range(m):
    b.append(list(input()))

for i in range(n - m + 1):
    for j in range(n - m + 1):
        c = [a[k][i: i + m] for k in range(j, j + m)]
        if b == c:
            print("Yes")
            sys.exit()
            
print("No")

Submission status: Accepted

Solution code:
def judge(a, b, y, x, m):
	for i in range(0, m):
		for j in range(0, m):
			if a[y+i][x+j] != b[i][j]: return False
	return True

N, M = map(int, raw_input().split())
A = []
B = []
for i in range(0, N):
	A.append(raw_input())
for i in range(0, M):
	B.append(raw_input())

ans = 'No'
for i in range(0, N-M+1):
	for j in range(0, N-M+1):
		if judge(A, B, i, j, M):
			ans = 'Yes'
			break

print ans

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
A_list=[input()for i in range(N)]
B_list=[input()for i in range(M)]

whole_flag = 0
for i in range(N-M+1):
    for j in range(N-M+1):
        flag = 0
        for k in range(M):
            if B_list[k] == A_list[i+k][j:j+M]:
                flag += 1
            else:
                pass
        if flag == M:
            whole_flag += 1
            
print("Yes" if whole_flag >0 else "No")

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
A_list = []
B_list = []
for _ in range(N):
    A_list.append(list(input()))
for _ in range(M):
    B_list.append(list(input()))
    

whole_flag = 0
for i in range(N-M+1):
    for j in range(N-M+1):
        flag = 0
        for k in range(M):
            if B_list[k] == A_list[i+k][j:j+M]:
                flag += 1
            else:
                pass
        if flag == M:
            whole_flag += 1
            
if whole_flag == 0:
    print("No")
else:
    print("Yes")

Submission status: Accepted

Solution code:
N, M = map(int, input().split())

A = [list(map(lambda x : 1 if x == '#' else 0, input())) for _ in range(N)]
B = [list(map(lambda x : 1 if x == '#' else 0, input())) for _ in range(M)]

for j in range(N-M+1):
    for i in range(N-M+1):
        result = True
        for y in range(M):
            for x in range(M):
                if A[y+j][x+i] != B[y][x]:
                    result = False
                    break
            if not result:
                break
        if result:
            print("Yes")
            exit()
print("No")

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
a=[input()for i in range(n)]
b=[input()for i in range(m)]
cnt=False
for i in range(n-m+1):
    for j in range(n-m+1):
        t=[k[j:j+m]for k in a[i:i+m]]#n*nの一部分を抜粋している
        if t==b:
            cnt=True
print("Yes" if cnt else "No")

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
a=[input()for i in range(n)]
b=[input()for i in range(m)]
cnt=False
for i in range(n-m+1):
    for j in range(n-m+1):
        t=[k[j:j+m]for k in a[i:i+m]]
        if t==b:
            cnt=True
print("Yes" if cnt else "No")

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
a = [input() for i in range(n)]
b = [input() for i in range(m)]
res = True
for i in range(len(b)):
    if b[i] not in a[i]:
        res = False
        break

print('Yes' if res else 'No')

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
A = [list(input()) for _ in range(N)]
B = [input() for _ in range(M)]
for i in range(M):
    for j in range(N-M+1):
        str_n = ''.join(A[i][j:j+M])
        if str_n == B[i]:
            break
    else:
        print("No")
        exit()
else:
    print("Yes")

Submission status: Accepted

Solution code:
import sys

n, m = list(map(int, input().split()))

a = []
for i in range(0, n):
    a.append(list(input()))

b = []
for i in range(0, m):
    b.append(list(input()))

def diff(x, y):
    r = []
    for i in range(y, y+m):
        r.append(a[i][x:(len(b[0]) + x)])
    return r

if __name__ == '__main__':
    for i in range(0, (n - m)+1):
        for j in range(0, (n - m)+1):
            if(diff(i, j) == b):
                print('Yes')
                sys.exit()
    print('No')

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
A = []
for i in range(N):
    A.append(input())
B = []
for i in range(M):
    B.append(input())
ans = False
for i in range(N-M+1):
    for j in range(N-M+1):
        if A[i][j] == B[0][0]:
            if all([A[i+h][j:j+M] == B[h] for h in range(M)]):
                ans = True
                break
print("Yes") if ans else print("No")

Submission status: Accepted

Solution code:
N, M = [int(i) for i in input().split()]
A = []
for i in range(N):
    A.append(input())
B = []
for i in range(M):
    B.append(input())
ans = False
for i in range(N-M+1):
    for j in range(N-M+1):
        if A[i][j] == B[0][0]:
            if all([A[i+h][j:j+M] == B[h] for h in range(M)]):
                ans = True
                break
print("Yes") if ans else print("No")

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
A=[input() for i in range(N)]
B=[input() for i in range(M)]
flag=0
for i in range(N-M+1):
    for j in range(N-M+1):
        flag2=1
        for x in range(M):
            for y in range(M):
                if A[i+x][j+y]!=B[x][y]:
                    flag2=0
                    break
            if flag2==0:
                break
        if flag2==1:
            flag=1
            break
    if flag==1:
        break
if flag==1:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
a = [input() for _ in range(n)]
b = [input() for _ in range(m)]
f = False
for i in range(n - m + 1):
    for j in range(n - m + 1):
        ok = True
        for k in range(m):
            for l in range(m):
                if a[i + k][j + l] != b[k][l]:
                    ok = False
                    break
            if not ok: break
        if ok:
            f = True
            break
    if f: break
if f: print('Yes')
else: print('No')

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
A=[[] for i in range(N)]
B=[[] for j in range(M)]

for i in range(N):
  s=input().strip()
  A[i]=list(s)
for i in range(M):
  s=input().strip()
  B[i]=list(s)

def check(a,b):
  for i in range(M):
    for j in range(M):
      if A[i+a][j+b] != B[i][j]:
        return False
  return True

ch=False
for i in range(N-M+1):
  if ch:
    break
  for j in range(N-M+1):
    ch=check(i,j)
    if ch:
      break
if ch:
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
def contains(a, b, n, m):
    def eq(i, j):
        for row in range(m):
            if b[row] != a[i + row][j:j+m]:
                return False
        return True

    for i in range(n - m + 1):
        for j in range(n - m + 1):
            if eq(i, j):
                return True
    return False


if __name__ == '__main__':
    n, m = list(map(int, input().split()))
    a = [list(input()) for _ in range(n)]
    b = [list(input()) for _ in range(m)]
    print('Yes') if contains(a, b, n, m) else print('No')

Submission status: Accepted

Solution code:
n,m = (int(i) for i in input().split())
a = [input() for i in range(n)]
b = [input() for i in range(m)]
answer ="No"
for i in range(n-m+1):
	for j in range(n-m+1):
		num = 0
		for k in range(m):
			if all(a[i+k][j+k2]==b[k][k2] for k2 in range(m)):
				num += 1
		if num == m:
			answer = "Yes"
			break
			break
print(answer)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())

a_list = []
b_list = []
for i in range(N):
    a_list.append(list(input()))

for i in range(M):
    b_list.append(list(input()))

test = True

for i in range(N-M):
    for j in range(N-M):
        if a_list[i][j:j+M] == b_list[0][:M]:
            test = True
            for k in range(1,M):
                if a_list[i+k][j:j + M] != b_list[k][:M+1]:
                    test = False
                    break
        else:
            test = False

        if test == True:
            break

    if test == True:
        break

if test == True:
  print('Yes')
else:
  print('No')

Submission status: Accepted

Solution code:
import pprint
from itertools import product

N, M = [int(n) for n in input().split()]

A = []
for _ in range(N):
    A.append(list(input()))

B = []
for _ in range(M):
    B.append(list(input()))

found = False
for dx, dy in product(range(N - M + 1), repeat=2):
    found = True
    for x, y in product(range(M), repeat=2):
        if A[dx + x][dy + y] != B[x][y]:
            found = False
            break
    if found:
        break
    
print('Yes' if found else 'No')

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
a=[list(input()) for i in range(n)]
b=[list(input()) for i in range(m)]
f=True
for i in range(n-m+1):
  for j in range(n-m+1):
    f=True
    for k in range(i,i+m):
      for l in range(j,j+m):
        if b[k-i][l-j]!=a[k][l]:
          f=False
    if f:
      print('Yes')
      break
  if f:
    break
if not f:
  print('No')

Submission status: Accepted

Solution code:
n, m = [int(i) for i in input().split()]

N, M = [], []
for i in range(n):
    N.append(list(input()))
for i in range(m):
    M.append(list(input()))

# print(N)
# print(M)

def check():
    for i in range(n-m+1):
        for j in range(n-m+1):
            flag = True
            for ii in range(m):
                for jj in range(m):
                    flag &= N[i+ii][j+jj] == M[ii][jj]
                    if not flag: break
                if not flag: break
            if flag: return "Yes"
    return "No"

print(check())

Submission status: Accepted

Solution code:
import sys
n, m = map(int, input().split())
n_list = [list(input()) for i in range(n)]
m_list = [list(input()) for i in range(m)]

def bunkatu(x, y):
    global n_list
    lis = []
    for i in range(y, y + m):
        lis.append(n_list[i][x: x + m])
    return lis

for j in range(n - m + 1):
    for i in range(n - m + 1):
        tmp = bunkatu(i, j)
        if m_list == tmp:
            print('Yes')
            sys.exit(0)
print('No')

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
a = [input() for _ in range(n)]
b = [input() for _ in range(m)]
f = 0
for i in range(n - m + 1):
    for j in range(n - m + 1):
        t = [k[j:j + m] for k in a[i:i + m]]
        if t == b: f = 1
print ("Yes" if f else "No")

Submission status: Accepted

Solution code:
def main():
    n,m = map(int,input().split())
    a = [input() for i in range(n)]
    b = [input() for i in range(m)]
    for i in range(n-m+1):
        for j in range(n-m+1):
            for k in range(m):
                if b[k] != a[i+k][j:j+m]: break
            else:
                print("Yes")
                return 0
    else:
        print("No")
main()

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
a=[input() for i in range(n)]
b=[input() for i in range(m)]
sum=0
for i in range(n-m+1):
    for j in range(n-m+1):
        for k in range(m):
            for l in range(m):
                if a[i+k][j+l]==b[k][l]:
                    sum+=1
        if sum==m**2: break
        else: sum=0
    if sum==m**2: break
print("Yes" if sum==m**2 else "No")

Submission status: Accepted

Solution code:
import sys
N,M=map(int,input().split())
Ai=[]
Bi=[]
for i in range(N):
    Ai.append(input())
for i in range(M):
    Bi.append(input())
roop=N-M+1
for i in range(roop):
    for j in range(roop):
        #print("A")
        flag=1
        for k in range(M):
            #print(Ai[i+k][j:j+M])
            if(Ai[i+k][j:j+M]!=Bi[k]):
                flag=0
                break;
        if(flag==1):
            print("Yes")
            sys.exit()
print("No")

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
A = []
for i in range(N):
    A.append(input())
B = []
for i in range(M):
    B.append(input())
isOK = False
for i in range(N - M + 1):
    if(isOK):
        break
    for j in range(N - M + 1):
        flag = True
        for k in range(M):
            if(flag == False):
                break
            for l in range(M):
                if(A[i + k][j + l] != B[k][l]):
                    flag = False
                    break
        if(flag):
            print('Yes')
            isOK = True
            break
if(isOK == False):
    print('No')

Submission status: Accepted

Solution code:
import sys
def main():
    n, m = map(int, input().split())
    A = [list(input()) for _ in range(n)]
    B = [list(input()) for _ in range(m)]

    for i in range(n - m + 1):
        for j in range(n - m + 1):
            f = 1
            for k in range(m):
                for l in range(m):
                    if A[i + k][j + l] != B[k][l]:
                        f = 0
                        break
                if f == 0:
                    break
            if f:
                print("Yes")
                sys.exit()
    print("No")


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N,M = [int(i) for i in input().split()]
A = [input().strip() for _ in range(N)]
B = [input().strip() for _ in range(M)]
flag = 0
for v in range(N-M+1):
  for h in range(N-M+1):
    for i in range(M):
      for j in range(M):
        if A[v+i][h+j] == B[i][j]:
          flag += 1
    if flag == M*M:
      break
    else:
      flag = 0
  if flag == M*M:
    break

if flag==0:
  print('No')
else:
  print('Yes')

Submission status: Accepted

Solution code:
N,M=map(int, input().split())

A=[list(input()) for i in range(N)]
B=[list(input()) for i in range(M)]




flag=0
for i in range(N-M+1):
    for j in range(N-M+1):
        for t in range(M):
            for s in range(M):
                if A[i+t][j+s]==B[t][s]:
                    flag+=1
        if flag==M*M: break
        else: flag=0
    if flag==M*M: break

if flag==0: print("No")
else: print("Yes")

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
a = [input() for _ in range(n)]
b = [input() for _ in range(m)]
for i in range(n-m+1):
    for j in range(n-m+1):
        if [k[j:j+m] for k in a[i:i+m]] == b: print('Yes'); exit()
            
print('No')

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin
def na():
    return map(int,stdin.readline().split())
def ns():
    return stdin.readline().strip()
N, M = na()
a = []
b = []

for i in range(N):
    a.append(ns())
for i in range(M):
    b.append(ns())

for i in range(N-M+1):
    for j in range(N-M+1):
        flag = True
        for k in range(M):
            if a[i+k][j:j+M] != b[k]:
                flag = False
                break
        if flag:
            print("Yes")
            sys.exit(0)
print("No")

Submission status: Accepted

Solution code:
n,m = map(int, input().split())
a =  ""
b = ""
for i in range(n):
   a += input()

for i in range(m):
   if not i%2 ==0:
      b += input()[::-1]
   else:
      b += input()

if b in a:
   print("Yes")
else:
   print("No")

Submission status: Accepted

Solution code:
import re
n, m = [int(x) for x in input().split()]
nm = ""
ss = ""
for _ in range(n):
    nm += input()
for i in range(m):
    ss += ".{{{}}}".format(n-m) if i>0 else ""
    ss += input().replace(".","\.")
print("Yes") if re.search(ss,nm) else print("No")

Submission status: Accepted

Solution code:
def main():
    N, M = map(int, input().split())
    A = [
        input()
        for i in range(N)
    ]
    B = [
        input()
        for i in range(M)
    ]

    diff = N - M + 1
    for i in range(diff):
        for j in range(diff):
            a = [
                A[k][j:j + M]
                for k in range(i, i + M)
            ]
            if a == B:
                print("Yes")
                return

    print("No")

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import re
n,m=map(int,input().split())
a=" ".join([input().replace(".","o") for i in [0]*n])
b=("."*(n-m+1)).join([input().replace(".","o") for i in [0]*m])
if re.search(b,a):
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
N,M = map(int,input().split())

A = ""
B = ""

for i in range(N):
	A += input()



for i in range(M):
	if not i % 2 == 0:
		B += input()[::-1]
	else:
		B += input()

if B in A:
	print("Yes")
else:
	print("No")

Submission status: Accepted

Solution code:
import sys
N,M=map(int,raw_input().split())
a=[raw_input() for _ in range(N)]
b=[raw_input() for _ in range(M)]
#print a
#print b

c=[]

for i in range(N-M+1):
	for j in range(N-M+1):
		tmp_c=[]
		for k in range(M):
			#print a[i+k][j:j+M]
			tmp_c.append(a[i+k][j:j+M])
		c.append(tmp_c)


print "Yes" if b in c else "No"

Submission status: Accepted

Solution code:
val = [int(x) for x in input().split()]
array_a = []
array_b = []
res = True

for i in range(val[0]):
    array_a.append(input())
for j in range(val[1]):
    array_b.append(input())

for k in range(len(array_b)):
    if array_b[k] not in array_a[k]:
        res = False
        break
print("Yes" if res == True else "No")

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
p = ""
c = ""

for i in range(n):
  p = p + input()

for i in range(m):
  if not i % 2 == 0:
    c = c + input()[::-1]
  else:
    c = c + input()

if c in p:
  print('Yes')
else:
  print('No')

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
a, b = [], []
for i in range(n):
    a.append(input())
for i in range(m):
    b.append(input())
for i in range(n - m + 1):
    for j in range(len(a[0]) - len(b[0]) + 1):
        for k in range(m):
            # print()
            # print(a[i+k][j:(j+m)])
            # print(b[k])

            if a[i+k][j:(j+m)] != b[k]:
                # print('break')
                break
            # else:
                # print('pass')
            if k == m-1:
                print('Yes')
                quit()
print('No')

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
A = [input() for _ in range(N)]
B = "".join([input() for _ in range(M)])

Z = N - M + 1
ans = [["".join(A[i+k][j:j+M] for k in range(M)) == B for i in range(Z)] for j in range(Z)]
for b in ans:
    if True in b:
        print("Yes")
        break
else:
    print("No")

Submission status: Accepted

Solution code:
#!/usr/bin/env python

import sys

N,M=list( int(i) for i in input().split() )
A=[] # large
B=[] # small

for i in range(0, N):
    A.append(input())

for i in range(0, M):
    B.append(input())

'''
print(A)
print(B)
'''

def check(start_x, start_y):
    for i in range(0, M):
        for j in range(0, M):
            # print("checking:","A:", start_x+i, start_y+j, "B:", i, j)
            if( A[start_x+i][start_y+j] != B[i][j] ):
                return False
    return True

for i in range(0, N-M+1):
    for j in range(0, N-M+1):
        # print("calling:", i, j)
        # check(i, j)
        if( check(i, j) ):
            # print("match", i, j)
            print("Yes")
            sys.exit()

print("No")

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
#matrixbがパターン
def check_match(matrixa, matrixb):
    arow=len(matrixa)
    acol=len(matrixa[0])
    brow=len(matrixb)
    bcol=len(matrixb[0])
    for i in range(arow-brow+1):
        for j in range(acol-bcol+1):
            flag=True
            for k in range(brow):
                for l in range(bcol):
                    if matrixa[i+k][j+l]!=matrixb[k][l]:
                        flag=False
                        break
                if not flag:
                    break
            if flag==True:
                return (i,j)
N, M = map(int, input().split())
A = [list(input()) for _ in range(N)]
B = [list(input()) for _ in range(M)]
print("Yes"if check_match(A,B) else "No")

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
a = [input() for i in range(n)]
b = [input() for i in range(m)]


for i in range(n-m+1):
    for j in range(n-m+1):
        aa = a[i:i + m]
        for k in range(m):
            aa[k] = aa[k][j:j+m]
        if aa == b:
            print('Yes')
            exit()

print('No')

Submission status: Accepted

Solution code:
N, M = map(int, input().split())

A = [list(input()) for _ in range(N)]
B = [list(input()) for _ in range(M)]

for i in range(N-M+1):
    for j in range(N-M+1):
        flag = True
        for k in range(M):
            for l in range(M):
                if A[i+k][j+l] != B[k][l]:
                    flag = False
                    break
            if not flag:
                break
        
        if flag:
            print('Yes')
            exit()

print('No')

Submission status: Accepted

Solution code:
n,m = map(int,input().split())

a = []
b = []

for i in range(n):
    a.append(input())
for i in range(m):
    b.append(input())
OKFlag = False

for i in range(n*n):
    SPRow,SPColumn = divmod(i,n)
    if SPRow + m-1 <= n-1 and SPColumn + m-1 <= n-1:
        for j in range(m*m):
            MPRow,MPColumn = divmod(j,m)

            if a[SPRow + MPRow][SPColumn + MPColumn] == b[MPRow][MPColumn]:
                if MPRow == (m-1) and MPColumn == (m-1):
                    OKFlag = True
                continue
            else:
                break
    else:
        continue
print("Yes" if OKFlag else "No")

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
a = []
b = []
for i in range(n):
    a.append(input())
for i in range(m):
    b.append(input())
OKFlag = False

#起点を管理するループ
for i in range(n * n):
    startRow,startColumn = divmod(i,n)
    maxRow,maxColumn = startRow + (m - 1),startColumn + (m - 1)
    if maxRow <= (n - 1) and maxColumn <= (n - 1):

        for j in range(m * m):
            moveRow,moveColumn = divmod(j,m)
        
            if a[startRow + moveRow][startColumn + moveColumn] == b[moveRow][moveColumn]:
                if moveRow == (m - 1) and moveColumn == (m - 1):
                    OKFlag = True
                continue
            else:
                break
    else:
        continue

print("Yes" if OKFlag else "No")

Submission status: Accepted

Solution code:
def solve(n, m, NUM):
    for i in range(len(m)):
        if n[NUM + i] is not m[i]:
            return -1
    return 1


N, M = [int(i) for i in input().split()]
n_pic = [input() for i in range(N)]
m_pic = [input() for i in range(M)]
num = 0
if M is 1:
    for n in n_pic:
        if -1 is not n.find(m_pic[0]):
            print('Yes')
            exit()
    print('No')
    exit()

for n in range(N - M + 1):
    for n_len in range(N - M + 1):
        while -1 is not solve(n_pic[n + num], m_pic[num], n_len):
            num += 1
            if num is M:
                print('Yes')
                exit()
        num = 0
print('No')

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
A = []
B = []

for _ in range(N):
    A.append(input())

for _ in range(M):
    B.append(input())

for i in range(N - M + 1):
    for j in range(N - M + 1):
        f = True

        for p in range(M):
            if A[i + p][j:j + M] != B[p]:
                f = False
                break
        if f:
            print('Yes')
            exit()
print('No')

Submission status: Accepted

Solution code:
def mask_judge(a, b, i, j):
    flag = 1
    for k in range(m):
        for l in range(m):
            if a[i+k][j+l] != b[k][l]:
                flag = 0
                break
    return flag


def main():
    a = [[0 if i == '.' else 1 for i in input()] for _ in range(n)]
    b = [[0 if i == '.' else 1 for i in input()] for _ in range(m)]

    flag = 0
    for i in range(n-m+1):
        for j in range(n-m+1):
            if mask_judge(a, b, i, j):
                flag = 1
                break
    if flag:
        print("Yes")
    else:
        print("No")


if __name__ == "__main__":
    n, m = map(int, input().split())
    main()

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
base = [input() for _ in range(n)]
tmp = [input() for _ in range(m)]
count = 0
flg = False

for i in range(n - m + 1):
    for j in range(n - m + 1):
        for k in range(m):
            if base[i + k][j:j+m] == tmp[k]:
                count += 1
            else:
                break
        if count == m:
            flg = True
            break
        else:
            count = 0
if flg:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
n,m=[int(x) for x in input().split()]
a=[]
b=[]
for i in [0]*n:
    a.append(input())
for i in [0]*m:
    b.append(input())
def check(x,y):
    for i in range(m):
        if a[y+i][x:x+m] != b[i]:
            return False
    return True
from itertools import product
for i,j in product(range(n-m+1),range(n-m+1)):
    if check(i,j):
        print("Yes")
        import sys
        sys.exit()
print("No")

Submission status: Accepted

Solution code:
N, M = map(int,input().split())
 
A=[]
B=[]
 
for i in range(N):
    a=input()
    A.append(a)
    
for j in range(M):
    b=input()
    B.append(b)


res = 'No'
    
for p in range(N-M+1):
    for q in range(N-M+1):
        # check
        C = 0
        for r in range(M):
            if B[r] == A[p+r][q:(q+M)]:
                C=C+1
            if C==M:
                res = 'Yes'
                            
print(res)

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
A=[]
for i in range(N):
 A.append(input())
B=[]
for i in range(M):
 B.append(input())
t = 0
t = 0
for i in range(N-M+1):
	for j in range(N-M+1):
		t = 0
		for k in range(M):
			if t:
				break
			for l in range(M):
				if A[i+k][j+l] != B[k][l]:
					t = 1
					break
		else:
			if A[i+k][j+l] == B[k][l]:
				print("Yes")
				exit()
print("No")

Submission status: Accepted

Solution code:
N, M = list(map(int, input().split(" ")))

A = []
for i in range(N):
    A.append(input())
    
B = []
for i in range(M):
    B.append(input())

    
ans_flag = False
for i in range(N-M+1):  
    for j in range(N-M+1):
        if A[i][j:j+M] == B[0]:
            ans_flag = True
            for k in range(1, M):
                if A[i+k][j:j+M] != B[k]:
                    ans_flag = False
                    break
            if ans_flag == True:
                break
        if ans_flag == True:
                break
    if ans_flag == True:
                break
            
if ans_flag == True:
    print("Yes")
else:
    print("No")