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: Wrong Answer

Solution code:
n = input().split()

n = [int(n[0]), int(n[1])]
H = n[0]
W=n[1]

s = [list(map(str, input().split())) for i in range(H)]
print(s[0][0][1])
c = True
for i in range(H):
    for j in range(W):
        if(s[i][0][j] == '#'):
            if(i == 0):
                if(j == 0):
                    if(s[i + 1][0][j] == '.' and s[i][0][j + 1] == '.'):
                        c = False
                        break
                elif(j == W - 1):
                    if(s[i+1][0][j ] == '.' and s[i][0][j-1] == '.'):
                        c = False
                        break
                else:
                     if(s[i + 1][0][j] == '.' and s[i][0][j + 1] == '.' and s[i][0][j-1] == '.'):
                        c = False
                        break
            elif(i == H - 1):
                if(j == 0):
                    if(s[i - 1][0][j] == '.' and s[i][0][j +1] == '.'):
                        c = False
                        break
                elif(j == W - 1):
                    if(s[i-1][0][j] == '.' and s[i][0][j-1] == '.'):
                        c = False
                        break
                else:
                     if(s[i - 1][0][j] == '.' and s[i][0][j + 1] == '.' and s[i][0][j-1] == '.'):
                        c = False
                        break
            else:
                if(j == 0):
                    if(s[i - 1][0][j] == '.' and s[i][0][j +1] == '.' and s[i + 1][0][j] == '.'):
                        c = False
                        break
                elif(j == W - 1):
                    if(s[i-1][0][j] == '.' and s[i][0][j-1] == '.' and s[i + 1][0][j] == '.'):
                        c = False
                        break
                else:
                     if(s[i - 1][0][j] == '.' and s[i][0][j + 1] == '.' and s[i][0][j-1] == '.' and s[i + 1][0][j] == '.'):
                        c = False
                        break
                
    
if(c):
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
def main():
    """
    1<=H,W<=50

    # or ## がない場合塗り方として無理
    #
    """
    H, W = map(int, input().split())

    s = [
        input()
        for _ in range(H)
    ]

    f(H, W, s)


def f(H, W, s):
    d = list(zip(
        (0, 0, 1, -1),
        (1, -1, 0, 0)
    ))
    for h in range(H):
        for w in range(W):
            if s[h][w] == ".":
                break

            ok = False
            for dy, dx in d:
                ny, nx = h+dy, w+dx
                if 0 <= ny < H and 0 <= nx < W and s[ny][nx] == "#":
                    ok = True
            if not ok:
                print("No")
                return

    print("Yes")


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def printg():
	for i in range(H+2):
		print(G[i])

def p(s):
	if s == '#':
		return True
	else:
		return False

def isok(i,j):
	u = p(G[i][j-1])
	r = p(G[i+1][j])
	d = p(G[i][j+1])
	l = p(G[i-1][j])
	if u or r or d or l:
		return True
	else:
		return False

if __name__ == '__main__':
	H,W = map(int,input().split())
	G = [['B']*(W+2) for _ in range(H+2)]

	for i in range(H):
		l = input()
		for j in range(W):
			G[i+1][j+1] = l[j]

	printg()

	for i in range(H+1):
		for j in range(W+1):
			if G[i][j] == '#':
				if not isok(i,j):
					print('No')
					exit()

	print('Yes')

Submission status: Wrong Answer

Solution code:
nums = list(map(int, input().split()))
H=nums[0]
W=nums[1]
Strings=[]
for k in range(H):
    Strings.append(input())
for i in range(H):
    list(Strings[i])
    c=0
    for j in range(1, W):
        if Strings[i][j]=="#" and Strings[i][j-1]=="#":
            c=1
            break
for l in range(W):
    for m in range(1,H):
        if Strings[m][l]=="#" and Strings[m-1][l]=="#":
            c=1
            break
if c==1:
    print("Yes") 
else:
    print("No")

