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: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
h,w = map(int,input().split())
s = [list(input()) for _ in range(h)]
visited = [[False]*w for _ in range(h)]
for y in range(h):
    for x in range(w):
        if s[y][x]=="#" and not visited[y][x]:
            visited[y][x]= True
            flag =False
            for dy,dx in ((1,0),(-1,0),(0,1),(0,-1)):
                ny,nx = y+dy,x+dx
                if 0<=ny<h and 0<=nx<w and s[ny][nx]=='#':
                    visited[ny][nx] = True
                    flag = True
                    
            if flag ==False:
                print('No')
                break
    if not flag:
        break
    

if flag:
    print('Yes')

Submission status: Runtime Error

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

grid = [[str(i) for i in input()]for _ in range(h)]
dxdy = [[1, 0], [0, 1], [-1, 0], [0, -1]]

for i in range(h):
    for j in range(w):
        if grid[i][j]=="#":
            f = False
            for d in dxdy:
                if(i+d[0]>-1 and j+d[1]>-1 and i+d[0]<w and j+d[1]<h):
                    if grid[i+d[0]][j+d[1]]=="#":
                        f = True
                        continue
            if f==False:
                print("No")
                exit()


print("Yes")

Submission status: Runtime Error

Solution code:
a, b = map(int, input().split())

grid = [[str(i) for i in input()]for _ in range(a)]
dxdy = [[1, 0], [0, 1], [-1, 0], [0, -1]]

for i in range(b):
    for j in range(a):
        if grid[i][j]=="#":
            f = False
            for d in dxdy:
                if(i+d[0]>-1 and j+d[1]>-1 and i+d[0]<b and j+d[1]<a):
                    if grid[i+d[0]][j+d[1]]=="#":
                        f = True
                        continue
            if f==False:
                print("No")
                exit()


print("Yes")

Submission status: Runtime Error

Solution code:
from itertools import product
from collections import deque
import numpy as np
inputs = open(0).readlines()
class Grid():
    def __init__(self, grid, w=0, h=0, function=lambda x: x):
        self.w = w = w if w else len(grid[0])
        self.h = h = h if h else len(grid)
        dtype = type(function(grid[0][0]))
        self.grid = np.empty((h, w), dtype=dtype)
        for i, row in zip(range(h), grid):
            for j, val in zip(range(w), row):
                self.grid[i][j] = function(val)
    
    def is_valid_x(self, x):
        return 0 <= x < self.w
    def is_valid_y(self, y):
        return 0 <= y < self.h
    def is_valid_xy(self, x, y):
        return self.is_valid_x(x) and self.is_valid_y(y) 
    
    def __iter__(self):
        return iter(self.grid)
    def __repr__(self):
        return '\n'.join([' '.join(map(str, row)) for row in self.grid])
    def __getitem__(self, x):
        return self.grid[x]
    def __setitem__(self, x, val):
        self.grid[x] = val

h, w = map(int, inputs[0].split())
grid = Grid(inputs[1:], function=lambda x: int(x == '#'))

def dfs(root):
    x, y = root
    grid[y, x] = 0
    stack = [root]
    while stack:
        x, y = stack.pop()
        for dx, dy in zip([1, 0, -1, 0], [0, 1, 0, -1]):
            if grid.is_valid_xy(x+dx, y+dy) and grid[y+dy, x+dx]:
                stack.append((x+dx, y+dy))
                grid[y+dy, x+dx] = 0
                count += 1
    return count
    
ans = 'Yes'
for i, j in product(range(h), range(w)):
    if grid[i, j]:
        if dfs((j, i)) == 1:
            ans = 'No'
            break
print(ans)

Submission status: Runtime Error

Solution code:
H, W = map(int, input().split())
s = [["."]*W]
for i in range(H):
    temp = "."
    temp += input()
    temp += "."
    s.append(temp)
s.append(["."]*W)
flag = True
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] == ".":
            flag = False
            break
    if not flag:
        break
if flag:
    result = "Yes"
else:
    result = "No"
print(result)

Submission status: Runtime Error

Solution code:
from itertools import product
from collections import deque
import numpy as np
inputs = open(0).readlines()

