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: Accepted

Solution code:
import sys

H,W = map(int,input().split())
s = [list(input()) for i in range(H)]
a = [["."]*W for _ in range(H)]
for i in range(H):
    for j in range(1,W):
        if s[i][j-1] == "#" and s[i][j] == "#":
            a[i][j-1] = "#"
            a[i][j] = "#"

sT = list(zip(*s))
aT = [list(x) for x in zip(*a)]

for i in range(W):
    for j in range(1,H):
        if sT[i][j-1] == "#" and sT[i][j] == "#":
            aT[i][j-1] = "#"
            aT[i][j] = "#"

ans = list(zip(*aT))

for i in range(H):
    for j in range(W):
        if s[i][j] != ans[i][j]:
            print("No")
            sys.exit()
print("Yes")

Submission status: Accepted

Solution code:
H,W=map(int,input().split(' '))
S=[list(input()) for i in range(H)]
for h in range(H):
    for w in range(W):
        if S[h][w]=='#':
            flg = False
            for x,y in [[-1,0],[1,0],[0,-1],[0,1]]:
                if 0<=h+x<H and 0<=w+y<W and S[h+x][w+y]=='#':
                    flg=True
                    break

            if not flg:
                print('No')
                exit()
print('Yes')

Submission status: Accepted

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

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

flag = True
for i in range(h):
    for j in range(w):
        if S[i][j] == ".":
            continue

        check = False
        for nx, ny in zip(dx, dy):
            nx += i
            ny += j

            if 0 <= nx < h and 0 <= ny < w:
                if S[nx][ny] == "#":
                    check = True

        if not check:
            flag = False
            break

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

Submission status: Accepted

Solution code:
def Grid_Repainting(h , w , sl):

    ans = "Yes"
    xl = [1, 0, -1, 0]
    yl = [0 , 1 , 0 , -1]

    for i in range(h):
        for v in range(w):
            count = 0
            countcheck = 4
            if sl[i][v] == "#":
                for q in range(4):
                    x = i + xl[q]
                    y = v + yl[q]
                    if x >= 0 and x < h and y >= 0 and y < w:
                        if sl[x][y] == ".":
                            count += 1
                    else:
                        countcheck -= 1
            if count == countcheck:
                ans = "No"

    return ans

def main():
    h , w = map(int , input().split())
    sl = [list(str(input())) for i in range(h)]
    print(Grid_Repainting(h , w , sl))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# abc096_c
H,W = map(int,input().split())
#glid = [][]
glid = ["."+input()+"." for i in range(H)]
glid.append("."*(W+2))
glid.insert(0,"."*(W+2))
ans = "Yes"
for i in range(1,H+1):
    for j in range(1,W+1):
        if glid[i][j]=="#":
            if glid[i][j-1] != "#" and glid[i][j+1] != "#" and glid[i-1][j] != "#" and glid[i+1][j] != "#" :
#                print(i,j,glid[i])
#                print(glid[i][j-1],glid[i][j+1], glid[i-1][j], glid[i+1][j])
                ans = "No"
print(ans)

Submission status: Accepted

Solution code:
h,w = map(int,input().split())
s = [input() for i in range(h)]
for i in range(h):
         for j in range(w):
                  if s[i][j] == "#":
                           if s[max(0,i-1)][j] == "." and s[min(h-1,i+1)][j] == "." and s[i][max(0,j-1)] == "." and s[i][min(w-1,j+1)] == ".":
                                    print("No")
                                    exit()
print("Yes")

Submission status: Accepted

Solution code:
h, w = [int(x) for x in input().split()]
matrix = [list(input()) for _ in range(h)]
surroundings = ((-1, 0), (1, 0), (0, -1), (0, 1))


def check_surroundings(i, j):
    for dis in surroundings:
        si = i + dis[0]
        sj = j + dis[1]
        if si < 0 or si >= h or sj < 0 or sj >= w:
            continue
        if matrix[si][sj] == '#':
            break
    else:
        yield True  # Can't paint.