Submission status: Wrong Answer

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],".")
at.append(["."]*(d[1]+2))
l = [[1,0],[0,1],[-1,0],[0,-1]]
re = True
op = False
def ao(k, re,op,l):
  for a in range(1,d[0]):
    for b in range(1,d[1]):
      for dx,dy in l:
        if k[a][b] =="#" and k[a+dx][b+dy] ==".":
          re = False
        elif k[a][b] =="#" and k[a+dx][b+dy] =="#":
          op = True
      if op == True:
        re = True
      op = False
  return re
if ao(at,re,op,l) == True:
  print("Yes")
else:
  print("No")

Submission status: Wrong Answer

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:
                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:
                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+1][j] == '#' or s[i][j-1] == '#' or s[i][j+1] == '#':
                    continue
                else:
                    print("No")
                    exit()        

print("Yes")

Submission status: Wrong Answer

Solution code:
x = list(map(int,input().split()))
h = x[0]
w = x[1]
can = list()
for i in range(h):
    y = input()
    can.append(y)
z = 0
for i in range(h):
    for j in range(w):
        if can[i][j] == "#":
            if i > 0:
                if can[i - 1][j] == "#":
                    break
            if i < h - 1:
                if can[i + 1][j] == "#":
                    break
            if j > 0:
                if can[i][j - 1] == "#":
                    break
            if j < w - 1:
                if can[i][j + 1] == "#":
                    break
            z += 1
if z == 0:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
x = list(map(int,input().split()))
h = x[0]
w = x[1]
can = list()
for i in range(h):
    y = input()
    can.append(y)
z = 0
for i in range(h):
    for j in range(w):
        if can[i][j] == "#":
            if i > 0:
                if can[i - 1][j] == "#":
                    break
            if i < h - 1:
                if can[i + 1][j] == "#":
                    break
            if j > 0:
                if can[i][j - 1] == "#":
                    break
            if j < w - 1:
                if can[i][j + 1] == "#":
                    break
            z += 1
            print(i)
            print(j)
if z == 0:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

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

d=[]

d.append("."*(w+2))

for i in range(h):
    r = input()
    d.append("."+r+".")
    
d.append("."*(w+2))
#print(d)

no=True

def isok(d,i,j):
    c = 0
    c = c+1 if d[i-1][j]=="#" else c
    c = c+1 if d[i][j-1]=="#" else c
    c = c+1 if d[i][j+1]=="#" else c
    c = c+1 if d[i+1][j]=="#" else c
    result= True if c > 0 else False
    return result
        

for i in range(h):
    if no == True:
        break
    for j in range(w):
        if no == True:
            break
        if d[i][j] == "#":
            a = isok(d,i,j)
            if a == False:
                no = True
                break


result = "No" if no==True else "Yes"
print(result)

Submission status: Wrong Answer

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

d=[]

d.append("."*(w+2))

for i in range(h):
    r = input()
    d.append("."+r+".")
    
d.append("."*(w+2))
#print(d)

no=True

def isok(d,i,j):
    c = 0
    c = c+1 if d[i-1][j]=="#" else c
    c = c+1 if d[i][j-1]=="#" else c
    c = c+1 if d[i][j+1]=="#" else c
    c = c+1 if d[i+1][j]=="#" else c
    result= True if c > 0 else False
    return result
        

for i in range(h):
    if no == True:
        break
    for j in range(w):
        if no == True:
            break
        if d[i][j] == "#":
            a = isok(d,i,j)
            if a == False:
                no = True
                break


result = "no" if no==True else "yes"
print(result)

Submission status: Wrong Answer

Solution code:
H,W  = map(int, input().split()) 
S = [list(input()) for i in range(H)] 
T =[['.']*(W+2)]
for y in range (H):
    T.append(['.']+S[y]+['.'])

T.append(['.']*(W+2))

ans = 'Yes'
for y in range(1,H+1):
    for x in range(1,W+1):
        if ((T[y][x]=='#') and (T[y-1][x-1]=='.') 
            and (T[y+1][x-1]=='.') and (T[y-1][x+1]=='.') and (T[y+1][x+1]=='.') ):
            ans = 'No'

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
H,W = map(int,input().split())
temp =[0 for i in range(H)]
now_point = [0,0]
for i in range(H):
    temp[i] = input()
