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: Accepted

Solution code:
h,w=map(int,input().split())
mez=['.'*(w+1)]

for _ in range(h):
    meztmp=input()
    mez.append('.'+meztmp+'.')
mez.append('.'*(w+1))
for y in range(1,h+1):
    for x in range(1,w+1):
        if mez[y][x]=='#':
            if mez[y-1][x]=='.' and mez[y+1][x]=='.' and mez[y][x+1]=='.' and mez[y][x-1]=='.':
                print('No')
                exit()
print('Yes')

Submission status: Accepted

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

Submission status: Accepted

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


def enclose_field(field, outline="#"):
    """
    迷路等の外周をoutlineで埋めることで、IndexErrorを回避できます。
    [0, 0] → [1, 1]、[H-1, W-1] → [H, W]となります。
    """
    for i in range(len(field)):
        field[i] = [outline] + field[i] + [outline]
    field.append([outline] * (len(field[0])))
    field.insert(0, [outline] * (len(field[0])))
    return field


S = enclose_field(S, outline="a")

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
from itertools import product
def inpl(): return map(int, input().split())
H, W = inpl()
S = [list("."*(W+2))]
for _ in range(H):
    S.append(list("." + input() + "."))
S.append(list("."*(W+2)))

for h, w, in product(range(1, H+1), range(1, W+1)):
    if S[h][w] == ".":
        continue
    ok = False
    for dh, dw in [[0, 1], [0, -1], [1, 0], [-1, 0]]:
        if S[h+dh][w+dw] == "#":
            ok = True
            break
    if not ok:
        print("No")
        break
else:
    print("Yes")

Submission status: Accepted

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

flag = True
for i in range(h):
    for j in range(w):
        if F[i][j] == "#":
            flag2 = False
            for dx, dy in [(1, 0), (0, 1), (-1, 0), (0, -1)]:
                nx, ny = i + dx, j + dy
                if 0 <= nx < h and 0 <= ny < w and F[nx][ny] == "#":
                    flag2 = True
            if not flag2:
                flag = False
                break

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

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
s = []
s.append("."*(W+2))
for _ in range(H):
    s.append("."+input()+".")
s.append("."*(W+2))


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

Submission status: Accepted

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

def main():
    H, W = map(int, input().split())
    grid = []
    for h in range(H):
        grid.append([c for c in input()])

    for x in range(W):
        for y in range(H):
            if grid[y][x] == '#':
                for x_, y_ in zip([0, 0, -1, 1], [-1, 1, 0, 0]):
                    nx = x + x_
                    ny = y + y_
                    if not(0 <= nx < W):
                        continue
                    if not(0 <= ny < H):
                        continue
                    if grid[ny][nx] == '#':
                        break
                else:
                    print('No')
                    return
    print("Yes")
    return


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
H, W = map(int,input().split())
C = ['.' * (W + 2)]

for i in range(H):
    C += ["." + input() + "."]

C += ['.' * (W + 2)]

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

print(result)

Submission status: Accepted

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

flag = True
for h in range(H):
    for w in range(W):
        if s[h][w] == "#" and not (h != 0 and s[h - 1][w] == "#" or
                h != H - 1 and s[h + 1][w] == "#" or
                w != 0 and s[h][w - 1] == "#" or
                w != W - 1 and s[h][w + 1] == "#"):
            print("No")
            sys.exit()
print("Yes")

Submission status: Accepted

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

C = ["."*(W+2)]
for k in range(H):
    C.append("."+input()+".")
C.append("."*(W+2))

for k in range(1,W+1):
    for l in range(1,H+1):
        if C[l][k]=="#":
            if C[l+1][k]=="#" or C[l-1][k]=="#" or C[l][k+1]=="#" or C[l][k-1]=="#":
                pass
            else:
                print("No")
                exit(0)
print("Yes")

Submission status: Accepted

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

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

cond = True
for i in range(h):
    for j in range(w):
        if matrix[i][j] == '#':
            tmp_cond = False
            try:
                if matrix[i - 1][j] == '#':
                    tmp_cond = True
            except:
                pass
            try:
                if matrix[i + 1][j] == '#':
                    tmp_cond = True
            except:
                pass
            try:
                if matrix[i][j - 1] == '#':
                    tmp_cond = True                    
            except:
                pass            
            try:
                if matrix[i][j + 1] == '#':
                    tmp_cond = True 
            except:
                pass
            
            if tmp_cond == False:
                cond = False
                
