Problem:


Score: 300 points

Problem Statement

We have a canvas divided into a grid with H rows and W columns. The square at the i-th row from the top and the j-th column from the left is represented as (i, j).

Initially, all the squares are white. square1001 wants to draw a picture with black paint. His specific objective is to make Square (i, j) black when s_{i, j}= #, and to make Square (i, j) white when s_{i, j}= ..

However, since he is not a good painter, he can only choose two squares that are horizontally or vertically adjacent and paint those squares black, for some number of times (possibly zero). He may choose squares that are already painted black, in which case the color of those squares remain black.

Determine if square1001 can achieve his objective.  

Constraints

H is an integer between 1 and 50 (inclusive).

W is an integer between 1 and 50 (inclusive).

For every (i, j) (1 \leq i \leq H, 1 \leq j \leq W), s_{i, j} is # or ..

Input

Input is given from Standard Input in the following format:

H W
s_{1, 1} s_{1, 2} s_{1, 3} ... s_{1, W}
s_{2, 1} s_{2, 2} s_{2, 3} ... s_{2, W}
  :   :
s_{H, 1} s_{H, 2} s_{H, 3} ... s_{H, W}

Output

If square1001 can achieve his objective, print Yes; if he cannot, print No.

Sample Input 1

3 3
.#.
###
.#.

Sample Output 1

Yes

One possible way to achieve the objective is shown in the figure below. Here, the squares being painted are marked by stars.

Sample Input 2

5 5
#.#.#
.#.#.
#.#.#
.#.#.
#.#.#

Sample Output 2

No

square1001 cannot achieve his objective here.

Sample Input 3

11 11
...#####...
.##.....##.
#..##.##..#
#..##.##..#
#.........#
#...###...#
.#########.
.#.#.#.#.#.
##.#.#.#.##
..##.#.##..
.##..#..##.

Sample Output 3

Yes



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


Sample output:
Yes

Submission status: Runtime Error

Solution code:
h , w = (int(i) for i in input().split())
a =[]
dy = [0, 0, 1, -1]
dx = [1, -1, 0, 0]


for i in range(w):
    a.append(input())
    
f = True
def check(x,y):
    if a[x][y] =='.':
        return True
    for n in range(4):
        i = dx[n]
        j = dy[n]
        if 0 <= x+i < h and 0 <= y + j < w and a[x+i][y+j]=='#':
            #print(x+i,y+j)
            return True
        return False


f = True
for i in range(w):
    for j in range(h):
        l = check(i,j)
        if not(l) and f:
                print ("No")
                f = False
                
if(f):
    print("Yes")

Submission status: Runtime Error

Solution code:
h , w = (int(i) for i in input().split())
a =[]
dy = [0, 0, 1, -1]
dx = [1, -1, 0, 0]


for i in range(w):
    a.append(input())
    
f = True
def check(x,y):
    if a[x][y] =='.':
        return True
    for n in range(4):
        i = dx[n]
        j = dy[n]
        if 0 <= x+i < h and 0 <= y + j < w and a[x+i][y+j]=='#':
            #print(x+i,y+j)
            return True
        return False

print(check(0,0))
f = True
for i in range(w):
    for j in range(h):
        l = check(i,j)
        if not(l) and f:
                print ("No")
                f = False
                
if(f):
    print("Yes")

Submission status: Runtime Error

Solution code:
h, w = map(int, input().split())
s = []
for _ in range(h):
    si = list(input())
    s.append(si[:-1])

flag = 1

for hi in range(h):
    for wi in range(w):
        black = 0
        if s[hi][wi] == '#':
            if hi > 0:
                if s[hi-1][wi] == '#':
                    black += 1
            if wi > 0:
                if s[hi][wi-1] == '#':
                    black += 1
            if hi < h-1:
                if s[hi+1][wi] == '#':
                    black += 1
            if wi < w-1:
                if s[hi][wi+1] == '#':
                    black += 1
            
            if black == 0:
                flag = 0
                break
    
    if flag == 0:
        break

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

Submission status: Runtime Error

