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 = []
for _ in [0]*N:
    A.append(list(input().rstrip()))
B = []
for _ in [0]*M:
    B.append(list(input().rstrip()))

def check(x, y):
    for s in range(M):
        for t in range(M):
            if A[x+s][y+t] == B[s][t]:
                continue
            else:
                return False
    return True

def main():
    for x in range(N-M+1):
        for y in range(N-M+1):
            if check(x, y):
                print('Yes')
                return
    print('No')
    return

main()

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
a=[]
b=[]
c=0
for i in range(n):
    a.append(input())
for j in range(m):
    b.append(input())
for m in range(len(a)):
    if a[m].find(b[0])!=-1:
        for l in range(len(b)-1):
            if m+l+2>len(a):
                break
            if a[m+l+1][(a[m].find(b[0])):(a[m].find(b[0]))+len(b[l+1]):]!=b[l+1]:
                break
            c+=1
        if c==len(b)-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)]
for i in range(n-m+1):
    for j in range(n-m+1):
        h = True
        for k in range(m):
            if a[i+k][j:j+m] != b[k]:
                h = False
        if h:
            print("Yes")
            exit()
print("No")

Submission status: Accepted

Solution code:
n, m = list(map(int, input().split()))
aa, bb = [], []
for _ in range(n):
    aa.append(input())
for _ in range(m):
    bb.append(input())

ans = 'No'
from itertools import product
for i, j in product(range(n - m + 1), repeat=2):
    ok = True
    for x, y in product(range(m), repeat=2):
        if aa[x+i][y+j] != bb[x][y]:
            ok = False
            break
    if ok:
        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())
strb=""
for i in range(m):
  strb+=B[i]
z=len(A[0])
x=len(B[0])
for i in range(z-x+1):
  Q=""
  for j in range(n):
    Q+=A[j][i:i+x+1]
  if strb in Q:
    print("Yes")
    exit()
print("No")

Submission status: Accepted

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


N, M = map(int, input().split())

A = []

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

B = []

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

flg = False

for i in range(N - M + 1):
    for j in range(N - M + 1):
        if match(i, j):
            flg = True

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

Submission status: Accepted

Solution code:
def fun():
     print('ac')
     print('AC')
     print('ACAC')
     print('ac')
N,M=map(int,input().split())
ls=[]
l=[]
result=0

for i in range(N):
     x=input()
     ls.append(x)
for i in range(M):
     y=input()
     l.append(y)
for i in range(0,N-M+1):
     k=0
     for t in range(0,N-M+1):
          if l[k] == ls[i][t:t+M]:
               for g in range(1,M):
                    if l[g]!=ls[g+i][t:t+M]:
                         break
               else:
                    result=1
if result==1:
     print('Yes')
else:
     print('No')

Submission status: Accepted

Solution code:
import numpy as np
n,m=map(int,input().split())
L1,L2=[],[]
for s in range(n):
  L1.append(list(input()))
for s in range(m):
  L2.append(list(input()))
L1,L2=np.array(L1),np.array(L2)
for s in range(n-m+1):
  for t in range(n-m+1):
#    print(L1[s:s+m,t:t+m],L2)
    if np.all(L1[s:s+m,t:t+m]==L2):
      print("Yes")
      exit()
print("No")

Submission status: Accepted

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

for i in range(n):
    a[i] = input()
for i in range(m):
    b[i] = input()

ans=0
for x in range(n-m+1):
    for y in range(n-m+1):
        k=0
        for i in range(m):
            if k != 0:
                break
            for j in range(m):
                if k != 0:
                    break
                if a[y+j][x+i] != b[j][i]:
                    k=1
        if k==0:
            ans=1

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

Submission status: Accepted

Solution code:
import sys

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

            if flag==0:
                break

        else:
            print("Yes")
            sys.exit()


else:
    print("No")

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
A = [[ch for ch in input()] for _ in range(N)]
B = [[ch for ch in input()] for _ in range(M)]
for ai in range(len(A)-len(B)+1):
    for aj in range(len(A)-len(B)+1):
        trimmed=[]
        for i_trimmer in range(ai,ai+len(B)):
            line=[]
            for j_trimmer in range(aj,aj+len(B)):
                line.append(A[i_trimmer][j_trimmer])
            trimmed.append(line)
        if trimmed==B:
            print('Yes')
            exit(0)

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)])
na = n - (m-1)
ans = 'No'

