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 = []
for i in range(h):
    s.append(list(input()))

for i in range(h):
    for j in range(w):
        if 0 <= i-1:
            up = s[i-1][j]
        else:
            up = s[i][j]
        
        if i+1 < h:
            down = s[i+1][j]
        else:
            down = s[i][j]

        if 0 <= j-1:
            left = s[i][j-1]
        else:
            left = s[i][j]
        
        if j+1 < w:
            right = s[i][j+1]
        else:
            right = s[i][j]
        
        if s[i][j] != up and s[i][j] != down and s[i][j] !=left and s[i][j] != right:
            print("No")
            exit()

print("Yes")

Submission status: Wrong Answer

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

for i in range(h-2):
    for j in range(w-2):
        if (s[i][j] == "#" and s[i][j+1] == "." and s[i][j+2] == "#" and s[i+1][j] == "." and s[i+1][j+1] == "#" and s[i+1][j+2] == ".") or (s[i][j] == "." and s[i][j+1] == "#" and s[i][j+2] == "." and s[i+1][j] == "#" and s[i+1][j+1] == "." and s[i+1][j+1] == "#"):
            print(i)
            print(j)
            print("No")
            exit()

print("Yes")

Submission status: Wrong Answer

Solution code:
#import numpy as np
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
pri = lambda x: print(*x, sep='\n')

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

def check(ny, nx):
    if 0<=ny<H and 0<=nx<W and S[ny][nx]=='#':
        return True
    else:
        return False

ddy = [-1, 0, 1, 0]
ddx = [0, -1, 0, 1]
deq = deque()

def dfs(y, x):
    deq.append([(y, x)]) # insert indices
    S[y][x] = '.'
    found = False
    while deq[0]:
        nqueue = []
        cqueue = deq.popleft()
        for val in cqueue:
            y, x = val
            for dy, dx in zip(ddy, ddx):
                ny, nx = y+dy, x+dx
                if check(ny, nx):
                    found = True
                    S[ny][nx] = '.'
                    nqueue.append((ny, nx))
        if found == False:
            print('No')
            exit()
        deq.append(nqueue)

for y in range(H):
    for x in range(W):
        if S[y][x] == '#':
            dfs(y, x)
else:
    print('Yes')

Submission status: Wrong Answer

Solution code:
h, w = map(int, input().split())
s = [input() for _ in range(h)]
if h == 1 and w == 1 and s[0][0] == '#':
    print('No')
    exit()
for i in range(h):
    for j in range(w):
        if s[i][j] == '#':
            flag = 0
            L = []
            if i == 0 and j == 0:
                L.extend([(0, 1), (1, 0)])
            elif i == 0 and j == w - 1:
                L.extend([(-1, 0), (1, 0)])
            elif i == h - 1 and j == 0:
                L.extend([(-1, 0), (0, 1)])
            elif i == h - 1 and j == w - 1:
                L.extend([(-1, 0), (0, -1)])
            elif i == 0:
                L.extend([(1, 0), (0, -1), (0, 1)])
            elif i == h - 1:
                L.extend([(-1, 0), (0, 1), (0, -1)])
            elif j == 0:
                L.extend([(-1, 0), (1, 0), (0, 1)])
            elif j == w - 1:
                L.extend([(-1, 0), (1, 0), (0, -1)])
            else:
                L.extend([(-1, 0), (1, 0), (0, -1), (0, 1)])
            
            for dx, dy in L:
                    if s[i + dx][j + dy] == '#':
                        flag = 1
            if flag == 0:
                print('No')
                exit()
else:
    print('Yes')

Submission status: Wrong Answer

