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:
import sys
n,w=map(int,input().split())
st=[[str(a) for s in b.strip()] for b in sys.stdin]
count=0
for i in range(1,n-2):
    for j in range(1,w-2):
        if st[i][j]=="#":
            count+=1
            if st[i][j]!=st[i-1][j] and st[i][j]!=st[i][j-1] and st[i][j+1]!=st[i][j] and st[i][j]!=st[i+1][j]:
                print("No")
                exit()
if st[0][0]=="#" and st[0][0]!=st[0][1] and st[1][0]!=st[0][0]:
    print("No")
    exit()

if st[0][w-1]=="#" and st[0][0]!=st[0][w-2] and st[1][w-1]!=st[0][w-1]:
    print("No")
    exit()

if st[n-1][w-1]=="#" and st[n-1][w-1]!=st[n-1][w-2] and st[n-1][w-1]!=st[n-2][w-1]:
    print("No")
    exit()
if st[n-1][0]=="#" and st[n-1][0]!=st[n-1][1] and st[n-2][0]!=st[n-1][0]:
    print("No")
    exit()
print("Yes")

Submission status: Runtime Error

Solution code:
import sys
n,w=map(int,input().split())
st=[[a for s in b.strip()] for b in sys.stdin]
count=0
for i in range(1,n-2):
    for j in range(1,w-2):
        if st[i][j]=="#":
            count+=1
            if st[i][j]!=st[i-1][j] and st[i][j]!=st[i][j-1] and st[i][j+1]!=st[i][j] and st[i][j]!=st[i+1][j]:
                print("No")
                exit()
if st[0][0]=="#" and st[0][0]!=st[0][1] and st[1][0]!=st[0][0]:
    print("No")
    exit()

if st[0][w-1]=="#" and st[0][0]!=st[0][w-2] and st[1][w-1]!=st[0][w-1]:
    print("No")
    exit()

if st[n-1][w-1]=="#" and st[n-1][w-1]!=st[n-1][w-2] and st[n-1][w-1]!=st[n-2][w-1]:
    print("No")
    exit()
if st[n-1][0]=="#" and st[n-1][0]!=st[n-1][1] and st[n-2][0]!=st[n-1][0]:
    print("No")
    exit()
print("Yes")

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

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

for i in range(H):
    for j in range(W):
        if s[i][j]=='#':
            dfs(i,j)
"""
for i in s:
    for j in i:
        if j=='#':
            print('No')
            exit()
"""
print('Yes')

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

s = [list(input()) for _ in range(h)]

DX = [-1, 0, 1, 0]
DY = [0, -1, 0, 1]

ans = True

for i in range(h):
    for j in range(w):
        if s[i][j] == ".":
            continue
        flag = 0
        for k in range(4):    
            if not(0<=i+DX[k]<=w and 0<=j+DY[k]<=h):
                continue
            if s[i + DX[k]][j + DY[k]] == "#":
                flag = 1
                break
        if flag == 0:
          ans = False
          break
print("Yes" if ans else "No")

Submission status: Runtime Error

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

s = [list(input()) for _ in range(h)]

DX = [-1, 0, 1, 0]
DY = [0, -1, 0, 1]

ans = True

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

Submission status: Runtime Error

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

s = [list(input()) for _ in range(h)]

DX = [-1, 0, 1, 0]
DY = [0, -1, 0, 1]

ans = True

for i in range(h):
    for j in range(w):
        flag = False
        for k in range(4):    
            if not(0<=i+DX[k]<=w-1 and 0<=j+DY[k]<=h-1):
                continue
            if s[i + DX[k]][j + DY[k]] == "#":
                flag = True
        ans = flag
print("Yes" if ans else "No")

Submission status: Runtime Error

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

s = [list(input()) for _ in range(h)]

DX = [-1, 0, 1, 0]
DY = [0, -1, 0, 1]

ans = True

for i in range(h):
    for j in range(w):
        if s[i][j] == ".":
            continue
        flag = False
        for k in range(4):    
            if not(0<=i+DX[k]<=w-1 and 0<=j+DY[k]<=h-1):
                continue
            if s[i + DX[k]][j + DY[k]] == "#":
                flag = True
        ans = flag
