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
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_nl = lambda: list(map(int, readline().split()))
in_na = lambda: map(int, read().split())
in_s = lambda: readline().rstrip().decode('utf-8')
in_map = lambda: [s == ord('.') for s in read() if s != ord('\n')]


def main():
    N, M = in_nn()
    t = in_map()
    A = np.array(t[:N * N]).reshape(N, N)
    B = np.array(t[N * N:]).reshape(M, M)

    ans = 'No'
    for y in range(N - M + 1):
        for x in range(N - M + 1):
            if np.all(A[y:y + M, x:x + M] == B):
                ans = 'Yes'

    print(ans)


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

for i in range(N-M+1):
    for j in range(N-M+1):
        result = True
        for k in range(M):
            for l in range(M):
                if b[k][l] != a[i+k][j+l]:
                    result = False
        if result:
            print('Yes')
            exit()
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)]


c = N - M + 1

for ic in range(c):
    for jc in range(c):
        cnt = 0
        for i in range(M):
            for j in range(M):
                if A[ic + i][jc + j] == B[i][j]:
                    cnt += 1

        if cnt == M * M:
            print("Yes")
            sys.exit()
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 x in range(0, n - m + 1):
    for y in range(0, n - m + 1):
        check = True
        for i in range(m):
            for j in range(m):
                if a[i+x][j+y] != b[i][j]:
                    check = False
                    break
            if check == False:
                break
        if check == True:
            ans = 'Yes'
            break
print(ans)

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 (A[i:i+m, j:j+m] == B).all():
            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)]
isIn = False
for i in range(N - M + 1):
    for j in range(N - M + 1):
        isOK = True
        for now in range(M):
            if A[i+now][j:j+M] != B[now]:
                isOK = False
                break
        if isOK:
            isIn = True
            break
    if isIn:
        break
if isIn:
    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):
        t = 1
        for k in range(m):
            for l in range(m):
                if a[i+k][j+l] != b[k][l]:
                    t = 0
        if t == 1:
            print('Yes')
            exit(0)

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()))
for i in range(n-m+1):
    for j in range(n-m+1):
        flg=True
        for k in range(m):
            for kk in range(m):
                if b[k][kk]!=a[i+k][j+kk]:
                    flg=False
        if flg:
            print("Yes")
            exit()
print("No")

Submission status: Accepted

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

Submission status: Accepted

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

# print(A)
# print(B)

# i = 行、j = 列
for i in range(N - M + 1):
    for j in range(N - M + 1):
        # print(i, j)
        A_part = []
        for k in range(i, i + M):
            A_part.append(A[k][j:j + M])
        # print(A_part)
        if A_part == B:
            print("Yes")
            exit()
print("No")

Submission status: Accepted

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

for i in range(n - m + 1):
    for j in range(n - m + 1):
        for k, row in enumerate(blst):
            if alst[i + k][j:j + m] == blst[k]:
                continue
            break
        else:
            print("Yes")
            exit()
print("No")

Submission status: Accepted

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

def main():
    N, M = map(int, input().split())
    A = [list(input().rstrip()) for _ in range(N)]
    B = [list(input().rstrip()) for _ in range(M)]
    mv = N - M + 1
    for i in range(mv):
        for j in range(mv):
            sub_A = [r[j:j+M] for r in A[i:i+M]]
            if sub_A == B:
                print("Yes")
                exit()
    print("No")


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n, m = map(int,input().split())
A = ['']*n
B = ['']*m
for i in range(n):
    A[i] = input()
for i in range(m):
    B[i] = input()

w_dif = len(A[0])-len(B[0])
w_w = len(B[0])
ans = 'No'
for h in range(n-m+1):
    for w in range(w_dif+1):
        window = [wh[w:w+w_w] for wh in A[h:h+m]]
        if window==B:
            ans = 'Yes'
            break
print(ans)

Submission status: Accepted

Solution code:
n,m=list(map(int,input().split()))
N=[list(input()) for _ in range(n)]
M=[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):
      if N[i+k][j:j+m] == M[k][:]:
        count += 1
    if count == m:
      print("Yes")
      exit()
    
print("No")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np

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

aa = np.zeros((n,n), dtype=int)
for i in range(n):
    for j in range(n):
        if a[i][0][j] == '#':
            aa[i][j] = 1

bb = np.zeros((m,m), dtype=int)
for i in range(m):
    for j in range(m):
        if b[i][0][j] == '#':
            bb[i][j] = 1

flg = False
for i in range(n-m+1):
    for j in range(n-m+1):
        aaa = aa[i:i+m,j:j+m]
        if np.all(aaa == bb):
            flg = True

