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:
def main():
    H,W = list(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] == ".":
                continue
            elif i==0:
                if j==0:
                    if s[i+1][j]=="." and s[i][j+1]==".":
                        return "No"
                elif j==W-1:
                    if s[i+1][j]=="." and s[i][j-1]==".":
                        return "No"
                else:
                    if s[i][j+1]=="." and s[i+1][j]=="." and s[i][j-1]==".":
                        return "No"
            elif i==H-1:
                if j==0:
                    if s[i-1][j]=="." and s[i][j+1]==".":
                        return "No"
                elif j==W-1:
                    if s[i-1][j]=="." and s[i][j-1]==".":
                        return "No"
                else:
                    if s[i-1][j]=="." and s[i][j-1]=="." and s[i][j+1]==".":
                        return "No"
            elif j==0:
                if s[i+1][j]=="." and s[i-1][j]=="." and s[i][j+1]==".":
                    return "No"
            elif j==W-1:
                if s[i+1][j]=="." and s[i-1][j]=="." and s[i][j-1]==".":
                    return "No"
            else:
                if s[i+1][j]=="." and s[i-1][j]=="." and s[i][j-1]=="." and s[i][j+1]==".":
                    return "No"
    return "Yes"

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

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
A = []
for i in range(H):
    B = input()
    C = []
    for j in B:
        C.append(j)
    A.append(C)

flag = 0
for k in range(H):
    if flag == 1:
        break
    for l in range(W):
        if A[k][l] == "#":
            if A[max(0, k-1)][l] == A[k][max(0, l-1)] == A[min(H-1, k+1)][l] == A[k][min(W-1, l+1)] == ".":
                flag = 1
                break

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

Submission status: Accepted

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

for x in range(h):
  for y in range(w):
    if s[x][y] == '#':
      counter = 0
      direction = 4
      t = [-1, 1, 0, 0, 0, 0, -1, 1]
      for i in range(4):
        try:
          counter += (s[x+t[i]][y+t[i+4]] != '#')
        except:
          direction -= 1
      if counter == direction:
        print('No')
        exit(0)
print('Yes')

Submission status: Accepted

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

result = True

def check(i, j):
  if board[i][j] == '.':
    return True
  
  if i == 0:
    if j == 0:
      if board[i][j + 1] == '.' and board[i + 1][j] == '.':
        return False
    elif j == w - 1:
      if board[i][j - 1] == '.' and board[i + 1][j] == '.':
        return False
    else:
      if board[i][j - 1] == '.' and board[i][j + 1] == '.' and board[i + 1][j] == '.':
        return False
  elif i == h - 1:
    if j == 0:
      if board[i][j + 1] == '.' and board[i - 1][j] == '.':
        return False
    elif j == w - 1:
      if board[i][j - 1] == '.' and board[i - 1][j] == '.':
        return False
    else:
      if board[i][j - 1] == '.' and board[i][j + 1] == '.' and board[i - 1][j] == '.':
        return False
  else:
    if j == 0:
      if board[i][j + 1] == '.' and board[i - 1][j] == '.' and board[i + 1][j] == '.':
        return False
    elif j == w - 1:
      if board[i][j - 1] == '.' and board[i - 1][j] == '.' and board[i + 1][j] == '.':
        return False
    else:
      if board[i][j - 1] == '.' and board[i][j + 1] == '.' and board[i - 1][j] == '.' and board[i + 1][j] == '.':
        return False

  return True

for i in range(h):
  for j in range(w):
    result = check(i, j)
    if not result:
      break
  if not result:
    break

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

Submission status: Accepted

Solution code:
# https://abc096.contest.atcoder.jp/tasks/abc096_c

neighbor_i = [-1, 0, 1, 0]
neighbor_j = [0, -1, 0, 1]

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


def can_draw(l, target_i, target_j):
    for i, j in zip(neighbor_i, neighbor_j):
        if target_i + i < 0 or target_j < 0:
            continue
        if target_i + i >= H or target_j + j >= W:
            continue
        if l[target_i + i][target_j + j] == '#':
            return True

    return False


data = []
for i in range(H):
    raw = list(str(input()))
    data.append(raw)


# print(data)


ok = True
for i in range(H):
    for j in range(W):
        if data[i][j] == '#':
            if not can_draw(data, i, j):
                ok = False
                break
    if not ok:
        break

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

Submission status: Accepted

Solution code:
import sys

h, w=(int(word) for word in input().split())
canvas=[["." for wi in range(w+2)] for hi in range(h+2)]
for hi in range(h):
    l=input()
    for wi in range(w):
        canvas[hi+1][wi+1]=l[wi]
ds=[(-1, 0), (1, 0), (0, -1), (0, 1)]
for hi in range(1, h+1):
    for wi in range(1, w+1):
        if canvas[hi][wi]==".": continue
        conts=False
        for d in ds:
            if canvas[hi+d[0]][wi+d[1]]=="#":
                conts=True
                break
        if not conts:
            print("No")
            sys.exit()
