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:
import  numpy as np
h,w=map(int,input().split())
s = [[0]*(w+2)]
for i in range(h):
    s.append([0]+list(input())+[0])
s.append([0]*(w+2))

t = np.array(s)
c = 0

def sirabe(t,i,j):
    if t[i-1][j] != "#" and t[i][j-1] != "#" and t[i+1][j] != "#" and t[i][j+1] != "#":
        return False
    else:
        return True


for i in range(1,h+1):
    for j in range(1,w+1):
        if sirabe(t,i,j):
            continue
        else:
            c = 1
            break
    if c == 1:
        break

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

Submission status: Runtime Error

Solution code:
import itertools
H,W = map(int,input().split())
mas = [input() for _ in range(H)]
ans = 0
for i, j in itertools.product(range(H), range(W)):
    if mas[i][j] == '.':
        pass
    else :
        if i == 0 : # top row
            if j == W - 1 : # right edge
                if mas[i][j-1] == '.' and mas[i][j+1] == '.' :
                    print('No')
                    #print(1)
                    ans = 1
                    break
            elif j == 0 : # left edge
                if mas[i+1][j] == '.' and mas[i][j+1] == '.' :
                    print('No')
                    #print(2)
                    ans = 1
                    break
            else :
                if mas[i][j - 1] == '.' and mas[i + 1][j] == '.' and mas[i][j + 1] == '.':
                    print('No')
                    #print(3)
                    ans = 1
                    break
        elif i == H - 1 : # bottom row
            if j == W - 1 : # right edge
                if mas[i-1][j] == '.' and mas[i][j-1] == '.' :
                    print('No')
                    #print(4)
                    ans = 1
                    break
            elif j == 0 : # left edge
                if mas[i+1][j] == '.' and mas[i][j-1] == '.' :
                    print('No')
                    #print(6)
                    ans = 1
                    break
            else :
                if mas[i-1][j] == '.' and mas[i][j + 1] == '.' and mas[i][j - 1] == '.':
                    print('No')
                    #print(5)
                    ans = 1
                    break
        else : # middle row
            if j == W - 1 : # right edge
                if mas[i-1][j] == '.' and mas[i][j-1] == '.' and mas[i+1][j] == '.' :
                    print('No')
                    #print(7)
                    ans = 1
                    break
            elif j == 0 : # left edge
                if mas[i+1][j] == '.' and mas[i][j-1] == '.' and mas[i][j+1] == '.' :
                    print('No')
                    #print(8)
                    ans = 1
                    break
            else :
                if mas[i-1][j] == '.' and mas[i + 1][j] == '.' and mas[i][j - 1] == '.' and mas[i][j + 1] == '.':
                    print('No')
                    #print(9)
                    ans = 1
                    break
if ans == 0 :
    print('Yes')

Submission status: Runtime Error

Solution code:
import itertools
H,W = map(int,input().split())
mas = [input() for _ in range(H)]
ans = 0
for i, j in itertools.product(range(H), range(W)):
    if mas[i][j] == '.':
        pass
    else :
        if i == 0 : # top row
            if j == W - 1 : # right edge
                if mas[i-1][j] == '.' and mas[i][j+1] == '.' :
                    print('No')
                    #print(1)
                    ans = 1
                    break
            elif j == 0 : # left edge
                if mas[i+1][j] == '.' and mas[i][j+1] == '.' :
                    print('No')
                    #print(2)
                    ans = 1
                    break
            else :
                if mas[i][j - 1] == '.' and mas[i + 1][j] == '.' and mas[i][j + 1] == '.':
                    print('No')
                    #print(3)
                    ans = 1
                    break
        elif i == H - 1 : # bottom row
            if j == W - 1 : # right edge
                if mas[i-1][j] == '.' and mas[i][j-1] == '.' :
                    print('No')
                    #print(4)
                    ans = 1
                    break
            elif j == 0 : # left edge
                if mas[i+1][j] == '.' and mas[i][j-1] == '.' :
                    print('No')
                    #print(6)
                    ans = 1
                    break
            else :
                if mas[i-1][j] == '.' and mas[i][j + 1] == '.' and mas[i][j - 1] == '.':
                    print('No')
                    #print(5)
                    ans = 1
                    break
        else : # middle row
            if j == W - 1 : # right edge
                if mas[i-1][j] == '.' and mas[i][j-1] == '.' and mas[i+1][j] == '.' :
                    print('No')
                    #print(7)
                    ans = 1
                    break
            elif j == 0 : # left edge
                if mas[i+1][j] == '.' and mas[i][j-1] == '.' and mas[i][j+1] == '.' :
                    print('No')
                    #print(8)
                    ans = 1
                    break
            else :
                if mas[i-1][j] == '.' and mas[i + 1][j] == '.' and mas[i][j - 1] == '.' and mas[i][j + 1] == '.':
                    print('No')
                    #print(9)
                    ans = 1
                    break
