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())
S = [[sign for sign in input()] for i in range(H)]

suspect = []
suspect2 = []
flag = True

if H > 1 and W > 1:
    for i, row in enumerate(S):
        for j, sign in enumerate(row):
            if j == 0:
                if row[j] == "#" and row[j + 1] == ".":
                    suspect.append([i, j])
            elif j == W - 1:
                if row[j] == "#" and row[j - 1] == ".":
                    suspect.append([i, j])
            else:
                if row[j] == "#" and row[j - 1] == "." and row[j + 1] == ".":
                    suspect.append([i, j])

    T = zip(*S)
    for i, row in enumerate(T):
        for j, sign in enumerate(row):
            if j == 0:
                if row[j] == "#" and row[j + 1] == ".":
                    suspect2.append([j, i])
            elif j == W - 1:
                if row[j] == "#" and row[j - 1] == ".":
                    suspect2.append([j, i])
            else:
                if row[j] == "#" and row[j - 1] == "." and row[j + 1] == ".":
                    suspect2.append([j, i])
elif H == 1 and W == 2:
    if S[0][0] != S[0][1]:
        flag = False
elif H == 2 and W == 1:
    if S[0][0] != S[1][0]:
        flag = False
else:
    if S[0][0] == "#":
        flag = False
        

for xy in suspect:
    if xy in suspect2:
        flag = False
if flag:
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

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

suspect = []
suspect2 = []

if H > 1 and W > 1:
    for i, row in enumerate(S):
        for j, sign in enumerate(row):
            if j == 0:
                if row[j] == "#" and row[j + 1] == ".":
                    suspect.append([i, j])
            elif j == W - 1:
                if row[j] == "#" and row[j - 1] == ".":
                    suspect.append([i, j])
            else:
                if row[j] == "#" and row[j - 1] == "." and row[j + 1] == ".":
                    suspect.append([i, j])

    T = zip(*S)
    for i, row in enumerate(T):
        for j, sign in enumerate(row):
            if j == 0:
                if row[j] == "#" and row[j + 1] == ".":
                    suspect2.append([j, i])
            elif j == W - 1:
                if row[j] == "#" and row[j - 1] == ".":
                    suspect2.append([j, i])
            else:
                if row[j] == "#" and row[j - 1] == "." and row[j + 1] == ".":
                    suspect2.append([j, i])

flag = True
for xy in suspect:
    if xy in suspect2:
        flag = False
if flag:
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

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

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

ans = 'Yes'

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

print(ans)

Submission status: Runtime Error

Solution code:
H, W = map(int, input().split())
lists = []
s_list = []
for i in range(H):
    s = str(input())
    s_list.append(s)
    lists.append(s)
cnt = 0
for i in range(H):
    for j in range(W):
        if i == 0 and j == 0:  # 左端上の処理
            cnt = 0
            if lists[i][j] == "#":
                if lists[i][1] == ".":
                    cnt += 1
                if lists[1][0] == ".":
                    cnt += 1
                if cnt == 2:
                    print("No")
                    exit()
                else:
                    pass
        if i == H-1 and j == 0:  # 左端下の処理
            cnt = 0
            if lists[i][j] == "#":
                if lists[i][1] == ".":
                    cnt += 1
                if lists[i-1][j+1] == ".":
                    cnt += 1
                if cnt == 2:
                    print("No")
                    exit()
                else:
                    pass
        if i == 0 and j == W - 1:  # 右端上の処理
            cnt = 0
            if lists[i][j] == "#":
                if lists[i][j - 1] == ".":
                    cnt += 1
                if lists[i + 1][j] == ".":
                    cnt += 1
                if cnt == 2:
                    print("No")
                    exit()
                else:
                    pass
        if i == H and j == W - 1:
            cnt = 0
            if lists[i][j] == "#":
                if lists[i][j - 1] == ".":
                    cnt += 1
                if lists[i - 1][j - 1] == ".":
                    cnt += 1
                if cnt == 2:
                    print("No")
                    exit()
                else:
                    pass
        if i == 0:
            if j == 0 or j == W - 1:
                pass
            cnt = 0
            if lists[i][j] == "#":
                if lists[i][j + 1] == ".":
                    cnt += 1
                if lists[i][j - 1] == ".":
                    cnt += 1
                if lists[i + 1][j] == ".":
                    cnt += 1
                if cnt == 3:
                    print("No")
                    exit()
            else:
                pass
        if i == H - 1 and (j != 0 or j != W - 1):
            if j == 0 or j == W - 1:
                pass
            cnt = 0
            if lists[i][j] == "#":
                if lists[i][j + 1] == ".":
                    cnt += 1
                if lists[i][j - 1] == ".":
                    cnt += 1
                if lists[i - 1][j] == ".":
                    cnt += 1
                if cnt == 3:
                    print(i, j)
                    print("No")
                    exit()
                else:
                    pass
        if (i != 0 or i != W - 1) and j == 0:
            cnt = 0
            if lists[i][j] == "#":
                if lists[i + 1][j] == ".":
                    cnt += 1
                if lists[i - 1][j] == ".":
                    cnt += 1
                if lists[i][j + 1] == ".":
                    cnt += 1
                if cnt == 3:
                    print("No")
                    exit()
                else:
                    pass
        if (i != 0 or i != W - 1) and j == W - 1:
            cnt = 0
            if lists[i][j] == "#":
                if lists[i + 1][j] == ".":
                    cnt += 1
                if lists[i - 1][j] == ".":
                    cnt += 1
                if lists[i][j - 1] == ".":
                    cnt += 1
                if cnt == 3:
                    print("No")
                    exit()
                else:
                    pass

