Problem:


Score : 200 points

Problem Statement

You are given an image A composed of N rows and N columns of pixels, and a template image B composed of M rows and M columns of pixels.

A pixel is the smallest element of an image, and in this problem it is a square of size 1×1.

Also, the given images are binary images, and the color of each pixel is either white or black.  

In the input, every pixel is represented by a character: . corresponds to a white pixel, and # corresponds to a black pixel.

The image A is given as N strings A_1,...,A_N.

The j-th character in the string A_i corresponds to the pixel at the i-th row and j-th column of the image A (1≦i,j≦N).

Similarly, the template image B is given as M strings B_1,...,B_M.

The j-th character in the string B_i corresponds to the pixel at the i-th row and j-th column of the template image B (1≦i,j≦M).  

Determine whether the template image B is contained in the image A when only parallel shifts can be applied to the images.  

Constraints

1≦M≦N≦50 

A_i is a string of length N consisting of # and ..

B_i is a string of length M consisting of # and ..

Input

The input is given from Standard Input in the following format:

N M
A_1
A_2
:  
A_N
B_1
B_2
:  
B_M

Output

Print Yes if the template image B is contained in the image A. Print No otherwise.

Sample Input 1

3 2
#.#
.#.
#.#
#.
.#

Sample Output 1

Yes

The template image B is identical to the upper-left 2 × 2 subimage and the lower-right 2 × 2 subimage of A. Thus, the output should be Yes.

Sample Input 2

4 1
....
....
....
....
#

Sample Output 2

No

The template image B, composed of a black pixel, is not contained in the image A composed of white pixels.



Sample input:
3 2
#.#
.#.
#.#
#.
.#


Sample output:
Yes

Submission status: Wrong Answer

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

ans="No"

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

print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

ly = len(t[0])
lt = m
ans = False
for i in range(n - m + 1):
  for j in range(n - m + 1):
    for k in range(lt):

      if ma[i + k][j : j + ly + 1] != t[k]:
        break
    else:
      ans = True

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

Submission status: Wrong Answer

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

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

ly = len(t[0])
lt = m
ans = False
for i in range(n):
  for j in range(n):
    for k in range(lt):
      if i + k >= n:
        break

      if ma[i + k][j : j + ly + 1] != t[k]:
        break
    else:
      ans = True

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

Submission status: Wrong Answer

Solution code:
from typing import List


def first_indexes(string: str, pattern: str) -> List[int]:
    indexes = []
    i = 0
    while i <= len(string) - len(pattern):
        index = string.find(pattern, i)
        if index != -1:
            indexes.append(index)
            i = index
        else:
            return indexes
        i += 1

    return indexes


def answer(n: int, m: int, a: List[str], b: List[str]) -> str:
    str_b = ''.join(b)
    for i in range(n - m):
        str_a = ''.join([line[i:i + m] for line in a])
        if str_b in str_a:
            bools = list(index % m == 0 for index in first_indexes(str_a, str_b))
            if any(bools):
                return 'Yes'

    return 'No'


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


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from typing import List


def answer(n: int, m: int, a: List[str], b: List[str]) -> str:
    str_b = ''.join(b)
    for i in range(n - m):
        str_a = ''.join([line[i:i + m] for line in a])
        if str_b in str_a:
            return 'Yes'

    return 'No'


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


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

A = []
B = []

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

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

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

print('No')

Submission status: Wrong Answer

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

A = []
B = []

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

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

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

print('No')

Submission status: Wrong Answer

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

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


dx = [-1, 0, 0, 1]
dy = [0, 1, -1, 0]

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

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


print('No')

Submission status: Wrong Answer

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

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


dx = [-1, 0, 0, 1]
dy = [0, 1, -1, 0]

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

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


print('No')

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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):
    t = True
    for k in range(M):
      if B[k] != A[i+k][j:j+M]:
        t = False
  if t:
    ans = "Yes"
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
def read(X):
  a = input()
  X.append(a)
  return

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

