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())
s = [list(input()) for j in range(H)]

if s[0][0] == "#":
    #print(0, 0, "黒")
    if not (s[0][1] == "#" or s[1][0] == "#"):
        print("No")
        exit()

for j in range(1, W-1):
    if s[0][j] == "#":
     #   print(0, j, "黒")
        if not (s[1][j] == "#" or s[0][j - 1] == "#" or s[0][j + 1] == "#"):
            print("No")
            exit()

if s[0][-1] == "#":
    #print(0, -1, "黒")
    if not (s[0][-2] == "#" or s[1][-1] == "#"):
        print("No")
        exit()

for i in range(1, H-1):
    if s[i][0] == "#":
     #   print(i, 0, "黒")
        if not (s[i][1] == "#" or s[i-1][0] == "#" or s[i+1][0] == "#"):
            print("No")
            exit()

for i in range(1, H-1):
    if s[i][-1] == "#":
     #   print(i, -1, "黒")
        if not (s[i][-2] == "#" or s[i-1][0] == "#" or s[i+1][0] == "#"):
            print("No")
            exit()

if s[-1][0] == "#":
    #print(-1, 0, "黒")
    if not (s[-1][1] == "#" or s[-2][0] == "#"):
        print("No")
        exit()

for j in range(1, W-1):
    if s[-1][j] == "#":
     #   print(-1, j, "黒")
        if not (s[-2][j] == "#" or s[-1][j - 1] == "#" or s[-1][j + 1] == "#"):
            print("No")
            exit()

if s[-1][-1] == "#":
    #print(-1, -1, "黒")
    if not (s[-1][-2] == "#" or s[-2][-1] == "#"):
        print("No")
        exit()

for i in range(1, H-1):
    for j in range(1, W-1):
        if s[i][j] == "#":
     #       print(i, j, "黒")
            if not (s[i - 1][j] == "#" or s[i + 1][j] == "#" or s[i][j - 1] == "#" or s[i][j + 1] == "#"):
                print("No")
                exit()
print("Yes")

Submission status: Wrong Answer

Solution code:
H,W=(int(i) for i in input().split())
s=[input() for i in range(H)]
for i in range(H):
    for j in range(W):
        if s[i][j]=='#':
            if i==0 or s[i-1][j]=='.':
                if i==H-1 or s[i+1][j]=='.':
                    if j==0 or s[i][j-1]=='.':
                        if j==W-1 or s[i][j-1]=='.':
                            print('No')
                            exit()
print('Yes')

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):
        if s[i][j]=='#':
            if i==0 or s[i-1][j]=='.':
                if i==H-1 or s[i+1][j]=='.':
                    if j==0 or s[i][j-1]=='.':
                        if j==W-1 or s[i][j-1]=='.':
                            print('No')
                            exit()
print('Yes')

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())
s = [input() for i in range(H)]
flag = True
count = 0
loop_num = 0

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):
                if 0 <= i+dy[k] < H and 0 <= j+dx[k] < W:
                    #数えるマスの数
                    loop_num += 1
                    if s[i+dy[k]][j+dx[k]] == '.':
                        #白い隣あったマスの数
                        count += 1
                #隣り合うマスが存在しないとき黒いマスは塗りつぶせないので目標は達成不可
                if count == loop_num:
                    flag = None
                    break
                else:
                    count = 0
                    loop_num = 0
        else:
            pass
    if flag == None:
        break

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

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())
s = [input() for i in range(H)]
flag = True
count = 0
loop_num = 0

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):
                if 0 <= i+dy[k] < H and 0 <= j+dx[k] < W:
                    #数えるマスの数
                    loop_num += 1
                    if s[i+dy[k]][j+dx[k]] == '.':
                        #白い隣あったマスの数
                        count += 1
                #隣り合うマスが存在しないとき黒いマスは塗りつぶせないので目標は達成不可
                if count == loop_num:
                    flag = None
                    break
                else:
                    count = 0
                    loop_num = 0
        else:
            pass

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

