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:
n,w=map(int,input().split())
st=[]
for i in range(n):
    st.append(list(input())) #0~n-1までの列ができる

for i in range(1,n-1):
    for j in range(1,w-1): #i,jに1足しても引いても範囲内だから安心！
        if st[i][j]=="#":
            if st[i+1][j]=="." and st[i][j-1]=="." and st[i][j+1]=="." and st[i+1][j]==".":
                print("No")
                exit()
        if st[0][j]=="#" and st[1][j]=="." and st[0][j+1]=="." and st[0][j-1]==".": #上辺
            print("No")
            exit()
        if st[i][0]=="#" and st[i][1]=="." and st[i-1][0]=="." and st[i+1][0]==".": #左辺
            print("No")
            exit()
        if st[i][w-1]=="#" and st[i][w-2]=="." and st[i-1][w-1]=="." and st[i+1][w-1]==".": #右辺
            print("No")
            exit()
        if st[n-1][j]=="#" and st[n-2][j]=="." and st[n-1][j+1]=="." and st[n-1][j-1]==".": #下辺
            print("No")
            exit()
if st[0][0]=="#" and st[0][1]=="." and st[1][0]==".": #左上
    print("No")
    exit()
if st[0][w-1]=="#" and st[0][w-2]=="." and st[1][w-1]==".": #右上
    print("No")
    exit()
if st[n-1][0]=="#" and st[n-1][1]=="." and st[n-2][0]==".": #左下
    print("No")
    exit()
if st[n-1][w-1]=="#" and st[n-1][w-2]=="." and st[n-2][w-2]==".": #右下
    print("No")
    exit()
print("Yes")

Submission status: Wrong Answer

Solution code:
S = input().split(" ")
N = int(S[0])
W = int(S[1])

ARR = []
for i in range(N):
    ar = list(input())
    ARR.append(ar)





def calculate(n,w,arr):
    result = True
    for i in range(n):
        for j in range(w):
            if arr[i][j] == "#":
                if i == n-1 and j == w - 1:
                    if arr[i-1][j] == "." and arr[i][j-1] == ".":
                        result = False
                        break
                    else:
                        continue

                if i == 0 and j == 0:
                    if arr[i+1][j] == "." and arr[i][j+1] == ".":
                        result = False
                        break
                    else:
                        continue

                if i == 0 and j < n - 1:
                    if arr[i-1][j] == "." and arr[i][j-1] == "." and arr[i][j+1] == ".":
                        result = False
                        break
                    else:
                        continue

                if j == 0 and i < w - 1:
                    if arr[i][j-1] == "." and arr[i-1][j] == "." and arr[i+1][j] == ".":
                        result = False
                        break
                    else:
                        continue

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

calculate(N,W,ARR)

Submission status: Wrong Answer

Solution code:
if __name__ == "__main__":
    h, w = map(int, input().split())
    s = list()
    s.append('.' * (w + 2))
    for i in range(h):
        s.append('.' + input() + '.')
    s.append('.' * (w + 2))

    for i in range(h):
        for j in range(w):
            tmp = s[i+1][j] + s[i][j+1] + s[i+1][j+2] + s[i+2][j+1]
            if tmp == '....':
                print('No')
                exit()

    print('Yes')

Submission status: Wrong Answer

Solution code:
H,W=map(int, input().split())
s = []
dx = [ -1, -1, 1, 1]
dy = [ -1, 1, -1, 1]
ans = "Yes"
for i in range(H):
  s.append( input())
for y in range(H):
  for x in range(W):
    if s[y][x] == '#':
      ng = 1
      for i in range(4):
        nx = x + dx[i]
        ny = y + dy[i]
        if (ny < 0) or (ny >= H) or (nx<0) or (nx>=W):
          continue
        if s[ny][nx] == '#':
          ng = 0
      if ng == 1:
        ans = "No"
print(ans)

Submission status: Wrong Answer

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

