Problem:


Score: 300 points

Problem Statement

We have a canvas divided into a grid with H rows and W columns. The square at the i-th row from the top and the j-th column from the left is represented as (i, j).

Initially, all the squares are white. square1001 wants to draw a picture with black paint. His specific objective is to make Square (i, j) black when s_{i, j}= #, and to make Square (i, j) white when s_{i, j}= ..

However, since he is not a good painter, he can only choose two squares that are horizontally or vertically adjacent and paint those squares black, for some number of times (possibly zero). He may choose squares that are already painted black, in which case the color of those squares remain black.

Determine if square1001 can achieve his objective.  

Constraints

H is an integer between 1 and 50 (inclusive).

W is an integer between 1 and 50 (inclusive).

For every (i, j) (1 \leq i \leq H, 1 \leq j \leq W), s_{i, j} is # or ..

Input

Input is given from Standard Input in the following format:

H W
s_{1, 1} s_{1, 2} s_{1, 3} ... s_{1, W}
s_{2, 1} s_{2, 2} s_{2, 3} ... s_{2, W}
  :   :
s_{H, 1} s_{H, 2} s_{H, 3} ... s_{H, W}

Output

If square1001 can achieve his objective, print Yes; if he cannot, print No.

Sample Input 1

3 3
.#.
###
.#.

Sample Output 1

Yes

One possible way to achieve the objective is shown in the figure below. Here, the squares being painted are marked by stars.

Sample Input 2

5 5
#.#.#
.#.#.
#.#.#
.#.#.
#.#.#

Sample Output 2

No

square1001 cannot achieve his objective here.

Sample Input 3

11 11
...#####...
.##.....##.
#..##.##..#
#..##.##..#
#.........#
#...###...#
.#########.
.#.#.#.#.#.
##.#.#.#.##
..##.#.##..
.##..#..##.

Sample Output 3

Yes



Sample input:
3 3
.#.
###
.#.


Sample output:
Yes

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
arr = [list(input()) for i in range(N)]
newmat = [[0 for i in range(M)] for j in range(N)]
nocheck = 0
for i in range(N):
    for j in range(M):
        if arr[i][j] is '#':
            newmat[i][j] = 1
        else:
            newmat[i][j] = 0

for i in range(N):
    for j in range(M):
        if newmat[i][j] == 1:
            if i == 0 and j == 0:
                if newmat[i][j+1] == 0 and newmat[i+1][j] == 0:
                    nocheck = 1
                    break
            elif i == 0 and j == (M-1):
                if newmat[i][j-1] == 0 and newmat[i+1][j] == 0:
                    nocheck = 1
                    break
            elif i == (N-1) and j == 0:
                if newmat[i][j+1] == 0 and newmat[i-1][j] == 0:
                    nocheck = 1
                    break
            elif i == (N-1) and j == (M-1):
                if newmat[i][j-1] == 0 and newmat[i-1][j] == 0:
                    nocheck = 1
                    break
            elif i == 0 and j != 0:
                if newmat[i][j+1] == 0 and newmat[i+1][j] == 0 and newmat[i][j-1] == 0:
                    nocheck = 1
                    break
            elif i != 0 and j == 0:
                if newmat[i][j + 1] == 0 and newmat[i + 1][j] == 0 and newmat[i-1][j] == 0:
                    nocheck = 1
                    break
            elif i == (N-1) and j != (M-1):
                if newmat[i][j+1] == 0 and newmat[i-1][j] == 0 and newmat[i][j-1] == 0:
                    nocheck = 1
                    break
            elif i != (N-1) and j == (M-1):
                if newmat[i-1][j] == 0 and newmat[i+1][j] == 0 and newmat[i][j-1] == 0:
                    nocheck = 1
                    break

            else:
                if newmat[i][j + 1] == 0 and newmat[i + 1][j] == 0 and newmat[i][j - 1] == 0 and newmat[i-1][j]:
                    nocheck = 1

if(nocheck == 0):
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
h, w = map(int, input().split())

