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
def main():
    input = sys.stdin.readline
    H,W = map(int, input().split())
    s = [list(input().rstrip()) for _ in range(H)]

    def check(i, j):
        for di, dj in [(0,1),(0,-1),(1,0),(-1,0)]:
            ni, nj = i+di, j+dj
            if ni < 0 or ni >= H or nj < 0 or nj >= W: continue
            if s[ni][nj] == '#': return True
        return False

    for i in range(H):
        for j in range(W):
            if s[i][j] == '#':
                if check(i,j) == False: return False
    return True

if __name__ == '__main__':
    print('Yes' if main() else 'No')

Submission status: Accepted

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7

h,w = MAP()
s = [STR() for _ in range(h)]
ii = [-1, 1, 0, 0]
jj = [0, 0, -1, 1]
for i in range(h):
    for j in range(w):
        if s[i][j] == '#':
            flag = [False for _ in range(4)]
            for k in range(4):
                iii = i + ii[k]
                jjj = j + jj[k]
                if 0 <= iii < h and 0 <= jjj < w and s[iii][jjj] == '#':
                    flag[k] = True
            if not sum(flag):
                print('No')
                exit()
print('Yes')

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
field = [list(input()) for i in range(n)]
flg = True
dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]
for i in range(n):
    for j in range(m):
        if field[i][j] == "#":
            f = 0
            for k in range(4):
            # 移動した後の点を (nx, ny) とする
                nx = i + dx[k]
                ny = j + dy[k]
                if 0 <= nx and nx < n and 0 <= ny and ny < m and field[nx][ny] == "#":
                    f += 1
            if f==False:
                flg = False
                
print("Yes" if flg else "No")

Submission status: Accepted

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7

h,w = MAP()
s = [STR() for _ in range(h)]
for i in range(h):
    for j in range(w):
        if s[i][j] == '#':
            flag = [False for _ in range(4)]
            if i > 0 and s[i-1][j] == '#':
                flag[0] = True
            if i < h - 1 and s[i+1][j] == '#':
                flag[1] = True
            if j > 0 and s[i][j-1] == '#':
                flag[2] = True
            if j < w - 1 and s[i][j+1] == '#':
                flag[3] = True
            if sum(flag) == 0:
                print('No')
                exit()
print('Yes')

Submission status: Accepted

Solution code:
from collections import deque
H,W=map(int,input().split())
s=[list(input()) for i in range(H)]
def dfs(h,w):
    q=deque()
    q.append((h,w))
    s[h][w]='.'

    dx=[0,1,0,-1]
    dy=[1,0,-1,0]
    cnt=0
    while q:
        task=q[-1]
        for i in range(4):
            nx=task[0]+dx[i]
            ny=task[1]+dy[i]
            if not(0<=nx<H and 0<=ny<W):continue
            if s[nx][ny]!='#':continue
            q.append((nx,ny))
            s[nx][ny]='.'
            cnt+=1
            break
        else:
            if cnt==0:
                print('No')
                exit()
            q.pop()
    return s
for i in range(H):
    for j in range(W):
        if s[i][j]=='#':
            s=dfs(i,j)
"""
for i in s:
    for j in i:
        if j=='#':
            print('No')
            exit()
"""
print('Yes')

Submission status: Accepted

Solution code:
if __name__ == "__main__":
    h, w = map(int, input().split())
    s = list()
    s.append('.' * (w + 2))
    for i in range(h):
        s.append('.' + input() + '.')
    s.append('.' * (w + 2))

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

Submission status: Accepted

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

for i in range(H):
    for j in range(W):
        if S[i][j] == "#":
            flag = False
            for x,y in [[i-1,j],[i+1,j],[i,j+1],[i,j-1]]:
                if 0 <= x < H and 0 <= y < W and S[x][y]=="#":
                    flag = True
            if not flag:
                print("No")
                exit()
print("Yes")

Submission status: Accepted

