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())
#左右に'.'を余分に付けて標準入力からリストを作成
grid = [list('.'+input()+'.') for i in range(H)]
#上下にも付けてやる
grid.insert(0, list('.' * (W + 2)))
grid.append(list('.' * (W + 2)))

tmp = 0
for i in range(1, H + 1):
  for j in range(1, W + 1):
    if grid[i][j] == '#' and (grid[i-1][j:j+1]+grid[i][j-1:j+2]+grid[i+1][j:j+1]).count('#') == 1:
        tmp += 1

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

Submission status: Accepted

Solution code:
import sys
h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]
hantei = [[0 for _ in range(w)] for _ in range(h)]
for i in range(h):
    for j in range(w):
        if s[i][j] == "#":
            if i < h-1:
                if s[i+1][j] == "#":
                    hantei[i][j] = 1
                    hantei[i+1][j] = 1
            if j < w-1:
                if s[i][j+1] == "#":
                    hantei[i][j] = 1
                    hantei[i][j+1] = 1

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

print("Yes")

Submission status: Accepted

Solution code:
H,W=map(int,input().split())
s=[list(input()) for _ in range(H)]
s2=[["" for _ in range(W)] for _ in range(H)]
flag=1
#print(s,s2)
for i in range(H):
    for j in range(W):
        if s[i][j]=="#":
            if (i==0):
                if (j==0):
                    if not((s[i][j+1]=="#")or(s[i+1][j]=="#")):
                        flag=0
                elif (j==W-1):
                    if not((s[i][j-1]=="#")or(s[i+1][j]=="#")):
                        flag=0
                else:
                    if not((s[i][j-1]=="#")or(s[i][j+1]=="#")or(s[i+1][j]=="#")):
                        flag = 0

            elif (i==H-1):
                if (j==0):
                    if not((s[i-1][j]=="#")or(s[i][j+1]=="#")):
                        flag=0
                elif (j==W-1):
                    if not((s[i-1][j]=="#")or(s[i][j-1]=="#")):
                        flag=0
                else:
                    if not((s[i][j+1]=="#")or(s[i-1][j]=="#")or(s[i][j-1]=="#")):
                        flag=0
            else:
                if (j==0):
                    if not ((s[i + 1][j] == "#") or (s[i - 1][j] == "#") or (s[i][j + 1] == "#")):
                        flag = 0
                elif (j==W-1):
                    if not ((s[i + 1][j] == "#") or (s[i - 1][j] == "#") or (s[i][j - 1] == "#")):
                        flag = 0
                else:
                    if not((s[i+1][j]=="#")or(s[i-1][j]=="#")or(s[i][j+1]=="#")or(s[i][j-1]=="#")):
                        flag=0
if flag==1:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
#N,Wを入力
H,W = map(int, input().split())

trout = []

for i in range(H):
    trout.append(list(input()))

# 配列の比較用の変数
h = H-1
w = W-1

reslut = "Yes"
for i in range(H):
    for j in range(W):
        
        c = -1
        # "."だったらスルー
        if trout[i][j] == ".":
            pass
        
        else:
             # 真上
            if i>=1 and trout[i-1][j] == "#":
                c = 1
             # 左
            if j>=1 and trout[i][j-1] == "#":
                c = 1
            # 右
            if j<w and trout[i][j+1] == "#":
                c = 1
            # 真下
            if i<h and trout[i+1][j] == "#":
                c = 1
            
            if c == -1:
                reslut = "No"
                break
    else:
        continue
    break
    
print(reslut)

Submission status: Accepted

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

for i in range(H):
  c = list(input())
  grid[i] = c
  
black = "#"
white = "."

ans = "Yes"

for i in range(H):
  for j in range(W):
    if grid[i][j] == black:
      around = ""
      #ヨコ
      for t in range(max(0,j - 1),min(W,j + 2)):
        if t != j:
          around += grid[i][t]
      #タテ
      for k in range(max(0,i - 1),min(H,i + 2)):
        if k != i:
          around += grid[k][j]
      
      if all([s == white for s in around]):
        ans = "No"
        break
  if ans == "No":
    break
      
