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())
s = [input() for i in range(h)]
dx = [ 1, 1,-1,-1]
dy = [ 1,-1, 1,-1]
for i in range(h):
    for j in range(w):
        count = 0
        if s[i][j]=="#":
            for k in range(4):
                x = i + dx[k]
                y = j + dy[k]
                if s[x][y] == "#" and x >= 0 and x <= h-1 and y >= 0 and y <= w-1:
                    count += 1
            if count == 0:
                print("No")
                break
        else:
            continue
        break
    else:
        continue
    break
print("Yes")

Submission status: Wrong Answer

Solution code:
h,w =map(int,input().split())
s = [input() for i in range(h)]
dx = [ 1, 1,-1,-1]
dy = [ 1,-1, 1,-1]
for i in range(h):
    for j in range(w):
        if s[i][j]=="#":
            count = 0
            for k in range(4):
                x = i + dx[k]
                y = j + dy[k]
                if s[x][y] == "#" and x >= 0 and x <= h-1 and y >= 0 and y <= w-1:
                    count += 1
            if count == 0:
                print("No")
                break
        else:
            continue
        break
    else:
        continue
    break
print("Yes")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

mp = []
for i in range(h):
    tmp = list(input())
    tml = []
    for j in range(w):
        tml.append(0 if tmp[j] == "." else 1)
    mp.append(tml)
    
#print(mp)

flg = 0
for i in range(1,h-1):
    for j in range(1,w-1):
        if((mp[i][j] == 1) and (mp[i-1][j]+mp[i+1][j]+mp[i][j-1]+mp[i][j+1] == 0)):
            flg = 1
 #           print("{}, {}".format(i,j))
            break
        
ans = ["YES","NO"]
		
print(ans[flg])

Submission status: Wrong Answer

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

mp = []
for i in range(h):
    tmp = list(input())
    tml = []
    for j in range(w):
        tml.append(0 if tmp[j] == "." else 1)
    mp.append(tml)
    
print(mp)

flg = 0
for i in range(1,h-1):
    for j in range(1,w-1):
        if((mp[i][j] == 1) and (mp[i-1][j]+mp[i+1][j]+mp[i][j-1]+mp[i][j+1] == 0)):
            flg = 1
            print("{}, {}".format(i,j))
            break
        
ans = ["YES","NO"]
		
print(ans[flg])

Submission status: Wrong Answer

Solution code:
h,w=map(int,input().split())
a=[0]*(w+2)
m=[a]
ans='Yes'
for i in range(h):
    s=input()
    m.append([0]+[1 if x=='#' else 0 for x in s]+[0])
m.append(a)
for i in range(1,h+1):
    for j in range(1,w+1):
        if m[i][j]==1 and sum(m[i][j-1:j+2],m[i-1][j]+m[i+1][j])==1:
            ans='No'
            print(i,j)
print(ans)

Submission status: Wrong Answer

Solution code:
h,w=map(int,input().split())
a=[0]*(w+2)
m=[a]
ans='Yes'
for i in range(h):
    s=input()
    m.append([0]+[1 if x=='#' else 0 for x in s]+[0])
m.append(a)
for i in range(1,h+1):
    for j in range(1,w+1):
        if sum(m[i][j-1:j+2],m[i-1][j]+m[i+1][j])==1:
            ans='No'
print(ans)

Submission status: Wrong Answer

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

achievable = True

for i in range(h):
    for j in range(w):
        x = grid[i][j]
        
        if x == '#':
            count = 0
            if i - 1 > 0 and grid[i - 1][j] == '#':
                count += 1
            if i + 1 < h and grid[i + 1][j] == '#':
                count += 1
            if j - 1 > 0 and grid[i][j - 1] == '#':
                count += 1
            if j + 1 < w and grid[i][j + 1] == '#':
                count += 1
            
            if count == 0:
                achievable = False
                
print('Yes' if achievable else 'No')

Submission status: Wrong Answer

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

for i in range(h):
    for j in range(w):
        if pic[i][j] == "#":
            # 上下左右の順に判定
            # １つでもあれば次へ
            if ((i-1 > 0 and pic[i-1][j] == "#")
                or 
                (i+1 < h and pic[i+1][j] == "#")
                or
                (j-1 > 0 and pic[i][j-1] == "#")
                or
                (j+1 < w and pic[i][j+1] == "#") ):
                continue
            else:
                print("No")
                exit()

