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:
import sys


def input(): return sys.stdin.readline().strip()


def solve():
    pass


def main():
    H, W = map(int, input().split())
    s = [['.' for _ in range(W+2)] for _ in range(H+2)]
    for i in range(H):
        tmp = list(input())
        for j in range(W):
            s[i+1][j+1] = tmp[j]

    #       Up Left Down Right
    d = zip([0, -1, 0, 1],
            [-1, 0, 1, 0])
    for i in range(1, H+1):
        for j in range(1, W+1):
            if s[i][j] == '.':
                continue

            count = 0
            for dx, dy in d:
                if s[i+dy][j+dx] == '.':
                    count += 1

            if count == 4:
                print('No')
                return

    print('Yes')


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
h, w = map(int, input().split())
s = [list(map(lambda x:x=="#", list(input())))for i in range(h)]
f=1
for i in range(h):
    for j in range(w):
        if 1^(s[max(0,i-1)][j] or s[i][max(0,j-1)] or s[i][min(w-1,j)] or s[min(h-1,i)][j]):f=0
print("YNeos"[f::2])

Submission status: Wrong Answer

Solution code:
h,w=map(int,input().split())
list1=[[0 for i in range(w)]for j in range(h)]
list2=[[0 for i in range(w)]for j in range(h)]
dx=[-1,-1,0,0]
dy=[0,0,-1,1]
a=0
for j in range(h):
 s=input()
 for i in range(w):
  list1[j][i]=s[i]
for j in range(h):
  for i in range(w):
   if list1[j][i]=="#":
    for k in range(4):
     xk=i+dx[k]
     yk=j+dy[k]
     if xk>=0 and xk<w and yk>=0 and yk<h:
      list2[yk][xk]+=1
for j in range(h):
  for i in range(w):
    if list1[j][i]=="#" and list2[j][i]==0:
     None
    else:
     a+=1
if a==h*w:
 print("Yes")
else:
 print("No")

Submission status: Wrong Answer

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

s = [[]*w]*h
dp = [[0]*w]*h
can = 1
for i in range(h):
    s[i] = input()

for i in range(h):
    for j in range(w):
        if(s[i][j] == "#"):
            if(i != 0 and s[i-1][j] == "#"):
                dp[i][j] += 1
            if(j != 0 and s[i][j-1] == "#"):
                dp[i][j] += 1
            if(i != h-1 and s[i+1][j] == "#"):
                dp[i][j] += 1
            if(j != w-1 and s[i][j+1] == "#"):
                dp[i][j] += 1
            if(dp[i][j] == 0):
                can = 0

print("Yes" if can == 1 else "No")

Submission status: Wrong Answer

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

s = [[]*w]*h
dp = [[0]*w]*h
can = 1
for i in range(h):
    s[i] = input()

for i in range(h):
    for j in range(w):
        if(s[i][j] == "#"):
            if(i != h-1 and s[i+1][j] == "#"):
                dp[i][j] = 1
                dp[i+1][j] = 1
            if(j != w-1 and s[i][j+1] == "#"):
                dp[i][j] = 1
                dp[i][j+1] = 1
            if(dp[i][j] == 0):
                can = 0

print("Yes" if can == 1 else "No")

Submission status: Wrong Answer

Solution code:
h,w  = map(int,input().split())
li = [(".")*(w+2)]
for i in range(h):
    li.append("."+input()+".")
li.append((".")*(w+2))
#print(li)
flag = False
dx = (-1,1)
dy = (-1,1)
for i in range(1,h+1):
    for j in range(1,w+1):
        if li[i][j] == "#":
            for k in dx:
                for l in dy:
                    if li[i+k][j] != "#" and li[i][j+l] != "#":
                        continue
                    elif li[i+k][j] == "#" or li[i][j+l] == "#":
                        flag = True
                        break
                else:
                    continue
                break
            break
if flag:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
h,w=map(int, input().split())
# 余白付け足し
s=['.'*(w+2)]
for _ in range(h):
    s.append('.'+input()+'.')
