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

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 i == lines-1 and j == rows-1:        
    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
    
    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

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:
H, W = map(int, input().split())

S = [list(input()) for _ in range(H)]
a = 1

for h in range(H):
    for w in range(W):
        if S[h][w] == "#":
            if h == 0:
                if w == 0:
                    down, right = S[h+1][w], S[h][w+1]
                    if down == "." and right == ".":
                        print("No")
                        a = 0 
                        break
                if w == W-1:
                    down, left = S[h+1][w], S[h][w-1]
                    if down == "." and left == ".":
                        print("No")
                        a = 0 
                        break
                else:
                    down, left, right = S[h+1][w], S[h][w-1], S[h][w+1]
                    if down == "." and left == "." and right == ".":
                        print("No")
                        a = 0 
                        break
            if h == H-1:
                if w == 0:
                    up, right = S[h-1][w], S[h][w+1]
                    if up == "." and right == ".":
                        print("No")
                        a = 0 
                        break
                if w == W-1:
                    up, left = S[h-1][w], S[h][w-1]
                    if up == "." and left == ".":
                        print("No")
                        a = 0 
                        break
                else:
                    up, left, right = S[h-1][w], S[h][w-1], S[h][w+1]
                    if up == "." and left == "." and right == ".":
                        print("No")
                        a = 0 
                        break
            else:
                if w == 0:
                    up, down, right = S[h-1][w], S[h+1][w], S[h][w+1]
                    if up == "." and down == "." and right == ".":
                        print("No")
                        a = 0 
                        break
                if w == W-1:
                    up, down, left = S[h-1][w], S[h+1][w], S[h][w-1]
                    if up == "." and down == "." and left == ".":
                        print("No")
                        a = 0 
                        break
                else:
                    up, down, left, right = S[h-1][w], S[h+1][w], S[h][w-1], S[h][w+1]
                    if up == "." and down == "." and left == "." and right == ".":
                        print("No")
                        a = 0 
                        break
if a == 1:
    print("Yes")

Submission status: Wrong Answer

Solution code:
HW = input().split()

H = int(HW[0])
W = int(HW[1])

tmp1 = ("." * W) + ".."
s = [list(tmp1)]
for i in range(H):
    tmp2 = "." + input() + "."
    s.append(list(tmp2))
s.append(list(tmp1))

checker = 1
for i in range(1, H+1):
    for j in range(1, W+1):
        if s[i][j] == "#":
            if s[i][j-1] == "." and s[i-1][j] == "." and s[i][j+1] == "." and s[i+1][j] == ".":
                checker == 0

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

Submission status: Wrong Answer

Solution code:
h,w=map(int,input().split())
mass=[]
f=0
for i in range(0,h):
    mass.append(list(input()))
for i in range(h):
    if f==0:
        for j in range(w):
            if i!=h-1 and j!=w-1:
                if mass[i][j]=="#" and mass[i][j]!=mass[i][j+1] and mass[i][j]!=mass[i+1][j]:
                    f=1
                    break
            elif i==h:
                if mass[i][j]=="#" and mass[i][j]!=mass[i][j+1]:
                    f=1
                    break
            elif j==w :
                if mass[i][j]=="#" and mass[i][j]!=mass[i+1][j]:
                    f=1
                    break
if f==0:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
h,w=map(int,input().split())
mass=[]
f=0
for i in range(0,h):
    mass.append(list(input()))
for i in range(h-1):
    if f==0:
        for j in range(w-1):
            if mass[i][j]=="#" and mass[i][j]!=mass[i][j+1] and mass[i][j]!=mass[i+1][j]:
                print(i,j)
                f=1
                break
if f==0:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
h, w = map(int, input().split(' ')) # H(行)とW（列）を入力
s = []
yorn = 'True'
for i in range(h):
    si = str(input()) #i行目を入力
#    print(i, '行目: ', si)
    s.append(si)
#    print(s)
    
    for j in range(w):
        #左側を比較する必要がないとき
        if (j == 0) or (s[i][j] == '.'):
#            print(j,': next')
            continue
        #左側を比較するとき
        #左に#があれば次の文字へ
        elif s[i][j-1] == '#':
#            print(j,': next')
            continue
        #左に#がないとき
        #上の行がなければ次の文字へ
        elif i == 0:
