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:
H, W = map(int, input().split(" "))

area = [["." for _ in range(W+2)]]
for _ in range(H):
    line = [d for d in ("."+input()+".")]
    area.append(line)
area.append(["." for _ in range(W+2)])
    
def distinct(x,y):
    if area[y+1][x] == "#" or area[y-1][x] == "#" or \
        area[y][x+1] == "#" or area[y][x-1] == "#":
        return 0
    else:
        return 1
    
flg = 0
for y in range(1,H+1):
    for x in range(1,W+1):
        if area[y][x] == "#":
            if distinct(x,y) == 1:
                flg = 1
                break
    if flg == 1:
        break

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

Submission status: Accepted

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

for i in range(h):
    for j in range(w):
        #print(S[i][j])
        cnt = 0
        if i == 0 or i == h - 1:
            cnt += 1
        if j == 0 or j == w - 1:
            cnt += 1

        if S[i][j] == "#" and i+1 < h and S[i+1][j] != "#":
                cnt += 1

        if S[i][j] == "#" and j+1 < w and S[i][j+1] != "#":
                cnt += 1

        if S[i][j] == "#" and i-1 > 0 and S[i-1][j] != "#":
                cnt += 1

        if S[i][j] == "#" and j-1 > 0 and S[i][j-1] != "#":
                cnt += 1

        if cnt == 4:
            print("No")
            exit()
print("Yes")

Submission status: Accepted

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

ch1=0

for x in range(h):
  for y in range(w):
    b=a[x][y]
    ch=0
    if b=='#':
      if 0<=x-1<=h-1 and a[x-1][y]=='#':
        ch+=1
      if 0<=x+1<=h-1 and a[x+1][y]=='#':
        ch+=1
      if 0<=y-1<=w-1 and a[x][y-1]=='#':
        ch+=1
      if 0<=y+1<=w-1 and a[x][y+1]=='#':
        ch+=1
      
      if ch==0:
        ch1+=1
   
  
if ch1==0:
  print('Yes')
else:
  print('No')

Submission status: Accepted

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

def judge (y,x):
    if y == 0:
        if x == 0:
            # gridの一番左上 → 右か下が # ならOK
            if grid[y][x+1] == '#' or grid[y+1][x] == '#':
                return True
            else:
                return False
        elif x == w-1:
            # gridの一番右上 → 左か下が # ならOK
            if grid[y][x-1] == '#' or grid[y+1][x] == '#':
                return True
            else:
                return False
        else:
            # girdの一番上列 → 左右か下が # ならOK
            if grid[y][x-1] == '#' or grid[y+1][x] == '#' or grid[y][x+1] == '#':
                return True
            else:
                return False
    elif y == h-1:
        if x == 0:
            # gridの一番左下 → 右か上が # ならOK
            if grid[y][x+1] == '#' or grid[y-1][x] == '#':
                return True
            else:
                return False
        elif x == w-1:
            # gridの一番右下 → 左か上が # ならOK
            if grid[y][x-1] == '#' or grid[y-1][x] == '#':
                return True
            else:
                return False
        else:
            # girdの一番下列 → 左右か上が # ならOK
            if grid[y][x-1] == '#' or grid[y-1][x] == '#' or grid[y][x+1] == '#':
                return True
            else:
                return False
    elif x == 0:
        # grid の一番左列。左上と左下のパターンは考えなくてOK
        if grid[y][x+1] == '#' or grid[y-1][x] == '#' or grid[y+1][x] == '#':
            return True
        else:
            return False
    elif x == w-1:
        # grid の一番右列。右上と右下のパターンは考えなくてOK
        if grid[y][x-1] == '#' or grid[y-1][x] == '#' or grid[y+1][x] == '#':
            return True
        else:
            return False
    else:
        # 端っこの列じゃない場合
        if grid[y+1][x] == '#' or grid[y-1][x] == '#' or grid[y][x+1] == '#' or grid[y][x-1] == '#':
            return True
        else:
            return False

for line in range(h):
    for p in range(w):
        if grid[line][p] == "#":
            if judge (line,p):
                pass
            else:
                print ("No")
                exit ()
print ("Yes")

Submission status: Accepted

Solution code:
import math
import sys
import collections
import bisect