if ans == 0 :
    print('Yes')

Submission status: Runtime Error

Solution code:
import itertools
H,W = map(int,input().split())
mas = [input() for _ in range(H)]
ans = 0
for i, j in itertools.product(range(H), range(W)):
    if mas[i][j] == '.':
        pass
    else :
        if i == 0 : # top row
            if j == W - 1 : # right edge
                if mas[i-1][j] == '.' and mas[i][j+1] == '.' :
                    print('No')
                    ans = 1
                    break
            elif j == 0 : # left edge
                if mas[i+1][j] == '.' and mas[i][j+1] == '.' :
                    print('No')
                    ans = 1
                    break
            else :
                if mas[i-1][j] == '.' and mas[i + 1][j] == '.' and mas[i][j + 1] == '.':
                    print('No')
                    ans = 1
                    break
        elif i == H - 1 : # bottom row
            if j == W - 1 : # right edge
                if mas[i-1][j] == '.' and mas[i][j-1] == '.' :
                    print('No')
                    ans = 1
                    break
            elif j == 0 : # left edge
                if mas[i+1][j] == '.' and mas[i][j-1] == '.' :
                    print('No')
                    ans = 1
                    break
            else :
                if mas[i-1][j] == '.' and mas[i + 1][j] == '.' and mas[i][j - 1] == '.':
                    print('No')
                    ans = 1
                    break
        else : # middle row
            if j == W - 1 : # right edge
                if mas[i-1][j] == '.' and mas[i][j-1] == '.' and mas[i][j+1] == '.' :
                    print('No')
                    ans = 1
                    break
            elif j == 0 : # left edge
                if mas[i+1][j] == '.' and mas[i][j-1] == '.' and mas[i][j+1] == '.' :
                    print('No')
                    ans = 1
                    break
            else :
                if mas[i-1][j] == '.' and mas[i + 1][j] == '.' and mas[i][j - 1] == '.' and mas[i][j + 1] == '.':
                    print('No')
                    ans = 1
                    break
if ans == 0 :
    print('Yes')

Submission status: Runtime Error

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

f1 = True
for i in range(H):
  if not f1:
    break
  for j in range(W):
    if not f1:
      break
    if s[i][j] == '.':
      continue
    f = False
    if i >= 1 and s[i-1][j] == '#':
      f = True
    if j <= W-2 and s[i][j+1] == '#':
      f = True
    if i <= H-2 and s[i+1][j] == '#':
      f = True
    if j >= 1 and s[i][j-1] == '#':
      f = True
    if not f:
      f1 = False

#print(s)
if f:
  print('Yes')
else:
  print('No')

Submission status: Runtime Error

Solution code:
H,W=map(int,input().split())
S=[]
for i in range(H):
    s=input()
    S.append(s)
for i in range(H):
    for j in range(W):
        if S[j][i]==".":
            continue
        l=[(j-1,i),(j+1,i),(j,i+1),(j,i-1)]
        koritu=True
        for y,x in l:
            if 0<=y<=H-1 and  0<=x<=W-1:
                koritu=koritu and S[y][x]=="."
        if koritu:
            print("No")
            quit()