Solution code:
import sys
def main():
    input = sys.stdin.readline
    H,W = map(int, input().split())
    s = [list(input().rstrip()) for _ in range(H)]

    c = lambda i,j: i*W+j
    used = [False] * (H*W+1)
    def dfs(si, sj):
        depth = 0
        stack = [(si, sj, 0)]
        while stack:
            i, j, d = stack.pop()
            for di, dj in [(0,1),(0,-1),(1,0),(-1,0)]:
                ni, nj = i+di, j+dj
                if ni < 0 or ni >= H or nj < 0 or nj >= W: continue
                if s[ni][nj] != '#': continue
                if used[c(ni,nj)]: continue
                used[c(ni,nj)] = True
                stack.append((ni, nj, d+1))
                depth = max(depth, d+1)
        return depth

    for i in range(H):
        for j in range(W):
            if used[c(i,j)] == False and s[i][j] == '#':
                depth = dfs(i,j)
                if depth == 0: return False
    return True

if __name__ == '__main__':
    print('Yes' if main() else 'No')

Submission status: Accepted

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

    for h in range(H):
        for w in range(W):
            if S[h][w] == '#':
                ok = False
                if h > 0 and S[h - 1][w] == '#':
                    ok = True
                if h < H - 1 and S[h + 1][w] == '#':
                    ok = True
                if w > 0 and S[h][w - 1] == '#':
                    ok = True
                if w < W - 1 and S[h][w + 1] == '#':
                    ok = True
                if not ok:
                    print('No')
                    return

    print('Yes')


if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
DX = (-1, 0, 1, 0)
DY = (0, 1, 0, -1)

S = [[1] * (W + 2) for _ in range(H + 2)]
for i in range(1, H + 1):
    for j, x in enumerate(input(), start=1):
        if x == ".":
            S[i][j] = 0


for x in range(1, H + 1):
    for y in range(1, W + 1):
        if S[x][y] == 0:
            continue
        cnt = 0
        for dx, dy in zip(DX, DY):
            if S[x + dx][y + dy] == 0:
                cnt += 1
        if cnt == 4:
            print("No")
            exit()

print("Yes")

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
h, w = map(int,input().split())
s = []
for i in range(h):
    s.append(list(input()))

ans = "Yes"
for i in range(h):
    for j in range(w):
        if s[i][j] == '#' and s[max(0,i - 1)][j] == '.' and s[min(h - 1, i + 1)][j] == '.' and s[i][min(w - 1, j + 1)] == '.' and s[i][max(0, j - 1)] == '.':
            ans = "No"
print(ans)

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
M = [str(input()) for _ in range(h)]
M = ['.'*w] + M + ['.'*w]
M = ['.'+c+'.' for c in M]

#print(M)

flag = True
for i in range(1, h+1):
    for j in range(1, w+1):
        if M[i][j] == '#':
            for p, q in (-1, 0), (1, 0), (0, 1), (0, -1):
                ni = i+p
                nj = j+q
                if M[ni][nj] == '#':
                    break
            else:
                flag = False

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

Submission status: Accepted

Solution code:
import sys
def solve():
    H, W = map(int, input().split())
    S = [input() for _ in range(H)]
    search = [(-1, 0), (1, 0), (0, -1), (0, 1)]
    possible = True
    for h in range(H):
        for w in range(W):
            if S[h][w] == "#":
                for dh, dw in search:
                    if 0 <= h + dh < H and 0 <= w + dw < W:
                        if S[h+dh][w+dw] == "#":
                            break
                else:
                    possible = False
                    break
        if not possible: break
    print("Yes" if possible else "No")

    
    return 0

if __name__ == "__main__":
    solve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    H, W = (int(i) for i in input().split())
    c = [input() for i in range(H)]
    for h in range(H):
        for w in range(W):
            if c[h][w] == "#":
                for dh, dw in ((-1, 0), (1, 0), (0, -1), (0, 1)):
                    nh = h + dh
                    nw = w + dw
                    if nh < 0 or H <= nh or nw < 0 or W <= nw:
                        continue
                    if c[nh][nw] == "#":
                        break
                else:
                    return print("No")
    print("Yes")


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:

H, W = map(int, input().split())
s = [input() for _ in range(H)]
d = [(1, 0), (0, 1), (-1, 0), (0, -1)]
for i in range(H):
    for j in range(W):
        if s[i][j] == '.':
            continue
        for di, dj in d:
            ni, nj = i+di, j+dj
            if 0 <= ni < H and 0 <= nj < W and s[ni][nj] == '#':
                break
        else:
            print('No')
            exit()
