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

dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]
  
flg = False
for i in range(H):
  for j in range(W):
    if S[i][j] == "#":
      flg = False
      for k in range(4):
        if i+dy[k]>=0 and i+dy[k]<H and j+dx[k]>=0 and j+dx[k]<W:
          if S[i+dy[k]][j+dx[k]]=='#':
            flg = True
      if flg == False:
        print("No")
        exit()
print("Yes")

Submission status: Accepted

Solution code:
h,w = map(int, input().split())
#get hight and weidth 
glid = [0] * ( h+ 2)

h_index = [-1, 0, 0,  1]
w_index = [ 0, -1, 1, 0]



glid[0]=["."] * ( w + 2 )
glid[h + 1 ] = ["."] * ( w + 2 )

for i in range(h):
	temp1 = ["."]
	temp2 = list(input())
	temp1.extend(temp2)
	temp1.append(".")
	glid[ i + 1 ] = temp1

# get glids 

cnt = 0

for j in range(h):
	for k in range(w):
		if glid[ j + 1 ][ k + 1 ] == "#" and glid[ j ][ k + 1 ] == "." and glid[ j + 2 ][ k + 1 ] == "." and glid[ j + 1][ k  ] == "." and glid[ j + 1][ k +2 ] == "." :
			cnt += 1

if cnt > 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)]
check = [[False]*W]*H
dx = -1,0,1,0
dy = 0,-1,0,1

for h in range(H):
  for w in range(W):
    bcount = 0 #隣接する黒ますの個数
    if s[h][w] == "#":
      for i in range(4):
        if 0 <= h+dx[i] <= H-1 and 0 <= w+dy[i] <= W-1 and s[h+dx[i]][w+dy[i]] == "#":
            bcount += 1
      if bcount == 0:
        print("No")
        exit()
print("Yes")

Submission status: Accepted

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

S = [[0 for j in range(W)] for i in range(H)]
for i in range(H):
    for j, sij in enumerate(input()):
        S[i][j] = sij

flag = True

for i in range(H):
    for j in range(W):
        if S[i][j] == '#':
            if 0 <= i-1 and S[i-1][j] == '#' or 0 <= j-1 and S[i][j-1] == '#' or j+1 < W and S[i][j+1] == '#' or i+1 < H and S[i+1][j] == '#':
                continue
            else:
                flag= False
                break
    if flag == False:
        break

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

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
s = []
for i in range(H):
    s.append(input())
for i in range(H):
    for j in range(W):
        if s[i][j] == "#":
            bool1 = i > 0 and s[i - 1][j] == "#"
            bool2 = i < H-1 and s[i+1][j] == "#"
            bool3 = j > 0 and s[i][j - 1] == "#"
            bool4 = j < W-1 and s[i][j + 1] == "#"
            if bool1 or bool2 or bool3 or bool4:
                continue
            else:
                print("No")
                exit()

print("Yes")

Submission status: Accepted

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

for i in range(h):
  for j in range(w):
    if s[i][j] == "#":
      if (i + 1 < h and s[i + 1][j] == "#") or (0 <= i - 1 and s[i - 1][j] == "#") or (j + 1 < w and s[i][j + 1] == "#") or (0 <= j - 1 and s[i][j - 1] == "#"):
        continue
      else:
        print("No")
        exit()
    else:
      continue
print("Yes")

Submission status: Accepted

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

def check_border(x, y):
  return 0<=x and x<W and 0<=y and y<H

def can_draw(x, y):
  a = 1 if check_border(x-1,y) and canvas[y][x-1]=='#' else 0
  b = 1 if check_border(x+1,y) and canvas[y][x+1]=='#' else 0
  c = 1 if check_border(x,y-1) and canvas[y-1][x]=='#' else 0
  d = 1 if check_border(x,y+1) and canvas[y+1][x]=='#' else 0
  return 0 < a+b+c+d
        

def solve():
  for y in range(H):
    for x in range(W):
      if  ((canvas[y][x]=='#') and (not can_draw(x, y))): return False
  return True

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
from itertools import product

H, W = map(int, input().split())
maps = [['.']*(W+2)] + [(['.'] + list(input()) + ['.']) for _ in range(H)] + [['.']*(W+2)]
dxy = ((0, -1), (0, 1), (-1, 0), (1, 0))

for i, j in product(range(1, H+1), range(1, W+1)):
    if maps[i][j] == '#':
        for k, l in dxy:
            if maps[i+k][j+l] == '#':
                break
        else:
            print("No")
            exit()

