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

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
A = []
B = []
C = 0
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):
        if A[i][j:M+j+1] == B[0]:
            for k in range(i,i+M):
                for l in range(0,M):
                    if A[k][j:M+j+1] == B[l]:
                        C = C+1
if C == M:
    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())
while 1:
    try:
        s=input()
        b.append(s)
    except:  
        break
def check(i,j): 
    if i+m>=n or j+m>=n:
        return 0 
    a1=-1 
    for x in range(i,i+m):
        a1+=1 
        b1=0 
        for y in range(j,j+m):
            if b[a1][b1]!=a[x][y]:
                return 0 
            b1+=1 
    return 1 
for i in range(n):
    for j in range(n): 
        if check(i,j):
            print('Yes')
            exit()
print('No')
#print(a,b)

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)]
for i in range(n-m):
    for j in range(n-m):
        cnt=0
        for k in range(m):
            if a[j+k][i:i+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())
A=[list(input()) for _ in range(N)]
B=[list(input()) for _ in range(M)]

for x in range(N-M+1):
  for y in range(N-M+1):
    j=1
    for i in range(M):
      for j in range(M):
        if A[x+i][y+j]!=B[i][j]:
          j=0
    if j==1:
      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)]


for i in range(N-M+1):
    for j in range(N-M+1):
        if A[i][j] == B[0][0]:
            for x in range(M):
                ta = A[i][j:M:]
                if ta != B[x]:
                    break
                i += 1
            else:
                print('Yes')
                exit()
print('No')

Submission status: Wrong Answer

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

A=[[0 for i in range(n)] for j in range(n)]
B=[[0 for i in range(m)] for j in range(m)]

for j in range(n):
    a=input()    
    for i in range(n):
        A[j][i]=a[i]

for j in range(m):
    b=input()
    for i in range(m):
        B[j][i]=b[i]
        
ans=False        
for j in range(m):
    for i in range(m):
        if A[j][i] == B[j][i]:
            ans=True
        else:
            ans=False

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

Submission status: Wrong Answer

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

A=[[0 for i in range(n)] for j in range(n)]
B=[[0 for i in range(m)] for j in range(m)]

for j in range(n):
    a=input()    
    for i in range(n):
        A[j][i]=a[i]

for j in range(m):
    b=input()
    for i in range(m):
        B[j][i]=b[i]
        
ans=False        
for j in range(m):
    for i in range(m):
        if A[j][i] == B[j][i]:
            ans=True

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

Submission status: Wrong Answer

Solution code:
from itertools import permutations
def main():
  n, m = map(int, input().split())
  a=[]
  for i in range(n):
    a.append(input())
  b = ""
  for j in range(m):
    b += input()
  for i in range(n - m + 1):
    for j in range(n - m + 1):
      x = ""
      for k in range(m):
        x += a[j][i + k: i + k + m]
      if b == x:
        print("Yes")
        return
  print("No")
main()

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

flag = False
for i in range(n-m+1):
    for j in range(n-m+1):
        for k in range(m):
            for l in range(m):
                if A[i+k][j+l] == B[k][l]:
                    flag = True
                else:
                    flag = False
                    break

if flag:
    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)]
x=n-~-m
C=0
for i in range(x):
    for j in range(x):
        c=0
        for k in range(m):
            if a[i+k][j:j+x]==b[k]:
                c+=1
        if c==m:
            C+=1
print('YNeos'[C<1::2])

Submission status: Wrong Answer

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

tmp = []
for i in range(n):
    if i+m <= n:
        for j in range(m):
            tmp.append(a[i+j][i:i+m])
    if tmp == b:
        print('Yes')
        break
    tmp = []
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)]

tmp = []
for i in range(n):
    if i+m <= n:
        for j in range(m):
            tmp.append(a[j][i:i+m])
    if tmp == b:
        print('Yes')
        break
    tmp = []
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)]

tmp = []
for i in range(n):
    if i+m < n:
        for j in range(m):
            tmp.append(a[j][i:i+m])
    if tmp == b:
        print('Yes')
        break
    tmp = []
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 range(N-M):
  for j in range(A[i].count(B[0])-1):
    l = A[i].index(B[0], j)
    result = True
    for k in range(1, M):
      if B[k] != A[i+k][l:l+len(B[k])]:
        result = False
        break
    if result:
      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-M):
  for j in range(A[i].count(B[0])):
    l = A[i].index(B[0], j)
    result = True
    for k in range(1, M):
      if B[k] != A[i+k][l:l+len(B[k])]:
        result = False
        break
    if result:
      print("Yes")
      exit()
      
