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 = (int(i) for i in input().split())
a = []
b = []
for i in range(N):
    data = list(input())
    a.append(data)
for i in range(M):
    data = list(input())
    b.append(data)

#N=4
#M=2
#a=[['a','s','a','s'],['a','a','s','s'],['s','a','a','s'],['s','a','a','a']]
#b=[['s','a'],['a','s']]

L = N-M

def check(i,j):
    ans=True
    for line in range(M):
        if (ans==False):
            break
        for row in range(M):
            if (a[i+line][j+row]!=b[line][row]):
                ans=False
                break
    return ans

ans=False
for i in range(L+1):
    if(ans==True):
        break
    for j in range(L+1):
        ansnow=check(i,j)
 #       print(ansnow,i,j)
        if(ansnow==True):
            ans=True
            break
if(ans==True):
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
from itertools import product as prd

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


c = n - m + 1
ans = [list(map(lambda l: l[j:j+m], a[i:i+m])) == b for i, j in prd(range(c), range(c))]
print("Yes" if any(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)]

res = "No"
c = n - m + 1
for i in range(c):
    for j in range(c):
        if list(map(lambda l: l[j:j+m], a[i:i+m])) == b:
            res = "Yes"
print(res)

Submission status: Accepted

Solution code:
#coding: UTF-8
import sys
N,M=map(int,input().split())
Alist=[input() for i in range(0,N)]
Blist=[input() for i in range(0,M)]

def is_match(A,B,M):
    for i in range(0,M):
        if A[i]!=B[i]:
            return False
    return True

def make_A(A,i,j,M):
    C=[0]*M
    for k in range(0,M):
        C[k]=A[k+i][j:j+M]
    return C

for i in range(0,N-M+1):
    for j in range(0,N-M+1):
        C=make_A(Alist,i,j,M)
        if is_match(C,Blist,M):
            print("Yes")
            sys.exit()
print("No")

Submission status: Accepted

Solution code:
from collections import defaultdict


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

    for sy in range(N):
        for sx in range(N):

            ok = True
            for y in range(M):
                for x in range(M):
                    if sy + y < N and sx + x < N:
                        ok &= A[sy + y][sx + x] == B[y][x]
                    else:
                        ok = False

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#ABC054A
import sys

n,m=map(int,raw_input().split())
a=[]
b=[]
for i in xrange(n):
 a.append(raw_input())
for i in xrange(m):
 b.append(raw_input())
for i in xrange(m):
 if b[i] not in a[i]:
  print 'No'
  sys.exit()
 else:
  print 'Yes'
  sys.exit()

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

def LI(): return list(map(int, input().split()))
def II(): return int(input())
def LS(): return input().split()
def S(): return input()


def main():
    n,m = LI()
    a = []
    for i in range(n):
        t = 0
        for c in S():
            t <<= 1
            if c == '#':
                t += 1
        a.append(t)

    b = []
    for i in range(m):
        t = 0
        for c in S():
            t <<= 1
            if c == '#':
                t += 1
        b.append(t)

    mask = 2**m-1
    for i in range(n-m+1):
        for j in range(n-m+1):
            f = True
            for k in range(m):
                ak = (a[k+j] >> i) & mask
                if ak != b[k]:
                    f = False
                    break
            if f:
                return 'Yes'
    return 'No'


print(main())

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import io

sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')

n, m = map(int, input().split())
n_list = [input().split()[0] for _ in range(n)]
m_list = [input().split()[0] for _ in range(m)]
dif = n-m

ans = ""

class DropNest(Exception):
    pass 

try:
    for i in range(dif+1):
        for j in range(dif+1):
            target = n_list[i][j:j+m]
           
            if target != m_list[0]:
                continue
            else:
                cnt = 0
                for k in range(m):
                    target_h = n_list[i+k][j:j+m]
                    if target_h == m_list[k]:
                        cnt+=1
                if cnt==m:
                    ans="Yes"
                    raise DropNest
    print("No")
except DropNest:
    print(ans)

Submission status: Accepted

Solution code:
# coding=utf-8

if __name__ == '__main__':
    n, m = [int(s) for s in raw_input().split()]
    a = [raw_input().strip() for row in range(n)]
    b = [raw_input().strip() for row in range(m)]

    for i in range(m):
        if b[i] not in a[i]:
            print('No')
            exit(0)
    else:
        print('Yes')