for i in range(na):
    A1 = ''.join([a[i:i+m] for a in A])
    if B in A1:
        ans = 'Yes'
        break
        
print(ans)

Submission status: Accepted

Solution code:
int_n, int_m = map(int, input().split())

li_a = list()
li_b = list()

for i in range(int_n):
    li_a.append(input())

for i in range(int_m):
    li_b.append(input())


for x in range(int_n - int_m + 1):
    for y in range(int_n - int_m + 1):
        li_w = [a[0 + x: int_m + x] for a in li_a[0 + y: int_m + y]]
        if "".join(li_w) == "".join(li_b):
            print("Yes")
            exit(0)
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())
if m > n:
    print('No')
    exit(0)
for j in range(n - m + 1):
    for i in range(n - m + 1):
        flag = 0
        for k in range(m):
            if A[j + k][i: i + m] == B[k][:]:
                flag = 1
                continue
            flag = 0
            break
        if flag == 1:
            print('Yes')
            exit(0)
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())
if m > n:
    print('No')
    exit(0)
for j in range(n - m + 1):
    for i in range(n - m + 1):
        flag = 1
        for k in range(m):
            if A[j + k][i: i + m] != B[k]:
                flag = 0
                break
        if flag == 1:
            print('Yes')
            exit(0)
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 = 'No'
for i in range(n - m + 1):
    sel = []
    for j in range(n):
        sel.append(a[j][i: i + m])
    for k in range(n - m + 1):
        tar = sel[k:k + m]
        if b == tar:
            ans = 'Yes'
            break

print(ans)

Submission status: Accepted

Solution code:
N, M = [int(_) for _ in input().split()]
A = [input() for i in range(N)]
B = [input() for i in range(M)]
 
def check(N, M, A, B):
    for i in range(N - M + 1):
        for j in range(N - M + 1):
            if all(a[j:j+M] == b for a, b in zip(A[i:i+M], B)):
                return True
    return False
 
if check(N, M, A, B):
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
x,y =[],[]
for i in range(n):
    x.append(list(input()))
for i in range(m):
    y.append(list(input()))
for i in range(n-m+1):
    for j in range(n-m+1):
        for a in range(m):
            s = True
            for b in range(m):
                if x[i+a][j+b] != y[a][b]:
                    s = False
                    break
            if not s:
                break
        if s:
            print("Yes")
            exit()
print("No")

Submission status: Accepted

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

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

if check(N, M, A, B):
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
import sys
n, m = map(int, input().split())
image = []
temp = []
match = False
for i in range(n):
  image.append(input())
for i in range(m):
  temp.append(input())
for i in range(n):
  for j in range(n - m + 1):
    if (temp[0] == image[i][j : j + m]):
      match = True
      for k in range(1, m):
        if (i + k >= n):
          match = False
          break
        elif (temp[k] != image[i + k][j : j + m]):
          match = False
          break
      if (match == True):
        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)]
for h in range(n-m+1):
    for k in range(n-m+1):
        if [a[i][k:k+m] for i in range(h, h+m)] == b:
            print("Yes")
            break
    else:
        continue
    break
else:
    print("No")

Submission status: Accepted

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

for i in range(N-M+1):
  for j in range(N-M+1):
    count = 0
    for p in range(M):
        for q in range(M):
          if N_[i+q][j+p] == M_[p][q]:
            count = count + 1
    if count == M*M:
      break
  else:
      continue
  break
if count == M*M:
  print('Yes')
else:
  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)]

f=False
for i in range(n-m+1):
    for j in range(n-m+1):
        sc=0
        for k in range(m):
            for l in range(m):
                if a[k+i][l+j]==b[k][l]:
                    sc+=1
        if sc==m*m:
            f=True
print("Yes" if f 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)]
C = []

for i in range(N-M+1):
    for j in range(N-M+1):
        tmp = []
        for k in range(i,i+M):
            tmp.append(A[k][j:j+M])
        C.append(tmp)

