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 = [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 = [input() for _ in range(N)]
B = [input() for _ in range(M)]
#ans = False
for dx in range(N-M+1):
    for dy in range(N-M+1):
        flg = True
        for i in range(M):
            for j in range(M):
                if A[i+dx][j+dy] != B[i][j]:
                    flg = False
        if flg:
            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 = False
for dx in range(N-M+1):
    for dy in range(N-M+1):
        flg = True
        for i in range(M):
            for j in range(M):
                if A[i+dx][j+dy] != B[i][j]:
                    flg = False
        if flg:
            ans = True
print("Yes" if ans else "No")

Submission status: Accepted

Solution code:
# ACB054A
import sys
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 M[0] not in N[i]:
        continue
    else:
        ind = N[i].index(M[0])
        A = True
        for j in range(m):
            if M[j] != N[i+j][ind:ind+m]:
                A = False
                break
        if A:
            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)]
#print(A, B)

for i in range(n - m + 1):
    for j in range(n - m + 1):
        ok = True
        for k in range(m):
            if A[i + k][j:j + m] != B[k]:
                ok = False
                break
        if ok:
            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)]

ah = len(a)
aw = len(a[0])
bh = len(b)
bw = len(b[0])

for i in range(ah - bh + 1):
    for j in range(aw - bw + 1):
        tmp = []
        for k in range(bh):
            tmp.append(a[i + k][j : j + bw])
        if b == tmp:
            print("Yes")
            break
    else:
        continue
    break
else:
    print("No")

Submission status: Accepted

Solution code:
def check(s,t):
    for i in range(s,s+M):
        for j in range(t,t+M):
            if A[i][j] != B[i-s][j-t]:
                return False
    return True


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):
        if check(i,j):
            print("Yes")
            exit()

print("No")

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
# from collections import defaultdict, deque
from math import log10, sqrt, ceil
def input(): return sys.stdin.readline()[:-1] # warning not \n
# def input(): return sys.stdin.buffer.readline()[:-1]


def solve():
    
    n, m = [int(x) for x in input().split()]
    a = []
    for i in range(n):
        a.append(input())
    b = []
    for i in range(m):
        b.append(input())

    ok = 0
    for i in range(n - m + 1):
        for j in range(n - m + 1):
            f = 1
            for x in range(m):
                for y in range(m):
                    if a[i+x][j+y] != b[x][y]:
                        f = 0
            ok |= f


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




t = 1
# t = int(input())
for case in range(1,t+1):
    ans = solve()



"""
1 -> (1, 2) -> (2 ** 3, 3) -> (3, 1)
100000007
"""

Submission status: Accepted

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

import sys
# import time
# import math
# import numpy as np
# import scipy.sparse.csgraph as cs            # csgraph_from_dense(ndarray, null_value=inf), bellman_ford(G, return_predecessors=True), dijkstra, floyd_warshall
# import random                                # random, uniform, randint, randrange, shuffle, sample
# import string                                # ascii_lowercase, ascii_uppercase, ascii_letters, digits, hexdigits
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from datetime import date, datetime          # date.today(), date(year,month,day) => date obj; datetime.now(), datetime(year,month,day,hour,second,microsecond) => datetime obj; subtraction => timedelta obj
# from datetime.datetime import strptime       # strptime('2019/01/01 10:05:20', '%Y/%m/%d/ %H:%M:%S') returns datetime obj
# from datetime import timedelta               # td.days, td.seconds, td.microseconds, td.total_seconds(). abs function is also available.
# from copy import copy, deepcopy              # use deepcopy to copy multi-dimentional matrix without reference
# from functools import reduce                 # reduce(f, iter[, init])
# from functools import lru_cache              # @lrucache ...arguments of functions should be able to be keys of dict (e.g. list is not allowed)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat   # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby                # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap                # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product, permutations  # product(iter, repeat=n), permutations(iter[,r])
# from itertools import combinations, combinations_with_replacement
# from itertools import accumulate             # accumulate(iter[, f])
# from operator import itemgetter              # itemgetter(1), itemgetter('key')
# from fractions import gcd                    # for Python 3.4 (previous contest @AtCoder)



def main():
    mod = 1000000007                # 10^9+7
    inf = float('inf')              # sys.float_info.max = 1.79...e+308
    # inf = 2 ** 64 - 1             # (for fast JIT compile in PyPy) 1.84...e+19
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())
    
    def compare(s_list, t_list):
        assert(len(s_list) == len(t_list))
        assert(len(s_list[0]) == len(t_list[0]))
        assert(len(s_list) == len(s_list[0]))
        size = len(s_list)
        for i in range(size):
            if s_list[i] != t_list[i]:
                return False
        return True

    def contain(A, B, n, m):
        diff = n - m
        for i in range(diff+1):
            for j in range(diff+1):
                new_A = [s[j:n-diff+j] for s in A[i:n-diff+i]]
                if compare(new_A, B):
                    return True
        return False


    n, m = mi()
    A = [input() for _ in range(n)]
    B = [input() for _ in range(m)]
    print('Yes') if contain(A, B, n, m) else print('No')


