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:
# from pprint import pprint
# import math
# import collections

# n = int(input())
h, w = map(int, input().split(' '))
# a = list(map(int, input().split(' ')))
s = []
for i in range(h):
    s.append(list(input()))

# すべての黒マスについて、上下左右に隣接している黒マスがあるかどうかを調べてあればOK
check = [[None] * w for i in range(h)]

for i in range(h):
    for j in range(w):
        if s[i][j] == '#':
            check[i][j] = False
            if i > 0 and s[i - 1][j] == '#':
                check[i][j] = True
                check[i - 1][j] = True

            if i < h - 1 and s[i + 1][j] == '#':
                check[i][j] = True
                check[i + 1][j] = True

            if j > 0 and s[i][j - 1] == '#':
                check[i][j] = True
                check[i][j - 1] = True

            if j < w - 1 and s[i][j + 1] == '#':
                check[i][j] = True
                check[i][j + 1] = True
        else:
            check[i][j] = True

print(all([all(c) for c in check]))

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())
S = [list(input()) for i in range(H)]
ans = 'Yes'
for i in range(H):
  for j in range(W):
    if S[i][j] == '#':
      a = 0
      if i > 0:
        if S[i-1][j] == '#':
          a = 1
      if i < H-1:
        if S[i+1][j] == '#':
          a = 1
      if j > 0:
        if S[i][j-1] == '#':
          a = 1
      if j < W-1:
        if S[i][j+1] == '#':
          a = 1
      if a == 0:
        ans = 'No'
        break
    else:
      continue
    break
  else:
    continue
  break
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

def err():
    print('No')
    quit()
n,m = inpl()
s = [input() for _ in range(n)]
if sum([1 if x=='#' else 0 for i in range(n) for x in s[i]]) == 0:
    err()
dx = (0,1,0,-1)
dy = (1,0,-1,0)
for i in range(n):
    for j in range(m):
        if s[i][j] == '#':
            for d in range(4):
                nx = dx[d]+j
                ny = dy[d]+i
                if 0 <= nx < m and 0 <= ny < n:
                    if s[ny][nx] == '#':
                        break
            else:
                err()
print('Yes')

Submission status: Wrong Answer

Solution code:
h,w = map(int,input().split())
flag = 0
for i in range(h):
  s = input()
  for j in range(w):
    if s[j] == "#":
      if j != w-1:
        if s[j+1] == "#":
          flag += 1
if flag == 0:
  print("No")
else:
  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] == '#':
            if i != 0 and s[i-1][j] == '#':
                break
            if i != h-1 and s[i+1][j] == '#':
                break
            if j != 0 and s[i][j-1] == '#':
                break
            if j != w-1 and s[i][j+1] == '#':
                break
            print('No')
            exit()
print('Yes')

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

def solve(h,w,s):
    for i in range(1,h):
        for j in range(1,w):
            if not (s[i][j] == s[i-1][j] or \
                    s[i][j] == s[i+1][j] or \
                    s[i][j] == s[i][j-1] or \
                    s[i][j] == s[i][j+1]):
                return "No"
    return "Yes"



def main():
    H,W = map(int,input().split())
    s = ['.'*55]*55
    for i in range(H):
        s[i] = input() + '.'*(55-W)
    print(solve(H,W,s))
    return

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

def solve(h,w,s):
    for i in range(1,h-1):
        for j in range(1,w-1):
            if not (s[i][j] == s[i-1][j] or \
                    s[i][j] == s[i+1][j] or \
                    s[i][j] == s[i][j-1] or \
                    s[i][j] == s[i][j+1]):
                return "No"
    return "Yes"



def main():
    H,W = map(int,input().split())
    s = ['.'*55]*55
    for i in range(H):
        s[i] = input() + '.'*(55-W)
    print(solve(H,W,s))
    return

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

def solve(h,w,s):
    for i in range(h):
        for j in range(w):
            if not (s[i][j] == s[i-1][j] or \
                    s[i][j] == s[i+1][j] or \
                    s[i][j] == s[i][j-1] or \
                    s[i][j] == s[i][j+1]):
                return "No"
    return "Yes"



