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 = (int(i) for i in input().split())
a = []
b = []
for i in range(N):
    data = list(input())
    a.append(data)
for i in range(M):
    data = list(input())
    b.append(data)
    
L = N-M

def check(i,j):
    ans=True
    for line in range(L+1):
        if (ans==False):
            break
        for row in range(L+1):
            if (a[i+line][j+row]!=b[line][row]):
                ans=False
                break
    return ans

ans=False
for i in range(L+1):
    if(ans==True):
        break
    for j in range(L+1):
        ansnow=check(i,j)
#        print(ansnow,i,j)
        if(ansnow==True):
            ans=True
            break
if(ans==True):
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

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

print(a[0])
    
L = N-M

def check(i,j):
    ans=True
    for line in range(L+1):
        for row in range(L+1):
            if (a[i+line][j+row]!=b[line][row]):
                ans=False
    return ans
                
for i in range(L+1):
    for j in range(L+1):
        ans=check(i,j)
        print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import product as prd

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


c = n - m + 1
ans = [list(map(lambda l: l[j:j+m], a[i:i+m])) for i, j in prd(range(c), range(c))]
print("Yes" if any(ans) else "No")

Submission status: Wrong Answer

Solution code:
from itertools import product as prd

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


c = n - m + 1
ans = [list(map(lambda l: l[j:j+m], a[i:i+m])) for i, j in prd(range(3), range(3))]
print("Yes" if any(ans) else "No")

Submission status: Wrong Answer

Solution code:
#coding: UTF-8
import sys
N,M=map(int,input().split())
Alist=[input() for i in range(0,N)]
Blist=[input() for i in range(0,M)]

def is_match(A,B,M):
    for i in range(0,M):
        if A[i]!=B[i]:
            return False
#            break
    return True

def make_A(A,i,j,M):
    C=[0]*M
    for k in range(0,M):
        C[k]=A[k+i][j:j+M]
    return C

for i in range(0,N-M):
    for j in range(0,N-M):
        C=make_A(Alist,i,j,M)
        if is_match(C,Blist,M):
            print("Yes")
            sys.exit()
print("No")

Submission status: Wrong Answer

Solution code:
#ABC054A
import sys

n,m=map(int,raw_input().split())
a=[]
b=[]
for i in xrange(n):
 a.append(raw_input())
for i in xrange(m):
 b.append(raw_input())
print a
print b
for i in xrange(m):
 if b[i] not in a[i]:
  print 'No'
  sys.exit()
 else:
  print 'Yes'
  sys.exit()

Submission status: Wrong Answer

Solution code:
import copy
import re

def judge(i, jlist, len):
    for l in jlist:
        k = 1
        while k < M:
            try:
                if n[i + 1][l:l + len] == m[k]:
                    pass
                else:
                    return 'No'
            except:
                return 'No'
            k += 1
        else:
            return 'Yes'

N, M = map(int, input().split())
i = 0
n = []
while i < N:
    n.append(input())
    i += 1

i = 0
m = []
while i < M:
    m.append(input())
    i += 1

i = 0
r = 'No'
while i < N:
    result = re.search(m[0], n[i])
    if result != None:
        r = judge(i, result.span(), len(m[0]))
        if r == 'Yes':
            break
    i += 1
print(r)

Submission status: Wrong Answer

Solution code:
import copy
import re

def judge(i, jlist, len):
    for l in jlist:
        k = 1
        while k < M:
            try:
                if n[i + 1][l:l + len] == m[k]:
                    pass
                else:
                    return 'No'
            except:
                return 'No'
            k += 1
        else:
            return 'Yes'

N, M = map(int, input().split())
i = 0
n = []
while i < N:
    n.append(input())
    i += 1

i = 0
m = []
while i < M:
    m.append(input())
    i += 1

i = 0
r = 'No'
while i < N:
    result = re.search(m[0], n[i])
    if result != None:
        r = judge(i, result.span(), len(m[0]))
    i += 1
print(r)

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

