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 = ['.'*(W+2)] + ['.'+input()+'.' for _ in range(H)] + ['.'*(W+2)]
for hi in range(1, W+1):
  for wi in range(1, H+1):
    if s[hi][wi] == '.':
      continue
    if s[hi-1][wi]=='.' and s[hi+1][wi]=='.':
      if s[hi][wi-1]=='.' and s[hi][wi+1]=='.':
        print('No')
        exit()
        
print('Yes')

Submission status: Runtime Error

Solution code:
h, w = map(int, input().split())
s = ['.'*(h+2)]
for i in range(h):
  ss = '.' + input() + '.'
  s.append(ss)
s.append('.'*(h+2))
dx = [1,0,-1,0]
dy = [0,1,0,-1]
for i in range(h):
  for j in range(w):
    cnt = 0
    for k in range(4):
      xi = i + dx[k]
      yi = j + dy[k]
      if s[i][j] == '#' and s[xi][yi] == '.':
        cnt += 1
    if cnt == 4:
      print('No')
      exit()

print('Yes')

Submission status: Runtime Error

Solution code:
import sys
h,w=map(int,input().split())
maze=[]
for i in range(w):
    maze.append(list(input()))
for i in range(w):
    for j in range(h):
        if maze[i][j]=="#":
            flg=False
            for l,m in [(0,1),(1,0),(-1,0),(0,-1)]:
                if 0<=i+l<w and 0<=j+m<h and maze[i+l][j+m]=="#":
                    flg=True
            if flg==False:
                print("No")
                sys.exit()
print("Yes")

Submission status: Runtime Error

Solution code:
import sys
h,w=map(int,input().split())
maze=[]
for i in range(w):
    maze.append(list(input()))
for i in range(w):
    for j in range(h):
        if maze[i][j]=="#":
            flg=False
            for l,m in [(0,1),(1,0),(-1,0),(0,-1)]:
                if 0<=i+l<w and 0<=j+m<h:
                    if maze[i+l][j+m]=="#":
                        flg=True
            if flg==False:
                print("No")
                sys.exit()
print("Yes")

Submission status: Runtime Error

Solution code:
h,w=map(int,input().split())
d=[['.']*(n+2) for j in range(n+2)]
for i in range(n):
  s,t=map(int,input().split())
  d[s][t]='#'
for k in range(1,n+1):
  for l in range(1,n+1):
    if all(aa=='.' or aa in [d[k-1][l],d[k+1][l],d[k][l-1],d[k][l+1]]):
      print('No')
      exit()
print('Yes')

Submission status: Runtime Error

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

ng = False
for i in range(h):
    for j in range(w):
        if M[i][j]  == '.':
            continue

        for mi, mj in [(0, 1), (0, -1), (1, 0), (-1, 0)]:
            ni = i + mi; nj = j + mj
            if ni < 0 or h <= ni or nj < 0 or w <= nj:
                continue

            if M[ni][nj] == '#':
                break
        else:
            ng=True
    if ng:
        break
if ng:
    break

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
H,W = map(int,input().split())
s = [list(input()) for i in range(W)]
w = [1,0,0,-1]
h = [0,1,-1,0]
for i in range(H):
    for j in range(W):
        if s[i][j] == '#':
            flag = False
            for k in range(4):
                if j+w[k] >= 0 and j+w[k] < H and i+h[k] >= 0 and i+h[k] < W:
                    if s[i+h[k]][j+w[k]] == '#':
                        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 i in range(W)]
for i in range(H):
    for j in range(W):
        if s[i][j] == '#':
            if i == 0:
                if j == 0:
                    if s[i+1][j] != '#' and s[i][j+1] != '#':
                        print('No')
                        exit()
                elif j == W-1:
                    if s[i+1][j] != '#' and s[i][j-1] != '#':
                        print('No')
                        exit()
                else:
                    if s[i+1][j] != '#' and s[i][j-1] != '#' and s[i][j+1] != '#':
                        print('No')
                        exit()
            elif i == H-1:
                if j == 0:
                    if s[i-1][j] != '#' and s[i][j+1] != '#':
                        print('No')
                        exit()
                elif j == W-1:
                    if s[i-1][j] != '#' and s[i][j-1] != '#':
                        print('No')
                        exit()
                else:
                    if s[i-1][j] != '#' and s[i][j-1] != '#' and s[i][j+1] != '#':
                        print('No')
                        exit()
            else:
                if j == 0:
                    if s[i-1][j] != '#' and s[i][j+1] != '#' and s[i+1][j] != '#':
                        print('No')
                        exit()
                elif j == W-1:
                    if s[i-1][j] != '#' and s[i][j-1] != '#' and s[i+1][j] != '#':
                        print('No')
                        exit()
                else:
                    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:
n,m = map(int,input().split())

s=[list(str(input())) for _ in range(n)]

di=[1,-1,0,0]
dj=[0,0,1,-1]
for i in range(1,n-1):
    for j in range(1,m-1):
        if s[i][j]=='#':
            found=False
            for k in range(4):
                i2=i+di[k]
                j2=j+dj[k]
                if 0<=i2 and i2<n and 0<=j2 and j2<m:
                    if s[i2][j2]=='#':
                        found=True
            if not found:
                print('No')
                sys.exit()

print('Yes')

Submission status: Runtime Error

Solution code:
n,m = map(int,input().split())

s=[list(str(input())) for _ in range(n)]

ans=True
di=[1,-1,0,0]
dj=[0,0,1,-1]
for i in range(n):
    for j in range(m):
        if s[i][j]=='#':
            found=False
            for k in range(4):
                i2=i+di[k]
                j2=j+dj[k]
                if 0<=i2 and i2<n and 0<=j2 and j2<m:
                    if s[i2][j2]=='#':
                        found=True
            if not found:
                print('No')
                sys.exit()

print('Yes')

Submission status: Runtime Error

Solution code:
H, W = map(int, input().split())
S = [input().split() for i in range(H)]
F = [[0]*(W+2) for i in range(H+2)]
D = [(-1,0), (0,1), (0, -1), (1, 0)]

for i in range(H):
    for j in range(W):
        if S[i][j] == '#':
            for d in D:
                F[i+1+d][j+1+d] == '#'

print('Yes' if F[1:H+1][1:W+1] == S else 'No')

Submission status: Runtime Error

Solution code:
import sys

a = sys.stdin.readline().split(' ')
data = sys.stdin.readlines()

S = int(a[0])
H = int(a[1])

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

ans = 'Yes'
if S == 1 and H == 1:
    continue
else:
    for i in range(S):
        for j in range(H):
            if data[i][j] == '.':
                continue
            else:
                for k in range(4):
                    x = j + dx[k]
                    y = i + dy[k]
                    if x < 0 or y < 0 or x >= H or y >= S:
                        continue
                    else:
                        if data[y][x] == "#":
                            ans = 'Yes'
                            break
                        else:
                            ans = 'No'
                            continue

print(ans)

Submission status: Runtime Error

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

for i in range(H):
  S = list(input())
  arr.append(S)
  
ck = 0
for i in range(H):
  for j in range(W):
    if arr[i][j] == "#":
      if i != 0:
        a = arr[i-1][j]
      else:
        a = "."
      if i != H-1:
        b = arr[i+1][j]
      else:
        b = "."
      if j != 0:
        c = arr[i][j-1]
      else:
        c = "."
      if j != W-1:
        d = arr[i][j+1]
      else:
        d = "."
    if a == "." and b == "." and c == "." and d == ".":
      ck = 1
      
if ck == 1:
  print("No")
else:
  print("Yes")

Submission status: Runtime Error

Solution code:
def resolve():
    # 整数 1 つ
    # n = int(input())
    # 整数複数個
    h, w = map(int, input().split())
    # 整数 N 個 (改行区切り)
    S = [list(input()) for i in range(h)]
    # 整数 N 個 (スペース区切り)
    # N = list(map(int, input().split()))
    # 整数 (縦 H 横 W の行列)
    # A = [list(map(int, input().split())) for i in range(H)]

    flag = True
    for i in range(h):
        for j in range(w):
            if S[i][j] == ".":
                continue
            else:
                if S[i][j-1] == "." and S[i][j+1] == "." and S[i-1][j] == "." and S[i+1][j] == ".":
                    flag = False
                    break
        if flag == False
            break

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


resolve()

Submission status: Runtime Error

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

def search(i, j):
  for dh, dw in [[1, 0], [-1, 0], [0, 1], [0, -1]]:
    x = max(0, min(i + dw, w-1))
    y = max(0, min(j + dh, h-1))
    if i == y and j == x: continue 
    if maps[x][y] == "#":
      return True
  return False

flag = True
for i in range(h):
  for j in range(w):
    if maps[i][j] == "#" and not search(i, j):
        flag = False
        break
        
print("Yes" if flag else "No")

Submission status: Runtime Error

Solution code:
import sys
H, W = map(int, input().split())
s = [input() for i in range(H)]
S = []
S.append('.' * (W + 2))
for i in range(W):
    S.append('.' + s[i] + '.')
