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:
#coding:utf-8
import sys
a=[]
b=[]
N,M=map(int ,raw_input().split())
for i in range(N):
    a.append(list(raw_input()))
for i in range(M):
    b.append(list(raw_input()))

def chk(a,b,x,y):
    global M
    global N
    #x,y:左上座標
    #print x,y
    for row in range(M):
        for col in range(M):
            if a[row+y][col+x]!= b[row][col]:
                return False
    return True

f=False
for row in range(N-M):
    for col in range(N-M):
        if chk(a,b,col,row):
            f=True
if f:
    print "Yes"
else:print "No"

Submission status: Wrong Answer

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

f = [0]*m
for j in range(m):
    f[j] = a[j].find(b[j])

while -1 in f: f.remove(-1)
if len(f) == 0:
    print('No')
else:
    flag = 1
    for i in range(len(f)):
        if f[i] != f[i-1]:
            flag = 0
    if flag == 1:
        print('Yes')
    else:
        print('No')

Submission status: Wrong Answer

Solution code:
# coding=utf-8

if __name__ == '__main__':
    n, m = [int(s) for s in raw_input().split()]

    a = list()

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

    b = list()

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

    i = j = 0

    for a_ in a:
        if (i == 0 and b[0] in a_) or (0 < i and a_.find(b[i]) == j):
            j = a_.find(b[i])
            i += 1
            if i == m:
                print('Yes')
                exit(0)
        else:
            i = j = 0

    print('No')

Submission status: Wrong Answer

Solution code:
# coding=utf-8

if __name__ == '__main__':
    n, m = [int(s) for s in raw_input().split()]

    a = list()

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

    b = list()

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

    i = 0
    j = 0

    for a_ in a:
        if (i == 0 and b[0] in a_) or (0 < i and a_.find(b[i]) == j):
            j = a_.find(b[i])
            i += 1
            if i == m:
                print('Yes')
                exit(0)

    print('No')

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

res = False
for sy in range(N - M + 1):
    for sx in range(N - M + 1):
        ok = True
        for dy in range(M):
            y = sy + dy
            a = A[y][sx:sx + M]
            ok = ok and a == B[dy]
        res = res or ok
print("Yes" if ok else "No")

Submission status: Wrong Answer

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

if b in a:
    print "Yes"
else:
    print "No"

Submission status: Wrong Answer

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

found = False
for x in range(m-n+1):
  for y in range(m-n+1):
    for k in range(n):
      if a[x+k][y:y+m] != b[k]:
        break
    else:
      found = True
      break
  if found: break    
if found:
  print("Yes")
else:
  print("No")

Submission status: Wrong Answer

Solution code:
# coding=utf-8

if __name__ == '__main__':
    n, m = [int(s) for s in raw_input().split()]

    a = list()

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

    b = list()

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

    i = 0

    for a_ in a:
        if b[i] in a_ or b[0] in a_:
            if b[i] not in a_:
                i = 0

            i += 1

            if i == m:
                print('Yes')
                exit(0)

    print('No')

Submission status: Wrong Answer

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

import itertools


def judge(n, m, fig_a, fig_b):
    for dr, dc in itertools.product(range(n - m + 1), repeat=2):
        g = itertools.product(range(m), repeat=2)
        if all(fig_a[r0 + dr][c0 + dc] == fig_b[r0][c0] for r0, c0 in g):
            return True
    return False


def main():
    n, m = (int(x) for x in input().split())
    fig_a = [[c == "#" for c in input()] for _ in range(n)]
    fig_b = [[c == "#" for c in input()] for _ in range(m)]
    print("YES" if judge(n, m, fig_a, fig_b) else "NO")


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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


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


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

Submission status: Wrong Answer

Solution code:
# coding=utf-8

if __name__ == '__main__':
    n, m = [int(s) for s in raw_input().split()]

    a = list()

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

    b = list()

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

    i = 0

    for a_ in a:
        if b[i] in a_:
            i += 1
            if i == m:
                print('Yes')
                exit(0)

    print('No')

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

