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 = ["."*(w+2)]+["."+input()+"." for i in range(h)]+["."*(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]==s[i][j-1]==s[i][j+1]==s[i+1][j]==".":
            print("No")
            exit()
print("Yes")

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
s=[input() for _ in range(h)]
for i in range(h):
    for j in range(w):
        if i==0:
            if j==0 and s[i][0]=='#':
                l1=[s[0][1],s[1][0],s[0][0]]
                l1l=l1.count('#')
                if l1l==1:
                    print('No')
                    exit()
            elif j==w-1 and s[i][w-1]=='#':
                r1=[s[0][w-2],s[0][w-1],s[1][w-1]]
                r1r=r1.count('#')
                if r1r==1:
                    print('No')
                    exit()
            elif s[i][j]=='#':
                l1j=[s[0][j-1],s[0][j+1],s[0][j],s[1][j]]
                l1jj=l1j.count('#')
                if l1jj==1:
                    print('No')
                    exit()
            else:pass
        elif i==h-1:
            if j==0 and s[i][0]=='#':
                lh=[s[h-1][0],s[h-2][0],s[h-1][1]]
                lhl=lh.count('#')
                if lhl==1:
                    print('No')
                    exit()
            elif j==w-1 and s[i][w-1]=='#':
                rh=[s[h-1][w-1],s[h-1][w-2],s[h-2][w-1]]
                rhr=rh.count('#')
                if rhr==1:
                    print('No')
                    exit()
            elif j!=0 and j!=w-1 and s[i][j]=='#':
                lhj=[s[i][j],s[i][j+1],s[i][j-1],s[i-1][j]]
                lhjj=lhj.count('#')
                if lhjj==1:
                    print('No')
                    exit()
        else:
            if j==0 and s[i][0]=='#':
                li=[s[i-1][0],s[i][0],s[i][1],s[i+1][0]]
                lil=li.count('#')
                if lil==1:
                    print('No')
                    exit()
            elif j==w-1 and s[i][w-1]=='#':
                ri=[s[i-1][w-1],s[i][w-1],s[i][w-2],s[i+1][w-1]]
                rir=ri.count('#')
                if rir==1:
                    print('No')
                    exit()
            elif s[i][j]=='#':
                lij=[s[i-1][j],s[i][j],s[i][j+1],s[i][j-1],s[i+1][j]]
                lijj=lij.count('#')
                if lijj==1:
                    print('No')
                    exit()
            else:pass
print('Yes')

Submission status: Accepted

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

dx = [0,0,1,-1]
dy = [1,-1,0,0]
s = []
for i in range(h):
	t = input()
	s.append(t)

for i in range(h):
	for j in range(w):
		if s[i][j] == ".":
			continue
		flg = 0
		for k in range(4):
			x = i + dx[k]
			y = j + dy[k]
			if x < 0 or x >= h or y < 0 or y >= w:
				continue
			if s[x][y] == "#":
				flg = 1
				break
		if flg == 0:
			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)]
flag = True

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]=='.':
            flag = False

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

Submission status: Accepted

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

pad_s = ['.'*(W+2)]
for h in range(H):
  pad_s.append('.' + input() + '.')
pad_s.append('.'*(W+2))

for i,ss in enumerate(pad_s):
  for j,s in enumerate(ss):
    if s == '#'\
      and pad_s[i][j+1] == '.'\
      and pad_s[i][j-1] == '.'\
      and pad_s[i+1][j] == '.'\
      and pad_s[i-1][j] == '.':
      print('No')
      exit()

print('Yes')

Submission status: Accepted

Solution code:
h,w = map(int,input().split())
t = "."*(w+2)
b = [t]
for i in range(h):
  s = str(input())
  s = "."+ s + "."
  b.append(s)
b.append(t)
for i in range(1,h+1):
  for j in range(1,w+1):
    if b[i][j] == "#":
      if all([b[i-1][j]==".",b[i+1][j]==".",b[i][j-1]==".",b[i][j+1]=="."]):
        print("No")
        exit()
print("Yes")

