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=[input() for _ in range(n)]
B=[input() for _ in range(m)]

#shift回数, 1軸
num = n - m + 1

#基本はNoとして一致するのものがあればYESを表示させる
check = 'No'

#起点の設定
for i in range(num):
    for j in range(num):
        C = []
        #要素の追加
        for k in range(m):
            #CにAからM*Mで抜き出した配列を作る
            C.append(A[i+k][j:j+m])
        #Bと抜き出したCを比較して一致したらYESにしてループも抜ける
        if C == B:
            check = 'Yes'
            break
print(check)

Submission status: Accepted

Solution code:
import numpy as np

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

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

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

A=np.asarray(A)
B=np.asarray(B)
flg=False

  
for x in range(N-M):
    for y in range(N-M):
        if (A[x:x+M,y:y+M] == B).all():
            flg=True
if flg:
    print("Yes")
else:
    try:
        if (A == B).all():
            print("Yes")
        else:
            print("No")
    except:
        print("No")

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
a = [input() for _ in range(n)]
b = [input() for _ in range(m)]
ans = "Yes"
for i in range(n):
    for j in range(m):
        if b[j] not in a[i]:
            ans ="No"
print(ans)

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
S = [input() for _ in range(N)]
T = [input() for _ in range(M)]
ans = False
cnt = N - M
for i in range(cnt+1):
    for j in range(cnt + 1):
        tmp = T[0]
        check = S[i][j:M+j]
        key = 0
        if(check == tmp):
            key += 1
            for k in range(1,M):
                tmp = T[k]
                check =  S[i+k][j:M+j]
                if(check == tmp):
                    key += 1
        if(key == M):
            ans =True
            break

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

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
a=[]
b=[]
for i in range(n):
    a.append(list(input()))
for i in range(m):
    b.append(list(input()))
#print(a,b)
ans='No'
cnt=0
for i in range(n-m+1):
    for j in range(n-m+1):
        for i1 in range(m):
            for j1 in range(m):
                if b[i1][j1]==a[i+i1][j+j1]:
                    cnt+=1
        #print(cnt)
        if cnt==m**2:
            ans='Yes'
            cnt=0
        else:
            cnt=0
print(ans)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
a=[input() for _ in range(n)]
b=[input() for _ in range(m)]
ans="No"
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 C==b:
            ans="Yes"

print(ans)

Submission status: Accepted

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

def subdata(a, i, j):
  return [row[j:j + m] for row in a[i:i + m]]

def template_matching(a, b):
  for i in range(n - m + 1):
    for j in range(n - m + 1):
      if subdata(a, i, j) == b:
        return "Yes"
  return "No"

print(template_matching([input() for _ in range(n)], [input() for _ in range(m)]))

Submission status: Accepted

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

flag=False
cnt=0
for a_i in range(n-m+1):
    for a_j in range(n-m+1):
        for b_i in range(m):
            if a[a_i+b_i][a_j:a_j+m]==b[b_i]:
                cnt+=1
        if cnt==m:
            flag=True
            break
        cnt=0
print('Yes' if flag 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)]

def check(w,h):
    if w+M>N or h+M>N:
        return False
    List=[A[j][w:w+M] for j in range(h,h+M)]
    return (List==B)

ans=0
for i in range(N):
    for k in range(N):
        ans+=check(i,k)

print(['No','Yes'][ans>=1])

Submission status: Accepted

Solution code:
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N,M = MI()
    A=tuple((ST()) for _ in range(N))
    B=tuple((ST()) for _ in range(M))

    for i in range(N-M+1):
        for j in range(N-M+1):
            #check
            ok = True
            for k in range(M):
                if A[i+k][j:j+M] != B[k][:]:
                    ok=False

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

Submission status: Accepted

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

Submission status: Accepted

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

A = [[x for x in str(input())] for _ in range(n)]
B = [[x for x in str(input())] for _ in range(m)]

#shift回数, 1軸
num = n - m + 1
check = 0

#起点の設定
for i in range(num):
    for j in range(num):
        C = []
        #要素の追加
        for k in range(m):
            C.append(A[i+k][j:j+m])
        if C == B:
            check += 1

