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:
# coding: utf-8

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

# 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, c in enumerate(S[0][1:W - 1]):
        if c == '#':
            if (S[1][j+1] == '.' and S[0][j + 2] == '.' and S[0][j] == '.'):
                ans = 'No'
                endFlg = True

if endFlg != True:
    # 下辺
    for j, c in enumerate(S[H - 1][1:W - 1]):
        if c == '#':
            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, c in enumerate(S[1:H - 2][0]):
        if c == '#':
            if (S[i+1][1] == '.' and S[i][0] == '.' and S[i+2][0] == '.'):
                ans = 'No'
                endFlg = True

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

for i, r in enumerate(S[1:H - 1][1:W - 2]):
    for j, c in enumerate(r):
        if c == '#':
            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:
import sys
H,W = input().split()
H = int(H)
W = int(W)
s = []

s.append("."*(W+2))
for i in range(H):
    s.append("."+input()+".")

s.append("."*(W+2))


for j in range(1,1+H):
    for i in range(1,1+W):
#        print(j,i)
        if s[i][j] == "#":
            if s[i][j-1] != "#" and s[i][j+1] != "#" and s[i-1][j] != "#" and s[i+1][j] != "#":
                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 = map(int, input().split())
s = []
for i in range(W):
    s.append(input().split())
print(s)
answer = 'No'

for ii in range(H-2):
    for jj in range(W-2):
        if s[ii][jj] + s[ii][jj+1] == '##':
            answer = 'Yes'

for jj in range(W-2):
    for ii in range(H-2):
        if s[ii][jj] + s[ii+1][jj] == '##':
            answer = 'Yes'

print(answer)

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:
H,W = map(int,input().split())
lists = [input() for i in range(H)]
x = 1
y = 1
check = True
while(x<W-1 and y<H-1):
    if(lists[x][y] == "#"):
        if(x!=0 or y!=0 or x==W-1or y==H-1):
            if((lists[x+1][y] == ".") and (lists[x-1][y] == ".") and (lists[x][y-1] == ".") and (lists[x][y+1] == ".")):
                check = False
    x = x+1
    if(x <=W-1):
        x = 1
        y = y+1
if(lists[0][0] == "#"):
     if(lists[0][1] == "." and lists[1][0] == "."):
        check = False
if(lists[H-1][0] == "#"):
     if(lists[H-2][0] == "." and lists[H-1][1] == "."):
            check = False
if(lists[0][W-1] == "#"):
    if(lists[0][W-2] == "." and lists[1][W-1] == "."):
        check = False
if(lists[H-1][W-1] == "#"):
    if(lists[H-2][W-1] == "." and lists[H-1][W-2] == "."):
        check = False
if(check):
    print("Yes")
else :
    print("No")

Submission status: Runtime Error

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

for ii in range(H-2):
    for jj in range(W-2):
        if s[ii][jj] + s[ii][jj-1] == '##':
            answer = 'Yes'

for jj in range(W-2):
    for ii in range(H-2):
        if s[ii][jj] + s[ii-1][jj] == '##':
            answer = 'Yes'

print(answer)

Submission status: Runtime Error

Solution code:
import sys

h, w = map(int, input().split())

s = []
for i in range(h):
    s.append(input())

ans = True
flag = False

for i in range(h):
    for j in range(w):
        if s[i][j] == '#':
            if i == 0:
                if(s[i][j-1] == '.' and s[i+1][j] == '.' and s[i][j+1] == '.'):
                    ans = False
                    break
                break

            elif j == 0:
                if(s[i-1][j] == '.' and s[i+1][j] == '.' and s[i][j+1] == '.'):
                    ans = False
                    break
                break
            elif i == h-1:
                if(s[i-1][j] == '.' and s[i][j-1] == '.' and s[i][j+1] == '.'):
                    ans = False
                    break
                break
            elif j == w-1:
                if(s[i-1][j] == '.' and s[i][j-1] == '.' and s[i+1][j] == '.'):
                    ans = False
                    break
                break
            else:
                if(s[i-1][j] == '.' and s[i][j-1] == '.' and s[i+1][j] == '.' and s[i][j+1] == '.'):
                    ans = False
                    break

    if not(ans):
        break

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

Submission status: Runtime Error

Solution code:
import sys

h, w = map(int, input().split())

s = []
for i in range(h):
    s.append(input())

ans = True
flag = False

