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:
def resolve():
    N, M = map(int, input().split())
    A = [list(input()) for _ in range(N)]
    B = [list(input()) for _ in range(M)]

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

resolve()

Submission status: Wrong Answer

Solution code:
import sys
from io import StringIO
import unittest

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

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

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)

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

Submission status: Wrong Answer

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

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

resolve()

Submission status: Wrong Answer

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

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

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

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

Submission status: Wrong Answer

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

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

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

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

print("No")

Submission status: Wrong Answer

Solution code:
import itertools 
n,m=map(int,input().split())
A=[list(input()) for _ in range(n)]
B=[list(input()) for _ in range(m)]
ans=False
for i in range(0,n-m+1):
  for j in range(0,n-m+1):
    a=[v[i:i+m] for v in zip(*A)]
    C=[list(w[j:j+m]) for w in zip(*a)]
    X=list(itertools.chain.from_iterable(C))
    Y=list(itertools.chain.from_iterable(B))
    ans=all(n==m for n,m in zip(X,Y))
print("Yes" if ans==True else "No")

Submission status: Wrong Answer

Solution code:
import itertools 
n,m=map(int,input().split())
A=[list(input()) for _ in range(n)]
B=[list(input()) for _ in range(m)]
ans=False
for i in range(0,n-m+1):
  for j in range(0,n-m+1):
    a=[v[i:i+m] for v in zip(*A)]
    C=[list(w[j:j+m]) for w in zip(*a)]
    X=list(itertools.chain.from_iterable(C))
    Y=list(itertools.chain.from_iterable(B))
    ans=all(n==m for n,m in zip(X,Y))
print("Yes" if ans is True else "No")

Submission status: Wrong Answer

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

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

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

print(AM)

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

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

for x in range(N - M):
    for y in range(N - M):
        if check(x, y):
            print("Yes")
            exit()
print("No")

Submission status: Wrong Answer

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

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

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

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

print("a, b: {}, {}".format(a, b))

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

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

Submission status: Wrong Answer

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

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

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

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

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

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

Submission status: Wrong Answer

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

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

if __name__ == '__main__':
    ans = bina(A , B)
    print(ans)

Submission status: Wrong Answer

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

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

if __name__ == '__main__':
    ans = bina(A , B)
    print(ans)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
A = [input() for _ in range(N)]
B = [input() for _ in range(M)]
b = any(all(A[i+k][j+l]==B[k][l] for k in range(M) for l in range(M)) for i in range(N-M) for j in range(N-M))
print("YNeos"[not b::2])

Submission status: Wrong Answer

Solution code:
import itertools

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

flag = False

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

Submission status: Wrong Answer

Solution code:
import itertools

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

flag = False

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

a_idx = 0
final_ok = False
while a_idx + len(b_lines) <= len(a_lines)-1:
    ok = True
    for idx, b_line in enumerate(b_lines):
        if b_line not in a_lines[a_idx+idx]:
            ok = False
            break
    if ok:
        final_ok = True
        break
    a_idx += 1

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

Submission status: Wrong Answer

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

a_idx = 0
final_ok = False
while a_idx + len(b_lines) <= len(a_lines)-1:
    ok = True
    for b_line in b_lines:
        if b_line not in a_lines[a_idx]:
            ok = False
            break
    if ok:
        final_ok = True
        break
    a_idx += 1

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

Submission status: Wrong Answer

Solution code:
import sys

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

for i in range(N - M + 1):
    if i >= M:
        break
    matched = True

    for j in range(N - M + 1):
        if A[i+j][i:i+M] == B[j]:
            continue
        else:
            matched = False
            break
    if matched:
        print('Yes')
        sys.exit()

print('No')

Submission status: Wrong Answer

Solution code:
import sys

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

