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:
wOFFSETS = [(-1,0),(0,-1),(0,1),(1,0)]

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

Ses = []
for _ in range(H):
    Ses.append(input())

for y in range(H):
    for x in range(W):
        if Ses[y][x] == "#":
            found = False
            for dx, dy in OFFSETS:
                now_x = x+dx
                now_y = y+dy
                if now_x < 0 or now_x >= W:
                    continue
                if now_y < 0 or now_y >= H:
                    continue
                if Ses[now_y][now_x] == "#":
                    found = True
                    break
            if not found:
                print("No")
                exit()

print("Yes")

Submission status: Runtime Error

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

hw = []
hw.append('.'*W)
for _ in range(H):
    edited = input()
    edited = '.' + edited + '.'
    hw.append(edited)
hw.append('.'*W)
#四方を白に囲まれた黒がある場合に達成不可能

for i in range(1,H+1):
    for j in range(1,W+1):
        if hw[i][j] == '#':
            #探索
            if hw[i+1][j] == '.' and hw[i-1][j] == '.' and hw[i][j+1] == '.' and hw[i][j-1] == '.':
                print('No')
                quit()

print('Yes')

Submission status: Runtime Error

Solution code:
H, W = map(int, input().split())
mat = [input() for i in range(W)]
mat_t = [''.join(x) for x in zip(*mat)]
def check(mat, t):
    stack = set()
    for i, string in enumerate(mat):
        string = '.' + string + '.'
        for j in range(len(string)):
            if j+3<=len(string):
                if string[j:j+3] == '.#.':
                    if t==False:
                        stack.add((i, j))
                    else:
                        stack.add((j, i))
    return stack

stack1 = check(mat, False)
stack2 = check(mat_t, True)
if stack1 & stack2:
    print('No')
else:
    print('Yes')

Submission status: Runtime Error

Solution code:
%%test_input https://atcoder.jp/contests/abc096/tasks/abc096_c
# 巡回セールスマン問題？
H, W = map(int, input().split())
mat = [input() for i in range(W)]
mat_t = [''.join(x) for x in zip(*mat)]
def check(mat, t):
    stack = set()
    for i, string in enumerate(mat):
        string = '.' + string + '.'
        for j in range(len(string)):
            if j+3<=len(string):
                if string[j:j+3] == '.#.':
                    if t==False:
                        stack.add((i, j))
                    else:
                        stack.add((j, i))
    return stack

stack1 = check(mat, False)
stack2 = check(mat_t, True)
if stack1 & stack2:
    print('No')
else:
    print('Yes')

Submission status: Runtime Error

Solution code:
H, W = map(int, input().split())
S = [['.']*W]
for i in range(H):
    S.append(['.'] + list(input()) + ['.'])
S.append(['.']*W)

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

else:
    print('Yes')

Submission status: Runtime Error

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

diff = [[-1, 0], [1, 0], [0, -1], [0, 1]]
def is_isolated(y, x):
    if Sij[y][x] != "#":
        return False
    for d in diff:
        y2 = y + d[0]
        x2 = x + d[1]
        if y2 >= 0 and y2 < H and x2 >= 0 and x2 < W:
            if Sij[y2][x2] == "#":
                return False
    return True

out = "Yes"
for y in range(H):
    for x in range(W):
        if is_isolated(x, y):
            out = "No"
            break
print(out)

Submission status: Runtime Error

Solution code:
h, w = map(int, input().split())
s = [input() for i in range(n)]
for i in range(h):
  for j in range(w):
    if s[i][j] = "#":
      d = set()
      if i>0:
        d.add(s[i-1][j])
      if i<h-1:
        d.add(s[i+1][j])
      if j>0:
        d.add(s[i][j-1])
      if j<w-1:
        d.add(s[i][j+1])
      if "#" not in d:
        print("No")
        exit()
print("Yes")

Submission status: Runtime Error

Solution code:
H, W = map(int, input().split())
field = [list(input()) for i in range(H)]
flag = [[False] * H] * W
metaflag = []
dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]

