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: Accepted

Solution code:
# coding: utf-8
import numpy as np
H, W = map(int, input().split())
S = []
cnt = 0
for i in range(H):
    s = input()
    cnt += s.count("#")
    S.append(s[:])
t_cnt = 0
T = [[False] * W] * H
T = np.array(T)
for i in range(H):
    for j in range(W):
        if S[i][j] == "#":
            if 0 < i < H-1:
                if 0 < j < W-1:
                    T[i-1][j] = True
                    T[i+1][j] = True
                    T[i][j-1] = True
                    T[i][j+1] = True
                elif j == 0:
                    T[i-1][j] = True
                    T[i+1][j] = True
                    T[i][j+1] = True
                else:
                    T[i-1][j] = True
                    T[i+1][j] = True
                    T[i][j-1] = True
            elif i == 0:
                if 0 < j < W-1:
                    T[i][j-1] = True
                    T[i][j+1] = True
                    T[i+1][j] = True
                elif j == 0:
                    T[i][j+1] = True
                    T[i+1][j] = True
                else:
                    T[i+1][j] = True
                    T[i][j-1] = True
            else:
                if 0 < j < W-1:
                    T[i][j-1] = True
                    T[i][j+1] = True
                    T[i-1][j] = True
                elif j == 0:
                    T[i][j+1] = True
                    T[i-1][j] = True
                else:
                    T[i-1][j] = True
                    T[i][j-1] = True
for i in range(H):
    for j in range(W):
        if T[i][j] and S[i][j] == "#":
            t_cnt += 1
print("Yes" if cnt == t_cnt else "No")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
H,W = map(int,input().split())
base = []
for _ in range(H):
  base.append(list(input()))
counter = 0
for i in range(H):
  for j in range(W):
    if base[i][j] == '#':
      counter += 1
      break
if counter == 0:
  print('Yes')
  exit()
TB = ['.']*(W+1)
WIDE = []
WIDE.append(TB)
for i in range(H):
  WIDE.append(['.'] + base[i] + ['.'])
WIDE.append(TB)
Answer = 'Yes'
for i in range(1,H+1):
  for j in range(1,W+1):
    if WIDE[i][j] == '#' and WIDE[i-1][j] == '.' and WIDE[i][j-1] == '.' and WIDE[i][j+1] == '.' and WIDE[i+1][j] == '.':
      Answer = 'No'
      break
print(Answer)

Submission status: Accepted

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

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

def dfs(x, y):
    flg = 0
    for ii in range(4):
        nx = x + dx[ii]
        ny = y + dy[ii]
        if nx < 0 or nx >= H or ny < 0 or ny >= W:
            continue
        if ls[nx][ny] == '#':
            flg = 1
    return flg

for i in range(H):
    for j in range(W):
        if ls[i][j] == '#':
            if dfs(i, j) == 0:
                print('No')
                exit()
print('Yes')

Submission status: Accepted

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

Submission status: Accepted

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

def black(i,j):
    if s[i][j]=='#':
        flag=False
        for m in range(-1,2):
            for n in range(-1,2):
                if (m==0 and n!=0) or (m!=0 and n==0):
                    if 0<=i+m<=h-1 and 0<=j+n<=w-1:
                        if s[i+m][j+n]=='#':
                            flag=True
                            break
            if flag:
                break
        return flag
    else:
        return True

flag=True
for i in range(h):
    for j in range(w):
        if black(i,j):
            flag=True
        else:
            flag=False
            print('No')
            break
    if not flag:
        break
if flag:
    print('Yes')

Submission status: Accepted

Solution code:

H, W = map(int, input().split())
edges = [[ None for i in range(W) ] for j in range(H)]

for h in range(H):
  v = input()
  for w in range(W):
    edges[h][w] = v[w]

for h in range(H):
  for w in range(W):
    if edges[h][w] == ".": continue

    flag = False
    flag = flag or (w + 1 != W and edges[h][w+1] == "#") # 右
    flag = flag or (w != 0 and edges[h][w-1] == "#") # 左
    flag = flag or (h + 1 != H and edges[h+1][w] == "#") # 下
    flag = flag or (h != 0 and edges[h-1][w] == "#") # 上

    if not flag:
      print("No")
      exit()

