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:
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"
                        
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"
                        
print(result)

Submission status: Runtime Error

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

can_draw = True

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

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

def search(i,j):
  flg = False
  if 0<=i-1:
    if s[i-1][j] == "#":
      flg = True
  if i+1 < h:
    if s[i+1][j] == "#":
      flg = True 
  if 0<=j-1:
    if s[i][j-1] == "#":
      flg = True
  if j+1 < w:
    if s[i][j+1] == "#":
      flg = True
  return flg
  
for i in range(h):
  for j in range(w):
    if s[i][j]=="#" and search(i,j)==False:
      print("No")
      break
  else:
    continue
  break
else:
  print("Yes")

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
#include <cmath>
using namespace std;

int main(){
    int h,w;
    char data[55][55]={};
    cin >>h>>w;
    bool ans=true;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin>>data[i][j];
        }
    }

    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            if(data[i][j]=='#'){
                ans=false;
                if(data[i][j]==data[i+1][j]){
                   ans=true;
                }

                if(data[i][j]==data[i][j+1]){
                   ans=true;
                }
                if(j!=0){
                    if (data[i][j] == data[i][j -1]){
                        ans = true;
                    }
                }

                if(i!=0){
                    if (data[i][j] == data[i-1][j]){
                        ans = true;
                    }
                }
                if(ans==false){
                    cout<<"No";
                    return 0;
                }
            }
        }
    }
    cout<<"Yes";
    return 0;

}

Submission status: Runtime Error

Solution code:
# coding: utf-8
import sys

ys.setrecursionlimit(200000)

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

canvas=[]

flg=True

def bfs(y,x):
    cnt[0]+=1
    canvas[y][x]="."
    dx=[1,0,-1,0]
    dy=[0,1,0,-1]
    for i in range(4):
        ny=y+dy[i]
        nx=x+dx[i]
        
        if 0<=nx<=W-1 and 0<=ny<=H-1:
            if canvas[ny][nx]=="#":
                bfs(ny,nx)

for i in range(H):
    row=list(input())
    canvas.append(row)


for i in range(H):
    for j in range(W):
        if canvas[i][j]=="#":
            cnt=[0]
            bfs(i,j)
            if cnt[0]==1:
                flg=False

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

Submission status: Runtime Error

Solution code:
# coding: utf-8

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

canvas=[]

flg=True

def bfs(y,x):
    cnt[0]+=1
    canvas[y][x]="."
    dx=[1,0,-1,0]
    dy=[0,1,0,-1]
    for i in range(4):
        ny=y+dy[i]
        nx=x+dx[i]
        
        if 0<=nx<=W-1 and 0<=ny<=H-1:
            if canvas[ny][nx]=="#":
                bfs(ny,nx)

for i in range(H):
    row=list(input())
    canvas.append(row)


for i in range(H):
    for j in range(W):
        if canvas[i][j]=="#":
            cnt=[0]
            bfs(i,j)
            if cnt[0]==1:
                flg=False

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

Submission status: Runtime Error

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

#1.角の黒マス（２マスと接している）が白で囲まれている場合
if S[0][0] == '#' and S[0][1] == S[1][0] == '.':
    print('No')
elif S[0][H-1] == '#' and S[0][H-2] == S[1][H-1] == '.':
    print('No')
elif S[W-1][0] == '#' and S[W-2][0] == S[W-1][1] == '.':
    print('No')
elif S[W-1][H-1] == '#' and S[W-2][H] == S[W][H-2] == '.':
    print('No')
else:
    print('Yes')

Submission status: Runtime Error

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

if S[0][0] == '#' and S[0][1] == S[1][0] == '.':
    print('No')
elif S[0][H-1] == '#' and S[0][H-2] == S[1][H-1] == '.':
    print('No')
elif S[W-1][0] == '#' and S[W-2][0] == S[W-1][1] == '.':
    print('No')
elif S[W-1][H-1] == '#' and S[W-2][H] == S[W][H-2] == '.':
    print('No')
else:
    print('Yes')