res = False
for sy in range(N - M + 1):
    for dy in range(M):
        y = sy + dy
        ok = True
        for i in range(N - M + 1):
            a = A[y][i:i + M]
            ok = ok and a == B[dy]
        res = res or ok
print("Yes" if ok else "No")

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

res = False
for sy in range(N - M + 1):
    for dy in range(M):
        y = sy + dy
        ok = True
        for i in range(N - M + 1):
            a = A[y][i:i+M]
            ok = ok and a == B[i]
        res = res or ok
print("Yes" if ok else "No")

Submission status: Wrong Answer

Solution code:
n, m = map(int, raw_input().split())
A = [raw_input() for i in xrange(n)]
B = [raw_input() for i in xrange(m)]

for i in xrange(n-m):
    for j in xrange(n-m):
        ok = 1
        for x in xrange(m):
            for y in xrange(m):
                if A[i+x][j+y] != B[x][y]:
                    ok = 0
        if ok:
            print "Yes"
            exit(0)
print "No"

Submission status: Time Limit Exceeded

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

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

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

ans = "No"
for a in range(n - m + 1):
    dup_a = img_a.copy()
    dup_b = img_b.copy()
    flag = True
    while flag:
        for b in range(m):
            if dup_b[b] in dup_a[b+a]:
                if b == 0:
                    index = dup_a[a].index(dup_b[0])
                current_index = dup_a[b+a].index(dup_b[b])
                if current_index == index:
                    continue
                elif current_index > index:
                    for line in dup_a:
                        line = line[current_index:]
                    break
                else:
                    for line in dup_a:
                        line = line[index:]
                    break
            else:   # if not substring in string.
                flag = False
                break

        else: # if not loop broken.
            ans = "Yes"
            break
        

print(ans)

Submission status: Time Limit Exceeded

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

for i in range(N-M+1):
    ind = -1
    while B[0] in A[i][ind+1:]:
        ind = A[i].find(B[0])
        ch = 0
        for j in range(1,M-1):
            if A[i][ind:ind+M+1] == B[j]:
                ch = 0
                continue
            else:
                ch = 1
                break
        if ch == 0:
            print('Yes')
            exit()
print('No')

Submission status: Time Limit Exceeded

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

for i in range(N):
    if B[0] in A[i]:
        ind = -1
        while B[0] in A[i][ind+1:]:
            ind = A[i].find(B[0])
            ch = 0
            for j in range(1,M-1):
                if A[i][ind:ind+M+1] == B[j]:
                    ch = 0
                    continue
                else:
                    ch = 1
                    break
            if ch == 0:
                print('Yes')
                exit()
print('No')

Submission status: Time Limit Exceeded

Solution code:
def check(y,x):
    if 0<=y<=n-1 and 0<=x<=n-1:
        return True
    return False

n,m=map(int,raw_input().split())
a=[raw_input() for _ in xrange(n)]
b=[raw_input() for _ in xrange(m)]
for i in xrange(n):
    for j in xrange(n):
        cnt=0
        for k in range(m):
            for l in xrange(m):
                if check(k+i,l+j):
                    if a[k+i][l+j]==b[k][l]:
                        cnt+=1
        if cnt==m*m:
            print("Yes")
            exit()
print("No")

Submission status: Accepted

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

ans="No"

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

print(ans)

Submission status: Accepted

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 = False
for i in range(n-m+1):
  for j in range(n-m+1):
    flag = True
    for k in range(m):
      if a[i+k][j:j+m] != b[k]:
        flag = False
    if flag:
      ans = True

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

Submission status: Accepted

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

for i in range(n - m + 1):
    for j in range(n - m + 1):
        ok = True
        for h in range(m):
            if not ok:
                break
            for w in range(m):
                # print(A[i + h][j + w])
                if A[i + h][j + w] != B[h][w]:
                    ok = False
                    break
        if ok:
            print("Yes")
            exit()
print("No")

Submission status: Accepted

Solution code:
import sys


