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: Runtime Error

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):
        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[nx][ny] == '#':
                    flag = True
            else:
                flag = True
        if flag == False:
            print('No')
            exit()        

print('Yes')

Submission status: Runtime Error

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

print('Yes')

Submission status: Runtime Error

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

dl = [(-1, 0), (0, 1), (1, 0), (0, -1)]
for i, row in enumerate(S):
    for j, val in enumerate(row):
        if val == '.':
            continue

        can_paint = False
        for dx, dy in dl:
            di, dj = i + dx, j + dy
            if di < 0 or H <= di or dj < 0 or W <= dj:
                continue
            if S[di][dj] == '#':
                can_paint = True
                break
        if not can_paint:
            print('No')
            return
print('Yes')

Submission status: Runtime Error

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

dl = [(-1, 0), (0, 1), (1, 0), (-1, -1)]
for i, row in enumerate(S):
    for j, val in enumerate(row):
        if val == '.':
            continue

        can_paint = False
        for dx, dy in dl:
            di, dj = i + dx, j + dy
            if di < 0 or H <= di or dj < 0 or W <= dj:
                continue
            if S[di][dj] == '#':
                can_paint = True
                break
        if not can_paint:
            print('No')
            sys.exit(0)
print('Yes')

Submission status: Runtime Error

Solution code:
H, W = map(int, input())
S = [list(input()) for __ in range(H)]

dl = [(-1, 0), (0, 1), (1, 0), (-1, -1)]
for i, row in enumerate(S):
    for j, val in enumerate(row):
        if val == '.':
            continue

        res = False
        for dx, dy in dl:
            di, dj = i + dx, j + dy
            if di < 0 or W < di or dj < 0 or H < dj:
                continue
            if S[di][dj] == '#':
                res = True
                break
        if res:
            print('No')
print('Yes')

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

for i in range(H):
  for j in range(W):
    if S[i][j] == "#":
      b = sum([t[j].count("#") for t in S[max(0,i-1):min(H,i+1)]])
      b += S[i][max(0,j-1):min(W,j+1)].count("#")-1
      if b == 1:
        print("No")
        c = 1
        break
  else:
    continue
  break

if c !=1:
  print("Yes")

Submission status: Runtime Error

Solution code:
hw = input().split(" ");
h = int(hw[0]);
w = int(hw[1]);
pic = [['.']*(h+2) for i in range(w+2)];
can = 0;
for i in range(1,h+1) :
	s = list(input().rstrip('\n'));
	for j in range(1,w+1) :
		pic[i][j] = s[j-1];
for i in range(1,h+1) :
	for j in range(1,w+1) :
		if pic[i][j] == '#' and pic[i][j-1] == '.' and pic[i-1][j] == '.' and pic[i][j+1] == '.' and pic[i+1][j] == '.' :
			can = can + 1;
if can == 0 :
	print('Yes');
else :
	print('No');

Submission status: Runtime Error

Solution code:
hw = input().split(" ");
h = int(hw[0]);
w = int(hw[1]);
pic = [[.]*h+2 for i in range(w+2)];
can = 0;
for i in range(1,h+1) :
	s = list(input().rstrip('\n'));
	for j in range(1,w+1) :
		pic[i][j] = s[j-1];
for i in range(1,h+1) :
	for j in range(1,w+1) :
		else :
			if pic[i][j] == '#' and pic[i][j-1] == '.' and pic[i-1][j] == '.' and pic[i][j+1] == '.' and pic[i+1][j] == '.' :
				can = can + 1;
if can == 0 :
	print('Yes');
else :
	print('No');

Submission status: Runtime Error

Solution code:
H,W = (int(i) for i in input().split())

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

canComplete = True

