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):
import sys
from collections import deque
def input(): return sys.stdin.readline().strip()


class UnionFind():
    """
    https://note.nkmk.me/python-union-find/
    DFSの上位互換と考えて良い
    ２要素x, yがpath-connectedかどうかをlogオーダーで判定する（螺旋本の14.1節参照）
    さらに連結成分の要素数がO(1)で取得可能なように改造してある
    """
    def __init__(self, n):
        """
        要素数をnとして、各ノードを0,1,...,(n-1)の番号で管理する
        parentsは各ノードの属する木の根を表す
        ただし根ノードのparentには(その木のノード数)*(-1)を格納する
        """
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        """
        xの属する木の根を返す
        このとき同時に経路圧縮して、探索途中のノードを全て根に繋ぎ直す
        """
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        """
        x, yのそれぞれ属する木Tx, Tyの根同士を繋ぐ
        このとき木の要素数が小さい方を大きい方に繋ぐ（rankではなくsizeを用いる）
        """
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        """
        xの属する木の要素数を返す
        根の親を要素数の(-1)倍で定めておいたおかげでO(1)で取得可能
        """
        return -self.parents[self.find(x)]

    def same(self, x, y):
        """
        xとyがpath-connectedかを判定する
        """
        return self.find(x) == self.find(y)

    def members(self, x):
        """
        xの属する木の要素を列挙する
        """
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        """
        連結成分の代表元のリストを返す
        """
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        """
        連結成分の個数を返す
        """
        return len(self.roots())

    def all_group_members(self):
         """
         連結成分およびそれぞれの代表元をまとめた辞書を返す
         代表元がキーになってる
         """
         return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        """
        連結成分およびその代表元を出力
        """
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


def main():
    H, W = map(int, input().split())
    S = [input() for _ in range(H)]
    tree = UnionFind(H * W)
    for i in range(H):
        for j in range(W):
            if S[i][j] != "
            for di, dj in [(1, 0), (0, 1), (-1, 0), (0, -1)]:
                ni, nj = i + di, j + dj
                if 0 <= ni < H and 0 <= nj < W and S[ni][nj] == "
                    tree.union(W * i + j, W * ni + nj)

    accomp = True
    for root in tree.roots():
        i, j = root // W, root % W
        if S[i][j] == "
            accomp = False
            break
    if accomp: print("Yes")
    else: print("No")

if __name__ == "__main__":
    main()

Solution (Python):





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

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


check = [[None] * w for i in range(h)]

for i in range(h):
    for j in range(w):
        if s[i][j] == '
            check[i][j] = False
            if i > 0 and s[i - 1][j] == '
                check[i][j] = True

            if i < h - 1 and s[i + 1][j] == '
                check[i][j] = True

            if j > 0 and s[i][j - 1] == '
                check[i][j] = True

            if j < w - 1 and s[i][j + 1] == '
                check[i][j] = True
        else:
            check[i][j] = True

if all([all(c) for c in check]):
    print('Yes')
else:
    print('No')

Solution (Python):
H,W=map(int,input().split())
p=[['.']*(W+2)]*(H+2)
for i in range(H):
  s=input()
  p[i+1]='.'+s+'.'
for i in range(1,H+1):
  for j in range(1,W+1):
    if p[i][j]=='
      flag=False
      for x,y in ([-1,0],[1,0],[0,-1],[0,1]):
        if p[i+x][j+y]=='
          flag=True
          break
      if not flag:
        print('No')
        exit()
print('Yes')

Solution (Python):
import sys

H, W = map(int, input().split())
square = []
for i in range(H):
    a = list(map(str, input()))
    square += a

if H == W == 1:
    print('Yes')
    sys.exit()
    
for i in range(H*W):
    if square[i] == '
        if i % W != W-1:
            if square[i+1] == '
                continue
        if i % W != 0:
            if square[i-1] == '
                continue
            
        if i-W >= 0:
            if square[i-W] == '
                continue
        if i+W <= H*W:
            if square[i+W] == '
                continue
        print('No')
        sys.exit()
        
print('Yes')

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]=='.':
            continue
        if not i==0:
            if s[i-1][j]=='
                continue
        if not j==0:
            if s[i][j-1]=='
                continue
        if not i==h-1:
            if s[i+1][j]=='
                continue
        if not j==w-1:
            if s[i][j+1]=='
                continue
        print('No')
        exit()