Solution code:
H, W = (int(i) for i in input().split())
t = []
t.append(['.']*(H+2))

for j in range(H):
	tmp = input()
	tmp = '.' + tmp + '.'
	t.append(list(tmp))

t.append(['.']*(H+2))

def CheckBlock(i,k):
	if t[i][k-1] == '#': #check up
		return 0
	elif t[i-1][k] == '#': #check left
		return 1
	elif t[i+1][k] == '#': #check right
		return 2
	elif t[i][k+1] == '#': #check down
		return 3
	else:
		return 4

for i in range(1,W+1):
	for k in range(1,H+1):
		if t[i][k] == '#':
			marker = CheckBlock(i,k)
			#ChangeBlock(i,k,marker)
			if marker == 4:
				print('No')
				quit()
print('Yes')

Submission status: Runtime Error

Solution code:
H, W = input().split(" ")
H = int(H)
W = int(W)

s = []
for i in range(W):
    s.append([1 if num=="#" else 0 for num in list(input())])

decision = True

for i in range(W):
    for j in range(H):
        if s[i][j] == 1:
            if i == 0 and j == 0:
                if s[i+1][j]==0 and s[i][j+1]==0:
                    decision=False
                    break
            elif i == 0 and j == H-1:
                if  s[i][j-1]==0 and s[i+1][j]==0:
                    decision=False
                    break
            elif i == 0:
                if  s[i][j-1]==0 and s[i+1][j]==0 and s[i][j+1]==0:
                    decision=False
                    break
            elif j == 0 and i == W-1:
                if s[i-1][j]==0 and s[i][j+1]==0:
                    decision=False
                    break
            elif j == 0:
                if s[i-1][j]==0 and s[i+1][j]==0 and s[i][j+1]==0:
                    decision=False
                    break
            elif i == W-1 and j==H-1:
                if s[i-1][j]==0 and s[i][j-1]==0:
                    decision=False
                    break
            elif i == W-1:
                if s[i-1][j]==0 and s[i][j-1]==0 and s[i][j+1]==0:
                    decision=False
                    break
            elif j == H-1:
                if s[i-1][j]==0 and s[i][j-1]==0 and s[i+1][j]==0:
                    decision=False
                    break
            else:
                if s[i-1][j]==0 and s[i][j-1]==0 and s[i+1][j]==0 and s[i][j+1]==0:
                    decision=False
                    break

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

Submission status: Runtime Error

Solution code:
from collections import deque

H, W = list(map(int, input().split()))

s = deque()

for i in range(H):
    s.append(input())

frg = 0

for i in range(1, H-2):
    if s[0][i] == s[0][i-1] or s[0][i] == s[1][i-1] or s[0][i] == s[0][i+1] or s[H-1][i] == s[H-1][i-1] or s[H-1][i] == s[H-2][i] or s[H-1][i] == s[H-1][i+1]:
        pass
    else:
        frg = 1
        
for i in range(1, W-2):
    if s[i][0] == s[i-1][0] or s[i][0] == s[i-1][1] or s[i][0] == s[i+1][0] or s[i][W-1] == s[i-1][W-1] or s[i][W-1] == s[i][W-2] or s[i][W-1] == s[i+1][W-1]:
        pass
    else:
        frg = 1
if frg == 0:
    for i in range(1, H-1):
        for l in range(1, W-1):
            if s[i][l] == s[i-1][l] or s[i][l] == s[i][l-1] or s[i][l] == s[i+1][l] or s[i][l] == s[i][l+1]:
                pass
            else:
                frg = 1
                break
        if frg == 1:
            break
    
if frg == 0:
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

Solution code:
H,W = list(map(int,input().split()))
temp = W
W = H
H = temp
import sys

block = [
    list(input()) for i in range(W)
]

isok = [[0] * H] * W

#middle
for i in range(1,H-1):
    for j in range(1,W-1):
        if block[i][i] == '.':
            continue
        else:
            if block[i+1][j] == '#' or block[i][j+1] == '#' or block[i-1][j] == '#' or block[i][j-1] == '#':
                continue
            else:
                print('No')
                sys.exit()

