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:
h,w = (int(i) for i in input().split())
s = ["."+input()+"." for i in range(h)]
s,flag = ["."*(w+2)]+s+["."*(w+2)],True
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]==".":
				flag = False
if flag: print("Yes")
else: print("No")

Submission status: Accepted

Solution code:
h,w = map(int, input().split())
B = '.'*(w+2)
s = [B]
s.extend(['.' + input() + '.' for _ in range(h)])
s.append(B)

def check():
    for i in range(1,h+1):
        for j in range(1,w+1):
            if s[i][j] == '.':
                continue
            if all([s[x][y]=='.' for x,y in [(i-1,j), (i+1,j), (i,j+1), (i,j-1)]]) :
                return False
    return True

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

Submission status: Accepted

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

T=0
if H==1 & W==1:
	print("No")
	T=1


D=0
Numlist = []
for i in range(H):
	D+=100
	I=0
	RawList = []
	RawList = list(input())

	for j in range(W):
		CheckNum = RawList[j]
		I+=1

		if CheckNum == "#":
			Numlist.append(D+I)

N=0
for k in range(len(Numlist)):
	A = Numlist[k]
#	print(A)

	OK=0

	if (A+1) in Numlist:
		OK+=1
	if (A-1) in Numlist:
		OK+=1
	if (A+100) in Numlist:
		OK+=1
	if (A-100) in Numlist:
		OK+=1

	if OK == 0 and T==0:
		print("No")
		N=1
		break
#	print(OK)

if N==0 and T==0:
	print("Yes")

Submission status: Accepted

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

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

            def ok(x,y):
                return x>=0 and x<h and y>=0 and y<w and s[x][y]=='#'

            if all([not ok(x,y) for x,y in [(i-1,j), (i+1,j), (i,j+1), (i,j-1)]]) :
                return False
    return True


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

Submission status: Accepted

Solution code:
d = list(map(int,input().split()))
at = []
at.append(["."]*(d[1]+2))
for i in range(d[0]):
  at.append(list(input()))
  at[i+1].insert(0,".")
  at[i+1].insert(d[1]+1,".")
at.append(["."]*(d[1]+2))
l = [[1,0],[0,1],[-1,0],[0,-1]]
re = True
op = False
ppp = True
def ao(k, re,op,l,ppp,d):
  for a in range(1,d[0]):
    for b in range(1,d[1]+1):
      for dx,dy in l:
        if k[a][b] =="#" and k[a+dx][b+dy] ==".":
          re = False
        if k[a][b] =="#" and k[a+dx][b+dy] =="#":
          op = True
      if op == True:
        re = True
      if re == False:
        ppp = False
      op = False
      re = True
  if ppp == False:
    return False
  else:
    return True
 
if ao(at,re,op,l,ppp,d) == True:
  print("Yes")
else:
  print("No")

Submission status: Accepted

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

def check():
    for i in range(h):
        for j in range(w):
            if s[i][j] == '.':
                continue
            ok = False
            for x,y in [(i-1,j), (i+1,j), (i,j+1), (i,j-1)]:
                if x<0 or x>=h or y<0 or y>=w :
                    continue
                if s[x][y] == '#':
                    ok = True
            if not ok:
                return False
    return True


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

Submission status: Accepted

Solution code:
H,W = map(int, input().split())
lis = [input() for i in range(H)]
flag = False
for i in range(H):
    for j in range(W):
        if lis[i][j] == "#":
            if i != 0:
                if lis[i-1][j] == "#":
                    continue
            if i != H-1:
                if lis[i+1][j] == "#":
                    continue
            if j != 0:
                if lis[i][j-1] == "#":
                    continue
            if j != W-1:
                if lis[i][j+1] == "#":
                    continue
            flag = True
    if flag:
        break
print("No" if flag else "Yes")

Submission status: Accepted