for i in range(N - M + 1):
    if i >= M:
        break

    matched = True
    for j in range(N - M + 1):
        if A[i][j:j+M] == B[i][j:j+M]:
            continue
        else:
            matched = False
            break
    if matched:
        print('Yes')
        sys.exit()

print('No')

Submission status: Wrong Answer

Solution code:
import sys

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

for i in range(N - M):
    if i >= M:
        break

    matched = True
    for j in range(N - M):
        if A[i][j:j+M] == B[i][j:j+M]:
            continue
        else:
            matched = False
            break
    if matched:
        print('Yes')
        sys.exit()

print('No')

Submission status: Wrong Answer

Solution code:
n, m = map(int,input().split())
a = [None]*n
b = [None]*m
for i in range(n):
  a[i] = input()
for j in range(m):
  b[j] = input()
r = 'No'
for i in range(n - m):
  end_yoko = i + m + 1
  a_t = [s[i:end_yoko] for s in a]
  for j in range(n - m):
    end_tate = j + m + 1
    if a_t[j:end_tate] == b:
      r = 'Yes'
print(r)

Submission status: Wrong Answer

Solution code:
n, m = map(int,input().split())
a = [None]*n
b = [None]*m
for i in range(n):
  a[i] = input()
for j in range(m):
  b[j] = input()
r = 'No'
for i in range(n - m + 1):
  end_yoko = i + m + 1
  a_t = [s[i:end_yoko] for s in a]
  for j in range(n - m + 1):
    end_tate = j + m + 1
    if a_t[j:end_tate] == b:
      r = 'Yes'
print(r)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
s=[input() for _ in range(n)]
t=[input() for _ in range(m)]
for i in range(n-m):
  for j in range(n-m):
    f=True
    for x in range(m):
      for y in range(m):
        if t[x][y]!=s[x+i][y+j]:
          f=False
          break
      if f is False:
        break
    if f:
      break
  if f:
    print("Yes")
    break
else:
  print("No")

Submission status: Wrong Answer

Solution code:
def is_same(si, sj):
    for i in range(M):
        for j in range(M):
            if gridsA[sj + j][si + i] != gridsB[j][i]:
                return False
    return True


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

for i in range(N - M):
    for j in range(N - M):
        if is_same(i, j):
            print('Yes')
            exit()
print('No')

Submission status: Wrong Answer

Solution code:
import numpy as np

n,m=map(int,input().split())
a= [list(input()) for i in range(n)] 
b= [list(input()) for i in range(m)] 
na=np.array(a)

sa=n-m+1

for x in range(sa):
    for y in range(sa):

        if na[x:x+m,y:y+m].tolist()==b:
            print("Yes")
print("No")

Submission status: Wrong Answer

Solution code:
from __future__ import print_function

import sys
input = sys.stdin.readline


def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)
    return


# import re
# import array
# import copy
# import functools
# import operator

# import math
# import string
# import fractions
# from fractions import Fraction
from fractions import gcd

# import collections
# import itertools
# import bisect

# import heapq
# from heapq import heappush
# from heapq import heappop
# from heapq import heappushpop
# from heapq import heapify
# from heapq import heapreplace
# from queue import PriorityQueue as pq
from queue import Queue

# from itertools import accumulate

# from collections import deque
# from collections import Counter

# from operator import mul
# from functools import reduce

# def lcm(n,m):
#     return int(n*m/gcd(n,m))

# def reduce(p, q):
#     common = fractions.gcd(p, q)
#     return (p//common , q//common )

# def combinations_count(n, r):
#     r = min(r, n - r)
#     numer = reduce(mul, range(n, n - r, -1), 1)
#     denom = reduce(mul, range(1, r + 1), 1)
#     return numer // denom

# import random
# import time


def main():
    n, m = map(int, input().strip().split())
    a = [input().strip() for _ in range(n)]
    b = [input().strip() for _ in range(m)]
    # success_flag = 0
    for i in range(n - m):
        for j in range(n - m):
            failure_flag = 0
            for col in range(m):
                for row in range(m):
                    if a[i + col][j + row] != b[col][row]:
                        failure_flag = 1
            if failure_flag == 0:
                print("Yes")
                return
    print("No")
    return


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from __future__ import print_function