for i in range(H):
    for j in range(W):
        if field[i][j] == '#':
            inflag = [False] * 4
            for k in range(4):
                ni = i + dx[k]
                nj = j + dy[k]
                if ni < 0 or ni >= H or nj < 0 or nj >= W:
                    inflag[k] = False
                elif field[ni][nj] == '#':
                    inflag[k] = True
            flag[i][j] = any(inflag)
        elif field[i][j] == '.':
            flag[i][j] = True
        metaflag.append(flag[i][j])

if all(metaflag):
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

Solution code:
import sys

H, W = map(int, input().split())
S = [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(S[i][j]=="."):
            continue
        exist = False
        for k in range(4):
            if(0<=i+dy[k]<H and 0<=j+dx[k]<W and S[i+dy[k]][j+dx[k]]=="#"):
                exist = True
        if(exist==False):
            print("No")
            sys.exit()     
if(exist==True):
    print("Yes")

Submission status: Runtime Error

Solution code:
import sys

H, W = map(int, input().split())
S = [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(S[i][j]=="."):
            continue
        exist = False
        for k in range(4):
            if(not 0<=i+dy[k]<H or not 0<=j+dx[k]<W):
                continue
            if(S[i+dy[k]][j+dx[k]]=="#"):
                exist = True
        if(exist==False):
            print("No")
            sys.exit()     
if(exist==True):
    print("Yes")

Submission status: Runtime Error

Solution code:
H, W = map(int, input().split())
S = [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(S[i][j]=="."):
            continue
        exist = False
        for k in range(4):
            if(not 0<=i+dy[k]<H or not 0<=j+dx[k]<W):
                continue
            if(S[i+dy[k]][j+dx[k]]=="#"):
                exist = True
        if(exist==False):
            print("No")
            break
            
if(exist==True):
    print("Yes")

Submission status: Runtime Error

Solution code:
H,W = map(int,input().split())
s = [input() for i in range(H)]
precount = 0
for i in range(H):
    precount += s[i].count("#")
if precount == 0:
    print("Yes")
else:
    ans = "Yes"
    dx = [1,0,-1,0]
    dy = [0,1,0,-1]
    for i in range(H):
        for j in range(W):
            if s[i][j] == "#":
               count = 0
               for k in range(4):
                   nx = j+dx[k]
                   ny = i+dy[k]
                   if 0 <= nx < W and 0 <= ny < H:
                      if s[ny][nx] == "#":
                         count += 1
               if count == 0:
                  ans = "No"

print(ans)

Submission status: Runtime Error

Solution code:
H,W = map(int,input().split())
s = [input() for i in range(H)]
ans = "No"
dx = [1,0,-1,0]
dy = [0,1,0,-1]
for i in range(0,H):
    for j in range(0,W):
        for k in range(4):
            nx = i+dx[k]
            ny = j+dy[k] 
            if s[i][j] == "#":
                if 0 <= nx < W and 0 <= ny < H:
                   if s[nx][ny] == "#":
                    ans = "Yes"

print(ans)

Submission status: Runtime Error

Solution code:
H,W = map(int,input().split())
s = [input() for i in range(H)]
ans = "No"
dx = [1,0,-1,0]
dy = [0,1,0,-1]
for i in range(0,H):
    for j in range(0,W):
        for k in range(4):
            nx = i+dx[k]
            ny = i+dy[k] 
            if s[i][j] == "#":
                if 0 <= nx < W and 0 <= ny < H:
                   if s[nx][ny] == "#":
                    ans = "Yes"

print(ans)

Submission status: Runtime Error

Solution code:
H,W = map(int,input().split())
s = [input() for i in range(H)]
ans = "No"
for i in range(1,W-1):
    for j in range(1,H-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] == "#":
                ans = "Yes"

print(ans)

Submission status: Runtime Error

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

ans = "Yes"
for i in range(H-1):
  for j in range(W-1):
    if(C[i][j] == "#"):
      if(i != 0 and C[i-1][j] == "#"):
        continue
      if(i != H and C[i+1][j] == "#"):
        continue
      if(j != 0 and C[i][j-1] == "#"):
        continue
      if(j != W and C[i][j+1] == "#"):
        continue
      ans = "No"
print(ans)

Submission status: Runtime Error

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

ans = "Yes"
for i in range(H):
  for j in range(W):
    if(C[i][j] == "."):
      continue
    if(i > 0 and C[i-1][j] == "#"):
      continue
    if(i+1 < H and C[i+1][j] == "#"):
      continue
    if(j > 0 and C[i][j-1] == "#"):
      continue
    if(j+1 < W and C[i][j+1] == "#"):
      continue
    ans = "No"
print(ans)

Submission status: Runtime Error

Solution code:
def repaint(h, w ,s):
    for i in (1, h+1):
        for p in (1, w+1):
            if s[i][p] == '#':
                if (s[i-1][p] != '#') and (s[i][p+1] != '#') and (s[i+1][p] != '#') and (s[i][p-1] != '#'):
                    return 'No'
    return 'Yes'
H, W = map(int, input().split())
S = [['.']*(w+2)]+[list('.'+input()+'.') for i in range(h)]+[['.']*(w+2)]
print(repaint(H, W, S))

Submission status: Runtime Error

Solution code:
def repaint(h, w):
    s = [[['.']*(w+2)]+[list('.'+input()+'.') for i in range(h)]+[['.']*(w+2)]]
    for i in (1, h+1):
        for p in (1, w+1):
            if s[i][p] == '#':
                if s[i-1][p] == s[i][p-1] == s[i+1][p] == s[i][p+1] == '.':
                    return 'No'
    return 'Yes'
H, W = map(int, input().split())
print(repaint(H, W))

Submission status: Runtime Error

Solution code:
H, W = map(int,input().split())
S = [list(input()) for _ in range(H)]
ans = "Yes"
for i in range(H):
  for j in range(W):
    if(S[i][j] == "#"):
      if(i != 0 and S[i-1][j] == "#"):
        continue
      if(i != H and S[i+1][j] == "#"):
        continue
      if(j != 0 and S[i][j-1] == "#"):
        continue
      if(j != W and S[i][j+1] == "#"):
        continue
      ans = "No"
print(ans)

Submission status: Runtime Error

Solution code:
H, W = map(int,input().split())
S = [list(input()) for _ in range(H)]
ans = "Yes"
for i in range(H):
  for j in range(W):
    if(S[i][j] == "#"):
      if(i != 0 and S[i-1][j] == "#"):
        continue
      if(i != H and S[i+1][j] == "#"):
        continue
      if(j != 0 and S[i][j-1] == "#"):
        continue
      if(j+1 < W and S[i][j+1] == "#"):
        continue
      ans = "No"
print(ans)

Submission status: Runtime Error

Solution code:
def main() -> None:
    H, W = map(int, input().split())
    s = ['0' + input() + '0' for _ in range(H)]
    s.insert(0, '0' * (W + 2))
    s.append('0' * (W + 2))
    num = 0
    # for v in s:
    #     print(v)
    for i in range(1, W + 1):
        for j in range(1, H + 1):
            # print(s[j][i])
            if s[i][j] == "#":
                num += 1
                if s[i+1][j] == "#" or s[i-1][j] == "#" or s[i][j+1] == "#" or s[i][j-1] == "#":
                    continue
                else:
                    print("No")
                    exit()
    if num == 0:
        print("No")
    else:
        print("Yes")


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
def main() -> None:
    H, W = map(int, input().split())
    s = ['0' + input() + '0' for _ in range(H)]
    s.insert(0, '0' * (W + 2))
    s.append('0' * (W + 2))
    for i in range(1, H + 1):
        for j in range(1, W + 1):
            if s[j][i] == "#":
                if s[j+1][i] == "#" or s[j-1][i] == "#" or s[j][i+1] == "#" or s[j][i-1] == "#":
                    continue
                else:
                    print("No")
                    exit()
    print("Yes")


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
def main() -> None:
    H, W = map(int, input().split())
    s = ['0' + input() + '0' for _ in range(H)]
    s.insert(0, '0' * (W + 2))
    s.append('0' * (W + 2))
    print(s)
    for v in s:
        print(v)
    for i in range(1, H + 1):
        for j in range(1, W + 1):
            if s[j][i] == "#":
                if s[j+1][i] == "#" or s[j-1][i] == "#" or s[j][i+1] == "#" or s[j][i-1] == "#":
                    continue
                else:
                    print("No")
                    exit()
    print("Yes")


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
def main() -> None:
    H, W = map(int, input().split())
    s = ['0' + input() + '0' for _ in range(W)]
    s.insert(0, '0' * (W + 2))
    s.append('0' * (W + 2))
    for i in range(1, H + 1):
        for j in range(1, W + 1):
            if s[j][i] == "#":
                if s[j+1][i] == "#" or s[j-1][i] == "#" or s[j][i+1] == "#" or s[j][i-1] == "#":
                    continue
                else:
                    print("No")
                    exit()
    print("Yes")


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
def main() -> None:
    H, W = map(int, input().split())
    s = ['0' + input() + '0' for _ in range(W)]
    s.insert(0, '0' * (W + 2))
    s.append('0' * (W + 2))
    for i in range(1, H):
        for j in range(1, W):
            if s[j][i] == "#":
                if s[j+1][i] == "#" or s[j-1][i] == "#" or s[j][i+1] == "#" or s[j][i-1] == "#":
                    pass
                else:
                    print("No")
                    exit()
    print("Yes")


if __name__ == '__main__':
    main()

Submission status: Runtime Error

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]=='#':
            if s[i-1][j]=='#' or s[i+1][j]=='#' or s[i][j-1]=='#' or s[i][j+1]=='#':
                continue
            else:
                print('No')
                exit()
print('Yes')

Submission status: Runtime Error

Solution code:
h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]
for i in range(h):
    for j in range(w):
        if s[i][j] == "#":
            f = False
            if 0 <= j+1 < h and 0 <= i < w and s[i][j+1] == "#":
                f = True
            if 0 <= j-1 < h and 0 <= i < w and s[i][j-1] == "#":
                f = True
            if 0 <= j < h and 0 <= i+1 < w and s[i+1][j] == "#":
                f = True
            if 0 <= j < h and 0 <= i-1 < w and s[i-1][j] == "#":
                f = True
            if not f:
                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)]