def main():
    h, w = map(int, input().split())
    hw = [["."] * (w + 2)] + [0] * h + [["."] * (w + 2)]
    for i in range(h):
        hw[i + 1] = ["."] + list(input()) + ["."]
    for i in range(1, h + 1):
        for j in range(1, w + 1):
            if hw[i][j] == "#":
                if hw[i - 1][j] == "#" or hw[i + 1][j] == "#" or hw[i][j - 1] == "#" or hw[i][j + 1] == "#":
                    continue
                else:
                    print("No")
                    return
    print("Yes")


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#13
import sys

h,w = map(int,input().split())
s = []
s.append(list("."*(w+2)))
for i in range(h):
    a = "."+input()+"."
    s.append(list(a))
s.append(list("."*(w+2)))


for i in range(1,h+1):
    for j in range(1,w+1):
        check = 0
        if s[i][j] == "#":
            for m in range(i-1,i+2,2):
                if s[m][j] == "#":
                    check +=1
                    break
            if check == 0:
                for n in range(j-1,j+2,2):
                    if s[i][n] == "#":
                        check += 1
                        break
            if check == 0:
                print("No")
                sys.exit()
            
            
            
print("Yes")

Submission status: Accepted

Solution code:
dxdy = ((0,1),(0,-1),(1,0),(-1,0))
 
H, W = map(int,input().split())
S = []
 
S.append('.'*(W+2))
for h in range(H):
    s = input()
    S.append('.'+s+'.')
S.append('.'*(W+2))
 
#print (S)
 
for h in range(1,H+1):
    for w in range(1,W+1):
        if S[h][w] == '.':
            continue
        ok = False
        for dx,dy in dxdy:
            if S[h+dx][w+dy] == '#':
                ok = True
                break
        if ok == False:
            print ('No')
            exit()
print ('Yes')

Submission status: Accepted

Solution code:
import numpy as np

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

s=np.zeros((H+2,W+2),dtype=int)

for i in range(H):
    s0=input()
    for j in range(W):
        if s0[j]==".":
            num=0
        elif s0[j]=="#":
            num=1
        
        s[i+1][j+1]=num
        

ans_s=s[1:H+1,1:W+1]

ans=0
for k in range(1,H+1):
    for l in range(1,W+1):
        if s[k][l]==1:
            if s[k-1][l]==0 and s[k+1][l]==0 and s[k][l-1]==0 and s[k][l+1]==0:
                ans=1
                break

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

Submission status: Accepted

Solution code:
H,W=map(int,input().split())
g=[[0]*(W+2)]+[[0]+[(i=="#")*1 for i in list(input())]+[0] for _ in range(H)]+[[0]*(W+2)]
ans="Yes"
for i in range(1,H+1):
  for j in range(1,W+1):
    t=0
    if g[i][j]==0:
      continue
    if g[i-1][j]==1:
      t+=1
    if g[i+1][j]==1:
      t+=1
    if g[i][j-1]==1:
      t+=1
    if g[i][j+1]==1:
      t+=1
    if t==0:
      ans="No"
      break
print(ans)

Submission status: Accepted

Solution code:
import numpy as np

H,W = [int(i) for i in input().split()]

maze = [['.']*(W+2)]
for i in range(H):
    maze.append(list('.'+input()+'.'))
maze.append(['.']*(W+2))

for i in range(1,H+1):
    for j in range(1,W+1):
        if maze[i][j] == '#':
            if maze[i-1][j] != '#' and maze[i+1][j] != '#' and maze[i][j-1] != '#' and maze[i][j+1] != '#':
                print('No')
                exit()

print('Yes')

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
H, W = map(int, input().split())
M = [list(input()) for _ in range(H)]

# yoko
for i in range(H):
    for j in range(W-1):
        if (M[i][j] == '#' or M[i][j] == 'M') and (M[i][j+1] == '#' or M[i][j+1] == 'M'):
            M[i][j] = 'M'
            M[i][j+1] = 'M'

#tate
for j in range(W):
    for i in range(H-1):
        if (M[i][j] == '#' or M[i][j] == 'M') and (M[i+1][j] == '#' or M[i+1][j] == 'M'):
            M[i][j] = 'M'
            M[i+1][j] = 'M'