print('Yes')

Submission status: Accepted

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

for i in range(h):
    for j in range(w):
        if i==0:
            if j==0:
                if l[i][j]=='.':
                    continue
                else:
                    if l[i][j+1]=='#' or l[i+1][j]=='#':
                        continue
                    else:
                        print('No')
                        exit()
            elif j==w-1:
                if l[i][j]=='.':
                    continue
                else:
                    if l[i][j-1]=='#' or l[i+1][j]=='#':
                        continue
                    else:
                        print('No')
                        exit()
            else:
                if l[i][j]=='.':
                    continue
                else:
                    if l[i][j-1]=='#' or l[i][j+1]=='#' or l[i+1][j]=='#':
                        continue
                    else:
                        print('No')
                        exit()
        elif i==h-1:
            if j==0:
                if l[i][j]=='.':
                    continue
                else:
                    if l[i][j+1]=='#' or l[i-1][j]=='#':
                        continue
                    else:
                        print('No')
                        exit()
            elif j==w-1:
                if l[i][j]=='.':
                    continue
                else:
                    if l[i][j-1]=='#' or l[i-1][j]=='#':
                        continue
                    else:
                        print('No')
                        exit()
            else:
                if l[i][j]=='.':
                    continue
                else:
                    if l[i][j-1]=='#' or l[i][j+1]=='#' or l[i-1][j]=='#':
                        continue
                    else:
                        print('No')
                        exit()
        else:
            if j==0:
                if l[i][j]=='.':
                    continue
                else:
                    if l[i][j+1]=='#' or l[i-1][j]=='#' or l[i+1][j]=='#':
                        continue
                    else:
                        print('No')
                        exit()
            elif j==w-1:
                if l[i][j]=='.':
                    continue
                else:
                    if l[i][j-1]=='#' or l[i-1][j]=='#' or l[i+1][j]=='#':
                        continue
                    else:
                        print('No')
                        exit()
            else:
                if l[i][j]=='.':
                    continue
                else:
                    if l[i][j-1]=='#' or l[i][j+1]=='#' or l[i-1][j]=='#' or l[i+1][j]=='#':
                        continue
                    else:
                        print('No')
                        exit()

print('Yes')

Submission status: Accepted

Solution code:
#abc096 c
h,w=map(int,input().split())
maze=[]
move=[[1,0],[0,1],[-1,0],[0,-1]]
for i in range(h):
    line=input()
    maze.append(line)

def no_conf(y,x):
    flag=False
    for i in move:
        my,mx=[a+b for a,b in zip(i,[y,x])]
        if 0<=my<h and 0<=mx<w:
            if maze[my][mx]=="#":
                flag=True
    return flag
ans=True
for i in range(h):
    for j in range(w):
        if maze[i][j]=="#":
            if no_conf(i,j)==False:
                ans=False
                break
if ans:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

#    下  右  上  左
dy = [1, 0, -1, 0]
dx = [0, 1, 0, -1]

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

grid = []
for i in range(H):
    grid.append(input())

# print(grid)

ans = True

for i in range(H):
    for j in range(W):
        if grid[i][j] == '#':
            cnt = 0
            # print(i, j, sep='-', end='=')
            for k in range(4):
                y = i + dy[k]
                x = j + dx[k]
                if x >= 0 and y >= 0 and x < W and y < H:
                    # print(y, x, grid[y][x], sep='-', end=' ')
                    if grid[y][x] == '#':
                        cnt += 1
            # print(cnt)
            if cnt == 0:
                ans = False
                break
    else:
        continue
    break

if ans is True:
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

H, W = map(int, input().split(' '))
S = [list(input().rstrip('\r\n')) for _ in range(H)]

def judge(h, w):
    ok = False
    if h-1 >= 0 and S[h-1][w] == '#':
        ok = True
    if w-1 >= 0 and S[h][w-1] == '#':
        ok = True
    if w+1 < W and S[h][w+1] == '#':
        ok = True
    if h+1 < H and S[h+1][w] == '#':
        ok = True
    return ok
ans = 'Yes'
for h in range(H):
    for w in range(W):
        if S[h][w] == '#':
            if judge(h, w) == False:
                ans = 'No'
