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: Runtime Error

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

Submission status: Runtime Error

Solution code:

def grid_search(grid, H, W):
    NO = 'No'
    for i in range(H):
        for j in range(W):
            if grid[i][j] == '#':
                if i == 0 or j == 0:
                    if j != 0:
                        if j == W-1:
                            if grid[i+1][j] != '#' and grid[i][j-1] != '#':
                                return NO
                        else:
                            if grid[i+1][j] != '#' and grid[i][j+1] != '#' and grid[i][j-1] != '#':
                                return NO
                    else:
                        if i == H-1:
                            if grid[i][j+1] != '#' and grid[i-1][j] != '#':
                                return NO
                        else:
                            if grid[i+1][j] != '#' and grid[i][j+1] != '#' and grid[i-1][j] != '#':
                                return NO
                elif i == H-1 or j == W-1:
                    if j != W-1:
                        if grid[i-1][j] != '#' and grid[i][j+1] != '#' and grid[i][j-1] != '#':
                            return NO
                    else:
                        if grid[i+1][j] != '#' and grid[i][j-1] != '#' and grid[i-1][j] != '#':
                            return NO
                else:
                    if grid[i+1][j] != '#' and grid[i][j+1] != '#' and grid[i][j-1] != '#' and grid[i-1][j] != '#':
                        return NO
    return 'Yes'

if __name__ == '__main__':
    H, W = map(int, input().split())
    grid = []
    for i in range(H):
        grid.append(input())
    print(grid_search(grid, H, W))

Submission status: Runtime Error

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

counter = 0

def check(li,x,y):
    d = [-1,1]
    bool = False
    for dx in d:
        if x + dx >= 0 and x + dx < W and li[x + dx][y] == '#':
            bool = True
        else:
            pass
    for dy in d:
        if y + dy >= 0 and y + dy < H and li[x][y + dy] == '#':
            bool = True
        else:
            pass
    return bool


for x in range(W):
    for y in range(H):
        if info[x][y] == '#':
            if check(info,x,y) == False:
                counter += 1
                pass
        else:
            pass

if counter > 0:
    print ('No')
else:
    print ('Yes')

Submission status: Runtime Error

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

counter = 0

def check(li,x,y):
    d = [-1,1]
    bool = False
    for dx in d:
        if x + dx >= 0 and x + dx < W and li[x + dx][y] == '#':
            bool = True
        else:
            pass
    for dy in d:
        if y + dy >= 0 and y + dy < H and li[x][y + dy] == '#':
            bool = True
        else:
            pass
    return bool


for x in range(W):
    for y in range(H):
        if info[x][y] == '#':
            if check(info,x,y) == False:
                counter += 1
                pass
        else:
            pass

if counter > 0:
    print ('No')
else:
    print ('Yes')

Submission status: Runtime Error

Solution code:
H,W = sorted(map(int,input().split()))
ss=[]
for s in range(H):
    ss.append(input().strip())
flg=True
for i in range(H):
    for j in range(W):
        if ss[i][j]== "#":
            if not (j>0 and ss[i][j-1] == "#"or j<W-1 and ss[i][j+1] == "#" or i>0 and ss[i-1][j]=="#" or i< H-1 and ss[i+1][j]=="#"):
                flg=False
                break
    if not flg:
        break
print("No Yes".split()[int(flg)])

Submission status: Runtime Error

Solution code:
import numpy as np
h, w = map(int, input().split())
s = np.array([list(input()) for _ in range(h)])
w1, w2 = np.array(["."]*w), np.array(["."]*(h+2))
s = np.hstack((w1, s))
s = np.hstack((s, w1))
s = np.vstack((w2.reshape(len(w2),1), s))
s = np.vstack((s, w2.reshape(len(w2),1)))
dx, dy = [1, 0, -1, 0], [0, 1, 0, -1]
for i in range(1, h+1, 1):
    for j in range(1, w+1, 1):
        now = s[i][j]
        c = 0
        if now == ".":
            continue
        for d in range(4):
            x = j + dx[d]
            y = i + dy[d]
            if now == s[y][x]:
                c += 1
        if c == 0:
            print("No")
            exit()
print("Yes")

Submission status: Runtime Error

