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:
N, M = map(int, input().split())
arr = [list(input()) for i in range(N)]
newmat = [[0 for i in range(M)] for j in range(N)]
nocheck = 0
for i in range(N):
    for j in range(M):
        if arr[i][j] is '#':
            newmat[i][j] = 1
        else:
            newmat[i][j] = 0

for i in range(N):
    for j in range(M):
        if newmat[i][j] == 1:
            if i == 0 and j == 0:
                if newmat[i][j+1] == 0 and newmat[i+1][j] == 0:
                    nocheck = 1
            elif i == 0 and j == (M-1):
                if newmat[i][j-1] == 0 and newmat[i+1][j] == 0:
                    nocheck = 1
            elif i == (N-1) and j == 0:
                if newmat[i][j+1] == 0 and newmat[i-1][j] == 0:
                    nocheck = 1
            elif i == (N-1) and j == (M-1):
                if newmat[i][j-1] == 0 and newmat[i-1][j] == 0:
                    nocheck = 1
            elif i == 0 and j != 0:
                if newmat[i][j+1] == 0 and newmat[i+1][j] == 0 and newmat[i][j-1] == 0:
                    nocheck = 1
            elif i != 0 and j == 0:
                if newmat[i][j + 1] == 0 and newmat[i + 1][j] == 0 and newmat[i-1][j] == 0:
                    nocheck = 1
            elif i == (N-1) and j != (M-1):
                if newmat[i][j+1] == 0 and newmat[i-1][j] == 0 and newmat[i][j-1] == 0:
                    nocheck = 1
            elif i != (N-1) and j == (M-1):
                if newmat[i-1][j] == 0 and newmat[i+1][j] == 0 and newmat[i][j-1] == 0:
                    nocheck = 1

            else:
                if newmat[i][j + 1] == 0 and newmat[i + 1][j] == 0 and newmat[i][j - 1] == 0 and newmat[i-1][j]:
                    nocheck = 1

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

Submission status: Runtime Error

Solution code:
h, w = map(int, input().split())
s = []
for _ in range(w):
    s.append(input())
ans = ((i < h-1 and s[i+1][j] == '#') or (i > 0 and s[i-1][j] == '#') or (j > 0 and s[i][j-1] == '#') or (j < w-1 and s[i][j+1] == '#') for i in range(h) for j in range(w) if s[i][j] == '#')
if False in ans:
    print("No")
else:
    print("Yes")

Submission status: Runtime Error

Solution code:
H,W = map(int,input().split())
s = [input() for i in range(H)]
dx=[0,-1,1,0]
dy=[1,0,0,-1]
flag = True
for i in range(W):
    for j in range(H):
        if s[i][j]=='#':
            cnt = 0
            for k in range(4):
                if 0<=j+dx[k] and j+dx[k]<H and 0<=i+dy[k] and i+dy[k]<W:
                    if s[i+dy[k]][j+dx[k]]=='#':
                        cnt += 1
            if cnt==0:
                flag=False
print('Yes' if flag else 'No')

Submission status: Runtime Error

Solution code:
H,W = map(int,input().split())
s = [input() for i in range(H)]
dx=[0,-1,1,0]
dy=[1,0,0,-1]
flag = True
for i in range(W):
    for j in range(H):
        if s[i][j]=='#':
            cnt = 0
            for k in range(4):
                if 0<=j+dx[k] and j+dx[k]<W and 0<=i+dy[k] and i+dy[k]<H:
                    if s[i+dy[k]][j+dx[k]]=='#':
                        cnt += 1
            if cnt==0:
                flag=False
print('Yes' if flag else 'No')

Submission status: Runtime Error

Solution code:
h, w = [int(i) for i in input().split()]
s = [list(input()) for _ in range(h)]
flg = True

for i in range(1, h - 1):
    for j in range(1, j - 1):
        if s[i][j] == "#" and s[i - 1][j] == "." and s[i + 1][j] == "." and s[i][j - 1] == "." and s[i][j + 1] == ".":
            flg = False