Solution code:
h, w = map(int, input().split())
s = [input() for _ in range(h)]
for i in range(h):
    for j in range(w):
        if s[i][j] == '#':
            flag = 0
            L = []
            if i == 0 and j == 0:
                L.extend([(0, 1), (1, 0)])
            elif i == 0 and j == w - 1:
                L.extend([(-1, 0), (1, 0)])
            elif i == h - 1 and j == 0:
                L.extend([(-1, 0), (0, 1)])
            elif i == h - 1 and j == w - 1:
                L.extend([(-1, 0), (0, -1)])
            elif i == 0:
                L.extend([(1, 0), (0, -1), (0, 1)])
            elif i == h - 1:
                L.extend([(-1, 0), (0, 1), (0, -1)])
            elif j == 0:
                L.extend([(-1, 0), (1, 0), (0, 1)])
            elif j == w - 1:
                L.extend([(-1, 0), (1, 0), (0, -1)])
            else:
                L.extend([(-1, 0), (1, 0), (0, -1), (0, 1)])
            
            for dx, dy in L:
                    if s[i + dx][j + dy] == '#':
                        flag = 1
            if flag == 0:
                print('No')
                exit()
else:
    print('Yes')

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

c=0
for i in range(h):
  for j in range(w):
    if s[i][j]=='#':
      for x,y in [1,0],[-1,0],[0,1],[0,-1]:
        ny=i+y
        nx=j+x
        if 0<=ny<=h-1 and 0<=nx<=w-1:
          if s[ny][nx]=='#':
            c=1
print('Yes' if c==1 else 'No')

Submission status: Wrong Answer

Solution code:
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10 ** 6)
from collections import defaultdict
from collections import Counter
import fractions
import math
from collections import deque
from bisect import bisect_left
from bisect import insort_left
import itertools
from heapq import heapify
from heapq import heappop
from heapq import heappush
import heapq
import numpy as np
INF = float("inf")
#d = defaultdict(int)
#d = defaultdict(list)
#N = int(input())
#A = list(map(int,input().split()))
#S = list(input())
#S.remove("\n")
#N,M = map(int,input().split())
#S,T = map(str,input().split())
#A = [int(input()) for _ in range(N)]
#S = [input() for _ in range(N)]
#A = [list(map(int,input().split())) for _ in range(N)]
H,W = map(int,input().split())
Map = [["."]*(W+2)]
for _ in range(H):
    Map.append(["."]+list(input())[:-1] + ["."])
Map.append(["."]*(W+2))
flag = 0
for i in range(1,H+1):
    if flag == 1:
        break
    for j in range(1,W+1):
        if Map[i][j] == ".":
            continue
        if Map[i][j+1] == "." and Map[i][j-1] == "." and Map[i+1][j] == "." and Map[i-1][j] == ".":
            print(i,j)
            flag = 1
            break
if flag == 0:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
h,w = map(int,input().split())
s = [input() for i in range(h)]
ans = "Yes"
for i in range(h):
    for j in range(w):
        if s[i][j]=="#":
            a = ""
            b = ""
            if i==h-1:
                a = s[i-1][j]
            elif i==0:
                a = s[i+1][j]
            else:
                a = s[i+1][j]+s[i-1][j]
            if j==0:
                b = s[i][j+1]
            elif j==w-1:
                b = s[i][j-1]
            else:
                b = s[i][j-1]+s[i][j+1]
            if not "#" in a+b:
                ans = "No"
                break
    else:
        break
print(ans)

Submission status: Wrong Answer

Solution code:
def resolve():
  h, w = map(int, input().split())
  s = []
  for i in range(h):
    s.append(input())
  for i in range(h):
    for j in range(w):
      if s[i][j] == '#':
        if j > 0 and s[i][j-1] == '#':
          break
        if j < w-1 and s[i][j+1] == '#':
          break
        if i > 0 and s[i-1][j] == '#':
          break
        if i < h-1 and s[i+1][j] == '#':
          break
        print('No')
        return
  print('Yes')
  return

if __name__ == "__main__":
  resolve()

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 and s[i-1][j] == '#':
                continue
            elif i < H-1 and s[i+1][j] == '#':
                continue
            elif j > 0 and s[i][j-2] == '#':
                continue
            elif j < W-1 and s[i][j+1] == '#':
                continue
            else:
                print("No")
                exit(0)
print("Yes")

Submission status: Wrong Answer

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

for i in range(H):
    for j in range(W):
        if G[i][j] == '.':
            continue
        for dx, dy in dd:
            nx = j + dy; ny = i + dy
            if 0 <= nx < W and 0 <= ny < H:
                if G[ny][nx] == '#':
                    break
        else:
            print('No')
            exit(0)