print("Yes")

Submission status: Accepted

Solution code:
H, W  = map(int, input().split())
fields = []
# 初期値が決まったフラグ
flg = False
for i in range(H):
    ls = list(input())
    fields.append(ls)

mvs = [(0,1),(0,-1),(1,0),(-1,0)]
for h in range(H):
    for w in range(W):
        if fields[h][w] == "#":
            flg = False #つながっているかどうか
            for dh,dw in mvs:
                h_new = h + dh
                w_new = w + dw
                if 0 <= h_new < H and 0 <= w_new < W:
                    if fields[h_new][w_new] == "#":
                        flg = True
            if not flg:
                print("No")
                exit()
print("Yes")

Submission status: Accepted

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

flag=True
if H==W==1:
    if s[0][0]=='#':
        flag=False
elif H>=2 and W==1:
    for i in range(H):
        if s[i][0] == '#':
            if i==0:
                if s[i+1][0]=='.':
                    flag=False
                    break
                else:
                    continue
            elif i==H-1:
                if s[i-1][0]=='.':
                    flag=False
                    break
                else:
                    continue
            else:
                if s[i+1][0]==s[i-1][0]=='.':
                    flag=False
                    break
                else:
                    continue
        else:
            continue
elif H==1 and W>=2:
    for i in range(W):
        if s[0][i]=='#':
            if i==0:
                if s[0][i+1]=='.':
                    flag=False
                    break
                else:
                    continue
            elif i==W-1:
                if s[0][i-1]=='.':
                    flag=False
                    break
                else:
                    continue
            else:
                if s[0][i+1]==s[0][i-1]=='.':
                    flag=False
                    break
                else:
                    continue
        else:
            continue
else:
    for i in range(H):
        if i==0:
            for j in range(W):
                if s[i][j]=='#':
                    if j==0:
                        if s[i][j+1]==s[i+1][j]=='.':
                            flag=False
                            break
                        else:
                            continue
                    elif j==W-1:
                        if s[i][j-1]==s[i+1][j]=='.':
                            flag=False
                            break
                        else:
                            continue
                    else:
                        if s[i][j+1]==s[i][j-1]==s[i+1][j]=='.':
                            flag=False
                            break
                        else:
                            continue
                else:
                    continue
            if flag==False:
                break
        elif i==H-1:
            for j in range(W):
                if s[i][j]=='#':
                    if j==0:
                        if s[i][j+1]==s[i-1][j]=='.':
                            flag=False
                            break
                        else:
                            continue
                    elif j==W-1:
                        if s[i][j-1]==s[i-1][j]=='.':
                            flag=False
                            break
                        else:
                            continue
                    else:
                        if s[i][j+1]==s[i][j-1]==s[i-1][j]=='.':
                            flag=False
                            break
                        else:
                            continue
                else:
                    continue
            if flag==False:
                break
        else:
            for j in range(W):
                if s[i][j]=='#':
                    if j==0:
                        if s[i-1][j]==s[i+1][j]==s[i][j+1]=='.':
                            flag=False
                            break
                        else:
                            continue
                    elif j==W-1:
                        if s[i-1][j]==s[i+1][j]==s[i][j-1]=='.':
                            flag=False
                            break
                        else:
                            continue
                    else:
                        if s[i-1][j]==s[i+1][j]==s[i][j-1]==s[i][j+1]=='.':
                            flag=False
                            break
                        else:
                            continue
                else:
                    continue
            if flag==False:
                break

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

Submission status: Accepted

Solution code:
a,b = map(int,input().split())
art = [list(str(input())) for _ in range(a)]

def check(x,y):
    if x > 0:
        if art[x-1][y] == "#":
            return
    if x < a-1:
        if art[x + 1][y] == "#":
            return

    if y > 0:
        if art[x][y-1] == "#":
            return
    if y < b-1:
        if art[x][y+1] == "#":
            return
    print('No')
    exit(0)