#            print(i,': next')
            continue
        #上の行と比較するとき
        #上に#があれば次の文字へ
        elif s[i-1][j] == '#':
            continue
#            print(j,': next')
        #上に#がないならば終了
        else:
            yorn = 'False'
#            print(j,': End')

if yorn == 'True':             
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]
r = False
for i in range(h):
    for j in range(w):
        if s[i][j] == ".":
            pass
        elif 0 <= (i - 1) and s[i - 1][j] == "#":
            r = True
        elif (i + 1) < h and s[i + 1][j] == "#":
            r = True
        elif 0 <= (j - 1) and s[i][j - 1] == "#":
            r = True
        elif (j + 1) < w and s[i][j + 1] == "#":
            r = True
        else:
            r = False
            break
    if r == False: break


print("Yes") if r else print("No")

Submission status: Wrong Answer

Solution code:
h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]
r = False
for i in range(h):
    for j in range(w):
        if s[i][j] == ".":
            pass
        elif 0 <= (i - 1) and s[i - 1][j] == "#":
            r = True
        elif (i + 1) < h and s[i + 1][j] == "#":
            r = True
        elif 0 <= (j - 1) and s[i][j - 1] == "#":
            r = True
        elif (j + 1) < w and s[i][j + 1] == "#":
            r = True
        else:
            r = False
            break


print("Yes") if r else print("No")

Submission status: Wrong Answer

Solution code:
h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]
r = False
for i in range(h):
    for j in range(w):
        if s[i][j] == ".":
            pass
        elif 0 < (i - 1) and s[i - 1][j] == "#":
            r = True
        elif (i + 1) < h and s[i + 1][j] == "#":
            r = True
        elif 0 < (j - 1) and s[i][j - 1] == "#":
            r = True
        elif (j + 1) < w and s[i][j + 1] == "#":
            r = True
        else:
            r = False
            break


print("Yes") if r else print("No")

Submission status: Wrong Answer

Solution code:
h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]
r = True
for i in range(h):
    for j in range(w):
        if s[i][j] == ".":
            pass
        elif 0 < (i - 1) and s[i - 1][j] == "#":
            pass
        elif (i + 1) < h and s[i + 1][j] == "#":
            pass
        elif 0 < (j - 1) and s[i][j - 1] == "#":
            pass
        elif (j + 1) < w and s[i][j + 1] == "#":
            pass
        else:
            r = False
            break


print("Yes") if r else print("No")

Submission status: Wrong Answer

Solution code:
h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]
r = False
for i in range(h):
  for j in range(w):
    if s[i][j] == ".":
      continue
    elif 0 < (i - 1) and s[i - 1][j] == "#":
      r = True
      continue
    elif (i + 1) < h and s[i + 1][j] == "#":
      r = True
      continue
    elif 0 < (j - 1) and s[i][j - 1] == "#":
      r = True
      continue
    elif (j + 1) < w and s[i][j + 1] == "#":
      r = True
      continue
    else:
      r = False

print("Yes") if r else print("No")

Submission status: Wrong Answer

Solution code:
h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]
r = True
for i in range(h):
  for j in range(w):
    if s[i][j] == ".":
      continue
    elif 0 < (i - 1) and s[i - 1][j] == "#":
      continue
    elif (i + 1) < h and s[i + 1][j] == "#":
      continue
    elif 0 < (j - 1) and s[i][j - 1] == "#":
      continue
    elif (j + 1) < w and s[i][j + 1] == "#":
      continue
    else:
      r = False

print("Yes") if r else print("No")

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

def main():
    h, w = map(int, raw_input().split())

    square = []
    for i in range(h):
        square.append(raw_input())

    for i in range(h):
        for j in range(w):
            if square[i][j] == '.':
                continue
            else:
                if check(square, i, j, h, w):
                    continue
                else:
                    print("No")
                    exit()

    print("Yes")

def check(square, i, j, h, w):
    if i-1 > 0:
        if square[i-1][j] == '#':
            return True
    if i+1 < h:
        if square[i+1][j] == '#':
            return True
    if j-1 > 0:
        if square[i][j-1] == '#':
            return True
    if j+1 < w:
        if square[i][j+1] == '#':
            return True

    return False

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
h,w = map(int, raw_input().split())
c = [ raw_input() for i in range(h) ]
ans = True
for i in range(h):
    for j in range(w):
        if c[i][j] == '#':
            ans = False
            if (i > 0) and (c[i-1][j] == '#'):
                ans = True
            if (j > 0) and (c[i][j-1] == '#'):
                ans = True
            if (i < h-1) and (c[i+1][j] == '#'):
                ans = True
            if (j < w-1) and (c[i][j+1] == '#'):
                ans = True
        if not(ans):
            break