ret = 0
for m in M:
    ret += m.count('#')

if ret == 0: print('Yes')
else: print('No')

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
S = []
for i in range(H):
    S.append(input())
for i in range(H):
    for j in range(W):
        safe = False
        s = S[i][j]
        if s == '#':
            if i != 0 and S[i-1][j] == '#': safe = True
            if j != 0 and S[i][j-1] == '#': safe = True
            if j != W-1 and S[i][j+1] == '#': safe = True
            if i != H-1 and S[i+1][j] == '#': safe = True
            if not safe:
                print('No')
                exit()
print('Yes')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
H,W=map(int,input().split())
s=[list(map(int, list(input().replace('#','1').replace('.','0')))) for _ in range(H)]

padded = [[0 for i in range(W+2)] for j in range(H+2)]

for i in range(H):
  for j in range(W):
    padded[i+1][j+1] = s[i][j] 

for i in range(1,H+1):
  for j in range(1,W+1):
    if padded[i][j]==1:
      if padded[i+1][j]==0 and padded[i-1][j]==0 and padded[i][j+1]==0 and padded[i][j-1]==0:
        print('No')
        exit()
print('Yes')

Submission status: Accepted

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

for i in range(H):
    for j in range(W):
        if arr[i][j] == '#':
            flg =False
            if i-1>=0:
                if arr[i-1][j] == '#':
                    flg = True
            if j-1>=0:
                if arr[i][j-1] == '#':
                    flg = True
            if i+1<H:
                if arr[i+1][j] == '#':
                    flg = True
            if j+1<W:
                if arr[i][j+1] == '#':
                    flg = True
            if flg == False:
                print('No')
                exit()

print('Yes')

Submission status: Accepted

Solution code:
# AtCoder Beginner Contest 096
# C - Grid Repainting 2

def f (i,j):
    if any ([area[i-1][j]=='#',
            area[i+1][j]=='#',
            area[i][j-1]=='#',
            area[i][j+1]=='#']):
        return True



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

area=['.'*(W+2)]

for i in range (H):
    A='.'+ input() +'.'
    area.append(A)

area.append('.'*(W+2))

ans='Yes'

for i in range (1,H+1):
    for j in range (1,W+1):
        if area[i][j]=='#':
            if f(i,j)==True:
                pass
            else:
                ans='No'
                break
        else:
            pass

print(ans)

Submission status: Accepted

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

for i in range(1,h+1):
    for j in range(1,w+1):
        t = 0
        if g[i][j] == 0:
            continue
        if g[i-1][j] == 1:
            t += 1
        if g[i+1][j] == 1:
            t += 1
        if g[i][j-1] == 1:
            t += 1
        if g[i][j+1] == 1:
            t += 1
        if t == 0:
            print("No")
            quit()

print("Yes")

Submission status: Accepted

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

S = [input() for _ in range(H)]

jdg = True
for i in range(H):
    for j in range(W):
        ans = 0
        if S[i][j] == '#':
            ans += 1
            for x, y in [[1, 0], [-1, 0], [0, 1], [0, -1]]:
                if 0 <= i + y <= H - 1 and 0 <= j + x <= W - 1:
                    if S[i + y][j + x] == '#':
                        ans += 1
            if ans == 1:
                jdg = False
                break
    if not jdg:break
print('Yes' if jdg else 'No')

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
s=[input() for i in range(h)]
res=True
a=[0,-1,1,0]
b=[-1,0,0,1]
for i in range(h):
    for j in range(w):
        if s[i][j]==".":
            continue
        else:
            res=False
            for k in range(4):
                if 0<=a[k]+i<h and 0<=b[k]+j<w:
                    if s[a[k]+i][b[k]+j]=="#":
                        res=True
        if not res:
            break
    if not res:
        break

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

Submission status: Accepted

Solution code:
import sys
import heapq
import math
import fractions
import bisect
import itertools
from collections import Counter
from collections import deque
from operator import itemgetter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

h,w=mp()
g=["."*(w+2)]
for i in range(h):
    g.append("."+input()+".")