print("No")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
a,b = map(int,input().split())
li1 = [input() for i in range(a)]
li2 = [input() for i in range(b)]
#print(li1,li2)
for i in range(a-b+1):
    for j in range(a-b+1):
        flag = False
        for k in range(b):
            if li1[i+k][j:j+b] == li2[k]:
                flag = True
        if flag:
            print("Yes")
            exit()
print("No")

Submission status: Wrong Answer

Solution code:
a,b = map(int,input().split())
li1 = [input() for i in range(a)]
li2 = [input() for i in range(b)]
#print(li1,li2)
for i in range(a-b+1):
    for j in range(a-b+1):
        flag = False
        for k in range(b):
            if li1[i][i:b] == li2[k]:
                flag = True
        if flag:
            print("Yes")
            exit()
print("No")

Submission status: Wrong Answer

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

a = list(map(lambda _: input(), range(n)))
b = list(map(lambda _: input(), range(m)))

for y in range(0, n - (m - 1)):
    for x in range(0, n - (m - 1)):
        if all(map(lambda y_b: a[y + y_b][x:m] == b[y_b], range(m))):
            print('Yes')
            exit(0)

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): 
  c = a[i].find(b[0]) 
  if c != -1:
    for k in range(m-1):
      if a[c:c+m] != b[k+1]:
        break
    else:
      continue
    print("Yes")
    break
else:
  print("No")

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
A = ["" for i in range(N)]
for i in range(N):
    A[i] = input()
B = ["" for i in range(M)]
for i in range(M):
    B[i] = input()
    
matched = False
for i in range(N - M + 1):
    for j in range(N - M + 1):
        matched = True
        for k in range(M):
            for l in range(M):
                if A[i + k][j + l] != B[k][l]:
                    matched = False

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

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
a = []
for i in range(n):
    a0 = list(input())
    a.append(a0)
b = []
for i in range(m):
    b0 = list(input())
    b.append(b0)
now = [0,0]
ans = "No"
count = 0
while now[0] < n-m+1 and now[1] < n-m+1:
    if a[now[0] + count//m][now[1]+count%m] == b[count//m][count%m]:
        count += 1
    else:
        count = 0
        if now[1] < n-m+1:
            now[1] += 1
        else:
            now[1] = 0
            now[0] += 1
    if count == m*m:
        ans = "Yes"
        break
print(ans)

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
a = []
for i in range(n):
    a0 = list(input())
    a.append(a0)
b = []
for i in range(m):
    b0 = list(input())
    b.append(b0)
now = [0,0]
ans = "No"
count = 0
while now[0] < n-m and now[1] < n-m:
    if a[now[0] + count//m][now[1]+count%m] == b[count//m][count%m]:
        count += 1
    else:
        count = 0
        if now[1] < n-m:
            now[1] += 1
        else:
            now[1] = 0
            now[0] += 1
    if count == m*m:
        ans = "Yes"
        break
print(ans)

Submission status: Wrong Answer

Solution code:
N, M = tuple(map(int, input().split()))
A = [input() for _ in range(N)]
B = [input() for _ in range(M)]
for i in range(N-M):
    for j in range(N-M):
        flag = True
        for y in range(M):
            for x in range(M):
                if A[i+y][j+x] != B[y][x]:
                    flag = False
        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.append(list(input()))

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

ans = True

for i in range(M):
    if A[i] not in B[i]:
        ans = False
        break

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

Submission status: Wrong Answer

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

ans = True

for i in range(M):
    if not A[i] in B[i]:
        ans = False
        break

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

Submission status: Wrong Answer

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

test = A[:len(B)]

end = len(B)
top = 0

flag = False
k = -1
while k < len(A) - len(B):
    i = 0
    ans_ls = []
    while i < len(B):
        ans_ls.append(test[i][top:end])
        i += 1
    if ans_ls == B:
        flag = True
    k += 1
    top += 1
    end += 1

if flag:
    print('Yes')
elif A == B:
    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(list(input()))

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

test = A[:len(B)]

end = len(B)
top = 0

flag = False
k = -1
while k < len(A) - len(B):
    i = 0
    ans_ls = []
    while i < len(B):
        ans_ls.append(test[i][top:end])
        i += 1
    if ans_ls == B:
        flag = True
    k += 1
    top += 1
    end += 1

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 j in range(M)]

ans = True
for k in range(len(B)):
    print(B[k])
    print(A[k])
    if B[k] not in A[k]:
        ans = False
        break
print("Yes" if ans == True else "No")

Submission status: Wrong Answer

Solution code:
def resolve():
    n, m = map(int, input().split())
    a = list(input() for _ in range(n))
    b = list(input() for _ in range(m))
    if n == m:
        if a == b:
            print('Yes')
        else:
            print('No')
        exit()
    for i in range(n - m + 1):
        part = [ai[i:i + m] for ai in a[i:i + m]]
        if part == b:
            print("Yes")
            exit()
    print("No")


if __name__ == "__main__":
    resolve()

Submission status: Wrong Answer

Solution code:
def resolve():
    n, m = map(int, input().split())
    a = list(input() for _ in range(n))
    b = list(input() for _ in range(m))
    for i in range(n - m + 1):
        part = [ai[i:i + m] for ai in a[i:i + m]]
        if part == b:
            print("Yes")
            return 0
    print("No")


if __name__ == "__main__":
    resolve()

Submission status: Wrong Answer

Solution code:
def resolve():
    n, m = map(int, input().split())
    a = list(input() for _ in range(n))
    b = list(input() for _ in range(m))
    for i in range(n - m + 1):
        part = [ai[i:i + m] for ai in a][i:i + m]
        if part == b:
            print("Yes")
            return 0
    print("No")


if __name__ == "__main__":
    resolve()

Submission status: Wrong Answer

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

flag = False
for i in range(a-b+1):
    for j in range(b):
        if li1[i][j] == li2[i][j]:
            #print(li1[i][j],li2[i][j])
            flag = True
        else:
            flag = False
            break
    else:
        continue
    break
if flag:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
l_n=[]
l_m=[]
ans='No'
n,m=map(int,input().split())
for i in range(n):
	l_n.append(input())
for i in range(m):
	l_m.append(input())
#print(l_n)
#print(l_m)
for k in range(n-(m-1)):
	count=0
	for j in range(n):
		#print(l_n[j][k:k+m])
		if count==m:
			ans='Yes'
			break
		elif l_n[j][k:k+m] == l_m[count]:
			count+=1
		else:
			count=0
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)]