print('Yes' if flg else 'No')

Submission status: Runtime Error

Solution code:
H, W = list(map(int, input().split()))
count = 0
s = [[None]*(W+2)]*(H+2)

for i in range(1, H+1):
    s[i] = input().split()

for i in range(1, H+1):
    for j in range(1, W+1):
        if s[i][j] == '#':
            if s[i-1][j] == '.' and s[i+1][j] == '.' and s[i][j-1] == '.' and s[i][j+1] == '.':
                print(No)
                break

count_list = [[i, j] for i in range(1, H+1) for j in range(1 W+1) if s[i][j] == '#']
count_black = len(count_list)

if count == count_list:
    print(Yes)

Submission status: Runtime Error

Solution code:
h,w = map(int, input().split())
k = [list(input()) for i in range(h)]

ans = True
for i in range(1,h):
    for j in range(1,w):
        if k[i][j] == "#" and k[i-1][j] =="." and k[i][j-1] =="." and k[i+1][j] =="." and k[i][j+1] =="." :
            ans = True

if ans:
    print('Yes')

else:
    print('No')

Submission status: Runtime Error

Solution code:
h,w = map(int, input().split())
k = [list(input()) for i in range(h)]

ans = True
for i in range(h):
    for j in range(w):
        if k[i][j] == "#" and k[i-1][j] =="." and k[i][j-1] =="." and k[i+1][j] =="." and k[i][j+1] =="." :
            ans = True

if ans:
    print('Yes')

else:
    print('No')

Submission status: Runtime Error

Solution code:
#Grid Repainting 2

#初期化
S = []
p = []
flag = True

#入力
H,W = map(int, input().split())
for i in range(H):
	s = input()
	s_list = list(s)
	S.append(s_list)

#計算
for i in range(0, W-1, 1):
	for j in range(0, H-1, 1):
		if S[i][j] == "#" and S[i+1][j] == "." and S[i][j+1] == "."  and S[i-1][j] == "." and S[i][j-1] == "." :
			flag = False
		

#出力
if flag == True:
	print("Yes")

else:
	print("No")

Submission status: Runtime Error

Solution code:
#Grid Repainting 2

#初期化
S = []
p = []
flag = True

#入力
H,W = map(int, input().split())
for i in range(W):
	s = input()
	s_list = list(s)
	S.append(s_list)

#計算
for i in range(0, W-1, 1):
	for j in range(0, H-1, 1):
		if S[i][j] == "#" and S[i+1][j] == "." and S[i][j+1] == "."  and S[i-1][j] == "." and S[i][j-1] == "." :
			flag = False
		

#出力
if flag == True:
	print("Yes")

else:
	print("No")

Submission status: Runtime Error

Solution code:
#Grid Repainting 2

#初期化
S = []
p = []
flag = True

#入力
H,W = map(int, input().split())
for i in range(W):
	s = input()
	s_list = list(s)
	S.append(s_list)

#計算
for i in range(0, W-1, 1):
	for j in range(1, H-1, 1):
		if S[i][j] == "#" and S[i+1][j] == "." and S[i][j+1] == "."  and S[i-1][j] == "." and S[i][j-1] == "." :
			flag = False
		

#出力
if flag == True:
	print("Yes")

else:
	print("No")

Submission status: Runtime Error

Solution code:
#Grid Repainting 2

#初期化
S = []
p = []
flag = True

#入力
H,W = map(int, input().split())
for i in range(W):
	s = input()
	s_list = list(s)
	S.append(s_list)

#枠外を白に塗りつぶす
for  i in range(H+2):
	p.append(".")

S.insert(0,p)
S.insert(W+1,p)

for i in range(1,W+1,1):
	S[i].insert(0,".")
	S[i].insert(H+2,".")

#計算
for i in range(1, W+1, 1):
	for j in range(1, H+1, 1):
		if S[i][j] == "#" and S[i+1][j] == "." and S[i][j+1] == "."  and S[i-1][j] == "." and S[i][j-1] == "." :
			flag = False
		#print("{}".format(S[i][j]))

