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())

tab = []
for i in range(0,h):
    tab.append(input())

alone = True

#print(tab[h-1][w-1])
for hi in range(0,h):
    for wi in range(0,w):

        if tab[hi][wi] != '#':
            continue

        if hi + 1 < h:
            alone &= tab[hi + 1][wi] != '#'

        if hi - 1 >= 0:
            alone &= tab[hi - 1][wi] != '#'

        if wi + 1 < w:
            alone &= tab[hi][wi + 1] != '#'

        if wi - 1 >= 0:
            alone &= tab[hi][wi - 1] != '#'

#    if alone:
#        break
print("Yes" if not alone else "No")

Submission status: Wrong Answer

Solution code:
h,w=map(int,input().split())
x=[[0]*(w+2)]
for i in range(h):
    x.append([0]+list(input())+[0])
x.append([0]*(w+2))
c=0
for i in range(1,h+1):
    if c==1:
        break
    for j in range(1,w+1):
        if x[i][j]=="#":
            if x[i-1][j]!="#" and x[i][j-1]!="#" and x[i][j+1]!="#" and x[i+1][j]!="#":
                print("NO")
                c+=1
                break
else:
    if c!=1:
        print("Yes")

Submission status: Wrong Answer

Solution code:
h,w = map(int,(input().split()))
li = []
jud = 1
for i in range(h):
    li.append(list(input()))
dx = [0,1,-1,0]
dy = [1,0,0,-1]
num = 0
for i in range(h):
    for j in range(w):
        if li[i][j] == '#':
            num=0
            for d in range(len(dx)):
                ni = i+dy[d]
                nj = j+dx[d]
                if ni < 0 or h <= ni:
                    continue
                if nj < 0 or w <= nj:
                    continue
                if li[ni][nj] == '#':
                    num+=1
            if num == 0:
                jud = 0
                break

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

Submission status: Wrong Answer

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

flg = 0    

for j in range(1, h):
    for k in range(1, w):
        if arr[j][k] == "#":
            if (arr[j-1][w] == '.') and (arr[j][w-1] == '.') and (arr[j+1][w] == '.') and (arr[j][w+1] == '.'):
                flg = 1    
        
if flg == 0:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

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

flg = 0    

for j in range(1, h+1):
    for k in range(1, w+1):
        if arr[j][k] == "#":
            if (arr[j-1][w] == '.') and (arr[j][w-1] == '.') and (arr[j+1][w] == '.') and  (arr[j][w+1] == '.'):
                flg = 1    
        
if flg == 0:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

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

print(arr)
flg = 0    

for j in range(1, h+1):
    for k in range(1, w+1):
        if arr[j][k] == "#":
            if (arr[j-1][w] == '.') and (arr[j][w-1] == '.') and (arr[j+1][w] == '.') and  (arr[j][w+1] == '.'):
                flg = 1    
        
if flg == 0:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

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

def decision(i, x):
    if i == 0:
        if s[i+1][x] != '#':
            return False
    elif i == H-1:
        if s[i-1][x] != '#':
            return False
    else:
        if s[i+1][x] != '#' and s[i-1][0] != '#':
            return False

    return True

for i in range(H):
    if s[i][:2] == '#.':
        flag = decision(i, 0)
        if not flag:
            break

    if s[i][-2:] == '.#':
        flag = decision(i, -1)
        if not flag:
            break

    if '.#.' in s[i]:
        array = [j for j, x in enumerate(s[i]) if x == '.#.']
        for j in array:
            flag = decision(i, j+1)
            if not flag:
                break
        if not flag:
            break

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
H,W=(int(i) for i in input().split(' '))
s=[]
for h in range(H):
  s+=[input()]
for h in range(H):
  for w in range(W):
    if s[h][w]=='#':
      if h>0:
        if s[h-1][w]=='#':
          break
      elif w>0:
        if s[h][w-1]=='#':
          break
      elif w<W-1:
        if s[h][w+1]=='#':
          break
      elif h<H-1:
        if s[h+1][w]=='#':
          break
      else:
        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 y in range(H):
  for x in range(W):
    if x-1 < 0 or y-1 < 0 or x+1 > W-1 or y+1 > H-1:
      continue
    if s[y][x] == '#' and s[y+1][x] != '#' and s[y-1][x] != '#' and s[y][x+1] != '#' and s[y][x-1] != '#':
      print("No")