def conv_e_2_num(x):
    return 1 if x == "#" else 0

def is_painted(masu, x, y):
    return masu[y][x] == 1

def check_lrtb(masu, x, y, w, h):
    return (x - 1 > 0 and is_painted(masu, x - 1, y)) \
        or (x + 1 < w and is_painted(masu, x + 1, y)) \
        or (y - 1 > 0 and is_painted(masu, x, y - 1)) \
        or (y + 1 < h and is_painted(masu, x, y + 1)) \

def check_all(masu, w, h):
    if w == h and w == 1:
        return True
    for y in range(h):
        for x in range(w):
            if is_painted(masu, x, y):
                if check_lrtb(masu, x, y, w, h):
                    continue
                else:
                    return False
    return True


masu = []
for y in range(h):
    masu.append(list(map(conv_e_2_num, list(input()))))

print('Yes') if check_all(masu, w, h) else print('No')

Submission status: Wrong Answer

Solution code:
h, w = map(int, input().split())

def conv_e_2_num(x):
    return 1 if x == "#" else 0

def is_painted(masu, x, y):
    return masu[y][x] == 1

def check_lrtb(masu, x, y, w, h):
    return (x - 1 > 0 and is_painted(masu, x - 1, y)) \
        or (x + 1 < w and is_painted(masu, x + 1, y)) \
        or (y - 1 > 0 and is_painted(masu, x, y - 1)) \
        or (y + 1 < h and is_painted(masu, x, y + 1)) \

def check_all(masu, w, h):
    for y in range(h):
        for x in range(w):
            if is_painted(masu, x, y):
                if check_lrtb(masu, x, y, w, h):
                    continue
                else:
                    return False
    return True


masu = []
for y in range(h):
    masu.append(list(map(conv_e_2_num, list(input()))))

print('Yes') if check_all(masu, w, h) else print('No')

Submission status: Wrong Answer

Solution code:
h, w = map(int, input().split())

def conv_e_2_num(x):
    return 1 if x == "#" else 0

def is_painted(masu, x, y):
    return masu[y][x] == 1

def check_lrtb(masu, x, y, w, h):
    return x - 1 > 0 and is_painted(masu, x - 1, y) \
        or x + 1 < w and is_painted(masu, x + 1, y) \
        or y - 1 > 0 and is_painted(masu, x, y - 1) \
        or y + 1 < h and is_painted(masu, x, y + 1) \

def check_all(masu, w, h):
    for y in range(h):
        for x in range(w):
            if is_painted(masu, x, y):
                if check_lrtb(masu, x, y, w, h):
                    continue
                else:
                    return False
    return True


masu = []
for y in range(h):
    masu.append(list(map(conv_e_2_num, list(input()))))

print('Yes') if check_all(masu, w, h) else print('No')

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())
grid = []
for i in range(0,H):
    grid.append(list(input().split()))
ans = "Yes"
for i in range(0,H):
    line = grid[i][0].split(".")
    if "#" in line:
        index = line.index("#")
        if i == 0 or i == H-1:
            continue
        previous = grid[i-1]
        next = grid[i+1]
        if next[0][index] == "." and previous[0][index] == ".":
            ans = "No"
            break
print(ans)

Submission status: Wrong Answer

Solution code:
import sys

H, W = map(int, input().split())
str = [input() for _ in range(H)]

for h in range(H):
  for w in range(W):
    if str[h][w] == "#":
      if h>0: 
        if str[h-1][w] == "#" : break;
      if h<H-1: 
        if str[h+1][w] == "#" : break;
      if w>0:
        if str[h][w-1] == "#" : break;
      if w<W-1:
        if str[h][w+1] == "#" : break;
      print("No")
      sys.exit()
print("Yes")

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
H, W = map(int, input().split())
inputs = [input() for _ in range(H)]
canvas = [char for char in inputs]


def isSpace(canvas, i, j):
    if i in range(len(canvas)):
        if j in range(len(canvas[i])):
            return True if canvas[i][j] == "." else False
        else:
            return True
    else:
        return True