#出力
if flag == True:
	print("Yes")

else:
	print("No")

Submission status: Runtime Error

Solution code:
#Grid Repainting 2

#初期化
S = []
p = []
flag = True

#入力
H,W = map(int, input().split())
for i in range(W):
	s = input()
	s_list = list(s)
	S.append(s_list)

#枠外を白に塗りつぶす
for  i in range(H+2):
	p.append(".")

S.insert(0,p)
S.insert(W+1,p)

for i in range(1,W+1,1):
	S[i].insert(0,".")
	S[i].insert(H+2,".")

print("{}".format(S))

#計算
for i in range(1, W+1, 1):
	for j in range(1, H+1, 1):
		if S[i][j] == "#" and S[i+1][j] == "." and S[i][j+1] == "."  and S[i-1][j] == "." and S[i][j-1] == "." :
			flag = False

#出力
if flag == True:
	print("Yes")

else:
	print("No")

Submission status: Runtime Error

Solution code:
#Grid Repainting 2

#初期化
S = []
p = []
flag = True

#入力
H,W = map(int, input().split())
for i in range(W):
	s = input()
	s_list = list(s)
	S.append(s_list)

#枠外を白に塗りつぶす
for  i in range(H+2):
	p.append(".")

S.insert(0,p)
S.insert(W+1,p)

for i in range(1,W+1,1):
	S[i].insert(0,".")
	S[i].insert(H+2,".")

#計算
for i in range(1, W+2, 1):
	for j in range(1, H+2, 1):
		if S[i][j] == "#" and S[i+1][j] == "." and S[i][j+1] == "." and S[i+1][j+1] == "." and S[i-1][j] == "." and S[i][j-1] == "." and S[i-1][j-1] == ".":
			flag = False

#出力
if flag == True:
	print("Yes")

else:
	print("No")

Submission status: Runtime Error

Solution code:
#Grid Repainting 2

#初期化
S = []
p = []
flag = True

#入力
H,W = map(int, input().split())
for i in range(W):
	s = input()
	s_list = list(s)
	S.append(s_list)

#枠外を白に塗りつぶす
for  i in range(H+2):
	p.append(".")

S.insert(0,p)
S.insert(W+1,p)

for i in range(1,W+1,1):
	S[i].insert(0,".")
	S[i].insert(H+2,".")

#計算
for i in range(1, W+1, 1):
	for j in range(1, H+1, 1):
		if S[i][j] == "#" and S[i+1][j] == "." and S[i][j+1] == "." and S[i+1][j+1] == "." and S[i-1][j] == "." and S[i][j-1] == "." and S[i-1][j-1] == ".":
			flag = False

#出力
if flag == True:
	print("Yes")

else:
	print("No")

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
h, w = map(int, raw_input().split())

matrix = []
matrix.append('.'*(w+2))

for i in range(w):
    matrix.append('.' + raw_input() + '.')

matrix.append('.'*(w+2))

for i in range(1, h+1):
    for j in range(1, w+1):
        if matrix[i][j] == '#':
            if matrix[i+1][j] == '#' or matrix[i-1][j] == '#' or matrix[i][j-1] == '#' or matrix[i][j+1] == '#':
                continue
            else:
                print 'No'
                exit()
print 'Yes'

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
h, w = map(int, raw_input().split())

matrix = []

matrix.append(list('.'*(w+2)))
for i in range(w):
    matrix.append(['.'] + list(raw_input()) + ['.'])
matrix.append(list('.'*(w+2)))

for i in range(1, h+1):
    for j in range(1, w+1):
        if matrix[i][j] == '#':
            if matrix[i+1][j] == '#' or matrix[i-1][j] == '#' or matrix[i][j-1] == '#' or matrix[i][j+1] == '#':
                continue
            else:
                print 'No'
                exit()
print 'Yes'

Submission status: Runtime Error

