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:
import math
import random
import heapq
from collections import Counter, defaultdict
from decimal import Decimal, ROUND_HALF_UP, ROUND_CEILING
from functools import lru_cache, reduce
from itertools import combinations_with_replacement, product, combinations


def read_int():
    return int(input())


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


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input()


def read_str_n():
    return list(map(str, input().split()))


def mt(f):
    import time
    import sys

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        print(e - s, 'sec', file=sys.stderr)
        return ret

    return wrap


@mt
def slv(H, W, M):
    def ok(i, j):
        f = False
        if i > 0 and M[i - 1][j] == '#':
            f = True
        if i < H - 1 and M[i + 1][j] == '#':
            f = True

        if j > 0 and M[i][j - 1] == '#':
            f = True

        if j < W - 1 and M[i][j + 1] == '#':
            f = True
        return f

    for i in range(H):
        for j in range(W):
            if M[i][j] == '#' and not ok(i, j):
                return 'No'

    return 'Yes'


def main():
    H, W = read_int_n()
    M = [read_str() for _ in range(H)]
    print(slv(H, W, M))


if __name__ == '__main__':
    main()

Submission status: Accepted

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

def isValid(i,j):
  # print("(i,j) = (" + str(i) + "," + str(j) + ")")
  st=False
  if i>0:
    st|=s[i-1][j]=='#'
  if i+1<H:
    st|=s[i+1][j]=='#'
  if j>0:
    st|=s[i][j-1]=='#'
  if j+1<W:
    st|=s[i][j+1]=='#'
  return st

for i in range(H):
  for j in range(W):
    if s[i][j]=='.':
      continue
    elif not isValid(i,j):
      print("No")
      exit(0)
print("Yes")

Submission status: Accepted

Solution code:

h, w = map(int, input().split())
s = [["." for _ in range(w + 2)]]

for _ in range(h):
    s_ = ["."]
    s_.extend([x for x in input()])
    s_.append(".")
    s.append(s_)

s.append(["." for _ in range(w + 2)])


for x in range(h):
    for y in range(w):
        target_x = x + 1
        target_y = y + 1
        # cross check
        if s[target_x][target_y]  == "#":
            if s[target_x - 1][target_y] == "#" or s[target_x + 1][target_y] == "#" or s[target_x][target_y -1 ] == "#" or  s[target_x][target_y +1 ] == "#":
                pass
                # ok
            else:
                # ng
                print("No")
                exit()
print("Yes")

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**6)
h,w=map(int,input().split())
c=[list(input()) for i in range(h)]
dxy=((0,1),(0,-1),(1,0),(-1,0))
def dfs(y,x):
    flag=False
    for dx,dy in dxy:
        nx,ny=x+dx,y+dy
        if 0<=nx<=w-1 and 0<=ny<=h-1 and c[ny][nx]=="#":
            flag=True
    return flag
for i in range(w):
    for j in range(h):
        if c[j][i]=="#":
            if not dfs(j,i):
                print("No")
                sys.exit()
print("Yes")

Submission status: Accepted

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

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

def func(H,W,a):
  for i in range(H):
    for j in range(W):
      if a[i][j] == '#':
        if i > 0 and a[i-1][j] == '#':
          continue
        if j > 0 and a[i][j-1] == '#':
          continue
        if i < H-1 and a[i+1][j] == '#':
          continue
        if j < W-1 and a[i][j+1] == '#':
          continue
        print('No')
        return 0
  print('Yes')
  return 0

func(H,W,a)

Submission status: Accepted

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

s = []
s.append(list(("." * (w+1))))

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

s.append(list(("." * (w+1))))
flag = False

for i in range(h-2):
    for j in range(w-2):
        if s[i+1][j+1] == '#':
            if s[i+2][j+1] == s[i][j+1] == s[i+1][j+2] == s[i+1][j] == '.':
                flag = True
            else:
                pass
        else:
            pass


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

Submission status: Accepted

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

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

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

for i in range(0,h):
    for j in range(0,w):
        if s[i][j]=="#":
            if flags[i][j]==0:
                print("No")
                sys.exit()
            else:
                continue