s.append('.'*(w+2))
    
# 全ての#マスにおいて、縦横のいずれかが#であればOK
for i in range(h+1):
    for j in range(w+1):
        if s[i][j]=="#":
            if s[i-1][j] == s[i+1][j] == s[i][j-1] == s[i][j+1] == ".":
                print("No")
                #exit()
print("Yes")

Submission status: Wrong Answer

Solution code:
h,w=map(int, input().split())
s=['.'*w]
for _ in range(h):
    s.append('.'+input()+'.')
s.append('.'*w)
    
# 全ての#マスにおいて、縦横のいずれかが#であればOK
for i in range(h):
    for j in range(w):
        if s[i][j]=="#":
            if s[i-1][j] == s[i+1][j] == s[i][j-1] == s[i][j+1] == ".":
                print("No")
                #exit()
print("Yes")

Submission status: Wrong Answer

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

mapping = {'.':0, '#':1}

ans = 'Yes'
for i in range(H):
    for j in range(W):
        if Ss[i][j] == '#':
            counter = 0
            
            if j>0:
                counter += mapping[Ss[i][j-1]]
            if i>0:
                counter += mapping[Ss[i-1][j]]
            if i<H-1:
                counter += mapping[Ss[i+1][j]]
            if j<W-1:
                counter += mapping[Ss[i][j+1]]
      
            if counter == 0:
                ans = 'No'
                break
        else:
        	continue
    break

print(ans)

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())
grid = ['.' * (W + 2)]
for i in range(H):
    grid.append('.' + input() + '.')
grid += ['.' * (W + 2)]
for i in range(1, H + 1):
    for j in range(1, W + 1):
        if grid[i][j] == "#":
            if not (grid[i][j + 1] == "#" or grid[i + 1][j] == "#"
                    or grid[i][j - 1] == "#" or grid[i - 1][j] == "#"):
                print('No')
print('Yes')

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())
grid = ['.' * (W + 2)]
for i in range(H):
    grid.append('.' + input() + '.')
grid += ['.' * (W + 2)]
for i in range(H):
    for j in range(W):
        if grid[i][j] == "#":
            if not (grid[i][j + 1] == "#" or grid[i + 1][j] == "#"
                    or grid[i][j - 1] == "#" or grid[i - 1][j] == "#"):
                print('No')
print('Yes')

Submission status: Wrong Answer

Solution code:
import sys

input = sys.stdin.readline


class AtCoder:
    def main(self):
        H, W = map(int, input().split())
        s = [input().rstrip() for _ in range(H)]

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

        for h in range(1, H + 1):
            for w in range(1, W + 1):
                if s[h][w] == '#':
                    cnt = 0
                    for lr, ud in (0, -1), (0, 1), (-1, 0), (1, 0):
                        if s[h + lr][w + ud] == '#':
                            cnt += 1
                    if cnt == 0:
                        print('No')
                        exit()
        print('Yes')

Submission status: Wrong Answer

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

can_paint = True
for i in range(1, h+1):
  for j in range(1, w+1):
    if pic[i][j] == "#":
      up = pic[i-1][j]
      down = pic[i+1][j]
      left = pic[i][j-1]
      right = pic[i][j+1]
      if up == "." and down == "." and left == "." and right == ".":
        can_paint = False
      
if can_paint == True:
  print("Yes")
else:
  print("No")

Submission status: Wrong Answer

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

can_paint = True
for i in range(1, h+1):
  for j in range(1, w+1):
    up = pic[i-1][j]
    down = pic[i+1][j]
    left = pic[i][j-1]
    right = pic[i][j+1]
    if up == "." and down == "." and left == "." and right == ".":
      can_paint = False
      
if can_paint == True:
  print("Yes")
else:
  print("No")

Submission status: Wrong Answer

Solution code:
x,y = map(int,input().split())
listA=[] #appendのために宣言が必要
while True:
    try:
        listA.append(list(input()))

    except:
        break;