g.append("."*(w+2))
v=[[1,0],[-1,0],[0,1],[0,-1]]
for i in range(1,h+1):
    for j in range(1,w+1):
        if g[i][j]=="#":
            c=True
            for x,y in v:
                if g[i+x][j+y]=="#":
                    c=False
            if c:
                print("No")
                exit()
print("Yes")

Submission status: Accepted

Solution code:
H,W = map(int,input().split())
S = [input() for _ in range(H)]
A = [(1,0),(0,1),(-1,0),(0,-1)]
for i in range(H):
    for j in range(W):
        if S[i][j] == "#":
            bol = 0
            for dx,dy in A:
                if 0<=j+dx<=W-1 and 0<=i+dy<=H-1:
                    if S[i+dy][j+dx] == "#":
                        bol = 1
            if bol == 0:
                print("No")
                exit()
print("Yes")

Submission status: Accepted

Solution code:
import sys
h, w = map(int, input().split())
l = [list(input()) for i in range(h)]
for i in range(h):
  l[i] = ["."] + l[i] + ["."]
l = [["." for i in range(w+2)]] + l + [["." for i in range(w+2)]]
for i in range(1, h+1):
  for j in range(1, w+1):
    if l[i][j] == "#":
      if "#" not in [l[i-1][j], l[i][j-1], l[i][j+1], l[i+1][j]]:
        print("No")
        sys.exit()
print("Yes")

Submission status: Accepted

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

grid = []
for _ in range(h):
    grid.append(list(input()))

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


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

        for x,y in zip(dx,dy):
            if i+x<0 or i+x>h-1 or j+y<0 or j+y>w-1:
                continue
            if grid[i+x][j+y]=="#":
                flag=True
                break

        if not flag:
            print("No")
            exit()

print("Yes")

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]
s = [["."] * (w+2)] + [[".", *i, "."] for i in s] + [["."] * (w+2)]
ans = "Yes"
for i in range(1, h+1):
    for j in range(1, w+1):
        if s[i][j] == "#":
            if s[i-1][j] == "." and s[i][j-1] == "." and s[i][j+1] == "." and s[i+1][j] == ".":
                ans = "No"
                break
print(ans)

Submission status: Accepted

Solution code:
import sys
import itertools
# import numpy as np
import time
import math
import heapq
from collections import defaultdict
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())

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

for i in range(H):
    for j in range(W):
        ok = False
        for dy, dx in [(1, 0), (0, 1), (-1, 0), (0, -1)]:
            y = i + dy
            x = j + dx
            if y < 0 or y >= H or x < 0 or x >= W:
                continue
            if S[i][j] == '.':
                ok = True
                continue

            if S[y][x] == '#':
                ok = True
        if not ok:
            print("No")
            exit()
print("Yes")

Submission status: Accepted

Solution code:
import itertools
import sys

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

for i, j in itertools.product(range(H), range(W)):  # jが先に増える
    c = 0
    if S[i][j] == "#":
        if i != 0 and S[i - 1][j] == "#":
            c += 1

        if i != H - 1 and S[i + 1][j] == "#":
            c += 1

        if j != 0 and S[i][j - 1] == "#":
            c += 1

        if j != W - 1 and S[i][j + 1] == "#":
            c += 1

        if c == 0:
            print("No")
            sys.exit()
            break
else:
    print("Yes")

Submission status: Accepted

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

lls = ["."*(w+2)]+["."+w+"."for w in lls] + ["."*(w+2)]
# N E S W
direction = [[-1, 0], [0, 1], [1, 0], [0, -1]]
cond = True
for i in range(1, h+2):
    for j in range(1, w+2):
        if lls[i][j] == ".":
            continue
        nb = False
        for d1, d2 in direction:
            if lls[i+d1][j+d2] == "#":
                nb = True
        if nb == False:
            cond = False

        now_dir = 0

print("Yes" if cond else "No")

Submission status: Accepted

Solution code:
[h,w] = [int(i) for i in input().split()]
ls = [["."] * (w+2)]
for i in range(h):
    tmp = input()
    tmp_ls = ["."]
    for j in range(w):
        tmp_ls.append(tmp[j])
    tmp_ls.append(".")
    ls.append(tmp_ls)
ls.append(["."] * (w+2))
ans = "Yes"