S.append('.' * (W + 2))
for i in range(1, H + 1):
    for j in range(1, W + 1):
        if S[i][j] == '#':
            if S[i + 1][j] == '#' or S[i - 1][j] == '#' or S[i][j + 1] == '#' or S[i][j - 1] == '#':
                continue
            else:
                print('No')
                sys.exit()
print('Yes')

Submission status: Runtime Error

Solution code:
import numpy as np


h, w = map(int, input().split())
tmp = []
for i in range(h):
    s = list(input())
    tmp.append(s)
cam = np.full((h+2, w+2), '.')
for i in range(h):
    cam[i+1][1:w+1] = tmp[i]

t = True
for i in range(h):
    for j in range(w):
        if cam[i+1][j+1] == '#':
            if cam[i+2][j+1] == '.' and cam[i+1][j+2] == '.' and cam[i][j+1] == '.' and cam[i+1][j] == '.':
                t = False
                break
    if not t:
        break
if t:
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

Solution code:
import sys

sys.setrecursionlimit(200000000)

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


str_list.append(["."]*w)
str_list.insert(0,["."]*w)
for i in range(h+2):
    str_list[i].append(".")
    str_list[i].insert(0,".")




for i in range(h):
    for j in range(w):
        if str_list[i+1][j+1] == ".":
            continue
        
        for a,b in enumerate([1,2]):
            write = 0

            if str_list[i+a][j+b]=="#":
                write = 1
                break
            
            if str_list[i+b][j+a]=="#":
                write = 1
                break
                

        
        if write == 0:
            break
    else:
        continue
    break
        

            

if write == 1:
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(4100000)

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


str_list.append(["."]*w)
str_list.insert(0,["."]*w)
for i in range(h+2):
    str_list[i].append(".")
    str_list[i].insert(0,".")




for i in range(h):
    for j in range(w):
        if str_list[i+1][j+1] == ".":
            continue
        
        for a,b in enumerate([1,2]):
            write = 0

            if str_list[i+a][j+b]=="#":
                write = 1
                break
            
            if str_list[i+b][j+a]=="#":
                write = 1
                break
                

        
        if write == 0:
            break
    else:
        continue
    break
        

            

if write == 1:
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
import sys

sys.setrecursionlimit(10**8)

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


str_list.append(["."]*w)
str_list.insert(0,["."]*w)
for i in range(h+2):
    str_list[i].append(".")
    str_list[i].insert(0,".")




for i in range(h):
    for j in range(w):
        if str_list[i+1][j+1] == ".":
            continue
        
        for a,b in enumerate([1,2]):
            write = 0

            if str_list[i+a][j+b]=="#":
                write = 1
                break
            
            if str_list[i+b][j+a]=="#":
                write = 1
                break
                

        
        if write == 0:
            break
    else:
        continue
    break
        

            

if write == 1:
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
import sys

sys.setrecursionlimit(10**6)

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


str_list.append(["."]*w)
str_list.insert(0,["."]*w)
for i in range(h+2):
    str_list[i].append(".")
    str_list[i].insert(0,".")




for i in range(h):
    for j in range(w):
        if str_list[i+1][j+1] == ".":
            continue
        
        for a,b in enumerate([1,2]):
            write = 0

            if str_list[i+a][j+b]=="#":
                write = 1
                break
            
            if str_list[i+b][j+a]=="#":
                write = 1
                break
                

        
        if write == 0:
            break
    else:
        continue
    break
        

            

if write == 1:
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

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


str_list.append(["."]*w)
str_list.insert(0,["."]*w)
for i in range(h+2):
    str_list[i].append(".")
    str_list[i].insert(0,".")




for i in range(h):
    for j in range(w):
        if str_list[i+1][j+1] == ".":
            continue
        
        for a,b in enumerate([1,2]):
            write = 0

            if str_list[i+a][j+b]=="#":
                write = 1
                break
            
            if str_list[i+b][j+a]=="#":
                write = 1
                break
                

        
        if write == 0:
            break
    else:
        continue
    break
        

            

if write == 1:
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

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

exist_sharp = False
for cell in cells:
    if '#' in cell:
        exist_sharp = True
if not exist_sharp:
    print("No")
    exit()
 
ans = True
for i in range(1,len(cells)-1):
    for j in range(1,len(cells)-1):
        if cells[i][j] == '#':
            if cells[i-1][j] != '#' and cells[i+1][j] != '#' and cells[i][j-1] != '#' and cells[i][j+1] != '#':
                ans = False

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

Submission status: Runtime Error

