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())
g = [input() for i in range(h)]

xi = [1,0,-1,0]
yi = [0,-1,0,1]
flag = True

for s in range(h):
    for t in range(w):
        if g[s][t] == '#':
            for u in range(4):
                if 0 <= s+xi[u] < h and 0 <= t+yi[u] < w and g[s+xi[u]][t+yi[u]] == '#':
                    break
                if u == 3:
                    flag = False
                    break
        else:
            continue
        break 
    if flag == False:
        break

                

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

Submission status: Wrong Answer

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

xi = [1,0,-1,0]
yi = [0,-1,0,1]
flag = True

for s in range(h):
    for t in range(w):
        if g[s][t] == '#':
            for u in range(4):
                if 0 <= s+xi[u] < h and 0 <= t+yi[u] < w and g[s+xi[u]][t+yi[u]] == '#':
                    break
                if u == 3:
                    flag = False
                    break
        else:
            continue
        break
    if flag == False:
        break

                

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

Submission status: Wrong Answer

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

xi = [1,0,-1,0]
yi = [0,-1,0,1]
flag = True

for s in range(h):
    for t in range(w):
        if g[s][t] == '#':
            for u in range(4):
                if 0 <= s+xi[u] < h and 0 <= t+yi[u] < w and g[s+xi[u]][t+yi[u]] == '#':
                    break
                if u == 3:
                    flag = False
                    break
        else:
            continue
        break
    if flag == False:
        break

                

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

Submission status: Wrong Answer

Solution code:
# coding: utf-8

# https://atcoder.jp/contests/abc096/tasks/abc096_c
# 13:17-13:33


def main():
    H, W = map(int, input().split())
    s = [None] * (H+2)
    s[0] = [-1] * (W+2)
    s[-1] = [-1] * (W+2)
    for i in range(1, H+1):
        s[i] = [None] * (W+2)
        s[i][0] = -1
        s[i][-1] = -1
        for j, bw in enumerate(input()):
            s[i][j+1] = 1 if bw == "#" else -1
    
    if H == 1 and W == 1 and s[1][1] == 1:
        return "Yes"
    
    for i in range(1, H+1):
        for j in range(1, W+1):
            if s[i][j] == 1:
                if sum([x for row in s[i-1:i+2] for x in row[j-1:j+2]]) == -7:
                    return "No"
    
    return "Yes"


print(main())

Submission status: Wrong Answer

Solution code:
# coding: utf-8

# https://atcoder.jp/contests/abc096/tasks/abc096_c
# 13:17-13:33


def main():
    H, W = map(int, input().split())
    s = [None] * (H+2)
    s[0] = [-1] * (W+2)
    s[-1] = [-1] * (W+2)
    for i in range(1, H+1):
        s[i] = [None] * (W+2)
        s[i][0] = -1
        s[i][-1] = -1
        for j, bw in enumerate(input()):
            s[i][j+1] = 1 if bw == "#" else -1
    
    for i in range(1, H+1):
        for j in range(1, W+1):
            if s[i][j] == 1:
                if sum([x for row in s[i-1:i+2] for x in row[j-1:j+2]]) == -7:
                    print(i, j)
                    return "No"
    
    return "Yes"


print(main())

Submission status: Wrong Answer

Solution code:
h,w=map(int,input().split())
s=[list(input()) for i in range(h)]
flag=True
count=0
for i in range(h):
  if flag==False:
    break
  for j in range(w):
    if flag==False:
      break
    if s[i][j]=="#":
      if flag and i>0 and s[i-1][j]!="#":
        flag=False
      elif flag and i>0 and s[i-1][j]=="#":
        flag=True
        
      if flag and i<(h-1) and s[i+1][j]!="#":
        flag=False
      elif flag and i<(h-1) and s[i+1][j]=="#":
        flag=True
        
      if flag and j>0 and s[i][j-1]!="#":
        flag=False
      elif flag and j>0 and s[i][j-1]=="#":
        flag=True
        
      if flag and j<(w-1) and s[i][j+1]!="#":
        flag=False
      elif flag and j<(w-1) and s[i][j+1]=="#":
        flag=True
    else:
      count+=1
        