edge = [(0,1),(0,-1),(1,0),(-1,0)]
ans = []
for i in range(h):
    for j in range(w):
        if s[i][j] =="#":
            for x,y in edge:
                if 0<= i+x <w and 0<= j+y < h and s[i+x][j+y] =="#":break #三番目のforから抜け出す
            else:
                print("No")
                break #二番目
    else:continue
    break
else:print("Yes")

Submission status: Runtime Error

Solution code:
H, W = list(map(int, input().split()))
s = ['.'*(W+2)] + ['.'+input()+'.' for i in range(H)] + ['.'*(W+2)]

ans = 'Yes'
for y in range(1, W+1):
    for x in range(1, H+1):
        if s[y][x] == '#':
            if '.' == s[y][x+1] and '.' == s[y][x-1] and '.' == s[y+1][x] and '.' == s[y-1][x]:
                ans = 'No'
print(ans)

Submission status: Runtime Error

Solution code:
H, W = list(map(int, input().split()))
s = ['.'*(W+2)] + ['.'+input()+'.' for i in range(H)] + ['.'*(W+2)]

ans = 'Yes'
for y in range(1, W+1):
    for x in range(1, H+1):
        if s[y][x] == '#':
            if '#' not in [s[y][x+1], s[y][x-1], s[y+1][x], s[y-1][x]]:
                ans = 'No'