print("Yes")

Submission status: Wrong Answer

Solution code:
row,column = map(int,input().split())
S = [list(input()) for i in range(row)]
status = "No"
coords = [[1,0],[-1,0],[0,1],[0,-1]]
for i in range(row):
  for j in range(column):
    if S[i][j] == "#":
      status = "No"
      for dx,dy in coords:
        if 0<= i+dy <row and 0<= j + dx < column:
          if S[i + dy][j + dx] ==  "#":
            status = "Yes"
print(status)

Submission status: Wrong Answer

Solution code:
row,column = map(int,input().split())
S = [list(input()) for i in range(row)]
status = "Yes"
coords = [[1,0],[-1,0],[0,1],[0,-1]]
for i in range(row):
  for j in range(column):
    if S[i][j] == "#":
      status = "No"
      for dx,dy in coords:
        if 0<= i+dy <row and 0<= j + dx < column:
          if S[i + dy][j + dx] ==  "#":
            status = "Yes"
print(status)

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())
matrix1 = list(list(input()) for i in range(H))
for i in matrix1:
    for j in i:
        if matrix1[matrix1.index(i)][i.index(j)] == "#":
            if matrix1.index(i) - 1 >= 0 and matrix1[matrix1.index(i) - 1][i.index(j)] == '.':
                if i.index(j) - 1 >= 0 and matrix1[matrix1.index(i)][i.index(j) - 1] == '.':
                    if i.index(j) + 1 <= len(i) - 1 and matrix1[matrix1.index(i)][i.index(j) + 1] == '.':
                        if matrix1.index(i) + 1 <= len(matrix1) - 1 and matrix1[matrix1.index(i) + 1][i.index(j)] == '.':
                            print('No')
                            exit()
print('Yes')

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())
matrix1 = list(list(input()) for i in range(H))
for i in matrix1:
    for j in i:
        if matrix1[matrix1.index(i)][i.index(j)] == "#":
            if matrix1.index(i) - 1 >= 0 and matrix1[matrix1.index(i) - 1][i.index(j)] == '#':
                break
            elif i.index(j) - 1 >= 0 and matrix1[matrix1.index(i)][i.index(j) - 1] == '#':
                break
            elif i.index(j) + 1 <= len(i) - 1 and matrix1[matrix1.index(i)][i.index(j) + 1] == '#':
                break
            elif matrix1.index(i) + 1 <= len(matrix1) - 1 and matrix1[matrix1.index(i) + 1][i.index(j)] == '#':
                break
            else:
                print('No')
                exit()
print('Yes')

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())
matrix1 = list(list(input()) for i in range(H))
for i in matrix1:
    for j in i:
        if matrix1[matrix1.index(i)][i.index(j)] == ".":
            break
        elif matrix1.index(i) - 1 >= 0 and matrix1[matrix1.index(i) - 1][i.index(j)] == '#':
            break
        elif i.index(j) - 1 >= 0 and matrix1[matrix1.index(i)][i.index(j) - 1] == '#':
            break
        elif i.index(j) + 1 <= len(i) - 1 and matrix1[matrix1.index(i)][i.index(j) + 1] == '#':
            break
        elif matrix1.index(i) + 1 <= len(matrix1) - 1 and matrix1[matrix1.index(i) + 1][i.index(j)] == '#':
            break
        else:
            print('No')
            exit()
print('Yes')

Submission status: Wrong Answer

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


for i in range(H):
    for j in range(W):
        if glid[i][j] == '#':

            if 0 <= i-1 and i+1 < H and 0 <= j-1 and j+1 < W:
                if glid[i-1][j] == glid[i][j-1] == glid[i][j+1] == glid[i+1][j] == '.':
                    print('No')
                    exit()
                else:
                    print('Yes')
                    exit()

Submission status: Wrong Answer

Solution code:
H, W = map(int,input().split())
matrix1 =[list(input()) for i in range(H)]
for i in range(H):
    for j in range(W):
        if matrix1[i][j] == '#':
            if i - 1 >= 0 and matrix1[i-1][j] == '#':
                break
            if j - 1 >= 0 and matrix1[i][j-1] == '#':
                break
            if j + 1 <= W-1 and matrix1[i][j+1] == '#':
                break
            if i + 1 <= H-1 and matrix1[i+1][j] == '#':
                break
            else:
                print('No')
                exit()