if h==1 and w==1:
  if s[0][0]=="#":
    flag=False
    
if count==(h*w):
  flag=True
  
if flag:
  print("Yes")
else:
  print("No")

Submission status: Wrong Answer

Solution code:
h,w=map(int,input().split())
s=[list(input()) for i in range(h)]
flag=True
count=0
flag2=True
for i in range(h):
  if flag==False:
    break
  for j in range(w):
    flag2=False
    if s[i][j]=="#":
      if i>0 and s[i-1][j]!="#":
        flag=False
      elif i>0 and s[i-1][j]=="#":
        flag2=True
        
      if i<(h-1) and s[i+1][j]!="#":
        flag=False
      elif i<(h-1) and s[i+1][j]=="#":
        flag2=True
        
      if j>0 and s[i][j-1]!="#":
        flag=False
      elif j>0 and s[i][j-1]=="#":
        flag2=True
        
      if j<(w-1) and s[i][j+1]!="#":
        flag=False
      elif j<(w-1) and s[i][j+1]=="#":
        flag2=True
      if flag2:
        flag=True
    else:
      count+=1
        
if h==1 and w==1:
  if s[0][0]=="#":
    flag=False
    
if count==(h*w):
  flag=True
  
if flag:
  print("Yes")
else:
  print("No")

Submission status: Wrong Answer

Solution code:
h,w=map(int,input().split())
s=[list(input()) for i in range(h)]
flag=True
count=0
for i in range(h):
  if flag==False:
    break
  for j in range(w):
    if s[i][j]=="#":
      if i>0 and s[i-1][j]!="#":
        flag=False
      elif i>0 and s[i-1][j]=="#":
        flag=True
        
      if i<(h-1) and s[i+1][j]!="#":
        flag=False
      elif i<(h-1) and s[i+1][j]=="#":
        flag=True
        
      if j>0 and s[i][j-1]!="#":
        flag=False
      elif j>0 and s[i][j-1]=="#":
        flag=True
        
      if j<(w-1) and s[i][j+1]!="#":
        flag=False
      elif j<(w-1) and s[i][j+1]=="#":
        flag=True
    else:
      count+=1
        
if h==1 and w==1:
  if s[0][0]=="#":
    flag=False
    
if count==(h*w):
  flag=True
  
if flag:
  print("Yes")
else:
  print("No")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
h,w=map(int,input().split())
s=[list(input()) for i in range(h)]
flag=True
count=0
for i in range(h):
  for j in range(w):
    if s[i][j]=="#":
      if i>0 and s[i-1][j]!="#":
        flag=False
      elif i>0 and s[i-1][j]=="#":
        flag=True
        break
        
      if i<(h-1) and s[i+1][j]!="#":
        flag=False
      elif i<(h-1) and s[i+1][j]=="#":
        flag=True
        break
        
      if j>0 and s[i][j-1]!="#":
        flag=False
      elif j>0 and s[i][j-1]=="#":
        flag=True
        break
        
      if j<(w-1) and s[i][j+1]!="#":
        flag=False
      elif j<(w-1) and s[i][j+1]=="#":
        flag=True
        break
    else:
      count+=1
        
if h==1 and w==1:
  if s[0][0]=="#":
    flag=False
    
if count==(h*w):
  flag=True
  
if flag:
  print("Yes")
else:
  print("No")

Submission status: Wrong Answer

Solution code:
h,w=map(int,input().split())
s=[list(input()) for i in range(h)]
flag=True
count=0
for i in range(h):
  if flag==False:
    break
  for j in range(w):
    if s[i][j]=="#":
      if i>0 and s[i-1][j]!="#":
        flag=False
      elif i>0 and s[i-1][j]=="#":
        flag=True
        break
        
      if i<(h-1) and s[i+1][j]!="#":
        flag=False
      elif i<(h-1) and s[i+1][j]=="#":
        flag=True
        break
        
      if j>0 and s[i][j-1]!="#":
        flag=False
      elif j>0 and s[i][j-1]=="#":
        flag=True
        break
        
      if j<(w-1) and s[i][j+1]!="#":
        flag=False
      elif j<(w-1) and s[i][j+1]=="#":
        flag=True
        break
    else:
      count+=1
        