class Grid():
    def __init__(self, grid, w=0, h=0, function=lambda x: x):
        self.w = w = w if w else len(grid[0])
        self.h = h = h if h else len(grid)
        dtype = type(function(grid[0][0]))
        self.grid = np.empty((h, w), dtype=dtype)
        for i, rows in zip(range(h), grid):
            for j, val in zip(range(w), rows):
                self.grid[i][j] = function(val)
    
    def is_valid_x(self, x):
        return 0 <= x < self.w
    def is_valid_y(self, y):
        return 0 <= y < self.h
    def is_valid_xy(self, x, y):
        return self.is_valid_x(x) and self.is_valid_y(y) 
    
    def __iter__(self):
        return iter(self.grid)
    def __repr__(self):
        return '\n'.join([' '.join(map(str, rows)) for rows in self.grid])

h, w = map(int, inputs[0].split())
grid = Grid(inputs[1:])

def dfs(root):
    count = 1
    stack = [root]
    while stack:
        x, y = stack.pop()
        grid[y, x] = 0
        for dx, dy in zip([1, 0, -1, 0], [0, 1, 0, -1]):
            if grid.is_valid_xy(x+dx, y+dy) and grid[y+dy, x+dx]:
                stack.append((x+dx, y+dy))
                count += 1
    return count

def bfs(root):
    count = 1
    queue = [root]
    while queue:
        x, y = queue.popleft()
        grid[y, x] = 0
        for dx, dy in zip([1, 0, -1, 0], [0, 1, 0, -1]):
            if grid.is_valid_xy(x+dx, y+dy) and grid[y+dy, x+dx]:
                queue.append((x+dx, y+dy))
                count += 1
    return count
    

ans = 'Yes'
for i, j in product(range(h), range(w)):
    if grid[i, j]:
        if dfs((j, i)) == 1:
            ans = 'No'
            break
print(ans)

Submission status: Runtime Error

Solution code:
from itertools import product
class Grid():
    def __init__(self, grid, w=0, h=0, function=lambda x: x):
        self.w = w = w if w else len(grid[0])
        self.h = h = h if h else len(grid)
        dtype = type(function(grid[0][0]))
        self.grid = np.empty((h, w), dtype=dtype)
        for i, rows in zip(range(h), grid):
            for j, val in zip(range(w), rows):
                self.grid[i][j] = function(val)
    
    def is_valid_x(self, x):
        return 0 <= x < self.w
    def is_valid_y(self, y):
        return 0 <= y < self.h
    def is_valid_xy(self, x, y):
        return self.is_valid_x(x) and self.is_valid_y(y) 
    
    def __iter__(self):
        return iter(self.grid)
    def __repr__(self):
        return '\n'.join([' '.join(map(str, rows)) for rows in self.grid])

inputs = open(0).readlines()
h, w = map(int, inputs[0].split())
grid = Grid(inputs[1:])

def dfs(root):
    count = 1
    stack = [root]
    while stack:
        x, y = stack.pop()
        grid.grid[y, x] = '.'
        for dx, dy in zip([1, 0, -1, 0], [0, 1, 0, -1]):
            if grid.is_valid_xy(x+dx, y+dy) and grid.grid[y+dy, x+dx] == '#':
                stack.append((x+dx, y+dy))
                count += 1
    return count

ans = 'No'
for i, j in product(range(h), range(w)):
    if grid.grid[i, j] == '#':
        if dfs((j, i)) == 1:
            ans = 'Yes'
            break
print(ans)

Submission status: Runtime Error

Solution code:
from itertools import product
class Grid():
    def __init__(self, grid, w=0, h=0, function=lambda x: x):
        self.w = w = w if w else len(grid[0])
        self.h = h = h if h else len(grid)
        dtype = type(function(grid[0][0]))
        self.grid = np.empty((h, w), dtype=dtype)
        for i, rows in zip(range(h), grid):
            for j, val in zip(range(w), rows):
                self.grid[i][j] = function(val)
    
    def is_valid_x(self, x):
        return 0 <= x < self.w
    def is_valid_y(self, y):
        return 0 <= y < self.h
    def is_valid_xy(self, x, y):
        return self.is_valid_x(x) and self.is_valid_y(y) 
    
    def __iter__(self):
        return iter(self.grid)
    def __repr__(self):
        return '\n'.join([' '.join(map(str, rows)) for rows in self.grid])

h, w = map(int, inputs[0].split())
grid = Grid(inputs[1:])

