Problem:


Score : 200 points

Problem Statement

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

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

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

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

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

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

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

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

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

Constraints

1≦M≦N≦50 

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

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

Input

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

N M
A_1
A_2
:  
A_N
B_1
B_2
:  
B_M

Output

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

Sample Input 1

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

Sample Output 1

Yes

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

Sample Input 2

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

Sample Output 2

No

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



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


Sample output:
Yes

Submission status: Accepted

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

a_grid = [list(input()) for _ in range(n)]
b_grid = [list(input()) for _ in range(m)]

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

Submission status: Accepted

Solution code:
ans='No'
X=''
Y=''
n=0
a,b=map(int,input().split())
x=[0]*(a*a)
y=[0]*(b*b)
for i in range(a):
    for s in input().split():
        X+=s
for i in range(b):
    for s in input().split():
        Y+=s

for h in range(a-b+1):
    for w in range(a-b+1):
        p_X=''
        for t in range(b):
            p_X+=X[(h+t)*a+w:(h+t)*a+w+b]
        if p_X==Y:
            ans='Yes'
print(ans)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
a=[input() for q in range(n)]
b=[input() for w in range(m)]
Flag=False
for i in range (n-m+1):
    for j in range (n-m+1):
        Flag=False
        for I in range(m):
            for J in range(m):
                if a[i+I][j+J]==b[I][J]:
                    continue
                else:
                    Flag=True
                    break
        if Flag:
            continue
        else:
            print("Yes")
            exit()
print("No")

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

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

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

for x in range(n-m+1):
    for y in range(n-m+1):
        f = True
        for i in range(m):
            if a[y+i][x:x+m] != b[i]:
                f = False
                break
        if f:
            break
    if f:
        break

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

Submission status: Accepted

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

frag = False
for i in range(N - K + 1):
  for j in range(N - K + 1):
    f = True
    for k in range(K):
      for l in range(K):
        if A[i + k][j + l] != B[k][l]:
          f = False
    if f:
      frag = True
print("YNeos"[not frag::2])

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

ans = "No"

for i in range(N-M+1):
    for j in range(N-M+1):
        C = []
        for k in range(i,i+M):
            C.append(A[k][j:j+M])
        if B == C:
            ans = "Yes"

print(ans)

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
a=[]
b=[]
for i in range(n):
    a1 = input()
    a.append(a1)
for i in range(m):
    b1 = input()
    b.append(b1)
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:
            print("Yes")
            exit()
print("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()
ans = False
for i in range(n-m+1):
    for j in range(n-m+1):
        tmp = True
        for k in range(m):
            if b[k] != a[i+k][j:m+j]:
                tmp = False
        if tmp:
            ans = True
if ans:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
[n,m] = [int(i) for i in input().split()]
a = []
b = []
for i in range(n):
    a.append(input())
for i in range(m):
    b.append(input())
cnt = 0
flag = "No"
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 = "Yes"
        else:
            cnt = 0
print(flag)

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)]
if n == m:
    if all(A[i]==B[i] for i in range(n)):
        print("Yes")
        exit()
    else:
        print("No")
        exit()
for i in range(n-m):
    for j in range(n-m):
        bool = True
        for l in range(m):
            if A[i+l][j:j+m] == B[l]:
                continue
            else:
                bool = False
        if bool:
            print("Yes")
            exit()
print("No")

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
n = []
m = []
for i in range(N):
  s = str(input())
  row = []
  for j in range(N):
    if s[j] == "#":
      row.append(1)
    else:
      row.append(0)
  n.append(row)
for i in range(M):
  s = str(input())
  row = []
  for j in range(M):
    if s[j] == "#":
      row.append(1)
    else:
      row.append(0)
  m.append(row)
 
def search(a,b):
  mr = mc = 0
  for r in range(a, a+M):
    for c in range(b, b+M):
      if n[r][c] != m[mr][mc]:
        return False
      mc += 1
    mr += 1
    mc = 0
  return True

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(1000000)