def isPaintableCanvasBySquare(canvas):
    H = len(canvas)
    W = len(canvas[0])
    for i, j in [(i, j) for i in range(H) for j in range(W)]:
        if(isSpace(canvas, i, j - 1) and
           isSpace(canvas, i, j + 1) and
           isSpace(canvas, i - 1, j) and
           isSpace(canvas, i + 1, j) and
           not isSpace(canvas, i, j)):
            return "No"
    return "Yes"


isPaintableCanvasBySquare(canvas)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
H, W = map(int, input().split())
inputs = [input() for _ in range(H)]
canvas = [char for char in inputs]


def isSpace(canvas, i, j):
    if i in range(len(canvas)):
        if j in range(len(canvas[i])):
            return True if canvas[i][j] == "." else False
        else:
            return True
    else:
        return True


def isPaintableCanvasBySquare(canvas):
    H = len(canvas)
    W = len(canvas[0])
    for i, j in [(i, j) for i in range(H) for j in range(W)]:
        if(isSpace(canvas, i, j - 1) and
           isSpace(canvas, i, j + 1) and
           isSpace(canvas, i - 1, j) and
           isSpace(canvas, i + 1, j) and
           not isSpace(canvas, i, j)):
            return False
    return True


isPaintableCanvasBySquare(canvas)

Submission status: Wrong Answer

Solution code:
def is_not_isolated(s_list, i, j):
    num_row, num_col = len(s_list), len(s_list[0])
    map_char_to_bool = {'.': False, '#': True}
    if num_row == 1 and num_col == 1:
        return False
    elif num_row == 1:
        if j == 0:
            not_isolated = map_char_to_bool[s_list[0][1]]
        elif j == num_col - 1:
            not_isolated = map_char_to_bool[s_list[0][num_col - 2]]
        else:
            not_isolated = map_char_to_bool[s_list[0][j - 1]]\
                        or map_char_to_bool[s_list[0][j + 1]]
    elif num_col == 1:
        if i == 0:
            not_isolated = map_char_to_bool[s_list[1][0]]
        elif i == num_row - 1:
            not_isolated = map_char_to_bool[s_list[num_row - 2][0]]
        else:
            not_isolated = map_char_to_bool[s_list[i - 1][0]]\
                        or map_char_to_bool[s_list[i + 1][0]]
    else:
        # assuming num_row >= 2 and num_col >= 2
        if i == 0 and j == 0:
            not_isolated = map_char_to_bool[s_list[0][1]]\
                        or map_char_to_bool[s_list[1][0]]
        elif i == 0 and j == num_col - 1:
            not_isolated = map_char_to_bool[s_list[0][num_col - 2]]\
                        or map_char_to_bool[s_list[1][num_col - 1]]
        elif i == num_row - 1 and j == 0:
            not_isolated = map_char_to_bool[s_list[num_row - 2][0]]\
                        or map_char_to_bool[s_list[num_row - 1][1]]
        elif i == num_row - 1 and j == num_col - 1:
            not_isolated = map_char_to_bool[s_list[num_row - 2][num_col - 1]]\
                        or map_char_to_bool[s_list[num_row - 1][num_col - 2]]
        elif i == 0:
            not_isolated = map_char_to_bool[s_list[0][j - 1]]\
                        or map_char_to_bool[s_list[0][j + 1]]\
                        or map_char_to_bool[s_list[1][j]]
        elif i == num_row - 1:
            not_isolated = map_char_to_bool[s_list[num_row - 1][j - 1]]\
                        or map_char_to_bool[s_list[num_row - 1][j + 1]]\
                        or map_char_to_bool[s_list[num_row - 2][j]]
        elif j == 0:
            not_isolated = map_char_to_bool[s_list[i - 1][0]]\
                        or map_char_to_bool[s_list[i + 1][0]]\
                        or map_char_to_bool[s_list[i][1]]
        elif j == num_col - 1:
            not_isolated = map_char_to_bool[s_list[i - 1][num_col - 1]]\
                        or map_char_to_bool[s_list[i + 1][num_col - 1]]\
                        or map_char_to_bool[s_list[i][num_col - 2]]
        else:
            not_isolated = map_char_to_bool[s_list[i][j - 1]]\
                        or map_char_to_bool[s_list[i][j + 1]]\
                        or map_char_to_bool[s_list[i + 1][j]]\
                        or map_char_to_bool[s_list[i + 1][j]]

    return not_isolated


