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:
import math
import string
import collections
from collections import Counter


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]
h, w = map(int, input().split())
tmp = [None]*h
for i in range(w):
    tmp[i] = input()
# print(tmp)
for i in range(h-1):
    for j in range(w-1):
        if tmp[i][j] == '#':
            if (tmp[i-1][j] == '#' and i-1 >= 0)or(tmp[i+1][j] == '#' and i+1 <= h-1) or(tmp[i][j-1] == '#' and j-1 >= 0)or(tmp[i][j+1] == '#' and j+1 <= w-1):
                continue
            else:
                print('No')
                exit()
print('Yes')

Submission status: Runtime Error

Solution code:
import math
import string
import collections
from collections import Counter


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]
h, w = map(int, input().split())
tmp = [None]*h
for i in range(w):
    tmp[i] = input()
# print(tmp)
for i in range(h-1):
    for j in range(w-1):

        if tmp[i][j] == '#':
            if (tmp[i-1][j] == '#' and i-1 >= 0)or(tmp[i+1][j] == '#' and i+1 <= h-1) or(tmp[i][j-1] == '#' and j-1 >= 0)or(tmp[i][j+1] == '#' and j+i <= w-1):
                continue
            else:
                print('No')
                exit()
print('Yes')

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
h,w=map(int,input().split())
b=[list("."*(w+2))]
for i in range(w):
  b.append(list("."+input()+"."))
b.append(list("."*(w+2)))
ans="Yes"
dx=[0,1,0,-1]
dy=[1,0,-1,0]
for i in range(1,h+1):
  for j in range(1,w+1):
    if b[i][j]==".":continue
    flag=True
    for x,y in zip(dx,dy):
      if b[i][j]==b[i+x][j+y]:flag=False
    if flag:ans="No"
print(ans)

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline


def read():
    H, W = map(int, input().strip().split())
    S = []
    for i in range(H):
        s = list(input().strip())
        S.append(s)
    return H, W, S


def solve(H, W, S):
    dd = [(1, 0), (0, 1), (-1, 0), (0, -1)]

    def dfs(y, x):
        depth = 0
        S[y][x] = "."
        for dy, dx in dd:
            ny = y + dy
            nx = x + dx
            if 0 <= ny < H and 0 <= nx < W and S[ny][nx] == "#":
                depth = max(depth, dfs(ny, nx) + 1)
        return depth

    for i in range(H):
        for j in range(W):
            depth = dfs(i, j)
            if depth == 1:
                return "No"
    return "Yes"


if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python
# coding: utf-8

# In[2]:


H, W = map(int, input().split())
data = [["a"]*(W+2)]
for i in range(H):
    data.append(list("a" + input() + "a"))
data.append([["a"]*(W+2)])
# print(data)


# In[5]:


for h in range(H+1):
#     print(data[h])
    for w in range(W+1):
#         print(data[h][w])
        if data[h][w] == "#":
            if data[h-1][w] != "#" and data[h+1][w] != "#" and data[h][w-1] != "#" and data[h][w+1] != "#":
                print("No")
                exit()

print("Yes")


# In[ ]:

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python
# coding: utf-8

# In[2]:


H, W = map(int, input().split())
data = [["."]*(W+2)]
for i in range(H):
    data.append(list("." + input() + "."))
data.append([["."]*(W+2)])
# print(data)


# In[5]:


flag = 0
for h in range(H+1):
#     print(data[h])
    for w in range(W+1):
#         print(data[h][w])
        if data[h][w] == "#":
            if data[h-1][w] != "#" and data[h+1][w] != "#" and data[h][w-1] != "#" and data[h][w+1] != "#":
                flag = 1
                break

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


# In[ ]:

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python
# coding: utf-8

# In[2]:


H, W = map(int, input().split())
data = [["."]*(W+2)]
for i in range(H):
    data.append(list("." + input() + "."))
data.append([["."]*(W+2)])
# print(data)


# In[5]:


flag = 0
for h in range(H+1):
#     print(data[h])
    for w in range(W+1):
#         print(data[h][w])
        if data[h][w] == "#":
            if data[h-1][w] != "#" and data[h+1][w] != "#" and data[h][w-1] != "#" and data[h][w+1] != "#":
                flag = 1

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


