Problem:


Score: 300 points

Problem Statement

We have a canvas divided into a grid with H rows and W columns. The square at the i-th row from the top and the j-th column from the left is represented as (i, j).

Initially, all the squares are white. square1001 wants to draw a picture with black paint. His specific objective is to make Square (i, j) black when s_{i, j}= #, and to make Square (i, j) white when s_{i, j}= ..

However, since he is not a good painter, he can only choose two squares that are horizontally or vertically adjacent and paint those squares black, for some number of times (possibly zero). He may choose squares that are already painted black, in which case the color of those squares remain black.

Determine if square1001 can achieve his objective.  

Constraints

H is an integer between 1 and 50 (inclusive).

W is an integer between 1 and 50 (inclusive).

For every (i, j) (1 \leq i \leq H, 1 \leq j \leq W), s_{i, j} is # or ..

Input

Input is given from Standard Input in the following format:

H W
s_{1, 1} s_{1, 2} s_{1, 3} ... s_{1, W}
s_{2, 1} s_{2, 2} s_{2, 3} ... s_{2, W}
  :   :
s_{H, 1} s_{H, 2} s_{H, 3} ... s_{H, W}

Output

If square1001 can achieve his objective, print Yes; if he cannot, print No.

Sample Input 1

3 3
.#.
###
.#.

Sample Output 1

Yes

One possible way to achieve the objective is shown in the figure below. Here, the squares being painted are marked by stars.

Sample Input 2

5 5
#.#.#
.#.#.
#.#.#
.#.#.
#.#.#

Sample Output 2

No

square1001 cannot achieve his objective here.

Sample Input 3

11 11
...#####...
.##.....##.
#..##.##..#
#..##.##..#
#.........#
#...###...#
.#########.
.#.#.#.#.#.
##.#.#.#.##
..##.#.##..
.##..#..##.

Sample Output 3

Yes



Sample input:
3 3
.#.
###
.#.


Sample output:
Yes

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LS()
    return l
sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    return

#B
def B():
    return

#C
def C():
    return

#D
def D():
    return

#E
def E():
    d = [(1,0),(-1,0),(0,1),(0,-1)]
    h,w = LI()
    s = SR(h)
    for i in range(h):
        for j in range(w):
            if s[i][j] == "#":
                su = 0
                for dy,dx in d:
                    y = i+dy
                    x = j+dx
                    if 0 <= y < h and 0 <= x < w:
                        if s[y][x] == "#":
                            su += 1
                if su == 0:
                    print("No")
                    quit()
    print("Yes")
    return

#F
def F():
    a,b,c,X,Y = LI()
    ans = float("inf")
    for z in range(300001):
        if z%2 == 0:
            m = c*z
            x = z//2
            y = z//2
            m += a*max(0,X-x)
            m += b*max(0,Y-y)
            if m < ans:
                ans = m
    print(ans)
    return

