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=[]
for _ in range(n):
    t1 = input()
    t1 = list(t1)
    a.append(t1)

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

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

Submission status: Accepted

Solution code:
from sys import stdin
input = stdin.readline

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


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


print("No")

Submission status: Accepted

Solution code:
#import itertools
#import fractions
#import numpy as np
#mod = 10**4 + 7
"""def kiri(n,m):
  r_ = n / m
  if (r_ - (n // m)) > 0:
    return (n//m) + 1
  else:
    return (n//m)"""

# Written by NoKnowledgeGG @YlePhan

#import math
#mod = 10**9+7



def main():
  n,m = map(int,input().split())
  A = [input() for _ in range(n)]
  B = [input() for _ in range(m)]
  
  def fa(i,j):
    for a in range(m):
      for b in range(m):
        if A[i+a][j+b] != B[a][b]:
          return False
        else:
          continue
    return True
  
  for i in range(n - m +1):
    for j in range(n-m+1):
      if fa(i,j):
        print("Yes")
        exit()
  print('No')
  
  
if __name__ == '__main__':
  main()

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

def solve(i, j):
    for a in range(M):
        for b in range(M):
            if A[i+a][j+b] != B[a][b]:
                return False
            else:
                continue
    return True

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

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
a = [list(input()) for i in range(n)]
b = [list(input()) for i in range(m)]
ans = 'No'
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: 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)]
if A == B:
  print("Yes")
  exit()
for i in range(N-M):
  for j in range(N-M):
    x = []
    for k in range(M):
      for l in range(M):
        x.append(A[i+k][j+l])
    if ''.join(x) == ''.join(B):
      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())
#print(A)
#print(B)

success=0
for right in range(N-M+1):
    for down in range(N-M+1):
        count=0
        for x in range(M):
            for y in range(M):
                if A[down+y][right+x]==B[y][x]:
                    count+=1
        if count==M*M:
            success=1

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

Submission status: Accepted

Solution code:
import sys

N, M = map(int,input().split())
An = [list(input()) for _ in range(N)]
Bn = [list(input()) for _ in range(M)]
for i in range(N - M + 1):
    for j in range(N - M + 1):
        flag = True
        for ii in range(M):
            for jj in range(M):
                if An[j+jj][i+ii] != Bn[ii][jj]: flag = False
        if flag is True:
            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)]
 
for i in range(n-m+1):
    for j in range(n-m+1):
        a1 = [a[k][j:j+m] for k in range(i,i+m)]
        if a1 == b:
            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(list(input()))

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


def ext(x, y):
    global a
    res = [[0 for _ in range(m)] for __ in range(m)]

    for i in range(m):
        for j in range(m):
            res[i][j] = a[i+x][j+y]

    return res


ans = "No"
for i in range(0, n - m + 1):
    for j in range(0, n - m + 1):
        if (ext(i, j) == b):
            ans = "Yes"

print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
# B - Template Matching
# モジュールのインポート
import itertools

# 標準入力の取得
N,M = list(map(int, input().split()))
A_LIST = [list(input()) for n in range(N)]
B_LIST = [list(input()) for m in range(M)]

# 左上を基準に全探索を行う
result = False
for n1,n2 in itertools.product(range(N-M+1), range(N-M+1)):
    is_included = True
    for m1,m2 in itertools.product(range(M), range(M)):
        char_A = A_LIST[n1+m1][n2+m2]
        char_B = B_LIST[m1][m2]
        if char_A != char_B:
            is_included = False

    if is_included:
        result = True
        break

# 結果出力
if result:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

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

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

existed = False
for i in range(N - M + 1):
  for j in range(N - M + 1):
    match = True
    for mi in range(M):
      for mj in range(M):
        x = i + mi
        y = j + mj

        if (A[y][x] != B[mj][mi]):
          match = False
          break
      
      if (match == False):
        break

    if (match):
      existed = True
      break
  
  if (existed):
    break

result = 'Yes' if (existed) else 'No'
print(result)

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

is_ok = False
for dx in range(n-m+1):
    for dy in range(n-m+1):
        f = True
        for y in range(m):
            for x in range(m):
                if a[y+dy][x+dx] != b[y][x]:
                    f = False
        if f:
            is_ok = True

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

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
a_list = []
for i in range(n):
	a_list.append(input())
b_list = []
for i in range(m):
	b_list.append(input())
b = ''.join(b_list)
r = 'No'
end = n - m if n - m > 0 else 1
for i in range(end):
	a =	''.join(list(map(lambda a: a[:m], a_list)))
	if b in a:
		r = 'Yes'
		break
print(r)

Submission status: Accepted

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

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

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

start_list = []
for i, a in enumerate(A):
  if (len(A) - i < M):
    break

  s_i = a.find(B[0])
  if (s_i == -1):
    continue
  else:
    start_list.append([i, s_i])

