AtCoder Beginner Contest 96-C
Published in
1 min readAug 14, 2019
If there is at least one square black which is arounded by white squares,
square1001 cannot achieve his objective.
So check this.
if there is a black square, count how many white squares which is sided it.
I want to think time complexity.
height is at most 50.
width is at most 50.
for-loop which is checked whether the square is black or white is 50 * 50.
if the square is black, check the square sided by black square for 4 times.
So, 50 * 50 * 4 = 10000.
My Solution
H, W = map(int,input().split())sw_list = []
sw_list.append(["."]*(W+2))
[sw_list.append(["."] + list(input()) + ["."]) for _ in range(H)]
sw_list.append(["."]*(W+2))def check():
for h in range(1,H+1):
for w in range(1,W+1):
if sw_list[h][w] == "#":
if all([sw_list[h-dh][w-dw]=="." for dh,dw in [(-1,0),(0,-1),(1,0),(0,1)]]):
return False
return Trueif check():
print("Yes")
else:
print("No")