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:
def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def solve(inputs):
    field = []
    for row in inputs:
        line = []
        for c in row:
            line.append(c)
        field.append(line)

    if len(field) == 1:
        if len(field[0]) == 1:
            return "No"

    print(field)
    for i, row in enumerate(field):
        for j, _ in enumerate(row):
            available = False
            if field[i][j] == ".":
                continue
            if i - 1 >= 0:
                available |= field[i - 1][j] == "#"

            if j - 1 >= 0:
                available |= field[i][j - 1] == "#"
            if j + 1 < len(row):
                available |= field[i][j + 1] == "#"

            if i + 1 < len(field):
                available |= field[i + 1][j] == "#"
            if not available:
                return "No"

    return "Yes"


if __name__ == "__main__":
    [N, _] = map(lambda x: int(x), input().split())
    ret = solve(inputs(N))
    print(ret)

Submission status: Wrong Answer

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

for i in range(h):
    s[i+1] = [x for x in input()]

for i in range(h+2):
    s[i].insert(w,".")
    s[i].insert(0,".")
    
for i in range(h+2):
    for j in range(w+2):
        if s[i][j] == "#":
            if s[i-1][j]=="#" or s[i+1][j]=="#" or s[i][j-1]=="#" or s[i][j+1]=="#":
                pass
            else:
                print("No")
                break
print("Yes")

Submission status: Wrong Answer

Solution code:
h, w = list(map(int, input().split()))
s = [input() for j in range(h)]
op = [(-1, 0), (0, -1), (0, 1), (1, 1)]
for i in range(h):
  for j in range(w):
    if s[i][j] == '.':
      continue
    count = 0
    for k in range(4):
      x = i + op[k][0]
      y = j + op[k][1]
      if x < 0 or y < 0 or x >= h or y >= w:
        continue
      if s[x][y] == '.':
        count += 1
    if count == 4:
      print('No')
      exit()
      
print('Yes')

Submission status: Wrong Answer

Solution code:
#ABC096-C
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(input())
def S(): return list(input())
h,w=IL()
S=[S() for i in range(h)]
ret=True
#grid周り探索
for i in range(h):
    for j in range(w):
        ans=False
        for ti in [-1,1]:
            if 0<=i+ti<h:
                if S[i+ti][j]=="#":
                    ans=True
        for tj in [-1,1]:
             if 0<=j+tj<w:
                if S[i][j+tj]=="#":
                    ans=True
        if not ans:
            ret=False
if ret:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

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

S = []

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

for i in range(h):
    S.append(list(input()))

hasNothing = True

for i in range(h):
    for j in range(w):

        if (S[i][j] == '.'): continue
            
        for dxy in dxy_list:
            ni = i + dxy[0]
            nj = j + dxy[1]

            if (ni < 0 or h <= ni): continue
            if (nj < 0 or w <= nj): continue

            if (S[ni][nj] == '#'):
                hasNothing = False
                break

        if (hasNothing):
            print('No')
            exit()

print('Yes')

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())
s = [input() for _ in range(H)]
flag = True
for h in range(H):
    for w in range(W):
        c0 = s[h][w] == '#'
        c1 = h > 1 and s[h - 1][w] == '#'
        c2 = h < H - 1 and s[h + 1][w] == '#'
        c4 = w > 1 and s[h][w - 1] == '#'
        c3 = w < W - 1 and s[h][w + 1] == '#'
        if c0 and not (c1 or c2 or c3 or c4):
            flag = False
                
print('Yes' if flag else 'No')

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())
s = [input() for _ in range(H)]
flag = True
for h in range(H - 1):
    for w in range(W - 1):
        if s[h][w] == '#':
            if s[h][w + 1] != '#' and s[h + 1][w] != '#':
                flag = False
                
print('Yes' if flag else 'No')

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())
s = [input() for _ in range(H)]
cnt = sum([v.count('#') for v in s])

ans = 0
for h in range(H):
    for w in range(W):
        if s[h][w] == '#':
            s[h][w] == '*'
            ans += 1
        if s[h][w] == '*':
            if w < W - 1 and s[h][w + 1] == '#':
                s[h][w + 1] == '*'
                ans += 1
            if h < H - 1 and s[h + 1][w] == '#':
                s[h + 1][w] == '*'
                ans += 1
                