Submission status: Wrong Answer

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

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):
                if 0 <= i+dy[k] < H and 0 <= j+dx[k] < W:
                    if s[i+dy[k]][j+dx[k]] == '.':
                        count += 1
                if count == 4:
                    flag = None
                    break
                else:
                    count = 0
        else:
            pass

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

Submission status: Wrong Answer

Solution code:
#ABC 096 C - Grid Repainting 2
H, W = map(int, input().split())
S = [input() for i in range(H)]

s = [[0] * (W+2) for i in range(H+2)]
for h in range(H):
    for w in range(W):
        s[h+1][w+1] = S[h][w]
print(s)

c = [[0] * (W+2) for i in range(H+2)]
for h in range(1,H+1):
    for w in range(1,W+1):
        if s[h][w] == '#':
            if s[h][w-1] == '#':
                c[h][w] += 1
                c[h][w-1] +=1
            if s[h][w+1] == '#':
                c[h][w] += 1
                c[h][w+1] +=1
            if s[h+1][w] == '#':
                c[h][w] += 1
                c[h+1][w] +=1
            if s[h-1][w] == '#':
                c[h-1][w] += 1
                c[h-1][w] +=1

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

Submission status: Wrong Answer

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

def check(h,w):
  ans = False
  if 0 < h:
    ans |= S[h-1][w] == "#"
  if 0 < w:
    ans |= S[h][w-1] == "#"
  if h < H-1:
    ans |= S[h+1][w] == "#"
  if w < W-1:
    ans |= S[h][w+1] == "#"
  return ans
for h in range(H):
  for w in range(W):
    if not check(h,w):
      print("No")
      exit()
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 = [0, 1, 0, -1]
dy = [1, 0, -1, 0]

for i in range(h):
    for j in range(w):
        if s[i][j] == '.':
            continue
        flag = 0
        for k in range(4):
            dh = i + dy[k]
            dw = j + dx[k]
            # print(dh, dw)
            if 0 <= dh < h and 0 <= dw < w and s[dh][dw] == '#':
                flag = 1
        if flag == 0:
            print('No')
            sys.exit()
print('Yes')

Submission status: Wrong Answer

Solution code:
H,W = map(int,input().split())
s = [input() for i in range(H)]
ans = "No"
dx = [1,0,-1,0]
dy = [0,1,0,-1]
flag = True
for i in range(H):
    for j in range(W):
        if s[i][j] == "#":
            flag = False
if flag:
    print("Yes")
    exit()
if W >= 2 or H >= 2:    
     for i in range(H):
        for j in range(W):
            for k in range(4):
                nx = i+dx[k]
                ny = j+dy[k] 
                if s[i][j] == "#":
                    if 0 <= nx < H and 0 <= ny < W:
                       if s[nx][ny] == "#":
                           ans = "Yes"

print(ans)

Submission status: Wrong Answer

Solution code:
H,W = map(int,input().split())
s = [input() for i in range(H)]
ans = "No"
dx = [1,0,-1,0]
dy = [0,1,0,-1]
for i in range(H):
    for j in range(W):
        for k in range(4):
            nx = i+dx[k]
            ny = j+dy[k] 
            if s[i][j] == "#":
                if 0 <= nx < H and 0 <= ny < W:
                   if s[nx][ny] == "#":
                    ans = "Yes"

print(ans)

Submission status: Wrong Answer

Solution code:
def repaint(h, w, s):
    for i in (1, h+1):
        for p in (1, w+1):
            if s[i][p] == '#':
                if (s[i-1][p] != '#') and (s[i][p+1] != '#') and (s[i+1][p] != '#') and (s[i][p-1] != '#'):
                    return 'No'
    return 'Yes'
H, W = map(int, input().split())
S = [['.']*(W+2)]+[list('.'+input()+'.') for i in range(H)]+[['.']*(W+2)]
print(repaint(H, W, S))

Submission status: Wrong Answer

Solution code:
def repaint(h, w):
    s = [['.']*(w+2)]+[list('.'+input()+'.') for i in range(h)]+[['.']*(w+2)]
    for i in (1, h+1):
        for p in (1, w+1):
            if s[i][p] == '#':
                if (s[i-1][p] != '#') and (s[i][p+1] != '#') and (s[i+1][p] != '#') and (s[i][p-1] != '#'):
                    return 'No'
    return 'Yes'
