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:
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 iy in range(0, n-m+1):
  if ans:
    break
  for ix in range(0, n-m+1):
    tmp = True
    for y in range(0, m):
      for x in range(0, m):
        if A[iy+y][ix+x] != B[y][x]:
          tmp = False
    if tmp:
      ans = tmp
      break
      
if ans:
  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)]

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

print("No")

Submission status: Accepted

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

    for i in range(N):
        B.append(input().split()[0])

    for _ in range(M):
        A.append(input().split()[0])

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

main()

Submission status: Accepted

Solution code:
#ABC054

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

c = False
exist = False

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

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

Submission status: Accepted

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

la = [list(input()) for i in range(n)]
lb = [list(input()) for i in range(m)]
c = 0
t = False

for i in range(n-m+1):
    for j in range(n-m+1):
        if la[i][j] == lb[0][0]:
            t = True
            for k in range(m):
                for l in range(m):
                    if la[i+k][j+l] != lb[k][l]:
                        t = False
                        break
                if t == False:
                    break
            if t == True:
                break
        if t == True:
            break
    if t == True:
        break

if t == True:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

Submission status: Accepted

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

mm = [input() for _ in range(M)]
nn = [input() for _ in range(N)]
ans = False
for i in range(M - N + 1):
    if (ans == True):
        break
    for j in range(M - N + 1):
        if (ans == True):
            break
        x = []
        temp = mm[j:j + N]
        for k in range(N):
            temp2 = temp[k]
            x.append(temp2[i:i + N])
            
        if (x == nn):
            ans = True

if ans == True:
    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 _ in range(N):
    A.append(input())
for _ in range(M):
    B.append(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
                    break

            if not flag:
                break

        if flag:
            break

    if flag:
        break

if flag:
    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 _ in range(N):
    A.append(input())
for _ in range(M):
    B.append(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:
import itertools
import math
import sys
import heapq
from collections import Counter
from collections import deque
from fractions import gcd
from functools import reduce
sys.setrecursionlimit(4100000)
from functools import lru_cache
INF = 1 << 60

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

Submission status: Accepted

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

count=0

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

Submission status: 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')
            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)]
def check(x,y):
    ans = True
    for i in range(m):
        for j in range(m):
            if b[i][j] != a[i+x][j+y]:
                ans = False
    return ans

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

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline


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

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


if __name__ == '__main__':
    main()

Submission status: 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'


def check(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


for i in range(N - M + 1):
    for j in range(N - M + 1):
        if check(i, j):
            ans = 'Yes'

print(ans)

Submission status: Accepted

Solution code:
import numpy as np
n, m = map(int, input().split())
a = np.array([list(input()) for _ in range(n)])
b = np.array([list(input()) for _ in range(m)])

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

a, b = MAP()
A = [list(input()) for i in range(a)]
B = [list(input()) for i in range(b)]

for h in range(a-b+1):
    for w in range(a-b+1):
        count = 0
        for bh in range(b):
            for bw in range(b):
                if A[bh+h][bw+w] == B[bh][bw]:
                    count += 1
        if count == b * 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)]

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
f = lambda k:[input() for _ in range(k)]
ln,lm = f(n),f(m)
for i in range(n-m+1):
  for j in range(n-m+1):
    lk = [s[j:j+m] for s in ln[i:i+m]]
    if lk==lm:
      print('Yes')
      break
  else:
    continue
  break
else:
  print('No')

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
a=[[i for i in input()] for l in range(n)]
b=[[i for i in input()] for l in range(m)]
bs=""
for p in b:bs+="".join(p)
s=""
for TopX in range(n-m+1):
    for TopY in range(n-m+1):
        s=""
        for x in range(m):
            for y in range(m):
                s+=a[TopY+y][TopX+x]
        if bs==s:
            print("Yes")
            exit(0)
print("No")

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(len(l)):
    if b==l[i]:
        ok=True
if ok:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

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

    
if __name__ == '__main__':
    solve()

Submission status: Accepted

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

def solve(i,j):
    for k in range(m):
        for l in range(m):
            if A[i+k][j+l] != B[k][l]:
                return False
    return True # match

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

Submission status: Accepted

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

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

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