print('Yes' if ans == cnt else 'No')

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

H,W=map(int,input().split())
grid = [list(input().rstrip()) for _ in range(H)]
for i in range(H):
  for j in range(W):
    if j > 0 and grid[i][j-1] != '.' and grid[i][j] == '#':
      grid[i][j] = '*'
    elif j < W-1 and grid[i][j+1] != '.' and grid[i][j] == '#':
      grid[i][j] = '*'
    elif i > 0 and grid[i-1][j] != '.' and grid[i][j] == '#':
      grid[i][j] = '*'
    elif i < H-1 and grid[i+1][j] != '.' and grid[i][j] == '#':
      grid[i][j] = '*'
print("No" if sum([row.count('*') for row in grid]) else "Yes")

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

H,W=map(int,input().split())
grid = [list(input().rstrip()) for _ in range(H)]
for i in range(H):
  for j in range(W):
    if j > 0 and grid[i][j-1] != '.' and grid[i][j] == '#':
      grid[i][j] = '*'
    elif j < W-1 and grid[i][j+1] != '.' and grid[i][j] == '#':
      grid[i][j] = '*'
    elif i > 0 and grid[i-1][j] != '.' and grid[i][j] == '#':
      grid[i][j] = '*'
    elif i < H-1 and grid[i+1][j] != '.' and grid[i][j] == '#':
      grid[i][j] = '*'
print("Yes" if sum([row.count('*') for row in grid]) else "No")

Submission status: Wrong Answer

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

import math

h,w = list(map(int,input().split(" ")))

c = []

for i in range(h):
    l = list(input())
    c.append(l)

for i in range(h):
    for j in range(w):
        if c[i][j] == "#":
            if j != 0:
                if c[i][j-1] == "#":
                    break
            if j != w-1:
                if c[i][j+1] == "#":
                    break
            if i != 0:
                if c[i-1][j] == "#":
                    break
            if i != h-1:
                if c[i+1][j] == "#":
                    break
            else:
                print('No')
                exit()
print('Yes')

Submission status: Wrong Answer

Solution code:
import numpy as np
h, w = map(int, input().split())
square = np.array([list(input()) for i in range(h)]).ravel()=="#"
def main():
    for i in range(h*w):
        if square[i] == True:
            flag = 0
            if i // w == 0:
                if square[i+w] == True:
                    flag += 1
            elif i // w == h-1:
                if square[i-w] == True:
                    flag += 1
            else:
                if square[i+w] + square[i-w] == True:
                    flag += 1
            if i % w == 0:
                if square[i+1] == True:
                    flag += 1
            elif i % w == w-1:
                if square[i-1] == True:
                    flag += 1
            else:
                if square[i+1] + square[i-1] == True:
                    flag += 1
            if flag == 0:
                print("No")
                print(i)
                return 0
    print("Yes")
main()

Submission status: Wrong Answer

Solution code:
N,M = [ int(it) for it in input().split() ]
li = [[ 1 if it=="#" else 0 for it in input() ]  for i in range(N)] 

flag = False
for i in range(N):
  for j in range(M):
    if (i+1<N):
      if (li[i][j]==li[i+1][j]):
        flag = True
    if (j+1<M):
      if (li[i][j]==li[i][j+1]):
        flag = True
print ( "Yes" if flag else "No"  )

Submission status: Wrong Answer

Solution code:
N,M = [ int(it) for it in input().split() ]
li = [[ 1 if it=="#" else 0 for it in input() ]  for i in range(N)] 

flag = False
for i in range(N):
  for j in range(M):
    if (i+1<N):
      if (li[i][j]==li[i+1][j]):
        flag = True
    if (j+1<M):
      if (li[i][j]==li[i][j+1]):
        flag = True
print ( flag  )

Submission status: Wrong Answer

Solution code:
import itertools

H, W = map(int, input().split())
s = []
for i in range(H):
  s.append(input())
print(s)  
  
for i in range(H):
  for j in range(W):
    if s[i][j] == "#":
      flag = False
      for x, y in [[1, 0],[-1, 0],[0, 1],[0, -1]]:
        if i + x >= 0 and i + x <= H - 1 and j + y >= 0 and j + y <= W - 1 and s[i + x][j + y] == '#':
          flag = True
      if not flag:
        print('No')
        exit(0)