#G
def G():
    n = I()
    x = LI()
    f = [(i,x[i]) for i in range(n)]
    f.sort(key = lambda x:x[1])
    g = [(f[i][0],i) for i in range(n)]
    g.sort(key = lambda x:x[0])
    for i in range(n):
        if g[i][1] < n//2:
            print(f[n//2][1])
        else:
            print(f[n//2-1][1])
    return

#H
def H():
    return

#I
def I_():
    return

#J
def J():
    return

#Solve
if __name__ == "__main__":
    E()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

import math

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

c = []

for i in range(h):
    l = list(input())
    c.append(l)

for i in range(h):
    for j in range(w):
        flg = 0
        if c[i][j] == "#":
            if j != 0:
                if c[i][j-1] == "#":
                    flg = 1
            if j != w-1:
                if c[i][j+1] == "#":
                    flg = 1
            if i != 0:
                if c[i-1][j] == "#":
                    flg = 1
            if i != h-1:
                if c[i+1][j] == "#":
                    flg = 1
            if flg == 0:
                print('No')
                exit()
print('Yes')

Submission status: Accepted

Solution code:
import numpy as np
h, w = map(int, input().split())
square = np.array([list(input()) for i in range(h)]).ravel()=="#"
def main():
    for i in range(h*w):
        if square[i] == True:
            flag = 0
            if i // w == 0:
                if square[i+w] == True:
                    flag += 1
            elif i // w == h-1:
                if square[i-w] == True:
                    flag += 1
            else:
                if square[i+w] + square[i-w] == True:
                    flag += 1
            if i % w == 0:
                if square[i+1] == True:
                    flag += 1
            elif i % w == w-1:
                if square[i-1] == True:
                    flag += 1
            else:
                if square[i+1] + square[i-1] == True:
                    flag += 1
            if flag == 0:
                print("No")
                return 0
    print("Yes")
main()

Submission status: Accepted

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

def check(i,j):
    if S[i][j] == ".":
        return 0

    if i==0:
        if S[i+1][j] == "#":
            return 0
    elif i==H-1:
        if S[i-1][j] == "#":
            return 0
    else:
        if S[i+1][j] == "#" or S[i-1][j] == "#":
            return 0

    if j==0:
        if S[i][j+1] == "#":
            return 0
    elif j==W-1:
        if S[i][j-1] == "#":
            return 0
    else:
        if S[i][j+1] == "#" or S[i][j-1] == "#":
            return 0

    return 1

if sum([check(i,j) for i in range(H) for j in range(W)]) == 0:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
height,width=map(int,input().split())
graph = [[s for s in input()] for i in range(height)]

for r in range(height):
    for c in range(width):
        if graph[r][c]==".":
            continue

        if r>0 and graph[r-1][c]=="#":
            continue

        if r<width-1 and graph[r+1][c]=="#":
            continue

        if c>0 and graph[r][c-1]=="#":
            continue

        if c<height-1 and graph[r][c+1]=="#":
            continue

        print("No")
        exit()
print("Yes")

Submission status: Accepted

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

def x_p(x,y):
    if x == H-1:
        return 0
    x += 1
    return ([x,y] in l)

def x_m(x,y):
    if x == 0:
        return 0
    x -= 1
    return ([x,y] in l)

def y_p(x,y):
    if y == W-1:
        return 0
    y += 1
    return ([x,y] in l)

def y_m(x,y):
    if y == 0:
        return 0
    y -= 1
    return ([x,y] in l)

H,W = [int(i) for i in input().split()]
l = []
for i in range(H):
    A = list(input())
    for j in range(W):
        if A[j] == "#":
            l.append([i,j])

for i in l:
    flag = 0
    x,y = i
    if x_p(x,y) == True or x_m(x,y) == True or y_p(x,y) == True or y_m(x,y) == True:
        flag = 1
    if flag == 0:
        print('No')
        exit()
print('Yes')

Submission status: Accepted

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

#独立した黒マスがあるか？
flag = True

for i in range(H):
    for j in range(W):
        f2 = False
        if s[i][j] == '#' :
            if i-1 >= 0 and s[i-1][j] == '#' :
                f2 = True
            if j-1 >= 0 and s[i][j-1] == '#' :
                f2 = True
            if i+1 < H and s[i+1][j] == '#' :
                f2 = True
            if j+1 < W and s[i][j+1] == '#' :
                f2 = True
            if not(f2):
                flag = False
                break
    else:
        continue
    break


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

Submission status: Accepted

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

ds = ((0, 1), (1, 0), (0, -1), (-1, 0))

def move(p, d):
	n = (p[0] + d[0], p[1] + d[1])
	if (0 <= n[0] < H) and (0 <= n[1] < W):
		return n
	return None

def getv(p):
	return STAGE[p[0]][p[1]]

for y in range(H):
	for x in range(W):
		if "#" == STAGE[y][x]:
			for d in ds:
				n = move((y, x), d)
				if n and "#" == getv(n):
					break
			else:
				print("No")
				exit()
print("Yes")

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
grid = [['.' for j in range(w + 2)]for i in range(h + 2)]
for i in range(h):
    line = list(input())
    grid[i + 1][1:w + 1] = line
direction =[[0, 1], [1, 0], [0, -1], [-1, 0]]
for i, line in enumerate(grid[1:h + 1][1:w + 1]):
    for j, dot in enumerate(line):
        if grid[i][j] == '.':
            continue
        for dire in direction:
            x = i + dire[0]
            y = j + dire[1]
            if grid[x][y] == '#':
                break
        else:
            print('No')
            exit()
else:
    print('Yes')

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
s = []
for i in range(H):
  s.append(input())
  
for i in range(H):
  for j in range(W):
    if s[i][j] == "#":
      flag = False
      for x, y in [[1, 0],[-1, 0],[0, 1],[0, -1]]:
        if i + x >= 0 and i + x <= H - 1 and j + y >= 0 and j + y <= W - 1 and s[i + x][j + y] == '#':
          flag = True
      if not flag:
        print('No')
        exit(0)
print('Yes')

Submission status: Accepted

Solution code:
import itertools

H, W = map(int, input().split())
s = []
for i in range(H):
  s.append(input())
  
for i in range(H):
  for j in range(W):
    if s[i][j] == "#":
      flag = False
      for x, y in [[1, 0],[-1, 0],[0, 1],[0, -1]]:
        if i + x >= 0 and i + x <= H - 1 and j + y >= 0 and j + y <= W - 1 and s[i + x][j + y] == '#':
          flag = True
      if not flag:
        print('No')
        exit(0)
print('Yes')

Submission status: Accepted

Solution code:
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    h,w = f()
    ss = [input() for i in range(h)]
    for i in range(h):
        for j in range(w):
            if ss[i][j] == '.':
                continue
            if i-1>=0 and ss[i-1][j]=='#':
                continue
            if i+1<h and ss[i+1][j] == '#':
                continue
            if j-1>=0 and ss[i][j-1]=='#':
                continue
            if j+1<w and ss[i][j+1]=='#':
                continue
            print('No')
            return
    
    print('Yes')

solve()

Submission status: Accepted

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

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

x = [0, -1, 0, 1]
y = [-1, 0, 1, 0]

for i in range(1, H + 1):
    for j in range(1, W + 1):
        check = False
        if s[i][j] == '#':
            for xx, yy in zip(x, y):
                if s[i + xx][j + yy] == '#':
                    check = True
            if not check:
                print("No")
                exit()

print("Yes")

Submission status: Accepted

Solution code:

def check(i, j, high, width, data):
    pre_j = max(0, j - 1)
    aft_j = min(width - 1, j + 1)
    pre_i = max(0, i - 1)
    aft_i = min(high - 1, i + 1)

    if pre_i != i:
        if data[pre_i][j] == '#':
            return 1
    if aft_i != i:
        if data[aft_i][j] == '#':
            return 1
    if pre_j != j:
        if data[i][pre_j] == '#':
            return 1
    if aft_j != j:
        if data[i][aft_j] == '#':
            return 1
    # print(i, j)
    return 0


def main():
    high, width = map(int, input().split())
    data = [list(input()) for i in range(high)]

    # for i in range(high):
    #     print(data[i])

    for i in range(high):
        for j in range(width):
            if data[i][j] == '#':
                if check(i, j, high, width, data) == 0:
                    print('No')
                    return

    print('Yes')



if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
from collections.abc import Iterable
from math import *
from itertools import *
from collections import *
from functools import *
from operator import *
try:
    from math import gcd
except Exception:
    from fractions import gcd

YES = "Yes"  # type: str
NO = "No"  # type: str

def solve(H: int, W: int, s: "List[str]"):
    m = [[0] * W for _ in range(H)]
    for j in range(H):
        for i in range(W):
            if s[j][i] == '#':
                if j < (H - 1) and s[j+1][i] == '#':
                    m[j][i] += 1
                    m[j+1][i] += 1
                if i < (W - 1) and s[j][i+1] == '#':
                    m[j][i] += 1
                    m[j][i+1] += 1
                if m[j][i] == 0:
                    return NO
    return YES


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    s = [ next(tokens) for _ in range(H)]  # type: "List[str]"
    result = solve(H, W, s)
    if isinstance(result, Iterable) and not isinstance(result, str):
        result = '\n'.join([str(v) for v in result])
    print(result)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

ans = "Yes"
dx = [-1, 0, 1, 0]
dy = [ 0, 1, 0,-1]

for i in range(1, h+1):
	for j in range(1, w+1):
		if s[i][j] == "#":
			CanPaint = False
			for k in range(4):
				if s[i+dx[k]][j+dy[k]] == "#":
					CanPaint = True
			if not CanPaint:
				ans = "No"

print(ans)

Submission status: Accepted

Solution code:
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] == '#':
            a = S[max(0,i-1)][j] == '#'
            b = S[i][max(0,j-1)] == '#'
            c = S[i][min(W-1,j+1)] == '#'
            d = S[min(H-1,i+1)][j] == '#'
            if any([a,b,c,d]):
                continue
            else:
                ans = 'No'
                break
print(ans)

Submission status: Accepted

Solution code:
H,W=map(int,input().split()) # H=縦（行）、W=横（列）
L=[ input() for i in range(H)]

def DFS():
  cond = True
  for i in range(H):
    for j in range(W):
      if L[i][j] != '#':
        #print('continue')
        continue
      IND=[(i,j-1), (i,j+1), (i-1,j), (i+1,j)]
      #print(IND)
      conds = []
      for (y, x) in IND:
        if x < 0 or y < 0 or x >= W or y >= H:
          conds.append('.')
        elif L[y][x] == '.':
          conds.append('.')
        else:
          #print(L[y][x], (y,x))
          conds.append('#')
      #print(conds, (i,j))
      if conds.count('#') == 0:
        return 'No'
  return 'Yes'

print(DFS())

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
l1="."*(m+2)
l2="."+input()+"."
b=True
for i in range(n-1):
  l3="."+input()+"."
  for j in range(1,1+m):
    if l2[j]=="#" and (l2[j-1]=="." and l2[j+1]=="." and l1[j]=="." and l3[j]=="."):
      b=False
      break
  l1,l2=l2,l3
l3=="."*(m+2)
for j in range(m):
    if l2[j]=="#" and (l2[j-1]=="." and l2[j+1]=="." and l1[j]=="." and l3[j]=="."):
      b=False
      break
if b:
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
def tonari(h,w):
    kuro = False
    if h != 0:
        if S[h-1][w] == '#':
            kuro = True
    if h != H-1:
        if S[h+1][w] == '#':
            kuro = True
    if w != 0:
        if S[h][w-1] == '#':
            kuro = True
    if w != W-1:
        if S[h][w+1] == '#':
            kuro = True
    if kuro == False:
        print('No')
        exit()

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

for h in range(H):
    for w in range(W):
        if S[h][w] == '#':
            tonari(h,w)

print('Yes')

Submission status: Accepted

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

flag = True
for i in range(h):
    for j in range(w):
        if s[i][j] == '#':
            neighbors = []
            if i != 0:
                neighbors.append([i-1, j])
            if i != h-1:
                neighbors.append([i+1, j])
            if j != 0:
                neighbors.append([i, j-1])
            if j != w-1:
                neighbors.append([i, j+1])
            neighbors_colors = []
            for n in neighbors:
                neighbors_colors.append(s[n[0]][n[1]])
            if '#' not in neighbors_colors:
                flag = False
if flag:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
tmp = (input().split(" "))
H = int(tmp[0])
W = int(tmp[1])

datas = [input() for i in range(0, H, 1)]

array = []

cnt1 = 0
cnt2 = 0

for data in datas:
  tmp = [x for x in list(data)]
  array.append(tmp)

for i in range(0, H, 1):
  
  a1=0
  a2=0
  a3=0
  a4=0
  
  for j in range(0, W, 1):
    
    if array[i][j] == "#":

      cnt1 += 1
      
      try:
        if array[i][j-1] == "#":
          a1 = 1
        else:
          a1 = 0
      except:
        a1 = 0
        
      try:
        if array[i][j+1] == "#":
          a2 = 1
        else:
          a2 = 0
      except:
        a2 = 0
        
      try:
        if array[i-1][j] == "#":
          a3 = 1
        else:
          a3 = 0
      except:
        a3 = 0
        
      try:
        if array[i+1][j] == "#":
          a4 = 1
        else:
          a4 = 0
      except:
        a4 = 0
        
      if (a1 + a2 + a3 + a4) > 0:
        cnt2 += 1
     
    else:
      continue

if cnt1 == cnt2:
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
import numpy as np

h, w = map(int,input().split())
hw = [input() for i in range(h)]

isPaintable = [[1]*w for _ in range(h)]

predList = [[0,1],[0,-1],[1,0],[-1,0]]

for i in range(h):
  for j in range(w):
    if hw[i][j] == "#":
      for x, y in predList:
        if i+y in range(h) and j+x in range(w):
#          print(hw[i][j],hw[i+y][j+x],i,j,y,x)
          if hw[i+y][j+x]=="#":
            isPaintable[i][j] = 0
            break
    elif hw[i][j] == ".":
      isPaintable[i][j] = 0

if np.array(isPaintable).sum() == 0:
  print("Yes")
else:
  print("No")

Submission status: Accepted

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

H, W = map(int, input().split())
L = [list(input().strip()) for _ in range(H)]
NL = [["."] * W for _ in range(H)]

for i in range(H):
    for j in range(W):
        if j < W - 1 and L[i][j] == "#" and L[i][j + 1] == "#":
            NL[i][j] = "#"
            NL[i][j + 1] = "#"
        if i > 0:
            if L[i][j] == "#" and L[i - 1][j] == "#":
                NL[i][j] = "#"
                NL[i - 1][j] = "#"
            
print("Yes" if L == NL else "No")

Submission status: Accepted

Solution code:


def read_input():
    h, w = map(int, input().split())
    board = []

    for i in range(h):
        s = [c for c in input().strip()]
        board.append(s)

    return h, w, board


# マス(i, j)の上下左右のいずれかに黒が居るかどうか調べる
def check_neighbor(board, i, j):
    if i - 1 >= 0:
        if board[i - 1][j] == '#':
            return True
    if i + 1 < len(board):
        if board[i + 1][j] == '#':
            return True

    if j - 1 >= 0:
        if board[i][j - 1] == '#':
            return True
    if j + 1 < len(board[i]):
        if board[i][j + 1] == '#':
            return True
    return False


def submit():
    h, w, board = read_input()

    for i in range(h):
        for j in range(w):
            if board[i][j] == '#' and not check_neighbor(board, i, j):
                print('No')
                return

    print('Yes')


if __name__ == '__main__':
    submit()

Submission status: Accepted

Solution code:
H,W = map(int,input().split(" "))
s = []
s.append('.'*(W+2))
for i in range(H):
    s.append('.'+input()+'.')
s.append('.'*(W+2))
H+=1
W+=1
for h in range(H):
    for w in range(W):
        g = s[h][w]
        if g == ".":
            continue
        if '#' in [s[h-1][w],s[h+1][w],s[h][w-1],s[h][w+1]]:
            continue
        print("No")
        exit()

print("Yes")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def solve(field):
  for i in range(1, h + 1):
    for j in range(1, w + 1):
      if field[i][j] == '.':
        continue
        #それ以後の処理がスキップされ、次のループに。つまり#の場合のみ次に進める。
      if field[i-1][j] == field[i][j-1] == field[i][j+1] == field[i+1][j] == '.':
      #上下左右に黒がない場合（全部白の場合）、黒色にできない（隣も塗らざるを得ないから）。
      #また黒色にできないのはその場合に限る（1つ以上あれば――ダブってても白には戻らないため――べたべた塗ればよい）
        return False
  return True
#インデント注意。任意の#のfieldに対してFalse返らなかったらTrueということなので、最初の条件節を出る（同じインデントかそれより前）。
h, w = list(map(int, input().split()))
field = ['.' + input() + '.' for _ in range(h)]
#左右の端についてもsolve(field)を適用するため、入力に左右を付け加える
field = ['.'*(w+2)] + field + ['.'*(w+2)]
#上下の端についても同様の処理。fieldは例えば['.....', '..#..', '.###.', '..#..', '.....']となる。
#これのi番目のリストのj項が、field[i][j]によって指示される。

print('Yes' if solve(field) else 'No')
#solve(field)だけで、Trueが返ってくるということを意味する。

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
s = ['.' * (w+2)]
for i in range(h):
    s.append('.' + input() + '.')
s.append('.' * (w+2))
from itertools import product
for y, x in product(range(1, h + 1), range(1, w + 1)):
    if s[y][x] == '#':
        if True in [s[y + i][x + j] == '#' for i, j in [(0, -1), (0, 1), (-1, 0), (1, 0)]]:
            continue
        print('No')
        import sys
        sys.exit()
print('Yes')

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
s = []
for i in range(-1, H+1):
	if i < 0 or i >= H:
		tmp = ["."] * (W + 1)
	else:
		tmp = ["."]
		for t in input():
			tmp.append(t)
	tmp.append(".")
	s.append(tmp)


for h in range(1, H+1):
	judge = True
	for w in range(1, W+1):
		if s[h][w] != "#":
			continue
		judge = False
		if s[h+1][w] == "#":
			judge = True
		if s[h-1][w] == "#":
			judge = True
		if s[h][w+1] == "#":
			judge = True
		if s[h][w-1] == "#":
			judge = True
		if not judge:
			break
	if not judge:
		break

ret = 'Yes' if judge else 'No'
print(ret)

Submission status: Accepted

Solution code:

BLACK = '#'
WHITE = '.'

def can_paint(arr, H, W, i, j):
    if (i > 0 and arr[i-1][j] == BLACK):
        return True
    elif (i < H - 1 and arr[i+1][j] == BLACK):
        return True
    elif (j > 0 and arr[i][j-1] == BLACK):
        return True
    elif (j < W - 1 and arr[i][j+1] == BLACK):
        return True
    else:
        return False

def solve():
    # Get Input
    H, W = [int(_) for _ in raw_input().split()]
    arr = []
    for i in range(H):
        row = raw_input() # in str type
        arr.append(row)
    # Solve
    for i in range(H):
        for j in range(W):
            if arr[i][j] == BLACK and not can_paint(arr, H, W, i, j):
                return False
    return True

if __name__ == '__main__':
    ret = solve()
    if ret:
        print 'Yes'
    else:
        print 'No'

Submission status: Accepted

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


def can_paint():
    for i in range(h):
        for j in range(w):
            if s[i][j] == '.':
                continue

            ns = []
            if i != 0:
                ns.append(s[i-1][j])
            if i != h-1:
                ns.append(s[i+1][j])
            if j != 0:
                ns.append(s[i][j-1])
            if j != w-1:
                ns.append(s[i][j+1])

            if ns.count('#') == 0:
                return False

    return True


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

Submission status: Accepted

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

c = 0
b = 0

def sirabe(t,i,j):
    if t[i-1][j] != "#" and t[i][j-1] != "#" and t[i+1][j] != "#" and t[i][j+1] != "#":
        return False
    else:
        return True


for i in range(1,h+1):
    for j in range(1,w+1):
        if s[i][j] == "#":
            if sirabe(s,i,j):
                continue
            else:
                c = 1
                break
    if c == 1:
        break


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

Submission status: Accepted

Solution code:
import  numpy as np
h,w=map(int,input().split())
s = [[0]*(w+2)]
for i in range(h):
    s.append([0]+list(input())+[0])
s.append([0]*(w+2))

t = np.array(s)
c = 0
b = 0

def sirabe(t,i,j):
    if t[i-1][j] != "#" and t[i][j-1] != "#" and t[i+1][j] != "#" and t[i][j+1] != "#":
        return False
    else:
        return True


for i in range(1,h+1):
    for j in range(1,w+1):
        if t[i][j] == "#":
            if sirabe(t,i,j):
                continue
            else:
                c = 1
                break
    if c == 1:
        break


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

Submission status: Accepted

Solution code:
import itertools
H,W = map(int,input().split())
mas = [input() for _ in range(H)]
ans = 0
for i, j in itertools.product(range(H), range(W)):
    if mas[i][j] == '.':
        pass
    else :
        if i == 0 : # top row
            if j == W - 1 : # right edge
                if mas[i][j-1] == '.' and mas[i][j+1] == '.' :
                    print('No')
                    #print(1)
                    ans = 1
                    break
            elif j == 0 : # left edge
                if mas[i+1][j] == '.' and mas[i][j+1] == '.' :
                    print('No')
                    #print(2)
                    ans = 1
                    break
            else :
                if mas[i][j - 1] == '.' and mas[i + 1][j] == '.' and mas[i][j + 1] == '.':
                    print('No')
                    #print(3)
                    ans = 1
                    break
        elif i == H - 1 : # bottom row
            if j == W - 1 : # right edge
                if mas[i-1][j] == '.' and mas[i][j-1] == '.' :
                    print('No')
                    #print(4)
                    ans = 1
                    break
            elif j == 0 : # left edge
                if mas[i-1][j] == '.' and mas[i][j-1] == '.' :
                    print('No')
                    #print(6)
                    ans = 1
                    break
            else :
                if mas[i-1][j] == '.' and mas[i][j + 1] == '.' and mas[i][j - 1] == '.':
                    print('No')
                    #print(5)
                    ans = 1
                    break
        else : # middle row
            if j == W - 1 : # right edge
                if mas[i-1][j] == '.' and mas[i][j-1] == '.' and mas[i+1][j] == '.' :
                    print('No')
                    #print(7)
                    ans = 1
                    break
            elif j == 0 : # left edge
                if mas[i+1][j] == '.' and mas[i][j-1] == '.' and mas[i][j+1] == '.' :
                    print('No')
                    #print(8)
                    ans = 1
                    break
            else :
                if mas[i-1][j] == '.' and mas[i + 1][j] == '.' and mas[i][j - 1] == '.' and mas[i][j + 1] == '.':
                    print('No')
                    #print(9)
                    ans = 1
                    break
if ans == 0 :
    print('Yes')

Submission status: Accepted

Solution code:
h,w = map(int,input().split())
m = [list(str(input())) for i in range(h)]
for i in range(h):
    for j in range(w):
        if m[i][j] == "#":
            if i == 1:
                if j == 0:
                    obj = [m[i][j+1],m[i+1][j]]
                elif j == w - 1:
                    obj = [m[i][j-1],m[i+1][j]]
                else:
                    obj = [m[i][j-1],m[i][j+1],m[i+1][j]]
            elif i == h - 1:
                if j == 0:
                    obj = [m[i-1][j],m[i][j+1]]
                elif j == w - 1:
                    obj = [m[i-1][j],m[i][j-1]]
                else:
                    obj = [m[i-1][j],m[i][j-1],m[i][j+1]]
            else:
                if j == 0:
                    obj = [m[i-1][j],m[i][j+1],m[i+1][j]]
                elif j == w - 1:
                    obj = [m[i-1][j],m[i][j-1],m[i+1][j]]
                else:
                    obj = [m[i-1][j],m[i][j-1],m[i][j+1],m[i+1][j]]
            
            if "#" not in obj:
                print("No")
                exit()
print("Yes")

Submission status: Accepted

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

f1 = True
for i in range(H):
  if not f1:
    break
  for j in range(W):
    if not f1:
      break
    if s[i][j] == '.':
      continue
    f = False
    if i >= 1 and s[i-1][j] == '#':
      f = True
    if j <= W-2 and s[i][j+1] == '#':
      f = True
    if i <= H-2 and s[i+1][j] == '#':
      f = True
    if j >= 1 and s[i][j-1] == '#':
      f = True
    if not f:
      f1 = False

#print(s)
if f1:
  print('Yes')
else:
  print('No')

Submission status: Accepted

Solution code:
H,W=map(int,input().split())
S=[]
for i in range(H):
    s=input()
    S.append(s)
for i in range(H):
    for j in range(W):
        if S[i][j]==".":
            continue
        l=[(j-1,i),(j+1,i),(j,i+1),(j,i-1)]
        koritu=True
        for x,y in l:
            if 0<=y<=H-1 and  0<=x<=W-1:
                koritu=koritu and S[y][x]=="."
        if koritu:
            print("No")
            quit()
print("Yes")