if cond:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:

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

str = []
for i in range(H):
    str.append("."+input()+".")
    
#for i in range(H):
#    print(str[i])

H+=2
W+=2

str.insert(0, "."*(W))
str.append("."*(W))

for i in range(1,H-1):
    for j in range(1,W-1):
        if(str[i][j]=='.'):
            continue

        diff = [0,1,0,-1,0]
        is_ok = False
        for d in range(4):
            if str[i+diff[d]][j+diff[d+1]] == '#':
                is_ok = True
        if is_ok==False:
            print("No")
            exit(0)
            
print("Yes")

Submission status: Accepted

Solution code:
# C
H, W = map(int, input().split())
s_list = list()
for _ in range(H):
    s_list.append(list(input()))

res = "Yes"
# check
for i in range(H):
    for j in range(W):
        
        if s_list[i][j] == "#":
            res_temp = "No"
        else:
            res_temp = "Yes"
        # check 1
        if i > 0:
            if s_list[i-1][j] == "#":
                res_temp = "Yes"
        # check 2
        if i+1 < H:
            if s_list[i+1][j] == "#":
                res_temp = "Yes"      
        # check 3
        if j > 0:
            if s_list[i][j-1] == "#":
                res_temp = "Yes"
        # check 4
        if j+1 < W:
            if s_list[i][j+1] == "#":
                res_temp = "Yes"   
        # check
        if res_temp == "No":
            res = "No"
print(res)

Submission status: Accepted

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

for i in range(h):
    for j in range(w):
        if s[i][j]=='.':
            continue
        flag=False
        if i>0:
            if s[i-1][j]=='#':
                continue
        if j>0:
            if s[i][j-1]=='#':
                continue
        if i<h-1:
            if s[i+1][j]=='#':
                continue
        if j<w+1:
            if s[i][j+1]=='#':
                continue
        break
    else:
        continue
    break
else:
    print('Yes')
    quit()
print('No')

Submission status: Accepted

Solution code:
def solve(field):
    for i in range(1, h + 1):
        for j in range(1, w + 1):
            if field[i][j] == '.':
                continue
            if field[i - 1][j] == field[i + 1][j] == field[i][j - 1] == field[i][j + 1] == '.':
                return False
    return True


h, w = list(map(int, input().split()))
field = ['.' + input() + '.' for _ in range(h)]
field = ['.' * (w + 2)] + field + ['.' * (w + 2)]
print('Yes' if solve(field) else 'No')

Submission status: Accepted

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

for i in range(h):
    for j in range(w):
        if(s[i][j]=="#"):
            if not ((s[i-1][j]=="#" if i>0 else 0) or (s[i][j-1]=="#" if j>0 else 0) or (s[i+1][j]=="#" if i<(h-1) else 0) or (s[i][j+1]=="#" if j<(w-1) else 0)):
                print("No")
                sys.exit(0)
print("Yes")

Submission status: Accepted

Solution code:
# cook your dish here
# from math import * 
#for _ in range(int(input().strip())):

h,w = map(int,input().split())
m = []
m.append('.'*(w+2))
for i in range(h):
    m.append('.'+input()+'.')
m.append('.'*(w+2))
for i in range(1,h+1):
    for j in range(1,w+1):
        if m[i][j]=='.':
            continue
        if (m[i][j]=='#' and m[i+1][j]=='#') or (m[i][j]=='#' and m[i-1][j]=='#') or (m[i][j]=='#' and m[i][j-1]=='#') or (m[i][j]=='#' and m[i][j+1]=='#'):
            pass
        else:
            print("No")
            exit(0)
print("Yes")

Submission status: Accepted

Solution code:
h, w=map(int, input().split())
s=[input() for i in range(h)]
ans=0
for i in range(h):
    for j in range(w):
        if s[i][j]=='#':
            t=0
            try:
                if s[i+1][j]=='#':
                    t=1
            except:
                pass
            try:
                if s[i-1][j]=='#':
                    t=1
            except:
                pass
            try:
                if s[i][j+1]=='#':
                    t=1
            except:
                pass
            try:
                if s[i][j-1]=='#':
                    t=1
            except:
                pass
            if t==0:
                ans+=1
print('Yes') if ans==0 else print('No')

Submission status: Accepted

Solution code:
H,W = map(int,input().split())
S = []
for i in range(H):
    S.append(input())
