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())
dat_a = []
dat_b = []
for i in range(n):
    dat_a.append(input())
for i in range(m):
    dat_b.append(input())
if n == 1 and m == 1:
    if dat_a[0][0] == dat_b[0][0]:
        t = True
    else:
        t = False

for i in range(n - m + 1):
    for j in range(n - m + 1):
        t = True
        for k in range(m):
            #print(dat_a[i + k][j:j+m])
            #print(dat_b[k])
            if dat_a[i + k][j:j+m] != dat_b[k]:
                t = False
                continue
            if t:
                break
        if t:
            break
    if t:
        break

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

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
dat_a = []
dat_b = []
for i in range(n):
    dat_a.append(input())
for i in range(m):
    dat_b.append(input())
if n == 1 and m == 1:
    if dat_a[0][0] == dat_b[0][0]:
        t = True
    else:
        t = False
for i in range(n - m+1):
    for j in range(n - m + 1):
        t = True
        for k in range(m):
            #print(dat_a[i + k][j:j+m])
            #print(dat_b[k])
            if dat_a[i + k][j:j+m] != dat_b[k]:
                t = False
                continue
            if t:
                break
        if t:
            break
    if t:
        break

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

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
dat_a = []
dat_b = []
for i in range(n):
    dat_a.append(input())
for i in range(m):
    dat_b.append(input())
if n == 1 and m == 1:
    if dat_a[0][0] == dat_b[0][0]:
        t = True
    else:
        t = False
for i in range(n - m):
    for j in range(n - m + 1):
        t = True
        for k in range(m):
            #print(dat_a[i + k][j:j+m])
            #print(dat_b[k])
            if dat_a[i + k][j:j+m] != dat_b[k]:
                t = False
                continue
            if t:
                break
        if t:
            break
    if t:
        break

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

Submission status: Wrong Answer

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

for i in range(m):
    b+=[input()]
ans='No'
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]:
                break
        else:
            ans='Yes'
        if ans=='Yes':
            break
    if ans=='Yes':
        break

   
print(ans)

Submission status: Wrong Answer

Solution code:

n, m = [ int(v) for v in input().split() ]
s1 = ""
for i in range(n):
	s1 += input()[:-1]
s2 = ""
for i in range(m):
	s2 += input()[:-1]


candidate = []
for i in range(n-m+1):
	for j in range(n-m+1):
	
		s3 = "".join([ s1[i*n+j+k:i*n+j+m+k] for k in range(m) ])
		candidate.append(s3)

if s2 in candidate:
	print("Yes")
else:
	print("No")

Submission status: Wrong Answer

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

def create_Array(N):
    array = ['x' for i in range(N)]
    for i in range(N):
        x = [x for x in input()]
        array[i] = x
    return array

N_array = np.array(create_Array(N))
M_array = np.array(create_Array(M))

for i in range(N - M):
    for j in range(N - M):
        if ((N_array[j:j+M,i:i+M ] == M_array).all()):
            print("Yes")
            sys.exit()
else:
    print("No")

Submission status: Wrong Answer

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

def solve():
    N, M = list(map(int, input().split()))
    A = []
    B = []

    for i in range(N):
        A.append(list(input()))
    for i in range(M):
        B.append(list(input()))
    
    # 左上から順に走査する
    for i in range(N-M+1):
        for j in range(N-M+1):
            if A[i][j] == B[0][0]:
                is_contained = True
                for k in range(i, M):
                    for l in range(j, M):
                        if A[k][l] != B[k][l]:
                            is_contained = False
                            break
                    if not is_contained: break
                if is_contained:
                    print("Yes")
                    return
    print("No")
                


if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
a = []
for i in range(n):
    a.append(input())
b = []
for g in range(m):
    b.append(input())
#print(a)
#print(b)
ans = 'No'
for c in range(n-m+1):
    for d in range(n-m+1):
        C = [a[d+e][c:c+m] for e in range(m)]

if C == b:
    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)]