print("Yes")

Submission status: Accepted

Solution code:
h, w = [int(i) for i in input().split()]
s = [[0 for i in range(w)] for j in range(h)]
s2 = [['.' for i in range(w + 2)] for j in range(h + 2)]

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

Submission status: Accepted

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

S=["" for i in range(H+2)]

S[0]="."*(W+2)

for i in range(1,H+1):
    S[i]="."+input()+"."

S[H+1]="."*(W+2)

#全ての黒マスの縦か横に黒マスがあることをチェック

CHECK=1

for i in range(1,H+1):

    for j in range(1,W+1):

        if S[i][j]=="#":
            if S[i][j+1]=="." and S[i][j-1]=="." and S[i-1][j]=="." and S[i+1][j]==".":
                CHECK=0


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

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
M = []
for i in range(H):
    M.append(list(input()))
answer = 'Yes'
for i in range(H):
    for j in range(W):
        elem = M[i][j]
        if elem == '#':
            neib = []
            if i != 0:
                neib.append(M[i-1][j])
            if i != H-1:
                neib.append(M[i+1][j])
            if j != 0:
                neib.append(M[i][j-1])
            if j != W-1:
                neib.append(M[i][j+1])
            if '#' not in neib:
                answer = 'No'
                break

print(answer)

Submission status: Accepted

Solution code:
H,W=map(int, raw_input().split())
s=[ list(raw_input()) for i in range(H)]
diff=[(1,0),(-1,0),(0,1),(0,-1)]

for i in range(H):
	for j in range(W):
		if s[i][j]=="#":
			for dx,dy in diff:
				if i+dx>=0 and j+dy>=0 and i+dx<H and j+dy<W:
					if s[i+dx][j+dy]=="#":
						break
			else:
				print "No"
				quit()
else:
	print "Yes"

Submission status: Accepted

Solution code:
H, W = list(map(int, input().split()))
S = [input() for _ in range(H)]
field = [[0 for w in range(W+2)] for h in range(H+2)]

def add(h, w):
    field[h][w + 1] += 1
    field[h + 2][w + 1] += 1
    field[h + 1][w] += 1
    field[h + 1][w + 2] += 1

for h in range(H):
    for w in range(W):
        if S[h][w] == "#":
            add(h, w)
        else:
            field[h+1][w+1] -= 10
        
res = 0
for l in field[1:H+1]:
    if 0 in l[1:W+1]:
        print("No") 
        break
else:
    print("Yes")

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
S = []
for _ in range(H):
    S.append(input())
#上下左右隣接しない独立した#があるかどうかを調べる
#境界処理をしたくなので周囲に.追加
newS = ["." * (W+2)]
for rowS in S:
    newS.append("." + rowS + ".")
newS.append("." * (W+2))

for i in range(1, H+1):
    for j in range(1, W+1):
        if newS[i][j] == "#" and newS[i][j+1] != "#" and newS[i][j-1] != "#"\
        and newS[i+1][j] != "#" and newS[i-1][j] != "#":
            print("No", end = "")
            break
    else:
        continue
    break
else:
    print("Yes", end = "")

Submission status: Accepted

Solution code:
def solve():
    for i in range(1, H):
        for j in range(1, W):
            if s[i][j] == "#":
                if s[i + 1][j] == "." and s[i][j + 1] == "." and s[i-1][j] == "." and s[i][j-1] == ".":
                    print("No")
                    return;
    else:
        print("Yes")


H, W = [int(i) for i in input().split()]
s = [["."] * (W + 2)]
for _ in range(H):
    sh = ["."] + list(input()) + ["."]
    s.append(sh)
s.append([["."] * (W + 2)])
solve()

Submission status: Accepted

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

##パターン1
#M = list( list(input()) for _ in range(h) )


m=['.']*(w+2)
M=[]
M.append(m)
for i in range(h):
	s = '.' + input() + '.'
	M.append(list(s))
M.append(m)

#print(M)


