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:
def main():
    height, width = map(int, input().split(" "))
    grids = ["." * (width + 2)]
    for _ in range(height):
        grids.append("." + input() + ".")
    grids.append("." * (width + 2))
    is_possible = True
    for i in range(1, height + 1):
        for j in range(1, width + 1):
            if grids[i][j] == "#":
                if not (grids[i + 1][j] == "#" or grids[i - 1][j] == "#" or grids[i][j + 1] == "#" or grids[i][j - 1] == "#"):
                    is_possible = False
    if is_possible:
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#coding: utf-8
import math
import heapq
import bisect
import numpy as np
from collections import Counter
#from scipy.misc import comb

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

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

flg = 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] == ".":
                flg = 0

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

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
list=["."+input()+"." for i in range(H)]
list=["."*(W+2)]+list+["."*(W+2)]
a=0
for h in range(H):
    for w in range(W):
        if list[h][w] == "#":
            if list[h+1][w] == "." and list[h-1][w] == "." and list[h][w-1] == "." and list[h][w+1] == ".":
                a=1
                break
print("Yes" if a==0 else "No")

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
list=["."+input()+"." for i in range(H)]
list=["."*(W+2)]+list+["."*(W+2)]
a=0
for h in range(H):
    for w in range(W):
        if list[h][w] == "#":
            if list[h+1][w] == "." and list[h-1][w] == "." and list[h][w-1] == "." and list[h][w+1] == ".":
                a=1
print("Yes" if a==0 else "No")

Submission status: Accepted

Solution code:
H, W = [int(x) for x in input().split()]
s_lst = [input() for i in range(H)]
can = True
for i in range(H):
    for j in range(W):
        if s_lst[i][j] == '#':
            f1 = 0
            f2 = 0
            f3 = 0
            f4 = 0
            if 0 < i and s_lst[i - 1][j] == '.':
                f1 = 1
            if i < H - 1 and s_lst[i + 1][j] == '.':
                f2 = 1
            if 0 < j and s_lst[i][j - 1] == '.':
                f3 = 1
            if j < W - 1 and s_lst[i][j + 1] == '.':
                f4 = 1
            if f1*f2*f3*f4 == 1:
                can = False
print('Yes') if can else print('No')

Submission status: Accepted

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

"""考え方
普通に全探索して問題あるか無いかを確認して行く。
1行目、H行目、1列目、W列目だけは少し注意！！！
→0行目、H+1行目、0列目、W+1列目を追加する
"""

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

ans = 'Yes'
for h in range(H):
  for w in range(W):
    ## 黒にする箇所があった時に、上下左右のいずれかに黒色の箇所があればOK！！！
    if list_[h][w] == '#':
      if list_[h-1][w] == '.':
        if list_[h+1][w] == '.':
          if list_[h][w-1] == '.':
            if list_[h][w+1] == '.':
              ans = 'No'
              break

print(ans)

Submission status: Accepted

Solution code:
import sys
h,w = map(int,input().split())
s = [list(input()) for i in range(h)]
dx = [0,-1,1,0]
dy = [-1,0,0,1]

for i in range(h):
    for j in range(w):
        cnt = 0
        if  s[i][j] == "#":
            for k in range(4):
                nx = j + dx[k]
                ny = i + dy[k]
                if nx>=0 and ny>=0 and ny<h and nx<w:
                    if s[ny][nx] == "#":
                        cnt += 1
            if cnt == 0:
                print("No")
                sys.exit()
print("Yes")

Submission status: Accepted

Solution code:
h,w = map(int,input().split())
a = ["." for i in range(w+2)]
dot_map = [a]
for _ in range(h):
    l = list(input())
    l.insert(0, ".")
    l.append(".")
    dot_map.append(l)
dot_map.append(a)
breaker = 0