print(ans)

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
s = [['.' for i in range(w + 2)] for j in range(h + 2)]
for i in range(h):
    t = str(input())
    for j in range(w):
        s[i+1][j+1] = t[j]
# 判定
ans = "Yes"
for i in range(1, h+1):
    for j in range(1, w+1):
        if s[i][j] == '.': continue
        if 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:
H, W = map(int, input().split())
S = [list(input()) for i in range(H)]

check_pat = [(1, 0), (-1, 0), (0, -1), (0, 1)]
for i in range(H):
    for j in range(W):
        if S[i][j] == ".":
            continue

        if H == 1:
            if W == 1:
                check_pat = []
            elif j == W-1:
                check_pat = [(0, -1)]
            else:
                check_pat = [(0, -1), (0, 1)]
        elif i == 0:
            if W == 1:
                check_pat = [(1, 0)]
            elif j == W-1:
                check_pat = [(1, 0), (0, -1)]
            else:
                check_pat = [(1, 0), (0, -1), (0, 1)]
        elif i == H-1:
            if W == 1:
                check_pat = [(-1, 0)]
            elif j == W-1:
                check_pat = [(-1, 0), (0, -1)]
            else:
                check_pat = [(-1, 0), (0, -1), (0, 1)]
        else:
            if W == 1:
                check_pat = [(-1, 0), (1, 0)]
            elif j == W-1:
                check_pat = [(-1, 0), (1, 0), (0, -1)]
            else:
                check_pat = [(-1, 0), (1, 0), (0, -1), (0, 1)]

        ng_flg = 1
        for pat in check_pat:
            if S[i+pat[0]][j+pat[1]] == "#":
                ng_flg = 0
                break
        if ng_flg == 1:
            print("No")
            exit()

print("Yes")

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
pic = [list(input()) for _ in range(H)]
ans = 'Yes'
for i in range(H):
    for j in range(W):
        if pic[i][j] == '#':
            if j != 0 and pic[i][j-1] == '#':
                continue
            if j != W-1 and pic[i][j+1] == '#':
                continue
            if i != 0 and pic[i-1][j] == '#':
                continue
            if i != H-1 and pic[i+1][j] == '#':
                continue
            ans = 'No'
            print(ans)
            exit()
print(ans)

Submission status: Accepted

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

src = [input() for i in range(H)]

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

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

Submission status: Accepted

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

s = []
for i in range(h):
    s.append([x for x in input().split()])


for i in range(h):
    for j in range(w):
        cnt = 0
        shape = 0

        if s[i][0][j] == "#":
            if i != 0 :
                cnt += 1
                if s[i-1][0][j] == "#":
                    shape += 1
            if i != h-1:
                cnt += 1
                if s[i+1][0][j] == "#":
                    shape += 1
            if j != 0:
                cnt += 1
                if s[i][0][j-1] == "#":
                    shape += 1
            if j != w-1:
                cnt += 1
                if s[i][0][j+1] == "#":
                    shape += 1

            if shape == 0:
                print("No")
                exit(0)

print("Yes")

Submission status: Accepted

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

    for hi in range(h):
        for wi in range(w):
            if s[hi][wi] == '.':
                continue

            flag = False
            for d in [[-1, 0], [1, 0], [0, -1], [0, 1]]:
                hp = hi + d[0]
                wp = wi + d[1]
                if hp < 0 or hp >= len(s) or wp < 0 or wp >= len(s[0]):
                    continue

                if s[hp][wp] == '#':
                    flag = True

            if not flag:
                print('No')
                exit()

    print('Yes')


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def main():
    H, W = map(int, input().split())
    matrix = [list(input()) for _ in range(H)]
    for r in matrix:
        r.insert(0, ".")
        r.append(".")
    matrix.insert(0, ["."] * (W + 2))
    matrix.append(["."] * (W + 2))

    ans = "Yes"
    for r in range(1, H + 1):
        for c in range(1, W + 1):
            if matrix[r][c] == ".":
                continue
            if matrix[r-1][c] == "." and matrix[r+1][c] == "." and matrix[r][c-1] == "." and matrix[r][c+1] == ".":
                ans = "No"
                break
        if ans == "No":
            break
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

