Problem:


Score: 300 points

Problem Statement

We have a canvas divided into a grid with H rows and W columns. The square at the i-th row from the top and the j-th column from the left is represented as (i, j).

Initially, all the squares are white. square1001 wants to draw a picture with black paint. His specific objective is to make Square (i, j) black when s_{i, j}= #, and to make Square (i, j) white when s_{i, j}= ..

However, since he is not a good painter, he can only choose two squares that are horizontally or vertically adjacent and paint those squares black, for some number of times (possibly zero). He may choose squares that are already painted black, in which case the color of those squares remain black.

Determine if square1001 can achieve his objective.  

Constraints

H is an integer between 1 and 50 (inclusive).

W is an integer between 1 and 50 (inclusive).

For every (i, j) (1 \leq i \leq H, 1 \leq j \leq W), s_{i, j} is # or ..

Input

Input is given from Standard Input in the following format:

H W
s_{1, 1} s_{1, 2} s_{1, 3} ... s_{1, W}
s_{2, 1} s_{2, 2} s_{2, 3} ... s_{2, W}
  :   :
s_{H, 1} s_{H, 2} s_{H, 3} ... s_{H, W}

Output

If square1001 can achieve his objective, print Yes; if he cannot, print No.

Sample Input 1

3 3
.#.
###
.#.

Sample Output 1

Yes

One possible way to achieve the objective is shown in the figure below. Here, the squares being painted are marked by stars.

Sample Input 2

5 5
#.#.#
.#.#.
#.#.#
.#.#.
#.#.#

Sample Output 2

No

square1001 cannot achieve his objective here.

Sample Input 3

11 11
...#####...
.##.....##.
#..##.##..#
#..##.##..#
#.........#
#...###...#
.#########.
.#.#.#.#.#.
##.#.#.#.##
..##.#.##..
.##..#..##.

Sample Output 3

Yes



Sample input:
3 3
.#.
###
.#.


Sample output:
Yes

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
s = [input() for i in range(H)]
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
ans = "Yes"
for i in range(H):
        for j in range(W):
                if s[i][j] == "#":
                        flag = 1 
                        for k in range(4):
                                y = i + dy[k]
                                x = j + dx[k]
                                if 0 <= x < W and 0 <= y < H:
                                        if s[y][x] == "#":
                                                flag = 0 
                        if flag:
                                ans = "No"
                                break
        else:
                continue
        break
print(ans)

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
s = [[True]*(W+2)]
for i in range(H):
    st = input()
    l = [False]
    for t in st:
        l.append(t == "#")
    l.append(False)
    s.append(l)
s.append([True]*(W+2))

flag = True
for i in range(1, H+1):
    for j in range(1, W+1):
        if s[i][j] and not s[i][j-1] and not s[i][j+1] and not s[i+1][j] and not s[i-1][j]:
            flag = False
            break

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

Submission status: Accepted

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

flag = True
for i in range(H):
    for j in range(W):
        if S[i][j] == '#':
            # 上下左右
            if (i-1 >= 0 and S[i-1][j] == '#') or (i+1 < H and S[i+1][j] == '#') or (j-1 >= 0 and S[i][j-1] == '#') or (j+1 < W and S[i][j+1] == '#'):
                continue
            else:
                flag = False

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
H, W = [int(x) for x in input().split()]
s = []
for _ in range(H):
    temp = list(input().rstrip())
    s.append(temp)
def A(i,j,s):
    next_point = [[i+1,j],[i-1,j],[i,j-1],[i,j+1]]
    for n in next_point:
        x, y = n[0], n[1]
        if 0 <= x <= H-1 and 0 <= y <= W-1:
            if s[x][y] == "#":
                return 0
    return 1
for k in range(H):
    for l in range(W):
        flag = 0
        if s[k][l] == "#":
            flag = A(k,l,s)
        if flag:
            print("No")
            sys.exit()
print("Yes")

Submission status: Accepted

Solution code:
import numpy as np
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

H,W = map(int,readline().split())
grid = np.frombuffer(read(),'S1').reshape(H,-1)[:,:W]