for x in range(1,h+1):
	for y in range(1,w+1):
		#print(M[x][y], end="")
		if M[x][y]=='.': continue
		
		b=False
		b=b or (M[x-1][y]=='#')
		b=b or (M[x+1][y]=='#')
		b=b or (M[x][y-1]=='#')
		b=b or (M[x][y+1]=='#')
		
		if b==False:
			print('No')
			exit(0)


print('Yes')

Submission status: Accepted

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


if H == 1 and W == 1 and nodes[0][0] == ".":
    print("No")
    quit()
if H == 1 and W == 1 and nodes[0][0] == "#":
    print("Yes")
    quit()


for i in range(H):
    for j in range(W):
        if nodes[i][j] == "#":
            flag = False
            if i - 1 >= 0:
                if nodes[i-1][j] == "#":
                    flag = True
            if i + 1 < H:
                if nodes[i+1][j] == "#":
                    flag = True
            if j - 1 >= 0:
                if nodes[i][j-1] == "#":
                    flag = True
            if j + 1 < W:
                if nodes[i][j+1] == "#":
                    flag = True

            if flag == False:
                print("No")
                quit()

print("Yes")

Submission status: Accepted

Solution code:
h,w = map(int,input().split()) 
a = [input() for _ in range(h)]
flag = False
for i in range(1,h-1):
    for j in range(1,w-1):
        if a[i][j] == "#" and a[i][j+1] == "." and a[i+1][j] == "." and a[i-1][j] == "." and a[i][j-1] == ".":
            flag = True
        
if flag :
    print("No")
else:
    print("Yes")

Submission status: Accepted

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

Submission status: Accepted

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

S = [["." for i in range(W + 2)] for j in range(H + 2)]

for i in range(1, H + 1):
    a = input()
    for j in range(1, W + 1):
        S[i][j] = a[j - 1]


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][j - 1] != "#" and S[i][j + 1] != "#" and S[i + 1][j] != "#":
                NO = 1
                break

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

Submission status: Accepted

Solution code:
H,W = map(int, raw_input().split())
s = [raw_input() for _ in range(H)]
ans = "Yes"
for y in range(H):
  for x in range(W):
    if s[y][x]=="#":
      ok = False
      for dx,dy in [(-1,0), (1,0), (0,-1), (0,1)]:
        if 0<=x+dx<W and 0<=y+dy<H and s[y+dy][x+dx]=="#":
          ok = True
      if not ok:
        ans = "No"
print ans

Submission status: Accepted

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

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

ans=True
for i in range(H):
  for j in range(W):
    if M[i][j]=='#':
      if (j+1 < W and M[i][j+1]=='#') or  (i+1 < H and M[i+1][j]=='#') or (j-1 >= 0 and M[i][j-1]=='#') or (i-1 >=0 and M[i-1][j]=='#'):
        continue
      else:
        ans=False
        break
if ans:
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
import sys
H,W = map(int,input().split())
listMap = [[i for i in input()] for j in range(H)]
listPatA = [-1,0,0,1]
listPatB = [0,-1,1,0]

def dfs(a,b):
    # 4方向確認
    for i in range(4):
        # 現在地a,bにpatternのiを足した値を設定
        A = a + listPatA[i]
        B = b + listPatB[i]

        # A,BがMAP範囲内　かつ　W出現で再帰
        if 0 <= A < H and 0 <= B < W and listMap[A][B] == '#':
            return True
    # 結果的になければFalse
    return False

for i in range(H):
    for j in range(W):
        # 初めのWを見つける
        if listMap[i][j] == '#':
            # 見つけたら周囲8方向検索
            if dfs(i,j) == False:
                print("No")
                sys.exit()
# 全探索終了でYes
print("Yes")

Submission status: Accepted

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

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

ans = True

for i in range(h):
    if not ans:
        break
    for j in range(w):
        if field[i][j] == '#':
            if i != 0 and field[i - 1][j] == '#':
                continue
            if i != h - 1 and field[i + 1][j] == '#':
                continue
            if j != 0 and field[i][j - 1] == '#':
                continue
            if j != w - 1 and field[i][j + 1] == '#':
                continue
            ans = False
            break

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

Submission status: Accepted

