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())
list_S = [ list(input()) for _ in range(h) ]
ans = "Yes"

for i in range(h):
    for j in range(w):
        cnt = 0
        if list_S[i][j] != "#":
            break
        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 h == 1 and w == 1 and list_S[0][0] == "#":
    ans = "Yes"


print(ans)

Submission status: Wrong Answer

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

for i in range(h):
    for j in range(w):
        cnt = 0
        if list_S[i][j] != "#":
            break
        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 h == 1 and w == 1 and list_S[0][0] == "#":
    ans = "Yes"

if h == 1 and w == 1 and list_S[0][0] == ".":
    ans = "No"
print(ans)

Submission status: Wrong Answer

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

for i in range(h):
    for j in range(w):
        cnt = 0
        if list_S[i][j] != "#":
            break
        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"

print(ans)

Submission status: Wrong Answer

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

for i in range(H):
  h=i
  for j in range(W):
    w=s[h][j]
    if w=='#':
      w=s[i].find('#')
      cnt=0
      for j,k in ([1,0], [-1,0], [0,1], [0,-1]):
        new_h, new_w=h+j, w+k
        if new_h<0 or new_h>=H or new_w<0 or new_w>=W:
          continue
        elif s[new_h][new_w] == '#':
          cnt+=1
          break
      if cnt==0:
        print('No')
        exit()
print('Yes')

Submission status: Wrong Answer

Solution code:
import math
import string
import collections
from collections import Counter
from collections import deque


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


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


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

H, W = map(int, input().split())
s = [None]*H
for i in range(H):
    s[i] = input()
d = deque()
d.append((0, 0))
while(len(d) != 0):
    g, r = d.popleft()
    if s[g][r] == '#':
        if g != 0 and s[g-1][r] == '#':
            d.append((g-1, r))
        else:
            print('No')
            break
        if g != H-1 and s[g+1][r] == '#':
            d.append((g+1, r))
        else:
            print('No')
            break
        if r != 0 and s[g][r-1] == '#':
            d.append((g, r-1))
        else:
            print('No')
            break
        if r != W-1 and s[g][r+1] == '#':
            d.append((g, r+1))
        else:
            print('No')
            break
    print('Yes')

Submission status: Wrong Answer

Solution code:
import math
import string
import collections
from collections import Counter
from collections import deque


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


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


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

H, W = map(int, input().split())
s = [None]*H
for i in range(H):
    s[i] = input()
d = deque()
d.append((0, 0))
while(len(d) != 0):
    g, r = d.popleft()
    if s[g][r] == '#':
        if g != 0:
            d.append((g-1, r))
        else:
            print('No')
            break
        if g != H-1:
            d.append((g+1, r))
        else:
            print('No')
            break
        if r != 0:
            d.append((g, r-1))
        else:
            print('No')
            break
        if r != W-1:
            d.append((g, r+1))
        else:
            print('No')
            break
    print('Yes')

Submission status: Wrong Answer

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

SS = []
for i in range(H):
    SS.append(list(input()))
    
def seekindices(h,w,H,W):
    cand = []
    for x in [-1,0,1]:
        for y in [-1,0,1]:
            if abs(x) == 1:
                if h + x >= 0 and h + x < H:
                    cand.append([h+x,w])
            elif abs(y) == 1:
                if w + y >=0 and w + y < W:
                    cand.append([h,w+y])
    return(cand)

ans = 'Yes'

for h in range(H):
    for w in range(W):
        seeks = seekindices(h,w,H,W)
        bochi = 0
        for s in seeks:
            i,j = s[:]
            if SS[i][j] == "#":
                bochi = 1
        if bochi == 0:
            ans = 'No'
            
print(ans)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
canvas = []
for i in range(n):
    line = []
    line_input = input()
    for j in range(m):
        if line_input[j] == '.':
            line.append(0)
        else:
            line.append(1)
    canvas.append(line)
for i in range(1, n):
    for j in range(0, m):
        if canvas[i-1][j]:
            canvas[i-1][j] += 1
            canvas[i-1][j] %= 2
            canvas[i][j] += 1
            canvas[i][j] %= 2
            if i < n-1:
                canvas[i+1][j] += 1
                canvas[i+1][j] %= 2
            if j > 0:
                canvas[i][j-1] += 1
                canvas[i][j-1] %= 2
            if j < m-1:
                canvas[i][j+1] += 1
                canvas[i][j+1] %= 2