def LI(): return list(map(int, input().split()))
def II(): return int(input())
def LS(): return input().split()
def S(): return input()


def main():
    n,m = LI()
    a = []
    for i in range(n):
        t = 0
        for c in S():
            t <<= 1
            if c == '#':
                t += 1
        a.append(t)

    b = []
    for i in range(m):
        t = 0
        for c in S():
            t <<= 1
            if c == '#':
                t += 1
        b.append(t)

    mask = 2**m-1
    for i in range(n-m+1):
        for j in range(n-m+1):
            f = True
            for k in range(m):
                ak = (a[k+j] >> i) & mask
                if ak != b[k]:
                    f = False
                    break
            if f:
                return 'YES'
    return 'NO'


print(main())

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
# スペース区切りの整数の入力
checker = True

n, m = map(int, raw_input().split())
N = []
M = []
counter = 0
ans = "No"
flag = 0
while checker:
    tmp = raw_input()
    if counter < n:
        N.append(tmp)
    else:
        M.append(tmp)
    counter += 1
    if counter == n + m:
        break

if M[0].find(N[0]) > -1:
    flag = 1
    start = M[0].find(N[0]) #開始文字列index
    for st in M:
        for stm in N:
            ch = st.find(stm)
            if ch != start:      
                flag = 0           
ans = "Yes" if flag == 1 else "No"
# 出力
print ans

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
# スペース区切りの整数の入力
checker = True

n, m = map(int, raw_input().split())
N = []
M = []
counter = 0
ans = "No"
while checker:
    tmp = raw_input()
    if counter < n:
        N.append(tmp)
    else:
        M.append(tmp)
    counter += 1
    if counter == n + m:
        break

for st in M:
    for stm in N:
        if st in stm:
            ans = "Yes"
# 出力
print ans

Submission status: Wrong Answer

Solution code:
import copy
N, M = map(int, input().split())
i = 0
n = []
while i < N:
    n.append(input())
    i += 1

i = 0
m = []
while i < M:
    m.append(input())
    i += 1

yn = -1
m_idx = 0
for s in n:
    idx = s.find(m[m_idx])
    if idx > -1:
        if m_idx == 0:
            yn = copy.deepcopy(idx)
            m_idx += 1
        elif idx != yn:
            m_idx = 0
            yn = -1
        else:
            m_idx += 1
    else:
        yn = -1
        m_idx = 0
    if m_idx == M:
        print('Yes')
        break
else:
    print('No')

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
i = 0
n = []
while i < N:
    s = str(input())
    n.append(s)
    i += 1

i = 0
m = []
while i < M:
    m.append(input())
    i += 1

yn = -1
m_idx = 0
for s in n:
    idx = s.find(m[m_idx])
    if idx > -1:
        if m_idx == 0:
            yn = idx
            m_idx += 1
        elif idx != yn:
            m_idx = 0
            yn = -1
        else:
            m_idx += 1
    else:
        yn = -1
        m_idx = 0
    if m_idx == M:
        print('Yes')
        break
else:
    print('No')

Submission status: Wrong Answer

Solution code:
import sys

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

cl = [[] for i in range(n - m + 1)]
for i in range(n - m + 1):
    for j in range(m):
        if not a[i].find(b[j]) == -1:
            c = a[i].find(b[j])
            cl[c].append(j)


if n == m:
    if cl == [list(range(n))]:
        print("Yes")
        sys.exit()
    else:
        print("No")
        sys.exit()
if m == 1:
    if not cl == [[]] * (n - m + 1):
        print("yes")
        sys.exit()
for cs in cl:
    if cs == [0]:
        print("Yes")
        sys.exit()
for ci in cl:
    if ci == list(range(m)) * (n - m):
        print("Yes")
        sys.exit()

print("No")

Submission status: Wrong Answer

Solution code:
import sys

input_num = input().split()
N = int(input_num[0])
M = int(input_num[1])

AB = [input() for i in range(0, N + M)]
A = AB[0: N]
B = AB[N:]

