Problem p03361 (python)

Fixed submission:
h, w = map(int, input().split())

s = [input() for _ in range(h)]

ans = 'Yes'

for i in range(1, h-1):
    for j in range(1, w-1):
        if s[i][j] == '#' and s[i-1][j] == '.' and s[i+1][j] == '.' and s[i][j-1] == '.' and s[i][j+1] == '.':
            ans = 'No'

print(ans)

Buggy submission (verdict: Runtime Error):
import sys
h,w=map(int,input().split())
lst=[[0 for i in range(w)]for j in range(h)]
for i in range(h):
  s=input().split()
  for j in range(len(s)):
    if s[j]=='#':
      lst[i][j]=1
if h,w==1,1:
  print('Yes')
  sys.exit()
for j in range(1,h-1):
  for k in range(1,w-1):
    if lst[j][k]==1:
      if lst[j-1][k]!=1 and lst[j+1][k]!=1 and lst[j][k-1]!=1 and lst[j][k+1]!=1:
        print('No')
        sys.exit()
if lst[0][0]==1:
  if lst[0][1]!=1 and lst[1][0]!=1:
    print('No')
    sys.exit()
if lst[h-1][0]==1:
  if lst[h-2][0]!=1 and lst[h-1][1]!=1:
    print('No')
    sys.exit()
if lst[0][k-1]==1:
  if lst[0][k-2]!=1 and lst[1][k-1]!=1:
    print('No')
    sys.exit()
if lst[h-1][k-1]==1:
  if lst[h-1][k-2]!=1 and lst[h-2][k-1]!=1:
    print('No')
    sys.exit()

print('Yes')

Buggy submission (verdict: Runtime Error):
import sys
h,w=map(int,input().split())
lst=[[0 for i in range(w)]for j in range(h)]
for i in range(h):
  s=input().split()
  for j in len(s):
    if s[j]=='#':
      lst[i][j]=1

for j in range(h-2):
  for k in range(w-2):
    if lst[j][k]*lst[j][k+1]==0 and lst[j][k+1]*lst[j][k+2]==0:
      print('No')
      sys.exit()
    if lst[j][k]*lst[j+1][k]==0 and lst[j+1][k]*lst[j+2][k]==0:
      print('No')
      sys.exit()
    
print('Yes')

Buggy submission (verdict: Runtime Error):
import sys
h,w=map(int,input().split())
s=[]
for num in range(h):
  s.append(list(map(int,input().split())))
if w==1:
  if h==1:
    if s[0][0]=='#':
      print('No')
      sys.exit()
  if h==2:
    if (s[0][0]=='#' and s[1][0]=='.') or (s[0][0]=='.' and s[1][0]=='#'):
      print('No')
      sys.exit()  
  else:
    for i in range(h-2):
      if (s[i][0]=='.' and s[i+1][0]=='#' and s[i+2][0]=='.'):
        print('No')
        sys.exit()
if w==2:
  if h==1:
    if (s[0][0]=='.' and s[0][1]=='#') or (s[0][0]=='#' and s[0][1]=='.'):
      print('No')
      sys.exit()  
  else:
    for i in range(h-1):
      if s[i][0]=='.' and s[i][1]=='#':
        if s[i+1][1]=='.':
          print('No')
          sys.exit()
      if s[i][0]=='#' and s[i][1]=='.':
        if s[i+1][0]=='.':
          print('No')
          sys.exit()     
for i in range(h):
  for j in range(w-2):
    if s[i][j]=='.' and s[i][j+1]=='#' and s[i][j+2]=='.':
      if s[i][j+1]=='.':
        print('No')
        sys.exit()
    if s[i][0]=='#' and s[i][1]=='.':
      if s[min(h-1,i+1)][0]=='.':
        print('No')
        sys.exit()
    if s[i][w-2]=='.' and s[i][w-1]=='#':
      if s[min(h-1,i+1)][w-1]=='.':
        print('No')
        sys.exit()
print('Yes')

Buggy submission (verdict: Runtime Error):
import sys
h,w=map(int,input().split())
s=[]
for num in range(h):
  s.append(list(map(int,input().split())))
if w==1:
  if h==1:
    if s[0]=='#':
      print('No')
      sys.exit()
  else:
    for i in range(h-1):
      if (s[i][0]=='#' and s[i+1][0]=='.') or (s[i][0]=='.' and s[i+1][0]=='#'):
        print('No')
        sys.exit()
if w==2:
  if h==1:
    if (s[0][0]=='.' and s[0][1]=='#') or (s[0][0]=='#' and s[0][1]=='.'):
      print('No')
      sys.exit()  
  else:
    for i in range(h-1):
      if s[i][0]=='.' and s[i][1]=='#':
        if s[i+1][1]=='.':
          print('No')
          sys.exit()
      if s[i][0]=='#' and s[i][1]=='.':
        if s[i+1][0]=='.':
          print('No')
          sys.exit()     
for i in range(h):
  for j in range(w-2):
    if s[i][j]=='.' and s[i][j+1]=='#' and s[i][j+2]=='.':
      if s[i][j+1]=='.':
        print('No')
        sys.exit()
    if s[i][0]=='#' and s[i][1]=='.':
      if s[min(h-1,i+1)][0]=='.':
        print('No')
        sys.exit()
    if s[i][w-2]=='.' and s[i][w-1]=='#':
      if s[min(h-1,i+1)][w-1]=='.':
        print('No')
        sys.exit()
print('Yes')

Buggy submission (verdict: Runtime Error):
import sys
h,w=map(int,input().split())
s=[]
for num in range(h):
  s.append(list(map(int,input().split())))
if w==1 and h==1:
  if s[0]=='#':
    print('No')
    sys.exit()
if w==2 and h==1:
  if (s[0][0]=='.' and s[0][1]=='#') or (s[0][0]=='#' and s[0][1]=='.'):
    print('No')
    sys.exit()  
for i in range(h):
  for j in range(w-2):
    if s[i][j]=='.' and s[i][j+1]=='#' and s[i][j+2]=='.':
      if s[i][j+1]=='.':
        print('No')
        sys.exit()
    if s[i][0]=='#' and s[i][1]=='.':
      if s[min(h-1,i+1)][0]=='.':
        print('No')
        sys.exit()
    if s[i][w-2]=='.' and s[i][w-1]=='#':
      if s[min(h-1,i+1)][w-1]=='.':
        print('No')
        sys.exit()
print('Yes')

Buggy submission (verdict: Runtime Error):
import sys
h,w=map(int,input().split())
s=[]
for i in range(h):
  s.append(list(map(int,input().split())))
for i in range(h):
  for j in range(w-2):
    if s[i][j]=='.' and s[i][j+1]=='#' and s[i][j+2]=='.':
      if s[i][j+1]=='.':
        print('No')
        sys.exit()
    if s[i][0]=='#' and s[i][1]=='.':
      if s[min(h-1,i+1)][0]=='.':
        print('No')
        sys.exit()
    if s[i][w-2]=='.' and s[i][w-1]=='#':
      if s[min(h-1,i+1)][w-1]=='.':
        print('No')
        sys.exit()
print('Yes')