Submission status: Wrong Answer

Solution code:
import sys
def read(X):
  a = input()
  X.append(a)
  return

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

Submission status: Wrong Answer

Solution code:
import sys
def read(X):
  a = input()
  X.append(a)
  return

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

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

Submission status: Wrong Answer

Solution code:
import sys
def read(X):
  a = input()
  X.append(a)
  return

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

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

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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):
        if b[0][0] == a[i][j]:
            for x in range(m):
                flag = True
                if flag == False:
                    break
                for y in range(m):
                    if b[x][y] == a[i+x][j+y]:
                        pass
                    else:
                        flag = False
                        break
                print("Yes")
                exit()
print("No")

Submission status: Wrong Answer

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):
        if b[0][0] == a[i][j]:
            for x in range(m):
                flag = True
                if flag == False:
                    break
                for y in range(m):
                    if b[x][y] == a[i+x][j+y]:
                        pass
                    else:
                        break
                print("Yes")
                exit()
print("No")

Submission status: Wrong Answer

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

b = 0
memo = -1
for a in range(len(A)):
    if b == m:
        break
    if "o" in list(A[a].replace(B[b],"o")):
        if memo + 1 != a:
            b = 0
        else:
            b += 1
            memo = a
    else:
        b = 0
        memo = a
        

if b == m:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

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

b = 0
memo = 0
flag = False
for a in range(len(A)):
    if b == m:
        break
    if "o" in list(A[a].replace(B[b],"o")):
        if memo + 1 != a:
            b = 0
        else:
            b += 1
            memo = a
        
if b == m:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

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

b = 0
for a in A:
    if b == m:
        break
    if "o" in list(a.replace(B[b],"o")):
        b += 1
if b == m:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
A=[input() for i in range(n)]
B=[input() for i in range(m)]
R=range(n-m+1)

for i in R:
  for j in R:
    for k in range(m):
      if A[j+k][i:i+m]!=B[k]:
        break
      else:
        print("Yes")
        exit()

print("No")

Submission status: Wrong Answer

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

if m == 1:
    for i in a:
        if b[0] in i:
            res = "Yes"
else:
    for k in range(n-m+1): # (0,1) ※aの長さを上限にbが縦に移動できる範囲
        if b[0] in a[k]: # もしa[0]かa[1]にb[0]が含まれるなら
            for l in range(n-m+1): # (0,1) ※aの長さを上限にbが横に移動できる範囲
                if b[0]==a[k][l:m+l]: # もし、b[0]がa[0/1][0:2]かa[0/1][1:3]と一致するなら
                    for o in range(len(b)-1):
                        if b[o+1] == a[k+o+1][l:m+1]:
                            res = "Yes"
print(res)

Submission status: Wrong Answer

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

if m == 1:
    for i in a:
        if b[0] in i:
            res = "Yes"
else:
    for k in range(len(a)-len(b)+1):
        if b[0] in a[k]:
            idx = a[k].index(b[0])
            for l in range(len(b)-1):
                if b[l+1] == a[k+l+1][idx:]:
                    res = "Yes"
print(res)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

wa = len(A[0])
wb = len(B[0])
  
matched = False
for i1 in range(N - M + 1):
  for j1 in range(wa - wb +1):
    cnt = 0
    for i2 in range(M):
      #print(B[i2]," vs ", A[i1+i2][j1:j1+wb])
      if B[i2] == A[i1+i2][j1:j1+wb]:
        cnt += 1
    if cnt == M:
      matched = True
      break
          

if matched:
  print("YES")
else:
  print("NO")

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
n=[input() for _ in range(n)]
m=[input() for _ in range(m)]
r=[]
for i in m:
  t=[]
  for j in n:
    if i in j:
      t.append(j.index(i))
  if t: r.append(t)
print('NYoe s'[len(r) and all([1 for i in r if 0 in i] or [1 for i in r if 1 in i])::2])