if check >= 1:
    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)]

for i in range(n-m+1):
	for j in range(n-m+1):
		ans = "Yes"
		for k in range(m):
			sA = A[i+k][j:j+m]
			sB = B[k]
			# print(sA,sB)
			if sA != sB:
				ans = "No"
				break
		if ans == 'Yes':
			break
	if ans == "Yes":
		break
print(ans)

Submission status: Accepted

Solution code:
import sys
from functools import reduce
import copy
import math
from pprint import pprint
import collections
import bisect


sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def int_inputs(num_of_input):
    ins = [int(input()) for i in range(num_of_input)]
    return ins


def is_match(parent, child, pi, pj):
    for ci in range(len(child)):
        for cj in range(len(child[ci])):
            # c = child[ci][cj]
            # p = parent[pi+ci][pj+cj]
            if child[ci][cj] != parent[pi+ci][pj+cj]:
                return False
    return True


def solve(N, M, inputs):
    map_parent = list(map(list, inputs[:N]))
    map_child = list(map(list, inputs[N:]))

    for pi in range(0, N-M+1):
        for pj in range(0, N-M+1):
            if is_match(map_parent, map_child, pi, pj):
                return 'Yes'
    return 'No'


def string_to_int(string):
    return list(map(int, string.split()))


if __name__ == "__main__":
    [N, M] = string_to_int(input())
    ret = solve(N, M, inputs(N+M))
    print(ret)

Submission status: Accepted

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

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

b_index = 0
for i in range(N):
    for j in range(len(A[i])):
        if A[i][j] == B[0][0]:
            for i2 in range(M):
                for j2 in range(len(B[i2])):
                    if i+i2 > N-1 or j+j2 > len(A[i+i2])-1:
                        break
                    elif A[i+i2][j+j2] != B[i2][j2]:
                        break
                else:
                    continue
                break
            else:
                print('Yes')
                exit()
print('No')

Submission status: Accepted

Solution code:
import numpy as np
n, m = map(int, input().split())
#文字列をlistとしてinputしそれをn行の配列にする
a = np.array([list(input()) for _ in range(n)])
b = np.array([list(input()) for _ in range(m)])

judge = False

for i in range(n - m + 1):
    for j in range(n - m +1):
        image = a[i:i+m,j:j+m]
        if (image == b).all(): #配列が完全に一位してた場合
            judge = True

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

Submission status: Accepted

Solution code:
import numpy as np

n, m = map(int, input().split())
a = np.array([list(input()) for _ in range(n)])
b = np.array([list(input()) for _ in range(m)])

# print(a, b)

flag = False

for i in range(n - m + 1):
    for j in range(n - m + 1):
        mat = a[i : i + m, j : j + m]
        # print(mat.shape)
        if (mat == b).all():
            flag = True

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

Submission status: Accepted

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

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

SUM=0
for i in range(M):
    for j in range(M):
        if(B[i][j]=="#"):
            SUM+=1

for k in range(N):
    t=0
    for i in range(M):
        if(A[k][i]=="#"):
            t+=1
    C[k][i-M+1]=t
    for i in range(M,N):
        if(A[k][i]=="#"):
            t+=1
        if(A[k][i-M]=="#"):
            t-=1
        C[k][i-M+1]=t
for i in range(N):
    for j in range(N-M+1):
        for k in range(M):
            D[j][i]+=C[j+k][i]

for i in range(N-M+1):
    for j in range(N-M+1):
        if(D[i][j]==SUM):
            e=1
            for k in range(M):
                for l in range(M):
                    if(A[i+l][j+k]!=B[k][l]):
                        e=0  
            if(e==1):
                print("Yes")
                exit()
print("No")

Submission status: Accepted

Solution code:
import sys

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):
            if k == 0:
                C = [A[i][j:m+j]]
            else:
                C += [A[i+k][j:m+j]]
        if B == C:
            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)]
#i, j はBの左端
for i in range(n-m+1):
    for j in range(n-m+1):
        ans = True
        for k in range(m):
            if a[i + k][j:j+m] != b[k]:
                ans = False
        if ans == True:
            break
    else:
        continue
    break

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

Submission status: Accepted

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

