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 drawable(s, i, j):
    if s[i - 1][j] == '#' or s[i + 1][j] == '#' or \
            s[i][j - 1] == '#' or s[i][j + 1] == '#':
        return True
    return False

H, W = map(int, raw_input().split())
s = [['.'] * (W + 2)]
s += [['.'] + list(raw_input()) + ['.'] for _ in range(H)]
s += [['.'] * (W + 2)]
for i in range(1, H + 1):
    for j in range(1, W + 1):
        if s[i][j] == '#' and not drawable(s, i, j):
            print 'No'
            sys.exit()
print 'Yes'

Submission status: Accepted

Solution code:
def main():
    h, w = map(int, input().split())
    coord = [list(input()) for _ in range(h)]
    dys = [-1, 0, 1, 0]
    dxs = [0, 1, 0, -1]
    for y in range(h):
        for x in range(w):
            if coord[y][x] == '.':
                continue
            can_paint = False
            for dy, dx in zip(dys, dxs):
                ny = y + dy
                nx = x + dx
                if ny < 0 or h <= ny or nx < 0 or w <= nx:
                    continue
                if coord[ny][nx] == '#':
                    can_paint = True
                    break
            if not can_paint:
                print('No')
                return
    print('Yes')


if __name__ == '__main__':
    main()

Submission status: Accepted

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

gri = [['.' for i in range(w+2)] for _ in range(h+2)]
for i in range(1, h+1):
    for j in range(1, w+1):
        gri[i][j] = l[i-1][j-1]

flag = 1
for i in range(1, h+1):
    for j in range(1, w+1):
        if gri[i][j] == '#':
            if gri[i-1][j] == '.' and gri[i+1][j] == '.' and gri[i][j-1] == '.' and gri[i][j+1] == '.':
                flag = 0
if flag == 1:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
a=[int(i) for i in input().split()]
#print(a)
#for i in range(a[0]):
#  for j in range(a[1]):

b=[['.']*(a[1]+2)]
b=b+[['.']+[i for i in input()]+['.'] for i in range(a[0])]
b=b+[['.']*(a[1]+2)]

#print(b)
flag=0
for k in range(1,a[0]+1):
  for i in range(1,a[1]+1):
    if b[k][i]=='#':
      if b[k-1][i]=='.' and b[k][i-1]=='.' and b[k][i+1]=='.'and b[k+1][i]=='.':
        flag=1
    
print('Yes' if flag==0 else 'No')

Submission status: Accepted

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

black = 0
for i in range(h):
    for j, x in enumerate(list(input())):
        if x == '#':
            area[i][j] = 1
            black += 1

def check(canvas, area, i, j):
    if area[i][j] != 1:
        canvas[i][j] = 1
        return canvas
    if j+1 < w:
        if area[i][j+1] == 1:
            canvas[i][j] = 2
            canvas[i][j+1] = 2
    if i+1 < h:
        if area[i+1][j] == 1:
            canvas[i][j] = 2
            canvas[i+1][j] = 2
    return canvas


black_painted = 0
for i in range(h):
    for j in range(w):
        canvas = check(canvas, area, i, j)
        if canvas[i][j] == 2:
            black_painted += 1


print('Yes') if black == black_painted else print('No')

Submission status: Accepted

Solution code:
H, W = map(int, input().split(" "))
L = [list(input()) for i in range(H)]
for i in range(H):
  for j in range(W):
    if L[i][j] != "#":
      continue
    cnt = 0
    for n in [[i+1, j], [i-1, j], [i, j-1], [i, j+1]]:
      if n[0] < 0 or n[0] > H-1:
        continue
      if n[1] < 0 or n[1] > W-1:
        continue
      if L[n[0]][n[1]] == "#":
        cnt += 1
    if cnt == 0:
      print("No")
      exit(0)
print("Yes")

Submission status: Accepted

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

ans = 'Yes'
for i in range(h):
    for j in range(w):
        if s[i][j] != '#':
            continue

        bl = False
        for dy,dx in [(-1,0),(1,0),(0,-1),(0,1)]:
            y,x = i+dy,j+dx
            if 0<=y<h and 0<=x<w and s[y][x]=='#':
                bl = True

        if not bl:
            ans = 'No'

print(ans)

Submission status: Accepted