Submission status: Accepted

Solution code:
def checkDraw(S, y, x):
  return S[y][x] == '#'

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

for h,ss in enumerate(S):
  for w,s in enumerate(ss):
    if s == '#':
      if h == 0:
        if w == 0:
          if checkDraw(S, h+1, w) or checkDraw(S, h, w+1):
            pass
          else:
            print('No')
            exit()
        elif w == W-1:
          if checkDraw(S, h+1, w) or checkDraw(S, h, w-1):
            pass
          else:
            print('No')
            exit()
        else:
          if checkDraw(S, h+1, w) or checkDraw(S, h, w-1) or checkDraw(S, h, w+1):
            pass
          else:
            print('No')
            exit()
      if h == H-1:
        if w == 0:
          if checkDraw(S, h-1, w) or checkDraw(S, h, w+1):
            pass
          else:
            print('No',1)
            exit()
        elif w == W-1:
          if checkDraw(S, h-1, w) or checkDraw(S, h, w-1):
            pass
          else:
            print('No',2)
            exit()
        else:
          if checkDraw(S, h-1, w) or checkDraw(S, h, w-1) or checkDraw(S, h, w+1):
            pass
          else:
            print('No',3)
            exit()
      if w == 0 and 0 < h < H-1:
        if checkDraw(S, h+1, w) or checkDraw(S, h-1, w) or checkDraw(S, h, w+1):
          pass
        else:
          print('No')
          exit()
      if w == W-1 and 0 < h < H-1:
        if checkDraw(S, h+1, w) or checkDraw(S, h-1, w) or checkDraw(S, h, w-1):
          pass
        else:
          print('No')
          exit()
      if 0 < h < H-1 and 0< w < W-1:
        if checkDraw(S, h-1, w) or checkDraw(S, h+1, w) or checkDraw(S, h, w-1) or checkDraw(S, h, w+1):
          pass
        else:
          print('No')
          exit()

print('Yes')

Submission status: Accepted

Solution code:
def check_current_posi(map_list, h, w):
  _height = len(map_list)
  _width = len(map_list[0])
  if h == -1 or w == -1 or h >= _height or w >= _width:
    # 枠外
    return False

  else:
    if map_list[h][w] == "#":
      # #がある
      return True

    else:
      # #ではない
      return False

# hとwは0から
# 引数の(h,w)の上下左右のマス目を調べる
def check_around(map_list, h, w):
  posi_list = [
    [h - 1, w], #上
    [h, w - 1], #左
    [h, w + 1], #右
    [h + 1, w] #下
  ]

  _result = False

  for check_posi_h, check_posi_w in posi_list:
    if check_current_posi(map_list, check_posi_h, check_posi_w):
      _result = True
      break
  
  return _result
  

# -------------------------------------------------------------------

_input = list(map(int, input().split(" ")))

_height = _input[0]
_width = _input[1]

_input_map = []

result = True

# マス目の情報を読み込む
for h in range(_height):
  _input_map.append(list(input()))

for h in range(_height):
  if result == False:
    break

  for w in range(_width):
    if _input_map[h][w] == "#":
      if check_around(_input_map, h, w):
        continue
      else:
        result = False
        break

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

Submission status: Accepted

Solution code:
import numpy as np
import itertools
 
H, W = map(int, input().split())
S = np.array([list(input()) for _ in range(H)])

def f(H, W, S):
  for i, j in itertools.product(range(H), range(W)):
    if S[i, j] == '#':
      if np.sum(np.concatenate([S[i-1:i, j], S[i, j-1:j], S[i+1:i+2, j], S[i, j+1:j+2]]) == '#') == 0:
        return False
  return True

if f(H, W, S):
  print('Yes')
else:
  print('No')

Submission status: Accepted

Solution code:
h , w = map(int,input().split())
p = [["." for i in range(w+2)]]
for i in range(h):
    kar = []
    kar.append(".")
    kar.extend(list(input()))
    kar.append(".")
    p.append(kar)
p.append(["." for i in range(w+2)])

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