print("Yes")

Submission status: Runtime Error

Solution code:
H, W = map(int, input().split())
sw = [list(str(input())) for i in range(H)]
dx = [1,0,-1,0]
dy = [0,1,0,-1]

for i in range(H):
  for j in range(W):
    if sw[i][j] == "#":
      counter = 0
      for k in range(4):
        if i+dx[k] < 0 or i+dx[k] >= H or j+dy[k] < 0 or j+dy[k] >= H:
          counter += 1
        elif sw[i+dx[k]][j+dy[k]] == ".":
          counter += 1
      if counter == 4:
        print("No")
        exit()
print("Yes")

Submission status: Runtime Error

Solution code:
def calc(x, y):
    x2 = x
    y2 = y - 1
    x4 = x - 1
    y4 = y
    x5 = x + 1
    y5 = y
    x7 = x
    y7 = y + 1
    return x2, y2, x4, y4, x5, y5, x7, y7

h, w = map(int, input().split())
s = []
for _ in range(h):
    s.append(list(input()))
ans = "Yes"
for i in range(h * w):
    x = i // h
    y = i % h
    c = 0
    if s[y][x] == "#":
        x2, y2, x4, y4, x5, y5, x7, y7 = calc(x, y)
        aaa = [[x2, y2], [x4, y4], [x5, y5], [x7, y7]]
        for (xx, yy) in aaa:
            if ((xx >= 0) & (xx < h) & (yy >= 0) & (yy < w)):
                if s[yy][xx] == "#":
                    c += 1
        if c == 0:
            ans = "No"
            break
print(ans)

Submission status: Runtime Error

Solution code:
def calc(x, y):
    x2 = x
    y2 = y - 1
    x4 = x - 1
    y4 = y
    x5 = x + 1
    y5 = y
    x7 = x
    y7 = y + 1
    return x2, y2, x4, y4, x5, y5, x7, y7

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

for i in range(h * w):
    x = i // h
    y = i % h
    c = 0
    if s[y][x] == "#":
        x2, y2, x4, y4, x5, y5, x7, y7 = calc(x, y)
        aaa = [[x2, y2], [x4, y4], [x5, y5], [x7, y7]]
        for (xx, yy) in aaa:
            if ((xx >= 0) & (xx < h) & (yy >= 0) & (yy < w)):
                if s[yy][xx] == "#":
                    c += 1
        if c == 0:
            ans = "No"
            break
        else:
            ans = "Yes"
print(ans)

Submission status: Runtime Error

Solution code:
def calc(x, y):
    x2 = x
    y2 = y - 1
    x4 = x - 1
    y4 = y
    x5 = x + 1
    y5 = y
    x7 = x
    y7 = y + 1
    return x2, y2, x4, y4, x5, y5, x7, y7

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

for i in range(h * w):
    x = i // h
    y = i % h
    c = 0
    if s[x][y] == "#":
        x2, y2, x4, y4, x5, y5, x7, y7 = calc(x, y)
        aaa = [[x2, y2], [x4, y4], [x5, y5], [x7, y7]]
        for (xx, yy) in aaa:
            if ((xx >= 0) & (xx < h) & (yy >= 0) & (yy < w)):
                if s[xx][yy] == "#":
                    c += 1
        if c == 0:
            ans = "No"
            break
        else:
            ans = "Yes"
print(ans)

Submission status: Runtime Error

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

for i in range(h * w):
    x = i // h
    y = i % h
    c = 0
    if s[x][y] == "#":
        x2, y2, x4, y4, x5, y5, x7, y7 = calc(x, y)
        aaa = [[x2, y2], [x4, y4], [x5, y5], [x7, y7]]
        for (xx, yy) in aaa:
            if ((xx >= 0) & (xx < h) & (yy >= 0) & (yy < w)):
                if s[xx][yy] == "#":
                    c += 1
        if c == 0:
            ans = "No"
            break
        else:
            ans = "Yes"
print(ans)