for i in range(a):
    for j in range(b):
        if art[i][j] == "#":
            check(i,j)

print('Yes')

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys

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

def solve(H: int, W: int, s: "List[str]"):
    s = ["."*(W+2)]+["."+ss+"." for ss in s]+["."*(W+2)]
    
    direction = ((0,1),(1,0),(0,-1),(-1,0))

    # 全ての黒マスの上下左右に一つでも黒マスがあればおk
    for i in range(H+2):
        for j in range(W+2):
            if s[i][j] == ".":
                continue
            
            for x,y in direction:
                if s[i+x][j+y] == "#":
                    break
            else:
                print(NO)
                return 
    
    print(YES)
    return


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(H)]  # type: "List[str]"
    solve(H, W, s)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

A = [['.']*(W+2) for i in range(H+2)]
for i in range(1,H+1):
    for j in range(1,W+1):
        A[i][j] = S[i-1][j-1]
        
ans = 'Yes'
for i in range(W+2):
    if(ans == 'No'):
        break
    for j in range(H+2):
         if(A[j][i] == '#'):
            if (A[j-1][i] != '#' and A[j+1][i] != '#' and A[j][i-1] != '#' and A[j][i+1] != '#'):
                ans = 'No'
                break

if(H == 1 and W ==1 and S[0][0] == '#'):
    ans = 'Yes'

print(ans)

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
S = [input() for _ in range(H)]
for h in range(H):
    for w in range(W):
        f = False
        if S[h][w] == '.':
            continue
        if h > 0 and S[h-1][w] == '#':
            f = True
        elif h < H-1 and S[h+1][w] == '#':
            f = True
        elif w > 0 and S[h][w-1] == '#':
            f = True
        elif w < W-1 and S[h][w+1] == '#':
            f = True
        if not f:
            break
    else:
        continue
    break
else:
    print('Yes')
    exit()
print('No')

Submission status: Accepted

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] == "#":
            st = 0
            if i != 0:
                if s[i-1][j] == "#":
                    st = 1
            if j != 0:
                if s[i][j-1] == "#":
                    st = 1
            if i != h-1:
                if s[i+1][j] == "#":
                    st = 1
            if j != w-1:
                if s[i][j+1] == "#":
                    st = 1
            if st == 0:
                print("No")
                exit()

print("Yes")

Submission status: Accepted

Solution code:
h,w = map(int,input().split())
data = [input() for _ in range(h)]
t = True
for i in range(h):
    for j in range(w):
        if data[i][j] == '#':
            if i >= 0 and data[i-1][j] == '#':continue
            elif h-1 > i  and data[i + 1][j] == '#': continue
            elif j >= 0 and data[i][j - 1] == '#': continue
            elif w-1 > j and data[i][j + 1] == '#': continue
            else:
                t = False
                break

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

Submission status: Accepted

Solution code:
import sys

h, w = map(int, sys.stdin.readline().split())
canvas = ['.' * (w + 2)]
canvas += ['.' + sys.stdin.readline().rstrip() + '.' for _ in range(h)]
canvas += ['.' * (w + 2)]

def main():
    d = [(1, 0), (0, 1), (-1, 0), (0, -1)]
    for i in range(1, h+1):
        for j in range(1, w+1):
            if canvas[i][j] == '#':
                for di, dj in d:
                    y = i + di
                    x = j + dj
                    if canvas[y][x] == '#':
                        break
                else:
                    return 'No'
    return 'Yes'

if __name__ == '__main__':
    ans = main()
    print(ans)

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    s = []
    H, W = LI()
    for i in range(H):
        _s = S()
        s.append(_s)
    for r in range(H):
        for c in range(W):
            if s[r][c] == '.':
                continue
            any_tonari_black = False
            for dr, dc in zip(DR, DC):
                new_r = r + dr
                new_c = c + dc
                if not (0 <= new_r < H and 0 <= new_c < W):
                    continue
                if s[new_r][new_c] == '#':
                    any_tonari_black = True
            if not any_tonari_black:
                print('No')
                return
    print('Yes')