print("Yes")

Submission status: Runtime Error

Solution code:
n,m=map(int,input().split())
mat=[]
dx=[0,0,-1,1]
dy=[1,-1,0,0]
for i in range(n):
    mat.append(list(input().strip()))
f=0 
for i in range(n):
    if f:
        break 
    for j in range(m):
        if mat[i][j]=='#':
            q=[[i,j]]
            f=1 
            vis=[[0 for x1 in range(m)]for y1 in range(n)]
            vis[i][j]=1 
            while q:
                t=q.pop(0)
                #print(t)
                x,y=t[0],t[1] 
                for k in range(4): 
                    if 0<=x+dx[k]<n and 0<=y+dy[k]<m and vis[x+dx[k]][y+dy[k]]==0 and mat[x+dx[k]][y+dy[k]]=='#': 
                        vis[x+dx[k]][y+dy[k]]=1 
                        q.append([x+dx[k],y+dy[k]])
            break 
for i in range(n):
    for j in range(m): 
        if vis[i][j]==0 and mat[i][j]=='#':
           # print(i,j)
            print('No')
            exit()
print('Yes')

Submission status: Runtime Error

Solution code:
n,m=map(int,input().split())
mat=[]
dx=[0,0,-1,1]
dy=[1,-1,0,0]
for i in range(n):
    mat.append(list(input().strip()))
f=0 
for i in range(n):
    if f:
        break 
    for j in range(m):
        if mat[i][j]=='#':
            q=[[i,j]]
            f=1 
            vis=[[0 for j in range(m)]for i in range(n)]
            vis[i][j]=1 
            while q:
                t=q.pop(0)
                #print(t)
                x,y=t[0],t[1] 
                for k in range(4): 
                    if 0<=x+dx[k]<n and 0<=y+dy[k]<m and vis[x+dx[k]][y+dy[k]]==0 and mat[x+dx[k]][y+dy[k]]=='#': 
                        vis[x+dx[k]][y+dy[k]]=1 
                        q.append([x+dx[k],y+dy[k]])
            break 
for i in range(n):
    for j in range(m): 
        if vis[i][j]==0 and mat[i][j]=='#':
           # print(i,j)
            print('No')
            exit()
print('Yes')

Submission status: Runtime Error

Solution code:
n,m=map(int,input().split())
mat=[]
dx=[0,0,-1,1]
dy=[1,-1,0,0]
for i in range(n):
    mat.append(list(input()))
f=0 
for i in range(n):
    if f:
        break 
    for j in range(m):
        if mat[i][j]=='#':
            q=[[i,j]]
            f=1 
            vis=[[0 for j in range(m)]for i in range(n)]
            vis[i][j]=1 
            while q:
                t=q.pop(0)
                #print(t)
                x,y=t[0],t[1] 
                for k in range(4): 
                    if 0<=x+dx[k]<n and 0<=y+dy[k]<m and vis[x+dx[k]][y+dy[k]]==0 and mat[x+dx[k]][y+dy[k]]=='#': 
                        vis[x+dx[k]][y+dy[k]]=1 
                        q.append([x+dx[k],y+dy[k]])
            break 