Solution code:
import sys

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]=="#":
                        if i==0:
                                if j==0:
                                        if s[i+1][j]=="." and s[i][j+1]==".":
                                                print("No")
                                                sys.exit(0)
                                elif j==W-1:
                                        if s[i+1][j]=="." and s[i][j-1]==".":
                                                print("No")
                                                sys.exit(0)
                                else:
                                        if s[i+1][j]=="." and s[i][j-1]=="." and s[i][j+1]==".":
                                                print("No")
                                                sys.exit(0)
                        elif i==H-1:
                                if j==0:
                                        if s[i-1][j]=="." and s[i][j+1]==".":
                                                print("No")
                                                sys.exit(0)
                                elif j==W-1:
                                        if s[i-1][j]=="." and s[i][j-1]==".":
                                                print("No")
                                                sys.exit(0)
                                else:
                                        if s[i-1][j]=="." and s[i][j-1]=="." and s[i][j+1]==".":
                                                print("No")
                                                sys.exit(0)
                        else:
                                if j==0:
                                        if s[i+1][j]=="." and s[i-1][j]=="." and s[i][j+1]==".":
                                                print("No")
                                                sys.exit(0)
                                elif j==W-1:
                                        if s[i+1][j]=="." and s[i-1][j]=="." and s[i][j-1]==".":
                                                print("No")
                                                sys.exit(0)
                                else:
                                        if s[i+1][j]=="." and s[i-1][j]=="." and s[i][j-1]=="." and s[i][j+1]==".":
                                                print("No")
                                                sys.exit(0)
print("Yes")

Submission status: Accepted

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

def check(x, y):
	global flag
	global c
	c += 1
	if flag:
		return
	if (x < 0 or x > W-1):
		return
	if (y < 0 or y > H-1):
		return
	if c != 1:
		if s_lines[y][x] == '#':
			flag = True
			return
		elif s_lines[y][x] == '.':
			return
	check(x+1, y)#right
	check(x-1, y)#left
	check(x, y+1)#down
	check(x, y-1)#up


for y, line in enumerate(s_lines):	
	for x, l in enumerate(line):
		if l == '#':
			flag = False
			c = 0
			check(x, y)
			if flag is False:
				print('No')
				exit()
print('Yes')

Submission status: Accepted

Solution code:
import sys
H,W = input().split()
H = int(H)
W = int(W)
s = []

s.append("."*(W+2))
for i in range(H):
    s.append("."+input()+".")

s.append("."*(W+2))


for i in range(1,1+H):
    for j in range(1,1+W):
#        print(j,i)
        if s[i][j] == "#":
            if s[i][j-1] != "#" and s[i][j+1] != "#" and s[i-1][j] != "#" and s[i+1][j] != "#":
                print("No")

                sys.exit()

print("Yes")

Submission status: Accepted

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

for i in range(h):
	list.append([])
	row = input()
	for j in range(w):
		element = row[j]
		list[i].append(element == '#')

def all_check(h, w, list):
	for i in range(h):
		for j in range(w):
			if not check(i, j, h, w, list):
				return False

	return True

def check(i, j, h, w,list):
	if list[i][j]:
		return subcheck(i, j, h, w, list)
	else:
		return True

def subcheck(i, j, h, w, list):
	if i > 0 and list[i-1][j]:
		return True
	if i < h-1 and list[i+1][j]:
		return True
	if j > 0 and list[i][j-1]:
		return True
	if j < w-1 and list[i][j+1]:
		return True

if all_check(h, w, list):
	print("Yes")
else:
	print("No")

Submission status: Accepted

Solution code:
s = input().rstrip().split()
h = int(s[0])
w = int(s[1])

table = []

for i in range(h):
  t = input()
  line = list(t)
  table.append(line)

flg = 0

h_edge = h-1
w_edge = w-1

for i in range(h):
  for j in range(w):
    if(table[i][j] == "#"):
      table[i][j] == "/"
      if(i == 0 and j == 0):
        if(table[i][j+1] == "." and table[i+1][j] == "."):
          flg = 1
      elif(i == 0 and j != w_edge):
        if(table[i][j+1] == "." and table[i+1][j] == "." and table[i][j-1] == "."):
          flg = 1
      elif(j == 0 and i != h_edge):
        if(table[i][j+1] == "." and table[i+1][j] == "." and table[i-1][j] == "."):
          flg = 1
      elif(i == h_edge and j == w_edge):
        if(table[i-1][j] == "." and table[i][j-1] == "."):
          flg = 1
      elif(i == h_edge):
        if(table[i][j+1] == "." and table[i][j-1] == "." and table[i-1][j] == "."):
          flg = 1
      elif(j == w_edge):
        if(table[i+1][j] == "." and table[i][j-1] == "." and table[i-1][j] == "."):
          flg = 1
      else:
        if(table[i][j+1] == "." and table[i+1][j] == "." and table[i][j-1] == "." and table[i-1][j] == "."):
          flg = 1
      if(flg == 1):
        break
  else:
    continue
  break

