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:
from collections import defaultdict


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

    for y in range(N - M + 1):
        for x in range(N - M + 1):
            ok = True
            for by in range(M):
                for bx in range(M):
                    if A[y + by][x + bx] != B[by][bx]:
                        ok = False
            if ok:
                print("Yes")
                return
    print("No")

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

ans = False
for sy in range(N-M+1):
	for sx in range(N-M+1):
		flag = True
		for iy in range(M):
			if B[iy] != A[sy+iy][sx:sx+M]:
				flag = False
				break
		if flag:
			ans = True
			break

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

Submission status: Accepted

Solution code:
import sys

# sys.stdin = open('b1.in')


def read_int_list():
    return list(map(int, input().split()))


def read_str_list():
    return input().split()


def read_int():
    return int(input())


def read_str():
    return input()


N, M = read_int_list()
A = [read_str() for i in range(N)]
B = [read_str() for j in range(M)]


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(0, N - M + 1):
        for j in range(0, 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:
N, M = map(int, input().split())

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

res = False
count = 0
for i in range(N - M + 1):
    if res:
        break
    for j in range(N - M + 1):
        count = 0
        for m in range(M):
            if A[i + m][j:j + M] != B[m]:
                res = False
                break
            else:
                count += 1
        if count == M:
            res = True
            break

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

Submission status: Accepted

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

import sys
import subprocess
import json
import time
import math
import re
import sqlite3

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):
        ok = True
        for k in range(M):
            for l in range(M):
                if A[i+k][j+l] != B[k][l]: ok = False;
        if ok:
            print("Yes")
            exit(0)
print("No")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a = input().split()
n = int(a[0])
m = int(a[1])
img1 = []
for i in range(n):
    img1.append(input())
img2 = []
for j in range(m):
    img2.append(input())

def match(x, y):
    for k in range(m):
        for l in range(m):
            if img1[x+k][y+l] != img2[k][l]:
                return False
    return True

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

Submission status: Accepted

Solution code:
def contains(a, b):
  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:
        return True
  return False

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

imga = [raw_input() for i in range(N)]
imgb = [raw_input() for i in range(M)]
print 'Yes' if contains(imga, imgb) else 'No'

Submission status: Accepted

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

A = [[i for i in input()] for j in range(N)]
B = [[i for i in input()] for k in range(M)]

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

        for k in range(M):
            for l in range(M):
                if A[i+k][j+l] != B[k][l]:
                    diff = 1
                    break

            if diff == 1:
                break

        if diff == 0:
            print('Yes')
            sys.exit()

print('No')

Submission status: Accepted

Solution code:
N, M = map(int, raw_input().split())
A = [raw_input() for i in range(N)]
B = [raw_input() for i in range(M)]
def judge():
    for i in range(N-M+1):
        for j in range(N-M+1):
            ok = True
            for r in range(M):
                for c in range(M):
                    if A[i+r][j+c] != B[r][c]:
                        ok = False
            if ok:
                return "Yes"
    return "No"
print judge()

Submission status: Accepted

Solution code:
# Suplemental: ABC54 B
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()))

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

print('No')

Submission status: Accepted

Solution code:
def bsolve(a,b,c,d):
	M=len(b)
	for i in range(M):
		for j in range(M):
			if(a[c+i][d+j]!=b[i][j]):
				return 0
	return 1
def b():
	N,M=list(map(int,input().split()))
	A=[input()for _ in range(N)]
	B=[input()for _ in range(M)]
	flag=0
	for i in range(N-M+1):
		for j in range(N-M+1):
			if(A[i][j]==B[0][0]):
				flag=bsolve(A,B,i,j)
				if(flag==1):
					print("Yes")
					return 
	if(flag==1):
		print("Yes")
	else:
		print("No")
b()

Submission status: Accepted

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

a = []
b = []

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

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

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

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


print("No")

Submission status: Accepted

Solution code:
so, sp = list(map(int, input().split()))
orig = []
part = []
for i in range(so):
    orig.append(input())
for i in range(sp):
    part.append(input())
sd = so - sp
def check(orig, part, sd, sp):
    for x in range(sd+1):
        for y in range(sd+1):
            if [a[y:y+sp] for a in orig[x:x+sp]] == part:
                return True
    return False
print('Yes' if check(orig, part, sd, sp) else 'No')

Submission status: Accepted

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

agree = False
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:
            agree = True
            break
    if agree:
        break
if agree:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

