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())

def conv_e_2_num(x):
    return 1 if x == "#" else 0

def is_painted(masu, x, y):
    return masu[y][x] == 1

def check_lrtb(masu, x, y, w, h):
    return (x - 1 >= 0 and is_painted(masu, x - 1, y)) \
        or (x + 1 < w and is_painted(masu, x + 1, y)) \
        or (y - 1 >= 0 and is_painted(masu, x, y - 1)) \
        or (y + 1 < h and is_painted(masu, x, y + 1)) \

def check_all(masu, w, h):
    if w == h and w == 1:
        return True
    for y in range(h):
        for x in range(w):
            if is_painted(masu, x, y):
                if check_lrtb(masu, x, y, w, h):
                    continue
                else:
                    return False
    return True


masu = []
for y in range(h):
    masu.append(list(map(conv_e_2_num, list(input()))))

print('Yes') if check_all(masu, w, h) else print('No')

Submission status: Accepted

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


def get_data():
    yield ['.'] * (W + 1)
    for _ in range(H):
        yield ['.'] + list(input()) + ['.']
    yield ['.'] * (W + 1)


def check(array):
    for i, row in enumerate(array):
        if i == 0 or i == len(array) - 1:
            continue
        sharp_index = [i for i, value in enumerate(row) if value == '#']
        for j in sharp_index:
            if j - 1 in sharp_index or j + 1 in sharp_index:
                continue
            if '#' in (array[i+1][j], array[i-1][j]):
                continue
            return False
    return True


Array = list(get_data())
if check(Array):
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
hw = [int(i) for i in input().split()]
ans = "Yes"

#low efficientcy
field = ["." * (hw[1] + 2)]
for h_i in range(hw[0]):
    field.append("." + input() + ".")
field.append("." * (hw[1] + 2))

for h_i in range(1, hw[0] + 1):
    if ans == "No":
        break
    for w_i in range(1, hw[1] + 1):
        if field[h_i][w_i] == "#":
            if field[h_i - 1][w_i] == "#" or field[h_i + 1][w_i] == "#"\
            or field[h_i][w_i - 1] == "#" or field[h_i][w_i + 1] == "#":
                continue
            ans = "No"
            break
print(ans)

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
Sij = []
for _ in range(H):
    Sij.append(input())
result = []
for a in range(H):
    for b in range(W):
        check = []    
        if Sij[a][b] == '#':
            if a-1 >= 0:
                H_up = a - 1
                S_H_up = Sij[H_up][b]
                check.append(S_H_up)
            if a+1 <= H-1:
                H_down = a + 1
                S_H_down = Sij[H_down][b]
                check.append(S_H_down)
            if b-1 >= 0:
                W_right = b - 1
                S_W_right = Sij[a][W_right]
                check.append(S_W_right)
            if b+1 <= W-1: 
                W_left = b + 1
                S_W_left = Sij[a][W_left]
                check.append(S_W_left)
            if '#' in check:
                result.append('good')
            else:
                result.append('bad')
                
if 'bad' in result:
    print('No')
else:
    print('Yes')

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
H, W = map(int, input().split())
inputs = [input() for _ in range(H)]
canvas = [char for char in inputs]


def isSpace(canvas, i, j):
    if i in range(len(canvas)):
        if j in range(len(canvas[i])):
            return True if canvas[i][j] == "." else False
        else:
            return True
    else:
        return True


def isPaintableCanvasBySquare(canvas):
    H = len(canvas)
    W = len(canvas[0])
    for i, j in [(i, j) for i in range(H) for j in range(W)]:
        if(isSpace(canvas, i, j - 1) and
           isSpace(canvas, i, j + 1) and
           isSpace(canvas, i - 1, j) and
           isSpace(canvas, i + 1, j) and
           not isSpace(canvas, i, j)):
            return "No"
    return "Yes"


print(isPaintableCanvasBySquare(canvas))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
H, W = [int(i) for i in input().split()]
s = []
for i in range(H):
    s.append(input())
#print(s)
s_num = []
for i in range(H):
    tmp = []
    for j in range(W):
        if(s[i][j] == "."):
            tmp.append(0)
        else:
            tmp.append(1)
    s_num.append(tmp)

#print(s_num)
ans = True
for i in range(H):
    for j in range(W):
        if(s_num[i][j] == 1):