#left
for i in [0]:
    for j in range(1,W-1):
        if block[i][i] == '.':
            continue
        else:
            if block[i+1][j] == '#' or block[i][j+1] == '#' or block[i][j-1] == '#':
                continue
            else:
                print('No')
                sys.exit()

#top
for i in range(1,H-1):
    for j in [0]:
        if block[i][i] == '.':
            continue
        else:
            if block[i+1][j] == '#' or block[i][j+1] == '#' or block[i-1][j] == '#':
                continue
            else:
                print('No')
                sys.exit()

#right
for i in [H-1]:
    for j in range(1,W-1):
        if block[i][i] == '.':
            continue
        else:
            if block[i][j+1] == '#' or block[i-1][j] == '#' or block[i][j-1] == '#':
                continue
            else:
                print('No')
                sys.exit()

#bottom
for i in range(1,H-1):
    for j in [W-1]:
        if block[i][i] == '.':
            continue
        else:
            if block[i+1][j] == '#' or block[i-1][j] == '#' or block[i][j-1] == '#':
                continue
            else:
                print('No')
                sys.exit()

#TL
if block[0][0] == '#':
    if not(block[1][0] == '#' or block[0][1] == '#'):
        print('No')
        sys.exit()

#TR
if block[H-1][0] == '#':
    if not(block[H-2][0] == '#' or block[H-1][1] == '#'):
        print('No')
        sys.exit()

#BL
if block[0][W-1] == '#':
    if not(block[1][W-1] == '#' or block[0][W-2] == '#'):
        print('No')
        sys.exit()

#TL
if block[H-1][W-1] == '#':
    if not(block[H-2][W-1] == '#' or block[H-1][W-2] == '#'):
        print('No')
        sys.exit()



print('Yes')

Submission status: Runtime Error

Solution code:
H, W = map(int, input().split())
grid = []
soloList = []
soloGrid = ""
for _ in range(W):
    row = list(input())
    grid.append(row)

if H == 1 and W == 1:
    if grid[0][0] == ".":
        print("Yes")
    else:
        print("No")

elif H == 1:
    for j in range(H):  #列数ぶん繰り返すが一回だけ
        for i in range(W): #行数ぶん繰り返す＝一列当たりのマス数分
            if i == 0:
                if grid[i][j] == "#" and grid[i+1][j] == "." :
                    soloGrid = str(i) + ", " + str(j)
                    soloList.append(soloGrid)
                else:
                    pass
                
            elif i == W-1:
                if grid[i][j] == "#" and grid[i-1][j] == "." :
                    soloGrid = str(i) + ", " + str(j)
                    soloList.append(soloGrid)
                else:
                    pass
            else:
                if grid[i][j] == "#" and grid[i-1][j] == "." and grid[i+1][j] == ".":
                    soloGrid = str(i) + ", " + str(j)
                    soloList.append(soloGrid)
                else:
                    pass
    print(soloGrid)
    if soloList == []:
        print("Yes")
    else:
        print("No")

elif W == 1:
    for i in range(W): #行数ぶん繰り返す
        for j in range(H): #列数ぶん繰り返す＝一行当たりのマス数分
            if j == 0:
                if grid[i][j] == "#" and grid[i][j+1] == "." :
                    soloGrid = str(i) + ", " + str(j)
                    soloList.append(soloGrid)
                else:
                    pass
                
            elif j == H-1:
                if grid[i][j] == "#" and grid[i][j-1] == "." :
                    soloGrid = str(i) + ", " + str(j)
                    soloList.append(soloGrid)
                else:
                    pass

            else:
                if grid[i][j] == "#" and grid[i][j-1] == "." and grid[i][j+1] == ".":
                    soloGrid = str(i) + ", " + str(j)
                    soloList.append(soloGrid)
                else:
                    pass
    if soloList == []:
        print("Yes")
    else:
        print("No")
                
