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 = (list)(map(int, input().split()))
l = [[lin for lin in input()] for _ in range(h)]

gri = [[0 for i in range(w+2)] for _ in range(h+2)]
for i in range(h+2):
    for j in range(w+2):
        if i == 0 or i == h+1 or j == 0 or j == w+1:
            gri[i][j] = '.'
        else:
            gri[i][j] = l[i-1][j-1]


flag = 0
for i in range(1, h+1):
    for j in range(1, w+1):
        if gri[i][j] == '#':
            flag += 1
            if gri[i-1][j] == '.' and gri[i+1][j] == '.' and gri[i][j-1] == '.' and gri[i][j+1] == '.':
                print("No")
                exit(1)

if flag >= 2:
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

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

gri = [[0 for i in range(w+2)] for _ in range(h+2)]
for i in range(h+2):
    for j in range(w+2):
        if i == 0 or i == h+1 or j == 0 or j == w+1:
            gri[i][j] = '.'
        else:
            gri[i][j] = l[i-1][j-1]

flag = 0
for i in range(1, h+1):
    for j in range(1, w+1):
        if gri[i][j] == '#':
            flag = 1
            if gri[i-1][j] == '.' and gri[i+1][j] == '.' and gri[i][j-1] == '.' and gri[i][j+1] == '.':
                print("No")
                exit(1)

if flag == 0:
    print("No")
else:
    print("Yes")
# print(l)
# print(gri)

Submission status: Runtime Error

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

gri = [[0 for i in range(w+2)] for _ in range(h+2)]
for i in range(h+2):
    for j in range(w+2):
        if i == 0 or i == h+1 or j == 0 or j == w+1:
            gri[i][j] = '.'
        else:
            gri[i][j] = l[i-1][j-1]

flag = 0
for i in range(1, h+1):
    for j in range(1, w+1):
        if gri[i][j] == '#':
            flag = 0
            if gri[i-1][j] == '.' and gri[i+1][j] == '.' and gri[i][j-1] == '.' and gri[i][j+1] == '.':
                print("No")
                exit(1)

if flag == 0:
    print("No")
else:
    print("Yes")
# print(l)
# print(gri)

Submission status: Runtime Error

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

gri = [[0 for i in range(w+2)] for _ in range(h+2)]
for i in range(h+2):
    for j in range(w+2):
        if i == 0 or i == h+1 or j == 0 or j == w+1:
            gri[i][j] = '.'
        else:
            gri[i][j] = l[i-1][j-1]

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

print("Yes")
# print(l)
# print(gri)

Submission status: Runtime Error

Solution code:
h, w = map(int,input().split())
arr = [["."] * (w + 2)]
for i in range(h):
    arr += [["."] + list(input()) + ["."]]
arr += [["."] * (w + 2)]

flg = 0    

for j in range(1, h+1):
    for k in range(1, w+!):
        if arr[j][k] == "#":
            if (arr[j-1][k] == '.') and (arr[j][k-1] == '.') and (arr[j+1][k] == '.') and (arr[j][k+1] == '.'):
                flg = 1    
        
if flg == 0:
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

Solution code:
h, w = map(int,input().split())
arr = [["."] * (w + 2)]
for i in range(w):
    arr += [["."] + list(input()) + ["."]]
arr += [["."] * (w + 2)]

print(arr)
flg = 0    

for j in range(1, h+1):
    for k in range(1, w+1):
        if arr[j][k] == "#":
            if (arr[j-1][w] == '.') and (arr[j][w-1] == '.') and (arr[j+1][w] == '.') and  (arr[j][w+1] == '.'):
                flg = 1    
        
if flg == 0:
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

Solution code:
h, w = map(int,input().split())
arr = [["."] * (w + 2)]
for i in range(w):
    arr += [["."] + list(input()) + ["."]]
arr += [["."] * (w + 2)]

flg = 0    

for j in range(1, h):
    for k in range(1, w):
        if arr[j][k] == "#":
            if (arr[j-1][w] == '.') and (arr[j][w-1] == '.') and (arr[j+1][w] == '.') and  (arr[j][w+1] == '.'):
                flg = 1    
        
if flg == 0:
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

Solution code:
h, w = map(int,input().split())
arr = [["."] * (w + 2)]
for i in range(w):
    arr += [["."] + list(input()) + ["."]]
