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: Wrong Answer

Solution code:
H, W = map(int, input().split())
matrix = []
for _ in range(H):
    row = input().split()
    matrix.append(row)
no_flag = False
for i, x in enumerate(matrix):
    for j, y in enumerate(matrix[i]):
        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')
else:
    print('Yes')

Submission status: Wrong Answer

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: Wrong Answer

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 Flag == True:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

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: Wrong Answer

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
if '#' in s:
    boo=True
else:
    boo=False

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: Wrong Answer

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
if '#' in s:
    boo=True
else:
    boo=False

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
    i+=1
if boo:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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:
		if table[y][x+1] == '#':
			counter += 1
	
	if y > 0:
		if table[y-1][x] == '#':
			counter += 1
	
	if y >= H:
		if table[y+1][x] == '#':
			counter += 1
	
	if counter == 0:
		print('No')
		quit()
			
	

for y in range(H):
	for x in range(W):
		check(x,y)

print ('Yes')

Submission status: Wrong Answer

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

table = []

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


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

for y in range(H):
	for x in range(W):
		check(x,y)

print ('Yes')

Submission status: Wrong Answer

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

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 = True
				break
if flag:
	print("Yes")
else:
	print("No")

Submission status: Wrong Answer

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

for i in range(1, H - 1):
	for j in range(1, W - 1):
		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 = True
			break
if flag:
	print("Yes")
else:
	print("No")

Submission status: Wrong Answer

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-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: Wrong Answer

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-1][j] == "." and s_list[i+1][j] == "." and s_list[i][j-1] == "." and s_list[i][j+1] == ".":
			flag = False
if flag:
	print("Yes")
else:
	print("No")

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())
s = [input() for i 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] == s[i+1][j] == s[i][j-1] == s[i][j+1] == ".":
                print("No")
                break
else:
    print("Yes")

Submission status: Wrong Answer

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)-1):
		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: Wrong Answer

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)-1):
		if(b!=i and blacklist[b][0] == blacklist[i][0]):
			if((blacklist[b][1] == blacklist[i][1]+1) or (blacklist[b][1]+1 == blacklist[i][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]+1 == blacklist[i][0])):
				count += 1
				break


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

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())
cam = []
for i in range(H):
	col = input()
	cam.append(col)
flag = True
for i in range(1, H-1):
	for j in range(1, W-1):
		if cam[i][j] == "#":
			if cam[i-1][j] == "." and cam[i+1][j] == "." and cam[i][j-1] and cam[i][j+1]:
				flag = False
if flag == True:
	print("Yes")
else:
	print("No")

Submission status: Wrong Answer

Solution code:
import sys
 
N, M = map(int, input().split())
a = []
tmp = []
for i in range(N):
    tmp = list(map(str,input().split()))
    a.append(list(tmp[0]))
 
 
cpi = [-1,0,0,1]
cpj = [0,-1,1,0]
 
smFlag = False
 
for i in range(N):
    for j in range(M):
        if a[i][j] == '#':
            for x,y in zip(cpi,cpj):
                if N > i + x > -1 and M > j + y > -1:
                    if a[i+x][j+y] == '#':
                        smFlag = True
            if not smFlag:
                print('No')
                sys.exit(0)

print('Yes')

Submission status: Wrong Answer

Solution code:
import sys
 
N, M = map(int, input().split())
a = []
tmp = []
for i in range(N):
    tmp = list(map(str,input().split()))
    a.append(list(tmp[0]))
 
 
cpi = [-1,0,0,1]
cpj = [0,-1,1,0]
 
smFlag = False
 
for i in range(N):
    for j in range(M):
        if a[i][j] == '#':
            for x,y in zip(cpi,cpj):
                if N > i + x > -1 and M > j + y > -1:
                    if a[i+x][j+y] == '#':
                        smFlag = True
            if not smFlag:
                print('No')
                sys.exit(0)
                
print('Yes')

Submission status: Wrong Answer

Solution code:
import sys

# pre process
X = [int(i) for i in input().split()]
H, W = X
grid = []
for row in range(H):
    grid.append([char for char in input()])



# solve
if H == 1 and W == 1:
    print('No')
    exit(0)
elif H == 1:
    for w in range(W):
        if grid[0][w] == "#":
            if w == 0:
                if not(grid[0][w+1] == '#'):
                    print("No")
                    exit(0)
            elif w == W-1:
                if not(grid[0][w-1] == '#'):
                    print("No")
                    exit(0)
            else:
                if not (grid[0][w - 1] == '#' or grid[0][w+1] == '#'):
                    print("No")
                    exit(0)