s=0
for i in range(x):
  for j in range(y):
    if  ((listA[i][j]!=listA[max(0,i-1)][j])&(listA[i][j]!=listA[min(x-1,i+1)][j])&
    (listA[i][j]!=listA[i][max(0,j-1)])&(listA[i][j]!=listA[i][min(y-1,j+1)])):
      s+=1
if s==0:
  print('Yes')
else:
  print('No')

Submission status: Wrong Answer

Solution code:
H, W=map (int, input().split(' '))
z=[]

for i in range(H):
    z.append(list(str(input())))

#上下左右なので斜めは消す
dx = [ 0,  -1,  1,   0, ]
dy = [ 1,   0,  0,  -1, ]

for h in range(H):
    for w in range(W):
        if z[h][w] == '#': 
            p=0
            for i in range(4):
                x = w + dx[i]
                y = h + dy[i]

                if x < 0 or y <0 or x > W-1 or y >H-1:
                    continue

                print("x:"+str(x)+" y:"+str(y))
                if z[y][x]=="#":
                    p+=1
            if p==0:
                print('No')
                exit()

print('Yes')

Submission status: Wrong Answer

Solution code:
def solve():
    H,W = list(map(int, input().split()))
    S = ['.'*(W+2)]+['.'+input()+'.' for _ in range(H)]+['.'*(W+2)]
    result = 'yes'
    
    # print(S)
    
    for i in range(1,H+1):
        for j in range(1,W+1):
            if S[i][j] == '#':
                if not(S[i+1][j] == '#' or S[i-1][j] == '#' or S[i][j+1] == '#' or S[i][j-1] == '#'):
                    result = 'no'
                    break
    
    print( result )
    
solve()

Submission status: Wrong Answer

Solution code:
from sys import exit
h, w = map(int, input().split())
s = [input() for _ in range(h)]
for i in range(h):
  for j in range(w):
    if s[i][j] == '.':
      continue
    if i > 1 and s[i - 1][j] == '#':
      continue
    if i < h - 1 and s[i + 1][j] == '#':
      continue
    if j > 1 and s[i][j - 1] == '#':
      continue
    if j < w - 1 and s[i][j + 1] == '#':
      continue
    print('No')
    exit()
print('Yes')

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
h,w = map(int,input().split())
s = ['']*h
for i in range(h):
  s[i] = input()
 
black = False
for i in range(h):
  for j in range(w):
    if s[i][j] == '#':
      black = True
      if j != w - 1:
        if s[i][j + 1] == '#':
          continue
      if  j != 0:
        if s[i][j - 1] == '#':
          continue
      if i != h - 1:
        if s[i + 1][j] == '#':
          continue
      if i != 0:
        if s[i - 1][j] == '#':
          continue
      print('No')
      sys.exit()       
if black:
  print('Yes')
else:
  print('No')

Submission status: Wrong Answer

Solution code:
import sys
h,w = map(int,input().split())
s = ['']*h
for i in range(h):
  s[i] = input()
 
black = False
for i in range(h):
  for j in range(w):
    if s[i][j] == '#':
      black = True
      if j != w - 1:
        if s[i][j + 1] == '#':
          continue
      if  j != 0:
        if s[i][j - 1] == '#':
          continue
      if i != h - 1:
        if s[i + 1][j] == '#':
          continue
      if i != 0:
        if s[i - 1][j] == '#':
          continue
      else:
        print('No')
        sys.exit()
if black:
  print('Yes')
else:
  print('No')

Submission status: Wrong Answer

Solution code:
import sys
h,w = map(int,input().split())
s = ['']*h
for i in range(h):
  s[i] = input()
 
for i in range(h):
  for j in range(w):
    if s[i][j] == '#':
      if j != w - 1:
        if s[i][j + 1] == '#':
          continue
      if  j != 0:
        if s[i][j - 1] == '#':
          continue
      if i != h - 1:
        if s[i + 1][j] == '#':
          continue
      if i != 0:
        if s[i - 1][j] == '#':
          continue
      else:
        print('No')
        sys.exit()
