Problem p03361 (python)

Fixed submission:
H,W = map(int, input().split())
s = []
answer = "Yes"

for i in range(H):
    s.append(str(input()))

for i in range(H):
    for j in range(W):
        if s[i][j] == "#":
            if j != 0 and s[i][j-1] == ".":
                if j+1 != W and s[i][j+1] == ".":
                    if i != 0 and s[i-1][j] == ".":
                        if i+1 != H and s[i+1][j] == ".":
                            answer ="No"

print(answer)

Buggy submission (verdict: Runtime Error):
h, w = map(int,input().split())
grids = []
for i in range(h):
    grids.append(input())
    
start = []
for i in range(len(grids)):
    if "#" in grids[i]:
        start = [i, grids[i].index("#")]
        break

if len(start) == 0:
    print("No")
    quit

queue = [start]
check = [start]
ans = "No"
while len(queue) != 0:
    x, y = queue[0][0], queue[0][1]
    queue.pop(0)

    if x > 0:
        if grids[x-1][y] == "#" and [x-1, y] not in check:
            queue.append([x-1, y])
            check.append([x-1, y])
    if x < h-1:
        if grids[x+1][y] == "#" and [x+1, y] not in check:
            queue.append([x+1, y])
            check.append([x+1, y])
    if y > 0:
        if grids[x][y-1] == "#" and [x, y-1] not in check:
            queue.append([x, y-1])
            check.append([x, y-1])
    if y < w-1:
        if grids[x][y+1] == "#" and [x, y+1] not in check:
            queue.append([x, y+1])
            check.append([x, y+1])

cnt = 0
for grid in grids:
    cnt += grid.count("#")
    
if cnt == len(check):
    ans = "Yes"
print(ans)

Buggy submission (verdict: Runtime Error):
h, w = map(int,input().split())
grids = []
for i in range(h):
    grids.append(input())
    
start = []
for i in range(len(grids)):
    if "#" in grids[i]:
        start = [i, grids[i].index("#")]
        break

if len(start) == 0:
    quit

queue = [start]
check = [start]
ans = "No"
while len(queue) != 0:
    x, y = queue[0][0], queue[0][1]
    queue.pop(0)

    if x > 0:
        if grids[x-1][y] == "#" and [x-1, y] not in check:
            queue.append([x-1, y])
            check.append([x-1, y])
    if x < h-1:
        if grids[x+1][y] == "#" and [x+1, y] not in check:
            queue.append([x+1, y])
            check.append([x+1, y])
    if y > 0:
        if grids[x][y-1] == "#" and [x, y-1] not in check:
            queue.append([x, y-1])
            check.append([x, y-1])
    if y < w-1:
        if grids[x][y+1] == "#" and [x, y+1] not in check:
            queue.append([x, y+1])
            check.append([x, y+1])

cnt = 0
for grid in grids:
    cnt += grid.count("#")
    
if cnt == len(check):
    ans = "Yes"
print(ans)

Buggy submission (verdict: Runtime Error):
h, w = map(int,input().split())
grids = []
for i in range(h):
    grids.append(input())
    
start = []
for i in range(len(grids)):
    if "@" in grids[i]:
        start = [i, grids[i].index("#")]

if len(start) == 0:
    quit
    
queue = [start]
check = []
ans = "No"
while len(queue) != 0:
    x, y = queue[0][0], queue[0][1]
    queue.pop(0)

    if x > 0:
        if grids[x-1][y] == "#" and [x-1, y] not in check:
            queue.append([x-1, y])
            check.append([x-1, y])
    if x < h-1:
        if grids[x+1][y] == "#" and [x+1, y] not in check:
            queue.append([x+1, y])
            check.append([x+1, y])
    if y > 0:
        if grids[x][y-1] == "#" and [x, y-1] not in check:
            queue.append([x, y-1])
            check.append([x, y-1])
    if y < w-1:
        if grids[x][y+1] == "#" and [x, y+1] not in check:
            queue.append([x, y+1])
            check.append([x, y+1])

cnt = 0
for grid in grids:
    cnt += grid.count("#")
    
if cnt == len(check):
    ans = "Yes"
print(ans)

Buggy submission (verdict: Runtime Error):
h, w = map(int,input().split())
grids = []
for i in range(h):
    grids.append(input())
    
start = []
for i in range(len(grids)):
    if "@" in grids[i]:
        start = [i, grids[i].index("@")]

if len(start) == 0:
    quit
    
queue = [start]
check = []
ans = "No"
while len(queue) != 0:
    x, y = queue[0][0], queue[0][1]
    queue.pop(0)

    if x > 0:
        if grids[x-1][y] == "#" and [x-1, y] not in check:
            queue.append([x-1, y])
            check.append([x-1, y])
    if x < h-1:
        if grids[x+1][y] == "#" and [x+1, y] not in check:
            queue.append([x+1, y])
            check.append([x+1, y])
    if y > 0:
        if grids[x][y-1] == "#" and [x, y-1] not in check:
            queue.append([x, y-1])
            check.append([x, y-1])
    if y < w-1:
        if grids[x][y+1] == "#" and [x, y+1] not in check:
            queue.append([x, y+1])
            check.append([x, y+1])

cnt = 0
for grid in grids:
    cnt += grid.count("#")
    
if cnt == len(check):
    ans = "Yes"
print(ans)