print('Yes')

Submission status: Wrong Answer

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


s=[['.']*(w+2)]
for i in range(h):
    s+=[['.']+list(input())+['.']]
s+=[['.']*(w+2)]

for i in s:
    print(*i)

dset=((-1,0),(0,1),(1,0),(0,-1))

for i in range(1,h+1):
    for j in range(1,w+2):
        if s[i][j]=='.':continue
        flag=False
        for y,x in dset:
            if s[i+y][j+x]=='#':
                flag=True
                break
        if not flag:
            print('No')
            exit()
print('Yes')

Submission status: Wrong Answer

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

    dl = [(-1, 0), (0, 1), (1, 0), (0, -1)]
    for i, row in enumerate(S):
        for j, val in enumerate(row):
            if val == '.':
                continue

            can_paint = False
            for dx, dy in dl:
                di, dj = i + dx, j + dy
                if di < 0 or H <= di or dj < 0 or W <= dj:
                    continue
                if S[di][dj] == '#':
                    can_paint = True
                    break
            if not can_paint:
                print('No')
                return
    print('Yes')

def main():
    resolve()

Submission status: Wrong Answer

Solution code:
H,W=map(int,input().split())
S=[input()+'.'for _ in range(H)]+['.'*(W+2)]
print(('Yes','No')[all(S[y-1][x]==S[y+1][x]==S[y][x-1]==S[y][x+1]=='.'for y in range(H)for x in range(W)if S[y][x]=='#')])

Submission status: Wrong Answer

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

for i in range(H):
  for j in range(W):
    if S[i][j] == "#":
      bk = sum([t[j].count("#") for t in S[max(0,i-1):min(H,i+1)]])
      bk += S[i][max(0,j-1):min(W,j+1)].count("#")-1
      if bk == 1:
        print("No")
        exit()

print("Yes")

Submission status: Wrong Answer

Solution code:
hw = input().split(" ");
h = int(hw[0]);
w = int(hw[1]);
pic = [0]*h;
can = 1;
for i in range(h) :
	pic[i] = list(input().rstrip('\n'));
for i in range(h) :
	for j in range(w) :
		if h == 1 and w == 1 :
			if pic[i][j] == '#' :
				can = 0;
				break;
		elif h == 1 and j == 0 :
			if pic[i][j] == '#' :
				if pic[i][j+1] == '#' :
					can = 1;
				else :
					can = 0;
					break;
		elif h == 1 and j == w-1 :
			if pic[i][j] == '#' :
				if pic[i][j-1] == '#' :
					can = 1;
				else :
					can = 0;
					break;
		elif w == 1 and i == 0 :
			if pic[i][j] == '#' :
				if pic[i+1][j] == '#' :
					can = 1;
				else :
					can = 0;
					break;
		elif w == 1 and i == h-1 :
			if pic[i][j] == '#' :
				if pic[i-1][j] == '#' :
					can = 1;
				else :
					can = 0;
					break;
		elif h == 1 :
			if pic[i][j] == '#' :
				if pic[i][j+1] == '#' or pic[i][j-1] == '#' :
					can = 1;
				else :
					can = 0;
					break;
		elif w == 1 :
			if pic[i][j] == '#' :
				if pic[i+1][j] == '#' or pic[i-1][j] == '#' :
					can = 1;
				else :
					can = 0;
					break;
		elif pic[i][j] == '#' :
			if i == 0 and j == 0 :
				if pic[i][j+1] == '#' or pic[i+1][j] == '#' :
					can = 1;
				else :
					can = 0;
					break;
			elif i == 0 and j == w-1 :
				if pic[i][j-1] == '#' or pic[i+1][j] == '#' :
					can = 1;
				else :
					can = 0;
					break;
			elif i == h-1 and j == 0 :
				if pic[i-1][j] == '#' or pic[i][j+1] == '#' :
					can = 1;
				else :
					can = 0;
					break;
			elif i == h-1 and j == w-1 :
				if pic[i][j-1] == '#' or pic[i-1][j] == '#' :
					can = 1;
				else :
					can = 0;
					break;
			elif i == 0 :
				if pic[i][j-1] == '#' or pic[i][j+1] == '#' or pic[i+1][j] == '#' :
					can = 1;
				else :
					can = 0;
					break;
			elif i == h-1 :
				if pic[i][j-1] == '#' or pic[i-1][j] == '#' or pic[i][j+1] == '#' :
					can = 1;
				else :
					can = 0;
					break;
			elif j == 0 :
				if pic[i-1][j] == '#' or pic[i][j+1] == '#' or pic[i+1][j] == '#' :
					can = 1;
				else :
					can = 0;
					break;
			elif j == w-1 :
				if pic[i][j-1] == '#' or pic[i-1][j] == '#' or pic[i+1][j] == '#' :
					can = 1;
				else :
					can = 0;
					break;
			else :
				if pic[i][j-1] == '#' or pic[i-1][j] == '#' or pic[i][j+1] == '#' or pic[i+1][j] == '#' :
					can = 1;
				else :
					can = 0;
					break;