if sum(sum(canvas, [])) == 0:
    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)]
s2 = [[0]*(w+2) for i in range(h+2)]
for i in range(h):
    for j in range(w):
        if s[i][j] == '#':
            s2[i+1][j+1] = 1
for i in range(h):
    for j in range(w):
        if s[i][j] == '#':
            if s2[i+1][j] + s2[i+1][j+2] + s2[i][j+1] + s2[i+2][j+1] == 0:
                print('No')
                break
print('Yes')

Submission status: Wrong Answer

Solution code:
h,w = map(int, input().split())
s = [list(input()) for i in range(h)]
s2 = [[0]*(w+2) for i in range(h+2)]
for i in range(h):
    for j in range(w):
        if s[i][j] == '#':
            s2[i+1][j+1] = 1
for i in range(h):
    for j in range(w):
        if s[i][j] == '#':
            if s2[i+1][j] + s2[i+1][j+2] + s2[i][j+1] + s2[i+2][j] == 0:
                print('No')
                exit()
print('Yes')

Submission status: Wrong Answer

Solution code:
h,w = map(int, input().split())
s = [list(input()) for i in range(h)]
s2 = [[0]*(w+2) for i in range(h+2)]
for i in range(h):
    for j in range(w):
        if s[i][j] == '#':
            s2[i+1][j+1] = 1
for i in range(h):
    for j in range(w):
        if s[i][j] == '#':
            if s2[i+1][j] + s2[i+1][j+2] + s2[i][j+1] + s2[i+2][j] == 0:
                print('No')
                break
print('Yes')

Submission status: Wrong Answer

Solution code:
h, w = map(int, input().split())
s = [list(input()) for i in range(h)]
S1 = [[0] * (w+2) for i in range(h+2)]
for i in range(h):
    for j in range(w):
        if s[i][j] == "#":
            S1[i+1][j+1] = 1
S2 = [[0] * w for i in range(h)]
for i in range(h):
    for j in range(w):
        if s[i][j] == "#":
            S2[i][j] = S1[i][j+1] + sum(S1[i+1][j:j+3]) + S1[i+2][j+1]
if 1 in S2:
  print("No")
else:
  print("Yes")

Submission status: Wrong Answer

Solution code:
H, W = map(int,input().split())
src = [list(input()) for i in range(H)]
 
dxy = [(-1,0),(0,-1),(0,1),(1,0)]

for h in range(H):
  count = 0
  for w in range(W):
    count = 0
    if src[h][w] == ".":
      continue
    print(h,w)
    
    for dx,dy in dxy:      
      count += 1
      if w + dx < 0 or w + dx > W-1 or h + dy < 0 or h + dy > H-1:
        continue
      
      if count == 4:
        print("No")
        exit()
        
print("Yes")

Submission status: Wrong Answer

Solution code:
H, W = map(int,input().split())
src = [list(input()) for i in range(H)]
 
dxy = [(-1,0),(0,-1),(0,1),(1,0)]
 
for h in range(H):
  count = 0
  for w in range(W):
    count = 0
    if src[h][w] == ".":
      continue

    for dx,dy in dxy:      
      count += 1
      if w + dx < 0 or w + dx > W-1 or h + dy < 0 or h + dy > H-1:
        continue

      if src[h + dy][w + dx] == "#":
        print("Yes")
        exit()
      
      if count == 4:
        print("No")
        exit()

Submission status: Wrong Answer

Solution code:
H, W = map(int,input().split())
src = [list(input()) for i in range(H)]
 
dxy = [(-1,-1),(-1,0),(-1,1),(0,-1),(0,1),(1,-1),(1,0),(1,1)]
 
for h in range(H):
  count = 0
  for w in range(W):
    count = 0
    if src[h][w] == ".":
      continue

    for dx,dy in dxy:      
      count += 1
      if w + dx < 0 or w + dx > W-1 or h + dy < 0 or h + dy > H-1:
        continue

      if src[h + dy][w + dx] == "#":
        print("Yes")
        exit()
      
      if count == 8:
        print("No")
        exit()

print("No")

Submission status: Wrong Answer

Solution code:
H, W = map(int,input().split())
src = [list(input()) for i in range(H)]
 
dxy = [(-1,-1),(-1,0),(-1,1),(0,-1),(0,1),(1,-1),(1,0),(1,1)]
 