if __name__ == "__main__":
    main()

Submission status: Accepted

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

A_image = [input() for i in range(N)]
B_image = [input() for i in range(M)]
Flag = False

for i in range(N):
    for j in range(N): # 画像Aをすべてループ
        if i + M <= N and j + M <= N:
            temp = []
            for k in range(M):
                temp.append(A_image[i+k][j : j+M])
            if temp == B_image:
                Flag = True

if Flag is True:
    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 = False  
for i in range(n-m+1):
    #flag = True
    for k in range(n-m+1):
        flag=True#ここ
        for j in range(i,i+m):
            #if i==k==3:
            #    print(a[j][k:k+m],b[j-i],a[j][k:k+m]==b[j-i],flag)
            if a[j][k:k+m]!=b[j-i]:
                flag = False
                break
        if flag:
            break
    if flag:
        break
#print(i,k,flag)        
print("Yes" if flag else "No")

Submission status: Accepted

Solution code:
from itertools import product
n, m = list(map(int, input().split()))
A = [list(input()) for _ in range(n)]
B = [list(input()) for _ in range(m)]
for i, j in product(range(n - m + 1), range(n - m + 1)):
    if all([A[i + k][j:j + m] == B[k] for k in range(m)]):
        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)]

def check():
    for i in range(n):
            for j in range(n):
                if i + m <= n and j + m <= n:
                    aa = []
                    for k in range(m):
                        aa.append(a[i + k][j : j+m])
                    if aa == b:
                        return 'Yes'
    return 'No'

print(check())

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 = True
for i in range(n):
    if flag:
        for j in range(n):
            if i + m <= n and j + m <= n:
                aa = []
                for k in range(m):
                    aa.append(a[i + k][j : j+m])
                if aa == b:
                    print('Yes')
                    flag = False
                    break

if flag:
        print('No')

Submission status: Accepted

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

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

def Main(N, M, A, B):
    for i in range(N-M+1):
        for j in range(N-M+1):
            if A[i][j] == B[0][0]:
                if check(i, j, A, B, M):
                    return 'Yes'
    return "No"     
    
res = Main(N, M, A, B)
print(res)

Submission status: Accepted

Solution code:
#入力
n,m = map(int,input().split())
a_list = [input() for nesya in range(n)]
b = [input() for motsu in range(m)]

#二重ループによりN*NからM*Mの正方形を取り出す(j行目i列目)
for i in range(n-m+1):
  for j in range(n-m+1):
    #j~j+m-1行目のi~i+m-1列目をリスト型にする
    s = [(a_list[k])[i:i+m] for k in range(j,j+m)]
    #テンプレート(問題文)と一致しているか
    if b == s:
      #一致していたら終わる
      break
    #違ったら続ける
  #一致していた時、外側のリストについても終了する
  if b == s:
    break    

#判定
if b == s:
  #含んでいた
  print('Yes')
else:
  #含んでいなかった
  print('No')

Submission status: Accepted

Solution code:
import numpy

n, m = map(int, input().split())
a = numpy.zeros([n, n], dtype=int)
b = numpy.zeros([m, m], dtype=int)
for i in range(n):
    s = input()
    for j in range(n):
        if s[j] == '#':
            a[i, j] = 1
for i in range(m):
    s = input()
    for j in range(m):
        if s[j] == '#':
            b[i, j] = 1
for i in range(n - m + 1):
    for j in range(n - m + 1):
        if numpy.all(a[i: i + m, j: j + m] == b):
            print("Yes")
            exit()
print("No")

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
from collections import defaultdict
from collections import deque
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def Yes(): print("Yes"); return
def No(): print("No"); return

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr

#####MakeDivisors######
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#####ChangeBase#####
def Base_10_to_n(X, n):
  if X//n:
    return Base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def Base_n_to_10(X, n):
  return sum(int(str(X)[-i])*n**i for i in range(len(str(X))))

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count

#############
# Main Code #
#############
N,M = inputIL()
n = inputSLs(N)
m = inputSLs(M)

for i in range(N-M+1):
  for j in range(N-M+1):
    if m == [ n[k][i:i+M] for k in range(j,j+M)]:
      Yes()
      exit()
No()

Submission status: Accepted

Solution code:
def sub(m, line, row, a, b):
    one_ans = "T"
    for j in range(1, m):
        a_match = a[line + j][row : row + m]
        #print(a_match)
        if b[j] == a_match:
            one_ans += "T"
        else:
            one_ans += "F"
    return (one_ans)