def dfs(root):
    count = 1
    stack = [root]
    while stack:
        x, y = stack.pop()
        grid.grid[y, x] = '.'
        for dx, dy in zip([1, 0, -1, 0], [0, 1, 0, -1]):
            if grid.is_valid_xy(x+dx, y+dy) and grid.grid[y+dy, x+dx] == '#':
                stack.append((x+dx, y+dy))
                count += 1
    return count

ans = 'No'
for i, j in product(range(h), range(w)):
    if grid.grid[i, j] == '#':
        if dfs((j, i)) == 1:
            ans = 'Yes'
            break
print(ans)

Submission status: Runtime Error

Solution code:
H, W = map(int, input().split())
S = ['.'*(W+2)] + [['.'] + input() + ['.'] for _ in range(H)] + ['.'*(W+2)]
flg = False
for i in range(1, H+1):
  for j in range(1, W+1):
    if S[i][j] == '#':
      cnt = 0
      if S[i][j-1] == '.':
        cnt += 1
      if S[i][j+1] == '.':
        cnt += 1
      if S[i-1][j] == '.':
        cnt += 1
      if S[i+1][j] == '.':
        cnt += 1
      flg = (cnt == 4)
if flg:
  print("No")
else:
  print("Yes")

Submission status: Runtime Error

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

for i in range(H):
  h=i
  for j in range(W):
    w=s[h][j]
    if w=='#':
      cnt=0
      for j,k in ([1,0], [-1,0], [0,1], [0,-1]):
        new_h, new_w=h+j, w+k
        if new_h<0 or new_h>=H or new_w<0 or new_w>=W:
          continue
        elif s[new_h][new_w] == '#':
          cnt+=1
          break
      if cnt==0:
        print('No')
        exit()
print('Yes')

Submission status: Runtime Error

Solution code:
def main():
    h, w = map(int, input().split())
    k = [["."]+list(input())+["."] for _ in range(h)]
    s = [[None]*(w+2) for _ in range(h+2)]
    s[0] = ["."]*(w+2)
    s[-1] = ["."]*(w+2)
    s[1:h+1] = k
    d = [[0, 1], [0, -1], [1, 0], [-1, 0]]
    if w == 1:
        for i in range(1, h+1):
            if s[i][1] == "#":
                if s[i+1][1] == "." and s[i-1][1] == ".":
                    print("No")
                    return  
        print("Yes")
        return
    if h == 1:
        for i in range(1, w+1):
            if s[1][i] == "#":
                if s[1][i+1] == "." and s[1][i-1] == ".":
                    print("No")
                    return  
        print("Yes")
        return
    for i in range(1, w+1):
        for j in range(1, h+1):
            if s[i][j] == ".":
                continue
            flag = True
            for (di, dj) in d:
                if s[i+di][j+dj] == "#":
                    flag = False
                    break
            if flag:
                print("No")
                return
    print("Yes")

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
def main():
    h, w = map(int, input().split())
    k = [["."]+list(input())+["."] for _ in range(h)]
    s = [[None]*(w+2) for _ in range(h+2)]
    s[0] = ["."]*(w+2)
    s[-1] = ["."]*(w+2)
    s[1:h+1] = k
    d = [[0, 1], [0, -1], [1, 0], [-1, 0]]
    for i in range(1, w+1):
        for j in range(1, h+1):
            if s[i][j] == ".":
                continue
            flag = True
            for (di, dj) in d:
                if s[i+di][j+dj] == "#":
                    flag = False
                    break
            if flag:
                print("No")
                return
    print("Yes")

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
H,W = map(int,input().split())
L = []
for i in range(H):
    L.append((input()))
for i in range(H):
    for j in range(W):
        if L[i][j] == "#":
            flag = False
            if i-1 >=0 and L[i-1][j] == "#":
                flag = True
            if i+1 <H and L[i+1][j] == "#":
                flag = True
            if j-1 >=0 and L[i][j-1] == "#":
                flag = True
            if j+1 <W and L[i][j+1] == "#":
                flag = True
            if flag == False:
                print("No")
                exit()
if flag:
    print("Yes")

Submission status: Runtime Error

Solution code:
from itertools import product
n, m = map(int,input().split())
canvas = []
for i in range(n):
    canvas.append(input())
for i,j in product([num for num in range(n)],[num for num in range(m)]):
    if canvas[i][j] == '.':
        continue
    result = 0
    if i > 0 and canvas[i-1][j] == '#':
        result += 1
    if i < n-1 and canvas[i+1][j] == '#':
        result += 1
    if j > 0 and canvas[i][j-1] == '#':
        result += 1
    if j < m-1 and canvas[i][j+1] == '#':
        result += 1
    if result == 0:
        flag = True
        break
