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: Wrong Answer

Solution code:
N,M = map(int,input().split())
Als = []
Bls = []
ans = 'No'
for i in range(N):
    Als.append(input())
for i in range(M):
    Bls.append(input())
for i in range(N-M):
    for j in range(0,N-M):
        for k in range(M):
            if Bls[k] == Als[i+k][j:M+j]:
                ans = 'Yes'
            else:
                ans = 'No'
                break
        if ans == 'Yes':
            break
    if ans == 'Yes':
        break
print(ans)

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
Als = []
Bls = []
ans = 'No'
for i in range(N):
    Als.append(input())
for i in range(M):
    Bls.append(input())
for i in range(N-M):
    for j in range(0,N-M):
        for k in range(M):
            if Bls[k] == Als[i+k][j:M]:
                ans = 'Yes'
            else:
                ans = 'No'
                break
        if ans == 'Yes':
            break
    if ans == 'Yes':
        break
print(ans)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
a=[list(input()) for _ in range(n)]
b=[list(input()) for _ in range(m)]
r=n-m+1
for x in range(r**2):
  for y in range(m**2):
    if a[x//r][x%r]!=b[y//m][y%m]:
      break
  else:
    print('Yes')
    break
else:
  print('No')

Submission status: Wrong Answer

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

eq = False
ans = 'No'
for i in range(n-m+1):
  for j in range(n-m+1):
    for p in range(m):
      for q in range(m):
        if a[p+i][q+j] == b[p][q]:
          eq = True
        else:
          eq = False
          break
      else:
        ans = 'Yes'
      if not eq:
        break
print(ans)

Submission status: Wrong Answer

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

eq = False
ans = 'No'
for i in range(n-m):
  for j in range(n-m):
    for p in range(m):
      for q in range(m):
        if a[p+i][q+j] == b[p][q]:
          eq = True
        else:
          eq = False
          break
      else:
        ans = 'Yes'
      if not eq:
        break
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque
n, m = map(int, input().split())
a = ["" for _ in range(n)]
b = ["" for _ in range(m)]
for i in range(n):
    a[i] = str(input())
for i in range(m):
    b[i] = str(input())
directions = [(1, 0), (0, 1)]
def check(ini_x, ini_y):
    global n, m, a, b
    for x in range(m):
        for y in range(m):
            if a[ini_x + x][ini_y + y] != b[x][y]:
                return False
    return True
    # if a[ini_x][ini_y] != b[0][0]:
    #     return False
    # seen = [[False] * m] * m
    # que = deque()
    # que.append((ini_x, ini_y))
    # while que:
    #     prev = que.popleft()
    #     if seen[prev[0] - ini_x][prev[1] - ini_y]:
    #         continue
    #     for d in directions:
    #         now_x = prev[0] + d[0]
    #         now_y = prev[1] + d[1]
    #         if not (0 <= now_x - ini_x < m) or not (0 <= now_y - ini_y < m):
    #             continue
    #         seen[now_x - ini_x][now_y - ini_y] = True
    #         if a[now_x][now_y] != b[now_x - ini_x][now_y - ini_y]:
    #             return False
    #         que.append((now_x, now_y))
    # return True
for i in range(n - m):
    for j in range(n - m):
        if check(i, j):
            print("Yes")
            exit()
print("No")

Submission status: Wrong Answer

Solution code:
from collections import deque
n, m = map(int, input().split())
a = ["" for _ in range(n)]
b = ["" for _ in range(m)]
for i in range(n):
    a[i] = str(input())
for i in range(m):
    b[i] = str(input())
directions = [(1, 0), (0, 1)]
def check(ini_x, ini_y):
    global n, m, a, b
    if a[ini_x][ini_y] != b[0][0]:
        return False
    seen = [[False] * m] * m
    que = deque()
    que.append((ini_x, ini_y))
    while que:
        prev = que.popleft()
        if seen[prev[0] - ini_x][prev[1] - ini_y]:
            continue
        for d in directions:
            now_x = prev[0] + d[0]
            now_y = prev[1] + d[1]
            if not (0 <= now_x - ini_x < m) or not (0 <= now_y - ini_y < m):
                continue
            seen[now_x - ini_x][now_y - ini_y] = True
            if a[now_x][now_y] != b[now_x - ini_x][now_y - ini_y]:
                return False
            que.append((now_x, now_y))
    return True
for i in range(n - m):
    for j in range(n - m):
        if check(i, j):
            print("Yes")
            exit()
print("No")

Submission status: Wrong Answer

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

a_list = []
b_list = []
ans = "No"

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

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

for i in range(n-m+1):
    for j in range(n-m+1):
        match = True
        for k in range(m):
            for l in range(m):
                if a_list[i+k][l+j] != b_list[k][l]:
                    match = False
        if match:
            ans = "True"
            break

print(ans)

Submission status: Wrong Answer

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) :
        a = True
        for k in range(M) :
            for l in range(M) :
                if A[i+k][j+l] != B[k][l] :
                    a = False
                    break
                else :
                    continue
                break
                    
