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:

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 = True

for i in range(M):
    if B[i] not in A[i]:
        ans = False
        break

print('Yes' if ans == True else 'No')

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
ls0 = [input().rstrip() for _ in range(n)]
ls1 = [input().rstrip() for _ in range(m)]
ok = True
for i in range(n - m):
    for j in range(n - m):
        ok = True
        for k in range(m):
            for l in range(m):
                if ls0[i + k][j + l] != ls1[k][l]:
                    ok = False
                    break
            if not ok:
                break
        if ok:
            break
    if ok:
        break
if ok:
    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(list(map(str,input())))
for i in range(m):
    b.append(list(map(str,input())))
#print(a)
#print(b)
for i in range(0,n-m+1):
    for j in range(0,n-m+1):
        l=[]
        for k in range(m):
            l.append(a[i+k][j:j+m])
        if l==b:
            print('Yes')
            break
    else:
        continue
    break
else:
    print('No')

Submission status: Accepted

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

ans = True
for k in range(len(B)):
    if B[k] not in A[k]:
        ans = False
        break
print("Yes" if ans == True else "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)]

def match(ii,jj):
  res=1
  for i in range(M):
    if A[i+ii][jj:jj+M]!=B[i]:
      res=0
      break
  return res

ans="No"
for i in range(N-M+1):
  for j in range(N-M+1):
    if match(i,j)==1:
      ans="Yes"
      break
  else:
    continue
  break

print(ans)

Submission status: Accepted

Solution code:
def resolve():
    n, m = map(int, input().split())
    a = list(input() for _ in range(n))
    b = list(input() for _ in range(m))
    if n == m:
        if a == b:
            print('Yes')
        else:
            print('No')
        exit()
    for i in range(n - m + 1):
        for j in range(n - m + 1):
            part = [ai[j:j + m] for ai in a[i:i + m]]
            if part == b:
                print("Yes")
                exit()
    print("No")


if __name__ == "__main__":
    resolve()

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):
        tmp = 1
        for l in range(M):
            for k in range(M):
                if A[i+l][j+k] != B[l][k]:
                    tmp = 0
        if tmp == 1:
            flag = 1
            
if flag == 1:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
l_n=[]
l_m=[]
ans='No'
n,m=map(int,input().split())
for i in range(n):
	l_n.append(input())
for i in range(m):
	l_m.append(input())
#print(l_n)
#print(l_m)
for k in range(n-(m-1)):
	count=0
	for j in range(n):
		#print(l_n[j][k:k+m])
		if l_n[j][k:k+m] == l_m[count]:
			count+=1
			if count==m:
				ans='Yes'
				break
		else:
			count=0
print(ans)

Submission status: Accepted

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

if N == M:
    if A == B:
        print('Yes')
    else:
        print('No')
    exit()

def isEmbeded(left, top):
    subA = [a[left: left + M] for a in A[top: top + M]]
    if subA == B:
        return True
    else:
        return False

for left in range(N - M):
    for top in range(N - M):
        if isEmbeded(left, top):
            print('Yes')
            exit()

print('No')

Submission status: Accepted

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

for i in range(N - M + 1):
    for j in range(N - M + 1):
        match = True
        for k in range(M):
            match = match and A[k + j][i:M + i] == B[k]
        if match:
            print("Yes")
            exit()

print("No")

Submission status: Accepted

Solution code:
import sys
def main():
    t = sys.stdin.readline()
    t1 = t.rstrip()
    t2 = t1.split(' ')
    stra = [] 
    for i in range(int(t2[0])):
        y = sys.stdin.readline()
        t = y.rstrip()
        stra += [t]
    strb = [] 
    for i in range(int(t2[1])):
        y = sys.stdin.readline()
        t = y.rstrip()
        strb += [t]
 
    suma = 0
    for x in strb:
        for y in stra:
            if x in y:
                suma +=1 
    if int(t2[0])*int(t2[1])==suma:
        print("Yes")
    else:
        print("No")
main()

Submission status: Accepted

Solution code:
def cmp(A, B, i, j, N, M):
    for y in range(M):
        for x in range(M):
            if A[i+y][j+x] != B[y][x]:
                return False
    return True

def main():
    A = []
    B = []
    [N, M] = list(map(int, input().split()))
    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):
            if cmp(A, B, i, j, N, M):
                print("Yes")
                return
    print("No")
    return

main()

Submission status: Accepted

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