H, W = [int(elem) for elem in input().split(' ')]
s_list = [list(input()) for _ in range(H)]
assert len(s_list) == H
assert len(s_list[0]) == W

if H == 1 and W == 1:
    if s_list[0][0] == ".":
        print("Yes")
        exit(0)
    else:
        print("No")
        exit(0)

for i in range(len(s_list)):
    for j in range(len(s_list[0])):
        if s_list[i][j] == ".":
            continue
        else:
            if not is_not_isolated(s_list, i, j):
                print("No")
                exit(0)
else:
    print("Yes")

Submission status: Wrong Answer

Solution code:
def is_not_isolated(s_list, i, j):
    num_row, num_col = len(s_list), len(s_list[0])
    map_char_to_bool = {'.': False, '#': True}
    if num_row == 1 and num_col == 1:
        return False
    elif num_row == 1:
        if j == 0:
            not_isolated = map_char_to_bool[s_list[0][1]]
        elif j == num_col - 1:
            not_isolated = map_char_to_bool[s_list[0][num_col - 2]]
        else:
            not_isolated = map_char_to_bool[s_list[0][j - 1]]\
                    or map_char_to_bool[s_list[0][j + 1]]
    elif num_col == 1:
        if i == 0:
            not_isolated = map_char_to_bool[s_list[1][0]]
        elif i == num_row - 1:
            not_isolated = map_char_to_bool[s_list[num_row - 2][0]]
        else:
            not_isolated = map_char_to_bool[s_list[i - 1][0]]\
                    or map_char_to_bool[s_list[i + 1][0]]
    else:
        # assuming num_row >= 2 and num_col >= 2
        if i == 0 and j == 0:
            not_isolated = map_char_to_bool[s_list[0][1]]\
                    or map_char_to_bool[s_list[1][0]]
        elif i == 0 and j == num_col - 1:
            not_isolated = map_char_to_bool[s_list[0][num_col - 2]]\
                    or map_char_to_bool[s_list[1][num_col - 1]]
        elif i == num_row - 1 and j == 0:
            not_isolated = map_char_to_bool[s_list[num_row - 2][0]]\
                    or map_char_to_bool[s_list[num_row - 1][1]]
        elif i == num_row - 1 and j == num_col - 1:
            not_isolated = map_char_to_bool[s_list[num_row - 2][num_col - 1]]\
                    or map_char_to_bool[s_list[num_row - 1][num_col - 2]]
        elif i == 0:
            not_isolated = map_char_to_bool[s_list[0][j - 1]]\
                    or map_char_to_bool[s_list[0][j + 1]]\
                    or map_char_to_bool[s_list[1][j]]
        elif i == num_row - 1:
            not_isolated = map_char_to_bool[s_list[num_row - 1][j - 1]]\
                    or map_char_to_bool[s_list[num_row - 1][j + 1]]\
                    or map_char_to_bool[s_list[num_row - 2][j]]
        elif j == 0:
            not_isolated = map_char_to_bool[s_list[i - 1][0]]\
                    or map_char_to_bool[s_list[i + 1][0]]\
                    or map_char_to_bool[s_list[i][1]]
        elif j == num_col - 1:
            not_isolated = map_char_to_bool[s_list[i - 1][num_col - 1]]\
                    or map_char_to_bool[s_list[i + 1][num_col - 1]]\
                    or map_char_to_bool[s_list[i][num_col - 2]]
        else:
            not_isolated = map_char_to_bool[s_list[i][j - 1]]\
                    or map_char_to_bool[s_list[i][j + 1]]\
                    or map_char_to_bool[s_list[i + 1][j]]\
                    or map_char_to_bool[s_list[i + 1][j]]

    return not_isolated


