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: Accepted

Solution code:
def mtx2vec(mtx):
    tmp = ''
    for s in mtx:
        tmp += s
    return tmp
N, M = map(int, input().split())
A = []
B = []
for _ in range(N):
    A.append(input())
for _ in range(M):
    B.append(input())

b = ''
for s in B:
    b += s
ans = 'No'
for i in range(N-M+1):
    for j in range(N-M+1):
        tmp = ''
        for k in range(M):
            tmp += A[i+k][j:j+M]
        if tmp == b:
            ans =  'Yes'
            break
print(ans)

Submission status: Accepted

Solution code:
def search():
    for i in range(N - M + 1):
        for j in range(N - M + 1):
            if all(B[k] == A[i + k][j:j + M] for k in range(M)):
                return 'Yes'
    return 'No'


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

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)]
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 A[i+k][j+l] == B[k][l]:
                    continue
                flag = False
                break
            if not flag:
                break
        if flag:
            ans = True
            break
    if ans:
        break
if ans:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
class RollingHash2D:
    def __init__(self, s, n, m, b=1007, c=2009, mod=10**9 + 7):
        self.s = s
        self.n = n
        self.m = m
        self.b = b
        self.c = c
        self.mod = mod

        # preprocess
        self.hash_cs = [[0] * (self.m + 1) for _ in range(self.n + 1)]
        self.b_pow = [1] * (self.n + 1)  # base_pow[i] = base ** i
        self.c_pow = [1] * (self.m + 1)  # base_pow[i] = base ** i
        for i in range(self.n):
            self.b_pow[i + 1] = (self.b_pow[i] * self.b) % mod
        for i in range(self.m):
            self.c_pow[i + 1] = (self.c_pow[i] * self.c) % mod

        for i in range(self.n):
            for j in range(self.m):
                self.hash_cs[i + 1][j + 1] = \
                    self.hash_cs[i + 1][j] * self.c \
                    + self.hash_cs[i][j + 1] * self.b \
                    - self.hash_cs[i][j] * self.b * self.c \
                    + self.s[i][j]
                self.hash_cs[i + 1][j + 1] %= self.mod

    def calc_rolling_hash(self, il: int, ir: int, jl: int, jr: int) -> int:
        hash_val = \
            self.hash_cs[ir][jr] \
             - self.hash_cs[ir][jl] * self.c_pow[jr-jl] \
             - self.hash_cs[il][jr] * self.b_pow[ir-il] \
             + self.hash_cs[il][jl] * self.b_pow[ir-il] * self.c_pow[jr-jl]
        hash_val %= self.mod
        return hash_val

    def calc_hash(self, t, nt, mt):
        h = 0
        for i in range(nt):
            for j in range(mt):
                h += t[i][j] * self.b_pow[nt - i - 1] * self.c_pow[mt - j - 1]
                h %= self.mod
        return h


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

rh = RollingHash2D(a, n, n)
b_hash = rh.calc_hash(b, m, m)
flag = False
for i in range(n - m + 1):
    for j in range(n - m + 1):
        if rh.calc_rolling_hash(i, i + m, j, j + m) == b_hash:
            flag = True
            break
    if flag:
        break

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

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
A = [input() for a in range(N)]
B = [input() for b in range(M)]
ans = False
for h in range(N - M + 1):
    for w in range(N - M + 1):
        if ans == True:
            break
        for m in range(M):
            if A[h + m][w:w + M] == B[m]:
                pass
            else:
                ans = False
                break
            ans = True
if ans == True:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
I = input().split()
N = int(I[0])
M = int(I[1])
## input A and B ##
A = [["" for i in range(N)] for i in range(N)]
B = [["" for i in range(M)] for i in range(M)]
for i in range(N):
    A[i] = list(input())
for i in range(M):
    B[i] = list(input())

# print(A,B)

# print([ A_i[0:2] for A_i in A[0:2] ])

# print( B == [ A_i[0:2] for A_i in A[0:2] ]  )

EQ_flag = 0
for i in range(N+M+1):
    for j in range(N+M+1):
        if ( B == [ A_i[i:i+M] for A_i in A[j:j+M] ] ):
            EQ_flag = 1
            break

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

Submission status: Accepted

Solution code:
#!python3

LI = lambda: list(map(int, input().split()))

# input
N, M = LI()
A = [input() for _ in range(N)]
B = [input() for _ in range(M)]


def solve():
    n = N - M + 1
    b = "".join(B)
    for i in range(n):
        for j in range(n):
            a = ""
            for k in range(M):
                a += A[i + k][j : j + M]
            if a == b:
                return "Yes"
    return "No"


def main():
    ans = solve()
    print(ans)


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