Solution code:
import math
H, W = map(int, input().split())
s = []
flag = 0
ans = "No"
for i in range(W):
  s.append(list(input()))
for i in range(H):
  for j in range(W):
    if flag == 0:
      if s[i][j] == "#":
        if s[max(0, i - 1)][j] == "#" or s[i][max(0, j - 1)] == "#" or s[min(H - 1, i + 1)][j] == "#" or s[i][min(W - 1, j + 1)] == "#":
          continue
        else:
          flag += 1
if flag == 0:
  ans = "Yes"
print(ans)

Submission status: Runtime Error

Solution code:
import math
H, W = map(int, input().split())
s = []
flag = 0
ans = "No"
for i in range(W):
  s.append(list(input()))
if flag == 0:
  for i in range(H):
    for j in range(W):
      if s[i][j] == "#":
        if s[max(0, i - 1)][j] == "#" or s[i][max(0, j - 1)] == "#" or s[min(H - 1, i + 1)][j] == "#" or s[i][min(W - 1, j + 1)] == "#":
          continue
        else:
          flag += 1
if flag == 0:
  ans = "Yes"
print(ans)

Submission status: Runtime Error

Solution code:
import sys

line_size, row_size = map(int, input().split())
mapmap = []#地図初期化

for i in range(line_size):
    mapmap.append(list(input()))

#探索
def Start_check(mapmap, px, py):
    start_flg = False
    move_x = [1, -1, 0, 0]
    move_y = [0, 0, 1, -1]
    for i in range(len(move_x)):#動ける範囲で探索
        nx = px + move_x[i]
        ny = py + move_y[i]
        if 0 <= nx and nx < line_size and 0 <= ny and ny < row_size:
            if mapmap[nx][ny] == '#':#もし黒塗りなら
                start_flg = True
    
    if start_flg == False:
        print('No')
        sys.exit()

#Main
count = 0#探索回数（塗り絵した回数）
for i in range(line_size):
    for j in range(row_size):
        if mapmap[i][j] == '#':
            Start_check(i, j)
            count += 1

#何もしなかった場合
if count == 0:
    print('No')
else:
    print('Yes')

Submission status: Runtime Error

Solution code:
import sys

sys.setrecursionlimit(5000)
line_size, row_size = map(int, input().split())
mapmap = []#地図初期化

for i in range(line_size):
    mapmap.append(list(input()))

#探索関数
def Dfs(px, py):
    global mapmap
    #自分のいるところを変換→globalにして更新
    mapmap[py][py] = '.'

    #自分の動けるところ定義
    move_x = [1, -1, 0, 0]
    move_y = [0, 0, 1, -1]
    for i in range(len(move_x)):#動ける範囲で探索
        nx = px + move_x[i]
        ny = py + move_y[i]
        if 0 <= nx and line_size > nx and 0 <= ny and row_size > ny:
            if mapmap[nx][ny] == '#':#もし黒塗りなら
                Dfs(nx, ny)#自分のいるところから突き進むむからfirst in last out
            else:
                return

#開始条件探索
def Start_check(px, py):
    global mapmap
    start_flg = False
    move_x = [1, -1, 0, 0]
    move_y = [0, 0, 1, -1]
    for i in range(len(move_x)):#動ける範囲で探索
        nx = px + move_x[i]
        ny = py + move_y[i]
        if 0 <= nx and line_size > nx and 0 <= ny and row_size > ny:
            if mapmap[nx][ny] == '#':#もし黒塗りなら
                start_flg = True
    
    if start_flg == False:
        print('No')
        sys.exit()

    print(start_flg)

#Main
count = 0#探索回数（塗り絵した回数）
for i in range(line_size):
    for j in range(row_size):
        if mapmap[i][j] == '#':
            Start_check(i, j)
            Dfs(i, j)
            count += 1

#何もしなかった場合
if count == 0:
    print('No')
else:
    print('Yes')

Submission status: Runtime Error

Solution code:
import sys