import sys
input = sys.stdin.readline


def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)
    return


# import re
# import array
# import copy
# import functools
# import operator

# import math
# import string
# import fractions
# from fractions import Fraction
from fractions import gcd

# import collections
# import itertools
# import bisect

# import heapq
# from heapq import heappush
# from heapq import heappop
# from heapq import heappushpop
# from heapq import heapify
# from heapq import heapreplace
# from queue import PriorityQueue as pq
from queue import Queue

# from itertools import accumulate

# from collections import deque
# from collections import Counter

# from operator import mul
# from functools import reduce

# def lcm(n,m):
#     return int(n*m/gcd(n,m))

# def reduce(p, q):
#     common = fractions.gcd(p, q)
#     return (p//common , q//common )

# def combinations_count(n, r):
#     r = min(r, n - r)
#     numer = reduce(mul, range(n, n - r, -1), 1)
#     denom = reduce(mul, range(1, r + 1), 1)
#     return numer // denom

# import random
# import time


def main():
    n, m = map(int, input().strip().split())
    a = [input().strip() for _ in range(n)]
    b = [input().strip() for _ in range(m)]
    # success_flag = 0
    for i in range(n - m):
        for j in range(n - m):
            failure_flag = 0
            for l in range(m):
                if a[i + l][j:j + m] != b[l]:
                    failure_flag = 1
            if failure_flag == 0:
                # success_flag = 1
                print("Yes")
                return

    print("No")
    return


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from __future__ import print_function

import sys
input = sys.stdin.readline


def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)
    return


# import re
# import array
# import copy
# import functools
# import operator

# import math
# import string
# import fractions
# from fractions import Fraction
from fractions import gcd

# import collections
# import itertools
# import bisect

# import heapq
# from heapq import heappush
# from heapq import heappop
# from heapq import heappushpop
# from heapq import heapify
# from heapq import heapreplace
# from queue import PriorityQueue as pq
from queue import Queue

# from itertools import accumulate

# from collections import deque
# from collections import Counter

# from operator import mul
# from functools import reduce

# def lcm(n,m):
#     return int(n*m/gcd(n,m))

# def reduce(p, q):
#     common = fractions.gcd(p, q)
#     return (p//common , q//common )

# def combinations_count(n, r):
#     r = min(r, n - r)
#     numer = reduce(mul, range(n, n - r, -1), 1)
#     denom = reduce(mul, range(1, r + 1), 1)
#     return numer // denom

# import random
# import time


def main():
    n, m = map(int, input().strip().split())
    a = [input().strip() for _ in range(n)]
    b = [input().strip() for _ in range(m)]
    success_flag = 0
    for i in range(n - m):
        for j in range(n - m):
            failure_flag = 0
            for l in range(m):
                if a[i + l][j:j + m] != b[l]:
                    failure_flag = 1
            if failure_flag == 0:
                success_flag = 1
                print("Yes")

    print("No")
    return


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from __future__ import print_function

import sys
input = sys.stdin.readline


def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)
    return


# import re
# import array
# import copy
# import functools
# import operator

# import math
# import string
# import fractions
# from fractions import Fraction
from fractions import gcd

# import collections
# import itertools
# import bisect

# import heapq
# from heapq import heappush
# from heapq import heappop
# from heapq import heappushpop
# from heapq import heapify
# from heapq import heapreplace
# from queue import PriorityQueue as pq
from queue import Queue

# from itertools import accumulate

# from collections import deque
# from collections import Counter

# from operator import mul
# from functools import reduce

# def lcm(n,m):
#     return int(n*m/gcd(n,m))

# def reduce(p, q):
#     common = fractions.gcd(p, q)
#     return (p//common , q//common )

