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:
def main():
    n,m = map(int,input().split()) 
    a=[]
    b=[]
    for _ in range(n):
        a.append( list(input()) )
    for _ in range(m):
        b.append( list(input()) )
    key=0
    for i in range(n-m+1):
        for j in range(n-m+1):
            for x in range(m):
                for y in range(m):
                    if b[x][y]==a[i+x][j+y]:
                        continue
                    else:
                        key=1
                        break
                if key==1:
                    break
            if key == 0:
                print("Yes")
                return
            key=0
    print("No")
main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, m = [int(x) for x in input().split()]
img_a = [input() for _ in range(n)]
img_b = [input() for _ in range(m)]

found = False
for a in range(n - m + 1):
    border = 0
    isok = True
    while isok and not found:
        for b in range(m):
            if img_b[b] in img_a[b+a][border:]:
                if b == 0:
                    index = img_a[a].index(img_b[0], border)
                current_index = img_a[b+a].index(img_b[b], border)
                if current_index == index:
                    continue
                elif current_index > index:
                    border = current_index
                    break
                else:
                    border = index
                    break
            else:   # if not substring in string.
                isok = False
                break

        else: # if not loop broken.
            ans = "Yes"
            found = True
            break
    if found:
        break
else: # if not 'found==True' even after last loop, then it means B is not in A.
    ans = "No"
        
print(ans)

Submission status: Accepted

Solution code:
n, m = [int(x) for x in input().split()]
img_a = [input() for _ in range(n)]
img_b = [input() for _ in range(m)]

flag = False
for a in range(n - m + 1):
    border = 0
    isok = True
    while isok and not flag:
        for b in range(m):
            if img_b[b] in img_a[b+a][border:]:
                if b == 0:
                    index = img_a[a].index(img_b[0], border)
                current_index = img_a[b+a].index(img_b[b], border)
                if current_index == index:
                    continue
                elif current_index > index:
                    border = current_index
                    break
                else:
                    border = index
                    break
            else:   # if not substring in string.
                isok = False
                break

        else: # if not loop broken.
            ans = "Yes"
            flag = True
            break
    if flag:
        break
else:
    ans = "No"
        
print(ans)

Submission status: Accepted

Solution code:
n, m = [int(x) for x in input().split()]
img_a = [input() for _ in range(n)]
img_b = [input() for _ in range(m)]

ans = "No"
for a in range(n - m + 1):
    border = 0
    isok = True
    while isok:
        for b in range(m):
            if img_b[b] in img_a[b+a][border:]:
                if b == 0:
                    index = img_a[a].index(img_b[0], border)
                current_index = img_a[b+a].index(img_b[b], border)
                if current_index == index:
                    continue
                elif current_index > index:
                    border = current_index
                    break
                else:
                    border = index
                    break
            else:   # if not substring in string.
                isok = False
                break

        else: # if not loop broken.
            ans = "Yes"
            break
        
print(ans)

Submission status: Accepted

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

for i in range(n):
    img_a.append(input())

for i in range(m):
    img_b.append(input())

ans = "No"
for a in range(n - m + 1):
    border = 0
    flag = True
    while flag:
        for b in range(m):
            if img_b[b] in img_a[b+a][border:]:
                if b == 0:
                    index = img_a[a].index(img_b[0], border)
                current_index = img_a[b+a].index(img_b[b], border)
                if current_index == index:
                    continue
                elif current_index > index:
                    border = current_index
                    break
                else:
                    border = index
                    break
            else:   # if not substring in string.
                flag = False
                break

        else: # if not loop broken.
            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 l_i in range(n-m+1):
  for n_i in range(n-m+1):
    sub_A = [A[l_i+m_i][n_i:n_i+m] for m_i in range(m)]
    if sub_A == B:
      ans = 'Yes'
      
print(ans)

Submission status: Accepted

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

A = [input() for _ in range(N)]
B = "".join([input() for _ in range(M)])