N,M = [int(x) for x in input().split()]
A = [input() for _ in range(N)]
B = [input() for _ in range(M)]
#%%
flag = False
for i in range(N-M):
    for j in range(N-M):
        flagx = True
        for x in range(M):
            if(A[i+x][j:j+M]!=B[x]):
                flagx = False
        if(flagx):
            flag = flag|flagx
            break

if(flag or (N==1 and M==1)):
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
data = []
for i in range(N):
  data.append(input())
input_data=[]
for i in range(M):
  input_data.append(input())
flag_1 = 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 data[i+k][j+l] != input_data[k][l]:
          flag = False
    if flag:
      flag_1 = True

if flag_1:
  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 j in range(M):
    B.append(input())
t=0
while t==0:
    for i in range(N-M+1):
        for j in range(len(A[0])-len(B[0])+1):
            m=0
            for h in range(M):
                for k in range(len(B[0])):
                    if B[h][k]==A[h+i][k+j]:
                        m+=1
            if m==M*len(B[0]):
                print('Yes')
                t=1
                break
        if t==1:
            break
    else:
        print('No')
        break

Submission status: Accepted

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

def solve(N, M, A, B):
    include = False
    for h in range(N-M+1):
        for w in range(N-M+1):
            match = True
            for i in range(M):
                for j in range(M):
                    if(A[h+i][w+j] != B[i][j]):
                        match = False
            if(match):
                include = True

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

if __name__ == '__main__':
    N, M = map(int, input().split())
    A, B = [], []
    for i in range(N):
        A.append(input())
    for j in range(M):
        B.append(input())

    solve(N, M, A, B)

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
A = [input() for _ in [0]*N]
B = [input() for _ in [0]*M]
endFlg = False
for i in range(N-M+1):
    for j in range(N-M+1):
        breakFlg = False
        for k in range(M):
            for l in range(M):
                if A[i+k][j+l] != B[k][l]:
                    breakFlg = True
                    break
            if breakFlg:break
        else:endFlg=True
        if endFlg: break
    if endFlg: break
if endFlg: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(N-M+1):
    for j in range(N-M+1):
        flag1=0
        for k in range(M):
            if B[k] != A[i+k][j:j+M]:
                flag1=1
                break
        if flag1==0:
            break
    if flag1==0:
        break
if flag1 == 0:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

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

n = N - M + 1

for i in range(n*n):
    j = i // n
    i %= n
    flag = True
    for k in range(M*M):
        l = k // M
        k %= M
        if A[j+l][i+k] != B[l][k]:
            flag = False
            break
    if flag:
        print("Yes")
        exit()

print("No")

Submission status: Accepted

Solution code:
n, m = [int(i) for i in input().split()]
a = []
b = []
flag_yes = 0
for i in range(n):
  a.append(input())
for i in range(m):
  b.append(input())
for ri in range(n-m+1):
  for ci in range(n-m+1):
    c = []
    for mi in range(m):
      c.append(a[ri+mi][ci:ci+m])
    if c == b:
      flag_yes = 1
if flag_yes == 1:
  print("Yes")
else:
  print("No")

Submission status: Accepted

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

for i in range(N-M+1):
    for j in range(N-M+1):
        NO = False
        for x in range(M):
            a = A[i+x][j:j+M]
            if a != B[x]:
                NO = True
                break
        if not NO:
            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)]

includes = False
for r in range(N - M + 1):
    for c in range(N - M + 1):
        for i in range(M):
            for j in range(M):
                if A[r + i][c + j] != B[i][j]:
                    break
            else:
                continue
            break
        else:
            includes = True

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

Submission status: Accepted

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

includes = False
for r in range(N - M + 1):
    for c in range(N - M + 1):
        matches = True
        for i in range(M):
            for j in range(M):
                if A[r + i][c + j] != B[i][j]:
                    matches = False
        if matches:
            includes = True

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

Submission status: Accepted

Solution code:
a, b = (int(i) for i in input().split())  

x = [input() for i in range(a)]
y = [input() for i in range(b)]

h = a - b + 1
w = len(x) - len(y) + 1
res = "No"