print('Yes')

Submission status: Wrong Answer

Solution code:
h, w = map(int, input().split())
s = ["."+input()+"." for _ in range(h)]
s = ["."*(w+2)]+s+["."*(w+2)]
flag = False

for i in range(h):
    for j in range(w):
        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 = True

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

Submission status: Wrong Answer

Solution code:
h, w = map(int, input().split())
s = ["."+input()+"." for _ in range(h)]
s = ["."*(w+2)]+s+["."*(w+2)]
flag = False

for i in range(h):
    for j in range(w):
        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 = True

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

Submission status: Wrong Answer

Solution code:
h, w = list(map(int, input().split()))
s = [input() for _ in range(h)]
move = [(-1, 0), (1, 0), (0, -1), (0, 1)]
flag = 1
for i in range(h):
    for j in range(w):
        hantei = []
        if s[i][j] == "#":
            for dx, dy in move:
                if i+dx<0 or j+dy<0 or i+dx>h-1 or j+dy>w-1:
                    continue
                else:
                    hantei.append(s[i+dx][j+dy])
            if "#" not in hantei:
                flag = 0
                break

if flag:
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

Solution code:

h, w = list(map(int, input().split()))
s = [list(input()) for i in range(h)]
dir = [[-1, 0], [1, 0], [0, -1], [0, 1]]
for y in range(h):
    for x in range(w):
        can_put = True
        if s[y][x] == "#":
            for dx, dy in dir:
                cx = x + dx
                cy = y + dy
                if cx >= 0 and cx < w and cy >= 0 and cy < h:
                    if s[cy][cx] == "#":
                        can_put = True
                        break
            else:
                can_put = False
        if can_put == False:
            break
if can_put == True:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
h, w = map(int, input().split())
src = [input() for i in range(h)]
ans = []
for row in src:
    ans.append(list(row))
dxy = [(-1, 0), (0, 1), (1, 0), (0, -1)]
for y in range(h):
    for x in range(w):
        for dx, dy in dxy:
            if y + dy < 0 or y + dy > h - 1 or x + dx < 0 or x + dx > w - 1: continue
            if src[y][x] == '#' and src[y+dy][x+dx] == '#':
                ans[y][x] = 'b'
                ans[y+dy][x+dx] = 'b'

for row in ans:
    if row.count('#') > 0:
        print('No')
        exit()
    else:
        print('Yes')
        exit()

Submission status: Wrong Answer

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

ls = [list(input()) for i in range(h)]

t=False

for i in range(h):
    for j in range(w):
        if (ls[i][j]=='#'):
            for x in range(-1,2):
                for y in range(-1,2):
                    if (0<=i+x<h and 0<=j+y<w):
                        if not((x==1 and y==1) or (x==1 and y==-1) or (x==-1 and y==1) or (x==-1 and y==-1)or(x==0 and y==0)):
                      	  if(ls[i+x][j+y]=='#'):
                              t=True
                              continue
                      	  else:
                              break
                        else:
                          continue
                    else:
                      continue
        else:
          continue      
if(t):
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:

import collections
import itertools
import sys

def getint(): return int(input())
def getints(): return list(map(int, input().split()))

h,w=getints()
grid=[input() for _ in range(h)]

def check(y, x):
    if grid[y][x] == '.':
        return True
    for xx in range(x-1, x+2):
        for yy in range(y-1, y+2):
            if abs(xx - x) + abs(yy - y) != 1:
                continue
            if xx < 0 or xx >= w or yy < 0 or yy >= h:
                continue
            if grid[yy][xx] == '#':
                return True
    return False

ok = True
for i in range(h):
    for j in range(w):
        if check(i, j) == False:
            print(i, j, check(i, j))
            ok = False
            break
print("Yes" if ok else "No")

