Problem:


Score : 200 points

Problem Statement

You are given an image A composed of N rows and N columns of pixels, and a template image B composed of M rows and M columns of pixels.

A pixel is the smallest element of an image, and in this problem it is a square of size 1×1.

Also, the given images are binary images, and the color of each pixel is either white or black.  

In the input, every pixel is represented by a character: . corresponds to a white pixel, and # corresponds to a black pixel.

The image A is given as N strings A_1,...,A_N.

The j-th character in the string A_i corresponds to the pixel at the i-th row and j-th column of the image A (1≦i,j≦N).

Similarly, the template image B is given as M strings B_1,...,B_M.

The j-th character in the string B_i corresponds to the pixel at the i-th row and j-th column of the template image B (1≦i,j≦M).  

Determine whether the template image B is contained in the image A when only parallel shifts can be applied to the images.  

Constraints

1≦M≦N≦50 

A_i is a string of length N consisting of # and ..

B_i is a string of length M consisting of # and ..

Input

The input is given from Standard Input in the following format:

N M
A_1
A_2
:  
A_N
B_1
B_2
:  
B_M

Output

Print Yes if the template image B is contained in the image A. Print No otherwise.

Sample Input 1

3 2
#.#
.#.
#.#
#.
.#

Sample Output 1

Yes

The template image B is identical to the upper-left 2 × 2 subimage and the lower-right 2 × 2 subimage of A. Thus, the output should be Yes.

Sample Input 2

4 1
....
....
....
....
#

Sample Output 2

No

The template image B, composed of a black pixel, is not contained in the image A composed of white pixels.



Sample input:
3 2
#.#
.#.
#.#
#.
.#


Sample output:
Yes

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
a = [input() for i in range(n)]
b = [input() for i in range(m)]
for k in range(n-m+1):
  for j in range(n-m+1):
    h="true"
    for i in range(m):
      if a[k+i][j:j+m]!=b[i]:
        h="false"    
    if h=="true":
      print("Yes")
      exit()
else:
  print("No")

Submission status: Accepted

Solution code:
nm=list(map(int,input().split()))
a,b=[],[]
for i in range(nm[0]):
    a.append(input())
for j in range(nm[1]):
    b.append(input())

def check(i,j):
    result="match"
    for k in range(nm[1]):
        if b[k]==a[i+k][j:j+nm[1]]:
            continue
        else:
            result="unmatch"
            break
    return result

flag=0
for i in range(nm[0]-nm[1]+1):
    if flag==0:
        for j in range(nm[0]-nm[1]+1):
            if check(i,j)=="match":
                print("Yes")
                flag=1
                break
if flag==0:
    print("No")

Submission status: Accepted

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

A=[]
B=[]

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

for m in range(M):
    B.append(input())
        
if N<M:
    print("No")
    exit()
# check
for n in range(N):
      # Bのm行目と一致
      # Bのm+1行目と一致するかチェック
      span =[m.span() for m in re.finditer(B[0], A[n])]
      #print(span)
      if span==[]:
          continue
      allgood=False
      for sp in span:
        for i in range(min(M,N)):
            if n+i>=N:
                allgood=False
                break
            #print(n)
            #print((B[i],A[n+i][span[0][0]:span[0][1]]))
            if (B[i]==A[n+i][sp[0]:sp[1]]):
                allgood=True
                continue
            else:
                allgood=False
                break
        if allgood==True:
            print("Yes")
            exit()

print("No")

Submission status: Accepted

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

for oh in range(N-M+1):
    for ow in range(N-M+1):
        match = True
        for ih in range(M):
            for iw in range(M):
                if A[oh+ih][ow+iw]!=B[ih][iw]:
                    match = False
                    break
            if not match: break
        if match:
            print('Yes')
            exit()
print('No')

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
la=[]
lb=[]
for i in range(N):
    la.append(input())
for i in range(M):
    lb.append(input())