existed = False
for sl in start_list:
  checkA = A[sl[0]:sl[0] + M]

  has_b = True
  for i, ca in enumerate(checkA):
    if (ca[sl[1]:sl[1]+M] != B[i]):
      has_b = False
      break
  
  if (has_b == False):
    continue
  else:
    existed = True
    break

result = 'Yes' if (existed == True) else 'No'
print(result)

Submission status: Accepted

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

A = [input().strip() for _ in range(N)]
B = [input().strip() for _ in range(M)]
temp = "".join(B)


ans = False

for j in range(N-M+1):
    for i in range(N-M+1):
        tmp = ""
        for y in range(M):
            tmp += A[j+y][i: i + M]
        if tmp == temp:
            ans = True

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

Submission status: Accepted

Solution code:
#template
def inputlist(): return [int(j) for j in input().split()]
#template
#issueから始める
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):
        a1 = [a[k][j:j+m] for k in range(i,i+m)]
        if a1 == 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)]

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

print('No')

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()
#print(A)
#print(B)
  
ans="No"
flag=True

for i in range(N-M+1):    #始点左上
  for j in range(N-M+1):  #始点左上
    flag=True
    for k in range(i,i+M):   #スキャン
      if flag:
        for l in range(j,j+M): #スキャン
          if A[k][l] != B[k-i][l-j]:
            flag=False
            break
    else:
      if flag==True:
        ans="Yes"
        break
print(ans)

Submission status: Accepted

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

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

for i in range(M):
    print(B[i])
