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()))
al = [input() for i in range(n)]
bl = [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 al[i+k][j:j+m] != bl[k]:
				break
		else:
			print("Yes")
			exit()
		#print("Yes")
		#exit()
print("No")

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
a=[]
b=[]
for i in range(n):
    a.append(input())
for i in range(m):
    b.append(input())
    
for i in range(n-m+1):
    if b[0] in a[i]:
        p=[]
        for j in range(n-m+1):
            if b[0]==a[i][j:j+m]:
                p.append(j)
        for j in range(1,m):
            for k in p:
                if b[j]!=a[i+j][k:k+m]:
                    p.remove(k)
        if p!=[]:
            print("Yes")
            import sys
            sys.exit()
print("No")

Submission status: Accepted

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

ans = 'No'

for i in range(N - M + 1):
    for j in range(N - M + 1):
        check = 0
        for ind, s in enumerate(B):
            #print(s)
            #print(A[i + ind][j])
            if s != A[i + ind][j: j+M]:

                check = 1
        if check == 0:
            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(len(A)-len(B)+1):
    for j in range(len(A)-len(B)+1):
        cond = 1
        for p in range(len(B)):
            for q in range(len(B)):
                if A[i+p][j+q] != B[p][q]:
                    cond = 0
        if cond == 1:
            print("Yes")
            exit()
print("No")

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
a = []
b = []
flag = False
def check(offset=[0, 0]):
    for i in range(m):
        for j in range(m):
            if a[i + offset[0]][j + offset[1]] != b[i][j]:
                return 1
    return 0

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 check((i,j)) == 0:
            flag = True

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

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
lia = [input() for i in range(n)]
lib = [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 lia[i+k][j:j+m] != lib[k]:
        break
    else:
      print("Yes")
      exit()
print("No")

Submission status: Accepted

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

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

ans = 'No'

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

Submission status: Accepted

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

# 基準を全探索
for row in range(n-m+1):
    for col in range(n-m+1):
        # 一致チェック
        blnOK=True
        for m_row in range(m):
            for m_col in range(m):
                if a_list[row+m_row][col+m_col]!=b_list[m_row][m_col]:
                    blnOK=False
                    break
            if not blnOK:
                break
        if blnOK:
            print('Yes')
            exit()
print('No')

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
N,M = map(int,input().split())

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

F = 0
for i in range(N-M+1):
    for j in range(N-M+1):
        if A[i][j] == B[0][0]:
            F = 1
            for k in range(M):
                for l in range(M):
                    if B[k][l] != A[i+k][j+l]:
                        F = 0
            if F:
                print('Yes')
                quit()
print('No')

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
#N=input()
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):
        t=True
        for x in range(M):
            if A[i+x][j:j+M]!=B[x]:
                t=False
                break
        if t:
            print("Yes")
            quit()
print("No")

Submission status: Accepted

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

N, M = map(int, input().split())
A_list = [input() for i in range(N)]
B_list = [input() for j in range(M)]

for i in range(N - M + 1):
    for j in range(N - M + 1):
        for k in range(M):
            if B_list[k] != A_list[i + k][j:j + M]:
                break
        else:
            print('Yes')
            exit()
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):
        t=True
        for x in range(M):
            if A[i+x][j:j+M]!=B[x]:
                t=False
                break
        if t:
            print("Yes")
            quit()
print("No")

Submission status: Accepted

Solution code:

n, m = [ int(v) for v in input().split() ]
image = [ input() for i in range(n)]
temp_image = [ input() for i in range(m)]


ans = "No"
for i in range(n-m+1):
    for j in range(n-m+1):
        part_image = [ image[k][j:j+m] for k in range(i,i+m) ]
        if part_image == temp_image:
            ans = "Yes"