Submission status: Accepted

Solution code:
s = input()
l = s.split()
N = int(l[0])
M = int(l[1])

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

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


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


def f(N, M, A, B):
    for i in range(N - M + 1):
        for j in range(N - M + 1):
            if g(N, M, A, B, i, j):
                return 'Yes'
    return 'No'

print(f(N, M, A, B))

Submission status: Accepted

Solution code:
m, n = input().split()
m = int(m)
n = int(n)
a = []
for i in range(m):
  row = input().rstrip()
  x = 0
  for c in row:
    x *= 2
    if c == "#":
      x += 1
  a.append(x)

b = []
for i in range(n):
  row = input().rstrip()
  x = 0
  for c in row:
    x *= 2
    if c == "#":
      x += 1
  b.append(x)
c = 2 ** n
found = False
for i in range(m - n + 1):
  for j in range(m - n + 1):
    if found:
      break
    found = True
    for k in range(n):
      if (((a[i+k] >> (m - n - j)) ^ b[k]) % c) != 0:
        found = False
        break
if found:
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
# -*- coding:utf-8 -*-
import re
import sys
N, M = map(int,input().split())
A = [ input() for i in range(N) ] 
B = [ input() for i in range(M) ]
for tmp in range(N-M+1):
    for tmp2 in range(N-M+1):
        flag = True
        for tmp3 in range(M):
            for tmp4 in range(M):
                if A[tmp+tmp3][tmp2+tmp4] != B[tmp3][tmp4]:
                    flag = False
        if flag:
            print("Yes")
            sys.exit()
print("No")
    #if A[tmp].find(B[tmp2]):
    #   pattern = re.complie(B[tmp2])
    #   iterator = re.finditer(pattern, A[tmp])

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
A = [input() for x in range(N)]
B = [input() for x in range(M)]
c = []
for i in range(N-M+1):
    for j in range(N-M+1):
        a = []
        for y in range(M):
            a += [A[j+y][i:i+M]]
        c += [a]
print('Yes' if sum(1 for x in c if x == B)>0 else 'No')

Submission status: Accepted

Solution code:
m,n=map(int,raw_input().split())
a=[]*m
b=[]*n
p=0
q=0
while(q<m):
	q+=1
	a.append(raw_input())
while(p<n):
	p+=1
	b.append(raw_input())
flag=False
# print a
# print b
for i in xrange(n):
	if not b[i] in (a[i]):
		flag=True
		break
if flag:
	print "No"
else:
	print "Yes"

Submission status: Accepted

Solution code:
import sys
if __name__ == '__main__':

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

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

    char = B[0][0]
    matc = False
    for i in range(N-M+1):
        for j in range(N-M+1):
            if A[i][j] == char:
                matc = True
                for k in range(M):
                    for l in range(M):
                        if A[i+k][j+l] == B[k][l]:
                            matc = True
                        else:
                            matc = False
                            break
                    if not matc:
                        break
                if matc == True:
                    print("Yes")
                    sys.exit(0)

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

Submission status: Accepted

Solution code:
import sys

count = 0
N_list = []
M_list = []
for line in sys.stdin:
    line = line.rstrip("\n")
    if count == 0:
        line = line.split(" ")
        N = int(line[0])
        M = int(line[1])
    elif count <= N:
        N_list.append(line)
    else:
        M_list.append(line)
    count+=1
    
    
def judge_match(N_l, M_l):
    slide_count = len(N_l[0]) - len(M_l[0]) + 1
    count = 0
    for j in range(slide_count):
        count = 0
        for i in range(len(N_l)):
            if N_l[i][j:j+len(M_l[0])] == M_l[i]:
                count += 1
                if count == len(M_l):
                    return count
    return count

m_count = 0
for i in range(len(N_list)):
    m_count = judge_match(N_list[i:i+len(M_list)], M_list)
    if m_count == len(M_list):
        print("Yes")
        exit(0)
print("No")

Submission status: Accepted

Solution code:
import sys
input_num = input().split()
N = int(input_num[0])
M = int(input_num[1])

AB = [input() for i in range(0, N + M)]
A = AB[0: N]
B = AB[N:]

