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 = [list(input()) for i in range(H)]

flag=True
if H==W==1:
    if s[0][0]=='#':
        flag=False
elif H>=2 and W==1:
    for i in range(H):
        if s[i][0] == '#':
            if i==0:
                if s[i+1][0]=='.':
                    flag=False
                    break
                else:
                    continue
            elif i==H-1:
                if s[i-1][0]=='.':
                    flag=False
                    break
                else:
                    continue
            else:
                if s[i+1][0]==s[i-1][0]=='.':
                    flag=False
                    break
                else:
                    continue
        else:
            continue
elif H==1 and W>=2:
    for i in range(W):
        if s[0][i]=='#':
            if i==0:
                if s[0][i+1]=='.':
                    flag=False
                    break
                else:
                    continue
            elif i==W-1:
                if s[0][i-1]=='.':
                    flag=False
                    break
                else:
                    continue
            else:
                if s[0][i+1]==s[0][i-1]=='.':
                    flag=False
                    break
                else:
                    continue
        else:
            continue
else:
    for i in range(H):
        if i==0:
            for j in range(W):
                if s[i][j]=='#':
                    if j==0:
                        if s[i][j+1]==s[i+1][j]=='.':
                            flag=False
                            break
                        else:
                            continue
                    elif j==W-1:
                        if s[i][j-1]==s[i+1][j]=='.':
                            flag=False
                            break
                        else:
                            continue
                    else:
                        if s[i][j+1]==s[i][j-1]==s[i+1][j]=='.':
                            flag=False
                            break
                        else:
                            continue
                else:
                    continue
        elif i==H-1:
            for j in range(W):
                if s[i][j]=='#':
                    if j==0:
                        if s[i][j+1]==s[i-1][j]=='.':
                            flag=False
                            break
                        else:
                            continue
                    elif j==W-1:
                        if s[i][j-1]==s[i-1][j]=='.':
                            flag=False
                            break
                        else:
                            continue
                    else:
                        if s[i][j+1]==s[i][j-1]==s[i-1][j]=='.':
                            flag=False
                            break
                        else:
                            continue
                else:
                    continue
        else:
            for j in range(W):
                if s[i][j]=='#':
                    if j==0:
                        if s[i-1][j]==s[i+1][j]==s[i][j+1]=='.':
                            flag=False
                            break
                        else:
                            continue
                    elif j==W-1:
                        if s[i-1][j]==s[i+1][j]==s[i][j-1]=='.':
                            flag=False
                            break
                        else:
                            continue
                    else:
                        if s[i-1][j]==s[i+1][j]==s[i][j-1]==s[i][j+1]=='.':
                            flag=False
                            break
                        else:
                            continue
                else:
                    continue
        if flag:
            break

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

Submission status: Wrong Answer

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

A = [['.']*(W+2) for i in range(H+2)]
for i in range(1,H+1):
    for j in range(1,W+1):
        A[i][j] = S[i-1][j-1]
        
ans = 'Yes'
for i in range(W+2):
    if(ans == 'No'):
        break
    for j in range(H+2):
         if(A[H][W] == '#'):
            if (A[H-1][W] != '#' and A[H+1][W] != '#' and A[H][W-1] != '#' and A[H][W+1] != '#'):
                ans = 'No'
                break

if(H == 1 and W ==1 and S[0][0] == '#'):
    ans = 'Yes'

print(ans)

Submission status: Wrong Answer

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

A = [['.']*(W+2) for i in range(H+2)]
for i in range(1,H+1):
    for j in range(1,W+1):
        A[i][j] = S[i-1][j-1]
        
ans = 'Yes'
for i in range(W+2):
    if(ans == 'No'):
        break
    for j in range(H+2):
         if(A[H][W] == '#'):
            if (A[H-1][W] != '#' and A[H+1][W] != '#' and A[H][W-1] != '#' and A[H][W+1] != '#'):
                ans = 'No'
                break

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
h, w = map(int,input().split())
s = [["."]*(w+2)] + \
    [list("." + input() + ".") for _ in range(h)] + \
    [["."]*(w+2)]
