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:
# import bisect
# import copy
# import fractions
# import math
import numpy as np
# from collections import Counter, deque
# from itertools import accumulate,permutations, combinations,combinations_with_replacement,product

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

    #print(A[1:3][1:3])
    def main():
        for i in range(N-M+1):
            for j in range(N-M+1):
                if (A[i:i + M, j:j + M] == B).all():
                    return 'Yes'
                elif i==N-M and j==N-M:
                    return 'No'
    print(main())

resolve()

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N,M=MI()
    A=[]
    B=[]
    
    for i in range(N):
        A.append(input())
        
    for i in range(M):
        B.append(input())
       
       
        
    def ch(a,b):
        for i in range(M):
            for j in range(M):
                if A[a+i][b+j]!=B[i][j]:
                    return False
        return True
    
     
    f=0
    for i in range(N-M+1):
        for j in range(N-M+1):
            if ch(i,j):
                f=1
                break
                
    if f==1:
        print("Yes")
    else:
        print("No")
            

main()

Submission status: Accepted

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

from itertools import product
for i,j in product(range(n-m+1), repeat=2):
    t = []
    for k in range(m):
        t.append(a[i+k][j:j+m])

    if t == b:
        print("Yes")
        break

else:
    print("No")

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
a = []
for i in range(n):
    a.append(list(input()))
b = []
for i in range(m):
    b.append(list(input()))
wa = len(a[0])
wb = len(b[0])
# print(wa)
# print(wb)
ans = 'No'
#print(a)
#print(b)
for i in range(n-m+1):
    for j in range(wa-wb+1):
        flg = True
        for k in range(m):
            for l in range(wb):
                #print(i,j,k,l)

                if a[i+k][j+l] != b[k][l]:
                    flg = False
        if flg == True:
            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 i in range(M)]
b=''
a='no'
for i in range(M):
    b+=B[i]
for i in range(N-M+1):
    if B[0]in A[i] :
        for j in range(N-M+1):
            a=''
            for k in range(M):
                a+=A[i+k][j:j+M]
            if a==b:
                print("Yes")
                exit()
print("No")

Submission status: Accepted

Solution code:
n,m = [int(i) for i in input().split()]
a = []
for i in range(n):
	array = input()
	a.append(array)
b = []
for i in range(m):
	line = input()
	b.append(line)
ans = 'No'
for i in range (n-m+1):
	for j in range(n-m+1):
		Ans = ans
		if a[i][j:j+m] == b[0]:
			#print(i,j)
			for k in range(m):
				if not a[i+k][j:j+m] == b[k]:
					ans = Ans
					break
				else:
					ans = 'Yes'
					#print(ans)
print(ans)

Submission status: Accepted

Solution code:
# B

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

flag=0
for i in range(N-M+1):
    for j in range(N-M+1):
        A_tmp = A[i:i+M,j:j+M]
        # print(A_tmp)
        # print(B)
        if (B==A_tmp).all():
            flag=1
        if flag==1:
            break
    if flag==1:
        break
if flag==1:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

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

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

if __name__=='__main__':
    main()

Submission status: Accepted

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


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

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

Submission status: Accepted

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

if n == 1:
    if a[0] == b[0]:
        print('Yes')
    else:
        print('No')
    exit()

for sx in range(n-m):
    for sy in range(n-m):
        chk = True
        for tx in range(m):
            for ty in range(m):
                #print(sx+tx, sy+ty)
                if a[sx+tx][sy+ty] == b[tx][ty]:
                    pass
                else:
                    chk = False
        if chk:
            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)]

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

for i in range(n-m+1):
    for j in range(n-m+1):
        c = [l[j:j+m] for l in a[i:i+m]]
        if c == 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)]

res=False
for dh in range(N-M+1):
    for dw in range(N-M+1):
        tres=True
        for h in range(M):
            for w in range(M):
                if B[h][w]!=A[h+dh][w+dw]:
                    tres=False
        res|=tres
print("Yes"if res else "No")

Submission status: Accepted

Solution code:
import sys
from io import StringIO
import unittest

doTest=0

def yn(b):
    print("Yes" if b==1 else "No")
    return

def resolve():
    readline=sys.stdin.readline
    a=[]
    b=[]
    n,m=list(map(int, readline().strip().split()))
    for _ in range(n):
        a.append(readline().strip())
    for _ in range(m):
        b.append(readline().strip())

    hikaku=""
    for one in b:
        hikaku += one

    #n*n
    #m*m
    for i in range(n-m+1):
        for j in range(n-m+1):
            tmp=""
            for k in range(m):
                tmp+=str(a[j+k])[i:i+m]
            if tmp==hikaku:
                print("Yes")
                return
    print("No")

    return

