Problem p03361 (python)

Fixed submission:
H,W = map(int,input().split())
L = [input() for i in range(H)]
dxy = [[1,0],[-1,0],[0,1],[0,-1]]
flag = 1

for y in range(H) :
    for x in range(W) :
        if L[y][x] == "#" and flag == 1 :
            for dx,dy in dxy :
                nx = x+dx
                ny = y+dy
                if (0 <= nx <= W-1) and (0 <= ny <= H-1) :
                    if L[ny][nx] == "#" :
                        flag = 1
                        break
                    else :
                        flag = 0
if flag == 1 :
    print("Yes")
else :
    print("No")

Buggy submission (verdict: Runtime Error):
H,W = map(int,input().split())
L = [input() for i in range(H)]
dxy = [[1,0],[-1,0],[0,1],[0,-1]]
flag = 0
for y in range(H) :
    for x in range(W) :
        if L[y][x] == "#" :
            for dx,dy in dxy :
                nx = x+dx
                ny = y+dy
                if (0 <= nx <= W-1) and (0 <= ny <= H-1) :
                    if L[nx][ny] == "#" :
                        flag = 1
                        break
                    else :
                        flag = 0
if flag == 1 :
    print("Yes")
else :
    print("No")

Buggy submission (verdict: Runtime Error):
H,W = map(int,input().split())
L = []
for i in range(H) :
    L.append(list(input()))

dxy = [(1,0),(-1,0),(0,1),(0,-1)]

flag = 0
for x in range(W) :
    for y in range(H) :
        if L[x][y] == "#" :
            for dx,dy in dxy :
                nx = x+dx
                ny = y+dy
                if (0 <= nx <= W-1) and (0 <= ny <= H-1) :
                    if L[nx][ny] == "#" :
                        flag = 0
                        
                        break
                    flag = 1
                else :
                    continue

if flag != 1 :
    print("Yes")
else :
    print("No")

Buggy submission (verdict: Runtime Error):
H,W = map(int,input().split())
L = []
for i in range(H) :
    L.append(list(input()))
flag = 0
if H == 1 :
    if W == 1 :
        if L[H][W] != "#" :
            flag = 1
    else :
        if L[i][j] == "#" :
            if j == 0 :
                if L[i][j+1] != "#" :
                    flag = 1
            elif j == W-1 :
                if L[i][j-1] != "#" :
                    flag = 1
            else :
                if (L[i][j+1] != "#") and (L[i][j-1] != "#") :
                    flag = 1
else :
    for i in range(H) :
        for j in range(W) :
            if L[i][j] == "#" :
                if j == 0 :
                    if i == 0 :
                        if (L[i+1][j] != "#") and (L[i][j+1] != "#") :
                            flag = 1
                    elif i == (W-1) :
                        if (L[i-1][j] != "#") and (L[i][j+1] != "#") :
                            flag = 1
                    else :
                        if (L[i-1][j] != "#") and (L[i][j+1] != "#") and (L[i+1][j] != "#") :
                            flag = 1
                elif j == (H-1) :
                    if i == 0 :
                        if (L[i+1][j] != "#") and (L[i][j-1] != "#") :
                            flag = 1
                    elif i == (W-1) :
                        if (L[i-1][j] != "#") and (L[i][j-1] != "#") :
                            flag = 1
                    else :
                        if (L[i-1][j] != "#") and (L[i][j-1] != "#") and (L[i+1][j] != "#") :
                            flag = 1
                else :
                    if i == 0 :
                        if (L[i+1][j] != "#") and (L[i][j+1] != "#") and (L[i][j-1] != "#") :
                            flag = 1
                    elif i == (W-1) :
                        if (L[i-1][j] != "#") and (L[i][j+1] != "#") and (L[i][j-1] != "#") :
                            flag = 1
                    else :
                        if (L[i-1][j] != "#") and (L[i][j+1] != "#") and (L[i+1][j] != "#") and (L[i][j-1] != "#") :
                            flag = 1
            if flag == 1 :
                break
        if flag == 1 :
            break
if flag == 0 :
    print("Yes")
else :
    print("No")

Buggy submission (verdict: Runtime Error):
H,W = map(int,input().split())
L = []
for i in range(H) :
    L.append(list(input()))
flag = 0
for i in range(H) :
    for j in range(W) :
        if L[i][j] == "#" :
            if j == 0 :
                if i == 0 :
                    if (L[i+1][j] != "#") and (L[i][j+1] != "#") :
                        flag = 1
                elif i == (W-1) :
                    if (L[i-1][j] != "#") and (L[i][j+1] != "#") :
                        flag = 1
                else :
                    if (L[i-1][j] != "#") and (L[i][j+1] != "#") and (L[i+1][j] != "#") :
                        flag = 1
            elif j == (H-1) :
                if i == 0 :
                    if (L[i+1][j] != "#") and (L[i][j-1] != "#") :
                        flag = 1
                elif i == (W-1) :
                    if (L[i-1][j] != "#") and (L[i][j-1] != "#") :
                        flag = 1
                else :
                    if (L[i-1][j] != "#") and (L[i][j-1] != "#") and (L[i+1][j] != "#") :
                        flag = 1
            else :
                if i == 0 :
                    if (L[i+1][j] != "#") and (L[i][j+1] != "#") and (L[i][j-1] != "#") :
                        flag = 1
                elif i == (W-1) :
                    if (L[i-1][j] != "#") and (L[i][j+1] != "#") and (L[i][j-1] != "#") :
                        flag = 1
                else :
                    if (L[i-1][j] != "#") and (L[i][j+1] != "#") and (L[i+1][j] != "#") and (L[i-1][j] != "#") :
                        flag = 1
        if flag == 1 :
            break
    if flag == 1 :
        break
if flag == 0 :
    print("Yes")
else :
    print("No")