flg = 0
for i in range(1,h+1):
    for j in range(1,w+1):
        if s[i][j] == "#":
            if s[i-1][j] == "." and s[i+1][j] == "." and s[i][j-1] == "." and s[i][j+1] == "." :
                flg = 1
                break
if flg == 0 : print("Yse")
else : print("No")

Submission status: Wrong Answer

Solution code:
h, w = map(int,input().split())
s = [["."]*(w+2)] + \
    [list("." + input() + ".") for _ in range(h)] + \
    [["."]*(w+2)]
flg = 0
for i in range(1,h+1):
    for j in range(1,w+1):
        if s[i][j] == "#":
            if s[i-1][j] == "." and s[i+1][j] == "." and s[i][-1] == "." and s[i][j+1] == "." :
                flg = 1
                break
if flg == 0 : print("Yse")
else : print("No")

Submission status: Wrong Answer

Solution code:
h, w = map(int,input().split())
s = [["."]*(w+2)] + \
    [list("." + input() + ".") for _ in range(h)] + \
    [["."]*(w+2)]
flg = 0
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][-1] == "." or s[i][j+1] == "." :
                flg = 1
                break
if flg == 0 : print("Yse")
else : print("No")

Submission status: Wrong Answer

Solution code:
h, w = map(int,input().split())
s = [["."]*(w+2)] + \
    [list("." + input() + ".") for _ in range(h)] + \
    [["."]*(w+2)]
flg = 0
for i in range(1,h+1):
    for j in range(1,w+1):
        if s[i][j] == "#":
            if not (s[i-1][j] == "#" or s[i+1][j] == "#" or s[i][-1] == "#" or s[i][j+1] == "#") :
                flg = 1
if flg == 0 : print("Yse")
else : print("No")

Submission status: Wrong Answer

Solution code:
h, w = map(int,input().split())
s = [["."]*(w+2)] + \
    [list("." + input() + ".") for _ in range(h)] + \
    [["."]*(w+2)]
flg = 0
for i in range(1,h+1):
    for j in range(1,w+1):
        if s[i][j] == "#":
            if not s[i-1][j] == "#" or s[i+1][j] == "#" or s[i][-1] == "#" or s[i][j+1] == "#" :
                flg = 1
if flg == 0 : print("Yse")
else : print("No")

Submission status: Wrong Answer

Solution code:
h, w = map(int,input().split())
s = [["."]*(w+2)] + \
    [list("." + input() + ".") for _ in range(h)] + \
    [["."]*(w+2)]
flg = 0
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][-1] == "#" or s[i][j+1] == "#" :
                flg = 1
if flg == 1 : print("Yse")
else : print("No")

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
H, W = [int(x) for x in input().split()]
s = []
if H == 1 and W == 1:
    print("Yes")
    sys.exit()
for _ in range(H):
    temp = list(input().rstrip())
    s.append(temp)
def A(i,j,s):
    next_point = [[i+1,j],[i-1,j],[i,j-1],[i,j+1]]
    for n in next_point:
        x, y = n[0], n[1]
        if 0 <= x <= W-1 and 0 <= y <= H-1:
            if s[x][y] == "#":
                return 0
    return 1
for k in range(H):
    for l in range(W):
        flag = 0
        if s[k][l] == "#":
            flag = A(k,l,s)
        if flag:
            print("No")
            sys.exit()
print("Yes")

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
H, W = [int(x) for x in input().split()]
s = []
for _ in range(H):
    temp = list(input().rstrip())
    s.append(temp)
def A(i,j,s):
    next_point = [[i+1,j],[i-1,j],[i,j-1],[i,j+1]]
    for n in next_point:
        x, y = n[0], n[1]
        if 0 <= x <= W-1 and 0 <= y <= H-1:
            if s[x][y] == "#":
                return 0
    return 1
for k in range(H):
    for l in range(W):
        flag = 0
        if s[k][l] == "#":
            flag = A(k,l,s)
        if flag:
            print("No")
            sys.exit()