def main():
    [N, M] = list(map(int, input().split()))
    A = [0 for i in range(N)]
    B = [0 for i in range(M)]
    for i in range(N):
        A[i] = input()
    for i in range(M):
        B[i] = input()
    # print(A)
    # print(B)

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

    for i in range(N-M+1):
        for j in range(N-M+1):
            if cmp(i,j):
                print("Yes")
                return
    print("No")
    return

main()

Submission status: Accepted

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

for y in range(n-m+1):
    for x in range(n-m+1):
        flag = [False for _ in range(m)]
        for j in range(m):
            if a[y+j][x:m+x] == b[j]:
                flag[j] = True
        if all(flag):
            print("Yes")
            exit()
print("No")

Submission status: Accepted

Solution code:
import sys

def solve():
    n,m = map(int, sys.stdin.readline().split())
    A = [sys.stdin.readline().rstrip() for _ in range(n)]
    B = [sys.stdin.readline().rstrip() for _ in range(m)]
    for r in range(n-m+1):
        for c in range(n-m+1):
            X = []
            for i,a in enumerate(A[r:r+m]):
                if a[c:c+m] != B[i]:
                    break
            else:
                print('Yes')
                exit()
    print('No')

if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
def solve():
    n,m = map(int, input().split())
    A = [input() for _ in range(n)]
    B = [input() for _ in range(m)]
    for r in range(n-m+1):
        for c in range(n-m+1):
            X = []
            for i,a in enumerate(A[r:r+m]):
                if a[c:c+m] != B[i]:
                    break
            else:
                print('Yes')
                exit()
    print('No')

if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
import sys

def solve():
    n,m = map(int, sys.stdin.readline().split())
    A = [sys.stdin.readline().rstrip() for _ in range(n)]
    B = [sys.stdin.readline().rstrip() for _ in range(m)]
    for r in range(n-m+1):
        for c in range(n-m+1):
            X = []
            for a in A[r:r+m]:
                X.append(a[c:c+m])
            if X == B:
                print('Yes')
                exit()
    print('No')

if __name__ == '__main__':
    solve()

Submission status: Accepted

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

for r in range(n-m+1):
    for c in range(n-m+1):
        X = []
        for a in A[r:r+m]:
            X.append(a[c:c+m])
        if X == B:
            print('Yes')
            exit()
print('No')

Submission status: Accepted

Solution code:
# ABC054B - Template Matching
def main():
    N, M, *AB = open(0).read().split()
    N, M = int(N), int(M)
    A, B, lim = AB[:N], AB[N:], N - M + 1
    for i in range(lim):
        for j in range(lim):
            if [A[j + k][i : i + M] for k in range(M)] == B:
                print("Yes")
                return
    print("No")


if __name__ == "__main__":
    main()

Submission status: Accepted

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

for ly in range(N):
    for lx in range(N):
        # 見ている範囲が NxN を超えている
        if ly+M-1 >= N or lx+M-1 >= N: continue

        # NxN を見ている範囲と MxM の match を探索
        match = True
        for y in range(M):
            for x in range(M):
                if A[ly+y][lx+x] != B[y][x]:
                    match = False
        if match:
            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)]

pt_max = m * m

def b():
    for i in range(n-m+1):
        for j in range(n-m+1):
            pt = 0
            for k in range(m):
                for l in range(m):
                    if A[i+k][j+l] == B[k][l]:
                        pt += 1
            if pt == pt_max:
                return "Yes"
    return "No"

print(b())

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)]
flg = 0
for dx in range(N-M+1):
    for dy in range(N-M+1):
#        for i in range(M):
#            print(A[dy+i][dx:dx+M],B[i])
        if all(A[dy+i][dx:dx+M]==B[i] for i in range(M)):
            flg =1
if flg == 1: print("Yes")
else: print("No")

Submission status: Accepted