print(ans)

Submission status: Runtime Error

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

s = ['.' * (W+2)]
for i in range(H):
    s.append('.' + input() + '.')
s.append('.' * (W+2))

ans = True
for y in range(1, W+1):
    for x in range(1, H+1):
        if s[y][x] == '#':
            if '#' not in [s[y][x+1], s[y][x-1], s[y+1][x], s[y-1][x]]:
                ans = False
                break
    if not ans:
        break

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

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
import sys
# ----------------------------------------------------------------
# Use Solve Function

def solve(lines):
    def solve_iter(hi, wi):
        vec = [(0,1),(0,-1),(1,0),(-1,0)]
        for v in vec:
            hn = hi + v[0]
            wn = wi + v[1]
            if hn >= 0 and hn < H and wn >= 0 and wn < W:
                if NLIST[hn][wn] == '#':
                    NLIST[hi][wi] = '.'
                    NLIST[hn][wn] = '.'
                    solve_iter(hn, wn)
        return

    H,W = map(int, lines.pop(0).split(' '))
    NLIST = []
    for i in range(H):
        NLIST.append(list(lines.pop(0)) )

    res = 'Yes'
    for i in range(H):
        for j in range(W):
            if NLIST[i][j] == '#':
                solve_iter(i, j)
            if NLIST[i][j] == '#':
                res = 'No'

    print(res)