#探索
def DFS(mapmap, start_flag = False):
    while 1:
        #はじめの探索
        for i in range(lines):
            for j in range(rows):
                if mapmap[i][j] == '#':
                    start_flag = True
                    break
        #則終了
        if start_flag == False:
            print('No')
            sys.exit()

        startl, startr = i, j
        #動き
        Stack = [[startl, startr]]
        #終了条件
        if mapmap[i+1][j] == '.' and mapmap[i-1][j] == '.' and mapmap[i][j+1] == '.' and mapmap[i][j-1] == '.':
            print('No')
            sys.exit()

        move_x = [1, -1, 0, 0]
        move_y = [0, 0, 1, -1]

        while Stack:
            x, y= Stack.pop()#今現在の位置
            #現在位置を変換
            mapmap[x][y] = '.'

            for i in range(len(move_x)):
                nx = x + move_x[i]
                ny = y + move_y[i]

                if 0 <= nx and nx < lines and 0 <= ny and ny < rows:
                    if mapmap[nx][ny] == '#':
                        Stack.append([nx, ny])
        
#入力管理
lines, rows = map(int, input().split())
mapmap = []

for i in range(lines):
    mapmap.append(list(input()))

DFS(mapmap)

Submission status: Runtime Error

Solution code:
import sys

#探索
def DFS(mapmap):
    while 1:
        #はじめの探索
        start_flag = False
        for i in range(lines):
            for j in range(rows):
                if mapmap[i][j] == '#':
                    start_flag = True
                    break
        #則終了
        if start_flag == False:
            print('No')
            sys.exit()

        startl, startr = i, j
        #動き
        Stack = [[startl, startr]]

        move_x = [1, -1, 0, 0]
        move_y = [0, 0, 1, -1]

        while Stack:
            x, y= Stack.pop()#今現在の位置
            #現在位置を変換
            mapmap[x][y] = '.'

            for i in range(len(move_x)):
                nx = x + move_x[i]
                ny = y + move_y[i]

                if 0 <= nx and nx < lines and 0 <= ny and ny < rows:
                    if mapmap[nx][ny] == '#':
                        Stack.append([nx, ny])
        
        DFS(mapmap)

#入力管理
lines, rows = map(int, input().split())
mapmap = []

for i in range(lines):
    mapmap.append(list(input()))

DFS(mapmap)

Submission status: Runtime Error

Solution code:
import sys
#入力管理
lines, rows = map(int, input().split())
mapmap = []

for i in range(lines):
    mapmap.append(list(input()))

start_flag == False
#最初の黒点探し
for i in range(lines):
    for j in range(rows):
        if mapmap[i][j] == '#':
            start_flag = True
            break
#則終了

if start_flag == False:
    print('No')
    sys.exit()

startl, startr = i, j

#動き
move_x = [1, -1, 0, 0]
move_y = [0, 0, 1, -1]
Stack = [[startl, startr]]

#探索開始
while Stack:
   x, y= Stack.pop()#今現在の位置
   #現在位置を変換
   mapmap[x][y] = '.'

   for i in range(len(move_x)):
       nx = x + move_x[i]
       ny = y + move_y[i]

       if 0 <= nx and nx < lines and 0 <= ny and ny < rows:
           if mapmap[nx][ny] == '#':
               Stack.append([nx, ny])


#黒点探し
for i in range(lines):
    for j in range(rows):
        if mapmap[i][j] == '#':
            print('No')
            sys.exit()

print('Yes')

Submission status: Runtime Error

Solution code:
import sys
#入力管理
lines, rows = map(int, input().split())
mapmap = []

for i in range(lines):
    mapmap.append(list(input()))

#最初の黒点探し
for i in range(lines):
    for j in range(rows):
        if mapmap[i][j] == '#':
            start_flag = True
            break
#則終了

if start_flag == False:
    print('No')
    sys.exit()

startl, startr = i, j

#動き
move_x = [1, -1, 0, 0]
move_y = [0, 0, 1, -1]
Stack = [[startl, startr]]

