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 sys
from itertools import accumulate
from functools import reduce
import queue
from fractions import gcd

def lcm(a, b):
    return a * b // gcd(a, b)

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

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

sys.setrecursionlimit(10000)

mod = 1000000007

"""
# 0埋め, 小数点出力桁指定時のときの出力
a = 100
b = 0.987654321
print("{0:06d}-{1:6f}".format(a,b))
000100-0.987654

# 文字列をリストに格納
char_list = list("abcd") # ["a","b","c","d"]

# 標準入力取得
## 文字列
    = sys.stdin.readline().rstrip()
    = list(sys.stdin.readline().rstrip())
    = [list(list(sys.stdin.readline().rstrip())) for i in range(h)] #文字列を分解して二次元配列入力

## 数値
    = int(sys.stdin.readline())
    = map(int, sys.stdin.readline().split())
    = list(map(int, sys.stdin.readline().split()))
    = [list(map(int,list(sys.stdin.readline().split()))) for i in range(h)]  # 二次元配列入力　二次元マップみたいな入力のとき
"""

if __name__ == "__main__":
    h,w = map(int, sys.stdin.readline().split())
    s =  [list(list(sys.stdin.readline().rstrip())) for i in range(h)]
    flag=0
    for i in range(h):
        for j in range(w): #２重for文で行列を一つずつ確認
            if s[i][j] == "#":
                if s[i-1][j] =="." and s[i+1][j] =="." and s[i][j-1] =="."  and s[i][j+1] ==".":#上下左右塗れなかった時
                    flag = 1
                    print("No")
                    exit()
    print("Yes" if flag==0 else "No")

Submission status: Runtime Error

Solution code:
import math
import sys
from itertools import accumulate
from functools import reduce
import queue
from fractions import gcd

def lcm(a, b):
    return a * b // gcd(a, b)

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

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

sys.setrecursionlimit(10000)

mod = 1000000007

"""
# 0埋め, 小数点出力桁指定時のときの出力
a = 100
b = 0.987654321
print("{0:06d}-{1:6f}".format(a,b))
000100-0.987654

# 文字列をリストに格納
char_list = list("abcd") # ["a","b","c","d"]

# 標準入力取得
## 文字列
    = sys.stdin.readline().rstrip()
    = list(sys.stdin.readline().rstrip())
    = [list(list(sys.stdin.readline().rstrip())) for i in range(h)] #文字列を分解して二次元配列入力

## 数値
    = int(sys.stdin.readline())
    = map(int, sys.stdin.readline().split())
    = list(map(int, sys.stdin.readline().split()))
    = [list(map(int,list(sys.stdin.readline().split()))) for i in range(h)]  # 二次元配列入力　二次元マップみたいな入力のとき
"""

if __name__ == "__main__":
    h,w = map(int, sys.stdin.readline().split())
    s =  [list(list(sys.stdin.readline().rstrip())) for i in range(h)]
    flag=0
    for i in range(h):
        for j in range(w):
            if s[i][j] == "#":
                if s[i-1][j] =="." and s[i+1][j] =="." and s[i][j-1] =="."  and s[i][j+1] ==".":
                    flag = 1
    print("Yes" if flag==0 else "No")

Submission status: Runtime Error

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

for i in range(W):
    S='.'+input()+'.'
    A.append(S)
K='.'
A.insert(0,K*(H+2))
A.append(K*(H+2))
for j in range(1,H):
    for i in range(1,W):
        if A[i][j]=='#':
            if A[i+1][j]=='.' and A[i-1][j]=='.' and A[i][j+1]=='.' and A[i][j-1]=='.':
                print('No')
                exit(0)

print('Yes')

Submission status: Runtime Error

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

count = [[0] * W for _ in range(H)]
for i in range(H):
    for j in range(W):
        if S[i][j] == '.':
            count[i][j] = 10**7
        else:
            count[i][j] = 0