white = (grid == b'.')

U = np.ones((H + 2, W + 2), np.int32)
U[:H, :W] = white
for i in range(H):
  for j in range(W):
    if U[i, j] == 0:
      if U[i - 1, j] * U[i + 1, j] * U[i, j - 1] * U[i, j + 1] != 0:
        print('No')
        quit()
print('Yes')

Submission status: Accepted

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

def search(y,x):
    if mat[y][x] == '#':
        y2 = [0,0,1,-1]
        x2 = [1,-1,0,0]
        for i in range(4):
            if 0<=y+y2[i]<=H-1 and 0<=x+x2[i]<=W-1:
                if mat[y+y2[i]][x+x2[i]] == '#':
                    return True
        return False
    
    return True
ans = 'Yes'
for i in range(H):
    for j in range(W):
        if ans == 'No':
            break
        if search(i,j):
            continue
        else:
            ans = 'No'
            break
print(ans)

Submission status: Accepted

Solution code:
import sys
H, W = map(int, sys.stdin.readline().split())
L = ['.' + sys.stdin.readline().rstrip() +'.' for _ in range(H)]
L.insert(0, '.'*(W+2))
L.append('.'*(W+2))
#print(L)
f = 'Yes'
for i in range(1, H+1):
    for j in range(1, W+1):
        if L[i][j] =='#':
            if not '#' in [L[i-1][j], L[i][j-1], L[i][j+1], L[i+1][j]]:
                f = 'No'
                break

print(f)

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
a=[]
for i in range(h):
  a.append(list("."+(input())+"."))
a.insert(0,["."]*(w+2))
a.append(["."]*(w+2))
flg = True
for i in range(h+2):
  for j in range(w+2):
    if a[i][j] == "#":
      for (k,l) in ((i,j+1),(i,j-1),(i+1,j),(i-1,j)):
        if a[k][l] != "#":
          cnt+=1
          if cnt == 4:
            flg = False
    cnt=0
if flg:
  print("Yes")
else:
  print("No")

Submission status: Accepted

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

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


def solve(H: int, W: int, s: "List[str]"):
    ans = YES
    for i in range(1, H-1):
        for j in range(1, W-1):
            if s[i][j] == "#" and s[i-1][j] == s[i+1][j] == s[i][j-1] == s[i][j+1] == ".":
                ans = NO
    print(ans)

# Generated by 1.1.6 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():
    H, W = map(int,input().split())  # type: int
    s = [input() for _ in range(H)]  # type: "List[str]"
    solve(H, W, s)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
h,w = map(int, input().split())
mat = ["."+input()+"." for _ in range(h)]
mat = ["."*(w+2)]+mat+["."*(w+2)]
for i in range(1,h+1):
  for j in range(1,w+1):
    if mat[i][j] == "#":
      if (mat[i+1][j] == ".") and  (mat[i-1][j] == ".") and  (mat[i][j+1] == ".") and  (mat[i][j-1] == "."):
        print("No")
        sys.exit()
print("Yes")

Submission status: Accepted

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

#四つのうち#があればOK
def four_next(i,j):
    global s
    if i>0 :
        if s[i-1][j]=="#":
            return True
    if i<h-1 :
        if s[i+1][j]=="#":
            return True
    if j>0 :
        if s[i][j-1]=="#":
            return True
    if j<w-1 :
        if s[i][j+1]=="#":
            return True
    return False

f=0
for i in range(h):
    for j in range(w):
        if s[i][j]=="#" and (not four_next(i,j)):
            f=1
            break
    if f==1:
        break