for i in range(1, h+1):
    if breaker == 1:
        break
    else:
        for j in range(1,w+1):
            if dot_map[i][j] == "#":
                flag = 0
                if dot_map[i-1][j] == "#":
                    flag += 1
                elif dot_map[i][j-1] == "#":
                    flag += 1
                elif dot_map[i][j+1] == "#":
                    flag += 1
                elif dot_map[i+1][j] == "#":
                    flag += 1
                if flag == 0:
                    breaker += 1
                    break

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

Submission status: Accepted

Solution code:
import sys
h,w = map(int,input().split())
matrix = [[0]*(w+2) for _ in range(h+2)]
for hi in range(h):
    all_inp = input()
    for i,a in enumerate(all_inp):
        matrix[hi+1][i+1]= 1 if a == '#' else 0
#print(matrix)
for ri,row in enumerate(matrix):
    for ci,column in enumerate(row):
        if column == 1:
            if row[ci-1] == 0 and row[ci+1] == 0 and matrix[ri-1][ci] == 0 and matrix[ri+1][ci] == 0:
                print('No')
                sys.exit()
print('Yes')

Submission status: Accepted

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

plan = []
for i in range(h):
  plan.append(input())

canvas = [[False] * w for _ in range(h)]

for i in range(h):
  for j in range(w - 1):
    if plan[i][j] == plan[i][j + 1] == '#':
      canvas[i][j] = canvas[i][j + 1] = True

for j in range(w):
  for i in range(h - 1):
    if plan[i][j] == plan[i + 1][j] == '#':
      canvas[i][j] = canvas[i + 1][j] = True

if all([all([plan[i][j] == '.' or canvas[i][j] for j in range(w)]) for i in range(h)]):
  print('Yes')
else:
  print('No')

Submission status: Accepted

Solution code:
h, w = list(map(int, input().split()))
graph = []
def check(s,t):
    if (0 <=  s <= w - 1) and (0 <= t <= h - 1):
        return True
    else:
        return False
def check_around(x,y):
    if check(x+1,y) and graph[y][x+1] == '#':
        return True
    if check(x,y+1) and graph[y+1][x] == '#':
        return True
    if check(x-1,y) and graph[y][x-1] == '#':
        return True
    if check(x,y-1) and graph[y-1][x] == '#':
        return True
    return False
for i in range(h):
    graph.append(list(input()))
for i in range(h):
    for j in range(w):
        if graph[i][j] == '#':
            if  not check_around(j,i):
                print("No")
                exit()
print("Yes")

Submission status: Accepted

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

#%%

def get_field(i, j):
    try:
        ret = field[i][j]
    except:
        ret = '.'
    return ret

ans = True
for i in range(H):
    for j in range(W):
        if field[i][j] == '#':
            up = get_field(i-1, j)
            down = get_field(i+1, j)
            left = get_field(i, j-1)
            right = get_field(i, j+1)
            if up == '#' or down == '#' or left == '#' or right == '#':
                ans = True
            else:
                ans = False
                break
    if ans == False:
        break

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

Submission status: Accepted

Solution code:
h, w = list(map(int, input().split()))
s = [["." for i in range(w+2)]]
for i in range(h):
    si = ["."]
    sie = list(input())
    for e in sie:
        si.append(e)
    si.append(".")
    s.append(si)
s.append(["." for i in range(w+2)])
ans = "Yes"
for i in range(1, h + 1):
    for j in range(1, w + 1):
        if s[i][j] == "#":
            if not ((s[i - 1][j] == "#") or (s[i + 1][j] == "#") or (s[i][j - 1] == "#") or (s[i][j + 1] == "#")):
                ans = "No"
print(ans)

Submission status: Accepted

Solution code:
h,w = map(int,input().split())
c = []
for _ in range(h):
    c.append(input())