for i in range(N):
	a = list(map(str, input()))
	A.append(a)
	
for i in range(M):
	b = list(map(str, input()))
	B.append(b)
	
def foo():
	for si in range(N - M + 1):
		for sj in range(N - M + 1):
			flg = 1
			for i in range(M):
				if not A[si + i][sj : sj + M] == B[i]:
					flg = 0
					break
			if flg:
				print("Yes")
				return 0
	print("No")
	return 0
	
foo()

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

Submission status: Accepted

Solution code:
from itertools import zip_longest
N, M = map(int, input().split())

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

def isSame(h, w):
    for lineA, lineB in zip_longest(A[h: h + M], B, fillvalue=[]):
        for a, b in zip_longest(lineA[w: w + M], lineB, fillvalue='?'):
            if a != b:
                return False
    return True

for h in range(N):
    for w in range(N):
        if isSame(h, w):
            print('Yes')
            exit()

print('No')

Submission status: Accepted

Solution code:
#Template Matching
N, M = map(int, input().split())
A = [input() for i in range(N)]
B = [input() for i in range(M)]
n = 0
n2 = 1

for i in range(N-M+1):
    for j in range(N-M+1):
        n2 = 1
        for k in range(M):
            if A[i+k][j:j+M] != B[k]:
                n2 = 0
        if n2 == 1:
            n = 1
        
if n == 1:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
import copy
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())
#check
#何行目かを決める
for i in range(n + 1 - m):
    #何文字目かを決める
    for j in range(n + 1 - m):
        k = 0
        while 1:
            if a[i + k][j:j+m] != b[k]:
                break
            else:
                if k == m - 1:
                    print("Yes")
                    exit()
                k += 1
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())
flag = 0
for i in range(N-M+1):
    for k in range(N-M+1):
        p = 1
        for j in range(i,i+M):
            a = A[j][k:k+M]
            b = B[j-i]
            if a != b:
                p = 0
                break
        if p == 1:
            flag = 1
        

if flag == 1:
    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 j in range(M)]
W = len(list(A[0]))-len(list(B[0]))+1
H = N - M + 1
ans = "No"
for i in range(H):
    for j in range(W):
        tmpA = []
        for k in range(M):
             tmpA.append(A[i+k][j:j+len(list(B[0]))])
        if tmpA == B:
            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)]
for i in range(n-m+1):
    for j in range(n-m+1):
        frag=True
        for y in range(m):
            for x in range(m):
                if b[y][x]!=a[i+y][j+x]:
                    frag=False
        if frag==True:
            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 y in range(n-m+1):
    for x in range(n-m+1):
        failed = False
        for by in range(m):
            for bx in range(m):
                if a[x+bx][y+by] != b[bx][by]:
                    failed = True
        if failed == False:
            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):
        result = True
        for k in range(M):
            for l in range(M):
                if A[i+k][j+l] != B[k][l]:
                    result = False
        if result:
            print("Yes")
            exit()




print("No")

Submission status: Accepted

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


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




print("No")

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
Alist = [list(input()) for _ in range(N)]
Blist = [list(input()) for _ in range(M)]
from sys import exit
for i in range(N - M + 1):
    for j in range(N - M + 1):
        for A, B in zip(Alist[i:i + M], Blist):
            if A[j:j + M] != B:
                break
        else:
            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)]
flag = False

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

        if B[0] == A[i][0+j:M+j]:
            for k in range(M):
                temp1 = B[k]
                temp2 = A[i + k][0+j:M+j]
                if B[k] != A[i + k][0+j:M+j]:
                    break
            else:
                flag = True
                break
    if flag:
        break

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

Submission status: Accepted

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

An = [ input() for _ in range(N)]
Bn = [ input() for _ in range(M)]
flag = False
for i in range(N-M+1):
    for j in range(N-M+1):
        for s in range(M):
            a = An[i+s][j:j+M]
            b =Bn[s]
            if An[i+s][j:j+M] != Bn[s]:
                break
            if s == M-1:
                flag = True
print('Yes' if flag else 'No')

Submission status: Accepted

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

