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())
canvas = list()
canvas.append(['.' for _ in range(W + 2)])
for _ in range(H):
    r = ['.']
    for c in input():
        r.append(c)
    r.append('.')
    canvas.append(r)
canvas.append(['.' for _ in range(W + 2)])

for i in range(len(canvas)):
    row = canvas[i]
    for j in range(len(row)):
        cell = row[j]
        if cell == '#':
            if '#' in [canvas[i - 1][j], canvas[i + 1][j], canvas[i][j - 1], canvas[i][j + 1]]:
                continue
            else:
                print('No')
                exit(0)
print('Yes')

Submission status: Accepted

Solution code:
X,Y = map(int,input().split())
given = []
for x in range(X):
  given.append(input())
#print(given)
nex = [[-1,0],[1,0],[0,-1],[0,1]]
for i in range(X * Y):
  x = i // Y
  y = i % Y
  if given[x][y] == '#':
    for ex in range(4):
      try:
        if given[x+nex[ex][0]][y+nex[ex][1]] == '#':
          break
      except:
        pass
    else:
      print('No')
      break
else:
  print('Yes')

Submission status: Accepted

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

mvs = [(0,1),(0,-1),(1,0),(-1,0)]
for i in range(h):
    for j in range(w):
        if fields[i][j] == "#":
            cnt = 0
            for dy,dx in mvs:
                next_y,next_x = i+dy,j+dx# 次の選び方を
                if 0 <= next_y < h and 0 <= next_x < w:
                    if fields[next_y][next_x] == "#":
                        cnt += 1
            if cnt == 0:
                print("No")
                exit()


print("Yes")

Submission status: Accepted

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

def search(x,y):
    flag = 0
    if x > 0:
        if G[y][x-1] == "#":
            flag = 1
    if x < W-1:
        if G[y][x+1] == "#":
            flag = 1
    if y > 0:
        if G[y-1][x] == "#":
            flag = 1
    if y < H-1:
        if G[y+1][x] == "#":
            flag = 1
    if flag == 1:
        return True
    else:
        return False

res = 1
for i in range(H):
    for j in range(W):
        x = j
        y = i
        if G[y][x] == "#":
            if search(x,y):
                pass
            else:
                res = 0
if res:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

yx = [[1, 0], [0, 1], [0, -1], [-1, 0]]
for i in range(1, h + 1):
    for j in range(1, w + 1):
        if a[i][j] == '#':
            flag = False
            for k in range(4):
                x = yx[k][0]
                y = yx[k][1]
                if a[i + x][j + y] == '#':
                    flag = 1

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

Submission status: Accepted

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

xy = [[1, 0], [0, 1], [0, -1], [-1, 0]]
for i in range(1, h):
    for j in range(1, w):
        if a[i][j] == '#':
            flag = False
            for k in range(4):
                x = xy[k][0]
                y = xy[k][1]
                if a[i + x][j + y] == '#':
                    flag = 1
                    
            if not flag:
                print('No')
                exit()
print('Yes')

Submission status: Accepted

Solution code:
from functools import reduce
H, W = map(int, input().split())
s = [list("." + input() + ".") for _ in range(H)]
s.insert(0, list("."*(W+2)))
s.append(list("."*(W+2)))

while "#" in reduce(lambda x,y: x+y, s):
    hantei = reduce(lambda x,y: x+y, s)
    index = hantei.index("#") + 1
    #切り上げ - 1
    h = -(-index//(W+2)) - 1
    w = index - (W+2)*(h+1) - 1
    roop = False
    if (s[h-1][w] == "#") or (s[h-1][w] == "Z"):
        s[h][w] = "Z"
        s[h-1][w] = "Z"
        roop = True
    if (s[h][w-1] == "#") or (s[h][w-1] == "Z"):
        s[h][w] = "Z"
        s[h][w-1] = "Z"
        roop = True
    if (s[h][w+1] == "#") or (s[h][w+1] == "Z"):
        s[h][w] = "Z"
        s[h][w+1] = "Z"
        roop = True
    if (s[h+1][w] == "#") or (s[h+1][w] == "Z"):
        s[h][w] = "Z"
        s[h+1][w] = "Z"
        roop = True
    if not roop:
        break

if "#" in reduce(lambda x,y: x+y, s):
    print("No")
else:
    print("Yes")

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
A = []
for _ in range(H):
  A.append(input())
  
all_flag = True
for i in range(H):
  for j in range(W):
    if A[i][j] == '.':
      flag = True
    else:
      flag = False
      if i > 0:
        if A[i-1][j] == '#':
          flag = True
      if i < H-1:
        if A[i+1][j] == '#':
          flag = True
      if j > 0:
        if A[i][j-1] == '#':
          flag = True
      if j < W-1:
        if A[i][j+1] == '#':
          flag = True
    if not flag:
      all_flag = False
      break
  if not all_flag:
    break
if all_flag:
  print('Yes')
else:
  print('No')

Submission status: Accepted

Solution code:
H,W = map(int,input().split())
S =[["."]*(W+2)]

for i in range(H):
    S.append("."+input()+".")
    
S.append("."*(W+2))

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]==".":
                print("No")
                exit()