for i in range(N - M + 1):
    for j in range(N - M + 1):
        A_ = "".join([A[k][j:(j+M)] for k in range(i, i + M)])
        if B == A_:
            print("Yes")
            exit()
print("No")

Submission status: Accepted

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

#pat_match
def pat_match(Temp, temp_w, temp_h, Big_pic, ind_w, ind_h):
  for i in range(temp_h):
    for j in range(temp_w):
      if Temp[i][j] != Big_pic[i + ind_w][j + ind_h]:
        return False
  else:
    return True

#print(pat_match(B, 2, 2, A, 0, 0))
import sys
for i in range(0, n-m+1):
  for j in range(0, len(A[0]) - len(B[0]) + 1):
    if pat_match(B, len(B[0]), m, A, j, i):
      print("Yes")
      sys.exit()
else:
  print("No")

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
imgA = [input() for i in range(N)]
imgB = [input() for i in range(M)]
flag = -1
flags = []

for i in range(N - M + 1):
    while True:
        flag = imgA[i].find(imgB[0], flag+1)
        if flag >= 0:
            for j in range(1, M):
                if imgA[i+j].find(imgB[j], flag) == flag:
                    continue
                else:
                    break
            else:
                print('Yes')
                exit()
        else:
            break
else:
    print('No')

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
A = [input().strip() for _ in range(N)]
B = [input().strip() for _ 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 B[k][l] != A[i+k][j+l]:
                    flag=1
                    break
            if flag==1:break
        if flag==0:break
    if flag==0:break
if flag==0:
    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 a:
    for j in b:
        if j not in i:
            print('No')
            quit()
print('Yes')

Submission status: Accepted

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heapify,heappop,heappush
import sys,bisect,math,itertools,string,queue
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

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

n,m = inpl()
a = []
b = []
for i in range(n):
    a.append(input())
for i in range(m):
    b.append(input())

bb = True
for i in range(n-m+1):
    for j in range(n-m+1):
        if check(i,j):
            print('Yes')
            quit()
print('No')

Submission status: Accepted

Solution code:
import numpy as np
n, m = map(int, input().split())
a = np.zeros((n, n))
b = np.zeros((m, m))
for i in range(n):
    for j, s in enumerate(input()):
        if s == "#": a[i][j] = 1
for i in range(m):
    for j, s in enumerate(input()):
        if s == "#": b[i][j] = 1
for i in range(n - m + 1):
    for j in range(n - m + 1):
        sa = a[i:i+m, j:j+m]
        if not np.sum(np.logical_xor(sa, b)):
            print("Yes")
            exit()
print("No")

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
A = []
B = []
ans = 'No'
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 A[i][j:M+j+1] == B[0]:
            D = 0
            for k in range(i,i+M):
                for l in range(0,M):
                    if A[k][j:M+j+1] == B[l]:
                        D += 1
            if D == M:
                ans = 'Yes'
if ans == 'Yes':
    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())
def check(i,j): 
    if i+m>n or j+m>n:
        return 0 
    a1=-1 
    for x in range(i,i+m):
        a1+=1 
        b1=0 
        for y in range(j,j+m):
            if b[a1][b1]!=a[x][y]:
                return 0 
            b1+=1 
    return 1 
for i in range(n):
    for j in range(n): 
        if check(i,j):
            print('Yes')
            exit()
print('No')
#print(a,b)

Submission status: Accepted

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

for i in range(N - M + 1):
  for j in range(N - M + 1):
    #start = A[i][j]
    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 == 0:
      print("Yes")
      quit()
  
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)]


def solve():
    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]
            if "".join(b) == c:
                print("Yes")
                return
    print("No")


solve()

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

Submission status: Accepted

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

ans = "No"

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

for j in range(M):
    B[j] = list(input())

for k in range(N-M+1):
    for l in range(N-M+1):
        det = 0
        for x in range(M):
            for y in range(M):
                if A[k+x][l+y] != B[x][y]:
                    det = -1
        if det == 0:
            ans = "Yes"

print(ans)

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