A = []
B = []
for _ in range(N):
    tmp = input()
    tmp = tmp.replace("#", "1")
    tmp = tmp.replace(".", "2")
    tmp = [int(i) for i in tmp]
    A.append(tmp)

for _ in range(M):
    tmp = input()
    tmp = tmp.replace("#", "1")
    tmp = tmp.replace(".", "2")
    tmp = [int(i) for i in tmp]
    B.append(tmp)

A = np.array(A)
B = np.array(B)

ans = 0
for i in range(N-M+1):
    for j in range(N-M+1):
        if np.all(A[i:i+M, j:j+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=[]
ans="Yes"
for _ in range(N):
  A.append(input().split())
for __ in range(M):
  B.append(input().split())
for i in range(N):
  for k in range(M):
    if B[k][0] not in A[i][0]:
       ans ="No"
      
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 = 'Yes'
for i in range(n):
    for j in range(m):
        if b[j] not in a[i]:
            ans = 'No'
print(ans)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
nn = []
mm = []
for i in range(n):
    nn.append(list(input()))
for i in range(m):
    mm.append(list(input()))
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 nn[i+k][j+l] != mm[k][l]:
                    break
                else:
                    count += 1
        if count == m*m:
            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 j in range(m)]
point=[[i,j] for i in range(m) for j in range(m)]
for i in range(n-(m-1)):
    for j in range(n-(m-1)):
        cnt=0
        for x,y in point:
            if B[x][y]==A[i+x][j+y]:
                cnt +=1
        if cnt==m**2:
            print("Yes")
            exit()
print("No")

Submission status: Accepted

Solution code:
N, M = map(int, input().split())  # N*Nの元の画像, M*Mの探したい画像

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):
        # print(i, j)
        if A[i][j] == B[0][0]:  # 今見ている元画像の場所と, 探したい画像の左上がマッチしたら探索開始
            flag = True
            # print("始まり")
            for n in range(i, i+M):
                for m in range(j, j+M):
                    # print(n, m)
                    if A[n][m] != B[n-i][m-j]:
                        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)]

for X in range(N-M+1):
    for Y in range(N-M+1):
        flag=1
        for x in range(M):
            for y in range(M):
                if B[x][y]!=A[x+X][y+Y]:
                    flag=0
                    break
            if not flag:
                break
        if flag:
            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):
    flag = True
    for k in range(M):
      for l in range(M):
        if A[i+k][j+l] != B[k][l]:
          flag = False
    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())
for a,b in zip(A,B):
  if b in a:
    flag = True
  else:
    flag = False
    break;
if flag:
  print('Yes')
else:
  print('No')

Submission status: Accepted

Solution code:
def examB():
    N, M = LI()
    A = [S() for _ in range(N)]
    B = [S() for _ in range(M)]
    loop = N-M+1
    ans = "No"
    for i in range(loop):
        for j in range(loop):
            cur = int(0)
            for k1 in range(M):
                for k2 in range(M):
                    if A[i+k1][j+k2]==B[k1][k2]:
                        cur +=1
            if cur==M**2:
                ans = "Yes"
    print(ans)

import sys
import copy
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examB()

Submission status: Accepted

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

for p in range(N-M+1):
    for q in range(N-M+1):
        data=[[A[p+j][q+i] for i in range(M)]  for j in range(M)]
        if data == B:
            ans=True
            break
        else:
            ans=False
            continue
    if ans:break
if ans:print('Yes')
else:print('No')

Submission status: Accepted

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


def check_in(add_tate, add_yoko):
    for A, B in zip(Alist[add_tate:add_tate + M], Blist):
        try:
            assert A[add_yoko:add_yoko + M] == B
        except AssertionError:
            return False
    return True


from sys import exit
if Alist == Blist:
    print("Yes")
    exit()
for add_tate in range(N - M):
    for add_yoko in range(N - M):
        if check_in(add_tate, add_yoko):
            print("Yes")
            exit()
print("No")

Submission status: Accepted

Solution code:
import numpy as np
n,m=map(int,input().split())
a=np.array([[0 if i!="." else 1 for i in input()]for j in range(n)])
b=np.array([[0 if i!="." else 1 for i in input()]for j in range(m)])
ans = 'No'
for i in range(n-m+1):
  for j in range(n-m+1):
    if np.all(b == a[i:i+m,j:j+m]):
      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 i in range(M)]