Solution code:
hw = list(map(int, input().split()))
s = []
for i in range(hw[0]):
    s1 = input()
    s2 = []
    for j in range(len(s1)):
        s2.append(s1[j])
    s.append(s2)

flag = True
if s[0][0] == "#" and (s[1][0] == "." and s[0][1] == "."):
    flag = False
if s[0][hw[1] - 1] == "#" and (s[1][hw[1] - 1] == "." and s[0][hw[1] - 2] == "."):
    flag = False
if s[hw[0] - 1][0] == "#" and (s[hw[0] - 2][0] == "." and s[hw[0] - 1][1] == "."):
    flag = False
if s[hw[0] - 1][hw[1] - 1] == "#" and (s[hw[0] - 1][hw[1] - 2] == "." and s[hw[0] - 2][hw[1] - 1] == "."):
    flag = False
if hw[0] >= 2:
    for i in range(hw[0] - 2):
        if s[i + 1][0] == "#" and (s[i][0] == "." and s[i + 2][0] == "." and s[i + 1][1] == "."):
            flag = False
            break
        if s[i + 1][hw[1] - 1] == "#" and (s[i][hw[1] - 1] == "." and s[i + 2][hw[1] - 1] == "." and s[i + 1][hw[1] - 2] == "."):
            flag = False
            break
if hw[1] >= 2:
    for i in range(hw[1] - 2):
        if s[0][i + 1] == "#" and (s[0][i] == "." and s[0][i + 2] == "." and s[1][i + 1] == "."):
            flag = False
            break
        if s[hw[0] - 1][i + 1] == "#" and (s[hw[0] - 1][i] == "." and s[hw[0] - 1][i + 2] == "." and s[hw[0] - 2][i + 1] == "."):
            flag = False
            break
if hw[0] >= 2 and hw[1] >= 2:
    for i in range(hw[0] - 2):
        for j in range(hw[1] - 2):
            if s[i + 1][j + 1] == "#" and (s[i][j + 1] == "." and s[i + 2][j + 1] == "." and s[i + 1][j] == "." and s[i + 1][j + 2] == "."):
                flag = False
                break
if flag == False:
    print("No")
else:
    print("Yes")

Submission status: Accepted

Solution code:
def checkBW(i,j):
    try:
        up = S[i-1][j]
    except:
        up = '.'
    try:
        right = S[i][j+1]
    except:
        right = '.'
    try:
        down = S[i+1][j]
    except:
        down = '.'
    try:
        left = S[i][j-1]
    except:
        left = '.'
    #print(up,right, down, left)
    if(up == '.' and right == '.' and down == '.' and left == '.'):
        return True
    else:
        return False

H, W = map(int, input().split())
S = []
for i in range(H):
    temp_input = input()
    S.append(temp_input)

# 黒を探索
for i in range(H):
    for j in range(W):
        if(S[i][j] == '#'):
            #print(i,j)
            if(checkBW(i,j)):
                print('No')
                exit()
print('Yes')

Submission status: Accepted

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

flag = False
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 j - 1 >= 0:
            if s[i][j - 1] == '#':
                continue
        if i + 1 < h:
            if s[i + 1][j] == '#':
                continue
        if j + 1 < w:
            if s[i][j + 1] == '#':
                continue
        flag = True
        break
    if flag:
        break

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

Submission status: Accepted