Solution code:
import numpy as np
h, w = map(int, input().split())
s = np.array([list(input()) for _ in range(h)])
w1, w2 = np.array(["."]*w), np.array(["."]*(h+2))
s = np.hstack((w1.reshape(len(w1),1), s))
s = np.hstack((s, w1.reshape(len(w1),1)))
s = np.vstack((w2, s))
s = np.vstack((s, w2))
dx, dy = [1, 0, -1, 0], [0, 1, 0, -1]
for i in range(1, h+1, 1):
    for j in range(1, w+1, 1):
        now = s[i][j]
        c = 0
        if now == ".":
            continue
        for d in range(4):
            x = j + dx[d]
            y = i + dy[d]
            if now == s[y][x]:
                c += 1
        if c == 0:
            print("No")
            exit()
print("Yes")

Submission status: Runtime Error

Solution code:
# 方針：黒く塗られるべきマスの隣（縦or横）に、同様のマスがあれば塗れる→Yes
# 逆に、黒く塗られるべきマスに接していない、黒く塗られるべきマスがあると、達成は不可能→No

# 行数・列数の入力(Row, Column)
H, W = list(map(int, input().split(" ")))

# 全入力を２次元配列へと変換
paint_map = []
for h in range(H):
    paint_map.append(list(input()))

# 各マス目の周りに黒があるかを確認する
ans = True  # 最終的な出力。始めは、塗ることが可能であるとして初期化してある

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

for i in range(H):
    for j in range(W):
        if paint_map[i][j] == "#":
            found = False  # 注目している黒マスの周りに、別の黒マスを見つけたか

            for k in range(k):
                ii = i + dx[k]
                jj = j + dy[k]

                if (H > ii >= 0) & (W > jj >= 0) & (paint_map[ii][jj] == "#"):  # 注目している座標がキャンパス上にあり、かつ黒色なら。
                    found = True

            if not found:  # もしも注目している黒マスの周りに、別の黒マスが見つからなかったら
                ans = False

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

Submission status: Runtime Error

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


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

field=[]
for i in range(H):
    tmp=list(input())
    field.append(tmp)

flag=False
for i in range(H):
    for j in range(W):
        if field[i][j]=="#":
            check="hoo"
            if i-1>=0 and field[i-1][j]=="#":
                check="hey"
            if j+1<=W and field[i][j+1]=="#":
                check="hey"
            if i+1<=H and field[i+1][j]=="#":
                check="hey"
            if j-1>=0 and field[i][j-1]=="#":
                check="hey"
            if check=="hoo":
                flag=True
                break
        else:
            continue
    if flag:
        print("No")
        break
if flag!=True:
    print(Yes)

Submission status: Runtime Error

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

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

field=[]
for i in range(H):
    tmp=list(input())
    field.append(tmp)

for i in range(H):
    for j in range(W):
        if field[i][j]=="#"
            check="hoo"
            if i-1>=0 and field[i-1][j]=="#":
                check="hey"
            if j+1<=W and field[i][j+1]=="#":
                check="hey"
            if i+1<=H and field[i+1][j]=="#":
                check="hey"
            if j-1>=0 and field[i][j-1]=="#":
                check="hey"
            if chack=="hoo":
                flag=True
                break
        else:
            continue
    if flag:
        print("No")
        break
if flag!=True:
    print(Yes)

Submission status: Runtime Error

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

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

field=[]
for i in range(H):
    tmp=list(input())
    field.append(tmp)

for i in range(H):
    for j in range(W):
        if field[i][j]=="#" and i-1>=0 and field[i-1][j]!="#" and j+1<=W and field[i][j+1]!="#" and
i+1<=H and field[i+1][j]!="#" and j-1>=0 and field[i][j-1]!="#":
            flag=True
            break
        else:
            continue
    if flag:
        print("No")
        break
if flag==False:
    print(Yes)

Submission status: Runtime Error

Solution code:
H,W = map(int,input().split())
S = []
flag = "Yes"
for i in range(0,H):
    S.append(list(input()))

    
for i in range(0,H):
    for j in range(0,W):
        if S[i][j] == "#":
            if i != 0 and S[i-1][j] == "#" : continue
            elif i != H-1 and S[i+1][j] == "#": continue
            elif j != 0 and S[i][j-1] == "#": continue
            elif j != W-1 and S[i][j+1] == "#":continue
            else flag = "No"
            