print('Yes')

Submission status: Wrong Answer

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

for i in range(H):
    for j in range(W):
        if G[i][j] == '.':
            continue
        for dx, dy in dd:
            nx = j + dy; ny = i + dy
            if 0 <= nx < W and 0 <= ny < H:
                if G[ny][nx] == '#':
                    break
        else:
            print('No')
            exit()

print('Yes')

Submission status: Wrong Answer

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

ans = 'Yes'
for i in range(H):
    for j in range(W):
        if G[i][j] == '#':
            if i == 0:
                if j == 0:
                    if G[i+1][j] == '#' or G[i][j+1] == '#':
                        continue
                    else:
                        ans = 'No'
                        break
                elif j == W-1:
                    if G[i+1][j] == '#' or G[i][j-1] == '#':
                        continue
                    else:
                        ans = 'No'
                        break
                else:
                    if G[i+1][j] == '#' or G[i-1][j] == '#' or G[i][j-1] == '#' or G[i][j+1] == '#':
                        continue
                    else:
                        ans = 'No'
                        break
    if ans == 'No':
        break

print(ans)

Submission status: Wrong Answer

Solution code:
#下，右，上，左
dy = [1, 0, -1, 0]
dx = [0, 1, 0, -1]

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

flg = False

for y in range(H):
    for x in range(W):

        if S[y][x] == ".":
            continue

        cnt = 0

        for k in range(4):
            ny = y + dy[k]
            nx = x + dx[k]

            if ny < 0 or ny >= H or nx < 0 or nx >= W:
                continue

            if S[ny][nx] == "#":
                flg = True
                break
        if flg:
            continue
        else:
            print("No")
            exit()

print("Yes")

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(200000)


def read():
    H, W = map(int, input().strip().split())
    S = []
    for i in range(H):
        s = list(input().strip())
        S.append(s)
    return H, W, S


def solve(H, W, S):
    if H == 1 and  W == 1 and S[0][0] == "#":
        return "No"
    
    dd = [(1, 0), (0, 1), (-1, 0), (0, -1)]

    def dfs(y, x):
        depth = 0
        S[y][x] = "."
        for dy, dx in dd:
            ny = y + dy
            nx = x + dx
            if 0 <= ny < H and 0 <= nx < W and S[ny][nx] == "#":
                depth = max(depth, dfs(ny, nx) + 1)
        return depth

    for i in range(H):
        for j in range(W):
            depth = dfs(i, j)
            if depth == 1:
                return "No"
    return "Yes"


if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(200000)


def read():
    H, W = map(int, input().strip().split())
    S = []
    for i in range(H):
        s = list(input().strip())
        S.append(s)
    return H, W, S


def solve(H, W, S):
    dd = [(1, 0), (0, 1), (-1, 0), (0, -1)]

    def dfs(y, x):
        depth = 0
        S[y][x] = "."
        for dy, dx in dd:
            ny = y + dy
            nx = x + dx
            if 0 <= ny < H and 0 <= nx < W and S[ny][nx] == "#":
                depth = max(depth, dfs(ny, nx) + 1)
        return depth

    for i in range(H):
        for j in range(W):
            depth = dfs(i, j)
            if depth == 1:
                return "No"
    return "Yes"


if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))

Submission status: Wrong Answer

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

for i in range(0, H):
    s.append(input())

ans="No"
for y in range(0, H):
    for x in range(0, W):
        if s[y][x]==".":
            continue
        
        for dx in range(-1, 2, 2):
            xx = x + dx
            if 0<=xx and xx<W:
                if s[y][xx]=="#":
                    ans="Yes"
                    break
                    
        for dy in range(-1, 2, 2):
            yy = y + dy
            if 0<=yy and yy<H:
                if s[yy][x]=="#":
                    ans="Yes"
                    break

print(ans)

Submission status: Wrong Answer

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

for i in range(0, H):
    s.append(input())