#
# main
#
lines = [x.strip() for x in sys.stdin.readlines()]

#
# solve !!
#
solve(lines)

Submission status: Runtime Error

Solution code:
from sys import stdin
h, w = [int(x) for x in stdin.readline().rstrip().split()]
matrix = [stdin.readline().rstrip() for _ in range(h)]
for i in range(h):
    matrix[i] = [matrix[i][x:x+1] for x in range(len(matrix[i]))]
    #matrix[i] = [0 if x == '.' else x for x in matrix[i]]
#print(matrix)
for i in range(h):
    for j in range(w):
        if matrix[i][j] == '#':
            flag = 0
            for n in list([-1, 1]):
                i_n = i + n
                j_n = j + n
                if matrix[i_n][j] == '#' and i_n >= 0 and i_n < h:
                    flag = 1
                    break
                if matrix[i][j_n] == '#' and j_n >= 0 and j_n < w:
                    flag = 1
                    break
            if flag == 0:
                print('No')
                exit()
print('Yes')
#print(*matrix, sep = '\n')

Submission status: Runtime Error

Solution code:
from sys import stdin
h, w = [int(x) for x in stdin.readline().rstrip().split()]
matrix = [stdin.readline().rstrip() for _ in range(h)]
for i in range(h):
    matrix[i] = [matrix[i][x:x+1] for x in range(len(matrix[i]))]
    #matrix[i] = [0 if x == '.' else x for x in matrix[i]]
print(matrix)
for i in range(h):
    for j in range(w):
        if matrix[i][j] == '#':
            flag = 0
            for n in list[-1, 1]:
                i_n = i + n
                j_m = j + m
                if matrix[i_n][j] == '#' and i_n >= 0 and i_n < h:
                    flag = 1
                    break
                if matrix[i][j_m] == '#' and j_m >= 0 and j_m < w:
                    flag = 1
                    break
            if flag == 0:
                print('No')
                exit()
print('Yes')
#print(*matrix, sep = '\n')

Submission status: Runtime Error

Solution code:
h,w = map(int, input().split())
s = []
for i in range(w):
    s.append(str(input()))
    
flag = True
for i in range(h):
    for j in range(w):
        if s[i][j] == '#':
            check = False
            if i+1 < h:
                if s[i+1][j] == '#':
                    check = True
            if j+1 < w:
                if s[i][j+1] == '#':
                    check = True
            if i-1 >= 0:
                if s[i-1][j] == '#':
                    check = True
            if j-1 >= 0:
                if s[i][j-1] == '#':
                    check = True
            if check == False:
                flag = False
if flag:
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

Solution code:
# https://atcoder.jp/contests/abc096/tasks/abc096_c

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

# 隣に # が一つ以上あるかどうか
def has_neighbor(y, x):
    dhs = [1, -1, 0, 0]
    dws = [0, 0, 1, -1]
    for dh, dw in zip(dhs, dws):
        if S[y + dh][x + dw] == "#":
            return True
    return False