if flag:
    print('No')
else:
    print('Yes')

Submission status: Runtime Error

Solution code:
H, W = map(int, input().split())
MAP = [list(input()) for h in range(H)]
b = False
for i in range(H):
    for j in range(W):
        sharp = False
        for x, y in [(0, 1), (1, 0), (0, -1), (-1, 0)]:
            dx, dy = i + x, j + y
            if 0 <= dx and 0 <= dy and dx < W and dy < H:
                if MAP[i][j] == '#' and MAP[dx][dy] == '#':
                    sharp = True
        if MAP[i][j] == '#' and not sharp:
            print('No')
            b = True
            break
    if b:
        break
else:
    print('Yes')

Submission status: Runtime Error

Solution code:
import numpy as np

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

s = [ list(input()) for i in range(h)]
s = np.array(s)

dy = [-1,0,1,0]
dx = [0,-1,0,1]

ans =True

for i in range(0,h):
    for j in range(0,w):
        flag = False
        if s[i][j] == '#' :
            for k in range(4):
                y = i+dy[k]
                x = i+dx[k]
                if  x < 0 or x >=w or y >= h or y < 0 :continue
#                print(x,y)
                if s[x][y] == '#':
                    flag = True

        if flag :ans = False


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

Submission status: Runtime Error

Solution code:
import numpy as np

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

s = [ list(input()) for i in range(h)]
s = np.array(s)

dy = [-1,0,1,0]
dx = [0,-1,0,1]

print(s.shape)
ans =True

for i in range(0,h):
    for j in range(0,w):
        flag = False
        if s[i][j] == '#' :
            for k in range(4):
                y = i+dy[k]
                x = i+dx[k]
                if  x < 0 or x >=w or y >= h or y < 0 :continue
#                print(x,y)
                if s[x][y] == '#':
                    flag = True

        if flag :ans = False


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

Submission status: Runtime Error

Solution code:
def main():
    H, W = map(int, input().split())
    S = ['.'*W]+['.'+input()+'.' for _ in range(H)]+['.'*W]

    for h in range(1, H+1):
        for w in range(1, W+1):
            if S[h][w] == '#':
                if S[h-1][w] == '.' and S[h+1][w] == '.' and S[h][w+1] == '.' and S[h][w-1] == '.':
                    return False
    return True


print('Yes' if main() else 'No')

Submission status: Runtime Error

Solution code:
import sys

H,W = map(int,input().split())
s = [list(input()) for i in range(W)]
a = [["."]*H for _ in range(W)]
for i in range(H):
    for j in range(1,W):
        if s[i][j-1] == "#" and s[i][j] == "#":
            a[i][j-1] = "#"
            a[i][j] = "#"

sT = list(zip(*s))
aT = [list(x) for x in zip(*a)]

for i in range(H):
    for j in range(1,W):
        if sT[i][j-1] == "#" and sT[i][j] == "#":
            aT[i][j-1] = "#"
            aT[i][j] = "#"

ans = list(zip(*aT))

for i in range(H):
    for j in range(W):
        if s[i][j] != ans[i][j]:
            print("No")
            sys.exit()
print("Yes")

Submission status: Runtime Error

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

s0 = ['.'*w]
S = s0 + s + s0
L = [0]*(h+2)

for i in range(h+2):
    l = '.' + S[i] + '.'
    L[i] = l

ans = True
cnt = 0
for i in range(1, w+2):
    for j in range(1, h+2):
        cnt = 0
        if L[i][j] == '#':
            if L[i+1][j] == '#':
                cnt += 1
            elif L[i-1][j] == '#':
                cnt += 1
            elif L[i][j+1] == '#':
                cnt += 1
            elif L[i][j-1] == '#':
                cnt += 1
            if cnt == 0:
                ans = False
                break

if ans:
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

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

s0 = ['.'*w]
S = s0 + s + s0
L = []

for i in S:
    l = '.' + i + '.'
    L.append(l)

ans = True
cnt = 0
for i in range(1, w+2):
    for j in range(1, h+2):
        cnt = 0
        if L[i][j] == '#':
            if L[i+1][j] == '#':
                cnt += 1
            elif L[i-1][j] == '#':
                cnt += 1
            elif L[i][j+1] == '#':
                cnt += 1
            elif L[i][j-1] == '#':
                cnt += 1
            if cnt == 0:
                ans = False
                break

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