if doTest==0:
    resolve()
    sys.exit()

Submission status: Accepted

Solution code:
import sys

N, M = map(int, input().split())

A = [list(sys.stdin.readline()) for i in range(N)]

B = [list(sys.stdin.readline()) for i in range(M)]

for x in range(N-M+1):
    for y in range(N-M+1):
        flag = 0
        for i in range(M):
            for j in range(M):
                if A[x+i][y+j] != B[i][j]:
                    flag = 1
        if flag == 0:
            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)]
check = False
for i in range(n - m + 1):
    for j in range(n - m + 1):
        tmp_check = True
        for k in range(m):
            for l in range(m):
                if not (a[i + k][j + l] == b[k][l]):
                    tmp_check = False
        check = check or tmp_check
print("Yes" if check 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)]
ans = False
for h in range(n-m+1):
  for w in range(n-m+1):
    flag = 1
    for i in range(m):
      for j in range(m):
        if a[h+i][w+j] != b[i][j]:
          flag = 0
          break
    if flag == 1:
      ans = True
      break
print("Yes" if ans 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)]
flag = False
i=0
j=0
for i in range(N-M+1):
    for j in range(N-M+1):
        if A[i][j:j+M]==B[0]:
            a = 0
            while A[i+a][j:j+M]==B[a]:
                if a == M-1:
                    flag = True
                    break
                a += 1
            if flag:
                break
    if flag:
            break
                
if flag == True:
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

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

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

diff = N - m

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

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

    else:
        continue

print('No')


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

Submission status: Accepted

Solution code:
from sys import stdin
def main():
    readline=stdin.readline
    N,M=map(int,readline().split())
    A=[]
    for i in range(N):
        s=readline().strip()
        A.append(s)
    B=[]
    for i in range(M):
        s=readline().strip()
        B.append(s)
    
    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 B[k][l]!=A[k+i][l+j]:
                        flag=False
                        break
                if flag==False:
                    break
            if flag:
                break
        if flag:
            break
    if flag:
        print("Yes")
    else:
        print("No")
        
if __name__=="__main__":
    main()

Submission status: Accepted

Solution code:
listA = []
listB = []
N, M = map(int, input().split())
for a in range(N):
    A = input()
    listA.append(A)
for b in range(M):
    B = input()
    listB.append(B)
kazu = N - M
answer=[]
number=0
suuji=0

while number<=kazu:
    for z in range(0, kazu + 1):
        count=0
        for y in range(0, M):
            for x in range(0, M):
                if listA[z + y][x+number]==listB[y][x]:
                    count+=1
        answer.append(count)
    number+=1
for v in answer:
    if v==M**2:
        print('Yes')
        break
    else:
        suuji+=1
if suuji==len(answer):
    print('No')

Submission status: Accepted

Solution code:
from pprint import pprint
n,m = map(int, input().split())
a = list()
for i in range(n):
    a.append(input())
b = list()
for i in range(m):
    b.append(input())
a_len = len(a[0])
b_len = len(b[0])
for i in range(a_len-b_len+1):
    for j in range(n-m+1):
        check = True
        for k in range(m):
            if a[k+j][i:i+b_len] == b[k]:
                pass
            else:
                check = False
                break
        if check == True:
            print("Yes")
            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)]
x = 0
for i in range(n - m + 1):
    for j in range(n - m + 1):
        c = 0
        for k in range(m):
            for l in range(m):
                if a[i + k][j + l] == b[k][l]:
                    c += 1
        if c == m ** 2:
            x = 1
            break
    if x == 1:
        break
if x == 1:
    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)]
flag = 0
for i in range(n-m+1):
    for j in range(n-m+1):
        for k in range(m):
            if a[j+k][i:i+m]!=b[k]:
                break
        else:
            flag = 1
print("Yes" if flag else "No")

Submission status: Accepted

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

Submission status: Accepted

Solution code:

def check(A: list, B: list, start: (int, int)) -> bool:
    B_len = len(B)
    for b_pos_y, a_pos_y in enumerate(range(start[0], start[0]+B_len)):
        for b_pos_x, a_pos_x in enumerate(range(start[1], start[1]+B_len)):
            #print(f'{A[a_pos_y][a_pos_x]=} {B[b_pos_y][b_pos_x]=}')
            if A[a_pos_y][a_pos_x] != B[b_pos_y][b_pos_x]:
                return False
    return True



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

