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)]
s = s + [['.']+list(input())+[','] for _ in range(w)]
s = s + [['.']*(w+2)]
a = True
for i in range(1, w+1):
    for j in range(1, w+1):
        if s[i][j] == '#':
           up = s[i-1][j]
           left = s[i][j-1]
           right = s[i][j+1]
           down = s[i+1][j]
           if up == '.' and left == '.' and right == '.' and down == '.':
               a = False
if a ==True:
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
h,w=map(int,input().split())
L=[list(input()) for i in range(h)]
for i in range(h):
    for j in range(w):
        if L[i][j]=='#':
            if L[i][max(i-1,0)]!='#' and L[i][min(i+1,w-1)]!='#' and L[max(i-1,0)][j]!='#' and L[min(i+1,h-1)][j]!='#':
                print('No')
                exit()
print('Yes')

Submission status: Runtime Error

Solution code:
h,w=map(int,input().split())
L=[list(input()) for i in range(h)]
for i in range(h):
    for j in range(w):
        if L[i][j]=='#':
            if L[i][max(i-1,0)]!='#' and L[i][min(i+1,w-1)]!='#' and L[max(i-1,0)][j]!='#' and L[min(i+1,h-1)][i]!='#':
                print('No')
                exit()
print('Yes')

Submission status: Runtime Error

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

s.insert(0, ['.']*W)
s.append(['.']*W)
for i in range(W+2):
    s[i].insert(0, '.')
    s[i].append('.')
#print(s)

if H == W == 1:
    print('Yes')
else:
    flag = False
    for i in range(1, H+1):
        for j in range(1, W+1):
            if s[i][j] == '#':
                if s[i][j-1] == s[i][j+1] == s[i-1][j] == s[i+1][j] == '.':
                    print('No')
                    flag = True
                    break
        if flag:
            break
    else:
        print('Yes')

Submission status: Runtime Error

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

s.insert(0, ['.']*W)
s.append(['.']*W)
for i in range(W+2):
    s[i].insert(0, '.')
    s[i].append('.')
#print(s)

flag = False
for i in range(1, H+1):
    for j in range(1, W+1):
        if s[i][j] == '#':
            if s[i][j-1] == s[i][j+1] == s[i-1][j] == s[i+1][j] == '.':
                print('No')
                flag = True
                break
    if flag:
        break
else:
    print('Yes')

Submission status: Runtime Error

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

s = []
for i in range(H):
    ss = input()
    s.append(ss)

shift = [[1,0],[-1,0],[0,1],[0,-1]]

for j in range(H):
    for i in range(W):
        if s[j][i] == "#":
            flag = False
            for dx, dy in shift:
                nx = i + dx
                ny = j + dy
                if nx >= 0 and nx < W and ny >= 0 and ny < H:
                    if s[ny][nx] == "#":
                        flag = True
            if not flag:
                exit(0)

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

Submission status: Runtime Error

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

s = []
for i in range(H):
    ss = input()
    s.append(ss)

shift = [[1,0],[-1,0],[0,1],[0,-1]]

for j in range(H):
    for i in range(W):
        if s[j][i] == "#":
            flag = False
            for dx, dy in shift:
                nx = i + dx
                ny = j + dy
                if nx >= 0 and nx < W and ny >= 0 and ny < H:
                    if s[ny][nx] == "#":
                        flag = True
            if not flag:
                break

if flag:
    print("Yes")