Submission status: Accepted

Solution code:
h, w = map(int,input().split())
a = []
flag = True
for i in range(h):
    aa = list(input().rstrip())
    a.append(aa)
for i in range(h):
    for j in range(w):
        if a[i][j]=='.': continue
        aa = ['','','','']
        if i!=0: aa[0] = a[i-1][j]
        if i+1!=h: aa[1] = a[i+1][j]
        if j!=0: aa[2] = a[i][j-1]
        if j+1!=w: aa[3] = a[i][j+1]
        if a[i][j] not  in aa:
            flag = False
            break
print('Yes' if flag else 'No')

Submission status: Accepted

Solution code:
import sys
H, W = map(int,input().split())
table = []
for _ in range(H):
    table.append(list(input()))
t_x = [0,1,0,-1]
t_y = [1,0,-1,0]

for x in range(H):
    for y in range(W):
        if table[x][y] == '#':
            flag = 1
            for k in range(4):
                n_x = x + t_x[k]
                n_y = y + t_y[k]
                if 0 <= n_x <= H-1 and 0 <= n_y <= W-1 and table[n_x][n_y] == '#':
                    flag = 0
            if flag:
                print('No')
                sys.exit()
print('Yes')

Submission status: Accepted

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

S = ["."*(W+2)]
ans = 'Yes'
for i in range(H):
    s = input()
    S.append('.'+s+'.')

S.append('.'*(W+2))

for i in range(1, H+1):
    for j in range(1, W+1):
        if S[i][j] == '#':
            if S[i][j+1] == '#' or S[i][j-1] == '#' or S[i+1][j] == '#' or S[i-1][j] == '#':
                continue
            else:
                ans = 'No'
                break

print(ans)

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
s=[]
s.append("."*(w+2))

for i in range(h):
    s.append("."+input()+".")
    
s.append("."*(w+2))

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

print("Yes")

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
a=[""]*(h+2)
a[0]="."*(w+2)
a[h+1]="."*(w+2)
flag=0
for i in range(h):
  a[i+1]=input()
  a[i+1]="."+a[i+1]+"."
for i in range(1,h+1):
  for j in range(1,w+1):
    if a[i][j]==".":
      continue
    elif a[i][j]=="#":
      if a[i-1][j]=="." and a[i+1][j]=="." and a[i][j-1]=="." and a[i][j+1]==".": 
        flag+=1
        print("No")
        exit()
      else:
        continue
if flag==0:
  print("Yes")

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
s = [["" for _ in range(h)] for _ in range(w)]
for i in range(h):
    S = input()
    for j in range(w):
        s[j][i] = S[j]
dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]

def bfs(x, y):
    if s[x][y] == ".":
        return True
    flag = False
    for i in range(4):
        nx = x + dx[i]
        ny = y + dy[i]
        if 0 <= nx and nx < w and 0 <= ny and ny < h:
            if s[nx][ny] == "#":
                flag = True
    return flag

ans = True
for i in range(h):
    for j in range(w):
        if bfs(j, i) == False:
            ans = False

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

Submission status: Accepted

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

ans='Yes'
for i in range(h):
    for j in range(w):
        if s[i][j]=='.':
            continue
        if i > 0 and s[i-1][j]=='#':
            continue
        if i < h-1 and s[i+1][j]=='#':
            continue
        if j > 0 and s[i][j-1]=='#':
            continue
        if j < w-1 and s[i][j+1]=='#':
            continue
        ans='No'
        break
    if ans=='No':
        break
print(ans)

Submission status: Accepted

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

ans = "Yes"
judge = 0

for i in range(w):
  for j in range(h):
    sign = 0
    
    if s[j][i] == ".":
      continue
    
    if (0<=j-1) and (s[j-1][i] == "#"):
      sign = 1
    
    if (0<=i-1) and (s[j][i-1] == "#"):
      sign = 1
      
    if (j+1<h) and (s[j+1][i] == "#"):
      sign = 1
      
    if (i+1<w) and (s[j][i+1] == "#"):
      sign = 1
      
    if sign != 1:
      ans = "No"
      judge = 1
      break
  
  if judge == 1:
    break
      