def resolve_mine(): #quote
    n, m = map(int, input().split())
    
    a = list()
    for i in range(n):
        line = input()
        a.append(line)
    
    b = list()
    for i in range(m):
        line = input()
        b.append(line)
    
    ans = list()
    for a_line in range(n - m + 1):
        count = a[a_line].count(b[0])
        #print(f"count is {count}, a_line is {a_line}")
        
        if count == 1:
            line, row = a_line, a[a_line].find(b[0])
            one_ans = sub(m, line, row, a, b)
            ans.append(one_ans)
        elif count > 1:
            line = a_line
            formar_row = -1
            for counter in range(count):
                formar_row = a[a_line].find(b[0], formar_row + 1)
                row = formar_row
                one_ans = sub(m, line, row, a, b)
                ans.append(one_ans)

    #print(ans)
    result = "No"
    for an in ans:
        if "T" * m == an:
            result = "Yes"
            break

    print(result)

resolve_mine()

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
from fractions import gcd


def read():
    N, M = map(int, input().strip().split())
    A = []
    B = []
    for i in range(N):
        a = input().strip()
        A.append(a)
    for i in range(M):
        b = input().strip()
        B.append(b)
    return N, M, A, B


def solve(N, M, A, B):
    R = N - M
    C = len(A[0]) - len(B[0])
    if R < 0 or C < 0:
        return "No"
    L = len(B[0])
    for i in range(R+1):
        for j in range(C+1):
            is_match = True
            for k in range(M):
                if A[i+k][j:j+L] != B[k]:
                    is_match = False
                    break
            if is_match:
                return "Yes"
    return "No"


if __name__ == '__main__':
    inputs = read()
    print(solve(*inputs))

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)]
check = 0

for i in range(N - M + 1):
    for j in range(N - M + 1):
        bb = []
        for k in range(M):
            bb.append(A[i + k][j:j+M])
        if bb == B:
            check = 1

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

Submission status: Accepted

Solution code:
import sys

N, M = map(int, sys.stdin.readline().strip().split())

A = []
for _ in range(N):
    A.append(list(sys.stdin.readline().strip()))

B = []
for _ in range(M):
    B.append(list(sys.stdin.readline().strip()))

for i in range(N-M+1):
    for j in range(N-M+1):
        flag = True
        for y in range(M):
            for x in range(M):
                if A[i+y][j+x] != B[y][x]:
                    flag = False
            if not flag:
                break
        if flag:
            print("Yes")
            sys.exit()
print("No")

Submission status: Accepted

Solution code:
import numpy

n, m = map(int, input().split())
a = numpy.zeros([n, n], dtype=int)
b = numpy.zeros([m, m], dtype=int)
for i in range(n):
    s = input()
    for j in range(n):
        if s[j] == '#':
            a[i, j] = 1
for i in range(m):
    s = input()
    for j in range(m):
        if s[j] == '#':
            b[i, j] = 1
for i in range(n - m + 1):
    for j in range(n - m + 1):
        if numpy.all(a[i: i + m, j: j + m] == b):
            print("Yes")
            f = True
            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)]

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
N, M = map(int, input().split())
A = []
B = []

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

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

Submission status: Accepted

Solution code:
import numpy as np

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

found = False
for i in range(N-M+1):
    for j in range(N-M+1):
        P = A[i:i+M,j:j+M]
        if (P == B).all():
            print("Yes")
            found = True
            break
    if found: break
if not found:
    print("No")

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**9)
INF=10**18
def input():
    return sys.stdin.readline().rstrip()

def main():
    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')

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys

readline = sys.stdin.readline
N, M = map(int, readline().split())
A = [readline().rstrip() for _ in range(N)]
B = [readline().rstrip() for _ in range(M)]

for i in range(N-M+1):
    for j in range(N-M+1):
        if all(A[i+x][j:j+M] == B[x] for x in range(M)):
            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)]
ans = "No"

for i in range(n - m + 1): #列のシフト分
    for j in range(n - m + 1): #行のシフト分
        for k in range(m): #bの列番号
            if b[k] != a[i + k][j:j + m]:
                break
            if k == m - 1 and b[k] == a[i + k][j:j + m]:
                ans = "Yes"

print(ans)

Submission status: Accepted

Solution code:
import numpy as np
N, M = map(int, input().split())

A = np.array([[1 if i == "#" else 0 for i in input()] for _ in range(N)])
B = np.array([[1 if i == "#" else 0 for i in input()] for _ in range(M)])

if N == M:
    if np.all(A == B):
        print("Yes")
    else:
        print("No")