def main():
    H,W = map(int,input().split())
    s = ['.'*55]*55
    for i in range(H):
        s[i] = input() + '.'*(55-W)
    print(solve(H,W,s))
    return

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

flag = 0

for j in range(1, h-1):
  for k in range(1, w-1):
#    print(j,k)
#    print(s[j][k],s[j+1][k],s[j-1][k],s[j][k+1],s[j][k-1])
    if s[j][k] != s[j+1][k] and s[j][k] != s[j-1][k] and s[j][k] != s[j][k+1] and s[j][k] != s[j][k-1]:
      flag += 1
      
if flag > 1:
  print("No")
else:
  print("Yes")

Submission status: Wrong Answer

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

flag = 0

for j in range(1, h-1):
  for k in range(1, w-1):
#    print(j,k)
#    print(s[j][k],s[j+1][k],s[j-1][k],s[j][k+1],s[j][k-1])
    if s[j][k] != s[j+1][k] or s[j][k] != s[j-1][k] or s[j][k] != s[j][k+1] or s[j][k] != s[j][k-1]:
      flag += 1
      
if flag > 1:
  print("No")
else:
  print("Yes")

Submission status: Wrong Answer

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

flag = 0

for j in range(1, h-1):
  for k in range(1, w-1):
    print(j,k)
    print(s[j][k],s[j+1][k],s[j-1][k],s[j][k+1],s[j][k-1])
    if s[j][k] != s[j+1][k] or s[j][k] != s[j-1][k] or s[j][k] != s[j][k+1] or s[j][k] != s[j][k-1]:
      flag += 1
      
if flag > 1:
  print("No")
else:
  print("Yes")

Submission status: Wrong Answer

Solution code:
h,w = map(int,input().rsplit())
s = []
s.append("."*(w+2))
for i in range(h):
	s.append("."+input()+".")
s.append("."*(w+2))
count = 0
ans = 0
for i in range(1,h+1):
	for j in range(1,w+1):
		if s[i][j] == "#":
			if s[i-1][j] == "#":
				count+=1
			elif s[i+1][j] == "#":
				count +=1
			elif s[i][j-1] == "#":
				count +=1
			elif s[i][j+1] == "#":
				count +=1
			else:
				ans = 1
				break

if ans == 0:
	print("YES")
if ans == 1:
	print("NO")

Submission status: Wrong Answer

Solution code:
h,w = map(int,input().rsplit())
s = []
s.append("."*(w+2))
for i in range(h):
	s.append("."+input()+".")
s.append("."*(w+2))
count = 0
for i in range(1,h+1):
	for j in range(1,w+1):
		if s[i][j] == "#":
			if s[i-1][j] == "#":
				count +=1
			elif s[i+1][j] == "#":
				count += 1
			elif s[i][j-1] == "#":
				count += 1
			elif s[i][j+1] == "#":
				count += 1
			else:
				print("NO")
				break
print("YES")

Submission status: Wrong Answer

Solution code:
h, w = map(int, input().split())
cambus = [list(input()) for _ in range(h)]
for i in range(h):
    for j in range(w):
        if cambus[i][j] == '#':
            if i-1 >= 0 and cambus[i-1][j] == '#':
                break
            elif j-1 >= 0 and cambus[i][j-1] == '#':
                break
            elif i+1 <= h-1 and cambus[i+1][j] == '#':
                break
            elif j+1 <= w-1 and cambus[i][j+1] == '#':
                break
            else:
                print('No')
                exit()
print('Yes')

Submission status: Wrong Answer

Solution code:
h,w = map(int,input().split())
grid = []
grid.append(["."]*(w+2))
for i in range(h):
    grid.append(["."]+list(input())+["."])
grid.append(["."]*(w+2))
dx = [0,1,0,-1]
dy = [1,0,-1,0]
for i in range(h):
    for j in range(w):
        if grid[h][w] == "#":
            ok = False
            for k in range(4):
                if grid[i+dy[k]][j+dx[k]] == "#":
                    ok = True
            if not ok:
                print("No")
                exit()