s=[]
t=[]
for hh in range(h):
    s.append(list(input()))
    t.append([1]*w)

for hh in range(h):
    for ww in range(w):
        if s[hh][ww]==".":
            t[hh][ww]=0
        else:
            if hh!=0:
                if s[hh-1][ww]=="#":
                    t[hh][ww]=0
            elif hh!=h-1:
                if s[hh+1][ww]=="#":
                    t[hh][ww]=0
            else:
                if s[hh-1][ww]=="#":
                    t[hh][ww]=0
                if s[hh+1][ww]=="#":
                    t[hh][ww]=0
            if ww!=0:
                if s[hh][ww-1]=="#":
                    t[hh][ww]=0
            elif ww!=w-1:
                if s[hh][ww+1]=="#":
                    t[hh][ww]=0
            else:
                if s[hh][ww-1]=="#":
                    t[hh][ww]=0
                if s[hh][ww+1]=="#":
                    t[hh][ww]=0

if max(max(t))==0:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())
m = [input() for _ in range(H)]
# print('m', m)
for i in range(H):
    for j in range(W):
        if m[i][j] == '#':
            # print('i j', i, j)
            for x, y in [(-1, 0), (1, 0), (0, -1), (0, 1)]:
                n_x = i + x
                n_y = j + y
                if n_x < 0 or W <= n_x:
                    continue
                if n_y < 0 or H <= n_y:
                    continue
                # print('pass')
                if m[n_x][n_y] == '#':
                    break
            else:
                print('No')
                exit()
print('Yes')

Submission status: Wrong Answer

Solution code:
# 下，右，上，左
dy = [1, 0, -1, 0]
dx = [0, 1, 0, -1]

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

field = []

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

for y in range(H):
    for x in range(W):
        
        if field[y][x] == ".":
            continue

        for k in range(4):

            cnt = 0

            ny = y + dy[k]
            nx = x + dx[k]

            if ny < 0 or H <= ny\
                or nx < 0 or W <= nx:
                continue

            elif field[ny][nx] == "#":
                cnt += 1

        if cnt == 0:
            print("No")
            exit()

print("Yes")

Submission status: Wrong Answer

Solution code:
# 下，右，上，左
dy = [1, 0, -1, 0]
dx = [0, 1, 0, -1]

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

field = []

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

for y in range(H):
    for x in range(W):
        
        if field[y][x] == ".":
            continue

        for k in range(4):

            cnt = 0

            ny = y + dy[k]
            nx = x + dx[k]

            if ny < 0 or H <= ny\
                or nx < 0 or W <= nx:
                continue

            elif field[ny][nx] == "#":
                continue

        if cnt == 0:
            print("No")
            exit()

print("Yes")

Submission status: Wrong Answer

Solution code:
#N,Wを入力
H,W = map(int, input().split())

trout = []

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

# 配列の比較用の変数
h = H-1
w = W-1

reslut = "Yes"
for i in range(H):
    for j in range(W):
        
        # "."だったらスルー
        if trout[i][j] == ".":
            pass
        
        else:
             # 真上
            if i>=1 and trout[i-1][j] == "#":
                pass
             # 左
            if j>=1 and trout[i][j-1] == "#":
                pass
            # 右
            if j<w and trout[i][j+1] == "#":
                pass
            # 真下
            if i<h and trout[i+1][j] == "#":
                pass
            
            else:
                reslut = "No"
                break
    else:
        continue
    break
    
print(reslut)

Submission status: Wrong Answer

Solution code:
#N,Wを入力
H,W = map(int, input().split())

trout = []

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

# 配列の比較用の変数
h = H-1
w = W-1

