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())
input_list = []
for i in range(H):
    input_list.append(input())
def contain_sharp(x, y):
    if input_list[y][x] == ".": return True
    dxy = [[0,1], [0, -1], [1,0],[-1,0]]
    for dx,dy in dxy:
        if 0<= y + dy < H and 0 <= x + dx < W:
            if input_list[y+dy][x+dx] == "#":
                return True
    else :
        return False


for y in range(H):
    for x in range(W):
        if not contain_sharp(x,y):
            print("No")
            exit()
print("Yes")

Submission status: Accepted

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

graph = [[] for _ in range(H+2)]
graph[0].extend(["." for i in range(W+2)])
for h in range(H):
    graph[h+1].append(".")
    graph[h+1].extend(list(input().rstrip()))
    graph[h+1].append(".")
graph[H+1].extend(["." for i in range(W+2)])

canAchieve = True
for h in range(1,H+1):
    for w in range(1,W+1):
        if graph[h][w] == '#':
            if graph[h+1][w] == "#":
                continue
            elif graph[h-1][w] == "#":
                continue
            elif graph[h][w+1] == "#":
                continue
            elif graph[h][w-1] == "#":
                continue
            
            canAchieve = False
            
if canAchieve:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

dxy = [(0,1),(1,0),(0,-1),(-1,0)]
def is_isolated(x,y):
    if src[y][x] == '.': return False
    for dx,dy in dxy:
        if not 0 <= x+dx < W: continue
        if not 0 <= y+dy < H: continue
        if src[y+dy][x+dx] == '#': return False
    else:
        return True

for y in range(H):
    for x in range(W):
        if is_isolated(x,y):
            print('No')
            exit()
print('Yes')

Submission status: Accepted

Solution code:
def get_adjacent(lists, pos, hw):
	h, w = hw
	x, y = pos
	adjacents = []
	for adjust_y, adjust_x in ((0, 1), (1, 0), (0, -1), (-1, 0)):
		if 0 <= y+adjust_y < h and 0 <= x+adjust_x < w:
			adjacents.append(lists[y+adjust_y][x+adjust_x])
	return adjacents

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] == "#":
			if "#" not in get_adjacent(s, (x, y), (h, w)):
				print("No")
				exit()
print("Yes")

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] == "#":
			is_have_hash = False
			for adjust_y, adjust_x in ((0, 1), (1, 0), (0, -1), (-1, 0)):
				if 0 <= y+adjust_y < h and 0 <= x+adjust_x < w:
					if s[y+adjust_y][x+adjust_x] == "#":
						is_have_hash = True
						break
			if not is_have_hash:
				print("No")
				exit()
print("Yes")

Submission status: Accepted

Solution code:
from itertools import product

H, W = map(int, input().split())
C = ['.' * (W + 2)] + ['.' + input() + '.' for _ in [0] * H] + ['.' * (W + 2)]

ans = True
for i, j in product(range(1, H+1), range(1, W + 1)):
    if C[i][j] == '#' and (
            '#' not in (C[i - 1][j], C[i + 1][j], C[i][j - 1], C[i][j + 1])):
        ans = False
        break

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

Submission status: Accepted

Solution code:
def getinputdata():

    # 配列初期化
    array_result = []    
    data = input()
    array_result.append(data.split(" "))

    flg = True

    try:
        while flg:

            data = input()

            array_temp = []

            if(data != ""):
                
                array_result.append(data.split(" "))

                flg = True

            else:

                flg = False
    finally:

        return array_result

arr_data = getinputdata()

h = int(arr_data[0][0])
w = int(arr_data[0][1])

arr=[]
for i in range(1,1+h):
    
    arr_temp=[]
    for v in arr_data[i][0]:
        
        arr_temp.append(v)
    
    arr.append(arr_temp)

chkflg=True