Submission status: Runtime Error

Solution code:
H,W = [int(x) for x in input().split()]
S = [list('.'*(W+2))]+[list('.'+input()+'.') for _ in range(H)]+[list('.'*(W+2))]
lix = [-1,0,1,0]
liy = [0,-1,0,1]
flag = True
def dfs(x,y):
    cnt = 0
    if(S[x][y]=='.'):
        return 0
    else:
        cnt += 1
        S[x][y]='.'
        for i in range(4):
            if(S[x+lix[i]][y+liy[i]]!='.'):
                cnt += dfs(x+lix[i],y+liy[i])
        return cnt

for i in range(1,H+1):
    for j in range(1,W+1):
          if(dfs(i,j)==1):
              flag = False
if(flag):
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

Solution code:
a,b=map(int,input().split())
grid=[["."]*(a+2)]+[list("."+input()+".")for i in range(b)]+[["."]*(a+2)]
for s in range(1,1+b):
    for t in range(1,1+a):
        if grid[s][t]=="#" and all([grid[s+x][t+y]=="."for x,y in ([0,-1],[0,1],[1,0],[-1,0])]):
            print("No")
            exit()
print("Yes")

Submission status: Runtime Error

Solution code:
a,b=map(int,input().split())
grid=[["."]*(a+2)]+[list("."+input()+".")for i in range(b)]+[["."]*(a+2)]
for s in range(1,1+a):
    for t in range(1,1+b):
        if grid[s][t]=="#" and all([grid[s+x][t+y]=="."for x,y in ([0,-1],[0,1],[1,0],[-1,0])]):
            print("No")
            exit()
print("Yes")

Submission status: Runtime Error

Solution code:
a,b=map(int,input().split())
grid=[["."]*(a+2)]+[list("."+input()+".")for i in range(b)]+[["."]*(a+2)]
for s in range(1,1+a):
    for t in range(1,1+a):
        if grid[s][t]=="#" and all([grid[s+x][t+y]=="."for x,y in ([0,-1],[0,1],[1,0],[-1,0])]):
            print("No")
            #exit()
print("Yes")

Submission status: Runtime Error

Solution code:
a,b=map(int,input().split())
grid=[["."]*(a+2)]+[list("."+input()+".")for i in range(b)]+[["."]*(a+2)]
for i in grid:
    print(*i)
for s in range(1,1+a):
    for t in range(1,1+a):
        if grid[s][t]=="#" and all([grid[s+x][t+y]=="."for x,y in ([0,-1],[0,1],[1,0],[-1,0])]):
            print("No")
            #exit()
print("Yes")

Submission status: Runtime Error

Solution code:
a,b=map(int,input().split())
grid=[["."]*(a+2)]+[list("."+input()+".")for i in range(b)]+[["."]*(a+2)]
for s in range(1,1+a):
    for t in range(1,1+a):
        if grid[s][t]=="#" and all([grid[s+x][t+y]=="."for x,y in ([0,-1],[0,1],[1,0],[-1,0])]):
            print("No")
            exit()
print("Yes")

Submission status: Runtime Error

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

for i in range(h):
  for j in range(w):
    if j > 0 and a[i][j-1] != "." and a[i][j] = "#":
      a[i][j] = "*"
    elif j < w - 1 and a[i][j+1] != "." and a[i][j] = "#":
      a[i][j] = "*"
    elif i > 0 and a[i-1][j] != "." and a[i][j] = "#":
      a[i][j] = "*"
    elif i < h - 1 and a[i+1][j] != "." and a[i][j] = "#":
      a[i][j] = "*"

print("No" if sum([row.count("#") for row in a]) else "Yes")

Submission status: Runtime Error

Solution code:
h,w=map(int,input().split())
l=[["."for i in range(w+2)],[".",input().split(),"."]for i in range(h),["."for i in range(w+2)]]
ans=0
for i in range(1,h+1):
  for j in range(1,w+1):
    if l[i][j]==".":
      continue
    if l[i+1][j]=="#" and l[i-1][j]=="#" and l[i][j+1]=="#" and l[i][j-1]=="#":
      continue
    ans=1
