Problem p03361 (python)

Fixed submission:
H, W = map(int, input().split())
s = [input() for i in range(H)]
for i in range(H):
    for j in range(W):
        if s[i][j] == ".":
            continue
        if i == 0 or s[i-1][j] == "#":
            continue
        if i == H-1 or s[i+1][j] == "#":
            continue
        if j == 0 or s[i][j-1] == "#":
            continue
        if j == W-1 or s[i][j+1] == "#":
            continue
        print("No")
        exit()
print("Yes")

Buggy submission (verdict: Runtime Error):
h, w = map(int, input().split())
box = [["."] + list(input()) + ["."] for i in range(h)]
box.insert(0, ["."] * (w + 2))
box.append(["."] * (w + 2))


def seek(box, i, j):
    if box[i][j] == "#":
        for x, y in [[1, 0], [-1, 0], [0, 1], [0, -1]]:
            xx = x + i
            yy = y + j
            if box[xx][yy] == "#" or box[xx][yy] == "O":
                box[i][j] = "O"
                seek(box, xx, yy)
    return box


for i in range(1, h + 1):
    for j in range(1, w + 1):
        seek(box, i, j)

for i in range(1, h + 1):
    for j in range(1, w + 1):
        if box[i][j] == "#":
            print("No")
            exit()

print("Yes")

Buggy submission (verdict: Runtime Error):
h, w = map(int, input().split())
box = [["."] + list(input()) + ["."] for i in range(h)]
box.insert(0, ["."] * (w + 2))
box.append(["."] * (w + 2))


def seek(box, i, j):
    if box[i][j] == "#":
        for x, y in [[1, 0], [-1, 0], [0, 1], [0, -1]]:
            xx = x + i
            yy = y + j
            if box[xx][yy] == "#" or box[xx][yy] == "O":
                box[i][j] = "O"
                seek(box, xx, yy)
    return box


for i in range(1, h + 1):
    for j in range(1, w + 1):
        seek(box, i, j)

for i in range(1, h + 1):
    for j in range(1, w + 1):
        if box[i][j] == "#":
            print("No")
            exit()

print("Yes")

Buggy submission (verdict: Runtime Error):
h,w=map(int,input().split())
box=[["."]+list(input())+["."] for i in range(h)]
box.insert(0,["."]*(w+2))
box.append(["."]*(w+2))

def seek(box,i,j):
    if box[i][j]=="#":
        for x,y in [[1,0],[-1,0],[0,1],[0,-1]]:
            xx=x+i
            yy=y+j
            if box[xx][yy]=="#" or box[xx][yy]=="O":
                box[i][j]="O"
                seek(box,xx,yy)
    return box

for i in range(1,h+1):
    for j in range(1,w+1):
        seek(box,i,j)

for i in range(1,h+1):
    for j in range(1,w+1):
        if box[i][j]=="#":
            print("No")
            exit()

print("Yes")

Buggy submission (verdict: Runtime Error):
h,w=map(int,input().split())
box=[["."]+list(input())+["."] for i in range(h)]
box.insert(0,["."]*(w+2))
box.append(["."]*(w+2))
count=0
def seek(box,i,j):
    point=[[1,0],[-1,0],[0,1],[0,-1]]
    if box[i][j]=="#":
        for x,y in point:
            xx=x+i
            yy=y+j
            if box[xx][yy]=="#" or box[xx][yy]=="O":
                box[i][j]="O"
                seek(box,xx,yy)
    return box

for i in range(1,h+1):
    for j in range(1,w+1):
        seek(box,i,j)

for i in range(1,h+1):
    for j in range(1,w+1):
        if box[i][j]=="#":print("No");exit()

print("Yes")

Buggy submission (verdict: Runtime Error):
import numpy as np
h,w=map(int,input().split())
box=[["."]+list(input())+["."] for i in range(h)]
box.insert(0,["."]*(w+2))
box.append(["."]*(w+2))
count=0
def seek(box,i,j):
    point=[[1,0],[-1,0],[0,1],[0,-1]]
    if box[i][j]=="#":
        for x,y in point:
            xx=x+i
            yy=y+j
            if box[xx][yy]=="#" or box[xx][yy]=="O":
                box[i][j]="O"
                seek(box,xx,yy)
    return box
for i in range(1,h+1):
    for j in range(1,w+1):
        seek(box,i,j)

for i in range(1,h+1):
    for j in range(1,w+1):
        if box[i][j]=="#":print("No");exit()

print("Yes")