print("Yes")

Submission status: Accepted

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

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

ans = True
for i in range(H):
    for j in range(W):
        if s[i][j] == '.':
            continue
        else:
            check = True
            for k in range(len(dx)):
                y = i+dy[k]
                x = j+dx[k]
                if x<0 or x>(W-1) or y<0 or y>(H-1):
                    continue
                else:
                    if s[y][x]=='#':
                        check = False
            if check:
                ans = False
                break
    if not ans:
        break

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

Submission status: Accepted

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

for y in range(H):
    for x in range(W):
        if f[y][x] == '#':
            flag = 0
            for dy, dx in [(1, 0), (-1, 0), (0, 1), (0, -1)]:
                ny, nx = y + dy, x + dx
                if 0 <= nx < W and 0 <= ny < H:
                    if f[ny][nx] == '#':
                        flag = 1
            if flag == 0:
                print('No')
                exit()
print('Yes')

Submission status: Accepted

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

for y in range(H):
    for x in range(W):
        if field[y][x] == '#':
            flag = False
            for dy, dx in [(1, 0), (-1, 0), (0, 1), (0, -1)]:
                ny, nx = y + dy, x + dx
                if 0 <= nx < W and 0 <= ny < H:
                    if field[ny][nx] == '#':
                        flag = True
                else:
                    continue
            if flag is False:
                print('No')
                exit()
print('Yes')

Submission status: Accepted

Solution code:
h,w=map(int,input().split());a=[input()for i in range(h)]
def che(i,j):
  global h,w,a
  if i==0:
    if a[i+1][j]=="#":return
  elif i==h-1:
    if a[i-1][j]=="#":return
  else:
    if a[i-1][j]=="#"or a[i+1][j]=="#":return
  print("No");exit()
for i in range(h):
  s=a[i]
  if s[:2]=="#.":che(i,0)
  if s[-2:]==".#":che(i,w-1)
  for j in range(w-2):
    if s[j]+s[j+1]+s[j+2]==".#.":che(i,j+1)
print("Yes")

Submission status: Accepted

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

Submission status: Accepted

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

S.append(list('@'*(W+2)))
for i in range(H):
  s = list(input())
  s.insert(0,'@')
  s.append('@')
  S.append(s)
S.append(list('@'*(W+2)))

judge = 1 #1: 可,0:不可
count = 0
vy = [0,0,1,-1]
vx = [1,-1,0,0]
for i in range(H+2):
  if(count == 4): break  
  if((i != 0)and(i != H+1)):    
   for j in range(W+2):
    if(count == 4): break  
    if((j != 0)and(j != W+1)):
      if(S[i][j] == '#'):
        count = 0
        for k in range(4):
          if(S[i+vy[k]][j+vx[k]] == '#'): break
          count += 1
        if(count == 4):
          judge = 0
          break

if(judge == 1):
  print('Yes')
else:
  print('No')

Submission status: Accepted

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

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

    for y in range(H):
        for x in range(W):
            flag = True
            if G[y][x] == ".":
                continue

            flag = False

            for i in range(4):
                nx = x + dx[i]
                ny = y + dy[i]

                if nx < 0 or W <= nx or ny < 0 or H <= ny:
                    continue

                if G[ny][nx] == "#":
                    flag = True
                    break

            if not flag:
                print("No")
                return

    print("Yes")

main()

Submission status: Accepted

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

h,w = map(int,input().split())
s = [0]*(h+2)
s[0]= ["."]*(w+2)
for i in range(h):
    s[i+1] = ["."] + list(input()) + ["."]

ans = True
for i in range(1,h):
    for j in range(1,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] == ".":
                ans = False
                break

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

Submission status: Accepted

Solution code:
H,W=map(int,input().split())
S=["."*(W+2)]
for i in range(H):
  S.append("."+input()+".")
S.append("."*(W+2))
print("Yes" if all(S[i][j]=="." or (S[i+1][j]=="#" or S[i-1][j]=="#" or S[i][j+1]=="#" or S[i][j-1]=="#") for i in range(1,H+1) for j in range(1,W)) else "No")

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

import sys

# while : 0
# black : 1
H, W = map(int, input().rstrip().split(' '))
field = [[0] * W for _ in range(H)]

for i in range(H):
    for j, c in enumerate(input()):
        if c == '#':
            field[i][j] = 1
       