print("YNeos"[ans::2])

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
import sys
INF = float("inf")


def yes():
    print("Yes")  # type: str


def no():
    print("No")  # type: str


def solve(H: int, W: int, s: "List[str]"):
    n = [[0]*(W+2) for _ in range(H+2)]
    for i in range(H):
        for j in range(W):
            if s[i][j] == "#":
                n[i+1][j+1] = 1  # 外枠を作りつつ

    flag = True
    for i in range(1, H+1):
        for i in range(1, W+1):
            if n[i][j] == 1 and n[i-1][j]+n[i+1][j]+n[i][j-1]+n[i][j+1] == 0:
                flag = False
                break
        if flag == False:
            break
    if flag == False:
        no()
    else:
        yes()

    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    s = [next(tokens) for _ in range(H)]  # type: "List[str]"
    solve(H, W, s)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
import sys
INF = float("inf")


def yes():
    print("Yes")  # type: str


def no():
    print("No")  # type: str


def solve(H: int, W: int, s: "List[str]"):
    n = [[0]*(W+2) for _ in range(H+2)]
    for i in range(H):
        for j in range(W):
            if s[i][j] == "#":
                n[i+1][j+1] = 1  # 外枠を作りつつ

    flag = True
    for i in range(1, H+1):
        for i in range(1, W+1):
            if n[i][j] == 1 and n[i-1][j]+n[i+1][j]+n[i][j-1]+n[i][j+1] == 0:
                flag = False
                break
        if flag == False:
            break
    if flag == False:
        no()
    else:
        yes()

    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    s = [next(tokens) for _ in range(W)]  # type: "List[str]"
    solve(H, W, s)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

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


picture = []
diff = [-1, 1]

for i_h in range(h):
    row = '...'
    for i_w in range(w):
        if S[i_h][i_w] == '.':continue
        else:
            for dh in diff:
                if (i_h+dh<0) or (i_h+dh>h-1):continue
                if S[i_h+dh][i_w] == '#':
                    row[i_w] = '#'
            for dw in diff:
                if (i_w+dw<0) or (i_w+dw<w-1):continue
                if S[i_h][i_w+dw] == '#':
                    row[i_w] = '#'
    picture.append(row)
    
if picture == S:
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

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

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

print("Yes")

Submission status: Runtime Error

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

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

print("Yes")

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str


def inRange(h: int, w: int, H: int, W: int):
    return h >= 0 and w >= 0 and h < H and w < W


def solve(H: int, W: int, s: "List[str]"):
    failed = False
    for h in range(H):
        for w in range(W):
            cur = s[h][w]
            if cur == "#":
                if inRange(h-1, w, H, W) and s[h-1][w] == "#":
                    continue
                if inRange(h+1, w, H, W) and s[h+1][w] == "#":
                    continue
                if inRange(h, w-1, H, W) and s[h][w-1] == "#":
                    continue
                if inRange(h, w+1, H, W) and s[h][w+1] == "#":
                    continue
                failed = True
                break
        if failed:
            break
    print("No") if failed else print("Yes")
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    s = [next(tokens) for _ in range(W)]  # type: "List[str]"
    solve(H, W, s)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str


def inRange(h: int, w: int, H: int, W: int):
    return h >= 0 and w >= 0 and h < H and w < W


def solve(H: int, W: int, s: "List[str]"):
    for h in range(H):
        for w in range(W):
            cur = s[h][w]
            if cur == "#":
                if inRange(h-1, w, H, W) and s[h-1][w] == "#":
                    continue
                if inRange(h+1, w, H, W) and s[h+1][w] == "#":
                    continue
                if inRange(h, w-1, H, W) and s[h][w-1] == "#":
                    continue
                if inRange(h, w+1, H, W) and s[h][w+1] == "#":
                    continue
                print("No")
                sys.exit(0)
    print("Yes")
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    s = [next(tokens) for _ in range(W)]  # type: "List[str]"
    solve(H, W, s)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import sys
