Problem p03361 (python)

Fixed submission:
import sys

line_size, row_size = map(int, input().split())
mapmap = []#地図初期化

for i in range(line_size):
    mapmap.append(list(input()))

#探索
def Start_check(mapmap, px, py):
    start_flg = False
    move_x = [1, -1, 0, 0]
    move_y = [0, 0, 1, -1]
    for i in range(4):#動ける範囲で探索
        nx = px + move_x[i]
        ny = py + move_y[i]
        if 0 <= nx and nx < line_size and 0 <= ny and ny < row_size:
            if mapmap[nx][ny] == '#':#もし黒塗りなら
                start_flg = True
    
    if start_flg == False:
        print('No')
        sys.exit()

#Main
count = 0#探索回数（塗り絵した回数）
for i in range(line_size):
    for j in range(row_size):
        if mapmap[i][j] == '#':
            Start_check(mapmap, i, j)
            count += 1

#何もしなかった場合
print('Yes')

Buggy submission (verdict: Runtime Error):
import sys

line_size, row_size = map(int, input().split())
mapmap = []#地図初期化

for i in range(line_size):
    mapmap.append(list(input()))

#探索
def Start_check(mapmap, px, py):
    start_flg = False
    move_x = [1, -1, 0, 0]
    move_y = [0, 0, 1, -1]
    for i in range(len(move_x)):#動ける範囲で探索
        nx = px + move_x[i]
        ny = py + move_y[i]
        if 0 <= nx and nx < line_size and 0 <= ny and ny < row_size:
            if mapmap[nx][ny] == '#':#もし黒塗りなら
                start_flg = True
    
    if start_flg == False:
        print('No')
        sys.exit()

#Main
count = 0#探索回数（塗り絵した回数）
for i in range(line_size):
    for j in range(row_size):
        if mapmap[i][j] == '#':
            Start_check(i, j)
            count += 1

#何もしなかった場合
if count == 0:
    print('No')
else:
    print('Yes')

Buggy submission (verdict: Runtime Error):
import sys

sys.setrecursionlimit(5000)
line_size, row_size = map(int, input().split())
mapmap = []#地図初期化

for i in range(line_size):
    mapmap.append(list(input()))

#探索関数
def Dfs(px, py):
    global mapmap
    #自分のいるところを変換→globalにして更新
    mapmap[py][py] = '.'

    #自分の動けるところ定義
    move_x = [1, -1, 0, 0]
    move_y = [0, 0, 1, -1]
    for i in range(len(move_x)):#動ける範囲で探索
        nx = px + move_x[i]
        ny = py + move_y[i]
        if 0 <= nx and line_size > nx and 0 <= ny and row_size > ny:
            if mapmap[nx][ny] == '#':#もし黒塗りなら
                Dfs(nx, ny)#自分のいるところから突き進むむからfirst in last out
            else:
                return

#開始条件探索
def Start_check(px, py):
    global mapmap
    start_flg = False
    move_x = [1, -1, 0, 0]
    move_y = [0, 0, 1, -1]
    for i in range(len(move_x)):#動ける範囲で探索
        nx = px + move_x[i]
        ny = py + move_y[i]
        if 0 <= nx and line_size > nx and 0 <= ny and row_size > ny:
            if mapmap[nx][ny] == '#':#もし黒塗りなら
                start_flg = True
    
    if start_flg == False:
        print('No')
        sys.exit()

    print(start_flg)

#Main
count = 0#探索回数（塗り絵した回数）
for i in range(line_size):
    for j in range(row_size):
        if mapmap[i][j] == '#':
            Start_check(i, j)
            Dfs(i, j)
            count += 1

#何もしなかった場合
if count == 0:
    print('No')
else:
    print('Yes')

Buggy submission (verdict: Runtime Error):
import sys

#探索
def DFS(mapmap, start_flag = False):
    while 1:
        #はじめの探索
        for i in range(lines):
            for j in range(rows):
                if mapmap[i][j] == '#':
                    start_flag = True
                    break
        #則終了
        if start_flag == False:
            print('No')
            sys.exit()

        startl, startr = i, j
        #動き
        Stack = [[startl, startr]]
        #終了条件
        if mapmap[i+1][j] == '.' and mapmap[i-1][j] == '.' and mapmap[i][j+1] == '.' and mapmap[i][j-1] == '.':
            print('No')
            sys.exit()

        move_x = [1, -1, 0, 0]
        move_y = [0, 0, 1, -1]

        while Stack:
            x, y= Stack.pop()#今現在の位置
            #現在位置を変換
            mapmap[x][y] = '.'

            for i in range(len(move_x)):
                nx = x + move_x[i]
                ny = y + move_y[i]

                if 0 <= nx and nx < lines and 0 <= ny and ny < rows:
                    if mapmap[nx][ny] == '#':
                        Stack.append([nx, ny])
        