ok = False
for i in range(n - m + 1):
    for j in range(n - m + 1):
        tmp = [a[k][j: j + m] for k in range(i, i + m)]
        if tmp == b:
            ok = True
            break
if ok:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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


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

    for ay in range(0, N-M+1):
        for ax in range(0, N-M+1):
            m = 0
            for by in range(M):
                for bx in range(M):
                    if A[ay + by][ax + bx] == B[by][bx]:
                        m += 1
                        if m == M*M:
                            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)]

def check():
    for i in range(n-m+1):
        for j in range(n-m+1):
            for k in range(m):
                if b[k] != a[j+k][i:i+m]:
                    break
            else:
                return "Yes"

    return "No"

ans = check()

print(ans)

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 x in range(N-M+1):
  for y in range(N-M+1):
    t=1
    for i in range(M):
      for j in range(M):
        if A[x+i][y+j]!=B[i][j]:
          t=0
    if t==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)]
 
ans=0        
for i in range(n-m+1):
    for j in range(n-m+1):
        if [a[j:j+m] for a in A[i:i+m]] == B:
            ans=1
        
        
if ans == 1:
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

for y in range(N - M + 1):
    for x in range(N - M + 1):
        mc = 0
        for i in range(M):
            for j in range(M):
                if A[y + i][x + j] == B[i][j]:
                    mc += 1
                else:
                    break
            else:
                continue
            break
        if mc == M * M:
            print("Yes")
            exit()
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):
        new = [A[k][j:j+M] for k in range(i,i+M)]
        if new == B:
            print('Yes')
            sys.exit()
print('No')

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
l=[]
for i in range(n):
    l.append(list(input()))
k=[]
for i in range(m):
    k.append(list(input()))
f=0
for i in range(n-m+1):
    for j in range(n-m+1):
        t=0
        for p in range(m):
            for q in range(m):
                if k[p][q]==l[i+p][j+q]:
                    t+=1
        if t==m*m:
            f+=1
if f>0:
    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)]


for i in range(N-M+1):
    for j in range(N-M+1):
        if A[i][j] == B[0][0]:
            for x in range(M):
                ta = A[i][j:j+M:]
                if ta != B[x]:
                    break
                i += 1
            else:
                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):
    #ここで左上の位置を固定。
    #この配置について、「m*mが全てこの位置のaに一致するか」を調べる。
    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==False:
        break
    if flag:
      print("Yes")
      exit()
        #一致しない場合は、この配置についての確認を終えるため、2段目のfor文に戻りたい…
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 j in range(n-m+1):
        if [a[j:j+m] for a in A[i:i+m]] == B:
            ans=1
        
        
if ans == 1:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
from itertools import permutations
def main():
  n, m = map(int, input().split())
  a=[]
  for i in range(n):
    a.append(input())
  b = ""
  for j in range(m):
    b += input()
  for i in range(n - m + 1):
    for j in range(n - m + 1):
      x = ""
      for k in range(m):
        x += a[j+k][i: i + m]
      if b == x:
        print("Yes")
        return
  print("No")
main()

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
a=[input()for _ in range(n)]
b=[input()for _ in range(m)]
x=n-~-m
C=0
for i in range(x):
    for j in range(x):
        c=0
        for k in range(m):
            if a[i+k][j:j+m]==b[k]:
                c+=1
        if c==m:
            C+=1
print('YNeos'[C<1::2])

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 = 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]:
                    flag = True
                else:
                    flag = False
                    break
    if k == m-1 and l == m-1 and flag:
        break

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 a:
  for j in b:
    if j not in i:
      print("No")
      quit()
print("Yes")

Submission status: Accepted

Solution code:
from sys import exit, stdin
N, M = [int(_) for _ in stdin.readline().rstrip().split()]
A = [stdin.readline().rstrip() for n in range(N)]
B = [stdin.readline().rstrip() for m in range(M)]
for i in range(N-M+1):
  for j in range(N-M+1):
    tmp = [a[j:j+M] for a in A[i:i+M]]
    if tmp == B:
      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)]