if a :
    print('Yes')
else :
    print('No')

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
a = []
c = []
for i in range(N):
    b = list(input())
    a+=b
for i in range(M):
  b = list(input())
  c+=b
f = False
for i in range(N*N):
  if f == True:
    break
  count=0
  if N*N-(i)<M*M:
    break
  flag = True
  if c[0] == a[i]:
    if N-((i+1)%N)>M:
      continue
    num = i
    for j in range(M):
      for k in range(M):
        if c[count] == a[num]:
          
          num+=1
          count+=1
        elif c[count]!=a[num]:
          flag =False
          break
      num+=N-M
      if flag == False:
        break  
      if j == M-1:
        f = True
            
  else:
    continue
if f == False:
  print('No')
else:
  print('Yes')

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
a = []
c = []
for i in range(N):
    b = list(input())
    a+=b
for i in range(M):
  b = list(input())
  c+=b
f = False
for i in range(N*N):
  if f == True:
    break
  count=0
  if N*N-(i)<M*M:
    break
  flag = True
  if c[0] == a[i]:
    if N-((i+1)%N)>M:
      continue
    num = i
    for j in range(M):
      for k in range(M):
        print(c[count],a[num])
        if c[count] == a[num]:
          
          num+=1
          count+=1
        elif c[count]!=a[num]:
          flag =False
          break
      num+=N-M
      if flag == False:
        print(i)
        break  
      if j == M-1:
        f = True
            
  else:
    continue
if f == False:
  print('No')
else:
  print('Yes')

Submission status: Wrong Answer

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

def c(a, m, x, y):
  tmp = []
  for i in range(m):
    tmp.append(a[y+i][x:x+m])
  return tmp

for x in range(n - m):
  for y in range(n - m):
    if c(a, m, x, y) == b:
      print("Yes")
      exit(0)
print("No")

Submission status: Wrong Answer

Solution code:
import numpy as np

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

A=[list(map(int,list(input().replace('.','0').replace('#','1')))) for _ in range(N)]
B=[list(map(int,list(input().replace('.','0').replace('#','1')))) for _ in range(M)]

A,B=map(np.array,(A,B))

for i in range(N-M):
  for j in range(N-M):
    if (A[i:i+M,j:j+M] == B).all():
      print('Yes')
      exit()

print('No')

Submission status: Wrong Answer

Solution code:

import sys

N,M=input().split()

N=int(N)

M=int(M)


list1=[input() for i in range(N)]

list2=[input() for i in range(M)]

#print(list1)

#print(list2)
    
aaa=[]
    
for i in range(N-M+1):
    if (list2[0] in list1[i]) == True:
        aaa.append(i)

#print(aaa)

if len(aaa)==0:
    print("No")
    sys.exit()



bbb=[]

for i in aaa:
    for k in range(M):
        if (list2[k] in list1[i+k])==True:
            hantei = True
        else:
            hantei = False
            bbb.append(hantei)
            break
        bbb.append(hantei)

#print(bbb)

