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 = [int(i) for i in input().split()]
a = []
for i in range(N):
	array = input()
	a.append(array)
b = []
for i in range(M):
	line = input()
	b.append(line)
for i in range(N-M+1):
	for j in range(N-M+1):
		ans = 'Yes'
		for n in range(M):
			for m in range(M):
				if a[i+n][j+m] == b[n][m]:
					pass
					#print(i,j,n,m)
				else:
					ans = 'No'
print(ans)

Submission status: Wrong Answer

Solution code:
# import sys
# import math
# import decimal
# import queue
# import bisect
# import heapq
# import time
# import itertools
# import collections # queue
# from fractions import Fraction

mod = int(1e9+7)
INF = 1<<29
lINF = 1<<35

def main():
    n,m = map(int,input().split())
    a = [0] * n
    for i in range(n):
        a[i] = list(input())
    b = [0] * m
    for i in range(m):
        b[i] = list(input())
    for i in range(n-m):
        for j in range(n-m):
            tmp = True
            for k in range(m):
                for l in range(m):
                    if a[i+k][j+l]!=b[k][l]:
                        tmp = False
                        break
                if not tmp:
                    break
            if tmp:
                print("Yes")
                return
    print("No")
    return

if __name__=='__main__':
    main()

Submission status: Wrong Answer

Solution code:
#n = int(input())
#n,k = map(int,input().split())
#x = list(map(int,input().split()))


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

flg1 = 1
flg2 = 0
for i in range(N-M):
    if flg2:
        break
    for j in range(N-M):
        if flg2:
            break
        flg1 = 1
        
        for k in range(M):
            if not(flg1):
                break
            for l in range(M):
                if A[i+k][j+l]==B[k][l]:
                    continue
                else:
                    flg1 = 0
        else:
            if flg1:
                print("Yes")
                flg2 = 1
else:
    if not(flg2):
        print("No")

Submission status: Wrong Answer

Solution code:
#n = int(input())
#n,k = map(int,input().split())
#x = list(map(int,input().split()))


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

flg1 = 1
flg2 = 0
for i in range(N-M):
    if flg2:
        break
    for j in range(N-M):
        if flg2:
            break
        flg1 = 1
        
        for k in range(M):
            if not(flg1):
                break
            for l in range(M):
                if A[i+k][j+l]==B[k][l]:
                    continue
                else:
                    flg1 = 0
        else:
            if flg1:
                print("Yes")
                flg2 = 1
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 = "No"

for i in range(N):
  if B[0] in A[i]:
    b = A[i].index(B[0])
    for j in range(i,M):
      if B[j] not in A[j] or A[j].index(B[j]) != b:
        break
    else:
      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)]

if n == m:
    if a == b:
        print('Yes')
    else:
        print('No')
    exit()

for i in range(n-m+1):
    for j in range(n-m+1):
        c = [l[j:j+m] for l in a[i:i+m]]
        print(c)
        if c == b:
            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)]
ans = False
for h in range(n-m):
  for w in range(n-m):
    flag = 1
    for i in range(m):
      for j in range(m):
        if a[h+i][w+j] != b[i][j]:
          flag = 0
    if flag == 1:
      ans = True
      break
print("Yes" if ans else "No")

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/abc054/tasks/abc054_b

N, M = map(int, input().split())
A_list = []
for n in range(N):
    a = input()
    A_list.append(a)

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

diff = N - m

for i in range(diff):
    is_same = False
    for j in range(diff):
        for b in range(M):
            if B_list[b] == A_list[i + b][j: j + M]:
                is_same = True
            else:
                is_same = False
                break

    if is_same:
        print('Yes')
        exit()

    else:
        continue

print('No')


# 5 3
# ..#..
# ..#.#
# .....
# #..#.
# .....
# ...
# ..#
# #.#

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/abc054/tasks/abc054_b

N, M = map(int, input().split())
A_list = []
for n in range(N):
    a = input()
    A_list.append(a)

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

diff = N - m