ans="No"
for y in range(0, H):
    for x in range(0, W):
        if s[y][x]==".":
            continue
        
        c=0
        for dx in range(-1, 2, 2):
            xx = x + dx
            if 0<=xx and xx<W:
                if s[y][xx]=="#":
                    c+=1
                    
        for dy in range(-1, 2, 2):
            yy = y + dy
            if 0<=yy and yy<H:
                if s[yy][x]=="#":
                    c+=1
        
        if c>=4:
            ans="Yes"

print(ans)

Submission status: Wrong Answer

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

for i in range(0, H):
    s.append(input())

ans="No"
for y in range(0, H):
    for x in range(0, W):
        if s[y][x]==".":
            continue

        for dx in range(-1, 2, 2):
            xx = x + dx
            if 0<=xx and xx<W:
                if s[y][xx]=="#":
                    ans="Yes"
                    break
                    
        for dy in range(-1, 2, 2):
            yy = y + dy
            if 0<=yy and yy<H:
                if s[yy][x]=="#":
                    ans="Yes"
                    break

print(ans)

Submission status: Wrong Answer

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

for i in range(0, H):
    s.append(input())

for y in range(0, H):
    for x in range(0, W):
        if s[y][x]==".":
            continue

        for d in range(-1, 2, 2):
            xx = x + d
            yy = y + d
            if 0<=xx and xx<W:
                if s[y][xx]=="#":
                    print("Yes")
                    break
            if 0<=yy and yy<H:
                if s[yy][x]=="#":
                    print("Yes")
                    break
        else:
            continue

        break
    else:
        continue
    
    break
else:
    print("No")

Submission status: Wrong Answer

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

for i in range(0, H):
    s.append(input())

for y in range(0, H):
    for x in range(0, W):
        c=0
        for dx in range(-1, 1):
            xx = x + dx
            if 0<=xx and xx<W:
                if s[y][xx]=="#":
                    c+=1
        if c>=2:
            print("Yes")
            break

        c=0
        for dy in range(-1, 1):
            yy = y + dy
            if 0<=yy and yy<H:
                if s[yy][x]=="#":
                    c+=1
        if c>=2:
            print("Yes")
            break
    else:
        continue
    
    break
else:
    print("No")

Submission status: Wrong Answer

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

for i in range(0, H):
    s.append(input())

for y in range(0, H):
    for x in range(0, W):
        c=0
        for dx in range(-1, 2):
            xx = x + dx
            if 0<=xx and xx<W:
                if s[y][xx]=="#":
                    c+=1
        if c>=3:
            print("Yes")
            break

        c=0
        for dy in range(-1, 2):
            yy = y + dy
            if 0<=yy and yy<H:
                if s[yy][x]=="#":
                    c+=1
        if c>=3:
            print("Yes")
            break
    else:
        continue
    
    break
else:
    print("No")

Submission status: Wrong Answer

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

for i in range(0, H):
    s.append(input())

ans=""
for y in range(0, H):
    for x in range(0, W):
        c=0
        for dx in range(-1, 1):
            xx = x + dx
            if 0<=xx and xx<W:
                if s[y][xx]=="#":
                    c+=1
        if c>=2:
            ans = "Yes"

        c=0
        for dy in range(-1, 1):
            yy = y + dy
            if 0<=yy and yy<H:
                if s[yy][x]=="#":
                    c+=1
        if c>=2:
            ans = "Yes"

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

Submission status: Wrong Answer

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

for i in range(0, H):
    s.append(input())

ans=""
for y in range(0, H):
    for x in range(0, W):
        c=0
        for dx in range(-1, 2, 2):
            xx = x + dx
            if 0<=xx and xx<W:
                if s[y][xx]=="#":
                    c+=1
        if c>=2:
            ans = "Yes"

        c=0
        for dy in range(-1, 2, 2):
            yy = y + dy
            if 0<=yy and yy<H:
                if s[yy][x]=="#":
                    c+=1
        if c>=2:
            ans = "Yes"

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

Submission status: Wrong Answer

Solution code:
import itertools

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

ok = True        
for i in range(H):
  for j in range(W):
    if S[i][j] == '#':
      for x,y in itertools.product([-1,0,1],repeat=2):
        if not (abs(x) + abs(y) == 1):
          continue
        nx = i + x;ny = j + y
        if 0 <= nx < H and 0 <= ny < W:
          if S[nx][ny] == '.':
            ok = False
            break
