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 = list(map(int, input().split()))
#a = list(map(int, input().split()))
a = []
b = []
for i in range(n):
    a.append(input())
for i in range(m):
    b.append(input())

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

Submission status: Wrong Answer

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

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

print("No")

Submission status: Wrong Answer

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


flag = 0
for i in range(n-m):
    for j in range(n-m):
        z = 0
        while a[i+z][j:j+m] == b[z]:
            if z == m-1:
                flag = 1
                break
            z += 1
            
if flag:
    print("Yes")
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] = input()
for i in range(M):
    B[i] = input()


mach = [-1] * M
for i in range(N-M):
    if B[0] in A[i]:
        for j in range(M):
            mach[j] = A[i+j].find(B[j])
if mach[0] != -1:
    tmp = mach[0]
    for i in range(1, M):
        if tmp != mach[i]:
            print("No")
            break
    else:
        print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/abc054/tasks/abc054_b
n, m = map(int, input().split())

A = []
for _ in range(n):
    row = list(input())
    A.append(row)

B = []
for _ in range(m):
    row = list(input())
    B.append(row)

def check(A, B, x, y):
    print(x, y)
    for i in range(m):
        for j in range(m):
            if B[i][j] == A[x + i][y + j]:
                continue
            else:
                return False
    return True

def main():
    for i in range(n):
        for j in range(n):
            if A[i][j] == B[0][0] and i + m <= n and j + m <= n:
                if check(A, B, i, j):
                    print('Yes')
                    return
    print('No')

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/abc054/tasks/abc054_b
n, m = map(int, input().split())

A = []
for _ in range(n):
    row = list(input())
    A.append(row)

B = []
for _ in range(m):
    row = list(input())
    B.append(row)

def check(A, B, x, y):
    for i in range(m):
        for j in range(m):
            if B[i][j] == A[x + i][y + j]:
                continue
            else:
                return False
    return True

def main():
    for i in range(n):
        for j in range(n):
            if A[i][j] == B[0][0] and i + m < n and j + m < n:
                if check(A, B, i, j):
                    print('Yes')
                    return
    print('No')

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
N,M=map(int, input().split())
N_str = []
M_str = []
for i in range(N):
  n=str(input())
  N_str.append(n)
for i in range(M):
  m=str(input())
  M_str.append(m)

equal = False
  
for i in range(N-M+1):
  for k in range(N-M+1):
    each_equal = True
    for l in range(M):
      each_equal = each_equal and (N_str[i+l][k:k+M] == M_str[l])
    equal = each_equal

print(["No","Yes"][equal])

Submission status: Wrong Answer

Solution code:
N,M=map(int, input().split())
N_str = []
M_str = []
for i in range(N):
  n=str(input())
  N_str.append(n)
for i in range(M):
  m=str(input())
  M_str.append(m)

equal = False
  
for i in range(N-M):
  for k in range(N-M):
    each_equal = True
    for l in range(M):
      each_equal = each_equal and (N_str[i+l][k:k+M] == M_str[l])
    equal = each_equal

print(["No","Yes"][equal])

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
L=[]
X=[]
for i in range(N):
	L.append(input())
for i in range(M):
	X.append(input())
for i in range(N-M+1):
	for j in range(N-M+1):
		if L[i][j]==X[0][0]:
			ans=0
			for x in range(M):
				for y in range(M):
					if L[x][y]==X[x][y]:
						ans+=1
			if ans==(M**2):
				print("Yes")
				exit()
print("No")

Submission status: Wrong Answer

Solution code:
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

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

ans = False
for ha in range(N):
    for wa in range(N):
        flag = True
        for hb in range(M):
            for wb in range(M):
                if ha + hb >= N or wa + wb >= N:
                    continue
                if A[ha + hb][wa + wb] != B[hb][wb]:
                    flag = False

        ans |= flag

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

Submission status: Wrong Answer

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

c = n - m + 1
for i in range(c):
    for j in range(c):
        flag = True
        for p in range(m):
            for q in range(m):
                if a[i+p][j+q] != b[p][q]:
                    flag = False
                    break
        if flag == True:
            break