main()

Submission status: Accepted

Solution code:

def main()->None:
    H, W = map(int, input().split())
    range_H = range(H)
    range_W = range(W)
    src = [input() for _ in range_H]
    #print(src)
    ans = [["." for _ in range_W] for _ in range_H]
    # 周囲4マスの探索するときの配列の場所指定の配列
    dxdy = [(-1,0),(0,-1),(0,1),(1,0)]
    # x, yで配列の位置を指定
    for y in range_H:
        for x in range_W:
            c = "."
            if src[y][x] == ".":continue
            for dx, dy in dxdy: # 周囲８マスを探索
                if x+dx < 0 or x+dx > W-1 or y+dy < 0 or y+dy > H-1 :continue
                if src[y+dy][x+dx] == "#": #周囲に黒マスがあれば対象の黒マスは黒くしていい
                    c = "#"
            ans[y][x] = c
    #print(ans)
    flag = True
    counter = 0
    for i in ans:
        res = "".join(i)
        if res == src[counter]:
            counter += 1
        else:
            flag = False
    if flag: print("Yes")
    else: print("No")



if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
s=['.'*(w+2)]
for i in range(h):
    s.append('.'+input()+'.')
s+=['.'*(w+2)]
for i in range(h):
    for j in range(w):
        if s[i+1][j+1]=='#':
            if (s[i][j+1]+s[i+1][j]+s[i+1][j+2]+s[i+2][j+1]).count('.')==4:
                print('No')
                quit()
print('Yes')

Submission status: Accepted

Solution code:
import sys
h, w = [int(i) for i in sys.stdin.readline().split()]
s_ls = []
for i in range(h):
    s = [i for i in sys.stdin.readline().strip()]
    s_ls.append(s)

def check(y, x):
    flg = False
    for move_y, move_x in [(0,1), (0,-1), (1,0), (-1,0)]:
        next_y = max(0, min(h-1, y + move_y))
        next_x = max(0, min(w-1, x + move_x))
        flg |= s_ls[next_y][next_x] == "#"
    return flg

flg = True
for i in range(h):
    for j in range(w):
        if s_ls[i][j] == "#":
            flg &= check(i, j)
print("Yes" if flg else "No")

Submission status: Accepted

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

ans = "Yes"

for h in range(H):
    s[h + 1] = "." + input() + "."

for h in range(1, H + 1):
    for w in range(1, W + 1):
        if s[h][w] == "#":
            t = [s[h + 1][w], s[h - 1][w], s[h][w + 1], s[h][w - 1]]
            if "#" not in t:
                ans = "No"
                break
    else:
        continue
    break

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
#枠を大きめに確保してout of rangeを避ける!
grid = ["."*(w+2)]
for _ in range(h):
    grid.append("." + input() + ".")
grid += ["."*(w+2)]

for i in range(1,h+1):
    for j in range(1,w+1):
        if grid[i][j]=="#":
            if not (grid[i][j-1]=="#" or grid[i][j+1]=="#"or \
                grid[i-1][j]=="#" or grid[i+1][j]=="#"):
                    print("No")
                    exit()
print("Yes")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
h, w = [int(el) for el in input().split(' ')]

S = []
for i in range(0, h):
	temp = [x == '#' for x in input()]
	temp.insert(0, False)
	temp.append(False)
	S.append(temp)


S.insert(0, [False]*(w+2))
S.append([False]*(w+2))


# evaluate
def sol():
	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]:
					pass
				else:
					return('No')
	else:
		return('Yes')

print(sol())

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
li=[]
for i in range(h):
    li.append(str(input()))
for i in range(h):
    for j in range(w):
        if li[i][j]=="#":
            jud=0
            if j>0 and li[i][j-1]=="#":
                jud+=1
            if j<w-1 and li[i][j+1]=="#":
                jud+=1
            if i>0 and li[i-1][j]=="#":
                jud+=1
            if i<h-1 and  li[i+1][j]=="#":
                jud+=1         
            if jud==0:
                print("No")
                exit()