for row in range(W):
    for column in range(H):
        above = row - 1
        bottom = row + 1
        left = column - 1
        right = column + 1
        
        if goal[row][column] == "#":
            if above >= 0 and goal[above][column] == "#":
                continue
            elif bottom < H and goal[bottom][column] == "#":
                continue
            elif left >= 0 and goal[row][left] == "#":
                continue
            elif right < W and goal[row][right] == "#":
                continue
            else:
                canComplete = False
                break

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

Submission status: Runtime Error

Solution code:
if __name__ == '__main__':
    H, W = map(int, input().split())
    s_list = [list(input()) for i in range(H)]


    answer = "Yes"

    for x in range(H):
        for y in range(W):
            if s_list[x][y] == '.':
                continue
            is_all_white = True
            dxs = [0, 1, 0, -1]
            dys = [1, 0, -1, 0]
            for dx, dy in zip(dxs, dys):
                nx = x + dx
                ny = y + dy
                if 0 <= nx <= H-1 and 0 <= ny <= W-1:
                    if s_list[nx][ny] == "#":
                        is_all_white = False
                        break
            if is_all_white:
                answer = "No"
                break
        if is_all_white:
            break

    print(answer)

Submission status: Runtime Error

Solution code:
if __name__ == '__main__':
    H, W = map(int, input().split())
    s_list = [list(input()) for i in range(H)]

    answer = "Yes"
    for i in range(H):
        for j in range(W):
            if s_list[i][j] == "#" and answer == "Yes":

                if i == 0:
                    if j == 0:
                        if s_list[i][j+1] == "." and s_list[i+1][j] == ".":
                            answer = "No"
                            break
                    elif j == W-1:
                        if s_list[i][j-1] == "." and s_list[i+1][j] == ".":
                            answer = "No"
                            break
                    else:
                        if s_list[i][j+1] == "." and s_list[i][j-1] == "." and s_list[i+1][j] == ".":
                            answer = "No"
                            break
                elif i == H - 1:
                    if s_list[i][j+1] == "." and s_list[i-1][j] == ".":
                            answer = "No"
                            break
                    elif j == W-1:
                        if s_list[i][j-1] == "." and s_list[i-1][j] == ".":
                            answer = "No"
                            break
                    else:
                        if s_list[i][j+1] == "." and s_list[i][j-1] == "." and s_list[i-1][j] == ".":
                            answer = "No"
                            break
                else:
                    if j == 0:
                        if s_list[i][j+1] == "." and s_list[i+1][j] == "." and s_list[i-1][j] == ".":
                            answer = "No"
                            break
                    elif j == W-1:
                        if s_list[i][j-1] == "." and s_list[i+1][j] == "." and s_list[i-1][j] == ".":
                            answer = "No"
                            break
                    else:
                        if s_list[i][j+1] == "." and s_list[i][j-1] == "." and s_list[i+1][j] == "." and s_list[i-1][j] == ".":
                            answer = "No"
                            break

    print(answer)

Submission status: Runtime Error

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

Submission status: Runtime Error

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


def check_around(x, y):
    if 0 < y and campus[y - 1][x] == '#':
        return True
    elif 0 < x and campus[y][x - 1] == '#':
        return True
    elif x < W - 1 and campus[y][x + 1] == '#':
        return True
    elif y < H - 1 and campus[y + 1][x] == '#':
        return True
    return False


can = True
for y in range(H):
    for x in range(W):
        if campus[y][x] == '#':
            can = check_around(x, y)
            if not can:
                print('No')
                exit()
print('Yes')

Submission status: Runtime Error

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


def check_around(x, y):
    if 0 < y and campus[y - 1][x] == '#':
        return True
    elif 0 < x and campus[y][x - 1] == '#':
        return True
    elif x < W - 1 and campus[y][x + 1] == '#':
        return True
    elif y < H - 1 and campus[y + 1][x] == '#':
        return True


can = True
for y in range(H):
    for x in range(W):
        if campus[y][x] == '#':
            can = check_around(x, y)
            if not can:
                print('No')
                exit()
print('Yes')

Submission status: Runtime Error