N, M = [int(x) for x in 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):
        found = True
        for _i in range(M):
            for _j in range(M):
                if A[i + _i][j + _j] != B[_i][_j]:
                    found = False
                    break
            if not found:
                break
        if found:
            print('Yes')
            sys.exit()
print('No')

Submission status: Accepted

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

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

ans = False
for i in range(n - m + 1):
  for j in range(n - m + 1):
    for k in range(m):
      ll = ma[i + k][j : j + m]
      if ll != t[k]:
        break
    else:
      ans = True

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

Submission status: Accepted

Solution code:
from typing import List


def answer(n: int, m: int, a: List[str], b: List[str]) -> str:
    for i in range(n - m + 1):
        for j in range(n - m + 1):
            if a[i][j:j + m] == b[0]:
                matched_lines = 1
                for k in range(1, m):
                    if a[i + k][j:j + m] == b[k]:
                        matched_lines += 1
                    else:
                        break
                if matched_lines == m:
                    return 'Yes'

    return 'No'


def main():
    n, m = map(int, input().split())
    a = [input() for _ in range(n)]
    b = [input() for _ in range(m)]
    print(answer(n, m, a, b))


if __name__ == '__main__':
    main()

Submission status: Accepted

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):
    flag=1
    for k in range(M):
      if A[i+k][j:j+M]!=B[k]:
        flag=0
    if flag:
      print("Yes")
      exit()
print("No")

Submission status: Accepted

Solution code:


def main():
    n, m = map(int, input().split())
    a = ['' for i in range(n)]
    b = ['' for i in range(m)]
    for i in range(n):
        a[i] = input()
    for i in range(m):
        b[i] = input()
    for i1 in range(n - m + 1):
        for i2 in range(n - m + 1):
            fl = True
            for j in range(m):
                for k in range(m):
                    if a[i1 + j][i2 + k] != b[j][k]:
                        fl = False
            if fl:
                print("Yes")
                exit(0)
    print("No")


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
A = [list(input()) for i in range(n)]
B = [list(input()) for i in range(m)]
for i in range(n-m+1):
  for j in range(n-m+1):
    flag = True
    for k in range(m):
      if A[k+j][i:i+m] != B[k][:]:
        flag = False
        break
    if flag:
      print("Yes")
      quit()
else:
  print("No")

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
#import string
#from collections import defaultdict, deque, Counter
#import bisect
#import heapq
#import math
#from itertools import accumulate
#from itertools import permutations as perm
#from itertools import combinations as comb
#from itertools import combinations_with_replacement as combr
#from fractions import gcd
#import numpy as np

stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)
MIN = -10 ** 9
MOD = 10 ** 9 + 7
INF = float("inf")
IINF = 10 ** 18

def solve():
    n,m = map(int, stdin.readline().rstrip().split())
    #l = list(map(int, stdin.readline().rstrip().split()))
    #numbers = [[int(c) for c in l.strip().split()] for l in sys.stdin]
    a = [stdin.readline().rstrip() for _ in range(n)]
    b = [stdin.readline().rstrip() for _ in range(m)]

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






if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
def f():
    n, m = map(int, input().split())
    a = [list(input()) for i in range(n)]
    b = [list(input()) for j in range(m)]
    for p in range(n - m + 1):
        for q in range(n - m + 1):
            cnt = 0
            for x in range(m):
                for y in range(m):
                    if a[x+p][y+q] == b[x][y]:
                        cnt += 1
                        if cnt == m*m:
                            return "Yes"
                    else:
                        break
    return "No"
print(f())

Submission status: Accepted

Solution code:
lst = input().split()
N = int(lst[0])
M = int(lst[1])

A = []
B = []

for i in range(N):
   A.append(input())

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

if A == B:
   print('Yes')
   exit()

for x in range(N-M):
   for y in range(N-M):
      count = 1
      for i in range(M):
         if A[y+i][x:x+M] != B[i]:
            count = 0
      if count == 1:
         print('Yes')
         exit()

print('No')