dx=[-1,0,1,0]
dy=[0,1,0,-1]
for i in range(h):
    for j in range(w):
        if grid[i][j]=='#':
            flag=False
            for k in range(4):
                x=i+dx[k]
                y=j+dy[k]
                if 0<=x<h and 0<=y<w and grid[x][y]=='#':
                    flag=True
                    break
            if flag:
                continue
            else:
                print('No')
                exit()
print('Yes')

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
gridgraph = ['.'*(W+2)]
for _ in range(H):
    area = input()
    gridgraph.append('.'+area+'.')
gridgraph.append('.'*(W+2))
# print(*gridgraph, sep='\n')

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

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
g=[input() for _ in range(h)]
for x in range(1,h-1):
  for y in range(1,w-1):
    if g[x][y]=='#' and all(g[x+dx][y+dy]=='.' for dx,dy in ((1,0),(0,1),(-1,0),(0,-1))):
      print('No'); exit()
print('Yes')

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
g=[input() for _ in range(h)]
for x in range(h):
  for y in range(w):
    if g[x][y]=='#':
      f=1
      for dx,dy in ((1,0),(0,1),(-1,0),(0,-1)):
        nx,ny=x+dx,y+dy
        if nx<0 or nx>=h or ny<0 or ny>=w:
          continue
        elif g[nx][ny]=='#':
          f=0
      if f:
        print('No')
        break
  else:
    continue
  break
else:
  print('Yes')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
s= [input() for _ in range(h)]
neighbor = [(-1,0),(0,-1),(1,0),(0,1)]
for i in range(h):
    for j in range(w):
        if s[i][j] == '.':
            continue
        else:
            flag = False
            for nei in neighbor:
                n = (i+nei[0],j+nei[1])
                if n[0]<0 or n[1]<0 or n[0]>=h or n[1]>=w:
                    continue
                if s[n[0]][n[1]] == '#':
                    flag = True
                    break
            if flag == False:
                print('No')
                exit()
print('Yes')

Submission status: Accepted

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

s = []
for _ in range(h):
    s.append(list(input()))

def ok(i, j):
    global h, w, s
    if i > 0 and s[i - 1][j] == '#':
        return True
    if i < h - 1 and s[i + 1][j] == '#':
        return True
    if j > 0 and s[i][j - 1] == '#':
        return True
    if j < w - 1 and s[i][j + 1] == '#':
        return True
    return False