r=any(a[i:i+m][j:j+m]==b for i in range(n-m+1) for j in range(n-m+1))
print('Yes' if r else '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)]
frd = N-M

def check(A,B,i):
    for yoko in range(M):
        for tate in range(M):
            if A[tate+i][yoko+i] != B[tate][yoko]:
                return False
    return True
    
for i in range(frd+1):
    if check(A,B,i):
        print("Yes")
        exit()
print("No")

Submission status: Wrong Answer

Solution code:
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
# import numpy as np

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

N,M = 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()

ans = False
for y in range(N-M):
    for x in range(N-M):
        for i in range(M):
            for j in range(M):
                if A[x+i][y+j] == B[i][j]:
                    pass
                else:
                    break
            else:
                continue
            break
        else:
            ans = True

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

Submission status: Wrong Answer

Solution code:
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
# import numpy as np

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

N,M = 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()

ans = False
for y in range(N-M):
    for x in range(N-M):
        for i in range(M):
            for j in range(M):
                if A[x+i][y+j] == B[i][j]:
                    pass
                else:
                    break
            else:
                continue
            break
        else:
            ans = True
        break



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

Submission status: Wrong Answer

Solution code:
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
# import numpy as np

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

N,M = 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()

ans = False
for y in range(N-M):
    for x in range(N-M):
        for i in range(M):
            for j in range(M):
                if A[x+i][y+j] == B[i][j]:
                    pass
                else:
                    break
            else:
                break
        else:
            break
        ans = True

if ans:
    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)]
A_new = []
B_new = []
result = 0

for i in range(N):
    A_line = A[i]
    count = 1
    for j in A_line:
        A_new.append(str(i) + str(count) + j)
        count = int(count) + 1
for k in range(M):
    B_line = B[k]
    count = 1
    for l in B_line:
        B_new.append(str(k) + str(count) + l)
        count = int(count) + 1

for m in range(M ** 2):
    B_element = B_new[m]
    if B_element in A_new:
        result += 1

if result == M**2:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

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

frag = False
for i in range(N - K):
  for j in range(N - K):
    f = True
    for k in range(K):
      for l in range(K):
        if A[i + k][j + l] != B[k][l]:
          f = False
    if f:
      frag = True
print("YNeos"[not frag::2])

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

ans = "No"

for i in range(N-M+1):
    for j in range(N-M+1):
        C = []
        for k in range(j,N):
            C.append(A[k][j:])
        if B == C:
            ans = "Yes"

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
[n,m] = [int(i) for i in input().split()]
a = []
b = []
for i in range(n):
    a.append(input())
for i in range(m):
    b.append(input())
cnt = 0
flag = "No"
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]:
                    cnt += 1

    if cnt == m ** 2:
        flag = "Yes"
    else:
        cnt = 0
print(flag)

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):
    for j in range(n-m):
        bool = True
        for l in range(m):
            if A[i+l][j:j+m] == B[l]:
                continue
            else:
                bool = False
        if bool:
            print("Yes")
            exit()
print("No")

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
n = []
m = []
for i in range(N):
  s = str(input())
  row = []
  for j in range(N):
    if s[j] == "#":
      row.append(1)
    else:
      row.append(0)
  n.append(row)
for i in range(M):
  s = str(input())
  row = []
  for j in range(M):
    if s[i] == "#":
      row.append(1)
    else:
      row.append(0)
  m.append(row)
 
def search(a,b):
  mr = mc = 0
  for r in range(a, a+M):
    for c in range(b, b+M):
      if n[r][c] != m[mr][mc]:
        return False
      mc += 1
    mr += 1
    mc = 0
  return True

ans = 0
for i in range(N-M+1):
  for j in range(N-M+1):
    if search(i,j):
      ans = 1
      break
  if ans:
    break
if ans:
  print("Yes")
else:
  print("No")

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(1000000)

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

flag = False
for i in range(N-M):
    for j in range(N-M):
        flagx = True
        for x in range(M):
            if(A[i+x][j:j+M]!=B[x]):
                flagx = False
        if(flagx):
            flag = flag|flagx
            break

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

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
data = []
for i in range(N):
  data.append(input())
input_data=[]
for i in range(M):
  input_data.append(input())
