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:
H,W = list(map(int,input().split(" ")))
mass = []
for _ in range(H):
    mass.append(input())


dirs = [[0,1],[1,0],[0,-1],[-1,0]]

flag = True
for h,row in enumerate(mass):
    for w,temp in enumerate(row):
        if temp == "#":
            cont = False
            for dir in dirs:
                x = dir[0]
                y = dir[1]
                hy =h+y
                wx = w + x
                if  hy < 0 or wx< 0 or wx==W or hy == H:
                    continue
                else:
                    if mass[hy][wx] == "#":
                        cont = True
            if not cont:
                flag = False
if flag:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
G=[list(input()) for i in range(h)]
ans=1
for l in G:
    for i in range(w-1):
        if l[i]==l[i+1]=='#':
            l[i]='o'
            l[i+1]='o'
        if l[i]=='o' and l[i+1]=='#':
            l[i+1]='o'
for k in range(h-1):
    for j in range(w):
        if G[k][j]=='#' and G[k+1][j]=='#':
            G[k][j]='o'
            G[k+1][j]='o'
        elif G[k][j]=='#' and G[k+1][j]=='o':
            G[k][j]='o'
        elif G[k][j]=='o' and G[k+1][j]=='#':
            G[k+1][j]='o'
for l in G:
    if '#' in l:
        ans*=0
if ans==0:
    print('No')
else:
    print('Yes')

Submission status: Accepted

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

S = [list(input()) for i in range(H)]

for i in range(H):
    for j in range(W):
        if S[i][j] == '.':
            continue

        cnt = 0
        for dy in [-1,1]:
            if 0 <= i + dy < H:
                if S[i+dy][j] == '#':
                        cnt += 1
        for dx in [-1,1]:
            if 0 <= j + dx < W:
                if S[i][j+dx] == '#':
                    cnt += 1
        if cnt == 0:
            print('No')
            exit()

print('Yes')

Submission status: Accepted

Solution code:
def solve(H, W, S):
    for h in range(1, H):
        for w in range(1, W):
            if S[h][w] == '#':
                if not (S[h-1][w] == '#' or S[h+1][w] == '#' or S[h][w+1] == '#' or S[h][w-1] == '#'):
                    return "No"
    return "Yes"


H, W = [int(x) for x in input().split()]
# H, W < 50
S = []
S.append('.' * (W+2))
for _ in range(H):
    S.append("."+input().strip()+".")
S.append('.' * (W+2))
import sys
for row in S:
    print(row, file=sys.stderr)
print(solve(H, W, S))

Submission status: Accepted

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

res.append("." * (w + 2))
quit = False
for i in range(h):
    for j in range(w):
        if res[i][j+1] == "." and res[i+1][j:j+3] == ".#." and res[i+2][j+1] == ".":
            print("No")
            quit = True
            break
    if quit:
        break
else:
    print("Yes")

Submission status: Accepted

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

answer = True
for i in range(H):
  for j in range(W):
    if s[i][j] == '#':
      count = 0
      if i != 0 and s[i - 1][j] == '.':
        count += 1
      if i != H - 1 and s[i + 1][j] == '.':
        count += 1
      if j != 0 and s[i][j - 1] == '.':
        count += 1
      if j != W - 1 and s[i][j + 1] == '.':
        count += 1
      if count == 4:
        answer = False

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

Submission status: Accepted

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

for i in range(h):
    s[i+1] = [x for x in input()]

for i in range(h+2):
    s[i].insert(w,".")
    s[i].insert(0,".")

flg ="Yes"
for i in range(h+2):
    for j in range(w+2):
        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:
                flg = "No"
print(flg)

Submission status: Accepted

Solution code:
h, w = list(map(int, input().split()))
s = [input() for j in range(h)]
op = [(-1, 0), (0, -1), (0, 1), (1, 0)]
for i in range(h):
  for j in range(w):
    if s[i][j] == '.':
      continue
    count = 0
    for k in range(4):
      x = i + op[k][0]
      y = j + op[k][1]
      if x < 0 or y < 0 or x >= h or y >= w:
        continue
      if s[x][y] == '.':
        count += 1
    if count == 4:
      print('No')
      exit()
      
print('Yes')

Submission status: Accepted

Solution code:
import sys
h,w=map(int,input().split())
s_list=[]
for i in range(h):
    s_list.append(input())