print(flag)

Submission status: Runtime Error

Solution code:
H,W = map(int,input().split())
S = []
flag = "Yes"
for i in range(0,H):
    S.append(list(input()))

for j in range(0,W)
    
for i in range(0,H):
    for j in range(0,W):
        if S[i][j] == "#":
            if i != 0 and S[i-1][j] == "#" : continue
            elif i != H-1 and S[i+1][j] == "#": continue
            elif j != 0 and S[i][j-1] == "#": continue
            elif j != W-1 and S[i][j+1] == "#":continue
            else flag = "No"
            
print(flag)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
# coding: utf-8

H, W = map(int, input().split())
S = []
for i in range(H):
    S.append(list(input()))
ans = 'Yes'
endFlg = False

# '#'の点をみつけたときに、その上下左右に'#'がない場合、孤立した点を黒く塗ることはできないので、答えはNoとなる。
# 全部の'#'の点について、その上下左右のいずれかに'#'が見つかれば、答えはYesとなる。

# 4隅
if S[0][0] == '#' and S[0][1] == '.' and S[1][0] == '.':
    ans = 'No'
    endFlg = True
if S[0][W - 1] == '#' and S[0][W - 2] == '.' and S[1][W - 1] == '.':
    ans = 'No'
    endFlg = True
if S[H - 1][0] == '#' and S[H - 1][1] == '.' and S[H - 2][0] == '.':
    ans = 'No'
    endFlg = True
if S[H - 1][W - 1] == '#' and S[H - 1][W - 2] == '.' and S[H - 2][W - 1] == '.':
    ans = 'No'
    endFlg = True

# 上辺
if endFlg != True:
    for j in range(1, W-1):
        if S[0][j] == '#':
            if (S[1][j + 1] == '.' and S[0][j + 2] == '.' and S[0][j] == '.'):
                ans = 'No'
                endFlg = True

if endFlg != True:
    # 下辺
    for j in range(1, W-1):
        if S[0][j] == '#':
            if (S[H-2][j+1] == '.' and S[H-1][j + 2] == '.' and S[H-1][j] == '.'):
                ans = 'No'
                endFlg = True

if endFlg != True:
    # 左辺
    for i in range(1,H-2):
        if S[i][0] == '#':
            if (S[i+1][1] == '.' and S[i][0] == '.' and S[i+2][0] == '.'):
                ans = 'No'
                endFlg = True

if endFlg != True:
    # 右辺
    if i in range(1, H-2):
        if S[i][W-1] == '#':
            if (S[i+1][W-2] == '.' and S[i][W-1] == '.' and S[i+2][W-1] == '.'):
                ans = 'No'
                endFlg = True

# 中の領域について探索
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][j + 1] == '.' and S[i + 1][j] == '.' and S[i][j - 1] == '.'):
                ans = 'No'
                endFlg = True
                break
    if endFlg == True:
        break

print(ans)

Submission status: Runtime Error

Solution code:
l = input().split()
h,w = int(l[0]),int(l[1])
mapxy = []
for i in range(h):
    mapxy.append(list(input()))
dx = [1,0,-1,0]
dy = [0,1,0,-1]
flag1 = 0
flag2 = 0
for i in range(h):
    for j in range(w):
        if mapxy[i][j] == "#":
            for k in range(4):
                if 0<=i+dx[k]<w and 0<=j+dy[k]<h:
                    if mapxy[i+dx[k]][j+dy[k]] == "#":
                        flag1 = 1
            if flag1 == 0:
                flag2 = 1
                break
            flag1 = 0
    if flag2 == 1:
        print("No")
        break
if flag2 != 1:
    print("Yes")

Submission status: Runtime Error

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

mx = [0, 1, 0, -1]
my = [1, 0, -1, 0]
for i in range(h):
  for  j in range(w):
    if table[i][j] == "#":
      for k in range(4):
        tx, ty = j + mx[k], i + my[k]
        if 0 <= tx <= w and 0 <= ty <= h and table[ty][tx] == "#":
          visited[i][j] = visited[ty][tx] = "#"