print('Yes')

Submission status: Wrong Answer

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

dict = (
    (-1, 0),
    (0, -1),
    (0, 1),
    (1, 0),
)

achievable = True

for i in range(h):
    for j in range(w):
        count = 0
        now = grid[i][j]
        if now == "#":
            for dy, dx in dict:
                y = i + dy
                x = j + dx
                if y >= 0 and h > y and x >= 0 and w > x:
                    if grid[y][x] == '#':
                        count += 1
            if count == 0:
                achievable = False

print('YES' if achievable else 'No')

Submission status: Wrong Answer

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

dict = (
    (-1, -1),
    (-1, 0),
    (-1, 1),
    (0, -1),
    (0, 1),
    (1, -1),
    (1, 0),
    (1, 1),
)

achievable = True

for i in range(h):
    for j in range(w):
        count = 0
        now = grid[i][j]
        if now == "#":
            for dy, dx in dict:
                y = i + dy
                x = j + dx
                if y >= 0 and h > y and x >= 0 and w > x:
                    if grid[y][x] == '#':
                        count += 1
            if count == 0:
                achievable = False

print('YES' if achievable else 'No')

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())
S =['.'*(W+2)]+ ['.'+input()+'.' for i in range(H)]+['.'*(W+2)]
print(S)
flag = True
for i in range(1, H+1):
    for k in range(1, W+1):
        if S[i][k] == '#':
            if S[i-1][k] == '.' and S[i+1][k] == '.' and S[i][k+1] == '.' and S[i][k-1] == '.':
                flag = False
                break
    if not flag:
        break
if flag:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
def solve(field):
  for i in range(1, h + 1):
    for j in range(1, w + 1):
      if field[i][j] == '.':
        continue
        #それ以後の処理がスキップされ、次のループに。つまり#の場合のみ次に進める。
      if field[i-1][j] == field[i][j-1] == field[i][j+1] == field[i+1][j] == '.':
      #上下左右に黒がない場合（全部白の場合）、黒色にできない（隣も塗らざるを得ないから）。
      #また黒色にできないのはその場合に限る（1つ以上あれば――ダブってても白には戻らないため――べたべた塗ればよい）
        return False
      return True
#インデント注意。任意の#のfieldに対してFalse返らなかったらTrueということなので、最初の条件節を出る（同じインデントかそれより前）。
h, w = list(map(int, input().split()))
field = ['.' + input() + '.' for _ in range(h)]
#左右の端についてもsolve(field)を適用するため、入力に左右を付け加える
field = ['.'*(w+2)] + field + ['.'*(w+2)]
#上下の端についても同様の処理。fieldは例えば['.....', '..#..', '.###.', '..#..', '.....']となる。
#これのi番目のリストのj項が、field[i][j]によって指示される。

print('Yes' if solve(field) else 'No')
#solve(field)だけで、Trueが返ってくるということを意味する。

Submission status: Wrong Answer

Solution code:
def solve(field):
  for i in range(1, h + 1):
    for j in range(1, w + 1):
      if field[i][j] == '.':
        continue #それ以後の処理がスキップされ、次のループに。つまり#の場合のみ次に進める。
      if field[i-1][j] == field[i][j-1] == field[i][j+1] == field[i+1][j] == '.':
      #上下左右に黒がない場合（全部白の場合）、黒色にできない（隣も塗らざるを得ないから）。
      #また黒色にできないのはその場合に限る（1つ以上あれば――ダブってても白には戻らないため――べたべた塗ればよい）
        return False
      return True
#インデント注意。任意の#のfieldに対してFalse返らなかったらTrueということなので、最初の条件節を出る（同じインデントかそれより前）。
h, w = list(map(int, input().split()))
field = ['.' + input() + '.' for _ in range(1, h + 1)]
#左右の端についてもsolve(field)を適用するため、入力に左右を付け加える
field = ['.'*(w+2)] + field + ['.'*(w+2)]
#上下の端についても同様の処理。fieldは例えば['.....', '..#..', '.###.', '..#..', '.....']となる。
#これのi番目のリストのj項が、field[i][j]によって指示される。

