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):
def iter_neighbor_indices(y, x, H, W):
    
    if y != 0:
        yield (y - 1, x)
    
    if y != H - 1:
        yield (y + 1, x)
    
    if x != 0:
        yield (y, x - 1)
    
    if x != W - 1:
        yield (y, x + 1)


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

    for y in range(H):
        for x in range(W):
            if color_grid[y][x] == '
                found = False

                
                for ny, nx in iter_neighbor_indices(y, x, H, W):
                    if color_grid[ny][nx] == '
                        found = True

                if not found:
                    print("No")
                    exit(0)

    print("Yes")

Solution (Python):
def check(y,x):
    if y-1 < 0:
        if x-1 < 0:
            move_x = [1,0]
            move_y = [0,1]
        if x+1 >= w:
            move_x = [-1,0]
            move_y = [0,1]
        else:
            move_x = [1,-1,0]
            move_y = [0,0,1]
    if y+1 >= h:
        if x-1 < 0:
            move_x = [1,0]
            move_y = [0,-1]
        if x+1 >= w:
            move_x = [-1,0]
            move_y = [0,-1]
        else:
            move_x = [1,-1,0]
            move_y = [0,0,-1]
    else:
        if x-1 < 0:
            move_x = [1,0,0]
            move_y = [0,1,-1]
        if x+1 >= w:
            move_x = [-1,0,0]
            move_y = [0,1,-1]
        else:
            move_x = [1,-1,0,0]
            move_y = [0,0,1,-1]
    for i in range(len(move_x)):
        if stage[y+move_y[i]][x+move_x[i]] == "
            return True
    return False
h,w = map(int, input().split())
stage = [input() for i in range(h)]
for i in range(h):
    for j in range(w):
        if stage[i][j] == "
            if not check(i,j):
                print("No")
                quit()
print("Yes")

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

def search(y, x):
    t = 0
    for i in [[0, 1], [0, -1], [1, 0], [-1, 0]]:
        dy, dx = y + i[0], x + i[1]
        if s[dy][dx] == '
            t += 1
    if t > 0:
        return True
    else:
        return False


for i in range(w):
    for j in range(h):
        if s[j+1][i+1] == '
            print('No')
            quit()
print('Yes')

Solution (Python):


def check(table,i,j,h,w):
    if i < h-1:
        if table[i+1][j] == "
            return 1
    if i > 0:
        if table[i-1][j] == "
            return 1
    if j < w -1:
        if table[i][j+1] == "
            return 1
    if j > 0:
        if table[i][j-1] == "
            return 1
    return 0

input_num = input().split(" ")
h = int(input_num[0])
w = int(input_num[1])
table = []
for i in range(h):
    s = input()
    table.append([])
    for j in range(w):
        table[i].append(s[j])

output = "Yes"
for i in range(h):
    for j in range(w):
        if table[i][j] == "
            if check(table,i,j,h,w) == 0:
                output = "No"

print(output)

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

for i in range(h):
    for j in range(w):
        if picture[i][j] == "
            if i == 0:
                if j == 0:
                    if picture[i+1][j] != "
                        flag = False
                        break
                elif j == w-1:
                    if picture[i+1][j] != "
                        flag = False
                        break
                else:
                    if picture[i+1][j] != "
                        flag = False
                        break
            elif i == h-1:
                if j == 0:
                    if picture[i-1][j] != "
                        flag = False
                        break
                elif j == w-1:
                    if picture[i-1][j] != "
                        flag = False
                        break
                else:
                    if picture[i-1][j] != "
                        flag = False
                        break
            else:
                if j == 0:
                    if picture[i+1][j] != "
                        flag = False
                        break
                elif j == w-1:
                    if picture[i+1][j] != "
                        flag = False
                        break
                else:
                    if picture[i+1][j] != "
                        flag = False
                        break

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

Solution (Python):
h, w = map(int, input().split())
S = []
for i in range(h):
    S.append(input())