elif W == 1:
    for h in range(H):
        if grid[h][0] == "#":
            if h == 0:
                if not(grid[h+1][0] == '#'):
                    print("No")
                    exit(0)
            elif h == H-1:
                if not(grid[h-1][0] == '#'):
                    print("No")
                    exit(0)
            else:
                if not (grid[h-1][0] == '#' or grid[h+1][0] == '#'):
                    print("No")
                    exit(0)
else:
    for h in range(H):
        for w in range(W):
            if grid[h][w] == "#":
                # 枠の内側
                if h != 0 and h != H-1 and w != 0 and w != W-1:
                    if not(grid[h+1][w] == "#" or grid[h-1][w] == '#' or grid[h][w-1] == '#' or grid[h][w+1] == '#'):
                        print("No1")
                        exit(0)
                # 枠の上ふち
                elif h == 0:
                    if w == 0:
                        if not(grid[h+1][w] == "#" or grid[h][w+1] == '#'):
                            print("No2")
                            exit(0)
                    elif w == W-1:
                        if not(grid[h+1][w] == "#" or grid[h][w-1] == '#'):
                            print("No3")
                            exit(0)
                    else:
                        if not (grid[h + 1][w] == "#" or grid[h][w - 1] == '#' or grid[h][w + 1] == '#'):
                            print("No4")
                            exit(0)
                # 枠の下ふち
                elif h == H-1:
                    if w == 0:
                        if not (grid[h - 1][w] == "#" or grid[h][w + 1] == '#'):
                            print("No5")
                            exit(0)
                    elif w == W-1:
                        if not (grid[h - 1][w] == "#" or grid[h][w - 1] == '#'):
                            print("No6")
                            exit(0)
                    else:
                        if not (grid[h - 1][w] == "#" or grid[h][w - 1] == '#' or grid[h][w + 1] == '#'):
                            print("No7")
                            exit(0)
                # 枠の左ふち
                elif w == 0:
                    if not (grid[h + 1][w] == "#" or grid[h-1][w] == '#' or grid[h][w + 1] == '#'):
                        print("No8")
                        print(h,w)
                        exit(0)
                # 枠の左ふち
                elif w == W-1:
                    if not (grid[h + 1][w] == "#" or grid[h - 1][w] == '#' or grid[h][w -1] == '#'):
                        print("No9")
                        exit(0)
print('Yes')

Submission status: Wrong Answer

Solution code:
a =str(input()).split(" ")
h = int(a[0])
w = int(a[1])
maps= []

for i in range(h):
    maps.append(list(input()))
   
for i in range(h):
    for j in range(w):
        if maps[i][j] == "#":
            if j - 1 > 0 and maps[i][j - 1] == "#":
                continue
            elif j + 1 < w and maps[i][j + 1] == "#" :
                continue
            elif i + 1 < h and maps[i + 1][j] == "#" :
                continue
            elif i - 1 > 0 and maps[i - 1][j] == "#":
                continue
            else:
                print("No")
                exit()
        else:
            pass
print("Yes")

Submission status: Wrong Answer

Solution code:
a =str(input()).split(" ")
h = int(a[0])
w = int(a[1])
maps= []

for i in range(h):
    maps.append(list(input()))
   
for i in range(h - 1 ):
    for j in range(w):
        if maps[i][j] == "#":
            if j - 1 > 0 and maps[i][j - 1] == "#":
                continue
            elif j + 1 < w and maps[i][j + 1] == "#" :
                continue
            elif i + 1 < h and maps[i + 1][j] == "#" :
                continue
            elif i - 1 > 0 and maps[i - 1][j] == "#":
                continue
            else:
                print("No")
                exit()
        else:
            pass
print("Yes")

Submission status: Wrong Answer

Solution code:
a =str(input()).split(" ")
h = int(a[0])
w = int(a[1])
maps= []

for i in range(h):
    maps.append(list(input()))
   
for i in range(h - 1 ):
    for j in range(w - 1):
        if maps[i][j] == "#":
            if j - 1 > 0 and maps[i][j - 1] == "#":
                continue
            elif j + 1 < w and maps[i][j + 1] == "#" :
                continue
            elif i + 1 < h and maps[i + 1][j] == "#" :
                continue
            elif i - 1 > 0 and maps[i - 1][j] == "#":
                continue
            else:
                print("No")
                exit()
        else:
            pass
print("Yes")

Submission status: Wrong Answer

Solution code:
a =str(input()).split(" ")
h = int(a[0])
w = int(a[1])
maps= []

for i in range(h):
    maps.append(list(input()))
   