else:
    print("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(1,w+1):
    if i == 0:
      if s[i][j]=="#" and s[i][j+1]=="." and s[i][j-1]=="." and s[i+1][j]==".":
        print("No")
        exit()
    elif i == h-1:
      if s[i][j]=="#" and s[i][j+1]=="." and s[i][j-1]=="." and s[i+1][j]==".":
        print("No")
        exit()
    else:
      if s[i][j]=="#" and s[i][j+1]=="." and s[i][j-1]=="." and s[i+1][j]=="." and s[i-1][j]==".":
        print("No")
        exit()
        
print("Yes")

Submission status: Runtime Error

Solution code:

def main():
	line = input()
	vector = [int(x) for x in line.split()]
	n = vector[0]
	m = vector[1]
	matrix = [ [] for i in range(m)]
	for i in range(n):
		line = input()
		for c in line:
			matrix[i].append(c)
			
	ok = "Yes"
	for i in range(n):
		for j in range(m):
			okUp = 0
			okLeft = 0
			okRight = 0
			okDown = 0
			if matrix[i][j] == '#':
				if i > 0:
					if matrix[i-1][j] == '#':
						okUp = 1
				if j > 0:
					if matrix[i][j - 1] == '#':
						okLeft = 1
				if i < n - 1:
					if matrix[i+1][j] == '#':
						okDown = 1
				if j < m - 1:
					if matrix[i][j + 1] == '#':
						okRight = 1
				if okRight == 0 and okDown == 0 and okLeft == 0 and okUp == 0:
					print("No")
					return
	
	print("Yes")
 
 
 
if __name__ == "__main__":
	main()

Submission status: Runtime Error

Solution code:

def main():
	line = input()
	vector = [int(x) for x in line.split()]
	n = vector[0]
	m = vector[1]
	matrix = [ [] for i in range(m)]
	for i in range(n):
		line = input()
		for c in line:
			matrix[i].append(c)
			
	ok = "Yes"
	for i in range(n):
		for j in range(m):
			okUp = 0
			okLeft = 0
			okRight = 0
			okDown = 0
			if matrix[i][j] == '#':
				if i > 0:
					if matrix[i-1][j] == '#':
						okUp = 1
				if j > 0:
					if matrix[i][j - 1] == '#':
						okLeft = 1
				if i < n - 1:
					if matrix[i+1][j] == '#':
						okDown = 1
				if j < n - 1:
					if matrix[i][j + 1] == '#':
						okRight = 1
				if okRight == 0 and okDown == 0 and okLeft == 0 and okUp == 0:
					print("No")
					return
	
	print("Yes")
 
 
 
if __name__ == "__main__":
	main()

Submission status: Runtime Error

Solution code:
if __name__ == "__main__":
    H, W = map(int, input().split())
    s = []
    for i in range(H):
        s.append(input())
    
    """
    # black
    . white
    """
    
    black = "#"
    white = "."
    
    ans = "Yes"
    break_flag = False
    for i in range(H):
        for j in range(W):
            if s[i][j] == black:
                above = False
                under = False
                left = False
                right = False
                
                if 0 < i:
                    above = (s[i - 1][j] == black)
                if i < W - 1:
                    under = (s[i + 1][j] == black)
                if 0 < j:
                    left = (s[i][j - 1] == black)
                if j < H - 1:
                    right = (s[i][j + 1] == black)
                
                if not (above or under or left or right):
                    break_flag = True
                    ans = "No"
                    #print(i, j)
                    #print(above, under, left, right)
            
            if break_flag:
                break
            
        if break_flag:
            break
    
    print(ans)

Submission status: Runtime Error

Solution code:
if __name__ == "__main__":
    H, W = map(int, input().split())
    s = []
    for i in range(H):
        s.append(input())
    
    """
    # black
    . white
    """
    
    black = "#"
    white = "."
    
    ans = "Yes"
    break_flag = False
    for i in range(H):
        for j in range(W):
            if s[i][j] == black:
                above = False
                under = False
                left = False
                right = False
                
                if 0 < i:
                    above = (s[i - 1][j] == black)
                if i < W - 1:
                    under = (s[i + 1][j] == black)
                if 0 < j:
                    left = (s[i][j - 1] == black)
                if j < W - 1:
                    right = (s[i][j + 1] == black)
                
                if not (above or under or left or right):
                    break_flag = True
                    ans = "No"
                    #print(i, j)
                    #print(above, under, left, right)
            
            if break_flag:
                break
            
        if break_flag:
            break
    
    print(ans)

Submission status: Runtime Error

Solution code:
import sys
h,w=map(int,input().split())
s=[]
for num in range(h):
  s.append(list(map(int,input().split())))
if w==1:
  if h==1:
    if s[0][0]=='#':
      print('No')
      sys.exit()
  if h==2:
    if (s[0][0]=='#' and s[1][0]=='.') or (s[0][0]=='.' and s[1][0]=='#'):
      print('No')
      sys.exit()  
  else:
    for i in range(h-2):
      if (s[i][0]=='.' and s[i+1][0]=='#' and s[i+2][0]=='.'):
        print('No')
        sys.exit()
if w==2:
  if h==1:
    if (s[0][0]=='.' and s[0][1]=='#') or (s[0][0]=='#' and s[0][1]=='.'):
      print('No')
      sys.exit()  
  else:
    for i in range(h-1):
      if s[i][0]=='.' and s[i][1]=='#':
        if s[i+1][1]=='.':
          print('No')
          sys.exit()
      if s[i][0]=='#' and s[i][1]=='.':
        if s[i+1][0]=='.':
          print('No')
          sys.exit()     
for i in range(h):
  for j in range(w-2):
    if s[i][j]=='.' and s[i][j+1]=='#' and s[i][j+2]=='.':
      if s[i][j+1]=='.':
        print('No')
        sys.exit()
    if s[i][0]=='#' and s[i][1]=='.':
      if s[min(h-1,i+1)][0]=='.':
        print('No')
        sys.exit()
    if s[i][w-2]=='.' and s[i][w-1]=='#':
      if s[min(h-1,i+1)][w-1]=='.':
        print('No')
        sys.exit()
print('Yes')

Submission status: Runtime Error

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

dx=[0,1,0,-1]
dy=[1,0,-1,0]
for i in range(h):
    for j in range(w):
        if s[i][j]=='#':
            ans=False
            for k in range(4):
                nx = i+dx[k]
                ny = j+dy[k]
                if nx>=0 and nx <h and ny>=0 and ny<w and s[nx][ny]=='#':
                    ans = True
                    break
            if ans ==False:
                print('No')
                exit()
if ans:
    print('Yes')

Submission status: Runtime Error

Solution code:
H, W = map(int,input().split())
s = [list(input()) for _ in range(H)]
for i in range(H):
    s[i] = [0] + s[i] + [0]
s = [[0]*W] + s + [[0]*W]
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][j-1] == '#' or s[i][j+1] == '#' or s[i+1][j] == '#':
                continue
            else:
                print('No')
                exit()