c = any([c[j:j+m] for c in a[i:i+m]] == b
        for j in range(n-m+1) for i in range(n-m+1))
print('Yes' if c else '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):
    for j in range(n):
        if a[i][j] == b[0][0]:
            if j+m <= n and i+m <= n:
                if [a[i+k][j:j+m] for k in range(m)] == b:
                    print('Yes')
                    exit()
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)]

for i in range(n):
    for j in range(n):
        if j+m <= n and i+m <= n:
            if [a[i+k][j:j+m] for k in range(m)] == b:
                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) ]

for i in range(N-M+1):
  l = 0
  for _ in range(A[i].count(B[0])):
    l = A[i].index(B[0], l)
    result = True
    for k in range(1, M):
      if B[k] != A[i+k][l:l+len(B[k])]:
        result = False
        break
    if result:
      print("Yes")
      exit()
    l += 1
      
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 _ in range(A[i].count(B[0])):
    l = A[i].index(B[0])
    result = True
    for k in range(1, M):
      if B[k] != A[i+k][l:l+len(B[k])]:
        result = False
        break
    if result:
      print("Yes")
      exit()
    l += 1
      
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)]
import sys
for a in A:
    for b in B:
        if b not in a:
            print('No')
            sys.exit()
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)]
ans =0
for i in range(n-m+1):
  for j in range(n-m+1):
    if [a[j:j+m] for a in a[i:i+m]]==b:
      ans =1
print('Yes' if ans ==1 else 'No')

Submission status: Accepted

Solution code:
a,b = map(int,input().split())
li1 = [input() for i in range(a)]
li2 = [input() for i in range(b)]
#print(li1,li2)
for i in range(a-b+1):
    for j in range(a-b+1):
        flag = True
        for k in range(b):
            if li1[i+k][j:j+b] != li2[k]:
                flag = False
                break
        if flag:
            print("Yes")
            exit()
print("No")

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
A=[input() for n in range(N)]
B=[input() for m in range(M)]
wb=len(B[0])
hb=len(B)
for h in range(len(A)-hb+1):
    for w in range(len(A[0])-wb+1):
        f=True
        for b in range(hb):
            if A[h+b][w:w+wb] != B[b]:
                f=False
                break
        if f:
            print('Yes')
            exit()
print('No')

Submission status: Accepted

Solution code:
def slove():
    import sys
    input = sys.stdin.readline
    n, m = list(map(int, input().rstrip('\n').split()))
    a = [list(str(input().rstrip('\n'))) for _ in range(n)]
    b = [list(str(input().rstrip('\n'))) for _ in range(m)]
    for i in range(n - m + 1):
        for j in range(n - m + 1):
            b_y = True
            for k in range(i, i + m):
                for l in range(j, j + m):
                    if a[k][l] != b[k-i][l-j]:
                        b_y = False
                        break
            if b_y:
                print("Yes")
                exit()
    print("No")


if __name__ == '__main__':
    slove()

Submission status: Accepted

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

for i in range(n - m + 1):
  for j in range(n - m + 1):
    temp = 0
    for k, one_b in enumerate(list_b):
      if one_b == list_a[j+k][i:(i+m)]:
        temp += 1
      else:
        break
    if temp == m:
      print("Yes")
      exit()
print("No")

Submission status: Accepted

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

def create_coords(x, y, l):
    return [(_x, _y) for _x in range(x, x + l) 
                     for _y in range(y, y + l)]

def concat(li, coords):
    return ''.join(map(lambda c: li[c[0]][c[1]], coords))

def main():
    ans = 'No'
    r = range(N - M + 1)
    l = M
    b = concat(B, create_coords(0, 0, l))
    for x in r:
        for y in r:
            a = concat(A, create_coords(x, y, l))
            if a == b:
                ans = 'Yes'
                break
    print(ans)

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 i in range(n-m+1):
    if b[0] in a[i]:
        x=a[i].index(b[0])
        st=0
        for j in range(1,m):
            for k in range(m):
                if a[i+j][x+k]!=b[j][k]:
                    st=1
                    break
        if st==0:
            print('Yes')
            exit()