Ans = "Yes"
for i in range(H):
    for j in range(W):
        check = ""
        if j-1 >= 0:
            check += S[i][j-1]
        if j+1 <= W-1:
            check += S[i][j+1]
        if i-1 >= 0:
            check += S[i-1][j]
        if i+1 <= H-1:
            check += S[i+1][j]
        if S[i][j]=="#" and "#" not in check:
            Ans = "No"
print(Ans)

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
wall = []
for i in range(h):
    wall.append(list(input()))
for i in range(h):
    for j in range(w):
        if wall[i][j] == "#":
            try:
                if wall[i+1][j]=="#":
                    continue
            except:
                pass
            try:
                if wall[i][j+1]=="#":
                    continue
            except:
                pass
            try:
                if wall[i-1][j]=="#":
                    continue
            except:
                pass
            try:
                if wall[i][j-1]=="#":
                    continue
            except:
                pass
            print("No")
            exit()
print("Yes")

Submission status: Accepted

Solution code:
H,W = map(int,input().split())
g = [input() for i in range(H)]
dr = [-1, 1, 0, 0]
dc = [0, 0, -1, 1]
for i in range(H):
    for j in range(W):
        if g[i][j] == '#':
            ok = False
            for k in range(4):
                x = i + dr[k]
                y = j + dc[k]
                if 0 <= x < H and 0 <= y < W:
                    ok = ok or g[x][y] == '#'
            if not ok:
                print('No')
                exit(0);
print('Yes')

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
s = [input() for _ in range(h)]
s = ['.'*(w+2)] + ['.'+l+'.' for l in s] + ['.'*(w+2)]
d = [0,1,0,-1,0]
check = True
for i in range(1, h+1):
    for j in range(1, w+1):
        if s[i][j] == '#':
            f = False
            for k in range(4):
                di = i+d[k+1]
                dj = j+d[k]
                if s[di][dj] == '#':
                    f = True
                    break
            if not f:
                check = False
                break
    if not check:
        break
print('Yes' if check else 'No')

Submission status: Accepted

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

dxy = [(-1,0),(0,-1),(1,0),(0,1)]
for y in range(H):
    for x in range(W):
        if src[y][x] == '.': continue
        for dx,dy in dxy:
            nx,ny = x+dx,y+dy
            if not 0 <= nx < W: continue
            if not 0 <= ny < H: continue
            if src[ny][nx] == '#':
                break
        else:
            print('No')
            exit()
print('Yes')

Submission status: Accepted

Solution code:
# coding: utf-8
h,w=map(int,input().split())
t=[]
for i in range(h):
    t.append(list(input()))
for i in range(h):
    for j in range(w):
        if t[i][j]=='#':
            tmp=0
            if i+1<h and t[i+1][j]=='#':
                tmp+=1
            if i-1>=0 and t[i-1][j]=='#':
                tmp+=1
            if j+1<w and t[i][j+1]=='#':
                tmp+=1
            if j-1>=0 and t[i][j-1]=='#':
                tmp+=1
            if tmp==0:
                print('No')
                exit()
print('Yes')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

n, m = na()

b = []
for i in range(n):
    b.append(ns())

for i in range(n):
    for j in range(m):
        if b[i][j] == "#":
            yes = 0
            if j-1 >= 0 and b[i][j-1] == "#":
                yes = 1
            if i-1 >= 0 and b[i-1][j] == "#":
                yes = 1
            if j+1 < m and b[i][j+1] == "#":
                yes = 1
            if i+1 < n and b[i+1][j] == "#":
                yes = 1
            if yes == 0:
                print("No")
                sys.exit(0)
print("Yes")

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
h,w=map(int,input().split()) 
l = [input() for _ in range(h)]
dx = [1,-1,0,0]
dy = [0,0,1,-1]
ans = 'No'
for i in range(w):
    for j in range(h):
        if l[j][i] =='#':
            for di in range(4):
                x = i+dx[di]
                y = j+dy[di]
                if x<0 or y<0 or x>w-1 or y>h-1:
                    continue
                else:
                    if l[x][y] =='#':
                        ans = 'Yes'
print(ans)

Submission status: Runtime Error

Solution code:
5 5
#.#.#
.#.#.
#.#.#
.#.#.
#.#.#

Submission status: Runtime Error

Solution code:
H,W  = map(int,input().split())
s = []
ans = 'Yes'
for _ in range(W):
    s.append(input())

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

Submission status: Runtime Error