f=0
for i in range(N-M+1):
    if f==1:
        break
    for j in range(N-M+1):
        if f==1:
            break
        f=0
        for k in range(M):
            for l in range(M):
                if la[i+k][j+l]!=lb[k][l]:
                    f=-1
                    break
            if f==-1:
                break

        if f!=-1:
            f=1
if f==1:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
import numpy as np

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

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
print("Yes" if bl 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)]


for i in range(N - M + 1):
        for j in range(N - M +1):
                flag = True
                for h in range(M):
                        for w in range(M):
                                if A[i+h][j+w] != B[h][w]:
                                        flag = False             
                                        break
                if flag == True:
                        print("Yes")
                        exit()
print("No")

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
 
import math
import itertools
import sys
import copy
 
# 入力
N, M = map(int, input().split())
#N = int(input())
#S = str(input())

A = []
for _ in range(N) :
  A.append(str(input()))

B = ""
for _ in range(M) :
  B += str(input())

for x in range(N-M+1) :
  for y in range(N-M+1) :
    t = ""
    for k in range(M) :
      t += (A[y+k])[x:x+M]
    #print (t)
    if t == B :
      print ("Yes")
      exit()
      
print ("No")

Submission status: Accepted

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

hantei = False

for i in range(N-M+1):
  for j in range(N-M+1):
    C=np.array(A[i:i+M,j:j+M])
    if (C==B).all():
      hantei = True
print('Yes' if hantei else 'No')

Submission status: Accepted

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

if N==M:
    f=1
    for i in range(N):
        if f==-1:
            break
        for j in range(N):
            if la[i][j]!=lb[i][j]:
                f=-1
                break
    if f==1:
        print("Yes")
    else:
        print("No")
else:
    f=0
    for i in range(N-M):
        if f==1:
            break
        for j in range(N-M):
            if f==1:
                break
            f=0
            for k in range(M):
                if f==-1:
                    break
                for l in range(M):
                    if la[i+k][j+l]!=lb[k][l]:
                        f=-1
                        break
                if k==M-1 and l==M-1 and f!=-1:
                    f=1
                    break
    if f==1:
        print("Yes")
    else:
        print("No")

Submission status: Accepted

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

def template_matching():
  for y in range(n-m+1):   
    for x in range(n-m+1):
      flag = True
      for yi in range(m):
        if aa[y+yi].find(bb[yi],x)-x != 0:          
          flag = False
      if flag :
        return True
  return False

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

Submission status: Accepted

Solution code:
from sys import exit

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


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

for i in range(N):
	A.append(list(map(lambda x:1 if x=='#' else 0, input())))

for i in range(M):
	B.append(list(map(lambda x:1 if x=='#' else 0, input())))


for i in range(N-M+1):
	for j in range(N-M+1):
		if func(i,j):
			print('Yes')
			exit()

print('No')

Submission status: Accepted

Solution code:
# atcoder problemsからきました
# 全探索
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):
        target = [["-" for _ in range(m)] for _ in range(m)]
        for y in range(m):
            for x in range(m):
                target[y][x] = a[i + y][j + x]
        if b == target:
            print("Yes")
            exit()
print("No")

Submission status: Accepted

Solution code:
#54b
import numpy as np

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

a_array = []
b_array = []

for i in range(N):
    a = str(input())
    a_list = [a[i] for i in range(N)]
    a_array.append(a_list)

for i in range(M):
    b = str(input())
    b_list = [b[i] for i in range(M)]
    b_array.append(b_list)

a_nparrary = np.array(a_array)
b_nparrary = np.array(b_array)
break_flag = 0

for x in range(N-M+1):
    for y in range(N-M+1):
        sliced_a_nparray = a_nparrary[x:x+M,y:y+M]
        #print(sliced_a_nparray)
        
        if (sliced_a_nparray == b_nparrary).all():
            print("Yes")
            break_flag = 1
            break
    
    if break_flag == 1:
        break