#探索開始
while Stack:
   x, y= Stack.pop()#今現在の位置
   #現在位置を変換
   mapmap[x][y] = '.'

   for i in range(len(move_x)):
       nx = x + move_x[i]
       ny = y + move_y[i]

       if 0 <= nx and nx < lines and 0 <= ny and ny < rows:
           if mapmap[nx][ny] == '#':
               Stack.append([nx, ny])


#黒点探し
for i in range(lines):
    for j in range(rows):
        if mapmap[i][j] == '#':
            print('No')
            sys.exit()

print('Yes')

Submission status: Runtime Error

Solution code:
import sys
#入力管理
lines, rows = map(int, input().split())
mapmap = []

for i in range(lines):
    mapmap.append(list(input()))

#最初の黒点探し
for i in range(lines):
    for j in range(rows):
        if mapmap[i][j] == '#':
            break
            
if mapmap[i][j] == '.'    
    print('No')
    sys.exit()

startl, startr = i, j

#動き
move_x = [1, -1, 0, 0]
move_y = [0, 0, 1, -1]
Stack = [[startl, startr]]

#探索開始
while Stack:
   x, y= Stack.pop()#今現在の位置
   #現在位置を変換
   mapmap[x][y] = '.'

   for i in range(len(move_x)):
       nx = x + move_x[i]
       ny = y + move_y[i]

       if 0 <= nx and nx < lines and 0 <= ny and ny < rows:
           if mapmap[nx][ny] == '#':
               Stack.append([nx, ny])


#黒点探し
for i in range(lines):
    for j in range(rows):
        if mapmap[i][j] == '#':
            print('No')
            sys.exit()

print('Yes')

Submission status: Runtime Error

Solution code:
h, w = map(int, input().split())
data = ''
for i in range(h):
    data += input()

array = list(data)

for i, x in enumerate(array):
    if x == '.':
        continue
    cnt = 0
    # 上の確認
    if not i < w:
        if array[i - w] == '#':
            cnt += 1
    # 下の確認
    if i + w < h * w:
        if array[i + w] == '#':
            cnt += 1
    # 左の確認
    if i % w != 0:
        if array[i - 1] == '#':
            cnt += 1
    # 右の確認
    if i + 1 % w != 0:
        if array[i + 1] == '#':
            cnt += 1

    if cnt == 0:
        print('No')
        break
else:
    print('Yes')

Submission status: Runtime Error

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

S = [list(input()) for _ in range(H+1)]
a = 1

for h in range(H):
    for w in range(W):
        if S[h][w] == "#":
            if h == 0:
                if w == 0:
                    down, right = S[h+1][w], S[h][w+1]
                    if down == "." and right == ".":
                        print("No")
                        a = 0 
                        break
                if w == W-1:
                    down, left = S[h+1][w], S[h][w-1]
                    if down == "." and left == ".":
                        print("No")
                        a = 0 
                        break
                else:
                    down, left, right = S[h+1][w], S[h][w-1], S[h][w+1]
                    if down == "." and left == "." and right == ".":
                        print("No")
                        a = 0 
                        break
            if h == H-1:
                if w == 0:
                    up, right = S[h-1][w], S[h][w+1]
                    if up == "." and right == ".":
                        print("No")
                        a = 0 
                        break
                if w == W-1:
                    up, left = S[h-1][w], S[h][w-1]
                    if up == "." and left == ".":
                        print("No")
                        a = 0 
                        break
                else:
                    up, left, right = S[h-1][w], S[h][w-1], S[h][w+1]
                    if up == "." and left == "." and right == ".":
                        print("No")
                        a = 0 
                        break
            else:
                if w == 0:
                    up, down, right = S[h-1][w], S[h+1][w], S[h][w+1]
                    if up == "." and down == "." and right == ".":
                        print("No")
                        a = 0 
                        break
                if w == W-1:
                    up, down, left = S[h-1][w], S[h+1][w], S[h][w-1]
                    if up == "." and down == "." and left == ".":
                        print("No")
                        a = 0 
                        break
                else:
                    up, down, left, right = S[h-1][w], S[h+1][w], S[h][w-1], S[h][w+1]
                    if up == "." and down == "." and left == "." and right == ".":
                        print("No")
                        a = 0 
                        break