arr += [["."] * (w + 2)]

flg = 0    

for j in range(1, h):
    for k in range(1, w):
        if arr[j][k] == "#":
            if arr[j-1][w] == arr[j][w-1] == arr[j+1][w] == arr[j][w+1] == '.':
                flg = 1    
        
if flg == 0:
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

Solution code:
H, W = map(int, input().split())
s = [input() for _ in range(H)]
case = [[1, 0], [-1, 0], [0, 1], [0, -1]]
flag = True

for i in range(H):
    for j in range(W):
        if s[i][j] == '#':
            flag = False
            for k in range(4):
                x, y = i+case[k][0], j+case[k][1]
                if x < 0 or x >= H or y < 0 or y >= H:
                    continue
                if s[x][y] == '#':
                    flag = True
                    break
            if not flag:
                break
    if not flag:
        break

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

Submission status: Runtime Error

Solution code:
H,W=(int(i) for i in input().split(' '))
s=[]
for h in range(H):
  s+=[input()]
for h in range(H):
  for w in range(W):
    if s[h][w]=='#':
      if h>0:
        if s[h-1][w]=='#':
          break
      elif w>0:
        if s[h][w-1]=='#':
          break
      elif w<W-1:
        if h[h][w+1]=='#':
          break
      elif h<H-1:
        if s[h+1][w]=='#':
          break
      else:
        print('No')
        exit()
print('Yes')

Submission status: Runtime Error

Solution code:
H,W = map(int,input().split())
L = []
for i in range(H):
    l = list(input())
    L.append(l)

def judge(list,i,j):
    if i != 0:
        top = list[i-1][j]
    else:
        top = "."
    if j != 0:
        left = list[i][j-1]
    else:
        left = "."
    if i != H-1:
        bottom = list[i+1][j]
    else:
        bottom = "."
    if j != W-1:
        right = list[i][j+1]
    else:
        right = "."
    return top == "#" or left == "#" or bottom == "#" or right == "#"

for i in range(H):
    for j in range(W):
        if L[i][i] == "#" and judge(L,i,j) is False:
            print("No")
            exit()
print("Yes")

Submission status: Runtime Error

Solution code:
H,W = map(int,input().split())
L = []
for i in range(H):
    l = list(input())
    L.append(l)

def judge(list,i,j):
    if i != 0:
        top = list[i-1][j]
    else:
        top = "."
    if j != 0:
        left = list[i][j-1]
    else:
        left = "."
    if i != W-1:
        bottom = list[i+1][j]
    else:
        bottom = "."
    if j != H-1:
        right = list[i][j+1]
    else:
        right = "."
    return top == "#" or left == "#" or bottom == "#" or right == "#"

for i in range(W):
    for j in range(H):
        if L[i][i] == "#" and judge(L,i,j) is False:
            print("No")
            exit()
print("Yes")

Submission status: Runtime Error

Solution code:
def main():
    h, w = map(int, input().split())
    c = []
    c.append(['.'] * (w + 2))
    for _ in range(h):
        c.append(['.'] + list(input()) + ['.'])
    c.append(['.'] * (w + 2))
    for h in range(1, h + 2):
        for w in range(1, w + 2):
            if c[h][w] == '#':
                if c[h - 1][w] == c[h + 1][w] == c[h][w - 1] == c[h][w + 1] == '.':
                    print('no')
                    return
    print('yes')


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
H,W = map(int,input().split())
L = [input() for i in range(H)]
dxy = [[1,0],[-1,0],[0,1],[0,-1]]
flag = 0
for y in range(H) :
    for x in range(W) :
        if L[y][x] == "#" :
            for dx,dy in dxy :
                nx = x+dx
                ny = y+dy
                if (0 <= nx <= W-1) and (0 <= ny <= H-1) :
                    if L[nx][ny] == "#" :
                        flag = 1
                        break
                    else :
                        flag = 0
if flag == 1 :
    print("Yes")
else :
    print("No")

Submission status: Runtime Error

Solution code:
H,W = map(int,input().split())
L = []
for i in range(H) :
    L.append(list(input()))

dxy = [(1,0),(-1,0),(0,1),(0,-1)]