for i in range(H):
    for j in range(W):
        if S[i][j] == '#':
            if j != W-1 and S[i][j+1] == '#':
                count[i][j] += 1
            if j != 0 and S[i][j-1] == '#':
                count[i][j] += 1
            if i != W-1 and S[i+1][j] == '#':
                count[i][j] += 1
            if i != 0 and S[i-1][j] == '#':
                count[i][j] += 1

check = 0
for i in range(H):
    for j in range(W):
        if count[i][j] < 1:
            check = 1

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

Submission status: Runtime Error

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

for i in range(W):
    S='.'+input()+'.'
    A.append(S)
K='.'
A.insert(0,K*(W+2))
A.append(K*(W+2))

for i in range(1,H):
    for j in range(1,W):
        if A[i][j]=='#':
            if A[i+1][j]=='.' and A[i-1][j]=='.' and A[i][j+1]=='.' and A[i][j-1]=='.':
                print('No')
                exit(0)

print('Yes')

Submission status: Runtime Error

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

for i in range(W):
    A.append(input())

for i in range(H):
    for j in range(W):
        flag = 0
        if A[i][j]=='#':
            if i!=0:
                if A[i-1][j]=='#':
                    flag=1
            if i != H-1:
                if A[i + 1][j] == '#':
                    flag = 1
            if j != 0:
                if A[i][j-1] == '#':
                    flag = 1
            if j != W-1:
                if A[i][j+1] == '#':
                    flag = 1
            if flag==0:
                print('No')
                exit(0)
print('Yes')

Submission status: Runtime Error

Solution code:
val = input()
val = [int(x.strip()) for x in val.split(" ")]
h = val[0]
w = val[1]

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

ans = "Yes"

for i in range(h):
    for j in range(w):
        d = 0
        if s[i][j] == ".":
            continue

        if i > 0:
            if s[i-1][j] == "#":
                d += 1

        if i < h-1:
            if s[i+1][j] == "#":
                d += 1

        if j > 0:
            if s[i][j-1] == "#":
                d += 1

        if j < h-1:
            if s[i][j+1] == "#":
                d += 1
        
        if d == 0:
            ans = "No"
            break
    if ans == "No":
        break

print(ans)

Submission status: Runtime Error

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

S.insert(0, '.'*(W+2))
S.insert(H+1, '.'*(W+2))

flg = 0
for i in range(1, W+1):
    for j in range(1, H+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]=='.':
                flg = 1
                break
    else:
        continue
    break
    
if flg==0:
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

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

S.insert(0, '.'*(W+2))
S.insert(H+1, '.'*(W+2))

flg = 0
for i in range(1, W+1):
    for j in range(1, H+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]=='.':
                flg = 1

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

Submission status: Runtime Error

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

S.insert(0, '.'*(W+2))
S.insert(H+1, '.'*(W+2))

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

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

Submission status: Runtime Error

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

S.insert(0, '.'*(W+2))
S.insert(H+1, '.'*(W+2))

flg = 0
for i in range(1, W+1):
    for j in range(1, H+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]=='.':
                flg = 1
                break

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

Submission status: Runtime Error

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

S.insert(0, '.'*(W+2))
S.insert(H+1, '.'*(W+2))