if B in C: print('Yes')
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)]

ans = 'No'
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 B == C:
            ans = 'Yes'
            break
            
print(ans)

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 = 'No'
for i in range(n - m + 1):
    C = []
    for j in range(n):
        C.append(A[j][i : i + m])
    for k in range(n - m +1):
        if B == C[k : k + m]:
            ans = 'Yes'
            break
            
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)]

ans = 'No'
for i in range(n - m + 1):
    for j in range(n - m + 1):
        C = []
        for k in range(m):
            c = A[i + k][j : j + m]
            C.append(c)
        if B == C:
            ans = 'Yes'
            break
print(ans)

Submission status: Accepted

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

ans = "No"

for i in range(N-M+1):
	for j in range(N-M+1):
		c = 0
		for k in range(M):
			for l in range(M):
				if A[i+k][j+l] == B[k][l]:
					c+=1
		if c == M**2:
			ans = "Yes"
			break

print(ans)

Submission status: Accepted

Solution code:
import numpy as np 

n,m = map(int,input().split())
a,b=[],[]

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

anp=np.array(a)
bnp=np.array(b)

for ax in range(n-m+1):
    for ay in range(n-m+1):
        crnt=anp[ax:ax+m,ay:ay+m]
        if (crnt==bnp).all():
            print('Yes')
            exit()
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)]
def match(x,y):
    for i in range(m):
        for j in range(m):
            if a[i+x][j+y]!=b[i][j]:
                return False
    return True
flag=False
for i in range(n-m+1):
    for j in range(n-m+1):
        if match(i,j):
            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)]

for i in range(len(A)-len(B)+1):
  tmp=A[i].find(B[0])
  if tmp==-1:
    continue
  else:
    newA=[a[tmp:tmp+len(B[0])] for a in A[i:i+len(B)]]
    if newA==B:
      print('Yes')
      break
else:
  print('No')

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
listA=[]
listB=[]
index1=0
while index1 < n:
    a = list(input())
    listA.append(a)
    index1+=1
index2=0
while index2 < m:
    b = list(input())
    listB.append(b)
    index2+=1


yesFlag=0
index1=0
while index1 < n-m+1 and yesFlag == 0:
    index2=0
    while index2 < n-m+1 and yesFlag == 0:
        indexTate = index1
        flag=0
        while indexTate < index1+m and yesFlag == 0:
            indexYoko = index2
            while indexYoko < index2+m and yesFlag == 0:
                if listA[indexTate][indexYoko] == listB[indexTate-index1][indexYoko-index2]:
                    indexYoko+=1
                else:
                    flag=1
                    break
            if flag == 1:
                break
            elif flag == 0 and indexTate == index1+m-1:
                yesFlag=1
                print("Yes")
            else:
                indexTate+=1
        index2+=1
    index1+=1
if yesFlag == 0:
    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):
        f = True
        for k in range(m):
            if a[i+k][j:j+m] != b[k]:
                f = False
                break
        if f:
            print('Yes')
            exit()

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):
        flag = True
        for k in range(M):
            if A[i+k][j:j+M] != B[k]:
                flag = False
                break
        if flag:
            print('Yes')
            exit()
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())
ans = 0
for i in range(N - M + 1):
    for j in range(N - M + 1):
        ans = 1
        for mi in range(M):
            for mj in range(M):
                if B[mi][mj] != A[i+mi][j+mj]:
                    ans = 0
                    break
            if ans == 0:
                break
        if ans == 1:
            break
    if ans == 1:
        break
if ans == 1:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
from itertools import product

n, m = [int(x) for x in input().split()]

a = [input() for x in range(n)]
b = [input() for x in range(m)]
ret = 'No'

for i, j in product(range(n - m + 1), range(n - m + 1)):
    if all([a[i + k][j:m + j] == x for k, x in enumerate(b)]):
        ret = 'Yes'
        break
print(ret)

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

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

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

Submission status: Accepted

Solution code:
I=input;n,m=map(int,I().split());a=[I()for _ in[0]*n];b=[I()for _ in[0]*m];print('YNeos'[all(b!=[t[j:j+m]for t in a[i:i+m]]for i in range(n-m+1)for j in range(n-m+1))::2])