print('Yes' if solve(field) else 'No')
#solve(field)だけで、Trueが返ってくるということを意味する。

Submission status: Wrong Answer

Solution code:
def solve(field):
  for i in range(1, h + 1):
    for j in range(1, w + 1):
      if field[i][j] == '.':
        continue#それ以後の処理がスキップされ、次のループに。つまり#の場合のみ次に進める。
      if field[i-1][j] == field[i][j-1] == field[i][j+1] == field[i+1][j] == '.':
      #上下左右に黒がない場合（全部白の場合）、黒色にできない（隣も塗らざるを得ないから）。
      #また黒色にできないのはその場合に限る（1つ以上あれば――ダブってても白には戻らないため――べたべた塗ればよい）
        return False
      return True
#インデント注意。任意の#のfieldに対してFalse返らなかったらTrueということなので、最初の条件節を出る（同じインデントかそれより前）。
h, w = list(map(int, input().split()))
field = ['.' + input() + '.' for _ in range(1, h + 1)]
#左右の端についてもsolve(field)を適用するため、入力に左右を付け加える
field = ['.'*(w+2)] + field + ['.'*(w+2)]
#上下の端についても同様の処理。fieldは例えば['.....', '..#..', '.###.', '..#..', '.....']となる。
#これのi番目のリストのj項が、field[i][j]によって指示される。

print('Yes' if solve(field) else 'No')#solve(field)だけで、Trueが返ってくるということを意味する。

Submission status: Wrong Answer

Solution code:
def solve(field):
  for i in range(1, h + 1):
    for j in range(1, w + 1):
      if field[i][j] == '#':
        continue
        if field[i-1][j] == field[i][j-1] == field[i][j+1] == field[i+1][j] == '.':
        #上下左右に黒がない場合（全部白の場合）、黒色にできない（隣も塗らざるを得ないから）。
        #また黒色にできないのはその場合に限る（1つ以上あれば――ダブってても白には戻らないため――べたべた塗ればよい）
          return False
      return True
#インデント注意。任意の#のfieldに対してFalse返らなかったらTrueということなので、最初の条件節まで浅くなる。

h, w = list(map(int, input().split()))
field = ['.' + input() + '.' for _ in range(1, h + 1)]
#左右の端についてもsolve(field)を適用するため、入力に左右を付け加える
field = ['.'*(w+2)] + field + ['.'*(w+2)]
#上下の端についても同様の処理。fieldは例えば['.....', '..#..', '.###.', '..#..', '.....']となる。
#これのi番目のリストのj項が、field[i][j]によって指示される。

print('Yes' if solve(field) else 'No')#solve(field)だけで、Trueが返ってくるということを意味する。

Submission status: Wrong Answer

Solution code:
def calc(x, y):
    x2 = x
    y2 = y - 1
    x4 = x - 1
    y4 = y
    x5 = x + 1
    y5 = y
    x7 = x
    y7 = y + 1
    return x2, y2, x4, y4, x5, y5, x7, y7

h, w = map(int, input().split())
s = []
for _ in range(h):
    s.append(list(input()))
ans = "Yes"
for i in range(h * w):
    x = i // h
    y = i % h
    c = 0
    if s[y][x] == "#":
        x2, y2, x4, y4, x5, y5, x7, y7 = calc(x, y)
        aaa = [[x2, y2], [x4, y4], [x5, y5], [x7, y7]]
        for (xx, yy) in aaa:
            if ((xx >= 0) & (xx < h) & (yy >= 0) & (yy < w)):
                if s[xx][yy] == "#":
                    c += 1
        if c == 0:
            ans = "No"
            break
print(ans)

Submission status: Wrong Answer

Solution code:
# https://qiita.com/_-_-_-_-_/items/34f933adc7be875e61d0
# abcde	s=input()	s='abcde'
# abcde	s=list(input())	s=['a', 'b', 'c', 'd', 'e']
# 5(1つだけ)	a=int(input())	a=5
# 1 2	| x,y = s_inpl()   |	x=1,y=2
# 1 2 3 4 5 ... n 　	li = input().split()	li=['1','2','3',...,'n']
# 1 2 3 4 5 ... n 　	li = inpl()	li=[1,2,3,4,5,...,n]
# FFFTFTTFF 　	li = input().split('T')	li=['FFF', 'F', '', 'FF']