op=[(1,0),(0,1),(-1,0),(0,-1)]
for i in range(h):
    for j in range(w):
        if s_list[i][j]=='#':
            count=1
            for k in op:
                if 0<=i+k[0]<=h-1 and 0<=j+k[1]<=w-1:
                    if s_list[i+k[0]][j+k[1]]=='#':
                        count=0
                    else:
                        pass
            if count==1:
                print('No')
                sys.exit()
print('Yes')

Submission status: Accepted

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

ans = True
for i in range(1, h + 1):
    for j in range(1, w + 1):
        if a[i][j] == '#' and a[i + 1][j] == '.' and a[i][j + 1] == '.'and a[i - 1][j] == '.' and a[i][j - 1] == '.':
            ans = False

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

Submission status: Accepted

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



def search_wall(H, W, x, y):
    tmp = []
    if x + 1 < W:
        tmp.append([0, 1])
    if x - 1 >= 0:
        tmp.append([0, -1])
    if y + 1 < H:
        tmp.append([1, 0])
    if y - 1 >= 0:
        tmp.append([-1, 0])
    return tmp
    
for row in range(H):
    for column in range(W):
        if (maze[row][column] == '#'):
            check = 0
            for y, x in search_wall(H, W, column, row):
                if maze[row + y][column + x] == '#':
                    check = 1
            if check != 1:
                print("No")
                exit()
print("Yes")

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
form = []
flg = 0
for i in range(h):
    form.append(input())
for i in range(h):
    for j in range(w):
        if form[i][j]==".":
            continue
        else:
            if i==0:
                if j==0:
                    if form[i][j+1]== "#" or form[i+1][j]=="#":
                        continue
                    else:
                        flg = 1
                        break
                elif j==w-1:
                    if form[i][j-1]== "#" or form[i+1][j]=="#":
                        continue
                    else:
                        flg = 1
                        break
                else:
                    if form[i][j-1]== "#" or form[i+1][j]=="#" or form[i][j+1]=="#":
                        continue
                    else:
                        flg=1
                        break
                        
            elif i==h-1:    
                if j==0:
                    if form[i][j+1]== "#" or form[i-1][j]=="#":
                        continue
                    else:
                        flg = 1
                        break
                elif j==w-1:
                    if form[i][j-1]== "#" or form[i-1][j]=="#":
                        continue
                    else:
                        flg = 1
                        break
                else:
                    if form[i][j-1]== "#" or form[i-1][j]=="#" or form[i][j+1]=="#":
                        continue
                    else:
                        flg=1
                        break
                
            else:
                if j==0:
                    if form[i][j+1]== "#" or form[i+1][j]=="#" or form[i-1][j]=="#":
                        continue
                    else:
                        flg = 1
                        break
                elif j==w-1:
                    if form[i][j-1]== "#" or form[i+1][j]=="#" or form[i-1][j]=="#":
                        continue
                    else:
                        flg = 1
                        break
                else:
                    if form[i][j-1]== "#"or form[i+1][j]=="#" or form[i][j+1]=="#" or form[i-1][j]=="#":
                        continue
                    else:
                        flg = 1
                        break
    if flg ==1:
        break
    
if flg ==0:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

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

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  h,w=LI()

  l=[]
  for i in range(h):
    l.append(S())

  a=[[0,-1],[-1,0],[1,0],[0,1]]

  for i in range(h):
    for j in range(w):
      b=l[i][j]
      f=True
      if b=='#':
        for k in a:
          _i=i
          _j=j
          _i+=k[0]
          _j+=k[1]
          if _i>=0 and _i<=h-1 and _j>=0 and _j<=w-1:
            if l[_i][_j]=='#':
              f=False
        if f:
          return 'No'
          exit()
  return 'Yes'


print(main())

Submission status: Accepted

Solution code:
# ABC096C - Grid Repainting 2
h, w = list(map(int, input().rstrip().split()))
arr = [list(input().rstrip()) for _ in range(h)]
arr.insert(0, ["."] * (w + 2))
arr.append(["."] * (w + 2))
for i in arr[1:-1]:
    i.insert(0, ".")
    i.append(".")

flg = False
for i in range(1, h + 1):
    for j in range(1, w + 1):
        if arr[i][j] == "#":
            if (
                arr[i - 1][j] != "#"
                and arr[i + 1][j] != "#"
                and arr[i][j - 1] != "#"
                and arr[i][j + 1] != "#"
            ):
                print("No")
                flg = True
                break
    if flg:
        break
if not flg:
    print("Yes")

Submission status: Accepted