dx = [-1,1,0,0]
dy = [0,0,1,-1]

for j in range(H*W):
    if temp[now_point[0]][now_point[1]] == "#":
        # temp_count1 = 0
        temp_count2 = 0
        for i in range(4):
            serch_point = [now_point[0]+dx[i],now_point[1]+dy[i]]
            if 0 <= serch_point[0] < H and 0 <= serch_point[1] < W:
                    # temp_count += 1
                if temp[serch_point[0]][serch_point[1]] == "#":   
                    temp_count2 += 1
        # if temp_count1 == temp_count2:
        if temp_count2 == 0:
            print("No")
            sys.exit()
print("Yes")

Submission status: Wrong Answer

Solution code:
H,W = map(int,input().split())
maps = [input().rstrip() for x in range(H)]
for i in range(H):
  for j in range(W):
    if maps[i][j] == '#':
      count = 0
      if 0 < i-1 and maps[i-1][j] == '#':
        count += 1
      if i+1 < H and maps[i+1][j] == '#':
        count += 1
      if 0 < j-1 and maps[i][j-1] == '#':
        count += 1
      if j+1 < W and maps[i][j+1] == '#':
        count += 1
      if count == 0:
        print('No')
        exit()
print('Yes')

Submission status: Wrong Answer

Solution code:
def printg():
	for i in range(H+1):
		print(G[i])

def p(s):
	if s == '#':
		return True
	else:
		return False

def isok(i,j):
	u = p(G[i][j-1])
	r = p(G[i+1][j])
	d = p(G[i][j+1])
	l = p(G[i-1][j])
	if u or r or d or l:
		return True
	else:
		return False

if __name__ == '__main__':
	H,W = map(int,input().split())
	G = [['B']*(W+1) for _ in range(H+1)]

	for i in range(1,H):
		l = input()
		for j in range(1,W):
			G[i][j] = l[j]

	for i in range(H+1):
		for j in range(W+1):
			if G[i][j] == '#':
				if not isok(i,j):
					print('No')
					exit()

	print('Yes')

Submission status: Wrong Answer

Solution code:
h,w=map(int,input().split())
t=[list(input())for i in range(h)]
cnt=0#"#"の数
for i in range(h):
    for j in range(w):
        if t[i][j]=="#":
            cnt+=1
dx=[1,0-1,0,0]
dy=[0,-1,0,1,0]
cout=0
for i in range(h):
    for j in range(w):
        if t[i][j]=="#":
            for k in range(4):
                x_p=i+dx[k]
                y_p=j+dy[k]
                if 0<=x_p and x_p<h and 0<=y_p and y_p<w and t[x_p][y_p]=="#":
                    cout+=1
                    t[x_p][y_p]="."
            t[i][j]="."
if cout==cnt:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
from collections import deque

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

s = deque()

for i in range(H):
    s.append(input())

frg = 0

for i in range(1, H-1):
    for l in range(1, W-1):
        if s[i][l] == s[i-1][l] or s[i][l] == s[i][l-1] or s[i][l] == s[i+1][l] or s[i][l] == s[i][l+1]:
            pass
        else:
            frg = 1
            break
    if frg == 1:
        print('No')
        break
if frg == 0:
    print('Yes')

Submission status: Wrong Answer

Solution code:
uu = list(map(int,input().split()))
h = uu[0]
w = uu[1]
arr = []
for i in range(0, h):
    arr.append(list(map(lambda x: x == "#", list(input()))))
res = True
for i in range(0, (h - 1)):
    for j in range (0, (w - 1)):
        if arr[i][j]:
            if (not arr[i + 1][j]) and (not arr[i][j + 1]):
                res = False
                break
    if not res:
        break
if res:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10000)

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