print("Yes")

Submission status: Wrong Answer

Solution code:
h, w = map(int, input().split())
grid = [list(input()) for _ in range(h)]
for i in range(h):
    flag = True
    for j in range(w):
        if grid[i][j] == '#':
            if i - 1 >= 0 and grid[i - 1][j] == '#':
                flag = False
            if i + 1 <= h - 1 and grid[i + 1][j] == '#':
                flag = False
            if j - 1 >= 0 and grid[i][j - 1] == '#':
                flag = False
            if j + 1 <= w - 1 and grid[i][j + 1] == '#':
                flag = False
            if flag:
                print('No')
                exit()
print('Yes')

Submission status: Wrong Answer

Solution code:
H, W = map(int,input().split())
s = [list(input()) for i in range(H)]
ans = "Yes"
ushm = [[-1, 1, 0, 0],[0, 0, -1, 0]]
for i in range(H):
    for j in range(W):
        tmp = 0
        if s[i][j] == "#":
            if i > 0:
                if s[i-1][j] == "#":
                    tmp = 1
            if i < H - 1:
                if s[i+1][j] == "#":
                    tmp = 1
            if j > 0:
                if s[i][j-1] == "#":
                    tmp = 1
            if j < W - 1:
                if s[i][j+1] == "#":
                    tmp = 1
            if tmp == 0:
                ans ="No"
                break
    if tmp == 0:
        break
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
H, W = map(int, input().split())
grid = np.zeros((H, W), dtype="unicode")
for h in range(H):
    input_ = input()
    for w in range(W):
        grid[h, w] = input_[w]
    
h_candi = [-1, -1, -1, 0, 0, 1, 1, 1]
w_candi = [-1, 0, 1, -1, 1, -1, 0, 1]

cannot_flag = 0
for h in range(H):
    if cannot_flag:
        break
    for w in range(W):
        if grid[h, w] == ".":
            continue
        count = 0
        for h_, w_ in zip(h_candi, w_candi):
            h_idx = h + h_
            w_idx = w + w_
            if (h_idx < 0) or (h_idx >= H):
                continue
            if (w_idx < 0) or (w_idx >= W):
                continue
            if grid[h_idx, w_idx] == "#":
                count += 1
        if count == 0:
            cannot_flag = 1
            break

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

Submission status: Wrong Answer

Solution code:
H,W=map(int,input().split())
S = [list(str(input())) for i in range(H)]
judge=True
for i in range(H):
    for j in range(W):
        if S[i][j]=='#':
            judge1=True
            judge2=True
            judge3=True
            judge4=True
            
            try:S[i][j-1]
            except IndexError:judge1=False
            else:
                if S[i][j-1]=='.':
                    judge1=False
                    
            try:S[i][j+1]
            except IndexError:judge2=False
            else:
                if S[i][j+1]=='.':
                    judge2=False
                    
            try:S[i+1][j]
            except IndexError:judge3=False
            else:
                if S[i+1][j]=='.':
                    judge3=False
                    
            try:S[i-1][j]
            except IndexError:judge4=False
            else:
                if S[i-1][j]=='.':
                    judge4=False

            if judge1==False and judge2==False and judge3==False and judge4==False:
                judge=False
                break

    if judge==False:break


print(judge)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
h,w=map(int,input().split())
lst=[[0 for i in range(w)]for j in range(h)]
for i in range(h):
  s=input().split()
  for j in range(len(s)):
    if s[j]=='#':
      lst[i][j]=1
if [h,w]==[1,1]:
  print('Yes')
  sys.exit()
if [h,w]==[1,2]:
  if lst[0][1]+lst[0][0]==1:
    print('No')
    sys.exit()
if [h,w]==[2,1]:
  if lst[1][0]+lst[0][0]==1:
    print('No')
    sys.exit()
for j in range(1,h-1):
  for k in range(1,w-1):
    if lst[j][k]==1:
      if lst[j-1][k]!=1 and lst[j+1][k]!=1 and lst[j][k-1]!=1 and lst[j][k+1]!=1:
        print('No')
        sys.exit()