else:
    for i in range(W): #行数ぶん繰り返す
        for j in range(H): #列数ぶん繰り返す＝一行当たりのマス数分
            if j == 0:
                if grid[i][j] == "#" and grid[i][j+1] == "." :
                    soloGrid = str(i) + ", " + str(j)
                    soloList.append(soloGrid)
                else:
                    pass
                
            elif j == H-1:
                if grid[i][j] == "#" and grid[i][j-1] == "." :
                    soloGrid = str(i) + ", " + str(j)
                    soloList.append(soloGrid)
                else:
                    pass

            else:
                if grid[i][j] == "#" and grid[i][j-1] == "." and grid[i][j+1] == ".":
                    soloGrid = str(i) + ", " + str(j)
                    soloList.append(soloGrid)
                else:
                    pass

#次に縦列で連続しているかチェック
    for j in range(H):  #列数ぶん繰り返す
        for i in range(W): #行数ぶん繰り返す＝一列当たりのマス数分
            if i == 0:
                if grid[i][j] == "#" and grid[i+1][j] == "." :
                    soloGrid = str(i) + ", " + str(j)
                    soloList.append(soloGrid)
                else:
                    pass
                
            elif i == W-1:
                if grid[i][j] == "#" and grid[i-1][j] == "." :
                    soloGrid = str(i) + ", " + str(j)
                    soloList.append(soloGrid)
                else:
                    pass
            else:
                if grid[i][j] == "#" and grid[i-1][j] == "." and grid[i+1][j] == ".":
                    soloGrid = str(i) + ", " + str(j)
                    soloList.append(soloGrid)
                else:
                    pass
            
    if len(soloList) == len(set(soloList)):
        print("Yes")
    else:
        print("No")

Submission status: Runtime Error

Solution code:
H,W = list(map(int,input().split()))
import sys

block = [
    list(input()) for i in range(H)
]

isok = [[0] * H] * W

#middle
for i in range(1,H-1):
    for j in range(1,W-1):
        if block[i][i] == '.':
            continue
        else:
            if block[i+1][j] == '#' or block[i][j+1] == '#' or block[i-1][j] == '#' or block[i][j-1] == '#':
                continue
            else:
                print('No')
                sys.exit()

#left
for i in [0]:
    for j in range(1,W-1):
        if block[i][i] == '.':
            continue
        else:
            if block[i+1][j] == '#' or block[i][j+1] == '#' or block[i][j-1] == '#':
                continue
            else:
                print('No')
                sys.exit()

#top
for i in range(1,H-1):
    for j in [0]:
        if block[i][i] == '.':
            continue
        else:
            if block[i+1][j] == '#' or block[i][j+1] == '#' or block[i-1][j] == '#':
                continue
            else:
                print('No')
                sys.exit()

#right
for i in [H-1]:
    for j in range(1,W-1):
        if block[i][i] == '.':
            continue
        else:
            if block[i][j+1] == '#' or block[i-1][j] == '#' or block[i][j-1] == '#':
                continue
            else:
                print('No')
                sys.exit()

#bottom
for i in range(1,H-1):
    for j in [W-1]:
        if block[i][i] == '.':
            continue
        else:
            if block[i+1][j] == '#' or block[i-1][j] == '#' or block[i][j-1] == '#':
                continue
            else:
                print('No')
                sys.exit()

#TL
if block[0][0] == '#':
    if not(block[1][0] == '#' or block[0][1] == '#'):
        print('No')
        sys.exit()

#TR
if block[H-1][0] == '#':
    if not(block[H-2][0] == '#' or block[H-1][1] == '#'):
        print('No')
        sys.exit()

#BL
if block[0][W-1] == '#':
    if not(block[1][W-1] == '#' or block[0][W-2] == '#'):
        print('No')
        sys.exit()

#TL
if block[H-1][W-1] == '#':
    if not(block[H-2][W-1] == '#' or block[H-1][W-2] == '#'):
        print('No')
        sys.exit()



print('Yes')

Submission status: Runtime Error