if ok:
  print('Yes')
else:
  print('No')

Submission status: Wrong Answer

Solution code:
import itertools

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

VALID = [[False] * W for _ in range(H)]

def dfs(h,w,parent):
  if parent:
    VALID[h][w] = True

  nxt = [-1,0,1]
  ok = False
  for x,y in itertools.product(nxt,repeat=2):
    if not (abs(x) + abs(y) == 1):
      continue
    nx = h + x
    ny = w + y
    if 0 <= nx < H and 0 <= ny < W and S[nx][ny] == '#' and not VALID[nx][ny]:
      ok = True
      dfs(nx,ny,True)
  
  if not parent and ok:
    VALID[h][w] = True
      
for i in range(H):
  for j in range(W):
    if S[i][j] == '.':
      VALID[i][j] = True
    else:
      if not VALID[i][j]:
        #dfs(i,j,False)
        pass
        
if all(sum(VALID,[])):
  print('Yes')
else:
  print('No')

Submission status: Wrong Answer

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

count = 0

for y in range(h):
    for x in range(w):
        cnt = 0
        for k in range(4):
            ny = y + dy[k]
            nx = x + dx[k]
            if nx < 0 or nx>=w or ny < 0 or ny >=h:
                continue
            if s[y][x] == '.':
                continue
            if s[y][x] == '#':
                if s[ny][nx] == '#':
                    cnt += 1
        if cnt == 0:
            print('No')
            exit()

                        
print('Yes')

Submission status: Wrong Answer

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

count = 0

for y in range(h):
    for x in range(w):
        cnt = 0
        for k in range(4):
            ny = y + dy[k]
            nx = x + dx[k]
            if nx < 0 or nx>=w or ny < 0 or ny >=h:
                continue
            if s[y][x] == '.':
                continue
            if s[y][x] == '#':
                if s[ny][nx] == '#':
                    cnt += 1
            if cnt == 0:
                print('No')
                exit()

                        
print('Yes')

Submission status: Wrong Answer

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

count = 0

for y in range(h):
    for x in range(w):
        cnt = 0
        for k in range(4):
            ny = y + dy[k]
            nx = x + dx[k]
            if nx < 0 or nx>=w or ny < 0 or ny >=h:
                continue
            if s[y][x] == '.':
                continue
            if s[y][x] == '#':
                if s[ny][nx] == '#':
                    cnt += 1
                if cnt == 0:
                    print('No')
                    exit()

                        
print('Yes')

Submission status: Wrong Answer

Solution code:

h, w = map(int,input().split())
# In[]
s = [list(input()) for _ in range(h)]
dx = [0,1,0,-1]
dy = [1,0,-1,0]


for y in range(h):
    for x in range(w):
        cnt = 0
        for k in range(4):
            ny = y + dy[k]
            nx = x + dx[k]
            if nx < 0 or nx>=w or ny < 0 or ny >=h:
                continue
            if s[y][x] == '#':
                if s[ny][nx] == '#':
                    cnt += 1
                    if cnt == 0:
                        print('No')
                        exit()
                        
print('Yes')

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
H,W = list(map(int,input().split()))
table = []
for i in range(H):
    table.append(list(input()))
if table == [["#"]]:
    print("No")
    exit()
for i in range(H):
    for j in range(W):
        A = table[i][j]
        if A == "#":
            try:
                if table[i-1][j] == "#":
                    break
            except IndexError:
                pass
            try:
                if table[i+1][j] == "#":
                    break
            except IndexError:
                pass
            try:
                if table[i][j-1] == "#":
                    break
            except IndexError:
                pass
            try:
                if table[i][j+1] == "#":
                    break
            except IndexError:
                pass
            print("No")
            exit()
        else:
            continue
print("Yes")

Submission status: Wrong Answer

Solution code:
H,W = list(map(int,input().split()))
table = []
for i in range(H):
    table.append(list(input()))