# In[ ]:

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python
# coding: utf-8

# In[2]:


H, W = map(int, input().split())
data = [["."]*(W+2)]
for i in range(H):
    data.append(list("." + input() + "."))
data.append([["."]*(W+2)])
# print(data)


# In[3]:


data


# In[5]:


flag = 0
for h in range(H+1):
#     print(data[h])
    for w in range(W+1):
#         print(data[h][w])
        if data[h][w] == "#":
            if data[h-1][w] != "#" and data[h+1][w] != "#" and data[h][w-1] != "#" and data[h][w+1] != "#":
                flag = 1

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


# In[ ]:

Submission status: Runtime Error

Solution code:
import itertools

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

VALID = [[False] * W for _ in range(H)]

def dfs(h,w,parent):
  if parent:
    VALID[h][w] = True

  nxt = [-1,0,1]
  for x,y in itertools.product(nxt,repeat=2):
    if not (abs(x) + abs(y) == 1):
      continue
    nx = h + x
    ny = w + y
    if 0 <= nx < H and 0 <= ny < W and S[nx][ny] == '#' and not VALID[nx][ny]:
      if not parent:
        VALID[h][w] = True
      dfs(nx,ny,True)
        
for i in range(H):
  for j in range(W):
    if S[i][j] == '.':
      VALID[i][j] = True
    else:
      if not VALID[i][j]:
        dfs(i,j,False)
        
if all(sum(VALID,[])):
  print('Yes')
else:
  print('No')

Submission status: Runtime Error

Solution code:
import itertools

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

VALID = [[False] * W for _ in range(H)]

def dfs(h,w,parent):
  if parent:
    VALID[h][w] = True

  nxt = [-1,0,1]
  ok = False
  for x,y in itertools.product(nxt,repeat=2):
    if not (abs(x) + abs(y) == 1):
      continue
    nx = h + x
    ny = w + y
    if 0 <= nx < H and 0 <= ny < W and S[nx][ny] == '#' and not VALID[nx][ny]:
      if not ok:
        ok = True
        VALID[h][w] = True
      dfs(nx,ny,True)
  
  if not parent and ok:
    VALID[h][w] = True
      
for i in range(H):
  for j in range(W):
    if S[i][j] == '.':
      VALID[i][j] = True
    else:
      if not VALID[i][j]:
        dfs(i,j,False)
        
if all(sum(VALID,[])):
  print('Yes')
else:
  print('No')

Submission status: Runtime Error

Solution code:
import itertools

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

VALID = [[False] * W for _ in range(H)]

def dfs(h,w,parent):
  if parent:
    VALID[h][w] = True

  nxt = [-1,0,1]
  ok = False
  for x,y in itertools.product(nxt,repeat=2):
    if not (abs(x) + abs(y) == 1):
      continue
    nx = h + x
    ny = w + y
    if 0 <= nx < H and 0 <= ny < W and S[nx][ny] == '#' and not VALID[nx][ny]:
      ok = True
      dfs(nx,ny,True)
  
  if not parent and ok:
    VALID[h][w] = True
      
for i in range(H):
  for j in range(W):
    if S[i][j] == '.':
      VALID[i][j] = True
    else:
      if not VALID[i][j]:
        dfs(i,j,False)
        
if all(sum(VALID,[])):
  print('Yes')
else:
  print('No')

Submission status: Runtime Error

Solution code:
import itertools

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

VALID = [[False] * W for _ in range(H)]

def dfs(h,w,parent):
  if parent:
    VALID[h][w] = True

  nxt = [-1,0,1]
  ok = False
  for x,y in itertools.product(nxt,repeat=2):
    if not (abs(x) + abs(y) == 1):
      continue
    nx = h + x
    ny = w + y
    if 0 <= nx < H and 0 <= ny < W and S[nx][ny] == '#':
      ok = True
      dfs(nx,ny,True)
  
  if not parent and ok:
    VALID[h][w] = True
      
for i in range(H):
  for j in range(W):
    if S[i][j] == '.':
      VALID[i][j] = True
    else:
      if not VALID[i][j]:
        dfs(i,j,False)
        