print("Yes")

Submission status: Wrong Answer

Solution code:
tate, yoko = map(int, input().split())
s  = [input()  for i in range(tate)]
dxy = [(-1, -1), (-1, 0), (-1, 1), (0, -1), (0, 1), (1, -1), (1, 0), (1, 1)]
for i in range(tate):
    for j in range(yoko):
        if s[i][j] == "#":
            save = []
            for dx, dy in dxy:
                if i + dy < 0 or i + dy > tate - 1 or j + dx < 0 or j + dx > yoko - 1: continue
                if s[i + dy][j + dx] == "#": 
                    save.append("#")
                    break
            if "#" in save: continue
            else:
                print("No")
                exit()
print("Yes")

Submission status: Wrong Answer

Solution code:
tate, yoko = map(int, input().split())
s  = [input()  for i in range(tate)]
dxy = [(-1, -1), (-1, 0), (-1, 1), (0, -1), (0, 1), (1, -1), (1, 0), (1, 1)]
for i in range(tate):
    for j in range(yoko):
        if s[i][j] == "#":
            save = []
            for dx, dy in dxy:
                if i + dy < 0 or i + dy > tate - 1 or j + dx < 0 or j + dx > yoko - 1: continue
                if s[i + dy][j + dx] == "#": 
                    save.append("#")
                    break
            if "#" in save: continue
            else:
                print("NO")
                exit()
print("YES")

Submission status: Wrong Answer

Solution code:
def inner(x, y):
    return 0 <= x and x < W and 0 <= y and y < H

def ok(s):
    for i in range(H):
         for j in range(W):
             if s[i][j] == '#':
                 if inner(i-1, j) and s[i-1][j] == '#':
                     continue
                 if inner(i+1, j) and s[i+1][j] == '#':
                     continue
                 if inner(i, j-1) and s[i][j-1] == '#':
                     continue
                 if inner(i, j+1) and s[i][j+1] == '#':
                     continue
                 return 'No'
    return 'Yes'


H, W = map(int, input().split())
s = []
for i in range(H):
    s.append(input())
print(ok(s))

Submission status: Wrong Answer

Solution code:
def inner(x, y):
    return 0 <= x and x < W and 0 <= y and y <= H

def ok(s):
    for i in range(H):
         for j in range(W):
             if s[i][j] == '#':
                 if inner(i-1, j) and s[i-1][j] == '#':
                     continue
                 if inner(i+1, j) and s[i+1][j] == '#':
                     continue
                 if inner(i, j-1) and s[i][j-1] == '#':
                     continue
                 if inner(i, j+1) and s[i][j+1] == '#':
                     continue
                 return 'No'
    return 'Yes'


H, W = map(int, input().split())
s = []
for i in range(H):
    s.append(input())
print(ok(s))

Submission status: Wrong Answer

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

for y in range(H) :
    for x in range(W) :
        if L[y][x] == "#" :
            for dx,dy in dxy :
                nx = x+dx
                ny = y+dy
                if (0 <= nx <= W-1) and (0 <= ny <= H-1) :
                    if L[ny][nx] == "#" :
                        break
                    print("No")
                    exit()
print("Yes")

Submission status: Wrong Answer

Solution code:
H,W = map(int,input().split())
L = [input() for i in range(H)]
dxy = [[1,0],[-1,0],[0,1],[0,-1]]
flag = 1
for y in range(H) :
    for x in range(W) :
        if L[y][x] == "#" :
            for dx,dy in dxy :
                nx = x+dx
                ny = y+dy
                if (0 <= nx <= W-1) and (0 <= ny <= H-1) :
                    if L[ny][nx] == "#" :
                        flag = 1
                        break
                    else :
                        flag = 0
if flag == 1 :
    print("Yes")
else :
    print("No")

Submission status: Wrong Answer

Solution code:
H,W = map(int,input().split())
L = [input() for i in range(H)]
dxy = [[1,0],[-1,0],[0,1],[0,-1]]
flag = 0
for y in range(H) :
    for x in range(W) :
        if L[y][x] == "#" :
            for dx,dy in dxy :
                nx = x+dx
                ny = y+dy
                if (0 <= nx <= W-1) and (0 <= ny <= H-1) :
                    if L[ny][nx] == "#" :
                        flag = 1
                        break
                    else :
                        flag = 0