# def combinations_count(n, r):
#     r = min(r, n - r)
#     numer = reduce(mul, range(n, n - r, -1), 1)
#     denom = reduce(mul, range(1, r + 1), 1)
#     return numer // denom

# import random
# import time


def main():
    n, m = map(int, input().strip().split())
    a = [input().strip() for _ in range(n)]
    b = [input().strip() for _ in range(m)]
    success_flag = 0
    for i in range(n - m):
        for j in range(n - m):
            failure_flag = 0
            for l in range(m):
                if a[i + l][j:j + m] != b[l]:
                    failure_flag = 1
            if failure_flag == 0:
                success_flag = 1

    if success_flag == 0:
        print("No")
    else:
        print("Yes")

    return


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from __future__ import print_function

import sys
input = sys.stdin.readline


def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)
    return


# import re
# import array
# import copy
# import functools
# import operator

# import math
# import string
# import fractions
# from fractions import Fraction
from fractions import gcd

# import collections
# import itertools
# import bisect

# import heapq
# from heapq import heappush
# from heapq import heappop
# from heapq import heappushpop
# from heapq import heapify
# from heapq import heapreplace
# from queue import PriorityQueue as pq
from queue import Queue

# from itertools import accumulate

# from collections import deque
# from collections import Counter

# from operator import mul
# from functools import reduce

# def lcm(n,m):
#     return int(n*m/gcd(n,m))

# def reduce(p, q):
#     common = fractions.gcd(p, q)
#     return (p//common , q//common )

# def combinations_count(n, r):
#     r = min(r, n - r)
#     numer = reduce(mul, range(n, n - r, -1), 1)
#     denom = reduce(mul, range(1, r + 1), 1)
#     return numer // denom

# import random
# import time


def main():
    n, m = map(int, input().strip().split())
    a = [input().strip() for _ in range(n)]
    b = [input().strip() for _ in range(m)]
    success_flag = 0
    for i in range(n - m):
        for j in range(n - m):
            failure_flag = 0
            for l in range(m):
                if a[i + l][j:j + m] != b[l]:
                    failure_flag = 1
            if failure_flag == 0:
                success_flag = 1

    if success_flag == 0:
        print("no")
    else:
        print("Yes")

    return


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#python3

def main():
    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):
        for j in range(n-m+1):
            for l in a[i:i+m]:
                for k in b:
                    if k == l[j:j+m]:
                        flag = True
                
    
    if flag:
        print('Yes')
    else:
        print('No')
main()

Submission status: Wrong Answer

Solution code:
#python3

            
def comp(array1, array2, a, b, m):
    f = False
    for i in array1[a:a+m]:
        for j in array2: 
            if i[b:b+m] == j:
                f = True
    return f

def main():
    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):
        for j in range(n-m):
            if comp(a, b, i, j, m):
                flag = True      
                break

    
    if flag:
        print('Yes')
    else:
        print('No')
main()

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

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

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

#二次元配列の部分配列を抽出する
for i in range(n-m):
    for j in range(n-m):
        if [l[i:m+i] for l in a[i:m+i]]==b:
            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)]

#二次元配列の部分配列を抽出する手法
#[l[i:m+i] for l in a[i:m+i]]
if m==1:
    for i in range(n):
        if b[0] in a[i]:
            print('Yes')
            exit()

    print('No')
    exit()

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

#二次元配列の部分配列を抽出する手法
#[l[i:m+i] for l in a[i:m+i]]
for i in range(n-m):
    for j in range(n-m):
        if [l[i:m+i] for l in a[i:m+i]]==b:
            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)]

ans = "No"
for i in range(M):
  n = []
  for j in range(N):
    if B[i] in A[j]:
      if len(n) == 0 or len(n) > 0 and  i == n[-1] + 1:
        n.append(j)
        if len(n) == M:
          ans = "Yes"
      else:
        break

