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 = list(map(int, input().split()))

a_list_list = []

for i in range(0, n):
    a_list_list.append(input().split()[0])

b_list_list = []

for i in range(0, m):
    b_list_list.append(input().split()[0])

def is_match(source_list_list, b_list_list, source_start_x):

    for k in range(len(b_list_list)):
        for l in range(len(b_list_list[0])):
            if source_list_list[k][source_start_x + l] != b_list_list[k][l]:
                return False

    return True

# def debug_print(source):
#     print('==============')
#     for row in source:
#         print(row)
#     print('==============')

is_ok = False

# debug_print(b_list_list)

for j in range(0, n-m+1):
    target_a_list_list = a_list_list[j:j+m]
    for i in range(0, n-m+1):
        # debug_print(target_a_list_list)
        if is_match(target_a_list_list, b_list_list, i):
            is_ok = True
            break
    if is_ok:
        break

ans = 'Yes' if is_ok else 'No'

print(ans)

Submission status: Accepted

Solution code:
import sys

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

    for i in range(N - M + 1):
        for j in range(N - M + 1):
            for k in range(M):
                if B[k] != A[i+k][j:j+M]:
                    break
                if k == M-1:
                    print('Yes')
                    return

    print('No')

if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
ann = [str(input()) for i in range(n)]
bmm = [str(input()) for i in range(m)]
for y in range (n-m+1):
    for x in range(n-m+1):
        
        flag = True
        for i in range(m):
            if bmm[i] != ann[y+i][x:x+m]:
                flag = False
        if flag == True:
            break
    if flag == True:
      break
if flag == True:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys, math, fractions, itertools

YES = "Yes"  # type: str
NO = "No"  # type: str

def solve(N: int, M: int, A: "List[str]", B: "List[str]"):
    f = 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 A[i+k][j+l] != B[k][l]:
                        flag = False
            if flag:
                f = True
    if f:
        print('Yes')
    else:
        print('No')
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    A = [ next(tokens) for _ in range(N) ]  # type: "List[str]"
    B = [ next(tokens) for _ in range(M) ]  # type: "List[str]"
    solve(N, M, A, B)

if __name__ == '__main__':
    main()

Submission status: Accepted

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


n,m = map(int,input().split())
A = []
for i in range(n):
    A.append(list(input()))
B = []
for i in range(m):
    B.append(list(input()))

flg = False
for i in range(n-m+1):
    for j in range(n-m+1):
        if match(i,j):
            flg = True
print('Yes' if flg else 'No')

Submission status: Accepted

Solution code:
N,M=[int(x) for x in input().split()]
An=[input() for _ in range(N)]
Bn=[input() for _ in range(M)]
ans='No'
for i in range(N-M+1):
  for c in range(N-M+1):
    for r in range(M):
      if An[i+r][c:c+M]!=Bn[r]:
        break
    else:
      ans='Yes'
    if ans=='Yes':
      break
  if 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)]

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

ans=False
for i in range(n - m + 1):
    for j in range(n - m + 1):
        if Check(i, j): ans = True
print('Yes' if ans 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)]

exists = []
for i in range(0, len(a)):
  exists.append([i, a[i].find(b[0])])

for x, y in exists:
  ari = []
  for i in range(0, len(b)):
    if x+i < len(a):
      ari.append(a[x+i][y:y+M])
  if "".join(ari) == "".join(b):
    print("Yes")
    exit()

print("No")

Submission status: Accepted

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

a = []
for x in range(0, N):
  a.append(input())

b = []
for x in range(0, M):
  b.append(input())

exists = []
for i in range(0, len(a)):
  exists.append([i, a[i].find(b[0])])

for x, y in exists:
  ari = []
  for i in range(0, len(b)):
    if x+i < len(a):
      ari.append(a[x+i][y:y+M])
  if "".join(ari) == "".join(b):
    print("Yes")
    exit()

print("No")

Submission status: Accepted

Solution code:
import numpy as np
n,m = list(map(int, input().split()))
tmp_a = [list(input()) for _ in range(n)]
tmp_b = [list(input()) for _ in range(m)]

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