#入力管理
lines, rows = map(int, input().split())
mapmap = []

for i in range(lines):
    mapmap.append(list(input()))

DFS(mapmap)

Buggy submission (verdict: Runtime Error):
import sys

#探索
def DFS(mapmap):
    while 1:
        #はじめの探索
        start_flag = False
        for i in range(lines):
            for j in range(rows):
                if mapmap[i][j] == '#':
                    start_flag = True
                    break
        #則終了
        if start_flag == False:
            print('No')
            sys.exit()

        startl, startr = i, j
        #動き
        Stack = [[startl, startr]]

        move_x = [1, -1, 0, 0]
        move_y = [0, 0, 1, -1]

        while Stack:
            x, y= Stack.pop()#今現在の位置
            #現在位置を変換
            mapmap[x][y] = '.'

            for i in range(len(move_x)):
                nx = x + move_x[i]
                ny = y + move_y[i]

                if 0 <= nx and nx < lines and 0 <= ny and ny < rows:
                    if mapmap[nx][ny] == '#':
                        Stack.append([nx, ny])
        
        DFS(mapmap)

#入力管理
lines, rows = map(int, input().split())
mapmap = []

for i in range(lines):
    mapmap.append(list(input()))

DFS(mapmap)

Buggy submission (verdict: Runtime Error):
import sys
#入力管理
lines, rows = map(int, input().split())
mapmap = []

for i in range(lines):
    mapmap.append(list(input()))

start_flag == False
#最初の黒点探し
for i in range(lines):
    for j in range(rows):
        if mapmap[i][j] == '#':
            start_flag = True
            break
#則終了

if start_flag == False:
    print('No')
    sys.exit()

startl, startr = i, j

#動き
move_x = [1, -1, 0, 0]
move_y = [0, 0, 1, -1]
Stack = [[startl, startr]]

#探索開始
while Stack:
   x, y= Stack.pop()#今現在の位置
   #現在位置を変換
   mapmap[x][y] = '.'

   for i in range(len(move_x)):
       nx = x + move_x[i]
       ny = y + move_y[i]

       if 0 <= nx and nx < lines and 0 <= ny and ny < rows:
           if mapmap[nx][ny] == '#':
               Stack.append([nx, ny])


#黒点探し
for i in range(lines):
    for j in range(rows):
        if mapmap[i][j] == '#':
            print('No')
            sys.exit()

print('Yes')

Buggy submission (verdict: Runtime Error):
import sys
#入力管理
lines, rows = map(int, input().split())
mapmap = []

for i in range(lines):
    mapmap.append(list(input()))

#最初の黒点探し
for i in range(lines):
    for j in range(rows):
        if mapmap[i][j] == '#':
            start_flag = True
            break
#則終了

if start_flag == False:
    print('No')
    sys.exit()

startl, startr = i, j

#動き
move_x = [1, -1, 0, 0]
move_y = [0, 0, 1, -1]
Stack = [[startl, startr]]

#探索開始
while Stack:
   x, y= Stack.pop()#今現在の位置
   #現在位置を変換
   mapmap[x][y] = '.'

   for i in range(len(move_x)):
       nx = x + move_x[i]
       ny = y + move_y[i]

       if 0 <= nx and nx < lines and 0 <= ny and ny < rows:
           if mapmap[nx][ny] == '#':
               Stack.append([nx, ny])


#黒点探し
for i in range(lines):
    for j in range(rows):
        if mapmap[i][j] == '#':
            print('No')
            sys.exit()

print('Yes')

Buggy submission (verdict: Runtime Error):
import sys
#入力管理
lines, rows = map(int, input().split())
mapmap = []

for i in range(lines):
    mapmap.append(list(input()))

#最初の黒点探し
for i in range(lines):
    for j in range(rows):
        if mapmap[i][j] == '#':
            break
            
if mapmap[i][j] == '.'    
    print('No')
    sys.exit()

startl, startr = i, j

#動き
move_x = [1, -1, 0, 0]
move_y = [0, 0, 1, -1]
Stack = [[startl, startr]]

#探索開始
while Stack:
   x, y= Stack.pop()#今現在の位置
   #現在位置を変換
   mapmap[x][y] = '.'

   for i in range(len(move_x)):
       nx = x + move_x[i]
       ny = y + move_y[i]

       if 0 <= nx and nx < lines and 0 <= ny and ny < rows:
           if mapmap[nx][ny] == '#':
               Stack.append([nx, ny])


#黒点探し
for i in range(lines):
    for j in range(rows):
        if mapmap[i][j] == '#':
            print('No')
            sys.exit()

print('Yes')