Submission status: Wrong Answer

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

drawMap=[]

i=0
while i<H:
  drawMap.append([])
  tempLine=input()
  
  j=0
  while j<W:
    drawMap[i].append(tempLine[j])
    j=j+1
  i=i+1
  
flag="Yes"

i=0
while i<H:
  j=0
  while j<W:

    #print("ij",i,j)
    if drawMap[i][j]=="#":
      tempFlag=0
      y=max([i-1,0])
      while y<i+2 and y<H:
        x=max([j-1,0])
        while x<j+2 and x<W:
          #print(i,j,y,x)
          if (x+y)%2==1  and drawMap[y][x]=="#":
            #print(i,j,y,x)
            tempFlag=1
          x=x+1
        y=y+1
      if tempFlag==0:
        flag="No"
        #print("No")
      
    j=j+1
  i=i+1

#print(drawMap)
print(flag)

Submission status: Wrong Answer

Solution code:
h,w = map(int,input().split())
s =[[i for i in input()] for j in range(h)]
for i in range(h):
	for j in range(w):
		if s[i][j]=='#':
			flag = 0
			for di in range(-1,2):
				for dj in range(-1,2):
					if di!=0 and (dj==-1 or dj==1):
						# print(1)
						continue
					if di==0 and dj ==0:
						continue
					if not (0<=i+di<h and 0<=j+dj<w):
						# print(2)
						continue
					if s[i+di][j+dj]=='#':
						flag = 1
			if flag ==0:
				print('No')
				break
		else:
			continue
		break
	else:
		continue
	break

else:
	print('Yes')

Submission status: Wrong Answer

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

def search(x,y):
    flag = 0
    if x > 0:
        if G[y][x-1] == "#":
            flag = 1
    if x < W-1:
        if G[y][x+1] == "#":
            flag = 1
    if y > 0:
        if G[y-1][x] == "#":
            flag = 1
    if y < H-1:
        if G[y+1][x] == "#":
            flag = 1
    if flag == 1:
        return True
    else:
        return False

res = 1
for i in range(H):
    for j in range(W):
        x = j
        y = i
        if G[i][j] == "#":
            if search(x,y):
                res = 1
            else:
                res = 0
                break
    else:
        break
if res:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

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

def search(x,y):
    flag = 0
    if x > 0:
        if G[y][x-1] == "#":
            flag = 1
    if x < W-1:
        if G[y][x+1] == "#":
            flag = 1
    if y > 0:
        if G[y-1][x] == "#":
            flag = 1
    if y < H-1:
        if G[y+1][x] == "#":
            flag = 1
    if flag == 1:
        return True
    else:
        return False

res = 1
for i in range(H):
    for j in range(W):
        x = j
        y = i
        if G[i][j] == "#":
            if search(x,y):
                res = 1
            else:
                res = 0
if res:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

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

def search(x,y):
    flag = 0
    if x > 0:
        if G[y][x-1] == "#":
            flag = 1
    if x < W-1:
        if G[y][x+1] == "#":
            flag = 1
    if y > 0:
        if G[y-1][x] == "#":
            flag = 1
    if y < H-1:
        if G[y+1][x] == "#":
            flag = 1
    if flag == 1:
        return True
    else:
        return False

res = 1
for i in range(H):
    for j in range(W):
        x = j
        y = i
        if search(x,y):
            res = 1
        else:
            res = 0
if res:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

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