for i in range(diff):
    is_same = False
    for j in range(diff):
        for b in range(M):
            if B_list[b] == A_list[i][j: j + M]:
                is_same = True
            else:
                is_same = False
                break
        else:
            continue
        break

    if is_same:
        print('Yes')
        exit()

    else:
        continue

print('No')


# 5 3
# ..#..
# ..#.#
# .....
# #..#.
# .....
# ...
# ..#
# #.#

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/abc054/tasks/abc054_b

N, M = map(int, input().split())
A_list = []
for n in range(N):
    a = input()
    A_list.append(a)

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

diff = N - m

for i in range(diff):
    is_same = False
    for j in range(diff):
        for b in range(M):
            if B_list[b] == A_list[i][j: j + M]:
                is_same = True
            else:
                is_same = False

    if is_same:
        print('Yes')
        exit()

    else:
        continue

print('No')


# 未完

Submission status: Wrong Answer

Solution code:
listA = []
listB = []
N, M = map(int, input().split())
for a in range(N):
    A = input()
    listA.append(A)
for b in range(M):
    B = input()
    listB.append(B)
kazu = N - M
answer=[]
for c in range(kazu+1):
    count=0
    for tate in range(M):
        for yoko in range(M):
            if listA[kazu+yoko][tate]==listB[yoko][tate]:
                count+=1
            else:
                pass
    answer.append(count)
for c in range(kazu+1):
    count=0
    for tate in range(M):
        for yoko in range(M):
            if listA[kazu+yoko][kazu+tate]==listB[yoko][tate]:
                count+=1
            else:
                pass
    answer.append(count)
for c in range(kazu+1):
    count=0
    for tate in range(M):
        for yoko in range(M):
            if listA[yoko][kazu+tate]==listB[yoko][tate]:
                count+=1
            else:
                pass
    answer.append(count)
suuji=0
for z in answer:
    if z==M**2:
        print('Yes')
        break
    else:
        suuji+=1
if suuji==len(answer):
    print('No')
else:
    pass

Submission status: Wrong Answer

Solution code:
n,m = map(int, input().split())
a = list()
for i in range(n):
    a.append(input())
b = list()
for i in range(m):
    b.append(input())
a_len = len(a[0])
b_len = len(b[0])
for i in range(a_len-b_len+1):
    check = True
    for j in range(n-m+1):
        if a[j][i:i+b_len] == b[j]:
            pass
        else:
            check = False
            break
    if check == True:
        print("Yes")
        exit()
print("No")

Submission status: Wrong Answer

Solution code:
listA = []
listB = []
N, M = map(int, input().split())
for a in range(N):
    A = input()
    listA.append(A)
for b in range(M):
    B = input()
    listB.append(B)
kazu = N - M
answer=[]
for c in range(kazu+1):
    count=0
    for d in range(M ):
        for e in range(M ):

            if listA[kazu + e][kazu + d] == listB[e][d]:
                count += 1

            else:
                continue
        answer.append(count)
suuji=0
for f in answer:
    if f==M*2:
        print('Yes')
        break
    else:
        suuji+=1
if suuji==len(answer):
    print('No')
else:
    pass

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

Submission status: Wrong Answer

Solution code:
line = input().split(' ')
N,M = int(line[0]),int(line[1])
A = []
B = []
exe = 0
for i in range(N):
  A.append(input())
for i in range(M):
  B.append(input())
for i in range(N-M+1):
  f = 0
  for j in range(N-M+1):
    if A[i][j:j+M] == B[0]:
      f = 1
      for k in range(M-1):
        if not A[i+k][j:j+M] == B[k]:
          f = 0
          break
    if f == 1:
      exe = 1
if exe == 0:
  print("No")
else:
  print("Yes")

Submission status: Wrong Answer

Solution code:
line = input().split(' ')
N,M = int(line[0]),int(line[1])
A = []
B = []
exe = 0
for i in range(N):
  A.append(input())
for i in range(M):
  B.append(input())