print('Yes')

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

visited = [[0] * W for i in range(H)]
def bfs(x, y):
  
  if visited[x][y] == 1:
    return 0
  visited[x][y] = 1
  
  if HW[x][y] == ".":
    return 0
    
  queue = [[0, 1], [0, -1], [1, 0], [-1, 0]]
  tt = 0
  for i, j in queue:
    if (0 <= x + i < H) and (0 <= y + j < W):
      if HW[x + i][y + j] == "
        tt = 1
        
  if tt == 0:
    return 1
  return 0
  
for i in range(H):
  for j in range(W):
    
    st = bfs(i, j)
    
    if st == 1:
      print("No")
      quit()
      
print("Yes")

Solution (Python):
import numpy as np


def main():
    h, w = map(int, input().split())
    sss = [list(input()) for _ in range(h)]
    check = [[0 for _ in range(w)] for _ in range(h)]
    move = [[-1, 0], [1, 0], [0, -1], [0, 1]]
    sharp_count = 0
    for i in range(h):
        for j in range(w):
            if sss[i][j] == '
                sharp_count += 1
                for k, l in move:
                    if i+k < h and i+k >= 0 and j+l < w and j+l >= 0:
                        if sss[i+k][j+l] == "
                            check[i][j] = 1
                            check[i+k][j+l] = 1
    if sharp_count == np.sum(check):
        print('Yes')
    else:
        print('No')


if __name__ == "__main__":
    main()

Solution (Python):
def grinp(h):
  ret=[]
  for i in range(h):
    ret.append(list(input()))
  return ret
h,w=map(int,input().split())
grid=grinp(h)
fa=False
for i in range(h):
  for j in range(w):
    if grid[i][j]==".":
      continue
    fl=0
    if i!=0 and grid[i-1][j]=="
      fl+=1
    if i!=h-1 and grid[i+1][j]=="
      fl+=1
    if j!=0 and grid[i][j-1]=="
      fl+=1
    if j!=w-1 and grid[i][j+1]=="
      fl+=1
    if fl==0:
      fa=True
      break
  if fa:
    break
if fa:
  print("No")
else:
  print("Yes")

Solution (Python):
h,w=map(int,input().split())
a=[input() for i in range(h)]
ans="Yes"
for i in range(h):
    for j in range(w):
        if i==0:
            if j==0:
                if a[i][j]=="
                    if h>=2:
                        if not a[i+1][j]=="
                            if w>=2:
                                if not a[i][j+1]=="
                                    ans="No"
                    elif w>=2:
                        if not a[i][j+1]=="
                            ans="No"
                    else:
                        ans="No"
                                    
            elif j==(w-1):
                if a[i][j]=="
                    if a[i][j-1]!="
                        if h==1:
                            ans="No"
                        else:
                            if a[i+1][j]!="
                                ans="No"
            else:
                if a[i][j]=="
                    if a[i][j-1]!="
                        if h==1:
                            ans="No"
                        else:
                            if a[i+1][j]!="
                                ans="No"
            
        elif i==(h-1):
            if j==0:
                if a[i][j]=="
                    if a[i-1][j]!="
                        if w==1:
                            ans="No"
                        else:
                            if a[i][j+1]!="
                                ans="No"
                
            elif j==(w-1):
                if a[i][j]=="
                    if a[i][j-1]!="
                        ans="No"
                
            else:
                if a[i][j]=="
                    if a[i][j-1]!="
                        ans="No"
                
        else:
            if j==0:
                if a[i][j]=="
                    if a[i-1][j]!="
                        if w==1:
                            ans="No"
                        else:
                            if a[i][j+1]!="
                                ans="No"
            elif j==(w-1):
                if a[i][j]=="
                    if a[i][j-1]!="
                        ans="No"
            else:
                if a[i][j]=="
                    if a[i][j-1]!="
                        ans="No"

print(ans)

Solution (Python):
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

def err():
    print('No')
    quit()
n,m = inpl()
s = [input() for _ in range(n)]
dx = (0,1,0,-1)
dy = (1,0,-1,0)
for i in range(n):
    for j in range(m):
        if s[i][j] == '
            for d in range(4):
                nx = dx[d]+j
                ny = dy[d]+i
                if 0 <= nx < m and 0 <= ny < n:
                    if s[ny][nx] == '
                        break
            else:
                err()