flag = 1
for i in range(h):
    for j in range(w):
        if(s[i][j] == "#"):
            if(i != 0 and s[i-1][j] == "#"):
                flag = 1
            elif(j != w-1 and s[i][j+1] == "#"):
                flag = 1
            elif(i != h-1 and s[i+1][j] == "#"):
                flag = 1
            elif(j != 0 and s[i][j-1] == "#"):
                flag = 1
            else:
                flag = 0
    if(flag == 0):
        print("No")
        exit()

print("Yes")

Submission status: Wrong Answer

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],".")
at.append([["."]*(d[1]+2)])

l = [[1,0],[1,1],[0,1],[-1,1],[-1,0],[-1,-1],[0,-1],[1,-1]]
re = True
op = False
def ao(k):
  for a in range(1,d[0]):
    for b in range(1,d[1]):
      for dx,dy in l:
        if at[a][b] =="#" and at[a+dx][b+dy] ==".":
          re = False
        if at[a][b] =="#" and at[a+dx][b+dy] =="#":
          op = True
      if op == true:
        re = True
      op = False

if re == True:
  print("Yes")
else:
  print("No")

Submission status: Wrong Answer

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]=="#":
            break
        if j>0 and a[i][j-1]=="#":
            break
        if j<w-1 and a[i][j+1]=="#":
            break
        if i<h-1 and a[i+1][j]=="#":
            break
        judge =False
    if judge :
        break
print("Yes" if judge else "No")

Submission status: Wrong Answer

Solution code:
nums = list(map(int, input().split()))
H=nums[0]
W=nums[1]
Strings=[]
for k in range(H):
    Strings.append(input())
for i in range(H):
    list(Strings[i])
    c=0
    for j in range(1, W):
        if Strings[i][j]=="#" and Strings[i][j-1]=="#":
            c=1
for l in range(W):
    for m in range(1,H):
        if Strings[m][l]=="#" and Strings[m-1][l]=="#":
            c=1
if c==1:
    print("Yes") 
else:
    print("No")

Submission status: Wrong Answer

Solution code:
def main():
    H, W = map(int, input().split())
    S = tuple(input() for _ in [0] * H)

    grid = ['.' * (W + 2)]
    apnd = grid.append
    for s in S:
        apnd('.' + s + '.')
    apnd('.' * (W + 2))

    for i in range(1, H + 2):
        j = grid[i].find('#')
        if j > -1:
            if grid[i-1][j] == grid[i+1][j] == grid[i][j-1] == grid[i][j+1] == '.':
                ans = 'No'
                break
    else:
        ans = 'Yes'

    print(ans)

main()

Submission status: Wrong Answer

Solution code:
nums = list(map(int, input().split()))
H=nums[0]
W=nums[1]
Strings=[]
for k in range(H):
    Strings.append(input())
for i in range(H):
    list(Strings[i])
    c=0
    for j in range(1, W):
        if Strings[i][j]=="#" and Strings[i][j-1]=="#":
            c=1
for l in range(W):
    for m in range(1,H):
        if Strings[i][j]=="#" and Strings[i-1][j]=="#":
            c=1
if c==1:
    print("Yes") 
else:
    print("No")

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10000)

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

flag = 1
for i in range(h):
    for j in range(w):
        if(s[i][j] == "#"):
            if(i != 0 and s[i][j] == "#" and s[i-1][j] == "#"):
                flag = 1
                break
            else:
                flag = 0

            if(j != w-1 and s[i][j] == "#" and s[i][j+1] == "#"):
                flag = 1
                break
            else:
                flag = 0

            if(i != h-1 and s[i][j] == "#" and s[i+1][j] == "#"):
                flag = 1
                break
            else:
                flag = 0

            if(j != 0 and s[i][j] == "#" and s[i][j-1] == "#"):
                flag = 1
                break
            else:
                flag = 0
    if(flag == 0):
        print("No")
        exit()

print("Yes")

Submission status: Wrong Answer

Solution code:
H, W = list(map(int, input().split(' ')))
import numpy as np
import sys
grid = np.zeros((H, W))
for h in range(H):
  grid[h,:] = [0 if g == '.' else 1 for g in input()]
  