for i in range(h):
  for ii in range(w):
    if all([y[z] == x[i+z][ii:ii+len(y)] for z in range(b)]):
      res = "Yes"
      break

print(res)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
ans='No'
a=[]
b=[]
for i in range(n):
    a1=list(input())
    a.append(a1)
for j in range(m):
    b1=list(input())
    b.append(b1)
for i in range(n-m+1):
    for j in range(n-m+1):
        if b==[l[i:i+m] for l in a[j:j+m]]:
            ans='Yes'
            break
print(ans)

Submission status: Accepted

Solution code:
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()))
f = False
for i in range(N-M+1):
    for j in range(N-M+1):
        g = True
        for k in range(M):
            for l in range(M):
                if A[i+k][j+l]!=B[k][l]:
                    g = False
        if g:
            f = True
print("Yes" if f else "No")

Submission status: Accepted

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

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

l = 0
while l <= len(A[0]) - len(B[0]):
	for i in range(N - M + 1):
		s = A[i][l:]
		if not B[0] in s:
			continue
		if 0 == s.index(B[0]):
			for m in range(1, M):
				if not B[m] in A[i + m][l:]:
					break
				if 0 != A[i + m][l:].index(B[m]):
					break
			else:
				print("Yes")
				exit()
	l += 1
print("No")

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
a = ['']*n
b = ['']*m
for i in range(n):
  a[i] = str(input())
for i in range(m):
  b[i] = str(input())
for i in range(n-m+2):
  c = a[i:i+m]
  for j in range(n-m+2):
    d = [e[j:j+m] for e in c]
    if b == d:
      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):
    for j in range(N-M+1):
        if A[i][j] == B[0][0]:
            flg = True
            for k in range(M):
                if flg:
                    for l in range(M):
                        if A[i+k][j+l] != B[k][l]:
                            flg = False
                            break
            if flg:
                print('Yes')
                quit()
print('No')

Submission status: Accepted

Solution code:
# ABC054B - Template Matching
n, m = list(map(int, input().rstrip().split()))
lst_n = [input().rstrip() for _ in range(n)]
lst_m = [input().rstrip() for _ in range(m)]

for i in range(n - m + 1):
    for j in range(n - m + 1):
        if [lst_n[j + k][i : i + m] for k in range(m)] == lst_m:
            print("Yes")
            break
    else:
        continue
    break
else:
    print("No")

Submission status: Accepted

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

A = []
for i in range(n):
    A.append(input())

B = []
for j 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):
            #print(A[i+k][j:j+m], B[k])
            if A[i+k][j:j+m] != B[k]:
                break
        else:
            print('Yes')
            break
        continue
    else:
        continue
    break
else:
    print('No')

Submission status: Accepted

Solution code:



def solve():
  N,M = map(int, input().split())
  An = []
  Bn = []
  [An.append(str(input())) for i in range(N)]
  [Bn.append(str(input())) for i in range(M)]

  for i in range(0,N-M+1):
    for j in range(0,N-M+1):
      ret = True
      for k in range(M):
        if An[i+k][j:M+j] != Bn[k]:
          ret = False
      if ret:
        return True
  return False

if __name__ == "__main__":
  if solve():
    print('Yes')
  else:
    print('No')

Submission status: Accepted

Solution code:
import sys

n, m = map(int, input().split())
a_array = [input() for i in range(n)]
b_array = [input() for i in range(m)]

for ai in range(n-m+1):
    for aj in range(n-m+1):
        can = True
        for bi in range(m):
            if a_array[ai+bi][aj:aj+m] != b_array[bi]:
                can = False
                break
        if can:
            print('Yes')
            sys.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 y in range(N-M+1):
    for x in range(N-M+1):
        for k in range(M):
            if A[y+k][x:x+M] != B[k]:
                break
        else:
            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)]

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

found = False
for i in range(N-M+1):
    for j in range(N-M+1):
        if match(i,j):
            found = True
            
print("Yes") if found 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)]

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 = map(int,input().split())
a = []
b = []
for i in range(n):
    a.append(list(input()))