for i in range(h):
    for j in range(w):
        if matrix[i][j] == '#':
            if sum(check_surroundings(i, j)):
                break
            else:
                continue
    else:
        continue

    print('No')
    break

else:
    print('Yes')


# 問題の意味を理解できていなかった。空中分解した黒マスがあるかどうかの判定。
# 隣のマスが無いか白か。

Submission status: Accepted

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

Submission status: Accepted

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

flag = True
output_rows = [['#' for _ in range(W)] for __ in range(H)]

for i in range(H):
    for j in range(W):
        if rows[i][j] != '#':
            continue
        else:
            found = False
            for (dx, dy) in [[0, -1], [0, 1], [-1, 0], [1, 0]]:
                y, x = i + dy, j + dx
                if x < 0 or x > W - 1 or y < 0 or y > H - 1:
                    continue
                else:
                    if rows[y][x] == '#':
                        found = True
            if not found:
                flag = False
                break

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

Submission status: Accepted

Solution code:
H, W = map(int, input().split(' '))
board = [input() for _ in range(H)]
dx = [1, 0, -1, 0]
dy = [0, -1, 0, 1]
ans = 'Yes'
for i in range(H):
    for j in range(W):
        if (board[i][j] == '#'):
            isFound = False
            for d in range(len(dx)):
                x = i + dx[d]
                y = j + dy[d]
                if (x < 0 or H <= x):
                    continue
                if (y < 0 or W <= y):
                    continue
                if (board[x][y] == '#'):
                    isFound = True
            if (isFound is False):
                ans = 'No'
print(ans)

Submission status: Accepted

Solution code:
H, W = map(int, input().split(' '))
board = [input() for i in range(H)]
dx = [1, 0, -1, 0]
dy = [0, -1, 0, 1]
ans = True
for i in range(H):
    for j in range(W):
        if (board[i][j] == '#'):
            isFound = False
            for d in range(len(dx)):
                x = i + dx[d]
                y = j + dy[d]
                if (x < 0 or H <= x):
                    continue
                if (y < 0 or W <= y):
                    continue
                if (board[x][y] == '#'):
                    isFound = True
            if (isFound is False):
                ans = False
if (ans):
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
#4方向走査
#下、右、上、左
dy=[1,0,-1,0]
dx=[0,1,0,-1]

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

field=[]
for _ in range(H):
  field.append(list(input()))

is_success=True

for y in range(H):
  for x in range(W):
    if field[y][x]==".":
      continue
    
    for k in range(4):
      tmp_y=y+dy[k]
      tmp_x=x+dx[k]

      if tmp_y<0 or tmp_y>=H or tmp_x<0 or tmp_x>=W:
        continue
      if field[tmp_y][tmp_x]=="#":
        break
      if k==3:
        print("No")
        exit()
print("Yes")

Submission status: Accepted

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

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

for i in range(h):
    for j in range(w):
        if l[i][j] == "#":
            ok=False
            for k in range(4):
                nx = j + dx[k]
                ny = i + dy[k]
                if 0<=nx<w and 0<=ny<h and l[ny][nx]=="#":
                    ok=True
            if not ok:
                print("No")
                exit()
print("Yes")

Submission status: Accepted

Solution code:
import sys
H,W = map(int,input().split())
S = []
for i in range(H):
    S.append(list(input()))
    S[i].append('0')
S.append(['0']*W)    
for i in range(H):
    for j in range(W):
        black = [S[i][j-1],S[i][j+1],S[i+1][j],S[i-1][j]]
        if S[i][j] == '#':
            if '#' not in black:
                print('No')
                sys.exit()
print('Yes')

Submission status: Accepted

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

B=[["." for _ in range(W+2)] for _ in range(H+2)]

for i in range(1,H+1):
  for j in range(1,W+1):
    B[i][j]= A[i-1][j-1]