for i in range(0,h):
    
    for j in range(0,w):

        if arr[i][j]=="#":
         
            if i==0 and j==0:
                
                if not(arr[i+1][j]=="#" or arr[i][j+1]=="#"):
                    
                    chkflg=False
                    break

            elif i==0 and j==w-1:

                if not(arr[i+1][j]=="#" or arr[i][j-1]=="#"):
                    
                    chkflg=False
                    break


            elif i==0 and 0<j<w-1:

                if not(arr[i+1][j]=="#" or arr[i][j-1]=="#" or arr[i][j+1]=="#"):
                    
                    chkflg=False
                    break

            elif i==h-1 and j==0:
                
                if not(arr[i-1][j]=="#" or arr[i][j+1]=="#"):
                    
                    chkflg=False
                    break

            elif i==h-1 and j==w:

                if not(arr[i-1][j]=="#" or arr[i][j-1]=="#"):
                    
                    chkflg=False
                    break
                    
            elif i==h and 0<j<w-1:
                
                if not(arr[i-1][j]=="#" or arr[i][j-1]=="#" or arr[i][j+1]=="#"):
                    
                    chkflg=False
                    break

            elif 0<i<h-1 and j==0:
                
                if not(arr[i-1][j]=="#" or arr[i+1][j]=="#" or arr[i][j+1]=="#"):
                    
                    chkflg=False
                    break

            elif 0<i<h-1 and j==w:

                if not(arr[i-1][j]=="#" or arr[i+1][j]=="#" or arr[i][j-1]=="#"):
                    
                    chkflg=False
                    break
                    
            elif 0<i<h-1 and 0<j<w-1:

                if not(arr[i-1][j]=="#" or arr[i+1][j]=="#" or arr[i][j-1]=="#" or arr[i][j+1]=="#"):
                    
                    chkflg=False
                    break
                    
print("Yes" if chkflg else "No")

Submission status: Accepted

Solution code:
'''input
11 11
...#####...
.##.....##.
#..##.##..#
#..##.##..#
#.........#
#...###...#
.#########.
.#.#.#.#.#.
##.#.#.#.##
..##.#.##..
.##..#..##.
'''
from sys import exit
def check(x,y):
	xx = [(0,-1),(0,1),(1,0),(-1,0)]
	flag = False
	for i in xx:
		x1 = x+i[0]
		y1 = y+i[1]
		if x1 < 0 or x1 > h-1 or y1 < 0 or y1 > w-1:
			continue
		else:
			if arr[x1][y1] == '#':
				flag = True
				break
	return flag
h,w = map(int,raw_input().split())
arr = []
for i in range(h):
	t = list(raw_input().strip())
	arr.append(t)
for i in range(h):
	for j in range(w):
		if arr[i][j] == '#':
			if not check(i,j):
				print "No"
				exit(0)
print "Yes"

Submission status: Accepted

Solution code:
H,W = map(int,input().split())
#s = [['' for j in range(W+2)] for i in range(H+2)]
s = [list(input()) for i in range(H)]
x = [-1, 0, 1, 0]
y = [0, 1 , 0, -1]
for i in range(H):
    for j in range(W):
        if (s[i][j] == "#"):
            flag = False
            for d in range(4):
                if (i+y[d] >= 0 and i+y[d] < H and j+x[d] >= 0 and j+x[d] < W):
                    if(s[i+y[d]][j+x[d]] == "#"):
                        flag = True
            if (flag == False):
                print("No")
                quit()
print("Yes")

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
t=[list(input())for i in range(h)]
def check(x,y):
    dx=[0,0,1,-1]
    dy=[1,-1,0,0]
    for k in range(4):
        x=i+dx[k]
        y=j+dy[k]
        if 0<=x and x<h and 0<=y and y<w and t[x][y]=="#":
            return True
for i in range(h):
    for j in range(w):
        if t[i][j]=="#":
            if check(i,j):
                pass
            else:
                print("No")
                exit()
print("Yes")

Submission status: Accepted