if lst[0][0]==1:
  if lst[0][1]!=1 and lst[1][0]!=1:
    print('No')
    sys.exit()
if lst[h-1][0]==1:
  if lst[h-2][0]!=1 and lst[h-1][1]!=1:
    print('No')
    sys.exit()
if lst[0][k-1]==1:
  if lst[0][k-2]!=1 and lst[1][k-1]!=1:
    print('No')
    sys.exit()
if lst[h-1][k-1]==1:
  if lst[h-1][k-2]!=1 and lst[h-2][k-1]!=1:
    print('No')
    sys.exit()

print('Yes')

Submission status: Wrong Answer

Solution code:
import sys
h,w=map(int,input().split())
lst=[[0 for i in range(w)]for j in range(h)]
for i in range(h):
  s=input().split()
  for j in range(len(s)):
    if s[j]=='#':
      lst[i][j]=1

for j in range(1,h-1):
  for k in range(1,w-1):
    if lst[j][k]==1:
      if lst[j-1][k]==1 or lst[j+1][k]==1 or lst[j][k-1]==1 or lst[j][k+1]==1:
        pass
      else:
        print('No')
        sys.exit()

print('Yes')

Submission status: Wrong Answer

Solution code:
import sys
h,w=map(int,input().split())
lst=[[0 for i in range(w)]for j in range(h)]
for i in range(h):
  s=input().split()
  for j in range(len(s)):
    if s[j]=='#':
      lst[i][j]=1

for j in range(h):
  for k in range(w):
    if lst[j][k]==1:
      if lst[max(j-1,0)][k]==1 or lst[min(j+1,h-1)][k]==1 or lst[j][max(0,k-1)]==1 or lst[j][min(k+1,w-1)]==1:
        if max(j-1,0)==0 or min(j+1,h-1)==0 or max(0,k-1)==0 or min(k+1,w-1)==0:
          continue
      else:
        print('No')
        sys.exit()

print('Yes')

Submission status: Wrong Answer

Solution code:
import sys
h,w=map(int,input().split())
lst=[[0 for i in range(w)]for j in range(h)]
for i in range(h):
  s=input().split()
  for j in range(len(s)):
    if s[j]=='#':
      lst[i][j]=1

for j in range(h):
  for k in range(w):
    if lst[j][k]==1:
      if lst[max(j-1,0)][k]==1 or lst[min(j+1,h-1)][k]==1 or lst[j][max(0,k-1)]==1 or lst[j][min(k+1,w-1)]==1:
        pass
      else:
        print('No')
        sys.exit()

print('Yes')

Submission status: Wrong Answer

Solution code:
import sys
h,w=map(int,input().split())
lst=[[0 for i in range(w)]for j in range(h)]
for i in range(h):
  s=input().split()
  for j in range(len(s)):
    if s[j]=='#':
      lst[i][j]=1

for j in range(h):
  for k in range(w-2):
    if lst[j][k]+lst[j][k+1]==1 and lst[j][k+1]+lst[j][k+2]==1:
      print('No')
      sys.exit()
    
for k in range(w):
  for j in range(h-2):
    if lst[j][k]+lst[j+1][k]==1 and lst[j+1][k]+lst[j+2][k]==1:
      print('No')
      sys.exit()
    
print('Yes')

Submission status: Wrong Answer

Solution code:
import sys
h,w=map(int,input().split())
lst=[[0 for i in range(w)]for j in range(h)]
for i in range(h):
  s=input().split()
  for j in range(len(s)):
    if s[j]=='#':
      lst[i][j]=1

for j in range(h):
  for k in range(w-2):
    if lst[j][k]*lst[j][k+1]==0 and lst[j][k+1]*lst[j][k+2]==0:
      print('No')
      sys.exit()
    
for k in range(w):
  for j in range(h-2):
    if lst[j][k]*lst[j+1][k]==0 and lst[j+1][k]*lst[j+2][k]==0:
      print('No')
      sys.exit()
    
print('Yes')