for i in range(h):
    for j in range(w):
        if c[i][j] == '.':
            continue
        if i == 0:
            if j == 0:
                if c[i][j+1] == '.' and c[i+1][j] == '.':
                    print('No')
                    exit(0)
            elif j == w-1:
                if c[i][j-1] == '.' and c[i+1][j] == '.':
                    print('No')
                    exit(0)
            else:
                if c[i][j-1] == '.' and c[i+1][j] == '.' and c[i][j+1] == '.':
                    print('No')
                    exit(0)
        elif i == h-1:
            if j == 0:
                if c[i][j+1] == '.' and c[i-1][j] == '.':
                    print('No')
                    exit(0)
            elif j == w-1:
                if c[i][j-1] == '.' and c[i-1][j] == '.':
                    print('No')
                    exit(0)
            else:
                if c[i][j-1] == '.' and c[i-1][j] == '.' and c[i][j+1] == '.':
                    print('No')
                    exit(0)
        else:
            if j == 0:
                if c[i][j+1] == '.' and c[i-1][j] == '.' and c[i+1][j] == '.':
                    print('No')
                    exit(0)
            elif j == w-1:
                if c[i][j-1] == '.' and c[i-1][j] == '.' and c[i+1][j] == '.':
                    print('No')
                    exit(0)
            else:
                if c[i][j-1] == '.' and c[i-1][j] == '.' and c[i][j+1] == '.' and c[i+1][j] == '.':
                    print('No')
                    exit(0)
print('Yes')

Submission status: Accepted

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

s.append(['.']*(w+2))
for i in range(1,h+1):
    s[i].insert(0,'.')
    s[i].append('.')


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

print("Yes")

Submission status: Accepted

Solution code:
import sys
H, W = map(int, input().split())
X = ['.'*(W+2)]
for _ in range(H):
    X.append('.'+input().strip()+'.')
X += ['.'*(W+2)]
for i in range(1, H+1):
    for j in range(1, W+1):
        if X[i][j] == "#" and '#' not in [X[i+1][j], X[i-1][j], X[i][j-1], X[i][j+1]]:
            print("No")
            sys.exit()
print("Yes")

Submission status: Accepted

Solution code:
H, W = map(int,input().split())
S = [input() for i in range(H)]
ok = True
def check(i,j,H,W,S):
    flag = False
    if i+1 <= H-1:
        if S[i+1][j] == "#":
            flag = True
    if i-1 >= 0:
        if S[i-1][j] == "#":
            flag = True
    if j+1 <= W-1:
        if S[i][j+1] == "#":
            flag = True
    if j-1 >= 0:
        if S[i][j-1] == "#":
            flag = True
    return flag
for i in range(H):
    for j in range(W):
        if S[i][j] == "#":
            ch = check(i,j,H,W,S)
            if not ch:
                ok = False
                break
    if not ok:
        break
if ok:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

for i in range(1, h-1):
    for j in range(1, w-1):
        if s[i][j] == '#':
            if not (s[i+1][j] == '#' or s[i-1][j] == '#' or s[i][j+1] == '#' or s[i][j-1] == '#'):
                print('No')
                exit()
print('Yes')

Submission status: Accepted

Solution code:
def two_int():
    N, K = map(int, input().split())
    return N,K

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))

H,W = two_int()

maps = [list(input()) for i in range(H)]

import copy 
temp_maps = copy.deepcopy(maps)

#start調査
def solve(W,H,maps):
    start_X=0
    start_Y=0
    for x in range(W):
        for y in range(H):
            count=0

            if maps[y][x]=="#":
                count += 1

                if x+1 < W:
                    if maps[y][x+1]=="#":
                        count += 1     

                if y+1 < H:
                    if maps[y+1][x]=="#":
                        count += 1     

                if x-1 >= 0:
                    if maps[y][x-1]=="#":
                        count += 1     


                if y-1 >= 0:
                    if maps[y-1][x]=="#":
                        count += 1     

                if count==1:
                    return "No"
    return "Yes"

ans = solve(W,H,maps)
print(ans)

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
table = [list(input()) for i in range(h)]
mask = [[1,0], [0,1], [-1, 0], [0, -1]]
flag = True