def issubset(l, u, r, d):
    for i, y in enumerate(range(u, d)):
        for j, x in enumerate(range(l, r)):
            res = A[y][x] == B[i][j]
            if not res:
                return False
    return True

if n == m:
    if issubset(0, 0, n, n):
        print("Yes")
    else:
        print("No")
    exit()

for y in range(n - m):
    for x in range(n - m):
        if issubset(x, y, x+m, y+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)]
s = 0
cnt = 0

for i in range(n-m+1):
    for j in range(n-m+1):
        for x in range(m):
            for y in range(m):
                if a[i+x][j+y] == b[x][y]:
                    s += 1
        if s == m ** 2:
            cnt += 1
        else:
            s = 0
if cnt > 0:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
a = []
b = []
for i in range(n):
    tmp = input()
    a.append(tmp)
    
for i in range(m):
    tmp = input()
    b.append(tmp)
    
ans = False
for w in range(0 , n-m+1):
    for h in range(0,n-m+1):
        if ans == True:
            break
        flag = True
        for i in range(m):
            if a[h+i][w:w+m] == b[i]:
                pass
            else:
                flag = False
                break
        if flag == True:
            ans = True
if ans:
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

for i in range(N - M + 1):
    for j in range(N - M + 1):
        # match
        flag = True
        for k in range(M):
            for l in range(M):
                if A[i + k][j + l] == B[k][l]:
                    pass
                else:
                    flag = False

        if flag:
            break

    if flag:
        break

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

Submission status: Accepted

Solution code:
from itertools import product

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

for i, j in product(range(n - m + 1), repeat=2):
    if all(a[i + k][j:j + m] == b[k] for k in range(m)):
        print('Yes')
        break
else:
    print('No')

Submission status: Accepted

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

z=0
c=0

for i in range(n-m+1):
    for j in range(n-m+1): 
        
        for x in range(m):
            for y in range(m):
                if s[i+x][j+y]==t[x][y]:
                    z+=1
        if z==m**2:
            c+=1
        else:
            z=0
if c>0:
    print('Yes')
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)]
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]:
                break
        else:
            print('Yes')
            exit()
print('No')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def matching(A, B, N, M) :
  if N == M : 
    for j in range(N) : 
      match = 0
      if A[j] != B[j] :
        break
      match += 1
    if match == M : 
      return True
    else :
      return False
  for i in range(N - M) : 
    for j in range(N - M) :
      match = 0
      for m in range(M) :
        if A[j + m][i : M + i] != B[m] :
          break
        match += 1
      if match == M : 
      	return True
  return False
      
          
N, M = tuple(map(int, input().split()))
A = list()
B = list()

for i in range(N) :
  A.append(input())
  
for i in range(M) :
  B.append(input())
  
if matching(A, B, N, M) :
  print('Yes')
else : 
  print('No')

Submission status: Accepted

Solution code:
N,M=list(map(int,input().split()))
l=[list(input()) for i in range(N)]
mini=[list(input()) for i in range(M)]
mini="".join(sum(mini,[]))
for i in range(N-M+1):
   for j in range(N-M+1):
      let=""
      for k in range(i,M+i):
         let+="".join(l[k][j:j+M])
      if mini == let:
         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)]

def comp(x,y):
    for i in range(M):
        for j in range(M):
            if A[x+i][y+j] != B[i][j]:
                return False
    return True
flag = False
for i in range(N-M+1):
    for j in range(N-M+1):
        if comp(i,j):
            flag = True
            break
if flag:
    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)]

def comp(i, j):
    for x in range(m):
        for y in range(m):
            if a[i+x][j+y] != b[x][y]:
                return False
    return True

ans = 'No'
for i in range(n-m+1):
    for j in range(n-m+1):
        if comp(i, j):
            ans = 'Yes'
print(ans)

Submission status: Accepted

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

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

for i in range(n-m+1):
  for j in range(n-m+1):
    if A[i][j:j+m] == B[0]:
      if all(A[i+k][j:j+m] == B[k] for k in range(1,m)):
        print("Yes")
        exit()
print("No")

Submission status: Accepted

Solution code:
import sys

# import re
import math
import collections
# import decimal
import bisect
import itertools
import fractions
# import functools
import copy
import heapq
import decimal
# import statistics
import queue
import numpy as np

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    n, m = ns()
    matA = [list(input()) for _ in range(n)]
    matB = [list(input()) for _ in range(m)]

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

    for i in range(n - m + 1):
        for j in range(n - m + 1):
            if np.all(a[j:j + m, i:i + m] == b):
                print("Yes")
                exit(0)

    print("No")


if __name__ == '__main__':
    main()

Submission status: Accepted

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