Submission status: Runtime Error

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

s0 = ['.'*w]
S = s0 + s + s0
L = []

for i in S:
    l = '.' + i + '.'
    L.append(l)

print(L)

ans = True
cnt = 0
for i in range(1, w+2):
    for j in range(1, h+2):
        cnt = 0
        if L[i][j] == '#':
            if L[i+1][j] == '#':
                cnt += 1
            elif L[i-1][j] == '#':
                cnt += 1
            elif L[i][j+1] == '#':
                cnt += 1
            elif L[i][j-1] == '#':
                cnt += 1
            if cnt == 0:
                print('No')
                ans = False
                exit()
if ans:
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

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

s0 = ['.'*w]
S = s0 + s + s0
L = []

for i in S:
    l = '.' + i + '.'
    L.append(l)

ans = True
cnt = 0
for i in range(1, w+2):
    for j in range(1, h+2):
        cnt = 0
        if L[i][j] == '#':
            if L[i+1][j] == '#':
                cnt += 1
            elif L[i-1][j] == '#':
                cnt += 1
            elif L[i][j+1] == '#':
                cnt += 1
            elif L[i][j-1] == '#':
                cnt += 1
            if cnt == 0:
                print('No')
                ans = False
                exit()
if ans:
    print('Yes')

Submission status: Runtime Error

Solution code:
h, w = map(int, input().split())
s = [['.']*(w+2)]
for _ in range(h):
    s.append(['.'] + list(input()) + ['.'])
s.append(['.']*(w+2))
ans = 'Yes'

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

print(ans)

Submission status: Runtime Error

Solution code:
h, w = map(int, input().split())
s = [['.']*(w+2)]
for _ in range(h):
    s.append(['.'] + list(input()) + ['.'])
s.append(['.']*(w+2))
ans = 'Yes'

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

print(ans)

Submission status: Runtime Error

Solution code:
height,width = map(int, input().split())
map_list = []
for i in range(height):
    map_list.append(list(input()))
    map_list[i].append('0')
map_list.append(['0'] * width)

for h in range(height):
    for w in range(width):
        if map_list[h][w] == '#':
            if '#' in [map_list[h-1][w], map_list[h+1][w], map_list[h][w-1], map_list[h][w+1]]:

            else:
                print("No")
                exit()

print("Yes")

Submission status: Runtime Error

Solution code:

# import
import numpy as np

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

Mtmp = []
for _ in range(H):
    tmp = list(input())
    Mtmp.append(tmp)

M = np.array(Mtmp)
S = np.array([[0]*W]*H)

#print(M)

digtmp = np.array([[0, 1], [1, 0], [0, -1], [-1, 0]])

def dfs(i, j):
    global ngflag
    global searchflag
    if S[i, j] == 1:
        return
    S[i, j] = 1
    if M[i, j] == '.':
        return
    #print("i:{}, j:{}".format(i, j))
    searchflag = 1
    dig = digtmp + np.array([i, j])
    for d in dig:
        if 0 <= d[0] < W and 0 <= d[1] < H:
            if M[d[0], d[1]] == '#':
                ngflag = 0
                dfs(d[0], d[1])

searchflag = 0

while True:
    ngflag = 1
    if 0 not in S:
        if M[target[0], target[1]] == '.':
            ngflag = 0
        break
    target = list(zip(*np.where(S == 0)))[0]
    #print("sf:{}, ng:{}".format(searchflag, ngflag))
    dfs(target[0], target[1])
    if M[target[0], target[1]] == '#' and searchflag == 1 and ngflag == 1:
        break
        

#print("sf:{}, ng:{}".format(searchflag, ngflag))

if searchflag == 1 and ngflag == 0:
    ans = 'Yes'
elif searchflag == 1 and ngflag == 1:
    ans = 'No'
else:
    ans = 'Yes'

print(ans)

Submission status: Runtime Error

Solution code:
# import
import numpy as np

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

Mtmp = []
for _ in range(H):
    tmp = list(input())
    Mtmp.append(tmp)

M = np.array(Mtmp)
S = np.array([[0]*W]*H)

#print(M)

digtmp = np.array([[0, 1], [1, 0], [0, -1], [-1, 0]])