print("Yes")

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())
G = []
for i in range(H):
    G.append(list(input()))
ans = "Yes"
if H == 1 and W == 1:
    if G[0][0] == '#':
        print('No')
        exit()
    else:
        print('Yes')
        exit()
for i in range(H-1):
    for j in range(W-1):
        boo = True
        if G[i][j] == '#':
            if G[i][j+1] == '#' and j+1 < W:
                boo = True
            elif G[i][j-1] == '#' and j-1 > 0:
                boo = True
            elif G[i+1][j] == '#' and i+1 < H:
                boo = True
            elif G[i-1][j] == '#' and i-1 > 0:
                boo = True
            else:
                boo = False
        if not boo:
            ans = "No"
            break
print(ans)

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())
G = []
for i in range(H):
    G.append(list(input()))
ans = "Yes"
if H == 1 and W == 1:
    if G[0][0] == '#':
        ans = "No"
for i in range(H - 1):
    for j in range(W - 1):
        boo = True
        if G[i][j] == '#':
            if G[i][j+1] == '#' and j+1 < W:
                boo = True
            elif G[i][j-1] == '#' and j-1 > 0:
                boo = True
            elif G[i+1][j] == '#' and i+1 < H:
                boo = True
            elif G[i-1][j] == '#' and i-1 > 0:
                boo = True
            else:
                boo = False
        if not boo:
            ans = "No"
            break
print(ans)

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())
G = []
for i in range(H):
    G.append(list(input()))
ans = "Yes"
if H == 1 and W == 1:
    if not (G[0][0] == '#' and G[1][0] == '#'):
        ans = "No"        
for i in range(H - 1):
    for j in range(W - 1):
        boo = True
        if G[i][j] == '#':
            if G[i][j+1] == '#' and j+1 < W:
                boo = True
            elif G[i][j-1] == '#' and j-1 > 0:
                boo = True
            elif G[i+1][j] == '#' and i+1 < H:
                boo = True
            elif G[i-1][j] == '#' and i-1 > 0:
                boo = True
            else:
                boo = False
        if not boo:
            ans = "No"
            break
print(ans)

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())
G = []
for i in range(H):
    G.append(list(input()))
ans = "Yes"
for i in range(H - 1):
    for j in range(W - 1):
        boo = True
        if G[i][j] == '#':
            if G[i][j+1] == '#' and j+1 < W:
                boo = True
            elif G[i][j-1] == '#' and j-1 > 0:
                boo = True
            elif G[i+1][j] == '#' and i+1 < H:
                boo = True
            elif G[i-1][j] == '#' and i-1 > 0:
                boo = True
            else:
                boo = False
        if not boo:
            ans = "No"
            break
print(ans)

Submission status: Wrong Answer

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


flag=True



for i in range(1,h+1):
    for j in range(1,w+1):
        if s[i][j]=="#":
            if s[i-1][j-1]=="." and s[i-1][j]=="." and s[i][j+1]=="." and s[i][j-1]=="." and s[i][j+1]=="." and s[i+1][j-1]=="." and s[i+1][j]=="." and s[i+1][j+1]==".":
                flag=False

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

Submission status: Wrong Answer

Solution code:
def main():
    H,W=map(int,input().split())
    m=[input() for _ in range(H)]
    is_ok = True
    for h in range(H):
        for w in range(W):
            if m[h][w] == "#":
                if 0 < h-1 and m[h-1][w] == "#":
                    pass
                elif 0 < w-1 and m[h][w-1] == "#":
                    pass
                elif h+1 < H and m[h+1][w] == "#":
                    pass
                elif w+1 < W and m[h][w+1] == "#":
                    pass
                else:
                    print("No")
                    return
    print("Yes")
        
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

flag=True
for i in range(1,h+1):
    for j in range(1,w+1):
        if s[i][j]=='#' and s[i-1][j]=='.' and s[i][j-1]=='.' and s[i+1][j]=='.' and s[i+1][j+1]=='.':
            flag=False