Solution code:
H,W = map(int,input().split())
lists2 = [input() for i in range(W)]
x = 1
y = 1
check = True
while(x<W-1 and y<H-1):
    if(lists2[x][y] == "#"):
        if(x!=0 or y!=0 or x==W-1or y==H-1):
            if((lists2[x+1][y] == ".") and (lists2[x-1][y] == ".") and (lists2[x][y-1] == ".") and (lists2[x][y+1] == ".")):
                check = False
    x = x+1
    y = y+1
if(check):
    print("Yes")
else :
    print("No")

Submission status: Runtime Error

Solution code:
H, W = (int(i) for i in input().split())
t = []
t.append(['.']*(H+2))

for j in range(H):
	tmp = input()
	tmp = '.' + tmp + '.'
	t.append(list(tmp))

t.append(['.']*(H+2))


def issharp(block):
	if block == '#':
		return True
	else: return False

def CheckBlock(i,k):
#   0
# 1 X 2
#   3
	if t[i][k-1] == '#': #check up
		return 0
	elif t[i-1][k] == '#': #check left
		return 1
	elif t[i+1][k] == '#': #check right
		return 2
	elif t[i][k+1] == '#': #check down
		return 3
	else:
		return 4

for i in range(1,W+1):
	for k in range(1,H+1):
		if issharp(t[i][k]) == True:
			marker = CheckBlock(i,k)
			if marker == 4:
				print('No')
				quit()
print('Yes')

Submission status: Runtime Error

Solution code:
H, W = map(int, input().split())
grid = []
soloList = []
soloGrid = ""
for _ in range(W):
    row = list(input())
    grid.append(row)

if H == 1 and W == 1:
    if grid[0][0] == ".":
        print("Yes")
    else:
        print("No")

elif H == 1:
    for j in range(H):  #列数ぶん繰り返す
        for i in range(W): #行数ぶん繰り返す＝一列当たりのマス数分
            if i == 0:
                if grid[i][j] == "#" and grid[i+1][j] == "." :
                    soloGrid = str(i) + ", " + str(j)
                    soloList.append(soloGrid)
                else:
                    pass
                
            elif i == W-1:
                if grid[i][j] == "#" and grid[i-1][j] == "." :
                    soloGrid = str(i) + ", " + str(j)
                    soloList.append(soloGrid)
                else:
                    pass
            else:
                if grid[i][j] == "#" and grid[i-1][j] == "." and grid[i+1][j] == ".":
                    soloGrid = str(i) + ", " + str(j)
                    soloList.append(soloGrid)
                else:
                    pass
    if soloGrid == []:
        print("Yes")
    else:
        print("No")

elif W == 1:
    for i in range(W): #行数ぶん繰り返す
        for j in range(H): #列数ぶん繰り返す＝一行当たりのマス数分
            if j == 0:
                if grid[i][j] == "#" and grid[i][j+1] == "." :
                    soloGrid = str(i) + ", " + str(j)
                    soloList.append(soloGrid)
                else:
                    pass
                
            elif j == H-1:
                if grid[i][j] == "#" and grid[i][j-1] == "." :
                    soloGrid = str(i) + ", " + str(j)
                    soloList.append(soloGrid)
                else:
                    pass

            else:
                if grid[i][j] == "#" and grid[i][j-1] == "." and grid[i][j+1] == ".":
                    soloGrid = str(i) + ", " + str(j)
                    soloList.append(soloGrid)
                else:
                    pass
    if soloGrid == []:
        print("Yes")
    else:
        print("No")
                
else:
    for i in range(W): #行数ぶん繰り返す
        for j in range(H): #列数ぶん繰り返す＝一行当たりのマス数分
            if j == 0:
                if grid[i][j] == "#" and grid[i][j+1] == "." :
                    soloGrid = str(i) + ", " + str(j)
                    soloList.append(soloGrid)
                else:
                    pass
                
            elif j == H-1:
                if grid[i][j] == "#" and grid[i][j-1] == "." :
                    soloGrid = str(i) + ", " + str(j)
                    soloList.append(soloGrid)
                else:
                    pass

            else:
                if grid[i][j] == "#" and grid[i][j-1] == "." and grid[i][j+1] == ".":
                    soloGrid = str(i) + ", " + str(j)
                    soloList.append(soloGrid)
                else:
                    pass