def dfs(i, j):
    global ngflag
    global searchflag
    if S[i, j] == 1:
        return
    S[i, j] = 1
    if M[i, j] == '.':
        return
    #print("i:{}, j:{}".format(i, j))
    searchflag = 1
    dig = digtmp + np.array([i, j])
    for d in dig:
        if 0 <= d[0] < H and 0 <= d[1] < W:
            if M[d[0], d[1]] == '#':
                ngflag = 0
                dfs(d[0], d[1])

searchflag = 0

while True:
    ngflag = 1
    if 0 not in S:
        if M[target[0], target[1]] == '.':
            ngflag = 0
        break
    target = list(zip(*np.where(S == 0)))[0]
    #print("sf:{}, ng:{}".format(searchflag, ngflag))
    dfs(target[0], target[1])
    if M[target[0], target[1]] == '#' and searchflag == 1 and ngflag == 1:
        break
        

#print("sf:{}, ng:{}".format(searchflag, ngflag))

if searchflag == 1 and ngflag == 0:
    ans = 'Yes'
elif searchflag == 1 and ngflag == 1:
    ans = 'No'
else:
    ans = 'Yes'

print(ans)

Submission status: Runtime Error

Solution code:
# import
import numpy as np

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

Mtmp = []
for _ in range(H):
    tmp = list(input())
    Mtmp.append(tmp)

M = np.array(Mtmp)
S = np.array([[0]*W]*H)

print(M)

digtmp = np.array([[0, 1], [1, 0], [0, -1], [-1, 0]])

def dfs(i, j):
    global ngflag
    global searchflag
    if S[i, j] == 1:
        return
    S[i, j] = 1
    if M[i, j] == '.':
        return
    print("i:{}, j:{}".format(i, j))
    searchflag = 1
    dig = digtmp + np.array([i, j])
    for d in dig:
        if 0 <= d[0] < H and 0 <= d[1] < W:
            if M[d[0], d[1]] == '#':
                ngflag = 0
                dfs(d[0], d[1])

searchflag = 0

while True:
    ngflag = 1
    if 0 not in S:
        if M[target[0], target[1]] == '.':
            ngflag = 0
        break
    target = list(zip(*np.where(S == 0)))[0]
    print("sf:{}, ng:{}".format(searchflag, ngflag))
    dfs(target[0], target[1])
    if M[target[0], target[1]] == '#' and searchflag == 1 and ngflag == 1:
        break
        

print("sf:{}, ng:{}".format(searchflag, ngflag))

if searchflag == 1 and ngflag == 0:
    ans = 'Yes'
elif searchflag == 1 and ngflag == 1:
    ans = 'No'
else:
    ans = 'Yes'

print(ans)

Submission status: Runtime Error

Solution code:
from collections import deque
from collections import Counter

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

c = [None]*h
d = [[-1 for i in range(w)] for j in range(h)]
dx = [1,0,-1,0]
dy = [0,1,0,-1]
kk = 0

for i in range(h):
    c[i] = input()
    
for i in range(h):
    for j in range(w):
        if c[i][j] == "#":
            d[i][j] = 0
    
def bfs(y,x):
    global kk
    d[y][x] = -1
    for k in range(4):
        nx = x + dx[k]
        ny = y + dy[k]
            
        if 0<=nx and nx<w and 0<=ny and ny<h and d[ny][nx] != -1:
            kk += 1
            bfs(ny,nx)
            

resmin  = 100000
an = []
res = 0
for i in range(h):
    for j in range(w):   
        if d[i][j] == 0:
            bfs(i,j)
            res += 1
            an.append(kk+1)
            
b = Counter(an)
if h == 1 and w == 1:
    print("Yes")
else:
    if b[1] != 0:
        print("No")
    else:
        print("Yes")

Submission status: Runtime Error

Solution code:
from collections import deque
from collections import Counter

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

c = [None]*h
d = [[-1 for i in range(w)] for j in range(h)]
dx = [1,0,-1,0]
dy = [0,1,0,-1]
kk = 0

for i in range(h):
    c[i] = input()
    
for i in range(h):
    for j in range(w):
        if c[i][j] == "#":
            d[i][j] = 0
    
def bfs(y,x):
    global kk
    d[y][x] = -1
    for k in range(4):
        nx = x + dx[k]
        ny = y + dy[k]
            
        if 0<=nx and nx<w and 0<=ny and ny<h and d[ny][nx] != -1:
            kk += 1
            bfs(ny,nx)
            

