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:
def main():
    n, m = (int(i) for i in input().split())
    a = [input() for i in range(n)]
    b = [input() for i in range(m)]
    
    equal_flag = False
    k = 0
    for i in range(n):
        for j in range(n-m+1):
            if a[i][j:j+m] == b[k]:
                plus = 1
                while k+plus != m:
                    if i+plus >= n or a[i+plus][j:j+m] != b[k+plus]:
                        break
                    plus += 1
                else:
                    equal_flag = True
        if equal_flag:
            print("Yes")
            break
    else:
        print("No")
 
if __name__ == '__main__':
    main()

Submission status: Accepted

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

for i in range(N - M + 1):
  for j in range(N - M + 1):
    if [a[j:j+M] for a in A[i:i+M]] == B:
      ans = "Yes"
print(ans)

Submission status: Accepted

Solution code:
import re

n, m = map(int, input().split())
a = [input().strip() for _ in range(n)]
b = [input().strip() for _ in range(m)]
for idx_a, arow in enumerate(a[:n-m+1]):
  for idx_obj in re.finditer(b[0], arow):
    falg = True
    for i in range(1,m):
      if b[i] != a[idx_a+i][idx_obj.start():idx_obj.end()]:
        falg = False
    if falg is True:
      print('Yes')
      exit()
print('No')

Submission status: Accepted

Solution code:
import re

n, m = map(int, input().split())
a = [input().strip() for _ in range(n)]
b = [input().strip() for _ in range(m)]
for idx_a, arow in enumerate(a[:n-m+1]):
  for result in re.finditer(b[0], arow):
    falg = True
    for i in range(1,m):
      if b[i] != a[idx_a+i][result.start():result.end()]:
        falg = False
    if falg is True:
      print('Yes')
      exit()
print('No')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
n,m=map(int,input().split())
a=[]
b=[]
for x in range(n):
    a.append(input())
for y in range(m):
    b.append(input())
for z in range(n-m+1):
    k=0
    l=0
    for w in range(n-m+1):
        if (a[w])[z:z+m]==b[k]:
            l+=1
            k+=1
            if l==m:
                print('Yes')
                sys.exit()
else:
    print('No')

Submission status: Accepted

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

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

#貪欲にやれドアホ
for i in range(n-m):
    for j in range(n-m):
        c=0
        for k in range(m):
            if b[k] == a[i+k][j:j+m]:
                c+=1
            else:
                break
        if c==m:
            break
    if c==m:
        break
#cが定義されない時(m==nでは)エラー
if a==b:
    print("Yes")
elif n==m:
    print("No")
elif c==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 i in range(n-m+1):
    for j in range(n-m+1):
        for k in range(m):
            Flag = True
            if a[i+k][j:j+m] != b[k]:
                Flag = False
                break
        if Flag == True:
            print('Yes')
            exit()

print('No')

Submission status: Accepted

Solution code:
m,n=[int(x) for x in str(input()).split()]
s=""
for i in range(m+2):
  s+="0"
A=[s]
for i in range(m):
  A.append("0"+input()+"0")
A.append(s)


s=""
for i in range(n+2):
  s+="0"
B=[s]
for j in range(n):
  B.append("0"+input()+"0")
B.append(s)
#print(A,B)

count=0
for j in range(1,m-n+2):
  for k in range(1,m-n+2):
    ans=1
    for a in range(1,n+1):
      for b in range(1,n+1):
        #print(a,b)
        if A[j+a-1][k+b-1]!=B[a][b]:
          ans=0
    if ans==1:
      count=1
if count==1:
  print("Yes")
else:
  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)]
BB = sum(B,[])
for i in range(n-m+1):
  for k in range(n-m+1):
    AA = []
    for v in range(m):
      AA += A[i+v][k:k+m]
    if BB == AA:
      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)]
for i in range(n - m + 1):
  for j in range(n - m + 1):
    isMatch = True
    for k in range(m):
      for l in range(m):
        if a[i + k][j + l] != b[k][l]:
          isMatch = False
    if isMatch == True:
      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)]
for i in range(n-m+1):
  for j in range(n-m+1):
    for k in range(m):
      if b[k] != a[i+k][j:j+m]:
        break
      if k == m-1:
        print('Yes')
        exit()