for h in range(H):
    for w in range(W):
        if field[h][w] == 1:
            if h + 1 < H:
                if field[h + 1][w] == 1:
                    continue
            if h - 1 >= 0:
                if field[h - 1][w] == 1:
                    continue
            if w + 1 < W:
                if field[h][w + 1] == 1:
                    continue
            if w - 1 >= 0:
                if field[h][w - 1] == 1:
                    continue
                    
            print('No')
            sys.exit()
            
print('Yes')

Submission status: Accepted

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

l = [['P' for _ in range(W + 2)] for _ in range(H + 2)]

for i in range(H) :
    s = list(input())
    for j in range(W) :
        l[i+1][j+1] = s[j]

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

ans = True

for i in range(1, H + 1) :
    for j in range(1, W + 1) :
        if l[i][j] != "#" :
            continue
        flag = False
        for k in range(len(dx)) :
            if l[i + dx[k]][j + dy[k]] == "#" :
                flag = True
                break
        if flag == False :
            ans = False

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

Submission status: Accepted

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

dx = [0, 1, 0, -1]
dy = [1, 0, -1, 0]
for h in range(H):
    for w in range(W):
        if S[h][w] == '#':
            for i in range(4):
                nh, nw = h+dx[i], w+dy[i]
                if 0 <= nh < H and 0 <= nw < W:
                    if S[nh][nw] == '#' or S[nh][nw] == 'b':
                        S[nh][nw] = 'b'
                        S[h][w] = 'b'

counter = 0
for i in range(H):
    for l in range(W):
        if S[i][l] == "#":
            counter += 1


if counter == 0:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
S = [['.' for _ in range(W+2)]]+[['.'] + list(input())+ ['.'] for _ in range(H)]+[['.' for _ in range(W+2)]]
S
Flag = True
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+1][j] == S[i][j-1] == S[i][j+1] == '.':
            Flag = False
if Flag:
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

Submission status: Accepted

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

def canPaint(h,w):
  if '#' in [S[h][w-1], S[h-1][w], S[h][w+1], S[h+1][w]]:
    return True
  else:
    return False

for h in range(1, H+1):
  for w in range(1, W+1):
    if S[h][w]=='#' and not canPaint(h,w):
      print('No')
      exit()
else:
  print('Yes')

Submission status: Accepted

Solution code:
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque, OrderedDict
from copy import deepcopy
from fractions import gcd
from functools import lru_cache, reduce
from math import ceil, floor
from sys import setrecursionlimit

import heapq
import itertools
import operator


inf = float('inf')


# globals
H, W = 0, 0
S = []


def set_inputs():
    global H, W, S
    H, W = get_li()
    for _ in range(H):
        row = get_lc()
        S.append(row)
    return


def main():
    setrecursionlimit(100000)
    set_inputs()
    # ----------MAIN----------
    for i in range(H):
        for j in range(W):
            if S[i][j] == ".":
                continue
            if i > 0 and S[i-1][j] == "#":
                continue
            if i < W - 1 and S[i+1][j] == "#":
                continue
            if j > 0 and S[i][j-1] == "#":
                continue
            if j < H - 1 and S[i][j+1] == "#":
                continue
            print("No")
            return
    print("Yes")
    return


def get_int():
    return int(input())


def get_float():
    return float(input())


def get_str():
    return input().strip()


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


def get_lf():
    return [float(f) for f in input().split()]


def get_lc():
    return list(input().strip())


def get_data(n, types):
    if len(types) == 1:
        return [types[0](input()) for _ in range(n)]
    return zip(*(
        [t(x) for t, x in zip(types, input().split())]
        for _ in range(n)
    ))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
 
a = list(map(int,input().split()))
H = a[0]
W = a[1]
board = [["d" for j in range(W+2)] for i in range(H+2)]
for i in range(H):
    temp = input()
    for j in range(W):
        board[i+1][j+1] = temp[j]
 
 
for i in range(1, H+1):
    for j in range(1, W+1):
        if board[i][j] == "#" and board[i][j-1] != "#" and board[i][j+1] != "#" and board[i-1][j] != "#" and board[i+1][j] != "#":
            print("No")
            sys.exit()
print("Yes")

Submission status: Accepted

Solution code:
h,w =map(int,input().split())
D = [[0]*(w+2) for _ in range(h+2)]
for _ in range(1,h+1):
    for inp,i in zip(input(),range(1,w+1)):
        if inp == ".":
            D[_][i] = 0
        else:
            D[_][i] = 1
Ans = True
for i in range(1,h+1):
    for j in range(1,w+1):
        if D[i][j] == 1:
            if D[i+1][j]+D[i-1][j]+D[i][j+1]+D[i][j-1] == 0:
                Ans = False
    if not(Ans):
        break