diff = N - M
matches = []
for i in range(0, diff+1):
    l = 0
    while N - l > diff:
        index = A[i][l:].find(B[0])
        if index != -1 and i <= diff:
            matches.append((index, l, i))
        l += 1
if len(matches) == 0:
    print("No")
    sys.exit()
print(matches)
count_no = []
for m, l, i in matches:
    for a, b in zip(A[i:], B):
        if a[l:].find(b) != m:
            count_no.append(0)
            break
if len(count_no) == len(matches):
    print("No")
else:
    print("Yes")

Submission status: Wrong Answer

Solution code:
n,m = map(int, raw_input().split())
n_list = [] #row major format
m_list = []
for i in range(0, n):
	n_list.append(raw_input())
 
for x in range(0, m):
	m_list.append(raw_input())
 
def match_first_rows(n_start):
	result = (-1,-1)
	first_m = m_list[0] # first row
	for x in range(n_start, n):
		n_row = n_list[x]
		if first_m in n_row: # substring matching of first m_row
			j = n_row.index(first_m)
			return (x, j)
	return (-1,-1) #return -1,-1 if none found
 
# given the leftmost corner of matching in matrix n, start matching each row to see if there is a potential match
# only guranteed first row match
def begin_matching(i,j):
	nx_start = i
	ny_start = j
	for x in range(0,m):
		n_row_string = n_list[nx_start+x]
		n_string = n_row_string[j:j+m] # align window
		m_string = m_list[x]
		if n_string!=m_string:
			return False
	return True
 
def find_m():
 
	found_m = False
	counter = 0
	while(counter<=n-m and not(found_m)):
 
		i,j = match_first_rows(counter)
		if i==-1: 
			#goes through entirety, not returning things at all
			print("No")
			found_m = True
		# found a potential starting point
		else:
			result = begin_matching(i,j)
			if result:
				print("Yes")
				found_m = True
			else:
				#do it again, but one row lower
				counter +=1 
 
find_m()

Submission status: Wrong Answer

Solution code:
import sys

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

cl = [[] for i in range(n - m + 1)]
for i in range(n - m + 1):
    for j in range(m):
        if not a[i].find(b[j]) == -1:
            c = a[i].find(b[j])
            cl[c].append(j)

if n == m:
    if cl == [[0]]:
        print("Yes")
        sys.exit()
    else:
        print("No")
        sys.exit()
if m == 1:
    if not cl == [[]] * (n - m + 1):
        print("yes")
        sys.exit()
for cs in cl:
    if cs == [0]:
        print("Yes")
        sys.exit()
for ci in cl:
    if ci == list(range(m)) * (n - m):
        print("Yes")
        sys.exit()

print("No")

Submission status: Wrong Answer

Solution code:
import sys
n,m = map(int,raw_input().split())
a = [[0 for i in range(n)] for j in range(n)]
b = [[0 for i in range(m)] for j in range(m)]
z = []
for i in range(n):
    at = list(raw_input())
    a[i] = at
for i in range(m):
    at = list(raw_input())
    b[i] = at
if n == m:
        if a == b:
            print "Yes"
            sys.exit(0)
        else:
            print "No"
            sys.exit(0)
temp = [[0 for r in range(m)] for z in range(m)]
for i in range(n-m+1):
    for j in range(n-m+1):
        for k in range(m):
            temp[k] = a[k][j:j+m]
        if temp == b:
            print "Yes"
            sys.exit(0)
        else:
            temp = [[0 for r in range(m)] for z in range(m)]
print "No"

Submission status: Wrong Answer

Solution code:
import sys

count = 0
N_list = []
M_list = []
for line in sys.stdin:
    line = line.rstrip("\n")
    if count == 0:
        line = line.split(" ")
        N = int(line[0])
        M = int(line[1])
    elif count <= N:
        N_list.append(line)
    else:
        M_list.append(line)
    count+=1
    
    