#            print("{},{}".format(i, j))
            sum_num = 1
            if(i > 0):
                sum_num += s_num[i-1][j]
            if(i < H-1):
                sum_num += s_num[i+1][j]
            
            if(j > 0):
                sum_num += s_num[i][j-1]
            if(j < W-1):
                sum_num += s_num[i][j+1]
            if(sum_num < 2):
                ans = False
                break

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

Submission status: Accepted

Solution code:
H,W = map(int,input().split())
s = [input() for i in range(H)]
dx=[0,-1,1,0]
dy=[1,0,0,-1]
flag = True
for i in range(H):
    for j in range(W):
        if s[i][j]=='#':
            cnt = 0
            for k in range(4):
                if 0<=j+dx[k] and j+dx[k]<W and 0<=i+dy[k] and i+dy[k]<H:
                    if s[i+dy[k]][j+dx[k]]=='#':
                        cnt += 1
            if cnt==0:
                flag=False
print('Yes' if flag else 'No')

Submission status: Accepted

Solution code:
h, w = [int(i) for i in input().split()]
s = [list(input()) for _ in range(h)]
flg = 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] == ".":
            flg = False

print('Yes' if flg else 'No')

Submission status: Accepted

Solution code:
def is_not_isolated(s_list, i, j):
    map_char_to_bool = {'.': False, '#': True}
    not_isolated = False
    for di, dj in ((-1, 0), (1, 0), (0, -1), (0, 1)):
        try:
            not_isolated = not_isolated or map_char_to_bool[s_list[i+di][j+dj]]
        except IndexError:
            pass
    return not_isolated

H, W = [int(elem) for elem in input().split(' ')]
s_list = [list(input()) for _ in range(H)]
assert len(s_list) == H
assert len(s_list[0]) == W

for i in range(len(s_list)):
    for j in range(len(s_list[0])):
        if s_list[i][j] == ".":
            continue
        else:
            if not is_not_isolated(s_list, i, j):
                print("No")
                exit(0)
else:
    print("Yes")

Submission status: Accepted

Solution code:
import numpy as np
H, W = list(map(int, input().split()))
count = 0
s = np.array([['d']*(W+2)]*(H+2))

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


def handan():
    for i in range(1, H+1):
        for j in range(1, W+1):
            if s[i][j] == '#':
                if (s[i-1][j] == ('.' or 'd')) and (s[i+1][j] == ('.' or 'd')) and (s[i][j-1] == ('.' or 'd')) and (s[i][j+1] == ('.' or 'd')):
                    return 'No'
    return 'Yes'

print(handan())

Submission status: Accepted

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

Submission status: Accepted

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

ans = True
for i in range(1,h-2):
    for j in range(1,w-2):
        if k[i][j] == "#" and k[i-1][j] =="." and k[i][j-1] =="." and k[i+1][j] =="." and k[i][j+1] =="." :
            ans = False

if ans:
    print('Yes')

else:
    print('No')

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
S = []
flag = True
for i in range(h):
    r = list(input())
    S.append(r)
for i in range(0,h-1):
    for j in range(0,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]=='.':
            flag = False
if flag:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
#Grid Repainting 2

#初期化
S = []
p = []
flag = True

#入力
H,W = map(int, input().split())
for i in range(H):
	s = input()
	s_list = list(s)
	S.append(s_list)

#計算
for i in range(0, H-1, 1):
	for j in range(0, W-1, 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] == "." :
			flag = False
		

#出力
if flag == True:
	print("Yes")

else:
	print("No")

Submission status: Accepted

Solution code:
import math
H, W = map(int, input().split())
s = []
flag = 0
ans = "No"
for i in range(H):
  s.append(list(input()))
for i in range(H):
  for j in range(W):
    if flag == 0:
      if s[i][j] == "#":
        if s[max(0, i - 1)][j] == "#" or s[i][max(0, j - 1)] == "#" or s[min(H - 1, i + 1)][j] == "#" or s[i][min(W - 1, j + 1)] == "#":
          continue
        else:
          flag += 1
if flag == 0:
  ans = "Yes"
print(ans)

Submission status: Accepted

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

ans = 'Yes'
for i in range(1, h+1):
    for j in range(1, w+1):
        if ls[i][j] == '#' and '#' not in [ls[i][j-1], ls[i][j+1], ls[i-1][j], ls[i+1][j]]:
            ans = 'No'