for i in range(n):
    for j in range(m): 
        if vis[i][j]==0 and mat[i][j]=='#':
           # print(i,j)
            print('No')
            exit()
print('Yes')

Submission status: Runtime Error

Solution code:
n,m=map(int,input().split())
mat=[]
dx=[0,0,-1,1]
dy=[1,-1,0,0]
for i in range(n):
    mat.append(list(input()))
f=0 
for i in range(n):
    if f:
        break 
    for j in range(n):
        if mat[i][j]=='#':
            q=[[i,j]]
            f=1 
            vis=[[0 for j in range(m)]for i in range(n)]
            vis[i][j]=1 
            while q:
                t=q.pop(0)
                x,y=t[0],t[1] 
                for k in range(4): 
                    if 0<=x+dx[k]<n and 0<=y+dy[k]<m and vis[x+dx[k]][y+dy[k]]==0: 
                        vis[x+dx[k]][y+dy[k]]=1 
                        q.append([x+dx[k],y+dy[k]])
            break 
for i in range(n):
    for j in range(m): 
        if vis[i][j]==0 and mat[i][j]=='#':
           # print(i,j)
            print('No')
            exit()
print('Yes')

Submission status: Runtime Error

Solution code:
def input():
    import sys
    return sys.stdin.readline().rstrip()


def main():
    import math
    import collections
    import itertools

    h, w = map(int, input().split())
    
    ss = ['.' * w] + ['.' + input() + '.' for _ in range(h)] + ['.' * w]

    for i in range(1, h + 1):
        for j in range(1, w + 1):
            if ss[i][j] == '#':
                if ss[i + 1][j] == '.' and ss[i - 1][j] == '.' and ss[i][j + 1] == '.' and ss[i][j - 1] == '.':
                    print("No")
                    break
        else:
            continue
        break
    else:
        print("Yes")



if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
def input():
    import sys
    return sys.stdin.readline().rstrip()


def main():
    import math
    import collections
    import itertools

    h, w = map(int, input().split())
    
    ss = [['.'] * w] + ['.' + input() + '.' for _ in range(h)] + [['.'] * w]

    for i in range(1, h + 1):
        for j in range(1, w + 1):
            if ss[i][j] == '#':
                if ss[i + 1][j] == '.' and ss[i - 1][j] == '.' and ss[i][j + 1] == '.' and ss[i][j - 1] == '.':
                    print("No")
                    break
        else:
            continue
        break
    else:
        print("Yes")



if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

for i in range(h):
    sq.append(input())

print(sq)

def is_valid(i, j):
    valid = False
    if i > 0 and sp[i-1][j] == '#':
        valid = True
    elif i < h-1 and sp[i+1][j] == '#':
        valid = True
    elif j > 0 and sp[i][j-1] == '#':
        valid = True
    elif j < w-1 and sp[i][j+1] == '#':
        valid = True
    return valid

for i in range(h):
    for j in range(w):
        #print(sq[i][j])
        c = sq[i][j]
        if c == '#':
            if not is_valid(i, j):
                print('No')
                sys.exit()

print('Yes')

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] == '#':
            if j + 1 < w and s[i][j+1] == '#':
                continue
            if j - 1 >= 0 and s[i][j-1] == '#':
                continue
            if i + 1 < h and s[i+1][j] == '#':
                continue
            if i - 1 >= 0 and s[i-1][j] == '#':
                continue
            print('No')
            exit()

print('Yes')

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(w):
    for j in range(h):
        if s[j][i] == '#':
            if j + 1 < w and s[j+1][i] == '#':
                continue
            if j - 1 >= 0 and s[j-1][i] == '#':
                continue
            if i + 1 < h and s[j][i+1] == '#':
                continue
            if i - 1 >= 0 and s[j][i-1] == '#':
                continue
            print('No')
            exit()

print('Yes')

Submission status: Runtime Error

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

b = [[False]*w]*h