print('Yes' if flag else 'No')

Submission status: Wrong Answer

Solution code:
#関数リスト
import sys
import numpy as np
input = sys.stdin.readline

 
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

h, w = MI()
mylist = [input().rstrip() for i in range(h)]


def find(x, y):
    if x == 0 and y == 0:
        if (mylist[0])[1] == "#" or (mylist[1])[0] == "#":
            return True
    elif x == 0 and y == w-1:
        if (mylist[0])[w-2] == "#" or (mylist[1])[w-1] == "#":
            return True
    elif x == 0:
        if (mylist[0])[y-1] == "#" or (mylist[0])[y+1] == "#" or (mylist[1])[y] == "#":
            return True
    elif x == h-1 and y == 0:
        if (mylist[h-1])[1] == "#" or (mylist[h-2])[0] == "#":
            return True        
    elif x == h-1 and y == w-1:
        if (mylist[h-1])[w-2] == "#" or (mylist[h-2])[w-1] == "#":
            return True
    elif x == h-1:
        if (mylist[h-1])[y-1] == "#" or (mylist[h-1])[y+1] == "#" or (mylist[h-2])[y] == "#":
            return True
    elif y == w-1:
        if (mylist[x-1])[y] == "#" or (mylist[x+1])[y] == "#" or (mylist[x])[y-1] == "#":
            return True
    elif y == 0:
        if (mylist[x-1])[y] == "#" or (mylist[x+1])[y] == "#" or (mylist[x])[y+1] == "#":
            return True 
    else:
        if (mylist[x-1])[y] == "#" or (mylist[x+1])[y] == "#" or (mylist[x])[y-1] == "#" or (mylist[x])[y+1] == "#":
            return True        
        
def main():
    for i in range(h):
        for j in range(w):
            if not(find(i, j)):
                print("No")
                sys.exit()
    print("Yes")

main()

Submission status: Wrong Answer

Solution code:
#関数リスト
import sys
import numpy as np
input = sys.stdin.readline

 
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

h, w = MI()
mylist = [input().rstrip() for i in range(h)]


def find(x, y):
    if x == 0 and y == 0:
        if (mylist[0])[1] == "#" or (mylist[1])[0] == "#":
            return True
    elif x == 0 and y == w-1:
        if (mylist[0])[w-2] == "#" or (mylist[1])[w-1] == "#":
            return True
    elif x == 0:
        if (mylist[0])[y-1] == "#" or (mylist[0])[y+1] == "#" or (mylist[1])[y] == "#":
            return True
    elif x == h-1 and y == 0:
        if (mylist[h-1])[1] == "#" or (mylist[h-2])[0] == "#":
            return True        
    elif x == h-1 and y == w-1:
        if (mylist[h-1])[w-2] == "#" or (mylist[h-2])[w-1] == "#":
            return True
    elif x == h-1:
        if (mylist[h-1])[y-1] == "#" or (mylist[h-1])[y+1] == "#" or (mylist[h-2])[y] == "#":
            return True
    elif y == w-1:
        if (mylist[x-1])[y] == "#" or (mylist[x+1])[y] == "#" or (mylist[x])[y-1] == "#":
            return True        
    else:
        if (mylist[x-1])[y] == "#" or (mylist[x+1])[y] == "#" or (mylist[x])[y-1] == "#" or (mylist[x])[y+1] == "#":
            return True        
        
def main():
    for i in range(h):
        for j in range(w):
            if not(find(i, j)):
                print("No")
                sys.exit()
    print("Yes")

main()

Submission status: Wrong Answer

Solution code:
#関数リスト
import sys
import numpy as np
input = sys.stdin.readline

 
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

h, w = MI()
mylist = [input().rstrip() for i in range(h)]