import sys
import os


N, M = map(int, input().split())
if N < M:
    print('No')
    quit()

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

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

#print(A)
#print(B)

# search
for offset_i in range(N-M+1):
    for offset_j in range(N-M+1):
        # check match
        all_match = True
        for i in range(M):
            for j in range(M):
                if A[i+offset_i][j+offset_j] != B[i][j]:
                    all_match = False
        if all_match:
            print('Yes')
            quit()
print('No')

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
n,m = map(int, raw_input().split())
picA = [raw_input() for _ in range(n)]
picB = [raw_input() for _ in range(m)]
find = True
for x in range(n-m+1):
    for y in range(n-m+1):
        find = True
        for p in range(m):
            if picA[y+p][x:x+m] != picB[p]:
                find = False
                break
        if find:
            break
    if find:
        break
if find:
    print 'Yes'
else:
    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())
t = 0
for i in range(N-M+1):
	for j in range(N-M+1):
		t = 0
		for k in range(M):
			if t:
				break
			for l in range(M):
				if A[i+k][j+l] != B[k][l]:
					t = 1
					break
		else:
			if A[i+k][j+l] == B[k][l]:
				print("Yes")
				exit()
print("No")

Submission status: Accepted

Solution code:
def main():
    #infile = open("compprog.txt", mode="r")
    #n, m = [int(x) for x in infile.readline().split()]
    n, m = [int(x) for x in input().split()]
    a = []
    b = []
    for _ in range(n):
        #a.append(infile.readline())
        a.append(input())
    for _ in range(m):
        #b.append(infile.readline())
        b.append(input())
    if solve(a, b, n, m):
        print("Yes")
    else:
        print("No")


def solve(a, b, n, m):
    for row in range(n - m + 1):
        for col in range(n - m + 1):
            if check(a, row, col, b, m):
                return True
    return False


def check(a, row, col, b, m):
    for this_row in range(row, row + m):
        for this_col in range(col, col + m):
            if a[this_row][this_col] != b[this_row - row][this_col - col]:
                return False
    return True


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def check_match(A, B):
    N = len(A)
    M = len(B)
    for i in range(N):
        for j in range(N):
            match = True
            for k1 in range(M):
                for k2 in range(M):
                    if i+k1 >= N or j+k2 >= N or A[i+k1][j+k2] != B[k1][k2]:
                        match = False
                        break
            if match == True:
                return True
    return False

if __name__ == "__main__":
    size = [int(i) for i in input().split()]
    N = size[0]
    M = size[1]
    A = []
    B = []
    for i in range(N):
        A.append(input())
    for i in range(M):
        B.append(input())
    if check_match(A, B) == True:
        print("Yes")
    else:
        print("No")

Submission status: Accepted

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

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

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

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

Submission status: Accepted

Solution code:
size = list(map(int,raw_input().split()))

large_pic=[]
small_pic=[]
for i in range (size[0]):
    large_pic.append (list(raw_input().strip()))
for i in range (size[1]):
    small_pic.append (list(raw_input().strip()))


flag = False
cut_pic = []
for i in range (size[0]-size[1]+1):
    for j in range (size[0]-size[1]+1):
        for k in range (size[1]):
            cut_pic.append(large_pic[i+k][j:j+size[1]])
        if cut_pic == small_pic:
            flag = True
        else:
            cut_pic =[]
print "Yes" if flag == True else "No"

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import numpy as np

N,M = map(int, raw_input().split())
image = np.zeros((N,N),dtype='int8')
template = np.zeros((M,M),dtype='int8')
YesFlag = 0

for i in range(N):
    S = raw_input()
    for j in range(len(S)):
        if(S[j]=='#'):
            image[i][j] = 0
        elif(S[j]=='.'):
            image[i][j] = 1
for i in range(M):
    S = raw_input()
    for j in range(len(S)):
        if(S[j]=='#'):
            template[i][j] = 0
        elif(S[j]=='.'):
            template[i][j] = 1

#print(image)
#print(template)

for i in range(N-M+1):
    for j in range(N-M+1):
        #print(image[i:M+i,j:M+j])
        if(np.all(image[i:M+i,j:M+j]==template) == True):
            YesFlag = 1
            break
    if(YesFlag == 1):
        break

if(YesFlag == 1):
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
import numpy as np