print(ans)

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
s_list = []
for i in range(H):
    s = list(input())
    s_list.append(s)
direction = [[-1, 0], [0, -1], [1, 0], [0, 1]]
for i in range(H):
    for j in range(W):
        if s_list[i][j]=="#" :
            ans = "No"
            for x,y in direction:
                if 0 <=i+x<= H-1 and 0 <=j+y<= W-1 and s_list[i+x][j+y]=="#":
                    ans = "Yes"
            if ans=="No":
                print(ans)
                exit()
print("Yes")

Submission status: Accepted

Solution code:
import sys
import numpy as np

h, w = map(int, sys.stdin.readline().split())
grid = np.array([list(sys.stdin.readline().rstrip()) for _ in range(h)], dtype='U1')
grid = np.pad(grid, 1, 'constant')
grid = grid == '#'

def main():
    res = grid[1:-1, 1:-1]
    l = grid[1:-1, :-2]
    r = grid[1:-1, 2:]
    u = grid[:-2, 1:-1]
    d = grid[2:, 1:-1]
    ans = 'No' if np.any(res & ~(l | r | u | d)) else 'Yes'
    print(ans)

if __name__ ==  '__main__':
    main()

Submission status: Accepted

Solution code:
import sys

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

field.insert(0,list('.'*w))
field.append(list('.'*w))
for i in range(h+2):
    field[i].insert(0,'.')
    field[i].append('.')

for i in range(1,h+1):
    for j in range(1,w+1):
        c = 0
        if field[i][j] == '#':
            for x,y in [[0,1], [1,0], [0,-1],[-1,0]]:
                if field[i+x][j+y] == '#':
                    c += 1
            
            if c == 0:
                print('No')
                sys.exit()
    
print('Yes')

Submission status: Accepted

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

ans = []
for s in S:
    ans.append([0 if c == '.' else 1 for c in s])

# horizontal
for i, s in enumerate(S):
    for j in range(0, W - 1):
        if (s[j] == '#') and (s[j + 1] == '#'):
            ans[i][j] = 0
            ans[i][j + 1] = 0

# vertical
S = [list(x) for x in zip(*S)]
ans = [list(x) for x in zip(*ans)]
for i, s in enumerate(S):
    for j in range(0, H - 1):
        if (s[j] == '#') and (s[j + 1] == '#'):
            ans[i][j] = 0
            ans[i][j + 1] = 0

if sum([sum(x) for x in ans]):
    print("No")
else:
    print("Yes")

Submission status: Accepted

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

dxy=[(-1,0),(0,1),(0,-1),(1,0)]
for i in range(h):
  for j in range(w):
    if s[i][j]=="#":
      f=False
      for x,y in dxy:
        
        if 0<=i+x<=h-1 and 0<=j+y<=w-1 and s[i+x][j+y]=="#":
          f=True
      
      if not f:
        print("No")
        exit()
        
        

print("Yes")

Submission status: Accepted

Solution code:
#import collections
#aa = collections.Counter(a) # list to list
#from itertools import combinations # (string,3) 3回

mod = 10**9 + 7

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

def readInts():
  return list(map(int,input().split()))
def search(S,y,x,h,w):
    #全探索で間に合うべ
    cnt = 0
    #print(y,x)
    for i in range(4):
        nx = x + dx[i]
        ny = y + dy[i]
        #print('nya',ny,nx)
        if 0 <= nx < w and 0 <= ny < h:
            #print('here',nx,ny)
            if S[ny][nx] == '#':
                cnt += 1
    #print(cnt)
    if cnt == 0:#隣接する#が一つもない
        return False
    else:
        return True

def main():
    h,w = readInts()
    S = [input() for _ in range(h)]
    #print(S)
    for i in range(h):
        for j in range(w):
            if S[i][j] == '#':
                #print(i,j)
                if search(S,i,j,h,w):
                    pass
                else:
                    print('No')
                    exit()
    print('Yes')