if flag == 1 :
    print("Yes")
else :
    print("No")

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):
        flag = 1
        if i > 0:
            if s[i-1][j] == "#":
                flag = 0
        if i < h-1:
            if s[i+1][j] == "#":
                flag = 0
        if j > 0:
            if s[i][j-1] == "#":
                flag = 0
        if j < w-1:
            if s[i][j+1] == "#":
                flag = 0
        if flag == 1:
            print("No")
            exit()

print("Yes")

Submission status: Wrong Answer

Solution code:

H, W = map(int, input().split())
s = [0]*H

def check(x, y):
    return 0 <= x and x < W and 0 <= y and y < H

def test(x, y):
    if check(x, y):
        return s[y][x]
    else:
        return "."

for i in range(H):
    s[i] = input()
ans = "Yes"
for y in range(H):
    for x in range(W):
        l = list(map(lambda p: test(p[0], p[1]), [(x-1, y),(x+1, y),(x, y-1),(x, y+1)]))
        if "#" not in l:
           ans = "No"
           break
print(ans)

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())
s = [[] for i in range(H)]
num = 0
judge = 0
start = []
for i in range(H):
    s[i] = input()
    if '#' in s[i]:
        start.append([i, s[i].index('#')])
        num += s[i].count('#')

if num == 0:
    print('Yes')
elif num == 1:
    print('No')
else:
    for nowy, nowx in start:
        flag = False
        for y, x in [1, 0], [-1, 0], [0, 1], [0, -1]:
            if 0 <= y+nowy <= H-1 and 0 <= x+nowx <= W-1:
                if s[nowy+y][nowx+x] == '#':
                    flag = True
        if flag == True:
            judge += 1
    if judge == num:
        print('Yes')
    else:
        print('No')

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())
s = [[] for i in range(H)]
num = 0
judge = 0
for i in range(H):
    s[i] = input()
    if '#' in s[i]:
        start = [i, s[i].index('#')]
        num += s[i].count('#')

if num == 0:
    print('Yes')
elif num == 1:
    print('No')
else:
    check = [[True]*W for i in range(H)]
    check[start[0]][start[1]] = False
    stack = [start]
    
    while len(stack) != 0:
        now = stack.pop()
        if s[now[0]][now[1]] == '#':
            judge += 1
            for y, x in [0, 1], [0, -1], [1, 0], [-1, 0]:
                if 0 <= now[0]+y <= H-1 and 0 <= now[1]+x <= W-1 and check[now[0]+y][now[1]+x] == True:
                    check[now[0]+y][now[1]+x] = False
                    stack.append([now[0]+y, now[1]+x])
    if judge == num:
        print('Yes')
    else:
        print('No')

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())
s = [[] for i in range(H)]
num = 0
judge = 0
for i in range(H):
    s[i] = input()
    if '#' in s[i]:
        start = [i, s[i].index('#')]
        num += s[i].count('#')

if num == 0:
    print('Yes')
else:
    check = [[True]*W for i in range(H)]
    check[start[0]][start[1]] = False
    stack = [start]
    
    while len(stack) != 0:
        now = stack.pop()
        if s[now[0]][now[1]] == '#':
            judge += 1
            for y, x in [0, 1], [0, -1], [1, 0], [-1, 0]:
                if 0 <= now[0]+y <= H-1 and 0 <= now[1]+x <= W-1 and check[now[0]+y][now[1]+x] == True:
                    check[now[0]+y][now[1]+x] = False
                    stack.append([now[0]+y, now[1]+x])
    if judge == num:
        print('Yes')
    else:
        print('No')

Submission status: Wrong Answer

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

judge = True
for i in range(H):
    for j in range(W):
        if s[i][j] =='#':
            flag = 0
            if i-1 >= 0 and s[i-1][j] == '#':
                flag = 1
            if j-1 >= 0 and s[i][j-1] == '#':
                flag = 1
            if j+1 < W and s[i][j+1] == '#':
                flag = 1
            if i+1 < H and s[i+1][j] == '#':
                flag = 1
            if flag == 0:
                judge == False
                