flag1 = False
for ax in range(n-m+1):
    for ay in range(n-m+1):

        flag2 = True
        for bx in range(m):
            for by in range(m):
                if al[ax+bx][ay+by] != bl[bx][by]:
                    flag2 = False
        if flag2:
            flag1 = True

if flag1:
    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)]
r=any([r[j:j+m] for r in a[i:i+m]]==b for i in range(n-m+1) for j in range(n-m+1))
print('Yes' if r else '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):
        # print(i,j)
        for k in range(m):
            for l in range(m):
                if a[i+k][j+l] != b[k][l]:
                    break
            else:
                continue
            break
        else:
            print('Yes')
            # print(i,j)
            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)]

def is_same(i,j):
  for l in range(m):
    for k in range(m):
      if a[i+l][j+k] != b[l][k]:
        return False
  return True
  
for i in range(n-m+1):
  for j in range(n-m+1):
    if is_same(i,j):
      print('Yes')
      exit()
print('No')

Submission status: Accepted

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

    ans = 'No'
    for i in range(N):
        for j in range(N):
            if A[i][j] == B[0][0]:
                count = 0
                for k in range(M):
                    for l in range(M):
                        if i+k>= N or j+l>= N:
                            continue
                        if A[i+k][j+l] == B[k][l]:
                            count += 1
                    if count == M * M:
                        ans = 'Yes'
                        break
    print(ans)

resolve()

Submission status: Accepted

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

    ans = 'No'
    for i in range(N):
        for j in range(N):
            if A[i][j] == B[0][0]:
                count = 0
                for k in range(M):
                    for l in range(M):
                        if i+k>= N or j+l>= N:
                            continue
                        if A[i+k][j+l] == B[k][l]:
                            count += 1
                    if count == M * M:
                        ans = 'Yes'
                        break
                if ans == 'Yes':
                    break
            if ans == 'Yes':
                break
        if ans == 'Yes':
            break
    
    print(ans)

resolve()

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
N,M=map(int,input().split())

AN=[]
for _ in range(N):
    AN.append(list(input()))
    
#print(AN)

AM=[]
for _ in range(M):
    AM.append(list(input()))

#print(AM)
for i in range(N-M+1):
    for j in range(N-M+1):
        #print(i,j)
        flag=True
        for k in range(M):
            if AN[i+k][j:j+M]!=AM[k]:
                #print(AN[i+k][j:j+M],AM[k])
                flag=False
        if flag:
            print("Yes")
            exit()
        
print("No")

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


def main():
    N, M = list(map(int, input().split()))
    A = [input() for _ in range(N)]
    B = [input() for _ in range(M)]
    for i in range((N - M + 1) ** 2):
        y = i // (N - M + 1)
        x = i % (N - M + 1)
        for j in range(M):
            if B[j] != A[y + j][x:x + M]:
                break
        else:
            print('Yes')
            break
    else:
        print('No')


if __name__ == "__main__":
    main()

Submission status: Accepted

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

list_Count = []
answer = "No"
for j in range(n - m + 1):
    #1行目を探す
    for i in range(n - m + 1):
        if m == 1 and list_a[j][i:m+i] == list_b[0]: answer = "Yes"
        elif list_a[j][i:m+i] == list_b[0]: 
            list_Count.append([i, j])

for id in range(len(list_Count)):
    for x in range(m - 1):
        if list_a[list_Count[id][1] + x + 1][list_Count[id][0] : m+ list_Count[id][0]] != list_b[x + 1]: break
        elif x + 1 ==  m - 1: answer = "Yes"

print(answer)

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)]
def AB(h,w):
  ret=[[None]*M for i in range(M)]
  for i in range(M):
    for j in range(M):
      ret[i][j]=A[h+i][w+j]
  return ret
ans='No'
for h in range(N-M+1):
  for w in range(N-M+1):
    if AB(h,w)==B:
      ans='Yes'
      break
print(ans)

Submission status: Accepted

Solution code:
n, m = list(map(int, input().split()))
a = [input() for _ in range(n)]
b = [input() for _ in range(m)]
for i in range((n-m+1) ** 2):
    y = i//(n-m+1)
    x = i%(n-m+1)
    for j in range(m):
        if b[j] != a[y+j][x:x+m]:
            break
    else: 
        print('Yes')
        break
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 permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect

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

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

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

for iy in range(n-m+1):
    for ix in range(n-m+1):
        bflag=True
        for jy in range(m):
            for jx in range(m):