def split_list(l, n):
    
    for idx in range(0, len(l), n):
        yield l[idx:idx + n]

ccc = list(split_list(bbb,len(aaa)))

#print(ccc)

ddd=[]

for i in ccc:
    #print(i)
    #print(all(i))
    ddd.append(all(i))

#print(ddd)

#print(any(ddd))

if any(ddd)==True:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
a=[input() for _ in range(n)]
b=[input() for _ in range(m)]
b1=b[0]
res="No"
for i in range(n-m+1):
    if b1 in a[i]:
        x=a[i].index(b1)
        match=1
        for j in range(1,m):
            if a[i+j][x:]!=b[j]:
                match=0
        if match:
            res="Yes"
print(res)

Submission status: Wrong Answer

Solution code:
def input_li():
    return list(map(int, input().split()))

def input_int():
    return int(input())

N, M = input_li()
A_LI = []
B_LI = []
for _ in range(N):
    A_LI.append(input())
for _ in range(M):
    B_LI.append(input())
for i in range(N - M):
    for j in range(N - M):
        is_ok = True
        for col in range(M):
            for row in range(M):
                if B_LI[col][row] != A_LI[i + col][j + row]:
                    is_ok = False
                    break
            if not is_ok:
                break
        if is_ok:
            print('Yes')
            exit()
print('No')

Submission status: Wrong Answer

Solution code:
from itertools import accumulate
N, M = map(int, input().split())

A = [[0 for _ in range(N + 1)]]
for i in range(N):
    text = list(input())
    rows = [0]
    for j, char in enumerate(text):
        if char == '#':
            rows.append(rows[j] + 1)
        else:
            rows.append(rows[j])
    A.append(rows)
B = [[0 for _ in range(M + 1)]]
for i in range(M):
    text = list(input())
    rows = [0]
    for j, char in enumerate(text):
        if char == '#':
            rows.append(rows[j] + 1)
        else:
            rows.append(rows[j])
    B.append(rows)
# print(A)
# print(B)
ans = False
for i in range(1, N - M + 2):
    for j in range(1, N + 2 - M):
        is_exist = True
        # print('=======', i, j)
        for k in range(1, M + 1):
            for l in range(1, M + 1):
                # print(k, l, B[k][l], A[i + k - 1][j + l - 1], A[i - 1][j], A[i][j - 1])
                if B[k][l] != (A[i + k - 1][j + l - 1] - A[i - 1][j] - A[i][j - 1]):
                    is_exist = False
        if is_exist:
            ans = is_exist
if ans:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
from itertools import accumulate
N, M = map(int, input().split())

A = [[0 for _ in range(N + 1)]]
for i in range(N):
    text = list(input())
    rows = [0]
    for j, char in enumerate(text):
        if char == '#':
            rows.append(rows[j] + 1)
        else:
            rows.append(rows[j])
    A.append(rows)
B = [[0 for _ in range(M + 1)]]
for i in range(M):
    text = list(input())
    rows = [0]
    for j, char in enumerate(text):
        if char == '#':
            rows.append(rows[j] + 1)
        else:
            rows.append(rows[j])
    B.append(rows)
# print(A)
# print(B)
ans = False
for i in range(1, N - M + 2):
    for j in range(1, N + 2 - M):
        is_exist = True
        # print('=======', i, j)
        for k in range(1, M + 1):
            for l in range(1, M + 1):
                # print(k, l)
                if B[k][l] != (A[i + k - 1][j + l - 1] - A[i - 1][j - 1]):
                    is_exist = False
        if is_exist:
            ans = is_exist
if ans:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
from itertools import accumulate
N, M = map(int, input().split())

A = []
for i in range(N):
    text = list(input())
    rows = [0]
    for j, char in enumerate(text):
        if char == '#':
            rows.append(rows[j] + 1)
        else:
            rows.append(rows[j])
    A.append(rows)