for i in range(N):
    A[i] = list(input())

for i in range(M):
    B[i] = list(input())

scope = N - M + 1

possible = False
for i in range(scope):
    for j in range(scope):
        if check(A, B, (i, j)) == True:
            possible = True
            break

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

Submission status: Accepted

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

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

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

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

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

else:
    print("No")

Submission status: Accepted

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


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

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

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

#print("candidate",candidate)

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

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

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

else:
    print("No")

Submission status: Accepted

Solution code:
import sys
#input = sys.stdin.buffer.readline

def main():
    N,M = map(int,input().split())
    sa = [list(str(input())) for _ in range(N)]
    sb = [list(str(input())) for _ in range(M)]
    
    ans = False
    for i in range(N-M+1):
        for j in range(N-M+1):
            if sa[i][j] == sb[0][0]:
                count = 0
                for k in range(M):
                    for l in range(M):
                        if sa[i+k][j+l] == sb[k][l]:
                            count += 1
                if count == M**2:
                    ans = True
    
    if ans:
        print("Yes")
    else:
        print("No")

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc054/tasks/abc054_b
# これも緑diffのB問題
import sys
read = sys.stdin.readline


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_map(H):
    '''
    H is number of rows
    文字列で与えられた盤面を読み取る用
    '''
    return [read()[:-1] for _ in range(H)]


from itertools import product
N, M = read_ints()
A = []
for a in read_map(N):
    for aa in a:
        A.append(1 if aa == '#' else 0)
B = []
for b in read_map(M):
    for bb in b:
        B.append(1 if bb == '#' else 0)


# 面倒なのでnumpy芸していっすか？
import numpy as np
A = np.array(A).reshape((N, N))
B = np.array(B).reshape((M, M))

for i, j in product(range(N - M + 1), range(N - M + 1)):
    ii, jj = i + M, j + M
    A_sub = A[i:ii, j:jj]
    if np.logical_xor(A_sub, B).sum() == 0:
        print('Yes')
        exit()

print('No')

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)])
# print('AB', A, B)
for i in range(N - M + 1):
    for j in range(N - M + 1):
        # print('i j', i, j)
        A_subset = A[i:i + M, j:j + M]
        # print('A_subset', A_subset)
        if np.all(A_subset == B):
            print('Yes')
            exit()
print('No')

Submission status: Accepted

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

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

Submission status: Accepted

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

for i in range(n-m+1):
    for j in range(n-m+1):
        for k in range(m):
            if N[i+k][j:j+m] != M[k]:
                break
        else:
            print('Yes')
            exit()
else:
    print('No')

Submission status: Accepted

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

for i in range(n-m+1):
    for j in range(n-m+1):
        for k in range(m):
            #print(N[i+k][j:j+m])
            #print(M[k])
            if N[i+k][j:j+m] != M[k]:
                break
        else:
            print('Yes')
            exit()
    #break
else:
    print('No')

Submission status: Accepted

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

flg=False
for i in range(n-m+1):
    for j in range(n-m+1):
        if all([b[l]==a[i+l][j:(j+m)] for l in range(m)]):
            flg=True
            break

print('Yes' if flg 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)]

hasFound = False
search = N-M+1
for y in range(search):
    for x in range(search):
        if hasFound: break
        for h in range(M):
            src = A[y+h][x:x+M]
            dst = B[h]
            if dst != src:
                break
        else:
            hasFound = True


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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
try:
    from typing import List
except ImportError:
    pass

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(N: int, M: int, A: "List[str]", B: "List[str]"):
    print(YES if any(all(
        A[y + dy][x + dx] == B[dy][dx]
        for dx in range(M) for dy in range(M)
    ) for x in range(N - M + 1) for y in range(N - M + 1)) else NO)


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    A = [next(tokens) for _ in range(N)]  # type: "List[str]"
    B = [next(tokens) for _ in range(M)]  # type: "List[str]"
    solve(N, M, A, B)


if __name__ == '__main__':
    main()

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

Diff = N - M + 1
if Diff == 1 :
    if A == B :
        print("Yes")
    else :
        print("No")
    exit()

def partofA(i, j) :
    Ans = []
    for x in range(M) :
        Ansx = []
        for y in range(M) :
            Ansx.append(A[x+i][y+j])
        Ans.append(Ansx)
    return Ans

for i in range(Diff) :
    for j in range(Diff) :
        if partofA(i,j) == 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):
        cnt = 0
        for k in a[i:i+m]:
            if not k[j:j+m]==b[cnt]:
                break
            cnt += 1
        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=[input() for i in range(M)]