else:
    for i in range(N - M): # 横移動
        for j in range(N - M): # 縦移動
            if np.all(A[i: M + i, j: M + j]== 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())
for i in range(M):
    B.append(input())

ans_list = list()
for i in range(N-M+1):
    #print(A[i])
    if B[0] in A[i]:
        ans = "T"
        y = A[i].find(B[0])
        #print("{}行目の{}文字目".format(i+1, y+1))
        for j in range(1,M):
    
            if A[i+j][y:y+M] == B[j]:
                ans += "T"
            else:
                ans += "F"
            #print(i, j, ans)
        ans_list.append(ans)

flag = False
for ans in ans_list:
    if "T" * M in ans:
        flag = True
    if flag:
        print("Yes")
        break
if not flag:
    print("No")

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
a_l=[]
b_l=[]
for i in range(N):
    a_l.append(list(input()))
for i in range(M):
    b_l.extend(input())
count=0
for t in range (N-M+1):
    for k in range(N-M+1):
        tmp=[]
        for i in range(M):
            for j in range(M):
                tmp.append(a_l[t+i][k+j])
        if tmp == b_l:
            print('Yes')
            exit()
        else:
            continue
print('No')

Submission status: Accepted

Solution code:
#まだ
N,M=map(int,input().split())
a_l=[]
b_l=[]
for i in range(N):
    a_l.append(list(input()))
for i in range(M):
    b_l.extend(input())
count=0
for t in range (N-M+1):
    for k in range(N-M+1):
        tmp=[]
        for i in range(M):
            for j in range(M):
                tmp.append(a_l[t+i][k+j])
        if tmp == b_l:
            break
    if tmp == b_l:
        print('Yes')
        count=1
        break
    else:
        continue
if count==0:
    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):
        for k in range(m):
            if B[k] != A[k+i][j:j+m]:
                break
            if k == m-1 and B[k] == A[k+i][j:j+m]:
                ans = "Yes"
                
print(ans)

Submission status: Accepted

Solution code:
import sys

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

A = [list(sys.stdin.readline().strip()) for _ in range(N)]
B = [list(sys.stdin.readline().strip()) for _ in range(M)]


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

if N == M:
    print("Yes") if check(0, 0) else print("No")
else:
    for i in range(N - M):
        for j in range(N - M):
            if A[i][j] == B[0][0]:
                if check(i, j):
                    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)]
be_included = False

for i in range(N - M + 1):
    for j in range(N - M + 1):
        tmp = [A[k][j:j+M] for k in range(i, i + M)]
        if tmp == B:
            be_included = True
            break
    if be_included:
        break

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

Submission status: Accepted

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

for y in range(n-m+1):
    for x in range(n-m+1):
        aa=[a[i][x:x+m] for i in range(y,y+m)]
        if aa==b:
            ok=True
            break
    if ok:
        break
if ok:
    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)]
ans='No'
 
for i in range(N-M+1):
    for j in range(N-M+1):
        cnt=0
        if A[i][j:j+M] ==B[0]:
            for k in range(1,M):
                if A[i+k][j:j+M] == B[k]:
                    cnt+=1
            if cnt==M-1:
                ans='Yes'
                
print(ans)

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    N, M = map(int, readline().split())
    A = []
    B = []
    for _ in range(N):
        A.append(readline().decode('utf-8').strip())
    for _ in range(M):
        B.append(readline().decode('utf-8').strip())
    AH = N
    AW = len(A[0])
    BH = M
    BW = len(B[0])
    ans = 'No'
    for i in range(AH-BH+1):
        for j in range(AW-BW+1):
            if A[i][j:j+BW] == B[0]:
                for h in range(BH):
                    if A[i+h][j:j+BW] == B[h]:
                        continue
                    else:
                        break
                else:
                    ans = 'Yes'
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

for i in range(N-M+1):
    for j in range(N-M+1):
        cnt=0
        for k in range(M):
            for l in range(M):
                if A[i+k][j+l]==B[k][l]:
                    cnt+=1
                    if cnt==M**2:
                        clear=True
                        flag=True
                        break
                else:
                    flag=True
                    break
            if flag:
                break
        if clear:
            break
        else:
            flag=False
            cnt=0
    if clear:
        break

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

Submission status: Accepted

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

a = []
for i in range(n):
	s = input()
	a.append(s)
b = []
for i in range(m):
	t = input()
	b.append(t)

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

Submission status: Accepted

Solution code:
import sys

stdin = sys.stdin
inf = 1 << 60
mod = 1000000007

sys.setrecursionlimit(10 ** 7)

ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

n, m = na()
a = nsn(n)
b = nsn(m)

ans = False
for i in range(n):
    for j in range(n):
        if i + m - 1 >= n or j + m - 1 >= 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:
            ans = True

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