for i in range(H):
    for j in range(W):
        A = table[i][j]
        if A == "#":
            try:
                if table[i-1][j] == "#":
                    break
            except IndexError:
                pass
            try:
                if table[i+1][j] == "#":
                    break
            except IndexError:
                pass
            try:
                if table[i][j-1] == "#":
                    break
            except IndexError:
                pass
            try:
                if table[i][j+1] == "#":
                    break
            except IndexError:
                pass
            print("No")
            exit()
        else:
            continue
print("Yes")

Submission status: Wrong Answer

Solution code:
from sys import stdin


if __name__ == "__main__":
    _in = [_.rstrip() for _ in stdin.readlines()]
    H, W = list(map(int,_in[0].split(' ')))  # type:list(int)
    s_arr = []
    for i in range(H):
        _ = [_ for _ in _in[i+1]]   # type:list(str)
        s_arr.append(_)
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    TF = 'Yes'
    for i in range(H):
        if i!=0 and i!=H-1 and TF == 'Yes':
            for j in range(W):
                if j!=0 and j!=W-1 and s_arr[i][j] == '#':
                    adjacent = []
                    if i>1:
                        if s_arr[i-1][j] == '#':
                            continue
                    if i<H-1: 
                        if s_arr[i+1][j] == '#':
                            continue
                    if j>1:   
                        if s_arr[i][j-1] == '#':
                            continue
                    if j<W-1: 
                        if s_arr[i][j+1] == '#':
                            continue
                    TF = 'No'
                    break
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    print(TF)

Submission status: Wrong Answer

Solution code:
from sys import stdin


if __name__ == "__main__":
    _in = [_.rstrip() for _ in stdin.readlines()]
    H, W = list(map(int,_in[0].split(' ')))  # type:list(int)
    s_arr = []
    for i in range(H):
        _ = [_ for _ in _in[i+1]]   # type:list(str)
        s_arr.append(_)
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    TF = 'Yes'
    for i in range(H):
        if TF == 'Yes':
            for j in range(W):
                if s_arr[i][j] == '#':
                    adjacent = []
                    if i>1:   
                        if s_arr[i-1][j] == '#':
                            continue
                    if i<H-1: 
                        if s_arr[i+1][j] == '#':
                            continue
                    if j>1:   
                        if s_arr[i][j-1] == '#':
                            continue
                    if j<W-1: 
                        if s_arr[i][j+1] == '#':
                            continue
                    TF = 'No'
                    break
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    print(TF)

Submission status: Wrong Answer

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

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

if (H == 1) and (W == 1):
    print('Yes')
else:
    cnt_list = []
    for i in range(1,H+1):
        for j in range(1, W+1):
            if S[i][j] == '.':
                cnt_list.append(1)
            else:
                ser = S[i-1][j] + S[i][j-1] + S[i][j+1] + S[i+1][j] + S[i+1][j+1]
                cnt_list.append(ser.count('#'))
    if 0 in cnt_list:
        print('No')
    else:
        print('Yes')

Submission status: Wrong Answer

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

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

cnt_list = []
for i in range(1,H+1):
    for j in range(1, W+1):
        if S[i][j] == '.':
            cnt_list.append(1)
        else:
            ser = S[i-1][j] + S[i][j-1] + S[i][j+1] + S[i+1][j] + S[i+1][j+1]
            cnt_list.append(ser.count('#'))
if 0 in cnt_list:
    print('No')
else:
    print('Yes')

Submission status: Wrong Answer

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

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

cnt_list = []
for i in range(1,H+1):
    for j in range(1, W+1):
        if S[i][j] == '.':
            pass
        else:
            ser = S[i-1][j] + S[i][j-1] + S[i][j+1] + S[i+1][j] + S[i+1][j+1]
            cnt_list.append(ser.count('#'))
if 0 in cnt_list:
    print('No')
else:
    print('Yes')

Submission status: Wrong Answer

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



for j in range(len(s) - 1):
    for i in range(len(s[j]) - 1):
        if s[j][i] == "#" and s[j][i] != s[j][i+1] and (s[j][i] != s[j][i-1] or i == 0):
            if s[j][i] != s[j+1][i] and (s[j][i] != s[j-1][i] or j == 0):
                print(j, i)
                print("No")
                exit()

print("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
            else:
                flag = False
                break
        else:
            continue
        break 
    if flag == False:
        break

                

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