if(flg==0):
  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())


def check(i, j):
    if i != 0 and s[i-1][j] == '#':
        return True
    if j != 0 and s[i][j -1] == '#':
        return True
    if i != h - 1 and s[i+1][j] == '#':
        return True
    if j != w -1 and s[i][j+1] == '#':
        return True
    return False

ret = True
for i in range(h):
    for j in range(w):
        if s[i][j] == '#' and not check(i, j):
            ret = False
print('Yes' if ret else 'No')

Submission status: Accepted

Solution code:
H,W = map(int,input().split())
lists = [input() for i in range(H)]
x = 1
y = 1
check = True
for x in range(1,H-1):
    for y in range(1,W-1):
        if(lists[x][y] == "#"):
            if(x!=0 or y!=0 or x==W-1or y==H-1):
                if((lists[x+1][y] == ".") and (lists[x-1][y] == ".") and (lists[x][y-1] == ".") and (lists[x][y+1] == ".")):
                    check = False
if(lists[0][0] == "#"):
     if(lists[0][1] == "." and lists[1][0] == "."):
        check = False
if(lists[H-1][0] == "#"):
     if(lists[H-2][0] == "." and lists[H-1][1] == "."):
            check = False
if(lists[0][W-1] == "#"):
    if(lists[0][W-2] == "." and lists[1][W-1] == "."):
        check = False
if(lists[H-1][W-1] == "#"):
    if(lists[H-2][W-1] == "." and lists[H-1][W-2] == "."):
        check = False
if(check):
    print("Yes")
else :
    print("No")

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
a=[]
for i in range(h):
    a.append(list(input()))
judge = True
for i in range(h):
    for j in range(w):
        if a[i][j]==".":
            continue
        if i>0 and a[i-1][j]=="#":
            continue
        if j>0 and a[i][j-1]=="#":
            continue
        if j<w-1 and a[i][j+1]=="#":
            continue
        if i<h-1 and a[i+1][j]=="#":
            continue
        judge =False
    if not judge :
        break
print("Yes" if judge else "No")

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
grid = []
soloList = []
soloGrid = ""
for _ in range(H):
    row = list(input())
    grid.append(row)

if H == 1 and W == 1:
    if grid[0][0] == ".":
        print("Yes")
    else:
        print("No")

elif H == 1:
    for i in range(H): #行数ぶん繰り返す
        for j in range(W): #列数ぶん繰り返す＝一行当たりのマス数分
            if j == 0:
                if grid[i][j] == "#" and grid[i][j+1] == "." :
                    soloGrid = str(i) + ", " + str(j)
                    soloList.append(soloGrid)
                else:
                    pass
                
            elif j == W-1:
                if grid[i][j] == "#" and grid[i][j-1] == "." :
                    soloGrid = str(i) + ", " + str(j)
                    soloList.append(soloGrid)
                else:
                    pass

            else:
                if grid[i][j] == "#" and grid[i][j-1] == "." and grid[i][j+1] == ".":
                    soloGrid = str(i) + ", " + str(j)
                    soloList.append(soloGrid)
                else:
                    pass
    if soloList == []:
        print("Yes")
    else:
        print("No")

elif W == 1:
    for j in range(W):  #列数ぶん繰り返すが一回だけ
        for i in range(H): #行数ぶん繰り返す＝一列当たりのマス数分
            if i == 0:
                if grid[i][j] == "#" and grid[i+1][j] == "." :
                    soloGrid = str(i) + ", " + str(j)
                    soloList.append(soloGrid)
                else:
                    pass
                
            elif i == H-1:
                if grid[i][j] == "#" and grid[i-1][j] == "." :
                    soloGrid = str(i) + ", " + str(j)
                    soloList.append(soloGrid)
                else:
                    pass
            else:
                if grid[i][j] == "#" and grid[i-1][j] == "." and grid[i+1][j] == ".":
                    soloGrid = str(i) + ", " + str(j)
                    soloList.append(soloGrid)
                else:
                    pass
    print(soloGrid)
    if soloList == []:
        print("Yes")
    else:
        print("No")
                