Solution code:
h, w = map(int, input().split())
s = [input() for _ in range(h)]
dx = [-1, 0, 0, 1]
dy = [0, -1, 1, 0]
for i in range(h):
    for j in range(w):
        if s[i][j] == '#':
            flag = 0
            for k in range(4):
                nx = i + dx[k]
                ny = j + dy[k]
                if nx < 0 or w <= nx:
                    continue
                if ny < 0 or h <= ny:
                    continue
                if s[nx][ny] == '#':
                    flag = 1
            if flag == 0:
                print('No')
                exit()
else:
    print('Yes')

Submission status: Runtime Error

Solution code:
h, w = map(int, input().split())
s = [input() for _ in range(w)]
for i in range(h):
    for j in range(w):
        if s[i][j] == '#':
            flag = 0
            L = []
            if i == 0 and j == 0:
                L.extend([(0, 1), (1, 0)])
            elif i == 0 and j == w - 1:
                L.extend([(-1, 0), (1, 0)])
            elif i == h - 1 and j == 0:
                L.extend([(-1, 0), (0, 1)])
            elif i == h - 1 and j == w - 1:
                L.extend([(-1, 0), (0, -1)])
            elif i == 0:
                L.extend([(1, 0), (0, -1), (0, 1)])
            elif i == h - 1:
                L.extend([(-1, 0), (0, 1), (0, -1)])
            elif j == 0:
                L.extend([(-1, 0), (1, 0), (0, 1)])
            elif j == w - 1:
                L.extend([(-1, 0), (1, 0), (0, -1)])
            else:
                L.extend([(-1, 0), (1, 0), (0, -1), (0, 1)])
            
            for dx, dy in L:
                    if s[i + dx][j + dy] == '#':
                        flag = 1
            if flag == 0:
                print('No')
                exit()
else:
    print('Yes')

Submission status: Runtime Error

Solution code:
h, w = map(int, input().split())
s = [input() for _ in range(w)]
for i in range(h):
    for j in range(w):
        if s[i][j] == '#':
            flag = 0
            L = []
            if i == 0 and j == 0:
                L.extend([(0, 1), (1, 0)])
            elif i == 0 and j == w - 1:
                L.extend([(-1, 0), (1, 0)])
            elif i == h - 1 and j == 0:
                L.extend([(1, 0), (0, 1)])
            elif i == h - 1 and j == w - 1:
                L.extend([(-1, 0), (0, -1)])
            elif i == 0:
                L.extend([(1, 0), (0, -1), (0, 1)])
            elif i == h - 1:
                L.extend([(-1, 0), (0, 1), (0, -1)])
            elif j == 0:
                L.extend([(-1, 0), (1, 0), (0, 1)])
            elif j == w - 1:
                L.extend([(-1, 0), (1, 0), (0, -1)])
            else:
                L.extend([(-1, 0), (1, 0), (0, -1), (0, 1)])
            
            for dx, dy in L:
                    if s[i + dx][j + dy] == '#':
                        flag = 1
            if flag == 0:
                print('No')
                exit()
else:
    print('Yes')

Submission status: Runtime Error

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

ans = True
for i in range(1,len(cells)-1):
    for j in range(1,len(cells)-1):
        if cells[i][j] == '#':
            if cells[i-1][j] != '#' and cells[i+1][j] != '#' and cells[i][j-1] != '#' and cells[i][j+1] != '#':
                ans = False

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

Submission status: Runtime Error

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

for i in range(1,len(cells)-1):
    for j in range(1,len(cells)-1):
        if cells[i][j] == '#':
            if cells[i-1][j] == '#':
                pass
            elif cells[i+1][j] == '#':
                pass
            elif cells[i][j-1] == '#':
                pass
            elif cells[i][j+1] == '#':
                pass
            else:
                print("No")
                exit()
print("Yes")

Submission status: Runtime Error

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

is_ok = True
for i in range(1,len(cells)-1):
    for j in range(1,len(cells)-1):
        if cells[i][j] == '#':
            if cells[i-1][j] == '#':
                is_ok = True
            elif cells[i+1][j] == '#':
                is_ok = True
            elif cells[i][j-1] == '#':
                is_ok = True
            elif cells[i][j+1] == '#':
                is_ok = True
            else:
                is_ok = False
        if not is_ok:
            print("No")
            exit()
print("Yes")

Submission status: Runtime Error

Solution code:
import math
import string
import collections
from collections import Counter


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]
h, w = map(int, input().split())
tmp = [None]*h
for i in range(w):
    tmp[i] = input()