print('No')

Submission status: Accepted

Solution code:
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)])
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):
            print('Yes')
            exit()
print('No')

Submission status: Accepted

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

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

c = []

d = 0

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

Submission status: Accepted

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

for i in range(M):
  b.append(input())
ans="No"

for i in range(N-M+1):
  for j in range(N-M+1):
    c=[a[k][j:j+M] for k in range(i,i+M)]
    #print(c)
    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)]
for i in range(n - m + 1):
    for j in range(n - m + 1):
        o = True
        for k in range(i, i + m):
            for l in range(j, j + m):
                if a[k][l] != b[k-i][l-j]:
                    o = False
        if o:
            print("Yes")
            exit()
print("No")

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
a=[list(map(int,list(input().replace('.','0').replace('#','1')))) for i in range(n)]
b=[list(map(int,list(input().replace('.','0').replace('#','1')))) for i in range(m)]
ans='No'
for i in range(n-m+1):
  for j in range(n-m+1):
    c=[a[k][j:j+m] for k in range(i,i+m)]
    if c==b:
      ans='Yes'
      break
print(ans)

Submission status: Accepted

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

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

B = []
for _ in range(M):
  B.append(input())
#print(B)

ans = False
for y in range(N-M+1):
  for x in range(N-M+1):
    matched = True
    for v in range(M):
      for u in range(M):
        if A[y+v][x+u]!=B[v][u]:
          matched = False
    if matched:
      ans = True
print('Yes' if ans else 'No')

Submission status: Accepted

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

n_grid=np.array([list(input()) for _ in range(n)])
m_grid=np.array([list(input()) for _ in range(m)])

found=False
for i in range(n-m+1):
  for j in range(n-m+1):
    if (m_grid == n_grid[i:i+m, j:j+m]).all():
      found=True
      break
if found:
  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)]
for i in range(N - M + 1):
    for j in range(N - M + 1):
        if A[j][i] == B[0][0]:
            flag = True
            for k in range(M):
                if A[j+k][i:i+M] != B[k]:
                    flag = False
            if flag:
                print("Yes")
                exit()
print("No")

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
As = []
for i in range(N):
  A = input()
  As.append(A)
Bs = []
for i in range(M):
  B = input()
  Bs.append(B)
r = False
for p in range(0, N-M+1):
  for q in range(0, N-M+1):
    ok = True
    for i in range(0, M):
      if Bs[i] != As[i+p][q:q+M]:
        ok = False
        break
    if ok:
      r = True
if r:
  print("Yes")
else:
  print("No")

Submission status: Accepted

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

A=[list(input()) for _ in range(N)]
B=[list(input()) for _ in range(M)]
offset=N-M
 
for row_offs in range(offset+1):
  for col_offs in range(offset+1):
    is_match=True
    for row in range(M):
      img_row=A[row+row_offs][col_offs:col_offs+M]
      tmp_row=B[row][:]
      if img_row != tmp_row:
        is_match=False
    if is_match:
      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)]
r=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 r 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)]
r=any([k[j:j+m] for k in a[i:i+m]]==b for i in range(n-m+1) for j in range(n-m+1))
print("Yes" if r else "No")

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
INF = float("inf")


def yes():
    print("Yes")  # type: str


def no():
    print("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):
            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:
                yes()
                return

    no()
    return


def main():

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(N-M+1):
    A_new = A[i:i+M]
    for j in range(N-M+1):
        A_new_new = list(map(lambda n:n[j:j+M], A_new))
        if A_new_new == B:
            print('Yes')
            exit()
print('No')

Submission status: Accepted

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

flg = False
if N == 1 and M == 1:
  if input() == input(): flg = True
else:
  A = [(input()) for _ in range(N)]
  B = [(input()) for _ in range(M)]


for i in range(N-M):
  if flg:
    break
  for j in range(N-M):
    if all([A[i+x][j+y] == B[x][y] for x in range(M) for y in range(M)]):
      flg = True
      break
if flg: print ("Yes")
else: print ("No")

Submission status: Accepted

Solution code:
import math
import sys
from itertools import accumulate
from functools import reduce
import queue
from fractions import gcd

def lcm(a, b):
    return a * b // gcd(a, b)

def combination_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)