if judge:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
x, y = map(int, input().split())
grid = [list(input()) for _ in range(x)]
flag = True
for i in range(x):
    for j in range(y):
        if grid[i][j] == '#':
            if i == 0:
                if j == 0:
                    if grid[i][j+1] == '#' or \
                        grid[i+1][j] == '#':
                        flag = True
                    else:
                        flag = False
                        break
                elif j == y-1:
                    if grid[i][j-1] == '#' or \
                        grid[i+1][j] == '#':
                        flag = True
                    else:
                        flag = False
                        break
                else:
                    if grid[i][j-1] == '#' or \
                        grid[i][j+1] == '#' or \
                        grid[i+1][j] == '#':
                        flag = True
                    else:
                        flag = False
                        break
            if i == x-1:
                if j == 0:
                    if grid[i][j+1] == '#' or \
                        grid[i-1][j] == '#':
                        flag = True
                    else:
                        flag = False
                        break
                elif j == y-1:
                    if grid[i][j-1] == '#' or \
                        grid[i-1][j] == '#':
                        flag = True
                    else:
                        flag = False
                        break
                else:
                    if grid[i][j-1] == '#' or \
                        grid[i][j+1] == '#' or \
                        grid[i-1][j] == '#':
                        flag = True
                    else:
                        flag = False
                        break
            else:
                if j == 0:
                    if grid[i][j+1] == '#' or \
                        grid[i-1][j] == '#' or \
                        grid[i+1][j] == '#':
                        flag = True
                    else:
                        flag = False
                        break
                elif j == y-1:
                    if grid[i][j-1] == '#' or \
                        grid[i-1][j] == '#' or \
                        grid[i+1][j] == '#':
                        flag = True
                    else:
                        flag = False
                        break
                else:
                    if grid[i][j-1] == '#' or \
                        grid[i][j+1] == '#' or \
                        grid[i-1][j] == '#' or \
                        grid[i+1][j] == '#':
                        flag = True
                    else:
                        flag = False
                        break
if flag:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

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

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

for i in range(H):
    for j in range(W):
        if s[i][j] == "#":
            if j != 0 and s[i][j-1] == ".":
                if j+1 != W and s[i][j+1] == ".":
                    if i != 0 and s[i-1][j] == ".":
                        if i+1 != H and s[i+1][j] == ".":
                            answer ="NO"

print(answer)

Submission status: Wrong Answer

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

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

for i in range(H):
    for j in range(W):
        if s[i][j] == "#":
            if j-1 >= 0 and s[i][j-1] == ".":
                if j+1 < W and s[i][j+1] == ".":
                    if i-1 >=0 and s[i-1][j] == ".":
                        if i+1 < H and s[i+1][j] == ".":
                            answer ="NO"

print(answer)

Submission status: Wrong Answer

Solution code:
import sys

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

# H = 2
# W = 3

s = [["" for j in range(W)] for i in range(H)]

for i in range(H):
    tmp = input()
    for j in range(W):
        s[i][j] = tmp[j]

# print(s)

for i in range(H):
    for j in range(W):
        if s[i][j] == "#":
            if i != 0:
                if s[i-1][j] == "#":
                    break
            if i != H-1:
                if s[i+1][j] == "#":
                    break
            if j != 0:
                if s[i][j-1] == "#":
                    break
            if j != W-1:
                if s[i][j+1] == "#":
                    break
            print("No")
            sys.exit()
print("Yes")

Submission status: Wrong Answer

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

for i in range(h):
    for j in range(w):
        if s_list[i][j] == '#':
            flag = False
            for dy in range(-1, 2):
                for dx in range(-1, 2):
                    # 自分自身は無視
                    if dy == 0 and dx == 0:
                        continue
                    # 上下左右に限定(斜めは無視)
                    if dy == 0 or dx == 0:
                        ny = dy + i
                        nx = dx + j
                        # 端っこは無視
                        if ny < 0 or nx < 0 or ny >= h or nx >= w:
                            continue
                        # 1つでも#あれば探索完了
                        if s_list[ny][nx] == '#':
                            flag = True
                            break
                if flag:
                    break
            if flag:
                break
            # 上下左右で#がない#のマスがあればそこで終了
            if not flag:
                print('No')
                exit()
print('Yes')

Submission status: Wrong Answer

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

