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()))
s = [list(input()) for i in range(h)]
ss = [["." for i in range(w+2)] for j in range(h+2)]

for i in range(w):
    for j in range(h):
        ss[i+1][j+1]=s[i][j]

flag = 1

for i in range(h):
    for j in range(w):
        if ss[i+1][j+1]=="#":
            if ss[i][j+1]=="." and ss[i+2][j+1]=="." and ss[i+1][j]=="." and ss[i+1][j+2]==".":
                flag = 0
                break
                
if flag==1:
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
def main():
  t = input().split(" ")
  H, W = int(t[0]), int(t[1])
  
  s = ["."*(W+2)]
  for i in range(H):
    t = input().strip()
    s.append("".join(['.', t, '.']))
  s.append("."*(W+2))
  flag == True
  for i in range(H):
    for j in range(W):
      if s[i+1][j+1] == '#':
        if s[i][j+1]=='.' and s[i+2][j+1]=='.' and s[i+1][j]=='.' and s[i+1][j+2]=='.':
          flag == False
  if flag:
    print("Yes")
  else:
    print("No")
main()

Submission status: Runtime Error

Solution code:
import numpy as np

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

grid = np.zeros((H, W), dtype=int)

for h in range(H):
    S = input()
    for i, s in enumerate(S):
        if s == '#':
            grid[h][i] = 1

# print(grid)


def is_safe(h, w):
    ns = []
    ns.append((h-1, w))
    ns.append((h, w-1))
    ns.append((h+1, w))
    ns.append((h, w+1))

    safe = False
    for n in ns:
        if 0 <= n[0] and n[0] < H \
           and 0 <= n[1] and n[1] < H \
           and grid[n[0]][n[1]] == 1:
            safe = True

    if safe is False:
        print("No")
        exit(0)

    
for h in range(H):
    for w in range(W):
        if grid[h][w] == 1:
            is_safe(h, w)

print("Yes")
exit(0)

Submission status: Runtime Error

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

dxy = [(0,1),(1,0),(0,-1),(-1,0)]
def is_isolated(x,y):
    if src[y][x] == '.': return False
    for dx,dy in dxy:
        if not 0 <= x+dx < W: continue
        if not 0 <= y+dy < H: continue
        if src[y+dy][x+dx] == '#': return False
    else:
        return True

for y in range(H):
    for x in range(W):
        if is_isolated(y,x):
            print('No')
            exit()
print('Yes')

Submission status: Runtime Error

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

# result = True
masu = [['.' for i in range(H+2)] for j in range(W+2)]
for h in range(H):
    s = "."+input()+"."
    masu[h+1] = s

# print(masu)

for h in range(1,H+1):
    for w in range(1,W+1):
        if masu[h][w] == "#":
            if "#" == masu[h+1][w] or "#" == masu[h][w+1] or "#" == masu[h-1][w] or "#" == masu[h][w-1]:
                pass
            else:
                # result = False
                print("No")
                exit()

print("Yes")

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Your code here!

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

# result = True
masu = [['.' for i in range(H+2)] for j in range(W+2)]
for h in range(H):
    s = "."+input()+"."
    masu[h+1] = list(s)

# print(masu)

for h in range(1,H+1):
    for w in range(1,W+1):
        if masu[h][w] == "#":
            if "#" == masu[h+1][w] or "#" == masu[h][w+1] or "#" == masu[h-1][w] or "#" == masu[h][w-1]:
                pass
            else:
                # result = False
                print("No")
                exit()

print("Yes")

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Your code here!

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

result = True
masu = [['.' for i in range(H+2)] for j in range(W+2)]
for h in range(H):
    s = "."+input()+"."
    masu[h+1] = list(s)

# print(masu)

for h in range(1,H+1):
    for w in range(1,W+1):
        if masu[h][w] == "#":
            if "#" == masu[h+1][w] or "#" == masu[h][w+1] or "#" == masu[h-1][w] or "#" == masu[h][w-1]:
                pass
            else:
                result = False

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

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Your code here!

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

result = True
masu = [['0' for i in range(H+2)] for j in range(W+2)]
for h in range(1, H+1):
    s = "0"+input()+"0"
    masu[h] = list(s)

# print(masu)