if bool(can) :
	print('Yes');
else :
	print('No');

Submission status: Wrong Answer

Solution code:
hw = input().split(" ");
h = int(hw[0]);
w = int(hw[1]);
pic = [0]*h;
can = 0;
for i in range(h) :
	pic[i] = list(input().rstrip('\n'));
for i in range(h) :
	for j in range(w) :
		if h == 1 and w == 1 :
			if pic[i][j] == '#' :
				can = 0;
				break;
		elif h == 1 and j == 0 :
			if pic[i][j] == '#' :
				if pic[i][j+1] == '#' :
					can = 1;
				else :
					can = 0;
					break;
		elif h == 1 and j == w-1 :
			if pic[i][j] == '#' :
				if pic[i][j-1] == '#' :
					can = 1;
				else :
					can = 0;
					break;
		elif w == 1 and i == 0 :
			if pic[i][j] == '#' :
				if pic[i+1][j] == '#' :
					can = 1;
				else :
					can = 0;
					break;
		elif w == 1 and i == h-1 :
			if pic[i][j] == '#' :
				if pic[i-1][j] == '#' :
					can = 1;
				else :
					can = 0;
					break;
		elif h == 1 :
			if pic[i][j] == '#' :
				if pic[i][j+1] == '#' or pic[i][j-1] == '#' :
					can = 1;
				else :
					can = 0;
					break;
		elif w == 1 :
			if pic[i][j] == '#' :
				if pic[i+1][j] == '#' or pic[i-1][j] == '#' :
					can = 1;
				else :
					can = 0;
					break;
		elif pic[i][j] == '#' :
			if i == 0 and j == 0 :
				if pic[i][j+1] == '#' or pic[i+1][j] == '#' :
					can = 1;
				else :
					can = 0;
					break;
			elif i == 0 and j == w-1 :
				if pic[i][j-1] == '#' or pic[i+1][j] == '#' :
					can = 1;
				else :
					can = 0;
					break;
			elif i == h-1 and j == 0 :
				if pic[i-1][j] == '#' or pic[i][j+1] == '#' :
					can = 1;
				else :
					can = 0;
					break;
			elif i == h-1 and j == w-1 :
				if pic[i][j-1] == '#' or pic[i-1][j] == '#' :
					can = 1;
				else :
					can = 0;
					break;
			elif i == 0 :
				if pic[i][j-1] == '#' or pic[i][j+1] == '#' or pic[i+1][j] == '#' :
					can = 1;
				else :
					can = 0;
					break;
			elif i == h-1 :
				if pic[i][j-1] == '#' or pic[i-1][j] == '#' or pic[i][j+1] == '#' :
					can = 1;
				else :
					can = 0;
					break;
			elif j == 0 :
				if pic[i-1][j] == '#' or pic[i][j+1] == '#' or pic[i+1][j] == '#' :
					can = 1;
				else :
					can = 0;
					break;
			elif j == w-1 :
				if pic[i][j-1] == '#' or pic[i-1][j] == '#' or pic[i+1][j] == '#' :
					can = 1;
				else :
					can = 0;
					break;
			else :
				if pic[i][j-1] == '#' or pic[i-1][j] == '#' or pic[i][j+1] == '#' or pic[i+1][j] == '#' :
					can = 1;
				else :
					can = 0;
					break;