print("Yes")

Submission status: Accepted

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

# print(s)
# print(s[1][1])

ok = True
for hi in range(h):
    for wi in range(w):
        if s[hi][wi] == '#':
            drawable = False
            # check
            if hi >= 1:
                drawable = (s[hi-1][wi] == '#') | drawable
            
            if hi <= h-2:
                drawable = (s[hi+1][wi] == '#') | drawable
            
            if wi >= 1:
                drawable = (s[hi][wi-1] == '#') | drawable
            
            if wi <= w-2:
                drawable = (s[hi][wi+1] == '#') | drawable

            # if hi >= 1:
            #     if s[hi-1][wi] == 

            if not drawable:
                ok = False

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

Submission status: Accepted

Solution code:
## グリッドに関する処理
# ABC096C_ Grid Repainting 2

## 考え方
# あるマスが'#'である場合、その上下左右の1つ以上が必ず'#'である必要がある

## for test
# # 1
# height, width = 3, 3
# _s_list = ['.#.', '###', '.#.']

# # 2
# height, width = 5, 5
# _s_list = ['#.#.#', '.#.#.', '#.#.#', '.#.#.', '#.#.#']

# # 3


## for submit
import numpy as np
height, width = map(int, input().split())
_s_list = [input() for i in range(height)]
s_list = [list(ss) for ss in _s_list]  # 列×行に1文字ずつ区切ってリストへ追加 -> 2次元配列化
s_arr  = np.array(s_list)

# print(s_arr)  # debug
its_ok = True
for _h in range(height):
    for _w in range(width):
        # 自分が'#'のときだけチェック
        if s_arr[_h, _w] == '#':
            checker = False
            # 一番上でなければ、上のマスをチェック
            if _h >= 1:
                if s_arr[_h-1, _w] == '#':
                    checker = True
            # 一番下でなければ、下のマスをチェック
            if _h != height-1:
                if s_arr[_h+1, _w] == '#':
                    checker = True
            # 一番左でなければ、左のマスをチェック
            if _w >= 1:
                if s_arr[_h, _w-1] == '#':
                    checker = True
            # 一番右でなければ、右のマスをチェック
            if _w != width-1:
                if s_arr[_h, _w+1] == '#':
                    checker = True
            
            if checker is False:
                its_ok = False
                break
    
    if its_ok is False:
        break

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

Submission status: Accepted

Solution code:
import numpy as np
height, width = map(int, input().split())
_s_list = [input() for i in range(height)]
s_list = [list(ss) for ss in _s_list]  # 列×行に1文字ずつ区切ってリストへ追加 -> 2次元配列化
s_arr  = np.array(s_list)

# print(s_arr)  # debug
its_ok = True
for _h in range(height):
    for _w in range(width):
        # 自分が'#'のときだけチェック
        if s_arr[_h, _w] == '#':
            checker = False
            # 一番上でなければ、上のマスをチェック
            if _h >= 1:
                if s_arr[_h-1, _w] == '#':
                    checker = True
            # 一番下でなければ、下のマスをチェック
            if _h != height-1:
                if s_arr[_h+1, _w] == '#':
                    checker = True
            # 一番左でなければ、左のマスをチェック
            if _w >= 1:
                if s_arr[_h, _w-1] == '#':
                    checker = True
            # 一番右でなければ、右のマスをチェック
            if _w != width-1:
                if s_arr[_h, _w+1] == '#':
                    checker = True
            
            if checker is False:
                its_ok = False
                break
    
    if its_ok is False:
        break

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

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][j-1]=="." and S[i+1][j]=="." and S[i][j+1]==".":
      ans="No"