for h in range(H):
    for w in range(W):
        if S[h][w] == "#":
            if not has_neighbor(h, w):
                print("No")
                exit()

print("Yes")

Submission status: Runtime Error

Solution code:
H, W = map(int, input().split())
M = ['.' * (W+2)]
for _ in range(H):
    M.append('.' + input() + '.')
M.append('.' * (H+2))
flag = True
for i in range(1, H+1):
    for j in range(1, W+1):
        if M[i][j] == '#':
            if '#' not in (M[i+1][j], M[i][j+1], M[i-1][j], M[i][j-1]):
                flag = False
if flag:
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

Solution code:
H, W = map(int, input().split())
M = ['.' * (W+2)]
for _ in range(H):
    M.append('.' + input() + '.')
M.append('.' * (H+2))
flag = True
for i in range(1, H+1):
    for j in range(1, W+1):
        if M[i][j] == '#':
            if '#' not in (M[i+1][j], M[i][j+1], M[i-1][j], M[i][j-1]):
                flag = False
                break
    if flag == False:
        break
if flag:
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

Solution code:
hw=[int(i) for i in input().split()]
s=['.'+input()+'.' for i in range(hw[0])]
s=['.'*(hw[1]+2)]+s+['.'*(hw[1]+2)]
for i in range(1,hw[1]+1):
    for n in range(1,hw[0]+1):
        if s[i][n]=='#':
            if s[i+1][n]=='.' and s[i][n+1]=='.' and s[i-1][n]=='.' and s[i][n-1]=='.':
                print('No')
                exit()
print('Yes')

Submission status: Runtime Error

Solution code:
def g2():
    hw=[int(i) for i in input().split()]
    s=['.'+input()+'.' for i in range(hw[0])]
    s=['.'*(hw[1]+2)]+s+['.'*(hw[1]+2)]
    for i in range(1,hw[1]+1):
        for n in range(1,hw[0]+1):
            if s[i][n]=='#':
                if s[i+1][n]=='.' and s[i][n+1]=='.' and s[i-1][n]=='.' and s[i][n-1]=='.':
                    print('No')
                    exit()
    print('Yes')
    exit()
print(g2())

Submission status: Runtime Error

Solution code:
from itertools import product
import numpy as np
h, w = map(int, input().split())
c = np.array(
    [[0 if i == "." else 1 for i in input()] for j in range(h)])

dxt = (1, 0, -1, 0)
dyt = (0, 1, 0, -1)

for i, j in product(range(h), range(w)):
    if c[i, j] == 1:
        ok = False
        for dx, dy in zip(dxt, dyt):
            p, q = i+dx, j+dy
            p, q = max(p, 0), max(q, 0)
            p, q = min(p, h-1), min(q, w-1)
            if c[p, q] == 1:
                ok = True
                break
        if ok is False:
            break
print('Yes') if ok else print('No')

Submission status: Runtime Error

Solution code:
H,W = map(int,input().split())
lis = ['.' +input()+'.' for _ in range(H)]
lis.insert(0,'.'*W)
lis.append('.'*W)
for i in range(1,H+1):
    for j in range(1,W+1):
        if lis[i][j] == '#':
            if lis[i+1][j]=='#' or lis[i-1][j]=='#' or lis[i][j+1]=='#' or lis[i][j-1] == '#':
                continue
            else:
                print('No')
                exit()
print('Yes')

Submission status: Runtime Error

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

shw = [list(map(str, input())) for _ in range(W)]

        

for i in range(1,H-1):
    for j in range(1,W-1):
        if shw[i][j] == str('#'):
            if shw[i][j] != shw[i+1][j] and shw[i][j] != shw[i][j+1] and shw[i][j] != shw[i-1][j] and shw[i][j] != shw[i][j-1]:
                print("No")
                exit()
print("Yes")

Submission status: Runtime Error

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

if ''.join(S).count('#') <= 1:
    print("Yes")
    quit()