for i in range(h):
    for j in range(w):
        if s_list[i][j] == '#':
            flag = True
            for dy in range(-1, 2):
                for dx in range(-1, 2):
                    # 自分自身は無視
                    if dy == 0 and dx == 0:
                        continue
                    ny = dy + i
                    nx = dx + j
                    # 端っこは無視
                    if ny <= 0 or nx <= 0 or ny >= h or nx >= w:
                        continue
                    # 上下左右(斜めは無視)のどれかで#かどうか
                    if (dy == 0 or dx == 0) and s_list[ny][nx] == '#':
                        flag = False
                        break
                if not flag:
                    break
            if not flag:
                break
            if flag:
                print('No')
                exit()
print('Yes')

Submission status: Wrong Answer

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

for i in range(h):
    for j in range(w):
        if s_list[i][j] == '#':
            flag = True
            for dy in range(-1, 2):
                for dx in range(-1, 2):
                    # 自分自身は無視
                    if dy == 0 and dx == 0:
                        continue
                    ny = dy + i
                    nx = dx + j
                    # 端っこは無視
                    if ny < 0 or nx < 0 or ny >= h or nx >= w:
                        continue
                    # 上下左右(斜めは無視)のどれかで#かどうか
                    if (dy == 0 or dx == 0) and s_list[ny][nx] == '#':
                        flag = False
                        break
                if not flag:
                    break
            if not flag:
                break
            if flag:
                print('No')
                exit()
print('Yes')

Submission status: Wrong Answer

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

for i in range(h):
    for j in range(w):
        if s_list[i][j] == '#':
            flag = True
            for dy in range(-1, 2):
                for dx in range(-1, 2):
                    if dy == 0 and dx == 0:
                        continue
                    ny = dy + i
                    nx = dx + j
                    if ny < 0 or nx < 0 or ny >= h or nx >= w:
                        continue
                    if (dy == 0 or dx == 0) and s_list[ny][nx] == '#':
                        flag = False
                        break
            if not flag:
                break
            if flag:
                print('No')
                exit()
print('Yes')

Submission status: Wrong Answer

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

flag = False
for i in range(h):
    for j in range(w):
        if s_list[i][j] == '#':
            for dy in range(-1, 2):
                for dx in range(-1, 2):
                    if dy == 0 and dx == 0:
                        continue
                    ny = dy + i
                    nx = dx + j
                    if ny < 0 or nx < 0 or ny >= h or nx >= w:
                        continue
                    if (dy == 0 or dx == 0) and s_list[ny][nx] == '#':
                        print('Yes')
                        flag = True
                        break
            if flag:
                break
    if flag:
        break

if flag == False:
    print('No')

Submission status: Wrong Answer

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

flag = False
for i in range(h):
    for j in range(w):
        if s_list[i][j] == '#':
            for dy in range(-1, 2):
                for dx in range(-1, 2):
                    if dy == 0 and dx == 0:
                        continue
                    ny = dy + i
                    nx = dx + j
                    if ny < 0 or nx < 0 or ny >= h or nx >= w:
                        continue
                    if (dy == 0 or dx == 0) and s_list[ny][nx] == '#':
                        print('Yes')
                        flag = True
                        break
                if flag:
                    break
            if flag:
                break
    if flag:
        break

if flag == False:
    print('No')

Submission status: Wrong Answer

Solution code:
def main():
  t = input().split(" ")
  H, W = int(t[0]), int(t[1])
  
  s = ["."*(W+2)]
  for i in range(H):
    t = input().strip()
    s.append("".join(['.', t, '.']))
  s.append("."*(W+2))
  flag = True
  for i in range(H):
    for j in range(W):
      if s[i+1][j+1] == '#':
        if s[i][j+1]=='.' and s[i+2][j+1]=='.' and s[i+1][j]=='.' and s[i+1][j+2]=='.':
          flag == False
  if flag:
    print("Yes")
  else:
    print("No")
main()

Submission status: Wrong Answer

Solution code:
H,W = map(int,input().split())
s = [list(input()) for i in range(H)]
flag = True
for i in range(H):
  for j in range(W):
    if s[i][j] == '#':
      flag = False
      if i > 0:
        if s[i-1][j] == '#':
          flag = True
      if j > 0:
        if s[i][j-1] == '#':
          flag = True
      if i < H-1:
        if s[i+1][j] == '#':
          flag = True
      if j < W-1:
        if s[i][j+1] == '#':
          flag = True
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
for i in range(H):
  for j in range(W):
    if s[i][j] == '#':
      flag = False
      if i > 0:
        if s[i-1][j] == '#':
          flag = True
      if j > 0:
        if s[i][j-1] == '#':
          flag = True
      if i < H-1:
        if s[i+1][j] == '#':
          flag = True
      if j < W-1:
        if s[i][j+1] == '#':
          flag = True