#次に縦列で連続しているかチェック
    for j in range(H):  #列数ぶん繰り返す
        for i in range(W): #行数ぶん繰り返す＝一列当たりのマス数分
            if i == 0:
                if grid[i][j] == "#" and grid[i+1][j] == "." :
                    soloGrid = str(i) + ", " + str(j)
                    soloList.append(soloGrid)
                else:
                    pass
                
            elif i == W-1:
                if grid[i][j] == "#" and grid[i-1][j] == "." :
                    soloGrid = str(i) + ", " + str(j)
                    soloList.append(soloGrid)
                else:
                    pass
            else:
                if grid[i][j] == "#" and grid[i-1][j] == "." and grid[i+1][j] == ".":
                    soloGrid = str(i) + ", " + str(j)
                    soloList.append(soloGrid)
                else:
                    pass
            
    if len(soloList) == len(set(soloList)):
        print("Yes")
    else:
        print("No")

Submission status: Runtime Error

Solution code:
H,W=map(int,input().split())
s=[list(input()) for i in range (H)] 
import sys
for j in range (1,W):
    for k in range (1,H-1):
        if s[j][k]=='#' and s[j][k-1]=='.' and s[j][k+1]=='.' and s[j-1][k]=='.' and s[j+1][k]=='.':
            print ('No')
            sys.exit()

#４枠の処理
for j in range (1,H-1):
    if s[j][0]=='#'  and s[j-1][0]=='.' and s[j+1][0]=='.' and  s[j][1]=='.':
        print ('No')
        sys.exit()
    if s[j][W-1]=='#'  and s[j-1][W-1]=='.' and s[j+1][W-1]=='.' and  s[j][W-2]=='.':
        print ('No')
        sys.exit()
        
for j in range (1,W-1):
    if s[0][j]=='#'  and s[0][j-1]=='.' and s[0][j+1]=='.' and  s[1][j]=='.':
        print ('No')
        sys.exit()
    if s[W-1][j]=='#'  and s[W-1][j-1]=='.' and s[W-1][j+1]=='.' and  s[W-2][j]=='.':
        print ('No')
        sys.exit()

if s[0][0]=='#' and s[1][0]=='.' and s[0][1]=='.':
    print ('No')
    sys.exit()
if s[H-1][0]=='#' and s[H-2][0]=='.' and s[H-1][1]=='.':
    print ('No')
    sys.exit()
if s[0][W-1]=='#' and s[1][W-1]=='.' and s[0][W-2]=='.':
    print ('No')
    sys.exit()
if s[H-1][W-1]=='#' and s[H-2][W-1]=='.' and s[H-1][W-2]=='.':
    print ('No')
    sys.exit()

print ('Yes')

Submission status: Runtime Error

Solution code:
H, W = map(int, input().split())
a = []
for i in range(W):
    a.append(list(input()))
ans = "Yes"
for j in range(H):
  for k in range(W):
    if a[j][k] == "#":
       if j == 0:
          if k == 0:
           if a[j][k+1]  == "#":
              continue
           elif a[j+1][k]  == "#":
              continue
           else:
              ans = "No"
              break 
          elif  k == W-1:
           if a[j][k-1] == "#":
              continue
           elif a[j+1][k]  == "#":
              continue
           else:
              ans = "No"
              break 
       elif j == H-1:
          if k == 0:
           if a[j][k+1]  == "#":
              continue
           elif a[j-1][k]  == "#":
              continue
           else:
              ans = "No"
              break 
          elif  k == W-1:
           if a[j][k-1] == "#":
              continue
           elif a[j-1][k]  == "#":
              continue
           else:
              ans = "No"
              break 
          else:
           if a[j][k-1] == "#":
              continue
           elif a[j][k+1]  == "#":
              continue
           elif a[j-1][k]  == "#":
              continue
           else:
              ans = "No"
              break
       elif k == 0:
         if a[j][k+1]  == "#":
            continue
         elif a[j-1][k]  == "#":
            continue
         elif a[j+1][k]  == "#":
            continue
         else:
            ans = "No"
            break 
       elif k == W-1:
         if a[j][k-1] == "#":
            continue
         elif a[j-1][k]  == "#":
            continue
         elif a[j+1][k]  == "#":
            continue
         else:
            ans = "No"
            break           
       else:
           if a[j][k-1] == "#":
              continue
           elif a[j][k+1]  == "#":
              continue
           elif a[j-1][k]  == "#":
              continue
           elif a[j+1][k]  == "#":
              continue
           else:
              ans = "No"
              break 