Submission status: Wrong Answer

Solution code:
# B - Template Matching
def main():
    n, m = map(int, input().split())

    a_l = [input() for i in range(n)]
    b_l = [input() for i in range(m)]

    for i in range(n-m+1):
        for j in range(n-m+1):
            ans = 'Yes'
            for k in range(m):
                for l in range(m):
                    if a_l[i+k][j+l] != b_l[k][l]:
                        ans = 'No'
                        break
    
    print(ans)

  
        
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#
# abc054 b
#
import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """3 2
#.#
.#.
#.#
#.
.#"""
        output = """Yes"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """4 1
....
....
....
....
#"""
        output = """No"""
        self.assertIO(input, output)


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

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

    print(ans)


if __name__ == "__main__":
    # unittest.main()
    resolve()

Submission status: Wrong Answer

Solution code:
#
# abc054 b
#
import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """3 2
#.#
.#.
#.#
#.
.#"""
        output = """Yes"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """4 1
....
....
....
....
#"""
        output = """No"""
        self.assertIO(input, output)


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

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

    print(ans)


if __name__ == "__main__":
    # unittest.main()
    resolve()

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
A = []
B = []
for _ in range(N):
    A.append(input())
for _ in range(M):
    B.append(input())
for n_i in range(N - M + 1):
    for n_j in range(N - M + 1):
        for m_i in range(M):
            for m_j in range(M):
                if A[n_i + m_i][n_j + m_j] == B[m_i][m_j]:
                    continue
                break
            else:
                continue
            break
        else:
            break
    else:
        break
else:
    print("Yes")
    exit()
print("No")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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 a:
  for j in b:
    if j not in a:
      print("No")
      exit()
print("Yes")

Submission status: Wrong Answer

Solution code:
A, B = map(int, input().split())

a_lst = []
for i in range(A):
    a_lst.append(input().replace('#', '1').replace('.', '0'))

b_lst = []
for i in range(B):
    b_lst.append(input().replace('#', '1').replace('.', '0'))

for i in range(len(a_lst)):
    if len(a_lst)-i < len(b_lst):
        break
    if b_lst[0] in a_lst[i]:
        for j in range(1, len(b_lst)):
            if b_lst[j] in a_lst[i+i]:
                continue
            else:
                break
        else:
            print('Yes')
            exit()

print('No')

Submission status: Wrong Answer

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(0,n-m):
    for j in range(0,n-m):
        p=[a[x][i:i+m] for x in range(j,j+m)]
        ok=0
        for h in range(m):
            x,y=p[h],b[h]
            for k in range(m):
                if x[k]!=y[k]:
                    ok+=1
        if ok==0:
            print('Yes')
            exit()
print('No')

Submission status: Wrong Answer

Solution code:
import sys
def input(): return sys.stdin.readline().strip()

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):
        for j in range(n - m):
            correspond = True
            for p in range(m):
                for q in range(m):
                    if A[i + p][j + q] != B[p][q]:
                        correspond = False
                        break
            if correspond:
                print("Yes")
                return
    print("No")

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

# input = stdin.readline

def solve(n,m,original,temp):
  def judge(sy,sx):
    for i in range(m):
      for j in range(m):
        if original[sy+i][sx+j] != temp[i][j]:
          return False
    return True
  

  sy = 0
  sx = 0
  while sy + m - 1 < n:
    while sx + m - 1 < n:
      if judge(sy,sx):
        return True
      sx += 1
    sy += 1

  return False

def main():
  N,M = map(int,input().split())
  a = [input() for _ in range(N)]
  b = [input() for _ in range(M)]
  print("Yes" if solve(N,M,a,b) else "No")
  pass

if __name__ == '__main__':
  main()

Submission status: Wrong Answer

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

# input = stdin.readline