for i in range(1, W+1):
    for j in range(1, H+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
            
print('Yes')

Submission status: Runtime Error

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

ans = "Yes"

for y in range(h):
    for x in range(w):
        if sL[y][x] == ".":
            continue
        for dx, dy in dxy:
            if y-1 < 0 or y+1 > h-1 or x-1 < 0 or x+1 > w-1:
                continue
            if sL[y+1][x] == sL[y-1][x]  == sL[y][x+1] == sL[y][x-1] == ".":
                ans = "No"
                break

print(ans)

Submission status: Runtime Error

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

# print(s)
# print(s[1][1])

ok = True
for hi in range(h):
    for wi in range(w):
        if s[hi][wi] == '#':
            drawable = False
            # check
            if hi >= 1:
                drawable = (s[hi-1][wi] == '#') | drawable
            
            if hi <= h-2:
                drawable = (s[hi+1][wi] == '#') | drawable
            
            if wi >= 1:
                drawable = (s[hi][wi-1] == '#') | drawable
            
            if wi <= w-2:
                drawable = (s[hi][wi+1] == '#') | drawable

            # if hi >= 1:
            #     if s[hi-1][wi] == 

            if not drawable:
                ok = False

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

Submission status: Runtime Error

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

# print(s)
# print(s[1][1])

ok = True
for hi in range(h):
    for wi in range(w):
        if s[hi][wi] == '#':
            drawable = False
            # check
            if hi >= 1:
                drawable = (s[hi-1][wi] == '#') | drawable
            
            if hi <= h-2:
                drawable = (s[hi+1][wi] == '#') | drawable
            
            if wi >= 1:
                drawable = (s[hi][wi-1] == '#') | drawable
            
            if wi <= w-2:
                drawable = (s[hi][wi+1] == '#') | drawable

            if not drawable:
                ok = False

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

Submission status: Runtime Error

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

# print(s)
# print(s[1][1])

ok = True
for hi in range(h):
    for wi in range(w):
        if s[hi][wi] == '#':
            drawable = False
            # check
            if hi > 0:
                drawable = (s[hi-1][wi] == '#') | drawable
            
            if hi < h-1:
                drawable = (s[hi+1][wi] == '#') | drawable
            
            if wi > 0:
                drawable = (s[hi][wi-1] == '#') | drawable
            
            if wi < w-1:
                drawable = (s[hi][wi+1] == '#') | drawable

            if not drawable:
                ok = False

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

Submission status: Runtime Error

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

# print(s)
# print(s[1][1])

ok = True
for hi in range(h):
    for wi in range(w):
        if s[hi][wi] == '#':
            drawable = False
            # check
            if hi > 0:
                drawable = (s[hi-1][wi] == '#') | drawable
            
            if hi < h-1:
                drawable = (s[hi+1][wi] == '#') | drawable
            
            if wi > 0:
                drawable = (s[hi][wi-1] == '#') | drawable
            
            if wi < w-1:
                drawable = (s[hi][wi+1] == '#') | drawable

            if not drawable:
                ok = False
                break

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

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
import sys, math, fractions, itertools

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

def solve(H: int, W: int, s: "List[str]"):
    flag = True
    for h in range(H):
        for w in range(W):
            if s[h][w] == '#':
                if h == H-1: U = True
                else: U = s[h+1][w] != '#'
                if h == 0: D = True
                else: D = s[h-1][w] != '#'
                if w == 0: L = True
                else: L = s[h][w-1] != '#'
                if w == W-1: R = True
                else: R = s[h][w+1] != '#'
                if all([U, D, L, R]):
                    flag = False
    if flag:
        print('Yes')
    else:
        print('No')
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
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:
#!/usr/bin/env python3
import sys, math, fractions, itertools

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

def solve(H: int, W: int, s: "List[str]"):
    flag = True
    for h in range(H):
        for w in range(W):
            if s[h][w] == '#':
                if h == H-1: U = False
                else: U = s[h+1][w] != '#'
                if h == 0: D = False
                else: D = s[h-1][w] != '#'
                if w == 0: L = False
                else: L = s[h][w-1] != '#'
                if w == W-1: R = False
                else: R = s[h][w+1] != '#'
                if all([U, D, L, R]):
                    flag = False
    if flag:
        print('Yes')
    else:
        print('No')
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
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())
grids = []
for i in range(h):
    grids.append(input())
    
start = []
for i in range(len(grids)):
    if "#" in grids[i]:
        start = [i, grids[i].index("#")]
        break

if len(start) == 0:
    print("No")
    quit

queue = [start]
check = [start]
ans = "No"
while len(queue) != 0:
    x, y = queue[0][0], queue[0][1]
    queue.pop(0)

    if x > 0:
        if grids[x-1][y] == "#" and [x-1, y] not in check:
            queue.append([x-1, y])
            check.append([x-1, y])
    if x < h-1:
        if grids[x+1][y] == "#" and [x+1, y] not in check:
            queue.append([x+1, y])
            check.append([x+1, y])
    if y > 0:
        if grids[x][y-1] == "#" and [x, y-1] not in check:
            queue.append([x, y-1])
            check.append([x, y-1])
    if y < w-1:
        if grids[x][y+1] == "#" and [x, y+1] not in check:
            queue.append([x, y+1])
            check.append([x, y+1])