# print(grid)
for h in range(H):
  for w in range(W):
    if grid[h, w] == 0:
      continue
    
    around = []
    if h > 0:
      around.append(grid[h-1, w])
    if w > 0:
      around.append(grid[h, w-1])
    if h < H-1:
      around.append(grid[h+1, w])
    if w < W-1:
      around.append(grid[h, w+1])
    if 1 in around:
      pass
    else:
      # print(h, w, around)
      print('No')
      sys.exit()
print('yes')

Submission status: Wrong Answer

Solution code:
def main():
    H, W = map(int, input().split())
    S = tuple(input() for _ in [0] * H)

    grid = ['.' * (W + 2)]
    apnd = grid.append
    for s in S:
        apnd('.' + s + '.')
    apnd('.' * (W + 2))

    for i in range(1, H + 1):
        j = grid[i].find('#')
        if j > -1:
            if grid[i-1][j] == grid[i+1][j] == grid[i][j-1] == grid[i][j+1] == '.':
                ans = 'No'
                break
    else:
        ans = 'Yes'

    print(ans)

main()

Submission status: Wrong Answer

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


def able_black(line, row):
    if data[line][row] == '.':
        return True
    else:
        for dx in range(-1, 2):
            for dy in range(-1, 2):
                if 0 <= line+dx <= h-1 and 0 <= row+dy <= w-1 and not ((dx == 0 and dy == 0) or (dx == 1 and dy == 1) or (dx == -1 and dy == -1)):
                    if data[line+dx][row+dy] == '#':
                        return True
        return False


for i in range(h):
    for j in range(w):
        if not able_black(i, j):
            print('No')
            exit()
print('Yes')

Submission status: Wrong Answer

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

cnt = 0
for i in range(h):
    cnt += s[i].count('#')
if cnt == 0:
    print('Yes')
    exit()

flg = False
for i in range(h):
    for j in range(w):
        if (s[i][j] == '#'):
            if (i -1) >= 0:
                flg = (flg or (s[i - 1][j] == '#'))
            if (j - 1) >= 0:
                flg = (flg or (s[i][j - 1] == '#'))
            if (j + 1) < w:
                flg = (flg or (s[i][j + 1] == '#'))
            if (i + 1) < h:
                flg = (flg or (s[i + 1][j] == '#'))
            if not(flg):
                break
    if not(flg):
        break

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

Submission status: Wrong Answer

Solution code:
nums = list(map(int, input().split()))
H=nums[0]
W=nums[1]
Strings=[]
for k in range(H):
    Strings.append(input())
for i in range(H):
    list(Strings[i])
    c=0
    for j in range(1, W):
        if Strings[i][j]==Strings[i][j-1]:
            c=1
for l in range(W):
    for m in range(1,H):
        if Strings[i][j]==Strings[i-1][j]:
            c=1
if c==1:
    print("Yes") 
else:
    print("No")

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10000)

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

flag = 1
for i in range(h):
    for j in range(w):
        if(i != 0 and s[i][j] == "#" and s[i-1][j] == "#"):
            flag = 1
            break
        else:
            flag = 0

        if(j != w-1 and s[i][j] == "#" and s[i][j+1] == "#"):
            flag = 1
            break
        else:
            flag = 0

        if(i != h-1 and s[i][j] == "#" and s[i+1][j] == "#"):
            flag = 1
            break
        else:
            flag = 0

        if(j != 0 and s[i][j] == "#" and s[i][j-1] == "#"):
            flag = 1
            break
        else:
            flag = 0
    if(flag == 0):
        print("No")
        exit()

print("Yes")

Submission status: Wrong Answer

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

flag = 'YES'
for i in range(h):
    for j in range(w):
        if s[i][j] == '#':
            if i != 0 and s[i-1][j] == '#':
                continue
            elif i != h-1 and s[i+1][j] == '#':
                continue
            elif j != 0 and s[i][j-1] == '#':
                continue
            elif j != w-1 and s[i][j+1] == '#':
                continue
            flag = 'NO'
        else:
            continue

print(flag)

Submission status: Wrong Answer