for i in range(h):
    for j in range(w):
        if s[i][j] == '#':
            if i==0 and j==0:
                if(s[i+1][j] == '.' and s[i][j+1] == '.'):
                    ans = False
                    break
                break
            elif i==0 and j==w-1:
                if(s[i][j-1] == '.' and s[i][j+1] == '.'):
                    ans = False
                    break
                break
            elif i==h-1 and j==0:
                if(s[i-1][j] == '.' and s[i][j+1] == '.')
                    ans = False
                    break
                break
            elif i==h-1 and j==w-1:
                if(s[i-1][j] == '.' and s[i][j-1] == '.'):
                    ans = False
                    break
                break



            if i == 0:
                if(s[i][j-1] == '.' and s[i+1][j] == '.' and s[i][j+1] == '.'):
                    ans = False
                    break
                break

            elif j == 0:
                if(s[i-1][j] == '.' and s[i+1][j] == '.' and s[i][j+1] == '.'):
                    ans = False
                    break
                break
            elif i == h-1:
                if(s[i-1][j] == '.' and s[i][j-1] == '.' and s[i][j+1] == '.'):
                    ans = False
                    break
                break
            elif j == w-1:
                if(s[i-1][j] == '.' and s[i][j-1] == '.' and s[i+1][j] == '.'):
                    ans = False
                    break
                break
            else:
                if(s[i-1][j] == '.' and s[i][j-1] == '.' and s[i+1][j] == '.' and s[i][j+1] == '.'):
                    ans = False
                    break

    if not(ans):
        break

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

Submission status: Runtime Error

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

table = []
for w 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
else:
    print('Yes')

Submission status: Runtime Error

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

s = []
for i in range(W):
    s.append([1 if num=="#" else 0 for num in list(input())])

decision = True