for i in range(N-M):
  f = 0
  for j in range(N-M):
    if A[i][j:j+M] == B[0]:
      f = 1
      for k in range(M-1):
        if not A[i+k][j:j+M] == B[k]:
          f = 0
          break
    if f == 1:
      exe = 1
if exe == 0:
  print("No")
else:
  print("Yes")

Submission status: Wrong Answer

Solution code:
line = input().split(' ')
N,M = int(line[0]),int(line[1])
A = []
B = []
exe = 0
for i in range(N):
  A.append(input())
for i in range(M):
  B.append(input())
for i in range(N-M):
  f = 0
  for j in range(N-M):
    if A[i][j:j+M] == B[0]:
      f = 1
      for k in range(M-1):
        if not A[i+k][j:j+M] == B[k]:
          f = 0
          break
    if f == 1:
      print("Yes")
      exe = 1
      break
  if exe == 1:
    break
if exe == 0:
  print("No")

Submission status: Wrong Answer

Solution code:
line = input().split(' ')
N,M = int(line[0]),int(line[1])
A = []
B = []
exe = 0
for i in range(N):
  A.append(input())
for i in range(M):
  B.append(input())
for i in range(N-M):
  f = 0
  for j in range(N-M):
    if A[i][j:j+M] == B[0]:
      for k in range(M-1):
        f = 1
        if not A[i+k][j:j+M] == B[k]:
          f = 0
          break
    if f == 1:
      print("Yes")
      exe = 1
      break
  if exe == 1:
    break
if exe == 0:
  print("No")

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
#import pprint
import re
import sys


N,M = list(map(int, input().rstrip().split()))
A_list = [input().strip() for _ in range(N)]
B_list = [input().strip() for _ in range(M)]

#print("N,M",N,M)
#print("A_list",A_list)
#print("B_list",B_list)
#-----

candidate=[]   # [[x,y]] start position of row(x) and column(y) 
for ia in range(N):
    #find_string = A_list[ia].find( B_list[0] )
    find_string = [m.start() for m in re.finditer( B_list[0] , A_list[ia])]
    
    
    #if find_string != -1 and N-ia >= M:
    if find_string != [] and N-ia >= M:
        candidate.append( [ia,find_string] )

#print("candidate",candidate)

if candidate == []:
    print("No")
    print("---No candidate")
    sys.exit()

check_column=""
#for start_r,start_c in candidate:
for start_r,start_c_list in candidate:
    for start_c in start_c_list:
    
        for ib in range(M):
            #print("start_r",start_r,"start_c",start_c,"ib",ib,"B_list",B_list[ib],"A_list",A_list[start_r + ib][start_c:(start_c + M)])

            #find_string = A_list[start_r + ib].find( B_list[ib] )
            if B_list[ib] ==  A_list[start_r + ib][start_c:(start_c + M)]:
                if ib == (M-1):
                    print("Yes")
                    sys.exit()
                else:
                    continue
            else:
                #print("break")
                break

else:
    print("No")

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
#import pprint
import sys


N,M = list(map(int, input().rstrip().split()))
A_list = [input().strip() for _ in range(N)]
B_list = [input().strip() for _ in range(M)]

#print("N,M",N,M)
#print("A_list",A_list)
#print("B_list",B_list)
#-----

candidate=[]   # [[x,y]] start position of row(x) and column(y) 
for ia in range(N):
    find_string = A_list[ia].find( B_list[0] )
    
    if find_string != -1 and N-ia >= M:
        candidate.append( [ia,find_string] )

#print("candidate",candidate)

if candidate == []:
    print("No")
#    print("---No candidate")
    sys.exit()

check_column=""
for start_r,start_c in candidate:
    for ib in range(M):
        find_string = A_list[start_r + ib].find( B_list[ib] )
        #print("start_r",start_r,"ib,find_string",ib,find_string)
        
        if ib ==0 and find_string != -1:
            check_column = find_string
        elif find_string == -1 or find_string != check_column:
            #print("break")
            break
        
        if ib == (M-1) and check_column != "":
            print("Yes")
            sys.exit()

else:
    print("No")

Submission status: Wrong Answer

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