for a_i in range(n - m + 1):
	for a_j in range(n - m + 1):
		if((a[a_i:a_i + m, a_j:a_j + m] == b).all()):
			print("Yes")
			exit()
print("No")

Submission status: Accepted

Solution code:
def solve(n, m, a, b):
  for i in range(n - m + 1):
    for j in range(n - m + 1):
      if [row[j:j+m] for row in a[i:i+m]] == b:
        return True
  return False

n, m = map(int, input().split())
a = [input() for _ in range(n)]
b = [input() for _ in range(m)]
print('Yes' if solve(n, m, a, b) else 'No')

Submission status: Accepted

Solution code:
N, M = list(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 x in range(M):
      for y in range(M):
        if A[i + x][j + y] != B[x][y]:
          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)]
ans="No"
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="Yes"
print(ans)

Submission status: Accepted

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

check = 0


for k in range(n-m+1):
    if check == m:
        break
    C = A[k:k+m]
    for i in range(n-m+1):
        if check == m:
            break
        check = 0
        for j in range(m): 
            if C[j][i:i+m] == B[j]:
                check += 1   
            if check == m:
                print('Yes')  
         


if check != m:
    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 s_h in range(n - m + 1):
    for s_w in range(n - m + 1):
        flag = True
        for i in range(m):
            for j in range(m):
                if a[s_h + i][s_w + j] != b[i][j]:
                    flag = False
                    break
            if not flag:
                break
        if flag:
            print("Yes")
            break
    if flag:
        break
if not flag:
    print("No")

Submission status: Accepted

Solution code:
a, b = map(int, input().split())
c = []
d = []
for i in range(a):
    c.append(list(input()))
for i in range(b):
    d.append(list(input()))
for i in range(a - b + 1):
    for j in range(a - b + 1):
        e = True
        for k in range(i, i + b):
            for l in range(j, j + b):
                if c[k][l] != d[k-i][l-j] and e:
                    e = not e
        if e:
            print("Yes")
            exit()
print("No")

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

Submission status: Accepted

Solution code:

import sys
def main():
    num_a, num_b = map(int, input().split())
    data_a = [list(input()) for i in range(num_a)]
    data_b = [list(input()) for i in range(num_b)]

    for i in range(num_a - num_b + 1):
        for j in range(num_a - num_b + 1):
            ok_flg = 1
            for k in range(num_b):
                for l in range(num_b):
                    # print(data_b[k][l],  data_a[k + i][l + j])
                    if data_b[k][l] != data_a[k + i][l + j]:
                        ok_flg = 0
                        break
            if ok_flg:
                print('Yes')
                sys.exit()

    print('No')



if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
li1 = []
li2 = []
for i in range(n):
	li1.append(input())
for j in range(m):
	li2.append(input())
k = 0	
for i in range(n - m + 1):
	for j in range(n - m + 1):
		x = i
		for k in range(m):
			if li1[x].find(li2[k], j) != j:
				break
			if k == m-1:
				print("Yes")
				exit()
			x += 1
print("No")

Submission status: Accepted

Solution code:
import numpy as np

N,M = map(int,input().split())
A = np.array([list(input()) for i in range(N)])
B = np.array([list(input()) for i in range(M)])
f = False

for i in range(N-M+1):
  for j in range(N-M+1):
    if (A[i:i+M,j:j+M]==B).all():
      f = True

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

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
A = [list(input()) for i in range(N)]
B = [list(input()) for i in range(M)]
ans = 'No'
for i in range(N - M + 1):
    for j in range(N - M + 1):
        count = 0
        for row in range(M):
            for col in range(M):
                if B[row][col] == A[i + row][j + col]:
                    count += 1
        if count == M * M:
            ans = 'Yes'

print(ans)

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
img_a = [list(input()) for _ in range(N)]
img_b = [list(input()) for _ in range(M)]
ans = "No"

for i in range(N-M+1):
    for j in range(N-M+1):
        cnt = 0
        for row in range(M):
            for col in range(M):
                if img_b[row][col] == img_a[i+row][j+col]:
                    cnt += 1
        if cnt == M*M:
            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)]
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")
      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 j in range(M):
    B.append(input())