if f==0:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
h, w = [int(i) for i in input().split()]
s = [["."] * (w + 2)] + [["."] + list(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] == ".":
      continue
    if s[i - 1][j] + s[i + 1][j] + s[i][j - 1] + s[i][j + 1] == "....":
      print("No")
      exit(0)
print("Yes")

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
s = []
for i in range(H):
    s_i = input()
    s.append([s_i[i] for i in range(len(s_i))])
direction = [[1, 0], [-1, 0], [0, -1], [0, 1]]
for i in range(H):
    for j in range(W):
        if s[i][j] == "#":
            # check isolated
            is_isolated = True
            for arrow in direction:
                neigh = [i + arrow[0], j + arrow[1]]
                if neigh[0] == -1 or neigh[0] == H or neigh[1] == -1 or neigh[1] == W:
                    continue
                if s[neigh[0]][neigh[1]] == "#":
                    is_isolated = False
                    break
            if is_isolated:
                print("No")
                exit()
print("Yes")

Submission status: Accepted

Solution code:
import queue as q

direction = [[1, 0], [-1, 0], [0, -1], [0, 1]]

H, W = map(int, input().split())
s = []
for i in range(H):
    s_i = input()
    s.append([s_i[i] for i in range(len(s_i))])


def do_bfs(s, que):
    while True:
        if que.empty():
            break
        pos = que.get()
        for arrow in direction:
            next = [pos[0] + arrow[0], pos[1] + arrow[1]]
            if next[0] == -1 or next[0] == H or next[1] == -1 or next[1] == W:
                continue
            if s[next[0]][next[1]] == "#":
                que.put(next)
                s[next[0]][next[1]] = "."


for i in range(H):
    for j in range(W):
        if s[i][j] == "#":
            # check not isolated
            is_conneted = False
            for arrow in direction:
                neighbor = [i + arrow[0], j + arrow[1]]
                if (
                    neighbor[0] == -1
                    or neighbor[0] == H
                    or neighbor[1] == -1
                    or neighbor[1] == W
                ):
                    continue
                if s[neighbor[0]][neighbor[1]] == "#":
                    is_conneted = True
                    break
            if is_conneted:
                s[i][j] = "."
                que = q.Queue()
                que.put([i, j])
                do_bfs(s, que)
# check
for i in range(H):
    for j in range(W):
        if s[i][j] == "#":
            print("No")
            exit()
print("Yes")

Submission status: Accepted

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

for i in range(H-1):
    for j in range(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: Accepted

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

Submission status: Accepted

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

def check(h,w):
    dx = [0,0,-1,1]
    dy = [1,-1,0,0]
    for k in range(len(dx)):
        if 0 <= h+dy[k] <= (H-1) and 0 <= w+dx[k] <= (W-1):
            if s[h+dy[k]][w+dx[k]] == "#":
                break
            elif k == 3:
                return True
    return False

ans = "Yes"
for i in range(H):
    for j in range(W):
        if s[i][j] == "#":
            if check(i,j):
                ans = "No"
                break
print(ans)

Submission status: Accepted

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

area = []
for i in range(h):
    array = input()
    area.append(array)


def check(i, j):
    x_1 = max(0, j-1)
    x_2 = min(j+1, w-1)
    y_1 = max(0, i-1)
    y_2 = min(i+1, h-1)
    if area[y_1][j] == '#' or area[y_2][j] == '#' or area[i][x_1] == '#' or area[i][x_2] == '#':
        a = 0
    else:
        print('No')
        exit()

for i in range(h):
    for j in range(w):
        if area[i][j] == '#':
            check(i, j)

print('Yes')

Submission status: Accepted

Solution code:
H, W=map(int, input().split())
m=[[-1 for i in range(W+2)]]
mm=[[-1]+[0 for i in range(W)]+[-1] for j in range(H)]
m=m+mm+m

for i in range(1, H+1):
  s=input()
  for j in range(1, W+1):
    if s[j-1]=='#':
      m[i][j]=1
      
out='Yes'
for i in range(1, H+1):
  for j in range(1, W+1):
    if m[i][j]==1:
      if m[i-1][j]<1 and m[i+1][j]<1 and m[i][j-1]<1 and m[i][j+1]<1:
        out='No'
        
print(out)

Submission status: Accepted

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

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

ans = 'Yes'

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**6)
if sys.platform in (['ios','darwin','win32']):
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

H, W = MAP()
M = [input().rstrip() for _ in range(H)]

for h in range(H):
	for w in range(W):
		if M[h][w] == '#':
			# print(h, w)
			cnt = 0
			for dh, dw in [[-1,0],[0,1],[1,0],[0,-1]]:
				nh = h+dh
				nw = w+dw
				if nh < H and nh >= 0 and nw < W and nw >= 0:
					cnt += 1
					if M[nh][nw] == '.':
						cnt -= 1
			if cnt == 0:
				print('No')
				sys.exit()

print('Yes')

Submission status: Accepted

Solution code:
#テストファイルで実行する時
import sys
if sys.platform =='ios':
	sys.stdin=open('input_file.txt')

h,w = map(int,input().split())
s = [str('#'+input())+'#' for i in range(h)]

test = ''
for i in range(w+2):
	test = test + '#' 

#リストsの頭にtestを追加
s.insert(0,test)

#リストsの最後にtestを追加
s.insert(len(s),test)

#for i in range(h+2):
#	print(''.join(s[i]))

check = 0

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]=='.':
				check = check + 1

