Problem p03361 (python)

Fixed submission:
H, W = map(int, input().split())
graph = []
for _ in range(H):
    graph.append(list(input()))

res = True

for j in range(1, W-1):
    for i in range(1, H-1):
        if graph[i][j] == '#' and graph[i + 1][j] == '.' and graph[i - 1][j] == '.' and graph[i][j + 1] == '.' and graph[i][j - 1] == '.':
            print('No')
            exit()
print('Yes')

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

res = True

for i in range(1, W-1):
    for j in range(1, H-1):
        if graph[i][j] == '#' and graph[i + 1][j] == '.' and graph[i - 1][j] == '.' and graph[i][j + 1] == '.' and graph[i][j - 1] == '.':
            print('No')
            exit()
print('Yes')

Buggy submission (verdict: Runtime Error):
H, W = map(int, input().split())
graph = []

for _ in range(H):
    graph.append(list(list(input())))

res = True

for i in range(1, W-1):
    for j in range(1, H-1):
        if graph[i][j] == '#' and graph[i + 1][j] == '.' and graph[i - 1][j] == '.' and graph[i][j + 1] == '.' and graph[i][j - 1] == '.':
            res = False
            break
    if not res:
        break
print('Yes' if res else 'No')

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

res = True

for i in range(1, W-1):
    for j in range(1, H-1):
        if graph[i][j] == '#' and graph[i + 1][j] == '.' and graph[i - 1][j] == '.' and graph[i][j + 1] == '.' and graph[i][j - 1] == '.':
            res = False
            break
    if not res:
        break
print('Yes' if res else 'No')

Buggy submission (verdict: Runtime Error):
H, W = map(int, input().split())
graph = []
for _ in range(H):
    graph.append([0 if e == '.' else 1 for e in list(input())])

res = True

for i in range(1, W-1):
    for j in range(1, H-1):
        if graph[i][j] == 1 and graph[i + 1][j] == 0 and graph[i - 1][j] == 0 and graph[i][j + 1] == 0 and graph[i][j - 1] == 0:
            res = False
print('Yes' if res else 'No')

Buggy submission (verdict: Runtime Error):
H, W = map(int, input().split())
graph = []
for _ in range(H):
    graph.append([0 if e == '.' else 1 for e in list(input())])

res = True

for i in range(1, W-1):
    for j in range(1, H-1):
        if graph[i][j] == 1 and graph[i + 1][j] == 0 and graph[i - 1][j] and graph[i][j + 1] and graph[i][j - 1]:
            res = False
            break
    if not res:
        break
print('Yes' if res else 'No')

Buggy submission (verdict: Runtime Error):
H, W = map(int, input().split())
graph = []
for _ in range(H):
    graph.append([0 if e == '.' else 1 for e in list(input())])

xx = [-1, 0, 1, 0]
yy = [0, -1, 0, 1]


res = True

for i in range(W):
    for j in range(H):
        if graph[i][j] == 1:
            flag = False
            for idx in range(4):
                nx, ny = i + xx[idx], j + yy[idx]
                if 0 <= nx and nx < W and 0 <= ny and ny < H and graph[nx][ny] == 1:
                    flag = True
                    break
            if not flag:
                res = False
                break
    if not res:
        break

print('Yes' if res else 'No')

Buggy submission (verdict: Runtime Error):
H, W = map(int, input().split())
graph = []
for _ in range(H):
    graph.append([0 if e == '.' else 1 for e in list(input())])

xx = [-1, 0, 1, 0]
yy = [0, -1, 0, 1]


res = True

for i in range(W):
    for j in range(H):
        if graph[i][j] == 1:
            flag = False
            for idx in range(4):
                nx, ny = i + xx[idx], j + yy[idx]
                if 0 <= x and x < W and 0 <= y and y < H and graph[nx][ny] == 1:
                    flag = True
                    break
            if not flag:
                res = False
                break
    if not res:
        break

print('Yes' if res else 'No')

Buggy submission (verdict: Runtime Error):
H, W = map(int, input().split())
graph = []
for _ in range(H):
    graph.append([0 if e == '.' else 1 for e in list(input())])

xx = [-1, 0, 1, 0]
yy = [0, -1, 0, 1]


res = True

for i in range(W):
    for j in range(H):
        if graph[i][j] == 1:
            flag = False
            for idx in range(4):
                nx, ny = i + xx[idx], j + yy[idx]
                if 0 <= x and x < W and 0 <= y and y < H and graph[nx][ny] == 1:
                    flag = True
            if not flag:
                res = False
                break
    if not res:
        break

print('Yes' if res else 'No')

Buggy submission (verdict: Runtime Error):
H, W = map(int, input().split())
graph = []
for _ in range(H):
    graph.append([0 if e == '.' else 1 for e in list(input())])

xx = [-1, 0, 1, 0]
yy = [0, -1, 0, 1]


def isValidTransition(x, y, H, W):
    return 0 <= x and x < W and 0 <= y and y < H

res = True

for i in range(W):
    for j in range(H):
        if graph[i][j] == 1:
            flag = False
            for idx in range(4):
                nx, ny = i + xx[idx], j + yy[idx]
                if isValidTransition(nx, ny, H, W) and graph[nx][ny] == 1:
                    flag = True
            if not flag:
                res = False
                break
    if not res:
        break

print('Yes' if res else 'No')

Buggy submission (verdict: Runtime Error):
H, W = map(int, input().split())
graph = []
for _ in range(H):
    graph.append([0 if e == '.' else 1 for e in list(input())])

xx = [-1, 0, 1, 0]
yy = [0, -1, 0, 1]


def isValidTransition(x, y, H, W):
    return 0 <= x and x < W and 0 <= y and y < H

res = True

for i in range(W):
    for j in range(i, H):
        if graph[i][j] == 1:
            flag = False
            for idx in range(4):
                nx, ny = i + xx[idx], j + yy[idx]
                if isValidTransition(nx, ny, H, W) and graph[nx][ny] == 1:
                    flag = True
            if not flag:
                res = False
                break
    if not res:
        break

print('Yes' if res else 'No')

Buggy submission (verdict: Runtime Error):
H, W = map(int, input().split())
graph = []
for _ in range(H):
    graph.append([0 if e == '.' else 1 for e in list(input())])

xx = [-1, 0, 1, 0]
yy = [0, -1, 0, 1]


def isValidTransition(x, y, H, W):
    return 0 <= x and x < W and 0 <= y and y < H

def dfs(x, y):
    graph[x][y] = 0
    flag = False
    for idx in range(4):
        nx, ny = x + xx[idx], y + yy[idx]
        if isValidTransition(nx, ny, H, W) and graph[nx][ny] == 1:
            dfs(nx, ny)
            flag = True
    return flag

res = True

for i in range(W):
    for j in range(i, H):
        if graph[i][j] == 1 and not dfs(i, j):
            res = False
            break
    if not res:
        break

print('Yes' if res else 'No')