flag=True
for i in range(1,H+1):
  if flag:
    for j in range(1,W+1):
      if B[i][j]=="#":
        if B[i-1][j]!="#" and B[i+1][j]!="#" and B[i][j-1]!="#" and B[i][j+1]!="#":
          flag=False
          break
          
if flag:
  print("Yes")
else:
  print("No")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


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

    for i in range(H):
        for j in range(W):
            if j > 0 and S[i][j - 1] != "." and S[i][j] == "#":
                S[i][j] = "*"
            elif j < W - 1 and S[i][j + 1] != "." and S[i][j] == "#":
                S[i][j] = "*"
            elif i > 0 and S[i - 1][j] != "." and S[i][j] == "#":
                S[i][j] = "*"
            elif i < H - 1 and S[i + 1][j] != "." and S[i][j] == "#":
                S[i][j] = "*"

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


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
h,w = map(int,input().split())          #周りを.で囲む↓
S=['.'+input()+'.' for i in range(h)]   #S[h][w+2]にする
S=['.'*(w+2)]+S+['.'*(w+2)]             #S[h+2][w+2]にする
ans = "Yes"
for i in range(1,h):
    for j in range(1,w):
        if S[i][j] == '#' and S[i][j-1] != '#' and S[i][j+1] != '#' and S[i-1][j] != '#' and S[i+1][j] != '#':
            ans ="No"
print(ans)

Submission status: Accepted

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

for i in range(H):
    for j in range(W):
        if path[i][j] == 0 and grid[i][j] == '#':
            judge = False
            path[i][j] = 1
            for dx, dy in [(1, 0), (-1, 0), (0, 1), (0, -1)]:
                nx = i + dx
                ny = j + dy
                if 0 <= nx < H and 0 <= ny < W and grid[nx][ny] == '#':
                    judge |= True
                    path[nx][ny] = 1
            if not judge:
                print('No')
                exit()
print('Yes')

Submission status: Accepted

Solution code:
height,width = map(int, input().split())
map_list = []
for i in range(height):
    map_list.append(list(input()))
    map_list[i].append('0')
map_list.append(['0'] * width)

for h in range(height):
    for w in range(width):
        if map_list[h][w] == '#':
            if '#' in [map_list[h-1][w], map_list[h+1][w], map_list[h][w-1], map_list[h][w+1]]:
                continue
            else:
                print("No")
                exit()

print("Yes")

Submission status: Accepted

Solution code:
height,width = map(int, input().split())
map_list = []
flag = False
for i in range(height):
    map_list.append(list(input()))
    map_list[i].append('0')
map_list.append(['0'] * width)
#print(map_list)

for h in range(height):
    for w in range(width):
        if map_list[h][w] == '#':
            #print("a")
            if '#' in [map_list[h-1][w], map_list[h+1][w], map_list[h][w-1], map_list[h][w+1]]:
                flag = True
                #print("b")
                if flag == True:
                    flag = False
                    #print("c")
            else:
                print("No")
                exit()

print("Yes")

Submission status: Accepted

Solution code:
import sys

# H行、W列
h, w = map(int, input().split())

# マス
goal = ["#" * (w + 2)]

for ii in range(h):
    st = input()
    goal.append("#" + st + "#")
    
goal.append("#####")

ng = 0
for i in range(1, h):
    for j in range(1, w):
        if goal[i][j] == "#":
            if goal[i-1][j] == "." and \
               goal[i+1][j] == "." and \
               goal[i][j-1] == "." and \
               goal[i][j+1] == ".":
                    print("No")
                    ng = 1
                    break
    if ng == 1:
        break
else:
    print("Yes")

Submission status: Accepted

Solution code:

# import
import numpy as np
import sys
sys.setrecursionlimit(10**6)

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

Mtmp = []
for _ in range(H):
    tmp = list(input())
    Mtmp.append(tmp)

M = np.array(Mtmp)
S = np.array([[0]*W]*H)

#print(M)

digtmp = np.array([[0, 1], [1, 0], [0, -1], [-1, 0]])