def isEmbeded(left, top):
    subA = [a[left: left + M] for a in A[top: top + M]]
    if subA == B:
        return True
    else:
        return False

for left in range(N - M):
    for top in range(N - M):
        if isEmbeded(left, top):
            print('Yes')
            exit()

print('No')

Submission status: Wrong Answer

Solution code:
import sys
def main():
    t = sys.stdin.readline()
    t1 = t.rstrip()
    t2 = t1.split(' ')
    stra = [] 
    for i in range(int(t2[0])):
        y = sys.stdin.readline()
        t = y.rstrip()
        stra += [t]
    strb = [] 
    for i in range(int(t2[1])):
        y = sys.stdin.readline()
        t = y.rstrip()
        strb += [t]
 
    suma = 0
    for x in strb:
        for y in stra:
            if x in y:
                suma +=1 
    if int(t2[0])*int(t2[1])==suma:
        print("Yes")
main()

Submission status: Wrong Answer

Solution code:
import sys
def main():
    t = sys.stdin.readline()
    t1 = t.rstrip()
    t2 = t1.split(' ')
    stra = [] 
    for i in range(int(t2[0])):
        y = sys.stdin.readline()
        t = y.rstrip()
        stra += [t]
    strb = [] 
    for i in range(int(t2[1])):
        y = sys.stdin.readline()
        t = y.rstrip()
        strb += [t]

    suma = 0
    for x in strb:
        for y in stra:
            if x in y:
                suma +=1 
    if int(t2[0])*int(t2[1])==suma:
        print("Yes")

main()

Submission status: Wrong Answer

Solution code:
import sys
def main():
    t = sys.stdin.readline()
    t1 = t.rstrip()
    t2 = t1.split(' ')
    stra = [] 
    for i in range(int(t2[0])):
        y = sys.stdin.readline()
        t = y.rstrip()
        stra += [t]
    strb = [] 
    for i in range(int(t2[1])):
        y = sys.stdin.readline()
        t = y.rstrip()
        strb += [t]

    suma = 0
    for x in strb:
        for y in stra:
            if x in y:
                suma +=1 
    if int(t2[0])*int(t2[1])==suma:
        print("yes")

main()

Submission status: Wrong Answer

Solution code:

import sys
def main():
    t = sys.stdin.readline()
    t1 = t.rstrip()
    t2 = t1.split(' ')
    stra = [] 
    for i in range(int(t2[0])):
        y = sys.stdin.readline()
        t = y.rstrip()
        stra += [t]
    strb = [] 
    for i in range(int(t2[1])):
        y = sys.stdin.readline()
        t = y.rstrip()
        strb += [t]

    suma = 0
    for x in strb:
        for y in stra:
            print(x,y)
            if x in y:
                suma +=1 
    if int(t2[0])*int(t2[1])==suma:
        print("yes")
    
    print(stra,strb)
main()

Submission status: Wrong Answer

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

def main():
    [N, M] = list(map(int, input().split()))
    A = [0 for i in range(N)]
    B = [0 for i in range(M)]
    for i in range(N):
        A[i] = input()
    for i in range(M):
        B[i] = input()
    # print(A)
    # print(B)

    def cmp(i, j):
        for k in range(M):
            if A[i+k][j:j+M] != B[k]:
                return False
        return True
        

    for i in range(N-M):
        for j in range(N-M):
            if cmp(i,j):
                print("Yes")
                return
    print("No")
    return

main()

Submission status: Wrong Answer

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

for y in range(n-m+1):
    for x in range(n-m+1):
        for j in range(m):
            if a[y+j][x:m+x] == b[j]:
                flag = True
print("No" if not flag else "Yes")

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 x in range(n-m+1):
    flag = False
    for y in range(n-m+1):
        for j in range(m):
            if a[y+j][x:m+x] == b[j]:
                flag = True
            else:flag = False
        if flag == True:
            print("Yes")
            exit()
print("No")

Submission status: Wrong Answer

Solution code:
h,w = map(int, input().split())
S = ['.' + input() + '.' for _ in range(h)]
S.insert(0,'.'*(w+2))
S.append('.'*(w+2))

for r in range(1, h+1):
    for c in range(1, w+1):
        if S[r][c] == '#':
            print('#', end='')
            continue
        else:
            count = 0
            count += S[r-1][c-1:c+2].count('#')
            count += S[r][c-1:c+2].count('#')
            count += S[r+1][c-1:c+2].count('#')
            print(count, end='')
    print()

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 ly in range(N):
    for lx in range(N):
        # 見ている範囲が NxN を超えている
        if ly+M-1 >= N or lx+M-1 >= N: continue

        # NxN を見ている範囲と MxM の match を探索
        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:
            ans = True

print("Yes" if match 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)]

pt_max = m * m

def b():
    for i in range(n-m):
        for j in range(n-m):
            pt = 0
            for k in range(m):
                for l in range(m):
                    if A[i+k][j+l] == B[k][l]:
                        pt += 1
            if pt == pt_max:
                return "Yes"
    return "No"

print(b())

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)]
flg = 0
for dx in range(N-M):
    for dy in range(N-M):
#        print(A[dy][dx:N-1-dx],B[dy])
        if all(A[dy+i][dx:dx+M]==B[i] for i in range(M)):
            flg =1
if flg == 1: 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)]
flg = 0
for dx in range(N-M):
    for dy in range(N-M):
#        print(A[dy][dx:N-1-dx],B[dy])
        if all(A[i+dy][dx:N-1-dx]==B[i] for i in range(M)):
            flg =1
if flg == 1: print("Yes")
else: print("No")

Submission status: Wrong Answer

Solution code:
t,*a=open(0);n,m=map(int,t.split());r=range(n-m+1)
print('YNeos'[all(a[n:]!=[t[j:j+m]for t in a[i:i+m]]for i in r for j in r)::2])

Submission status: Wrong Answer

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

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

    ok = False
    for sy in range(N-M+1):
        for sx in range(N-M+1):
            ok = True
            for y in range(M):
                for x in range(M):
                    if A[sy+y][sy+x] != B[y][x]:
                        ok = False
                        break
                if not ok:
                    break
            if ok:
                break
        if ok:
            break
    
    if ok:
        print("Yes")
    else:
        print("No")

if __name__ == "__main__":
    main()

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

#スタート地点を動かす
for i in range(N - M):
    for j in range(N - M):
        #あるスタート地点でAにBが含まれるかをチェック
        flag = True
        for x in range(M):
            for y in range(M):
                if A[i + x][j + y] != B[x][y]:
                    flag = False
                    break
            if flag == False:
                break
        if flag == True:
            print ('Yes')
            exit()

print ('No')

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
a=["" for _ in range(n)]
b=["" for _ in range(m)]
for i in range(n):
    a[i]=list(input())
for i in range(m):
    b[i]=list(input())
    
for i in range(n-m+1):
    for j in range(n-m+1):
        ans="Yes"
        for k in range(m):
            for l in range(m):
                if(b[k][l]!=a[i+k][j+l]):
                    ans="No"
        if(ans=="Yes"):
            break