Solution code:
a,b = map(int,input().split(" "))
ar = []
for i in range(a):
    l = list(input())
    ar.append(l)
count = 0
for i in range(a):
    for j in range(b):
        if ar[i][j] == "#":
            if i == 0:
                if j == 0:
                    if ar[i+1][j] == "." and ar[i][j+1] == ".":
                        count += 1
                        break
                elif j == b-1:
                    if ar[i+1][j] == "." and ar[i][j-1] == ".":
                        count += 1
                        break
                else:
                    if ar[i+1][j] == "." and ar[i][j-1] == "." and ar[i][j+1] == ".":
                        count += 1
                        break
            elif i == a-1:
                if j == 0:
                    if ar[i-1][j] == "." and ar[i][j+1] == ".":
                        count += 1
                        break
                elif j == b-1:
                    if ar[i-1][j] == "." and ar[i][j-1] == ".":
                        count += 1
                        break
                else:
                    if ar[i-1][j] == "." and ar[i][j-1] == "." and ar[i][j+1] == ".":
                        count += 1
                        break
            else:
                if j == 0:
                    if ar[i+1][j] == "." and ar[i][j+1] == "." and ar[i-1][j] == ".":
                        count += 1
                        break
                elif j == b-1:
                    if ar[i+1][j] == "." and ar[i][j-1] == "." and ar[i-1][j] == ".":
                        count += 1
                        break
                else:
                    if ar[i+1][j] == "." and ar[i][j-1] == "." and ar[i][j+1] == "." and ar[i-1][j] == ".":
                        count += 1
                        break
if count == 0:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
def check_4(i,j):
    hi = [1,0,-1,0]
    wi = [0,-1,0,1] #↓←↑→
    for p in range(4):
        if 0 <= i+hi[p] < H and 0 <= j+wi[p] < W:
            if cambus[i+hi[p]][j+wi[p]] == '#':
                return True
    return False

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

for i in range(H):
    for j in range(W):
        if cambus[i][j] == '#':
            if not check_4(i,j):
                print('No')
                exit()
print('Yes')

Submission status: Accepted

Solution code:

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

tab = []
for i in range(0,h):
    tab.append(input())

alone = False

#for i in range(0,h):
#    print(tab[i][0:])

#print(tab[h-1][w-1])
for hi in range(0,h):
    if alone :
        break
    for wi in range(0,w):

        if tab[hi][wi] != '#':
            continue

        if hi + 1 < h:
            if tab[hi + 1][wi] == '#':
                continue

        if hi - 1 >= 0:
            if tab[hi - 1][wi] == '#':
                continue

        if wi + 1 < w:
            if tab[hi][wi + 1] == '#':
                continue

        if wi - 1 >= 0:
            if tab[hi][wi - 1] == '#':
                continue

        alone = True
        break;

#    if alone:
#        break
print("Yes" if not alone else "No")

Submission status: Accepted

Solution code:
def check_4(i, j):
    hi = [1, 0, -1, 0]
    wi = [0, -1, 0, 1]
    for p in range(4):
        if 0 <= i+hi[p] < H and 0 <= j+wi[p] < W:
            if cambus[i+hi[p]][j+wi[p]] == '#':
                return True
    return False


H, W = map(int, input().split(' '))
cambus = [input() for i in range(H)]

for i in range(H):
    for j in range(W):
        if cambus[i][j] == '#':
            if not check_4(i, j):
                print('No')
                exit()
print('Yes')

Submission status: Accepted

Solution code:
# coding: UTF-8
import sys
#sys.setrecursionlimit(n)
import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *

h, w = map(int, input().split())
e = []
e2 = [[0 for _ in range(w)] for _ in range(h)]
count = 0
for i in range(h):
    t = list(map(str, input().split()))
    e.append(list(t[0]))
    for j in list(t[0]):
        if (j == '#'):
            count += 1
for i in range(1, h):
    for j in range(1, w):
        b = False
        if (e[i][j] == '#'):
            if (i < h - 1):
                if(e[i + 1][j] == '#'):
                    b = True
            if (i > 0):
                if (e[i - 1][j] == '#'):
                    b = True
            if (j < w - 1):
                if (e[i][j + 1] == '#'):
                    b = True
            if (j > 0):
                if (e[i][j - 1] == '#'):
                    b = True
            if not(b):
                print("No")
                sys.exit()