flag_1 = False
for i in range(N - M + 1):
  for j in range(N - M + 1):
    flag = False
    for k in range(M):
      for l in range(M):
        if data[i+k][j+l] != input_data[k][l]:
          flag = True
    if flag:
      flag_1 = True

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

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
n = []
m = []
for i in range(N):
  s = str(input())
  row = []
  for j in range(N):
    if s[i] == "#":
      row.append(1)
    else:
      row.append(0)
  n.append(row)
for i in range(M):
  s = str(input())
  row = []
  for j in range(M):
    if s[i] == "#":
      row.append(1)
    else:
      row.append(0)
  m.append(row)
 
def search(a,b):
  mr = mc = 0
  for r in range(a, a+M):
    for c in range(b, b+M):
      if n[r][c] != m[mr][mc]:
        return False
      mc += 1
    mr += 1
    mc = 0
  return True

ans = 0
for i in range(N-M+1):
  for j in range(N-M+1):
    if search(i,j):
      ans = 1
      break
  if ans:
    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):
    A.append(input())
for j in range(M):
    B.append(input())
for i in range(N-M+1):
    m=0
    for k in range(M):
        c=0
        for h in range(len(B[0])):
            if B[k][h]==A[k][h+i]:
                c+=1
        if c==len(B[0]):
            m+=1
    if m==M:
        print('Yes')
        break
else:
    print('No')

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
A = [input() for _ in [0]*N]
B = [input() for _ in [0]*M]
endFlg = False
for i in range(N-M):
    for j in range(N-M):
        breakFlg = False
        for k in range(M):
            for l in range(M):
                if A[i+k][j+l] != B[k][l]:
                    breakFlg = True
                    break
            if breakFlg:break
        else:endFlg=True
        if endFlg: break
    if endFlg: break
if endFlg:print("Yes")
else:print("No")

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
A = [input() for _ in [0]*N]
B = [input() for _ in [0]*M]
endFlg = False
for i in range(N-M):
    for j in range(N-M):
        breakFlg = False
        for k in range(M):
            for l in range(M):
                if A[i+k][j+l] != B[k][l]:
                    breakFlg = True
                    break
            if breakFlg:break
        else:endFlg = True
    if endFlg: break
if endFlg:print("Yes")
else:print("No")

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
A = [input() for _ in [0]*N]
B = [input() for _ in [0]*M]
endFlg = False
for i in range(N-M):
    for j in range(N-M):
        breakFlg = False
        for k in range(M):
            for l in range(M):
                if A[i+k][j+l] != B[k][l]:
                    breakFlg = True
                    break
        if breakFlg: break

        else: endFlg = True
    if endFlg: break
if endFlg:print("Yes")
else:print("No")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
A = [''] * N
B = [''] * M

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

for i in range(N-M):
    for j in range(N-M):
        NO = False
        for x in range(M):
            a = A[i+x][j:j+M]
            if a != B[x]:
                NO = True
                break
        if not NO:
            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)]
point = 0

for i, j in zip(a, b):
    for k in range(m):
        if i[k] != j[k]:
            break
        else:
            point += 1

if point == m*m:
    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)]

includes = False
for r in range(N - M + 1):
    for c in range(N - M + 1):
        for i in range(M):
            for j in range(M):
                if A[r + i][c + j] != B[i][j]:
                    break
            else:
                continue
            break
        else:
            includes = True
            continue
        break

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

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
a = ['']*n
b = ['']*m
for i in range(n):
  a[i] = str(input())
for i in range(m):
  b[i] = str(input())
for i in range(n-m+2):
  c = a[0:m]
  for j in range(n-m+2):
    d = [e[j:j+m] for e in c]
    if b == d:
      print('Yes')
      exit()
else:
  print('No')

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
a = ['']*n
b = ['']*m
for i in range(n):
  a[i] = str(input())
for i in range(m):
  b[i] = str(input())
for i in range(n-m+2):
  c = a[0:m]
  for j in range(n-m+2):
    d = [e[j:j+m] for e in c]
    print(d)
    if b == d:
      print('Yes')
      exit()
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+1):
    for j in range(N-M+1):
        if A[i][j] == B[0][0]:
            flg = False
            for k in range(M):
                for l in range(M):
                    if A[i+k][j+l] != B[k][l]:
                        flg = False
                        break
                    flg = True
            if flg:
                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)]

