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

Solution (Python):
h, w = map(int, input().split())
s_list = [list(input()) for _ in range(h)]
dx_list = [1, 0, -1, 0]
dy_list = [0, 1, 0, -1]
answer = 'Yes'
for i in range(h):
    for j in range(w):
        if s_list[i][j] == '
            num = 0
            for dx, dy in zip(dx_list, dy_list):
                x = j + dx
                y = i + dy
                if x < 0 or x >= w:
                    continue
                if y < 0 or y >= h:
                    continue
                if s_list[y][x] == '
                    num += 1
            if not num:
                answer = 'No'
print(answer)

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

f=True
for i in range(H):
	for j in range(W):
		if A[i][j]=='
			g=False
			for a,b in [(-1,0),(1,0),(0,1),(0,-1)]:
				if 0<=i+a<H and 0<=j+b<W:
					if A[i+a][j+b]=='
			if not(g):f=False

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

Solution (Python):
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] == '
            isOK = False
            if i > 0 and S[i-1][j] == '
                isOK = True
            elif i < H-1 and S[i+1][j] == '
                isOK = True
            elif j > 0 and S[i][j-1] == '
                isOK = True
            elif j < W-1 and S[i][j+1] == '
                isOK = True
            if not isOK:
                break
    else:
        continue
    print('No')
    break
else:
    print('Yes')

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

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

for y in range(h):
    if impossible:
        break

    for x in range(w):
        if field[y][x] == '.':
            continue

        check = False

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

            if nx < 0 or nx >= w or ny < 0 or ny >= h:
                continue

            if field[ny][nx] == '
                check = True
        if not check:
            impossible = True
            break

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