cnt = 0
for grid in grids:
    cnt += grid.count("#")
    
if cnt == len(check):
    ans = "Yes"
print(ans)

Submission status: Runtime Error

Solution code:
h, w = map(int,input().split())
grids = []
for i in range(h):
    grids.append(input())
    
start = []
for i in range(len(grids)):
    if "#" in grids[i]:
        start = [i, grids[i].index("#")]
        break

if len(start) == 0:
    quit

queue = [start]
check = [start]
ans = "No"
while len(queue) != 0:
    x, y = queue[0][0], queue[0][1]
    queue.pop(0)

    if x > 0:
        if grids[x-1][y] == "#" and [x-1, y] not in check:
            queue.append([x-1, y])
            check.append([x-1, y])
    if x < h-1:
        if grids[x+1][y] == "#" and [x+1, y] not in check:
            queue.append([x+1, y])
            check.append([x+1, y])
    if y > 0:
        if grids[x][y-1] == "#" and [x, y-1] not in check:
            queue.append([x, y-1])
            check.append([x, y-1])
    if y < w-1:
        if grids[x][y+1] == "#" and [x, y+1] not in check:
            queue.append([x, y+1])
            check.append([x, y+1])

cnt = 0
for grid in grids:
    cnt += grid.count("#")
    
if cnt == len(check):
    ans = "Yes"
print(ans)

Submission status: Runtime Error

Solution code:
h, w = map(int,input().split())
grids = []
for i in range(h):
    grids.append(input())
    
start = []
for i in range(len(grids)):
    if "@" in grids[i]:
        start = [i, grids[i].index("#")]

if len(start) == 0:
    quit
    
queue = [start]
check = []
ans = "No"
while len(queue) != 0:
    x, y = queue[0][0], queue[0][1]
    queue.pop(0)

    if x > 0:
        if grids[x-1][y] == "#" and [x-1, y] not in check:
            queue.append([x-1, y])
            check.append([x-1, y])
    if x < h-1:
        if grids[x+1][y] == "#" and [x+1, y] not in check:
            queue.append([x+1, y])
            check.append([x+1, y])
    if y > 0:
        if grids[x][y-1] == "#" and [x, y-1] not in check:
            queue.append([x, y-1])
            check.append([x, y-1])
    if y < w-1:
        if grids[x][y+1] == "#" and [x, y+1] not in check:
            queue.append([x, y+1])
            check.append([x, y+1])

cnt = 0
for grid in grids:
    cnt += grid.count("#")
    
if cnt == len(check):
    ans = "Yes"
print(ans)

Submission status: Runtime Error

Solution code:
h, w = map(int,input().split())
grids = []
for i in range(h):
    grids.append(input())
    
start = []
for i in range(len(grids)):
    if "@" in grids[i]:
        start = [i, grids[i].index("@")]

if len(start) == 0:
    quit
    
queue = [start]
check = []
ans = "No"
while len(queue) != 0:
    x, y = queue[0][0], queue[0][1]
    queue.pop(0)

    if x > 0:
        if grids[x-1][y] == "#" and [x-1, y] not in check:
            queue.append([x-1, y])
            check.append([x-1, y])
    if x < h-1:
        if grids[x+1][y] == "#" and [x+1, y] not in check:
            queue.append([x+1, y])
            check.append([x+1, y])
    if y > 0:
        if grids[x][y-1] == "#" and [x, y-1] not in check:
            queue.append([x, y-1])
            check.append([x, y-1])
    if y < w-1:
        if grids[x][y+1] == "#" and [x, y+1] not in check:
            queue.append([x, y+1])
            check.append([x, y+1])