Submission status: Wrong Answer

Solution code:
import sys
h,w=map(int,input().split())
lst=[[0 for i in range(w)]for j in range(h)]
for i in range(h):
  s=input().split()
  for j in range(len(s)):
    if s[j]=='#':
      lst[i][j]=1

for j in range(h-2):
  for k in range(w-2):
    if lst[j][k]*lst[j][k+1]==0 and lst[j][k+1]*lst[j][k+2]==0:
      print('No')
      sys.exit()
    if lst[j][k]*lst[j+1][k]==0 and lst[j+1][k]*lst[j+2][k]==0:
      print('No')
      sys.exit()
    
print('Yes')

Submission status: Wrong Answer

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

s = [input() for _ in range(h)]

ans = 'No'

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

print(ans)

Submission status: Wrong Answer

Solution code:
H, W = list(map(lambda x: int(x), input().split(' ')))
table = [[c for c in input()] for _ in range(H)]

for i in range(H):
    for j in range(W):
        if table[i][j] == '#':
            if i > 1 and table[i-1][j] == '#':
                continue

            elif i < H-1 and table[i+1][j] == '#':
                continue

            elif j > 1 and table[i][j-1] == '#':
                continue

            elif j < W-1 and table[i][j+1] == '#':
                continue

            else:
                print('No')
                exit()

print('Yes')

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
mat=[]
dx=[0,0,-1,1]
dy=[1,-1,0,0]
for i in range(n):
    mat.append(list(input().strip()))
f=0 
for i in range(n):
    if f:
        break 
    for j in range(m):
        if mat[i][j]=='#':
            q=[[i,j]]
            f=1 
            vis=[[0 for x1 in range(m)]for y1 in range(n)]
            vis[i][j]=1 
            while q:
                t=q.pop(0)
                #print(t)
                x,y=t[0],t[1] 
                for k in range(4): 
                    if 0<=x+dx[k]<n and 0<=y+dy[k]<m and vis[x+dx[k]][y+dy[k]]==0 and mat[x+dx[k]][y+dy[k]]=='#': 
                        vis[x+dx[k]][y+dy[k]]=1 
                        q.append([x+dx[k],y+dy[k]])
            break 
if not f:
    print('Yes')
    exit()
for i in range(n):
    for j in range(m): 
        if vis[i][j]==0 and mat[i][j]=='#':
           # print(i,j)
            print('No')
            exit()
print('Yes')

Submission status: Wrong Answer

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

for i in range(1,H-1):
    for j in range(1,W-1):
        if s[i][j] == "#" and s[i-1][j] == "#" and s[i][j-1] == "#" and s[i+1][j] == "#" and s[i][j+1] == "#":
            A = "Yes"
print(A)

Submission status: Wrong Answer

Solution code:
from collections import deque
H,W = map(int, input().split())
m = [input() for _ in range(H)]
visited=[[0]*W for _ in range(H)]
dhw = [(1,0),(-1,0),(0,1),(0,-1)]
def main():
  global visited
  for h in range(H):
    for w in range(W):
      if m[h][w]==".":
        continue
      for dh, dw in dhw:
        nh, nw = h+dh, w+dw
        if 0<=nh<H and 0<=nw<W:
          if m[nh][nw]=="#":
            break
      else:
        print("NO")
        return
  print("YES")
  return

if __name__ == "__main__":
  main()

Submission status: Wrong Answer

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

for h in range(H):
    for w in range(W):
        try:
            if s[h][w] == '#':
                if s[h - 1][w] != '#' and s[h + 1][w] != '#' and s[h][w - 1] != '#' and s[h][w + 1] != '#':
                    print('No')
                    exit()
        except:
            continue
print('Yes')

Submission status: Wrong Answer

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

for i in range(h):
    for k in range(w):
        count =True
        if s[i][k] == ".":
            break

        d = [[0, 1], [1, 0], [0, -1], [-1, 0]]
        for l in d:
            if 0 <= i + l[0] < h and 0 <= k + l[1] < w:
                if s[i + l[0]][k + l[1]] == "#":
                    count = False

        if count:
            ans = False

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