Solution code:
H, W = map(int, input().split())
s_list = []
for i in range(W):
    s_list.append(input())
cnt = 0
for i in range(1, H):
    for j in range(1, W):
        if s_list[i][j] == '#':
            if s_list[i][j-1] != '#' and s_list[i-1][j] != '#'\
               and s_list[i][j+1] !='#' and s_list[i+1][j] != '#':
            cnt += 1
if cnt == 0:
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

Solution code:
H, W = map(int, input().split())
s_list = []
for i in range(W):
    s_list.append(input())
cnt = 0
for i in range(1, H):
    for j in range(1, W):
        if s_list[i][j] == '#' and s_list[i][j-1] != '#' and\
           s_list[i-1][j] != '#' and s_list[i][j+1] !='#' and\
                                                       s_list[i+1][j] != '#':
            cnt += 1
if cnt == 0:
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

Solution code:
H, W = map(int, input().split())
s_list = []
for i in range(W):
    s_list.append(input())
cnt = 0
for i in range(H):
    for j in range(1, W):
        if s_list[i][j] == '#' and s_list[i][j-1] != '#' and\
           s_list[i-1][j] != '#' and s_list[i][j+1] !='#' and\
                                                       s_list[i+1][j] != '#':
            cnt += 1
if cnt == 0:
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

Solution code:
def search(X, Y, MAP, H, W):
    if X < 0 or X >= W or Y < 0 or Y >= H:
        return False
    elif MAP[X][Y] == '.':
        return False
    else: 
        return True

def each(X, Y, MAP, H, W):
    right = search(X+1, Y, MAP, H, W)
    down = search(X, Y-1, MAP, H, W)
    left = search(X-1, Y, MAP, H, W)
    up = search(X, Y+1, MAP, H, W)
    return (right or down or left or up)

def main():
    h, w = map(int, input().split())
    s = [input() for _ in range(h)]
    for i in range(h):
        for j in range(w):
            if s[i][j] == '#':
                if not each(i, j, s, h, w):
                    print("No")
                    exit()
    print("Yes")

main()

Submission status: Runtime Error

Solution code:
def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def solve(inputs):
    field = []
    for row in inputs:
        line = []
        for c in row:
            line.append(c)
        field.append(line)

    if len(field) == 1:
        if len(field[0]) == 1:
            return "No"

    for i, row in enumerate(field):
        for j, _ in enumerate(row):
            available = False
            if field[i][j] == ".":
                continue
            if i - 1 >= 0:
                available |= field[i - 1][j] == "#"

            if j - 1 >= 0:
                available |= field[i][j - 1] == "#"
            if j + 1 < len(row):
                available |= field[i][j + 1] == "#"

            if i + 1 < len(row):
                available |= field[i + 1][j] == "#"
            if not available:
                return "No"

    return "Yes"


if __name__ == "__main__":
    [N, _] = map(lambda x: int(x), input().split())
    ret = solve(inputs(N))
    print(ret)

Submission status: Runtime Error

Solution code:
def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def solve(inputs):
    field = []
    for row in inputs:
        line = []
        for c in row:
            line.append(c)
        field.append(line)

    for i, row in enumerate(field):
        for j, _ in enumerate(row):
            available = False
            if field[i][j] == ".":
                continue
            if i - 1 >= 0:
                available |= field[i - 1][j] == "#"

            if j - 1 >= 0:
                available |= field[i][j - 1] == "#"
            if j + 1 < len(row):
                available |= field[i][j + 1] == "#"

            if i + 1 < len(row):
                available |= field[i + 1][j] == "#"
            if not available:
                return "No"

    return "Yes"


if __name__ == "__main__":
    [N, _] = map(lambda x: int(x), input().split())
    ret = solve(inputs(N))
    print(ret)

Submission status: Runtime Error

Solution code:
def solve(H, W, S):
    for h in range(1, H):
        for w in range(1, W):
            if S[h][w] == '#':
                if not (S[h-1][w] == '#' or S[h+1][w] == '#' or S[h][w+1] == '#' or S[h][w-1] == '#'):
                    return "No"
    return "Yes"