print('Yes') if flg 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):
        check = True
        count = 0
        for k in range(M):
            if (A[i + k][j: j + M] == B[k]):
                # print(A[i + k][j:j + M], B[k])
                count += 1
                continue
            else:
                check = False
                break

        if (check and count == 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)]

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

Submission status: Accepted

Solution code:
N,M,*f = open(0).read().split()
N = int(N)
M = int(M)
A = f[:N]
B = f[N:]
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]:
                    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)]

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

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
A = [list(map(str,list(input()))) for i in range(n)] 
B = [list(map(str,list(input()))) for i in range(m)] 
def move(h,w):
    cnt = 0
    for i in range(m):
        for j in range(m):
            if B[i][j] == A[i+h][j+w]:
                cnt += 1
    return cnt
flg = 0
for i in range(n-m+1):
    for j in range(n-m+1):
        if move(i,j)==m*m:
            flg = 1
            break
if flg == 1:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
N,M = map(int,input().rstrip().split(" "))
A = []
B = []
ans = False
for i in range(N):
    A.append(list(input()))
for i in range(M):
    B.append(list(input()))
for i in range(N - M + 1):
    for i2 in range(N - M + 1):
        for i3 in range(M):
            if A[i3 + i][i2:i2 + M] != B[i3]:
                break
            if i3 == M -1:
                ans = True
if ans:
    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 n in range(N)])
B = np.array([list(input()) for m in range(M)])
a = "No"
 
for i in range(N-M+1):
  for j in range(N-M+1):
    if (A[i:i+M,j:j+M]==B).all():
      a = "Yes"

print(a)

Submission status: Accepted

Solution code:
import numpy as np

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

A=np.array(A)
B=np.array(B)
ans="No"
for i in range(N):
    for j in range(N):
        if i+M<=N and j+M<=N:
            if (A[i:i+M, j:j+M]==B).all():
                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)]

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

Submission status: Accepted

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

def main(n,m,a,b):
    for i in range(n-m+1):
        for j in range(n-m+1):
            for k in range(m):
                #print(a[i+k][j:j+m],b[k])
                if a[i+k][j:j+m]!=b[k]:
                    break
            else:
                return 'Yes'
    return 'No'

if __name__=='__main__':
    n,m,a,b=readinput()
    ans=main(n,m,a,b)
    print(ans)

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())
flg = True
for i in range(N):
    for j in range(N-M+1):
        #print(a[i][j:j+(M-1)])
        if a[i][j:j+M] == b[0]:
            if M == 1:
                print('Yes')
                exit()
            else:
                for k in range(1,M):
                    if a[k][j:j+M] != b[k]:
                        flg = False
                        break
                if flg:
                    print('Yes')
                    exit()
                else:
                    flg = 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)]

r = n - m + 1
for i_r in range(r):
    for j_r in range(r):
        ok = True
        for i in range(m):
            for j in range(m):
                if a[i_r + i][j_r + j] != b[i][j]:
                    ok = False
        if ok:
            print('Yes')
            exit(0)

print('No')

Submission status: Accepted

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

for ly in range(N):
    for lx in range(N):
        if N - M + 1 <= lx:
            continue
        if N - M + 1 <= ly:
            continue
        flag = True
        for y in range(M):
            for x in range(M):
                if B[y][x] != A[ly+y][lx+x]:
                    flag = False
        if flag:
            ans = True

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

Submission status: Accepted

Solution code:
def resolve():
    '''
    code here
    '''

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

    is_found = False
    for i in range(N-M+1):
        temp_line = A[i:i+M]
        for j in range(N-M+1):
            temp_grid = [line[j:j+M] for line in temp_line]
            # print(temp_grid)
            if B == temp_grid:
                is_found = True
                break
        if is_found:
            break

    print('Yes') if is_found else print('No')

if __name__ == "__main__":
    resolve()

Submission status: Accepted

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

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

A = []
B = []

for i in range(N):
    A.append(list(map(str, input())))

for i in range(M):
    B.append(list(map(str, input())))

tmp = []
for i in range(N - M + 1):
    for j in range(N - M + 1):
        tmp = []
        for k in range(M):
            tmp.append(A[i + k][j:j+M])
        # 判定
        if tmp == B:
            print('Yes')
            exit()

print('No')

Submission status: Accepted

Solution code:
import sys
N, M = map(int, input().split())
A = [list(map(str, input())) for _ in range(N)]
B = [list(map(str, 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')
            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)]
flag = False

for x1 in range(N - M + 1):
    for x2 in range(N - M + 1):
        check = True
        for y in range(M):
            for z in range(M):
                if A[z + x1][y + x2] != B[z][y]:
                    check = False

                # print(A[z][y])
                # print(B[z][y])
        if check:
            flag = True
            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)])

ans = 'No'
for i in range(n-m+1):
    for j in range(n-m+1):
        if (a[i:m+i, j:m+j] == b).all():
            ans = 'Yes'