frag='No'
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]:
        break
    else:
      frag="Yes"
      break
  continue
print(frag)

Submission status: Accepted

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

A = [""] * N
for _ in range(N):
    A[_] = input()

B = [""] * M
for _ in range(M):
    B[_] = input()

import sys
ans = True

for nvi in range(N-M+1):
    for nhi in range(N-M+1):
        ok = True

        for vi in range(M):
            for hi in range(M):
                if A[nvi+vi][nhi+hi] == B[vi][hi]:
                    pass
                else:
                    ok = False
                    break
        
        if ok:
            print("Yes")
            sys.exit()

print("No")

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
lista=[]
for i in range(n):
    lista.append(input())
listb=[]
for i in range(m):
    listb.append(input())
ans=0
num1=n-m+1
for i in range(num1):
    for j in range(num1):
        yn=0
        for k in range(m):
            str1=lista[i+k]
            if listb[k]!=str1[j:j+m]:
                yn=1
                break
        if yn==0:
            ans=1
            break
    if ans==1:
        break
if ans==0:
    print("No")
else:
    print("Yes")

Submission status: Accepted

Solution code:
import numpy as np

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

for i in range(N-M+1):
  for j in range(N-M+1):
    if (A[i:i+M,j:j+M] == B).all():
      print('Yes')
      quit()

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

for i in range(n):
    for j in range(n):
        if i + m > n or j + m > n:
            continue
        flag = True
        for k in range(m):
            for l in range(m):
                if a[i + k][j + l] != b[k][l]:
                    flag = False
        if flag is True:
            print("Yes")
            exit(0)

print("No")

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
A = [str(input()) for _ in range(n)]
B = [str(input()) for _ in range(m)]
for i in range(n-m+1):
    for j in range(n-m+1):
        for x in range(m):
            for y in range(m):
                if A[j+y][i+x] != B[y][x]:
                    break
            else:
                continue
            break
        else:
            print('Yes')
            exit()
else:
    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)]

ans = 'No'
for i in range(n - m + 1):
    for j in range(n - m + 1):
        C = []
        for k in range(m):
            C.append(A[i + k][j : j + m])
        if B == C:
            ans = 'Yes'
            
print(ans)

Submission status: Accepted

Solution code:
import sys

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

for k in range(N-M+1):
    for i in range(N-M+1):
        a = [A[j+k][i:i+M] for j in range(M)]
        if a == B:
            print('Yes')
            sys.exit()

print('No')

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    n, m = map(int, input().split())
    lista=[]
    listb =[]
    for i in range(0,n):
        a = input()
        lista.append(a)

    for i in range(0,m):
        a = input()
        listb.append(a)
    flag =0

    for i in range(0,n-m+1):
        for j in range(0,n-m+1):
            count = 0
            for k in range(m):
                if listb[k] == lista[i+k][j:j+m]:
                    count +=1
            if count == m:
                flag=1
    if flag ==1:
        print("Yes")
    else:
        print("No")

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun May 31 13:15:13 2020