reslut = "Yes"
for i in range(H):
    for j in range(W):
        
        c = -1
        # "."だったらスルー
        if trout[i][j] == ".":
            pass
        
        else:
             # 真上
            if i>=1 and trout[i-1][j] == "#":
                c = 1
                break
             # 左
            if j>=1 and trout[i][j-1] == "#":
                c = 1
                break
            # 右
            if j<w and trout[i][j+1] == "#":
                c = 1
            # 真下
            if i<h and trout[i+1][j] == "#":
                c = 1
            
            if c == -1:
                reslut = "No"
                break
    else:
        continue
    break
    
print(reslut)

Submission status: Wrong Answer

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

for i in range(H):
  c = list(input())
  grid[i] = c
  
black = "#"
white = "."

ans = "Yes"

for i in range(H):
  for j in range(W):
    if grid[i][j] == black:
      around = ""
      for k in range(max(0, i - 1),min(W - 1,i + 2)):
        if k != j:
          around += grid[i][k]
      for t in range(max(0, j - 1),min(H - 1,j + 2)):
        if t != i:
          around += grid[t][j]
      
      if all([s == white for s in around]):
        ans = "No"
        break
  if ans == "No":
    break
      
print(ans)

Submission status: Wrong Answer

Solution code:
h,w=map(int,input().split())
g=[input() for _ in range(h)]
for x in range(h):
  for y in range(w):
    if g[x][y:]=='#':
      f=1
      for dx,dy in ((1,0),(0,1),(-1,0),(0,-1)):
        nx,ny=x+dx,y+dy
        if nx<0 or nx>=h or ny<0 or ny>=w:
          continue
        elif g[nx][ny]=='#':
          f=0
      if f:
        print('No')
        break
  else:
    continue
  break
else:
  print('Yes')

Submission status: Wrong Answer

Solution code:
h,w=map(int,input().split())
data=[[0 for i in range(w+2)] for j in range(h+2)]
for j in range(h):
    s=input()
    for i in range(w):
        if s[i]=="#":
            data[j+1][i+1]=1
flag=True
for i in range(1,h+1):
    for j in range(1,w+1):
        
        c=0
        for a in range(i-1,i+2):
            for b in range(j-1,j+2):
                c+=data[a][b]
        if c==1 and data[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())
mp = [list(input()) for i in range(H)]
for i in range(H):
    mp[i].insert(0,'.')
    mp[i].append('.')
lo = ['.' for i in range(W+2)]
mp.insert(0,lo)
mp.append(lo)

dir =[[-1,0], [0,-1], [0,1], [1,0]]
def check(x,y):
    if mp[x][y] =='#':
        bw =False
        for i in range(len(dir)):
            if mp[x + dir[i][0]][y + dir[i][1]] =='#':
                bw = True
        if bw == True:
            return True
        else:
            return False
    else:
        return True

ok =True
for i in range(1,H+1):
    for k in range(1,W+1):
        if check(i,k) == False:
            ok = False
            break

if ok == True:
    print('YES')
else:
    print('NO')

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
h,w = map(int,input().split())
grid = [["."]*(w+2) for _ in range(h+2)]
for i in range(h):
    s = input()
    for j in range(w):
        grid[i+1][j+1] = s[j]
for i in range(h):
    for j in range(w):
        if grid[i][j+1] == "."  and  grid[i+1][j] == "." and grid[i-1][j] == "#" and grid[i][j-1] == "#":
            print("No")
            exit()
print("Yes")

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())
list=["."+input()+"." for i in range(H)]
list=["."*(W+2)]+list+["."*(W+2)]
a=0
for h in range(H):
    for w in range(W):
        if list[h][w] == "#":
            if list[h+1][w] == "#" or list[h-1][w] == "#" or list[h][w-1] == "#" or list[h][w+1] == "#":
                a=0
            else:
                a=1
                break
print("Yes" if a==0 else "No")

Submission status: Wrong Answer

Solution code:
h, w = map(int, input().split())
list=["."+input()+"." for i in range(h)]
list=["."*(w+2)]+list+["."*(w+2)]
a=0
for h in range(h):
    for w in range(w):
        if list[h][w] == "#":
            if list[h+1][w] == "." and list[h-1][w] == "." and list[h][w-1] == "." and list[h][w+1] == ".":
                a=1