Solution code:
# ABC096C - Grid Repainting 2
h, w = list(map(int, input().rstrip().split()))
arr = [list(input().rstrip()) for _ in range(h)]
arr.insert(0, ["."] * (w + 2))
arr.append(["."] * (w + 2))
for i in arr[1:-1]:
    i.insert(0, ".")
    i.append(".")

for i in range(1, h + 1):
    for j in range(1, w + 1):
        if arr[i][j] == "#":
            if (
                arr[i - 1][j] != "#"
                and arr[i + 1][j] != "#"
                and arr[i][j - 1] != "#"
                and arr[i][j + 1] != "#"
            ):
                print("No")
                break
    else:
        continue
    break
else:
    print("Yes")

Submission status: Accepted

Solution code:
# ABC096C - Grid Repainting 2
h, w = list(map(int, input().rstrip().split()))
arr = [list(input().rstrip()) for _ in range(h)]
arr.insert(0, ["."] * (w + 2))
arr.append(["."] * (w + 2))
for i in arr[1:-1]:
    i.insert(0, ".")
    i.append(".")

for i in range(1, h + 1):
    for j in range(1, w + 1):
        if arr[i][j] == "#":
            if arr[i - 1][j] == "#":
                continue
            elif arr[i + 1][j] == "#":
                continue
            elif arr[i][j - 1] == "#":
                continue
            elif arr[i][j + 1] == "#":
                continue
            else:
                print("No")
                break
    else:
        continue
    break
else:
    print("Yes")

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
l=[list(input()) for i in range(h)]
f=0
for i in range(h):
  for j in range(w):
    c=0
    if l[i][j]=="#":
      if i>0 and l[i-1][j]=="#":
        c+=1
      if i<h-1 and l[i+1][j]=="#":
        c+=1
      if j>0 and l[i][j-1]=="#":
        c+=1
      if j<w-1 and l[i][j+1]=="#":
        c+=1
      if c==0:
        f=1
        break
if f==1:
  print("No")
else:
  print("Yes")

Submission status: Accepted

Solution code:

h, w = [ int(v) for v in input().split() ]
field = [ list(input()) for i in range(h) ]
ans = "Yes"

for i in range(h):
	for j in range(w):
		if field[i][j] == "#":
			adjust = [ (i-1,j), (i,j-1), (i,j+1), (i+1,j) ]
			adjust = [ field[k[0]][k[1]] for k in adjust if 0 <= k[0] < h and 0 <= k[1] < w ]
			if adjust.count("#") == 0:
				ans = "No"
				break
print(ans)

Submission status: Accepted

Solution code:
H,W=map(int,input().split())
L=list(list(input()) for _ in range(H))
for h in range(H):
    for w in range(W):
        if L[h][w]=='#':
            if not any((0<=h+d<=H-1 and L[h+d][w]=='#')
                   or (0<=w+d<=W-1 and L[h][w+d]=='#')for d in [-1,1]):
                print('No')
                exit()
print('Yes')

Submission status: Accepted

Solution code:
#ABC096-C
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(input())
def S(): return list(input())
h,w=IL()
G=[["."]*(w+2)]
for i in range(h):
    G.append(["."]+S()+["."])
G.append(["."]*(w+2))
ret=True
#grid周り探索
for i in range(1,h):
    for j in range(1,w):
        if G[i][j]==".":
            continue
        ans=False
        for ti,tj in[[-1,0],[1,0],[0,1],[0,-1]]:
            if G[i+ti][j+tj]=="#":
                ans=True
        if not ans:
            ret=False
if ret:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
#ABC096-C
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(input())
def S(): return list(input())
h,w=IL()
S=[S() for i in range(h)]
ret=True
#grid周り探索
for i in range(h):
    for j in range(w):
        if S[i][j]==".":
            continue
        ans=False
        for ti in [-1,1]:
            if 0<=i+ti<h:
                if S[i+ti][j]=="#":
                    ans=True
        for tj in [-1,1]:
             if 0<=j+tj<w:
                if S[i][j+tj]=="#":
                    ans=True
        if not ans:
            ret=False
if ret:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
H, W = map(int, raw_input().split())
board = []
for i in range(0, H):
	board.append(raw_input())
flag1 = True
for i in range(0, H):
	for j in range(0, W):
		if board[i][j] == '#':
			flag2 = True
			for k in range(0, 2):
				if 0 <= i-1+2*k and i-1+2*k < H:
					if board[i-1+2*k][j] == '#':
						flag2 = False
						break
				if 0 <= j-1+2*k and j-1+2*k < W:
					if board[i][j-1+2*k] == '#':
						flag2 = False
						break
			if flag2:
				flag1 = False
				break