ans = 1
for h in range(H):
    for w in range(W):
        if ans == 0:
            break
        if grid[h][w] == "#":
            if h == 0:
                if w == 0:
                    if grid[h + 1][w] == "." and grid[h][w+1] == ".":
                        ans = 0
                elif w == W - 1:
                    if grid[h + 1][w] == "." and grid[h][w-1] == ".":
                        ans = 0
                elif grid[h + 1][w] == "." and grid[h][w - 1] == "." and grid[h][w + 1] == ".":
                    ans = 0
            elif h == H - 1:
                if w == 0:
                    if grid[h - 1][w] == "." and grid[h][w+1] == ".":
                        ans = 0
                elif w == W - 1:
                    if grid[h - 1][w] == "." and grid[h][w-1] == ".":
                        ans = 0
                elif grid[h - 1][w] == "." and grid[h][w - 1] == "." and grid[h][w + 1] == ".":
                    ans = 0
            elif w == 0:
                if grid[h - 1][w] == "." and grid[h][w+1] == "."and grid[h + 1][w] == ".":
                    ans = 0
            elif w == W - 1:
                if grid[h - 1][w] == "." and grid[h][w-1] == "."and grid[h + 1][w] == ".":
                    ans = 0
            elif grid[h - 1][w] == "." and grid[h][w - 1] == "." and grid[h][w + 1] == "." and grid[h - 1][w] == ".":
                ans = 0

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

Submission status: Wrong Answer

Solution code:
h, w = map(int,input().split())
grids = []
for i in range(h):
    grids.append(input())
    
start = []
for i in range(len(grids)):
    if "#" in grids[i]:
        start = [i, grids[i].index("#")]
        break

if len(start) == 0:
    print("No")
    exit()

queue = [start]
check = [start]
ans = "No"
while len(queue) != 0:
    x, y = queue[0][0], queue[0][1]
    queue.pop(0)

    if x > 0:
        if grids[x-1][y] == "#" and [x-1, y] not in check:
            queue.append([x-1, y])
            check.append([x-1, y])
    if x < h-1:
        if grids[x+1][y] == "#" and [x+1, y] not in check:
            queue.append([x+1, y])
            check.append([x+1, y])
    if y > 0:
        if grids[x][y-1] == "#" and [x, y-1] not in check:
            queue.append([x, y-1])
            check.append([x, y-1])
    if y < w-1:
        if grids[x][y+1] == "#" and [x, y+1] not in check:
            queue.append([x, y+1])
            check.append([x, y+1])

cnt = 0
for grid in grids:
    cnt += grid.count("#")
    
if cnt == len(check):
    ans = "Yes"
print(ans)

Submission status: Wrong Answer

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

queue = [[0,0],[0,1]]
check = []
ans = "No"
while len(queue) != 0:
    x, y = queue[0][0], queue[0][1]
    queue.pop(0)

    if x > 0:
        if grids[x-1][y] == "#" and [x-1, y] not in check:
            queue.append([x-1, y])
            check.append([x-1, y])
    if x < h-1:
        if grids[x+1][y] == "#" and [x+1, y] not in check:
            queue.append([x+1, y])
            check.append([x+1, y])
    if y > 0:
        if grids[x][y-1] == "#" and [x, y-1] not in check:
            queue.append([x, y-1])
            check.append([x, y-1])
    if y < w-1:
        if grids[x][y+1] == "#" and [x, y+1] not in check:
            queue.append([x, y+1])
            check.append([x, y+1])

cnt = 0
for grid in grids:
    cnt += grid.count("#")
    
if cnt == len(check):
    ans = "Yes"
print(ans)

Submission status: Wrong Answer

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

queue = [[0,0],[0,1]]
check = []
ans = "NO"
while len(queue) != 0:
    x, y = queue[0][0], queue[0][1]
    queue.pop(0)

    if x > 0:
        if grids[x-1][y] == "#" and [x-1, y] not in check:
            queue.append([x-1, y])
            check.append([x-1, y])
    if x < h-1:
        if grids[x+1][y] == "#" and [x+1, y] not in check:
            queue.append([x+1, y])
            check.append([x+1, y])
    if y > 0:
        if grids[x][y-1] == "#" and [x, y-1] not in check:
            queue.append([x, y-1])
            check.append([x, y-1])
    if y < w-1:
        if grids[x][y+1] == "#" and [x, y+1] not in check:
            queue.append([x, y+1])
            check.append([x, y+1])