diff = N - M
matches = []
for i in range(0, diff+1):
    l = 0
    while N - l > diff:
        index = A[i][l:].find(B[0])
        if index != -1 and i <= diff:
            matches.append((index, l, i))
        l += 1
if len(matches) == 0:
    print("No")
    sys.exit()
count_no = []
for m, l, i in matches:
    for a, b in zip(A[i:], B):
        if a[l:].find(b) != m:
            count_no.append(0)
            break
if len(count_no) == len(matches):
    print("No")
else:
    print("Yes")

Submission status: Accepted

Solution code:

n, m = map(int, raw_input().split())
a = [raw_input() for _ in xrange(n)]
b = [raw_input() for _ in xrange(m)]
f = 0
for i in xrange(m):
    if b[i] in a[i]:
        f += 1

if f == m:
    print "Yes"
else:
    print "No"

Submission status: Accepted

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

allFlag = 0
for i in range(n-m+1):
    for j in range(n-m+1):
        if ns[i][j:j+m] == ms[0]:
            Flag = 1
            for k in range(m):
                if ns[i+k][j:j+m]!=ms[k]:
                    Flag = 0
            if Flag and not allFlag:
                print("Yes")
                allFlag = 1
if not allFlag:
    print("No")

Submission status: Accepted

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

for x in range(n):
    a.append(list(input()))

for y in range(m):
    b.append(list(input()))


def check_photo(base, target):
    for i in range(n-m+1):
        check = base[i:i+m]
#        print(check)
        for j in range(n-m+1):
            check2 = [line[j:j+m] for line in check]
#            print(check2)
            if check2 == target:
                return print('Yes')
    return print('No')

check_photo(a, b)

Submission status: Accepted

Solution code:
def compare_image(A, B, N, M):
    for i in range(N):
        for j in range(N):
            # 範囲内なら
            if (i+M <= N) and (j+M <= N):
                b_flag = True

                for k in range(M):
                    str_a = A[i+k][j:j+M]
                    str_b = B[k]
                    if str_a != str_b:
                        b_flag = False

                if b_flag:
                    return True

    return False


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

if compare_image(A, B, N, M):
    string = "Yes"
else:
    string = "No"

print(string)

Submission status: Accepted

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

f = [0]*m
tmp = []
for j in range(m):
    f[j] = a[j].find(b[j])
    if f[j] != -1:
        tmp.append(j)
while -1 in f: f.remove(-1)

try:
    if len(f) == 0:
        print('No')
    else:
        count = 0
        for i in range(len(tmp)):
            count += 1
            if (b[tmp[i]] in a[tmp[i]]) == False:
                count = 0
        if count == m:
            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)]

res=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 res else '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())
ans = "No"

for i in range(n - m + 1):
    for j in range(n - m + 1):
        if a[i][j] == b[0][0]:
            c = []
            for k in range(m):
                c.append(a[i + k][j:j + m])
            if c == b:
                ans = "Yes"
print(ans)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
A = [list(input()) for _ in range(N)]
B = [list(input()) for _ in range(M)]
f = 0
for i in range(N-M+1):
	for j in range(N-M+1):
		for k in range(M):
			if f:
				f = 0
				break
			for l in range(M):
				if A[i+k][j+l] != B[k][l]:
					f = 1
					break
			else:
				if k == l == M-1:
					print("Yes")
					exit()
print("No")

Submission status: Accepted

Solution code:
import sys

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

strNs = []
strMs = []

for n in range(N):
	strNs.append(input())
	
for m in range(M):
	strMs.append(input())
	
def check_rest(start_row, start_col):
	for j in range(1,M):
		if strNs[start_row+j][start_col:start_col+M] != strMs[j]:
			return False
	else:
		return True
		

for i in range(N-M+1):
	tmp = strNs[i].find(strMs[0])
	while tmp >= 0:
		if check_rest(i, tmp):
			print("Yes")
			sys.exit()
		elif tmp + M > N:
			break
		else:
			tmp = strNs[i].find(strMs[0],tmp+1)
			
print("No")

Submission status: Accepted

Solution code:
def equal(A,B,i,j):
	ret = True
	for row in xrange(i,i+len(B)):
		if A[row][j:j+len(B)] != B[row-i]:
			ret = False
	return ret

n,m = map(int,raw_input().split())
A = []
B = []
for i in xrange(n):
	A.append(raw_input())