H, W = [int(x) for x in input().split()]
# H, W < 50
S = []
S.append('.' * (H+2))
for _ in range(H):
    S.append("."+input().strip()+".")
S.append('.' * (H+2))
print(solve(H, W, S))

Submission status: Runtime Error

Solution code:
h,w=sorted(map(int, input().split()))
s= ["."+input()+"." for _ in range(h)]
t=".."
for i in range(w):
    t+="."
s.insert(0,t)
s.append(t)
ans=0
for i in range(h):
    for j in range(w):
        if ans==1:
            break
        if s[i+1][j+1]=="#":
            if s[i][j+1]=="." and s[i+1][j]=="." and s[i+1][j+2]=="." and s[i+2][j+1]==".":
                ans=1
                
print("Yes" if ans==0 else "No")

Submission status: Runtime Error

Solution code:
h, w = map(int, input().split())
form = []
flg = 0
for i in range(h):
    form.append(input())
for i in range(h):
    for j in range(w):
        if form[i][j]==".":
            continue
        else:
            if i==0:
                if j==0:
                    if form[i][j+1]== "#" or form[i+1][j]=="#":
                        continue
                    else:
                        flg = 1
                        break
                elif j==w-1:
                    if form[i][j-1]== "#" or form[i+1][j]=="#":
                        continue
                    else:
                        flg = 1
                        break
                else:
                    if form[i][j-1]== "#" or form[i+1][j]=="#" or form[i][j+1]=="#":
                        continue
                    else:
                        flg=1
                        break
                        
            elif i==h-1:    
                if j==0:
                    if form[i][j+1]== "#" or form[i-1][j]=="#":
                        continue
                    else:
                        flg = 1
                        break
                elif j==w-1:
                    if form[i][j-1]== "#" or form[i-1][j]=="#":
                        continue
                    else:
                        flg = 1
                        break
                else:
                    if form[i][j-1]== "#" or form[i-1][j]=="#" or form[i][j+1]=="#":
                        continue
                    else:
                        flg=1
                        break
                
            else:
                if form[i][j-1]== "#"or form[i+1][j]=="#" or form[i][j+1]=="#" or form[i-1][j]=="#":
                    continue
                else:
                    flg = 1
                    break
    if flg ==1:
        break
    
if flg ==0:
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

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

Submission status: Runtime Error

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

YES = "Yes"  # type: str
NO = "No"  # type: str

def get_s(i,j,s,H,W):
    if 0 <= i < H and 0 <= j < W:
        return s[i][j]
    else:
        return "."

def solve(H: int, W: int, s: "List[str]"):


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

    print(YES)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    s = [ next(tokens) for _ in range(W) ]  # type: "List[str]"
    solve(H, W, s)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

YES = "Yes"  # type: str
NO = "No"  # type: str

def solve(H: int, W: int, s: "List[str]"):

    def get_s(i,j):
        if 0 <= i < H and 0 <= j < W:
            return s[i][j]
        else:
            return "."

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

    print(YES)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    s = [ next(tokens) for _ in range(W) ]  # type: "List[str]"
    solve(H, W, s)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

YES = "Yes"  # type: str
NO = "No"  # type: str

def solve(H: int, W: int, s: "List[str]"):

    def get_s(i,j):
        if 0 <= i < H and 0 <= j < W:
            return s[i][j]
        else:
            return "."

    for i in range(H):
        for j in range(W):
            if s[i][j] == "#":
                if  all([get_s(i+di,j+dj) == "." for di,dj in [(1,0),(-1,0),(0,1),(0,-1)]]):
                    print(NO)
                    return

    print(YES)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    s = [ next(tokens) for _ in range(W) ]  # type: "List[str]"
    solve(H, W, s)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

YES = "Yes"  # type: str
NO = "No"  # type: str