for i in range(N-M+1):
    for j in range(N-M+1):
        if A[i][j] == B[0][0]:
            flg = False
            for k in range(M):
                for l in range(M):
                    if A[i+k][j+l] != B[k][l]:
                        break
                    flg = True
            if flg:
                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)]
cm = 0
for i in range(N):
    x = A[i].find(B[cm]) if cm == 0 else x
    if (x >= 0) and(B[cm] == A[i][x:x+M]):
        cm += 1
        if cm >= M:
            print('Yes')
            break
    else:
        cm = 0
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)]
cm = 0
for i in range(N):
    x = A[i].find(B[cm]) if cm == 0 else x
    lb = len(B[cm]) if cm == 0 else lb
    if (x >= 0) and (B[cm] == A[i][x:lb]):
        cm += 1
        if cm >= M:
            print('Yes')
            break
    else:
        cm = 0
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)]
cm = 0
for i in range(N):
    x = A[i].find(B[cm])
    lb = len(B[cm])
    if (x >= 0) and (B[cm] == A[i][x:lb]):
        cm += 1
        if cm >= M:
            print('Yes')
            break
    else:
        cm = 0
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)]
cm = 0
for i in range(N):
    x = A[i].find(B[cm])
    lb = len(B[cm])
    if (x >= 0) and (B[cm] in A[i][x:lb]):
        cm += 1
        if cm >= M:
            print('Yes')
            break
    else:
        cm = 0
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)]
cm = 0
pre = -1
for i in range(N):
    x = A[i].find(B[cm])
    if (x >= 0) and ((pre == -1) or (pre == x)):
        cm += 1
        if cm >= M:
            print('Yes')
            break
        pre = x
    else:
        cm = 0
        pre = -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)]
cm = 0
for i in range(N):
    if B[cm] in A[i]:
        cm += 1
        if cm >= M:
            print('Yes')
            break
    else:
        cm = 0
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)]
cm = 0
pre = -1
for i in range(N-M+1):
    x = A[i].find(B[cm])
    if (x >= 0) and ((pre == -1) or (pre == x)):
        cm += 1
        if cm >= M:
            print('Yes')
            break
        pre = x
    else:
        cm = 0
        pre = -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)]
cm = 0
for i in range(N-M+1):
    if B[cm] in A[i]:
        cm += 1
        if cm >= M:
            print('Yes')
            break
    else:
        cm = 0
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)]
cm = 0
for i in range(N-M+1):
    if B[cm] in A[i]:
        cm += 1
        if cm >= M:
            print('Yes')
            break
else:
    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):
    for j in range(N-M+1):
        ans = "Yes"
        for k in range(M):
            for l in range(M):
                if A[i+k][j+l] != B[k][l]:
                    ans = "No"
                    break
            break
        if ans == "Yes":
            break
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

def fn(a, b):
    for i in range(n-m):
        for j in range(n-m):
            if np.all(b == a[i:m+i,j:m+j]):
                return True
    return False

n, m = [int(i) for i in input().split()]
a = []
for i in range(n):
    res = []
    for j in input():
        if j == ".":
            res.append(1)
        elif j == "#":
            res.append(0)
    a.append(res)
b = []
for i in range(m):
    res = []
    for j in input():
        if j == ".":
            res.append(1)
        elif j == "#":
            res.append(0)
    b.append(res)

a = np.array(a)
b = np.array(b)

if fn(a, b):
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
# vim: set fileencoding=utf-8:


def main():
    N, M = map(int, input().split())  # 1 <= M <= N <= 50
    A = [input() for _ in range(N)]
    B = [input() for _ in range(M)]
    ct = 0
    flag = 0
    ans = 'No'

    # N^3だとしても、50*50*50=12,500で、pythonで計算が間に合いそう

    for B_row in B:
        flag = 0
        for A_row in A:
            for i in range(N-M):
                # M <= N であるから、B_row が A_rowに含まれているかを探索していく
                if B_row == A_row[i:M]:
                    ct += 1
                    flag = 1
                    break

            if flag == 1:
                break

    if ct == M:
        ans = 'Yes'

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys

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

for i in range(0, N):
    Ai = input()
    A.append(Ai)

