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:
h,w=map(int,input().split()) 
l = [input() for _ in range(h)]
dx = [1,-1,0,0]
dy = [0,0,1,-1]
ans = 'ans'
for i in range(h):
    for j in range(w):
        if l[i][j] =='#':
            for di in range(4):
                y = i+dx[di]
                x = j+dy[di]
                if x<0 or y<0 or x>w-1 or y>h-1:
                    continue
                else:
                    if l[y][x] !='#':
                        ans = 'No'
print(ans)

Submission status: Wrong Answer

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

mx = [0, 1, 0, -1]
my = [1, 0, -1, 0]
for i in range(h):
    for  j in range(w):
        if table[i][j] == "#":
            for k in range(4):
                tx, ty = j + mx[k], i + my[k]
                if 0 <= tx < w and 0 <= ty < h and table[ty][tx] == "#":
                    break
                else:
                    print("No")
                    exit(0)
print("Yes")

Submission status: Wrong Answer

Solution code:
h, w = map(int, input().split())
table = [list(input()) for _ in range(h)]
ans = 'Yes'
mx = [0, 1, 0, -1]
my = [1, 0, -1, 0]

for i in range(h):
    for j in range(w):
        if table[i][j] == "#":
            for k in range(4):
                tx, ty = j + mx[k], i + my[k]
                if 0 <= tx < w and 0 <= ty < h and table[ty][tx] == "#":
                    break
                else:
                    ans='No'

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import copy
import math
import itertools
import numpy as np

H,W = [int(c) for c in input().split()]
s = [list(input()) for c in range(H)]
a = [[1 for c in range(W)] for d in range(H)]
b = [[0 for c in range(W)] for d in range(H)]

if H == 1 and W == 1:
    print("Yes")
    sys.exit(0)

for i in range(H):
    for j in range(W):
        if s[i][j]=="#":
            if i-1 > 0:
                if s[i-1][j] == "#":
                    a[i][j]=0
            if j-1 > 0:
                if s[i][j-1] == "#":
                    a[i][j]=0
            if j+1 < W:
                if s[i][j+1] == "#":
                    a[i][j]=0
            if i+1 < H:
                if s[i+1][j] == "#":
                    a[i][j]=0
        else:
            a[i][j]=0
        if a[i][j] == 1:
            print("No")
            sys.exit(0)

print("Yes")

Submission status: Wrong Answer

Solution code:
import sys
import copy
import math
import itertools
import numpy as np

H,W = [int(c) for c in input().split()]
s = [list(input()) for c in range(H)]
a = [[1 for c in range(W)] for d in range(H)]
b = [[0 for c in range(W)] for d in range(H)]
for i in range(H):
    for j in range(W):
        if s[i][j]=="#":
            if i-1 > 0:
                if s[i-1][j] == "#":
                    a[i][j]=0
            if j-1 > 0:
                if s[i][j-1] == "#":
                    a[i][j]=0
            if j+1 < W:
                if s[i][j+1] == "#":
                    a[i][j]=0
            if i+1 < H:
                if s[i+1][j] == "#":
                    a[i][j]=0
        else:
            a[i][j]=0
        if a[i][j] == 1:
            print("No")
            sys.exit(0)

print("Yes")

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), (-1, 0), (0, 1), (0, -1)]
for x in range(h):
        for y in range(w):
                if src[x][y] == ".":
                        continue
                if src[x][y] == "#":
                        for dx, dy in dxy:
                                if x + dx < 0 or x + dx > h -1 or y + dy < 0 or y + dy > w - 1:
                                        continue
                                if src[x + dx][y + dy] == "#":
                                        break
                        
                        print("No")
                        exit()

print("Yes")

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

flag = 0
dxy = [(1, 0), (-1, 0), (0, 1), (0, -1)]
for x in range(h):
        for y in range(w):
                if src[x][y] == ".":
                        continue
                else:
                        for dx, dy in dxy:
                                if x + dx < 0 or x + dx > h -1 or y + dy < 0 or y + dy > w - 1:
                                        continue
                                if src[x + dx][y + dy] == "#":
                                        flag = 1
                                        break
                        if flag == 0:
                                print("No")
                                exit()

print("Yes")

Submission status: Wrong Answer

Solution code:
H,W=map(int,input().split())
List = [list(input()) for i in range(H)]
res = "Yes"
flag = True