def find(x, y):
    if x == 0 and y == 0:
        if (mylist[0])[1] == "#" or (mylist[1])[0] == "#":
            return True
    elif x == 0 and y == w-1:
        if (mylist[0])[w-2] == "#" or (mylist[1])[w-1] == "#":
            return True
    elif x == 0:
        if (mylist[0])[y-1] == "#" or (mylist[0])[y+1] == "#" or (mylist[1])[y] == "#":
            return True
    elif x == h-1 and y == 0:
        if (mylist[h-1])[1] == "#" or (mylist[h-2])[0] == "#":
            return True        
    elif x == h-1 and y == w-1:
        if (mylist[h-1])[w-2] == "#" or (mylist[h-2])[w-1] == "#":
            return True
    elif x == h-1:
        if (mylist[h-1])[y-1] == "#" or (mylist[h-1])[y+1] == "#" or (mylist[h-2])[y] == "#":
            return True
    else:
        if (mylist[x-1])[y] == "#" or (mylist[x+1])[y] == "#" or (mylist[x])[y-1] == "#" or (mylist[x])[y+1] == "#":
            return True        
        
def main():
    for i in range(h):
        for j in range(w):
            if not(find(i, j)):
                print("No")
                sys.exit()
    print("Yes")

main()

Submission status: Wrong Answer

Solution code:
h,w=map(int,input().split())
d=[['.']*(w+2) for j in range(h+2)]
for hh in range(h):
  moji=input()
  for ww in range(w):
    d[hh+1][ww+1]=moji[ww]
for k in range(1,h+1):
  for l in range(1,w+1):
    if all(aa=='.' for aa in [d[k-1][l],d[k+1][l],d[k][l-1],d[k][l+1]]):
      print('No')
      exit()
print('Yes')

Submission status: Wrong Answer

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
#from decimal import *
 
H, W = MAP()
s = [input() for _ in range(H)]

dy = (1, 0, -1, 0)
dx = (0, -1, 0, 1)

for x in range(W):
	for y in range(H):
		if s[y][x] =="#":
			for i in range(4):
				ny = y + dy[i]
				nx = x + dx[i]
				if 0 <= ny < H and 0 <= nx < W and s[ny][nx] == "#":
					break
			else:
				print("NO")
				exit()

print("YES")

Submission status: Wrong Answer

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

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

for i in range(H):
  for j in range(W):
    ok=0
    if S[i][j]=='#':
      for k in range(4):
        x=i+dx[k]
        y=j+dy[k]
        if 0<=x<W and 0<=y<H and S[y][x]=='#':
          ok=1
          break
      if ok==0:
        print('No')
        exit()
print('Yes')

Submission status: Wrong Answer

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

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

for i in range(H):
  for j in range(W):
    ok=0
    if S[i][j]=='#':
      for k in range(4):
        x=i+dx[k]
        y=j+dy[k]
        if 0<=x<W and 0<=y<H:
          if S[x][y]=='#':
            ok=1
            break
      if ok==0:
        print('No')
        exit()
print('Yes')

Submission status: Wrong Answer

Solution code:
h,w = map(int, input().split())
original = [list(input()) for _ in range(h)]
for i in range(h-1):
  for j in range(w-1):
    if original[i][j]=='#' and original[i-1][j]!='#' and original[i+1][j]!='#' and original[i][j-1]!='#' and original[i][j+1]!='#':
      print(i,j)
      print('No')
      exit()
      
print('Yes')

Submission status: Wrong Answer

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

listHW = []
flag = False
for i in range(0, h):
  listHW.append(list(input()))

  