if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:
h,w = map(int,input().split())
s = [input()for i in range(h)]
OK = True
for i in range(h):
    for j in range(w):
        if s[i][j] == '.':continue
        ok = False
        if i-1>=0 and s[i-1][j] == '#':ok = True
        if j-1>=0 and s[i][j-1] == '#':ok = True
        if i+1<=h-1 and s[i+1][j] == '#':ok = True
        if j+1 <= w-1 and s[i][j+1] == '#':ok = True
        if not ok:
            OK = False
            break
            
if OK :print('Yes')
else:print('No')

Submission status: Accepted

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

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

def judge(y,x):
    for i in range(4):
        if (0 <= y + dy[i] and y + dy[i] <= H-1) and (0 <= x + dx[i] and x + dx[i] <= W-1):
            if s[y + dy[i]][x + dx[i]] == "#":
                return True
    return False

for y in range(H):
    for x in range(W):
        if s[y][x] == "#":
            if judge(y,x) == False:
                print("No")
                exit()
print("Yes")

Submission status: Accepted

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

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

for y in range(H):
    for x in range(W):
        flag = False
        if s[y][x] == "#":
            for i in range(4):
                if (0 <= y + dy[i] and y + dy[i] <= H-1) and (0 <= x + dx[i] and x + dx[i] <= W-1):
                    if s[y + dy[i]][x + dx[i]] == "#":
                        flag = True
                        break
            if flag == False:
                print("No")
                exit()
print("Yes")

Submission status: Accepted

Solution code:
import sys
IS = lambda: sys.stdin.readline().rstrip()
II = lambda: int(IS())
MII = lambda: list(map(int, IS().split()))

def main():
    h, w = MII()
    ss = ['.'*(w+2)]
    for i in range(h):
        s = '.'+IS()+'.'
        ss.append(s)
    ss.append('.'*(w+2))
    flag = True
    for i in range(1, h+1):
        for j in range(1, w+1):
            if ss[i][j]=='#':
                if ss[i-1][j]=='#' or ss[i+1][j]=='#' or ss[i][j-1]=='#' or ss[i][j+1]=='#':
                    continue
                else:
                    flag = False
                    break
    if flag: print('Yes')
    else: print('No')
if __name__ == '__main__':
    main()

Submission status: Accepted

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

for i in range(h):
    for j in range(w):
        if s[i][j] == '#':
            check = 0
            for x, y in ([1,0],[0,1],[0,-1],[-1,0]):
                new_h, new_w = i + x, j + y
                #print(new_h,new_w)
                if new_h < 0 or new_h >= h or new_w < 0 or new_w >= w:
                    continue
                if s[new_h][new_w] == '.':
                    check += 1
            if check == 4:
                print('No')
                quit()
print('Yes')

Submission status: Accepted

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

for i in range(h):
    for j in range(w):
        if s[i][j] == '#':
            check = 0
            for x, y in ([1,0],[0,1],[0,-1],[-1,0]):
                new_h, new_w = i + x, j + y
                #print(new_h,new_w)
                if new_h < 0 or new_h >= h or new_w < 0 or new_w >= w:
                    continue
                if s[new_h][new_w] == '.':
                    check += 1
            if check == 4:
                print('No')
                quit()
print('Yes')

Submission status: Accepted

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

for i in range(h):
    for j in range(w):
        if s[i][j] == '#':
            check = 0
            for x, y in ([1,0],[0,1],[0,-1],[-1,0]):
                new_h, new_w = i + x, j + y
                #print(new_h,new_w)
                if new_h < 0 or new_h >= h or new_w < 0 or new_w >= w:
                    continue
                if s[new_h][new_w] == '.':
                    check += 1
            if check == 4:
                print('No')
                quit()
print('Yes')

Submission status: Accepted

Solution code:
import sys
import numpy as np
#データ読み込み
H,W = list(map(int,input().split()))
data = [input().strip().split() for _ in range(H)]
data_ = np.array([list(str(data[i])) for i in range(H)])[:,2:-2]

