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 = map(int, input().split())
grid = []
soloList = []
soloGrid = ""
for _ in range(W):
    row = list(input())
    grid.append(row)

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())
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):
        if pic[i][j] == '#':
            flag = 0
            break

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

Submission status: Runtime Error

Solution code:
H,W = map(int,input().split())
a = [[x for x in input()] for i in range(H)]
f = True
if H ==1 and W == 1:
    if a[0][0] == "#":
        print("No")
        f = False
if H == 1 and W != 1:
    if a[0][0] == "#":
        if a[0][1] == ".":
            print("No")
            f = False
    if a[0][-1] == "#":
        if a[0][-2] == ".":
            print("No")
            f = False
    for i in range(1,W-1):
        if a[0][i] == "#":
            if a[0][i-1] == "." and a[0][i+1] == ".":
                print("No")
                f = False
                break

if H != 1 and W == 1:
    if a[0][0] == "#":
        if a[1][0] == ".":
            print("No")
            f = False
    if a[-1][0] == "#":
        if a[-2][0] == ".":
            print("No")
            f = False
    for i in range(1,H-1):
        if a[i][0] == "#":
            if a[i-1][0] == "." and a[i+1][0] == ".":
                print("No")
                f = False
                break

if H != 1 and W != 1:
    if a[0][0] == "#":
        if a[0][1] == "." and a[1][0] == ".":
            print("No")
            f = False
    if a[0][-1] == "#":
        if a[0][-2] == "." and a[1][-1] == ".":
            print("No")
            f = False
    if a[-1][0] == "#":
        if a[-1][1] == "." and a[-2][0] == ".":
            print("No")
            f = False
    if a[-1][-1] == "#":
        if a[-1][-2] == "." and a[-2][-1] == ".":
            print("No")
            f = False
    for i in range(1,H-1):
        if a[0][i] == "#":
            if a[0][i-1] == "." and a[0][i+1] == "." and a[1][i] == ".":
                print("No")
                f = False
                break
        if a[-1][i] == "#":
            if a[-1][i-1] == "." and a[-1][i+1] == "." and a[-2][i] == ".":
                print("No")
                f = False
                break
    for i in range(1,W-1):
        if a[i][0] == "#":
            if a[i-1][0] == "." and a[i+1][0] == "." and a[i][1] == ".":
                print("No")
                f = False
                break
        if a[i][-1] == "#":
            if a[i-1][-1] == "." and a[i+1][-1] == "." and a[i][-2] == ".":
                print("No")
                f = False
                break
        if f:
            for i in range(1,H-1):
                for j in range(1,W-1):
                    if a[i][j] == "#":
                        if a[i][j+1] == "." and a[i][j-1] == "." and a[i+1][j] == "." and a[i-1][j] == ".":
                            print("No")
                            f = False
                            break
                            break
    if f:
        print("Yes")

Submission status: Runtime Error

Solution code:
import sys

h, w = map(int, input().split())

s = []
for i in range(h):
    s.append(input())

ans = True
flag = False

for i in range(h):
    for j in range(w):
        if s[i][j] == '#':
            if i == 0:
                if(s[i][j-1] == '.' and s[i+1][j] == '.' and s[i][j+1] == '.'):
                    ans = False
                    break

            elif j == 0:
                if(s[i-1][j] == '.' and s[i+1][j] == '.' and s[i][j+1] == '.'):
                    ans = False
                    break
            elif i == h-1:
                if(s[i-1][j] == '.' and s[i][j-1] == '.' and s[i][j+1] == '.'):
                    ans = False
                    break
            elif j == w-1:
                if(s[i-1][j] == '.' and s[i][j-1] == '.' and s[i+1][j] == '.'):
                    ans = False
                    break
            else:
                if(s[i-1][j] == '.' and s[i][j-1] == '.' and s[i+1][j] == '.' and s[i][j+1] == '.'):
                    ans = False
                    break

    if not(ans):
        break

if ans:
    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 not ((masu[h][w] == masu[h+1][w]) or (masu[h][w] == masu[h][w+1]) or (masu[h][w] == masu[h-1][w]) or (masu[h][w] == masu[h][w-1])):
                result = False
                break

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

Submission status: Runtime Error

Solution code:
h,w = map(int,input().split())
c = [[] for i in range(0,h+2)]
ans = "Yes"
c[0] = ["."for i in range(0,w+2)]
c[h+1] = ["."for i in range(0,w+2)]
for i in range(1,h+1):
    d = []
    d = list(input())
    d.append(".")
    d.insert(0,".")
    c[i] = d
for i in range(1,h+1):
    for j in range(1,w+1):
        if c[j][i] == "#":
            flag = "No"
            if(c[j][i-1] == "#"):
                flag = "Yes"
            if(c[j][i+1] == "#"):
                flag = "Yes"
            if(c[j-1][i] == "#"):
                flag = "Yes"
            if(c[j+1][i] == "#"):
                flag = "Yes"
            if(flag == "No"):
                ans = "No"