else:
    for i in range(H): #行数ぶん繰り返す
        for j in range(W): #列数ぶん繰り返す＝一行当たりのマス数分
            if j == 0:
                if grid[i][j] == "#" and grid[i][j+1] == "." :
                    soloGrid = str(i) + ", " + str(j)
                    soloList.append(soloGrid)
                else:
                    pass
                
            elif j == W-1:
                if grid[i][j] == "#" and grid[i][j-1] == "." :
                    soloGrid = str(i) + ", " + str(j)
                    soloList.append(soloGrid)
                else:
                    pass

            else:
                if grid[i][j] == "#" and grid[i][j-1] == "." and grid[i][j+1] == ".":
                    soloGrid = str(i) + ", " + str(j)
                    soloList.append(soloGrid)
                else:
                    pass

#次に縦列で連続しているかチェック
    for j in range(W):  #列数ぶん繰り返す
        for i in range(H): #行数ぶん繰り返す＝一列当たりのマス数分
            if i == 0:
                if grid[i][j] == "#" and grid[i+1][j] == "." :
                    soloGrid = str(i) + ", " + str(j)
                    soloList.append(soloGrid)
                else:
                    pass
                
            elif i == H-1:
                if grid[i][j] == "#" and grid[i-1][j] == "." :
                    soloGrid = str(i) + ", " + str(j)
                    soloList.append(soloGrid)
                else:
                    pass
            else:
                if grid[i][j] == "#" and grid[i-1][j] == "." and grid[i+1][j] == ".":
                    soloGrid = str(i) + ", " + str(j)
                    soloList.append(soloGrid)
                else:
                    pass
            
    if len(soloList) == len(set(soloList)):
        print("Yes")
    else:
        print("No")

Submission status: Accepted

Solution code:
h,w = map(int,input().split())
c = [[] for i in range(0,h+2)]
ans = "Yes"
c[0] = ["."for i in range(0,w+2)]
c[h+1] = ["."for i in range(0,w+2)]
for i in range(1,h+1):
    d = []
    d = list(input())
    d.append(".")
    d.insert(0,".")
    c[i] = d
for j in range(1,h+1):
    for i in range(1,w+1):
        if c[j][i] == "#":
            flag = "No"
            if(c[j][i-1] == "#"):
                flag = "Yes"
            if(c[j][i+1] == "#"):
                flag = "Yes"
            if(c[j-1][i] == "#"):
                flag = "Yes"
            if(c[j+1][i] == "#"):
                flag = "Yes"
            if(flag == "No"):
                ans = "No"
print(ans)

Submission status: Accepted

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

As_is_campus=[[False for w in range(W)] for h in range(H)]
#Tobeは上下左右に1マスずつゆとりを持たせる。
To_be_campus=[[False for w in range(W+2)] for h in range(H+2)]

for h in range(H):
    for i,w in enumerate(input()):
        if w=="#":
            To_be_campus[h+1][i+1]=True
            
#print(To_be_campus)

#Trueが上下左右に並んでいるか確認する
flag = True
for i in range(1,H+2):
    if not flag :
        break
    for j in range(1,W+2):
        if To_be_campus[i][j]:
            if not (To_be_campus[i-1][j] or To_be_campus[i][j-1] or To_be_campus[i][j+1]  or To_be_campus[i+1][j] ):
                flag = False
                break

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

Submission status: Accepted

Solution code:
# 方針：黒く塗られるべきマスの隣（縦or横）に、同様のマスがあれば塗れる→Yes
# 逆に、黒く塗られるべきマスに接していない、黒く塗られるべきマスがあると、達成は不可能→No

# 行数・列数の入力(Row, Column)
R, C = list(map(int, input().split(" ")))
# print(R, C)

# Want map = 設計図、Can map = 塗れるかのマップ
want_map = []
can_map = []

for r in range(R):
    # 一行ずつ、両マップを更新
    want_map.append(list(input()))
    can_map.append(["?"] * C)