for i in range(N - M + 1):
    for j in range(N - M + 1):
        l = 0
        i1 = i
        for l in range(M):
            
            if A[i1].find(B[l],j) != j:
                break   
            if l == M-1:
                print("Yes")
                exit()
            i1 +=1

print("No")

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
A = []
for i in range(0, N):
	A.append(input())
B = []
for i in range(0, M):
	B.append(input())
flag1 = False
for i in range(0, N-M+1):
	for j in range(0, N-M+1):
		flag2 = True
		for p in range(0, M):
			for q in range(0, M):
				if A[i+p][j+q] != B[p][q]:
					flag2 = False
					break
			if not flag2:
				break
		if flag2:
			flag1 = True
			break
	if flag1:
		break
if flag1:
	print('Yes')
else:
	print('No')

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
i1=[input() for _ in range(n)]
i2=[input() for _ in range(m)]
ans="No"
for i in range(n-m+1):
    for j in range(n-m+1):
        count=0
        for k in range(m):
            if i1[i+k][j:m+j]==i2[k]:
                count+=1
                if count==m:
                    ans="Yes"
print(ans)

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 j in range(n-m+1):
        new_list = [a_list[k][j:j+m] for k in range(i,i+m)]
        if(new_list == b_list):
            print('Yes')
            sys.exit()
print('No')

Submission status: Accepted

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

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

print("No")

Submission status: Accepted

Solution code:
a, b = map(int, input().split())
c = [list(input())for _ in range(a)]
d = [list(input())for _ in range(b)]
for i in range(a - b + 1):
    for j in range(a - b + 1):
        e = True
        for k in range(i, i + b):
            for l in range(j, j + b):
                if c[k][l] != d[k-i][l-j] and e:
                    e = not e
        if e:
            print("Yes")
            exit()
print("No")

Submission status: Accepted

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

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

def main():
     for i in range(N-M+1):
          for j in range(N-M+1):
               if is_same(i,j, A, B):
                    return True
     return False

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

Submission status: Accepted

Solution code:
# review

n,m = map(int,input().split())
li_a = [list(input()) for _ in range(n)]
li_b = [list(input()) for _ in range(m)]
 
 
for i in range(n-m+1):
    for j in range(n-m+1):
        for k in range(m):
            if li_a[i+k][j:j+m] != li_b[k][:]:
                break
        else:
            print("Yes")
            exit()
            
print("No")

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    a, b = LI()
    a -= 2
    b -= 2
    a %= 13
    b %= 13
    if a > b:
        print("Alice")
    elif a < b:
        print("Bob")
    else:
        print("Draw")
    return

#B
def B():
    n, m = LI()
    a = SR(n)
    b = SR(m)
    if a == b:
        print("Yes")
        return
    for y in range(n - m):
        for x in range(n - m):
            if a[y][x] == b[0][0]:
                flg = 0
                for yi in range(m):
                    for xi in range(m):
                        if b[yi][xi] == a[y + yi][x + xi]:
                            continue
                        flg = 1
                        break
                    if flg:
                        break
                if flg:
                    continue
                print("Yes")
                return
    print("No")
    return

#C
def C():
    return

#D
def D():
    return

#Solve
if __name__ == '__main__':
    B()

Submission status: Accepted

Solution code:
a, b = map(int, input().split())
c = []
d = []
for i in range(a):
    c.append(list(input()))
for i in range(b):
    d.append(list(input()))
for i in range(a-b+1):
    for j in range(a-b+1):
        o = True
        for k in range(i, i+b):
            for l in range(j, j+b):
                if c[k][l] != d[k-i][l-j] and o:
                    o = not o
        if o:
            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)]
arr=[]
for i in range(N-M+1):
	for j in range(N-M+1):
		l=list(map(lambda x:x[j:j+M],A[i:i+M]))
		arr.append(all([l[j]==B[j] for j in range(M)]))
print("Yes" if any(arr) else "No")

Submission status: Accepted

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

res = 'No'

for r in range(N-M+1):
    for c in range(N-M+1):
        if B == [e[r:r+M:1] for e in A[c:c+M:1]]:
            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)]