Submission status: Accepted

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):
  if B[i] in A[i]:
    for j in range(m-1):
      if B[i+j] not in B[i+j]:
        print("No")
        exit()
    print("Yes")
    exit()
  else:
    print("No")
    exit()

Submission status: Accepted

Solution code:
from sys import exit
n, m = map(int, input().split())
A = [input() for _ in range(n)]
B = [input() for _ in range(m)]
for x, a in enumerate(A):
    if x > n - m + 1:
        break
    for i in range(n - m + 1):
        if a[i: i + m] == B[0]:
            for j in range(m):
                if A[x + j][i: i + m] != B[j]:
                    break
            else:
                print("Yes")
                exit()
print("No")

Submission status: Accepted

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

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

Submission status: Accepted

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

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

idx = [0, 0]
while True:
    if idx[0] == N - 1 and idx[1] == N - 1:
        break
    if A[idx[0]][idx[1]] == B[0][0]:
        check = False
        for i in range(M):
            for j in range(M):
                if 0 <= idx[0] + i < N and 0 <= idx[1] + j < N:
                    if A[idx[0] + i][idx[1] + j] != B[i][j]:
                        check = True
                        break
                else:
                    check = True
                    break
            if check:
                break

        if not check:
            print('Yes')
            exit()
    if idx[1] < N - 1:
        idx[1] += 1
        continue
    else:
        idx[0] += 1
        idx[1] = 1
        continue

if A[-1][-1] == B[0][0] and M == 1:
    print('Yes')
    exit()

print('No')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
A = [input() for i in range(n)]
B = [input() for i in range(m)]
 
flag = False
for i in range(n-m+1):
    for j in range(n-m+1):
        flag = True
        for k in range(m):
            if B[k] != A[i+k][j:j+m]:
                flag = False
        if flag:
            print("Yes")
            exit()
print("No")

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
A = []
B = []
clear = 0
same = 0
for i in range(N):
    A.append(str(input()))
for i in range(M):
    B.append(str(input()))

for i in range(N - M + 1):
    for j in range(N - M + 1):
        same = 0
        for k in range(M):
            if A[i + k][j: j + M] == B[k]:
                same += 1
            else:
                break
        if same == M:
            clear = 1
            break

if clear == 1:
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

check = False

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

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

Submission status: Accepted

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+1):
  if b[i] in a[i]:
    for x in range(m-1):
      if b[i+x] not in a[i+x]:
        print("No")
        exit()
    print("Yes")
    exit()
  else:
    print("No")
    exit()

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
A=[input() for i in range(N)]
B=[input() for i in range(M)]
ans = "Yes"
for i in A:
  for j in B:
    if j not in i:
      ans = "No"
print(ans)

Submission status: Accepted

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

def detect(i, j):
  flag = True
  for k in range(len(b)):
    for l in range(len(b)):
      if i+k >= n or j+l >= n or a[i+k][j+l] != b[k][l]:
        flag = False
        break
    if not flag:
      break
  return flag
  
ans = "No"
for i in range(len(a)):
  for j in range(len(a)):
    if detect(i, j):
      ans = "Yes"
      break
  if ans == "Yes":
    break
print(ans)

Submission status: Accepted

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

success = 0
for i in range(n - m + 1):
    fail = 0
    for j in range(n - m + 1):
        fail = 0
        for ii in range(m):
            for jj in range(m):
                if b[ii][jj] == a[i + ii][j + jj]:
                    continue
                else:
                    fail = 1
                    break
            if fail == 1:
                break
        else:
            success = 1
            print('Yes')
            break
    if success == 1:
        break
else:
    if fail == 1:
        print('No')

Submission status: Accepted

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):
        flg = True
        for k in range(M):
            for l in range(M):
                flg = flg & (B[k][l] == A[i+k][j+l])
        
        if flg:
            ans = 'Yes'
            print(ans)
            exit()

ans = 'No'
print(ans)

Submission status: Accepted

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