flag = 0
for x in range(W) :
    for y in range(H) :
        if L[x][y] == "#" :
            for dx,dy in dxy :
                nx = x+dx
                ny = y+dy
                if (0 <= nx <= W-1) and (0 <= ny <= H-1) :
                    if L[nx][ny] == "#" :
                        flag = 0
                        
                        break
                    flag = 1
                else :
                    continue

if flag != 1 :
    print("Yes")
else :
    print("No")

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import sys
(h, w) = map(int, input().split())
sw = []
sw.append(['.' for i in range(h + 2)])
for i in range(w):
    sw.append(['.'] + list(input()) + ['.'])
sw.append(['.' for i in range(h + 2)])

dirs = [[1, 0], [-1, 0], [0, 1], [0, -1]]
for i in range(1, h + 1):
    for j in range(1, w + 1):
        if sw[i][j] == '.':
            continue
        ok = False
        for dir in dirs:
            if sw[i + dir[0]][j + dir[1]] == '#':
                ok = True
                break
        if ok == False:
            print('No')
            sys.exit(0)
print('Yes')

Submission status: Runtime Error

Solution code:
import sys
(h, w) = map(int, input().split())
sw = [['.' for i in range(h + 2)]]
for i in range(w):
    sw.append(['.'] + list(input()) + ['.'])
sw.append(['.' for i in range(h + 2)])

dirs = [[1, 0], [-1, 0], [0, 1], [0, -1]]
for i in range(1, w + 1):
    for j in range(1, h + 1):
        if sw[i][j] == '.':
            continue
        ok = False
        for dir in dirs:
            if sw[i + dir[0]][j + dir[1]] == '#':
                ok = True
                break
        if ok == False:
            print('No')
            sys.exit(0)
print('Yes')

Submission status: Runtime Error

Solution code:
(h, w) = map(int, input().split())
sw = [['.' for i in range(h + 2)]]
for i in range(w):
    sw.append(['.'] + list(input()) + ['.'])
sw.append(['.' for i in range(h + 2)])

dirs = [[1, 0], [-1, 0], [0, 1], [0, -1]]
ng = False
for i in range(1, w + 1):
    if ng == True:
        break
    for j in range(1, h + 1):
        if ng == True:
            break
        if sw[i][j] == '.':
            continue
        ok = False
        for dir in dirs:
            if sw[i + dir[0]][j + dir[1]] == '#':
                ok = True
                break
        if ok == False:
            print('No')
            ng = True
if ng == False:
    print('Yes')

Submission status: Runtime Error

Solution code:
H, W = map(int, input().rstrip().split())
s =[list(input().rstrip()) for _ in range(W)]

judge = True
for i in range(H):
    for j in range(W):
        if s[i][j] =='#':
            flag = 0
            if i-1 >= 0 and s[i-1][j] == '#':
                flag = 1
            if j-1 >= 0 and s[i][j-1] == '#':
                flag = 1
            if j+1 < W and s[i][j+1] == '#':
                flag = 1
            if i+1 < H and s[i+1][j] == '#':
                flag = 1
            if flag == 0:
                judge == False
                
if judge:
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

Solution code:
H, W = map(int, input().rstrip().split())
s =[list(input().rstrip()) for _ in range(W)]
colors = [['.' for _ in range(W)] for _ in range(H)] 
search = [[-1, 0], [0, -1], [0, 1], [1, 0]]

judge = True
for i in range(H):
    for j in range(W):
        if s[i][j] =='#':
            flag = 0
            for k in range(len(search)):
                x = i + search[k][0]
                y = j + search[k][1]
                if 0 <= x < H and 0 <= y < W and s[x][y] == '#':
                    colors[i][j] = colors[x][y] = '#'
                    flag = 1
                    if flag == 0:
                        judge = False
                        
if s != colors:
    judge = False

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

Submission status: Runtime Error

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

for i in range(H):
    picture.append(list(input()))