else:
    print("No")

Submission status: Accepted

Solution code:
import numpy as np
a,b = [int(i) for i in input().split()]

al = np.array([list(input()) for _ in range(a)])
bl = np.array([list(input()) for _ in range(b)])

flg  = False
for i in range(a - b + 1):
    for j in range(a - b + 1):
        if(al[i:i+b,j:j+b] == bl).all():
            flg = True
            
print('Yes' if flg else 'No')

Submission status: Accepted

Solution code:
import sys
 
stdin = sys.stdin
def na(): return map(int, stdin.readline().split())
def ns(): return stdin.readline().strip()
 
n,m = na()
ba = []
for i in range(n):
    ba.append(ns())
bb = []
for i in range(m):
    bb.append(ns())
 
for i in range(n-m+1):
    for j in range(n-m+1):
        ok = True
        for k in range(m):
            if ba[i+k][j:j+m] != bb[k]:
                ok = False
                break
        if ok:
            print("Yes")
            sys.exit(0)
print("No")

Submission status: Accepted

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

hidariue = b[0][0]
hasikouho = []
for i in range(n-m+1):
    for j in range(n-m+1):
        if a[i][j] == hidariue:
            hasikouho.append([i,j])

x = []

for v in hasikouho:
    ans = "Yes"
    i = int(v[0])
    j = int(v[1])
    for p in range(m):
        if ans == "Yes":
            for q in range(m):
                if a[i+p][j+q] != b[p][q]:
                    ans = "No"
                    break
        else:
            break
    x.append(ans)

if "Yes" in x:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
A = []
B = []
for _ in range(N):
    A.append(input())
for _ in range(M):
    B.append(input())
for i in range(N-M+1):
    for j in range(N-M+1):
        AND = True
        for k in range(M):
            judge = A[i+k][j:j+M] == B[k][0:M]
            AND &= judge
        if AND:
            print('Yes')
            exit()

print('No')

Submission status: Accepted

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

A = []
for i in range(N):
    tmp = input()
    A.append([0 if s=="." else 1 for s in tmp])
B = []
for i in range(M):
    tmp = input()
    B.append([0 if s=="." else 1 for s in tmp])
    
A = np.array(A)
B = np.array(B)

def is_match(a, b):
    return (a==b).all()
flag = False
for i in range(N):
    for j in range(N):
        x_left = i
        x_right = i + M
        y_up = j
        y_under = j + M
        if x_right > N or y_under > N:
            continue
        if is_match(B, A[x_left:x_right, y_up:y_under]):
            flag = True
if flag:
    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):
    for j in range(n):
        for k in range(m):
            for l in range(m):
                if i + k >= n or j + l >= n:
                    flag = True
                    break
                if a[i + k][j + l] != b[k][l]:
                    flag = True
                    break
            if flag:
                flag = False
                break
            if k == m - 1:
                print('Yes')
                exit()
print('No')

Submission status: Accepted

Solution code:
import numpy as np
import sys

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

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

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

Submission status: Accepted

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

class Image:
    def __init__(self, n):
        self.matrix = [list(input()) for _ in range(n)]
        self.n = n

    def isIncluded(self, a):
        for i in range(a.n-self.n+1):
            for j in range(a.n-self.n+1):
                template = [row[j:j+self.n] for row in a.matrix[i:i+self.n]]
                if template == self.matrix:
                    return True
        return False


a = Image(n)
b = Image(m)

print("Yes" if b.isIncluded(a) else "No")

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf')
ans = 0 ;count = 0 ;pro = 1

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

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
A = []
for i in range(N):
    A.append(list(input()))
B = []
for i in range(M):
    B.append(list(input()))
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'
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
A=[list(input()) for i in range(n)]
B=[list(input()) for j in range(m)]
c=0
flag2=0
for l in range(n-m+1):
    for t in range(n-m+1):
        for k in range(m):
            if A[t+k][l:l+m]==B[k]:
                c+=1
        if c==m:
            flag2=1
        c=0  