for h in range(H):
  count = 0
  for w in range(W):
    count = 0
    if src[h][w] == ".":
      continue

    for dx,dy in dxy:      
      count += 1
      if w + dx < 0 or w + dx > W-1 or h + dy < 0 or h + dy > H-1:
        continue

      if src[h + dy][w + dx] == "#":
        print("Yes")
        exit()
      
      if count == 8:
        print("No")
        exit()

print("Yes")

Submission status: Wrong Answer

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

dxy = [(-1,-1),(-1,0),(-1,1),(0,-1),(0,1),(1,-1),(1,0),(1,1)]

for h in range(H):
  for w in range(W):
    count = 0
    for dx,dy in dxy:
      count += 1
      if w + dx < 0 or w + dx > W-1 or h + dy < 0 or h + dy > H-1:
        continue

      if src[h + dy][w + dx] == "#":
        print("Yes")
        exit()
      
      if count == 8:
        print("No")
        exit()

Submission status: Wrong Answer

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

for i in range(H):
    L[i] = list(input())

for i in range(H):
    for j in range(W):

        if L[i][j] == "#":

            c = 0
            if i-1 >= 0:
                if L[i-1][j] == "#":
                    c += 1
            if i+1 < H-1:
                if L[i+1][j] == "#":
                    c += 1
            if j-1 >= 0:
                if L[i][j-1] == "#":
                    c += 1
            if j+1 < W-1:
                if L[i][j+1] == "#":
                    c += 1

            if c == 0:
                print("No")
                break
    
    else:
        continue
    break
else:
    print("Yes")

Submission status: Wrong Answer

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

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

flag = False
for i in range(h):
    for j in range(w):
        if s[i][j] == "#":
            for k in range(4):
                y = i + dy[k]
                x = j + dx[k]
                if 0 <= y < h and 0 <= x < w:
                    if s[y][x] == "#":
                        flag = True
            if flag == False:
                print("No")
                exit()
print("Yes")

Submission status: Wrong Answer

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

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

flag = False
for i in range(h):
    for j in range(w):
        if s[i][j] == "#":
            for k in range(4):
                y = i + dy[k]
                x = j + dx[k]
                if 0 <= y < h and 0 <= x < w:
                    if s[y][x] == "#":
                        flag = True
            if flag == False:
                print("No")
                exit()

print("Yes")

Submission status: Wrong Answer

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

flag = True
output_rows = [['#' for _ in range(W)] for __ in range(H)]

for i in range(H):
    for j in range(W):
        if rows[i][j] != '#':
            continue
        else:
            found = False
            for dy in range(-1, 1 + 1):
                for dx in range(-1, 1 + 1):
                    y, x = i + dy, j + dx
                    if x < 0 or x > W - 1 or y < 0 or y > H - 1:
                        continue
                    else:
                        if rows[y][x] == '#':
                            found = True
            if not found:
                flag = False
                break

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

Submission status: Wrong Answer

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

flag = True
output_rows = [['#' for _ in range(W)] for __ in range(H)]

for i in range(H):
    for j in range(W):
        if rows[i][j] == '#':
            continue
        else:
            found = False
            for dy in range(-1, 1 + 1):
                for dx in range(-1, 1 + 1):
                    y, x = i + dy, j + dx
                    if x < 0 or x > W - 1 or y < 0 or y > H - 1:
                        continue
                    else:
                        if rows[y][x] == '#':
                            found = True
            if not found:
                flag = False
                break

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

Submission status: Wrong Answer

Solution code:
#4方向走査
#下、右、上、左
dy=[1,0,-1,0]
dx=[0,1,0,-1]

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

field=[]
for _ in range(H):
  field.append(list(input()))

is_success=True

for y in range(H):
  for x in range(W):
    if field[y][x]==".":
      continue
    
    for k in range(4):
      tmp_y=y+dy[k]
      tmp_x=x+dx[k]

      if tmp_y<0 or tmp_y>=H or tmp_x<0 or tmp_x>=W:
        continue
      if field[tmp_y][tmp_x]==".":
        break
      if k==3:
        print("No")
        exit()
print("Yes")

Submission status: Wrong Answer

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

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

for i in range(h):
    for j in range(w):
        if l[i][j] == "#":
            ok=False
            for k in range(4):
                nx = j + dx[k]
                ny = i + dy[k]
                if 0<=nx<w and 0<=ny<h and l[ny][nx]=="#":
                    ok=True
            if not ok:
                print(i,j)
                print("No")
                exit()
print("Yes")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:

# import
import numpy as np
import sys
sys.setrecursionlimit(10**6)

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

