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: Runtime Error

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

result = True
masu = [[0 for i in range(H+2)] for j in range(W+2)]
for h in range(1, H+1):
    s = "0"+input()+"0"
    masu[h] = list(s)

# print(masu)    

for h in range(H+1):
    for w in range(W+1):
        if masu[h][w] == "#":
            if (masu[h][w] == masu[h+1][w]) or (masu[h][w] == masu[h][w+1]) or (masu[h][w] == masu[h-1][w]) or (masu[h][w] == masu[h][w-1]):
                pass
            else:
                result = False

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

Submission status: Runtime Error

Solution code:
H, W = map(int, input().split(' '))
matrix = []
for _ in range(W):
    tmp = [0 if j == '.' else 1 for j in input()]
    matrix.append(tmp)

flag = 'Yes'
for i, row in enumerate(matrix):
    for j, s in enumerate(row):
        if s == 1:
            if (j > 0 and row[j-1] == 0) and (j < W - 1 and row[j+1] == 0):
                if (i > 0 and matrix[i-1][j] == 0) and (i < H - 1 and matrix[i+1][j] == 0):
                    flag = 'No'
        if flag == 'No':
            break

print(flag)

Submission status: Runtime Error

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

result = True
masu = [[0 for i in range(H+2)] for j in range(W+2)]
for h in range(1, H+1):
    s = "0"+input()+"0"
    masu[h] = list(s)

print(masu)    

for h in range(H+2):
    for w in range(W+2):
        if masu[h][w] == "#":
            if (masu[h][w] == masu[h+1][w]) or (masu[h][w] == masu[h][w+1]) or (masu[h][w] == masu[h-1][w]) or (masu[h][w] == masu[h][w-1]):
                pass
            else:
                result = False

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

Submission status: Runtime Error

Solution code:
h, w = map(int,input().split())
pic = []

kabe_up_down = []
for i in range(w):
    kabe_up_down.append('.')

pic.append(kabe_up_down)
for i in range(h):
    onelist = ['.']
    inp = list(str(input()))
    for i in range(len(inp)):
        onelist.append(inp[i])
    onelist.append('.')
    pic.append(onelist)
pic.append(kabe_up_down)    
flag = 1
a = 'a'
for i in range(1,h+1):
    for j in range(1,w+1):
        here = pic[i][j]
        if here =='#' and pic[i+1][j] == '#':
            pic[i][j] = a
            pic[i+1][j] = a
        elif here =='#' and pic[i][j+1] == '#':
            pic[i][j] = a
            pic[i][j+1] = a
            
for i in range(h+1):
    for j in range(w+1):
        if pic[i][j] == '#':
            flag = 0
            break
        
if flag == 0:
    print('No')
else:
    print('Yes')

Submission status: Runtime Error

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

H, W = map(int, input().split(' '))
matrix = []
for _ in range(W):
    tmp = [0 if j == '.' else 1 for j in input()]
    matrix.append(tmp)

for i, row in enumerate(matrix):
    for j, s in enumerate(row):
        flag = True
        if s == 1:
            if (j > 0 and row[j-1] == 0) and (j < W - 1 and row[j+1] == 0):
                if (i > 0 and matrix[i-1][j] == 0) and (i < H - 1 and matrix[i+1][j] == 0):
                    print('No')
                    exit(0)

print('Yes')

Submission status: Runtime Error

Solution code:
H,W=map(int,input().split())
S=[input() for i in range(H)]
ans="No"
for i in range(H):
    for j in range(W):
        if S[i][j]=='#':
            if i>0 and S[i-1][j]=='#':
                ans="Yes"
            if i<H-1 and S[i+1][j]=='#':
                ans="Yes"
            if j>0 and S[i][j-1]=='#':
                ans="Yes"
            if j<W-1 and S[i][j+1]='#':
                ans="Yes"
print(ans)

Submission status: Runtime Error

Solution code:
h, w = map(int,input().split())
pic = []

kabe_up_down = []
for i in range(w):
    kabe.append('.')

for i in range(h):
    onelist = ['.']
    inp = list(str(input()))
    for i in range(len(inp)):
        onelist.append(inp[i])
    onelist.append('.')
    pic.append(onelist)
    