Solution code:
H,W  = map(int,input().split())
s = []
ans = 'Yes'
for _ in range(W):
    s.append(input())

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

Submission status: Runtime Error

Solution code:
H,W  = map(int,input().split())
s = []
ans = 'Yes'
for _ in range(W):
    s.append(input())

for i in range(H-1):
    for j in range(W-1):
        if s[i][j]=='.':
            continue
        else:
            if s[i][j+1]=='.' and s[i+1][j]=='.':
                print('No')
                exit()
print(ans)

Submission status: Runtime Error

Solution code:
import sys
h,w = map(int,input().split())
s = [list(input()) for i in range(h)]
for i in range(w-1):
  for l in range(h-1):
    if s[i][l] == "#":
      if i != 0 and s[i-1][l] == "#" :
        continue
      elif l != 0 and s[i][l-1] == "#":
        continue
      elif s[i][l+1] == "." and s[i+1][l] == ".":
        print("No")
        sys.exit()
    
      
print("Yes")

Submission status: Runtime Error

Solution code:
import sys
h,w = map(int,input().split())
s = [list(input()) for i in range(h)]
for i in range(w-1):
  for l in range(h-1):
    if s[i][l] == "#":
      if s[i-1][l] == "#" :
        continue
      elif s[i][l-1] == "#":
        continue
      elif s[i][l+1] == "." and s[i+1][l] == ".":
        print("No")
        sys.exit()
    
      
print("Yes")

Submission status: Runtime Error

Solution code:
H, W = map(int, input().split())
s = [list(input()) for _ in range(H)]
a = [[-1]*W for _ in range(H)]
for i in range(H):
  for j in range(W):
    if s[i][j] == ".":
      a[i][j] = 1
    dh = [-1,0,1,0]
    dw = [0,-1,0,1]
    for k in range(4):
      ii = i + dh[k]
      jj = j + dw[k]
      if 0 <= ii < W and 0 <= jj < H:
        if s[i][j] == "#" and s[ii][jj] == "#":
          a[i][j] = 1
          a[ii][jj] = 1
flag = True
for i in range(H):
  for j in range(W):
    if a[i][j] != 1:
      flag = False
      break
if flag:
  print("Yes")
else:
  print("No")

Submission status: Runtime Error

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

ans = []
for row in src:
        ans.append(list(row))

flag = 0
dxy = [(1, 0), (-1, 0), (0, 1), (0, -1)]
for x in range(h):
        for y in range(w):
                if src[x][y] == ".":
                        continue
                else:
                        for dx, dy in dxy:
                                if x + dx < 0 or x + dx > h -1 or y + dy < 0 or y + dy > w - 1:
                                        continue
                                if src[x + dx][y + dx] == "#":
                                        flag = 1
                                        break
                        if flag == 0:
                                print("No")
                                exit()

print("Yes")

Submission status: Runtime Error

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

ans = []
for row in src:
        ans.append(list(row))

flag = 0
dxy = [(1, 0), (-1, 0), (0, 1), (0, -1)]
for x in range(h):
        for y in range(w):
                if src[x][y] == ".":
                        continue
                else:
                        for dx, dy in dxy:
                                if x + dx < 0 or x + dx > h -1 or y + dy < 0 or y + dy > w - 1:
                                        continue
                                if src[y +dy][x+dx] == "#":
                                        flag = 1
                                        break
                        if flag == 0:
                                print("No")
                                exit()

print("Yes")

Submission status: Runtime Error

Solution code:
import sys
H,W = map(int,input().split())
s = [list(input()) for _ in range(H)]
sys.setrecursionlimit(10**7)

flag = [[-1 for _ in range(W)] for _ in range(H)]
move = [(-1,0),(1,0),(0,-1),(0,1)]

def search(x,y):
  if x < 0 or H <= x or y < 0 or W <= y:
    return
  if s[x][y] == "." or flag[x][y] != -1:
    return
  flag[x][y] = 0
  s[x][y] = 0
  for (nx,ny) in move:
    wx, wy = x+nx, y+ny
    search(wx,wy)
  return 

check_1 = False
for i in range(H):
  for j in range(W):
    if s[i][j] == "#":
      sx, sy = i, j
      check_1 = True
      break
  if check_1:
    break
    
search(sx,sy)

check_2 = True
for i in range(H):
  for j in range(W):
    if s[i][j] == "#":
      check_2 = False
      
print("Yes" if check_2 else "No")

Submission status: Runtime Error

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