print(ans)

Submission status: Accepted

Solution code:
n, m = map(int,input().split())
A = [[] for _ in range(n)]
for i in range(n):
    A[i] = input()
B = [[] for _ in range(m)]
for i in range(m):
    B[i] = input()
    
flag = False
for tate_begin in range(n-m+1):
    for yoko_begin in range(len(A[0])-len(B[0])+1):
        for check in range(m):
            a_yoko = A[tate_begin+check][yoko_begin:yoko_begin+len(B[0])]
            if a_yoko != B[check]:
                break
        else:
            flag = True
            print('Yes')
    if flag:
        break
else:
    print('No')

Submission status: Accepted

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

ok = 0
for i in range(n - m + 1):
    for j in range(n - m + 1):
        from_n = [l[j:j+m] for l in A[i:i+m]]
        ok += from_n == B
print('Yes' if ok > 0 else 'No')

Submission status: Accepted

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

def II(): return int(input())
def MII(): return map(int, input().split())
def LII(): return list(map(int, input().split()))

def main():
    N, M = MII()
    A = []
    for _ in range(N):
        A.append(list(input()))

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

    f = True
    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]:
                    f = False
                    break
                f = True
            if f:
                print('Yes')
                return
    
    print('No')

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(map(int,input().split()))
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
INF = 10**9
mod = 10**9+7

N,M = I()
maze1 = [list(s()) for _ in range(N)]
maze2 = [list(s()) for _ in range(M)]
L = [[-1]*N for _ in range(N)]
def dfs(x,y):
    if x == N or y == N:
        return
    if x-i == M or y-j == M:
        return
    if maze1[x][y] != maze2[x-i][y-j]:
        L[i][j] = 0
        return
    dfs(x+1,y)
    dfs(x,y+1)
for i in range(N-M+1):
    for j in range(N-M+1):
        dfs(i,j)
        if L[i][j] == -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 n in range(N)])
B = np.array([list(input()) for m in range(M)])
a = "No"

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

print(a)

Submission status: Accepted

Solution code:
# coding: utf-8
N,M=map(int,input().split())
picN=[]
picM=[]

for i in range(N):
    L=list(input())
    picN.append(L)

for i in range(M):
    L=list(input())
    picM.append(L)

K=N-M

for i in range(K+1):
    for j in range(K+1):
        flg=True
        for a in range(M):
            for b in range(M):
                if picN[a+i][b+j]!=picM[a][b]:
                    flg=False
        if flg:
            break
    if flg:
        break

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

Submission status: Accepted

Solution code:
# coding: utf-8

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()))
    
w = len(B[0])
flg = False    
for i in range(N-M+1):
    if flg:
        break
    
    for j in range(len(A[0])-len(B[0])+1):
        if flg:
            break
        cnt = 0
        for k in range(M):
            #print(i+k)
            #print(A[i+k][j:j+w], B[i+k])
            #print(k, j,j+w)
            if A[i+k][j:j+w] == B[k]:
                cnt += 1
        if cnt == M:
            flg = True
            break

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

Submission status: Accepted

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

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

d=0
r=0
while d<n-m+1 :
    for r in range(n-m+1):
        flg=0
        for i in range(m):
            for j in range(m):
                s=a[i+d][j+r]
                t=b[i][j]
                if s==t:
                    continue
                else:
                    flg+=1
        
        if flg==0:
            print('Yes')
            exit(0)

    d+=1


print('No')

Submission status: Accepted

Solution code:
from itertools import product
import numpy as np

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

for i, j in product(range(N-M+1), repeat=2):
  if np.prod([A[i+k][j:j+M] == B[k] for k in range(M)]):
    print('Yes')
    break
else:
  print('No')

Submission status: Accepted

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

for r in range(n-m+1):
    for c in range(n-m+1):
        flg=True
        for i in range(m):
            for j in range(m):
                if a[r+i][c+j] != b[i][j]:
                    flg=False
                    break
            if not flg:
                break
        if flg:
            print('Yes')
            exit()

print('No')

Submission status: Accepted

Solution code:
import numpy as np
import scipy.sparse as sps
import scipy.misc as spm
import collections as col
import functools as func
import itertools as ite
import fractions as frac
import math as ma
from math import cos,sin,tan,sqrt
import cmath as cma
import copy as cp
import sys
import re
sys.setrecursionlimit(10**7)
EPS = sys.float_info.epsilon
PI = np.pi; EXP = np.e; INF = np.inf
MOD = 10**9 + 7

def sinput(): return sys.stdin.readline().strip()
def iinput(): return int(sinput())
def imap(): return map(int, sinput().split())
def fmap(): return map(float, sinput().split())
def iarr(n=0):
    if n: return [0 for _ in range(n)]
    else: return list(imap())