if flag1: print 'Yes'
else: print 'No'

Submission status: Accepted

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

S = []

dxy_list = [(-1, 0), (0, 1), (1, 0), (0, -1)]

for i in range(h):
    S.append(list(input()))


for i in range(h):
    for j in range(w):

        if (S[i][j] == '.'): continue
            
        has_sharp = False

        for dxy in dxy_list:
            ni = i + dxy[0]
            nj = j + dxy[1]

            if (ni < 0 or h <= ni): continue
            if (nj < 0 or w <= nj): continue

            if (S[ni][nj] == '#'):
                has_sharp = True
                break

        if (not has_sharp):
            print('No')
            exit()

print('Yes')

Submission status: Accepted

Solution code:
import sys
H,W=map(int,input().split())
#H×Wのマス目入力の周りに"."を付け加える関数
def pixel_input(H,W,border="."):
    pixel = [[border]*(W+2)] + \
    [[border] + list(input()) + [border] for _ in range(H)] + \
    [[border]*(W+2)]
    return pixel
S=pixel_input(H,W)
flag=0
for i in range(1,H+1):
    for j in range(1,W+1):
        if S[i][j]=="#":
            if S[i-1][j]==S[i+1][j]==S[i][j-1]==S[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)]
s = ['.' * (W + 2)] + s + ['.' * (W + 2)]
flag = True
for h in range(1, H + 1):
    for w in range(1, W + 1):
        if (s[h][w] == '#' and (not '#' in [s[h - 1][w], s[h + 1][w], s[h][w - 1], s[h][w + 1]])):
            flag = False
                
print('Yes' if flag else 'No')

Submission status: Accepted

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

Submission status: Accepted

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

def check(i, j):
  return '#' in [cells[i - 1][j], cells[i][j - 1], cells[i][j + 1], cells[i + 1][j]]

for i in range(1, H + 1):
  for j in range(1, W + 1):
    if cells[i][j] == '#' and not check(i, j):
      print('No')
      break
  else:
    continue
  break
else:
  print('Yes')

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
s=eval('input(),'*h)
for i in range(h):
    for j in range(w):
        if s[i][j]=='.':continue
        for y,x in((i-1,j),(i+1,j),(i,j-1),(i,j+1)):
            if h>y>=0 and w>x>=0 and s[y][x]=='#':
                break
        else:
            print('No')
            exit()
print('Yes')

Submission status: Accepted

Solution code:
def check(H, W, S):
    for y in range(1, H + 1):
        for x in range(1, W + 1):
            if S[y][x] == '#':
                if len([1 for i in range(y-1, y+2) if S[i][x] == '#'] + [1 for j in range(x-1, x+2) if S[y][j] == '#']) < 3:
                    return False
    return True

if __name__ == '__main__':
    H, W = list(map(int, input().strip().split(' ')))
    S = [['.' for _ in range(W+2)]] + [list('.' + input() + '.') for _ in range(H)] + [['.' for _ in range(W+2)]]

    if check(H, W, S):
        print('Yes')
    else:
        print('No')

Submission status: Accepted

Solution code:
h,w=map(int, input().split())
S=["."+input()+"." for _ in range(h)]
S = ["."*(w+2)]+S+["."*(w+2)]
# print(S)
flag=True
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=False
print("Yes" if flag else "No")

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
l=[input() for _ in range(h)]
nb=[(0,1),(1,0),(0,-1),(-1,0)]
for i in range(h):
	for j in range(w):
		if l[i][j]=='#':
			for a,b in nb:
				if 0<=i+a<=h-1 and 0<=j+b<=w-1 and l[i+a][j+b]=='#':
					break
			else:
				print('No')
				exit()
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]"):
    def is_valid(i, j):
        if (i > 0 and s[i - 1][j] == '#' or 
            i < H - 1 and s[i + 1][j] == '#' or 
            j > 0 and s[i][j - 1] == '#' or 
            j < W - 1 and s[i][j + 1] == '#'):
            return True
        return False

    for i, R in enumerate(s):
        for j, c in enumerate(R):
            if c == '#' and not is_valid(i, j):
                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:
import sys
H, W = map(int, input().split())

lst = [['.'] * (W+2)]
lst += [['.'] + list(input()) + ['.'] for _ in range(H)]
lst += [['.'] * (W+2)]