def checkAround(ListX,i,j):
  if i == 0 and j ==0:
    if List[i+1][j] == "#" or List[i][j+1] == "#":
      return True
    else: 
      return False
  elif i == 0 and j !=0 and j != W-1:
    if List[i+1][j] == "#" or List[i][j-1] == "#" or List[i][j+1] == "#":
      return True
    else: 
      return False
  elif i == 0 and j == W-1:
    if List[i+1][j] == "#" or List[i][j-1] == "#":
      return True
    else: 
      return False
  elif i != 0 and i != H-1 and j == 0:
    if List[i+1][j] == "#" or List[i-1][j] == "#" or List[i][j+1] == "#":
      return True
    else: 
      return False
  elif i == H-1 and j == W-1:
    if List[i-1][j] == "#" or List[i][j-1] == "#":
      return True
    else: 
      return False
  elif i == H-1 and j !=0 and j != W-1:
    if List[i-1][j] == "#" or List[i][j+1] == "#" or List[i][j-1] == "#":
      return True
    else: 
      return False
  elif i == H-1 and j == 0:
    if List[i-1][j] == "#" or List[i][j-1] == "#":
      return True
    else: 
      return False
  elif i != 0 and i != H-1 and j == W-1:
    if List[i+1][j] == "#" or List[i-1][j] == "#" or List[i][j-1] == "#":
      return True
    else: 
      return False
  else:
    if List[i+1][j] == "#" or List[i-1][j] == "#" or List[i][j-1] == "#" or List[i][j+1] == "#":
      return True
    else: 
      return False

for k in range(H):
  for l in range(W):
    if List[k][l] == ".":
      pass
    else:
      flag = checkAround(List,k,l)
      if not flag:
        print(k,l)
        res = "No"
        break
  if not flag:
    break
print(res)

Submission status: Wrong Answer

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

import sys
for j in range(H):
    for i in range(W):
        if s[j][i] =='#':
            if j+1<W and i+1<H and j-1<=0 and i-1<=0:
                if (s[j+1][i]=='#' or s[j][i+1]=='#'):
                    continue
                if s[j+1][i]!='#' or s[j][i+1]!='#' or s[j-1][i]!='#' or s[j][i-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)]

import sys
for j in range(H):
    for i in range(W):
        if s[j][i] =='#':
            if j+1<W and i+1<H and j-1<0 and i-1<0:
                if (s[j+1][i]=='#' or s[j][i+1]=='#'):
                    continue
                if s[j+1][i]!='#' or s[j][i+1]!='#' or s[j-1][i]!='#' or s[j][i-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)]

import sys
for j in range(H):
    print("j={}".format(j))
    for i in range(W):
        print(i)
        print('s[{}][{}]={}'.format(j,i,s[j][i]))
        if s[j][i] =='#':
            if j+1<W and i+1<H and j-1<0 and i-1<0:
                if (s[j+1][i]=='#' or s[j][i+1]=='#'):
                    continue
                if s[j+1][i]!='#' or s[j][i+1]!='#' or s[j-1][i]!='#' or s[j][i-1]!='#':
                    print('No')
                    sys.exit()
print('Yes')

Submission status: Wrong Answer

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

ans = True
for i in range(h):
    for j in range(w):
        if s[i][j] == "#":
            u_r_d_l = [(-1, 0), (0, 1), (1, 0), (0, -1)]
            if i == 0:
                u_r_d_l[0] = (0, 0)
            if i == h - 1:
                u_r_d_l[2] = (0, 0)
            if j == 0:
                u_r_d_l[3] = (0, 0)
            if j == w - 1:
                u_r_d_l[1] = (0, 0)
            for k in u_r_d_l:
                if k != (0, 0):
                    if s[i + k[0]][j + k[1]] == "#":
                        ans = True
                        break
            else:
                ans = False


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

Submission status: Wrong Answer

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

ans = True
for i in range(h):
    for j in range(w):
        if s[i][j] == "#":
            u_r_d_l = [(-1, 0), (0, 1), (1, 0), (0, -1)]
            if i == 0:
                u_r_d_l[0] = (0, 0)
            if i == h - 1:
                u_r_d_l[2] = (0, 0)
            if j == 0:
                u_r_d_l[3] = (0, 0)
            if j == w - 1:
                u_r_d_l[1] = (0, 0)
            for k in u_r_d_l:
                if k != (0, 0):
                    if s[i + k[0]][j + k[1]] == "#":
                        ans = True
                        break
                    else:
                        ans = False


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

Submission status: Wrong Answer

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