def judge_match(N_l, M_l):
    slide_count = len(N_l[0]) - len(M_l[0]) + 1
    count = 0
    for j in range(slide_count):
        count = 0
        for i in range(len(N_l)):
            if N_l[i][j:len(M_l[0])] == M_l[i]:
                count += 1
                if count == len(M_l):
                    return count
    return count

m_count = 0
for i in range(len(N_list)):
    m_count = judge_match(N_list[i:i+len(M_list)], M_list)
    if m_count == len(M_list):
        print("Yes")
        exit(0)
print("No")

Submission status: Wrong Answer

Solution code:
import sys

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

cl = [[] for i in range(n - m + 1)]
for i in range(n - m + 1):
    for j in range(m):
        if not a[i].find(b[j]) == -1:
            c = a[i].find(b[j])
            cl[c].append(j)

if m == 1:
    if not cl == [[]] * (n - m + 1):
        print("yes")
        sys.exit()
if n == m:
    if cl == [[0]]:
        print("Yes")
        sys.exit()

for cs in cl:
    if cs == [0]:
        print("Yes")
        sys.exit()
for ci in cl:
    if ci == list(range(m)) * (n - m):
        print("Yes")
        sys.exit()

print("No")

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
i = 0
n = []
while i < N:
    s = str(input())
    n.append(s)
    i += 1

i = 0
m = []
while i < M:
    m.append(input())
    i += 1

yn = -1
m_idx = 0
for s in n:
    idx = s.find(m[m_idx])
    if idx > -1:
        if m_idx == 0:
            yn = idx
            m_idx += 1
        elif idx != yn:
            m_idx = 0
            yn = -1
        else:
            m_idx += 1
    if m_idx == M:
        print('Yes')
        break
else:
    print('No')

Submission status: Wrong Answer

Solution code:

n, m = map(int, raw_input().split())
a = [raw_input() for _ in xrange(n)]
b = [raw_input() for _ in xrange(m)]
f = False
for i in xrange(m):
    if b[i] in a:
        f = True

if f:
    print "Yes"
else:
    print "No"

Submission status: Wrong Answer

Solution code:
import sys
n,m = map(int,raw_input().split())
a = [[0 for i in range(n)] for j in range(n)]
b = [[0 for i in range(m)] for j in range(m)]
z = []
for i in range(n):
    at = list(raw_input())
    a[i] = at
for i in range(m):
    at = list(raw_input())
    b[i] = at
if n == m:
        if a == b:
            print "Yes"
            sys.exit(0)
        else:
            print "No"
            sys.exit(0)
temp = [[0 for i in range(m)] for j in range(m)]
for i in range(n-m+1):
    for j in range(n-m+1):
        for k in range(m):
            temp[k] = a[k][j:j+m]
        print temp
        if temp == b:
            print "Yes"
            sys.exit(0)
        else:
            temp = [[0 for r in range(m)] for z in range(m)]
print "No"

Submission status: Wrong Answer

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

allFlag = 0
for i in range(n-m+1):
    for j in range(n-m+1):
        if ns[i][j:j+m] == ms[0]:
            Flag = 1
            for k in range(m):
                if ns[i+k][j:j+m]!=ms[k]:
                    Flag = 0
            if Flag:
                print("Yes")
                allFlag = 1
if not allFlag:
    print("No")

Submission status: Wrong Answer

Solution code:
import sys

input_num = input().split()
N = int(input_num[0])
M = int(input_num[1])

AB = [input() for i in range(0, N + M)]
A = AB[0: N]
B = AB[N:]

diff = N - M
matches = []
for i in range(0, diff+1):
    index = A[i].find(B[0])
    if index != -1 and i <= diff:
        matches.append((index, i))
if len(matches) == 0:
    print("No")
    sys.exit()
count_no = []
for m, i in matches:
    for a, b in zip(A[i:], B):
        if a.find(b) != m:
            count_no.append(0)
            break
if len(count_no) == len(matches):
    print("No")
else:
    print("Yes")

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
i = 0
n = []
while i < N:
    s = str(input())
    n.append(s)
    i += 1