cnt = 0
for grid in grids:
    cnt += grid.count("#")
    
if cnt == len(check):
    ans = "Yes"
print(ans)

Submission status: Runtime Error

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

s1=[['.' for i in range(h+2)] for i in range(w+2)]

for i in range(h):
    for j in range(w):
        if s[i][j]=='#':
            s1[i+1][j+1]='#'
for i in range(h+2):
    for j in range(w+2):
        if s1[i][j]=='#':
            if s1[i-1][j]==s1[i+1][j]==s1[i][j-1]==s1[i][j+1]=='.':
                print('No')
                exit()
print('Yes')

Submission status: Runtime Error

Solution code:
H, W = map(int, input().split())
campus = [list(map(int, input().split())) for _ in range(H)]
ans = [[0] * (W) for _ in range(H)]

for i in range(H):
  before = ''
  for j in range(W):
    if campus[i][j] == before and campus[i][j] == '#':
      ans[il[j-1], ans[i][j] = 0, 0
    elif campus[i][j] == '#':
      ans[i][j] = 1
    before = campus[i][j]
for j in range(W):
  before = ''
  for i in range(H):
    if campus[i][j] == before and campus[i][j] == '#':
      ans[i-1][j], ans[i][j] = 0, 0
    elif campus[i][j] == '#':
      ans[i][j] = 1
    before = campus[i][j]
finish = 'Yes'
for i in range(H):
  for j in range(W):
    if ans[i][j] == 1:
      finish = 'No'
      break
   else:
     continue
   break
prin(finish)

Submission status: Runtime Error

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

def drow(i,j, map = map):
  if j > 0 and map[i][j-1] == "#":
    return "Yes"
  if j < W-1 and map[i][j+1] == "#":
    return "Yes"
  if i > 0 and map[i-1][j] == "#":
    return "Yes"
  if i < H -1 and map[i+1][j] == "#":
    return "Yes"
  return "No"


for i in range(H):
  for j in range(W):
    if map[i][j] == "#":
      ans = drow(i,j)
      if ans == "No":
        break
if H == 1 and W == 1:
  ans = "No"
  if map[0][0] == "#":
    ans = "Yes"
print(ans)

Submission status: Runtime Error

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

def drow(i,j, map = map):
  if j > 0 and map[i][j-1] == ".":
    return "No"
  if j < W-1 and map[i][j+1] == ".":
    return "No"
  if i > 0 and map[i-1][j] == ".":
    return "No"
  if i < H -1 and map[i+1][j] == ".":
    return "No"
  return "Yes"

for i in range(H):
  for j in range(W):
    if map[i][j] == "#":
      ans = drow(i,j)
      if ans == "No":
        break
print(ans)

Submission status: Runtime Error

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

def drow(i,j, map = map):
  if j > 0 and map[i][j-1] == "#":
    return "Yes"
  if j < W-1 and map[i][j+1] == "#":
    return "Yes"
  if i > 0 and map[i-1][j] == "#":
    return "Yes"
  if i < H -1 and map[i+1][j] == "#":
    return "Yes"
  return "No"

if H == 1 and W==1:
  if map[0][0] =="#":
    ans = "Yes"
  else:
    ans = "No"

for i in range(H):
  for j in range(W):
    if map[i][j] == "#":
      ans = drow(i,j)
      if ans == "No":
        break
print(ans)

Submission status: Runtime Error

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

def drow(i,j, map = map):
  if j > 0 and map[i][j-1] == "#":
    return "YES"
  if j < W-1 and map[i][j+1] == "#":
    return "YES"
  if i > 0 and map[i-1][j] == "#":
    return "YES"
  if i < H -1 and map[i+1][j] == "#":
    return "YES"
  return "NO"
    

for i in range(H):
  for j in range(W):
    if map[i][j] == "#":
      ans = drow(i,j)
      if ans == "NO":
        break
print(ans)

Submission status: Runtime Error

Solution code:
H, W = map(int, input().split())
state = [[1 if a == '#' else 0 for a in list(input()+'.')] for _ in range(H)]
state.extend([[0]*(W+1)])

ans = 'Yes'
for h in range(H):
    for w in range(W):
        if state[h][w] == 0:
            continue
        nexts = [[h+1, w], [h-1, w], [h, w+1], [h, w-1]]
        ok = False
        for n in nexts:
            if state[n[0]][n[1]] == 1:
                ok = True
        if not ok:
            ans = 'No'
            break
    if not ok:
        break

print(ans)

Submission status: Runtime Error

Solution code:
# 行数Hおよび列数Wを入力する
H, W = map(int, input().split())
# マスを初期化する（ワンサイズ大きめに作成する）
s = ["." * (W + 2) for _ in range(H + 2)]
# マスを入力する
for i in range(1, H + 1):
    s[i] = input()
# 判定を初期化する
judge = "Yes"
# 各マスについて、黒く塗れるかを調べる
for i in range(1, H + 1):
    for j in range(1, W + 1):
        # 黒く塗らないマスの場合、以降の処理は行わずに次のマスに移る
        if s[i][j] == ".":
            continue
        # 上下左右に黒く塗るべきマスがない場合、塗り分け不可能
        if s[i - 1][j] + s[i][j - 1] + s[i][j + 1] + s[i + 1][j] == "....":
            # 判定を更新する
            judge = "No"
            # マスの調査を終了する
            break
# 判定を出力する
print(judge)

Submission status: Runtime Error

Solution code:
h, w = map(int, input().split())
s = [list(input()) for i in range(h)]
for x in range(h):
    for y in range(w):
        if(s[x][y] == '#'):
            up = s[max(0, x-1)][y]
            down = s[min(h-1, x+1)][y]
            right = s[x][max(0, y-1)]
            left = s[x][max(w-1,  y+1)]
            if(up == '.' and down == '.' and right == '.' and left == '.'):
                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 x in range(h):
    for y in range(w):
        if(s[x][y] == '#'):
            up = s[max(0, x-1)][y]
            down = s[min(x+1, h-1)][y]
            right = s[x][max(0, y-1)]
            left = s[x][max(y+1, w-1)]
            if(up == '.' and down == '.' and right == '.' and left == '.'):
                print("No")
                exit()
print("Yes")

Submission status: Runtime Error

Solution code:
row = list(map(int, input().split()))
s = [input().split() for i in range(row[0])]
for i in range(row[0]):
    s[i] = list(s[i][0])
dx = [0, -1, 1, 0]
dy = [-1, 0, 0, 1]
for i in range(row[0]):
    for j in range(row[1]):
        if s[i][j] == "#":
            Flag = False
            for d in range(4):
                nx = i + dx[d]
                ny = j + dy[d]
                if 0 <= nx < row[0] and 0<= ny < row[1]:
                    if s[nx][ny] == "#":
                        Flag = True
                        break
            if Flag != True:
                break
    if Flag != True:
        print("No")
        break
if Flag:
    print("Yes")

Submission status: Runtime Error

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

mp = []
for i in range(h):
    tmp = list(input())
    tml = []
    for j in range(w):
        tml.append(0 if tmp[j] == "." else 1)
    mp.append(tml)

flg = 0
for i in range(1,h-1):
    for j in range(1,w-1):
        if(mp[i-1][j]+mp[i+1][j]+mp[i][j-1]+mp[i][j+1] == 0):
            flag = 1
            break
        
ans = ["YES","NO"]
		
print(ans[flag])

Submission status: Runtime Error

Solution code:
h, w = map(int, input().split())
s = ['.'*(h+2)] + ['.' + input() + '.' for i in range(h)] + ['.'*(h+2)]
d = [[1, 0], [0, 1], [-1, 0], [0, -1]]

ans = 0
for i in range(1, h+1):
    for j in range(1, w+1):
        if s[i][j] == '.':
            continue
        c = 0
        for k in range(4):
            if s[i+d[k][0]][j+d[k][1]] == "#":
                c += 1
        if c == 0:
            ans = -1

if ans == -1:
    print("No")
else:
    print("Yes")

Submission status: Runtime Error

Solution code:
h, w = map(int, input().split())
cam = [input() for _ in range(h)]
painted = [[False for i in range(w)] for j in range(h)]

def dfs(x, y):
    global cnt
    if x < 0 or y < 0 or x > h-1 or y > w-1:
        return
    elif cam[x][y] == ".":
        return
    elif painted[x][y]:
        return
    cnt += 1
    painted[x][y] = True
    dfs(x-1, y)
    dfs(x, y-1)
    dfs(x+1, y)
    dfs(x, y+1)
    
for i in range(h):
    for j in range(w):
        cnt = 0
        if cam[i][j] == "#":
            dfs(i, j)
        if cnt == 1:
            painted[i][j] = False
            
flag = False
for i in range(h):
    for j in range(w):
        if cam[i][j] == "#":
            if not painted[i][j]:
                flag = True
                break
        elif cam[i][j] == ".":
            if painted[i][j]:
                flag = True
                break
    if flag:
        break
if flag:
    print("No")
else:
    print("Yes")

Submission status: Runtime Error

Solution code:
import sys
H, W = map(int, input().split())
S = [input() for i in range(H)]
drawable = True


def can_draw(y, x):
    is_connected = False
    if S[y][x] == '.':
        return True

    dl = [(-1, 0), (0, 1), (1, 0), (0, -1)]
    for dy, dx in dl:
        if not(0 <= y + dy < W) or not(0 <= x + dx < H):
            continue
        if S[y + dy][x + dx] == '#':
            is_connected = True
            break
    return is_connected


for i in range(len(S)):
    for j in range(len(S[i])):
        if not can_draw(i, j):
            print('No')
            sys.exit()

print('Yes')

Submission status: Runtime Error

Solution code:
import sys
H, W = map(int, input().split())
S = [input() for i in range(H)]
drawable = True


def can_draw(y, x):
    is_connected = False
    if S[y][x] == '.':
        return True

    dl = [(-1, 0), (0, 1), (1, 0), (0, -1)]
    for dy, dx in dl:
        if not(0 <= y + dy < W) or not(0 <= x + dx < H):
            continue
        if S[y + dy][x + dx] == '#':
            is_connected = True
            break
    return is_connected


for i in range(H):
    for j in range(W):
        if not can_draw(i, j):
            print('No')
            sys.exit()

print('Yes')

Submission status: Runtime Error

Solution code:
import sys
H, W = map(int, input().split())
S = [input() for i in range(H)]
drawable = True


def can_draw(y, x):
    if S[y][x] == '.':
        return True

    dl = [(-1, 0), (0, 1), (1, 0), (0, -1)]
    for dy, dx in dl:
        if not(0 <= y + dy < W) or not(0 <= x + dx < H):
            continue
        if S[y + dy][x + dx] == '#':
            return True
    return False


for i in range(H):
    for j in range(W):
        if not can_draw(i, j):
            print('No')
            sys.exit()

print('Yes')

Submission status: Runtime Error

Solution code:
h,w = map(int,input().split())
s=[]
for _ in range(h):
  s.append(str(input()))
for i in range(h):
  for j in range(w):
    flag=False
    if s[i][j]!="#":
      continue
    for k in [-1,1]:
      if 0<=i+k<h:
        if s[i+k][j]=="#":
          flag=True
      if 0<=j+k<h:
        if s[i][j+k]=="#":
          flag=True
    if not flag:
      print("No")
      exit()
print("Yes")

Submission status: Runtime Error

Solution code:
h,w = map(int,input().split())
s=[]
for _ in range(h):
  s.append(str(input()))
for i in range(h):
  for j in range(w):
    flag=False
    if s[i][j]!="#":
      break
    for k in [-1,1]:
      if 0<=i+k<h:
        if s[i+k][j]=="#":
          flag=True
      if 0<=j+k<h:
        if s[i][j+k]=="#":
          flag=True
    if not flag:
      print("No")
      exit()
print("Yes")