H, W = [int(elem) for elem in input().split(' ')]
s_list = [list(input()) for _ in range(H)]
assert len(s_list) == H
assert len(s_list[0]) == W

for i in range(len(s_list)):
    for j in range(len(s_list[0])):
        if s_list[i][j] == ".":
            continue
        else:
            if not is_not_isolated(s_list, i, j):
                print("No")
                exit(0)
else:
    print("Yes")

Submission status: Wrong Answer

Solution code:
h,w = map(int, input().split())
k = [list(input()) for i in range(h)]

ans = True
for i in range(0,h-1):
    for j in range(0,w-1):
        if k[i][j] == "#" and k[i-1][j] =="." and k[i][j-1] =="." and k[i+1][j] =="." and k[i][j+1] =="." :
            ans = True

if ans:
    print('Yes')

else:
    print('No')

Submission status: Wrong Answer

Solution code:
h,w = map(int, input().split())
k = [list(input()) for i in range(h)]

ans = True
for i in range(1,h-1):
    for j in range(1,w-1):
        if k[i][j] == "#" and k[i-1][j] =="." and k[i][j-1] =="." and k[i+1][j] =="." and k[i][j+1] =="." :
            ans = True

if ans:
    print('Yes')

else:
    print('No')

Submission status: Wrong Answer

Solution code:
h,w = map(int, input().split())
k = [list(input()) for i in range(h)]

ans = True
for i in range(1,h-2):
    for j in range(1,w-2):
        if k[i][j] == "#" and k[i-1][j] =="." and k[i][j-1] =="." and k[i+1][j] =="." and k[i][j+1] =="." :
            ans = True

if ans:
    print('Yes')

else:
    print('No')

Submission status: Wrong Answer

Solution code:
h, w = map(int, input().split())
S = []
flag = True
for i in range(h):
    r = list(input())
    S.append(r)
for i in range(0,h-1):
    for j in range(0,w-1):
        if S[i][j]=='#' and S[i-1][j]=='.' and S[i][j-1]=='.' and S[i+1][j]=='.' and S[i][j+1]=='.':
            flag = False
print(flag)

Submission status: Wrong Answer

Solution code:
h, w = map(int, input().split())
s = [input() for _ in range(h)]

for i in range(1,h-1):
    for j in range(1,w-1):
        if(s[i][j] == "#"):
            if(s[i - 1][j] == "." and s[i + 1][j] == "." and s[i][j - 1] == "." and s[i][j + 1] == "."):
                print("No")
                print("[%d][%d]"%(i,j))
                exit()
print("Yes")

Submission status: Wrong Answer

Solution code:
# 1.上下左右を探索
def searchAround(sheet, h,w):
    # 上がblackか？
    try:
        isSharpAbove = (sheet[h+1][w]=="#")
    except IndexError:
        isSharpAbove = False
        
    # 下がblackか？
    try:
        isSharpBelow = (sheet[h-1][w]=="#")
        if h==0:
            isSharpBelow = False
    except IndexError:
        isSharpBelow = False
    
    # 右がblackか？
    try:
        isSharpRight = (sheet[h][w+1]=="#")
    except IndexError:
        isSharpRight = False
    
    # 左がblackか？
    try:
        isSharpLeft = (sheet[h][w-1]=="#")
        if w==0:
            isSharpLeft = False
    except IndexError:
        isSharpLeft = False  
        
        
    # blackがあるか？
    if isSharpAbove \
    or isSharpBelow \
    or isSharpRight \
    or isSharpLeft:
            return 0
    else:
        return 1
            
    

def main():
    H,W = map(int, input().split())
    sheet = []
    for h in range(H):
        sheet.append(list(input()))
    print(sheet)
    
    for h in range(H):
        for w in range(W):
            flag = searchAround(sheet, h,w)
            if flag==1:
                print('No')
                return 0

    if flag == 0:
        print('Yes')


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
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

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

Submission status: Wrong Answer