for i in range(h):
    for j in range(w):
        if s[j][i] == '#':
            if j + 1 < w and s[j+1][i] == '#':
                continue
            if j - 1 >= 0 and s[j-1][i] == '#':
                continue
            if i + 1 < h and s[j][i+1] == '#':
                continue
            if i - 1 >= 0 and s[j][i-1] == '#':
                continue
            print('No')
            exit()

print('Yes')

Submission status: Runtime Error

Solution code:
n,m=map(int,input().split())
hoge=[[0 for i in range(n+2)] for j in range(m+2)]
for i in range(m):
  sss=input()
  for j in range(n):
    if(sss[j]=="#"):
      hoge[1+i][1+j]=1
    
flag=True
for i in range(m):
  for j in range(n):
    if(hoge[1+i][1+j]==1):
      ans=0
      ans+=hoge[i][1+j]+hoge[1+i][j]+hoge[2+i][1+j]+hoge[1+i][2+j]
      if(ans==0):
        flag=False
        
if(flag):
  print("Yes")
else:
  print("No")

Submission status: Runtime Error

Solution code:
n,m=map(int,input().split())
hoge=[[0 for i in range(n+2)] for j in range(m+2)]
for i in range(n):
  sss=input()
  for j in range(m):
    if(sss[j]=="#"):
      hoge[1+i][1+j]=1
    
flag=True
for i in range(m):
  for j in range(n):
    if(hoge[1+i][1+j]==1):
      ans=0
      ans+=hoge[i][1+j]+hoge[1+i][j]+hoge[2+i][1+j]+hoge[1+i][2+j]
      if(ans==0):
        flag=False
        
if(flag):
  print("Yes")
else:
  print("No")

Submission status: Runtime Error

Solution code:
h, w = map(int, input().split())
ans = "Yes"
c = [0]*(w+2)
s = c
for i in range(h):
    S = ["0"]
    S1 = list(input())
    S.append(S1)
    S.append("0")
    s.append(S)
s.append(c)

for i in range(1,h+1):
    for j in range(1, w+1):
        if s[i][j]=="#":
            if s[i-1][j]!="#" and s[i+1][j]!="#" and s[i][j-1]!="#" and s[i][j+1]!="#":
                ans ="No"
            else:
                continue
print(ans)

Submission status: Runtime Error

Solution code:
h, w = map(int, input().split())
ans = "Yes"
s = []
for i in range(h):
    S = list(input())
    s.append(S)

for i in range(h):
    for j in range(w):
        if s[i][j]=="#":
            if s[i-1][j]!="#" and s[i+1][j]!="#" and s[i][j-1]!="#" and s[i][j+1]!="#":
                ans ="No"
            else:
                continue
print(ans)

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Your code here!
H,W=map(int,input().split())
l=[]

def dfs(h,w):
    judge=True
    if l[h][w]!="#":
        return
    l[h][w]="@"
    if h!=H-1:
        if l[h+1][w]!=".":
            dfs(h+1,w)
            judge=False
    if w!=W-1: 
        if l[h][w+1]!=".":
            dfs(h,w+1)
            judge=False
    if h!=0:
        if l[h-1][w]!=".":
            dfs(h-1,w)
            judge=False
    if w!=0:
        if l[h][w-1]!=".":
            dfs(h,w-1)
            judge=False
    if judge:
        print("No")
        exit()
    else:
        l[h][w]="."
        return

for _ in range(H):
    l.append(list(input()))
print("blue")
for i in range(H):
    for j in range(W):
        dfs(i,j)

print("Yes")

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Your code here!
H,W=map(int,input().split())
l=[]

def dfs(h,w):
    judge=True
    if l[h][w]!="#":
        return
    l[h][w]="@"
    if h!=H-1:
        if l[h+1][w]!=".":
            dfs(h+1,w)
            judge=False
    if w!=W-1: 
        if l[h][w+1]!=".":
            dfs(h,w+1)
            judge=False
    if h!=0:
        if l[h-1][w]!=".":
            dfs(h-1,w)
            judge=False
    if w!=0:
        if l[h][w-1]!=".":
            dfs(h,w-1)
            judge=False
    if judge:
        print("No")
        exit()
    else:
        l[h][w]="."
        return

for _ in range(H):
    l.append(list(input()))

for i in range(H):
    for j in range(W):
        dfs(i,j)

print("Yes")

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Your code here!
H,W=map(int,input().split())
l=[]