Solution code:
#coding:utf-8
H,W = map(int,input().split())
mtrx = []
for i in range(H):
    col = list(input())
    mtrx.append(col)
    
cross = [[0,1],[-1,0],[0,-1],[1,0]]

def check(i,j):
    if mtrx[i][j] == "#":
        for ij in cross:
            [im,jm] = ij
            iNew = i + im
            jNew = j + jm
            if 0 <= iNew < H and 0 <= jNew <W:
                if mtrx[iNew][jNew] == "#":
                    return
        else:
            return True
    

for i in range(H):
    for j in  range(W):
        if check(i,j):
            print("No")
            break
    else:
        continue
    break
else:
    print("Yes")

Submission status: Accepted

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

def solve(h,w):
    for i in range(1, h - 1):
        for j in range(1, w - 1):
            if s[i][j] == "#":
                if s[i - 1][j] == "#":
                    continue
                elif s[i + 1][j] == "#":
                    continue
                elif s[i][j - 1] == "#":
                    continue
                elif s[i][j + 1] == "#":
                    continue
                else:
                    return "No"
    return "Yes"

print(solve(h,w))

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
t=[list(input())for i in range(h)]
def check(x,y):
    dx=[0,0,1,-1]
    dy=[1,-1,0,0]
    jugde=False
    for k in range(4):
        i=x+dx[k]
        j=y+dy[k]
        if 0<=i and i<h and 0<=j and j<w and t[i][j]=="#":
            jugde=True
    if jugde==False:
        return False
    return True
for i in range(h):
    for j in range(w):
        if t[i][j]=="#":
            if check(i,j):
                jugde=True
            else:
                print("No")
                exit()
print("Yes")

Submission status: Accepted

Solution code:

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

# result = True
masu = [['.' for i in range(W+2)] for j in range(H+2)]
for h in range(H):
    s = "."+input()+"."
    masu[h+1] = s

# print(masu)

for h in range(1,H+1):
    for w in range(1,W+1):
        if masu[h][w] == "#":
            if "#" == masu[h+1][w] or "#" == masu[h][w+1] or "#" == masu[h-1][w] or "#" == masu[h][w-1]:
                pass
            else:
                # result = False
                print("No")
                exit()

print("Yes")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
h,w=map(int,input().split());m=["."];l=[m*(w+2)];p=l+[m+list(map(str,input()))+m for i in range(h)]+l
print("Yes"if all([any([p[i+x[0]][I+x[1]]=="#"for x in [[0,1],[0,-1],[1,0],[-1,0]]])for I in range(1,w+1)for i in range(1,h+1)if p[i][I]=="#"])else"No")

Submission status: Accepted

Solution code:
h,w=map(int,input().split());p=[["."]*(w+2)]+[["."]+list(map(str,input()))+["."]for i in range(h)]+[["."]*(w+2)]
print("Yes"if all([any([p[i+x[0]][I+x[1]]=="#"for x in [[0,1],[0,-1],[1,0],[-1,0]]])for I in range(1,w+1)for i in range(1,h+1)if p[i][I]=="#"])else"No")

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
p=[["."]*(w+2)]+[["."]+list(map(str,input()))+["."]for i in range(h)]+[["."]*(w+2)]
print(["No","Yes"][int(all([any([p[i+x[0]][I+x[1]]=="#"for x in [[0,1],[0,-1],[1,0],[-1,0]]])for I in range(1,w+1)for i in range(1,h+1)if p[i][I]=="#"]))])

Submission status: Accepted

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

def main():
    H, W = list(map(int, input().split()))
    grid = [[0 for i in range(W+2)] for j in range(H+2)]

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

ans='Yes'
for i in range(1,H-1):
    for j in range(1,W-1):
        if cambas[i][j]=='#' and cambas[i][j+1]==cambas[i+1][j]==cambas[i-1][j]==cambas[i][j-1]=='.':
            ans='No'
            break
                