N,M = list(map(int, input().rstrip().split()))
A_list = [input().strip() for _ in range(N)]
B_list = [input().strip() for _ in range(M)]
#-----

candidate=[]   # [[x,y]] start position of row(x) and column(y) 
for ia in range(N):
    find_string = A_list[ia].find( B_list[0] )
    
    if find_string != -1 and N-ia >= M:
        candidate.append( [ia,find_string] )

if candidate == []:
    print("No")
    sys.exit()

for start_r,start_c in candidate:
    for ib in range(M):
        find_string = A_list[start_r + ib].find( B_list[ib] )
        
        if ib ==0 and find_string != -1:
            check_column = find_string
        elif find_string == -1 or find_string != check_column:
            break
        elif ib == (M-1):
            print("Yes")
            sys.exit()

else:
    print("No")

Submission status: Wrong Answer

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

N,M = list(map(int, input().rstrip().split()))
A_list = [input().strip() for _ in range(N)]
B_list = [input().strip() for _ in range(M)]
#-----

candidate=[]   # [[x,y]] start position of row(x) and column(y) 
for ia in range(N):
    find_string = A_list[ia].find( B_list[0] )
    
    if find_string != -1 and N-ia >= M:
        candidate.append( [ia,find_string] )

if candidate == []:
    print("No")
    sys.exit()

for start_r,start_c in candidate:
    for ib in range(M):
        find_string = A_list[start_r + ib].find( B_list[ib] )
        if find_string == -1:
            break
        elif ib == (M-1):
            print("Yes")
            sys.exit()

else:
    print("No")

Submission status: Wrong Answer

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

for i in range(n-m+1):
  for j in range(n-m+1):
    c =0
    for k in range(m):
      for l in range(m):
        if a[i+k][j+l] == b[k][l]:
          c +=1
          print(c)
          
    print(c)
    if c == m**2:
      print("Yes")
      exit()
      
      
      
print("No")

Submission status: Wrong Answer

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

for i in range(n-m+1):
  for j in range(n-m+1):
    c =0
    for k in range(m):
      for l in range(m):
        if a[i+k][j+l] == b[k][l]:
          c +=1
          
 
  if c == m**2:
    print("Yes")
    exit()
      
      
      
print("No")

Submission status: Wrong Answer

Solution code:
n,m = map(int, input().split())
a = list()
b = list()
for i in range(n):
    a.append(list(input()))
for i in range(m):
    b.append(list(input()))
blen = len(b[0])
for i in range(n-m+1):
    for j in range(len(a[0])-len(b[0])+1):
        if [x[j:blen+i] for x in a[i:m+i]] == b:
            print("Yes")
            exit()
print("No")

Submission status: Wrong Answer

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

s1 = ""
s2 = ""

for i in range(n):
    string = str(input())
    s1 += string
    
for i in range(m):
    string = str(input())
    s2 += string

s1w = s1.count('.')
s1b = s1.count('#')
s2w = s2.count('.')
s2b = s2.count('#')

if (s1w >= s2w) and (s1b >= s2b):
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

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

ans = "No"
for y in range(N-M):
    for x in range(N-M):
        same = True
        for dy in range(M):
            for dx in range(M):
                if n[y+dy][x+dx] != m[dy][dx]:
                    same = False
                    break
            if not same:
                break
        if same:
            ans = "Yes"
            break
print(ans)

Submission status: Wrong Answer

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

"""考え方
端から端まで、で一致するパターンがないか全探索
"""

## 1.INPUTの取得
A = []
for n in range(N):
  A.append(input())
B = []
for m in range(M):
  B.append(input())


## 2.全探索
ans = 'No'
for i in range(N-M): ## Aの行
  for j in range(N-M): ## Aの列 
    ## 2-1.M,Nの一番上の行を比較
    if B[0] == A[i][j:j+M]:
      ## 下の行も比較
      for x in range(1,M):
        if B[x] != A[i+x][j:j+M]:
          break
      else:
        ans = 'Yes'
  

print(ans)