ans = True
for i in range(h):
    for j in range(w):
        if s[i][j] == "#":
            u_r_d_l = [(-1, 0), (0, 1), (1, 0), (0, -1)]
            if i == 0:
                u_r_d_l[0] = (0, 0)
            elif i == h - 1:
                u_r_d_l[2] = (0, 0)
            if j == 0:
                u_r_d_l[3] = (0, 0)
            elif j == w - 1:
                u_r_d_l[1] = (0, 0)
            for k in u_r_d_l:
                if k != (0, 0):
                    if s[i + k[0]][j + k[1]] == "#":
                        ans = True
                        break
            else:
                ans = False


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

Submission status: Wrong Answer

Solution code:
def color(s):
    col = 'black'
    if s == '.':
        col = 'white'
    return col


def main():
    h, w = map(int, input().split())
    s_lst = list(str(input()) for _ in range(h))
    sw_lst = []
    for i in range(h):
        tmp_lst = []
        for j in range(w):
            tmp_lst.append(s_lst[i][j])
        sw_lst.append(tmp_lst)

    flag = True
    black_count = 0

    for i in range(h):
        for j in range(w):

            surroundings = []
            if color(sw_lst[i][j]) == 'black':
                black_count += 1
                if i != 0:
                    surroundings.append(color(sw_lst[i - 1][j]))
                if i != h - 1:
                    surroundings.append(color(sw_lst[i + 1][j]))
                if j != 0:
                    surroundings.append(color(sw_lst[i][j - 1]))
                if j != w - 1:
                    surroundings.append(color(sw_lst[i][j + 1]))

                if 'black' not in surroundings:
                    flag = False

    if black_count < 2:
        flag = False

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


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

def judge(i,j,s,H,W):
    find=False
    dh=[0,1,0,-1]
    dw=[1,0,-1,0]
    for n in range(4):
        if 0<=i+dh[n]<=H-1 and 0<=j+dw[n]<=W-1:
            if s[i+dh[n]][j+dw[n]]=="#":
                find=True
                break
    return find

def main():
    end=False
    for i in range(H):
        if end==True:
            break
        for j in range(W):
            if s[i][j]=="#":
                if judge(i,j,s,H,W):
                    print("Yes")
                    end=True
                    break
    if end==False:
        print("No")
if __name__=="__main__":
	main()

Submission status: Wrong Answer

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

def judge(i,j,s,H,W):
    find=False
    dh=[0,1,0,-1]
    dw=[1,0,-1,0]
    for n in range(4):
        if 0<=i+dh[n]<=H-1 and 0<=j+dw[n]<=W-1:
            if s[i+dh[n]][j+dw[n]]=="#":
                find=True
                break
    return find

def main():
    end=False
    for i in range(H):
        if end==True:
            break
        for j in range(W):
            if s[i][j]=="#":
                if judge(i,j,s,H,W):
                    print("Yes")
                    end=True
                    break
    else:
        print("No")
if __name__=="__main__":
	main()

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())
S = [input() for _ in range(H)]
t = [(0, 1), (0, -1), (1, 0), (-1, 0)]
ans = False
for h in range(H):
    for w in range(W):
        if S[h][w] == '#':
            for h1, w1 in t:
                h2 = h1 + h
                w2 = w1 + w
                if H <= h2 or W <= w2 or h2 < 0 or w2 < 0:
                    continue
                if S[h2][w2] == '#':
                    ans = True
                    break
            else:
                ans = False
print('Yes' if ans else 'No')

Submission status: Wrong Answer

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

dj = [-1, 0, 0, 1]
dk = [0, -1, 1, 0]
for j in range(H):
  for k in range(W):
    judge = 'No'
    if S[j][k] == '.':
      judge = 'Yes'
    if S[j][k] == '#':
      for d in range(4):
        if 0 <= j+dj[d] <= H-1:
          if 0 <= k+dk[d] <= W-1:
            if S[j+dj[d]][k+dk[d]] == '#':
              judge = 'Yes'
      if judge == 'No':
        exit
  if judge == 'No':
    exit
if judge == 'No':
  exit
print(judge)

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())
S = []
for h in range(H):
    S_h = list(input())
    S.append(S_h)

d = [-1, 1]
ls = []
for h in range(H):
    for w in range(W):
        if S[h][w] == '#':
            for i in range(2):
                for j in range(2):
                    hs = h + d[i]
                    ws = w + d[j]
                    if 0 <= hs < H and 0 <= ws < W:
                        ls.append(S[hs][w])
                        ls.append(S[h][ws])