B = []
for i in range(M):
    text = list(input())
    rows = [0]
    for j, char in enumerate(text):
        if i == 0:
            if char == '#':
                rows.append(rows[j] + 1)
            else:
                rows.append(rows[j])
        else:
            if char == '#':
                rows.append(rows[j] + 1)
            else:
                rows.append(rows[j])
    B.append(rows)
# print(A)
# print(B)
ans = False
for i in range(N - M + 1):
    for j in range(1, N + 2 - M):
        is_exist = True
        for k in range(M):
            for l in range(1, M + 1):
                # print(i, j, k, l)
                if B[k][l] != A[i + k - 1][j + l - 1]:
                    is_exist = False
        if is_exist:
            ans = is_exist
if ans:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
from itertools import accumulate
N, M = map(int, input().split())

A = []
for i in range(N):
    text = list(input())
    rows = [0]
    for j, char in enumerate(text):
        if char == '#':
            rows.append(rows[j] + 1)
        else:
            rows.append(rows[j])
    A.append(rows)
B = []
for i in range(M):
    text = list(input())
    rows = [0]
    for j, char in enumerate(text):
        if i == 0:
            if char == '#':
                rows.append(rows[j] + 1)
            else:
                rows.append(rows[j])
        else:
            if char == '#':
                rows.append(rows[j] + 1)
            else:
                rows.append(rows[j])
    B.append(rows)
# print(A)
# print(B)
ans = False
for i in range(N - M + 1):
    for j in range(1, N + 1 - M):
        is_exist = True
        for k in range(M):
            for l in range(1, M + 1):
                # print(i, j, k, l)
                if B[k][l] != A[i + k - 1][j + l - 1]:
                    is_exist = False
        if is_exist:
            ans = is_exist
if ans:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n,m = readInts()
A = [list(input()) for _ in range(n)]
B = [list(input()) for _ in range(m)]
flag = False
for i in range(n-m):
    for j in range(n-m):
        if A[j][i] == B[0][0]:
            flag = True
            for k in range(m):
                for s in range(m):
                    if A[j+k][i+s] == B[k][s]:
                        pass
                    else:
                        flag = False
                        break
                else:
                    break
            if flag:
                print('Yes')
                exit()
print('No')

Submission status: Wrong Answer

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

ans = "No"
for i in range(n-m+1):
    n = -1
    cnt = 0
    for j in range(m):
        if B[j] in A[i+j]:
            if n < 0:
                n = A[i+j].index(B[j])
            cnt += 1
        else:
            if B[j] in A[i+j][n:n+b+1]:
                cnt += 1
    if cnt == m:
        ans = "Yes"
print(ans)

Submission status: Wrong Answer

Solution code:
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(tin())
mod=1000000007

#+++++

def tm(a, b, hi, wi):
	lb=len(b[0])
	for i, bi in enumerate(b):
		if a[hi+i][wi: wi+lb] != bi:
			return False
	return True
	


def main():
	#a = int(input())
	n, m = tin()
	#s = input()
	al=[input() for _ in range(n)]
	bl=[input() for _ in range(m)]
	for hi in range(n-m):
		for wi in range(n-m):
			if tm(al, bl, hi, wi):
				return 'Yes'
	return 'No'
	
	
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
s1=[input() for _ in range(n)]
s2=[input() for _ in range(m)]
ans='No'
for i in range(n-m+1):
  for j in range(n-m+1):
    flg=0
    print(i,j)
    for k in range(m):
      if s1[j+k][i:i+m]==s2[k]:
        flg+=1
    if flg==m:
      ans='Yes'
print(ans)

Submission status: Wrong Answer

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:i+m] for a in A[i:i+m]] == B:
            print('Yes')
            exit()
print('No')

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

#print(A)
#print(B)

for a in A:
    for b in B:
        flg = True
        if b not in a:
            flg = False
        if flg:
            print("Yes")
            exit()
print("No")

Submission status: Wrong Answer

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

for a in A:
    #print(a)
    for i in range(1, -2, -2):
        if i == 1:
            tmp = a[i:]
        else:
            tmp = a[:i]
        for b in B:
            flg = True
            if tmp != b:
                flg = False
            if flg:
                print("Yes")
                exit()