for h in range(1,H+1):
    for w in range(1,W+1):
        if masu[h][w] == "#":
            if "#" == masu[h+1][w] or "#" == masu[h][w+1] or "#" == masu[h-1][w] or "#" == masu[h][w-1]:
                pass
            else:
                result = False

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

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Your code here!

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

result = True
masu = [['0' for i in range(H+2)] for j in range(W+2)]
for h in range(1, H+1):
    s = "0"+input()+"0"
    masu[h] = list(s)

# print(masu)

for h in range(1,H+1):
    for w in range(1,W+1):
        if masu[h][w] == "#":
            if ("#" == masu[h+1][w]) or ("#" == masu[h][w+1]) or ("#" == masu[h-1][w]) or ("#" == masu[h][w-1]):
                pass
            else:
                result = False

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

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Your code here!

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

result = True
masu = [[0 for i in range(H+2)] for j in range(W+2)]
for h in range(1, H+1):
    s = "0"+input()+"0"
    masu[h] = list(s)

# print(masu)

for h in range(1,H+1):
    for w in range(1,W+1):
        if masu[h][w] == "#":
            if ("#" == masu[h+1][w]) or ("#" == masu[h][w+1]) or ("#" == masu[h-1][w]) or ("#" == masu[h][w-1]):
                pass
            else:
                result = False

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

Submission status: Runtime Error

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

result = True
masu = [[0 for i in range(H+2)] for j in range(W+2)]
for h in range(1, H+1):
    s = "0"+input()+"0"
    masu[h] = list(s)

# print(masu)

for h in range(H):
    for w in range(W):
        if masu[h][w] == "#":
            if (masu[h][w] == masu[h+1][w]) or (masu[h][w] == masu[h][w+1]) or (masu[h][w] == masu[h-1][w]) or (masu[h][w] == masu[h][w-1]):
                pass
            else:
                result = False

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

Submission status: Runtime Error

Solution code:
h,w=map(int,input().split())
p=[["."]*(w+2)]+[["."]+list(map(str,input()))+["."]for i in range(w)]+[["."]*(w+2)]
print(["No","Yes"][int(all([any([p[i+x[0]][I+x[1]]=="#"for x in [[0,1],[0,-1],[1,0],[-1,0]]])for I in range(1,w+1)for i in range(1,h+1)if p[i][I]=="#"]))])

Submission status: Runtime Error

Solution code:
H, W = map(int, input().split())
matrix = []
for _ in range(H):
    row = input().split()
    matrix.append(row)
no_flag = False
for i, x in matrix:
    for j, y in matrix[i]:
        if y == '#':
            if j != 0 and matrix[i][j - 1] == '#':
                continue
            elif j != W - 1 and matrix[i][j + 1] == '#':
                continue
            elif i != 0 and matrix[i - 1][j] == '#':
                continue
            elif i != H - 1 and matrix[i + 1][j] == '#':
                continue
            else:
                no_flag = True
                break
    if no_flag == True:
        print('No')
else:
    print('Yes')

Submission status: Runtime Error

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

for y in range(h):
    for x in range(w):
        if field[y][x] == "#":
            try:
                if("#" in [field[y + 1][x], field[y - 1][x], field[y][x + 1], field[y][x - 1]]):
                    pass
                else:
                    print("No")
                    quit()
            except IndexError:
                False

print("Yes")

Submission status: Runtime Error

Solution code:

def main():
    x, y = [int(i) for i in input().split()]
    a = []
    for i in range(y):
        a.append(input().strip())

    for i in range(x):
        for j in range(y):
            link = False
            if a[j][i] == '#':
                if i-1 >= 0 and a[j][i-1] == '#':
                    link = True
                if i+1 < x and a[j][i+1] == '#':
                    link = True
                if j-1 >= 0 and a[j-1][i] == '#':
                    link = True
                if j+1 < y and a[j+1][i] == '#':
                    link = True

                if not link:
                    print('No')
                    return

    print('Yes')

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:

def main():
    x, y = [int(i) for i in input().split()]
    a = []
    for i in range(y):
        a.append(input().strip())

    for i in range(x):
        for j in range(y):
            f = False
            if a[j][i] == '#':
                if i-1 > 0 and a[j][i-1] == '#':
                    f = True
                if i+1 < x and a[j][i+1] == '#':
                    f = True
                if j-1 > 0 and a[j-1][i] == '#':
                    f = True
                if j+1 < y and a[j+1][i] == '#':
                    f = True

                if not f:
                    print('No')
                    return

    print('Yes')

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
#ABC096 C - Grid Repainting 2
I = raw_input().split(" ")
H = int(I[0])
W = int(I[1])
A = [list(raw_input()) for i in range(W)]
ans = 0
for X in range(H):
    for Y in range(W):
        counter = 0
        if A[X][Y] == "#":
            if X != 0 and A[X][Y] == A[X - 1][Y]:
                counter += 1
            if X != H - 1 and A[X][Y] == A[X + 1][Y]:
                counter += 1
            if Y != 0 and A[X][Y] == A[X][Y - 1]:
                counter += 1
            if Y != W - 1 and A[X][Y] == A[X][Y + 1]:
                counter += 1
            if counter == 0:
                ans += 1
if ans == 0:
    print "Yes"
else:
    print "No"

Submission status: Runtime Error

Solution code:

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

table = []

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


def check(x,y):
	if table[y-1][x]=='#' or table[y+1][x]=='#' or table[y][x-1]=='#' or table[y][x+1]=='#' :
		return
	else:
		print ('No')
		quit()
		

for y in range(H):
	for x in range(W):
		check(x,y)

print ('Yes')

Submission status: Runtime Error

Solution code:
h,w=map(int,input().split())
lis = []
for _ in range(h):
 lis.append(input())
for i in range(h):
 for j in range(w):
  if lis[i][j] = "#":
    if (i == 0 or lis[i-1][j] == ".") and (j==0 or lis[i][j-1] == ".")  and (i == h-1 or lis[i+1][j] == ".") and (j == w-1 or lis[i][j+1] == "."):
      print("No")
      quit()
print("Yes")

Submission status: Runtime Error

Solution code:
h,w=map(int,input().split())
s=[]
white=[]
for i in range(w):
  white.append(".")
s.append(white)
for i in range(h):
  a=[]
  a.append(".")
  for j in range(w):
    wh=list(map(int,input().split()))
    a.append(wh)
  a.append(".")
s.append(white)

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

Submission status: Runtime Error

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

for i in range(h):
    l2 = list(input())
    l1.append(l2)

is_no = 0
for i in range(w):
    for j in range(h):
        if l1[i][j] == '#':
            if i == 0:
                if j == 0:
                    if l1[i][j + 1] == '.' and l1[i + 1][j] == '.':
                        is_no = 1
                        
                elif j == w - 1:
                    if l1[i][j - 1] == '.' and l1[i + 1][j] == '.':
                     is_no = 1

                else:
                    if l1[i][j - 1] == '.'  and l1[i][j + 1] == '.' and l1[i + 1][j] == '.':
                        is_no = 1


            elif i == h - 1:
                if j == 0:
                    if l1[i][j + 1] == '.' and l1[i - 1][j] == '.':
                        is_no = 1

                elif j == w - 1:
                    if l1[i][j - 1] == '.' and l1[i - 1][j] == '.':
                        is_no = 1

                else:
                    if l1[i][j - 1] == '.'  and l1[i][j + 1] == '.' and l1[i - 1][j] == '.':
                        is_no = 1


            else:
                if j == 0:
                    if l1[i][j + 1] == '.' and l1[i - 1][j] == '.' and l1[i + 1][j] == '.':
                        is_no = 1

                elif j == w - 1:
                    if l1[i][j - 1] == '.' and l1[i - 1][j] == '.' and l1[i + 1][j] == '.':
                        is_no = 1

                else:
                    if l1[i][j - 1] == '.'  and l1[i][j + 1] == '.' and l1[i - 1][j] == '.' and l1[i + 1][j] == '.':
                        is_no = 1


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

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
a = []
tmp = []
for i in range(N):
    tmp = list(map(str,input().split()))
    a.append(list(tmp[0]))

for i in range(1,N):
    for j in range(1,M):
        if a[i][j] == '#':
            if a[i][j - 1] != '#' and a[i - 1][j] != '#' and a[i][j + 1] != '#' and a[i + 1][j] != '#':
                print("No")
                exit()
        else:
            pass