for i in range(h):
  for  j in range(w):
    if table[i][j] != visited[i][j]:
      print("No")
      exit(0)
print("Yes")

Submission status: Runtime Error

Solution code:
H, W = map(int, input().split(" "))
result = True
masu = [["." for i in range(H+2)] for j in range(W+2)]
for h in range(1, H+1):
    s = "0"+input()+"0"
    masu[h] = list(s)
# print(masu)
for h in range(1, H+1):
    for w in range(1, W+1):
        # print(h, w, masu[h][w])
        if masu[h][w] == "#" and masu[h+1][w] != "#" and masu[h][w+1] != "#" and masu[h-1][w] != "#" and masu[h][w-1] != "#":
            result = False
if result:
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
H, W = map(int, input().split(" "))
if H == 1 or W == 1:
    print("No")
    break
result = True
masu = [["." for i in range(H+2)] for j in range(W+2)]
for h in range(1, H+1):
    s = "0"+input()+"0"
    masu[h] = list(s)
# print(masu)
for h in range(1, H+1):
    for w in range(1, W+1):
        # print(h, w, masu[h][w])
        if masu[h][w] == "#" and masu[h+1][w] != "#" and masu[h][w+1] != "#" and masu[h-1][w] != "#" and masu[h][w-1] != "#":
            result = False
            break
if result:
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
H, W = map(int, input().split(" "))
result = True
masu = [["." for i in range(H+2)] for j in range(W+2)]
for h in range(1, H+1):
    s = "."+input()+"."
    masu[h] = list(s)
# print(masu)
for h in range(1, H+1):
    for w in range(1, W+1):
        # print(h, w, masu[h][w])
        if masu[h][w] == "#" and masu[h+1][w] != "#" and masu[h][w+1] != "#" and masu[h-1][w] != "#" and masu[h][w-1] != "#":
            result = False
            break
if result:
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:

H, W = map(int, input().split(" "))
 
result = True
masu = [["0" for i in range(H+2)] for j in range(W+2)]
for h in range(1, H+1):
    s = "0"+input()+"0"
    masu[h] = list(s)
 
# print(masu)    
 
for h in range(1, H+1):
    for w in range(1, W+1):
        # print(h, w, masu[h][w])
        if masu[h][w] == "#" and masu[h+1][w] != "#" and masu[h][w+1] != "#" and masu[h-1][w] != "#" and masu[h][w-1] != "#":
            result = False
            break
if result:
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
import numpy as np

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

S = np.zeros((H, W))

d_flag = 0

for i in range(H):
    tmp = list(raw_input())
    for j in range(W):
        if tmp[j] == "#":
            S[i, j] = 1
            d_flag = 1
        else:
            S[i, j] = 0



for i in range(H):
    for j in range(W):
        if S[i, j] == 1:
            flag = 0
            if i>1:
                a1 = S[i-1, j]
            else:
                a1 = 0
            if j>1:
                a2 = S[i, j-1]
            else:
                a2 = 0
            if i<H-1:
                a3 = S[i+1, j]
            else:
                a3 = 0
            if j<W-1:
                a4 = S[i, j+1]
            else:
                a4 = 0
            print(a1+a2+a3+a4)
            if a1+a2+a3+a4 == 0:
                d_flag = 0
                
if d_flag == 1:

Submission status: Runtime Error

Solution code:
H,W=map(int,input().split())
s=[input() for i in range (H)] #listしたらだめ
import sys
for j in range (1,W):
    for k in range (1,H-1):
        if s[j][k]=='#' and s[j][k-1]=='.' and s[j][k+1]=='.' and s[j-1][k]=='.' and s[j+1][k]=='.':
            print ('No')
            sys.exit()

#４枠の処理
for j in range (1,H-1):
    if s[j][0]=='#'  and s[j-1][0]=='.' and s[j+1][0]=='.' and  s[j][1]=='.':
        print ('No')
        sys.exit()
    if s[j][W-1]=='#'  and s[j-1][W-1]=='.' and s[j+1][W-1]=='.' and  s[j][W-2]=='.':
        print ('No')
        sys.exit()
        