if h==1 and w==1:
  if s[0][0]=="#":
    flag=False
    
if count==(h*w):
  flag=True
  
if flag:
  print("Yes")
else:
  print("No")

Submission status: Wrong Answer

Solution code:
h,w=map(int,input().split())
s=[list(input()) for i in range(h)]
flag=True
count=0
for i in range(h):
  if flag==False:
    break
  for j in range(w):
    if s[i][j]=="#":
      if i!=0 and s[i-1][j]!="#":
        flag=False
      elif i!=0 and s[i-1][j]=="#":
        flag=True
        break
        
      if i!=(h-1) and s[i+1][j]!="#":
        flag=False
      elif i!=(h-1) and s[i+1][j]=="#":
        flag=True
        break
        
      if j!=0 and s[i][j-1]!="#":
        flag=False
      elif j!=0 and s[i][j-1]=="#":
        flag=True
        break
        
      if j!=(w-1) and s[i][j+1]!="#":
        flag=False
      elif j!=(w-1) and s[i][j+1]=="#":
        flag=True
        break
    else:
      count+=1
        
if h==1 and w==1:
  if s[0][0]=="#":
    flag=False
    
if count==(h*w):
  flag=True
  
if flag:
  print("Yes")
else:
  print("No")

Submission status: Wrong Answer

Solution code:
h,w=map(int,input().split())
s=[list(input()) for i in range(h)]
flag=True
count=0
if h==1 and w==1:
  flag=False
for i in range(h):
  if flag==False:
    break
  for j in range(w):
    if s[i][j]=="#":
      if i!=0 and s[i-1][j]!="#":
        flag=False
      elif i!=0 and s[i-1][j]=="#":
        flag=True
        break
        
      if i!=(h-1) and s[i+1][j]!="#":
        flag=False
      elif i!=(h-1) and s[i+1][j]=="#":
        flag=True
        break
        
      if j!=0 and s[i][j-1]!="#":
        flag=False
      elif j!=0 and s[i][j-1]=="#":
        flag=True
        break
        
      if j!=(w-1) and s[i][j+1]!="#":
        flag=False
      elif j!=(w-1) and s[i][j+1]=="#":
        flag=True
        break
    else:
      count+=1
        
if count==(h*w):
  flag=True
if h==1 and w==1:
  if s[0][0]==".":
    flag=True
  else:
    flag=False
if flag:
  print("Yes")
else:
  print("No")

Submission status: Wrong Answer

Solution code:
h,w=map(int,input().split())
s=[list(input()) for i in range(h)]
flag=True
if h==1 and w==1:
  flag=False
for i in range(h):
  if flag==False:
    break
  for j in range(w):
    if s[i][j]=="#":
      if i!=0 and s[i-1][j]!="#":
        flag=False
      elif i!=0 and s[i-1][j]=="#":
        flag=True
        break
        
      if i!=(h-1) and s[i+1][j]!="#":
        flag=False
      elif i!=(h-1) and s[i+1][j]=="#":
        flag=True
        break
        
      if j!=0 and s[i][j-1]!="#":
        flag=False
      elif j!=0 and s[i][j-1]=="#":
        flag=True
        break
        
      if j!=(w-1) and s[i][j+1]!="#":
        flag=False
      elif j!=(w-1) and s[i][j+1]=="#":
        flag=True
        break
        
if h==1 and w==1:
  if s[0][0]==".":
    flag=True
  else:
    flag=False
if flag:
  print("Yes")
else:
  print("No")

Submission status: Wrong Answer

Solution code:
h,w=map(int,input().split())
s=[list(input()) for i in range(h)]
flag=True
if h==1 and w==1:
  flag=False