if ans:
    print "Yes"
else:
    print "No"

Submission status: Wrong Answer

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

mx = [0, 1, 0, -1]
my = [1, 0, -1, 0]
for i in range(h):
  for  j in range(w):
    if table[i][j] == "#":
      for k in range(4):
        tx, ty = j + mx[k], i + my[k]
        if 0 <= tx < w and 0 <= ty < h and table[ty][tx] == "#":
          break
      else:
        print("No")
print("Yes")

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

# 入力
H, W = map(int, input().split())
S = [list(input()) for i in range(H)]

ans = "Yes"
for i in range(0, H):
    for j in range(0, W):
        if i == 0 and j == 0 or i == 0 and j == W-1 or \
            i == H-1 and j == 0 or i == H-1 and j == W-1:
            continue
        if S[i][j] == "#":
            if i == 0:
                if S[i][j+1] != "#" and S[i][j-1] != "#" and S[i+1][j] != "#":
                    ans = "No"
            elif i == H-1:
                if S[i][j+1] != "#" and S[i][j-1] != "#" and S[i-1][j] != "#":
                    ans = "No"
            elif j == 0:
                if S[i][j+1] != "#" and S[i+1][j] != "#" and S[i-1][j] != "#":
                    ans = "No"
            elif j == W-1:
                if S[i][j-1] != "#" and S[i+1][j] != "#" and S[i-1][j] != "#":
                    ans = "No"
        else:
            if S[i][j] == "#" and S[i][j+1] != "#" and S[i][j-1] != "#" \
                and S[i+1][j] != "#" and S[i-1][j] != "#":
                ans = "No"
print(ans)

Submission status: Wrong Answer

Solution code:
H,W = map(int,raw_input().split())
S = range(H);ans = range(H);z = 0
for x in range(H):
	S[x] = map(str,raw_input())
	ans[x] = map(int,range(W))
	for y in range(W):
		if x > 0 and S[x][y] <> S[x-1][y] and y > 0 and S[x][y] <> S[x][y-1] and S[x][y] == '#':
			z += 1
print('No' if z >= 1 else 'Yes')

Submission status: Wrong Answer

Solution code:
import sys

def get_value_by_lists(values_list, pos):
    h, w = len(values_list), len(values_list[0])
    if 0 <= pos[1] < h and 0 <= pos[0] < w:
        return values_list[pos[1]][pos[0]]
    else:
        return None

def is_black_in_four_dir(cells_list, pos):
    for p in ((0, 1), (0, -1), (1, 0), (-1, 0)):
        if get_value_by_lists(cells_list, (pos[0]+p[0], pos[1]+p[1])) == "#":
            return True
    return False

h, w = map(lambda x: int(x), input().split(" "))
cells_list = [input() for _ in range(h)]

print(cells_list)

for y, cells in enumerate(cells_list):
    for x, cell in enumerate(cells):
        if cell == "#" and not (is_black_in_four_dir(cells_list, (x, y))):
            print("No")
            sys.exit()
print("Yes")

Submission status: Wrong Answer

Solution code:
import sys

def is_black_in_four_dir(char_list, pos):
    for p in ((1, 0), (-1, 0), (0, 1), (0, -1)):
        if square_list[pos[1]+p[1]][pos[0]+p[0]] == "#":
            return True
    return False

h, w = map(lambda x: int(x), input().split(" "))
square_list = [input() for i in range(h)]

square_list = ["."*(w+2)] + ["." + s + "." for s in square_list] + ["."*(w+2)]

print(square_list)

for y in range(1, h+2):
    for x in range(1, w+2):
        if square_list[y][x] == "#":
            if not is_black_in_four_dir(square_list, (x, y)):
                print("No")
                sys.exit()
    
print("Yes")

Submission status: Wrong Answer

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

for i in range(h):
    for j in range(w):
        if s[i][j] == '.':
            continue
        if i-1 > 0 and s[i-1][j] == '#':
            continue
        if i+1 < h and s[i+1][j] == '#':
            continue
        if j-1 > 0 and s[i][j-1] == '#':
            continue
        if j+1 < w and s[i][j+1] == '#':
            continue
        print('No')
        break
    else:
      continue
    break