print('No')

Submission status: Accepted

Solution code:
import sys
n, m = map(int, input().split())
a_list = sum([input().split() for i in range(n)], [])
b_list = sum([input().split() for i in range(m)], [])
for b in b_list:
    for a in a_list:
        if b not in a:
            print('No')
            sys.exit()
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)]

point=0

for nx in range(N-M+1):
  for ny in range(N-M+1):
    ans=[a[ny:ny+M] for a in A[nx:nx+M]]
    if ans == B:
      point+=1

if point==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): 
  c = a[i].find(b[0]) 
  if c != -1:
    for k in range(m-1):
      if a[i+k+1][c:c+m] != b[k+1]:
        break
    else:
      print("Yes")
      break
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):
        for k in range(m):
            for l in range(m):
                if a[k + i][l + j] != b[k][l]:
                    break
            else:
                continue
            break
        else:
            print('Yes')
            exit()
print('No')

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
A = ["" for i in range(N)]
for i in range(N):
    A[i] = input()
B = ["" for i in range(M)]
for i in range(M):
    B[i] = input()
    
matched = False
for i in range(N - M + 1):
    for j in range(N - M + 1):
        matched = True
        for k in range(M):
            for l in range(M):
                if A[i + k][j + l] != B[k][l]:
                    matched = False
        if matched:
            break
    if matched:
        break

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

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
a = []
for i in range(n):
    a0 = list(input())
    a.append(a0)
b = []
for i in range(m):
    b0 = list(input())
    b.append(b0)
now = [0,0]
ans = "No"
count = 0
while now[0] <= n-m and now[1] <= n-m:
    #print([now[0] + count//m,now[1]+count%m],[count//m,count%m])
    if a[now[0] + count//m][now[1]+count%m] == b[count//m][count%m]:
        count += 1
    else:
        count = 0
        if now[1] < n-m:
            now[1] += 1
        else:
            now[1] = 0
            now[0] += 1
    if count == m*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)]

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[k + i][l + j] != B[k][l]:
                    break
            else:
                continue
            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)]

for i in range(n - m + 1):
    for j in range(n - m + 1):
        tmp = 0
        for k in range(m):
            for l in range(m):
                if a[i + k][j + l] == b[k][l]:
                    tmp += 1
        if tmp == m ** 2:
            print("Yes")
            exit()
print("No")

Submission status: Accepted

Solution code:
N, M = tuple(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 y in range(M):
            for x in range(M):
                if A[i+y][j+x] != B[y][x]:
                    flag = False
        if flag:
            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 = [list(input()[:-1]) for _ in range(N)]
    B = [list(input()[:-1]) for _ in range(M)]

    for i in range(N-M+1):
        for j in range(N-M+1):
            flg = True
            for y in range(M):
                for x in range(M):
                    if A[i+y][j+x]!=B[y][x]:
                        flg = False
            if flg:
                print('Yes')
                return
    print('No')
    
    

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
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 l in range(N - M + 1):
        if A[i][l:l+M] == B[0]:
            for q in range(M):
                if A[i+q][l:l+M] != B[q]:
                    break
                if q == M-1:
                    print("Yes")
                    sys.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)]
flag = False

for p in range(n): #Aの中の始点の縦座標
    for q in range(n): # Aの中の始点の横座標
        # print('p,q =',p,q)
        # print(p+m-1 < n) #縦にはみ出ないかチェック
        # print(q+m-1 < n) #横にはみ出ないかチェック
        # print(all(all( a[p+i][q+j] == b[i][j] for j in range(m)) for i in range(m))) #全部のマスが同じかどうかチェック
        if p+m-1 < n and q+m-1 < n and all(all( a[p+i][q+j] == b[i][j] for j in range(m)) for i in range(m)):
            flag = True

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