if flag:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

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

c = n - m + 1
for i in range(c):
    for j in range(c):
        flag = True
        for p in range(m):
            for q in range(m):
                if a[i+p][j+q] != b[p][q]:
                    flag = False
        if flag == True:
            break
if flag:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

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

ans = 'No'
for i in range(0,n-m+1):
    for j in range(0,n-m+1):
        if a_l[i][j] == b_l[0][0]:
            for k in range(m):
                judge = a_l[i+k][j:j+m+1] == b_l[k]
                if judge == False:
                    break
            else:
                ans = 'Yes'

print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
N,M = [int(i) for i in input().split()]
big = []
small = []
flag = 0

for i in range(N):
    a = input()
    big.append(a)
for i in range(M):
    a = input()
    small.append(a)

for i in range(0,N-M+1):
    for j in range(0,N-M+1):
        if big[i][j] == small[0][0]:
            for k in range(M):
                for l in range(M):
                    if big[i+k][j+l] != small[k][l]:
                        continue
                    else:
                        if k == M-1 and l == M-1:
                            flag = 1
                            break


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

Submission status: Wrong Answer

Solution code:
N,M = [int(i) for i in input().split()]
big = []
small = []
flag = 0

for i in range(N):
    a = input()
    big.append(a)
for i in range(M):
    a = input()
    small.append(a)

for i in range(0,N-M+1):
    for j in range(0,N-M+1):
        if big[i][j] == small[0][0]:
            for k in range(M):
                for l in range(M):
                    if big[i+k][j+l] == small[k][l]:
                        if k == M-1 and l == M-1:
                            flag = 1

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

Submission status: Wrong Answer

Solution code:
def resolve():
	n, m = map(int, input().split())
	a = []
	sb = ""
	ans = "No"
	for _ in range(n):
		a.append(input())
	for _ in range(m):
		sb += input()
	for i in range(n-m):
		for j in range(n-m):
			sa = ""
			for k in range(m):
				sa += a[i+k][j:j+m]
			if sa == sb:
				ans = "Yes"
				break
	print(ans)
resolve()

Submission status: Wrong Answer

Solution code:
def resolve():
	n, m = map(int, input().split())
	a = []
	sb = ""
	ans = "No"
	for _ in range(n):
		a.append(input())
	for _ in range(m):
		sb += input()
	for i in range(n-m, n):
		sa = ""
		for j in range(n-m, n):
			sa += a[j][i:i+m]
		if sa == sb:
			ans = "Yes"
	print(ans)
resolve()

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


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


if __name__ == '__main__':
    resolve()

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


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):
        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]:
                        break
                else:
                    print("Yes")
                    exit()
    else:
        print("No")


if __name__ == '__main__':
    resolve()

Submission status: Wrong Answer

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

bl_left_top=bl[0][0]

ans=0
for i in range(n-m):
    for j in range(n-m):
        for k in range(m):
            if al[i+k][j:j+m]!=bl[k]:
                break
            if k==m-1:
                ans=1
    if ans==1:
        break

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

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
aaa = [input() for _ in range(n)]
bbb = [input() for _ in range(m)]
ans = False
for i in range(n - m + 1):
    for j in range(n - m + 1):
        flag = True
        for k in range(m):
            for l in range(m):
                if aaa[i + k][j + l] != bbb[k][l]:
                    flag = False
            if flag:
                ans = True
if ans:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
def judge(h, w):
    for i in range(b_h):
        for j in range(b_w):
            b_element = B[i][j]
            a_element = A[i+h][w+j]
            if a_element != b_element:
                return False
    return True

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

a_h, a_w = N, len(A[0])
b_h, b_w = M, len(B[0])
max_h, max_w = a_h - b_h, a_w - b_w
ans = "No"
# 二重ループで左上のスタート地点を全探索する
for i in range(a_h):
    for j in range(a_w):
        if j >= max_w or i >= max_h:
            continue
        if judge(i, j):
            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)]
flg=False

def check(i_, j_):
    cnt=0
    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:
        return True
    