for i in xrange(m):
	B.append(raw_input())


contained = False
for i in xrange(n-m+1):
	for j in xrange(n-m+1):
		if equal(A,B,i,j):
			contained = True
			break
		else:
		 	pass
	if contained: break

if contained: print 'Yes'
else: print 'No'

Submission status: Accepted

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

for i in range(N-M+1):
    index=A[i].find(B[0])
    if index==-1:
        continue
    for j in range(M):
        if A[i+j][index:index+M] !=B[j]:
            break
    else :
        print "Yes"
        break
else:
    print "No"

Submission status: Accepted

Solution code:
import itertools

def solve(n, m, a, b):
    for i, j in itertools.product(range(n - m + 1), repeat=2):
        if all(a[i + x][j + y] == b[x][y] for x, y in itertools.product(range(m), repeat=2)): return "Yes"
    return "No"


if __name__ == '__main__':
    n, m = map(int, input().split())
    a = [[token for token in input()] for _ in range(n)]
    b = [[token for token in input()] for _ in range(m)]

    ans = solve(n, m, a, b)
    print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
n = input().split()

ar = int(n[0])
br = int(n[1])

a = []
b = []
for i in range(0, ar):
    a.append(input())

for j in range(0, br):
    b.append(input())

find = False
for i in range(0, ar - br + 1):
    for j in range(0, ar -br + 1):
        if a[i][j] == b[0][0]:
            same = True
            for k in range(0, br):
                for l in range(0, br):
                    if a[i+k][j+l] != b[k][l]:
                        same = False
                        break
            if same:
                find = True
                break
if find:
    print("Yes")