print(ans)

Submission status: Accepted

Solution code:
import sys
h,w = map(int,raw_input().split())

arr = []

for i in range(h):
	arr.append(list(raw_input()))

field = [['.' for i in range(w)] for j in range(h)]

direct = [[0,-1],[1,0],[0,1],[-1,0]]

for i in range(h):
	for j in range(w):
		for k in range(4):
			dx = j + direct[k][1] 
			dy = i + direct[k][0]
			if -1 < dx and dx < w and -1 < dy and dy < h :
				if arr[i][j] == '#' and arr[dy][dx] == '#':
					field[i][j] = '#'
					field[dy][dx] = '#'

for i in range(h):
	for j in range(w):
		if arr[i][j] != field[i][j]:
			print 'No'
			sys.exit()

print 'Yes'

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
a=['.'*(w+2)]
for _ in range(h):
    a.append('.'+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]=='#' and a[i-1][j]=='.' and a[i][j-1]=='.' and a[i][j+1]=='.' and a[i+1][j]=='.':
            ans="No"
print(ans)

Submission status: Accepted

Solution code:
def m():
    h, w = map(int, input().split())
    a = [list(("."+input()+".")) for _ in range(h)]
    a.insert(0, ['.' for _ in range(w+2)])
    a.insert(h+1, ['.' for _ in range(w+2)])
    for i in range(1,h+1):
        for j in range(1,w+1):
            if a[i][j] != "#":
                continue
            if a[i+1][j] == "#":
                continue
            if a[i][j+1] == "#":
                continue
            if a[i-1][j] == "#":
                continue
            if a[i][j-1] == "#":
                continue
            return "No"
    return "Yes"

print(m())

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
matrix = []
for _ in range(H):
    row = input()
    matrix.append(row)
no_flag = False
for i, row in enumerate(matrix):
    for j, y in enumerate(row):
        if y == '#':
            if j != 0 and matrix[i][j - 1] == '#':
                continue
            elif j != W - 1 and matrix[i][j + 1] == '#':
                continue
            elif i != 0 and matrix[i - 1][j] == '#':
                continue
            elif i != H - 1 and matrix[i + 1][j] == '#':
                continue
            else:
                no_flag = True
                break
    if no_flag == True:
        print('No')
        break
else:
    print('Yes')

Submission status: Accepted

Solution code:
H,W = map(int, input().split())
A = [list(input()) for i in range(H)]
Flag = True
for i in range(H):
    for j in range(W):
        if A[i][j] == '#':
            if A[max(0, i-1)][j] == '#' or A[min(H-1,i+1)][j] == '#' or A[i][max(0,j-1)] == '#' or A[i][min(W-1,j+1)] == '#':
                pass
            else:
                Flag = False
                break
    if Flag == False:
        break
if H == 1 and W == 1 and A[0][0] == '#':
    Flag = False
if Flag == True:
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
h,w = map(int, input().split())
# print(h,w)
row = []
for x in range(h):
    col = list(input())
    row.append(col)

out = "Yes"

for x in range(h):
    for y in range (w):
        if row[x][y] == "#":
           #print(x,y)
            if  x > 0 and row[x-1][y] == "#":
                pass
            elif x < h-1 and row[x+1][y] == "#":
                pass
            elif y > 0 and row[x][y-1] == "#" :
                pass
            elif y < w-1  and row [x][y+1] == "#" :
                pass
            else:
                out = "No"
                break
        pass

print(out)

Submission status: Accepted

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

#与えられた領域の上下左右を塗れないマスで埋める
s.append('.'*(W+2))
for i in range(H):
  s.append('.'+input()+'.')
s.append('.'*(W+2))