# print(tmp)
for i in range(h):
    for j in range(w):
        if tmp[i][j] == '#':
            if (i != 0 and tmp[i-1][j] == '#')or(i != h-1 and tmp[i+1][j] == '#') or(j != 0 and tmp[i][j-1] == '#')or(j != w-1 and tmp[i][j+1] == '#'):
                continue

            print('No')
            exit()
print('Yes')

Submission status: Runtime Error

Solution code:
import math
import string
import collections
from collections import Counter


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]
h, w = map(int, input().split())
tmp = [None]*h
for i in range(w):
    tmp[i] = input()
# print(tmp)
for i in range(h-1):
    for j in range(w-1):
        if tmp[i][j] == '#':
            if (i != 0 and tmp[i-1][j] == '#')or(i+1 < h and tmp[i+1][j] == '#') or(j != 0 and tmp[i][j-1] == '#')or(j+1 < w and tmp[i][j+1] == '#'):
                continue

            print('No')
            exit()
print('Yes')

Submission status: Runtime Error

Solution code:
import math
import string
import collections
from collections import Counter


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]
h, w = map(int, input().split())
tmp = [None]*h
for i in range(w):
    tmp[i] = input()
# print(tmp)
for i in range(h):
    for j in range(w):
        if tmp[i][j] == '#':
            if (i != 0 and tmp[i-1][j] == '#')or(i+1 < h and tmp[i+1][j] == '#') or(j != 0 and tmp[i][j-1] == '#')or(j+1 < w and tmp[i][j+1] == '#'):
                continue
            else:
                print('No')
                exit()
print('Yes')

Submission status: Runtime Error

Solution code:
import math
import string
import collections
from collections import Counter


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]
h, w = map(int, input().split())
tmp = [None]*h
for i in range(w):
    tmp[i] = input()
# print(tmp)
for i in range(h):
    for j in range(w):
        if tmp[i][j] == '#':
            if (i != 0 and tmp[i-1][j] == '#')or(i != h-1 and tmp[i+1][j] == '#') or(j != 0 and tmp[i][j-1] == '#')or(j != w-1 and tmp[i][j+1] == '#'):
                continue
            else:
                print('No')
                exit()
print('Yes')

Submission status: Runtime Error

Solution code:
import math
import string
import collections
from collections import Counter


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]
h, w = map(int, input().split())
tmp = [None]*h
for i in range(w):
    tmp[i] = input()
# print(tmp)
for i in range(h):
    for j in range(w):
        if tmp[i][j] == '#':
            if (i-1 >= 0 and tmp[i-1][j] == '#')or(i < h-1 and tmp[i+1][j] == '#') or(j-1 >= 0 and tmp[i][j-1] == '#')or(j < w-1 and tmp[i][j+1] == '#'):
                continue
            else:
                print('No')
                exit()
print('Yes')

Submission status: Runtime Error

Solution code:
import math
import string
import collections
from collections import Counter


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]
h, w = map(int, input().split())
tmp = [None]*h
for i in range(w):
    tmp[i] = input()
# print(tmp)
for i in range(h):
    for j in range(w):
        if tmp[i][j] == '#':
            if (i-1 >= 0 and tmp[i-1][j] == '#')or(i+1 <= h-1 and tmp[i+1][j] == '#') or(j-1 >= 0 and tmp[i][j-1] == '#')or(j+1 <= w-1 and tmp[i][j+1] == '#'):
                continue
            else:
                print('No')
                exit()
print('Yes')

Submission status: Runtime Error

Solution code:
import math
import string
import collections
from collections import Counter


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]
h, w = map(int, input().split())
tmp = [None]*h
for i in range(w):
    tmp[i] = input()
# print(tmp)
for i in range(h):
    for j in range(w):
        if tmp[i][j] == '#':
            if (i-1 >= 0 and tmp[i-1][j] == '#')or(i+1 <= h-1 and tmp[i+1][j] == '#') or(tmp[i][j-1] == '#' and j-1 >= 0)or(j+1 <= w-1 and tmp[i][j+1] == '#'):
                continue
            else:
                print('No')
                exit()
print('Yes')

Submission status: Runtime Error

Solution code:
import math
import string
import collections
from collections import Counter


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]
h, w = map(int, input().split())
tmp = [None]*h
for i in range(w):
    tmp[i] = input()
# print(tmp)
for i in range(h):
    for j in range(w):
        if tmp[i][j] == '#':
            if (tmp[i-1][j] == '#' and i-1 >= 0)or(tmp[i+1][j] == '#' and i+1 <= h-1) or(tmp[i][j-1] == '#' and j-1 >= 0)or(tmp[i][j+1] == '#' and j+1 <= w-1):
                continue
            else:
                print('No')
                exit()
print('Yes')