print("Yes")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
h,w = map(int,(input().split()))
li = []
jud = 1
for i in range(h):
    li.append(list(input()))
dx = [0,1,-1,0]
dy = [1,0,0,-1]
num = 0
for i in range(h):
    for j in range(w):
        if li[i][j] == '#':
            num=0
            for d in range(len(dx)):
                ni = i+dy[d]
                nj = j+dx[d]
                if ni < 0 or h <= ni:
                    continue
                if nj < 0 or w <= nj:
                    continue
                if li[ni][nj] == '#':
                    num+=1
            if num == 0:
                jud = 0
                break

if jud == 0:
    print("No")
if jud == 1:
    print("Yes")

Submission status: Accepted

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

for i, row in enumerate(grid[1: -1]):
    for j, s in enumerate(row[1: -1]):
        if s == '.':
            continue
        if grid[i + 1][j] == '#' or  grid[i +1][j + 2] == '#' or grid[i][j + 1] == '#' or  grid[i +2][j + 1] == '#':
            continue
        print('No')
        sys.exit()
print('Yes')

Submission status: Accepted

Solution code:
H, W = (int(i) for i in input().split())
L = []
L.append(["."]*(W + 2))
for i in range(H):
    D = [str(i) for i in input()]
    L.append(["."] + D + ["."])
L.append(["."]*(W + 2))

res = "Yes"

for i in range(1,H + 1):
    for j in range(1,W + 1):
        if L[i+1][j] == "." and L[i-1][j] == "." and L[i][j+1] == "." and L[i][j-1] == "." and L[i][j] == "#":
            res = "No"

print(res)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
h,w = map(int, input().split())
s = [["." for _ in range(w+2)]]
for _ in range(h):
    line = list(input())
    s.append(["."]+line+["."])
s.append(["." for _ in range(w+2)])
diff = [
    [1,0]
    ,[0,1]
    ,[-1,0]
    ,[0,-1]
]
def dfs(hi,wi):
    stack = [(hi,wi)]
    while len(stack)>0:
        hi,wi = stack.pop()
        s[hi][wi] = "."
        for d in diff:
            if s[hi+d[0]][wi+d[1]] == "#":
                stack.append((hi+d[0], wi+d[1]))

for hi in range(1,h+1):
    for wi in range(1,w+1):
        if s[hi][wi] == "#":
            f = False
            for d in diff:
                f = f or s[hi+d[0]][wi+d[1]]=="#"
            if f:
                dfs(hi, wi)

for hi in range(1,h+1):
    for wi in range(1,w+2):
        if s[hi][wi] == "#":
            print("No")
            exit()
print("Yes")

Submission status: Accepted

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

dh = [-1, 0, 1, 0]
dw = [0, 1, 0, -1]

flg = True
for h in range(H):
    for w in range(W):
        if S[h][w] == ".":
            continue

        nexts = []
        for i in range(4):
            nh = h + dh[i]
            nw = w + dw[i]
            if nh >= 0 and nh < H and nw >= 0 and nw < W:
                nexts.append(S[nh][nw])
        if all([n == "." for n in nexts]):
            print("No")
            exit()
print("Yes")

Submission status: Accepted

Solution code:
def inpl(): return [int(i) for i in input().split()]

H, W = inpl()
S = [[] for _ in range(H)]
direct = [(-1,0), (1,0), (0,-1), (0, 1)]

for i in range(H):
    S[i] = list(input())
ans = 'Yes'
for nh in range(H):
    for nw in range(W):
        if S[nh][nw] == '.':
            continue
        check = 0
        for dh, dw in direct:
            mh, mw =nh + dh, nw + dw
            if 0 > mh or mh > H-1 or 0 > mw or mw > W-1:
                continue
            if S[mh][mw] == '#':
                check = 1
        if not check:
            ans = 'No'
print(ans)

Submission status: Accepted

Solution code:
# encoding: utf-8
H, W = map(int, input().split())
s = [list(input()) for i in range(H)]

ans = "Yes"
for y in range(H):
    for x in range(W):
        if s[y][x] == ".": continue
        for dx, dy in ((1, 0), (-1, 0), (0, 1), (0, -1)):
            # skip
            if y + dy < 0 or H <= y + dy: continue
            elif x + dx < 0 or W <= x + dx: continue
            # check
            if s[y][x] == s[y + dy][x + dx] == "#": break
            else: continue
        else:
            ans = "No"
        if ans == "No": break
    if ans == "No": break