for i in range(h):
  if flag==False:
    break
  for j in range(w):
    if s[i][j]=="#":
      if i!=0 and s[i-1][j]!="#":
        flag=False
      elif i!=0 and s[i-1][j]=="#":
        flag=True
        break
        
      if i!=(h-1) and s[i+1][j]!="#":
        flag=False
      elif i!=(h-1) and s[i+1][j]=="#":
        flag=True
        break
        
      if j!=0 and s[i][j-1]!="#":
        flag=False
      elif j!=0 and s[i][j-1]=="#":
        flag=True
        break
        
      if j!=(w-1) and s[i][j+1]!="#":
        flag=False
      elif j!=(w-1) and s[i][j+1]=="#":
        flag=True
        break
        
if h==1 and w==1:
  flag=False
  
if flag:
  print("Yes")
else:
  print("No")

Submission status: Wrong Answer

Solution code:
h,w=map(int,input().split())
s=[list(input()) for i in range(h)]
flag=True
for i in range(h):
  if flag==False:
    break
  for j in range(w):
    if s[i][j]=="#":
      if i!=0 and s[i-1][j]!="#":
        flag=False
      else:
        flag=True
        break
      if i!=(h-1) and s[i+1][j]!="#":
        flag=False
      else:
        flag=True
        break
      if j!=0 and s[i][j-1]!="#":
        flag=False
      else:
        flag=True
        break
      if j!=(w-1) and s[i][j+1]!="#":
        flag=False
      else:
        flag=True
        break
if flag:
  print("Yes")
else:
  print("No")

Submission status: Wrong Answer

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

# #で上下左右隣接するマスに#がなければNo
s = []
for h in range(H):
    s.append(input())

for h in range(H):
    print("h: %d" % h)
    for w in range(W):
        if s[h][w] == '.':
            continue

        above = s[h - 1][w] if h >= 1 else '.'
        if above == '#':
            continue

        below = s[h + 1][w] if h < len(s) - 1 else '.'
        if below == '#':
            continue

        left = s[h][w - 1] if w >= 1 else '.'
        if left == '#':
            continue

        right = s[h][w + 1] if w < len(s[h]) - 1 else '.'
        if right == '#':
            continue

        print('No')
        exit(0)

print('Yes')

Submission status: Wrong Answer

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

# #で上下左右隣接するマスに#がなければNo
s = []
for h in range(H):
    s.append(input())

for h in range(H):
    print("h: %d" % h)
    for w in range(W):
        if s[h][w] == '.':
            continue

        above = s[h - 1][w] if h >= 1 else '.'
        print(" above: " + above)
        if above == '#':
            continue

        below = s[h + 1][w] if h < len(s) - 1 else '.'
        print(" below: " + below)
        if below == '#':
            continue

        left = s[h][w - 1] if w >= 1 else '.'
        print(" left: " + left)
        if left == '#':
            continue

        right = s[h][w + 1] if w < len(s[h]) - 1 else '.'
        print(" right: " + right)
        if right == '#':
            continue

        print('No')
        exit(0)

print('Yes')

Submission status: Wrong Answer

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

# #で上下左右隣接するマスに#がなければNo
s = []
for h in range(H):
    s.append(input())

for h in range(H):
    for w in range(W):
        if s[h][w] == '.':
            continue

        above = s[h - 1][w] if h > 1 else '.'
        if above == '#':
            continue

        below = s[h + 1][w] if h < len(s) - 1 else '.'
        if below == '#':
            continue

        left = s[h][w - 1] if w > 1 else '.'
        if left == '#':
            continue

        right = s[h][w + 1] if w < len(s[h]) - 1 else '.'
        if right == '#':
            continue

        print('No')
        exit(0)

print('Yes')

Submission status: Wrong Answer