if a == 1:
    print("Yes")

Submission status: Runtime Error

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

S = [list(input()) for _ in range(H)]
a = 1

for h in range(H):
    for w in range(W):
        if S[h][w] == "#":
            if h == 0:
                if w == 0:
                    down, right = S[h+1][w], S[h][w+1]
                    if down == "." and right == ".":
                        print("No")
                        a = 0 
                        break
                if w == W:
                    down, left = S[h+1][w], S[h][w-1]
                    if down == "." and left == ".":
                        print("No")
                        a = 0 
                        break
                else:
                    down, left, right = S[h+1][w], S[h][w-1], S[h][w+1]
                    if down == "." and left == "." and right == ".":
                        print("No")
                        a = 0 
                        break
            if h == H:
                if w == 0:
                    up, right = S[h-1][w], S[h][w+1]
                    if up == "." and right == ".":
                        print("No")
                        a = 0 
                        break
                if w == W:
                    up, left = S[h-1][w], S[h][w-1]
                    if up == "." and left == ".":
                        print("No")
                        a = 0 
                        break
                else:
                    up, left, right = S[h-1][w], S[h][w-1], S[h][w+1]
                    if up == "." and left == "." and right == ".":
                        print("No")
                        a = 0 
                        break
            else:
                if w == 0:
                    up, down, right = S[h-1][w], S[h+1][w], S[h][w+1]
                    if up == "." and down == "." and right == ".":
                        print("No")
                        a = 0 
                        break
                if w == W:
                    up, down, left = S[h-1][w], S[h+1][w], S[h][w-1]
                    if up == "." and down == "." and left == ".":
                        print("No")
                        a = 0 
                        break
                else:
                    up, down, left, right = S[h-1][w], S[h+1][w], S[h][w-1], S[h][w+1]
                    if up == "." and down == "." and left == "." and right == ".":
                        print("No")
                        a = 0 
                        break
if a == 1:
    print("Yes")

Submission status: Runtime Error

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

S = [list(input()) for _ in range(H)]

for h in range(H):
    for w in range(W):
        if S[h][w] == "#":
            if h == 0:
                if w == 0:
                    down, right = S[h+1][w], S[h][w+1]
                    if down == "." and right == ".":
                        print("No")
                        break
                if w == W:
                    down, left = S[h+1][w], S[h][w-1]
                    if down == "." and left == ".":
                        print("No")
                        break
                else:
                    down, left, right = S[h+1][w], S[h][w-1], S[h][w+1]
                    if down == "." and left == "." and right == ".":
                        print("No")
                        break
            if h == H:
                if w == 0:
                    up, right = S[h-1][w], S[h][w+1]
                    if up == "." and right == ".":
                        print("No")
                        break
                if w == W:
                    up, left = S[h-1][w], S[h][w-1]
                    if up == "." and left == ".":
                        print("No")
                        break
                else:
                    up, left, right = S[h-1][w], S[h][w-1], S[h][w+1]
                    if up == "." and left == "." and right == ".":
                        print("No")
                        break
            else:
                if w == 0:
                    up, down, right = S[h-1][w], S[h+1][w], S[h][w+1]
                    if up == "." and down == "." and right == ".":
                        print("No")
                        break
                if w == W:
                    up, down, left = S[h-1][w], S[h+1][w], S[h][w-1]
                    if up == "." and down == "." and left == ".":
                        print("No")
                        break
                else:
                    up, down, left, right = S[h-1][w], S[h+1][w], S[h][w-1], S[h][w+1]
                    if up == "." and down == "." and left == "." and right == ".":
                        print("No")
                        break
else:print("Yes")

Submission status: Runtime Error

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

S = [list(input()) for _ in range(H)]