def ans():
    for i in range(h):
        for j in range(w):
            if (S[i][j] == '
                    and (i == 0 or S[i-1][j] == '.')\
                    and (i+1 == h or S[i+1][j] == '.')\
                    and (j == 0 or S[i][j-1] == '.')\
                    and (j+1 == w or S[i][j+1] == '.'):
                return 'No'
    return 'Yes'


print(ans())

Solution (Python):
import sys

def sub(field, x, y):
  if y < 0 or x < 0 or y >= len(field) or x >= len(field[y]):
    return True
  if field[y][x] == '
    return True
  return False

def isok(field, x, y):
  units = [(0, 1), (1, 0), (0, -1), (-1, 0)]
  for unit in units:
    _x = x + unit[0]
    _y = y + unit[1]
    if sub(field, _x, _y):
      return True
  return False


l = sys.stdin.readline()
xy = [int(x) for x in l.rstrip('\n').split(' ')]
height = xy[0]
width = xy[1]

field = []
for _ in xrange(height):
  field.append(sys.stdin.readline().rstrip('\n'))

for y in xrange(len(field)):
  for x in xrange(len(field[y])):
    if field[y][x] == '
      print 'No'
      exit()
print 'Yes'

Solution (Python):
def paintable(grid, rows, columns):
    def isolated(r, c):
        if r > 0 and grid[r-1][c] == '
            return False
        if r < rows - 1 and grid[r+1][c] == '
            return False
        if c > 0 and grid[r][c-1] == '
            return False
        if c < columns - 1 and grid[r][c+1] == '
            return False
        return True

    for r in range(rows):
        for c in range(columns):
            if grid[r][c] == '
                return False
    return True
            

if __name__ == '__main__':
    h, w = map(int, input().split())
    grid = [list(input()) for _ in range(h)]
    if paintable(grid, h, w):
        print('Yes')
    else:
        print('No')

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

paintable = True

for i in range(H):
    for j in range(W):
        if grid[i][j] == '
            if i == 0:
                if j == 0:
                    if grid[i][j+1] == '.' and grid[i+1][j] == '.':
                        paintable = False
                elif j == W - 1:
                    if grid[i][j-1] == '.' and grid[i+1][j] == '.':
                        paintable = False
                else:
                    if grid[i][j+1] == '.' and grid[i+1][j] == '.' and grid[i][j-1] == '.':
                        paintable = False
            elif i == H - 1:
                if j == 0:
                    if grid[i][j+1] == '.' and grid[i-1][j] == '.':
                        paintable = False
                elif j == W - 1:
                    if grid[i][j-1] == '.' and grid[i-1][j] == '.':
                        paintable = False
                else:
                    if grid[i][j+1] == '.' and grid[i-1][j] == '.' and grid[i][j-1] == '.':
                        paintable = False
            else:
                if j == 0:
                    if grid[i][j+1] == '.' and grid[i-1][j] == '.' and grid[i+1][j] == '.':
                        paintable = False
                elif j == W - 1:
                    if grid[i][j-1] == '.' and grid[i-1][j] == '.' and grid[i+1][j] == '.':
                        paintable = False
                else:
                    if grid[i][j+1] == '.' and grid[i+1][j] == '.' and grid[i][j-1] == '.' and grid[i-1][j] == '.':
                        paintable = False
                    
if paintable:
    print("Yes")
else:
    print("No")

Solution (Python):
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]
[h,w]=i2()
s=[]
for i in range(h):
 s.append(input())
y=[[-1,0],[1,0],[0,1],[0,-1]]
ss="Yes"
for i in range(h):
 for j in range(w):
   if s[i][j]=="
     f=0
     for kx,ky in y:
       if 0<=i+kx<h and 0<=j+ky<w:
          if s[i+kx][j+ky]=="
               f=1
     if f==0:
        ss="No"
print(ss)

Solution (Python):


h, w = map(int, input().split())

m = []
for i in range(h):
    m.append(input())

res = True

for r in range(h):

    for c in range(w):
        if m[r][c] == ".": continue
        if c > 0 and m[r][c-1] == "
            continue
        if c < w-1 and m[r][c+1] == "
            continue
        if r > 0 and m[r-1][c] == "
            continue
        if r < h-1 and m[r+1][c] == "
            continue
        res = False

if res == True:
    print("Yes")
else:
    print("No")

Solution (Python):
x = [int(i) for i in input().split()]
h = x[0]
w = x[1]
aim = [[0 for i in range(w+2)] for j in range(h+2)]
for height in range(h):
    ipt = list(input())
    for width in range(w):
        if ipt[width] == '
            aim[height+1][width+1] =1

judge = 0
for height in range(h):
    for width in range(w):
        if aim[height+1][width+1] == 1:
            if aim[height][width+1] == 0 and aim[height+2][width+1] == 0 and aim[height+1][width] == 0 and aim[height+1][width+2] == 0:
                judge = 1

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