sys.setrecursionlimit(10000)

mod = 1000000007

"""
# 0埋め, 小数点出力桁指定時のときの出力
a = 100
b = 0.987654321
print("{0:06d}-{1:6f}".format(a,b))
000100-0.987654

# 文字列をリストに格納
char_list = list("abcd") # ["a","b","c","d"]

# 標準入力取得
## 文字列
    = sys.stdin.readline().rstrip()
    = list(sys.stdin.readline().rstrip())
    = [list(list(sys.stdin.readline().rstrip())) for i in range(h)] #文字列を分解して二次元配列入力

## 数値
    = int(sys.stdin.readline())
    = map(int, sys.stdin.readline().split())
    = list(map(int, sys.stdin.readline().split()))
    = [list(map(int,list(sys.stdin.readline().split()))) for i in range(h)]  # 二次元配列入力　二次元マップみたいな入力のとき
"""

if __name__ == "__main__":
    n,m = map(int, sys.stdin.readline().split())
    a=[input() for _ in range(n)]
    b=[input() for _ in range(m)]
    r = 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 r else "No")

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
al=[input() for _ in range(n)]
bl=[input() for _ in range(m)]
for i in range(n-m+1):
    for j in range(n-m+1):
        for k in range(m):
            if bl[k]!=al[i+k][j:j+m]:
                break
        else:
            print('Yes')
            exit()
else:
    print('No')

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush, heapify
import math
import itertools
import random
 
# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev
 
INF = float('inf')
def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    N,M = inputMap()
    A = []
    for i in range(N):
        tmp = input()
        A.append(tmp)
        
    B = []
    for i in range(M):
        tmp = input()
        B.append(tmp)
        
    if N < M:
        print("No")
        sys.exit()
        
    if N == M:
        tmp1 = "".join(A)
        tmp2 = "".join(B)
        
        if tmp1 == tmp2:
            print("Yes")
        else:
            print("No")
        sys,exit()
        
    points = []
    AA = copy.deepcopy(A)
    for i,val in enumerate(AA):
        while True:
            tmp = run(val, B[0])
            if tmp != -1 and N-i >= M:
                points.append((i,tmp))
                valval = list(copy.deepcopy(val))
                valval[tmp] = "T"
                val = "".join(valval)
            else:
                break
            
    for i in points:
        lines, point = i
        flg = True
        for j,val in enumerate(B):
            tmp = A[lines+j][point:].find(val)
            if tmp == -1 or tmp != 0:
                flg = False
        
        if flg == True:
            print("Yes")
            sys.exit()
            
    print("No")
    
def run(ss, dd):
    return ss.find(dd)
    
if __name__ == "__main__":
	main()

Submission status: Accepted

Solution code:
import numpy as np

n,m=map(int,input().split())
a=np.zeros([n,n])
b=np.zeros([m,m])
map_ = {".":1,"#":-1}

for i in range(n):
  temp = list(input())
  temp = [map_[c] for c in temp]
  a[i,:] = np.array(temp)
  
for i in range(m):
  temp = list(input())
  temp = [map_[c] for c in temp]
  b[i,:] = np.array(temp)

flag=False
for i in range(n-m+1):
  for j in range(n-m+1):
    temp_a = a[i:i+m,j:j+m]
    check=np.sum(temp_a*b,axis=1)
    check=np.sum(check,axis=0)
    if check==m*m:
      flag=True
      break
    else:
      pass
if flag:
  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())

diff = n - m
if diff == 0:
    if a == b:
        print('Yes')
    else:
        print('No')
else:
    for i in range(diff + 1):
        for j in range(diff + 1):
            ans = True
            for k in range(m):
                for l in range(m):
                    if b[k][l] != a[i + k][j + l]:
                        ans = False
            if ans:
                print('Yes')
                exit()
    print('No')

Submission status: Accepted

Solution code:
n, m = map(int,input().split())
a = [input() for _ in range(n)]
b = [input() for _ in range(m)]
r = 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 r 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):
        count=0
        for k in range(M):
            for l in range(M):
                if a[i+k][j+l]!=b[k][l]:
                    break
                else:
                    count+=1
        if count==M*M:
            print("Yes")
            exit()