print(ans)

Submission status: Accepted

Solution code:
import sys
h, w = map(int, input().split())
grid = [list('.' + input() + '.') for _ in range(h)]
grid.insert(0, list('.'*(w+2)))
grid.append(list('.'*(w+2)))

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

Submission status: Accepted

Solution code:
# Grid Repainting 2
import numpy as np
h, w = map(int, input().split())
s = np.array([[0]*(w+2) for i in range(h+2)])
for i in range(h):
    t = input()
    for j in range(w):
        if t[j] == '#':
            s[i+1][j+1] = 1

for x in range(h):
    i = x + 1
    for y in range(w):
        j = y + 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:
                exit(print('No'))
print('Yes')

Submission status: Accepted

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

Submission status: Accepted

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

if h == 1:
    if w == 1:
        if s[0][0] == "#":
            print("No")
            exit()
    else:
        for j in range(w):
            if s[0][j] == ".":
                continue
            else:
                if j == 0:
                    if s[0][1] == ".":
                        print("No")
                        exit()
                if j == w-1:
                    if s[0][w-2] == ".":
                        print("No")
                        exit()
                else:
                    if s[0][j-1] == "." and s[0][j+1] == ".":
                        print("No")
                        exit()

elif w == 1:
    for i in range(h):
        if s[i][0] == ".":
            continue
        else:
            if i == 0:
                if s[1][0] == ".":
                    print("No")
                    exit()
            elif i == h-1:
                if s[h-2][0] == ".":
                    print("No")
                    exit()
            else:
                if s[i- 1][0] == "." and s[i+1][0] == ".":
                    print("No")
                    exit()

else:
    for i in range(h):
        for j in range(w):
            if s[i][j] == ".":
                continue
            else:
                if i == 0:
                    if j == 0:
                        if s[0][1] == "." and s[1][0] == ".":
                            print("No")
                            exit()
                    elif j == w-1:
                        if s[0][w-2] == "." and s[1][w-1] == ".":
                            print("No")
                            exit()
                    else:
                        if s[i][j-1] == "." and s[i][j+1] == "." and s[i+1][j] == ".":
                            print("No")
                            exit()

                elif i == h-1:
                    if j == 0:
                        if s[h-1][1] == "." and s[h-2][0] == ".":
                            print("No")
                            exit()
                    elif j == w-1:
                        if s[h-1][w-2] == "." and s[h-2][w-1] == ".":
                            print("No")
                            exit()
                    else:
                        if s[h-1][j-1] == "." and s[h-1][j+1] == "." and s[h-2][j] == ".":
                            print("No")
                            exit()

                elif j == 0:
                    if s[i-1][0] == "." and s[i][1] == "." and s[i+1][0] == ".":
                            print("No")
                            exit()

                elif j == w-1:
                    if s[i-1][w-1] == "." and s[i][w-2] == "." and s[i+1][w-1] == ".":
                            print("No")
                            exit()

                else:
                    if s[i][j-1] == "." and s[i-1][j] == "." and s[i+1][j] == "." and s[i][j+1] == ".":
                            print("No")
                            exit()

print("Yes")

Submission status: Accepted

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

if h == 1:
    if w == 1:
        if s[0][0] == "#":
            print("No")
            exit()
    else:
        for j in range(w):
            if s[0][j] == ".":
                continue
            else:
                if j == 0:
                    if s[0][1] == ".":
                        print("No")
                        exit()
                if j == w-1:
                    if s[0][w-2] == ".":
                        print("No")
                        exit()
                else:
                    if s[0][j-1] == "." and s[0][j+1] == ".":
                        print("No")
                        exit()

elif w == 1:
    for i in range(h):
        if s[i][0] == ".":
            continue
        else:
            if i == 0:
                if s[1][0] == ".":
                    print("No")
                    exit()
            elif i == h-1:
                if s[h-2][0] == ".":
                    print("No")
                    exit()
            else:
                if s[i- 1][0] == "." and s[i+1][0] == ".":
                    print("No")
                    exit()