print('Yes')

Submission status: Runtime Error

Solution code:
import sys
h,w=map(int,input().split())
s=[]
for num in range(h):
  s.append(list(map(int,input().split())))
if w==1:
  if h==1:
    if s[0]=='#':
      print('No')
      sys.exit()
  else:
    for i in range(h-1):
      if (s[i][0]=='#' and s[i+1][0]=='.') or (s[i][0]=='.' and s[i+1][0]=='#'):
        print('No')
        sys.exit()
if w==2:
  if h==1:
    if (s[0][0]=='.' and s[0][1]=='#') or (s[0][0]=='#' and s[0][1]=='.'):
      print('No')
      sys.exit()  
  else:
    for i in range(h-1):
      if s[i][0]=='.' and s[i][1]=='#':
        if s[i+1][1]=='.':
          print('No')
          sys.exit()
      if s[i][0]=='#' and s[i][1]=='.':
        if s[i+1][0]=='.':
          print('No')
          sys.exit()     
for i in range(h):
  for j in range(w-2):
    if s[i][j]=='.' and s[i][j+1]=='#' and s[i][j+2]=='.':
      if s[i][j+1]=='.':
        print('No')
        sys.exit()
    if s[i][0]=='#' and s[i][1]=='.':
      if s[min(h-1,i+1)][0]=='.':
        print('No')
        sys.exit()
    if s[i][w-2]=='.' and s[i][w-1]=='#':
      if s[min(h-1,i+1)][w-1]=='.':
        print('No')
        sys.exit()
print('Yes')

Submission status: Runtime Error

Solution code:
import sys
h,w=map(int,input().split())
s=[]
for num in range(h):
  s.append(list(map(int,input().split())))
if w==1 and h==1:
  if s[0]=='#':
    print('No')
    sys.exit()
if w==2 and h==1:
  if (s[0][0]=='.' and s[0][1]=='#') or (s[0][0]=='#' and s[0][1]=='.'):
    print('No')
    sys.exit()  