if flag:
  print('Yes')
else:
  print('No')

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Tue Aug  7 23:17:21 2018

@author: Yuki
"""


def check_good(S, w, h, W, H):
    upper_flag = True
    down_flag = True
    left_flag = True
    right_flag = True
    if w == 0:
        left_flag = False
    if w == W - 1:
        right_flag = False
    if h == 0:
        upper_flag = False
    if h == H - 1:
        down_flag = False
    tmp = []
    if left_flag:
        tmp.append(S[h][w-1] == '#')
    if right_flag:
        tmp.append(S[h][w+1] == '#')
    if upper_flag:
        tmp.append(S[h-1][w] == '#')
    if down_flag:
        tmp.append(S[h+1][w] == '#')
    return sum(tmp)
def main():
    H, W = map(int, input().split())
    S = []
    for i in range(H):
        S.append(input())
    
    Yes_flag = True
    for w in range(W):
        for h in range(H):
            if S[h][w] == '#':
                res = check_good(S, w, h, W, H)
                if res == 0:
                    Yes_flag = False
                    print(w, h)
            if Yes_flag == False:
                break
        if Yes_flag == False:
            break
    if Yes_flag:
        print('Yes')
    else:
        print('No')

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Tue Aug  7 23:17:21 2018

@author: Yuki
"""


def check_good(S, w, h, W, H):
    upper_flag = True
    down_flag = True
    left_flag = True
    right_flag = True
    if w == 0:
        left_flag = False
    if w == W - 1:
        right_flag = False
    if h == 0:
        upper_flag = False
    if h == H - 1:
        down_flag = False
    tmp = []
    if left_flag:
        tmp.append(S[h][w-1] == '#')
    if right_flag:
        tmp.append(S[h][w+1] == '#')
    if upper_flag:
        tmp.append(S[h-1][w] == '#')
    if down_flag:
        tmp.append(S[h+1][w] == '#')
    return sum(tmp)
def main():
    H, W = map(int, input().split())
    S = []
    for i in range(H):
        S.append(input())
    
    Yes_flag = True
    for w in range(W):
        for h in range(H):
            res = check_good(S, w, h, W, H)
            if res == 0:
                Yes_flag = False
            if Yes_flag ==False:
                break
        if Yes_flag ==False:
            break
    if Yes_flag:
        print('Yes')
    else:
        print('No')

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())
 
C = ["."*(W+2)]
for k in range(H):
    C.append("."+input()+".")
C.append("."*(W+2))
 
for k,l in zip(range(1,W+1),range(1,H+1)):
    if C[l][k]=="#":
        if C[l+1][k]=="#" or C[l-1][k]=="#" or C[l][k+1]=="#" or C[l][k-1]=="#":
            pass
        else:
            print("No")
            exit()
print("Yes")

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())
matrix = []
for _ in range(H):
    row = input().split()
    matrix.append(row)
no_flag = False
for i, x in enumerate(matrix):
    for j, y in enumerate(x):
        if y == '#':
            if j != 0 and matrix[i][j - 1] == '#':
                continue
            elif j != W - 1 and matrix[i][j + 1] == '#':
                continue
            elif i != 0 and matrix[i - 1][j] == '#':
                continue
            elif i != H - 1 and matrix[i + 1][j] == '#':
                continue
            else:
                no_flag = True
                break
    if no_flag == True:
        print('No')
        break
else:
    print('Yes')

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())
matrix = []
for _ in range(H):
    row = input().split()
    matrix.append(row)
no_flag = False
for i, x in enumerate(matrix):
    for j, y in enumerate(matrix[i]):
        if y == '#':
            if j != 0 and matrix[i][j - 1] == '#':
                continue
            elif j != W - 1 and matrix[i][j + 1] == '#':
                continue
            elif i != 0 and matrix[i - 1][j] == '#':
                continue
            elif i != H - 1 and matrix[i + 1][j] == '#':
                continue
            else:
                no_flag = True
                break
    if no_flag == True:
        print('No')
        break
else:
    print('Yes')