i = 0
m = []
while i < M:
    m.append(input())
    i += 1

yn = -1
m_idx = 0
for s in n:
    idx = s.find(m[m_idx])
    if idx > -1:
        if m_idx == 0:
            yn = idx
            m_idx += 1
        elif idx != yn:
            m_idx = 0
            yn = -1
        else:
            m_idx += 1
    if m_idx == M - 1 and idx > -1:
        print('Yes')
        break
else:
    print('No')

Submission status: Wrong Answer

Solution code:

if __name__ == '__main__':

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

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

    char = B[0][0]
    matc = False
    for i in range(N-M+1):
        for j in range(N-M+1):
            if A[i][j] == char:
                matc = True
                for k in range(M):
                    for l in range(M):
                        if A[i+k][j+l] == B[k][l]:
                            matc = True
                        else:
                            matc = False
                            break
                    if not matc:
                        break

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

Submission status: Wrong Answer

Solution code:
import sys

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

cl = [[] for i in range(n - m + 1)]
for i in range(n - m + 1):
    for j in range(m):
        if not a[i].find(b[j]) == -1:
            cl[i].append(j)

# print(cl)
if n == m:
    if cl == [[0]]:
        print("Yes")
        sys.exit()
    else:
        print("No")
        sys.exit()

for cs in cl:
    if cs == [0]:
        print("Yes")
        sys.exit()
for ci in cl:
    if ci == list(range(m)) * (n - m):
        print("Yes")
        sys.exit()

print("No")

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
i = 0
n = []
while i < N:
    s = str(input())
    n.append(s)
    i += 1

i = 0
m = []
while i < M:
    m.append(input())
    i += 1

yn = -1
m_idx = 0
for s in n:
    idx = s.find(m[m_idx])
    if idx > -1:
        if m_idx == 0:
            yn = idx
            m_idx += 1
        elif idx != yn:
            m_idx = 0
            yn = -1
    if m_idx == M - 1 and idx > -1:
        print('Yes')
        break
else:
    print('No')

Submission status: Wrong Answer

Solution code:
import sys

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

cl = [[] for i in range(n - m + 1)]
for i in range(n - m + 1):
    for j in range(m):
        if not a[i].find(b[j]) == -1:
            cl[i].append(j)

if n == m and cl == [[0]]:
    print("Yes")
    sys.exit()
else:
    print("No")
    sys.exit()

for cs in cl:
    if cs == [0]:
        print("Yes")
        sys.exit()
for ci in cl:
    if ci == list(range(m)) * (n - m):
        print("Yes")
        sys.exit()

print("No")

Submission status: Wrong Answer

Solution code:
if __name__ == '__main__':

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

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

    char = B[0][0]
    matc = False
    for i in range(N-M+1):
        for j in range(N-M+1):
            if A[i][j] == char:
                for k in range(M):
                    for l in range(M):
                        if A[i+k][j+l] == B[k][l]:
                            matc = True
                        else:
                            matc = False
                            break
                    if not matc:
                        break

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

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
i = 0
n = []
while i < N:
    s = str(input())
    n.append(s)
    i += 1

i = 0
m = []
while i < M:
    m.append(input())
    i += 1

yn = -1
m_idx = 0
for s in n:
    idx = s.find(m[m_idx])
    if idx > -1:
        if m_idx == 0:
            m_idx += 1
            yn = idx
        elif idx != yn:
            yn = -1
    if m_idx == M - 1 and idx > -1:
        print('Yes')
        break
else:
    print('No')

Submission status: Wrong Answer

Solution code:
import sys

input_num = input().split()
N = int(input_num[0])
M = int(input_num[1])

AB = [input() for i in range(0, N + M)]
A = AB[0: N]
B = AB[N:]

diff = N - M
matches = []
for i in range(0, diff+1):
    index = A[i].find(B[0])
    if index != -1:
        matches.append((index, i))
if len(matches) == 0:
    print("No")
    sys.exit()