for i in range(W):
    for j in range(H):
        if s[i][j] == 1:
            if i == 0:
                if j == 0:
                    if s[i+1][j]==0 and s[i][j+1]==0:
                        decision=False
                        break
                elif j == H-1:
                    if  s[i][j-1]==0 and s[i+1][j]==0:
                        decision=False
                        break
                else:
                    if  s[i][j-1]==0 and s[i+1][j]==0 and s[i][j+1]==0:
                        decision=False
                        break
            elif j == 0:
                if i == W-1:
                    if s[i-1][j]==0 and s[i][j+1]==0:
                        decision=False
                        break
                else:
                    if s[i-1][j]==0 and s[i+1][j]==0 and s[i][j+1]==0:
                        decision=False
                        break
            elif i == W-1:
                if j == H-1:
                    if s[i-1][j]==0 and s[i][j-1]==0:
                        decision=False
                        break
                else:
                    if s[i-1][j]==0 and s[i][j-1]==0 and s[i][j+1]==0:
                        decision=False
                        break
            elif j == H-1:
                if s[i-1][j]==0 and s[i][j-1]==0 and s[i+1][j]==0:
                    decision=False
                    break
            else:
                if s[i-1][j]==0 and s[i][j-1]==0 and s[i+1][j]==0 and s[i][j+1]==0:
                    decision=False
                    break

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

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 < h and 0 <= y + j < w 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 (2,W):
    for k in range (2,H-1):
        if s[j][k-2:k+1]==['#', '.', '#'] and s[j-2:j+1][k]==['#', '.', '#']:
            print ('No')
            sys.exit()

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 < h and 0 <= y + j < w 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 = (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 < h and 0 <= y + j < w 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",i,j)
            f = False
if(f):
    print("Yes")

Submission status: Runtime Error

Solution code:
import sys

h, w = map(int, input().split())

s = []
for i in range(h):
    s.append(input())

ans = True
flag = False

for i in range(h):
    for j in range(w):
        if s[i][j] == '#':
            if i==0 and j==0:
                if(s[i+1][j] == '.' and s[i][j+1] == '.'):
                    ans = False
                    break

            elif i==0 and j==w-1:
                if(s[i][j-1] == '.' and s[i][j+1] == '.'):
                    ans = False
                    break
            elif i==h-1 and j==0:
                if(s[i-1][j] == '.' and s[i][j+1] == '.')
                    ans = False
                    break
            elif i==h-1 and j==w-1:
                if(s[i-1][j] == '.' and s[i][j-1] == '.'):
                    ans = False
                    break



            if i == 0:
                if(s[i][j-1] == '.' and s[i+1][j] == '.' and s[i][j+1] == '.'):
                    ans = False
                    break

            elif j == 0:
                if(s[i-1][j] == '.' and s[i+1][j] == '.' and s[i][j+1] == '.'):
                    ans = False
                    break
            elif i == h-1:
                if(s[i-1][j] == '.' and s[i][j-1] == '.' and s[i][j+1] == '.'):
                    ans = False
                    break
            elif j == w-1:
                if(s[i-1][j] == '.' and s[i][j-1] == '.' and s[i+1][j] == '.'):
                    ans = False
                    break
            else:
                if(s[i-1][j] == '.' and s[i][j-1] == '.' and s[i+1][j] == '.' and s[i][j+1] == '.'):
                    ans = False
                    break

    if not(ans):
        break

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

Submission status: Runtime Error

Solution code:
import sys

def rec_function(i, j, lasting):
    check_list[i][j] = 1

    if (not lasting) and \
       (not (i < W - 1 and s_list[i+1][j] == "#")) and \
       (not (j < H - 1 and s_list[i][j+1] == "#")):
        global impossible
        impossible = True
        return

    if i < W - 1 and s_list[i+1][j] == "#":
        rec_function(i + 1, j, True)
    if j < H - 1 and s_list[i][j+1] == "#":
        rec_function(i, j + 1, True)



H, W = list(map(int, input().split()))
s_list = list()
check_list = [[0]*W]*H
impossible = False

for _ in range(H):
    s = input()
    s_list.append(s)

for i in range(H):
    for j in range(W):
        if check_list[i][j] == 1:
            continue

        if s_list[i][j] == '.':
            check_list[i][j] = 1
            continue

        rec_function(i, j, False)
        
        if impossible:
            print('No')
            sys.exit()

print('Yes')

Submission status: Runtime Error

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

def search(nx,ny):
    if(nx==0 and ny==0):
        if(S[ny][nx]=="#" and S[ny+1][nx]=="." and S[ny][nx+1]=="."):
            return 1
    elif(nx==W-1 and ny==H-1):
        if(S[ny][nx]=="#" and S[ny-1][nx]=="." and S[ny][nx-1]=="."):
            return 1
    elif(nx==0 and ny==H-1):
        if(S[ny][nx]=="#" and S[ny-1][nx]=="." and S[ny][nx+1]=="."):
            return 1
    elif(nx==W-1 and ny==0):
        if(S[ny][nx]=="#" and S[ny+1][nx]=="." and S[ny][nx-1]=="."):
            return 1
    elif(ny==0):
        if(S[ny][nx]=="#" and S[ny][nx-1]=="." and S[ny][nx+1]=="." and S[ny+1][nx]=="."):
            return 1
    elif(nx==0):
        if(S[ny][nx]=="#" and S[ny-1][nx]=="." and S[ny+1][nx]=="." and S[ny][nx+1]=="."):
            return 1
    elif(ny==H-1):
        if(S[ny][nx]=="#" and S[ny][nx-1]=="." and S[ny][nx+1]=="." and S[ny-1][nx]=="."):
            return 1
    elif(nx==W-1):
        if(S[ny][nx]=="#" and S[ny-1][nx]=="." and S[ny+1][nx]=="." and S[ny][nx-1]=="."):
            return 1
    else:
        if(S[ny][nx]=="#" and S[ny][nx-1]=="." and S[ny][nx+1]=="." and S[ny-1][nx]=="." and S[ny+1][nx]=="."):
            return 1
    
    return 0

sum = 0
for i in range(H):
    for j in range(W):
        sum += search(i,j)
        
if(sum==0):
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
nums = list(map(int, input().split()))
H=nums[0]
W=nums[1]
Strings=[]
for k in range(H):
    Strings.append(input())
c=0
for p in range(H):
    list(Strings[p])
for i in range(H):
    for j in range(1, W):
        if (Strings[i][j]=="#" and Strings[i][j-1]=="#") or :
            c=1
            break
for l in range(W):
    for m in range(1,H):
        if Strings[m][l]=="#" and Strings[m-1][l]=="#":
            c=1
            break
if c==1:
    print("Yes") 
else:
    print("No")

Submission status: Runtime Error

Solution code:
import sys

def rec_function(i, j, lasting):
    check_list[i][j] = 1

    if (not lasting) and \
       (not (i < W - 1 and s_list[i+1][j] == "#")) and \
       (not (j < H - 1 and s_list[i][j+1] == "#")):
        global impossible
        impossible = True
        return

    if i < W - 1 and s_list[i+1][j] == "#":
        rec_function(i + 1, j, True)
    if j < H - 1 and s_list[i][j+1] == "#":
        rec_function(i, j + 1, True)



H, W = list(map(int, input().split()))
s_list = list()
check_list = [[0]*W]*H
impossible = False

for _ in range(H):
    s = input()
    s_list.append(s)

for i in range(W):
    for j in range(H):
        if check_list[i][j] == 1:
            continue

        if s_list[i][j] == '.':
            check_list[i][j] = 1
            continue

        rec_function(i, j, False)
        
        if impossible:
            print('No')
            sys.exit()

print('Yes')

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       
        for j in range(0,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         
    
    
    print(result)
  
else:
    print(result)

Submission status: Runtime Error

Solution code:
H, W = (int(i) for i in input().split())
t = []
t.append(['.']*(H+2))

for j in range(H):
	tmp = input()
	tmp = '.' + tmp + '.'
	t.append(list(tmp))

t.append(['.']*(H+2))

def CheckBlock(i,k):
	if t[i][k-1] == '#': #check up
		return 0
	elif t[i-1][k] == '#': #check left
		return 1
	elif t[i+1][k] == '#': #check right
		return 2
	elif t[i][k+1] == '#': #check down
		return 3
	else:
		return 4

for i in range(1,W+1):
	for k in range(1,H+1):
		if t[i][k] == '#':
			marker = CheckBlock(i,k)
			if marker == 4:
				print('No')
				quit()
print('Yes')

Submission status: Runtime Error

Solution code:
n = int(input())
a = []
sosu = []

def sosuuhantei(x):
    p = x
    if p < 2:
        return false
    elif  n == 2:
        return p
    else:
        for i in range(3,math.floor(math.sqrt(x)) + 1,2):
            if x % i == 0:
                return False
        else:
             return x
            
            
sosulist = []
 
if n < 2:
    None
elif n == 2:
    sosulist.append(2)
else:
    sosulist.append(2)
    for i in range(3,55555+1,2):
        sosulist.append(sosuuhantei(i))
import random
print(random.choice(sosulist,k = 5))

Submission status: Runtime Error

Solution code:
h,w = map(int,input().split())
c = [[] for i in range(0,h+2)]
ans = "Yes"
c[0] = ["#"for i in range(0,w+2)]
c[h+1] = ["#"for i in range(0,w+2)]
for i in range(1,h+1):
    d = []
    d = list(input())
    d.append("#")
    d.insert(0,"#")
    c[i] = d
for i in range(1,h+1):
    for j in range(1,w+1):
        if c[j][i] == "#":
            flag = "No"
            if(c[j][i-1] == "#"):
                flag = "Yes"
            if(c[j][i+1] == "#"):
                flag = "Yes"
            if(c[j-1][i] == "#"):
                flag = "Yes"
            if(c[j+1][i] == "#"):
                flag = "Yes"
            if(flag == "No"):
                ans = "No"
print(ans)

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)

    if all([(t in targets) for t in get_arounds(target) for target in targets]):
        print('Yew')
    else:
        print('No')


if __name__ == '__main__':
    main()

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
                    if bord[y+1][x]=='#':Answer=1
                elif x==h-1:
                    if bord[y][x-1]=='#': Answer=1
                    if bord[y+1][x]=='#':Answer=1
                else:
                    if bord[y][x+1]=='#': Answer=1
                    if bord[y][x-1]=='#': Answer=1
                    if bord[y+1][x]=='#':Answer=1
            elif y==w-1:
                if x==0:
                    if bord[y][x+1]=='#': Answer=1
                    if bord[y-1][x]=='#':Answer=1
                elif x==h-1:
                    if bord[y][x-1]=='#': Answer=1
                    if bord[y-1][x]=='#':Answer=1
                else:
                    if bord[y][x+1]=='#': Answer=1
                    if bord[y][x-1]=='#': Answer=1
                    if bord[y-1][x]=='#':Answer=1
            elif x==0:
                if bord[y+1][x]=='#':Answer=1
                if bord[y-1][x]=='#':Answer=1
                if bord[y][x+1]=='#': Answer=1
            elif x==h-1:
                if bord[y+1][x]=='#':Answer=1
                if bord[y-1][x]=='#':Answer=1
                if bord[y][x-1]=='#': Answer=1
            else:
                if bord[y+1][x]=='#':Answer=1
                if bord[y-1][x]=='#':Answer=1
                if bord[y][x-1]=='#': Answer=1
                if bord[y][x+1]=='#': Answer=1
if Answer == 1:
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

Solution code:
import sys

h, w = map(int, input().split())

s = []
for i in range(h):
    s.append(input())

ans = True
flag = False

for i in range(h):
    for j in range(w):
        if s[i][j] == '#':
            if i == 0:
                if(s[i][j-1] == '.' and s[i+1][j] == '.' and s[i][j+1] == '.'):
                    ans = False
                    break

            elif j == 0:
                if i==0:
                    if(s[i+1][j] == '.' and s[i][j+1] == '.'):
                        ans = False
                        break

                else:
                    if(s[i-1][j] == '.' and s[i+1][j] == '.' and s[i][j+1] == '.'):
                        ans = False
                        break
            elif i == h-1:
                if(s[i-1][j] == '.' and s[i][j-1] == '.' and s[i][j+1] == '.'):
                    ans = False
                    break
            elif j == w-1:
                if i == h-1:
                    if(s[i-1][j] == '.' and s[i][j-1] == '.'):
                        ans = False
                        break
                    else:
                        if(s[i-1][j] == '.' and s[i][j-1] == '.' and s[i+1][j] == '.'):
                            ans = False
                            break
            else:
                if(s[i-1][j] == '.' and s[i][j-1] == '.' and s[i+1][j] == '.' and s[i][j+1] == '.'):
                    ans = False
                    break

    if not(ans):
        break

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