def solve(n,m,original,template):
  def judge(sy,sx):
    for i in range(m):
      for j in range(m):
        if original[sy+i][sx+j] != template[i][j]:
          return False
    return True
  

  sy = 0
  sx = 0
  while sy + m < n:
    while sx + m < n:
      if judge(sy,sx):
        return True
      sx += 1
    sy += 1

  return False

def main():
  N,M = map(int,input().split())
  a = [input() for _ in range(N)]
  b = [input() for _ in range(M)]
  print("Yes" if solve(N,M,a,b) else "No")
  pass

if __name__ == '__main__':
  main()

Submission status: Wrong Answer

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

# input = stdin.readline

def solve(n,m,original,template):
  def judge(sy,sx):
    for i in range(m):
      for j in range(m):
        if original[sy+i][sx+j] != template[i][j]:
          return False
    return True
  
  for i in range(n-m):
    for j in range(n-m):
      if judge(i,j):
        return True

  return False

def main():
  N,M = map(int,input().split())
  a = [input() for _ in range(N)]
  b = [input() for _ in range(M)]
  print("Yes" if solve(N,M,a,b) else "No")
  pass

if __name__ == '__main__':
  main()

Submission status: Wrong Answer

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):
    start_h = i
    end_h = i+m
    for j in range(n-m):
        start_w = j
        end_w = j+m
        for k in range(m):
            if a[start_h+k][start_w:end_w] != b[k]:
                break
        else:
            print("Yes")
            exit()
print("No")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

for s in range((n-m+1)**2):
    for i in range(n-m+1):
        for j in range(n-m+1):
            x.append(a[i][j:j+m])
            if x==b:
                print("Yes")
                cnt+=1
                break

        else:
            continue
        break

if cnt==0:
    print("No")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

x=[input() for i in range(n)]
y=[input() for i in range(m)]

for i in range(n-m+1):
  for j in range(n-m+1):
    if x[i][j]==y[0][0]:
      if m==1:
        print('Yes')
        exit()
      ans='Yes'
      for k in range(m):
        if x[i+k][j:j+n-m+1]!=y[k]:
          ans='No'

      if ans=='Yes':   
        print('Yes')
        exit()
        
print('No')

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
x,y=[],[]

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

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

for i in range(n-m+1):
  for j in range(n-m+1):
    if x[i][j]==y[0][0]:
      if m==1:
        print('Yes')
        exit()
      ans='Yes'
      for k in range(m):
        if x[i+k][j:j+n-m+1]!=y[k]:
          ans='No'

      if ans=='Yes':   
        print('Yes')
        exit()
        
print('No')

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
x,y=[],[]

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

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

for i in range(n-m+1):
  for j in range(n-m+1):
    if x[i][j]==y[0][0]:
      if m==1:
        print('Yes')
        exit()
      for k in range(m):
        if x[i+k][j:j+n-m+1]!=y[k]:
          continue
          
        print('Yes')
        exit()
        
print('No')

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

for i in range(n-m+1):
  for j in range(n-m+1):
    if x[i][j]==y[0][0]:
      if m==1:
        print('Yes')
        exit()
      for k in range(m):
        if x[i+k][j:j+n-m+1]!=y[k]:
          continue
          
        print('Yes')
        exit()
        
print('No')

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

for i in range(n-m+1):
  for j in range(n-m+1):
    if x[i][j]==y[0][0]:
      for k in range(m):
        if x[i+k][j:j+n-m+1]!=y[k]:
          continue
          
        print('Yes')
        exit()
        
print('No')

Submission status: Wrong Answer

Solution code:
import sys
N,M=map(int,input().split())
A=[]
for i in range(N):
  a=input()
  A.append(a)
B=[]
for j in range(M):
  b=input()
  B.append(b)
for k in range(N-M+1):
  for l in range(N-M+1):
    z=0
    for m in range(M):
      try:
        if B[k+m]==A[k+m][l:l+M]:
          z+=1
      except:
#        sys.stderr.write(f"{k,l,m}")
        pass
    if z==M:
      print("Yes")
      sys.exit()
print("No")