Solution code:
import sys
H, W = map(int, input().split())
s = [input() for _ in range(H)]
print(s)
dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]
for i in range(H):
    for j in range(W):
        if s[i][j] == '#':
            for k in range(4):
                try:
                    if s[i + dy[k]][j + dx[k]] == '#':
                        flag = False
                        break
                    else:
                        flag = True
                except IndexError:
                    pass
            if flag:
                print('No')
                sys.exit()
print('Yes')

Submission status: Wrong Answer

Solution code:
h,w = map(int,input().split())
array = []
for _ in range(h):
  array.append(list(map(str,input())))
print(array)
for i in range(h):
  array[i].insert(0,".")
  array[i].append(".")
print(array)
array.insert(0,["."]*(w+2))
array.append(["."]*(w+2))
print(array)
for i in range(1,h+1):
  for j in range(1,w+1):
    if array[i][j]=="#" and array[i][j-1] ==  array[i][j+1] == array[i-1][j] == array[i+1][j] == ".":
      print("No")
      break
    if i==h and j==w:
      print("Yes")
      break
  else:
    continue
  break

Submission status: Wrong Answer

Solution code:
h, w = map(int, input().split())
s = [input() for i in range(h)]
for i in range(h):
    for j in range(w):
        ans = "No"
        if s[i][j]=="#":
            for x, y in [(-1, 0), (0, -1), (0, 1), (1, 0)]:
                if  0<=i+x<h and 0<=j+y<w and s[i+x][j+y]=="#":
                    ans = "Yes"
            if ans == "No":
                print(ans)
                exit()
print(ans)

Submission status: Wrong Answer

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

pad_s = [['.'*(W+2)] for _ in range(H+2)]
pad_s[1:-1][1:-1] = S

for i,ss in enumerate(pad_s):
  for j,s in enumerate(ss):
    if s == '#'\
      and pad_s[i][j+1] == '.'\
      and pad_s[i][j-1] == '.'\
      and pad_s[i+1][j] == '.'\
      and pad_s[i-1][j] == '.':
      print('No')
      exit()

print('Yes')

Submission status: Wrong Answer

Solution code:
import numpy as np
import itertools
 
H, W = map(int, input().split())
S = np.array([list(input()) for _ in range(H)])

def f():
  for i, j in itertools.product(range(H), range(W)):
    if S[i, j] == '#':
      if np.sum(np.concatenate([S[i-1:i, j], S[i, j-1:j], S[i+1:i, j], S[i, j+1:j]]) == '#') == 0:
        return False
  return True

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

Submission status: Wrong Answer

Solution code:
import numpy as np
 
H, W = map(int, input().split())
S = np.array([list(input()) for _ in range(H)])

for i in range(H):
  for j in range(W):
    if S[i, j] == '#':
      if np.sum(np.concatenate([S[i-1:i, j], S[i, j-1:j], S[i+1:i, j], S[i, j+1:j]]) == '#') == 0:
        print('No')
        break
else:
  print('Yes')

Submission status: Wrong Answer

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

ans = "Yes"
judge = 0

for i in range(w):
  for j in range(h):
    sign = 0
    
    if s[j][i] == ".":
      continue
    
    if (0<j-1) and (s[j-1][i] == "#"):
      sign = 1
    
    if (0<i-1) and (s[j][i-1] == "#"):
      sign = 1
      
    if (j+1<h) and (s[j+1][i] == "#"):
      sign = 1
      
    if (i+1<w) and (s[j][i+1] == "#"):
      sign = 1
      
    if sign != 1:
      ans = "No"
      judge = 1
      break
  
  if judge == 1:
    break
      
print(ans)

Submission status: Wrong Answer

Solution code:
h,w=map(int,input().split())
s=[list(input()) for i in range(h)]
f=True
dxy=[(-1,0),(0,1),(0,-1),(1,0)]
for i in range(h):
  for j in range(w):
    if s[i][j]=="#":
      for x,y in dxy:
        
        if 0<=i+x<=h-1 and 0<=j+y<=w-1 and s[i+x][j+y]=="#":
          f=False
          
if f:
  print("No")
else:
  print("Yes")

Submission status: Wrong Answer

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