#　上下左右ベクトル作成
vec = [[0,1],[1,0],[0,-1],[-1,0]]
# '#'の座標取得
where = np.where(data_ == '#')

# '#'の上下左右に'#'が存在するか否かを検索
for y,x in zip(where[0],where[1]):
	# '#'の上下左右の値('.' or '#')をcheckに代入
	check = [data_[y+vy, x+vx] for vy,vx in vec if (0 <= y+vy < H and 0 <= x+vx < W)]
	# checkに'#'が一つもなければ上下左右のいずれも'#'でない→２連続となっていない
	if '#' in  check:
		continue
	else:
		print('No')
		sys.exit()
print('Yes')

Submission status: Accepted

Solution code:
H,W = map(int,input().split())
s = [list(input()) for i in range(H)]
def judge(h,w):
    h1 = [0,0,1,-1]
    w1 = [1,-1,0,0]
    for i in range(4):
        if 0 <= h+h1[i] <= H-1 and 0 <= w+w1[i] <= W-1:
            if s[h+h1[i]][w+w1[i]] == '#':
                return True
    return False

ans = 'Yes'
for h in range(H):
    for w in range(W):
        if s[h][w] == '#' and not judge(h,w):
            ans = 'No'
            break
print(ans)

Submission status: Accepted

Solution code:
import sys
# int(input()) # 入力が1つ
h, w = map(int, input().split()) # 入力が複数
# [int(i) for i in input().split()] # 配列で数字

square = [[''] * (w + 2)]
for _ in range(h):
    row = list(input())
    row = ['.'] + row + ['.']
    square.append(row)
square.append([''] * (w + 2))

for i in range(1, h):
    for j in range(1, w):
        if square[i][j] == '#':
            if square[i + 1][j] == '#' or square[i][j + 1] == '#' or square[i - 1][j] == '#' or square[i][j - 1] == '#':
                # right, down, left, up
                continue
            else:
                print('No')
                sys.exit()
print('Yes')

Submission status: Accepted

Solution code:
import numpy as np
H, W=map(int, input().split())
S=[]
for i in range(H):
  s=list(input())
  S.append(s)
S=np.array(S)  
vec=[(0,1),(1,0),(0,-1),(-1,0)]
ok=True
for i in range(H):
  for j in range(W):
    now=S[i,j]
    if now=="#":
      suround=False
      for dx,dy in vec:
        nx,ny=i+dx,j+dy
        if 0<=nx and nx<H and 0<=ny and ny<W:
          if S[nx,ny]=="#":
            suround=True
      if not suround:
        ok=False
        break
if ok:
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

H, W = MAP()
S = [input() for i in range(H)]

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

for h in range(H):
    for w in range(W):
        if S[h][w] == "#":
            cnt = 0
            for i in range(4):
                if 0 <= h + dy[i] < H and 0 <= w + dx[i] < W:
                    if S[h+dy[i]][w+dx[i]] == "#":
                        cnt += 1
            if cnt == 0:
                print("No")
                exit()
print("Yes")

Submission status: Accepted

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

for i in range(h):
  for j in range(w):
    if s[i][j]=="#":
      if 0<j:c[i][j-1]=1
      if j<w-1:c[i][j+1]=1
      if 0<i:c[i-1][j]=1
      if i<h-1:c[i+1][j]=1

ok=True
for i in range(h):
  for j in range(w):
    if s[i][j]=="#":
        if c[i][j]!=1:ok=False
print("Yes") if ok else print("No")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

def solve():
    input = sys.stdin.readline
    H, W = map(int, input().split())
    S = [input().strip("\n") for _ in range(H)]
    D = ((-1, 0), (0, -1), (1, 0), (0, 1))
    for h in range(H):
        possible = True
        for w in range(W):
            if S[h][w] == "#":
                for dh, dw in D:
                    if 0 <= h+dh < H and 0 <= w+dw < W and S[h+dh][w+dw] == "#":
                        break
                else:
                    possible = False
                    break
        if not possible:
            print("No")
            break
    else: print("Yes")


    return 0