for j in range (1,W-1):
    if s[0][j]=='#'  and s[0][j-1]=='.' and s[0][j+1]=='.' and  s[1][j]=='.':
        print ('No')
        sys.exit()
    if s[W-1][j]=='#'  and s[W-1][j-1]=='.' and s[W-1][j+1]=='.' and  s[W-2][j]=='.':
        print ('No')
        sys.exit()

if s[0][0]=='#' and s[1][0]=='.' and s[0][1]=='.':
    print ('No')
    sys.exit()
if s[H-1][0]=='#' and s[H-2][0]=='.' and s[H-1][1]=='.':
    print ('No')
    sys.exit()
if s[0][W-1]=='#' and s[1][W-1]=='.' and s[0][W-2]=='.':
    print ('No')
    sys.exit()
if s[H-1][W-1]=='#' and s[H-2][W-1]=='.' and s[H-1][W-2]=='.':
    print ('No')
    sys.exit()

print ('Yes')

Submission status: Runtime Error

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

inpt =[]
for h in H:
    i = str(input())
    inpt.append(i)

string = 'No'

for h in range(H):
    for w in range(W):
        if h == H-1 or w == W-1:
            continue
        if inpt[h][w] == '#':
            if inpt[h+1][w] == '#' or inpt[h][w+1] == '#':
                 string = 'Yes'
                 
print(string)

Submission status: Runtime Error

Solution code:
h,w = map(int, input().split())
bord = [list(input()) for n in range(w)]
Answer = 1
for y in range(len(bord)):
    for x in range(len(bord[0])):
        if bord[y][x]=='#':
            if y==0:
                if x==0:
                    if bord[y][x+0]=='.': 
                        Answer=0;continue
                    if bord[y+0][x]=='.':
                        Answer=0;continue
                elif x==h-0:
                    if bord[y][x-0]=='.':
                        Answer=0
                        continue
                    if bord[y+0][x]=='.':
                        Answer=0;continue
                else:
                    if bord[y][x+0]=='.':
                        Answer=0;continue
                    if bord[y][x-0]=='.':
                        Answer=0;continue
                    if bord[y+0][x]=='.':
                        Answer=0;continue
            elif y==w-0:
                if x==0:
                    if bord[y][x+0]=='.':
                        Answer=0;continue
                    if bord[y-0][x]=='.':
                        Answer=0;continue
                elif x==h-0:
                    if bord[y][x-0]=='.':
                        Answer=0;continue
                    if bord[y-0][x]=='.':
                        Answer=0;continue
                else:
                    if bord[y][x+0]=='.':
                        Answer=0;continue
                    if bord[y][x-0]=='.':
                        Answer=0;continue
                    if bord[y-0][x]=='.':
                        Answer=0;continue
            elif x==0:
                if bord[y+0][x]=='.':
                    Answer=0;continue
                if bord[y-0][x]=='.':
                    Answer=0;continue
                if bord[y][x+0]=='.':
                    Answer=0;continue
            elif x==h-0:
                if bord[y+0][x]=='.':
                    Answer=0;continue
                if bord[y-0][x]=='.':
                    Answer=0;continue
                if bord[y][x-0]=='.':
                    Answer=0;continue
            else:
                if bord[y+0][x]=='.':
                    Answer=0;continue
                if bord[y-0][x]=='.':
                    Answer=0;continue
                if bord[y][x-0]=='.':
                    Answer=0;continue
                if bord[y][x+0]=='.':
                    Answer=0;continue
if Answer == 1:
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

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

inpt =[]
for h in H:
    i = str(input())

string = 'No'

for h in range(H):
    for w in range(W):
        if h == H-1 or w == W-1:
            continue
        if inpt[h][w] == '#':
            if inpt[h+1][w] == '#' or inpt[h][w+1] == '#':
                 string = 'Yes'
                 
print(string)

Submission status: Runtime Error

Solution code:
from itertools import repeat, product

def get_targets(a_grid):
    h = len(a_grid)
    w = len(a_grid[0])

    targets = [t for t in product(range(h), range(w)) if a_grid[t[0]][t[1]] == '#']

    return targets

def get_arounds(t, h, w):
    arounds = map(lambda a: (t[0] + a[0], t[1] + a[1]), ((0, 1), (1, 0), (0, -1), (-1, 0)))

    return list(filter(lambda x: -1 < x[0] < w and -1 < x[1] < h, arounds))