def dfs(i, j):
    global ngflag
    global searchflag
    if S[i, j] == 1:
        return
    S[i, j] = 1
    if M[i, j] == '.':
        return
    #print("i:{}, j:{}".format(i, j))
    searchflag = 1
    dig = digtmp + np.array([i, j])
    for d in dig:
        if 0 <= d[0] < H and 0 <= d[1] < W:
            if M[d[0], d[1]] == '#':
                ngflag = 0
                dfs(d[0], d[1])

searchflag = 0
ngflag = 1

while True:
    if 0 not in S:
        if M[target[0], target[1]] == '.':
            ngflag = 0
        break
    target = list(zip(*np.where(S == 0)))[0]
    #print("sf:{}, ng:{}".format(searchflag, ngflag))
    if M[target[0], target[1]] == '#':
        ngflag = 1
    dfs(target[0], target[1])
    if M[target[0], target[1]] == '#' and searchflag == 1 and ngflag == 1:
        break


#print("sf:{}, ng:{}".format(searchflag, ngflag))

if searchflag == 1 and ngflag == 0:
    ans = 'Yes'
elif searchflag == 1 and ngflag == 1:
    ans = 'No'
else:
    ans = 'Yes'

print(ans)

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
grid=[list(input()) for i in range(h)]
c=[['.']*w for i in range(h)]
dx=[1,0,-1,0]
dy=[0,1,0,-1]
for i in range(h):
  for j in range(w):
    for k in range(4):
      ny=i+dy[k]
      nx=j+dx[k]
      if 0<=ny<h and 0<=nx<w and grid[i][j]=='#' and grid[ny][nx]=='#':
        c[i][j]=c[ny][nx]='#'
for i in range(h):
  for j in range(w):
    if c[i][j]!=grid[i][j]:
      print('No')
      exit()
print('Yes')

Submission status: Accepted

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

ls = []

ls += [['.']*(w+2)]
for _ in range(h):
    ls += [['.'] + list(input()) + ['.']]
ls += [['.']*(w+2)]

for i in range(1, h+1):
    for j in range(1, w+1):
        if ls[i][j] != '#':
            continue
        if ls[i][j-1] != '#' and ls[i-1][j] != '#' and ls[i+1][j] != '#' and ls[i][j+1] != '#':
            print('No')
            exit()

print('Yes')

Submission status: Accepted

Solution code:
H,W=map(int,input().split())
answers=[]
answers.append([' ',]*(W+2))
for a in range(H):
    S=input()
    T=[b for b in S]
    T.append(' ')
    T.insert(0,' ')
    answers.append(T)
answers.append([' ',]*(W+2))
lll=[]
kotae=0
for a in range(H):
    A=answers[a+1]
    for b in range(W):
        if A[b+1]=='#':
            if A[b]=='#' or A[b+2]=='#'  or answers[a][b+1]=='#' or answers[a+2][b+1]=='#':
                pass
            else:
                kotae+=100
if kotae==0:
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

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

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

for i in range(h):
    for j in range(w):
        if(s[i][j]=='.'):continue
        f=False
        for k in range(4):
            ni=i+dx[k]
            nj=j+dy[k]
            if(0<=ni<=h-1 and 0<=nj<=w-1):
                if(s[ni][nj]=='#'):f=True
        if(not f):
           # print(i,j)
            print("No")
            exit()
print("Yes")

Submission status: Accepted

Solution code:
import sys

h,w = map(int,input().split())
c = [None]*h
dx = [1,0,-1,0]
dy = [0,1,0,-1]

for i in range(h):
    c[i] = input()
    
for i in range(h):
    for j in range(w):
        a = 0
        b = 0
        for k in range(4):
            nx = j + dx[k]
            ny = i + dy[k]
            if c[i][j] == '#' and 0<=nx and nx<w and 0<=ny and ny<h:
                b += 1
                if c[ny][nx] == '.':
                    a += 1
                    
        if a == b and b != 0:
            print("No")
            sys.exit()
            
print("Yes")

Submission status: Accepted