for i in range(h):
  for j in range(w):
    if table[i][j] == '#':
      count = 0
      for k in range(len(mask)):
        if (i + mask[k][0]) >= 0 and (i + mask[k][0]) < h and (j + mask[k][1]) >= 0 and (j + mask[k][1]) < w:
          if table[i+mask[k][0]][j+mask[k][1]] == '#':
            count+=1
     
      if count == 0:
        flag = False
  if 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)]

ok = True
def check(i,j,H,W,s):
    flag = False
    if (i+1) <= (H-1):
        if s[i+1][j] == "#":
            flag = True
    if (i-1) >= 0:
        if s[i-1][j] == "#":
            flag = True
    if (j+1) <= (W-1):
        if s[i][j+1] == "#":
            flag = True
    if (j-1) >= 0:
        if s[i][j-1] == "#":
            flag = True
    return flag

for i in range(H):
    for j in range(W):
        if s[i][j] == "#":
            ch = check(i,j,H,W,s)
            if not ch:
                ok = False
                break
    if not ok:
        break



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

Submission status: Accepted

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

dx = [-1, 0, 0, 1]
dy = [0, 1, -1, 0]
for i in range(H):
    for j in range(W):
        if s[i][j] == '#':
            flag = False
            for k in range(4):
                if s[i][j] == '#':
                    nx = j + dx[k]
                    ny = i + dy[k]
                    if nx < 0 or nx >= W or ny < 0 or ny >= H:
                        continue
                if s[ny][nx] == '#':
                    flag = True
            if flag == False:
                print('No')
                exit()        

print('Yes')

Submission status: Accepted

Solution code:
def solve(h, w, S):
    A = [[s == '#' for s in l] for l in S]
    for y in range(h):
        for x in range(w):
            if A[y][x] and \
                (y == 0 or not A[y - 1][x]) and (y == h - 1 or not A[y + 1][x]) and \
                (x == 0 or not A[y][x - 1]) and (x == w - 1 or not A[y][x + 1]):
                return 'No'
    return 'Yes'

_h, _w = map(int, input().split())
_S = [input() for _ in range(_h)]
print(solve(_h, _w, _S))

Submission status: Accepted

Solution code:
N, M = map(int,input().split()) 
p = [input() for i in range(N)]

ans = "Yes"
for n in range(1,N-1):
    for m in range(1,M-1):
        if p[n][m] == '#':
            if p[n-1][m] != "#" and p[n][m-1] != "#" and p[n+1][m] != "#" and p[n][m+1]!= "#":
                ans = "No"
                break
print(ans)

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
l = [list(input()) for i in range(n)]
for i in range(n):
    for j in range(m):
        if l[i][j] == "#":
            count = 0
            if 0 < i and l[i-1][j] == "#":
                count += 1
            if 0 < j and l[i][j-1] == "#":
                count += 1
            if i != n-1 and l[i+1][j] == "#":
                count += 1
            if j != m-1 and l[i][j+1] == "#":
                count += 1
            if count == 0:
                print("No")
                exit()
print("Yes")

Submission status: Accepted

Solution code:
from itertools import product

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

ans = "Yes"
for y, x in product(range(H), range(W)):
    if grid[y][x] != "#":
        continue
    for dy, dx in ((0, -1), (0, 1), (-1, 0), (1, 0)):
        ny, nx = y + dy, x + dx
        if not (0 <= ny < H and 0 <= nx < W):
            continue
        if grid[ny][nx] == "#":
            break
    else:
        ans = "No"
print(ans)

Submission status: Accepted

Solution code:
N,M = map(int, input().split())
boards = [None] * N
passed = [[False] * M for i in range(N)]
for i in range(N):
    boards[i] = list(input())
for i in range(N):
    for j in range(M):
        if boards[i][j] == '#':
            if ((i < N - 1 and boards[i+1][j] == '#') or 
                (i >= 1 and boards [i-1][j] == '#') or 
                (j < M - 1 and boards[i][j+1] == '#') or
                (j >= 1 and boards[i][j-1] == '#')):
                    continue
            else:
                print('No')
                exit()
