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:
import sys

readline = sys.stdin.readline

def main():
    N, M = map(int, readline().split())
    n = []
    for _ in range(N):
        n.append(list(readline()[:-1]))
    m = []
    for _ in range(M):
        m.append(list(readline()[:-1]))

    s = N - M
    if s == 0:
        if n == m:
            flag = True
        else:
            flag = False

    for i in range(s):
        for j in range(s):
            flag = True
            for k in range(M):
                if n[i+k][j:j+M] != m[k]:
                    flag = False
                    break
            if flag:
                break
        if flag:
            break
    if flag:
        print('Yes')
    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)]
flag=0
for i in range(n-m+1):
    for j in range(n-m+1):
        flag=0
        for k1 in range(m):
            for k2 in range(m):
                if A[i+k1][j+k2]!=B[k1][k2]:
                    flag=1
                    break
            else:
                continue
            if flag==1:
                break
        else:
            print('Yes')
            exit()
else:
    print('No')

Submission status: Accepted

Solution code:
import numpy as np


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

    As_arr = np.array(As)
    Bs_arr = np.array(Bs)
    for i in range(n-m+1):
        for j in range(n-m+1):
            xs, xe = i, i+m
            ys, ye = j, j+m
            if np.all(As_arr[ys:ye, xs:xe] == Bs_arr):
                print('Yes')
                exit()
    print('No')


if __name__ == "__main__":
    main()

Submission status: Accepted

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

amat=[]
for _ in range(N):
  amat.append([x=="." for x in input()])
bmat=[]
for _ in range(M):
  bmat.append([x=="." for x in input()])
#print(amat)
#print(bmat)

for i in range(N-M+1):
  for j in range(N-M+1):
    isTemplate=True
    for k1 in range(M):
      for k2 in range(M):
        if amat[k1+i][k2+j]!=bmat[k1][k2]:
          isTemplate=False
          break
      if not isTemplate:
        break
    else:
      print("Yes")
      sys.exit(0)
else:
  print("No")

Submission status: Accepted

Solution code:
import numpy as np
n, m = map(int, input().split())
a = []
for _ in range(n):
    a.append(list(input()))
a = np.array(a)
b = []
for _ in range(m):
    b.append(list(input()))
b = np.array(b)
for dy in range(n-m+1):
    for dx in range(n-m+1):
        if (a[dy:m+dy, dx:m+dx]==b).all():
            print('Yes')
            break
    else:
        continue
    break
else:
    print('No')

Submission status: Accepted

Solution code:
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]

from collections import defaultdict, deque, Counter
from sys import exit
import heapq
import math
import copy
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)

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

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

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

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Thu May 14 17:06:47 2020