print(ans)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
al=[input() for _ in range(n)]
bl=[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 bl[k]!=al[i+k][j:j+m]:
                break
        else:
            print('Yes')
            exit()
else:
    print('No')

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
image = []
template = ''
for i in range(n):
    image.append(input().rstrip())
for i in range(m):
    template += input().rstrip()

for x in range(n - m + 1):
    for y in range(n - m + 1):
        target = ''
        for i in range(m):
            target += ''.join(image[y+i][x:x + m])
        if target == template:
            print('Yes')
            exit()
print('No')

Submission status: Accepted

Solution code:
nl = lambda: list(map(int, input().split()))
sl = lambda: input().split()
n = lambda: int(input())
s = lambda: input()

N, M = nl()
A = []
B = []
for i in range(N):
    A.append(s())
for i in range(M):
    B.append(s())

for i in range(N-M+1):
    col = A[i].find(B[0])
    if col >= 0:
        found = True
        for j in range(1, M):
            if A[i+j][col:col+M] != B[j]:
                found = False
                break
        if found:
            print('Yes')
            import sys
            sys.exit()

print('No')

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
a = []
b = []
r = False
for i in range(n):
    s = input()
    a.append(s)
for i in range(m):
    s = input()
    b.append(s)

for i in range(n-m+1):
    for j in range(n-m+1):
        for k in range(m):
            test = True
            if (b[k] != a[i+k][j:m+j]):
                test = False
                break
        if(test):
            r = True

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

Submission status: Accepted

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

for i in range(N-M+1):
    for j in range(N-M+1):
        tmp = [A[i+k][j:j+M] for k in range(M)]
        if tmp == B:
            print('Yes')
            exit()
print('No')

Submission status: Accepted

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

if A == B:
    print('Yes')
    exit()

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

print('No')

Submission status: Accepted

Solution code:
from collections import Counter
from collections import deque
from functools import reduce
from pprint import pprint
import bisect
import copy
import fractions
import itertools
import math
import queue
import random
import sys
import time
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def MI(): return map(int, sys.stdin.readline().split())
def II(): return int(sys.stdin.readline())
def IS(): return input()
def C(x): return Counter(x)
def GCD_LIST(numbers): return reduce(fractions.gcd, numbers)
def LCM_LIST(numbers): return reduce(LCM, numbers)
def LCM(m, n): return (m * n // fractions.gcd(m, n))


n , m = MI()
a = []
b = []
for i in range(n):
    a.append(IS())
for i in range(m):
    b.append(IS())
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')
                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)]
flag = 'No'
for i in range(n - m + 1):
    for j in range(n - m + 1):
        flag = 'Yes'
        for r in range(m):
            for c in range(m):
                if a[i+r][j+c] != b[r][c]:
                    flag = 'No'
                    break
        if flag == 'Yes':
            print(flag)
            quit()
print(flag)

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

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
A = []
B = []
flag = False
for i in range(N):
    A.append(input())
for k in range(M):
    B.append(input())
    
for i in range(N-M+1):   #リストAを縦に見る
    for k in range(N-M+1):   #リストAを横に見る
        S = []
        for j in range(i, i+M):   #リストAをMxMになるように抜き出してSに入れる
            S.append(A[j][k : k+M])
        if S == B:
            flag = True
if flag:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

if n == 1 and m == 1:
    if dat_a[0][0] == dat_b[0][0]:
        t = True
    else:
        t = False

for i in range(n - m + 1):
    for j in range(n - m + 1):
        for k in range(m):
            #print(dat_a[i + k][j : j + m])
            if dat_a[i + k][j : j + m] != dat_b[k]:
                t = False
                break
            t = True
        if t:
            break
    if t:
        break

print("Yes" if t else "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 m():

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

    for x in range(N-M+1):
        for y in range(N-M+1):
            if is_match(x, y):
                return 'Yes'
            else:
                continue
    return 'No'


print(m())

Submission status: Accepted

Solution code:
N, M = [int(i) for i in 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 r in range(M):
            for c in range(M):
                if A[i + r][j + c] != B[r][c]:
                   flag = False
                   break
        if flag:
            print("Yes")
            quit()
print("No")

Submission status: Accepted

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

for i in range(m):
    b+=[input()]
ans='No'
if n==m:
    ans='Yes'

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

   
print(ans)

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

bl = 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():
      bl = True

answer = 'Yes' if bl else 'No'
print(answer)

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

Submission status: Accepted

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

pic1=[]
pic2=[]

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

for j in range(m):
    pic2.append(input())

#print(pic1)
#print(pic2)

ans="No"

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 pic1[i+k][j+l]!=pic2[k][l]:
                    flag=False

            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)]
ans = 'No'

for h in range(N - M + 1):
    for i in range(N - M + 1):
        count = 0
        for j in range(M):
            if A[i + j][h:M + h] == B[j]:
                count += 1

                if count == M:
                    ans = 'Yes'

print(ans)