def main():
    h, w = tuple(map(int, input().split()))
    a_grid = [list(input()) for _ in range(h)]

    grid = [list(repeat('#', w)) for _ in range(h)]

    targets = get_targets(a_grid)

    while len(targets) != 0:
        t = targets.pop()
        arounds = get_arounds(t, h, w)
        if any([(a in targets) for a in arounds]):
            targets = list(filter(lambda e: e not in arounds), targets)
        else:
            print('No')
    else:
        print('Yes')


if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

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

s = []
for i in range(0,W):
    data = input()
    s.append(data)

result ="Yes"
check = 0

#1行目
for i in range(0,W):
    if s[0][i]=="#":
        if i==0:
            if s[1][i] == "." and s[0][i+1] == ".":
                result = "No"
                check = 1
                break
        elif i == W-1:
            if s[1][i] == "." and s[0][i-1] == ".":
                result = "No"
                check = 1
                break                
        else:        
            if s[1][i] == "." and s[0][i+1] == "." and s[0][i-1] == ".":
                result = "No"
                check = 1
                break


if check == 0:
    #H行目
    for i in range(0,W):
        if s[H-1][i]=="#":
            if i==0:
                if s[H-2][i] == "." and s[H-1][i+1] == ".":
                    result = "No"
                    check = 1
                    break
            elif i == W-1:
                if s[H-2][i] == "." and s[H-1][i-1] == ".":
                    result = "No"
                    check = 1
                    break                
            else:        
                if s[H-2][i] == "." and s[H-1][i+1] == "." and s[H-1][i-1] == ".":
                    result = "No"
                    check = 1
                    break
else:
    pass

if check == 0:
    for i in range(1,H-1):#行
        if check == 1:
            break
        if "#" in s[i] == True:
            for j in range(s[i].index("#"),W):#列
                if s[i][j]=="#":            
                    if j==0:#左端
                        if s[i-1][j] == "." and s[i+1][j] == "." and s[i][j+1] == ".":
                            result = "No"
                            check = 1
                            break
                    elif j == W-1:#右端
                        if s[i-1][j] == "." and s[i+1][j] == "." and s[i][j-1] == ".":
                            result = "No"
                            check = 1
                            break                
                    else:        
                        if  s[i-1][j] == "." and s[i+1][j] == "." and s[i][j+1] == "." and s[i][j-1] == ".":
                            result = "No"
                            check = 1
                            break
                else:
                    pass
    
    
    print(result)
  
else:
    print(result)

Submission status: Runtime Error

Solution code:
h,w = map(int, input().split())
bord = [list(input()) for n in range(w)]
Answer = 0
for y in range(len(bord)):
    for x in range(len(bord[0])):
        if bord[y][x]=='#':
            if y==0:
                if x==0:
                    if bord[y][x+1]=='#': 
                        Answer=1;continue
                    if bord[y+1][x]=='#':
                        Answer=1;continue
                elif x==h-1:
                    if bord[y][x-1]=='#':
                        Answer=1
                        continue
                    if bord[y+1][x]=='#':
                        Answer=1;continue
                else:
                    if bord[y][x+1]=='#':
                        Answer=1;continue
                    if bord[y][x-1]=='#':
                        Answer=1;continue
                    if bord[y+1][x]=='#':
                        Answer=1;continue
            elif y==w-1:
                if x==0:
                    if bord[y][x+1]=='#':
                        Answer=1;continue
                    if bord[y-1][x]=='#':
                        Answer=1;continue
                elif x==h-1:
                    if bord[y][x-1]=='#':
                        Answer=1;continue
                    if bord[y-1][x]=='#':
                        Answer=1;continue
                else:
                    if bord[y][x+1]=='#':
                        Answer=1;continue
                    if bord[y][x-1]=='#':
                        Answer=1;continue
                    if bord[y-1][x]=='#':
                        Answer=1;continue
            elif x==0:
                if bord[y+1][x]=='#':
                    Answer=1;continue
                if bord[y-1][x]=='#':
                    Answer=1;continue
                if bord[y][x+1]=='#':
                    Answer=1;continue
            elif x==h-1:
                if bord[y+1][x]=='#':
                    Answer=1;continue
                if bord[y-1][x]=='#':
                    Answer=1;continue
                if bord[y][x-1]=='#':
                    Answer=1;continue
            else:
                if bord[y+1][x]=='#':
                    Answer=1;continue
                if bord[y-1][x]=='#':
                    Answer=1;continue
                if bord[y][x-1]=='#':
                    Answer=1;continue
                if bord[y][x+1]=='#':
                    Answer=1;continue