Solution code:
x,*c=open(0);n,m=map(int,x.split());o=n-m+1;print("YNeos"[all(any(c[p//o+q//m][p%o+q%m]!=c[n+q//m][q%m]for q in range(m*m))for p in range(o*o))::2])

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
a=[input() for _ in range(n)]
b=[input() for _ in range(m)]
for h in range(n-m+1):
	for w in range(n-m+1):
		if all(a[h+y][w+x]==b[y][x] for y in range(m) for x in range(m)):
			print("Yes")
			exit()
print("No")

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

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

    ok = False
    for sy in range(N-M+1):
        for sx in range(N-M+1):
            ok = True
            for y in range(M):
                for x in range(M):
                    if A[sy+y][sx+x] != B[y][x]:
                        ok = False
                        break
                if not ok:
                    break
            if ok:
                break
        if ok:
            break
    
    if ok:
        print("Yes")
    else:
        print("No")

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys

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):
        if A[i][j:j+M] == B[0]:
            check = True
            for k in range(1,M):
                if A[i+k][j:j+M] == B[k]:
                    pass
                else:
                    check = False
                    break
            if check:
                print('Yes')
                sys.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):
        #あるスタート地点でAにBが含まれるかをチェック
        flag = True
        for x in range(M):
            for y in range(M):
                if A[i + x][j + y] != B[x][y]:
                    flag = False
                    break
            if flag == False:
                break
        if flag == True:
            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):
        flg = True
        for k in range(M):
            for l in range(M):
                if A[i+k][j+l]!=B[k][l]:
                    flg = False    
        if flg == True:
            print('Yes')
            exit()             
print('No')

Submission status: Accepted

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

for i in range(0,n-m+1):
    for j in range(0,n-m+1):
        if a[i][j:j+m] == b[0]:
            flag = 1
            for k in range(1,m):
                if a[i+k][j:j+m] != b[k]:
                    break
                flag += 1
            if flag == m:
                res = 'Yes'
        if res == 'Yes':
            break
    if res == 'Yes':
        break


print(res)

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)]

import sys

for r in range(n - m + 1):
  for c in range(n - m + 1):
    for x in range(m):
      if a[r+x][c:c+m] != b[x]:
        break
    else:
      print("Yes")
      sys.exit()

print("No")

Submission status: Accepted

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

for h in range(N-M+1):
  for w in range(N-M+1):
    for m in range(M):
      for mm in range(M):
        #print(h+m,w+mm, Mgrid[m][mm])
        if Ngrid[h+m][w+mm] == Mgrid[m][mm]:
          continue
        else:
          break
      else:
        continue
      break
    else:
      print("Yes")
      exit()
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)];print("YNeos"[all(any(t!=s[j:j+M]for s,t in zip(A[i:],B))for i in range(N-M+1)for j in range(N-M+1))::2])

Submission status: Accepted

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

# print(N)
# print(M)

A = []
for i in range(N):
	tmp = input()
	# print(tmp)
	A.append(tmp)

B = []
for i in range(M):
	tmp = input()
	# print(tmp)
	B.append(tmp)
	
# print(A)
# print(B)
# print(''.join(B))


flag = False
for i in range(N - M + 1):
	for j in range(N - M + 1):
		# print(i)
		# print(j)
		
		lst = []
		for k in range(M):
			for l in range(M):
				lst.append(A[k + i][l + j])
		# print(lst)
		# print(''.join(lst))
		# print(''.join(B) == ''.join(lst))
		if ''.join(B) == ''.join(lst):
			flag = True
			
if flag:
	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)]

from itertools import permutations
import sys

def match(lt):
    if m == 1:
        rng = [(0, 0)]
    else:
        rng = permutations(range(m), 2)
    for b_x, b_y in rng:
        a_x = lt[0] + b_x
        a_y = lt[1] + b_y
        if a[a_y][a_x] != b[b_y][b_x]:
            return False

    return True

cnt = 0
for i in range(n - m + 1):
    for j in range(n - m + 1):
        if match((i, j)):
            print("Yes")
            sys.exit()

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)]

from itertools import permutations

def match(lt):
    if m == 1:
        rng = [(0, 0)]
    else:
        rng = permutations(range(m), 2)
    for b_x, b_y in rng:
        a_x = lt[0] + b_x
        a_y = lt[1] + b_y
        if a[a_y][a_x] != b[b_y][b_x]:
            return False

    return True

cnt = 0
for i in range(n - m + 1):
    for j in range(n - m + 1):
        if match((i, j)):
            print("Yes")
            exit()

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)]

flag = 'No'
for i in range(N-M+1):
    for j in range(N-M+1):
        check = []
        for k in range(M):
            if A[i+k][j:j+M] == B[k]:
                check.append(1)
            else:
                check.append(-1)
        if sum(check) == M:
            flag = 'Yes'
print(flag)

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 b[0] == a[i][j:j+m]:
            for k in range(1, m):
                if b[k] != a[i + k][j:j+m]:
                    break
            else:
                print("Yes")
                exit()

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)]
r = any([r[j:j+m] for r in a[i:i+m]]==b for i in range(n-m+1) for j in range(n-m+1))
print("Yes" if r else "No")