grid = [[str(i) for i in input()]for _ in range(h)]
dxdy = [[1, 0], [0, 1], [-1, 0], [0, -1]]
print(grid)
for i in range(h):
    for j in range(w):
        if grid[i][j]=="#":
            f = False
            for d in dxdy:
                if(i+d[0]>-1 and j+d[1]>-1 and j+d[1]<w and i+d[0]<h):
                    if grid[i+d[0]][j+d[1]]=="#":
                        f = True
                        continue
            if f==False:
                print("No")
                exit()
print("Yes")

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
H, W = map(int, input().split())
S = [list(input())[: -1] for _ in range(H)]
d = [-1, 0, 1, 0]
for i in range(H):
  for j in range(W):
    t = 0
    for k in range(4):
      y = i + d[k]
      x = j + d[-1 - k]
      if y in range(H) and (x in range(W)):
        t += S[y][x] == "#"
    if t: continue
    print("No")
    exit(0)
print("Yes")

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())
s = [0 for _ in range(H)]
for i in range(H):
    s[i] = input()      # intをかけずにinputすると文字列として扱われる
# ここまでが入力

dx = [1, 0, 0, -1]    # これらは移動を表すリスト
dy = [0, 1, -1, 0]    # 順番に、下・右・左・上となっている

ans = "Yes"
for i in range(H):
    for j in range(W):
        if s[i][j] == ".":      # "#"が隣接しているかどうかが知りたいので、"."の周りに何があってもどうでもいい
            continue            # つまり注目しているマスが"#"のときだけ以下の処理をする
        ans = "No"      # この文を入れる場所は要注意
        for d in range(4):      # s[i][j]に対して、隣接する8マスについて"#"があるかを判定する
            di = i + dx[d]
            dj = j + dy[d]
            if di<0 or dj<0 or H-1<di or W-1<dj:    # 注目した隣接マスが「ない」ときは処理をしない
                continue
            if s[di][dj] == "#":
                ans = "Yes"
print(ans)

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())
s = [0 for _ in range(H)]
for i in range(H):
    s[i] = input()      # intをかけずにinputすると文字列として扱われる
# ここまでが入力

dx = [1, 0, 0, -1]    # これらは移動を表すリスト
dy = [0, 1, -1, 0]    # 順番に、下・右・左・上となっている

ans = "Yes"
for i in range(H):
    for j in range(W):
        if s[i][j] == ".":      # "#"が隣接しているかどうかが知りたいので、"."の周りに何があってもどうでもいい
            continue            # つまり注目しているマスが"#"のときだけ以下の処理をする
        ans = "No"      # この文を入れる場所は要注意
        for d in range(4):      # s[i][j]に対して、隣接する8マスについて"#"があるかを判定する
            di = i + dx[d]
            dj = j + dy[d]
            if di<0 or dj<0 or H-1<di or W-1<dj:    # 注目した隣接マスが「ない」ときは処理をしない
                continue
            if s[di][dj] == "#":
                ans = "Yes"
print(ans)

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())
s = [0 for _ in range(H)]
for i in range(H):
    s[i] = input()      # intをかけずにinputすると文字列として扱われる
# ここまでが入力

dx = [1, 0, 0, -1]    # これらは移動を表すリスト
dy = [0, 1, -1, 0]    # 順番に、下・右・左・上となっている

for i in range(H):
    for j in range(W):
        if s[i][j] == ".":      # "#"が隣接しているかどうかが知りたいので、"."の周りに何があってもどうでもいい
            ans = "Yes"
            continue            # つまり注目しているマスが"#"のときだけ以下の処理をする
        ans = "No"      # この文を入れる場所は要注意
        for d in range(4):      # s[i][j]に対して、隣接する8マスについて"#"があるかを判定する
            di = i + dx[d]
            dj = j + dy[d]
            if di<0 or dj<0 or H-1<di or W-1<dj:    # 注目した隣接マスが「ない」ときは処理をしない
                continue
            if s[di][dj] == "#":
                ans = "Yes"