Submission status: Wrong Answer

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

for i in range(h):
    for k in range(w):
        if s[i][k] == ".":
            break

        count = True
        d = [[0, 1], [1, 0], [0, -1], [-1, 0]]
        for l in d:
            if 0 <= i + l[0] < h and 0 <= k + l[1] < w:
                if s[i + l[0]][k + l[1]] == "#":
                    count = False

        if count:
            ans = False

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

Submission status: Wrong Answer

Solution code:
h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]
count = 0
ans = True

for i in range(h):
    for k in range(w):
        count = True
        d = [[0, 1], [1, 0], [0, -1], [-1, 0]]
        for l in d:
            if 0 <= i + l[0] <= h - 1 and 0 <= k + l[1] <= w - 1:
                if s[i + l[0]][k + l[1]] == "#":
                    count = False

        if count:
            ans = False

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

Submission status: Wrong Answer

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

for i in range(h):
    for j in range(w):
        if m[i][j] == '#':
            if 0 < i <= h and 0 < j <= w:
                cnt = 4
            else:
                cnt = 3
            # up
            if 0 <= i-1:
                if m[i-1][j] != '#':
                    cnt -= 1

            # down
            if i+1 < h:
                if m[i+1][j] != '#':
                    cnt -= 1
            # left
            if 0 >= j-1:
                if m[i][j-1] != '#':
                    cnt -= 1

            # right
            if j+1 < w:
                if m[i][j+1] != '#':
                    cnt -= 1

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

Submission status: Wrong Answer

Solution code:
h,w = map(int,input().split())
li = [list(input()) for i in range(h)]
#print(li)
flag = False
for i in range(h):
    for j in range(w):
        
        if li[i][j] == ".":
            continue
        if li[i][j] == "#":
            if not i+1 < h or not 0<= i-1 or not j+1 < w or  not 0 <= j+1 :
                continue
        
            if li[i][j-1] == "#"  or li[i][j+1] == "#"  or li[i-1][j] == "#"  or li[i+1][j] == "#" :
                flag = True
               
if flag:                    
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

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

for i in range(h):
    for j in range(w):
        if m[i][j] == '#':
            cnt = 0
            # up
            if 0 <= i-1:
                if m[i-1][j] != '#':
                    cnt += 1
            # down
            if i+1 < h:
                if m[i+1][j] != '#':
                    cnt += 1
            # left
            if 0 >= j-1:
                if m[i][j-1] != '#':
                    cnt += 1
            # right
            if j+1 < w:
                if m[i][j+1] != '#':
                    cnt += 1
            if cnt == 4:
                print('No')
                exit(0)
            cnt = 0
else:
    print('Yes')

Submission status: Wrong Answer

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

f=True
for i in range(H):
	for j in range(W):
		if A[i][j]=='#':
			f=False
			for a,b in [(-1,0),(1,0),(0,1),(0,-1)]:
				if 0<=i+a<H and 0<=j+b<W:
					if A[i+a][j+b]=='#':f=True
			if not(f):break

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

Submission status: Wrong Answer

Solution code:
def checkA(x):
    i,j = x[0],x[1]
    if A[i][j]=="#":
        if A[i][j+1]=="." and A[i-1][j]=="." and A[i][j-1]=="." and A[i+1][j]==".":
            return 1
        else:
            return 0
    else:
        return 0      
H,W = map(int,input().split())
A = [["#" for _ in range(W+2)]]
for i in range(H):
    row = list(input())
    row.insert(0,"#")
    row.append("#")
    A.append(row)
A.append(["#" for _ in range(W+2)])

ind = 0
for i in range(1,H+1):
    for j in range(1,W+1):
        ind = checkA([i,j])
        if ind==1:
            break
if ind==1:
    print("No")
else:
    print("Yes")

Submission status: Wrong Answer