print('Yes')

Solution (Python):
def main():
    h, w = map(int, input().split())
    campus = []
    
    for i in range(h):
        campus.append(input())
    
    for y in range(h):
        for x in range(w):
            if campus[y][x] == '.':
                continue
            
            flg = True
            
            for l, k in [1, 0], [0, 1], [-1, 0], [0, -1]:
                ad_y, ad_x = y + l, x + k
                
                if ad_y < 0 or h <= ad_y or ad_x < 0 or w <= ad_x:
                    continue
                
                if campus[ad_y][ad_x] == '
                    flg = False
            
            if flg:
                print('No')
                return
    
    print('Yes')
    
if __name__ == '__main__':
    main()

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

for H in range(h):
    for W in range(w):
        stat=0
        
        if S[H][W]=='.':
            continue
        if H!=0:
            if S[H][W]==S[H-1][W]:
                stat=1
        if W!=w-1:
            if S[H][W]==S[H][W+1]:
                stat=1
        if H!=h-1:
            if S[H][W]==S[H+1][W]:
                stat=1
        if W!=0:
            if S[H][W]==S[H][W-1]:
                stat=1
        if stat==0:
            print('No')
            exit()

print('Yes')

Solution (Python):
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] == '
            flag = True
            if i != 0 and s[i-1][j] == '
                flag = False
            if i != h-1 and s[i+1][j] == '
                flag = False
            if j != 0 and s[i][j-1] == '
                flag = False
            if j != w-1 and s[i][j+1] == '
                flag = False
            if flag:
                print('No')
                exit()
print('Yes')

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] == "
            ok = False
            for x,y in [(1,0), (0,1), (-1, 0), (0,-1)]:
                new_h, new_w = i+x, j+y
                if new_h >= h or new_h < 0 or new_w >= w or new_w < 0: continue
                if s[new_h][new_w] == "
                    ok = True
                    break
            if not ok:
                print("No")
                exit()
print("Yes")

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

Solution (Python):
def check():
    H, W = map(int, input().split())
    S = [0]*(H+2)
    S[0] = '.'*(W+2)
    S[H+1] = '.'*(W+2)
    for h in range(1,H+1):
        S[h] = '.' + input() + '.'
    
    dh = [0,1,0,-1]
    dw = [1,0,-1,0]
    
    for h in range(1,H+1):
        for w in range(1,W+1):
            if S[h][w]=='.':
                continue
            for i in range(4):
                h0 = h+dh[i]
                w0 = w+dw[i]
                if S[h0][w0]=='
                    break
            else:
                return 'No'
    return 'Yes'
    
print(check())

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

vector = [[0,1],[1,0],[-1,0],[0,-1]]

for i in range(H):
    for j in range(W):
        if m[i][j] == "
            flag = False
            for dx,dy in vector:
                x = i + dx
                y = j + dy

                if 0 <= x < H and 0 <= y < W:
                    if m[x][y] == "
                        flag = True
            if not flag:
                print("No")
                exit()
                
print("Yes")

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

    DX = (-1, 0, 1, 0, -1, -1, 1, 1)
    DY = (0, 1, 0, -1, -1, 1, -1, 1)
    DX = DX[:4]
    DY = DY[:4]
    for i in range(1, H + 1):
        for j in range(1, W + 1):
            if grid[i][j] == ".":
                continue
            isOK = False
            for dx, dy in zip(DX, DY):
                if grid[i + dx][j + dy] == "
                    isOK = True
            if not isOK:
                return "No"

    return "Yes"


if __name__ == "__main__":
    print(main())

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

for i in range(h):
    for j in range(w):
        if S[i][j] == '
            flag = False
            for di, dj in (-1, 0), (1, 0), (0, 1), (0, -1):
                ni, nj = i+di, j+dj
                if 0 <= ni < h and 0 <= nj < w:
                    if S[ni][nj] == '
                        flag = True
                        break
            if not flag:
                print('No')
                exit()
else:
    print('Yes')

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

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

    return True