for i in range(n-m+1):
    for j in range(n-m+1):
        if b==[a[k][j:j+m] for k in range(i,i+m)]:print('Yes');exit()
        else:pass
print('No')

Submission status: Accepted

Solution code:
a, b = map(int, input().split())
c = []
d = ""
for i in range(a):
    c.append(list(input()))
for i in range(b):
    d += input()
e = []
for i in range(a-b+1):
    for j in range(a-b+1):
        f = ""
        for k in range(b):
            for l in range(b):
                f += c[i+k][j+l]
        e.append(f)
print("Yes" if d in e else "No")

Submission status: Accepted

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


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

Submission status: Accepted

Solution code:
def main():
    n,m=map(int,input().split(' '))
    a = []
    b = []
    ans = True
    for i in range(n):
        a.append(list(input()))
    for i in range(m):
        b.append(list(input()))
    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(m):
                    if a[i+k][j:j+m] != b[k]:
                        ans = False
                if ans == True:
                    print('Yes')
                    exit()
                ans = True

    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 judge() :
    for i in range(N - M + 1) :
        for j in range(N - M + 1) :
            flg = True
            for k in range(M) :
                for l in range(M) :
                    if A[i+k][j+l] != B[k][l] :
                        flg = False
                        break
                    if not flg :
                        break
            if flg :
                return 'Yes'
                    
    return 'No'
    
print(judge())

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

print('No')

Submission status: Accepted

Solution code:
import math
import fractions
import copy
import numpy as np
def j(q):
    if q==1: print("Yes")
    elif q == 0:print("No")
    exit(0)
rem = pow(10,9)+7
"""
def ct(x,y):
    if (x>y):print("+")
    elif (x<y): print("-")
    else: print("?")
"""

def ip():
    return int(input())
def iprow():
    return [int(i) for i in input().split()]
def ips():
    return (int(i) for i in input().split())
def printrow(a):
    for i in a:
        print(i)
"""
#decomment when needed
def combinations(n,r):
    if n<r:return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
def permutations(n,r):
    if n<r:return 0
    return math.factorial(n) // math.factorial(n - r)
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)
"""
n ,m= ips()
a= []
b= []
for i in range(n):
    a.append(input())
for i in range(m):
    b.append(input())
left = 0
right =m
for sy in range(n-m+1):
    for sx in range(n-m+1):
        c = []
        for i in range(sy,sy+m):
            c.append(a[i][sx:(sx+m)])
        if c==b:j(1)
j(0)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(300000)

YES = "Yes"  # type: str
NO = "No"  # type: str

def solve(N: int, M: int, A: "List[str]", B: "List[str]"):
    for i in range(N - M + 1):
        for j in range(N - M + 1):
            found = True
            for x in range(M):
                for y in range(M):
                    if A[i + x][j + y] != B[x][y]:
                        found = False
                        break
                if not found:
                    break
            if found:
                print(YES)
                return
    print(NO)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    A = [ next(tokens) for _ in range(N) ]  # type: "List[str]"
    B = [ next(tokens) for _ in range(M) ]  # type: "List[str]"
    solve(N, M, A, B)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
a=[str(input()) for _ in range(n)]
b=[str(input()) for _ in range(m)]
for i in range(n-m+1):
    for j in range(n-m+1):
        tmp=[]
        for k in range(m):
            tmp.append(a[j+k][i:i+m])
        if tmp==b:
            print("Yes")
            exit()
print("No")

Submission status: Accepted

Solution code:

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

A = []
B = []

for i in range(N):

    a = input()
    A.append(a)

for i in range(M):

    b = input()
    B.append(b)

if N-M < 0:
    print ("No")

elif N == M:

    flag = True
    for i in range(N):

        for j in range(N):

            if A[i][j] != B[i][j]:

                flag = False

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

else:

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

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

            flag = True
            for x in range(M):

                for y in range(M):

                    if A[i+x][j+y] != B[x][y]:

                        flag = False

            if flag:
                break
        if flag:
            break

    if flag:
        print("Yes")

    else:
        print("No")

Submission status: Accepted

Solution code:
import numpy as np