Submission status: Accepted

Solution code:
N, M = [int(x) for x in input().split()]

A = []
B = []

for _ in range(N):
	A.append(input())

for _ in range(M):
	B.append(input())

judge = False
	
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:
				judge = True

if judge:
	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)]
ans='No'
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:
            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 = "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:
import sys

import numpy as np
import itertools

N, M = list(map(int, sys.stdin.readline().split()))
A = np.array([list(sys.stdin.readline().rstrip()) for _ in range(N)]) == "#"
B = np.array([list(sys.stdin.readline().rstrip()) for _ in range(M)]) == "#"

ok = False
for i, j in itertools.product(range(len(A) - len(B) + 1), repeat=2):
    ok |= (A[i: i + len(B), j: j + len(B)] == B).all()

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

Submission status: Accepted

Solution code:
import sys

import numpy as np

N, M = list(map(int, sys.stdin.readline().split()))
A = np.array([list(sys.stdin.readline().rstrip()) for _ in range(N)]) == '#'
B = np.array([list(sys.stdin.readline().rstrip()) for _ in range(M)]) == '#'
size = len(B)

ok = False
for i in range(len(A) - size + 1):
    for j in range(len(A) - size + 1):
        ok |= (A[i:i + size, j:j + size] == B).all()
if ok:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
import itertools
n, m = [int(i) for i in input().split()]
a = [input() for i in range(n)]
b = [input() for i in range(m)]
ans = 0
for i, j in itertools.product(range(n - m + 1), repeat = 2):
    if b == [a[i + _][j:j + m] for _ in range(m)]:
        ans = 1
print(["No", "Yes"][ans])

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 j in range(m):
    b.append(input())

for i in range(n-m+1):
    for j in range(n-m+1):
        a_dash = [a[i+_][j:j+m] for _ in range(m)]
        if b == a_dash:
            print("Yes")
            exit()
else:
    print("No")

Submission status: Accepted

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

tg = [input() for _ in range(N)]

#tmpl0〜M-1
tmpl = [input() for _ in range(M)]

#tg0〜N-Mにつき、tmpl0を探し、一致したら同じ添字のtmpl1~M-1を探す
for i in range(0,N-M+1):
  for j in range(0,N-M+1):
    if tmpl[0] == tg[i][j:j+M]:
      if N == 1:
        print('Yes')
        exit()
      for k in range(1,M):
        if tmpl[k] != tg[i+k][j:j+M]: break
      else:
        print('Yes')
        exit()
print('No')

Submission status: Accepted

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

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

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

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

ans = 0

for i in range(n):
    for j in range(n):
        if i+m-1 <= n-1 and j+m-1 <= n-1:
            lili = [['aaa']*m for k in range(m)]
            for h in range(m):
                for w in range(m):
                    # import pdb
                    # pdb.set_trace()
                    lili[h][w] = a[i+h][j+w]

            if b == lili:
                ans += 1

print('Yes' if ans >= 1 else 'No')

Submission status: Accepted

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

A = []
B = []
for n in range(N):
    A.append(str(input()))
for m in range(M):
    B.append(str(input()))

count = 0
for i in range(len(B)):
    if B[i] in A[i]:
        count += 1
    else:
        count += 0

if count == len(B):
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

Submission status: Accepted

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

def solve():
    N, M = list(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 i in range(N-M+1):
        for j in range(N-M+1):
            if A[i][j] == B[0][0]:
                is_contained = True
                for k in range(0, M):
                    for l in range(0, M):
                        if A[i+k][j+l] != B[k][l]:
                            is_contained = False
                            break
                    if not is_contained: break
                if is_contained:
                    print("Yes")
                    return
    print("No")


if __name__ == "__main__":
    solve()

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):
            for l in range(m):
                if a[i+k][j+l] != b[k][l]:
                    flag = False
            if not flag:
                break
        if flag:
            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)]

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

Submission status: Accepted

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

for c in range(n-m+1):
    for d in range(n-m+1):
        C = [a[d+e][c:c+m] for e in range(m)]
        if C == b:
            ans = 'Yes'
    
print(ans)

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
a = []
for i in range(n):
    a.append(input())
b = []
for g in range(m):
    b.append(input())