print(ans)

Submission status: Accepted

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

ans = 1
for h in range(H):
    for w in range(W):
        if ans == 0:
            break
        if grid[h][w] == "#":
            if h == 0:
                if w == 0:
                    if grid[h + 1][w] == "." and grid[h][w+1] == ".":
                        ans = 0
                elif w == W - 1:
                    if grid[h + 1][w] == "." and grid[h][w-1] == ".":
                        ans = 0
                else:
                    if grid[h + 1][w] == "." and grid[h][w - 1] == "." and grid[h][w + 1] == ".":
                        ans = 0

            elif h == H - 1:
                if w == 0:
                    if grid[h - 1][w] == "." and grid[h][w+1] == ".":
                        ans = 0
                elif w == W - 1:
                    if grid[h - 1][w] == "." and grid[h][w-1] == ".":
                        ans = 0
                else:
                    if grid[h - 1][w] == "." and grid[h][w - 1] == "." and grid[h][w + 1] == ".":
                        ans = 0

            else:
                if w == 0:
                    if grid[h - 1][w] == "." and grid[h][w+1] == "."and grid[h + 1][w] == ".":
                        ans = 0
                elif w == W - 1:
                    if grid[h - 1][w] == "." and grid[h][w-1] == "."and grid[h + 1][w] == ".":
                        ans = 0
                else:
                    if grid[h - 1][w] == "." and grid[h][w - 1] == "." and grid[h][w + 1] == "." and grid[h + 1][w] == ".":
                        ans = 0

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys, math, fractions, itertools

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

def solve(H: int, W: int, s: "List[str]"):
    flag = True
    for h in range(H):
        for w in range(W):
            if s[h][w] == '#':
                if h == H-1: U = True
                else: U = s[h+1][w] != '#'
                if h == 0: D = True
                else: D = s[h-1][w] != '#'
                if w == 0: L = True
                else: L = s[h][w-1] != '#'
                if w == W-1: R = True
                else: R = s[h][w+1] != '#'
                if all([U, D, L, R]):
                    flag = False
    if flag:
        print('Yes')
    else:
        print('No')
    return


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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
h,w = map(int,input().split())
buf = '#' * (w+2)
lst = [buf]
for i in range(h):
    s = '#' + input() + '#'
    lst.append(s)
lst.append(buf)

def check(x,y):
    if (lst[x-1][y]=='#') or (lst[x+1][y]=='#') or (lst[x][y+1]=='#') or (lst[x][y-1]=='#'):
        return True
    else:
        return False

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

Submission status: Accepted

Solution code:
def check(i, j, s, H, W):
    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

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

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

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

print(ans)

Submission status: Accepted

Solution code:
def solve():
    h, w = list(map(int, input().split()))
    field = [["."] * (w + 2)] + [["."] + list(input()) + ["."] for _ in range(h)] + [["."] * (w + 2)]
    for i in range(1, h + 2):
        for j in range(1, w + 2):
            if field[i][j] == "#" and not is_paintable(field, i, j):
                return "No"
    return "Yes"


def is_paintable(field: list, i: int, j: int):
    return "#" in [field[i - 1][j], field[i + 1][j], field[i][j - 1], field[i][j + 1]]


if __name__ == "__main__":
    print(solve())

Submission status: Accepted