def main():
    for i in range(h):
        for j in range(w):
            if (board[i][j] == "
                if(check(i,j)):
                    return "No"

    return "Yes"

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

Solution (Python):
H,W = map(int,input().split())
A = []
for _ in range(H):
    a = input()
    a.split()
    A.append(a)
dist = [(1,0),(-1,0),(0,1),(0,-1)]
for i in range(H):
    for j in range(W):
        if A[i][j]=='
            cnt =0
            for dx,dy in dist:
                if 0<=i+dx<H and 0<=j+dy<W:
                    if A[i+dx][j+dy]=='
                        cnt +=1
            if cnt ==0: print('No');exit()
print('Yes')

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

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

for i in range(1,h-1):
    for j in range(1,w-1):
        if lis[i][j] == "
            if lis[i-1][j] == "." and lis[i+1][j] == "." and lis[i][j-1] == "." and lis[i][j+1] == ".":
                print("No")
                exit()

print("Yes")

Solution (Python):
def check(ss, r, c):
    for_chk = ((-1, 0), (0, -1), (0, 1), (1, 0))
    H = len(ss)
    W = len(ss[0])
    for ri, ci in for_chk:
        rc = r + ri
        cc = c + ci
        if 0 <= rc and rc < H and 0 <= cc and cc < W:
            if ss[rc][cc] == "
                return True
    return False


def resolve():
    H, W = [int(i) for i in input().split()]
    ss = [list(input()) for _ in range(H)]
    for r in range(H):
        for c in range(W):
            if ss[r][c] == "
                if not check(ss, r, c):
                    print("No")
                    return
    print("Yes")


resolve()

Solution (Python):
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7

H,W = I()
maze = [list(s()) for _ in range(H)]
for i in range(H):
    for j in range(W):
        if maze[i][j] == '
            if i != 0:
                if maze[i-1][j] == '
                    continue
            if j != 0:
                if maze[i][j-1] == '
                    continue
            if i != H-1:
                if maze[i+1][j] == '
                    continue
            if j != W-1:
                if maze[i][j+1] == '
                    continue
            print('No')
            exit()
print('Yes')

Solution (Python):


def solve(h,w,s):
    for i in range(1,h):
        for j in range(1,w):
            if s[i][j] == "
               s[i+1][j] != "
               s[i-1][j] != "
               s[i][j+1] != "
               s[i][j-1] != "
                return "No"
    return "Yes"



def main():
    H,W = map(int,input().split())
    s = ['.'*55]*55
    for i in range(H):
        s[i] = input() + '.'*(55-W)
    print(solve(H,W,s))
    return

if __name__ == '__main__':
    main()

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

if s[0][0] == "
    if s[0][1] == "." and s[1][0] == ".":
        print("No")
        exit()

if s[0][W-1] == "
    if s[0][W-2] == "." and s[1][W-1] == ".":
        print("No")
        exit()

if s[H-1][0] == "
    if s[H-1][1] == "." and s[H-2][0] == ".":
        print("No")
        exit()

if s[H-1][W-1] == "
    if s[H-1][W-2] == "." and s[H-2][W-1] == ".":
        print("No")
        exit()


for i in range(1, W-1):
    if s[0][i] == "
        if s[0][i-1] == "." and s[0][i+1] == "." and s[1][i] ==".":
            print("No")
            exit()
        if s[H-1][i-1] == "." and s[H-1][i+1] == "." and s[H-2][i] ==".":
            print("No")
            exit()

for i in range(1, H-1):
    if s[i][0] == "
        if s[i-1][0] == "." and s[i+1][0] == "." and s[i][1] ==".":
            print("No")
            exit()
        if s[i-1][W-1] == "." and s[i+1][W-1] == "." and s[i][W-2] ==".":
            print("No")
            exit()

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):
H,W=map(int,input().split())
Map=[]
for i in range(H):
  Map.append(input())
for i in range(H):
  for j in range(W):
    if Map[i][j]=='
      if i-1>=0 and i+1<H and j-1>=0 and j+1<W:
        if Map[i-1][j]!='
          print('No')
          exit()
print('Yes')

Solution (Python):
h,w=map(int,input().split())
s=[input() for _ in range(h)]
d=[[0,1],[1,0],[-1,0],[0,-1]]
for i in range(h):
    for j in range(w):
        if s[i][j]==".":
            continue
        ok=False
        for dx,dy in d:
            nx,ny=i+dx,j+dy
            if 0<=nx<h and 0<=ny<w:
                if s[nx][ny]=="
                    ok=True
        if not ok:
            print("No")
            exit()