for i in range(N-M+1):
    for j in range(N-M+1):
        if A[i][j] == B[0][0]:
            flg = check(i, j)
            
ans='Yes' if flg else 'No'
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)]
flg=False

def check(i, j):
    cnt=0
    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:
        return True
    
for i in range(N-M+1):
    for j in range(N-M+1):
        if A[i][j] == B[0][0]:
            flg = check(i, j)
            
ans='Yes' if flg else 'No'
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)]
lenB = M**2
flg=False

def check(i, j):
    cnt=0
    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:
        return True
    
for i in range(N-M+1):
    for j in range(N-M+1):
        if A[i][j] == B[0][0]:
            flg = check(i, j)
            
ans='Yes' if flg else 'No'
print(ans)

Submission status: Wrong Answer

Solution code:
import sys,os
from collections import defaultdict, deque
from math import ceil, floor
if sys.version_info[1] >= 5:
    from math import gcd
else:
    from fractions import gcd
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0
def main(given=sys.stdin.readline):
    input = lambda: given().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    MOD = 10**9+7

    N,M = LMIIS()
    A = [0]*N
    for i in range(N):
        A[i] = input()
    B = [0]*M
    for i in range(M):
        B[i] = input()
    if M > N:
        print('No')
        return
    for i in range(N-M):
        for j in range(N-M):
            found = True
            for k in range(M):
                for l in range(M):
                    if A[i+k][j+l] != B[k][l]:
                        found = False
                        break
                if not found:
                    break
            if found:
                print('Yes')
                return
    print('No')



if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys,os
from collections import defaultdict, deque
from math import ceil, floor
if sys.version_info[1] >= 5:
    from math import gcd
else:
    from fractions import gcd
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0
def main(given=sys.stdin.readline):
    input = lambda: given().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    MOD = 10**9+7

    N,M = LMIIS()
    A = [0]*N
    for i in range(N):
        A[i] = input()
    B = [0]*M
    for i in range(M):
        B[i] = input()
    if M > N:
        print('No')
        return
    for i in range(N-M):
        for j in range(N-M):
            for k in range(M):
                found = True
                for l in range(M):
                    if A[i+k][j+l] != B[k][l]:
                        found = False
                        break
                if found:
                    print('Yes')
                    return
    print('No')



if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

for i in range(m):
    flag=False
    b=input()
    for j in range(n):
        if b in a[j]:
            flag=True
if flag:
    print("Yes")
    exit()

print("No")

Submission status: Wrong Answer

Solution code:
import math  # noqa
import bisect  # noqa
import queue  # noqa


if __name__ == '__main__':
    N, M = map(int, input().split())
    A = [[a for a in input()] for _ in range(N)]
    B = [[b for b in input()] for _ in range(M)]

    ans = False
    for i in range(0, N - M + 1):
        for j in range(0, N - M + 1):
            res = True
            for k in range(0, M):
                for l in range(0, M):
                    if A[i + k][i + l] != B[k][l]:
                        res = False
            if res:
                ans = True
                break

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

Submission status: Wrong Answer

Solution code:
def match(x,y):
    re = True
    for i in range(M):
        for j in range(M):
            if A[i+x][j+y] != B[i][j]:
                re = False
    return re
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 = False

for i in range(N-M+1):
    for j in range(N-M+1):
        if match(j,i):
            ans = True
if ans==True:
    print("yes")
else:
    print("No")

Submission status: Wrong Answer

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

for i in range(n):
  a = input()
  
for j in range(m):
  b = input()
  
if b in a:
  print('Yes')
elif b == a:
  print('Yes')
else:
  print('No')

Submission status: Wrong Answer

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

for i in range(n):
  a = input()
  
for j in range(m):
  b = input()
  
if b in a:
  print('Yes')
else:
  print('No')

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline


def solve():
    N, M = map(int, rl().split())
    A = [input() for _ in range(N)]
    B = [input() for _ in range(M)]
    
    def check(y, x):
        res = True
        for dy in range(M):
            for dx in range(M):
                if A[y + dy][x + dx] != B[dy][dx]:
                    res = False
                    break
            if not res:
                break
        return res
    
    for sy in range(N - M):
        for sx in range(N - M):
            if check(sy, sx):
                print('Yes')
                exit()
    print('No')