if bool(can) :
	print('Yes');
else :
	print('No');

Submission status: Wrong Answer

Solution code:
hw = input().split(" ");
h = int(hw[0]);
w = int(hw[1]);
pic = [0]*h;
can = 0;
for i in range(h) :
	pic[i] = list(input().rstrip('\n'));
for i in range(h) :
	for j in range(w) :
		if pic[i][j] == '#' :
			if i == 0 and j == 0 :
				if pic[i][j+1] == '#' or pic[i+1][j] == '#' :
					can = 1;
				else :
					can = 0;
					break;
			elif i == 0 and j == w-1 :
				if pic[i][j-1] == '#' or pic[i+1][j] == '#' :
					can = 1;
				else :
					can = 0;
					break;
			elif i == h-1 and j == 0 :
				if pic[i-1][j] == '#' or pic[i][j+1] == '#' :
					can = 1;
				else :
					can = 0;
					break;
			elif i == h-1 and j == w-1 :
				if pic[i][j-1] == '#' or pic[i-1][j] == '#' :
					can = 1;
				else :
					can = 0;
					break;
			elif i == 0 :
				if pic[i][j-1] == '#' or pic[i][j+1] == '#' or pic[i+1][j] == '#' :
					can = 1;
				else :
					can = 0;
					break;
			elif i == h-1 :
				if pic[i][j-1] == '#' or pic[i-1][j] == '#' or pic[i][j+1] == '#' :
					can = 1;
				else :
					can = 0;
					break;
			elif j == 0 :
				if pic[i-1][j] == '#' or pic[i][j+1] == '#' or pic[i+1][j] == '#' :
					can = 1;
				else :
					can = 0;
					break;
			elif j == w-1 :
				if pic[i][j-1] == '#' or pic[i-1][j] == '#' or pic[i+1][j] == '#' :
					can = 1;
				else :
					can = 0;
					break;
			else :
				if pic[i][j-1] == '#' or pic[i-1][j] == '#' or pic[i][j+1] == '#' or pic[i+1][j] == '#' :
					can = 1;
				else :
					can = 0;
					break;
if bool(can) :
	print('Yes');
else :
	print('No');

Submission status: Wrong Answer

Solution code:
hw = input().split(" ");
h = int(hw[0]);
w = int(hw[1]);
pic = [0]*h;
can = 0;
for i in range(h) :
	pic[i] = list(input().rstrip('\n'));
for i in range(h) :
	for j in range(w) :
		if i == 0 and j == 0 :
			if pic[i][j+1] == '#' or pic[i+1][j] == '#' :
				can = 1;
			else :
				can = 0;
				break;
		elif i == 0 and j == w-1 :
			if pic[i][j-1] == '#' or pic[i+1][j] == '#' :
				can = 1;
			else :
				can = 0;
				break;
		elif i == h-1 and j == 0 :
			if pic[i-1][j] == '#' or pic[i][j+1] == '#' :
				can = 1;
			else :
				can = 0;
				break;
		elif i == h-1 and j == w-1 :
			if pic[i][j-1] == '#' or pic[i-1][j] == '#' :
				can = 1;
			else :
				can = 0;
				break;
		elif i == 0 :
			if pic[i][j-1] == '#' or pic[i][j+1] == '#' or pic[i+1][j] == '#' :
				can = 1;
			else :
				can = 0;
				break;
		elif i == h-1 :
			if pic[i][j-1] == '#' or pic[i-1][j] == '#' or pic[i][j+1] == '#' :
				can = 1;
			else :
				can = 0;
				break;
		elif j == 0 :
			if pic[i-1][j] == '#' or pic[i][j+1] == '#' or pic[i+1][j] == '#' :
				can = 1;
			else :
				can = 0;
				break;
		elif j == w-1 :
			if pic[i][j-1] == '#' or pic[i-1][j] == '#' or pic[i+1][j] == '#' :
				can = 1;
			else :
				can = 0;
				break;
		else :
			if pic[i][j-1] == '#' or pic[i-1][j] == '#' or pic[i][j+1] == '#' or pic[i+1][j] == '#' :
				can = 1;
			else :
				can = 0;
				break;
if bool(can) :
	print('Yes');