print(ans)

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
s = [input() for _ 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 + 1][j] == "." and s[i][j - 1] == "." and s[i][j + 1] == "."):
                print("No")
                # print("[%d][%d]"%(i,j))
                exit()
print("Yes")

Submission status: Accepted

Solution code:
# 1.上下左右を探索
def searchAround(sheet, h,w):
    # 上がblackか？
    try:
        isSharpAbove = (sheet[h-1][w]=="#")
        if h==0:
            isSharpAbove = False
    except IndexError:
        isSharpAbove = False
        
    # 下がblackか？
    try:
        isSharpBelow = (sheet[h+1][w]=="#")
    except IndexError:
        isSharpBelow = False
    
    # 右がblackか？
    try:
        isSharpRight = (sheet[h][w+1]=="#")
    except IndexError:
        isSharpRight = False
    
    # 左がblackか？
    try:
        isSharpLeft = (sheet[h][w-1]=="#")
        if w==0:
            isSharpLeft = False
    except IndexError:
        isSharpLeft = False  
        
        
    # blackがあるか？
    if isSharpAbove \
    or isSharpBelow \
    or isSharpRight \
    or isSharpLeft:
            return 0
    else:
        return 1
            
    

def main():
    H,W = map(int, input().split())
    sheet = []
    flag = 0
    for h in range(H):
        sheet.append(list(input()))
    
    for h in range(H):
        for w in range(W):
            if sheet[h][w] == "#":
                flag = searchAround(sheet, h,w)
            if flag==1:
                print('No')
                return 0

    if flag == 0:
        print('Yes')


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys

line_size, row_size = map(int, input().split())
mapmap = []#地図初期化

for i in range(line_size):
    mapmap.append(list(input()))

#探索
def Start_check(mapmap, px, py):
    start_flg = False
    move_x = [1, -1, 0, 0]
    move_y = [0, 0, 1, -1]
    for i in range(4):#動ける範囲で探索
        nx = px + move_x[i]
        ny = py + move_y[i]
        if 0 <= nx and nx < line_size and 0 <= ny and ny < row_size:
            if mapmap[nx][ny] == '#':#もし黒塗りなら
                start_flg = True
    
    if start_flg == False:
        print('No')
        sys.exit()

#Main
count = 0#探索回数（塗り絵した回数）
for i in range(line_size):
    for j in range(row_size):
        if mapmap[i][j] == '#':
            Start_check(mapmap, i, j)
            count += 1

#何もしなかった場合
print('Yes')

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
data = ''
for i in range(h):
    data += input()

array = list(data)
#print(array)

for i, x in enumerate(array):
    if x == '.':
        continue
    cnt = 0
    # 上の確認
    if not i < w:
        if array[i - w] == '#':
            cnt += 1
    # 下の確認
    if i + w < h * w:
        if array[i + w] == '#':
            cnt += 1
    # 左の確認
    if i % w != 0:
        if array[i - 1] == '#':
            cnt += 1
    # 右の確認
    if i % w != w - 1:
        if array[i + 1] == '#':
            cnt += 1

    if cnt == 0:
        print('No')
        break
else:
    print('Yes')

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
HW = input().split()

H = int(HW[0])
W = int(HW[1])

tmp1 = ("." * W) + ".."
s = [list(tmp1)]
for i in range(H):
    tmp2 = "." + input() + "."
    s.append(list(tmp2))
s.append(list(tmp1))

checker = 1
for i in range(1, H+1):
    for j in range(1, W+1):
        if s[i][j] == "#":
            if s[i][j-1] == "." and s[i-1][j] == "." and s[i][j+1] == "." and s[i+1][j] == ".":
                checker = 0
                break
    if checker == 0:
        break

if checker == 0:
    print("No")
else:
    print("Yes")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
mass=[]
f=0
frame=[["."]*(w+2) for i in range(h+2)]
for i in range(h):
    mass.append(list(input()))
for i in range(h):
    for j in range(w):
        frame[i+1][j+1]=mass[i][j]
for i in range(1,h):
    if f==0:
        for j in range(1,w):
            if frame[i][j]=="#" and frame[i][j]!=frame[i][j+1] and frame[i][j]!=frame[i+1][j] and frame[i][j]!=frame[i][j-1] and frame[i][j]!=frame[i-1][j]:
                    f=1
                    break