for i in range(H):
    for j in range(W):
        if picture[i][j] == ".":
            continue
        elif picture[i][j] == "S":
            if i == 0:
                if (j == W-1)and(picture[1][j] == "#"):
                    picture[1][j] == "S"
                else:
                    if picture[0][j+1] == "#":
                        picture[0][j+1] = "S"
                    if picture[1][j] == "#":
                        picture[1][j] = "S"
            elif i == H-1:
                if (j == 0)and(picture[i][1] == "#"):
                    picture[i][1] ="S"
                elif j == W-1:
                    continue
                else:
                    if picture[i][j+1] == "#":
                        picture[i][j+1] = "S"
            elif j == W-1:
                if picture[i+1][j] == "#":
                    picture[i+1][j] = "S"
            else:
                if picture[i][j+1] == "#":
                    picture[i][j+1] = "S"
                if picture[i+1][j] == "#":
                    picture[i+1][j] = "S"
        else:
            if i==0:
                if (j != 0)and(j != W-1):
                    if (picture[i][j-1] == ".")and(picture[i-1][j] == ".")and(picture[i][j+1] == "."):
                        print("No")
                        exit()
                    if picture[i][j+1] == "#":
                        picture[i][j+1] == "S"
                    if picture[i+1][j] == "#":
                        picture[i+1][j] == "S"
                elif j == 0:
                    if (picture[1][0] == ".")and(picture[0][1] == "."):
                        print("No")
                        exit()
                    if picture[1][0] == "#":
                        picture[1][0] = "S"
                    if picture[0][1] == "#":
                        picture[0][1] = "S"
                else:
                    print("No")
                    exit()
            elif i==H-1:
                if (j != 0)and(j != W-1):
                    if (picture[i][j-1] == ".")and(picture[i][j+1] == "."):
                        print("No")
                        exit()
                    if picture[i][j+1] == "#":
                        picture[i][j+1] == "S"
                elif j == 0:
                    if picture[i][1] == ".":
                        print("No")
                        exit()
                    if picture[i][1] == "#":
                        picture[i][1] = "S"
                else:
                    if picture[i][j] == "#":
                        print("No")
                        exit()
            elif j==0:
                if (picture[i+1][j] == ".")and(picture[i][1] == "."):
                    print("No")
                    exit()
                if picture[i+1][0] == "#":
                    picture[i+1][0] = "S"
                if picture[i][1] == "#":
                    picture[i][1] = "S"
            elif j==W-1:
                if picture[i+1][j] == ".":
                    print("No")
                    exit()
                if picture[i+1][j] == "#":
                    picture[i+1][j] = "S"
            else:
                if (picture[i+1][j] == ".")and(picture[i-1][j] == ".")and(picture[i][j+1] == ".")and(picture[i][j-1] == "."):
                    print("No")
                    exit()
                if picture[i+1][j] == "#":
                    picture[i+1][j] = "S"
                if picture[i-1][j] == "#":
                    picture[i-1][j] = "S"
                if picture[i][j+1] == "#":
                    picture[i][j+1] = "S"
                if picture[i][j-1] == "#":
                    picture[i][j-1] = "S"
print("Yes")

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-

H, W = map(int, input().split())
s = []

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

for i in range(H):
    for j in range(W):
        OK_cnt = 0
        if s[i][j] == '#':
            #上
            if j > 0 and s[i][j-1] == '#':
                OK_cnt += 1
            #右
            if i+1 < W and s[i+1][j] == '#':
                OK_cnt += 1
            #下
            if j+1 < H and s[i][j+1] == '#':
                OK_cnt += 1
            #左
            if i > 0 and s[i-1][j] == '#':
                OK_cnt += 1
            if OK_cnt == 0:
                print('No')
                exit()

print('Yes')

Submission status: Runtime Error

Solution code:
xy=[(1,0),(-1,0),(0,1),(0,-1)]

h,w=map(int,input().split())
l=[]
for i in range(h):
    l.appned(input())
for i in range(h):
    for j in range(w):
        if l[i][j]=="#":
            f=0
            for x,y in xy:
                if 0<=(i+y)<h and 0<=(j+x)<w l[i+y][j+x]=="#": f=1
            if f==0:
                print("No")
                exit()
                

print("Yes")

Submission status: Runtime Error

Solution code:
H,W = map(int,raw_input().split())
 
s = []
for i in range(H):
	s.append(raw_input())
 
flag=True
for i in range(H):
	for j in range(W):
		if s[i][j]=='#':
			local_flag=False
			if i+1<H:
				if s[i+1][j]=='#':
					local_flag=True
			if j+1<W:
				if s[i][j+1]=='#':
					local_flag=True
			if i-1>=0:
				if s[i-1][j]=='#':
					local_flag=True
			if j-1>=0:
				if s[i][j-1]=='#':
					local_flag=True
			if local_flag=False:
				flag=False
if flag:
	print 'Yes'
