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 = list(map(int,input().split()))
s = []
for _ in range(H):
    s.append(input())

d = [[1,0],[-1,0],[0,1],[0,-1]]
def check(i,j):
    flag = 0
    if s[i][j] == '#':
        for d_ in d:
            i_ = i+d_[0]
            j_ = j+d_[1]
            if H > i_ >= 0 and W > j_ >= 0:
                if s[i_][j_] == '#':
                    flag = 1
    else:
        flag = 1
    return flag

ans = 1
for i in range(H):
    for j in range(W):
        if check(i,j) == 0:
            ans = 0
if ans:
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

grid = []
grid.append("."*(W+2))
for i in range(H):
    grid.append("."+input()+".")
grid.append("."*(W+2))

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

flag = True

for i in range(1, H+1):
    for j in range(1, W+1):
        if grid[i][j] == "#" and grid[i+dx[0]][j+dy[0]] == "#":
            pass
        elif grid[i][j] == "#" and grid[i+dx[1]][j+dy[1]] == "#":
            pass
        elif grid[i][j] == "#" and grid[i+dx[2]][j+dy[2]] == "#":
            pass
        elif grid[i][j] == "#" and grid[i+dx[3]][j+dy[3]] == "#":
            pass
        elif grid[i][j] == "#":
            flag = False

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

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
S = ["." + input() + "." for _ in range(H)]
S.insert(0, "." * W)
S.append("." * W)
dx, dy = [1, -1, 0, 0], [0, 0, 1, -1]

for h in range(H):
    for w in range(W):
        if not S[h][w] == "#":
            continue
        cnt = 0
        for i in range(4):
            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())
l=[]
for i in range(h):
  l.append(list(input()))
f=False
for i in range(h):
  for j in range(w):
    if i==0 and j==0 and l[i][j]=='#':
      if l[i][j+1]=='.' and l[i+1][j]=='.':
        f=True
    if i==0 and 0<j<w-1 and l[i][j]=='#':
      if l[i][j-1]=='.' and l[i][j+1]=='.' and l[i+1][j]=='.':
        f=True
    if i==0 and j==w-1 and l[i][j]=='#':
      if l[i][j-1]=='.' and l[i+1][j]=='.':
        f=True
    if 0<i<h-1 and j==0 and l[i][j]=='#':
      if l[i-1][j]=='.' and l[i][j+1]=='.' and l[i+1][j]=='.':
        f=True
    if 0<i<h-1 and 0<j<w-1 and l[i][j]=='#':
      if l[i][j-1]=='.' and l[i-1][j]=='.' and l[i][j+1]=='.' and l[i+1][j]=='.':
        f=True
    if 0<i<h-1 and j==w-1 and l[i][j]=='#':
      if l[i][j-1]=='.' and l[i-1][j]=='.' and l[i+1][j]=='.':
        f=True
    if i==h-1 and j==0 and l[i][j]=='#':
      if l[i-1][j]=='.' and l[i][j+1]=='.':
        f=True
    if i==h-1 and 0<j<w-1 and l[i][j]=='#':
      if l[i-1][j]=='.' and l[i][j-1]=='.' and l[i][j+1]=='.':
        f=True
    if i==h-1 and j==w-1 and l[i][j]=='#':
      if l[i][j-1]=='.' and l[i-1][j]=='.':
        f=True
if f:
  print('No')
else:
  print('Yes')

Submission status: Accepted

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

space = [["." for w in range(W+1)] ]
for h in range(H):
    space.append(["."]+list(input())+["."])
space.append(["." for w in range(W+1)])

neighbor_num = [[0 for w in range(W+2)] for h in range(H+2)]

for h in range(1,H+1):
    for w in range(1,W+1):
        if space[h][w] == "#":
            neighbor_num[h][w] += 1
            neighbor_num[h-1][w] += 1
            neighbor_num[h+1][w] += 1
            neighbor_num[h][w+1] += 1
            neighbor_num[h][w-1] += 1

