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

A = [input() for n in range(N)]
B = [input() for m in range(M)]
for a in A:
    cnt = 0
    for b in B:
        if b in a:
            cnt += 1
        else:
            cnt = 0
        if cnt == M:
            print("Yes")
            exit()

print("No")

Submission status: Wrong Answer

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

A = [input() for n in range(N)]
B = [input() for m in range(M)]
for a in A:
    cnt = 0
    for b in B:
        if b in a:
            cnt += 1
        if cnt == M:
            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)]
row = 0
column = 0
flg = True
while True:
    if N < M+column:
        break
    row = 0
    while True:
        if N < M+row:
            break
        for i in range(M):
            for k in range(M):
                if B[i][k] == A[i+column][k+row]:
                    continue
                else:
                    flg = False
                    break
        if flg:
            print('Yes')
            exit()
        row += 1
    column += 1
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)]
row = 0
column = 0
flg = True
while True:
    if N < M+column:
        break
    row = 0
    while True:
        if N < M+row:
            break
        for i in range(M):
            for k in range(M):
                if B[i][k] == A[i+row][k+column]:
                    continue
                else:
                    flg = False
                    break
        if flg:
            print('Yes')
            exit()
        row += 1
    column += 1
print('No')

Submission status: Wrong Answer

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

for i in range(n - m + 1):
    a = True
    for j in range(n - m + 1):
        for k in range(m):
            if lstn[i + k][j : j + m] != lstm[k]:
                a = False
                break
        if a:
            print('Yes')
            quit()
print('No')

Submission status: Wrong Answer

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

for i in range(n - m + 1):
    a = False
    for j in range(n - m + 1):
        for k in range(m):
            if lstn[i + k][j : j + m] != lstm[k]:
                a = True
                break
        if a:
            print('Yes')
            quit()
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 = 0
for i in range(N-M+1):
  for j in range(N-M+1):
    for k in range(i,i+M):
      for l in range(j,j+M):
        if A[k][l] != B[k-i][l-j]:
          break
        if A[k][l] == B[k-i][l-j] and k == i+M-1 and l == j+M-1:
          ans = 1
    else:
      continue
    break
if ans == 0:
  print("No")
else:
  print("Yes")

Submission status: Wrong Answer

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

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(N: int, M: int, A: "List[str]", B: "List[str]"):
    for i in range(N-M):
        for j in range(N-M):
            # AとBが等しいか判定
            for k in range(M):
                for l in range(M):
                    if A[i+k][j+l] == B[k][l]:
                        continue
                    else:
                        break
                else:
                    continue
                break    
            else:
                print(YES)
                return

    print(NO)    
    return


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

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
if sys.platform == 'ios':
	sys.stdin = open('input_file.txt')
	

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

a = [str(input()) for i in range(n)]
b = [str(input()) for i in range(m)]

s = [ [0]*m for i in range(m) ]

ans = 0

for i in range(n-m+1):
	for j in range(n-m+1):
		for k in range(m):
			#print(i,j,k)
			s[k] = a[i+k][j:j+m]
		#print(s)
		
		if s == b :
			print(i,j,s)
			ans = ans +1

print('Yes' if ans >= 1 else 'No')

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
import numpy as np
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):
  if (A[i:i+M,i:i+M]==B).all():
    ans='Yes'
    break
    
print(ans)

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
import numpy as np
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):
  if (A[i:i+M,i:i+M]==B).all:
    ans='Yes'
    break
    
print(ans)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
a=[]
b=[]
ans=0
for i in range(n):
	a.append(input())
for i in range(m):
	b.append(input())
for i in range(n):
	for j in range(n-m):
		if a[i][j:j+m]==b[0]:
			for k in range(m):
				tans=1
				if i+k<n:
					if a[i+k][j:j+m]!=b[k]:
						tans=tans*0
			if tans==1:
				ans=1
print("Yes" if ans==1 else "No")

Submission status: Wrong Answer

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

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

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

def check(i, j):
    flag = True
    for u in range(m):
        x = area_a[i+u][j:j+n+1]
        if x != area_b[u][:]:
            flag = False
            break
        else:
            continue
    if flag is True:
        print('Yes')
        exit()

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

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 = "No"

for i in range(N - M + 1):
    for j in range(N - M + 1):
        c = 0
        for x in range(M):
            for y in range(M):
                if A[x + i][y + j] == B[x][y]:
                    c += 1
        if c == M * 2:
            ans = "Yes"
            break