if all(sum(VALID,[])):
  print('Yes')
else:
  print('No')

Submission status: Runtime Error

Solution code:
import itertools

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

VALID = [[False] * W for _ in range(H)]

def dfs(h,w,parent):
  if parent:
    VALID[h][w] = True

  nxt = [-1,0,1]
  ok = False
  for x,y in itertools.product(nxt,repeat=2):
    if not (abs(x) + abs(y) == 1):
      continue
    nx = h + x
    ny = w + y
    if 0 <= nx < H and 0 <= ny < W and S[nx][ny] == '#':
      ok = True
      dfs(nx,ny,True)
  
  if not parent and ok:
    VALID[h][w] = True
      
for i in range(H):
  for j in range(W):
    if S[i][j] == '.':
      VALID[i][j] = True
    else:
      if not VALID[i][j]:
        dfs(i,j,False)
        
if all(sum(VALID,[])):
  print('Yes')
else:
  print('No')

Submission status: Runtime Error

Solution code:
H, W = map(int,input().split())
List = [list("." +input()+ ".") for i in range(H)]
B = ["."]*(W+2)
List.insert(0,B)
List.append(B)

for i in range(1,W+1):
  for j in range(1,H+1):
    if List[i][j]=="#" and List[i-1][j]==List[i][j-1]\
        ==List[i][j+1]==List[i+1][j]==".":
      print("No")
      break
  else:
    continue
  break  

else:print("Yes")

Submission status: Runtime Error

Solution code:
# In[]
s = [list(input()) for _ in range(h)]
dx = [0,1,0,-1]
dy = [1,0,-1,0]

count = 0

for y in range(h):
    for x in range(w):
        cnt = 0
        for k in range(4):
            ny = y + dy[k]
            nx = x + dx[k]
            if nx < 0 or nx>=w or ny < 0 or ny >=h:
                continue
            if s[y][x] == '#':
                if s[ny][nx] == '#':
                    cnt += 1
        if cnt == 0:
            print('No')
            exit()

                        
print('Yes')

Submission status: Runtime Error

Solution code:
import sys
import math

h, w = map(int, input().split())
li = [[0] * h for i in range(w)]
ans = "Yes"
for i in range(h):
    tmp = input()
    for j in range(w):
        li[i][j] = tmp[j]
# 一行目
for j in range(1, w-1):
    if li[0][j - 1] != li[0][j] and li[0][j + 1] != li[0][j] and li[0][j] != li[1][j]:
        ans = "No"
for i in range(1, h-1):
    for j in range(1, w-1):
        if (
            li[i][j - 1] != li[i][j]
            and li[i][j + 1] != li[i][j]
            and li[i][j] != li[i - 1][j]
            and li[i][j] != li[i + 1][j]
        ):
            ans = "No"
for j in range(1, w-1):
    if (
        li[h-1][j - 1] != li[h-1][j]
        and li[h-1][j + 1] != li[h-1][j]
        and li[h-1][j] != li[h - 2][j]
    ):
        ans = "No"
print(ans)

Submission status: Runtime Error

Solution code:
import sys
import math

h, w = map(int, input().split())
li = [[0] * h for i in range(w)]
ans = "Yes"
for i in range(h):
    tmp = input()
    for j in range(w):
        li[i][j] = tmp[j]
# 一行目
for j in range(1, w-1):
    if li[0][j - 1] != li[0][j] and li[0][j + 1] != li[0][j] and li[0][j] != li[1][j]:
        ans = "No"
for i in range(1, h-1):
    for j in range(1, w-1):
        if (
            li[i][j - 1] != li[i][j]
            and li[i][j + 1] != li[i][j]
            and li[i][j] != li[i - 1][j]
            and li[i][j] != li[i + 1][j]
        ):
            ans = "No"
            print(i, j)
for j in range(1, w-1):
    if (
        li[h-1][j - 1] != li[h-1][j]
        and li[h-1][j + 1] != li[h-1][j]
        and li[h-1][j] != li[h - 2][j]
    ):
        ans = "No"
print(ans)