Solution code:
# 1.上下左右を探索
def searchAround(sheet, h,w,H,W):
    # 上がblackか？
    try:
        isSharpAbove = (sheet[h+1][w]=="#")
    except IndexError:
        isSharpAbove = False
        
    # 下がblackか？
    try:
        isSharpBelow = (sheet[h-1][w]=="#")
    except IndexError:
        isSharpBelow = False
    
    # 右がblackか？
    try:
        isSharpRight = (sheet[h][w+1]=="#")
    except IndexError:
        isSharpRight = False
    
    # 左がblackか？
    try:
        isSharpLeft = (sheet[h][w-1]=="#")
    except IndexError:
        isSharpLeft = False  
        
        
    # blackがあるか？
    if isSharpAbove \
    or isSharpBelow \
    or isSharpRight \
    or isSharpLeft:
            return 0
    else:
        return 1
            
    

def main():
    H,W = map(int, input().split())
    sheet = []
    for h in range(H):
        sheet.append(input())
    
    for h in range(H):
        for w in range(W):
            flag = searchAround(sheet, h,w,H,W)
            if flag==1:
                print('No')
                return 0

    if flag == 0:
        print('Yes')


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
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()

    return mapmap

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

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

Submission status: Wrong Answer

Solution code:
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(mapmap, i, j)
            count += 1

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

Submission status: Wrong Answer

Solution code:
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 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)
            count += 1

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

Submission status: Wrong Answer

Solution code:
import sys

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

#開始条件探索
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 line_size > nx and 0 <= ny and row_size > ny:
            if mapmap[nx][ny] == '#':#もし黒塗りなら
                start_flg = True
    
    if start_flg == True:
        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)
            Dfs(i, j)
            count += 1

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

Submission status: Wrong Answer

Solution code:
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
        
        move_x = [1, -1, 0, 0]
        move_y = [0, 0, 1, -1]

        startl, startr = i, j
        Stack = [[startl, startr]]

        #終了条件
        fin_flag = True
        for i in range(len(move_x)):
            nx = startl + move_x[i]
            ny = startr + move_y[i]

            if 0 <= nx and nx < lines and 0 <= ny and ny < rows:
                if mapmap[nx][ny] == '#':
                    fin_flag = False
                    break

        if fin_flag == True:
            print('No')
            sys.exit()

        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])
        
        #owarrino探索
        fin_flag_2 = False
        for i in range(lines):
            for j in range(rows):
                if mapmap[i][j] == '#':
                    start_flag_2 = True
                    break
        
        if fin_flag_2 == False:
            print('Yes')
            sys.exit()

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

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

DFS(mapmap)

Submission status: Wrong Answer

Solution code:
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
        
        move_x = [1, -1, 0, 0]
        move_y = [0, 0, 1, -1]

        startl, startr = i, j
        Stack = [[startl, startr]]

        #終了条件
        fin_flag = True
        for i in range(len(move_x)):
            nx = startl + move_x[i]
            ny = startr + move_y[i]

            if 0 <= nx and nx < lines and 0 <= ny and ny < rows:
                if mapmap[nx][ny] == '#':
                    fin_flag = False
                    break

        if fin_flag == True:
            print('No')
            sys.exit()

        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])
        
        #owarrino探索
        fin_flag_2 = False
        for i in range(lines):
            for j in range(rows):
                if mapmap[i][j] == '#':
                    start_flag = True
                    break
        
        if fin_flag_2 == False:
            print('Yes')
            sys.exit()

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

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

DFS(mapmap)

Submission status: Wrong Answer

Solution code:
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()

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

        startl, startr = i, j
        #動き
        Stack = [[startl, startr]]
        #終了条件
        for i in range(len(move_x)):
            nx = i + move_x[i]
            ny = j + move_y[i]

            if 0 <= nx and nx < lines and 0 <= ny and ny < rows:
                if mapmap[nx][ny] == '#':
                    break
            print('No')
            sys.exit()


        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)

Submission status: Wrong Answer

Solution code:
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')

Submission status: Wrong Answer

Solution code:
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')