Solution code:
def checkA(x):
    i,j = x[0],x[1]
    if A[i][j]=="#":
        if A[i][j+1]=="." and A[i-1][j]=="." and A[i][j-1]=="." and A[i+1][j]==".":
            return 1
        else:
            return 0
    else:
        return 0      
H,W = map(int,input().split())
A = [["." for _ in range(W+2)]]
for i in range(H):
    row = list(input())
    row.insert(0,".")
    row.append(".")
    A.append(row)
A.append(["." for _ in range(W+2)])
if H==1 and W==1 and A[H][W]==".":
    ind = 0
else:
    ind = 0
    for i in range(1,H+1):
        for j in range(1,W+1):
            ind = checkA([i,j])
            if ind==1:
                break
if ind==1:
    print("No")
else:
    print("Yes")

Submission status: Wrong Answer

Solution code:
def checkA(x):
    i,j = x[0],x[1]
    if A[i][j]=="#":
        if A[i][j+1]=="." and A[i-1][j]=="." and A[i][j-1]=="." and A[i+1][j]==".":
            return 1
        else:
            return 0
    else:
        return 0      
H,W = map(int,input().split())
A = [["." for _ in range(W+2)]]
for i in range(H):
    row = list(input())
    row.insert(0,".")
    row.append(".")
    A.append(row)
A.append(["." for _ in range(W+2)])
ind = 0
for i in range(1,H+1):
    for j in range(1,W+1):
        if A[i][j]=="#":
            ind = 1
            break
    if ind==1:break
if ind==0:
    ind = 1
else:
    ind = 0
    for i in range(1,H+1):
        for j in range(1,W+1):
            ind = checkA([i,j])
            if ind==1:
                break
if ind==1:
    print("No")
else:
    print("Yes")

Submission status: Wrong Answer

Solution code:
def checkA(x):
    i,j = x[0],x[1]
    if A[i][j]=="#":
        if A[i][j+1]=="." and A[i-1][j]=="." and A[i][j-1]=="." and A[i+1][j]==".":
            return 1
        else:
            return 0
    else:
        return 0      
H,W = map(int,input().split())
A = [["." for _ in range(W+2)]]
for i in range(H):
    row = list(input())
    row.insert(0,".")
    row.append(".")
    A.append(row)
A.append(["." for _ in range(W+2)])
ind = 0
for i in range(1,H+1):
    for j in range(1,W+1):
        ind = checkA([i,j])
        if ind==1:
            break
if ind==1:
    print("No")
else:
    print("Yes")

Submission status: Wrong Answer

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

while (count != 0):
    count = 0
    for i in range(h):
        for j in range(w):
            count = s[i][j].count('#')
            if (s[i][j] == '#'):
                s[i][j].replace('#', '.')
            if (s[max(i-1,0)][j] == '#'):
                s[max(i-1,0)][j].replace('#', '.')
            elif (s[i][max(j-1,0)] == '#'):
                s[i][max(j-1,0)].replace('#', '.')
            elif (s[i][min(j+1,w-1)] == '#'):
                s[i][min(j+1,w-1)].replace('#', '.')
            elif (s[min(i+1,h-1)][j] == '#'):
                s[min(i+1,h-1)][j].replace('#', '.')
    case += 1
    if (case > 100):
        break

if (case>100):
    print('No')
else:
    print('Yes')

Submission status: Wrong Answer

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

while (count != 0):
    count = 0
    for i in range(h):
        for j in range(w):
            count = s[i][j].count('#')
            if (s[i][j] == '#'):
                s[i][j].replace('#', '.')
            if (s[max(i-1,0)][j] == '#'):
                s[max(i-1,0)][j].replace('#', '.')
            elif (s[i][max(j-1,0)] == '#'):
                s[i][max(j-1,0)].replace('#', '.')
            elif (s[i][min(j+1,w-1)] == '#'):
                s[i][min(j+1,w-1)].replace('#', '.')
            elif (s[min(i+1,h-1)][j] == '#'):
                s[min(i+1,h-1)][j].replace('#', '.')
    case += 1
    if (case > 1000):
        break

if (case>1000):
    print('No')
else:
    print('Yes')