match_cnt = 0
for i in range(N - M + 1):
    for j in range(N - M + 1):
        flag = True
        for y in range(M):
            if A[y + i][j:j + M] != B[y]:
                flag = False
        if flag:
            match_cnt += 1

if match_cnt > 0:
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

match_cnt = 0
for i in range(N - M + 1):
    for j in range(N - M + 1):
        flag = True
        for y in range(M):
            for x in range(M):
                if A[y + i][x + j] != B[y][x]:
                    flag = False
        if flag:
            match_cnt += 1

if match_cnt > 0:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
A=[input()for _ in range(N)]
B=[input()for _ in range(M)]
print('Yes'if any([A[i+k][j:j+M]for k in range(M)]==B for i in range(N-M+1)for j in range(N-M+1)) else'No')

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
A = [list(input()) for _ in range(N)]
B = [list(input()) for _ in range(M)]
for i in range(N-M+1):
    for j in range(N-M+1):
        c = 1
        for k in range(M):
            if A[i+k][j:j+M] != B[k]:
                c = 0
        if c:
            print('Yes')
            exit()
print('No')

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
A=list(list(input()) for _ in range(N))
B=list(list(input()) for _ in range(M))
flag=False
for i in range(0,N-M+1):
    for j in range(0,N-M+1):
        sub=True
        for x in range(0,M):
            for y in range(0,M):
                if A[i+x][j+y]!=B[x][y]:
                    sub=False
        flag=flag or sub
if flag:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def v(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")
al = "abcdefghijklmnopqrstuvwxyz"
AL = al.upper()

n,m = I()
a = []
b = []

for _ in range(n):
    a += [list(input())]
for _ in range(m):
    b += [list(input())]

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
from sys import exit
from collections import deque
from bisect import bisect_left, bisect_right, insort_left, insort_right #func(リスト,値)
from heapq import heapify, heappop, heappush
from itertools import product, permutations, combinations, combinations_with_replacement
from functools import reduce
from math import sin, cos, tan, asin, acos, atan, degrees, radians

sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7

def lcm(x,y):
    return x*y//gcd(x,y)
def lgcd(l):
    return reduce(gcd,l)
def llcm(l):
    return reduce(lcm,l)
def powmod(n,i,mod):
    return pow(n,mod-1+i,mod) if i<0 else pow(n,i,mod)
def div2(x):
    return x.bit_length()
def div10(x):
    return len(str(x))-(x==0)
def perm(n,mod=None):
    ans = 1
    for i in range(1,n+1):
        ans *= i
        if mod!=None:
            ans %= mod
    return ans
def intput():
    return int(input())
def mint():
    return map(int,input().split())
def lint():
    return list(map(int,input().split()))
def ilint():
    return int(input()), list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)
def ston(c, c0='a'):
    return ord(c)-ord(c0)
def ntos(x, c0='a'):
    return chr(x+ord(c0))
class counter(dict):
    def __init__(self, *args):
        super().__init__(args)
    def add(self,x,d=1):
        self.setdefault(x,0)
        self[x] += d
class comb():
    def __init__(self, n, mod=None):
        self.l = [1]
        self.n = n
        self.mod = mod
    def get(self,k):
        l,n,mod = self.l, self.n, self.mod
        k = n-k if k>n//2 else k
        while len(l)<=k:
            i = len(l)
            l.append(l[i-1]*(n+1-i)//i if mod==None else (l[i-1]*(n+1-i)*powmod(i,-1,mod))%mod)
        return l[k]

N,M=mint()
A = [input() for _ in range(N)]
B = [input() for _ in range(M)]
for x in range(N-M+1):
    for y in range(N-M+1):
        tmp=True
        for i,j in product(range(M),repeat=2):
            if A[x+i][y+j]!=B[i][j]:
                tmp=False
                break
        if tmp:
            print('Yes')
            exit()
print('No')

Submission status: Accepted

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):
        flg = True
        for k in range(M):
            if A[i + k][j:j+M] == B[k]:
                continue
            else:
                flg = False
                break
        if flg:
            print('Yes')
            exit()
print('No')