else:
    print('Yes')

Submission status: Wrong Answer

Solution code:
h,w=map(int,input().split())
s=[["."]*(w+2)]
for i in range(h):
    s+=[["."]+list(input())+["."]]
s+=[["."]*(w+2)]
for j in range(1,h+1):
    for k in range(1,w+1):
        if s[j+1][k]=="." and s[j-1][k]=="." and s[j][k+1]=="." and s[j][k-1]==".":
            print("No")
            exit()
print("Yes")

Submission status: Wrong Answer

Solution code:
from itertools import product

H, W = map(int, input().split())

s = []
for i in range(H):
    s.append(list(input()))

res = 'Yes'
for h, w in product(range(H), range(W)):
    if s[h][w] == '#':
        if h != 0 and s[h - 1][w] == '#':
            continue
        if h != H - 1 and s[h + 1][w] == '#':
            continue
        if w != 0 and s[h][w - 1] == '#':
            continue
        if w < W - 1 and s[h][w + 1] == '#':
            continue
        else:
            res = 'No'
            exit()

print(res)

Submission status: Wrong Answer

Solution code:
from itertools import product

H, W = map(int, input().split())

s = []
for i in range(H):
    s.append(list(input()))

for h, w in [(h, w) for h, w in product(range(H), range(W)) if s[h][w] != '.']:
    R = False
    if h > 0 and s[h - 1][w] == '#':
        # 上
        R = True
    if h < H - 2 and s[h + 1][w] == '#':
        # 下
        R = True
    if w > 0 and s[h][w - 1] == '#':
        # 左
        R = True
    if w < W - 2 and s[h][w + 1] == '#':
        # 右
        R = True

    if not R:
        print('No')
        exit()

print('Yes')

Submission status: Wrong Answer

Solution code:
import sys

h, w = map(int, input().split())

array = ["".join(list(input())) for x in range(h)]

flag = True
for h_i in range(1, len(array)-2):
    for w_i in range(1, len(array[h_i]) - 2):
        if array[h_i][w_i] == "#" and array[h_i+1][w_i] == "." and array[h_i][w_i+1] == "." and \
                array[h_i - 1][w_i] == "." and "." == array[h_i][w_i - 1]:
            print(h_i, w_i)
            print("No")
            sys.exit()

print("Yes" if flag else "No")

Submission status: Wrong Answer

Solution code:
from itertools import product

H, W = map(int, input().split())

s = []
for i in range(H):
    s.append(list(input()))

for h, w in [(h, w) for h, w in product(range(H), range(W)) if s[h][w] != '.']:
    R = False
    if h > 0 and s[h - 1][w] == '#':
        # 上
        R = True
    if h < H - 1 and s[h + 1][w] == '#':
        # 下
        R = True
    if w > 0 and s[h][w - 1] == '#':
        # 左
        R = True
    if w < W - 1 and s[h][w + 1] == '#':
        # 右
        R = True

    if not R:
        print('No')

print('Yes')

Submission status: Wrong Answer

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

s = [0 for i in range(h)]
for i in range(h):
    s[i] = list(input())


flag = False


def hantei(i, j):
    if i < 0 or i > h-1 or j < 0 or j > w-1:
        return False
    elif s[i][j] == "#":
        return True
    else:
        return False


def hantei2(i,j):
    if hantei(i-1, j) or hantei(i+1, j) or hantei(i, j-1) or hantei(i, j+1):
        return True
    else:
        return  False


for i in range(0, h):
    for j in range(0, w):
        if s[i][j] == '#':
            flag = hantei2(i,j)
            if flag == False:
                break
    if flag == False:
        break

            
        

if flag:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

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

s = [0 for i in range(h)]
for i in range(h):
    s[i] = list(input())


flag = False


def hantei(i, j):
    if i < 0 or i > h-1 or j < 0 or j > w-1:
        return False
    elif s[i][j] == "#":
        return True
    else:
        return False


def hantei2(i,j):
    if hantei(i-1, j) or hantei(i+1, j) or hantei(i, j-1) or hantei(i, j+1):
        return True
    else:
        return  False


for i in range(0, h):
    if flag == False:
        break
    for j in range(0, w):
        if s[i][j] == '#':
            flag = hantei2(i,j)
            if flag == False:
                break
            
        