for i in range(0, M):
    Bi = input()
    B.append(Bi)

found = True
for i_offset in range(0, N-M):
    found = True
    j_offset = A[i_offset].find(B[0])
    if j_offset < 0:
        continue
    for i in range(0, M):
        if A[i+i_offset][j_offset:j_offset+M] != B[i][0:M]:
            found = False
            break
    if found:
        print("Yes")
        sys.exit()

print("No")

Submission status: Wrong Answer

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

a=[input() for i in range(int(n))]
b=[input() for j in range(int(m))]
flag=0

for k in range(n-m):
  flag=1
  for l in range(m):
    if(b[l] in a[l][k:k+m]):
      continue
    else:
      flag=0
      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)]
for i in range(N - M):
    for j in range(N - M):
        for x in range(M):
            if A[j + x][i:i + M] != B[x]:
                break
        else:
            print("Yes")
            exit()
print("No")

Submission status: Wrong Answer

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

for i in range(n-m):
    for j in range(n-m):
        ans = True
        for k in range(m):
            for l in range(m):
                if not a[i+k][j+l] == b[k][l]:
                    ans = False
                    break
        if ans:
            print("Yes")
            exit()
print("No")

Submission status: Wrong Answer

Solution code:
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    n,m = f()
    a = [""] * n
    b = [""] * m
    for i in range(n):
        a[i] = input()
    
    for i in range(m):
        b[i] = input()
    
    if m>n:
        print("No")
    else:
        for i in range(0, n - m+1):
            for j in range(0, n - m+1):
                for k in range(m):
                    ok = True
                    if a[i+k][j:j+ m] != b[k]:
                        ok = False
                    if ok:
                        print("Yes")
                        return
        
        print("No")


solve()

Submission status: Wrong Answer

Solution code:
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    n,m = f()
    a = [""] * n
    b = [""] * m
    for i in range(n):
        a[i] = input()
    
    for i in range(m):
        b[i] = input()
    
    if m>n:
        print("No")
    else:
        for i in range(0, n - m+1):
            for j in range(0, n - m+1):
                for k in range(m):
                    if a[i+k][j:j+ m] == b[k]:
                        print("Yes")
                        return
        
        print("No")


solve()

Submission status: Wrong Answer

Solution code:
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    n,m = f()
    a = [""] * n
    b = [""] * m
    for i in range(n):
        a[i] = input()
    
    for i in range(m):
        b[i] = input()
    
    if m>n:
        print("No")
    else:
        for i in range(0, n - m):
            for j in range(0, n - m):
                for k in range(m):
                    if a[i+k][j:j+ m] == b[k]:
                        print("Yes")
                        return
        
        print("No")


solve()

Submission status: Wrong Answer

Solution code:
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    n,m = f()
    a = [""] * n
    b = [""] * m
    for i in range(n):
        a[i] = input()
    
    for i in range(m):
        b[i] = input()
    
    if m>n:
        print("No")
    else:
        for i in range(0, n - m):
            for j in range(0, n - m):
                for k in range(m):
                    if a[i][j:j+ m] == b[k]:
                        print("Yes")
                        return
        
        print("No")


solve()

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'
flag=False
for i in range(n-m+1):
    for j in range(n-m+1):
        if A[i][j:j+m]==B[0]:
            for k in range(1,m):
                if A[i+k][j:j+m]==B[k]:
                    ans='Yes'
                    flag=True
                else:
                    ans='No'
                    flag=False
                    break
    if flag:
        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)]

ans='No'
flag=False
for i in range(n-m):
    for j in range(n-m):
        if A[i][j:j+m]==B[0]:
            for k in range(1,m):
                if A[i+k][j:j+m]==B[k]:
                    ans='Yes'
                    flag=True
                else:
                    ans='No'
                    flag=False
                    break
    if flag:
        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)]

ans='No'
flag=False
for i in range(n-m):
    for j in range(n-m):
        if A[i][j:j+m]==B[0]:
            for k in range(1,m):
                if A[i+k][j:j+m]==B[k]:
                    ans='Yes'
                    flag=True
                else:
                    ans='No'
                    break
    if flag:
        break

print(ans)