@author: shinba
"""
import sys

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

for i in range(n-m+1):
    for j in range(n-m+1):
        for k in range(m):
            if A[j+k][i:i+m] == B[k]:
                continue
            else:
                break
        else:
            print("Yes")
            sys.exit()
else:
    print("No")

Submission status: Accepted

Solution code:
if __name__ == '__main__':
  n, m = map(int, input().split())
  a_lst = []
  for i in range(n):
    a_lst.append(input())
  b_lst = []
  for i in range(m):
    b_lst.append(input())
  for j in range(n-m+1):
    for k in range(n-m+1):
      flag = 0
      for l in range(m):
        if a_lst[k+l][j:j+m] != b_lst[l]:
          flag = 1
          break
      if flag == 0:
        break
    if flag == 0:
      break
  if flag == 0:
    print("Yes")
  else:
    print("No")

Submission status: Accepted

Solution code:
from itertools import product

N, M = map(int, input().split(' '))
image = [tuple(input()) for _ in range(N)]
template = [tuple(input()) for _ in range(M)]


def is_matched(template, image, offset_y, offset_x):
    for y, x in product(range(M), range(M)):
        if template[y][x] != image[offset_y + y][offset_x + x]:
            return False
    return True


for y, x in product(range(N - M + 1), range(N - M + 1)):
    if is_matched(template, image, y, x):
        print('Yes')
        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'

for i in range(N-M+1):
    for j in range(N-M+1):
        cnt=0
        if A[i][j:j+M] ==B[0]:
            for k in range(1,M):
                if A[i+k][j:j+M] == B[k]:
                    cnt+=1
            if cnt==M-1:
                ans='Yes'
                
print(ans)

Submission status: Accepted

Solution code:
N, M = [int(i) for i in input().split()]
AA = []
for _ in range(N):
    AA.append(input())
BB = []
for _ in range(M):
    BB.append(input())

for i in range(N - M + 1):
    for j in range(N - M + 1):
        for k in range(M):
            for l in range(M):
                if AA[i + k][j + l] != BB[k][l]:
                    break
            else:
                continue
            break
        else:
            print("Yes")
            exit()

print("No")

Submission status: Accepted

Solution code:
import numpy as np
N, M = map(int, input().split())
A = np.array([int(input().replace("#", "1").replace(".", "0"), base=2) for _ in range(N)], dtype=np.int64)
B = "".join(str(int(input().replace("#", "1").replace(".", "0"), base=2)) for _ in range(M))
mask = (1 << M) - 1
for _ in range(N - M + 1):
    if B in "".join(str(a) for a in A & mask):
        print("Yes")
        break
    A >>= 1
else:
    print("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())
move = n - m + 1
ans = "No"
for i in range(move):
  for j in range(move):
    check = True
    for k  in range(m):
      for l in range(m):
        if a_list[i + k][j + l] != b_list[k][l] :
          check = False
    if check == True:
      ans = "Yes"
print(ans)

Submission status: Accepted

Solution code:
import sys
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):
        flg = False
        for k in range(m):
            if flg:
                break
            for l in range(m):
                if b[k][l] != a[i + k][j + l]:
                    flg = True
                    break
        
        if flg:
            pass
        else:
            print('Yes')
            sys.exit()

print('No')

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n, m = map(int, readline().split())
a = [readline().rstrip().decode() for _ in range(n)]
b = [readline().rstrip().decode() for _ in range(m)]
print('Yes' if any([aa[x:x + m] for aa in a[y:y + m]] == b for y in range(n - m + 1) for x in range(n - m + 1)) else 'No')

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n, m = map(int, readline().split())
a = [readline().rstrip().decode() for _ in range(n)]
b = [readline().rstrip().decode() for _ in range(m)]
for y in range(n - m + 1):
    for x in range(n - m + 1):
        if [aa[x:x + m] for aa in a[y:y + m]] == b:
            print('Yes')
            exit()
print('No')

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n, m = map(int, readline().split())
a = [readline().rstrip().decode() for _ in range(n)]
b = [readline().rstrip().decode() for _ in range(m)]
for y in range(n - m + 1):
    for x in range(n - m + 1):
        flag = True
        for i in range(m):
            for j in range(m):
                if a[i + y][j + x] != b[i][j]:
                    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=['']*N
for i in range(N):
    A[i]=input()
B=['']*M
for i in range(M):
    B[i]=input()

ans='No'
i=0
while i+M<=N:
    j=0
    while j+M<=N:
        k=0
        count=0
        while k<M:
            if A[j+k][i:i+M]==B[k]:
                count+=1
            else:
                break
            if count==M:
                ans='Yes'
            k+=1
        j+=1
    i+=1

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

flag=0
for i in range(N-M+1):
  for j in range(N-M+1):
    for k in range(M):
      if A[i+k][j:j+M]!=B[k]:
        break
      #print(i,j,k,' ',A[i+k][j:j+M],' ',B[k])
    else:
      flag=1
print('Yes' if flag==1 else 'No')

Submission status: Accepted

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

for i in range(n-m+1):
    for j in range(n-m+1):
        cut = []
        for k in range(m):
            cut.append(As[j+k][i:i+m])
        # print(i,j,cut)
        if cut == Bs:
            print("Yes")
            exit()
print("No")

Submission status: Accepted

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

ans = 'No'
for i in range(N-M+1):
  for j in range(N-M+1):
    sbstr = ''
    for k in range(M):
      sbstr += ''.join(A[i+k][j:j+M]) 
    if B == sbstr:
      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)]
def check(dx, dy):
    cut_A = [[] for _ in range(M)]
    for i in range(dx, dx + M):
        for j in range(dy, dy + M):
            cut_A[i-dx].append(A[i][j])
    return cut_A == B

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

Submission status: Accepted

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

for i in range(n):
    a[i] = input()
for i in range(m):
    b[i] = input()
    
f=0
for i in range(n-m+1):
    for j in range(n-m+1):
        acut = [aa[i:i+m] for aa in a[j:j+m]]

        if acut==b:
            f=1
            break
    if f==1: break
print(f*"Yes"+(1-f)*"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)]

for i in range(N):
    for j in range(N):
        flg = True
        for k in range(M):
            for l in range(M):
                try:
                    if A[i+k][j+l] != B[k][l]:
                        flg = False
                except IndexError:
                    flg = False
        if flg:
            print("Yes")
            exit()

print("No")

Submission status: Accepted

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

nl = [list(input()) for _ in range(n)]

ml = [list(input()) for _ in range(m)]



for i in range (0,1+n-m):
    for j in range (0,1+n-m):
        if nl[i][j] ==ml[0][0]:
            flag = 1
            for k in range(0,m):
                for l in range(0,m):
                    if nl[i+k][j+l] !=ml[k][l]:
                        flag = 0
            if flag ==1:
                print("Yes")
                exit() 
print("No")

Submission status: Accepted

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

def main():
    N, M = map(int, readline().rstrip().split())
    A = [readline().rstrip() for _ in range(N)]
    B = [readline().rstrip() for _ in range(M)]
    if A == B:
        print('Yes')
        return
    for h in range(N-M):
        for w in range(N-M):
            a = [l[w:w+M] for l in A[h:h+M]]
            if a == B:
                print('Yes')
                return

    print('No')

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n,m = map(int, input().split())
A = []
for _ in range(n):
  A.append(list(input()))
B = []
for _ in range(m):
  B.append(list(input()))
  
ans = 'No'
for r in range(0, n-m+1):
  for c in range(0, n-m+1):
    row = 0
    while A[r+row][c:c+m] == B[row]:
      row += 1
      if row > m-1:
        ans = 'Yes'
        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)]

flg = False
for y in range(N-M+1):
  for x in range(N-M+1):
    res = True
    for i in range(M):
      if A[y+i][x+i:x+i+M] != B[i][i:i+M]: res = False
    if res: flg = True
    if flg: break
  if flg: break

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

Submission status: Accepted

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

res = "No"

for i in range(N-M+1):
    for j in range(N-M+1):
        if A[i][j:j+M] == B[0]:
            for k in range(1,M):
                if A[i+k][j:j+M] == B[k]:
                    pass
                else:
                    break
            else:
                res = "Yes"
                break

print(res)

Submission status: Accepted

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

for i in range(N-M+1):
  for j in range(N-M+1):
    for k in range(M):
      if(A[i+k][j:j+M] != B[k]):
        break
      if(k==M-1):
        res="Yes"
          
print(res)

Submission status: Accepted

Solution code:
def main():
    N, M = map(int, input().split())
    A, B = ['']*N, ['']*M
    for i in range(N):
        A[i] = input()
    for i in range(M):
        B[i] = input()
    ans = False
    len_a = len(A[0])
    len_b = len(B[0])
    for i in range(N - M + 1):
        for j in range(len_a - len_b + 1):
            match = True
            for k in range(M):
                a = A[i + k]
                b = B[k]
                if a[j:j+len_b] != b:
                    match = False
            if match:
                ans = True
                break
        if ans:
            break
    print('Yes' if ans else 'No')

if __name__ == '__main__':
    main()

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

Submission status: Accepted

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

for dy in range(n-m+1):
    for dx in range(n-m+1):
        flag = True
        for row in range(m):
            for col in range(m):
                if b[row][col] != a[dy+row][dx+col]:
                    flag = False
        if flag:
            print("Yes")
            exit()
print("No")

Submission status: Accepted

Solution code:
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
MOD = 10**9 + 7

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

d = []
for i in range( n - m + 1):
    for j in range( n - m + 1):
        koho = []
        for k in range(m):
            c = ""
            for l in range(m):
                c += li[i+k][j+l]
            koho.append(c)
        if koho == li2:
            print("Yes")
            sys.exit()
print("No")

Submission status: Accepted

Solution code:
def judge(A,B,n,m):
    C = []
    for i in range(n-m+1):
        for j in range(n-m+1):
            C = [A[i+k][j:m+j] for k in range(m)]
            if B == C:
                return True
    return False

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

    if judge(A,B,N,M):
        print("Yes")
    else:
        print("No")

if __name__ == "__main__":
    main()

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):
        flg = True
        for e, k in enumerate(range(m)):
            if A[i+e][j:j+m] != B[k]:
                flg = False
        if flg:
            ans = True
            break
print('Yes' if ans 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 p in range(n-m+1):
    for c in range(m):
      if B[c] != A[p+c][i:i+m]:
        break
    else:
      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):
        flg = True
        for k in range(M):
            for l in range(M):
                if A[i+k][j+l] != B[k][l]:
                    flg = False
        if flg:
            ans = 'Yes'
print(ans)

Submission status: Accepted

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

cnt=0
Yes=False
for i in nl:
    if(ml[0] in i):
        idx = i.find(ml[0])
        cnt2=cnt+1
        if m==1:
            Yes = True
            break
        for j in range(1,m):
            if cnt2>n-1:
                break
            elif(not ml[j]==nl[cnt2][idx:idx+m]):
                break
            elif(j==m-1):
                Yes = True
                break
            cnt2+=1
    if(Yes):
        break
    cnt+=1
if Yes:
    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)]
for i in range(n-m+1):
    for j in range(n-m+1):
        flag = True
        if a[i][j] == b[0][0]:
            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
        else:
            flag = False
        if flag:
            break
    if flag:
        break
if flag:
    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)])

T = N - M + 1

for i in range(T):
    for j in range(T):
        if np.sum(A[i:i+M, j:j+M] == B) == M ** 2:
            print('Yes')
            exit(0)
print('No')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
n, m = map(int, input().split())
a = []
for i in range(n):
  a.append(list(input()))
b = []
for i in range(m):
  b.append(list(input()))
for i in range(n - m + 1):
  for j in range(n - m + 1):
    if [c[j:j+m] for c in a[i:i+m]] == b:
      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)]
ans = 'No'
for i in range(N-M+1):
    flag1 = False
    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:
            ans = 'Yes'
            flag1 = True
            break
    if flag1:
        break
    
print(ans)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#https://atcoder.jp/contests/abc054/tasks/abc054_b
n,m=mii()

mata=[]
matb=[]

for i in range(n):
    arra=list(ss())
    mata.append(arra)
for i in range(m):
    arrb=list(ss())
    matb.append(arrb)
ans=False
#print(n-m+1)
for i in range(n-m+1):
    for j in range(n-m+1):
        chk=0
        for p in range(m):
            for q in range(m):
                if mata[p+i][q+j]==matb[p][q]:
                    chk+=1

        if chk==m*m:
            ans=True
        
if ans:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,sqrt
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7
#s=input().rstrip()

n,m=MI()
picla=[]
picsm=[]
for i in range(n):
    picla.append(input().rstrip())
for i in range(m):
    picsm.append(input().rstrip())
for i in range(n-m+1):
    for j in range(n-m+1):
        count=0
        for k in range(m):
            '''print(picla[i+k][j:j+m],end=" ")
            print(picsm[k])'''
            if picla[i+k][j:j+m]==picsm[k]:
                count+=1
        if count==m:
            print("Yes")
            sys.exit()
print("No")

Submission status: Accepted

Solution code:
import numpy as np
N,M = map(int,input().split())
A = np.array([list(input()) for i in range(N)])
B = np.array([list(input()) for i in range(M)])
for i in range(N):
    for j in range(N):
        check = A[i:i+M,j:j+M]
        if check.shape != (M,M):
            continue
        if (check==B).all():
            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())

res=0
for i in range(0,n-m+1):
  for k in range(0,n-m+1):
    keep=0
    for j in range(i,i+m):    
      if b[j-i] in a[j][k:k+m]:
        keep+=1
      if keep==m:
        print("Yes")
        res=1
        break
  if res==1:
    break
if res==0:
  print("No")

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
a=[list(input()) for i in range(n)]
b=[list(input()) for i in range(m)]
count=0
flag=False
for i in range(len(a)-len(b)+1):
  for j in range((len(a[0])-len(b[0])+1)):
    s=[]
    for k in range(i,i+len(b)):
      s.append(a[k][j:j+len(b[0])])
    count=0
    for l in range(m):
      if s[l]==b[l]:
        count+=1
      if count==m:
        flag=True
if flag:
  print("Yes")
else:
  print("No")

Submission status: Accepted

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

for i in range(N-M+1):
    for j in range(N-M+1):
        if B[0] == A[i][j:j+M]:
            for k in range(1,M):
                if B[k] != A[i+k][j:j+M]:
                    break
            else:
                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 k in range(n-m+1):
        for M in range(m):
            # print(f"i:{i}")
            # print(f"k:{k}")
            # print(f"a:{a[i+M][k:k+m]}")
            # print(f"b:{b[M]}")
            if a[i+M][k:k+m]!=b[M]:
                break
        else:
            ans="Yes"
print(ans)

Submission status: Accepted

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


def f(r, c):
    if r+M > N or c+M > N:
        return False
    for i in range(M):
        if A[r+i][c:c+M] != B[i]:
            return False
    return True


def main():
    for i in range(N):
        for j in range(N):
            if f(i,j):
                print("Yes")
                return 
    print("No")

main()

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(n-m+1):#二回
    for j in range(n-m+1):#二回
        jugh=True
      #  print(i,j)
        for x in range(m):
            for y in range(m):
         #       print(x,y)
                if a[x+i][y+j]!=b[x][y]:
                    jugh=False
                   # print(x,y)
                    break
        if jugh==True:
            print("Yes")
            exit()

print("No")

Submission status: Accepted

Solution code:
import sys

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

As = []
for i in range(N):
    As.append(list(input()))

Bs = []
for i in range(M):
    Bs.append(list(input()))


def isEqual(A_i, A_j):
    try:
        for i in range(M):
            for j in range(M):
                if As[A_i+i][A_j+j] != Bs[i][j]:
                    return
    except IndexError:
        return

    print('Yes')
    sys.exit(0)


for A_i in range(N):
    for A_j in range(N):
        isEqual(A_i, A_j)

print('No')

Submission status: Accepted

Solution code:
import sys

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):
    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 == True:
      print("Yes")
      sys.exit()
      
print("No")

Submission status: Accepted

Solution code:
N, M = [int(i) for i in 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):
        if b == [a[k+i][j:j+M] for k in range(M)]:
            flag = True

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