Submission status: Runtime Error

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

#4隅が黒で両隣が白の場合、達成不可能
if S[0][0] == '#' and S[0][1] == S[1][0] == '.':
    print('No')
elif S[0][H-1] == '#' and S[0][H-2] == S[1][H-1] == '.':
    print('No')
elif S[W-1][0] == '#' and S[W-2][0] == S[W-1][1] == '.':
    print('No')
elif S[W-1][H-1] == '#' and S[W-2][H] == S[W][H-2] == '.':
    print('No')
else:
    print('Yes')

Submission status: Runtime Error

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

for h in range(H):
    for w in range(W):
        if s[h][w] == "#":
            if h>0 ans s[h-1][w]=="#":
                continue
            elif h<H-1 ans s[h+1][w]=="#":
                continue
            elif w>0 ans s[h][w-1]=="#":
                continue
            elif h<W-1 ans s[h][w+1]=="#":
                continue
            else:
                print("No")
                break
else:
    print("Yes")

Submission status: Runtime Error

Solution code:
H,W = map(int,input().split())
s = [["."] *(W+2)]+[["."]+list(input())+["."] for _ in range(W)]+[["."] *(W+2)]
#print(*s, sep="\n")
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+1][j]=="." and s[i][j+1]==".":
                print("No")
                exit()
print("Yes")

Submission status: Runtime Error

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

for i in range(h):
    ls[i] = ["."] + ls[i] + ["."]

ls_s = [["."] * len(ls[0])]
ls_s.extend(ls)
ls_s.extend([["."] * len(ls[0])])

for i in range(1, len(ls)+1):
    for j in range(1, len(ls)+1):
        if ls_s[i][j] == "#":
            if ls_s[i-1][j] == ls_s[i+1][j] == ls_s[i][j-1] == ls_s[i][j+1] == ".":
                print("No")
                break
            elif i == j == len(ls):
                print("Yes")
        elif i == j == len(ls):
            print("Yes")
    else:
        continue
    break

Submission status: Runtime Error

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

for i in range(h):
    ls[i] = ["."] + ls[i] + ["."]

ls_s = [["."] * len(ls[0])]
ls_s.extend(ls)
ls_s.extend([["."] * len(ls[0])])

for i in range(1, len(ls)+1):
    for j in range(1, len(ls)+1):
        if ls_s[i][j] == "#":
            if ls_s[i-1][j] == ls_s[i+1][j] == ls_s[i][j-1] == ls_s[i][j+1] == ".":
                print("No")
                break
        elif i == j == len(ls):
            print("Yes")
    else:
        continue
    break

Submission status: Runtime Error

Solution code:
H,W=map(int,input().split())
s=[list(input()) for _ in range(H)]
l=[-1,1]
cnt=0
for i in range(H):
    for j in range(W):
        a=set()
        if s[i][j]=='#':
            cnt+=1
            for v in l:
                if H>i-v>=0:
                    a.add(s[i-v][j])
                if H>j-v>=0:
                    s[i][j-v]
                    a.add(s[i][j-v])
            if '#' not in a:
                print('No')
                exit()
if cnt==0:
    print('No')
else:
    print('Yes')

Submission status: Runtime Error

Solution code:
h, w = map(int, input().split())
hor = '.' * (h+2)
board = [hor] * (w+2)
for i in range(1, h+1):
    board[i] = '.' + input() + '.'

# print(board)
ans = "Yes"
for i in range(1, h+1):
    for j in range(1, w+1):
        if board[i][j] == '#':
            if board[i+1][j] == "." and\
            board[i][j+1] == "." and\
            board[i][j-1] == "." and\
            board[i-1][j] == ".":
                ans = "No"
                break