Submission status: Runtime Error

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

    m = []
    wall = ['.' for _ in range(w + 2)]
    m.append(wall)
    for _ in range(w):
        r = ["."] + list(input()) + ["."]
        m.append(r)
    m.append(wall)

    for i in range(1, h + 1):
        for j in range(1, w + 1):
            if m[i][j] == '#':
                f = any([m[i + x][j + y] == "#" for (x, y) in ((1, 0), (-1, 0), (0, 1), (0, -1))])
                if not f:
                    print("No")
                    exit()
    else:
        print("Yes")


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
h,w=map(int,input().split())
List=[input() for i in range(h)]
dx=[1,0,-1,0]
dy=[0,1,0,-1]

for i in range(h):
  for j in range(w):
    if List[i][j] == '.':
      continue
    else:
      c=0
      for k in range(4):
            i2 = i+dy[k]
            j2 = j+dx[k]
            if i2<0 or h<=i2:
                continue
            if j2<0 or w <=j2:
                continue
            else:
              if List[i2][j2]=="#":
                c+=1
if c == 0:
  print('No')
else:
  print('Yes')

Submission status: Runtime Error

Solution code:
h,w=map(int,input().split())
S=[]
for i in range(h):
    s=list(map(int,input.split())
    S.append(s)
for i in range(h):
    for j in range(w):
        if S[i+1][j]==S[i][j+1]==S[i-1][j]==S[i][j-1]==".":
            print("No")
            quit()
print("Yes")

Submission status: Runtime Error

Solution code:
h,w=map(int,input().split())
S=[]
for i in range(h):
    s=list(map(int,input.split()))
    S.append(s)
for i in range(h):
    for j in range(w):
        if S[i+1][j]==S[i][j+1]==S[i-1][j]==S[i][j-1]==".":
            print("No")
            quit()
print("Yes")

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
from sys import stdin


if __name__ == "__main__":
    _in = [_.rstrip() for _ in stdin.readlines()]
    H, W = list(map(int,_in[0].split(' ')))  # type:list(int)
    s_arr = []
    for i in range(H):
        _ = [_ for _ in _in[i+1]]   # type:list(str)
        s_arr.append(_)
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    s_arr = list(zip(*s_arr))
    TF = 'Yes'
    for i in range(H):
        if TF == 'Yes':
            for j in range(W):
                if s_arr[i][j] == '#':
                    adjacent = []
                    if i>1:   
                        if s_arr[i-1][j] == '#':
                            continue
                    if i<H-1: 
                        if s_arr[i+1][j] == '#':
                            continue
                    if j>1:   
                        if s_arr[i][j-1] == '#':
                            continue
                    if j<W-1: 
                        if s_arr[i][j+1] == '#':
                            continue
                    TF = 'No'
                    break
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    print(TF)

Submission status: Runtime Error

Solution code:
H, W = map(int, input().split())
s = [list(input()) i in range(H)]
dh = [-1, 0, 0, 1]
dw = [0, -1, 1, 0]
cnt = 0

for h in range(H):
  for w in range(W):
    # Check only black cell
    if s[h][w] == '.':
      continue
    for k in range(4):
      nh = h + dh[k]
      nw = w + dw[k]
      if nh < 0 or nw < 0 or H <= nh or W <= nw:
        continue
      # ok
      if s[nh][nw] == '#':
        break
    # failed
    else:
      cnt += 1

if cnt == 0:
  print('Yes')
else:
  print('No')

Submission status: Runtime Error

Solution code:
H, W = map(int, input().split())
s = [list(input()) i in range(H)]
dh = [-1, 0, 0, 1]
dw = [0, -1, 1, 0]

for h in range(H):
  for w in range(W):
    # Don't check white cell
    if s[h][w] == '.':
      continue
    # check neighbor cell
    for k in range(4):
      nh = h + dh[k]
      nw = w + dw[k]
      if nh < 0 or nw < 0 or H <= nh or W <= nw:
        continue
      # neighbor black is found => ok
      if s[nh][nw] == '#':
        break
    # There is independ black => failed
    else:
      print('No')
      break
  # ok
  else:
    continue
  # failed
  break
# ok
else:
  print('Yes')

Submission status: Runtime Error

Solution code:
H, W = map(int, input().split())
s = [list(input()) i in range(H)]
dh = [-1, 0, 0, 1]
dw = [0, -1, 1, 0]

for h in range(H):
  for w in range(W):
    # Don't check white cell
    if s[h][w] == '.':
      continue
    # check neighbor cell
    for k in range(4):
      nh = h + dh
      nw = w + dw
      if nh < 0 or nw < 0 or H <= nh or W <= nw:
        continue
      # neighbor black is found => ok
      if s[nh][nw] == '#':
        break
    # There is independ black => failed
    else:
      print('No')
      break
  # ok
  else:
    continue
  # failed
  break
# ok
else:
  print('Yes')

Submission status: Runtime Error

Solution code:
h,w = map(int, input().split())
a = [list(input) for _ in range(h)]
dx = [1,0,-1,0]
dy = [0,1,0,-1]
for k in range(h):
    for j in range(w):
        x,y = k,j
        if a[x][y] == "#":
            for i in range(4):
                xi,yi = x+dx[i],y+dy[i]
                if 0 <= xi < h and 0 <= yi < w and a[xi][yi] == "#":
                    break
            else:
                print("No")
                exit()
 
print("Yes")

Submission status: Runtime Error

Solution code:
for k in range(h):
    for j in range(w):
        x,y = k,j
        if a[x][y] == "#":
            for i in range(4):
                xi,yi = x+dx[i],y+dy[i]
                if 0 <= xi < h and 0 <= yi < w and a[xi][yi] == "#":
                    break
            else:
                print("No")
                exit()
 
print("Yes")

Submission status: Runtime Error

Solution code:
def func(x,y):
    global s,h,w,seen
    d = [1,-1]
    flag = False
    for i in d:
        if x+i < h and x+i >= 0:
            if s[x+i][y] == "#":
                seen[x+i+y*w] = 1
                seen[x+y*w] = 1
                flag = True
        if y+i < h and y+i >= 0:
            if s[x][y+i] == "#":
                seen[x+(y+i)*w] = 1
                seen[x+y*w] = 1
                flag = True
    return flag


h,w = map(int,input().split())
s = [input() for _ in range(h)]
seen = [0 for _ in range(h*w)]
ans = False
for i in range(h):
    for j in range(w):
        if s[i][j] == "#" and seen[i+j*w] == 0:
            if not func(i,j):
                ans = True
if ans:
    print("No")
else:
    print("Yes")

Submission status: Runtime Error

Solution code:
H,W=map(int,input().split())
endmap=[list(s for s in input()) for _ in range(H)]
exlarge=[[0]*(W+2)*(H+2)]
ans='Yes'
for i in range(H):
  for j in range(W):
    if endmap[i][j]=='#':
      exlarge[i+1][j+1]=1
 
for k in range(H+2):
  for l in range(W+2):
    if exlarge[k][l]==1: 
        if exlarge[k][l-1]== exlarge[k][l+1]==exlarge[k-1][l]==exlarge[k+1][l]==0:
          ans='No'
 
print(ans)

Submission status: Runtime Error

Solution code:
H,W=map(int,input().split())
endmap=[list(s for s in input()) for _ in range(H)]
exlarge=[[0]*(W+2)*(H+2)]
ans='Yes'
for i in range(H):
  for j in range(W):
    if endmap[i][j]=='#':
      exlarge[i+1][j+1]=1
 
for k in range(H+2):
  for l in range(W+2):
    if exlarge[k][l]==1: 
        if exlarge[k][l-1]!=1 or exlarge[k][l+1]!=1 or exlarge[k-1][l]!=1 or exlarge[k+1][l]!=1:
          ans='No'
 
print(ans)

Submission status: Runtime Error

Solution code:
H,W=map(int,input().split())
endmap=[list(s for s in input()) for _ in range(H)]
exlarge=[[0]*(W+2)*(H+2)]
ans='Yes'
for i in range(H):
  for j in range(W):
    if endmap[i][j]=='#':
      exlarge[i+1][j+1]=1

for k in range(H+2):
  for l in range(W+2):
    if endmap[k][l]==1: 
        if endmap[k][l-1]!=1 or endmap[k][l+1]!=1 or endmap[k-1][l]!=1 or endmap[k+1][l]!=1:
          ans='No'

print(ans)

Submission status: Runtime Error

Solution code:
H,W=map(int,input().split())
endmap=[list(s for s in input()) for _ in range(H)]
exlarge=[[0]*(W+2)*(H+2)]
ans='Yes'
for i in range(H):
  for j in range(W):
    if endmap[i][j]=='#':
      exlarge[i+1][j+1]=1

for k in range(H+2):
  for l in range(W+2):
    if endmap[i][j]==1: 
        if endmap[i][j-1]!=1 or endmap[i][j+1]!=1 or endmap[i-1][j]!=1 or endmap[i+1][j]!=1:
          ans='No'

print(ans)

Submission status: Runtime Error

Solution code:
h,w=map(int,input().split())
s=[list(input()) for i in range(h)]
flag=True
count=0
for i in range(h):
  if flag==False:
    break
  for j in range(w):
    if s[i][j]=="#":
      if i>0 and s[i-1][j]!="#":
        flag=False
      elif i>0 and s[i-1][j]=="#":
        flag2=True
        
      if i<(h-1) and s[i+1][j]!="#":
        flag=False
      elif i<(h-1) and s[i+1][j]=="#":
        flag2=True
        
      if j>0 and s[i][j-1]!="#":
        flag=False
      elif j>0 and s[i][j-1]=="#":
        flag2=True
        
      if j<(w-1) and s[i][j+1]!="#":
        flag=False
      elif j<(w-1) and s[i][j+1]=="#":
        flag2=True
      if flag2:
        flag=True
    else:
      count+=1
        
if h==1 and w==1:
  if s[0][0]=="#":
    flag=False
    
if count==(h*w):
  flag=True
  
if flag:
  print("Yes")
else:
  print("No")

Submission status: Runtime Error

Solution code:
h,w=map(int,input().split())
s=[list(input()) for i in range(h)]
flag=True
count=0
for i in range(h):
  if flag==False:
    break
  for j in range(w):
    if s[i][j]=="#":
      if i>0 and s[i-1][j]!="#":
        flag=False
      elif i> and s[i-1][j]=="#":
        flag=True
        break
        
      if i<(h-1) and s[i+1][j]!="#":
        flag=False
      elif i<(h-1) and s[i+1][j]=="#":
        flag=True
        break
        
      if j>0 and s[i][j-1]!="#":
        flag=False
      elif j>0 and s[i][j-1]=="#":
        flag=True
        break
        
      if j<(w-1) and s[i][j+1]!="#":
        flag=False
      elif j<(w-1) and s[i][j+1]=="#":
        flag=True
        break
    else:
      count+=1
        
if h==1 and w==1:
  if s[0][0]=="#":
    flag=False
    
if count==(h*w):
  flag=True
  
if flag:
  print("Yes")
else:
  print("No")

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))