print('Yes' if flag2==1 else 'No')

Submission status: Accepted

Solution code:
import sys
import numpy as np

n, m = map(int, sys.stdin.readline().split())
A = np.array([list(sys.stdin.readline().rstrip()) for _ in range(n)], dtype='U1')
B = np.array([list(sys.stdin.readline().rstrip()) for _ in range(m)], dtype='U1')

def main():
    
    for i in range(n - m + 1):
        for j in range(n - m + 1):
            if np.all(A[i:i+m, j:j+m] == B):
                return 'Yes'
    return 'No'

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

Submission status: Accepted

Solution code:
import sys
n, m = [int(i) for i in sys.stdin.readline().split()]
a_ls = []
b_ls = []
for i in range(n):
    a_ls.append(sys.stdin.readline().strip())
for i in range(m):
    b_ls.append(sys.stdin.readline().strip())

def matching(a, b, size, start):
    start_y, start_x = start
    flg = True
    for i in range(size):
        for j in range(size):
            flg &= a[start_y + i][start_x + j] == b[i][j]
            if not flg:
                return flg
    return flg

res = False
for i in range(n - m + 1):
    for j in range(n - m + 1):
        res |= matching(a_ls, b_ls, m, (i, j))
        if res:
            break
    if res:
        break
print("Yes" if res else "No")

Submission status: Accepted

Solution code:
n,m = map(int, input().split())
a = [input() for _ in range(n)]
b = [input() for _ in range(m)]
for i in range(n-m+1):
    for j in range(n-m+1):
        window = [x[i:i+m] for x in a[j:j+m]]
        if window == b:
            print('Yes')
            quit()
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())

ans="No"
for i in range(n-m+1):
	for j in range(n-m+1):
		check=0
		for k in range(m):
			for l in range(m):
				if b[k][l]==a[i+k][j+l]:
					check+=1
					if check==m*m:
						ans="Yes"
				else:
					break
			else:
				continue
			break
print(ans)

Submission status: Accepted

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

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

print("No")

Submission status: Accepted

Solution code:
import numpy as np
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)]
ans = 'No'
na = np.array(a)
nb = np.array(b)
for i in range(n-m+1):
    for j in range(n-m+1):
        s = na[i:m+i, range(j, m+j)]
        if (s == nb).all():
            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 j in range(M)]
u = 0
for i in range(N - M + 1):
  for j in range(N - M + 1):
    s = 0
    for k in range(M):
      for l in range(M):
        if A[i+k][j+l] != B[k][l]:
          s += 1
    if s == 0:
      u = 1
if u == 1:
  print('Yes')
elif u == 0:
  print('No')

Submission status: Accepted

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

for idx1 in range(N - M + 1):
    lst_j = [x for x in lst_n[idx1 : idx1 + M]]
    for idx2 in range(N - M + 1):
        lst_k = [y[idx2 : idx2 + M] for y in lst_j]
        if lst_k == lst_m:
            print("Yes")
            exit()
print("No")

Submission status: Accepted

Solution code:
# ABC054 B - Template Matching
si = lambda: input()
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))
n,m=nl()
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):
        cnt=0
        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:
            print('Yes')
            exit()
print('No')

Submission status: Accepted

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

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

ans = False
for i in range(n - m + 1):
    for j in range(n - m + 1):
        #check
        f = True
        for x in range(m):
            for y in range(m):
                if a[x + i][y + j] != b[x][y]:
                    f = False

        if f:
            ans = True

if ans:
    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):
    S = []
    for k in range(m):
      S.append(A[i + k][j:j + m])
      if S == B:
        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)]

ans = "No"
flag = False

for i in range(n-m+1):
    for j in range(n-m+1):
        if b[0][0] == a[i][j]:
            atmp = []
            atmp.extend([a[s][j:j+m] for s in range(i,i+m)])
            if b == atmp:
                ans = "Yes"
                flag = True
        if flag:
            break
    if flag:
        break

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