Solution code:
def main():
    H, W = map(int, input().split())
    S = tuple(input() for _ in [0] * H)

    grid = ['.' * (W + 2)]
    apnd = grid.append
    for s in S:
        apnd('.' + s + '.')
    apnd('.' * (W + 2))

    for i, s in enumerate(grid):
        j = s.find('#')
        if j > -1:
            if s[j-1] == s[j+1] == grid[i-1][j] == grid[i+1][j] == '.':
                ans = 'No'
                break
    else:
        ans = 'Yes'

    print(ans)

main()

Submission status: Wrong Answer

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

if H == 1 and W == 1 and grid[0][0] == "#":
    print("Yes")
    exit()

sharp_counter = 0
for h in range(H):
    for w in range(W):
        if grid[h][w] == ".":
            continue

        sharp_counter += 1
        nearby_sharp_counter = 0

        for a, b in [(-1, 0), (1, 0), (0, -1), (0, 1)]:
            if h+a < 0 or h+a >= H or w+b < 0 or w+b >= W:
                continue
            elif grid[h+a][w+b] == "#":
                nearby_sharp_counter += 1
        
        if nearby_sharp_counter == 0:
            print("No")
            exit()

if sharp_counter == 0:
    print("No")
    exit()

print("Yes")

Submission status: Wrong Answer

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

if H == 1 and W == 1 and grid[1][1] == "#":
    print("Yes")
    exit()

sharp_counter = 0
for h in range(H):
    for w in range(W):
        if grid[h][w] == ".":
            continue

        sharp_counter += 1
        nearby_sharp_counter = 0

        for a, b in [(-1, 0), (1, 0), (0, -1), (0, 1)]:
            if h+a < 0 or h+a >= H or w+b < 0 or w+b >= W:
                continue
            elif grid[h+a][w+b] == "#":
                nearby_sharp_counter += 1
        
        if nearby_sharp_counter == 0:
            print("No")
            exit()

if sharp_counter == 0:
    print("No")
    exit()

print("Yes")

Submission status: Wrong Answer

Solution code:
H,W = map(int,input().split())
a = [[x for x in input()] for i in range(H)]
f = True
if a[0][0] == "#":
    if a[0][1] == "." and a[1][0] == ".":
        print("No")
        f = False
elif a[0][-1] == "#":
    if a[0][-2] == "." and a[1][-1] == ".":
        print("No")
        f = False
elif a[-1][0] == "#":
    if a[-1][1] == "." and a[-2][0] == ".":
        print("No")
        f = False
elif a[-1][-1] == "#":
    if a[-1][-2] == "." and a[-2][-1] == ".":
        print("No")
        f = False
else:
    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] == ".":
                    print("No")
                    f = False
                    break
                    break
if f:
    print("Yes")

Submission status: Wrong Answer

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

flg = False
for i in range(h):
    for j in range(w):
        if (s[i][j] == '#'):
            if (i -1) >= 0:
                flg = (flg or (s[i - 1][j] == '#'))
            if (j - 1) >= 0:
                flg = (flg or (s[i][j - 1] == '#'))
            if (j + 1) < w:
                flg = (flg or (s[i][j + 1] == '#'))
            if (i + 1) < h:
                flg = (flg or (s[i + 1][j] == '#'))
            if not(flg):
                break
    if not(flg):
        break

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

Submission status: Wrong Answer

Solution code:
H, W = list(map(int, input().split()))
S = [input() for _ in range(H)]
field = [[0 for w in range(W+2)] for h in range(H+2)]

def add(h, w):
    field[h][w + 1] += 1
    field[h + 2][w + 1] += 1
    field[h + 1][w] += 1
    field[h + 1][w + 2] += 1

for h in range(H):
    for w in range(W):
        if S[h][w] == "#":
            add(h, w)
        else:
            field[h+1][w+1] -= 10
        
res = 0
for l in field[1:W+1]:
    if 0 in l[1:H+1]:
        print("No") 
        break
else:
    print("Yes")

Submission status: Wrong Answer

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

s = []
s.append(list(("." * (w+1))))