flag = 1
for h,numbers in enumerate(neighbor_num[1:H+1]):
    for w,neighber in enumerate(numbers[1:W+1]):
        if space[h+1][w+1] == "#" and neighber < 2:
            flag = 0
if flag == 1:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

def func():
    for hh in range(h):
        for ww in range(w):
            if li[hh][ww] == '.':
                continue
            if ww - 1 >= 0 and li[hh][ww - 1] == '#':
                continue
            if ww + 1 < w and li[hh][ww + 1] == '#':
                continue
            if hh - 1 >= 0 and li[hh - 1][ww] == '#':
                continue
            if hh + 1 < h and li[hh + 1][ww] == '#':
                continue
            return 'No'
    return 'Yes'

print(func())

Submission status: Accepted

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

dirs = [(1,0), (-1,0), (0,1), (0,-1)]
for i in range(1, h+1):
  for j in range(1, w+1):
    if f[i][j]=='#':
      flag = True
      for d in dirs:
        x,y = i+d[0],j+d[1]
        if f[x][y]=='#':
          flag = False
          break
      if flag:
        print("No")
        sys.exit()
print("Yes")

Submission status: Accepted

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

import sys
dd = [(1,0),(-1,0),(0,1),(0,-1)]
for h in range(H):
    for w in range(W):
        if S[h][w]=="#":
            chk = False
            for (dw,dh) in dd:
                if 0<=h+dh<H and 0<=w+dw<W:
                    if S[h+dh][w+dw]=="#":
                        chk = True
                        break
            if not chk:
                print("No")
                sys.exit()

print("Yes")

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

import numpy as np

def main():
    h, w = map(int, input().split())
    s = [list(input()) for i in range(h)]
    s = np.array(s)

    flag = True
    for i in range(h):
        for j in range(w):
            if s[i, j] == "#":
                if not adj(s, h, w, i, j):
                    flag = False
    print("Yes" if flag else "No")

def adj(s, h, w, i, j):
    up = s[i - 1, j] if i > 0 else "."
    down = s[i + 1, j] if i < h - 1 else "."
    left = s[i, j - 1] if j > 0 else "."
    right = s[i, j + 1] if j < w - 1 else "."
    return ("#" in [up, down, left, right])

main()

Submission status: Accepted

Solution code:
H ,W =map(int,input().split())
L = []
tmp = ['.' for x in range(W+2)]
L.append(tmp)
for _ in range(H):
    l =  list('.'+input()+'.')
    L.append(l)
L.append(tmp)
flag = 0
for x in range(1,H+1):
    for y in range(1,W+1):
        if L[x-1][y] == L[x][y-1] == L[x+1][y] == L[x][y+1] =='.' and L[x][y] == '#':
            flag = 1

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

Submission status: Accepted

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

Submission status: Accepted

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

def judge(i,j):
  if s[i][j]==".":
    return True
  else:
    return judge_zibun(i-1,j) or judge_zibun(i+1,j) or judge_zibun(i,j-1) or judge_zibun(i,j+1)
    
def judge_zibun(i,j):
  if not(0<=i<h and 0<=j<w):
    return False
  if s[i][j]=="#":
    return True
  else:
    return False

ans = True
for i in range(h):
  for j in range(w):
    ans = ans & judge(i,j)
if ans:
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
S = []
S.append(['.'] * (w + 2))
for i in range(h):
    S.append(list('.' + input() + '.'))