judge=any([line[j:j+M] for line in A[i:i+M]]==B for i in range(N-M+1) for j in range(N-M+1))
print("Yes" if judge else "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))

ans = 'No'
for i in range(n-m+1): 
  for j in range(n-m+1):
    if b[0] == a[i][j:j+m]:
      for x in range(1,m):
        if b[x] != a[i+x][j:j+m]:
          break
      else:
        ans = 'Yes'
print(ans)

Submission status: Accepted

Solution code:
n,m = map(int, input().split())
 
"""
考え方
端から端まで、で一致するパターンがないか全探索
"""
 
## 1.INPUTの取得
a = list(input() for i in range(n))
b = list(input() for i in range(m))
 
## 2.全探索
ans = 'No'
for i in range(n-m+1): ## aの行
  for j in range(n-m+1): ## aの列 
    ## 2-1.m,nの一番上の行を比較
    if b[0] == a[i][j:j+m]:
      ## 下の行も比較
      for x in range(1,m):
        if b[x] != a[i+x][j:j+m]:
          break
      else:
        ans = 'Yes'
  
 
print(ans)

Submission status: Accepted

Solution code:
import sys
n, m = map(int, input().split())
a = [input() for _ in range(n)]
b = [input() for _ in range(m)]
index = n - m + 1


def check(a, b):
    for u, v in zip(a, b):
        for i in range(m):
            if u[i] == v[i]:
                pass
            else:
                return False
    return True


for i in range(index):
    x = a[i:i + m]
    for j in range(index):
        r = []
        for w in x:
            y = w[j:j+m]
            r.append(y)
        if check(r, b):
            print("Yes")
            sys.exit()

print("No")

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def main():
    def ok(i,j):
        for ii in range(m):
            if aa[ii+i][j:j+m]!=bb[ii]:return False
        return True

    n,m=MI()
    aa=[[c=="#" for c in input()] for _ in range(n)]
    bb=[[c=="#" for c in input()] for _ in range(m)]
    for i in range(n-m+1):
        for j in range(n-m+1):
            if ok(i,j):
                print("Yes")
                exit()
    print("No")

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)]
a=0
for i in range(N-M+1):
    for j in range(N-M+1):
        for k in range(M):
            if A[j+k][i:i+M]!=B[k]:
                break
        else:
            a=1
print("Yes" if a 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):  # 横方向の探索
        flag = 0
        if B[0] == A[i][j:j + m]:
            flag = 1
            for k in range(1, m):
                if B[k] != A[i+k][j:j + m]:
                    flag = 0
            if flag == 1:
                print('Yes')
                exit()
print('No')

Submission status: Accepted

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

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

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


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

print(ans)

Submission status: 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 judge(i,j):
    for k in range(m):
        for l in range(m):
            if b[k][l]!=a[i+k][j+l]:
                return False
    return True

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

Submission status: Accepted

Solution code:
import sys
import bisect
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
n,m = map(int,readline().split())
lst1 = []
for i in range(n):
    lst1.append(readline().rstrip().decode('utf-8'))

lst2 = []
for i in range(m):
    lst2.append(readline().rstrip().decode('utf-8'))

for i in range(n-m+1):
    for j in range(n-m+1):
        flag = 1
        for k in range(m):
            if lst1[i+k][j:j+m] != lst2[k]:
                flag = 0
        
        if flag:
            print("Yes")
            exit()
print("No")

Submission status: Accepted

Solution code:
def main():
    img_a_row, img_b_row = map(int, input().split())
    img_a = [input() for _ in range(img_a_row)]
    img_b = [input() for _ in range(img_b_row)]
    answer = False
    for i in range(img_a_row - img_b_row + 1):
        for j in range(img_a_row - img_b_row + 1):
            count = 0
            for k in range(img_b_row):
                if img_a[i + k][j:j+img_b_row] == img_b[k]:
                    count += 1
            if count == img_b_row:
                answer = True
    print("Yes" if answer else "No")


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
n, m = map(int, input().split())
a = [list(input()) for _ in range(n)]
b = [list(input()) for _ in range(m)]
for i in range(n-m+1):
    for j in range(n-m+1):
        A = [a[s][i:i+m] for s in range(j,j+m)]
        if A == b:
            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 i in range(M)]
inc=0
for i in range(N-M+1):
    for j in range(N-M+1):
        if(B[0]==A[i][j:j+M]):
            t=1
            for k in range(1,M):
                if(B[k]!=A[i+k][j:j+M]):
                    t=0
            if(t==1):
                print("Yes")
                exit()
print("No")