for i in range(m):
    b.append(list(input()))
for y in range(n-m+1):
    for x in range(n-m+1):
        judge = True
        for i in range(m):
            for j in range(m):
                # print(y+i)
                # print(x+j)
                # print(a)
                if a[y+i][x+j] != b[i][j]:
                    judge = False
        if judge:
            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)]
ans = "No"
for i in range(N-M+1):
    for j in range(N-M+1):
        ans = "Yes"
        for k in range(M):
            for l in range(M):
                #print(i+k,j+l,k,l)
                if A[i+k][j+l] != B[k][l]:
                    ans = "No"
                    break
            if ans == "No":
                break
        if ans == "Yes":
            break
    else:
        continue
    break
print(ans)

Submission status: Accepted

Solution code:


def read_input():
    n, m = map(int, input().split())

    alist = []
    for i in range(n):
        alist.append(input().strip())

    blist = []
    for i in range(m):
        blist.append(input().strip())

    return n, m, alist, blist




def submit():
    n, m, alist, blist = read_input()

    for i in range(n - m + 1):
        for j in range(n - m + 1):

            check = True
            for x in range(m):
                for y in range(m):
                    if alist[i + x][j + y] != blist[x][y]:
                        check = False
                        break
                if not check:
                    break

            if check:
                print('Yes')
                return

    print('No')


if __name__ == '__main__':
    submit()

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
a = [list(input()) for _ in range(n)]
b = [list(input()) for _ in range(m)]
for i in range(n - m + 1):
    for j in range(n - m + 1):
        flag = True
        for k in range(m):
            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())

la=[]
for i in range(N):
  la.append(input())

lb=[]
for i in range(M):
  lb.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 la[i+k][j+l]!=lb[k][l]:
          f=False
    if f:
      print('Yes')
      exit()

print('No')

Submission status: Accepted

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

As = []
for i in range(N):
    As.append(input())

Bs = []
for i in range(M):
    Bs.append(input())


for x in range(N):
    for y in range(N):
        if x + M > N or y + M > N:
            break

        flag = True
        for tx in range(M):
            for ty in range(M):
                if As[x + tx][y + ty] != Bs[tx][ty]:
                    flag = False

        if flag:
            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)]

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

for x in range (n-m+1):
    for y in range(n - m + 1):
        if same(x,y):
            print('Yes')
            import sys
            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)]
f = False
for i in range(N-M+1):
  if f:
    break
  for j in range(N-M+1):
    if f:
      break
    match = True
    for k in range(M):
      if not match:
        break
      for l in range(M):
        if not match:
          break
        if A[i+k][j+l] != B[k][l]:
          match = False
    if match:
      f = True

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

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
a = []
for _ in range(n):
    a.append(list(input()))
b = []
for _ in range(m):
    b.append(list(input()))
ans = "No"
for i in range(n-m+1):
    for j in range(n-m+1):
        aaa = 0
        for k in range(m):
            if b[k] == a[i+k][j:j+m]:
                aaa += 1
            else:
                break
        if aaa == m:
            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 = 0
for i in range(N-M+1):
    for j in range(N-M+1):
        flg = 0
        for k in range(M):
            for l in range(M):
                if A[i+k][j+l] != B[k][l]:
                    flg = 1
                    break
        if flg == 0:
            ans = 1
            break

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

Submission status: Accepted

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

ans = 'No'
for i in range((N-M+1)**2):
    y = i % (N-M+1)
    x = i // (N-M+1)
    check = True
    for j in range(M**2):
        v = j % M
        h = j // M
        if A[y+v][x+h] != B[v][h]:
            check = False
        if not check:
            break
    if check:
        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)]
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:
def check(i,j):
    for y in range(M):
        for x in range(M):
            if A[i+y][j+x] != B[y][x]:
                return False
    return True
    
[N,M] = list(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):
        if check(i,j):
            ans = "Yes"
print(ans)

Submission status: Accepted

Solution code:
import numpy as np