@author: NEC-PCuser
"""

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

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

result = "No" 
for i in range(N - M + 1):
    for j in range(N - M + 1):
        for k in range(M):
            for l in range(M):
                if (A[i + k][j + l] != B[k][l]):
                    break
            else:
                continue
            break
        else:
            result = "Yes"
            break

print(result)

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
a_g=[];b_g=[]
for i in range(N):
  a_g.append(list(input()))
for i in range(M):
  b_g.append(list(input()))

for i in range(N-M+1):
  for j in range(N-M+1):
    flag=1
    for k in range(M):
      for l in range(M):
        if a_g[k+i][l+j] != b_g[k][l]:
          flag=0
          break
    if flag:
      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 = 0
for i in range(N-M+1):
    for h in range(N-M+1):
        cnt = 0
        for k in range(M):
            for j in range(M):
                if A[i+k][h+j] != B[k][j]:
                    cnt += 1
        if cnt == 0:
            ans += 1
if ans != 0:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
def main():
  num = list(map(int,input().split()))
  n=num[0]
  m=num[1]
  a = [input() for i in range(n)]
  b = [input() for i in range(m)]

  flg=0
  
  for i in range(0 , n):
    if m==1 and a[i].find(b[0])!=-1:
      flg=1
      break
    while n-i >= m and a[i].find(b[0])!=-1:
      start=a[i].find(b[0])
      for j in range(1 , m):
        if a[i+j][start:start+m]!=b[j]:
          break
        if j==m-1:
          flg=1
      if flg==1:
        break
      a[i]=a[i][a[i].find(b[0])+1:]
    if flg==1:
        break
        
  if flg==1:
    print("Yes")
  else:
    print("No")

main()

Submission status: Accepted

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

'''
for _ in pic:
    print("".join(_))

for _ in template:
    print("".join(_))
'''


def ifIncluded(start_position, pic, template):
    for t in range(M):
        for y in range(M):
            if not template[t][y] == pic[start_position[0] + t][start_position[1]+y]:
                return False
    return True


for t in range(N - M+1):
    for y in range(N - M+1):
        start_position = [t, y]
        if ifIncluded(start_position, pic, template):
            print('Yes')
            exit()
print('No')

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
a=[]
b=[]
for i in range(n):
  temp=list(map(str,input()))
  a.append(temp)
for i in range(m):
  temp=list(map(str,input()))
  b.append(temp)
temp=[]
ans=0
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 b[k][l]==a[k+i][l+j]:
          count=count+1
    if count==m*m:
      ans=1
if ans==1:
  print("Yes")
else:
  print("No")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy, copy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
#import numpy as np
#from decimal import *

N, M = MAP()
 
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):
			if A[i+k][j:j+M] != B[k]:
				break
		else:
			print("Yes")
			exit()
else:
	print("No")

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy, copy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
#import numpy as np
#from decimal import *

N, M = MAP()
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):  #左上のますが(i, j)
		tmp_lis = []
		for k in range(M):
			tmp_lis.append(A[i+k][j:j+M])
		if tmp_lis == B:
			print("Yes")
			exit()
else:
	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 x in range(n-m+1):
    for y in range(n-m+1):
        for i in range(m):
            if b[i] != a[y+i][x:x+m]:
                break
        else:
            print('Yes')
            exit()
print('No')

Submission status: Accepted

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

for g in range(n-m+1):
    for h in range(n-m+1):
        p=0
        for i in range(m):
            p+=a[g+i][h:h+m]==b[i]
        if p==m:
            print('Yes')
            exit()
print('No')

Submission status: Accepted

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

Submission status: Accepted

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

a = [list(map(str, input().rstrip())) for x in range(n)]
b = [list(map(str, input().rstrip())) for x in range(m)]

ans = []
for i in range(n - m + 1):
    for j in range(n - m + 1):
        tmp = []
        for x in range(m):
            for y in range(m):
                if a[i + x][j + y] == b[x][y]:
                    tmp.append(True)
                else:
                    tmp.append(False)
        ans.append(all(tmp))

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

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
A = []
B = []
C = []
flag = 0

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

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

Submission status: Accepted

Solution code:
# Python3 (3.4.3)
import sys
input = sys.stdin.readline

# -------------------------------------------------------------
# function
# -------------------------------------------------------------


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

for dh in range(N-M+1):
    for dw in range(N-M+1):
        flg = True
        for h in range(M):
            for w in range(M):
                if B[h][w] != A[h+dh][w+dw]:
                    flg = False
                    break
        if flg:
            print("Yes")
            sys.exit()

print("No")

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
 
N, M = MAP()
 
A = [input() for _ in range(N)]
B = [input() for _ in range(M)]
 
if A == B:
	print("Yes")
	exit()

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

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7

N, M = MAP()

A = [input() for _ in range(N)]
B = [input() for _ in range(M)]

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

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

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

print('No')

Submission status: Accepted

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

diff = n-m+1
include = False
for up_y in range(diff):
    for left_x in range(diff):
        same = True
        for y in range(up_y, up_y+m):
            for x in range(left_x,left_x+m):
                if small_image_ls[y-up_y][x-left_x] != big_image_ls[y][x]:
                    same = False
        if same:
            include = True
if include:
    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)]

for i in range(n - m + 1):
    for j in range(n - m + 1):
        check = [a[i + k][j:j + m] for k in range(m)]

        flag = True
        for x in range(m):
            if check[x] != b[x]:
                flag = False
                break

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

print('No')

Submission status: Accepted

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

for i in range(n-m+1):
    if not M[0] in N[i]:
        continue
    else:
        pos = N[i].index(M[0])
        flag = True
        for j in range(m):
            if M[j] != N[i+j][pos:pos+m]:
                flag = False
                break
        if flag:
            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 dx in range(N-M+1):
    for dy in range(N-M+1):
        flg = True
        for i in range(M):
          if A[i+dx][dy:dy+M] != B[i]:
            flg = False
            break
        if flg:
          print("Yes")
          exit()
print("No")

Submission status: Accepted

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

contain = False
for i in range(n-m+1):
    for j in range(n-m+1):
        ok = True
        for k in range(m):
            if not ok:
                break
            for l in range(m):
                if a_mat[i+k][j+l] != b_mat[k][l]:
                    ok = False
                    break
        if ok:
            contain = True
            break
if contain:
    print("Yes")
else:
    print("No")