Solution (Python):
def inpl(): return list(map(int, input().split()))
H, W = inpl()
s = ['.'*(W+2)]
for i in range(H):
    s.append('.'+input()+'.')
s.append('.'*(W+2))

end = 0
dxy = [[1,0],[0,1],[-1,0],[0,-1]]
for i in range(1,H+1):
    for j in range(1,W+1):
        if s[i][j] == '
            for k in dxy:
                if s[i+k[0]][j+k[1]]=='
                    break
            else:
                end = 1
                break
    if end == 1:
        break
if end == 1:
    print('No')
else:
    print('Yes')

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

flag = False

for i in range(h):
    if flag:
        break
    for j in range(w):
        if s[i][j] == '.':
            continue
        
        if i > 0 and s[i-1][j] == '
            continue
        
        if i < h-1 and s[i+1][j] == '
            continue
        
        if j > 0 and s[i][j-1] == '
            continue
        
        if j < w-1 and s[i][j+1] == '
            continue
        flag = True
        break

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

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

for hi in range(h):
    for wi in range(w):
        if m[hi][wi] == "
            f = False
            for l in ([0,-1],[1,0],[0,1],[-1,0]):
                x=l[0]
                y=l[1]
                x +=hi
                y +=wi
                if 0<=x<h and 0<=y<w:
                    if m[x][y] == "
                        f=True
            if not f:
                print("No")
                exit()
print("Yes")

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

for j in range(H):
    for i in range(W):
        if M[j][i]!='
            continue
        
        if j>0 and M[j-1][i]=='
            continue
        
        if j<H-1 and M[j+1][i]=='
            continue
        
        if i>0 and M[j][i-1]=='
            continue
        
        if i<W-1 and M[j][i+1]=='
            continue
        print('No')
        exit()
print('Yes')

Solution (Python):
h,w = map(int,input().split())
m = [[j for j in list(input())] for i in range(h)]
def check(i,j):

    if i+1 < h and m[i+1][j] == '
        i-1 >= 0 and m[i-1][j] == '
        j+1 < w and m[i][j+1] == '
        j - 1 >= 0 and m[i][j-1] == '
        return True
    return False

for i in range(h):
    for j in range(w):
        if m[i][j] == '.':
            continue
        if not check(i,j):
            print('No')
            exit()
print('Yes')

Solution (Python):
y,x=[int(i) for i in input().split()]
a=[list(input()) for j in range(y)]
s=0
for i in range(y):
  for j in range(x):
    f=0
    if i-1>=0:
     if a[i-1][j]=='
        f+=1
    if j-1>=0:
     if a[i][j-1]=='
        f+=1        
    if i+1<=y-1:
     if a[i+1][j]=='
        f+=1
    if j+1<=x-1:
     if a[i][j+1]=='
        f+=1        
    if a[i][j]=='
      s=1 
if s==1:
  print('No')
else:
  print('Yes')

Solution (Python):
h, w = map(int, input().split())
l = []
l.append([0]*(w+2))
target = 0
count = 0
dirs = [[-1, 0], [1, 0], [0, -1], [0, 1]]
for i in range(h):
  temp = list(input())
  target += temp.count('
  l.append([0] + temp + [0])
l.append([0]*(w+2))
ans = []
for i in range(1, h+1):
  for j in range(1, w+1):
    if l[i][j] == '
      for dir in dirs:
        if l[i+dir[0]][j+dir[1]] == "
          count += 1
          break
    else:
      continue
    pass

if count == target:
  print('Yes')
else:
  print('No')

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] == "
            p = n = f = b = False
            if i > 0:
                if S[i - 1][j] == "
                    p = True
            if H - 1 > i:
                if S[i + 1][j] == "
                    n = True
            if j > 0:
                if S[i][j - 1] == "
                    b = True
            if W - 1 > j:
                if S[i][j + 1] == "
                    f = True
            if (p or n or f or b) == False:
                ans = "No"
print(ans)

Solution (Python):
l = map(int, raw_input().split())
H = l[0]
W = l[1]

s = []
for i in range(H):
    s.append(raw_input())

for i in range(H):
    for j in range(W):
        if s[i][j] == '
            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')
            exit(0)

print('Yes')

Solution (Python):
import re
import math