H, W = map(int, input().split())
print(repaint(H, W))

Submission status: Wrong Answer

Solution code:
def repaint(h, w):
    s = [['.']*(w+2)]+[list('.'+input()+'.') for i in range(h)]+[['.']*(w+2)]
    for i in (1, h+1):
        for p in (1, w+1):
            if s[i][p] == '#':
                if s[i-1][p] == s[i][p+1] == s[i+1][p] == s[i][p-1] == '.':
                    return 'No'
    return 'Yes'
H, W = map(int, input().split())
print(repaint(H, W))

Submission status: Wrong Answer

Solution code:
def repaint(h, w):
    s = [['.']*(w+2)]+[list('.'+input()+'.') for i in range(h)]+[['.']*(w+2)]
    for i in (1, h+1):
        for p in (1, w+1):
            if s[i][p] == '#':
                if s[i-1][p] == s[i][p-1] == s[i+1][p] == s[i][p+1] == '.':
                    return 'No'
    return 'Yes'
H, W = map(int, input().split())
print(repaint(H, W))

Submission status: Wrong Answer

Solution code:
H, W = map(int,input().split())
S = [list(input()) for _ in range(H)]
ans = "No"
for i in range(H):
  for j in range(W):
    if(S[i][j] == "#"):
      if(i > 0 and S[i-1][j] == "#"):
        ans = "Yes"
      elif(i+1 < H and S[i+1][j] == "#"):
        ans = "Yes"
      elif(j > 0 and S[i][j-1] == "#"):
        ans = "Yes"
      elif(j+1 < W and S[i][j+1] == "#"):
        ans = "Yes"
print(ans)

Submission status: Wrong Answer

Solution code:
def main() -> None:
    H, W = map(int, input().split())
    s = ['0' + input() + '0' for _ in range(H)]
    s.insert(0, '0' * (W + 2))
    s.append('0' * (W + 2))
    num = 0
    # for v in s:
    #     print(v)
    for i in range(1, H + 1):
        for j in range(1, W + 1):
            # print(s[j][i])
            if s[i][j] == "#":
                num += 1
                if s[i+1][j] == "#" or s[i-1][j] == "#" or s[i][j+1] == "#" or s[i][j-1] == "#":
                    continue
                else:
                    print("No")
                    exit()
    if num == 0:
        print("No")
    else:
        print("Yes")


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main() -> None:
    H, W = map(int, input().split())
    s = ['0' + input() + '0' for _ in range(H)]
    s.insert(0, '0' * (W + 2))
    s.append('0' * (W + 2))
    num = 0
    # for v in s:
    #     print(v)
    for i in range(1, W + 1):
        for j in range(1, H + 1):
            # print(s[j][i])
            if s[j][i] == "#":
                num += 1
                if s[j+1][i] == "#" or s[j-1][i] == "#" or s[j][i+1] == "#" or s[j][i-1] == "#":
                    continue
                else:
                    print("No")
                    exit()
    if num == 0:
        print("No")
    else:
        print("Yes")


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]
if h == 1 and w == 1:
    print("Yes")
    exit()

for i in range(h):
    for j in range(w):
        if s[i][j] == "#":
            f = False
            if 0 <= i+1 < h and 0 <= i < w and s[i+1][j] == "#":
                f = True
            if 0 <= i-1 < h and 0 <= i < w and s[i-1][j] == "#":
                f = True
            if 0 <= i < h and 0 <= j+1 < w and s[i][j+1] == "#":
                f = True
            if 0 <= i < h and 0 <= j-1 < w and s[i][j-1] == "#":
                f = True
            if not f:
                print("No")
                exit()
print("Yes")

Submission status: Wrong Answer

Solution code:
h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]
if h == 1 and w == 1:
    print("Yes")