def main():
    # 入力処理
    # M = int(input())
    N, M = map(int, input().split())
    sA = ''.join([input() for i in range(N)])
    sB = ''.join([input() for i in range(M)])
    A = np.array([s for s in sA]).reshape(N,N)
    B = np.array([s for s in sB]).reshape(M,M)

    # アルゴリズム本体
    result = np.zeros((N-M+1,N-M+1), dtype=bool)
    for i in range(N-M+1):
        for j in range(N-M+1):
            result[i,j] = (A[i:i+M, j:j+M] == B).all()

    # 出力
    if result.any():
        print('Yes')
    else:
        print('No')


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    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):
            if check(i, j, M, A, B):
                print('Yes')
                return
    print('No')


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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
if __name__ == '__main__':
  s = str(input()).split(" ")
  N = int(s[0])
  M = int(s[1])
  A, T = list(), list()
  for i in range(0,N):
    A.append(input())
  for i in range(0,M):
    T.append(input())

  # for i in range(0,N):
  #   for j in range(0,N):
  #     print(A[i][j], end='')
  #   print()
  ans = False
  for t in range(0, N-M+1):
    for l in range(0, N-M+1):
      ok = True
      for i in range(t, t+M):
        for j in range(l, l+M):
          if A[i][j] != T[i-t][j-l]:
            ok = False
      if ok:
        ans = True
  if ans:
    print("Yes")
  else:
    print("No")

Submission status: Accepted

Solution code:
import sys

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

for i in range(n-m+1):
    for j in range(n-m+1):
        for k in range(m):
            if k <= m-2:
                if a[i+k][j:j+m] == b[k]:
                    continue
                else:
                    break
            else:
                if a[i+k][j:j+m] == b[k]:
                    print("Yes")
                    sys.exit()
                else:
                    break

print("No")

Submission status: Accepted

Solution code:
import sys
m,n = map(int,input().split())
mlist = []
nlist = []
for i in range(m):
    a = input()
    mlist.append(list(a))
for i in range(n):
    a = input()
    nlist.append(list(a))

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

Submission status: Accepted

Solution code:
def main():
    nm = map(int, raw_input().split())
    A = []
    B = []
    flag = False
    for i in range(nm[0]):
        A.append(raw_input())
    for i in range(nm[1]):
        B.append(raw_input())

    for i in range(nm[0]):
      if i + nm[1] <= nm[0]:
        for j in range(nm[0]):
            if j + nm[1] <= nm[0]:
                for k in range(nm[1]):
                    for l in range(nm[1]):
                        if(A[i+k][j+l] == B[k][l]):
                            flag = True
                        else:
                            flag = False
                            break 
                    if flag == False:
                        break
            else:
                break
            if flag:
                 break
        if flag:
            break
      else:
          break
       
    if flag:
        return "Yes"
    else:
        return "No"    
print main()

Submission status: Accepted

Solution code:
import numpy as np

N, M = [int(x) for x in input().split()]
A=[]
B=[]
for i in range(N):
    A.append(list(input()))
for j in range(M):
    B.append(list(input()))
A = np.array(A)
B = np.array(B)
for i in range(N-M+1):
    for j in range(N-M+1):
        A_ = A[i:(i+M),j:(j+M)]
        if np.array_equal(A_,B):
            print('Yes')
            exit()

print('No')

Submission status: Accepted

Solution code:
N,M = map(int, input().split())
a=[input() for i in range(N)]
b=[input() for i in range(M)]
 
ans = 0
for i in range(N-M+1):
    for j in range(N-M+1):
        t = [k[j:j+M] for k in a[i:i+M]]
        if t==b: ans =1
 
print("Yes" if ans else "No")

Submission status: Accepted

Solution code:
t = list(str(input()).split(" "))
n = int(t[0])
m = int(t[1])

a = list()
for i in range(n):
    a.append(str(input()))

b = list()
for i in range(m):
    b.append(str(input()))

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

        if(fg == False):
            print("Yes")
            exit()

print("No")

Submission status: Accepted

Solution code:
def subImage(x,y,M,A):
    C = []
    for i in range(M):
        C.append(A[x+i][y:y+M])
    return C
    
def containIm(N,M,A,B):
    judge = 0    
    for x in range(N-M+1):
        for y in range(N-M+1):
            C = subImage(x,y,M,A)
            if C == B:
                judge = 1
                return judge
    return judge
    

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

judge = containIm(N,M,A,B)
if judge == 1:
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

def check(i, j):
    for ii in range(M):
        for jj in range(M):
            if A[i + ii][j + jj] != B[ii][jj]:
                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:
#-*- coding: utf-8 -*-

#matching
def matching(x,y):
    for s in range(m):
        for t in range(m):
            if not a[x+s][y+t] == b[s][t]:
                return 0

    return 1


if __name__ == '__main__':
    #read
    n, m = map(int,raw_input().split())
    a=[]
    for i in range(n):
        a.append(list(raw_input()))
    b=[]
    for j in range(m):
        b.append(list(raw_input()))


    #slide  an origin point
    for i in range(n - m + 1):
        for j in range(n - m + 1):
            #print a[i][j]
            ans = matching(i,j)
            if ans == 1:
                print 'Yes'
                exit()

    if ans == 0:
        print 'No'

    '''
    基準点をスライドさせていく
    一列目がマッチングするか確認
    その後の列もマッチングするか確認
    全てマッチすればYesと返す
    '''

Submission status: Accepted

Solution code:
n,m = map(int, raw_input().split())
np=[]
mp=[]
for i in xrange(0, n):
  np.append(raw_input())
for i in xrange(0, m):
  mp.append(raw_input())
 
for i in xrange(0,n-m+1):
  for j in xrange(0, n-m+1):
    flag = True
    for x in xrange(0, m):
      for y in xrange(0, m):
        if mp[x][y] != np[i+x][j+y]:
          flag = False
          break
      if flag == False:
        break
    if flag:
      print "Yes"
      break
  if flag: break
if flag==False: print "No"

Submission status: Accepted

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

f = 0
for i in range(n - m + 1):
    for j in range(n - m + 1):
        t = [k[j:j + m] for k in a[i:i + m]]
        if t == b: f = 1

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

Submission status: Accepted

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

for _ in xrange(N):
    A.append(raw_input())
for _ in xrange(M):
    B.append(raw_input())

def match(x, y):
    for i in xrange(M):
        for j in xrange(M):
            if A[x+i][y+j] != B[i][j]: return None
    return 1

def main():
    for x in xrange(N-M+1):
        for y in xrange(N-M+1):
            if match(x, y):
                return 'Yes'
    return 'No'

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

Submission status: Accepted

Solution code:
n, m = map(int, raw_input().strip().split(" "))
arr_n = [None] * n
arr_m = [None] * m
for i in range(n):
	arr_n[i] = raw_input().strip()
for i in range(m):
	arr_m[i] = raw_input().strip()

found = False
for i in range(n-m+1):
	if found:
		break
	for j in range(n-m+1):
		if found:
			break
		match = True
		for k in range(m):
			if arr_m[k] != arr_n[i+k][j:j+m]:
				match = False
				break
		if match:
			found = True
			print "Yes"
if not found:
	print "No"

Submission status: Accepted

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

for p in range(n-m+1):
    for q in range(n-m+1):
        ans=0
        for i in range(m):

            row = str(a[q+i])
            cut = str(row[p:p+m])

            if cut == b[i]:
                ans += 1
                
            # print(row,cut,b[i],ans)

        if ans == m:
            print('Yes')
            exit()

print('No')

Submission status: Accepted

Solution code:
# coding: utf-8

## atode

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

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

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

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

def move(d):
	for x in range(d):
		for y in range(d):
			if check(x, y):
				return True
	return False

is_include = move(n-m+1)

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

ret = False
for i in range(N):
    for j in range(N):
        if i + M > N or j + M > N:
            continue
        f = True
        for k in range(M):
            for l in range(M):
                if A[i + k][j + l] != B[k][l]:
                    f = False
                    break
            if not f:
                break
        if f:
            ret = True
if ret:
    print('Yes')
else:
    print("No")

Submission status: Accepted

Solution code:
import numpy as np

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

N, M = [], []
for i in range(n):
    N.append(list(input()))
for i in range(m):
    M.append(list(input()))

N, M = np.array(N), np.array(M)

# print(N)
# print(M)

def match():
    for i in range(n - m + 1):
        for j in range(n - m + 1):
            # print(i, i+m, j, j+m)
            if (N[i:i+m, j:j+m] == M).all():
                return "Yes"
    return "No"

print(match())

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
A = []
B = []
N, M = list(map(int, input().split()))

for n in range(N):
    A.append(input())
for n in range(M):
    B.append(input())

def match(r, c):
    for i, row in enumerate(range(r, r+M)):
#        print("{} : {}  {}".format(A[row][c:c+M], B[i], A[row][c:c+M]==B[i]))
        if A[row][c:c+M] != B[i]:
            return False
    return True