for i in range(h):
    for j in range(w):
        if s[i][j] == '#' and not ok(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 h in range(H) :
    for w in range(W) :
        if S[h][w] == "#" :
            check = False
            for a in [-1,1] :
                if h+a >= 0 and S[h+a:] :
                    if S[h+a][w] == "#" :
                        check = True
            for b in [-1,1] :
                if w+b >= 0 and S[h][w+b:] :
                    if S[h][w+b]== "#" :
                        check = True
            if check == False :
                ans = "No"

print(ans)

Submission status: Accepted

Solution code:
H, W = map(int,input().split())
mp = [list(input()) for i in range(H)]
for i in range(H):
    mp[i].insert(0,'.')
    mp[i].append('.')
lo = ['.' for i in range(W+2)]
mp.insert(0,lo)
mp.append(lo)

dir =[[-1,0], [0,-1], [0,1], [1,0]]
def check(x,y):
    if mp[x][y] =='#':
        bw =False
        for i in range(len(dir)):
            if mp[x + dir[i][0]][y + dir[i][1]] =='#':
                bw = True
        if bw == True:
            return True
        else:
            return False
    else:
        return True

ok =True
for i in range(1,H+1):
    for k in range(1,W+1):
        if check(i,k) == False:
            ok = False
            break

if ok == True:
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

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

for i in range(H):
    for j in range(W):
        if status[i][j] == "#":
            if i - 1 >= 0:
                if status[i - 1][j] == "#":
                    continue
            if i + 1 <= H -1:
                if status[i + 1][j] == "#":
                    continue
            if j - 1 >= 0:
                if status[i][j - 1] == "#":
                    continue
            if j + 1 <= W -1:
                if status[i][j + 1] == "#":
                    continue
            print("No")
            exit()
print("Yes")

Submission status: Accepted

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

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

for i in range(H):
    for j in range(W):
        if status[i][j] == "#":
            flag = 0
            if i - 1 >= 0:
                if status[i - 1][j] == "#":
                    flag = 1
                    continue
            if i + 1 <= H -1:
                if status[i + 1][j] == "#":
                    flag = 1
                    continue
            if j - 1 >= 0:
                if status[i][j - 1] == "#":
                    flag = 1
                    continue
            if j + 1 <= W -1:
                if status[i][j + 1] == "#":
                    flag = 1
                    continue
            if flag == 0:
                print("No")
                exit()
print("Yes")

Submission status: Accepted

Solution code:
import sys
 
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
 
ni = lambda: int(ns())
nin = lambda y: [ni() for _ in range(y)]
na = lambda: list(map(int, stdin.readline().split()))
nan = lambda y: [na() for _ in range(y)]
ns = lambda: stdin.readline().rstrip()
nsn = lambda y: [ns() for _ in range(y)]
ncl = lambda y: [list(ns()) for _ in range(y)]
nas = lambda: stdin.readline().split()

H, W = na()
M = ncl(H)
dx, dy = [0, 1, -1, 0], [1, 0, 0, -1]

flag = True
for i in range(H):
    for j in range(W):
        if M[i][j] == '#':
            ok = False
            for k in range(4):
                nx, ny = j + dx[k], i + dy[k]
                if 0 <= nx and nx < W and 0 <= ny and ny < H and M[ny][nx] == '#':
                    ok = True
            if not ok:
                flag = False

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

Submission status: Accepted

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

black=[(i,j) for i in range(0,H) for j in range(0,W) if s[i][0][j]=='#']

flag=0
for i in range(0,H):
    for j in range(0,W):
        if (i,j) in black:
            if not ((i+1,j) in black or (i,j+1) in black or (i-1,j) in black or (i,j-1) in black):
                flag=1
if flag==0:
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

ans = "Yes"
for i in range(h):
    for j in range(w):
        if mass[i][j] == "#":
            if i < h-1:
                if mass[i+1][j] == "#":
                    continue
            if 0 < i:
                if mass[i-1][j] == "#":
                    continue
            if j < w-1:
                if mass[i][j+1] == "#":
                    continue
            if 0 < j:
                if mass[i][j-1] == "#":
                    continue
            ans = "No"
            break

print(ans)

Submission status: Accepted

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


def check(all_S_list):
    delta_list = [        [-1,0],
                   [0,-1],        [0,1],
                           [1,0]
                 ]

    for i in range(H):
        for j in range(W):
            
            if all_S_list[i][j] == "#":
            
                next_too_flag = False
                for d_i,d_j in delta_list:
                    check_i = i + d_i
                    check_j = j + d_j
                    
                    if check_i < 0 or (H-1) < check_i: continue
                    if check_j < 0 or (W-1) < check_j: continue
 
                    if all_S_list[check_i][check_j] == "#":
                        next_too_flag = True
                
                if next_too_flag == False:
                    return False
    
    return True

#----------
H,W = list(map(int, input().rstrip().split()))
all_S_list = [ list(input().strip()) for _ in range(H) ]
#----------
if check(all_S_list):
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

t=".."
for _ in range(w):
  t += "."

s=[]
s.append(t)
for i in range(h):
  s.append("." + input() + ".")
s.append(t)
f=True
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] != "#" :
          f=False