print("Yes" if ans else "No")

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import sys
h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]
hantei = [[0 for _ in range(h)] for _ in range(w)]
for i in range(h):
    for j in range(w):
        if s[i][j] == "#":
            if i < h-1:
                if s[i+1][j] == "#":
                    hantei[i][j] = 1
                    hantei[i+1][j] = 1
            if j < w-1:
                if s[i][j+1] == "#":
                    hantei[i][j] = 1
                    hantei[i][j+1] = 1

for i in range(h):
    for j in range(w):
        if s[i][j] == "#":
            if hantei[i][j] == 0:
                print("No")
                sys.exit()

print("Yes")

Submission status: Runtime Error

Solution code:
import sys
h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]
hantei = [[0 for _ in range(h)] for _ in range(w)]
for i in range(h):
    for j in range(w):
        if s[i][j] == "#":
            if i < h-1:
                if s[i+1][j] == "#":
                    hantei[i][j] = 1
                    hantei[i+1][j] = 1
            if j < w-1:
                if s[i][j+1] == "#":
                    hantei[i][j] = 1
                    hantei[i][j+1] = 1

for i in range(w):
    for j in range(h):
        if s[i][j] == "#":
            if hantei[i][j] == 0:
                print("No")
                sys.exit()

print("Yes")

Submission status: Runtime Error

Solution code:
import sys
h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]
hantei = [[0 for _ in range(h)] for _ in range(w)]
for i in range(w-1):
    for j in range(h-1):
        if s[i][j] == "#":
            if s[i+1][j] == "#":
                hantei[i+1][j] = 1
                hantei[i][j] = 1
            if s[i][j+1] == "#":
                hantei[i][j+1] = 1
                hantei[i][j] = 1
for j in range(w-1):
    if s[h-1][j] == "#":
        if s[h-1][j+1] == "#":
            hantei[h-1][j] = 1
            hantei[h-1][j+1] = 1
for i in range(h-1):
    if s[i][w-1] == "#":
        if s[i+1][w-1] == "#":
            hantei[i][w-1] = 1
            hantei[i+1][w-1] = 1


for i in range(w):
    for j in range(h):
        if s[i][j] == "#":
            if hantei[i][j] == 0:
                print("No")
                sys.exit()

print("Yes")

Submission status: Runtime Error

Solution code:
H,W = map(int,input().split())
grid = [[]] * H

for i in range(H):
  c = list(input())
  grid[i] = c
  
black = "#"
white = "."

ans = "Yes"


for i in range(H):
  for j in range(W):
    if grid[i][j] == black:
      here = grid[i][j]
      around = ""
      
      if i == 0:
        around += grid[i + 1][j]
      elif i == W - 1:
        around += grid[i - 1][j]
      else:
        around += (grid[i - 1][j] + grid[i + 1][j])
      
      if j == 0:
        around += grid[i][j + 1]
      elif j == H - 1:
        around += grid[i][j - 1]
      else:
        around += (grid[i][j + 1] + grid[i][j - 1])
      
      if all([i == white for i in around]):
        ans = "No"
        break

print(ans)

Submission status: Runtime Error

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

dx=[-1,0,1,0]
dy=[0,1,0,-1]
for i in range(h):
    for j in range(w):
        if grid[i][j]=='#':
            flag=False
            for k in range(4):
                x=i+dx[k]
                y=j+dy[k]
                if 0<=x<w and 0<=y<h and grid[x][y]=='#':
                    flag=True
                    break
            if flag:
                continue
            else:
                print('No')
                exit()
print('Yes')

Submission status: Runtime Error

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

Submission status: Runtime Error

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

ans = "Yes"
for i in range(h):
    for j in range(w):
        if mass[i][j] == "#":
            if i < w-1:
                if mass[i+1][j] == "#":
                    continue
            if 0 < i:
                if mass[i-1][j] == "#":
                    continue
            if j < h-1:
                if mass[i][j+1] == "#":
                    continue
            if 0 < j:
                if mass[i][j-1] == "#":
                    continue
            ans = "No"
            break

print(ans)

Submission status: Runtime Error

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

ans = "Yes"
for i in range(w):
    for j in range(h):
        if mass[i][j] == "#":
            if i < w-1:
                if mass[i+1][j] == "#":
                    continue
            if 0 < i:
                if mass[i-1][j] == "#":
                    continue
            if j < h-1:
                if mass[i][j+1] == "#":
                    continue
            if 0 < j:
                if mass[i][j-1] == "#":
                    continue
            ans = "No"
            break