def solve(H: int, W: int, s: "List[str]"):

    def get_s(i,j):
        if 0 <= i < H and 0 <= j < W:
            return s[i][j]
        else:
            return "."

    for i in range(H):
        for j in range(W):
            if s[i][j] == "#":
                if  all([get_s(i+di,j+dj) == "." for di,dj in [(1,0),(-1,0),(0,1),(0,-1)]]):
                    print(NO)
                    return

    print(YES)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    s = [ list(next(tokens)) for _ in range(W) ]  # type: "List[str]"
    solve(H, W, s)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
H, W = map(int, input().split())
s = ['.' + input() +'.' for _ in range(H)]
s = ['.'] * (W + 2) s + ['.'] * (W + 2)
flag = True
for h in range(1, H + 1):
    for w in range(1, W + 1):
        if (s[h][w] == '#' and s[h - 1][w] == '.' and s[h + 1][w] == '.'
               and s[h][w - 1] == '.' and s[h][w + 1] == '.'):
            flag = False
                
print('Yes' if flag else 'No')

Submission status: Runtime Error

Solution code:
h,w=map(int, input().split())
S=["."+input()+"." for _ in range(h)]
S = ["."*(w+2)]+S+["."*(w+2)]
# print(S)
flag=True
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]==".":
                flag=False
print("Yes" if flag else "No")a

Submission status: Runtime Error

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

YES = "Yes"  # type: str
NO = "No"  # type: str

def solve(H: int, W: int, s: "List[str]"):
    def is_valid(i, j):
        if (i > 0 and s[i - 1][j] == '#' or 
            i < H - 1 and s[i + 1][j] == '#' or 
            j > 0 and s[i][j - 1] == '#' or 
            j < W - 1 and s[i][j + 1] == '#'):
            return True
        return False

    for i, R in enumerate(s):
        for j, c in enumerate(R):
            if c == '#' and not is_valid(i, j):
                print(NO)
                return
    print(YES)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    s = [ next(tokens) for _ in range(W) ]  # type: "List[str]"
    solve(H, W, s)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
a,b,c,x,y = map(int,input().split())
m = 0
if a + b <= 2*c:
    m += (a+b) * min(x,y)
else:
    m += c * 2 * min(x,y)

if x > y:
    if a <= 2*c:
        m += a * (x-y)
    else:
        m += c * 2 * (x-y)


else:
     if b <= 2*c:
         m += b * (y-x)
     else:
         m += c * 2 * (y-x)

print(m)

Submission status: Runtime Error

Solution code:
a,b,c,x,y = map(int,input().split())
m = 0
if a + b <= 2*c:
    m += (a+b) * min(x,y)
else:
    m += c * 2 * min(x,y)

if x > y:
    if a <= 2*c:
        m += a * (x-y)
    else:
        m += c * 2 * (x-y)

elif x == y:
    pass

else:
     if b <= 2*c:
         m += b * (y-x)
     else:
         m += c * 2 * (y-x)

print(m)

Submission status: Runtime Error

Solution code:
height,width=map(int,input().split())
graph = [[s for s in input()] for i in range(height)]

for r in range(width):
    for c in range(height):
        if graph[r][c]==".":
            continue

        if r>0 and graph[r-1][c]=="#":
            continue

        if r<width-1 and graph[r+1][c]=="#":
            continue

        if c>0 and graph[r][c-1]=="#":
            continue

        if c<height-1 and graph[r][c+1]=="#":
            continue

        print("No")
        exit()
print("Yes")

Submission status: Runtime Error

Solution code:
height,width=map(int,input().split())
graph = [[s for s in input()] for i in range(height)]

for r in range(width):
    for c in range(height):
        if graph[r][c]==".":
            continue

        if r>1 and graph[r-1][c]=="#":
            continue

        if r<width-1 and graph[r+1][c]=="#":
            continue

        if c>1 and graph[r][c-1]=="#":
            continue

        if c<height-1 and graph[r][c+1]=="#":
            continue

        print("No")
        exit()