print('Yes' if check ==0 else 'No')

Submission status: Accepted

Solution code:
# WIP
import sys


sys_input = sys.stdin.readline

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

areamap = []
areamap.append(['.']*(W+2))
for h in enumerate(range(H)):
    row = list(sys_input().replace('\n', ''))
    row = ['.'] + row + ['.']
    areamap.append(row)
areamap.append(['.']*(W+2))

for h in range(1, H+1):
    for w in range(1, W+1):
        if areamap[h][w] == '#' and \
                areamap[h][w+1] == '.' and \
                areamap[h][w-1] == '.' and \
                areamap[h+1][w] == '.' and \
                areamap[h-1][w] == '.':
            print('No')
            exit()

print('Yes')

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(H):
    for j in range(W):
        if canvas[i][j] == '#':
            up_cell = canvas[i - 1][j] if i > 0 else '.'
            down_cell = canvas[i + 1][j] if i < H - 1 else '.'
            right_cell = canvas[i][j + 1] if j < W - 1 else '.'
            left_cell = canvas[i][j - 1] if j > 0 else '.'
            if up_cell == '.' and down_cell == '.' and right_cell == '.' and left_cell == '.':
                print('No')
                exit()
print('Yes')

Submission status: Accepted

Solution code:
from collections import deque
h, w = map(int, input().split())
s = [list(input()) for i in range(h)]
for i in range(h):
    for j in range(w):
        if s[i][j] == '#':
            A = False
            B = False
            C = False
            D = False
            if i != h-1 and s[i+1][j] == '#':
                A = True
            if i != 0 and s[i-1][j] == '#':
                B = True
            if j != w-1 and s[i][j+1] == '#':
                C = True
            if j != 0 and s[i][j-1] == '#':
                D = True
            if not A and not B and not C and not D:
                print('No')
                exit(0)
print('Yes')

Submission status: Accepted

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

grid = []
grid.append(['.'] * (w + 2))
for _ in range(h):
    word = '.' + input() + '.'
    grid.append([i for i in word])
grid.append(['.'] * (w + 2))

for i in range(1, h):
    for j in range(1, w):
        if grid[i][j] == '#':
            if grid[i][j-1] == '#' or grid[i-1][j] == '#' or grid[i][j+1] == '#' or grid[i+1][j] == '#':
                pass
            else:
                print('No')
                exit()

print('Yes')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
S = ["."*(w+2)] + [ "."+input()+"." for _ in range(h) ] + ["."*(w+2)]
for i in range(h+2):
  for j in range(w+2):
    if S[i][j] == "#":
      for k in range(4):
        if S[i+1][j] != "#" and S[i][j+1] != "#" and S[i-1][j] != "#" and S[i][j-1] != "#":
          print("No")
          exit()
print("Yes")

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
s = [input() for _ in range(h)]
ans = 'Yes'
x = [[-1, 0], [0, -1], [1, 0], [0, 1]]
for i in range(h):
    for j in range(w):
        if s[i][j] == '#':
            flag = 1
            for k in x:
                if 0 <= i + k[0] < h and 0 <= j + k[1] < w and s[i + k[0]][j + k[1]] == '#':
                    flag = 0
            if flag:
                ans = 'No'