resmin  = 100000
an = []
res = 0
for i in range(h):
    for j in range(w):   
        if d[i][j] == 0:
            bfs(i,j)
            res += 1
            an.append(kk+1)
            
b = Counter(an)
if a == 1 and b == 1:
    print("Yes")
else:
    if b[1] != 0:
        print("No")
    else:
        print("Yes")

Submission status: Runtime Error

Solution code:
from collections import deque
from collections import Counter

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

c = [None]*h
d = [[-1 for i in range(w)] for j in range(h)]
dx = [1,0,-1,0]
dy = [0,1,0,-1]
kk = 0

for i in range(h):
    c[i] = input()
    
for i in range(h):
    for j in range(w):
        if c[i][j] == "#":
            d[i][j] = 0
    
def bfs(y,x):
    global kk
    d[y][x] = -1
    for k in range(4):
        nx = x + dx[k]
        ny = y + dy[k]
            
        if 0<=nx and nx<w and 0<=ny and ny<h and d[ny][nx] != -1:
            kk += 1
            bfs(ny,nx)
            

resmin  = 100000
an = []
res = 0
for i in range(h):
    for j in range(w):   
        if d[i][j] == 0:
            bfs(i,j)
            res += 1
            an.append(kk+1)
            
b = Counter(an)
if b[1] != 0:
    print("No")
else:
    print("Yes")

Submission status: Runtime Error

Solution code:
H, W = map(int,input().split())
S = [list(input()) for _ in range(W)]
for i in range(H):
  for j in range(W):
    up = down = left = right = "#"
    if S[i][j] == "#":
      if i-1 >= 0:
        up = S[i-1][j]
      if j-1 >= 0:
        left = S[i][j-1]
      if i+1 <= H-1:
        down = S[i+1][j]
      if j+1 <= W-1:
        right = S[i][j+1]
      if up == down == left == right == ".":
        print("No")
        exit()
print("Yes")

Submission status: Runtime Error

Solution code:
h, w = map(int, input().split())
masu = ['.'*(w+2)]
masu += ['.' + input() + '.' for _ in range(w)]
masu.append('.'*(w+2))
ans = 'Yes'
for i in range(1,h+1):
    for j in range(1,w+1):
        if masu[i][j] == '#':
            if masu[i+1][j] == '#' or masu[i-1][j] == '#' or masu[i][j+1] == '#' or masu[i][j-1] == '#':
                continue
            else:
                ans = 'No'
                break
print(ans)

Submission status: Runtime Error

Solution code:
h, w = map(int, input().split())
masu = ['.'*(w+2)]
masu += ['.' + input() + '.' for _ in range(w)]
masu.append('.'*(w+2))
ans = 'Yes'
for i in range(1,h):
    for j in range(1,w):
        if masu[i][j] == '#':
            if masu[i+1][j] == '#' or masu[i-1][j] == '#' or masu[i][j+1] == '#' or masu[i][j-1] == '#':
                continue
            else:
                ans = 'No'
                break
print(ans)

Submission status: Runtime Error

Solution code:
h, w = map(int, input().split())
masu = ['.'*(w+2)]
masu += ['.' + input() + '.' for _ in range(w)]
masu.append('.'*(w+2))
ans = 'Yes'
for i in range(1,h-1):
    for j in range(1,w-1):
        if masu[i][j] == '#':
            if masu[i+1][j] == '#' or masu[i-1][j] == '#' or masu[i][j+1] == '#' or masu[i][j-1] == '#':
                continue
            else:
                ans = 'No'
                break
print(ans)

Submission status: Runtime Error

Solution code:
h, w = map(int, input().split())
S = [list(input()) for _ in range(h)]
drc = [[0,1],[0,-1],[1,0],[-1,0]]
for i in range(h):
  for j in range(w):
    if S[i][j] == "#":
      if all([S[i+x][j+y] =="." for x, y in drc if 0 <= i+x < w and 0 <= j+y < h]):
        print("No")
        exit()
print("Yes")

Submission status: Runtime Error

Solution code:
11 11
...#####...
.##.....##.
#..##.##..#
#..##.##..#
#.........#
#...###...#
.#########.
.#.#.#.#.#.
##.#.#.#.##
..##.#.##..
.##..#..##.