print(ans)

Submission status: Wrong Answer

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

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

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

for i in range(n - m + 1):
    for j in range(n - m + 1):
        yesNo = 'Yes'
        for b_x in range(m):
            a_x = b_x + i
            for b_y in range(m):
                a_y = b_y + j
                if(a[a_x][a_y] != b[b_x][b_y]):
                    yesNo = 'No'

print(yesNo)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

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

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

A=np.asarray(A)
B=np.asarray(B)

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

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
S = [input() for _ in range(N)]
T = [input() for _ in range(M)]
ans = False
cnt = N - M
for i in range(cnt+1):
    for j in range(cnt + 1):
        tmp = T[0]
        check = S[i][j:M+j]
        key = 1
        if(check == tmp):
            for k in range(1,M):
                tmp = T[k]
                check =  S[i+k][j:M+j]
                if(check == tmp):
                    key += 1
        if(key == M):
            ans =True
            break

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

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
S = [input() for _ in range(N)]
T = [input() for _ in range(M)]
ans = False
cnt = N - M
for i in range(cnt+1):
    for j in range(cnt + 1):
        tmp = T[0]
        check = S[i][j+0:M+j]
        if(check == tmp):
            cnt = 1
            for k in range(1,M):
                tmp = T[k]
                check =  S[i+k][j+0:M+j]
                if(check == tmp):
                    cnt += 1
        if(cnt == M):
            ans =True
            break

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

Submission status: Wrong Answer

Solution code:
n,m = map(int, input().split())
a = []
b = []
for i in range(n):
    ai = input()
    a.append(ai)
for i in range(m):
    bi = input()
    b.append(bi)
flag = True    
for i in range(n-m+1):
    flag = True
    for k in range(n-m+1):
        for j in range(i,i+m):
        
            if a[j][k:k+m]!=b[j-i]:
                flag = False
                break
        if flag:
            break
    if flag:
        break
#print(i,k,flag)        
print("Yes" if flag else "No")

Submission status: Wrong Answer

Solution code:
#制約小さいのでハッシュ等不要
n,m = map(int, input().split())
a = []
b = []
for i in range(n):
    ai = input()
    a.append(ai)
for i in range(m):
    bi = input()
    b.append(bi)
flag = True    
for i in range(n-m):
    flag = True
    for j in range(i,i+m):
        for k in range(n-m):
            if a[j][k:k+m]!=b[j-i]:
                flag = False
                break
            if not flag:
                break
    if flag:
        break
        
print("Yes" if flag 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)]

for i in range(n-m+1):
	ans = "Yes"
	for j in range(m):
		sA = A[j][i:i+m]
		sB = B[j]
		# print(sA,sB)
		if sA != sB:
			ans = "No"
	if ans == 'Yes':
		break
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from functools import reduce
import copy
import math
from pprint import pprint
import collections
import bisect


sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def int_inputs(num_of_input):
    ins = [int(input()) for i in range(num_of_input)]
    return ins


def is_match(parent, child, pi, pj):
    for ci in range(len(child)):
        for cj in range(len(child[ci])):
            # c = child[ci][cj]
            # p = parent[pi+ci][pj+cj]
            if child[ci][cj] != parent[pi+ci][pj+cj]:
                return False
    return True


def solve(N, M, inputs):
    map_parent = list(map(list, inputs[:N]))
    map_child = list(map(list, inputs[N:]))

    for pi in range(0, N-M):
        for pj in range(0, N-M):
            if is_match(map_parent, map_child, pi, pj):
                return 'Yes'
    return 'No'


def string_to_int(string):
    return list(map(int, string.split()))


if __name__ == "__main__":
    [N, M] = string_to_int(input())
    ret = solve(N, M, inputs(N+M))
    print(ret)

Submission status: Wrong Answer

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

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

b_index = 0
for i in range(N):
    if B[b_index] in A[i]:
        b_index += 1
        if b_index == M:
            print('Yes')
            break
    else:
        b_index = 0
        if B[b_index] in A[i]:
            b_index += 1
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)]

b_index = 0
for i in range(N):
    if B[b_index] in A[i]:
        b_index += 1
    else:
        b_index = 0
    if b_index == M:
        print('Yes')
        break
else:
    print('No')

Submission status: Wrong Answer

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

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

SUM=0
for i in range(M):
    for j in range(M):
        if(B[i][j]=="#"):
            SUM+=1