print("Yes")

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
import sys
from collections.abc import Iterable
from math import *
from itertools import *
from collections import *
from functools import *
from operator import *
try:
    from math import gcd
except Exception:
    from fractions import gcd

YES = "Yes"  # type: str
NO = "No"  # type: str

def solve(H: int, W: int, s: "List[str]"):
    m = [[0] * W for _ in range(H)]
    for j in range(len(s)):
        for i in range(len(s[j])):
            if s[j][i] == '#':
                if j < (len(s) - 1) and s[j+1][i] == '#':
                    m[j][i] += 1
                    m[j+1][i] += 1
                if i < (len(s[j]) - 1) and s[j][i+1] == '#':
                    m[j][i] += 1
                    m[j][i+1] += 1
                if m[j][i] == 0:
                    return NO
    return YES


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    s = [ next(tokens) for _ in range(W) ]  # type: "List[str]"
    result = solve(H, W, s)
    if isinstance(result, Iterable) and not isinstance(result, str):
        result = '\n'.join([str(v) for v in result])
    print(result)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

s = []
s.append("." * (w+2)) 
for _ in range(h):
	s.append("." + input() + ".")
s.append("." * (w+2)) 

ans = "Yes"
dx = [-1, 0, 1, 0]
dy = [ 0, 1, 0,-1]

for i in range(1, h+1):
	for j in range(1, h+1):
		if s[i][j] == "#":
			CanPaint = False
			for k in range(4):
				if s[i+dx[k]][j+dy[k]] == "#":
					CanPaint = True
			if not CanPaint:
				ans = "No"

print(ans)

Submission status: Runtime Error

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

s = []
s.append("." * (w+2)) 
for _ in range(h):
	s.append("." + input() + ".")
s.append("." * (w+2)) 

ans = "Yes"
dx = [-1, 0, 1, 0]
dy = [ 0, 1, 0,-1]

for i in range(1, h+1):
	for j in range(1, h+1):
		if s[i][j] == "#":
			CanPaint = False
			for k in range(4):
				if s[i+dx[k]][j+dy5 5
#.#.#
.#.#.
#.#.#
.#.#.
#.#.#[k]] == "#":
					CanPaint = True
			if not CanPaint:
				ans = "No"

print(ans)

Submission status: Runtime Error

Solution code:
H, W = map(int, input().split())
S =['.']*(W+2)+ ['.'+input()+'.' for i in range(H)]+['.']*(W+2)
flag = True
for i in range(1, H+1):
    for k in range(1, W+1):
        if S[i][k] == '#':
            if S[i-1][k] == '.' and S[i+1][k] == '.' and S[i][k+1] == '.' and S[i][k-1] == '.':
                flag = False
                break
    if not flag:
        break
if flag:
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

Solution code:
def solve(field):
  for i in range(1, h + 1):
    for j in range(1, w + 1):
      if field[i][j] == '#':
        continue
        if field[i-1][j] == field[i][j-1] == field[i][j+1] == field[i+1][j] == '.':
        '''上下左右に黒がない場合、黒色にできない（隣も塗らざるを得ないから）。
        また黒色にできないのはその場合に限る（1つ以上あれば――ダブってても白には戻らないため――べたべた塗ればよい）'''
          return False
        return True

h, w = list(map(int, input().split()))
field = ['.' + input() + '.' for _ in range(1, h + 1)]
#左右の端についてもsolve(field)を適用するため、入力に左右を付け加える
field = ['.'*(w+2)] + field + ['.'*(w+2)]
'''上下の端についても同様の処理。fieldは例えば['.....', '..#..', '.###.', '..#..', '.....']となる。
これのi番目のリストのj項が、field[i][j]によって指示される。'''
print('Yes' if solve(field) else 'No')#solve(field)だけで、Trueが返ってくるということを意味する。