Solution (Python):
h,w = (int(i) for i in input().split())
s = ['.' * (w+2)] + ['.' + input() + '.' for i in range(h)] + ['.' * (w+2)]
for i in range(1,h-1):
  for j in range(1,w-1):
    if s[i][j] == '
      tonari = [s[i][j+1], s[i][j-1], s[i+1][j], s[i-1][j]]
      if not(any(i == '
        print('No')
        exit()
print('Yes')

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

Solution (Python):

def main():
    
    H, W, *S = open(0).read().split()
    H, W = int(H), int(W)
    dxy = [(1, 0), (-1, 0), (0, 1), (0, -1)]
    for x, s in enumerate(S):
        for y, a in enumerate(s):
            if a == "
                for dx, dy in dxy:
                    nx, ny = x + dx, y + dy
                    if 0 <= nx < H and 0 <= ny < W and S[nx][ny] == "
                        break
                else:
                    print("No")
                    return
    print("Yes")


if __name__ == "__main__":
    main()

Solution (Python):
import sys


def input(): return sys.stdin.readline().strip()


def main():
    H, W = map(int, input().split())
    s = [['.']*(W+2) for _ in range(H+2)]
    for i in range(H):
        s[i+1][1:-1] = list(input())

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

    for i in range(1, H+1):
        for j in range(1, W+1):
            if s[i][j] == '.':
                continue

            count = 0
            for x, y in zip(dx, dy):
                if s[i+y][j+x] == '.':
                    count += 1

            if count == 4:
                print('No')
                return

    print('Yes')


if __name__ == "__main__":
    main()

Solution (Python):

H,W=map(int,input().split())
nx=[1,0,-1,0]
ny=[0,1,0,-1]

field=[]
for i in range(H):
  field.append(list(input()))

for n in range(W):
  for m in range(H):
    if field[m][n]=='.':
      continue
    
    hope=0
    for j in range(4):
      x=n+nx[j]
      y=m+ny[j]
      
      if x<0 or W<=x or y<0 or H<=y:
        continue

      if field[y][x]=='
        hope=1
      
    if hope==0:
      print('No')
      exit()

print('Yes')

Solution (Python):
H,W=map(int, input().split())
S=["."+input()+"." for _ in range(H)]
S=["."*(W+2)]+S+["."*(W+2)]
ans="Yes"
for i in range(H):
  for j in range(W):
    if S[i][j]=="
      ans="No"
print(ans)

Solution (Python):
H,W=[int(s) for s in input().split()]
cam_ls=[ "." for _ in range(H+2)]
for j in range(W+1):
  cam_ls[0]=cam_ls[0]+"."
  cam_ls[H+1]=cam_ls[H+1]+"."
for i in range(1,H+1):
  cam_ls[i]=cam_ls[i]+input()+"."
  
def pos(h,w):
  if cam_ls[h][w]==".":
    return 1
  elif (cam_ls[h+1][w]=="." and
        cam_ls[h-1][w]=="." and
        cam_ls[h][w+1]=="." and
        cam_ls[h][w-1]=="."):
    return 0
  else:
    return 1

ans=1
for i in range(1,H+1):
  for j in range(1,W+1):
    ans*=pos(i,j)
if ans==1:
  print("Yes")
else:
  print("No")

Solution (Python):
h, w = map(int, input().split())
board = ["
for i in range(h):
    board += ["
board += ["

for i in range(1, h):
    for j in range(1, w):
        f = 0
        if board[i][j] == ".":
            continue
        for dy, dx in zip([0, -1, 1, 0], [-1, 0, 0, 1]):
            if board[i + dy][j + dx] == ".":
                f += 1
            if f == 4:
                print("No")
                exit()
print("Yes")

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

arr=[]
for h in range(0,H):
    for w in range(0,W):
        if S[h][w]=='
            cnt=0
            if w!=0:
                cnt+=S[h][w-1]=='
            if w!=W-1:
                cnt+=S[h][w+1]=='
            if h!=0:
                cnt+=S[h-1][w]=='
            if h!=H-1:
                cnt+=S[h+1][w]=='
            arr.append(cnt>0)
print('Yes' if all(arr) else 'No')

Solution (Python):
h,w = map(int, input().split())
s = [list(input()) for i in range(h)]
dx = [0,1,0,-1]
dy = [1,0,-1,0]

for x in range(h):
    for y in range(w):
        if s[x][y] == "
            flag = False

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

                if 0 <= nx < h and 0 <= ny < w and s[nx][ny] == "
                    flag = True

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

print("Yes")

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

def check() :
    for y in range(H) :
        for x in range(W) :
            if s[y][x] == '.' :
                continue
                
            for dx, dy in ((1, 0), (-1, 0), (0, 1), (0, -1)) :
                if not (0 <= (y + dy) < H and 0 <= (x + dx) < W) :
                    continue
                if s[y+dy][x+dx] == '
                    break
            else :
                return 'No'
    return 'Yes'
    
print(check())

Solution (Python):
h, w = map(int, input().split())
s = [list(map(lambda x:x=="
f=0
for i in range(h):
    for j in range(w):
        if s[i][j]:
            s[i][j] ^= 1
            if 1^(s[max(0,i-1)][j]or s[i][max(0,j-1)]or s[i][min(w-1,j+1)]or s[min(h-1,i+1)][j]):f=1
            s[i][j] ^= 1
print("YNeos"[f::2])

Solution (Python):
h,w=map(int,input().split())
list1=[[0 for i in range(w)]for j in range(h)]
list2=[[0 for i in range(w)]for j in range(h)]
dx=[-1,1,0,0]
dy=[0,0,-1,1]
a=0
for j in range(h):
 s=input()
 for i in range(w):
  list1[j][i]=s[i]
for j in range(h):
  for i in range(w):
   if list1[j][i]=="
    for k in range(4):
     xk=i+dx[k]
     yk=j+dy[k]
     if xk>=0 and xk<w and yk>=0 and yk<h:
      list2[yk][xk]+=1
for j in range(h):
  for i in range(w):
    if list1[j][i]=="
     None
    else:
     a+=1
if a==h*w:
 print("Yes")
else:
 print("No")

Solution (Python):
H,W = [int(x) for x in input().split()]
meiro = [list(input()) for _ in range(H)]
memo =[[0 for i in range(W)] for l in range(H)]
dx = [1,0,-1,0]
dy = [0,1,0,-1]
for i in range(H):
  for j in range(W):
    cnt = 0
    if meiro[i][j]=="
      for x,y in zip(dx,dy):
        if i+x<0 or W<=j+y or j+y<0 or H<=x+i or meiro[i+x][y+j]==".":
          cnt += 1
          if cnt==4:
            print("No")
            exit()
print("Yes")

Solution (Python):
def check(m, i, j, H, W):
    left = False
    up = False
    right = False
    down = False
    left = ((j == 0) or (m[i][j-1] == "
    up = ((i == 0) or (m[i-1][j] == "
    right = ((j == (W - 1)) or (m[i][j+1] == "
    down = ((i == (H-1)) or (m[i+1][j] == "
    return left or right or up or down
  
H, W = map(int, input().split())
l = [str(input()) for i in range(H)]
ans = "Yes"
for i in range(H):
    for j in range(W):
        if (l[i][j] == "
            ans = "No"
print(ans)

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

grid = []

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

dir = [[0,1],[-1,0],[0,-1],[1,0]]

for i in range(h):
    for j in range(w):
        flg = 0
        if grid[i][j] == '
            for k in range(4):
                if 0 <= i + dir[k][0] <= h-1 and 0 <= j + dir[k][1] <= w-1:
                    if grid[i + dir[k][0]][j + dir[k][1]] == '
                        flg = 0
                        break
                    flg = 1
        if flg == 1:
            break
    if flg == 1:
        break

if flg == 1:
    print("No")
else:
    print("Yes")

Solution (Python):
H,W = map(int, input().split())
L = []
for i in range(H):
    L.append(input())
    
ans = "Yes"
for i in range(H):
    for j in range(W):
        if L[i][j] == "
            temp = []
            if i != 0:
                temp.append(L[i-1][j])
            if i != H-1:
                temp.append(L[i+1][j])
            if j != 0:
                temp.append(L[i][j-1])
            if j != W-1:
                temp.append(L[i][j+1])
            if "
                ans = "No"
                break

print(ans)

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

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

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

        flag = False
        for dx, dy in d:
            i2, j2 = i+dx, j+dy
            if not (0 <= i2 < H and 0 <= j2 < W):
                continue

            if S[i2][j2] == "
                flag = True

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

Solution (Python):
H,W=map(int,input().split())
S=[input() for _ in range(H)]
ans='Yes'
for i in range (H):
  for j in range (W):
    if S[i][j]=='
      if S[max(0,i-1)][j]!='
        ans='No'
        break
print(ans)

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

s=['.'*(w+2)]
for _ in range(h):
    s.append('.'+input()+'.')
s.append('.'*(w+2))
    

for i in range(h+1):
    for j in range(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")
                exit()
print("Yes")

Solution (Python):
h,w = map(int,input().split())
g = [['.'] * (w+2) for i in range(h+2)]
for i in range(h):
  g[i+1][1:-1] = input()
for i in range(h):
  for j in range(w):
    if g[i+1][j+1] == '
      f = 1
      for a,b in [[1,0],[0,1],[-1,0],[0,-1]]:
        if g[i+a+1][j+b+1] == '
          f = 0
          break
      if f:
        print('No')
        exit()
print('Yes')

Solution (Python):
h, w = map(int, input().split())
board = [ [0 for _ in range(w)] for _ in range(h) ]
for i in range(h):
  s = input()
  for j, c in enumerate(s):
    if c == '
      board[i][j] = 1

for i in range(h):
  c0 = board[i][0]
  for j in range(1, w):
    c = board[i][j]
    if c == 0:
      continue
    if board[i][j-1] == 1 or (j < w-1 and board[i][j+1] == 1):
      continue
    if (i > 0 and board[i-1][j] == 1) or (i < h-1 and board[i+1][j] == 1):
      continue
    print('No')
    exit()
print('Yes')

Solution (Python):
import sys
H, W = map(int, input().split())
s = [list(input()) for _ in range(H)]

for i in range(H):
    for j in range(W):
        if s[i][j] == '.':
            continue
        if i != 0:
            if s[i - 1][j] == '
                continue
        if i != H - 1:
            if s[i + 1][j] == '
                continue
        if j != 0:
            if s[i][j - 1] == '
                continue
        if j != W - 1:
            if s[i][j + 1] == "
                continue

        print('No')
        sys.exit()

print('Yes')

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

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

print('Yes')

Solution (Python):
h,w=map(int, input().split())
t=[["."]*(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 t[i][j]==".":continue
        if t[i-1][j]=="." and t[i+1][j]=="." and t[i][j-1]=="." and t[i][j+1]==".":
            print("No")
            exit()
print("Yes")

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

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

mapping = {'.':0, '

ans = 'Yes'
for i in range(H):
    for j in range(W):
        if ans == 'No':
          continue
        if Ss[i][j] == '
            counter = 0
            
            if j>0:
                counter += mapping[Ss[i][j-1]]
            if i>0:
                counter += mapping[Ss[i-1][j]]
            if i<H-1:
                counter += mapping[Ss[i+1][j]]
            if j<W-1:
                counter += mapping[Ss[i][j+1]]
      
            if counter == 0:
                ans = 'No'
            
print(ans)

Solution (Python):
import sys
input = sys.stdin.readline


def main():
    H, W = map(int, input().split())
    S = [list(input()[:-1]) for _ in range(H)]
    for i in range(H):
        for j in range(W):
            if S[i][j] != '
                continue

            flg = True
            if i-1>=0 and S[i-1][j]=='
                flg = False
            if i+1<H and S[i+1][j]=='
                flg = False
            if j-1>=0 and S[i][j-1]=='
                flg = False
            if j+1<W and S[i][j+1]=='
                flg = False
            
            if flg:
                print('No')
                return
    
    print('Yes')


if __name__ == '__main__':
    main()

Solution (Python):
h,w=map(int,input().split())
L=[list(input()) for i in range(h)]
for i in range(h):
    for j in range(w):
        if L[i][j]=='
            if L[i][max(j-1,0)]!='
                print('No')
                exit()
print('Yes')

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

flag = False
for i in range(H):
    for j in range(W):
        if s[i][j] == '
            if (j-1 >= 0 and s[i][j-1] == '.') and (j+1 < W and s[i][j+1] == '.') and (i-1 >= 0 and s[i-1][j] == '.') and (i+1 < H and s[i+1][j] == '.'):
                print('No')
                flag = True
                break
    if flag:
        break
else:
    print('Yes')

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


def lonely(i,j):
  if S[i][j]=="
    res=0
    if i-1>=0: res+=1 if S[i-1][j]=="
    if i+1<H: res+=1 if S[i+1][j]=="
    if j-1>=0: res+=1 if S[i][j-1]=="
    if j+1<W: res+=1 if S[i][j+1]=="
    
    return res
  else:
    return 1

ans="Yes"
for i in range(H):
  for j in range(W):
    if lonely(i,j)==0:
      ans="No"
print(ans)

Solution (Python):
def main():
    h,w=map(int, input().split())
    t=[["."]*(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 t[i][j]==".":continue
            if t[i-1][j]=="." and t[i+1][j]=="." and t[i][j-1]=="." and t[i][j+1]==".":
                print("No")
                exit()
    print("Yes")

main()

Solution (Python):
H, W = map(int, input().split())
grid = ['.' * (W + 2)]
for i 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] == "
                print('No')
                exit()
print('Yes')

Solution (Python):
import sys

def solve():
    H, W = map(int, sys.stdin.readline().split())
    S = ['.' + sys.stdin.readline().rstrip() + '.' for _ in range(H)]
    S.insert(0,'.'*(W+2))
    S.append('.'*(W+2))
    for h in range(1,H+1):
        for w in range(1,W+1):
            if S[h][w] == '
                if '.' == S[h-1][w] == S[h][w-1] == S[h][w+1] == S[h+1][w]:
                    print('No')
                    exit()
    print('Yes')
    
if __name__ == '__main__':
    solve()

Solution (Python):
import sys

input = sys.stdin.readline


class AtCoder:
    def main(self):
        H, W = map(int, input().split())
        s = [input().rstrip() for _ in range(H)]

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

        for h in range(1, H + 1):
            for w in range(1, W + 1):
                if s[h][w] == '
                    cnt = 0
                    for lr, ud in (0, -1), (0, 1), (-1, 0), (1, 0):
                        if s[h + lr][w + ud] == '
                            cnt += 1
                    if cnt == 0:
                        print('No')
                        exit()
        print('Yes')



if __name__ == '__main__':
    AtCoder().main()

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


can_paint = True
for i in range(1, h+1):
  for j in range(1, w+1):
    if pic[i][j] == "
      up = pic[i-1][j]
      down = pic[i+1][j]
      left = pic[i][j-1]
      right = pic[i][j+1]
      if up == "." and down == "." and left == "." and right == ".":
        can_paint = False
      
if can_paint == True:
  print("Yes")
else:
  print("No")

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

total = []
tmp = ''
for i in range(w+2):
    tmp += '.'
total.append(tmp)

for i in range(h):
    tmp = '.'
    row = input()
    tmp += row
    tmp += '.'
    total.append(tmp)

tmp = ''
for i in range(w+2):
    tmp += '.'
total.append(tmp)

flag = 0
for i in range(1, h+1):
    for j in range(1, w+1):
        if total[i][j] == '
            flag = 1

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

Solution (Python):


import sys
input = sys.stdin.readline
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7



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



for h in range(H):
    for w in range(W):
        if S[h][w] != '
            continue


        
        if h > 0:
            if S[h-1][w] == '
                continue

        
        if w > 0:
            if S[h][w-1] == '
                continue

        
        if h < H-1:
            if S[h+1][w] == '
                continue

        
        if w < W-1:
            if S[h][w+1] == '
                continue

        
        print('No')
        exit()

print('Yes')

Solution (Python):
h, w = map(int,input().split())
a = [input() for _ in range(h)]
y = [1,-1,0, 0]
x = [0, 0,1,-1]
flag = True
for i in range(h):
    for j in range(w):
        if a[i][j] == "
            for k in range(4):
                if i + y[k] < 0 or i + y[k] >= h or j + x[k] < 0 or j + x[k] >= w:continue
                if a[i+y[k]][j+x[k]] == "
                    break
            else:
                print("No")
                exit()
print("Yes")

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

hw = ['.' * (W+2)]
for i in range(H):
  hw.append('.' + input() + '.')
hw.append('.' * (W+2)) 
  
ans = "Yes"

for i in range(1, H+1):
  for j in range(1, W+1):
    if hw[i][j] == "
      if hw[i-1][j] == "." and hw[i][j-1] == "." and hw[i][j+1] == "." and hw[i+1][j] == ".":
        ans = "No"
        
print(ans)

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

jud = 'Yes'
for i in range(H):
    for j in range(W):
        if grid[i][j] == '
            try:
                if grid[i-1][j] == grid[i][j-1] == grid[i][j+1] == grid[i+1][j] == '.':
                    jud = 'No'
                else:
                    continue
            except Exception:
                break

print(jud)

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

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


def exist_neighbor_black_cell(i,j):
    if "
        return True
    else:
        print("No")
        exit()


for i in range(H):
    for j in range(W):
        if S[i][j] == "
            exist_neighbor_black_cell(i, j)

print("Yes")

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

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


def exist_neighbor_black_cell(i,j):
    if "
        return True
    else:
        print("No")
        exit()


for i in range(H):
    for j in range(W):
        if S[i][j] == "
            exist_neighbor_black_cell(i, j)

print("Yes")

Solution (Python):
import itertools
H,W = map(int, input().strip().split(' '))

board = ['.'*(W+2)]
board += ['.'+input().strip()+'.' for _ in range(H)]
board.append('.'*(W+2))


for x,y in itertools.product(range(1,W+1), range(1,H+1)):
  if board[y][x] == '.' : continue
  flag = False
  for dx,dy in [(1,0),(-1,0),(0,1),(0,-1)]:
    if board[y+dy][x+dx] == '
  if not flag:
    print('No')
    exit()
print('Yes')

Solution (Python):
def slove():
    import sys
    input = sys.stdin.readline
    h, w = list(map(int, input().rstrip('\n').split()))
    s = [list(str(input().rstrip('\n'))) for _ in range(h)]
    for i in range(h):
        for j in range(w):
            if s[i][j] == "
                b = False
                t = [[i + 1, j], [i - 1, j], [i, j + 1], [i, j - 1]]
                for ti, tj in t:
                    if 0 <= ti < h and 0 <= tj < w:
                        if s[ti][tj] == "
                            b = True
                            break
                if not b:
                    print("No")
                    exit()
    print("Yes")


if __name__ == '__main__':
    slove()

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


def is_valid(s, i, j):
    if 0 > i or i >= len(s):
        return False
    if 0 > j or j >= len(s[0]):
        return False
    return True


def check(s, i, j):
    if not is_valid(s, i, j):
        return True
    if '.' == s[i][j]:
        return True

    if is_valid(s, i - 1, j + 0):
        if '
            return True
    if is_valid(s, i + 0, j - 1):
        if '
            return True
    if is_valid(s, i + 1, j + 0):
        if '
            return True
    if is_valid(s, i + 0, j + 1):
        if '
            return True
    return False


for i in range(h):
    for j in range(w):
        if not check(s, i, j):
            print("No")
            exit(0)
print("Yes")

Solution (Python):
import sys

h, w = map(int, input().split())
s = [['.'] + list(input()) + ['.'] for i in range(h)]
s = [['.'] * (w+2)] + s + [['.'] * (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')
                sys.exit(0)
print('Yes')

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

for i in range(H):
    for j in range(W):
        if S[i][j]=='
            isOK=False
            if i-1 >= 0 and S[i-1][j]=='
                isOK=True
            if j-1 >= 0 and S[i][j-1]=='
                isOK=True
            if i+1 <= H-1 and S[i+1][j]=='
                isOK=True
            if j+1 <= W-1 and S[i][j+1]=='
                isOK=True
            
            if isOK==False:
                print("No")
                exit()

print("Yes")

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

for i in range(1,h-1):
  for j in range(1,w-1):
    if SW[i][j]=='
      if SW[i-1][j]=='
        pass
      else:
        print('No')
        exit()
print('Yes')

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

for i in range(h):
  for j in range(1,w+1):
    if i == 0:
      if s[i][j]=="
        print("No")
        exit()
    elif i == h-1:
      if s[i][j]=="
        print("No")
        exit()
    else:
      if s[i][j]=="
        print("No")
        exit()
        
print("Yes")

Solution (Python):

def main():
    H, W, *S = open(0).read().split()
    H, W = int(H), int(W)
    dxy = [(1, 0), (-1, 0), (0, 1), (0, -1)]
    for x, s in enumerate(S):
        for y, a in enumerate(s):
            if a == "
                for dx, dy in dxy:
                    nx, ny = x + dx, y + dy
                    if 0 <= nx < H and 0 <= ny < W and S[nx][ny] == "
                        break
                else:
                    print("No")
                    return
    print("Yes")


if __name__ == "__main__":
    main()

Solution (Python):





from sys import stdin,setrecursionlimit


setrecursionlimit(10**6)
input=stdin.readline

h,w=map(int,input().split())
s=[list(input().rstrip()) for _ in range(h)]
mas=[["."]*w for _ in range(h)]
for i in range(h):
    for j in range(w):
        if j+1<w and (s[i][j],s[i][j+1])==("
            mas[i][j],mas[i][j+1]="
        if j-1>=0 and (s[i][j],s[i][j-1])==("
            mas[i][j],mas[i][j-1]="
        if i+1<h and (s[i][j],s[i+1][j])==("
            mas[i][j],mas[i+1][j]="
        if i-1>=0 and (s[i][j],s[i-1][j])==("
            mas[i-1][j],mas[i][j]="
print("Yes" if mas==s else "No")

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

for i in range(H):
    for j in range(W):
        if s_list[i][j] == '.':
            continue
        else:
            if i != 0:
                if s_list[i - 1][j] == '
                    continue
            if i != H - 1:
                if s_list[i + 1][j] == '
                    continue
            if j != 0:
                if s_list[i][j - 1] == '
                    continue
            if j != W - 1:
                if s_list[i][j + 1] == '
                    continue
        print("No")
        exit()

print("Yes")

Solution (Python):
import sys
a, b = map(int, input().split())
paint = []
paint.append("".join(["."]*(b+2)))
for _ in range(a):
    t = input()
    s = "".join([".", t, "."])
    paint.append(s)
paint.append("".join(["."]*(b+2)))
for i in range(a):
    for j in range(b):
       if paint[i][j] == "
           if paint[i+1][j] == "." and paint[i-1][j] == "." and paint[i][j+1] == "." and paint[i][j-1] == ".":
                print("No")
                sys.exit()
print("Yes")

Solution (Python):
h,w = map(int,input().split())
zero = ['0' for i in range(w+2)]
S = [['0']+list(input())+['0'] for i in range(h)]
S = [zero] + S + [zero]
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] == '
        continue
      else:
        print('No')
        exit()
print('Yes')

Solution (Python):
x,y = map(int,input().split())
listA=[] 
while True:
    try:
        listA.append(list(input()))

    except:
        break;
s=0
for i in range(x):
  for j in range(y):
    if  ((listA[i][j]=='
    (listA[i][j]!=listA[i][max(0,j-1)])&(listA[i][j]!=listA[i][min(y-1,j+1)])):
      s+=1
if s==0:
  print('Yes')
else:
  print('No')

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

flag = 'Yes'
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] == '.':
				flag = 'No'
print(flag)

Solution (Python):
H, W = map(int, input().split())
S = [list(input()) for _ in range(H)]
d = [-1, 0, 1, 0]
for i in range(H):
  for j in range(W):
    if S[i][j] == ".":
      continue
    f = 1
    for k in range(4):
      if 0 <= i + d[k] < H and 0 <= j + d[-1 - k] < W:
        if S[i + d[k]][j + d[-1 - k]] == "
          f = 0
          break
    if f:
      print("No")
      exit(0)
print("Yes")

Solution (Python):
D = ((-1,0), (0,-1), (1,0), (0,1))
F, f = False, False
H, W = map(int, input().split())
S = [""] * H

for i in range(H):
  S[i] = input()
  
for i in range(H):
  for j in range(W):
    if S[i][j] != ".":
      f = True
      for d in D:
        if (0 <= d[0]+i < H) and (0 <= d[1]+j < W) :
          if S[d[0]+i][d[1]+j] == "
            f = False
            break
    if f:
      F = True
if F:
  print("No")
else:
  print("Yes")

Solution (Python):
H,W = map(int,input().split())
S = ["."+input()+"."for i in range(H)]
S = ["."*(W+2)]+S+["."*(W+2)]
flag=0
for i in range(H):
    for j in range(W):
        if S[i][j] == "
            if S[i-1][j]== "." and S[i+1][j]=="." and S[i][j-1]=="." and S[i][j+1]==".":
                flag=1
print("Yes" if flag==0 else "No")