for i in range(h):
    for j in range(w):
        if s[i][j] == "#":
            f = False
            if 0 <= i+1 < h and 0 <= i < w and s[i+1][j] == "#":
                f = True
            if 0 <= i-1 < h and 0 <= i < w and s[i-1][j] == "#":
                f = True
            if 0 <= i < h and 0 <= j+1 < w and s[i][j+1] == "#":
                f = True
            if 0 <= i < h and 0 <= j-1 < w and s[i][j-1] == "#":
                f = True
            if not f:
                print("No")
                exit()
print("Yes")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())
l = [["." for i in range(W + 2)]]
for i in range(H):
    temp = list(input())
    temp.insert(0, ".")
    temp.append(".")
    l.append(temp)

l.append(["." for i in range(W + 2)])
Flag = True
for i in range(H + 2):
    if i == 0 or i == H + 1:
        continue
    
    for j in range(W + 2):
        if j == 0 or j == W + 1:
            continue
        if l[i][j] == "#":
            #上下左右
            if l[i-1][j] == "#" or l[i+1][j] == "#" or l[i][j-1] == "#" or l[i][j+1] == "#":
                Flag == False
                break
    
    if Flag == False:
        break 

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

Submission status: Wrong Answer

Solution code:
h,w,*a=list(open(0).read().split())
w,h=int(w),int(h)
for s in range(h-1):
  for t in range(w-1):
    if a[s][t]=="#":
      if a[s][t+1]=="#" or a[s+1][t]=="#":
        continue
      else:
        try:
          if a[s][t-1]=="#":
            continue
          else:
            print("No")
            exit()
        except IndexError:
          continue
s=h-1
for t in range(w-1):
  if a[s][t]=="#":
    if a[s][t+1]=="#" or a[s-1][t]=="#":
      continue
    else:
      try:
        if a[s][t-1]=="#":
          continue
        else:
          print("No")
          exit()
      except IndexError:
        continue
print("Yes")

Submission status: Wrong Answer

Solution code:
h,w,*a=list(open(0).read().split())
w,h=int(w),int(h)
for s in range(h-1):
  for t in range(w-1):
    if a[s][t]=="#":
      if a[s][t+1]=="#" or a[s+1][t]=="#":
        continue
      else:
        try:
          if a[s][t-1]=="#":
            continue
          else:
            print("No")
            exit()
        except IndexError:
          continue
print("Yes")

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
# ----------------------------------------------------------------
# Use Solve Function

def solve(lines):
    def solve_iter(hi, wi):
        vec = [(0,1),(1,0)]
        for v in vec:
            hn = hi + v[0]
            wn = wi + v[1]
            if hn >= 0 and hn < H and wn >= 0 and wn < W:
                if NLIST[hn][wn] == '#':
                    NLIST[hi][wi] = '.'
                    NLIST[hn][wn] = '.'
                    solve_iter(hn, wn)
        return

    H,W = map(int, lines.pop(0).split(' '))
    NLIST = []
    for i in range(H):
        NLIST.append(list(lines.pop(0)) )

    res = 'Yes'
    for i in range(H):
        for j in range(W):
            if NLIST[i][j] == '#':
                solve_iter(i, j)
            if NLIST[i][j] == '#':
                res = 'No'

    print(res)

#
# main
#
lines = [x.strip() for x in sys.stdin.readlines()]

#
# solve !!
#
solve(lines)

Submission status: Wrong Answer

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

def search(arr, x, y):
    dif = ((-1, -1), (-1, 0), (-1, 1), (0, -1), (0, 1), (1, -1), (1, 0), (1, 1))
    flag = 0
    try:
        for dx, dy in dif:
            if (x+dx) >= 0 and (y+dy) >= 0 and arr[x + dx][y + dy] == '#':
                flag = 1
                break
    except:
        pass
    return flag

for i in range(h):
    for j in range(w):
        if s[i][j] == '#':
            if not search(s, i, j):
                print("No")
                exit(0)
print("Yes")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

can = True
for i in range(h-1):
    for j in range(w-1):
        if s[i][j] == '#':
            cnt = 0
            if j+1 < w and s[i][j+1] == '#':
                cnt += 1
            if j-1 > 0 and s[i][j-1] == '#':
                cnt += 1
            if i+1 < h and s[i+1][j] == '#':
                cnt += 1
            if i-1 > 0 and s[i-1][j] == '#':
                cnt += 1
            if cnt > 0:
                continue
            else:
                can = False
                break
    if not can:
        break