print("No")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
A = []
B = []
for i in range(N):
  a = str(input())
  A.append(a)
for i in range(M):
  b = str(input())
  B.append(b)
  
flag = False
for i in range(N-M+1):
  for j in range(N-M+1):
    if A[i][j:j+M] == B[0]:
      k = 1
      while k < M:
        if A[i+1][j:j+M] == B[k]:
          k += 1
        else:
          break
      if k == M:
        flag = True
        break
  if flag:
    break
        
if flag:
  print('Yes')
else:
  print('No')

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
A = []
B = []
for i in range(N):
  a = str(input())
  A.append(a)
for i in range(M):
  b = str(input())
  B.append(b)
  
flag = False
for i in range(N-M+1):
  for j in range(N-M+1):
    if A[i][j:j+M] == B[0]:
      k = 1
      while k < M:
        if A[i+1][j:j+M] == B[k]:
          k += 1
        else:
          break
      if k == M:
        flag = True
        break
        
if flag:
  print('Yes')
else:
  print('No')

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
A = []
B = []
for i in range(N):
  a = str(input())
  A.append(a)
for i in range(M):
  b = str(input())
  B.append(b)
  
flag = False
for i in range(N-M+1):
  for j in range(N-M+1):
    if A[i][j:j+M] == B[0]:
      if M == 1:
        flag = True
        break
      k = 1
      while k < M:
        if A[i+1][j:j+M] == B[k]:
          k += 1
        else:
          break
      else:
        flag = True
        break
        
if flag:
  print('Yes')
else:
  print('No')

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
A = []
B = []
for i in range(N):
  a = str(input())
  A.append(a)
for i in range(M):
  b = str(input())
  B.append(b)
  
flag = False
for i in range(N-M+1):
  for j in range(N-M+1):
    if A[i][j:j+M] == B[0]:
      k = 1
      while k < M:
        if A[i+1][j:j+M] == B[k]:
          k += 1
        else:
          break
      else:
        flag = True
        break
        
if flag:
  print('Yes')
else:
  print('No')

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
A=[input()for i in range(N)]
B=[input()for i in range(M)]
ok=False
for i in range(N-M+1):
    for j in range(len(A[0])-len(B[0])+1):
        l=[]
        for k in range(M):
            l.append(A[i+k][j:j+M])
        ok=l==B
        if ok:break
print('Yes'if ok else'No')

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
A=[input()for i in range(N)]
B=[input()for i in range(M)]
ok=False
for i in range(N-M+1):
    for j in range(len(A[0])-len(B[0])+1):
        l=[]
        for k in range(M):
            l.append(A[i+k][j:j+M])
        ok=l==B
print('Yes'if ok else'No')

Submission status: Wrong Answer

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

B=[]
ans=0
for i in range(m):
  b=[x for x in input()]
  ans+=len(b)
  B.append(b)

cnt=0
flag=0
for i in range(len(B[0])):
  for j in range(m):
    if A[i][j]==B[i][j]:
      cnt+=1
      if cnt==ans:
        flag=1
    else:
      cnt=0

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

Submission status: Wrong Answer

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

B=[]
ans=0
for i in range(m):
  b=[x for x in input()]
  ans+=len(b)
  B.append(b)

cnt=0
flag=0
for i in range(m):
  for j in range(m):
    if A[i][j]==B[i][j]:
      cnt+=1
      if cnt==ans:
        flag=1
    else:
      cnt=0

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

Submission status: Wrong Answer

Solution code:
import sys

N,M=map(int,input().split())
A=[list(sys.stdin.readline().strip()) for _ in range(N)]
B=[list(sys.stdin.readline().strip()) for _ in range(M)]
 
for i in range(N-M+1):
  for j in range(N-M+1):
    As=[x[j:j+M] for x in A[j:j+M]]
    if B==As:
      print('Yes')
      sys.exit()
print('No')

Submission status: Wrong Answer

Solution code:
import sys