for i in range(1,h+1):
    for j in range(1,w+1):
        flag = 0
        if ls[i][j] == "#":
            flag = flag or (ls[i-1][j] == "#")
            flag = flag or (ls[i+1][j] == "#")
            flag = flag or (ls[i][j-1] == "#")
            flag = flag or (ls[i][j+1] == "#")
            if flag == 0:
                ans = "No"
print(ans)

Submission status: Accepted

Solution code:
H,W = [int(i) for i in input().split()]
S = [list(input()) for i in range(H)]
box = [[1,0], [-1,0], [0,1], [0,-1]]
pos = True
for i in range(H):
    for j in range(W):
        if S[i][j] == "#":
            for dx,dy in box:
                x,y = i+dx, j+dy
                if 0 <= x < H and 0 <= y < W and S[x][y] == "#":
                    break
            else:
                pos = False
print("Yes" if pos else "No")

Submission status: Accepted

Solution code:
H,W=map(int,input().split())
s=[list(input())for i in range(H)]
c=[['.']*W for i in range(H)]
for i in range(H):
    countX=0
    nowX=s[i][0]
    for j in range(W):
        if nowX==s[i][j]:
            countX+=1
            if 1<countX and nowX=='#':
                c[i][j-1],c[i][j]='#','#'
        else:
            countX=1
        nowX=s[i][j]
for i in range(W):
    countY=0
    nowY=s[0][i]
    for j in range(H):
        if nowY==s[j][i]:
            countY+=1
            if 1<countY and nowY =='#':
                c[j-1][i],c[j][i]='#','#'
        else:
            countY=1
        nowY=s[j][i]
print('Yes' if c==s else 'No')

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
g=[input() for _ in range(h)]
for x in range(h):
  for y in range(w):
    if g[x][y]=='.': continue
    ng=1
    for dx,dy in [(1,0),(0,1),(-1,0),(0,-1)]:
      nx,ny=x+dx,y+dy
      if 0<=nx<h and 0<=ny<w:
        if g[nx][ny]=='#': ng=0
    if ng:
      print('No')
      exit()
print('Yes')

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
g=[input() for _ in range(h)]
for x in range(h):
  for y in range(w):
    if g[x][y]=='.': continue
    ok=0
    for dx,dy in [(1,0),(0,1),(-1,0),(0,-1)]:
      nx,ny=x+dx,y+dy
      if 0<=nx<h and 0<=ny<w:
        if g[nx][ny]=='#': ok=1
    if ok<1:
      print('No')
      exit()
print('Yes')

Submission status: Accepted

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

H,W = [int(i) for i in input().split()]
F = []
F.append("."*(W+2))
for i in range(H):
    F.append("."+input()+".")
F.append("."*(W+2))

flg = True
for y in range(1,H+1):
    for x in range(1,W+1):
        if F[y][x] == '.':
            continue
        elif F[y-1][x] != '#' and F[y+1][x] != '#' and F[y][x-1] != '#' and F[y][x+1] != '#':
            flg = False
            break
if flg:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
H,W = map(int,input().split())
S = [(W+2)*"."]+["."+input()+"." for h in range(H)]+[(W+2)*"."]
ans = "Yes"

for h in range(1,H+1):
  for w in range(1,W+1):
    if S[h][w]=="#" and S[h][w-1]==S[h][w+1]==S[h-1][w]==S[h+1][w]==".":
      ans = "No"

print(ans)

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
s = [list(input()) for _ in range(H)]
dd = [[0, -1], [-1, 0], [0, 1], [1, 0]]
for i in range(H):
    for j in range(W):
        if s[i][j] == "#":
            for dx, dy in dd:
                nx = j + dx
                ny = i + dy
                if 0 <= nx < W and 0 <= ny < H:
                    if s[ny][nx] == "#":
                        break
            else:
                print("No")
                exit(0)

print("Yes")

Submission status: Accepted

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

def koritu(h,w):
    bo=0
    hoko = [[1,0],[0,1],[-1,0],[0,-1]]
    for ya in hoko:
        if 0 <= h+ya[0] < H and 0 <= w+ya[1] < W:
            if masu[h+ya[0]][w+ya[1]] == '#':
                bo = 1
    return bo
   
   