print(ans)

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
a=["" for _ in range(n)]
b=["" for _ in range(m)]
for i in range(n):
    a[i]=list(input())
for i in range(m):
    b[i]=list(input())
    
for i in range(n-m+1):
    for j in range(n-m+1):
        ans="Yes"
        for k in range(m):
            if(b[k]!=a[i+k][j:j+m]):
                ans="No"
        if(ans=="Yes"):
            break
print(ans)

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
a=["" for _ in range(n)]
b=["" for _ in range(m)]
for i in range(n):
    a[i]=list(input())
for i in range(m):
    b[i]=list(input())
    
for i in range(n-m+1):
    ans="Yes"
    for j in range(m):
        for k in range(m):
            if(b[j][k]!=a[i+j][i+k]):
                ans="No"
    if(ans=="Yes"):
        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):
        cnt = 0
        for k in range(M): # yoko
            for l in range(M): # tate
                if A[k][l]!=B[k][l]:
                    break
                else:
                    cnt+=1
        if cnt == M*M:
            print('Yes')
            exit()             
print('No')

Submission status: Wrong Answer

Solution code:
n, m = map(int,input().split())
a, b = [''] * n, [''] * m
for i in range(n):
  a[i] = input()
for i in range(m):
  b[i] = input()
flag = False
for i in range(n - m + 1):
  count = 0
  for j in range(m):
    if b[j] in a[i + j]:
      count += 1
    if count == m:
      flag = True
  if flag:
    break
if flag:
  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)]

from itertools import permutations

def match(lt):
    for b_x, b_y in permutations(range(m), 2):
        a_x = lt[0] + b_x
        a_y = lt[1] + b_y
        if a[a_y][a_x] != b[b_y][b_x]:
            return False

    return True

cnt = 0
for i in range(n - m + 1):
    for j in range(n - m + 1):
        if match((i, j)):
            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)]

flag = 'No'
for i in range(N-M):
    for j in range(N-M):
        check = []
        for k in range(M):
            if A[i+k][j:j+M] == B[k]:
                check.append(1)
            else:
                check.append(-1)
        if sum(check) == M:
            flag = 'Yes'
print(flag)

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 b[0] == a[i][j:j+m]:
            for k in range(1, m):
                if b[k] != a[i + k][j:j+m]:
                    break
            print("Yes")
            exit()

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)]
j = 0
fi = fd = 0

#左上の検索
for i in range(n-m+1):
  if b[0] in a[i]:
    fi = i
    fd = a[i].find(b[0])
    
    for j in range(m):
      if b[j] != a[j+fi][fd:fd+m]:
        break
    print("Yes")
    exit()
    
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)]
j = 0
fi = fd = 0

#左上の検索
for i in range(n-m+1):
  if b[0] in a[i]:
    fi = i
    fd = a[i].find(b[0])
    
    for j in range(m):
      if b[j] != a[j+fi][fd:fd+m]:
        print("No")
        exit()
    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)]

ans='No'
for i in range(n-m+1):
    check=0
    for j in range(m):
        for k in range(n-m+1):
            if b[j] == a[i+j][k:k+m]:
                check+=1
                break
            else:
                continue
    if check==m:
        ans='Yes'
print(ans)

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

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

Submission status: Wrong Answer

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)])
P = np.zeros(B.shape,str)
a = 0
for i in range(n-m+1):
   for j in range(n-m+1):
      P= A[i:i+m,j:j+m]
      # print(P)
      if np.all(B==P):
         print("Yes")
         a = 1
         break

if a ==0:
   print("No")

Submission status: Wrong Answer

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)])
P = np.zeros(B.shape,str)
a = 0
for i in range(n-m+1):
   for j in range(n-m+1):
      # P= A[i:i+m,j:j+m]
      print(P)
      if np.all(B==P):
         print("Yes")
         a = 1
         break

if a ==0:
   print("No")

Submission status: Wrong Answer

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)])
P = np.zeros(B.shape,str)
a = 0
for i in range(n-m):
   for j in range(n-m):
      P= A[i:i+m,j:j+m]
      if np.all(B==P):
         print("Yes")
         a = 1
         break

if a ==0:
   print("No")

Submission status: Wrong Answer

Solution code:
import sys
import copy
import string
import  math
from _bisect import *
from collections import *
from operator import itemgetter
from math import factorial
"""
from fractions import gcd
def lcm(x, y):
    return (x * y) // gcd(x, y)
"""
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

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