def main():
  n,m = map(int,input().split())
  an = np.array([list(input()) for i in range(n)])
  bm = np.array([list(input()) for i in range(m)])
  
  for i in range(n-m+1):
    for j in range(n-m+1):
      if (an[i:i+m,j:j+m] == bm).all():
        print('Yes')
        exit()
  print('No')
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys

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

for i in range(n-m+1):
    for j in range(n-m+1):
        for k in range(m):
            if a[i+k][j:j+m] != b[k]:
                break
            if k == m-1:
                print('Yes')
                sys.exit(0)
print('No')

Submission status: Accepted

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

i1 = [ input() for i in range(n) ]
i2 = [ input() for i in range(m) ]

for i in range(0, n - m + 1):
    for j in range(0, n - m + 1):
        si = [ x[j:j + m] for x in i1[i:i + m] ]
        if si == i2:
            print("Yes")
            exit(0)
print("No")

Submission status: Accepted

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

    for row in range(n - m + 1):
        for index in range(n - m + 1):
            if b == [i[index:index + m] for i in a[row:row + m]]:
                print('Yes')
                return

    print('No')

    # for row in range(n - m + 1):
    #    current_index = 0
    #    for index in range(n - m + 1):
    #        current_index = a[row].find(b[0], index)
    #        if current_index < 0:
    #            break
    #
    #        for i in range(m):
    #            if a[row + i].find(b[i], current_index) != current_index:
    #                break
    #        else:
    #            print('Yes')
    #            return
    #
    # print('No')


if __name__ == "__main__":

    main()

Submission status: Accepted

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

    for row in range(n - m + 1):
        current_index = 0
        for index in range(n - m + 1):
            current_index = a[row].find(b[0], index)
            if current_index < 0:
                break

            for i in range(m):
                if a[row + i].find(b[i], current_index) != current_index:
                    break
            else:
                print('Yes')
                return

    print('No')


if __name__ == "__main__":

    main()

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
x='No'
a=[input() for _ in range(n)]
b=[input() for _ in range(m)]
def c(i,j):
  global m
  global a
  global b
  for k in range(m):
    for l in range(m):
      if b[k][l]!=a[i+k][j+l]:
        return 0
  return 1
for i in range(n-m+1):
  for j in range(n-m+1):
    if c(i,j)==1:
      x='Yes'
      break
print(x)

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):
        comp = True
        for k in range(m):
            for l in range(m):
                if a[i+k][j+l] != b[k][l]:
                    comp = False
        if comp:
            print("Yes")
            exit(0)
print("No")

Submission status: Accepted

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

f = lambda x: 1 if x == "#" else 0
A = [list(map(f, input())) for _ in range(N)]
B = [list(map(f, input())) for _ in range(M)]

def func():
  for i in range(N-M+1):
    for j in range(N-M+1):
      if all(A[i+k][j+l] == B[k][l] for k in range(M) for l in range(M)):
        return True
  return False

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

Submission status: Accepted

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

mat_N = []
for _ in range(N):
    mat_N.append(input())
mat_M = []
for _ in range(M):
    mat_M.append(input())

def chk(y, x):
    for k in range(M):
        if mat_N[y + k][x:M + x] != mat_M[k]:
            return False
    return True

if M <= N:
    for y in range(N-M+1):
        for x in range(N-M+1):
            if chk(y, x):
                print("Yes")
                exit()
print("No")

Submission status: Accepted

Solution code:
from sys import stdin
N,M = [int(x) for x in stdin.readline().rstrip().split()]
A = []
for _ in range(N):
    A.append(list(input()))
    
B = []
for _ in range(M):
    B.append(list(input()))

for dh in range(0,N-M+1):
    for dw in range(0,N-M+1):
        ans = True
        for bh in range(0,M):
            for bw in range(0,M):
                if B[bh][bw] != A[bh+dh][bw+dw]:
                    ans = False
        if ans:
            print("Yes")
            break
    else:
      continue
    break
if ans == False:
    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 i in range(N - M + 1):
    for j in range(N - M + 1):
        flag = True

        for x in range(M):
            if A[j+x][i:i+M] != B[x]:
                flag = False
                break

        if flag == True:
            print('Yes')
            exit()

print('No')