else:
	print 'No'

Submission status: Runtime Error

Solution code:

H,W = map(int,raw_input().split())
 
s = []
for i in range(H):
	s.append(raw_input())
 
flag=True
for i in range(H):
	for j in range(W):
 
		if s[i][j]=='#':
			local_flag=False
			if i+1<H:
			  if s[i+1][j]=='#':
					local_flag=True
			if j+1<W:
			  if s[i][j+1]=='#':
					local_flag=True
			if i-1>=0:
			  if s[i-1][j]=='#':
					local_flag=True
			if j-1>=0:
				if s[i][j-1]=='#':
					local_flag=True
			if local_flag=False:
				flag=False
if flag:
	print 'Yes'
else:
	print 'No'

Submission status: Runtime Error

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

s = []
for i in range(H):
  s.append(raw_input())

flag=True
for i in range(H):
  for j in range(W):

    if s[i][j]=='#':
    	local_flag=False
		if i+1<H:
          if s[i+1][j]=='#':
            local_flag=True
        if j+1<W:
          if s[i][j+1]=='#':
            local_flag=True
        if i-1>=0:
          if s[i-1][j]=='#':
            local_flag=True
        if j-1>=0:
          if s[i][j-1]=='#':
            local_flag=True
        if local_flag=False:
          flag=False
if flag:
  print 'Yes'
else:
  print 'No'

Submission status: Runtime Error

Solution code:
import sys
h,w = ri()
C = [input() for _ in range(h)]

dd = [(0,1),(0,-1),(1,0),(-1,0)]
for i in range(h):
    for j in range(w):
        if C[i][j] == '#':
            b = []
            for di,dj in dd:
                if 0<=i+di<h and 0<=j+dj<w:
                    b.append(C[i+di][j+dj] == '.')
            if all(b):
                print('No')
                sys.exit()
print('Yes')

Submission status: Runtime Error

Solution code:
H, W = list(map(int, input().split()))
s = [[c for c in input()] for _ in range(H)]
accept = True

def dfs(x, y, count):
    if  x < 0 or W <= x or y < 0 or H <= y:
        return count - 1
    elif s[y][x] != "#":
        return count - 1
    else:
        s[y][x] = "."
        return max(dfs(x-1, y, count+1), dfs(x+1, y, count+1), dfs(x, y-1, count+1), dfs(x, y+1, count+1))

for y in range(H):
    for x in range(W):
        if s[y][x] != "#":
            continue
        elif dfs(x, y, 0) == 0:
            accept = False

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

Submission status: Runtime Error

Solution code:
H, W = map(int, input().split())
picture = [input() for _ in range(H)]

for i in range(H):
	for j in range(W):
		if picture[i][j] == '#':
			if i == 0 or picture[i-1][j] == '.':
				if j == 0 or picture[i][j-1] == '.':
					if i == H or picture[i+1][j] == '.':
						if j == W or picture[i][j+1] == '.':
							print('No')
							exit()

print('Yes')

Submission status: Runtime Error

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

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

for i in range(1,h-1):
    for j in range(1, w-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]==".":
            print("No")
            exit()

for j in range(1,w-1):
    if s[0][j] == "#" and s[1][j] == "." and s[0][j + 1] == "." and s[0][j - 1] == ".":
        print("No")
        exit()
    if s[h-1][j] == "#" and s[h-2][j] == "." and s[h-1][j + 1] == "." and s[h-1][j - 1] == ".":
        print("No")
        exit()


for i in range(1,h-1):
    if s[i][0] == "#" and s[i + 1][0] == "." and s[i][1] == "." and s[i - 1][0] == ".":
        print("No")
        exit()
    if s[i][w-1] == "#" and s[i + 1][w-1] == "." and s[i][w-2] == "." and s[i - 1][w-1] == ".":
        print("No")
        exit()

if s[0][0]=="#" and s[1][0]=="." and s[0][1]==".":
    print("No")
    exit()

if s[h-1][0]=="#" and s[h-1][1]=="." and s[h-2][0]==".":
    print("No")
    exit()

if s[0][w-1]=="#" and s[1][w-1]=="." and s[0][w-2]==".":
    print("No")
    exit()

if s[h-1][w-1]=="#" and s[h-1][w-2]=="." and s[h-2][s-1]==".":
    print("No")
    exit()

print("Yes")