if f==0:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

def main():
    h, w = map(int, raw_input().split())

    square = []
    for i in range(h):
        square.append(raw_input())

    for i in range(h):
        for j in range(w):
            if square[i][j] == '.':
                continue
            else:
                if check(square, i, j, h, w):
                    continue
                else:
                    print("No")
                    exit()

    print("Yes")

def check(square, i, j, h, w):
    if i-1 >= 0:
        if square[i-1][j] == '#':
            return True
    if i+1 < h:
        if square[i+1][j] == '#':
            return True
    if j-1 >= 0:
        if square[i][j-1] == '#':
            return True
    if j+1 < w:
        if square[i][j+1] == '#':
            return True

    return False

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys

h, w = map(int, raw_input().split())
s = [raw_input() for _ in xrange(h)]

dir = [(-1, 0), (1, 0), (0, -1), (0, 1)]
for i in range(h):
    for j in range(w):
        if s[i][j] == '#':
            flag = False
            for d in dir:
                x = j + d[0]
                y = i + d[1]
                if 0 <= x < w and 0 <= y < h and s[y][x] == '#':
                    flag = True
            if not flag:
                print 'No'
                sys.exit()
print 'Yes'

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
# 入力
h, w = map(int, input().split())
cb = []
# キャンバスを取得
for _i in range(h):
    s = input()
    cb.append(s)

# 処理
# 全ての黒マス('#')に、上下左右に隣接する黒マスが存在すれば可能
# => 上下左右が全て白マス('.')であるような黒マスが存在すれば不可能
def find_impossible_tile(cb, i, j, h, w):
    t = cb[i][j]
    # 黒マスのみをチェックする
    if t == '.':
        return False
    # 上下左右のマスをチェック
    is_black_u = (i > 0 and cb[i-1][j] == '#')
    is_black_d = (i < h - 1 and cb[i+1][j] == '#')
    is_black_l = (j > 0 and cb[i][j-1] == '#')
    is_black_r = (j < w - 1 and cb[i][j+1] == '#')
    # いずれもが黒マスでなければ真でない
    return not (is_black_u or is_black_d or is_black_l or is_black_r)
    
# 各マスをチェック
found = False
for i in range(h):
    for j in range(w):
        if find_impossible_tile(cb, i, j, h, w):
            found = True
            break
    if found:
        break
        
if not found:
    ans = 'Yes'
else:
    ans = 'No'

# 出力
print("{}".format(ans))

Submission status: Accepted

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

checkMap = [[1 for _ in range(W)] for _ in range(H)]

flag = False
end = False
for i in range(H):
    for j in range(W):
        flag = False
        if(checkMap[i][j] == 1):
            if(map[i][j] == "."):
                flag = True
                checkMap[i][j] = 0
            if(map[i][j] == "#"):
                if(j < W-1 and map[i][j+1] == "#"):
                    checkMap[i][j] = 0
                    checkMap[i][j+1] = 0
                    flag = True
                if(j > 0 and map[i][j-1] == "#"):
                    checkMap[i][j] = 0
                    checkMap[i][j-1] = 0
                    flag = True
                if(i < H-1 and map[i+1][j] == "#"):
                    checkMap[i][j] = 0
                    checkMap[i+1][j] = 0
                    flag = True
                if(i > 0 and map[i-1][j] == "#"):
                    checkMap[i][j] = 0
                    checkMap[i-1][j] = 0
                    flag = True
            if(flag == False):
                print("No")
                end = True
                break
        else:
            flag = True
            continue
        if(flag == False):
            break
    if(flag == False):
        break

if(end == False):
    print("Yes")

Submission status: Accepted

Solution code:
h,w = list(map(int,input().split()))
a = []
a.append('.'*(w+2))
for i in range(h):
    a.append('.'+input()+'.')
a.append('.'*(w+2))
b = 1
c = ''
for i in range(h):
    for j in range(w):
        if a[i+1][j+1] == '.':
            c += '.'
        else:
            if a[i][j+1]=='#':
                b += 1
            if a[i+2][j+1]=='#':
                b += 1
            if a[i+1][j]=='#':
                b += 1
            if a[i+1][j+2]=='#':
                b += 1
            c += str(b)
            b = 1