Submission status: Accepted

Solution code:
I=input;n,m=map(int,I().split());a=[I()for _ in[0]*n];b=[I()for _ in[0]*m];r=n-m+1;print('YNeos'[sum(sum(b==[t[j:j+m]for t in a[i:i+m]]for j in range(r))for i in range(r))<1::2])

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
a=[list(input())for i in range(n)]
t=[list(input())for i in range(m)]
c=0
p=[]
for i in range(n-m+1):
    d=a[i:i+m]
    for h in range(n-m+1):
        for j in range(m):
            s=d[j]
            p.append(s[h:h+m])
        else:
            if p==t:
                c=1
            else:
                p=[]
print("No"if c!=1else"Yes")

Submission status: Accepted

Solution code:
# ABC 054
def getIntList(): return [int(x) for x in input().split()]

N, M = getIntList()
A = []
for i in range(N):
    A.append(input())
B = []
for i in range(M):
    B.append(input())
#print(N,M)#
#print(A)#
#print(B)#
for i in range(N-M+1):
    for j in range(N-M+1):
        match = True
        for p in range(M):
            for q in range(M):
                if B[p][q]!=A[i+p][j+q]:
                    match = False
                    break
            if not match: break
        if match: break
    if match: break
#print(i,j)#
if match: print('Yes')
else: print('No')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

n,m=map(int,input().split())
ln=[list(input()) for i in range(n)]
lm=[list(input()) for i in range(m)]

flg=0
for i in range(n-m+1):
  for j in range(n-m+1):
    if ln[i][j:j+m]==lm[0][0:]:
      flg=1
      for k in range(m-1):
        if ln[i+k+1][j:j+m]!=lm[k+1][0:]:
          flg=0
    if flg==1:
      print("Yes")
      sys.exit()
print("No")

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):
        ans = True
        for ii in range(M):
            for jj in range(M):
                if A[i+ii][j+jj] != B[ii][jj]: 
                    ans = False
        if ans:
            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)]
for i in range(n - m + 1):
    for j in range(n - m + 1):
        flag = True
        for k in range(m):
            if a[k + j][i:i + m] != b[k]:
                flag = False
                break
        if flag:
            print("Yes")
            exit()
print("No")

Submission status: Accepted

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

for i in range(n-m+1):
    for j in range(n-m+1):
        N_ = []
        for k in range(m):
            N_.append(N[i+k][j:j+m])
        if N_ == M:
            print('Yes')
            exit()
print('No')

Submission status: Accepted

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

for i in range(m):
    row = str(input())
    M.append(row)
for i in range(n):
    row = str(input())
    N.append(row)

for i in range(m-n+1):
    for j in range(m-n+1):
        M_ = []
        for k in range(n):
            M_.append(M[i+k][j:j+n])
            if M_ == N:
                print("Yes")
                exit()
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) ]
for i in range(N-M+1):
    for j in range(N-M+1):
        C = [ A[j+k][i:i+M] for k in range(M) ]
        if B==C:
             print("Yes")
             exit()
print("No")

Submission status: Accepted

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

ans = 'No'
for i in range(N-M+1):
    for j in range(N-M+1):
        isDiff = False
        for di in range(M):
            for dj in range(M):
                if Ass[i+di][j+dj] != Bss[di][dj]:
                    isDiff = True
                    break
            if isDiff:
                break
        else:
            ans = 'Yes'

print(ans)

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 = "No"
for i in range(N-M+1):
    for j in range(N-M+1):
        count = 0
        for k in range(M):
            for l in range(M):
                if B[k][l] == A[i+k][j+l]:
                    count += 1
        if count == M*M:
            ans = "Yes"
            break
    else:
        continue
    break
print(ans)

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):
        flag = 0
        for k in range(m):
            for l in range(m):
                if a[i + k][j + l] != b[k][l]:
                    flag = 1
        if flag == 0:
            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())
eflag=False
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 B[k][l]!=A[i+k][j+l]:
                    flag=False
                    break
            if flag==False:
                break
        if flag:
            eflag=True
if eflag:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
def is_equal(i,j,m):
    d = 0
    for k in range(m):
        if a[i+k][0][j:j+m] == b[k][0][::]:
            d = 0
        else:
            return False
    if d == 0:
        return True

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