print("Yes")

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

dp=[[0]*w for i in range(h)]

def dfs(x,y):
    dx=[0,1,0,-1]
    dy=[1,0,-1,0]
    if s[x][y]=="
        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]=="
                dp[x][y]=1
for i in range(h):
    for j in range(w):
        dfs(i,j)
for i in range(h):
    for j in range(w):
        if s[i][j]=="
            print("No")
            sys.exit()
print("Yes")

Solution (Python):
import sys

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))

def main():
    h, w = MI()
    s = []
    for _ in range(h):
        s.append(list(input()))
    for i in range(h):
        for j in range(w):
            flag = False
            if s[i][j] == '.':
                continue
            if i == 0 and j == 0:
                flag |= s[i][j+1] == '
                flag |= s[i+1][j] == '
            elif i == 0 and j == w-1:
                flag |= s[i+1][j] == '
                flag |= s[i][j-1] == '
            elif i == h-1 and j == 0:
                flag |= s[i-1][j] == '
                flag |= s[i][j+1] == '
            elif i == h-1 and j == w-1:
                flag |= s[i-1][j] == '
                flag |= s[i][j-1] == '
            elif i == 0:
                flag |= s[i][j+1] == '
                flag |= s[i+1][j] == '
                flag |= s[i][j-1] == '
            elif i == h-1:
                flag |= s[i-1][j] == '
                flag |= s[i][j+1] == '
                flag |= s[i][j-1] == '
            elif j == 0:
                flag |= s[i-1][j] == '
                flag |= s[i][j+1] == '
                flag |= s[i+1][j] == '
            elif j == w-1:
                flag |= s[i-1][j] == '
                flag |= s[i+1][j] == '
                flag |= s[i][j-1] == '
            else:
                flag |= s[i-1][j] == '
                flag |= s[i][j+1] == '
                flag |= s[i+1][j] == '
                flag |= s[i][j-1] == '
            if not flag:
                print("No")
                sys.exit()
    print("Yes")

if __name__ == '__main__':
    main()

Solution (Python):

 

 
import sys
from fractions import gcd
import math
from math import ceil,floor
import collections
from collections import Counter
import itertools


 







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