cnt = 0
for grid in grids:
    cnt += grid.count("#")
    
if cnt == len(check):
    ans = "YES"
print(ans)

Submission status: Wrong Answer

Solution code:
h,w = map(int,input().split())
li = [input() for _ in range(h)]
dx = [1,0,-1,0]
dy = [0,1,0,-1]

for i in range(h):
  for j in range(w):
    if li[i][j] == ".":
      break
    for k in range(4):
      if not(0<=i+dx[k]<h) or not(0<=j+dy[k]<w):
        continue
      else:
        if li[i+dx[k]][j+dy[k]] == "#":
          break
    else:
      print("No")
      exit()
print("Yes")

Submission status: Wrong Answer

Solution code:
import sys
h,w = map(int,input().split())
a = ["."*(w+2)]+['.'+input()+'.' for i in range(h)]+["."*(w+2)]
for i in range(h):
    for j in range(w):
        if a[i][j+1] != "#" and a[i+1][j] != "#" and a[i+1][j+2]  != "#" and a[i+2][j+1] != "#":
            print("No")
            sys.exit()
print("Yes")

Submission status: Wrong Answer

Solution code:
h,w=map(int,input().split())
s=[input() for _ in range(h)]
for i in range(h):
    for j in range(w):
        if s[i][j]=='#':
            flg=True
            if i>0:
                if s[i-1][j]=='#':
                    flg=False
                    break
            if j>0:
                if s[i][j-1]=='#':
                    flg=False
                    break
            if i<h-1:
                if s[i+1][j]=='#':
                    flg=False
                    break
            if j<w-1:
                if s[i][j+1]=='#':
                    flg=False
                    break
            if flg:
                print('No')
                exit()
print('Yes')

Submission status: Wrong Answer

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

def drow(i,j, map = map):
  if j > 0 and map[i][j-1] == "#":
    return "Yes"
  if j < W-1 and map[i][j+1] == "#":
    return "Yes"
  if i > 0 and map[i-1][j] == "#":
    return "Yes"
  if i < H -1 and map[i+1][j] == "#":
    return "Yes"
  return "No"

ans = "No"
for i in range(H):
  for j in range(W):
    if map[i][j] == "#":
      ans = drow(i,j)
      if ans == "No":
        print(ans)
        exit()
print(ans)

Submission status: Wrong Answer

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

def drow(i,j, map = map):
  if j > 0 and map[i][j-1] == ".":
    return "No"
  if j < W-1 and map[i][j+1] == ".":
    return "No"
  if i > 0 and map[i-1][j] == ".":
    return "No"
  if i < H -1 and map[i+1][j] == ".":
    return "No"
  return "Yes"

ans = "No"
for i in range(H):
  for j in range(W):
    if map[i][j] == "#":
      ans = drow(i,j)
      if ans == "No":
        break
print(ans)

Submission status: Wrong Answer

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

def drow(i,j, map = map):
  if j > 0 and map[i][j-1] == "#":
    return "Yes"
  if j < W-1 and map[i][j+1] == "#":
    return "Yes"
  if i > 0 and map[i-1][j] == "#":
    return "Yes"
  if i < H -1 and map[i+1][j] == "#":
    return "Yes"
  return "No"
    
ans = "No"
for i in range(H):
  for j in range(W):
    if map[i][j] == "#":
      ans = drow(i,j)
      if ans == "No":
        break
print(ans)

Submission status: Wrong Answer

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

def drow(i,j, map = map):
  if j > 0 and map[i][j-1] == "#":
    return "Yes"
  if j < W-1 and map[i][j+1] == "#":
    return "Yes"
  if i > 0 and map[i-1][j] == "#":
    return "Yes"
  if i < H -1 and map[i+1][j] == "#":
    return "Yes"
  return "No"
    
ans = "No"
for i in range(H):
  for j in range(W):
    if map[i][j] == "#":
      ans = drow(i,j)
      print(ans)
      if ans == "No":
        break
print(ans)