else:
    for i in range(h):
        for j in range(w):
            if s[i][j] == ".":
                continue
            else:
                if i == 0:
                    if j == 0:
                        if s[0][1] == "." and s[1][0] == ".":
                            print("No")
                            exit()
                    elif j == w-1:
                        if s[0][w-2] == "." and s[1][w-1] == ".":
                            print("No")
                            exit()
                    else:
                        if s[i][j-1] == "." and s[i][j+1] == "." and s[i+1][j] == ".":
                            print("No")
                            exit()

                elif i == h-1:
                    if j == 0:
                        if s[h-1][1] == "." and s[h-2][0] == ".":
                            print("No")
                            exit()
                    elif j == w-1:
                        if s[h-1][w-2] == "." and s[h-2][w-1] == ".":
                            print("No")
                            exit()
                    else:
                        if s[h-1][j-1] == "." and s[h-1][j+1] == "." and s[h-2][j] == ".":
                            print("No")
                            exit()

                elif j == 0:
                    if s[i-1][0] == "." and s[i][1] == "." and s[i+1][0] == ".":
                            print("No")
                            exit()

                elif j == w-1:
                    if s[i-1][w-1] == "." and s[i][w-2] == "." and s[i+1][w-1] == ".":
                            print(".")
                            exit()

                else:
                    if s[i][j-1] == "." and s[i-1][j] == "." and s[i+1][j] == "." and s[i][j+1] == ".":
                            print("No")
                            exit()

print("Yes")

Submission status: Accepted

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

sharp_ind = set()
count = 0
for i in range(h):
    for j in range(w):
        if grid[i][j] == "#":
            sharp_ind.add((i,j))
            count += 1

check_ind = [(-1,0),(1,0),(0,-1),(0,1)]
check_res = []

for i in range(h):
    for j in range(w):
        if grid[i][j] == '#':
            flag = False
            for r,c in check_ind:
                if (i+r, j+c) in sharp_ind:
                    flag = True
            check_res.append(flag)

if sum(check_res) == count:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

flg = 0    

for j in range(1, h+1):
    for k in range(1, w+1):
        if arr[j][k] == "#":
            if (arr[j-1][k] == '.') and (arr[j][k-1] == '.') and (arr[j+1][k] == '.') and (arr[j][k+1] == '.'):
                flg = 1    
        
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)]
case = [[1, 0], [-1, 0], [0, 1], [0, -1]]
flag = True

for i in range(H):
    for j in range(W):
        if s[i][j] == '#':
            flag = False
            for k in range(4):
                x, y = i+case[k][0], j+case[k][1]
                if x < 0 or x >= H or y < 0 or y >= W:
                    continue
                if s[x][y] == '#':
                    flag = True
                    break
            if not flag:
                break
    if not flag:
        break

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

Submission status: Accepted

Solution code:
size = input().split(' ')
H = int(size[0])
W = int(size[1])
S = []
for k in range(H):
    row = input()
    S.append(row)

answer = 'Yes'
for i in range(H):
    for j in range(W):
        #if S[i][j] == '#':
            #print('i={},j={},i-1={},i+1={},j-1={},j+1={}'.format(i,j,i-1,i+1,j-1,j+1))
        if (S[i][j] == '#') and (((i - 1) >= 0) and (S[i-1][j] != '#')) and (((j - 1) >= 0) and (S[i][j-1] != '#')) and (((j + 1) < W) and (S[i][j+1] != '#')) and (((i + 1) < H) and (S[i+1][j] != '#')):
            answer = 'No'
            break
print(answer)

Submission status: Accepted

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

s = []

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

flag = True

for i in range(h):
    for j in range(w):
        if s[i][j]=='#':
            if i==0:
                f = s[i+1][j]=='#'
            elif i==h-1:
                f = s[i-1][j]=='#'
            else:
                f = s[i-1][j]=='#' or s[i+1][j]=='#'
            if j==0:
                f = f or s[i][j+1]=='#'
            elif j==w-1:
                f = f or s[i][j-1]=='#'
            else:
                f = f or s[i][j-1]=='#' or s[i][j+1]=='#'

            flag = flag and f

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

Submission status: Accepted