#print(a)
#print(b)
ans = 'No'
for c in range(n-m+1):
    for d in range(n-m+1):
        flag = 0
        for e in range(m):
            if a[d+e][c:c+m] != b[e]:
                flag = 1
        if flag == 0:
            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(min(N - M + 2, N)):
	for j in range(min(N - M + 2, N)):
		# print("i=", i, "j=", j)
		if A[i][j: j + M] == B[0]:
			tmp = True
			for k in range(1, M):
				if A[i + k][j: j + M] == B[k]:
					pass
				else:
					tmp = False
					break
			if tmp:
				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):
        C=[A[i+k][j:j+m] for k in range(m)]
        if B==C:
            ans='Yes'
        
print(ans)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
a=[[j for j in input()] for i in range(n)]
b=[[j for j in input()] for i in range(m)]
for i in range(n-m+1):
    for j in range(n-m+1):
        if all(k[j:j+m]==b[bi] for bi,k in enumerate(a[i:i+m])):
            print("Yes")
            quit()
print("No")

Submission status: Accepted

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

cnt = 0
flg = '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:
            flg = 'Yes'
        else:
            cnt = 0
print(flg)

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)]
frd = N-M

def check(A,B,i,j):
    for yoko in range(M):
        for tate in range(M):
            if A[tate+i][yoko+j] != B[tate][yoko]:
                return False
    return True
    
for i in range(frd+1):
    for j in range(frd+1):
        if check(A,B,i,j):
            print("Yes")
            exit()
print("No")

Submission status: Accepted

Solution code:
import sys
import numpy as np

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

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

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

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
a = [input() for i in range(n)]
b = [input() for j in range(m)]
ans = "No"
for i in range(n-m+1):
    for j in range(n-m+1):
        count = 0
        for k in range(m):
            for l in range(m):
                if b[k][l] == a[i+k][j+l]:
                    count += 1
        if count == m*m:
            ans = "Yes"
            break

print(ans)

Submission status: Accepted

Solution code:
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
# import numpy as np

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

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

ans = False
for y in range(N-M+1):
    for x in range(N-M+1):
        for i in range(M):
            for j in range(M):
                if A[x+i][y+j] == B[i][j]:
                    pass
                else:
                    break
            else:
                continue
            break
        else:
            ans = True

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

Submission status: Accepted

Solution code:
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    n,m = f()
    a = [""] * n
    b = [""] * m
    for i in range(n):
        a[i] = input()
    
    for i in range(m):
        b[i] = input()
    
    if m>n:
        print("No")
    else:
        for i in range(0, n - m+1):
            for j in range(0, n - m+1):
                ok = True
                for k in range(m):
                    if a[i+k][j:j+ m] != b[k]:
                        ok = False
                if ok:
                    print("Yes")
                    return
        
        print("No")


solve()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
B - Template Matching
https://atcoder.jp/contests/abc054/tasks/abc054_b

"""
import sys


def solve(N, M, A, B):
    for y in range(0, N-M+1):
        for x in range(0, N-M+1):
            for m in range(M):
                t = A[y+m][x:x+M]
                if t != B[m]:
                    break
            else:
                return 'Yes'
    return 'No'


def main(args):
    N, M = map(int, input().split())
    A = [input() for _ in range(N)]
    B = [input() for _ in range(M)]
    ans = solve(N, M, A, B)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Accepted

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

ans = False
for i in range(n - m + 1):
    for j in range(n - m + 1):
        inc = True
        for ii in range(m):
            for jj in range(m):
                if a[i+ii][j+jj] != b[ii][jj]:
                    inc = False

        if inc:
            ans = True

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)]
f=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 a[i+k][j+l]!=b[k][l]:
                    break
            else:continue
            break
        else:
            f=1
            break
    if f==1:break
print("Yes" if f else "No")

Submission status: Accepted

Solution code:
N , M = map(int, input().split())
As =[input() for _ in range(N)]
Bs =[input() for _ in range(M)]
m = N-M
for i in range(m+1):
    for j in range(m+1):
        flag = True
        for k in range(M):
            for l in range(M):
                if As[k+i][l+j] != Bs[k][l]:
                    flag = False
                    break
            if not flag:
                break
        if flag:
            break
    if flag:
        break
if flag:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
from itertools import product

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

for i, j in product(range(N-M+1), range(N-M+1)):
    A_partial = [a[j:j+M] for a in A[i:i+M]]
    if A_partial == B:
        print('Yes')
        break
else:
    print('No')