print("Yes")

Submission status: Accepted

Solution code:
h,w = map(int,raw_input().split())
s = []
a = True
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 - 1 >= 0 and s[i-1][j] == '#':
                continue
            if i + 1 < h and s[i+1][j] == "#":
                continue
            if j - 1 >= 0 and s[i][j-1] == '#':
                continue
            if j + 1 < w and s[i][j+1] == '#':
                continue
            a = False
if a == True:
    print 'Yes'
else:
    print 'No'

Submission status: Accepted

Solution code:
def iter_neighbor_indices(y, x, H, W):
    # up
    if y != 0:
        yield (y - 1, x)
    # bottom
    if y != H - 1:
        yield (y + 1, x)
    # left
    if x != 0:
        yield (y, x - 1)
    # right
    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)]
    # H, W = 3, 3
    # color_grid = [list('.#.'), list('###'), list('.#.')]

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

                # search '#' on neighbors
                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")

Submission status: Accepted

Solution code:
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")

Submission status: Accepted

Solution code:
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] == '#' and not search(j+1, i+1):
            print('No')
            quit()
print('Yes')

Submission status: Accepted

Solution code:
# coding: utf-8

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)

Submission status: Accepted

Solution code:
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())

Submission status: Accepted

Solution code:
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] == '#' and not isok(field, x, y):
      print 'No'
      exit()
print 'Yes'

Submission status: Accepted

Solution code:
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] == '#' and isolated(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')

Submission status: Accepted

Solution code:
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")

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

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

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")

Submission status: Accepted

Solution code:
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)]#aim[h+2][w+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")

Submission status: Accepted

Solution code:
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')

Submission status: Accepted

Solution code:
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
        #ue
        if i > 0 and s[i-1][j] == '#':
            continue
        #shita
        if i < h-1 and s[i+1][j] == '#':
            continue
        #hidari
        if j > 0 and s[i][j-1] == '#':
            continue
        #migi
        if j < w-1 and s[i][j+1] == '#':
            continue
        flag = True
        break

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

Submission status: Accepted

Solution code:
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")

Submission status: Accepted

Solution code:
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
        #up
        if j>0 and M[j-1][i]=='#':
            continue
        #down
        if j<H-1 and M[j+1][i]=='#':
            continue
        #left
        if i>0 and M[j][i-1]=='#':
            continue
        #right
        if i<W-1 and M[j][i+1]=='#':
            continue
        print('No')
        exit()
print('Yes')

Submission status: Accepted

Solution code:
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] == '#' or \
        i-1 >= 0 and m[i-1][j] == '#' or \
        j+1 < w and m[i][j+1] == '#' or \
        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')

Submission status: Accepted

Solution code:
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]=='#' and f==0:
      s=1 
if s==1:
  print('No')
else:
  print('Yes')

Submission status: Accepted

Solution code:
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')

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] == "#":
            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)

Submission status: Accepted

Solution code:
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')

Submission status: Accepted

Solution code:
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')

Submission status: Accepted

Solution code:
# n = int(input())

# k = [int(i) for i in input().split()]
# a,b,c = (int(i) for i in input().split()) 
# cnt = 0
# for i in range(n):
#   sum = 0
#   for j in range(i,n):
#     sum+=a[j]
#     if sum==0:
#       cnt+=1
# print(cnt)
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()

Submission status: Accepted

Solution code:
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] == "#":key = 1
            except:
                key = 0
            if key == 0:
                try:
                    if lis[k][h-1] == "#":key = 1
                except:
                    key = 0
                if key == 0:
                    try:
                        if lis[k+1][h] == "#":key = 1
                    except:
                        key = 0
                    if key == 0:
                        try:
                            if lis[k-1][h] == "#":key = 1
                        except:
                            key = 0
                        if key == 0:
                            print("No")
                            exit()
print("Yes")

Submission status: Accepted

Solution code:
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')

Submission status: Accepted

Solution code:
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")

Submission status: Accepted

Solution code:
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):
        #上からi行目、左からk列目を見てる
        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")

Submission status: Accepted

Solution code:
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)])

Submission status: Accepted

Solution code:
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] == "#" and
                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")

Submission status: Accepted

Solution code:
#■標準入力ショートカット


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()

Submission status: Accepted

Solution code:
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] == "#": b+=1
            if S[h][w+1] == "#": b+=1
            if S[h-1][w] == "#": b+=1
            if S[h+1][w] == "#": b+=1
            if b==0:
                isok = False
                break
    if not isok: break

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

Submission status: Accepted

Solution code:
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')

Submission status: Accepted

Solution code:
# your code goes here
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')

Submission status: Accepted

Solution code:
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")

Submission status: Accepted

Solution code:
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"