Solution code:
import itertools
H, W = [int(_) for _ in input().split()]
S = [input() for _ in range(H)]
for i, j in itertools.product(range(H), range(W)):
    if S[i][j] == '#':
        cand = [i - 1, j], [i + 1, j], [i, j - 1], [i, j + 1]
        exist = False
        for x, y in cand:
            if x < 0 or H <= x or y < 0 or W <= y:
                continue
            else:
                if S[x][y] == '#':
                    exist = True
        if not exist:
            print('No')
            exit()
print('Yes')

Submission status: Accepted

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


for y in range(h):
    for x in range(w):
        if cells[y][x] == '.':
            continue
        is_alone = True
        for dy,dx in [(-1, 0), (1, 0), (0, -1), (0, 1)]:
            ny = y+dy
            nx= x+dx
            if 0<=ny<h and 0<=nx<w and cells[ny][nx] == '#':
                is_alone = False
                break
        if is_alone:
            print('No')
            exit()
print('Yes')

Submission status: Accepted

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

s = [input() for i in range(H)]

for y in range(H):
  for x in range(W):
    if x-1 < 0 or y-1 < 0 or x+1 > W-1 or y+1 > H-1:
      continue
    if s[y][x] == '#' and 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:
h,w = list(map(int, input().split()))
s = []
for i in range(h):
    s.append(list(input()))
for y in range(h):
    for x in range(w):
        if s[y][x] == "#":
            ay = [0, -1, 0, 1]
            ax = [1, 0, -1, 0]
            for i in range(4):
                if 0 <= x+ax[i] < w and 0 <= y+ay[i] < h:
                    if s[y+ay[i]][x+ax[i]] == "#":
                        break
            else:
                break
    else:
        continue
    print("No")
    break
else:
    print("Yes")

Submission status: Accepted

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

def judge(list,i,j):
    if i != 0:
        top = list[i-1][j]
    else:
        top = "."
    if j != 0:
        left = list[i][j-1]
    else:
        left = "."
    if i != H-1:
        bottom = list[i+1][j]
    else:
        bottom = "."
    if j != W-1:
        right = list[i][j+1]
    else:
        right = "."
    return top == "#" or left == "#" or bottom == "#" or right == "#"

for i in range(H):
    for j in range(W):
        if L[i][j] == "#" and judge(L,i,j) is False:
            print("No")
            exit()
print("Yes")

Submission status: Accepted

Solution code:
tate, yoko = map(int, input().split())
s  = [input()  for i in range(tate)]
dxy = [(-1, 0), (0, -1), (0, 1), (1, 0),]
for i in range(tate):
    for j in range(yoko):
        if s[i][j] == "#":
            save = []
            for dx, dy in dxy:
                if i + dy < 0 or i + dy > tate - 1 or j + dx < 0 or j + dx > yoko - 1: continue
                if s[i + dy][j + dx] == "#": 
                    save.append("#")
                    break
            if "#" in save: continue
            else:
                print("No")
                exit()
print("Yes")

Submission status: Accepted

Solution code:
def main():
    H, W = map(int, input().split())
    c = []
    c.append(['.'] * (W + 2))
    for _ in range(H):
        c.append(['.'] + list(input()) + ['.'])
    c.append(['.'] * (W + 2))
    for h in range(1, H + 2):
        for w in range(1, W + 2):
            if c[h][w] == '#':
                if c[h - 1][w] == c[h + 1][w] == c[h][w - 1] == c[h][w + 1] == '.':
                    print('No')
                    return
    print('Yes')


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys

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

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

dxdy = [[1, 0], [-1, 0], [0, 1], [0, -1]]


for y in range(1, H + 1):
    for x in range(1, W + 1):
        if col[y][x] == '#':
            for dx, dy in dxdy:
                if col[y + dy][x + dx] == '#':
                    break
            else:
                print('No')
                sys.exit()
print('Yes')

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
l = []
for i in range(h):
    l.append(input())
x = [-1,0,1,0]
y = [0,-1,0,1]
flg = False
for i in range(h):
    for j in range(w):
        if l[i][j] == "#":
            cnt = 0
            for k in range(4):
                if j+x[k] != -1 and i+y[k] != -1 and j+x[k] != w and i+y[k] != h:
                     if l[i+y[k]][j+x[k]] == "#":
                         cnt += 1
            if cnt == 0:
                flg =True
print("YNeos"[flg::2])

Submission status: Accepted

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