flag = [[-1 for _ in range(W)] for _ in range(H)]
move = [(-1,0),(1,0),(0,-1),(0,1)]

def search(x,y):
  if x < 0 or H <= x or y < 0 or W <= y:
    return
  if s[x][y] == "." or flag[x][y] != -1:
    return
  flag[x][y] = 0
  s[x][y] = 0
  for (nx,ny) in move:
    wx, wy = x+nx, y+ny
    search(wx,wy)
  return 

check_1 = False
for i in range(H):
  for j in range(W):
    if s[i][j] == "#":
      sx, sy = i, j
      check_1 = True
      break
  if check_1:
    break
    
search(sx,sy)

check_2 = True
for i in range(H):
  for j in range(W):
    if s[i][j] == "#":
      check_2 = False
      
print("Yes" if check_2 else "No")

Submission status: Runtime Error

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

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


def solve(H: int, W: int, S: "List[str]"):
    for i in range(H):
        for j in range(W):
            if S[i][j] == ".":
                continue
            if i - 1 >= 0:
                if S[i - 1][j] == "#":
                    continue
            if i + 1 < H:
                if S[i + 1][j] == "#":
                    continue
            if j - 1 >= 0 and S[i][j - 1] == "#":
                continue
            if j + 1 < W and S[i][j + 1] == "#":
                continue
            print(NO)
            return
    print(YES)
    return


# Generated by 1.1.7.1 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 = [list(next(tokens)) for _ in range(W)]  # type: "List[str]"
    solve(H, W, S)


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
from itertools import product

h, w = map(int, input().split())
s = [list(input()) for i in range(h)]
visited = []

def dfs(p):
    if s[p[1]][p[0]] == '.':
        return None

    temp = [1 if s[p[0]+x][p[1]+y] == '#' else 0 for (y, x) in [[1, 0], [0, 1], [0, -1], [-1, 0]]
            if 0 <= x+p[0] < len(s[0]) and 0 <= y+p[1] < len(s)]
    if sum(temp) <= 0:
        print('No')
        exit(0)


for i in range(len(s)):
    for j in range(len(s[0])):
        dfs([j, i])
print('Yes')

Submission status: Runtime Error

Solution code:
from itertools import product
h, w = map(int, input().split())
s = [list(input()) for i in range(h)]
visited = []

def dfs(p):
    if p in visited or s[p[0]][p[1]] == '.':
        return None

    temp = [1 if s[p[0]+x][p[1]+y] == '#' else 0 for (y, x) in [[1, 0], [0, 1], [0, -1], [-1, 0]]
            if 0 <= x+p[0] < len(s[0]) and 0 <= y+p[1] < len(s)]
    if sum(temp) <= 0:
        print('No')
        exit(0)


for i in range(len(s)):
    for j in range(len(s[0])):
        dfs([j, i])
print('Yes')

Submission status: Runtime Error

Solution code:
from itertools import product
h, w = map(int, input().split())
s = [list(input()) for i in range(h)]
visited = []

def dfs(p):
    if p in visited or s[p[0]][p[1]] == '.':
        return None

    temp = [1 if s[p[0]+y][p[1]+x] == '#' else 0 for (y, x) in [[1, 0], [0, 1], [0, -1], [-1, 0]] if 0 <= y+p[0] < len(s) and 0 <= x+p[1] < len(s[0])]
    if sum(temp) <= 0:
        print('No')
        exit(0)


for i in range(len(s)):
    for j in range(len(s[0])):
        dfs([j, i])
print('Yes')

Submission status: Runtime Error

Solution code:

H,W = map(int, input().split())
s = [input() for _ in range(H)]
import sys
for j in range(H):
    for i in range(W):
        if s[j][i] =='#':
            if 0<i and s[j][i-1] == '#':
                pass
            elif 0<j and s[j-1][i] == '#':
                pass
            elif i<H-1 and s[j][i+1] == '#':
                pass
            elif j<W-1 and s[j+1][i] == '#':
                pass
            else:
                print('No')
                sys.exit()
print('Yes')

Submission status: Runtime Error

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

import sys
for j in range(H):
    for i in range(W):
        if s[j][i] =='#':
            if j+1<W and i+1<H and j-1>=0 and i-1>=0:
                if (s[j+1][i]=='#' or s[j][i+1]=='#'or s[j][i-1]=='#',or s[j-1][i]=='#'):
                    continue
                if s[j+1][i]!='#' or s[j][i+1]!='#' or s[j-1][i]!='#' or s[j][i-1]!='#':
                    sys.exit()