if '#' in ls:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

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

dx=[1,1,1,0,0,-1,-1,-1]
dy=[0,1,-1,1,-1,1,0,-1]

for i in range(1,h+1):
  for j in range(1,w+1):
    if lst[i][j]=='#':
      judge=False
      for k in range(8):
        nx=i+dx[k]
        ny=j+dy[k]
        if lst[nx][ny]=='#':
          judge=True
          
      if judge==False:
        print('No')
        exit()
        
print('Yes')

Submission status: Wrong Answer

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

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

        if not flag:
            print('No')
            exit()


print('Yes')

Submission status: Wrong Answer

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

for i in range(h):
    flag = False
    for j in range(w):
        if s[i][j] == '#':
            if i != 0:
                if s[i-1][j] == '#':
                    break
            if j != 0:
                if s[i][j-1] == '#':
                    break
            if i != h-1:
                if s[i+1][j] == '#':
                    break
            if j != w-1:
                if s[i][j+1] == '#':
                    break
                else:
                    print('No')
                    exit()
        else:
            flag = True
            break

print('Yes')

Submission status: Wrong Answer

Solution code:
H,W=map(int,input().split())
L=[[0 for i in range(W)] for j in range(H)]
for i in range(H):
  L1=list(input())
  L[i]=L1
L = [["."] + i + ["."] for i in L]
L = [["." for i in range(W+2)]] + L + [["." for i in range(W+2)]]
for i in range(H+2):
  for j in range(W+2):
    if L[i][j]=="#":
      if L[i][j+1]==L[i][j-1]==L[i+1][j-1]==L[i-1][j]==".":
        print("No")
        exit()
print("Yes")

Submission status: Wrong Answer

Solution code:
h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]
f = True
for i in range(h):
    for j in range(w):
        if s[i][j] == "#":
            dx = [0]
            dy = [0]
            if i != 0:
                dx.append(-1)
            if i != h - 1:
                dx.append(1)
            if j != 0:
                dy.append(-1)
            if j != w - 1:
                dy.append(1)
            ff = False
            for x in dx:
                for y in dy:
                    if abs(x) == abs(y):
                        continue
                    ff |= (s[i + x][j + y] == "#")
            f &= ff

print("YES" if f else "NO")

Submission status: Wrong Answer

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

ans = "Yes"
for i in range(1,H+1):
    for j in range(1,W+1):
        if S[i][j] == "#":
            UDLR = [S[i-1][j], S[i+1][j], S[i][j-1], S[i][j+1]]
            if "#" in UDLR:
                pass
            else:
                ans = "No"
                break
    else:
        break

print(ans)

Submission status: Wrong Answer

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

area = [["." for _ in range(W+2)]]
for _ in range(H):
    line = [d for d in ("."+input()+".")]
    area.append(line)
area.append(["." for _ in range(W+2)])
    
def distinct(x,y):
    if area[y+1][x] == "#" or area[y-1][x] == "#" or \
        area[y][x+1] == "#" or area[y][x-1] == "#":
        return 0
    else:
        return 1
    
flg = 0
for y in range(1,H+1):
    for x in range(1,W+1):
        if distinct(x,y) == 1:
            flg = 1
            break
    if flg == 1:
        break

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

Submission status: Wrong Answer

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

ch=0
ch1=0

for x in range(h):
  for y in range(w):
    b=a[x][y]
    if b=='#':
      if 0<=x-1<=h-1 and a[x-1][y]=='#':
        ch+=1
      if 0<=x+1<=h-1 and a[x+1][y]=='#':
        ch+=1
      if 0<=y-1<=w-1 and a[x][y-1]=='#':
        ch+=1
      if 0<=y+1<=w-1 and a[x][y+1]=='#':
        ch+=1
      
      if ch==0:
        ch1+=1
   
  
if ch1==0:
  print('Yes')
else:
  print('No')

Submission status: Wrong Answer

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

xy=((-1,0),(1,0),(0,-1),(0,1))
S=[]
S.append("."*(W+2))
for i in range(H):
    S.append("."+input()+".")

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

for i in range(1,H+1):
    for j in range(1,W+1):
        if S[i][j]==".":
            ans=True
            continue
        ans=False
        for x,y in xy:
            if S[i+x][j+y]=="#":
                ans=True
                break

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

Submission status: Wrong Answer

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

xy=((-1,0),(-1,0),(1,0),(0,1))
S=[]
S.append("."*(W+2))
for i in range(H):
    S.append("."+input()+".")

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