print("Yes" if a==0 else "No")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
h, w = map(int, input().split())
list=["."+input()+"." for i in range(h)]
list=["."*(w+2)]+list+["."*(w+2)]
a=0
for h in range(h):
    for w in range(w):
        if list[h][w] == "#":
            if list[h+1][w] == "#" or list[h-1][w] == "#" or list[h][w-1] == "#" or list[h][w+1] == "#":
                a=0
            else:
                a=1
print("Yes" if a==0 else "No")

Submission status: Wrong Answer

Solution code:
h, w = map(int, input().split())
list=["."+input()+"." for i in range(h)]
list=["."*(w+2)]+list+["."*(w+2)]
a=0
for h in range(h):
    for w in range(w):
        if list[h][w] == "#":
            if list[h+1][w] == "#" or list[h-1][w] == "#" or list[h][w-1] == "#" or list[h][w+1] == "#":
                a=0
            else:
                a=1
                break
print("Yes" if a==0 else "No")

Submission status: Wrong Answer

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

#%%

def get_field(i, j):
    try:
        ret = field[i][j]
    except:
        ret = '.'
    return ret

ans = False
for i in range(H):
    for j in range(W):
        if field[i][j] == '#':
            up = get_field(i-1, j)
            down = get_field(i+1, j)
            left = get_field(i, j-1)
            right = get_field(i, j+1)
            if up == '#' or down == '#' or left == '#' or right == '#':
                ans = True
            else:
                ans = False
                break

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

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10000000)

H, W = map(int, input().split())
field = [list(input()) for _ in range(H)]

def get_field(i, j):
    try:
        ret = field[i][j]
    except:
        ret = '.'
    return ret

ans = True
for i in range(H):
    for j in range(W):
        if field[i][j] == '#':
            up = get_field(i-1, j)
            down = get_field(i+1, j)
            left = get_field(i, j-1)
            right = get_field(i, j+1)
            if up == '#' or down == '#' or left == '#' or right == '#':
                ans = True
            else:
                ans = False
                break

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

Submission status: Wrong Answer

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

ok = True
def check(i,j,H,W,s):
    flag = False
    if (i+1) < (H-1):
        if s[i+1][j] == "#":
            flag = True
    if (i-1) >= 0:
        if s[i-1][j] == "#":
            flag = True
    if (j+1) < (W-1):
        if s[i][j+1] == "#":
            flag = True
    if (j-1) >= 0:
        if s[i][j-1] == "#":
            flag = True
    return flag

for i in range(H):
    for j in range(W):
        if s[i][j] == "#":
            ch = check(i,j,H,W,s)
            if not ch:
                ok = False
                break
    if not ok:
        break
    


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

Submission status: Wrong Answer

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

ok = True
def check(i,j,H,W,s):
    flag = False
    if (i+1) < (H-1):
        if s[i+1][j] == "#":
            flag = True
    if (i-1) >= 0:
        if s[i-1][j] == "#":
            flag = True
    if (j+1) < (W-1):
        if s[i][j+1] == "#":
            flag = True
    if (j-1) >= 0:
        if s[i][j-1] == "#":
            flag = True
    return flag

for i in range(H):
    for j in range(W):
        if s[i][j] == "#":
            ch = check(i,j,H,W,s)
            if not ch:
                ok = False

if H==1 and W==1:
    if s[0][0] == "#":
        print("Yes")
        exit()

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

Submission status: Wrong Answer

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

ok = True
def check(i,j,H,W,s):
    flag = False
    if (i+1) < (H-1):
        if s[i+1][j] == "#":
            flag = True
    if (i-1) >= 0:
        if s[i-1][j] == "#":
            flag = True
    if (j+1) < (W-1):
        if s[i][j+1] == "#":
            flag = True
    if (j-1) >= 0:
        if s[i][j-1] == "#":
            flag = True
    return flag