print("No")

Submission status: Accepted

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

def main():

    for i in range(n-m+1):
        for j in range(n-m+1):
            if match(i, j):
                print("Yes")
                exit()
    
    print("No")

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

    return True

if __name__ == "__main__":
    main()

Submission status: Accepted

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

flag = False
for i in range(n-m+1):
    for k in range(n-m+1):
        part = []
        for j in range(m):
            part.append(a[k+j][i:i+m])
        if b == part:
            flag = True

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

Submission status: Accepted

Solution code:
#ABC054b
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

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


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


for i in range(n - m + 1):
    for j in range(n - m + 1):
        if (a[i][j] == b[0][0] and match(i, j)):
            print("Yes")
            exit(0)
print("No")

Submission status: Accepted

Solution code:
import sys
# (x,y) 探索開始座標を与えると、それで画像が一致していればTrue,そうでなければ　Falseを返す関数hantei
def hantei(x,y,m):
    for h in range(m):
        if A[h+y][x:x+m]!=B[h]:
            return False
    else:
        return True
            
n,m =map(int,input().split())
A=[]
B=[]
for i in range(n):
    A.append(input())
for j in range(m):
    B.append(input())  

for y in range(n-m+1):
    for x in range(n-m+1):
        if hantei(x,y,m):
            print("Yes")
            sys.exit()
        else: continue
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 sy in range(n):
    for sx in range(n):
        # start point
        if sy + m - 1 >= n or sx + m - 1 >= n:
            break

        ok = True
        for y in range(m):
            for x in range(m):
                if a[sy + y][sx + x] != b[y][x]:
                    ok = False
        if ok:
            print('Yes')
            exit()
print('No')

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
N = []
for _ in range(n):
  N.append(input())
M = []
for _ in range(m):
  M.append(input())
for i in range(n-m+1):
  for j in range(n-m+1):
    for k in range(m):
      if M[k] != N[i+k][j:j+m]:
        break
    else:
      print('Yes')
      break
  else:
    continue
  break
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'
def match(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
for i in range(N-M+1):
  for j in range(N-M+1):
    if match(i, j):
      ans = 'Yes'
      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)]
for i in range(n - m + 1):
    for j in range(n - m + 1):
        bb = True
        for k in range(i, i + m):
            for l in range(j, j + m):
                if a[k][l] != b[k-i][l-j]:
                    bb = False
        if bb:
            print("Yes")
            exit()
print("No")

Submission status: Accepted

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

r=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 r else 'No')

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
a=[]
b=[]
for i in range(n):
    a.append(list(str(input())))
for i in range(m):
    b.append(list(str(input())))
f2=True
for y in range(n-m+1):
    for x in range(n-m+1):
        f=True
        for dy in range(m):
            for dx in range(m):
                if b[dy][dx]!=a[y+dy][x+dx]:
                    f=False
        if f:
             f2=False
print("YNeos"[f2::2])

Submission status: Accepted

Solution code:
n,m = map(int, input().rstrip().split())
x = list()
y = list()

for i in range(n):
    x.append(input().rstrip())
for i in range(m):
    y.append(input().rstrip())

for i in range(n-m+1):
    for j in range(n-m+1):
        z = True
        for k in range(m):
            for l in range(m):
                if x[i+k][j+l] != y[k][l]:
                    z = False
                    break
            if not z: break
        if z:
            print("Yes")
            exit()
print("No")

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
a = [input() for i in range(n)]
b = [input() for i in range(m)]
for i in range(n-m+1):
  for j in range(n-m+1):
    count = 0
    for x in range(m):
      for y in range(m):
        if b[x][y]!=a[i+x][j+y]:
          break
        else:
          count += 1
    if count == m**2:
      print('Yes')
      exit()
print('No')

Submission status: Accepted

Solution code:
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:
N, M = [int(x) for x in input().split()]

A = [None]*N
for i in range(N):
    A[i] = input()

B = [None]*M
for i in range(M):
    B[i] = input()

def check():
    for x in range(N-M+1):
        for y in range(N-M+1):
            match = True
            for r in range(M):
                if not all(A[r+x][c+y] == B[r][c] for c in range(M)):
                    match = False
                    break
            if match:
                return "Yes"

    return "No"