h,w = iim()

flag = True

l = []
dx = [0,0,1,-1]
dy = [1,-1,0,0]
for i in range(h):
    l.append(list(input()))

for i in range(h):
    for j in range(w):
        if l[i][j] == '#':
            check = False
            for k in range(4):
                if i+dx[k] < 0 or i+dx[k] >= w:
                    continue
                if j+dy[k] < 0 or j+dy[k] >= h:
                    continue
                if l[i+dx[k]][j+dy[k]] == '#':
                    check = True
            if not check:
                flag = False

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

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
import sys
try:
    from typing import List
except ImportError:
    pass

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(H: int, W: int, s: "List[str]"):
    print(YES if all(
        any(
            s[y + dy][x + dx] == "#"
            for dx, dy in [(1, 0), (0, 1), (-1, 0), (0, -1)]
            if 0 <= x + dx < W and 0 <= y + dy < H
        )
        for y in range(H)
        for x in range(W)
        if s[y][x] == "#"
    ) else NO)


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    s = [next(tokens) for _ in range(W)]  # type: "List[str]"
    solve(H, W, s)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
h,w = map(int,input().split())
t = "."*(w+2)
b = [t]
for i in range(h):
  s = str(input())
  s = "."+ s + "."
  b.append(s)
b.append(t)
for i in range(1,h+1):
  for j in range(1,w+1):
    if s[i][j] == "#":
      if all([s[i-1][j]==".",s[i+1][j]==".",s[i][j-1]==".",s[i][j+1]=="."]):
        print("No")
        exit()