def dfs(x: int, y: int, i: int, j: int) -> bool:
    if i-x == m:
        return True
    if j-y == m:
        return True

    if a[i][j] != b[i-x][j-y]:
        return False

    if not dfs(x, y, i, j+1):
        return False
    if not dfs(x, y, i+1, j):
        return False
    if not dfs(x, y, i+1, j+1):
        return False

    return True

ans = "No"
for i in range(n-m+1):
    for j in range(n-m+1):
        if a[i][j] == b[0][0]:
            x = i
            y = j
            if dfs(x, y, i, j):
                ans = "Yes"
                break

print(ans)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
nn=""
mm=[]
for i in range(n):
    nn+=input()+"\n"
for i in range(m):
    mm.append(input()+"\n")
count=0
for i in range(m):
    if(mm[i] in nn ):
        count+=1

if(count==m):
    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)]
for y in range(n-m+1):
    for x in range(n-m+1):
        f=1
        for i in range(m):
            for j in range(m):
                if a[i+x][j+y]!=b[i][j]:
                    f=0
        if f:
            print("Yes")
            exit()
print("No")

Submission status: Accepted

Solution code:
import sys
import numpy as np
N,M=map(int,input().split())
A=np.zeros((N,N))
B=np.zeros((M,M))
for i in range(N):
    temp=input()
    temp=temp.replace('.',"0")
    temp=temp.replace('#',"1")
    A[i] = list(map(int,list(temp)))
for i in range(M):
    temp=input()
    temp=temp.replace('.',"0")
    temp=temp.replace('#',"1")
    B[i] = list(map(int,list(temp)))

for i in range(N-M+1):
    for j in range(N-M+1):
        if np.all(B == A[i:i+M,j:j+M]):
            print("Yes")
            sys.exit()
else:
    print("No")

Submission status: Accepted

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

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

ans = "Yes"
for a in A:
    for b in B:
        if b not in a:
            ans = "No"
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)]
row = 0
column = 0
flg = True
while True:
    flg = True
    if N < M+column:
        break
    row = 0
    while True:
        flg = True
        if N < M+row:
            break
        for i in range(M):
            for k in range(M):
                if B[i][k] != A[i+column][k+row]:
                    flg = False
                    break
        if flg:
            print('Yes')
            exit()
        row += 1
    column += 1
print('No')

Submission status: Accepted

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

for i in range(n - m + 1):
    for j in range(n - m + 1):
        a = True
        for k in range(m):
            if lstn[i + k][j : j + m] != lstm[k]:
                a = False
                break
        if a:
            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)]
ans = 0
for i in range(N-M+1):
  for j in range(N-M+1):
    for k in range(i,i+M):
      for l in range(j,j+M):
        if A[k][l] != B[k-i][l-j]:
          break
        if A[k][l] == B[k-i][l-j] and k == i+M-1 and l == j+M-1:
          ans = 1
      else:
        continue
      break

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

Submission status: Accepted

Solution code:
from sys import stdin

n,m = [int(x) for x in stdin.readline().rstrip().split()]

li = [["" for i in range(n)]for j in range(n)]
for i in range(n):
    s = stdin.readline().rstrip()
    for j in range(n):
        li[i][j] = s[j]

lin = [["" for i in range(m)]for j in range(m)]
for i in range(m):
    s = stdin.readline().rstrip()
    for j in range(m):
        lin[i][j] = s[j]

for i in range(n-m+1):
    for j in range(n-m+1):
        point = 0
        for k in range(m):
            for l in range(m):
                if lin[k][l] == li[k+i][l+j]:
                    point += 1
                    if point == m**2:
                        print("Yes")
                        exit()
                        
print("No")

Submission status: Accepted

Solution code:
import numpy as np