#    print("Want Map: {}".format(want_map))

    for c in range(C):
        if can_map[r][c] != "feasible":
            if want_map[r][c] == ".":
                can_map[r][c] = "feasible"

            else:
                if c + 1 < C:
                    if want_map[r][c+1] == "#":
                        can_map[r][c] = "feasible"
                        can_map[r][c+1] = "feasible"
        else:
            if c + 1 < C:
                if want_map[r][c + 1] == "#":
                    can_map[r][c + 1] = "feasible"

        if r != 0:
            if (want_map[r][c] == "#") & (want_map[r-1][c] == "#"):
                can_map[r][c] = "feasible"
                can_map[r-1][c] = "feasible"

#    print("Can Map: {}".format(can_map))


# can_mapの中に"?"が残っていたらNo, なければYes
can_elements = []

for can_map_row in can_map:
    can_elements.extend(can_map_row)

if "?" in can_elements:
    print("No")
else:
    print("Yes")

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
lst = [[0 for x in range(W)] for y in range(H)]

for i in range(H):
  x = input().split()
  x = list(x[0])
  for j,l in enumerate(x):
    lst[i][j] = l

for i in range(H):
  for j in range(W):
    checker = []
    if lst[i][j] == '#':
      if i != 0:
        num = 1 if lst[i - 1][j] == '.' else 0
        checker.append(num)
      if i != H - 1:
        num = 1 if lst[i + 1][j] == '.' else 0
        checker.append(num)
      if j != 0:
        num = 1 if lst[i][j - 1] == '.' else 0
        checker.append(num)
      if j != W - 1:
        num = 1 if lst[i][j + 1] == '.' else 0
        checker.append(num)
    
    if len(checker) == sum(checker) and len(checker) != 0:
      print('No')
      exit()

print('Yes')

Submission status: Accepted

Solution code:
import itertools
H, W = list(map(int,input().strip().split(' ')))
pict = [[0]*W]*H
for i in range(H):
    pict[i] = list(map(str,input().strip().split(' ')))
now = [['.' for i in range(W)] for j in range(H)]
for i,j in itertools.product(range(H),range(W)):
    if pict[i][0][j] == '#':
        if j < W-1:
            if pict[i][0][j+1]== '#':
                now[i][j],now[i][j+1] = '#','#'
        if i < H-1:
            if pict[i+1][0][j] == '#':
                now[i][j],now[i+1][j] = '#','#'
flg = 'Yes'

for i,j in itertools.product(range(H),range(W)):
    if pict[i][0][j] != now[i][j]:
        flg = 'No'
print(flg)

Submission status: Accepted

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

array = ["".join(list(input())) for x in range(h)]

array2 = list(map(list, zip(*array)))
array3 = []
for i in array2:
    array3.append("".join(i))

flag = True
for h_i in range(len(array)):
    for w_i in range(len(array[h_i]) - 2):
        if array[h_i][w_i:w_i + 3] == ".#.":
            if array3[w_i + 1][h_i:h_i + 3] == ".#." or array3[w_i + 1][h_i - 3:h_i] == ".#.":
                flag = False
                break
    if not flag:
        break

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

Submission status: Accepted

Solution code:
H,W = map(int,input().split())
a = [["."]*(W+2)]*(H+1)
f = True
for i in range(H):
    a[i+1] = ["."]
    a[i+1].extend([x for x in input()])
    a[i+1].append(".")
a.append(["."]*(W+2))
for i in range(1,H+1):
    for j in range(1,W+1):
        if a[i][j] == "#":
            if a[i][j+1] == "." and a[i][j-1] == "." and a[i+1][j] == "." and a[i-1][j] == ".":
                f = False
                break
                break
if f:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
H, W = (int(i) for i in input().split())
t = []
t.append(['.']*(H+2))

for j in range(H):
	tmp = input()
	tmp = '.' + tmp + '.'
	t.append(list(tmp))

t.append(['.']*(H+2))

def CheckBlock(i,k):
	if t[i][k-1] == '#': #check up
		return 0
	elif t[i-1][k] == '#': #check left
		return 1
	elif t[i+1][k] == '#': #check right
		return 2
	elif t[i][k+1] == '#': #check down
		return 3
	else:
		return 4