print(ans)

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]"):
    s = ["."*(W+2)]+["."+ss+"."for ss in s]+["."*(W+2)]
    direction = ((0,1),(1,0),(0,-1),(-1,0))
    # 全ての黒マスの上下左右に一つでも黒マスがあればおk
    for i in range(H+2):
        for j in range(W+2):
            if s[i][j] == ".":
                continue
            
            for x,y in direction:
                if s[i+x][j+y] == "#":
                    break
            else:
                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:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    s = []
    H, W = LI()
    for i in range(H):
        _s = S()
        s.append(_s)
    for i in range(W):
        for j in range(H):
            if s[i][j] == '.':
                continue
            any_tonari_black = False
            for dr, dc in zip(DR, DC):
                new_i = i + dr
                new_j = j + dc
                if not (0 <= new_i < W and 0 <= new_j < H):
                    continue
                if s[new_i][new_j] == '#':
                    any_tonari_black = True
            if not any_tonari_black:
                print('No')
                return
    print('Yes')
main()

Submission status: Runtime Error

Solution code:
h, w = map(int, input().split())
s = [list(input()) for j in range(h)]
ans = 'Yes'
for j in range(w):
  for i in range(h):
    ok = False
    if s[j][i] == '#':
      if j-1>=0:
        if s[j-1][i] == '#': ok = True
      if i-1>=0:
        if s[j][i-1] == '#': ok = True
      if j+1<h:
        if s[j+1][i] == '#': ok = True
      if i+1<w:
        if s[j][i+1] == '#': ok = True
      if ok == False:
        print('No')
        exit()
print(ans)

Submission status: Runtime Error

Solution code:
h, w = map(int, input().split())
s = [list(input()) for j in range(h)]
ans = 'Yes'
for j in range(w):
  for i in range(h):
    ok = False
    if s[j][i] == '#':
      if j-1>=0:
        if s[j-1][i] == '#': ok = True
      if i-1>=0:
        if s[j][i-1] == '#': ok = True
      if j+1<w:
        if s[j+1][i] == '#': ok = True
      if i+1<h:
        if s[j][i+1] == '#': ok = True
      if ok == False:
        print('No')
        exit()
print(ans)

Submission status: Runtime Error

Solution code:
h, w = map(int, input().split())
s = [list(input()) for j in range(h)]
cross = [[0,-1],[-1,0],[1,0],[0,1]] # 上左右下の定義

for j in range(w):
  for i in range(h):
    if s[j][i] == '#' or s[j][i] == 'B':
      if i-1>=0 :
        if s[j][i-1] == '#': s[j][i-1] = 'B'
      if i+1<w :
        if s[j][i+1] == '#': s[j][i+1] = 'B'
      if j-1>=0 :
        if s[j-1][i] == '#': s[j-1][i] = 'B'
      if j+1<h :
        if s[j+1][i] == '#': s[j+1][i] = 'B'

for se in s:
  if '#' in se:
    print('No')
    exit()

print('Yes')

Submission status: Runtime Error

Solution code:
h,w=map(int,input().split())
#枠を大きめに確保してout of rangeを避ける!
grid = ["."*(w+2)]
for _ in range(h):
    grid.append("." + input() + ".")
grid += ["."*(w+2)]

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

Submission status: Runtime Error

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


def ix(index, H=H, W=W):
    if index < 0:
        index = 0
    if index >= H:
        index = (H-1)
    if index >= W:
        index = (W-1)
    return index


for i in range(H):
    for j in range(W):
        if c[i][j] == "#":
            result = "No"
            if (ix(i - 1) != i) and (c[ix(i-1)][j] == "#"):
                result = "Yes"
            if (ix(i + 1) != H-1) and (c[ix(i+1)][j] == "#"):
                result = "Yes"
            if (ix(j - 1) != j) and (c[i][ix(j-1)] == "#"):
                result = "Yes"
            if (ix(j + 1) != W-1) and (c[i][ix(j+1)] == "#"):
                result = "Yes"
            if result == "No":
                break
print(result)

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(2000)
h, w = map(int, raw_input().split())
s = [[c for c in raw_input()] for i in range(h)]
def isValid(i, j):
    if i < 0 or i >= h or j < 0 or j >= w:
        return False
    return True
    