print("Yes")

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
a = []
tmp = []
for i in range(N):
    tmp = list(map(str,input().split()))
    a.append(list(tmp[0]))

for i in range(1,N+1):
    for j in range(1,M+1):
        if a[i][j] == '#':
            if a[i][j - 1] != '#' and a[i - 1][j] != '#' and a[i][j + 1] != '#' and a[i + 1][j] != '#':
                print("No")
                exit()
        else:
            pass

print("Yes")

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
a = []
tmp = []
for i in range(N):
    tmp = list(map(str,input().split()))
    a.append(list(tmp[0]))

for i in range(N):
    for j in range(M):
        if a[i][j] == '#':
            if a[i][j - 1] != '#' and a[i - 1][j] != '#' and a[i][j + 1] != '#' and a[i + 1][j] != '#':
                print("No")
                exit()
        else:
            pass

print("Yes")

Submission status: Runtime Error

Solution code:
import sys
 
N, M = map(int, input().split())
a = []
tmp = []
for i in range(N):
    tmp = list(map(str,input().split()))
    a.append(list(tmp[0]))

for i in range(N):
    for j in range(M):
        if a[i][j] == '#':
            if a[i][j - 1] != '#' and a[i - 1][j] != '#' and a[i][j + 1] != '#' and a[i + 1][j] != '#':
                print("No")
                sys.exit(0)
        else:
            pass

print("Yes")

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
a = []
tmp = []
for i in range(M):
    tmp = list(map(str,input().split()))
    a.append(list(tmp[0]))

Submission status: Runtime Error

Solution code:
import sys
 
N, M = map(int, input().split())
a = []
tmp = []
for i in range(M):
    tmp = list(map(str,input().split()))
    a.append(list(tmp[0]))
 
 
cpi = [-1,0,0,1]
cpj = [0,-1,1,0]
 
smFlag = False
 
for i in range(N):
    for j in range(M):
        if a[i][j] == '#':
            for x,y in zip(cpi,cpj):
                if N > i + x > -1 and M > j + y > -1:
                    if a[i+x][j+y] == '#':
                        smFlag = True
            if not smFlag:
                print('No')
                sys.exit()
 
print('Yes')

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
a = []
tmp = []
for i in range(M):
    tmp = list(map(str,input().split()))
    a.append(list(tmp[0]))


cpi = [-1,0,0,1]
cpj = [0,-1,1,0]

smFlag = False
result = True

for i in range(N):
    for j in range(M):
        if a[i][j] == '#':
            for x,y in zip(cpi,cpj):
                if i + x > -1 and j + y > -1 and i + x < N  and j + y < M:
                    if a[i+x][j+y] == '#':
                        smFlag = True
            if not smFlag:
                print('No')
                result = False

if result:
    print('Yes')

Submission status: Runtime Error

Solution code:
import sys

N, M = map(int, input().split())
a = []
tmp = []
for i in range(M):
    tmp = list(map(str,input().split()))
    a.append(list(tmp[0]))


cpi = [-1,0,0,1]
cpj = [0,-1,1,0]

smFlag = False

for i in range(N):
    for j in range(M):
        if a[i][j] == '#':
            for x,y in zip(cpi,cpj):
                if i + x > -1 and j + y > -1 and i + x < N  and j + y < M:
                    if a[i+x][j+y] == '#':
                        smFlag = True
            if not smFlag:
                print('No')
                sys.exit()

print('Yes')

Submission status: Runtime Error

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

field = []

for i in range(H):
  field.append(list(input()))
count = 0

for i in range(1,H+1):
    for j in range(1,W+1):
        if C[i][j]=='#'and'#'not in[C[i-1][j], C[i][j-1], C[i][j+1], C[i+1][j]]:
            print('No')
            exit()
print("Yes")

Submission status: Runtime Error

Solution code:
a =str(input()).split(" ")
h = int(a[0])
w = int(a[1])
maps= []

for i in range(h):
    maps.append(list(input()))
   