Mtmp = []
for _ in range(H):
    tmp = list(input())
    Mtmp.append(tmp)

M = np.array(Mtmp)
S = np.array([[0]*W]*H)

#print(M)

digtmp = np.array([[0, 1], [1, 0], [0, -1], [-1, 0]])

def dfs(i, j):
    global ngflag
    global searchflag
    if S[i, j] == 1:
        return
    S[i, j] = 1
    if M[i, j] == '.':
        return
    #print("i:{}, j:{}".format(i, j))
    searchflag = 1
    dig = digtmp + np.array([i, j])
    for d in dig:
        if 0 <= d[0] < H and 0 <= d[1] < W:
            if M[d[0], d[1]] == '#':
                ngflag = 0
                dfs(d[0], d[1])

searchflag = 0

while True:
    ngflag = 1
    if 0 not in S:
        if M[target[0], target[1]] == '.':
            ngflag = 0
        break
    target = list(zip(*np.where(S == 0)))[0]
    #print("sf:{}, ng:{}".format(searchflag, ngflag))
    dfs(target[0], target[1])
    if M[target[0], target[1]] == '#' and searchflag == 1 and ngflag == 1:
        break
        

#print("sf:{}, ng:{}".format(searchflag, ngflag))

if searchflag == 1 and ngflag == 0:
    ans = 'Yes'
elif searchflag == 1 and ngflag == 1:
    ans = 'No'
else:
    ans = 'Yes'

print(ans)

Submission status: Wrong Answer

Solution code:
H,W=map(int,input().split())
answers=[]
answers.append([' ',]*(W+2))
for a in range(H):
    S=input()
    T=[b for b in S]
    T.append(' ')
    T.insert(0,' ')
    answers.append(T)
answers.append([' ',]*(W+2))
lll=[]
kotae=0
for a in range(H):
    A=answers[a+1]
    for b in range(W):
        if A[b+1]=='#':
            if A[b]=='#' or A[b+2]=='#'  or answers[a][b+1]=='#' or answers[a+2][b+1]=='#':
                pass
            else:
                kotae+=100
            break
if kotae==0:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
H,W=map(int,input().split())
answers=[]
answers.append([' ',]*(W+2))
for a in range(H):
    S=input()
    T=[b for b in S]
    T.append(' ')
    T.insert(0,' ')
    answers.append(T)
answers.append([' ',]*(W+2))
kotae=0
for a in range(H):
    A=answers[a+1]
    for b in range(W):
        if A[b+1]=='#':
            if A[b]=='#' or A[b+2]=='#'  or answers[a][b+1]=='#' or answers[a+2][b+1]=='#':
                pass
    else:
        print('No')
        kotae=100
    break
if kotae==0:
    print('Yes')

Submission status: Wrong Answer

Solution code:
H,W=map(int,input().split())
answers=[]
answers.append([' ',]*(W+2))
for a in range(H):
    S=input()
    T=[b for b in S]
    T.append(' ')
    T.insert(0,' ')
    answers.append(T)
answers.append([' ',]*(W+2))
kotae=0
for a in range(H):
    A=answers[a+1]
    for b in range(W):
        if A[b+1]=='#':
            if A[b]=='#' or A[b+2]=='#' or answers[a][b]=='#' or answers[a][b+1]=='#' or answers[a][b+2]=='#' or answers[a+2][b]=='#' or answers[a+2][b+1]=='#' or answers[a+2][b+2]=='#':
                pass
            else:
                print('No')
                kotae=100
                break
if kotae==0:
    print('Yes')

Submission status: Wrong Answer

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

s=[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(s[i][j]=='.'):continue
        f=False
        for k in range(4):
            ni=i+dx[k]
            nj=j+dy[k]
            if(0<=ni<=h-1 and 0<=nj<=w-1):
                if(s[ni][nj]=='#'):f=True
        if(not f):
            print(i,j)
            print("No")
            exit()
print("Yes")

Submission status: Wrong Answer

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

    d = [[-1, 0], [0, -1], [0, 1], [1, 0]]

    count = 0
    for i in range(h):
        for j in range(w):

            for dx, dy in d:
                m = i + dx
                n = j + dy
                if m < 0 or m > h - 1:
                    pass
                elif n < 0 or n > w - 1:
                    pass
                elif l[i][j] == '#' and l[m][n] == '#':
                    count += 1

    if count == 0:
        return print('No')
    else:
        return print('Yes')

if __name__ == '__main__':
    resolve()

Submission status: Wrong Answer

Solution code:
H, W = map(int,input().split())
S = [list(input()) for _ in range(H)]
flag = False
for i in range(H):
  for j in range(W):
    up = down = left = right = "."
    if S[i][j] == "#":
      if i-1 >= 0:
        up = S[i-1][j]
      if j-1 >= 0:
        left = S[i][j-1]
      if i+1 <= H-1:
        down = S[i+1][j]
      if j+1 <= W-1:
        right = S[i][j+1]
      if up == down == left == right == ".":
        print("No")
        exit()
      flag = True
if flag:
  print("Yes")
else:
  print("No")

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())
s = []
for _ in range(H):
    s.append(input())
    