print('Yes')

Submission status: Runtime Error

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

import sys
for j in range(H):
    for i in range(W):
        if s[j][i] =='#':
            if j+1<W and i+1<H and 0<=j-1 and 0<=i-1:
                if (s[j+1][i]=='#' or s[j][i+1]=='#' or s[j-1][i] or s[j][i-1]):
                    continue
                if s[j+1][i]!='#' and s[j][i+1]!='#' and s[j-1][i]!='#' and s[j][i-1]!='#':
                    print('No')
                    sys.exit()
print('Yes')

Submission status: Runtime Error

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

import sys
for j in range(H):
    for i in range(W):
        if s[j][i] =='#':
            if j+1<W and i+1<H and 0<=j-1 and 0<=i-1:
                if (s[j+1][i]=='#' or s[j][i+1]=='#' or s[j-1][i] or s[j][i-1]):
                    continue
                if s[j+1][i]!='#' or s[j][i+1]!='#' or s[j-1][i]!='#' or s[j][i-1]!='#':
                    print('No')
                    sys.exit()
print('Yes')

Submission status: Runtime Error

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

import sys
for j in range(H):
    for i in range(W):
        if s[j][i] =='#':
            if j+1<W and i+1<H and 0<=j-1 and 0<=i-1:
                if (s[j+1][i]=='#' or s[j][i+1]=='#'):
                    continue
                if s[j+1][i]!='#' or s[j][i+1]!='#' or s[j-1][i]!='#' or s[j][i-1]!='#':
                    print('No')
                    sys.exit()
print('Yes')

Submission status: Runtime Error

Solution code:
H,W = map(int,input().split())
List = [[""]*H]*W
for i in range(H):
    tmp = input()
    tmp = list(tmp)
    List[i] = tmp
for i in range(H):
    for j in range(W):
        if(List[i][j] == "#"):
            if(i == H-1):
                pass
            elif(j == W-1):
                pass
            elif(i == 0):
                pass
            elif(j == 0):
                pass
            else:
                if(List[i+1][j] == "#" or List[i][j+1] == "#" or List[i][j-1] == "#" or List[i-1][j] == "#"):
                    pass
                else:
                    print("No")
                    exit()
print("Yes")

Submission status: Runtime Error

Solution code:
H,W = map(int,input().split())
List = [[""]*H]*W
for i in range(H):
    tmp = input()
    tmp = list(tmp)
    List[i] = tmp
for i in range(H):
    for j in range(W):
        if(List[i][j] == "#"):
            if(i == H-1):
                pass
            elif(j == W-1):
                pass
            elif(i == 0):
                pass
            elif(j == 0):
                pass
            else:
                if(List[i+1][j] == "#" or List[i][j+1] == "#" or List[i][j-1] == "#" or List[i-1][j-1] == "#"):
                    pass
                else:
                    print("No")
                    exit()
print("Yes")

Submission status: Runtime Error

Solution code:
H,W = map(int,input().split())
List = [[""]*H]*W
for i in range(H):
    tmp = input()
    tmp = list(tmp)
    List[i] = tmp
for i in range(H):
    for j in range(W):
        if(List[i][j] == "#"):
            if(i == H-1):
                pass
            elif(j == W-1):
                pass
            else:
                if(List[i+1][j] == "#" or List[i][j+1] == "#" or List[i][j-1] == "#" or List[i-1][j-1] == "#"):
                    pass
                else:
                    print("No")
                    exit()
print("Yes")

Submission status: Runtime Error

Solution code:
import sys

input = sys.stdin.readline

d = '.'
dn = '#'

def isPaintable(h, w, x, y, canvas):
    ret = False
    if x > 0:
        if canvas[x-1, y] == dn:
            ret = True
    elif x < w:
        if canvas[x+1, y] == dn:
            ret = True
    elif y > 0:
        if canvas[x, y-1] == dn:
            ret = True
    elif y < h:
        if canvas[x, y+1] == dn:
            ret = True
    return ret

def main():
    ans = 'Yes'
    h, w = map(int, input().split())
    canavs = []
    for _ in range(h):
        s = list(input().split().rstrip('\n'))
        canvas.append(s)
    for i in h:
        if ans == 'No':
            break
        for j in w:
            if not isPaintable(h, w, j, i, canvas):
                ans = 'No'
                break
    print(ans)

if __name__ == '__main__':
    main()