for i in range(1,H+1):
    for j in range(1,W+1):
        if S[i][j]==".":
            ans=True
            continue
        ans=False
        for x,y in xy:
            if S[i+x][j+y]=="#":
                ans=True
                break

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

Submission status: Wrong Answer

Solution code:
import numpy as np

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

s=np.zeros((H+2,W+2),dtype=int)
s1=s
s2=s
s3=s
s4=s

for i in range(H):
    s0=input()
    for j in range(W):
        if s0[j]==".":
            num=0
        elif s0[j]=="#":
            num=1
        
        s[i+1][j+1]=num
        s1[i+1][j]=num
        s2[i][j+1]=num
        s3[i+1][j+2]=num
        s4[i+2][j+1]=num
        
s=s+s1+s2+s3+s4
ans_s=s[1:H+1,1:W+1]

ans=np.count_nonzero(ans_s==1)


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

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())
arr = [input() for _ in range(H)]
if arr[0][0]=='.' and arr[0][-1]=='.' and arr[-1][0]=='.' and arr[-1][-1]=='.':
    print('Yes')

else:
    print('No')

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())
arr = [input() for _ in range(H)]
if arr[0][0]=='.' and arr[0][-1]=='.' and arr[-1][0]=='.' and arr[-1][-1]=='.':
    print('NO')

else:
    print('YES')

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())
arr = [input() for _ in range(H)]
if arr[0][0]=='.' and arr[0][-1]=='.' and arr[-1][0]=='.' and arr[-1][-1]=='.':
    print('YES')

else:
    print('NO')

Submission status: Wrong Answer

Solution code:
import sys
h, w = map(int, input().split())
l = [list(input()) for i in range(h)]
for i in range(h):
  l[i] = ["."] + l[i] + ["."]
l = [["." for i in range(w+2)]] + l + [["." for i in range(w+2)]]
for i in range(1, h+1):
  for j in range(1, w+1):
    if "#" not in [l[i-1][j], l[i][j-1], l[i][j+1], l[i+1][j]]:
      print("No")
      sys.exit()
print("Yes")

Submission status: Wrong Answer

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

grid = []
for _ in range(h):
    grid.append(list(input()))

dx=[-1,0,0,1]
dy=[0,-1,1,0]


for i in range(h):
    for j in range(w):
        flag=False
        if grid[i][j]==".":
            continue

        for x,y in zip(dx,dy):
            if i+x<0 or i+x>h-1 or j+y<0 or j+y>w-1:
                continue
            if grid[i+x][j+y]=="#":
                flag=True
                break

        if not flag:
            print("NO")
            exit()

print("YES")

Submission status: Wrong Answer

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

s = [list(input()) for y in range(H)]

for y in range(H):
    for x in range(W):
        if s[y][x]=="#":
            enable = False
            if x-1>0 and s[y][x-1]=="#":
                enable=True
            if x+1<W and s[y][x+1]=="#":
                enable=True
            if y-1>0 and s[y-1][x]=="#":
                enable=True
            if y+1<H and s[y+1][x]=="#":
                enable=True
            if enable==False:
                print("No")
                exit()
print("Yes")

Submission status: Wrong Answer

Solution code:
import sys

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

ans = "Yes"
for i in range(h):
    for j in range(w):
        if p[i][j] != "#":
            continue
        _ = False
        # x(j):-1
        if j-1 > 0 and p[i][j-1] == "#":
            _ = True
        # x:+1
        if j+1 < w and p[i][j+1] == "#":
            _ = True
        # y(i):-1
        if i-1 > 0 and p[i-1][j] == "#":
            _ = True
        # y:+1
        if i+1 < h and p[i+1][j] == "#":
            _ = True
        if _ is False:
            ans = "No"
            print(ans)
            sys.exit()
print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8

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

S = []
for i in range(H):
    tmp = input()
    S.append(list(tmp))


def eight_math_index(i, j, H, W):
    result = [(i-1, j-1), (i-1, j), (i-1, j+1),
              (i, j - 1), (i, j), (i, j + 1),
              (i + 1, j - 1), (i + 1, j), (i + 1, j + 1)]
    return list(filter(lambda x: (0 <= x[0] <= (H-1)) and (0 <= x[1] <= (W-1)), result))