Flg = "Yes"
for i in range(H-1):
    for j in range(W):
        if(s[i][j] == '#'):
            if(s[i][max(j-1, 0)] == "." and s[i][min(j+1, W-1)] == '.' and s[i+1][j] == '.'):
                Flg = "No"

print(Flg)

Submission status: Wrong Answer

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

for i in range(h):
  for j in range(w):
    if j > 0 and a[i][j-1] == "#" and a[i][j] == "#":
      a[i][j] = "-"
    elif j < w - 1 and a[i][j+1] == "#" and a[i][j] == "#":
      a[i][j] = "-"
    elif i > 0 and a[i-1][j] == "#" and a[i][j] == "#":
      a[i][j] = "-"
    elif i < h - 1 and a[i+1][j] == "#" and a[i][j] == "#":
      a[i][j] = "-"
print("No" if sum([row.count("#") for row in a]) else "Yes")

Submission status: Wrong Answer

Solution code:
inH, inW = map(int, input().split())
inMap = list()

for i in range(inH):
  inMap.append(list(input()))

def chkPaint(x,y):
  mv = [[-1,0], [1,0], [0,-1], [0,1]]
  for pos in mv:
    if x+pos[0]<0 or x+pos[0]>=inH or y+pos[1]<0 or y+pos[1]>=inH  :
      continue
    if inMap[x+pos[0]][y+pos[1]] == "#":
        return True
  return False

flg=True
for i in range(inH):
  for j in range(inW):
    if inMap[i][j] == "#":
      flg = chkPaint(i,j)
    if flg == False:
      break
  if flg == False:
    break

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

Submission status: Wrong Answer

Solution code:
h, w = map(int, input().split())
masu = ['.'*(w+2)]
masu += ['.' + input() + '.' for _ in range(h)]
masu.append('.'*(w+2))
ans = 'Yes'
for i in range(1,h+1):
    for j in range(1,w+1):
        print(masu[i][j])
        if masu[i][j] == '#':
            if masu[i+1][j] == '#' or masu[i-1][j] == '#' or masu[i][j+1] == '#' or masu[i][j-1] == '#':
                continue
            else:
                ans = 'No'
                break
print(masu)

Submission status: Wrong Answer

Solution code:
S = input().split(" ")
N = int(S[0])
W = int(S[1])

ARR = []

for i in range(N):
    ar = list(input())
    ARR.append(ar)


def calculate(n, w, arr):
    result = True
    hasShape = False
    for i in range(n):
        for j in range(w):
            if arr[i][j] == "#":
                hasShape = True
                sss = []
                if i -1 >= 0:
                    sss.append(arr[i-1][j])
                if i + 1 < n:
                    sss.append(arr[i+1][j])

                if j - 1 >= 0:
                    sss.append(arr[i][j-1])
                if j + 1 < w:
                    sss.append(arr[i][j+1])

                if "#" not in sss:
                    result = False
                    break

    if hasShape == False:
        print("No")
        return

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


calculate(N, W, ARR)

Submission status: Wrong Answer

Solution code:
n,w=map(int,input().split())
st=[]
for i in range(n):
    st.append(list(input())) #0~n-1までの列ができる
if n==w==1:
    print("Yes")
    exit()

for i in range(1,n-1):
    for j in range(1,w-1): #i,jに1足しても引いても範囲内だから安心！
        if st[i][j]=="#":
            if st[i+1][j]=="." and st[i][j-1]=="." and st[i][j+1]=="." and st[i+1][j]==".":
                print("No")
                exit()
        

print("Yes")

Submission status: Wrong Answer

Solution code:
n,w=map(int,input().split())
st=[]
for i in range(n):
    st.append(list(input())) #0~n-1までの列ができる