if Ans:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

def check(h, w):
    b1 = False
    b2 = False
    b3 = False
    b4 = False
    if h > 0:
        b1 = Sh[h-1][w] == '#'
    if w > 0:
        b2 = Sh[h][w-1] == '#'
    if h < H-1:
        b3 = Sh[h+1][w] == '#'
    if w < W-1:
        b4 = Sh[h][w+1] == '#'
    return b1 or b2 or b3 or b4

for h in range(H):
    for w in range(W):
        if Sh[h][w] == '#':
            if not check(h, w):
                print("No")
                break
    else:
        continue
    break
else:
    print("Yes")

Submission status: Accepted

Solution code:
h,w=map(int, input().split())
lst = [input() for i in range(h)] 
for i in range(h):
  for j in range(w): 
    if(lst[i][j]=="#"):
      u=1
      l=1
      r=1
      d=1
      if(i==0):
        u=0
      if(i==h-1):
        d=0
      if(j==0):
        l=0
      if(j==w-1):
        r=0
      if not(lst[i-u][j]=="#" or lst[i+d][j]=="#" or 
         lst[i][j-l]=="#" or lst[i][j+r]=="#"):
        print("No")
        quit()
else:
    print("Yes")

Submission status: Accepted

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

for y in range(1, h+1):
    pict[y][1:w+1] = list(input())
ans = "Yes"
for y in range(h):
    for x in range(w):
        if pict[y][x] == "#":
            if pict[y-1][x] == "." and pict[y+1][x] == "." and pict[y][x-1] == "." and pict[y][x+1] == ".":
                ans = "No"
print(ans)

Submission status: Accepted

Solution code:
def makegrid(target=False):
    H,W = map(int,input().split())
    S = [["" for i in range(W+2)]for j in range(H+2)]
    target_xy = []
    for y in range(H):
        line = input()
        for x in range(W):
            S[y+1][x+1] = line[x]
            if line[x] == target:
                target_xy.append([y+1,x+1])
    return H,W,S,target_xy

def getvalue_9(S,y,x): 
    around9 = [None for i in range(9)]      
    idx = 0 
    for h in range(-1,2):
        for w in range(-1,2):
            around9[idx] = S[y+h][x+w]
            idx +=1
    return around9

def getvalue_4(S,y,x):
    around4 = [S[y+1][x],S[y][x-1],S[y][x+1],S[y-1][x]]
    return around4

H,W,S,targets_xy = makegrid(target="#")
ans = "Yes"
for xy in targets_xy:
    around4 = getvalue_4(S,xy[0],xy[1])
    if not ("#" in around4):
        ans = "No"

print(ans)

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
S = [['.']*(W + 2)] + [list('.' + input() + '.') for _ in range(H)] + [['.']*(W + 2)]
# print(S)
# 上下左右に隣り合う黒がいない黒を探す
for i in range(1, H):
    for k in range(1, W):
        if S[i][k] == '#' and S[i][k - 1] != '#' and S[i - 1][k] != '#' and S[i][k + 1] != '#' and S[i + 1][k] != '#':
            print('No')
            exit()
print('Yes')

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
s = ["".join(["0"]*(W+2))] + ["0"+input()+"0" for _ in range(H)] + ["".join(["0"]*(W+2))]
failed = False
for i in range(1, H+1):
    for j in range(1, W+1):
        if '#' != s[i][j]:
            continue
        if '#' in [s[i+x][j+y] for x, y in [(0, -1), (-1, 0), (1, 0), (0, 1)]]:
            continue
        else:
            failed = True
            break
    if failed:
        print("No")
        break
else:
    print("Yes")

Submission status: Accepted

Solution code:
H,W=map(int,input().split(' '))
F=[input() for i in range(H)]
ans='Yes'
for y in range(H):
    for x in range(W):
        if ans=='No':
            break
        else:
            a = F[y][x]=='#'
            b = x==0 or (x>0 and F[y][x-1]=='.')
            c = x==W-1 or (x<W-1 and F[y][x+1]=='.')
            d = y==0 or (y>0 and F[y-1][x]=='.')
            e = y==H-1 or (y<H-1 and F[y+1][x]=='.')
            if a and b and c and d and e:
                ans='No'
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
h, w = [int(item) for item in input().split()]
shw = ["." * (w+2)] + ["." + input() + "." for _ in range(h)] + ["." * (w+2)]