if __name__ == '__main__':

    h, w = [int(x) for x in input().split()]
    s = list()
    for i in range(h):
        tmp = list(input())
        s.append(tmp)

    for i in range(h):
        for j in range(w):
            if s[i][j] == '
                flg_none = True
                if i != 0 and s[i-1][j] == '
                    continue
                if i != h-1 and s[i+1][j] == '
                    continue
                if j != 0 and s[i][j-1] == '
                    continue
                if j != w-1 and s[i][j+1] == '
                    continue

                print('No')
                exit(0)

    print('Yes')

Solution (Python):












def f():
  a,b = (int(i) for i in input().split()) 
  s = []
  for i in range(a):
    s.append(input())
  for i in range(a):
    for j in range(b):
      if s[i][j]=='
        ok = False
        if i+1<a:
          if s[i+1][j]=='
            ok = True
        if j+1<b:
          if s[i][j+1]=='
            ok =True
        if i-1>=0:
          if s[i-1][j] == '
            ok=True
        if j-1>=0:
          if s[i][j-1]=='
            ok=True
        if ok==False:
          print('No')
          return
  print('Yes')
f()

Solution (Python):
n,m = map(int,input().split())
lis = []
for i in range(n):
    lis.append(str(input()))
for k in range(n):
    for h in range(m):
        if lis[k][h] == "
            key = 0
            try:
                if lis[k][h+1] == "
            except:
                key = 0
            if key == 0:
                try:
                    if lis[k][h-1] == "
                except:
                    key = 0
                if key == 0:
                    try:
                        if lis[k+1][h] == "
                    except:
                        key = 0
                    if key == 0:
                        try:
                            if lis[k-1][h] == "
                        except:
                            key = 0
                        if key == 0:
                            print("No")
                            exit()
print("Yes")

Solution (Python):
H, W = map(int, input().split(' '))
campus = ['.' + input() + '.' for _ in range(H)]
campus.insert(0, '.' * (W + 2))
campus.append('.' * (W + 2))
flag = 0
for i in range(H):
    for j in range(W):
        if campus[i][j] == '
            and campus[i-1][j] == '.' \
            and campus[i][j-1] == '.' \
            and campus[i+1][j] == '.' \
            and campus[i][j+1] == '.':
            flag = 1
            break
if flag == 0:
    print('Yes')
else:
    print('No')

Solution (Python):
H,W=[int(x) for x in input().split()]
matrix=[]
for _ in [0]*H:
    matrix.append(input())
import sys
for h in range(H):
    for w in range(W):
        if matrix[h][w]==".":
            continue
        elif h>0 and matrix[h-1][w]=="
            continue
        elif h<H-1 and matrix[h+1][w]=="
            continue
        elif w>0 and matrix[h][w-1]=="
            continue
        elif w<W-1 and matrix[h][w+1]=="
            continue
        else:
            print("No")
            sys.exit()
print("Yes")

Solution (Python):
h,w = map(int,input().split())
a = []
for i in range(h):
    m = str(input())
    a.append(m)


ans = True

for i in range(h):
    for k in range(w):
        
        if a[i][k] == "
            if i != 0 and k != 0 and i != h-1 and k != w-1:
                if a[i][k-1] == "." and a[i][k+1] == "." and a[i-1][k] == "." and a[i+1][k] == ".":
                    ans = False
            elif i == 0 and k == 0 :
                if a[i][k+1] == "." and a[i+1][k] == ".":
                    ans = False
            elif i == 0 and k == w-1:
                if a[i][k-1] == "." and a[i+1][k] == ".":
                    ans = False
            elif i == h-1 and k == 0 :
                if a[i][k+1] == "." and a[i-1][k] == ".":
                    ans = False
            elif i == h-1 and k == w-1:
                if a[i][k-1] == "." and a[i-1][k] == ".":
                    ans = False

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

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

b = [[False] * w for _ in range(h)]

for y in range(h):
    for x in range(w):
        if ls[y][x] == '.':
            b[y][x] = True

for y in range(h):
    for x in range(w - 1):
        if ls[y][x] == ls[y][x + 1] == '
            b[y][x] = b[y][x + 1] = True

for x in range(w):
    for y in range(h - 1):
        if ls[y][x] == ls[y + 1][x] == '
            b[y][x] = b[y + 1][x] = True

print(('No', 'Yes')[all(all(xs) for xs in b)])

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

def solve(H, W, S):
    S = [s + "." for s in S] + ["." * (W + 1)]
    for y in range(H):
        for x in range(W):
            if (S[y][x] == "
                S[y][x + 1] == "." and S[y][x - 1] == "." and
                S[y + 1][x] == "." and S[y - 1][x] == "."
            ):
                return False
    return True