if f:
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
dx=[1,-1,0,0]
dy=[0,0,1,-1]
s=[]
for i in range(h):
    s.append(list(input()))
for i in range(h):
    for j in range(w):
        if s[i][j]=="#":
            for t in range(4):
                if all(s[i+dy[t]][j+dx[t]]!="#" for t in range(4) if 0<=i+dy[t]<=h-1 and 0<= j+dx[t] <= w-1):
                    print("No")
                    exit(0)
                else:
                    pass
print("Yes")

Submission status: Accepted

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

L=[]
l=["." for i in range(W+2)]
L.append(l)
for i in range(H):
    S=["."]+list(input())+["."]
    L.append(S)
L.append(l)
#print(L)
X=[1,-1,0,0]
Y=[0,0,1,-1]
for h in range(1,H+1):
    for w in range(1,W+1):
        if L[h][w]=="#":
            F=0
            for i in range(4):
                if L[h+X[i]][w+Y[i]]=="#":
                    F=1
            if F==0:
                print("No")
                exit()
print("Yes")

Submission status: Accepted

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

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]=='.':
                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]=='#':
      flg = 0
      flg += 1 if i-1>=0 and S[i-1][j]=='#' else 0
      flg += 1 if i+1<H and S[i+1][j]=='#' else 0
      flg += 1 if j-1>=0 and S[i][j-1]=='#' else 0
      flg += 1 if j+1<W and S[i][j+1]=='#' else 0
      if flg==0:
        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)
ans="Yes"
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:
                ans="No"
        if ans=="No":
            break
    if ans=="No":
        break
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
h, w = map(int, input().split())
grid = np.array([list(input()) for _ in range(h)])

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

flag = False
for x in range(h):
    for y in range(w):
        if grid[x, y] == '.':
            continue
        for i in range(4):
            nx = x + dx[i]
            ny = y + dy[i]
            if nx >= 0 and nx < h and ny >= 0 and ny < w:
                if grid[nx, ny] == '#':
                    break
        else:
            flag = True
            break
    if flag:
        break

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

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
s = []
OK = True
# OK1 = True
# OK2 = True
# OK3 = True
# OK4 = True
for _ in range(H):
    s.append(input())
for i in range(H):
    for j in range(W):
        OK1 = True
        OK2 = True
        OK3 = True
        OK4 = True
        if s[i][j] == '#':
            if i != 0:
                if s[i-1][j] != '#':
                    OK1 = False
            if i != H-1:
                if s[i+1][j] != '#':
                    OK2 = False
            if j != 0:
                if s[i][j-1] != '#':
                    OK3 = False
            if j != W-1:
                if s[i][j+1] != '#':
                    OK4 = False
        if OK1 or OK2 or OK3 or OK4:
            continue
        else:
            OK = False

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

Submission status: Accepted

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

for i in range(h):
    for j in range(w):
        if s[i][j] == '#':
            chk = False
            # UP
            if not i == 0:
                if s[i-1][j] == '#':
                    chk = True
            # DOWN
            if not i == h-1:
                if s[i+1][j] == '#':
                    chk = True
            # LEFT
            if not j == 0:
                if s[i][j-1] == '#':
                    chk = True
            # RIGHT
            if not j == w-1:
                if s[i][j+1] == '#':
                    chk = True
            if chk:
                pass
            else:
                print('No')
                exit()

print('Yes')

Submission status: Accepted

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