if flag:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

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

s = [0 for i in range(h)]
for i in range(h):
    s[i] = list(input())


flag = False


def hantei(i, j):
    if i < 0 or i > h-1 or j < 0 or j > w-1:
        return False
    elif True:
        if s[i][j] == '#':
            return True
    else:
        
        return False


def hantei2(i,j):
    if hantei(i-1, j) or hantei(i+1, j) or hantei(i, j-1) or hantei(i, j+1):
        return True
    else:
        return  False


for i in range(0, h):
    for j in range(0, w):
        if s[i][j] == '#':
            flag = hantei2(i,j)
        

if flag:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:



import numpy as np

H, W = map(int, raw_input().split())

S = np.zeros((H, W))

d_flag = 0

for i in range(H):
    tmp = list(raw_input())
    for j in range(W):
        if tmp[j] == "#":
            S[i, j] = 1
            d_flag = 1
        else:
            S[i, j] = 0



for i in range(H):
    for j in range(W):
        if S[i, j] == 1:
            flag = 0
            if i>1:
                a1 = S[i-1, j]
            else:
                a1 = 0
            if j>1:
                a2 = S[i, j-1]
            else:
                a2 = 0
            if i<H-1:
                a3 = S[i+1, j]
            else:
                a3 = 0
            if j<W-1:
                a4 = S[i, j+1]
            else:
                a4 = 0
            if a1+a2+a3+a4 == 0:
                d_flag = 0
                
if d_flag == 1:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
from itertools import repeat, product

def get_targets(a_grid):
    h = len(a_grid)
    w = len(a_grid[0])

    targets = [t for t in product(range(h), range(w)) if a_grid[t[0]][t[1]] == '#']

    return targets

def get_arounds(t, h, w):
    arounds = map(lambda a: (t[0] + a[0], t[1] + a[1]), ((0, 1), (1, 0), (0, -1), (-1, 0)))

    return list(filter(lambda x: -1 < x[0] < w and -1 < x[1] < h, arounds))

def main():
    h, w = tuple(map(int, input().split()))
    a_grid = [list(input()) for _ in range(h)]

    grid = [list(repeat('#', w)) for _ in range(h)]

    targets = get_targets(a_grid)

    while len(targets) != 0:
        t = targets.pop()
        arounds = get_arounds(t, h, w)
        if any([(a in targets) for a in arounds]):
            targets = list(filter(lambda e: e not in arounds, targets))
        else:
            print('No')
            break
    else:
        print('Yes')


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
d = list(map(int,input().split()))
at = []
at.append(["."]*(d[1]+2))
for i in range(d[0]):
  at.append(list(input()))
  at[i+1].insert(0,".")
  at[i+1].insert(d[1],".")
at.append(["."]*(d[1]+2))
l = [[1,0],[0,1],[-1,0],[0,-1]]
re = True
op = False
ppp = True
def ao(k, re,op,l,ppp,d):
  for a in range(1,d[0]):
    for b in range(1,d[1]):
      for dx,dy in l:
        if k[a][b] =="#" and k[a+dx][b+dy] ==".":
          re = False
        if k[a][b] =="#" and k[a+dx][b+dy] =="#":
          op = True
      if op == True:
        re = True
      if re == False:
        ppp = False
      op = False
      re = True
  if ppp == False:
    return False
  else:
    return True
 
if ao(at,re,op,l,ppp,d) == True:
  print("Yes")
else:
  print("No")

Submission status: Wrong Answer

Solution code:
from itertools import repeat, product

def get_targets(a_grid):
    h = len(a_grid)
    w = len(a_grid[0])

    targets = [t for t in product(range(h), range(w)) if a_grid[t[0]][t[1]] == '#']

    return targets

def get_arounds(t, h, w):
    arounds = map(lambda a: (t[0] + a[0], t[1] + a[1]), ((0, 1), (1, 0), (0, -1), (-1, 0)))

    return list(filter(lambda x: -1 < x[0] < w and -1 < x[1] < h, arounds))