for i in range(h):
    s.append(list(("." + input()+ ".")))

s.append(list(("." * (w+1))))
flag = False

for i in range(h-2):
    for j in range(w-1):
        if s[i+1][j+1] == '#':
            if s[i+2][j+1] == s[i][j+1] == s[i+1][j+2] == s[i+1][j]:
                flag = True
        else:
            pass


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

Submission status: Wrong Answer

Solution code:
import numpy as np
h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]
s = np.array(s)
out = "Yes"
for i in range(h):
    for j in range(w):
        if i == 0 and j == 0:
            up = s[i][j]
            down = s[i + 1][j]
            left = s[i][j]
            right = s[i][j + 1]
        elif i == 0 and j == w-1:
            up = s[i][j]
            down = s[i + 1][j]
            left = s[i][j - 1]
            right = s[i][j]
        elif i == h-1 and j == 0:
            up = s[i - 1][j]
            down = s[i][j]
            left = s[i][j]
            right = s[i][j + 1]
        elif i == h-1 and j == w-1:
            up = s[i - 1][j]
            down = s[i][j]
            left = s[i][j - 1]
            right = s[i][j]
        elif i == 0 and j != 0 and j != w-1:
            up = s[i][j]
            down = s[i + 1][j]
            left = s[i][j - 1]
            right = s[i][j + 1]
        elif i == h-1 and j != 0 and j != w-1:
            up = s[i - 1][j]
            down = s[i][j]
            left = s[i][j - 1]
            right = s[i][j + 1]
        elif j == 0 and i !=  0 and i != h-1:
            up = s[i - 1][j]
            down = s[i + 1][j]
            left = s[i][j]
            right = s[i][j + 1]
        elif j == w-1 and i != 0 and i!= h-1:
            up = s[i - 1][j]
            down = s[i + 1][j]
            left = s[i][j - 1]
            right = s[i][j]
        else:
            up = s[i-1][j]
            down = s[i+1][j]
            left = s[i][j-1]
            right = s[i][j+1]
        if s[i][j] != up and s[i][j] != down and s[i][j] != left and s[i][j] != right:
            out = "No"
print(out)

Submission status: Wrong Answer

Solution code:
import numpy as np
na = np.array

def ii():
    return int(input())


def lii():
    return list(map(int, input().split(' ')))


def lvi(N):
    l = []
    for _ in range(N):
        l.append(ii())
    return l


def lv(N):
    l = []
    for _ in range(N):
        l.append(input())
    return l


def yn(b):
    if b:
        print('yes')
    else:
        print('no')


def is_prime(q):
    q = abs(q)
    if q == 2: return True
    if q < 2 or q&1 == 0: return False
    return pow(2, q-1, q) == 1


def ok(S, i, j):
    try:
        if S[i+1][j] == '#':
            return True
    except:
        pass
    try:
        if S[i-1][j] == '#':
            return True
    except:
        pass
    try:
        if S[i][j+1] == '#':
            return True
    except:
        pass
    try:
        if S[i][j-1] == '#':
            return True
    except:
        pass

    return False


def C():

    H, W = lii()
    S = []
    for _ in range(H):
        S.append(input())

    for i, l in enumerate(S):
        for j in range(len(l)):
            if S[i][j] == '#':
                if not ok(S, i, j):
                    return False

    return True


if __name__ == '__main__':
    yn(C())

Submission status: Wrong Answer

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

mp = []

for i in range(hw[0]):
    mp.append(input())

def check(i,j,mp,hw):
    
    checker = ((i-1,j),(i+1,j),(i,j-1),(i,j+1))
    cur_flag = False
    
    for i in range(4):
        cur = checker[i]
        try: 
            if mp[cur[0]][cur[1]] == "#":
                cur_flag = True
                continue
        except IndexError:
            pass
    return cur_flag

ans = True

for i in range(hw[0]):
    for j in range(hw[1]):
        if mp[i][j] == "#":
            if check(i,j,mp,hw):
                pass
            else:
                ans = False
                break
            break
        
if ans:
    print("Yes")
else:
    print("No")