Submission status: Runtime Error

Solution code:
H, W = map(int, input().split())
S = [input() for i in range(W)]
dd = ((0, -1), (-1, 0), (0, 1), (1, 0))
for i in range(H):
  for j in range(W):
    if S[i][j] == '.':
      continue
    for dx, dy in dd:
      nx = j + dx
      ny = i + dy
      if 0 <= nx < W and 0 <= ny < H:
        if S[ny][nx] == '#':
          break
    else:
      print('No')
      quit()
print('Yes')

Submission status: Runtime Error

Solution code:
H, W = map(int, input().split())
S = [input() for i in range(W)]
dd = ((0,-1),(-1,0),(0,1),(1,0))
for i in range(H):
  for j in range(W):
    if S[i][j] == '.':
      continue
    for dx,dy in dd:
      nx = j + dx
      ny = i + dy
      if 0 <= nx < W and 0 <= ny < H and S[ny][nx] == '#':
        break
    else:
      print('No')
      exit()
print('Yes')

Submission status: Runtime Error

Solution code:
H, W = map(int, input().split())
S = [input() for i in range(W)]
dd = ((0,-1),(-1,0),(0,1),(1,0))
for i in range(H):
  for j in range(W):
    if S[i][j] == '.':
      continue
    for dx,dy in dd:
      nx = j + dx
      ny = i + dy
      if 0 <= nx < W and 0 <= ny < H and S[ny][nx] == '#':
        break
    else:
      print('No')
      quit()
print('Yes')

Submission status: Runtime Error

Solution code:
H, W = map(int, input().split())
S = [input() for i in range(W)]
dd = ((0,-1),(-1,0),(0,1),(1,0))
for i in range(H):
  for j in range(W):
    if S[i][j] == '.':
      continue
    for dx,dy in dd:
      nx = j + dx
      ny = i + dy
      if 0<= nx < W and 0 <= ny < H and S[ny][nx] == '#':
        break
    else:
      print('No')
      quit()
print('Yes')

Submission status: Runtime Error

Solution code:
import sys

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

A = []
for i in range(W):
    A.append(list(input()))

# print(A)
for r in range(H):
    for line in range(W):
        # print(r, line)
        if(A[r][line] != "#"):
            continue

        # print(r, line, A[r][line])

        if(line == 0 or W == 1):
            L = False
        else:
            L = A[r][line - 1] == "#"

        if(r == 0 or H == 1):
            U = False
        else:
            U = A[r - 1][line] == "#"

        if(line == W - 1 or W == 1):
            R = False
        else:
            R = A[r][line + 1] == "#"

        if(r == H - 1 or H == 1):
            D = False
        else:
            D = A[r + 1][line] == "#"

        # print(L, U, R, D)
        # print(L or U or R or D)
        if((L or U or R or D) is False):
            print("No")
            sys.exit()

print("Yes")

Submission status: Runtime Error

Solution code:
import sys

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

A = []
for i in range(W):
    A.append(list(input()))

# print(A)
for r in range(H):
    for line in range(W):
        # print(r, line)
        if(A[r][line] != "#"):
            continue

        # print(r, line, A[r][line])

        if(line == 0):
            L = False
        else:
            L = A[r][line - 1] == "#"

        if(r == 0):
            U = False
        else:
            U = A[r - 1][line] == "#"

        if(line == W - 1):
            R = False
        else:
            R = A[r][line + 1] == "#"

        if(r == H - 1):
            D = False
        else:
            D = A[r + 1][line] == "#"

        # print(L, U, R, D)
        # print(L or U or R or D)
        if((L or U or R or D) is False):
            print("No")
            sys.exit()

print("Yes")

Submission status: Runtime Error

Solution code:
import sys

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

A = []
for i in range(W):
  A.append(input())

for r in range(H):
  for l in range(W):
    if(A[r][l] != "#"):
      continue
    
    if(l == 0):
      L = True
    else:
      L = A[r][l-1] == "#"
    
    if(r == 0):
      U = True
    else:
      U = A[r-1][l] == "#"
    
    if(l == W - 1):
      R = True
    else:
      R = A[r][l+1] == "#"
    
    if(r == H -1):
      D = True
    else:
      D = A[r+1][l] == "#"
    
    if(L or U or R or D is False):
      print("No")
      sys.exit()
      
print("Yes")