for k in range(N):
    t=0
    for i in range(M):
        if(A[k][i]=="#"):
            t+=1
    C[k][i-M+1]=t
    for i in range(M,N):
        if(A[k][i]=="#"):
            t+=1
        if(A[k][i-M]=="#"):
            t-=1
        C[k][i-M+1]=t
for i in range(N):
    for j in range(N-M+1):
        for k in range(M):
            D[i][j]+=C[i][j+k]

for i in range(N-M+1):
    for j in range(N-M+1):
        if(D[i][j]==SUM):
            for k in range(M):
                for l in range(M):
                     if(A[i+k][j+l]==B[k][l]):
                         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)]
#i, j はBの左端
for i in range(n-m+1):
    ans = True
    for j in range(n-m+1):
        for k in range(m):
            if a[i + k][j:j+m] != b[k]:
                ans = False
        if ans == True:
            break
    else:
        continue
    break

if ans == 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)]
#i, j はBの左端
ans = 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]:
                ans = False
        if ans == True:
            break
    else:
        ans = True
        continue
    break

if ans == 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)]
#i, j はBの左端
ans = 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]:
                ans = False
        if ans == True:
            break
    else:
        continue
    break

if ans == 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)]
#i, j はBの左端
ans = True
for i in range(n-m):
    for j in range(n-m):
        for k in range(m):
            if a[i + k][j:j+m] != b[k]:
                ans = False
        if ans == True:
            break
    else:
        continue
    break

if ans == 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)]
#i, j はBの左端
ans = True
for i in range(n-m):
    for j in range(n-m):
        for k in range(m):
            if a[i + k][j:j+m] != b[k]:
                ans = False
        if ans == True:
            break
    if ans == True:
        break

if ans == 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)]
#i, j はBの左端
ans = True
for i in range(n-m):
    for j in range(n-m):
        for k in range(m):
            if a[i + k][j:j+m] != b[k]:
                ans = False
        if ans == True:
            break
    break

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

Submission status: Wrong Answer

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

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

def isSame(h, w):
    for lineA, lineB in zip_longest(A[h:], B, fillvalue=[]):
        for a, b in zip_longest(lineA[w:], lineB, fillvalue='?'):
            if a != b:
                return False
    return True

for h in range(N):
    for w in range(N):
        if isSame(h, w):
            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.append(input())
for i in range(M):
    B.append(input())
flag = 0
for i in range(N-M+1):
    for k in range(N-M+1):
        p = 1
        for j in range(i,i+M):
            a = A[j][k:k+M]
            b = B[j-i][k:k+M]
            if a != b:
                p = 0
                break
        if p == 1:
            flag = 1
        

if flag == 1:
    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.append(input())
for i in range(M):
    B.append(input())
ans = 0
for i in range(N-M+1):
    for k in range(N-M+1):
        p = 1
        for j in range(i,i+M):
            a = A[j][k:k+M]
            b = B[j-i][k:k+M]
            if a != b:
                p = 0
        ans += p

if ans > 0:
    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)]
for y in range(n-m):
    for x in range(n-m):
        failed = False
        for by in range(m):
            for bx in range(m):
                if a[x+bx][y+by] != b[bx][by]:
                    failed = True
        if failed == False:
            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)]
result = "No"


for i in range(N):
    count = 0
    ans = A[i].find(B[0])
    if not(ans == -1):
        count = count + 1
        for x in range(1,N):
            if i+x >= len(A) or x >= len(B):
                break
            ans1 = A[i+x].find(B[x])
            if ans == ans1:
                count = count + 1
        if count == M:
            result = "Yes"
            break


print(result)

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())
result = "No"


for i in range(N):
    count = 0
    ans = A[i].find(B[0])
    if not(ans == -1):
        count = count + 1
        for x in range(1,N):
            if i+x >= len(A) or x >= len(B):
                break
            ans1 = A[i+x].find(B[x])
            if ans == ans1:
                count = count + 1
        if count == M:
            result = "Yes"


print(result)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
Alist = [list(input()) for _ in range(N)]
Blist = [list(input()) for _ in range(M)]
from sys import exit
for i in range(N - M):
    for j in range(N - M):
        if Alist[i:i + M][j:j + M] == Blist:
            print("Yes")
            exit()
print("No")

Submission status: Wrong Answer

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

A = []
B = []
for _ in range(N):
    tmp = input()
    tmp = tmp.replace("#", "1")
    tmp = tmp.replace(".", "2")
    tmp = [int(i) for i in tmp]
    A.append(tmp)