S.append(['.']*(W+2))
for _ in range(H):
    S.append(['.']+list(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")
            sys.exit()

print("Yes")

Solution (Python):

 

 
import sys
from fractions import gcd
import math
from math import ceil,floor
import collections
from collections import Counter
import itertools


 







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

S.append(['.']*(W+2))
for _ in range(H):
    S.append(['.']+list(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")
            sys.exit()

print("Yes")

Solution (Python):
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

h,w = nm()
s = []
for y in range(h):
  s.append([_ for _ in input()])

for y in range(h):
  for x in range(w):
    xx = [1,0,-1,0]
    yy = [0,1,0,-1]

    if s[y][x]=='.':
      continue

    ok = False
    for i in range(4):
      nx = x + xx[i]
      ny = y + yy[i]

      if 0 <= nx < w and 0 <= ny < h:
        if s[ny][nx]=='
          ok = True
    if not ok:
      print('No')
      exit()
print('Yes')

Solution (Python):
H, W = map(int, input().split())
dstr = '.' * (W + 2)
b1 = []
b1.append(dstr)
for h in range(H):
  str1 = '.' + input() + '.'
  b1.append(str1)
b1.append(dstr)

for i in range(1, H - 1):
  for j in range(1, W - 1):
    if b1[i][j] == '
      print('No')
      exit()
print('Yes')

Solution (Python):
h,w = map(int,input().rsplit())
s = []
s.append("."*(w+2))
for i in range(h):
	s.append("."+input()+".")
s.append("."*(w+2))
count = 0
ans = 0
for i in range(1,h+1):
	for j in range(1,w+1):
		if s[i][j] == "
			if s[i-1][j] == "
				count+=1
			elif s[i+1][j] == "
				count +=1
			elif s[i][j-1] == "
				count +=1
			elif s[i][j+1] == "
				count +=1
			else:
				ans = 1
				break

if ans == 0:
	print("Yes")
if ans == 1:
	print("No")

Solution (Python):
H,W = map(int,input().split())
figure = [input() for _ in range(H)]
D = [(1,0), (-1, 0), (0,1), (0,-1)]

for h in range(H):
  for w in range(W):
    if figure[h][w] == '
      for dh,dw in D:
        nh, nw = h+dh, w+dw
        if not (0 <= nh <H and 0 <= nw < W):
          continue
        if figure[nh][nw] == '
          break
      else:
        print('No')
        exit()
print('Yes')

Solution (Python):
def solve(S,H,W):
    for i in range(H):
        S[i] = "." + S[i] + "."
    S = ["." * (W+2)] + S + ["." * (W+2)]

    for i in range(1,H+1):
        for j in range(1,W+1):
            if not judge(S,i,j):
                return False

    return True

def judge(S,h,w):
    V = [(-1,0),(1,0),(0,-1),(0,1)]
    if S[h][w] == ".":
        return True
    else:
        for vh,vw in V:
            if S[h+vh][w+vw] == "
                return True
        return False

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

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

if __name__ == "__main__":
    main()

Solution (Python):
h,w = map(int,input().split())
l = [['']*(w+2)]
for i in range(h):
    l.append(['']+list(input())+[''])
l.append(['']*(w+2))
for i in range(1,h+1):
    for j in range(1,w+1):
        if l[i][j] == '
            flag = False
            for k in [(-1,0),(1,0),(0,-1),(0,1)]:
                if l[i + k[0]][j + k[1]] == '
                    flag = True
            if not flag:
                print('No')
                exit()
print('Yes')

Solution (Python):
H, W = map(int, input().split())
S = [""]*H
for i in range(H):
    S[i] = list(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 j > 0:
                if S[i][j-1] == "
                    continue
            if j < W-1:
                if S[i][j+1] == "
                    continue
            if i < H-1 :
                if S[i+1][j] == "
                    continue
                
            print("No")
            exit()

print("Yes")

Solution (Python):
h, w = map(int, input().split())
cambus = [list(input()) for _ in range(h)]
for i in range(h):
    for j in range(w):
        if cambus[i][j] == '
            if i-1 >= 0 and cambus[i-1][j] == '
                continue
            elif j-1 >= 0 and cambus[i][j-1] == '
                continue
            elif i+1 <= h-1 and cambus[i+1][j] == '
                continue
            elif j+1 <= w-1 and cambus[i][j+1] == '
                continue
            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(W):
        if s[i][j] == ".":
            continue
        else:
            check = []
            append = check.append

            if i - 1 >= 0:
                append(s[i - 1][j])
            if i + 1 < H:
                append(s[i + 1][j])
            if j - 1 >= 0:
                append(s[i][j - 1])
            if j + 1 < W:
                append(s[i][j + 1])

            if set(check) == {"."}:
                print("No")
                exit(0)
print("Yes")

Solution (Python):
h,w = map(int,input().split())
grid = []
grid.append(["."]*(w+2))
for i in range(h):
    grid.append(["."]+list(input())+["."])
grid.append(["."]*(w+2))
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 grid[i][j] == "
            ok = False
            for k in range(4):
                if grid[i+dy[k]][j+dx[k]] == "
                    ok = True
            if not ok:
                print("No")
                exit()
print("Yes")

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

def f():
    a = [(-1, 0), (0, -1), (0, 1), (1, 0)]
    for h in range(H):
        for w in range(W):

            if s[h][w] == "
                f = True
                for x, y in a:
                    h2 = h + x
                    w2 = w + y
                    if 0 <= h2 < H and 0 <= w2 < W:
                        if s[h2][w2] == "
                            f = False
                if f:
                    print("No")
                    return
    print("Yes")
    return

f()

Solution (Python):
H, W = map(int, input().split())
G = []
for i in range(H):
    G.append(list(input()))
fd = [[-1, 0], [1, 0], [0, 1], [0, -1]]
for i in range(H-1):
    for j in range(W-1):
        if G[i][j] == '
            boo = False
            for x, y in fd:
                if i+y < 0 or i+y >= H or j+x < 0 or j+y >= W:
                    continue
                if G[i+y][j+x] == '
                    boo = True
            if not boo:
                print('No')
                exit()
print('Yes')