print("Yes")

Submission status: Runtime Error

Solution code:
import numpy as np
 
H, W = map(int, input().split())
S = np.array([list(input()) for _ in range(H)])

for i in range(H):
  for j in range(W):
    if S[i, j] == '#':
      if np.sum(np.concatenate(S[i-1:i, j], S[i, j-1:j], S[i+1:i, j], S[i, j+1:j]) == '#') == 0:
        print('No')
        break
else:
  print('Yes')

Submission status: Runtime Error

Solution code:
H, W = map(int, input().split())

S = ["."*W]
ans = 'Yes'
for i in range(H):
    s = input()
    S.append('.'+s+'.')

S.append('.'*W)

for i in range(1, H+1):
    for j in range(1, W+1):
        if S[i][j] == '#':
            if S[i][j+1] == '#' or S[i][j-1] == '#' or S[i+1][j] == '#' or S[i-1][j] == '#':
                continue
            else:
                ans = 'No'
                break

print(ans)

Submission status: Runtime Error

Solution code:
h,w=map(int,input().split())
s=[]
s.append("."*(h+2))

for i in range(w):
    s.append("."+input()+".")
    
s.append("."*(h+2))

for i in range(1,w+1):
    for j in range(1,h+1):
        #print(i,j)
        if s[i][j]=="#":
            if s[i][j+1]=="#" or s[i][j-1]=="#" or s[i+1][j]=="#" or s[i-1][j]=="#":
                pass
            else:
                print("No")
                exit()
        