if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
list_A = [ list(input()) for _ in range(n) ]
list_B = [ list(input()) for _ in range(m) ]
ans = "No"
for i in range(n-m):
    for j in range(n-m):
        cnt = 0
        for k in range(i, i+m):
            for l in range(j, j+m):
                if list_B[k-i][l-j] == list_A[k][l]:
                    cnt += 1
        if cnt == m*m:
            ans = "Yes"

print(ans)

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 y in range(n-m+1):
    for z in range(n-m):
        count = 0
        for p in range(m):
            if b[p] == a[y+p][z:(z+m)]:
                count += 1
                if count == m:
                    print("Yes")
                    exit()
            else:
                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)]
for y in range(n-m+1):
    for z in range(n-m):
        count = 0
        for p in range(m):
            if b[p] == a[y+p][z:(z+m)]:
                count += 1
                if count == m:
                    print("Yes")
                    exit()
            else:
                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)]
count = 0
for x in range (m):
    #print(x)
    for y in range(n-m):
        #print(y)
        for z in range(n-m):
            if b[x] == a[y][z:(z+m)]:
                for p in range(m-1):
                    if b[x+p] == a[y+p][z:(z+m)]:
                        count += 1
                        if count == m-1:
                            print("Yes")
                            exit()
else:
    print("No")

Submission status: Wrong Answer

Solution code:
icase=0
if icase==0:
    n,m=map(int,input().split())
    a=[""]*n
    for i in range(n):
        a[i]=input()
    b=[""]*m
    for i in range(m):
        b[i]=input()
#    n,m=3,2
#    a=['#.#', '.#.', '#.#']
#    b=['#.', '.#']
    for ni in range(n-m+1):
        for nj in range(n-m+1):
            yn=""
            for im in range(m):
                print(a[ni+im][nj:nj+m],b[im])
                if a[ni+im][nj:nj+m]!=b[im]:
                    yn="NG"
                    break
            if yn=="NG":
                continue
            if yn=="":
                yn="OK"
                break
        if yn=="OK":
            break
        else:
            continue
    if yn=="OK":
        print("Yes")
    else:
        print("No")

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
map_n = [0]*n
for i in range(n):
  map_n[i] = input()
map_m = [0]*m
for i in range(m):
  map_m[i] = input()

ans = False
for i in range(n-m+1):
  for j in range(n-m+1):
    flag = False
    for p in range(m):
      for q in range(m):
        if map_n[i+p][j+q] != map_m[p][q]:
          flag = True
          break
      if flag:
        break
    if flag:
      break
    else:
      ans = True
      break
  if ans:
    break

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

Submission status: Wrong Answer

Solution code:
import sys
IS = lambda: sys.stdin.readline().rstrip()
II = lambda: int(IS())
MII = lambda: list(map(int, IS().split()))
MIIZ = lambda: list(map(lambda x: x-1, MII()))