def fn(a, b):
    for i in range(n-m+1):
        for j in range(n-m+1):
            if np.all(b == a[i:m+i,j:m+j]):
                return True
    return False

n, m = [int(i) for i in input().split()]
a = []
for i in range(n):
    res = []
    for j in input():
        if j == ".":
            res.append(1)
        elif j == "#":
            res.append(0)
    a.append(res)
b = []
for i in range(m):
    res = []
    for j in input():
        if j == ".":
            res.append(1)
        elif j == "#":
            res.append(0)
    b.append(res)

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

if fn(a, b):
    print("Yes")
else:
    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 j in range(M):
    B.append(input())
    

for b in range(N-M+1):
    for a in range(N-M+1):
        count = 0
        for i in range(M):
            if B[i] == A[i+b][a:a+M]:
                count += 1
        if count == M:
            print('Yes')
            sys.exit()
    
print('No')

Submission status: Accepted

Solution code:
# vim: set fileencoding=utf-8:


def main():
    N, M = map(int, input().split())  # 1 <= M <= N <= 50
    A = [input() for _ in range(N)]
    B = [input() for _ in range(M)]
    ct = 0
    flag = 0
    ans = 'No'

    # N^3だとしても、50*50*50=12,500で、pythonで計算が間に合いそう

    for B_row in B:
        flag = 0
        for A_row in A:
            if(N-M) == 0:
                if B_row == A_row:
                    ct += 1
                    flag = 1
            else:
                for i in range(N-M):
                    # M <= N であるから、B_row が A_rowに含まれているかを探索していく
                    if B_row == A_row[i:M]:
                        ct += 1
                        flag = 1
                        break

            if flag == 1:
                break

    if ct == M:
        ans = 'Yes'

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys

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

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

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

found = True
for i_offset in range(0, N-M+1):
    found = True
    j_offset = A[i_offset].find(B[0])
    if j_offset < 0:
        continue
    for i in range(0, M):
        if A[i+i_offset][j_offset:j_offset+M] != B[i][0:M]:
            found = False
            break
    if found:
        print("Yes")
        sys.exit()

print("No")

Submission status: Accepted

Solution code:
n, m = list(map(int, input().split()))
a = []
b = []
for i in range(n):
    a.append(input())
for i in range(m):
    b.append(input())
ax = len(a[0])
ay = len(a)
bx = len(b[0])
by = len(b)
ans = False
for i in range(ax - bx + 1):
    for j in range(ay - by + 1):
        flag = True
        for x in range(bx):
            if not flag:
                break
            nx = x + i
            for y in range(by):
                ny = y + j
                if a[nx][ny] != b[x][y]:
                    flag = False
                    break
        if flag:
            ans = True
if ans:
    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(N - M + 1):
    for j in range(N - M + 1):
        for x in range(M):
            if A[j + x][i:i + M] != B[x]:
                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())

def match(i,j):
    # i,j <= N-M
    for k in range(M):
        row = A[i+k][j:j+M]
        if row != B[k]:
            return(False)
    return(True)

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

Submission status: Accepted

Solution code:
import numpy as np
n, m = map(int,input().split())
A = []
B = []
for i in range(n):
    a = list(input())
    A.append(a)
for i in range(m):
    b = list(input())
    B.append(b)
A_arr = np.array(A)
B_arr = np.array(B)

for h in range(n-m+1):
    for w in range(n-m+1):
        if np.all(A_arr[h:h+m, w:w+m] == B_arr):
            print("Yes")
            exit()
print("No")

Submission status: Accepted

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

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

Submission status: Accepted

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

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

print("No")

Submission status: Accepted

Solution code:
import sys

def main():
    input = sys.stdin.readline
    N, M = map(int, input().split())
    A = [str(input().strip()) for _ in range(N)]
    B = ''
    for _ in range(M):
        B += str(input().strip())

    for i in range(N-M+1):
        for j in range(N-M+1):
            a = ''
            for k in range(M):
                a += A[i+k][j:j+M]

            if a == B:
                return 'Yes'

    return 'No'


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