if solve(H, W, S):
    print("Yes")
else:
    print("No")

Solution (Python):



def get_next_int():
    return int(float(input()))


def get_next_ints(delim=" "):
    return tuple([int(float(x)) for x in input().split(delim)])


def get_next_str():
    return input()


def get_next_strs(delim=" "):
    return tuple(input().split(delim))


def get_next_by_types(*value_types, delim=" "):
    return tuple([t(x) for t, x in zip(value_types, input().split(delim))])


class Grid():

    def __init__(self):
        self.H, self.W = get_next_ints()
        self.canvas = []
        for i in range(self.H):
            self.canvas.append(get_next_str())

    def check(self, x, y):
        checker = False
        if x-1 >= 0:
            checker = checker or self.canvas[y][x-1] == '
        if x+1 < self.W:
            checker = checker or self.canvas[y][x+1] == '
        if y-1 >= 0:
            checker = checker or self.canvas[y-1][x] == '
        if y+1 < self.H:
            checker = checker or self.canvas[y+1][x] == '
        return checker

    def solve(self):
        available = True
        for y in range(self.H):
            if not available:
                break
            for x in range(self.W):
                if self.canvas[y][x] == '
                    available = available and self.check(x, y)
        if available:
            print('Yes')
        else:
            print('No')


def solve():
    g = Grid()
    g.solve()
    
solve()

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

S = ["".join(["." for i in range(W+2)])]
for i in range(H):
    S.append("."+input()+".")
S.append("".join(["." for i in range(W+2)]))

isok = True
for h in range(1,H+1):
    for w in range(1,W+1):
        if S[h][w] == "
            b = 0
            if S[h][w-1] == "
            if S[h][w+1] == "
            if S[h-1][w] == "
            if S[h+1][w] == "
            if b==0:
                isok = False
                break
    if not isok: break

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

Solution (Python):
H = input().split()
W = int(H[1])
H = int(H[0])

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

ans = True
for h in range(H):
    for w in range(W):
        if M[h][w] == '.':
            continue
        flag = False
        if h > 0 and M[h-1][w] == '
            flag = True
        if h < H - 1 and M[h+1][w] == '
            flag = True
        if w > 0 and M[h][w-1] == '
            flag = True
        if w < W - 1 and M[h][w+1] == '
            flag = True
        if not flag:
            ans = False

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

Solution (Python):

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

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

for i in range(H):
	for j in range(W):
		if flag:
			break
		if canvas[i][j] == '.':
			continue
		flag = True
		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 and canvas[i+dy[k]][j+dx[k]] == '
				flag = False
				break
	if flag:
		break

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

Solution (Python):
c = []
h, w = list(map(int, input().split()))
for i in range(h):
    c.append(input())