for k in range(1,W+1):
	for i in range(1,H+1):
		if t[i][k] == '#':
			marker = CheckBlock(i,k)
			if marker == 4:
				print('No')
				quit()
print('Yes')

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
H,W = list(map(int,raw_input().split()))
field = []
answer = "Yes"
for i in range (H):
    li = list(raw_input().strip())
    field.append(li[:])
def check(a,b):
    if field[a][b] ==".":
        return True
    check_li = [[a-1,b],[a+1,b],[a,b+1],[a,b-1]]
    check_li = filter(lambda x: 0 <= x[0] <= H-1 and 0<= x[1] <=W-1,check_li )
    for i in check_li:
        if field[i[0]][i[1]] == "#":
            return True
            break
    else:
        return False

for i in range (H):
    for j in range (W):
        if check(i,j) == False:
            answer = "No"
            break
print answer

Submission status: Accepted

Solution code:
H, W = [int(a) for a in input().split()]
cambus = []
cambus.append(list("."*(W+2)))
for i in range(H):
     cambus.append(["."] + list(input()) + ["."])
cambus.append(list("."*(W+2)))
stop_num = 0


for i in range(H):
    for j in range(W):
        if cambus[i+1][j:j + 3] == [".", "#", "."]:
            if cambus[i][j+1] == "." and cambus[i+2][j+1] == ".":
                stop_num = 1
                break
if stop_num == 1:
    print("No")
else:
    print("Yes")

Submission status: Accepted

Solution code:
h,w = map(int,input().split())
s = [input() for i in range(h)]
ans = "Yes"
for i in range(h-1):
    for j in range(w-1):
        if s[i][j] == "#" and s[i][j] != s[i][j+1] and s[i][j] != s[i+1][j]:
            if (j >= 1 and s[i][j] == "#" and s[i][j] == s[i][j-1]) or (i >= 1 and s[i][j] == "#" and s[i][j] == s[i-1][j]):
                continue
            else:
                ans = "No"
                print(ans)
                exit()
        else:
            continue
print(ans)

Submission status: Accepted

Solution code:

H, W = map(int, input().split())
grid = []
answer = 'Yes'
for i in range(H):
    grid.append(list(input()))

for i in range(H):
    for j in range(W):
        tonari = []
        if i != 0:
            tonari.append(grid[i-2][j-1])
        if i != H:
            tonari.append(grid[i][j-1])
        if j != 0:
            tonari.append(grid[i-1][j-2])
        if j != W:
            tonari.append(grid[i-1][j])
            
        if '#' not in tonari and grid[i-1][j-1] == '#':
            answer = 'No'
print(answer)

Submission status: Accepted

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

square = []
empty = []
for i in range(W+2):
    empty.append('.')
square.append(empty)

for i in range(H):
    line = list(input())
    line.append('.')
    line.insert(0, '.')
    square.append(line)

square.append(empty)
a = 0
for i in range(H):
    for j in range(W):
        if square[1 + i][1 + j] =='#':
            if square[i][1 + j] == '#' or square[i + 1][j] == '#'\
               or square[i +1][j+2] == '#' or square[i +2][j +1] =='#':
                continue
            else:
                a = 1
                break

if a == 0:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
def abc096_c():
    import numpy as np
    h, w = map(int, input().split())
    c = np.zeros([h + 2, w + 2], dtype=int)
    for i in range(h):
        row = "." + input() + "."
        for j in range(w + 2):
            c[i + 1][j] = [0, 1][row[j] == "#"]

    for i in range(1, h + 2):
        for j in range(1, w + 2):
            if c[i][j] == 1 and (np.sum([c[i - 1][j], c[i + 1][j], c[i][j - 1], c[i][j + 1]]) == 0):
                return "No"

    return "Yes"


print(abc096_c())

Submission status: Accepted

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

result = "Yes"
#  .
# .#. が無いか調べる
#  .
for j in range(H-1):
    for k in range(W):
        if i[j][k] == '.':
            if k == 0 or j == H - 1 or i[j+1][k-1] == '.':
                if i[j+1][k] == '#':
                    if j == H - 1 or k == W - 1 or i[j+1][k+1] == '.':
                        if j > H - 3 or i[j+2][k] == '.':
                            result = "No"