k = 1
for w in range(W):
    for h in range(H):
        if masu[h][w] == '#' and koritu(h,w)==0:
            print('No')
            break
    else:
        continue
    break
else:print('Yes')

Submission status: Accepted

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

for i in range(h):
    for j in range(w):
        if masu[i][j] == '.':
            continue

        directions = [[1,0],[0,1],[-1,0],[0,-1]]
        for d in directions:
            if 0 <= i + d[0] <= h-1 and 0 <= j + d[1] <= w-1:
                if masu[i+d[0]][j+d[1]] != '.':
                    masu[i][j] = '黒'
                    masu[i + d[0]][j + d[1]] = '黒'

if '#' in list(itertools.chain.from_iterable(masu)):
    print('No')
else:
    print('Yes')

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
field = [list(input()) for _ in range(h)]
dx = [0, 1, 0, -1]
dy = [-1, 0, 1, 0]
count = 0
for i in range(h):
    for j in range(w):
        if field[i][j] == '#':
            count = 0
            for d in range(4):
                if 0<=i+dy[d]<h and 0<=j+dx[d]<w:
                    count += 1 if field[i+dy[d]][j+dx[d]]=='#' else 0

            if count<1:
                print('No')
                exit()
print('Yes')

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
# H行受け取る
ab = list(input() for _ in range(h))
# (h+2)*(w+2)、indexは0,1,...,h+1(or w+1)で、考えるのは1,2,...,h(or w)
dp = [["_" for i in range(w + 2)] for j in range(h + 2)]

for i in range(h):
    for j in range(w):
        dp[i + 1][j + 1] = ab[i][j]

for i in range(h):
    for j in range(w):
        if dp[i + 1][j + 1] == "#":
            # 四方の少なくとも一つが#ならOK
            if dp[i][j + 1] == "#" or dp[i + 2][j + 1] == "#" or dp[i + 1][j] == "#" or dp[i + 1][j + 2] == "#":
                pass
            # そうでない場合は塗ることはできない
            else:
                print("No")
                exit()

print("Yes")

Submission status: Accepted

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

s = [list(input()) for y in range(H)]

for y in range(H):
    for x in range(W):
        if s[y][x]=="#":
            enable = False
            if x-1>=0 and s[y][x-1]=="#":
                enable=True
            if x+1<W and s[y][x+1]=="#":
                enable=True
            if y-1>=0 and s[y-1][x]=="#":
                enable=True
            if y+1<H and s[y+1][x]=="#":
                enable=True
            if enable==False:
                print("No")
                exit()
print("Yes")

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
n, *g = [i.split() for i in open(0)]
h, w = map(int, n)
d = ((1, 0), (-1, 0), (0, -1), (0, 1))
for i in range(h):
    for j in range(w):
        if g[i][0][j] == "#":
            if all(g[i + p][0][j + q] == "." for p, q in d
                   if 0 <= i + p < h and 0 <= j + q < w):
                print("No")
                exit()
print("Yes")

Submission status: Accepted

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

ab = list(input() for _ in range(h))

dp =[["_" for i in range(w+2)] for j in range(h+2)]

for i in range(h):
    for j in range(w):
        dp[i+1][j+1] = ab[i][j]

for i in range(h):
    for j in range(w):
        if dp[i+1][j+1] =="#":
            if dp[i][j+1]=="#" or dp[i+2][j+1]=="#" or dp[i+1][j] =="#" or dp[i+1][j+2]=="#":
                pass
            else:
                print("No")
                exit()
print("Yes")

Submission status: Accepted

Solution code:
h,w = map(int,input().split())
s = [list(input()) for i in range(h)]
for i in range(h):
    s[i].insert(w,0)
    s[i].insert(0,0)
s.insert(h,[0]*(w+2))
s.insert(0,[0]*(w+2))
x = '#'
for i in range(1,h+1):
    for j in range(1,w+1):
        if s[i][j] == x:
            if s[i-1][j] == x or s[i][j-1] == x or s[i][j+1] == x or s[i+1][j] == x:
                pass
            else:
                print('No')
                exit(0)

print('Yes')

Submission status: Accepted

Solution code:
H,W = map(int,input().split())
t = [list(input()) for _ in range(H)]
udlr = [[-1, 0],[ 1, 0],[ 0,-1],[ 0, 1]]
#[print(line) for line in t];print()