yes = True
for i in range(h):
    for j in range(w):
        if(c[i][j] == "."):
            continue
        if(i != 0 and c[i - 1][j] == "
            continue
        if(i != h - 1 and c[i + 1][j] == "
            continue
        if(j != 0 and c[i][j - 1] == "
            continue
        if(j != w - 1 and c[i][j + 1] == "
            continue
        yes = False
if(yes):
    print("Yes")
else:
    print("No")

Solution (Python):
dxy = [[0, 1], [1, 0], [0, -1], [-1, 0]]

def solve():
    H, W = map(int, raw_input().split())
    s = [raw_input() for i in xrange(H)]
    for y in xrange(H):
        for x in xrange(W):
            if s[y][x] == "
                for dx, dy in dxy:
                    nx, ny = x + dx, y + dy
                    if not (0 <= nx < W and 0 <= ny < H):
                        continue
                    if s[ny][nx] == "
                        break
                else:
                    return False
    return True

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

Solution (Python):
h,w=map(int,input().split())
mez=['.'*(w+1)]

for _ in range(h):
    meztmp=input()
    mez.append('.'+meztmp+'.')
mez.append('.'*(w+1))
for y in range(1,h+1):
    for x in range(1,w+1):
        if mez[y][x]=='
            if mez[y-1][x]=='.' and mez[y+1][x]=='.' and mez[y][x+1]=='.' and mez[y][x-1]=='.':
                print('No')
                exit()
print('Yes')

Solution (Python):
h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]
flag = True
for i in range(h):
    for j in range(w):
        if s[i][j] == '
            if not(i == 0 or s[i-1][j] == '
                flag = False
            if not(flag):
                break
        if not(flag):
            break
print('Yes' if flag else 'No')

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


def enclose_field(field, outline="
    """
    迷路等の外周をoutlineで埋めることで、IndexErrorを回避できます。
    [0, 0] → [1, 1]、[H-1, W-1] → [H, W]となります。
    """
    for i in range(len(field)):
        field[i] = [outline] + field[i] + [outline]
    field.append([outline] * (len(field[0])))
    field.insert(0, [outline] * (len(field[0])))
    return field


S = enclose_field(S, outline="a")

for i in range(H):
    for j in range(W):
        if S[i][j] == "
            adj = [S[i+1][j], S[i-1][j], S[i][j+1], S[i][j-1]]
            if "
                print("No")
                exit()
else:
    print("Yes")

Solution (Python):

from itertools import product
def inpl(): return map(int, input().split())
H, W = inpl()
S = [list("."*(W+2))]
for _ in range(H):
    S.append(list("." + input() + "."))
S.append(list("."*(W+2)))

for h, w, in product(range(1, H+1), range(1, W+1)):
    if S[h][w] == ".":
        continue
    ok = False
    for dh, dw in [[0, 1], [0, -1], [1, 0], [-1, 0]]:
        if S[h+dh][w+dw] == "
            ok = True
            break
    if not ok:
        print("No")
        break
else:
    print("Yes")

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

flag = True
for i in range(h):
    for j in range(w):
        if F[i][j] == "
            flag2 = False
            for dx, dy in [(1, 0), (0, 1), (-1, 0), (0, -1)]:
                nx, ny = i + dx, j + dy
                if 0 <= nx < h and 0 <= ny < w and F[nx][ny] == "
                    flag2 = True
            if not flag2:
                flag = False
                break

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

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


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

Solution (Python):



def main():
    H, W = map(int, input().split())
    grid = []
    for h in range(H):
        grid.append([c for c in input()])

    for x in range(W):
        for y in range(H):
            if grid[y][x] == '
                for x_, y_ in zip([0, 0, -1, 1], [-1, 1, 0, 0]):
                    nx = x + x_
                    ny = y + y_
                    if not(0 <= nx < W):
                        continue
                    if not(0 <= ny < H):
                        continue
                    if grid[ny][nx] == '
                        break
                else:
                    print('No')
                    return
    print("Yes")
    return


if __name__ == '__main__':
    main()

Solution (Python):
H, W = map(int,input().split())
C = ['.' * (W + 2)]

for i in range(H):
    C += ["." + input() + "."]

C += ['.' * (W + 2)]

result = "Yes"
for i in range(1, H + 2):
    for j in range(1, W + 2):
        if C[i][j] == "
            if "
                result = "No"

print(result)

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

flag = True
for h in range(H):
    for w in range(W):
        if s[h][w] == "
                h != H - 1 and s[h + 1][w] == "
                w != 0 and s[h][w - 1] == "
                w != W - 1 and s[h][w + 1] == "
            print("No")
            sys.exit()
print("Yes")

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

C = ["."*(W+2)]
for k in range(H):
    C.append("."+input()+".")
C.append("."*(W+2))

for k in range(1,W+1):
    for l in range(1,H+1):
        if C[l][k]=="
            if C[l+1][k]=="
                pass
            else:
                print("No")
                exit(0)
print("Yes")

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

matrix = [input() for _ in range(h)]

cond = True
for i in range(h):
    for j in range(w):
        if matrix[i][j] == '
            tmp_cond = False
            try:
                if matrix[i - 1][j] == '
                    tmp_cond = True
            except:
                pass
            try:
                if matrix[i + 1][j] == '
                    tmp_cond = True
            except:
                pass
            try:
                if matrix[i][j - 1] == '
                    tmp_cond = True                    
            except:
                pass            
            try:
                if matrix[i][j + 1] == '
                    tmp_cond = True 
            except:
                pass
            
            if tmp_cond == False:
                cond = False
                
if cond:
    print('Yes')
else:
    print('No')

Solution (Python):

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

str = []
for i in range(H):
    str.append("."+input()+".")
    



H+=2
W+=2

str.insert(0, "."*(W))
str.append("."*(W))

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

        diff = [0,1,0,-1,0]
        is_ok = False
        for d in range(4):
            if str[i+diff[d]][j+diff[d+1]] == '
                is_ok = True
        if is_ok==False:
            print("No")
            exit(0)
            
print("Yes")