print("Yes")

Submission status: Runtime Error

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

dxy=[(-1,0),(0,1),(0,-1),(1,0)]
for i in range(h):
  for j in range(w):
    if s[i][j]=="#":
      f=False
      for x,y in dxy:
        
        if 0<=i+x<=h-1 and 0<=j+y<=w-1 and s[i+x][j+y]=="#":
          f=True
      
      if not f:
        print("No")
        exit()
        
        
if f:
  print("Yes")

Submission status: Runtime Error

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

dxy=[(-1,0),(0,1),(0,-1),(1,0)]
for i in range(h):
  for j in range(w):
    if s[i][j]=="#":
      f=False
      for x,y in dxy:
        
        if 0<=i+x<=h-1 and 0<=j+y<=w-1 and s[i+x][j+y]=="#":
          f=True
      
      if not f:
        print("No")
        break
        
        
if f:
  print("Yes")

Submission status: Runtime Error

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

dxy=[(-1,0),(0,1),(0,-1),(1,0)]
for i in range(h):
  for j in range(w):
    if s[i][j]=="#":
      f=False
      for x,y in dxy:
        
        if 0<=i+x<=h-1 and 0<=j+y<=w-1 and s[i+x][j+y]=="#":
          f=True
      
      if not f:
        print("No")
        
        
if f:
  print("Yes")

Submission status: Runtime Error

Solution code:
#import collections
#aa = collections.Counter(a) # list to list
#from itertools import combinations # (string,3) 3回

mod = 10**9 + 7

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

def readInts():
  return list(map(int,input().split()))
def search(S,x,y,h,w):
    #全探索で間に合うべ
    cnt = 0
    for i in range(4):
        nx = x + dx[i]
        ny = y + dy[i]
        if 0 <= nx < w and 0 <= ny < h:
            if S[nx][ny] == '#':
                cnt += 1
    if not cnt:#隣接する#が一つもない
        return False
    else:
        return True

def main():
    h,w = readInts()
    S = [list(input()) for _ in range(h)]
    for i in range(h):
        for j in range(w):
            if S[i][j] == '#':
                if search(S,i,j,h,w):
                    pass
                else:
                    print('No')
                    exit()
    print('Yes')


if __name__ == '__main__':
  main()