h, w = map(int, input().split())
s = [[j for j in input()] for i in range(h)]
# print(s)
for i in range(h):
    flag = False
    for j in range(w):
        if s[i][j] == "#":
            con1 = True
            con2 = True
            con3 = True
            con4 = True
            if 0 <= i + 1 < h:
                if s[i + 1][j] == ".":
                    con1 = False
            if 0 <= j - 1 < w:
                if s[i][j - 1] == ".":
                    con2 = False
            if 0 <= i - 1 < h:
                if s[i - 1][j] == ".":
                    con3 = False
            if 0 <= j + 1 < w:
                if s[i][j + 1] == ".":
                    con4 = False
            if con1 == con2 == con3 == con4 == False:
                flag = True
                # print(i, j)
                print("No")
                break
    if flag:
        break
else:
    print("Yes")

Submission status: Accepted

Solution code:
import sys
H,W=map(int,input().split())
smap=[input() for i in range(H)]
dx=[1,0,-1,0]
dy=[0,1,0,-1]

for i in range(H):
    for j in range(W):
        if(smap[i][j]=='#'):
            t=True
            for k in range(4):
                ni=i+dx[k]
                nj=j+dy[k]
                if(ni<0 or ni>=H or nj<0 or nj>=W):
                    continue
                if(smap[ni][nj]=='#'):
                    t=False
            if(t):
                print("No")
                sys.exit()
print("Yes")

Submission status: Accepted

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

def a(s, h, w, diff):
    num, cnt = 0, 0
    for i in range(h):
        for j in range(w):
            if s[i][j]=='#':
                for k in diff:
                    i += k[0]
                    j += k[1]
                    if (0<=i and i<=h-1) and (0<=j and j<=w-1):
                        num += 1
                        if s[i][j]=='.':
                            cnt += 1
                    i -= k[0]
                    j -= k[1]
                if cnt==num:
                    return print('No')
            num, cnt = 0, 0
    return print('Yes')
a(s, h, w, diff)

Submission status: Accepted

Solution code:
import bisect
import cmath
import heapq
import itertools
import math
import operator
import os
import random
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353


H, W = list(map(int, sys.stdin.buffer.readline().split()))
S = [sys.stdin.buffer.readline().decode().rstrip() for _ in range(H)]


def black(h, w):
    if 0 <= h < H and 0 <= w < W:
        return S[h][w] == '#'
    return False

def test(h, w):
    if S[h][w] == '.':
        return True
    cnt = 0
    cnt += black(h - 1, w)
    cnt += black(h + 1, w)
    cnt += black(h, w - 1)
    cnt += black(h, w + 1)
    return cnt >= 1


ok = True
for h, w in itertools.product(range(H), range(W)):
    ok &=test(h, w)
if ok:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
s=[list(input()) for _ in range(h)]
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]==".":
      print("No") 
      exit()
print("Yes")

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
s=[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]=='#':
            cnt=0
            for k in range(4):
                nx=i+dx[k]
                ny=j+dy[k]

                if 0<=nx<=h-1 and 0<=ny<=w-1:
                    if s[nx][ny]=='#':
                        cnt=1
            if cnt!=1:
                print('No')
                exit()

print('Yes')

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
h,w = map(int,input().split())
grid = [["."]*(w+2) for _ in range(h+2)]
for i in range(h):
    s = input()
    for j in range(w):
        grid[i+1][j+1] = s[j]
for i in range(h):
    for j in range(w):
        if grid[i+1][j+1] == "#":
            if grid[i][j+1] == "."  and  grid[i+1][j] == "." and grid[i+2][j+1] == "." and grid[i+1][j+2] == ".":
                print("No")
                exit()
print("Yes")

Submission status: Accepted

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

ans="Yes"

di=[0,0,1,-1]
dj=[1,-1,0,0]

def ch(i,j):
    for k in range(4):
        if s[i+di[k]][j+dj[k]]=="#":
            return True
    return False
            


for i in range(1,H+1):
    for j in range(1,W+1):
        if s[i][j]=="#":
            if ch(i,j):
                continue
            else:
                ans="No"
                break
                
print(ans)

Submission status: Accepted

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