# INPUT
# 3
# hoge
# foo
# bar
# ANSWER
# n=int(input())
# string_list=[input() for i in range(n)]

import math
import copy
from collections import defaultdict
from collections import Counter
from collections import deque
# 直積 A={a, b, c}, B={d, e}:のとき，A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)
from itertools import product
# 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)
from itertools import permutations
# 組み合わせ {}_len(seq) C_n: combinations(seq, n)
from itertools import combinations
from bisect import bisect_left, bisect_right
# import numpy as np

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

# 四方向: 右, 下, 左, 上
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]

def i_inpl(): return int(input())
def s_inpl(): return map(int,input().split())
def l_inpl(): return list(map(int, input().split()))
INF = float("inf")

#############################################

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

flag = True

for y in range(H):
    for x in range(W):
        tmp = False
        for i in range(4):
            ny = y + dy[i]
            nx = x + dx[i]
            if inside(ny, nx, H, W) and f[ny][nx] == "#":
                tmp = True
                break
        if not tmp:
            flag = False
            break

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

Submission status: Wrong Answer

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

for i in range(h):
  for j in range(w):
    if j > 0 and a[i][j-1] != ".":
      a[i][j] = "*"
    elif j < w - 1 and a[i][j+1] != ".":
      a[i][j] = "*"
    elif i > 0 and a[i-1][j] != ".":
      a[i][j] = "*"
    elif i < h - 1 and a[i+1][j] != ".":
      a[i][j] = "*"

print("No" if sum([row.count("#") for row in a]) else "Yes")

Submission status: Wrong Answer

Solution code:
h,w=map(int,input().split())
l=["."*(w+2)]
for i in range(h):
  l+=["."+input()+"."]
l+=["."*(w+2)]
ans=0
print(l)
for i in range(1,h+1):
  for j in range(1,w+1):
    if l[i][j]==".":
      continue
    if l[i+1][j]=="#" or l[i-1][j]=="#" or l[i][j+1]=="#" or l[i][j-1]=="#":
      continue
    ans=1
print("YNeos"[ans::2])

Submission status: Wrong Answer

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

sss = [input() for _ in range(h)]

def f(sss, i, j):
    if sss[i][j] == '.':
        return True
    for v in (-1, 1):
        if i+v < 0 or h <= i+v:
            continue
        if sss[i+v][j] == '#':
            return True
    for u in (-1, 1):
        if j+u < 0 or w <= j+u:
            continue
        if sss[i][j+u] == '#':
            return True
    return False

def solve(sss):
    for i in range(h):
        for j in range(w):
            if f(sss, i, j):
                return True
    return False

print("Yes" if solve(sss) else "No")

Submission status: Wrong Answer

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

sss = [input() for _ in range(h)]

def f(sss, i, j):
    if sss[i][j] == '.':
        return False
    for v in (-1, 1):
        if i+v < 0 or h <= i+v:
            continue
        if sss[i+v][j] == '#':
            return True
    for u in (-1, 1):
        if j+u < 0 or w <= j+u:
            continue
        if sss[i][j+u] == '#':
            return True
    return False

def solve(sss):
    for i in range(h):
        for j in range(w):
            if f(sss, i, j):
                return True
    return False

print("Yes" if solve(sss) else "No")

Submission status: Wrong Answer

Solution code:
H, W = [int(i) for i in input().split()]
list = [list(input()) for i in range(H)]
dxy = [(-1,0), (1, 0), (0, 1), (0, -1)]
flg = True
for i in range(H):
    for j in range(W):
        count = 0
        if list[i][j] == ".":
            continue
        if list[i][j] == "#":
            for l, m in dxy:
                if (i + l < 0) or (i + l > H -1) or (j + m < 0) or (j + m > W -1):
                    continue
                if list[i + l][j + m] == "#":
                    count += 1
            print(count)
        if count == 0:
            flg = False