def dfs(h,w):
    judge=True
    if h!=H:
        dfs(h+1,w)
        judge=False
    if w!=W:
        dfs(h,w+1)
        judge=False
    if h!=0:
        dfs(h-1,w)
        judge=False
    if w!=0:
        dfs(h,w-1)
        judge=False
    if judge:
        print("No")
        exit()

for _ in range(H):
    l.append(list(input()))

for h in H:
    for w in W:
        if w="#"
            dfs(h,w)

print("Yes")
#ほぞん

Submission status: Runtime Error

Solution code:
H, W = map(int, input().split())
S = ["."+input()+"." for i in range(H)]
#print(S)
S = ["."*(H+2)]+S+["."*(W+2)]
#print(S)
flag = 0
for i in range(H):
  for j in range(W):
    if S[i][j] == "#":
      #print(i, j)
      if S[i-1][j] == "." and S[i+1][j] == "." and S[i][j-1] == "." and S[i][j+1] == ".":
        flag = 1
print("Yes" if flag==0 else "No")

Submission status: Runtime Error

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

for i in range(1, w - 1):
    for k in range(1, h - 1):
        if s[i - 1][k] == "." and s[i + 1][k] == "." and s[i][k - 1] == "." and s[i][k + 1] == ".":
            output = "No"

print(output)

Submission status: Runtime Error

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

for i in range(1, w - 1):
    for k in range(1, h - 1):
        if s[i - 1][k] == "." and s[i + 1][k] == "." and s[i][k - 1] == "." and s[i][k + 1] == ".":
            output = "No"
            break

    else:
        break
    continue

print(output)

Submission status: Runtime Error

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

for i in range(h):
    for j in range(w):
        if m[i][j] == '#':
            cnt = 0
            # left
            if 0 <= i-1:
                if m[i-1][j] != '#':
                    cnt += 1
            # right
            if i+1 < w:
                if m[i+1][j] != '#':
                    cnt += 1
            # up
            if 0 >= j-1:
                if m[i][j-1] != '#':
                    cnt += 1
            # down
            if j+1 < h:
                if m[i][j+1] != '#':
                    cnt += 1
            if cnt == 4:
                print('No')
                exit(0)
            cnt = 0
else:
    print('Yes')

Submission status: Runtime Error

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

for i in range(H):
	for j in range(W):
		if A[i][j]=='#':
			f=False
			for a,b in [(-1,0),(1,0),(0,1),(0,-1)]:
				if 0<=i+a<H and 0<=j+b<W:
					if A[i+a][j+b]=='#':f=True
			if not(f):break

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

Submission status: Runtime Error

Solution code:
raw_input = input().split()[2:]
W = len(raw_input[0])
H = len(raw_input)
added_input = [row + '.' for row in raw_input] + ['.' * len(raw_input[0])]
for y in range(H):
    for x in range(W):
        if added_input[y][x] == '#' and added_input[y+1][x] \
        == added_input[y-1][x] == added_input[y][x+1] == added_input[y][x-1] == '.':
            print('NO')
            break
else:
    print('YES')

Submission status: Runtime Error

Solution code:
H,W=[int(s) for s in input().split()]
cam_ls=[ "." for _ in range(H+2)]
for j in range(H+1):
  cam_ls[0]=cam_ls[0]+"."
  cam_ls[H+1]=cam_ls[H+1]+"."
for i in range(1,H+1):
  cam_ls[i]=cam_ls[i]+input()+"."
  
def pos(h,w):
  if cam_ls[h][w]==".":
    return 1
  elif (cam_ls[h+1][w]=="." and
        cam_ls[h-1][w]=="." and
        cam_ls[h][w+1]=="." and
        cam_ls[h][w-1]=="."):
    return 0
  else:
    return 1

ans=1
for i in range(1,H+1):
  for j in range(1,W+1):
    ans*=pos(i,j)
if ans==1:
  print("Yes")
else:
  print("No")

Submission status: Runtime Error

Solution code:
# -*- coding:utf-8 -*-
H,W=map(int,input().split())
nx=[1,0,-1,0]
ny=[0,1,0,-1]

field=[]
for i in range(H):
  field.append(list(input()))

for n in range(W):
  for m in range(H):
    if field[n][m]=='.':
      continue
    
    hope=0
    for j in range(4):
      x=n+nx[j]
      y=m+ny[j]
      
      if x<0 or W<=x or y<0 or H<=y:
        continue

      if field[x][y]=='#':
        hope=1
      
    if hope==0:
      print('No')
      exit()