Solution code:
import numpy as np
h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]
s = np.array(s)
out = "Yes"
for i in range(h):
    for j in range(w):
        if s[i][j] == ".":
            continue
        if i == 0 and j == 0:
            up = s[i][j]
            down = s[i + 1][j]
            left = s[i][j]
            right = s[i][j + 1]
        elif i == 0 and j == w-1:
            up = s[i][j]
            down = s[i + 1][j]
            left = s[i][j - 1]
            right = s[i][j]
        elif i == h-1 and j == 0:
            up = s[i - 1][j]
            down = s[i][j]
            left = s[i][j]
            right = s[i][j + 1]
        elif i == h-1 and j == w-1:
            up = s[i - 1][j]
            down = s[i][j]
            left = s[i][j - 1]
            right = s[i][j]
        elif i == 0 and j != 0 and j != w-1:
            up = s[i][j]
            down = s[i + 1][j]
            left = s[i][j - 1]
            right = s[i][j + 1]
        elif i == h-1 and j != 0 and j != w-1:
            up = s[i - 1][j]
            down = s[i][j]
            left = s[i][j - 1]
            right = s[i][j + 1]
        elif j == 0 and i !=  0 and i != h-1:
            up = s[i - 1][j]
            down = s[i + 1][j]
            left = s[i][j]
            right = s[i][j + 1]
        elif j == w-1 and i != 0 and i!= h-1:
            up = s[i - 1][j]
            down = s[i + 1][j]
            left = s[i][j - 1]
            right = s[i][j]
        else:
            up = s[i-1][j]
            down = s[i+1][j]
            left = s[i][j-1]
            right = s[i][j+1]
        if s[i][j] != up and s[i][j] != down and s[i][j] != left and s[i][j] != right:
            out = "No"
print(out)

Submission status: Accepted

Solution code:
import numpy as np
na = np.array

def ii():
    return int(input())


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


def lvi(N):
    l = []
    for _ in range(N):
        l.append(ii())
    return l


def lv(N):
    l = []
    for _ in range(N):
        l.append(input())
    return l


def yn(b):
    if b:
        print('Yes')
    else:
        print('No')


def is_prime(q):
    q = abs(q)
    if q == 2: return True
    if q < 2 or q&1 == 0: return False
    return pow(2, q-1, q) == 1


def ok(S, i, j):
    try:
        if S[i+1][j] == '#':
            return True
    except:
        pass
    try:
        if S[i-1][j] == '#':
            return True
    except:
        pass
    try:
        if S[i][j+1] == '#':
            return True
    except:
        pass
    try:
        if S[i][j-1] == '#':
            return True
    except:
        pass

    return False


def C():

    H, W = lii()
    S = []
    for _ in range(H):
        S.append(input())

    for i, l in enumerate(S):
        for j in range(len(l)):
            if S[i][j] == '#':
                if not ok(S, i, j):
                    return False

    return True


if __name__ == '__main__':
    yn(C())

Submission status: Accepted

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

#for i in range(h):
#    s.append(input())

c_org = [ [ 0 if c_org == "#" else -1 for c_org in input()] for r in range(h)]
 

#周囲をシャープ(というか-1)で囲む------------------------------
#c_org の左右を囲む
for i in range(h):
    c_org[i].append( -1)
    c_org[i].insert(0,-1)
    count=count+c_org[i].count(9999)
c_plus=[-1 for i in range(w+2)]
 
#上下も囲んだ配列をcとする
c=[]
c.append(c_plus)
for i in range(h):
    c.append(c_org[i])
c.append(c_plus)
#-------------------------------------------------------------------

aaaaa=0
for i in range(h):
  for j in range(w):
     if c[i+1][j+1]==0:
         if c[i+1][j+2]==0 or c[i+2][j+1]==0 or c[i][j+1]==0 or c[i+1][j]==0:
           pass
         else:
#           print(i+1, j+1)
           aaaaa=1
 


#for i in range(h):
#    print(c[i])

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

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
arr=[]
for i in range(h):
	s=str(input())
	arr.append(s)
if(h==1 and w==1):
	if(arr[0][0]=='.'):
		print("Yes")
	else:
		print("No")
elif(h==1 and w>1):
	if(arr[0][0]=='#'):
		print("No")
	elif(arr[0][w-1]=='#'):
		print("No")
	else:
		for j in range(1,w-1):
			if(arr[0][j]=='#'):
				if(arr[0][j-1]!='#' and arr[0][j+1]!='#'):
					print("No")
					flag=1
					break
		if(flag==0):
			print("Yes")

elif(h>1 and w==1):
	if(arr[0][0]=='#'):
		print("No")
	elif(arr[h-1][0]=='#'):
		print("No")
	else:
		flag=0
		for j in range(1,h-1):
			if(arr[j][0]=='#'):
				if(arr[j-1][0]!='#' and arr[j+1][0]!='#'):
					print("No")
					flag=1
					break
		if(flag==0):
			print("Yes")