ans = "No"
for h in range(N-M+1):
    for w in range(N-M+1):
        if A[h][w]==B[0][0]:
            k = 1
            for h1 in range(M):
                for w1 in range(M):
                    if A[h+h1][w+w1]!=B[h1][w1]:
                        k=0
                        break
                if not k:break
            if k:ans="Yes"
print(ans)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
l1=[]
l2=[]
for i in range(n):
  w=list(input())
  l1.append(w)
for i in range(m):
  w=list(input())
  l2.append(w)
d=n-m
b1=False
for i in range(d+1):#始点を横に動かす
  for j in range(d+1):#縦に動かす
    b=True
    for k in range(m):
      for h in range(m):
        if l2[k][h]!=l1[i+k][j+h]:
          b=False
    if b:
      b1=True
if b1:
  print("Yes")
else:
  print("No")

Submission status: Accepted

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

flag = "No"
diff = n - m + 1
for i in range(diff):
  for j in range(diff):
    T = []
    for k in range(m):
      T.append(A[i+k][j:j+m])
    if T == B:
      flag = "Yes"
      break

print(flag)

Submission status: Accepted

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

for i in range(n-m+1):
    for j in range(n-m+1):
        if b == [w[j:j+m] for w in a[i:i+m]]:
            print("Yes")
            break
    else:
        continue
    break
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):
    c = True
    for k in range(m):
      if a[i+k][j:j+m] != b[k]:
        c = False
    if c:
      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)]
ans = 'No'

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

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

count=0

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

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

        for k in range(m):

            for l in range(m):

                if b[k][l]==a[i+k][j+l]:
                    count+=1

                else:
                    count=0
                    break
            if count==0:
                break
            
        if count==m**2:
            print('Yes')
            exit()
        
print('No')

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
a = [[c for c in input()] for i in range(n)]
b = [[v for v in input()] for j in range(m)]
exist = False
for y in range(n):
    for x in range(n):
        if y+m-1 >= n or x+m-1 >= n: continue
        match = True
        for by in range(m):
            for bx in range(m):
                if a[y+by][x+bx] != b[by][bx]: match = False
        if match: exist = True
print('Yes' if exist else 'No')

Submission status: Accepted

Solution code:
from fractions import gcd
from datetime import date, timedelta
from heapq import*
import math
from collections import defaultdict, Counter, deque
import sys
from bisect import *
import itertools
import copy
sys.setrecursionlimit(10 ** 7)
MOD = 10 ** 9 + 7


def main():
    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):
            f = True
            for p in range(m):
                for q in range(m):
                    if a[i + p][j + q] != b[p][q]:
                        f= False
            
            if f:
                print("Yes")
                exit()

    print("No")


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
gazoa=[0 for i in range(n)]
gazob=[0 for j in range(m)]
for i in range(n):
    s=input()
    gazoa[i]=s
for j in range(m):
    s=input()
    gazob[j]=s
flag=False
for i in range(n-m+1):
    #縦から上から1番目　そして2番目　そして。。。。という感じでn-m+1番目までについてのスタート地点を決める
    for k in range(n-m+1):
        realflag=True
        #k=0,1,2,....n-mという感じになる
        for num in range(m):
            if gazoa[i+num][k:k+m]!=gazob[num]:
                realflag=False
        if realflag:
            flag=True
if flag:
    print("Yes")
        
        
else:
    print("No")

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
A=[];B=[]
for i in range(N):
    Ai=input()
    A.append([Ai[j]=='#' for j in range(N)])
for i in range(M):
    Bi=input()
    B.append([Bi[j]=='#' for j in range(M)])
fans=False
fnext=False
for k in range(N-M+1):
    if fans:
        break
    for l in range(N-M+1):
        if fans:
            break      
        if fnext:
            fnext=False
        for i in range(M):
            if fnext:
                break
            for j in range(M):                    
                if A[k+i][l+j]!=B[i][j]:
                    fnext=True
                    break
                if i==j==M-1:
                    fans=True

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