def main():
    h, w = tuple(map(int, input().split()))
    a_grid = [list(input()) for _ in range(h)]

    grid = [list(repeat('#', w)) for _ in range(h)]

    targets = get_targets(a_grid)

    while len(targets) != 0:
        t = targets.pop()
        arounds = get_arounds(t, h, w)
        if any([(a in targets) for a in arounds]):
            targets = list(filter(lambda e: e not in arounds, targets))
        else:
            print('No')
    else:
        print('Yes')


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
b = input().split(" ")
H = int(b[0])
W = int(b[1])
a = [0 for i in range(H)]
j = "YES"
for i in range(H):
    a[i] = input()
for i0 in range(H):
    for i1 in range(W):
        if i1 == 0:
            if i0 == 0:
                if a[0][1] == '.' and a[1][0] =='.' and a[i0][i1] == '#':
                    j = "NO"
            elif i0 == H-1:
                if a[H-2][0] == '.' and a[H-1][1] == '.' and a[i0][i1] == '#':
                    j ="NO"
            else:
                if a[i0-1][0] == '.' and a[i0+1][0] =='.' and a[i0][1] == '.' and a[i0][i1] == '#':
                    j = "NO"
        elif i1 == W-1:
            if i0 == 0:
                if a[0][W-2] == '.' and a[1][W-1] =='.' and a[i0][i1] == '#':
                    j = "NO"
            elif i0 == H-1:
                if a[H-2][W-1] == '.' and a[H-1][W-2] == '.' and a[i0][i1] == '#':
                    j ="NO"
            else:
                if a[i0-1][W-1] == '.' and a[i0+1][W-1] =='.' and a[i0][W-2] == '.' and a[i0][i1] == '#':
                    j = "NO"
        else:
            if i0 == 0:
                if a[0][i1-1] == '.' and a[1][i1] =='.' and a[0][i1+1] == '.' and a[i0][i1] == '#':
                    j = "NO"
            elif i0 == H-1:
                if a[H-1][i1-1] == '.' and a[H-1][i1+1] == '.' and a[H-2][i1] == '.' and a[i0][i1] == '#':
                    j ="NO"
            else:
                if a[i0-1][i1] == '.' and a[i0+1][i1] =='.' and a[i0][i1-1] == '.' and a[i0][i1+1] == '.' and a[i0][i1] == '#':
                    j = "NO"
print(j)

Submission status: Wrong Answer

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

s = [0 for i in range(h)]
for i in range(h):
    s[i] = list(input())


flag = False


def hantei(i, j):
    if i < 0 or i > h-1 or j < 0 or j > w-1:
        return False
    elif True:
        if s[i][j] == '#':
            return True
    else:
        
        return False


def hantei2(i,j):
    if hantei(i-1, j) or hantei(i+1, j) or hantei(i, j-1) or hantei(i, j+1):
        return True
    else:
        return  False


for i in range(0, h):
    for j in range(0, w):
        if s[i][j] == '#':
            flag = hantei2(i,j)
        

if flag:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
import math

h, w = map(int, input().split())
canvas = []
flag = True
cnt = 0
dcnt = 0
for i in range(h):
    x = list(map(list, input().split()))
    canvas.append(x)
# canvas[h][0][w]
# 黒く塗った所は@で表す
for i in range(h):
    for j in range(w):
        if canvas[i][0][j] == ".":
            dcnt += 1
        if canvas[i][0][j] == "#":
            cnt += 1
            if j-1 >= 0:
                # 左
                try:
                    if canvas[i][0][j-1] == "#" or canvas[i][0][j-1] == "@":
                        canvas[i][0][j-1] = "@"
                        canvas[i][0][j] = "@"
                except Exception as e:
                    pass
                try:
                    if canvas[i][0][j+1] == "#" or canvas[i][0][j+1] == "@":
                        canvas[i][0][j+1] = "@"
                        canvas[i][0][j] = "@"
                except Exception as e:
                    pass
            if i-1 >= 0:
                # 上
                try:
                    if canvas[i-1][0][j] == "#" or canvas[i-1][0][j] == "@":
                        canvas[i-1][0][j] = "@"
                        canvas[i][0][j] = "@"
                except Exception as e:
                    pass
                # 下
                try:
                    if canvas[i+1][0][j] == "#" or canvas[i+1][0][j] == "@":
                        canvas[i+1][0][j] = "@"
                        canvas[i][0][j] = "@"
                except Exception as e:
                    pass

for i in range(h):
    for j in range(w):
        if canvas[i][0][j] == "#":
            flag = False
            break
    if flag == False:
        break

if flag and dcnt > 2:
    print("Yes")
else:
    print("No")