'''
for i in range(N):
    for j in range(len(A[i])):
        flg=True
        for x in range(M):
            for y in range(len(B[x])):
                if i+x==N or j+y==len(A[i]):
                    flg=False
                    break
                if A[i+x][j+y]!=B[x][y]:
                    flg=False
                    break
            if flg==False:
                break
        if flg==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)]
#print(a,b)
ans=0
cnt=0
for i in range(n-m+1):
  for j in range(n-m+1):
    cnt=0
    for k in range(m):
      if b[k]!=a[i+k][j:j+m]:
        break
      cnt+=1
      #print(a[i+k][j:j+m],b[k],a[i+k][j:j+m]==b[k])
    if cnt==m:
      ans+=1
    if ans>0:
      break
  if ans>0:
    break
  
print("Yes" if ans>0 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)]

diff = N-M

if diff==0:
    flag = True
    for i in range(M):
        for j in range(M):
            if B[i][j] != A[i][j]:
                flag = False
                break

        if flag==False:
            break
        
    if flag:
        print('Yes')
        exit()

else:
    for di in range(diff):
        for dj in range(diff):
            flag = True
            for i in range(M):
                for j in range(M):
                    if B[i][j] != A[i+di][j+dj]:
                        flag = False
                        break

                if flag==False:
                    break
                
            if flag:
                print('Yes')
                exit()

print('No')

Submission status: Accepted

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

for i in a:
    for j in b:
        if j not in i:
            print("No")
            quit()
print("Yes")

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
list_A = list(input() for i in range(n))
list_B = list(input() for i in range(m))
k = "No"
for i in range(n-m+1):
  for t in range(n-m+1):
      if all(list_A[v+i][t:t+m]==list_B[v] for v in range(m)):
        k = "Yes"
        break
print(k)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
A = [input() for _ in range(n)]
B = [input() for _ in range(m)]
for idx_row in range(n - m + 1):
    for idx_col in range(n - m + 1):
        is_ans = True
        for B_row_offset in range(m):
            if A[idx_row + B_row_offset][idx_col:idx_col + m] != B[B_row_offset]:
                is_ans = False
        if is_ans:
            print('Yes')
            exit()
print('No')

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
A = list()
B = list()
for i in range(N):
  A.append(input())
for i in range(M):
  B.append(input())
def check(posx, posy):
  for y in range(M):
    for x in range(M):
      if not B[y][x] == A[y + posy][x + posx]:
        return False
  return True
for y in range(N - M + 1):
  for x in range(N - M + 1):
    if check(x,y):
      print("Yes")
      exit()
print("No")

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
a = [[i for i in input()] for _ in range(n)]
b = [[i for i in input()] for _ in range(m)]
com = True
for h in range(n-m+1):
    for w in range(n-m+1):
        for hi in range(m):
            for wi in range(m):
                if a[h+hi][w+wi] != b[hi][wi]:
                    com = False
        if com:
            print("Yes")
            exit()
        else:
            com = True
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 g in range(n-m+1):
        d=[]
        for l in range(m):
            d.append(a[l+i][g:g+m])
        if d==b:
            print("Yes")
            exit()
print("No")

Submission status: Accepted

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

def init_img(n):
    return [[0 if j == "#" else 1 for j in input()] for i in range(n)]

img = init_img(n)

tmp_img = init_img(m)

flg = False

for i in range(n):
    if flg:
        break

    if i+m > n:
        break

    for j in range(n):
        count = 0
        if j+m > n:
            break
        
        for k in range(m):
            if img[i+k][j:j+m] == tmp_img[k]:
                count += 1

        if count == m:
            flg = True

if flg:
    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)]
#print(a)
#print(b)
ans='No'
for i in range(n-m+1):
    for j in range(n-m+1):
 #       print(i,j,end=' checking \n')
        #check if b is a matching from (i,j) as it's top left
        flag=True
        for ii in range(i,i+m):
            for jj in range(j,j+m):
  #              print(ii,jj,end=' ii, jj \n')
   #             print(ii-i,jj-j,end=' ii-i,jj-j\n')
                if a[ii][jj]!=b[ii-i][jj-j]:
                    flag=False
                    break
            if flag==False:
                break
        if flag==True:
            ans='Yes'
            print(ans)
            import sys
            sys.exit()
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np

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

As = np.array([["." for n in range(N)] for nn in range(N)])
for n in range(N):
  As[n,:] = np.array(list(input()))
  
Bs = np.array([["." for n in range(M)] for nn in range(M)])
for m in range(M):
  Bs[m,:] = np.array(list(input()))
  
ok = False
for i in range(N-M+1):
  for j in range(N-M+1):
    if (As[i:i+M,j:j+M] == Bs).all():
      ok = True
      break
if ok:
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
S =list(map(int,input().split()))
N=S[0]
M=S[1]

la=[]
for i in range(N):
    la.append(input())
lb=[]
for i in range(M):
    lb.append(input())

c=0
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 la[i+k][j+l]!=lb[k][l]:
                    flag =False
        if flag==True:
            c+=1

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

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
l=[input() for i in range(n)]
ml=[input() for i in range(m)]
for i in range(n-m+1):
  for j in range(n-m+1):
    for h in range(m):
      if ml[h]!=l[i+h][j:j+m]:break
    else:print("Yes");exit()
print("No")

Submission status: Accepted

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

gridA = [[v for v in input()] for _ in range(N)]
gridB = [[v for v in input()] for _ in range(M)]

for x_A in range(N):
    for y_A in range(N):
        ok = True
        for x_B in range(M):
            for y_B in range(M):
                if x_A+x_B >= N or y_A+y_B >= N:
                    break
                if gridA[x_A+x_B][y_A+y_B] == gridB[x_B][y_B]:
                    continue
                else:
                    ok = False
                    break
            else:
                continue
            break
        else:
            print("Yes")
            exit()
print("No")

Submission status: Accepted

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


ans = False
for i in range(n-m+1):
    for j in range(n-m+1):
        tmp = True
        for y in range(m):
            for z in range(m):
                tmp &= a[i+y][j+z] == b[y][z]
        if tmp:
            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 = False
for u in range(n-m+1):
    for l in range(n-m+1):
        #check
        ok = True
        for i in range(m):
            for j in range(m):
                ok &= a[u+i][l+j] == b[i][j]
        if ok:
            ans = True
if ans:
    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())

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

print("No")

Submission status: Accepted

Solution code:

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

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

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

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

        f = True
        for k in range(m):
            for l in range(m):
                if la[i+k][j+l] !=lb[k][l]:
                    f = False
        if f:
            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)]
d = n - m + 1
flag1 = True
flag2 = False

for k in range(d):
    for i in range(d):
        for j in range(m):
            for l in range(m):
                flag1 = True
                if A[k + j][i + l] != B[j][l]:
                    flag1 = False
                    break

            if flag1 == False:
                break

            if j == m - 1 and flag1 == True:
                flag2 = True

        if flag2 == True:
            break

    if flag2 == True:
        break

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

Submission status: Accepted

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

ans=0
flag=0

for i in range(N-M+1):
    for j in range(N-M+1):
        if A[i][j]==B[0][0]:
            for k in range(0,M):
                for l in range(0,M):
                    if A[i+k][j+l]==B[k][l]:
                        ans+=1
                        if ans==M**2:
                            flag=1
                    else:
                        ans=0
                        break
    
print("Yes" if flag else "No")

Submission status: Accepted

Solution code:
import sys

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

a_list = [[l for l in input()] for _ in range(n)]
b_list = [[l for l in input()] for _ in range(m)]

if n == m:
    if a_list == b_list:
        print('Yes')
        sys.exit()

for i in range(n-m):
    for j in range(n-m):
        a_list_sub = a_list.copy()
        a_list_sub = a_list[i:i+m]
        a_list2 = [row[j:j+m] for row in a_list_sub]
        if a_list2 == b_list:
            print('Yes')
            sys.exit()

print('No')

Submission status: Accepted

Solution code:
from __future__ import print_function

import sys

import re
import array
import copy
import functools
import operator

import math
import string
import fractions
from fractions import Fraction
from fractions import gcd
# fractions.gcd() を用いること
# math.log2()はatcoderでは対応していない．留意せよ．

import collections
import itertools
import bisect

import random
import time

import heapq
from heapq import heappush
from heapq import heappop
from heapq import heappushpop
from heapq import heapify
from heapq import heapreplace
from queue import PriorityQueue as pq
from queue import Queue

from itertools import accumulate

from collections import deque
from collections import Counter

from operator import mul
from functools import reduce

input = sys.stdin.readline


def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)
    return


def lcm(n, m):
    return int(n * m / gcd(n, m))


def coprimize(p, q):
    common = fractions.gcd(p, q)
    return (p // common, q // common)


def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom


def main():
    n, m = map(int, input().strip().split())
    g1 = []
    g2 = []
    for i in range(n):
        g1.append(input().strip())
    for i in range(m):
        g2.append(input().strip())

    for row in range(n-m+1):
        for col in range(n-m+1):
            if g1[row][col] == g2[0][0] and [g1[row+i][col+j] == g2[i][j] for i in range(m) for j in range(m)] == [True for _ in range(m**2)]:
                print("Yes")
                return
            else:
                pass    # 
    print("No")


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
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(m):
            for l in range(m):
                if b[k][l] == a[i+k][j+l]:
                    count += 1
        if count == m * m:
            print("Yes")
            exit()
print("No")

Submission status: Accepted

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7

n, m = MAP()
a = [STR() for _ in range(n)]
b = [STR() for _ in range(m)]
for i in range(n - m + 1):
    for j in range(n - m + 1):
        flag = True
        for k in range(m):
            if a[i + k][j:j + m] != b[k]:
                flag = False
                break
        if flag:
            print('Yes')
            exit()
print('No')

Submission status: Accepted

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7

n, m = MAP()
a = [STR() for _ in range(n)]
b = [STR() for _ in range(m)]
for i in range(n - m + 1):
    for j in range(n - m + 1):
        flag = True
        for k in range(m):
            for l in range(m):
                if a[i + k][j + l] != b[k][l]:
                    flag = False
                    break
            if not flag:
                break
        if flag:
            print('Yes')
            exit()
print('No')

Submission status: Accepted

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

A = [list(input()) for i in range(n)]
B = [list(input()) for i in range(m)]
ans = 0
for i in range(n-m+1):
    for j in range(n-m+1):
        temp=0
        for k in range(m):
            for l in range(m):
                if B[k][l]==A[i+k][j+l]:
                    temp+=1
                    ans = max(ans,temp)
                                    
print('Yes' if ans==m*m else 'No')

Submission status: Accepted

Solution code:
#abc054 b
n,m=map(int,input().split())
a=[]
b=[]
for i in range(n):
    a.append(list(input()))
for i in range(m):
    b.append(list(input()))
aaa=True
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
                    continue
        if flag:
            aaa=False
            break
if aaa:
    print("No")
else:
    print("Yes")

Submission status: Accepted

Solution code:
import sys

def pmatch(A, B, X, Y):
    for y, Bx in enumerate(B):
        for x, b in enumerate(Bx):
            if A[Y+y][X+x] != b:
                return False
    return True

def main():
    raw = sys.stdin.readlines()
    N, M = map(int, raw[0].split())
    A = [i.rstrip() for i in raw[1:N+1]]
    B = [i.rstrip() for i in raw[N+1:]]

    rg = range(N-M+1)

    for Y in rg:
        for X in rg:
            if pmatch(A, B, X, Y):
                return True

    return False

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

Submission status: Accepted

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

a = []
b = []
sa = n-m
ans = 0

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

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

for i in range(sa+1):
    for j in range(sa+1):
        for p in range(m):
            if a[i+p][j:j+m] != b[p]:
                break
            if p == m-1:
                ans = 1
        if ans == 1:
            break
    if ans == 1:
        break
if ans == 1:
    print('Yes')
else :
    print('No')

Submission status: Accepted

Solution code:
import sys
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 b[i][j] == a[i+y][j+x]:
                    pass
                else:
                    f = 0
                    break
            if f == 0:
                break
        if f == 1:
            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)]

nm=N-M+1
for i in range(nm):
    for j in range(nm):
        flag=[0]*M
        for k in range(M):
            a=A[i+k][j:j+M]
            b=B[k]
            if a==b: flag[k]=1
            else: flag[k]=0
        if sum(flag)==M:
            print('Yes')
            exit()
print('No')