for i in range(H):
    for j in range(W):
        if s[i][j] == "#":
            ch = check(i,j,H,W,s)
            if not ch:
                ok = False

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

Submission status: Wrong Answer

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

dx = [-1, 0, 0, 1]
dy = [0, 1, -1, 0]
for i in range(H):
    for j in range(W):
        flag = False
        for k in range(4):
            if s[i][j] == '#':
                nx = j + dx[k]
                ny = i + dy[k]
                if nx < 0 or nx >= W or ny < 0 or ny >= H:
                    continue
                if s[ny][nx] == '#':
                    flag = True
        if flag == False:
            print('No')
            exit()        

print('Yes')

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def main():
    # 下、右、上、左
    dy = [1, 0, -1, 0]
    dx = [0, 1, 0, -1]
    H, W = map(int, input().split())
    s = ["." * (W + 2)]
    s += ["." + input() + "." for i in range(H)]
    s.append("." * (W + 2))
    print(s)
    for y in range(1, H + 1):
        for x in range(1, W + 1):
            if s[y][x] == "#" and s[y + dy[0]][x + dx[0]] == "."\
                    and s[y + dy[1]][x + dx[1]] == "."\
                    and s[y + dy[2]][x + dx[2]] == "."\
                    and s[y + dy[3]][x + dx[3]] == ".":
                print("No")
                return
    print("Yes")
    return


main()

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(H):
  for j in range(W):
    if S[i][j]==".":
      continue
    adj=[]
    if 0<i:
      adj.append(S[i-1][j])
    if i<H-1:
      adj.append(S[i+1][j])
    if 0<j:
      adj.append(S[i][j-1])
    if j<W-1:
      adj.append(S[i][j-1])
    # print(adj)
    if all('.'==m for m in adj):
      flag=False
print('Yes' if flag else 'No')

Submission status: Wrong Answer

Solution code:
print("Yes")

Submission status: Wrong Answer

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


a="YES"

for i in range(h):
    if a=="NO":
        break
    for j in range(w):
        a="NO"
        if s[i][j]==".":
            a="YES"
        else:
            if i-1>=0 and s[i-1][j]=="#":
                a="YES"
            elif j-1>=0 and s[i][j-1]=="#":
                a="YES"
            elif j+1<w and s[i][j+1]=="#":
                a="YES"
            elif i+1<h and s[i+1][j]=="#":
                a="YES"
        if a=="NO":
            break


print(a)

Submission status: Wrong Answer

Solution code:

def GridRepainting():
    H, W = map(int, input().split())
    strlist = []
    for _ in range(0, H):
        strlist.append(list(input()))
    for i in range(0, H):
        for j in range(0, W):
            if strlist[i][j] == '#':
                flag = False
                for x in range(-1, 2):
                    if i + x == -1 or i + x == H:continue
                    for y in range(-1, 2):
                        if j + y == -1 or j + y == W:continue
                        if x == 0 and y == 0:continue
                        if strlist[i + x][j + y] == '#':
                            flag = True
                if flag == False:
                    print('No')
                    return()
    print('Yes')
    return()

GridRepainting()

Submission status: Wrong Answer

Solution code:

def GridRepainting():
    H, W = map(int, input().split())
    strlist = []
    for _ in range(0, H):
        strlist.append(list(input()))
    for i in range(0, H):
        for j in range(0, W):
            if strlist[i][j] == '#':
                flag = False
                for x in range(-1, 2):
                    if i + x == -1 or i + x == H:continue
                    for y in range(-1, 2):
                        if j + y == -1 or j + y == W:continue
                        if i == 0 and j == 0:continue
                        if strlist[i + x][j + y] == '#':
                            flag = True
                if flag == False:
                    print('No')
                    return()
    print('Yes')
    return()

GridRepainting()