flag = 1
a = 'a'
for i in range(1,h+1):
    for j in range(1,w+1):
        here = pic[i][j]
        if here =='#' and pic[i+1][j] == '#':
            pic[i][j] = a
            pic[i+1][j] = a
        elif here =='#' and pic[i][j+1] == '#':
            pic[i][j] = a
            pic[i][j+1] = a
            
for i in range(h+1):
    for j in range(w+1):
        if pic[i][j] == '#':
            flag = 0
            break
        
if flag == 0:
    print('No')
else:
    print('Yes')

Submission status: Runtime Error

Solution code:

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

result = True
masu = [[0 for i in range(H+2)] for j in range(W+2)]
for h in range(1, H+1):
    s = "0"+input()+"0"
    masu[h] = list(s)

# print(masu)    

for h in range(H):
    for w in range(W):
        if masu[h][w] == "#":
            if (masu[h][w] == masu[h+1][w]) or (masu[h][w] == masu[h][w+1]) or (masu[h][w] == masu[h-1][w]) or (masu[h][w] == masu[h][w-1]):
                pass
            else:
                result = False

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

Submission status: Runtime Error

Solution code:
h,w = map(int,input().split())
lst = []
for i in range(h):
  lst.append([s for s in input()])
def dfs(x,y):
  if lst[x][y] == '#':
    lst[x][y] = '.'
    if x + 1 <= h - 1:
      dfs(x + 1,y)
    if x - 1 >= 0:
      dfs(x - 1,y)
    if y + 1 <= w - 1:
      dfs(x, y + 1)
    if y - 1 >= 0:
      dfs(x,y - 1)
flag = True
for i in range(h):
  for j in range(w):
    if lst[i][j] == '#':
      if (i - 1 >= 0 and lst[i - 1][j] == "#") or (i + 1 < h and lst[i + 1][j] == "#") or (j - 1 >= 0 and lst[i][j - 1] == "#") or (j + 1 < w and lst[i][j + 1] == "#"):
        dfs(i,j)
      else:
        flag = False
        break
if flag:
  print("Yes")
else:
  print("No")

Submission status: Runtime Error

Solution code:
h, w = map(int,input().split())
pic = []

kabe_up_down = []
for i in range(w):
    kabe.append('.')

for i in range(h):
    onelist = ['.']
    inp = list(str(input()))
    for i in range(len(inp)):
        onelist.append(inp[i])
    onelist.append('.')
    pic.append(onelist)
    
flag = 1
a = 'a'
for i in range(1,h+1):
    for j in range(1,w+1):
        here = pic[i][j]
        if here =='#' and pic[i+1][j] == '#':
            pic[i][j] = a
            pic[i+1][j] = a
        elif here =='#' and pic[i][j+1] == '#':
            pic[i][j] = a
            pic[i][j+1] = a
            
for i in range(h+1):
    for j in range(w+1):
        if pic[i][j] == #:
        flag = 0
        break
        
if flag == 0:
    print('No')
else:
    print('Yes')

Submission status: Runtime Error

Solution code:
H, W = map(int, input().split(' '))
matrix = []
for _ in range(W):
    tmp = [0 if j == '.' else 1 for j in input()]
    matrix.append(tmp)

for i, row in enumerate(matrix):
    for j, s in enumerate(row):
        flag = True
        if s == 1:
            if (j > 0 and row[j-1] == 0) and (j < W - 1 and row[j+1] == 0):
                if (i > 0 and matrix[i-1][j] == 0) or (i < H - 1 and matrix[i+1][j] == 0):
                  exit(0)

print('Yes')

Submission status: Runtime Error

Solution code:
h, w = map(int,input().split())
pic = []

kabe_up_down = []
for i in range(w):
    kabe.append('.')

for i in range(h):
    onelist = ['.']
    inp = list(str(input()))
    for i in range(len(inp)):
        onelist.append(inp[i])
    onelist.append('.')
    pic.append(onelist)
    
flag = 1
a = 'a'
for i in range(1,h+1):
    for j in range(1,w+1):
        here = pic[i][j]
        if here =='#' and pic[i+1][j] == '#':
            pic[i][j] = a
            pic[i+1][j] = a
        elif here =='#' and pic[i][j+1] == '#':
            pic[i][j] = a
            pic[i][j+1] = a
            