def farr(): return list(fmap())
def sarr(n=0):
    if n: return ["" for _ in range(n)]
    else: return sinput().split()
def adj(n): return [[] for _ in range(n)]

n,m = imap()
a = [[int(elm=="#") for elm in list(input())] for i in range(n)]
b = [[int(elm=="#") for elm in list(input())] for i in range(m)]
a,b = np.array(a),np.array(b)
#print(a)
#print(b)

flag = 0
for i in range(n-m+1):
    for j in range(n-m+1):
        tmp = a[i:i+m, j:j+m]
        if (tmp == b).all(): flag = 1; break

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

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)])
d=n-m+1
for i in range(d):
 for j in range(d):
  if (a[i:i+m,j:j+m]==b).all():print("Yes");exit()
print("No")

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
ag = []
for i in range(n):
    ag.append(list(input()))
bg = []
for i in range(m):
    bg.append(list(input()))
for i in range(n-m+1):
    for j in range(n-m+1):
        u = []
        for k in range(m):
            u.append(ag[j+k][i:i+m])
        if u == bg:
            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)])
ans="No"
bl = False
for i in range(N-M+1):
    for j in range(N-M+1):
        if (A[i:i+M,j:j+M] == B).all():
            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)]
na = len(A[0])
nb = len(B[0])
flag = False
for i in range(n-nb+1):
    for j in range(n-m+1):
        cnt = 0
        for a, b in zip(A[i:i+nb], B):
            if a[j:j+m] == b:
                cnt += 1
        if cnt == m:
            flag = True
            break
print('Yes' if flag 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):
        flag=1
        for k in range(m):
            for l in range(m):
                if b[k][l]!=a[i+k][j+l]:
                    flag=0
                    break
            if not flag: break
        if flag:
            print("Yes")
            break
    if flag: break
if not flag: print("No")

Submission status: Accepted

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


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

Submission status: Accepted

Solution code:
def main():
    n,m = map(int,input().split())
    a,b = [],[]
    for i in range(n):
        a.append(list(input()))
    for j in range(m):
        b.append(list(input()))
    flag = 0
    for i in range((n-m)+1):
        for j in range((n-m)+1):
            counter = 0
            for k in range(m):
                for l in range(m):
                    if a[k+i][l+j] == b[k][l]:
                        counter += 1
            if counter == m**2:
                flag = 1
    print("Yes" if flag else "No")
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)]

import numpy as np
A = np.array(A)
B = np.array(B)
# print(A)
# print()
# print(B)
# print()

if N==M:
    if np.all(A==B):
        print('Yes')
    else:
        print('No')
else:
    for i in range(N-M):
        for j in range(N-M):
    #         print(i,j)
            a = A[i: i+M, j: j+M]
    #         print(a)
    #         print()
            if np.all(a == B):
                print('Yes')
                break
        else:
            continue
        break
    else:
        print('No')

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 y in range(N):
  A[y]=list(input())
for y in range(M):
  B[y]=list(input())
exist=False
for ly in range(N):
  for lx in range(N):
    if ly+M-1>=N or lx+M-1>=N:
      continue
    match=True
    for y in range(M):
      for x in range(M):
        if A[ly+y][lx+x]!=B[y][x]:
          match=False
    if match==True:
      exist=True
print("Yes" if exist==True else "No")

Submission status: Accepted

Solution code:
def f(s):
    if s==".":
        return 1
    else:
        return 0

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

B=[]
for _ in range(M):
    B.append(list(map(f,input())))

F=False
for i in range(N-M+1):
    for j in range(N-M+1):
        G=True
        for k in range(M):
            G=G and (A[j+k][i:i+M]==B[k])
        F=F|G
    
if F:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

X = [input() for _ in range(n)]
np_x = np.zeros((n, n), dtype=int)
for i in range(n):
  for j in range(n):
    np_x[i, j] = X[i][j] == '.'
Y = [input() for _ in range(m)]
np_y = np.zeros((m, m), dtype=int)
for i in range(m):
  for j in range(m):
    np_y[i, j] = Y[i][j] == '.'

for i in range(n-m+1):
  for j in range(n-m+1):
    if np.all(np_x[i:i+m, j:j+m] == np_y):
      print('Yes')
      exit()
else:
  print('No')

Submission status: Accepted

Solution code:
a, b = map(int,input().split())
A = [input() for _ in range(a)]
B = [input() for _ in range(b)]
ans = "No"
for i in range(a-b+1):
    for j in range(a-b+1):
        cnt = 0
        if A[i][j] == B[0][0]:
            for k in range(b):
                for l in range(b):
                    if A[i+k][j+l] == B[k][l]:
                        cnt += 1
                    if cnt == b**2:
                        ans = "Yes"

print(ans)