print(ans)

Submission status: Accepted

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

dxy = [(-1,0), (0,-1),(1,0),(0,1)]
for y in range(h):
    for x in range(w):
        if src[y][x] == '.': continue
        for dx, dy in dxy:
            nx, ny = x+dx, y+dy
            if not 0 <= nx < w: continue
            if not 0 <= ny < h: continue
            if src[ny][nx] == '#':
                break
        else:
            print('No')
            exit()
print('Yes')

Submission status: Accepted

Solution code:
H,W = map(int,input().split())
grid = [None for _ in range(H)]
for i in range(H):
  s = input()
  grid[i] = s
dire = [[0,-1],[-1,0],[1,0],[0,1]]
for r in range(H):
  for c in range(W):
    if grid[r][c] == "#":
      ok = False
      for d in dire:
        if 0 <= r+d[0] and r+d[0] < H and 0 <= c+d[1] and c+d[1] < W and grid[r+d[0]][c+d[1]] == "#":
          ok = True
          break
      if not ok:
        print("No")
        exit()
print("Yes")

Submission status: Accepted

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

s = [list(input()) for _ 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 s[i][j] == ".":
            continue
        flag = 0
        for k in range(4):    
            if not(0<=j+DX[k]<=w-1 and 0<=i+DY[k]<=h-1):
                continue
            if s[i + DY[k]][j + DX[k]] == "#":
                flag = 1
                break
        if flag == 0:
          ans = False
          break
print("Yes" if ans else "No")

Submission status: Accepted

Solution code:
def main():
    h, w = map(int,input().split())
    s = []
    for i in range(h):
        ss = list(input())
        s.append(ss)
    for i in range(h):
        for j in range(w):
            if check(s, i, j):
                if i != 0:
                    if check(s, i-1, j):
                        continue
                if i != h-1:
                    if check(s, i+1, j):
                        continue
                if j != 0:
                    if check(s, i, j-1):
                        continue
                if j != w-1:
                    if check(s, i, j+1):
                        continue
                print('No')
                return
    print('Yes')


def check(mtrx, n, m):
    if mtrx[n][m] == '#':
        return True
    else:
        return False
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
H,W = map(int,input().split())
HW = []
for i in range(H+2):
    if i == 0 or i == H+1:
        HW.append(["."]*(W+1))
    else:
        HW.append(["."]+list(input())+["."])

for i in range(1,H):
    for j in range(1,W):
        if HW[i][j] == "#":
            if HW[i-1][j] == "#" or HW[i][j-1] == "#" or HW[i+1][j] == "#" or HW[i][j+1] == "#":
                continue
            else:
                print("No")
                exit()
print("Yes")

Submission status: Accepted

Solution code:
h,w = [int(x) for x in input().split()]
l = []
for _ in range(h):
    l.append(list(input()))
possible = True
tmplst = []

for i in range(h):
    for y in range(1,w-1):
        if l[i][y-1] == l[i][y+1] == '.' and l[i][y] == '#':
            tmplst.append([i,y])

for x in tmplst:
    if x[0] == 0:
        if l[0][x[1]] == '.':
            possible = False
    elif x[0] == h-1:
        if l[h-1][x[1]] == '.':
            possible = False
    else:
        if l[x[0]-1][x[1]] == l[x[0]+1][x[1]] == '.':
            possible = False

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

Submission status: Accepted

Solution code:
H,W=map(int, input().split())
s = []
dx = [  0, 0, 1, -1]
dy = [ -1, 1, 0, 0]
ans = "Yes"
for i in range(H):
  s.append( input())
for y in range(H):
  for x in range(W):
    if s[y][x] == '#':
      ng = 1
      for i in range(4):
        nx = x + dx[i]
        ny = y + dy[i]
        if (ny < 0) or (ny >= H) or (nx<0) or (nx>=W):
          continue
        if s[ny][nx] == '#':
          ng = 0
      if ng == 1:
        ans = "No"
print(ans)

Submission status: Accepted

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

s = [0]*(H+2)

s[0] = ["."]*(W+2)

for i in range(1,H+1):
    s[i] = ["."]+list(str(input()))+["."]

s[H+1] = ["."]*(W+2)

#print(s)

det = 0
for i in range(1,H+1):
    for j in range(1,W+1):
        #print(i,j,s[i][j],s[i][j-1],s[i][j+1],s[i-1][j],s[i+1][j])
        if s[i][j] == "#" and s[i][j-1] == "." and s[i][j+1] == "." and s[i-1][j] == "." and s[i+1][j] == ".":
            det = -1

if det == -1:
    print("No")
else:
    print("Yes")

Submission status: Accepted

Solution code:
H,W=map(int,input().split())
field=[["#"]*(W+2)]
for i in range(H):
    field.append(["#"])
    field[-1].extend(list(input()))
    field[-1].append("#")
field.append(["#"]*(W+2))
for i in range(1,H+1):
    for j in range(1,W+1):
        cnt=0
        for dy,dx in ([1, 0], [-1, 0], [0, 1], [0, -1]):
            if field[i][j]=="#" and field[i][j]!=field[i+dy][j+dx]:
                cnt+=1
        if cnt==4:
            print("No")
            exit()
print("Yes")

Submission status: Accepted

Solution code:
h,w = (int(x) for x in input().split())
ab = []
count = 0
for _ in range(h):
    a = input()
    a = a+'.'
    ab.append(list(a))
ab.append(list('.'*w))

for i in range(h):
    for j in range(w):
        if ab[i][j] == '#':
            if ab[i+1][j] == '#' :
                continue
            elif ab[i][j+1] == '#' :
                continue
            elif ab[i-1][j] == '#' :
                continue
            elif ab[i][j-1] == '#' :
                continue
            else:
                print('No')
                exit()
print('Yes')

Submission status: Accepted

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

s=[]
t=[]
for hh in range(h):
    s.append(list(input()))
    t.append([1]*w)

for hh in range(h):
    for ww in range(w):
        if s[hh][ww]==".":
            t[hh][ww]=0
        else:
            if hh==0:
                if s[hh+1][ww]=="#":
                    t[hh][ww]=0
            elif hh==h-1:
                if s[hh-1][ww]=="#":
                    t[hh][ww]=0
            else:
                if s[hh+1][ww]=="#":
                    t[hh][ww]=0
                if s[hh-1][ww]=="#":
                    t[hh][ww]=0
            if ww==0:
                if s[hh][ww+1]=="#":
                    t[hh][ww]=0
            elif ww==w-1:
                if s[hh][ww-1]=="#":
                    t[hh][ww]=0
            else:
                if s[hh][ww+1]=="#":
                    t[hh][ww]=0
                if s[hh][ww-1]=="#":
                    t[hh][ww]=0
tmax=0
for hh in range(h):
    if max(t[hh])>0:
        tmax=1

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

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
cv = [input() for _ in range(h)]
for y in range(h):
    for x in range(w):
        if cv[y][x] == '#':
            if (y > 0 and cv[y - 1][x] == '#') or (y < h - 1 and cv[y + 1][x] == '#') \
                    or (x > 0 and cv[y][x - 1] == '#') or (x < w - 1 and cv[y][x + 1] == '#'):
                continue
            print('No')
            exit()
print('Yes')

Submission status: Accepted

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

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 = 'Yes'

for i in range(h):
  for j in range(w):
    if board[i][j] == '#' and ans == 'Yes':
      T_F = False
      for d in range(4):
        ni = i + dx[d]
        nj = j + dy[d]
        if 0 <= ni < h and 0 <= nj < w and board[ni][nj] == '#':
          T_F = True
      if not T_F :
        ans = 'No'
        break
print(ans)

Submission status: Accepted

Solution code:
# 下，右，上，左
dy = [1, 0, -1, 0]
dx = [0, 1, 0, -1]

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

field = []

for i in range(H):
    field.append(list(input()))

for y in range(H):
    for x in range(W):
        
        if field[y][x] == "#":

            cnt = 0

            for k in range(4):

                ny = y + dy[k]
                nx = x + dx[k]

                if ny < 0 or H <= ny or nx < 0 or W <= nx:
                    continue

                if field[ny][nx] == "#":
                    cnt += 1

            if cnt == 0:
                print("No")
                exit()

print("Yes")

Submission status: Accepted

Solution code:
h,w = map(int,input().split())
canbas = []
for _ in range(h):
    canbas.append(input())
x = 0
for i in range(h):
    for j in range(w):
        if canbas[i][j] == '.':
            continue
        else:
            if i ==0:
                a = '.'
            else:
                a = canbas[i-1][j]
            if j ==0:
                b = '.'
            else:
                b = canbas[i][j-1]
            if i == h-1:
                c = '.'
            else:
                c = canbas[i+1][j]
            if j == w-1:
                d = '.'
            else:
                d = canbas[i][j+1]
            if a==b==c==d=='.':
                x = 1
                break
    if x == 1:
        break

if x == 1:
    print('No')
else:
    print('Yes')

Submission status: Accepted

Solution code:
#096_C
h,w=map(int,input().split())
s=['.'+input()+'.' for _ in range(h)]
s=['.'*(w+2)]+s+['.'*(w+2)]
flg=True
for i in range(1,h+1):
    for  j in range(1,w+1):
        if s[i][j]=='#':
            if all(s[i+_i][j+_j]=='.' for _i,_j in [(1,0),(0,1),(-1,0),(0,-1)]):
                flg=False
                break

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

Submission status: Accepted

Solution code:
# coding: utf-8

def get_ans():
    (h, w) = [int(i) for i in input().rstrip().split(" ")]
    map = [input().rstrip() for i in range(h)]

    for i in range(h):
        for j in range(w):
            if map[i][j] != "#":
                continue

            nearBlack = False
            for k in range(i - 1, i + 2):
                if k < 0 or k >= h:
                    continue
                for l in range(j - 1, j + 2):
                    if (l < 0) or (l >= w):
                        continue
                    if k == i and l == j:
                        continue
                    if k != i and l != j:
                        continue
                    if map[k][l] == "#":
                        nearBlack = True
                        break
                if nearBlack:
                    break

            if not nearBlack:
                return False
    return True


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

Submission status: Accepted

Solution code:
h,w = map(int,input().split())
s = [input() for i in range(h)]
def judge(i,j,s):
    #print('judge')
    for k in range(-1,2):
        for l in range(-1,2):
            if abs(k-l) == 1:
                temp_i = i+k
                temp_j = j+l
                if temp_i < 0 or temp_i-1 > h or temp_j < 0 or temp_j > w-1:
                    #print('pass{} {}'.format(k,l))
                    pass
                else:
                    #print('notpass{} {}'.format(k,l))
                    #print(s[i][j])
                    if s[temp_i][temp_j] == '#':
                        return True
    return False

flag = True
for i in range(h):
    for j in range(w):
        #print('{} {}'.format(i,j))
        if s[i][j] == '#':
            flag = judge(i,j,s)
            if flag == False:
                print('No')
                exit()
print('Yes')

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
A = []
A.append("."*(w+2))
for i in range(h):
  A.append(list("." + input() + "."))
A.append("."*(w+2))
f = True
for i in range(1, h+1):
  for j in range(1, w+1):
    if A[i][j] == "#" and A[i+1][j] == "." and A[i-1][j] == "." and A[i][j+1] == "." and A[i][j-1] == ".":
      f = False
if f:print("Yes")
else: print("No")

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
s = [input() for _ in range(h)]
idx = [[-1, 0], [0, -1], [0, 1], [1, 0]]
a = "Yes"
for i in range(h):
    for j in range(w):
        if s[i][j] != "#": continue
        else:
            t = False
            for h_, w_ in idx:
                i_, j_ = i + h_, j + w_
                if (i_ == -1 or i_ == h) or (j_ == -1 or j_ == w): continue
                elif s[i_][j_] == "#":
                    t = True
                    break
            if t == False: a = "No"
    if a == "No": break
print(a)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
mat = [input() for _ in range(n)]


for i in range(n):
    for j in range(m):
        target = mat[i][j]
        if target == "#":
            if not i == 0:
                if mat[i-1][j] == "#":
                    continue
            if not i == n-1:
                if mat[i+1][j] == "#":
                    continue
            if not j == 0:
                if mat[i][j-1] == "#":
                    continue
            if not j == m-1:
                if mat[i][j+1] == "#":
                    continue
            print("No")
            exit()
                
print("Yes")