else:
	flag=0
	for j in range(1,w-1):
			if(arr[0][j]=='#'):
				if(arr[0][j-1]!='#' and arr[0][j+1]!='#' and arr[1][j]!='#'):
					print("No")
					flag=1
					break
	if(flag==0):
		for j in range(1,w-1):
			if(arr[h-1][j]=='#'):
				if(arr[h-1][j-1]!='#' and arr[h-1][j+1]!='#' and arr[h-2][j]!='#'):
					print("No")
					flag=1
					break
	if(flag==0):
		for j in range(1,h-1):
			if(arr[j][0]=='#'):
				if(arr[j-1][0]!='#' and arr[j+1][0]!='#' and arr[j][1]!='#'):
					print("No")
					flag=1
					break
	if(flag==0):
		for j in range(1,h-1):
			if(arr[j][w-1]=='#'):
				if(arr[j-1][w-1]!='#' and arr[j+1][w-1]!='#' and arr[j][w-2]!='#'):
					print("No")
					flag=1
					break
	if(flag==0):				
		for j in range(1,h-1):
			for k in range(1,w-1):
				if(arr[j][k]=='#'):
					if(arr[j-1][k]!='#' and arr[j+1][k]!='#' and arr[j][k-1]!='#' and arr[j][k+1]!='#'):
						print("No")
						flag=1
						break
			if(flag==1):
				break
	if(flag==0):
		print("Yes")

Submission status: Accepted

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

# 連結しているものが一つもなければNo

dx = [1, 0, -1, 0]
dy = [0, -1, 0, 1]
import sys
for i in range(h):
    for j in range(w):
        if ma[i][j] == '#':
            flag = False
            for x, y in zip(dx, dy):
                if j + x < 0 or i + y < 0 or j + x >= w or i + y >= h:
                    continue

                if ma[i + y][j + x] == '#':
                    flag = True

            if flag == False:
                print('No')
                sys.exit(0)
print('Yes')
sys.exit(0)

Submission status: Accepted

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

def is_check():
    for i in range(h):
        for j in range(w):
            if s[i][j] == '#' and (j+1 >= w or s[i][j] != s[i][j+1]) and (j-1 < 0 or s[i][j] != s[i][j-1]) and (i+1 >= h or s[i][j] != s[i+1][j]) and (i-1 < 0 or s[i][j] != s[i-1][j]):
                return 'No'
    return 'Yes'

print(is_check())

Submission status: Accepted

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

flag = True

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

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

Submission status: Accepted

Solution code:
import numpy as np
H, W = map(int, input().split())
lines = [input() for i in range(H)]
grid = np.zeros([H, W])
for i in range(H):
    for ii in range(W):
        if lines[i][ii] == '#':
            grid[i, ii] = 1
flag = True
for i in range(H):
    for ii in range(W):
        if grid[i, ii] == 1:
            if i == 0:
                if ii == 0:
                    a = grid[i, ii+1] + grid[i+1, ii]
                elif ii == W-1:
                    a = grid[i, ii-1] + grid[i+1, ii]
                else:
                    a = grid[i, ii-1] + grid[i, ii+1] + grid[i+1, ii]
            elif i == H-1:
                if ii == 0:
                    a = grid[i, ii+1] + grid[i-1, ii]
                elif ii == W-1:
                    a = grid[i, ii-1] + grid[i-1, ii]
                else:
                    a = grid[i, ii-1] + grid[i, ii+1] + grid[i-1, ii]
            else:                
                if ii == 0:
                    a = grid[i, ii+1] + grid[i+1, ii] + grid[i-1, ii]
                elif ii == W-1:
                    a = grid[i, ii-1] + grid[i+1, ii] + grid[i-1, ii]
                else:
                    a = grid[i, ii-1] + grid[i, ii+1] + grid[i+1, ii] + grid[i-1, ii]
            if a == 0:
                flag = False
if flag:
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

for i in range(h):
    low = [i for i in input()]
    c.append(low)