print("Yes")

Submission status: Accepted

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


def canAchive(m):
    for i in range(h):
        for j in range(w):
            around = [m[i-1][j],
                      m[i+1][j],
                      m[i][j-1],
                      m[i][j+1]]
            if m[i][j] == '#' and all(s != "#" for s in around):
                return False
    return True


print('Yes' if canAchive(m) else 'No')

Submission status: Accepted

Solution code:
H,W = map(int,input().split())
black_count = 0
board = []
got_start = False
ans = "Yes"
start_point = None
for h in range(H):
  row = tuple(input())
  if "#" in row:
    index = row.index("#")
    if got_start == False:
      start_point = (h,index)
      got_start = True
  board.append(row)

def check(y,x):
  if y >= H or y < 0 or x >= W or x < 0:
    return 0
  if board[y][x] == "#":
    return 1

for i in range(H):
  for j in range(W):
    y,x = i,j
    if board[i][j] == ".":
      continue
    is_adjacent = False
    if check(y + 1,x):
      is_adjacent = True
    if check(y - 1,x):
      is_adjacent = True
    if check(y, x + 1):
      is_adjacent = True
    if check(y,x - 1):
      is_adjacent = True
    if is_adjacent == False:
      ans = "No"
print(ans)

Submission status: Accepted

Solution code:

import sys
def resolve():
    input = sys.stdin.readline
    H,W=map(int,input().rstrip().split())
    S=[input().rstrip() for _ in range(H)]

    dx=[0,0,-1,1]#上下左右
    dy=[1,-1,0,0]

    for i in range(H):
        for j in range(W):
            if(S[i][j]=="#"):
                for dir in range(4):
                    nx=j+dx[dir]
                    ny=i+dy[dir]

                    if(nx<0 or nx>=W):
                        continue
                    if(ny<0 or ny>=H):
                        continue

                    if(S[i][j]==S[ny][nx]):
                        break
                else:
                    print("No")
                    return
    print("Yes")




from io import StringIO
import unittest

class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """3 3
.#.
###
.#."""
        output = """Yes"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """5 5
#.#.#
.#.#.
#.#.#
.#.#.
#.#.#"""
        output = """No"""
        self.assertIO(input, output)
    def test_入力例_3(self):
        input = """11 11
...#####...
.##.....##.
#..##.##..#
#..##.##..#
#.........#
#...###...#
.#########.
.#.#.#.#.#.
##.#.#.#.##
..##.#.##..
.##..#..##."""
        output = """Yes"""
        self.assertIO(input, output)

if __name__ == "__main__":
    #unittest.main()
    resolve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
h, w = map(int, input().split())
grid = [['.' for i in range(w + 2)]]
for i in range(h):
    row = input()
    grid.append('.' + row + '.')
grid.append(['.' for i in range(w + 2)])

for i in range(1,h+1):
    for j in range(1, w+1):
        if grid[i][j] == '#':
            if '#' not in (grid[i-1][j], grid[i+1][j], grid[i][j-1], grid[i][j+1]):
                print('No')
                sys.exit()
print('Yes')

Submission status: Accepted

Solution code:
h,w = map(int,input().split())
s = [input() for _ in range(h)]
count = [[0]*w for _ in range(h)]
for i in range(h):
    for j in range(w):
        if j>0   and s[i][j-1] == '#': count[i][j] = 1
        if j<w-1 and s[i][j+1] == '#': count[i][j] = 1
        if i>0   and s[i-1][j] == '#': count[i][j] = 1
        if i<h-1 and s[i+1][j] == '#': count[i][j] = 1

ans='Yes'
for row1,row2 in zip(s,count):
    for c1,c2 in zip(row1,row2):
        if c1 == '#' and c2 == 0:
            ans = 'No'
print(ans)

Submission status: Accepted

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