for i in range(n-m+1):
    ans = 0
    for j in range(n-m+1):
        if is_equal(i,j,m):
            ans =1
            break
    if ans == 1:
        break
if ans == 1:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
def isSame(h, w):
    for i in range(h, h+m):
        for j in range(w, w+m):
            # print(i, j)
            if A[i][j] != B[i-h][j-w]:
                return False
    return True


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

for i in range(0, n-m+1):
    for j in range(0, n-m+1):
        if isSame(i, j) is True:
            print("Yes")
            exit()
print("No")

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
L=[]
S=[]
for i in range(N):
    x = input()
    l=[y for y in x]
    L.append(l)
for i in range(M):
    x = input()
    s=[y for y in x]
    S.append(s)
flag = 0
sum = 0
for i in range(N):
    for j in range(N):
        for k in range(M):
            for l in range(M):
                if i+k < N and j+l < N:
                    if L[i+k][j+l] == S[k][l]:
                        sum += 1
                        if sum == M * M:
                            flag = 1
                    else:
                        sum = 0
                else:
                    sum = 0
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(0, N - M + 1):
    for j in range(0, N - M + 1):
        isOk = True
        for p in range(M):
            for q in range(M):
                if A[i + p][j + q] != B[p][q]:
                    isOk = False
                    break
            if not isOk:
                break
        else:
            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())
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 b[k][l]!=a[i+k][j+l]:
          f=False
    if f:
      print('Yes')
      exit()
print('No')

Submission status: Accepted

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

Submission status: Accepted

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

a=[]
b=[]

for i in range(N):
    a.append(input())

N=0

for i in range(M):
    b.append(input())
    if(b[i] in a[i]):
        N+=1

if(N==M):
    print("Yes")
else:
    print("No")
#コピペです。

Submission status: Accepted

Solution code:
line = input().split(" ")
n = int(line[0])
m = int(line[1])
a = []
b = []

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

for nh in range(n-m+1):
    for nw in range(n-m+1):
        for k in range(m):
            s1 = a[nh+k][nw : nw+m]
            s2 = b[k]
            if s1 != s2:
                break
        else:
            print("Yes")
            exit()

print("No")

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-


def main():
    """Function."""
    n, m = map(int, input().split())

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

    flag = 0
    for i in range(n - m + 1):
        for j in range(n - m + 1):
            dum = []
            for x in range(m):
                if pic_n[i+x][j:j+m] != pic_m[x]:
                    dum.append(0)
                else:
                    dum.append(1)

            if 0 in dum:
                continue
            else:
                flag = 1
        if flag == 1:
            break

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


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
nlis = []
for i in range(N):
    nlis.append(input())
mlis = []
for i in range(M):
    mlis.append(input())
k = N-M
for i in range(k+1):
    for j in range(k+1):
        l = []
        for o in range(M):
            l.append(nlis[i+o][j:j+M])
        if l == mlis:
            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)]

cnt = 0
tmp = []
for a in A:
  for b in B:
    if(tmp != B):
      if(b in a):
        tmp.append(b)
    else:
      break
if(tmp == B):
  print("Yes")
else:
  print("No")

Submission status: Accepted

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

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

judge = "No"

for i in range(N - M + 1):
	for j in range(N - M + 1):
		c = "Yes"
		for k in range(M):
			for l in range(M):
				if AL[i + k][j + l] != BL[k][l]:
					c = "No"
					break
		if c == "Yes":
			judge = "Yes"

print(judge)

Submission status: Accepted

Solution code:
n = 0
m = 0
aa = []
bb = []


def match(y0, x0):
    global m, aa, bb
    for i, y in enumerate(range(y0, y0 + m)):
        if aa[y][x0:(x0 + m)] != bb[i]:
            return False
    return True


def main():
    global n, m, aa, bb
    n, m = map(int, input().split())
    aa = [input() for _ in range(n)]
    bb = [input() for _ in range(m)]
    for y0 in range(n - m + 1):
        for x0 in range(n - m + 1):
            if match(y0, x0):
                print('Yes')
                return
    print('No')


if __name__ == '__main__':
    main()