Solution code:
h,w=map(int,input().split());w+=2
s=["."*w]+["."+input()+"." for _ in[0]*h]+["."*w]
for i in range(1,h+2):
	for j in range(1,w):
		if s[i][j]=="#":
			if "#" not in (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=["."*(w+2)]+["."+input()+"." for _ in range(h)]+["."*(w+2)]
for i in range(1,h+2):
	for j in range(1,w+2):
		if s[i][j]=="#":
			if "#" not in (s[i-1][j],s[i+1][j],s[i][j-1],s[i][j+1]):
				print("No");exit()
			else:pass
		else:pass
print("Yes")

Submission status: Accepted

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

for i in range(h):
  for j in range(w):
    if li[i][j] == ".":
      continue
    for k in range(4):
      if not(0<=i+dx[k]<h) or not(0<=j+dy[k]<w):
        continue
      else:
        if li[i+dx[k]][j+dy[k]] == "#":
          break
    else:
      print("No")
      exit()
print("Yes")

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
s = [input() for _ in range(h)] 
 
d = {(i, j):c for i, row in enumerate(s) for j, c in enumerate(row)}
 
def next_to_black(i, j):
    directions = ((-1, 0), (1, 0), (0, -1), (0, 1))
    surroundings = ((i + a, j + b) for a, b in directions)
    colors = (d.get(cell, '.') for cell in surroundings)
    return any(color == '#' for color in colors)
 
black_coords = (coord for coord, c in d.items() if c == '#')
paintable = all(next_to_black(*coord) for coord in black_coords)
print('Yes' if paintable else 'No')

Submission status: Accepted

Solution code:
H,W = map(int,input().split())
s =[input() for i in range(H)]
t = ["."*(W+2)]
for i in range(H):
    t.append("."+s[i]+".")
t.append("."*(W+2))
flag = 0
for i in range(1,H+1):
    for j in range(1,W+1):
        if t[i][j] == "#" and t[i][j+1] == "." and t[i][j-1] == "." and t[i-1][j] == "." and t[i+1][j] == ".":
            flag = 1
            break
    else:
        continue
    break
if flag == 1:
    print("No")
else:
    print("Yes")

Submission status: Accepted

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

s1=[['.' for i in range(w+2)] for i in range(h+2)]

for i in range(h):
    for j in range(w):
        if s[i][j]=='#':
            s1[i+1][j+1]='#'
for i in range(h+2):
    for j in range(w+2):
        if s1[i][j]=='#':
            if s1[i-1][j]==s1[i+1][j]==s1[i][j-1]==s1[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 [0]*h]+['.'*(w+2)]
a='Yes'
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]=='.':a='No'
print(a)

Submission status: Accepted

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

Submission status: Accepted

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

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

def draw(i,j):
	if j>0 and s[i][j-1] == "#":
		return "Yes"
	if j<W-1 and s[i][j+1] == "#":
		return "Yes"
	if i>0 and s[i-1][j] == "#":
		return "Yes"
	if i<H-1 and s[i+1][j] == "#":
		return "Yes"
	return "No"

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

print(ans)

Submission status: Accepted

Solution code:
import itertools
H, W = map(int, input().split())
pic = [input() for i in range(H)]
for i, j in itertools.product(range(H), range(W)):
    if pic[i][j] == "#":
        S = set()
        if i > 0:
            S.add(pic[i-1][j])
        if i < H-1:
            S.add(pic[i+1][j])
        if j > 0:
            S.add(pic[i][j-1])
        if j < W-1:
            S.add(pic[i][j+1])
        if not "#" in S:
            print("No")
            exit()
else:
    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]=='#':
            flg=True
            if i>0:
                if s[i-1][j]=='#':
                    flg=False
            if j>0:
                if s[i][j-1]=='#':
                    flg=False
            if i<h-1:
                if s[i+1][j]=='#':
                    flg=False
            if j<w-1:
                if s[i][j+1]=='#':
                    flg=False
            if flg:
                print('No')
                exit()
print('Yes')

Submission status: Accepted

Solution code:
H, W = [int(x) for x in input().split()]

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

check = False

for i in range(H):
	for j in range(W):
		if canvas[i][j] == '#':
			check = True
			if i > 0:
				if canvas[i-1][j] == '#':
					check = False
			if i < H - 1 and check:
				if canvas[i+1][j] == '#':
					check = False
			if j > 0 and check:
				if canvas[i][j-1] == '#':
					check = False
			if j < W - 1 and check:
				if canvas[i][j+1] == '#':
					check = False
			if check:
				print('No')
				break
	if check:
		break
	if i == H - 1:
		print('Yes')

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
s = []
for _ in range(H):
    sr = input()
    s.append(sr)
for i in range(H):
    for j in range(W):
        if s[i][j] == ".":
            continue
        if i == 0 or s[i-1][j] == "#":
            continue
        if i == H-1 or s[i+1][j] == "#":
            continue
        if j == 0 or s[i][j-1] == "#":
            continue
        if j == W-1 or s[i][j+1] == "#":
            continue
        print("No")
        exit()
print("Yes")

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007

#A
def A():
    a, b = LI()
    if a <= b:
        print(a)
    else:
        print(a-1)
    return