for i in range(h - 1 ):
    for j in range(w:
        if maps[i][j] == "#":
            if j - 1 > 0 and maps[i][j - 1] == "#":
                continue
            elif j + 1 < w and maps[i][j + 1] == "#" :
                continue
            elif i + 1 < h and maps[i + 1][j] == "#" :
                continue
            elif i - 1 > 0 and maps[i - 1][j] == "#":
                continue
            else:
                print("No")
                exit()
        else:
            pass
print("Yes")

Submission status: Runtime Error

Solution code:
a =str(input()).split(" ")
h = int(a[0])
w = int(a[1])
maps= []

for i in range(h):
    maps.append(list(input()))
   
for i in range(h-1):
    for j in range(w):
        if maps[i][j] == "#":
            if maps[i][j - 1] == "#" and j - 1 > 0:
                continue
            elif maps[i][j + 1] == "#" and j + 1 < w:
                continue
            elif maps[i + 1][j] == "#" and i + 1 < h:
                continue
            elif maps[i - 1][j] == "#" and i - 1 > 0:
                continue
            else:
                print("No")
                exit()
        else:
            pass

print("Yes")

Submission status: Runtime Error

Solution code:
H, W = list(map(int, input().split()))
s = []
s.append(['.']*(W+2))
for i in range(H):
    #二次元配列に入力を入れる
    array =['.']
    array.extend(list(input()))
    array.extend(['.'])
    s.append(array)
s.append(['.']*(W+2))
#print(s)
count = 0
for i in range(1,W+1):
    for j in range(1,H+1):
        if(s[i][j] == '#' and s[i][j-1] != '#' and s[i][j+1] != '#' and s[i-1][j] != '#' and s[i+1][j] != '#'):
            count += 1

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

Submission status: Runtime Error

Solution code:
H, W = list(map(int, input().split()))
s = []
s.append(['.']*(W+2))
for i in range(W):
    #二次元配列に入力を入れる
    array =['.']
    array.extend(list(input()))
    array.extend(['.'])
    s.append(array)
s.append(['.']*(W+2))
count = 0
for i in range(1,W+1):
    for j in range(1,H+1):
        if(s[i][j] == '#' and s[i][j-1] != '#' and s[i][j+1] != '#' and s[i-1][j] != '#' and s[i+1][j] != '#'):
            count += 1

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

Submission status: Runtime Error

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

res = True

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

Submission status: Runtime Error

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

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

res = True

for i in range(1, W-1):
    for j in range(1, H-1):
        if graph[i][j] == '#' and graph[i + 1][j] == '.' and graph[i - 1][j] == '.' and graph[i][j + 1] == '.' and graph[i][j - 1] == '.':
            res = False
            break
    if not res:
        break
print('Yes' if res else 'No')

Submission status: Runtime Error

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

res = True

for i in range(1, W-1):
    for j in range(1, H-1):
        if graph[i][j] == '#' and graph[i + 1][j] == '.' and graph[i - 1][j] == '.' and graph[i][j + 1] == '.' and graph[i][j - 1] == '.':
            res = False
            break
    if not res:
        break
print('Yes' if res else 'No')

Submission status: Runtime Error

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

res = True

for i in range(1, W-1):
    for j in range(1, H-1):
        if graph[i][j] == 1 and graph[i + 1][j] == 0 and graph[i - 1][j] == 0 and graph[i][j + 1] == 0 and graph[i][j - 1] == 0:
            res = False
print('Yes' if res else 'No')

Submission status: Runtime Error

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

res = True

for i in range(1, W-1):
    for j in range(1, H-1):
        if graph[i][j] == 1 and graph[i + 1][j] == 0 and graph[i - 1][j] and graph[i][j + 1] and graph[i][j - 1]:
            res = False
            break
    if not res:
        break
print('Yes' if res else 'No')

Submission status: Runtime Error

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

xx = [-1, 0, 1, 0]
yy = [0, -1, 0, 1]


res = True

for i in range(W):
    for j in range(H):
        if graph[i][j] == 1:
            flag = False
            for idx in range(4):
                nx, ny = i + xx[idx], j + yy[idx]
                if 0 <= nx and nx < W and 0 <= ny and ny < H and graph[nx][ny] == 1:
                    flag = True
                    break
            if not flag:
                res = False
                break
    if not res:
        break

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

Submission status: Runtime Error

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

xx = [-1, 0, 1, 0]
yy = [0, -1, 0, 1]


res = True

for i in range(W):
    for j in range(H):
        if graph[i][j] == 1:
            flag = False
            for idx in range(4):
                nx, ny = i + xx[idx], j + yy[idx]
                if 0 <= x and x < W and 0 <= y and y < H and graph[nx][ny] == 1:
                    flag = True
                    break
            if not flag:
                res = False
                break
    if not res:
        break

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

Submission status: Runtime Error

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

xx = [-1, 0, 1, 0]
yy = [0, -1, 0, 1]


res = True

for i in range(W):
    for j in range(H):
        if graph[i][j] == 1:
            flag = False
            for idx in range(4):
                nx, ny = i + xx[idx], j + yy[idx]
                if 0 <= x and x < W and 0 <= y and y < H and graph[nx][ny] == 1:
                    flag = True
            if not flag:
                res = False
                break
    if not res:
        break

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

Submission status: Runtime Error

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

xx = [-1, 0, 1, 0]
yy = [0, -1, 0, 1]


def isValidTransition(x, y, H, W):
    return 0 <= x and x < W and 0 <= y and y < H

res = True

for i in range(W):
    for j in range(H):
        if graph[i][j] == 1:
            flag = False
            for idx in range(4):
                nx, ny = i + xx[idx], j + yy[idx]
                if isValidTransition(nx, ny, H, W) and graph[nx][ny] == 1:
                    flag = True
            if not flag:
                res = False
                break
    if not res:
        break

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

Submission status: Runtime Error

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

xx = [-1, 0, 1, 0]
yy = [0, -1, 0, 1]


def isValidTransition(x, y, H, W):
    return 0 <= x and x < W and 0 <= y and y < H

res = True

for i in range(W):
    for j in range(i, H):
        if graph[i][j] == 1:
            flag = False
            for idx in range(4):
                nx, ny = i + xx[idx], j + yy[idx]
                if isValidTransition(nx, ny, H, W) and graph[nx][ny] == 1:
                    flag = True
            if not flag:
                res = False
                break
    if not res:
        break

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

Submission status: Runtime Error

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

xx = [-1, 0, 1, 0]
yy = [0, -1, 0, 1]


def isValidTransition(x, y, H, W):
    return 0 <= x and x < W and 0 <= y and y < H

def dfs(x, y):
    graph[x][y] = 0
    flag = False
    for idx in range(4):
        nx, ny = x + xx[idx], y + yy[idx]
        if isValidTransition(nx, ny, H, W) and graph[nx][ny] == 1:
            dfs(nx, ny)
            flag = True
    return flag

res = True

for i in range(W):
    for j in range(i, H):
        if graph[i][j] == 1 and not dfs(i, j):
            res = False
            break
    if not res:
        break

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

Submission status: Runtime Error

Solution code:
H,W = map(int,input().split())
s = [list(input()) for i in range(H)]
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] == ".":
			    print("No")
			    exit()