for j in range(h):
    for k in range(w):
        cnt = 0
        if c[j][k] == "#":
            if j != 0:
                if c[j-1][k] == "#":
                    cnt += 1
            if k != 0:
                if c[j][k-1] == "#":
                    cnt += 1
            if j != h - 1:
                if c[j+1][k] == "#":
                    cnt += 1
            if k != w - 1:
                if c[j][k+1] == "#":
                    cnt += 1

            if cnt == 0:
                print("No")
                break

    else:
        continue
    break

else:
    print("Yes")

Submission status: Accepted

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

    for _ in range(h):
        line = input()
        m.append(line)

    if judge_map(m):
        print('Yes')
    else:
        print('No')

def judge_map(m):
    for i in range(len(m)):
        for j in range(len(m[i])):
            if not judge(m, i, j):
                return False
    return True

def judge(m, i, j):
    if m[i][j] == '.':
        return True
    
    if i - 1 >= 0 and m[i - 1][j] == '#':
        return True
    
    if i + 1 < len(m) and m[i + 1][j] == '#':
        return True
    
    if j - 1 >= 0 and m[i][j-1] == '#':
        return True
    
    if j + 1 < len(m[i]) and m[i][j + 1] == '#':
        return True
    
    return False


main()

Submission status: Accepted

Solution code:
H,W=map(int,input().split())
s = [['.' for i in range(W+2)] for j in range(H+2)]
f=0
for i in range(H):
 s[i+1] = ['.'] + list(input()) + ['.']
for i in range(H+2):
 if f == 0:
  for j in range(W+2):
   if s[i][j] == '#':
    if s[i-1][j] == '.' and s[i+1][j] == '.' and s[i][j-1] == '.' and s[i][j+1] == '.':
     f = 1
     print('No')
     break
if f == 0:
 print('Yes')

Submission status: Accepted

Solution code:
h,w = map(int,input().split())
s = []
for i in range(h):
	stemp = list(input())
	s.append(stemp)
check = True
for i in range(h):
	for k in range(w):
		if s[i][k] == '#':
			counter = 0
			if k+1 < w and s[i][k+1] == '#':
				counter += 1
			if 0 <= k-1 and s[i][k-1] == '#':
				counter += 1
			if i+1 < h and s[i+1][k] == '#':
				counter += 1
			if 0 <= i-1 and s[i-1][k] == '#':
				counter += 1
			if counter == 0:
				check = False
if check:
	print('Yes')
else:
	print('No')

Submission status: Accepted

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

ans = "Yes"
for i in range(h):
    for j in range(w):
        if s[i][j] == '#':
            ok = False
            if 0 < i and s[i - 1][j] == '#':
                ok = True
            if i + 1 < h and s[i + 1][j] == '#':
                ok = True
            if 0 < j and s[i][j - 1] == '#':
                ok = True
            if j + 1 < w and s[i][j + 1] == '#':
                ok = True
            if not ok:
                ans = "No"
print(ans)

Submission status: Accepted

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

def search(y,x):
    if s[y][x] != "#":
        return True
    if s[y][x] == "#":
        for dy,dx in ((1,0),(-1,0),(0,1),(0,-1)):
            ny,nx = (y+dy,x+dx)
            if 0 <= ny <= h-1 and 0 <= nx <= w-1:
                if s[ny][nx] == "#":
                    return True
    return False


for i in range(h):
    for j in range(w):
        if search(i,j) == False:
            print("No")
            exit()
print("Yes")

Submission status: Accepted

Solution code:
import sys

def check(i,j):
    delta = [(-1,0), (1,0), (0,1), (0,-1)]
    for d in delta:
        ni = i + d[0]
        nj = j + d[1]
        if (ni >= 0 and ni < H and nj >= 0 and nj < W):
            if (m[ni][nj] == '#'):
                return True
        else:
            continue
    return False
        
H,W = list(map(int, input().split()))
m = []
for i in range(H):
    l = str(input())
    m.append(l)

for i in range(H):
    for j in range(W):
        if m[i][j] == '#' and check(i,j) == False:
            print('No')
            sys.exit()
print('Yes')