else:
    print("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 j in range(M)]

check = True
Flag = False

for s in range(N-M+1):
    for t in range(N-M+1):
        check = True
        for p in range(M):
            for q in range(M):
                if A[s+p][t+q] != B[p][q]:
                    check = False
        if check:
            Flag = True

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

Submission status: Accepted

Solution code:
import numpy as np
import sys

if __name__=="__main__":
   N, M = list(map(int, input().replace("\n","").split(" ")))
   a = [list(map(int, list(input().replace("\n","").replace(".", "1").replace("#", "0")))) for i in range(N)]
   a = np.array(a)
   b = [list(map(int, list(input().replace("\n","").replace(".", "1").replace("#", "0")))) for i in range(M)]
   b = np.array(b)


   for i in range(N - M + 1):
       for j in	range(N - M + 1):
           if((a[i:i+M,j:j+M] == b).all()):
               print("Yes")
               sys.exit(0)
   print("No")

Submission status: Accepted

Solution code:
nums = list(map(int, input().split()))
N =  nums[0] 
M = nums[1] 
K = N - M + 1
a = 0
b = 0
m = [[]]
n  = [[]]
while(a<N):
	if a == 0:
		n[0] = list(input())
	else:
		n.append(list(input()))
	a+=1
while(b<M):
	if b == 0:
		m[0] = list(input())
	else:
		m.append(list(input()))
	b+=1
judge = 0
for i in range(K):
	for j in range(K):
		num = 0
		for h in range(M):
			for k in range(M):
				if(m[h][k] == n[h+i][k+j]):
					num+=1
		if num == M*M:
			judge = 1

if judge == 1:
	print('Yes')
if judge == 0:
	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 = 0
for i in range(0,n-m+1):
    for j in range(0,n-m+1):
        if ans == 0:
            count = 0
            for k in range(m):
                for l in range(m):
                    if b[k][l] == a[i+k][j+l]:
                        count = count + 1
            if count == m*m:
                ans = 1
if ans == 0:
    print("No")
else:
    print("Yes")

Submission status: Accepted

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


def is_ok(A, B):
    for i in range(n - m + 1):
        for j in range(n - m + 1):
            C = []
            for k in range(i, i + m):
                line = ""
                for l in range(j, j + m):
                    line += A[k][l]
                C.append(line)
            # print(C)
            if C == B: return True
    return False


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

for i in range(m):
    B.append(input())
# print(A)
# print(B)
if is_ok(A, B):
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
N,M=map(int, raw_input().split())
#print N,M
A=[]
B=[]
for i in xrange(N):
    A.append(list(raw_input()))
#print A

for i in xrange(M):
    B.append(list(raw_input()))
#print B

diff=N-M+1
#print diff

found=False
for i in xrange(diff):
    for j in xrange(diff):
        wrong=False
        for k1 in xrange(M):
            for k2 in xrange(M):
                if A[i+k1][j+k2] != B[k1][k2]:
                    wrong=True
                    break
            if wrong:
                break
        if wrong==False:
            found=True
            break
    if found==True:
        break
if found:
    print 'Yes'
else:
    print 'No'

Submission status: Accepted

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

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

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

def is_contain(i, b_pos):
    containing = True
    for k in range(1, m):
        if A[i+k][b_pos:(b_pos+len(B))] != B[k]:
            containing = False
    return containing

if n < m or len(A) < len(B):
    print("No")
    exit()

for i in range(n - m + 1):
    lineA = A[i]
    lineB = B[0]
    lineB_pos = lineA.find(lineB)
    if lineB_pos >= 0:
        if is_contain(i, lineB_pos):
            print("Yes")
            exit()

print("No")

Submission status: Accepted

Solution code:
data = raw_input()

n,m = map(int,data.split(" "))

data = []

for x in range(n):
  data.append(raw_input())

temp = []

for x in range(m):
  temp.append(raw_input())

for x in range(n-m+1):
  for y in range(n-m+1):
    if temp[0] == data[x][y:y+m]:
      flag = 1
      pos = y
      for xx in range(x+1,x+m):
        if temp[xx - x] != data[xx][pos:pos+m]:
          flag = 0
          break
      if flag == 1:
        print "Yes"
        exit(0)

print "No"

Submission status: Accepted

Solution code:
from itertools import product

n, m = [int(i) for i in input().rstrip().split()]
AA = [[0 if i == '.' else 1 for i in input().rstrip()] for _ in range(n)]
BB = [[0 if i == '.' else 1 for i in input().rstrip()] for _ in range(m)]

for i_r, i_c in product(range(n - m + 1), range(n - m + 1)):
    i_r -= 1
    i_c -= 1
    for k_r, k_c in product(range(m), range(m)):
        if AA[i_r + k_r][i_c + k_c] == BB[k_r][k_c]:
            continue
        else:
            break
    else:
        print('Yes')
        break
else:
    print('No')

Submission status: Accepted

Solution code:
import sys
import numpy as np

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

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

for row in range(N - M + 1):
    for col in range(N - M + 1):
        patch = A[row:row + M, col:col + M].flatten()
        if str(patch) == str(B):
            print('Yes')
            sys.exit()
print('No')

Submission status: Accepted

Solution code:
import numpy as np
import sys
temp = input().split()
N = int(temp[0])
M = int(temp[1])
A = []
B = []
check = False
def change(n):
  if(n=='#'):
    return True;
  return False;

for i in range(N):
  temp = input()
  A.append(list(map(change, temp)))
for i in range(M):
  temp = input()
  B.append(list(map(change, temp)))
A = np.array(A)
B = np.array(B)

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

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

Submission status: Accepted

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

found = False
for x in range(m-n+1):
  for y in range(m-n+1):
    for k in range(n):
      if a[x+k][y:y+n] != b[k]:
        break
    else:
      found = True
      break
  if found: break    
if found:
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
master,sub=[],[]
for i in range(n):
    master.append(input())
for j in range(m):
    sub.append(input())
def chk(a,b,y,x):
    t=len(b)
    for i in range(t):
        if a[y+i][x:x+t]!=b[i]:
            return 0
    return 1

for i in range(n-m+1):
    for j in range(n-m+1):
        if master[i][j:j+m]==sub[0]:
            if chk(master,sub,i,j):
                print('Yes')
                exit()
print('No')

Submission status: Accepted

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


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


for i in range(N-M+1):
    for j in range(N-M+1):
        if check(i, j):
            print "Yes"
            exit()
print "No"

Submission status: Accepted

Solution code:
import numpy as np
N, M = map(int,input().split())
A = [list(map(lambda x: 1 if x == "." else 0, list(input()))) for n in range(N)]
B = [list(map(lambda x: 1 if x == "." else 0, list(input()))) for m in range(M)]

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

flag = False
for r in range(N-M+1):
    for c in range(N-M+1):
        if (A[r:r+M, c:c+M] == B).all():
            flag = True
if flag:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

N, M = map(int, raw_input().split())
A, B = [], []
for i in range(N): A.append(raw_input())
for i in range(M): B.append(raw_input())
result = "No"
for x in range(N):
	for y in range(N):
		if(match_m(x,y,N,M,A,B)): 
			result = "Yes"
			break
print result

Submission status: Accepted

Solution code:
from sys import exit, setrecursionlimit
from functools import reduce
from itertools import *
from collections import defaultdict
from bisect import bisect

def read():
  return int(input())

def reads():
  return [int(x) for x in input().split()]

setrecursionlimit(1000000)

(N, M) = reads()

A = []; B = []
for _ in range(N):
  s = input()
  A.append(s)
for _ in range(M):
  s = input()
  B.append(s)

for x in range(N-M+1):
  for y in range(N-M+1):
    if all(A[y+j][x:x+M] == B[j] for j in range(M)):
      print("Yes"); exit()

print("No")

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
L1 = [input() for x in range(N)]
L2 = [input() for x in range(M)]
LL = []
for i in range(N-M+1):
    for j in range(N-M+1):
        a = []
        for y in range(M):
            a += [L1[j+y][i:i+M]]
            pass
        LL += [a]
print('Yes' if sum(1 for x in LL if x == L2)>0 else 'No')

Submission status: Accepted

Solution code:
import sys

def debug(x, table):
    for name, val in table.items():
        if x is val:
            print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr)
            return None