print("Yes")

Submission status: Runtime Error

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

line_list = []
for i in range(w):
    line_list.append(input())

if h == 1:
    if w == 1:
        print("No")
        exit()
    else:
        for j in range(w-1):
            if line_list[0][j] == "#":
                if line_list[0][j + 1] != "#":
                    print("No")
                    exit()
                else:
                    j += 1
                    continue
    print("Yes")
    exit()
elif w == 1:
    if h == 1:
        print("No")
        exit()
    else:
        for j in range(h-1):
            if line_list[j] == "#":
                if line_list[j + 1] != "#":
                    print("No")
                    exit()
                else:
                    j += 1
                    continue
    print("Yes")
    exit()


before_line = [["."] for _ in range(w)]
current_line = list(line_list[0])
for i in range(h-1):
    after_line = list(line_list[i + 1])
    j = 0
    while j < w-1:
        if current_line[j] == "#":
            if current_line[j+1] == "#":
                j += 1
                while j < w - 1:
                    if current_line[j + 1] != "#":
                       break
                    else:
                        j += 1
                j += 1
                continue
            elif before_line[j] != "#" and after_line[j] != "#":
                print("No")
                exit()
        j += 1
    before_line = current_line
    current_line = after_line

print("Yes")

Submission status: Runtime Error

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

ns = ((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 ns:
            nx = i + dx
            ny = j + dy
            if nx < 0 or nx >= w:
                continue
            if ny < 0 or ny >= h:
                continue
            if s[nx][ny] == '#':
                break
        else:
            print('No')
            exit()

print('Yes')