for i in range(H):
    for j in range(W):
        if S[i][j] == "#":
            eight = eight_math_index(i, j, H, W)
            shuui_kuro_kazu = 0
            for (k, l) in eight:
                if S[k][l] == "#":
                    shuui_kuro_kazu += 1
            if shuui_kuro_kazu == 0:
                print("No")
                exit(0)

print("Yes")

Submission status: Wrong Answer

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

j = True
for h in range(H):
    for w in range(W):
        if l[h][w] == "#":
            j = False
            if h != 0:
                if l[h - 1][w] == "#":
                    j = True
            if h != H - 1:
                if l[h + 1][w] == "#":
                    j = True
            if w != 0:
                if l[h][w - 1] == "#":
                    j = True
            if w != W - 1:
                if l[h][w + 1] == "#":
                    j = True
            if not j:
                break
if j:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
# C - Grid Repainting 2
from collections import deque

H, W = map(int, input().split())
grid = [[''] * W for _ in range(H)]
for i in range(H):
    grid[i] = list(str(input()))

d = deque()
ans = 'Yes'
for i in range(H):
    for j in range(W):
        if grid[i][j] == '.':
            continue
        d.append((i, j))
        grid[i][j] = '.'
        tmp = 1
        while d:
            p, q = d.popleft()
            for x, y in ((0, 1), (1, 0), (1, 0), (0, -1)):
                nx = p+x
                ny = q+y
                if nx < 0 or nx >= H or ny < 0 or ny >= W:
                    continue
                if grid[nx][ny] == '.':
                    continue
                d.append((nx, ny))
                grid[nx][ny] = '.'
                tmp += 1
        if tmp == 1:
            ans = 'No'
            break
    else:
        continue
    break
print(ans)

Submission status: Wrong Answer

Solution code:
h,w=map(int,input().split())
s=["."*(w+2)]
for i in range(h):s.append("."+input()+".")
s.append("."*(w+2))
ans="Yes"
for i in range(1,h+1):
  for j in range(1,w+1):
    if s[i-1][j]+s[i+1][j]+s[i][j-1]+s[i][j+1]=="....":ans="No"
print(ans)

Submission status: Wrong Answer

Solution code:
H,W=map(int,input().split())
zu=["."*(W+2)]

for i in range(H):
  zu.append("."+input()+".")

zu.append(zu[0])
#print(zu)

for h in range(1,H+2):
    for w in range(1,W+2):
        if zu[h][w]=="#":
          if zu[h-1][w]==".":
            if zu[h][w-1]==".":
              if zu[h+1][w]==".":
                if zu[h][w+1]==".":
                  print("No")
   
    else:
        continue
    break

else:
  print("Yes")
  
#if zu[h-1][w]=="." and zu[h][w-1]=="." and zu[h+1][w]=="." and zu[h][w+1]==".":

Submission status: Wrong Answer

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

for h in range(H):
    for w in range(W):
        if s[h][w] == '#':
            for dx, dy in ([-1, 0], [0, -1], [1, 0], [0, 1]):
                x = h + dx
                y = w + dy
                if x<0 or x>=H:
                    continue
                if y<0 or y>=W:
                    continue
                if s[x][y] == '#':
                    flag = True
                    break

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

Submission status: Wrong Answer

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

for h in range(H):
    for w in range(W):
        if s[h][w] == '.':
            continue
        for dx, dy in ([-1, 0], [0, -1], [1, 0], [0, 1]):
            x = h + dx
            y = h + dy
            if x<0 or x>=H:
                continue
            if y<0 or y>=W:
                continue
            if s[x][y] == '#':
                flag = True
                break

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

Submission status: Wrong Answer

Solution code:
import itertools

H, W = map(int, input().split())
s = [input() for h in range(H)]
judge = True

for h in range(H):
    for w in range(W):
        flag = {(-1,0):True, (0,-1):True, (1,0):True, (0,1):True}
        if s[h][w] == '.':
            continue
        for dx, dy in itertools.permutations([-1, 0], 2):
            x = h + dx
            y = h + dy
            if x<0 or x>=H:
                continue
            if y<0 or y>=W:
                continue
            if s[x][y] == '.':
                flag[(dx,dy)] = False
        for dx, dy in itertools.permutations([1, 0], 2):
            x = h + dx
            y = h + dy
            if x<0 or x>=H:
                continue
            if y<0 or y>=W:
                continue
            if s[x][y] == '.':
                flag[(dx,dy)] = False
        if flag[(-1,0)] or flag[(0,-1)] or flag[(1,0)] or flag[(0,1)]:
            None
        else:
            judge = False
            break

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