Solution code:
H,W = map(int,input().split())
field = []
for i in range(H):
    field.append(list(input()))
flag = True

#4方向走査
#下、上、左、右
dy = [1,-1,0,0]
dx = [0,0,1,-1]


for y in range(H):
    for x in range(W):
        if field[y][x] == "#":
            state = False
            for k in range(4):
                ny = y + dy[k]
                nx = x + dx[k]
                if 0 <= ny and ny < H and 0 <= nx and nx < W:
                    if field[ny][nx] == "#":
                        state = True
            if state:
                continue
            else:
                flag = False
                break

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

Submission status: Accepted

Solution code:
h,w = map(int,input().split())
ans = []
flag = True

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

for i in range(h):
    for j in range(w):
        if flag == False:
            break
        if ans[i][j] == '#':
            if j-1 >= 0:
                if ans[i][j-1] == '#':
                    continue
            if i-1 >= 0:
                if ans[i-1][j] == '#':
                    continue
            if j+1 < w:
                if ans[i][j+1] == '#':
                    continue
            if i+1 < h:
                if ans[i+1][j] == '#':
                    continue
            flag = False

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

Submission status: Accepted

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

    d = [[-1, 0], [0, -1], [0, 1], [1, 0]]

    for i in range(h):
        for j in range(w):
            for dx, dy in d:
                m = i + dx
                n = j + dy
                if m < 0 or m > h - 1:
                    pass
                elif n < 0 or n > w - 1:
                    pass
                elif l[i][j] == '#' and l[m][n] == '#':
                    l[i][j] = 'z'
                    l[m][n] = 'z'
                elif l[i][j] == 'z' and l[m][n] == '#':
                    l[m][n] = 'z'
                elif l[i][j] == '#' and l[m][n] == 'z':
                    l[i][j] = 'z'

    count = 0
    for i in l:
        count += i.count('#')

    if count == 0:
        return print('Yes')
    else:
        return print('No')

if __name__ == '__main__':
    resolve()

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
s = [["."] + list(input()) + ["."] for _ in range(h)]
s0 = ["."] * (w + 2)
s.insert(0, s0)
s.append(s0)
v = [[0, 1], [0, -1], [1, 0], [-1, 0]]
ans = 1
for i in range(1, h + 1):
    for j in range(1, w + 1):
        if s[i][j] == "#":
            c = 0
            for k in v:
                if s[i + k[0]][j + k[1]] == "#":
                    c += 1
            if c == 0:
                ans = 0
#print(s)
if ans == 1:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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):
    up = down = left = right = "."
    if S[i][j] == "#":
      if i-1 >= 0:
        up = S[i-1][j]
      if j-1 >= 0:
        left = S[i][j-1]
      if i+1 <= H-1:
        down = S[i+1][j]
      if j+1 <= W-1:
        right = S[i][j+1]
      if up == down == left == right == ".":
        print("No")
        exit()
print("Yes")

Submission status: Accepted

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

for h in range(1,H+1):
  for w in range(1,W+1):
    if S[h][w] == '#':
      if '#' not in [S[h-1][w], S[h][w-1], S[h][w+1], S[h+1][w]]:
        print('No')
        exit()
print('Yes')

Submission status: Accepted

Solution code:
## coding: UTF-8
s = input().split()
t = [int(p) for p in s]

a = []
H = t[0]
W = t[1]
for i in range(H):
    a.append(input())

#上と下に入れる行を作る
b = ''
for i in range(W+2):
    b += '.'

#上と下と右と左に空きマスを挿入する
a.insert(0, b)
for i in range(1, 1+H):
    a[i] = '.' + a[i] + '.'
a.append(b)

#print(a)

def detect(l, h, w):
    answer = 'ng'
    dx = [1, -1, 0, 0]
    dy = [0, 0, 1, -1]
    for i in range(4):
        if(l[h + dy[i]][w + dx[i]] == '#'):
            answer = 'ok'
    return answer