import queue

def search(h,w):
  global arr

  c_max=1
  q=queue.Queue()
  q.put((h,w,1))
  while not q.empty():
    h,w,c=q.get()
    if c_max<c:
      c_max=c

    arr[h][w]="."

    if h>=1 and arr[h-1][w]=="#":
      q.put((h-1,w,c+1))
    if h<=len(arr)-2 and arr[h+1][w]=="#":
      q.put((h+1,w,c+1))
    if w>=1 and arr[h][w-1]=="#":
      q.put((h,w-1,c+1))
    if w>=len(arr[h])-2 and arr[h][w+1]=="#":
      q.put((h,w+1,c+1))

  return c_max

H,W=list(map(int,input().split(" ")))
arr=[]
for z in range(H):
  arr.append(list(input()))

h,w=0,0

while True:

  if arr[h][w]=="#":
    if search(h,w)==1:
      print("No")
      sys.exit()

  w+=1
  if w>=W:
    w=0
    h+=1
  if h>=H:
    break

print("Yes")

Submission status: Runtime Error

Solution code:
        H,W = map(int,input().split())
        s = [list(input()) for _ in range(H)]
        dir4 = ((0, 1), (0, -1), (1, 0), (-1, 0))
        for i in range(H):
            for j in range(W):
                if s[i][j] == ".": continue
                cnt = 0
                for d in dir4:
                    nx = i + d[0]
                    ny = j + d[1]
                    if not (0 <= nx < H): continue
                    if not (0 <= ny < W): continue
                    if s[nx][ny] == "#": cnt += 1
                if cnt == 0:
                    print("No")
                    exit()
        print("Yes")

Submission status: Runtime Error

Solution code:
h,w = map(int, input().split())
#get hight and weidth 
glid = [0] * ( h+ 2)

h_index = [-1, 0, 0,  1]
w_index = [ 0, -1, 1, 0]



glid[0]=["."] * ( w + 2 )
glid[h + 1 ] = ["."] * ( w + 2 )

for i in range(h):
	temp1 = ["."]
	temp2 = list(input())
	temp1.extend(temp2)
	temp1.append(".")
	glid[ i + 1 ] = temp1

# get glids 

cnt = 0

for j in range(h):
	for k in range(w):
		if glid[ j + 1 ][ k + 1 ] == ".":
			continue
		else:
			flg = False
			for n in range(4):
				if glid[ j  + 1 + h_index[ n ] ][ k + 1 + w_index[ n ]] == "#" :
					flg = True
					break
				cnt += 1
			if flg == False :
				break
	if flg == False :
		break

if cnt<0:
	print("Yes")
else:
	print("No")

Submission status: Runtime Error

Solution code:
h,w = map(int, input().split())
#get hight and weidth 
glid = [0] * ( h+ 2)

h_index = [-1, 0, 0,  1]
w_index = [ 0, -1, 1, 0]



glid[0]=["."] * ( w + 2 )
glid[h + 1 ] = ["."] * ( w + 2 )

for i in range(h):
	temp1 = ["."]
	temp2 = list(input())
	temp1.extend(temp2)
	temp1.append(".")
	glid[ i + 1 ] = temp1

# get glids 

cnt = 0

for j in range(h):
	for k in range(w):
		if glid[ j + 1 ][ k + 1 ] == ".":
			continue
		else:
			flg = False
			for n in range(4):
				if glid[ j  + 1 + h_index[ n ] ][ k + 1 + w_index[ n ]] == "#" :
					flg = True
					break
				cnt += 0
			if flg == False :
				break
	if flg == False :
		break

if cnt < 1:
	print("Yes")
else:
	print("No")

Submission status: Runtime Error

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

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

ans = True
for i in range(H):
    for j in range(W):
        if s[i][j] == '.':
            continue
        else:
            check = True
            for k in range(len(dx)):
                x = i+dx[k]
                y = j+dy[k]
                if x<0 or x>(W-1) or y<0 or y>(H-1):
                    continue
                else:
                    if s[x][y]=='#':
                        check = False
            if check:
                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())