if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
h,w = map(int,input().split())
s = [list(input()) for _ in range(h)]
visited = [[False]*w for _ in range(h)]
flag = True
for y in range(h):
    for x in range(w):
        if s[y][x]=='#':
            flag = False
            for dy,dx in ((1,0),(0,1),(-1,0),(0,-1)):
                ny,nx = y+dy,x+dx
                if 0<=ny<h and 0<=nx<w and s[ny][nx]=='#':
                    flag = True
                    break
        
        if not flag:
            break
    if not flag:
        break


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

Submission status: Accepted

Solution code:
H,W=map(int,input().split())
L=[list(input()) for _ in range(H)]
N=L.count("#")
for i in range (H):
	for j in range(W):
		if L[i][j]=="#":
			if not((i-1>=0 and L[i-1][j]=="#") or (j-1>=0 and L[i][j-1]=="#") or (i+1<H and L[i+1][j]=="#") or (j+1<W and L[i][j+1]=="#")):
				print("No")
				exit()
print("Yes")

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
canvas = list(list(input()) for _ in range(H))
dx_list = [0, 1, 0, -1]
dy_list = [1, 0, -1, 0]
for x in range(W):
    for y in range(H):
        if canvas[y][x] == ".":
            continue
        is_connect = False
        for dx, dy in zip(dx_list, dy_list):
            if 0 <= x + dx < W and 0 <= y + dy < H:
                if canvas[y + dy][x + dx] == '#':
                    is_connect = True
        if not is_connect:
            print("No")
            exit()
print('Yes')

Submission status: Accepted

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

grid = [[str(i) for i in input()]for _ in range(h)]
dxdy = [[1, 0], [0, 1], [-1, 0], [0, -1]]
for i in range(h):
    for j in range(w):
        if grid[i][j]=="#":
            f = False
            for d in dxdy:
                if(i+d[0]>-1 and j+d[1]>-1 and j+d[1]<w and i+d[0]<h):
                    if grid[i+d[0]][j+d[1]]=="#":
                        f = True
                        continue
            if f==False:
                print("No")
                exit()
print("Yes")

Submission status: Accepted

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

area = []

for i in range(h+2):
    if i == 0 or i == h+1:
        array = '.' * (w+2)
    else:
        array = input()
        array = '.' + array + '.'
    area.append(array)

def check(i, j):
    if area[i][j-1] == '#' or area[i][j+1] == '#' or area[i-1][j] == '#' or area[i+1][j] == '#':
        return True
    else:
        return False

for i in range(1, h+1):
    for j in range(1, w+1):
        if area[i][j] == '#':
            if not check(i, j):
                print('No')
                exit()
print('Yes')

Submission status: Accepted

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

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

for i in range(h):
    for j in range(w):
        if cvs[i][j] == '#':
            ok = False
            for d in range(4):
                if 0<=i+di[d]<h and 0<=j+dj[d]<w:
                    if cvs[i+di[d]][j+dj[d]] == '#':
                        ok = True
            if not ok:
                print('No')
                exit()
print('Yes')

Submission status: Accepted

Solution code:
H, W = map(int,input().split())
G = ["."*(W+2)]
for k in range(H):
    G.append("."+input()+".")
G.append("."*(W+2))
for k in range(1,H+1):
    for l in range(1,W+1):
        if G[k][l] == "#":
            if G[k+1][l] == "." and G[k-1][l] == "." and G[k][l-1] == "." and G[k][l+1] == ".":
                print("No")
                exit(0)
print("Yes")

Submission status: Accepted

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

S = []
for _ in range(H):
    hw = list(input())
    S.append(hw)

for i in range(H):
    for j in range(W):

        if S[i][j] == '.':
            continue

        # 上
        if i != 0 and S[i-1][j] == '#':
            continue
        # 下
        elif i != H-1 and S[i+1][j] == '#':
            continue
        # 左
        elif j != 0 and S[i][j-1] == '#':
            continue
        # 右
        elif j != W-1 and S[i][j+1] == '#':
            continue

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