fori in range(h+1):
    for j in range(w+1):
        if pic[i][j] == #:
        flag = 0
        break
        
if flag == 0:
    print('No')
else:
    print('Yes')

Submission status: Runtime Error

Solution code:

h, w = map(int, input().split())
s = [["." for _ in range(w + 2)]]

for _ in range(h):
    s_ = ["."]
    s_.extend([x for x in input()])
    s_.append(".")
    s.append(s_)

s.append(["." for _ in range(w + 2)])


for y in range(h):
    for x in range(w):
        target_x = x + 1
        target_y = y + 1
        # cross check
        if s[target_x][target_y]  == "#":
            if s[target_x - 1][target_y] == "#" or s[target_x + 1][target_y] == "#" or s[target_x][target_y -1 ] == "#" or  s[target_x][target_y +1 ] == "#":
                pass
                # ok
            else:
                # ng
                print("No")
                exit()
print("Yes")

Submission status: Runtime Error

Solution code:
import sys
h, w = (int(i) for i in input().split())
s =[list(input()) for i in range(h)]
flags = []
for i in range(0,h):
    flags.append([0 for i in range(w)])

for i in range(0,h):
    for j in range(0,w-1):
        if s[i][j]=='#' and s[i][j+1]=='#':
            flags[i][j]=1
            flags[i][j+1]=1

for i in range(0,w):
    for j in range(0,h-1):
        if s[j][i]=='#' and s[j+1][i]=='#':
            flags[j][i]=1
            flags[j+1][i]=1

for i in range(0,w):
    for j in range(0,h):
        if s[i][j]=="#":
            if flags[i][j]==0:
                print("No")
                sys.exit()
            else:
                continue

print("Yes")

Submission status: Runtime Error

Solution code:
H,W=map(int,input().split())
S=[input() for i in range(H)]
ans="No"
for i in range(W):
    for j in range(H):
        if S[i][j]=='#':
            if i>0 and S[i-1][j]=='#':
                ans="Yes"
            if i<W-1 and S[i+1][j]=='#':
                ans="Yes"
            if j>0 and S[i][j-1]=='#':
                ans="Yes"
            if j<H-1 and S[i][j+1]=='#':
                ans="Yes"
print(ans)

Submission status: Runtime Error

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


if H == 1 and W == 1 and nodes[0][0] == ".":
    print("No")
    quit()

for i in range(len(nodes)):
    for j in range(len(nodes)):
        if nodes[i][j] == "#":
            flag = False
            if i - 1 >= 0:
                if nodes[i-1][j] == "#":
                    flag = True
            if i + 1 < H:
                if nodes[i+1][j] == "#":
                    flag = True
            if j - 1 >= 0:
                if nodes[i][j-1] == "#":
                    flag = True
            if j + 1 < W:
                if nodes[i][j+1] == "#":
                    flag = True

            if flag == False:
                print("No")
                quit()

print("Yes")

Submission status: Runtime Error

Solution code:
def solve():
    for i in range(1, W):
        for j in range(1, H):
            if s[i][j] == "#":
                if s[i + 1][j] == "." and s[i][j + 1] == "." and s[i-1][j] == "." and s[i][j-1] == ".":
                    print("No")
                    return;
    else:
        print("Yes")


H, W = [int(i) for i in input().split()]
s = [["."] * (W + 2)]
for _ in range(H):
    sh = ["."] + list(input()) + ["."]
    s.append(sh)
s.append([["."] * (W + 2)])
solve()

Submission status: Runtime Error

Solution code:
import numpy as np
import sys

w, h = map(int, sys.stdin.readline().strip().split(" "))

a = np.zeros((w,h), dtype=int)

for i in range(w):
    l = sys.stdin.readline().strip()
    for j in range(h):
        a[i, j] = (l[j] == "#")

for i in range(w):
    for j in range(h):
        if a[i, j] == 0:
            continue
        check = True
        if i >= 1:
            check &= a[i-1, j] == 0
        if i < h-1:
            check &= a[i+1, j] == 0
        if j >= 1:
            check &= a[i, j-1] == 0
        if j < w-1:
            check &= a[i, j+1] == 0
        if check:
            print("No")
            quit()