def main():
    n, m = MII()
    aa = bb = ''
    for _ in range(n): aa += IS()
    for _ in range(m): bb += IS()
    cnt = (-(-n//m))**2
    for j in range(n*n+1):
        if cnt == 0: break
        if j%n == n-m+1: continue
        t = ''
        for i in range(j-n,j-n+m):
            t += aa[i+n:i+n+m]
        if bb == t: print('Yes'); exit(0)
        cnt -= 1
    print('No')

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
IS = lambda: sys.stdin.readline().rstrip()
II = lambda: int(IS())
MII = lambda: list(map(int, IS().split()))
MIIZ = lambda: list(map(lambda x: x-1, MII()))

def main():
    n, m = MII()
    aa = bb = ''
    for _ in range(n): aa += IS()
    for _ in range(m): bb += IS()
    cnt = -(-n//m)**2
    for j in range(n*n+1):
        if cnt == 0: break
        if j%n == n-m+1: continue
        t = ''
        for i in range(j-n,j-n+m):
            t += aa[i+n:i+n+m]
        if bb == t: print('Yes'); exit(0)
        cnt -= 1
    print('No')

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
A=[0 for k in range(N)]
B=[0 for k in range(M)]
for i in range(N):
    A[i]=input()
for i in range(M):
    B[i]=input()
L=N-M
mark=0
for k in range(L+1):
    if mark==0:
        for l in range(L+1):
            count=0
            for i in range(M):
                for j in range(M):
                    if B[i][j]==A[i+k][j+l]:
                        count+=1
                    else:
                        break
        if count==M**2:
            print("Yes")
            mark=1
            break
    else:
        break
if mark==0:
    print("No")

Submission status: Wrong Answer

Solution code:
#!/usr/local/bin python
# -*- coding: utf-8 -*-
#
# ~/PycharmProjects/atcoder/B-TempleteMatching.py
#
n, m = map(int, input().split())
a = []
b = []
is_contain = True

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

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

print(a)
print(b)


for i in range(n-m+1):
    for j in range(n-m+1):
        count = 0
        for k in range(m):
            for l in range(m):
                if a[i+k][j+l] == b[k][l]:
                    count += 1

        # print(count)
        if count == m*m:
            print("Yes")
            exit()


print("No")

Submission status: Wrong Answer

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

def func():
    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]:
                        return False
                return True
    return False

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

Submission status: Wrong Answer

Solution code:
def main():
    N, M = map(int, input().split())
    target = list()
    pattern = list()

    for n in range(N):
        l = input()
        target.append(l)

    for m in range(M):
        l = input()
        pattern.append(l)

    find = False

    for i in range(N):
        for j in range(N):

            if i + (M - 1) <= N - 1 and j + (M - 1) <= N - 1 :
                find = True

                for k in range(M):
                    for l in range(M):
                        if target[i+k][j+l] != pattern[k][l]:
                            find = False
    if find:
        print("Yes")
    else:
        print("No")
main()

Submission status: Wrong Answer

Solution code:
def main():
    N, M = map(int, input().split())
    target = list()
    pattern = list()

    for n in range(N):
        l = input()
        target.append(l)

    for m in range(M):
        l = input()
        pattern.append(l)

    find = True

    for i in range(N):
        for j in range(N):

            if i + (M - 1) <= N - 1 and j + (M - 1) <= N - 1 :
                find = True

                for k in range(M):
                    for l in range(M):
                        if target[i+k][j+l] != pattern[k][l]:
                            find = False
    if find:
        print("Yes")
    else:
        print("No")
main()

Submission status: Wrong Answer

Solution code:
def main():
    N, M = map(int, input().split())
    target = list()
    pattern = list()

    for n in range(N):
        l = input()
        target.append(l)

    for m in range(M):
        l = input()
        pattern.append(l)

    find = True

    for i in range(N):
        for j in range(N):

            if i + M <= N - 1 and j + M <= N - 1 :
                find = True

                for k in range(M):
                    for l in range(M):
                        if target[i+k][j+l] != pattern[k][l]:
                            find = False
    if find:
        print("Yes")
    else:
        print("No")
main()

Submission status: Wrong Answer

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


def scan(i1, j1):
    for i2 in range(m):
        for j2 in range(m):
            if a[i1+i2][j1+j2] != b[i2][j2]:
                return False
    return True


def solve():
    for i1 in range(n-m):
        for j1 in range(n-m):
            if scan(i1, j1):
                return True
    return False


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

Submission status: Wrong Answer

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


def solve():
    for i1 in range(n-m):
        for j1 in range(n-m):
            nomatch = False
            for i2 in range(m):
                for j2 in range(m):
                    if a[i1+i2][j1+j2] != b[i2][j2]:
                        nomatch = True
                        break
                if nomatch: break
            if not nomatch:
                return True
    return False


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

Submission status: Wrong Answer

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


def solve():
    for i1 in range(n-m):
        for j1 in range(n-m):
            for i2 in range(m):
                for j2 in range(m):
                    if a[i1+i2][j1+j2] != b[i2][j2]:
                        return False
            return True
    return False


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