Submission status: Accepted

Solution code:
N,M = (int(i) for i in input().split())
A = []
for i in range(N):
    a = str(input())
    a = list(a)
    A.append(a)

B = []
for i in range(M):
    b = str(input())
    b = list(b)
    B.append(b)
    
    
ans = 0
for i in range(N-M+1):
    for j in range(N-M+1):
        X = []
        Y = A[i:M+i]
        for k in range(M):
            x = Y[k][j:M+j]
            X.append(x)
        
        if X == B:
            ans = 1
if ans == 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)]
ans="No"
for i in range(n-m+1):
    for k in range(n-m+1):
        if b[0]==a[i][k:k+m]:
            if sum([b[l]==a[i+l][k:k+m] for l in range(m)])==m:
                ans="Yes"
                break
print(ans)

Submission status: Accepted

Solution code:
a,b = map(int,input().split())
lineA = [input() for i in range(a)]
lineB = [input() for i in range(b)]
count = 0
for i in range(b):
    if lineB[i] in lineA[i]:
        count += 1
if count == b:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
#インポート
import sys

#入力用
def ILI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def ISI(): return map(int, sys.stdin.readline().rstrip().split())
def II(): return int(sys.stdin.readline().rstrip())
def ISS(): return sys.stdin.readline().rstrip().split()
def IS(): return sys.stdin.readline().rstrip()

N, M = ISI()
A = [IS() for _ in range(N)]
B = [IS() for _ in range(M)]

def match(x, y):
    ok = True
    for i in range(M):
        for j in range(M):
            if A[x+i][y+j] != B[i][j]:
                ok = False
    return ok


find = False
for i in range(N-M+1):
    for j in range(N-M+1):
        if match(i, j) == True:
            find = True
if find == True:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
a=[]
for _ in range(n):
    a.append(input())
b=[]
for _ in range(m):
    b.append(input())
for i in range(n-m+1):
    for j in range(n-m+1):
        for k in range(m):
            if a[i+k][j:j+m]!=b[k]:
                break
            elif k==m-1:
                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)]
x = y = 0

def check(x,y):
  for i in range(m):
    if b[i] != a[y+i][x:x+m]:
      return(False)
  return(True)

for x in range(n-m+1):
  for y in range(n-m+1):
    if check(x,y):
      print("Yes")
      exit()
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)]
for i in range(N - M + 1):
    for j in range(N - M + 1):
        if all([A[i+x][j+y] == B[x][y] for x in range(M) for y in range(M)]):
            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)]
ans=0
for i in range(n-m+1):
  for s in range(n-m+1):
    t = [k[s:s+m] for k in a[i:i+m]]
    if t==b:ans=1
print("Yes") if ans==1 else print("No")

Submission status: Accepted

Solution code:
import numpy as np
n,m =map(int,input().split())


A = np.array([list(input()) for i in range(n)])
B = np.array([list(input()) for i in range(m)])
P = np.zeros(B.shape,str)
a = 0
for i in range(n-m+1):
   for j in range(n-m+1):
      P= A[i:i+m,j:j+m]
      if np.all(B==P):
         a = 1
         break

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

Submission status: Accepted

Solution code:
import sys
import copy
import string
import  math
from _bisect import *
from collections import *
from operator import itemgetter
from math import factorial
"""
from fractions import gcd
def lcm(x, y):
    return (x * y) // gcd(x, y)
"""
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

n, m = na()
a = [list(input()) for _ in range(n)]
b = [list(input()) for _ in range(m)]
ans = 'No'
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 flag:
            ans = 'Yes'
print(ans)

Submission status: Accepted

Solution code:
from itertools import product
#%%
def resolve():
    n,m=map(int,input().split())
    A=[input() for _ in range(n)]
    B=[input() for _ in range(m)]
    flag = any([r[j:j+m] for r in A[i:i+m]]==B for i,j in product(range(n-m+1),range(n-m+1)))
    print("Yes" if flag else "No")
resolve()

Submission status: Accepted

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

f = False
ff = False

for i in range(N-M+1):
  for j in range(N-M+1):
    f = True
    for k in range(M):
      for l in range(M):
        if A[i+k][j+l] != B[k][l]:
          f = False
    if f:
      ff = True
      break

if ff:
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
import numpy as np
N, M = map(int, input().split())
A = np.array([list(input()) for i in range(N)])
B = np.array([list(input()) for i in range(M)])