count_no = []
for m, i in matches:
    for l in range(0, len(B)):
        if A[l+i].find(B[l]) != m:
            count_no.append(0)
            break
if len(count_no) == len(matches):
    print("No")
else:
    print("Yes")

Submission status: Wrong Answer

Solution code:
import sys

input_num = input().split()
N = int(input_num[0])
M = int(input_num[1])

AB = [input() for i in range(0, N + M)]
A = AB[0: N]
B = AB[N:]

diff = N - M
matches = []
for i in range(0, diff+1):
    index = A[i].find(B[0])
    if index != -1:
        matches.append((index, i))
if len(matches) == 0:
    print("No")
    sys.exit()
count_no = []
for m, i in matches:
    for l in range(0, len(B)):
        if A[l+i].find(B[l]) != m:
            count_no.append(0)
            break
if count_no == len(matches):
    print("No")
else:
    print("Yes")

Submission status: Wrong Answer

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

for x in range(n):
    a.append(list(input()))

for y in range(m):
    b.append(list(input()))


def check_photo(base, target):
    for i in range(n-m+1):
        check = base[i:i+m+1]
#        print(check)
        for j in range(n-m+1):
            check = [line[j:j+m+1] for line in check]
#            print(check)
            if check == target:
                return print('Yes')
    return print('No')

check_photo(a, b)

Submission status: Wrong Answer

Solution code:
import sys

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

cl = [[] for i in range(n - m + 1)]
for i in range(n - m + 1):
    for j in range(m):
        if not a[i].find(b[j]) == -1:
            cl[i].append(j)

for cs in cl:
    if cs == [0]:
        print("Yes")
        sys.exit()
for ci in cl:
    if ci == list(range(m)) * (n - m):
        print("Yes")
        sys.exit()

print("No")

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
i = 0
n = []
while i < N:
    s = str(input())
    n.append(s)
    i += 1

i = 0
m = []
while i < M:
    m.append(input())
    i += 1

m_idx = 0
for s in n:
    idx = s.find(m[m_idx])
    if idx > -1:
        if m_idx < M - 1:
            m_idx += 1
    if m_idx == M - 1 and idx > -1:
        print('Yes')
        break
else:
    print('No')

Submission status: Wrong Answer

Solution code:
import sys

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

cl = [[] for i in range(n - m + 1)]
for i in range(n - m + 1):
    for j in range(m):
        if not a[i].find(b[j]) == -1:
            cl[i].append(j)
print(cl)
for cs in cl:
    if cs == [0]:
        print("Yes")
        sys.exit()
for ci in cl:
    if ci == list(range(m)) * (n - m):
        print("Yes")
        sys.exit()

print("No")

Submission status: Wrong Answer

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

for x in range(n):
    a.append(list(input()))

for y in range(m):
    b.append(list(input()))


def check_photo(base, target):
    for i in range(n-m+2):
        check = base[i:i+m]
#        print(check)
        for j in range(n-m+2):
            check = [line[j:j+m] for line in check]
#            print(check)
            if check == target:
                return print('Yes')
    return print('No')

check_photo(a, b)

Submission status: Wrong Answer

Solution code:
if __name__ == '__main__':

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

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

    char = B[0][0]
    matc = False
    for i in range(N-M+1):
        for j in range(N-M+1):
            if A[i][j] == char:
                for (y,k) in enumerate(range(i,M)):
                    for (x,l) in enumerate(range(j,M)):
                        if A[k][l] == B[y][x]:
                            matc = True
                        else:
                            matc = False
                            break
                    if not matc:
                        break

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

Submission status: Wrong Answer

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

for x in range(n):
    a.append(list(input()))

for y in range(m):
    b.append(list(input()))


def check_photo(base, target):
    for i in range(n-m+1):
        check = base[i:i+m]
#        print(check)
        for j in range(n-m+1):
            check = [line[j:j+m] for line in check]
#            print(check)
            if check == target:
                return print('Yes')
    return print('No')

check_photo(a, b)

Submission status: Wrong Answer

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