if '1' in c:
    print('No')
else:
    print('Yes')

Submission status: Accepted

Solution code:
# PROBLEM C
h, w = [int(s) for s in input().split()]
sij = [input() for _ in range(h)]
#print(sij)

lonely_sharp = False
for idx in range(h):
    for jdx in range(w):
        #print(idx, jdx)
        if sij[idx][jdx] == '#' and all([
                idx == 0 or sij[idx - 1][jdx] == '.',
                idx == h - 1 or sij[idx + 1][jdx] == '.',
                jdx == 0 or sij[idx][jdx - 1] == '.',
                jdx == w - 1 or sij[idx][jdx + 1] == '.']):
            lonely_sharp = True
            break
if lonely_sharp:
    print('No')
else:
    print('Yes')

Submission status: Accepted

Solution code:
import numpy as np
import sys
H,W = [int(i) for i in input().split()]

s = []
for i in range(H):
    s.append(list(input()))
#print('hogehoge\n')
#print(s)
for i in range(1,H-2):
    for j in range(1,W-2):
        if s[i][j]=='#':
            if s[i-1][j]=='.'and s[i+1][j]=='.'and s[i][j-1]=='.'and s[i][j+1]=='.':
                print('No')
                sys.exit()
for i in range(1,H-2):
    if s[i][0] == '#':
        if s[i-1][0]=='.'and s[i+1][0]=='.'and s[i][1]=='.':
            print('No')
            sys.exit()
    if s[i][W-1]=='#':
        if s[i-1][W-1]=='.'and s[i+1][W-1]=='.'and s[i][W-2]=='.':
            print('No')
            sys.exit()

for i in range(1,W-2):
    if s[0][i] == '#':
        if s[0][i-1]=='.'and s[0][i+1]=='.'and s[1][i]=='.':
            print('No')
            sys.exit()
    if s[H-1][i]=='#':
        if s[H-1][i+1]=='.'and s[H-1][i-1]=='.'and s[H-2][i]=='.':
            print('No')
            sys.exit()
if s[0][0]=='#' and s[0][1]=='.' and s[1][0]=='.':
    print('No')
    sys.exit()    
if s[0][W-1]=='#' and s[0][W-2]=='.' and s[1][W-1]=='.':
    print('No')
    sys.exit()    
if s[H-1][0]=='#' and s[H-2][0]=='.' and s[H-1][1]=='.':
    print('No')
    sys.exit()    
if s[H-1][W-1]=='#' and s[H-1][W-2]=='.' and s[H-2][W-1]=='.':
    print('No')
    sys.exit()   

print('Yes')

Submission status: Accepted

Solution code:
"""
list(map(int,input().split()))
map(int,input().split())
"""
import numpy as np
N,M = map(int,input().split())

arr = [list(input())for i in range(N)]

for i in range(N):
    for j in range(M):

        if arr[i][j] == "#":
            arr[i][j] = 0
        else:
            arr[i][j] = 1

arr = np.array(arr)
arr = np.pad(arr,1,"constant",constant_values=1)
key = 0

for i in range(N):
    for j in range(M):
        if arr[i+1][j+1] == 0:
            if arr[i+1][j+1] + arr[i][j+1] + arr[i+1][j] + arr[i+2][j+1] + arr[i+1][j+2] >= 4:
                key+=1

if key>=1:
    print("No")
else:
    print("Yes")

Submission status: Accepted

Solution code:
dr = [-1, 0, 1, 0]
dc = [ 0, 1, 0,-1]

H,W = map(int,input().split())
s = [None] * H
for i in range(H):
	s[i] = input()

ok = True
for i in range(H):
	for j in range(W):
		if s[i][j] == '#':
			curr = False
			for k in range(4):
				nr = i + dr[k]
				nc = j + dc[k]
				if nr < 0 or nr >= H or nc < 0 or nc >= W:
					continue
				if s[nr][nc] == '#':
					curr = True
			if curr == False:
				ok = False

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

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**15
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    h,w = LI()
    a = [[c for c in S()] for _ in range(h)]
    ff = True
    for i in range(h):
        for j in range(w):
            if a[i][j] == '.':
                continue
            f = False
            if (i>0 and a[i-1][j] == '#') or (i<h-1 and a[i+1][j] == '#') or (j>0 and a[i][j-1] == '#') or (j<w-1 and a[i][j+1] == '#'):
                f = True
            if not f:
                ff = False
                break
        if not ff:
            break

    if ff:
        return 'Yes'
    return 'No'