for i in range(h):
  for j in range(w-2):
    if s[i][j]=='.' and s[i][j+1]=='#' and s[i][j+2]=='.':
      if s[i][j+1]=='.':
        print('No')
        sys.exit()
    if s[i][0]=='#' and s[i][1]=='.':
      if s[min(h-1,i+1)][0]=='.':
        print('No')
        sys.exit()
    if s[i][w-2]=='.' and s[i][w-1]=='#':
      if s[min(h-1,i+1)][w-1]=='.':
        print('No')
        sys.exit()
print('Yes')

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
H, W = map(int, input().split())
S = ['.'*(W+2)] + ['.' + input() + '.' for _ in range(H)] + ['.'*(W+2)]
for i in range(1, H+1):
  for j in range(1, W+1):
    if S[i][j] == '#':
      for x, y in [(-1, 0), (1, 0), (0, -1), (0, 1)]:
        if S[i+x][j+y] == '#':
          break
      else:
        print('No')
        return
else:
  print('Yes')

Submission status: Runtime Error

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

temp = "0" * (h+2)

s = [temp]

for i in range(h):
    s.append("0" + input() + "0")

s.append(temp)

# print(s)

for i in range(h+2):
    for j in range(w+2):
        flag = False
        if s[i][j] == "#":
            if s[i-1][j] == "#" or s[i+1][j] == "#" or s[i][j+1] == "#" or s[i][j-1] == "#":
                flag = True
            if not flag:
                print("No")
                exit()

print("Yes")

Submission status: Runtime Error

Solution code:
import sys
import math
from fractions import gcd
# import queue
# from collections import Counter
# from itertools import accumulate
# from functools import reduce

def lcm(a, b):
    return a * b // gcd(a, b)

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

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

big_prime = 1000000007

"""
# 標準入力取得
## 文字列
 =  sys.stdin.readline().rstrip()
 =  list(sys.stdin.readline().rstrip())

## 数値
 =  int(sys.stdin.readline())
 =  map(int, sys.stdin.readline().split())
 =  list(map(int, sys.stdin.readline().split()))
 =  [list(map(int,list(sys.stdin.readline().split()))) for i in range(N)]
"""
# 塗ることができないケースを考察してみる
# 愚直にシミュレーションしてもいけるかもしれない

H, W =  map(int, sys.stdin.readline().split())
L =  [list(list(sys.stdin.readline().rstrip())) for i in range(W)]

PL = [["0"] + l + ["0"] for l in L]

t = ["0"] * (W + 2)

PL.insert(0, t)
PL.append(t)

for i in range(1, H + 1):
    for j in range(1, W + 1):
        if PL[i][j] == "#":
            if PL[i][j - 1] == "#" or PL[i - 1][j] == "#" or PL[i][j + 1] == "#" or PL[i + 1][j] == "#":
                continue
            else:
                print("No")
                exit()

print("Yes")

Submission status: Runtime Error

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

Submission status: Runtime Error

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

for i in range(h):
  for j in range(w):
    if s[i][j] == '#':
      if j != w and s[i][j + 1] == '#':
        continue
      elif  j != 0 and s[i][j - 1] == '#':
        continue
      elif i != h and s[i + 1][j] == '#':
        continue
      elif i != 0 and s[i - 1][j] == '#':
        continue
      else:
        print('No')
        sys.exit()
print('Yes')

Submission status: Runtime Error

Solution code:
h, w = list(map(int, input().split()))
s = [list(input()) for i in range(h)]
dir = [[-1, 0], [1, 0], [0, -1], [0, 1]]
for y in range(h):
    for x in range(w):
        can_put = True
        if s[y][x] == "#":
            for dx, dy in dir:
                cx = x + dx
                cy = y + dy
                if x >= 0 and x < w and y >= 0 and y < h and s[cy][cx] == "#":
                    can_put = True
                    break
            else:
                can_put = False
        if can_put == False:
            break
if can_put == True:
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
h, w = list(map(int, input().split()))
s = [list(input()) for i in range(h)]
dir = [[-1, 0], [1, 0], [0, -1], [0, 1]]
for y in range(h):
    for x in range(w):
        if s[y][x] == "#":
            for dx, dy in dir:
                cx = x + dx
                cy = y + dy
                if x >= 0 and x < w and y >= 0 and y < h and s[cy][cx] == "#":
                    break
            else:
                break
    else:
        continue
    print("No")
    break