ok = 0

for r in range(N-M+1):
    if ok == 1:
        break
    else:
        for c in range(N-M+1):
            if match(r, c):
                print("Yes")
                ok = 1
                break
            
if not ok:
    print("No")

Submission status: Accepted

Solution code:
import itertools

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

ref_tuple = itertools.product(range(0,N-M+1),range(0,N-M+1))
t=False
for ref_row_a, ref_col_a in ref_tuple:
    for row_b, col_b in itertools.product(range(0,M),range(0,M)):
        if not A[ref_row_a+row_b][ref_col_a+col_b]==B[row_b][col_b]:
            break
        if (row_b, col_b)==(M-1,M-1):
            t=True
            break
    if t:
        break

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

Submission status: Accepted

Solution code:
n,m = map(int, raw_input().split())
aa = [0] * n
bb = [0] * m
for i in range(n):
    aa[i] = list(raw_input())
for i in range(m):
    bb[i] = list(raw_input())

flag = True
for i in range(n-m):
    for j in range(n-m):
        flag = True
        for ik in range(m):
            for jk in range(m):
                if aa[i+ik][j+jk] != bb[ik][jk]:
                    flag = False
                    
        if flag == True: break
    if flag == True: break

if flag == True:
    print 'Yes'
else:
    print 'No'

Submission status: Accepted

Solution code:
# -*- coding:utf8

N,M = [int(x) for x in raw_input().split(' ')]

A = [raw_input() for x in range(N)]
B = [raw_input() for x in range(M)]

def getpattern(image, s = 0, x = 0, y = 0):
    if s == 0:
        s = len(image)

    return ''.join([image[i][x:x+s] for i in range(y, y + s)])

def match(N,M,A,B):
    size = M

    bpattern = getpattern(B)
    for j in range(0, N - M + 1):
        for i in range(0, N - M + 1):
            if getpattern(A, size, i, j) == bpattern:
                return 'Yes'

    return 'No'

print match(N,M,A,B)

Submission status: Accepted

Solution code:
def srch_all(ptn, str):
    index = []
    i = -1
    while True:
        i = str.find(ptn, i + 1)
        if i > -1:
            index.append(i)
        else:
            break
    return index

def judge(i, jlist, len):
    for l in jlist:
        k = 1
        while k < M:
            try:
                if n[i + 1][l:l + len] == m[k]:
                    pass
                else:
                    return 'No'
            except:
                return 'No'
            i += 1
            k += 1
        else:
            return 'Yes'

N, M = map(int, input().split())
i = 0
n = []
while i < N:
    n.append(input())
    i += 1

i = 0
m = []
while i < M:
    m.append(input())
    i += 1

i = 0
r = 'No'
while i < N:
    result = srch_all(m[0], n[i])
    if len(result) > 0:
        r = judge(i, result, len(m[0]))
        if r == 'Yes':
            break
    i += 1
print(r)

Submission status: Accepted

Solution code:
import sys

A=[]
B=[]
NM=input().split(" ")
N=int(NM[0])
M=int(NM[1])

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



for i in range(N-M+1):
    for j in range(N-M+1):
        k=i
        count=0
        while A[k+count][j:M+j:1]==B[count]:
            count+=1
            if count==M:
                print("Yes")
                sys.exit()

print("No")

Submission status: Accepted

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


def f():
    if a == b:
        return True
    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:
                return True
    return False

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

Submission status: Accepted

Solution code:
# determines whether b is a subimage of a at start point (x,y)
def findMatch(x, y):
	for i in range(m):
		for j in range(m):
			if b[i][j] != a[i+x][j+y]:
				return False
	return True

# get size of picture A (NxN) and picture B (MxM)
n, m = map(int, raw_input().split())

# populate image a
a = []
for i in range(n):
	a.append(list(raw_input()))

# populate image b
b = []
for i in range(m):
	b.append(list(raw_input()))

# iterate over all possible start points to find valid subimage
found = False
for i in range(n-m+1):
	for j in range(n-m+1):
		if findMatch(i,j):
			found = True

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())
for y in range(n-m+1):
    for x in range(n-m+1):
        eq=True
        for yy in range(m):
            for xx in range(m):
                eq &= a[y+yy][x+xx] == b[yy][xx]
                if not eq: break
            if not eq: break
        if eq:
            print("Yes")
            exit(0)
print("No")