if flg:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
H, W = [int(i) for i in input().split()]
list = [list(input()) for i in range(H)]
dx = [-1, 0 , 1]
dy = [-1, 0 , 1]
flg = True
for i in range(H):
    for j in range(W):
        count = 0
        if list[i][j] == ".":
            continue
        if list[i][j] == "#":
            for l in dx:
                for m in dy:
                    if (i + l < 0) or (i + l > H -1) or (j + m < 0) or (j + m > W -1) or l + m == 0:
                        continue
                    if list[i + l][j + m] == "#":
                        count += 1
        if count == 0:
            flg = False
if flg:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
def count(i,j):
  count=0
  dx=[-1,0,1]
  dy=[-1,0,1]
  for x in range(3):
    for y in range(3):
      if list[i+dx[x]][j+dy[y]] == '#':
        count += 1
  if count >= 2:
    return True
  else:
    return False

h,w = map(int, input().split())
s_init='0'*(w+2)
flag=True
list=[]
list.append(s_init)
for i in range(h):
  s=str(input())
  list.append('0'+s+'0')
list.append(s_init)
for i in range(1,h+1):
  for j in range(1,w+1):
    if list[i][j]=='#':
      if not(count(i,j)):
        flag=False
if flag:
  print('Yes')
else:
  print('No')

Submission status: Wrong Answer

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

dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]
  
flg = False
for i in range(H):
  for j in range(W):
    if S[i][j] == "#":
      for k in range(4):
        flg = False
        if i+dy[k]>=0 and i+dy[k]<H and j+dx[k]>=0 and j+dx[k]<W:
          if S[i+dy[k]][j+dx[k]]=='#':
            flg = True
        if flg == False:
          print("No")
          exit()
print("Yes")

Submission status: Wrong Answer

Solution code:
h,w = map(int, input().split())
#get hight and weidth 
glid = [0] * ( h+ 2)

h_index = [-1, 0, 0,  1]
w_index = [ 0, -1, 1, 0]



glid[0]=["."] * ( w + 2 )
glid[h + 1 ] = ["."] * ( w + 2 )

for i in range(h):
	temp1 = ["."]
	temp2 = list(input())
	temp1.extend(temp2)
	temp1.append(".")
	glid[ i + 1 ] = temp1

# get glids 

flg = False
for j in range(h):
	for k in range(w):
		if glid[ j + 1 ][ k + 1 ] == ".":
			continue
		else:
			for n in range(4):
				if glid[ j  + 1 + h_index[ n ] ][ k + 1 + w_index[ n ]] == "#" :
					flg = True
					break
			if flg == False :
				break
	if flg == False :
		break

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

Submission status: Wrong Answer

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

for i in range(h):
  for j in range(w):
    if s[i][j] == "#":
      if (i + 1 < h and s[i + 1][j] == "#") or (0 <= i - 1 or s[i - 1][j] == "#") or (j + 1 < w and s[i][j + 1] == "#") or (0 <= j - 1 and s[i][j - 1] == "#"):
        continue
      else:
        print("No")
        exit()
    else:
      continue
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] == "#":
      if (i + 1 < h and s[i + 1][j] == "#") or (0 <= i - 1 or s[i - 1][j] == "#") or (j + 1 < w and s[i][j + 1] == "#") or (0 <= j - 1 and s[i][j - 1] == "#"):
          continue
      else:
        print("No")
        exit()
    else:
      continue
print("Yes")

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!

import sys

# while : 0
# black : 1
H, W = map(int, input().rstrip().split(' '))
field = [[0] * W for _ in range(H)]

for i in range(H):
    for j, c in enumerate(input()):
        if c == '#':
            field[i][j] = 1
          
if H == 1 and W == 1:
    if field[0][0] == 1:
        print('No')
    else:
        print('No')
    sys.exit()
            
for h in range(H):
    for w in range(W):
        if field[h][w] == 1:
            if h + 1 < H:
                if field[h + 1][w] == 1:
                    continue
            if h - 1 > 0:
                if field[h - 1][w] == 1:
                    continue
            if w + 1 < W:
                if field[h][w + 1] == 1:
                    continue
            if w - 1 > 0:
                if field[h][w - 1] == 1:
                    continue
                    
            print('No')
            sys.exit()
            
print('Yes')

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!

import sys