for _ in range(M):
    tmp = input()
    tmp = tmp.replace("#", "1")
    tmp = tmp.replace(".", "2")
    tmp = [int(i) for i in tmp]
    B.append(tmp)

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

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

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

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
A=[]
B=[]
ans="No"
for _ in range(N):
  A.append(input().split())
for __ in range(M):
  B.append(input().split())
for i in range(N):
  for k in range(M):
    if B[k][0]  in A[i][0]:
       ans ="Yes"
    else:
      ans="No"
      
print(ans)

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
A=[]
B=[]
ans="Yes"
for _ in range(N):
  A.append(input().split())
for __ in range(M):
  B.append(input().split())
for i in range(N):
  for k in range(M):
    if B[k][0]  in A[i][0]:
       ans ="Yes"
    else:
      ans="No"
      
print(ans)

Submission status: Wrong Answer

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

hantei = False

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

Submission status: Wrong Answer

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

hantei = False

for i in range(N-M+1):
  for j in range(N-M+1):
    if (A[i:M+i,j:M+j] == B).all:
      hantei = True
      print(A[i:M+i,j:M+j])
print('Yes' if hantei 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)]

for X in range(N-M+1):
    for Y in range(N-M+1):
        flag=1
        for x in range(M):
            for y in range(M):
                if B[x][y]!=A[x+X][y+Y]:
                    flag=0
                    break
            if not flag:
                break
        if flag:
            print("Yes")
            exit()
print("NO")

Submission status: Wrong Answer

Solution code:
# ABC 054: B – Template Matching
n, m = [int(s) for s in input().split()]
a = []
b = []

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

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

is_contained = 'No'

for i in range(n - m + 1):
    if b[0] in a[i]:
        for j in range(m - i):
            if b[j] in a[j]:
                if a[j].index(b[j]) != a[i].index(b[i]):
                    break
        else:
            is_contained = 'Yes'
            break

print(is_contained)

Submission status: Wrong Answer

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

for p in range(N-M):
    for q in range(N-M):
        data=[[A[p+j][q+i] for i in range(M)]  for j in range(M)]
        if data == B:
            ans=True
            break
        else:
            ans=False
            continue
    break
if ans:print('Yes')
else:print('No')

Submission status: Wrong Answer

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


def check_in(add_tate, add_yoko):
    for A, B in zip(Alist[add_tate:add_tate + M], Blist):
        try:
            assert A[add_yoko:add_yoko + M] == B
        except AssertionError:
            return False
    return True


from sys import exit
for add_tate in range(N - M):
    for add_yoko in range(N - M):
        if check_in(add_tate, add_yoko):
            print("Yes")
            exit()
print("No")

Submission status: Wrong Answer

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

if n == 0 or m == 0:
  print('No')
  exit(0)

pic = []
for i in range(n):
  image = []
  for s in input():
    image.append(s)
  pic.append(image)

count = 0
template = []
for i in range(m):
  image = []
  for s in input():
    image.append(s)
    count += 1
  template.append(image)

answer = 0
for line_index, i in enumerate(template[:]):
  if line_index >= len(pic):
    continue
  
  for row_index, ib in enumerate(i):
    if row_index >= len(pic[line_index]):
      continue
    
    if pic[line_index][row_index] == template[line_index][row_index]:
      answer += 1

if count == answer:
  print('Yes')
else:
  print('No')

Submission status: Wrong Answer

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

image_a = []
for i in range(n):
  image = []
  for s in input():
    image.append(s)
  image_a.append(image)

count = 0
image_b = []
for i in range(m):
  image = []
  for s in input():
    image.append(s)
    count += 1
  image_b.append(image)

answer = 0
for line_index, i in enumerate(image_b[:]):
  if line_index >= len(image_a):
    continue
  
  for row_index, ib in enumerate(i):
    if row_index >= len(image_a[line_index]):
      continue
    
    if image_a[line_index][row_index] == image_b[line_index][row_index]:
      answer += 1

if count == answer:
  print('Yes')
else:
  print('No')

Submission status: Wrong Answer

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

image_a = []
for i in range(n):
  image = []
  for s in input():
    image.append(s)
  image_a.append(image)

count = 0
image_b = []
for i in range(m):
  image = []
  for s in input():
    image.append(s)
    count += 1
  image_b.append(image)

answer = 0
for line_index, i in enumerate(image_b[:]):
  if line_index > len(image_a):
    continue
  
  for row_index, ib in enumerate(i):
    if row_index > len(image_a[line_index]):
      continue
    
    if image_a[line_index][row_index] == image_b[line_index][row_index]:
      answer += 1