print(ans)

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())
s = [0 for _ in range(H)]
for i in range(H):
    s[i] = input()      # intをかけずにinputすると文字列として扱われる
# ここまでが入力

dx = [1, 0, 0, -1]    # これらは移動を表すリスト
dy = [0, 1, -1, 0]    # 順番に、下・右・左・上となっている

ans = "Yes"
for i in range(H):
    for j in range(W):
        if s[i][j] == ".":      # "#"が隣接しているかどうかが知りたいので、"."の周りに何があってもどうでもいい
            continue            # つまり注目しているマスが"#"のときだけ以下の処理をする
        ans = "No"      # この文を入れる場所は要注意
        for d in range(4):      # s[i][j]に対して、隣接する8マスについて"#"があるかを判定する
            di = i + dx[d]
            dj = j + dy[d]
            if di<0 or dj<0 or H-1<di or W-1<dj:    # 注目した隣接マスが「ない」ときは処理をしない
                continue
            if s[di][dj] == "#":
                ans = "Yes"
print(ans)

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())
s = [0 for _ in range(H)]
for i in range(H):
    s[i] = input()      # intをかけずにinputすると文字列として扱われる
# ここまでが入力

dx = [1, 0, 0, -1]    # これらは移動を表すリスト
dy = [0, 1, -1, 0]    # 順番に、下・右・左・上となっている

for i in range(H):
    for j in range(W):
        ans = "No"      # 判定したいマスに注目したときに、この文を入れないと不正解
        if s[i][j] == ".":      # "#"が隣接しているかどうかが知りたいので、"."の周りに何があってもどうでもいい
            continue            # つまり注目しているマスが"#"のときだけ以下の処理をする
        for d in range(4):      # s[i][j]に対して、隣接する8マスについて"#"があるかを判定する
            di = i + dx[d]
            dj = j + dy[d]
            if di<0 or dj<0 or H-1<di or W-1<dj:    # 注目した隣接マスが「ない」ときは処理をしない
                continue
            if s[di][dj] == "#":
                ans = "Yes"
print(ans)

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())
s = [0 for _ in range(H)]
for i in range(H):
    s[i] = input()      # intをかけずにinputすると文字列として扱われる
# ここまでが入力

ans = "No"

dx = [1, 0, 0, -1]    # これらは移動を表すリスト
dy = [0, 1, -1, 0]    # 順番に、下・右・左・上となっている

for i in range(H):
    for j in range(W):
        if s[i][j] == ".":      # "#"が隣接しているかどうかが知りたいので、"."の周りに何があってもどうでもいい
            continue            # つまり注目しているマスが"#"のときだけ以下の処理をする
        for d in range(4):      # s[i][j]に対して、隣接する8マスについて"#"があるかを判定する
            di = i + dx[d]
            dj = j + dy[d]
            if di<0 or dj<0 or H-1<di or W-1<dj:    # 注目した隣接マスが「ない」ときは処理をしない
                continue
            if s[di][dj] == "#":
                ans = "Yes"
print(ans)

Submission status: Wrong Answer

Solution code:
if __name__ == '__main__':
    h, w = map(int, input().split())
    field = [list(input()) for i in range(h)]
    d = [(1, 0), (0, 1), (-1, 0), (0, -1)]
    for y in range(h):
        flag = False
        for x in range(w):
            if field[y][x] == "#":
                for dx, dy in d:
                    if 0 <= x + dx < w and 0 <= y + dy < h:
                        if field[y + dy][x + dx] == "#":
                            flag |= True
                if not flag:
                    print("No")
                    exit(0)
    print("Yes")

Submission status: Wrong Answer

Solution code:
if __name__ == '__main__':
    h, w = map(int, input().split())
    field = [list(input()) for i in range(h)]
    d = [(1, 0), (0, 1), (-1, 0), (0, -1)]
    for y in range(h):
        flag = 0
        for x in range(w):
            if field[y][x] == "#":
                for dx, dy in d:
                    if 0 <= x + dx < w and 0 <= y + dy < h:
                        if field[y + dy][x + dx] == "#":
                            flag += 1
                if flag == 0:
                    print("No")
                    exit(0)
    print("Yes")