print("Yes")

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
H,W=map(int,input().split())
S=[input() for i in range(H)]
ans="Yes"
for i in range(W):
    for j in range(H):
        Tonari=[]
        if i>0:
            Tonari.append(S[i-1][j])
        if i<W-1:
            Tonari.append(S[i+1][j])
        if j>0:
            Tonari.append(S[i][j-1])
        if j<H-1:
            Tonari.append(S[i][j+1])
        if S[i][j]=='#' and all([t=='.' for t in Tonari]):
            ans="No"
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

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)))
for i in s:
    print(i)

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

Submission status: Runtime Error

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

cnt = 0

if s[0][0] == "#" and s[0][1] == "." and s[1][0] == ".":
	cnt += 1

for w in range(1, W - 1):
	if s[0][w] == "#" and s[0][w - 1] == "." and s[0][w + 1] == "." and s[1][w] == ".":
		cnt += 1

if s[0][W - 1] == "#" and s[0][W - 2] == "." and s[1][W - 1] == ".":
	cnt += 1 

for h in range(1, H - 1):
	if s[h][0] == "#" and s[h][1] == "." and s[h + 1][0] == "." and s[h - 1][0] == ".":
		cnt += 1

	for w in range(1, W - 1):
		if s[h][w] == "#" and s[h][w - 1] == "." and s[h][w + 1] == "." and s[h + 1][w] == "." and s[h - 1][w] == ".":
			cnt += 1

	if s[h][W - 1] == "#" and s[h][W - 2] == "." and s[h + 1][W - 1] == "." and s[h - 1][W - 1] == ".":
		cnt += 1 

if s[H - 1][0] == "#" and s[H - 1][1] == "." and s[H - 2][0] == ".":
	cnt += 1

for w in range(1, W - 1):
	if s[H - 1][w] == "#" and s[H - 1][w - 1] == "." and s[H - 1][w + 1] == "." and s[H - 2][w] == ".":
		cnt += 1

if s[H - 1][W - 1] == "#" and s[H - 1][W - 2] == "." and s[H - 2][W - 1] == ".":
	cnt += 1

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

Submission status: Runtime Error

Solution code:
H,W=map(int,input().split())
s = [['.' for i in range(H+2)] for j in range(W+2)]
f=0
for i in range(H):
 s[i+1] = ['.'] + list(input()) + ['.']
for i in range(H+2):
 if f == 0:
  for j in range(W+2):
   if s[i][j] == '#':
    if s[i-1][j] == '.' and s[i+1][j] == '.' and s[i][j-1] == '.' and s[i][j+1] == '.':
     f = 1
     print('No')
     break
if f == 0:
 print('Yes')

Submission status: Runtime Error

Solution code:
imports 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 False
  return True

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 not sub(field, _x, _y):
      return False
  return True
    
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())
 
for y in len(field):
  for x in len(field[y]):
    if not isok(field, x, y):
      print 'No'
print 'Yes'

Submission status: Runtime Error

Solution code:
H,W=map(int,input().split())
s=[list(input()) for i in range(H)]
dx=[0,0,1,-1]
dy=[-1,1,0,0]
L=[0]
k=0
#s[i][j]
#i in range(H)
#j in range(W)
def dfs(x,y):
    s[x][y]="."
    L[k]+=1
    for p in range(4):
        nx=x+dx[p]
        ny=y+dy[p]
        if 0<=nx<H and 0<=ny<W:
            if s[nx][ny]=="#":
                dfs(nx,ny)
for i in range(H):
    for j in range(W):
        if s[i][j]=="#":
            dfs(i,j)
            k+=1
            L.append(0)
if min(L[:-1])==1:
    print("No")
else:
    print("Yes")
#print(L[:-1])

Submission status: Runtime Error

Solution code:
imports 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 False
  return True

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 not sub(field, _x, _y):
      return False
  return True
    
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())
 
for y in len(field):
  for x in len(field[y]):
    if not isok (field, x, y):
      print 'No'
print 'Yes'

Submission status: Runtime Error

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(H):
            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: Runtime Error

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 + 1][j] == field[i][j - 1] == field[i][j + 1] == '.':
                return False
    return True


h, w = list(map(int, input().split()))
field = ['.' + input() + '.' for _ in range(h)]
field = ['.' * w] + field + ['.' * w]
print('Yes' if solve(field) else 'No')