#                print(iy,ix,jy,jx)
                if(a[iy+jy][ix+jx] != b[jy][jx]):
                    bflag=False
                    break
            if(not bflag):
                break
        else:
            print("Yes")
            sys.exit()

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 check(x, y):
    for i in range(M):
        for j in range(M):
            if A[x + i][y + j] == B[i][j]:
                continue
            else:
                return False
    return True
if A == B:
    print("Yes")
    exit()
for x in range(N - M):
    for y in range(N - M):
        if check(x, y):
            print("Yes")
            exit()
print("No")

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
n,m = map(int,input().split())
a = [input() for i in range(n+m)]
bit = 0
for i in range(n-m+1):
    for j in range(n-m+1):
        #if a[i][j][0] != a[n][j][0]: pass
        for k in range(m):
            if a[i+k][j:j+m] !=  a[n+k]: break
            if k == m-1: bit = 1
if bit: print("Yes")
else: print("No")

Submission status: Accepted

Solution code:
s = input()  # "3 2"
n, m = s.split()  # ("3", "2")
n = int(n)  # 3
m = int(m)  # 2

a = []
for i in range(0, n):
    a.append(input())

b = []
for i in range(0, m):
    b.append(input())

def same(a, b, i, j):
    for k in range(0, len(b)):
        if a[i + k][j:j + len(b)] != b[k]:
            return False
    return True

is_same = False
for i in range(0, n - m + 1):
    for j in range(0, n - m + 1):
        if same(a, b, i, j):
            is_same = True
            break
    else:
        continue
    break

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

Submission status: Accepted

Solution code:
import itertools
import sys

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

for i, j in itertools.product(range(n - m + 1), range(n - m + 1)):
	if a[i][j] == b[0][0]:
		for p, q in itertools.product(range(m), range(m)):
			if a[i + p][j + q] != b[p][q]:
				if i == n - m and j == n - m:
					print('No')
				break
			elif p == m - 1 and q == m - 1:
				print('Yes')
				sys.exit()
				
	elif i == n - m and j == n - m:
		print('No')

Submission status: Accepted

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

def bina(A , B):
    for i in range((N-M)+1):
        for w in range(N):
            c = []
            for q in range(M):
                c += [A[i+q][w:w+M]]
            if c == B:
                return "Yes"
    return "No"

if __name__ == '__main__':
    ans = bina(A , B)
    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)]
b = any(all(A[i+k][j+l]==B[k][l] for k in range(M) for l in range(M)) for i in range(N-M+1) for j in range(N-M+1))
print("YNeos"[not b::2])

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

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

for i in range(n-m+1):
    cnt=0
    while cnt<n-m+1:
        l=[]
        for j in range(m):
        #bと同じ長さの部分配列を作る
            l+=[a[j+cnt][i:i+m]]

        if l==b:
            print('Yes')
            exit()
        cnt+=1
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):
        jud=True
        for k in range(m):
            if b[k]!=a[i+k][j:j+m]:
                jud=False
                break
        if jud:
            print("Yes")
            exit()
print("No")

Submission status: Accepted

Solution code:
def solve(n, m, A, B):
    if n == m:
        if all(a == b for a, b in zip(A, B)):
            return 'Yes'
        else:
            return 'No'
    for i in range(len(A) - len(B)):
        for j in range(len(A[0]) - len(B[0])):
            if all(a[j:j + len(B[0])] == b for a, b in zip(A[i:i + len(B)], B)):
                return 'Yes'
    return 'No'

_n, _m = map(int, input().split())
_A = [input() for _ in range(_n)]
_B = [input() for _ in range(_m)]
print(solve(_n, _m, _A, _B))

Submission status: Accepted

Solution code:
import sys

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):
        matched = True

        for k in range(M):
            if A[i+k][j:j+M] == B[k]:
                continue
            else:
                matched = False
                break
    
        if matched:
            print('Yes')
            sys.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):
        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 not flag:
                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 i in range(0,n-m+1):
    for j in range(0,n-m+1):
        #print(i,j)

        flg = True
        for ii in range(m):
            for jj in range(m):
                if a[i+ii][j+jj] != b[ii][jj]:
                    flg = False

        if flg == True:
            print('Yes')
            exit()
print('No')