print(ans)

Submission status: Runtime Error

Solution code:
H,W = list(map(int,input().split()))
import sys

block = [
    list(input()) for i in range(W)
]

isok = [[0] * H] * W

#middle
for i in range(1,H-1):
    for j in range(1,W-1):
        if block[i][i] == '.':
            continue
        else:
            if block[i+1][j] == '#' or block[i][j+1] == '#' or block[i-1][j] == '#' or block[i][j-1] == '#':
                continue
            else:
                print('No')
                sys.exit()

#left
for i in [0]:
    for j in range(1,W-1):
        if block[i][i] == '.':
            continue
        else:
            if block[i+1][j] == '#' or block[i][j+1] == '#' or block[i][j-1] == '#':
                continue
            else:
                print('No')
                sys.exit()

#top
for i in range(1,H-1):
    for j in [0]:
        if block[i][i] == '.':
            continue
        else:
            if block[i+1][j] == '#' or block[i][j+1] == '#' or block[i-1][j] == '#':
                continue
            else:
                print('No')
                sys.exit()

#right
for i in [H-1]:
    for j in range(1,W-1):
        if block[i][i] == '.':
            continue
        else:
            if block[i][j+1] == '#' or block[i-1][j] == '#' or block[i][j-1] == '#':
                continue
            else:
                print('No')
                sys.exit()

#bottom
for i in range(1,H-1):
    for j in [W-1]:
        if block[i][i] == '.':
            continue
        else:
            if block[i+1][j] == '#' or block[i-1][j] == '#' or block[i][j-1] == '#':
                continue
            else:
                print('No')
                sys.exit()

#TL
if block[0][0] == '#':
    if not(block[1][0] == '#' or block[0][1] == '#'):
        print('No')
        sys.exit()

#TR
if block[H-1][0] == '#':
    if not(block[H-2][0] == '#' or block[H-1][1] == '#'):
        print('No')
        sys.exit()

#BL
if block[0][W-1] == '#':
    if not(block[1][W-1] == '#' or block[0][W-2] == '#'):
        print('No')
        sys.exit()

#TL
if block[H-1][W-1] == '#':
    if not(block[H-2][W-1] == '#' or block[H-1][W-2] == '#'):
        print('No')
        sys.exit()



print('Yes')

Submission status: Runtime Error

Solution code:
H,W = map(int,input().split())
lists = [input() for i in range(W)]
x = 1
y = 1
for i in range(H):
    lists[i] = list(lists[i])
lists1 = []
lists2 = []
for i in range(W+1):
    lists1.append(".")
for i in range(W+1):
    lists2.append(".")
for i in range(H):
    lists[i].append(".")
lists2 = lists
check = True
while(x<W-1 and y<H-1):
    if(lists2[x][y] == "#"):
        if(x!=0 or y!=0 or x==W-1or y==H-1):
            if((lists2[x+1][y] == ".") and (lists2[x-1][y] == ".") and (lists2[x][y-1] == ".") and (lists2[x][y+1] == ".")):
                check = False
    x = x+1
    y = y+1
if(check):
    print("Yes")
else :
    print("No")

Submission status: Runtime Error

Solution code:
H, W = map(int, input().split(" "))

result = True
masu = [["0" for i in range(H+2)] for j in range(W+2)]
for h in range(1, H+1):
    s = "0"+input()+"0"
    masu[h] = list(s)

# print(masu)    