Submission status: Wrong Answer

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

bre = False
for h in range(H):
    for w in range(W):
        if s[h][w] == "#":
            if h>0 and s[h-1][w]=="#":
                continue
            elif h<H-1 and s[h+1][w]=="#":
                continue
            elif w>0 and s[h][w-1]=="#":
                continue
            elif w<W-1 and s[h][w+1]=="#":
                continue
            else:
                print(h,w)
                print("No")
                bre = True
                break
    if bre:
        break
else:
    print("Yes")

Submission status: Wrong Answer

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

bre = False
for h in range(H):
    for w in range(W):
        if s[h][w] == "#":
            if h>0 and s[h-1][w]=="#":
                continue
            elif h<H-1 and s[h+1][w]=="#":
                continue
            elif w>0 and s[h][w-1]=="#":
                continue
            elif h<W-1 and s[h][w+1]=="#":
                continue
            else:
                print("No")
                bre = True
                break
    if bre:
        break
else:
    print("Yes")

Submission status: Wrong Answer

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

for h in range(H):
    for w in range(W):
        if s[h][w] == "#":
            if h>0 and s[h-1][w]=="#":
                continue
            elif h<H-1 and s[h+1][w]=="#":
                continue
            elif w>0 and s[h][w-1]=="#":
                continue
            elif h<W-1 and s[h][w+1]=="#":
                continue
            else:
                print("No")
                break
else:
    print("Yes")

Submission status: Wrong Answer

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


for h in range(H):
    for w in range(W):
        lst=[]
        if h>1:
            lst.append([-1,0])
        if w>1:
            lst.append([0,-1])
        if h<H-1:
            lst.append([1,0])
        if w<W-1:
            lst.append([0,1])

        if S[h][w]=="#":
            flag=0
            for y,x in lst:
                if S[h+y][w+x]=="#":
                    flag=1
                    break
            if not flag:
                print("No")
                exit()
print("Yes")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
H,W=map(int,input().split())
s=[]
s0=""
for i in range(W+2):
    s0+="."
s.append(s0)
for i in range(H):
    ss="."
    ss+=input().strip()+"."
    s.append(ss)
s.append(s0)
#print(s)
flg=True
for h in range(H+1):
    for w in range(W+1):
        if s[h][w]=="#":
            flg=False
            for i in [1,-1]:
                if s[h+i][w]=="#":
                    flg=True
            for j in [1,-1]:
                if s[h][w+j]=="#":
                    flg=True
print("Yes" if flg else "No")

Submission status: Wrong Answer

Solution code:
import sys

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

rows = []
for i in range(H):
    chars = list(input())
    rows.append([1 if c == '#' else 0 for c in chars])


def is_possible(rows):
    for h in range(H):
        for w in range(W):
            if rows[h][w] == 0:
                continue

            pair_candidates = []
            if w - 1 >= 0:
                pair_candidates.append((h, w - 1))
            if w + 1 < W:
                pair_candidates.append((h, w + 1))
            if h - 1 >= 0:
                pair_candidates.append((h - 1, w))
            if h + 1 < H:
                pair_candidates.append((h + 1, w))
            pair_candidates_sum = sum([
                rows[_h][_w] for _h, _w in pair_candidates
            ])

            if pair_candidates_sum == 0:
                return False

    return True


if is_possible(rows):
    print('Yes')
else:
    print('NO')

Submission status: Wrong Answer

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

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

def dfs(x, y):
    flg = 0
    for ii in range(4):
        nx = x + dx[ii]
        ny = y + dy[ii]
        if nx < 0 or nx >= H or ny < 0 or ny >= W:
            continue
        if ls[nx][ny] == '#':
            flg = 1
    return flg

flg2 = 0
for i in range(H):
    for j in range(W):
        if ls[i][j] == '#':
            if dfs(i, j) == 0:
                flg2 = -1
                break
        else:
            continue
        break

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