ans = True
for i in range(1,w+1):
  for j in range(1,h+1):
    if shw[j][i] == ".":
      continue
    if shw[j][i+1] == "." and shw[j][i-1] == "." and shw[j+1][i] == "." and shw[j-1][i] == ".":
      ans = False
      break

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

Submission status: Accepted

Solution code:
def isDraw(s, H, W):
    for h in range(H):
        for w in range(W):
            if s[h][w] != "#":
                continue
            if h > 0 and s[h-1][w] == "#":
                continue
            if h < H-1 and s[h+1][w] == "#":
                continue
            if w > 0 and s[h][w-1] == "#":
                continue
            if w < W-1 and s[h][w+1] == "#":
                continue
            return "No"
    return "Yes"

H, W = map(int, input().split())
s = []

for i in range(H):
    s.append(input())

print(isDraw(s, H, W))

Submission status: Accepted

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

if s[0][0] == "#":
    #print(0, 0, "黒")
    if not (s[0][1] == "#" or s[1][0] == "#"):
        print("No")
        exit()

for j in range(1, W-1):
    if s[0][j] == "#":
     #   print(0, j, "黒")
        if not (s[1][j] == "#" or s[0][j - 1] == "#" or s[0][j + 1] == "#"):
            print("No")
            exit()

if s[0][-1] == "#":
    #print(0, -1, "黒")
    if not (s[0][-2] == "#" or s[1][-1] == "#"):
        print("No")
        exit()

for i in range(1, H-1):
    if s[i][0] == "#":
     #   print(i, 0, "黒")
        if not (s[i][1] == "#" or s[i-1][0] == "#" or s[i+1][0] == "#"):
            print("No")
            exit()

for i in range(1, H-1):
    if s[i][-1] == "#":
     #   print(i, -1, "黒")
        if not (s[i][-2] == "#" or s[i-1][-1] == "#" or s[i+1][-1] == "#"):
            print("No")
            exit()

if s[-1][0] == "#":
    #print(-1, 0, "黒")
    if not (s[-1][1] == "#" or s[-2][0] == "#"):
        print("No")
        exit()

for j in range(1, W-1):
    if s[-1][j] == "#":
     #   print(-1, j, "黒")
        if not (s[-2][j] == "#" or s[-1][j - 1] == "#" or s[-1][j + 1] == "#"):
            print("No")
            exit()

if s[-1][-1] == "#":
    #print(-1, -1, "黒")
    if not (s[-1][-2] == "#" or s[-2][-1] == "#"):
        print("No")
        exit()

for i in range(1, H-1):
    for j in range(1, W-1):
        if s[i][j] == "#":
     #       print(i, j, "黒")
            if not (s[i - 1][j] == "#" or s[i + 1][j] == "#" or s[i][j - 1] == "#" or s[i][j + 1] == "#"):
                print("No")
                exit()
print("Yes")

Submission status: Accepted

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

Submission status: Accepted

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

S =[list(input()) for i in range(H)]
dy = [-1, 0, 1, 0]
dx = [0, 1, 0, -1]

for y in range(H):
    for x in range(W):
        if S[y][x] == "#":
            count = 0
            err_count = 0
            for i in range(4):
                    if not (0 <= y + dy[i] < H) or not(0 <= x + dx[i] < W):
                        err_count += 1
                        continue
                    else:
                        if S[y + dy[i]][x + dx[i]] == ".":
                            count += 1
            if count + err_count== 4:
                print("No")
                sys.exit()
#if 0 > y + dy  or y + dy >= H or 0 > x + dx or x +dx >= W:
print("Yes")

Submission status: Accepted

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

S =[list(input()) for i in range(H)]
dy = [-1, 0, 1, 0]
dx = [0, 1, 0, -1]

for y in range(H):
    for x in range(W):
        if S[y][x] == "#":
            count = 0
            for i in range(4):
                    if not (0 <= y + dy[i] < H) or not(0 <= x + dx[i] < W):
                        continue
                    else:
                        if S[y + dy[i]][x + dx[i]] == ".":
                            count += 1
            if count == 4:
                print("No")
                sys.exit()
#if 0 > y + dy  or y + dy >= H or 0 > x + dx or x +dx >= W:
print("Yes")

Submission status: Accepted

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

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

for i in range(h):
  for j in range(w):
    if area[i][j] == '#':
      flag=0
      for x, y in xy:
        #斜めに黒が存在しないか確認（存在してしまったらそれは塗ることができないのでfalse）
        if 0 <= i + y < h and 0 <= j + x < w and area[i+y][j+x]=="#":
          flag=1
      if not flag:
        print('No')
        exit()