if count == answer:
  print('Yes')
else:
  print('No')

Submission status: Wrong Answer

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

image_a = []
for i in range(n):
  image = []
  for s in input():
    image.append(s)
  image_a.append(image)

count = 0
image_b = []
for i in range(m):
  image = []
  for s in input():
    image.append(s)
    count += 1
  image_b.append(image)

answer = 0
for line_index, i in enumerate(image_b[:]):
  if line_index > len(image_a):
    continue
  
  for row_index, ib in enumerate(i):
    if row_index > len(image_a[line_index]):
      continue
    
    if image_a[line_index][row_index] == image_b[line_index][row_index]:
      answer += 1

if count == answer:
  print('YES\n')
else:
  print('NO\n')

Submission status: Wrong Answer

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

image_a = []
for i in range(n):
  image = []
  for s in input():
    image.append(s)
  image_a.append(image)

count = 0
image_b = []
for i in range(m):
  image = []
  for s in input():
    image.append(s)
    count += 1
  image_b.append(image)

answer = 0
for line_index, i in enumerate(image_b[:]):
  if line_index > len(image_a):
    continue
  
  for row_index, ib in enumerate(i):
    if row_index > len(image_a[line_index]):
      continue
    
    if image_a[line_index][row_index] == image_b[line_index][row_index]:
      answer += 1

if count == answer:
  print('YES')
else:
  print('NO')

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
a = [[c for c in input()] for i in range(n)]
b = [[c for c in input()] for j in range(m)]
exist = False
for y in range(n):
    for x in range(n):
        if y+m-1 >= n or x+m-1 >= n: continue
        match = True
        for by in range(m):
            for bx in range(m):
                if a[y+by][x+bx] != b[by][bx]: match = False
            if match: exist = True
print('Yes' if exist else 'No')

Submission status: Wrong Answer

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

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

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

ans = "No"
for a in range(n - m + 1):
    for b in range(m):
        if img_b[b] in img_a[b+a]:
            if b == 0:
                index = img_a[a].index(img_b[0])
            current_index = img_a[b+a].index(img_b[b])
            
            if current_index != index:
                break
        else:
            break
    else:
        ans = "Yes"
        break

print(ans)

Submission status: Wrong Answer

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

#pat_match
def pat_match(Temp, temp_w, temp_h, Big_pic, ind_w, ind_h):
  for i in range(temp_h):
    for j in range(temp_w):
      if Temp[i][j] != Big_pic[i + ind_w][j + ind_h]:
        return False
    else:
      return True

#print(pat_match(B, 2, 2, A, 0, 0))
import sys
for i in range(0, n-m+1):
  for j in range(0, len(A[0]) - len(B[0]) + 1):
    if pat_match(B, len(B[0]), m, A, j, i):
      print("Yes")
      sys.exit()
else:
  print("No")

Submission status: Wrong Answer

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

#pat_match
def pat_match(Temp, temp_w, temp_h, Big_pic, ind_w, ind_h):
  for i in range(temp_h):
    for j in range(temp_w):
      if Temp[i][j] != Big_pic[i + ind_w][j + ind_h]:
        return False
    else:
      return True

#print(pat_match(B, 2, 2, A, 0, 0))
import sys
for i in range(0, n-m):
  for j in range(0, len(A[0]) - len(B[0])):
    if pat_match(B, len(B[0]), m, A, j, i):
      print("Yes")
      sys.exit()
else:
  print("No")

Submission status: Wrong Answer

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

#pat_match
def pat_match(Temp, temp_w, temp_h, Big_pic, ind_w, ind_h):
  for i in range(temp_h):
    for j in range(temp_w):
      if Temp[i][j] != Big_pic[i + ind_w][j + ind_h]:
        return False
    else:
      return True

#print(pat_match(B, 2, 2, A, 0, 0))

for i in range(0, n-m):
  for j in range(0, len(A[0]) - len(B[0])):
    if pat_match(B, len(B[0]), m, A, j, i):
      print("Yes")
      break
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)]

for i in a:
    for j in b:
        if j not in i:
            print('No')
            exec
print('Yes')

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)]
count=0
for i in range(n-m+1):
  for j in range(m):
    if B[j] in A[i+j]:
      count+=1
    else:
      count=0
      break
  if count==m:
    print('Yes')
    break
if count!=m:
  print('No')