for i in range(0, len(listHW)):
  if flag:
    break
  listw = listHW[i]
  #print("listw", listw)
  for ii in range(0, len(listw)):
    w = listw[ii]
    if w == "#":

      if i == 0:
        #右上
        if ii == len(listw)-1:
          if w == listHW[i+1][ii] or w == listw[ii-1]:
            break
        #左上
        elif ii == 0:
          if w == listHW[i+1][ii] or w == listw[ii+1]:
            break 
        #上段
        elif w == listw[ii+1] or w == listw[ii-1] or w == listHW[i+1][ii]:
          break

      elif i == len(listHW)-1:
        #右下
        if ii == len(listw)-1:
          if w == listHW[i-1][ii] or w == listw[ii-1]:
            break
        #左下
        elif ii == 0:
          if w == listHW[i-1][ii] or w == listw[ii+1]:
            break 
        #下段
        elif w == listw[ii+1] or w == listw[ii-1] or w == listHW[i-1][ii]:
          break
      
      #左列
      elif ii == 0:
        if w == listw[ii+1]  or w == listHW[i-1][ii] or w == listHW[i+1][ii]:
          break
      #右列
      elif ii == len(listw)-1:
        if w == listw[ii-1]  or w == listHW[i-1][ii] or w == listHW[i+1][ii]:
          break
              
      #通常
      elif w == listw[ii-1] or w == listw[ii+1]or w == listHW[i-1][ii] or w == listHW[i+1][ii]:
        break

      #隣接するものがなかった時点で終了      
      flag = True
      break
    
    #「.」だったときはとばす
    else:
      continue
    



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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

listHW = []
flag = False
for i in range(0, h):
  listHW.append(list(input()))

  
for i in range(0, len(listHW)):
  if flag:
    break
  listw = listHW[i]
  #print("listw", listw)
  for ii in range(0, len(listw)):
    w = listw[ii]
    if w == "#":

      if i == 0:
        if ii == len(listw)-1:
          if w == listHW[i+1][ii]:
            break
        elif w == listw[ii + 1] or w == listHW[i+1][ii]:
          break

      elif i == len(listHW)-1:
        if ii == len(listw)-1:
          if w == listHW[i-1][ii]:
            break
        elif w == listw[ii + 1] or w == listHW[i-1][ii]:
          break

      else:
        if ii == len(listw)-1:
          if w == listHW[i-1][ii] or w == listHW[i+1][ii]:
            break

        elif w == listw[ii + 1] or w == listHW[i-1][ii] or w == listHW[i+1][ii]:
          break
    else:
      continue

    flag = True

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

Submission status: Wrong Answer

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

listHW = []
flag = False
for i in range(0, h):
  listHW.append(list(input()))

  
for i in range(0, len(listHW)):
  if flag:
    break
  listw = listHW[i]
  #print("listw", listw)
  for ii in range(0, len(listw)):
    w = listw[ii]
    if w == "#":

      if i == 0:
        if ii == len(listw)-1:
          if w == listHW[i+1][ii]:
            w = "OK"
            break
        elif w == listw[ii + 1] or w == listHW[i+1][ii]:
          w = "OK"
          break
        elif ii == len(listw)-1:
          if w == listHW[i-1][ii] or w == listHW[i-1][ii]:
            w = "OK"
            break

      elif i == len(listHW)-1:
        if ii == len(listw)-1:
          if w == listHW[i-1][ii]:
            w = "OK"
            break
        elif w == listw[ii + 1] or w == listHW[i-1][ii]:
          w = "OK"
          break

      else:
        if ii == len(listw)-1:
          if w == listHW[i-1][ii] or w == listHW[i+1][ii]:
            w = "OK"
            break

        elif w == listw[ii + 1] or w == listHW[i-1][ii] or w == listHW[i+1][ii]:
          w = "OK"
          break
    else:
      continue

    flag = True

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

Submission status: Wrong Answer

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

for i in range(h):
    for j in range(w):
        if table[i][j] == "#":
            if i - 1 >= 0 and table[i-1][j] == "#":
                ok = True
            elif i + 1 <= h-1 and table[i+1][j] == "#":
                ok = True
            elif j - 1 >= 0 and table[i][j-1] == "#":
                ok = True
            elif j + 1 <= w-1 and table[i][j+1] == "#":
                ok = True
            else:
                ok = False
            if ok == False:
                 print("NO")
                 exit()
print("YES")

Submission status: Wrong Answer

Solution code:
import sys

a = sys.stdin.readline().split(' ')
data = sys.stdin.readlines()

S = int(a[0])
H = int(a[1])

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