for i in range(h - 1 ):
    for j in range(w - 1):
        if maps[i][j] == "#":
            if j - 1 > 0 and maps[i][j - 1] == "#":
                continue
            elif j + 1 < w and maps[i][j + 1] == "#" :
                continue
            elif i + 1 < h and maps[i + 1][j] == "#" :
                continue
            elif i - 1 > 0 and maps[i - 1][j] == "#":
                continue
            else:
                print("No")
                exit()
        else:
            pass
        print(i,j)
print("Yes")

Submission status: Wrong Answer

Solution code:
a =str(input()).split(" ")
h = int(a[0])
w = int(a[1])
maps= []

for i in range(h):
    maps.append(list(input()))
   
for i in range(h - 1 ):
    for j in range(w - 1):
        if maps[i][j] == "#":
            if j - 1 > 0 and maps[i][j - 1] == "#":
                continue
            elif j + 1 < w and maps[i][j + 1] == "#" :
                continue
            elif i + 1 < h and maps[i + 1][j] == "#" :
                continue
            elif i - 1 > 0 and maps[i - 1][j] == "#":
                continue
            else:
                print("No")
                exit()
        print(i,j)
print("Yes")

Submission status: Wrong Answer

Solution code:
a =str(input()).split(" ")
h = int(a[0])
w = int(a[1])
maps= []

for i in range(h):
    maps.append(list(input()))
   
for i in range(h - 1 ):
    for j in range(w):
        if maps[i][j] == "#":
            if j - 1 > 0 and maps[i][j - 1] == "#":
                continue
            elif j + 1 < w and maps[i][j + 1] == "#" :
                continue
            elif i + 1 < h and maps[i + 1][j] == "#" :
                continue
            elif i - 1 > 0 and maps[i - 1][j] == "#":
                continue
            else:
                print("No")
                exit()
        print(i,j)
print("Yes")

Submission status: Wrong Answer

Solution code:
a =str(input()).split(" ")
h = int(a[0])
w = int(a[1])
maps= []

for i in range(h):
    maps.append(list(input()))
   
for i in range(h-1):
    for j in range(w-1):
        if maps[i][j] == "#":
            if maps[i][j - 1] == "#" and j - 1 > 0:
                continue
            elif maps[i][j + 1] == "#" and j + 1 < w:
                continue
            elif maps[i + 1][j] == "#" and i + 1 < h:
                continue
            elif maps[i - 1][j] == "#" and i - 1 > 0:
                continue
            else:
                print("No")
                exit()
        else:
            pass

print("Yes")

Submission status: Wrong Answer

Solution code:
a =str(input()).split(" ")
h = int(a[0])
w = int(a[1])
maps= []

for i in range(h):
    maps.append(list(input()))

for i in range(h-1):
    for j in range(w-1):
        if maps[i][j] == "#":
            if maps[i][j - 1] == "#" and j - 1 > 0:
                break
            elif maps[i][j + 1] == "#" and j + 1 < w:
                break
            elif maps[i + 1][j] == "#" and i + 1 < h:
                break
            elif maps[i - 1][j] == "#" and i - 1 > 0:
                break
            else:
                print("No")
                exit()
        else:
            pass

print("Yes")

Submission status: Wrong Answer

Solution code:
a =str(input()).split(" ")
h = int(a[0])
w = int(a[1])
maps= []

for i in range(h):
    maps.append(list(input()))

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

print("Yes")

Submission status: Wrong Answer

Solution code:
import numpy as np
h,w=map(int,input().split())
s=list(input() for i in range(h))
flag=False
ans="Yes"
for i in range(h):
    for j in range(w):
        if(s[i][j]=="#"):
            flag=False
            for k in[-1,1]:
                if(i+k<h and 0<=i+k and s[i+k][j]=="#"):
                    flag=True
                    break
                if(j+k<w and 0<=j+k and s[i][j+k]=="#"):
                    flag=True
                    break
                if(flag==False):
                    ans="No"
                    break

        
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
h,w=map(int,input().split())
s=list(input() for i in range(h))
flag=False
ans="Yes"
for i in range(h):
    for j in range(w):
        if(s[i][j]=="#"):
            flag=False
            for k in[-1,1]:
                if(i+k<h and 0<=i+k and s[i+k][j]=="#"):
                    flag=True
                    break
                if(j+k<w and 0<=j+k and s[i][j+k]=="#"):
                    flag=True
                    break
                ans="No"

        
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
h,w=map(int,input().split())
s=list(input() for i in range(h))
flag=False
for i in range(h):
    for j in range(w):
        if(s[i][j]=="#"):
            flag=False
            for k in[-1,1]:
                if(i+k<h and 0<=i+k and s[i+k][j]=="#"):
                    flag=True
                if(j+k<w and 0<=j+k and s[i][j+k]=="#"):
                    flag=True

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