N, M = map(int, input().split())
A = []
for i in range(N):
    S = input()
    A.append([S[i] for i in range(len(S))])
A = np.array(A)
B = []
for i in range(M):
    S = input()
    B.append([S[i] for i in range(len(S))])
for i_raw in range(N - M + 1):
    for j_col in range(N - M + 1):
        if (A[i_raw : i_raw + M, j_col : j_col + M] == B).all():
            print("Yes")
            exit()
print("No")

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys

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


def solve(N: int, M: int, A: "List[str]", B: "List[str]"):
    for i in range(N-M+1):
        for j in range(N-M+1):
            # AとBが等しいか判定
            for k in range(M):
                for l in range(M):
                    if A[i+k][j+l] == B[k][l]:
                        continue
                    else:
                        break
                else:
                    continue
                break    
            else:
                print(YES)
                return

    print(NO)    
    return


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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
if sys.platform == 'ios':
	sys.stdin = open('input_file.txt')
	

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

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

s = [ [0]*m for i in range(m) ]

ans = 0

for i in range(n-m+1):
	for j in range(n-m+1):
		for k in range(m):
			#print(i,j,k)
			s[k] = a[i+k][j:j+m]
		#print(s)
		
		if s == b :
			#print(i,j,s)
			ans = ans +1

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

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
import numpy as np
A=np.array([list(input()) for _ in range(N)])
B=np.array([list(input()) for _ in range(M)])
ans='No'
for i in range(N-M+1):
  for j in range(N-M+1):
    if (A[i:i+M,j:j+M]==B).all():
      ans='Yes'
      break
  else:continue
  break
    
    
print(ans)

Submission status: Accepted

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

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

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

def check(i, j):
    flag = True
    for u in range(m):
        x = area_a[i+u][j:j+m]
        if x != area_b[u][:]:
            flag = False
            break
        else:
            continue
    if flag is True:
        print('Yes')
        exit()

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

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 = 0
        for x in range(M):
            if A[x + i][j:j + M] == B[x]:
                c += 1
        if c == M:
            ans = "Yes"
            break
    else:
        continue
    break

print(ans)

Submission status: Accepted

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

ans = "No"

for i in range(N - M + 1):
    for j in range(N - M + 1):
        c = 0
        for x in range(M):
            for y in range(M):
                if A[x + i][y + j] == B[x][y]:
                    c += 1
        if c == M ** 2:
            ans = "Yes"
            break

print(ans)

Submission status: Accepted

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

ba = []
for i in range(n):
    ba.append(input())
bb = []
for i in range(m):
    bb.append(input())
    
#print(ba,bb)  
 
for i in range(n-m+1):
    for j in range(n-m+1):
        ok = True
        for k in range(m):
            #ba[]
            if ba[i+k][j:j+m] != bb[k]:
                ok = False
                break
        if ok:
            print("Yes")
            exit()
print("No")

Submission status: Accepted

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

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

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

for i in range(n - m + 1):
    for j in range(n - m + 1):
        flag = True
        for b_x in range(m):
            a_x = b_x + i
            for b_y in range(m):
                a_y = b_y + j
                if(a[a_x][a_y] != b[b_x][b_y]):
                    flag = False
        if flag == True :
            print('Yes')
            exit()
print('No')

# print(yesNo)

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

def CheckExist(ai, aj):
    for bi in range(M):
        for bj in range(M):
            if A[ai+bi][aj+bj] != B[bi][bj]:
                return False
    return True

for ai in range(N - M + 1):
    for aj in range(N - M + 1):
        if CheckExist(ai, aj):
            print('Yes')
            exit(0)
print('No')

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
gridA=[None]*N
gridB=[None]*M
for i in range(N):
  gridA[i]=input()
for i in range(M):
  gridB[i]=input()

def isMatch(y,x):
  for i in range(M):
    for j in range(M):
      if gridB[i][j]!=gridA[y+i][x+j]:
        return False
  return True

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