print('Yes')

Submission status: Accepted

Solution code:
import sys
H, W = map(int, input().split())
rows = []
for _ in range(0, H):
    rows.append(input())
x = [0,  0, 1, -1]
y = [1, -1, 0,  0]
for row_i in range(0, H):
    for col_i in range(0, W):
        if rows[row_i][col_i] != "#":
            continue
        flag = False
        for i in range(0, 4):
            dx = col_i + x[i]
            dy = row_i + y[i]
            if dx >= W or dx < 0 or dy >= H or dy < 0:
                continue
            if rows[dy][dx] == "#":
                flag = True
        if not flag:
            print ("No")
            sys.exit()
print ("Yes")

Submission status: Accepted

Solution code:
H, W = list(map(int, input().split()))
s = [input() for i in range(H)]
a = "#"
Ans = "Yes"
for i in range(H):
  for j in range(W):
    if s[i][j] == a:
      if i - 1 >= 0 and s[i - 1][j] == a: continue
      if i + 1 <= H - 1 and s[i + 1][j] == a: continue
      if j - 1 >= 0 and s[i][j - 1] == a: continue
      if j + 1 <= W - 1 and s[i][j + 1] == a: continue
      Ans = "No"
      break

print(Ans)

Submission status: Accepted

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

for i in range(0, h):
    s[i] = input()
    
def s_cor(i, j):
    global h, w
    if i < 0 or j < 0 or i >= h or j >= w:
        return False
    else:
        return s[i][j] == "#"

p = True
for i in range(0, h):
    for j in range(0, w):
        if s_cor(i, j) and (not s_cor(i - 1, j)) and (not s_cor(i, j - 1)) and (not s_cor(i + 1, j)) and (not s_cor(i, j + 1)):
            p = False
            break
    
if p:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
import sys
H,W = map(int,input().split())
lists= [[j for j in input()] for i in range(H)]
for l in lists:
    l.append(".")
    l.insert(0,".")
lists.insert(0,["."]*len(lists[0]))
lists.insert(len(lists),["."]*len(lists[0]))
check = True
for h in range(len(lists)):
    for w in range(len(lists[0])):
        if lists[h][w]=="#":
            if lists[h+1][w]!="#" and lists[h-1][w]!="#" and lists[h][w+1]!="#" and lists[h][w-1]!="#":
                print("No")
                sys.exit()
print("Yes")

Submission status: Accepted

Solution code:
OFFSETS = [(-1,0),(0,-1),(0,1),(1,0)]

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

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

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

print("Yes")

Submission status: Accepted

Solution code:
from itertools import product

H, W = map(int,input().split())
grid = [input() for i in range(H)]
colored_grid = ['.'*W for i in range(H)] #白色であることを.、黒色であることを#で表す #問題を解くだけならば必要ない

for i,j in product(range(H),range(W)):
    if grid[i][j] == '#':
        colored_grid[i][j].replace('.','#',1) #こちらも思ったようには動作しない "....."->"..#.."にならない
        #colored_grid[i][j] = '#' 思ったように動作しない
        for x,y in product(range(-1,2),repeat=2): #x=0,y=0で自身を含むことに注意
            if abs(x) + abs(y) == 2:
                continue
            if x == 0 and y == 0:
                continue
            if 0 <= i+x <= H-1 and 0 <= j+y <= W-1 and grid[i+x][j+y] == '#': #8近傍の黒色を探す
                colored_grid[i+x][j+y].replace('.','#',1)
                break #黒色に塗れた！
        else: #黒色に塗れなかった 
            colored_grid[i][j].replace('#','.',1)
            print('No')
            break
else:
    print('Yes')

Submission status: Accepted

Solution code:
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-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 pf(s): return print(s, flush=True)

H, W = LI()

rows = [['.' for i in range(W+2)]]
for i in range(H):
    row = input()
    chars = ['.']
    for w in range(W):
        chars.append(row[w])
    chars.append('.')
    rows.append(chars)
rows.append(['.' for i in range(W+2)])
#  for row in rows:
#      print(row)

# rows[高さ][幅]ができあがった
for h in range(1, H+1):
    for w in range(1, W+1):
        if rows[h][w] == '#':
            if not (rows[h][w-1] == '#' or rows[h][w+1] == '#' or rows[h-1][w] == '#' or rows[h+1][w] == '#'):
                print('No')
                exit()
print('Yes')