Submission status: Wrong Answer

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

"""考え方
端から端まで、で一致するパターンがないか全探索
"""

## 1.INPUTの取得
A = []
for n in range(N):
  A.append(input())
B = []
for m in range(M):
  B.append(input())


## 2.全探索
ans = 'No'
for i in range(N-M): ## Aの行
  for j in range(N-M): ## Aの列 
    ## 2-1.Mの要素とNの対象要素の比較
    if B[0] == A[i][j:j+M]:
      ## 再度、行単位で検証開始。
      for x in range(1,M):
        if B[x] == A[i+x][j:j+M]:
          ans = 'Yes'
  

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
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 = [a[s][i:i+m] for s in range(j,j+m)]
        if A == b:
            print("Yes")
            sys.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)]

si, sj = 0, 0
c = 0
while si < n - m:
    ni, nj = si, sj
    rest = m ** 2
    for i in range(m):
        nj = sj
        for j in range(m):
            # print(ni, nj, i, j)
            if a[ni][nj] != b[i][j]:
                break
            nj +=1
            rest -= 1
        ni += 1
        # print()
    if rest == 0:
        print("Yes")
        exit()
    sj += 1
    if sj > n - m:
        si += 1
        sj = 0

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

si, sj = 0, 0
c = 0
while si < n - m:
    ni, nj = si, sj
    rest = m ** 2
    for i in range(m):
        nj = sj
        for j in range(m):
            print(ni, nj, i, j)
            if a[ni][nj] != b[i][j]:
                break
            nj +=1
            rest -= 1
        ni += 1
        print()
    if rest == 0:
        print("Yes")
        exit()
    sj += 1
    if sj > n - m:
        si += 1
        sj = 0

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

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

ni, nj = 0, 0
for i in range(m):
    for j in range(m):
        if a[ni][nj] == b[m-1][m-1]:
            print("Yes")
            exit()
            break
        if a[ni][nj] != b[i][j]:
            break
        nj += 1
    ni += 1
else:
    print("No")

Submission status: Wrong Answer

Solution code:
#ABC054

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

c = False
exist = False

for i in range(n-m):
    for j in range(n-m):
        if a[i][j] == b[0][0]:
            c = True
            for k in range(m):
                for l in range(m):
                    if a[i+k][j+l] != b[k][l]:
                        c = False
            if c:
                exist = True

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

Submission status: Wrong Answer

Solution code:
import itertools
import math
import sys
import heapq
from collections import Counter
from collections import deque
from fractions import gcd
from functools import reduce
sys.setrecursionlimit(4100000)
from functools import lru_cache
INF = 1 << 60

#ここから書き始める
n, m = map(int, input().split())
a = [[""] * n] * n
b = [[""] * m] * m
for i in range(n):
    a[i] = [j for j in input()]
for i in range(m):
    b[i] = [j for j in input()]
# print(a)
# print(b)
for i in range(n - m):
    for j in range(n - m):
        flag = True
        for k in range(i, i + m):
            for l in range(j, j + m):
                if a[k][l] != b[k - i][l - j]:
                    flag = False
                    break
            if not flag:
                break
        if flag:
            print("Yes")
            sys.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 j in range(m)]

count=0

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

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
a = [list(input()) for i in range(n)]
b = [list(input()) for i in range(m)]
def check(x,y):
    ans = True
    for i in range(m):
        for j in range(m):
            if b[i][j] != a[i+x][j+x]:
                ans = False
    return ans

for i in range(n-m+1):
  for j in range(n-m+1):
      if check(i,j):
          print("Yes")
          exit()
print("No")

Submission status: Wrong Answer

Solution code:
import sys

input = sys.stdin.readline


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

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


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys

input = sys.stdin.readline


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

    for i in range(N - M):
        f = True
        for j in range(M):
            for k in range(M):
                if A[j + i][k + i] != B[j][k]:
                    f = False
                    break

        if f:
            print("Yes")
            return
    else:
        print("No")


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
a_li = [input() for i in range(N)]
b_li = [input() for i in range(M)]