else:
    print("Yes")

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]"):

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

    for i in range(H):
        for j in range(W):
            if(s[i][j] == '#'):
                f = False
                for k in range(4):
                    iy = i+dy[k]
                    ix = j+dx[k]
                    if(0 <= iy < H and 0 <= ix < W and s[iy][ix] == '#'):
                        f = True
                if(f == False):
                    print(NO)
                    exit()
                
    print(YES)

    return


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

if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

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


def solve(H: int, W: int, s: "List[str]"):

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

    for i in range(H):
        for j in range(W):
            if(s[i][j] == '#'):
                f = False
                for k in range(4):
                    iy = i+dy[k]
                    ix = j+dx[k]
                    if(0 <= iy < H and 0 <= ix < W and s[iy][ix] == '#'):
                        f = True
                if(not f):
                    print(NO)
                    exit()
                
    print(YES)

    return


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

if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

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


def solve(H: int, W: int, s: "List[str]"):

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

    for i in range(H):
        for j in range(W):
            if(s[i][j] == '#'):
                f = False
                for k in range(4):
                    iy = i+dy[k]
                    ix = j+dx[k]
                    if(0 <= iy < H and 0 <= ix < W and s[iyw][ix] == '#'):
                        f = True
                if(not f):
                    print(NO)
                    exit()
                
    print(YES)

    return


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

if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

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


def solve(H: int, W: int, s: "List[str]"):

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

    for i in range(H):
        for j in range(W):
            if(s[i][j] == '#'):
                f = False
                for k in range(4):
                    iy = i+dx[k]
                    ix = j+dy[k]
                    if(0 <= iy < H and 0 <= ix < W and s[iy][ix] == '#'):
                        f = True
                if(not f):
                    print(NO)
                    exit()
                
    print(YES)

    return


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

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import sys
input=sys.stdin.readline

H,W=map(int, input().split())
C = [[] for i in range(H)]

for h in range(H):
    C[h] = list(input().strip())
#print(*C)

for h in range(H):
    for w in range(W):
        if C[w][h] == "#":
            if h == 0 or (h>0 and C[h-1][w] == "."):
                if w == 0 or (w>0 and C[h][w-1] == "."):
                    if w == W-1 or (w<W-1 and C[h][w+1] == "."):
                        if h == H-1 or (h<H-1 and C[h+1][w] == "."):
                            print("No")
                            exit()
print("Yes")

Submission status: Runtime Error

Solution code:
import sys
input=sys.stdin.readline

H,W=map(int, input().split())
C = [[] for i in range(H)]

for h in range(H):
    C[h] = list(input().strip())
#print(*C)

for h in range(H):
    for w in range(W):
        if C[w][h] == "#":
            if h == 0 or (h>0 and C[h-1][w] == "."):
                if w == 0 or (w>0 and C[h][w-1] == "."):
                    if w == W-1 or (w+1<W and C[h][w+1] == "."):
                        if h == H-1 or (h+1<h and C[h+1][w] == "."):
                            print("No")
                            exit()
print("Yes")

Submission status: Runtime Error

Solution code:
h,w = map(int,input())
L = [input() for i in range(h)]
ans = "ahe"
if L[0][0]=="#" and (L[0][1]=="." and L[1][0]=="."):
    ans="No"
elif L[0][w]=="#" and (L[0][w-1]=="." and L[1][w]=="."):
    ans="No"
elif L[h][0]=="#" and (L[h][1]=="." and L[h-1][0]=="."):
    ans="No"
elif L[h][w]=="#" and (L[h][w-1]=="." and L[h-1][w]=="."):
    ans="No"
for i in range(1,w):
    if L[0][i]=="#" and (L[0][i+1]=="." and L[1][i] =="." and L[1][i-1]):
        ans="No"
for i in range(1,w):
    if L[h][i]=="#" and (L[h][i+1]=="." and L[h-1][i] =="." and L[h][i-1]):
        ans="No"
for i in range(1,h):
    if L[i][0]=="#" and (L[i][1]=="." and L[i+1][0]=="." and L[i-1][0]=="."):
        ans="No"