for h in range(H):
    for w in range(W):
        if S[h][w] == "#":
            try:
                up, down, left, right = S[H-1][W], S[H+1][W], S[H][W-1], S[H][w+1]
            except IndexError:
                pass
            if up == "." and down == "." and left == "." and right == ".":
                print("No")
                break
else:print("Yes")

Submission status: Runtime Error

Solution code:
HW = input().split()

H = int(HW[0])
W = int(HW[1])

tmp1 = ("." * W) + ".."
s = [list(tmp1)]
for i in range(H):
    tmp2 = "." + input() + "."
    s.append(list(tmp2))
s.append(list(tmp1))

checker = 1
for i in range(1, H+1):
    for j in range(1, W+1):
        if s[i, j] == "#":
            if s[i, j-1] == "." and s[i-1, j] == "." and s[i, j+1] == "." and s[i+1, j] == ".":
                checker == 0

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

Submission status: Runtime Error

Solution code:
h,w=map(int,input().split())
mass=[]
f=0
for i in range(0,h):
    mass.append(list(input()))
for i in range(h):
    if f==0:
        for j in range(w):
            if i!=h and j!=w:
                if mass[i][j]=="#" and mass[i][j]!=mass[i][j+1] and mass[i][j]!=mass[i+1][j]:
                    f=1
                    break
            elif i==h:
                if mass[i][j]=="#" and mass[i][j]!=mass[i][j+1]:
                    f=1
                    break
            else:
                if mass[i][j]=="#" and mass[i][j]!=mass[i+1][j]:
                    f=1
                    break
if f==0:
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
h,w=map(int,input().split())
mass=[]
f=0
for i in range(0,h):
    mass.append(list(input()))
for i in range(h):
    if f==0:
        for j in range(w-1):
            if i!=h and j!=w:
                if mass[i][j]=="#" and mass[i][j]!=mass[i][j+1] and mass[i][j]!=mass[i+1][j]:
                    f=1
                    break
            elif i==h:
                if mass[i][j]=="#" and mass[i][j]!=mass[i][j+1]:
                    f=1
                    break
            else:
                if mass[i][j]=="#" and mass[i][j]!=mass[i+1][j]:
                    f=1
                    break
if f==0:
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
h,w=map(int,input().split())
mass=[]
f=0
for i in range(h):
    mass.append(input().split())
for i in range(h-1):
    if f==0:
        for j in range(w-1):
            if mass[i][j]=="#" and mass[i][j]!=mass[i][j+1] and mass[i][j]!=mass[i+1][j]:
                print(i,j)
                f=1
                break
if f==0:
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
h,w=map(int, input().split())
s=[' '*(w+2)]
for _ in range(h):
    s.append(' '+input()+' ')
s.append(' '*(w+2))

for i in range(1,w+1):
    for j in range(1,h+1):
        if s[j][i]=='#':
            if s[i-1][j]!='#' and s[i+1][j]!='#' and s[i][j-1]!='#' and s[i][j+1]!='#' :
                    print('No')
                    exit()
print('Yes')

Submission status: Runtime Error

Solution code:
h,w=map(int, input().split())
s=[' '*(w+2)]
for _ in range(h):
    s.append(' '+input()+' ')
s.append(' '*(w+2))

#print(s)

for i in range(1,w+1):
    for j in range(1,h+1):
        if s[i][j]=='#':
            if s[i-1][j]!='#' and s[i+1][j]!='#' and s[i][j-1]!='#' and s[i][j+1]!='#' :
                    print('No')
                    exit()
print('Yes')

Submission status: Runtime Error

Solution code:
h,w=map(int, input().split())
s=['.'*(w+2)]
for _ in range(h):
    s.append('.'+input()+',')
s.append('.'*(w+2))

#print(s)

for i in range(1,w+1):
    for j in range(1,h+1):
        if s[i][j]=='#':
            if s[i-1][j]!='#' and s[i+1][j]!='#' and s[i][j-1]!='#' and s[i][j+1]!='#' :
                    print('No')
                    exit()
print('Yes')