print(ans)

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
s = [input() for _ in range(h)]
ans = 'Yes'
x = [[-1, 0], [0, -1], [1, 0], [0, 1]]
for i in range(h):
    for j in range(w):
        if s[i][j] == '#':
            flag = 0
            for k in x:
                if 0 <= i + k[0] < h and 0 <= j + k[1] < w and s[i + k[0]][j + k[1]] == '#':
                    flag = 1
            if flag < 1:
                ans = 'No'
print(ans)

Submission status: Accepted

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

S_array = [[0 for i in range(W+2)]]

for i in range(1,H+1):
    S = list(input())
    S_array.append([0]+S+[0])
    
S_array.append([0 for i in range(W+2)])

No_flag = 0

#H,W <= 50 なので 最大2500ループで済むので通る
for i in range(1,H+1):
    for j in range(1,W+1):
        if S_array[i][j]=="#" and S_array[i+1][j]!="#" and S_array[i][j+1]!="#" and S_array[i-1][j]!="#" and S_array[i][j-1]!="#":
            print("No")
            No_flag = 1
            break
    if No_flag == 1:
        break
else:
    print("Yes")

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
L = ['.'*(w+1)]
for i in range(h):
  L.append('.'+input()+'.')
L.append('.'*(w+1))  

out = 1
for i in range(1, h+1):
  for j in range(1, w+1):
    if L[i][j] == '#':
      if L[i][j+1] == '#' or L[i][j-1] == '#' or L[i-1][j] == '#' or L[i+1][j] == '#':
        out *= 1
      else:
        out *= 0

if out == 1:
  print('Yes')
else:
  print('No')

Submission status: Accepted

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

dx = [0,1,0,-1]
dy = [1,0,-1,0]
for i in range(H):
    for j in range(W):
        if stage[i][j] == ".":
            continue
        Flag = True
        for k in range(4):
            if 0 <= j + dx[k] < W and 0 <= i + dy[k] < H and stage[i + dy[k]][j + dx[k]] == "#":
                Flag = False
                break
        if Flag:
            print("No")
            exit()
print("Yes")

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
li=[list(input()) for i in range(h)]
yoko=[[1,0],[-1,0],[0,1],[0,-1]]
import itertools
for i in range(h):
  for j in range(w):
    if li[i][j]=="#":
      flag=0
      for dx,dy in yoko:
        if h>i+dx>=0 and w>j+dy>=0:
          if li[i+dx][j+dy]=="#":
            flag+=1
      if flag==0:
        print("No")
        exit()
print("Yes")

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
li=[list(input()) for i in range(h)]
yoko=[[1,0],[-1,0],[0,1],[0,-1]]
import itertools
for i in range(h):
  for j in range(w):
    if li[i][j]=="#":
      flag=0
      for za in yoko:
        dx=za[0]
        dy=za[1]
        if h>i+dx>=0 and w>j+dy>=0:
          if li[i+dx][j+dy]=="#":
            flag+=1
      if flag==0:
        print("No")
        exit()
print("Yes")

Submission status: Accepted

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

d = [(1,0),(-1,0),(0,1),(0,-1)]
ans = True

for i in range(H):
    for j in range(W):
        if Grid[i][j] == '#':
            count = 0
            for dx, dy in d:
                if 0 <= i + dy and i + dy <= H-1 and 0 <= j + dx and j + dx <= W-1:
                    if Grid[i+dy][j+dx] == '#':
                        count += 1
        
            if count == 0:
                ans = False
                break

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

Submission status: Accepted

Solution code:
import numpy as np
H,W=map(int,input().split())
X=np.array([list(input()) for _ in range(H)])
Y=np.array([[0]*(W+2)]*(H+2))

for i in range(H):
  for j in range(W):
    if X[i][j]=='#':
      Y[i+1][j+1]=1
      