if can:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

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

can = True
for i in range(h-1):
    for j in range(w-1):
        if s[i][j] == '#':
            cnt = 0
            if s[i][j+1] == '#':
                cnt += 1
            if j-1 > 0 and s[i][j-1] == '#':
                cnt += 1
            if s[i+1][j] == '#':
                cnt += 1
            if i-1 > 0 and s[i-1][j] == '#':
                cnt += 1
            if cnt > 0:
                continue
            else:
                can = False
                break
    if not can:
        break
if can:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

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

count = 0
pa = 0
for i in range(H):
    for j in range(W):
        a = S[i][j]
        if a == '#':
            if j-1 >= 0 and S[i][j-1] == '#':
                count += 1
            if j+1 <= W-1 and S[i][j+1] == '#':
                count += 1
            if i-1 >= 0 and S[i-1][j] == '#':
                count += 1
            if i+1 <= H-1 and S[i+1][j] == '#':
                count += 1

            if count >= 1:
                continue
            else:
                pa += 1
                break
if pa != 0:
    print('No')
else:
    print('Yes')

Submission status: Wrong Answer

Solution code:
h,w=map(int,input().split())
from collections import defaultdict
data=defaultdict(int)
for y in range(h):
    line=input()
    for x in range(w):
        if line[x]=='.':data[(y,x)]=-1
        if line[x]=='#':
            for i in range(-1,2):
                for j in range(-1,2):
                    if data[(y+i,x+j)]!=-1:
                        if i!=0 or j!=0:
                            data[(y+i,x+j)]+=1
ans=0            
for y in range(h):
    for x in range(w):
        if data[(y,x)]==0:ans+=1
if ans==0:print('Yes')
elif ans>0:print('No')

Submission status: Wrong Answer

Solution code:
h,w=map(int,input().split())
from collections import defaultdict
data=defaultdict(int)
for y in range(h):
    line=input()
    for x in range(w):
        if line[x]=='.':data[(y,x)]=-1
        if line[x]=='#':
            for i in range(-1,2):
                for j in range(-1,2):
                    if data[(y+i,x+j)]!=-1:
                        data[(y+i,x+j)]+=1
ans=0            
for y in range(h):
    for x in range(w):
        if data[(y,x)]==0:ans+=1
if ans==0:print('Yes')
elif ans>0:print('No')

Submission status: Wrong Answer

Solution code:
H ,W =map(int,input().split())
L = []
tmp = ['.' for x in range(W+2)]
L.append(tmp)
for _ in range(H):
    l =  list('.'+input()+'.')
    L.append(l)
L.append(tmp)
flag = 0
for x in range(1,H+1):
    for y in range(1,W+1):
        if L[x-1][y] == L[x][y-1] == L[x+1][y] == L[x][y+1] =='.':
            flag = 1

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

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
from sys import stdin
import sys
import numpy as np



xy = stdin.readline().rstrip().split()
x = int(xy[0])
y = int(xy[1])

data = [stdin.readline().rstrip().split() for _ in range(x)]
print(*data, sep='\n')
print('----------------')

for i in range(x):
    data[i] = list(data[i][0])

arr = np.array(data)
print(arr)
print('----------------')

OK = True
for i in range(x):
    for j in range(y):

        if arr[i][j] == '#':
            can_paint = False

            if i != 0:
                if arr[i-1][j] == '#':
                    can_paint =True

            if j != 0:
                if arr[i][j-1] == '#':
                    can_paint = True

            if i != x-1:
                if arr[i+1][j] == '#':
                    can_paint = True

            if j != y-1:
                if arr[i][j+1] == '#':
                    can_paint = True

            if can_paint != True:
                OK = False

if OK == True:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
r,c = map(int,input().split())
masume = [[0 for i in range(c)] for j in range(r)]
for i in range(r):
	masume[i] = list(input())

