Problem p03361 (python)

Fixed submission:
H, W = map(int, input().split())
a = []
tmp = []
for i in range(H):
    tmp = list(map(str,input().split()))
    a.append(list(tmp[0]))

for i in range(H):
    for j in range(W):
        if a[i][j] == '#':
            if j - 1 >= 0 and a[i][j - 1] == "#":
                continue
            elif j + 1 < W and a[i][j + 1] == "#" :
                continue
            elif i + 1 < H and a[i + 1][j] == "#" :
                continue
            elif i - 1 >= 0 and a[i - 1][j] == "#":
                continue
            else:
                print("No")
                exit()
 
print("Yes")

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
a = []
tmp = []
for i in range(N):
    tmp = list(map(str,input().split()))
    a.append(list(tmp[0]))

for i in range(1,N):
    for j in range(1,M):
        if a[i][j] == '#':
            if a[i][j - 1] != '#' and a[i - 1][j] != '#' and a[i][j + 1] != '#' and a[i + 1][j] != '#':
                print("No")
                exit()
        else:
            pass

print("Yes")

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
a = []
tmp = []
for i in range(N):
    tmp = list(map(str,input().split()))
    a.append(list(tmp[0]))

for i in range(1,N+1):
    for j in range(1,M+1):
        if a[i][j] == '#':
            if a[i][j - 1] != '#' and a[i - 1][j] != '#' and a[i][j + 1] != '#' and a[i + 1][j] != '#':
                print("No")
                exit()
        else:
            pass

print("Yes")

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
a = []
tmp = []
for i in range(N):
    tmp = list(map(str,input().split()))
    a.append(list(tmp[0]))

for i in range(N):
    for j in range(M):
        if a[i][j] == '#':
            if a[i][j - 1] != '#' and a[i - 1][j] != '#' and a[i][j + 1] != '#' and a[i + 1][j] != '#':
                print("No")
                exit()
        else:
            pass

print("Yes")

Buggy submission (verdict: Runtime Error):
import sys
 
N, M = map(int, input().split())
a = []
tmp = []
for i in range(N):
    tmp = list(map(str,input().split()))
    a.append(list(tmp[0]))

for i in range(N):
    for j in range(M):
        if a[i][j] == '#':
            if a[i][j - 1] != '#' and a[i - 1][j] != '#' and a[i][j + 1] != '#' and a[i + 1][j] != '#':
                print("No")
                sys.exit(0)
        else:
            pass

print("Yes")

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
a = []
tmp = []
for i in range(M):
    tmp = list(map(str,input().split()))
    a.append(list(tmp[0]))

Buggy submission (verdict: Runtime Error):
import sys
 
N, M = map(int, input().split())
a = []
tmp = []
for i in range(M):
    tmp = list(map(str,input().split()))
    a.append(list(tmp[0]))
 
 
cpi = [-1,0,0,1]
cpj = [0,-1,1,0]
 
smFlag = False
 
for i in range(N):
    for j in range(M):
        if a[i][j] == '#':
            for x,y in zip(cpi,cpj):
                if N > i + x > -1 and M > j + y > -1:
                    if a[i+x][j+y] == '#':
                        smFlag = True
            if not smFlag:
                print('No')
                sys.exit()
 
print('Yes')

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
a = []
tmp = []
for i in range(M):
    tmp = list(map(str,input().split()))
    a.append(list(tmp[0]))


cpi = [-1,0,0,1]
cpj = [0,-1,1,0]

smFlag = False
result = True

for i in range(N):
    for j in range(M):
        if a[i][j] == '#':
            for x,y in zip(cpi,cpj):
                if i + x > -1 and j + y > -1 and i + x < N  and j + y < M:
                    if a[i+x][j+y] == '#':
                        smFlag = True
            if not smFlag:
                print('No')
                result = False

if result:
    print('Yes')

Buggy submission (verdict: Runtime Error):
import sys

N, M = map(int, input().split())
a = []
tmp = []
for i in range(M):
    tmp = list(map(str,input().split()))
    a.append(list(tmp[0]))


cpi = [-1,0,0,1]
cpj = [0,-1,1,0]

smFlag = False

for i in range(N):
    for j in range(M):
        if a[i][j] == '#':
            for x,y in zip(cpi,cpj):
                if i + x > -1 and j + y > -1 and i + x < N  and j + y < M:
                    if a[i+x][j+y] == '#':
                        smFlag = True
            if not smFlag:
                print('No')
                sys.exit()

print('Yes')