def dfs(s, i, j):
    if not isValid(i, j) or s[i][j] == "0" or s[i][j] == ".":
        return 0
    if s[i][j] == "#":
        s[i][j] = "0"
        a = dfs(s, i+1, j)
        b = dfs(s, i-1, j)
        c = dfs(s, i, j+1)
        d = dfs(s, i, j-1)
        return 1 + a + b + c + d

for i in range(h):
    for j in range(w):
        if s[i][j] == "#":
            ccs = dfs(s, i, j)
            #print ccs
            if ccs == 1:
                print "No"
                exit()
print "Yes"

Submission status: Runtime Error

Solution code:
h, w = map(int, raw_input().split())
s = [[c for c in raw_input()] for i in range(h)]
def isValid(i, j):
    if i < 0 or i >= h or j < 0 or j >= w:
        return False
    return True
    
def dfs(s, i, j):
    if not isValid(i, j) or s[i][j] == "0" or s[i][j] == ".":
        return 0
    if s[i][j] == "#":
        s[i][j] = "0"
        a = dfs(s, i+1, j)
        b = dfs(s, i-1, j)
        c = dfs(s, i, j+1)
        d = dfs(s, i, j-1)
        return 1 + a + b + c + d

for i in range(h):
    for j in range(w):
        if s[i][j] == "#":
            ccs = dfs(s, i, j)
            #print ccs
            if ccs == 1:
                print "No"
                exit()
print "Yes"

Submission status: Runtime Error

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

def search(y,x):
    if mat[y][x] == '#':
        y2 = [0,0,1,-1]
        x2 = [1,-1,0,0]
        for i in range(4):
            if 0<=y+y2[i]<=H-1 and 0<=x+x2[i]<=W-1:
                if mat[y+y2[i]][x+x2[i]] == '#':
                    return True
        return False
    
    return True
ans = 'Yes'
for i in range(H):
    for j in range(W):
        if ans == 'No':
            break
        if search(j,i):
            continue
        else:
            ans = 'No'
            break
print(ans)

Submission status: Runtime Error

Solution code:
h,w=map(int,input().split())
a=[]
for i in range(h):
  a.append(list("."+(input())+"."))
a.insert(0,["."]*(h+2))
a.append(["."]*(h+2))
flg = True
for i in range(h+2):
  for j in range(w+2):
    if a[i][j] == "#":
      for (k,l) in ((i,j+1),(i,j-1),(i+1,j),(i-1,j)):
        if a[k][l] != "#":
          cnt+=1
          if cnt == 4:
            flg = False
    cnt=0
if flg:
  print("Yes")
else:
  print("No")

Submission status: Runtime Error

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

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


def solve(H: int, W: int, s: "List[str]"):
    ans = YES
    for i in range(1, H-1):
        for j in range(1, W-1):
            if s[i][j] == "#" and s[i-1][j] == s[i+1][j] == s[i][j-1] == s[i][j+1] == ".":
                ans = NO
    print(ans)

# Generated by 1.1.6 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
import numpy as np

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


def solve(H: int, W: int, s: "List[str]"):
    def chk_neighbor(i, j):
        if i < 0 or j < 0 or i >= H or j >= W:
            return "."
        else:
            return s[i][j]

    count = 0
    numofshirp = 0
    for s_ in s:
        numofshirp += s_.count("#")

    for i in range(H):
        for j in range(W):
            if s[i][j] == "#":
                if "#" in [chk_neighbor(i - 1, j), chk_neighbor(i + 1, j), chk_neighbor(i, j - 1), chk_neighbor(i, j + 1)]:
                    count += 1

    if count == numofshirp:
        print(YES)
    else:
        print(NO)

# Generated by 1.1.6 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
import numpy as np

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

def solve(H: int, W: int, s: "List[str]"):
    count = 0
    numofshirp = 0
    for s_ in s:
        numofshirp += s_.count("#")

    #padding
    edge = ["".join(["."] * (W + 2))]
    for i, si in enumerate(s):
        s[i] = "".join("."+si+".")
    s.extend(edge)
    edge.extend(s)

    for i, ei in enumerate(edge):
        for j, eij in enumerate(ei):
            if eij == "#" and i > 0 and j > 0 and i < len(edge) - 1 and j < len(edge[0]) - 1:
                if "#" in (edge[i - 1][j], edge[i + 1][j], edge[i][j - 1], edge[i][j + 1]):
                    count += 1

    if count == numofshirp:
        print(YES)
    else:
        print(NO)