for x in range(n):
    a.append(list(input()))

for y in range(m):
    b.append(list(input()))


def check_photo(base, target):
    for i in range(n-m):
        check = base[i:i+m]
#        print(check)
        for j in range(n-m):
            check = [line[j:j+m] for line in check]
#            print(check)
            if check == target:
                return print('Yes')
    return print('No')

check_photo(a, b)

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 = "No"
print(a, b)

for i in range(n - m + 1):
    for j in range(n - m + 1):
        if a[i][j] == b[0][0]:
            c = []
            for k in range(m):
                c.append(a[i + k][j:j + m])
            if c == b:
                ans = "Yes"
print(ans)

Submission status: Wrong Answer

Solution code:
import sys

input_num = input().split()
N = int(input_num[0])
M = int(input_num[1])

AB = [input() for i in range(0, N + M)]
A = AB[0: N]
B = AB[N:]

diff = N - M
breaked = 0
index = 0
for i in range(0, len(A)-1):
    l = i
    while l <= i + diff and l < len(B):
        ind = A[i].find(B[l])
        if ind != -1:
            if breaked > 0 and index != ind:
                print("No")
                sys.exit()
            index = ind
            breaked += 1
            break
        else:
            if breaked > 0:
                print("No")
                sys.exit()
            l += 1
if breaked == len(B):
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
if __name__ == '__main__':

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

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

    char = B[0][0]
    matc = False
    for i in range(N-M+1):
        for j in range(N-M+1):
            if A[i][j] == char:
                for k in range(i,M):
                    for l in range(j,M):
                        if A[k][l] == B[k][l]:
                            matc = True
                        else:
                            matc = False
                            break
                    if not matc:
                        break

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

Submission status: Wrong Answer

Solution code:
import sys
n,m = map(int,raw_input().split())
a = [[0 for i in range(n)] for j in range(n)]
b = [[0 for i in range(m)] for j in range(m)]
z = []
for i in range(n):
    at = list(raw_input())
    a[i] = at
for i in range(m):
    at = list(raw_input())
    b[i] = at
if n == m:
        if a == b:
            print "Yes"
            sys.exit(0)
        else:
            print "No"
            sys.exit(0)
temp = [[0 for i in range(m)] for j in range(m)]
for i in range(n-m):
    for j in range(n-m):
        for k in range(m):
            temp[k] = a[i+k][j:j+m]
        if temp == b:
            print "Yes"
            sys.exit(0)
        else:
            temp = [[0 for i in range(m)] for j in range(m)]
print "No"

Submission status: Wrong Answer

Solution code:
import sys
n,m = map(int,raw_input().split())
a = [[0 for i in range(n)] for j in range(n)]
b = [[0 for i in range(m)] for j in range(m)]
z = []
for i in range(n):
    at = list(raw_input())
    a[i] = at
for i in range(m):
    at = list(raw_input())
    b[i] = at
if n == m:
        if a == b:
            print "Yes"
            sys.exit(0)
        else:
            print "No"
temp = [[0 for i in range(m)] for j in range(m)]
for i in range(n-m):
    for j in range(n-m):
        for k in range(m):
            temp[k] = a[i+k][j:j+m]
        if temp == b:
            print "Yes"
            sys.exit(0)
        else:
            temp = [[0 for i in range(m)] for j in range(m)]
print "No"

Submission status: Wrong Answer

Solution code:
import sys

input_num = input().split()
N = int(input_num[0])
M = int(input_num[1])

AB = [input() for i in range(0, N + M)]
A = AB[0: N]
B = AB[N:]

diff = N - M
breaked = 0
index = 0
for i in range(0, len(A)-1):
    l = i
    while l <= i + diff and l < len(B):
        ind = A[i].find(B[l])
        if ind != -1:
            if breaked > 0 and index != ind:
                print("No")
            index = ind
            breaked += 1
            break
        else:
            if breaked > 0:
                print("No")
                sys.exit()
            l += 1
if breaked == len(B):
    print("Yes")
else:
    print("No")