ans = 'Yes'
#全探索して、黒色の隣接マスがすべて白色なら、Noとなる
for h, s in enumerate(S):
	for w, c in enumerate(s):
		if c == '#':
			if w-1 >= 0 and S[h][w-1] == '#':
				continue
			if w+1 < W and S[h][w+1] == '#':
				continue
			if h-1 >= 0 and S[h-1][w] == '#':
				continue
			if h+1 < H and S[h+1][w] == '#':
				continue
			ans = 'No'
			break
	else:
		continue
	break
	
print(ans)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(3000)
h, w = map(int, raw_input().split())
s = [[c for c in raw_input()] for i in range(h)]
def isValid(i, j):
    if i < 0 or i >= h or j < 0 or j >= w:
        return False
    return True
    
def dfs(s, i, j):
    if not isValid(i, j) or s[i][j] == "0" or s[i][j] == ".":
        return 0
    if s[i][j] == "#":
        s[i][j] = "0"
        a = dfs(s, i+1, j)
        b = dfs(s, i-1, j)
        c = dfs(s, i, j+1)
        d = dfs(s, i, j-1)
        return 1 + a + b + c + d

for i in range(h):
    for j in range(w):
        if s[i][j] == "#":
            ccs = dfs(s, i, j)
            #print ccs
            if ccs == 1:
                print "No"
                exit()
print "Yes"

Submission status: Accepted

Solution code:
h, w = map(int,input().split())
s = [["."]*(w+2)] + \
    [list("." + input() + ".") for _ in range(h)] + \
    [["."]*(w+2)]
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: Accepted

Solution code:
h, w = map(int,input().split())
s = [["."]*(w+2)] + \
    [list("." + input() + ".") for _ in range(h)] + \
    [["."]*(w+2)]
flg = 0
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] == "." :
                flg = 1
                break
if flg == 0 : print("Yes")
else : print("No")

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
h,w = list(map(int,input().split()))

cmbs = [["."] + list(input()) + ["."]  for _ in range(h)]
cmbs.insert(0,["."] * (w+2))
cmbs.append(["."] * (w+2))

#print(cmbs)
#全てのsについて、上下左右いずれかに#があるか調べる
ret = "Yes"
for i in range(1,h+1):
    for j in range(1,w+1):
        if cmbs[i][j] == "#":
            if cmbs[i-1][j] =="." and cmbs[i+1][j] =="." and cmbs[i][j-1] =="." and cmbs[i][j+1] ==".":
                ret ="No"
print(ret)

Submission status: Accepted

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

H,W = map(int, input().split())
vP = ["." * (W+2),]
mM = vP+["."+input()+"." for _ in [0,]*H]+vP
mD = [(-1,0),(1,0),(0,-1),(0,1)]

for i in range(1,H+1):
  for j in range(1,W+1):
    if (mM[i][j]=="#" and
        all(mM[i+x][j+y]=="."
            for x,y in mD)):
      print("No")
      exit(0)

print("Yes")

Submission status: Accepted

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

for i in range(1, h+1):
    for j in range(1, w+1):
        if grid[i][j] == '.':
            continue
        else:
            up = grid[i-1][j]
            right = grid[i][j+1]
            left = grid[i][j-1]
            down = grid[i+1][j]

            if up + right + left + down == '....':
                print('No')
                exit()

print('Yes')

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
L=[list(input()) for i in range(h)]
dx=[1,0,-1,0]
dy=[0,1,0,-1]
flag=0
for i in range(h):
    for j in range(w):
        c=0
        d=0
        if L[i][j]=='#':
            for k in range(4):
                if (j+dx[k] in range(w)) and (i+dy[k] in range(h)):
                    d+=1
                    if L[i+dy[k]][j+dx[k]]=='.':
                        c+=1
            if c!=0 and c==d:
                flag=1
print('Yes' if flag==0 else 'No')

Submission status: Accepted

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

grid = []

grid.append(['.']*(w+2))
for row in grid_t:
	grid.append(row)
grid.append(['.']*(w+2))

ok = 1
for i in range(h+2):
    for j in range(w+2):
        if grid[i][j] == '#':
            if grid[i+1][j] != '#' and grid[i-1][j] != '#' and grid[i][j+1] != '#' and grid[i][j-1] != '#':
                ok = 0

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