for k in range(N-M+1):
  for l in range(N-M+1):
    C = A[k:k+M,l:l+M]
    if (B==C).all():
      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)]
flag = False
for i in range(N-M+1):
    for j in range(N-M+1):
        a = [x[j:j+M] for x in A[i:i+M]]
        if a == B:
            flag = True
print('Yes' if flag == True else 'No')

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
A=[""]*N
B=[""]*M
for i in range(N):
  A[i]=input()
for i in range(M):
  B[i]=input()
  
A_tmp=[""]*M
for i in range(N-M+1):
  for j in range(N-M+1):
    for k in range(M):
      A_tmp[k]=A[j+k][i:i+M]
    if A_tmp==B:
      print("Yes")
      exit(0)

print("No")

Submission status: Accepted

Solution code:
import sys

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):
        for k in range(M):
            if A[i + k][j:j + M] != B[k]:
                break
        else:
            print("Yes")
            sys.exit()
else:
    print("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)]

for i in range(n):
    if n < i + m:
        break
    for j in range(n):
        if n < j + m:
            break
        if all(a[j+k][i:i+m] == b[k] for k in range(m)):
            print("Yes")
            exit()
print("No")

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
a=[[i for i in input()] for i in range(n)]
b=[[i for i in input()] for i in range(m)]
ans='No'
for i in range(n-m+1):
    for j in range(n-m+1):
        c=[]
        for k in range(m):
#インデックスi+kのリストのインデックスj以上j+m未満の要素
            c.append(a[i+k][j:j+m])
            if c==b:
                ans='Yes'
                break
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    N, M = map(int, input().split())
    A = []
    for _ in range(N):
        A.append(input())
    B = []
    for _ in range(M):
        B.append(input())
    for i in range(N-M+1):
        for j in range(N-M+1):
            isMatch = True
            for k in range(M):
                for l in range(M):
                    if A[i+k][j+l] != B[k][l]:
                        isMatch = False
                        break
            if isMatch:
                return "Yes"
    return "No" 


if __name__ == '__main__':
    print(main())

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 all((A[i+y][j:j+M] == B[y] for y in range(M))):
            print("Yes")
            break
    else:
        continue
    break
else:
    print("No")

Submission status: Accepted

Solution code:
import sys


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):
        valid = True
        for k in range(m):
            for l in range(m):
                if A[i + k][j + l] != B[k][l]:
                    valid = False
                    break
            if valid is False:
                break
        if valid:
            print("Yes")
            sys.exit()
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)]
fl = False
for i in range(n - m + 1):
    if b[0] in a[i]:
        tmp = a[i].find(b[0])
        if m == 1:
            fl = True
        for j in range(1,m):
            if a[i+j][tmp:tmp+m] != b[j]:
                fl = False
                break
            fl = True
    if fl:
        break
if fl:
    print("Yes")
else:
    print("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)]

for i in range(n - m + 1):
    for j in range(n - m + 1):
        ans = 0
        for k in range(m):
            if b[k] == a[i+k][j:j+m]:
                ans += 1
        if ans == m:
            print('Yes')
            exit()
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)]

fl = False
for i in range(n-m+1):
    if b[0] in a[i]:
        tmp = a[i].find(b[0])
        if m == 1:
            fl = True
        for j in range(1,m):
            if a[i+j][tmp:tmp+m] != b[j]:
                fl = False
                break
            fl = True
    if fl:
        break
if fl:
    print("Yes")
else:
    print("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)]
ans = 'No'
for i in range(n-m+1):
    for j in range(n-m+1):
        cnt = m**2
        for k in range(m):
            for l in range(m):
                if a[i+k][j+l] == b[k][l]:
                    cnt -= 1
        if cnt == 0:
            ans = 'Yes'
print(ans)

Submission status: Accepted

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

cnt = 0
flag = False

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]:
                    cnt += 1
        if cnt == m ** 2:
            flag = True
        else:
            cnt = 0

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

Submission status: Accepted

Solution code:
def ck(i,j):
  flag = True
  for a, b in zip(A[i:i+M], B):
    for aa, bb in zip(a[j:j+M], b):
      if aa != bb:
        flag = False
  return flag

f = False

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):
    if A[i][j] == B[0][0]:
      if (ck(i,j)):
        f = True
        
if f:
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
As=[input() for _ in range(n)]
Bs=[input() for _ in range(m)]

flag=False
for i in range(n-m+1):
  for j in range(n-m+1):
    if [a[j:j+m] for a in As[i:i+m]]==Bs:
      flag=True

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