print(result)

Submission status: Accepted

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


for i in range(w):
    for j in range(h):
        if s[i][j] == '#':
            if j-1<0 and i+1>=w and j+1>=h and i-1>=0:
                if s[i-1][j] == '#' or s[i+1][j] == '#'  or s[i][j+1] == '#':
                    continue
                else:
                    print("No")
                    exit()        
            elif i-1<0 and j-1>=0 and j+1<h and i+1>=w:
                if  s[i+1][j] == '#' or s[i][j-1] == '#' or s[i][j+1] == '#':
                    continue
                else:
                    print("No")
                    exit() 
            elif j-1>=0 and i+1<w and j+1>=h and i-1 >=0:
                if s[i-1][j] == '#' or s[i+1][j] == '#' or s[i][j-1] == '#' :
                    continue
                else:
                    print("No")
                    exit() 
            elif j-1>=0 and i+1>=w and j+1<h and i-1 >=0 :
                if s[i-1][j] == '#'  or s[i][j-1] == '#' or s[i][j+1] == '#':
                    continue
                else:
                    print("No")
                    exit()  
            elif j-1>=0 and i+1<w and j+1<h and i-1 >=0 :
                if s[i-1][j] == '#' or s[i+1][j] == '#' or s[i][j-1] == '#' or s[i][j+1] == '#':
                    continue
                else:
                    print("No")
                    exit()        

print("Yes")

Submission status: Accepted

Solution code:
import numpy as np

i = input().split(' ')
H = int(i[0])
W = int(i[1])

arr = []

for h in range(0,H):
    s = input().replace('\n', "")
    s = s.replace('.', "0")
    s = s.replace('#', "1")
    arr.append(list(s))

arr = np.array(arr, dtype=int)
able = "Yes"

for i in range(0,H):
    for j in range(0,W):
        if arr[i,j] == 0:
            continue
        localAble = 0
        if 0<=i-1:
            if arr[i-1,j] == 1:
                localAble = 1
        if i+1<H:
            if arr[i+1,j] == 1:
                localAble = 1
        if 0<=j-1:
            if arr[i,j-1] == 1:
                localAble = 1
        if j+1<W:
            if arr[i,j+1] == 1:
                localAble = 1
        if localAble == 0:
            #print("{} {}".format(i,j))
            #print(arr[i,j])
            able = "No"

print(able)

Submission status: Accepted

Solution code:
import sys
h, w = (int(i) for i in input().split()) 
arr = [['.' for i in range(w)] for j in range(h)]
for j in range(h):
  k = 0
  for char in input():
    arr[j][k] = char
    k += 1
for H in range(h):
  for W in range(w):
    if arr[H][W] =="#":
      if (H+1 <= h-1 and arr[H+1][W] == ".") and (H-1 >= 0 and arr[H-1][W] == ".") and (W+1 <= w-1 and arr[H][W+1] == ".") and (W-1 >= 0 and arr[H][W-1] == "."):
        print("No")
        sys.exit()
print("Yes")

Submission status: Accepted

Solution code:
import sys

h,w = map(int, input().split())
a = []
for i in range(w):
  a.append(0)
for i in range(h):
  for s in input():
    if s == "#":
      a.append(1)
    else:
      a.append(0)
for i in range(w):
  a.append(0)

for i,j in enumerate(a):
  if i < w:
    continue
  if i >= h*w+w:
    break
  if j == 1 and a[i-1]+a[i-w]+a[i+1]+a[i+w] == 0:
    print("No")
    sys.exit()
print("Yes")

Submission status: Accepted

Solution code:
h, w = list(map(int, input().split()))
grid = []
grid.append(list('.'*(w+2)))
for i in range(h):
    grid.append(['.'] + list(input()) + ['.'])
grid.append(list('.'*(w+2)))
bools = []
for i in range(h):
    for j in range(w):
        if grid[i+1][j+1] == '.':
            bools.append(True)
        else:
            if grid[i][j+1] == '#' or grid[i+1][j] == '#' or grid[i+2][j+1] == '#' or grid[i+1][j+2] == '#':
                bools.append(True)
            else:
                bools.append(False)
if all(bools):
    print('Yes')
else:
    print('No')