#隣接領域について判定
for j in range(1,H+1):
  for i in range(1,W+1):
    if s[j][i]=='#' and (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:
h,w=map(int,input().split())
b=[]
b.append(list('.'*(w*2)))
for i in range(h):
    a=list('.'+str(input())+'.')
    b.append(a)

b.append(list('.'*(w*2)))

for y in range(1,h+1):
    for x in range(1,w+1):
        if b[y][x]=='#':
            up   = b[y-1][x]
            down = b[y+1][x]
            left = b[y][x-1]
            right= b[y][x+1]

            if up=='.' and down=='.' and left=='.' and right=='.':
                print('No')
                exit()

print('Yes')

Submission status: Accepted

Solution code:
x=input().split()
h=int(x[0])
w=int(x[1])
s=['']*h*w
for i in range(h):
    row=input()
    for j in range(w):
        s[i*w+j]=row[j]
i=0
boo=True

while i<h*w:
    if i<w:
        if i==0:
            if s[i]=='#' and s[i+1]!='#' and s[i+w]!='#':
                boo=False
                break
        elif i==w-1:
            if s[i]=='#' and s[i-1]!='#' and s[i+w]!='#':
                boo=False
                break
        else:
            if s[i]=='#' and s[i+1]!='#' and s[i+w]!='#' and s[i-1]!='#':
                boo=False
                break
    elif i%w==0:
        if i==w*(h-1):
            if s[i]=='#' and s[i+1]!='#' and s[i-w]!='#':
                boo=False
                break
        else:
            if s[i]=='#' and s[i+1]!='#' and s[i+w]!='#' and s[i-w]!='#':
                boo=False
                break
    elif i%w==w-1:
        if i==h*w-1:
            if s[i]=='#' and s[i-1]!='#' and s[i-w]!='#':
                boo=False
                break
        else:
            if s[i]=='#' and s[i-1]!='#' and s[i+w]!='#' and s[i-w]!='#':
                boo=False
                break
    elif i>w*(h-1):
        if s[i]=='#' and s[i-1]!='#' and s[i+1]!='#' and s[i-w]!='#':
            boo=False
            break
    else:
        if s[i]=='#' and s[i-1]!='#' and s[i+1]!='#' and s[i-w]!='#' and s[i+w]!='#':
            boo=False
            break
    i+=1
if boo:
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

for y in range(1, h + 1):
    for x in range(1, w + 1):
        if field[y][x] == "#":
                if("#" in [field[y + 1][x], field[y - 1][x], field[y][x + 1], field[y][x - 1]]):
                    pass
                else:
                    print("No")
                    quit()

print("Yes")

Submission status: Accepted

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

for i in range(1, H+1):
    for j in range(1,W+1):
        if grid[i][j]=='#':
            if grid[i-1][j]=='.' and grid[i][j-1]=='.' and grid[i+1][j]=='.' and grid[i][j+1]=='.':
                print("No")
                quit()
        else:
            pass
print('Yes')

Submission status: Accepted

Solution code:
import sys

H, W = map(int, input().split())
S = [list(input()) for _ in range(H)]
for i in S:
    i.insert(0, '.')
    i.append('.')
S.insert(0, ['.' for _ in range(W+2)])
S.append(['.' for _ in range(W+2)])
DI = [-1, 0, 0, 1]
DJ = [0, -1, 1, 0]
count = 0

for i in range(1, H+1):
    for j in range(1, W+1):
        if S[i][j] == '#':
            # '#'であれば隣接マスを探索
            for di, dj in zip(DI, DJ):
                if S[i+di][j+dj] == '#':
                    count += 1
            if count == 0:
                print('No')
                sys.exit()
            count = 0
print('Yes')

Submission status: Accepted

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

for i in range(h):
  for j in range(w):
    f = 0
    if s[i][j] == "#":
      for dx_ in dx:
        for dy_ in dy:
          if (dx_==0 and dy_!=0) or (dx_!=0 and dy_==0):
            nx, ny = j+dx_, i+dy_
            if 0<=nx<w and 0<=ny<h:
              if s[ny][nx] == "#":
                f = 1
      if f == 0:
        flag = 1
if flag:
  print("No")
else:
  print("Yes")

Submission status: Accepted

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

ssum = 0
ssum2 = 0
for i in range(h):
    for j in range(w):
        if s[i][j] == "#":
            # print(i, j, s[i][j])
            if 0 < i:
                # print(s[i-1][j])
                if s[i-1][j] == "#":
                    s2[i][j] = True
            if i < h-1:
                # print(s[i+1][j])
                if s[i+1][j] == "#":
                    s2[i][j] = True
            if 0 < j:
                # print(s[i][j-1])
                if s[i][j-1] == "#":
                    s2[i][j] = True
            if j < w-1:
                # print(s[i][j+1])
                if s[i][j+1] == "#":
                    s2[i][j] = True
            if s2[i][j]:
                ssum2 += 1
            ssum += 1
if ssum == ssum2:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:

def main():
    y, x = [int(i) for i in input().split()]
    a = []
    for i in range(y):
        a.append(input().strip())

    for i in range(x):
        for j in range(y):
            link = False
            if a[j][i] == '#':
                if i-1 >= 0 and a[j][i-1] == '#':
                    link = True
                if i+1 < x and a[j][i+1] == '#':
                    link = True
                if j-1 >= 0 and a[j-1][i] == '#':
                    link = True
                if j+1 < y and a[j+1][i] == '#':
                    link = True

                if not link:
                    print('No')
                    return

    print('Yes')

if __name__ == '__main__':
    main()

Submission status: Accepted

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

for i in range(1, h+1):
    line = input()
    for j in range(1, w+1):
        s[i][j] = line[j-1]

flag = True

for i in range(1, h+1):
    for j in range(1, w+1):
        if s[i][j] == '#':
            if s[i-1][j] == '#' or s[i+1][j] == '#' or s[i][j-1] == '#' or s[i][j+1] == '#':
                pass
            else:
                flag = False
                break

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

Submission status: Accepted

Solution code:
#ABC096 C - Grid Repainting 2
I = raw_input().split(" ")
H = int(I[0])
W = int(I[1])
A = [list(raw_input()) for i in range(H)]
ans = 0
for X in range(H):
    for Y in range(W):
        counter = 0
        if A[X][Y] == "#":
            if X != 0 and A[X][Y] == A[X - 1][Y]:
                counter += 1
            if X != H - 1 and A[X][Y] == A[X + 1][Y]:
                counter += 1
            if Y != 0 and A[X][Y] == A[X][Y - 1]:
                counter += 1
            if Y != W - 1 and A[X][Y] == A[X][Y + 1]:
                counter += 1
            if counter == 0:
                ans += 1
if ans == 0:
    print "Yes"
else:
    print "No"

Submission status: Accepted

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

s.append(['.']*W)
s.insert(0, ['.']*W)
for i in range(H+2):
  s[i].append('.')
  s[i].insert(0, '.')


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

print(ans)

Submission status: Accepted

Solution code:
y,x=map(int,input().split())
g=[input() for i in range(y)]
flag=True
for yy in range(1,y-1):
    for xx in range(1,x-1):
        if g[yy][xx]=='#':
            if g[yy-1][xx]==g[yy+1][xx]==g[yy][xx-1]==g[yy][xx+1]=='.':
                flag=False
if(flag):
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

table = []

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

counter = 0
	
def check(x,y):
	counter = 0
			
	if x > 0:
		if table[y][x-1] == '#':
			counter += 1
			
	if x < W-1:
		if table[y][x+1] == '#':
			counter += 1
	
	if y > 0:
		if table[y-1][x] == '#':
			counter += 1
	
	if y < H-1:
		if table[y+1][x] == '#':
			counter += 1
	
	if counter == 0:
		print('No')
		quit()
			
	

for y in range(H):
	for x in range(W):
		if table[y][x] == '#':
			check(x,y)

print ('Yes')

Submission status: Accepted

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

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

Submission status: Accepted

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

def check(i,j):
    if s[i][j] == '.':
        return True
    if i != 0 and s[i-1][j] == '#':
        return True
    if j != 0 and s[i][j-1] == '#':
        return True
    if i != H-1 and s[i+1][j] == '#':
        return True
    if j != W-1 and s[i][j+1] == '#':
        return True
    return False

for i in range(H):
    for j in range(W):
        if not check(i,j):
            print('No')
            exit()
print('Yes')

Submission status: Accepted

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

Submission status: Accepted

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

flag = False
for i in range(1, H-1):
    for j in range(1, W-1):
        if s[i][j] == "#" and (s[i-1][j] == s[i+1][j] == s[i][j-1] == s[i][j+1] == "."):
            print("No")
            flag = True
            break
    if flag:
        break
else:
    print("Yes")

Submission status: Accepted

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

list_masu = []

for i in range(H):
	str1 = str(input())
	charlist = list(str1)
	list_masu.append(charlist)

blacklist = []
for n in range(H):
	for m in range(W):
		if(list_masu[n][m]=="#"):
			blacklist.append((n,m))

blacklist.sort()

count = 0

for b in range(0,len(blacklist)):
	for i in range(0,len(blacklist)):
		if(b!=i and blacklist[b][0] == blacklist[i][0]):
			if((blacklist[b][1] == blacklist[i][1]+1) or (blacklist[b][1] == blacklist[i][1]-1)):
				count += 1
				break
		elif(b!=i and blacklist[b][1] == blacklist[i][1]):
			if((blacklist[b][0] == blacklist[i][0]+1) or (blacklist[b][0] == blacklist[i][0]-1)):
				count += 1
				break


if(count==len(blacklist)):
	print("Yes")
else:
	print("No")

Submission status: Accepted

Solution code:
# HとWに整数型で行数、列数を代入
H, W = map(int, input().split())
# print(H, W)
c = []

# for分で列をリスト化して代入
for i in range(H):
    s = list(input())
    c.append(s)

# print(c)
# count変数を初期化
count = 0

# for文でcの各要素を調べて'#'の場合、上下左右に'#'があるかどうか調べる
for i in range(H):
    for j in range(W):
        # pythonではリストの範囲外を指定するとエラーが発生するので、try except で回避する
        try:
            if (c[i][j] == '#' and c[i][j-1] != '#' and c[i-1][j] != '#' and c[i][j+1] != '#' and c[i+1][j] != '#'):
                # 問題文にそぐわない並びをしていたら、countに足す
                count += 1
        except IndexError:
            if i == W - 1 and i == H - 1:
                if (c[i][j] == '#' and c[i][j-1] != '#' and c[i-1][j] != '#'):
                    count += 1

            elif i == W - 1:
                if (c[i][j] == '#' and c[i][j-1] != '#' and c[i-1][j] != '#' and c[i+1][j] != '#'):
                    count += 1

            elif i == H - 1:
                if (c[i][j] == '#' and c[i][j-1] != '#' and c[i-1][j] != '#' and c[i][j+1] != '#'):
                    count += 1

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
r,c=[int(x) for x in str(input()).split()]
image=[[0 for x in range(0,c+2)]]
for i in range(1,r+1):
  x=list(str(input()))

  d=[0]
  for i in range(0,c):
    if x[i]=='.':
      d.append(0)
    else:
      d.append(1)
  d.append(0)

  image.append(d)
image+=[[0 for x in range(0,c+2)]]

counter=0
for x in range(1,r+1):
  for y in range(1,c+1):
    if image[x][y]==1:
      s=image[x-1][y]
      t=image[x+1][y] 
      u=image[x][y-1] 
      v=image[x][y+1]
      if s+t+u+v==0:

        counter=-1
if counter==-1:
  print('No')
else:
  print('Yes')