print(ans)

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):
        if pic[i][j] == '#':
            flag = 0
            break

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

Submission status: Runtime Error

Solution code:
H,W=list(map(int,input().split())) # R行 C列 の迷路を受け取る

canv=[]
for i in range(H):
    canv.append([])
    line_input=input() # 迷路を1行取得
    for j in range(W):
        canv[i].append(line_input[j:j+1]) # slice による部分文字列取得

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

def dfs(x,y):
    for i in range(4):
        canv[x][y]="."
        nx = x + dx[i]
        ny = y + dy[i]
        if 0<=nx and nx<H and 0<=ny and ny<W:
            if canv[nx][ny]=="#":
                dfs(nx,ny)

for i in range(H):
    for j in range(W):
        for k in range(4):
            nx1 = i + dx[k]
            ny1 = j + dy[k]
            if 0<=nx1 and nx1<H and 0<=ny1 and ny1<W:
                if canv[i][j]=="#" and canv[nx1][ny1]=="#":
                    dfs(i,j)
flg = True
for i in range(H):
    for j in range(W):
        if canv[i][j]=="#":
            flg = False
if flg: print("Yes")
else: print("No")

Submission status: Runtime Error

Solution code:
import sys
H,W = input().split()
H = int(H)
W = int(W)
s = []

s.append("."*(W+2))
for i in range(H):
    s.append("."+input()+".")

s.append("."*(W+2))

for j in range(1,1+H):
    for i in range(1,1+W):

        if s[i][j] == "#":
            if s[i][j-1] != "#" and s[i][j+1] != "#" and s[i-1][j] != "#" and s[i+1][j] != "#":
                print("No")

                sys.exit()



print("Yes")

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)    

print(pic)
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):
        if pic[i][j] == '#':
            flag = 0
            break

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

Submission status: Runtime Error

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

kabe_up_down = []
for i in range(w+1):
    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)    

print(pic)
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):
        if pic[i][j] == '#':
            flag = 0
            break

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

Submission status: Runtime Error

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

kabe_up_down = []
for i in range(w):
    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):
        if pic[i][j] == '#':
            flag = 0
            break

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

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 not ((masu[h][w] == masu[h+1][w]) or (masu[h][w] == masu[h][w+1]) or (masu[h][w] == masu[h-1][w]) or (masu[h][w] == masu[h][w-1])):
                result = False
                break

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

Submission status: Runtime Error

Solution code:
H, W = map(int, input().split(' '))
matrix = []
for _ in range(W):
    tmp = [0 if j == '.' else 1 for j in input()]
    matrix.append(tmp)

flag = 'Yes'
for i, row in enumerate(matrix):
    for j, s in enumerate(row):
        if s == 1:
            if j > 0 and row[j-1] == 0:
                if j < W - 1 and row[j+1] == 0:
                    if i > 0 and matrix[i-1][j] == 0:
                        if i < H - 1 and matrix[i+1][j] == 0:
                            flag = 'No'
                            break

print(flag)

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][w] == masu[h+1][w]) or (masu[h][w] == masu[h][w+1]) or (masu[h][w] == masu[h-1][w]) or (masu[h][w] == masu[h][w-1]):
                pass
            else:
                result = False

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

Submission status: Runtime Error

Solution code:
import sys
H,W = input().split()
H = int(H)
W = int(W)
s = []

s.append("."*(W+1))
for i in range(H):
    s.append("."+input()+".")

s.append("."*(W+2))

for j in range(1,1+H):
    for i in range(1,1+W):
#        print(i,j,s[i][j])
        if s[i][j] == "#":
            if s[i][j-1] != "#" and s[i][j+1] != "#" and s[i-1][j] != "#" and s[i+1][j] != "#":
                print("No")
#                print(s[i][j-1],s[i][j+1], s[i-1][j],s[i+1][j])
                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)

for i in range(H): #行数ぶん繰り返す
    for j in range(W): #列数ぶん繰り返す＝一行当たりのマス数分
        if j == 0:
            if grid[i][j] == "#" and grid[i][j+1] == "." :
                soloGrid = str(i) + ", " + str(j)
                soloList.append(soloGrid)
            else:
                pass
                
        elif j == W-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(W):  #列数ぶん繰り返す
    for i in range(H): #行数ぶん繰り返す＝一列当たりのマス数分
        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())
masu = [[0 for y in range(h)] for x in range(w)]
for y in range(0, h):
    z = list(input())
    for x in range(0, w):
        masu[y][x] = z[x]