print('Yes')

Submission status: Runtime Error

Solution code:
# -*- coding:utf-8 -*-
H,W=map(int,input().split())
nx=[1,0,-1,0,1,1,-1,-1]
ny=[0,1,0,-1,1,-1,1,-1]

field=[]
for i in range(H):
  field.append(list(input()))

for n in range(W):
  for m in range(H):
    if field[n][m]=='.':
      continue
    
    hope=0
    for j in range(8):
      x=n+nx[j]
      y=m+ny[j]
      
      if x<0 or W<=x or y<0 or H<=y:
        continue

      if field[x][y]=='#':
        hope=1
      
    if hope==0:
      print('No')
      exit()

print('Yes')

Submission status: Runtime Error

Solution code:
# -*- coding:utf-8 -*-
H,W=map(int,input().split())
nx=[1,0,-1,0,1,1,-1,-1]
ny=[0,1,0,-1,1,-1,1,-1]

field=[]
for i in range(H):
  field.append(list(split()))

for n in range(W):
  for m in range(H):
    if field[n][m]=='.':
      continue
      
    for j in range(8):
      x=n+nx[j]
      y=m+ny[j]

      if field[x][y]=='.':
        print('No')
        exit()
      else:
        pass
print('Yes')

Submission status: Runtime Error

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

arr=[]
for h in range(0,H):
    for w in range(0,W):
        if S[w][h]=='#':
            cnt=0
            if w!=0:
                cnt+=S[w-1][h]=='#'
            if w!=W-1:
                cnt+=S[w+1][h]=='#'
            if h!=0:
                cnt+=S[w][h-1]=='#'
            if h!=H-1:
                cnt+=S[w][h+1]=='#'
            arr.append(cnt>0)
print('Yes' if all(arr) else 'No')

Submission status: Runtime Error

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

arr=[]
for h in range(0,H):
    for w in range(0,W):
        if S[w][h]=='#':
            cnt=0
            if w!=0:
                cnt+=S[w-1][h]=='#'
            if w!=W-1:
                cnt+=S[w+1][h]=='#'
            if h!=0:
                cnt+=S[w][h-1]=='#'
            if h!=H-1:
                cnt+=S[w][h+1]=='#'
            arr.append(cnt>0)
print(all(arr))

Submission status: Runtime Error

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

for x in range(h):
    for y in range(w):
        if s[x][y] == "#":
            flag = False

            for i in range(4):
                nx = x + dx[i]
                ny = y + dy[i]
                if 0 <= nx < h and 0 <= ny < w and s[nx][ny] == "#":
                    flag = True

            if not flag:
                print("No")
                exit()

print("Yes")

Submission status: Runtime Error

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

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

for i in range(H):
    for j in range(W):
        if S[i][j] == ".":
            continue

        flag = False
        for dx, dy in ds:
            x, y = i + dx, j + dy
            if x < 0 or W <= x or y < 0 or H <= y:
                continue

            if S[x][y] == "#":
                flag = True
                break

        if not flag:
            print("No")
            exit()
print("Yes")

Submission status: Runtime Error

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

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

for i in range(H):
    for j in range(W):
        if S[i][j] == ".":
            continue

        flag = False
        for dx, dy in ds:
            x, y = i + dy, j + dx
            if x < 0 or W <= x or y < 0 or H <= y:
                continue

            if S[x][y] == "#":
                flag = True
                break

        if not flag:
            print("No")
            exit()
print("Yes")

Submission status: Runtime Error

Solution code:
H,W=map(int,input().split())
S=[input() for _ in range(H)]
ans='Yes'
for i in range (H):
  for j in range (W):
    if S[i][j]=='#':
      if S[max(0,i-1)][j]!='#' and S[min(i+1,W-1)][j]!='#' and S[i][max(0,j-1)]!='#' and S[i-1][min(j+1,H-1)]!='#':
        ans='No'
        break
print(ans)

Submission status: Runtime Error