hantei = True      
for i in range(1,H+1):
  for j in range(1,W+1):
    if Y[i][j]==1:
      if Y[i-1][j]==0 and Y[i+1][j]==0 and Y[i][j+1]==0 and Y[i][j-1]==0:
        hantei =False
        break
print('Yes' if hantei else'No')

Submission status: Accepted

Solution code:
H,W=map(int,input().split())
s=[[0 for x in range(W+2)] for y in range(H+2)]
for y in range(1,H+1):
	t=input()
	for i in range(W):
		if t[i]=='#':
			s[y][i+1]=1

for y in range(1,H+1):
	for x in range(1,W+1):
		if s[y][x]==1:
			for d in [[-1,0],[1,0],[0,-1],[0,1]]:
				f=False
				if s[y+d[0]][x+d[1]]==1:
					f=True
					break
			if f==False:
				print('No')
				exit()

print('Yes')

Submission status: Accepted

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

for i in range(H):
  for j in range(W):
    if S[i][j]=="#":
      if   i>=1 and S[i-1][j]=="#":
        continue
      elif i<=H-2 and S[i+1][j]=="#":
        continue
      elif j>=1 and S[i][j-1]=="#":
        continue
      elif j<=W-2 and S[i][j+1]=="#":
        continue
      else:
        print("No");exit()
print("Yes")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a,b = list(map(int, input().split()))

cs = []
cs.append("." * (b+2))
for i in range(a):
  s = "." + input() + "."
  cs.append(s)
cs.append("." * (b+2))

ans = True
for i in range(a):
  for j in range(b):
    if cs[i][j] == "#":
      if cs[i-1][j] == "." and cs[i][j-1] == "." and cs[i+1][j] == "." and cs[i][j+1] == ".":
        ans = False
        break
    if not ans:
      break
  if not ans:
    break
if ans:
  print("Yes")
else:
  print("No")

Submission status: Accepted

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

grid=[None]*h
for i in range(h):
  grid[i]=input()
  
def isOk(y,x):
  if y-1>=0 and grid[y-1][x]=="#":
    return True
  if y+1<h and grid[y+1][x]=="#":
    return True
  if x-1>=0 and grid[y][x-1]=="#":
    return True
  if x+1<w and grid[y][x+1]=="#":
    return True
  return False
  
for i in range(h):
  for j in range(w):
    if grid[i][j]=="#":
      if not isOk(i,j):
        print("No")
        exit(0)
print("Yes")

Submission status: Accepted

Solution code:
H, W = map(int,input().split())
s = [list(input()) for i in range(H)]
ans = "Yes"
for i in range(H):
    for j in range(W):
        tmp = 1
        if s[i][j] == "#":
            tmp = 0
            if i > 0:
                if s[i-1][j] == "#":
                    tmp = 1
            if i < H - 1:
                if s[i+1][j] == "#":
                    tmp = 1
            if j > 0:
                if s[i][j-1] == "#":
                    tmp = 1
            if j < W - 1:
                if s[i][j+1] == "#":
                    tmp = 1
            if tmp == 0:
                ans ="No"
                break
    if tmp == 0:
        break
print(ans)

Submission status: Accepted

Solution code:
def judge(L,i,j):
    a=0
    if L[i][j]=="#":
        a= (L[i-1][j]!="#" and L[i+1][j]!="#"
        and L[i][j-1]!="#" and L[i][j+1]!="#")
    return a

h,w=map(int,input().split())
A=[input() for _ in range(h)]
ans=0

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

for i in range(h+2):
    for j in range(w+2):
        if judge(A,i,j)==1:
            ans=1

print("Yes" if ans==0 else "No")

Submission status: Accepted

Solution code:
def judge(L,i,j):
    a=0
    if L[i][j]=="#":
        a= (L[i-1][j]!="#" and L[i+1][j]!="#"
        and L[i][j-1]!="#" and L[i][j+1]!="#")
    return a