N,M=map(int,input().split())
A=[sys.stdin.readline().strip() for _ in range(N)]
B=[sys.stdin.readline().strip() for _ in range(M)]
 
for i in range(N-M+1):
  for j in range(N-M+1):
    As=[x[j:j+M] for x in A[j:j+M]]
    if B==As:
      print('Yes')
      sys.exit()
print('No')

Submission status: Wrong Answer

Solution code:
import sys

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

for i in range(N-M):
  for j in range(N-M):
    As=[x[j:j+M] for x in A[j:j+M]]
    if B==As:
      print('Yes')
      sys.exit()
print('No')

Submission status: Wrong Answer

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: Wrong Answer

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

ans = False
for i in range(n-m):
    for j in range(n-m):
        bad = False 
        for k in range(m):
            for l in range(m):
                if grida[k+i][l+j] != gridb[k][l]:
                    bad = True
        if not bad:
            ans = True

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

Submission status: Wrong Answer

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

if N == M:
    if A == B:
        print("Yes")
    else:
        print("No")
    exit()
    
for a_i in range(N-M):
    if B[0] in A[a_i]:
        #スタート地点を記憶
        start = []
        for a_j in range(N-M+1):
            if B[0] == A[a_i][a_j:M+a_j]:
                start.append(a_j)
        print(start)
        for s in start:
            f = True
            for b_i in range(M):
                #記録したスタート地点の列で、他の行も一致するか確認
                if B[b_i] != A[a_i+b_i][s:s+M]:
                    f = False
            if f == True:
                print("Yes")
                exit()
print("No")

Submission status: Wrong Answer

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

for a_i in range(N-M):
    if B[0] in A[a_i]:
        #スタート地点を記憶
        start = []
        for a_j in range(N-M+1):
            if B[0] == A[a_i][a_j:M+a_j]:
                start.append(a_j)
        for s in start:
            f = True
            for b_i in range(M):
                #記録したスタート地点の列で、他の行も一致するか確認
                if B[b_i] != A[a_i+b_i][s:s+M]:
                    f = False
            if f == True:
                print("Yes")
                exit()
print("No")

Submission status: Wrong Answer

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

def search(h,w):
    for i in range(m):
        if not b[i]==a[h+i][w:w+m]:
            return False
    return True

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

Submission status: Wrong Answer

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

def chk(upper, left):
    for i in range(m):
        for j in range(m):
            if a[i+upper][j+left] != b[i][j]:
                return False
    return True

f = False
for upper in range(n-m):
    for left in range(n-m):
        if chk(upper, left):
            print('Yes')
            f = True
if not f:
    print('No')

Submission status: Wrong Answer

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

for i in range(N-M+1):
    for j in range(N-M+1):
        f=True
        for k in range(M):
            if A[i+k][i:M+i]==B[k]:continue
            else:
                f=False
                break
        if f:
            print("Yes")
            exit()
print("No")

Submission status: Wrong Answer

Solution code:
import sys,math,collections,itertools
input = sys.stdin.readline

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

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

for h in range(N-M):
    for w in range(N-M):
        cutA = [ A[h+i][w:w+M] for i in range(M)]
        if cutA == B:
            print('Yes')
            exit()
        else:
            continue
print('No')

Submission status: Wrong Answer

Solution code:
n,m = map(int, input().split())
a = [input() for _ in range(n)]
b = [input() for _ in range(m)]
ans = False
for pattern_h in range(n-m+1):
  for pattern_w in range(n-m+1):
    p = []
    for h in range(m):
      p.append(a[h][pattern_w:pattern_w+m])
    if p==b: ans = True
print('Yes' if ans else 'No')

Submission status: Wrong Answer

Solution code:
# 53
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


INF = float('inf')


n, m = LI()
a = SR(n)
b = SR(m)
ans = 'No'
for h in range(n - m + 1):
    for w in range(n - m + 1):
        is_ok = True
        for i in range(m):
            for j in range(m):
                if a[h + i][w + j] != b[i][j]:
                    is_ok = False
                    break
            if is_ok:
                ans = 'Yes'
                break
print(ans)