thispoint = True
for ri in range(r):
	for ci in range(c):
		if masume[ri][ci] == '#':
			draw = False
			for ar in [-1,0,1]:
				for ac in [-1,0,1]:
					if abs(ar) == abs(ac):
						continue
					chkr = ri + ar
					chkc = ci + ac
					if chkr >= 0 and chkr < r and chkc >= 0 and chkc < c and masume[chkr][chkc] == '#':
						draw = True
						break
			if draw:
				break
			if not(draw):
				thispoint = False
				break
	if not(thispoint):
		break
if thispoint:
	print('Yes')
else:
	print('No')

Submission status: Wrong Answer

Solution code:
hw=[int(i) for i in input().split()]
s=['.'+input()+'.' for i in range(hw[0])]
s=['.'*(hw[1]+2)]+s+['.'*(hw[1]+2)]
print(s)
for i in range(1,hw[0]+1):
    for n in range(1,hw[1]+1):
        if s[i][n]=='#':
            print(s[i])
            if s[i+1][n]==s[i][n+1]==s[i-1][n]==s[i][n-1]=='.':
                print('No')
                exit()
print('Yes')

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(200000)


def input():
    return sys.stdin.readline()[:-1]


def ii(t: type = int):
    return t(input())


def il(t: type = int):
    return list(map(t, input().split()))


def imi(N: int, t: type = int):
    return [ii(t) for _ in range(N)]


def iml(N: int, t: type = int):
    return [il(t) for _ in range(N)]


class PathFinder:
    def __init__(self, num_dst, border):
        if num_dst == 4:
            self.dx = (-1, 0, 0, 1)
            self.dy = (0, -1, 1, 0)
        elif num_dst == 8:
            self.dx = (-1, -1, -1, 0, 0, 1, 1, 1)
            self.dy = (-1, 0, 1, -1, 1, -1, 0, 1)
        self.border = border

    # 周辺探索
    def find_neighbours(self, current_x, current_y):
        for neighbour in zip(self.dx, self.dy):
            neighbour_x = current_x + neighbour[0]
            neighbour_y = current_y + neighbour[1]
            if (
                self.border[0] <= neighbour_x < self.border[1]
                and self.border[2] <= neighbour_y < self.border[3]
            ):
                yield neighbour_x, neighbour_y


def solve():
    from itertools import product

    H, W = il()
    S = imi(H, str)
    board = [[0] * W for _ in range(H)]
    finder = PathFinder(4, (0, H, 0, W))
    for i, j in product(range(H), range(W)):
        for x, y in finder.find_neighbours(i, j):
            if S[i][j] == "#" and S[x][y] == "#":
                board[i][j] += 1
                board[x][y] += 1

    flatten_board = sum(board, [])
    all_0 = all([f == 0 for f in flatten_board])
    any_odd = any([f % 2 == 1 for f in flatten_board])
    if all_0 or any_odd:
        return "No"
    return "Yes"


if __name__ == "__main__":
    print(solve())

Submission status: Wrong Answer

Solution code:
a, b = map(int, input().split())

A = []
A.append(['.']*(b+2))

for i in range(a):
    
    A.append(list('.'+input()+'.'))
A.append(['.']*(b+2))

ans = 0
for i in range(1, a+2):
    for j in range(1, b+2):
        if(A[i][j] == '#'):
            if(A[i][j-1] != "#" and A[i][j+1] != "#" and A[i-1][j] != "#" and A[i+1][j] != "#"):
                print('No')
                ans += 1
                break
    break
if(ans == 0):
    print('Yes')

Submission status: Wrong Answer

Solution code:
N,M = map(int, input().split())
field =[]
field.append(list("."*(M+2)))
for i in range(N):
    t = list("."+input()+".")
    field.append(t)
field.append(list("."*(M+2)))
res = 1
def dfs(x,y):
    r = 0 #周りの”.”の数を数える
    #field[x][y] = "."
    
    for dx in range(-1,2):
        for dy in range(-1,2):
            if abs(dx+dy) ==1: #ここがなかったら周り８マス探す
                nx = x + dx
                ny = y + dy
                if field[nx][ny]==".":
                    r+=1
    if r==4: return 0
    else: return 1
                    
        
                