print(ans)

Submission status: Wrong Answer

Solution code:
def find_indices(a, b, L):
    # aからbのパターンをみつける
    return [i for i in range(L) if b in a[i:]]

def solve():
    N,M = map(int, input().split())
    A = [input() for _ in range(N)]
    B = [input() for _ in range(M)]
    idx = 0
    start_pos = {}
    for S_a in A:
        indices = set(find_indices(S_a, B[idx], N))
        if not start_pos:
            start_pos = indices
        else:
            start_pos = start_pos&indices
        
        if start_pos:
            idx += 1
        else:
            start_pos = {}
            idx = 0
            
        if idx == M:
            break
    
    print('Yes' if start_pos else 'No')
    
solve()

Submission status: Wrong Answer

Solution code:
import functools 

def find_indices(a, b, L):
    # aからbのパターンをみつける
    return [i for i in range(L) if b in a[i:]]

def solve():
    N,M = map(int, input().split())
    A = [input() for _ in range(N)]
    B = [input() for _ in range(M)]
    idx = 0
    start_pos = []
    for S_a in A:
        indices = find_indices(S_a, B[idx], N)
        
        if indices:
            start_pos.append(set(indices))
            idx += 1
        else:
            start_pos = []
            idx = 0
            
        if idx == M:
            break
    
    # print(start_pos)
    print('Yes' if start_pos and functools.reduce(lambda a,b:a&b, start_pos) else 'No')

solve()

Submission status: Wrong Answer

Solution code:
import functools 

def find_indices(a, b, L):
    # aからbのパターンをみつける
    return [i for i in range(L) if b in a[i:]]

def solve():
    N,M = map(int, input().split())
    A = [input() for _ in range(N)]
    B = [input() for _ in range(M)]
    idx = 0
    start_pos = []
    for S_a in A:
        indices = find_indices(S_a, B[idx], N)
        
        if indices:
            start_pos.append(set(indices))
            idx += 1
        else:
            start_pos = []
            idx = 0
            
        if idx == M:
            break
    
    # print(start_pos)
    print('Yes' if indices and functools.reduce(lambda a,b:a&b, start_pos) else 'No')
    
solve()

Submission status: Wrong Answer

Solution code:
import functools 

def find_indices(a, b, L):
    # aからbのパターンをみつける
    return [i for i in range(L) if b in a[i:]]

def solve():
    N,M = map(int, input().split())
    A = [input() for _ in range(N)]
    B = [input() for _ in range(M)]
    idx = 0
    start_pos = []
    for S_a in A:
        indices = find_indices(S_a, B[idx], N)
        
        if indices:
            start_pos.append(set(indices))
            idx += 1
        else:
            start_pos = []
            idx = 0
            
        if idx == M:
            break
    
    # print(start_pos)
    print('Yes' if indices and functools.reduce(lambda a,b:a&b, start_pos) else 'No')

Submission status: Wrong Answer

Solution code:
def check():
    N,M = map(int, input().split())
    A = [input() for _ in range(N)]
    B = [input() for _ in range(M)]
    
    for i in range(N-M+1):
        for j in range(N-M+1):
            flag = True
            for k in range(M):
                if A[i+k][j:j+2] != B[k]:
                    flag = False
            if flag:
                return 'Yes'
    return 'No'
  
print(check())

Submission status: Wrong Answer

Solution code:
N, M = [int(i) for i in 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 ii in range(M):
            for jj in range(M):
                if A[i+ii][j+jj] != B[ii][jj]:
                    break
            else:
                continue
            break
        else:
            print("Yes")
            exit()
        break
print("No")

Submission status: Wrong Answer

Solution code:
N, M = [int(i) for i in 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 ii in range(M):
            for jj in range(M):
                if A[i+ii][j+jj] != B[ii][jj]:
                    break
            else:
                print("Yes")
                exit()
            break
print("No")