Submission status: Wrong Answer

Solution code:
import numpy as np
h,w=map(int,input().split())
s=list(input() for i in range(h))
flag=False
for i in range(h):
    for j in range(w):
        if(s[i][j]=="#"):
            flag=False
            for k in[-1,1]:
                if(i+k<h and 0<i+k and s[i+k][j]=="#"):
                    flag=True
                if(j+k<w and 0<j+k and s[i][j+k]=="#"):
                    flag=True

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

Submission status: Wrong Answer

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

ans = "Yes"

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

print(ans)

Submission status: Wrong Answer

Solution code:
# H * W の行列をする
H, W = map(int, input().split())
field = [input() for i in range(H)] 
count = 0

print(field)

for i in range(H):
    for j in range(W):
        # 注目している点が#でその上下左右が#でないときにcountが加算される
        # このcountが1以上になると、#が孤立していることになり、Noが出力される
        if (i == 0 and j == 0) or (i == H-1 and j == 0) or (i == 0 and j == W-1) or (i == H-1 and j == W-1):
            pass
        elif i == 0:
            if field[i][j] == '#' and field[i][j-1] != '#' and field[i][j+1] != '#' and field[i+1][j] != '#':
                count += 1
        elif i == H-1:
            if field[i][j] == '#' and field[i][j-1] != '#' and field[i][j+1] != '#' and field[i-1][j] != '#':
                count += 1
        elif j == 0:
            if field[i][j] == '#' and field[i][j-1] != '#' and field[i][j+1] != '#' and field[i+1][j] != '#':
                count += 1
        elif j == W-1:
            if field[i][j] == '#' and field[i][j-1] != '#' and field[i+1][j] != '#' and field[i-1][j] != '#':
                count += 1
        elif field[i][j] == '#' and field[i][j-1] != '#' and field[i][j+1] != '#' and field[i+1][j] != '#' and field[i-1][j] != '#':
            count += 1
print('No' if count>=1 else 'Yes')

Submission status: Wrong Answer

Solution code:
h, w = map(int, input().split())
#inputの両端に.を入れてリストに格納
ls = [[i for i in '.'+input()+'.'] for i in range(h)]
print(ls)
#上段を埋める
ls.insert(0, ['.' for i in range(w+2)])
print(ls)
#下段を埋める
ls.append(['.' for i in range(w+2)])
print(ls)

for i in range(len(ls)):
    print(ls[i])

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
arr = [list(input()) for i in range(N)]
newmat = [[0 for i in range(M)] for j in range(N)]
nocheck = 0
count = 0
for i in range(N):
    for j in range(M):
        if arr[i][j] is '#':
            newmat[i][j] = 1
        else:
            newmat[i][j] = 0

for i in range(N):
    for j in range(M):
        if newmat[i][j] == 1:
            count += 1
            if i == 0 and j == 0:
                if newmat[i][j+1] == 0 and newmat[i+1][j] == 0:
                    nocheck = 1
                    break
            elif i == 0 and j == (M-1):
                if newmat[i][j-1] == 0 and newmat[i+1][j] == 0:
                    nocheck = 1
                    break
            elif i == (N-1) and j == 0:
                if newmat[i][j+1] == 0 and newmat[i-1][j] == 0:
                    nocheck = 1
                    break
            elif i == (N-1) and j == (M-1):
                if newmat[i][j-1] == 0 and newmat[i-1][j] == 0:
                    nocheck = 1
                    break
            elif i == 0 and j != 0:
                if newmat[i][j+1] == 0 and newmat[i+1][j] == 0 and newmat[i][j-1] == 0:
                    nocheck = 1
                    break
            elif i != 0 and j == 0:
                if newmat[i][j + 1] == 0 and newmat[i + 1][j] == 0 and newmat[i-1][j] == 0:
                    nocheck = 1
                    break
            elif i == (N-1) and j != (M-1):
                if newmat[i][j+1] == 0 and newmat[i-1][j] == 0 and newmat[i][j-1] == 0:
                    nocheck = 1
                    break
            elif i != (N-1) and j == (M-1):
                if newmat[i-1][j] == 0 and newmat[i+1][j] == 0 and newmat[i][j-1] == 0:
                    nocheck = 1
                    break

            else:
                if newmat[i][j + 1] == 0 and newmat[i + 1][j] == 0 and newmat[i][j - 1] == 0 and newmat[i-1][j]:
                    nocheck = 1

if(nocheck == 0 and count != 1):
    print("Yes")
else:
    print("No")