hantei = "Yes"
for y in range(0, h):
    for x in range(0, w):
        if (masu[y][x] == "#"):
            if (not((y > 0 and masu[y - 1][x] == "#") or (y < h - 1 and masu[y + 1][x] == "#") or (x > 0 and masu[y][x - 1] == "#") or (x < w - 1 and masu[y][x + 1] == "#"))):
                hantei = "No"
print (hantei)

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)
        if masu[h][w] == "#":
            if (masu[h][w] == masu[h+1][w]) or (masu[h][w] == masu[h][w+1]) or (masu[h][w] == masu[h-1][w]) or (masu[h][w] == masu[h][w-1]):
                pass
            else:
                result = False

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

Submission status: Runtime Error

Solution code:
H,W = map(int,input().split())
a = [[x for x in input()] for i in range(H)]
f = True
if a[0][0] == "#":
    if a[0][1] == "." and a[1][0] == ".":
        print("No")
        f = False
if a[0][-1] == "#":
    if a[0][-2] == "." and a[1][-1] == ".":
        print("No")
        f = False
if a[-1][0] == "#":
    if a[-1][1] == "." and a[-2][0] == ".":
        print("No")
        f = False
if a[-1][-1] == "#":
    if a[-1][-2] == "." and a[-2][-1] == ".":
        print("No")
        f = False
for i in range(1,H-1):
    if a[0][i] == "#":
        if a[0][i-1] == "." and a[0][i+1] == "." and a[1][i] == ".":
            print("No")
            f = False
            break
    elif a[-1][i] == "#":
        if a[-1][i-1] == "." and a[-1][i+1] == "." and a[-2][i] == ".":
            print("No")
            f = False
            break
for i in range(1,W-1):
    if a[i][0] == "#":
        if a[i-1][0] == "." and a[i+1][0] == "." and a[i][1] == ".":
            print("No")
            f = False
            break
    if a[i][-1] == "#":
        if a[i-1][-1] == "." and a[i+1][-1] == "." and a[i][-2] == ".":
            print("No")
            f = False
            break
    if f:
        for i in range(1,H-1):
            for j in range(1,W-1):
                if a[i][j] == "#":
                    if a[i][j+1] == "." and a[i][j-1] == "." and a[i+1][j] == "." and a[i-1][j] == ".":
                        print("No")
                        f = False
                        break
                        break
if f:
    print("Yes")

Submission status: Runtime Error

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

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

pic.append(kabe_up_down)
for i in range(h):
    onelist = ['.']
    inp = list(str(input()))
    for i in range(len(inp)):
        onelist.append(inp[i])
    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):
        if pic[i][j] == '#':
            flag = 0
            break

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

Submission status: Runtime Error

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

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

pic.append(kabe_up_down)
for i in range(h):
    onelist = ['.']
    inp = list(str(input()))
    for i in range(len(inp)):
        onelist.append(inp[i])
    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):
        if pic[i][j] == '#':
            flag = 0
            break

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

Submission status: Runtime Error

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

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

pic.append(kabe_up_down)
for i in range(h):
    onelist = ['.']
    inp = list(str(input()))
    for i in range(len(inp)):
        onelist.append(inp[i])
    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):
        if pic[i][j] == '#':
            flag = 0
            break
        
if flag == 0:
    print('No')
else:
    print('Yes')

Submission status: Runtime Error

Solution code:
H,W = map(int,input().split())
a = [[x for x in input()] for i in range(H)]
f = True
if a[0][0] == "#":
    if a[0][1] == "." and a[1][0] == ".":
        print("No")
        f = False
elif a[0][-1] == "#":
    if a[0][-2] == "." and a[1][-1] == ".":
        print("No")
        f = False
elif a[-1][0] == "#":
    if a[-1][1] == "." and a[-2][0] == ".":
        print("No")
        f = False
elif a[-1][-1] == "#":
    if a[-1][-2] == "." and a[-2][-1] == ".":
        print("No")
        f = False
else:
    for i in range(1,H-1):
        if a[0][i] == "#":
            if a[0][i-1] == "." and a[0][i+1] == "." and a[1][i] == ".":
                print("No")
                f = False
                break
        elif a[-1][i] == "#":
            if a[-1][i-1] == "." and a[-1][i+1] == "." and a[-2][i] == ".":
                print("No")
                f = False
                break
    for i in range(1,W-1):
        if a[i][0] == "#":
            if a[i-1][0] == "." and a[i+1][0] == "." and a[i][1] == ".":
                print("No")
                f = False
                break
        elif a[i][-1] == "#":
            if a[i-1][-1] == "." and a[i+1][-1] == "." and a[i][-2] == ".":
                print("No")
                f = False
                break
    if f:
        for i in range(1,H-1):
            for j in range(1,W-1):
                if a[i][j] == "#":
                    if a[i][j+1] == "." and a[i][j-1] == "." and a[i+1][j] == "." and a[i-1][j] == ".":
                        print("No")
                        f = False
                        break
                        break
if f:
    print("Yes")