print(main())

Submission status: Accepted

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

flag = 'Yes'
for i in range(h):
    for j in range(w):
        if s[i][j] == '#':
            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
            flag = 'No'
        else:
            continue

print(flag)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(3000)
H, W = map(int, input().split())
s = ['.'*(W+2)] + [list('.'+input()+'.') for _ in range(H)] + ['.'*(W+2)]

def dfs(x, y):
  if s[y][x] == '.':
    return 0
  s[y][x] = '.'
  return 1+dfs(x+1,y)+dfs(x-1,y)+dfs(x,y+1)+dfs(x,y-1)

for y in range(1, H+1):
  for x in range(1, W+1):
    if dfs(x, y) == 1:
      print('No')
      exit()
print('Yes')

Submission status: Accepted

Solution code:
H, W = map(int, input().split(' '))
cells = [[False if tgt == '.' else True for tgt in list(input())] for i in range(H)]

paintable = True

for line in cells:
    line.append(False)
    line.insert(0, False)
cells.insert(0, [False for i in range(W + 2)])
cells.append([False for i in range(W + 2)])

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

print ('Yes' if paintable else 'No')

Submission status: Accepted

Solution code:
H,W = map(int,input().split())
board = ["."*(W+2)]
for i in range(H):
    board.append("." + input() + ".")
board.append("."*(W+2))

for i in range(1,H+1):
    for j in range(1,W+1):
        if board[i][j] == "#":
            if board[i-1][j] == board[i+1][j] == board[i][j-1] == board[i][j+1] == ".":
                print("No")
                break
    else:
        continue
    break
else:
    print("Yes")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
H,W=map(int,input().split())
s=[]
s.append(['.' for i in range(W+2)])
for i in range(H):
    kr=list(input())
    kr=["."]+kr+["."]
    s.append(kr)
s.append(['.' for i in range(W+2)])
ans='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]=='.':
                ans='No'
print(ans)

Submission status: Accepted

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

flag = True

for x in range(1,h + 1):
  for y in range(1,w + 1):
    if lst[x][y] == "#":
      if lst[x - 1][y] == "." and lst[x + 1][y] == "." and lst[x][y + 1] == "." and lst[x][y - 1] == ".":
        flag = False
        break

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

Submission status: Accepted

Solution code:
# coding=utf-8

n, m = map(int, input().split())

s = [ list(str(input())) for _ in range(n) ]
add = [[1, 0],[-1, 0],[0, 1],[0, -1]]
ans = 'Yes'
for i in range(n):
    for j in range(m):
        if s[i][j] == '.': continue
        mid = False
        for k in range(4):
            ii = i + add[k][0]
            jj = j + add[k][1]
            if ii >= 0 and jj < m and ii < n and jj >= 0:
                if s[ii][jj] == '#': mid = True
        if not mid: ans = 'No';break
print(ans)

Submission status: Accepted

Solution code:
h, w = map(int,input().split())
arr = ['.' * (w + 2)]
flg = True
for _ in range(h):
    tmp = '.' + input() + '.'
    arr.append(tmp)
    tmp = ''
arr += ['.' * (w + 2)]

for i in range(1,h):
    for j in range(1,w):
        base = arr[i][j]
        up = arr[i-1][j]
        down = arr[i + 1][j]
        right = arr[i][j + 1]
        left = arr[i][j - 1]
        if base == '#' and up == down == right == left == '.':
            flg = False
            print('No')
            break
    if not flg:
        break
if flg:
    print('Yes')

Submission status: Accepted

Solution code:
H,W = map(int,input().split())
ss=[]
for s in range(H):
    ss.append(input().strip())
flg=True
for i in range(H):
    for j in range(W):
        if ss[i][j]== "#":
            if not (j>0 and ss[i][j-1] == "#"or j<W-1 and ss[i][j+1] == "#" or i>0 and ss[i-1][j]=="#" or i< H-1 and ss[i+1][j]=="#"):
                flg=False
                break
    if not flg:
        break
print("No Yes".split()[int(flg)])