print(ans)

Submission status: Runtime Error

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

ans = "Yes"
for i in range(w):
    for j in range(h):
        if mass[i][j] == "#":
            if i < w-1:
                if mass[i+1][j] == "#":
                    continue
            if 0 < i:
                if mass[i-1][j] == "#":
                    continue
            if j < h-1:
                if mass[i][j+1] == "#":
                    continue
            if 0 < j:
                if mass[i][j-1] == "#":
                    continue
            ans = "No"
            break

print(ans)
h, w = map(int, input().split())
mass = [list(input()) for _ in range(h)]

ans = "Yes"
for i in range(w):
    for j in range(h):
        if mass[i][j] == "#":
            if i < w-1:
                if mass[i+1][j] == "#":
                    continue
            if 0 < i:
                if mass[i-1][j] == "#":
                    continue
            if j < h-1:
                if mass[i][j+1] == "#":
                    continue
            if 0 < j:
                if mass[i][j-1] == "#":
                    continue
            ans = "No"
            break

print(ans)

Submission status: Runtime Error

Solution code:
h,w=map(int,input().split())
s=[list(map(int,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 s[i-1][j]=='.' and s[i][j-1]=='.' and s[i][j+1]=='.' and s[i+1][j]=='.':
                print('No')
                exit()
print('Yes')

Submission status: Runtime Error

Solution code:
sal
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] == "#":
      d = set()
      if i>0:
        d.add(s[i-1][j])
      if i<h-1:
        d.add(s[i+1][j])
      if j>0:
        d.add(s[i][j-1])
      if j<w-1:
        d.add(s[i][j+1])
      if "#" not in d:
        print("No")
        exit()
print("Yes")

Submission status: Runtime Error

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, width + 1):
        for j in range(1, height + 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: Runtime Error

Solution code:
def main():
    height, width = map(int, input().split(" "))
    grids = ["." * (width + 2)]
    for _ in range(height):
        tmp = input()
        grids.append("." + tmp + ".")
    grids.append("." * (width + 2))
    is_possible = True
    for i in range(1, width + 1):
        for j in range(1, height + 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: Runtime Error

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, width + 1):
        for j in range(1, height + 1):
            if grids[i][j] == "#":
                if grids[i + 1][j] == "." and grids[i - 1][j] == "." and grids[i][j + 1] == "." and grids[i][j - 1] == ".":
                    is_possible = False
    if is_possible:
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    main()

Submission status: Runtime Error

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, width):
        for j in range(1, height):
            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: Runtime Error

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, width):
        for j in range(1, height + 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: Runtime Error

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, width + 1):
        for j in range(1, height + 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: Runtime Error

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


if __name__ == '__main__':
    main()

Submission status: Runtime Error

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


if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

r = 'Yes'
for i in range(1, w-1):
    for j in range(1, h-1):
        if S[i][j]=='#':
            if S[i-1][j]=='.' and S[i+1][j]=='.' or S[i][j-1]=='.' or S[i][j+1]=='.':
                r = 'No'
                break
print(r)

Submission status: Runtime Error

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

r = 'Yes'
for i in range(1, w-1):
    for j in range(1, h-1):
        if S[i][j]=='#':
            if S[i-1][j]=='#' or S[i+1][j]=='#' or S[i][j-1]=='#' or S[i][j+1]=='#':
                continue
            else:
                r = 'No'
print(r)

Submission status: Runtime Error

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] == "#" or list[h-1][w] == "#" or list[h][w-1] == "#" or list[h][w+1] == "#":
                a=0
            else:
                a=1
                break
print("Yes" if a==0 else "No")

Submission status: Runtime Error

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] == "#" or list[h-1][w] == "#" or list[h][w-1] == "#" or list[h][w+1] == "#":
                a=0
            else:
                a=1
                break
print("Yes" if a==0 else "No")

Submission status: Runtime Error

Solution code:
import sys
h,w = map(int,input().split())
matrix = [[0]*(h+2) for _ in range(w+2)]
for hi in range(h):
    all_inp = input()
    for i,a in enumerate(all_inp):
        matrix[hi+1][i+1]= 0 if a == '.' else 1