#B
def B():
    a, b, c = LI()
    k = II()
    print(a + b + c + max(a, b, c) * ((2 ** k) - 1))
    return

#C
def C():
    H, W = LI()
    s = SR(H)
    for h in range(H):
        for w in range(W):
            if s[h][w] == "#":
                for mh, mw in [(0, 1), (1, 0), (-1, 0), (0, -1)]:
                    hm = mh + h
                    wm = mw + w
                    if 0 <= hm < H and 0 <= wm < W:
                        if s[hm][wm] == "#":
                            break
                else:
                    print("No")
                    return

    print("Yes")
    return

#D
def D():
    n = II()
    ans = []
    sosu = [2]
    i = 2
    while len(ans) != n:
        for k in sosu:
            if i % k == 0:
                i += 1
                break
        else:
            sosu.append(i)
            if i % 5 == 1:
                ans.append(i)
            i += 1
    for i in ans:
        print(i, end=" ")
    print()
    return


#Solve
if __name__ == '__main__':
    C()

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
S = []
for i in range(H):
    S.append(input())
for i in range(H):
    for j in range(W):
        if S[i][j] == ".":
            continue
        count = 0
        for xs, ys in [(0, 1), (0, -1), (1, 0), (-1, 0)]:
            if i + ys < 0 or i + ys >= H or j + xs < 0 or j + xs >= W:
                break
            pos_x = j + xs
            pos_y = i + ys
            if S[i][j] == "#" and S[pos_y][pos_x] == ".":
                count += 1
        if count == 4:
            print("No")
            exit()
print("Yes")

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
#ABC089C
import sys

tmp = input().split()
hoge = list(map(lambda a: int(a), tmp))
h = hoge[0]
w = hoge[1]

list = [[0 for i in range(w+2)] for j in range(h+2)]

for i in range(0,h):
	fuga = input()
	for j in range(0,w):
		if(fuga[j]=="."):
			list[i+1][j+1]=0
		else:
			list[i+1][j+1]=1

flg=0
for i in range(1,h+1):
	for j in range(1,w+1):
		if(list[i+1][j+1] == 1):
			if(list[i][j+1] == 0)and(list[i+1][j] == 0)and(list[i+1][j+2] == 0)and(list[i+2][j+1] == 0):
				flg=1
if(flg):
	print("No")
else:
	print("Yes")

#print(list)

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
campus = [['.' for _ in range(W+2)]]
for _ in range(H):
    campus.append(['.'] + list(input()) + ['.'])
campus.append(['.' for _ in range(W+2)])

finish = True
for i in range(1, H+1):
    for j in range(1, W+1):
        if campus[i][j] == '#':
            if campus[i-1][j] != '#' and campus[i][j+1] != '#' and campus[i+1][j] != '#' and campus[i][j-1] != '#':
                finish = False
                break
    else:
        continue
    break
if finish:
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

def drow(i,j, map = map):
  if j > 0 and map[i][j-1] == "#":
    return "Yes"
  if j < W-1 and map[i][j+1] == "#":
    return "Yes"
  if i > 0 and map[i-1][j] == "#":
    return "Yes"
  if i < H -1 and map[i+1][j] == "#":
    return "Yes"
  return "No"

ans = "Yes"
for i in range(H):
  for j in range(W):
    if map[i][j] == "#":
      ans = drow(i,j)
      if ans == "No":
        print(ans)
        exit()
print(ans)

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 s[max(0,i-1)][j] == "." and s[min(H-1,i+1)][j] == "." and s[i][max(0,j-1)] == "." and s[i][min(W-1,j+1)] == ".":
			    print("No")
			    exit()
print("Yes")

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
state = [[1 if a == '#' else 0 for a in list(input()+'.')] for _ in range(H)]
state.extend([[0]*(W+1)])


ans = 'Yes'
for h in range(H):
    for w in range(W):
        if state[h][w] == 0:
            continue
        nexts = [[h+1, w], [h-1, w], [h, w+1], [h, w-1]]
        ok = False
        for n in nexts:
            if state[n[0]][n[1]] == 1:
                ok = True
        if not ok:
            ans = 'No'
            break
    if ans == 'No':
        break

print(ans)

Submission status: Accepted