exist_F_count = 0
for i in range(H):
    for j in range(W):
        if t[i][j] == "#":
            exist = False
            for x,y in udlr:
                if (0 <= i+x < H) and (0 <= j+y < W):
                    if t[i+x][j+y] == "#":
                        exist = True
                        break
            if exist == False:
                exist_F_count += 1
                print("No")
                exit()
if exist_F_count == 0:
    print("Yes")

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
def main():
    h, w = map(int, input().split())
    # 「黒にするマス」の上下左右にも１つ以上の「黒にするマス」があればOK。
    # '#'を1、'.'を0にする。
    # グリッドの上下左右にダミーマスとして0を置く。
    grid = []
    grid.append([0] * (w + 2))
    for _ in range(h):
        row = list(input())
        row2 = [1 if c == '#' else 0 for c in row]
        grid.append([0] + row2 + [0])
    grid.append([0] * (w + 2))

    for i1 in range(1, h + 1):
        for i2 in range(1, w + 1):
            if grid[i1][i2] == 1:
                black = grid[i1-1][i2] + grid[i1][i2-1] + grid[i1][i2+1] + grid[i1+1][i2]
                if black == 0:
                    print('No')
                    sys.exit()
    print('Yes')

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
H, W = list(map(int,input().split()))
s = []
for i in range(H):
    s.append(input())
r = "Yes"
for i in range(H):
    for j in range(W):
        if s[i][j]==".":
            continue
        p = False
        for y,x in [[i-1,j],[i+1,j],[i,j-1],[i,j+1],]:
            if 0<=y<H and 0<=x<W and s[y][x]=="#":
                p = True
        if not p:
            r = "No"
print(r)

Submission status: Accepted

Solution code:
h, w = map(int, input().split(" "))
s = []
for i in range(h):
    s.append(str(input()))
d = [(1, 0), (0, 1), (-1, 0), (0, -1)]
ss = ["" for i in range(h)]
for i in range(h):
    for j in range(w):
        f = False
        if s[i][j] == ".":
            f = True
            continue
        for dy, dx in d:
            if 0 <= i + dy < h and 0 <= j + dx < w:
                if s[i + dy][j + dx] == "#":
                    f = True
                    break
        if not f:
            break
    if not f:
        break

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

Submission status: Accepted

Solution code:
import sys
H, W = list(map(int, input().split()))
C = [list(input()) for _ in range(H)]
for i in range(H):
    for j in range(W):
        if C[i][j] == '#':
            cnt = 0
            if i - 1 >= 0 and C[i - 1][j] == '#':
                cnt += 1
            if i + 1 < H and C[i + 1][j] == '#':
                cnt += 1
            if j - 1 >= 0 and C[i][j - 1] == '#':
                cnt += 1
            if j + 1 < W and C[i][j + 1] == '#':
                cnt += 1
            if cnt == 0:
                print('No')
                sys.exit()
print('Yes')

Submission status: Accepted

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

for y in range(1,h+1):
    for x in range(1,w+1):
        if S[y][x] == "#":
            if S[y-1][x] == "." and S[y+1][x] == "." and S[y][x+1] == "." and S[y][x-1] == ".":
                print("No")
                exit()
print("Yes")

Submission status: Accepted

Solution code:
import sys
import math
import itertools as it
def I():return int(sys.stdin.readline().replace("\n",""))
def I2():return map(int,sys.stdin.readline().replace("\n","").split())
def S():return str(sys.stdin.readline().replace("\n",""))
def L():return list(sys.stdin.readline().replace("\n",""))
def Intl():return [int(k) for k in sys.stdin.readline().replace("\n","").split()]
def Lx(k):return list(map(lambda x:int(x)*-k,sys.stdin.readline().replace("\n","").split()))

if __name__ == "__main__":
    h,w = I2()
    s = [S() for _ in range(h)]
    for i in range(1,h-1):
        for j in range(1,w-1):
            if(s[i][j] == "#" and s[i][j-1]!="#" and s[i][j+1]!="#" and s[i-1][j]!="#" and s[i+1][j] != "#"):
                print("No")
                exit()
    print("Yes")