# while : 0
# black : 1
H, W = map(int, input().rstrip().split(' '))
field = [[0] * W for _ in range(H)]

for i in range(H):
    for j, c in enumerate(input()):
        if c == '#':
            field[i][j] = 1
          
if H == 1 and W == 1:
    if field[0][0] == 1:
        print('No')
    else:
        print('Yes')
    sys.exit()
            
for h in range(H):
    for w in range(W):
        if field[h][w] == 1:
            if h + 1 < H:
                if field[h + 1][w] == 1:
                    continue
            if h - 1 > 0:
                if field[h - 1][w] == 1:
                    continue
            if w + 1 < W:
                if field[h][w + 1] == 1:
                    continue
            if w - 1 > 0:
                if field[h][w - 1] == 1:
                    continue
                    
            print('No')
            sys.exit()
            
print('Yes')

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!

import sys

# while : 0
# black : 1
H, W = map(int, input().rstrip().split(' '))
field = [[0] * W for _ in range(H)]

for i in range(H):
    for j, c in enumerate(input()):
        if c == '#':
            field[i][j] = 1
            
if H == 1 and W == 1:
    print('Yes')
    sys.exit()
            
for h in range(H):
    for w in range(W):
        if field[h][w] == 1:
            if h + 1 < H:
                if field[h + 1][w] == 1:
                    continue
            if h - 1 > 0:
                if field[h - 1][w] == 1:
                    continue
            if w + 1 < W:
                if field[h][w + 1] == 1:
                    continue
            if w - 1 > 0:
                if field[h][w - 1] == 1:
                    continue
                    
            print('No')
            sys.exit()
            
print('Yes')

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!

import sys

# while : 0
# black : 1
H, W = map(int, input().rstrip().split(' '))
field = [[0] * W for _ in range(H)]

for i in range(H):
    for j, c in enumerate(input()):
        if c == '#':
            field[i][j] = 1
            
for h in range(H):
    for w in range(W):
        if field[h][w] == 1:
            if h + 1 < H:
                if field[h + 1][w] == 1:
                    continue
            if h - 1 > 0:
                if field[h - 1][w] == 1:
                    continue
            if w + 1 < W:
                if field[h][w + 1] == 1:
                    continue
            if w - 1 > 0:
                if field[h][w - 1] == 1:
                    continue
                    
            print('No')
            sys.exit()
            
print('Yes')

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())
S = [['.' for _ in range(W+2)]]+[['.'] + list(input())+ ['.'] for _ in range(H)]+[['.' for _ in range(W+2)]]
Flag = True
for i in range(1,H+1):
    for j in range(1, W+1):
        if S[i][j]=='.':
            continue
        if S[i-1][j-1] == S[i-1][j+1] == S[i+1][j-1] == S[i+1][j+1] == '.':
            Flag = False
if Flag:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())
S = [['.' for _ in range(W+2)]]+[['.'] + list(input())+ ['.'] for _ in range(H)]+[['.' for _ in range(W+2)]]
Flag = True
for i in range(1,H+1):
    for j in range(1, W+1):
        if S[i][j]=='.':
            continue
        if S[i-1][j-1] == S[i-1][j+1] == S[i+1][j-1] == S[i+1][j+1] == '.':
            Flag = False
            break
    else:
        continue
    break
if Flag:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())
S = [['.' for _ in range(W+2)]]+[['.'] + list(input())+ ['.'] for _ in range(H)]+[['.' for _ in range(W+2)]]
Flag = True
for i in range(1,H+1):
    for j in range(1, W+1):
        if S[i][j]=='.':
            continue
        if S[i-1][j-1] == S[i-1][j+1] == S[i+1][j-1] == S[i+1][j+1] == '.':
            Flagb = False
            break
    else:
        continue
    break
if Flag:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())
S = [['.']*(W + 2)] + [list('.' + input() + '.') for _ in range(H)] + [['.']*(W + 2)]
# print(S)
# 上下左右に隣り合う黒がいない黒を探す
for i in range(1, H):
    for k in range(1, W):
        if S[i][k] == '#' and S[i][k - 1] != '#' and S[i - 1][k] != '#' and S[i][k + 1] != '#' and S[i + 1][k] != '#':
            print('Yes')
            exit()
print('No')