for h in range(1, H+1):
    for w in range(1, W+1):
        # print(h, w, masu[h][w])
        if masu[h][w] == "#":
            if masu[h+1][w] != "#" and masu[h][w+1] != "#" and masu[h-1][w] != "#" and masu[h][w-1] != "#":
                result = False
                break

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

Submission status: Runtime Error

Solution code:
def main():
    h, w = input().split()
    h = int(h)
    w = int(w)

    lst =[]
    for i in range(h):
        tmp = input()
        lst.append(list(tmp))

    flag = False

    for i in range(len(lst)):
        if flag:
            break

        for j in range(i):
            if lst[i][j] == "#":
                if j != w - 1:
                    if lst[i][j+1] == "#":
                        continue

                if j != 0:
                    if lst[i][j-1] == '#':
                        continue

                if i != 0:
                    if lst[i-1][j] == '#':
                        continue

                if i != h -1:
                    if lst[i+1][j] == '#':
                        continue

                print("No")
                flag = True
                break

    if flag == False:
        print("Yes")

if __name__ == "__main__":
        main()

Submission status: Runtime Error

Solution code:
 h, w = map(int,input().split())
pic = []

kabe_up_down = []
for i in range(w+2):
    kabe_up_down.append('.')
pic.append(kabe_up_down)

for i in range(h):
    onelist = ['.']
    inp = list(str(input()))
    for mm in range(len(inp)):
        onelist.append(inp[mm])
    onelist.append('.')
    pic.append(onelist)
    
pic.append(kabe_up_down)    


flag = 1
a = 'a'
for i in range(1,h+1):
    for j in range(1,w+1):
        here = pic[i][j]
        if here =='#' and pic[i+1][j] == '#':
            pic[i][j] = a
            pic[i+1][j] = a
        elif here =='#' and pic[i][j+1] == '#':
            pic[i][j] = a
            pic[i][j+1] = a
        elif here =='#' and pic[i-1][j] == '#':
            pic[i][j] = a
            pic[i-1][j] = a
        elif here =='#' and pic[i][j+1] == '#':
            pic[i][j] = a
            pic[i][j+1] = a    
            
for i in range(1,h+1):
    for j in range(1,w+1):
        here = pic[i][j]
        if here == '#' and pic[i+1][j] == 'a':
            pic[i][j] = a
            pic[i+1][j] = a
        elif here =='#' and pic[i][j+1] == 'a':
            pic[i][j] = a
            pic[i][j+1] = a
        elif here =='#' and pic[i-1][j] == 'a':
            pic[i][j] = a
            pic[i-1][j] = a
        elif here =='#' and pic[i][j+1] == 'a':
            pic[i][j] = a
            pic[i][j+1] = a    
        
for i in range(1,h+1):
    for j in range(1,w+1):
        here = pic[i][j]
        if here == a and pic[i+1][j] == '#':
            pic[i][j] = a
            pic[i+1][j] = a
        elif here =='a' and pic[i][j+1] == '#':
            pic[i][j] = a
            pic[i][j+1] = a
        elif here =='a' and pic[i-1][j] == '#':
            pic[i][j] = a
            pic[i-1][j] = a
        elif here =='a' and pic[i][j+1] == '#':
            pic[i][j] = a
            pic[i][j+1] = a            
            
for i in range(1,h+1):
    for j in range(1,w+1):
        if pic[i][j] == '#':
            flag = 0
            

if flag == 0:
    print('No')
else:
    print('Yes')

Submission status: Runtime Error

Solution code:
h, w = input().split()
h = int(h)
w = int(w)
field = []
for _ in range(h):
    field.append(input())
    
ans = True
for i in range(h):
    for j in range(w):
        if field[i][j] == '#':
            temp = 1
            dd = [(1, 0), (-1, 0), (0, 1), (0, -1)]
            for ddd in dd:
                dx, dy = ddd
                nx, ny = x + dx, y + dy
                if nx >= 0 and nx < h and ny >= 0 and ny < w and field[nx][ny] == '#':
                    temp += 1
            if temp == 1:
                ans = False
                break

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