Solution code:
H,W=map(int,input().split())
S=[input() for _ in range(H)]
Ans = 'Yes'
for i in range (H):
  for j in range (W):
    if S[i][j]=='#':
      if S[max(0,i-1)][j]=='#'or [min(i+1,W)][j]=='#'or[i][max(0,j-1)]=='#'or[i-1][min(j+1,H)]=='#':
        continue
      else:
        Ans = 'No'
  print(Ans)

Submission status: Runtime Error

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

for i in range(W):
    S='.'+input()+'.'
    A.append(S)
K='.'
A.insert(0,K*(H+2))
A.append(K*(H+2))
for i in range(1,H):
    for j in range(1,W):
        if A[i][j]=='#':
            if A[i+1][j]=='.' and A[i-1][j]=='.' and A[i][j+1]=='.' and A[i][j-1]=='.':
                print('No')
                exit(0)

print('Yes')

Submission status: Runtime Error

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

for i in range(W):
    S='.'+input()+'.'
    A.append(S)
K='.'
A.insert(0,K*(H+2))
A.append(K*(H+2))
for j in range(1,H+1):
    for i in range(1,W+1):
        if A[i][j]=='#':
            if A[i+1][j]=='.' and A[i-1][j]=='.' and A[i][j+1]=='.' and A[i][j-1]=='.':
                print('No')
                exit(0)

print('Yes')

Submission status: Runtime Error

Solution code:
h, w = map(int, input().split())
s = [['.']*(w+2)] + [['.']+list(input())+['.'] for _ in range(w)] + [['.']*(w+2)]
for i in range(1, w+1):
    for j in range(1, w+1):
        if s[i][j] == '.': continue
        if s[i-1][j] == '.' and s[i][j-1] == '.' and s[i][j+1] == '.' and s[i+1][j] == '.':
            print('No')
            exit()
print('Yes')

Submission status: Runtime Error

Solution code:
h, w = map(int, input().split())
s = [['.']*(w+2)] + [['.']+list(input())+['.'] for _ in range(w)] + [['.']*(w+2)]
for i in range(1, w+1):
    for j in range(1, w+1):
        if s[i][j] == '#':
           if s[i-1][j] == '.' and s[i][j-1] == '.' and s[i][j+1] == '.' and s[i+1][j] == '.':
                print('No')
                exit()
print('Yes')

Submission status: Runtime Error

Solution code:
h, w = map(int, input().split())
s = [['.']*(w+2)] + [['.']+list(input())+['.'] for _ in range(w)] + [['.']*(w+2)]
a = True
for i in range(1, w+1):
    for j in range(1, w+1):
        if s[i][j] == '#':
           if s[i-1][j] == '.' and s[i][j-1] == '.' and s[i][j+1] == '.' and s[i+1][j] == '.':
                a = False
                break
    if not a:
        break
if a ==True:
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

Solution code:
#96
h, w = map(int, input().split())
s = [['.']*(w+2)] + [['.']+list(input())+['.'] for _ in range(w)] + [['.']*(w+2)]
a = True
for i in range(1, w+1):
    for j in range(1, w+1):
        if s[i][j] == '#':
           up = s[i-1][j]
           left = s[i][j-1]
           right = s[i][j+1]
           down = s[i+1][j]
           if up == '.' and left == '.' and right == '.' and down == '.':
                a = False
                break
    if not a:
        break
if a ==True:
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

Solution code:
h, w = map(int, input().split())
s = [['.']*(w+2)]
s = s + [['.']+list(input())+['.'] for _ in range(w)]
s = s + [['.']*(w+2)]
a = True
for i in range(1, w+1):
    for j in range(1, w+1):
        if s[i][j] == '#':
           up = s[i-1][j]
           left = s[i][j-1]
           right = s[i][j+1]
           down = s[i+1][j]
           if up == '.' and left == '.' and right == '.' and down == '.':
                a = False
                break
    if not a:
        break
if a ==True:
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

Solution code:
h, w = map(int, input().split())
s = [['.']*(w+2)]
s = s + [['.']+list(input())+['.'] for _ in range(w)]
s = s + [['.']*(w+2)]
a = True
for i in range(1, w+1):
    for j in range(1, w+1):
        if s[i][j] == '#':
           up = s[i-1][j]
           left = s[i][j-1]
           right = s[i][j+1]
           down = s[i+1][j]
           if up == '.' and left == '.' and right == '.' and down == '.':
               a = False
if a ==True:
    print('Yes')
else:
    print('No')