for i in range(0,N+2):
    for j in range(0,M+2):
        if field[i][j] == "W":
            res = res *dfs(i,j)
            
if res:print("Yes")
else:print("No")

Submission status: Wrong Answer

Solution code:
N,M = map(int, input().split())
field =[]
field.append(list("."*(M+2)))
for i in range(N):
    t = list("."+input()+".")
    field.append(t)
field.append(list("."*(M+2)))
print(field)
res = 1
def dfs(x,y):
    r = 0 #周りの”.”の数を数える
    #field[x][y] = "."
    
    for dx in range(-1,2):
        for dy in range(-1,2):
            if abs(dx+dy) ==1: #ここがなかったら周り８マス探す
                nx = x + dx
                ny = y + dy
                if field[nx][ny]==".":
                    r+=1
    if r==4: return 0
    else: return 1
                    
        
                
for i in range(0,N+2):
    for j in range(0,M+2):
        if field[i][j] == "W":
            res = res *dfs(i,j)
            
if res:print("Yes")
else:print("No")

Submission status: Wrong Answer

Solution code:
#全てのますに対して
#もし#なら、四方の１つでも#ならok
#孤立まんがいたらアウト

H,W= map(int,input().split())
le = [input() for i in range(H)]
answer = [['0' for i in range(W)] for j in range(H)]

ass='Yes'
for i in range(0,H):
    for j in range(0,W):
        bool=False

        if le[i][j]!='#':
            continue
            
        if (i!=H-1):
            if(le[i+1][j]=='#'):
                bool=True


        if (i!=0):
            if(le[i-1][j]=='#'):
                bool=True
    
        if (j!=W-1):
            if(le[i][j+1]=='#'):
                bool=True

        if (j!=0):
            if(le[i][j-1]=='#'):
                bool=True

        if bool==False:
            ans="No"

print(ass)

Submission status: Wrong Answer

Solution code:
H,W=map(int,input().split())
s=[]
s1=[[]for i in range(H)]
dir=[[-1,0],[1,0],[0,-1],[0,1]]
a=0
for i in range(H):
    s.append(input())
for i in range(H):
    for a in s[i]:
        s1[i].append(a)
for i in range(H):
    for j in range(W):
        c=0
        if s1[i][j]=='#':
            for k in dir:
                if i+k[0]>=0 and i+k[0]<H and j+k[1]>=0 and j+k[1]<W and s1[i+k[0]][j+k[1]]=='#':
                    c=1
                    break
        else:
            break
        if c==0:
            a=1
            break
    if a==1:
        break
if a==1:
    print('No')
else:
    print('Yes')

Submission status: Wrong Answer

Solution code:
H,W=map(int,input().split())
s=[]
s1=[[]for i in range(H)]
dir=[[-1,0],[1,0],[0,-1],[0,1]]
a=0
for i in range(H):
    s.append(input())
for i in range(H):
    for a in s[i]:
        s1[i].append(a)
for i in range(H):
    for j in range(W):
        c=0
        if s1[i][j]=='#':
            for k in dir:
                if i+k[0]>=0 and i+k[0]<H and j+k[1]>=0 and j+k[1]<W and s1[i+k[0]][j+k[1]]=='#':
                    c=1
                    break
        else:
            break
        if c==0:
            a=1
            break
if a==1:
    print('No')
else:
    print('Yes')

Submission status: Wrong Answer

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

for i in range(1, h+1):
    for j in range(1, w + 1):
        if array[i][j] == "*" and array[i-1][j] == "." and array[i+1][j] == "." and array[i][j-1] == "." and array[i][j+1] == ".":
            print("No")
            exit()
print("Yes")

Submission status: Wrong Answer

Solution code:
def check_4(i,j):
    hi = [1,0,-1,0]
    wi = [0,-1,0,1] #↓←↑→
    for p in range(4):
        if 0 <= i+hi[p] < H and 0 <= j+wi[p] < W:
            if cambus[i+hi[p]][j+wi[p]] == '#':
                return True
    return False

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

for i in range(H):
    for j in range(W):
        if not check_4(i,j):
            print('No')
            exit()
print('Yes')