print(check())

Submission status: Accepted

Solution code:
import itertools
N,M = map(int, input().strip().split(' '))
A = [input().strip() for _ in range(N)]
B = [input().strip() for _ in range(M)]
for i,j in itertools.product(range(N-M+1), repeat=2):
  if sum(A[y+i][j:j+M] == B[y] for y in range(M)) == M:
    print('Yes')
    exit()
print('No')

Submission status: Accepted

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


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

    for i in range(n - m + 1):
        for j in range(n - m + 1):
            count = 0

            for k in range(i, i + m):
                for l in range(j, j + m):
                    if a[k][l] == b[k - i][l - j]:
                        count += 1

            if count == m ** 2:
                print('Yes')
                exit()

    print('No')


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
N, M = map(int, input().split())
aLst = list(input() for i in range(N))
bLst = list(input() for i in range(M))
ans = False
cnt = 0
for j in range(N - M + 1):
    for k in range(N - M + 1):
        if aLst[j][k:k + M] == bLst[0]:
            cnt += 1
            for l in range(1, M):
                if aLst[j + l][k:k + M] == bLst[l]:
                    cnt += 1
                else:
                    break

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

print('No')

Submission status: Accepted

Solution code:
a=[]
b=[]
n,m=map(int,input().split())
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 x in range(m):
			for y in range(m):
				if b[x][y]!=a[i+x][j+y]:
					break
				else:
					cnt+=1
		if cnt==m**2:
			print("Yes")
			exit()
print("No")

Submission status: Accepted

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

def is_match(i, j):
  # x, y is each pixel in A
  for xb in range(M):
    for yb in range(M):
      xa = xb+i
      ya = yb+j
      #print("xb: {}, yb:{}, xa:{}, ya:{}".format(str(xb), str(yb), str(xa), str(ya)))
      if B[xb][yb] != A[xa][ya]:
        return False
  return True

# i, j is top left index
for i in range(N-M+1):
  for j in range(N-M+1):
    #print("i: {}, j:{}".format(str(i), str(j)))
    if is_match(i, j):
      print("Yes")
      exit()
print("No")

Submission status: Accepted

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

for i in range(N):
  if i + M > N:
    break
  for j in range(N):
    if j + M > N:
      break
    same = True
    for k in range(i, i+M):
      for l in range(j, j+M):
        if photo_a[k][l] != photo_b[k-i][l-j]:
          same = False
          break
      else:
        continue
      break
    if same:
      print('Yes')
      exit()
print('No')

Submission status: Accepted

Solution code:
# ABC 54, B - template matching
n, m = [int(el) for el in input().split(' ')]
A = [list(input()) for i in range(n)]
B = [list(input()) for i in range(m)]

def compute():

    for i in range(n-m+1):
        for j in range(n-m+1):
            sub_A = [a[j:j+m] for a in A[i:i+m]]
            if sub_A == B:
                return('Yes')
    else:
        return('No')

print(compute())

Submission status: Accepted

Solution code:
def main():
    N, M = map(int, input().split())
    A = [input() for _ in range(N)]
    B = [input() for _ in range(M)]
    for i in range(N):
        for j in range(N):
            f = True
            for k in range(M):
                for l in range(M):
                    if i + k >= N or j + l >= N:
                        f = False
                        break
                    if A[i + k][j + l] != B[k][l]:
                        f = False
                        break
                if f is False:
                    break
            if f is True:
                print('Yes')
                exit()
    print('No')


main()

Submission status: Accepted

Solution code:
n,m = list(map(int,input().split()))
import numpy as np
A = np.zeros([n,n]).astype(np.int)
B = np.zeros([m,m]).astype(np.int)
for i in range(n):
    A[i,:] = [1 if s == '#' else 0 for s in input()]
for i in range(m):
    B[i,:] = [1 if s == '#' else 0 for s in input()]
# print(A)
# print("---")
# print(B)
# print("---")

ans = 0
for i in range(0,n-m+1):
    for j in range(0,n-m+1):
        if (A[i:i+m,j:j+m] == B).all():
            ans = 1
            break

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