print('Yes')

Submission status: Accepted

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

dh = (-1, 0, 0, 1)
dw = (0, -1, 1, 0)
for i in range(h):
    for j in range(w):
        if s[i][j] == '#':
            for y, x in zip(dh, dw):
                if 0 <= i+y < h and 0 <= j+x < w:
                    if s[i+y][j+x] == '#':
                        break
            else:
                break
    else:
        continue
    print('No')
    break
else:
    print('Yes')

Submission status: Accepted

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

can_draw = True

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

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

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
s = [input() for x 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-1][j] != '#' and s[i][j+1] != '#' and s[i+1][j] != '#'):
            print("No")
            exit()

print("Yes")

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools

class cin():
    def int():
        return int(sys.stdin.readline().rstrip())
    def string():
        return sys.stdin.readline().rstrip()
    def mapInt():
        return [int(x) for x in cin.string().split()]
    def stringList(n):
        return [input() for i in range(n)]

class Util():
    def round_up(a,b):
        return -(-a // b)
    def toUpperMultiple(a,x):
        return Util.round_up(a,x) * x
    def toLowerMultiple(a,x):
        return (a // x) * x

H,W = cin.mapInt()
S = cin.stringList(H)
for h in range(H):
    for w in range(W):
        if S[h][w] == ".":
            continue
        if h - 1 >= 0 and S[h - 1][w] == "#":
            continue
        if w - 1 >= 0 and S[h][w - 1] == "#":
            continue
        if h + 1 < H and S[h + 1][w] == "#":
            continue
        if w + 1 < W and S[h][w + 1] == "#":
            continue
        print("No")
        sys.exit()
print("Yes")

Submission status: Accepted

Solution code:
H,W=map(int,input().split())
graph=[list(input()) for _ in range(H)]
onesteps=((-1,0),(0,-1),(1,0),(0,1))
for x in range(H):
    for y in range(W):
        if graph[x][y]=="#":
            flag=0
            for dx,dy in onesteps:
                if (0<=x+dx<H) and (0<=y+dy<W):
                    if graph[x+dx][y+dy]=="#":
                        flag+=1
            if flag==0:
                print('No')
                exit(0)
print('Yes')

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(H):
    for j in range(W):
        if(L[i][j]=="#"):
            f=1
            if(i>0):
                if(L[i-1][j]=="#" or L[i-1][j]=="$"):
                    L[i][j]="$"
                    L[i-1][j]="$"
                    f=0
            if(j>0):
                if(L[i][j-1]=="#" or L[i][j-1]=="$"):
                    L[i][j]="$"
                    L[i][j-1]="$"
                    f=0
            if(i<H-1):
                if(L[i+1][j]=="#" or L[i+1][j]=="$"):
                    L[i][j]="$"
                    L[i+1][j]="$"
                    f=0
            if(j<W-1):
                if(L[i][j+1]=="#" or L[i][j+1]=="$"):
                    L[i][j]="$"
                    L[i][j+1]="$"
                    f=0
            if(f==1):
                print("No")
                exit()
print("Yes")

Submission status: Accepted

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

# はみだす判定が面倒なので適当な文字で囲む
fill_l = []
for i in range(-1,h+1):
    if i == -1 or i == h:
        fill_l.append(['?' for _ in range(w+2)])
    else:
        ext = ['?']
        ext.extend(l[i])
        ext.append('?')
        fill_l.append(ext)
        
flg = True
for i in range(1,h):
    for j in range(1,w):
        if fill_l[i][j] == '#' and not (fill_l[i+1][j] == '#' or fill_l[i-1][j] == '#' or fill_l[i][j-1] == '#' or fill_l[i][j+1] == '#'):
            flg = False
            break
        
print('Yes' if flg else 'No')

Submission status: Accepted

Solution code:
def main():
    # 下、右、上、左
    dyx = [(1, 0), (0, 1), (-1, 0), (0, -1)]
    H, W = map(int, input().split())
    s = ["." * (W + 2)]
    s += ["." + input() + "." for i in range(H)]
    s.append("." * (W + 2))
    for y in range(1, H + 1):
        for x in range(1, W + 1):
            if "." == s[y][x]:
                continue
            for dy, dx in dyx:
                if "#" == s[y + dy][x + dx]:
                    break
            else:
                print("No")
                return
    print("Yes")
    return


main()

Submission status: Accepted

Solution code:
def main():
    # 下、右、上、左
    dyx = [(1, 0), (0, 1), (-1, 0), (0, -1)]
    H, W = map(int, input().split())
    s = ["." * (W + 2)]
    s.extend(["." + input() + "." for i in range(H)])
    s.append("." * (W + 2))
    for y in range(1, H + 1):
        for x in range(1, W + 1):
            if "." == s[y][x]:
                continue
            for dy, dx in dyx:
                if "#" == s[y + dy][x + dx]:
                    break
            else:
                print("No")
                return
    print("Yes")
    return


main()

Submission status: Accepted

Solution code:
def main():
    # 下、右、上、左
    dyx = [(1, 0), (0, 1), (-1, 0), (0, -1)]
    H, W = map(int, input().split())
    s = ["." * (W + 2)]
    s += ["." + input() + "." for i in range(H)]
    s += ["." * (W + 2)]
    for y in range(1, H + 1):
        for x in range(1, W + 1):
            if "." == s[y][x]:
                continue
            for dy, dx in dyx:
                if "#" == s[y + dy][x + dx]:
                    break
            else:
                print("No")
                return
    print("Yes")
    return


main()

Submission status: Accepted

Solution code:
def main():
    # 下、右、上、左
    dy = (1, 0, -1, 0)
    dx = (0, 1, 0, -1)
    H, W = map(int, input().split())
    s = ["." * (W + 2)]
    s += ["." + input() + "." for i in range(H)]
    s += ["." * (W + 2)]
    for y in range(1, H + 1):
        for x in range(1, W + 1):
            if "." == s[y][x]:
                continue
            if "#" == s[y + dy[0]][x + dx[0]]:
                continue
            if "#" == s[y + dy[1]][x + dx[1]]:
                continue
            if "#" == s[y + dy[2]][x + dx[2]]:
                continue
            if "#" == s[y + dy[3]][x + dx[3]]:
                continue
            print("No")
            return
    print("Yes")
    return


main()

Submission status: Accepted

Solution code:
def main():
    # 下、右、上、左
    dy = (1, 0, -1, 0)
    dx = (0, 1, 0, -1)
    H, W = map(int, input().split())
    s = ["." * (W + 2)]
    s += ["." + input() + "." for i in range(H)]
    s.append("." * (W + 2))
    for y in range(1, H + 1):
        for x in range(1, W + 1):
            if "." == s[y][x]:
                continue
            if "#" == s[y + dy[0]][x + dx[0]]:
                continue
            if "#" == s[y + dy[1]][x + dx[1]]:
                continue
            if "#" == s[y + dy[2]][x + dx[2]]:
                continue
            if "#" == s[y + dy[3]][x + dx[3]]:
                continue
            print("No")
            return
    print("Yes")
    return


main()

Submission status: Accepted

Solution code:
def main():
    # 下、右、上、左
    dy = [1, 0, -1, 0]
    dx = [0, 1, 0, -1]
    H, W = map(int, input().split())
    s = ["." * (W + 2)]
    s += ["." + input() + "." for i in range(H)]
    s.append("." * (W + 2))
    for y in range(1, H + 1):
        for x in range(1, W + 1):
            if "." == s[y][x]:
                continue
            if "#" == s[y + dy[0]][x + dx[0]]:
                continue
            if "#" == s[y + dy[1]][x + dx[1]]:
                continue
            if "#" == s[y + dy[2]][x + dx[2]]:
                continue
            if "#" == s[y + dy[3]][x + dx[3]]:
                continue
            print("No")
            return
    print("Yes")
    return


main()

Submission status: Accepted

Solution code:
def main():
    H, W = map(int, input().split())
    s = ["." * (W + 2)]
    s += ["." + input() + "." for i in range(H)]
    s.append("." * (W + 2))
    for y in range(1, H + 1):
        for x in range(1, W + 1):
            if "." == s[y][x]:
                continue
            if "#" == s[y + 1][x]:
                continue
            if "#" == s[y][x + 1]:
                continue
            if "#" == s[y - 1][x]:
                continue
            if "#" == s[y][x - 1]:
                continue

            print("No")
            return
    print("Yes")
    return


main()

Submission status: Accepted

Solution code:
def main():
    H, W = map(int, input().split())
    s = ["." * (W + 2)]
    s += ["." + input() + "." for i in range(H)]
    s.append("." * (W + 2))
    for y in range(1, H + 1):
        for x in range(1, W + 1):
            if s[y][x] == ".":
                continue
            if "...." == s[y + 1][x]\
                    + s[y][x + 1]\
                    + s[y - 1][x]\
                    + s[y][x - 1]:
                print("No")
                return
    print("Yes")
    return


main()

Submission status: Accepted

Solution code:
def main():
    H, W = map(int, input().split())
    s = ["." * (W + 2)]
    s += ["." + input() + "." for i in range(H)]
    s.append("." * (W + 2))
    for y in range(1, H + 1):
        for x in range(1, W + 1):
            if s[y][x] == ".":
                continue
            if "." == s[y + 1][x]\
                    == s[y][x + 1]\
                    == s[y - 1][x]\
                    == s[y][x - 1]:
                print("No")
                return
    print("Yes")
    return


main()

Submission status: Accepted

Solution code:
def main():
    # 下、右、上、左
    dyx = ((1, 0), (0, 1), (-1, 0), (0, -1))
    H, W = map(int, input().split())
    s = ["." * (W + 2)]
    s += ["." + input() + "." for i in range(H)]
    s.append("." * (W + 2))
    for y in range(1, H + 1):
        for x in range(1, W + 1):
            if s[y][x] == ".":
                continue
            if "." == s[y + dyx[0][0]][x + dyx[0][1]]\
                    == s[y + dyx[1][0]][x + dyx[1][1]]\
                    == s[y + dyx[2][0]][x + dyx[2][1]]\
                    == s[y + dyx[3][0]][x + dyx[3][1]]:
                print("No")
                return
    print("Yes")
    return


main()

Submission status: Accepted

Solution code:
def main():
    # 下、右、上、左
    dy = [1, 0, -1, 0]
    dx = [0, 1, 0, -1]
    H, W = map(int, input().split())
    s = ["." * (W + 2)]
    s += ["." + input() + "." for i in range(H)]
    s.append("." * (W + 2))
    for y in range(1, H + 1):
        for x in range(1, W + 1):
            if s[y][x] == ".":
                continue
            elif "." == s[y + dy[0]][x + dx[0]]\
                    == s[y + dy[1]][x + dx[1]]\
                    == s[y + dy[2]][x + dx[2]]\
                    == s[y + dy[3]][x + dx[3]]:
                print("No")
                return
    print("Yes")
    return


main()

Submission status: Accepted

Solution code:
def main():
    # 下、右、上、左
    dy = [1, 0, -1, 0]
    dx = [0, 1, 0, -1]
    H, W = map(int, input().split())
    s = ["." * (W + 2)]
    s += ["." + input() + "." for i in range(H)]
    s.append("." * (W + 2))
    for y in range(1, H + 1):
        for x in range(1, W + 1):
            if s[y][x] == ".":
                continue
            if "." == s[y + dy[0]][x + dx[0]]\
                    == s[y + dy[1]][x + dx[1]]\
                    == s[y + dy[2]][x + dx[2]]\
                    == s[y + dy[3]][x + dx[3]]:
                print("No")
                return
    print("Yes")
    return


main()