#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: Runtime Error

Solution code:
import sys
h,w = map(int,input().split())
matrix = [[0]*(h+2) for _ in range(w+2)]
for hi in range(h):
    all_inp = input()
    for i,a in enumerate(all_inp):
        matrix[hi+1][i+1]= 0 if a == '.' else 1
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: Runtime Error

Solution code:
H,W = [int(i) for i in input().split()]
pic = [list(input()) for _ in range(H)]
dx = [1,0,-1,0]
dy = [0,1,0,-1]
def dfs(x,y):
    pic[x][y] = "."
    for i in range(4):
        nx = x + dx[i]
        ny = y + dy[i]
        if nx < 0 or ny < 0 or nx >= W or ny >= H:
            continue
        if pic[nx][ny] == ".":
            continue
        dfs(nx,ny)
a = 1
ans = "Yes"
for i in range(H):
    for j in range(W):
        if pic[i][j] == "#":
            count = 0
            for k in range(4):
                nx = i + dx[k]
                ny = j + dy[k]
                if nx < 0 or ny < 0 or nx >= W or ny >= H:
                    continue
                if pic[nx][ny] == "#":
                    count+=1
            if count == 0:
                ans = "No"
                a = 0
                break
    if a == 0:
        break
print(ans)

Submission status: Runtime Error

Solution code:


a,b,ab,x,y=map(int,input().split())
ans=0
abcnt=min(x,y)
if (a+b)//2>=ab:
    if min(a,b)>ab*2:
        ans+=max(x,y)*2*ab
    else:
        ans+=abcnt*2*ab
        if x>y:
            ans+=(x-abcnt)*a
        else:
            ans+=(y-abcnt)*b
else:
    ans+=x*a+y*b
print(ans)

Submission status: Runtime Error

Solution code:
H,W = [int(i) for i in input().split()]
li = ['0'] * H
for i in range(H) :
    li[i] = list(input())
dx = [1,0,-1,0]
dy = [0,1,0,-1]
counta = 0
count = 0
for i in range(H) :
    for j in range(W) :
        if li[i][j] == "#" :
            counta+=1
for i in range(H) :
    for j in range(W) :
        if li[i][j] == "#" :
            for k in range(4) :
                nx = i + dx[k]
                ny = j + dy[k]
                if nx < 0 or nx > W-1 or ny < 0 or ny > H-1 :
                    continue
                if li[nx][ny] == "#" :
                    count+=1
                    break
if count == counta:
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

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

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

ans = "Yes"
for n in range(N):
    for m in range(M):
        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: Runtime Error

Solution code:

a,b=map(int,input().split())
x=[0,0,-1,1]
y=[-1,1,0,0]
d=[]
for i in range(b):
    d.append(list(input()))
    
    
for i in range(b):
    for j in range(a):
    
        if d[i][j] == '#':
        
            check=0
            
            for xv,yv in zip(x,y):
                if 0 <= xv + j < a  and 0 <= yv + i < b:
                    if d[i+yv][j+xv] == "#":
                        check=1
                        break
        
            if check==0:
                print("No")
                exit()
            
                        
print("Yes")

Submission status: Runtime Error

Solution code:
a,b=map(int,input().split())
x=[0,0,-1,1]
y=[-1,1,0,0]
d=[]
for i in range(b):
    d.append(list(input()))
    
result="Yes"
for i in range(b):
    for j in range(a):
        if d[i][j] == '#':
            check=0
            for xv,yv in zip(x,y):
                if 0 <= xv + j < a  and 0 <= yv + i < b:
                    if d[i+yv][j+xv] == '#':
                        check=1
                        break
        
            if check==0:
                result="No"
                break
            
                    
print(result)

Submission status: Runtime Error

Solution code:

a,b=map(int,input().split())
x=[0,0,-1,1]
y=[-1,1,0,0]
d=[[0]*a for x in range(b)]
for i in range(b):
    d[i]=list(input())
    
result="Yes"

for i in range(b):
    for j in range(a):
        if d[i][j] == '#':
            check=0
            for xv,yv in zip(x,y):
                if 0 <= xv + j < a  and 0 <= yv + i < b:
                    if d[i+yv][j+xv] == '#':
                        check=1
                        #break
        
            if check==0:
                result="No"
                #break
            
                        
print(result)