Submission status: Wrong Answer

Solution code:
if __name__ == '__main__':
    h, w = map(int, input().split())
    field = [list(input()) for i in range(h)]
    d = [(1, 0), (0, 1), (-1, 0), (0, -1)]
    for y in range(h):
        flag = 0
        for x in range(w):
            if field[y][x] == "#":
                for dx, dy in d:
                    if 0 <= x + dx < w and 0 <= y + dy < h:
                        if field[y + dy][x + dx] == "#":
                            flag += 1
                if flag == 0:
                    print("x = {}, y = {}".format(x, y))
                    print("No")
                    exit(0)
    print("Yes")

Submission status: Wrong Answer

Solution code:
from itertools import product
import numpy as np
class Grid():
    def __init__(self, grid, w=0, h=0, function=lambda x: x):
        self.w = w = w if w else len(grid[0])
        self.h = h = h if h else len(grid)
        dtype = type(function(grid[0][0]))
        self.grid = np.empty((h, w), dtype=dtype)
        for i, rows in zip(range(h), grid):
            for j, val in zip(range(w), rows):
                self.grid[i][j] = function(val)
    
    def is_valid_x(self, x):
        return 0 <= x < self.w
    def is_valid_y(self, y):
        return 0 <= y < self.h
    def is_valid_xy(self, x, y):
        return self.is_valid_x(x) and self.is_valid_y(y) 
    
    def __iter__(self):
        return iter(self.grid)
    def __repr__(self):
        return '\n'.join([' '.join(map(str, rows)) for rows in self.grid])

inputs = open(0).readlines()
h, w = map(int, inputs[0].split())
grid = Grid(inputs[1:])

def dfs(root):
    count = 1
    stack = [root]
    while stack:
        x, y = stack.pop()
        grid.grid[y, x] = '.'
        for dx, dy in zip([1, 0, -1, 0], [0, 1, 0, -1]):
            if grid.is_valid_xy(x+dx, y+dy) and grid.grid[y+dy, x+dx] == '#':
                stack.append((x+dx, y+dy))
                count += 1
    return count

ans = 'No'
for i, j in product(range(h), range(w)):
    if grid.grid[i, j] == '#':
        if dfs((j, i)) == 1:
            ans = 'Yes'
            break
print(ans)

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())
S = ['.'*(W+2)] + ['.' + input() + '.' for _ in range(H)] + ['.'*(W+2)]
flg = False
for i in range(1, H+1):
  for j in range(1, W+1):
    if S[i][j] == '#':
      cnt = 0
      if S[i][j-1] == '.':
        cnt += 1
      if S[i][j+1] == '.':
        cnt += 1
      if S[i-1][j] == '.':
        cnt += 1
      if S[i+1][j] == '.':
        cnt += 1
      flg = (cnt == 4)
if flg:
  print("No")
else:
  print("Yes")

Submission status: Wrong Answer

Solution code:
h, w = map(int, input().split())
list_S = [ list(input()) for _ in range(h) ]
ans = "Yes"
a = 0
for i in range(h):
    for j in range(w):
        cnt = 0
        if list_S[i][j] != "#":
            break
        a += 1
        if i + 1 >= 0 and i + 1< h and j >= 0 and j < w:
            if list_S[i+1][j] == "#":
                cnt += 1

        if i - 1 >= 0 and i - 1< h and j >= 0 and j < w:
            if list_S[i-1][j] == "#":
                cnt += 1

        if i >= 0 and i < h and j + 1 >= 0 and j + 1 < w:
            if list_S[i][j+1] == "#":
                cnt += 1

        if i >= 0 and i < h and j - 1>= 0 and j - 1 < w:
            if list_S[i][j-1] == "#":
                cnt += 1
        if cnt == 0:
            ans = "No"


if a == 1:
    ans = "Yes"


print(ans)