S.append(['.'] * (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'
                break
                
print(ans)

Submission status: Accepted

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

def draw_check(s):

    for i in range(H):
        for j in range(W):
            if s[i][j] == '.':
                continue
            else:
                 if all([s[max(0, i - 1)][j] == '.', s[min(H - 1, i + 1)][j] == '.', s[i][max(0, j - 1)] == '.', s[i][min(W - 1, j + 1)] == '.']):
                    return False

    return True

if draw_check(s):
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

def draw_check(s):
    for i in range(H):
        for j in range(W):
            if s[i][j] == '.':
                continue
            else:
                if all([s[max(0,i-1)][j] == '.',s[min(H-1,i+1)][j] == '.',s[i][max(0,j-1)] == '.',s[i][min(W-1,j+1)] == '.']):
                    return False
                    break
        else:
            continue
        break

    return True

if draw_check(s):
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
from sys import stdin
import sys
import numpy as np

xy = stdin.readline().rstrip().split()
x = int(xy[0])
y = int(xy[1])

data = [stdin.readline().rstrip().split() for _ in range(x)]
#print(*data, sep='\n')
#print('----------------')

for i in range(x):
    data[i] = list(data[i][0])

arr = np.array(data)
#print(arr)
#print('----------------')

OK = True
for i in range(x):
    for j in range(y):

        if arr[i][j] == '#':
            can_paint = False

            if i != 0:
                if arr[i-1][j] == '#':
                    can_paint =True

            if j != 0:
                if arr[i][j-1] == '#':
                    can_paint = True

            if i != x-1:
                if arr[i+1][j] == '#':
                    can_paint = True

            if j != y-1:
                if arr[i][j+1] == '#':
                    can_paint = True

            if can_paint != True:
                OK = False

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

Submission status: Accepted

Solution code:
r,c = map(int,input().split())
masume = [[0 for i in range(c)] for j in range(r)]
for i in range(r):
	masume[i] = list(input())

thispoint = True
for ri in range(r):
	for ci in range(c):
		if masume[ri][ci] == '#':
			draw = False
			for ar in [-1,0,1]:
				for ac in [-1,0,1]:
					if abs(ar) == abs(ac):
						continue
					chkr = ri + ar
					chkc = ci + ac
					if chkr >= 0 and chkr < r and chkc >= 0 and chkc < c and masume[chkr][chkc] == '#':
						draw = True
						break
			if not(draw):
				thispoint = False
				break
	if not(thispoint):
		break
if thispoint:
	print('Yes')
else:
	print('No')

Submission status: Accepted

Solution code:
# ABC 096
def getIntList(): return [int(x) for x in input().split()]
def db(x): 
    global debug
    if debug: print(x)
debug = False
H,W = getIntList()
db((H,W))
BL,WH = '#','.'
S = [WH*(W+2)]
for i in range(H):
    S.append(WH+input()+WH)
S.append(WH*(W+2))
db(S)
can = True
for i in range(1,H+1):
    for j in range(1,W+1):
        if S[i][j]==BL:
            if not (S[i-1][j]==BL or S[i+1][j]==BL or S[i][j-1]==BL or S[i][j+1]==BL):
                can = False
                break
    if not can: break
if can: print('Yes')
else: print('No')

Submission status: Accepted

Solution code:
hw=[int(i) for i in input().split()]
s=['.'+input()+'.' for i in range(hw[0])]
s=['.'*(hw[1]+2)]+s+['.'*(hw[1]+2)]
for i in range(1,hw[0]+1):
    for n in range(1,hw[1]+1):
        if s[i][n]=='#':
            if s[i+1][n]==s[i][n+1]==s[i-1][n]==s[i][n-1]=='.':
                print('No')
                exit()
print('Yes')

Submission status: Accepted

Solution code:
import sys
from itertools import product

sys.setrecursionlimit(200000)


def input():
    return sys.stdin.readline()[:-1]


def ii(t: type = int):
    return t(input())


def il(t: type = int):
    return list(map(t, input().split()))


def imi(N: int, t: type = int):
    return [ii(t) for _ in range(N)]


def iml(N: int, t: type = int):
    return [il(t) for _ in range(N)]


class PathFinder:
    def __init__(self, num_dst, border):
        if num_dst == 4:
            self.dx = (-1, 0, 0, 1)
            self.dy = (0, -1, 1, 0)
        elif num_dst == 8:
            self.dx = (-1, -1, -1, 0, 0, 1, 1, 1)
            self.dy = (-1, 0, 1, -1, 1, -1, 0, 1)
        self.border = border

    # 周辺探索
    def find_neighbours(self, current_x, current_y):
        for neighbour in zip(self.dx, self.dy):
            neighbour_x = current_x + neighbour[0]
            neighbour_y = current_y + neighbour[1]
            if (
                self.border[0] <= neighbour_x < self.border[1]
                and self.border[2] <= neighbour_y < self.border[3]
            ):
                yield neighbour_x, neighbour_y


def solve():

    H, W = il()
    S = imi(H, str)
    finder = PathFinder(4, (0, H, 0, W))
    for i, j in product(range(H), range(W)):
        flag = 0
        for x, y in finder.find_neighbours(i, j):
            if S[i][j] == "#" and S[x][y] == ".":
                flag += 1
        if flag == 4:
            return "No"
    return "Yes"


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

Submission status: Accepted

Solution code:
H,W=(int(i) for i in input().split())
s = []
s.append('.'*(W+2))
for i in range(H):
    s.append('.'+input()+'.')
s.append('.'*(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'
                break

print(ans)

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
art = []
ansflag = 1
for i in range(H):
    art.append(input())
for i in range(H):
    for j in range(W):
        if art[i][j] == "#":
            flag = 0
            for a in [1, -1]:
                try:
                    if art[i][j+a] == "#":
                        flag = 1
                except IndexError:
                    pass
                try:
                    if art[i+a][j] == "#":
                        flag = 1
                except IndexError:
                    pass
            if flag == 0:
                ansflag = 0
if ansflag == 0:
    print("No")
else:
    print("Yes")

Submission status: Accepted

Solution code:
H,W = map(int,input().split())
lis = ['.' +input()+'.' for _ in range(H)]
lis.insert(0,'.'*(W+2))
lis.append('.'*(W+2))
for i in range(1,H+1):
    for j in range(1,W+1):
        if lis[i][j] == '#':
            if lis[i+1][j]=='#' or lis[i-1][j]=='#' or lis[i][j+1]=='#' or lis[i][j-1] == '#':
                continue
            else:
                print('No')
                exit()
print('Yes')

Submission status: Accepted

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

A = []
A.append(['.']*(b+2))

for i in range(a):
    
    A.append(list('.'+input()+'.'))
A.append(['.']*(b+2))

ans = 0
for i in range(1, a+2):
    for j in range(1, b+2):
        if(A[i][j] == '#' and ans == 0):
            if(A[i][j-1] != "#" and A[i][j+1] != "#" and A[i-1][j] != "#" and A[i+1][j] != "#"):
                print('No')
                ans += 1
                break
if(ans == 0):
    print('Yes')

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

def main():
    na = list(map(int, input().split()))
    H, W = na[0], na[1]
    s = []
    s.append('.' * (W + 2))
    for i in range(H):
        s.append('.' + input() + '.')
    s.append('.' * (W + 2))

    r = True
    for i in range(H):
        for j in range(W):
            if s[i + 1][j + 1] == '#':
                if s[i + 1][j] == '.' \
                        and s[i + 1][j + 2] == '.' \
                        and s[i][j + 1] == '.' \
                        and s[i + 2][j + 1] == '.':
                    r = False
                    break
        if not r:
            break


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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
H,W=map(int,input().split())
S=["."+input()+"." for i in range(H)]
S=["."*(W+2)]+S+["."*(W+2)]
flag=0
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]==".":
                flag=1
print("Yes" if flag==0 else "No")

Submission status: Accepted

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

s = [input() for i in range(H)]
check = 0
for y in range(H):
    for x in range(W):
        if s[y][x] == '#':
            for dy, dx in [1, 0], [-1, 0], [0, 1], [0, -1]:
                if 0 <= y + dy <= H-1 and 0 <= x + dx <= W-1:
                    if s[y + dy][x + dx] == '#':
                        break
            else:
                check = 1
if check == 0:
    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(list('.' + input() + '.'))
A.append(['.'] * (w+2))

ans = 'Yes'
for i in range(1, h+1):
    for j in range(1, w+1):
        if A[i][j] == '#':
            if A[i+1][j] == '#' or A[i-1][j] == '#' or A[i][j+1] == '#' or A[i][j-1] == '#':
                continue
            else:
                ans = 'No'

print(ans)

Submission status: Accepted

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

def check(s,i,j):
    p = []
    if i-1 >= 0: p.append(s[i-1][j])
    if i+1 <= H-1:p.append(s[i+1][j])
    if j-1 >= 0: p.append(s[i][j-1])
    if j+1 <= W-1:p.append(s[i][j+1])

    if all(k == '.' for k in p):
        return False
    else:
        return True
    


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

Submission status: Accepted

Solution code:
H,W=map(int,input().split())
a=""
s=list()
for r in range(H):
        s+=(list(input()))

ans="Yes"

def field(s,h,d):
        try:
                if(s[h+d]=="#"):
                        return True
                else:
                        return False
        except:
                return False

lens=len(s)
for r in range(lens):
        if(s[r]=="#"):
                if(field(s,r,1) or field(s,r,-1) or field(s,r,H) or field(s,r,-H)):
                        pass
                else:
                        ans="No"
                        break
print(ans)

Submission status: Accepted

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

ans = 'Yes'
for i in range(1, h + 1):
    for j in range(1, w + 1):
        if A[i][j] == '#':
            if A[i - 1][j] == '#' or A[i + 1][j] == '#' or A[i][j - 1] == '#' or A[i][j + 1] == '#':
                continue
            else:
                ans = 'No'
                break
                
print(ans)

Submission status: Accepted

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

if ''.join(S).count('#') <= 1:
    print("Yes")
    quit()

for y in range(1, H + 1):
    for x in range(1, W + 1):
        if S[y][x] == '#' and set([S[y - 1][x], S[y + 1][x], S[y][x - 1], S[y][x + 1]]) == set('.'):
            print("No")
            quit()
print("Yes")

Submission status: Accepted

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


def main():
    h, w = map(int, input().split())
    board = [list(input()) for _ in range(h)]
    dx = [0, 0, -1, 1]
    dy = [-1, 1, 0, 0]

    for i in range(h):
        for k in range(w):
            if board[i][k] == '#':
                count = 0

                for m in range(4):
                    x = i + dx[m]
                    y = k + dy[m]

                    if 0 <= x < h and 0 <= y < w and board[x][y] == '#':
                        count += 1

                if count == 0:
                    print('No')
                    exit()

    print('Yes')


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys

h, w = [int(i) for i in input().split()]
s = [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 s[i][j] == '.':
            continue
        else:
            for d in range(4):
                if (0 <= i+dy[d] < h) and (0 <= j+dx[d] < w):
                    if s[i+dy[d]][j+dx[d]] == '#':
                        break
            else:
                print("No")
                sys.exit()
else:
    print("Yes")

Submission status: Accepted

Solution code:
H,W = map(int,input().split())
array = []
for i in range(H):
    array.append(list(str(input())))
flag = 0
for j in range(H):
    k = 0
    for k in range(W):
        if array[j][k] == "#":
            if j == 0 and k == 0:
                if array[j+1][k] == "." and array[j][k+1] == ".":
                    flag = 1
                    break
                else:
                    pass
            elif j == 0 and k == W-1:
                if array[j+1][k] == "." and array[j][k-1] == ".":
                    flag = 1
                    break
                else:
                    pass
            elif j == H-1 and k == 0:
                if array[j-1][k] == "." and array[j][k+1] == ".":
                    flag = 1
                    break
                else:
                    pass
            elif j == H-1 and k == W-1:
                if array[j-1][k] == "." and array[j][k-1] == ".":
                    flag = 1
                    break
                else:
                    pass
            elif j == 0:
                if array[j+1][k] == "." and array[j][k-1] == "." and array[j][k+1] == ".":
                    flag = 1
                    break
                else:
                    pass
            elif j == H-1:
                if array[j-1][k] == "." and array[j][k-1] == "." and array[j][k+1] == ".":
                    flag = 1
                    break
                else:
                    pass
            elif k == 0:
                if array[j-1][k] == "." and array[j+1][k] == "." and array[j][k+1] == ".":
                    flag = 1
                    break
                else:
                    pass
            elif k ==W-1:
                if array[j-1][k] == "." and array[j+1][k] == "." and array[j][k-1] == ".":
                    flag = 1
                    break
                else:
                    pass
            else:
                if array[j-1][k] == "." and array[j+1][k] == "." and array[j][k-1] == "." and array[j][k+1] == ".":
                    flag = 1
                    break
                else:
                    pass
            
        else:
            pass
if flag == 0:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

A = [[0] * (W + 2) for _ in range(H + 2)]

for h in range(H):
    s = input()
    for w in range(W):
        A[h + 1][w + 1] = 1 if s[w] == "#" else 0

for h in range(1, H + 1):
    for w in range(1, W + 1):
        a = A[h][w] + A[h][w + 1] + A[h][w - 1] + A[h + 1][w] + A[h - 1][w]
        if A[h][w] == 1 and a == 1:
            print("No")
            sys.exit(0)

print("Yes")

Submission status: Accepted

Solution code:
from itertools import product
h, w = list(map(int,input().split()))
canvas = [list(input()) for i in range(h)]

cross = [[1,0],[0,1],[-1,0],[0,-1]]
flag = True
for i, j in product(range(h), range(w)):
    if canvas[i][j] == ".":
        continue
    flag_tmp = False
    for di, dj in cross:
        if 0<= i + di < h and 0 <= j + dj < w:
            if canvas[i+di][j+dj] == "#":
                flag_tmp = True
    if not flag_tmp:
        flag = False
        break
if flag:
    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(['.'] + list(input()) + ['.'])
A.append(['.'] * (w + 2))

ans = 'Yes'

for i in range(1, h - 1):
    for j in range(1, w - 1):
        if A[i][j] == '#':
            if A[i - 1][j] == '#' or A[i +1][j] == '#' or A[i][j + 1] == '#' or A[i][j - 1] == '#':
                continue
            else:
                ans = 'No'
                break
                
print(ans)

Submission status: Accepted

Solution code:
N,M = map(int, input().split())
field =[]
field.append(list("."*(M+2)))
for i in range(N):
    t = list("."+input()+".")
    field.append(t)
field.append(list("."*(M+2)))
res = 1
def dfs(x,y):
    r = 0 #周りの”.”の数を数える
    #field[x][y] = "."
    
    for dx in range(-1,2):
        for dy in range(-1,2):
            if abs(dx+dy) ==1: #ここがなかったら周り８マス探す
                nx = x + dx
                ny = y + dy
                if field[nx][ny]==".":
                    r+=1
    if r==4: return 0
    else: return 1
                    
        
                
for i in range(0,N+2):
    for j in range(0,M+2):
        if field[i][j] == "#":
            res = res *dfs(i,j)
            
if res:print("Yes")
else:print("No")

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
C = [[0] * (W + 2) for _ in [0] * (H + 2)]
for i in range(1, H + 1):
    C[i][1:-1] = input()
for i in range(1, H + 1):
    for j in range(1, W + 1):
        if C[i][j] == '.':
            continue
        if '#' not in [C[i - 1][j], C[i][j - 1], C[i][j + 1], C[i + 1][j]]:
            print('No')
            exit()
print('Yes')

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
edge = '.' * (W + 2)
C = [edge]
for _ in range(H):
    C.append('.' + input() + '.')
C.append(edge)
for i in range(1, H + 1):
    for j in range(1, W + 1):
        if C[i][j] == '.':
            continue
        if '#' not in [C[i - 1][j], C[i][j - 1], C[i][j + 1], C[i + 1][j]]:
            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())
ok = True
for i in range(h):
    for j in range(w):
        tmp = False
        if s[i][j] == '#':
            if i+1 < h and s[i+1][j] == '#':
                tmp = True
            elif j+1 < w and s[i][j+1] == '#':
                tmp = True
            elif i-1 > -1 and s[i-1][j] == '#':
                tmp = True
            elif j-1 > -1 and s[i][j-1] == '#':
                tmp = True
        
            if tmp == False:
                ok = False

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

Submission status: Accepted

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

matrix=[]
for i in range(H):
    matrix.append(list(input()))
for h in range(1,H-1):
    for w in range(1,W-1):
        if(matrix[h][w]=="#"):
           if(matrix[h-1][w]=="." and matrix[h][w-1]=="."
              and matrix[h+1][w]=="." and matrix[h][w+1]=="."):
               print("No")
               exit()
print("Yes")

Submission status: Accepted

Solution code:
#全てのますに対して
#もし#なら、四方の１つでも#ならok
#孤立まんがいたらアウト

H,W= map(int,input().split())
le = [input() for i in range(H)]
answer = [['0' for i in range(W)] for j in range(H)]

ass='Yes'
for i in range(0,H):
    for j in range(0,W):
        bool=False

        if le[i][j]!='#':
            continue
            
        if (i!=H-1):
            if(le[i+1][j]=='#'):
    
                bool=True


        if (i!=0):
            if(le[i-1][j]=='#'):
    
                bool=True
    
        if (j!=W-1):
            if(le[i][j+1]=='#'):
    
                bool=True

        if (j!=0):
            if(le[i][j-1]=='#'):

                bool=True


        if bool==False:
            ass="No"
            break

print(ass)

Submission status: Accepted

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

isPaintable = True
for y in range(h):
    for x in range(w):
        if s[y][x]=="#":
            if x-1>=0 and s[y][x-1]=="#":
                continue
            elif y-1>=0 and s[y-1][x]=="#":
                continue
            elif x+1<w and s[y][x+1]=="#":
                continue
            elif y+1<h and s[y+1][x]=="#":
                continue
            isPaintable=False
if isPaintable:
    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):
    H = [str(i) for i in input()]
    A.append(['.'] + H + ['.'])
A.append(['.'] * (w + 2))

ans = 'Yes'

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

print(ans)

Submission status: Accepted

Solution code:
H,W=map(int,input().split())
s=[]
s1=[[]for i in range(H)]
dir=[[-1,0],[1,0],[0,-1],[0,1]]
a=0
for i in range(H):
    s.append(input())
for i in range(H):
    for a in s[i]:
        s1[i].append(a)
for i in range(H):
    for j in range(W):
        c=0
        if s1[i][j]=='#':
            for k in dir:
                if i+k[0]>=0 and i+k[0]<H and j+k[1]>=0 and j+k[1]<W and s1[i+k[0]][j+k[1]]=='#':
                    c=1
                    continue
        else:
            continue
        if c==0:
            a=1
            break
    if a==1:
        break
if a==1:
    print('No')
else:
    print('Yes')

Submission status: Accepted

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

judge = "Yes"
dx = [-1, 0, 0, 1]
dy = [0, -1, 1, 0]
for i in range(H):
	for j in range(W):
		if S[i][j] == "#":
			c = 0
			cc = 0
			for d in range(4):
				if 0 <= i + dx[d] and i + dx[d] <= H - 1 and 0 <= j + dy[d] and j + dy[d] <= W - 1:
					cc += 1
					if S[i + dx[d]][j + dy[d]] == ".":
						c += 1
			if c == cc:
				judge = "No"
				break
				

print(judge)