for i in range(N - M):
    for j in range(N - M) :
        for k in range(M) :
            if a_li[i + k][j : j + M] != b_li[k] :
                break
            if k == M - 1:
                print("Yes")
                exit()
print("No")

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
a_li = [input() for i in range(N)]
b_li = [input() for i in range(M)]

for i in range(N - M):
    for j in range(N - M) :
        for k in range(i, M) :
            if a_li[k][j : j + M] != b_li[k] :
                break
            if k == M - 1:
                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())
c = 0
ans = "No"
for i in range(M):
    b.append(input())
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]:
                c += 1
        if c == M:
            ans = "Yes"
            break
print(ans)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
a = []
b = []
for i in range(N):
    a.append(input())
c, d = 0, 0
for i in range(M):
    b.append(input())
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]:
                c += 1
        if c == M:
            d = 1
            break
print("Yes" if d == 1 else "No")

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
a = []
b = []
for i in range(N):
    a.append(input())
c = 0
for i in range(M):
    b.append(input())
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]:
                c += 1
        if c == M:
            print("Yes")
            break
print("No")

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
a = []
b = []
for i in range(N):
    a.append(input())
c = 0
for i in range(M):
    b.append(input())
for i in range(N-M+1):
    for j in range(N-M+1):
        for k in range(M):
            s1 = a[i][j:j+M] 
            s2 = b[k]
            if s1 != s2:
                break
        else:
            print("Yes")
print("No")

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
A=[]
for i in range(N):
    a=input()
    A.append(a)
B=[]
for i in range(M):
    b=input()
    B.append(b)
a=""
b=""
for i in range(M):
    b=b+B[i]
l=[]
for i in range(N):
    if (i+M)>=N:
        break
    for j in range(N):
        if (j+M)>=N:
            break
        c=""
        for n in range(i,i+M):
            for m in range(j,j+M):
                    c+=A[n][m]
        l.append(c)
ok=False
for i in range(len(l)):
    if b==l[i]:
        ok=True
if ok:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
list = []
for i in range(N):
    list.append(input())
count = 0
for i in range(M):
    x = input()
    for j in list:
        count+=j.count(x)
print("No" if count==0 else "Yes")

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)]
#print(A,B)
count=0
ep=0
flag=0
for i in range(0,N-M+1,1):
    for j in range(0,N-M+1,1):
        for k in range(0,M,1):
            for l in range(0,M,1):
                if A[i+k][j+l]==B[k][l]:
                    count=count+1
        ep=ep+1
        #print(i,j)
    if count==M*M:
        flag=1
        break
    count=0
#print(ep)
if flag==1:
    print("Yes")
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)]
#print(A,B)
count=0
ep=0
flag=0
for i in range(0,N-M+1,1):
    for j in range(0,N-M+1,1):
        for k in range(0,M,1):
            for l in range(0,M,1):
                if A[i+k][j+l]==B[k][l]:
                    count=count+1
        ep=ep+1
        #print(i,j)
    if count==M*M:
        flag=1
        break
    count=0
print(ep)
if flag==1:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

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

fl = False
for i in range(N-M+1):
    for j in range(N-M+1):
        #print(i,j)
        #print(a[i][j:j+M])
        #print(a[i+1][j:j+M])
        if b==[a[k][j:j+M] for k in range(M)]:
            fl = True
            break
print('Yes') if fl else print('No')

Submission status: Wrong Answer

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

    i = 0
    j = 0
    snipped = []
    while i + M < N:
        for di in range(M):
            snipped.append(A[i+di][j:M+j])
        if B == snipped:
            print('Yes')
            break

        j += 1
        if j + M >= N:
            i += 1
            j = 0
    else:
        print('No')

    
if __name__ == '__main__':
    solve()

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)):
  c = []
  for j in range(M):
    if B[j] in A[i+j]:
      c.append(A[i+j].index(B[j]))
  if len(set(c)) == 1:
    ans = "Yes"
print(ans)

Submission status: Wrong Answer

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

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