final_answer = 'Yes'
for i in range(len(a)):
    for j in range(len(a[i])):
        if(a[i][j] == '#'):
            #print('i:{}, j:{}, answer:{}'.format(i,j,detect(a,i,j)))
            if(detect(a,i,j) == 'ng'):
                final_answer = 'No'

print(final_answer)

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
s = []
for _ in range(H):
    s.append(input())
    
Flg = "Yes"
for i in range(H):
    for j in range(W):
        if(s[i][j] == '#'):
            if(s[i][max(j-1, 0)] == "." and s[i][min(j+1, W-1)] == '.' and s[min(i+1, H-1)][j] == '.' and s[max(i-1, 0)][j] == '.'):
                Flg = "No"

print(Flg)

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
S = [0]*(H+2)
for i in range(1,H+1):
  S[i] = '.'+input()+'.'
S[0]= '.'*(W+2)
S[H+1]= '.'*(W+2)
for i in range(1,H+1):
  for j in range(1,W+1):
    if S[i][j]=='#':
      check = [S[i-1][j],S[i][j-1],S[i+1][j],S[i][j+1]]
      if '#' not in check:
        print('No')
        exit()
print('Yes')

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
S = [0]*H
for i in range(H):
  S[i] = input()
for i in range(H):
  for j in range(W):
    if S[i][j]=='#':
      check = []
      try:
        check.append(S[i-1][j])
      except:
        check.append('.')
      try:
        check.append(S[i][j-1])
      except:
        check.append('.')
      try:
        check.append(S[i+1][j])
      except:
        check.append('.')
      try:
        check.append(S[i][j+1])
      except:
        check.append('.')
      if '#' not in check:
        print('No')
        exit()

print('Yes')

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
paint=[]
paint.append(["." for _ in range(w+2)])
for i in range(h):
    P=["."] +list(input()) +["."]
    paint.append(P)
paint.append(["." for _ in range(w+2)])
ans="Yes"
for i in range(h):
    for j in range(w):
        if paint[i+1][j+1]=="#":
            if not(paint[i][j+1]=="#" or paint[i+1][j]=="#" or paint[i+1][j+2]=="#" or paint[i+2][j+1]=="#"):
                ans="No"
                break
    else:
        continue
    break
print(ans)

Submission status: Accepted

Solution code:
from sys import exit

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

for i in range(H):
    for j in range(W):
        if goal[i][j] == "#":
            if i + 1 < H and goal[i+1][j] == "#":
                continue
            if i - 1 >= 0 and goal[i-1][j] == "#":
                continue
            if j + 1 < W and goal[i][j+1] == "#":
                continue
            if j - 1 >= 0 and goal[i][j-1] == "#":
                continue
            print("No")
            exit()
print("Yes")

Submission status: Accepted

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] != "." and a[i][j] == "#":
      a[i][j] = "*"
    elif j < w - 1 and a[i][j+1] != "." and a[i][j] == "#":
      a[i][j] = "*"
    elif i > 0 and a[i-1][j] != "." and a[i][j] == "#":
      a[i][j] = "*"
    elif i < h - 1 and a[i+1][j] != "." and a[i][j] == "#":
      a[i][j] = "*"

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

Submission status: Accepted

Solution code:
inH, inW = map(int, input().split())
inMap = list()

for i in range(inH):
  inMap.append(list(input()))

def chkPaint(x,y):
  mv = [[-1,0], [1,0], [0,-1], [0,1]]
  for pos in mv:
    if x+pos[0]<0 or x+pos[0]>=inH or y+pos[1]<0 or y+pos[1]>=inW  :
      continue
    if inMap[x+pos[0]][y+pos[1]] == "#":
        return True
  return False

flg=True
for i in range(inH):
  for j in range(inW):
    if inMap[i][j] == "#":
      flg = chkPaint(i,j)
    if flg == False:
      break
  if flg == False:
    break

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

Submission status: Accepted

Solution code:
import sys
dx = [0, -1, 1, 0]
dy = [-1, 0, 0, 1]
field = []
H, W = map(int, input().split())
for _ in range(H):
    field.append(list(input()))