else :
	print('No');

Submission status: Wrong Answer

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

for i in range(H):
    for j in range(W):
        if s[i][j] == "#":
            flag = 0
            if i > 0:
                if s[i-1][j] == "#":
                    flag = 1
                    break
            if j < W-1:
                if s[i][j + 1] == "#":
                    flag = 1
                    break
            if i < H-1:
                if s[i + 1][j] == "#":
                    flag = 1
                    break
            if j > 0:
                if s[i][j - 1] == "#":
                    flag = 1
                    break

            if flag == 0:
                print("No")
                sys.exit(0)
print("Yes")

Submission status: Wrong Answer

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


for i in range(H):
    for j in range(W):
        if s[i][j] == "#":
            flag = 0b0000
            if i > 0:
                if s[i-1][j] == "#":
                    flag |= 0b1000
                    break
            if j < W-1:
                if s[i][j + 1] == "#":
                    flag |= 0b0100
                    break
            if i < H-1:
                if s[i + 1][j] == "#":
                    flag |= 0b0010
                    break
            if j > 0:
                if s[i][j - 1] == "#":
                    flag |= 0b0001
                    break

            if flag & 0x0000 == 0:
                print("No")
                sys.exit(0)

print("Yes")

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())
s = [list(input()) for _ in range(H)]
flag = 0b0000
flagggg = True
for i in range(H):
    for j in range(W):
        if s[i][j] == "#":

            if i > 0:
                if s[i-1][j] == "#":
                    flag |= 0b1000
                    break
            if j < W-1:
                if s[i][j + 1] == "#":
                    flag |= 0b0100
                    break
            if i < H-1:
                if s[i + 1][j] == "#":
                    flag |= 0b0010
                    break
            if j > 0:
                if s[i][j - 1] == "#":
                    flag |= 0b0001
                    break

            if flag & 0x0000 == 0:
                flagggg = False
                break
    else:
        continue
    break
if flagggg:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())
s = [list(input()) for _ in range(H)]
flag = 1
flagggg = True
for i in range(H):
    for j in range(W):
        if s[i][j] == "#":
            if i > 0:
                if s[i-1][j] == "#":
                    flag &= 1000
                    break
            if j < W-1:
                if s[i][j + 1] == "#":
                    flag &= 100
                    break
            if i < H-1:
                if s[i + 1][j] == "#":
                    flag &= 10
                    break
            if j > 0:
                if s[i][j - 1] == "#":
                    flag &= 1
                    break
            if flag & 1111 != 1111:
                flagggg = False
                break
    else:
        continue
    break
if flagggg:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())
s = [list(input()) for _ in range(H)]
flag = 0000
flagggg = True
for i in range(H):
    for j in range(W):
        if s[i][j] == "#":
            if i > 0:
                if s[i-1][j] == "#":
                    flag &= 1000
                    break
            if j < W-1:
                if s[i][j + 1] == "#":
                    flag &= 100
                    break
            if i < H-1:
                if s[i + 1][j] == "#":
                    flag &= 10
                    break
            if j > 0:
                if s[i][j - 1] == "#":
                    flag &= 1
                    break
            if flag & 1111 != 1111:
                flagggg = False
                break
    else:
        continue
    break
if flagggg:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

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

dxy = [(1,0),(0,1),(0,-1),(-1,0)]
flag = False

for y in range(h):
    for x in range(w):
        if lst[y][x] == ".":
            continue
        sum_count = 8
        dot_count = 0
        for dx,dy in dxy:
            if x+dx < 0 or x+dx > w-1 or y+dy < 0 or y+dy > h-1:
                sum_count -= 1
                continue
            if lst[y+dy][x+dx] == ".":
                dot_count += 1
        if sum_count == dot_count:
            flag = True
            break
    if flag:
        break

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

Submission status: Wrong Answer

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

dxy = [(1,1),(1,0),(1,-1),(0,1),(0,-1),(-1,1),(-1,0),(-1,-1)]
flag = False

for y in range(h):
    for x in range(w):
        if lst[y][x] == ".":
            continue
        sum_count = 8
        dot_count = 0
        for dx,dy in dxy:
            if x+dx < 0 or x+dx > w-1 or y+dy < 0 or y+dy > h-1:
                sum_count -= 1
                continue
            if lst[y+dy][x+dx] == ".":
                dot_count += 1
        if sum_count == dot_count:
            flag = True
            break
    if flag:
        break

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