Solution code:
if __name__ == '__main__':
  check_flag = True
  
  h, w = map(int, input().split())
  s = []
  
  s.append('.' + '.' * w + '.')
  for i in range(h):
      s.append('.' + input() + '.')
  s.append('.' + '.' * w + '.')
  

  for i in range(h):
      for j in range(w):
          target_cell = ''
          if s[i + 1][j + 1] == '#':
            target_cell += s[i+1][j:j+3]
            target_cell += s[i][j+1]
            target_cell += s[i+2][j+1]
              
            if target_cell.count('#') == 1:
                check_flag = False
                break
      if not check_flag:
          break

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

Submission status: Accepted

Solution code:
import sys

#+++++
		
def check_near_black(c,i,j):
	dd=[[1,0],[0,1],[-1,0],[0,-1]]
	for dx,dy in dd:
		if c[i+dy][j+dx] == '#':
			return True
	return False

def main():
	h,w = map(int, input().split())
	camp=[]
	ww=list('.'*(w+2))
	camp.append(ww)
	for i in range(h):
		s = '.'+input()+'.'
		camp.append(list(s))
	camp.append(ww)
	
	for i in range(1,1+h):
		for j in range(1,1+w):
			#print(camp[i][j])
			if camp[i][j]=='#' and not check_near_black(camp,i,j):
				return 'No'
				
				
	return 'Yes'
		
	
	
	
#+++++

if __name__ == "__main__":
	if sys.platform =='ios':
		sys.stdin=open('inputFile.txt')
	else:
		input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
s = [input() for i in range(h)]
for y in range(h):
    for x in range(w):
        if s[y][x] == '#':
            cnt = 0
            cnt += 1 if 0 < x and s[y][x - 1] == '#' else 0
            cnt += 1 if x < w - 1 and s[y][x + 1] == '#' else 0
            cnt += 1 if 0 < y and s[y - 1][x] == '#' else 0
            cnt += 1 if y < h - 1 and s[y + 1][x] == '#' else 0
            if cnt == 0:
                print('No')
                exit()
print('Yes')

Submission status: Accepted

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

dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]
memo = [[0]*W for i in range(H)]

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

# print(S)

for i in range(H):
    for j in range(W):
        if S[i][j] == '#':
            flag = False
            for n in range(4):
                if i+dy[n] > -1 and i+dy[n] < H and j+dx[n] > -1 and j+dx[n] < W:
                    if S[i+dy[n]][j+dx[n]] == '#':
                        flag = True

            if flag == False:
                print('No')
                exit()


print('Yes')

Submission status: Accepted

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

for i in range(h):
    for j in range(w):
        if s[i][j]=="#":
            count = 0
            for k in range(4):
                x = i + dx[k]
                y = j + dy[k]
                if x >= 0 and x <= h-1 and y >= 0 and y <= w-1 and s[x][y] == "#":
                    count += 1
            if count == 0:
                Bool = False
                
if Bool == True:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
H, W = map(int,input().split())
B = []
B.append(["." for _ in range(W+2)])
for _ in range(H):
    S = input()
    L = []
    L.append(".")
    for s in S:
        L.append(s)
    L.append(".")
    B.append(L)
B.append(["." for _ in range(W+2)])

for i in range(H):
    for j in range(W):
        if B[i+1][j+1] == "#" and B[i][j+1] == "." and B[i+2][j+1] == "." and B[i+1][j] == "." and B[i+1][j+2] == ".":
            print("No")
            exit()
print("Yes")

Submission status: Accepted

Solution code:
# 行数Hおよび列数Wを入力する
H, W = map(int, input().split())
# マスを初期化する（ワンサイズ大きめに作成する）
s = ["." * (W + 2) for _ in range(H + 2)]
# マスを入力する
for i in range(1, H + 1):
    s[i] = "." + input() + "."
# 判定を初期化する
judge = "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] + s[i][j - 1] + s[i][j + 1] + s[i + 1][j] == "....":
            # 判定を更新する
            judge = "No"
            # マスの調査を終了する
            break
# 判定を出力する
print(judge)

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
s = [list(input()) for i in range(h)]
for x in range(h):
    for y in range(w):
        if(s[x][y] == '#'):
            up = s[max(0, x-1)][y]
            down = s[min(h-1, x+1)][y]
            right = s[x][max(0, y-1)]
            left = s[x][min(w-1,  y+1)]
            if(up == '.' and down == '.' and right == '.' and left == '.'):
                print("No")
                exit()
print("Yes")