for y in range(H):
    for x in range(W):
        if field[y][x] == '#':
            flag = 0
            for i in range(4):
                nx = dx[i] + x
                ny = dy[i] + y
                if nx < 0 or W <= nx or ny < 0 or H <= ny:
                    continue
                if field[ny][nx] == '#':
                    flag = 1
                    break
            if flag == 0:
                print('No')
                sys.exit()
print('Yes')

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
masu = ['.'*(w+2)]
masu += ['.' + input() + '.' for _ in range(h)]
masu.append('.'*(w+2))
ans = 'Yes'
for i in range(1,h+1):
    for j in range(1,w+1):
        if masu[i][j] == '#':
            if masu[i+1][j] == '#' or masu[i-1][j] == '#' or masu[i][j+1] == '#' or masu[i][j-1] == '#':
                continue
            else:
                ans = 'No'
                break
print(ans)

Submission status: Accepted

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

def hantei(i,j,grid):
  flag=False
  if i>0:
    flag=flag or grid[i-1][j]=='#'
  if j>0:
    flag=flag or grid[i][j-1]=='#'
  if i<h-1:
    flag=flag or grid[i+1][j]=='#'
  if j<w-1:
    flag=flag or grid[i][j+1]=='#'
  return flag

for i in range(h):
  for j in range(w):
    if grid[i][j]=='.':
      continue
    if hantei(i,j,grid)==False:
      print('No')
      exit()
print('Yes')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# Problem C - Grid Repainting

# input process
H, W = map(int, input().split())
s_list = [[0]*W for i in range(H)]
for i in range(H):
    tmp = input()
    for j in range(W):
        s_list[i][j] = tmp[j]

# search process
is_ok = True
for i in range(H):
    for j in range(W):
        if s_list[i][j]==".":
            continue
        # right process
        if j+1<W:
            if s_list[i][j+1]=="#":
                continue
        # left process
        if j-1>=0:
            if s_list[i][j-1]=="#":
                continue
        # down process
        if i+1<H:
            if s_list[i+1][j]=="#":
                continue
        # up process
        if i-1>=0:
            if s_list[i-1][j]=="#":
                continue
        # stop process
        is_ok = False
        break

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

Submission status: Accepted

Solution code:
S = input().split(" ")
N = int(S[0])
W = int(S[1])

ARR = []

for i in range(N):
    ar = list(input())
    ARR.append(ar)


def calculate(n, w, arr):
    result = True
    hasShape = False
    for i in range(n):
        for j in range(w):
            if arr[i][j] == "#":
                hasShape = True
                sss = []
                if i -1 >= 0:
                    sss.append(arr[i-1][j])
                if i + 1 < n:
                    sss.append(arr[i+1][j])

                if j - 1 >= 0:
                    sss.append(arr[i][j-1])
                if j + 1 < w:
                    sss.append(arr[i][j+1])

                if "#" not in sss:
                    result = False
                    break

    if hasShape == False:
        print("Yes")
        return

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


calculate(N, W, ARR)

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
S = [list(input()) for _ in range(h)]
drc = [[0,1],[0,-1],[1,0],[-1,0]]
for i in range(h):
  for j in range(w):
    if S[i][j] == "#":
      if all([S[i+y][j+x] == "." for x, y in drc if (0 <= j+x < w) and (0 <= i+y < h)]):
        print("No")
        exit()
print("Yes")

Submission status: Accepted

Solution code:
n,w=map(int,input().split())
st=[]
for i in range(n):
    st.append(list(input())) #0~n-1までの列ができる
if n==w==1:
    print("Yes")
    exit()

for i in range(1,n-1):
    for j in range(1,w-1): #i,jに1足しても引いても範囲内だから安心！
        if st[i][j]=="#":
            if st[i+1][j]=="." and st[i][j-1]=="." and st[i][j+1]=="." and st[i-1][j]==".":
                print("No")
                exit()
        

print("Yes")