# Generated by 1.1.6 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
import numpy as np

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

def solve(H: int, W: int, s: "List[str]"):
    count = 0
    numofshirp = 0
    for s_ in s:
        numofshirp += s_.count("#")

    #padding
    edge = ["".join(["."] * (W + 2))]
    for i, si in enumerate(s):
        s[i] = "".join("."+si+".")
    s.extend(edge)
    edge.extend(s)

    for i, ei in enumerate(edge):
        for j, eij in enumerate(ei):
            if eij == "#" and i > 0 and j > 0:
                if "#" in (edge[i - 1][j], edge[i + 1][j], edge[i][j - 1], edge[i][j + 1]):
                    count += 1

    if count == numofshirp:
        print(YES)
    else:
        print(NO)

# Generated by 1.1.6 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
import numpy as np

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

def solve(H: int, W: int, s: "List[str]"):
    count = 0
    numofshirp = 0
    for s_ in s:
        numofshirp += s_.count("#")

    #padding
    edge = ["".join(["."] * (W + 2))]
    for i, si in enumerate(s):
        s[i] = "".join("."+si+".")
    s.extend(edge)
    edge.extend(s)

    for i, ei in enumerate(edge):
        for j, eij in enumerate(ei):
            if eij == "#":
                if "#" in (edge[i - 1][j], edge[i + 1][j], edge[i][j - 1], edge[i][j + 1]):
                    count += 1

    if count == numofshirp:
        print(YES)
    else:
        print(NO)

# Generated by 1.1.6 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:
H,W = map(int,input().split())
mat = [list(input()) for _ in range(H)]
ans = "Yes"

def judge(i, j):
    dx = [-1, 0, 1, 0]
    dy = [0, 1, 0, -1]
    for k in range(4):
        if 0 <= i+dy[k] <= (W-1) and 0 <= j+dx[k] <= (H-1):
            if mat[i+dy[k]][j+dx[k]] == "#":
                return True
    return False

for x in range(W):
    for y in range(H):
        if mat[x][y] == "#":
            if not judge(x,y):
                ans = "No"
                break
print(ans)

Submission status: Runtime Error

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

def judge(i, j):
    dx = [-1, 0, 1, 0]
    dy = [0, 1, 0, -1]
    for k in range(4):
        if 0 <= i+dy[k] <= (W-1) and 0 <= j+dx[k] <= (H-1):
            if mat[i+dy[k]][j+dx[k]] == "#":
                return True
    return False

for i in range(W):
    for j in range(H):
        if mat[i][j] == "#":
            if not judge(i,j):
                ans = "No"
                break
print(ans)

Submission status: Runtime Error

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

def judge(i, j):
    dx = [-1, 0, 1, 0]
    dy = [0, 1, 0, -1]
    for k in range(4):
        if 0 <= i+dx[k] <= (W-1) and 0 <= j+dy[k] <= (H-1):
            if mat[i+dx[k]][j+dy[k]] == "#":
                return True
    return False

for i in range(W):
    for j in range(H):
        if mat[i][j] == "#":
            if not judge(i,j):
                ans = "No"
                break
print(ans)

Submission status: Runtime Error

Solution code:
H,W = map(int,input().split())
mat = [list(input()) for _ in range(H)]
ans = "Yes"
dx = [-1,0,1,0]
dy = [0,1,0,-1]
for i in range(W):
    for j in range(H):
        if mat[i][j] == "#":
            for k in range(4):
                if 0 <= i+dx[k] <= W-1 and 0 <= j+dy[k] <= H-1:
                    if mat[i+dx[k]][j+dy[k]] == "#":
                        break
                    elif k == 3:
                        ans = "No"
                        break