def solve():
    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):
        for j in range(N - M + 1):
            for k in range(M):
                s1 = A[i + k][j:j + M]
                s2 = B[k]
                if s1 != s2:
                    break
            else:
                print('Yes')
                return None

    print('No')


if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
import sys

N , M = [int(n) for n in 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):
    for j in range(N-M+1):
        corres = True
        for k in range(M):
            if A[i+k][j:j+M] != B[k]:
                corres = False
                break
        if corres == True:
            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 i in range(M)]
def _search(i, j):
    flag = True
    for k in range(M):
        for l in range(M):
            flag &= A[i+k][j+l] == B[k][l]
            if not flag:
                return flag
    return flag

def search():
    for i in range(N-M+1):
        for j in range(N-M+1):
            if _search(i, j):
                return 'Yes'
    return 'No'
print(search())

Submission status: Accepted

Solution code:
#coding:utf-8
import sys
a=[]
b=[]
N,M=map(int ,raw_input().split())
for i in range(N):
    a.append(list(raw_input()))
for i in range(M):
    b.append(list(raw_input()))

def chk(a,b,x,y):
    global M
    global N
    #x,y:左上座標
    #print x,y
    for row in range(M):
        for col in range(M):
            if a[row+y][col+x]!= b[row][col]:
                return False
    return True

f=False
for row in range(N-M):
    for col in range(N-M):
        if chk(a,b,col,row):
            f=True
if N==1 and M==1 and a[0][0]==b[0][0]:
    print "Yes"
elif f:
    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)]

res=False
for i in range(n-m+1):
    for j in range(n-m+1):
        t=[r[j:j+m] for r in a[i:i+m]]
        res|=t==b
print('Yes' if res else '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())

res = False
for sy in range(N - M + 1):
    for sx in range(N - M + 1):
        ok = True
        for dy in range(M):
            y = sy + dy
            a = A[y][sx:sx + M]
            ok = ok and a == B[dy]
        res = res or ok
print("Yes" if res else "No")

Submission status: Accepted

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

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

ball = ''.join(b)

def check():
    for i in range(n):
        if i + m > n:
            continue

        for j in range(n):
            if j + m > n:
                continue

            aall = ""
            for k in range(m):
                aall += a[i+k][j:j+m]

            if aall == ball:
                return True

    return False

ret = "Yes" if check() else "No"
print(ret)

Submission status: Accepted

Solution code:
N, M = map(int, raw_input().split())
A = [None] * N
for i in xrange(N):
    A[i] = list(raw_input())
B = [None] * M
for i in xrange(M):
    B[i] = list(raw_input())


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

found = False
for y in xrange(N - M + 1):
    for x in xrange(N - M + 1):
        if find(x, y):
            found = True
            break
    if found:
        break
print 'Yes' if found else 'No'