for y in range(1, H + 1):
    for x in range(1, W + 1):
        if S[y][x] == '#' and set([S[y - 1][x], S[y + 1][x], S[y][x - 1], S[y][x + 1]]) == set('.'):
            print("No")
            quit()
print("Yes")

Submission status: Runtime Error

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

for y in range(1, H + 1):
    for x in range(1, W + 1):
        if S[y][x] == '#' and \
        set([S[y - 1][x], S[y + 1][x], S[y][x - 1], S[y][x + 1]]) == set('.'):
            print("No")
            quit()
print("Yes")

Submission status: Runtime Error

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

    for y in range(1, H + 1):
        for x in range(1, W + 1):
            if S[y][x] == '#' and \
            set([S[y - 1][x], S[y + 1][x], S[y][x - 1], S[y][x + 1]]) == set('.'):
                print("No")
                return
    print("Yes")

main()

Submission status: Runtime Error

Solution code:
H, W = map(int, input().split())
s = [list(input()) for i in range(W)]
for i in range(H):
    for j in range(W):
        if s[i][j] == "#":
            count = 4
            if i == 0:
                pass
            else:
                if s[i-1][j] != "#":
                    count -= 1
            if j == 0:
                pass
            else:
                if s[i][j-1] != "#":
                    count -= 1
            if i == H-1:
                pass
            else:
                if s[i+1][j] != "#":
                    count -= 1
            if j == W-1:
                pass
            else:
                if s[i][j+1] != "#":
                    count -= 1
            if count == 0:
                print("No")
                exit()
print("Yes")

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import sys
H, W = map(int, input().split())
s = [input() for i in range(W)]
for i in range(1, H-1):
    for j in range(1, W-1):
        if s[i][j] == "#":
            if s[i-1][j] == "#" or s[i+1][j] == "#" or s[i][j-1] == "#" or s[i][j+1] == "#":
                print("Yes")
                exit()
print("No")

Submission status: Runtime Error

Solution code:
H, W = map(int, input().split())
s = [input() for i in range(W)]
for i in range(1, H-1):
    for j in range(1, W-1):
        if s[i][j] == "#":
            if s[i-1][j] == "#" or s[i+1][j] == "#" or s[i][j-1] == "#" or s[i][j+1] == "#":
                print("Yes")
                exit()
print("No")

Submission status: Runtime Error

Solution code:
H, W = map(int, input().split())
edge = '.' * (W + 2)
field = [edge]
for _ in range(H):
    field.append('.' + input() + '.')
field.append(edge)
for i in range(1, H + 1):
    for j in range(1, W + 1):
        if C[i][j] == '.':
            continue
        if '#' not in [C[i - 1][j], C[i][j - 1], C[i][j + 1], C[i + 1][j]]:
            print('No')
            exit()
print('Yes')

Submission status: Runtime Error

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

isPaintable = True
for y in range(h):
    for x in range(w):
        if s[x][y]=="#":
            if x-1>=0 and s[x-1][y]=="#":
                continue
            elif y-1>=0 and s[x][y-1]=="#":
                continue
            elif x+1<w and s[x+1][y]=="#":
                continue
            elif y+1<h and s[x][y+1]=="#":
                continue
            isPaintable=False
if isPaintable:
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

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

isPaintable = True
for y in range(h):
    for x in range(w):
        if s[x][y]=="#":
            if x-1>=0 and s[x-1][y]=="#":
                continue
            elif y-1>=0 and s[x][y-1]=="#":
                continue
            elif x+1<w and s[x+1][y]=="#":
                continue
            elif y+1<h and s[x][y+1]=="#":
                continue
            isPaintable=False
if isPaintable:
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

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

gri = [[0 for i in range(w+2)] for _ in range(h+2)]
for i in range(h+2):
    for j in range(w+2):
        if i == 0 or i == h+1 or j == 0 or j == w+1:
            gri[i][j] = '.'
        else:
            gri[i][j] = l[i-1][j-1]


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

print("Yes")