for i in range(1, H+1):
    for j in range(1, W+1):
        if lst[i][j] == '#':
            if lst[i+1][j] == '#' or lst[i-1][j] == '#' or lst[i][j+1] == '#' or lst[i][j-1] == '#':
                pass
            else:
                print ('No')
                sys.exit()

print ('Yes')

Submission status: Accepted

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

S = [list(input()) for _ in range(H)]

for k in range(1, H - 1):
    for i in range(1, W - 1):
        if S[k][i] == "#":
            if S[k][i + 1] != "#" and S[k + 1][i] != "#" and \
               S[k - 1][i] != "#" and S[k][i - 1] != "#":
                print("No")
                exit()

for i in range(1, W - 1):
    if S[0][i] == "#":
        if S[0][i + 1] != "#" and S[1][i] != "#" and S[0][i - 1] != "#":
            print("No")
            exit()

    if S[H - 1][i] == "#":
        if S[H - 1][i + 1] != "#" and S[H - 2][i] != "#" and \
           S[H - 1][i - 1] != "#":
            print("No")
            exit()

for i in range(1, H - 1):
    if S[i][0] == "#":
        if S[i + 1][0] != "#" and S[i - 1][0] != "#" and S[i][1] != "#":
            print("No")
            exit()

    if S[i][W - 1] == "#":
        if S[i + 1][W - 1] != "#" and S[i - 1][W - 1] != "#" and \
           S[i][W - 2] != "#":
            print("No")
            exit()

if S[0][0] == "#":
    if S[0][1] != "#" and S[1][0] != "#":
        print("No")
        exit()

if S[0][W - 1] == "#":
    if S[0][W - 2] != "#" and S[1][W - 1] != "#":
        print("No")
        exit()

if S[H - 1][0] == "#":
    if S[H - 2][0] != "#" and S[H - 1][1] != "#":
        print("No")
        exit()

if S[H - 1][W - 1] == "#":
    if S[H - 1][W - 2] != "#" and S[H - 2][W - 1] != "#":
        print("No")
        exit()

print("Yes")

Submission status: Accepted

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

def array_pointer(L,i,j): #配列の１要素を引数に、チェックするべき要素を二重リストで返す
    L_next=[[i-1,j],[i+1,j],[i,j-1],[i,j+1]]
    if j==W-1:
        del L_next[3]
    elif j==0:
        del L_next[2]
    if i==H-1:
        del L_next[1] 
    elif i==0:
        del L_next[0]
    return L_next

def check(L,L_check):
    for k in L_check:
        a,b=k[0],k[1]
        if L[a][b]=='#':
            return True
    return False

ans='Yes'
for i in range(H):
    for j in range(W):
        if li[i][j]=='#':
            li_check=array_pointer(li,i,j)
            if not check(li,li_check):
                ans='No'
                break
print(ans)

Submission status: Accepted

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

H,W=map(int,input().split())
grid = [list(input().rstrip()) for _ in range(H)]
for i in range(H):
  for j in range(W):
    if j > 0 and grid[i][j-1] != '.' and grid[i][j] == '#':
      grid[i][j] = '*'
    elif j < W-1 and grid[i][j+1] != '.' and grid[i][j] == '#':
      grid[i][j] = '*'
    elif i > 0 and grid[i-1][j] != '.' and grid[i][j] == '#':
      grid[i][j] = '*'
    elif i < H-1 and grid[i+1][j] != '.' and grid[i][j] == '#':
      grid[i][j] = '*'
print("No" if sum([row.count('#') for row in grid]) else "Yes")

Submission status: Accepted

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

S = [list(input()) for _ in range(H)]

Board = [['.' for _ in range(W+2)] for _ in range(H+2)]

for i in range(H):
    for j in range(W):
        Board[i+1][j+1] = '#' if S[i][j] == '#' else '.'

ans = "Yes"
for i in range(1, H+1):
    for j in range(1, W+1):
        if Board[i][j] == '.':
            continue
        is_paintable = False
        for di, dj in [(-1, 0), (1, 0), (0, -1), (0, 1)]:
            if Board[i+di][j+dj] == '#':
                is_paintable = True
                break
        if not is_paintable:
            ans = 'No'
            break

print(ans)

Submission status: Accepted

Solution code:
###############################################################################

from sys import stdout
from bisect import bisect_left as binl
from copy import copy, deepcopy
from collections import defaultdict


mod = 1