ans = 'Yes'
for i in range(S):
    for j in range(H):
        if data[i][j] == '.':
            continue
        else:
            for k in range(4):
                x = j + dx[k]
                y = i + dy[k]
                if x < 0 or y < 0 or x >= H or y >= S:
                    continue
                else:
                    if data[y][x] == "#":
                        ans = 'Yes'
                        break
                    else:
                        ans = 'No'
                        continue

print(ans)

Submission status: Wrong Answer

Solution code:
import sys

a = sys.stdin.readline().split(' ')
data = sys.stdin.readlines()

S = int(a[0])
H = int(a[1])

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

ans = 'Yes'
if S == 1 and H == 1:
    ans = 'Yes'
else:
    for i in range(S):
        for j in range(H):
            if data[i][j] == '.':
                continue
            else:
                for k in range(4):
                    x = j + dx[k]
                    y = i + dy[k]
                    if x < 0 or y < 0 or x >= H or y >= S:
                        continue
                    else:
                        if data[y][x] == "#":
                            ans = 'Yes'
                            break
                        else:
                            ans = 'No'
                            continue

print(ans)

Submission status: Wrong Answer

Solution code:
import sys

a = sys.stdin.readline().split(' ')
data = sys.stdin.readlines()

S = int(a[0])
H = int(a[1])

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

ans = 'Yes'
if S == 1 and H == 1:
    if data[0][0] == ".":
        ans = 'Yes'
    else:
        ans = 'No'
else:
    for i in range(S):
        for j in range(H):
            if data[i][j] == '.':
                continue
            else:
                for k in range(4):
                    x = j + dx[k]
                    y = i + dy[k]
                    if x < 0 or y < 0 or x >= H or y >= S:
                        continue
                    else:
                        if data[y][x] == "#":
                            ans = 'Yes'
                            break
                        else:
                            ans = 'No'
                            continue

print(ans)

Submission status: Wrong Answer

Solution code:
import sys

a = sys.stdin.readline().split(' ')
data = sys.stdin.readlines()

S = int(a[0])
H = int(a[1])

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

ans = ''
if S == 1 and H == 1:
    if data[0][0] == ".":
        ans = 'Yes'
    else:
        ans = 'No'
else:
    for i in range(S):
        for j in range(H):
            if data[i][j] == '.':
                ans = 'Yes'
                continue
            else:
                for k in range(4):
                    x = j + dx[k]
                    y = i + dy[k]
                    if x < 0 or y < 0 or x >= H or y >= S:
                        continue
                    else:
                        if data[y][x] == "#":
                            ans = 'Yes'
                            break
                        else:
                            ans = 'No'
                            continue

print(ans)

Submission status: Wrong Answer

Solution code:
import sys

a = sys.stdin.readline().split(' ')
data = sys.stdin.readlines()

S = int(a[0])
H = int(a[1])

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

ans = ''
if S == 1 and H == 1:
    ans = 'Yes'
else:
    for i in range(S):
        for j in range(H):
            if data[i][j] == '.':
                ans = 'Yes'
                continue
            else:
                for k in range(4):
                    x = j + dx[k]
                    y = i + dy[k]
                    if x < 0 or y < 0 or x >= H or y >= S:
                        continue
                    else:
                        if data[y][x] == "#":
                            ans = 'Yes'
                            break
                        else:
                            ans = 'No'
                            continue

print(ans)

Submission status: Wrong Answer

Solution code:
import sys

a = sys.stdin.readline().split(' ')
data = sys.stdin.readlines()

S = int(a[0])
H = int(a[1])

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

ans = ''
if S == 1 and H == 1:
    ans = 'Yes'
else:
    for i in range(S):
        for j in range(H):
            if data[i][j] == '.':
                continue
            else:
                for k in range(4):
                    x = j + dx[k]
                    y = i + dy[k]
                    if x < 0 or y < 0 or x >= H or y >= S:
                        continue
                    else:
                        if data[y][x] == "#":
                            ans = 'Yes'
                            break
                        else:
                            ans = 'No'
                            continue

print(ans)