if n==w==1:
    print("Yes")
    exit()

for i in range(1,n-1):
    for j in range(1,w-1): #i,jに1足しても引いても範囲内だから安心！
        if st[i][j]=="#":
            if st[i+1][j]=="." and st[i][j-1]=="." and st[i][j+1]=="." and st[i+1][j]==".":
                print("No")
                exit()
        if st[0][j]=="#" and st[1][j]=="." and st[0][j+1]=="." and st[0][j-1]==".": #上辺
            print("No")
            exit()
        if st[i][0]=="#" and st[i][1]=="." and st[i-1][0]=="." and st[i+1][0]==".": #左辺
            print("No")
            exit()
        if st[i][w-1]=="#" and st[i][w-2]=="." and st[i-1][w-1]=="." and st[i+1][w-1]==".": #右辺
            print("No")
            exit()
        if st[n-1][j]=="#" and st[n-2][j]=="." and st[n-1][j+1]=="." and st[n-1][j-1]==".": #下辺
            print("No")
            exit()

print("Yes")

Submission status: Wrong Answer

Solution code:
n,w=map(int,input().split())
st=[]
for i in range(n):
    st.append(list(input())) #0~n-1までの列ができる
if n==w==1:
    print("Yes")
    exit()

for i in range(1,n-1):
    for j in range(1,w-1): #i,jに1足しても引いても範囲内だから安心！
        if st[i][j]=="#":
            if st[i+1][j]=="." and st[i][j-1]=="." and st[i][j+1]=="." and st[i+1][j]==".":
                print("No")
                exit()
        if st[0][j]=="#" and st[1][j]=="." and st[0][j+1]=="." and st[0][j-1]==".": #上辺
            print("No")
            exit()
        if st[i][0]=="#" and st[i][1]=="." and st[i-1][0]=="." and st[i+1][0]==".": #左辺
            print("No")
            exit()
        if st[i][w-1]=="#" and st[i][w-2]=="." and st[i-1][w-1]=="." and st[i+1][w-1]==".": #右辺
            print("No")
            exit()
        if st[n-1][j]=="#" and st[n-2][j]=="." and st[n-1][j+1]=="." and st[n-1][j-1]==".": #下辺
            print("No")
            exit()
if st[0][0]=="#" and st[0][1]=="." and st[1][0]==".": #左上
    print("No")
    exit()
if st[0][w-1]=="#" and st[0][w-2]=="." and st[1][w-1]==".": #右上
    print("No")
    exit()
if st[n-1][0]=="#" and st[n-1][1]=="." and st[n-2][0]==".": #左下
    print("No")
    exit()
if st[n-1][w-1]=="#" and st[n-1][w-2]=="." and st[n-2][w-1]==".": #右下
    print("No")
    exit()
print("Yes")

Submission status: Wrong Answer

Solution code:
n,w=map(int,input().split())
st=[]
for i in range(n):
    st.append(list(input())) #0~n-1までの列ができる

for i in range(1,n-1):
    for j in range(1,w-1): #i,jに1足しても引いても範囲内だから安心！
        if st[i][j]=="#":
            if st[i+1][j]=="." and st[i][j-1]=="." and st[i][j+1]=="." and st[i+1][j]==".":
                print("No")
                exit()
        if st[0][j]=="#" and st[1][j]=="." and st[0][j+1]=="." and st[0][j-1]==".": #上辺
            print("No")
            exit()
        if st[i][0]=="#" and st[i][1]=="." and st[i-1][0]=="." and st[i+1][0]==".": #左辺
            print("No")
            exit()
        if st[i][w-1]=="#" and st[i][w-2]=="." and st[i-1][w-1]=="." and st[i+1][w-1]==".": #右辺
            print("No")
            exit()
        if st[n-1][j]=="#" and st[n-2][j]=="." and st[n-1][j+1]=="." and st[n-1][j-1]==".": #下辺
            print("No")
            exit()
if st[0][0]=="#" and st[0][1]=="." and st[1][0]==".": #左上
    print("No")
    exit()
if st[0][w-1]=="#" and st[0][w-2]=="." and st[1][w-1]==".": #右上
    print("No")
    exit()
if st[n-1][0]=="#" and st[n-1][1]=="." and st[n-2][0]==".": #左下
    print("No")
    exit()
if st[n-1][w-1]=="#" and st[n-1][w-2]=="." and st[n-2][w-1]==".": #右下
    print("No")
    exit()
print("Yes")