def intin():
    input_tuple = input().split()
    if len(input_tuple) <= 1:
        return int(input_tuple[0])
    return tuple(map(int, input_tuple))


def intina():
    return [int(i) for i in input().split()]


def intinl(count):
    return [intin() for _ in range(count)]


def modadd(x, y):
    global mod
    return (x + y) % mod


def modmlt(x, y):
    global mod
    return (x * y) % mod


def lcm(x, y):
    while y != 0:
        z = x % y
        x = y
        y = z
    return x


def combination(x, y):
    assert(x >= y)

    if y > x // 2:
        y = x - y

    ret = 1

    for i in range(0, y):
        j = x - i
        i = i + 1

        ret = ret * j
        ret = ret // i

    return ret


def get_divisors(x):
    retlist = []
    for i in range(1, int(x**0.5) + 3):
        if x % i == 0:
            retlist.append(i)
            retlist.append(x // i)
    return retlist


def get_factors(x):
    retlist = []
    for i in range(2, int(x**0.5) + 3):
        while x % i == 0:
            retlist.append(i)
            x = x // i
    retlist.append(x)
    return retlist


def make_linklist(xylist):
    linklist = {}
    for a, b in xylist:
        linklist.setdefault(a, [])
        linklist.setdefault(b, [])
        linklist[a].append(b)
        linklist[b].append(a)
    return linklist


def calc_longest_distance(linklist, v=1):
    distance_list = {}
    distance_count = 0
    distance = 0
    vlist_previous = []
    vlist = [v]
    nodecount = len(linklist)

    while distance_count < nodecount:
        vlist_next = []
        for v in vlist:
            distance_list[v] = distance
            distance_count += 1
            vlist_next.extend(linklist[v])
        distance += 1
        vlist_to_del = vlist_previous
        vlist_previous = vlist
        vlist = list(set(vlist_next) - set(vlist_to_del))

    max_distance = -1
    max_v = None
    for v, distance in distance_list.items():
        if distance > max_distance:
            max_distance = distance
            max_v = v

    return (max_distance, max_v)


def calc_tree_diameter(linklist, v=1):
    _, u = calc_longest_distance(linklist, v)
    distance, _ = calc_longest_distance(linklist, u)
    return distance


class UnionFind:

    def __init__(self, n):
        self.parent = [i for i in range(n)]

    def root(self, i):
        if (self.parent[i] == i):
            return i
        self.parent[i] = self.root(self.parent[i])
        return self.parent[i]

    def unite(self, i, j):
        rooti = self.root(i)
        rootj = self.root(j)
        if rooti == rootj:
            return
        if i < j:
            self.parent[rootj] = rooti
        else:
            self.parent[rooti] = rootj

    def same(self, i, j):
        return self.root(i) == self.root(j)


###############################################################################


def main():
    h, w = intin()
    slistlist = ['.' * (w + 2)]
    for i in range(h):
        row = input()
        row = '.' + row + '.'
        slistlist.append(row)
    slistlist.append('.' * (w + 2))

    for i in range(h + 2):
        for j in range(w + 2):
            if slistlist[i][j] == '#':
                if slistlist[i-1][j] == '#':
                    continue
                if slistlist[i+1][j] == '#':
                    continue
                if slistlist[i][j-1] == '#':
                    continue
                if slistlist[i][j+1] == '#':
                    continue
                print('No')
                return

    print('Yes')


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
r, c = map(int, input().split())
d = [list(input()) for i in range(r)]
bom = [(x,y) for (x,i) in enumerate(d) for (y,j) in enumerate(i) if j == '#']
temp, result = [], "Yes"
for b in bom:
    pattern = [(b[0],b[1]+1), (b[0], b[1]-1), (b[0]+1, b[1]), (b[0]-1, b[1])]
    if sum([1 if x in bom else 0 for x in pattern]) == 0:
        result = "No"
        break
print(result)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*- #

h, w = map(int, input().split())
s_list = [list(input()) for _ in range(h)]
xy = [[0, 1], [-1, 0], [1, 0], [0, -1]]
flag = False
ans = "Yes"

for i in range(h):
    for j in range(w):
        if s_list[i][j] == "#":
            for k in xy:
                if (i+k[1] < 0 or i+k[1] >= h or j+k[0] < 0 or j+k[0] >= w) == False:
                    if s_list[i+k[1]][j+k[0]] == "#":
                        flag = True
            if flag == False:
                ans = "No"
                break
            flag = False
    else:
        continue
    break

print(ans)