Submission status: Wrong Answer

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

dxy = [(1,1),(1,0),(1,-1),(0,1),(0,-1),(-1,1),(-1,0),(-1,-1)]
flag = False

for y in range(h):
    for x in range(w):
        if lst[y][x] == ".":
            continue
        for dx,dy in dxy:
            sum_count = 8
            dot_count = 0
            if x+dx < 0 or x+dx > w-1 or y+dy < 0 or y+dy > h-1:
                sum_count -= 1
                continue
            if lst[y+dy][x+dx] == ".":
                dot_count += 1
        if sum_count == dot_count:
            flag = True
            break
    if flag:
        break

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

Submission status: Wrong Answer

Solution code:
import numpy as np
H,W=map(int,input().split())
M=[list(input()) for i in range(H)]
M=[[1 if s=='#' else 0 for s in M[h]] for h in range(H)]
M=np.array(M)
U=np.zeros((H,W))
D=np.zeros((H,W))
R=np.zeros((H,W))
L=np.zeros((H,W))
for h in range(H):
  for w in range(W):
    if M[h][w]==0:
      continue
    else:
      if h-1>=0 and M[h-1][w]>0:
        U[h][w]=U[h][w]+1
      if h+1<H and M[h+1][w]>0:
        D[h][w]=D[h][w]+1
      if w+1<W and M[h][w+1]>0:
        R[h][w]=R[h][w]+1
      if w-1>0 and M[h][w-1]>0:
        L[h][w]=L[h][w]+1
T=U+D+R+L+M
if np.any(T==1):
  print("No")
else:
  print("Yes")

Submission status: Wrong Answer

Solution code:
import numpy as np
H,W=map(int,input().split())
M=[list(input()) for i in range(H)]
M=[[1 if s=='#' else 0 for s in M[h]] for h in range(H)]
M=np.array(M)
U=np.zeros((H,W))
D=np.zeros((H,W))
R=np.zeros((H,W))
L=np.zeros((H,W))
for h in range(H):
  for w in range(W):
    if M[h][w]==0:
      continue
    else:
      #上方向
      if h-1>=0 and M[h-1][w]>0:
        U[h][w]=U[h][w]+1
      #下方向
      if h+1<H and M[h+1][w]>0:
        D[h][w]=D[h][w]+1
      #右方向
      if w+1<W and M[h][w+1]>0:
        R[h][w]=R[h][w]+1
      #左方向
      if w-1>0 and M[h][w-1]>0:
        L[h][w]=L[h][w]+1
T=U+D+R+L+M
if np.any(T==1):
  print("No")
else:
  print("Yes")

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
l=[]
f=0
nf=0
for i in range(n):
    l.append(list(input()))
    
for i in range(n):
    for j in range(m):
        if l[i][j]=='#':
            if (i>0 and l[i-1][j]=='#') or (j>0 and l[i][j-1]=='#') or (i<n-1 and l[i+1][j]) or (j<m-1 and l[i][j+1]):
                f=0
            else:
                nf=1
if nf==1:
    print('No')
else:
    print('Yes')

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
l=[]
f=0
nf=0
for i in range(n):
    l.append(list(input()))
    
for i in range(n):
    for j in range(m):
        if l[i][j]=='#':
            if (i>0 and l[i-1][j]=='#') or (j>0 and l[i][j-1]=='#') or (i<n-1 and l[i+1][j]) or (j<n-1 and l[i][j+1]):
                f=0
            else:
                nf=1
if nf==1:
    print('No')
else:
    print('Yes')

Submission status: Wrong Answer

Solution code:
h,w=map(int,input().split())
p = [input() for i in range(h)]
j=0
for y in range(h):
    for x in range(w):
        if p[y][x]=="#":
            if x>0 and p[y][x-1]=="#":j=1
            elif j==0 and y>0 and p[y-1][x]=="#":j=1
            elif j==0 and x!=w-1 and p[y][x+1]=="#":j=1
            elif j==0 and y!=h-1 and p[y+1][x]=="#":j=1
            if j==0:
                print("No")
                exit()
print("Yes")