for i in range(1,h):
    if L[i][w]=="#" and (L[i][w-1]=="." and L[i+1][w]=="." and L[i-1][w]==".")
for i in range(1,h):
    for j in range(1,w):
        if L[i][j]=="#" and (L[i+1][j]=="." and L[i-1][j]=="." and L[i][j+1]=="." and L[i][j-1]=="."):
            ans="No"
if ans !="No":
    ans ="Yes"
print(ans)

Submission status: Runtime Error

Solution code:
h, w = map(int, input().split())
box = [["."] + list(input()) + ["."] for i in range(h)]
box.insert(0, ["."] * (w + 2))
box.append(["."] * (w + 2))


def seek(box, i, j):
    if box[i][j] == "#":
        for x, y in [[1, 0], [-1, 0], [0, 1], [0, -1]]:
            xx = x + i
            yy = y + j
            if box[xx][yy] == "#" or box[xx][yy] == "O":
                box[i][j] = "O"
                seek(box, xx, yy)
    return box


for i in range(1, h + 1):
    for j in range(1, w + 1):
        seek(box, i, j)

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

print("Yes")

Submission status: Runtime Error

Solution code:
h,w=map(int,input().split())
box=[["."]+list(input())+["."] for i in range(h)]
box.insert(0,["."]*(w+2))
box.append(["."]*(w+2))

def seek(box,i,j):
    if box[i][j]=="#":
        for x,y in [[1,0],[-1,0],[0,1],[0,-1]]:
            xx=x+i
            yy=y+j
            if box[xx][yy]=="#" or box[xx][yy]=="O":
                box[i][j]="O"
                seek(box,xx,yy)
    return box

for i in range(1,h+1):
    for j in range(1,w+1):
        seek(box,i,j)

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

print("Yes")

Submission status: Runtime Error

Solution code:
h,w=map(int,input().split())
box=[["."]+list(input())+["."] for i in range(h)]
box.insert(0,["."]*(w+2))
box.append(["."]*(w+2))
count=0
def seek(box,i,j):
    point=[[1,0],[-1,0],[0,1],[0,-1]]
    if box[i][j]=="#":
        for x,y in point:
            xx=x+i
            yy=y+j
            if box[xx][yy]=="#" or box[xx][yy]=="O":
                box[i][j]="O"
                seek(box,xx,yy)
    return box

for i in range(1,h+1):
    for j in range(1,w+1):
        seek(box,i,j)

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

print("Yes")

Submission status: Runtime Error

Solution code:
import numpy as np
h,w=map(int,input().split())
box=[["."]+list(input())+["."] for i in range(h)]
box.insert(0,["."]*(w+2))
box.append(["."]*(w+2))
count=0
def seek(box,i,j):
    point=[[1,0],[-1,0],[0,1],[0,-1]]
    if box[i][j]=="#":
        for x,y in point:
            xx=x+i
            yy=y+j
            if box[xx][yy]=="#" or box[xx][yy]=="O":
                box[i][j]="O"
                seek(box,xx,yy)
    return box
for i in range(1,h+1):
    for j in range(1,w+1):
        seek(box,i,j)

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

print("Yes")

Submission status: Runtime Error

Solution code:

h,w=map(int,input().split())
a=["."*(w+2)]
for i in range(h):
	x=input()
	a.append("."+x+".")
a.append("."*(w+2)
for i in range(h):
	for j in range(w):
		if a[i+1][j+1]=="#":
			if a[i][j+1]=="#" or \
a[i+2][j+1]=="#" or a[i+1][j+2]=="#" or\
a[i+1][j]=="#":
				continue
			else:
				print("No")
				exit()
print("Yes")

Submission status: Runtime Error

Solution code:
h,w=map(int,input().split())
a=["."*w]
for i in range(h):
	x=input()
	a.append("."+x+".")
a.append("."*w)
for i in range(h):
	for j in range(w):
		if a[i+1][j+1]=="#":
			if a[i][j+1]=="#" or \
a[i+2][j+1]=="#" or a[i+1][j+2]=="#" or\
a[i+1][j]=="#":
				continue
			else:
				print("No")
				exit()
print("Yes")