def judge_ed(L,i,j):
    a=0
    if L[i][j]=="#":
        if i == 0:
            a= (L[i+1][j]!="#" and L[i][j-1]!="#" and L[i][j+1]!="#")
        elif i == h-1:
            a= (L[i-1][j]!="#" and L[i][j-1]!="#" and L[i][j+1]!="#")
        elif j == 0:
            a= (L[i-1][j]!="#" and L[i+1][j]!="#" and L[i][j+1]!="#")
        else:
            a= (L[i-1][j]!="#" and L[i+1][j]!="#" and L[i][j-1]!="#")
    return a

h,w=map(int,input().split())
A=[input() for _ in range(h)]
ans=0

for i in range(h):
    for j in range(w):
        a=0
        if i in (0,h-1) and j in (0,w-1):a=0
        elif i in (0,h-1) or j in (0,w-1):
            a = judge_ed(A,i,j)
        else:a = judge(A,i,j)
        if a==1:
            ans=1

print("Yes" if ans==0 else "No")

Submission status: Accepted

Solution code:
def examC():
    H, W = LI()
    S = [SI() for _ in range(H)]
    ans = "Yes"
    for i in range(H):
        for j in range(W):
            if S[i][j]=="#":
                if (i>0 and S[i-1][j]==".") or i==0:
                    if (H-1>i and S[i+1][j]==".") or i==H-1:
                        if (j>0 and S[i][j-1]==".") or j==0:
                            if (W-1>j and S[i][j+1]==".") or j==H-1:
                                ans = "No"
    print(ans)


import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examC()

Submission status: Accepted

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

S = [[x for x in str(input())] for _ in range(h)]

for i in range(h):
    S[i].insert(0, '/')
    S[i].append('/')

S.insert(0, ['/']*(w+2))
S.append(['/']*(w+2))

count = 0

for j in range(1, h+1):
    for k in range(1, w+1):
        if S[j][k] == '#':
            count += 1
            if S[j-1][k].count('#') + S[j+1][k].count('#') + S[j][k-1].count('#') + S[j][k+1].count('#') >= 1:
                count -= 1

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

Submission status: Accepted

Solution code:
H, W = map(int,input().split())
s = [[i for i in list(input())] for j in range(H)]
dx = [0,0,-1,1]
dy = [-1,1,0,0]
 
for i in range(H):
    for j in range(W):
        if s[i][j] == ".": continue
 
        # 上下左右の4方向
        for k in range(4):
            ni = i + dy[k]
            nj = j + dx[k]
 
            if ni < 0 or ni >= H: continue
            if nj < 0 or nj >= W: continue
 
            if s[ni][nj] == "#": break
            if k == 3:
                print("No")
                exit()
 
print("Yes")

Submission status: Accepted

Solution code:
import numpy as np
H, W = map(int, input().split())
grid = np.zeros((H, W), dtype="unicode")
for h in range(H):
    input_ = input()
    for w in range(W):
        grid[h, w] = input_[w]
    
h_candi = [0, 0, 1, -1]
w_candi = [1, -1, 0, 0]

cannot_flag = 0
for h in range(H):
    if cannot_flag:
        break
    for w in range(W):
        if grid[h, w] == ".":
            continue
        count = 0
        for h_, w_ in zip(h_candi, w_candi):
            h_idx = h + h_
            w_idx = w + w_
            if (h_idx < 0) or (h_idx >= H):
                continue
            if (w_idx < 0) or (w_idx >= W):
                continue
            if grid[h_idx, w_idx] == "#":
                count += 1
        if count == 0:
            cannot_flag = 1
            break

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

Submission status: Accepted

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

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

s2 = []

for i in range(h + 2):
    if i == 0 or i == h + 1:
        s2.append("." * (w + 2))
    else:
        s2.append("." + s[i - 1] + ".")
# print(s2)

c = []

for i in range(1, h + 1):
    for j in range(1, w + 1):
        if s2[i][j] == "#":
            c.append(
                (s2[i - 1][j] == "#")
                + (s2[i + 1][j] == "#")
                + (s2[i][j - 1] == "#")
                + (s2[i][j + 1] == "#")
            )
# print(c)

if c.count(0) > 0:
    print("No")
else:
    print("Yes")