print(ans)

Submission status: Runtime Error

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

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

ans = 'Yes'

for i in range(h):
    for j in range(w):
        if s[i][j] == '#' and s[i-1][j] == '.' and s[i+1][j] == '.' and s[i][j-1] == '.' and s[i][j+1] == '.':
            ans = 'No'

print(ans)

Submission status: Runtime Error

Solution code:
a,b = map(int,input().split())
c=[list(map(str,list(input()))) for i in range(b)]
x=a
y=b
e=0
r=0
if y>1 or x>1:
    for i in range(0,y,2):
        for j in range(1,x,2):
            if c[i][j] == "#":
                e+=2
                # if i > 0 and i < x-1 and j >0 and j < y-1:
                #     if c[i+1][j]=="#" or c[i][j+1]=="#" or c[i-1][j]=="#" or c[i][j-1]=="#" :
                #         r+=2
                #
                # elif i==0 and j!= 0 and j != y-1 :
                #     if c[i+1][j]=="#" or c[i][j+1]=="#" or c[i][j-1]=="#" :
                #         r+=2
                #
                # elif i == x-1 and j != 0 and j != y-1 :
                #     if c[i][j+1] == "#" or c[i-1][j] == "#" or c[i][j-1] == "#" :
                #         r+=2
                #
                # elif j == 0 and i != 0 and i != y-1:
                #     if c[i+1][j] == "#" or c[i][j+1] == "#" or c[i-1][j] == "#" :
                #         r+=2
                #
                # elif j == y-1 and i != y-1 and i != 0:
                #     if c[i+1][j] == "#" or c[i-1][j] == "#" or c[i][j-1] == "#" :
                #         r+=2
                #
                # elif i==0 and j == 0:
                #     if c[i+1][j]=="#" or c[i][j+1]=="#" :
                #         r+=2
                #
                # elif i==0 and j == y-1:
                #     if c[i+1][j]=="#"  or c[i][j-1]=="#" :
                #         r+=2
                #
                # elif i==x-1 and j == 0:
                #     if c[i][j+1]=="#" or c[i-1][j]=="#" :
                #         r+=2
                #
                # elif i == x-1 and j == y-1:
                #     if c[i-1][j]=="#" or c[i][j-1]=="#" :
                #         r+=2
                if i < x-1 and j < y-1:
                    if c[i+1][j]=="#" or c[i][j+1]=="#" :
                        r+=2

                # elif i==0 and j!= 0 and j != y-1 :
                #     if c[i+1][j]=="#" or c[i][j+1]=="#" or c[i][j-1]=="#" :
                #         r+=2

                elif i == x-1 and j != y-1 :
                    if c[i][j+1] == "#" :
                        r+=2

                # elif j == 0 and i != 0 and i != y-1:
                #     if c[i+1][j] == "#" or c[i][j+1] == "#" or c[i-1][j] == "#" :
                #         r+=2

                elif j == y-1 and i != y-1 :
                    if c[i+1][j] == "#":
                        r+=2

                # elif i==0 and j == 0:
                #     if c[i+1][j]=="#" or c[i][j+1]=="#" :
                #         r+=2
                #
                # elif i==0 and j == y-1:
                #     if c[i+1][j]=="#"  or c[i][j-1]=="#" :
                #         r+=2
                #
                # elif i==x-1 and j == 0:
                #     if c[i][j+1]=="#" or c[i-1][j]=="#" :
                #         r+=2
                #
                # elif i == x-1 and j == y-1:
                #     if c[i-1][j]=="#" or c[i][j-1]=="#" :
                #         r+=2
elif y==1 :
    for i in range(0,x,2):
        if c[0][i] == "#":
            e+=2
            if i < x-1 :
                if c[0][i+1]=="#" :
                    r+=2
elif x==1 :
    for i in range(0,y,2):
        if c[i][0] == "#":
            e+=2
            if i < y-1 :
                if c[i+1][0]=="#" :
                    r+=2
if r==e and r!=0:
    print("Yes")
else :
    print("No")