if Answer == 1:
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

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

table = []
for _ in range(h):
    row = input()
    table.append(row)


def is_paintable(r, c):
    if r > 0:
        if table[r-1][c] == "#":
            return True
    if r+1 <= h:
        if table[r+1][c] == "#":
            return True
    if c > 0:
        if table[r][c-1] == "#":
            return True
    if c+1 <= w:
        if table[r][c+1] == "#":
            return True
    else:
        return False

is_Yes = True
for i in range(h):
    if is_Yes == False:
        break
    for j in range(w):
        if table[i][j] == "#":
            if is_paintable(i, j) == False:
                print('No')
                is_Yes = False
                break

if is_Yes:
    print('Yes')

Submission status: Runtime Error

Solution code:
h , w = (int(i) for i in input().split())
a =[]
dy = [0, 0, 1, -1]
dx = [1, -1, 0, 0]


for i in range(h):
    a.append(input())
    
f = True
def check(x,y):
    if a[x][y] =='.':
        return True
    for n in range(4):
        i = dx[n]
        j = dy[n]
#        print(a[x+i][y+j])
        if 0 <= x+i < w and 0 <= y + j < h and a[x+i][y+j]=='#':
            #print(x+i,y+j)
            return True
    return False
#print(check(0,3))
f = True
for i in range(w):
    for j in range(h):
        l = check(i,j)
        if not(l) and f:
            print ("No")
            f = False
if(f):
    print("Yes")

Submission status: Runtime Error

Solution code:
H,W=map(int,input().split())
s=[list(input()) for i in range (H)] 
import sys
for j in range (1,W):
    for k in range (1,H-1):
        if s[j][k]=='#' and s[j][k-1]=='.' and s[j][k+1]=='.' and s[j-1][k]=='.' and s[j+1][k]=='.':
            print ('No')
            sys.exit()
print ('Yes')

Submission status: Runtime Error

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

table = []
for _ in range(h):
    row = input()
    table.append(row)


def is_paintable(r, c):
    if r >= 0:
        if table[r-1][c] == "#":
            return True
    if r+1 < h:
        if table[r+1][c] == "#":
            return True
    if c >= 0:
        if table[r][c-1] == "#":
            return True
    if c+1 < w:
        if table[r][c+1] == "#":
            return True
    else:
        return False

is_Yes = True
for i in range(h):
    if is_Yes == False:
        break
    for j in range(w):
        if table[i][j] == "#":
            if is_paintable(i, j) == False:
                print('No')
                is_Yes = False
                break

if is_Yes:
    print('Yes')

Submission status: Runtime Error

Solution code:
h , w = (int(i) for i in input().split())
a =[]
dy = [0, 0, 1, -1]
dx = [1, -1, 0, 0]


for i in range(w):
    a.append(input())
    
f = True
def check(x,y):
    if a[x][y] =='.':
        return True
    for n in range(4):
        i = dx[n]
        j = dy[n]
#        print(a[x+i][y+j])
        if 0 <= x+i < w and 0 <= y + j < h and a[x+i][y+j]=='#':
            #print(x+i,y+j)
            return True
    return False
#print(check(0,3))
f = True
for i in range(w):
    for j in range(h):
        l = check(i,j)
        if not(l) and f:
            print ("No")
            f = False
if(f):
    print("Yes")

Submission status: Runtime Error

Solution code:
H,W=map(int,input().split())
s=[list(input()) for i in range (H)] 
import sys
for j in range (1,W):
    for k in range (1,H-1):
        if s[j][k]=='#' and s[j][k-1]=='.' and s[j][k+1]=='.' and s[j-1][k]=='.' and s[j+1][k]=='.':
            print ('No')
            sys.exit()