s = [input() for i in range(H)]

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

ans = True
for i in range(H):
    for j in range(W):
        if s[i][j]==".":
            continue
        else:
            check = True
            for k in range(len(dx)):
                x = i+dx[k]
                y = j+dy[k]
                if x<0 or x>(W-1) or y<0 or y>(H-1):
                    continue
                else:
                    if s[x][y]=='#':
                        check = False
            if check:
                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())
s = [input() for i in range(H)]

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

ans = True
for i in range(W):
    for j in range(H):
        if s[i][j] == '.':
            continue
        else:
            check = True
            for k in range(len(dx)):
                x = i+dx[k]
                y = j+dy[k]
                if x<0 or x>(W-1) or y<0 or y>(H-1):
                    continue
                else:
                    if s[x][y]=='#':
                        check = False
            if check:
                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())

l = [['P' for _ in range(H + 2)] for _ in range(W + 2)]

for i in range(H) :
    s = list(input())
    for j in range(W) :
        l[i+1][j+1] = s[j]

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

ans = True

for i in range(1, H + 1) :
    for j in range(1, W + 1) :
        if l[i][j] != "#" :
            continue
        flag = False
        for k in range(len(dx)) :
            if l[i + dx[k]][j + dy[k]] == "#" :
                flag = True
                break
        if flag == False :
            ans = False

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

Submission status: Runtime Error

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

dx = [0, 1, 0, -1]
dy = [1, 0, -1, 0]
for h in range(H):
    for w in range(W):
        if S[h][w] == '#' or 'b':
            for i in range(4):
                nh, nw = h+dx[i], w+dy[i]
                if 0 <= nh < H and 0 <= nw < W:
                    if S[nh][nw] == '#' or S[nh][nw] == 'b':
                        S[nh][nw] = 'b'
                        S[h][w] = 'b'

counter = 0
for i in range(H):
    for l in range(W):
        if S[i][l] == "#":
            counter += 1


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

Submission status: Runtime Error

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

for y in range(1, h+1):
    pict[y][1:w+1] = list(input())
ans = "Yes"
for y in range(h):
    for x in range(w):
        if pict[x][y] == "#":
            if pict[x-1][y] == "." and pict[x+1][y] == "." and pict[x][y-1] == "." and pict[x][y+1] == ".":
                ans = "No"
print(ans)

Submission status: Runtime Error

Solution code:
H, W = map(int, input().split())
s = ["".join(["0"]*(H+2))] + ["0"+input()+"0" for _ in range(H)] + ["".join(["0"]*(H+2))]
failed = False
for i in range(1, W+1):
    for j in range(1, H+1):
        if '#' != s[i][j]:
            continue
        if '#' in [s[i+x][j+y] for x, y in [(0, -1), (-1, 0), (1, 0), (0, 1)]]:
            continue
        else:
            failed = True
            break
    if failed:
        print("No")
        break
else:
    print("Yes")

Submission status: Runtime Error

Solution code:
H, W = list(map(int, input().split()))
s = ['.'*(W+2)] + ['.' + input() + '.' for i in range(H)] + ['.'*(W+2)]
ans = 'Yes'

for w in range(1, W+1):
    for h in range(1, H+1):
        if s[w][h] == '#':
            if '#' not in [s[w-1][h], s[w+1][h], s[w][h-1], s[w][h+1]]:
                ans = 'No'
                break
    if ans == 'No':
        break
print(ans)

Submission status: Runtime Error

Solution code:
H, W = list(map(int, input().split()))
s = ['.'*(W+2)] + ['.' + input() + '.' for i in range(H)] + ['.'*(W+2)]
ans = 'Yes'

for w in range(1, W+1):
    for h in range(1, H+1):
        if s[w][h] == '#':
            if '#' not in [s[w-1][h], s[w+1][h], s[w][h-1], s[w][h+1]]:
                ans = 'No'
print(ans)